]>
Commit | Line | Data |
---|---|---|
62e797a4 A |
1 | /**@file\r |
2 | \r | |
d6ebcab7 HT |
3 | Copyright (c) 2006 - 2009, Intel Corporation. All rights reserved.<BR>\r |
4 | Portions copyright (c) 2008 - 2010, Apple Inc. All rights reserved.<BR>\r | |
96a8bc11 | 5 | Portions copyright (c) 2011 - 2012, ARM Ltd. All rights reserved.<BR>\r |
6 | \r | |
d6ebcab7 | 7 | This program and the accompanying materials\r |
62e797a4 A |
8 | are licensed and made available under the terms and conditions of the BSD License\r |
9 | which accompanies this distribution. The full text of the license may be found at\r | |
10 | http://opensource.org/licenses/bsd-license.php\r | |
11 | \r | |
12 | THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r | |
13 | WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r | |
14 | \r | |
62e797a4 A |
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 | |
225290eb | 24 | #include <Library/SemihostLib.h>\r |
62e797a4 A |
25 | #include <Library/PrintLib.h>\r |
26 | \r | |
225290eb | 27 | /**\r |
3402aac7 | 28 | Append string to debugger script file, create file if needed.\r |
225290eb A |
29 | \r |
30 | This library can show up in mulitple places so we need to append the file every time we write to it.\r | |
31 | For example Sec can use this to load the DXE core, and the DXE core would use this to load all the\r | |
32 | other modules. So we have two instances of the library in the system.\r | |
62e797a4 | 33 | \r |
225290eb A |
34 | @param Buffer Buffer to write to file.\r |
35 | @param Length Length of Buffer in bytes.\r | |
36 | **/\r | |
62e797a4 | 37 | VOID\r |
225290eb A |
38 | WriteStringToFile (\r |
39 | IN VOID *Buffer,\r | |
40 | IN UINT32 Length\r | |
41 | )\r | |
42 | {\r | |
43 | // Working around and issue with the code that is commented out. For now send it to the console.\r | |
3402aac7 RC |
44 | // You can copy the console into a file and source the file as a script and you get symbols.\r |
45 | // This gets you all the symbols except for SEC. To get SEC symbols you need to copy the\r | |
225290eb A |
46 | // debug print in the SEC into the debugger manually\r |
47 | SemihostWriteString (Buffer);\r | |
48 | /*\r | |
49 | I'm currently having issues with this code crashing the debugger. Seems like it should work.\r | |
50 | \r | |
51 | UINT32 SemihostHandle;\r | |
c20f8ec6 | 52 | UINT32 SemihostMode = SEMIHOST_FILE_MODE_WRITE | SEMIHOST_FILE_MODE_BINARY | SEMIHOST_FILE_MODE_UPDATE;\r |
225290eb A |
53 | \r |
54 | SemihostFileOpen ("c:\rvi_symbols.inc", SemihostMode, &SemihostHandle);\r | |
55 | SemihostFileWrite (SemihostHandle, &Length, Buffer);\r | |
56 | SemihostFileClose (SemihostHandle);\r | |
57 | */\r | |
58 | }\r | |
59 | \r | |
60 | \r | |
61 | /**\r | |
3402aac7 | 62 | If the build is done on cygwin the paths are cygpaths.\r |
225290eb A |
63 | /cygdrive/c/tmp.txt vs c:\tmp.txt so we need to convert\r |
64 | them to work with RVD commands\r | |
65 | \r | |
66 | @param Name Path to convert if needed\r | |
67 | \r | |
68 | **/\r | |
69 | CHAR8 *\r | |
70 | DeCygwinPathIfNeeded (\r | |
62e797a4 A |
71 | IN CHAR8 *Name\r |
72 | )\r | |
73 | {\r | |
74 | CHAR8 *Ptr;\r | |
75 | UINTN Index;\r | |
76 | UINTN Len;\r | |
3402aac7 | 77 | \r |
62e797a4 A |
78 | Ptr = AsciiStrStr (Name, "/cygdrive/");\r |
79 | if (Ptr == NULL) {\r | |
225290eb | 80 | return Name;\r |
62e797a4 | 81 | }\r |
3402aac7 | 82 | \r |
62e797a4 | 83 | Len = AsciiStrLen (Ptr);\r |
3402aac7 | 84 | \r |
62e797a4 A |
85 | // convert "/cygdrive" to spaces\r |
86 | for (Index = 0; Index < 9; Index++) {\r | |
87 | Ptr[Index] = ' ';\r | |
88 | }\r | |
89 | \r | |
90 | // convert /c to c:\r | |
91 | Ptr[9] = Ptr[10];\r | |
92 | Ptr[10] = ':';\r | |
3402aac7 | 93 | \r |
11c20f4e | 94 | // switch path separators\r |
62e797a4 A |
95 | for (Index = 11; Index < Len; Index++) {\r |
96 | if (Ptr[Index] == '/') {\r | |
97 | Ptr[Index] = '\\' ;\r | |
98 | }\r | |
99 | }\r | |
225290eb A |
100 | \r |
101 | return Name;\r | |
62e797a4 A |
102 | }\r |
103 | \r | |
104 | \r | |
105 | /**\r | |
106 | Performs additional actions after a PE/COFF image has been loaded and relocated.\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 has already been loaded and relocated.\r | |
112 | \r | |
113 | **/\r | |
114 | VOID\r | |
115 | EFIAPI\r | |
116 | PeCoffLoaderRelocateImageExtraAction (\r | |
117 | IN OUT PE_COFF_LOADER_IMAGE_CONTEXT *ImageContext\r | |
118 | )\r | |
119 | {\r | |
120 | CHAR8 Buffer[256];\r | |
3402aac7 | 121 | \r |
96a8bc11 | 122 | #if (__ARMCC_VERSION < 500000)\r |
3d4c7abc | 123 | AsciiSPrint (Buffer, sizeof(Buffer), "load /a /ni /np \"%a\" &0x%08x\n", ImageContext->PdbPointer, (UINTN)(ImageContext->ImageAddress + ImageContext->SizeOfHeaders));\r |
96a8bc11 | 124 | #else\r |
125 | AsciiSPrint (Buffer, sizeof(Buffer), "add-symbol-file %a 0x%08x\n", ImageContext->PdbPointer, (UINTN)(ImageContext->ImageAddress + ImageContext->SizeOfHeaders));\r | |
126 | #endif\r | |
225290eb | 127 | DeCygwinPathIfNeeded (&Buffer[16]);\r |
3402aac7 | 128 | \r |
225290eb | 129 | WriteStringToFile (Buffer, AsciiStrSize (Buffer));\r |
62e797a4 A |
130 | }\r |
131 | \r | |
132 | \r | |
133 | \r | |
134 | /**\r | |
135 | Performs additional actions just before a PE/COFF image is unloaded. Any resources\r | |
136 | that were allocated by PeCoffLoaderRelocateImageExtraAction() must be freed.\r | |
3402aac7 | 137 | \r |
62e797a4 | 138 | If ImageContext is NULL, then ASSERT().\r |
3402aac7 | 139 | \r |
62e797a4 A |
140 | @param ImageContext Pointer to the image context structure that describes the\r |
141 | PE/COFF image that is being unloaded.\r | |
142 | \r | |
143 | **/\r | |
144 | VOID\r | |
145 | EFIAPI\r | |
146 | PeCoffLoaderUnloadImageExtraAction (\r | |
147 | IN OUT PE_COFF_LOADER_IMAGE_CONTEXT *ImageContext\r | |
148 | )\r | |
149 | {\r | |
150 | CHAR8 Buffer[256];\r | |
3402aac7 | 151 | \r |
3d4c7abc | 152 | AsciiSPrint (Buffer, sizeof(Buffer), "unload symbols_only \"%a\"\n", ImageContext->PdbPointer);\r |
225290eb | 153 | DeCygwinPathIfNeeded (Buffer);\r |
3402aac7 | 154 | \r |
225290eb | 155 | WriteStringToFile (Buffer, AsciiStrSize (Buffer));\r |
62e797a4 | 156 | }\r |