Bug 730140 - NUL-terminate strings when dumping the heap. r=mccr8
authorSteve Fink <sfink@mozilla.com>
Thu, 23 Feb 2012 18:47:51 -0800
changeset 87606 52fe920f26851ec313712b4e1c6b21d18fc7d27a
parent 87605 f2b33e6f0981744e516d876344a281abf9b403bb
child 87607 18fda283b571313bbed29eb01d23001818d55264
push id22133
push usermak77@bonardo.net
push dateFri, 24 Feb 2012 10:23:30 +0000
treeherdermozilla-central@fbcdc2c87df8 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmccr8
bugs730140
milestone13.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 730140 - NUL-terminate strings when dumping the heap. r=mccr8
js/src/jsapi.cpp
js/src/jsfriendapi.cpp
--- a/js/src/jsapi.cpp
+++ b/js/src/jsapi.cpp
@@ -2451,47 +2451,30 @@ JS_TraceChildren(JSTracer *trc, void *th
 JS_PUBLIC_API(void)
 JS_CallTracer(JSTracer *trc, void *thing, JSGCTraceKind kind)
 {
     js::CallTracer(trc, thing, kind);
 }
 
 #ifdef DEBUG
 
-#ifdef HAVE_XPCONNECT
-#include "dump_xpc.h"
-#endif
-
 JS_PUBLIC_API(void)
 JS_PrintTraceThingInfo(char *buf, size_t bufsize, JSTracer *trc, void *thing,
                        JSGCTraceKind kind, JSBool details)
 {
     const char *name = NULL; /* silence uninitialized warning */
     size_t n;
 
     if (bufsize == 0)
         return;
 
     switch (kind) {
       case JSTRACE_OBJECT:
       {
-        JSObject *obj = (JSObject *)thing;
-        Class *clasp = obj->getClass();
-
-        name = clasp->name;
-#ifdef HAVE_XPCONNECT
-        if (clasp->flags & JSCLASS_PRIVATE_IS_NSISUPPORTS) {
-            void *privateThing = obj->getPrivate();
-            if (privateThing) {
-                const char *xpcClassName = GetXPCObjectClassName(privateThing);
-                if (xpcClassName)
-                    name = xpcClassName;
-            }
-        }
-#endif
+        name = static_cast<JSObject *>(thing)->getClass()->name;
         break;
       }
 
       case JSTRACE_STRING:
         name = ((JSString *)thing)->isDependent()
                ? "substring"
                : "string";
         break;
@@ -2520,73 +2503,76 @@ JS_PrintTraceThingInfo(char *buf, size_t
     }
 
     n = strlen(name);
     if (n > bufsize - 1)
         n = bufsize - 1;
     js_memcpy(buf, name, n + 1);
     buf += n;
     bufsize -= n;
+    *buf = '\0';
 
     if (details && bufsize > 2) {
-        *buf++ = ' ';
-        bufsize--;
-
         switch (kind) {
           case JSTRACE_OBJECT:
           {
-            JSObject  *obj = (JSObject *)thing;
+            JSObject *obj = (JSObject *)thing;
             Class *clasp = obj->getClass();
             if (clasp == &FunctionClass) {
                 JSFunction *fun = obj->toFunction();
                 if (!fun) {
-                    JS_snprintf(buf, bufsize, "<newborn>");
+                    JS_snprintf(buf, bufsize, " <newborn>");
                 } else if (fun != obj) {
-                    JS_snprintf(buf, bufsize, "%p", fun);
+                    JS_snprintf(buf, bufsize, " %p", fun);
                 } else {
-                    if (fun->atom)
+                    if (fun->atom) {
+                        *buf++ = ' ';
+                        bufsize--;
                         PutEscapedString(buf, bufsize, fun->atom, 0);
+                    }
                 }
             } else if (clasp->flags & JSCLASS_HAS_PRIVATE) {
-                JS_snprintf(buf, bufsize, "%p", obj->getPrivate());
+                JS_snprintf(buf, bufsize, " %p", obj->getPrivate());
             } else {
-                JS_snprintf(buf, bufsize, "<no private>");
+                JS_snprintf(buf, bufsize, " <no private>");
             }
             break;
           }
 
           case JSTRACE_STRING:
           {
+            *buf++ = ' ';
+            bufsize--;
             JSString *str = (JSString *)thing;
             if (str->isLinear())
                 PutEscapedString(buf, bufsize, &str->asLinear(), 0);
             else
                 JS_snprintf(buf, bufsize, "<rope: length %d>", (int)str->length());
             break;
           }
 
           case JSTRACE_SCRIPT:
           {
             JSScript *script = static_cast<JSScript *>(thing);
-            JS_snprintf(buf, bufsize, "%s:%u", script->filename, unsigned(script->lineno));
+            JS_snprintf(buf, bufsize, " %s:%u", script->filename, unsigned(script->lineno));
             break;
           }
 
           case JSTRACE_SHAPE:
           case JSTRACE_BASE_SHAPE:
           case JSTRACE_TYPE_OBJECT:
             break;
 
 #if JS_HAS_XML_SUPPORT
           case JSTRACE_XML:
           {
             extern const char *js_xml_class_str[];
             JSXML *xml = (JSXML *)thing;
 
-            JS_snprintf(buf, bufsize, "%s", js_xml_class_str[xml->xml_class]);
+            JS_snprintf(buf, bufsize, " %s", js_xml_class_str[xml->xml_class]);
             break;
           }
 #endif
         }
     }
     buf[bufsize - 1] = '\0';
 }
 
--- a/js/src/jsfriendapi.cpp
+++ b/js/src/jsfriendapi.cpp
@@ -540,16 +540,17 @@ js::DumpHeapComplete(JSContext *cx, FILE
         DumpingChildInfo dci = dtrc.nodes.popCopy();
         JS_PrintTraceThingInfo(dtrc.buffer, sizeof(dtrc.buffer),
                                &dtrc, dci.node, dci.kind, JS_TRUE);
         fprintf(fp, "%p %s\n", dci.node, dtrc.buffer);
         JS_TraceChildren(&dtrc, dci.node, dci.kind);
     }
 
     dtrc.visited.finish();
+    fflush(dtrc.output);
 }
 
 #endif
 
 namespace js {
 
 /* static */ void
 AutoLockGC::LockGC(JSRuntime *rt)