MdePkg/UefiImageLib: Introduce DebugAddress

Signed-off-by: Marvin Häuser <mhaeuser@posteo.de>
This commit is contained in:
Mikhail Krichanov 2023-12-15 16:34:17 +03:00
parent 410e9987f3
commit 028bb3e2c7
37 changed files with 299 additions and 183 deletions

View File

@ -84,19 +84,19 @@ UefiImageLoaderRelocateImageExtraAction (
#ifdef __CC_ARM
#if (__ARMCC_VERSION < 500000)
// Print out the command for the RVD debugger to load symbols for this image
DEBUG ((DEBUG_LOAD | DEBUG_INFO, "load /a /ni /np %a &0x%p\n", DeCygwinPathIfNeeded (PdbPath, Temp, sizeof (Temp)), UefiImageLoaderGetImageAddress (ImageContext)));
DEBUG ((DEBUG_LOAD | DEBUG_INFO, "load /a /ni /np %a &0x%p\n", DeCygwinPathIfNeeded (PdbPath, Temp, sizeof (Temp)), UefiImageLoaderGetDebugAddress (ImageContext)));
#else
// Print out the command for the DS-5 to load symbols for this image
DEBUG ((DEBUG_LOAD | DEBUG_INFO, "add-symbol-file %a -o 0x%p\n", DeCygwinPathIfNeeded (PdbPath, Temp, sizeof (Temp)), UefiImageLoaderGetImageAddress (ImageContext)));
DEBUG ((DEBUG_LOAD | DEBUG_INFO, "add-symbol-file %a -o 0x%p\n", DeCygwinPathIfNeeded (PdbPath, Temp, sizeof (Temp)), UefiImageLoaderGetDebugAddress (ImageContext)));
#endif
#elif __GNUC__
// This may not work correctly if you generate PE/COFF directly as then the Offset would not be required
DEBUG ((DEBUG_LOAD | DEBUG_INFO, "add-symbol-file %a -o 0x%p\n", DeCygwinPathIfNeeded (PdbPath, Temp, sizeof (Temp)), UefiImageLoaderGetImageAddress (ImageContext)));
DEBUG ((DEBUG_LOAD | DEBUG_INFO, "add-symbol-file %a -o 0x%p\n", DeCygwinPathIfNeeded (PdbPath, Temp, sizeof (Temp)), UefiImageLoaderGetDebugAddress (ImageContext)));
#else
DEBUG ((DEBUG_LOAD | DEBUG_INFO, "Loading driver at 0x%11p EntryPoint=0x%11p\n", (VOID *)(UINTN)UefiImageLoaderGetImageAddress (ImageContext), FUNCTION_ENTRY_POINT (UefiImageLoaderGetImageEntryPoint (ImageContext))));
DEBUG ((DEBUG_LOAD | DEBUG_INFO, "Loading driver at 0x%11p DebugBase=0x%11p EntryPoint=0x%11p\n", (VOID *)(UINTN)UefiImageLoaderGetImageAddress (ImageContext), (VOID *)(UINTN)UefiImageLoaderGetDebugAddress (ImageContext), FUNCTION_ENTRY_POINT (UefiImageLoaderGetImageEntryPoint (ImageContext))));
#endif
} else {
DEBUG ((DEBUG_LOAD | DEBUG_INFO, "Loading driver at 0x%11p EntryPoint=0x%11p\n", (VOID *)(UINTN)UefiImageLoaderGetImageAddress (ImageContext), FUNCTION_ENTRY_POINT (UefiImageLoaderGetImageEntryPoint (ImageContext))));
DEBUG ((DEBUG_LOAD | DEBUG_INFO, "Loading driver at 0x%11p DebugBase=0x%11p EntryPoint=0x%11p\n", (VOID *)(UINTN)UefiImageLoaderGetImageAddress (ImageContext), (VOID *)(UINTN)UefiImageLoaderGetDebugAddress (ImageContext), FUNCTION_ENTRY_POINT (UefiImageLoaderGetImageEntryPoint (ImageContext))));
}
}
@ -131,11 +131,11 @@ UefiImageLoaderUnloadImageExtraAction (
DEBUG ((DEBUG_LOAD | DEBUG_INFO, "unload symbols_only %a\n", DeCygwinPathIfNeeded (PdbPath, Temp, sizeof (Temp))));
#elif __GNUC__
// This may not work correctly if you generate PE/COFF directly as then the Offset would not be required
DEBUG ((DEBUG_LOAD | DEBUG_INFO, "remove-symbol-file %a 0x%08x\n", DeCygwinPathIfNeeded (PdbPath, Temp, sizeof (Temp)), (UINTN)UefiImageLoaderGetImageAddress (ImageContext)));
DEBUG ((DEBUG_LOAD | DEBUG_INFO, "remove-symbol-file %a 0x%08x\n", DeCygwinPathIfNeeded (PdbPath, Temp, sizeof (Temp)), (UINTN)UefiImageLoaderGetDebugAddress (ImageContext)));
#else
DEBUG ((DEBUG_LOAD | DEBUG_INFO, "Unloading %a\n", PdbPath));
#endif
} else {
DEBUG ((DEBUG_LOAD | DEBUG_INFO, "Unloading driver at 0x%11p\n", (VOID *)(UINTN)UefiImageLoaderGetImageAddress (ImageContext)));
DEBUG ((DEBUG_LOAD | DEBUG_INFO, "Unloading driver at 0x%11p DebugBase=0x%11p\n", (VOID *)(UINTN)UefiImageLoaderGetImageAddress (ImageContext), (VOID *)(UINTN)UefiImageLoaderGetDebugAddress (ImageContext)));
}
}

View File

