Skip to content

Commit e593c7c

Browse files
authored
Fix in how lldb-mi integrates with the debugger detection logic (#1315)
* Tweak in the logic of detecting the CppTools lldb-mi debugger * Updated test expectations. One more fix regarding how lldb-mi integrates with the debugger detection logic. * Fix a mistake in the IF/ELSE changes * Improve readability in the debugger detection code
1 parent d1539be commit e593c7c

File tree

2 files changed

+41
-24
lines changed

2 files changed

+41
-24
lines changed

src/debugger.ts

Lines changed: 26 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -151,30 +151,35 @@ export async function getDebugConfigurationFromCache(cache: CMakeCache, target:
151151
}
152152

153153
if (!debuggerPathOverride) {
154-
const clang_compiler_regex = /(clang[\+]{0,2})+(?!-cl)/gi;
155154
// Look for a debugger, in the following order:
156-
const cpptoolsExtension = vscode.extensions.getExtension('ms-vscode.cpptools');
157-
const cpptoolsDebuggerPath = cpptoolsExtension ? path.join(cpptoolsExtension.extensionPath, "debugAdapters", "lldb-mi", "bin", "lldb-mi") : undefined;
158-
let clang_debugger_path = compiler_path.replace(clang_compiler_regex, 'lldb-mi');
159-
// 1. lldb-mi in the compiler path
160-
if ((clang_debugger_path.search(new RegExp('lldb-mi')) != -1) && await checkDebugger(clang_debugger_path)) {
161-
return createLLDBDebugConfiguration(clang_debugger_path, target);
162-
} else if (cpptoolsDebuggerPath && await checkDebugger(cpptoolsDebuggerPath)) {
163-
// 2. lldb-mi installed by CppTools
164-
return createLLDBDebugConfiguration(cpptoolsDebuggerPath, target);
165-
} else {
166-
// 3. gdb in the compiler path
167-
clang_debugger_path = compiler_path.replace(clang_compiler_regex, 'gdb');
168-
if ((clang_debugger_path.search(new RegExp('gdb')) != -1) && await checkDebugger(clang_debugger_path)) {
169-
return createGDBDebugConfiguration(clang_debugger_path, target);
170-
} else {
171-
// 4. lldb in the compiler path
172-
clang_debugger_path = compiler_path.replace(clang_compiler_regex, 'lldb');
173-
if ((clang_debugger_path.search(new RegExp('lldb')) != -1) && await checkDebugger(clang_debugger_path)) {
174-
return createLLDBDebugConfiguration(clang_debugger_path, target);
175-
}
155+
// 1. LLDB-MI
156+
const clang_compiler_regex = /(clang[\+]{0,2})+(?!-cl)/gi;
157+
let mi_debugger_path = compiler_path.replace(clang_compiler_regex, 'lldb-mi');
158+
if ((mi_debugger_path.search(new RegExp('lldb-mi')) != -1)) {
159+
const cpptoolsExtension = vscode.extensions.getExtension('ms-vscode.cpptools');
160+
const cpptoolsDebuggerPath = cpptoolsExtension ? path.join(cpptoolsExtension.extensionPath, "debugAdapters", "lldb-mi", "bin", "lldb-mi") : undefined;
161+
// 1a. lldb-mi in the compiler path
162+
if (await checkDebugger(mi_debugger_path)) {
163+
return createLLDBDebugConfiguration(mi_debugger_path, target);
164+
}
165+
166+
// 1b. lldb-mi installed by CppTools
167+
if (cpptoolsDebuggerPath && await checkDebugger(cpptoolsDebuggerPath)) {
168+
return createLLDBDebugConfiguration(cpptoolsDebuggerPath, target);
176169
}
177170
}
171+
172+
// 2. gdb in the compiler path
173+
mi_debugger_path = compiler_path.replace(clang_compiler_regex, 'gdb');
174+
if ((mi_debugger_path.search(new RegExp('gdb')) != -1) && await checkDebugger(mi_debugger_path)) {
175+
return createGDBDebugConfiguration(mi_debugger_path, target);
176+
}
177+
178+
// 3. lldb in the compiler path
179+
mi_debugger_path = compiler_path.replace(clang_compiler_regex, 'lldb');
180+
if ((mi_debugger_path.search(new RegExp('lldb')) != -1) && await checkDebugger(mi_debugger_path)) {
181+
return createLLDBDebugConfiguration(mi_debugger_path, target);
182+
}
178183
}
179184

180185
const debugger_name = platform == 'darwin' ? 'lldb' : 'gdb';

test/unit-tests/select-debugger.test.ts

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import * as chai from 'chai';
22
import * as chaiAsPromised from 'chai-as-promised';
33
import * as path from 'path';
4+
import * as vscode from 'vscode';
45

56
chai.use(chaiAsPromised);
67

@@ -37,13 +38,24 @@ suite('Select debugger', async () => {
3738
throw new Error();
3839
}
3940
expect(config.name).to.be.eq('Debug Test');
40-
expect(config['MIMode']).to.be.eq('gdb');
4141
expect(config.type).to.be.eq('cppdbg');
42-
expect(config['miDebuggerPath']).to.be.eq('gdb');
4342
expect(stub.called).to.be.true;
4443

44+
// If CppTools extension is installed, the lldb-mi installed with that extension
45+
// will represent the debugger fallback instead of gdb.
46+
const cpptoolsExtension = vscode.extensions.getExtension('ms-vscode.cpptools');
47+
const cpptoolsDebuggerPath = cpptoolsExtension ? path.join(cpptoolsExtension.extensionPath, "debugAdapters", "lldb-mi", "bin", "lldb-mi") : undefined;
48+
if (cpptoolsDebuggerPath) {
49+
expect(config['MIMode']).to.be.eq('lldb');
50+
expect(config['miDebuggerPath']).to.be.eq(cpptoolsDebuggerPath);
51+
expect(stub.calledWith('gdb')).to.be.false;
52+
} else {
53+
expect(config['MIMode']).to.be.eq('gdb');
54+
expect(config['miDebuggerPath']).to.be.eq('gdb');
55+
expect(stub.calledWith('gdb')).to.be.true;
56+
}
57+
4558
expect(stub.calledWith('lldb-mi')).to.be.true;
46-
expect(stub.calledWith('gdb')).to.be.true;
4759
});
4860

4961
test('Create debug config from cache - GCC', async () => {

0 commit comments

Comments
 (0)