Skip to content
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
62 changes: 61 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,16 @@
"description": "Additional arguments to pass to GDB",
"default": []
},
"valuesFormatting": {
"type": "string",
"description": "Set the way of showing variable values. 'disabled' - show value as is, 'parseText' - parse debuggers output text into structure, 'prettyPrinters' - enable debuggers custom pretty-printers if there are any",
"default": "parseText",
"enum": [
"disabled",
"parseText",
"prettyPrinters"
]
},
"printCalls": {
"type": "boolean",
"description": "Prints all GDB calls to the console",
Expand Down Expand Up @@ -192,6 +202,16 @@
"description": "If true this will connect to a gdbserver instead of attaching to a PID",
"default": false
},
"valuesFormatting": {
"type": "string",
"description": "Set the way of showing variable values. 'disabled' - show value as is, 'parseText' - parse debuggers output text into structure, 'prettyPrinters' - enable debuggers custom pretty-printers if there are any",
"default": "parseText",
"enum": [
"disabled",
"parseText",
"prettyPrinters"
]
},
"printCalls": {
"type": "boolean",
"description": "Prints all GDB calls to the console",
Expand Down Expand Up @@ -466,6 +486,16 @@
"description": "Additional arguments to pass to LLDB",
"default": []
},
"valuesFormatting": {
"type": "string",
"description": "Set the way of showing variable values. 'disabled' - show value as is, 'parseText' - parse debuggers output text into structure, 'prettyPrinters' - enable debuggers custom pretty-printers if there are any",
"default": "parseText",
"enum": [
"disabled",
"parseText",
"prettyPrinters"
]
},
"printCalls": {
"type": "boolean",
"description": "Prints all lldb calls to the console",
Expand Down Expand Up @@ -552,6 +582,16 @@
"type": "string",
"description": "PID of running program or program name"
},
"valuesFormatting": {
"type": "string",
"description": "Set the way of showing variable values. 'disabled' - show value as is, 'parseText' - parse debuggers output text into structure, 'prettyPrinters' - enable debuggers custom pretty-printers if there are any",
"default": "parseText",
"enum": [
"disabled",
"parseText",
"prettyPrinters"
]
},
"printCalls": {
"type": "boolean",
"description": "Prints all LLDB calls to the console",
Expand Down Expand Up @@ -713,6 +753,16 @@
"description": "Additional arguments to pass to mago",
"default": []
},
"valuesFormatting": {
"type": "string",
"description": "Set the way of showing variable values. 'disabled' - show value as is, 'parseText' - parse debuggers output text into structure, 'prettyPrinters' - enable debuggers custom pretty-printers if there are any",
"default": "parseText",
"enum": [
"disabled",
"parseText",
"prettyPrinters"
]
},
"printCalls": {
"type": "boolean",
"description": "Prints all mago calls to the console",
Expand All @@ -739,6 +789,16 @@
"type": "string",
"description": "PID of running program or program name"
},
"valuesFormatting": {
"type": "string",
"description": "Set the way of showing variable values. 'disabled' - show value as is, 'parseText' - parse debuggers output text into structure, 'prettyPrinters' - enable debuggers custom pretty-printers if there are any",
"default": "parseText",
"enum": [
"disabled",
"parseText",
"prettyPrinters"
]
},
"printCalls": {
"type": "boolean",
"description": "Prints all mago calls to the console",
Expand Down Expand Up @@ -834,4 +894,4 @@
"@types/node": "^7.0.5",
"@types/mocha": "^2.2.39"
}
}
}
65 changes: 64 additions & 1 deletion src/backend/backend.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
import { MINode } from "./mi_parse";
import { DebugProtocol } from "vscode-debugprotocol/lib/debugProtocol";

export type ValuesFormattingMode = "disabled" | "parseText" | "prettyPrinters";

export interface Breakpoint {
file?: string;
line?: number;
Expand Down Expand Up @@ -59,4 +64,62 @@ export interface IBackend {
isReady(): boolean;
changeVariable(name: string, rawValue: string): Thenable<any>;
examineMemory(from: number, to: number): Thenable<any>;
}
}

