Skip to content

Commit 5a4c4a9

Browse files
committed
Add threadId and FrameId as optional parameters
The GDB MI commands can take a threadId and frameId if specified so add that capability as an optional parameter.
1 parent cd740cd commit 5a4c4a9

File tree

4 files changed

+59
-9
lines changed

4 files changed

+59
-9
lines changed

src/GDBDebugSession.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1177,6 +1177,7 @@ export class GDBDebugSession extends LoggingDebugSession {
11771177
args.name.replace(/^\[(\d+)\]/, '$1');
11781178
const stackDepth = await mi.sendStackInfoDepth(this.gdb, {
11791179
maxDepth: 100,
1180+
threadId: frame.threadId,
11801181
});
11811182
const depth = parseInt(stackDepth.depth, 10);
11821183
let varobj = this.gdb.varManager.getVar(
@@ -1321,6 +1322,7 @@ export class GDBDebugSession extends LoggingDebugSession {
13211322

13221323
const stackDepth = await mi.sendStackInfoDepth(this.gdb, {
13231324
maxDepth: 100,
1325+
threadId: frame.threadId,
13241326
});
13251327
const depth = parseInt(stackDepth.depth, 10);
13261328
let varobj = this.gdb.varManager.getVar(
@@ -1908,6 +1910,7 @@ export class GDBDebugSession extends LoggingDebugSession {
19081910
// stack depth necessary for differentiating between similarly named variables at different stack depths
19091911
const stackDepth = await mi.sendStackInfoDepth(this.gdb, {
19101912
maxDepth: 100,
1913+
threadId: frame.threadId,
19111914
});
19121915
const depth = parseInt(stackDepth.depth, 10);
19131916

@@ -2061,6 +2064,7 @@ export class GDBDebugSession extends LoggingDebugSession {
20612064
// fetch stack depth to obtain frameId/threadId/depth tuple
20622065
const stackDepth = await mi.sendStackInfoDepth(this.gdb, {
20632066
maxDepth: 100,
2067+
threadId: frame.threadId,
20642068
});
20652069
const depth = parseInt(stackDepth.depth, 10);
20662070
// we need to keep track of children and the parent varname in GDB

src/mi/data.ts

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,20 +54,28 @@ export function sendDataReadMemoryBytes(
5454
gdb: GDBBackend,
5555
address: string,
5656
size: number,
57-
offset = 0
57+
offset = 0,
58+
threadId?: number,
59+
frameId?: number
5860
): Promise<MIDataReadMemoryBytesResponse> {
61+
const cmdThread = threadId ? `--thread ${threadId}` : '';
62+
const cmdFrame = frameId ? `--frame ${frameId}` : '';
5963
return gdb.sendCommand(
60-
`-data-read-memory-bytes -o ${offset} "${address}" ${size}`
64+
`-data-read-memory-bytes ${cmdThread} ${cmdFrame} -o ${offset} "${address}" ${size}`
6165
);
6266
}
6367

6468
export function sendDataWriteMemoryBytes(
6569
gdb: GDBBackend,
6670
memoryReference: string,
67-
data: string
71+
data: string,
72+
threadId?: number,
73+
frameId?: number
6874
): Promise<void> {
75+
const cmdThread = threadId ? `--thread ${threadId}` : '';
76+
const cmdFrame = frameId ? `--frame ${frameId}` : '';
6977
return gdb.sendCommand(
70-
`-data-write-memory-bytes "${memoryReference}" "${data}"`
78+
`-data-write-memory-bytes ${cmdThread} ${cmdFrame} "${memoryReference}" "${data}"`
7179
);
7280
}
7381

src/mi/var.ts

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -142,9 +142,17 @@ export function sendVarUpdate(
142142
| MIVarPrintValues.no
143143
| MIVarPrintValues.all
144144
| MIVarPrintValues.simple;
145+
threadId?: number;
146+
frameId?: number;
145147
}
146148
): Promise<MIVarUpdateResponse> {
147149
let command = '-var-update';
150+
if (params.threadId !== undefined) {
151+
command += ` --thread ${params.threadId}`;
152+
}
153+
if (params.frameId !== undefined) {
154+
command += ` --frame ${params.frameId}`;
155+
}
148156
if (params.printValues) {
149157
command += ` ${params.printValues}`;
150158
} else {
@@ -162,9 +170,18 @@ export function sendVarDelete(
162170
gdb: GDBBackend,
163171
params: {
164172
varname: string;
173+
threadId?: number;
174+
frameId?: number;
165175
}
166176
): Promise<void> {
167-
const command = `-var-delete ${params.varname}`;
177+
let command = `-var-delete`;
178+
if (params.threadId !== undefined) {
179+
command += ` --thread ${params.threadId}`;
180+
}
181+
if (params.frameId !== undefined) {
182+
command += ` --frame ${params.frameId}`;
183+
}
184+
command += ` ${params.varname}`;
168185
return gdb.sendCommand(command);
169186
}
170187

@@ -183,9 +200,18 @@ export function sendVarEvaluateExpression(
183200
gdb: GDBBackend,
184201
params: {
185202
varname: string;
203+
threadId?: number;
204+
frameId?: number;
186205
}
187206
): Promise<MIVarEvalResponse> {
188-
const command = `-var-evaluate-expression ${params.varname}`;
207+
let command = '-var-evaluate-expression';
208+
if (params.threadId !== undefined) {
209+
command += ` --thread ${params.threadId}`;
210+
}
211+
if (params.frameId !== undefined) {
212+
command += ` --frame ${params.frameId}`;
213+
}
214+
command += ` ${params.varname}`;
189215
return gdb.sendCommand(command);
190216
}
191217

src/varManager.ts

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,11 @@ export class VarManager {
124124
}
125125
}
126126
if (deleteme) {
127-
await sendVarDelete(this.gdb, { varname: deleteme.varname });
127+
await sendVarDelete(this.gdb, {
128+
varname: deleteme.varname,
129+
threadId,
130+
frameId,
131+
});
128132
vars.splice(vars.indexOf(deleteme), 1);
129133
for (const child of deleteme.children) {
130134
await this.removeVar(
@@ -145,7 +149,11 @@ export class VarManager {
145149
varobj: VarObjType
146150
): Promise<VarObjType> {
147151
let returnVar = varobj;
148-
const vup = await sendVarUpdate(this.gdb, { name: varobj.varname });
152+
const vup = await sendVarUpdate(this.gdb, {
153+
name: varobj.varname,
154+
threadId,
155+
frameId,
156+
});
149157
const update = vup.changelist[0];
150158
if (update) {
151159
if (update.in_scope === 'true') {
@@ -155,7 +163,11 @@ export class VarManager {
155163
}
156164
} else {
157165
this.removeVar(frameId, threadId, depth, varobj.varname);
158-
await sendVarDelete(this.gdb, { varname: varobj.varname });
166+
await sendVarDelete(this.gdb, {
167+
varname: varobj.varname,
168+
threadId,
169+
frameId,
170+
});
159171
const createResponse = await sendVarCreate(this.gdb, {
160172
frame: 'current',
161173
expression: varobj.expression,

0 commit comments

Comments
 (0)