diff src/os/bsd/vm/os_bsd.cpp @ 6258:3b01d0321dfa

7186778: MachO decoder implementation for MacOSX Summary: Implementation of decoder for Apple's MacOSX. The implementation is based on the patch provided by Kevin Walls. Reviewed-by: coleenp, kamg, kevinw
author zgu
date Mon, 30 Jul 2012 10:25:52 -0400
parents 65906dc96aa1
children 957c266d8bc5 bf2edd3c9b0f
line wrap: on
line diff
--- a/src/os/bsd/vm/os_bsd.cpp	Thu Jul 19 06:24:46 2012 -0700
+++ b/src/os/bsd/vm/os_bsd.cpp	Mon Jul 30 10:25:52 2012 -0400
@@ -1946,10 +1946,16 @@
   return false;
 }
 
+
+#define MACH_MAXSYMLEN 256
+
 bool os::dll_address_to_function_name(address addr, char *buf,
                                       int buflen, int *offset) {
   Dl_info dlinfo;
-
+  char localbuf[MACH_MAXSYMLEN];
+
+  // dladdr will find names of dynamic functions only, but does
+  // it set dli_fbase with mach_header address when it "fails" ?
   if (dladdr((void*)addr, &dlinfo) && dlinfo.dli_sname != NULL) {
     if (buf != NULL) {
       if(!Decoder::demangle(dlinfo.dli_sname, buf, buflen)) {
@@ -1965,6 +1971,14 @@
     }
   }
 
+  // Handle non-dymanic manually:
+  if (dlinfo.dli_fbase != NULL &&
+      Decoder::decode(addr, localbuf, MACH_MAXSYMLEN, offset, dlinfo.dli_fbase)) {
+    if(!Decoder::demangle(localbuf, buf, buflen)) {
+      jio_snprintf(buf, buflen, "%s", localbuf);
+    }
+    return true;
+  }
   if (buf != NULL) buf[0] = '\0';
   if (offset != NULL) *offset = -1;
   return false;