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]

RFA: fix PR gdb/1136


PR 1136 noticed that expanding a macro containing the token-pasting
"##" operator caused gdb to emit an error message about
stringification.

I tracked this down to a bug in the macro lexer.  The lexer relies on
the ordering of the punctuator table to pick token boundaries.  So, a
longer token must occur before any shorter token which is a prefix.
In particular, in this case "##" must occur before "#".

I went ahead and rearranged the entire table to be correct.  I am not
sure the old ordering causes a visible problem in practice in other
cases.

Regression test included.  Built & tested on x86 F8.  Ok?

Tom

ChangeLog:
2008-07-26  Tom Tromey  <tromey@redhat.com>

	PR gdb/1136:
	* macroexp.c (get_punctuator) <punctuators>: Rearrange to put
	longer tokens first.

testsuite/ChangeLog:
2008-07-26  Tom Tromey  <tromey@redhat.com>

	* gdb.base/macscp.exp: Add test for macro lexing bug.

Index: macroexp.c
===================================================================
RCS file: /cvs/src/src/gdb/macroexp.c,v
retrieving revision 1.14
diff -u -r1.14 macroexp.c
--- macroexp.c	18 Jul 2008 20:55:32 -0000	1.14
+++ macroexp.c	26 Jul 2008 18:24:34 -0000
@@ -416,16 +416,27 @@
 {
   /* Here, speed is much less important than correctness and clarity.  */
 
-  /* ISO/IEC 9899:1999 (E)  Section 6.4.6  Paragraph 1  */
+  /* ISO/IEC 9899:1999 (E)  Section 6.4.6  Paragraph 1.
+     Note that this table is ordered in a special way.  A punctuator
+     which is a prefix of another punctuator must appear after its
+     "extension".  Otherwise, the wrong token will be returned.  */
   static const char * const punctuators[] = {
-    "[", "]", "(", ")", "{", "}", ".", "->", 
-    "++", "--", "&", "*", "+", "-", "~", "!",
-    "/", "%", "<<", ">>", "<", ">", "<=", ">=", "==", "!=", 
-    "^", "|", "&&", "||",
-    "?", ":", ";", "...",
-    "=", "*=", "/=", "%=", "+=", "-=", "<<=", ">>=", "&=", "^=", "|=",
-    ",", "#", "##",
-    "<:", ":>", "<%", "%>", "%:", "%:%:",
+    "[", "]", "(", ")", "{", "}", "?", ";", ",", "~",
+    "...", ".",
+    "->", "--", "-=", "-",
+    "++", "+=", "+",
+    "*=", "*",
+    "!=", "!",
+    "&&", "&=", "&",
+    "/=", "/",
+    "%>", "%:%:", "%:", "%=", "%",
+    "^=", "^",
+    "##", "#",
+    ":>", ":",
+    "||", "|=", "|",
+    "<<=", "<<", "<=", "<:", "<%", "<",
+    ">>=", ">>", ">=", ">",
+    "==", "=",
     0
   };
 
Index: testsuite/gdb.base/macscp.exp
===================================================================
RCS file: /cvs/src/src/gdb/testsuite/gdb.base/macscp.exp,v
retrieving revision 1.8
diff -u -r1.8 macscp.exp
--- testsuite/gdb.base/macscp.exp	18 Jul 2008 20:55:33 -0000	1.8
+++ testsuite/gdb.base/macscp.exp	26 Jul 2008 18:24:35 -0000
@@ -472,3 +472,8 @@
 gdb_test "print M" \
     "No symbol \"M\" in current context\." \
     "print expression with macro after user undef."
+
+# Regression test; this used to emit the wrong error.
+gdb_test "macro expand SPLICE(x, y)" \
+  "Token splicing is not implemented yet." \
+  "macro splicing lexes correctly"


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