Assertion failure because of missing inferior

Marc Khouzam marc.khouzam@ericsson.com
Sat Dec 4 19:11:00 GMT 2010


Hi,

it seems that GDB expects that there always will be a current inferior.
To make sure of this, the CLI command 'remove-inferior' rejects the removing
of the current inferior.

The problem is that the corresponding MI command '-remove-inferior' does not
have the same check.  Please see the session below which makes GDB fail
on an assert.

Now, there is not MI command equivalent to 'inferior' to properly allow a frontend
to change the current inferior.  I understand this as saying that the frontend should
not need to change the current inferior, but should instead always use the MI
--thread-group flag to indicate which inferior the command applies to.
That is fine with me.

So, I was thinking that since a frontend shouldn't care which inferior is
the current one, then '-remove-inferior' could change the current inferior to another
inferior, before doing the removal.  This is pretty much what the frontend would have
to do anyway.  Removing the very last inferior would not be allowed.

The patch below does this.  What do you think of this approach?

Session showing error:

> ./gdb
GNU gdb (GDB) 7.2.0.20101112-cvs
(gdb) add-inferior 
Added inferior 2
(gdb) inf inf
  Num  Description       Executable        
  2    <null>                              
* 1    <null>                              
(gdb) remove-inferior 1
Can not remove current symbol inferior.

=== Not allowed to remove using CLI ===

(gdb) interpreter-exec mi "-remove-inferior i1"
^done

=== Allowed to remove using MI ===

(gdb)  inf inf
  Num  Description       Executable        
  2    <null>                              

=== No current inferior ===

(gdb) file a.out
Reading symbols from /home/lmckhou/testing/a.out...done.
(gdb) list
../../src/gdb/inferior.c:59: internal-error: set_current_inferior: Assertion `inf != NULL' failed.
A problem internal to GDB has been detected,
further debugging may prove unreliable.
Quit this debugging session? (y or n) y


2010-12-04  Marc Khouzam  <marc.khouzam@ericsson.com>

	* mi/mi-main.c (mi_cmd_remove_inferior): Don't delete last 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.182
diff -u -r1.182 mi-main.c
--- gdb/mi/mi-main.c    12 Nov 2010 18:46:42 -0000      1.182
+++ gdb/mi/mi-main.c    4 Dec 2010 19:01:02 -0000
@@ -1744,6 +1744,17 @@
   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)
 {
@@ -1760,6 +1771,15 @@
   if (!inf)
     error ("the specified thread group does not exist");
 
+  if (inf == current_inferior ())
+    {
+      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);
+    }
+
   delete_inferior_1 (inf, 1 /* silent */);
 }



More information about the Gdb-patches mailing list