Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MdePkg: Convert new normal debug info to separate struct #59

Merged
merged 2 commits into from
Dec 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
6 changes: 3 additions & 3 deletions BaseTools/ImageTool/PeEmit.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -583,7 +583,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;
Expand Down
10 changes: 5 additions & 5 deletions BaseTools/ImageTool/UeEmit.c
Original file line number Diff line number Diff line change
Expand Up @@ -598,7 +598,7 @@ ToolImageEmitUeDebugTable (
)
{
UE_DEBUG_TABLE DebugTable;
uint8_t SymOffsetFactor;
uint8_t SymSubtrahendFactor;
uint32_t DebugTableOffset;
uint32_t DebugTableSize;
uint16_t Index;
Expand All @@ -609,14 +609,14 @@ ToolImageEmitUeDebugTable (
assert (Image->DebugInfo.SymbolsPathLen <= MAX_UINT8);
assert (IS_ALIGNED (BaseAddressSubtrahend, Image->SegmentInfo.SegmentAlignment));

SymOffsetFactor = (uint8_t)(BaseAddressSubtrahend / Image->SegmentInfo.SegmentAlignment);
if (SymOffsetFactor > 0x03) {
SymSubtrahendFactor = (uint8_t)(BaseAddressSubtrahend / Image->SegmentInfo.SegmentAlignment);
if (SymSubtrahendFactor > 0x03) {
DEBUG_RAISE ();
return false;
}

DebugTable.ImageInfo = SymOffsetFactor;
assert (UE_DEBUG_TABLE_IMAGE_INFO_SYM_OFFSET_FACTOR (DebugTable.ImageInfo) == SymOffsetFactor);
DebugTable.ImageInfo = SymSubtrahendFactor;
assert (UE_DEBUG_TABLE_IMAGE_INFO_SYM_SUBTRAHEND_FACTOR (DebugTable.ImageInfo) == SymSubtrahendFactor);
assert ((DebugTable.ImageInfo & 0xFCU) == 0);

DebugTable.SymbolsPathLength = (uint8_t)Image->DebugInfo.SymbolsPathLen;
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
93 changes: 50 additions & 43 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,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;
}
}
}

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
Loading