ROS 2 Application Remote Debugging

This section describes how to remotely debug ROS 2 applications on the Renesas R-Car V4H SH platform by using GDB.

It covers the required setup, the debugging workflow, and practical notes for running a remote debugging session from VS Code.

Note

Before proceeding, make sure you have completed the previous sections for cross-compilation, deployment, and VS Code workspace configuration.

Prerequisites

  1. Complete the Cross-compilation Environment Setup section.

    Make sure VS Code is configured with the required extensions and workspace settings for ROS 2 development, and that the application has been successfully deployed to the R-Car V4H SH platform.

  2. Make sure the required variables in settings.json are configured correctly, especially TARGET_IP.

  3. Ensure that all runtime dependencies required by the application are installed on the target device.

  4. Install gdbserver on the R-Car V4H SH platform if it is not already available:

    sudo apt-get update
    sudo apt-get install gdbserver
    

Debugging Workflow

  1. Before starting the debugging workflow, open settings.json and make sure the required variables are configured correctly for the mode you want to use.

    • For debugging with ros2 run, set:

      • TARGET_IP

      • NODE_PACKAGE_NAME

      • NODE_EXECUTABLE_NAME

    • For debugging with ros2 launch, set:

      • TARGET_IP

      • LAUNCH_PACKAGE_NAME

      • LAUNCH_FILE_NAME

      • NODE_PACKAGE_NAME

      • NODE_EXECUTABLE_NAME

  2. Open the Run and Debug view in VS Code:

    • Press Ctrl+Shift+D.

    • Select the appropriate debug configuration:

      • GDB for ROS2 Run to debug an application started with ros2 run

      • GDB for ROS2 Launch to debug an application started with ros2 launch

    • If prompted, enter any required runtime arguments, such as ROS 2 parameters.

  3. Press F5 (or click the green Start Debugging arrow) to begin the remote debugging session. Each debug configuration runs a pre-launch task automatically before the debugger attaches, and that task is what starts gdbserver on the board:

    • The GDB for ROS2 Run configuration runs the ROS2: Debug Run (GDB) task, which executes the following command on the target device:

      ros2 run --prefix 'gdbserver localhost:<debug_port>' <package_name> <executable_name>
      
    • The GDB for ROS2 Launch configuration runs the ROS2: Debug Launch (GDB) task, which executes the following command on the target device:

      ros2 launch --launch-prefix 'gdbserver localhost:<debug_port>' --launch-prefix-filter '<executable_name>' <launch_package_name> <launch_file_name>
      

Note

The current debug task already performs a debug build before starting the session. Therefore, you do not need to run the build step manually.