DumpFunctions.h (4245B)
1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- 2 * vim: set ts=8 sts=2 et sw=2 tw=80: 3 * This Source Code Form is subject to the terms of the Mozilla Public 4 * License, v. 2.0. If a copy of the MPL was not distributed with this 5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 6 7 /* Functions to print out values during debugging. */ 8 9 #ifndef js_friend_DumpFunctions_h 10 #define js_friend_DumpFunctions_h 11 12 #include "mozilla/Attributes.h" 13 #include "mozilla/MemoryReporting.h" // mozilla::MallocSizeOf 14 15 #include <stddef.h> // size_t 16 #include <stdio.h> // FILE 17 18 #include "jstypes.h" // JS_PUBLIC_API 19 20 #include "js/Printer.h" // js::GenericPrinter 21 #include "js/Utility.h" // JS::UniqueChars 22 23 class JS_PUBLIC_API JSAtom; 24 struct JS_PUBLIC_API JSContext; 25 class JS_PUBLIC_API JSObject; 26 class JS_PUBLIC_API JSScript; 27 class JS_PUBLIC_API JSString; 28 29 namespace JS { 30 31 class JS_PUBLIC_API BigInt; 32 class JS_PUBLIC_API PropertyKey; 33 class JS_PUBLIC_API Value; 34 35 } // namespace JS 36 37 namespace js { 38 39 class InterpreterFrame; 40 41 } // namespace js 42 43 namespace JS { 44 45 /** Exposed for DumpJSStack */ 46 extern JS_PUBLIC_API JS::UniqueChars FormatStackDump(JSContext* cx, 47 bool showArgs, 48 bool showLocals, 49 bool showThisProps); 50 51 } // namespace JS 52 53 namespace js { 54 55 /* 56 * These functions are FRIEND_API to help the debugger find them and to support 57 * temporarily hacking js::Dump* calls into other code. Note that there are 58 * overloads that do not require the FILE* parameter, which will default to 59 * stderr. 60 * 61 * These functions are no-ops unless built with DEBUG or JS_JITSPEW. 62 */ 63 64 extern JS_PUBLIC_API void DumpString(JSString* str, FILE* fp); 65 66 extern JS_PUBLIC_API void DumpAtom(JSAtom* atom, FILE* fp); 67 68 extern JS_PUBLIC_API void DumpObject(JSObject* obj, FILE* fp); 69 70 extern JS_PUBLIC_API void DumpChars(const char16_t* s, size_t n, FILE* fp); 71 72 // DumpBigInt() outputs the value in decimal if it fits within a 64-bit int, and 73 // otherwise in hex, prefixed with "0x". In both cases the "n" is appended. 74 extern JS_PUBLIC_API void DumpBigInt(JS::BigInt* bi, FILE* fp); 75 76 extern JS_PUBLIC_API void DumpValue(const JS::Value& val, FILE* fp); 77 78 extern JS_PUBLIC_API void DumpId(JS::PropertyKey id, FILE* fp); 79 80 extern JS_PUBLIC_API bool DumpPC(JSContext* cx, FILE* fp); 81 82 extern JS_PUBLIC_API bool DumpScript(JSContext* cx, JSScript* scriptArg, 83 FILE* fp); 84 85 // Versions for use directly in a debugger (default parameters are not handled 86 // well in gdb; built-in handles like stderr are not handled well in lldb.) 87 extern JS_PUBLIC_API void DumpString(JSString* str); 88 extern JS_PUBLIC_API void DumpAtom(JSAtom* atom); 89 extern JS_PUBLIC_API void DumpObject(JSObject* obj); 90 extern JS_PUBLIC_API void DumpChars(const char16_t* s, size_t n); 91 extern JS_PUBLIC_API void DumpBigInt(JS::BigInt* bi); 92 extern JS_PUBLIC_API void DumpValue(const JS::Value& val); 93 extern JS_PUBLIC_API void DumpId(JS::PropertyKey id); 94 extern JS_PUBLIC_API void DumpInterpreterFrame( 95 JSContext* cx, InterpreterFrame* start = nullptr); 96 extern JS_PUBLIC_API bool DumpPC(JSContext* cx); 97 extern JS_PUBLIC_API bool DumpScript(JSContext* cx, JSScript* scriptArg); 98 99 // DumpBacktrace(), unlike the other dump functions, always dumps a backtrace -- 100 // regardless of DEBUG or JS_JITSPEW. 101 102 extern JS_PUBLIC_API void DumpBacktrace(JSContext* cx, FILE* fp); 103 104 extern JS_PUBLIC_API void DumpBacktrace(JSContext* cx, GenericPrinter& out); 105 106 extern JS_PUBLIC_API void DumpBacktrace(JSContext* cx); 107 108 enum DumpHeapNurseryBehaviour { 109 CollectNurseryBeforeDump, 110 IgnoreNurseryObjects 111 }; 112 113 /** 114 * Dump the complete object graph of heap-allocated things. 115 * fp is the file for the dump output. 116 */ 117 extern JS_PUBLIC_API void DumpHeap( 118 JSContext* cx, FILE* fp, DumpHeapNurseryBehaviour nurseryBehaviour, 119 mozilla::MallocSizeOf mallocSizeOf = nullptr); 120 121 extern JS_PUBLIC_API void DumpFmt(FILE* fp, const char* fmt, ...) 122 MOZ_FORMAT_PRINTF(2, 3); 123 extern JS_PUBLIC_API void DumpFmt(const char* fmt, ...) MOZ_FORMAT_PRINTF(1, 2); 124 125 } // namespace js 126 127 #endif // js_friend_DumpFunctions_h