gdb, gdbserver: split iterate_over_lwps into for_each_lwp and find_lwp

Even though it works, I have always been mildly annoyed by
iterate_over_lwps being used for both iterating over all lwps and
finding one lwp matching a criterion.  I think it would be clearer to
have two functions for the two use cases.  Then it would be 100% clear
at the call site what the intention is.  It would be clear that a
callback returning bool is meant to be a predicate for the find
function, while a callback returning void is meant to be a callback for
the "for each" function.

Therefore, split iterate_over_lwps in two:

 - find_lwp to find the first lwp matching a boolean predicate (and the
   given ptid filter)
 - for_each_lwp to apply a function on all lwps (optionally filtering by
   ptid or pid)

The callbacks given to for_each_lwp can now return void.

Introduce some overloads for for_each_lwp, for the various common use
cases:

 - filtering by ptid
 - filtering by pid
 - no ptid/pid filter

find_lwp and two overloads of for_each_lwp are actually only used in
gdb/linux-nat.c, so make them local to that file.  Only the pid variant
of for_each_lwp is used in shared code.

The pattern used in this patch serves as the basis for subsequent
patches that split other "iterate over" functions the same way.

Change-Id: I49d3af0916622300cc81e3c32d22e1aff13cf38f
Approved-By: Andrew Burgess <aburgess@redhat.com>
9 files changed