From mboxrd@z Thu Jan 1 00:00:00 1970 Subject: Debugging Ovmf with GDB: No symbol is recognized To: devel@edk2.groups.io From: koenig_regina@arcor.de X-Originating-Location: Freiburg im Breisgau, Baden-Württemberg, DE (132.230.196.224) X-Originating-Platform: Linux Firefox 100 User-Agent: GROUPS.IO Web Poster MIME-Version: 1.0 Date: Fri, 20 May 2022 06:10:40 -0700 Message-ID: Content-Type: multipart/alternative; boundary="gWVR5vXDAzTj7Je1Ta0L" --gWVR5vXDAzTj7Je1Ta0L Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Hi, I am trying to debug OVMF as suggested in https://retrage.github.io/201= 9/12/05/debugging-ovmf-en.html. Almost every step seems to work fine. I built edk2 as follow: ------------------------------ $ git clone git@github.com:tianocore/edk2.git \ $ cd edk2$ git submodule update --init --recursive $ make -C BaseTools $ source ./edksetup.sh $ build -p OvmfPkg/OvmfPkgX64.dsc -b DEBUG -a X64 -t GCC5 My Makefile looks like this: -------------------------------------- #!/usr/bin/env make SHELL=3D/bin/bash LOG=3Ddebug.log OVMFBASE=3Dedk2/Build/OvmfX64/DEBUG_GCC5/ OVMFCODE=3D$(OVMFBASE)/FV/OVMF_CODE.fd OVMFVARS=3D$(OVMFBASE)/FV/OVMF_VARS.fd QEMU=3Dqemu-system-x86_64 QEMUFLAGS=3D-drive format=3Draw,file=3Dfat:rw:image \ -drive if=3Dpflash,format=3Draw,readonly,file=3D$(OVMFCODE) \ -drive if=3Dpflash,format=3Draw,file=3D$(OVMFVARS) \ -debugcon file:$(LOG) -global isa-debugcon.iobase=3D0x402 \ -serial stdio \ -nographic \ -nodefaults run: $(QEMU) $(QEMUFLAGS) debug: $(QEMU) $(QEMUFLAGS) -s -S .PHONY: run debug As first step, I let it run to get a debug.log where all the loading addres= ses are stored: ---------------------------------------------------------------------------= ------------------------------------------ $ make run Here an example of the information stored in debug.log: ---------------------------------------------------------------------------= ----- $ less debug.log ... The 0th FV start address is 0x0000082000 ... Loading PEIM at 0x0000082BFC0 Entry Point =3D 0x0000082F40A PcdPeim.efi ... To extract the .text section from *.efi binaries, I need peinfo: ---------------------------------------------------------------------------= -------------- $ git clone git@github.com:retrage/peinfo.git $ cd peinfo $ make I use peinfo in a bash script (gen_symbol_offset.sh) to get the symbol addr= esses: ...........................................................................= ..................... #!/bin/bash LOG=3D"debug.log" BUILD=3D"edk2/Build/OvmfX64/DEBUG_GCC5/X64" PEINFO=3D"peinfo/peinfo" cat ${LOG} | grep Loading | grep -i efi | while read LINE; do BASE=3D"`echo ${LINE} | cut -d " " -f4`" NAME=3D"`echo ${LINE} | cut -d " " -f6 | tr -d "[:cntrl:]"`" ADDR=3D"`${PEINFO} ${BUILD}/${NAME} \ | grep -A 5 text | grep VirtualAddress | cut -d " " -f2`" TEXT=3D"`python -c "print(hex(${BASE} + ${ADDR}))"`" SYMS=3D"`echo ${NAME} | sed -e "s/\.efi/\.debug/g"`" echo "add-symbol-file ${BUILD}/${SYMS} ${TEXT}" done ...and create a script for gdb to add the symbol files: ---------------------------------------------------------------------------= -- $ bash gen_symbol_offsets.sh > gdbscript $ cat gdb ... add-symbol-file edk2/Build/OvmfX64/DEBUG_GCC5/X64/PcdPeim.debug 0x82c380 add-symbol-file edk2/Build/OvmfX64/DEBUG_GCC5/X64/ReportStatusCodeRouterPei= .debug 0x831080 add-symbol-file edk2/Build/OvmfX64/DEBUG_GCC5/X64/StatusCodeHandlerPei.debu= g 0x833100 add-symbol-file edk2/Build/OvmfX64/DEBUG_GCC5/X64/PlatformPei.debug 0x83510= 0 add-symbol-file edk2/Build/OvmfX64/DEBUG_GCC5/X64/PeiCore.debug 0x7ee8240 add-symbol-file edk2/Build/OvmfX64/DEBUG_GCC5/X64/DxeIpl.debug 0x7ee3240 add-symbol-file edk2/Build/OvmfX64/DEBUG_GCC5/X64/S3Resume2Pei.debug 0x7edf= 240 add-symbol-file edk2/Build/OvmfX64/DEBUG_GCC5/X64/CpuMpPei.debug 0x7ed6240 add-symbol-file edk2/Build/OvmfX64/DEBUG_GCC5/X64/DxeCore.debug 0x7ea8240 add-symbol-file edk2/Build/OvmfX64/DEBUG_GCC5/X64/DevicePathDxe.debug 0x7b8= f240 ... Second step is to run it again with -s -S flags, Qemu waits for connection ---------------------------------------------------------------- $ make debug In a second Terminal I type: ------------------------------------------------- $ gdb (gdb) source gdbscript .... add symbol table from file "/home/koenigr/Memtest/git/edk2/Build/OvmfX64/DE= BUG_GCC5/X64/UsbBusDxe.debug" at .text_addr =3D 0x6c85240 add symbol table from file "/home/koenigr/Memtest/git/edk2/Build/OvmfX64/DE= BUG_GCC5/X64/UsbKbDxe.debug" at .text_addr =3D 0x6cb3240 add symbol table from file "/home/koenigr/Memtest/git/edk2/Build/OvmfX64/DE= BUG_GCC5/X64/UsbMassStorageDxe.debug" at .text_addr =3D 0x6c6d240 add symbol table from file "/home/koenigr/Memtest/git/edk2/Build/OvmfX64/DE= BUG_GCC5/X64/QemuVideoDxe.debug" at .text_addr =3D 0x6c66240 add symbol table from file "/home/koenigr/Memtest/git/edk2/Build/OvmfX64/DE= BUG_GCC5/X64/VirtioGpuDxe.debug" at .text_addr =3D 0x6c60240 add symbol table from file "/home/koenigr/Memtest/git/edk2/Build/OvmfX64/DE= BUG_GCC5/X64/Shell.debug" at .text_addr =3D 0x64f5240 The next three commands are just to verify that the symbols are loaded corr= ectly: ---------------------------------------------------------------------------= ------------------------------------------- (gdb) info functions CoreHandleProtocol All functions matching regular expression "CoreHandleProtocol": File /.../edk2/MdeModulePkg/Core/Dxe/Hand/Handle.c: EFI_STATUS CoreHandleProtocol(EFI_HANDLE, EFI_GUID *, void **); (gdb) info address CoreHandleProtocol Symbol "CoreHandleProtocol" is a function at address 0x7ea4aa9. (gdb) info symbol 0x82F40A _ModuleEntryPoint in section .text of /home/koenigr/Memtest/git/edk2/Build/= OvmfX64/DEBUG_GCC5/X64/PcdPeim.debug (gdb) b CoreHandleProtocol (gdb) b *0x82F40A Breakpoint 2 at 0x82f40a: file /home/koenigr/Memtest/git/edk2/MdePkg/Librar= y/PeimEntryPoint/PeimEntryPoint.c, line 33. (gdb) target remote localhost:1234 Remote debugging using localhost:1234 warning: No executable has been specified and target does not support determining executable automatically.=C2=A0 Try using the "file" command. 0x000000000000fff0 in ?? () (gdb) c Qemu starts to continue.... The debugger should stop at a breakpoint, so that we could do source code l= evel debug. !!!BUT NOTHING HAPPENS.!! OVMF.fd starts und runs until the Shell is loaded and is waiting for user i= nput. BUT NO STOP at any breakpoint. Do you have any suggestions what might be the reason why it does not work? Thanks in advance, Regina K=C3=B6nig --gWVR5vXDAzTj7Je1Ta0L Content-Type: text/html; charset="utf-8" Content-Transfer-Encoding: quoted-printable Hi, I am trying to debug OVMF as suggested in https://retrage.github.io/2019/12/05/debuggi= ng-ovmf-en.html.
Almost every step seems to work fine.

