This is the mail archive of the
gdb-patches@sources.redhat.com
mailing list for the GDB project.
Re: RFA: test that GDB tolerates bad #inclusion data
- From: Jim Blandy <jimb at redhat dot com>
- To: David Carlton <carlton at kealia dot com>
- Cc: gdb-patches at sources dot redhat dot com
- Date: 23 Sep 2003 12:03:28 -0500
- Subject: Re: RFA: test that GDB tolerates bad #inclusion data
- References: <vt2u173cwpq.fsf@zenia.home> <yf2he337a2e.fsf@hawaii.kealia.com>
David Carlton <carlton@kealia.com> writes:
> On 23 Sep 2003 11:10:09 -0500, Jim Blandy <jimb@redhat.com> 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 <jimb@redhat.com>
* 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