Skip to content

Commit 35fb237

Browse files
committed
[vm/bytecode] Properly handle non-live bytecode frames in debugger.
Change-Id: I30db495fbda03a983f21dc45d27c57c5cb35f162 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/110139 Commit-Queue: Régis Crelier <[email protected]> Reviewed-by: Alexander Markov <[email protected]>
1 parent 3e3d647 commit 35fb237

File tree

4 files changed

+49
-45
lines changed

4 files changed

+49
-45
lines changed

runtime/vm/debugger.cc

Lines changed: 35 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -264,6 +264,7 @@ ActivationFrame::ActivationFrame(Kind kind)
264264
token_pos_initialized_(false),
265265
token_pos_(TokenPosition::kNoSource),
266266
try_index_(-1),
267+
deopt_id_(DeoptId::kNone),
267268
line_number_(-1),
268269
column_number_(-1),
269270
context_level_(-1),
@@ -287,6 +288,7 @@ ActivationFrame::ActivationFrame(const Closure& async_activation)
287288
token_pos_initialized_(false),
288289
token_pos_(TokenPosition::kNoSource),
289290
try_index_(-1),
291+
deopt_id_(DeoptId::kNone),
290292
line_number_(-1),
291293
column_number_(-1),
292294
context_level_(-1),
@@ -769,6 +771,7 @@ void ActivationFrame::PrintDescriptorsError(const char* message) {
769771
// Calculate the context level at the current bytecode pc or code deopt id
770772
// of the frame.
771773
intptr_t ActivationFrame::ContextLevel() {
774+
ASSERT(live_frame_);
772775
const Context& ctx = GetSavedCurrentContext();
773776
if (context_level_ < 0 && !ctx.IsNull()) {
774777
ASSERT(IsInterpreted() || !code_.is_optimized());
@@ -805,27 +808,6 @@ intptr_t ActivationFrame::ContextLevel() {
805808
}
806809
}
807810
}
808-
if (context_level_ < 0 && function().IsClosureFunction()) {
809-
// Obtain the context level from the parent function.
810-
// TODO(alexmarkov): Define scope which includes the whole closure body.
811-
Function& parent = Function::Handle(zone, function().parent_function());
812-
do {
813-
bytecode = parent.bytecode();
814-
kernel::BytecodeLocalVariablesIterator local_vars(zone, bytecode);
815-
while (local_vars.MoveNext()) {
816-
if (local_vars.Kind() ==
817-
kernel::BytecodeLocalVariablesIterator::kScope) {
818-
if (local_vars.StartTokenPos() <= TokenPos() &&
819-
TokenPos() <= local_vars.EndTokenPos()) {
820-
ASSERT(context_level_ <= local_vars.ContextLevel());
821-
context_level_ = local_vars.ContextLevel();
822-
}
823-
}
824-
}
825-
if (context_level_ >= 0) break;
826-
parent = parent.parent_function();
827-
} while (!parent.IsNull());
828-
}
829811
if (context_level_ < 0) {
830812
PrintDescriptorsError("Missing context level in local variables info");
831813
}
@@ -883,9 +865,14 @@ RawObject* ActivationFrame::GetAsyncContextVariable(const String& name) {
883865
ASSERT(kind == RawLocalVarDescriptors::kContextVar);
884866
if (!live_frame_) {
885867
ASSERT(!ctx_.IsNull());
868+
// Compiled code uses relative context levels, i.e. the frame context
869+
// level is always 0 on entry.
870+
// Bytecode uses absolute context levels, i.e. the frame context level
871+
// on entry must be calculated.
872+
const intptr_t frame_ctx_level =
873+
IsInterpreted() ? ctx_.GetLevel() : 0;
886874
return GetRelativeContextVar(var_info.scope_id,
887-
variable_index.value(),
888-
/* frame_ctx_level = */ 0);
875+
variable_index.value(), frame_ctx_level);
889876
}
890877
return GetContextVar(var_info.scope_id, variable_index.value());
891878
}
@@ -1605,20 +1592,31 @@ const char* ActivationFrame::ToCString() {
16051592
const String& url = String::Handle(SourceUrl());
16061593
intptr_t line = LineNumber();
16071594
const char* func_name = Debugger::QualifiedFunctionName(function());
1608-
return Thread::Current()->zone()->PrintToString(
1609-
"[ Frame pc(0x%" Px " offset:0x%" Px ") fp(0x%" Px ") sp(0x%" Px
1610-
")\n"
1611-
"\tfunction = %s\n"
1612-
"\turl = %s\n"
1613-
"\tline = %" Pd
1614-
"\n"
1615-
"\tcontext = %s\n"
1616-
"\tcontext level = %" Pd " ]\n",
1617-
pc(),
1618-
pc() -
1619-
(IsInterpreted() ? bytecode().PayloadStart() : code().PayloadStart()),
1620-
fp(), sp(), func_name, url.ToCString(), line, ctx_.ToCString(),
1621-
ContextLevel());
1595+
if (live_frame_) {
1596+
return Thread::Current()->zone()->PrintToString(
1597+
"[ Frame pc(0x%" Px " %s offset:0x%" Px ") fp(0x%" Px ") sp(0x%" Px
1598+
")\n"
1599+
"\tfunction = %s\n"
1600+
"\turl = %s\n"
1601+
"\tline = %" Pd
1602+
"\n"
1603+
"\tcontext = %s\n"
1604+
"\tcontext level = %" Pd " ]\n",
1605+
pc(), IsInterpreted() ? "bytecode" : "code",
1606+
pc() - (IsInterpreted() ? bytecode().PayloadStart()
1607+
: code().PayloadStart()),
1608+
fp(), sp(), func_name, url.ToCString(), line, ctx_.ToCString(),
1609+
ContextLevel());
1610+
} else {
1611+
return Thread::Current()->zone()->PrintToString(
1612+
"[ Frame %s function = %s\n"
1613+
"\turl = %s\n"
1614+
"\tline = %" Pd
1615+
"\n"
1616+
"\tcontext = %s\n",
1617+
IsInterpreted() ? "bytecode" : "code", func_name, url.ToCString(), line,
1618+
ctx_.ToCString());
1619+
}
16221620
}
16231621

