This is the mail archive of the
gdb-patches@sources.redhat.com
mailing list for the GDB project.
Re: [rfa+testsuite] don't search off the end of partial symbol tables
- From: Elena Zannoni <ezannoni at redhat dot com>
- To: David Carlton <carlton at math dot stanford dot edu>
- Cc: gdb-patches at sources dot redhat dot com, Elena Zannoni <ezannoni at redhat dot com>, Jim Blandy <jimb at redhat dot com>, Fernando Nasser <fnasser at redhat dot com>
- Date: Mon, 16 Dec 2002 20:35:20 -0500
- Subject: Re: [rfa+testsuite] don't search off the end of partial symbol tables
- References: <ro1wum9o2u5.fsf@jackfruit.Stanford.EDU>
David Carlton writes:
> It turns out that the binary search in lookup_partial_symbol isn't too
> careful about array boundaries: it looks for the first partial symbol
> with the appropriate name (if there is one), and then looks, starting
> at that position, for the partial symbol that is in the correct
> namespace. It stops when it finds a match or when it finds a symbol
> with the wrong name.
>
> So if you construct a partial symbol table whose last element has the
> name you're looking for but is in the wrong namespace, then GDB will
> read off the end of the psymtab.
>
Ahh. Good catch.
> The robustness of GDB with respect to partial symbol errors is a
> constant sources of joy and delight. Or something. Jim: you'll be
> happy to learn that I found this bug while running gdb.c++/psmang.exp
> on a branch.
>
> Here's a patch, and a test to catch it. This patch is completely
> orthogonal to (and much less important than) other patches of mine
> that are awaiting review.
>
Yes, sorry, but also easier to review... :-)
OK.
Wait for Fernando's word on the tests.
Elena
> David Carlton
> carlton@math.stanford.edu
>
> 2002-12-16 David Carlton <carlton@math.stanford.edu>
>
> * symtab.c (lookup_partial_symbol): Don't search past the end of
> the partial symbols.
>
> 2002-12-16 David Carlton <carlton@math.stanford.edu>
>
> * gdb.base/psymtab.exp: New file.
> * gdb.base/psymtab1.c: Ditto.
> * gdb.base/psymtab2.c: Ditto.
>
> Index: symtab.c
> ===================================================================
> RCS file: /cvs/src/src/gdb/symtab.c,v
> retrieving revision 1.81
> diff -u -p -r1.81 symtab.c
> --- symtab.c 5 Dec 2002 21:26:57 -0000 1.81
> +++ symtab.c 17 Dec 2002 00:33:20 -0000
> @@ -1300,7 +1300,7 @@ lookup_partial_symbol (struct partial_sy
> {
> struct partial_symbol *temp;
> struct partial_symbol **start, **psym;
> - struct partial_symbol **top, **bottom, **center;
> + struct partial_symbol **top, **real_top, **bottom, **center;
> int length = (global ? pst->n_global_syms : pst->n_static_syms);
> int do_linear_search = 1;
>
> @@ -1323,6 +1323,7 @@ lookup_partial_symbol (struct partial_sy
>
> bottom = start;
> top = start + length - 1;
> + real_top = top;
> while (top > bottom)
> {
> center = bottom + (top - bottom) / 2;
> @@ -1348,7 +1349,7 @@ lookup_partial_symbol (struct partial_sy
> /* djb - 2000-06-03 - Use SYMBOL_MATCHES_NAME, not a strcmp, so
> we don't have to force a linear search on C++. Probably holds true
> for JAVA as well, no way to check.*/
> - while (SYMBOL_MATCHES_NAME (*top,name))
> + while (top <= real_top && SYMBOL_MATCHES_NAME (*top,name))
> {
> if (SYMBOL_NAMESPACE (*top) == namespace)
> {
> Index: gdb.base/psymtab.exp
> --- /dev/null Thu Apr 11 07:25:15 2002
> +++ /extra/gdb/working/src/gdb/testsuite/gdb.base/psymtab.exp Mon Dec 16 16:44:17 2002
> @@ -0,0 +1,72 @@
> +# Copyright 2002 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 2 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, write to the Free Software
> +# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
> +
> +# Please email any bugs, comments, and/or additions to this file to:
> +# bug-gdb@prep.ai.mit.edu
> +
> +# This file is part of the gdb testsuite
> +
> +# This is intended to be a repository for tests that partial symbols
> +# are working properly. If multiple tests are added, make sure that
> +# you exit and restart GDB between tests.
> +
> +if $tracelevel then {
> + strace $tracelevel
> +}
> +
> +#
> +# test running programs
> +#
> +
> +set prms_id 0
> +set bug_id 0
> +
> +if { [skip_cplus_tests] } { continue }
> +
> +set testfile "psymtab"
> +set binfile ${objdir}/${subdir}/${testfile}
> +
> +if { [gdb_compile "${srcdir}/${subdir}/${testfile}1.c" "${testfile}1.o" object {debug}] != "" } {
> + gdb_suppress_entire_file "Testcase compile failed, so all tests in this file will automatically fail."
> +}
> +
> +if { [gdb_compile "${srcdir}/${subdir}/${testfile}2.c" "${testfile}2.o" object {debug}] != "" } {
> + gdb_suppress_entire_file "Testcase compile failed, so all tests in this file will automatically fail."
> +}
> +
> +if { [gdb_compile "${testfile}1.o ${testfile}2.o" ${binfile} executable {debug}] != "" } {
> + gdb_suppress_entire_file "Testcase compile failed, so all tests in this file will automatically fail."
> +}
> +
> +# Create and source the file that provides information about the compiler
> +# used to compile the test case.
> +if [get_compiler_info ${binfile}] {
> + return -1;
> +}
> +
> +gdb_exit
> +gdb_start
> +gdb_reinitialize_dir $srcdir/$subdir
> +gdb_load ${binfile}
> +
> +# This test is looking for a bug that manifested itself when GDB was
> +# looking for a partial symbol such that there wasn't such a partial
> +# symbol in the psymtab, but such that the last psym in the psymtab
> +# had the right name but the wrong namespace. Here, searching for
> +# zzz::dummy currently causes a search for 'zzz' in STRUCT_NAMESPACE
> +# without a preceding search for 'zzz' in VAR_NAMESPACE.
> +
> +gdb_test "break zzz::dummy" "Can't find member of namespace, class, struct, or union named \"zzz::dummy\"\r\n.*" "Don't search past end of psymtab."
> Index: gdb.base/psymtab1.c
> --- /dev/null Thu Apr 11 07:25:15 2002
> +++ /extra/gdb/working/src/gdb/testsuite/gdb.base/psymtab1.c Mon Dec 16 16:29:37 2002
> @@ -0,0 +1,4 @@
> +int main ()
> +{
> + return 0;
> +}
> Index: gdb.base/psymtab2.c
> --- /dev/null Thu Apr 11 07:25:15 2002
> +++ /extra/gdb/working/src/gdb/testsuite/gdb.base/psymtab2.c Mon Dec 16 16:29:49 2002
> @@ -0,0 +1,3 @@
> +extern int zzz;
> +
> +int zzz = 123;