]> git.proxmox.com Git - mirror_edk2.git/blame_incremental - ArmPkg/Library/RvdPeCoffExtraActionLib/RvdPeCoffExtraActionLib.c
ArmPkg: Apply uncrustify changes
[mirror_edk2.git] / ArmPkg / Library / RvdPeCoffExtraActionLib / RvdPeCoffExtraActionLib.c
... / ...
CommitLineData
1/**@file\r
2\r
3Copyright (c) 2006 - 2009, Intel Corporation. All rights reserved.<BR>\r
4Portions copyright (c) 2008 - 2010, Apple Inc. All rights reserved.<BR>\r
5Portions copyright (c) 2011 - 2012, ARM Ltd. All rights reserved.<BR>\r
6\r
7SPDX-License-Identifier: BSD-2-Clause-Patent\r
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/SemihostLib.h>\r
19#include <Library/PrintLib.h>\r
20\r
21/**\r
22 Append string to debugger script file, create file if needed.\r
23\r
24 This library can show up in multiple places so we need to append the file every time we write to it.\r
25 For example Sec can use this to load the DXE core, and the DXE core would use this to load all the\r
26 other modules. So we have two instances of the library in the system.\r
27\r
28 @param Buffer Buffer to write to file.\r
29 @param Length Length of Buffer in bytes.\r
30**/\r
31VOID\r
32WriteStringToFile (\r
33 IN VOID *Buffer,\r
34 IN UINT32 Length\r
35 )\r
36{\r
37 // Working around and issue with the code that is commented out. For now send it to the console.\r
38 // You can copy the console into a file and source the file as a script and you get symbols.\r
39 // This gets you all the symbols except for SEC. To get SEC symbols you need to copy the\r
40 // debug print in the SEC into the debugger manually\r
41 SemihostWriteString (Buffer);\r
42\r
43 /*\r
44 I'm currently having issues with this code crashing the debugger. Seems like it should work.\r
45\r
46 UINT32 SemihostHandle;\r
47 UINT32 SemihostMode = SEMIHOST_FILE_MODE_WRITE | SEMIHOST_FILE_MODE_BINARY | SEMIHOST_FILE_MODE_UPDATE;\r
48\r
49 SemihostFileOpen ("c:\rvi_symbols.inc", SemihostMode, &SemihostHandle);\r
50 SemihostFileWrite (SemihostHandle, &Length, Buffer);\r
51 SemihostFileClose (SemihostHandle);\r
52 */\r
53}\r
54\r
55/**\r
56 If the build is done on cygwin the paths are cygpaths.\r
57 /cygdrive/c/tmp.txt vs c:\tmp.txt so we need to convert\r
58 them to work with RVD commands\r
59\r
60 @param Name Path to convert if needed\r
61\r
62**/\r
63CHAR8 *\r
64DeCygwinPathIfNeeded (\r
65 IN CHAR8 *Name\r
66 )\r
67{\r
68 CHAR8 *Ptr;\r
69 UINTN Index;\r
70 UINTN Len;\r
71\r
72 Ptr = AsciiStrStr (Name, "/cygdrive/");\r
73 if (Ptr == NULL) {\r
74 return Name;\r
75 }\r
76\r
77 Len = AsciiStrLen (Ptr);\r
78\r
79 // convert "/cygdrive" to spaces\r
80 for (Index = 0; Index < 9; Index++) {\r
81 Ptr[Index] = ' ';\r
82 }\r
83\r
84 // convert /c to c:\r
85 Ptr[9] = Ptr[10];\r
86 Ptr[10] = ':';\r
87\r
88 // switch path separators\r
89 for (Index = 11; Index < Len; Index++) {\r
90 if (Ptr[Index] == '/') {\r
91 Ptr[Index] = '\\';\r
92 }\r
93 }\r
94\r
95 return Name;\r
96}\r
97\r
98/**\r
99 Performs additional actions after a PE/COFF image has been loaded and relocated.\r
100\r
101 If ImageContext is NULL, then ASSERT().\r
102\r
103 @param ImageContext Pointer to the image context structure that describes the\r
104 PE/COFF image that has already been loaded and relocated.\r
105\r
106**/\r
107VOID\r
108EFIAPI\r
109PeCoffLoaderRelocateImageExtraAction (\r
110 IN OUT PE_COFF_LOADER_IMAGE_CONTEXT *ImageContext\r
111 )\r
112{\r
113 CHAR8 Buffer[256];\r
114\r
115 #if (__ARMCC_VERSION < 500000)\r
116 AsciiSPrint (Buffer, sizeof (Buffer), "load /a /ni /np \"%a\" &0x%08x\n", ImageContext->PdbPointer, (UINTN)(ImageContext->ImageAddress + ImageContext->SizeOfHeaders));\r
117 #else\r
118 AsciiSPrint (Buffer, sizeof (Buffer), "add-symbol-file %a 0x%08x\n", ImageContext->PdbPointer, (UINTN)(ImageContext->ImageAddress + ImageContext->SizeOfHeaders));\r
119 #endif\r
120 DeCygwinPathIfNeeded (&Buffer[16]);\r
121\r
122 WriteStringToFile (Buffer, AsciiStrSize (Buffer));\r
123}\r
124\r
125/**\r
126 Performs additional actions just before a PE/COFF image is unloaded. Any resources\r
127 that were allocated by PeCoffLoaderRelocateImageExtraAction() must be freed.\r
128\r
129 If ImageContext is NULL, then ASSERT().\r
130\r
131 @param ImageContext Pointer to the image context structure that describes the\r
132 PE/COFF image that is being unloaded.\r
133\r
134**/\r
135VOID\r
136EFIAPI\r
137PeCoffLoaderUnloadImageExtraAction (\r
138 IN OUT PE_COFF_LOADER_IMAGE_CONTEXT *ImageContext\r
139 )\r
140{\r
141 CHAR8 Buffer[256];\r
142\r
143 AsciiSPrint (Buffer, sizeof (Buffer), "unload symbols_only \"%a\"\n", ImageContext->PdbPointer);\r
144 DeCygwinPathIfNeeded (Buffer);\r
145\r
146 WriteStringToFile (Buffer, AsciiStrSize (Buffer));\r
147}\r