Commit | Line | Data |
---|---|---|
618f726f | 1 | # Copyright 2002-2016 Free Software Foundation, Inc. |
a04ba985 JG |
2 | |
3 | # This program is free software; you can redistribute it and/or modify | |
4 | # it under the terms of the GNU General Public License as published by | |
5 | # the Free Software Foundation; either version 3 of the License, or | |
6 | # (at your option) any later version. | |
7 | # | |
8 | # This program is distributed in the hope that it will be useful, | |
9 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | |
10 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
11 | # GNU General Public License for more details. | |
12 | # | |
13 | # You should have received a copy of the GNU General Public License | |
14 | # along with this program. If not, see <http://www.gnu.org/licenses/>. */ | |
15 | ||
16 | # code_elim.exp -- tests that GDB can handle executables where some data/code | |
17 | # has been eliminated by the linker. | |
18 | ||
a04ba985 JG |
19 | set testfile1 code_elim1 |
20 | set testfile2 code_elim2 | |
21 | set srcfile1 ${testfile1}.c | |
22 | set srcfile2 ${testfile2}.c | |
f76495c8 TT |
23 | set binfile1 [standard_output_file ${testfile1}] |
24 | set binfile2 [standard_output_file ${testfile2}] | |
a04ba985 JG |
25 | set opts [list debug] |
26 | lappend opts "additional_flags=-ffunction-sections" | |
27 | lappend opts "additional_flags=-fdata-sections" | |
28 | lappend opts "additional_flags=-Wl,-gc-sections" | |
29 | lappend opts "additional_flags=-Wl,-e,main" | |
30 | ||
31 | remote_exec build "rm -f ${binfile1}" | |
32 | remote_exec build "rm -f ${binfile2}" | |
33 | ||
34 | if { [gdb_compile "${srcdir}/${subdir}/${srcfile1}" "${binfile1}" executable $opts] != "" } { | |
5b362f04 | 35 | untested "failed to compile" |
a04ba985 JG |
36 | return -1 |
37 | } | |
38 | ||
39 | if { [gdb_compile "${srcdir}/${subdir}/${srcfile2}" "${binfile2}" executable $opts] != "" } { | |
5b362f04 | 40 | untested "failed to compile" |
a04ba985 JG |
41 | return -1 |
42 | } | |
43 | ||
a04ba985 JG |
44 | proc not_null_var_address { var } { |
45 | ||
46 | # Same as get_var_address, expect that it reports a failure if a null | |
47 | # address is returned by gdb. | |
48 | ||
49 | set address [get_var_address $var] | |
50 | regexp "0x\[0-9a-fA-F\]+" $address address | |
51 | if { "$address" == "0x0" } { | |
52 | fail "$var has null address" | |
53 | } | |
54 | } | |
55 | ||
56 | proc test_eliminated_var { var } { | |
57 | global gdb_prompt hex | |
58 | ||
59 | # Match output 'No symbol "${var}" in current context' | |
60 | ||
61 | gdb_test_multiple "print &${var}" "test eliminated var ${var}" { | |
62 | -re "No symbol \"${var}\" in current context\\.\[\r\n\]+${gdb_prompt} $" { | |
63 | pass "test eliminated var ${var}" | |
64 | } | |
65 | -re "\\\$\[0-9\]+ = \\(.*\\) (0|$hex)( <${var}>)?\[\r\n\]+${gdb_prompt} $" { | |
66 | fail "test eliminated var ${var}" | |
67 | } | |
68 | } | |
69 | } | |
70 | ||
71 | # Check that the code and data eliminated in binfile1 are not included | |
72 | # into partial symtab... and that non-eliminated symbols are still there. | |
73 | ||
74 | gdb_exit | |
75 | gdb_start | |
76 | ||
d0d86158 | 77 | gdb_test "symbol-file ${binfile1}" \ |
a04ba985 | 78 | "Reading symbols from .*${testfile1}\\.\\.\\.done\\.(|\r\nUsing host libthread_db library .*libthread_db.so.*\\.)" \ |
d0d86158 | 79 | "symbol-file ${testfile1}" |
a04ba985 | 80 | |
d0d86158 JK |
81 | with_test_prefix "single psymtabs" { |
82 | test_eliminated_var my_global_symbol | |
83 | test_eliminated_var my_static_symbol | |
84 | test_eliminated_var my_global_func | |
85 | not_null_var_address main | |
86 | } | |
a04ba985 JG |
87 | |
88 | # Same thing for symtabs | |
89 | ||
90 | gdb_exit | |
91 | global GDBFLAGS | |
92 | set saved_gdbflags $GDBFLAGS | |
93 | set GDBFLAGS "$GDBFLAGS --readnow $binfile1" | |
94 | gdb_start | |
95 | set GDBFLAGS $saved_gdbflags | |
96 | ||
d0d86158 JK |
97 | with_test_prefix "single symtabs" { |
98 | test_eliminated_var my_global_symbol | |
99 | test_eliminated_var my_static_symbol | |
100 | test_eliminated_var my_global_func | |
101 | not_null_var_address main | |
102 | } | |
a04ba985 JG |
103 | |
104 | # binfile2 contains the symbols that have been eliminated in binfile1. Check | |
105 | # the eliminated symbols does not hide these valid ones. | |
106 | ||
107 | gdb_exit | |
108 | gdb_start | |
109 | ||
d0d86158 | 110 | with_test_prefix "order1" { |
952cf74c JK |
111 | gdb_test "add-symbol-file ${binfile1} 0x100000 -s .bss 0x120000" \ |
112 | "Reading symbols from .*${testfile1}\\.\\.\\.done\\." \ | |
113 | "add-symbol-file ${testfile1} 0x100000" \ | |
114 | "add symbol table from file \".*${testfile1}\" at.*\\(y or n\\) " \ | |
115 | "y" | |
116 | ||
117 | gdb_test "add-symbol-file ${binfile2} 0x200000 -s .data 0x210000 -s .bss 0x220000" \ | |
118 | "Reading symbols from .*${testfile2}\\.\\.\\.done\\." \ | |
119 | "add-symbol-file ${testfile2} 0x200000" \ | |
120 | "add symbol table from file \".*${testfile2}\" at.*\\(y or n\\) " \ | |
121 | "y" | |
122 | ||
d0d86158 JK |
123 | not_null_var_address my_global_symbol |
124 | not_null_var_address my_static_symbol | |
125 | not_null_var_address my_global_func | |
126 | not_null_var_address main | |
127 | } | |
a04ba985 JG |
128 | |
129 | # Same thing, but loading binfile2 before binfile1. | |
130 | ||
131 | gdb_exit | |
132 | gdb_start | |
133 | ||
d0d86158 | 134 | with_test_prefix "order2" { |
952cf74c JK |
135 | gdb_test "add-symbol-file ${binfile2} 0x200000 -s .data 0x210000 -s .bss 0x220000" \ |
136 | "Reading symbols from .*${testfile2}\\.\\.\\.done\\." \ | |
137 | "add-symbol-file ${testfile2} 0x200000" \ | |
138 | "add symbol table from file \".*${testfile2}\" at.*\\(y or n\\) " \ | |
139 | "y" | |
140 | ||
141 | gdb_test "add-symbol-file ${binfile1} 0x100000 -s .bss 0x120000" \ | |
142 | "Reading symbols from .*${testfile1}\\.\\.\\.done\\." \ | |
143 | "add-symbol-file ${testfile1} 0x100000" \ | |
144 | "add symbol table from file \".*${testfile1}\" at.*\\(y or n\\) " \ | |
145 | "y" | |
146 | ||
d0d86158 JK |
147 | not_null_var_address my_global_symbol |
148 | not_null_var_address my_static_symbol | |
149 | not_null_var_address my_global_func | |
150 | not_null_var_address main | |
151 | } |