3 Copyright (c) 2006 - 2009, Intel Corporation. All rights reserved.<BR>
4 Portions copyright (c) 2008 - 2010, Apple Inc. All rights reserved.<BR>
5 Portions copyright (c) 2011 - 2012, ARM Ltd. All rights reserved.<BR>
7 This program and the accompanying materials
8 are licensed and made available under the terms and conditions of the BSD License
9 which accompanies this distribution. The full text of the license may be found at
10 http://opensource.org/licenses/bsd-license.php
12 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
13 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
18 #include <Library/PeCoffLib.h>
20 #include <Library/BaseLib.h>
21 #include <Library/DebugLib.h>
22 #include <Library/BaseMemoryLib.h>
23 #include <Library/PeCoffExtraActionLib.h>
24 #include <Library/SemihostLib.h>
25 #include <Library/PrintLib.h>
28 Append string to debugger script file, create file if needed.
30 This library can show up in mulitple places so we need to append the file every time we write to it.
31 For example Sec can use this to load the DXE core, and the DXE core would use this to load all the
32 other modules. So we have two instances of the library in the system.
34 @param Buffer Buffer to write to file.
35 @param Length Length of Buffer in bytes.
43 // Working around and issue with the code that is commented out. For now send it to the console.
44 // You can copy the console into a file and source the file as a script and you get symbols.
45 // This gets you all the symbols except for SEC. To get SEC symbols you need to copy the
46 // debug print in the SEC into the debugger manually
47 SemihostWriteString (Buffer
);
49 I'm currently having issues with this code crashing the debugger. Seems like it should work.
51 UINT32 SemihostHandle;
52 UINT32 SemihostMode = SEMIHOST_FILE_MODE_WRITE | SEMIHOST_FILE_MODE_BINARY | SEMIHOST_FILE_MODE_CREATE;
54 SemihostFileOpen ("c:\rvi_symbols.inc", SemihostMode, &SemihostHandle);
55 SemihostFileWrite (SemihostHandle, &Length, Buffer);
56 SemihostFileClose (SemihostHandle);
62 If the build is done on cygwin the paths are cygpaths.
63 /cygdrive/c/tmp.txt vs c:\tmp.txt so we need to convert
64 them to work with RVD commands
66 @param Name Path to convert if needed
70 DeCygwinPathIfNeeded (
78 Ptr
= AsciiStrStr (Name
, "/cygdrive/");
83 Len
= AsciiStrLen (Ptr
);
85 // convert "/cygdrive" to spaces
86 for (Index
= 0; Index
< 9; Index
++) {
94 // switch path separators
95 for (Index
= 11; Index
< Len
; Index
++) {
96 if (Ptr
[Index
] == '/') {
106 Performs additional actions after a PE/COFF image has been loaded and relocated.
108 If ImageContext is NULL, then ASSERT().
110 @param ImageContext Pointer to the image context structure that describes the
111 PE/COFF image that has already been loaded and relocated.
116 PeCoffLoaderRelocateImageExtraAction (
117 IN OUT PE_COFF_LOADER_IMAGE_CONTEXT
*ImageContext
122 #if (__ARMCC_VERSION < 500000)
123 AsciiSPrint (Buffer
, sizeof(Buffer
), "load /a /ni /np \"%a\" &0x%08x\n", ImageContext
->PdbPointer
, (UINTN
)(ImageContext
->ImageAddress
+ ImageContext
->SizeOfHeaders
));
125 AsciiSPrint (Buffer
, sizeof(Buffer
), "add-symbol-file %a 0x%08x\n", ImageContext
->PdbPointer
, (UINTN
)(ImageContext
->ImageAddress
+ ImageContext
->SizeOfHeaders
));
127 DeCygwinPathIfNeeded (&Buffer
[16]);
129 WriteStringToFile (Buffer
, AsciiStrSize (Buffer
));
135 Performs additional actions just before a PE/COFF image is unloaded. Any resources
136 that were allocated by PeCoffLoaderRelocateImageExtraAction() must be freed.
138 If ImageContext is NULL, then ASSERT().
140 @param ImageContext Pointer to the image context structure that describes the
141 PE/COFF image that is being unloaded.
146 PeCoffLoaderUnloadImageExtraAction (
147 IN OUT PE_COFF_LOADER_IMAGE_CONTEXT
*ImageContext
152 AsciiSPrint (Buffer
, sizeof(Buffer
), "unload symbols_only \"%a\"\n", ImageContext
->PdbPointer
);
153 DeCygwinPathIfNeeded (Buffer
);
155 WriteStringToFile (Buffer
, AsciiStrSize (Buffer
));