From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from rn-mailsvcp-ppex-lapp15.apple.com (rn-mailsvcp-ppex-lapp15.apple.com [17.179.253.34]) by mx.groups.io with SMTP id smtpd.web12.812.1652120290982484161 for ; Mon, 09 May 2022 11:18:11 -0700 Authentication-Results: mx.groups.io; dkim=pass header.i=@apple.com header.s=20180706 header.b=gpvFLtEQ; spf=pass (domain: apple.com, ip: 17.179.253.34, mailfrom: afish@apple.com) Received: from pps.filterd (rn-mailsvcp-ppex-lapp15.rno.apple.com [127.0.0.1]) by rn-mailsvcp-ppex-lapp15.rno.apple.com (8.16.1.2/8.16.1.2) with SMTP id 249IAg1i024986; Mon, 9 May 2022 11:18:10 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=apple.com; h=from : message-id : content-type : mime-version : subject : date : in-reply-to : cc : to : references; s=20180706; bh=xDBEbeRL7UZr2RTBp2qe46RBdvZ2QCXDHeiWWhS2HYU=; b=gpvFLtEQQV0QGG+KRz63cfw5I+Pf9fqkQeAG8m2+wFnoFPyLRo6uV3wwvBwdcYlXeS5u sKPxbqp/EPeFQ1pd6JVpA8QwNipPtjevWdEQHj1IwqZQxCb2acHgpGDvnSMxIHJudQUs LPlFAHxWYdhtRyFtpg/RQvepZrJLKbUHH2OlLiH+lUSdMKVpr+Mh5JlCnGKaAE0QvuYa uR/lFnWGunzcVxku2b+R6lYAJAMwXHdd6duw7ut2O2McKr3xasTy8BnM1qFmYiKoMnYr 72AfWW1BezqunPsll+zokUJCwaSNabkAZD+DDcqVJizq0jqO6/2EKB+j4OLJEeABZ9sQ Ig== Received: from rn-mailsvcp-mta-lapp02.rno.apple.com (rn-mailsvcp-mta-lapp02.rno.apple.com [10.225.203.150]) by rn-mailsvcp-ppex-lapp15.rno.apple.com with ESMTP id 3fwpbc0gva-7 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128 verify=NO); Mon, 09 May 2022 11:18:10 -0700 Received: from rn-mailsvcp-mmp-lapp01.rno.apple.com (rn-mailsvcp-mmp-lapp01.rno.apple.com [17.179.253.14]) by rn-mailsvcp-mta-lapp02.rno.apple.com (Oracle Communications Messaging Server 8.1.0.18.20220407 64bit (built Apr 7 2022)) with ESMTPS id <0RBM006UUO6858J0@rn-mailsvcp-mta-lapp02.rno.apple.com>; Mon, 09 May 2022 11:18:08 -0700 (PDT) Received: from process_milters-daemon.rn-mailsvcp-mmp-lapp01.rno.apple.com by rn-mailsvcp-mmp-lapp01.rno.apple.com (Oracle Communications Messaging Server 8.1.0.18.20220407 64bit (built Apr 7 2022)) id <0RBM00D00O323300@rn-mailsvcp-mmp-lapp01.rno.apple.com>; Mon, 09 May 2022 11:18:08 -0700 (PDT) X-Va-A: X-Va-T-CD: 159e65cf5d47202b04bd3f023f2dd26b X-Va-E-CD: 69405dc827466b59b4d5a7f3a2e3603f X-Va-R-CD: a746c2fbd3d44c00feaad9c81df137ae X-Va-CD: 0 X-Va-ID: 0eda1c68-7b1e-415d-bee0-58a0b1a484a1 X-V-A: X-V-T-CD: 159e65cf5d47202b04bd3f023f2dd26b X-V-E-CD: 69405dc827466b59b4d5a7f3a2e3603f X-V-R-CD: a746c2fbd3d44c00feaad9c81df137ae X-V-CD: 0 X-V-ID: bbf39bc0-4e88-4b74-b83c-da9849aff582 X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.486,18.0.858 definitions=2022-05-09_05:2022-05-09,2022-05-09 signatures=0 Received: from smtpclient.apple (unknown [17.235.7.9]) by rn-mailsvcp-mmp-lapp01.rno.apple.com (Oracle Communications Messaging Server 8.1.0.18.20220407 64bit (built Apr 7 2022)) with ESMTPSA id <0RBM00A53O68BV00@rn-mailsvcp-mmp-lapp01.rno.apple.com>; Mon, 09 May 2022 11:18:08 -0700 (PDT) From: "Andrew Fish" Message-id: MIME-version: 1.0 (Mac OS X Mail 15.0 \(3693.20.0.1.32\)) Subject: Re: [edk2-devel] Debug OVMF Date: Mon, 09 May 2022 11:18:07 -0700 In-reply-to: <9db9a4e4993be2641c2e8752a456481cb71a1181.camel@intel.com> Cc: "kraxel@redhat.com" , "Yao, Jiewen" To: edk2-devel-groups-io , sebastien.boeuf@intel.com References: <712bc220a0deb8cface468a5f1fb6cbe462662bb.camel@intel.com> <20220509094917.sydwsa6iy46eeroc@sirius.home.kraxel.org> <9db9a4e4993be2641c2e8752a456481cb71a1181.camel@intel.com> X-Mailer: Apple Mail (2.3693.20.0.1.32) X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.486,18.0.858 definitions=2022-05-09_05:2022-05-09,2022-05-09 signatures=0 Content-type: multipart/alternative; boundary="Apple-Mail=_B9C343B8-34A9-467B-A4FF-725D52227928" --Apple-Mail=_B9C343B8-34A9-467B-A4FF-725D52227928 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=utf-8 Sebastien, The UEFI ROMs generally contain sets of PE/COFF images (drivers, apps, etc)= that execute not at their linked address. These PE/COFF images have been s= tripped of debug information and optionally contain a PE/COFF debug directo= ry entry that points to a file that contains the debug info. Generally for = Windows this is a PDB file, for macOS it is a dSYM, for Linux it is the ELF= . Given this we have to teach debuggers how to load EFI symbols. The idea behind efi_gdb.py is to add a gdb command that can load EFI symbol= s. The idea is to take the PC/address/frame address and walk backwards to f= ind the PE/COFF header. The PE/COFF header start gives you the load address= and the PE/COFF debug directory entry lets you point gdb at the file with = the symbols. If you are into EFI proper (DXE) you can also pass an =E2=80= =94extended flag and the gdb command will use symbols from the frame to try= and find the EFI System Table that contains a list of the load address of = all the modules, and then load symbols for everything.=20 Assuming you tell QEMU to create a gdb remote stub (-gdb tcp::9000)=E2=80= =A6 TL;DR=E2=80=A6. When OVMF is running from another terminal window gdb -ex "target remote lo= calhost:9000" -ex "source efi_gdb.py=E2=80=9D and that should connect to OV= MF and load the EFI Symbols.=20 There are some basic instructions in the header of the Python script.=20 https://github.com/tianocore/edk2/blob/master/BaseTools/Scripts/efi_gdb.py The efi_gdb.py script also adds some other useful EFI related gdb commands = to dump things like Device Path, HOB, guid, and EFI System Tables.=20 Caveat emptor there is a debugger agnostic script, efi_debugging.py, that n= eeds to be next to efi_gdb.py. My daily driver is lldb so I wrote these scr= ipts for lldb, and then ported to gdb with lots of interweb searching. But = even if something goes wrong I can probably help out on the mailing list.= =20 Thanks, Andrew Fish PS It should be possible to use the efi_debugging.py Python classes with an= y debugger that supports Python, or to use the services from other gdb debu= gging scripts etc.=20 > On May 9, 2022, at 3:00 AM, Boeuf, Sebastien = wrote: >=20 > On Mon, 2022-05-09 at 11:49 +0200, kraxel@redhat.com wrote: >> On Mon, May 09, 2022 at 09:32:52AM +0000, Boeuf, Sebastien wrote: >>> Hi, >>>=20 >>> I'm trying to debug OVMF with gdb connected to Cloud Hypervisor but >>> the >>> problem is that the debug binary that I have generated doesn't >>> contain >>> any symbols. Do you know how to generate debug symbols for OVMF? >>=20 >> Build/OvmfX64/DEBUG_GCC5/X64/*.debug >>=20 >> You might want checkout BaseTools/Scripts/efi_*.py too (didn't try >> them >> myself yet). >=20 > Ah thanks for the pointers, I'll try these :) >=20 > Sebastien >=20 >>=20 >> take care, >> Gerd >>=20 >=20 > --------------------------------------------------------------------- > Intel Corporation SAS (French simplified joint stock company) > Registered headquarters: "Les Montalets"- 2, rue de Paris,=20 > 92196 Meudon Cedex, France > Registration Number: 302 456 199 R.C.S. NANTERRE > Capital: 5 208 026.16 Euros >=20 > This e-mail and any attachments may contain confidential material for > the sole use of the intended recipient(s). Any review or distribution > by others is strictly prohibited. If you are not the intended > recipient, please contact the sender and delete all copies. >=20 >=20 >=20 --Apple-Mail=_B9C343B8-34A9-467B-A4FF-725D52227928 Content-Transfer-Encoding: quoted-printable Content-Type: text/html; charset=utf-8 Sebastien,
=
The UEFI ROMs generally contain sets o= f PE/COFF images (drivers, apps, etc) that execute not at their linked addr= ess. These PE/COFF images have been stripped of debug information and optio= nally contain a PE/COFF debug directory entry that points to a file that co= ntains the debug info. Generally for Windows this is a PDB file, for macOS = it is a dSYM, for Linux it is the ELF. Given this we have to teach debugger= s how to load EFI symbols.

