This is the mail archive of the gdb-patches@sourceware.org mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

FYI: fix buglet in C lexer


While reading Denis' patch and comments about parse_to_comma_and_eval,
I ran across a bug.  The C lexer will terminate an expression at a
comma inside of [].

The fix is to treat [] like () when counting the paren depth.  This is
ok because this is the only use for the paren depth.

Built and regression tested on x86-64 (compile farm).
New test case included.

Tom

ChangeLog:
2009-04-27  Tom Tromey  <tromey@redhat.com>

	* c-exp.y (yylex): Handle '[' and ']' like '(' and ')'.

testsuite/ChangeLog:
2009-04-27  Tom Tromey  <tromey@redhat.com>

	* gdb.base/printcmds.exp (test_printf): Test comma operator in [].

Index: c-exp.y
===================================================================
RCS file: /cvs/src/src/gdb/c-exp.y,v
retrieving revision 1.54
diff -u -r1.54 c-exp.y
--- c-exp.y	20 Mar 2009 23:04:29 -0000	1.54
+++ c-exp.y	27 Apr 2009 23:54:35 -0000
@@ -1885,11 +1885,13 @@
       lexptr++;
       goto retry;
 
+    case '[':
     case '(':
       paren_depth++;
       lexptr++;
       return c;
 
+    case ']':
     case ')':
       if (paren_depth == 0)
 	return 0;
@@ -1991,8 +1993,6 @@
     case '@':
     case '<':
     case '>':
-    case '[':
-    case ']':
     case '?':
     case ':':
     case '=':
Index: testsuite/gdb.base/printcmds.exp
===================================================================
RCS file: /cvs/src/src/gdb/testsuite/gdb.base/printcmds.exp,v
retrieving revision 1.23
diff -u -r1.23 printcmds.exp
--- testsuite/gdb.base/printcmds.exp	20 Mar 2009 23:04:39 -0000	1.23
+++ testsuite/gdb.base/printcmds.exp	27 Apr 2009 23:54:37 -0000
@@ -666,6 +666,9 @@
     gdb_test "printf \"x=%d,y=%f,z=%d\\n\", 5, 6.0, 7" "x=5,y=6\.0+,z=7"
     gdb_test "printf \"%x %f, %c %x, %x, %f\\n\", 0xbad, -99.541, 'z',\
 0xfeedface, 0xdeadbeef, 5.0" "bad -99.54\[0-9\]+, z feedface, deadbeef, 5.0+"
+
+    # Regression test for C lexer bug.
+    gdb_test "printf \"%c\\n\", \"x\"\[1,0\]" "x"
 }
 
 #Test printing DFP values with printf


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]