OSDev.org

The Place to Start for Operating System Developers
It is currently Fri Mar 29, 2024 2:39 am

All times are UTC - 6 hours




Post new topic Reply to topic  [ 6 posts ] 
Author Message
 Post subject: [SOLVED] UEFI debugging
PostPosted: Tue Jan 10, 2017 11:42 am 
Offline
Member
Member

Joined: Sat Feb 27, 2016 10:52 pm
Posts: 45
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:
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:
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:
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

_________________
My operating system:
https://github.com/neonorb/aura


Last edited by chris13524 on Wed Jan 11, 2017 12:44 pm, edited 1 time in total.

Top
 Profile  
 
 Post subject: Re: UEFI debugging
PostPosted: Tue Jan 10, 2017 12:00 pm 
Offline
Member
Member
User avatar

Joined: Thu Jul 12, 2012 7:29 am
Posts: 723
Location: Tallinn, Estonia
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.


Top
 Profile  
 
 Post subject: Re: UEFI debugging
PostPosted: Tue Jan 10, 2017 12:22 pm 
Offline
Member
Member

Joined: Sat Feb 27, 2016 10:52 pm
Posts: 45
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


Top
 Profile  
 
 Post subject: Re: UEFI debugging
PostPosted: Tue Jan 10, 2017 4:23 pm 
Offline
Member
Member
User avatar

Joined: Thu Oct 13, 2016 4:55 pm
Posts: 1584
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.


Top
 Profile  
 
 Post subject: Re: UEFI debugging
PostPosted: Wed Jan 11, 2017 12:19 am 
Offline
Member
Member

Joined: Fri May 16, 2014 2:40 pm
Posts: 36
Code:
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?


Top
 Profile  
 
 Post subject: Re: UEFI debugging
PostPosted: Wed Jan 11, 2017 10:13 am 
Offline
Member
Member

Joined: Sat Feb 27, 2016 10:52 pm
Posts: 45
Figured it out, I was adding the section
Code:
.debug_debugstr
instead of
Code:
.debug_str

_________________
My operating system:
https://github.com/neonorb/aura


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 6 posts ] 

All times are UTC - 6 hours


Who is online

Users browsing this forum: Bing [Bot], DotBot [Bot], Google [Bot] and 94 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group