The idea behind efi_gdb.py is to add a gdb command that = can load EFI symbols. The idea is to take the PC/address/frame address and = walk backwards to find the PE/COFF header. The PE/COFF header start gives y= ou the load address and the PE/COFF debug directory entry lets you point gd= b at the file with the symbols. If you are into EFI proper (DXE) you can al= so pass an =E2=80=94extended flag and the gdb command will use symbols from= the frame to try and find the EFI System Table that contains a list of the= load address of all the modules, and then load symbols for everything.&nbs= p;

Assuming you t= ell QEMU to create a gdb remote stub (-gdb tcp::9000)=E2=80=A6 TL;DR=E2=80= =A6.

When OVMF is= running from another terminal window gdb -ex "target remote localhost:9000= " -ex "source efi_gdb.py=E2=80=9D and that should connect to OVMF and load = the EFI Symbols. 

There are some basic instructions in the header of the Python script.=  

The efi_gdb.py script also adds some = other useful EFI related gdb commands to dump things like Device Path, HOB,= guid, and EFI System Tables. 

Caveat emptor there is a debugger agnostic script, efi_d= ebugging.py, that needs to be next to efi_gdb.py. My daily driver is lldb s= o I wrote these scripts for lldb, and then ported to gdb with lots of inter= web searching. But even if something goes wrong I can probably help out on = the mailing list. 

