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