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 SPDX-License-Identifier: BSD-2-Clause-Patent
12 #include <Library/PeCoffLib.h>
14 #include <Library/BaseLib.h>
15 #include <Library/DebugLib.h>
16 #include <Library/BaseMemoryLib.h>
17 #include <Library/PeCoffExtraActionLib.h>
18 #include <Library/PrintLib.h>
21 If the build is done on cygwin the paths are cygpaths.
22 /cygdrive/c/tmp.txt vs c:\tmp.txt so we need to convert
23 them to work with RVD commands
25 @param Name Path to convert if needed
29 DeCygwinPathIfNeeded (
39 Ptr
= AsciiStrStr (Name
, "/cygdrive/");
44 for (Index
= 9, Index2
= 0; (Index
< (Size
+ 9)) && (Ptr
[Index
] != '\0'); Index
++, Index2
++) {
45 Temp
[Index2
] = Ptr
[Index
];
46 if (Temp
[Index2
] == '/') {
51 Temp
[Index2
- 1] = Ptr
[Index
];
60 Performs additional actions after a PE/COFF image has been loaded and relocated.
62 If ImageContext is NULL, then ASSERT().
64 @param ImageContext Pointer to the image context structure that describes the
65 PE/COFF image that has already been loaded and relocated.
70 PeCoffLoaderRelocateImageExtraAction (
71 IN OUT PE_COFF_LOADER_IMAGE_CONTEXT
*ImageContext
74 #if !defined (MDEPKG_NDEBUG)
78 if (ImageContext
->PdbPointer
) {
80 // Print out the command for the DS-5 to load symbols for this image
81 DEBUG ((DEBUG_LOAD
| DEBUG_INFO
, "add-symbol-file %a 0x%p\n", DeCygwinPathIfNeeded (ImageContext
->PdbPointer
, Temp
, sizeof (Temp
)), (UINTN
)(ImageContext
->ImageAddress
+ ImageContext
->SizeOfHeaders
)));
83 // This may not work correctly if you generate PE/COFF directly as then the Offset would not be required
84 DEBUG ((DEBUG_LOAD
| DEBUG_INFO
, "add-symbol-file %a 0x%p\n", DeCygwinPathIfNeeded (ImageContext
->PdbPointer
, Temp
, sizeof (Temp
)), (UINTN
)(ImageContext
->ImageAddress
+ ImageContext
->SizeOfHeaders
)));
86 DEBUG ((DEBUG_LOAD
| DEBUG_INFO
, "Loading driver at 0x%11p EntryPoint=0x%11p\n", (VOID
*)(UINTN
)ImageContext
->ImageAddress
, FUNCTION_ENTRY_POINT (ImageContext
->EntryPoint
)));
89 DEBUG ((DEBUG_LOAD
| DEBUG_INFO
, "Loading driver at 0x%11p EntryPoint=0x%11p\n", (VOID
*)(UINTN
)ImageContext
->ImageAddress
, FUNCTION_ENTRY_POINT (ImageContext
->EntryPoint
)));
94 Performs additional actions just before a PE/COFF image is unloaded. Any resources
95 that were allocated by PeCoffLoaderRelocateImageExtraAction() must be freed.
97 If ImageContext is NULL, then ASSERT().
99 @param ImageContext Pointer to the image context structure that describes the
100 PE/COFF image that is being unloaded.
105 PeCoffLoaderUnloadImageExtraAction (
106 IN OUT PE_COFF_LOADER_IMAGE_CONTEXT
*ImageContext
109 #if !defined (MDEPKG_NDEBUG)
113 if (ImageContext
->PdbPointer
) {
115 // Print out the command for the RVD debugger to load symbols for this image
116 DEBUG ((DEBUG_LOAD
| DEBUG_INFO
, "unload symbols_only %a\n", DeCygwinPathIfNeeded (ImageContext
->PdbPointer
, Temp
, sizeof (Temp
))));
118 // This may not work correctly if you generate PE/COFF directly as then the Offset would not be required
119 DEBUG ((DEBUG_LOAD
| DEBUG_INFO
, "remove-symbol-file %a 0x%08x\n", DeCygwinPathIfNeeded (ImageContext
->PdbPointer
, Temp
, sizeof (Temp
)), (UINTN
)(ImageContext
->ImageAddress
+ ImageContext
->SizeOfHeaders
)));
121 DEBUG ((DEBUG_LOAD
| DEBUG_INFO
, "Unloading %a\n", ImageContext
->PdbPointer
));
124 DEBUG ((DEBUG_LOAD
| DEBUG_INFO
, "Unloading driver at 0x%11p\n", (VOID
*)(UINTN
)ImageContext
->ImageAddress
));