forked from oceanbase/oceanbase
-
Notifications
You must be signed in to change notification settings - Fork 4
How to use vscode for developing
yangxinyu7427 edited this page Oct 20, 2023
·
12 revisions
参考插件:
以下设置基于这些插件。
参考.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",
}
}
参考.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
}
]
}
]
}
使用attach request
{
"version": "0.2.0",
"configurations": [
{
"name": "(gdb) Attach",
"type": "cppdbg",
"request": "attach",
"program": "/root/.obd/repository/oceanbase-ce/4.1.0.1/oceanbase-ce/bin/observer",
"processId": "${input:FindPID}",
"MIMode": "gdb",
"miDebuggerPath": "gdb",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
],
"sourceFileMap": {
"./build_debug/src/observer/./src/observer/omt": {
"editorPath": "${workspaceFolder}/src/observer/omt"
},
"./build_debug/src/sql/parser/./src/sql/parser": {
"editorPath": "${workspaceFolder}/src/sql/parser",
"useForBreakpoints": true
},
"./build_debug/src/sql/./src/sql": {
"editorPath": "${workspaceFolder}/src/sql",
"useForBreakpoints": true
},
"./build_debug/src/sql/engine/expr/./src/sql/engine/expr": {
"editorPath": "${workspaceFolder}/src/sql/engine/expr",
"useForBreakpoints": true
},
"./build_debug/src/storage/./src/storage": {
"editorPath": "${workspaceFolder}/src/storage",
"useForBreakpoints": true
},
"./build_debug/src/observer/./src/observer/mysql": {
"editorPath": "${workspaceFolder}/src/observer/mysql",
"useForBreakpoints": true
},
"./build_debug/deps/oblib/src/rpc/./deps/oblib/src/rpc/": {
"editorPath": "${workspaceFolder}/deps/oblib/src/rpc/",
"useForBreakpoints": true
},
"./build_debug/src/observer/./deps/oblib/src/lib/allocator/": {
"editorPath": "${workspaceFolder}/deps/oblib/src/lib/allocator",
"useForBreakpoints": true
},
"./build_debug/deps/oblib/src/lib/./deps/oblib/src/lib/": {
"editorPath": "${workspaceFolder}/deps/oblib/src/lib",
"useForBreakpoints": true
},
"./build_debug/src/storage/./src/sql/engine/basic": {
"editorPath": "${workspaceFolder}/src/sql/engine/basic",
"useForBreakpoints": true
}
}
}
],
"inputs": [
{
"id": "FindPID",
"type": "command",
"command": "shellCommand.execute",
"args": {
"command": "ps -aux | grep /bin/observer | grep -v grep | awk '{print $2}'",
"description": "Select your observer PID",
"useFirstResult": true,
}
}
]
}
如果想通过写Debug例程验证一些东西可以使用此方法:
- 在某个源码文件夹添加新的源码文件
- 在对应文件夹下Cmake文件中添加编译目标
- 上方为功能区;
- 下方为调试入口,右边选择target.
由于ob会在后台多线程执行一些随机的sql语句,所以如果直接使用普通的断点很难捕获到用户自己想要执行的sql语句,这里可以使用条件断点的方式对捕获的条件加以限制。具体步骤如下。
首先在连接ob数据库之后通过gdb attach的方式启动调试。

启动成功后可以在执行环境上下文变量中找到可以标识自己执行的sql的特殊变量,以此为基础添加条件变量,下面将以执行 show tables; 为例。
在src/sql/ob_sql.cpp的generate_stmt方法中添加条件断点,设置条件为 context.cur_sql_.data_length_==11

然后在obclient中执行sql show tables;即可捕获该sql,查看context.spm_ctx_.bl_key_.db_id_的值即为执行该sql的数据库id。

后续在调试时设置关于数据库id的断点即可捕获自己执行的sql语句。
