Merge
This commit is contained in:
commit
804e3ed06d
@ -29,54 +29,51 @@
|
|||||||
#include <thread_db.h>
|
#include <thread_db.h>
|
||||||
#include "libproc_impl.h"
|
#include "libproc_impl.h"
|
||||||
|
|
||||||
static const char* alt_root = NULL;
|
|
||||||
static int alt_root_len = -1;
|
|
||||||
|
|
||||||
#define SA_ALTROOT "SA_ALTROOT"
|
#define SA_ALTROOT "SA_ALTROOT"
|
||||||
|
|
||||||
static void init_alt_root() {
|
|
||||||
if (alt_root_len == -1) {
|
|
||||||
alt_root = getenv(SA_ALTROOT);
|
|
||||||
if (alt_root) {
|
|
||||||
alt_root_len = strlen(alt_root);
|
|
||||||
} else {
|
|
||||||
alt_root_len = 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
int pathmap_open(const char* name) {
|
int pathmap_open(const char* name) {
|
||||||
int fd;
|
static const char *alt_root = NULL;
|
||||||
char alt_path[PATH_MAX + 1];
|
static int alt_root_initialized = 0;
|
||||||
|
|
||||||
init_alt_root();
|
int fd;
|
||||||
|
char alt_path[PATH_MAX + 1], *alt_path_end;
|
||||||
|
const char *s;
|
||||||
|
|
||||||
if (alt_root_len > 0) {
|
if (!alt_root_initialized) {
|
||||||
strcpy(alt_path, alt_root);
|
alt_root_initialized = -1;
|
||||||
strcat(alt_path, name);
|
alt_root = getenv(SA_ALTROOT);
|
||||||
fd = open(alt_path, O_RDONLY);
|
}
|
||||||
if (fd >= 0) {
|
|
||||||
print_debug("path %s substituted for %s\n", alt_path, name);
|
|
||||||
return fd;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (strrchr(name, '/')) {
|
if (alt_root == NULL) {
|
||||||
strcpy(alt_path, alt_root);
|
return open(name, O_RDONLY);
|
||||||
strcat(alt_path, strrchr(name, '/'));
|
}
|
||||||
fd = open(alt_path, O_RDONLY);
|
|
||||||
if (fd >= 0) {
|
|
||||||
print_debug("path %s substituted for %s\n", alt_path, name);
|
|
||||||
return fd;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
fd = open(name, O_RDONLY);
|
|
||||||
if (fd >= 0) {
|
|
||||||
return fd;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return -1;
|
strcpy(alt_path, alt_root);
|
||||||
|
alt_path_end = alt_path + strlen(alt_path);
|
||||||
|
|
||||||
|
// Strip path items one by one and try to open file with alt_root prepended
|
||||||
|
s = name;
|
||||||
|
while (1) {
|
||||||
|
strcat(alt_path, s);
|
||||||
|
s += 1;
|
||||||
|
|
||||||
|
fd = open(alt_path, O_RDONLY);
|
||||||
|
if (fd >= 0) {
|
||||||
|
print_debug("path %s substituted for %s\n", alt_path, name);
|
||||||
|
return fd;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Linker always put full path to solib to process, so we can rely
|
||||||
|
// on presence of /. If slash is not present, it means, that SOlib doesn't
|
||||||
|
// physically exist (e.g. linux-gate.so) and we fail opening it anyway
|
||||||
|
if ((s = strchr(s, '/')) == NULL) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
*alt_path_end = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool _libsaproc_debug;
|
static bool _libsaproc_debug;
|
||||||
|
@ -55,31 +55,21 @@ class LinuxCDebugger implements CDebugger {
|
|||||||
if (pc == null) {
|
if (pc == null) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
List objs = getLoadObjectList();
|
|
||||||
Object[] arr = objs.toArray();
|
|
||||||
// load objects are sorted by base address, do binary search
|
|
||||||
int mid = -1;
|
|
||||||
int low = 0;
|
|
||||||
int high = arr.length - 1;
|
|
||||||
|
|
||||||
while (low <= high) {
|
/* Typically we have about ten loaded objects here. So no reason to do
|
||||||
mid = (low + high) >> 1;
|
sort/binary search here. Linear search gives us acceptable performance.*/
|
||||||
LoadObject midVal = (LoadObject) arr[mid];
|
|
||||||
long cmp = pc.minus(midVal.getBase());
|
List objs = getLoadObjectList();
|
||||||
if (cmp < 0) {
|
|
||||||
high = mid - 1;
|
for (int i = 0; i < objs.size(); i++) {
|
||||||
} else if (cmp > 0) {
|
LoadObject ob = (LoadObject) objs.get(i);
|
||||||
long size = midVal.getSize();
|
Address base = ob.getBase();
|
||||||
if (cmp >= size) {
|
long size = ob.getSize();
|
||||||
low = mid + 1;
|
if ( pc.greaterThanOrEqual(base) && pc.lessThan(base.addOffsetTo(size))) {
|
||||||
} else {
|
return ob;
|
||||||
return (LoadObject) arr[mid];
|
}
|
||||||
}
|
|
||||||
} else { // match found
|
|
||||||
return (LoadObject) arr[mid];
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
// no match found.
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -371,19 +371,23 @@ function sym2addr(dso, sym) {
|
|||||||
return sa.dbg.lookup(dso, sym);
|
return sa.dbg.lookup(dso, sym);
|
||||||
}
|
}
|
||||||
|
|
||||||
// returns the ClosestSymbol or null
|
function loadObjectContainingPC(addr) {
|
||||||
function closestSymbolFor(addr) {
|
if (sa.cdbg == null) {
|
||||||
if (sa.cdbg == null) {
|
|
||||||
// no CDebugger support, return null
|
// no CDebugger support, return null
|
||||||
return null;
|
return null;
|
||||||
} else {
|
}
|
||||||
var dso = sa.cdbg.loadObjectContainingPC(addr);
|
|
||||||
if (dso != null) {
|
return sa.cdbg.loadObjectContainingPC(addr);
|
||||||
return dso.closestSymbolToPC(addr);
|
}
|
||||||
} else {
|
|
||||||
return null;
|
// returns the ClosestSymbol or null
|
||||||
}
|
function closestSymbolFor(addr) {
|
||||||
}
|
var dso = loadObjectContainingPC(addr);
|
||||||
|
if (dso != null) {
|
||||||
|
return dso.closestSymbolToPC(addr);
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Address-to-symbol
|
// Address-to-symbol
|
||||||
@ -884,21 +888,29 @@ function isOop(addr) {
|
|||||||
|
|
||||||
// returns description of given pointer as a String
|
// returns description of given pointer as a String
|
||||||
function whatis(addr) {
|
function whatis(addr) {
|
||||||
addr = any2addr(addr);
|
addr = any2addr(addr);
|
||||||
var ptrLoc = findPtr(addr);
|
var ptrLoc = findPtr(addr);
|
||||||
if (ptrLoc.isUnknown()) {
|
if (!ptrLoc.isUnknown()) {
|
||||||
var vmType = vmTypeof(addr);
|
return ptrLoc.toString();
|
||||||
if (vmType != null) {
|
}
|
||||||
return "pointer to " + vmType.name;
|
|
||||||
} else {
|
var vmType = vmTypeof(addr);
|
||||||
var sym = closestSymbolFor(addr);
|
if (vmType != null) {
|
||||||
if (sym != null) {
|
return "pointer to " + vmType.name;
|
||||||
return sym.name + '+' + sym.offset;
|
}
|
||||||
} else {
|
|
||||||
return ptrLoc.toString();
|
var dso = loadObjectContainingPC(addr);
|
||||||
}
|
if (dso == null) {
|
||||||
}
|
return ptrLoc.toString();
|
||||||
} else {
|
}
|
||||||
return ptrLoc.toString();
|
|
||||||
}
|
var sym = dso.closestSymbolToPC(addr);
|
||||||
|
if (sym != null) {
|
||||||
|
return sym.name + '+' + sym.offset;
|
||||||
|
}
|
||||||
|
|
||||||
|
var s = dso.getName();
|
||||||
|
var p = s.lastIndexOf("/");
|
||||||
|
var base = dso.getBase();
|
||||||
|
return s.substring(p+1, s.length) + '+' + addr.minus(base);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user