From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 22740 invoked by alias); 21 Oct 2008 21:18:54 -0000 Received: (qmail 22731 invoked by uid 22791); 21 Oct 2008 21:18:53 -0000 X-Spam-Check-By: sourceware.org Received: from mx2.redhat.com (HELO mx2.redhat.com) (66.187.237.31) by sourceware.org (qpsmtpd/0.31) with ESMTP; Tue, 21 Oct 2008 21:18:11 +0000 Received: from int-mx2.corp.redhat.com (int-mx2.corp.redhat.com [172.16.27.26]) by mx2.redhat.com (8.13.8/8.13.8) with ESMTP id m9LLE2AJ028454; Tue, 21 Oct 2008 17:14:02 -0400 Received: from ns3.rdu.redhat.com (ns3.rdu.redhat.com [10.11.255.199]) by int-mx2.corp.redhat.com (8.13.1/8.13.1) with ESMTP id m9LLE1no031608; Tue, 21 Oct 2008 17:14:01 -0400 Received: from opsy.redhat.com (vpn-12-160.rdu.redhat.com [10.11.12.160]) by ns3.rdu.redhat.com (8.13.8/8.13.8) with ESMTP id m9LLE0Pt022554; Tue, 21 Oct 2008 17:14:01 -0400 Received: by opsy.redhat.com (Postfix, from userid 500) id 9800F508073; Tue, 21 Oct 2008 15:13:59 -0600 (MDT) To: Pedro Alves Cc: gdb-patches@sourceware.org Subject: Re: RFA: fix PR 2506 References: <200810211727.18574.pedro@codesourcery.com> From: Tom Tromey Reply-To: Tom Tromey X-Attribution: Tom Date: Tue, 21 Oct 2008 21:18:00 -0000 In-Reply-To: (Tom Tromey's message of "Tue\, 21 Oct 2008 12\:53\:55 -0600") Message-ID: User-Agent: Gnus/5.11 (Gnus v5.11) Emacs/22.2 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii 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: 2008-10/txt/msg00524.txt.bz2 Tom> I'll resubmit once the testing is finished. This fixes the problems you reported, and adds a new test case. Built & regression tested on x86-64 (compile farm). Ok? Tom 2008-10-21 Tom Tromey PR gdb/2506: * c-exp.y (string_exp): New production. (exp): Use it. 2008-08-20 Tom Tromey * gdb.base/exprs.exp (test_expr): Add test for string concatenation. diff --git a/gdb/c-exp.y b/gdb/c-exp.y index 6d16940..153e2be 100644 --- a/gdb/c-exp.y +++ b/gdb/c-exp.y @@ -184,7 +184,7 @@ static int parse_number (char *, int, int, YYSTYPE *); %token NAME /* BLOCKNAME defined below to give it higher precedence. */ %token COMPLETE %token TYPENAME -%type name +%type name string_exp %type name_not_typename %type typename @@ -562,7 +562,34 @@ exp : SIZEOF '(' type ')' %prec UNARY write_exp_elt_opcode (OP_LONG); } ; -exp : STRING +string_exp: + STRING + { + /* We copy the string here, and not in the + lexer, to guarantee that we do not leak a + string. Note that we follow the + NUL-termination convention of the + lexer. */ + $$.length = $1.length; + $$.ptr = malloc ($1.length + 1); + memcpy ($$.ptr, $1.ptr, $1.length + 1); + } + + | string_exp STRING + { + /* Note that we NUL-terminate here, but just + for convenience. */ + struct stoken t; + t.length = $1.length + $2.length; + t.ptr = malloc (t.length + 1); + memcpy (t.ptr, $1.ptr, $1.length); + memcpy (t.ptr + $1.length, $2.ptr, $2.length + 1); + free ($1.ptr); + $$ = t; + } + ; + +exp : string_exp { /* C strings are converted into array constants with an explicit null byte added at the end. Thus the array upper bound is the string length. @@ -583,7 +610,9 @@ exp : STRING write_exp_elt_opcode (OP_ARRAY); write_exp_elt_longcst ((LONGEST) 0); write_exp_elt_longcst ((LONGEST) ($1.length)); - write_exp_elt_opcode (OP_ARRAY); } + write_exp_elt_opcode (OP_ARRAY); + free ($1.ptr); + } ; /* C++. */ diff --git a/gdb/testsuite/gdb.base/exprs.exp b/gdb/testsuite/gdb.base/exprs.exp index e25de77..484b5a4 100644 --- a/gdb/testsuite/gdb.base/exprs.exp +++ b/gdb/testsuite/gdb.base/exprs.exp @@ -248,3 +248,7 @@ gdb_test "print (void*) ((long long) (unsigned long) -1 + 1)" \ if [expr ! $ok] { setup_xfail "*-*-*" } gdb_test "print (void*) (~((long long)(unsigned long) -1) - 1)" \ "warning: value truncated.*" "truncate (void*) 0xffffffff00000000 - 1" + +# String concatentation. +test_expr "print \"x\" \"y\"" "\\$\[0-9\]* = \"xy\"" +test_expr "print \"x\" \"y\" \"z\"" "\\$\[0-9\]* = \"xyz\""