[edk2-devel] [PATCH 1/3] EmulatorPkg: Use Image base address for GDB symbols loading

Marvin Häuser mhaeuser at posteo.de
Sat Aug 21 19:55:45 UTC 2021


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 at apple.com>
Cc: Ray Ni <ray.ni at intel.com>
Cc: Vitaly Cheptsov <vit9696 at protonmail.com>
Signed-off-by: Marvin Häuser <mhaeuser at 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



-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#79669): https://edk2.groups.io/g/devel/message/79669
Mute This Topic: https://groups.io/mt/85048606/1813853
Group Owner: devel+owner at edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [edk2-devel-archive at redhat.com]
-=-=-=-=-=-=-=-=-=-=-=-






More information about the edk2-devel-archive mailing list