From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by spool.mail.gandi.net (Postfix) with ESMTPS id 2D999D8018D for ; Fri, 4 Aug 2023 19:47:17 +0000 (UTC) DKIM-Signature: a=rsa-sha256; bh=/FdM1RXeRZnnQ+l/4zEL3dTscNRsfM3ftGo/9f4IPnk=; 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=1691178435; v=1; b=a5AFaJ+h3rWi35SC5bus/KSunxcmKabo9muz5a/MKHJxET+c+Dna2lZNRpNAnUYMcJToZYe/ S6wF8DCFrFoIXFLp1Gx6QGBOB5JyPJWxlfPBBAngIJ0iFusP0IdDe91/KPlC/rfB73cQTH28vX+ E0DQFMFBqbLjmZmsq6y9sXhU= X-Received: by 127.0.0.2 with SMTP id VoTvYY7687511xvjkfZeHy4W; Fri, 04 Aug 2023 12:47:15 -0700 X-Received: from mail-pl1-f173.google.com (mail-pl1-f173.google.com [209.85.214.173]) by mx.groups.io with SMTP id smtpd.web11.6439.1691178431952252822 for ; Fri, 04 Aug 2023 12:47:12 -0700 X-Received: by mail-pl1-f173.google.com with SMTP id d9443c01a7336-1bbf3da0ea9so18012265ad.2 for ; Fri, 04 Aug 2023 12:47:11 -0700 (PDT) X-Gm-Message-State: mTGHSmiyzsWW9XWW1UPsoZ7wx7686176AA= X-Google-Smtp-Source: AGHT+IF/HYrBuS9qVzMv6VN7dhoCX585DkCG4bUCcjcnmTjATgQu+s6e9Uviowvz5atoeznNyxgHaQ== X-Received: by 2002:a17:903:22d1:b0:1b8:c6:ec8f with SMTP id y17-20020a17090322d100b001b800c6ec8fmr2789062plg.46.1691178431272; Fri, 04 Aug 2023 12:47:11 -0700 (PDT) X-Received: from localhost.localdomain ([50.46.230.135]) by smtp.gmail.com with ESMTPSA id h15-20020a170902f7cf00b001b890b3bbb1sm2114133plw.211.2023.08.04.12.47.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 04 Aug 2023 12:47:10 -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, 4 Aug 2023 12:46:48 -0700 Message-ID: <20230804194649.2001-15-t@taylorbeebe.com> In-Reply-To: <20230804194649.2001-1-t@taylorbeebe.com> References: <20230804194649.2001-1-t@taylorbeebe.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,t@taylorbeebe.com List-Unsubscribe-Post: List-Unsubscribe=One-Click List-Unsubscribe: Content-Transfer-Encoding: 8bit X-GND-Status: LEGIT Authentication-Results: spool.mail.gandi.net; dkim=pass header.d=groups.io header.s=20140610 header.b=a5AFaJ+h; spf=pass (spool.mail.gandi.net: domain of bounce@groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce@groups.io; dmarc=none From: Taylor Beebe 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 --- 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 #include #include +#include #include #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 { ImagePropertiesRecordLib|MdeModulePkg/Library/ImagePropertiesRecordLib/ImagePropertiesRecordLib.inf + PeCoffGetEntryPointLib|MdePkg/Library/BasePeCoffGetEntryPointLib/BasePeCoffGetEntryPointLib.inf } # -- 2.41.0.windows.3 -=-=-=-=-=-=-=-=-=-=-=- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#107600): https://edk2.groups.io/g/devel/message/107600 Mute This Topic: https://groups.io/mt/100553446/7686176 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [rebecca@openfw.io] -=-=-=-=-=-=-=-=-=-=-=-