3 Copyright (c) 2008 - 2009, 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
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.
16 #include <Library/PeCoffGetEntryPointLib.h>
17 #include <Library/UefiLib.h>
19 #include <Guid/DebugImageInfoTable.h>
22 Use the EFI Debug Image Table to lookup the FaultAddress and find which PE/COFF image
23 it came from. As long as the PE/COFF image contains a debug directory entry a
24 string can be returned. For ELF and Mach-O images the string points to the Mach-O or ELF
25 image. Microsoft tools contain a pointer to the PDB file that contains the debug information.
27 @param FaultAddress Address to find PE/COFF image for.
28 @param ImageBase Return load address of found image
29 @param PeCoffSizeOfHeaders Return the size of the PE/COFF header for the image that was found
31 @retval NULL FaultAddress not in a loaded PE/COFF image.
32 @retval Path and file name of PE/COFF image.
37 IN UINTN FaultAddress
,
39 OUT UINTN
*PeCoffSizeOfHeaders
43 EFI_DEBUG_IMAGE_INFO_TABLE_HEADER
*DebugTableHeader
;
44 EFI_DEBUG_IMAGE_INFO
*DebugTable
;
48 Status
= EfiGetSystemConfigurationTable (&gEfiDebugImageInfoTableGuid
, (VOID
**)&DebugTableHeader
);
49 if (EFI_ERROR (Status
)) {
53 DebugTable
= DebugTableHeader
->EfiDebugImageInfoTable
;
54 if (DebugTable
== NULL
) {
58 Address
= (CHAR8
*)(UINTN
)FaultAddress
;
59 for (Entry
= 0; Entry
< DebugTableHeader
->TableSize
; Entry
++, DebugTable
++) {
60 if (DebugTable
->NormalImage
!= NULL
) {
61 if ((DebugTable
->NormalImage
->ImageInfoType
== EFI_DEBUG_IMAGE_INFO_TYPE_NORMAL
) &&
62 (DebugTable
->NormalImage
->LoadedImageProtocolInstance
!= NULL
)) {
63 if ((Address
>= (CHAR8
*)DebugTable
->NormalImage
->LoadedImageProtocolInstance
->ImageBase
) &&
64 (Address
<= ((CHAR8
*)DebugTable
->NormalImage
->LoadedImageProtocolInstance
->ImageBase
+ DebugTable
->NormalImage
->LoadedImageProtocolInstance
->ImageSize
))) {
65 *ImageBase
= (UINTN
)DebugTable
->NormalImage
->LoadedImageProtocolInstance
->ImageBase
;
66 *PeCoffSizeOfHeaders
= PeCoffGetSizeOfHeaders ((VOID
*)(UINTN
)*ImageBase
);
67 return PeCoffLoaderGetPdbPointer (DebugTable
->NormalImage
->LoadedImageProtocolInstance
->ImageBase
);