Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 "lib/error.h" | 5 #include "lib/error.h" |
| 6 | 6 |
| 7 #include "vm/bootstrap_natives.h" | 7 #include "vm/bootstrap_natives.h" |
| 8 #include "vm/exceptions.h" | 8 #include "vm/exceptions.h" |
| 9 #include "vm/object_store.h" | 9 #include "vm/object_store.h" |
| 10 #include "vm/runtime_entry.h" | 10 #include "vm/runtime_entry.h" |
| (...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 133 script.GetTokenLocation(error_pos, &line, &column); | 133 script.GetTokenLocation(error_pos, &line, &column); |
| 134 Exceptions::SetField(error, cls, "line", Smi::Handle(Smi::New(line))); | 134 Exceptions::SetField(error, cls, "line", Smi::Handle(Smi::New(line))); |
| 135 Exceptions::SetField(error, cls, "className", class_name); | 135 Exceptions::SetField(error, cls, "className", class_name); |
| 136 | 136 |
| 137 // Throw AbstractClassInstantiationError instance. | 137 // Throw AbstractClassInstantiationError instance. |
| 138 Exceptions::Throw(error); | 138 Exceptions::Throw(error); |
| 139 UNREACHABLE(); | 139 UNREACHABLE(); |
| 140 return Object::null(); | 140 return Object::null(); |
| 141 } | 141 } |
| 142 | 142 |
| 143 | |
| 144 // Get a full stack trace. | |
| 145 // Arg0: stack trace object. | |
| 146 // Return value: String that represents the full stack trace. | |
| 147 DEFINE_NATIVE_ENTRY(Stacktrace_getFullStacktrace, 1) { | |
| 148 const Stacktrace& trace = | |
| 149 Stacktrace::CheckedHandle(arguments->NativeArgAt(0)); | |
| 150 return trace.FullStacktrace(); | |
| 151 } | |
| 152 | |
| 153 | |
| 154 // Get a concise and pertinent stack trace. | |
| 155 // Arg0: stack trace object. | |
| 156 // Return value: String that represents the concise and pertinent stack trace. | |
| 157 DEFINE_NATIVE_ENTRY(Stacktrace_getStacktrace, 1) { | |
| 158 const Stacktrace& trace = | |
| 159 Stacktrace::CheckedHandle(arguments->NativeArgAt(0)); | |
| 160 return String::New(trace.ToCString()); | |
| 161 } | |
| 162 | |
| 163 | |
| 164 // Setup a full stacktrace. | |
|
srdjan
2013/02/26 18:00:43
s/stacktrace/stack trace/
siva
2013/02/27 02:21:59
Done.
| |
| 165 // Arg0: stack trace object. | |
| 166 // Return value: None. | |
| 167 DEFINE_NATIVE_ENTRY(Stacktrace_setupFullStacktrace, 1) { | |
| 168 const Stacktrace& trace = | |
| 169 Stacktrace::CheckedHandle(arguments->NativeArgAt(0)); | |
| 170 const GrowableObjectArray& func_list = | |
| 171 GrowableObjectArray::Handle(GrowableObjectArray::New()); | |
| 172 const GrowableObjectArray& code_list = | |
| 173 GrowableObjectArray::Handle(GrowableObjectArray::New()); | |
| 174 const GrowableObjectArray& pc_offset_list = | |
| 175 GrowableObjectArray::Handle(GrowableObjectArray::New()); | |
| 176 StackFrameIterator frames(StackFrameIterator::kDontValidateFrames); | |
| 177 StackFrame* frame = frames.NextFrame(); | |
| 178 ASSERT(frame != NULL); // We expect to find a dart invocation frame. | |
| 179 Function& func = Function::Handle(); | |
| 180 Code& code = Code::Handle(); | |
| 181 Smi& offset = Smi::Handle(); | |
| 182 bool catch_frame_skipped = false; // Tracks if catch frame has been skipped. | |
| 183 while (!frame->IsEntryFrame()) { | |
| 184 if (frame->IsDartFrame()) { | |
| 185 code = frame->LookupDartCode(); | |
| 186 if (code.is_optimized()) { | |
| 187 // For optimized frames, extract all the inlined functions if any | |
| 188 // into the stack trace. | |
| 189 for (InlinedFunctionsIterator it(frame); !it.Done(); it.Advance()) { | |
| 190 func = it.function(); | |
| 191 code = it.code(); | |
| 192 uword pc = it.pc(); | |
| 193 ASSERT(pc != 0); | |
| 194 ASSERT(code.EntryPoint() <= pc); | |
| 195 ASSERT(pc < (code.EntryPoint() + code.Size())); | |
| 196 if (func.is_visible()) { | |
| 197 if (!catch_frame_skipped) { | |
| 198 catch_frame_skipped = true; | |
| 199 } else { | |
| 200 offset = Smi::New(pc - code.EntryPoint()); | |
| 201 func_list.Add(func); | |
| 202 code_list.Add(code); | |
| 203 pc_offset_list.Add(offset); | |
| 204 } | |
| 205 } | |
| 206 } | |
| 207 } else { | |
| 208 offset = Smi::New(frame->pc() - code.EntryPoint()); | |
| 209 func = code.function(); | |
| 210 if (func.is_visible()) { | |
| 211 if (!catch_frame_skipped) { | |
| 212 catch_frame_skipped = true; | |
| 213 } else { | |
| 214 func_list.Add(func); | |
| 215 code_list.Add(code); | |
| 216 pc_offset_list.Add(offset); | |
| 217 } | |
| 218 } | |
| 219 } | |
| 220 } | |
| 221 frame = frames.NextFrame(); | |
| 222 ASSERT(frame != NULL); | |
| 223 } | |
| 224 const Array& func_array = Array::Handle(Array::MakeArray(func_list)); | |
| 225 const Array& code_array = Array::Handle(Array::MakeArray(code_list)); | |
| 226 const Array& pc_offset_array = | |
| 227 Array::Handle(Array::MakeArray(pc_offset_list)); | |
| 228 trace.SetCatchStacktrace(func_array, code_array, pc_offset_array); | |
| 229 return Object::null(); | |
| 230 } | |
| 231 | |
| 143 } // namespace dart | 232 } // namespace dart |
| OLD | NEW |