Hi Regina,

I am not sure if I can help you with exactly the approach you are describing.
Are you aware of the efi_gdb.py script in BaseToosl/Scripts?
This can be used to debug OVMF with Qemu and gdb.

See these messages:
https://edk2.groups.io/g/devel/message/89621
https://edk2.groups.io/g/devel/message/77969

- Oliver

On Mon, May 23, 2022 at 3:03 AM koenig_regina via groups.io
<koenig_regina=arcor...@groups.io> wrote:
>
> Hi, I am trying to debug OVMF as suggested in 
> https://retrage.github.io/2019/12/05/debugging-ovmf-en.html.
> Almost every step seems to work fine.
>
> I built edk2 as follow:
> ------------------------------
> $ git clone g...@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=/bin/bash
>
> LOG=debug.log
> OVMFBASE=edk2/Build/OvmfX64/DEBUG_GCC5/
> OVMFCODE=$(OVMFBASE)/FV/OVMF_CODE.fd
> OVMFVARS=$(OVMFBASE)/FV/OVMF_VARS.fd
> QEMU=qemu-system-x86_64
> QEMUFLAGS=-drive format=raw,file=fat:rw:image \
>           -drive if=pflash,format=raw,readonly,file=$(OVMFCODE) \
>           -drive if=pflash,format=raw,file=$(OVMFVARS) \
>           -debugcon file:$(LOG) -global isa-debugcon.iobase=0x402 \
>           -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 0x0000082BFC0
>     Entry Point = 0x0000082F40A PcdPeim.efi
> ...
>
>
> To extract the .text section from *.efi binaries, I need peinfo:
> -----------------------------------------------------------------------------------------
> $ git clone g...@github.com:retrage/peinfo.git
> $ cd peinfo
> $ make
>
> I use peinfo in a bash script (gen_symbol_offset.sh) to get the symbol 
> addresses:
> ................................................................................................
> #!/bin/bash
>
> LOG="debug.log"
> BUILD="edk2/Build/OvmfX64/DEBUG_GCC5/X64"
> PEINFO="peinfo/peinfo"
>
> cat ${LOG} | grep Loading | grep -i efi | while read LINE; do
>   BASE="`echo ${LINE} | cut -d " " -f4`"
>   NAME="`echo ${LINE} | cut -d " " -f6 | tr -d "[:cntrl:]"`"
>   ADDR="`${PEINFO} ${BUILD}/${NAME} \
>         | grep -A 5 text | grep VirtualAddress | cut -d " " -f2`"
>   TEXT="`python -c "print(hex(${BASE} + ${ADDR}))"`"
>   SYMS="`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.debug 
> 0x833100
> add-symbol-file edk2/Build/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-symbol-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 0x7ea8240
> add-symbol-file edk2/Build/OvmfX64/DEBUG_GCC5/X64/DevicePathDxe.debug 
> 0x7b8f240
> ...
>
> 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/DEBUG_GCC5/X64/UsbBusDxe.debug" 
> at
>         .text_addr = 0x6c85240
> add symbol table from file 
> "/home/koenigr/Memtest/git/edk2/Build/OvmfX64/DEBUG_GCC5/X64/UsbKbDxe.debug" 
> at
>         .text_addr = 0x6cb3240
> add symbol table from file 
> "/home/koenigr/Memtest/git/edk2/Build/OvmfX64/DEBUG_GCC5/X64/UsbMassStorageDxe.debug"
>  at
>         .text_addr = 0x6c6d240
> add symbol table from file 
> "/home/koenigr/Memtest/git/edk2/Build/OvmfX64/DEBUG_GCC5/X64/QemuVideoDxe.debug"
>  at
>         .text_addr = 0x6c66240
> add symbol table from file 
> "/home/koenigr/Memtest/git/edk2/Build/OvmfX64/DEBUG_GCC5/X64/VirtioGpuDxe.debug"
>  at
>         .text_addr = 0x6c60240
> add symbol table from file 
> "/home/koenigr/Memtest/git/edk2/Build/OvmfX64/DEBUG_GCC5/X64/Shell.debug" at
>         .text_addr = 0x64f5240
>
> The next three commands are just to verify that the symbols are loaded 
> correctly:
> ----------------------------------------------------------------------------------------------------------------------
> (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/Library/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.  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 
> 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
> 



-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#89964): https://edk2.groups.io/g/devel/message/89964
Mute This Topic: https://groups.io/mt/91279461/21656
Group Owner: devel+ow...@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [arch...@mail-archive.com]
-=-=-=-=-=-=-=-=-=-=-=-


Reply via email to