]> git.proxmox.com Git - mirror_edk2.git/blob - ArmPkg/Library/DebugPeCoffExtraActionLib/DebugPeCoffExtraActionLib.c
Sync up ArmPkg with patch from mailing list. Changed name of BdsLib.h to BdsUnixLib...
[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 This program and the accompanying materials
6 are licensed and made available under the terms and conditions of the BSD License
7 which accompanies this distribution. The full text of the license may be found at
8 http://opensource.org/licenses/bsd-license.php
9
10 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
11 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
12
13 **/
14
15 #include <PiDxe.h>
16 #include <Library/PeCoffLib.h>
17
18 #include <Library/BaseLib.h>
19 #include <Library/DebugLib.h>
20 #include <Library/BaseMemoryLib.h>
21 #include <Library/PeCoffExtraActionLib.h>
22 #include <Library/PrintLib.h>
23
24
25 /**
26 If the build is done on cygwin the paths are cygpaths.
27 /cygdrive/c/tmp.txt vs c:\tmp.txt so we need to convert
28 them to work with RVD commands
29
30 @param Name Path to convert if needed
31
32 **/
33 CHAR8 *
34 DeCygwinPathIfNeeded (
35 IN CHAR8 *Name,
36 IN CHAR8 *Temp,
37 IN UINTN Size
38 )
39 {
40 CHAR8 *Ptr;
41 UINTN Index;
42 UINTN Index2;
43
44 Ptr = AsciiStrStr (Name, "/cygdrive/");
45 if (Ptr == NULL) {
46 return Name;
47 }
48
49 for (Index = 9, Index2 = 0; (Index < (Size + 9)) && (Ptr[Index] != '\0'); Index++, Index2++) {
50 Temp[Index2] = Ptr[Index];
51 if (Temp[Index2] == '/') {
52 Temp[Index2] = '\\' ;
53 }
54
55 if (Index2 == 1) {
56 Temp[Index2 - 1] = Ptr[Index];
57 Temp[Index2] = ':';
58 }
59 }
60
61 return Temp;
62 }
63
64
65 /**
66 Performs additional actions after a PE/COFF image has been loaded and relocated.
67
68 If ImageContext is NULL, then ASSERT().
69
70 @param ImageContext Pointer to the image context structure that describes the
71 PE/COFF image that has already been loaded and relocated.
72
73 **/
74 VOID
75 EFIAPI
76 PeCoffLoaderRelocateImageExtraAction (
77 IN OUT PE_COFF_LOADER_IMAGE_CONTEXT *ImageContext
78 )
79 {
80 CHAR8 Temp[512];
81
82 #ifdef __CC_ARM
83 // Print out the command for the RVD debugger to load symbols for this image
84 DEBUG ((EFI_D_ERROR, "load /a /ni /np %a &0x%08x\n", DeCygwinPathIfNeeded (ImageContext->PdbPointer, Temp, sizeof (Temp)), (UINTN)(ImageContext->ImageAddress + ImageContext->SizeOfHeaders)));
85 #elif __GNUC__
86 // This may not work correctly if you generate PE/COFF directlyas then the Offset would not be required
87 DEBUG ((EFI_D_ERROR, "add-symbol-file %a 0x%08x\n", DeCygwinPathIfNeeded (ImageContext->PdbPointer, Temp, sizeof (Temp)), (UINTN)(ImageContext->ImageAddress + ImageContext->SizeOfHeaders)));
88 #else
89 DEBUG ((EFI_D_ERROR, "Loading driver at 0x%11p EntryPoint=0x%11p ", (VOID *)(UINTN) ImageContext->ImageAddress, FUNCTION_ENTRY_POINT (ImageContext->EntryPoint)));
90 #endif
91 }
92
93
94
95 /**
96 Performs additional actions just before a PE/COFF image is unloaded. Any resources
97 that were allocated by PeCoffLoaderRelocateImageExtraAction() must be freed.
98
99 If ImageContext is NULL, then ASSERT().
100
101 @param ImageContext Pointer to the image context structure that describes the
102 PE/COFF image that is being unloaded.
103
104 **/
105 VOID
106 EFIAPI
107 PeCoffLoaderUnloadImageExtraAction (
108 IN OUT PE_COFF_LOADER_IMAGE_CONTEXT *ImageContext
109 )
110 {
111 CHAR8 Temp[512];
112
113 #ifdef __CC_ARM
114 {
115 // Print out the command for the RVD debugger to load symbols for this image
116 DEBUG ((EFI_D_ERROR, "unload symbols_only %a", DeCygwinPathIfNeeded (ImageContext->PdbPointer, Temp, sizeof (Temp))));
117 }
118 #elif __GNUC__
119 // This may not work correctly if you generate PE/COFF directlyas then the Offset would not be required
120 DEBUG ((EFI_D_ERROR, "remove-symbol-file %a 0x%08x\n", DeCygwinPathIfNeeded (ImageContext->PdbPointer, Temp, sizeof (Temp)), (UINTN)(ImageContext->ImageAddress + ImageContext->SizeOfHeaders)));
121 #else
122 DEBUG ((EFI_D_ERROR, "Unloading %a", ImageContext->PdbPointer));
123 #endif
124 }