@ -39,7 +39,8 @@ STATIC BOOLEAN mRecursiveException;
CONST CHAR8 *
GetImageName (
IN UINTN FaultAddress,
OUT UINTN *ImageBase
OUT UINTN *ImageBase,
OUT UINTN *DebugBase
);
STATIC
@ -212,18 +213,20 @@ DefaultExceptionHandler (
DEBUG_CODE_BEGIN ();
CONST CHAR8 *Pdb, *PrevPdb;
UINTN ImageBase;
UINTN DebugBase;
UINT64 *Fp;
UINT64 RootFp[2];
UINTN Idx;
PrevPdb = Pdb = GetImageName (SystemContext.SystemContextAArch64->ELR, &ImageBase);
PrevPdb = Pdb = GetImageName (SystemContext.SystemContextAArch64->ELR, &ImageBase, &DebugBase);
if (Pdb != NULL) {
DEBUG ((
DEBUG_ERROR,
"PC 0x%012lx (0x%012lx+0x%08x) [ 0] %a\n",
"PC 0x%012lx (0x%012lx+0x%08x) (DebugBase=%012lx) [ 0] %a\n",
SystemContext.SystemContextAArch64->ELR,
ImageBase,
SystemContext.SystemContextAArch64->ELR - ImageBase,
DebugBase,
BaseName (Pdb)
));
} else {
@ -241,7 +244,7 @@ DefaultExceptionHandler (
}
for (Fp = RootFp; Fp[0] != 0; Fp = (UINT64 *)Fp[0]) {
Pdb = GetImageName (Fp[1], &ImageBase);
Pdb = GetImageName (Fp[1], &ImageBase, &DebugBase);
if (Pdb != NULL) {
if (Pdb != PrevPdb) {
Idx++;
@ -250,10 +253,11 @@ DefaultExceptionHandler (
DEBUG ((
DEBUG_ERROR,
"PC 0x%012lx (0x%012lx+0x%08x) [% 2d] %a\n",
"PC 0x%012lx (0x%012lx+0x%08x) (DebugBase=0x%012lx) [% 2d] %a\n",
Fp[1],
ImageBase,
Fp[1] - ImageBase,
DebugBase,
Idx,
BaseName (Pdb)
));
@ -262,14 +266,14 @@ DefaultExceptionHandler (
}
}
PrevPdb = Pdb = GetImageName (SystemContext.SystemContextAArch64->ELR, &ImageBase);
PrevPdb = Pdb = GetImageName (SystemContext.SystemContextAArch64->ELR, &ImageBase, &DebugBase);
if (Pdb != NULL) {
DEBUG ((DEBUG_ERROR, "\n[ 0] %a\n", Pdb));
}
Idx = 0;
for (Fp = RootFp; Fp[0] != 0; Fp = (UINT64 *)Fp[0]) {
Pdb = GetImageName (Fp[1], &ImageBase);
Pdb = GetImageName (Fp[1], &ImageBase, &DebugBase);
if ((Pdb != NULL) && (Pdb != PrevPdb)) {
DEBUG ((DEBUG_ERROR, "[% 2d] %a\n", ++Idx, Pdb));
PrevPdb = Pdb;

View File

@ -56,7 +56,8 @@ STATIC CONST CPSR_CHAR mCpsrChar[] = {
CONST CHAR8 *
GetImageName (
IN UINTN FaultAddress,
OUT UINTN *ImageBase
OUT UINTN *ImageBase,
OUT UINTN *DebugBase
);
/**
@ -229,6 +230,7 @@ DefaultExceptionHandler (
DEBUG_CODE_BEGIN ();
CONST CHAR8 *Pdb;
UINT32 ImageBase;
UINT32 DebugBase;
UINT32 Offset;
CHAR8 CpsrStr[CPSR_STRING_SIZE]; // char per bit. Lower 5-bits are mode
// that is a 3 char string
@ -239,7 +241,7 @@ DefaultExceptionHandler (
CpsrString (SystemContext.SystemContextArm->CPSR, CpsrStr);
DEBUG ((DEBUG_ERROR, "%a\n", CpsrStr));
Pdb = GetImageName (SystemContext.SystemContextArm->PC, &ImageBase);
Pdb = GetImageName (SystemContext.SystemContextArm->PC, &ImageBase, &DebugBase);
Offset = SystemContext.SystemContextArm->PC - ImageBase;
if (Pdb != NULL) {
DEBUG ((DEBUG_ERROR, "%a\n", Pdb));
@ -254,7 +256,7 @@ DefaultExceptionHandler (
//
// FIXME: Used to have (ELF or Mach-O offset) 0x%x
// Substitute with .text address (better + may be needed for GDB symbols?)
DEBUG ((EFI_D_ERROR, "loaded at 0x%08x (PE/COFF offset) 0x%x", ImageBase, Offset));
DEBUG ((EFI_D_ERROR, "loaded at 0x%08x (DebugBase=0x%08x) (PE/COFF offset) 0x%x", ImageBase, DebugBase, Offset));
// If we come from an image it is safe to show the instruction. We know it should not fault
DisAsm = (UINT8 *)(UINTN)SystemContext.SystemContextArm->PC;

View File

@ -19,6 +19,7 @@
@param FaultAddress Address to find PE/COFF image for.
@param ImageBase Return load address of found image
@param ImageBase Return debug address of found image
@retval NULL FaultAddress not in a loaded PE/COFF image.
@retval Path and file name of PE/COFF image.
@ -27,7 +28,8 @@
CONST CHAR8 *
GetImageName (
IN UINTN FaultAddress,
OUT UINTN *ImageBase
OUT UINTN *ImageBase,
OUT UINTN *DebugBase
)
{
EFI_STATUS Status;
@ -48,15 +50,16 @@ GetImageName (
Address = (CHAR8 *)(UINTN)FaultAddress;
for (Entry = 0; Entry < DebugTableHeader->TableSize; Entry++, DebugTable++) {
if (DebugTable->NormalImage != NULL) {
if ((DebugTable->NormalImage->ImageInfoType == EFI_DEBUG_IMAGE_INFO_TYPE_NORMAL) &&
(DebugTable->NormalImage->LoadedImageProtocolInstance != NULL))
if (DebugTable->NormalImage2 != NULL) {
if ((DebugTable->NormalImage2->ImageInfoType == EFI_DEBUG_IMAGE_INFO_TYPE_NORMAL2) &&
(DebugTable->NormalImage2->LoadedImageProtocolInstance != NULL))
{
if ((Address >= (CHAR8 *)DebugTable->NormalImage->LoadedImageProtocolInstance->ImageBase) &&
(Address <= ((CHAR8 *)DebugTable->NormalImage->LoadedImageProtocolInstance->ImageBase + DebugTable->NormalImage->LoadedImageProtocolInstance->ImageSize)))
if ((Address >= (CHAR8 *)DebugTable->NormalImage2->LoadedImageProtocolInstance->ImageBase) &&
(Address <= ((CHAR8 *)DebugTable->NormalImage2->LoadedImageProtocolInstance->ImageBase + DebugTable->NormalImage2->LoadedImageProtocolInstance->ImageSize)))
{
*ImageBase = (UINTN)DebugTable->NormalImage->LoadedImageProtocolInstance->ImageBase;
return DebugTable->NormalImage->PdbPath;
*ImageBase = (UINTN)DebugTable->NormalImage2->LoadedImageProtocolInstance->ImageBase;
*DebugBase = (UINTN)DebugTable->NormalImage2->DebugBase;
return DebugTable->NormalImage2->PdbPath;
}
}
}

View File

@ -32,12 +32,12 @@ typedef struct {
EFI_IMAGE_DEBUG_CODEVIEW_NB10_ENTRY Nb10;
} image_tool_debug_dir_t;
#define SIZE_OF_DATA_DIRECRORY \
#define SIZE_OF_DATA_DIRECTORY \
EFI_IMAGE_NUMBER_OF_DIRECTORY_ENTRIES * sizeof (EFI_IMAGE_DATA_DIRECTORY)
#define SIZE_OF_OPTIONAL_HEADER \
sizeof (EFI_IMAGE_NT_HEADERS) - sizeof (EFI_IMAGE_NT_HEADERS_COMMON_HDR) \
+ SIZE_OF_DATA_DIRECRORY
+ SIZE_OF_DATA_DIRECTORY
static
bool
@ -581,7 +581,7 @@ ToolImageEmitPeFile (
return false;
}
SectionHeadersOffset = sizeof (*PeHdr) + SIZE_OF_DATA_DIRECRORY;
SectionHeadersOffset = sizeof (*PeHdr) + SIZE_OF_DATA_DIRECTORY;
SectionHeadersSize = NumSections * sizeof (EFI_IMAGE_SECTION_HEADER);
SizeOfPeHeaders = SectionHeadersOffset + SectionHeadersSize;
SizeOfHeaders = sizeof (mDosHdr) + SizeOfPeHeaders;

View File

@ -873,10 +873,10 @@ QxferLibrary (
if (gDebugTable != NULL) {
for ( ; gEfiDebugImageTableEntry < gDebugImageTableHeader->TableSize; gEfiDebugImageTableEntry++, gDebugTable++) {
if (gDebugTable->NormalImage != NULL) {
if ((gDebugTable->NormalImage->ImageInfoType == EFI_DEBUG_IMAGE_INFO_TYPE_NORMAL) &&
(gDebugTable->NormalImage->LoadedImageProtocolInstance != NULL)) {
Pdb = gDebugTable->NormalImage->PdbPath;
if (gDebugTable->NormalImage2 != NULL) {
if ((gDebugTable->NormalImage2->ImageInfoType == EFI_DEBUG_IMAGE_INFO_TYPE_NORMAL2) &&
(gDebugTable->NormalImage2->LoadedImageProtocolInstance != NULL)) {
Pdb = gDebugTable->NormalImage2->PdbPath;
if (Pdb != NULL) {
Size = AsciiSPrint (
gXferLibraryBuffer,

View File

@ -892,15 +892,17 @@ PrintLoadAddress (
if (EFI_ERROR (Status)) {
fprintf (
stderr,
"0x%08lx Loading NO DEBUG with entry point 0x%08lx\n",
"0x%08lx (0x%08lx) Loading NO DEBUG with entry point 0x%08lx\n",
(unsigned long) UefiImageLoaderGetImageAddress (ImageContext),
(unsigned long) UefiImageLoaderGetDebugAddress (ImageContext),
(unsigned long) UefiImageLoaderGetImageEntryPoint (ImageContext)
);
} else {
fprintf (
stderr,
"0x%08lx Loading %s with entry point 0x%08lx\n",
"0x%08lx (0x%08lx) Loading %s with entry point 0x%08lx\n",
(unsigned long) UefiImageLoaderGetImageAddress (ImageContext),
(unsigned long) UefiImageLoaderGetDebugAddress (ImageContext),
PdbPath,
(unsigned long) UefiImageLoaderGetImageEntryPoint (ImageContext)
);
@ -952,7 +954,7 @@ GdbScriptAddImage (
if (FeaturePcdGet (PcdEmulatorLazyLoadSymbols)) {
GdbTempFile = fopen (gGdbWorkingFileName, "a");
if (GdbTempFile != NULL) {
long unsigned int SymbolsAddr = (long unsigned int)UefiImageLoaderGetImageAddress (ImageContext);
long unsigned int SymbolsAddr = (long unsigned int)UefiImageLoaderGetDebugAddress (ImageContext);
mScriptSymbolChangesCount++;
fprintf (
GdbTempFile,
@ -963,7 +965,7 @@ GdbScriptAddImage (
);
fclose (GdbTempFile);
// This is for the lldb breakpoint only
SecGdbScriptBreak (PdbPath, PdbPathSize, (long unsigned int)UefiImageLoaderGetImageAddress (ImageContext), 1);
SecGdbScriptBreak (PdbPath, PdbPathSize, (long unsigned int)UefiImageLoaderGetDebugAddress (ImageContext), 1);
} else {
ASSERT (FALSE);
}
@ -974,7 +976,7 @@ GdbScriptAddImage (
GdbTempFile,
"add-symbol-file %s -o 0x%08lx\n",
PdbPath,
(long unsigned int)UefiImageLoaderGetImageAddress (ImageContext)
(long unsigned int)UefiImageLoaderGetDebugAddress (ImageContext)
);
fclose (GdbTempFile);
@ -984,7 +986,7 @@ GdbScriptAddImage (
// Also used for the lldb breakpoint script. The lldb breakpoint script does
// not use the file, it uses the arguments.
//
SecGdbScriptBreak (PdbPath, PdbPathSize, (long unsigned int)UefiImageLoaderGetImageAddress (ImageContext), 1);
SecGdbScriptBreak (PdbPath, PdbPathSize, (long unsigned int)UefiImageLoaderGetDebugAddress (ImageContext), 1);
} else {
ASSERT (FALSE);
}

View File

@ -452,6 +452,7 @@ DumpMemoryProfileDriverInfo (
}
Print (L" ImageBase - 0x%016lx\n", DriverInfo->ImageBase);
Print (L" DebugBase - 0x%016lx\n", DriverInfo->DebugBase);
Print (L" ImageSize - 0x%016lx\n", DriverInfo->ImageSize);
Print (L" EntryPoint - 0x%016lx\n", DriverInfo->EntryPoint);
Print (L" ImageSubsystem - 0x%04x (%a)\n", DriverInfo->ImageSubsystem, mSubsystemString[(DriverInfo->ImageSubsystem < sizeof (mSubsystemString)/sizeof (mSubsystemString[0])) ? DriverInfo->ImageSubsystem : 0]);
@ -947,7 +948,11 @@ DumpContextSummaryData (
}
if (DriverInfo->PdbStringOffset != 0) {
Print (L" (Pdb - %a)\n", (CHAR8 *)((UINTN)DriverInfo + DriverInfo->PdbStringOffset));
Print (
L" (DebugBase - 0x%016lx, Pdb - %a)\n",
(UINT64)DriverInfo->DebugBase,
(CHAR8 *)((UINTN)DriverInfo + DriverInfo->PdbStringOffset)
);
} else {
Print (L"\n");
}

View File

@ -2373,20 +2373,19 @@ CoreUpdateDebugTableCrc32 (
/**
Adds a new DebugImageInfo structure to the DebugImageInfo Table. Re-Allocates
the table if it's not large enough to accomidate another entry.
the table if it's not large enough to accommodate another entry.
@param ImageInfoType type of debug image information
@param LoadedImage pointer to the loaded image protocol for the image being
loaded
@param ImageHandle image handle for the image being loaded
@param ImageContext image context for the image being loaded
**/
VOID
CoreNewDebugImageInfoEntry (
IN UINT32 ImageInfoType,
IN EFI_LOADED_IMAGE_PROTOCOL *LoadedImage,
IN EFI_HANDLE ImageHandle,
IN UEFI_IMAGE_LOADER_IMAGE_CONTEXT *ImageContext
IN EFI_LOADED_IMAGE_PROTOCOL *LoadedImage,
IN EFI_HANDLE ImageHandle,
IN CONST UEFI_IMAGE_LOADER_IMAGE_CONTEXT *ImageContext
);
/**

View File

@ -393,7 +393,6 @@ DxeMain (
//
CoreInitializeDebugImageInfoTable ();
CoreNewDebugImageInfoEntry (
EFI_DEBUG_IMAGE_INFO_TYPE_NORMAL,
gDxeCoreLoadedImage,
gImageHandle,
&ImageContext

View File

@ -1343,7 +1343,7 @@ CoreLoadImageCommon (
// Register the image in the Debug Image Info Table if the attribute is set
//
if ((Attribute & EFI_LOAD_PE_IMAGE_ATTRIBUTE_DEBUG_IMAGE_INFO_TABLE_REGISTRATION) != 0) {
CoreNewDebugImageInfoEntry (EFI_DEBUG_IMAGE_INFO_TYPE_NORMAL, &Image->Info, Image->Handle, &ImageContext);
CoreNewDebugImageInfoEntry (&Image->Info, Image->Handle, &ImageContext);
}
//

View File

@ -315,6 +315,7 @@ BuildDriverInfo (
}
DriverInfo->ImageBase = UefiImageLoaderGetImageAddress (ImageContext);
DriverInfo->DebugBase = UefiImageLoaderGetDebugAddress (ImageContext);
DriverInfo->ImageSize = UefiImageGetImageSize (ImageContext);
DriverInfo->EntryPoint = UefiImageLoaderGetImageEntryPoint (ImageContext);
DriverInfo->ImageSubsystem = UefiImageGetSubsystem (ImageContext);

View File

@ -150,30 +150,29 @@ CoreUpdateDebugTableCrc32 (
/**
Adds a new DebugImageInfo structure to the DebugImageInfo Table. Re-Allocates
the table if it's not large enough to accomidate another entry.
the table if it's not large enough to accommodate another entry.
@param ImageInfoType type of debug image information
@param LoadedImage pointer to the loaded image protocol for the image being
loaded
@param ImageHandle image handle for the image being loaded
@param ImageContext image context for the image being loaded
**/
VOID
CoreNewDebugImageInfoEntry (
IN UINT32 ImageInfoType,
IN EFI_LOADED_IMAGE_PROTOCOL *LoadedImage,
IN EFI_HANDLE ImageHandle,
IN OUT UEFI_IMAGE_LOADER_IMAGE_CONTEXT *ImageContext
IN EFI_LOADED_IMAGE_PROTOCOL *LoadedImage,
IN EFI_HANDLE ImageHandle,
IN CONST UEFI_IMAGE_LOADER_IMAGE_CONTEXT *ImageContext
)
{
EFI_DEBUG_IMAGE_INFO *Table;
EFI_DEBUG_IMAGE_INFO *NewTable;
UINTN Index;
UINTN TableSize;
EFI_DEBUG_IMAGE_INFO_NORMAL *NormalImage;
RETURN_STATUS Status;
CONST CHAR8 *PdbPath;
UINT32 PdbPathSize;
EFI_DEBUG_IMAGE_INFO *Table;
EFI_DEBUG_IMAGE_INFO *NewTable;
UINTN Index;
UINTN TableSize;
EFI_DEBUG_IMAGE_INFO_NORMAL2 *NormalImage2;
RETURN_STATUS Status;
CONST CHAR8 *PdbPath;
UINT32 PdbPathSize;
//
// Set the flag indicating that we're in the process of updating the table.
@ -187,7 +186,7 @@ CoreNewDebugImageInfoEntry (
// We still have empty entires in the Table, find the first empty entry.
//
Index = 0;
while (Table[Index].NormalImage != NULL) {
while (Table[Index].NormalImage2 != NULL) {
Index++;
}
@ -232,24 +231,26 @@ CoreNewDebugImageInfoEntry (
//
// Allocate data for new entry
//
NormalImage = AllocateZeroPool (sizeof (EFI_DEBUG_IMAGE_INFO_NORMAL));
if (NormalImage != NULL) {
NormalImage2 = AllocateZeroPool (sizeof (EFI_DEBUG_IMAGE_INFO_NORMAL2));
if (NormalImage2 != NULL) {
//
// Update the entry
//
NormalImage->ImageInfoType = (UINT32)ImageInfoType;
NormalImage->LoadedImageProtocolInstance = LoadedImage;
NormalImage->ImageHandle = ImageHandle;
NormalImage2->ImageInfoType = EFI_DEBUG_IMAGE_INFO_TYPE_NORMAL2;
NormalImage2->LoadedImageProtocolInstance = LoadedImage;
NormalImage2->ImageHandle = ImageHandle;
Status = UefiImageGetSymbolsPath (ImageContext, &PdbPath, &PdbPathSize);
if (!RETURN_ERROR (Status)) {
NormalImage->PdbPath = AllocateCopyPool (PdbPathSize, PdbPath);
NormalImage2->PdbPath = AllocateCopyPool (PdbPathSize, PdbPath);
}
NormalImage2->DebugBase = UefiImageLoaderGetDebugAddress (ImageContext);
//
// Increase the number of EFI_DEBUG_IMAGE_INFO elements and set the mDebugInfoTable in modified status.
//
mDebugInfoTableHeader.UpdateStatus |= EFI_DEBUG_IMAGE_INFO_TABLE_MODIFIED;
Table[Index].NormalImage = NormalImage;
Table[Index].NormalImage2 = NormalImage2;
mDebugInfoTableHeader.TableSize++;
}
@ -267,34 +268,42 @@ CoreRemoveDebugImageInfoEntry (
EFI_HANDLE ImageHandle
)
{
EFI_DEBUG_IMAGE_INFO *Table;
UINTN Index;
EFI_DEBUG_IMAGE_INFO_NORMAL *NormalImage;
EFI_DEBUG_IMAGE_INFO *Table;
UINTN Index;
EFI_DEBUG_IMAGE_INFO_NORMAL2 *NormalImage2;
mDebugInfoTableHeader.UpdateStatus |= EFI_DEBUG_IMAGE_INFO_UPDATE_IN_PROGRESS;
Table = mDebugInfoTableHeader.EfiDebugImageInfoTable;
for (Index = 0; Index < mMaxTableEntries; Index++) {
if ((Table[Index].NormalImage != NULL) && (Table[Index].NormalImage->ImageHandle == ImageHandle)) {
//
// Found a match. Free up the record, then NULL the pointer to indicate the slot
// is free.
//
NormalImage = Table[Index].NormalImage;
//
// Decrease the number of EFI_DEBUG_IMAGE_INFO elements and set the mDebugInfoTable in modified status.
//
mDebugInfoTableHeader.UpdateStatus |= EFI_DEBUG_IMAGE_INFO_TABLE_MODIFIED;
mDebugInfoTableHeader.TableSize--;
Table[Index].NormalImage = NULL;
if (NormalImage->PdbPath != NULL) {
FreePool (NormalImage->PdbPath);
if (Table[Index].NormalImage2 != NULL) {
if (*Table[Index].ImageInfoType != EFI_DEBUG_IMAGE_INFO_TYPE_NORMAL2)
{
ASSERT (FALSE);
continue;
}
CoreFreePool (NormalImage);
break;
if (Table[Index].NormalImage2->ImageHandle == ImageHandle) {
//
// Found a match. Free up the record, then NULL the pointer to indicate the slot
// is free.
//
NormalImage2 = Table[Index].NormalImage2;
//
// Decrease the number of EFI_DEBUG_IMAGE_INFO elements and set the mDebugInfoTable in modified status.
//
mDebugInfoTableHeader.UpdateStatus |= EFI_DEBUG_IMAGE_INFO_TABLE_MODIFIED;
mDebugInfoTableHeader.TableSize--;
Table[Index].NormalImage2 = NULL;
if (NormalImage2->PdbPath != NULL) {
FreePool (NormalImage2->PdbPath);
}
CoreFreePool (NormalImage2);
break;
}
}
}

View File

@ -158,7 +158,8 @@ LoadAndRelocateUefiImage (
IN VOID *Pe32Data,
IN UINT32 Pe32DataSize,
OUT UEFI_IMAGE_LOADER_IMAGE_CONTEXT *ImageContext,
OUT EFI_PHYSICAL_ADDRESS *ImageAddress
OUT EFI_PHYSICAL_ADDRESS *ImageAddress,
OUT UINTN *DebugBase
)
{
EFI_STATUS Status;
@ -339,6 +340,7 @@ LoadAndRelocateUefiImage (
}
*ImageAddress = UefiImageLoaderGetImageAddress (ImageContext);
*DebugBase = UefiImageLoaderGetDebugAddress (ImageContext);
return ReturnStatus;
}
@ -457,6 +459,7 @@ PeiLoadImageLoadImage (
VOID *Pe32Data;
UINT32 Pe32DataSize;
EFI_PHYSICAL_ADDRESS ImageAddress;
UINTN DebugBase;
UEFI_IMAGE_LOADER_IMAGE_CONTEXT ImageContext;
*EntryPoint = 0;
@ -491,7 +494,8 @@ PeiLoadImageLoadImage (
Pe32Data,
Pe32DataSize,
&ImageContext,
&ImageAddress
&ImageAddress,
&DebugBase
);
if (EFI_ERROR (Status)) {
@ -521,12 +525,12 @@ PeiLoadImageLoadImage (
// Print debug message: Loading PEIM at 0x12345678 EntryPoint=0x12345688 Driver.efi
//
if (Machine != EFI_IMAGE_MACHINE_IA64) {
DEBUG ((DEBUG_INFO | DEBUG_LOAD, "Loading PEIM at 0x%11p EntryPoint=0x%11p ", (VOID *)(UINTN)ImageAddress, (VOID *)(UINTN)*EntryPoint));
DEBUG ((DEBUG_INFO | DEBUG_LOAD, "Loading PEIM at 0x%11p DebugBase=0x%11p EntryPoint=0x%11p ", (VOID *)(UINTN)ImageAddress, (VOID *)(UINTN)DebugBase, (VOID *)(UINTN)*EntryPoint));
} else {
//
// For IPF Image, the real entry point should be print.
//
DEBUG ((DEBUG_INFO | DEBUG_LOAD, "Loading PEIM at 0x%11p EntryPoint=0x%11p ", (VOID *)(UINTN)ImageAddress, (VOID *)(UINTN)(*(UINT64 *)(UINTN)*EntryPoint)));
DEBUG ((DEBUG_INFO | DEBUG_LOAD, "Loading PEIM at 0x%11p DebugBase=0x%11p EntryPoint=0x%11p ", (VOID *)(UINTN)ImageAddress, (VOID *)(UINTN)DebugBase, (VOID *)(UINTN)(*(UINT64 *)(UINTN)*EntryPoint)));
}
//

View File

@ -49,30 +49,29 @@ SmmInitializeDebugImageInfoTable (
/**
Adds a new DebugImageInfo structure to the DebugImageInfo Table. Re-Allocates
the table if it's not large enough to accomidate another entry.
the table if it's not large enough to accommodate another entry.
@param ImageInfoType type of debug image information
@param LoadedImage pointer to the loaded image protocol for the image being
loaded
@param ImageHandle image handle for the image being loaded
@param ImageContext image context for the image being loaded
**/
VOID
SmmNewDebugImageInfoEntry (
IN UINT32 ImageInfoType,
IN EFI_LOADED_IMAGE_PROTOCOL *LoadedImage,
IN EFI_HANDLE ImageHandle,
IN OUT UEFI_IMAGE_LOADER_IMAGE_CONTEXT *ImageContext
IN EFI_LOADED_IMAGE_PROTOCOL *LoadedImage,
IN EFI_HANDLE ImageHandle,
IN CONST UEFI_IMAGE_LOADER_IMAGE_CONTEXT *ImageContext
)
{
EFI_DEBUG_IMAGE_INFO *Table;
EFI_DEBUG_IMAGE_INFO *NewTable;
UINTN Index;
UINTN TableSize;
EFI_DEBUG_IMAGE_INFO_NORMAL *NormalImage;
RETURN_STATUS Status;
CONST CHAR8 *PdbPath;
UINT32 PdbPathSize;
EFI_DEBUG_IMAGE_INFO *Table;
EFI_DEBUG_IMAGE_INFO *NewTable;
UINTN Index;
UINTN TableSize;
EFI_DEBUG_IMAGE_INFO_NORMAL2 *NormalImage2;
RETURN_STATUS Status;
CONST CHAR8 *PdbPath;
UINT32 PdbPathSize;
//
// Set the flag indicating that we're in the process of updating the table.
@ -86,7 +85,7 @@ SmmNewDebugImageInfoEntry (
// We still have empty entires in the Table, find the first empty entry.
//
Index = 0;
while (Table[Index].NormalImage != NULL) {
while (Table[Index].NormalImage2 != NULL) {
Index++;
}
//
@ -129,24 +128,26 @@ SmmNewDebugImageInfoEntry (
//
// Allocate data for new entry
//
NormalImage = AllocateZeroPool (sizeof (EFI_DEBUG_IMAGE_INFO_NORMAL));
if (NormalImage != NULL) {
NormalImage2 = AllocateZeroPool (sizeof (EFI_DEBUG_IMAGE_INFO_NORMAL2));
if (NormalImage2 != NULL) {
//
// Update the entry
//
NormalImage->ImageInfoType = (UINT32) ImageInfoType;
NormalImage->LoadedImageProtocolInstance = LoadedImage;
NormalImage->ImageHandle = ImageHandle;
NormalImage2->ImageInfoType = EFI_DEBUG_IMAGE_INFO_TYPE_NORMAL2;
NormalImage2->LoadedImageProtocolInstance = LoadedImage;
NormalImage2->ImageHandle = ImageHandle;
Status = UefiImageGetSymbolsPath (ImageContext, &PdbPath, &PdbPathSize);
if (!RETURN_ERROR (Status)) {
NormalImage->PdbPath = AllocateCopyPool (PdbPathSize, PdbPath);
NormalImage2->PdbPath = AllocateCopyPool (PdbPathSize, PdbPath);
}
NormalImage2->DebugBase = UefiImageLoaderGetDebugAddress (ImageContext);
//
// Increase the number of EFI_DEBUG_IMAGE_INFO elements and set the mDebugInfoTable in modified status.
//
mDebugInfoTableHeader.UpdateStatus |= EFI_DEBUG_IMAGE_INFO_TABLE_MODIFIED;
Table[Index].NormalImage = NormalImage;
Table[Index].NormalImage2 = NormalImage2;
mDebugInfoTableHeader.TableSize++;
}
mDebugInfoTableHeader.UpdateStatus &= ~EFI_DEBUG_IMAGE_INFO_UPDATE_IN_PROGRESS;

View File

@ -571,7 +571,6 @@ SmmLoadImage (
// Register the image in the Debug Image Info Table if the attribute is set
//
SmmNewDebugImageInfoEntry (
EFI_DEBUG_IMAGE_INFO_TYPE_NORMAL,
&DriverEntry->SmmLoadedImage,
DriverEntry->SmmImageHandle,
ImageContext

View File

@ -876,7 +876,6 @@ SmmCoreInstallLoadedImage (
//
SmmInitializeDebugImageInfoTable ();
SmmNewDebugImageInfoEntry (
EFI_DEBUG_IMAGE_INFO_TYPE_NORMAL,
&mSmmCoreDriverEntry->SmmLoadedImage,
mSmmCoreDriverEntry->SmmImageHandle,
&gSmmCorePrivate->PiSmmCoreImageContext

View File

@ -1375,20 +1375,19 @@ SmmInitializeDebugImageInfoTable (
/**
Adds a new DebugImageInfo structure to the DebugImageInfo Table. Re-Allocates
the table if it's not large enough to accomidate another entry.
the table if it's not large enough to accommodate another entry.
@param ImageInfoType type of debug image information
@param LoadedImage pointer to the loaded image protocol for the image being
loaded
@param ImageHandle image handle for the image being loaded
@param ImageContext image context for the image being loaded
**/
VOID
SmmNewDebugImageInfoEntry (
IN UINT32 ImageInfoType,
IN EFI_LOADED_IMAGE_PROTOCOL *LoadedImage,
IN EFI_HANDLE ImageHandle,
IN UEFI_IMAGE_LOADER_IMAGE_CONTEXT *ImageContext
IN EFI_LOADED_IMAGE_PROTOCOL *LoadedImage,
IN EFI_HANDLE ImageHandle,
IN CONST UEFI_IMAGE_LOADER_IMAGE_CONTEXT *ImageContext
);
/**

View File

@ -984,6 +984,7 @@ ExecuteSmmCoreFromSmram (
UINTN PageCount;
EFI_IMAGE_ENTRY_POINT EntryPoint;
EFI_PHYSICAL_ADDRESS LoadAddress;
UINTN DebugBase;
//
// Search all Firmware Volumes for a PE/COFF image in a file of type SMM_CORE
@ -1106,6 +1107,7 @@ ExecuteSmmCoreFromSmram (
Status = UefiImageLoadImageForExecution (&gSmmCorePrivate->PiSmmCoreImageContext, (VOID *)(UINTN)LoadAddress, DestinationSize, NULL, 0);
if (!EFI_ERROR (Status)) {
LoadAddress = UefiImageLoaderGetImageAddress (&gSmmCorePrivate->PiSmmCoreImageContext);
DebugBase = UefiImageLoaderGetDebugAddress (&gSmmCorePrivate->PiSmmCoreImageContext);
//
// Print debug message showing SMM Core entry point address.
//
@ -1113,6 +1115,7 @@ ExecuteSmmCoreFromSmram (
gSmmCorePrivate->PiSmmCoreImageBase = LoadAddress;
DEBUG ((DEBUG_INFO, "PiSmmCoreImageBase - 0x%016lx\n", gSmmCorePrivate->PiSmmCoreImageBase));
DEBUG ((DEBUG_INFO, "PiSmmCoreDebugBase - 0x%016lx\n", DebugBase));
DEBUG ((DEBUG_INFO, "PiSmmCoreImageSize - 0x%016lx\n", UefiImageGetImageSize (&gSmmCorePrivate->PiSmmCoreImageContext)));
//

View File

@ -267,7 +267,6 @@ BuildDriverInfo (
IN MEMORY_PROFILE_CONTEXT_DATA *ContextData,
IN EFI_GUID *FileName,
IN UEFI_IMAGE_LOADER_IMAGE_CONTEXT *ImageContext,
IN EFI_PHYSICAL_ADDRESS LoadAddress,
IN EFI_FV_FILETYPE FileType
)
{
@ -313,7 +312,8 @@ BuildDriverInfo (
CopyMem (&DriverInfo->FileName, FileName, sizeof (EFI_GUID));
}
DriverInfo->ImageBase = LoadAddress;
DriverInfo->ImageBase = UefiImageLoaderGetImageAddress (ImageContext);
DriverInfo->DebugBase = UefiImageLoaderGetDebugAddress (ImageContext);
DriverInfo->ImageSize = UefiImageGetImageSize (ImageContext);
DriverInfo->EntryPoint = UefiImageLoaderGetImageEntryPoint (ImageContext);
DriverInfo->ImageSubsystem = UefiImageGetSubsystem (ImageContext);
@ -505,7 +505,6 @@ RegisterSmmCore (
ContextData,
&gEfiCallerIdGuid,
&gSmmCorePrivate->PiSmmCoreImageContext,
gSmmCorePrivate->PiSmmCoreImageBase,
EFI_FV_FILETYPE_SMM_CORE
);
if (DriverInfoData == NULL) {
@ -668,7 +667,6 @@ RegisterSmramProfileImage (
ContextData,
FileName,
ImageContext,
UefiImageLoaderGetImageAddress (ImageContext),
EFI_FV_FILETYPE_SMM
);
if (DriverInfoData == NULL) {

View File

@ -58,6 +58,8 @@ typedef struct {
UINT64 PeakUsageByType[EfiMaxMemoryType + 2];
UINT16 PdbStringOffset;
UINT8 Reserved2[6];
// FIXME: Changes struct layout.
UINT64 DebugBase;
// CHAR8 PdbString[];
} MEMORY_PROFILE_DRIVER_INFO;

View File

@ -949,15 +949,15 @@ EdbPatchSymbolRVA (
CandidateImageBase = NULL;
ImageTable = mDebuggerPrivate.DebugImageInfoTableHeader->EfiDebugImageInfoTable;
for (ImageNumber = 0; ImageNumber < mDebuggerPrivate.DebugImageInfoTableHeader->TableSize; ImageNumber++) {
if (ImageTable[ImageNumber].NormalImage == NULL) {
if (ImageTable[ImageNumber].NormalImage2 == NULL) {
continue;
}
ImageBase = ImageTable[ImageNumber].NormalImage->LoadedImageProtocolInstance->ImageBase;
ImageBase = ImageTable[ImageNumber].NormalImage2->LoadedImageProtocolInstance->ImageBase;
//
// Get PDB path
//
PdbPath = ImageTable[ImageNumber].NormalImage->PdbPath;
PdbPath = ImageTable[ImageNumber].NormalImage2->PdbPath;
if (PdbPath == NULL) {
continue;
}

View File

@ -25,7 +25,8 @@
#define EFI_DEBUG_IMAGE_INFO_UPDATE_IN_PROGRESS 0x01
#define EFI_DEBUG_IMAGE_INFO_TABLE_MODIFIED 0x02
#define EFI_DEBUG_IMAGE_INFO_TYPE_NORMAL 0x01
#define EFI_DEBUG_IMAGE_INFO_TYPE_NORMAL 0x01
#define EFI_DEBUG_IMAGE_INFO_TYPE_NORMAL2 0x02
typedef struct {
UINT64 Signature; ///< A constant UINT64 that has the value EFI_SYSTEM_TABLE_SIGNATURE
@ -35,8 +36,8 @@ typedef struct {
typedef struct {
///
/// Indicates the type of image info structure. For PE32 EFI images,
/// this is set to EFI_DEBUG_IMAGE_INFO_TYPE_NORMAL.
/// When this debug image info structure is present, ImageInfoType is set
/// to EFI_DEBUG_IMAGE_INFO_TYPE_NORMAL indicating a loaded PE32 EFI image.
///
UINT32 ImageInfoType;
///
@ -47,12 +48,50 @@ typedef struct {
/// Indicates the image handle of the associated image.
///
EFI_HANDLE ImageHandle;
CHAR8 *PdbPath;
} EFI_DEBUG_IMAGE_INFO_NORMAL;
typedef struct {
///
/// When this debug image info structure is present, ImageInfoType is
/// set to EFI_DEBUG_IMAGE_INFO_TYPE_NORMAL2, indicating that PdbPath
/// and DebugBase fields are available for symbolication. The format
/// of the loaded image is not specified and may or may not be PE.
///
UINT32 ImageInfoType;
///
/// A pointer to an instance of the loaded image protocol for the associated image.
///
EFI_LOADED_IMAGE_PROTOCOL *LoadedImageProtocolInstance;
///
/// Indicates the image handle of the associated image.
///
EFI_HANDLE ImageHandle;
///
/// Symbol file path for debug symbolication.
///
CHAR8 *PdbPath;
///
/// Image base address for debug symbolication.
///
UINTN DebugBase;
} EFI_DEBUG_IMAGE_INFO_NORMAL2;
typedef union {
UINT32 *ImageInfoType;
EFI_DEBUG_IMAGE_INFO_NORMAL *NormalImage;
///
/// Indicates the type of image info structure which is present. For
/// PE32 EFI images loaded with the old image loader, this is set to
/// EFI_DEBUG_IMAGE_INFO_TYPE_NORMAL. For all images loaded with the new
/// image loader, this is set to EFI_DEBUG_IMAGE_INFO_TYPE_NORMAL2.
///
UINT32 *ImageInfoType;
///
/// Present when ImageInfoType is EFI_DEBUG_IMAGE_INFO_TYPE_NORMAL.
///
EFI_DEBUG_IMAGE_INFO_NORMAL *NormalImage;
///
/// Present when ImageInfoType is EFI_DEBUG_IMAGE_INFO_TYPE_NORMAL2.
///
EFI_DEBUG_IMAGE_INFO_NORMAL2 *NormalImage2;
} EFI_DEBUG_IMAGE_INFO;
typedef struct {

View File

@ -234,7 +234,7 @@ typedef struct {
UINT64 SizeOfHeapCommit;
UINT32 LoaderFlags;
UINT32 NumberOfRvaAndSizes;
EFI_IMAGE_DATA_DIRECTORY DataDirectory[EFI_IMAGE_NUMBER_OF_DIRECTORY_ENTRIES];
EFI_IMAGE_DATA_DIRECTORY DataDirectory[EFI_IMAGE_NUMBER_OF_DIRECTORY_ENTRIES];
} EFI_IMAGE_OPTIONAL_HEADER64;

View File

@ -650,4 +650,9 @@ UefiImageDebugPrintImageRecord (
IN CONST UEFI_IMAGE_RECORD *ImageRecord
);
UINTN
UefiImageLoaderGetDebugAddress (
IN CONST UEFI_IMAGE_LOADER_IMAGE_CONTEXT *Context
);
#endif // UEFI_IMAGE_LIB_H_

View File

@ -236,6 +236,14 @@ UefiImageLoaderGetImageAddressPe (
return PeCoffLoaderGetImageAddress (&Context->Ctx.Pe);
}
UINTN
UefiImageLoaderGetDebugAddressPe (
IN CONST UEFI_IMAGE_LOADER_IMAGE_CONTEXT *Context
)
{
return PeCoffLoaderGetImageAddress (&Context->Ctx.Pe);
}
/**
Retrieves the memory protection attributes corresponding to PE/COFF Image
section permissions.
@ -750,6 +758,7 @@ GLOBAL_REMOVE_IF_UNREFERENCED CONST UEFI_IMAGE_FORMAT_SUPPORT mPeSupport = {
UefiImageGetBaseAddressPe,
UefiImageGetRelocsStrippedPe,
UefiImageLoaderGetImageAddressPe,
UefiImageLoaderGetDebugAddressPe,
UefiImageLoaderGetImageRecordPe,
UefiImageDebugLocateImagePe,
UefiImageGetFixedAddressPe,

View File

@ -176,6 +176,12 @@ UINTN
IN CONST UEFI_IMAGE_LOADER_IMAGE_CONTEXT *Context
);
typedef
UINTN
(*UEFI_IMAGE_LOADER_GET_DEBUG_ADDRESS) (
IN CONST UEFI_IMAGE_LOADER_IMAGE_CONTEXT *Context
);
typedef
UEFI_IMAGE_RECORD *
(*UEFI_IMAGE_LOADER_GET_IMAGE_RECORD) (
@ -226,6 +232,7 @@ typedef struct {
UEFI_IMAGE_GET_BASE_ADDRESS GetBaseAddress;
UEFI_IMAGE_GET_RELOCS_STRIPPED GetRelocsStripped;
UEFI_IMAGE_LOADER_GET_IMAGE_ADDRESS LoaderGetImageAddress;
UEFI_IMAGE_LOADER_GET_DEBUG_ADDRESS LoaderGetDebugAddress;
UEFI_IMAGE_LOADER_GET_IMAGE_RECORD LoaderGetImageRecord;
UEFI_IMAGE_DEBUG_LOCATE_IMAGE DebugLocateImage;
UEFI_IMAGE_GET_FIXED_ADDRESS GetFixedAddress;

View File

@ -565,6 +565,23 @@ UefiImageLoaderGetImageAddress (
return Result;
}
UINTN
UefiImageLoaderGetDebugAddress (
IN CONST UEFI_IMAGE_LOADER_IMAGE_CONTEXT *Context
)
{
UINTN Result;
UEFI_IMAGE_EXEC (
Result,
Context->FormatIndex,
LoaderGetDebugAddress,
Context
);
return Result;
}
UEFI_IMAGE_RECORD *
UefiImageLoaderGetImageRecord (
IN OUT UEFI_IMAGE_LOADER_IMAGE_CONTEXT *Context

View File

@ -211,11 +211,11 @@ GetImagePdb (
}
for (Entry = 0; Entry < DebugTableHeader->TableSize; Entry++, DebugTable++) {
if (DebugTable->NormalImage != NULL) {
if ((DebugTable->NormalImage->ImageInfoType == EFI_DEBUG_IMAGE_INFO_TYPE_NORMAL) &&
(DebugTable->NormalImage->LoadedImageProtocolInstance != NULL)) {
if (ImageBase == DebugTable->NormalImage->LoadedImageProtocolInstance->ImageBase) {
return DebugTable->NormalImage->PdbPath;
if (DebugTable->NormalImage2 != NULL) {
if ((DebugTable->NormalImage2->ImageInfoType == EFI_DEBUG_IMAGE_INFO_TYPE_NORMAL2) &&
(DebugTable->NormalImage2->LoadedImageProtocolInstance != NULL)) {
if (ImageBase == DebugTable->NormalImage2->LoadedImageProtocolInstance->ImageBase) {
return DebugTable->NormalImage2->PdbPath;
}
}
}

View File

@ -66,7 +66,7 @@ UefiImageLoaderExtraActionCommon (
RETURN_STATUS Status;
CONST CHAR8 *PdbPath;
UINT32 PdbPathSize;
EFI_PHYSICAL_ADDRESS ImageBase;
EFI_PHYSICAL_ADDRESS DebugBase;
ASSERT (ImageContext != NULL);
@ -111,7 +111,7 @@ UefiImageLoaderExtraActionCommon (
}
}
ImageBase = UefiImageLoaderGetImageAddress (ImageContext);
DebugBase = UefiImageLoaderGetDebugAddress (ImageContext);
//
// Save Debug Register State
@ -126,7 +126,7 @@ UefiImageLoaderExtraActionCommon (
//
// DR0 = Signature
// DR1 = The address of the Null-terminated ASCII string for the PE/COFF image's PDB file name
// DR2 = The pointer to the ImageBase address
// DR2 = The pointer to the DebugBase address
// DR3 = IO_PORT_BREAKPOINT_ADDRESS
// DR7 = Disables all HW breakpoints except for DR3 I/O port access of length 1 byte
// CR4 = Make sure DE(BIT3) is set
@ -134,7 +134,7 @@ UefiImageLoaderExtraActionCommon (
AsmWriteDr7 (BIT10);
AsmWriteDr0 (Signature);
AsmWriteDr1 ((UINTN)PdbPath);
AsmWriteDr2 ((UINTN)&ImageBase);
AsmWriteDr2 ((UINTN)&DebugBase);
AsmWriteDr3 (IO_PORT_BREAKPOINT_ADDRESS);
if (LoadImageMethod == DEBUG_LOAD_IMAGE_METHOD_IO_HW_BREAKPOINT) {
@ -172,7 +172,7 @@ UefiImageLoaderExtraActionCommon (
AsmWriteDr1 (Dr1);
}
if (!IsDrxEnabled (2, NewDr7) && (AsmReadDr2 () == (UINTN)&ImageBase)) {
if (!IsDrxEnabled (2, NewDr7) && (AsmReadDr2 () == (UINTN)&DebugBase)) {
AsmWriteDr2 (Dr2);
}

View File

@ -120,9 +120,10 @@ DumpModuleImageInfo (
{
BOOLEAN Result;
UINTN ImageBase;
UINTN DebugBase;
CONST CHAR8 *PdbPath;
Result = GetImageInfoByIp (&ImageBase, &PdbPath, CurrentEip);
Result = GetImageInfoByIp (&ImageBase, &DebugBase, &PdbPath, CurrentEip);
if (!Result) {
InternalPrintMessage ("!!!! Can't find image information. !!!!\n");
@ -139,8 +140,9 @@ DumpModuleImageInfo (
}
InternalPrintMessage (
" (ImageBase=%016lp) !!!!\n",
(EFI_PHYSICAL_ADDRESS) ImageBase
" (ImageBase=%016lp, DebugBase=%016lp) !!!!\n",
(EFI_PHYSICAL_ADDRESS) ImageBase,
(EFI_PHYSICAL_ADDRESS) DebugBase
);
}
}

View File

@ -327,6 +327,7 @@ AsmGetTssTemplateMap (
BOOLEAN
GetImageInfoByIp (
OUT UINTN *ImageBase,
OUT UINTN *DebugBase,
OUT CONST CHAR8 **SymbolsPath,
IN UINTN CurrentEip
);

View File

@ -143,13 +143,14 @@ InitializeSeparateExceptionStacks (
BOOLEAN
GetImageInfoByIp (
OUT UINTN *ImageBase,
OUT UINTN *DebugBase,
OUT CONST CHAR8 **SymbolsPath,
IN UINTN CurrentEip
)
{
EFI_STATUS Status;
UINT32 Index;
CONST EFI_DEBUG_IMAGE_INFO_NORMAL *NormalImage;
EFI_STATUS Status;
UINT32 Index;
CONST EFI_DEBUG_IMAGE_INFO_NORMAL2 *NormalImage2;
if (mDebugImageInfoTable == NULL) {
Status = EfiGetSystemConfigurationTable (
@ -169,18 +170,19 @@ GetImageInfoByIp (
continue;
}
if (*mDebugImageInfoTable->EfiDebugImageInfoTable[Index].ImageInfoType != EFI_DEBUG_IMAGE_INFO_TYPE_NORMAL) {
if (*mDebugImageInfoTable->EfiDebugImageInfoTable[Index].ImageInfoType != EFI_DEBUG_IMAGE_INFO_TYPE_NORMAL2) {
continue;
}
NormalImage = mDebugImageInfoTable->EfiDebugImageInfoTable[Index].NormalImage;
NormalImage2 = mDebugImageInfoTable->EfiDebugImageInfoTable[Index].NormalImage2;
ASSERT (NormalImage->LoadedImageProtocolInstance != NULL);
ASSERT (NormalImage2->LoadedImageProtocolInstance != NULL);
if (CurrentEip >= (UINTN) NormalImage->LoadedImageProtocolInstance->ImageBase &&
CurrentEip < (UINTN) NormalImage->LoadedImageProtocolInstance->ImageBase + NormalImage->LoadedImageProtocolInstance->ImageSize) {
*ImageBase = (UINTN) NormalImage->LoadedImageProtocolInstance->ImageBase;
*SymbolsPath = NormalImage->PdbPath;
if (CurrentEip >= (UINTN) NormalImage2->LoadedImageProtocolInstance->ImageBase &&
CurrentEip < (UINTN) NormalImage2->LoadedImageProtocolInstance->ImageBase + NormalImage2->LoadedImageProtocolInstance->ImageSize) {
*ImageBase = (UINTN) NormalImage2->LoadedImageProtocolInstance->ImageBase;
*DebugBase = NormalImage2->DebugBase;
*SymbolsPath = NormalImage2->PdbPath;
return TRUE;
}
}

View File

@ -218,6 +218,7 @@ InitializeSeparateExceptionStacks (
BOOLEAN
GetImageInfoByIp (
OUT UINTN *ImageBase,
OUT UINTN *DebugBase,
OUT CONST CHAR8 **SymbolsPath,
IN UINTN CurrentEip
)
@ -232,6 +233,7 @@ GetImageInfoByIp (
}
*ImageBase = UefiImageLoaderGetImageAddress (&ImageContext);
*DebugBase = UefiImageLoaderGetDebugAddress (&ImageContext);
Status = UefiImageGetSymbolsPath (&ImageContext, SymbolsPath, &PdbPathSize);
return !RETURN_ERROR (Status);

View File

@ -226,6 +226,7 @@ InitializeSeparateExceptionStacks (
BOOLEAN
GetImageInfoByIp (
OUT UINTN *ImageBase,
OUT UINTN *DebugBase,
OUT CONST CHAR8 **SymbolsPath,
IN UINTN CurrentEip
)

View File

@ -150,13 +150,14 @@ InternalGetSystemConfigurationTable (
BOOLEAN
GetImageInfoByIp (
OUT UINTN *ImageBase,
OUT UINTN *DebugBase,
OUT CONST CHAR8 **SymbolsPath,
IN UINTN CurrentEip
)
{
EFI_STATUS Status;
UINT32 Index;
CONST EFI_DEBUG_IMAGE_INFO_NORMAL *NormalImage;
EFI_STATUS Status;
UINT32 Index;
CONST EFI_DEBUG_IMAGE_INFO_NORMAL2 *NormalImage2;
if (mDebugImageInfoTableHeader == NULL) {
Status = InternalGetSystemConfigurationTable (
@ -176,18 +177,19 @@ GetImageInfoByIp (
continue;
}
if (*mDebugImageInfoTableHeader->EfiDebugImageInfoTable[Index].ImageInfoType != EFI_DEBUG_IMAGE_INFO_TYPE_NORMAL) {
if (*mDebugImageInfoTableHeader->EfiDebugImageInfoTable[Index].ImageInfoType != EFI_DEBUG_IMAGE_INFO_TYPE_NORMAL2) {
continue;
}
NormalImage = mDebugImageInfoTableHeader->EfiDebugImageInfoTable[Index].NormalImage;
NormalImage2 = mDebugImageInfoTableHeader->EfiDebugImageInfoTable[Index].NormalImage2;
ASSERT (NormalImage->LoadedImageProtocolInstance != NULL);
ASSERT (NormalImage2->LoadedImageProtocolInstance != NULL);
if (CurrentEip >= (UINTN) NormalImage->LoadedImageProtocolInstance->ImageBase &&
CurrentEip < (UINTN) NormalImage->LoadedImageProtocolInstance->ImageBase + NormalImage->LoadedImageProtocolInstance->ImageSize) {
*ImageBase = (UINTN) NormalImage->LoadedImageProtocolInstance->ImageBase;
*SymbolsPath = NormalImage->PdbPath;
if (CurrentEip >= (UINTN) NormalImage2->LoadedImageProtocolInstance->ImageBase &&
CurrentEip < (UINTN) NormalImage2->LoadedImageProtocolInstance->ImageBase + NormalImage2->LoadedImageProtocolInstance->ImageSize) {
*ImageBase = (UINTN) NormalImage2->LoadedImageProtocolInstance->ImageBase;
*DebugBase = NormalImage2->DebugBase;
*SymbolsPath = NormalImage2->PdbPath;
return TRUE;
}
}

View File

@ -190,14 +190,14 @@ SmmGetSystemConfigurationTable (
CONST EFI_DEBUG_IMAGE_INFO_TABLE_HEADER *mDebugImageInfoTableHeader = NULL;
// FIXME:
CONST EFI_DEBUG_IMAGE_INFO_NORMAL *
CONST EFI_DEBUG_IMAGE_INFO_NORMAL2 *
InternalLocateImage (
IN UINTN CurrentEip
)
{
EFI_STATUS Status;
UINT32 Index;
CONST EFI_DEBUG_IMAGE_INFO_NORMAL *NormalImage;
CONST EFI_DEBUG_IMAGE_INFO_NORMAL2 *NormalImage2;
if (mDebugImageInfoTableHeader == NULL) {
Status = SmmGetSystemConfigurationTable (
@ -217,17 +217,17 @@ InternalLocateImage (
continue;
}
if (*mDebugImageInfoTableHeader->EfiDebugImageInfoTable[Index].ImageInfoType != EFI_DEBUG_IMAGE_INFO_TYPE_NORMAL) {
if (*mDebugImageInfoTableHeader->EfiDebugImageInfoTable[Index].ImageInfoType != EFI_DEBUG_IMAGE_INFO_TYPE_NORMAL2) {
continue;
}
NormalImage = mDebugImageInfoTableHeader->EfiDebugImageInfoTable[Index].NormalImage;
NormalImage2 = mDebugImageInfoTableHeader->EfiDebugImageInfoTable[Index].NormalImage2;
ASSERT (NormalImage->LoadedImageProtocolInstance != NULL);
ASSERT (NormalImage2->LoadedImageProtocolInstance != NULL);
if (CurrentEip >= (UINTN) NormalImage->LoadedImageProtocolInstance->ImageBase &&
CurrentEip < (UINTN) NormalImage->LoadedImageProtocolInstance->ImageBase + NormalImage->LoadedImageProtocolInstance->ImageSize) {
return NormalImage;
if (CurrentEip >= (UINTN) NormalImage2->LoadedImageProtocolInstance->ImageBase &&
CurrentEip < (UINTN) NormalImage2->LoadedImageProtocolInstance->ImageBase + NormalImage2->LoadedImageProtocolInstance->ImageSize) {
return NormalImage2;
}
}
@ -245,17 +245,17 @@ DumpModuleInfoByIp (
IN UINTN CallerIpAddress
)
{
CONST EFI_DEBUG_IMAGE_INFO_NORMAL *NormalImage;
CONST EFI_DEBUG_IMAGE_INFO_NORMAL2 *NormalImage2;
NormalImage = InternalLocateImage (CallerIpAddress);
NormalImage2 = InternalLocateImage (CallerIpAddress);
//
// Find Image Base
//
if (NormalImage != NULL) {
if (NormalImage2 != NULL) {
DEBUG ((DEBUG_ERROR, "It is invoked from the instruction before IP(0x%p)", (VOID *)CallerIpAddress));
if (NormalImage->PdbPath!= NULL) {
DEBUG ((DEBUG_ERROR, " in module (%a)\n", NormalImage->PdbPath));
if (NormalImage2->PdbPath!= NULL) {
DEBUG ((DEBUG_ERROR, " in module (%a)\n", NormalImage2->PdbPath));
}
}
}