Fix for newer kernels with: t (tracing stop)

Message ID 20160604122904.GA11651@host1.jankratochvil.net
State New, archived
Headers

Commit Message

Jan Kratochvil June 4, 2016, 12:29 p.m. UTC
  Hi,

I did provide wrong ptrace data which should fail on their write.
	error (_("Unexpected error setting hardware debug registers"));
But GDB did not print that error, only inferior did hang, because the data was
not written.

It is because this error/exception gets suppressed by:
linux_resume_one_lwp():
1578          if (!check_ptrace_stopped_lwp_gone (lp))
1579            throw_exception (ex);

Which happens because check_ptrace_stopped_lwp_gone()
expects 'T (tracing stop)' while recent Linux kernels
provide 't (tracing stop)' instad.
	What does lowercase t means in ps state code
	http://stackoverflow.com/questions/35895886/what-does-lowercase-t-means-in-ps-state-code

Found it on:
	kernel-4.4.6-301.fc23.aarch64
by:
	gdb/nat/aarch64-linux-hw-point.c
	-  ctrl |= ((1 << len) - 1) << 5;
	+  ctrl |= (((1 << len) - 1)&~1) << 5;

It does not change testsuite results on that F-23.aarch64 machine.
I see no real regessions on rawhide.x86_64 machine (with F-23 kernel) although
there were some fuzzy results I will need to check more.

OK for check-in?


Thanks,
Jan
gdb/ChangeLog
2016-06-04  Jan Kratochvil  <jan.kratochvil@redhat.com>

	* nat/linux-procfs.c (linux_proc_pid_has_state): Add parameter state2.
	(linux_proc_pid_is_stopped): Update caller.
	(linux_proc_pid_is_trace_stopped_nowarn): Add 't (tracing stop)'.
	(linux_proc_pid_is_zombie_maybe_warn): Update caller.
  

Comments

Pedro Alves July 22, 2016, 3:35 p.m. UTC | #1
On 06/04/2016 01:29 PM, Jan Kratochvil wrote:
> Hi,
> 
> I did provide wrong ptrace data which should fail on their write.
> 	error (_("Unexpected error setting hardware debug registers"));
> But GDB did not print that error, only inferior did hang, because the data was
> not written.
> 
> It is because this error/exception gets suppressed by:
> linux_resume_one_lwp():
> 1578          if (!check_ptrace_stopped_lwp_gone (lp))
> 1579            throw_exception (ex);
> 
> Which happens because check_ptrace_stopped_lwp_gone()
> expects 'T (tracing stop)' while recent Linux kernels
> provide 't (tracing stop)' instad.
> 	What does lowercase t means in ps state code
> 	http://stackoverflow.com/questions/35895886/what-does-lowercase-t-means-in-ps-state-code

Eh, I'm not sure how I ended up with "T (tracing stop)"
in the first place last year, as I think I was on Fedora 20,
and lowercase "t (tracing stop)" is around since 2009.

> 
> Found it on:
> 	kernel-4.4.6-301.fc23.aarch64
> by:
> 	gdb/nat/aarch64-linux-hw-point.c
> 	-  ctrl |= ((1 << len) - 1) << 5;
> 	+  ctrl |= (((1 << len) - 1)&~1) << 5;
> 
> It does not change testsuite results on that F-23.aarch64 machine.
> I see no real regessions on rawhide.x86_64 machine (with F-23 kernel) although
> there were some fuzzy results I will need to check more.
> 
> OK for check-in?

OK.

I wonder whether it wouldn't simplify things to parse the
state into some new enum lwp_state instead of the current scheme
of passing state strings around.  I may give that a try as follow up.

Thanks,
Pedro Alves
  

Patch

--- a/gdb/nat/linux-procfs.c
+++ b/gdb/nat/linux-procfs.c
@@ -129,17 +129,20 @@  linux_proc_pid_is_gone (pid_t pid)
     }
 }
 
-/* Return non-zero if 'State' of /proc/PID/status contains STATE.  If
-   WARN, warn on failure to open the /proc file.  */
+/* Return non-zero if 'State' of /proc/PID/status contains STATE or STATE2.
+   STATE2 can be NULL.  If WARN, warn on failure to open the /proc file.  */
 
 static int
-linux_proc_pid_has_state (pid_t pid, const char *state, int warn)
+linux_proc_pid_has_state (pid_t pid, const char *state, const char *state2,
+			  int warn)
 {
   char buffer[100];
   int have_state;
 
   have_state = linux_proc_pid_get_state (pid, buffer, sizeof buffer, warn);
-  return (have_state > 0 && strstr (buffer, state) != NULL);
+  return (have_state > 0
+	  && (strstr (buffer, state) != NULL
+	      || (state2 != NULL && strstr (buffer, state2) != NULL)));
 }
 
 /* Detect `T (stopped)' in `/proc/PID/status'.
@@ -148,16 +151,18 @@  linux_proc_pid_has_state (pid_t pid, const char *state, int warn)
 int
 linux_proc_pid_is_stopped (pid_t pid)
 {
-  return linux_proc_pid_has_state (pid, "T (stopped)", 1);
+  return linux_proc_pid_has_state (pid, "T (stopped)", NULL, 1);
 }
 
-/* Detect `T (tracing stop)' in `/proc/PID/status'.
-   Other states including `T (stopped)' are reported as false.  */
+/* Detect `t (tracing stop)'  or `T (tracing stop)' (present in older
+   kernels) in `/proc/PID/status'.  Other states including `T (stopped)'
+   are reported as false.  */
 
 int
 linux_proc_pid_is_trace_stopped_nowarn (pid_t pid)
 {
-  return linux_proc_pid_has_state (pid, "T (tracing stop)", 1);
+  return linux_proc_pid_has_state (pid, "t (tracing stop)", "T (tracing stop)",
+                                   1);
 }
 
 /* Return non-zero if PID is a zombie.  If WARN, warn on failure to
@@ -166,7 +171,7 @@  linux_proc_pid_is_trace_stopped_nowarn (pid_t pid)
 static int
 linux_proc_pid_is_zombie_maybe_warn (pid_t pid, int warn)
 {
-  return linux_proc_pid_has_state (pid, "Z (zombie)", warn);
+  return linux_proc_pid_has_state (pid, "Z (zombie)", NULL, warn);
 }
 
 /* See linux-procfs.h declaration.  */