Remove code for old, undocumented, and most likely broken, John Metzler RSP thread protocol
target_find_new_threads -> target_update_thread_list

Eliminate all the silly "thread alive" RSP traffic (one packet per
thread...) whenever we fetch the thread list.
Implement all-stop on top of a target running non-stop mode

This implements all-stop on top of a target running in non-stop mode.
From the user's perspective, the all-stop mode is really just a
special case of being able to stop and resume specific sets of
threads, so it makes sense to do this step first.

This starts by adding a new target method "target_is_non_stop_p",
where targets that can do non-stop can always return true, even if
"set non-stop" is off.  With this, even in all-stop, the target is no
longer in charge of stopping all threads before reporting an event to
the core -- the core takes care of it when it sees fit.  For example,
when "next"- or "step"-ing, we can avoid stopping and resuming every
thread at each internal single-step, but instead stop all threads when
we're about to present the stop to the user.  While developing this, I
progressed in stages.  First I made wait_for_inferior stop all threads
right after the target returning an event, as that's the least
invasive change.  When I got that regression free, I added the
`stop_only_if_needed' global, which when true, means what I mentioned
above -- we only stop all threads when stop_stepping is called, which
means we're reporting an event to the user.  This flag will probably
go away at a later stage.

This forces always-inserted on for such targets that can always do
non-stop.  I think it would make sense to make the "breakpoint
always-inserted" auto mode actually remove breakpoints from the
inferior when all is stopped.  That way, we'd get the classic
behavior, that is a bit safer in that is avoids leaving breakpoints
planted on the target if gdb crashes in most cases, but, it'd also
leave breakpoints always inserted whenever there's a chance a thread
is running.  That'd get us the best of both worlds.


This is in need of a bit of cleanup and commenting throughout.  The
logic around target_pass_signals in do_target_resume may need a bit
more care.  Particularly after the later patch in the series that adds
itsets support to execution commands (apply_execution_command).  All
other !ptrace && !remote targets will need adjustment similar to
inf_ptrace_attach.


v2:

- fixes a bunch of regressions.

 I had the "force target-async on" patch after this one in the
 previous iteration, so I had been testing this patch in a weird mode
 with non-stop mode on, and with async off...  When I reversed the
 patches order, a bunch of problems appeared.

gdb/
2011-11-16  Pedro Alves  <pedro@codesourcery.com>

	* breakpoint.c (breakpoints_always_inserted_mode): Check
	target_is_non_stop_p instead of non_stop.
	(update_global_location_list): Ditto.
	* gdbthread.h (ALL_THREADS, ALL_LIVE_THREADS): New.
	(thread_list): Declare.
	(struct thread_control_state): New field `resumed'.
	(struct thread_suspend_state): New fields `waitstatus' and
	`waitstatus_pending_p'.
	* inf-ptrace.c (inf_ptrace_attach): Set the main thread's resumed
	flag.
	* infcall.c (run_inferior_call): Set the thread's state to
	THREAD_STOPPED while calling clear_proceed_status.
	* infrun.c: Include event-loop.h.
	(infrun_async_inferior_event_token): New global.
	(use_displaced_stepping): Check target_is_non_stop_p instead of
	non_stop.
	(displaced_step_fixup): Change return type to int.  Factor out
	bits into ...
	(displaced_step_next): ... this.  Use do_target_resume.
	(queued_for_displaced_step): New.
	(do_target_resume): New.
	(resume): Return early is the thread has a pending status.  Resume
	all threads if placed in the displaced stepping queue.  Use
	do_target_resume.
	(clear_proceed_status_thread): Bail out if the thread is running.
	(print_target_wait_results): Print the whole ptid.
	(do_target_wait): New.
	(prepare_for_detach): Use do_target_wait.
	(cancel_breakpoints): New.
	(set_executing_from_state): New.
	(stop_only_if_needed): New global.
	(select_event_thread): New.
	(wait_for_inferior): Use do_target_wait.  Call
	set_executing_from_state.  Add the event thread to the thread list
	if not already there.  Stop all threads and select the event
	thread.
	(fetch_inferior_event): Ditto.
	(adjust_pc_after_break): Change prototype.  Use
	target_is_non_stop_p.  Return an indication of whether adjustment
	was necessary.
	(wait_one): New.
	(stop_all_threads): New.
	(handle_inferior_event): Adjust to interface changes.  Use
	target_is_non_stop.
	(stop_stepping): Stop all threads if necessary.
	(keep_going): Stop all threads if starting a step-over.
	(infrun_async_inferior_event_handler): New.
	(_initialize_infrun): Install event source in the event-loop.
	* linux-nat.c (get_pending_status, linux_nat_detach): Use
	target_is_non_stop_p.
	(linux_handle_extended_wait): Set the resumed flag of the new lwp.
	Use target_is_non_stop_p.
	(linux_nat_wait_1, linux_nat_wait): Use target_is_non_stop_p.
	(linux_nat_is_non_stop_p): New.
	(linux_nat_stop): Use target_is_non_stop_p.
	(linux_nat_add_target): Install linux_nat_is_non_stop_p.
	* remote.c (remote_start_remote, extended_remote_attach_1): Set
	the resumed flag of the main thread.
	* target.c (update_current_target): INHERIT and de_fault
	to_is_non_stop_p.
	(target_wait): Return TARGET_WAITKIND_NO_RESUMED by default.
	* target.h (struct target_ops) <to_is_non_stop_p>: New field.
	(target_is_non_stop_p): New.
	* thread.c (thread_list): Make extern.
	(new_thread): Clear the suspend.waitstatus.kind field.
