From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 20713 invoked by alias); 9 May 2012 19:08:19 -0000 Received: (qmail 20699 invoked by uid 22791); 9 May 2012 19:08:16 -0000 X-SWARE-Spam-Status: No, hits=-1.1 required=5.0 tests=AWL,BAYES_00,KAM_STOCKGEN,RCVD_IN_HOSTKARMA_NO,TW_BJ,TW_TX X-Spam-Check-By: sourceware.org Received: from rock.gnat.com (HELO rock.gnat.com) (205.232.38.15) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Wed, 09 May 2012 19:08:02 +0000 Received: from localhost (localhost.localdomain [127.0.0.1]) by filtered-rock.gnat.com (Postfix) with ESMTP id 9A9331C6951; Wed, 9 May 2012 15:08:01 -0400 (EDT) Received: from rock.gnat.com ([127.0.0.1]) by localhost (rock.gnat.com [127.0.0.1]) (amavisd-new, port 10024) with LMTP id 3x-12BzoZoIl; Wed, 9 May 2012 15:08:01 -0400 (EDT) Received: from joel.gnat.com (localhost.localdomain [127.0.0.1]) by rock.gnat.com (Postfix) with ESMTP id 23E3B1C6933; Wed, 9 May 2012 15:08:01 -0400 (EDT) Received: by joel.gnat.com (Postfix, from userid 1000) id 73AB8145616; Wed, 9 May 2012 12:07:53 -0700 (PDT) Date: Wed, 09 May 2012 19:08:00 -0000 From: Joel Brobecker To: Tom Tromey Cc: gdb-patches@sourceware.org Subject: Re: [RFA] choose symbol from given block's objfile first. Message-ID: <20120509190753.GA31769@adacore.com> References: <1336430581-11262-1-git-send-email-brobecker@adacore.com> <874nrqvbeh.fsf@fleche.redhat.com> <20120509190529.GI15555@adacore.com> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="tKW2IUtsqtDRztdT" Content-Disposition: inline In-Reply-To: <20120509190529.GI15555@adacore.com> User-Agent: Mutt/1.5.20 (2009-06-14) 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: 2012-05/txt/msg00305.txt.bz2 --tKW2IUtsqtDRztdT Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-length: 1056 > Attached are two patches, the first being the code change, and the > second a testcase for it. > > gdb/ChangeLog: > > * findvar.c (default_read_var_value): For LOC_UNRESOLVED symbols, > try locating the symbol in the symbol's own objfile first, before > extending the search to all objfiles. > * symtab.c (lookup_symbol_aux_objfile): New function, extracted > out of lookup_symbol_aux_symtabs. > (lookup_symbol_aux_symtabs): Add new parameter "exclude_objfile". > Replace extracted-out code by call to lookup_symbol_aux_objfile. > Do not search EXCLUDE_OBJFILE. > (lookup_static_symbol_aux): Update call to lookup_symbol_aux_symtabs. > (lookup_symbol_global): Search for matches in the block's objfile > first, before searching all other objfiles. > > gdb/testsuite/ChangeLog: > > * gdb.base/ctxobj-f.c, gdb.base/ctxobj-m.c, gdb.base/ctxobj-v.c, > gdb.base/ctxobj.exp: New files. > > Tested on x86_64-linux. No regression. ENOPATCH. -- Joel --tKW2IUtsqtDRztdT Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="0001-Search-global-symbols-from-the-expression-s-block-ob.patch" Content-length: 6963 >From 60b3578a23eef7b06e0a2e6a38191a2bcb09651e Mon Sep 17 00:00:00 2001 From: Joel Brobecker Date: Mon, 7 May 2012 14:43:28 -0700 Subject: [PATCH 1/2] Search global symbols from the expression's block objfile first. gdb/ChangeLog: * findvar.c (default_read_var_value): For LOC_UNRESOLVED symbols, try locating the symbol in the symbol's own objfile first, before extending the search to all objfiles. * symtab.c (lookup_symbol_aux_objfile): New function, extracted out of lookup_symbol_aux_symtabs. (lookup_symbol_aux_symtabs): Add new parameter "exclude_objfile". Replace extracted-out code by call to lookup_symbol_aux_objfile. Do not search EXCLUDE_OBJFILE. (lookup_static_symbol_aux): Update call to lookup_symbol_aux_symtabs. (lookup_symbol_global): Search for matches in the block's objfile first, before searching all other objfiles. --- gdb/findvar.c | 10 +++++- gdb/symtab.c | 108 ++++++++++++++++++++++++++++++++++++++++----------------- 2 files changed, 85 insertions(+), 33 deletions(-) diff --git a/gdb/findvar.c b/gdb/findvar.c index 9009e6f..ed7903c 100644 --- a/gdb/findvar.c +++ b/gdb/findvar.c @@ -562,7 +562,15 @@ default_read_var_value (struct symbol *var, struct frame_info *frame) struct minimal_symbol *msym; struct obj_section *obj_section; - msym = lookup_minimal_symbol (SYMBOL_LINKAGE_NAME (var), NULL, NULL); + /* First, try locating the associated minimal symbol within + the same objfile. This prevents us from selecting another + symbol with the same name but located in a different objfile. */ + msym = lookup_minimal_symbol (SYMBOL_LINKAGE_NAME (var), NULL, + SYMBOL_SYMTAB (var)->objfile); + /* If the lookup failed, try expanding the search to all + objfiles. */ + if (msym == NULL) + msym = lookup_minimal_symbol (SYMBOL_LINKAGE_NAME (var), NULL, NULL); if (msym == NULL) error (_("No global symbol \"%s\"."), SYMBOL_LINKAGE_NAME (var)); if (overlay_debugging) diff --git a/gdb/symtab.c b/gdb/symtab.c index d68e542..3fce349 100644 --- a/gdb/symtab.c +++ b/gdb/symtab.c @@ -95,7 +95,8 @@ struct symbol *lookup_symbol_aux_local (const char *name, static struct symbol *lookup_symbol_aux_symtabs (int block_index, const char *name, - const domain_enum domain); + const domain_enum domain, + struct objfile *exclude_objfile); static struct symbol *lookup_symbol_aux_quick (struct objfile *objfile, @@ -1361,7 +1362,7 @@ lookup_static_symbol_aux (const char *name, const domain_enum domain) struct objfile *objfile; struct symbol *sym; - sym = lookup_symbol_aux_symtabs (STATIC_BLOCK, name, domain); + sym = lookup_symbol_aux_symtabs (STATIC_BLOCK, name, domain, NULL); if (sym != NULL) return sym; @@ -1500,40 +1501,61 @@ lookup_global_symbol_from_objfile (const struct objfile *main_objfile, return NULL; } -/* Check to see if the symbol is defined in one of the symtabs. - BLOCK_INDEX should be either GLOBAL_BLOCK or STATIC_BLOCK, +/* Check to see if the symbol is defined in one of the OBJFILE's + symtabs. BLOCK_INDEX should be either GLOBAL_BLOCK or STATIC_BLOCK, depending on whether or not we want to search global symbols or static symbols. */ static struct symbol * -lookup_symbol_aux_symtabs (int block_index, const char *name, - const domain_enum domain) +lookup_symbol_aux_objfile (struct objfile *objfile, int block_index, + const char *name, const domain_enum domain) { - struct symbol *sym; - struct objfile *objfile; + struct symbol *sym = NULL; struct blockvector *bv; const struct block *block; struct symtab *s; + if (objfile->sf) + objfile->sf->qf->pre_expand_symtabs_matching (objfile, block_index, + name, domain); + + ALL_OBJFILE_SYMTABS (objfile, s) + if (s->primary) + { + bv = BLOCKVECTOR (s); + block = BLOCKVECTOR_BLOCK (bv, block_index); + sym = lookup_block_symbol (block, name, domain); + if (sym) + { + block_found = block; + return fixup_symbol_section (sym, objfile); + } + } + + return NULL; +} + +/* Same as lookup_symbol_aux_objfile, except that it searches all + objfiles except for EXCLUDE_OBJFILE. Return the first match found. + + If EXCLUDE_OBJFILE is NULL, then all objfiles are searched. */ + +static struct symbol * +lookup_symbol_aux_symtabs (int block_index, const char *name, + const domain_enum domain, + struct objfile *exclude_objfile) +{ + struct symbol *sym; + struct objfile *objfile; + ALL_OBJFILES (objfile) { - if (objfile->sf) - objfile->sf->qf->pre_expand_symtabs_matching (objfile, - block_index, - name, domain); - - ALL_OBJFILE_SYMTABS (objfile, s) - if (s->primary) - { - bv = BLOCKVECTOR (s); - block = BLOCKVECTOR_BLOCK (bv, block_index); - sym = lookup_block_symbol (block, name, domain); - if (sym) - { - block_found = block; - return fixup_symbol_section (sym, objfile); - } - } + if (objfile != exclude_objfile) + { + sym = lookup_symbol_aux_objfile (objfile, block_index, name, domain); + if (sym) + return sym; + } } return NULL; @@ -1659,24 +1681,46 @@ lookup_symbol_global (const char *name, const domain_enum domain) { struct symbol *sym = NULL; + struct objfile *block_objfile = NULL; struct objfile *objfile = NULL; /* Call library-specific lookup procedure. */ - objfile = lookup_objfile_from_block (block); - if (objfile != NULL) - sym = solib_global_lookup (objfile, name, domain); + block_objfile = lookup_objfile_from_block (block); + if (block_objfile != NULL) + sym = solib_global_lookup (block_objfile, name, domain); if (sym != NULL) return sym; - sym = lookup_symbol_aux_symtabs (GLOBAL_BLOCK, name, domain); + /* If BLOCK_OBJFILE is not NULL, then search this objfile first. + In case the global symbol is defined in multiple objfiles, + we have a better chance of finding the most relevant symbol. */ + + if (block_objfile != NULL) + { + sym = lookup_symbol_aux_objfile (block_objfile, GLOBAL_BLOCK, + name, domain); + if (sym == NULL) + sym = lookup_symbol_aux_quick (block_objfile, GLOBAL_BLOCK, + name, domain); + if (sym != NULL) + return sym; + } + + /* Symbol not found in the BLOCK_OBJFILE, so try all the other + objfiles, starting with symtabs first, and then partial symtabs. */ + + sym = lookup_symbol_aux_symtabs (GLOBAL_BLOCK, name, domain, block_objfile); if (sym != NULL) return sym; ALL_OBJFILES (objfile) { - sym = lookup_symbol_aux_quick (objfile, GLOBAL_BLOCK, name, domain); - if (sym) - return sym; + if (objfile != block_objfile) + { + sym = lookup_symbol_aux_quick (objfile, GLOBAL_BLOCK, name, domain); + if (sym) + return sym; + } } return NULL; -- 1.7.1 --tKW2IUtsqtDRztdT Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="0002-New-testcase-gdb.base-ctxobj.exp.patch" Content-length: 7939 >From c3b79f2dfd48d1052d012ce1c390fdb271bad2dc Mon Sep 17 00:00:00 2001 From: Joel Brobecker Date: Wed, 9 May 2012 10:35:31 -0700 Subject: [PATCH 2/2] New testcase: gdb.base/ctxobj.exp gdb/testsuite/ChangeLog: * gdb.base/ctxobj-f.c, gdb.base/ctxobj-m.c, gdb.base/ctxobj-v.c, gdb.base/ctxobj.exp: New files. --- gdb/testsuite/gdb.base/ctxobj-f.c | 27 +++++++++++ gdb/testsuite/gdb.base/ctxobj-m.c | 31 ++++++++++++ gdb/testsuite/gdb.base/ctxobj-v.c | 21 ++++++++ gdb/testsuite/gdb.base/ctxobj.exp | 94 +++++++++++++++++++++++++++++++++++++ 4 files changed, 173 insertions(+), 0 deletions(-) create mode 100644 gdb/testsuite/gdb.base/ctxobj-f.c create mode 100644 gdb/testsuite/gdb.base/ctxobj-m.c create mode 100644 gdb/testsuite/gdb.base/ctxobj-v.c create mode 100644 gdb/testsuite/gdb.base/ctxobj.exp diff --git a/gdb/testsuite/gdb.base/ctxobj-f.c b/gdb/testsuite/gdb.base/ctxobj-f.c new file mode 100644 index 0000000..43cc328 --- /dev/null +++ b/gdb/testsuite/gdb.base/ctxobj-f.c @@ -0,0 +1,27 @@ +/* This testcase is part of GDB, the GNU debugger. + Copyright 2012 Free Software Foundation, Inc. + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . */ + +extern int this_version_num; + +#ifndef GET_VERSION +#error GET_VERSION macro is undefined +#endif + +int +GET_VERSION (void) +{ + return this_version_num; +} diff --git a/gdb/testsuite/gdb.base/ctxobj-m.c b/gdb/testsuite/gdb.base/ctxobj-m.c new file mode 100644 index 0000000..203f838 --- /dev/null +++ b/gdb/testsuite/gdb.base/ctxobj-m.c @@ -0,0 +1,31 @@ +/* This testcase is part of GDB, the GNU debugger. + Copyright 2012 Free Software Foundation, Inc. + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . */ + +extern int get_version_1 (void); +extern int get_version_2 (void); + +int +main (void) +{ + if (get_version_1 () != 104) + return 1; + + if (get_version_2 () != 203) + return 2; + + return 0; +} + diff --git a/gdb/testsuite/gdb.base/ctxobj-v.c b/gdb/testsuite/gdb.base/ctxobj-v.c new file mode 100644 index 0000000..6d3a8d0 --- /dev/null +++ b/gdb/testsuite/gdb.base/ctxobj-v.c @@ -0,0 +1,21 @@ +/* This testcase is part of GDB, the GNU debugger. + Copyright 2012 Free Software Foundation, Inc. + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . */ + +#ifndef VERSION +#error VERSION macro is not defined. +#endif + +int this_version_num = VERSION; diff --git a/gdb/testsuite/gdb.base/ctxobj.exp b/gdb/testsuite/gdb.base/ctxobj.exp new file mode 100644 index 0000000..57ed4c1 --- /dev/null +++ b/gdb/testsuite/gdb.base/ctxobj.exp @@ -0,0 +1,94 @@ +# Copyright 2012 Free Software Foundation, Inc. + +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . */ + +set executable ctxobj-m + +# The sources used to build two shared libraries (SO). We use the exact +# same sources to build both SOs, but differentiate them through the use +# of macros defined when calling the compiler. +# +# We need two source files per SO, because we need to test the situation +# where we are trying to print the value of a global variable defined +# in that SO while the variable's associated symtab has not been created +# yet. +set libsrc [list "${srcdir}/${subdir}/ctxobj-v.c" \ + "${srcdir}/${subdir}/ctxobj-f.c"] + +set libobj1 "${objdir}/${subdir}/libctxobj1.so" +set libobj2 "${objdir}/${subdir}/libctxobj2.so" + +set libobj1_opts { debug additional_flags=-fPIC + additional_flags=-DVERSION=104 + additional_flags=-DGET_VERSION=get_version_1 } +set libobj2_opts { debug additional_flags=-fPIC + additional_flags=-DVERSION=203 + additional_flags=-DGET_VERSION=get_version_2 } + +if { [gdb_compile_shlib $libsrc $libobj1 $libobj1_opts ] != "" } { + return -1 +} +if { [gdb_compile_shlib $libsrc $libobj2 $libobj2_opts ] != "" } { + return -1 +} +if { [gdb_compile "${srcdir}/${subdir}/${executable}.c" \ + "${objdir}/${subdir}/${executable}" \ + executable \ + [list debug shlib=${libobj1} shlib=${libobj2}]] + != ""} { + return -1 +} + +clean_restart $executable + +if ![runto_main] { + untested "could not run to main" + return -1 +} + +gdb_breakpoint "get_version_1" +gdb_test "continue" \ + "Breakpoint $decimal, get_version_1 \\(\\).*" \ + "continue to get_version_1" + +# Try printing "this_version_num". There are two global variables +# with that name, but we should pick the one in the shared library +# we are currently debugging. We will know we picked the correct one +# if the value printed is 104. The first print test verifies that +# we're doing things right when the partial symtab hasn't been +# expanded. And the second print test will do the same, but after +# the partial symtab has been expanded. + +gdb_test "print this_version_num" \ + " = 104" \ + "print libctxobj1's this_version_num from partial symtab" + +gdb_test "print this_version_num" \ + " = 104" \ + "print libctxobj1's this_version_num from symtab" + +# Do the same, but from get_version_2. + +gdb_breakpoint "get_version_2" +gdb_test "continue" \ + "Breakpoint $decimal, get_version_2 \\(\\).*" \ + "continue to get_version_2" + +gdb_test "print this_version_num" \ + " = 203" \ + "print libctxobj2's this_version_num from partial symtab" + +gdb_test "print this_version_num" \ + " = 203" \ + "print libctxobj2's this_version_num from symtab" -- 1.7.1 --tKW2IUtsqtDRztdT--