From f60763376a58d50eeafd0d69b491a78ba03d1f75 Mon Sep 17 00:00:00 2001 From: "igor@mir2.org" Date: Thu, 26 Apr 2007 23:12:39 -0700 Subject: [PATCH] Bug 378255: DEBUG build of xpc now dumps JS heap on shutdown to a file defined by XPC_SHUTDOWN_HEAP_DUMP environment variable. r=brendan sr=jst --- js/src/xpconnect/src/nsXPConnect.cpp | 33 ++++++++++++++++------------ 1 file changed, 19 insertions(+), 14 deletions(-) diff --git a/js/src/xpconnect/src/nsXPConnect.cpp b/js/src/xpconnect/src/nsXPConnect.cpp index 22a86012294..2fd13aa6b04 100644 --- a/js/src/xpconnect/src/nsXPConnect.cpp +++ b/js/src/xpconnect/src/nsXPConnect.cpp @@ -297,15 +297,6 @@ nsXPConnect::GetXPConnect() return gSelf; } -// In order to enable this jsgc heap dumping you need to compile -// _both_ js/src/jsgc.c and this file with 'GC_MARK_DEBUG' #defined. -// Normally this is done by adding -DGC_MARK_DEBUG to the appropriate -// defines lists in the makefiles. - -#ifdef GC_MARK_DEBUG -extern "C" JS_FRIEND_DATA(FILE *) js_DumpGCHeap; -#endif - // static nsXPConnect* nsXPConnect::GetSingleton() @@ -331,15 +322,29 @@ nsXPConnect::ReleaseXPConnectSingleton() } #endif -#ifdef GC_MARK_DEBUG +#ifdef DEBUG // force a dump of the JavaScript gc heap if JS is still alive + // if requested through XPC_SHUTDOWN_HEAP_DUMP environment variable XPCCallContext ccx(NATIVE_CALLER); if(ccx.IsValid()) { - FILE* oldFileHandle = js_DumpGCHeap; - js_DumpGCHeap = stdout; - JS_GC(ccx); - js_DumpGCHeap = oldFileHandle; + const char* dumpName = getenv("XPC_SHUTDOWN_HEAP_DUMP"); + if(dumpName) + { + FILE* dumpFile = (*dumpName == '\0' || + strcmp(dumpName, "stdout") == 0) + ? stdout + : fopen(dumpName, "w"); + if(dumpFile) + { + JS_DumpHeap(ccx, nsnull, 0, nsnull, + NS_STATIC_CAST(size_t, -1), nsnull, + NS_REINTERPRET_CAST(JSPrintfFormater, fprintf), + dumpFile); + if(dumpFile != stdout) + fclose(dumpFile); + } + } } #endif #ifdef XPC_DUMP_AT_SHUTDOWN