X-Git-Url: https://git.libre-soc.org/?a=blobdiff_plain;f=gdb%2Finferior.c;h=45b31419f4635b9eaef22d3ae8ae745fafba145e;hb=5357150c97899af2cc93072780a9c3a128c5b1ae;hp=2e44f175bb1442a438c536b55d5018d6c4b220fb;hpb=e3ae3c4345fa14f2f3b0b2c5d4d23760af9f74f5;p=binutils-gdb.git diff --git a/gdb/inferior.c b/gdb/inferior.c index 2e44f175bb1..45b31419f46 100644 --- a/gdb/inferior.c +++ b/gdb/inferior.c @@ -1,6 +1,6 @@ /* Multi-process control for GDB, the GNU debugger. - Copyright (C) 2008-2015 Free Software Foundation, Inc. + Copyright (C) 2008-2016 Free Software Foundation, Inc. This file is part of GDB. @@ -74,7 +74,7 @@ set_current_inferior (struct inferior *inf) static void restore_inferior (void *arg) { - struct inferior *saved_inferior = arg; + struct inferior *saved_inferior = (struct inferior *) arg; set_current_inferior (saved_inferior); } @@ -128,15 +128,24 @@ add_inferior_silent (int pid) { struct inferior *inf; - inf = xmalloc (sizeof (*inf)); + inf = XNEW (struct inferior); memset (inf, 0, sizeof (*inf)); inf->pid = pid; inf->control.stop_soon = NO_STOP_QUIETLY; inf->num = ++highest_inferior_num; - inf->next = inferior_list; - inferior_list = inf; + + if (inferior_list == NULL) + inferior_list = inf; + else + { + struct inferior *last; + + for (last = inferior_list; last->next != NULL; last = last->next) + ; + last->next = inf; + } inf->environment = make_environ (); init_environ (inf->environment); @@ -171,7 +180,8 @@ struct delete_thread_of_inferior_arg static int delete_thread_of_inferior (struct thread_info *tp, void *data) { - struct delete_thread_of_inferior_arg *arg = data; + struct delete_thread_of_inferior_arg *arg + = (struct delete_thread_of_inferior_arg *) data; if (ptid_get_pid (tp->ptid) == arg->pid) { @@ -449,22 +459,41 @@ have_inferiors (void) return 0; } +/* Return the number of live inferiors. We account for the case + where an inferior might have a non-zero pid but no threads, as + in the middle of a 'mourn' operation. */ + int -have_live_inferiors (void) +number_of_live_inferiors (void) { struct inferior *inf; + int num_inf = 0; for (inf = inferior_list; inf; inf = inf->next) if (inf->pid != 0) { struct thread_info *tp; - - tp = any_thread_of_process (inf->pid); - if (tp && target_has_execution_1 (tp->ptid)) - break; + + ALL_NON_EXITED_THREADS (tp) + if (tp && ptid_get_pid (tp->ptid) == inf->pid) + if (target_has_execution_1 (tp->ptid)) + { + /* Found a live thread in this inferior, go to the next + inferior. */ + ++num_inf; + break; + } } - return inf != NULL; + return num_inf; +} + +/* Return true if there is at least one live inferior. */ + +int +have_live_inferiors (void) +{ + return number_of_live_inferiors () > 0; } /* Prune away any unused inferiors, and then prune away no longer used @@ -719,8 +748,8 @@ inferior_command (char *args, int from_tty) switch_to_thread (tp->ptid); } - printf_filtered (_("[Switching to thread %d (%s)] "), - pid_to_thread_id (inferior_ptid), + printf_filtered (_("[Switching to thread %s (%s)] "), + print_thread_id (inferior_thread ()), target_pid_to_str (inferior_ptid)); } else @@ -979,6 +1008,26 @@ show_print_inferior_events (struct ui_file *file, int from_tty, fprintf_filtered (file, _("Printing of inferior events is %s.\n"), value); } +/* Return a new value for the selected inferior's id. */ + +static struct value * +inferior_id_make_value (struct gdbarch *gdbarch, struct internalvar *var, + void *ignore) +{ + struct inferior *inf = current_inferior (); + + return value_from_longest (builtin_type (gdbarch)->builtin_int, inf->num); +} + +/* Implementation of `$_inferior' variable. */ + +static const struct internalvar_funcs inferior_funcs = +{ + inferior_id_make_value, + NULL, + NULL +}; + void @@ -1042,4 +1091,5 @@ Show printing of inferior events (e.g., inferior start and exit)."), NULL, show_print_inferior_events, &setprintlist, &showprintlist); + create_internalvar_type_lazy ("_inferior", &inferior_funcs, NULL); }