From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 25697 invoked by alias); 22 Apr 2009 18:39:35 -0000 Received: (qmail 25686 invoked by uid 22791); 22 Apr 2009 18:39:33 -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 18:39:23 +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 n3MIdKLD006640 for ; Wed, 22 Apr 2009 14:39:20 -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 n3MIdJP7026379 for ; Wed, 22 Apr 2009 14:39:20 -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 n3MIdInE006014 for ; Wed, 22 Apr 2009 14:39:19 -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 n3MIdGAI004593 for ; Wed, 22 Apr 2009 20:39:17 +0200 Received: (from jkratoch@localhost) by host0.dyn.jankratochvil.net (8.14.3/8.14.2/Submit) id n3MIdGAK004590 for gdb-patches@sourceware.org; Wed, 22 Apr 2009 20:39:16 +0200 Date: Wed, 22 Apr 2009 18:39:00 -0000 From: Jan Kratochvil To: gdb-patches@sourceware.org Subject: [patch] Make a function for block->objfile lookups Message-ID: <20090422183915.GA20196@host0.dyn.jankratochvil.net> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline 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/msg00602.txt.bz2 Hi, the patch generalizes the `display' command code to use objfile and not so_list matching; the modified code was created recently by: Re: Fix a crash when displaying variables from shared library. http://sourceware.org/ml/gdb-patches/2009-03/msg00090.html This patch was made so that it can be reused from varobj.c where only objfile (not so_list) is available. [patch] [4/5] Types reference counting [varobj-validation] http://sourceware.org/ml/gdb-patches/2009-04/threads.html#00203 I found it as a simplification, one may disagree. I can use matching_objfiles/block_objfile just for varobj.c. No regressions on x86_64-unknown-linux-gnu. 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 18:15:44 -0000 @@ -309,3 +309,20 @@ 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 18:15:44 -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 18:15:44 -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 18:15:45 -0000 @@ -508,6 +508,7 @@ extern void set_objfile_data (struct obj const struct objfile_data *data, void *value); extern void *objfile_data (struct objfile *objfile, const struct objfile_data *data); +extern int matching_objfiles (struct objfile *a, struct objfile *b); /* Traverse all object files. ALL_OBJFILES_SAFE works even if you delete --- gdb/printcmd.c 25 Mar 2009 22:38:46 -0000 1.150 +++ gdb/printcmd.c 22 Apr 2009 18:15:45 -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,10 @@ 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)) + if (matching_objfiles (block_objfile (block), objfile)) return 1; - if (section && section->objfile == solib->objfile) + if (section && section->objfile == objfile) return 1; } endpos -= oplen; @@ -1820,7 +1816,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;