Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(568)

Side by Side Diff: runtime/vm/debugger.cc

Issue 2419013004: Add local variable declaration token position to service protocol (Closed)
Patch Set: test closure variables Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 #include "vm/debugger.h" 5 #include "vm/debugger.h"
6 6
7 #include "include/dart_api.h" 7 #include "include/dart_api.h"
8 8
9 #include "vm/code_generator.h" 9 #include "vm/code_generator.h"
10 #include "vm/code_patcher.h" 10 #include "vm/code_patcher.h"
(...skipping 878 matching lines...) Expand 10 before | Expand all | Expand 10 after
889 intptr_t num = 0; 889 intptr_t num = 0;
890 while ((frame != NULL)) { 890 while ((frame != NULL)) {
891 OS::PrintErr("#%04" Pd " %s\n", num++, frame->ToCString()); 891 OS::PrintErr("#%04" Pd " %s\n", num++, frame->ToCString());
892 frame = iterator.NextFrame(); 892 frame = iterator.NextFrame();
893 } 893 }
894 } 894 }
895 895
896 896
897 void ActivationFrame::VariableAt(intptr_t i, 897 void ActivationFrame::VariableAt(intptr_t i,
898 String* name, 898 String* name,
899 TokenPosition* token_pos, 899 TokenPosition* declaration_token_pos,
900 TokenPosition* end_pos, 900 TokenPosition* visible_start_token_pos,
901 TokenPosition* visible_end_token_pos,
901 Object* value) { 902 Object* value) {
902 GetDescIndices(); 903 GetDescIndices();
903 ASSERT(i < desc_indices_.length()); 904 ASSERT(i < desc_indices_.length());
904 intptr_t desc_index = desc_indices_[i]; 905 intptr_t desc_index = desc_indices_[i];
905 ASSERT(name != NULL); 906 ASSERT(name != NULL);
906 907
907 *name = var_descriptors_.GetName(desc_index); 908 *name = var_descriptors_.GetName(desc_index);
908 909
909 RawLocalVarDescriptors::VarInfo var_info; 910 RawLocalVarDescriptors::VarInfo var_info;
910 var_descriptors_.GetInfo(desc_index, &var_info); 911 var_descriptors_.GetInfo(desc_index, &var_info);
911 ASSERT(token_pos != NULL); 912 ASSERT(declaration_token_pos != NULL);
912 *token_pos = var_info.begin_pos; 913 *declaration_token_pos = var_info.declaration_pos;
913 ASSERT(end_pos != NULL); 914 ASSERT(visible_start_token_pos != NULL);
914 *end_pos = var_info.end_pos; 915 *visible_start_token_pos = var_info.begin_pos;
916 ASSERT(visible_end_token_pos != NULL);
917 *visible_end_token_pos = var_info.end_pos;
915 ASSERT(value != NULL); 918 ASSERT(value != NULL);
916 const int8_t kind = var_info.kind(); 919 const int8_t kind = var_info.kind();
917 if (kind == RawLocalVarDescriptors::kStackVar) { 920 if (kind == RawLocalVarDescriptors::kStackVar) {
918 *value = GetStackVar(var_info.index()); 921 *value = GetStackVar(var_info.index());
919 } else { 922 } else {
920 ASSERT(kind == RawLocalVarDescriptors::kContextVar); 923 ASSERT(kind == RawLocalVarDescriptors::kContextVar);
921 *value = GetContextVar(var_info.scope_id, var_info.index()); 924 *value = GetContextVar(var_info.scope_id, var_info.index());
922 } 925 }
923 } 926 }
924 927
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
959 962
960 963
961 RawArray* ActivationFrame::GetLocalVariables() { 964 RawArray* ActivationFrame::GetLocalVariables() {
962 GetDescIndices(); 965 GetDescIndices();
963 intptr_t num_variables = desc_indices_.length(); 966 intptr_t num_variables = desc_indices_.length();
964 String& var_name = String::Handle(); 967 String& var_name = String::Handle();
965 Object& value = Instance::Handle(); 968 Object& value = Instance::Handle();
966 const Array& list = Array::Handle(Array::New(2 * num_variables)); 969 const Array& list = Array::Handle(Array::New(2 * num_variables));
967 for (intptr_t i = 0; i < num_variables; i++) { 970 for (intptr_t i = 0; i < num_variables; i++) {
968 TokenPosition ignore; 971 TokenPosition ignore;
969 VariableAt(i, &var_name, &ignore, &ignore, &value); 972 VariableAt(i, &var_name, &ignore, &ignore, &ignore, &value);
970 list.SetAt(2 * i, var_name); 973 list.SetAt(2 * i, var_name);
971 list.SetAt((2 * i) + 1, value); 974 list.SetAt((2 * i) + 1, value);
972 } 975 }
973 return list.raw(); 976 return list.raw();
974 } 977 }
975 978
976 979
977 RawObject* ActivationFrame::GetReceiver() { 980 RawObject* ActivationFrame::GetReceiver() {
978 GetDescIndices(); 981 GetDescIndices();
979 intptr_t num_variables = desc_indices_.length(); 982 intptr_t num_variables = desc_indices_.length();
980 String& var_name = String::Handle(); 983 String& var_name = String::Handle();
981 Instance& value = Instance::Handle(); 984 Instance& value = Instance::Handle();
982 for (intptr_t i = 0; i < num_variables; i++) { 985 for (intptr_t i = 0; i < num_variables; i++) {
983 TokenPosition ignore; 986 TokenPosition ignore;
984 VariableAt(i, &var_name, &ignore, &ignore, &value); 987 VariableAt(i, &var_name, &ignore, &ignore, &ignore, &value);
985 if (var_name.Equals(Symbols::This())) { 988 if (var_name.Equals(Symbols::This())) {
986 return value.raw(); 989 return value.raw();
987 } 990 }
988 } 991 }
989 return Symbols::OptimizedOut().raw(); 992 return Symbols::OptimizedOut().raw();
990 } 993 }
991 994
992 995
993 static bool IsSyntheticVariableName(const String& var_name) { 996 static bool IsSyntheticVariableName(const String& var_name) {
994 return (var_name.Length() >= 1) && (var_name.CharAt(0) == ':'); 997 return (var_name.Length() >= 1) && (var_name.CharAt(0) == ':');
995 } 998 }
996 999
997 1000
998 static bool IsPrivateVariableName(const String& var_name) { 1001 static bool IsPrivateVariableName(const String& var_name) {
999 return (var_name.Length() >= 1) && (var_name.CharAt(0) == '_'); 1002 return (var_name.Length() >= 1) && (var_name.CharAt(0) == '_');
1000 } 1003 }
1001 1004
1002 1005
1003 RawObject* ActivationFrame::Evaluate(const String& expr) { 1006 RawObject* ActivationFrame::Evaluate(const String& expr) {
1004 GetDescIndices(); 1007 GetDescIndices();
1005 const GrowableObjectArray& param_names = 1008 const GrowableObjectArray& param_names =
1006 GrowableObjectArray::Handle(GrowableObjectArray::New()); 1009 GrowableObjectArray::Handle(GrowableObjectArray::New());
1007 const GrowableObjectArray& param_values = 1010 const GrowableObjectArray& param_values =
1008 GrowableObjectArray::Handle(GrowableObjectArray::New()); 1011 GrowableObjectArray::Handle(GrowableObjectArray::New());
1009 String& name = String::Handle(); 1012 String& name = String::Handle();
1010 Object& value = Instance::Handle(); 1013 Object& value = Instance::Handle();
1011 intptr_t num_variables = desc_indices_.length(); 1014 intptr_t num_variables = desc_indices_.length();
1012 for (intptr_t i = 0; i < num_variables; i++) { 1015 for (intptr_t i = 0; i < num_variables; i++) {
1013 TokenPosition ignore; 1016 TokenPosition ignore;
1014 VariableAt(i, &name, &ignore, &ignore, &value); 1017 VariableAt(i, &name, &ignore, &ignore, &ignore, &value);
1015 if (!name.Equals(Symbols::This()) && !IsSyntheticVariableName(name)) { 1018 if (!name.Equals(Symbols::This()) && !IsSyntheticVariableName(name)) {
1016 if (IsPrivateVariableName(name)) { 1019 if (IsPrivateVariableName(name)) {
1017 name = String::ScrubName(name); 1020 name = String::ScrubName(name);
1018 } 1021 }
1019 param_names.Add(name); 1022 param_names.Add(name);
1020 param_values.Add(value); 1023 param_values.Add(value);
1021 } 1024 }
1022 } 1025 }
1023 1026
1024 if (function().is_static()) { 1027 if (function().is_static()) {
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
1080 // in the world where we pass the script as part of the 1083 // in the world where we pass the script as part of the
1081 // location. 1084 // location.
1082 jsobj->AddProperty("script", script, !full); 1085 jsobj->AddProperty("script", script, !full);
1083 } 1086 }
1084 { 1087 {
1085 JSONArray jsvars(jsobj, "vars"); 1088 JSONArray jsvars(jsobj, "vars");
1086 const int num_vars = NumLocalVariables(); 1089 const int num_vars = NumLocalVariables();
1087 for (intptr_t v = 0; v < num_vars; v++) { 1090 for (intptr_t v = 0; v < num_vars; v++) {
1088 String& var_name = String::Handle(); 1091 String& var_name = String::Handle();
1089 Instance& var_value = Instance::Handle(); 1092 Instance& var_value = Instance::Handle();
1090 TokenPosition token_pos; 1093 TokenPosition declaration_token_pos;
1091 TokenPosition end_token_pos; 1094 TokenPosition visible_start_token_pos;
1092 VariableAt(v, &var_name, &token_pos, &end_token_pos, &var_value); 1095 TokenPosition visible_end_token_pos;
1096 VariableAt(v,
1097 &var_name,
1098 &declaration_token_pos,
1099 &visible_start_token_pos,
1100 &visible_end_token_pos,
1101 &var_value);
1093 if (var_name.raw() != Symbols::AsyncOperation().raw()) { 1102 if (var_name.raw() != Symbols::AsyncOperation().raw()) {
1094 JSONObject jsvar(&jsvars); 1103 JSONObject jsvar(&jsvars);
1095 jsvar.AddProperty("type", "BoundVariable"); 1104 jsvar.AddProperty("type", "BoundVariable");
1096 var_name = String::ScrubName(var_name); 1105 var_name = String::ScrubName(var_name);
1097 jsvar.AddProperty("name", var_name.ToCString()); 1106 jsvar.AddProperty("name", var_name.ToCString());
1098 jsvar.AddProperty("value", var_value, !full); 1107 jsvar.AddProperty("value", var_value, !full);
1099 // TODO(turnidge): Do we really want to provide this on every 1108 // Where was the variable declared?
1100 // stack dump? Should be associated with the function object, I 1109 jsvar.AddProperty("declarationTokenPos", declaration_token_pos);
1101 // think, and not the stack frame. 1110 // When the variable becomes visible to the scope.
1102 jsvar.AddProperty("_tokenPos", token_pos); 1111 jsvar.AddProperty("visibleStartTokenPos", visible_start_token_pos);
1103 jsvar.AddProperty("_endTokenPos", end_token_pos); 1112 // When the variable stops being visible to the scope.
1113 jsvar.AddProperty("visibleEndTokenPos", visible_end_token_pos);
1104 } 1114 }
1105 } 1115 }
1106 } 1116 }
1107 } 1117 }
1108 1118
1109 1119
1110 1120
1111 void DebuggerStackTrace::AddActivation(ActivationFrame* frame) { 1121 void DebuggerStackTrace::AddActivation(ActivationFrame* frame) {
1112 if (FLAG_show_invisible_frames || frame->function().is_visible()) { 1122 if (FLAG_show_invisible_frames || frame->function().is_visible()) {
1113 trace_.Add(frame); 1123 trace_.Add(frame);
(...skipping 2223 matching lines...) Expand 10 before | Expand all | Expand 10 after
3337 3347
3338 void Debugger::RegisterCodeBreakpoint(CodeBreakpoint* bpt) { 3348 void Debugger::RegisterCodeBreakpoint(CodeBreakpoint* bpt) {
3339 ASSERT(bpt->next() == NULL); 3349 ASSERT(bpt->next() == NULL);
3340 bpt->set_next(code_breakpoints_); 3350 bpt->set_next(code_breakpoints_);
3341 code_breakpoints_ = bpt; 3351 code_breakpoints_ = bpt;
3342 } 3352 }
3343 3353
3344 #endif // !PRODUCT 3354 #endif // !PRODUCT
3345 3355
3346 } // namespace dart 3356 } // namespace dart
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698