macOS平台使用vscode调试ffmpeg

准备知识:Debug C++ in Visual Studio Code

ffmpeg 源码 github.com/FFmpeg/FFmp…

调试ffmpeg_g, ffplay_g

ffmpeg 配置, 使其支持调试

关于-g3相关知识gcc-g-vs-g3-gdb-flag-what-is-the-difference

./configure  --disable-optimizations --disable-stripping --enable-debug=3 --disable-doc
make -j `nproc`
复制代码

image-20210422182014703.png

_g结尾的就是可以调试的程序ffmpeg_g, ffplay_g, ffprobe_g

vscode配置

image-20210422181630503.png

如下命令:

# macOS上列出所有的音视频设备
ffmpeg -f avfoundation -list_devices true -i ""
复制代码

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": "(lldb) Launch",
            "type": "cppdbg",
            "request": "launch",
            "program": "${workspaceFolder}/ffmpeg_g",
            "args": ["-f", "avfoundation", "-list_devices", "true", "-i", "\"\""],
            "stopAtEntry": false,
            "cwd": "${workspaceFolder}",
            "environment": [],
            "externalConsole": false,
            "MIMode": "lldb"
        }
    ]
}
复制代码

打上断点,点击运行,就可以愉快的调试了

附上链接:lldb 使用教程 Tutorial

调试ffmpeg/doc/example

make examples 
复制代码

在ffmpeg/doc/example目录下, 以_g结尾的就是可以调试的

配置launch.json

开始调试吧

备注:m1 芯片的mac 如果遇到调试问题

ERROR: Unable to start debugging. Unexpected LLDB output from command “-exec-run”. process exited with status -1 (attach failed ((os/kern) invalid argument)) 

解决办法:

使用 CodeLLDB debugger插件,而不是vc code 原生的调试插件

I would suggest you to use CodeLLDB debugger (vadimcn.vscode-lldb). It’s an extension in VSCode and works exactly like the native debugger in VSCode. For its setup, you just need to change the configuration of your launch.json file with the one provided by the extension. And that should do the trick.

Now if you would try to debug then, VSCode will make use of that extension and should be able to debug your programs as it was to be done by the native debugger.

I am personally using it on my M1 chip MacBook Air, and it works perfectly fine. According to me, It’s much easier to implement than other workarounds present at the moment.

© 版权声明
THE END
喜欢就支持一下吧
点赞0 分享