Pantek Library
Hosting Provided By
CybrHost
High Speed Hosting

Re: Debugging ld.so

From: Kurt Miller <truk(at)optonline.net>
Date: Tue Jul 08 2003 - 11:48:24 EDT

From: "Dale Rahn" <dalerahn@comcast.net>
> You are right about the ... sym->st_value + ooff ... is supposed to

I haven't had a chance to try your suggestions yet. My day job seems to be getting in the way of getting my preferred work done. ;-) However, my setup is as follows:

  1. A very -current i386 system so as to include some necessary commits from niklas@ and theo in the libexec area.
  2. A slightly modified port for devel/jdk/1.2 that includes a patch niklas@ posted to the ports list and a modified Makefile to build only the debug version of the jdk.

Change the ALL_TARGET from release-images to world-debug to build only the debug versions of the jdk.

Place the following into the patches directory in the port:

patch-src_bsd_hpi_src_linker_md_c:
$OpenBSD$
--- src/bsd/hpi/src/linker_md.c.orig Sun Jun 8 10:43:23 2003 +++ src/bsd/hpi/src/linker_md.c Sun Jun 8 10:50:44 2003 @@ -251,6 +251,42 @@ char *
 dlfname(const void *addr)
 {
 #if defined(__OpenBSD__) || (defined(__FreeBSD__) && (__FreeBSD__ < 3))

+#ifdef __ELF__
+    int tag;
+    Elf_Dyn *dp;
+    struct link_map *lm;
+    Elf_Ehdr *ehdr;
+    Elf_Phdr *phdr;
+    char *s;
+    int i;
+
+    for (dp = _DYNAMIC; (tag = dp->d_tag) != 0; dp++) {
+        if (tag == DT_DEBUG) {
+            lm = ((struct r_debug *)(dp->d_un.d_ptr))->r_map;
+        }
+    }
+
+    for (; lm != NULL; lm = lm->l_next) {
+        ehdr = (Elf_Ehdr *)lm->l_addr;
+        if (ehdr == NULL)
+                continue;
+
+        phdr = (Elf_Phdr *)((char *)lm->l_addr + ehdr->e_phoff);
+
+        for (i = 0; i < ehdr->e_phnum; i++) {
+                switch (phdr[i].p_type) {
+                case PT_LOAD:
+                        s = (char *)phdr[i].p_vaddr + (int)lm->l_addr;
+                        if (addr >= s && addr < s + phdr[i].p_memsz)
+                                return lm->l_name;
+                        break;
+                default:
+                }
+        }
+    }
+
+    return NULL;
+#else
     struct so_map *so_map;

     so_map = (struct so_map *)dlopen(0, RTLD_LAZY);
@@ -262,6 +298,7 @@ dlfname(const void *addr)
        }
     }
     return so_map ? so_map->som_path : NULL;
+#endif
 #else

     Obj_Entry * so_map;

3) Manually fetch the source from Sun and the BSD patchset from eyesbeyond as described in the port Makefile. Build the port and it will fail upon the first execution on javac_g.

Do you need help?X

4) I debug using the following .gdbinit file to save typing: set environment
LD_LIBRARY_PATH=/usr/ports/devel/jdk/1.2/w-jdk-1.2.2/build/bsd/bin/../lib/i3 86/green_threads:/usr/ports/devel/jdk/1.2/w-jdk-1.2.2/build/bsd/bin/../lib/i 386/classic:/usr/ports/devel/jdk/1.2/w-jdk-1.2.2/build/bsd/bin/../lib/i386: set environment LD_DEBUG=1
#set environment LD_TRACE_LOADED_OBJECTS=1 set environment LD_NORANDOM=1
file
/usr/ports/devel/jdk/1.2/w-jdk-1.2.2/build/bsd/bin/i386/green_threads/javac_ g
break main Received on Tue Jul 8 00:09:51 2003

This archive was generated by hypermail 2.1.8 : Wed Aug 23 2006 - 13:48:42 EDT


Contact Us  Legal Notices  Order Services Online 
Pantek Home  Privacy Policy  IT news  Site Map  Pantek Library