Skip to content

How to use vscode for developing

Ahoy, the Fate Weaver edited this page Aug 10, 2023 · 12 revisions

如何使用vscode进行开发和调试

vscode插件

参考插件:

image

以下设置基于这些插件。

c/c++, cmake设置

参考.vscode/setting.json

{
    "cmake.cmakePath": "${workspaceFolder}/deps/3rd/usr/local/oceanbase/devtools/bin/cmake",
    "cmake.parallelJobs": 6,
    "cmake.generator": "Unix Makefiles",
    "cmake.buildDirectory": "${workspaceFolder}/build_debug",
    "cmake.configureArgs": [
        "-DCMAKE_BUILD_TYPE=Debug",
        "-DOB_USE_LLD=ON",
        "-DOB_BUILD_UNITTEST=ON"
    ],
    "C_Cpp.default.compilerPath": "${workspaceFolder}/deps/3rd/usr/local/oceanbase/devtools/bin/clang++",
    "C_Cpp.default.configurationProvider": "ms-vscode.cmake-tools",
    "cmake.debugConfig": {
        "MIMode": "gdb",
        "miDebuggerPath": "/usr/bin/gdb",
      }
}

Debug设置

参考.vscode/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": [
        // debug using vscode cmake tools.
        // choose debug target underneath.
        // debug target will be set automatically.
        {
            "name": "(gdb) Launch",
            "type": "cppdbg",
            "request": "launch",
            // Resolved by CMake Tools:
            "program": "${command:cmake.launchTargetPath}",
            "args": [],
            "stopAtEntry": false,
            // working dirctory resolved by CMake Tools.
            "cwd": "${command:cmake.getLaunchTargetDirectory}",
            // configure source file map manually to walk around debug files
            // not found bug in vscode.
            // Here shows an example for debugging source files in sql/parser
            "sourceFileMap":{
                "./build_debug/unittest/sql/parser/./unittest/sql/parser": {
                    "editorPath": "${workspaceFolder}/unittest/sql/parser"
                },
                "./build_debug/src/sql/parser/./src/sql/parser": {
                    "editorPath": "${workspaceFolder}/src/sql/parser"
                },
            },
            "environment": [
                {
                    // add the directory where our target was built to the PATHs
                    // it gets resolved by CMake Tools:
                    "name": "PATH",
                    "value": "${env:PATH}:${command:cmake.getLaunchTargetDirectory}"
                },
            ],
            "MIMode": "gdb",
            "setupCommands": [
                {
                    "description": "Enable pretty-printing for gdb",
                    "text": "-enable-pretty-printing",
                    "ignoreFailures": true
                }
            ]
        },
        // traditional debug configuration: set target manually.
        {
            "name": "(gdb) manual Launch",
            "type": "cppdbg",
            "request": "launch",
            "program": "${workspaceFolder}/build_debug/unittest/sql/parser/test_parser",
            "args": [],
            "stopAtEntry": false,
            "cwd": "${fileDirname}",
            "environment": [],
            "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
                }
            ]
        }

    ]
}

Cmake Tools的UI使用

image

  • 上方为功能区;
  • 下方为调试入口,右边选择target.

参考文档

Cmake Tools