cs01 / gdbgui

Browser-based frontend to gdb (gnu debugger). Add breakpoints, view the stack, visualize data structures, and more in C, C++, Go, Rust, and Fortran. Run gdbgui from the terminal and a new tab will open in your browser.
https://gdbgui.com
GNU General Public License v3.0
9.9k stars 499 forks source link

Issue reading symbols while running remote ARM gdb session #389

Open lukehutch opened 3 years ago

lukehutch commented 3 years ago

Describe the bug I am trying to use gdbgui with TeensyDebug, a gdb stub for the Teensy SBC: https://github.com/ftrias/TeensyDebug

When I run with gdbgui rather than gdb, gdbgui is not able to read the symbols from the executable.

Running under commandline gdb:

Command:

/opt/arduino-1.8.13/hardware/tools/arm/bin/arm-none-eabi-gdb /tmp/arduino_build_637692/Test_Teensy.ino.elf

gdb session:

$ /opt/arduino-1.8.13/hardware/tools/arm/bin/arm-none-eabi-gdb /tmp/arduino_build_637692/Test_Teensy.ino.elf
GNU gdb (GNU Tools for ARM Embedded Processors) 7.10.1.20160923-cvs
Copyright (C) 2015 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 "--host=x86_64-linux-gnu --target=arm-none-eabi".
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 /tmp/arduino_build_637692/Test_Teensy.ino.elf...done.
(gdb) target remote /dev/ttyACM1
Remote debugging using /dev/ttyACM1
setup_main () at /home/luke/Arduino/Test_Teensy/Test_Teensy.ino:81
81    Serial.printf(F("Initializing\n"));
(gdb) quit

Running under gdbgui:

Commandline:

gdbgui --debug -g /opt/arduino-1.8.13/hardware/tools/arm/bin/arm-none-eabi-gdb --args /tmp/arduino_build_637692/Test_Teensy.ino.elf

First pane:

running command: /opt/arduino-1.8.13/hardware/tools/arm/bin/arm-none-eabi-gdb

Exception ignored in: <function _after_fork at 0x7faa98d8a670>
Traceback (most recent call last):
  File "/usr/lib64/python3.9/threading.py", line 1490, in _after_fork
    thread._reset_internal_locks(True)
  File "/usr/lib64/python3.9/threading.py", line 827, in _reset_internal_locks
    self._started._at_fork_reinit()
  File "/usr/lib64/python3.9/threading.py", line 527, in _at_fork_reinit
    self._cond._at_fork_reinit()
  File "/usr/lib64/python3.9/threading.py", line 253, in _at_fork_reinit
    self._lock._at_fork_reinit()
AttributeError: 'Semaphore' object has no attribute '_at_fork_reinit'
GNU gdb (GNU Tools for ARM Embedded Processors) 7.10.1.20160923-cvs
Copyright (C) 2015 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 "--host=x86_64-linux-gnu --target=arm-none-eabi".
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".
Undefined command: "new-ui".  Try "help".
(gdb) target remote /dev/ttyACM1
Remote debugging using /dev/ttyACM1
Register 25 is not available
0x00000184 in ?? ()

Second pane:

gdbgui output (read-only)
Copy/Paste available in all terminals with ctrl+shift+c, ctrl+shift+v
-exec-arguments 
-file-exec-and-symbols /tmp/arduino_build_637692/Test_Teensy.ino.elf
-break-insert main
-break-list
Started new gdb process, pid 3165910
-list-features
-list-target-features
No gdb response received after 10 seconds.
Possible reasons include:
1) gdbgui, gdb, or the debugged process is not running.
2) gdb or the inferior process is busy running and needs to be interrupted (press the pause button up top).
3) Something is just taking a long time to finish and respond back to this browser window, in which case you can just keep waiting.
1-thread-info
1-stack-list-variables --simple-values
1-var-update --all-values *
-break-list
1-stack-list-frames

To Reproduce See above

Expected behavior gdbgui should work exactly the same as commandline gdb

Please complete the following information:

cs01 commented 3 years ago

There is an error being raised which is likely the cause of this:

AttributeError: 'Semaphore' object has no attribute '_at_fork_reinit'

Could you try downloading and running a prebuilt release from the GitHub releases page?

lukehutch commented 3 years ago

@cs01 I really appreciate the quick response.

I'm not sure what is going on here...

$ /opt/gdbgui_0.14.0.2 --debug -g /opt/arduino-1.8.13/hardware/tools/arm/bin/arm-none-eabi-gdb --args /tmp/arduino_build_637692/Test_Teensy.ino.elf
failed to initialize socketio app with async mode "eventlet". Continuing with async mode "threading".
View gdbgui at http://127.0.0.1:5000
View gdbgui dashboard at http://127.0.0.1:5000/dashboard
exit gdbgui by pressing CTRL+C
(2021-05-17 19:38:39,449) WebSocket transport not available. Install eventlet or gevent and gevent-websocket for improved performance.
(2021-05-17 19:38:39,450)  * Running on %s://%s:%d/ %s
(2021-05-17 19:38:39,450)  * Restarting with stat
usage: gdbgui_0.14.0.2 [-h] [-g GDB_CMD] [-p PORT] [--host HOST] [-r]
                       [--auth-file AUTH_FILE] [--user USER]
                       [--password PASSWORD] [--key KEY] [--cert CERT]
                       [--remap-sources REMAP_SOURCES] [--project PROJECT]
                       [-v] [-n] [-b BROWSER] [--debug] [--args ...]
                       [debug_program]
