[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: devel/jdk status?



Who was working on 1.2?  Is there a dladdr function defined in the
OpenBSD patches there?  If so, try using this code (it is in
src/solaris/hpi/src/linker_md.c in 1.3.1) I have adapted from
code written by Dale Rahn:

#if defined(__OpenBSD__)
char *
dlfname(const void *addr)
{
#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);
    for (; so_map; so_map = so_map->som_next) {
	if (addr >= (void *) so_map->som_addr
	    && (so_map->som_next == 0
		|| addr < (void *) so_map->som_next->som_addr)) {
	    break;
	}
    }
    return so_map ? so_map->som_path : NULL;
#endif
}

int
dladdr(const void *addr, Dl_info *info)
{
    return((info->dli_fname = dlfname(addr)) ? 1 : 0);
}
#endif