]>
Commit | Line | Data |
---|---|---|
ecd75fc8 | 1 | # Copyright 2013-2014 Free Software Foundation, Inc. |
681f229a NB |
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 | # Test adding and removing a symbol file dynamically: | |
17 | # 1) Run to gdb_add_symbol_file in $srcfile. | |
18 | # 2) Set a pending breakpoint at bar in $srcfile3. | |
19 | # 3) Load $shlib_name using 'add-symbol-file'. | |
20 | # 4) 'info files' must display ${lib_basename}. | |
21 | # 5) Continue to bar in $srcfile3. | |
22 | # 6) Set a breakpoint at foo in $srcfile3. | |
23 | # 7) Continue to foo in $srcfile3. | |
24 | # 8) Set a breakpoint at gdb_remove_symbol_file. | |
25 | # 9) Continue to gdb_remove_symbol_file in $srcfile. | |
26 | # 10) Remove $shlib_name using 'remove-symbol-file'. | |
27 | # 11) 'info files' must not display ${lib_basename}, anymore. | |
28 | # 12) Check that the breakpoints at foo and bar are pending. | |
29 | # 13) Check that the execution can continue without error. | |
30 | ||
31 | if {![is_elf_target]} { | |
32 | return 0 | |
33 | } | |
34 | ||
35 | if [skip_shlib_tests] { | |
36 | return 0 | |
37 | } | |
38 | ||
39 | if [is_remote target] { | |
40 | return 0 | |
41 | } | |
42 | ||
43 | set target_size TARGET_UNKNOWN | |
44 | if {[is_lp64_target]} { | |
45 | set target_size TARGET_LP64 | |
46 | } elseif {[is_ilp32_target]} { | |
47 | set target_size TARGET_ILP32 | |
48 | } else { | |
49 | return 0 | |
50 | } | |
51 | ||
52 | set main_basename sym-file-main | |
53 | set loader_basename sym-file-loader | |
54 | set lib_basename sym-file-lib | |
55 | ||
56 | standard_testfile $main_basename.c $loader_basename.c $lib_basename.c | |
57 | ||
58 | set libsrc "${srcdir}/${subdir}/${srcfile3}" | |
59 | set shlib_name [standard_output_file ${lib_basename}.so] | |
60 | set exec_opts [list debug "additional_flags= -I$srcdir/../../include/ -D$target_size\ | |
61 | -DSHLIB_NAME\\=\"$shlib_name\""] | |
62 | ||
63 | if [get_compiler_info] { | |
64 | return -1 | |
65 | } | |
66 | ||
67 | if {[gdb_compile_shlib $libsrc $shlib_name {debug}] != ""} { | |
68 | untested ${testfile} | |
69 | return | |
70 | } | |
71 | ||
72 | if {[prepare_for_testing $testfile $binfile "$srcfile $srcfile2" $exec_opts]} { | |
73 | return | |
74 | } | |
75 | ||
76 | # 1) Run to GDB_ADD_SYMBOl_FILE in $srcfile for adding | |
77 | # $shlib_name. | |
78 | set result [runto gdb_add_symbol_file] | |
79 | if {!$result} then { | |
80 | return | |
81 | } | |
82 | ||
83 | # 2) Set a pending breakpoint at bar in $srcfile3. | |
84 | set result [gdb_breakpoint bar allow-pending] | |
85 | if {!$result} then { | |
86 | return | |
87 | } | |
88 | ||
89 | # 3) Add $shlib_name using 'add-symbol-file'. | |
90 | set result [gdb_test "add-symbol-file ${shlib_name} addr" \ | |
91 | "Reading symbols from .*${lib_basename}\\.so\\.\\.\\.done\\." \ | |
92 | "add-symbol-file .*${lib_basename}\\.so addr" \ | |
93 | "add symbol table from file \".*${lib_basename}\\.so\"\ | |
94 | at.*\\(y or n\\) " \ | |
95 | "y"] | |
96 | if {$result != 0} then { | |
97 | return | |
98 | } | |
99 | ||
100 | # 4) 'info files' must display $srcfile3. | |
101 | gdb_test "info files" \ | |
102 | "^(?=(.*${lib_basename})).*" \ | |
103 | "info files must display ${lib_basename}" | |
104 | ||
105 | # 5) Continue to bar in $srcfile3 to ensure that the breakpoint | |
106 | # was bound correctly after adding $shilb_name. | |
107 | set lnum_bar [gdb_get_line_number "break at bar" $srcfile3] | |
108 | gdb_continue_to_breakpoint bar ".*${lib_basename}\\.c:$lnum_bar.*" | |
109 | ||
110 | # 6) Set a breakpoint at foo in $srcfile3. | |
111 | set result [gdb_breakpoint foo] | |
112 | if {!$result} then { | |
113 | return | |
114 | } | |
115 | ||
116 | # 7) Continue to foo in $srcfile3 to ensure that the breakpoint | |
117 | # was bound correctly. | |
118 | set lnum_foo [gdb_get_line_number "break at foo" $srcfile3] | |
119 | gdb_continue_to_breakpoint foo ".*${lib_basename}\\.c:$lnum_foo.*" | |
120 | ||
121 | # 8) Set a breakpoint at gdb_remove_symbol_file in $srcfile for | |
122 | # removing $shlib_name. | |
123 | set result [gdb_breakpoint gdb_remove_symbol_file] | |
124 | if {!$result} then { | |
125 | return | |
126 | } | |
127 | ||
128 | # 9) Continue to gdb_remove_symbol_file in $srcfile. | |
129 | gdb_continue_to_breakpoint gdb_remove_symbol_file | |
130 | ||
131 | # 10) Remove $shlib_name using 'remove-symbol-file'. | |
132 | set result [gdb_test "remove-symbol-file -a addr" \ | |
133 | ""\ | |
134 | "remove-symbol-file -a addr" \ | |
135 | "Remove symbol table from file \".*${lib_basename}\\.so\"\\?\ | |
136 | .*\\(y or n\\) " \ | |
137 | "y"] | |
138 | if {$result != 0} then { | |
139 | return | |
140 | } | |
141 | ||
142 | # 11) 'info files' must not display ${lib_basename}, anymore. | |
143 | gdb_test "info files" \ | |
144 | "^(?!(.*${lib_basename})).*" \ | |
145 | "info files must not display ${lib_basename}" | |
146 | ||
147 | # 12) Check that the breakpoints at foo and bar are pending after removing | |
148 | # $shlib_name. | |
149 | gdb_test "info breakpoints 2" \ | |
150 | ".*PENDING.*" \ | |
151 | "check if Breakpoint 2 is pending." | |
152 | ||
153 | gdb_test "info breakpoints 3" \ | |
154 | ".*PENDING.*" \ | |
155 | "check if Breakpoint 3 is pending." | |
156 | ||
157 | # 13) Check that the execution can continue without error. | |
158 | gdb_continue_to_end |