= I built edk2 as follow:
------------------------------
$ git clon= e git@github.com:tianocore/edk2.git\
$ cd edk2$ git s= ubmodule update --init --recursive
$ make -C BaseTools
$ source .= /edksetup.sh
$ build -p OvmfPkg/OvmfPkgX64.dsc -b DEBUG -a X64 -t GCC5=


My Makefile looks like this:
-----------------------= ---------------
#!/usr/bin/env make

SHELL=3D/bin/bash
=
LOG=3Ddebug.log
OVMFBASE=3Dedk2/Build/OvmfX64/DEBUG_GCC5/
O= VMFCODE=3D$(OVMFBASE)/FV/OVMF_CODE.fd
OVMFVARS=3D$(OVMFBASE)/FV/OVMF_V= ARS.fd
QEMU=3Dqemu-system-x86_64
QEMUFLAGS=3D-drive format=3Draw,= file=3Dfat:rw:image \
        =   -drive if=3Dpflash,format=3Draw,readonly,file=3D$(OVMFCODE) \
&= nbsp;         -drive if=3Dpflash,fo= rmat=3Draw,file=3D$(OVMFVARS) \
      &n= bsp;   -debugcon file:$(LOG) -global isa-debugcon.iobase=3D0x402 = \
          -serial stdio= \
          -nographic \=
          -nodefaults
