Skip to content

Commit a7b89c3

Browse files
committed
Fix crash in threadsRequest with no miDebugger, and undefined thread names
1 parent 596674f commit a7b89c3

File tree

3 files changed

+26
-7
lines changed

3 files changed

+26
-7
lines changed

src/backend/backend.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@ export interface Breakpoint {
1313

1414
export interface Thread {
1515
id: number;
16-
name: string;
16+
targetId: string;
17+
name?: string;
1718
}
1819

1920
export interface Stack {

src/backend/mi2/mi2.ts

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -598,12 +598,17 @@ export class MI2 extends EventEmitter implements IBackend {
598598
let threads = result.result("threads");
599599
let ret: Thread[] = [];
600600
return threads.map(element => {
601-
let id = parseInt(MINode.valueOf(element, "id"));
602-
let name = MINode.valueOf(element, "name") + "";
603-
return {
604-
id,
605-
name
601+
let ret : Thread = {
602+
id: parseInt(MINode.valueOf(element, "id")),
603+
targetId: MINode.valueOf(element, "target-id")
606604
};
605+
606+
let name = MINode.valueOf(element, "name");
607+
if (name) {
608+
ret.name = name;
609+
}
610+
611+
return ret;
607612
});
608613
}
609614

src/mibase.ts

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,8 @@ export class MI2DebugSession extends DebugSession {
235235
Promise.all(all).then(brkpoints => {
236236
let finalBrks = [];
237237
brkpoints.forEach(brkp => {
238+
// TODO: Currently all breakpoints returned are marked as verified,
239+
// which leads to verified breakpoints on a broken lldb.
238240
if (brkp[0])
239241
finalBrks.push(new DebugAdapter.Breakpoint(true, brkp[1].line));
240242
});
@@ -256,13 +258,24 @@ export class MI2DebugSession extends DebugSession {
256258
}
257259

258260
protected threadsRequest(response: DebugProtocol.ThreadsResponse): void {
261+
if (!this.miDebugger) {
262+
this.sendResponse(response);
263+
}
259264
this.miDebugger.getThreads().then(
260265
threads => {
261266
response.body = {
262267
threads: []
263268
};
264269
for (const thread of threads) {
265-
response.body.threads.push(new Thread(thread.id, thread.id + ":" + thread.name));
270+
let threadName = thread.name;
271+
// TODO: Thread names are undefined on LLDB
272+
if (threadName === undefined) {
273+
threadName = thread.targetId;
274+
}
275+
if (threadName === undefined) {
276+
threadName = "<unnamed>";
277+
}
278+
response.body.threads.push(new Thread(thread.id, thread.id + ":" + threadName));
266279
}
267280
this.sendResponse(response);
268281
});

0 commit comments

Comments
 (0)