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