This is the mail archive of the
gdb-patches@sourceware.org
mailing list for the GDB project.
RE: Assertion failure because of missing inferior
> Below is a more complete solution, copying the code from:
> mi_cmd_execute(). It basically sets a thread, after setting the inferior.
> Sorry about missing it before.
>
> Doing this lead me to another segfault. I confirmed that it is part
> of 7.2 and not introduced by my patch. So, I'm posting this patch now,
> but I will email and investigate about the new segfault. There is
> not much point to this current patch until the segfault is fixed, but
> they are still two different issues, which is why I'm still posting this
> patch.
The segfault is caused by the fact that I removed the inferior while
it was still running. I posted a question about that, but I think it is not
a normal use case, and therefore, does not prevent the below patch
from adding value.
What do you think of the below for 7_2?
Thanks
Marc
2010-12-10 Marc Khouzam <marc.khouzam@ericsson.com>
* mi/mi-main.c (mi_cmd_remove_inferior): Don't delete current inferior.
(get_other_inferior): New.
### Eclipse Workspace Patch 1.0
#P src
Index: gdb/mi/mi-main.c
===================================================================
RCS file: /cvs/src/src/gdb/mi/mi-main.c,v
retrieving revision 1.178.2.4
diff -u -r1.178.2.4 mi-main.c
--- gdb/mi/mi-main.c 9 Dec 2010 19:22:59 -0000 1.178.2.4
+++ gdb/mi/mi-main.c 10 Dec 2010 20:45:44 -0000
@@ -1623,6 +1623,18 @@
ui_out_field_fmt (uiout, "inferior", "i%d", inf->num);
}
+/* Callback used to find the first inferior other than the
+ current one. */
+
+static int
+get_other_inferior (struct inferior *inf, void *arg)
+{
+ if (inf == current_inferior ())
+ return 0;
+
+ return 1;
+}
+
void
mi_cmd_remove_inferior (char *command, char **argv, int argc)
{
@@ -1639,6 +1651,22 @@
if (!inf)
error ("the specified thread group does not exist");
+ if (inf == current_inferior ())
+ {
+ struct thread_info *tp = 0;
+ struct inferior *new_inferior
+ = iterate_over_inferiors (get_other_inferior, NULL);
+
+ if (new_inferior == NULL)
+ error (_("Cannot remove last inferior"));
+
+ set_current_inferior (new_inferior);
+ if (new_inferior->pid != 0)
+ tp = any_thread_of_process (new_inferior->pid);
+ switch_to_thread (tp ? tp->ptid : null_ptid);
+ set_current_program_space (new_inferior->pspace);
+ }
+
delete_inferior_1 (inf, 1 /* silent */);
}