public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
* Debugging Ovmf with GDB: No symbol is recognized
@ 2022-05-20 13:10 koenig_regina
  2022-05-23 12:01 ` [edk2-devel] " Oliver Steffen
  2024-08-25 19:05 ` Moon Fault
  0 siblings, 2 replies; 6+ messages in thread
From: koenig_regina @ 2022-05-20 13:10 UTC (permalink / raw)
  To: devel

[-- Attachment #1: Type: text/plain, Size: 6028 bytes --]

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 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=/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 git@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

[-- Attachment #2: Type: text/html, Size: 9921 bytes --]

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2024-08-27 15:12 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-05-20 13:10 Debugging Ovmf with GDB: No symbol is recognized koenig_regina
2022-05-23 12:01 ` [edk2-devel] " Oliver Steffen
2024-08-25 19:05 ` Moon Fault
2024-08-26 20:48   ` Andrew Fish via groups.io
2024-08-27  8:32     ` Moon Fault
2024-08-27 15:11       ` Andrew Fish via groups.io

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox