Ask Your Question

VSCode debug cpp ROS node

asked 2019-01-22 08:00:31 -0500


I am trying to debug my cpp ROS node, based on the microepsilon_scancontrol (I am porting it to the latest driver). I can build with catkin, I can start it, but ofc not perfect (why would it..).

Therefor, I would like to debug it. I am using:

When I start debug I select ROS debugger and run my code with roslaunch (or rosrun, doesn't matter... same result). My node starts in the built-in console, but basically that's it, nothing more. Even if I add some brakepoints, doesn't matter, won't stop, keep running.

What am I missing? Also this automatic include generator doesn't seem to work. glibconfig.h is missing for some reason (I can build my code with catkin_make, so it has to be somewhere). And to be honest it is not really generating all of the includes, vscode offers me to add this and that, but when it comes to glibconfig.h it stops and ask me to add it manually.

Do you guys have some advice how to debug nodes in the given environment?


edit retag flag offensive close merge delete



run my code with roslaunch (or rosrun, doesn't matter... same result).

Do you mean you type roslaunch/rosrun in the built-in terminal?

Isha Dijcks gravatar image Isha Dijcks  ( 2019-01-22 08:34:09 -0500 )edit

ofc not. debug screen -> play button (or pressing F5), then I select ROS -> roslaunch (or rosrun) -> my package -> launch file. and then it starts a new console.

balint.tahi gravatar image balint.tahi  ( 2019-01-22 11:15:55 -0500 )edit

3 Answers

Sort by ยป oldest newest most voted

answered 2019-01-22 16:07:06 -0500

borgman_jeremy gravatar image

It literally says in the notes for that VS Code extension that breakpoints are not enabled when using Ros Launch or Ros Run.

If you are developing in C++ you can configure VS code to just use GDB:

I assume the same can be done for a python debugger but I have not done this.

edit flag offensive delete link more


Thanks, I was blind ... I have no problems debugging a python code, it is working just fine... but c++ with it tons of includes and catkin_make, then try again, not working, start over was a bit "hassle" for me, so I ended up porting the whole thing to Python... now it is working.

balint.tahi gravatar image balint.tahi  ( 2019-01-22 16:25:03 -0500 )edit

No problem....BTW if you want to use c++ there is nothing special about ROS with respect to VSCode and the GDB plugin. You can use debug it the same way you would any c++ program with GDB.

borgman_jeremy gravatar image borgman_jeremy  ( 2019-01-22 16:59:08 -0500 )edit

GDB is usable, but with workarounds.. You need to programmatically set your environment variables such as ROS_MASTER_URI, since GDB cannot detect them. Also, you have to attach your debugger to the executable file that is located under /devel/.private/<your_package>/lib/<your_package>/<your_node>.

tahsinkose gravatar image tahsinkose  ( 2019-01-24 01:40:31 -0500 )edit

answered 2019-02-11 16:23:16 -0500

sai krishna gravatar image

updated 2019-02-11 16:36:38 -0500

I had the same issue where my simple c++ code projects built with cmake works perfectly fine but not the same c++ file in catkin workspace which uses catkin_make. I had the executable run with out the errors but doesn't stop at my break points to debug my code. Later with the following changes in the launch.json and tasks.json, I could debug my executables(the ones I run using roslaunch or rosrun from terminal) in vscode effortlessly.

Please note to use the below fields correctly in respective json files as those commands are the ones that helps to pipe and enable the code with debugger in vscode and terminal.

*In launch.json--*

  1. "preLaunchTask": "prerun"
  2. "avoidWindowsConsoleRedirection": true
  3. "stopAtEntry": false

In tasks.json --

  1. in Prerun task a. "command": "source ./devel/setup.bash && export ROS_MASTER_URI=http://localhost:11311/ "
  2. In build task a. "command": "catkin config --extend /opt/ros/kinetic && catkin build -DCMAKE_BUILD_TYPE = Debug -j8"

The above changes would hopefully work for anyone struggling with a similar issue. The changes are considered to work assuming the ROS environment is setup with the required extensions and catkin_make is executed without any errors.

************** launch.json ***************

    // Use IntelliSense to learn about possible attributes.
    // Hover to view descriptions of existing attributes.
    // For more information, visit:
    "version": "0.2.0",
    "configurations": [
            "name": "(gdb) launch",
            "type": "cppdbg",
            "request": "launch",
            "program": "${workspaceFolder}/devel/lib/project_folder/executable_file",
            "args": [],
            "stopAtEntry": false,
            "cwd": "${workspaceFolder}",
            "environment": [],
            "externalConsole": false,
            "preLaunchTask": "prerun",
            "MIMode": "gdb",
            "targetArchitecture": "x64",
            "avoidWindowsConsoleRedirection": true,
            "setupCommands": [
                    "description": "Enable pretty-printing for gdb",
                    "text": "-enable-pretty-printing",
                    "ignoreFailures": true

***************** tasks.json ****************

        // See
        // for the documentation about the tasks.json format
        "version": "2.0.0",
        "tasks": [
                "label": "prerun",
                "type": "shell",
                "command": "source ./devel/setup.bash && export ROS_MASTER_URI=http://localhost:11311/ "
                "label": "build",
                "type": "shell",
                "command": "catkin config --extend /opt/ros/kinetic && catkin build -DCMAKE_BUILD_TYPE = Debug -j8",
                "group": {
                    "kind": "build",
                    "isDefault": true
                "problemMatcher": []
                "label": "clean",
                "type": "shell",
                "command": "catkin clean --yes"
                "label": "release",
                "type": "shell",
                "command": "sudo checkinstall --install=no catkin build -j4 --cmake--args -DCMAKE_BUILD_TYPE=Release"

edit flag offensive delete link more


Then I guess when can not use other atributes in ROSLAUNCH like param right?

onlytailei gravatar image onlytailei  ( 2019-12-20 01:26:48 -0500 )edit

Is the best answer, i make one gist based in your answer :

Diogo42 gravatar image Diogo42  ( 2020-11-30 13:22:21 -0500 )edit

answered 2020-07-09 20:25:09 -0500

stephanst gravatar image

I believe this is exactly what you're looking for.

I know this is a relatively old post, but I recently came across this page still feeling lost. I then found the above doc on the vscode-ros github, and it literally walks you through how to debug a node even when launching from a *.launch file. I do believe it is important to build your catkin workspace using the following line like it says in the notes.

$ catkin_make -DCMAKE_BUILD_TYPE=RelWithDebInfo
edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools



Asked: 2019-01-22 08:00:31 -0500

Seen: 8,076 times

Last updated: Feb 11 '19