Skip to content

Conversation

@delan
Copy link
Member

@delan delan commented Jun 24, 2025

devtools clients query source actors to determine where the user can set breakpoints in a source. there are two relevant requests here: getBreakableLines controls which line numbers can be clicked in the margin, and once a line number is clicked, getBreakpointPositionsCompressed controls where to show breakpoint buttons within that line.

this patch handles those requests by querying the SpiderMonkey Debugger API for that information:

  • devtools sends its script thread a GetPossibleBreakpoints message for the source’s spidermonkey_id
  • the script thread fires a getPossibleBreakpoints event into its debugger global
  • the debugger script looks up the root Debugger.Script for that source, calls getPossibleBreakpoints(), and returns the result via DebuggerGlobalScope#getPossibleBreakpointsResult()
  • that method takes the pending result sender, and sends the result back to devtools
  • devtools massages the result into the format required by the request, and replies to the client

as a result, users of the Firefox devtools client can now set breakpoints, though they don’t have any effect.

Testing: this patch adds new devtools tests
Fixes: part of #36027

image

@delan delan force-pushed the devtools-set-breakpoint branch 3 times, most recently from 3cbf9c7 to 3ef1980 Compare June 25, 2025 00:52
@delan delan force-pushed the devtools-set-breakpoint branch 8 times, most recently from 84aca55 to a9ec9e5 Compare July 23, 2025 09:05
@delan delan force-pushed the devtools-set-breakpoint branch 2 times, most recently from 5067308 to 9844f5a Compare July 23, 2025 11:27
github-merge-queue bot pushed a commit that referenced this pull request Jul 23, 2025
…8236)