Thanks,

An= drew Fish

PS It s= hould be possible to use the efi_debugging.py Python classes with any debug= ger that supports Python, or to use the services from other gdb debugging s= cripts etc. 

On May 9, 2022, at 3:00 AM, Boeuf, Sebastien = <sebastien.boeuf= @intel.com> wrote:

On Mon, 2022-05-09 at= 11:49 +0200, kraxel@redhat.com&nb= sp;wrote:
On Mon, May 09, 2022 at 09:32:52AM +0000, Boeuf, Sebastien wrote:
Hi,

I'm trying to debug OVMF with gdb connected to Cloud Hypervisor but<= br class=3D"">the
problem is that the debug binary that I hav= e generated doesn't
contain
any symbols. Do you= know how to generate debug symbols for OVMF?
Build/OvmfX64/DEBUG_GCC5/X64/*.debug

You might want checkout BaseTools/Scripts/efi_*.py too (didn't trythem
myself yet).

Ah thanks for the pointers, I'll = try these :)

Sebastien


take care,
  Gerd


------------------------------------------= ---------------------------
Intel Corporation SAS (French simplified joint stock company)<= br style=3D"caret-color: rgb(0, 0, 0); font-family: Helvetica; font-size: 1= 2px; font-style: normal; font-variant-caps: normal; font-weight: normal; le= tter-spacing: normal; text-align: start; text-indent: 0px; text-transform: = none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0p= x; text-decoration: none;" class=3D"">Registered headquarters: "Les = Montalets"- 2, rue de Paris, 
92196 Meudon Cedex= , France
Registration N= umber:  302 456 199 R.C.S. NANTERRE
Capital: 5 208 026.16 Euros

This e-mail a= nd any attachments may contain confidential material for
the sole use of the intended recipient(s)= . Any review or distribution
<= span style=3D"caret-color: rgb(0, 0, 0); font-family: Helvetica; font-size:= 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; = letter-spacing: normal; text-align: start; text-indent: 0px; text-transform= : none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: = 0px; text-decoration: none; float: none; display: inline !important;" class= =3D"">by others is strictly prohibited. If you are not the intended<= br style=3D"caret-color: rgb(0, 0, 0); font-family: Helvetica; font-size: 1= 2px; font-style: normal; font-variant-caps: normal; font-weight: normal; le= tter-spacing: normal; text-align: start; text-indent: 0px; text-transform: = none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0p= x; text-decoration: none;" class=3D"">recipient, please contact the = sender and delete all copies.
=


--Apple-Mail=_B9C343B8-34A9-467B-A4FF-725D52227928--