Bug 995345 - Improve efficiency of NS_DescribeCodeAddress. r=froydnj
authorEric Rahm <erahm@mozilla.com>
Mon, 14 Apr 2014 13:25:04 -0700
changeset 196905 727e064bb219f4ba2eed27cc6854e447e1b4b974
parent 196904 40260af420a7b7c13fc48fcb178a559186d98446
child 196906 4f42a748cfaa993e07798bf7da5a9e74511e9b7d
push id3624
push userasasaki@mozilla.com
push dateMon, 09 Jun 2014 21:49:01 +0000
treeherdermozilla-beta@b1a5da15899a [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersfroydnj
bugs995345
milestone31.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 995345 - Improve efficiency of NS_DescribeCodeAddress. r=froydnj
xpcom/base/nsStackWalk.cpp
--- a/xpcom/base/nsStackWalk.cpp
+++ b/xpcom/base/nsStackWalk.cpp
@@ -864,20 +864,20 @@ void DemangleSymbol(const char * aSymbol
                     char * aBuffer,
                     int aBufLen)
 {
     aBuffer[0] = '\0';
 
 #if defined(MOZ_DEMANGLE_SYMBOLS)
     /* See demangle.h in the gcc source for the voodoo */
     char * demangled = abi::__cxa_demangle(aSymbol,0,0,0);
-    
+
     if (demangled)
     {
-        strncpy(aBuffer,demangled,aBufLen);
+        PL_strncpyz(aBuffer,demangled,aBufLen);
         free(demangled);
     }
 #endif // MOZ_DEMANGLE_SYMBOLS
 }
 
 
 #if NSSTACKWALK_SUPPORTS_SOLARIS
 
@@ -1312,31 +1312,27 @@ NS_DescribeCodeAddress(void *aPC, nsCode
   if (!ok) {
     return NS_OK;
   }
 
   PL_strncpyz(aDetails->library, info.dli_fname, sizeof(aDetails->library));
   aDetails->loffset = (char*)aPC - (char*)info.dli_fbase;
 
   const char * symbol = info.dli_sname;
-  int len;
-  if (!symbol || !(len = strlen(symbol))) {
+  if (!symbol || symbol[0] == '\0') {
     return NS_OK;
   }
 
-  char demangled[4096] = "\0";
-
-  DemangleSymbol(symbol, demangled, sizeof(demangled));
+  DemangleSymbol(symbol, aDetails->function, sizeof(aDetails->function));
 
-  if (strlen(demangled)) {
-    symbol = demangled;
-    len = strlen(symbol);
+  if (aDetails->function[0] == '\0') {
+    // Just use the mangled symbol if demangling failed.
+    PL_strncpyz(aDetails->function, symbol, sizeof(aDetails->function));
   }
 
-  PL_strncpyz(aDetails->function, symbol, sizeof(aDetails->function));
   aDetails->foffset = (char*)aPC - (char*)info.dli_saddr;
   return NS_OK;
 }
 
 EXPORT_XPCOM_API(nsresult)
 NS_FormatCodeAddressDetails(void *aPC, const nsCodeAddressDetails *aDetails,
                             char *aBuffer, uint32_t aBufferSize)
 {