* c-exp.y (exp:STRING): Convert C strings into array-of-char
[deliverable/binutils-gdb.git] / gdb / c-exp.y
index 21df46d65237ff0230dc07bdc08b4cb7f7a5b371..bca3d6d75e10bb32a428b3e95d078d91f77cc720 100644 (file)
@@ -480,9 +480,27 @@ exp        :       SIZEOF '(' type ')'     %prec UNARY
        ;
 
 exp    :       STRING
-                       { write_exp_elt_opcode (OP_STRING);
-                         write_exp_string ($1);
-                         write_exp_elt_opcode (OP_STRING); }
+                       { /* 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.
+                            There is no such thing in C as a completely empty
+                            string. */
+                         char *sp = $1.ptr; int count = $1.length;
+                         while (count-- > 0)
+                           {
+                             write_exp_elt_opcode (OP_LONG);
+                             write_exp_elt_type (builtin_type_char);
+                             write_exp_elt_longcst ((LONGEST)(*sp++));
+                             write_exp_elt_opcode (OP_LONG);
+                           }
+                         write_exp_elt_opcode (OP_LONG);
+                         write_exp_elt_type (builtin_type_char);
+                         write_exp_elt_longcst ((LONGEST)'\0');
+                         write_exp_elt_opcode (OP_LONG);
+                         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); }
        ;
 
 /* C++.  */
This page took 0.024607 seconds and 4 git commands to generate.