远程调试MySQL内核
1 vscode 需要安装remote-ssh插件
安装成功后,登录:
默认远程服务器的登录
ssh root@ip
注意,Linux需要设置root远程登录;
2 安装debug扩展
C\C++ extemsion Pack
C\C++
3 设置Attach进程
{// 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) Pipe Attach","type": "cppdbg","request": "attach","program": "enter program name, for example ${workspaceFolder}/a.out","processId": "${command:pickRemoteProcess}","pipeTransport": {"debuggerPath": "/usr/bin/gdb","pipeProgram": "/usr/bin/ssh","pipeArgs": [],"pipeCwd": ""},"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}]}]
}
这里
"processId": "${command:pickRemoteProcess}",
填写mysql的进程ID;
# lsof -i:3306
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
mysqld 199182 mysql 17u IPv6 1323770 0t0 TCP *:mysql (LISTEN)
#
样例
{// 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) Pipe Attach","type": "cppdbg","request": "attach","program": "enter program name, for example ${workspaceFolder}/a.out","processId": "199182","pipeTransport": {"debuggerPath": "/usr/bin/gdb","pipeProgram": "/usr/bin/ssh","pipeArgs": [],"pipeCwd": ""},"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}]}]
}
4 断点
sql_parse.cc文件
函数:
int mysql_execute_command(THD *thd, bool first_level = false);
(备注,mysql必须是debug版本)