配置launch.json
vscode的debug和前面的qtcreator实际上是一样的,vscode需要安装Native Debug工具,配置json文件,配置好之后vscode用起来一样方便。
首先,安装Native Debug插件:
安装好之后,如图所示,选择点击左侧的Run and Debug图标,然后点击"Run and Debug"-> “C++ GDB” -> “default configuration”,就会打开默认的launch.json
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "(gdb) Launch",
"type": "cppdbg",
"request": "launch",
"program": "enter program name, for example ${workspaceFolder}/a.out",
"args": [],
"stopAtEntry": false,
"cwd": "${workspaceFolder}",
"environment": [],
"externalConsole": false,
"MIMode": "gdb",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
]
}
]
}
修改json中的下面几项,即可以进入调试
program
"/home/hui/disk4t/codes/gstreamer/gst-open-source/gst-build-1.16.3/inst/bin/gst-launch-1.0"
args,格式为:["arg1", "arg2"]
,必须用空格的地方得用双引号隔开
"playbin","uri=http://192.168.31.122/hls/index.m3u8"
environment,格式为: {"name":"var2", "value": "var2_value"}
{"name":"GST_PLUGIN_SCANNER", "value":"/home/hui/disk4t/codes/gstreamer/gst-open-source/gst-build-1.16.3/inst/libexec/gstreamer-1.0/gst-plugin-scanner"}, {"name":"LD_LIBRARY_PATH", "value":"$LD_LIBRARY_PATH:/home/hui/disk4t/codes/gstreamer/gst-open-source/gst-build-1.16.3/inst/lib/x86_64-linux-gnu"}, {"name":"GST_PLUGIN_PATH", "value":"/home/hui/disk4t/codes/gstreamer/gst-open-source/gst-build-1.16.3/inst/lib/x86_64-linux-gnu/gstreamer-1.0"}
完整的launch文件如下:
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "(gdb) Launch",
"type": "cppdbg",
"request": "launch",
"program": "/home/hui/disk4t/codes/gstreamer/gst-open-source/gst-build-1.16.3/inst/bin/gst-launch-1.0",
// ["arg1", "arg2"]
"args": [
"playbin","uri=http://192.168.31.122/hls/index.m3u8"
],
"stopAtEntry": false,
// "cwd": "${workspaceFolder}",
"cwd": "/home/hui/disk4t/codes/gstreamer/gst-open-source/gst-build-1.16.3/subprojects",
// "cwd": "/home/hui/disk4t/codes/gstreamer/gst-open-source/gst-build-1.16.3/subprojects/gst-plugins-bad",
"environment": [
// {"name":"var2", "value": "var2_value"}
{"name":"GST_PLUGIN_SCANNER", "value":"/home/hui/disk4t/codes/gstreamer/gst-open-source/gst-build-1.16.3/inst/libexec/gstreamer-1.0/gst-plugin-scanner"},
{"name":"LD_LIBRARY_PATH", "value":"$LD_LIBRARY_PATH:/home/hui/disk4t/codes/gstreamer/gst-open-source/gst-build-1.16.3/inst/lib/x86_64-linux-gnu"},
{"name":"GST_PLUGIN_PATH", "value":"/home/hui/disk4t/codes/gstreamer/gst-open-source/gst-build-1.16.3/inst/lib/x86_64-linux-gnu/gstreamer-1.0"}
],
"externalConsole": false,
"MIMode": "gdb",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
]
}
]
}
高版本的配置,注意args部分的区别:
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "(gdb) Launch",
"type": "cppdbg",
"request": "launch",
"program": "/home/hui/disk4t/codes/gstreamer/gst-open-source/gstreamer-meson/inst/usr/local/bin/gst-launch-1.0",
"args": [
"filesrc", "location=/home/hui/disk4t/media-test/media-files/1.mp4", "!qtdemux!h264parse!avdec_h264!xvimagesink"
],
"stopAtEntry": false,
"cwd": "${fileDirname}",
"environment": [
{"name":"GST_PLUGIN_SCANNER", "value":"/home/hui/disk4t/codes/gstreamer/gst-open-source/gstreamer-meson/inst/usr/local/libexec/gstreamer-1.0/gst-plugin-scanner"},
{"name":"LD_LIBRARY_PATH", "value":"$LD_LIBRARY_PATH:/home/hui/disk4t/codes/gstreamer/gst-open-source/gstreamer-meson/inst/usr/local/lib/x86_64-linux-gnu"},
{"name":"GST_PLUGIN_PATH", "value":"/home/hui/disk4t/codes/gstreamer/gst-open-source/gstreamer-meson/inst/usr/local/lib/x86_64-linux-gnu/gstreamer-1.0"}
],
"externalConsole": false,
"MIMode": "gdb",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
},
{
"description": "Set Disassembly Flavor to Intel",
"text": "-gdb-set disassembly-flavor intel",
"ignoreFailures": true
}
]
}
]
}
播放audio的命令和args的对应写法对比
gst-launch-1.0 filesrc location=/home/hui/disk4t/media-test/media-files/debug/audio.data \
! qtdemux ! aacparse ! audio/mpeg,stream-format=adts ! avdec_aac_fixed ! audioconvert ! audioresample ! pulsesink
"program": "/home/hui/disk4t/codes/gstreamer/gst-open-source/gstreamer-meson/inst/usr/local/bin/gst-launch-1.0",
"args": [
"filesrc", "location=/home/hui/disk4t/media-test/media-files/debug/audio.data", "!qtdemux!aacparse!audio/mpeg,stream-format=adts!avdec_aac_fixed!audioconvert!audioresample!pulsesink"
],
F5进入DEBUG模式
设置断点,f5进入debug模式,左侧的callstack看起来很漂亮。如果没有断点成功,就需要检查下前面配置的json中参数,环境变量是否路径正确。
参考