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