Page 1 of 1

[Help] Debugging UEFI application with GDB in VS Code?

Posted: Thu Jun 08, 2023 12:38 pm
by CousinOfThor
I'm making a basic UEFI bootloader (filename: BootX64.efi), which loads a ELF64 kernel, both written in C on Arch Linux x86_64 and built with clang and lld. I am testing it with qemu-system-x86_64 with [ur=https://archlinux.org/packages/extra/any/edk2-ovmfl]OVMF[/url] as firmware. You can find the source code, along with a Makefile, here: https://github.com/CousinOfThor/uefi-elf. I would like to debug it in VS Code with GDB, but I am not able to do so: I run QEMU with the flags -gdb tcp::1234 -S, as you can see in the Makefile, and I am able to connect to it running gdb BootX64.efi, then, inside GDB, I run target remote localhost:1234, and I can continue the execution. Now, onto VS Code: the best I was able to come up with is this launch.json configuration:

Code: Select all

{
     "version": "0.2.0",
     "configurations": [
         {
             "name": "Attach",
             "type": "gdb",
             "request": "attach",
             "executable": "./BootX64.efi",
             "target": "localhost:1234",
             "cwd": "${workspaceRoot}",
             "remote": true,
          }   
      ]
}
I can connect to QEMU, because I see it start running the bootloader as soon as I press F5 to start debugging, but I can't step through the code. I enabled the debug info on clang with the option -ggdb, both for the bootloader and the kernel, but GDB says it can not read the BootX64.pdb produced by clang while compiling the bootloader, nor I can step through the code of the ELF64 kernel.

How is it possible to do this? Any help is appreciated, thanks.

Re: [Help] Debugging UEFI application with GDB in VS Code?

Posted: Thu Jun 15, 2023 12:12 pm
by Octocontrabass
This question was asked and answered elsewhere. (In short: use LLDB instead, because it recognizes the PDB file.)