VSCode debug配置对比

Huan Lee Lv5
text
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# 测试c++代码
#include <iostream>
#include <string>
#include <vector>
using namespace std;

string longestCommonPrefix(vector<string> &strs) {
int maxLen = 0, strNum = strs.size();
for (int l = 0; l < strs[0].length(); l++) {
char c = strs[0][l]; // 断点设置位置;
for (int i = 1; i < strNum; i++) {
if (strs[i].length() < l || strs[i][l] != c)
return strs[0].substr(0, maxLen);
}
maxLen++;
}
return strs[0];
}

int main() {
vector<string> strs = {"flower", "flow", "flight"};
string output = longestCommonPrefix(strs);
cout << output << endl;
}
text
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# launch.json
{
// 欲了解更多信息,请访问: https://code.visualstudio.com/docs/cpp/launch-json-reference
"version": "0.2.0",
"configurations": [
{
"name": "clang + codelldb", // 对容器的支持弱于gdb
"type": "lldb",
"request": "launch",
"program": "${workspaceRoot}/main",
"args": [],
"cwd": "${workspaceRoot}",
"preLaunchTask": "clang++ build"
},
{
"name": "clang + cppdbg", // 混搭gdb和clang效果不好; 还是应该统一使用gnu或llvm
"type": "cppdbg",
"request": "launch",
"program": "${workspaceRoot}/main",
"args": [],
"stopAtEntry": false,
"cwd": "${workspaceRoot}",
"environment": [],
"externalConsole": false,
"linux": {
"MIMode": "gdb",
"miDebuggerPath": "/usr/bin/gdb"
},
"osx": {
"MIMode": "lldb"
},
"preLaunchTask": "clang++ build"
},
{
"name": "gcc + cppdbg", // gcc + gdb 效果最好
"type": "cppdbg",
"request": "launch",
"program": "${workspaceRoot}/main",
"args": [],
"stopAtEntry": false,
"cwd": "${workspaceRoot}",
"environment": [],
"externalConsole": false,
"linux": {
"MIMode": "gdb",
"miDebuggerPath": "/usr/bin/gdb"
},
"osx": {
"MIMode": "lldb"
},
"setupCommands": [
{
"description": "为 gdb 启用整齐打印",
"text": "-enable-pretty-printing",
"ignoreFailures": false
}
],
"preLaunchTask": "g++ build"
}
]
}

codelldb

对容器的支持有待提高

Untitled

gcc+gdb

设置的断点位置异常可能导致调试出错, 当然普通的变量监控是没问题的. 但是在监控中调用方法就可能出错.

Untitled

Untitled

Untitled

clang + gdb

显然, 混用gnu和llvm的配置并不好. 其实还有一种lldb+gcc, 这种我甚至运行不起来..

Untitled

  • 如果只是简单的监控变量, llvm和gnu系列的体验都不错, 都能够看到容器内的变量;

  • 但是在watch中调用方法的体验, 都有各自的问题, 硬要说的话, 可能gnu的搭配还是要好一些.

    • 结论, 最好不要在watch中调用方法!
  • Title: VSCode debug配置对比
  • Author: Huan Lee
  • Created at : 2023-05-28 16:16:29
  • Updated at : 2024-02-26 04:53:15
  • Link: https://www.mirthfullee.com/2023/05/28/VSCode debug配置对比/
  • License: This work is licensed under CC BY-NC-SA 4.0.
On this page
VSCode debug配置对比