OSDev.org https://forum.osdev.org/ |
|
UEFI debugging with GDB in QEMU https://forum.osdev.org/viewtopic.php?f=1&t=33000 |
Page 1 of 1 |
Author: | Freggar [ Tue Jun 12, 2018 11:39 am ] |
Post subject: | UEFI debugging with GDB in QEMU |
I'm trying to debug UEFI with GDB in QEMU, but can't get the debug symbol loaded correctly. I've followed the tutorial from http://wiki.osdev.org/Debugging_UEFI_ap ... s_with_GDB and have already seen another related forum thread (viewtopic.php?f=1&t=31192) but sadly couldn't apply my problem to it. Here's the main.c file: Code: #include <efi.h> #include <efilib.h> EFI_STATUS efi_main (EFI_HANDLE image, EFI_SYSTEM_TABLE *systab) { EFI_LOADED_IMAGE *loaded_image = NULL; EFI_STATUS status; InitializeLib(image, systab); status = uefi_call_wrapper(systab->BootServices->HandleProtocol, 3, image, &LoadedImageProtocol, (void **)&loaded_image); if (EFI_ERROR(status)) { Print(L"handleprotocol: %r\n", status); } Print(L"Image base: 0x%lx\n", loaded_image->ImageBase); int wait = 1; while (wait) { __asm__ __volatile__("pause"); } return EFI_SUCCESS; } Ouptut of the UEFI App: Code: Image base: 0x2EA1D000 Here's how I try to load GDB and the error that occurs: Code: [piri@XPIRI efi_gdb]$ gdb BOOTx64.EFI GNU gdb (GDB) 8.1 Copyright (C) 2018 Free Software Foundation, Inc. License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html> This is free software: you are free to change and redistribute it. There is NO WARRANTY, to the extent permitted by law. Type "show copying" and "show warranty" for details. This GDB was configured as "x86_64-pc-linux-gnu". Type "show configuration" for configuration details. For bug reporting instructions, please see: <http://www.gnu.org/software/gdb/bugs/>. Find the GDB manual and other documentation resources online at: <http://www.gnu.org/software/gdb/documentation/>. For help, type "help". Type "apropos word" to search for commands related to "word"... Reading symbols from BOOTx64.EFI...(no debugging symbols found)...done. (gdb) info files Symbols from "/home/piri/osdev/efi_gdb/BOOTx64.EFI". Local exec file: `/home/piri/osdev/efi_gdb/BOOTx64.EFI', file type pei-x86-64. Entry point: 0x3000 0x0000000000003000 - 0x0000000000008950 is .text 0x0000000000009000 - 0x000000000000900a is .reloc 0x000000000000a000 - 0x000000000000bce0 is .data 0x000000000000c000 - 0x000000000000c100 is .dynamic 0x000000000000d000 - 0x000000000000de58 is .rela 0x000000000000e000 - 0x000000000000e210 is .dynsym (gdb) file No executable file now. No symbol file now. (gdb) add-symbol-file debug.BOOTx64.EFI 0x2EA20000 -s .data 0x2EA27000 add symbol table from file "debug.BOOTx64.EFI" at .text_addr = 0x2ea20000 .data_addr = 0x2ea27000 (y or n) y Reading symbols from debug.BOOTx64.EFI...done. (gdb) set architecture i386:x86-64:intel The target architecture is assumed to be i386:x86-64:intel (gdb) target remote :1234 Remote debugging using :1234 warning: No executable has been specified and target does not support determining executable automatically. Try using the "file" command. 0x000000002ea200cf in efi_main () (gdb) set variable wait = 0 No symbol "wait" in current context. (gdb) And lastly my Makefile: Code: ARCH = x86_64
OBJS = main.o TARGET = BOOTx64.EFI EFIINC = /usr/include/efi EFIINCS = -I$(EFIINC) -I$(EFIINC)/$(ARCH) -I$(EFIINC)/protocol EFILIB = /usr/lib EFI_CRT_OBJS = $(EFILIB)/crt0-efi-$(ARCH).o EFI_LDS = $(EFILIB)/elf_$(ARCH)_efi.lds CFLAGS = $(EFIINCS) -fno-stack-protector -fpic \ -fshort-wchar -mno-red-zone -Wall ifeq ($(ARCH),x86_64) CFLAGS += -DEFI_FUNCTION_WRAPPER endif LDFLAGS = -nostdlib -znocombreloc -T $(EFI_LDS) -shared \ -Bsymbolic -L $(EFILIB) $(EFI_CRT_OBJS) SECTIONS = .text .sdata .data .dynamic .dynsym .rel .rela .reloc DEBUG_SECTIONS = .debug_info .debug_abbrev .debug_loc .debug_aranges \ .debug_line .debug_macinfo .debug_str .PHONY : all all: $(TARGET) debug.$(TARGET) BOOTx64.so: $(OBJS) ld $(LDFLAGS) $(OBJS) -o $@ -lefi -lgnuefi %.EFI: %.so objcopy $(foreach sec,$(SECTIONS), -j $(sec))\ --target=efi-app-$(ARCH) $^ $@ debug.%.EFI: %.so objcopy $(foreach sec,$(SECTIONS) $(DEBUG_SECTIONS), -j $(sec))\ --target=efi-app-$(ARCH) $^ $@ |
Page 1 of 1 | All times are UTC - 6 hours |
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group http://www.phpbb.com/ |