diff --git a/ArmPkg/Library/DebugUefiImageExtraActionLib/DebugUefiImageExtraActionLib.c b/ArmPkg/Library/DebugUefiImageExtraActionLib/DebugUefiImageExtraActionLib.c index db74ff779b..2ffcba1646 100644 --- a/ArmPkg/Library/DebugUefiImageExtraActionLib/DebugUefiImageExtraActionLib.c +++ b/ArmPkg/Library/DebugUefiImageExtraActionLib/DebugUefiImageExtraActionLib.c @@ -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))); } } diff --git a/ArmPkg/Library/DefaultExceptionHandlerLib/AArch64/DefaultExceptionHandler.c b/ArmPkg/Library/DefaultExceptionHandlerLib/AArch64/DefaultExceptionHandler.c index 93814bb266..a5f04c04ce 100644 --- a/ArmPkg/Library/DefaultExceptionHandlerLib/AArch64/DefaultExceptionHandler.c +++ b/ArmPkg/Library/DefaultExceptionHandlerLib/AArch64/DefaultExceptionHandler.c @@ -38,7 +38,8 @@ STATIC BOOLEAN mRecursiveException; CONST CHAR8 * GetImageName ( IN UINTN FaultAddress, - OUT UINTN *ImageBase + OUT UINTN *ImageBase, + OUT UINTN *DebugBase ); STATIC @@ -211,18 +212,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 { @@ -240,7 +243,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++; @@ -249,10 +252,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) )); @@ -261,14 +265,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; diff --git a/ArmPkg/Library/DefaultExceptionHandlerLib/Arm/DefaultExceptionHandler.c b/ArmPkg/Library/DefaultExceptionHandlerLib/Arm/DefaultExceptionHandler.c index d05b2f7d80..eb9b4ee7b7 100644 --- a/ArmPkg/Library/DefaultExceptionHandlerLib/Arm/DefaultExceptionHandler.c +++ b/ArmPkg/Library/DefaultExceptionHandlerLib/Arm/DefaultExceptionHandler.c @@ -55,7 +55,8 @@ STATIC CONST CPSR_CHAR mCpsrChar[] = { CONST CHAR8 * GetImageName ( IN UINTN FaultAddress, - OUT UINTN *ImageBase + OUT UINTN *ImageBase, + OUT UINTN *DebugBase ); /** @@ -225,6 +226,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 @@ -232,7 +234,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)); @@ -247,7 +249,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)); } DEBUG_CODE_END (); diff --git a/ArmPkg/Library/DefaultExceptionHandlerLib/DefaultExceptionHandlerUefi.c b/ArmPkg/Library/DefaultExceptionHandlerLib/DefaultExceptionHandlerUefi.c index 290827a99b..dc049ae6b4 100644 --- a/ArmPkg/Library/DefaultExceptionHandlerLib/DefaultExceptionHandlerUefi.c +++ b/ArmPkg/Library/DefaultExceptionHandlerLib/DefaultExceptionHandlerUefi.c @@ -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; } } } diff --git a/BaseTools/ImageTool/PeEmit.c b/BaseTools/ImageTool/PeEmit.c index 910d5125a7..305f42f945 100644 --- a/BaseTools/ImageTool/PeEmit.c +++ b/BaseTools/ImageTool/PeEmit.c @@ -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; diff --git a/EmbeddedPkg/GdbStub/GdbStub.c b/EmbeddedPkg/GdbStub/GdbStub.c index 3d317cb05a..6e4f894a21 100644 --- a/EmbeddedPkg/GdbStub/GdbStub.c +++ b/EmbeddedPkg/GdbStub/GdbStub.c @@ -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, diff --git a/EmulatorPkg/Unix/Host/Host.c b/EmulatorPkg/Unix/Host/Host.c index 5400f8b5ce..8142e8c5c6 100644 --- a/EmulatorPkg/Unix/Host/Host.c +++ b/EmulatorPkg/Unix/Host/Host.c @@ -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); } diff --git a/MdeModulePkg/Application/MemoryProfileInfo/MemoryProfileInfo.c b/MdeModulePkg/Application/MemoryProfileInfo/MemoryProfileInfo.c index 326603503f..80f2eb26ac 100644 --- a/MdeModulePkg/Application/MemoryProfileInfo/MemoryProfileInfo.c +++ b/MdeModulePkg/Application/MemoryProfileInfo/MemoryProfileInfo.c @@ -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"); } diff --git a/MdeModulePkg/Core/Dxe/DxeMain.h b/MdeModulePkg/Core/Dxe/DxeMain.h index 53df82381d..77397b6367 100644 --- a/MdeModulePkg/Core/Dxe/DxeMain.h +++ b/MdeModulePkg/Core/Dxe/DxeMain.h @@ -2374,20 +2374,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 ); /** diff --git a/MdeModulePkg/Core/Dxe/DxeMain/DxeMain.c b/MdeModulePkg/Core/Dxe/DxeMain/DxeMain.c index d567400e1e..83cd23363a 100644 --- a/MdeModulePkg/Core/Dxe/DxeMain/DxeMain.c +++ b/MdeModulePkg/Core/Dxe/DxeMain/DxeMain.c @@ -401,7 +401,6 @@ DxeMain ( // CoreInitializeDebugImageInfoTable (); CoreNewDebugImageInfoEntry ( - EFI_DEBUG_IMAGE_INFO_TYPE_NORMAL, gDxeCoreLoadedImage, gImageHandle, &ImageContext diff --git a/MdeModulePkg/Core/Dxe/Image/Image.c b/MdeModulePkg/Core/Dxe/Image/Image.c index 34db9746ea..c12d234dfa 100644 --- a/MdeModulePkg/Core/Dxe/Image/Image.c +++ b/MdeModulePkg/Core/Dxe/Image/Image.c @@ -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); } // diff --git a/MdeModulePkg/Core/Dxe/Mem/MemoryProfileRecord.c b/MdeModulePkg/Core/Dxe/Mem/MemoryProfileRecord.c index b67596f48e..f19a5d8abd 100644 --- a/MdeModulePkg/Core/Dxe/Mem/MemoryProfileRecord.c +++ b/MdeModulePkg/Core/Dxe/Mem/MemoryProfileRecord.c @@ -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); diff --git a/MdeModulePkg/Core/Dxe/Misc/DebugImageInfo.c b/MdeModulePkg/Core/Dxe/Misc/DebugImageInfo.c index 9074de9670..072d55c105 100644 --- a/MdeModulePkg/Core/Dxe/Misc/DebugImageInfo.c +++ b/MdeModulePkg/Core/Dxe/Misc/DebugImageInfo.c @@ -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; + } } } diff --git a/MdeModulePkg/Core/Pei/Image/Image.c b/MdeModulePkg/Core/Pei/Image/Image.c index 506e3488a0..277e2806d7 100644 --- a/MdeModulePkg/Core/Pei/Image/Image.c +++ b/MdeModulePkg/Core/Pei/Image/Image.c @@ -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))); } // diff --git a/MdeModulePkg/Core/PiSmmCore/DebugImageInfo.c b/MdeModulePkg/Core/PiSmmCore/DebugImageInfo.c index 1812eacc2d..499e93791a 100644 --- a/MdeModulePkg/Core/PiSmmCore/DebugImageInfo.c +++ b/MdeModulePkg/Core/PiSmmCore/DebugImageInfo.c @@ -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; diff --git a/MdeModulePkg/Core/PiSmmCore/Dispatcher.c b/MdeModulePkg/Core/PiSmmCore/Dispatcher.c index 068fcee891..fb0e861463 100644 --- a/MdeModulePkg/Core/PiSmmCore/Dispatcher.c +++ b/MdeModulePkg/Core/PiSmmCore/Dispatcher.c @@ -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 diff --git a/MdeModulePkg/Core/PiSmmCore/PiSmmCore.c b/MdeModulePkg/Core/PiSmmCore/PiSmmCore.c index 9f3e9392e8..0a6d8c9aab 100644 --- a/MdeModulePkg/Core/PiSmmCore/PiSmmCore.c +++ b/MdeModulePkg/Core/PiSmmCore/PiSmmCore.c @@ -876,7 +876,6 @@ SmmCoreInstallLoadedImage ( // SmmInitializeDebugImageInfoTable (); SmmNewDebugImageInfoEntry ( - EFI_DEBUG_IMAGE_INFO_TYPE_NORMAL, &mSmmCoreDriverEntry->SmmLoadedImage, mSmmCoreDriverEntry->SmmImageHandle, &gSmmCorePrivate->PiSmmCoreImageContext diff --git a/MdeModulePkg/Core/PiSmmCore/PiSmmCore.h b/MdeModulePkg/Core/PiSmmCore/PiSmmCore.h index 6b33a9d34a..71e826e198 100644 --- a/MdeModulePkg/Core/PiSmmCore/PiSmmCore.h +++ b/MdeModulePkg/Core/PiSmmCore/PiSmmCore.h @@ -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 ); /** diff --git a/MdeModulePkg/Core/PiSmmCore/PiSmmIpl.c b/MdeModulePkg/Core/PiSmmCore/PiSmmIpl.c index 8b78d965af..b3ca963049 100644 --- a/MdeModulePkg/Core/PiSmmCore/PiSmmIpl.c +++ b/MdeModulePkg/Core/PiSmmCore/PiSmmIpl.c @@ -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))); // diff --git a/MdeModulePkg/Core/PiSmmCore/SmramProfileRecord.c b/MdeModulePkg/Core/PiSmmCore/SmramProfileRecord.c index 1fa33efbbe..ebd7ff1c8c 100644 --- a/MdeModulePkg/Core/PiSmmCore/SmramProfileRecord.c +++ b/MdeModulePkg/Core/PiSmmCore/SmramProfileRecord.c @@ -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) { diff --git a/MdeModulePkg/Include/Guid/MemoryProfile.h b/MdeModulePkg/Include/Guid/MemoryProfile.h index 33a033bb00..ab24477cc9 100644 --- a/MdeModulePkg/Include/Guid/MemoryProfile.h +++ b/MdeModulePkg/Include/Guid/MemoryProfile.h @@ -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; diff --git a/MdeModulePkg/Universal/EbcDxe/EbcDebugger/EdbSymbol.c b/MdeModulePkg/Universal/EbcDxe/EbcDebugger/EdbSymbol.c index cf8ff3d371..c00cef68b1 100644 --- a/MdeModulePkg/Universal/EbcDxe/EbcDebugger/EdbSymbol.c +++ b/MdeModulePkg/Universal/EbcDxe/EbcDebugger/EdbSymbol.c @@ -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; } diff --git a/MdePkg/Include/Guid/DebugImageInfoTable.h b/MdePkg/Include/Guid/DebugImageInfoTable.h index 82f337f67e..44b9fce337 100644 --- a/MdePkg/Include/Guid/DebugImageInfoTable.h +++ b/MdePkg/Include/Guid/DebugImageInfoTable.h @@ -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 { diff --git a/MdePkg/Include/IndustryStandard/PeImage.h b/MdePkg/Include/IndustryStandard/PeImage.h index cfcabad63f..bafe707600 100644 --- a/MdePkg/Include/IndustryStandard/PeImage.h +++ b/MdePkg/Include/IndustryStandard/PeImage.h @@ -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; diff --git a/MdePkg/Include/Library/UefiImageLib.h b/MdePkg/Include/Library/UefiImageLib.h index 1bd574e775..7528f3a6eb 100644 --- a/MdePkg/Include/Library/UefiImageLib.h +++ b/MdePkg/Include/Library/UefiImageLib.h @@ -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_ diff --git a/MdePkg/Library/BaseUefiImageLib/PeSupport.c b/MdePkg/Library/BaseUefiImageLib/PeSupport.c index b03b85ee25..27dff54b7f 100644 --- a/MdePkg/Library/BaseUefiImageLib/PeSupport.c +++ b/MdePkg/Library/BaseUefiImageLib/PeSupport.c @@ -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, diff --git a/MdePkg/Library/BaseUefiImageLib/UefiImageFormat.h b/MdePkg/Library/BaseUefiImageLib/UefiImageFormat.h index efe7048891..da64c5c462 100644 --- a/MdePkg/Library/BaseUefiImageLib/UefiImageFormat.h +++ b/MdePkg/Library/BaseUefiImageLib/UefiImageFormat.h @@ -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; diff --git a/MdePkg/Library/BaseUefiImageLib/UefiImageLib.c b/MdePkg/Library/BaseUefiImageLib/UefiImageLib.c index 6e9eaa9364..18d323f585 100644 --- a/MdePkg/Library/BaseUefiImageLib/UefiImageLib.c +++ b/MdePkg/Library/BaseUefiImageLib/UefiImageLib.c @@ -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 diff --git a/ShellPkg/DynamicCommand/DpDynamicCommand/DpUtilities.c b/ShellPkg/DynamicCommand/DpDynamicCommand/DpUtilities.c index 240093dc26..4d0079898c 100644 --- a/ShellPkg/DynamicCommand/DpDynamicCommand/DpUtilities.c +++ b/ShellPkg/DynamicCommand/DpDynamicCommand/DpUtilities.c @@ -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; } } } diff --git a/SourceLevelDebugPkg/Library/UefiImageExtraActionLibDebug/UefiImageExtraActionLib.c b/SourceLevelDebugPkg/Library/UefiImageExtraActionLibDebug/UefiImageExtraActionLib.c index 35f7db1258..c624f911f6 100644 --- a/SourceLevelDebugPkg/Library/UefiImageExtraActionLibDebug/UefiImageExtraActionLib.c +++ b/SourceLevelDebugPkg/Library/UefiImageExtraActionLibDebug/UefiImageExtraActionLib.c @@ -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); } diff --git a/UefiCpuPkg/Library/CpuExceptionHandlerLib/CpuExceptionCommon.c b/UefiCpuPkg/Library/CpuExceptionHandlerLib/CpuExceptionCommon.c index 76ea152955..1599fa8e51 100644 --- a/UefiCpuPkg/Library/CpuExceptionHandlerLib/CpuExceptionCommon.c +++ b/UefiCpuPkg/Library/CpuExceptionHandlerLib/CpuExceptionCommon.c @@ -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 ); } } diff --git a/UefiCpuPkg/Library/CpuExceptionHandlerLib/CpuExceptionCommon.h b/UefiCpuPkg/Library/CpuExceptionHandlerLib/CpuExceptionCommon.h index 6d3dc46b6e..0356abd7ab 100644 --- a/UefiCpuPkg/Library/CpuExceptionHandlerLib/CpuExceptionCommon.h +++ b/UefiCpuPkg/Library/CpuExceptionHandlerLib/CpuExceptionCommon.h @@ -327,6 +327,7 @@ AsmGetTssTemplateMap ( BOOLEAN GetImageInfoByIp ( OUT UINTN *ImageBase, + OUT UINTN *DebugBase, OUT CONST CHAR8 **SymbolsPath, IN UINTN CurrentEip ); diff --git a/UefiCpuPkg/Library/CpuExceptionHandlerLib/DxeException.c b/UefiCpuPkg/Library/CpuExceptionHandlerLib/DxeException.c index 2a4fca621a..30731a8071 100644 --- a/UefiCpuPkg/Library/CpuExceptionHandlerLib/DxeException.c +++ b/UefiCpuPkg/Library/CpuExceptionHandlerLib/DxeException.c @@ -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; } } diff --git a/UefiCpuPkg/Library/CpuExceptionHandlerLib/PeiCpuException.c b/UefiCpuPkg/Library/CpuExceptionHandlerLib/PeiCpuException.c index 2e49bd88b6..6c109f6353 100644 --- a/UefiCpuPkg/Library/CpuExceptionHandlerLib/PeiCpuException.c +++ b/UefiCpuPkg/Library/CpuExceptionHandlerLib/PeiCpuException.c @@ -230,6 +230,7 @@ InitializeSeparateExceptionStacks ( BOOLEAN GetImageInfoByIp ( OUT UINTN *ImageBase, + OUT UINTN *DebugBase, OUT CONST CHAR8 **SymbolsPath, IN UINTN CurrentEip ) @@ -244,6 +245,7 @@ GetImageInfoByIp ( } *ImageBase = UefiImageLoaderGetImageAddress (&ImageContext); + *DebugBase = UefiImageLoaderGetDebugAddress (&ImageContext); Status = UefiImageGetSymbolsPath (&ImageContext, SymbolsPath, &PdbPathSize); return !RETURN_ERROR (Status); diff --git a/UefiCpuPkg/Library/CpuExceptionHandlerLib/SecPeiCpuException.c b/UefiCpuPkg/Library/CpuExceptionHandlerLib/SecPeiCpuException.c index 8351d29b96..41e9091e1a 100644 --- a/UefiCpuPkg/Library/CpuExceptionHandlerLib/SecPeiCpuException.c +++ b/UefiCpuPkg/Library/CpuExceptionHandlerLib/SecPeiCpuException.c @@ -226,6 +226,7 @@ InitializeSeparateExceptionStacks ( BOOLEAN GetImageInfoByIp ( OUT UINTN *ImageBase, + OUT UINTN *DebugBase, OUT CONST CHAR8 **SymbolsPath, IN UINTN CurrentEip ) diff --git a/UefiCpuPkg/Library/CpuExceptionHandlerLib/SmmException.c b/UefiCpuPkg/Library/CpuExceptionHandlerLib/SmmException.c index d14d00aa7e..4e02f35fa2 100644 --- a/UefiCpuPkg/Library/CpuExceptionHandlerLib/SmmException.c +++ b/UefiCpuPkg/Library/CpuExceptionHandlerLib/SmmException.c @@ -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; } } diff --git a/UefiCpuPkg/PiSmmCpuDxeSmm/PiSmmCpuDxeSmm.c b/UefiCpuPkg/PiSmmCpuDxeSmm/PiSmmCpuDxeSmm.c index 38724cddd7..d19eda5c31 100644 --- a/UefiCpuPkg/PiSmmCpuDxeSmm/PiSmmCpuDxeSmm.c +++ b/UefiCpuPkg/PiSmmCpuDxeSmm/PiSmmCpuDxeSmm.c @@ -52,14 +52,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 ( @@ -79,17 +79,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; } }