public inbox for git-commits@fedoraproject.org
help / color / mirror / Atom feed
From: Jan Kratochvil <jan.kratochvil@redhat.com>
To: git-commits@fedoraproject.org
Subject: [rpms/gdb] gdb-17.2-rebase-f44: Never kill PID on: gdb exec PID (Jan Kratochvil, RH BZ 1219747).
Date: Sat, 27 Jun 2026 23:57:37 GMT	[thread overview]
Message-ID: <178260465732.1.14894816872166135434.rpms-gdb-7ecbbb2a1685@fedoraproject.org> (raw)

A new commit has been pushed.

Repo   : rpms/gdb
Branch : gdb-17.2-rebase-f44
Commit : 7ecbbb2a1685c02e5b3a29e8cdeb6daab98ebb63
Author : Jan Kratochvil <jan.kratochvil@redhat.com>
Date   : 2016-04-12T21:36:15+02:00
Stats  : +230/-1 in 2 file(s)
URL    : https://src.fedoraproject.org/rpms/gdb/c/7ecbbb2a1685c02e5b3a29e8cdeb6daab98ebb63?branch=gdb-17.2-rebase-f44

Log:
Never kill PID on: gdb exec PID (Jan Kratochvil, RH BZ 1219747).

---
diff --git a/gdb-bz1219747-attach-kills.patch b/gdb-bz1219747-attach-kills.patch
new file mode 100644
index 0000000..fe3781c
--- /dev/null
+++ b/gdb-bz1219747-attach-kills.patch
@@ -0,0 +1,222 @@
+http://sourceware.org/ml/gdb-patches/2015-10/msg00301.html
+Subject: [PATCH 1/3] Never kill PID on: gdb exec PID
+
+Hi,
+
+in some cases with deleted main executable GDB will want to kill the inferior.
+
+$ cp /bin/sleep /tmp/sleep;/tmp/sleep 1h&p=$!
+$ rm /tmp/sleep
+$ gdb /tmp/sleep $p
+GNU gdb (GDB) 7.10.50.20151016-cvs
+/tmp/sleep: No such file or directory.
+Attaching to process 9694
+/tmp/sleep (deleted): No such file or directory.
+A program is being debugged already.  Kill it? (y or n) _
+
+The first attachment of "/tmp/sleep" commandline argument errors at:
+
+#0  throw_error (error=GENERIC_ERROR, fmt=0x116d135 "%s.") at ./common/common-exceptions.c:371
+#1  in throw_perror_with_name (errcode=GENERIC_ERROR, string=0x7fffffffdb96 "/dfsfds") at utils.c:974
+#2  in perror_with_name (string=0x7fffffffdb96 "/dfsfds") at utils.c:982
+#3  in exec_file_attach (filename=0x7fffffffdb96 "/dfsfds", from_tty=1) at exec.c:268
+267               if (scratch_chan < 0)
+268                 perror_with_name (filename);
+#4  in catch_command_errors_const (command=0x80f59f <exec_file_attach>, arg=0x7fffffffdb96 "/dfsfds", from_tty=1) at main.c:395
+#5  in captured_main (data=0x7fffffffd6f0) at main.c:1051
+1051          if (catch_command_errors_const (exec_file_attach, execarg,
+1052                                          !batch_flag))
+
+Then GDB tries to attach to the process $p:
+
+#0  inferior_appeared (inf=0x240e0b0, pid=29210) at inferior.c:305
+#1  in inf_ptrace_attach (ops=0x2339540, args=0x21dcdc0 "29210", from_tty=1) at inf-ptrace.c:206
+#2  in linux_nat_attach (ops=0x2339540, args=0x21dcdc0 "29210", from_tty=1) at linux-nat.c:1278
+#3  in attach_command (args=0x21dcdc0 "29210", from_tty=1) at infcmd.c:2748
+#4  in catch_command_errors (command=0x79d7e5 <attach_command>, arg=0x7fffffffdb9e "29210", from_tty=1) at main.c:368
+#5  in captured_main (data=0x7fffffffd6f0) at main.c:1082
+1082              if (catch_command_errors (attach_command, pid_or_core_arg,
+1083                                        !batch_flag) == 0)
+
+This succeeds and since this moment GDB has a valid inferior.  But despite that
+the lines
+1082              if (catch_command_errors (attach_command, pid_or_core_arg,
+1083                                        !batch_flag) == 0)
+still fail because consequently attach_command() fails to find the associated
+executable file:
+
+#0  throw_error (error=GENERIC_ERROR, fmt=0x116d135 "%s.") at ./common/common-exceptions.c:371
+#1  in throw_perror_with_name (errcode=GENERIC_ERROR, string=0x2477860 "/tmp/sleep (deleted)") at utils.c:974
+#2  in perror_with_name (string=0x2477860 "/tmp/sleep (deleted)") at utils.c:982
+#3  in exec_file_attach (filename=0x2477860 "/tmp/sleep (deleted)", from_tty=1) at exec.c:268
+267               if (scratch_chan < 0)
+268                 perror_with_name (filename);
+#4  in exec_file_locate_attach (pid=29210, from_tty=1) at exec.c:173
+#5  in attach_command_post_wait (args=0x24739b0 "29210", from_tty=1, async_exec=0) at infcmd.c:2628
+#6  in attach_command_continuation (args=0x2473590, err=0) at infcmd.c:2700
+#7  in do_my_continuations_1 (pmy_chain=0x7fffffffd190, err=0) at continuations.c:59
+#8  in do_my_continuations (list=0x240e130, err=0) at continuations.c:83
+#9  in do_all_inferior_continuations (err=0) at continuations.c:125
+#10 in inferior_event_handler (event_type=INF_EXEC_COMPLETE, client_data=0x0) at inf-loop.c:60
+#11 in fetch_inferior_event (client_data=0x0) at infrun.c:3929
+#12 in inferior_event_handler (event_type=INF_REG_EVENT, client_data=0x0) at inf-loop.c:44
+#13 in handle_target_event (error=0, client_data=0x0) at linux-nat.c:4681
+#14 in handle_file_event (file_ptr=0x21e4170, ready_mask=1) at event-loop.c:708
+#15 in gdb_wait_for_event (block=0) at event-loop.c:834
+#16 in gdb_do_one_event () at event-loop.c:298
+#17 in wait_sync_command_done () at top.c:373
+#18 in maybe_wait_sync_command_done (was_sync=0) at top.c:388
+#19 in catch_command_errors (command=0x79d7e5 <attach_command>, arg=0x7fffffffdb9e "29210", from_tty=1) at main.c:370
+#20 in captured_main (data=0x7fffffffd6f0) at main.c:1082
+1082              if (catch_command_errors (attach_command, pid_or_core_arg,
+1083                                        !batch_flag) == 0)
+
+and therefore GDB executes the following:
+
+(gdb) bt
+#5  in query (ctlstr=0x1141ae8 "A program is being debugged already.  Kill it? ") at utils.c:1371
+#6  in target_preopen (from_tty=1) at target.c:2183
+2179	  if (have_inferiors ())
+2180	    {
+2181	      if (!from_tty
+2182		  || !have_live_inferiors ()
+2183		  || query (_("A program is being debugged already.  Kill it? ")))
+2184		iterate_over_inferiors (dispose_inferior, NULL);
+2185	      else
+2186		error (_("Program not killed."));
+2187	    }
+#7  in core_open (arg=0x7fffffffdb9f "9694", from_tty=1) at corelow.c:283
+#8  in core_file_command (filename=0x7fffffffdb9f "9694", from_tty=1) at corefile.c:77
+#9  in catch_command_errors (command=0x86ca16 <core_file_command>, arg=0x7fffffffdb9f "9694", from_tty=1) at main.c:368
+#10 in captured_main (data=0x7fffffffd6f0) at main.c:1084
+1084		    catch_command_errors (core_file_command, pid_or_core_arg,
+1085					  !batch_flag);
+
+No regressions on {x86_64,x86_64-m32,i686}-fedora24pre-linux-gnu.
+
+
+Thanks,
+Jan
+
+
+gdb/ChangeLog
+2015-10-16  Jan Kratochvil  <jan.kratochvil@redhat.com>
+
+	* main.c (captured_main): Run core_file_command for pid_or_core_arg
+	only if not have_inferiors ().
+
+gdb/testsuite/ChangeLog
+2015-10-16  Jan Kratochvil  <jan.kratochvil@redhat.com>
+
+	* gdb.base/attach-kills.c: New.
+	* gdb.base/attach-kills.exp: New.
+---
+ gdb/testsuite/gdb.base/attach-kills.c   |   25 ++++++++++++++++
+ gdb/testsuite/gdb.base/attach-kills.exp |   49 +++++++++++++++++++++++++++++++
+ 2 files changed, 74 insertions(+)
+ create mode 100644 gdb/testsuite/gdb.base/attach-kills.c
+ create mode 100644 gdb/testsuite/gdb.base/attach-kills.exp
+
+diff --git a/gdb/main.c b/gdb/main.c
+index 49c9b68..bc19699 100644
+--- a/gdb/main.c
++++ b/gdb/main.c
+@@ -1080,7 +1080,10 @@ captured_main (void *data)
+       if (isdigit (pid_or_core_arg[0]))
+ 	{
+ 	  if (catch_command_errors (attach_command, pid_or_core_arg,
+-				    !batch_flag) == 0)
++				    !batch_flag) == 0
++	      /* attach_command could succeed partially and core_file_command
++		 would try to kill it.  */
++	      && !have_inferiors ())
+ 	    catch_command_errors (core_file_command, pid_or_core_arg,
+ 				  !batch_flag);
+ 	}
+diff --git a/gdb/testsuite/gdb.base/attach-kills.c b/gdb/testsuite/gdb.base/attach-kills.c
+new file mode 100644
+index 0000000..2398f00
+--- /dev/null
++++ b/gdb/testsuite/gdb.base/attach-kills.c
+@@ -0,0 +1,25 @@
++/* This testcase is part of GDB, the GNU debugger.
++
++   Copyright 2015 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 <http://www.gnu.org/licenses/>.  */
++
++#include <unistd.h>
++
++int
++main (void)
++{
++  sleep (600);
++  return 0;
++}
+diff --git a/gdb/testsuite/gdb.base/attach-kills.exp b/gdb/testsuite/gdb.base/attach-kills.exp
+new file mode 100644
+index 0000000..9a93cb7
+--- /dev/null
++++ b/gdb/testsuite/gdb.base/attach-kills.exp
+@@ -0,0 +1,49 @@
++# Copyright (C) 2015 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 <http://www.gnu.org/licenses/>.
++
++if { ![can_spawn_for_attach] } {
++    return 0
++}
++
++standard_testfile
++
++if { [build_executable ${testfile}.exp $testfile] == -1 } {
++    return -1
++}
++
++# Start the program running and then wait for a bit, to be sure
++# that it can be attached to.
++
++set test_spawn_id [spawn_wait_for_attach $binfile]
++set testpid [spawn_id_get_pid $test_spawn_id]
++
++remote_exec target "cp -pf -- $binfile $binfile-copy"
++remote_exec target "rm -f -- $binfile"
++
++set test "start gdb"
++set res [gdb_spawn_with_cmdline_opts \
++	 "-iex \"set height 0\" -iex \"set width 0\" /DoEsNoTeXySt $testpid"]
++if { $res != 0} {
++    fail "$test (spawn)"
++    kill_wait_spawned_process $test_spawn_id
++    return -1
++}
++gdb_test_multiple "" $test {
++    -re "\r\nAttaching to .*\r\n$gdb_prompt $" {
++	pass $test
++    }
++}
++
++kill_wait_spawned_process $test_spawn_id
+

