From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 21998 invoked by alias); 4 Dec 2010 19:11:09 -0000 Received: (qmail 21988 invoked by uid 22791); 4 Dec 2010 19:11:08 -0000 X-SWARE-Spam-Status: No, hits=-1.5 required=5.0 tests=AWL,BAYES_00 X-Spam-Check-By: sourceware.org Received: from imr4.ericy.com (HELO imr4.ericy.com) (198.24.6.8) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Sat, 04 Dec 2010 19:11:03 +0000 Received: from eusaamw0712.eamcs.ericsson.se ([147.117.20.181]) by imr4.ericy.com (8.14.3/8.14.3/Debian-9.1ubuntu1) with ESMTP id oB4JdpJ2008637 for ; Sat, 4 Dec 2010 13:39:52 -0600 Received: from EUSAACMS0703.eamcs.ericsson.se ([169.254.1.63]) by eusaamw0712.eamcs.ericsson.se ([147.117.20.181]) with mapi; Sat, 4 Dec 2010 14:10:55 -0500 From: Marc Khouzam To: "gdb-patches@sourceware.org" Date: Sat, 04 Dec 2010 19:11:00 -0000 Subject: Assertion failure because of missing inferior Message-ID: Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-IsSubscribed: yes Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org X-SW-Source: 2010-12/txt/msg00031.txt.bz2 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 f= rontend to change the current inferior. I understand this as saying that the front= end 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=20 Added inferior 2 (gdb) inf inf Num Description Executable=20=20=20=20=20=20=20=20 2 =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20 * 1 =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20 (gdb) remove-inferior 1 Can not remove current symbol inferior. =3D=3D=3D Not allowed to remove using CLI =3D=3D=3D (gdb) interpreter-exec mi "-remove-inferior i1" ^done =3D=3D=3D Allowed to remove using MI =3D=3D=3D (gdb) inf inf Num Description Executable=20=20=20=20=20=20=20=20 2 =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20 =3D=3D=3D No current inferior =3D=3D=3D (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: Assertio= n `inf !=3D 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 * 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 =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D 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); } =20 +/* Callback used to find the first inferior other than the + current one. */ +static int +get_other_inferior (struct inferior *inf, void *arg) +{ + if (inf =3D=3D 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"); =20 + if (inf =3D=3D current_inferior ()) + { + struct inferior *new_inferior =3D iterate_over_inferiors (get_other_= inferior, NULL); + if (new_inferior =3D=3D NULL) + error ("Cannot remove last inferior"); + + set_current_inferior (new_inferior); + } + delete_inferior_1 (inf, 1 /* silent */); }