Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SOLUTION FOUND - support remote debug from x86_64 based PC gdb client with gdbgui, to ARM arch gdbserver (multiarch) #237

Open
adowdy opened this issue Oct 11, 2018 · 3 comments

Comments

@adowdy
Copy link

@adowdy adowdy commented Oct 11, 2018

TLDR - I found a way to make gdbgui work for my usecase described! I'll put the fix at the bottom of the post

Is your feature request related to a problem? Please describe.
I really want to be able to use gdbgui frontend for a multiarch remote debugging usecase. My target system is running gdbserver on an ARM based device. If I try to run gdbgui then connect to gdbserver by any means (target remote 192.168.0.212:9091) I get the following issue:

target remote 192.168.0.212:9091

Remote debugging using 192.168.0.212:9091

warning: Architecture rejected target-supplied description

Reading /home/root/myRemoteTestApplicationExecutable from remote target...

warning: File transfers from remote targets can be slow. Use "set sysroot" to access files locally instead.

Architecture of file not recognized.

So I believe this issue is that my desktop machine's gdb binary is not sufficient for multiarch debugging, so I did:
sudo apt-get install gdb-multiarch on my Ubuntu system. I tried it out just with commandline first, and it works like a charm:
gdb-multiarch --eval-command="target remote 192.168.0.212:9091"

Now though, I want to use gdb-multiarch as the debugger binary for gdbgui
gdbgui --gdb gdb-multiarch --gdb-args='--eval-command="target remote 192.168.0.212:9091"'
OR
gdbgui --gdb gdb-multiarch

  • then use GUI to connect to gdbserver...

This method sadly also doesn't work, giving me a different error though:

gdbgui spawned subprocess with pid 28321 from executable gdb-multiarch.

gdb process 28321 is running for this tab

GNU gdb (Ubuntu 7.11.1-0ubuntu1~16.5) 7.11.1

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.

.... editing out some boilerplate GDB output...

set breakpoint pending on

warning: Architecture rejected target-supplied description

Reading /home/root/myRemoteTestApplicationExecutable from remote target...

warning: File transfers from remote targets can be slow. Use "set sysroot" to access files locally instead.

Reading /home/root/myRemoteTestApplicationExecutable from remote target...

Reading symbols from target:/home/root/myRemoteTestApplicationExecutable...

done.

Reading /lib/ld-linux-armhf.so.3 from remote target...

Reading /lib/ld-linux-armhf.so.3 from remote target...

Reading /lib/ld-2.23.so from remote target...

Reading /lib/.debug/ld-2.23.so from remote target...

0x76fcfac0 in ?? () from target:/lib/ld-linux-armhf.so.3

Connected to remote target! Adding breakpoint to main, then continuing target execution.


Program

 received signal SIGSEGV, Segmentation fault.

0x00000000 in ?? ()

gdbgui noticed a signal was recieved (Segmentation fault, SIGSEGV).

If the program exited due to a fault, you can attempt to re-enter the state of the program when the fault 

occurred by clicking the below button.


Program

 received signal SIGSEGV, Segmentation fault.

0x00000000 in ?? ()

gdbgui noticed a signal was recieved (Segmentation fault, SIGSEGV).

If the program exited due to a fault, you can attempt to re-enter the state of the program when the fault 

occurred by clicking the below button.


Program terminated with signal 

SIGSEGV, Segmentation fault.

The program no longer exists.

/home/root/myRemoteTestApplicationExecutable: No such file or directory.

Cannot access memory at address 0x0

Describe the solution you'd like
I am not picky, but so long as there's a way to use gdbgui to debug a remote gdbserver that's actually running ARM arch instead of matching the desktop architecture would be an absolute dream! (I'd even take a solution from any similar tool to gdbgui, but this one is really quite nice).

Describe alternatives you've considered
The closest I've gotten (aside from just using gdb-multiarch commandline) is using ddd but it's ancient and buggy on my modern system.
ddd --eval-command="target remote $ADOLOCAL:9091" --debugger gdb-multiarch
This gives some sort of minimal GUI and I've been able to set breakpoints and step through (so it gets further than gdbgui at the moment) -- but it's really clunky, and freezes up constantly.

Additional context
alt text

TLDR Solution:

I was trying to rely on a prebuild gdb-multiarch from ubuntu apt repos, which didn't work. When I decided to download gdb and rebuild from source while configuring for arm-linux-gnuabi target arch.

Build method:

  1. downloaded latest gdb source code
  2. unzip it, go into folder
./configure  --host=x86_64-pc-linux-gnu --build=x86_64-pc-linux-gnu --target=arm-linux-gnuabi &&
make -j8 &&
sudo make install
  1. now arm-linux-gnuabi-gdb is installed by default to /usr/local/bin ... but you can instead provide prefix=<path> to where you want it to install in ./configure script above

Using this, I was able to build a secondary copy of gdb called arm-linux-gnuabi-gdb which i could feed to gdbgui like this:

gdbgui -g arm-linux-gnuabi-gdb

Works great! This is leaps and bounds better than running gdb on commandline on my remote target.

Relevant link for building gdb:
https://sourceware.org/gdb/wiki/BuildingCrossGDBandGDBserver
http://www.brain-dump.org/blog/entry/138/Cross_Arch_Remote_Debugging_with_gdb_and_gdbserver

@adowdy adowdy changed the title support remote debug from x86_64 based PC gdb client with gdbgui, to ARM arch gdbserver (multiarch) SOLUTION FOUND - support remote debug from x86_64 based PC gdb client with gdbgui, to ARM arch gdbserver (multiarch) Oct 12, 2018
@E3V3A
Copy link

@E3V3A E3V3A commented Oct 25, 2018

@nerael
Thanks for sharing this very helpful and useful info.

@cs01
Copy link
Owner

@cs01 cs01 commented Apr 21, 2019

I updated gdbgui's docs to be easier to modify for the community. They are all hosted in this repository under docs/, and are just markdown files. This should be added to give it this workflow exposure. Thanks for writing it up!

@seanybaggins
Copy link

@seanybaggins seanybaggins commented Jun 7, 2021

This solution is somewhat out of date. The API for gdbgui has changed.

gdbgui --version
0.14.0.2

trying to modify the tutorial here to match the current API.

Here is the command I ultimately end up running.

gdbgui --gdb-cmd 'arm-none-eabi-gdb -command=debug.gdb' target/thumbv7em-none-eabihf/debug/blinky-st

Here is the content of my debug.gdb file

# This connects to the GDB server running locally.
#   - for openocd, use port :3333
#   - for JLinkGDBServer, use port :2331
target remote :3333

# Due to https://github.com/rust-embedded/cortex-m-rt/issues/139,
#   we will get an infinite backtrace on a panic!(). Set a finite
#   limit to the backtrace to prevent the debugger falling into
#   an endless loop trying to read the backtrace
set backtrace limit 32

# Load the specified firmware onto the device
load

# Reset the target device before running (using JLinkGDBServer)
# monitor reset

# Reset the target device before running (using openocd)
monitor reset halt

# Begin running the program
continue

The gui launches but gdb does not load the microprocessor. I think it is because the script does not have the binary being passed to it.

GDB input terminal

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 "--host=x86_64-pc-linux-gnu --target=arm-none-eabi".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
<https://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".
warning: No executable has been specified and target does not support
determining executable automatically.  Try using the "file" command.


debug.gdb:13: Error in sourced command file:
No executable file specified.
Use the "file" or "exec-file" command.
New UI allocated

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
4 participants