Date: Fri, 13 Sep 2002 23:26:36 +0200 From: Thomas Moestl <tmoestl@gmx.net> To: sparc@freebsd.org Subject: Re: No gdb yet? Message-ID: <20020913212636.GD6560@crow.dom2ip.de> In-Reply-To: <20020913210535.GC6560@crow.dom2ip.de> References: <XFMail.20020913141454.jhb@FreeBSD.org> <200209132045.g8DKjloj035471@vashon.polstra.com> <20020913210535.GC6560@crow.dom2ip.de>
next in thread | previous in thread | raw e-mail | index | archive | help
On Fri, 2002/09/13 at 23:05:35 +0200, Thomas Moestl wrote: > It's at > http://people.freebsd.org/~jake/coredump.tar > > I've attached a small patch that should make it work better with > stripped dynamic objects (particularly rtld) by looking for symbols in > the dynamic symtab too. Oh, sorry, that patch was outdated, I've attached an improved and cleaned-up one. - Thomas -- Thomas Moestl <tmoestl@gmx.net> http://www.tu-bs.de/~y0015675/ <tmm@FreeBSD.org> http://people.FreeBSD.org/~tmm/ PGP fingerprint: 1C97 A604 2BD0 E492 51D0 9C0F 1FE6 4F1D 419C 776C diff -ur coredump/coredump.c coredump.tmm/coredump.c --- coredump/coredump.c Thu Jul 18 00:27:29 2002 +++ coredump.tmm/coredump.c Fri Sep 13 23:28:44 2002 @@ -232,14 +232,11 @@ } static Elf_Sym * -elf_find_sym_by_address(Elf_Ehdr *e, Elf_Addr addr) +elf_search_symtab_address(Elf_Ehdr *e, Elf_Shdr *sh, Elf_Addr addr) { - Elf_Shdr *sh; Elf_Sym *st; int i; - if ((sh = elf_find_shdr(e, ".symtab", 0)) == NULL) - return (NULL); st = (Elf_Sym *)((char *)e + sh->sh_offset); for (i = 0; i < sh->sh_size / sizeof(*st); i++) { if (addr >= st[i].st_value && @@ -250,24 +247,53 @@ } static Elf_Sym * -elf_find_sym_by_name(Elf_Ehdr *e, char *name) +elf_find_sym_by_address(Elf_Ehdr *e, Elf_Addr addr) { Elf_Shdr *sh; + Elf_Sym *s; + + if ((sh = elf_find_shdr(e, ".symtab", 0)) != NULL && + (s = elf_search_symtab_address(e, sh, addr)) != NULL) + return (s); + + if ((sh = elf_find_shdr(e, ".dynsym", 0)) == NULL) + return (NULL); + return (elf_search_symtab_address(e, sh, addr)); +} + +static Elf_Sym * +elf_search_symtab_name(Elf_Ehdr *e, Elf_Shdr *shstr, Elf_Shdr *shtab, + char *name) +{ Elf_Sym *st; char *strtab; int i; - if ((sh = elf_find_shdr(e, ".strtab", 0)) == NULL) - return (NULL); - strtab = (char *)e + sh->sh_offset; - if ((sh = elf_find_shdr(e, ".symtab", 0)) == NULL) - return (NULL); - st = (Elf_Sym *)((char *)e + sh->sh_offset); - for (i = 0; i < sh->sh_size / sizeof(*st); i++) { + strtab = (char *)e + shstr->sh_offset; + st = (Elf_Sym *)((char *)e + shtab->sh_offset); + for (i = 0; i < shtab->sh_size / sizeof(*st); i++) { if (strcmp(name, strtab + st[i].st_name) == 0) return (&st[i]); } return (NULL); +} + +static Elf_Sym * +elf_find_sym_by_name(Elf_Ehdr *e, char *name) +{ + Elf_Shdr *shstr, *shtab; + Elf_Sym *s; + + if ((shstr = elf_find_shdr(e, ".strtab", 0)) != NULL && + (shtab = elf_find_shdr(e, ".symtab", 0)) != NULL && + (s = elf_search_symtab_name(e, shstr, shtab, name)) != NULL) + return (s); + + if ((shstr = elf_find_shdr(e, ".dynstr", 0)) == NULL || + (shtab = elf_find_shdr(e, ".dynsym", 0)) == NULL) + return (NULL); + + return (elf_search_symtab_name(e, shstr, shtab, name)); } static int To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-sparc" in the body of the message
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20020913212636.GD6560>