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 28, 2023
1 parent 100f289 commit c95e9b8
Show file tree
Hide file tree
Showing 19 changed files with 169 additions and 142 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: 2 additions & 6 deletions BaseTools/ImageTool/PeEmit.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,8 @@ typedef struct {
EFI_IMAGE_DEBUG_CODEVIEW_NB10_ENTRY Nb10;
} image_tool_debug_dir_t;

#define SIZE_OF_DATA_DIRECRORY \
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
sizeof (EFI_IMAGE_NT_HEADERS) - sizeof (EFI_IMAGE_NT_HEADERS_COMMON_HDR)

static
bool
Expand Down Expand Up @@ -583,7 +579,7 @@ ToolImageEmitPeFile (
return false;
}

SectionHeadersOffset = sizeof (*PeHdr) + SIZE_OF_DATA_DIRECRORY;
SectionHeadersOffset = sizeof (*PeHdr);
SectionHeadersSize = NumSections * sizeof (EFI_IMAGE_SECTION_HEADER);
SizeOfPeHeaders = SectionHeadersOffset + SectionHeadersSize;
SizeOfHeaders = sizeof (mDosHdr) + SizeOfPeHeaders;
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
11 changes: 5 additions & 6 deletions MdeModulePkg/Core/Dxe/DxeMain.h
Original file line number Diff line number Diff line change
Expand Up @@ -2367,20 +2367,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
);

/**
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
63 changes: 31 additions & 32 deletions MdeModulePkg/Core/Dxe/Misc/DebugImageInfo.c
Original file line number Diff line number Diff line change
Expand Up @@ -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.
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,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);
}

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 +268,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
45 changes: 22 additions & 23 deletions MdeModulePkg/Core/PiSmmCore/DebugImageInfo.c
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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++;
}
//
Expand Down Expand Up @@ -129,26 +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);
}

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
1 change: 0 additions & 1 deletion MdeModulePkg/Core/PiSmmCore/Dispatcher.c
Original file line number Diff line number Diff line change
Expand Up @@ -572,7 +572,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
Expand Down
1 change: 0 additions & 1 deletion MdeModulePkg/Core/PiSmmCore/PiSmmCore.c
Original file line number Diff line number Diff line change
Expand Up @@ -859,7 +859,6 @@ SmmCoreInstallLoadedImage (
//
SmmInitializeDebugImageInfoTable ();
SmmNewDebugImageInfoEntry (
EFI_DEBUG_IMAGE_INFO_TYPE_NORMAL,
&mSmmCoreDriverEntry->SmmLoadedImage,
mSmmCoreDriverEntry->SmmImageHandle,
&gSmmCorePrivate->PiSmmCoreImageContext
Expand Down
11 changes: 5 additions & 6 deletions MdeModulePkg/Core/PiSmmCore/PiSmmCore.h
Original file line number Diff line number Diff line change
Expand Up @@ -1374,20 +1374,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
);

/**
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
Loading

0 comments on commit c95e9b8

Please sign in to comment.