public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
From: "Marvin Häuser" <mhaeuser@posteo.de>
To: devel@edk2.groups.io
Cc: Andrew Fish <afish@apple.com>, Ray Ni <ray.ni@intel.com>,
	Vitaly Cheptsov <vit9696@protonmail.com>
Subject: [PATCH 1/3] EmulatorPkg: Use Image base address for GDB symbols loading
Date: Sat, 21 Aug 2021 19:55:45 +0000	[thread overview]
Message-ID: <750e31c0e12705c54e9367ad1315f611cd198930.1629574351.git.mhaeuser@posteo.de> (raw)
In-Reply-To: <cover.1629574351.git.mhaeuser@posteo.de>

GDB symbols are currently loaded by specifying the .text section
address. It is assumed to be the value of the PE/COFF SizeOfHeaders
field. This may not be the case for various reasons, including a
sufficiently strict Image section alignment. Use the "-o" parameter
to specify the Image base address instead. This works because the GCC
linker scripts are designed to emit Image section addresses that are
equal to those of the final PE/COFF Image.

Cc: Andrew Fish <afish@apple.com>
Cc: Ray Ni <ray.ni@intel.com>
Cc: Vitaly Cheptsov <vit9696@protonmail.com>
Signed-off-by: Marvin Häuser <mhaeuser@posteo.de>
---
 EmulatorPkg/Unix/Host/Host.c | 12 ++++++------
 EmulatorPkg/Unix/GdbRun.sh   |  2 +-
 EmulatorPkg/Unix/lldbefi.py  |  2 +-
 3 files changed, 8 insertions(+), 8 deletions(-)

