Bug 855081 patch 2: Use a single buffer for the demangled names. r=jesup
authorL. David Baron <dbaron@dbaron.org>
Mon, 03 Mar 2014 00:54:38 -0800
changeset 171437 8a72d26209182966111fcc0a6a721c65ac3160ec
parent 171436 c66cd5bf1aadd254aefa2078ef3d3f319e006a53
child 171438 31b472f3e282a08ca53db8eaf137c4924cd1dc69
push id26324
push useremorley@mozilla.com
push dateMon, 03 Mar 2014 14:45:05 +0000
treeherdermozilla-central@73ab6437a1de [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjesup
bugs855081
milestone30.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 855081 patch 2: Use a single buffer for the demangled names. r=jesup
tools/jprof/bfd.cpp
--- a/tools/jprof/bfd.cpp
+++ b/tools/jprof/bfd.cpp
@@ -182,41 +182,47 @@ void leaky::ReadSymbols(const char *aFil
     }
     symbolFile = lib;
   }
 
   asymbol* store;
   store = bfd_make_empty_symbol(symbolFile);
 
   // Scan symbols
+  size_t demangle_buffer_size = 128;
+  char *demangle_buffer = (char*) malloc(demangle_buffer_size);
   bfd_byte* from = (bfd_byte *) minisyms;
   bfd_byte* fromend = from + symcount * size;
   for (; from < fromend; from += size) {
     asymbol *sym;
     sym = bfd_minisymbol_to_symbol(symbolFile, kDynamic, (const PTR) from, store);
 
     symbol_info syminfo;
     bfd_get_symbol_info (symbolFile, sym, &syminfo);
 
 //    if ((syminfo.type == 'T') || (syminfo.type == 't')) {
       const char* nm = bfd_asymbol_name(sym);
       if (nm && nm[0]) {
         char* dnm = nullptr;
         if (strncmp("__thunk", nm, 7)) {
-          dnm = abi::__cxa_demangle(nm, 0, 0, 0);
+          dnm =
+            abi::__cxa_demangle(nm, demangle_buffer, &demangle_buffer_size, 0);
+          if (dnm) {
+            demangle_buffer = dnm;
+          }
         }
         (*sp)->Init(dnm ? dnm : nm, syminfo.value + aBaseAddress);
-        if (dnm) {
-          free(dnm);
-        }
         NEXT_SYMBOL;
       }
 //    }
   }
 
+  free(demangle_buffer);
+  demangle_buffer = nullptr;
+
   bfd_close(symbolFile);
 
   int interesting = sp - externalSymbols;
   if (!quiet) {
     printf("%s provided %d symbols\n", aFileName,
            interesting - initialSymbols);
   }
   usefulSymbols = interesting;