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

Is it possible to add GDB debugger in this toolchain? #7

Closed
oneWayOut opened this issue Jan 12, 2019 · 11 comments
Closed

Is it possible to add GDB debugger in this toolchain? #7

oneWayOut opened this issue Jan 12, 2019 · 11 comments
Assignees
Labels
question Further information is requested

Comments

@oneWayOut
Copy link
Contributor

The windows toolchain is awesome. I tried to debug the program in simulation but didn't find gdb. Could you add GDB in this toolchain?

@bys1123
Copy link

bys1123 commented Jan 12, 2019

FYI PX4/PX4-Autopilot#10911

@hamishwillee
Copy link

A question for you @MaEtUgR !

@oneWayOut
Copy link
Contributor Author

Thank you! 谢谢! @bys1123

@MaEtUgR MaEtUgR added the question Further information is requested label Jan 13, 2019
@MaEtUgR
Copy link
Member

MaEtUgR commented Jan 13, 2019

@oneWayOut Yes it's theoretically well possible. I think it should even work out of the box if you use gdb which is shipped with cygwin. I can give you some hints but I guess won't have the time to add it myself anytime soon.

  • Download the cygwin installer https://cygwin.com/setup-x86_64.exe
  • start it and choose C:\PX4\toolchain\cygwin64 as installation folder
  • search for the packages you need e.g. gdb
  • continue and install them
  • run them from the run-console.bat terminal

If you figure it out and get the debugger working I'm happy to incorporate pull requests e.g. extending this script: https://github.com/PX4/windows-toolchain/blob/master/toolchain/cygwin64/install-cygwin-px4.bat

@oneWayOut
Copy link
Contributor Author

@MaEtUgR Thanks for your prompt response.
Following your instructions, I installed gdb 7.9.1-1 successfully.
But the command " make px4_sitl_default jmavsim___gdb " doesn't work properly.
image
It seems that PX4.exe could not be found. But I checked that it is definitely there.
"make px4_sitl_default jmavsim" still works fine.

Anyway, this toolchain is good enough for me, Thank you. If I need debug, I can do it in Ubuntu.

@hamishwillee
Copy link

@MaEtUgR Would be good to understand why that toolchain doesn't find PX4 - we're so close to getting this working, would be good to get it all the way :-)

Any ideas?

@MaEtUgR
Copy link
Member

MaEtUgR commented Jan 15, 2019

@hamishwillee You have a point, espacially because it should in principle work.

Now I took myself the time to try out the basic test, installed the gdb version currently recommended by cygwin $ gdb --version -> GNU gdb (GDB) (Cygwin 8.0.1-1) 8.0.1. Started the makefile with the previously mentioned command and got it running. The part which failed for @oneWayOut succeeded Reading symbols from /cygdrive/c/PX4/home/Firmware/build/px4_sitl_default/bin/px4.exe...done. and I got into the gdb console. I'm gdb terminal noob but after I found out I have to run the program first with the command r, I saw the application starting and some debug output what the threads are doing and got some memory address info of the stack frame and program counter. I'm not sure how to proceed from there but I'm sure if you know how to use gdb it is working fine.

Here's my console output:

