From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 29016 invoked by alias); 7 Nov 2007 19:58:20 -0000 Received: (qmail 29003 invoked by uid 22791); 7 Nov 2007 19:58:19 -0000 X-Spam-Check-By: sourceware.org Received: from zigzag.lvk.cs.msu.su (HELO zigzag.lvk.cs.msu.su) (158.250.17.23) by sourceware.org (qpsmtpd/0.31) with ESMTP; Wed, 07 Nov 2007 19:58:13 +0000 Received: from Debian-exim by zigzag.lvk.cs.msu.su with spam-scanned (Exim 4.50) id 1Ipr2J-0000RG-DA for gdb-patches@sources.redhat.com; Wed, 07 Nov 2007 22:58:09 +0300 Received: from localhost ([127.0.0.1] helo=ip6-localhost) by zigzag.lvk.cs.msu.su with esmtps (TLS-1.0:DHE_RSA_AES_256_CBC_SHA:32) (Exim 4.50) id 1Ipr2I-0000RB-Or for gdb-patches@sources.redhat.com; Wed, 07 Nov 2007 22:58:03 +0300 From: Vladimir Prus To: gdb-patches@sources.redhat.com Subject: Fix crash in -var-delete Date: Wed, 07 Nov 2007 19:58:00 -0000 User-Agent: KMail/1.9.6 MIME-Version: 1.0 Content-Type: Multipart/Mixed; boundary="Boundary-00=_HjhMHM+tgJ8Bk8E" Message-Id: <200711072257.59372.ghost@cs.msu.su> 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: 2007-11/txt/msg00136.txt.bz2 --Boundary-00=_HjhMHM+tgJ8Bk8E Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Content-Disposition: inline Content-length: 773 A KDevelop user has reported that gdb 6.7 consistently crashes when used in KDevelop. Of course, I should have tested gdb 6.7 before it's released, but it's too late at this point, so here's a patch instead. Historically, KDevelop deletes variable objects recursively -- first most nested ones, then their parents and so on. Note that while it's not necessary in most cases, there's nothing inherently wrong about it. Say, if GUI for some reason does not care about particular child anymore, it's free to delete it (even though with frozen varobj, it can just freeze it). Unfortunately gdb 6.7, when deleting varobj where some children of it are already deleted, tries to mess with NULL pointers, and crashes. The patch and a testcase are attached. OK? - Volodya --Boundary-00=_HjhMHM+tgJ8Bk8E Content-Type: text/x-diff; charset="utf-8"; name="child_deletion.diff" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="child_deletion.diff" Content-length: 2430 Index: varobj.c =================================================================== RCS file: /cvs/src/src/gdb/varobj.c,v retrieving revision 1.96 diff -u -p -r1.96 varobj.c --- varobj.c 27 Sep 2007 18:04:12 -0000 1.96 +++ varobj.c 7 Nov 2007 19:51:19 -0000 @@ -1292,6 +1292,8 @@ delete_variable_1 (struct cpstack **resu for (i = 0; i < VEC_length (varobj_p, var->children); ++i) { varobj_p child = VEC_index (varobj_p, var->children, i); + if (!child) + continue; if (!remove_from_parent_p) child->parent = NULL; delete_variable_1 (resultp, delcountp, child, 0, only_children_p); Index: testsuite/gdb.mi/mi-var-child.c =================================================================== RCS file: /cvs/src/src/gdb/testsuite/gdb.mi/mi-var-child.c,v retrieving revision 1.6 diff -u -p -r1.6 mi-var-child.c --- testsuite/gdb.mi/mi-var-child.c 23 Aug 2007 18:08:49 -0000 1.6 +++ testsuite/gdb.mi/mi-var-child.c 7 Nov 2007 19:51:20 -0000 @@ -306,6 +306,29 @@ do_special_tests (void) incr_a(2); } +struct very_simple_struct +{ + int a; + int b; +}; + +int +do_child_deletion (void) +{ + /*: BEGIN: child_deletion :*/ + struct very_simple_struct s = {1, 2}; + /*: + mi_create_varobj S s "create varobj for s" + mi_list_varobj_children S {{S.a a 0 int} {S.b b 0 int}} \ + "list children of S" + mi_delete_varobj S.a "delete S.a" + mi_delete_varobj S.b "delete S.b" + mi_delete_varobj S "delete S" + :*/ + return 99; + /*: END: child_deletion :*/ +} + int main (int argc, char *argv []) { @@ -313,6 +336,7 @@ main (int argc, char *argv []) do_block_tests (); do_children_tests (); do_special_tests (); + do_child_deletion (); exit (0); } Index: testsuite/gdb.mi/mi-var-child.exp =================================================================== RCS file: /cvs/src/src/gdb/testsuite/gdb.mi/mi-var-child.exp,v retrieving revision 1.26 diff -u -p -r1.26 mi-var-child.exp --- testsuite/gdb.mi/mi-var-child.exp 23 Aug 2007 18:14:19 -0000 1.26 +++ testsuite/gdb.mi/mi-var-child.exp 7 Nov 2007 19:51:20 -0000 @@ -1227,7 +1227,9 @@ mi_gdb_test "-var-update *" \ "\\^done,changelist=\\\[\{name=\"psnp->ptrs.0.next.next.long_ptr\",in_scope=\"true\",type_changed=\"false\"\}\\\]" \ "update all vars psnp->next->next->long_ptr (and 2.long_ptr) changed" +mi_prepare_inline_tests $srcfile +mi_run_inline_test child_deletion mi_gdb_exit --Boundary-00=_HjhMHM+tgJ8Bk8E--