Skip to content
Closed
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
45 changes: 23 additions & 22 deletions src/gdb/GDBDebugSessionBase.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2041,7 +2041,9 @@ export abstract class GDBDebugSessionBase extends LoggingDebugSession {
const stackDepth = await mi.sendStackInfoDepth(this.gdb, {
maxDepth: 100,
});

const depth = parseInt(stackDepth.depth, 10);

// we need to keep track of children and the parent varname in GDB
let children;
let parentVarname = ref.varobjName;
Expand All @@ -2052,6 +2054,7 @@ export abstract class GDBDebugSessionBase extends LoggingDebugSession {
depth,
ref.varobjName
);

if (varobj) {
children = await mi.sendVarListChildren(this.gdb, {
name: varobj.varname,
Expand All @@ -2065,13 +2068,19 @@ export abstract class GDBDebugSessionBase extends LoggingDebugSession {
printValues: mi.MIVarPrintValues.all,
});
}

// Grab the full path of parent.
const topLevelPathExpression =
const topLevelPathExpression = // still required for 'class' objects
varobj?.expression ??
(await this.getFullPathExpression(parentVarname));

// iterate through the children
for (const child of children.children) {
const varInfoExpression = await this.getInfoExpression(child.name);
const varInfoPathExpression = await this.getFullPathExpression(
child.name
);

// check if we're dealing with a C++ object. If we are, we need to fetch the grandchildren instead.
const isClass = this.isChildOfClass(child);
if (isClass) {
Expand Down Expand Up @@ -2101,35 +2110,18 @@ export abstract class GDBDebugSessionBase extends LoggingDebugSession {
}
} else {
// check if we're dealing with an array
let name = `${ref.varobjName}.${child.exp}`;
const varobjName = name;
const value = child.value ? child.value : child.type;
const isArrayParent = arrayRegex.test(child.type);
const isArrayChild =
varobj !== undefined
? arrayRegex.test(varobj.type) &&
arrayChildRegex.test(child.exp)
: false;
if (isArrayChild) {
// update the display name for array elements to have square brackets
name = `[${child.exp}]`;
}
const variableName = isArrayChild ? name : child.exp;
const evaluateName =
isArrayParent || isArrayChild
? `${topLevelPathExpression}[${child.exp}]`
: `${topLevelPathExpression}.${child.exp}`;
variables.push({
name: variableName,
evaluateName,
name: varInfoExpression, //variableName,
evaluateName: varInfoPathExpression, //evaluateName,
value,
type: child.type,
variablesReference:
parseInt(child.numchild, 10) > 0
? this.variableHandles.create({
type: 'object',
frameHandle: ref.frameHandle,
varobjName,
varobjName: `${ref.varobjName}.${child.exp}`,
})
: 0,
});
Expand All @@ -2145,7 +2137,16 @@ export abstract class GDBDebugSessionBase extends LoggingDebugSession {
inputVarName
);
// result from GDB looks like (parentName).field so remove ().
return exprResponse.path_expr.replace(/[()]/g, '');
return exprResponse.path_expr; //.replace(/[()]/g, '');
}

/** Query GDB using varXX name to get variable name */
protected async getInfoExpression(inputVarName: string) {
const exprResponse = await mi.sendVarInfoExpression(
this.gdb,
inputVarName
);
return exprResponse.exp;
}

// Register view
Expand Down
20 changes: 10 additions & 10 deletions src/integration-tests/var.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -440,36 +440,36 @@ describe('Variables Test Suite', function () {
children.body.variables.length,
'There is a different number of child variables than expected'
).to.equal(3);
verifyVariable(children.body.variables[0], '[0]', 'int', '1', {
verifyVariable(children.body.variables[0], '0', 'int', '1', {
hasMemoryReference: false,
});
verifyVariable(children.body.variables[1], '[1]', 'int', '2', {
verifyVariable(children.body.variables[1], '1', 'int', '2', {
hasMemoryReference: false,
});
verifyVariable(children.body.variables[2], '[2]', 'int', '3', {
verifyVariable(children.body.variables[2], '2', 'int', '3', {
hasMemoryReference: false,
});
// set the variables to something different
const set0inHex = await dc.setVariableRequest({
name: '[0]',
name: '0',
value: '0x11',
variablesReference: childVR,
});
expect(set0inHex.body.value).to.equal('17');
const set0 = await dc.setVariableRequest({
name: '[0]',
name: '0',
value: '11',
variablesReference: childVR,
});
expect(set0.body.value).to.equal('11');
const set1 = await dc.setVariableRequest({
name: '[1]',
name: '1',
value: '22',
variablesReference: childVR,
});
expect(set1.body.value).to.equal('22');
const set2 = await dc.setVariableRequest({
name: '[2]',
name: '2',
value: '33',
variablesReference: childVR,
});
Expand All @@ -480,13 +480,13 @@ describe('Variables Test Suite', function () {
children.body.variables.length,
'There is a different number of child variables than expected'
).to.equal(3);
verifyVariable(children.body.variables[0], '[0]', 'int', '11', {
verifyVariable(children.body.variables[0], '0', 'int', '11', {
hasMemoryReference: false,
});
verifyVariable(children.body.variables[1], '[1]', 'int', '22', {
verifyVariable(children.body.variables[1], '1', 'int', '22', {
hasMemoryReference: false,
});
verifyVariable(children.body.variables[2], '[2]', 'int', '33', {
verifyVariable(children.body.variables[2], '2', 'int', '33', {
hasMemoryReference: false,
});
// step the program and see that the values were passed to the program and evaluated.
Expand Down
13 changes: 13 additions & 0 deletions src/mi/var.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,11 @@ export interface MIVarAssignResponse {
value: string;
}

export interface MIVarInfoResponse {
exp: string;
lang: string;
}

export interface MIVarPathInfoResponse {
path_expr: string;
}
Expand Down Expand Up @@ -189,6 +194,14 @@ export function sendVarEvaluateExpression(
return gdb.sendCommand(command);
}

export function sendVarInfoExpression(
gdb: IGDBBackend,
name: string
): Promise<MIVarInfoResponse> {
const command = `-var-info-expression ${name}`;
return gdb.sendCommand(command);
}

export function sendVarInfoPathExpression(
gdb: IGDBBackend,
name: string
Expand Down