run:
    $(QEMU) $(QEMUFLAGS)

debug= :
    $(QEMU) $(QEMUFLAGS) -s -S

.PHONY: run= debug

As first step, I let it run to get a debug.log where all = the loading addresses are stored:
------------------------------------= ---------------------------------------------------------------------------= ------
$ make run


Here an example of the information = stored in debug.log:
-------------------------------------------------= -------------------------------
$ less debug.log
...
The 0th= FV start address is 0x0000082000
...
Loading PEIM at 0x0000082BF= C0
    Entry Point =3D 0x0000082F40A PcdPeim.efi
.= ..


To extract the .text section from *.efi binaries, I nee= d peinfo:
------------------------------------------------------------= -----------------------------
$ git clone git@github.com:retrage/peinf= o.git
$ cd peinfo
$ make

I use peinfo in a bash script= (gen_symbol_offset.sh) to get the symbol addresses:
.................= ...........................................................................= ....
#!/bin/bash

LOG=3D"debug.log"
BUILD=3D"edk2/Build= /OvmfX64/DEBUG_GCC5/X64"
PEINFO=3D"peinfo/peinfo"

cat ${LOG= } | grep Loading | grep -i efi | while read LINE; do
  BASE=3D"`e= cho ${LINE} | cut -d " " -f4`"
  NAME=3D"`echo ${LINE} | cut -d "= " -f6 | tr -d "[:cntrl:]"`"
  ADDR=3D"`${PEINFO} ${BUILD}/${NAME= } \
        | grep -A 5 text | grep= VirtualAddress | cut -d " " -f2`"
  TEXT=3D"`python -c "print(he= x(${BASE} + ${ADDR}))"`"
  SYMS=3D"`echo ${NAME} | sed -e "s/\.ef= i/\.debug/g"`"
  echo "add-symbol-file ${BUILD}/${SYMS} ${TEXT}"<= br />done

...and create a script for gdb to add the symbol files= :
--------------------------------------------------------------------= ---------
$ bash gen_symbol_offsets.sh > gdbscript
$ cat gdb...
add-symbol-file edk2/Build/OvmfX64/DEBUG_GCC5/X64/PcdPeim.debu= g 0x82c380
add-symbol-file edk2/Build/OvmfX64/DEBUG_GCC5/X64/ReportSta= tusCodeRouterPei.debug 0x831080
add-symbol-file edk2/Build/OvmfX64/DEB= UG_GCC5/X64/StatusCodeHandlerPei.debug 0x833100
add-symbol-file edk2/B= uild/OvmfX64/DEBUG_GCC5/X64/PlatformPei.debug 0x835100
add-symbol-file= edk2/Build/OvmfX64/DEBUG_GCC5/X64/PeiCore.debug 0x7ee8240
add-symbol-= file edk2/Build/OvmfX64/DEBUG_GCC5/X64/DxeIpl.debug 0x7ee3240
add-symb= ol-file edk2/Build/OvmfX64/DEBUG_GCC5/X64/S3Resume2Pei.debug 0x7edf240
add-symbol-file edk2/Build/OvmfX64/DEBUG_GCC5/X64/CpuMpPei.debug 0x7ed6240=
add-symbol-file edk2/Build/OvmfX64/DEBUG_GCC5/X64/DxeCore.debug 0x7ea= 8240
add-symbol-file edk2/Build/OvmfX64/DEBUG_GCC5/X64/DevicePathDxe.d= ebug 0x7b8f240
...

