Flutter Engine
The Flutter Engine
gdb_helpers.cc
Go to the documentation of this file.
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 "lib/stacktrace.h"
7#include "vm/heap/safepoint.h"
8#include "vm/object.h"
9#include "vm/os_thread.h"
10#include "vm/stack_frame.h"
11
12namespace dart {
13
14#if !defined(PRODUCT)
15
16#if defined(__GNUC__)
17// Older toolchains don't know about "retain"
18#pragma GCC diagnostic ignored "-Wattributes"
19#define GDB_HELPER extern "C" __attribute__((used, retain))
20#else
21#define GDB_HELPER extern "C"
22#endif
23
27}
28
30void _printObjectPtr(uword object) {
31 OS::PrintErr("%s\n",
32 Object::Handle(static_cast<ObjectPtr>(object)).ToCString());
33}
34
37 return &Object::Handle(static_cast<ObjectPtr>(object));
38}
39
43 if (code.IsNull()) {
44 OS::PrintErr("No code found\n");
45 } else {
46 Object& owner = Object::Handle(code.owner());
47 if (owner.IsFunction()) {
48 Disassembler::DisassembleCode(Function::Cast(owner), code,
49 code.is_optimized());
50 } else {
52 }
53 }
54}
55
56// An utility method for convenient printing of dart stack traces when
57// inside 'gdb'. Note: This function will only work when there is a
58// valid exit frame information. It will not work when a breakpoint is
59// set in dart code and control is got inside 'gdb' without going through
60// the runtime or native transition stub.
63 const StackTrace& stacktrace = GetCurrentStackTrace(0);
64 OS::PrintErr("=== Current Trace:\n%s===\n", stacktrace.ToCString());
65}
66
67// Like _printDartStackTrace, but works in a NoSafepointScope. Use it if you're
68// in the middle of a GC or interested in stub frames.
72}
73
74// Like _printDartStackTrace, but works when stopped in generated code.
75// Must be called with the current fp, sp, and pc. I.e.,
76//
77// (gdb) print _printGeneratedStackTrace($rbp, $rsp, $rip)
83 StackFrame* frame = frames.NextFrame();
84 while (frame != nullptr) {
85 OS::PrintErr("%s\n", frame->ToCString());
86 frame = frames.NextFrame();
87 }
88}
89
91 public:
93 : ObjectPointerVisitor(IsolateGroup::Current()) {}
94
95 void VisitPointers(ObjectPtr* first, ObjectPtr* last) override {
96 for (ObjectPtr* p = first; p <= last; p++) {
97 Object& obj = Object::Handle(*p);
98 OS::PrintErr("%p: %s\n", p, obj.ToCString());
99 }
100 }
101
102#if defined(DART_COMPRESSED_POINTERS)
103 void VisitCompressedPointers(uword heap_base,
104 CompressedObjectPtr* first,
105 CompressedObjectPtr* last) override {
106 for (CompressedObjectPtr* p = first; p <= last; p++) {
107 Object& obj = Object::Handle(p->Decompress(heap_base));
108 OS::PrintErr("%p: %s\n", p, obj.ToCString());
109 }
110 }
111#endif
112};
113
120 StackFrame* frame = frames.NextFrame();
121 while (frame != nullptr) {
122 OS::PrintErr("%s\n", frame->ToCString());
123 frame->VisitObjectPointers(&visitor);
124 frame = frames.NextFrame();
125 }
126}
127
128#endif // !PRODUCT
129
130} // namespace dart
static CodePtr FindCodeUnsafe(uword pc)
Definition: object.cc:18220
static void DisassembleStub(const char *name, const Code &code)
static void DisassembleCode(const Function &function, const Code &code, bool optimized)
static ThreadState * CurrentVMThread()
Definition: os_thread.h:188
static void static void PrintErr(const char *format,...) PRINTF_ATTRIBUTE(1
void VisitCompressedPointers(uword heap_base, CompressedObjectPtr *first, CompressedObjectPtr *last)
Definition: visitor.h:43
virtual const char * ToCString() const
Definition: object.h:366
static Object & Handle()
Definition: object.h:407
void VisitPointers(ObjectPtr *first, ObjectPtr *last) override
Definition: gdb_helpers.cc:95
StackFrame * NextFrame()
Definition: stack_frame.cc:549
static void DumpCurrentTrace()
Definition: stack_frame.cc:454
static Thread * Current()
Definition: thread.h:362
double frame
Definition: examples.cpp:31
#define GDB_HELPER
Definition: gdb_helpers.cc:21
Definition: dart_vm.cc:33
GDB_HELPER Object * _handle(uword object)
Definition: gdb_helpers.cc:36
GDB_HELPER void _disassemble(uword pc)
Definition: gdb_helpers.cc:41
GDB_HELPER void _printDartStackTrace()
Definition: gdb_helpers.cc:62
uintptr_t uword
Definition: globals.h:501
const uint32_t fp
GDB_HELPER void _printObjectPtr(uword object)
Definition: gdb_helpers.cc:30
GDB_HELPER void * _currentThread()
Definition: gdb_helpers.cc:25
GDB_HELPER void _printGeneratedStackTrace(uword fp, uword sp, uword pc)
Definition: gdb_helpers.cc:79
const StackTrace & GetCurrentStackTrace(int skip_frames)
Definition: stacktrace.cc:94
GDB_HELPER void _printStackTrace()
Definition: gdb_helpers.cc:70
GDB_HELPER void _printStackTraceWithLocals()
Definition: gdb_helpers.cc:115