Add base itsets support

This adds the base itsets support.  v2 implements some of the ideas
mentioned in the v1 posts.  Particularly, it drifts the spec syntax
away from HPD.  All kinds of objects you can specify on a spec have
the same weight.  Object types have a prefix letter followed by a id
or id range.  `i' for inferior, `t' for thread, `a' for Ada task, `c'
for core, and others may be added latter (e.g., process or target
thread id).  `.' is the intersection operator.  `,' is the union
operator.  `,' (union) has precedence over `.' (intersect).  `(' and
`)' can be used in the natural way to defeat precedence.  `~' is the
negating operator.  `!' specifies a static set.  Sets are dynamic by
default.  `$' represents the current focus set.

This allows for example using just "c1" to mean "everything on core
1"; "foobar.c2" (or c2.foobar) to mean "all threads in the foobar
group that are in core 2"; "workers.~(i2,i3)" to mean all workers not
in inferior 2 or 3.

The current syntax follows this grammar:

  ELEM = RANGE | NEG | PARENS_SET | '$' | NAME
  NEG = '~' ELEM
  PARENS_SET = '(' ITSET_ONE ')'
  INTERS = ELEM ('.' ELEM)*
  ITSET_ONE = INTERS (',' INTERS)*
  ITSET = | ('!' ITSET_ONE) | ITSET_ONE

  E.g.,:

  c1-3.~i1.(t1,other),foo is transformed to a tree like:

   UNION
     foo
     INTERS
       c1-3
       NEG
         i1-1
       UNION
         t1-1
	 other

Currently:

 - Supports user-specified named sets, and built-in sets.  The
   built-in sets are currently: all (all threads, all inferiors);
   running (set of running threads); stopped (set of stopped threads);
   curinf (the current inferior); empty (the empty set); $ (the
   current focus set); and a special exec(FILENAME) set, that takes a
   program file name (exec) as argument, to match all inferiors
   running a given program.

 - An "itfocus" command.  This serves two related purposes.  If passed
   an I/T set and nothing else, as in `itfocus SET', e.g.,

     (gdb) itfocus i2

   it sets the current focus to SET.  In this example, the focus was
   set to inferior 2.

   If in addition, a command is passed after the SET, as in,
   `itfocus SET CMD`, then CMD is executed with the current focus
   switched to SET temporarily.  E.g.,

     (gdb) itfocus i3 break foo

   the breakpoint is set on inferior 3.  This is the same as:

     (gdb) itfocus i3
     (gdb) break foo
     (gdb) itfocus what_ever_was_the_current_set_before

 - a "defset" command.  This is used to define named itsets.  E.g.,

     (gdb) defset firstthree t1-3

   defines the set `firstthree', as being the threads 1, 2 and 3.  You
   can then use the set wherever an itset is allowed.  E.g., with a
   later patch, you'll be able to interrupt all threads in a specific
   set with:

     (gdb) interrupt -p firstthree

 - an "undefset" command.  Used to undefine a set defined by itset.
   "undefset -all" undefines all user-defined named sets.

 - an "info itsets" command.  Lists all named sets, in GDB "info"
   style.

 - A "whichsets" command.  This shows which sets does a thread belong
   to.

 - A "viewset" command.  This shows which inferiors and threads are
   included in a specified itset.  It's the reverse of "whichsets".

The current default current set is this patch is `all'.  I'm thinking
it may make sense to default to `curinf' instead, and thus get rid of
"set schedule-multiple" (see the patch about execution commands
further in the series).

Examples:

all> defset test t1,t2
all> info threads
  Id   Target Id         Frame
  3    Thread 0x7ffff7028700 (LWP 6128) "threads" 0x00007ffff7bcc78e in __lll_lock_wait_private () from /lib/x86_64-linux-gnu/libpthread.so.0
* 2    Thread 0x7ffff7829700 (LWP 6127) "threads" thread_function0 (arg=0x0) at threads.c:63
  1    Thread 0x7ffff7fcb720 (LWP 6124) "threads" 0x00007ffff7910011 in clone () from /lib/x86_64-linux-gnu/libc.so.6
all> info itsets
Num     Name           What
1       test           t1,t2
all> viewset test
test contains:
  inferiors: 1
  threads: 2, 1
  cores: 5, 0
all> whichsets t1
i1.t1 (Thread 0x7ffff7fcb720 (LWP 6124)) is in: all, stopped, curinf, test
all> undefset test


I haven't had much chance yet of playing with the syntax and think of
many real use cases; I'm sure there are holes to fill.  Perhaps we may
even find out this syntax doesn't work, though it looks promising to
me.


v2:

  - Dropped [] everywhere; forbids spaces in specs.
  - Replaced the [] prefix command the "itfocus" command taking an
    optional command to execute.
  - object types in spec require prefix letter.
  - Parsing rewritten as a simple recursing descent parser.  ()'s
    support for grouping added.
  - Added `empty' and `$' sets.
  - Many cleanups and bugfixes.

2011-12-16  Pedro Alves  <pedro@codesourcery.com>
	    Tom Tromey  <tromey@redhat.com>

	* Makefile.in (SFILES): Add itset.c.
	(COMMON_OBS): Add itset.o.
	* gdbthread.h (get_thread_inferior): Declare.
	* thread.c (get_thread_inferior): New.
	* itset.h, itset.c: New.
Expand %ITSET% and %THREAD% in the prompt

This adds a simple prompt hook that expands "%ITSET%" to the current
set, and "%THREAD%" to the current thread.  It was discussed in v1
that it would be better to reuse or follow the syntax of "set
extended-prompt".

Here's how I use it currently:

$ gdb -q -nx -ex "set prompt %ITSET%;%THREAD%> " ~/gdb/tests/threads
all;i1.t2> info threads
  Id   Target Id         Frame
  3    Thread 0x7ffff7028700 (LWP 31058) "threads" __lll_lock_wait_private () at ../nptl/sysdeps/unix/sysv/linux/x86_64/lowlevellock.S:97
* 2    Thread 0x7ffff7829700 (LWP 31057) "threads" thread_function0 (arg=0x0) at threads.c:63
  1    Thread 0x7ffff7fcb720 (LWP 31053) "threads" clone () at ../sysdeps/unix/sysv/linux/x86_64/clone.S:84
all;i1.t2>
all;i1.t2> itfocus i1
warning: 3 threads for inferior 1 in the current i/t set, switching to first
Current inferior is 1.
i1;i1.t3>

This was just a quick hack to make it easy to work on the rest of the
stuff without getting lost.  I'll make use of this in all examples in
this series.

v2:

 - also expand %THREAD%.
I/T set support for breakpoints - trigger set, and stop set

This adds support for setting a breakpoint that only triggers on a
given set (a superset of the current thread specific breakpoints
support).  In addition, it adds support for specifying the set of
threads that are suspended when the breakpoint is triggered.

Breakpoints need two sets.  The trigger set, which is a generalization
of the "break foo thread N", meaning the set of inferiors/threads
where the breakpoint should fire, and, a suspend/stop set, which is
the set of inferiors/threads that should be suspended when the
breakpoint fires.

The trigger set of breakpoints is set from the current set at the time
the breakpoint is created.  The stop set is passed explicitly as
optional switch.  E.g.,:

 [itfocus TRIGGER-SET] break [-stop STOP-SET] LINESPEC

This leaves LINESPEC last, so that we can keep supporting the current
form, but avoid more hacks in linespecs like the special termination
for "thread/task/if" in the lexers.

So the old:

 (gdb) break LINESPEC

still works just the same.  The breakpoint's trigger set will be
inferred from the current set as set or temporarily overriden by
itfocus.  The stop set, if not specified, is inferred from the "set
non-stop" global option.  If non-stop is on, only the thread that
triggers the breakpoint should be suspended; if non-stop is off, then
all threads in the current focus will be suspended when the breakpoint
fires.  The thread that fired the breakpoint always remains stopped,
nomatter the stop set.

E.g.,

(gdb) info threads
  Id   Target Id         Frame
  3    Thread 0x7ffff7028700 (LWP 2296) "threads" (running)
* 2    Thread 0x7ffff7829700 (LWP 2295) "threads" thread_function0 (arg=0x0) at threads.c:63
  1    Thread 0x7ffff7fcb720 (LWP 2290) "threads" (running)
(gdb) itfocus t2 break -stop t3 63
Breakpoint 4 at 0x40076d: file threads.c, line 63.

Breakpoint 4 triggers on thread 2 (equivalent to break 63 thread 2),
and when the breakpoint fires, thread 3 is suspended.  Like so:

(gdb) c -a&
Continuing.
(gdb)
Breakpoint 4, thread_function0 (arg=0x0) at threads.c:63
63              (*myp) ++;
info threads
  Id   Target Id         Frame
  3    Thread 0x7ffff7028700 (LWP 2296) "threads" 0x00007ffff78d75ad in nanosleep () from /lib/x86_64-linux-gnu/libc.so.6
* 2    Thread 0x7ffff7829700 (LWP 2295) "threads" thread_function0 (arg=0x0) at threads.c:63
  1    Thread 0x7ffff7fcb720 (LWP 2290) "threads" (running)

(gdb) info breakpoints
Num     Type           Disp Enb Address            What
4       breakpoint     keep y   0x000000000040076d in thread_function0 at threads.c:63
        stop only in trigger-set: t2
        suspend all in stop-set: t3
        breakpoint already hit 1 time

We can make a breakpoint that stops the world with (recall I had
non-stop on):

(gdb) del 4
(gdb) itfocus t2 break -stop all 63
Breakpoint 5 at 0x40076d: file threads.c, line 63.
(gdb) c -a&
Continuing.
(gdb)
Breakpoint 5, thread_function0 (arg=0x0) at threads.c:63
63              (*myp) ++;
info threads
  Id   Target Id         Frame
  3    Thread 0x7ffff7028700 (LWP 2296) "threads" 0x00007ffff78d75ad in nanosleep () from /lib/x86_64-linux-gnu/libc.so.6
* 2    Thread 0x7ffff7829700 (LWP 2295) "threads" thread_function0 (arg=0x0) at threads.c:63
  1    Thread 0x7ffff7fcb720 (LWP 2290) "threads" 0x00007ffff7bc606d in pthread_join () from /lib/x86_64-linux-gnu/libpthread.so.0

Since all-stop was reimplemented on top of the target running in
non-stop mode, when "set non-stop" is off, not specifying a stop set
(or specifying it as empty, like -stop empty) means that all threads
stop by default, e.g., `itfocus t2 break 63', but you can still
override that explicitly by specifying "-stop SET", so the breakpoint
only forces suspension of a given itset, with:

(gdb) itfocus t2 break -stop t3 63
Breakpoint 5 at 0x40076d: file threads.c, line 63.
(gdb) c &
Continuing.
(gdb)
Breakpoint 5, thread_function0 (arg=0x0) at threads.c:63
63              (*myp) ++;
info threads
  Id   Target Id         Frame
  3    Thread 0x7ffff7028700 (LWP 2645) "threads" 0x00007ffff78d75ad in nanosleep () from /lib/x86_64-linux-gnu/libc.so.6
* 2    Thread 0x7ffff7829700 (LWP 2644) "threads" thread_function0 (arg=0x0) at threads.c:63
  1    Thread 0x7ffff7fcb720 (LWP 2610) "threads" (running)


v2:

 - Adjusted to new itset spec syntax.
 - All breakpoint-ish commands adjusted to accept "-stop", and handle
   the trigger and stop sets.
 - The stop set when multiple breakpoints are hit is the union of the
   stop sets of all the breakpoints that caused the stop.
 - Some cleanup, some bugfixes, some hacks removed.


2011-12-16  Pedro Alves  <pedro@codesourcery.com>

	* ada-lang.c: Include itset.h.
	(create_ada_exception_catchpoint): Add trigger_set and stop_set
	parameters.  Adjust.
	(catch_ada_exception_command, catch_assert_command): Parse
	`-stop', and pass down trigger and stop sets.
	* breakpoint.c: Include itset.h.
	(bpstat_check_trigger_set): New.
	(breakpoint_thread_match): Handle the trigger set.
	(bpstat_check_breakpoint_conditions): Handle the trigger set.
	(bpstat_stop_set): New.
	(print_one_breakpoint_location): Print the trigger and stop sets.
	(init_raw_breakpoint_without_location): Initialize new fields.
	(init_catchpoint, create_fork_vfork_event_catchpoint)
	(create_syscall_event_catchpoint, init_breakpoint_sal)
	(create_breakpoint_sal): Add trigger_set and stop_set parameters.
	Adjust.
	(parse_breakpoint_sals): Handle pointer to pointer to empty string
	as no arg.
	(parse_breakpoint_args): New.
	(create_breakpoint, watch_command_1, catch_fork_command_1)
	(catch_exec_command_1): Parse `-stop', and pass down trigger and
	stop sets.
	(init_ada_exception_breakpoint): Add trigger_set and stop_set
	parameters.  Adjust.
	(catch_syscall_command_1): Parse `-stop', and pass down trigger
	and stop sets.
	(base_breakpoint_dtor): Free the trigger and stop sets.
	* breakpoint.h (struct itset): Forward declare.
	(struct breakpoint) <trigger_set, stop_set>: New fields.
	(bpstat_stop_set): Declare.
	(init_ada_exception_breakpoint): Adjust.
	* infcall.c (call_function_by_hand): Set the breakpoint's trigger
	and stop sets.
	* infrun.c: Include itset.h.
	(struct execution_control_state) <stop_set>: New field.
	(ecs_destroy, ecs_destroy_cleanup): New.
	(infrun_thread_stop_requested_callback): Destroy ecs.
	(select_event_thread): Adjust.
	(wait_for_inferior, fetch_inferior_event): Destroy ecs.
	(stop_set_match): New.
	(stop_all_threads): New parameter `stop_set'.  Stop only stops in
	the specified stop set.
	(handle_inferior_event): Set the stop set from the bpstat's stop
	set.
	(stop_stepping): If there's no stop set in the ecs, infer from
	non_stop setting.  Only clear the resumed flag of threads in the
	stop set.
	(keep_going): Adjust.
Add I/T set support to most execution commands

This adds I/T set support to most execution commands.  For execution
commands, there are actually two sets in effect:

- The "apply set":

This is the set of threads the execution command is applied to.  For
example, for "step", the apply set is the set of threads that will be
stepped; for "finish", the apply set is the set of threads that will
the finished.

- The "run free set":

This is the set of threads that is allowed to run free while the
execution command is applied to the all threads in the "apply set".
The run free set is derived from the current set (either as set by
itfocus, or by using itfocus as prefix command), and to remain
backwards compatible, from "set scheduler-locking on/step", "set
schedule-multiple" and "set non-stop on" too.  Example, if the current
set is `all' (all threads), by default the run free set is the `all'
set too.  But if either scheduler-locking is on/step or "set non-stop"
is on, the run free set is set to the empty set, meaning no thread is
let run free.

With these two sets, a user that is not aware of GDBs new
capabilities, does not notice any user interface change.  For example,
by default, "(gdb) step" will still step the current thread, and let
all other threads in the current inferior run free.

The pointer them comes from being able to override these new sets to
do more complicated commands.

For example, making use of the %ITSET% prompt substitution patch,

$ gdb -ex "set prompt %ITSET%> " ~/gdb/tests/threads
[all]> start
Temporary breakpoint 1 at 0x40068c: file threads.c, line 35.
Starting program: /home/pedro/gdb/tests/threads
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib/x86_64-linux-gnu/libthread_db.so.1".

Temporary breakpoint 1,
main () at threads.c:35
35          long i = 0;
all> info threads
  Id   Target Id         Frame
  3    Thread 0x7ffff7028700 (LWP 22403) "threads" 0x00007ffff7bcc78e in __lll_lock_wait_private () from /lib/x86_64-linux-gnu/libpthread.so.0
* 2    Thread 0x7ffff7829700 (LWP 22402) "threads" thread_function0 (arg=0x0) at threads.c:63
  1    Thread 0x7ffff7fcb720 (LWP 22323) "threads" 0x00007ffff7910011 in clone () from /lib/x86_64-linux-gnu/libc.so.6
all> itfocus i1
warning: 3 threads for inferior 1 in the current i/t set, switching to first
Current inferior is 1.
i1> info threads
  Id   Target Id         Frame
* 3    Thread 0x7ffff7028700 (LWP 22403) "threads" 0x00007ffff7bcc78e in __lll_lock_wait_private () from /lib/x86_64-linux-gnu/libpthread.so.0
  2    Thread 0x7ffff7829700 (LWP 22402) "threads" thread_function0 (arg=0x0) at threads.c:63
  1    Thread 0x7ffff7fcb720 (LWP 22323) "threads" 0x00007ffff7910011 in clone () from /lib/x86_64-linux-gnu/libc.so.6
i1> step

This last "step" command steps thread 3 (the apply set, derived from
the selected thread), and, lets all other threads of inferior 1 run
free (derived from the current focus).

You can step more than one thread in parallel.  For that, you pass an
explicit apply set as argument to the execution command.  For example:

i1> step -p t1,t2

That steps threads 1 and 2, and lets all other threads in the current
focus run free.  Currently each of threads in the apply set steps
independently and unaware of other threads in the same apply set.
That is, say, thread 1 finishes stepping first, and we'll give back
the prompt to the user immediately, while thread 2 continues stepping
in the background (as if "thread 1; step&; thread 2; step&" had been
issued).  A later patch in the series will make all threasd in the the
apply set to finish what they were told to do before considering the
whole command done with (and giving the prompt back to the user, in
case of a foreground command).

If you want to step all threads in the current focus in parallel,
although you could, you don't need to spell out the current focus set
as the apply set explicitly as in

i1> step i1

Instead, you can pass the -a (from "all") flag to the execution
command, as in:

i1> step -a

That is, this makes the apply set be equal to the current set, thus
stepping all threads in parallel.  The "run free set" is still the
current set, but, naturally, there are no threads left to run free.

Note you can make use of the itfocus command as prefix command to
temporarily switch the current set, so you can for example have
defined a set named `workers', and then step them all with:

i1> itfocus workers step -a


Often you'll want to step only a given thread or set of threads, and
not let any other thread run free while stepping.  That is, run a step
as if "set scheduler-locking" was step or on.  You can do that already
with what I've presented above, with e.g.,

i1> itfocus t2 step -p t2

That is, set the current set temporarily to thread 2, and the apply
set is also set to thread 2.

Or, you may also do:

i1> itfocus empty step -p t2

That is, the focus is set temporarily to the empty set, and the apply
set is thread 2.

Or, you may also do:

i1> itfocus empty step

where the current set is set to the empty set, and the apply set is
derived from the current thread.  I've added yet a third option (-l,
from lock) to get the same explicit locking.  E.g., if the current
thread is thread 2, then these are equivalent:

t2> step
i1> itfocus t2 step
i1> itfocus empty step
i1> step -l

they all step thread 2, with scheduler locking on.

Lastly, it'd be useful to have a way to override the global "set
scheduler-locking on/step" or "set non-stop on" options.  That is done
with the "-c" (from current set) option.  Maybe that that instead be
"-u" for unlocked?

So this:

all> set scheduler-locking on
all> step

steps the currently selected thread, and doesn't let any other thread
run free.

And this:

all> set scheduler-locking on
all> step -c

steps the currently selected thread, and lets all threads in `all' run
free.  This is the equivalent of:

