3 Copyright (c) 2008 - 2009, Apple Inc. All rights reserved.<BR>
5 SPDX-License-Identifier: BSD-2-Clause-Patent
10 #include <Library/PeCoffGetEntryPointLib.h>
11 #include <Library/UefiLib.h>
13 #include <Guid/DebugImageInfoTable.h>
16 Use the EFI Debug Image Table to lookup the FaultAddress and find which PE/COFF image
17 it came from. As long as the PE/COFF image contains a debug directory entry a
18 string can be returned. For ELF and Mach-O images the string points to the Mach-O or ELF
19 image. Microsoft tools contain a pointer to the PDB file that contains the debug information.
21 @param FaultAddress Address to find PE/COFF image for.
22 @param ImageBase Return load address of found image
23 @param PeCoffSizeOfHeaders Return the size of the PE/COFF header for the image that was found
25 @retval NULL FaultAddress not in a loaded PE/COFF image.
26 @retval Path and file name of PE/COFF image.
31 IN UINTN FaultAddress
,
33 OUT UINTN
*PeCoffSizeOfHeaders
37 EFI_DEBUG_IMAGE_INFO_TABLE_HEADER
*DebugTableHeader
;
38 EFI_DEBUG_IMAGE_INFO
*DebugTable
;
42 Status
= EfiGetSystemConfigurationTable (&gEfiDebugImageInfoTableGuid
, (VOID
**)&DebugTableHeader
);
43 if (EFI_ERROR (Status
)) {
47 DebugTable
= DebugTableHeader
->EfiDebugImageInfoTable
;
48 if (DebugTable
== NULL
) {
52 Address
= (CHAR8
*)(UINTN
)FaultAddress
;
53 for (Entry
= 0; Entry
< DebugTableHeader
->TableSize
; Entry
++, DebugTable
++) {
54 if (DebugTable
->NormalImage
!= NULL
) {
55 if ((DebugTable
->NormalImage
->ImageInfoType
== EFI_DEBUG_IMAGE_INFO_TYPE_NORMAL
) &&
56 (DebugTable
->NormalImage
->LoadedImageProtocolInstance
!= NULL
)) {
57 if ((Address
>= (CHAR8
*)DebugTable
->NormalImage
->LoadedImageProtocolInstance
->ImageBase
) &&
58 (Address
<= ((CHAR8
*)DebugTable
->NormalImage
->LoadedImageProtocolInstance
->ImageBase
+ DebugTable
->NormalImage
->LoadedImageProtocolInstance
->ImageSize
))) {
59 *ImageBase
= (UINTN
)DebugTable
->NormalImage
->LoadedImageProtocolInstance
->ImageBase
;
60 *PeCoffSizeOfHeaders
= PeCoffGetSizeOfHeaders ((VOID
*)(UINTN
)*ImageBase
);
61 return PeCoffLoaderGetPdbPointer (DebugTable
->NormalImage
->LoadedImageProtocolInstance
->ImageBase
);