xref: /netbsd-src/external/gpl3/gdb.old/dist/gdb/testsuite/gdb.base/valgrind-infcall-2.exp (revision cb63e24e8d6aae7ddac1859a9015f48b1d8bd90e)
1# Copyright 2020 Free Software Foundation, Inc.
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# This test-case tests the scenario for the crash fixed by commit ee3c5f8968
17# "Fix GDB crash when registers cannot be modified":
18# $ valgrind /usr/bin/sleep 10000
19# ==31595== Memcheck, a memory error detector
20# ==31595== Command: /usr/bin/sleep 10000
21# ==31595==
22# $ gdb /usr/bin/sleep
23# (gdb) target remote | vgdb --pid=31595
24# Remote debugging using | vgdb --pid=31595
25#   ...
26# $hex in __GI___nanosleep () at nanosleep.c:27
27# 27	  return SYSCALL_CANCEL (nanosleep, requested_time, remaining);
28# (gdb) p printf ("bla")
29# terminate called after throwing an instance of 'gdb_exception_error'
30# Aborted (core dumped)
31
32load_lib valgrind.exp
33
34if [is_remote target] {
35    # The test always runs locally.
36    return 0
37}
38
39standard_testfile .c
40if {[build_executable $testfile.exp $testfile $srcfile {debug}] == -1} {
41    return -1
42}
43
44set active_at_startup 0
45if { [vgdb_start $active_at_startup] == -1 } {
46    return -1
47}
48
49# Determine whether we're at nanosleep.
50gdb_test_multiple "bt 1" "do printf" {
51    -re -wrap "nanosleep.*" {
52	# If gdb doesn't crash, we get something like:
53	# (gdb) p printf ("bla")
54	# Could not write register "rdi"; remote failure reply 'E.
55	# ERROR changing register rdi regno 5
56	# gdb commands changing registers (pc, sp, ...) (e.g. 'jump',
57	# set pc, calling from gdb a function in the debugged process, ...)
58	# can only be accepted if the thread is VgTs_Runnable or VgTs_Yielding
59	# state
60	# Thread status is VgTs_WaitSys
61	# '
62	# (gdb)
63	gdb_test "p (int)printf (\"bla\")" \
64	    "can only be accepted if the thread is .*" \
65	    $gdb_test_name
66    }
67    -re -wrap "" {
68	# For some reason the error condition does not trigger if we're not
69	# at nanosleep at the point that we're connecting to vgdb.  See also
70	# comment at "exec sleep 1" in vgdb_start.
71	unsupported $gdb_test_name
72    }
73}
74
75vgdb_stop
76