gdbgui_0.14.0.2: error: argument --args: not allowed with argument debug_program

$ /opt/gdbgui_0.14.0.2 --debug -g /opt/arduino-1.8.13/hardware/tools/arm/bin/arm-none-eabi-gdb /tmp/arduino_build_637692/Test_Teensy.ino.elf
failed to initialize socketio app with async mode "eventlet". Continuing with async mode "threading".
View gdbgui at http://127.0.0.1:5000
View gdbgui dashboard at http://127.0.0.1:5000/dashboard
exit gdbgui by pressing CTRL+C
(2021-05-17 19:48:57,693) WebSocket transport not available. Install eventlet or gevent and gevent-websocket for improved performance.
(2021-05-17 19:48:57,694)  * Running on %s://%s:%d/ %s
(2021-05-17 19:48:57,694)  * Restarting with stat
usage: gdbgui_0.14.0.2 [-h] [-g GDB_CMD] [-p PORT] [--host HOST] [-r]
                       [--auth-file AUTH_FILE] [--user USER]
                       [--password PASSWORD] [--key KEY] [--cert CERT]
                       [--remap-sources REMAP_SOURCES] [--project PROJECT]
                       [-v] [-n] [-b BROWSER] [--debug] [--args ...]
                       [debug_program]
gdbgui_0.14.0.2: error: unrecognized arguments: /tmp/arduino_build_637692/Test_Teensy.ino.elf
cs01 commented 3 years ago

Hmm not sure what’s going on with that, but you can see available options with the “—help” flag and go from there.

lukehutch commented 3 years ago

@cs01 removing the --debug fixed the errors in my previous comment. (I had that option added because of #382, in the pip version -- but the prebuilt latest release version doesn't seem to need that option anymore, so maybe you can close that bug.)

However, the prebuilt latest build version still can't read the symbols from the binary.

Command:

$ /opt/gdbgui_0.14.0.2 -g /opt/arduino-1.8.13/hardware/tools/arm/bin/arm-none-eabi-gdb /tmp/arduino_build_637692/Test_Teensy.ino.elf

First pane:

running command: /opt/arduino-1.8.13/hardware/tools/arm/bin/arm-none-eabi-gdb

GNU gdb (GNU Tools for ARM Embedded Processors) 7.10.1.20160923-cvs
Copyright (C) 2015 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 "--host=x86_64-linux-gnu --target=arm-none-eabi".
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".
Undefined command: "new-ui".  Try "help".
(gdb) target remote /dev/ttyACM1
Remote debugging using /dev/ttyACM1
Register 25 is not available
0x00000184 in ?? ()

Second pane:

gdbgui output (read-only)
Copy/Paste available in all terminals with ctrl+shift+c, ctrl+shift+v
Started new gdb process, pid 3182761
No gdb response received after 10 seconds.
Possible reasons include:
1) gdbgui, gdb, or the debugged process is not running.
2) gdb or the inferior process is busy running and needs to be interrupted (press the pause button up top).
3) Something is just taking a long time to finish and respond back to this browser window, in which case you can just keep waiting.
lukehutch commented 3 years ago

I figured out some more things...

From the gdbgui help:

usage: gdbgui_0.14.0.2 [-h] [-g GDB_CMD] [-p PORT] [--host HOST] [-r] [--auth-file AUTH_FILE] [--user USER] [--password PASSWORD] [--key KEY] [--cert CERT] [--remap-sources REMAP_SOURCES] [--project PROJECT] [-v] [-n] [-b BROWSER] [--debug] [--args ...] [debug_program]

No matter what I put as --args or [debug_program], it is ignored.

But the commandline options do seem to be passed through to the gdbgui.html template OK -- from the web source for the request for / , the JSON parameter is initial_binary_and_args:

initial_data = {"csrf_token": "...", "gdb_command": "/opt/arduino-1.8.13/hardware/tools/arm/bin/arm-none-eabi-gdb", "gdbgui_version": "0.14.0.2", "gdbpid": 0, "initial_binary_and_args": ["/tmp/arduino_build_637692/Test_Teensy.ino.elf"], "project_home": null, "remap_sources": {}, "signals": {...}, "themes": ["monokai", "light"], "using_windows": false}

lukehutch commented 3 years ago

@cs01 As far as I can tell, the initial_binary_and_args arg is ignored by gdbgui:

https://github.com/cs01/gdbgui/blob/531d89890c0b4bd3bbf15d266b9ec25a2c7eebaa/gdbgui/server/app.py#L104

app.config["gdb_command"] is used, but app.config["initial_binary_and_args"] is not used to start a new gdb session.