Add threads request to debugger

Summary:
Release note: none

- let UI send threads request
- adapter returns information about the one thread
Closes https://github.com/facebook/prepack/pull/1130

Differential Revision: D6227708

Pulled By: JWZ2018

fbshipit-source-id: 40a14f786842dec01491c03eee49a41a15af98cd
This commit is contained in:
Wuhan Zhou 2017-11-02 17:16:56 -07:00 committed by Facebook Github Bot
parent e63daa5585
commit bd9d49d618
2 changed files with 35 additions and 2 deletions

View File

@ -197,6 +197,18 @@ class PrepackDebugSession extends LoggingDebugSession {
this.sendResponse(response);
});
}
threadsRequest(response: DebugProtocol.ThreadsResponse): void {
// There will only be 1 thread, so respond immediately
let thread: DebugProtocol.Thread = {
id: DebuggerConstants.PREPACK_THREAD_ID,
name: "main",
};
response.body = {
threads: [thread],
};
this.sendResponse(response);
}
}
DebugSession.run(PrepackDebugSession);

View File

@ -129,8 +129,15 @@ export class UISession {
}
_processResponse(response: DebugProtocol.Response) {
// to be implemented
console.log(response);
if (response.command === "threads") {
this._processThreadsResponse(((response: any): DebugProtocol.ThreadsResponse));
}
}
_processThreadsResponse(response: DebugProtocol.ThreadsResponse) {
for (const thread of response.body.threads) {
this._uiOutput(`${thread.id}: ${thread.name}`);
}
}
// execute a command if it is valid
@ -167,6 +174,10 @@ export class UISession {
this._sendBreakpointRequest(filePath, line, column);
}
break;
case "threads":
if (parts.length !== 1) return false;
this._sendThreadsRequest();
break;
default:
// invalid command
return false;
@ -256,6 +267,16 @@ export class UISession {
this._packageAndSend(json);
}
_sendThreadsRequest() {
let message = {
type: "request",
seq: this._sequenceNum,
command: "threads",
};
let json = JSON.stringify(message);
this._packageAndSend(json);
}
// write out a message to the adapter on stdout
_packageAndSend(message: string) {
// format: Content-Length: <length> separator <message>