1# Test macro handling of #included files. 2# Copyright 2003, 2007 Free Software Foundation, Inc. 3 4# This program is free software; you can redistribute it and/or modify 5# it under the terms of the GNU General Public License as published by 6# the Free Software Foundation; either version 3 of the License, or 7# (at your option) any later version. 8# 9# This program is distributed in the hope that it will be useful, 10# but WITHOUT ANY WARRANTY; without even the implied warranty of 11# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12# GNU General Public License for more details. 13# 14# You should have received a copy of the GNU General Public License 15# along with this program. If not, see <http://www.gnu.org/licenses/>. 16 17# Please email any bugs, comments, and/or additions to this file to: 18# bug-gdb@prep.ai.mit.edu 19 20# The test program lineinc.c contains a mix of #line directives and 21# #include directives that will cause the compiler to attribute more 22# than one #inclusion to the same source line. You can get similar 23# effects using things like GCC's '-imacros' flag. 24# 25# Compiling lineinc.c with Dwarf 2 macro information will produce 26# something like this: 27# 28# $ gcc -g3 lineinc.c -o lineinc 29# $ readelf -wml lineinc 30# ... 31# The File Name Table: 32# Entry Dir Time Size Name 33# 1 0 0 0 lineinc.c 34# 2 0 0 0 lineinc1.h 35# 3 0 0 0 lineinc2.h 36# 4 0 0 0 lineinc3.h 37# ... 38# Contents of the .debug_macinfo section: 39# 40# DW_MACINFO_start_file - lineno: 0 filenum: 1 41# DW_MACINFO_define - lineno : 1 macro : __VERSION__ "3.2 20020903 (Red Hat Linux 8.0 3.2-7)" 42# DW_MACINFO_define - lineno : 2 macro : __USER_LABEL_PREFIX__ 43# ... 44# DW_MACINFO_define - lineno : 1 macro : __i386__ 1 45# DW_MACINFO_define - lineno : 1 macro : __tune_i386__ 1 46# DW_MACINFO_start_file - lineno: 10 filenum: 2 47# DW_MACINFO_define - lineno : 1 macro : FOO 1 48# DW_MACINFO_end_file 49# DW_MACINFO_start_file - lineno: 10 filenum: 3 50# DW_MACINFO_undef - lineno : 1 macro : FOO 51# DW_MACINFO_define - lineno : 2 macro : FOO 2 52# DW_MACINFO_end_file 53# DW_MACINFO_start_file - lineno: 11 filenum: 4 54# DW_MACINFO_undef - lineno : 1 macro : FOO 55# DW_MACINFO_define - lineno : 2 macro : FOO 3 56# DW_MACINFO_end_file 57# DW_MACINFO_end_file 58# $ 59# 60# Note how the inclusions of lineinc1.h and lineinc2.h are both 61# attributed to line 10 of lineinc.c, and the #inclusion of lineinc3.h 62# is attributed to line 11. This is all correct, given the #line 63# directives in lineinc.c. 64# 65# Dwarf 2 macro information doesn't contain enough information to 66# allow GDB to figure out what's really going on here --- it makes no 67# mention of the #line directives --- so we just try to cope as best 68# we can. If the macro table were to attribute more than one 69# #inclusion to the same source line, then GDB wouldn't be able to 70# tell which #included file's #definitions and #undefinitions come 71# first, so it can't tell which #definitions are in scope following 72# all the #inclusions. To cope with this, GDB puts all the files 73# #included by a given source file in a list sorted by the line at 74# which they were #included; this gives GDB the chance to detect 75# multiple #inclusions at the same line, complain, and assign 76# distinct, albiet incorrect, line numbers to each #inclusion. 77# 78# However, at one point GDB was sorting the list in reverse order, 79# while the code to assign new, distinct line numbers assumed it was 80# sorted in ascending order; GDB would get an internal error trying to 81# read the above debugging info. 82 83if $tracelevel then { 84 strace $tracelevel 85} 86 87set prms_id 0 88set bug_id 0 89 90set testfile "lineinc" 91set binfile ${objdir}/${subdir}/${testfile} 92 93 94if {[gdb_compile "${srcdir}/${subdir}/${testfile}.c" ${binfile} executable {debug}] != ""} { 95 untested lineinc.exp 96 return -1 97} 98 99gdb_exit 100gdb_start 101gdb_reinitialize_dir $srcdir/$subdir 102gdb_load ${binfile} 103 104# Any command that causes GDB to read the debugging info for the 105# lineinc.c compilation unit will do here. 106set test_name "tolerate macro info with multiple #inclusions per line" 107gdb_test_multiple "break main" $test_name { 108 -re "Breakpoint 1 at 0x.*: file .*lineinc.c.*\\.\r\n${gdb_prompt}" { 109 pass $test_name 110 } 111 -re ".*internal-error:.*.y or n. " { 112 fail $test_name 113 send_gdb "y\n" 114 gdb_expect { 115 -re ".*.y or n. " { 116 send_gdb "n\n" 117 exp_continue 118 } 119 -re "$gdb_prompt" { 120 } 121 timeout { 122 fail "$test_name (timeout)" 123 } 124 } 125 } 126} 127