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