Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 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
146 changes: 70 additions & 76 deletions src/gdb/GDBDebugSessionBase.ts
Original file line number Diff line number Diff line change
Expand Up @@ -967,7 +967,10 @@ export abstract class GDBDebugSessionBase extends LoggingDebugSession {
args: DebugProtocol.StepOutArguments
): Promise<void> {
try {
await mi.sendExecFinish(this.gdb, args.threadId, 0);
await mi.sendExecFinish(this.gdb, {
threadId: args.threadId,
frameId: 0,
});
this.sendResponse(response);
} catch (err) {
this.sendErrorResponse(
Expand Down Expand Up @@ -1023,7 +1026,7 @@ export abstract class GDBDebugSessionBase extends LoggingDebugSession {
response: DebugProtocol.ScopesResponse,
args: DebugProtocol.ScopesArguments
): void {
const frame: FrameVariableReference = {
const frameVarRef: FrameVariableReference = {
type: 'frame',
frameHandle: args.frameId,
};
Expand All @@ -1035,7 +1038,11 @@ export abstract class GDBDebugSessionBase extends LoggingDebugSession {

response.body = {
scopes: [
new Scope('Local', this.variableHandles.create(frame), false),
new Scope(
'Local',
this.variableHandles.create(frameVarRef),
false
),
new Scope(
'Registers',
this.variableHandles.create(registers),
Expand Down Expand Up @@ -1092,8 +1099,8 @@ export abstract class GDBDebugSessionBase extends LoggingDebugSession {
this.sendResponse(response);
return;
}
const frame = this.frameHandles.get(ref.frameHandle);
if (!frame) {
const frameRef = this.frameHandles.get(ref.frameHandle);
if (!frameRef) {
this.sendResponse(response);
return;
}
Expand All @@ -1107,21 +1114,18 @@ export abstract class GDBDebugSessionBase extends LoggingDebugSession {
});
const depth = parseInt(stackDepth.depth, 10);
let varobj = this.gdb.varManager.getVar(
frame.frameId,
frame.threadId,
frameRef,
depth,
varname,
ref.type
);
if (!varobj && ref.type === 'registers') {
const varCreateResponse = await mi.sendVarCreate(this.gdb, {
expression: '$' + args.name,
frameId: frame.frameId,
threadId: frame.threadId,
frameRef,
});
varobj = this.gdb.varManager.addVar(
frame.frameId,
frame.threadId,
frameRef,
depth,
args.name,
false,
Expand Down Expand Up @@ -1158,8 +1162,7 @@ export abstract class GDBDebugSessionBase extends LoggingDebugSession {
'.' +
args.name.replace(/^\[(\d+)\]/, '$1');
varobj = this.gdb.varManager.getVar(
frame.frameId,
frame.threadId,
frameRef,
depth,
grandchildVarname
);
Expand Down Expand Up @@ -1207,6 +1210,27 @@ export abstract class GDBDebugSessionBase extends LoggingDebugSession {
// this.sendResponse(response);
// }

protected async evaluateRequestGdbCommand(
response: DebugProtocol.EvaluateResponse,
args: DebugProtocol.EvaluateArguments,
frameRef: FrameReference | undefined
): Promise<void> {
if (args.expression[1] === '-') {
await this.gdb.sendCommand(args.expression.slice(1));
} else {
await mi.sendInterpreterExecConsole(this.gdb, {
frameRef,
command: args.expression.slice(1),
});
}
response.body = {
result: '\r',
variablesReference: 0,
};
this.sendResponse(response);
return;
}

protected async evaluateRequest(
response: DebugProtocol.EvaluateResponse,
args: DebugProtocol.EvaluateArguments
Expand All @@ -1222,49 +1246,39 @@ export abstract class GDBDebugSessionBase extends LoggingDebugSession {
);
}

const frame = this.frameHandles.get(args.frameId);
if (!frame) {
const frameRef = args.frameId
? this.frameHandles.get(args.frameId)
: undefined;

if (!frameRef) {
this.sendResponse(response);
return;
}

if (args.expression.startsWith('>') && args.context === 'repl') {
if (args.expression[1] === '-') {
await this.gdb.sendCommand(args.expression.slice(1));
} else {
await mi.sendInterpreterExecConsole(this.gdb, {
threadId: frame.threadId,
frameId: frame.frameId,
command: args.expression.slice(1),
});
}
response.body = {
result: '\r',
variablesReference: 0,
};
this.sendResponse(response);
return;
return await this.evaluateRequestGdbCommand(
response,
args,
frameRef
);
}

const stackDepth = await mi.sendStackInfoDepth(this.gdb, {
maxDepth: 100,
});
const depth = parseInt(stackDepth.depth, 10);
let varobj = this.gdb.varManager.getVar(
frame.frameId,
frame.threadId,
frameRef,
depth,
args.expression
);
if (!varobj) {
const varCreateResponse = await mi.sendVarCreate(this.gdb, {
expression: args.expression,
frameId: frame.frameId,
threadId: frame.threadId,
frameRef,
});
varobj = this.gdb.varManager.addVar(
frame.frameId,
frame.threadId,
frameRef,
depth,
args.expression,
false,
Expand All @@ -1283,8 +1297,7 @@ export abstract class GDBDebugSessionBase extends LoggingDebugSession {
}
} else {
this.gdb.varManager.removeVar(
frame.frameId,
frame.threadId,
frameRef,
depth,
varobj.varname
);
Expand All @@ -1295,13 +1308,11 @@ export abstract class GDBDebugSessionBase extends LoggingDebugSession {
this.gdb,
{
expression: args.expression,
frameId: frame.frameId,
threadId: frame.threadId,
frameRef,
}
);
varobj = this.gdb.varManager.addVar(
frame.frameId,
frame.threadId,
frameRef,
depth,
args.expression,
false,
Expand All @@ -1311,7 +1322,7 @@ export abstract class GDBDebugSessionBase extends LoggingDebugSession {
}
}
}
if (varobj) {
if (varobj && args.frameId) {
const result =
args.context === 'variables' && Number(varobj.numchild)
? await this.getChildElements(varobj, args.frameId)
Expand Down Expand Up @@ -1870,8 +1881,8 @@ export abstract class GDBDebugSessionBase extends LoggingDebugSession {
): Promise<DebugProtocol.Variable[]> {
// initialize variables array and dereference the frame handle
const variables: DebugProtocol.Variable[] = [];
const frame = this.frameHandles.get(ref.frameHandle);
if (!frame) {
const frameRef = this.frameHandles.get(ref.frameHandle);
if (!frameRef) {
return Promise.resolve(variables);
}

Expand All @@ -1889,11 +1900,7 @@ export abstract class GDBDebugSessionBase extends LoggingDebugSession {
const toDelete = new Array<string>();

// get the list of vars we need to update for this frameId/threadId/depth tuple
const vars = this.gdb.varManager.getVars(
frame.frameId,
frame.threadId,
depth
);
const vars = this.gdb.varManager.getVars(frameRef, depth);
if (vars) {
for (const varobj of vars) {
// ignore expressions and child entries
Expand Down Expand Up @@ -1949,38 +1956,29 @@ export abstract class GDBDebugSessionBase extends LoggingDebugSession {
}
// clean up out of scope entries
for (const varname of toDelete) {
await this.gdb.varManager.removeVar(
frame.frameId,
frame.threadId,
depth,
varname
);
await this.gdb.varManager.removeVar(frameRef, depth, varname);
}
}
// if we had out of scope entries or no entries in the frameId/threadId/depth tuple, query GDB for new ones
if (callStack === true || numVars === 0) {
const result = await mi.sendStackListVariables(this.gdb, {
thread: frame.threadId,
frame: frame.frameId,
frameRef,
printValues: 'simple-values',
});
for (const variable of result.variables) {
let varobj = this.gdb.varManager.getVar(
frame.frameId,
frame.threadId,
frameRef,
depth,
variable.name
);
if (!varobj) {
// create var in GDB and store it in the varMgr
const varCreateResponse = await mi.sendVarCreate(this.gdb, {
expression: variable.name,
frameId: frame.frameId,
threadId: frame.threadId,
frameRef,
});
varobj = this.gdb.varManager.addVar(
frame.frameId,
frame.threadId,
frameRef,
depth,
variable.name,
true,
Expand All @@ -1990,8 +1988,7 @@ export abstract class GDBDebugSessionBase extends LoggingDebugSession {
} else {
// var existed as an expression before. Now it's a variable too.
varobj = await this.gdb.varManager.updateVar(
frame.frameId,
frame.threadId,
frameRef,
depth,
varobj
);
Expand Down Expand Up @@ -2027,8 +2024,8 @@ export abstract class GDBDebugSessionBase extends LoggingDebugSession {
): Promise<DebugProtocol.Variable[]> {
// initialize variables array and dereference the frame handle
const variables: DebugProtocol.Variable[] = [];
const frame = this.frameHandles.get(ref.frameHandle);
if (!frame) {
const frameRef = this.frameHandles.get(ref.frameHandle);
if (!frameRef) {
return Promise.resolve(variables);
}

Expand All @@ -2043,8 +2040,7 @@ export abstract class GDBDebugSessionBase extends LoggingDebugSession {

// if a varobj exists, use the varname stored there
const varobj = this.gdb.varManager.getVarByName(
frame.frameId,
frame.threadId,
frameRef,
depth,
ref.varobjName
);
Expand Down Expand Up @@ -2153,15 +2149,14 @@ export abstract class GDBDebugSessionBase extends LoggingDebugSession {
): Promise<DebugProtocol.Variable[]> {
// initialize variables array and dereference the frame handle
const variables: DebugProtocol.Variable[] = [];
const frame = this.frameHandles.get(ref.frameHandle);
if (!frame) {
const frameRef = this.frameHandles.get(ref.frameHandle);
if (!frameRef) {
return Promise.resolve(variables);
}

if (this.registerMap.size === 0) {
const result_names = await mi.sendDataListRegisterNames(this.gdb, {
frameId: frame.frameId,
threadId: frame.threadId,
frameRef,
});
let idx = 0;
const registerNames = result_names['register-names'];
Expand All @@ -2176,8 +2171,7 @@ export abstract class GDBDebugSessionBase extends LoggingDebugSession {

const result_values = await mi.sendDataListRegisterValues(this.gdb, {
fmt: 'x',
frameId: frame.frameId,
threadId: frame.threadId,
frameRef,
});
const reg_values = result_values['register-values'];
for (const n of reg_values) {
Expand Down
11 changes: 5 additions & 6 deletions src/mi/data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
*********************************************************************/

import { IGDBBackend } from '../types/gdb';
import { FrameReference } from '../types/session';
import { MIResponse, MIRegisterValueInfo } from './base';

interface MIDataReadMemoryBytesResponse {
Expand Down Expand Up @@ -123,11 +124,10 @@ export function sendDataListRegisterNames(
gdb: IGDBBackend,
params: {
regno?: number[];
frameId: number;
threadId: number;
frameRef: FrameReference;
}
): Promise<MIListRegisterNamesResponse> {
let command = `-data-list-register-names --frame ${params.frameId} --thread ${params.threadId}`;
let command = `-data-list-register-names --frame ${params.frameRef.frameId} --thread ${params.frameRef.threadId}`;

if (params.regno) {
command += params.regno.join(' ');
Expand All @@ -141,11 +141,10 @@ export function sendDataListRegisterValues(
params: {
fmt: string;
regno?: number[];
frameId: number;
threadId: number;
frameRef: FrameReference;
}
): Promise<MIListRegisterValuesResponse> {
let command = `-data-list-register-values --frame ${params.frameId} --thread ${params.threadId} ${params.fmt}`;
let command = `-data-list-register-values --frame ${params.frameRef.frameId} --thread ${params.frameRef.threadId} ${params.fmt}`;

if (params.regno) {
command += params.regno.join(' ');
Expand Down
Loading