美文网首页
VSCode下使用CMake调试问题记录

VSCode下使用CMake调试问题记录

作者: ClaireYuan_e78c | 来源:发表于2019-04-30 18:32 被阅读0次

    问题背景

    第一步: 安装cmake tool插件,其主要作用是使用cmake工具链进行工程的跨平台构建。

    第二步:在各目录下加入CMakeLists.txt,用cmake命令编译,提示选择kit,因是在mac下code,kit选择clang。

    第三步:状态栏选择debug,提示找不到MI

    解决方法

    vscode下有两种方式进行debug,一种是quick debug,不需要launch.json;一种是使用launch.json。在状态栏单击dubug灰虫子使用的是前一种方式,那mi是什么?

    直接debug

    MI是机器接口驱动,cmake只是调用平台的编译器和链接器,最终的执行或debug还是要调用lldb-mi去执行。debug信息在编译链接生成的机器码中。

    关于lldb-mi的描述:
    The Machine Interface Driver (MI Driver) is a stand alone executable
    that either be used via a client i.e. Eclipse or directly from the command
    line. It processes MI commands, actions those commands using the internal
    debugger then forms MI response formatted text which is returned to the
    client.MI是

    知道了mi的定义就好解决了,修改vscode的设置属性,告诉vscode在使用cmake工具链debug时去哪里找mi。在setting.json文件增加:

    {
        "cmake.debugConfig": {
            "stopAtEntry": false,
            "MIMode": "lldb",
            "miDebuggerPath": "/Users/usersname/.vscode/extensions/ms-vscode.cpptools-0.22.1/debugAdapters/lldb/bin/lldb-mi"
        }
    

    这时,用状态栏的debugger调试可以work。

    使用launch.json进行Debug

    在vs-code下,如果不使用cmake工具链需要编辑launch和task两个文件,launch包括可执行文件的路径和名称,命令行参数等,task包括编译命令行。debug时用F5会进行断点调试,调用的就是launch文件。

    使用cmake时用到的launch文件:

    {
        "version": "0.2.0",
        "configurations": [
            {
                "name": "(lldb) Launch",
                "type": "cppdbg",
                "request": "launch",
                "program": "${workspaceFolder}/build/CMakeBuildProject",
                "args": [
                    "hello",
                    "you"
                ],
                "stopAtEntry": false,
                "cwd": "${workspaceFolder}",
                "environment": [],
                "MIMode": "lldb",
                "setupCommands": [
                    {
                        "description": "Enable pretty-printing for lldb",
                        "text": "-enable-pretty-printing",
                        "ignoreFailures": true
                    }
                ]
            }
        ]
    }
    

    小结

    vs-code官网.
    cmake-tool官网.
    Microsoft的cpp-tool官网.

    相关文章

      网友评论

          本文标题:VSCode下使用CMake调试问题记录

          本文链接:https://www.haomeiwen.com/subject/qcnmnqtx.html