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

Unified Diff: runtime/lib/error.cc

Issue 12316116: Add functionality to get full stack trace when exceptions are thrown. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 7 years, 10 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | runtime/lib/errors_patch.dart » ('j') | runtime/vm/raw_object.h » ('J')
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: runtime/lib/error.cc
===================================================================
--- runtime/lib/error.cc (revision 19025)
+++ runtime/lib/error.cc (working copy)
@@ -140,4 +140,93 @@
return Object::null();
}
+
+// Get a full stack trace.
+// Arg0: stack trace object.
+// Return value: String that represents the full stack trace.
+DEFINE_NATIVE_ENTRY(Stacktrace_getFullStacktrace, 1) {
+ const Stacktrace& trace =
+ Stacktrace::CheckedHandle(arguments->NativeArgAt(0));
+ return trace.FullStacktrace();
+}
+
+
+// Get a concise and pertinent stack trace.
+// Arg0: stack trace object.
+// Return value: String that represents the concise and pertinent stack trace.
+DEFINE_NATIVE_ENTRY(Stacktrace_getStacktrace, 1) {
+ const Stacktrace& trace =
+ Stacktrace::CheckedHandle(arguments->NativeArgAt(0));
+ return String::New(trace.ToCString());
+}
+
+
+// Setup a full stacktrace.
srdjan 2013/02/26 18:00:43 s/stacktrace/stack trace/
siva 2013/02/27 02:21:59 Done.
+// Arg0: stack trace object.
+// Return value: None.
+DEFINE_NATIVE_ENTRY(Stacktrace_setupFullStacktrace, 1) {
+ const Stacktrace& trace =
+ Stacktrace::CheckedHandle(arguments->NativeArgAt(0));
+ const GrowableObjectArray& func_list =
+ GrowableObjectArray::Handle(GrowableObjectArray::New());
+ const GrowableObjectArray& code_list =
+ GrowableObjectArray::Handle(GrowableObjectArray::New());
+ const GrowableObjectArray& pc_offset_list =
+ GrowableObjectArray::Handle(GrowableObjectArray::New());
+ StackFrameIterator frames(StackFrameIterator::kDontValidateFrames);
+ StackFrame* frame = frames.NextFrame();
+ ASSERT(frame != NULL); // We expect to find a dart invocation frame.
+ Function& func = Function::Handle();
+ Code& code = Code::Handle();
+ Smi& offset = Smi::Handle();
+ bool catch_frame_skipped = false; // Tracks if catch frame has been skipped.
+ while (!frame->IsEntryFrame()) {
+ if (frame->IsDartFrame()) {
+ code = frame->LookupDartCode();
+ if (code.is_optimized()) {
+ // For optimized frames, extract all the inlined functions if any
+ // into the stack trace.
+ for (InlinedFunctionsIterator it(frame); !it.Done(); it.Advance()) {
+ func = it.function();
+ code = it.code();
+ uword pc = it.pc();
+ ASSERT(pc != 0);
+ ASSERT(code.EntryPoint() <= pc);
+ ASSERT(pc < (code.EntryPoint() + code.Size()));
+ if (func.is_visible()) {
+ if (!catch_frame_skipped) {
+ catch_frame_skipped = true;
+ } else {
+ offset = Smi::New(pc - code.EntryPoint());
+ func_list.Add(func);
+ code_list.Add(code);
+ pc_offset_list.Add(offset);
+ }
+ }
+ }
+ } else {
+ offset = Smi::New(frame->pc() - code.EntryPoint());
+ func = code.function();
+ if (func.is_visible()) {
+ if (!catch_frame_skipped) {
+ catch_frame_skipped = true;
+ } else {
+ func_list.Add(func);
+ code_list.Add(code);
+ pc_offset_list.Add(offset);
+ }
+ }
+ }
+ }
+ frame = frames.NextFrame();
+ ASSERT(frame != NULL);
+ }
+ const Array& func_array = Array::Handle(Array::MakeArray(func_list));
+ const Array& code_array = Array::Handle(Array::MakeArray(code_list));
+ const Array& pc_offset_array =
+ Array::Handle(Array::MakeArray(pc_offset_list));
+ trace.SetCatchStacktrace(func_array, code_array, pc_offset_array);
+ return Object::null();
+}
+
} // namespace dart
« no previous file with comments | « no previous file | runtime/lib/errors_patch.dart » ('j') | runtime/vm/raw_object.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698