Bumping manifests a=b2g-bump
[gecko.git] / js / xpconnect / src / XPCDebug.cpp
blob06f022d4f4adf2e1d067bec2ea13a0ae0075684a
1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /* vim: set ts=8 sts=4 et sw=4 tw=99: */
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/. */
7 #include "xpcprivate.h"
8 #include "jsprf.h"
9 #include "js/OldDebugAPI.h"
11 #ifdef XP_WIN
12 #include <windows.h>
13 #endif
15 static void DebugDump(const char* fmt, ...)
17 char buffer[2048];
18 va_list ap;
19 va_start(ap, fmt);
20 #ifdef XPWIN
21 _vsnprintf(buffer, sizeof(buffer), fmt, ap);
22 #else
23 vsnprintf(buffer, sizeof(buffer), fmt, ap);
24 #endif
25 buffer[sizeof(buffer)-1] = '\0';
26 va_end(ap);
27 #ifdef XP_WIN
28 if (IsDebuggerPresent()) {
29 OutputDebugStringA(buffer);
31 #endif
32 printf("%s", buffer);
35 bool
36 xpc_DumpJSStack(JSContext* cx, bool showArgs, bool showLocals, bool showThisProps)
38 if (char* buf = xpc_PrintJSStack(cx, showArgs, showLocals, showThisProps)) {
39 DebugDump("%s\n", buf);
40 JS_smprintf_free(buf);
42 return true;
45 char*
46 xpc_PrintJSStack(JSContext* cx, bool showArgs, bool showLocals,
47 bool showThisProps)
49 JS::AutoSaveExceptionState state(cx);
51 char* buf = JS::FormatStackDump(cx, nullptr, showArgs, showLocals, showThisProps);
52 if (!buf)
53 DebugDump("%s", "Failed to format JavaScript stack for dump\n");
55 state.restore();
56 return buf;