1 # Copyright
(C
) 2021-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 # This is a test case
for bug
27831:
18 # https
://sourceware.org
/bugzilla
/show_bug.cgi?id
=27831
20 # Prior to fixing this bug
, GDB could be caused to assert by doing
21 # the following
: A simple
program with a global was started outside
22 # of GDB. Once GDB was started
, the symbol file was loaded in an
23 # atypical manner via the
'add-symbol-file' command.
Then, the
24 #
program was attached to via the
'attach' command at which time the
25 # symbol file was loaded again. Once attached
, printing the global
26 #
variable in the
program would trigger the assertion error.
28 # This is what the assert looked like
:
30 # gdb
/symtab.c
:6599: internal
-error
: get_msymbol_address
:
31 # Assertion `
(objf
->flags
& OBJF_MAINLINE
) == 0' failed.
33 require can_spawn_for_attach
37 if {[build_executable $testfile.exp $testfile $srcfile debug] == -1} {
38 untested "failed to compile"
42 # Use 'spawn_wait_for_attach
' to start the test program running. It'll
43 # also
sleep for a short time in order to make sure that it
's running
44 # so that GDB may attach to it.
46 set test_spawn_id [spawn_wait_for_attach $binfile]
47 set testpid [spawn_id_get_pid $test_spawn_id]
51 # Load the symbol file in an atypical manner by using the add-symbol-file
54 set test "add-symbol-file before attach"
55 gdb_test_multiple "add-symbol-file $binfile" $test {
56 -re "add symbol table from file.*y or n. $" {
60 -re -wrap "Reading symbols from .*" {
65 # Attach to the process started above. GDB will want to load a "new"
66 # symbol table, so handle that case.
69 gdb_test_multiple "attach $testpid" $test {
70 -re "Attaching to process.*Load new symbol table.*y or n. $" {
74 -re -wrap "Reading symbols from .*" {
79 # Print out the value of the global. Prior to fixing bug 27831, GDB
80 # would assert while executing this command.
82 gdb_test "print foo" "42"