Vscode debugging gstreamer source code

1. Install vscode plugin

  • C/C++
  • C/C++ Extension

2. Configuration file modification

Each project in vscode has a set of configuration files, located in the .vscode directory, including:

  • tasks.json: related configuration for compilation
  • launch.json: related configuration of debug
  • c_cpp_properties.json: c/c++ program related configuration

2.1 Customize c_cpp_properties.json

{
    
    
    "configurations": [
        {
    
    
                "name": "Linux", # 配置标识符 linux, mac, win32
            "includePath": [
                    "${workspaceFolder}/**" #头文件搜索路径 
                    # **:表示递归搜索
            ],
            "defines": [],
                "compilerPath": "/usr/bin/gcc", # 编译器路径
            "cStandard": "gnu11",               # c语言的标准版本
            "cppStandard": "gnu++14",           # c++语言的标准版本
            "intelliSenseMode": "linux-gcc-x64"
        }
    ],
    "version": 4
}

2.2 Custom tasks.json file

{
    
    
    "tasks": [
        {
    
    
            "type": "shell",
            "label": "test",
            "command": "make",
            // "args": [
            //     "-fdiagnostics-color=always",
            //     "-g",
            //     "${file}",
            //     "-o",
            //     "${fileDirname}/${fileBasenameNoExtension}"
            // ],
            // "options": {
    
    
            //     "cwd": "${fileDirname}"
            // },
            // "problemMatcher": [
            //     "$gcc"
            // ],
            "group": {
    
    
                "kind": "build",
                "isDefault": true
            },
            "detail": "调试器生成的任务。"
        }
    ],
    "version": "2.0.0"
}

Other parameter meanings:

  • workspaceFolder: open vscode directory
  • workspaceFolderBasename: root directory of workspaceFolder
  • fileDirname: The directory where the current VsCode opens the file
  • fileBasenameNoExtension: each file in file does not have a suffix

2.3 Debug

{
    
    
    // 使用 IntelliSense 了解相关属性。 
    // 悬停以查看现有属性的描述。
    // 欲了解更多信息,请访问: https://go.microsoft.com/fwlink/?linkid=830387
    "version": "0.2.0",
    "configurations": [
        {
    
    
            "name": "test",
            "type": "cppdbg",
            // debug的模式,分为launch和attach两种
            "request": "launch",
            // 程序可执行文件的完整路径
            "program": "${workspaceFolder}/deepstream-test-rt-src-add-del", 
            // 传递给程序的命令行参数
            "args": ["file:///opt/nvidia/deepstream/deepstream-6.0/samples/streams/sample_720p.h264"],
            // 可选参数。如果为 true,则调试程序应在目标的入口点处停止
            "stopAtEntry": false,
            // 目标的工作目录
            "cwd": "${workspaceFolder}",
            // 要添加到程序环境的环境变量
            "environment": [],
            "externalConsole": false,
            // 指示 MIDebugEngine 要连接到的控制台调试程序。允许的值为 "gdb"、"lldb"。
            "MIMode": "gdb",
            
            "setupCommands": [
                {
    
    
                "description": "Enable pretty-printing for gdb",
                "text": "-enable-pretty-printing",
                "ignoreFailures": true
                }
            ],
            // 调试会话开始前要运行的任务
            "preLaunchTask": "test",
            // MI 调试程序(如 gdb)的路径。如果未指定,将首先在路径中搜索调试程序
            "miDebuggerPath": "/usr/bin/gdb"
        }
    ]
}

3. Under the Makefile environment

Use -g to start the debug environment

4. Python debugging

{
    
    
  // 使用 IntelliSense 了解相关属性。 
  // 悬停以查看现有属性的描述。
  // 欲了解更多信息,请访问: https://go.microsoft.com/fwlink/?linkid=830387
  "version": "0.2.0",
  "configurations": [
    {
    
    
      "name": "test",
      "type": "python",
      "request": "launch",
      "program": "${workspaceRoot}/tools/inference.py",
      "args": ["--config", "anomalib/models/padim/config.yaml", "--weight_path", "results/padim/mvtec/test7/weights/model.ckpt", 
        "--image_path", "datasets/MVTec/test7/train/good/", "--save_path", "results/padim/mvtec/test7/train_data"],
      "console": "integratedTerminal",
      "cwd":"${workspaceRoot}",
      "justMyCode": true
    }
  ]
}

5. Debug gstreamer source code

