]> git.proxmox.com Git - mirror_edk2.git/blob - ArmPkg/Library/DebugPeCoffExtraActionLib/DebugPeCoffExtraActionLib.c
a1d3c06f2a2221ea80e7cc4effecc0a1bbb2d796
[mirror_edk2.git] / ArmPkg / Library / DebugPeCoffExtraActionLib / DebugPeCoffExtraActionLib.c
1 /**@file
2
3 Copyright (c) 2006 - 2009, Intel Corporation
4 Portions copyright (c) 2008-2010 Apple Inc. All rights reserved.
5 All rights reserved. This program and the accompanying materials
6 are licensed and made available under the terms and conditions of the BSD License
7 which accompanies this distribution. The full text of the license may be found at
8 http://opensource.org/licenses/bsd-license.php
9
10 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
11 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
12
13 **/
14
15 #include <PiDxe.h>
16 #include <Library/PeCoffLib.h>
17
18 #include <Library/BaseLib.h>
19 #include <Library/DebugLib.h>
20 #include <Library/BaseMemoryLib.h>
21 #include <Library/PeCoffExtraActionLib.h>
22 #include <Library/PrintLib.h>
23
24
25 /**
26 If the build is done on cygwin the paths are cygpaths.
27 /cygdrive/c/tmp.txt vs c:\tmp.txt so we need to convert
28 them to work with RVD commands
29
30 @param Name Path to convert if needed
31
32 **/
33 CHAR8 *
34 DeCygwinPathIfNeeded (
35 IN CHAR8 *Name
36 )
37 {
38 CHAR8 *Ptr;
39 UINTN Index;
40 UINTN Len;
41
42 Ptr = AsciiStrStr (Name, "/cygdrive/");
43 if (Ptr == NULL) {
44 return Name;
45 }
46
47 Len = AsciiStrLen (Ptr);
48
49 // convert "/cygdrive" to spaces
50 for (Index = 0; Index < 9; Index++) {
51 Ptr[Index] = ' ';
52 }
53
54 // convert /c to c:
55 Ptr[9] = Ptr[10];
56 Ptr[10] = ':';
57
58 // switch path seperators
59 for (Index = 11; Index < Len; Index++) {
60 if (Ptr[Index] == '/') {
61 Ptr[Index] = '\\' ;
62 }
63 }
64
65 return Name;
66 }
67
68
69 /**
70 Performs additional actions after a PE/COFF image has been loaded and relocated.
71
72 If ImageContext is NULL, then ASSERT().
73
74 @param ImageContext Pointer to the image context structure that describes the
75 PE/COFF image that has already been loaded and relocated.
76
77 **/
78 VOID
79 EFIAPI
80 PeCoffLoaderRelocateImageExtraAction (
81 IN OUT PE_COFF_LOADER_IMAGE_CONTEXT *ImageContext
82 )
83 {
84 #ifdef __CC_ARM
85 // Print out the command for the RVD debugger to load symbols for this image
86 DEBUG ((EFI_D_ERROR, "load /a /ni /np %a &0x%08x\n", DeCygwinPathIfNeeded (ImageContext->PdbPointer), (UINTN)(ImageContext->ImageAddress + ImageContext->SizeOfHeaders)));
87 #elif __GNUC__
88 // This may not work correctly if you generate PE/COFF directlyas then the Offset would not be required
89 DEBUG ((EFI_D_ERROR, "add-symbol-file %a 0x%08x\n", DeCygwinPathIfNeeded (ImageContext->PdbPointer), (UINTN)(ImageContext->ImageAddress + ImageContext->SizeOfHeaders)));
90 #else
91 DEBUG ((EFI_D_ERROR, "Loading driver at 0x%11p EntryPoint=0x%11p ", (VOID *)(UINTN) ImageContext->ImageAddress, FUNCTION_ENTRY_POINT (ImageContext->EntryPoint)));
92 #endif
93 }
94
95
96
97 /**
98 Performs additional actions just before a PE/COFF image is unloaded. Any resources
99 that were allocated by PeCoffLoaderRelocateImageExtraAction() must be freed.
100
101 If ImageContext is NULL, then ASSERT().
102
103 @param ImageContext Pointer to the image context structure that describes the
104 PE/COFF image that is being unloaded.
105
106 **/
107 VOID
108 EFIAPI
109 PeCoffLoaderUnloadImageExtraAction (
110 IN OUT PE_COFF_LOADER_IMAGE_CONTEXT *ImageContext
111 )
112 {
113 #ifdef __CC_ARM
114 // Print out the command for the RVD debugger to load symbols for this image
115 DEBUG ((EFI_D_ERROR, "unload symbols_only %a", DeCygwinPathIfNeeded (ImageContext->PdbPointer)));
116 #elif __GNUC__
117 // This may not work correctly if you generate PE/COFF directlyas then the Offset would not be required
118 DEBUG ((EFI_D_ERROR, "remove-symbol-file %a 0x%08x\n", DeCygwinPathIfNeeded (ImageContext->PdbPointer), (UINTN)(ImageContext->ImageAddress + ImageContext->SizeOfHeaders)));
119 #else
120 DEBUG ((EFI_D_ERROR, "Unloading %a", ImageContext->PdbPointer));
121 #endif
122 }