Reuse ids of stask frames, add some type inference
Use GDB's stask frames number as its id in vscode
This commit is contained in:
parent
f171d9f4ac
commit
77b689443f
1 changed files with 53 additions and 46 deletions
|
|
@ -18,8 +18,11 @@ class ExtendedVariable {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const STACK_HANDLES_START = 1000;
|
||||||
|
const VAR_HANDLES_START = 2000;
|
||||||
|
|
||||||
export class MI2DebugSession extends DebugSession {
|
export class MI2DebugSession extends DebugSession {
|
||||||
protected variableHandles = new Handles<any>();
|
protected variableHandles = new Handles<string | ExtendedVariable>(VAR_HANDLES_START);
|
||||||
protected quit: boolean;
|
protected quit: boolean;
|
||||||
protected attached: boolean;
|
protected attached: boolean;
|
||||||
protected needContinue: boolean;
|
protected needContinue: boolean;
|
||||||
|
|
@ -253,7 +256,7 @@ export class MI2DebugSession extends DebugSession {
|
||||||
|
|
||||||
protected scopesRequest(response: DebugProtocol.ScopesResponse, args: DebugProtocol.ScopesArguments): void {
|
protected scopesRequest(response: DebugProtocol.ScopesResponse, args: DebugProtocol.ScopesArguments): void {
|
||||||
const scopes = new Array<Scope>();
|
const scopes = new Array<Scope>();
|
||||||
scopes.push(new Scope("Local", this.variableHandles.create("@frame:" + (args.frameId || 0)), false));
|
scopes.push(new Scope("Local", STACK_HANDLES_START + (parseInt(args.frameId as any) || 0), false));
|
||||||
|
|
||||||
response.body = {
|
response.body = {
|
||||||
scopes: scopes
|
scopes: scopes
|
||||||
|
|
@ -263,7 +266,13 @@ export class MI2DebugSession extends DebugSession {
|
||||||
|
|
||||||
protected async variablesRequest(response: DebugProtocol.VariablesResponse, args: DebugProtocol.VariablesArguments): Promise<void> {
|
protected async variablesRequest(response: DebugProtocol.VariablesResponse, args: DebugProtocol.VariablesArguments): Promise<void> {
|
||||||
const variables: DebugProtocol.Variable[] = [];
|
const variables: DebugProtocol.Variable[] = [];
|
||||||
const id = this.variableHandles.get(args.variablesReference);
|
let id: number | string | ExtendedVariable;
|
||||||
|
if (args.variablesReference < VAR_HANDLES_START) {
|
||||||
|
id = args.variablesReference - STACK_HANDLES_START;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
id = this.variableHandles.get(args.variablesReference);
|
||||||
|
}
|
||||||
|
|
||||||
let createVariable = (arg, options?) => {
|
let createVariable = (arg, options?) => {
|
||||||
if (options)
|
if (options)
|
||||||
|
|
@ -296,58 +305,56 @@ export class MI2DebugSession extends DebugSession {
|
||||||
return res;
|
return res;
|
||||||
};
|
};
|
||||||
|
|
||||||
if (typeof id == "string") {
|
if (typeof id == "number") {
|
||||||
if (id.startsWith("@frame:")) {
|
let stack: Variable[];
|
||||||
let stack: Variable[];
|
try {
|
||||||
try {
|
stack = await this.miDebugger.getStackVariables(this.threadID, id);
|
||||||
stack = await this.miDebugger.getStackVariables(this.threadID, parseInt(id.substr("@frame:".length)));
|
for (const variable of stack) {
|
||||||
for (const variable of stack) {
|
try {
|
||||||
try {
|
const varObj = await this.miDebugger.varCreate(variable.name);
|
||||||
const varObj = await this.miDebugger.varCreate(variable.name);
|
let v = miVarObjToVariable(varObj.resultRecords.results);
|
||||||
let v = miVarObjToVariable(varObj.resultRecords.results);
|
v.name = variable.name;
|
||||||
v.name = variable.name;
|
variables.push(v);
|
||||||
variables.push(v);
|
}
|
||||||
}
|
catch (err) {
|
||||||
catch (err) {
|
variables.push({
|
||||||
variables.push({
|
name: variable.name,
|
||||||
name: variable.name,
|
value: `<${err}>`,
|
||||||
value: err,
|
variablesReference: 0
|
||||||
variablesReference: 0
|
});
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
response.body = {
|
|
||||||
variables: variables
|
|
||||||
};
|
|
||||||
this.sendResponse(response);
|
|
||||||
}
|
|
||||||
catch (err) {
|
|
||||||
this.sendErrorResponse(response, 1, `Could not expand variable: ${err}`);
|
|
||||||
}
|
}
|
||||||
|
response.body = {
|
||||||
|
variables: variables
|
||||||
|
};
|
||||||
|
this.sendResponse(response);
|
||||||
}
|
}
|
||||||
else {
|
catch (err) {
|
||||||
// Variable members
|
this.sendErrorResponse(response, 1, `Could not expand variable: ${err}`);
|
||||||
let listChildren;
|
}
|
||||||
try {
|
}
|
||||||
listChildren = await this.miDebugger.varListChildren(id);
|
else if (typeof id == "string") {
|
||||||
const children: any[] = listChildren.result("children");
|
// Variable members
|
||||||
// TODO: use hasMore when it's > 0
|
let listChildren;
|
||||||
// const hasMore = parseInt(listChildren.result("has_more"));
|
try {
|
||||||
const vars = children.map(child => miVarObjToVariable(child[1]));
|
listChildren = await this.miDebugger.varListChildren(id);
|
||||||
|
const children: any[] = listChildren.result("children");
|
||||||
|
// TODO: use hasMore when it's > 0
|
||||||
|
// const hasMore = parseInt(listChildren.result("has_more"));
|
||||||
|
const vars = children.map(child => miVarObjToVariable(child[1]));
|
||||||
|
|
||||||
response.body = {
|
response.body = {
|
||||||
variables: vars
|
variables: vars
|
||||||
}
|
|
||||||
this.sendResponse(response);
|
|
||||||
}
|
|
||||||
catch (err) {
|
|
||||||
this.sendErrorResponse(response, 1, `Could not expand variable: ${err}`);
|
|
||||||
}
|
}
|
||||||
|
this.sendResponse(response);
|
||||||
|
}
|
||||||
|
catch (err) {
|
||||||
|
this.sendErrorResponse(response, 1, `Could not expand variable: ${err}`);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (typeof id == "object") {
|
else if (typeof id == "object") {
|
||||||
if (id instanceof ExtendedVariable) {
|
if (id instanceof ExtendedVariable) {
|
||||||
let varReq = <ExtendedVariable>id;
|
let varReq = id;
|
||||||
if (varReq.options.arg) {
|
if (varReq.options.arg) {
|
||||||
let strArr = [];
|
let strArr = [];
|
||||||
let argsPart = true;
|
let argsPart = true;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue