]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
Make "set scheduler-locking step" depend on user intention, only
authorPedro Alves <palves@redhat.com>
Tue, 24 Mar 2015 17:50:31 +0000 (17:50 +0000)
committerPedro Alves <palves@redhat.com>
Tue, 24 Mar 2015 17:50:31 +0000 (17:50 +0000)
Currently, "set scheduler-locking step" is a bit odd.  The manual
documents it as being optimized for stepping, so that focus of
debugging does not change unexpectedly, but then it says that
sometimes other threads may run, and thus focus may indeed change
unexpectedly...  A user can then be excused to get confused and wonder
why does GDB behave like this.

I don't think a user should have to know about details of how "next"
or whatever other run control command is implemented internally to
understand when does the "scheduler-locking step" setting take effect.

This patch completes a transition that the code has been moving
towards for a while.  It makes "set scheduler-locking step" hold
threads depending on whether the _command_ the user entered was a
stepping command [step/stepi/next/nexti], or not.

Before, GDB could end up locking threads even on "continue" if for
some reason run control decides a thread needs to be single stepped
(e.g., for a software watchpoint).

After, if a "continue" happens to need to single-step for some reason,
we won't lock threads (unless when stepping over a breakpoint,
naturally).  And if a stepping command wants to continue a thread for
bit, like when skipping a function to a step-resume breakpoint, we'll
still lock threads, so focus of debugging doesn't change.

In order to make this work, we need to record in the thread structure
whether what set it running was a stepping command.

(A follow up patch will remove the "step" parameters of 'proceed' and 'resume')

FWIW, Fedora GDB, which defaults to "scheduler-locking step" (mainline
defaults to "off") carries a different patch that goes in this
direction as well.

Tested on x86_64 Fedora 20, native and gdbserver.

gdb/ChangeLog:
2015-03-24  Pedro Alves  <palves@redhat.com>

* gdbthread.h (struct thread_control_state) <stepping_command>:
New field.
* infcmd.c (step_once): Pass step=1 to clear_proceed_status.  Set
the thread's stepping_command field.
* infrun.c (resume): Check the thread's stepping_command flag to
determine which threads should be resumed.  Rename 'entry_step'
local to user_step.
(clear_proceed_status_thread): Clear 'stepping_command'.
(schedlock_applies): Change parameter type to struct thread_info
pointer.  Adjust.
(find_thread_needs_step_over): Remove 'step' parameter.  Adjust.
(switch_back_to_stepped_thread): Adjust calls to
'schedlock_applies'.
(_initialize_infrun): Adjust "set scheduler-locking step" help.

gdb/testsuite/ChangeLog:
2015-03-24  Pedro Alves  <palves@redhat.com>

* gdb.threads/schedlock.exp (test_step): No longer expect that
"set scheduler-locking step" with "next" over a function call runs
threads unlocked.

gdb/doc/ChangeLog:
2015-03-24  Pedro Alves  <palves@redhat.com>

* gdb.texinfo (test_step) <set scheduler-locking step>: No longer
mention that threads may sometimes run unlocked.

gdb/ChangeLog
gdb/doc/ChangeLog
gdb/doc/gdb.texinfo
gdb/gdbthread.h
gdb/infcmd.c
gdb/infrun.c
gdb/testsuite/ChangeLog
gdb/testsuite/gdb.threads/schedlock.exp

index d131d9acef420870e7d075629a66ba01fb9ab0b1..3695bb39a5a58d9d968c19429acb90bcc7b71aab 100644 (file)
@@ -1,3 +1,20 @@
+2015-03-24  Pedro Alves  <palves@redhat.com>
+
+       * gdbthread.h (struct thread_control_state) <stepping_command>:
+       New field.
+       * infcmd.c (step_once): Pass step=1 to clear_proceed_status.  Set
+       the thread's stepping_command field.
+       * infrun.c (resume): Check the thread's stepping_command flag to
+       determine which threads should be resumed.  Rename 'entry_step'
+       local to user_step.
+       (clear_proceed_status_thread): Clear 'stepping_command'.
+       (schedlock_applies): Change parameter type to struct thread_info
+       pointer.  Adjust.
+       (find_thread_needs_step_over): Remove 'step' parameter.  Adjust.
+       (switch_back_to_stepped_thread): Adjust calls to
+       'schedlock_applies'.
+       (_initialize_infrun): Adjust "set scheduler-locking step" help.
+
 2015-03-24  Pedro Alves  <palves@redhat.com>
 
        * infrun.c (step_start_function): Delete and ...
index b41c5cb3058e01c07efed25468fbeb4fabe9ef74..30d5a5b199dded499c3a6d190e47219e7ef13830 100644 (file)
@@ -1,3 +1,8 @@
+2015-03-24  Pedro Alves  <palves@redhat.com>
+
+       * gdb.texinfo (test_step) <set scheduler-locking step>: No longer
+       mention that threads may sometimes run unlocked.
+
 2015-03-23  Yurij Grechishhev  <yurij.grechishhev@gmail.com>
 
        * gdb.texinfo (Remote configuration): Document "set/show
index 7117e42c38e55de25b689f74fa324d8766fa25ce..c03ecb0260ce58a5a2f24b5e4314ec78940fee61 100644 (file)
@@ -5846,9 +5846,8 @@ current thread may run when the inferior is resumed.  The @code{step}
 mode optimizes for single-stepping; it prevents other threads 
 from preempting the current thread while you are stepping, so that 
 the focus of debugging does not change unexpectedly.
-Other threads only rarely (or never) get a chance to run
-when you step.  They are more likely to run when you @samp{next} over a
-function call, and they are completely free to run when you use commands
+Other threads never get a chance to run when you step, and they are
+completely free to run when you use commands
 like @samp{continue}, @samp{until}, or @samp{finish}.  However, unless another
 thread hits a breakpoint during its timeslice, @value{GDBN} does not change
 the current thread away from the thread that you are debugging.
index ce4f76f7b7fa8ec7fb5671bd13c7a8ec1fc9d840..bb15717b4146fd8a2201b08c7798fe5786491468 100644 (file)
@@ -138,6 +138,11 @@ struct thread_control_state
      thread was resumed as a result of a command applied to some other
      thread (e.g., "next" with scheduler-locking off).  */
   struct interp *command_interp;
+
+  /* Whether the command that started the thread was a stepping
+     command.  This is used to decide whether "set scheduler-locking
+     step" behaves like "on" or "off".  */
+  int stepping_command;
 };
 
 /* Inferior thread specific part of `struct infcall_suspend_state'.
index 0211b5d05585254c2dc12f1b7d5eaad841a07e02..eddbbff5910baaccd7b3ddb4efdaddab982699ac 100644 (file)
@@ -1047,7 +1047,7 @@ step_once (int skip_subroutines, int single_inst, int count, int thread)
         THREAD is set.  */
       struct thread_info *tp = inferior_thread ();
 
-      clear_proceed_status (!skip_subroutines);
+      clear_proceed_status (1);
       set_step_frame ();
 
       if (!single_inst)
@@ -1121,6 +1121,7 @@ step_once (int skip_subroutines, int single_inst, int count, int thread)
        tp->control.step_over_calls = STEP_OVER_ALL;
 
       tp->step_multi = (count > 1);
+      tp->control.stepping_command = 1;
       proceed ((CORE_ADDR) -1, GDB_SIGNAL_DEFAULT, 1);
 
       /* For async targets, register a continuation to do any
index be1cc748b1a96bf989abb590ba08525006ffc281..a8c3cce7aaeec1b453b931af95905d4a39ca5de1 100644 (file)
@@ -2038,7 +2038,6 @@ user_visible_resume_ptid (int step)
    we get a SIGINT random_signal, but for remote debugging and perhaps
    other targets, that's not true).
 
-   STEP nonzero if we should step (zero to continue instead).
    SIG is the signal to give the inferior (zero for none).  */
 void
 resume (int step, enum gdb_signal sig)
@@ -2050,13 +2049,10 @@ resume (int step, enum gdb_signal sig)
   CORE_ADDR pc = regcache_read_pc (regcache);
   struct address_space *aspace = get_regcache_aspace (regcache);
   ptid_t resume_ptid;
-  /* From here on, this represents the caller's step vs continue
-     request, while STEP represents what we'll actually request the
-     target to do.  STEP can decay from a step to a continue, if e.g.,
-     we need to implement single-stepping with breakpoints (software
-     single-step).  When deciding whether "set scheduler-locking step"
-     applies, it's the callers intention that counts.  */
-  const int entry_step = step;
+  /* This represents the user's step vs continue request.  When
+     deciding whether "set scheduler-locking step" applies, it's the
+     user's intention that counts.  */
+  const int user_step = tp->control.stepping_command;
 
   tp->stepped_breakpoint = 0;
 
@@ -2165,7 +2161,7 @@ resume (int step, enum gdb_signal sig)
              target_pass_signals ((int) GDB_SIGNAL_LAST, signal_pass);
              /* ... and safe to let other threads run, according to
                 schedlock.  */
-             resume_ptid = user_visible_resume_ptid (entry_step);
+             resume_ptid = user_visible_resume_ptid (user_step);
              target_resume (resume_ptid, 0, GDB_SIGNAL_0);
              discard_cleanups (old_cleanups);
              return;
@@ -2207,7 +2203,7 @@ resume (int step, enum gdb_signal sig)
             Unless we're calling an inferior function, as in that
             case we pretend the inferior doesn't run at all.  */
          if (!tp->control.in_infcall)
-           set_running (user_visible_resume_ptid (entry_step), 1);
+           set_running (user_visible_resume_ptid (user_step), 1);
          discard_cleanups (old_cleanups);
          return;
        }
@@ -2280,7 +2276,7 @@ resume (int step, enum gdb_signal sig)
   /* Decide the set of threads to ask the target to resume.  Start
      by assuming everything will be resumed, than narrow the set
      by applying increasingly restricting conditions.  */
-  resume_ptid = user_visible_resume_ptid (entry_step);
+  resume_ptid = user_visible_resume_ptid (user_step);
 
   /* Even if RESUME_PTID is a wildcard, and we end up resuming less
      (e.g., we might need to step over a breakpoint), from the
@@ -2413,6 +2409,7 @@ clear_proceed_status_thread (struct thread_info *tp)
   tp->control.proceed_to_finish = 0;
 
   tp->control.command_interp = NULL;
+  tp->control.stepping_command = 0;
 
   /* Discard any remaining commands or status from previous stop.  */
   bpstat_clear (&tp->control.stop_bpstat);
@@ -2492,21 +2489,19 @@ thread_still_needs_step_over (struct thread_info *tp)
    we're about to do a step/next-like command to a thread.  */
 
 static int
-schedlock_applies (int step)
+schedlock_applies (struct thread_info *tp)
 {
   return (scheduler_mode == schedlock_on
          || (scheduler_mode == schedlock_step
-             && step));
+             && tp->control.stepping_command));
 }
 
 /* Look a thread other than EXCEPT that has previously reported a
    breakpoint event, and thus needs a step-over in order to make
-   progress.  Returns NULL is none is found.  STEP indicates whether
-   we're about to step the current thread, in order to decide whether
-   "set scheduler-locking step" applies.  */
+   progress.  Returns NULL is none is found.  */
 
 static struct thread_info *
-find_thread_needs_step_over (int step, struct thread_info *except)
+find_thread_needs_step_over (struct thread_info *except)
 {
   struct thread_info *tp, *current;
 
@@ -2517,7 +2512,7 @@ find_thread_needs_step_over (int step, struct thread_info *except)
 
   /* If scheduler locking applies, we can avoid iterating over all
      threads.  */
-  if (schedlock_applies (step))
+  if (schedlock_applies (except))
     {
       if (except != current
          && thread_still_needs_step_over (current))
@@ -2652,7 +2647,7 @@ proceed (CORE_ADDR addr, enum gdb_signal siggnal, int step)
 
         Look for a thread other than the current (TP) that reported a
         breakpoint hit and hasn't been resumed yet since.  */
-      step_over = find_thread_needs_step_over (step, tp);
+      step_over = find_thread_needs_step_over (tp);
       if (step_over != NULL)
        {
          if (debug_infrun)
@@ -5592,7 +5587,7 @@ switch_back_to_stepped_thread (struct execution_control_state *ecs)
         current thread is stepping.  If some other thread not the
         event thread is stepping, then it must be that scheduler
         locking is not in effect.  */
-      if (schedlock_applies (0))
+      if (schedlock_applies (ecs->event_thread))
        return 0;
 
       /* Look for the stepping/nexting thread, and check if any other
@@ -5628,7 +5623,7 @@ switch_back_to_stepped_thread (struct execution_control_state *ecs)
                 stepping, then scheduler locking can't be in effect,
                 otherwise we wouldn't have resumed the current event
                 thread in the first place.  */
-             gdb_assert (!schedlock_applies (currently_stepping (tp)));
+             gdb_assert (!schedlock_applies (tp));
 
              stepping_thread = tp;
            }
@@ -7875,9 +7870,8 @@ Set mode for locking scheduler during execution."), _("\
 Show mode for locking scheduler during execution."), _("\
 off  == no locking (threads may preempt at any time)\n\
 on   == full locking (no thread except the current thread may run)\n\
-step == scheduler locked during every single-step operation.\n\
-       In this mode, no other thread may run during a step command.\n\
-       Other threads may run while stepping over a function call ('next')."), 
+step == scheduler locked during stepping commands (step, next, stepi, nexti).\n\
+       In this mode, other threads may run during other commands."),
                        set_schedlock_func,     /* traps on target vector */
                        show_scheduler_mode,
                        &setlist, &showlist);
index 12865424589471c6fddd30bc7f2ed91fefe426a5..824d6fc54bb1fd9f27e7221c4f41833445b3bda3 100644 (file)
@@ -1,3 +1,9 @@
+2015-03-24  Pedro Alves  <palves@redhat.com>
+
+       * gdb.threads/schedlock.exp (test_step): No longer expect that
+       "set scheduler-locking step" with "next" over a function call runs
+       threads unlocked.
+
 2015-03-24  Antoine Tremblay  <antoine.tremblay@ericsson.com>
 
        * gdb.mi/mi-pending.exp: Fix output of breakpoint test.
index b47af77917404911f6aef5716bdc8f771da390e1..54e847efda8f23b4e9d6061219bd9eab0b760d23 100644 (file)
@@ -285,8 +285,7 @@ proc test_step { schedlock cmd call_function } {
 
     step_ten_loops $cmd
 
-    # "next" lets other threads run while stepping over functions.
-    if { $schedlock == "on" || ($schedlock == "step" && !$call_function) } {
+    if { $schedlock == "on" || $schedlock == "step" } {
        set locked 1
     } else {
        set locked 0
@@ -302,10 +301,10 @@ foreach schedlock {"off" "step" "on"} {
            test_step $schedlock "step" 0
        }
        with_test_prefix "cmd=next" {
-           # With "next", and schedlock "step", threads run unlocked
-           # when stepping over a function call.  This exercises both
-           # with and without a function call.  Without a function
-           # call "next" should behave just like "step".
+           # In GDB <= 7.9, with schedlock "step", "next" would
+           # unlock threads when stepping over a function call.  This
+           # exercises "next" with and without a function call.  WRT
+           # "schedlock step", "next" should behave just like "step".
            foreach call_function {0 1} {
                with_test_prefix "call_function=$call_function" {
                    test_step $schedlock "next" $call_function