Commit 23b2fe3
authored
Debugging: allow frame cursor to visit all activations. (#12176)
* Debugging: allow frame cursor to visit all activations.
In the initial design for the `DebugFrameCursor`, I was concerned
about the effects of host async on the stability of visiting earlier
activations (see also the discussion of async combinators in #11896).
The basic hypothesized problem was that when Wasm calls host-code
calls Wasm, the sequence of activations on the stack is not even
stable between async polls; so any debugger hook, which is an async
function, should not be allowed to hold a frame cursor across a yield
point since it could become invalidated if the next poll stacks up the
activations differently.
In further conversations it's become clear that this is not actually a
possibility, for the simple reason that the inner re-entrant
activations into the same store take full ownership (mutably reborrow)
that store, and that mut reborrow becomes part of the future; so the
exact chain of activations will remain in the same sequence when
re-polled. Said another way, it is impossible at any given level of
async host-code to create *more than one* future that re-enters the
same store and somehow poll those in different orders at different
times. The worst that a host-code async combinator can do is drop the
future that re-enters the store. This drops and invalidates whatever
frames a cursor held over a yield might be referencing, but it *also*
drops the async invocation of the debugger hook itself, and due to
lifetimes the cursor cannot escape that hook, so everything is still
sound.
This PR thus updates the `DebugFrameCursor` to visit all
activations. I've generalized the backtrace code a bit to enable this,
and built an internal `StoreBacktrace` that is an iterator over all
activations associated with the store.
At the `DebugFrameCursor` (public API) level, the two basic choices
were to present a sentinel for host frame(s) explicitly and make all
Wasm-specific accessors return `Option<T>`, or skip over host
frames. I opted for the latter, with `move_to_parent()` returning an
enum value now that indicates whether it moved to a new activation.
A note regarding the *async* component ABI: once debugging is possible
within a `run_concurrent` environment, it will again be the case that
a single frame cursor should see only one activation, because
each (re)-entry into the store becomes a new task, if my understanding
is correct. At that time, we should build an API that lets the
debugger see the activation for each task separately. That's a simpler
model ultimately, and it will be nice when we move to it, but as long
as we have the sync component ABI with async host code and the ability
to stack activations as we do today, we need to provide the debugger
this visibility.
(Aside: why does the debugger *need* to see more than one activation?
In addition to presenting a weird and incoherent view of the world to
the user if we don't, it is also necessary to implement the
"next" (step-over) debugger action, because otherwise a call to a host
function that re-enters the store may lead to a state with fewer, but
completely disjoint, stack frames on the "one latest activation" from
which it's not possible to reason about whether we've left the
called-into function yet.)
* Review feedback.
* cargo fmt.1 parent dde1ada commit 23b2fe3
File tree
6 files changed
+414
-87
lines changed- crates/wasmtime/src/runtime
- vm
- traphandlers
- tests/all
6 files changed
+414
-87
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
6 | 6 | | |
7 | 7 | | |
8 | 8 | | |
9 | | - | |
| 9 | + | |
10 | 10 | | |
11 | 11 | | |
12 | 12 | | |
| |||
43 | 43 | | |
44 | 44 | | |
45 | 45 | | |
46 | | - | |
47 | | - | |
48 | | - | |
49 | | - | |
50 | | - | |
| 46 | + | |
51 | 47 | | |
52 | 48 | | |
53 | 49 | | |
| |||
90 | 86 | | |
91 | 87 | | |
92 | 88 | | |
93 | | - | |
| 89 | + | |
94 | 90 | | |
95 | 91 | | |
96 | 92 | | |
97 | 93 | | |
98 | 94 | | |
99 | 95 | | |
100 | | - | |
| 96 | + | |
101 | 97 | | |
102 | 98 | | |
103 | 99 | | |
| |||
120 | 116 | | |
121 | 117 | | |
122 | 118 | | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
123 | 131 | | |
124 | 132 | | |
125 | | - | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
126 | 138 | | |
127 | 139 | | |
128 | 140 | | |
| |||
133 | 145 | | |
134 | 146 | | |
135 | 147 | | |
| 148 | + | |
136 | 149 | | |
137 | | - | |
| 150 | + | |
138 | 151 | | |
139 | | - | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
140 | 169 | | |
141 | | - | |
142 | | - | |
143 | | - | |
144 | | - | |
145 | | - | |
146 | 170 | | |
147 | 171 | | |
148 | 172 | | |
149 | 173 | | |
150 | 174 | | |
151 | 175 | | |
| 176 | + | |
152 | 177 | | |
153 | 178 | | |
154 | 179 | | |
| |||
178 | 203 | | |
179 | 204 | | |
180 | 205 | | |
181 | | - | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
182 | 214 | | |
183 | 215 | | |
184 | 216 | | |
| |||
229 | 261 | | |
230 | 262 | | |
231 | 263 | | |
232 | | - | |
| 264 | + | |
233 | 265 | | |
234 | 266 | | |
235 | 267 | | |
| |||
246 | 278 | | |
247 | 279 | | |
248 | 280 | | |
249 | | - | |
| 281 | + | |
250 | 282 | | |
251 | 283 | | |
252 | 284 | | |
| |||
468 | 500 | | |
469 | 501 | | |
470 | 502 | | |
471 | | - | |
| 503 | + | |
472 | 504 | | |
473 | 505 | | |
474 | 506 | | |
475 | 507 | | |
476 | | - | |
| 508 | + | |
| 509 | + | |
| 510 | + | |
| 511 | + | |
477 | 512 | | |
478 | 513 | | |
479 | 514 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
33 | 33 | | |
34 | 34 | | |
35 | 35 | | |
36 | | - | |
| 36 | + | |
37 | 37 | | |
38 | 38 | | |
39 | 39 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1256 | 1256 | | |
1257 | 1257 | | |
1258 | 1258 | | |
1259 | | - | |
1260 | | - | |
1261 | | - | |
1262 | | - | |
1263 | | - | |
1264 | 1259 | | |
1265 | 1260 | | |
1266 | 1261 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
32 | 32 | | |
33 | 33 | | |
34 | 34 | | |
35 | | - | |
| 35 | + | |
36 | 36 | | |
37 | 37 | | |
38 | 38 | | |
| |||
0 commit comments