From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 3032 invoked by alias); 20 Oct 2003 14:25:32 -0000 Mailing-List: contact gdb-patches-help@sources.redhat.com; run by ezmlm Precedence: bulk List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sources.redhat.com Received: (qmail 3024 invoked from network); 20 Oct 2003 14:25:31 -0000 Received: from unknown (HELO maxipes.logix.cz) (81.0.234.97) by sources.redhat.com with SMTP; 20 Oct 2003 14:25:31 -0000 Received: from suse.cz (styx.suse.cz [213.210.157.162]) (using TLSv1 with cipher RC4-MD5 (128/128 bits)) (Client CN "Michal Ludvig", Issuer "Personal Freemail RSA 2000.8.30" (verified OK)) by maxipes.logix.cz (Postfix) with ESMTP id 09B9429A65 for ; Mon, 20 Oct 2003 16:25:30 +0200 (CEST) Message-ID: <3F93F058.5060104@suse.cz> Date: Mon, 20 Oct 2003 14:25:00 -0000 From: Michal Ludvig Organization: SuSE CR, s.r.o. User-Agent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.5) Gecko/20030925 X-Accept-Language: cs, cz, en MIME-Version: 1.0 To: GDB Patches Subject: [RFA] Find the most specific symtab Content-Type: multipart/mixed; boundary="------------010401020003020000060900" X-SW-Source: 2003-10/txt/msg00614.txt.bz2 This is a multi-part message in MIME format. --------------010401020003020000060900 Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit Content-length: 1482 Hi, when debugging modules in linux kernel one must load symtab from each module using add-symbol-file command. However find_pc_sect_psymtab() returns with the first, usually less specific entry among all psymtabs instead of the newly added one, which leads to a situation where the wrong source file is chosen and therefore the "next", "next", ... stepping is unusable. The attached patch modifies find_pc_sect_psymtab() so that it always returns the most specific symtab. Typical debugging session with verbosity tured on now looks like: $ ./gdb /share/linux-2.4.21-2-mludvig/vmlinux GNU gdb 2003-10-20-cvs [...] (gdb) add-symbol-file /share/lkm/lkm.o 0xffa00180c0 add symbol table from file "/share/lkm/lkm.o" at .text_addr = 0xffa00180c0 (y or n) y Reading symbols from /share/lkm/lkm.o...done. (gdb) set verbose (gdb) l lkm_exit More symtabs for PC=0xffffffffa00181b0 found: Ignoring vsyscall.c (vmlinux) PC=0xff802c9400...0xffff60042a Choosing lkm.c (lkm.o) PC=0xffa00180c0...0xffa00181d9 55 void 56 lkm_exit(void) 57 { 58 printk(KERN_INFO "Exitting LKM (jiffies=%lu)...\n", jiffies); 59 lkm_func(jiffies); 60 } 61 (gdb) OK for mainline? Or should there be a different approach? Michal Ludvig -- sUsE cR, s.R.o mludvig@suse.cz | I would like to change (+420) 296.545.373 http://www.suse.cz | the world, but they wont Personal homepage http://www.logix.cz/~mic | tell me the source code. --------------010401020003020000060900 Content-Type: text/plain; name="symtab-minimal-2-head.diff" Content-Transfer-Encoding: quoted-printable Content-Disposition: inline; filename="symtab-minimal-2-head.diff" Content-length: 3265 2003-10-23 Michal Ludvig * symtab.c (choose_better_psymab): New function. (find_pc_sect_psymtab): Instead of returning first=20 matching psymtab choose the most specific one. Index: symtab.c =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D RCS file: /cvs/src/src/gdb/symtab.c,v retrieving revision 1.113.4.1 diff -u -p -r1.113.4.1 symtab.c --- symtab.c 8 Aug 2003 14:06:26 -0000 1.113.4.1 +++ symtab.c 20 Oct 2003 09:56:31 -0000 @@ -673,13 +673,63 @@ init_sal (struct symtab_and_line *sal) } =0C =20 +/* Return psymtab with more specific address range. */ + +static inline struct partial_symtab * +choose_better_psymab (CORE_ADDR pc, struct partial_symtab *pst1, + struct partial_symtab *pst2) +{ + if (pst1 =3D=3D NULL) + return pst2; + + if (pst2 =3D=3D NULL) + return pst1; + + if ((pst1->texthigh - pst1->textlow) > (pst2->texthigh - pst2->textlow)) + { + static CORE_ADDR last_pc =3D 0; + + if (pc !=3D last_pc && info_verbose) + { + char *objname[2]; + struct partial_symtab *pst[2] =3D { pst1, pst2 }; + int i; + + for (i =3D 0; i < 2; i++) + { + if (pst[i]->objfile) + objname[i] =3D strrchr (pst[i]->objfile->name, '/') + ? strrchr (pst[i]->objfile->name, '/') + 1 + : pst[i]->objfile->name; + else + objname[i] =3D ""; + } +=09 + printf_unfiltered ("More symtabs for PC=3D0x%lx found:\n" + "\tIgnoring %s (%s) PC=3D0x%lx...0x%lx\n" + "\tChoosing %s (%s) PC=3D0x%lx...0x%lx\n", + (unsigned long) pc, + pst1->filename, objname[0], + (unsigned long) pst1->textlow, + (unsigned long) pst1->texthigh, + pst2->filename, objname[1], + (unsigned long) pst2->textlow, + (unsigned long) pst2->texthigh); + + last_pc =3D pc; + } + return pst2; + } + else + return pst1; +} =20 /* Find which partial symtab on contains PC and SECTION. Return 0 if none= . */ =20 struct partial_symtab * find_pc_sect_psymtab (CORE_ADDR pc, asection *section) { - struct partial_symtab *pst; + struct partial_symtab *pst, *result =3D NULL; struct objfile *objfile; struct minimal_symbol *msymbol; =20 @@ -707,10 +757,16 @@ find_pc_sect_psymtab (CORE_ADDR pc, asec function containing the PC. */ if (!(objfile->flags & OBJF_REORDERED) && section =3D=3D 0) /* can't validate section this way */ - return (pst); + { + result =3D choose_better_psymab (pc, result, pst); + continue; + } =20 if (msymbol =3D=3D NULL) - return (pst); + { + result =3D choose_better_psymab (pc, result, pst); + continue; + } =20 for (tpst =3D pst; tpst !=3D NULL; tpst =3D tpst->next) { @@ -722,13 +778,17 @@ find_pc_sect_psymtab (CORE_ADDR pc, asec if (p !=3D NULL && SYMBOL_VALUE_ADDRESS (p) =3D=3D SYMBOL_VALUE_ADDRESS (msymbol)) - return (tpst); + { + result =3D choose_better_psymab (pc, result, tpst); + } } } - return (pst); + + result =3D choose_better_psymab (pc, result, pst); } } - return (NULL); +=20 + return (result); } =20 /* Find which partial symtab contains PC. Return 0 if none.=20 --------------010401020003020000060900--