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