]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blame - gdb/testsuite/gdb.base/ctxobj.exp
Show locno for 'multi location' breakpoint hit msg+conv var $_hit_bbnum $_hit_locno...
[thirdparty/binutils-gdb.git] / gdb / testsuite / gdb.base / ctxobj.exp
CommitLineData
4a94e368 1# Copyright 2012-2022 Free Software Foundation, Inc.
afba63f1
JB
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
48b56b6a 16if {[skip_shlib_tests]} {
17 return -1
18}
19
afba63f1
JB
20set executable ctxobj-m
21
22# The sources used to build two shared libraries (SO). We use the exact
23# same sources to build both SOs, but differentiate them through the use
24# of macros defined when calling the compiler.
25#
26# We need two source files per SO, because we need to test the situation
27# where we are trying to print the value of a global variable defined
28# in that SO while the variable's associated symtab has not been created
29# yet.
30set libsrc [list "${srcdir}/${subdir}/ctxobj-v.c" \
31 "${srcdir}/${subdir}/ctxobj-f.c"]
32
f76495c8
TT
33set libobj1 [standard_output_file libctxobj1.so]
34set libobj2 [standard_output_file libctxobj2.so]
afba63f1 35
2f413264 36set libobj1_opts { debug
afba63f1
JB
37 additional_flags=-DVERSION=104
38 additional_flags=-DGET_VERSION=get_version_1 }
2f413264 39set libobj2_opts { debug
afba63f1
JB
40 additional_flags=-DVERSION=203
41 additional_flags=-DGET_VERSION=get_version_2 }
42
43if { [gdb_compile_shlib $libsrc $libobj1 $libobj1_opts ] != "" } {
44 return -1
45}
46if { [gdb_compile_shlib $libsrc $libobj2 $libobj2_opts ] != "" } {
47 return -1
48}
49if { [gdb_compile "${srcdir}/${subdir}/${executable}.c" \
f76495c8 50 [standard_output_file ${executable}] \
afba63f1
JB
51 executable \
52 [list debug shlib=${libobj1} shlib=${libobj2}]]
53 != ""} {
54 return -1
55}
56
57clean_restart $executable
d9019901
SM
58gdb_load_shlib $libobj1
59gdb_load_shlib $libobj2
afba63f1
JB
60
61if ![runto_main] {
afba63f1
JB
62 return -1
63}
64
c56e7c43
JB
65set bp_location [gdb_get_line_number "STOP" "ctxobj-f.c"]
66gdb_test "break ctxobj-f.c:$bp_location" \
67 "Breakpoint \[0-9\]+ at 0x\[0-9a-fA-F\]+: .*" \
68 "break in get_version functions"
69
78805ff8
PW
70global expect_out
71set test "continue to get_version_1"
72gdb_test_multiple "continue" $test {
73 -re "Breakpoint ($bkptno_num_re), get_version_1 \\(\\).*" {
74 set bpno $expect_out(1,string)
75 pass $test
76 }
77}
78# Verify $_hit_bpnum.$_hit_locno convenience variables are set to the hit bpno.
79gdb_test "printf \"%d.%d\\n\", \$_hit_bpnum, \$_hit_locno" "$bpno" \
80 "$test \$_hit_bpnum.\$_hit_locno is $bpno"
afba63f1
JB
81
82# Try printing "this_version_num". There are two global variables
c56e7c43
JB
83# with that name, and some systems such as GNU/Linux merge them
84# into one single entity, while some other systems such as Windows
85# keep them separate. In the first situation, we have to verify
86# that GDB does not randomly select the wrong instance. And in
87# the second case, we have to verify that GDB prints the value
88# of the instance from the current debugging context (the shared
89# library currently being debugged).
90#
91# We perform two tests: The first print test verifies that we are
92# doing things right when the partial symtab hasn't been expanded.
93# And the second print test will do the same, but after the partial
94# symtab has been expanded.
95#
96# To avoid adding target-specific code in this testcase, the program
97# sets a local variable named 'v' with the value of the global
98# variable 'this_version_number'. This allows us to compare the value
99# that GDB thinks 'this_version_num' has, against the actual value
100# seen by the program itself.
101
102gdb_test "print this_version_num == v" \
103 " = 1" \
afba63f1
JB
104 "print libctxobj1's this_version_num from partial symtab"
105
c56e7c43
JB
106gdb_test "print this_version_num == v" \
107 " = 1" \
afba63f1
JB
108 "print libctxobj1's this_version_num from symtab"
109
110# Do the same, but from get_version_2.
78805ff8
PW
111set test "continue to get_version_2"
112gdb_test_multiple "continue" $test {
113 -re "Breakpoint ($bkptno_num_re), get_version_2 \\(\\).*" {
114 set bpno $expect_out(1,string)
115 pass $test
116 }
117}
118# Verify the $_hit_bpnum.$_hit_locno convenience variables are set to the hit bpno.
119gdb_test "printf \"%d.%d\\n\", \$_hit_bpnum, \$_hit_locno" "$bpno" \
120 "$test \$_hit_bpnum.\$_hit_locno is $bpno"
afba63f1 121
c56e7c43
JB
122gdb_test "print this_version_num == v" \
123 " = 1" \
afba63f1
JB
124 "print libctxobj2's this_version_num from partial symtab"
125
c56e7c43
JB
126gdb_test "print this_version_num == v" \
127 " = 1" \
afba63f1 128 "print libctxobj2's this_version_num from symtab"