How to Debug gst-launch pipeline under VScode

Sure, here is the revised guide with the additional instruction to compile relevant code in debug mode:


Hi all,

The best method for debugging GStreamer elements (and hailofilter post-processes) is to launch gst-launch-1.0 under the control of the debugger from the start. Here’s how you can do it using gdb and VSCode:

  1. Open Your Project in VSCode:

    • Open the folder containing your GStreamer plugin source code in VSCode.
  2. Install Necessary Tools:

    • Ensure you have VSCode and the C/C++ extension installed.
    • Ensure you have GStreamer development files and tools installed on your system.
    • Make sure you have gdb (GNU Debugger) installed.
  3. Compile Relevant Code in Debug Mode:

    • Ensure that you compile your GStreamer plugin and any other relevant code in debug mode. This usually means using the -g flag in your CFLAGS. For example, if you are using gcc:

      gcc -g -o myplugin myplugin.c `pkg-config --cflags --libs gstreamer-1.0`
      
  4. Configure the Debugger:

    • Create a launch.json file in the .vscode directory of your project folder if it does not already exist. You can do this by clicking on the debug icon on the left sidebar, then clicking on the gear icon and selecting “Add Configuration…”.
    • Add a configuration to launch gst-launch-1.0 under gdb control:
    {
        "version": "0.2.0",
        "configurations": [
            {
                "name": "Launch gst-launch",
                "type": "cppdbg",
                "request": "launch",
                "program": "/usr/bin/gst-launch-1.0",
                "args": ["videotestsrc", "!", "autovideosink"],  // Adjust this to your pipeline
                "stopAtEntry": true,
                "cwd": "${workspaceFolder}",
                "environment": [],
                "externalConsole": false,
                "MIMode": "gdb",
                "setupCommands": [
                    {
                        "description": "Enable pretty-printing for gdb",
                        "text": "-enable-pretty-printing",
                        "ignoreFailures": true
                    }
                ],
                "miDebuggerPath": "/usr/bin/gdb",
                "logging": {
                    "engineLogging": true
                }
            }
        ]
    }
    
  5. Set Breakpoints:

    • Open your GStreamer plugin source file in VSCode.
    • Set breakpoints by clicking in the gutter to the left of the line numbers.
  6. Start Debugging:

    • Go to the debug panel and select the “Launch gst-launch” configuration.
    • Start debugging by pressing F5.

This setup will start gst-launch-1.0 under gdb control from the very beginning. The debugger will stop at the entry point of the program, allowing you to step through the code right from the start and catch any early crashes.

If the gst-launch-1.0 binary is not in /usr/bin, adjust the program path in the launch.json accordingly. If your pipeline is different, update the args array with the correct elements.

Hope you find this topic useful :smile:

2 Likes