MdeModulePkg: Update DumpImageRecord() in ImagePropertiesRecordLib

Update DumpImageRecord() to be DumpImageRecords(), and improve
the debug output. The function will output at DEBUG_INFO instead,
and the function will be run in DXE and SMM
MAT logic when the MAT is installed at EndOfDxe on DEBUG builds.

Cc: Jian J Wang <jian.j.wang@intel.com>
Cc: Liming Gao <gaoliming@byosoft.com.cn>
Cc: Dandan Bi <dandan.bi@intel.com>
Cc: Jiaxin Wu <jiaxin.wu@intel.com>
Cc: Ray Ni <ray.ni@intel.com>
Signed-off-by: Taylor Beebe <taylor.d.beebe@gmail.com>
Reviewed-by: Liming Gao <gaoliming@byosoft.com.cn>
This commit is contained in:
Taylor Beebe 2023-11-03 08:29:44 -07:00 committed by mergify[bot]
parent 3565ee6c29
commit 4ec2fab279
6 changed files with 137 additions and 23 deletions

View File

@ -284,6 +284,15 @@ InstallMemoryAttributesTableOnEndOfDxe (
{ {
mMemoryAttributesTableEndOfDxe = TRUE; mMemoryAttributesTableEndOfDxe = TRUE;
InstallMemoryAttributesTable (); InstallMemoryAttributesTable ();
DEBUG_CODE_BEGIN ();
if ( mImagePropertiesPrivateData.ImageRecordCount > 0) {
DEBUG ((DEBUG_INFO, "DXE - Total Runtime Image Count: 0x%x\n", mImagePropertiesPrivateData.ImageRecordCount));
DEBUG ((DEBUG_INFO, "DXE - Dump Runtime Image Records:\n"));
DumpImageRecords (&mImagePropertiesPrivateData.ImageRecordList);
}
DEBUG_CODE_END ();
} }
/** /**

View File

@ -496,9 +496,14 @@ SmmInstallMemoryAttributesTable (
return EFI_SUCCESS; return EFI_SUCCESS;
} }
DEBUG ((DEBUG_VERBOSE, "SMM Total Image Count - 0x%x\n", mImagePropertiesPrivateData.ImageRecordCount)); DEBUG_CODE_BEGIN ();
DEBUG ((DEBUG_VERBOSE, "SMM Dump ImageRecord:\n")); if ( mImagePropertiesPrivateData.ImageRecordCount > 0) {
DumpImageRecord (&mImagePropertiesPrivateData.ImageRecordList); DEBUG ((DEBUG_INFO, "SMM - Total Runtime Image Count - 0x%x\n", mImagePropertiesPrivateData.ImageRecordCount));
DEBUG ((DEBUG_INFO, "SMM - Dump Runtime Image Records:\n"));
DumpImageRecords (&mImagePropertiesPrivateData.ImageRecordList);
}
DEBUG_CODE_END ();
PublishMemoryAttributesTable (); PublishMemoryAttributesTable ();

View File

@ -182,13 +182,13 @@ FindImageRecord (
); );
/** /**
Dump image record. Debug dumps the input list of IMAGE_PROPERTIES_RECORD structs.
@param[in] ImageRecordList A list of IMAGE_PROPERTIES_RECORD entries @param[in] ImageRecordList Head of the IMAGE_PROPERTIES_RECORD list
**/ **/
VOID VOID
EFIAPI EFIAPI
DumpImageRecord ( DumpImageRecords (
IN LIST_ENTRY *ImageRecordList IN LIST_ENTRY *ImageRecordList
); );

View File

@ -14,6 +14,7 @@
#include <Library/BaseMemoryLib.h> #include <Library/BaseMemoryLib.h>
#include <Library/DebugLib.h> #include <Library/DebugLib.h>
#include <Library/MemoryAllocationLib.h> #include <Library/MemoryAllocationLib.h>
#include <Library/PeCoffGetEntryPointLib.h>
#include <Library/ImagePropertiesRecordLib.h> #include <Library/ImagePropertiesRecordLib.h>
#define PREVIOUS_MEMORY_DESCRIPTOR(MemoryDescriptor, Size) \ #define PREVIOUS_MEMORY_DESCRIPTOR(MemoryDescriptor, Size) \
@ -785,31 +786,128 @@ SortImageRecord (
} }
/** /**
Dump image record. Extract the .efi filename out of the input PDB.
@param[in] ImageRecordList A list of IMAGE_PROPERTIES_RECORD entries @param[in] PdbPointer Pointer to the PDB file path.
@param[out] EfiFileName Pointer to the .efi filename.
@param[in] EfiFileNameSize Size of the .efi filename buffer.
**/
STATIC
VOID
GetFilename (
IN CHAR8 *PdbPointer,
OUT CHAR8 *EfiFileName,
IN UINTN EfiFileNameSize
)
{
UINTN Index;
UINTN StartIndex;
if ((PdbPointer == NULL) || (EfiFileNameSize < 5)) {
return;
}
// Print Module Name by Pdb file path.
StartIndex = 0;
for (Index = 0; PdbPointer[Index] != 0; Index++) {
if ((PdbPointer[Index] == '\\') || (PdbPointer[Index] == '/')) {
StartIndex = Index + 1;
}
}
// Copy the PDB file name to EfiFileName and replace .pdb with .efi
for (Index = 0; Index < EfiFileNameSize - 4; Index++) {
EfiFileName[Index] = PdbPointer[Index + StartIndex];
if (EfiFileName[Index] == 0) {
EfiFileName[Index] = '.';
}
if (EfiFileName[Index] == '.') {
EfiFileName[Index + 1] = 'e';
EfiFileName[Index + 2] = 'f';
EfiFileName[Index + 3] = 'i';
EfiFileName[Index + 4] = 0;
break;
}
}
if (Index == sizeof (EfiFileName) - 4) {
EfiFileName[Index] = 0;
}
}
/**
Debug dumps the input list of IMAGE_PROPERTIES_RECORD structs.
@param[in] ImageRecordList Head of the IMAGE_PROPERTIES_RECORD list
**/ **/
VOID VOID
EFIAPI EFIAPI
DumpImageRecord ( DumpImageRecords (
IN LIST_ENTRY *ImageRecordList IN LIST_ENTRY *ImageRecordList
) )
{ {
IMAGE_PROPERTIES_RECORD *ImageRecord; LIST_ENTRY *ImageRecordLink;
LIST_ENTRY *ImageRecordLink; IMAGE_PROPERTIES_RECORD *CurrentImageRecord;
UINTN Index; LIST_ENTRY *CodeSectionLink;
IMAGE_PROPERTIES_RECORD_CODE_SECTION *CurrentCodeSection;
CHAR8 *PdbPointer;
CHAR8 EfiFileName[256];
for (ImageRecordLink = ImageRecordList->ForwardLink, Index = 0; if (ImageRecordList == NULL) {
ImageRecordLink != ImageRecordList; return;
ImageRecordLink = ImageRecordLink->ForwardLink, Index++) }
{
ImageRecord = CR ( ImageRecordLink = ImageRecordList->ForwardLink;
ImageRecordLink,
IMAGE_PROPERTIES_RECORD, while (ImageRecordLink != ImageRecordList) {
Link, CurrentImageRecord = CR (
IMAGE_PROPERTIES_RECORD_SIGNATURE ImageRecordLink,
); IMAGE_PROPERTIES_RECORD,
DEBUG ((DEBUG_VERBOSE, "Image[%d]: 0x%016lx - 0x%016lx\n", Index, ImageRecord->ImageBase, ImageRecord->ImageSize)); Link,
IMAGE_PROPERTIES_RECORD_SIGNATURE
);
PdbPointer = PeCoffLoaderGetPdbPointer ((VOID *)(UINTN)CurrentImageRecord->ImageBase);
if (PdbPointer != NULL) {
GetFilename (PdbPointer, EfiFileName, sizeof (EfiFileName));
DEBUG ((
DEBUG_INFO,
"%a: 0x%llx - 0x%llx\n",
EfiFileName,
CurrentImageRecord->ImageBase,
CurrentImageRecord->ImageBase + CurrentImageRecord->ImageSize
));
} else {
DEBUG ((
DEBUG_INFO,
"Unknown Image: 0x%llx - 0x%llx\n",
CurrentImageRecord->ImageBase,
CurrentImageRecord->ImageBase + CurrentImageRecord->ImageSize
));
}
CodeSectionLink = CurrentImageRecord->CodeSegmentList.ForwardLink;
while (CodeSectionLink != &CurrentImageRecord->CodeSegmentList) {
CurrentCodeSection = CR (
CodeSectionLink,
IMAGE_PROPERTIES_RECORD_CODE_SECTION,
Link,
IMAGE_PROPERTIES_RECORD_CODE_SECTION_SIGNATURE
);
DEBUG ((
DEBUG_INFO,
" Code Section: 0x%llx - 0x%llx\n",
CurrentCodeSection->CodeSegmentBase,
CurrentCodeSection->CodeSegmentBase + CurrentCodeSection->CodeSegmentSize
));
CodeSectionLink = CodeSectionLink->ForwardLink;
}
ImageRecordLink = ImageRecordLink->ForwardLink;
} }
} }

View File

@ -24,6 +24,7 @@
BaseMemoryLib BaseMemoryLib
DebugLib DebugLib
MemoryAllocationLib MemoryAllocationLib
PeCoffGetEntryPointLib
[Packages] [Packages]
MdePkg/MdePkg.dec MdePkg/MdePkg.dec

View File

@ -57,6 +57,7 @@
MdeModulePkg/Library/ImagePropertiesRecordLib/UnitTest/ImagePropertiesRecordLibUnitTestHost.inf { MdeModulePkg/Library/ImagePropertiesRecordLib/UnitTest/ImagePropertiesRecordLibUnitTestHost.inf {
<LibraryClasses> <LibraryClasses>
ImagePropertiesRecordLib|MdeModulePkg/Library/ImagePropertiesRecordLib/ImagePropertiesRecordLib.inf ImagePropertiesRecordLib|MdeModulePkg/Library/ImagePropertiesRecordLib/ImagePropertiesRecordLib.inf
PeCoffGetEntryPointLib|MdePkg/Library/BasePeCoffGetEntryPointLib/BasePeCoffGetEntryPointLib.inf
} }
# #