From nobody Sun Nov 10 22:40:47 2024 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+110662+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+110662+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1699031848; cv=none; d=zohomail.com; s=zohoarc; b=GAoJUY9kSEFrr7WggmqlGeh7K5x0DKWwZOIQXT0RGLJiLMEy1whPj0QqPw5Y6up4AlNvpZtGK5ngH6uJ59zH192XspMunM4SD8bcZpxj7hiPDDVoh6NaSueKz8D1mCD1y3xQOiPoQ6nSR9qSib6xk2f70pMJcZdFzAuWdFIvfXk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1699031848; 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=QnaQsgTtxV37CBcadqrsXl86eSjfYfC17Z3m7DlK/7k=; b=bnxxL//KzdUsx5vaWNh6UTLYhlCCP94xwa/PmEby1pKMwNxQVFfuA1J1daWLXecMlViEpo+pHuI/JITERMoY1gb+tbDFcjjU9qPQ6JiwoyUy5c7E6P24D/VwKlOyuqj7rXvPaTxngbbEhe6XpJ9w3+EoouYOfLt5XxVEnQ9dDAY= 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+110662+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 1699031848716539.3546595974186; Fri, 3 Nov 2023 10:17:28 -0700 (PDT) Return-Path: DKIM-Signature: a=rsa-sha256; bh=IKnsoao+0D7VWfFBvNa+55aLSyqdl9bdZuxELIREBaE=; 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=1699031848; v=1; b=fngYqhM8BjyVfiKocMv3fb/f2DB/qjvBFGk+865dKpel4yVo/EIEK7nUm8dN/NmuiZmM/azJ wRsRoz+21Srbk0Ehw1PAflBNYCvYmppontItvssrcCCxrQJ4zpPFFKJhY40KCPUQMSWk2GUVvzw wjfDW/+AksRgWWBXuC0RRAdc= X-Received: by 127.0.0.2 with SMTP id bmYjYY1788612x2cRp3jPzrv; Fri, 03 Nov 2023 10:17:28 -0700 X-Received: from mail-pl1-f172.google.com (mail-pl1-f172.google.com [209.85.214.172]) by mx.groups.io with SMTP id smtpd.web11.59071.1699031847048630009 for ; Fri, 03 Nov 2023 10:17:27 -0700 X-Received: by mail-pl1-f172.google.com with SMTP id d9443c01a7336-1cc131e52f1so27367305ad.0 for ; Fri, 03 Nov 2023 10:17:27 -0700 (PDT) X-Gm-Message-State: NuoJsqftXk1qh5Qbf2edzlYox1787277AA= X-Google-Smtp-Source: AGHT+IF3nrPgcrN1+d5NjCIEEahP4aqdJrG9dPVKVd9IbXdnO5Lg9/HD3R/+3GLt+KEgEXxwWITvYA== X-Received: by 2002:a17:902:ea02:b0:1cc:476c:8974 with SMTP id s2-20020a170902ea0200b001cc476c8974mr4369256plg.0.1699031846375; Fri, 03 Nov 2023 10:17:26 -0700 (PDT) X-Received: from localhost.localdomain ([50.46.253.1]) by smtp.gmail.com with ESMTPSA id b8-20020a170903228800b001bf5e24b2a8sm1625152plh.174.2023.11.03.10.17.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 03 Nov 2023 10:17:26 -0700 (PDT) From: "Taylor Beebe" To: devel@edk2.groups.io Cc: Jian J Wang , Liming Gao , Dandan Bi , Jiaxin Wu , Ray Ni Subject: [edk2-devel] [PATCH v4 14/14] MdeModulePkg: Update DumpImageRecord() in ImagePropertiesRecordLib Date: Fri, 3 Nov 2023 10:17:06 -0700 Message-ID: <20231103171706.148-15-taylor.d.beebe@gmail.com> In-Reply-To: <20231103171706.148-1-taylor.d.beebe@gmail.com> References: <20231103171706.148-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: 1699031850981100055 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 (#110662): https://edk2.groups.io/g/devel/message/110662 Mute This Topic: https://groups.io/mt/102368856/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-