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