This is the mail archive of the elfutils-devel@sourceware.org mailing list for the elfutils project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[patch] T-stopped detach for RHEL-6 era kernels


Hi Mark,

jankratochvil/stoppedel6

this is similar to the patch
	[unwinder-portable patch 1/3] Handle T-stopped detach for old kernels
	https://lists.fedorahosted.org/pipermail/elfutils-devel/2013-November/003393.html

already checked in the 'portable' branch but this time it is more lightweight
needed for RHEL-6 era kernels (the 'portable' branch was for RHEL-5 era
kernels).

This patch somehow also belongs to the 'portable' branch but so far there is
AFAIK an agreement RHEL-6 era kernels are recent enough they should still be
supported by elfutils trunk.

This patch mostly replaces the 'portable' patch above although it has slightly
different naming - it matches more the current at-most-one-TID-attached.
Most of the 'portable' patch gets obsoleted/replaced by this one (but sure not
completely).


Thanks,
Jan


b3efd86b33df5a9fa20018800c9eac953ef32da9 Mon Sep 17 00:00:00 2001
From: Jan Kratochvil <jan.kratochvil@redhat.com>
Date: Sun, 17 Nov 2013 21:07:20 +0100
Subject: [PATCH] Compatibility with older kernels such as RHEL-6.

libdwfl/
2013-11-17  Jan Kratochvil  <jan.kratochvil@redhat.com>

	Compatibility with older kernels such as RHEL-6.
	* linux-pid-attach.c (struct pid_arg): New field tid_was_stopped.
	(ptrace_attach): New parameter tid_was_stoppedp.  Set it.
	(pid_set_initial_registers): Pass tid_was_stopped.
	(pid_thread_detach): Use tid_was_stopped.

Signed-off-by: Jan Kratochvil <jan.kratochvil@redhat.com>
---
 libdwfl/linux-pid-attach.c | 16 ++++++++++++----
 1 file changed, 12 insertions(+), 4 deletions(-)

diff --git a/libdwfl/linux-pid-attach.c b/libdwfl/linux-pid-attach.c
index ca82144..e4eb621 100644
--- a/libdwfl/linux-pid-attach.c
+++ b/libdwfl/linux-pid-attach.c
@@ -42,6 +42,8 @@ struct pid_arg
   DIR *dir;
   /* It is 0 if not used.  */
   pid_t tid_attached;
+  /* Valid only if TID_ATTACHED is not zero.  */
+  bool tid_was_stopped;
 };
 
 static bool
@@ -69,14 +71,15 @@ linux_proc_pid_is_stopped (pid_t pid)
 }
 
 static bool
-ptrace_attach (pid_t tid)
+ptrace_attach (pid_t tid, bool *tid_was_stoppedp)
 {
   if (ptrace (PTRACE_ATTACH, tid, NULL, NULL) != 0)
     {
       __libdwfl_seterrno (DWFL_E_ERRNO);
       return false;
     }
-  if (linux_proc_pid_is_stopped (tid))
+  *tid_was_stoppedp = linux_proc_pid_is_stopped (tid);
+  if (*tid_was_stoppedp)
     {
       /* Make sure there is a SIGSTOP signal pending even when the process is
 	 already State: T (stopped).  Older kernels might fail to generate
@@ -211,7 +214,7 @@ pid_set_initial_registers (Dwfl_Thread *thread, void *thread_arg)
   struct pid_arg *pid_arg = thread_arg;
   assert (pid_arg->tid_attached == 0);
   pid_t tid = INTUSE(dwfl_thread_tid) (thread);
-  if (! ptrace_attach (tid))
+  if (! ptrace_attach (tid, &pid_arg->tid_was_stopped))
     return false;
   pid_arg->tid_attached = tid;
   Dwfl_Process *process = thread->process;
@@ -235,7 +238,12 @@ pid_thread_detach (Dwfl_Thread *thread, void *thread_arg)
   pid_t tid = INTUSE(dwfl_thread_tid) (thread);
   assert (pid_arg->tid_attached == tid);
   pid_arg->tid_attached = 0;
-  ptrace (PTRACE_DETACH, tid, NULL, NULL);
+  /* This handling is needed only on older Linux kernels such as
+     2.6.32-358.23.2.el6.ppc64.  Later kernels such as 3.11.7-200.fc19.x86_64
+     remember the T (stopped) state themselves and no longer need to pass
+     SIGSTOP during PTRACE_DETACH.  */
+  ptrace (PTRACE_DETACH, tid, NULL,
+	  (void *) (intptr_t) (pid_arg->tid_was_stopped ? SIGSTOP : 0));
 }
 
 static const Dwfl_Thread_Callbacks pid_thread_callbacks =
-- 
1.8.3.1


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]