Line data Source code
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/. */
6 :
7 : #include "xpcprivate.h"
8 : #include "jsprf.h"
9 : #include "nsThreadUtils.h"
10 : #include "nsContentUtils.h"
11 :
12 : #include "mozilla/Sprintf.h"
13 :
14 : #ifdef XP_WIN
15 : #include <windows.h>
16 : #endif
17 :
18 0 : static void DebugDump(const char* fmt, ...)
19 : {
20 : char buffer[2048];
21 : va_list ap;
22 0 : va_start(ap, fmt);
23 : #ifdef XPWIN
24 : _vsnprintf(buffer, sizeof(buffer), fmt, ap);
25 : buffer[sizeof(buffer)-1] = '\0';
26 : #else
27 0 : VsprintfLiteral(buffer, fmt, ap);
28 : #endif
29 0 : va_end(ap);
30 : #ifdef XP_WIN
31 : if (IsDebuggerPresent()) {
32 : OutputDebugStringA(buffer);
33 : }
34 : #endif
35 0 : printf("%s", buffer);
36 0 : }
37 :
38 : bool
39 0 : xpc_DumpJSStack(bool showArgs, bool showLocals, bool showThisProps)
40 : {
41 0 : JSContext* cx = nsContentUtils::GetCurrentJSContextForThread();
42 0 : if (!cx) {
43 0 : printf("there is no JSContext on the stack!\n");
44 0 : } else if (JS::UniqueChars buf = xpc_PrintJSStack(cx, showArgs, showLocals, showThisProps)) {
45 0 : DebugDump("%s\n", buf.get());
46 : }
47 0 : return true;
48 : }
49 :
50 : JS::UniqueChars
51 0 : xpc_PrintJSStack(JSContext* cx, bool showArgs, bool showLocals,
52 : bool showThisProps)
53 : {
54 0 : JS::AutoSaveExceptionState state(cx);
55 :
56 0 : JS::UniqueChars buf = JS::FormatStackDump(cx, nullptr, showArgs, showLocals, showThisProps);
57 0 : if (!buf)
58 0 : DebugDump("%s", "Failed to format JavaScript stack for dump\n");
59 :
60 0 : state.restore();
61 0 : return buf;
62 : }
|