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/. */
7 #include "xpcprivate.h"
8 #include "js/friend/DumpFunctions.h" // JS::FormatStackDump
9 #include "nsThreadUtils.h"
10 #include "nsContentUtils.h"
12 #include "mozilla/Sprintf.h"
16 # include "nsPrintfCString.h"
20 # include <android/log.h>
23 static void DebugDump(const char* str
) {
25 if (IsDebuggerPresent()) {
26 nsPrintfCString
output("%s\n", str
);
27 OutputDebugStringA(output
.get());
29 #elif defined(ANDROID)
30 __android_log_print(ANDROID_LOG_DEBUG
, "Gecko", "%s\n", str
);
35 bool xpc_DumpJSStack(bool showArgs
, bool showLocals
, bool showThisProps
) {
36 JSContext
* cx
= nsContentUtils::GetCurrentJSContext();
38 printf("there is no JSContext on the stack!\n");
39 } else if (JS::UniqueChars buf
=
40 xpc_PrintJSStack(cx
, showArgs
, showLocals
, showThisProps
)) {
46 JS::UniqueChars
xpc_PrintJSStack(JSContext
* cx
, bool showArgs
, bool showLocals
,
48 JS::AutoSaveExceptionState
state(cx
);
51 JS::FormatStackDump(cx
, showArgs
, showLocals
, showThisProps
);
53 DebugDump("Failed to format JavaScript stack for dump");