diff --git a/EmulatorPkg/Unix/Host/Host.c b/EmulatorPkg/Unix/Host/Host.c
index b4e5510613c8..f5b7d6709e47 100644
--- a/EmulatorPkg/Unix/Host/Host.c
+++ b/EmulatorPkg/Unix/Host/Host.c
@@ -1042,7 +1042,7 @@ PrintLoadAddress (
   } else {
     fprintf (stderr,
       "0x%08lx Loading %s with entry point 0x%08lx\n",
-      (unsigned long)(ImageContext->ImageAddress + ImageContext->SizeOfHeaders),
+      (unsigned long)ImageContext->ImageAddress,
       ImageContext->PdbPointer,
       (unsigned long)ImageContext->EntryPoint
       );
@@ -1148,7 +1148,7 @@ GdbScriptAddImage (
     if (FeaturePcdGet (PcdEmulatorLazyLoadSymbols)) {
       GdbTempFile = fopen (gGdbWorkingFileName, "a");
       if (GdbTempFile != NULL) {
-        long unsigned int SymbolsAddr = (long unsigned int)(ImageContext->ImageAddress + ImageContext->SizeOfHeaders);
+        long unsigned int SymbolsAddr = (long unsigned int)ImageContext->ImageAddress;
         mScriptSymbolChangesCount++;
         fprintf (
           GdbTempFile,
@@ -1159,7 +1159,7 @@ GdbScriptAddImage (
           );
         fclose (GdbTempFile);
         // This is for the lldb breakpoint only
-        SecGdbScriptBreak (ImageContext->PdbPointer, strlen (ImageContext->PdbPointer) + 1, (long unsigned int)(ImageContext->ImageAddress + ImageContext->SizeOfHeaders), 1);
+        SecGdbScriptBreak (ImageContext->PdbPointer, strlen (ImageContext->PdbPointer) + 1, (long unsigned int)ImageContext->ImageAddress, 1);
       } else {
         ASSERT (FALSE);
       }
@@ -1168,9 +1168,9 @@ GdbScriptAddImage (
       if (GdbTempFile != NULL) {
         fprintf (
           GdbTempFile,
-          "add-symbol-file %s 0x%08lx\n",
+          "add-symbol-file %s -o 0x%08lx\n",
           ImageContext->PdbPointer,
-          (long unsigned int)(ImageContext->ImageAddress + ImageContext->SizeOfHeaders)
+          (long unsigned int)ImageContext->ImageAddress
           );
         fclose (GdbTempFile);
 
@@ -1180,7 +1180,7 @@ GdbScriptAddImage (
         // Also used for the lldb breakpoint script. The lldb breakpoint script does
         // not use the file, it uses the arguments.
         //
-        SecGdbScriptBreak (ImageContext->PdbPointer, strlen (ImageContext->PdbPointer) + 1, (long unsigned int)(ImageContext->ImageAddress + ImageContext->SizeOfHeaders), 1);
+        SecGdbScriptBreak (ImageContext->PdbPointer, strlen (ImageContext->PdbPointer) + 1, (long unsigned int)ImageContext->ImageAddress, 1);
       } else {
         ASSERT (FALSE);
       }
diff --git a/EmulatorPkg/Unix/GdbRun.sh b/EmulatorPkg/Unix/GdbRun.sh
index b050ad5e2c5c..6fea1c9d5b82 100644
--- a/EmulatorPkg/Unix/GdbRun.sh
+++ b/EmulatorPkg/Unix/GdbRun.sh
@@ -41,7 +41,7 @@ set $SymbolFileChangesCount = 0
 #
 define AddFirmwareSymbolFile
   if $SymbolFileChangesCount < $arg0
-    add-symbol-file $arg1 $arg2
+    add-symbol-file $arg1 -o $arg2
     set $SymbolFileChangesCount = $arg0
   end
 end
diff --git a/EmulatorPkg/Unix/lldbefi.py b/EmulatorPkg/Unix/lldbefi.py
index c3fb2675cbc1..4f4c04509e58 100755
--- a/EmulatorPkg/Unix/lldbefi.py
+++ b/EmulatorPkg/Unix/lldbefi.py
@@ -395,7 +395,7 @@ def LoadEmulatorEfiSymbols(frame, bp_loc , internal_dict):
 
     debugger = frame.thread.process.target.debugger
     if frame.FindVariable ("AddSymbolFlag").GetValueAsUnsigned() == 1:
-        LoadAddress = frame.FindVariable ("LoadAddress").GetValueAsUnsigned() - 0x240
+        LoadAddress = frame.FindVariable ("LoadAddress").GetValueAsUnsigned()
 
         debugger.HandleCommand ("target modules add  %s" % FileName)
         print "target modules load --slid 0x%x %s" % (LoadAddress, FileName)
-- 
2.31.1


  reply	other threads:[~2021-08-21 19:56 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-08-21 19:55 [PATCH 0/3] Update GDB and RVCT symbols loading to use the Image base address Marvin Häuser
2021-08-21 19:55 ` Marvin Häuser [this message]
2021-08-21 19:55 ` [PATCH 1/1] MdeModulePkg: Move PiSmmCoreMemoryAllocationLib into PiSmmCore Marvin Häuser
2021-09-01  4:21   ` Ni, Ray
2021-09-01  7:17     ` Marvin Häuser
2021-09-02 10:53       ` Ni, Ray
2021-09-02 13:22         ` [edk2-devel] " Marvin Häuser
2021-09-03  1:29           ` 回复: " gaoliming
2021-08-21 19:55 ` [PATCH 1/5] MdeModulePkg/PeiCore: Align fixed-address error behaviour Marvin Häuser
2021-08-21 19:55   ` [PATCH 2/5] MdeModulePkg/DxeCore: " Marvin Häuser
2021-08-21 19:55   ` [PATCH 3/5] MdeModulePkg/DxeCore: Check for fixed-address Image relocations Marvin Häuser
2021-08-21 19:55   ` [PATCH 4/5] MdeModulePkg/PiSmmIpl: Disallow stripped " Marvin Häuser
2021-08-21 19:55   ` [PATCH 5/5] MdeModulePkg/PiSmmCore: " Marvin Häuser
2021-08-21 20:10   ` [edk2-devel] [PATCH 1/5] MdeModulePkg/PeiCore: Align fixed-address error behaviour Marvin Häuser
2021-08-22  9:28     ` Marvin Häuser
2021-08-21 19:55 ` [PATCH 2/3] ArmPkg: Use Image base address for GDB symbols loading Marvin Häuser
2021-08-21 19:55 ` [PATCH 3/3] ArmPkg: Use Image base address for RVCT " Marvin Häuser

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=750e31c0e12705c54e9367ad1315f611cd198930.1629574351.git.mhaeuser@posteo.de \
    --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