From: "Taylor Beebe" <taylor.d.beebe@gmail.com>
To: devel@edk2.groups.io
Cc: Jian J Wang <jian.j.wang@intel.com>,
Liming Gao <gaoliming@byosoft.com.cn>,
Dandan Bi <dandan.bi@intel.com>, Jiaxin Wu <jiaxin.wu@intel.com>,
Ray Ni <ray.ni@intel.com>
Subject: [edk2-devel] [PATCH v5 16/16] MdeModulePkg: Update DumpImageRecord() in ImagePropertiesRecordLib
Date: Mon, 27 Nov 2023 10:18:14 -0800 [thread overview]
Message-ID: <20231127181818.411-17-taylor.d.beebe@gmail.com> (raw)
In-Reply-To: <20231127181818.411-1-taylor.d.beebe@gmail.com>
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>
---
MdeModulePkg/Core/Dxe/Misc/MemoryAttributesTable.c | 9 ++
MdeModulePkg/Core/PiSmmCore/MemoryAttributesTable.c | 11 +-
MdeModulePkg/Library/ImagePropertiesRecordLib/ImagePropertiesRecordLib.c | 134 +++++++++++++++++---
MdeModulePkg/Include/Library/ImagePropertiesRecordLib.h | 6 +-
MdeModulePkg/Library/ImagePropertiesRecordLib/ImagePropertiesRecordLib.inf | 1 +
MdeModulePkg/Test/MdeModulePkgHostTest.dsc | 1 +
6 files changed, 138 insertions(+), 24 deletions(-)
diff --git a/MdeModulePkg/Core/Dxe/Misc/MemoryAttributesTable.c b/MdeModulePkg/Core/Dxe/Misc/MemoryAttributesTable.c
index 993db281062a..e9343a2c4ef1 100644
--- a/MdeModulePkg/Core/Dxe/Misc/MemoryAttributesTable.c
+++ b/MdeModulePkg/Core/Dxe/Misc/MemoryAttributesTable.c
@@ -284,6 +284,15 @@ InstallMemoryAttributesTableOnEndOfDxe (
{
mMemoryAttributesTableEndOfDxe = TRUE;
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 ();
}
/**
diff --git a/MdeModulePkg/Core/PiSmmCore/MemoryAttributesTable.c b/MdeModulePkg/Core/PiSmmCore/MemoryAttributesTable.c
index 03de9b2c5fff..28fe74ecc421 100644
--- a/MdeModulePkg/Core/PiSmmCore/MemoryAttributesTable.c
+++ b/MdeModulePkg/Core/PiSmmCore/MemoryAttributesTable.c
@@ -496,9 +496,14 @@ SmmInstallMemoryAttributesTable (
return EFI_SUCCESS;
}
- DEBUG ((DEBUG_VERBOSE, "SMM Total Image Count - 0x%x\n", mImagePropertiesPrivateData.ImageRecordCount));
- DEBUG ((DEBUG_VERBOSE, "SMM Dump ImageRecord:\n"));
- DumpImageRecord (&mImagePropertiesPrivateData.ImageRecordList);
+ DEBUG_CODE_BEGIN ();
+ if ( mImagePropertiesPrivateData.ImageRecordCount > 0) {
+ 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 ();
diff --git a/MdeModulePkg/Library/ImagePropertiesRecordLib/ImagePropertiesRecordLib.c b/MdeModulePkg/Library/ImagePropertiesRecordLib/ImagePropertiesRecordLib.c
index 6c5eb1dc3185..e53ce086c54c 100644
--- a/MdeModulePkg/Library/ImagePropertiesRecordLib/ImagePropertiesRecordLib.c
+++ b/MdeModulePkg/Library/ImagePropertiesRecordLib/ImagePropertiesRecordLib.c
@@ -14,6 +14,7 @@
#include <Library/BaseMemoryLib.h>
#include <Library/DebugLib.h>
#include <Library/MemoryAllocationLib.h>
+#include <Library/PeCoffGetEntryPointLib.h>
#include <Library/ImagePropertiesRecordLib.h>
#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
EFIAPI
-DumpImageRecord (
+DumpImageRecords (
IN LIST_ENTRY *ImageRecordList
)
{
- IMAGE_PROPERTIES_RECORD *ImageRecord;
- LIST_ENTRY *ImageRecordLink;
- UINTN Index;
-
- for (ImageRecordLink = ImageRecordList->ForwardLink, Index = 0;
- ImageRecordLink != ImageRecordList;
- ImageRecordLink = ImageRecordLink->ForwardLink, Index++)
- {
- ImageRecord = CR (
- ImageRecordLink,
- IMAGE_PROPERTIES_RECORD,
- Link,
- IMAGE_PROPERTIES_RECORD_SIGNATURE
- );
- DEBUG ((DEBUG_VERBOSE, "Image[%d]: 0x%016lx - 0x%016lx\n", Index, ImageRecord->ImageBase, ImageRecord->ImageSize));
+ LIST_ENTRY *ImageRecordLink;
+ IMAGE_PROPERTIES_RECORD *CurrentImageRecord;
+ LIST_ENTRY *CodeSectionLink;
+ IMAGE_PROPERTIES_RECORD_CODE_SECTION *CurrentCodeSection;
+ CHAR8 *PdbPointer;
+ CHAR8 EfiFileName[256];
+
+ if (ImageRecordList == NULL) {
+ return;
+ }
+
+ ImageRecordLink = ImageRecordList->ForwardLink;
+
+ while (ImageRecordLink != ImageRecordList) {
+ CurrentImageRecord = CR (
+ ImageRecordLink,
+ IMAGE_PROPERTIES_RECORD,
+ 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;
}
}
diff --git a/MdeModulePkg/Include/Library/ImagePropertiesRecordLib.h b/MdeModulePkg/Include/Library/ImagePropertiesRecordLib.h
index 5090a521536b..87c94c723752 100644
--- a/MdeModulePkg/Include/Library/ImagePropertiesRecordLib.h
+++ b/MdeModulePkg/Include/Library/ImagePropertiesRecordLib.h
@@ -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
EFIAPI
-DumpImageRecord (
+DumpImageRecords (
IN LIST_ENTRY *ImageRecordList
);
diff --git a/MdeModulePkg/Library/ImagePropertiesRecordLib/ImagePropertiesRecordLib.inf b/MdeModulePkg/Library/ImagePropertiesRecordLib/ImagePropertiesRecordLib.inf
index cfe0c04b3b05..1f82cc3e469c 100644
--- a/MdeModulePkg/Library/ImagePropertiesRecordLib/ImagePropertiesRecordLib.inf
+++ b/MdeModulePkg/Library/ImagePropertiesRecordLib/ImagePropertiesRecordLib.inf
@@ -24,6 +24,7 @@ [LibraryClasses]
BaseMemoryLib
DebugLib
MemoryAllocationLib
+ PeCoffGetEntryPointLib
[Packages]
MdePkg/MdePkg.dec
diff --git a/MdeModulePkg/Test/MdeModulePkgHostTest.dsc b/MdeModulePkg/Test/MdeModulePkgHostTest.dsc
index 2b8cbb867a73..198cdd814fb9 100644
--- a/MdeModulePkg/Test/MdeModulePkgHostTest.dsc
+++ b/MdeModulePkg/Test/MdeModulePkgHostTest.dsc
@@ -57,6 +57,7 @@ [Components]
MdeModulePkg/Library/ImagePropertiesRecordLib/UnitTest/ImagePropertiesRecordLibUnitTestHost.inf {
<LibraryClasses>
ImagePropertiesRecordLib|MdeModulePkg/Library/ImagePropertiesRecordLib/ImagePropertiesRecordLib.inf
+ PeCoffGetEntryPointLib|MdePkg/Library/BasePeCoffGetEntryPointLib/BasePeCoffGetEntryPointLib.inf
}
#
--
2.42.0.windows.2
-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#111753): https://edk2.groups.io/g/devel/message/111753
Mute This Topic: https://groups.io/mt/102834925/7686176
Group Owner: devel+owner@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [rebecca@openfw.io]
-=-=-=-=-=-=-=-=-=-=-=-
next prev parent reply other threads:[~2023-11-27 18:18 UTC|newest]
Thread overview: 33+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-11-27 18:17 [edk2-devel] [PATCH v5 00/16] Add ImagePropertiesRecordLib and Fix MAT Bugs Taylor Beebe
2023-11-27 18:17 ` [edk2-devel] [PATCH v5 01/16] MdeModulePkg: Add ImagePropertiesRecordLib Taylor Beebe
2023-11-27 18:18 ` [edk2-devel] [PATCH v5 02/16] ArmVirtPkg: Add ImagePropertiesRecordLib Instance Taylor Beebe
2023-11-27 18:18 ` [edk2-devel] [PATCH v5 03/16] EmulatorPkg: " Taylor Beebe
2023-11-27 18:18 ` [edk2-devel] [PATCH v5 04/16] OvmfPkg: " Taylor Beebe
2023-11-27 18:18 ` [edk2-devel] [PATCH v5 05/16] UefiPayloadPkg: " Taylor Beebe
2023-11-27 18:18 ` [edk2-devel] [PATCH v5 06/16] MdeModulePkg: Update MemoryAttributesTable.c to Reduce Global Variable Use Taylor Beebe
2023-11-27 18:18 ` [edk2-devel] [PATCH v5 07/16] MdeModulePkg: Move Some DXE MAT Logic to ImagePropertiesRecordLib Taylor Beebe
2023-11-27 18:18 ` [edk2-devel] [PATCH v5 08/16] MdeModulePkg: Add ImagePropertiesRecordLib Host-Based Unit Test Taylor Beebe
2023-11-27 18:18 ` [edk2-devel] [PATCH v5 09/16] MdeModulePkg: Fix MAT Descriptor Count Calculation Taylor Beebe
2023-11-27 18:18 ` [edk2-devel] [PATCH v5 10/16] MdeModulePkg: Fix MAT SplitRecord() Logic Taylor Beebe
2024-04-12 5:14 ` [edk2-devel] MdeModulePkg: Fix MAT SplitRecord() Logic introduce one bug and will cause SUT reset when boot to windows Huang, Yanbo
2024-04-12 15:09 ` Taylor Beebe
2024-04-14 14:35 ` Huang, Yanbo
2024-04-15 10:57 ` Dandan Bi
2024-04-16 1:17 ` Taylor Beebe
2024-04-17 2:32 ` Taylor Beebe
2024-04-17 14:04 ` Huang, Yanbo
2024-04-17 23:53 ` Taylor Beebe
2024-04-18 13:02 ` Dandan Bi
2024-04-18 13:17 ` Ard Biesheuvel
2024-04-18 13:56 ` Huang, Yanbo
2024-04-18 14:21 ` Oliver Smith-Denny
2024-04-19 6:43 ` Ni, Ray
2024-04-23 14:33 ` Oliver Smith-Denny
2023-11-27 18:18 ` [edk2-devel] [PATCH v5 11/16] MdeModulePkg: Fix MAT SplitTable() Logic Taylor Beebe
2023-11-27 18:18 ` [edk2-devel] [PATCH v5 12/16] MdeModulePkg: Add NULL checks and Return Status to ImagePropertiesRecordLib Taylor Beebe
2023-11-27 18:18 ` [edk2-devel] [PATCH v5 13/16] UefiCpuPkg: Use Attribute From SMM MemoryAttributesTable if Nonzero Taylor Beebe
2023-11-27 18:18 ` [edk2-devel] [PATCH v5 14/16] MdeModulePkg: Transition SMM MAT Logic to Use ImagePropertiesRecordLib Taylor Beebe
2023-11-27 18:18 ` [edk2-devel] [PATCH v5 15/16] MdeModulePkg: Add Logic to Create/Delete Image Properties Records Taylor Beebe
2023-11-27 18:18 ` Taylor Beebe [this message]
2023-11-27 18:40 ` [edk2-devel] [PATCH v5 00/16] Add ImagePropertiesRecordLib and Fix MAT Bugs Ard Biesheuvel
2023-11-28 10:22 ` Ni, Ray
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-list from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20231127181818.411-17-taylor.d.beebe@gmail.com \
--to=devel@edk2.groups.io \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox