Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright (c) 2017, the Dart project authors. Please see the AUTHORS file | |
| 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. | |
| 4 | |
| 5 #include "vm/object.h" | |
| 6 #include "vm/stack_frame.h" | |
| 7 | |
| 8 #include "lib/stacktrace.h" | |
| 9 | |
| 10 namespace dart { | |
| 11 | |
| 12 #if !defined(PRODUCT) | |
| 13 | |
| 14 DART_EXPORT | |
| 15 void _printRawObject(RawObject* object) { | |
|
zra
2017/06/29 21:06:12
Can we use namespaces or an AllStatic class to avo
rmacnak
2017/06/29 21:19:00
Putting these in a class interfers with the export
| |
| 16 OS::PrintErr("%s\n", Object::Handle(object).ToCString()); | |
| 17 } | |
| 18 | |
| 19 | |
| 20 DART_EXPORT | |
| 21 Object* _handle(RawObject* object) { | |
| 22 return &Object::Handle(object); | |
| 23 } | |
| 24 | |
| 25 | |
| 26 // An utility method for convenient printing of dart stack traces when | |
| 27 // inside 'gdb'. Note: This function will only work when there is a | |
| 28 // valid exit frame information. It will not work when a breakpoint is | |
| 29 // set in dart code and control is got inside 'gdb' without going through | |
| 30 // the runtime or native transition stub. | |
| 31 DART_EXPORT | |
| 32 void _printDartStackTrace() { | |
| 33 const StackTrace& stacktrace = GetCurrentStackTrace(0); | |
| 34 OS::PrintErr("=== Current Trace:\n%s===\n", stacktrace.ToCString()); | |
| 35 } | |
| 36 | |
| 37 | |
| 38 // Like _printDartStackTrace, but works in a NoSafepointScope. Use it if you're | |
| 39 // in the middle of a GC or interested in stub frames. | |
| 40 DART_EXPORT | |
| 41 void _printStackTrace() { | |
| 42 StackFrameIterator frames(StackFrameIterator::kDontValidateFrames, | |
| 43 Thread::Current(), | |
| 44 StackFrameIterator::kNoCrossThreadIteration); | |
| 45 StackFrame* frame = frames.NextFrame(); | |
| 46 while (frame != NULL) { | |
| 47 OS::PrintErr("%s\n", frame->ToCString()); | |
| 48 frame = frames.NextFrame(); | |
| 49 } | |
| 50 } | |
| 51 | |
| 52 | |
| 53 class PrintObjectPointersVisitor : public ObjectPointerVisitor { | |
| 54 public: | |
| 55 PrintObjectPointersVisitor() : ObjectPointerVisitor(Isolate::Current()) {} | |
| 56 | |
| 57 void VisitPointers(RawObject** first, RawObject** last) { | |
| 58 for (RawObject** p = first; p <= last; p++) { | |
| 59 Object& obj = Object::Handle(*p); | |
| 60 OS::PrintErr("%p: %s\n", p, obj.ToCString()); | |
| 61 } | |
| 62 } | |
| 63 }; | |
| 64 | |
| 65 | |
| 66 DART_EXPORT | |
| 67 void _printStackTraceWithLocals() { | |
| 68 PrintObjectPointersVisitor visitor; | |
| 69 StackFrameIterator frames(StackFrameIterator::kDontValidateFrames, | |
| 70 Thread::Current(), | |
| 71 StackFrameIterator::kNoCrossThreadIteration); | |
| 72 StackFrame* frame = frames.NextFrame(); | |
| 73 while (frame != NULL) { | |
| 74 OS::PrintErr("%s\n", frame->ToCString()); | |
| 75 frame->VisitObjectPointers(&visitor); | |
| 76 frame = frames.NextFrame(); | |
| 77 } | |
| 78 } | |
| 79 | |
| 80 #endif // !PRODUCT | |
| 81 | |
| 82 } // namespace dart | |
| OLD | NEW |