Fix crash in threadsRequest with no miDebugger, and undefined thread names

This commit is contained in:
Leszek Swirski 2018-02-21 11:40:38 +00:00
commit a7b89c3569
3 changed files with 26 additions and 7 deletions

View file

@ -13,7 +13,8 @@ export interface Breakpoint {
export interface Thread { export interface Thread {
id: number; id: number;
name: string; targetId: string;
name?: string;
} }
export interface Stack { export interface Stack {

View file

@ -598,12 +598,17 @@ export class MI2 extends EventEmitter implements IBackend {
let threads = result.result("threads"); let threads = result.result("threads");
let ret: Thread[] = []; let ret: Thread[] = [];
return threads.map(element => { return threads.map(element => {
let id = parseInt(MINode.valueOf(element, "id")); let ret : Thread = {
let name = MINode.valueOf(element, "name") + ""; id: parseInt(MINode.valueOf(element, "id")),
return { targetId: MINode.valueOf(element, "target-id")
id,
name
}; };
let name = MINode.valueOf(element, "name");
if (name) {
ret.name = name;
}
return ret;
}); });
} }

View file

@ -235,6 +235,8 @@ export class MI2DebugSession extends DebugSession {
Promise.all(all).then(brkpoints => { Promise.all(all).then(brkpoints => {
let finalBrks = []; let finalBrks = [];
brkpoints.forEach(brkp => { brkpoints.forEach(brkp => {
// TODO: Currently all breakpoints returned are marked as verified,
// which leads to verified breakpoints on a broken lldb.
if (brkp[0]) if (brkp[0])
finalBrks.push(new DebugAdapter.Breakpoint(true, brkp[1].line)); finalBrks.push(new DebugAdapter.Breakpoint(true, brkp[1].line));
}); });
@ -256,13 +258,24 @@ export class MI2DebugSession extends DebugSession {
} }
protected threadsRequest(response: DebugProtocol.ThreadsResponse): void { protected threadsRequest(response: DebugProtocol.ThreadsResponse): void {
if (!this.miDebugger) {
this.sendResponse(response);
}
this.miDebugger.getThreads().then( this.miDebugger.getThreads().then(
threads => { threads => {
response.body = { response.body = {
threads: [] threads: []
}; };
for (const thread of threads) { for (const thread of threads) {
response.body.threads.push(new Thread(thread.id, thread.id + ":" + thread.name)); let threadName = thread.name;
// TODO: Thread names are undefined on LLDB
if (threadName === undefined) {
threadName = thread.targetId;
}
if (threadName === undefined) {
threadName = "<unnamed>";
}
response.body.threads.push(new Thread(thread.id, thread.id + ":" + threadName));
} }
this.sendResponse(response); this.sendResponse(response);
}); });