From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 25360 invoked by alias); 3 Jun 2008 20:39:05 -0000 Received: (qmail 25334 invoked by uid 367); 3 Jun 2008 20:39:05 -0000 Date: Tue, 03 Jun 2008 20:39:00 -0000 Message-ID: <20080603203905.25319.qmail@sourceware.org> From: cagney@sourceware.org To: frysk-cvs@sourceware.org Subject: [SCM] master: Dynamically allocate/free the dwfl callback struct. X-Git-Refname: refs/heads/master X-Git-Reftype: branch X-Git-Oldrev: 4cd7a853702c58f9b5037d8470d5b79adad712f1 X-Git-Newrev: 4c67208accaec119dcda3f2ec795e8e98584a740 Mailing-List: contact frysk-cvs-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Post: List-Help: , Sender: frysk-cvs-owner@sourceware.org Reply-To: frysk@sourceware.org X-SW-Source: 2008-q2/txt/msg00321.txt.bz2 The branch, master has been updated via 4c67208accaec119dcda3f2ec795e8e98584a740 (commit) from 4cd7a853702c58f9b5037d8470d5b79adad712f1 (commit) Those revisions listed above that are new to this repository have not appeared on any other notification email. - Log ----------------------------------------------------------------- commit 4c67208accaec119dcda3f2ec795e8e98584a740 Author: Andrew Cagney Date: Tue Jun 3 16:32:15 2008 -0400 Dynamically allocate/free the dwfl callback struct. The change to store a per-dwfl debug-info path in the dwfl callback struct wasn't accompanied by a change to allocate the callback struct dynamically. Consequently each successive dwfl-begin call was overwriting the previous debug-info path. frysk-sys/lib/dwfl/ChangeLog 2008-06-03 Andrew Cagney * Dwfl.java (callbackBegin, callbackEnd): New. (Dwfl(String), close()): Use. * cni/Dwfl.cxx: Update. * jni/Dwfl.cxx: Update. ----------------------------------------------------------------------- Summary of changes: frysk-sys/lib/dwfl/ChangeLog | 5 +++ frysk-sys/lib/dwfl/Dwfl.java | 44 +++++++++++++++++++------------ frysk-sys/lib/dwfl/cni/Dwfl.cxx | 55 ++++++++++++++++++++++---------------- frysk-sys/lib/dwfl/jni/Dwfl.cxx | 50 +++++++++++++++++++++++------------ 4 files changed, 97 insertions(+), 57 deletions(-) First 500 lines of diff: diff --git a/frysk-sys/lib/dwfl/ChangeLog b/frysk-sys/lib/dwfl/ChangeLog index e1e448f..527f68b 100644 --- a/frysk-sys/lib/dwfl/ChangeLog +++ b/frysk-sys/lib/dwfl/ChangeLog @@ -1,5 +1,10 @@ 2008-06-03 Andrew Cagney + * Dwfl.java (callbackBegin, callbackEnd): New. + (Dwfl(String), close()): Use. + * cni/Dwfl.cxx: Update. + * jni/Dwfl.cxx: Update. + * Dwfl.java (mapModule): Fix parameter order. * Dwfl.java (mapBegin(long), mapEnd(), mapModule): New. diff --git a/frysk-sys/lib/dwfl/Dwfl.java b/frysk-sys/lib/dwfl/Dwfl.java index 85f1ffd..7dff8a1 100644 --- a/frysk-sys/lib/dwfl/Dwfl.java +++ b/frysk-sys/lib/dwfl/Dwfl.java @@ -46,14 +46,39 @@ public class Dwfl { private static final Log fine = Log.fine(Dwfl.class); private long pointer; + private long callbacks; private DwflModule[] modules; protected final DwarfDieFactory factory = DwarfDieFactory.getFactory(); - public Dwfl(String sysroot) { - pointer = dwflBegin(sysroot); + /** + * Create a dwfl with the specified debug-info search path. + */ + public Dwfl(String debugInfoPath) { + callbacks = callbacksBegin(debugInfoPath); + pointer = dwflBegin(callbacks); + } + private static native long callbacksBegin(String debugInfoSearchPath); + private static native long dwflBegin(long callbacks); + + protected void finalize () { + if (this.pointer != 0) { + fine.log(this, "finalize doing close"); + close(); + } + } + public void close() { + if (this.pointer != 0) { + dwflEnd(pointer); + this.pointer = 0; + callbacksEnd(callbacks); + this.callbacks = 0; + } } + private static native void dwflEnd(long pointer); + private static native void callbacksEnd(long callbacks); + /** * Get all the DwflModule objects associated with this Dwfl. Use a @@ -114,10 +139,6 @@ public class Dwfl { return pointer; } - protected void finalize () { - close(); - } - /** * Get all the DwflLine objects associated with a line in a source file. */ @@ -164,15 +185,6 @@ public class Dwfl { return factory; } - public void close() { - if (this.pointer != 0) { - dwfl_end(); - this.pointer = 0; - } - } - - private static native long dwflBegin (String s); - /** * Start a refresh of the address map. */ @@ -264,8 +276,6 @@ public class Dwfl { reportEnd(); } - protected native void dwfl_end (); - // protected native long[] dwfl_get_modules(); // protected native long[] dwfl_getdwarf(); protected native long dwfl_getsrc (long addr); diff --git a/frysk-sys/lib/dwfl/cni/Dwfl.cxx b/frysk-sys/lib/dwfl/cni/Dwfl.cxx index d369e55..006dfb9 100644 --- a/frysk-sys/lib/dwfl/cni/Dwfl.cxx +++ b/frysk-sys/lib/dwfl/cni/Dwfl.cxx @@ -73,6 +73,7 @@ extern "C" void *arg); } #define DWFL_POINTER ((::Dwfl *) pointer) +#define DWFL_CALLBACKS ((::Dwfl_Callbacks *) callbacks) static ssize_t read_proc_memory (void *arg, void *data, GElf_Addr address, @@ -128,23 +129,37 @@ dwfl_frysk_proc_find_elf (Dwfl_Module *mod, } jlong -lib::dwfl::Dwfl::dwflBegin(jstring jsysroot) -{ - int len = jsysroot->length (); - char sysroot[len+1]; - JvGetStringUTFRegion(jsysroot, 0, len, sysroot); - sysroot[len] = '\0'; - static char* flags; - if (asprintf (&flags, ".debug:%s", sysroot) < 0) - return (jlong) NULL; - - static Dwfl_Callbacks callbacks = { - &::dwfl_frysk_proc_find_elf, - &::dwfl_standard_find_debuginfo, - NULL, - &flags, - }; - return (jlong) ::dwfl_begin(&callbacks); +lib::dwfl::Dwfl::callbacksBegin(jstring debugInfoPath) { + char** path = (char**) JvMalloc(sizeof (char*)); + int len = JvGetStringUTFLength(debugInfoPath); + *path = (char*)JvMalloc(len + 1); + JvGetStringUTFRegion(debugInfoPath, 0, len, *path); + (*path)[len] = '\0'; + jlong callbacks = (jlong) JvMalloc(sizeof(Dwfl_Callbacks)); + if (DWFL_CALLBACKS == 0) { + return 0; + } + DWFL_CALLBACKS->find_elf = &::dwfl_frysk_proc_find_elf; + DWFL_CALLBACKS->find_debuginfo = &::dwfl_standard_find_debuginfo; + DWFL_CALLBACKS->debuginfo_path = path; + return callbacks; +} + +void +lib::dwfl::Dwfl::callbacksEnd(jlong callbacks) { + JvFree(*DWFL_CALLBACKS->debuginfo_path); + JvFree(DWFL_CALLBACKS->debuginfo_path); + JvFree(DWFL_CALLBACKS); +} + +jlong +lib::dwfl::Dwfl::dwflBegin(jlong callbacks) { + return (jlong) ::dwfl_begin(DWFL_CALLBACKS); +} + +void +lib::dwfl::Dwfl::dwflEnd(jlong pointer){ + ::dwfl_end(DWFL_POINTER); } void @@ -171,12 +186,6 @@ lib::dwfl::Dwfl::reportModule(jlong pointer, jstring moduleName, (::Dwarf_Addr) high); } -void -lib::dwfl::Dwfl::dwfl_end(){ - ::dwfl_end(DWFL_POINTER); -} - - extern "C" int moduleCounter(Dwfl_Module *, void **, const char *, Dwarf_Addr, void *arg) { diff --git a/frysk-sys/lib/dwfl/jni/Dwfl.cxx b/frysk-sys/lib/dwfl/jni/Dwfl.cxx index 7e84be0..7cb3472 100644 --- a/frysk-sys/lib/dwfl/jni/Dwfl.cxx +++ b/frysk-sys/lib/dwfl/jni/Dwfl.cxx @@ -43,6 +43,7 @@ #include #include #include +#include #include "jni.hxx" @@ -69,6 +70,9 @@ extern "C" { // Assume the method was parameterised with POINTER. #define DWFL_POINTER ((::Dwfl *)pointer) +// Ditto for callbacks pointer. +#define DWFL_CALLBACKS ((::Dwfl_Callbacks*)callbacks) + struct proc_memory_context { jnixx::env env; inua::eio::ByteBuffer memory; @@ -130,18 +134,36 @@ dwfl_frysk_proc_find_elf(Dwfl_Module *mod, } jlong -lib::dwfl::Dwfl::dwflBegin(jnixx::env env, String jsysroot) { - jstringUTFChars sysroot = jstringUTFChars(env, jsysroot); - static char* flags; - if (asprintf (&flags, ".debug:%s", sysroot.elements()) < 0) +lib::dwfl::Dwfl::callbacksBegin(jnixx::env env, String jdebugInfoPath) { + jstringUTFChars debugInfoPath = jstringUTFChars(env, jdebugInfoPath); + char** path = (char**) ::malloc(sizeof (char*)); + if (path == NULL) { return 0; - static Dwfl_Callbacks callbacks = { - &::dwfl_frysk_proc_find_elf, - &::dwfl_standard_find_debuginfo, - NULL, - &flags, - }; - return (jlong) ::dwfl_begin(&callbacks); + } + *path = ::strdup(debugInfoPath.elements()); + jlong callbacks = (jlong) ::malloc(sizeof(Dwfl_Callbacks)); + ::memset(DWFL_CALLBACKS, 0, sizeof(Dwfl_Callbacks)); + DWFL_CALLBACKS->find_elf = &::dwfl_frysk_proc_find_elf; + DWFL_CALLBACKS->find_debuginfo = &::dwfl_standard_find_debuginfo; + DWFL_CALLBACKS->debuginfo_path = path; + return callbacks; +} + +void +lib::dwfl::Dwfl::callbacksEnd(jnixx::env env, jlong callbacks) { + ::free(*DWFL_CALLBACKS->debuginfo_path); + ::free(DWFL_CALLBACKS->debuginfo_path); + ::free(DWFL_CALLBACKS); +} + +jlong +lib::dwfl::Dwfl::dwflBegin(jnixx::env env, jlong callbacks) { + return (jlong) ::dwfl_begin(DWFL_CALLBACKS); +} + +void +lib::dwfl::Dwfl::dwflEnd(jnixx::env env, jlong pointer) { + ::dwfl_end(DWFL_POINTER); } void @@ -163,12 +185,6 @@ lib::dwfl::Dwfl::reportModule(jnixx::env env, jlong pointer, (::Dwarf_Addr) low, (::Dwarf_Addr) high); } -void -lib::dwfl::Dwfl::dwfl_end(jnixx::env env) { - ::dwfl_end(DWFL_POINTER_FIXME); -} - - static int moduleCounter(Dwfl_Module *, void **, const char *, Dwarf_Addr, void *arg) { hooks/post-receive -- frysk system monitor/debugger