Skip to content

Commit e047ece

Browse files
Clement Skaucommit-bot@chromium.org
Clement Skau
authored andcommitted
[SDK] Fixes stack trace service API tests.
Fixes an issue where stack['asyncCausalFrames'] would be populated in if --lazy-async-stacks was set. The field should be filled iff the stack contains an async function - regardless of whether it's sync-async. Bug: #39525 Change-Id: Ia68f113402962c07a1e9a38ea9320b44140241e4 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/132820 Commit-Queue: Clement Skau <[email protected]> Reviewed-by: Martin Kustermann <[email protected]>
1 parent 52c535c commit e047ece

File tree

5 files changed

+20
-15
lines changed

5 files changed

+20
-15
lines changed

runtime/observatory/tests/service/causal_async_stack_contents_test.dart

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,7 @@ var tests = <IsolateTest>[
3838
(Isolate isolate) async {
3939
ServiceMap stack = await isolate.getStack();
4040
// No causal frames because we are in a completely synchronous stack.
41-
if (useCausalAsyncStacks) {
42-
expect(stack['asyncCausalFrames'], isNull);
43-
} else {
44-
// TODO(dartbug.com/37668): Implement suport for this in the debugger.
45-
expect(stack['asyncCausalFrames'], isNotNull);
46-
}
41+
expect(stack['asyncCausalFrames'], isNull);
4742
},
4843
resumeIsolate,
4944
hasStoppedAtBreakpoint,

runtime/observatory/tests/service/causal_async_stack_presence_test.dart

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,7 @@ var tests = <IsolateTest>[
3636
(Isolate isolate) async {
3737
ServiceMap stack = await isolate.getStack();
3838
// No causal frames because we are in a completely synchronous stack.
39-
if (useCausalAsyncStacks) {
40-
expect(stack['asyncCausalFrames'], isNull);
41-
} else {
42-
// TODO(dartbug.com/37668): Implement suport for this in the debugger.
43-
expect(stack['asyncCausalFrames'], isNotNull);
44-
}
39+
expect(stack['asyncCausalFrames'], isNull);
4540
},
4641
resumeIsolate,
4742
hasStoppedAtBreakpoint,

runtime/vm/debugger.cc

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2348,8 +2348,14 @@ DebuggerStackTrace* Debugger::CollectAsyncLazyStackTrace() {
23482348
zone, GrowableObjectArray::New(kDefaultStackAllocation));
23492349
const auto& pc_offset_array = GrowableObjectArray::ZoneHandle(
23502350
zone, GrowableObjectArray::New(kDefaultStackAllocation));
2351+
bool has_async = false;
23512352
StackTraceUtils::CollectFramesLazy(thread, code_array, pc_offset_array,
2352-
/*skip_frames=*/0, &on_sync_frame);
2353+
/*skip_frames=*/0, &on_sync_frame,
2354+
&has_async);
2355+
2356+
if (!has_async) {
2357+
return nullptr;
2358+
}
23532359

23542360
const intptr_t length = code_array.Length();
23552361
for (intptr_t i = stack_trace->Length(); i < length; ++i) {

runtime/vm/stack_trace.cc

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -309,7 +309,11 @@ void StackTraceUtils::CollectFramesLazy(
309309
const GrowableObjectArray& code_array,
310310
const GrowableObjectArray& pc_offset_array,
311311
int skip_frames,
312-
std::function<void(StackFrame*)>* on_sync_frames) {
312+
std::function<void(StackFrame*)>* on_sync_frames,
313+
bool* has_async) {
314+
if (has_async != nullptr) {
315+
*has_async = false;
316+
}
313317
Zone* zone = thread->zone();
314318
DartFrameIterator frames(thread, StackFrameIterator::kNoCrossThreadIteration);
315319
StackFrame* frame = frames.NextFrame();
@@ -363,6 +367,10 @@ void StackTraceUtils::CollectFramesLazy(
363367
// Either continue the loop (sync-async case) or find all await'ers and
364368
// return.
365369
if (function.IsAsyncClosure() || function.IsAsyncGenClosure()) {
370+
if (has_async != nullptr) {
371+
*has_async = true;
372+
}
373+
366374
// Next, look up caller's closure on the stack and walk backwards through
367375
// the yields.
368376
frame = frames.NextFrame();

runtime/vm/stack_trace.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,8 @@ class StackTraceUtils : public AllStatic {
3737
const GrowableObjectArray& code_array,
3838
const GrowableObjectArray& pc_offset_array,
3939
int skip_frames,
40-
std::function<void(StackFrame*)>* on_sync_frames = nullptr);
40+
std::function<void(StackFrame*)>* on_sync_frames = nullptr,
41+
bool* has_async = nullptr);
4142

4243
/// Counts the number of stack frames.
4344
/// Skips over the first |skip_frames|.

0 commit comments

Comments
 (0)