MaEtUgR@Optiplex ~/Firmware
$ make px4_sitl_default jmavsim___gdb
ninja: Entering directory `/cygdrive/c/PX4/home/Firmware/build/px4_sitl_default'
[6/697] git submodule src/drivers/gps/devices
[17/697] git submodule src/lib/DriverFramework
[20/697] git submodule src/lib/ecl
[176/697] git submodule mavlink/include/mavlink/v2.0
[191/697] git submodule Tools/jMAVSim
[696/697] cd /cygdrive/c/PX4/home/Firmware/build/px4_sitl_default/tmp && /cygdrive/c/PX4/home/Firmware/Tools/sitl_run.sh /cygdrive/c/PX4/ho...ware/build/px4_sitl_default/bin/px4.exe gdb jmavsim none /cygdrive/c/PX4/home/Firmware /cygdrive/c/PX4/home/Firmware/build/px4_sitl_default
SITL ARGS
sitl_bin: /cygdrive/c/PX4/home/Firmware/build/px4_sitl_default/bin/px4.exe
debugger: gdb
program: jmavsim
model: none
src_path: /cygdrive/c/PX4/home/Firmware
build_path: /cygdrive/c/PX4/home/Firmware/build/px4_sitl_default
empty model, setting iris as default
SITL COMMAND: "/cygdrive/c/PX4/home/Firmware/build/px4_sitl_default/bin/px4.exe" "/cygdrive/c/PX4/home/Firmware"/ROMFS/px4fmu_common -s etc/init.d-posix/rcS -t "/cygdrive/c/PX4/home/Firmware"/test_data
GNU gdb (GDB) (Cygwin 8.0.1-1) 8.0.1
Copyright (C) 2017 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-pc-cygwin".
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 /cygdrive/c/PX4/home/Firmware/build/px4_sitl_default/bin/px4.exe...done.
warning: File "/cygdrive/c/PX4/home/Firmware/build/px4_sitl_default/tmp/rootfs/.gdbinit" auto-loading has been declined by your `auto-load safe-path' set to "$debugdir:$datadir/auto-load".
To enable execution of this file add
        add-auto-load-safe-path /cygdrive/c/PX4/home/Firmware/build/px4_sitl_default/tmp/rootfs/.gdbinit
line to your configuration file "/cygdrive/c/PX4/home/.gdbinit".
To completely disable this security protection add
        set auto-load safe-path /
line to your configuration file "/cygdrive/c/PX4/home/.gdbinit".
For more information about this security protection see the
"Auto-loading safe path" section in the GDB manual.  E.g., run from the shell:
        info "(gdb)Auto-loading safe path"
(gdb) Buildfile: C:\PX4\home\Firmware\Tools\jMAVSim\build.xml

make_dirs:

compile:
    [javac] Compiling 26 source files to C:\PX4\home\Firmware\Tools\jMAVSim\out\production\jMAVSim

create_run_jar:
      [jar] Building jar: C:\PX4\home\Firmware\Tools\jMAVSim\out\production\jmavsim_run.jar

copy_res:

BUILD SUCCESSFUL
Total time: 2 seconds
Options parsed, starting Sim.
Starting GUI...
3D [dev] 1.6.0-pre12-daily-experimental daily


(gdb)
(gdb) i args
No frame selected.
(gdb) info break
No breakpoints or watchpoints.
(gdb) where
No stack.
(gdb) where
No stack.
(gdb) where
No stack.
(gdb) info frame
No stack.
(gdb) r
Starting program: /cygdrive/c/PX4/home/Firmware/build/px4_sitl_default/bin/px4.exe /cygdrive/c/PX4/home/Firmware/ROMFS/px4fmu_common -s etc/init.d-posix/rcS -t /cygdrive/c/PX4/home/Firmware/test_data
[New Thread 17016.0xae20]
[New Thread 17016.0x938c]
[New Thread 17016.0xb38c]
[New Thread 17016.0x49cc]
[New Thread 17016.0x684]
INFO  [px4] Creating symlink /cygdrive/c/PX4/home/Firmware/ROMFS/px4fmu_common -> /cygdrive/c/PX4/home/Firmware/build/px4_sitl_default/tmp/rootfs/etc
[New Thread 17016.0x40e4]
[New Thread 17016.0x2534]
[New Thread 17016.0x2950]
[New Thread 17016.0x79bc]
[New Thread 17016.0x28a4]
[New Thread 17016.0xa988]

______  __   __    ___
| ___ \ \ \ / /   /   |
| |_/ /  \ V /   / /| |
|  __/   /   \  / /_| |
| |     / /^\ \ \___  |
\_|     \/   \/     |_/

px4 starting.

INFO  [px4] Calling startup script: /bin/sh etc/init.d-posix/rcS 0
[New Thread 17016.0xb3d4]
[New Thread 17016.0x6938]
[Thread 17016.0x6938 exited with code 0]
[New Thread 17016.0x58cc]
[Thread 17016.0x58cc exited with code 0]
[New Thread 17016.0x7e9c]
[Thread 17016.0x7e9c exited with code 0]
[New Thread 17016.0x830c]

