Use an IDE to debug px4 modules

Hi everyone!

I’m trying to debug a px4’s module (ekf2) in a simulated environment (jMAVsim).
Following the doc i found the command

make posix_sitl_default jmavsim___gdb

but this enable gdb from command line!
I want to use an IDE (in my case VScode), so i set up the launch config in the following way:

"configurations": [
        { 
            "name": "(gdb) Attach",
            "request": "attach",
            "program": "/home/dan/src/Firmware/build/posix_sitl_default/bin/px4",
            "processId": "8362",
            "MIMode": "gdb",
        },
        {
            "name": "(gdb) Launch",
            "request": "launch",
            "program": "/home/dan/src/Firmware/build/posix_sitl_default/bin/px4",
            "args": [
                "-t /home/dan/src/Firmware/test_data",
                "-s etc/init.d-posix/rcS",
                "/home/dan/src/Firmware/ROMFS/px4fmu_common"                
            ],
            "stopAtEntry": false,
            "cwd": "${workspaceFolder}",
            "environment": [],
            "externalConsole": false,
            "MIMode": "gdb",
        }
    ]

However when i run the debug in Launch mode, I get these errors at runtime:

px4 starting.

INFO  [Unknown] Calling startup script: bash etc/init.d/rcS 0
mount: only root can use "--types" option
etc/init.d/rcS: line 107: sercon: command not found
etc/init.d/rcS: line 112: ver: command not found
etc/init.d/rcS: line 119: uorb: command not found
etc/init.d/rcS: line 124: tone_alarm: command not found
mount: only root can use "--types" option
etc/init.d/rcS: line 146: tune_control: command not found
etc/init.d/rcS: line 147: mkfatfs: command not found
etc/init.d/rcS: line 163: ver: command not found
etc/init.d/rcS: line 166: [: ==: unary operator expected
sh: 0: can't access tty; job control turned off

It seems like the terminal emulator that VScode use for debug (xterm) doesn’t find the links to the modules: uorb should start the bin px4-uorb etc… so that I’m able to debug the px4 daemon but not his modules.
While when I’m running the debug in Attach mode (the processID in the config is the pid of the px4 daemon that make posix_sitl_default jmavsim spawn) I get the following exception:

Thread 4 "hpwork" received signal SIGCONT, Continued.
__pthread_kill (threadid=<optimized out>, signo=signo@entry=18) at ../sysdeps/unix/sysv/linux/pthread_kill.c:62
62	in ../sysdeps/unix/sysv/linux/pthread_kill.c

So, once and for all, how can i debug the px4 daemon and his modules using an IDE?
Thanks in advance!

1 Like