Fix: Null pointer dereference in ldlex.l
[binutils-gdb.git] / gdb / testsuite / gdb.base / msym-bp-shl.exp
blob3cc2a9f84447f5908d705532b17ea20d9c8d30bb
1 # Copyright 2020-2023 Free Software Foundation, Inc.
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.
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.
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/>.
16 # Test that when setting a breakpoint at "foo", GDB creates a location
17 # for an unresolved <foo@plt> PLT in the main binary, even when a
18 # static function named "foo" exists in the shared library. Tests
19 # both with and without debug info.
21 require allow_shlib_tests
23 standard_testfile msym-bp-shl-main.c msym-bp-shl-main-2.c msym-bp-shl-lib.c
24 set srcfile ${srcdir}/${subdir}/${srcfile}
25 set srcfile2 ${srcdir}/${subdir}/${srcfile2}
26 set libsrc ${srcdir}/${subdir}/${srcfile3}
28 # Run "info breakpoints", and check that we find the two locations,
29 # LOC_A and LOC_B, in either order.
30 proc test_info_break_2 {loc_a loc_b} {
31 set re1 ".*\.1.*${loc_a}\r\n.*\.2.*${loc_b}"
32 set re2 ".*\.1.*${loc_b}\r\n.*\.2.*${loc_a}"
33 gdb_test "info breakpoint" "$re1|$re2"
36 proc test {debug} {
37 global testfile binfile srcfile srcfile2 libsrc
38 global decimal
40 if {$debug} {
41 set options "debug"
42 } else {
43 set options ""
46 set bin ${binfile}-$debug
47 set lib [standard_output_file msym-bp-shl-lib-$debug.sl]
49 set exec_opts [list $options shlib=${lib}]
51 if { [gdb_compile_shlib $libsrc $lib $options] != ""
52 || [gdb_compile [list $srcfile $srcfile2] $bin \
53 executable $exec_opts] != ""} {
54 untested "failed to compile"
55 return
58 clean_restart $bin
59 gdb_load_shlib $lib
61 # Should find two locations: the static foo in the
62 # msym-bp-shl-main-2 file, and <foo@plt>, both in the main binary.
63 with_test_prefix "before run" {
64 gdb_test "break foo" "\\(2 locations\\)"
66 if {$debug} {
67 test_info_break_2 \
68 "<foo@plt.*>" \
69 "in foo at .*msym-bp-shl-main-2.c:$decimal"
70 } else {
71 test_info_break_2 \
72 "<foo@plt.*>" \
73 "<foo(\\+$decimal)?>"
77 if ![runto_main] {
78 return
81 delete_breakpoints
83 # Should still find two locations, but the <foo@plt> PLT location
84 # should not be present anymore. I.e., we should find the static
85 # foo in the msym-bp-shl-main-2 file, and the extern foo in the
86 # shared library.
87 with_test_prefix "at main" {
88 gdb_test "break foo" "\\(2 locations\\)"
90 if {$debug} {
91 test_info_break_2 \
92 "in foo at .*msym-bp-shl-main-2.c:$decimal" \
93 "in foo at .*msym-bp-shl-lib.c:$decimal"
94 } else {
95 test_info_break_2 \
96 "<foo(\\+$decimal)?>" \
97 "<foo(\\+$decimal)?>"
102 foreach_with_prefix debug {0 1} {
103 test $debug