16241622
void ActivationFrame::PrintToJSONObject(JSONObject* jsobj) {
@@ -2126,8 +2124,6 @@ ActivationFrame* Debugger::CollectDartFrame(Isolate* isolate,
21262124
if (FLAG_trace_debugger_stacktrace) {
21272125
const Context& ctx = activation->GetSavedCurrentContext();
21282126
OS::PrintErr("\tUsing saved context: %s\n", ctx.ToCString());
2129-
}
2130-
if (FLAG_trace_debugger_stacktrace) {
21312127
OS::PrintErr("\tLine number: %" Pd "\n", activation->LineNumber());
21322128
}
21332129
return activation;
@@ -2145,8 +2141,6 @@ ActivationFrame* Debugger::CollectDartFrame(Isolate* isolate,
21452141
if (FLAG_trace_debugger_stacktrace) {
21462142
const Context& ctx = activation->GetSavedCurrentContext();
21472143
OS::PrintErr("\tUsing saved context: %s\n", ctx.ToCString());
2148-
}
2149-
if (FLAG_trace_debugger_stacktrace) {
21502144
OS::PrintErr("\tLine number: %" Pd "\n", activation->LineNumber());
21512145
}
21522146
return activation;

runtime/vm/object.cc

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15536,6 +15536,16 @@ RawLocalVarDescriptors* Bytecode::GetLocalVarDescriptors() const {
1553615536
#endif
1553715537
}
1553815538

15539+
intptr_t Context::GetLevel() const {
15540+
intptr_t level = 0;
15541+
Context& parent_ctx = Context::Handle(parent());
15542+
while (!parent_ctx.IsNull()) {
15543+
level++;
15544+
parent_ctx = parent_ctx.parent();
15545+
}
15546+
return level;
15547+
}
15548+
1553915549
RawContext* Context::New(intptr_t num_variables, Heap::Space space) {
1554015550
ASSERT(num_variables >= 0);
1554115551
ASSERT(Object::context_class() != Class::null());

runtime/vm/object.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5852,6 +5852,8 @@ class Context : public Object {
58525852
}
58535853
inline void SetAt(intptr_t context_index, const Object& value) const;
58545854

5855+
intptr_t GetLevel() const;
5856+
58555857
void Dump(int indent = 0) const;
58565858

58575859
static const intptr_t kBytesPerElement = kWordSize;

runtime/vm/runtime_entry.cc

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2136,9 +2136,7 @@ static void HandleStackOverflowTestCases(Thread* thread) {
21362136
// Ensure that we have unoptimized code.
21372137
frame->function().EnsureHasCompiledUnoptimizedCode();
21382138
}
2139-
// TODO(regis): Provide var descriptors in kernel bytecode.
2140-
const int num_vars =
2141-
frame->IsInterpreted() ? 0 : frame->NumLocalVariables();
2139+
const int num_vars = frame->NumLocalVariables();
21422140
#else
21432141
// Variable locations and number are unknown when precompiling.
21442142
const int num_vars = 0;
@@ -2149,7 +2147,7 @@ static void HandleStackOverflowTestCases(Thread* thread) {
21492147
}
21502148
}
21512149
if (FLAG_stress_async_stacks) {
2152-
Debugger::CollectAwaiterReturnStackTrace();
2150+
isolate->debugger()->CollectAwaiterReturnStackTrace();
21532151
}
21542152
FLAG_stacktrace_every = saved_stacktrace_every;
21552153
}

0 commit comments

Comments
 (0)