export class VariableObject {
name: string;
exp: string;
numchild: number;
type: string;
value: string;
threadId: string;
frozen: boolean;
dynamic: boolean;
displayhint: string;
has_more: boolean;
id: number;
constructor(node: any) {
this.name = MINode.valueOf(node, "name");
this.exp = MINode.valueOf(node, "exp");
this.numchild = parseInt(MINode.valueOf(node, "numchild"));
this.type = MINode.valueOf(node, "type");
this.value = MINode.valueOf(node, "value");
this.threadId = MINode.valueOf(node, "thread-id");
this.frozen = !!MINode.valueOf(node, "frozen");
this.dynamic = !!MINode.valueOf(node, "dynamic");
this.displayhint = MINode.valueOf(node, "displayhint");
// TODO: use has_more when it's > 0
this.has_more = !!MINode.valueOf(node, "has_more");
}

public applyChanges(node: MINode) {
this.value = MINode.valueOf(node, "value");
if (!!MINode.valueOf(node, "type_changed")) {
this.type = MINode.valueOf(node, "new_type");
}
this.dynamic = !!MINode.valueOf(node, "dynamic");
this.displayhint = MINode.valueOf(node, "displayhint");
this.has_more = !!MINode.valueOf(node, "has_more");
}

public isCompound(): boolean {
return this.numchild > 0 ||
this.value === "{...}" ||
(this.dynamic && (this.displayhint === "array" || this.displayhint === "map"));
}

public toProtocolVariable(): DebugProtocol.Variable {
let res: DebugProtocol.Variable = {
name: this.exp,
evaluateName: this.name,
value: (this.value === void 0) ? "<unknown>" : this.value,
type: this.type,
// kind: this.displayhint,
variablesReference: this.id
};
if (this.displayhint) {
res.kind = this.displayhint;
}
return res;
}
}
77 changes: 57 additions & 20 deletions src/backend/mi2/mi2.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Breakpoint, IBackend, Stack, SSHArguments, Variable } from "../backend"
import { Breakpoint, IBackend, Stack, SSHArguments, Variable, VariableObject } from "../backend"
import * as ChildProcess from "child_process"
import { EventEmitter } from "events"
import { parseMI, MINode } from '../mi_parse';
Expand Down Expand Up @@ -196,6 +196,9 @@ export class MI2 extends EventEmitter implements IBackend {
];
if (!attach)
cmds.push(this.sendCommand("file-exec-and-symbols \"" + escape(target) + "\""));
if (this.prettyPrint)
cmds.push(this.sendCommand("enable-pretty-printing"));

return cmds;
}

Expand Down Expand Up @@ -617,27 +620,25 @@ export class MI2 extends EventEmitter implements IBackend {
});
}

getStackVariables(thread: number, frame: number): Thenable<Variable[]> {
async getStackVariables(thread: number, frame: number): Promise<Variable[]> {
if (trace)
this.log("stderr", "getStackVariables");
return new Promise((resolve, reject) => {
this.sendCommand("stack-list-variables --thread " + thread + " --frame " + frame + " --simple-values").then((result) => {
let variables = result.result("variables");
let ret: Variable[] = [];
variables.forEach(element => {
const key = MINode.valueOf(element, "name");
const value = MINode.valueOf(element, "value");
const type = MINode.valueOf(element, "type");
ret.push({
name: key,
valueStr: value,
type: type,
raw: element
});
});
resolve(ret);
}, reject);
});

const result = await this.sendCommand(`stack-list-variables --thread ${thread} --frame ${frame} --simple-values`);
const variables = result.result("variables");
let ret: Variable[] = [];
for (const element of variables) {
const key = MINode.valueOf(element, "name");
const value = MINode.valueOf(element, "value");
const type = MINode.valueOf(element, "type");
ret.push({
name: key,
valueStr: value,
type: type,
raw: element
});
}
return ret;
}

examineMemory(from: number, length: number): Thenable<any> {
Expand All @@ -660,6 +661,41 @@ export class MI2 extends EventEmitter implements IBackend {
});
}

async varCreate(expression: string, name: string = "-"): Promise<VariableObject> {
if (trace)
this.log("stderr", "varCreate");
const res = await this.sendCommand(`var-create ${name} @ "${expression}"`);
return new VariableObject(res.result(""));
}

async varEvalExpression(name: string): Promise<MINode> {
if (trace)
this.log("stderr", "varEvalExpression");
return this.sendCommand(`var-evaluate-expression ${name}`);
}

async varListChildren(name: string): Promise<VariableObject[]> {
if (trace)
this.log("stderr", "varListChildren");
//TODO: add `from` and `to` arguments
const res = await this.sendCommand(`var-list-children --all-values ${name}`);
const children = res.result("children");
let omg: VariableObject[] = children.map(child => new VariableObject(child[1]));
return omg;
}

async varUpdate(name: string = "*"): Promise<MINode> {
if (trace)
this.log("stderr", "varUpdate");
return this.sendCommand(`var-update --all-values ${name}`)
}