all> set scheduler-locking off
all> step
all> set scheduler-locking on

Lastly, all these switches are currently implemented in the following commands:

step, next, stepi, nexti, continue, until, jump, signal, finish and interrupt.


You'll note that several of the commands' implementations have split
in two passes - the first pass loops over all threads in the apply
set, validating if everything is okay to apply the command, thus
avoiding most cases of resuming thread 1..3, and then later throwing
an error resuming thread N.

A lot is yet missing:

 - It'd be great to be able to come up with a way to merge the run
   free sets and the apply sets, and the current thread/inferior, into
   a single concept, thus simplifying the interface, mostly for when
   wanting to parallel debug some threads (need to pass -p SET to all
   commands, which is a bit awkward if you alternate commands.  E.g.,
   step -p t2,t3; next -p t2,t3; step -p t2,t3; etc.).  Extending the
   "selected thread" concept to "selected set" would help (e.g., allow
   "thread SET" instead of just "thread N"., though I'm not sure
   that's a good idea.

 - This whole series is almost regression free, but not quite.
   There's a nasty bug somewhere that causes sometimes threads to
   report spurious SIGTRAPs.  Seems related to displaced stepping.
   Reveals itself more often in the manythreads.exp test.

 - make sure that we're not regressing against a target that doesn't
   support non-stop/async.  I haven't tried that yet.

 - MI support.

 - We're always resuming all threads individually.  This is not really
   a problem for native targets, but if you're debugging 1000 threads
   against the remote target, and you do a "s", we'll send 1
   vCont;sTID packet, plus 999 vCont;cTID packets, instead of a single
   vCont;sTID;c".  We could make remote_resume not really resume, but
   collect resume requests in a vector, and add a new
   target_apply_resume method that actually applies all pending resume
   requests, so we could compress the requests.  Native targets would
   still resume from within target_resume, and would implement
   target_apply_resume as doing nothing.  The trouble is in knowing
   whether the 999 continue requests do indeed map to "all threads",
   and so can be compressed.  vCont;c is not really the same as
   resuming all threads individually.  The former means that we'll get
   the pending events for threads we hadn't heard yet too.  This needs
   a bit more thought and experimentation.  I'm not sure I'll be able
   to get this far in this first round though, so I may end up leaving
   all this native only at first somehow.

 - Comments! Tests! Docs! Help!

 - Probably many other things I'm still not remembering.

v2:

  - Adjustment to new itset spec scheme.
  - Many bug fixes.  Fix testsuite regressions.
  - Adjust MI to preserve backwards compatibility.


2011-12-16  Pedro Alves  <pedro@codesourcery.com>

	* breakpoint.c (struct until_break_cmd_data, struct
	until_break_aec_callback_data): New.
	(itset_free_p): New.
	(until_break_command): Handle new command args.  Handle the apply
	and run free sets.
	(until_break_aec_callback): New.
	* gdbthread.h (struct thread_info) <reported_event, cmd_data>: New
	fields.
	* infcall.c (run_inferior_call): Handle the apply and run free
	sets.
	* infcmd.c: Include itset.h and cli/cli-utils.h.
	(current_thread_set): New.
	(apply_execution_command): New.
	(run_command_1): Use target_is_non_stop_p.
	(proceed_thread_callback): Access thread state directly.  Use
	clear_proceed_status_thread.
	(itset_free_p): New.
	(default_run_free_itset): New.
	(parse_execution_args): New.
	(continue_aec_callback): New.
	(continue_command): Handle new command args.  Handle the apply and
	run free sets.
	(struct step_1_args): New.
	(step_1_aec_callback): New.
	(ensure_runnable): New.
	(step_1): Handle new command args.  Handle the apply and run free
	sets.
	(step_1_1): Factored out from step_1.
	(struct step_1_continuation_args): Deleted.
	(step_1_continuation): Adjust.
	(struct jump_cmd_data): New.
	(struct jump_aec_callback_data): New.
	(jump_aec_callback): New.
	(jump_command): Handle new command args.  Handle the apply and run
	free sets.
	(struct signal_aec_callback_data): New.
	(signal_command): Handle new command args.  Handle the apply and
	run free sets.
	(signal_aec_callback): New.
	(until_next_command): New parameter `arg'.  Handle new command
	args.  Handle the apply and run free sets.
	(until_next_aec_callback): New.
	(advance_command): Handle new command args.  Handle the apply and
	run free sets.
	(struct finish_cmd_data, struct finish_aec_callback_data): New.
	(finish_command): Handle new command args.  Handle the apply and
	run free sets.
	(finish_aec_callback): New.
	(interrupt_target_1): Adjust to handle sets.
	(interrupt_target_command): Allow -a in all-stop.
	* inferior.h (clear_proceed_status_thread): Declare.
	(schedlock_off, schedlock_on, schedlock_step, scheduler_mode):
	Declare.
	* infrun.c (follow_fork): Split in two: follow_fork, and ...
	(prepare_to_follow_fork): ... this.
	(schedlock_off, schedlock_on, schedlock_step, scheduler_mode):
	Make extern.
	(user_visible_resume_ptid): Use target_is_non_stop_p.
	(do_target_resume): Make extern.  No longer resume all threads
	when placed in the displaced stepping queue.
	(clear_proceed_status_thread): Make extern.
	(clear_proceed_status): Use target_is_non_stop_p.
	(proceed): Adjust.  Use target_is_non_stop_p.
	(delete_step_thread_step_resume_breakpoint, prepare_for_detach):
	Use target_is_non_stop_p.
	(fetch_inferior_event): Always switch to the event thread.  Use
	target_is_non_stop_p.
	(handle_inferior_event): Clear event_thread when mourning.
	Adjust.  Use target_is_non_stop_p.
	(stop_stepping): Mark the even thread as having reported an event.
	* mi/mi-interp.c (mi_on_resume): Be backwards compatible.
	* thread.c (free_thread): Free cmd_data.

	gdb/testsuite/
	* gdb.base/jump.exp: Adjust.
Parallel steps, wait for all threads to reach their goal

Something I mentioned in previous patches.  This makes it so that with e.g.,

	(gdb) step -p t1,t2

	you only get the prompt back when both t1 and t2 finished
	stepping.

2011-12-16  Pedro Alves  <pedro@codesourcery.com>

	* breakpoint.c (until_break_command): Adjust.
	* gdbthread.h (struct itset): Forward declare.
	(struct thread_info) <apply_set, waiting_for_apply_set_siblings>:
	New fields.
	* infcmd.c (apply_execution_command): New parameter
	`want_parallel'.  Handle it.
	(continue_command, step_1, jump_command, signal_command)
	(until_next_command, finish_command): Adjust.
	* infrun.c (clear_proceed_status_thread): Clear the thread's apply
	set and waiting_for_apply_set_siblings flag.
	(all_in_apply_set_done_p): New.
	(handle_inferior_event): Check if there are other thread's in the
	even thread's apply set.  If so, wait for them to finish before
	considering the execution command done with.
Default the current itset to the current inferior set (curset).

This goes hand-in-hand with the next patch.  So far, we default to
"all".  And, the "set schedule-multiple" is "off" by default.  This
means, that in some cases that "all" isn't really "all", but the
inferior of the selected thread only.  This is confusing.

If by default we only focus on the current inferior, then we can flip
the schedule-multiple setting to on, meaning, resume all inferiors in
the focus, and so the schedule-multiple setting isn't really required
anymore.
Default "set schedule-multiple" to on

See description of previous patch.
Rename "itfocus" command to "scope".
Comment out new info breakpoints output, in order to not break the test suite