Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

check for configured debugger before start to provide a nicer error message #401

Merged
merged 2 commits into from
Feb 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,22 @@ 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

- Added registers view ([@nomtats]) #242
- Enabled breakpoints inside `riscv` files ([@William-An]) #404

[0.27.0]: https://github.com/WebFreak001/code-debug/compare/v0.26.1...v0.27.0

## [0.26.1] - 2022-12-31

### Fixed
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
Loading