-
-
Notifications
You must be signed in to change notification settings - Fork 59
/
Copy pathdebugger.ts
168 lines (152 loc) · 5.7 KB
/
debugger.ts
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
'use strict';
// imports
import * as vscode from 'vscode';
import * as fs from 'fs';
import * as path from 'path';
import * as os from 'os';
import * as encoding from 'encoding';
import * as process from './process';
import { log } from './log';
import { config } from './config';
// the debugger class
export class Debugger implements vscode.Disposable {
// the diagnostic collection
private _diagnosticCollection: vscode.DiagnosticCollection;
// the constructor
constructor() {
}
// dispose
public dispose() {
}
// find gdb path
async findGdbPath() {
var gdbPath = null;
let findGdbScript = path.join(__dirname, `../../assets/find_gdb.lua`);
if (fs.existsSync(findGdbScript)) {
gdbPath = (await process.iorunv(config.executable, ["l", findGdbScript], {"COLORTERM": "nocolor"}, config.workingDirectory)).stdout.trim();
if (gdbPath) {
gdbPath = gdbPath.split('\n')[0].trim();
}
}
return gdbPath? gdbPath : "";
}
// startDebugging
async startDebugging(targetName?: string, targetProgram?: string, targetRunDir?: string, plat?: string) {
// no target program?
if (!targetProgram) {
return;
}
// no target name? get it from target program
if (!targetName) {
targetName = path.basename(targetProgram);
}
// get target arguments
let args = [];
if (targetName in config.debuggingTargetsArguments)
args = config.debuggingTargetsArguments[targetName];
else if ("default" in config.debuggingTargetsArguments)
args = config.debuggingTargetsArguments["default"];
// uses codelldb debugger?
var codelldb = false;
if (config.debugConfigType == "codelldb" || (os.platform() == "darwin" && vscode.extensions.getExtension("vadimcn.vscode-lldb"))) {
codelldb = true;
}
// get target run directory
if (!targetRunDir) {
targetRunDir = path.dirname(targetProgram);
}
// init debug configuration
var debugConfig: vscode.DebugConfiguration = null
if (codelldb) {
debugConfig = {
name: `launch: ${targetName}`,
type: 'lldb',
request: 'launch',
program: targetProgram,
args: args,
stopAtEntry: true,
cwd: targetRunDir,
environment: [],
externalConsole: false,
};
} else {
// uses cpptools debugger
if (os.platform() == "darwin") {
debugConfig = {
name: `launch: ${targetName}`,
type: 'cppdbg',
request: 'launch',
program: targetProgram,
args: args,
stopAtEntry: true,
cwd: targetRunDir,
environment: [],
externalConsole: true,
MIMode: "lldb",
miDebuggerPath: ""
};
} else if (os.platform() == "linux") {
debugConfig = {
name: `launch: ${targetName}`,
type: 'cppdbg',
request: 'launch',
program: targetProgram,
args: args,
stopAtEntry: true,
cwd: targetRunDir,
environment: [],
externalConsole: false, // @see https://github.com/xmake-io/xmake-vscode/issues/36
MIMode: "gdb",
miDebuggerPath: await this.findGdbPath(),
description: "Enable pretty-printing for gdb",
text: "-enable-pretty-printing",
ignoreFailures: true
};
} else if (os.platform() == "win32" && plat == "mingw") {
debugConfig = {
name: `launch: ${targetName}`,
type: 'cppdbg',
request: 'launch',
program: targetProgram,
args: args,
stopAtEntry: true,
cwd: targetRunDir,
environment: [],
externalConsole: false,
MIMode: "gdb",
miDebuggerPath: await this.findGdbPath(),
description: "Enable pretty-printing for gdb",
text: "-enable-pretty-printing",
ignoreFailures: true
};
} else if (os.platform() == "win32") {
debugConfig = {
name: `launch: ${targetName}`,
type: 'cppvsdbg',
request: 'launch',
program: targetProgram,
args: args,
stopAtEntry: true,
cwd: targetRunDir,
environment: [],
externalConsole: true,
MIMode: "gdb",
miDebuggerPath: "",
description: "Enable pretty-printing for gdb",
text: "-enable-pretty-printing",
ignoreFailures: true
};
}
}
var customcfg = config.customDebugConfig;
for (let key in customcfg) {
debugConfig[key] = customcfg[key];
}
// default type if not set yet
debugConfig.type = debugConfig.type || 'cppdbg';
// start debugging
if (debugConfig) {
await vscode.debug.startDebugging(vscode.workspace.workspaceFolders[0], debugConfig);
}
}
}