[SOLVED] UEFI debugging

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
chris13524
Member
Member
Posts: 45
Joined: Sat Feb 27, 2016 10:52 pm

[SOLVED] UEFI debugging

Post by chris13524 »

I'm trying to debug my UEFI application, however I'm having problems loading the debug symbol file. I followed this tutorial: http://wiki.osdev.org/Debugging_UEFI_ap ... s_with_GDB

Here's my UEFI boot file:

Code: Select all

EFI_SYSTEM_TABLE* systemTable;
EFI_LOADED_IMAGE* loadedImage;

extern "C" EFIAPI EFI_STATUS efi_main(EFI_HANDLE ImageHandle,
		EFI_SYSTEM_TABLE* _systemTable) {
	systemTable = _systemTable;

	EFI_STATUS status = uefi_call_wrapper(
			(void* ) systemTable->BootServices->HandleProtocol, 3, ImageHandle,
			&LoadedImageProtocol, (void** )&loadedImage);

	if (status != EFI_SUCCESS) {
		crash("error while checking image base");
	}

	// disable the watchdog timer - if this is enabled, the firmware will reset the system after 5 minutes
	EFI_STATUS watchdogStatus = uefi_call_wrapper((void*) systemTable->BootServices->SetWatchdogTimer, 4, 0, 0, 0, NULL);
	if(watchdogStatus != EFI_SUCCESS) {
		crash("error while disabling the watchdog timer");
	}

#ifdef DEBUGGING
	InitializeLib(ImageHandle, systemTable);
	Print((CHAR16*) L"Image base: 0x%lx\n", loadedImage->ImageBase);
	int wait = 1;
	while (wait) {
		__asm__ __volatile__("pause");
	}
#endif

	kernel_main();

	return EFI_SUCCESS;
}
Here's the image base displayed: 0x6738000

Here's my GDB commands and the error produced:

Code: Select all

chris13524@blueberry ~/programming/cpp/aura
 % gdb build/aura.efi 
GNU gdb (Ubuntu 7.11.90.20161005-0ubuntu1) 7.11.90.20161005-git
Copyright (C) 2016 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-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 build/aura.efi...(no debugging symbols found)...done.
(gdb) info files
Symbols from "/home/chris13524/programming/cpp/aura/build/aura.efi".
Local exec file:
	`/home/chris13524/programming/cpp/aura/build/aura.efi', file type pei-x86-64.
	Entry point: 0x8a24
	0x0000000000005000 - 0x000000000000eb90 is .text
	0x000000000000f000 - 0x000000000000f00a is .reloc
	0x0000000000010000 - 0x0000000000012d10 is .data
	0x0000000000013000 - 0x0000000000013160 is .dynamic
	0x0000000000014000 - 0x0000000000014e28 is .rela
	0x0000000000016000 - 0x0000000000018928 is .dynsym
(gdb) file
No executable file now.
No symbol file now.
(gdb) add-symbol-file build/debug.aura.efi 0x673D000 -s .data 0x6748000
add symbol table from file "build/debug.aura.efi" at
	.text_addr = 0x673d000
	.data_addr = 0x6748000
(y or n) y
Reading symbols from build/debug.aura.efi...DW_FORM_strp used without .debug_str section [in module /home/chris13524/programming/cpp/aura/build/debug.aura.efi]
(no debugging symbols found)...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.
0x000000000673d100 in efi_main ()
(gdb) set variable wait = 0
No symbol table is loaded.  Use the "file" command.
(gdb) 
Here's my makefile stuff:

Code: Select all

build/aura.so: $(OBJECTS-all) | build/.dirstamp
	@ld $^                            \
		gnu-efi/crt0-efi-x86_64.o     \
		-nostdlib                     \
		-znocombreloc                 \
		-T gnu-efi/elf_x86_64_efi.lds \
		-shared                       \
		-fPIC                         \
		-Bsymbolic                    \
		-L gnu-efi/libs               \
		-l:libgnuefi.a                \
		-l:libefi.a                   \
		$(LIB_FLAGS)                  \
		-o $@

REGULAR_SECTIONS=-j .text    \
				 -j .sdata   \
				 -j .data    \
				 -j .dynamic \
				 -j .dynsym  \
				 -j .rel     \
				 -j .rela    \
				 -j .reloc   \
				 -j .mish
DEBUG_SECTIONS=-j .debug_info     \
			   -j .debug_abbrev   \
			   -j .debug_loc      \
			   -j .debug_aranges  \
			   -j .debug_line     \
			   -j .debug_macinfo  \
			   -j .debug_debugstr \

OBJCOPY_FLAGS=--target=efi-app-x86_64
build/aura.efi: build/aura.so | build/.dirstamp
	@objcopy $(REGULAR_SECTIONS) \
		$(OBJCOPY_FLAGS)        \
		build/aura.so           \
		build/aura.efi

build/debug.aura.efi: build/aura.so | build/.dirstamp
	@objcopy $(REGULAR_SECTIONS) $(DEBUG_SECTIONS) \
		$(OBJCOPY_FLAGS)      \
		build/aura.so         \
		build/debug.aura.efi
Last edited by chris13524 on Wed Jan 11, 2017 12:44 pm, edited 1 time in total.
My operating system:
https://github.com/neonorb/aura
User avatar
dozniak
Member
Member
Posts: 723
Joined: Thu Jul 12, 2012 7:29 am
Location: Tallinn, Estonia

Re: UEFI debugging

Post by dozniak »

Self-explanatory wrote: (gdb) file
No executable file now.
...
warning: No executable has been specified and target does not support
determining executable automatically. Try using the "file" command.
Learn to read.
chris13524
Member
Member
Posts: 45
Joined: Sat Feb 27, 2016 10:52 pm

Re: UEFI debugging

Post by chris13524 »

dozniak wrote:
Self-explanatory wrote: (gdb) file
No executable file now.
...
warning: No executable has been specified and target does not support
determining executable automatically. Try using the "file" command.
But I did, I did exactly what the tutorial told me to do. Is it inaccurate?
My operating system:
https://github.com/neonorb/aura
User avatar
bzt
Member
Member
Posts: 1584
Joined: Thu Oct 13, 2016 4:55 pm
Contact:

Re: UEFI debugging

Post by bzt »

One thing, it's not gdb related: you should call InitializeLib() as the first thing in your executable, and always, not just when you're debugging. Chances are good that without it, your first uefi_call_wrapper() will misbehave.
robbiedobbie
Member
Member
Posts: 36
Joined: Fri May 16, 2014 2:40 pm
Libera.chat IRC: robbiedobbie

Re: UEFI debugging

Post by robbiedobbie »

Code: Select all

Reading symbols from build/debug.aura.efi...DW_FORM_strp used without .debug_str section [in module /home/chris13524/programming/cpp/aura/build/debug.aura.efi]
(no debugging symbols found)...done.
Your problem is that it's simply not finding any symbols. Did you strip them out of the binary? Or do you have some custom linkerscript or something?
chris13524
Member
Member
Posts: 45
Joined: Sat Feb 27, 2016 10:52 pm

Re: UEFI debugging

Post by chris13524 »

Figured it out, I was adding the section

Code: Select all

.debug_debugstr
instead of

Code: Select all

.debug_str
My operating system:
https://github.com/neonorb/aura
Post Reply