GStreamerIt is an open source multimedia framework (framework) for building streaming media applications , and its goal is to simplify the development of audio/video applications.

Download gstreamer source code

You can use gst-inspect1.0the tool to obtain the information gstreamerin element, as multifilesrc elementan example, enter the following command:

gst-inspect-1.0 multifilesrc

You can output the information in the figure below and find the source code download address.

insert image description here


Select the following version

insert image description here


Download the source code, unzip

insert image description here

Compile the source code

To compile the source code, please refer to the following article 【Compile gstreamer plugin-multifilesrc】

Modify Makefile

  1. search -goption information
    insert image description here

  2. Modify -O2the option-O0
    insert image description here

  3. Recompile to get the dynamic library

root@2a2466b40131:~/homework/gst_plugin_good/gst/multifile# make
CC       test_splitmux_part_reader-test-splitmuxpartreader.o
CC       test_splitmux_part_reader-gstsplitmuxpartreader.o
CC       test_splitmux_part_reader-gstsplitmuxsrc.o
CC       test_splitmux_part_reader-gstsplitutils.o
CC       test_splitmux_part_reader-patternspec.o
CCLD     test-splitmux-part-reader
CC       libgstmultifile_la-gstmultifilesink.lo
CC       libgstmultifile_la-gstmultifilesrc.lo
CC       libgstmultifile_la-gstmultifile.lo
CC       libgstmultifile_la-gstsplitfilesrc.lo
CC       libgstmultifile_la-gstsplitmuxsink.lo
CC       libgstmultifile_la-gstsplitmuxpartreader.lo
CC       libgstmultifile_la-gstsplitmuxsrc.lo
CC       libgstmultifile_la-gstsplitutils.lo
CC       libgstmultifile_la-patternspec.lo
CCLD     libgstmultifile.la
  1. Copy the dynamic library to the system path
make install 
cp /root/homework/gst_plugin_good/bin/lib/gstreamer-1.0/libgstmultifile.so /usr/lib/x86_64-linux-gnu/gstreamer-1.0/

Modify launch.jsonfile content

launch.jsonThe content of the file needs to modify the following three parameters:

insert image description here


The content of the entire launch.jsonfile is as follows, and the specific test is pipelineas follows:

gst-launch-1.0 multifilesrc location=test%d.jpg ! jpegparse ! jpegdec ! videoconvert ! jpegenc ! multifilesink location=output%d.jpg
{
    
    
  // 使用 IntelliSense 了解相关属性。 
  // 悬停以查看现有属性的描述。
  // 欲了解更多信息,请访问: https://go.microsoft.com/fwlink/?linkid=830387
  "version": "0.2.0",
  "configurations": [
    {
    
    
      "name": "test",
      "type": "cppdbg",
      // debug的模式,分为launch和attach两种
      "request": "launch",
      // 程序可执行文件的完整路径
      "program": "/usr/bin/gst-launch-1.0",
      // 传递给程序的命令行参数
      "args":["multifilesrc", "location=test%d.jpg", "!", "jpegparse", "!", "jpegdec", "!", "videoconvert", "!", "jpegenc", "!", "multifilesink", "location=output%d.jpg"],
      // 可选参数。如果为 true,则调试程序应在目标的入口点处停止
      "stopAtEntry": false,
      // 目标的工作目录
      "cwd": "${workspaceFolder}/data",
      // 要添加到程序环境的环境变量
      "environment": [],
      "externalConsole": false,
      // 指示 MIDebugEngine 要连接到的控制台调试程序。允许的值为 "gdb"、"lldb"。
      "MIMode": "gdb",

      "setupCommands": [
        {
    
    
          "description": "Enable pretty-printing for gdb",
          "text": "-enable-pretty-printing",
          "ignoreFailures": true
        }
      ],
      // 调试会话开始前要运行的任务
      // "preLaunchTask": "test",
      // MI 调试程序(如 gdb)的路径。如果未指定,将首先在路径中搜索调试程序
      "miDebuggerPath": "/usr/bin/gdb"
    }
  ]
}

Enter breakpoint

Put a breakpoint in the following gst_multi_file_src_set_locationfunction, press F5 to start debugging, and you can debug

insert image description here

Summarize

In this article, it mainly introduces how to use vscode to debug C++ and python programs, and further analyzes how to debug gstreamer source code, and describes the specific process of how to debug gstreamer source code.

Guess you like

Origin blog.csdn.net/hello_dear_you/article/details/128540033