- Loading...
Here are the hotspot agent changes linux vs bsd:
diff -rus agent/src/os/linux/Makefile agent/src/os/bsd/Makefile
--- agent/src/os/linux/Makefile 2011-07-26 20:21:17.000000000 -0600
+++ agent/src/os/bsd/Makefile 2011-07-26 20:21:17.000000000 -0600
@@ -22,7 +22,7 @@
#
#
-ARCH := $(shell if ([ `uname -m` = "ia64" ]) ; then echo ia64 ; elif ([ `uname -m` = "x86_64" ]) ; then echo amd64; elif ([ `uname -m` = "sparc64" ]) ; then echo sparc; else echo i386 ; fi )
+ARCH := $(shell if ([ `uname -m` = "ia64" ]) ; then echo ia64 ; elif ([ `uname -m` = "amd64" ]) ; then echo amd64; elif ([ `uname -m` = "sparc64" ]) ; then echo sparc; else echo i386 ; fi )
GCC = gcc
JAVAH = ${JAVA_HOME}/bin/javah
@@ -32,25 +32,25 @@
libproc_impl.c \
ps_proc.c \
ps_core.c \
- LinuxDebuggerLocal.c
+ hsearch_r.c \
+ BsdDebuggerLocal.c
-INCLUDES = -I${JAVA_HOME}/include -I${JAVA_HOME}/include/linux
+INCLUDES = -I${JAVA_HOME}/include -I${JAVA_HOME}/include/$(shell uname -s | tr "[:upper:]" "[:lower:]")
OBJS = $(SOURCES:.c=.o)
-LIBS = -lthread_db
+LIBS = -lutil -lthread_db
-CFLAGS = -c -fPIC -g -D_GNU_SOURCE -D$(ARCH) $(INCLUDES)
+CFLAGS = -c -fPIC -g -Wall -D_ALLBSD_SOURCE -D_GNU_SOURCE -D$(ARCH) $(INCLUDES)
LIBSA = $(ARCH)/libsaproc.so
all: $(LIBSA)
-LinuxDebuggerLocal.o: LinuxDebuggerLocal.c
- $(JAVAH) -jni -classpath ../../../build/classes \
+BsdDebuggerLocal.o: BsdDebuggerLocal.c
+ $(JAVAH) -jni -classpath ../../../../../build/bsd-i586/hotspot/outputdir/bsd_i486_compiler2/generated/saclasses \
sun.jvm.hotspot.debugger.x86.X86ThreadContext \
- sun.jvm.hotspot.debugger.sparc.SPARCThreadContext \
- sun.jvm.hotspot.debugger.amd64.AMD64ThreadContext
+ sun.jvm.hotspot.debugger.amd64.AMD64ThreadContext
$(GCC) $(CFLAGS) $<
.c.obj:
@@ -60,26 +60,19 @@
LFLAGS_LIBSA = -Xlinker --version-script=mapfile
endif
-# If this is a --hash-style=gnu system, use --hash-style=both
-# The gnu .hash section won't work on some Linux systems like SuSE 10.
-_HAS_HASH_STYLE_GNU:=$(shell $(CC) -dumpspecs | grep -- '--hash-style=gnu')
-ifneq ($(_HAS_HASH_STYLE_GNU),)
- LDFLAGS_HASH_STYLE = -Wl,--hash-style=both
-endif
-LFLAGS_LIBSA += $(LDFLAGS_HASH_STYLE)
-
$(LIBSA): $(OBJS) mapfile
if [ ! -d $(ARCH) ] ; then mkdir $(ARCH) ; fi
$(GCC) -shared $(LFLAGS_LIBSA) -o $(LIBSA) $(OBJS) $(LIBS)
-test.o: test.c
+test.o: $(LIBSA) test.c
$(GCC) -c -o test.o -g -D_GNU_SOURCE -D$(ARCH) $(INCLUDES) test.c
test: test.o
$(GCC) -o test test.o -L$(ARCH) -lsaproc $(LIBS)
clean:
- rm -rf $(LIBSA)
- rm -rf $(OBJS)
- rmdir $(ARCH)
+ rm -f $(LIBSA)
+ rm -f $(OBJS)
+ rm -f test.o
+ -rmdir $(ARCH)
Only in agent/src/os/bsd: StubDebuggerLocal.c
diff -rus agent/src/os/linux/elfmacros.h agent/src/os/bsd/elfmacros.h
--- agent/src/os/linux/elfmacros.h 2011-07-26 20:21:17.000000000 -0600
+++ agent/src/os/bsd/elfmacros.h 2011-07-26 20:21:17.000000000 -0600
@@ -25,16 +25,19 @@
#ifndef _ELFMACROS_H_
#define _ELFMACROS_H_
+#define ELF_NHDR Elf_Note
+
#if defined(_LP64)
#define ELF_EHDR Elf64_Ehdr
#define ELF_SHDR Elf64_Shdr
#define ELF_PHDR Elf64_Phdr
#define ELF_SYM Elf64_Sym
-#define ELF_NHDR Elf64_Nhdr
#define ELF_DYN Elf64_Dyn
#define ELF_ADDR Elf64_Addr
+#ifndef ELF_ST_TYPE
#define ELF_ST_TYPE ELF64_ST_TYPE
+#endif
#else
@@ -42,11 +45,12 @@
#define ELF_SHDR Elf32_Shdr
#define ELF_PHDR Elf32_Phdr
#define ELF_SYM Elf32_Sym
-#define ELF_NHDR Elf32_Nhdr
#define ELF_DYN Elf32_Dyn
#define ELF_ADDR Elf32_Addr
+#ifndef ELF_ST_TYPE
#define ELF_ST_TYPE ELF32_ST_TYPE
+#endif
#endif
Only in agent/src/os/bsd: hsearch_r.c
Only in agent/src/os/bsd: hsearch_r.h
diff -rus agent/src/os/linux/libproc.h agent/src/os/bsd/libproc.h
--- agent/src/os/linux/libproc.h 2011-07-26 20:21:17.000000000 -0600
+++ agent/src/os/bsd/libproc.h 2011-07-26 20:21:17.000000000 -0600
@@ -27,7 +27,8 @@
#include <unistd.h>
#include <stdint.h>
-#include "proc_service.h"
+#include <machine/reg.h>
+#include <proc_service.h>
#if defined(sparc) || defined(sparcv9)
/*
@@ -50,14 +51,11 @@
adds Pgrab__ and some missing stuff. We hide the difference b/w live process and core
file by this interface.
-1. pthread_id unique in both NPTL & LinuxThreads. We store this in
-OSThread::_pthread_id in JVM code.
+1. pthread_id is unique. We store this in OSThread::_pthread_id in JVM code.
-2. All threads see the same pid when they call getpid() under NPTL.
-Threads receive different pid under LinuxThreads. We used to save the result of
-::getpid() call in OSThread::_thread_id. This way uniqueness of OSThread::_thread_id
-was lost under NPTL. Now, we store the result of ::gettid() call in
-OSThread::_thread_id. Because gettid returns actual pid of thread (lwp id), this is
+2. All threads see the same pid when they call getpid().
+We used to save the result of ::getpid() call in OSThread::_thread_id.
+Because gettid returns actual pid of thread (lwp id), this is
unique again. We therefore use OSThread::_thread_id as unique identifier.
3. There is a unique LWP id under both thread libraries. libthread_db maps pthread_id
@@ -74,20 +72,7 @@
*************************************************************************************/
-#ifdef ia64
-struct user_regs_struct {
-/* copied from user.h which doesn't define this in a struct */
-
-#define IA64_REG_COUNT (EF_SIZE/8+32) /* integer and fp regs */
-unsigned long regs[IA64_REG_COUNT]; /* integer and fp regs */
-};
-#endif
-
-#if defined(sparc) || defined(sparcv9)
-#define user_regs_struct pt_regs
-#endif
-
-// This C bool type must be int for compatibility with Linux calls and
+// This C bool type must be int for compatibility with BSD calls and
// it would be a mistake to equivalence it to C++ bool on many platforms
typedef int bool;
@@ -118,7 +103,7 @@
lwpid_t get_lwp_id(struct ps_prochandle* ph, int index);
// get regs for a given lwp
-bool get_lwp_regs(struct ps_prochandle* ph, lwpid_t lid, struct user_regs_struct* regs);
+bool get_lwp_regs(struct ps_prochandle* ph, lwpid_t lid, struct reg* regs);
// get number of shared objects
int get_num_libs(struct ps_prochandle* ph);
diff -rus agent/src/os/linux/libproc_impl.c agent/src/os/bsd/libproc_impl.c
--- agent/src/os/linux/libproc_impl.c 2011-07-26 20:21:17.000000000 -0600
+++ agent/src/os/bsd/libproc_impl.c 2011-07-26 20:21:17.000000000 -0600
@@ -174,10 +174,13 @@
return NULL;
}
- newlib->symtab = build_symtab(newlib->fd, libname);
+ newlib->symtab = build_symtab(newlib->fd);
if (newlib->symtab == NULL) {
print_debug("symbol table build failed for %s\n", newlib->name);
}
+ else {
+ print_debug("built symbol table for %s\n", newlib->name);
+ }
// even if symbol table building fails, we add the lib_info.
// This is because we may need to read from the ELF file for core file
@@ -272,7 +275,7 @@
print_debug("thread_db : pthread %d (lwp %d)\n", ti.ti_tid, ti.ti_lid);
- if (ptr->callback(ptr->ph, ti.ti_tid, ti.ti_lid) != true)
+ if (ptr->callback(ptr->ph, (pthread_t)ti.ti_tid, ti.ti_lid) != true)
return TD_ERR;
return TD_OK;
@@ -324,7 +327,7 @@
}
// get regs for a given lwp
-bool get_lwp_regs(struct ps_prochandle* ph, lwpid_t lwp_id, struct user_regs_struct* regs) {
+bool get_lwp_regs(struct ps_prochandle* ph, lwpid_t lwp_id, struct reg* regs) {
return ph->ops->get_lwp_regs(ph, lwp_id, regs);
}
@@ -375,11 +378,6 @@
//--------------------------------------------------------------------------
// proc service functions
-// get process id
-pid_t ps_getpid(struct ps_prochandle *ph) {
- return ph->pid;
-}
-
// ps_pglobal_lookup() looks up the symbol sym_name in the symbol table
// of the load object object_name in the target process identified by ph.
// It returns the symbol's value as an address in the target process in
@@ -392,17 +390,33 @@
}
// read "size" bytes info "buf" from address "addr"
-ps_err_e ps_pdread(struct ps_prochandle *ph, psaddr_t addr,
- void *buf, size_t size) {
+ps_err_e ps_pread(struct ps_prochandle *ph, psaddr_t addr,
+ void *buf, size_t size) {
return ph->ops->p_pread(ph, (uintptr_t) addr, buf, size)? PS_OK: PS_ERR;
}
// write "size" bytes of data to debuggee at address "addr"
-ps_err_e ps_pdwrite(struct ps_prochandle *ph, psaddr_t addr,
- const void *buf, size_t size) {
+ps_err_e ps_pwrite(struct ps_prochandle *ph, psaddr_t addr,
+ const void *buf, size_t size) {
return ph->ops->p_pwrite(ph, (uintptr_t)addr, buf, size)? PS_OK: PS_ERR;
}
+// fill in ptrace_lwpinfo for lid
+ps_err_e ps_linfo(struct ps_prochandle *ph, lwpid_t lwp_id, void *linfo) {
+ return ph->ops->get_lwp_info(ph, lwp_id, linfo)? PS_OK: PS_ERR;
+}
+
+// needed for when libthread_db is compiled with TD_DEBUG defined
+void
+ps_plog (const char *format, ...)
+{
+ va_list alist;
+
+ va_start(alist, format);
+ vfprintf(stderr, format, alist);
+ va_end(alist);
+}
+
// ------------------------------------------------------------------------
// Functions below this point are not yet implemented. They are here only
// to make the linker happy.
@@ -427,8 +441,12 @@
return PS_OK;
}
-// new libthread_db of NPTL seem to require this symbol
-ps_err_e ps_get_thread_area() {
- print_debug("ps_get_thread_area not implemented\n");
+ps_err_e ps_lstop(struct ps_prochandle *ph, lwpid_t lid) {
+ print_debug("ps_lstop not implemented\n");
+ return PS_OK;
+}
+
+ps_err_e ps_pcontinue(struct ps_prochandle *ph) {
+ print_debug("ps_pcontinue not implemented\n");
return PS_OK;
}
diff -rus agent/src/os/linux/libproc_impl.h agent/src/os/bsd/libproc_impl.h
--- agent/src/os/linux/libproc_impl.h 2011-07-26 20:21:17.000000000 -0600
+++ agent/src/os/bsd/libproc_impl.h 2011-07-26 20:21:17.000000000 -0600
@@ -47,7 +47,7 @@
typedef struct thread_info {
lwpid_t lwp_id;
pthread_t pthread_id; // not used cores, always -1
- struct user_regs_struct regs; // not for process, core uses for caching regset
+ struct reg regs; // not for process, core uses for caching regset
struct thread_info* next;
} thread_info;
@@ -71,7 +71,9 @@
bool (*p_pwrite)(struct ps_prochandle *ph,
uintptr_t addr, const char *buf , size_t size);
// get integer regset of a thread
- bool (*get_lwp_regs)(struct ps_prochandle* ph, lwpid_t lwp_id, struct user_regs_struct* regs);
+ bool (*get_lwp_regs)(struct ps_prochandle* ph, lwpid_t lwp_id, struct reg* regs);
+ // get info on thread
+ bool (*get_lwp_info)(struct ps_prochandle *ph, lwpid_t lwp_id, void *linfo);
} ps_prochandle_ops;
// the ps_prochandle
@@ -79,7 +81,7 @@
struct core_data {
int core_fd; // file descriptor of core file
int exec_fd; // file descriptor of exec file
- int interp_fd; // file descriptor of interpreter (ld-linux.so.2)
+ int interp_fd; // file descriptor of interpreter (ld-elf.so.1)
// part of the class sharing workaround
int classes_jsa_fd; // file descriptor of class share archive
uintptr_t dynamic_addr; // address of dynamic section of a.out
diff -rus agent/src/os/linux/mapfile agent/src/os/bsd/mapfile
--- agent/src/os/linux/mapfile 2011-07-26 20:21:17.000000000 -0600
+++ agent/src/os/bsd/mapfile 2011-07-26 20:21:17.000000000 -0600
@@ -29,27 +29,31 @@
SUNWprivate_1.1 {
global:
- # native methods of LinuxDebuggerLocal class
- Java_sun_jvm_hotspot_debugger_linux_LinuxDebuggerLocal_init0;
- Java_sun_jvm_hotspot_debugger_linux_LinuxDebuggerLocal_getAddressSize;
- Java_sun_jvm_hotspot_debugger_linux_LinuxDebuggerLocal_attach0__I;
- Java_sun_jvm_hotspot_debugger_linux_LinuxDebuggerLocal_attach0__Ljava_lang_String_2Ljava_lang_String_2;
- Java_sun_jvm_hotspot_debugger_linux_LinuxDebuggerLocal_detach0;
- Java_sun_jvm_hotspot_debugger_linux_LinuxDebuggerLocal_lookupByName0;
- Java_sun_jvm_hotspot_debugger_linux_LinuxDebuggerLocal_lookupByAddress0;
- Java_sun_jvm_hotspot_debugger_linux_LinuxDebuggerLocal_readBytesFromProcess0;
- Java_sun_jvm_hotspot_debugger_linux_LinuxDebuggerLocal_getThreadIntegerRegisterSet0;
+ # native methods of BsdDebuggerLocal class
+ Java_sun_jvm_hotspot_debugger_bsd_BsdDebuggerLocal_init0;
+ Java_sun_jvm_hotspot_debugger_bsd_BsdDebuggerLocal_getAddressSize;
+ Java_sun_jvm_hotspot_debugger_bsd_BsdDebuggerLocal_attach0__I;
+ Java_sun_jvm_hotspot_debugger_bsd_BsdDebuggerLocal_attach0__Ljava_lang_String_2Ljava_lang_String_2;
+ Java_sun_jvm_hotspot_debugger_bsd_BsdDebuggerLocal_detach0;
+ Java_sun_jvm_hotspot_debugger_bsd_BsdDebuggerLocal_lookupByName0;
+ Java_sun_jvm_hotspot_debugger_bsd_BsdDebuggerLocal_lookupByAddress0;
+ Java_sun_jvm_hotspot_debugger_bsd_BsdDebuggerLocal_readBytesFromProcess0;
+ Java_sun_jvm_hotspot_debugger_bsd_BsdDebuggerLocal_getThreadIntegerRegisterSet0;
# proc_service.h functions - to be used by libthread_db
ps_getpid;
ps_pglobal_lookup;
- ps_pdread;
- ps_pdwrite;
+ ps_pread;
+ ps_pwrite;
ps_lsetfpregs;
ps_lsetregs;
ps_lgetfpregs;
ps_lgetregs;
- ps_get_thread_area;
+ ps_lcontinue;
+ ps_lgetxmmregs;
+ ps_lsetxmmregs;
+ ps_lstop;
+ ps_linfo;
# used by attach test program
init_libproc;
Only in agent/src/os/linux: proc_service.h
diff -rus agent/src/os/linux/ps_core.c agent/src/os/bsd/ps_core.c
--- agent/src/os/linux/ps_core.c 2011-07-26 20:21:17.000000000 -0600
+++ agent/src/os/bsd/ps_core.c 2011-07-26 20:21:17.000000000 -0600
@@ -142,6 +142,7 @@
map->next = ph->core->class_share_maps;
ph->core->class_share_maps = map;
+ return map;
}
// Return the map_info for the given virtual address. We keep a sorted
@@ -228,8 +229,8 @@
// 4991491 NOTICE These are C++ bool's in filemap.hpp and must match up with
// the C type matching the C++ bool type on any given platform. For
- // Hotspot on Linux we assume the corresponding C type is char but
- // licensees on Linux versions may need to adjust the type of these fields.
+ // Hotspot on BSD we assume the corresponding C type is char but
+ // licensees on BSD versions may need to adjust the type of these fields.
char _read_only; // read only space?
char _allow_exec; // executable code in space?
@@ -240,7 +241,7 @@
static bool read_jboolean(struct ps_prochandle* ph, uintptr_t addr, jboolean* pvalue) {
jboolean i;
- if (ps_pdread(ph, (psaddr_t) addr, &i, sizeof(i)) == PS_OK) {
+ if (ps_pread(ph, (psaddr_t) addr, &i, sizeof(i)) == PS_OK) {
*pvalue = i;
return true;
} else {
@@ -250,7 +251,7 @@
static bool read_pointer(struct ps_prochandle* ph, uintptr_t addr, uintptr_t* pvalue) {
uintptr_t uip;
- if (ps_pdread(ph, (psaddr_t) addr, &uip, sizeof(uip)) == PS_OK) {
+ if (ps_pread(ph, (psaddr_t) addr, &uip, sizeof(uip)) == PS_OK) {
*pvalue = uip;
return true;
} else {
@@ -264,7 +265,7 @@
char c = ' ';
while (c != '\0') {
- if (ps_pdread(ph, (psaddr_t) addr, &c, sizeof(char)) != PS_OK)
+ if (ps_pread(ph, (psaddr_t) addr, &c, sizeof(char)) != PS_OK)
return false;
if (i < size - 1)
buf[i] = c;
@@ -296,7 +297,6 @@
uintptr_t base = 0, useSharedSpacesAddr = 0;
uintptr_t sharedArchivePathAddrAddr = 0, sharedArchivePathAddr = 0;
jboolean useSharedSpaces = 0;
- map_info* mi = 0;
memset(classes_jsa, 0, sizeof(classes_jsa));
jvm_name = lib->name;
@@ -306,9 +306,9 @@
return false;
}
- // Hotspot vm types are not exported to build this library. So
- // using equivalent type jboolean to read the value of
- // UseSharedSpaces which is same as hotspot type "bool".
+ // Hotspot vm types are not exported to build this library. So
+ // using equivalent type jboolean to read the value of
+ // UseSharedSpaces which is same as hotspot type "bool".
if (read_jboolean(ph, useSharedSpacesAddr, &useSharedSpaces) != true) {
print_debug("can't read the value of 'UseSharedSpaces' flag\n");
return false;
@@ -507,12 +507,12 @@
}
static bool core_get_lwp_regs(struct ps_prochandle* ph, lwpid_t lwp_id,
- struct user_regs_struct* regs) {
+ struct reg* regs) {
// for core we have cached the lwp regs from NOTE section
thread_info* thr = ph->threads;
while (thr) {
if (thr->lwp_id == lwp_id) {
- memcpy(regs, &thr->regs, sizeof(struct user_regs_struct));
+ memcpy(regs, &thr->regs, sizeof(struct reg));
return true;
}
thr = thr->next;
@@ -520,11 +520,17 @@
return false;
}
+static bool core_get_lwp_info(struct ps_prochandle *ph, lwpid_t lwp_id, void *linfo) {
+ print_debug("core_get_lwp_info not implemented\n");
+ return false;
+}
+
static ps_prochandle_ops core_ops = {
.release= core_release,
.p_pread= core_read_data,
.p_pwrite= core_write_data,
- .get_lwp_regs= core_get_lwp_regs
+ .get_lwp_regs= core_get_lwp_regs,
+ .get_lwp_info= core_get_lwp_info
};
// read regs and create thread from NT_PRSTATUS entries from core file
@@ -539,52 +545,52 @@
return false;
// copy regs
- memcpy(&newthr->regs, prstat->pr_reg, sizeof(struct user_regs_struct));
+ memcpy(&newthr->regs, &prstat->pr_reg, sizeof(struct reg));
if (is_debug()) {
print_debug("integer regset\n");
#ifdef i386
// print the regset
- print_debug("\teax = 0x%x\n", newthr->regs.eax);
- print_debug("\tebx = 0x%x\n", newthr->regs.ebx);
- print_debug("\tecx = 0x%x\n", newthr->regs.ecx);
- print_debug("\tedx = 0x%x\n", newthr->regs.edx);
- print_debug("\tesp = 0x%x\n", newthr->regs.esp);
- print_debug("\tebp = 0x%x\n", newthr->regs.ebp);
- print_debug("\tesi = 0x%x\n", newthr->regs.esi);
- print_debug("\tedi = 0x%x\n", newthr->regs.edi);
- print_debug("\teip = 0x%x\n", newthr->regs.eip);
+ print_debug("\teax = 0x%x\n", newthr->regs.r_eax);
+ print_debug("\tebx = 0x%x\n", newthr->regs.r_ebx);
+ print_debug("\tecx = 0x%x\n", newthr->regs.r_ecx);
+ print_debug("\tedx = 0x%x\n", newthr->regs.r_edx);
+ print_debug("\tesp = 0x%x\n", newthr->regs.r_esp);
+ print_debug("\tebp = 0x%x\n", newthr->regs.r_ebp);
+ print_debug("\tesi = 0x%x\n", newthr->regs.r_esi);
+ print_debug("\tedi = 0x%x\n", newthr->regs.r_edi);
+ print_debug("\teip = 0x%x\n", newthr->regs.r_eip);
#endif
#if defined(amd64) || defined(x86_64)
// print the regset
- print_debug("\tr15 = 0x%lx\n", newthr->regs.r15);
- print_debug("\tr14 = 0x%lx\n", newthr->regs.r14);
- print_debug("\tr13 = 0x%lx\n", newthr->regs.r13);
- print_debug("\tr12 = 0x%lx\n", newthr->regs.r12);
- print_debug("\trbp = 0x%lx\n", newthr->regs.rbp);
- print_debug("\trbx = 0x%lx\n", newthr->regs.rbx);
- print_debug("\tr11 = 0x%lx\n", newthr->regs.r11);
- print_debug("\tr10 = 0x%lx\n", newthr->regs.r10);
- print_debug("\tr9 = 0x%lx\n", newthr->regs.r9);
- print_debug("\tr8 = 0x%lx\n", newthr->regs.r8);
- print_debug("\trax = 0x%lx\n", newthr->regs.rax);
- print_debug("\trcx = 0x%lx\n", newthr->regs.rcx);
- print_debug("\trdx = 0x%lx\n", newthr->regs.rdx);
- print_debug("\trsi = 0x%lx\n", newthr->regs.rsi);
- print_debug("\trdi = 0x%lx\n", newthr->regs.rdi);
- print_debug("\torig_rax = 0x%lx\n", newthr->regs.orig_rax);
- print_debug("\trip = 0x%lx\n", newthr->regs.rip);
- print_debug("\tcs = 0x%lx\n", newthr->regs.cs);
- print_debug("\teflags = 0x%lx\n", newthr->regs.eflags);
- print_debug("\trsp = 0x%lx\n", newthr->regs.rsp);
- print_debug("\tss = 0x%lx\n", newthr->regs.ss);
- print_debug("\tfs_base = 0x%lx\n", newthr->regs.fs_base);
- print_debug("\tgs_base = 0x%lx\n", newthr->regs.gs_base);
- print_debug("\tds = 0x%lx\n", newthr->regs.ds);
- print_debug("\tes = 0x%lx\n", newthr->regs.es);
- print_debug("\tfs = 0x%lx\n", newthr->regs.fs);
- print_debug("\tgs = 0x%lx\n", newthr->regs.gs);
+ print_debug("\tr15 = 0x%lx\n", newthr->regs.r_r15);
+ print_debug("\tr14 = 0x%lx\n", newthr->regs.r_r14);
+ print_debug("\tr13 = 0x%lx\n", newthr->regs.r_r13);
+ print_debug("\tr12 = 0x%lx\n", newthr->regs.r_r12);
+ print_debug("\trbp = 0x%lx\n", newthr->regs.r_rbp);
+ print_debug("\trbx = 0x%lx\n", newthr->regs.r_rbx);
+ print_debug("\tr11 = 0x%lx\n", newthr->regs.r_r11);
+ print_debug("\tr10 = 0x%lx\n", newthr->regs.r_r10);
+ print_debug("\tr9 = 0x%lx\n", newthr->regs.r_r9);
+ print_debug("\tr8 = 0x%lx\n", newthr->regs.r_r8);
+ print_debug("\trax = 0x%lx\n", newthr->regs.r_rax);
+ print_debug("\trcx = 0x%lx\n", newthr->regs.r_rcx);
+ print_debug("\trdx = 0x%lx\n", newthr->regs.r_rdx);
+ print_debug("\trsi = 0x%lx\n", newthr->regs.r_rsi);
+ print_debug("\trdi = 0x%lx\n", newthr->regs.r_rdi);
+ //print_debug("\torig_rax = 0x%lx\n", newthr->regs.orig_rax);
+ print_debug("\trip = 0x%lx\n", newthr->regs.r_rip);
+ print_debug("\tcs = 0x%lx\n", newthr->regs.r_cs);
+ //print_debug("\teflags = 0x%lx\n", newthr->regs.eflags);
+ print_debug("\trsp = 0x%lx\n", newthr->regs.r_rsp);
+ print_debug("\tss = 0x%lx\n", newthr->regs.r_ss);
+ //print_debug("\tfs_base = 0x%lx\n", newthr->regs.fs_base);
+ //print_debug("\tgs_base = 0x%lx\n", newthr->regs.gs_base);
+ //print_debug("\tds = 0x%lx\n", newthr->regs.ds);
+ //print_debug("\tes = 0x%lx\n", newthr->regs.es);
+ //print_debug("\tfs = 0x%lx\n", newthr->regs.fs);
+ //print_debug("\tgs = 0x%lx\n", newthr->regs.gs);
#endif
}
@@ -656,7 +662,7 @@
* contains a set of saved /proc structures), and PT_LOAD (which
* represents a memory mapping from the process's address space).
*
- * Difference b/w Solaris PT_NOTE and Linux PT_NOTE:
+ * Difference b/w Solaris PT_NOTE and BSD PT_NOTE:
*
* In Solaris there are two PT_NOTE segments the first PT_NOTE (if present)
* contains /proc structs in the pre-2.6 unstructured /proc format. the last
@@ -725,7 +731,7 @@
return false;
}
-// process segments from interpreter (ld.so or ld-linux.so)
+// process segments from interpreter (ld-elf.so.1)
static bool read_interp_segments(struct ps_prochandle* ph) {
ELF_EHDR interp_ehdr;
@@ -826,7 +832,7 @@
dyn.d_tag = DT_NULL;
while (dyn.d_tag != DT_DEBUG) {
- if (ps_pdread(ph, (psaddr_t) addr, &dyn, sizeof(ELF_DYN)) != PS_OK) {
+ if (ps_pread(ph, (psaddr_t) addr, &dyn, sizeof(ELF_DYN)) != PS_OK) {
print_debug("can't read debug info from _DYNAMIC\n");
return false;
}
@@ -836,23 +842,27 @@
// we have got Dyn entry with DT_DEBUG
debug_base = dyn.d_un.d_ptr;
// at debug_base we have struct r_debug. This has first link map in r_map field
- if (ps_pdread(ph, (psaddr_t) debug_base + FIRST_LINK_MAP_OFFSET,
+ if (ps_pread(ph, (psaddr_t) debug_base + FIRST_LINK_MAP_OFFSET,
&first_link_map_addr, sizeof(uintptr_t)) != PS_OK) {
print_debug("can't read first link map address\n");
return false;
}
// read ld_base address from struct r_debug
- if (ps_pdread(ph, (psaddr_t) debug_base + LD_BASE_OFFSET, &ld_base_addr,
+ // XXX: There is no r_ldbase member on BSD
+/*
+ if (ps_pread(ph, (psaddr_t) debug_base + LD_BASE_OFFSET, &ld_base_addr,
sizeof(uintptr_t)) != PS_OK) {
print_debug("can't read ld base address\n");
return false;
}
ph->core->ld_base_addr = ld_base_addr;
+*/
+ ph->core->ld_base_addr = 0;
print_debug("interpreter base address is 0x%lx\n", ld_base_addr);
- // now read segments from interp (i.e ld.so or ld-linux.so)
+ // now read segments from interp (i.e ld-elf.so.1)
if (read_interp_segments(ph) != true)
return false;
@@ -870,26 +880,23 @@
// address mentioned in shared object and the actual virtual base where runtime
// linker loaded it. We use "base diff" in read_lib_segments call below.
- if (ps_pdread(ph, (psaddr_t) link_map_addr + LINK_MAP_ADDR_OFFSET,
+ if (ps_pread(ph, (psaddr_t) link_map_addr + LINK_MAP_ADDR_OFFSET,
&lib_base_diff, sizeof(uintptr_t)) != PS_OK) {
print_debug("can't read shared object base address diff\n");
return false;
}
// read address of the name
- if (ps_pdread(ph, (psaddr_t) link_map_addr + LINK_MAP_NAME_OFFSET,
+ if (ps_pread(ph, (psaddr_t) link_map_addr + LINK_MAP_NAME_OFFSET,
&lib_name_addr, sizeof(uintptr_t)) != PS_OK) {
print_debug("can't read address of shared object name\n");
return false;
}
// read name of the shared object
- lib_name[0] = '\0';
- if (lib_name_addr != 0 &&
- read_string(ph, (uintptr_t) lib_name_addr, lib_name, sizeof(lib_name)) != true) {
+ if (read_string(ph, (uintptr_t) lib_name_addr, lib_name, sizeof(lib_name)) != true) {
print_debug("can't read shared object name\n");
- // don't let failure to read the name stop opening the file. If something is really wrong
- // it will fail later.
+ return false;
}
if (lib_name[0] != '\0') {
@@ -924,7 +931,7 @@
}
// read next link_map address
- if (ps_pdread(ph, (psaddr_t) link_map_addr + LINK_MAP_NEXT_OFFSET,
+ if (ps_pread(ph, (psaddr_t) link_map_addr + LINK_MAP_NEXT_OFFSET,
&link_map_addr, sizeof(uintptr_t)) != PS_OK) {
print_debug("can't read next link in link_map\n");
return false;
@@ -938,7 +945,6 @@
struct ps_prochandle* Pgrab_core(const char* exec_file, const char* core_file) {
ELF_EHDR core_ehdr;
ELF_EHDR exec_ehdr;
- ELF_EHDR lib_ehdr;
struct ps_prochandle* ph = (struct ps_prochandle*) calloc(1, sizeof(struct ps_prochandle));
if (ph == NULL) {
diff -rus agent/src/os/linux/ps_proc.c agent/src/os/bsd/ps_proc.c
--- agent/src/os/linux/ps_proc.c 2011-07-26 20:21:17.000000000 -0600
+++ agent/src/os/bsd/ps_proc.c 2011-07-26 20:21:17.000000000 -0600
@@ -22,20 +22,22 @@
*
*/
+#include <limits.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
+#include <sys/types.h>
+#include <sys/wait.h>
#include <sys/ptrace.h>
+#include <sys/param.h>
+#include <sys/user.h>
+#include <elf.h>
+#include <sys/elf_common.h>
+#include <sys/link_elf.h>
+#include <libutil.h>
#include "libproc_impl.h"
-
-#if defined(x86_64) && !defined(amd64)
-#define amd64 1
-#endif
-
-#ifndef __WALL
-#define __WALL 0x40000000 // Copied from /usr/include/linux/wait.h
-#endif
+#include "elfmacros.h"
// This file has the libproc implementation specific to live process
// For core files, refer to ps_core.c
@@ -50,253 +52,359 @@
// read "size" bytes of data from "addr" within the target process.
// unlike the standard ptrace() function, process_read_data() can handle
-// unaligned address - alignment check, if required, should be done
+// unaligned address - alignment check, if required, should be done
// before calling process_read_data.
static bool process_read_data(struct ps_prochandle* ph, uintptr_t addr, char *buf, size_t size) {
- long rslt;
+ int rslt;
size_t i, words;
uintptr_t end_addr = addr + size;
- uintptr_t aligned_addr = align(addr, sizeof(long));
+ uintptr_t aligned_addr = align(addr, sizeof(int));
if (aligned_addr != addr) {
char *ptr = (char *)&rslt;
errno = 0;
- rslt = ptrace(PTRACE_PEEKDATA, ph->pid, aligned_addr, 0);
+ rslt = ptrace(PT_READ_D, ph->pid, (caddr_t) aligned_addr, 0);
if (errno) {
- print_debug("ptrace(PTRACE_PEEKDATA, ..) failed for %d bytes @ %lx\n", size, addr);
+ print_debug("ptrace(PT_READ_D, ..) failed for %d bytes @ %lx\n", size, addr);
return false;
}
for (; aligned_addr != addr; aligned_addr++, ptr++);
- for (; ((intptr_t)aligned_addr % sizeof(long)) && aligned_addr < end_addr;
- aligned_addr++)
+ for (; ((intptr_t)aligned_addr % sizeof(int)) && aligned_addr < end_addr;
+ aligned_addr++)
*(buf++) = *(ptr++);
}
- words = (end_addr - aligned_addr) / sizeof(long);
+ words = (end_addr - aligned_addr) / sizeof(int);
- // assert((intptr_t)aligned_addr % sizeof(long) == 0);
+ // assert((intptr_t)aligned_addr % sizeof(int) == 0);
for (i = 0; i < words; i++) {
errno = 0;
- rslt = ptrace(PTRACE_PEEKDATA, ph->pid, aligned_addr, 0);
+ rslt = ptrace(PT_READ_D, ph->pid, (caddr_t) aligned_addr, 0);
if (errno) {
- print_debug("ptrace(PTRACE_PEEKDATA, ..) failed for %d bytes @ %lx\n", size, addr);
+ print_debug("ptrace(PT_READ_D, ..) failed for %d bytes @ %lx\n", size, addr);
return false;
}
- *(long *)buf = rslt;
- buf += sizeof(long);
- aligned_addr += sizeof(long);
+ *(int *)buf = rslt;
+ buf += sizeof(int);
+ aligned_addr += sizeof(int);
}
if (aligned_addr != end_addr) {
char *ptr = (char *)&rslt;
errno = 0;
- rslt = ptrace(PTRACE_PEEKDATA, ph->pid, aligned_addr, 0);
+ rslt = ptrace(PT_READ_D, ph->pid, (caddr_t) aligned_addr, 0);
if (errno) {
- print_debug("ptrace(PTRACE_PEEKDATA, ..) failed for %d bytes @ %lx\n", size, addr);
+ print_debug("ptrace(PT_READ_D, ..) failed for %d bytes @ %lx\n", size, addr);
return false;
}
- for (; aligned_addr != end_addr; aligned_addr++)
+ for (; aligned_addr != end_addr; aligned_addr++)
*(buf++) = *(ptr++);
}
return true;
}
// null implementation for write
-static bool process_write_data(struct ps_prochandle* ph,
+static bool process_write_data(struct ps_prochandle* ph,
uintptr_t addr, const char *buf , size_t size) {
return false;
}
-// "user" should be a pointer to a user_regs_struct
-static bool process_get_lwp_regs(struct ps_prochandle* ph, pid_t pid, struct user_regs_struct *user) {
+// "user" should be a pointer to a reg
+static bool process_get_lwp_regs(struct ps_prochandle* ph, pid_t pid, struct reg *user) {
// we have already attached to all thread 'pid's, just use ptrace call
// to get regset now. Note that we don't cache regset upfront for processes.
-// Linux on x86 and sparc are different. On x86 ptrace(PTRACE_GETREGS, ...)
-// uses pointer from 4th argument and ignores 3rd argument. On sparc it uses
-// pointer from 3rd argument and ignores 4th argument
-#if defined(sparc) || defined(sparcv9)
-#define ptrace_getregs(request, pid, addr, data) ptrace(request, pid, addr, data)
-#else
-#define ptrace_getregs(request, pid, addr, data) ptrace(request, pid, data, addr)
-#endif
-
-#if defined(_LP64) && defined(PTRACE_GETREGS64)
-#define PTRACE_GETREGS_REQ PTRACE_GETREGS64
-#elif defined(PTRACE_GETREGS)
-#define PTRACE_GETREGS_REQ PTRACE_GETREGS
-#elif defined(PT_GETREGS)
-#define PTRACE_GETREGS_REQ PT_GETREGS
-#endif
-
-#ifdef PTRACE_GETREGS_REQ
- if (ptrace_getregs(PTRACE_GETREGS_REQ, pid, user, NULL) < 0) {
+ if (ptrace(PT_GETREGS, pid, (caddr_t) user, 0) < 0) {
print_debug("ptrace(PTRACE_GETREGS, ...) failed for lwp %d\n", pid);
return false;
}
return true;
-#else
- print_debug("ptrace(PTRACE_GETREGS, ...) not supported\n");
- return false;
-#endif
+}
+
+// fill in ptrace_lwpinfo for lid
+static bool process_get_lwp_info(struct ps_prochandle *ph, lwpid_t lwp_id, void *linfo) {
+ errno = 0;
+ ptrace(PT_LWPINFO, lwp_id, linfo, sizeof(struct ptrace_lwpinfo));
+ return (errno == 0)? true: false;
}
// attach to a process/thread specified by "pid"
static bool ptrace_attach(pid_t pid) {
- if (ptrace(PTRACE_ATTACH, pid, NULL, NULL) < 0) {
+ if (ptrace(PT_ATTACH, pid, NULL, 0) < 0) {
print_debug("ptrace(PTRACE_ATTACH, ..) failed for %d\n", pid);
return false;
} else {
int ret;
int status;
do {
- // Wait for debuggee to stop.
+ // Wait for debuggee to stop.
ret = waitpid(pid, &status, 0);
- if (ret == -1 && errno == ECHILD) {
- // try cloned process.
- ret = waitpid(pid, &status, __WALL);
- }
if (ret >= 0) {
- if (WIFSTOPPED(status)) {
- // Debuggee stopped.
- return true;
+ if (WIFSTOPPED(status)) {
+ // Debuggee stopped.
+ return true;
} else {
- print_debug("waitpid(): Child process exited/terminated (status = 0x%x)\n", status);
- return false;
- }
+ print_debug("waitpid(): Child process exited/terminated (status = 0x%x)\n", status);
+ return false;
+ }
} else {
- switch (errno) {
- case EINTR:
+ switch (errno) {
+ case EINTR:
continue;
- break;
- case ECHILD:
- print_debug("waitpid() failed. Child process pid (%d) does not exist \n", pid);
- break;
- case EINVAL:
- print_debug("waitpid() failed. Invalid options argument.\n");
- break;
- default:
- print_debug("waitpid() failed. Unexpected error %d\n",errno);
+ break;
+ case ECHILD:
+ print_debug("waitpid() failed. Child process pid (%d) does not exist \n", pid);
+ break;
+ case EINVAL:
+ print_debug("waitpid() failed. Invalid options argument.\n");
+ break;
+ default:
+ print_debug("waitpid() failed. Unexpected error %d\n",errno);
}
return false;
- }
+ }
} while(true);
- }
-}
-
+ }
+}
+
// -------------------------------------------------------
// functions for obtaining library information
// -------------------------------------------------------
-/*
- * splits a string _str_ into substrings with delimiter _delim_ by replacing old * delimiters with _new_delim_ (ideally, '\0'). the address of each substring
- * is stored in array _ptrs_ as the return value. the maximum capacity of _ptrs_ * array is specified by parameter _n_.
- * RETURN VALUE: total number of substrings (always <= _n_)
- * NOTE: string _str_ is modified if _delim_!=_new_delim_
- */
-static int split_n_str(char * str, int n, char ** ptrs, char delim, char new_delim)
-{
- int i;
- for(i = 0; i < n; i++) ptrs[i] = NULL;
- if (str == NULL || n < 1 ) return 0;
-
- i = 0;
-
- // skipping leading blanks
- while(*str&&*str==delim) str++;
-
- while(*str&&i<n){
- ptrs[i++] = str;
- while(*str&&*str!=delim) str++;
- while(*str&&*str==delim) *(str++) = new_delim;
- }
-
- return i;
+// callback for read_thread_info
+static bool add_new_thread(struct ps_prochandle* ph, pthread_t pthread_id, lwpid_t lwp_id) {
+ return add_thread_info(ph, pthread_id, lwp_id) != NULL;
}
+#if defined(__FreeBSD__) && __FreeBSD_version < 701000
/*
- * fgets without storing '\n' at the end of the string
+ * TEXT_START_ADDR from binutils/ld/emulparams/<arch_spec>.sh
+ * Not the most robust but good enough.
*/
-static char * fgets_no_cr(char * buf, int n, FILE *fp)
-{
- char * rslt = fgets(buf, n, fp);
- if (rslt && buf && *buf){
- char *p = strchr(buf, '\0');
- if (*--p=='\n') *p='\0';
- }
- return rslt;
-}
-// callback for read_thread_info
-static bool add_new_thread(struct ps_prochandle* ph, pthread_t pthread_id, lwpid_t lwp_id) {
- return add_thread_info(ph, pthread_id, lwp_id) != NULL;
+#if defined(amd64) || defined(x86_64)
+#define TEXT_START_ADDR 0x400000
+#elif defined(i386)
+#define TEXT_START_ADDR 0x8048000
+#else
+#error TEXT_START_ADDR not defined
+#endif
+
+#define BUF_SIZE (PATH_MAX + NAME_MAX + 1)
+
+uintptr_t linkmap_addr(struct ps_prochandle *ph) {
+ uintptr_t ehdr_addr, phdr_addr, dyn_addr, dmap_addr, lmap_addr;
+ ELF_EHDR ehdr;
+ ELF_PHDR *phdrs, *phdr;
+ ELF_DYN *dyns, *dyn;
+ struct r_debug dmap;
+ unsigned long hdrs_size;
+ unsigned int i;
+
+ /* read ELF_EHDR at TEXT_START_ADDR and validate */
+
+ ehdr_addr = (uintptr_t)TEXT_START_ADDR;
+
+ if (process_read_data(ph, ehdr_addr, (char *)&ehdr, sizeof(ehdr)) != true) {
+ print_debug("process_read_data failed for ehdr_addr %p\n", ehdr_addr);
+ return (0);
+ }
+
+ if (!IS_ELF(ehdr) ||
+ ehdr.e_ident[EI_CLASS] != ELF_TARG_CLASS ||
+ ehdr.e_ident[EI_DATA] != ELF_TARG_DATA ||
+ ehdr.e_ident[EI_VERSION] != EV_CURRENT ||
+ ehdr.e_phentsize != sizeof(ELF_PHDR) ||
+ ehdr.e_version != ELF_TARG_VER ||
+ ehdr.e_machine != ELF_TARG_MACH) {
+ print_debug("not an ELF_EHDR at %p\n", ehdr_addr);
+ return (0);
+ }
+
+ /* allocate space for all ELF_PHDR's and read */
+
+ phdr_addr = ehdr_addr + ehdr.e_phoff;
+ hdrs_size = ehdr.e_phnum * sizeof(ELF_PHDR);
+
+ if ((phdrs = malloc(hdrs_size)) == NULL)
+ return (0);
+
+ if (process_read_data(ph, phdr_addr, (char *)phdrs, hdrs_size) != true) {
+ print_debug("process_read_data failed for phdr_addr %p\n", phdr_addr);
+ return (0);
+ }
+
+ /* find PT_DYNAMIC section */
+
+ for (i = 0, phdr = phdrs; i < ehdr.e_phnum; i++, phdr++) {
+ if (phdr->p_type == PT_DYNAMIC)
+ break;
+ }
+
+ if (i >= ehdr.e_phnum) {
+ print_debug("PT_DYNAMIC section not found!\n");
+ free(phdrs);
+ return (0);
+ }
+
+ /* allocate space and read in ELF_DYN headers */
+
+ dyn_addr = phdr->p_vaddr;
+ hdrs_size = phdr->p_memsz;
+ free(phdrs);
+
+ if ((dyns = malloc(hdrs_size)) == NULL)
+ return (0);
+
+ if (process_read_data(ph, dyn_addr, (char *)dyns, hdrs_size) != true) {
+ print_debug("process_read_data failed for dyn_addr %p\n", dyn_addr);
+ free(dyns);
+ return (0);
+ }
+
+ /* find DT_DEBUG */
+
+ dyn = dyns;
+ while (dyn->d_tag != DT_DEBUG && dyn->d_tag != DT_NULL) {
+ dyn++;
+ }
+
+ if (dyn->d_tag != DT_DEBUG) {
+ print_debug("failed to find DT_DEBUG\n");
+ free(dyns);
+ return (0);
+ }
+
+ /* read struct r_debug into dmap */
+
+ dmap_addr = (uintptr_t)dyn->d_un.d_ptr;
+ free(dyns);
+
+ if (process_read_data(ph, dmap_addr, (char *)&dmap, sizeof(dmap)) != true) {
+ print_debug("process_read_data failed for dmap_addr %p\n", dmap_addr);
+ return (0);
+ }
+
+ lmap_addr = (uintptr_t)dmap.r_map;
+
+ return (lmap_addr);
}
+#endif // __FreeBSD__ && __FreeBSD_version < 701000
static bool read_lib_info(struct ps_prochandle* ph) {
- char fname[32];
- char buf[256];
- FILE *fp = NULL;
-
- sprintf(fname, "/proc/%d/maps", ph->pid);
- fp = fopen(fname, "r");
- if (fp == NULL) {
- print_debug("can't open /proc/%d/maps file\n", ph->pid);
- return false;
+#if defined(__FreeBSD__) && __FreeBSD_version >= 701000
+ struct kinfo_vmentry *freep, *kve;
+ int i, cnt;
+
+ freep = kinfo_getvmmap(ph->pid, &cnt);
+ if (freep == NULL) {
+ print_debug("can't get vm map for pid\n", ph->pid);
+ return false;
}
- while(fgets_no_cr(buf, 256, fp)){
- char * word[6];
- int nwords = split_n_str(buf, 6, word, ' ', '\0');
- if (nwords > 5 && find_lib(ph, word[5]) == false) {
- intptr_t base;
- lib_info* lib;
-#ifdef _LP64
- sscanf(word[0], "%lx", &base);
-#else
- sscanf(word[0], "%x", &base);
-#endif
- if ((lib = add_lib_info(ph, word[5], (uintptr_t)base)) == NULL)
+ for (i = 0; i < cnt; i++) {
+ kve = &freep[i];
+ if ((kve->kve_flags & KVME_FLAG_COW) &&
+ kve->kve_path != NULL &&
+ strlen(kve->kve_path) > 0) {
+
+ if (find_lib(ph, kve->kve_path) == false) {
+ lib_info* lib;
+ if ((lib = add_lib_info(ph, kve->kve_path,
+ (uintptr_t) kve->kve_start)) == NULL)
continue; // ignore, add_lib_info prints error
- // we don't need to keep the library open, symtab is already
- // built. Only for core dump we need to keep the fd open.
- close(lib->fd);
- lib->fd = -1;
+ // we don't need to keep the library open, symtab is already
+ // built. Only for core dump we need to keep the fd open.
+ close(lib->fd);
+ lib->fd = -1;
+ }
}
}
- fclose(fp);
+
+ free(freep);
+
return true;
+#else
+ char *l_name;
+ struct link_map *lmap;
+ uintptr_t lmap_addr;
+
+ if ((l_name = malloc(BUF_SIZE)) == NULL)
+ return false;
+
+ if ((lmap = malloc(sizeof(*lmap))) == NULL) {
+ free(l_name);
+ return false;
+ }
+
+ lmap_addr = linkmap_addr(ph);
+
+ if (lmap_addr == 0) {
+ free(l_name);
+ free(lmap);
+ return false;
+ }
+
+ do {
+ if (process_read_data(ph, lmap_addr, (char *)lmap, sizeof(*lmap)) != true) {
+ print_debug("process_read_data failed for lmap_addr %p\n", lmap_addr);
+ free (l_name);
+ free (lmap);
+ return false;
+ }
+
+ if (process_read_data(ph, (uintptr_t)lmap->l_name, l_name,
+ BUF_SIZE) != true) {
+ print_debug("process_read_data failed for lmap->l_name %p\n",
+ lmap->l_name);
+ free (l_name);
+ free (lmap);
+ return false;
+ }
+
+ if (find_lib(ph, l_name) == false) {
+ lib_info* lib;
+ if ((lib = add_lib_info(ph, l_name,
+ (uintptr_t) lmap->l_addr)) == NULL)
+ continue; // ignore, add_lib_info prints error
+
+ // we don't need to keep the library open, symtab is already
+ // built. Only for core dump we need to keep the fd open.
+ close(lib->fd);
+ lib->fd = -1;
+ }
+ lmap_addr = (uintptr_t)lmap->l_next;
+ } while (lmap->l_next != NULL);
+
+ free (l_name);
+ free (lmap);
+
+ return true;
+#endif
}
// detach a given pid
static bool ptrace_detach(pid_t pid) {
- if (pid && ptrace(PTRACE_DETACH, pid, NULL, NULL) < 0) {
+ if (pid && ptrace(PT_DETACH, pid, (caddr_t)1, 0) < 0) {
print_debug("ptrace(PTRACE_DETACH, ..) failed for %d\n", pid);
return false;
} else {
return true;
- }
-}
-
-// detach all pids of a ps_prochandle
-static void detach_all_pids(struct ps_prochandle* ph) {
- thread_info* thr = ph->threads;
- while (thr) {
- ptrace_detach(thr->lwp_id);
- thr = thr->next;
- }
+ }
}
static void process_cleanup(struct ps_prochandle* ph) {
- detach_all_pids(ph);
+ ptrace_detach(ph->pid);
}
static ps_prochandle_ops process_ops = {
.release= process_cleanup,
.p_pread= process_read_data,
.p_pwrite= process_write_data,
- .get_lwp_regs= process_get_lwp_regs
+ .get_lwp_regs= process_get_lwp_regs,
+ .get_lwp_info= process_get_lwp_info
};
// attach to the process. One and only one exposed stuff
@@ -323,21 +431,14 @@
// read library info and symbol tables, must do this before attaching threads,
// as the symbols in the pthread library will be used to figure out
// the list of threads within the same process.
- read_lib_info(ph);
-
+ if (read_lib_info(ph) != true) {
+ ptrace_detach(pid);
+ free(ph);
+ return NULL;
+ }
+
// read thread info
read_thread_info(ph, add_new_thread);
- // attach to the threads
- thr = ph->threads;
- while (thr) {
- // don't attach to the main thread again
- if (ph->pid != thr->lwp_id && ptrace_attach(thr->lwp_id) != true) {
- // even if one attach fails, we get return NULL
- Prelease(ph);
- return NULL;
- }
- thr = thr->next;
- }
return ph;
}
diff -rus agent/src/os/linux/salibelf.c agent/src/os/bsd/salibelf.c
--- agent/src/os/linux/salibelf.c 2011-07-26 20:21:17.000000000 -0600
+++ agent/src/os/bsd/salibelf.c 2011-07-26 20:21:17.000000000 -0600
@@ -25,6 +25,7 @@
#include "salibelf.h"
#include <stdlib.h>
#include <unistd.h>
+#include <string.h>
extern void print_debug(const char*,...);
Files agent/src/os/linux/salibelf.h and agent/src/os/bsd/salibelf.h are identical
diff -rus agent/src/os/linux/symtab.c agent/src/os/bsd/symtab.c
--- agent/src/os/linux/symtab.c 2011-07-26 20:21:17.000000000 -0600
+++ agent/src/os/bsd/symtab.c 2011-07-26 20:21:17.000000000 -0600
@@ -23,10 +23,10 @@
*/
#include <unistd.h>
-#include <sys/procfs.h>
#include <search.h>
#include <stdlib.h>
#include <string.h>
+#include "hsearch_r.h"
#include "symtab.h"
#include "salibelf.h"
@@ -53,276 +53,9 @@
struct hsearch_data *hash_table;
} symtab_t;
-
-// Directory that contains global debuginfo files. In theory it
-// should be possible to change this, but in a Java environment there
-// is no obvious place to put a user interface to do it. Maybe this
-// could be set with an environment variable.
-static const char debug_file_directory[] = "/usr/lib/debug";
-
-/* The CRC used in gnu_debuglink, retrieved from
- http://sourceware.org/gdb/current/onlinedocs/gdb/Separate-Debug-Files.html#Separate-Debug-Files. */
-unsigned int gnu_debuglink_crc32 (unsigned int crc,
- unsigned char *buf, size_t len)
-{
- static const unsigned int crc32_table[256] =
- {
- 0x00000000, 0x77073096, 0xee0e612c, 0x990951ba, 0x076dc419,
- 0x706af48f, 0xe963a535, 0x9e6495a3, 0x0edb8832, 0x79dcb8a4,
- 0xe0d5e91e, 0x97d2d988, 0x09b64c2b, 0x7eb17cbd, 0xe7b82d07,
- 0x90bf1d91, 0x1db71064, 0x6ab020f2, 0xf3b97148, 0x84be41de,
- 0x1adad47d, 0x6ddde4eb, 0xf4d4b551, 0x83d385c7, 0x136c9856,
- 0x646ba8c0, 0xfd62f97a, 0x8a65c9ec, 0x14015c4f, 0x63066cd9,
- 0xfa0f3d63, 0x8d080df5, 0x3b6e20c8, 0x4c69105e, 0xd56041e4,
- 0xa2677172, 0x3c03e4d1, 0x4b04d447, 0xd20d85fd, 0xa50ab56b,
- 0x35b5a8fa, 0x42b2986c, 0xdbbbc9d6, 0xacbcf940, 0x32d86ce3,
- 0x45df5c75, 0xdcd60dcf, 0xabd13d59, 0x26d930ac, 0x51de003a,
- 0xc8d75180, 0xbfd06116, 0x21b4f4b5, 0x56b3c423, 0xcfba9599,
- 0xb8bda50f, 0x2802b89e, 0x5f058808, 0xc60cd9b2, 0xb10be924,
- 0x2f6f7c87, 0x58684c11, 0xc1611dab, 0xb6662d3d, 0x76dc4190,
- 0x01db7106, 0x98d220bc, 0xefd5102a, 0x71b18589, 0x06b6b51f,
- 0x9fbfe4a5, 0xe8b8d433, 0x7807c9a2, 0x0f00f934, 0x9609a88e,
- 0xe10e9818, 0x7f6a0dbb, 0x086d3d2d, 0x91646c97, 0xe6635c01,
- 0x6b6b51f4, 0x1c6c6162, 0x856530d8, 0xf262004e, 0x6c0695ed,
- 0x1b01a57b, 0x8208f4c1, 0xf50fc457, 0x65b0d9c6, 0x12b7e950,
- 0x8bbeb8ea, 0xfcb9887c, 0x62dd1ddf, 0x15da2d49, 0x8cd37cf3,
- 0xfbd44c65, 0x4db26158, 0x3ab551ce, 0xa3bc0074, 0xd4bb30e2,
- 0x4adfa541, 0x3dd895d7, 0xa4d1c46d, 0xd3d6f4fb, 0x4369e96a,
- 0x346ed9fc, 0xad678846, 0xda60b8d0, 0x44042d73, 0x33031de5,
- 0xaa0a4c5f, 0xdd0d7cc9, 0x5005713c, 0x270241aa, 0xbe0b1010,
- 0xc90c2086, 0x5768b525, 0x206f85b3, 0xb966d409, 0xce61e49f,
- 0x5edef90e, 0x29d9c998, 0xb0d09822, 0xc7d7a8b4, 0x59b33d17,
- 0x2eb40d81, 0xb7bd5c3b, 0xc0ba6cad, 0xedb88320, 0x9abfb3b6,
- 0x03b6e20c, 0x74b1d29a, 0xead54739, 0x9dd277af, 0x04db2615,
- 0x73dc1683, 0xe3630b12, 0x94643b84, 0x0d6d6a3e, 0x7a6a5aa8,
- 0xe40ecf0b, 0x9309ff9d, 0x0a00ae27, 0x7d079eb1, 0xf00f9344,
- 0x8708a3d2, 0x1e01f268, 0x6906c2fe, 0xf762575d, 0x806567cb,
- 0x196c3671, 0x6e6b06e7, 0xfed41b76, 0x89d32be0, 0x10da7a5a,
- 0x67dd4acc, 0xf9b9df6f, 0x8ebeeff9, 0x17b7be43, 0x60b08ed5,
- 0xd6d6a3e8, 0xa1d1937e, 0x38d8c2c4, 0x4fdff252, 0xd1bb67f1,
- 0xa6bc5767, 0x3fb506dd, 0x48b2364b, 0xd80d2bda, 0xaf0a1b4c,
- 0x36034af6, 0x41047a60, 0xdf60efc3, 0xa867df55, 0x316e8eef,
- 0x4669be79, 0xcb61b38c, 0xbc66831a, 0x256fd2a0, 0x5268e236,
- 0xcc0c7795, 0xbb0b4703, 0x220216b9, 0x5505262f, 0xc5ba3bbe,
- 0xb2bd0b28, 0x2bb45a92, 0x5cb36a04, 0xc2d7ffa7, 0xb5d0cf31,
- 0x2cd99e8b, 0x5bdeae1d, 0x9b64c2b0, 0xec63f226, 0x756aa39c,
- 0x026d930a, 0x9c0906a9, 0xeb0e363f, 0x72076785, 0x05005713,
- 0x95bf4a82, 0xe2b87a14, 0x7bb12bae, 0x0cb61b38, 0x92d28e9b,
- 0xe5d5be0d, 0x7cdcefb7, 0x0bdbdf21, 0x86d3d2d4, 0xf1d4e242,
- 0x68ddb3f8, 0x1fda836e, 0x81be16cd, 0xf6b9265b, 0x6fb077e1,
- 0x18b74777, 0x88085ae6, 0xff0f6a70, 0x66063bca, 0x11010b5c,
- 0x8f659eff, 0xf862ae69, 0x616bffd3, 0x166ccf45, 0xa00ae278,
- 0xd70dd2ee, 0x4e048354, 0x3903b3c2, 0xa7672661, 0xd06016f7,
- 0x4969474d, 0x3e6e77db, 0xaed16a4a, 0xd9d65adc, 0x40df0b66,
- 0x37d83bf0, 0xa9bcae53, 0xdebb9ec5, 0x47b2cf7f, 0x30b5ffe9,
- 0xbdbdf21c, 0xcabac28a, 0x53b39330, 0x24b4a3a6, 0xbad03605,
- 0xcdd70693, 0x54de5729, 0x23d967bf, 0xb3667a2e, 0xc4614ab8,
- 0x5d681b02, 0x2a6f2b94, 0xb40bbe37, 0xc30c8ea1, 0x5a05df1b,
- 0x2d02ef8d
- };
- unsigned char *end;
-
- crc = ~crc & 0xffffffff;
- for (end = buf + len; buf < end; ++buf)
- crc = crc32_table[(crc ^ *buf) & 0xff] ^ (crc >> 8);
- return ~crc & 0xffffffff;
-}
-
-/* Open a debuginfo file and check its CRC. If it exists and the CRC
- matches return its fd. */
-static int
-open_debug_file (const char *pathname, unsigned int crc)
-{
- unsigned int file_crc = 0;
- unsigned char buffer[8 * 1024];
-
- int fd = pathmap_open(pathname);
-
- if (fd < 0)
- return -1;
-
- lseek(fd, 0, SEEK_SET);
-
- for (;;) {
- int len = read(fd, buffer, sizeof buffer);
- if (len <= 0)
- break;
- file_crc = gnu_debuglink_crc32(file_crc, buffer, len);
- }
-
- if (crc == file_crc)
- return fd;
- else {
- close(fd);
- return -1;
- }
-}
-
-/* Find an ELF section. */
-static struct elf_section *find_section_by_name(char *name,
- int fd,
- ELF_EHDR *ehdr,
- ELF_SHDR *shbuf,
- struct elf_section *scn_cache)
-{
- ELF_SHDR* cursct = NULL;
- char *strtab;
- int cnt;
-
- if (scn_cache[ehdr->e_shstrndx].c_data == NULL) {
- if ((scn_cache[ehdr->e_shstrndx].c_data
- = read_section_data(fd, ehdr, cursct)) == NULL) {
- return NULL;
- }
- }
-
- strtab = scn_cache[ehdr->e_shstrndx].c_data;
-
- for (cursct = shbuf, cnt = 0;
- cnt < ehdr->e_shnum;
- cnt++, cursct++) {
- if (strcmp(cursct->sh_name + strtab, name) == 0) {
- scn_cache[cnt].c_data = read_section_data(fd, ehdr, cursct);
- return &scn_cache[cnt];
- }
- }
-
- return NULL;
-}
-
-/* Look for a ".gnu_debuglink" section. If one exists, try to open a
- suitable debuginfo file. */
-static int open_file_from_debug_link(const char *name,
- int fd,
- ELF_EHDR *ehdr,
- ELF_SHDR *shbuf,
- struct elf_section *scn_cache)
-{
- int debug_fd;
- struct elf_section *debug_link = find_section_by_name(".gnu_debuglink", fd, ehdr,
- shbuf, scn_cache);
- if (debug_link == NULL)
- return -1;
- char *debug_filename = debug_link->c_data;
- int offset = (strlen(debug_filename) + 4) >> 2;
- static unsigned int crc;
- crc = ((unsigned int*)debug_link->c_data)[offset];
- char *debug_pathname = malloc(strlen(debug_filename)
- + strlen(name)
- + strlen(".debug/")
- + strlen(debug_file_directory)
- + 2);
- strcpy(debug_pathname, name);
- char *last_slash = strrchr(debug_pathname, '/');
- if (last_slash == NULL)
- return -1;
-
- /* Look in the same directory as the object. */
- strcpy(last_slash+1, debug_filename);
-
- debug_fd = open_debug_file(debug_pathname, crc);
- if (debug_fd >= 0) {
- free(debug_pathname);
- return debug_fd;
- }
-
- /* Look in a subdirectory named ".debug". */
- strcpy(last_slash+1, ".debug/");
- strcat(last_slash, debug_filename);
-
- debug_fd = open_debug_file(debug_pathname, crc);
- if (debug_fd >= 0) {
- free(debug_pathname);
- return debug_fd;
- }
-
- /* Look in /usr/lib/debug + the full pathname. */
- strcpy(debug_pathname, debug_file_directory);
- strcat(debug_pathname, name);
- last_slash = strrchr(debug_pathname, '/');
- strcpy(last_slash+1, debug_filename);
-
- debug_fd = open_debug_file(debug_pathname, crc);
- if (debug_fd >= 0) {
- free(debug_pathname);
- return debug_fd;
- }
-
- free(debug_pathname);
- return -1;
-}
-
-static struct symtab* build_symtab_internal(int fd, const char *filename, bool try_debuginfo);
-
-/* Look for a ".gnu_debuglink" section. If one exists, try to open a
- suitable debuginfo file and read a symbol table from it. */
-static struct symtab *build_symtab_from_debug_link(const char *name,
- int fd,
- ELF_EHDR *ehdr,
- ELF_SHDR *shbuf,
- struct elf_section *scn_cache)
-{
- fd = open_file_from_debug_link(name, fd, ehdr, shbuf, scn_cache);
-
- if (fd >= 0) {
- struct symtab *symtab = build_symtab_internal(fd, NULL, /* try_debuginfo */ false);
- close(fd);
- return symtab;
- }
-
- return NULL;
-}
-
-// Given a build_id, find the associated debuginfo file
-static char *
-build_id_to_debug_filename (size_t size, unsigned char *data)
-{
- char *filename, *s;
-
- filename = malloc(strlen (debug_file_directory) + (sizeof "/.build-id/" - 1) + 1
- + 2 * size + (sizeof ".debug" - 1) + 1);
- s = filename + sprintf (filename, "%s/.build-id/", debug_file_directory);
- if (size > 0)
- {
- size--;
- s += sprintf (s, "%02x", *data++);
- }
- if (size > 0)
- *s++ = '/';
- while (size-- > 0)
- s += sprintf (s, "%02x", *data++);
- strcpy (s, ".debug");
-
- return filename;
-}
-
-// Read a build ID note. Try to open any associated debuginfo file
-// and return its symtab
-static struct symtab* build_symtab_from_build_id(Elf64_Nhdr *note)
-{
- int fd;
- struct symtab *symtab = NULL;
-
- unsigned char *bytes
- = (unsigned char*)(note+1) + note->n_namesz;
- unsigned char *filename
- = (build_id_to_debug_filename (note->n_descsz, bytes));
-
- fd = pathmap_open(filename);
- if (fd >= 0) {
- symtab = build_symtab_internal(fd, NULL, /* try_debuginfo */ false);
- close(fd);
- }
- free(filename);
-
- return symtab;
-}
-
-// read symbol table from given fd. If try_debuginfo) is true, also
-// try to open an associated debuginfo file
-static struct symtab* build_symtab_internal(int fd, const char *filename, bool try_debuginfo) {
+// read symbol table from given fd.
+struct symtab* build_symtab(int fd) {
ELF_EHDR ehdr;
- char *names = NULL;
struct symtab* symtab = NULL;
// Reading of elf header
@@ -331,8 +64,9 @@
ELF_SHDR* shbuf = NULL;
ELF_SHDR* cursct = NULL;
ELF_PHDR* phbuf = NULL;
- ELF_PHDR* phdr = NULL;
- int sym_section = SHT_DYNSYM;
+ int symtab_found = 0;
+ int dynsym_found = 0;
+ uint32_t symsection = SHT_SYMTAB;
uintptr_t baseaddr = (uintptr_t)-1;
@@ -357,23 +91,30 @@
for (cursct = shbuf, cnt = 0; cnt < ehdr.e_shnum; cnt++) {
scn_cache[cnt].c_shdr = cursct;
- if (cursct->sh_type == SHT_SYMTAB || cursct->sh_type == SHT_STRTAB
- || cursct->sh_type == SHT_NOTE || cursct->sh_type == SHT_DYNSYM) {
+ if (cursct->sh_type == SHT_SYMTAB ||
+ cursct->sh_type == SHT_STRTAB ||
+ cursct->sh_type == SHT_DYNSYM) {
if ( (scn_cache[cnt].c_data = read_section_data(fd, &ehdr, cursct)) == NULL) {
goto quit;
}
}
- if (cursct->sh_type == SHT_SYMTAB) {
- // Full symbol table available so use that
- sym_section = cursct->sh_type;
- }
+
+ if (cursct->sh_type == SHT_SYMTAB)
+ symtab_found++;
+
+ if (cursct->sh_type == SHT_DYNSYM)
+ dynsym_found++;
+
cursct++;
}
+ if (!symtab_found && dynsym_found)
+ symsection = SHT_DYNSYM;
+
for (cnt = 1; cnt < ehdr.e_shnum; cnt++) {
ELF_SHDR *shdr = scn_cache[cnt].c_shdr;
- if (shdr->sh_type == sym_section) {
+ if (shdr->sh_type == symsection) {
ELF_SYM *syms;
int j, n, rslt;
size_t size;
@@ -435,45 +176,6 @@
}
}
- // Look for a separate debuginfo file.
- if (try_debuginfo) {
-
- // We prefer a debug symtab to an object's own symtab, so look in
- // the debuginfo file. We stash a copy of the old symtab in case
- // there is no debuginfo.
- struct symtab* prev_symtab = symtab;
- symtab = NULL;
-
-#ifdef NT_GNU_BUILD_ID
- // First we look for a Build ID
- for (cursct = shbuf, cnt = 0;
- symtab == NULL && cnt < ehdr.e_shnum;
- cnt++) {
- if (cursct->sh_type == SHT_NOTE) {
- Elf64_Nhdr *note = (Elf64_Nhdr *)scn_cache[cnt].c_data;
- if (note->n_type == NT_GNU_BUILD_ID) {
- symtab = build_symtab_from_build_id(note);
- }
- }
- cursct++;
- }
-#endif
-
- // Then, if that doesn't work, the debug link
- if (symtab == NULL) {
- symtab = build_symtab_from_debug_link(filename, fd, &ehdr, shbuf,
- scn_cache);
- }
-
- // If we still haven't found a symtab, use the object's own symtab.
- if (symtab != NULL) {
- if (prev_symtab != NULL)
- destroy_symtab(prev_symtab);
- } else {
- symtab = prev_symtab;
- }
- }
-
quit:
if (shbuf) free(shbuf);
if (phbuf) free(phbuf);
@@ -488,11 +190,6 @@
return symtab;
}
-struct symtab* build_symtab(int fd, const char *filename) {
- return build_symtab_internal(fd, filename, /* try_debuginfo */ true);
-}
-
-
void destroy_symtab(struct symtab* symtab) {
if (!symtab) return;
if (symtab->strs) free(symtab->strs);
diff -rus agent/src/os/linux/symtab.h agent/src/os/bsd/symtab.h
--- agent/src/os/linux/symtab.h 2011-07-26 20:21:17.000000000 -0600
+++ agent/src/os/bsd/symtab.h 2011-07-26 20:21:17.000000000 -0600
@@ -32,7 +32,7 @@
struct symtab;
// build symbol table for a given ELF file descriptor
-struct symtab* build_symtab(int fd, const char *filename);
+struct symtab* build_symtab(int fd);
// destroy the symbol table
void destroy_symtab(struct symtab* symtab);
diff -rus agent/src/os/linux/test.c agent/src/os/bsd/test.c
--- agent/src/os/linux/test.c 2011-07-26 20:21:17.000000000 -0600
+++ agent/src/os/bsd/test.c 2011-07-26 20:21:17.000000000 -0600
@@ -44,7 +44,7 @@
}
default: {
- printf("usage %s <pid> or %s <exec file> <core file>\n");
+ fprintf(stderr, "usage %s <pid> or %s <exec file> <core file>\n", argv[0], argv[0]);
return 1;
}
}
--- agent/src/os/linux/LinuxDebuggerLocal.c 2011-07-26 20:21:17.000000000 -0600
+++ agent/src/os/bsd/BsdDebuggerLocal.c 2011-07-26 20:21:17.000000000 -0600
@@ -22,6 +22,7 @@
*
*/
+#include <stdlib.h>
#include <jni.h>
#include "libproc.h"
@@ -65,15 +66,15 @@
}
/*
- * Class: sun_jvm_hotspot_debugger_linux_LinuxDebuggerLocal
+ * Class: sun_jvm_hotspot_debugger_bsd_BsdDebuggerLocal
* Method: init0
* Signature: ()V
*/
-JNIEXPORT void JNICALL Java_sun_jvm_hotspot_debugger_linux_LinuxDebuggerLocal_init0
+JNIEXPORT void JNICALL Java_sun_jvm_hotspot_debugger_bsd_BsdDebuggerLocal_init0
(JNIEnv *env, jclass cls) {
jclass listClass;
- if (init_libproc(getenv("LIBSAPROC_DEBUG")) != true) {
+ if (init_libproc(getenv("LIBSAPROC_DEBUG") != NULL) != true) {
THROW_NEW_DEBUGGER_EXCEPTION("can't initialize libproc");
}
@@ -102,7 +103,7 @@
CHECK_EXCEPTION;
}
-JNIEXPORT jint JNICALL Java_sun_jvm_hotspot_debugger_linux_LinuxDebuggerLocal_getAddressSize
+JNIEXPORT jint JNICALL Java_sun_jvm_hotspot_debugger_bsd_BsdDebuggerLocal_getAddressSize
(JNIEnv *env, jclass cls)
{
#ifdef _LP64
@@ -155,11 +156,11 @@
}
/*
- * Class: sun_jvm_hotspot_debugger_linux_LinuxDebuggerLocal
+ * Class: sun_jvm_hotspot_debugger_bsd_BsdDebuggerLocal
* Method: attach0
* Signature: (I)V
*/
-JNIEXPORT void JNICALL Java_sun_jvm_hotspot_debugger_linux_LinuxDebuggerLocal_attach0__I
+JNIEXPORT void JNICALL Java_sun_jvm_hotspot_debugger_bsd_BsdDebuggerLocal_attach0__I
(JNIEnv *env, jobject this_obj, jint jpid) {
struct ps_prochandle* ph;
@@ -171,11 +172,11 @@
}
/*
- * Class: sun_jvm_hotspot_debugger_linux_LinuxDebuggerLocal
+ * Class: sun_jvm_hotspot_debugger_bsd_BsdDebuggerLocal
* Method: attach0
* Signature: (Ljava/lang/String;Ljava/lang/String;)V
*/
-JNIEXPORT void JNICALL Java_sun_jvm_hotspot_debugger_linux_LinuxDebuggerLocal_attach0__Ljava_lang_String_2Ljava_lang_String_2
+JNIEXPORT void JNICALL Java_sun_jvm_hotspot_debugger_bsd_BsdDebuggerLocal_attach0__Ljava_lang_String_2Ljava_lang_String_2
(JNIEnv *env, jobject this_obj, jstring execName, jstring coreName) {
const char *execName_cstr;
const char *coreName_cstr;
@@ -199,11 +200,11 @@
}
/*
- * Class: sun_jvm_hotspot_debugger_linux_LinuxDebuggerLocal
+ * Class: sun_jvm_hotspot_debugger_bsd_BsdDebuggerLocal
* Method: detach0
* Signature: ()V
*/
-JNIEXPORT void JNICALL Java_sun_jvm_hotspot_debugger_linux_LinuxDebuggerLocal_detach0
+JNIEXPORT void JNICALL Java_sun_jvm_hotspot_debugger_bsd_BsdDebuggerLocal_detach0
(JNIEnv *env, jobject this_obj) {
struct ps_prochandle* ph = get_proc_handle(env, this_obj);
if (ph != NULL) {
@@ -212,11 +213,11 @@
}
/*
- * Class: sun_jvm_hotspot_debugger_linux_LinuxDebuggerLocal
+ * Class: sun_jvm_hotspot_debugger_bsd_BsdDebuggerLocal
* Method: lookupByName0
* Signature: (Ljava/lang/String;Ljava/lang/String;)J
*/
-JNIEXPORT jlong JNICALL Java_sun_jvm_hotspot_debugger_linux_LinuxDebuggerLocal_lookupByName0
+JNIEXPORT jlong JNICALL Java_sun_jvm_hotspot_debugger_bsd_BsdDebuggerLocal_lookupByName0
(JNIEnv *env, jobject this_obj, jstring objectName, jstring symbolName) {
const char *objectName_cstr, *symbolName_cstr;
jlong addr;
@@ -241,11 +242,11 @@
}
/*
- * Class: sun_jvm_hotspot_debugger_linux_LinuxDebuggerLocal
+ * Class: sun_jvm_hotspot_debugger_bsd_BsdDebuggerLocal
* Method: lookupByAddress0
* Signature: (J)Lsun/jvm/hotspot/debugger/cdbg/ClosestSymbol;
*/
-JNIEXPORT jobject JNICALL Java_sun_jvm_hotspot_debugger_linux_LinuxDebuggerLocal_lookupByAddress0
+JNIEXPORT jobject JNICALL Java_sun_jvm_hotspot_debugger_bsd_BsdDebuggerLocal_lookupByAddress0
(JNIEnv *env, jobject this_obj, jlong addr) {
uintptr_t offset;
const char* sym = NULL;
@@ -258,11 +259,11 @@
}
/*
- * Class: sun_jvm_hotspot_debugger_linux_LinuxDebuggerLocal
+ * Class: sun_jvm_hotspot_debugger_bsd_BsdDebuggerLocal
* Method: readBytesFromProcess0
* Signature: (JJ)Lsun/jvm/hotspot/debugger/ReadResult;
*/
-JNIEXPORT jbyteArray JNICALL Java_sun_jvm_hotspot_debugger_linux_LinuxDebuggerLocal_readBytesFromProcess0
+JNIEXPORT jbyteArray JNICALL Java_sun_jvm_hotspot_debugger_bsd_BsdDebuggerLocal_readBytesFromProcess0
(JNIEnv *env, jobject this_obj, jlong addr, jlong numBytes) {
jboolean isCopy;
@@ -275,19 +276,18 @@
bufPtr = (*env)->GetByteArrayElements(env, array, &isCopy);
CHECK_EXCEPTION_(0);
- err = ps_pdread(get_proc_handle(env, this_obj), (psaddr_t) (uintptr_t)addr, bufPtr, numBytes);
+ err = ps_pread(get_proc_handle(env, this_obj), (psaddr_t) (uintptr_t)addr, bufPtr, numBytes);
(*env)->ReleaseByteArrayElements(env, array, bufPtr, 0);
return (err == PS_OK)? array : 0;
}
-JNIEXPORT jlongArray JNICALL Java_sun_jvm_hotspot_debugger_linux_LinuxDebuggerLocal_getThreadIntegerRegisterSet0
+JNIEXPORT jlongArray JNICALL Java_sun_jvm_hotspot_debugger_bsd_BsdDebuggerLocal_getThreadIntegerRegisterSet0
(JNIEnv *env, jobject this_obj, jint lwp_id) {
- struct user_regs_struct gregs;
+ struct reg gregs;
jboolean isCopy;
jlongArray array;
jlong *regs;
- int i;
struct ps_prochandle* ph = get_proc_handle(env, this_obj);
if (get_lwp_regs(ph, lwp_id, &gregs) != true) {
@@ -317,26 +317,27 @@
#ifdef i386
#define REG_INDEX(reg) sun_jvm_hotspot_debugger_x86_X86ThreadContext_##reg
- regs[REG_INDEX(GS)] = (uintptr_t) gregs.xgs;
- regs[REG_INDEX(FS)] = (uintptr_t) gregs.xfs;
- regs[REG_INDEX(ES)] = (uintptr_t) gregs.xes;
- regs[REG_INDEX(DS)] = (uintptr_t) gregs.xds;
- regs[REG_INDEX(EDI)] = (uintptr_t) gregs.edi;
- regs[REG_INDEX(ESI)] = (uintptr_t) gregs.esi;
- regs[REG_INDEX(FP)] = (uintptr_t) gregs.ebp;
- regs[REG_INDEX(SP)] = (uintptr_t) gregs.esp;
- regs[REG_INDEX(EBX)] = (uintptr_t) gregs.ebx;
- regs[REG_INDEX(EDX)] = (uintptr_t) gregs.edx;
- regs[REG_INDEX(ECX)] = (uintptr_t) gregs.ecx;
- regs[REG_INDEX(EAX)] = (uintptr_t) gregs.eax;
- regs[REG_INDEX(PC)] = (uintptr_t) gregs.eip;
- regs[REG_INDEX(CS)] = (uintptr_t) gregs.xcs;
- regs[REG_INDEX(SS)] = (uintptr_t) gregs.xss;
+ regs[REG_INDEX(GS)] = (uintptr_t) gregs.r_gs;
+ regs[REG_INDEX(FS)] = (uintptr_t) gregs.r_fs;
+ regs[REG_INDEX(ES)] = (uintptr_t) gregs.r_es;
+ regs[REG_INDEX(DS)] = (uintptr_t) gregs.r_ds;
+ regs[REG_INDEX(EDI)] = (uintptr_t) gregs.r_edi;
+ regs[REG_INDEX(ESI)] = (uintptr_t) gregs.r_esi;
+ regs[REG_INDEX(FP)] = (uintptr_t) gregs.r_ebp;
+ regs[REG_INDEX(SP)] = (uintptr_t) gregs.r_isp;
+ regs[REG_INDEX(EBX)] = (uintptr_t) gregs.r_ebx;
+ regs[REG_INDEX(EDX)] = (uintptr_t) gregs.r_edx;
+ regs[REG_INDEX(ECX)] = (uintptr_t) gregs.r_ecx;
+ regs[REG_INDEX(EAX)] = (uintptr_t) gregs.r_eax;
+ regs[REG_INDEX(PC)] = (uintptr_t) gregs.r_eip;
+ regs[REG_INDEX(CS)] = (uintptr_t) gregs.r_cs;
+ regs[REG_INDEX(SS)] = (uintptr_t) gregs.r_ss;
#endif /* i386 */
#if ia64
regs = (*env)->GetLongArrayElements(env, array, &isCopy);
+ int i;
for (i = 0; i < NPRGREG; i++ ) {
regs[i] = 0xDEADDEAD;
}
@@ -345,31 +346,31 @@
#ifdef amd64
#define REG_INDEX(reg) sun_jvm_hotspot_debugger_amd64_AMD64ThreadContext_##reg
- regs[REG_INDEX(R15)] = gregs.r15;
- regs[REG_INDEX(R14)] = gregs.r14;
- regs[REG_INDEX(R13)] = gregs.r13;
- regs[REG_INDEX(R12)] = gregs.r12;
- regs[REG_INDEX(RBP)] = gregs.rbp;
- regs[REG_INDEX(RBX)] = gregs.rbx;
- regs[REG_INDEX(R11)] = gregs.r11;
- regs[REG_INDEX(R10)] = gregs.r10;
- regs[REG_INDEX(R9)] = gregs.r9;
- regs[REG_INDEX(R8)] = gregs.r8;
- regs[REG_INDEX(RAX)] = gregs.rax;
- regs[REG_INDEX(RCX)] = gregs.rcx;
- regs[REG_INDEX(RDX)] = gregs.rdx;
- regs[REG_INDEX(RSI)] = gregs.rsi;
- regs[REG_INDEX(RDI)] = gregs.rdi;
- regs[REG_INDEX(RIP)] = gregs.rip;
- regs[REG_INDEX(CS)] = gregs.cs;
- regs[REG_INDEX(RSP)] = gregs.rsp;
- regs[REG_INDEX(SS)] = gregs.ss;
- regs[REG_INDEX(FSBASE)] = gregs.fs_base;
- regs[REG_INDEX(GSBASE)] = gregs.gs_base;
- regs[REG_INDEX(DS)] = gregs.ds;
- regs[REG_INDEX(ES)] = gregs.es;
- regs[REG_INDEX(FS)] = gregs.fs;
- regs[REG_INDEX(GS)] = gregs.gs;
+ regs[REG_INDEX(R15)] = gregs.r_r15;
+ regs[REG_INDEX(R14)] = gregs.r_r14;
+ regs[REG_INDEX(R13)] = gregs.r_r13;
+ regs[REG_INDEX(R12)] = gregs.r_r12;
+ regs[REG_INDEX(RBP)] = gregs.r_rbp;
+ regs[REG_INDEX(RBX)] = gregs.r_rbx;
+ regs[REG_INDEX(R11)] = gregs.r_r11;
+ regs[REG_INDEX(R10)] = gregs.r_r10;
+ regs[REG_INDEX(R9)] = gregs.r_r9;
+ regs[REG_INDEX(R8)] = gregs.r_r8;
+ regs[REG_INDEX(RAX)] = gregs.r_rax;
+ regs[REG_INDEX(RCX)] = gregs.r_rcx;
+ regs[REG_INDEX(RDX)] = gregs.r_rdx;
+ regs[REG_INDEX(RSI)] = gregs.r_rsi;
+ regs[REG_INDEX(RDI)] = gregs.r_rdi;
+ regs[REG_INDEX(RIP)] = gregs.r_rip;
+ regs[REG_INDEX(CS)] = gregs.r_cs;
+ regs[REG_INDEX(RSP)] = gregs.r_rsp;
+ regs[REG_INDEX(SS)] = gregs.r_ss;
+// regs[REG_INDEX(FSBASE)] = gregs.fs_base;
+// regs[REG_INDEX(GSBASE)] = gregs.gs_base;
+// regs[REG_INDEX(DS)] = gregs.ds;
+// regs[REG_INDEX(ES)] = gregs.es;
+// regs[REG_INDEX(FS)] = gregs.fs;
+// regs[REG_INDEX(GS)] = gregs.gs;
#endif /* amd64 */
diff -rus agent/src/share/classes/sun/jvm/hotspot/debugger/linux/SharedObject.java agent/src/share/classes/sun/jvm/hotspot/debugger/bsd/SharedObject.java
--- agent/src/share/classes/sun/jvm/hotspot/debugger/linux/SharedObject.java 2011-07-26 20:21:18.000000000 -0600
+++ agent/src/share/classes/sun/jvm/hotspot/debugger/bsd/SharedObject.java 2011-07-26 20:21:18.000000000 -0600
@@ -22,7 +22,7 @@
*
*/
-package sun.jvm.hotspot.debugger.linux;
+package sun.jvm.hotspot.debugger.bsd;
import sun.jvm.hotspot.debugger.*;
import sun.jvm.hotspot.debugger.cdbg.*;
@@ -31,7 +31,7 @@
/** A Object can represent either a .so or an a.out file. */
class SharedObject extends DSO {
- SharedObject(LinuxDebugger dbg, String filename, long size, Address relocation) {
+ SharedObject(BsdDebugger dbg, String filename, long size, Address relocation) {
super(filename, size, relocation);
this.dbg = dbg;
}
@@ -44,5 +44,5 @@
return dbg.getAddressValue(addr);
}
- private LinuxDebugger dbg;
+ private BsdDebugger dbg;
}
--- agent/src/share/classes/sun/jvm/hotspot/debugger/linux/LinuxAddress.java 2011-07-26 20:21:18.000000000 -0600
+++ agent/src/share/classes/sun/jvm/hotspot/debugger/bsd/BsdAddress.java 2011-07-26 20:21:18.000000000 -0600
@@ -22,15 +22,15 @@
*
*/
-package sun.jvm.hotspot.debugger.linux;
+package sun.jvm.hotspot.debugger.bsd;
import sun.jvm.hotspot.debugger.*;
-class LinuxAddress implements Address {
- protected LinuxDebugger debugger;
+class BsdAddress implements Address {
+ protected BsdDebugger debugger;
protected long addr;
- LinuxAddress(LinuxDebugger debugger, long addr) {
+ BsdAddress(BsdDebugger debugger, long addr) {
this.debugger = debugger;
this.addr = addr;
}
@@ -44,11 +44,11 @@
return false;
}
- if (!(arg instanceof LinuxAddress)) {
+ if (!(arg instanceof BsdAddress)) {
return false;
}
- return (addr == ((LinuxAddress) arg).addr);
+ return (addr == ((BsdAddress) arg).addr);
}
public int hashCode() {
@@ -178,7 +178,7 @@
if (value == 0) {
return null;
}
- return new LinuxAddress(debugger, value);
+ return new BsdAddress(debugger, value);
}
public OopHandle addOffsetToAsOopHandle(long offset) throws UnsupportedOperationException {
@@ -186,7 +186,7 @@
if (value == 0) {
return null;
}
- return new LinuxOopHandle(debugger, value);
+ return new BsdOopHandle(debugger, value);
}
/** (FIXME: any signed/unsigned issues? Should this work for
@@ -195,7 +195,7 @@
if (arg == null) {
return addr;
}
- return addr - ((LinuxAddress) arg).addr;
+ return addr - ((BsdAddress) arg).addr;
}
// Two's complement representation.
@@ -207,7 +207,7 @@
if (a == null) {
return false;
}
- LinuxAddress arg = (LinuxAddress) a;
+ BsdAddress arg = (BsdAddress) a;
if ((addr >= 0) && (arg.addr < 0)) {
return true;
}
@@ -221,7 +221,7 @@
if (a == null) {
return false;
}
- LinuxAddress arg = (LinuxAddress) a;
+ BsdAddress arg = (BsdAddress) a;
if ((addr >= 0) && (arg.addr < 0)) {
return true;
}
@@ -235,7 +235,7 @@
if (a == null) {
return true;
}
- LinuxAddress arg = (LinuxAddress) a;
+ BsdAddress arg = (BsdAddress) a;
if ((addr >= 0) && (arg.addr < 0)) {
return false;
}
@@ -249,7 +249,7 @@
if (a == null) {
return true;
}
- LinuxAddress arg = (LinuxAddress) a;
+ BsdAddress arg = (BsdAddress) a;
if ((addr >= 0) && (arg.addr < 0)) {
return false;
}
@@ -264,7 +264,7 @@
if (value == 0) {
return null;
}
- return new LinuxAddress(debugger, value);
+ return new BsdAddress(debugger, value);
}
public Address orWithMask(long mask) throws UnsupportedOperationException {
@@ -272,7 +272,7 @@
if (value == 0) {
return null;
}
- return new LinuxAddress(debugger, value);
+ return new BsdAddress(debugger, value);
}
public Address xorWithMask(long mask) throws UnsupportedOperationException {
@@ -280,7 +280,7 @@
if (value == 0) {
return null;
}
- return new LinuxAddress(debugger, value);
+ return new BsdAddress(debugger, value);
}
@@ -305,10 +305,10 @@
// p/n indicates whether the interior address is really positive
// or negative. In unsigned terms, p1 < p2 < n1 < n2.
- LinuxAddress p1 = new LinuxAddress(null, 0x7FFFFFFFFFFFFFF0L);
- LinuxAddress p2 = (LinuxAddress) p1.addOffsetTo(10);
- LinuxAddress n1 = (LinuxAddress) p2.addOffsetTo(10);
- LinuxAddress n2 = (LinuxAddress) n1.addOffsetTo(10);
+ BsdAddress p1 = new BsdAddress(null, 0x7FFFFFFFFFFFFFF0L);
+ BsdAddress p2 = (BsdAddress) p1.addOffsetTo(10);
+ BsdAddress n1 = (BsdAddress) p2.addOffsetTo(10);
+ BsdAddress n2 = (BsdAddress) n1.addOffsetTo(10);
// lessThan positive tests
check(p1.lessThan(p2), "lessThan 1");
@@ -394,6 +394,6 @@
check(!p2.greaterThanOrEqual(n1), "greaterThanOrEqual 15");
check(!p1.greaterThanOrEqual(p2), "greaterThanOrEqual 16");
- System.err.println("LinuxAddress: all tests passed successfully.");
+ System.err.println("BsdAddress: all tests passed successfully.");
}
}
--- agent/src/share/classes/sun/jvm/hotspot/debugger/linux/LinuxCDebugger.java 2011-07-26 20:21:18.000000000 -0600
+++ agent/src/share/classes/sun/jvm/hotspot/debugger/bsd/BsdCDebugger.java 2011-07-26 20:21:18.000000000 -0600
@@ -22,7 +22,7 @@
*
*/
-package sun.jvm.hotspot.debugger.linux;
+package sun.jvm.hotspot.debugger.bsd;
import java.io.*;
import java.util.*;
@@ -30,16 +30,14 @@
import sun.jvm.hotspot.debugger.cdbg.*;
import sun.jvm.hotspot.debugger.x86.*;
import sun.jvm.hotspot.debugger.amd64.*;
-import sun.jvm.hotspot.debugger.sparc.*;
-import sun.jvm.hotspot.debugger.linux.x86.*;
-import sun.jvm.hotspot.debugger.linux.amd64.*;
-import sun.jvm.hotspot.debugger.linux.sparc.*;
+import sun.jvm.hotspot.debugger.bsd.x86.*;
+import sun.jvm.hotspot.debugger.bsd.amd64.*;
import sun.jvm.hotspot.utilities.*;
-class LinuxCDebugger implements CDebugger {
- private LinuxDebugger dbg;
+class BsdCDebugger implements CDebugger {
+ private BsdDebugger dbg;
- LinuxCDebugger(LinuxDebugger dbg) {
+ BsdCDebugger(BsdDebugger dbg) {
this.dbg = dbg;
}
@@ -91,21 +89,14 @@
if (ebp == null) return null;
Address pc = context.getRegisterAsAddress(X86ThreadContext.EIP);
if (pc == null) return null;
- return new LinuxX86CFrame(dbg, ebp, pc);
+ return new BsdX86CFrame(dbg, ebp, pc);
} else if (cpu.equals("amd64")) {
AMD64ThreadContext context = (AMD64ThreadContext) thread.getContext();
Address rbp = context.getRegisterAsAddress(AMD64ThreadContext.RBP);
if (rbp == null) return null;
Address pc = context.getRegisterAsAddress(AMD64ThreadContext.RIP);
if (pc == null) return null;
- return new LinuxAMD64CFrame(dbg, rbp, pc);
- } else if (cpu.equals("sparc")) {
- SPARCThreadContext context = (SPARCThreadContext) thread.getContext();
- Address sp = context.getRegisterAsAddress(SPARCThreadContext.R_SP);
- if (sp == null) return null;
- Address pc = context.getRegisterAsAddress(SPARCThreadContext.R_O7);
- if (pc == null) return null;
- return new LinuxSPARCCFrame(dbg, sp, pc, LinuxDebuggerLocal.getAddressSize());
+ return new BsdAMD64CFrame(dbg, rbp, pc);
} else {
throw new DebuggerException(cpu + " is not yet supported");
}
--- agent/src/share/classes/sun/jvm/hotspot/debugger/linux/LinuxDebugger.java 2011-07-26 20:21:18.000000000 -0600
+++ agent/src/share/classes/sun/jvm/hotspot/debugger/bsd/BsdDebugger.java 2011-07-26 20:21:18.000000000 -0600
@@ -22,7 +22,7 @@
*
*/
-package sun.jvm.hotspot.debugger.linux;
+package sun.jvm.hotspot.debugger.bsd;
import java.util.List;
import sun.jvm.hotspot.debugger.*;
@@ -32,7 +32,7 @@
support 32-bit vs. 64-bit debugging as well as features required
by the architecture-specific subpackages. */
-public interface LinuxDebugger extends JVMDebugger {
+public interface BsdDebugger extends JVMDebugger {
public String addressValueToString(long address) throws DebuggerException;
public boolean readJBoolean(long address) throws DebuggerException;
public byte readJByte(long address) throws DebuggerException;
@@ -44,15 +44,15 @@
public short readJShort(long address) throws DebuggerException;
public long readCInteger(long address, long numBytes, boolean isUnsigned)
throws DebuggerException;
- public LinuxAddress readAddress(long address) throws DebuggerException;
- public LinuxAddress readCompOopAddress(long address) throws DebuggerException;
- public LinuxOopHandle readOopHandle(long address) throws DebuggerException;
- public LinuxOopHandle readCompOopHandle(long address) throws DebuggerException;
+ public BsdAddress readAddress(long address) throws DebuggerException;
+ public BsdAddress readCompOopAddress(long address) throws DebuggerException;
+ public BsdOopHandle readOopHandle(long address) throws DebuggerException;
+ public BsdOopHandle readCompOopHandle(long address) throws DebuggerException;
public long[] getThreadIntegerRegisterSet(int lwp_id) throws DebuggerException;
public long getAddressValue(Address addr) throws DebuggerException;
public Address newAddress(long value) throws DebuggerException;
- // For LinuxCDebugger
+ // For BsdCDebugger
public List getThreadList();
public List getLoadObjectList();
public ClosestSymbol lookup(long address);
--- agent/src/share/classes/sun/jvm/hotspot/debugger/linux/LinuxDebuggerLocal.java 2011-07-26 20:21:18.000000000 -0600
+++ agent/src/share/classes/sun/jvm/hotspot/debugger/bsd/BsdDebuggerLocal.java 2011-07-26 20:21:18.000000000 -0600
@@ -22,7 +22,7 @@
*
*/
-package sun.jvm.hotspot.debugger.linux;
+package sun.jvm.hotspot.debugger.bsd;
import java.io.*;
import java.net.*;
@@ -48,14 +48,14 @@
RuntimeException if they are called before the debugger is
configured with the Java primitive type sizes. </P> */
-public class LinuxDebuggerLocal extends DebuggerBase implements LinuxDebugger {
+public class BsdDebuggerLocal extends DebuggerBase implements BsdDebugger {
private boolean useGCC32ABI;
private boolean attached;
private long p_ps_prochandle; // native debugger handle
private boolean isCore;
// CDebugger support
- private LinuxCDebugger cdbg;
+ private BsdCDebugger cdbg;
// threadList and loadObjectList are filled by attach0 method
private List threadList;
@@ -94,7 +94,7 @@
throws DebuggerException;
public native static int getAddressSize() ;
- // Note on Linux threads are really processes. When target process is
+ // Note on Bsd threads are really processes. When target process is
// attached by a serviceability agent thread, only that thread can do
// ptrace operations on the target. This is because from kernel's point
// view, other threads are just separate processes and they are not
@@ -105,15 +105,15 @@
// all JNI functions that are making ptrace calls.
interface WorkerThreadTask {
- public void doit(LinuxDebuggerLocal debugger) throws DebuggerException;
+ public void doit(BsdDebuggerLocal debugger) throws DebuggerException;
}
- class LinuxDebuggerLocalWorkerThread extends Thread {
- LinuxDebuggerLocal debugger;
+ class BsdDebuggerLocalWorkerThread extends Thread {
+ BsdDebuggerLocal debugger;
WorkerThreadTask task;
DebuggerException lastException;
- public LinuxDebuggerLocalWorkerThread(LinuxDebuggerLocal debugger) {
+ public BsdDebuggerLocalWorkerThread(BsdDebuggerLocal debugger) {
this.debugger = debugger;
setDaemon(true);
}
@@ -157,7 +157,7 @@
}
}
- private LinuxDebuggerLocalWorkerThread workerThread = null;
+ private BsdDebuggerLocalWorkerThread workerThread = null;
//----------------------------------------------------------------------
// Implementation of Debugger interface
@@ -168,14 +168,14 @@
<P> useCache should be set to true if debugging is being done
locally, and to false if the debugger is being created for the
purpose of supporting remote debugging. </P> */
- public LinuxDebuggerLocal(MachineDescription machDesc,
+ public BsdDebuggerLocal(MachineDescription machDesc,
boolean useCache) throws DebuggerException {
this.machDesc = machDesc;
utils = new DebuggerUtilities(machDesc.getAddressSize(),
machDesc.isBigEndian()) {
public void checkAlignment(long address, long alignment) {
// Need to override default checkAlignment because we need to
- // relax alignment constraints on Linux/x86
+ // relax alignment constraints on Bsd/x86
if ( (address % alignment != 0)
&&(alignment != 8 || address % 4 != 0)) {
throw new UnalignedAddressException(
@@ -188,7 +188,7 @@
};
if (useCache) {
- // FIXME: re-test necessity of cache on Linux, where data
+ // FIXME: re-test necessity of cache on Bsd, where data
// fetching is faster
// Cache portion of the remote process's address space.
// Fetching data over the socket connection to dbx is slow.
@@ -206,7 +206,7 @@
}
}
- workerThread = new LinuxDebuggerLocalWorkerThread(this);
+ workerThread = new BsdDebuggerLocalWorkerThread(this);
workerThread.start();
}
@@ -255,7 +255,7 @@
loadObjectList = new ArrayList();
class AttachTask implements WorkerThreadTask {
int pid;
- public void doit(LinuxDebuggerLocal debugger) {
+ public void doit(BsdDebuggerLocal debugger) {
debugger.attach0(pid);
debugger.attached = true;
debugger.isCore = false;
@@ -296,7 +296,7 @@
class DetachTask implements WorkerThreadTask {
boolean result = false;
- public void doit(LinuxDebuggerLocal debugger) {
+ public void doit(BsdDebuggerLocal debugger) {
debugger.detach0();
debugger.attached = false;
result = true;
@@ -316,7 +316,7 @@
if (addr == 0) {
return null;
}
- return new LinuxAddress(this, addr);
+ return new BsdAddress(this, addr);
}
/** From the Debugger interface via JVMDebugger */
@@ -334,7 +334,7 @@
}
public String consoleExecuteCommand(String cmd) throws DebuggerException {
- throw new DebuggerException("No debugger console available on Linux");
+ throw new DebuggerException("No debugger console available on Bsd");
}
public String getConsolePrompt() throws DebuggerException {
@@ -359,15 +359,15 @@
if (isCore) {
long addr = lookupByName0(objectName, symbol);
- return (addr == 0)? null : new LinuxAddress(this, handleGCC32ABI(addr, symbol));
+ return (addr == 0)? null : new BsdAddress(this, handleGCC32ABI(addr, symbol));
} else {
class LookupByNameTask implements WorkerThreadTask {
String objectName, symbol;
Address result;
- public void doit(LinuxDebuggerLocal debugger) {
+ public void doit(BsdDebuggerLocal debugger) {
long addr = debugger.lookupByName0(objectName, symbol);
- result = (addr == 0 ? null : new LinuxAddress(debugger, handleGCC32ABI(addr, symbol)));
+ result = (addr == 0 ? null : new BsdAddress(debugger, handleGCC32ABI(addr, symbol)));
}
}
@@ -399,48 +399,48 @@
/** From the ThreadAccess interface via Debugger and JVMDebugger */
public ThreadProxy getThreadForIdentifierAddress(Address addr) {
- return new LinuxThread(this, addr);
+ return new BsdThread(this, addr);
}
/** From the ThreadAccess interface via Debugger and JVMDebugger */
public ThreadProxy getThreadForThreadId(long id) {
- return new LinuxThread(this, id);
+ return new BsdThread(this, id);
}
//----------------------------------------------------------------------
- // Internal routines (for implementation of LinuxAddress).
+ // Internal routines (for implementation of BsdAddress).
// These must not be called until the MachineDescription has been set up.
//
- /** From the LinuxDebugger interface */
+ /** From the BsdDebugger interface */
public String addressValueToString(long address) {
return utils.addressValueToString(address);
}
- /** From the LinuxDebugger interface */
- public LinuxAddress readAddress(long address)
+ /** From the BsdDebugger interface */
+ public BsdAddress readAddress(long address)
throws UnmappedAddressException, UnalignedAddressException {
long value = readAddressValue(address);
- return (value == 0 ? null : new LinuxAddress(this, value));
+ return (value == 0 ? null : new BsdAddress(this, value));
}
- public LinuxAddress readCompOopAddress(long address)
+ public BsdAddress readCompOopAddress(long address)
throws UnmappedAddressException, UnalignedAddressException {
long value = readCompOopAddressValue(address);
- return (value == 0 ? null : new LinuxAddress(this, value));
+ return (value == 0 ? null : new BsdAddress(this, value));
}
- /** From the LinuxDebugger interface */
- public LinuxOopHandle readOopHandle(long address)
+ /** From the BsdDebugger interface */
+ public BsdOopHandle readOopHandle(long address)
throws UnmappedAddressException, UnalignedAddressException,
NotInHeapException {
long value = readAddressValue(address);
- return (value == 0 ? null : new LinuxOopHandle(this, value));
+ return (value == 0 ? null : new BsdOopHandle(this, value));
}
- public LinuxOopHandle readCompOopHandle(long address)
+ public BsdOopHandle readCompOopHandle(long address)
throws UnmappedAddressException, UnalignedAddressException,
NotInHeapException {
long value = readCompOopAddressValue(address);
- return (value == 0 ? null : new LinuxOopHandle(this, value));
+ return (value == 0 ? null : new BsdOopHandle(this, value));
}
//----------------------------------------------------------------------
@@ -456,7 +456,7 @@
class GetThreadIntegerRegisterSetTask implements WorkerThreadTask {
int lwp_id;
long[] result;
- public void doit(LinuxDebuggerLocal debugger) {
+ public void doit(BsdDebuggerLocal debugger) {
result = debugger.getThreadIntegerRegisterSet0(lwp_id);
}
}
@@ -496,31 +496,31 @@
// Address access. Can not be package private, but should only be
// accessed by the architecture-specific subpackages.
- /** From the LinuxDebugger interface */
+ /** From the BsdDebugger interface */
public long getAddressValue(Address addr) {
if (addr == null) return 0;
- return ((LinuxAddress) addr).getValue();
+ return ((BsdAddress) addr).getValue();
}
- /** From the LinuxDebugger interface */
+ /** From the BsdDebugger interface */
public Address newAddress(long value) {
if (value == 0) return null;
- return new LinuxAddress(this, value);
+ return new BsdAddress(this, value);
}
- /** From the LinuxCDebugger interface */
+ /** From the BsdCDebugger interface */
public List/*<ThreadProxy>*/ getThreadList() {
requireAttach();
return threadList;
}
- /** From the LinuxCDebugger interface */
+ /** From the BsdCDebugger interface */
public List/*<LoadObject>*/ getLoadObjectList() {
requireAttach();
return loadObjectList;
}
- /** From the LinuxCDebugger interface */
+ /** From the BsdCDebugger interface */
public synchronized ClosestSymbol lookup(long addr) {
requireAttach();
if (isCore) {
@@ -530,7 +530,7 @@
long addr;
ClosestSymbol result;
- public void doit(LinuxDebuggerLocal debugger) {
+ public void doit(BsdDebuggerLocal debugger) {
result = debugger.lookupByAddress0(addr);
}
}
@@ -549,7 +549,7 @@
// IA-64 is not supported because of stack-walking issues
return null;
}
- cdbg = new LinuxCDebugger(this);
+ cdbg = new BsdCDebugger(this);
}
return cdbg;
}
@@ -565,7 +565,7 @@
class ReadBytesFromProcessTask implements WorkerThreadTask {
long address, numBytes;
ReadResult result;
- public void doit(LinuxDebuggerLocal debugger) {
+ public void doit(BsdDebuggerLocal debugger) {
byte[] res = debugger.readBytesFromProcess0(address, numBytes);
if (res != null)
result = new ReadResult(res);
--- agent/src/share/classes/sun/jvm/hotspot/debugger/linux/LinuxOopHandle.java 2011-07-26 20:21:18.000000000 -0600
+++ agent/src/share/classes/sun/jvm/hotspot/debugger/bsd/BsdOopHandle.java 2011-07-26 20:21:18.000000000 -0600
@@ -22,12 +22,12 @@
*
*/
-package sun.jvm.hotspot.debugger.linux;
+package sun.jvm.hotspot.debugger.bsd;
import sun.jvm.hotspot.debugger.*;
-class LinuxOopHandle extends LinuxAddress implements OopHandle {
- LinuxOopHandle(LinuxDebugger debugger, long addr) {
+class BsdOopHandle extends BsdAddress implements OopHandle {
+ BsdOopHandle(BsdDebugger debugger, long addr) {
super(debugger, addr);
}
@@ -36,11 +36,11 @@
return false;
}
- if (!(arg instanceof LinuxOopHandle)) {
+ if (!(arg instanceof BsdOopHandle)) {
return false;
}
- return (addr == ((LinuxAddress) arg).addr);
+ return (addr == ((BsdAddress) arg).addr);
}
public Address addOffsetTo (long offset) throws UnsupportedOperationException {
--- agent/src/share/classes/sun/jvm/hotspot/debugger/linux/LinuxThread.java 2011-07-26 20:21:18.000000000 -0600
+++ agent/src/share/classes/sun/jvm/hotspot/debugger/bsd/BsdThread.java 2011-07-26 20:21:18.000000000 -0600
@@ -22,17 +22,17 @@
*
*/
-package sun.jvm.hotspot.debugger.linux;
+package sun.jvm.hotspot.debugger.bsd;
import sun.jvm.hotspot.debugger.*;
-class LinuxThread implements ThreadProxy {
- private LinuxDebugger debugger;
+class BsdThread implements ThreadProxy {
+ private BsdDebugger debugger;
private int lwp_id;
/** The address argument must be the address of the _thread_id in the
OSThread. It's value is result ::gettid() call. */
- LinuxThread(LinuxDebugger debugger, Address addr) {
+ BsdThread(BsdDebugger debugger, Address addr) {
this.debugger = debugger;
// FIXME: size of data fetched here should be configurable.
// However, making it so would produce a dependency on the "types"
@@ -40,17 +40,17 @@
this.lwp_id = (int) addr.getCIntegerAt(0, 4, true);
}
- LinuxThread(LinuxDebugger debugger, long id) {
+ BsdThread(BsdDebugger debugger, long id) {
this.debugger = debugger;
this.lwp_id = (int) id;
}
public boolean equals(Object obj) {
- if ((obj == null) || !(obj instanceof LinuxThread)) {
+ if ((obj == null) || !(obj instanceof BsdThread)) {
return false;
}
- return (((LinuxThread) obj).lwp_id == lwp_id);
+ return (((BsdThread) obj).lwp_id == lwp_id);
}
public int hashCode() {
@@ -63,7 +63,7 @@
public ThreadContext getContext() throws IllegalThreadStateException {
long[] data = debugger.getThreadIntegerRegisterSet(lwp_id);
- ThreadContext context = LinuxThreadContextFactory.createThreadContext(debugger);
+ ThreadContext context = BsdThreadContextFactory.createThreadContext(debugger);
for (int i = 0; i < data.length; i++) {
context.setRegister(i, data[i]);
}
--- agent/src/share/classes/sun/jvm/hotspot/debugger/linux/LinuxThreadContextFactory.java 2011-07-26 20:21:18.000000000 -0600
+++ agent/src/share/classes/sun/jvm/hotspot/debugger/bsd/BsdThreadContextFactory.java 2011-07-26 20:21:18.000000000 -0600
@@ -22,25 +22,19 @@
*
*/
-package sun.jvm.hotspot.debugger.linux;
+package sun.jvm.hotspot.debugger.bsd;
import sun.jvm.hotspot.debugger.*;
-import sun.jvm.hotspot.debugger.linux.amd64.*;
-import sun.jvm.hotspot.debugger.linux.ia64.*;
-import sun.jvm.hotspot.debugger.linux.x86.*;
-import sun.jvm.hotspot.debugger.linux.sparc.*;
+import sun.jvm.hotspot.debugger.bsd.amd64.*;
+import sun.jvm.hotspot.debugger.bsd.x86.*;
-class LinuxThreadContextFactory {
- static ThreadContext createThreadContext(LinuxDebugger dbg) {
+class BsdThreadContextFactory {
+ static ThreadContext createThreadContext(BsdDebugger dbg) {
String cpu = dbg.getCPU();
if (cpu.equals("x86")) {
- return new LinuxX86ThreadContext(dbg);
+ return new BsdX86ThreadContext(dbg);
} else if (cpu.equals("amd64")) {
- return new LinuxAMD64ThreadContext(dbg);
- } else if (cpu.equals("ia64")) {
- return new LinuxIA64ThreadContext(dbg);
- } else if (cpu.equals("sparc")) {
- return new LinuxSPARCThreadContext(dbg);
+ return new BsdAMD64ThreadContext(dbg);
} else {
throw new RuntimeException("cpu " + cpu + " is not yet supported");
}
--- agent/src/share/classes/sun/jvm/hotspot/debugger/linux/amd64/LinuxAMD64CFrame.java 2011-07-26 20:21:18.000000000 -0600
+++ agent/src/share/classes/sun/jvm/hotspot/debugger/bsd/amd64/BsdAMD64CFrame.java 2011-07-26 20:21:18.000000000 -0600
@@ -22,15 +22,15 @@
*
*/
-package sun.jvm.hotspot.debugger.linux.amd64;
+package sun.jvm.hotspot.debugger.bsd.amd64;
import sun.jvm.hotspot.debugger.*;
-import sun.jvm.hotspot.debugger.linux.*;
+import sun.jvm.hotspot.debugger.bsd.*;
import sun.jvm.hotspot.debugger.cdbg.*;
import sun.jvm.hotspot.debugger.cdbg.basic.*;
-final public class LinuxAMD64CFrame extends BasicCFrame {
- public LinuxAMD64CFrame(LinuxDebugger dbg, Address rbp, Address rip) {
+final public class BsdAMD64CFrame extends BasicCFrame {
+ public BsdAMD64CFrame(BsdDebugger dbg, Address rbp, Address rip) {
super(dbg.getCDebugger());
this.rbp = rbp;
this.rip = rip;
@@ -64,12 +64,12 @@
if (nextPC == null) {
return null;
}
- return new LinuxAMD64CFrame(dbg, nextRBP, nextPC);
+ return new BsdAMD64CFrame(dbg, nextRBP, nextPC);
}
// package/class internals only
private static final int ADDRESS_SIZE = 8;
private Address rip;
private Address rbp;
- private LinuxDebugger dbg;
+ private BsdDebugger dbg;
}
--- agent/src/share/classes/sun/jvm/hotspot/debugger/linux/amd64/LinuxAMD64ThreadContext.java 2011-07-26 20:21:18.000000000 -0600
+++ agent/src/share/classes/sun/jvm/hotspot/debugger/bsd/amd64/BsdAMD64ThreadContext.java 2011-07-26 20:21:18.000000000 -0600
@@ -22,16 +22,16 @@
*
*/
-package sun.jvm.hotspot.debugger.linux.amd64;
+package sun.jvm.hotspot.debugger.bsd.amd64;
import sun.jvm.hotspot.debugger.*;
import sun.jvm.hotspot.debugger.amd64.*;
-import sun.jvm.hotspot.debugger.linux.*;
+import sun.jvm.hotspot.debugger.bsd.*;
-public class LinuxAMD64ThreadContext extends AMD64ThreadContext {
- private LinuxDebugger debugger;
+public class BsdAMD64ThreadContext extends AMD64ThreadContext {
+ private BsdDebugger debugger;
- public LinuxAMD64ThreadContext(LinuxDebugger debugger) {
+ public BsdAMD64ThreadContext(BsdDebugger debugger) {
super();
this.debugger = debugger;
}
--- agent/src/share/classes/sun/jvm/hotspot/debugger/linux/x86/LinuxX86CFrame.java 2011-07-26 20:21:18.000000000 -0600
+++ agent/src/share/classes/sun/jvm/hotspot/debugger/bsd/x86/BsdX86CFrame.java 2011-07-26 20:21:18.000000000 -0600
@@ -22,16 +22,16 @@
*
*/
-package sun.jvm.hotspot.debugger.linux.x86;
+package sun.jvm.hotspot.debugger.bsd.x86;
import sun.jvm.hotspot.debugger.*;
-import sun.jvm.hotspot.debugger.linux.*;
+import sun.jvm.hotspot.debugger.bsd.*;
import sun.jvm.hotspot.debugger.cdbg.*;
import sun.jvm.hotspot.debugger.cdbg.basic.*;
-final public class LinuxX86CFrame extends BasicCFrame {
+final public class BsdX86CFrame extends BasicCFrame {
// package/class internals only
- public LinuxX86CFrame(LinuxDebugger dbg, Address ebp, Address pc) {
+ public BsdX86CFrame(BsdDebugger dbg, Address ebp, Address pc) {
super(dbg.getCDebugger());
this.ebp = ebp;
this.pc = pc;
@@ -65,11 +65,11 @@
if (nextPC == null) {
return null;
}
- return new LinuxX86CFrame(dbg, nextEBP, nextPC);
+ return new BsdX86CFrame(dbg, nextEBP, nextPC);
}
private static final int ADDRESS_SIZE = 4;
private Address pc;
private Address ebp;
- private LinuxDebugger dbg;
+ private BsdDebugger dbg;
}
--- agent/src/share/classes/sun/jvm/hotspot/debugger/linux/x86/LinuxX86ThreadContext.java 2011-07-26 20:21:18.000000000 -0600
+++ agent/src/share/classes/sun/jvm/hotspot/debugger/bsd/x86/BsdX86ThreadContext.java 2011-07-26 20:21:18.000000000 -0600
@@ -22,16 +22,16 @@
*
*/
-package sun.jvm.hotspot.debugger.linux.x86;
+package sun.jvm.hotspot.debugger.bsd.x86;
import sun.jvm.hotspot.debugger.*;
import sun.jvm.hotspot.debugger.x86.*;
-import sun.jvm.hotspot.debugger.linux.*;
+import sun.jvm.hotspot.debugger.bsd.*;
-public class LinuxX86ThreadContext extends X86ThreadContext {
- private LinuxDebugger debugger;
+public class BsdX86ThreadContext extends X86ThreadContext {
+ private BsdDebugger debugger;
- public LinuxX86ThreadContext(LinuxDebugger debugger) {
+ public BsdX86ThreadContext(BsdDebugger debugger) {
super();
this.debugger = debugger;
}
--- agent/src/share/classes/sun/jvm/hotspot/runtime/linux/LinuxSignals.java 2011-07-26 20:21:19.000000000 -0600
+++ agent/src/share/classes/sun/jvm/hotspot/runtime/bsd/BsdSignals.java 2011-07-26 20:21:19.000000000 -0600
@@ -22,43 +22,42 @@
*
*/
-package sun.jvm.hotspot.runtime.linux;
+package sun.jvm.hotspot.runtime.bsd;
-public class LinuxSignals {
+public class BsdSignals {
private static String[] signalNames = {
"", /* No signal 0 */
"SIGHUP", /* hangup */
- "SIGINT", /* interrupt (rubout) */
- "SIGQUIT", /* quit (ASCII FS) */
- "SIGILL", /* illegal instruction (not reset when caught) */
+ "SIGINT", /* interrupt */
+ "SIGQUIT", /* quit */
+ "SIGILL", /* illegal instr. (not reset when caught) */
"SIGTRAP", /* trace trap (not reset when caught) */
- "SIGABRT", /* used by abort, replace SIGIOT in the future */
- "SIGIOT",
- "SIGBUS",
+ "SIGABRT", /* abort() */
+ "SIGEMT", /* EMT instruction */
"SIGFPE", /* floating point exception */
"SIGKILL", /* kill (cannot be caught or ignored) */
- "SIGUSR1", /* user defined signal 1 */
+ "SIGBUS", /* bus error */
"SIGSEGV", /* segmentation violation */
- "SIGUSR2", /* user defined signal 2 */
+ "SIGSYS", /* non-existent system call invoked */
"SIGPIPE", /* write on a pipe with no one to read it */
"SIGALRM", /* alarm clock */
"SIGTERM", /* software termination signal from kill */
- "SIGSTKFLT",
- "SIGCHLD", /* child status change alias */
- "SIGCONT", /* stopped process has been continued */
- "SIGSTOP", /* stop (cannot be caught or ignored) */
- "SIGTSTP", /* user stop requested from tty */
- "SIGTTIN", /* background tty read attempted */
- "SIGTTOU", /* background tty write attempted */
- "SIGURG", /* urgent socket condition */
- "SIGXCPU", /* exceeded cpu limit */
+ "SIGURG", /* urgent condition on IO channel */
+ "SIGSTOP", /* sendable stop signal not from tty */
+ "SIGTSTP", /* stop signal from tty */
+ "SIGCONT", /* continue a stopped process */
+ "SIGCHLD", /* to parent on child stop or exit */
+ "SIGTTIN", /* to readers pgrp upon background tty read */
+ "SIGTTOU", /* like TTIN if (tp->t_local<OSTOP) */
+ "SIGIO", /* input/output possible signal */
+ "SIGXCPU", /* exceeded CPU time limit */
"SIGXFSZ", /* exceeded file size limit */
- "SIGVTALRM", /* virtual timer expired */
- "SIGPROF", /* profiling timer expired */
- "SIGWINCH", /* window size change */
- "SIGPOLL", /* pollable event occured */
- "SIGPWR", /* power-fail restart */
- "SIGSYS"
+ "SIGVTALRM", /* virtual time alarm */
+ "SIGPROF", /* profiling time alarm */
+ "SIGWINCH", /* window size changes */
+ "SIGINFO", /* information request */
+ "SIGUSR1", /* user defined signal 1 */
+ "SIGUSR2" /* user defined signal 2 */
};
public static String getSignalName(int sigNum) {
--- agent/src/share/classes/sun/jvm/hotspot/runtime/linux_amd64/LinuxAMD64JavaThreadPDAccess.java 2011-07-26 20:21:19.000000000 -0600
+++ agent/src/share/classes/sun/jvm/hotspot/runtime/bsd_amd64/BsdAMD64JavaThreadPDAccess.java 2011-07-26 20:21:19.000000000 -0600
@@ -22,7 +22,7 @@
*
*/
-package sun.jvm.hotspot.runtime.linux_amd64;
+package sun.jvm.hotspot.runtime.bsd_amd64;
import java.io.*;
import java.util.*;
@@ -33,7 +33,7 @@
import sun.jvm.hotspot.types.*;
import sun.jvm.hotspot.utilities.*;
-public class LinuxAMD64JavaThreadPDAccess implements JavaThreadPDAccess {
+public class BsdAMD64JavaThreadPDAccess implements JavaThreadPDAccess {
private static AddressField lastJavaFPField;
private static AddressField osThreadField;
--- agent/src/share/classes/sun/jvm/hotspot/runtime/linux_x86/LinuxSignals.java 2011-07-26 20:21:19.000000000 -0600
+++ agent/src/share/classes/sun/jvm/hotspot/runtime/bsd_x86/BsdSignals.java 2011-07-26 20:21:19.000000000 -0600
@@ -22,43 +22,42 @@
*
*/
-package sun.jvm.hotspot.runtime.linux_x86;
+package sun.jvm.hotspot.runtime.bsd_x86;
-public class LinuxSignals {
+public class BsdSignals {
private static String[] signalNames = {
"", /* No signal 0 */
"SIGHUP", /* hangup */
- "SIGINT", /* interrupt (rubout) */
- "SIGQUIT", /* quit (ASCII FS) */
- "SIGILL", /* illegal instruction (not reset when caught) */
+ "SIGINT", /* interrupt */
+ "SIGQUIT", /* quit */
+ "SIGILL", /* illegal instr. (not reset when caught) */
"SIGTRAP", /* trace trap (not reset when caught) */
- "SIGABRT", /* used by abort, replace SIGIOT in the future */
- "SIGIOT",
- "SIGBUS",
+ "SIGABRT", /* abort() */
+ "SIGEMT", /* EMT instruction */
"SIGFPE", /* floating point exception */
"SIGKILL", /* kill (cannot be caught or ignored) */
- "SIGUSR1", /* user defined signal 1 */
+ "SIGBUS", /* bus error */
"SIGSEGV", /* segmentation violation */
- "SIGUSR2", /* user defined signal 2 */
+ "SIGSYS", /* non-existent system call invoked */
"SIGPIPE", /* write on a pipe with no one to read it */
"SIGALRM", /* alarm clock */
"SIGTERM", /* software termination signal from kill */
- "SIGSTKFLT",
- "SIGCHLD", /* child status change alias */
- "SIGCONT", /* stopped process has been continued */
- "SIGSTOP", /* stop (cannot be caught or ignored) */
- "SIGTSTP", /* user stop requested from tty */
- "SIGTTIN", /* background tty read attempted */
- "SIGTTOU", /* background tty write attempted */
- "SIGURG", /* urgent socket condition */
- "SIGXCPU", /* exceeded cpu limit */
+ "SIGURG", /* urgent condition on IO channel */
+ "SIGSTOP", /* sendable stop signal not from tty */
+ "SIGTSTP", /* stop signal from tty */
+ "SIGCONT", /* continue a stopped process */
+ "SIGCHLD", /* to parent on child stop or exit */
+ "SIGTTIN", /* to readers pgrp upon background tty read */
+ "SIGTTOU", /* like TTIN if (tp->t_local<OSTOP) */
+ "SIGIO", /* input/output possible signal */
+ "SIGXCPU", /* exceeded CPU time limit */
"SIGXFSZ", /* exceeded file size limit */
- "SIGVTALRM", /* virtual timer expired */
- "SIGPROF", /* profiling timer expired */
- "SIGWINCH", /* window size change */
- "SIGPOLL", /* pollable event occured */
- "SIGPWR", /* power-fail restart */
- "SIGSYS"
+ "SIGVTALRM", /* virtual time alarm */
+ "SIGPROF", /* profiling time alarm */
+ "SIGWINCH", /* window size changes */
+ "SIGINFO", /* information request */
+ "SIGUSR1", /* user defined signal 1 */
+ "SIGUSR2" /* user defined signal 2 */
};
public static String getSignalName(int sigNum) {
--- agent/src/share/classes/sun/jvm/hotspot/runtime/linux_x86/LinuxX86JavaThreadPDAccess.java 2011-07-26 20:21:19.000000000 -0600
+++ agent/src/share/classes/sun/jvm/hotspot/runtime/bsd_x86/BsdX86JavaThreadPDAccess.java 2011-07-26 20:21:19.000000000 -0600
@@ -22,7 +22,7 @@
*
*/
-package sun.jvm.hotspot.runtime.linux_x86;
+package sun.jvm.hotspot.runtime.bsd_x86;
import java.io.*;
import java.util.*;
@@ -33,7 +33,7 @@
import sun.jvm.hotspot.types.*;
import sun.jvm.hotspot.utilities.*;
-public class LinuxX86JavaThreadPDAccess implements JavaThreadPDAccess {
+public class BsdX86JavaThreadPDAccess implements JavaThreadPDAccess {
private static AddressField lastJavaFPField;
private static AddressField osThreadField;
--- agent/src/os/linux/LinuxDebuggerLocal.c 2011-07-26 20:21:17.000000000 -0600
+++ agent/src/os/bsd/BsdDebuggerLocal.c 2011-07-26 20:21:17.000000000 -0600
@@ -22,6 +22,7 @@
*
*/
+#include <stdlib.h>
#include <jni.h>
#include "libproc.h"
@@ -65,15 +66,15 @@
}
/*
- * Class: sun_jvm_hotspot_debugger_linux_LinuxDebuggerLocal
+ * Class: sun_jvm_hotspot_debugger_bsd_BsdDebuggerLocal
* Method: init0
* Signature: ()V
*/
-JNIEXPORT void JNICALL Java_sun_jvm_hotspot_debugger_linux_LinuxDebuggerLocal_init0
+JNIEXPORT void JNICALL Java_sun_jvm_hotspot_debugger_bsd_BsdDebuggerLocal_init0
(JNIEnv *env, jclass cls) {
jclass listClass;
- if (init_libproc(getenv("LIBSAPROC_DEBUG")) != true) {
+ if (init_libproc(getenv("LIBSAPROC_DEBUG") != NULL) != true) {
THROW_NEW_DEBUGGER_EXCEPTION("can't initialize libproc");
}
@@ -102,7 +103,7 @@
CHECK_EXCEPTION;
}
-JNIEXPORT jint JNICALL Java_sun_jvm_hotspot_debugger_linux_LinuxDebuggerLocal_getAddressSize
+JNIEXPORT jint JNICALL Java_sun_jvm_hotspot_debugger_bsd_BsdDebuggerLocal_getAddressSize
(JNIEnv *env, jclass cls)
{
#ifdef _LP64
@@ -155,11 +156,11 @@
}
/*
- * Class: sun_jvm_hotspot_debugger_linux_LinuxDebuggerLocal
+ * Class: sun_jvm_hotspot_debugger_bsd_BsdDebuggerLocal
* Method: attach0
* Signature: (I)V
*/
-JNIEXPORT void JNICALL Java_sun_jvm_hotspot_debugger_linux_LinuxDebuggerLocal_attach0__I
+JNIEXPORT void JNICALL Java_sun_jvm_hotspot_debugger_bsd_BsdDebuggerLocal_attach0__I
(JNIEnv *env, jobject this_obj, jint jpid) {
struct ps_prochandle* ph;
@@ -171,11 +172,11 @@
}
/*
- * Class: sun_jvm_hotspot_debugger_linux_LinuxDebuggerLocal
+ * Class: sun_jvm_hotspot_debugger_bsd_BsdDebuggerLocal
* Method: attach0
* Signature: (Ljava/lang/String;Ljava/lang/String;)V
*/
-JNIEXPORT void JNICALL Java_sun_jvm_hotspot_debugger_linux_LinuxDebuggerLocal_attach0__Ljava_lang_String_2Ljava_lang_String_2
+JNIEXPORT void JNICALL Java_sun_jvm_hotspot_debugger_bsd_BsdDebuggerLocal_attach0__Ljava_lang_String_2Ljava_lang_String_2
(JNIEnv *env, jobject this_obj, jstring execName, jstring coreName) {
const char *execName_cstr;
const char *coreName_cstr;
@@ -199,11 +200,11 @@
}
/*
- * Class: sun_jvm_hotspot_debugger_linux_LinuxDebuggerLocal
+ * Class: sun_jvm_hotspot_debugger_bsd_BsdDebuggerLocal
* Method: detach0
* Signature: ()V
*/
-JNIEXPORT void JNICALL Java_sun_jvm_hotspot_debugger_linux_LinuxDebuggerLocal_detach0
+JNIEXPORT void JNICALL Java_sun_jvm_hotspot_debugger_bsd_BsdDebuggerLocal_detach0
(JNIEnv *env, jobject this_obj) {
struct ps_prochandle* ph = get_proc_handle(env, this_obj);
if (ph != NULL) {
@@ -212,11 +213,11 @@
}
/*
- * Class: sun_jvm_hotspot_debugger_linux_LinuxDebuggerLocal
+ * Class: sun_jvm_hotspot_debugger_bsd_BsdDebuggerLocal
* Method: lookupByName0
* Signature: (Ljava/lang/String;Ljava/lang/String;)J
*/
-JNIEXPORT jlong JNICALL Java_sun_jvm_hotspot_debugger_linux_LinuxDebuggerLocal_lookupByName0
+JNIEXPORT jlong JNICALL Java_sun_jvm_hotspot_debugger_bsd_BsdDebuggerLocal_lookupByName0
(JNIEnv *env, jobject this_obj, jstring objectName, jstring symbolName) {
const char *objectName_cstr, *symbolName_cstr;
jlong addr;
@@ -241,11 +242,11 @@
}
/*
- * Class: sun_jvm_hotspot_debugger_linux_LinuxDebuggerLocal
+ * Class: sun_jvm_hotspot_debugger_bsd_BsdDebuggerLocal
* Method: lookupByAddress0
* Signature: (J)Lsun/jvm/hotspot/debugger/cdbg/ClosestSymbol;
*/
-JNIEXPORT jobject JNICALL Java_sun_jvm_hotspot_debugger_linux_LinuxDebuggerLocal_lookupByAddress0
+JNIEXPORT jobject JNICALL Java_sun_jvm_hotspot_debugger_bsd_BsdDebuggerLocal_lookupByAddress0
(JNIEnv *env, jobject this_obj, jlong addr) {
uintptr_t offset;
const char* sym = NULL;
@@ -258,11 +259,11 @@
}
/*
- * Class: sun_jvm_hotspot_debugger_linux_LinuxDebuggerLocal
+ * Class: sun_jvm_hotspot_debugger_bsd_BsdDebuggerLocal
* Method: readBytesFromProcess0
* Signature: (JJ)Lsun/jvm/hotspot/debugger/ReadResult;
*/
-JNIEXPORT jbyteArray JNICALL Java_sun_jvm_hotspot_debugger_linux_LinuxDebuggerLocal_readBytesFromProcess0
+JNIEXPORT jbyteArray JNICALL Java_sun_jvm_hotspot_debugger_bsd_BsdDebuggerLocal_readBytesFromProcess0
(JNIEnv *env, jobject this_obj, jlong addr, jlong numBytes) {
jboolean isCopy;
@@ -275,19 +276,18 @@
bufPtr = (*env)->GetByteArrayElements(env, array, &isCopy);
CHECK_EXCEPTION_(0);
- err = ps_pdread(get_proc_handle(env, this_obj), (psaddr_t) (uintptr_t)addr, bufPtr, numBytes);
+ err = ps_pread(get_proc_handle(env, this_obj), (psaddr_t) (uintptr_t)addr, bufPtr, numBytes);
(*env)->ReleaseByteArrayElements(env, array, bufPtr, 0);
return (err == PS_OK)? array : 0;
}
-JNIEXPORT jlongArray JNICALL Java_sun_jvm_hotspot_debugger_linux_LinuxDebuggerLocal_getThreadIntegerRegisterSet0
+JNIEXPORT jlongArray JNICALL Java_sun_jvm_hotspot_debugger_bsd_BsdDebuggerLocal_getThreadIntegerRegisterSet0
(JNIEnv *env, jobject this_obj, jint lwp_id) {
- struct user_regs_struct gregs;
+ struct reg gregs;
jboolean isCopy;
jlongArray array;
jlong *regs;
- int i;
struct ps_prochandle* ph = get_proc_handle(env, this_obj);
if (get_lwp_regs(ph, lwp_id, &gregs) != true) {
@@ -317,26 +317,27 @@
#ifdef i386
#define REG_INDEX(reg) sun_jvm_hotspot_debugger_x86_X86ThreadContext_##reg
- regs[REG_INDEX(GS)] = (uintptr_t) gregs.xgs;
- regs[REG_INDEX(FS)] = (uintptr_t) gregs.xfs;
- regs[REG_INDEX(ES)] = (uintptr_t) gregs.xes;
- regs[REG_INDEX(DS)] = (uintptr_t) gregs.xds;
- regs[REG_INDEX(EDI)] = (uintptr_t) gregs.edi;
- regs[REG_INDEX(ESI)] = (uintptr_t) gregs.esi;
- regs[REG_INDEX(FP)] = (uintptr_t) gregs.ebp;
- regs[REG_INDEX(SP)] = (uintptr_t) gregs.esp;
- regs[REG_INDEX(EBX)] = (uintptr_t) gregs.ebx;
- regs[REG_INDEX(EDX)] = (uintptr_t) gregs.edx;
- regs[REG_INDEX(ECX)] = (uintptr_t) gregs.ecx;
- regs[REG_INDEX(EAX)] = (uintptr_t) gregs.eax;
- regs[REG_INDEX(PC)] = (uintptr_t) gregs.eip;
- regs[REG_INDEX(CS)] = (uintptr_t) gregs.xcs;
- regs[REG_INDEX(SS)] = (uintptr_t) gregs.xss;
+ regs[REG_INDEX(GS)] = (uintptr_t) gregs.r_gs;
+ regs[REG_INDEX(FS)] = (uintptr_t) gregs.r_fs;
+ regs[REG_INDEX(ES)] = (uintptr_t) gregs.r_es;
+ regs[REG_INDEX(DS)] = (uintptr_t) gregs.r_ds;
+ regs[REG_INDEX(EDI)] = (uintptr_t) gregs.r_edi;
+ regs[REG_INDEX(ESI)] = (uintptr_t) gregs.r_esi;
+ regs[REG_INDEX(FP)] = (uintptr_t) gregs.r_ebp;
+ regs[REG_INDEX(SP)] = (uintptr_t) gregs.r_isp;
+ regs[REG_INDEX(EBX)] = (uintptr_t) gregs.r_ebx;
+ regs[REG_INDEX(EDX)] = (uintptr_t) gregs.r_edx;
+ regs[REG_INDEX(ECX)] = (uintptr_t) gregs.r_ecx;
+ regs[REG_INDEX(EAX)] = (uintptr_t) gregs.r_eax;
+ regs[REG_INDEX(PC)] = (uintptr_t) gregs.r_eip;
+ regs[REG_INDEX(CS)] = (uintptr_t) gregs.r_cs;
+ regs[REG_INDEX(SS)] = (uintptr_t) gregs.r_ss;
#endif /* i386 */
#if ia64
regs = (*env)->GetLongArrayElements(env, array, &isCopy);
+ int i;
for (i = 0; i < NPRGREG; i++ ) {
regs[i] = 0xDEADDEAD;
}
@@ -345,31 +346,31 @@
#ifdef amd64
#define REG_INDEX(reg) sun_jvm_hotspot_debugger_amd64_AMD64ThreadContext_##reg
- regs[REG_INDEX(R15)] = gregs.r15;
- regs[REG_INDEX(R14)] = gregs.r14;
- regs[REG_INDEX(R13)] = gregs.r13;
- regs[REG_INDEX(R12)] = gregs.r12;
- regs[REG_INDEX(RBP)] = gregs.rbp;
- regs[REG_INDEX(RBX)] = gregs.rbx;
- regs[REG_INDEX(R11)] = gregs.r11;
- regs[REG_INDEX(R10)] = gregs.r10;
- regs[REG_INDEX(R9)] = gregs.r9;
- regs[REG_INDEX(R8)] = gregs.r8;
- regs[REG_INDEX(RAX)] = gregs.rax;
- regs[REG_INDEX(RCX)] = gregs.rcx;
- regs[REG_INDEX(RDX)] = gregs.rdx;
- regs[REG_INDEX(RSI)] = gregs.rsi;
- regs[REG_INDEX(RDI)] = gregs.rdi;
- regs[REG_INDEX(RIP)] = gregs.rip;
- regs[REG_INDEX(CS)] = gregs.cs;
- regs[REG_INDEX(RSP)] = gregs.rsp;
- regs[REG_INDEX(SS)] = gregs.ss;
- regs[REG_INDEX(FSBASE)] = gregs.fs_base;
- regs[REG_INDEX(GSBASE)] = gregs.gs_base;
- regs[REG_INDEX(DS)] = gregs.ds;
- regs[REG_INDEX(ES)] = gregs.es;
- regs[REG_INDEX(FS)] = gregs.fs;
- regs[REG_INDEX(GS)] = gregs.gs;
+ regs[REG_INDEX(R15)] = gregs.r_r15;
+ regs[REG_INDEX(R14)] = gregs.r_r14;
+ regs[REG_INDEX(R13)] = gregs.r_r13;
+ regs[REG_INDEX(R12)] = gregs.r_r12;
+ regs[REG_INDEX(RBP)] = gregs.r_rbp;
+ regs[REG_INDEX(RBX)] = gregs.r_rbx;
+ regs[REG_INDEX(R11)] = gregs.r_r11;
+ regs[REG_INDEX(R10)] = gregs.r_r10;
+ regs[REG_INDEX(R9)] = gregs.r_r9;
+ regs[REG_INDEX(R8)] = gregs.r_r8;
+ regs[REG_INDEX(RAX)] = gregs.r_rax;
+ regs[REG_INDEX(RCX)] = gregs.r_rcx;
+ regs[REG_INDEX(RDX)] = gregs.r_rdx;
+ regs[REG_INDEX(RSI)] = gregs.r_rsi;
+ regs[REG_INDEX(RDI)] = gregs.r_rdi;
+ regs[REG_INDEX(RIP)] = gregs.r_rip;
+ regs[REG_INDEX(CS)] = gregs.r_cs;
+ regs[REG_INDEX(RSP)] = gregs.r_rsp;
+ regs[REG_INDEX(SS)] = gregs.r_ss;
+// regs[REG_INDEX(FSBASE)] = gregs.fs_base;
+// regs[REG_INDEX(GSBASE)] = gregs.gs_base;
+// regs[REG_INDEX(DS)] = gregs.ds;
+// regs[REG_INDEX(ES)] = gregs.es;
+// regs[REG_INDEX(FS)] = gregs.fs;
+// regs[REG_INDEX(GS)] = gregs.gs;
#endif /* amd64 */