Skip to content

Commit

Permalink
MdePkg: Convert new normal debug info to separate struct
Browse files Browse the repository at this point in the history
  • Loading branch information
mikebeaton committed Nov 27, 2023
1 parent 100f289 commit 3e6fb77
Show file tree
Hide file tree
Showing 15 changed files with 160 additions and 119 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -50,16 +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;
*DebugBase = (UINTN)DebugTable->NormalImage->DebugBase;
return DebugTable->NormalImage->PdbPath;
*ImageBase = (UINTN)DebugTable->NormalImage2->LoadedImageProtocolInstance->ImageBase;
*DebugBase = (UINTN)DebugTable->NormalImage2->DebugBase;
return DebugTable->NormalImage2->PdbPath;
}
}
}
Expand Down
8 changes: 4 additions & 4 deletions EmbeddedPkg/GdbStub/GdbStub.c
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
9 changes: 4 additions & 5 deletions MdeModulePkg/Core/Dxe/DxeMain.h
Original file line number Diff line number Diff line change
Expand Up @@ -2369,18 +2369,17 @@ CoreUpdateDebugTableCrc32 (
Adds a new DebugImageInfo structure to the DebugImageInfo Table. Re-Allocates
the table if it's not large enough to accomidate 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
);

/**
Expand Down
1 change: 0 additions & 1 deletion MdeModulePkg/Core/Dxe/DxeMain/DxeMain.c
Original file line number Diff line number Diff line change
Expand Up @@ -389,7 +389,6 @@ DxeMain (
//
CoreInitializeDebugImageInfoTable ();
CoreNewDebugImageInfoEntry (
EFI_DEBUG_IMAGE_INFO_TYPE_NORMAL,
gDxeCoreLoadedImage,
gImageHandle,
&ImageContext
Expand Down
2 changes: 1 addition & 1 deletion MdeModulePkg/Core/Dxe/Image/Image.c
Original file line number Diff line number Diff line change
Expand Up @@ -1385,7 +1385,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);
}

//
Expand Down
62 changes: 31 additions & 31 deletions MdeModulePkg/Core/Dxe/Misc/DebugImageInfo.c
Original file line number Diff line number Diff line change
Expand Up @@ -152,28 +152,27 @@ CoreUpdateDebugTableCrc32 (
Adds a new DebugImageInfo structure to the DebugImageInfo Table. Re-Allocates
the table if it's not large enough to accomidate 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.
Expand All @@ -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++;
}

Expand Down Expand Up @@ -232,26 +231,27 @@ 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->Size = sizeof (EFI_DEBUG_IMAGE_INFO_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);
}

NormalImage->DebugBase = UefiImageLoaderGetDebugAddress (ImageContext);
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++;
}

Expand All @@ -269,33 +269,33 @@ 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)) {
if ((Table[Index].NormalImage2 != NULL) && (Table[Index].NormalImage2->ImageHandle == ImageHandle)) {
//
// Found a match. Free up the record, then NULL the pointer to indicate the slot
// is free.
//
NormalImage = Table[Index].NormalImage;
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].NormalImage = NULL;
Table[Index].NormalImage2 = NULL;

if (NormalImage->PdbPath != NULL) {
FreePool (NormalImage->PdbPath);
if (NormalImage2->PdbPath != NULL) {
FreePool (NormalImage2->PdbPath);
}

CoreFreePool (NormalImage);
CoreFreePool (NormalImage2);
break;
}
}
Expand Down
34 changes: 17 additions & 17 deletions MdeModulePkg/Core/PiSmmCore/DebugImageInfo.c
Original file line number Diff line number Diff line change
Expand Up @@ -65,14 +65,14 @@ SmmNewDebugImageInfoEntry (
IN OUT 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.
Expand All @@ -86,7 +86,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++;
}
//
Expand Down Expand Up @@ -129,26 +129,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 = (UINT32) ImageInfoType;
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);
}

NormalImage->DebugBase = UefiImageLoaderGetDebugAddress (ImageContext);
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;
Expand Down
2 changes: 1 addition & 1 deletion MdeModulePkg/Core/PiSmmCore/Dispatcher.c
Original file line number Diff line number Diff line change
Expand Up @@ -572,7 +572,7 @@ SmmLoadImage (
// Register the image in the Debug Image Info Table if the attribute is set
//
SmmNewDebugImageInfoEntry (
EFI_DEBUG_IMAGE_INFO_TYPE_NORMAL,
EFI_DEBUG_IMAGE_INFO_TYPE_NORMAL2,
&DriverEntry->SmmLoadedImage,
DriverEntry->SmmImageHandle,
ImageContext
Expand Down
2 changes: 1 addition & 1 deletion MdeModulePkg/Core/PiSmmCore/PiSmmCore.c
Original file line number Diff line number Diff line change
Expand Up @@ -859,7 +859,7 @@ SmmCoreInstallLoadedImage (
//
SmmInitializeDebugImageInfoTable ();
SmmNewDebugImageInfoEntry (
EFI_DEBUG_IMAGE_INFO_TYPE_NORMAL,
EFI_DEBUG_IMAGE_INFO_TYPE_NORMAL2,
&mSmmCoreDriverEntry->SmmLoadedImage,
mSmmCoreDriverEntry->SmmImageHandle,
&gSmmCorePrivate->PiSmmCoreImageContext
Expand Down
6 changes: 3 additions & 3 deletions MdeModulePkg/Universal/EbcDxe/EbcDebugger/EdbSymbol.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
57 changes: 50 additions & 7 deletions MdePkg/Include/Guid/DebugImageInfoTable.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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;
///
Expand All @@ -47,13 +48,55 @@ typedef struct {
/// Indicates the image handle of the associated image.
///
EFI_HANDLE ImageHandle;
CHAR8 *PdbPath;
UINTN DebugBase;
} 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;
///
/// The size of the current instance of this struct, including any
/// custom extensions.
///
UINTN Size;
///
/// 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 {
Expand Down
Loading

0 comments on commit 3e6fb77

Please sign in to comment.