127 lines
4.6 KiB
TypeScript
127 lines
4.6 KiB
TypeScript
import { MI2DebugSession, RunCommand } from './mibase';
|
|
import { DebugSession, InitializedEvent, TerminatedEvent, StoppedEvent, OutputEvent, Thread, StackFrame, Scope, Source, Handles } from 'vscode-debugadapter';
|
|
import { DebugProtocol } from 'vscode-debugprotocol';
|
|
import { MI2_LLDB } from "./backend/mi2/mi2lldb";
|
|
import { SSHArguments, ValuesFormattingMode } from './backend/backend';
|
|
|
|
export interface LaunchRequestArguments extends DebugProtocol.LaunchRequestArguments {
|
|
cwd: string;
|
|
target: string;
|
|
lldbmipath: string;
|
|
env: any;
|
|
debugger_args: string[];
|
|
pathSubstitutions: { [index: string]: string };
|
|
arguments: string;
|
|
autorun: string[];
|
|
stopAtEntry: boolean | string;
|
|
ssh: SSHArguments;
|
|
valuesFormatting: ValuesFormattingMode;
|
|
printCalls: boolean;
|
|
showDevDebugOutput: boolean;
|
|
}
|
|
|
|
export interface AttachRequestArguments extends DebugProtocol.AttachRequestArguments {
|
|
cwd: string;
|
|
target: string;
|
|
lldbmipath: string;
|
|
env: any;
|
|
debugger_args: string[];
|
|
pathSubstitutions: { [index: string]: string };
|
|
executable: string;
|
|
autorun: string[];
|
|
stopAtConnect: boolean;
|
|
stopAtEntry: boolean | string;
|
|
valuesFormatting: ValuesFormattingMode;
|
|
printCalls: boolean;
|
|
showDevDebugOutput: boolean;
|
|
}
|
|
|
|
class LLDBDebugSession extends MI2DebugSession {
|
|
protected initializeRequest(response: DebugProtocol.InitializeResponse, args: DebugProtocol.InitializeRequestArguments): void {
|
|
response.body.supportsGotoTargetsRequest = true;
|
|
response.body.supportsHitConditionalBreakpoints = true;
|
|
response.body.supportsConfigurationDoneRequest = true;
|
|
response.body.supportsConditionalBreakpoints = true;
|
|
response.body.supportsFunctionBreakpoints = true;
|
|
response.body.supportsEvaluateForHovers = true;
|
|
this.sendResponse(response);
|
|
}
|
|
|
|
protected launchRequest(response: DebugProtocol.LaunchResponse, args: LaunchRequestArguments): void {
|
|
this.miDebugger = new MI2_LLDB(args.lldbmipath || "lldb-mi", [], args.debugger_args, args.env);
|
|
this.setPathSubstitutions(args.pathSubstitutions);
|
|
this.initDebugger();
|
|
this.quit = false;
|
|
this.attached = false;
|
|
this.initialRunCommand = RunCommand.RUN;
|
|
this.isSSH = false;
|
|
this.started = false;
|
|
this.crashed = false;
|
|
this.setValuesFormattingMode(args.valuesFormatting);
|
|
this.miDebugger.printCalls = !!args.printCalls;
|
|
this.miDebugger.debugOutput = !!args.showDevDebugOutput;
|
|
this.stopAtEntry = args.stopAtEntry;
|
|
if (args.ssh !== undefined) {
|
|
if (args.ssh.forwardX11 === undefined)
|
|
args.ssh.forwardX11 = true;
|
|
if (args.ssh.port === undefined)
|
|
args.ssh.port = 22;
|
|
if (args.ssh.x11port === undefined)
|
|
args.ssh.x11port = 6000;
|
|
if (args.ssh.x11host === undefined)
|
|
args.ssh.x11host = "localhost";
|
|
if (args.ssh.remotex11screen === undefined)
|
|
args.ssh.remotex11screen = 0;
|
|
this.isSSH = true;
|
|
this.setSourceFileMap(args.ssh.sourceFileMap, args.ssh.cwd, args.cwd);
|
|
this.miDebugger.ssh(args.ssh, args.ssh.cwd, args.target, args.arguments, undefined, false).then(() => {
|
|
if (args.autorun)
|
|
args.autorun.forEach(command => {
|
|
this.miDebugger.sendUserInput(command);
|
|
});
|
|
this.sendResponse(response);
|
|
});
|
|
} else {
|
|
this.miDebugger.load(args.cwd, args.target, args.arguments, undefined).then(() => {
|
|
if (args.autorun)
|
|
args.autorun.forEach(command => {
|
|
this.miDebugger.sendUserInput(command);
|
|
});
|
|
this.sendResponse(response);
|
|
});
|
|
}
|
|
}
|
|
|
|
protected attachRequest(response: DebugProtocol.AttachResponse, args: AttachRequestArguments): void {
|
|
this.miDebugger = new MI2_LLDB(args.lldbmipath || "lldb-mi", [], args.debugger_args, args.env);
|
|
this.setPathSubstitutions(args.pathSubstitutions);
|
|
this.initDebugger();
|
|
this.quit = false;
|
|
this.attached = true;
|
|
this.initialRunCommand = !!args.stopAtConnect ? RunCommand.NONE : RunCommand.CONTINUE;
|
|
this.isSSH = false;
|
|
this.setValuesFormattingMode(args.valuesFormatting);
|
|
this.miDebugger.printCalls = !!args.printCalls;
|
|
this.miDebugger.debugOutput = !!args.showDevDebugOutput;
|
|
this.stopAtEntry = args.stopAtEntry;
|
|
this.miDebugger.attach(args.cwd, args.executable, args.target).then(() => {
|
|
if (args.autorun)
|
|
args.autorun.forEach(command => {
|
|
this.miDebugger.sendUserInput(command);
|
|
});
|
|
this.sendResponse(response);
|
|
});
|
|
}
|
|
|
|
// Add extra commands for source file path substitution in LLDB-specific syntax
|
|
protected setPathSubstitutions(substitutions: { [index: string]: string }): void {
|
|
if (substitutions) {
|
|
Object.keys(substitutions).forEach(source => {
|
|
this.miDebugger.extraCommands.push("settings append target.source-map " + source + " " + substitutions[source]);
|
|
})
|
|
}
|
|
}
|
|
}
|
|
|
|
DebugSession.run(LLDBDebugSession);
|