Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Partha Satapathy <partha.satapathy@oracle.com>
To: Guinevere Larsen <blarsen@redhat.com>,
	gdb-patches@sourceware.org, bert.barbe@oracle.com,
	rajesh.sivaramasubramaniom@oracle.com
Subject: Re: [External] : Re: [PATCH v4] gdb : Signal to pstack/gdb kills the attached process.
Date: Thu, 7 Mar 2024 15:28:53 +0530	[thread overview]
Message-ID: <5dc1b891-943a-4f28-b75f-cc4a4f99ea0c@oracle.com> (raw)
In-Reply-To: <1018173c-5fff-4430-8db1-44b542a64cd2@redhat.com>

Author: Partha Sarathi Satapathy <partha.satapathy@oracle.com>
Date:   Fri Nov 17 09:18:56 2023 +0000

gdb : Signal to pstack/gdb kills the attached process.

Problem: While gdb is attaching an inferior, if ctrl-c is pressed in the
middle of the process attach,  the sigint is passed to the debugged
process. This triggers the exit of the inferior. For example in pstack,
printing a stack can take significant time, and ctrl-c is pressed to
abort the pstack/gdb application. This in turn kills the debugged
process, which can be critical for the system. In this case, the
intention of ctrl+c is to kill pstack/gdb, but not the inferior
application.
gdb -p <<pid>>
or gdb /proc/<<pid>>/exe pid
Attaching to process
<< ctrl+c is pressed during attach
(gdb) q
<<<< inferior process exited >>>>

A Ctrl-C/sigint received by gdb during the attachment of an inferior
passed to the debugged at some definite points during the window of
process attachment. The process of attaching an inferior is a multistep
process, and it takes time to get ready with the GDB prompt. As the
debugger and debugger are not fully attached during this period, the
sigint takes its default action to terminate the process.

Solution: While GDB attaches processes, the inferior is not the current
session leader. Hence, until attach is complete and the GDB prompt is
available, the sigint should not be passed to the inferior.
The signal should be skipped if the process runs in the background. With
this approach, we can skip passing the signature if the process is
attached to the GDB and the process attach is not complete.

Reviewed-By: Guinevere Larsen <blarsen@redhat.com>
---
  gdb/infcmd.c   | 2 ++
  gdb/inferior.h | 3 +++
  gdb/target.c   | 3 +++
  3 files changed, 8 insertions(+)

diff --git a/gdb/infcmd.c b/gdb/infcmd.c
index c1fdbb300c67..8ab2d50477f4 100644
--- a/gdb/infcmd.c
+++ b/gdb/infcmd.c
@@ -2528,6 +2528,8 @@ enum async_reply_reason
    target_post_attach (inferior_ptid.pid ());

    post_create_inferior (from_tty);
+  current_inferior ()->sync_flag = true;
+  check_quit_flag();
  }

  /* What to do after the first program stops after attaching.  */
diff --git a/gdb/inferior.h b/gdb/inferior.h
index 7be28423aeb1..a6065da19a87 100644
--- a/gdb/inferior.h
+++ b/gdb/inferior.h
@@ -600,6 +600,9 @@ class inferior : public refcounted_object,
    /* True if this child process was attached rather than forked.  */
    bool attach_flag = false;

+  /* True if inferior has been fully synced and prompt is no longer 
blocked */
+  bool sync_flag = false;
+
    /* If this inferior is a vfork child, then this is the pointer to
       its vfork parent, if GDB is still attached to it.  */
    inferior *vfork_parent = NULL;
diff --git a/gdb/target.c b/gdb/target.c
index bbc1badc9e19..7c7df9c2ed87 100644
--- a/gdb/target.c
+++ b/gdb/target.c
@@ -3794,6 +3794,9 @@ struct target_ops *
                  through the target_stack.  */
               scoped_restore_current_inferior restore_inferior;
               set_current_inferior (inf);
+             if ((current_inferior ()->attach_flag)
+               && !(current_inferior ()->sync_flag))
+                 return;
               current_inferior ()->top_target ()->pass_ctrlc ();
               return;
             }
-- 
1.8.3.1


Hi Team,

Here is the V4 for review and its a rebase to latest.

Thanks
Partha

  parent reply	other threads:[~2024-03-07  9:59 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-10-16  9:28 [PATCH] " Partha Satapathy
2023-10-25 15:54 ` Guinevere Larsen
2023-11-02 18:24   ` [External] : " Partha Satapathy
2023-11-02 18:27     ` [External] : Re: [PATCH v2] " Partha Satapathy
2023-11-06 13:38       ` Guinevere Larsen
2023-11-17 14:48         ` [External] : Re: [PATCH v3] " Partha Satapathy
2023-12-03  5:51           ` Partha Satapathy
2023-12-05 13:13           ` Guinevere Larsen
2024-01-10 15:59             ` Partha Satapathy
2024-01-24 15:19               ` Partha Satapathy
2024-02-19  5:10                 ` Partha Satapathy
2024-03-05  8:47                   ` Guinevere Larsen
2024-03-07  8:41                     ` Partha Satapathy
2024-03-07  9:58                     ` Partha Satapathy [this message]
2024-03-26  9:59                       ` [External] : Re: [PATCH v4] " Partha Satapathy
2024-03-26  9:59                       ` Partha Satapathy
2024-04-16 10:14                         ` Partha Satapathy

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=5dc1b891-943a-4f28-b75f-cc4a4f99ea0c@oracle.com \
    --to=partha.satapathy@oracle.com \
    --cc=bert.barbe@oracle.com \
    --cc=blarsen@redhat.com \
    --cc=gdb-patches@sourceware.org \
    --cc=rajesh.sivaramasubramaniom@oracle.com \
    /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