]> git.proxmox.com Git - mirror_edk2.git/blob - ArmPkg/Library/DebugPeCoffExtraActionLib/DebugPeCoffExtraActionLib.c
ArmPkg: Change use of EFI_D_* to DEBUG_*
[mirror_edk2.git] / ArmPkg / Library / DebugPeCoffExtraActionLib / DebugPeCoffExtraActionLib.c
1 /**@file
2
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>
6
7 SPDX-License-Identifier: BSD-2-Clause-Patent
8
9 **/
10
11 #include <PiDxe.h>
12 #include <Library/PeCoffLib.h>
13
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>
19
20
21 /**
22 If the build is done on cygwin the paths are cygpaths.
23 /cygdrive/c/tmp.txt vs c:\tmp.txt so we need to convert
24 them to work with RVD commands
25
26 @param Name Path to convert if needed
27
28 **/
29 CHAR8 *
30 DeCygwinPathIfNeeded (
31 IN CHAR8 *Name,
32 IN CHAR8 *Temp,
33 IN UINTN Size
34 )
35 {
36 CHAR8 *Ptr;
37 UINTN Index;
38 UINTN Index2;
39
40 Ptr = AsciiStrStr (Name, "/cygdrive/");
41 if (Ptr == NULL) {
42 return Name;
43 }
44
45 for (Index = 9, Index2 = 0; (Index < (Size + 9)) && (Ptr[Index] != '\0'); Index++, Index2++) {
46 Temp[Index2] = Ptr[Index];
47 if (Temp[Index2] == '/') {
48 Temp[Index2] = '\\' ;
49 }
50
51 if (Index2 == 1) {
52 Temp[Index2 - 1] = Ptr[Index];
53 Temp[Index2] = ':';
54 }
55 }
56
57 return Temp;
58 }
59
60
61 /**
62 Performs additional actions after a PE/COFF image has been loaded and relocated.
63
64 If ImageContext is NULL, then ASSERT().
65
66 @param ImageContext Pointer to the image context structure that describes the
67 PE/COFF image that has already been loaded and relocated.
68
69 **/
70 VOID
71 EFIAPI
72 PeCoffLoaderRelocateImageExtraAction (
73 IN OUT PE_COFF_LOADER_IMAGE_CONTEXT *ImageContext
74 )
75 {
76 #if !defined(MDEPKG_NDEBUG)
77 CHAR8 Temp[512];
78 #endif
79
80 if (ImageContext->PdbPointer) {
81 #ifdef __CC_ARM
82 #if (__ARMCC_VERSION < 500000)
83 // Print out the command for the RVD debugger to load symbols for this image
84 DEBUG ((DEBUG_LOAD | DEBUG_INFO, "load /a /ni /np %a &0x%p\n", DeCygwinPathIfNeeded (ImageContext->PdbPointer, Temp, sizeof (Temp)), (UINTN)(ImageContext->ImageAddress + ImageContext->SizeOfHeaders)));
85 #else
86 // Print out the command for the DS-5 to load symbols for this image
87 DEBUG ((DEBUG_LOAD | DEBUG_INFO, "add-symbol-file %a 0x%p\n", DeCygwinPathIfNeeded (ImageContext->PdbPointer, Temp, sizeof (Temp)), (UINTN)(ImageContext->ImageAddress + ImageContext->SizeOfHeaders)));
88 #endif
89 #elif __GNUC__
90 // This may not work correctly if you generate PE/COFF directly as then the Offset would not be required
91 DEBUG ((DEBUG_LOAD | DEBUG_INFO, "add-symbol-file %a 0x%p\n", DeCygwinPathIfNeeded (ImageContext->PdbPointer, Temp, sizeof (Temp)), (UINTN)(ImageContext->ImageAddress + ImageContext->SizeOfHeaders)));
92 #else
93 DEBUG ((DEBUG_LOAD | DEBUG_INFO, "Loading driver at 0x%11p EntryPoint=0x%11p\n", (VOID *)(UINTN) ImageContext->ImageAddress, FUNCTION_ENTRY_POINT (ImageContext->EntryPoint)));
94 #endif
95 } else {
96 DEBUG ((DEBUG_LOAD | DEBUG_INFO, "Loading driver at 0x%11p EntryPoint=0x%11p\n", (VOID *)(UINTN) ImageContext->ImageAddress, FUNCTION_ENTRY_POINT (ImageContext->EntryPoint)));
97 }
98 }
99
100
101
102 /**
103 Performs additional actions just before a PE/COFF image is unloaded. Any resources
104 that were allocated by PeCoffLoaderRelocateImageExtraAction() must be freed.
105
106 If ImageContext is NULL, then ASSERT().
107
108 @param ImageContext Pointer to the image context structure that describes the
109 PE/COFF image that is being unloaded.
110
111 **/
112 VOID
113 EFIAPI
114 PeCoffLoaderUnloadImageExtraAction (
115 IN OUT PE_COFF_LOADER_IMAGE_CONTEXT *ImageContext
116 )
117 {
118 #if !defined(MDEPKG_NDEBUG)
119 CHAR8 Temp[512];
120 #endif
121
122 if (ImageContext->PdbPointer) {
123 #ifdef __CC_ARM
124 // Print out the command for the RVD debugger to load symbols for this image
125 DEBUG ((DEBUG_LOAD | DEBUG_INFO, "unload symbols_only %a\n", DeCygwinPathIfNeeded (ImageContext->PdbPointer, Temp, sizeof (Temp))));
126 #elif __GNUC__
127 // This may not work correctly if you generate PE/COFF directly as then the Offset would not be required
128 DEBUG ((DEBUG_LOAD | DEBUG_INFO, "remove-symbol-file %a 0x%08x\n", DeCygwinPathIfNeeded (ImageContext->PdbPointer, Temp, sizeof (Temp)), (UINTN)(ImageContext->ImageAddress + ImageContext->SizeOfHeaders)));
129 #else
130 DEBUG ((DEBUG_LOAD | DEBUG_INFO, "Unloading %a\n", ImageContext->PdbPointer));
131 #endif
132 } else {
133 DEBUG ((DEBUG_LOAD | DEBUG_INFO, "Unloading driver at 0x%11p\n", (VOID *)(UINTN) ImageContext->ImageAddress));
134 }
135 }