From nobody Sun Feb 8 18:29:57 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) client-ip=66.175.222.108; envelope-from=bounce+27952+111753+1787277+3901457@groups.io; helo=mail02.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+111753+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1701109123; cv=none; d=zohomail.com; s=zohoarc; b=C/Owf22shSqrXaxUoPplL6DJ9+/0RWL9RfJIlq7GP0YnGNPS7MrM1mNjf9ikj4+jPxraGDlYMAZzljzqx48j3Eu62crFHw5wWPoH6R2zt4bU/khYLn92uCB6meeiMcklFZxG0BQjiXe1aPmv42kIwW8LyRQ8ApA4fM7cowisT0E= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1701109123; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:Reply-To:References:Sender:Subject:Subject:To:To:Message-Id; bh=v5vzUWiltWoN0+XA5Po5wahtbNzY6lKKrSWjHv7UZUQ=; b=lJnlzhAsIS7IjdQ4olSUGA+lE82OnoLDcH8a43FcZF8TPrRM2YRSzKnXKBCDcpBLDag8s+IUqhjkbLSry+8sJkKBjjTg87jqCMNQ8SNQsD6AOp49A8eDIRmNHrq71RSednzRtlTF0aIzDOFiktcsxk2fy7ZaG/WphNWWSj5d6C4= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+111753+1787277+3901457@groups.io; dmarc=fail header.from= (p=none dis=none) Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 1701109123134738.4183541922306; Mon, 27 Nov 2023 10:18:43 -0800 (PST) Return-Path: DKIM-Signature: a=rsa-sha256; bh=UpUeg+dCsEA4/xjr4sRSYry7RfMmCbK7aP7u/Ch4xas=; c=relaxed/simple; d=groups.io; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References:MIME-Version:Precedence:List-Subscribe:List-Help:Sender:List-Id:Mailing-List:Delivered-To:Reply-To:List-Unsubscribe-Post:List-Unsubscribe:Content-Transfer-Encoding; s=20140610; t=1701109122; v=1; b=YqbE++lhFOwzvpGiY+urlhZS9Zv+JE9u9o7zUl4tAvHSKFosMnTlwgJ0fpNtP4fxc8NfLX/S nWFqr/nhH+2TdkCoo8DVpuiJtz6aOyNVuySvx9ql/MsBKvUF0X1Y6R+8fSpiJvqtg8P0wnmUf+P g0R2/uzyyunc+AWRoLPAAqPM= X-Received: by 127.0.0.2 with SMTP id IS4yYY1788612xNXsa7H2u9u; Mon, 27 Nov 2023 10:18:42 -0800 X-Received: from mail-pl1-f177.google.com (mail-pl1-f177.google.com [209.85.214.177]) by mx.groups.io with SMTP id smtpd.web11.102331.1701109121929965480 for ; Mon, 27 Nov 2023 10:18:41 -0800 X-Received: by mail-pl1-f177.google.com with SMTP id d9443c01a7336-1ce3084c2d1so37535345ad.3 for ; Mon, 27 Nov 2023 10:18:41 -0800 (PST) X-Gm-Message-State: 62rc7TWnatCZRtw6nSUB4KgGx1787277AA= X-Google-Smtp-Source: AGHT+IHjPmuJ0s0yBhh+jIbxxoGiEPRrp0CgcVjKaC4F7G1s0aXwED1/wNKEKxoqKbqV/Pzt8mOWSg== X-Received: by 2002:a17:903:22d2:b0:1c9:c6f4:e0c3 with SMTP id y18-20020a17090322d200b001c9c6f4e0c3mr14463717plg.62.1701109121189; Mon, 27 Nov 2023 10:18:41 -0800 (PST) X-Received: from localhost.localdomain ([50.46.253.1]) by smtp.gmail.com with ESMTPSA id c6-20020a170902c1c600b001cfd0ed1604sm2013259plc.87.2023.11.27.10.18.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 27 Nov 2023 10:18:40 -0800 (PST) From: "Taylor Beebe" To: devel@edk2.groups.io Cc: Jian J Wang , Liming Gao , Dandan Bi , Jiaxin Wu , Ray Ni Subject: [edk2-devel] [PATCH v5 16/16] MdeModulePkg: Update DumpImageRecord() in ImagePropertiesRecordLib Date: Mon, 27 Nov 2023 10:18:14 -0800 Message-ID: <20231127181818.411-17-taylor.d.beebe@gmail.com> In-Reply-To: <20231127181818.411-1-taylor.d.beebe@gmail.com> References: <20231127181818.411-1-taylor.d.beebe@gmail.com> MIME-Version: 1.0 Precedence: Bulk List-Subscribe: List-Help: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,taylor.d.beebe@gmail.com List-Unsubscribe-Post: List-Unsubscribe=One-Click List-Unsubscribe: Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1701109124404000065 Content-Type: text/plain; charset="utf-8" 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 Cc: Liming Gao Cc: Dandan Bi Cc: Jiaxin Wu Cc: Ray Ni Signed-off-by: Taylor Beebe Reviewed-by: Liming Gao --- 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/MdeModule= Pkg/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 =3D TRUE; InstallMemoryAttributesTable (); + + DEBUG_CODE_BEGIN (); + if ( mImagePropertiesPrivateData.ImageRecordCount > 0) { + DEBUG ((DEBUG_INFO, "DXE - Total Runtime Image Count: 0x%x\n", mImageP= ropertiesPrivateData.ImageRecordCount)); + DEBUG ((DEBUG_INFO, "DXE - Dump Runtime Image Records:\n")); + DumpImageRecords (&mImagePropertiesPrivateData.ImageRecordList); + } + + DEBUG_CODE_END (); } =20 /** diff --git a/MdeModulePkg/Core/PiSmmCore/MemoryAttributesTable.c b/MdeModul= ePkg/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; } =20 - DEBUG ((DEBUG_VERBOSE, "SMM Total Image Count - 0x%x\n", mImagePropertie= sPrivateData.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", mImage= PropertiesPrivateData.ImageRecordCount)); + DEBUG ((DEBUG_INFO, "SMM - Dump Runtime Image Records:\n")); + DumpImageRecords (&mImagePropertiesPrivateData.ImageRecordList); + } + + DEBUG_CODE_END (); =20 PublishMemoryAttributesTable (); =20 diff --git a/MdeModulePkg/Library/ImagePropertiesRecordLib/ImagePropertiesR= ecordLib.c b/MdeModulePkg/Library/ImagePropertiesRecordLib/ImagePropertiesR= ecordLib.c index 6c5eb1dc3185..e53ce086c54c 100644 --- a/MdeModulePkg/Library/ImagePropertiesRecordLib/ImagePropertiesRecordLi= b.c +++ b/MdeModulePkg/Library/ImagePropertiesRecordLib/ImagePropertiesRecordLi= b.c @@ -14,6 +14,7 @@ #include #include #include +#include #include =20 #define PREVIOUS_MEMORY_DESCRIPTOR(MemoryDescriptor, Size) \ @@ -785,31 +786,128 @@ SortImageRecord ( } =20 /** - Dump image record. + Extract the .efi filename out of the input PDB. =20 - @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 =3D=3D NULL) || (EfiFileNameSize < 5)) { + return; + } + + // Print Module Name by Pdb file path. + StartIndex =3D 0; + for (Index =3D 0; PdbPointer[Index] !=3D 0; Index++) { + if ((PdbPointer[Index] =3D=3D '\\') || (PdbPointer[Index] =3D=3D '/'))= { + StartIndex =3D Index + 1; + } + } + + // Copy the PDB file name to EfiFileName and replace .pdb with .efi + for (Index =3D 0; Index < EfiFileNameSize - 4; Index++) { + EfiFileName[Index] =3D PdbPointer[Index + StartIndex]; + if (EfiFileName[Index] =3D=3D 0) { + EfiFileName[Index] =3D '.'; + } + + if (EfiFileName[Index] =3D=3D '.') { + EfiFileName[Index + 1] =3D 'e'; + EfiFileName[Index + 2] =3D 'f'; + EfiFileName[Index + 3] =3D 'i'; + EfiFileName[Index + 4] =3D 0; + break; + } + } + + if (Index =3D=3D sizeof (EfiFileName) - 4) { + EfiFileName[Index] =3D 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 =3D ImageRecordList->ForwardLink, Index =3D 0; - ImageRecordLink !=3D ImageRecordList; - ImageRecordLink =3D ImageRecordLink->ForwardLink, Index++) - { - ImageRecord =3D CR ( - ImageRecordLink, - IMAGE_PROPERTIES_RECORD, - Link, - IMAGE_PROPERTIES_RECORD_SIGNATURE - ); - DEBUG ((DEBUG_VERBOSE, "Image[%d]: 0x%016lx - 0x%016lx\n", Index, Imag= eRecord->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 =3D=3D NULL) { + return; + } + + ImageRecordLink =3D ImageRecordList->ForwardLink; + + while (ImageRecordLink !=3D ImageRecordList) { + CurrentImageRecord =3D CR ( + ImageRecordLink, + IMAGE_PROPERTIES_RECORD, + Link, + IMAGE_PROPERTIES_RECORD_SIGNATURE + ); + + PdbPointer =3D PeCoffLoaderGetPdbPointer ((VOID *)(UINTN)CurrentImageR= ecord->ImageBase); + if (PdbPointer !=3D 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 =3D CurrentImageRecord->CodeSegmentList.ForwardLink; + + while (CodeSectionLink !=3D &CurrentImageRecord->CodeSegmentList) { + CurrentCodeSection =3D 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->CodeSegm= entSize + )); + + CodeSectionLink =3D CodeSectionLink->ForwardLink; + } + + ImageRecordLink =3D ImageRecordLink->ForwardLink; } } =20 diff --git a/MdeModulePkg/Include/Library/ImagePropertiesRecordLib.h b/MdeM= odulePkg/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 ( ); =20 /** - Dump image record. + Debug dumps the input list of IMAGE_PROPERTIES_RECORD structs. =20 - @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 ); =20 diff --git a/MdeModulePkg/Library/ImagePropertiesRecordLib/ImagePropertiesR= ecordLib.inf b/MdeModulePkg/Library/ImagePropertiesRecordLib/ImagePropertie= sRecordLib.inf index cfe0c04b3b05..1f82cc3e469c 100644 --- a/MdeModulePkg/Library/ImagePropertiesRecordLib/ImagePropertiesRecordLi= b.inf +++ b/MdeModulePkg/Library/ImagePropertiesRecordLib/ImagePropertiesRecordLi= b.inf @@ -24,6 +24,7 @@ [LibraryClasses] BaseMemoryLib DebugLib MemoryAllocationLib + PeCoffGetEntryPointLib =20 [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/ImagePropertiesRe= cordLibUnitTestHost.inf { ImagePropertiesRecordLib|MdeModulePkg/Library/ImagePropertiesRecordL= ib/ImagePropertiesRecordLib.inf + PeCoffGetEntryPointLib|MdePkg/Library/BasePeCoffGetEntryPointLib/Bas= ePeCoffGetEntryPointLib.inf } =20 # --=20 2.42.0.windows.2 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- 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/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-