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