gdb/ChangeLog 2015-01-15 Jan Kratochvil * thread.c (tp_array_compar): New function. (thread_apply_all_command): Sort tp_array using it. diff --git a/gdb/thread.c b/gdb/thread.c index ed20fbe..cdab5d8 100644 --- a/gdb/thread.c +++ b/gdb/thread.c @@ -1382,6 +1382,17 @@ make_cleanup_restore_current_thread (void) restore_current_thread_cleanup_dtor); } +/* Sort an array for struct thread_info pointers by their ascending NUM. */ + +static int +tp_array_compar (const void *ap_voidp, const void *bp_voidp) +{ + const struct thread_info *const *ap = ap_voidp; + const struct thread_info *const *bp = bp_voidp; + + return ((*ap)->num > (*bp)->num) - ((*ap)->num < (*bp)->num); +} + /* Apply a GDB command to a list of threads. List syntax is a whitespace seperated list of numbers, or ranges, or the keyword `all'. Ranges consist of two numbers seperated by a hyphen. Examples: @@ -1431,6 +1442,8 @@ thread_apply_all_command (char *cmd, int from_tty) i++; } + qsort (tp_array, i, sizeof (*tp_array), tp_array_compar); + make_cleanup (set_thread_refcount, &ta_cleanup); for (k = 0; k != i; k++)