RFA: fix macro expansion bug

Tom Tromey tromey@redhat.com
Thu Dec 11 23:28:00 GMT 2008


>>>>> "Pedro" == Pedro Alves <pedro@codesourcery.com> writes:

Pedro> Though, I'm having a bit of trouble convincing myself that the logic to
Pedro> handle 'pp-number e|E|p|P|. sign' below is 100% sane.
[...]
Pedro> It seems macro_is_identifier_nondigit will always eat any of "eEpP",
Pedro> thus, say, when parsing "1e-" only "1e" will be identified as a pp
Pedro> number, leaving "+" in the stream.  Is this right?

Yeah.  Also, "." should not appear in the strchr argument.

Here's a new patch.  I'll regression-test it.  I don't expect
problems.  Ok if it passes?

>> +  "expands to: siginfo. fields.fault.si_addr" \

Pedro> Just curious, as it's just a visual annoyance: do you know where
Pedro> this space comes from?  Do we store the definition with the space for
Pedro> some reason?  We don't get that extra space if the define came
Pedro> from the code, instead of from a 'macro define'.

Yes, it is a bug in "macro define".
I'll fix shortly.

Tom


2008-12-11  Tom Tromey  <tromey@redhat.com>

	* macroexp.c (get_pp_number): Require digit after leading ".".
	Correctly handle suffixes.

2008-12-11  Tom Tromey  <tromey@redhat.com>

	* gdb.base/macscp.exp: New regression test.

diff --git a/gdb/macroexp.c b/gdb/macroexp.c
index 7fb23ce..dda3592 100644
--- a/gdb/macroexp.c
+++ b/gdb/macroexp.c
@@ -278,20 +278,22 @@ get_pp_number (struct macro_buffer *tok, char *p, char *end)
 {
   if (p < end
       && (macro_is_digit (*p)
-          || *p == '.'))
+          || (*p == '.'
+	      && p + 2 <= end
+	      && macro_is_digit (p[1]))))
     {
       char *tok_start = p;
 
       while (p < end)
         {
-          if (macro_is_digit (*p)
-              || macro_is_identifier_nondigit (*p)
-              || *p == '.')
-            p++;
-          else if (p + 2 <= end
-                   && strchr ("eEpP.", *p)
-                   && (p[1] == '+' || p[1] == '-'))
+	  if (p + 2 <= end
+	      && strchr ("eEpP", *p)
+	      && (p[1] == '+' || p[1] == '-'))
             p += 2;
+          else if (macro_is_digit (*p)
+		   || macro_is_identifier_nondigit (*p)
+		   || *p == '.')
+            p++;
           else
             break;
         }
diff --git a/gdb/testsuite/gdb.base/macscp.exp b/gdb/testsuite/gdb.base/macscp.exp
index 9cb9ef5..40021b9 100644
--- a/gdb/testsuite/gdb.base/macscp.exp
+++ b/gdb/testsuite/gdb.base/macscp.exp
@@ -652,3 +652,11 @@ gdb_test "print str(maude)" \
 gdb_test "print xstr(maude)" \
   " = \"5\"" \
   "stringify with substitution"
+
+# Regression test for pp-number bug.
+gdb_test "macro define si_addr fields.fault.si_addr" \
+  "" \
+  "define si_addr macro"
+gdb_test "macro expand siginfo.si_addr" \
+  "expands to: siginfo. fields.fault.si_addr" \
+  "macro expand siginfo.si_addr"



More information about the Gdb-patches mailing list