From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 7266 invoked by alias); 22 Apr 2009 20:05:46 -0000 Received: (qmail 7257 invoked by uid 22791); 22 Apr 2009 20:05:45 -0000 X-SWARE-Spam-Status: No, hits=-1.6 required=5.0 tests=AWL,BAYES_00,KAM_STOCKGEN,SPF_HELO_PASS,SPF_PASS X-Spam-Check-By: sourceware.org Received: from mx2.redhat.com (HELO mx2.redhat.com) (66.187.237.31) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Wed, 22 Apr 2009 20:05:36 +0000 Received: from int-mx2.corp.redhat.com (int-mx2.corp.redhat.com [172.16.27.26]) by mx2.redhat.com (8.13.8/8.13.8) with ESMTP id n3MK5XvB032604 for ; Wed, 22 Apr 2009 16:05:33 -0400 Received: from ns3.rdu.redhat.com (ns3.rdu.redhat.com [10.11.255.199]) by int-mx2.corp.redhat.com (8.13.1/8.13.1) with ESMTP id n3MK5Wmi024502; Wed, 22 Apr 2009 16:05:32 -0400 Received: from host0.dyn.jankratochvil.net (sebastian-int.corp.redhat.com [172.16.52.221]) by ns3.rdu.redhat.com (8.13.8/8.13.8) with ESMTP id n3MK5Vft026258; Wed, 22 Apr 2009 16:05:31 -0400 Received: from host0.dyn.jankratochvil.net (localhost [127.0.0.1]) by host0.dyn.jankratochvil.net (8.14.3/8.14.3) with ESMTP id n3MK5UdR010688; Wed, 22 Apr 2009 22:05:30 +0200 Received: (from jkratoch@localhost) by host0.dyn.jankratochvil.net (8.14.3/8.14.2/Submit) id n3MK5TUw010687; Wed, 22 Apr 2009 22:05:29 +0200 Date: Wed, 22 Apr 2009 20:05:00 -0000 From: Jan Kratochvil To: Tom Tromey Cc: gdb-patches@sourceware.org Subject: Re: [patch] Make a function for block->objfile lookups Message-ID: <20090422200529.GA18314@host0.dyn.jankratochvil.net> References: <20090422183915.GA20196@host0.dyn.jankratochvil.net> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.18 (2008-05-17) X-IsSubscribed: yes Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org X-SW-Source: 2009-04/txt/msg00609.txt.bz2 On Wed, 22 Apr 2009 21:17:12 +0200, Tom Tromey wrote: > Just to be sure I understand... in the loop in display_uses_solib_p, > there are two checks: > > if (block != NULL > && solib_contains_address_p (solib, block->startaddr)) > return 1; > > if (section && section->objfile == solib->objfile) > return 1; > > So I gather from this change that the first check is checking for > functions and the second one will handle variables coming from the > solib? Yes. This patch does not change anything wrt it. Made a comment there now. BTW I do not see expression->block to be set anywhere, only display->block is AFAICS in charge by the current outer GDB (C) code. > And that is why it is ok to replace the first change with block_objfile? My > concern here is that the patch not affect the semantics of the existing > check; and I don't really know the block stuff very well. - if (block != NULL - && solib_contains_address_p (solib, block->startaddr)) + if (matching_objfiles (block_objfile (block), objfile)) This is a different implementation but IMO with the same result. solib_contains_address_p existence makes sense as sometimes it is being used when only CORE_ADDR is available. But at this point we have full `struct block' which should be even cheaper to resolve by getting the (non-inlined) function name -> symbol table -> objfile. If there would not be full DWARF available there would be no `struct block'. This change is required for the later use in varobj.c patch where so_list does not have to be available. > Assuming my understanding of the semantics is correct, then this is ok > with the above fixlets. Thanks. Sorry for that indentation/placement. Thanks, Jan gdb/ 2009-04-22 Jan Kratochvil * block.c (block_objfile): New function. * block.h (block_objfile): New prototype. * objfiles.c (matching_objfiles): New function. * objfiles.h (matching_objfiles): New prototype. * printcmd.c: Remove include solib.h. (display_uses_solib_p): Rename to ... (display_uses_objfile): ... a new function name. Change the SOLIB parameter to OBJFILE parameter. Use now a matching_objfiles call. (clear_dangling_display_expressions): Update the caller. --- gdb/block.c 3 Jan 2009 05:57:50 -0000 1.18 +++ gdb/block.c 22 Apr 2009 19:51:40 -0000 @@ -309,3 +309,21 @@ allocate_block (struct obstack *obstack) return bl; } + +/* Return OBJFILE in which BLOCK is located or NULL if we cannot find it for + whatever reason. */ + +struct objfile * +block_objfile (const struct block *block) +{ + struct symbol *func; + + if (block == NULL) + return NULL; + + func = block_linkage_function (block); + if (func == NULL) + return NULL; + + return SYMBOL_SYMTAB (func)->objfile; +} --- gdb/block.h 3 Jan 2009 05:57:50 -0000 1.19 +++ gdb/block.h 22 Apr 2009 19:51:40 -0000 @@ -164,4 +164,6 @@ extern const struct block *block_global_ extern struct block *allocate_block (struct obstack *obstack); +extern struct objfile *block_objfile (const struct block *block); + #endif /* BLOCK_H */ --- gdb/objfiles.c 11 Mar 2009 20:26:02 -0000 1.82 +++ gdb/objfiles.c 22 Apr 2009 19:51:40 -0000 @@ -891,3 +891,21 @@ objfile_data (struct objfile *objfile, c gdb_assert (data->index < objfile->num_data); return objfile->data[data->index]; } + +/* Return non-zero if A and B point to the same OBJFILE, ignoring any binary + vs. debuginfo variants of the pointers. If either A or B is NULL return + zero as not a match. */ + +int +matching_objfiles (struct objfile *a, struct objfile *b) +{ + if (a == NULL || b == NULL) + return 0; + + if (a->separate_debug_objfile_backlink) + a = a->separate_debug_objfile_backlink; + if (b->separate_debug_objfile_backlink) + b = b->separate_debug_objfile_backlink; + + return a == b; +} --- gdb/objfiles.h 15 Jan 2009 16:35:22 -0000 1.59 +++ gdb/objfiles.h 22 Apr 2009 19:51:40 -0000 @@ -497,6 +497,8 @@ extern struct obj_section *find_pc_secti extern int in_plt_section (CORE_ADDR, char *); +extern int matching_objfiles (struct objfile *a, struct objfile *b); + /* Keep a registry of per-objfile data-pointers required by other GDB modules. */ --- gdb/printcmd.c 25 Mar 2009 22:38:46 -0000 1.150 +++ gdb/printcmd.c 22 Apr 2009 19:51:40 -0000 @@ -46,7 +46,6 @@ #include "exceptions.h" #include "observer.h" #include "solist.h" -#include "solib.h" #include "parser-defs.h" #include "charset.h" @@ -1760,19 +1759,17 @@ disable_display_command (char *args, int } } -/* Return 1 if D uses SOLIB (and will become dangling when SOLIB +/* Return 1 if D uses OBJFILE (and will become dangling when OBJFILE is unloaded), otherwise return 0. */ static int -display_uses_solib_p (const struct display *d, - const struct so_list *solib) +display_uses_objfile (const struct display *d, struct objfile *objfile) { int endpos; struct expression *const exp = d->exp; const union exp_element *const elts = exp->elts; - if (d->block != NULL - && solib_contains_address_p (solib, d->block->startaddr)) + if (matching_objfiles (block_objfile (d->block), objfile)) return 1; for (endpos = exp->nelts; endpos > 0; ) @@ -1791,11 +1788,12 @@ display_uses_solib_p (const struct displ const struct obj_section *const section = SYMBOL_OBJ_SECTION (symbol); - if (block != NULL - && solib_contains_address_p (solib, block->startaddr)) + /* Check objfile where is placed the code touching the variable. */ + if (matching_objfiles (block_objfile (block), objfile)) return 1; - if (section && section->objfile == solib->objfile) + /* Check objfile where the variable itself is placed. */ + if (section && section->objfile == objfile) return 1; } endpos -= oplen; @@ -1820,7 +1818,7 @@ clear_dangling_display_expressions (stru for (d = display_chain; d; d = d->next) { - if (d->exp && display_uses_solib_p (d, solib)) + if (d->exp && display_uses_objfile (d, solib->objfile)) { xfree (d->exp); d->exp = NULL;