From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 24166 invoked by alias); 6 Jul 2006 16:19:06 -0000 Received: (qmail 24152 invoked by uid 22791); 6 Jul 2006 16:19:03 -0000 X-Spam-Check-By: sourceware.org Received: from fra-del-01.spheriq.net (HELO fra-del-01.spheriq.net) (195.46.51.97) by sourceware.org (qpsmtpd/0.31) with ESMTP; Thu, 06 Jul 2006 16:18:58 +0000 Received: from fra-out-01.spheriq.net (fra-out-01.spheriq.net [195.46.51.129]) by fra-del-01.spheriq.net with ESMTP id k66GIqEa011944 for ; Thu, 6 Jul 2006 16:18:53 GMT Received: from fra-cus-02.spheriq.net (fra-cus-02.spheriq.net [195.46.51.38]) by fra-out-01.spheriq.net with ESMTP id k66GIpA4004037 for ; Thu, 6 Jul 2006 16:18:51 GMT Received: from beta.dmz-eu.st.com (beta.dmz-eu.st.com [164.129.1.35]) by fra-cus-02.spheriq.net with ESMTP id k66GInQS006031 (version=TLSv1/SSLv3 cipher=EDH-RSA-DES-CBC3-SHA bits=168 verify=OK) for ; Thu, 6 Jul 2006 16:18:51 GMT Received: from zeta.dmz-eu.st.com (ns2.st.com [164.129.230.9]) by beta.dmz-eu.st.com (STMicroelectronics) with ESMTP id F1B9EDA41 for ; Thu, 6 Jul 2006 16:18:48 +0000 (GMT) Received: from mail1.bri.st.com (mail1.bri.st.com [164.129.8.218]) by zeta.dmz-eu.st.com (STMicroelectronics) with ESMTP id E620D473D9 for ; Thu, 6 Jul 2006 16:18:47 +0000 (GMT) Received: from [164.129.15.13] (bri1043.bri.st.com [164.129.15.13]) by mail1.bri.st.com (MOS 3.5.8-GR) with ESMTP id CHU37895 (AUTH stubbsa); Thu, 6 Jul 2006 17:18:46 +0100 (BST) Message-ID: <44AD37E6.5050705@st.com> Date: Thu, 06 Jul 2006 16:19:00 -0000 From: Andrew STUBBS User-Agent: Thunderbird 1.5.0.4 (Windows/20060516) MIME-Version: 1.0 To: gdb-patches@sourceware.org Subject: Re: [PATCH] Fix segfault on empty else References: <44980741.4040404@st.com> <20060620201752.GA1453@nevyn.them.org> <4499247B.7050404@st.com> <20060706133044.GC18827@nevyn.them.org> In-Reply-To: <20060706133044.GC18827@nevyn.them.org> Content-Type: multipart/mixed; boundary="------------000806000905090103060602" X-IsSubscribed: yes Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org X-SW-Source: 2006-07/txt/msg00037.txt.bz2 This is a multi-part message in MIME format. --------------000806000905090103060602 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Content-length: 1508 Daniel Jacobowitz wrote: > Works fine for me - very clever. This patch is OK. I'd recommend two > changes, at your discretion: > >> +send_gdb "if 1\necho true\\n\nelse\necho false\\n\nend\n" > > Due to the patterns you're matching, this is safe, but in general it's > bad style to use send_gdb without a matching gdb_expect. If you use > gdb_test with the third argument empty, it will not be registered > as a "test", and no pass message will be issued - unless the test > fails, that is. So this is useful for tests which aren't part of the > testcase, and are always assumed to pass. I could certainly do this. >> +# with true condition >> +send_gdb "if 1\nelse\nend\necho got here\\n\n" >> +gdb_expect { > > gdb_test_multiple is a little nicer here. You can still supply your > own eof handler; the only difference is that it will pick > up other quirky bits like internal error messages (and the default > timeout handler should be fine for you here). I have tried to do this, but have hit trouble. Please find my best effort attached. The problem is that it now calls perror which means that any test that fails due to a crash is marked UNRESOLVED, not FAIL. It also prevents any further tests in the file from running. So the result is that failures are not flagged up as clearly as they should be - you just get one unresolved test case instead of the proper handful of failures that would set the alarm bells ringing. It does do the right thing when everything passes. Andrew --------------000806000905090103060602 Content-Type: text/plain; name="ifelse.exp" Content-Transfer-Encoding: 7bit Content-Disposition: inline; filename="ifelse.exp" Content-length: 2991 # Copyright 2006 Free Software Foundation, Inc. # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. # This test checks that the if .. else .. end construct works and may # contain empty bodies without crashing. if $tracelevel then { strace $tracelevel } gdb_exit gdb_start # First test that the if command works with an empty body # Test with different conditions because the body is ignored # if it is not executed. # with true condition if {[gdb_test_multiple "if 1\nend\necho got here\\n" "if 1 with empty body" { -re ".*got here.*$gdb_prompt $" {pass "if 1 with empty body"} }] != 0} { gdb_exit gdb_start } # with false condition if {[gdb_test_multiple "if 0\nend\necho got here\\n" "if 0 with empty body" { -re ".*got here.*$gdb_prompt $" {pass "if 0 with empty body"} }] != 0} { gdb_exit gdb_start } # Second, do the same tests with an empty else body. # This fails in GDB <=6.5 # Unfortunately it was an uninitialised memory problem so # sometimes it just works. Preceed it with an if else end with # bodies and hopefully the memory with be dirty and the problem # will show itself (this works at time of writing). gdb_test "if 1\necho true\\n\nelse\necho false\\n\nend" "true" "" # with true condition if {[gdb_test_multiple "if 1\nelse\nend\necho got here\\n" \ "if 1 .. else with empty body" { -re ".*got here.*$gdb_prompt $" {pass "if 1 .. else with empty body"} } ] != 0} { gdb_exit gdb_start } # dirty memory gdb_test "if 1\necho true\\n\nelse\necho false\\n\nend" "true" "" # with false condition if {[gdb_test_multiple "if 0\nelse\nend\necho got here\\n" \ "if 0 .. else with empty body" { -re ".*got here.*$gdb_prompt $" {pass "if 0 .. else with empty body"} }] != 0} { gdb_exit gdb_start } gdb_test "set confirm off" "" "" # Test that a define with an empty else can be replaced. # If there is memory corruption then free will fail. # dirty memory gdb_test "if 1\necho true\\n\nelse\necho false\\n\nend" "true" "" # create gdb_test "define abc\nif 1\nelse\nend\nend" "" "create define with empty else" # call gdb_test "abc" "" "call original define" # replace gdb_test "define abc\necho got here\\n\nend" "" \ "replace define with if .. else with empty body" # call gdb_test "abc" "got here" "call replacement define" --------------000806000905090103060602--