Servers by jDrones

Run SITL in a debug mode

Hello - Is it possible to run the SITL in a debug mode? I would like to be able to set breakpoints in the autopilot code while I simulate a flight. I am currently executing the SITL via sim_vehicle.py which seems to be compiling and running the flight code, model, etc. Thanks!

@hanzichi You can pass the --debug arg when you invoke sim_vehicle.py, which will build SITL in debug mode. I can’t remember if there is a system call you can embed in SITL to break wherever you want, but I just waited for it to come up and then used gdb to attach to the ardu{plane/copter/…} process and continued. That worked pretty well for most things. There is a gui called gdbgui that tried a few days ago, but I haven’t used it much. There are other ones too.

Add

–gdb --debug

to the SITL commandline.

You can set breakpoints from the commandline with (e.g.)

-B Tracker::set_mode

To add on to this, you can configure the build to have debug symbols by adding --debug:
./waf configure --board sitl --debug

Then yeah you can simply add -D --gdb --breakpoint : when you launch SITL from sim_vehicle.py
-D (one dash in front) is for debug (same as --debug)
–gdb (two dashes in front) is for gdb and can be replaced with -G (one dash in front)
–breakpoint (two dashes in front) is used to set an initial breakpoint for SITL to hit. You will then be in gdb and can set more breakpoints after etc. (This is the way that worked best for me, but @sridharanNH 's way should work perfectly well)

Example of running SITL (it has been some time since I last tested this, but I believe this is right):
sim_vehicle.py -v ArduCopter --console --map -D --gdb --breakpoint mode_loiter:29

Here is a link to the dev documentation that will also help:
http://ardupilot.org/dev/docs/debugging-with-gdb-on-linux.html

Hope this helps!

EDIT To improve clarity of commands.

@peterbarker @vchadha Thank you. It’s good to know that you can specify --gdb and actually set breakpoints from the commandline while invoking SITL. Do these args work both when executing SITL directly via waf as well as through sim_vehicle.py?

I have only ever tired this through sim_vehicle.py
I didn’t realize you could also launch SITL through waf, isn’t that just the build tool?

I should definitely amend my previous point to make what I did clearer.

@vchadha Hi! I’m sorry, I meant to say directly, not through waf, like this:

$~/ArduPilot/build/sitl/bin/arduplane --model xplane

for ArduPlane. Thanks for catching the error!

I’m not sure you can actually execute SITL binaries via waf. You can
certainly specify --debug to waf to get a debug build, 'though.

Incidentally, these flags are also available on autotest.py - like
sim_vehicle.py but with a lot less typing required :wink:

Thanks all for these great explanations!

I’ll give it a try. Has anybody tried this on windows? I don’t have linux, so I’d have to get a VM going or dual boot.

I haven’t fully tested anything on windows, but you should be able to get it working.
You can use cygwin or the new linux subsystems windows supports and it should work (if you don’t want a VM or dual boot).
Personally, I have successfully used cygwin in the past to launch SITL on windows.

Here is a link to the documentation for setting up ardupilot and SITL on windows etc.
http://ardupilot.org/dev/docs/building-setup-windows.html#building-setup-windows
http://ardupilot.org/dev/docs/sitl-native-on-windows.html

Hope this helps!

Edit For clarity

I have configured gdb and running sim_vehicle as suggested above. I’m pretty sure it’s hitting a breakpoint because mavproxy loses connection. I followed the instructions for configuring vscode in the dev wiki, and seem to have set everything up correctly, but it complains. The exe is definitely there.

image

Thanks for the help! I’m a novice at this, and have not used gdb before, so hopefully this is something simple I’m missing. And note, I am running this on windows, executing sim from cygwin.

I am trying gdb directly to get any vscode issues out of the loop. Get a similar error. See below. Am I specifiying the directory incorrectly? Running from cygwin on windows 10.

me@mycomp ~/ardupilot
$ pwd
/home/me/ardupilot

me@mycomp ~/ardupilot
$ pidof arducopter
9296

me@mycomp ~/ardupilot
$ gdb /build/sitl/bin/ 9296
GNU gdb (GDB) (Cygwin 8.1.1-1) 8.1.1
Copyright © 2018 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”…
/build/sitl/bin/: No such file or directory.
Can’t attach to process.
/home/me/ardupilot/9296: No such file or directory.

I was running sim_vehicle with -G which I guess was already running gdb. So, I ran with just -D, and then in a separate cygwin console I can successfully attach:

$ gdb /build/sitl/bin 5890
GNU gdb (GDB) (Cygwin 8.1.1-1) 8.1.1
Copyright © 2018 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”…
/build/sitl/bin: No such file or directory.
Attaching to process 20512
[New Thread 20512.0x1ed8]
[New Thread 20512.0x577c]
[New Thread 20512.0x401c]
[New Thread 20512.0x2d90]
[New Thread 20512.0x4ae0]
[New Thread 20512.0x5684]
Reading symbols from /home/henrywon/ardupilot/build/sitl/bin/arducopter.exe…done.

I guess I can use this method, but was hoping to use vscode for convenience. But, when I try in vscode, it freezes up the vehicle (no link reported by mavproxy), but it is not stopped within vscode as far as I can tell.

So I switched to trying WSL since vscode has a help page on that, implying that it might work. Got it all set up and try to run the debugger (attach gdb), but get this error:

/usr/bin/pkexec “/usr/bin/gdb” --interpreter=mi --tty=${DbgTerm} 0<"/tmp/Microsoft-MIEngine-In-grev5zsm.tr7" 1>"/tmp/Microsoft-MIEngine-Out-s69t9063.3kb"

I tried looking in the /tmp directory, and they are not there. There are some vscode files there…

So I got home and tried it on my Zorin linux set up and it just works using the straight instructions from the ardupilot wiki. I’ll just abandon windows for now!

Hi,
iam trying to debug ardupilot code as mentioned in this documentation(ardupilot documentation)
Debugging with GDB on linux — Dev documentation
i ran a command as they mention in documentation for arduplane code
in console it was showing that it is waiting for connection after that what do i need to run? is there any program to run like client-server mechanism? i want to know about debugging of ardupilot(arduplane code)
can anyone help me to start debug the arduplane code in linux(ubuntu), if possible give me the inputs step by step please help me to come out of this problem.
Thanks…!

I was able to successfully debug from vscode in linux (Zorin) following the instructions on that page. I could not get it to work from a VM or in windows. I did not try the GDB command line option.

now i’m able to debug ardupilot code while running SITL in Linux(ubuntu 18.04 lts) using GDB,issue solved, everything mentioned in documentation need to follow it carefully

Servers by jDrones