From owner-freebsd-sparc Fri Sep 13 14:25:46 2002 Delivered-To: freebsd-sparc@freebsd.org Received: from mx1.FreeBSD.org (mx1.FreeBSD.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 329EB37B400 for ; Fri, 13 Sep 2002 14:25:42 -0700 (PDT) Received: from mail.gmx.net (mail.gmx.net [213.165.64.20]) by mx1.FreeBSD.org (Postfix) with SMTP id 1E13843E3B for ; Fri, 13 Sep 2002 14:25:41 -0700 (PDT) (envelope-from tmoestl@gmx.net) Received: (qmail 13139 invoked by uid 0); 13 Sep 2002 21:25:39 -0000 Received: from pd9538d06.dip.t-dialin.net (HELO forge.local) (217.83.141.6) by mail.gmx.net (mp016-rz3) with SMTP; 13 Sep 2002 21:25:39 -0000 Received: from tmm by forge.local with local (Exim 4.10 #1) id 17pxxU-0009fe-00 for ; Fri, 13 Sep 2002 23:26:36 +0200 Date: Fri, 13 Sep 2002 23:26:36 +0200 From: Thomas Moestl To: sparc@freebsd.org Subject: Re: No gdb yet? Message-ID: <20020913212636.GD6560@crow.dom2ip.de> Mail-Followup-To: sparc@freebsd.org References: <200209132045.g8DKjloj035471@vashon.polstra.com> <20020913210535.GC6560@crow.dom2ip.de> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20020913210535.GC6560@crow.dom2ip.de> User-Agent: Mutt/1.4i Sender: owner-freebsd-sparc@FreeBSD.ORG Precedence: bulk List-ID: List-Archive: (Web Archive) List-Help: (List Instructions) List-Subscribe: List-Unsubscribe: X-Loop: FreeBSD.org 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 http://www.tu-bs.de/~y0015675/ 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