Skip to content

Commit

Permalink
check for configured debugger before start to provide a nicer error m…
Browse files Browse the repository at this point in the history
…essage
  • Loading branch information
GitMensch committed Feb 7, 2024
1 parent 9fb2875 commit d559072
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 10 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,13 @@ Versioning].
[keep a changelog]: https://keepachangelog.com/en/1.0.0
[semantic versioning]: https://semver.org/spec/v2.0.0.html

## Unreleased

### Added

- check for configured debugger before start to provide a nicer error message
([@GitMensch])

## [0.27.0] - 2024-02-07

### Added
Expand Down
14 changes: 12 additions & 2 deletions src/gdb.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,12 @@ class GDBDebugSession extends MI2DebugSession {
}

protected launchRequest(response: DebugProtocol.LaunchResponse, args: LaunchRequestArguments): void {
this.miDebugger = new MI2(args.gdbpath || "gdb", ["-q", "--interpreter=mi2"], args.debugger_args, args.env);
const dbgCommand = args.gdbpath || "gdb";
if (this.checkCommand(dbgCommand)) {
this.sendErrorResponse(response, 104, `Configured debugger ${dbgCommand} not found.`);
return;
}
this.miDebugger = new MI2(dbgCommand, ["-q", "--interpreter=mi2"], args.debugger_args, args.env);
this.setPathSubstitutions(args.pathSubstitutions);
this.initDebugger();
this.quit = false;
Expand Down Expand Up @@ -94,7 +99,12 @@ class GDBDebugSession extends MI2DebugSession {
}

protected attachRequest(response: DebugProtocol.AttachResponse, args: AttachRequestArguments): void {
this.miDebugger = new MI2(args.gdbpath || "gdb", ["-q", "--interpreter=mi2"], args.debugger_args, args.env);
const dbgCommand = args.gdbpath || "gdb";
if (this.checkCommand(dbgCommand)) {
this.sendErrorResponse(response, 104, `Configured debugger ${dbgCommand} not found.`);
return;
}
this.miDebugger = new MI2(dbgCommand, ["-q", "--interpreter=mi2"], args.debugger_args, args.env);
this.setPathSubstitutions(args.pathSubstitutions);
this.initDebugger();
this.quit = false;
Expand Down
14 changes: 12 additions & 2 deletions src/lldb.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,12 @@ class LLDBDebugSession extends MI2DebugSession {
}

protected launchRequest(response: DebugProtocol.LaunchResponse, args: LaunchRequestArguments): void {
this.miDebugger = new MI2_LLDB(args.lldbmipath || "lldb-mi", [], args.debugger_args, args.env);
const dbgCommand = args.lldbmipath || "lldb-mi";
if (this.checkCommand(dbgCommand)) {
this.sendErrorResponse(response, 104, `Configured debugger ${dbgCommand} not found.`);
return;
}
this.miDebugger = new MI2_LLDB(dbgCommand, [], args.debugger_args, args.env);
this.setPathSubstitutions(args.pathSubstitutions);
this.initDebugger();
this.quit = false;
Expand Down Expand Up @@ -89,7 +94,12 @@ class LLDBDebugSession extends MI2DebugSession {
}

protected attachRequest(response: DebugProtocol.AttachResponse, args: AttachRequestArguments): void {
this.miDebugger = new MI2_LLDB(args.lldbmipath || "lldb-mi", [], args.debugger_args, args.env);
const dbgCommand = args.lldbmipath || "lldb-mi";
if (this.checkCommand(dbgCommand)) {
this.sendErrorResponse(response, 104, `Configured debugger ${dbgCommand} not found.`);
return;
}
this.miDebugger = new MI2_LLDB(dbgCommand, [], args.debugger_args, args.env);
this.setPathSubstitutions(args.pathSubstitutions);
this.initDebugger();
this.quit = false;
Expand Down
14 changes: 12 additions & 2 deletions src/mago.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,12 @@ class MagoDebugSession extends MI2DebugSession {
}

protected launchRequest(response: DebugProtocol.LaunchResponse, args: LaunchRequestArguments): void {
this.miDebugger = new MI2_Mago(args.magomipath || "mago-mi", ["-q"], args.debugger_args, args.env);
const dbgCommand = args.magomipath || "mago-mi";
if (this.checkCommand(dbgCommand)) {
this.sendErrorResponse(response, 104, `Configured debugger ${dbgCommand} not found.`);
return;
}
this.miDebugger = new MI2_Mago(dbgCommand, ["-q"], args.debugger_args, args.env);
this.initDebugger();
this.quit = false;
this.attached = false;
Expand All @@ -69,7 +74,12 @@ class MagoDebugSession extends MI2DebugSession {
}

protected attachRequest(response: DebugProtocol.AttachResponse, args: AttachRequestArguments): void {
this.miDebugger = new MI2_Mago(args.magomipath || "mago-mi", [], args.debugger_args, args.env);
const dbgCommand = args.magomipath || "mago-mi";
if (this.checkCommand(dbgCommand)) {
this.sendErrorResponse(response, 104, `Configured debugger ${dbgCommand} not found.`);
return;
}
this.miDebugger = new MI2_Mago(dbgCommand, ["-q"], args.debugger_args, args.env);
this.initDebugger();
this.quit = false;
this.attached = true;
Expand Down
20 changes: 16 additions & 4 deletions src/mibase.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { Breakpoint, IBackend, Variable, VariableObject, ValuesFormattingMode, M
import { MINode } from './backend/mi_parse';
import { expandValue, isExpandable } from './backend/gdb_expansion';
import { MI2 } from './backend/mi2/mi2';
import { execSync } from 'child_process';
import * as systemPath from "path";
import * as net from "net";
import * as os from "os";
Expand All @@ -17,10 +18,10 @@ class ExtendedVariable {
}

class VariableScope {
constructor (public readonly name: string, public readonly threadId: number, public readonly level: number) {
constructor(public readonly name: string, public readonly threadId: number, public readonly level: number) {
}

public static variableName (handle: number, name: string): string {
public static variableName(handle: number, name: string): string {
return `var_${handle}_${name}`;
}
}
Expand Down Expand Up @@ -92,6 +93,17 @@ export class MI2DebugSession extends DebugSession {
}
}

// verifies that the specified command can be executed
protected checkCommand(debuggerName: string): boolean {
try {
const command = process.platform === 'win32' ? 'where' : 'command -v';
execSync(`${command} ${scriptName}`, { stdio: 'ignore' });
return true;
} catch (error) {
return false;
}
}

protected setValuesFormattingMode(mode: ValuesFormattingMode) {
switch (mode) {
case "disabled":
Expand Down Expand Up @@ -728,7 +740,7 @@ export class MI2DebugSession extends DebugSession {
id: 1,
label: args.source.name,
column: args.column,
line : args.line
line: args.line
}]
};
this.sendResponse(response);
Expand All @@ -743,7 +755,7 @@ export class MI2DebugSession extends DebugSession {

protected setSourceFileMap(configMap: { [index: string]: string }, fallbackGDB: string, fallbackIDE: string): void {
if (configMap === undefined) {
this.sourceFileMap = new SourceFileMap({[fallbackGDB]: fallbackIDE});
this.sourceFileMap = new SourceFileMap({ [fallbackGDB]: fallbackIDE });
} else {
this.sourceFileMap = new SourceFileMap(configMap, fallbackGDB);
}
Expand Down

0 comments on commit d559072

Please sign in to comment.