Second step is to run it again with -s -= S flags, Qemu waits for connection
-----------------------------------= -----------------------------
$ make debug


In a secon= d Terminal I type:
-------------------------------------------------$ gdb
(gdb) source gdbscript
....
add symbol table from = file "/home/koenigr/Memtest/git/edk2/Build/OvmfX64/DEBUG_GCC5/X64/UsbBusDxe= .debug" at
        .text_addr =3D 0= x6c85240
add symbol table from file "/home/koenigr/Memtest/git/edk2/Bu= ild/OvmfX64/DEBUG_GCC5/X64/UsbKbDxe.debug" at
    =     .text_addr =3D 0x6cb3240
add symbol table from file= "/home/koenigr/Memtest/git/edk2/Build/OvmfX64/DEBUG_GCC5/X64/UsbMassStorag= eDxe.debug" at          &= nbsp;           &nbs= p;            &= nbsp;     
      &nb= sp; .text_addr =3D 0x6c6d240        = ;            &n= bsp;            = ;         
add symbol table fr= om file "/home/koenigr/Memtest/git/edk2/Build/OvmfX64/DEBUG_GCC5/X64/QemuVi= deoDxe.debug" at          = ;            &n= bsp;            = ;      
      &= nbsp; .text_addr =3D 0x6c66240      
add symb= ol table from file "/home/koenigr/Memtest/git/edk2/Build/OvmfX64/DEBUG_GCC5= /X64/VirtioGpuDxe.debug" at        =             &nb= sp;            =       
      &n= bsp; .text_addr =3D 0x6c60240       &nbs= p;            &= nbsp;           &nbs= p;          
add symbol t= able from file "/home/koenigr/Memtest/git/edk2/Build/OvmfX64/DEBUG_GCC5/X64= /Shell.debug" at          = ;            &n= bsp;            = ;      
      &= nbsp; .text_addr =3D 0x64f5240   

The next three comma= nds are just to verify that the symbols are loaded correctly:
--------= ---------------------------------------------------------------------------= -----------------------------------
(gdb) info functions CoreHandlePro= tocol
All functions matching regular expression "CoreHandleProtocol":<= br />File /.../edk2/MdeModulePkg/Core/Dxe/Hand/Handle.c:
EFI_STATUS Co= reHandleProtocol(EFI_HANDLE, EFI_GUID *, void **);

(gdb) info ad= dress CoreHandleProtocol
Symbol "CoreHandleProtocol" is a function at = address 0x7ea4aa9.

(gdb) info symbol 0x82F40A   &= nbsp;        
_ModuleEntryPoint in = section .text of /home/koenigr/Memtest/git/edk2/Build/OvmfX64/DEBUG_GCC5/X6= 4/PcdPeim.debug


(gdb) b CoreHandleProtocol
(gdb) b *= 0x82F40A           &= nbsp;           &nbs= p;             =
Breakpoint 2 at 0x82f40a: file /home/koenigr/Memtest/git/edk2/MdePkg/= Library/PeimEntryPoint/PeimEntryPoint.c, line 33.  

(gdb) t= arget remote localhost:1234
Remote debugging using localhost:1234 = ;            &n= bsp;            = ;            &n= bsp;  
warning: No executable has been specified and target does = not support      
determining executable auto= matically.  Try using the "file" command.     = ;            &n= bsp;            = ;            
0= x000000000000fff0 in ?? ()  

(gdb) c
Qemu starts to co= ntinue....
The debugger should stop at a breakpoint, so that we could = do source code level debug.

!!!BUT NOTHING HAPPENS.!!
OVMF.= fd starts und runs until the Shell is loaded and is waiting for user input.= BUT NO STOP at any breakpoint.

Do you have any suggestions what= might be the reason why it does not work?

Thanks in advance,Regina König --gWVR5vXDAzTj7Je1Ta0L--