1、Windows下的vscode可以遠(yuǎn)程連接linux
2、Linux環(huán)境已安裝g++、gdb
3、安裝gdbserver: sudo apt install gdbserver
|----------files
|------file1.h
|------file1.cc
|------file2.h
|------file2.cc
|----------tests
|------main.cc
|----------build
|----------bin (放置可執(zhí)行文件)
|----------CMakeList.txt
1、配置文件CMakeList.txt
cmake_minimum_required(VERSION 3.0)
project(files)
option(TEST "ON for complile test" ON)
set(CMAKE_VERBOSE_MAKEFILE ON)
set(CMAKE_CXX_FLAGS "$ENV{CXXFLAGS} -rdynamic -O0 -ggdb -std=c++17 -Wall -Wno-deprecated -Werror -Wno-unused-function")
set(LIB_SRC
file/file1.cc
file/file2.cc
) # (變量 文件名/路徑/...)
add_library(file SHARED ${LIB_SRC}) # (庫文件名稱 STATIC 文件)
add_executable(tests tests/main.cc) # (可執(zhí)行文件名稱 文件)
add_dependencies(tests file)
target_link_libraries(tests file) # (庫文件名稱/可執(zhí)行文件名稱 鏈接的庫文件名稱)
SET(EXECUTABLE_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/bin)
SET(LIBRARY_OUTPUT_PATH ${PROJECT_SOURCE_DIR}
launch.json
{// 使用 IntelliSense 了解相關(guān)屬性。
// 懸停以查看現(xiàn)有屬性的描述。
// 欲了解更多信息,請訪問: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{"name": "gcc - 生成和調(diào)試活動文件",
"type": "cppdbg",
"request": "launch",
"program": "${workspaceFolder}/bin/tests",
"args": [],
"stopAtEntry": true,
"cwd": "${workspaceFolder}",
"environment": [],
"externalConsole": false,
"linux": {"MIMode": "gdb",
"miDebuggerPath": "/usr/bin/gdb",
"miDebuggerServerAddress": "192.168.1.119:2334", //linux機(jī)器的IP地址,端口號和gdbserver的端口號一致
},
"logging": {"moduleLoad": false,
"engineLogging": false,
"trace": false
},
"setupCommands": [
{"description": "為 gdb 啟用整齊打印",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
]
}
]
}
task.json
{"version": "2.0.0",
"tasks": [
{"type": "cppbuild",
"label": "${workspaceFolder}/bin/tests",
"command": "/usr/bin/gbd",
"args": [
"-g",
"${workspaceRoot}/tests/main.cpp",
"-o",
"${workspaceFolder}/bin/tests" //可執(zhí)行文件路徑
],
"options": {"cwd": "${workspaceFolder}"
},
"problemMatcher": [
"$gcc"
],
"group": {"kind": "build",
"isDefault": true
},
"detail": "調(diào)試器生成的任務(wù)。"
}
]
}
2、編譯mkdir build
cd build/
cmake ..
cd ..
cd bin/
./test
vscode終端執(zhí)行命令:
sudo gdbserver localhost:2334 /home/test/sylar/build/tests args1 args2 ..
//端口號和launch.json中的端口號一致,若有參數(shù)則加入args處
3、設(shè)置斷點(diǎn)調(diào)試
你是否還在尋找穩(wěn)定的海外服務(wù)器提供商?創(chuàng)新互聯(lián)www.cdcxhl.cn海外機(jī)房具備T級流量清洗系統(tǒng)配攻擊溯源,準(zhǔn)確流量調(diào)度確保服務(wù)器高可用性,企業(yè)級服務(wù)器適合批量采購,新人活動首月15元起,快前往官網(wǎng)查看詳情吧