前提:已经在服务器上编译安装好mysql5.7.37源码了,这里只是记录一下使用vscode远程连接服务器时如何成功debug,这篇与我发布的关于openGauss源码部署有双向链接关系,后续可方便查看。
1. 远程连接服务器进入连接界面
2. 设置Cmake参数
方法有三,我是第一种方法成功。
法一:
- 打开settings.json
- 写入以下内容
{
"cmake.sourceDirectory": "/usr/local/mysql/cmake-3.20.2/Auxiliary",
"cmake.buildBeforeRun": true,
"cmake.buildDirectory": "${workspaceFolder}/cmake-build-debug/build",
"cmake.configureSettings": {
"WITH_DEBUG": "1",
"CMAKE_INSTALL_PREFIX": "${workspaceFolder}/cmake-build-debug",
"MYSQL_DATADIR": "${workspaceFolder}/cmake-build-debug/data",
"SYSCONFDIR": "${workspaceFolder}/cmake-build-debug/etc",
"MYSQL_TCP_PORT": "3307",
"MYSQL_UNIX_ADDR": "${workspaceFolder}/cmake-build-debug/data/mysql-debug.sock",
"WITH_BOOST": "/usr/local/mysql/mysql-5.7.37/boost/boost_1_59_0/",
"DOWNLOAD_BOOST": "1",
"DOWNLOAD_BOOST_TIMEOUT": "600"
}
}
3. 编辑launch.json
这里注意miDebuggerPath位置一定要正确,我当时报错原因是我的服务器没有安装gdb,所以显示路径不正确。
{
"version": "0.2.0",
"configurations": [
{
"name": "MySQL-debug",
"type": "cppdbg",
"request": "launch",
"program": "/usr/local/mysql/bin/mysqld",
"args": ["--user=mysql --datadir=/usr/local/mysql/data"],
"stopAtEntry": true,
"environment": [],
"externalConsole": false,
"MIMode": "gdb",
"miDebuggerPath": "gdb",
"miDebuggerArgs": "gdb",
"linux": {
"MIMode": "gdb",
"miDebuggerPath": "/usr/bin/gdb"
},
"logging": {
"moduleLoad": false,
"engineLogging": false,
"trace": false
},
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
],
"cwd": "${workspaceFolder}",
}
]
}
yum install gdb
rpm -ql gdb
- 点击debug就成功了
成功界面如第一张图所示。
法二
File → Preferences → Settings → 'cmake:Configure' → 【Cmake:Configure Args】-DWITH_BOOST=/usr/local/mysql/mysql-5.7.37/boost/boost_1_59_0/
-DDOWNLOAD_BOOST=1
法三
按下Ctrl + ,,选择workspace,在左侧选择extension,再选中Cmake,找到Configuration Args,添加以下参数:
-DDOWNLOAD_BOOST=1
-DWITH_BOOST=/usr/local/mysql/mysql-5.7.37/boost/boost_1_59_0/
这里注意一下,我是一开始就预先在自己的虚拟机上编译完成了一遍,所以这里即使再编译一次也是很快完成,所以这篇博客的目的重在已经预先在自己的虚拟机上成功编译安装好源码后,如何通过vscode远程连接服务器来进行debug操作的(毕竟vscode方便看源码噻~)