to use the [SpiderMonkey Debugger
API](https://firefox-source-docs.mozilla.org/js/Debugger/), we need to
call it from an internal debugger script that we will supply. this
script must run in the same runtime as the debuggee(s), but in a
separate
[compartment](https://udn.realityripple.com/docs/Mozilla/Projects/SpiderMonkey/Compartments)
([more
details](https://hacks.mozilla.org/2020/03/future-proofing-firefoxs-javascript-debugger-implementation/)).

when creating two globals in the same runtime, Servo will generally try
to reuse an existing compartment for the second global, and there are
other places in script where we rely on this reuse. but for the debugger
script, we can’t do this.

this patch adds a `use_system_compartment` flag to global object
descriptors, which isolates the global in its own compartment in both
possible directions:
- it forces the global to create a new compartment, preventing the reuse
of any debuggee’s compartment
- it fails the check in select_compartment(), preventing future
debuggees from reusing the global’s compartment

Testing: manually tested working in devtools debugger patch (#37667),
where it will undergo automated tests

---------

Signed-off-by: Delan Azabani <dazabani@igalia.com>
Co-authored-by: atbrakhi <atbrakhi@igalia.com>
@delan delan changed the title Devtools: set breakpoints devtools: set breakpoints Jul 25, 2025
@delan delan changed the title devtools: set breakpoints devtools: Set breakpoints Jul 25, 2025
github-merge-queue bot pushed a commit that referenced this pull request Jul 28, 2025
in the [SpiderMonkey Debugger
API](https://firefox-source-docs.mozilla.org/js/Debugger/), hooks like
[onNewGlobalObject()](https://firefox-source-docs.mozilla.org/js/Debugger/Debugger.html#onnewglobalobject-global)
use an AutoDebuggerJobQueueInterruption to [switch to a new microtask
queue](https://github.com/servo/mozjs/blob/b14aebff23ac4d5b0652060ef949334bda08b22f/mozjs-sys/mozjs/js/src/debugger/Debugger.cpp#L2834-L2841)
and avoid clobbering the debuggee’s microtask queue. this in turn relies
on JobQueue::saveJobQueue(), which is [not yet implemented in
RustJobQueue](https://github.com/servo/mozjs/blob/b14aebff23ac4d5b0652060ef949334bda08b22f/mozjs-sys/src/jsglue.cpp#L83-L86).

this patch bumps mozjs to servo/mozjs#595, which implements
[saveJobQueue() and
SavedJobQueue](https://github.com/servo/mozjs/blob/b14aebff23ac4d5b0652060ef949334bda08b22f/mozjs-sys/mozjs/js/public/Promise.h#L92-L114)
for RustJobQueue by calling into Servo via two new JobQueueTraps that
create and destroy extra “interrupt” queues for use by the debugger.

SpiderMonkey [does not own external job
queues](https://github.com/servo/mozjs/blob/b14aebff23ac4d5b0652060ef949334bda08b22f/mozjs-sys/mozjs/js/public/Promise.h#L117-L123),
so the lifetime of these queues is managed in Servo, where they are
stored in a Vec-based stack. stack-like behaviour is adequate for
SpiderMonkey’s save and restore patterns, as far as we can tell, but
we’ve added an assertion just in case.

Testing: manually tested working in devtools debugger patch (#37667),
where it will undergo automated tests
Fixes: #38311

---------

Signed-off-by: Delan Azabani <dazabani@igalia.com>
Co-authored-by: atbrakhi <atbrakhi@igalia.com>
abdelrahman1234567 pushed a commit to abdelrahman1234567/servo that referenced this pull request Jul 28, 2025
in the [SpiderMonkey Debugger
API](https://firefox-source-docs.mozilla.org/js/Debugger/), hooks like
[onNewGlobalObject()](https://firefox-source-docs.mozilla.org/js/Debugger/Debugger.html#onnewglobalobject-global)
use an AutoDebuggerJobQueueInterruption to [switch to a new microtask
queue](https://github.com/servo/mozjs/blob/b14aebff23ac4d5b0652060ef949334bda08b22f/mozjs-sys/mozjs/js/src/debugger/Debugger.cpp#L2834-L2841)
and avoid clobbering the debuggee’s microtask queue. this in turn relies
on JobQueue::saveJobQueue(), which is [not yet implemented in
RustJobQueue](https://github.com/servo/mozjs/blob/b14aebff23ac4d5b0652060ef949334bda08b22f/mozjs-sys/src/jsglue.cpp#L83-L86).

this patch bumps mozjs to servo/mozjs#595, which implements
[saveJobQueue() and
SavedJobQueue](https://github.com/servo/mozjs/blob/b14aebff23ac4d5b0652060ef949334bda08b22f/mozjs-sys/mozjs/js/public/Promise.h#L92-L114)
for RustJobQueue by calling into Servo via two new JobQueueTraps that
create and destroy extra “interrupt” queues for use by the debugger.

SpiderMonkey [does not own external job
queues](https://github.com/servo/mozjs/blob/b14aebff23ac4d5b0652060ef949334bda08b22f/mozjs-sys/mozjs/js/public/Promise.h#L117-L123),
so the lifetime of these queues is managed in Servo, where they are
stored in a Vec-based stack. stack-like behaviour is adequate for
SpiderMonkey’s save and restore patterns, as far as we can tell, but
we’ve added an assertion just in case.

Testing: manually tested working in devtools debugger patch (servo#37667),
where it will undergo automated tests
Fixes: servo#38311

---------

Signed-off-by: Delan Azabani <dazabani@igalia.com>
Co-authored-by: atbrakhi <atbrakhi@igalia.com>
@delan delan force-pushed the devtools-set-breakpoint branch 2 times, most recently from d2bbe18 to a0be1d7 Compare July 29, 2025 10:23
github-merge-queue bot pushed a commit that referenced this pull request Jul 29, 2025
…38330)

This is allowed by the [protocol
docs](https://firefox-source-docs.mozilla.org/devtools/backend/protocol.html#loading-script-sources),
and eliminates an unwrap().

Testing: does not get exercised yet, but will be used in #37667 
Fixes: part of #36027

Signed-off-by: Delan Azabani <dazabani@igalia.com>
Co-authored-by: Delan Azabani <dazabani@igalia.com>
@delan delan force-pushed the devtools-set-breakpoint branch from b4c5e98 to aad368f Compare July 29, 2025 12:17
github-merge-queue bot pushed a commit that referenced this pull request Jul 31, 2025
in the [SpiderMonkey Debugger
API](https://firefox-source-docs.mozilla.org/js/Debugger/), hooks like
[onNewGlobalObject()](https://firefox-source-docs.mozilla.org/js/Debugger/Debugger.html#onnewglobalobject-global)
use an AutoDebuggerJobQueueInterruption to [switch to a new microtask
queue](https://github.com/servo/mozjs/blob/b14aebff23ac4d5b0652060ef949334bda08b22f/mozjs-sys/mozjs/js/src/debugger/Debugger.cpp#L2834-L2841)
and avoid clobbering the debuggee’s microtask queue. this in turn relies
on JobQueue::runJobs(), which is [not yet implemented in
RustJobQueue](https://github.com/servo/mozjs/blob/b14aebff23ac4d5b0652060ef949334bda08b22f/mozjs-sys/src/jsglue.cpp#L76-L78).

this patch bumps mozjs to servo/mozjs#597, which implements
[runJobs()](https://github.com/servo/mozjs/blob/b14aebff23ac4d5b0652060ef949334bda08b22f/mozjs-sys/mozjs/js/public/Promise.h#L61-L76)
for RustJobQueue by calling into Servo’s MicrotaskQueue::checkpoint()
via a new function in JobQueueTraps.

SpiderMonkey [does not own external job
queues](https://github.com/servo/mozjs/blob/b14aebff23ac4d5b0652060ef949334bda08b22f/mozjs-sys/mozjs/js/public/Promise.h#L117-L123),
so the lifetime of these queues is managed in Servo, where they are
stored in a Vec-based stack. stack-like behaviour is adequate for
SpiderMonkey’s save and restore patterns, as far as we can tell, but
we’ve added an assertion just in case.

Testing: manually tested working in devtools debugger patch (#37667),
where it will undergo automated tests

Signed-off-by: Delan Azabani <dazabani@igalia.com>
Co-authored-by: atbrakhi <atbrakhi@igalia.com>
@delan delan force-pushed the devtools-set-breakpoint branch 4 times, most recently from 385f8e1 to 5f6a0ee Compare August 11, 2025 08:36
delan and others added 4 commits August 11, 2025 17:01
Co-authored-by: atbrakhi <atbrakhi@igalia.com>
Signed-off-by: Delan Azabani <dazabani@igalia.com>
Co-authored-by: atbrakhi <atbrakhi@igalia.com>
Signed-off-by: Delan Azabani <dazabani@igalia.com>
Co-authored-by: atbrakhi <atbrakhi@igalia.com>
Signed-off-by: Delan Azabani <dazabani@igalia.com>
Co-authored-by: atbrakhi <atbrakhi@igalia.com>
Signed-off-by: Delan Azabani <dazabani@igalia.com>
@delan delan force-pushed the devtools-set-breakpoint branch from caa9754 to 4a1fbaf Compare August 11, 2025 09:05
@delan delan changed the title devtools: Set breakpoints devtools: Show clients where they can set breakpoints Aug 11, 2025
@delan delan requested review from jdm and sagudev August 11, 2025 09:29
@delan delan marked this pull request as ready for review August 11, 2025 09:29
@delan delan requested a review from gterzian as a code owner August 11, 2025 09:29
Signed-off-by: Delan Azabani <dazabani@igalia.com>
@delan delan force-pushed the devtools-set-breakpoint branch from 4a1fbaf to 91f6dc1 Compare August 11, 2025 09:42
Copy link
Member

@jdm jdm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice work! I appreciate the new unit test, too.

delan added 2 commits August 12, 2025 10:39
Signed-off-by: Delan Azabani <dazabani@igalia.com>
Signed-off-by: Delan Azabani <dazabani@igalia.com>
@delan delan force-pushed the devtools-set-breakpoint branch from 2ca0955 to 79edffd Compare August 12, 2025 02:40
@delan delan enabled auto-merge August 12, 2025 02:41
@delan delan added this pull request to the merge queue Aug 12, 2025
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Aug 12, 2025
@delan delan added this pull request to the merge queue Aug 12, 2025
delan added a commit that referenced this pull request Aug 12, 2025
Co-authored-by: atbrakhi <atbrakhi@igalia.com>
Signed-off-by: Delan Azabani <dazabani@igalia.com>
Merged via the queue into main with commit f5b631e Aug 12, 2025
21 checks passed
@delan delan deleted the devtools-set-breakpoint branch August 12, 2025 06:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants