]>
Commit | Line | Data |
---|---|---|
619b3998 | 1 | /** @file\r |
2 | \r | |
3 | Copyright (c) 2008 - 2009, Apple Inc. All rights reserved.<BR>\r | |
4 | \r | |
4059386c | 5 | SPDX-License-Identifier: BSD-2-Clause-Patent\r |
619b3998 | 6 | \r |
7 | **/\r | |
8 | \r | |
9 | #include <Uefi.h>\r | |
10 | #include <Library/PeCoffGetEntryPointLib.h>\r | |
11 | #include <Library/UefiLib.h>\r | |
12 | \r | |
13 | #include <Guid/DebugImageInfoTable.h>\r | |
14 | \r | |
619b3998 | 15 | /**\r |
16 | Use the EFI Debug Image Table to lookup the FaultAddress and find which PE/COFF image\r | |
17 | it came from. As long as the PE/COFF image contains a debug directory entry a\r | |
18 | string can be returned. For ELF and Mach-O images the string points to the Mach-O or ELF\r | |
19 | image. Microsoft tools contain a pointer to the PDB file that contains the debug information.\r | |
20 | \r | |
21 | @param FaultAddress Address to find PE/COFF image for.\r | |
22 | @param ImageBase Return load address of found image\r | |
23 | @param PeCoffSizeOfHeaders Return the size of the PE/COFF header for the image that was found\r | |
24 | \r | |
25 | @retval NULL FaultAddress not in a loaded PE/COFF image.\r | |
26 | @retval Path and file name of PE/COFF image.\r | |
27 | \r | |
28 | **/\r | |
29 | CHAR8 *\r | |
30 | GetImageName (\r | |
c63626b7 | 31 | IN UINTN FaultAddress,\r |
32 | OUT UINTN *ImageBase,\r | |
33 | OUT UINTN *PeCoffSizeOfHeaders\r | |
619b3998 | 34 | )\r |
35 | {\r | |
82ea9a6b EC |
36 | EFI_STATUS Status;\r |
37 | EFI_DEBUG_IMAGE_INFO_TABLE_HEADER *DebugTableHeader;\r | |
38 | EFI_DEBUG_IMAGE_INFO *DebugTable;\r | |
39 | UINTN Entry;\r | |
40 | CHAR8 *Address;\r | |
41 | \r | |
42 | Status = EfiGetSystemConfigurationTable (&gEfiDebugImageInfoTableGuid, (VOID **)&DebugTableHeader);\r | |
43 | if (EFI_ERROR (Status)) {\r | |
44 | return NULL;\r | |
45 | }\r | |
619b3998 | 46 | \r |
82ea9a6b | 47 | DebugTable = DebugTableHeader->EfiDebugImageInfoTable;\r |
619b3998 | 48 | if (DebugTable == NULL) {\r |
49 | return NULL;\r | |
50 | }\r | |
51 | \r | |
52 | Address = (CHAR8 *)(UINTN)FaultAddress;\r | |
82ea9a6b | 53 | for (Entry = 0; Entry < DebugTableHeader->TableSize; Entry++, DebugTable++) {\r |
619b3998 | 54 | if (DebugTable->NormalImage != NULL) {\r |
55 | if ((DebugTable->NormalImage->ImageInfoType == EFI_DEBUG_IMAGE_INFO_TYPE_NORMAL) &&\r | |
56 | (DebugTable->NormalImage->LoadedImageProtocolInstance != NULL)) {\r | |
57 | if ((Address >= (CHAR8 *)DebugTable->NormalImage->LoadedImageProtocolInstance->ImageBase) &&\r | |
58 | (Address <= ((CHAR8 *)DebugTable->NormalImage->LoadedImageProtocolInstance->ImageBase + DebugTable->NormalImage->LoadedImageProtocolInstance->ImageSize))) {\r | |
c63626b7 | 59 | *ImageBase = (UINTN)DebugTable->NormalImage->LoadedImageProtocolInstance->ImageBase;\r |
619b3998 | 60 | *PeCoffSizeOfHeaders = PeCoffGetSizeOfHeaders ((VOID *)(UINTN)*ImageBase);\r |
61 | return PeCoffLoaderGetPdbPointer (DebugTable->NormalImage->LoadedImageProtocolInstance->ImageBase);\r | |
62 | }\r | |
63 | }\r | |
64 | }\r | |
65 | }\r | |
66 | \r | |
67 | return NULL;\r | |
68 | }\r | |
c63626b7 | 69 | \r |