]> git.proxmox.com Git - mirror_edk2.git/blame - ArmPkg/Library/RvdPeCoffExtraActionLib/RvdPeCoffExtraActionLib.c
ArmPkg: Apply uncrustify changes
[mirror_edk2.git] / ArmPkg / Library / RvdPeCoffExtraActionLib / RvdPeCoffExtraActionLib.c
CommitLineData
62e797a4
A
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
62e797a4 8\r
62e797a4
A
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
225290eb 18#include <Library/SemihostLib.h>\r
62e797a4
A
19#include <Library/PrintLib.h>\r
20\r
225290eb 21/**\r
3402aac7 22 Append string to debugger script file, create file if needed.\r
225290eb 23\r
ff5fef14 24 This library can show up in multiple places so we need to append the file every time we write to it.\r
225290eb
A
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
62e797a4 27\r
225290eb
A
28 @param Buffer Buffer to write to file.\r
29 @param Length Length of Buffer in bytes.\r
30**/\r
62e797a4 31VOID\r
225290eb
A
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
3402aac7
RC
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
225290eb
A
40 // debug print in the SEC into the debugger manually\r
41 SemihostWriteString (Buffer);\r
225290eb 42\r
429309e0
MK
43 /*\r
44 I'm currently having issues with this code crashing the debugger. Seems like it should work.\r
225290eb 45\r
429309e0
MK
46 UINT32 SemihostHandle;\r
47 UINT32 SemihostMode = SEMIHOST_FILE_MODE_WRITE | SEMIHOST_FILE_MODE_BINARY | SEMIHOST_FILE_MODE_UPDATE;\r
225290eb 48\r
429309e0
MK
49 SemihostFileOpen ("c:\rvi_symbols.inc", SemihostMode, &SemihostHandle);\r
50 SemihostFileWrite (SemihostHandle, &Length, Buffer);\r
51 SemihostFileClose (SemihostHandle);\r
52 */\r
53}\r
225290eb
A
54\r
55/**\r
3402aac7 56 If the build is done on cygwin the paths are cygpaths.\r
225290eb
A
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
429309e0 65 IN CHAR8 *Name\r
62e797a4
A
66 )\r
67{\r
429309e0
MK
68 CHAR8 *Ptr;\r
69 UINTN Index;\r
70 UINTN Len;\r
3402aac7 71\r
62e797a4
A
72 Ptr = AsciiStrStr (Name, "/cygdrive/");\r
73 if (Ptr == NULL) {\r
225290eb 74 return Name;\r
62e797a4 75 }\r
3402aac7 76\r
62e797a4 77 Len = AsciiStrLen (Ptr);\r
3402aac7 78\r
62e797a4
A
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
3402aac7 87\r
11c20f4e 88 // switch path separators\r
62e797a4
A
89 for (Index = 11; Index < Len; Index++) {\r
90 if (Ptr[Index] == '/') {\r
429309e0 91 Ptr[Index] = '\\';\r
62e797a4
A
92 }\r
93 }\r
225290eb
A
94\r
95 return Name;\r
62e797a4
A
96}\r
97\r
62e797a4
A
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
429309e0 113 CHAR8 Buffer[256];\r
3402aac7 114\r
429309e0
MK
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
225290eb 120 DeCygwinPathIfNeeded (&Buffer[16]);\r
3402aac7 121\r
225290eb 122 WriteStringToFile (Buffer, AsciiStrSize (Buffer));\r
62e797a4
A
123}\r
124\r
62e797a4
A
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
3402aac7 128\r
62e797a4 129 If ImageContext is NULL, then ASSERT().\r
3402aac7 130\r
62e797a4
A
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
429309e0 141 CHAR8 Buffer[256];\r
3402aac7 142\r
429309e0 143 AsciiSPrint (Buffer, sizeof (Buffer), "unload symbols_only \"%a\"\n", ImageContext->PdbPointer);\r
225290eb 144 DeCygwinPathIfNeeded (Buffer);\r
3402aac7 145\r
225290eb 146 WriteStringToFile (Buffer, AsciiStrSize (Buffer));\r
62e797a4 147}\r