Thread 10 "lpwork" received signal SIGCONT, Continued.
[Switching to Thread 17016.0x28a4]
0x00000001005d101d in work_lpthread (argc=<optimized out>, argv=<optimized out>) at ../../src/platforms/common/work_queue/work_thread.c:296
296                     work_process(&g_work[LPWORK], LPWORK);
(gdb) info frame
Stack level 0, frame at 0xff82c7c8:
 rip = 0x1005d101d in work_lpthread (../../src/platforms/common/work_queue/work_thread.c:296); saved rip = 0x0
 called by frame at 0x0
 source language c.
 Arglist at 0xff82c790, args: argc=<optimized out>, argv=<optimized out>
 Locals at 0xff82c790, Previous frame's sp is 0xff82c7c8
 Saved registers:
  rbx at 0xff82c7b8, rip at 0xff82c7c0, xmm15 at 0xff82c7c0
(gdb) info frame
Stack level 0, frame at 0xff82c7c8:
 rip = 0x1005d101d in work_lpthread (../../src/platforms/common/work_queue/work_thread.c:296); saved rip = 0x0
 called by frame at 0x0
 source language c.
 Arglist at 0xff82c790, args: argc=<optimized out>, argv=<optimized out>
 Locals at 0xff82c790, Previous frame's sp is 0xff82c7c8
 Saved registers:
  rbx at 0xff82c7b8, rip at 0xff82c7c0, xmm15 at 0xff82c7c0
(gdb) where
#0  0x00000001005d101d in work_lpthread (argc=<optimized out>, argv=<optimized out>) at ../../src/platforms/common/work_queue/work_thread.c:296
#1  0x0000000000000000 in ?? ()
Backtrace stopped: previous frame inner to this frame (corrupt stack?)
(gdb) where
#0  0x00000001005d101d in work_lpthread (argc=<optimized out>, argv=<optimized out>) at ../../src/platforms/common/work_queue/work_thread.c:296
#1  0x0000000000000000 in ?? ()
Backtrace stopped: previous frame inner to this frame (corrupt stack?)
(gdb) where
#0  0x00000001005d101d in work_lpthread (argc=<optimized out>, argv=<optimized out>) at ../../src/platforms/common/work_queue/work_thread.c:296
#1  0x0000000000000000 in ?? ()
Backtrace stopped: previous frame inner to this frame (corrupt stack?)
(gdb) where
#0  0x00000001005d101d in work_lpthread (argc=<optimized out>, argv=<optimized out>) at ../../src/platforms/common/work_queue/work_thread.c:296
#1  0x0000000000000000 in ?? ()
Backtrace stopped: previous frame inner to this frame (corrupt stack?)
(gdb)

@hamishwillee hamishwillee reopened this Jan 15, 2019
@hamishwillee
Copy link

@MaEtUgR Thanks very much for that (and I have reopened while we discuss).

So that looks like working to me. I vote that you update the https://github.com/PX4/windows-toolchain/blob/master/toolchain/cygwin64/install-cygwin-px4.bat with the config and we update the docs to say this is working.

Then people can raise PRs to say it isn't working if they have a problem and we can debug - make sense?

If you update the build script and make a new release I can update the other docs (probably just a 2-liner to state the gdb debugging commands work)

@MaEtUgR
Copy link
Member

MaEtUgR commented Jan 16, 2019

It takes more time:

  • check if it really works, I didn't incorporate it into the IDE and I'm so far unfamiliar with gdb command line usage
  • add the debugger installation to the script
  • generate new installer that includes it
  • finally add it to the documentation

While a debugger could help with issues like PX4/PX4-Autopilot#11027 I think I'm fast by solving it printf style just now. That issue is right now really urgent for Windows use.

I want to enable debugger use but as I said it doesn't fit my short term planning right now. I'm sure I'll get to it.

@hamishwillee
Copy link

Not a problem. Let's just keep this open until you have time.

@MaEtUgR
Copy link
Member

MaEtUgR commented Sep 24, 2019

GDB got into the toolchain thanks to @oneWayOut pushing it 👍 Sorry it took so long.
To use gdb out of the box you can use the Cygwin Toolchain >v0.6 linked as fast AWS download in the dev guide soon. Context: PX4/PX4-Autopilot#13016 (comment)

It would be nice to have documentation about how and configuration shortcuts to use it e.g. together with an IDE like VS code also on Windows because I expect it to be a bit different.

@MaEtUgR MaEtUgR closed this as completed Sep 24, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

4 participants