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

Unified Diff: runtime/lib/stacktrace.cc

Issue 1448003002: Add StackTrace.current getter. (Closed) Base URL: https://github.com/dart-lang/sdk.git@master
Patch Set: Address VM comments. Created 5 years, 1 month 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 | « runtime/lib/core_patch.dart ('k') | runtime/vm/bootstrap_natives.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: runtime/lib/stacktrace.cc
diff --git a/runtime/lib/stacktrace.cc b/runtime/lib/stacktrace.cc
index 6175b24b4d18d841ce132233347e27e3053439a3..7b793141f2c5f0de3c120a6b3abc85ea48bbb399 100644
--- a/runtime/lib/stacktrace.cc
+++ b/runtime/lib/stacktrace.cc
@@ -11,7 +11,8 @@
namespace dart {
static void IterateFrames(const GrowableObjectArray& code_list,
- const GrowableObjectArray& pc_offset_list) {
+ const GrowableObjectArray& pc_offset_list,
+ int skip_frames) {
StackFrameIterator frames(StackFrameIterator::kDontValidateFrames);
StackFrame* frame = frames.NextFrame();
ASSERT(frame != NULL); // We expect to find a dart invocation frame.
@@ -19,33 +20,49 @@ static void IterateFrames(const GrowableObjectArray& code_list,
Smi& offset = Smi::Handle();
while (frame != NULL) {
if (frame->IsDartFrame()) {
- code = frame->LookupDartCode();
- offset = Smi::New(frame->pc() - code.EntryPoint());
- code_list.Add(code);
- pc_offset_list.Add(offset);
+ if (skip_frames > 0) {
+ skip_frames--;
+ } else {
+ code = frame->LookupDartCode();
+ offset = Smi::New(frame->pc() - code.EntryPoint());
+ code_list.Add(code);
+ pc_offset_list.Add(offset);
+ }
}
frame = frames.NextFrame();
}
}
-
-// An utility method for convenient printing of dart stack traces when
-// inside 'gdb'. Note: This function will only work when there is a
-// valid exit frame information. It will not work when a breakpoint is
-// set in dart code and control is got inside 'gdb' without going through
-// the runtime or native transition stub.
-void _printCurrentStacktrace() {
+// Creates a Stacktrace object from the current stack.
+//
+// Skips the first skip_frames Dart frames.
+static const Stacktrace& GetCurrentStacktrace(int skip_frames) {
const GrowableObjectArray& code_list =
GrowableObjectArray::Handle(GrowableObjectArray::New());
const GrowableObjectArray& pc_offset_list =
GrowableObjectArray::Handle(GrowableObjectArray::New());
- IterateFrames(code_list, pc_offset_list);
+ IterateFrames(code_list, pc_offset_list, skip_frames);
const Array& code_array = Array::Handle(Array::MakeArray(code_list));
const Array& pc_offset_array =
Array::Handle(Array::MakeArray(pc_offset_list));
const Stacktrace& stacktrace = Stacktrace::Handle(
Stacktrace::New(code_array, pc_offset_array));
+ return stacktrace;
+}
+
+// An utility method for convenient printing of dart stack traces when
+// inside 'gdb'. Note: This function will only work when there is a
+// valid exit frame information. It will not work when a breakpoint is
+// set in dart code and control is got inside 'gdb' without going through
+// the runtime or native transition stub.
+void _printCurrentStacktrace() {
+ const Stacktrace& stacktrace = GetCurrentStacktrace(0);
OS::PrintErr("=== Current Trace:\n%s===\n", stacktrace.ToCString());
}
+DEFINE_NATIVE_ENTRY(StackTrace_current, 0) {
+ const Stacktrace& stacktrace = GetCurrentStacktrace(1);
+ return stacktrace.raw();
+}
+
} // namespace dart
« no previous file with comments | « runtime/lib/core_patch.dart ('k') | runtime/vm/bootstrap_natives.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698