* printcmd.c (printf_command): Handle ptr_arg. Correct typo
authorDaniel Jacobowitz <drow@false.org>
Tue, 4 Sep 2007 14:18:47 +0000 (14:18 +0000)
committerDaniel Jacobowitz <drow@false.org>
Tue, 4 Sep 2007 14:18:47 +0000 (14:18 +0000)
in internal error message.

* gdb.base/display.exp: Add tests for printf %p.

gdb/ChangeLog
gdb/printcmd.c
gdb/testsuite/ChangeLog
gdb/testsuite/gdb.base/display.exp

index d8eca3ad187386f46cc2e1d1960e121ca9c2288d..af3cf2fc864ad51ce356219aa5b20d1de6b2e9a9 100644 (file)
@@ -1,3 +1,8 @@
+2007-09-04  Daniel Jacobowitz  <dan@codesourcery.com>
+
+       * printcmd.c (printf_command): Handle ptr_arg.  Correct typo
+       in internal error message.
+
 2007-09-04  Pedro Alves  <pedro_alves@portugalmail.pt>
            Daniel Jacobowitz  <dan@codesourcery.com>
 
index 9fc716b88200bdb49f4181b623d5c7462be3c1b4..019a4a627032f6109c57a061e585abdfa02ecd92 100644 (file)
@@ -2079,9 +2079,68 @@ printf_command (char *arg, int from_tty)
              printf_filtered (current_substring, val);
              break;
            }
+         case ptr_arg:
+           {
+             /* We avoid the host's %p because pointers are too
+                likely to be the wrong size.  The only interesting
+                modifier for %p is a width; extract that, and then
+                handle %p as glibc would: %#x or a literal "(nil)".  */
+
+             char *p, *fmt, *fmt_p;
+#if defined (CC_HAS_LONG_LONG) && defined (PRINTF_HAS_LONG_LONG)
+             long long val = value_as_long (val_args[i]);
+#else
+             long val = value_as_long (val_args[i]);
+#endif
+
+             fmt = alloca (strlen (current_substring) + 5);
+
+             /* Copy up to the leading %.  */
+             p = current_substring;
+             fmt_p = fmt;
+             while (*p)
+               {
+                 int is_percent = (*p == '%');
+                 *fmt_p++ = *p++;
+                 if (is_percent)
+                   {
+                     if (*p == '%')
+                       *fmt_p++ = *p++;
+                     else
+                       break;
+                   }
+               }
+
+             if (val != 0)
+               *fmt_p++ = '#';
+
+             /* Copy any width.  */
+             while (*p >= '0' && *p < '9')
+               *fmt_p++ = *p++;
+
+             gdb_assert (*p == 'p' && *(p + 1) == '\0');
+             if (val != 0)
+               {
+#if defined (CC_HAS_LONG_LONG) && defined (PRINTF_HAS_LONG_LONG)
+                 *fmt_p++ = 'l';
+#endif
+                 *fmt_p++ = 'l';
+                 *fmt_p++ = 'x';
+                 *fmt_p++ = '\0';
+                 printf_filtered (fmt, val);
+               }
+             else
+               {
+                 *fmt_p++ = 's';
+                 *fmt_p++ = '\0';
+                 printf_filtered (fmt, "(nil)");
+               }
+
+             break;
+           }
          default:
            internal_error (__FILE__, __LINE__,
-                           _("failed internal consitency check"));
+                           _("failed internal consistency check"));
          }
        /* Skip to the next substring.  */
        current_substring += strlen (current_substring) + 1;
index ea169285963a6a5d1051b76f217926ab10866a63..c453ab26200164f0729171ac5a9a308326a5d749 100644 (file)
@@ -1,3 +1,7 @@
+2007-09-04  Daniel Jacobowitz  <dan@codesourcery.com>
+
+       * gdb.base/display.exp: Add tests for printf %p.
+
 2007-09-03  Pedro Alves  <pedro_alves@portugalmail.pt>
 
        * gdb.base/unload.c (dlopen, dlsym): Use the TEXT macro to convert
index 653b5d9cc0d2fa42e40e0959e2980c7fbb8ce1d3..254c4313db9a50c5e4225f00edd1f0563f5845d1 100644 (file)
@@ -178,6 +178,8 @@ gdb_test "printf \"\\\\!\\a\\f\\r\\t\\v\\b\\n\"" ".*!.*"
 gdb_test "printf \"\"" ".*" "re-set term"
 gdb_test "printf \"\\w\"" ".*Unrecognized escape character.*"
 gdb_test "printf \"%d\" j" ".*Invalid argument syntax.*"
+gdb_test "printf \"%p\\n\", 0" "\\(nil\\)"
+gdb_test "printf \"%p\\n\", 1" "0x1"
 
 # play with "print", too
 #