From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mout01.posteo.de (mout01.posteo.de [185.67.36.65]) by mx.groups.io with SMTP id smtpd.web11.2461.1629575784124446127 for ; Sat, 21 Aug 2021 12:56:24 -0700 Authentication-Results: mx.groups.io; dkim=pass header.i=@posteo.de header.s=2017 header.b=dc3YX+f2; spf=pass (domain: posteo.de, ip: 185.67.36.65, mailfrom: mhaeuser@posteo.de) Received: from submission (posteo.de [89.146.220.130]) by mout01.posteo.de (Postfix) with ESMTPS id 6838B240028 for ; Sat, 21 Aug 2021 21:56:22 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=posteo.de; s=2017; t=1629575782; bh=FdXTFCQk0S+9olg7kD5c+HTkeowF04PszXcar0s+x8k=; h=From:To:Cc:Subject:Date:From; b=dc3YX+f266Fi3C0s7lHGY0cmtR28KV5adTUPU9J/hJOIkTkqIyV/JoyJMiTa5vCk1 ApuSNFe1g8gu+0XYr1dbQy7ni1djLzsIuoiy9LPL6S0kBagDVq5mV6xUUrt0fD78Sp ZR6cBQWD60QB58TY8Kquoo0deLgj9ikzgorAodKr+FqMJgEApvtaeRewXxqEVDcwJ6 fecuelBuhYguXTAIvywiAVl3jn+e8OqST12F3rmk8gBuqbjBeJfGp/AA11DbW/Q8o6 F8ZFnUjt1cZHE1r4xyFDCMaRl2CFPM3Wd9ZwF+gl+Jp+zWBV3p/WuMm1b1PHyp0FRX acxo2rVSIFULw== Received: from customer (localhost [127.0.0.1]) by submission (posteo.de) with ESMTPSA id 4GsTlp0TGTz9rxP; Sat, 21 Aug 2021 21:56:22 +0200 (CEST) From: =?UTF-8?B?TWFydmluIEjDpHVzZXI=?= To: devel@edk2.groups.io Cc: Andrew Fish , Ray Ni , Vitaly Cheptsov Subject: [PATCH 1/3] EmulatorPkg: Use Image base address for GDB symbols loading Date: Sat, 21 Aug 2021 19:55:45 +0000 Message-Id: <750e31c0e12705c54e9367ad1315f611cd198930.1629574351.git.mhaeuser@posteo.de> In-Reply-To: References: MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable 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 Cc: Ray Ni Cc: Vitaly Cheptsov Signed-off-by: Marvin H=C3=A4user --- 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 {=0D fprintf (stderr,=0D "0x%08lx Loading %s with entry point 0x%08lx\n",=0D - (unsigned long)(ImageContext->ImageAddress + ImageContext->SizeOfHea= ders),=0D + (unsigned long)ImageContext->ImageAddress,=0D ImageContext->PdbPointer,=0D (unsigned long)ImageContext->EntryPoint=0D );=0D @@ -1148,7 +1148,7 @@ GdbScriptAddImage ( if (FeaturePcdGet (PcdEmulatorLazyLoadSymbols)) {=0D GdbTempFile =3D fopen (gGdbWorkingFileName, "a");=0D if (GdbTempFile !=3D NULL) {=0D - long unsigned int SymbolsAddr =3D (long unsigned int)(ImageContext= ->ImageAddress + ImageContext->SizeOfHeaders);=0D + long unsigned int SymbolsAddr =3D (long unsigned int)ImageContext-= >ImageAddress;=0D mScriptSymbolChangesCount++;=0D fprintf (=0D GdbTempFile,=0D @@ -1159,7 +1159,7 @@ GdbScriptAddImage ( );=0D fclose (GdbTempFile);=0D // This is for the lldb breakpoint only=0D - SecGdbScriptBreak (ImageContext->PdbPointer, strlen (ImageContext-= >PdbPointer) + 1, (long unsigned int)(ImageContext->ImageAddress + ImageCon= text->SizeOfHeaders), 1);=0D + SecGdbScriptBreak (ImageContext->PdbPointer, strlen (ImageContext-= >PdbPointer) + 1, (long unsigned int)ImageContext->ImageAddress, 1);=0D } else {=0D ASSERT (FALSE);=0D }=0D @@ -1168,9 +1168,9 @@ GdbScriptAddImage ( if (GdbTempFile !=3D NULL) {=0D fprintf (=0D GdbTempFile,=0D - "add-symbol-file %s 0x%08lx\n",=0D + "add-symbol-file %s -o 0x%08lx\n",=0D ImageContext->PdbPointer,=0D - (long unsigned int)(ImageContext->ImageAddress + ImageContext->S= izeOfHeaders)=0D + (long unsigned int)ImageContext->ImageAddress=0D );=0D fclose (GdbTempFile);=0D =0D @@ -1180,7 +1180,7 @@ GdbScriptAddImage ( // Also used for the lldb breakpoint script. The lldb breakpoint s= cript does=0D // not use the file, it uses the arguments.=0D //=0D - SecGdbScriptBreak (ImageContext->PdbPointer, strlen (ImageContext-= >PdbPointer) + 1, (long unsigned int)(ImageContext->ImageAddress + ImageCon= text->SizeOfHeaders), 1);=0D + SecGdbScriptBreak (ImageContext->PdbPointer, strlen (ImageContext-= >PdbPointer) + 1, (long unsigned int)ImageContext->ImageAddress, 1);=0D } else {=0D ASSERT (FALSE);=0D }=0D 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 =3D 0 # define AddFirmwareSymbolFile if $SymbolFileChangesCount < $arg0 - add-symbol-file $arg1 $arg2 + add-symbol-file $arg1 -o $arg2 set $SymbolFileChangesCount =3D $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_dic= t): =0D debugger =3D frame.thread.process.target.debugger=0D if frame.FindVariable ("AddSymbolFlag").GetValueAsUnsigned() =3D=3D 1:= =0D - LoadAddress =3D frame.FindVariable ("LoadAddress").GetValueAsUnsig= ned() - 0x240=0D + LoadAddress =3D frame.FindVariable ("LoadAddress").GetValueAsUnsig= ned()=0D =0D debugger.HandleCommand ("target modules add %s" % FileName)=0D print "target modules load --slid 0x%x %s" % (LoadAddress, FileNam= e)=0D --=20 2.31.1