如需转载请标明出处:http://blog.csdn.net/itas109
QQ技术交流群:129518033
环境:
OS:centos 7.9.2009 Minimal(无界面版本)
cmake: 2.8.12
编译器:g++ 4.8.5
调试器:gdb 4.8.5
code-server: v4.0.2(vscode v1.63.0)
code-server插件:
ms-vscode.cpptools-1.9.0@linux-x64.vsix
twxs.cmake-0.0.17.vsix
ms-vscode.cmake-tools-1.9.2.vsix
linux下使用gdb调试程序是一个基本操作。
本文介绍使用code-server + gdb离线远程web浏览器调试C++的cmake工程。
最终效果:可以在没有GUI界面的centos上,在windows/linux等上以浏览器的方式调试centos上的C++程序。
wget https://github.com/coder/code-server/releases/download/v4.0.2/code-server-4.0.2-amd64.rpm
镜像加速
wget https://ghproxy.com/https://github.com/coder/code-server/releases/download/v4.0.2/code-server-4.0.2-amd64.rpm
安装
sudo yum -ivh code-server-4.0.2-amd64.rpm
目录结构:
$ tree
.
+--- .vscode
| +--- launch.json
+--- CMakeLists.txt
+--- myprint.cpp
+--- myprint.h
+--- test.cpp
test.cpp
#include "myprint.h"
int main()
{
int num = 1;
myprintf(num);
return 0;
}
myprint.h
void myprintf(int num);
myprint.cpp
#include <iostream>
void myprintf(int num)
{
std::cout << "num: " << num << std::endl;
}
CMakeLists.txt
cmake_minimum_required(VERSION 2.8.12)
project(test)
include_directories(.)
add_executable(${PROJECT_NAME} test.cpp myprint.cpp)
注意:必须生成Debug模式,否则无法调试
mkdir build
cd build
cmake .. -DCMAKE_BUILD_TYPE=Debug
cmake --build . --config Debug
建议使用CMake Tools进行编译。
注意:离线下需要同时下载CMake和CMake Tools
$ code-server --install-extension twxs.cmake-0.0.17.vsix
Installing extensions...
Extension 'twxs.cmake-0.0.17.vsix' was successfully installed.
$ code-server --install-extension ms-vscode.cmake-tools-1.9.2.vsix
Installing extensions...
Extension 'ms-vscode.cmake-tools-1.9.2.vsix' was successfully installed.
linux下验证应用程序是否为debug版本:
readelf -S test | grep debug
默认使用配置文件:~/.config/code-server/config.yaml
code-server
设置密码
export PASSWORD="123456" && code-server --bind-addr 0.0.0.0:8080
不设置密码
code-server --auth=none --bind-addr 0.0.0.0:8080
浏览器中输入http://IP:8080
即可访问
安装C++调试插件 C/C++ extension for VS Code
$ code-server --install-extension ms-vscode.cpptools-1.9.0@linux-x64.vsix
Installing extensions...
Extension 'ms-vscode.cpptools-1.9.0@linux-x64.vsix' was successfully installed.
安装cmake插件 CMake Tools
注意:离线下需要同时下载CMake和CMake Tools
【Run(Ctrl + Shift + D)】-> 【create a launch.json file】-> 【C++ (GDB/LLDB)】
launch.json
{
"version": "0.2.0",
"configurations": [
{
"name": "(gdb) 启动",
"type": "cppdbg",
"request": "launch",
"program": "${workspaceFolder}/build/test",
"args": [],
"stopAtEntry": false,
"cwd": "${workspaceFolder}",
"environment": [],
"externalConsole": false,
"MIMode": "gdb",
"setupCommands": [
{
"description": "为 gdb 启用整齐打印",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
]
}
]
}
设置断点,在code-server中按F5进行调试。
code-server左侧有变量、监视、调用堆栈、断点和Modules信息。
License
License under CC BY-NC-ND 4.0: 署名-非商业使用-禁止演绎
如需转载请标明出处:http://blog.csdn.net/itas109
QQ技术交流群:129518033
Reference:
NULL