7127191: SA JSDB does not display native symbols correctly for transported Linux cores

Wed, 12 Feb 2014 23:39:53 +0400

author
dsamersoff
date
Wed, 12 Feb 2014 23:39:53 +0400
changeset 9627
d626acee4654
parent 9626
ce13ce932e31
child 9628
04cb6ac03887

7127191: SA JSDB does not display native symbols correctly for transported Linux cores
Summary: Better handle SA_ALTROOT
Reviewed-by: sla, sspitsyn

agent/src/os/linux/libproc_impl.c file | annotate | diff | comparison | revisions
agent/src/share/classes/sun/jvm/hotspot/debugger/linux/LinuxCDebugger.java file | annotate | diff | comparison | revisions
agent/src/share/classes/sun/jvm/hotspot/utilities/soql/sa.js file | annotate | diff | comparison | revisions
     1.1 --- a/agent/src/os/linux/libproc_impl.c	Wed Oct 25 13:11:07 2017 -0700
     1.2 +++ b/agent/src/os/linux/libproc_impl.c	Wed Feb 12 23:39:53 2014 +0400
     1.3 @@ -29,54 +29,51 @@
     1.4  #include <thread_db.h>
     1.5  #include "libproc_impl.h"
     1.6  
     1.7 -static const char* alt_root = NULL;
     1.8 -static int alt_root_len = -1;
     1.9 -
    1.10  #define SA_ALTROOT "SA_ALTROOT"
    1.11  
    1.12 -static void init_alt_root() {
    1.13 -   if (alt_root_len == -1) {
    1.14 -      alt_root = getenv(SA_ALTROOT);
    1.15 -      if (alt_root) {
    1.16 -         alt_root_len = strlen(alt_root);
    1.17 -      } else {
    1.18 -         alt_root_len = 0;
    1.19 -      }
    1.20 -   }
    1.21 -}
    1.22 +int pathmap_open(const char* name) {
    1.23 +  static const char *alt_root = NULL;
    1.24 +  static int alt_root_initialized = 0;
    1.25  
    1.26 -int pathmap_open(const char* name) {
    1.27 -   int fd;
    1.28 -   char alt_path[PATH_MAX + 1];
    1.29 +  int fd;
    1.30 +  char alt_path[PATH_MAX + 1], *alt_path_end;
    1.31 +  const char *s;
    1.32  
    1.33 -   init_alt_root();
    1.34 +  if (!alt_root_initialized) {
    1.35 +    alt_root_initialized = -1;
    1.36 +    alt_root = getenv(SA_ALTROOT);
    1.37 +  }
    1.38  
    1.39 -   if (alt_root_len > 0) {
    1.40 -      strcpy(alt_path, alt_root);
    1.41 -      strcat(alt_path, name);
    1.42 -      fd = open(alt_path, O_RDONLY);
    1.43 -      if (fd >= 0) {
    1.44 -         print_debug("path %s substituted for %s\n", alt_path, name);
    1.45 -         return fd;
    1.46 -      }
    1.47 +  if (alt_root == NULL) {
    1.48 +    return open(name, O_RDONLY);
    1.49 +  }
    1.50  
    1.51 -      if (strrchr(name, '/')) {
    1.52 -         strcpy(alt_path, alt_root);
    1.53 -         strcat(alt_path, strrchr(name, '/'));
    1.54 -         fd = open(alt_path, O_RDONLY);
    1.55 -         if (fd >= 0) {
    1.56 -            print_debug("path %s substituted for %s\n", alt_path, name);
    1.57 -            return fd;
    1.58 -         }
    1.59 -      }
    1.60 -   } else {
    1.61 -      fd = open(name, O_RDONLY);
    1.62 -      if (fd >= 0) {
    1.63 -         return fd;
    1.64 -      }
    1.65 -   }
    1.66 +  strcpy(alt_path, alt_root);
    1.67 +  alt_path_end = alt_path + strlen(alt_path);
    1.68  
    1.69 -   return -1;
    1.70 +  // Strip path items one by one and try to open file with alt_root prepended
    1.71 +  s = name;
    1.72 +  while (1) {
    1.73 +    strcat(alt_path, s);
    1.74 +    s += 1;
    1.75 +
    1.76 +    fd = open(alt_path, O_RDONLY);
    1.77 +    if (fd >= 0) {
    1.78 +      print_debug("path %s substituted for %s\n", alt_path, name);
    1.79 +      return fd;
    1.80 +    }
    1.81 +
    1.82 +    // Linker always put full path to solib to process, so we can rely
    1.83 +    // on presence of /. If slash is not present, it means, that SOlib doesn't
    1.84 +    // physically exist (e.g. linux-gate.so) and we fail opening it anyway
    1.85 +    if ((s = strchr(s, '/')) == NULL) {
    1.86 +      break;
    1.87 +    }
    1.88 +
    1.89 +    *alt_path_end = 0;
    1.90 +  }
    1.91 +
    1.92 +  return -1;
    1.93  }
    1.94  
    1.95  static bool _libsaproc_debug;
     2.1 --- a/agent/src/share/classes/sun/jvm/hotspot/debugger/linux/LinuxCDebugger.java	Wed Oct 25 13:11:07 2017 -0700
     2.2 +++ b/agent/src/share/classes/sun/jvm/hotspot/debugger/linux/LinuxCDebugger.java	Wed Feb 12 23:39:53 2014 +0400
     2.3 @@ -55,31 +55,21 @@
     2.4      if (pc == null) {
     2.5        return null;
     2.6      }
     2.7 +
     2.8 +    /* Typically we have about ten loaded objects here. So no reason to do
     2.9 +      sort/binary search here. Linear search gives us acceptable performance.*/
    2.10 +
    2.11      List objs = getLoadObjectList();
    2.12 -    Object[] arr = objs.toArray();
    2.13 -    // load objects are sorted by base address, do binary search
    2.14 -    int mid  = -1;
    2.15 -    int low  = 0;
    2.16 -    int high = arr.length - 1;
    2.17  
    2.18 -    while (low <= high) {
    2.19 -       mid = (low + high) >> 1;
    2.20 -       LoadObject midVal = (LoadObject) arr[mid];
    2.21 -       long cmp = pc.minus(midVal.getBase());
    2.22 -       if (cmp < 0) {
    2.23 -          high = mid - 1;
    2.24 -       } else if (cmp > 0) {
    2.25 -          long size = midVal.getSize();
    2.26 -          if (cmp >= size) {
    2.27 -             low = mid + 1;
    2.28 -          } else {
    2.29 -             return (LoadObject) arr[mid];
    2.30 -          }
    2.31 -       } else { // match found
    2.32 -          return (LoadObject) arr[mid];
    2.33 -       }
    2.34 +    for (int i = 0; i < objs.size(); i++) {
    2.35 +      LoadObject ob = (LoadObject) objs.get(i);
    2.36 +      Address base = ob.getBase();
    2.37 +      long size = ob.getSize();
    2.38 +      if ( pc.greaterThanOrEqual(base) && pc.lessThan(base.addOffsetTo(size))) {
    2.39 +        return ob;
    2.40 +      }
    2.41      }
    2.42 -    // no match found.
    2.43 +
    2.44      return null;
    2.45    }
    2.46  
     3.1 --- a/agent/src/share/classes/sun/jvm/hotspot/utilities/soql/sa.js	Wed Oct 25 13:11:07 2017 -0700
     3.2 +++ b/agent/src/share/classes/sun/jvm/hotspot/utilities/soql/sa.js	Wed Feb 12 23:39:53 2014 +0400
     3.3 @@ -371,19 +371,23 @@
     3.4     return sa.dbg.lookup(dso, sym);
     3.5  }
     3.6  
     3.7 +function loadObjectContainingPC(addr) {
     3.8 +    if (sa.cdbg == null) {
     3.9 +      // no CDebugger support, return null
    3.10 +      return null;
    3.11 +    }
    3.12 +
    3.13 +    return  sa.cdbg.loadObjectContainingPC(addr);
    3.14 +}
    3.15 +
    3.16  // returns the ClosestSymbol or null
    3.17  function closestSymbolFor(addr) {
    3.18 -   if (sa.cdbg == null) {
    3.19 -      // no CDebugger support, return null
    3.20 -      return null;
    3.21 -   } else {
    3.22 -      var dso = sa.cdbg.loadObjectContainingPC(addr);
    3.23 -      if (dso != null) {
    3.24 -         return dso.closestSymbolToPC(addr);
    3.25 -      } else {
    3.26 -         return null;
    3.27 -      }
    3.28 -   }
    3.29 +    var dso = loadObjectContainingPC(addr);
    3.30 +    if (dso != null) {
    3.31 +      return dso.closestSymbolToPC(addr);
    3.32 +    }
    3.33 +
    3.34 +    return null;
    3.35  }
    3.36  
    3.37  // Address-to-symbol
    3.38 @@ -884,21 +888,29 @@
    3.39  
    3.40  // returns description of given pointer as a String
    3.41  function whatis(addr) {
    3.42 -   addr = any2addr(addr);
    3.43 -   var ptrLoc = findPtr(addr);
    3.44 -   if (ptrLoc.isUnknown()) {
    3.45 -      var vmType = vmTypeof(addr);
    3.46 -      if (vmType != null) {
    3.47 -         return "pointer to " + vmType.name;
    3.48 -      } else {
    3.49 -         var sym = closestSymbolFor(addr);
    3.50 -         if (sym != null) {
    3.51 -            return sym.name + '+' + sym.offset;
    3.52 -         } else {
    3.53 -            return ptrLoc.toString();
    3.54 -         }
    3.55 -      }
    3.56 -   } else {
    3.57 -      return ptrLoc.toString();
    3.58 -   }
    3.59 +  addr = any2addr(addr);
    3.60 +  var ptrLoc = findPtr(addr);
    3.61 +  if (!ptrLoc.isUnknown()) {
    3.62 +    return ptrLoc.toString();
    3.63 +  }
    3.64 +
    3.65 +  var vmType = vmTypeof(addr);
    3.66 +  if (vmType != null) {
    3.67 +    return "pointer to " + vmType.name;
    3.68 +  }
    3.69 +
    3.70 +  var dso = loadObjectContainingPC(addr);
    3.71 +  if (dso == null) {
    3.72 +    return ptrLoc.toString();
    3.73 +  }
    3.74 +
    3.75 +  var sym = dso.closestSymbolToPC(addr);
    3.76 +  if (sym != null) {
    3.77 +    return sym.name + '+' + sym.offset;
    3.78 +  }
    3.79 +
    3.80 +  var s = dso.getName();
    3.81 +  var p = s.lastIndexOf("/");
    3.82 +  var base = dso.getBase();
    3.83 +  return s.substring(p+1, s.length) + '+' + addr.minus(base);
    3.84  }

mercurial