Skip to content

Commit aca4dc7

Browse files
jasonLasterbomsy
authored andcommitted
suppress resumed events while interrupted (firefox-devtools#4972)
1 parent f44c740 commit aca4dc7

2 files changed

Lines changed: 63 additions & 0 deletions

File tree

src/client/README.md

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
# Debugger Client
2+
3+
The Debugger client is responsible for managing the communication between the
4+
client application and JS server.
5+
6+
* When the server sends a notification to the client, the client receives an
7+
"event" and notifies the application via redux actions.
8+
* When the application, wants to send a command to the server, it invokes
9+
"commands" in the client.
10+
11+
The Debugger supports a Firefox and a Chrome client, which lets it attach and
12+
debug Firefox, Chrome, and Node contexts. The clients are defined in
13+
`src/client` and have an `onConnect` function, and a `commands` and `events`
14+
module.
15+
16+
Both clients implement client adapters for translating commands and events into
17+
JSON packets. The chrome client debugger adapter is defined in
18+
[chrome-remote-interface][chrome-remote-interface]. The Firefox client adapters
19+
are defined in two places:
20+
21+
* The launchpad client adapter is maintained in the package
22+
[devtools-connection][dt-connect].
23+
* The panel client adapter is maintained in
24+
[devtools-client.js][devtools-client.js].
25+
26+
## Firefox
27+
28+
### Remote Debugger Protocol
29+
30+
The [Remote Debugger Protocol][protocol] specifies the client / server API.
31+
32+
### Interrupt
33+
34+
When the client wants to add a breakpoint, it avoids race conditions by doing
35+
temporary pauses called interrupts.
36+
37+
We want to do these interrupts transparently, so we've decided that the client
38+
should not notify the application that the thread has been paused or resumed.
39+
40+
[protocol]: https://searchfox.org/mozilla-central/source/devtools/docs/backend/protocol.md
41+
[dt-connect]: https://github.com/devtools-html/devtools-core/tree/master/packages/devtools-connection
42+
[devtools-client.js]: https://searchfox.org/mozilla-central/source/devtools/shared/client/debugger-client.js
43+
44+
## Chrome
45+
46+
### Chrome Debugger Protocol
47+
48+
The chrome debugger protocol is available [here][devtools-protocol-viewer]. And
49+
is maintained in the devtools-protocol [repo][devtools-protocol-gh].
50+
51+
[chrome-remote-interface]: https://github.com/cyrus-and/chrome-remote-interface
52+
[devtools-protocol-viewer]: https://chromedevtools.github.io/devtools-protocol/
53+
[devtools-protocol-gh]: https://github.com/ChromeDevTools/devtools-protocol

src/client/firefox/events.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ type Dependencies = {
2727
let threadClient: ThreadClient;
2828
let actions: Actions;
2929
let supportsWasm: boolean;
30+
let isInterrupted: boolean;
3031

3132
function setupEvents(dependencies: Dependencies) {
3233
threadClient = dependencies.threadClient;
@@ -47,6 +48,7 @@ async function paused(_: "paused", packet: PausedPacket) {
4748
// breakpoints, ignore the event.
4849
const { why } = packet;
4950
if (why.type === "interrupted" && !packet.why.onNext) {
51+
isInterrupted = true;
5052
return;
5153
}
5254

@@ -61,6 +63,14 @@ async function paused(_: "paused", packet: PausedPacket) {
6163
}
6264

6365
function resumed(_: "resumed", packet: ResumedPacket) {
66+
// NOTE: the client suppresses resumed events while interrupted
67+
// to prevent unintentional behavior.
68+
// see [client docs](../README.md#interrupted) for more information.
69+
if (isInterrupted) {
70+
isInterrupted = false;
71+
return;
72+
}
73+
6474
actions.resumed(packet);
6575
}
6676

0 commit comments

Comments
 (0)