From 120d9979a082b349590f64faa40dba0c04716646 Mon Sep 17 00:00:00 2001 From: Pedro Alves Date: Tue, 9 Jan 2018 00:37:36 +0000 Subject: [PATCH] Fix backwards compatibility with old GDBservers (PR remote/22597) gdb/testsuite/ChangeLog: yyyy-mm-dd Pedro Alves PR remote/22597 * gdb.server/stop-reply-no-thread.c: New file. * gdb.server/stop-reply-no-thread.exp: New file. gdb/ChangeLog: yyyy-mm-dd Pedro Alves PR remote/22597 * remote.c (remote_parse_stop_reply): Default to the last-set general thread instead of to 'magic_null_ptid'. --- gdb/remote.c | 8 ++- gdb/testsuite/gdb.server/stop-reply-no-thread.c | 22 +++++++ gdb/testsuite/gdb.server/stop-reply-no-thread.exp | 74 +++++++++++++++++++++++ 3 files changed, 103 insertions(+), 1 deletion(-) create mode 100644 gdb/testsuite/gdb.server/stop-reply-no-thread.c create mode 100644 gdb/testsuite/gdb.server/stop-reply-no-thread.exp diff --git a/gdb/remote.c b/gdb/remote.c index 81c772a5451..a1cd9ae1df3 100644 --- a/gdb/remote.c +++ b/gdb/remote.c @@ -6940,7 +6940,13 @@ Packet: '%s'\n"), event->ptid = read_ptid (thr + strlen (";thread:"), NULL); else - event->ptid = magic_null_ptid; + { + /* Either the current thread hasn't changed, + or the inferior is not multi-threaded. + The event must be for the thread we last + set as (or learned as being) current. */ + event->ptid = event->rs->general_thread; + } } if (rsa == NULL) diff --git a/gdb/testsuite/gdb.server/stop-reply-no-thread.c b/gdb/testsuite/gdb.server/stop-reply-no-thread.c new file mode 100644 index 00000000000..a9058de0483 --- /dev/null +++ b/gdb/testsuite/gdb.server/stop-reply-no-thread.c @@ -0,0 +1,22 @@ +/* This testcase is part of GDB, the GNU debugger. + + Copyright 2018 Free Software Foundation, Inc. + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . */ + +int +main () +{ + return 0; +} diff --git a/gdb/testsuite/gdb.server/stop-reply-no-thread.exp b/gdb/testsuite/gdb.server/stop-reply-no-thread.exp new file mode 100644 index 00000000000..2bb8c7ac7c5 --- /dev/null +++ b/gdb/testsuite/gdb.server/stop-reply-no-thread.exp @@ -0,0 +1,74 @@ +# This testcase is part of GDB, the GNU debugger. +# +# Copyright 2018 Free Software Foundation, Inc. +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + +# Test backward compatibility with older GDBservers which did not +# include ";thread:NNN" in T stop replies when debugging +# single-threaded programs, even though they'd list the main thread in +# response to qfThreadInfo/qsThreadInfo. See PR remote/22597. + +load_lib gdbserver-support.exp + +if { [skip_gdbserver_tests] } { + verbose "skipping gdbserver tests" + return -1 +} + +standard_testfile +if [prepare_for_testing "failed to prepare" $testfile $srcfile] { + return -1 +} + +# Make sure we're disconnected, in case we're testing with an +# extended-remote board, therefore already connected. +gdb_test "disconnect" ".*" + +# Start GDBserver, with ";thread:NNN" in T stop replies disabled, +# emulating old gdbservers when debugging single-threaded programs. +set res [gdbserver_start "--disable-packet=Tthread" $binfile] +set gdbserver_protocol [lindex $res 0] +set gdbserver_gdbport [lindex $res 1] + +# Disable XML-based thread listing, and multi-process extensions. +gdb_test_no_output "set remote threads-packet off" +gdb_test_no_output "set remote multiprocess-feature-packet off" + +set res [gdb_target_cmd $gdbserver_protocol $gdbserver_gdbport] +if ![gdb_assert {$res == 0} "connect"] { + return +} + +# There should be only one thread listed. +set test "info threads" +gdb_test_multiple $test $test { + -re "2 Thread.*$gdb_prompt $" { + fail $test + } + -re "has terminated.*$gdb_prompt $" { + fail $test + } + -re "\\\* 1\[\t \]*Thread\[^\r\n\]*\r\n$gdb_prompt $" { + pass $test + } +} + +gdb_breakpoint "main" + +# Bad GDB behaved like this: +# (gdb) c +# Cannot execute this command without a live selected thread. +# (gdb) +gdb_test "c" "Breakpoint $decimal, main.*" "continue to main" -- 2.14.3