@@ -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.
771773intptr_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- " \t function = %s\n "
1612- " \t url = %s\n "
1613- " \t line = %" Pd
1614- " \n "
1615- " \t context = %s\n "
1616- " \t context 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+ " \t function = %s\n "
1600+ " \t url = %s\n "
1601+ " \t line = %" Pd
1602+ " \n "
1603+ " \t context = %s\n "
1604+ " \t context 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+ " \t url = %s\n "
1614+ " \t line = %" Pd
1615+ " \n "
1616+ " \t context = %s\n " ,
1617+ IsInterpreted () ? " bytecode" : " code" , func_name, url.ToCString (), line,
1618+ ctx_.ToCString ());
1619+ }
16221620}
16231621
16241622void 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 (" \t Using saved context: %s\n " , ctx.ToCString ());
2129- }
2130- if (FLAG_trace_debugger_stacktrace) {
21312127 OS::PrintErr (" \t Line 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 (" \t Using saved context: %s\n " , ctx.ToCString ());
2148- }
2149- if (FLAG_trace_debugger_stacktrace) {
21502144 OS::PrintErr (" \t Line number: %" Pd " \n " , activation->LineNumber ());
21512145 }
21522146 return activation;
0 commit comments