async varAssign(name: string, rawValue: string): Promise<MINode> {
if (trace)
this.log("stderr", "varAssign");
return this.sendCommand(`var-assign ${name} ${rawValue}`);
}

logNoNewLine(type: string, msg: string) {
this.emit("msg", type, msg);
}
Expand Down Expand Up @@ -710,6 +746,7 @@ export class MI2 extends EventEmitter implements IBackend {
return this.isSSH ? this.sshReady : !!this.process;
}

prettyPrint: boolean = true;
printCalls: boolean;
debugOutput: boolean;
public procEnv: any;
Expand Down
8 changes: 6 additions & 2 deletions src/gdb.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { MI2DebugSession } from './mibase';
import { DebugSession, InitializedEvent, TerminatedEvent, StoppedEvent, OutputEvent, Thread, StackFrame, Scope, Source, Handles } from 'vscode-debugadapter';
import { DebugProtocol } from 'vscode-debugprotocol';
import { MI2 } from "./backend/mi2/mi2";
import { SSHArguments } from './backend/backend';
import { SSHArguments, ValuesFormattingMode } from './backend/backend';

export interface LaunchRequestArguments {
cwd: string;
Expand All @@ -14,6 +14,7 @@ export interface LaunchRequestArguments {
terminal: string;
autorun: string[];
ssh: SSHArguments;
valuesFormatting: ValuesFormattingMode;
printCalls: boolean;
showDevDebugOutput: boolean;
}
Expand All @@ -28,6 +29,7 @@ export interface AttachRequestArguments {
remote: boolean;
autorun: string[];
ssh: SSHArguments;
valuesFormatting: ValuesFormattingMode;
printCalls: boolean;
showDevDebugOutput: boolean;
}
Expand All @@ -54,6 +56,7 @@ class GDBDebugSession extends MI2DebugSession {
this.started = false;
this.crashed = false;
this.debugReady = false;
this.setValuesFormattingMode(args.valuesFormatting);
this.miDebugger.printCalls = !!args.printCalls;
this.miDebugger.debugOutput = !!args.showDevDebugOutput;
if (args.ssh !== undefined) {
Expand Down Expand Up @@ -121,6 +124,7 @@ class GDBDebugSession extends MI2DebugSession {
this.needContinue = true;
this.isSSH = false;
this.debugReady = false;
this.setValuesFormattingMode(args.valuesFormatting);
this.miDebugger.printCalls = !!args.printCalls;
this.miDebugger.debugOutput = !!args.showDevDebugOutput;
if (args.ssh !== undefined) {
Expand Down Expand Up @@ -177,4 +181,4 @@ class GDBDebugSession extends MI2DebugSession {
}
}

DebugSession.run(GDBDebugSession);
DebugSession.run(GDBDebugSession);
8 changes: 6 additions & 2 deletions src/lldb.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { MI2DebugSession } 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 } from './backend/backend';
import { SSHArguments, ValuesFormattingMode } from './backend/backend';

export interface LaunchRequestArguments {
cwd: string;
Expand All @@ -13,6 +13,7 @@ export interface LaunchRequestArguments {
arguments: string;
autorun: string[];
ssh: SSHArguments;
valuesFormatting: ValuesFormattingMode;
printCalls: boolean;
showDevDebugOutput: boolean;
}
Expand All @@ -25,6 +26,7 @@ export interface AttachRequestArguments {
debugger_args: string[];
executable: string;
autorun: string[];
valuesFormatting: ValuesFormattingMode;
printCalls: boolean;
showDevDebugOutput: boolean;
}
Expand All @@ -49,6 +51,7 @@ class LLDBDebugSession extends MI2DebugSession {
this.started = false;
this.crashed = false;
this.debugReady = false;
this.setValuesFormattingMode(args.valuesFormatting);
this.miDebugger.printCalls = !!args.printCalls;
this.miDebugger.debugOutput = !!args.showDevDebugOutput;
if (args.ssh !== undefined) {
Expand Down Expand Up @@ -108,6 +111,7 @@ class LLDBDebugSession extends MI2DebugSession {
this.needContinue = true;
this.isSSH = false;
this.debugReady = false;
this.setValuesFormattingMode(args.valuesFormatting);
this.miDebugger.printCalls = !!args.printCalls;
this.miDebugger.debugOutput = !!args.showDevDebugOutput;
this.miDebugger.attach(args.cwd, args.executable, args.target).then(() => {
Expand All @@ -120,4 +124,4 @@ class LLDBDebugSession extends MI2DebugSession {
}
}

DebugSession.run(LLDBDebugSession);
DebugSession.run(LLDBDebugSession);
Loading