From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 7291 invoked by alias); 22 Aug 2017 14:05:12 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Received: (qmail 7262 invoked by uid 89); 22 Aug 2017 14:05:11 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-26.9 required=5.0 tests=BAYES_00,GIT_PATCH_0,GIT_PATCH_1,GIT_PATCH_2,GIT_PATCH_3,RP_MATCHES_RCVD,SPF_HELO_PASS autolearn=ham version=3.3.2 spammy=occasions, multi X-HELO: mx1.redhat.com Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Tue, 22 Aug 2017 14:05:04 +0000 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id ACFC325C29 for ; Tue, 22 Aug 2017 14:05:03 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com ACFC325C29 Authentication-Results: ext-mx06.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx06.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=sergiodj@redhat.com Received: from psique.yyz.redhat.com (unused-10-15-17-193.yyz.redhat.com [10.15.17.193]) by smtp.corp.redhat.com (Postfix) with ESMTP id EFD6977C0D; Tue, 22 Aug 2017 14:04:57 +0000 (UTC) From: Sergio Durigan Junior To: GDB Patches Cc: Jan Kratochvil , Pedro Alves , Sergio Durigan Junior Subject: [PATCH] Fix PR remote/21852: Remote run without specifying a local binary crashes GDB Date: Tue, 22 Aug 2017 14:05:00 -0000 Message-Id: <20170822140448.19153-1-sergiodj@redhat.com> X-IsSubscribed: yes X-SW-Source: 2017-08/txt/msg00416.txt.bz2 The fix for PR gdb/20609: commit bb805577d2b212411fb7b0a2d01644567fac4e8d Author: Jan Kratochvil Date: Thu Sep 29 17:38:16 2016 +0200 Introduced the concept of deferring the call to breakpoint_re_set on certain useful occasions. However, there is one specific scenario where delaying needs to be done and still isn't: the case when we're starting a GDB to debug a remote inferior without specifying a local binary, as in for example: ./gdb -nx -q --data-directory=data-directory -ex "tar ext :1234" \ -ex "set remote exec-file /bin/ls" -ex r In this case, when calling exec_file_locate_attach to locate the inferior, GDB is incorrectly resetting the breakpoints without a thread/inferior even running, which causes an assertion to be triggered: binutils-gdb/gdb/thread.c:1609: internal-error: scoped_restore_current_thread::scoped_restore_current_thread(): Assertion `tp != NULL' failed. A problem internal to GDB has been detected, further debugging may prove unreliable. Quit this debugging session? (y or n) The right thing to do is to defer resetting the breakpoints when locating the binary, which is what this patch does. A testcase is also provided. Regtested on buildbot. gdb/ChangeLog: 2017-08-22 Sergio Durigan Junior PR remote/21852 * remote.c (remote_add_inferior): Tell "exec_file_locate_attach" to defer calling breakpoint_re_set. gdb/testsuite/ChangeLog: 2017-08-22 Sergio Durigan Junior PR remote/21852 * gdb.server/normal.c: New file, copied from gdb.base. * gdb.server/run-without-local-binary.exp: New file. --- gdb/remote.c | 2 +- gdb/testsuite/gdb.server/normal.c | 24 ++++++++++ .../gdb.server/run-without-local-binary.exp | 56 ++++++++++++++++++++++ 3 files changed, 81 insertions(+), 1 deletion(-) create mode 100644 gdb/testsuite/gdb.server/normal.c create mode 100644 gdb/testsuite/gdb.server/run-without-local-binary.exp diff --git a/gdb/remote.c b/gdb/remote.c index ff59a0f81f..c9bcb163e7 100644 --- a/gdb/remote.c +++ b/gdb/remote.c @@ -1825,7 +1825,7 @@ remote_add_inferior (int fake_pid_p, int pid, int attached, /* If no main executable is currently open then attempt to open the file that was executed to create this inferior. */ if (try_open_exec && get_exec_file (0) == NULL) - exec_file_locate_attach (pid, 0, 1); + exec_file_locate_attach (pid, 1, 1); return inf; } diff --git a/gdb/testsuite/gdb.server/normal.c b/gdb/testsuite/gdb.server/normal.c new file mode 100644 index 0000000000..f0eb1541fd --- /dev/null +++ b/gdb/testsuite/gdb.server/normal.c @@ -0,0 +1,24 @@ +/* This testcase is part of GDB, the GNU debugger. + + Copyright 2013-2017 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 . */ + +/* This test is just a normal return 0. */ + +int +main (int argc, char *argv[]) +{ + return 0; +} diff --git a/gdb/testsuite/gdb.server/run-without-local-binary.exp b/gdb/testsuite/gdb.server/run-without-local-binary.exp new file mode 100644 index 0000000000..5af2d1bb25 --- /dev/null +++ b/gdb/testsuite/gdb.server/run-without-local-binary.exp @@ -0,0 +1,56 @@ +# Copyright 2017 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 . */ + +load_lib gdbserver-support.exp + +if {[skip_gdbserver_tests]} { + return +} + +standard_testfile normal.c + +if {[prepare_for_testing "failed to prepare" $testfile $srcfile debug]} { + return -1 +} + +# Test running GDB without providing a local binary for it. In order +# to do that, we unset GDBFLAGS before running GDB. We also start +# gdbserver "by hand". For more details about this test, see PR +# remote/21852. +save_vars { GDBFLAGS } { + set GDBFLAGS "" + gdb_exit + gdb_start + + gdb_test_no_output "set remote exec-file $binfile" \ + "set remote exec-file" + + # Let's start gdbserver in extended-remote mode now. + set res [gdbserver_start "--multi" ""] + set gdbserver_protocol [lindex $res 0] + if { [string first "extended-" $gdbserver_protocol] != 0} { + set gdbserver_protocol "extended-$gdbserver_protocol" + } + set gdbserver_gdbport [lindex $res 1] + set use_gdb_stub 0 + + gdb_test "target ${gdbserver_protocol} ${gdbserver_gdbport}" \ + "Remote debugging using $gdbserver_gdbport" \ + "connect to gdbserver" + + gdb_test "run" \ + "\\\[Inferior $decimal \\\(process $decimal\\\) exited normally\\\]" \ + "run test program until the end" +} -- 2.13.3