diff --git a/gdb.spec b/gdb.spec
index c4815d1..441b3c2 100644
--- a/gdb.spec
+++ b/gdb.spec
@@ -27,7 +27,7 @@ Version: 7.11
 
 # The release always contains a leading reserved number, start it at 1.
 # `upstream' is not a part of `name' to stay fully rpm dependencies compatible for the testing.
-Release: 68%{?dist}
+Release: 69%{?dist}
 
 License: GPLv3+ and GPLv3+ with exceptions and GPLv2+ and GPLv2+ with exceptions and GPL+ and LGPLv2+ and BSD and Public Domain and GFDL
 Group: Development/Debuggers
@@ -538,6 +538,9 @@ Patch927: gdb-python-gil.patch
 # Fix jit-reader.h for multi-lib.
 Patch978: gdb-jit-reader-multilib.patch
 
+# Never kill PID on: gdb exec PID (Jan Kratochvil, RH BZ 1219747).
+Patch1053: gdb-bz1219747-attach-kills.patch
+
 # Fix the pahole command breakage due to its Python3 port (RH BZ 1264532).
 Patch1044: gdb-pahole-python2.patch
 
@@ -863,6 +866,7 @@ find -name "*.info*"|xargs rm -f
 %patch925 -p1
 %patch927 -p1
 %patch978 -p1
+%patch1053 -p1
 %patch1056 -p1
 %patch1073 -p1
 %patch848 -p1
@@ -1393,6 +1397,9 @@ then
 fi
 
 %changelog
+* Tue Apr 12 2016 Jan Kratochvil <jan.kratochvil@redhat.com> - 7.11-69.fc24
+- Never kill PID on: gdb exec PID (Jan Kratochvil, RH BZ 1219747).
+
 * Fri Apr  8 2016 Jan Kratochvil <jan.kratochvil@redhat.com> - 7.11-68.fc24
 - [--with testsuite] Add two more BuildRequires.
 

                 reply	other threads:[~2026-06-27 23:57 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=178260465732.1.14894816872166135434.rpms-gdb-7ecbbb2a1685@fedoraproject.org \
    --to=jan.kratochvil@redhat.com \
    --cc=git-commits@fedoraproject.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox