]> git.proxmox.com Git - mirror_edk2.git/blame - ArmPkg/Library/DebugPeCoffExtraActionLib/DebugPeCoffExtraActionLib.c
ArmPkg: Change use of EFI_D_* to DEBUG_*
[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
96a8bc11 5Portions copyright (c) 2011 - 2012, ARM Ltd. All rights reserved.<BR>\r
6\r
4059386c 7SPDX-License-Identifier: BSD-2-Clause-Patent\r
5b792f1a 8\r
9**/\r
10\r
11#include <PiDxe.h>\r
12#include <Library/PeCoffLib.h>\r
13\r
14#include <Library/BaseLib.h>\r
15#include <Library/DebugLib.h>\r
16#include <Library/BaseMemoryLib.h>\r
17#include <Library/PeCoffExtraActionLib.h>\r
18#include <Library/PrintLib.h>\r
19\r
20\r
21/**\r
3402aac7 22 If the build is done on cygwin the paths are cygpaths.\r
5b792f1a 23 /cygdrive/c/tmp.txt vs c:\tmp.txt so we need to convert\r
24 them to work with RVD commands\r
25\r
26 @param Name Path to convert if needed\r
27\r
28**/\r
29CHAR8 *\r
30DeCygwinPathIfNeeded (\r
1bfda055 31 IN CHAR8 *Name,\r
32 IN CHAR8 *Temp,\r
33 IN UINTN Size\r
5b792f1a 34 )\r
35{\r
36 CHAR8 *Ptr;\r
37 UINTN Index;\r
1bfda055 38 UINTN Index2;\r
3402aac7 39\r
5b792f1a 40 Ptr = AsciiStrStr (Name, "/cygdrive/");\r
41 if (Ptr == NULL) {\r
42 return Name;\r
43 }\r
3402aac7 44\r
1bfda055 45 for (Index = 9, Index2 = 0; (Index < (Size + 9)) && (Ptr[Index] != '\0'); Index++, Index2++) {\r
46 Temp[Index2] = Ptr[Index];\r
47 if (Temp[Index2] == '/') {\r
48 Temp[Index2] = '\\' ;\r
5b792f1a 49 }\r
50\r
1bfda055 51 if (Index2 == 1) {\r
52 Temp[Index2 - 1] = Ptr[Index];\r
53 Temp[Index2] = ':';\r
5b792f1a 54 }\r
55 }\r
56\r
1bfda055 57 return Temp;\r
5b792f1a 58}\r
59\r
60\r
61/**\r
62 Performs additional actions after a PE/COFF image has been loaded and relocated.\r
63\r
64 If ImageContext is NULL, then ASSERT().\r
65\r
66 @param ImageContext Pointer to the image context structure that describes the\r
67 PE/COFF image that has already been loaded and relocated.\r
68\r
69**/\r
70VOID\r
71EFIAPI\r
72PeCoffLoaderRelocateImageExtraAction (\r
73 IN OUT PE_COFF_LOADER_IMAGE_CONTEXT *ImageContext\r
74 )\r
75{\r
3402aac7 76#if !defined(MDEPKG_NDEBUG)\r
e862cd50 77 CHAR8 Temp[512];\r
78#endif\r
1bfda055 79\r
28929e20 80 if (ImageContext->PdbPointer) {\r
5b792f1a 81#ifdef __CC_ARM\r
96a8bc11 82#if (__ARMCC_VERSION < 500000)\r
28929e20 83 // Print out the command for the RVD debugger to load symbols for this image\r
a4a582e1 84 DEBUG ((DEBUG_LOAD | DEBUG_INFO, "load /a /ni /np %a &0x%p\n", DeCygwinPathIfNeeded (ImageContext->PdbPointer, Temp, sizeof (Temp)), (UINTN)(ImageContext->ImageAddress + ImageContext->SizeOfHeaders)));\r
96a8bc11 85#else\r
28929e20 86 // Print out the command for the DS-5 to load symbols for this image\r
a4a582e1 87 DEBUG ((DEBUG_LOAD | DEBUG_INFO, "add-symbol-file %a 0x%p\n", DeCygwinPathIfNeeded (ImageContext->PdbPointer, Temp, sizeof (Temp)), (UINTN)(ImageContext->ImageAddress + ImageContext->SizeOfHeaders)));\r
96a8bc11 88#endif\r
5b792f1a 89#elif __GNUC__\r
3d34b5f3 90 // This may not work correctly if you generate PE/COFF directly as then the Offset would not be required\r
a4a582e1 91 DEBUG ((DEBUG_LOAD | DEBUG_INFO, "add-symbol-file %a 0x%p\n", DeCygwinPathIfNeeded (ImageContext->PdbPointer, Temp, sizeof (Temp)), (UINTN)(ImageContext->ImageAddress + ImageContext->SizeOfHeaders)));\r
5b792f1a 92#else\r
a4a582e1 93 DEBUG ((DEBUG_LOAD | DEBUG_INFO, "Loading driver at 0x%11p EntryPoint=0x%11p\n", (VOID *)(UINTN) ImageContext->ImageAddress, FUNCTION_ENTRY_POINT (ImageContext->EntryPoint)));\r
5b792f1a 94#endif\r
28929e20 95 } else {\r
a4a582e1 96 DEBUG ((DEBUG_LOAD | DEBUG_INFO, "Loading driver at 0x%11p EntryPoint=0x%11p\n", (VOID *)(UINTN) ImageContext->ImageAddress, FUNCTION_ENTRY_POINT (ImageContext->EntryPoint)));\r
28929e20 97 }\r
5b792f1a 98}\r
99\r
100\r
101\r
102/**\r
103 Performs additional actions just before a PE/COFF image is unloaded. Any resources\r
104 that were allocated by PeCoffLoaderRelocateImageExtraAction() must be freed.\r
3402aac7 105\r
5b792f1a 106 If ImageContext is NULL, then ASSERT().\r
3402aac7 107\r
5b792f1a 108 @param ImageContext Pointer to the image context structure that describes the\r
109 PE/COFF image that is being unloaded.\r
110\r
111**/\r
112VOID\r
113EFIAPI\r
114PeCoffLoaderUnloadImageExtraAction (\r
115 IN OUT PE_COFF_LOADER_IMAGE_CONTEXT *ImageContext\r
116 )\r
117{\r
e862cd50 118#if !defined(MDEPKG_NDEBUG)\r
1bfda055 119 CHAR8 Temp[512];\r
e862cd50 120#endif\r
3402aac7 121\r
28929e20 122 if (ImageContext->PdbPointer) {\r
5b792f1a 123#ifdef __CC_ARM\r
28929e20 124 // Print out the command for the RVD debugger to load symbols for this image\r
a6cd7fba 125 DEBUG ((DEBUG_LOAD | DEBUG_INFO, "unload symbols_only %a\n", DeCygwinPathIfNeeded (ImageContext->PdbPointer, Temp, sizeof (Temp))));\r
5b792f1a 126#elif __GNUC__\r
3d34b5f3 127 // This may not work correctly if you generate PE/COFF directly as then the Offset would not be required\r
a6cd7fba 128 DEBUG ((DEBUG_LOAD | DEBUG_INFO, "remove-symbol-file %a 0x%08x\n", DeCygwinPathIfNeeded (ImageContext->PdbPointer, Temp, sizeof (Temp)), (UINTN)(ImageContext->ImageAddress + ImageContext->SizeOfHeaders)));\r
5b792f1a 129#else\r
a6cd7fba 130 DEBUG ((DEBUG_LOAD | DEBUG_INFO, "Unloading %a\n", ImageContext->PdbPointer));\r
5b792f1a 131#endif\r
28929e20 132 } else {\r
a6cd7fba 133 DEBUG ((DEBUG_LOAD | DEBUG_INFO, "Unloading driver at 0x%11p\n", (VOID *)(UINTN) ImageContext->ImageAddress));\r
28929e20 134 }\r
5b792f1a 135}\r