gdb
authorTom Tromey <tromey@redhat.com>
Wed, 22 Oct 2008 16:38:09 +0000 (16:38 +0000)
committerTom Tromey <tromey@redhat.com>
Wed, 22 Oct 2008 16:38:09 +0000 (16:38 +0000)
PR gdb/2506:
* c-exp.y (string_exp): New production.
(exp): Use it.
gdb/testsuite
* gdb.base/exprs.exp (test_expr): Add test for string
concatenation.

gdb/ChangeLog
gdb/c-exp.y
gdb/testsuite/ChangeLog
gdb/testsuite/gdb.base/exprs.exp

index cc6b0bb2e02766c0d79b3ef1073602bb7d61565c..f76063212b06b112dfea942d5a7561ec10c4a545 100644 (file)
@@ -1,3 +1,9 @@
+2008-10-22  Tom Tromey  <tromey@redhat.com>
+
+       PR gdb/2506:
+       * c-exp.y (string_exp): New production.
+       (exp): Use it.
+
 2008-10-21  Jan Kratochvil  <jan.kratochvil@redhat.com>
 
        * mips-tdep.c (mips_n32n64_fp_arg_chunk_p): Update TYPE_FIELD_STATIC
index 6d169405840beb7cb4073eaec2487a142bd68ace..153e2be3cf8a188549d81c65452d8e2270209c66 100644 (file)
@@ -184,7 +184,7 @@ static int parse_number (char *, int, int, YYSTYPE *);
 %token <ssym> NAME /* BLOCKNAME defined below to give it higher precedence. */
 %token <voidval> COMPLETE
 %token <tsym> TYPENAME
-%type <sval> name
+%type <sval> name string_exp
 %type <ssym> name_not_typename
 %type <tsym> 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++.  */
index 9c3e624ee21bd5affa7f9dce1a385a061df0d581..dd4ccf54f16b45eabc95747f0a81c77a74d1920c 100644 (file)
@@ -1,3 +1,8 @@
+2008-10-22  Tom Tromey  <tromey@redhat.com>
+
+       * gdb.base/exprs.exp (test_expr): Add test for string
+       concatenation.
+
 2008-10-19  Pedro Alves  <pedro@codesourcery.com>
 
        * configure.ac: Output gdb.python/Makefile.
index e25de77d25097ce9247d83ee8d5624d388e657ab..484b5a4a8f5a0bb84e2595cda2db9b1be2ec4ee6 100644 (file)
@@ -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\""