From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 29303 invoked by alias); 23 Sep 2003 17:06:51 -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 29288 invoked from network); 23 Sep 2003 17:06:49 -0000 Received: from unknown (HELO zenia.home) (12.223.225.216) by sources.redhat.com with SMTP; 23 Sep 2003 17:06:49 -0000 Received: by zenia.home (Postfix, from userid 5433) id 3E27C20762; Tue, 23 Sep 2003 12:03:29 -0500 (EST) To: David Carlton Cc: gdb-patches@sources.redhat.com Subject: Re: RFA: test that GDB tolerates bad #inclusion data References: From: Jim Blandy Date: Tue, 23 Sep 2003 17:06:00 -0000 In-Reply-To: Message-ID: User-Agent: Gnus/5.09 (Gnus v5.9.0) Emacs/21.3 MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-SW-Source: 2003-09/txt/msg00495.txt.bz2 David Carlton writes: > On 23 Sep 2003 11:10:09 -0500, Jim Blandy said: > > > + # Note how this attributes the inclusions of badinc1.h and badinc2.h > > + # (requested via the -imacros command-line switches) are attributed to > > + # lines 1 and 2 of badinc.c, > > I think the "this attributes" at the beginning should be deleted. *moip* 2003-09-23 Jim Blandy * gdb.base/badinc.exp, gdb.base/badinc1.h, gdb.base/badinc2.h, gdb.base/badinc3.h, gdb.base/badinc.c: New tests. Index: gdb/testsuite/gdb.base/badinc.exp =================================================================== RCS file: gdb/testsuite/gdb.base/badinc.exp diff -N gdb/testsuite/gdb.base/badinc.exp *** gdb/testsuite/gdb.base/badinc.exp 1 Jan 1970 00:00:00 -0000 --- gdb/testsuite/gdb.base/badinc.exp 23 Sep 2003 17:04:42 -0000 *************** *** 0 **** --- 1,154 ---- + # Test macro handling of #included files. + # Copyright 2003 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 + + # Some versions of GCC produce Dwarf 2 macro information that lists + # all files #included via the '-imacros' flag as appearing at line 1 + # of the main source file, like this: + # + # $ gcc -g3 -imacros badinc1.h -imacros badinc2.h badinc.c -o badinc + # $ readelf -wml badinc + # ... + # The File Name Table: + # Entry Dir Time Size Name + # 1 0 0 0 badinc.c + # 2 0 0 0 badinc1.h + # 3 0 0 0 badinc2.h + # 4 0 0 0 badinc3.h + # ... + # Contents of the .debug_macinfo section: + # + # DW_MACINFO_start_file - lineno: 0 filenum: 1 + # DW_MACINFO_define - lineno : 1 macro : __VERSION__ "3.2 20020903 (Red Hat Linux 8.0 3.2-7)" + # DW_MACINFO_define - lineno : 2 macro : __USER_LABEL_PREFIX__ + # ... + # DW_MACINFO_define - lineno : 1 macro : __i386__ 1 + # DW_MACINFO_define - lineno : 1 macro : __tune_i386__ 1 + # DW_MACINFO_start_file - lineno: 1 filenum: 2 + # DW_MACINFO_define - lineno : 1 macro : FOO 1 + # DW_MACINFO_end_file + # DW_MACINFO_start_file - lineno: 2 filenum: 3 + # DW_MACINFO_undef - lineno : 1 macro : FOO + # DW_MACINFO_define - lineno : 2 macro : FOO 2 + # DW_MACINFO_end_file + # DW_MACINFO_start_file - lineno: 1 filenum: 4 + # DW_MACINFO_undef - lineno : 1 macro : FOO + # DW_MACINFO_define - lineno : 2 macro : FOO 3 + # DW_MACINFO_end_file + # DW_MACINFO_end_file + # $ + # + # Note how the inclusions of badinc1.h and badinc2.h (requested via + # the -imacros command-line switches) are attributed to lines 1 and 2 + # of badinc.c, and the #inclusion of badinc3.h (requested via a real + # #include directive) is attributed to line 1 of badinc.c. + # + # This script tests GDB's ability to work around this kind of bogus + # information. In particular, versions of GDB before Sep 2003 would + # get an internal error when trying to read the above debugging info. + # + # If more than one #inclusion is alleged to have taken place at the + # same source line, then GDB can't tell which file's definitions and + # undefinitions come first, so it can't tell which definitions are in + # scope after the #inclusions. To work around this, GDB puts all the + # files #included from a given source file in a list sorted by the + # line at which they were #included; this gives it the chance to + # detect multiple #inclusions at the same line, complain, and assign + # distinct, albiet incorrect, line numbers to each #inclusion. + # + # The bug was that GDB didn't put files in the sorted list correctly; + # the condition deciding how long to walk the list was reversed. This + # is why we have to have three #include files in the test: if there + # are only two headers, then when the second #inclusion at line 1 + # (badinc3.h) is added to the list, the list has only one other + # element, and the traversal stops in the right place anyway. With + # three header files, badinc2.h, #included at line two, ends up before + # badinc1.h, #included at line one, so we don't notice the duplication + # when we insert badinc3.h at line one too. + + if $tracelevel then { + strace $tracelevel + } + + set prms_id 0 + set bug_id 0 + + set testfile "badinc" + set binfile ${objdir}/${subdir}/${testfile} + + + # Create and source the file that provides information about the compiler + # used to compile the test case. + if [get_compiler_info ${binfile}] { + return -1; + } + + + if {$gcc_compiled} { + # Some versions of GCC (like 3.2) can be persuaded to produce + # appropriately bogus info by #including files using the -imacros + # flag. + set header1 "${srcdir}/${subdir}/badinc1.h" + set header2 "${srcdir}/${subdir}/badinc2.h" + set additional_flags \ + "additional_flags=-imacros $header1 -imacros $header2" + if {[gdb_compile "${srcdir}/${subdir}/${testfile}.c" ${binfile} \ + executable [list debug $additional_flags]] != ""} { + gdb_suppress_entire_file "Testcase compile failed, so all tests in this file will automatically fail." + } + } else { + # We don't know how to run this test on this compiler, so don't bother. + return 0 + } + + gdb_exit + gdb_start + gdb_reinitialize_dir $srcdir/$subdir + gdb_load ${binfile} + + # Any command that causes GDB to read the debugging info for the + # badinc.c compilation unit will do here. + set test_name "tolerate macro info with bad #inclusion line numbers" + send_gdb "break main\n" + gdb_expect { + -re "Breakpoint 1 at 0x.*: file .*badinc.c.*\\.\r\n${gdb_prompt}" { + pass $test_name + } + -re ".*internal-error:.*.y or n. " { + fail $test_name + send_gdb "y\n" + gdb_expect { + -re ".*.y or n. " { + send_gdb "n\n" + exp_continue + } + -re "$gdb_prompt" { + } + timeout { + fail "$test_name (timeout)" + } + } + } + -re ".*$gdb_prompt" { + fail "$test_name (unexpected response)" + } + timeout { + fail "$test_name (timeout)" + } + } Index: gdb/testsuite/gdb.base/badinc.c =================================================================== RCS file: gdb/testsuite/gdb.base/badinc.c diff -N gdb/testsuite/gdb.base/badinc.c *** gdb/testsuite/gdb.base/badinc.c 1 Jan 1970 00:00:00 -0000 --- gdb/testsuite/gdb.base/badinc.c 23 Sep 2003 17:04:42 -0000 *************** *** 0 **** --- 1,6 ---- + #include "badinc3.h" + + int + main (int argc, char **argv) + { + } Index: gdb/testsuite/gdb.base/badinc1.h =================================================================== RCS file: gdb/testsuite/gdb.base/badinc1.h diff -N gdb/testsuite/gdb.base/badinc1.h *** gdb/testsuite/gdb.base/badinc1.h 1 Jan 1970 00:00:00 -0000 --- gdb/testsuite/gdb.base/badinc1.h 23 Sep 2003 17:04:42 -0000 *************** *** 0 **** --- 1 ---- + #define FOO 1 Index: gdb/testsuite/gdb.base/badinc2.h =================================================================== RCS file: gdb/testsuite/gdb.base/badinc2.h diff -N gdb/testsuite/gdb.base/badinc2.h *** gdb/testsuite/gdb.base/badinc2.h 1 Jan 1970 00:00:00 -0000 --- gdb/testsuite/gdb.base/badinc2.h 23 Sep 2003 17:04:42 -0000 *************** *** 0 **** --- 1,2 ---- + #undef FOO + #define FOO 2 Index: gdb/testsuite/gdb.base/badinc3.h =================================================================== RCS file: gdb/testsuite/gdb.base/badinc3.h diff -N gdb/testsuite/gdb.base/badinc3.h *** gdb/testsuite/gdb.base/badinc3.h 1 Jan 1970 00:00:00 -0000 --- gdb/testsuite/gdb.base/badinc3.h 23 Sep 2003 17:04:42 -0000 *************** *** 0 **** --- 1,2 ---- + #undef FOO + #define FOO 3