*** empty log message ***
[binutils-gdb.git] / gdb / printcmd.c
index 155dff1a59a7dda5adcefa215de67f9fedb6490c..0dfe80be0f3386fa58f028bba1a2fc52543c6a66 100644 (file)
@@ -1,14 +1,14 @@
 /* Print values for GNU debugger GDB.
 
    Copyright (C) 1986, 1987, 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995,
-   1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007
-   Free Software Foundation, Inc.
+   1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007,
+   2008, 2009 Free Software Foundation, Inc.
 
    This file is part of GDB.
 
    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
-   the Free Software Foundation; either version 2 of the License, or
+   the Free Software Foundation; either version 3 of the License, or
    (at your option) any later version.
 
    This program is distributed in the hope that it will be useful,
@@ -17,9 +17,7 @@
    GNU General Public License for more details.
 
    You should have received a copy of the GNU General Public License
-   along with this program; if not, write to the Free Software
-   Foundation, Inc., 51 Franklin Street, Fifth Floor,
-   Boston, MA 02110-1301, USA.  */
+   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
 
 #include "defs.h"
 #include "gdb_string.h"
 #include "gdb_assert.h"
 #include "block.h"
 #include "disasm.h"
+#include "dfp.h"
+#include "valprint.h"
 
 #ifdef TUI
 #include "tui/tui.h"           /* For tui_active et.al.   */
 #endif
 
+#if defined(__MINGW32__) && !defined(PRINTF_HAS_LONG_LONG)
+# define USE_PRINTF_I64 1
+# define PRINTF_HAS_LONG_LONG
+#else
+# define USE_PRINTF_I64 0
+#endif
+
 extern int asm_demangle;       /* Whether to demangle syms in asm printouts */
-extern int addressprint;       /* Whether to print hex addresses in HLL " */
 
 struct format_data
   {
@@ -70,6 +76,10 @@ static char last_size = 'w';
 
 static CORE_ADDR next_address;
 
+/* Number of delay instructions following current disassembled insn.  */
+
+static int branch_delay_insns;
+
 /* Last address examined.  */
 
 static CORE_ADDR last_examine_address;
@@ -110,13 +120,6 @@ Printing of source filename and line number with <symbol> is %s.\n"),
 
 int current_display_number;
 
-/* Flag to low-level print routines that this value is being printed
-   in an epoch window.  We'd like to pass this as a parameter, but
-   every routine would need to take it.  Perhaps we can encapsulate
-   this in the I/O stream once we have GNU stdio. */
-
-int inspect_it = 0;
-
 struct display
   {
     /* Chain link to next auto-display item.  */
@@ -212,14 +215,14 @@ decode_format (char **string_ptr, int oformat, int osize)
       case 'a':
       case 's':
        /* Pick the appropriate size for an address.  */
-       if (TARGET_PTR_BIT == 64)
+       if (gdbarch_ptr_bit (current_gdbarch) == 64)
          val.size = osize ? 'g' : osize;
-       else if (TARGET_PTR_BIT == 32)
+       else if (gdbarch_ptr_bit (current_gdbarch) == 32)
          val.size = osize ? 'w' : osize;
-       else if (TARGET_PTR_BIT == 16)
+       else if (gdbarch_ptr_bit (current_gdbarch) == 16)
          val.size = osize ? 'h' : osize;
        else
-         /* Bad value for TARGET_PTR_BIT.  */
+         /* Bad value for gdbarch_ptr_bit.  */
          internal_error (__FILE__, __LINE__,
                          _("failed internal consistency check"));
        break;
@@ -244,14 +247,15 @@ decode_format (char **string_ptr, int oformat, int osize)
   return val;
 }
 \f
-/* Print value VAL on stream according to FORMAT, a letter or 0.
+/* Print value VAL on stream according to OPTIONS.
    Do not end with a newline.
-   0 means print VAL according to its own type.
    SIZE is the letter for the size of datum being printed.
-   This is used to pad hex numbers so they line up.  */
+   This is used to pad hex numbers so they line up.  SIZE is 0
+   for print / output and set for examine.  */
 
 static void
-print_formatted (struct value *val, int format, int size,
+print_formatted (struct value *val, int size,
+                const struct value_print_options *options,
                 struct ui_file *stream)
 {
   struct type *type = check_typedef (value_type (val));
@@ -260,106 +264,135 @@ print_formatted (struct value *val, int format, int size,
   if (VALUE_LVAL (val) == lval_memory)
     next_address = VALUE_ADDRESS (val) + len;
 
-  switch (format)
+  if (size)
     {
-    case 's':
-      /* FIXME: Need to handle wchar_t's here... */
-      next_address = VALUE_ADDRESS (val)
-       + val_print_string (VALUE_ADDRESS (val), -1, 1, stream);
-      break;
-
-    case 'i':
-      /* The old comment says
-         "Force output out, print_insn not using _filtered".
-         I'm not completely sure what that means, I suspect most print_insn
-         now do use _filtered, so I guess it's obsolete.
-         --Yes, it does filter now, and so this is obsolete.  -JB  */
-
-      /* We often wrap here if there are long symbolic names.  */
-      wrap_here ("    ");
-      next_address = VALUE_ADDRESS (val)
-       + gdb_print_insn (VALUE_ADDRESS (val), stream);
-      break;
+      switch (options->format)
+       {
+       case 's':
+         /* FIXME: Need to handle wchar_t's here... */
+         next_address = VALUE_ADDRESS (val)
+           + val_print_string (VALUE_ADDRESS (val), -1, 1, stream,
+                               options);
+         return;
 
-    default:
-      if (format == 0
-         || TYPE_CODE (type) == TYPE_CODE_ARRAY
-         || TYPE_CODE (type) == TYPE_CODE_STRING
-         || TYPE_CODE (type) == TYPE_CODE_STRUCT
-         || TYPE_CODE (type) == TYPE_CODE_UNION
-         || TYPE_CODE (type) == TYPE_CODE_NAMESPACE)
-       /* If format is 0, use the 'natural' format for that type of
-          value.  If the type is non-scalar, we have to use language
-          rules to print it as a series of scalars.  */
-       value_print (val, stream, format, Val_pretty_default);
-      else
-       /* User specified format, so don't look to the the type to
-          tell us what to do.  */
-       print_scalar_formatted (value_contents (val), type,
-                               format, size, stream);
+       case 'i':
+         /* We often wrap here if there are long symbolic names.  */
+         wrap_here ("    ");
+         next_address = (VALUE_ADDRESS (val)
+                         + gdb_print_insn (VALUE_ADDRESS (val), stream,
+                                           &branch_delay_insns));
+         return;
+       }
     }
+
+  if (options->format == 0 || options->format == 's'
+      || TYPE_CODE (type) == TYPE_CODE_REF
+      || TYPE_CODE (type) == TYPE_CODE_ARRAY
+      || TYPE_CODE (type) == TYPE_CODE_STRING
+      || TYPE_CODE (type) == TYPE_CODE_STRUCT
+      || TYPE_CODE (type) == TYPE_CODE_UNION
+      || TYPE_CODE (type) == TYPE_CODE_NAMESPACE)
+    value_print (val, stream, options);
+  else
+    /* User specified format, so don't look to the the type to
+       tell us what to do.  */
+    print_scalar_formatted (value_contents (val), type,
+                           options, size, stream);
+}
+
+/* Return builtin floating point type of same length as TYPE.
+   If no such type is found, return TYPE itself.  */
+static struct type *
+float_type_from_length (struct gdbarch *gdbarch, struct type *type)
+{
+  const struct builtin_type *builtin = builtin_type (gdbarch);
+  unsigned int len = TYPE_LENGTH (type);
+
+  if (len == TYPE_LENGTH (builtin->builtin_float))
+    type = builtin->builtin_float;
+  else if (len == TYPE_LENGTH (builtin->builtin_double))
+    type = builtin->builtin_double;
+  else if (len == TYPE_LENGTH (builtin->builtin_long_double))
+    type = builtin->builtin_long_double;
+
+  return type;
 }
 
 /* Print a scalar of data of type TYPE, pointed to in GDB by VALADDR,
-   according to letters FORMAT and SIZE on STREAM.
-   FORMAT may not be zero.  Formats s and i are not supported at this level.
+   according to OPTIONS and SIZE on STREAM.
+   Formats s and i are not supported at this level.
 
    This is how the elements of an array or structure are printed
    with a format.  */
 
 void
 print_scalar_formatted (const void *valaddr, struct type *type,
-                       int format, int size, struct ui_file *stream)
+                       const struct value_print_options *options,
+                       int size, struct ui_file *stream)
 {
   LONGEST val_long = 0;
   unsigned int len = TYPE_LENGTH (type);
+  enum bfd_endian byte_order = gdbarch_byte_order (current_gdbarch);
+
+  /* If we get here with a string format, try again without it.  Go
+     all the way back to the language printers, which may call us
+     again.  */
+  if (options->format == 's')
+    {
+      struct value_print_options opts = *options;
+      opts.format = 0;
+      opts.deref_ref = 0;
+      val_print (type, valaddr, 0, 0, stream, 0, &opts,
+                current_language);
+      return;
+    }
 
   if (len > sizeof(LONGEST) &&
       (TYPE_CODE (type) == TYPE_CODE_INT
        || TYPE_CODE (type) == TYPE_CODE_ENUM))
     {
-      switch (format)
+      switch (options->format)
        {
        case 'o':
-         print_octal_chars (stream, valaddr, len);
+         print_octal_chars (stream, valaddr, len, byte_order);
          return;
        case 'u':
        case 'd':
-         print_decimal_chars (stream, valaddr, len);
+         print_decimal_chars (stream, valaddr, len, byte_order);
          return;
        case 't':
-         print_binary_chars (stream, valaddr, len);
+         print_binary_chars (stream, valaddr, len, byte_order);
          return;
        case 'x':
-         print_hex_chars (stream, valaddr, len);
+         print_hex_chars (stream, valaddr, len, byte_order);
          return;
        case 'c':
-         print_char_chars (stream, valaddr, len);
+         print_char_chars (stream, valaddr, len, byte_order);
          return;
        default:
          break;
        };
     }
 
-  if (format != 'f')
+  if (options->format != 'f')
     val_long = unpack_long (type, valaddr);
 
   /* If the value is a pointer, and pointers and addresses are not the
      same, then at this point, the value's length (in target bytes) is
-     TARGET_ADDR_BIT/TARGET_CHAR_BIT, not TYPE_LENGTH (type).  */
+     gdbarch_addr_bit/TARGET_CHAR_BIT, not TYPE_LENGTH (type).  */
   if (TYPE_CODE (type) == TYPE_CODE_PTR)
-    len = TARGET_ADDR_BIT / TARGET_CHAR_BIT;
+    len = gdbarch_addr_bit (current_gdbarch) / TARGET_CHAR_BIT;
 
   /* If we are printing it as unsigned, truncate it in case it is actually
      a negative signed value (e.g. "print/u (short)-1" should print 65535
      (if shorts are 16 bits) instead of 4294967295).  */
-  if (format != 'd')
+  if (options->format != 'd')
     {
       if (len < sizeof (LONGEST))
        val_long &= ((LONGEST) 1 << HOST_CHAR_BIT * len) - 1;
     }
 
-  switch (format)
+  switch (options->format)
     {
     case 'x':
       if (!size)
@@ -404,17 +437,21 @@ print_scalar_formatted (const void *valaddr, struct type *type,
       break;
 
     case 'c':
-      value_print (value_from_longest (builtin_type_true_char, val_long),
-                  stream, 0, Val_pretty_default);
+      {
+       struct value_print_options opts = *options;
+       opts.format = 0;
+       if (TYPE_UNSIGNED (type))
+         value_print (value_from_longest (builtin_type_true_unsigned_char,
+                                          val_long),
+                      stream, &opts);
+       else
+         value_print (value_from_longest (builtin_type_true_char, val_long),
+                      stream, &opts);
+      }
       break;
 
     case 'f':
-      if (len == TYPE_LENGTH (builtin_type_float))
-        type = builtin_type_float;
-      else if (len == TYPE_LENGTH (builtin_type_double))
-        type = builtin_type_double;
-      else if (len == TYPE_LENGTH (builtin_type_long_double))
-        type = builtin_type_long_double;
+      type = float_type_from_length (current_gdbarch, type);
       print_floating (valaddr, type, stream);
       break;
 
@@ -470,7 +507,7 @@ print_scalar_formatted (const void *valaddr, struct type *type,
       break;
 
     default:
-      error (_("Undefined output format \"%c\"."), format);
+      error (_("Undefined output format \"%c\"."), options->format);
     }
 }
 
@@ -478,14 +515,15 @@ print_scalar_formatted (const void *valaddr, struct type *type,
    The `info lines' command uses this.  */
 
 void
-set_next_address (CORE_ADDR addr)
+set_next_address (struct gdbarch *gdbarch, CORE_ADDR addr)
 {
+  struct type *ptr_type = builtin_type (gdbarch)->builtin_data_ptr;
+
   next_address = addr;
 
   /* Make address available to the user as $_.  */
   set_internalvar (lookup_internalvar ("_"),
-                  value_from_pointer (lookup_pointer_type (builtin_type_void),
-                                      addr));
+                  value_from_pointer (ptr_type, addr));
 }
 
 /* Optionally print address ADDR symbolically as <SYMBOL+OFFSET> on STREAM,
@@ -560,9 +598,8 @@ build_address_symbolic (CORE_ADDR addr,  /* IN */
 {
   struct minimal_symbol *msymbol;
   struct symbol *symbol;
-  struct symtab *symtab = 0;
   CORE_ADDR name_location = 0;
-  asection *section = 0;
+  struct obj_section *section = NULL;
   char *name_temp = "";
   
   /* Let's say it is unmapped.  */
@@ -598,7 +635,7 @@ build_address_symbolic (CORE_ADDR addr,  /* IN */
       if (do_demangle || asm_demangle)
        name_temp = SYMBOL_PRINT_NAME (symbol);
       else
-       name_temp = DEPRECATED_SYMBOL_NAME (symbol);
+       name_temp = SYMBOL_LINKAGE_NAME (symbol);
     }
 
   if (msymbol != NULL)
@@ -608,12 +645,11 @@ build_address_symbolic (CORE_ADDR addr,  /* IN */
          /* The msymbol is closer to the address than the symbol;
             use the msymbol instead.  */
          symbol = 0;
-         symtab = 0;
          name_location = SYMBOL_VALUE_ADDRESS (msymbol);
          if (do_demangle || asm_demangle)
            name_temp = SYMBOL_PRINT_NAME (msymbol);
          else
-           name_temp = DEPRECATED_SYMBOL_NAME (msymbol);
+           name_temp = SYMBOL_LINKAGE_NAME (msymbol);
        }
     }
   if (symbol == NULL && msymbol == NULL)
@@ -645,37 +681,10 @@ build_address_symbolic (CORE_ADDR addr,  /* IN */
          *filename = xstrdup (sal.symtab->filename);
          *line = sal.line;
        }
-      else if (symtab && symbol && symbol->line)
-       {
-         *filename = xstrdup (symtab->filename);
-         *line = symbol->line;
-       }
-      else if (symtab)
-       {
-         *filename = xstrdup (symtab->filename);
-         *line = -1;
-       }
     }
   return 0;
 }
 
-/* Print address ADDR on STREAM.  USE_LOCAL means the same thing as for
-   print_longest.  */
-void
-deprecated_print_address_numeric (CORE_ADDR addr, int use_local,
-                                 struct ui_file *stream)
-{
-  if (use_local)
-    fputs_filtered (paddress (addr), stream);
-  else
-    {
-      int addr_bit = TARGET_ADDR_BIT;
-
-      if (addr_bit < (sizeof (CORE_ADDR) * HOST_CHAR_BIT))
-       addr &= ((CORE_ADDR) 1 << addr_bit) - 1;
-      print_longest (stream, 'x', 0, (ULONGEST) addr);
-    }
-}
 
 /* Print address ADDR symbolically on STREAM.
    First print it as a number.  Then perhaps print
@@ -684,7 +693,7 @@ deprecated_print_address_numeric (CORE_ADDR addr, int use_local,
 void
 print_address (CORE_ADDR addr, struct ui_file *stream)
 {
-  deprecated_print_address_numeric (addr, 1, stream);
+  fputs_filtered (paddress (addr), stream);
   print_address_symbolic (addr, stream, asm_demangle, " ");
 }
 
@@ -697,13 +706,15 @@ void
 print_address_demangle (CORE_ADDR addr, struct ui_file *stream,
                        int do_demangle)
 {
+  struct value_print_options opts;
+  get_user_print_options (&opts);
   if (addr == 0)
     {
       fprintf_filtered (stream, "0");
     }
-  else if (addressprint)
+  else if (opts.addressprint)
     {
-      deprecated_print_address_numeric (addr, 1, stream);
+      fputs_filtered (paddress (addr), stream);
       print_address_symbolic (addr, stream, do_demangle, " ");
     }
   else
@@ -735,6 +746,7 @@ do_examine (struct format_data fmt, CORE_ADDR addr)
   struct type *val_type = NULL;
   int i;
   int maxelts;
+  struct value_print_options opts;
 
   format = fmt.format;
   size = fmt.size;
@@ -765,6 +777,8 @@ do_examine (struct format_data fmt, CORE_ADDR addr)
   if (format == 's' || format == 'i')
     maxelts = 1;
 
+  get_formatted_print_options (&opts, format);
+
   /* Print as many objects as specified in COUNT, at most maxelts per line,
      with the address of the next one at the start of each line.  */
 
@@ -786,8 +800,8 @@ do_examine (struct format_data fmt, CORE_ADDR addr)
            value_free (last_examine_value);
 
          /* The value to be displayed is not fetched greedily.
-            Instead, to avoid the posibility of a fetched value not
-            being used, its retreval is delayed until the print code
+            Instead, to avoid the possibility of a fetched value not
+            being used, its retrieval is delayed until the print code
             uses it.  When examining an instruction stream, the
             disassembler will perform its own memory fetch using just
             the address stored in LAST_EXAMINE_VALUE.  FIXME: Should
@@ -799,7 +813,11 @@ do_examine (struct format_data fmt, CORE_ADDR addr)
          if (last_examine_value)
            release_value (last_examine_value);
 
-         print_formatted (last_examine_value, format, size, gdb_stdout);
+         print_formatted (last_examine_value, size, &opts, gdb_stdout);
+
+         /* Display any branch delay slots following the final insn.  */
+         if (format == 'i' && count == 1)
+           count += branch_delay_insns;
        }
       printf_filtered ("\n");
       gdb_flush (gdb_stdout);
@@ -814,7 +832,7 @@ validate_format (struct format_data fmt, char *cmdname)
   if (fmt.count != 1)
     error (_("Item count other than 1 is meaningless in \"%s\" command."),
           cmdname);
-  if (fmt.format == 'i' || fmt.format == 's')
+  if (fmt.format == 'i')
     error (_("Format letter \"%c\" is meaningless in \"%s\" command."),
           fmt.format, cmdname);
 }
@@ -833,10 +851,6 @@ print_command_1 (char *exp, int inspect, int voidprint)
   struct format_data fmt;
   int cleanup = 0;
 
-  /* Pass inspect flag to the rest of the print routines in a global
-     (sigh).  */
-  inspect_it = inspect;
-
   if (exp && *exp == '/')
     {
       exp++;
@@ -865,6 +879,7 @@ print_command_1 (char *exp, int inspect, int voidprint)
   if (voidprint || (val && value_type (val) &&
                    TYPE_CODE (value_type (val)) != TYPE_CODE_VOID))
     {
+      struct value_print_options opts;
       int histindex = record_latest_value (val);
 
       if (histindex >= 0)
@@ -881,7 +896,10 @@ print_command_1 (char *exp, int inspect, int voidprint)
       if (histindex >= 0)
        annotate_value_history_value ();
 
-      print_formatted (val, format, fmt.size, gdb_stdout);
+      get_formatted_print_options (&opts, format);
+      opts.inspect_it = inspect;
+
+      print_formatted (val, fmt.size, &opts, gdb_stdout);
       printf_filtered ("\n");
 
       if (histindex >= 0)
@@ -895,7 +913,6 @@ print_command_1 (char *exp, int inspect, int voidprint)
 
   if (cleanup)
     do_cleanups (old_chain);
-  inspect_it = 0;              /* Reset print routines to normal.  */
 }
 
 static void
@@ -928,6 +945,7 @@ output_command (char *exp, int from_tty)
   char format = 0;
   struct value *val;
   struct format_data fmt;
+  struct value_print_options opts;
 
   fmt.size = 0;
 
@@ -946,7 +964,8 @@ output_command (char *exp, int from_tty)
 
   annotate_value_begin (value_type (val));
 
-  print_formatted (val, format, fmt.size, gdb_stdout);
+  get_formatted_print_options (&opts, format);
+  print_formatted (val, fmt.size, &opts, gdb_stdout);
 
   annotate_value_end ();
 
@@ -972,7 +991,6 @@ sym_info (char *arg, int from_tty)
   struct minimal_symbol *msymbol;
   struct objfile *objfile;
   struct obj_section *osect;
-  asection *sect;
   CORE_ADDR addr, sect_addr;
   int matches = 0;
   unsigned int offset;
@@ -988,27 +1006,71 @@ sym_info (char *arg, int from_tty)
     if (objfile->separate_debug_objfile_backlink)
       continue;
 
-    sect = osect->the_bfd_section;
-    sect_addr = overlay_mapped_address (addr, sect);
+    sect_addr = overlay_mapped_address (addr, osect);
 
-    if (osect->addr <= sect_addr && sect_addr < osect->endaddr &&
-       (msymbol = lookup_minimal_symbol_by_pc_section (sect_addr, sect)))
+    if (obj_section_addr (osect) <= sect_addr
+       && sect_addr < obj_section_endaddr (osect)
+       && (msymbol = lookup_minimal_symbol_by_pc_section (sect_addr, osect)))
       {
+       const char *obj_name, *mapped, *sec_name, *msym_name;
+       char *loc_string;
+       struct cleanup *old_chain;
+
        matches = 1;
        offset = sect_addr - SYMBOL_VALUE_ADDRESS (msymbol);
+       mapped = section_is_mapped (osect) ? _("mapped") : _("unmapped");
+       sec_name = osect->the_bfd_section->name;
+       msym_name = SYMBOL_PRINT_NAME (msymbol);
+
+       /* Don't print the offset if it is zero.
+          We assume there's no need to handle i18n of "sym + offset".  */
        if (offset)
-         printf_filtered ("%s + %u in ",
-                          SYMBOL_PRINT_NAME (msymbol), offset);
+         xasprintf (&loc_string, "%s + %u", msym_name, offset);
        else
-         printf_filtered ("%s in ",
-                          SYMBOL_PRINT_NAME (msymbol));
-       if (pc_in_unmapped_range (addr, sect))
-         printf_filtered (_("load address range of "));
-       if (section_is_overlay (sect))
-         printf_filtered (_("%s overlay "),
-                          section_is_mapped (sect) ? "mapped" : "unmapped");
-       printf_filtered (_("section %s"), sect->name);
-       printf_filtered ("\n");
+         xasprintf (&loc_string, "%s", msym_name);
+
+       /* Use a cleanup to free loc_string in case the user quits
+          a pagination request inside printf_filtered.  */
+       old_chain = make_cleanup (xfree, loc_string);
+
+       gdb_assert (osect->objfile && osect->objfile->name);
+       obj_name = osect->objfile->name;
+
+       if (MULTI_OBJFILE_P ())
+         if (pc_in_unmapped_range (addr, osect))
+           if (section_is_overlay (osect))
+             printf_filtered (_("%s in load address range of "
+                                "%s overlay section %s of %s\n"),
+                              loc_string, mapped, sec_name, obj_name);
+           else
+             printf_filtered (_("%s in load address range of "
+                                "section %s of %s\n"),
+                              loc_string, sec_name, obj_name);
+         else
+           if (section_is_overlay (osect))
+             printf_filtered (_("%s in %s overlay section %s of %s\n"),
+                              loc_string, mapped, sec_name, obj_name);
+           else
+             printf_filtered (_("%s in section %s of %s\n"),
+                              loc_string, sec_name, obj_name);
+       else
+         if (pc_in_unmapped_range (addr, osect))
+           if (section_is_overlay (osect))
+             printf_filtered (_("%s in load address range of %s overlay "
+                                "section %s\n"),
+                              loc_string, mapped, sec_name);
+           else
+             printf_filtered (_("%s in load address range of section %s\n"),
+                              loc_string, sec_name);
+         else
+           if (section_is_overlay (osect))
+             printf_filtered (_("%s in %s overlay section %s\n"),
+                              loc_string, mapped, sec_name);
+           else
+             printf_filtered (_("%s in section %s\n"),
+                              loc_string, sec_name);
+
+       do_cleanups (old_chain);
       }
   }
   if (matches == 0)
@@ -1021,8 +1083,7 @@ address_info (char *exp, int from_tty)
   struct symbol *sym;
   struct minimal_symbol *msymbol;
   long val;
-  long basereg;
-  asection *section;
+  struct obj_section *section;
   CORE_ADDR load_addr;
   int is_a_field_of_this;      /* C++: lookup_symbol sets this to nonzero
                                   if exp is a field of `this'. */
@@ -1031,7 +1092,7 @@ address_info (char *exp, int from_tty)
     error (_("Argument required."));
 
   sym = lookup_symbol (exp, get_selected_block (0), VAR_DOMAIN,
-                      &is_a_field_of_this, (struct symtab **) NULL);
+                      &is_a_field_of_this);
   if (sym == NULL)
     {
       if (is_a_field_of_this)
@@ -1057,15 +1118,16 @@ address_info (char *exp, int from_tty)
          fprintf_symbol_filtered (gdb_stdout, exp,
                                   current_language->la_language, DMGL_ANSI);
          printf_filtered ("\" is at ");
-         deprecated_print_address_numeric (load_addr, 1, gdb_stdout);
+         fputs_filtered (paddress (load_addr), gdb_stdout);
          printf_filtered (" in a file compiled without debugging");
-         section = SYMBOL_BFD_SECTION (msymbol);
+         section = SYMBOL_OBJ_SECTION (msymbol);
          if (section_is_overlay (section))
            {
              load_addr = overlay_unmapped_address (load_addr, section);
              printf_filtered (",\n -- loaded at ");
-             deprecated_print_address_numeric (load_addr, 1, gdb_stdout);
-             printf_filtered (" in overlay section %s", section->name);
+             fputs_filtered (paddress (load_addr), gdb_stdout);
+             printf_filtered (" in overlay section %s",
+                              section->the_bfd_section->name);
            }
          printf_filtered (".\n");
        }
@@ -1075,12 +1137,11 @@ address_info (char *exp, int from_tty)
     }
 
   printf_filtered ("Symbol \"");
-  fprintf_symbol_filtered (gdb_stdout, DEPRECATED_SYMBOL_NAME (sym),
+  fprintf_symbol_filtered (gdb_stdout, SYMBOL_PRINT_NAME (sym),
                           current_language->la_language, DMGL_ANSI);
   printf_filtered ("\" is ");
   val = SYMBOL_VALUE (sym);
-  basereg = SYMBOL_BASEREG (sym);
-  section = SYMBOL_BFD_SECTION (sym);
+  section = SYMBOL_OBJ_SECTION (sym);
 
   switch (SYMBOL_CLASS (sym))
     {
@@ -1091,19 +1152,19 @@ address_info (char *exp, int from_tty)
 
     case LOC_LABEL:
       printf_filtered ("a label at address ");
-      deprecated_print_address_numeric (load_addr = SYMBOL_VALUE_ADDRESS (sym),
-                            1, gdb_stdout);
+      fputs_filtered (paddress (load_addr = SYMBOL_VALUE_ADDRESS (sym)),
+                     gdb_stdout);
       if (section_is_overlay (section))
        {
          load_addr = overlay_unmapped_address (load_addr, section);
          printf_filtered (",\n -- loaded at ");
-         deprecated_print_address_numeric (load_addr, 1, gdb_stdout);
-         printf_filtered (" in overlay section %s", section->name);
+         fputs_filtered (paddress (load_addr), gdb_stdout);
+         printf_filtered (" in overlay section %s",
+                          section->the_bfd_section->name);
        }
       break;
 
     case LOC_COMPUTED:
-    case LOC_COMPUTED_ARG:
       /* FIXME: cagney/2004-01-26: It should be possible to
         unconditionally call the SYMBOL_OPS method when available.
         Unfortunately DWARF 2 stores the frame-base (instead of the
@@ -1113,53 +1174,37 @@ address_info (char *exp, int from_tty)
       break;
 
     case LOC_REGISTER:
-      printf_filtered (_("a variable in register %s"), REGISTER_NAME (val));
+      if (SYMBOL_IS_ARGUMENT (sym))
+       printf_filtered (_("an argument in register %s"),
+                        gdbarch_register_name (current_gdbarch, val));
+      else
+       printf_filtered (_("a variable in register %s"),
+                        gdbarch_register_name (current_gdbarch, val));
       break;
 
     case LOC_STATIC:
       printf_filtered (_("static storage at address "));
-      deprecated_print_address_numeric (load_addr = SYMBOL_VALUE_ADDRESS (sym),
-                            1, gdb_stdout);
-      if (section_is_overlay (section))
-       {
-         load_addr = overlay_unmapped_address (load_addr, section);
-         printf_filtered (_(",\n -- loaded at "));
-         deprecated_print_address_numeric (load_addr, 1, gdb_stdout);
-         printf_filtered (_(" in overlay section %s"), section->name);
-       }
-      break;
-
-    case LOC_INDIRECT:
-      printf_filtered (_("external global (indirect addressing), at address *("));
-      deprecated_print_address_numeric (load_addr = SYMBOL_VALUE_ADDRESS (sym),
-                            1, gdb_stdout);
-      printf_filtered (")");
+     fputs_filtered (paddress (load_addr = SYMBOL_VALUE_ADDRESS (sym)),
+                    gdb_stdout);
       if (section_is_overlay (section))
        {
          load_addr = overlay_unmapped_address (load_addr, section);
          printf_filtered (_(",\n -- loaded at "));
-         deprecated_print_address_numeric (load_addr, 1, gdb_stdout);
-         printf_filtered (_(" in overlay section %s"), section->name);
+         fputs_filtered (paddress (load_addr), gdb_stdout);
+         printf_filtered (_(" in overlay section %s"),
+                          section->the_bfd_section->name);
        }
       break;
 
-    case LOC_REGPARM:
-      printf_filtered (_("an argument in register %s"), REGISTER_NAME (val));
-      break;
-
     case LOC_REGPARM_ADDR:
       printf_filtered (_("address of an argument in register %s"),
-                      REGISTER_NAME (val));
+                      gdbarch_register_name (current_gdbarch, val));
       break;
 
     case LOC_ARG:
       printf_filtered (_("an argument at offset %ld"), val);
       break;
 
-    case LOC_LOCAL_ARG:
-      printf_filtered (_("an argument at frame offset %ld"), val);
-      break;
-
     case LOC_LOCAL:
       printf_filtered (_("a local variable at frame offset %ld"), val);
       break;
@@ -1168,16 +1213,6 @@ address_info (char *exp, int from_tty)
       printf_filtered (_("a reference argument at offset %ld"), val);
       break;
 
-    case LOC_BASEREG:
-      printf_filtered (_("a variable at offset %ld from register %s"),
-                      val, REGISTER_NAME (basereg));
-      break;
-
-    case LOC_BASEREG_ARG:
-      printf_filtered (_("an argument at offset %ld from register %s"),
-                      val, REGISTER_NAME (basereg));
-      break;
-
     case LOC_TYPEDEF:
       printf_filtered (_("a typedef"));
       break;
@@ -1185,13 +1220,14 @@ address_info (char *exp, int from_tty)
     case LOC_BLOCK:
       printf_filtered (_("a function at address "));
       load_addr = BLOCK_START (SYMBOL_BLOCK_VALUE (sym));
-      deprecated_print_address_numeric (load_addr, 1, gdb_stdout);
+      fputs_filtered (paddress (load_addr), gdb_stdout);
       if (section_is_overlay (section))
        {
          load_addr = overlay_unmapped_address (load_addr, section);
          printf_filtered (_(",\n -- loaded at "));
-         deprecated_print_address_numeric (load_addr, 1, gdb_stdout);
-         printf_filtered (_(" in overlay section %s"), section->name);
+         fputs_filtered (paddress (load_addr), gdb_stdout);
+         printf_filtered (_(" in overlay section %s"),
+                          section->the_bfd_section->name);
        }
       break;
 
@@ -1199,32 +1235,36 @@ address_info (char *exp, int from_tty)
       {
        struct minimal_symbol *msym;
 
-       msym = lookup_minimal_symbol (DEPRECATED_SYMBOL_NAME (sym), NULL, NULL);
+       msym = lookup_minimal_symbol (SYMBOL_LINKAGE_NAME (sym), NULL, NULL);
        if (msym == NULL)
          printf_filtered ("unresolved");
        else
          {
-           section = SYMBOL_BFD_SECTION (msym);
-           printf_filtered (_("static storage at address "));
+           section = SYMBOL_OBJ_SECTION (msym);
            load_addr = SYMBOL_VALUE_ADDRESS (msym);
-           deprecated_print_address_numeric (load_addr, 1, gdb_stdout);
-           if (section_is_overlay (section))
+
+           if (section
+               && (section->the_bfd_section->flags & SEC_THREAD_LOCAL) != 0)
+             printf_filtered (_("a thread-local variable at offset %s "
+                                "in the thread-local storage for `%s'"),
+                              paddr_nz (load_addr), section->objfile->name);
+           else
              {
-               load_addr = overlay_unmapped_address (load_addr, section);
-               printf_filtered (_(",\n -- loaded at "));
-               deprecated_print_address_numeric (load_addr, 1, gdb_stdout);
-               printf_filtered (_(" in overlay section %s"), section->name);
+               printf_filtered (_("static storage at address "));
+               fputs_filtered (paddress (load_addr), gdb_stdout);
+               if (section_is_overlay (section))
+                 {
+                   load_addr = overlay_unmapped_address (load_addr, section);
+                   printf_filtered (_(",\n -- loaded at "));
+                   fputs_filtered (paddress (load_addr), gdb_stdout);
+                   printf_filtered (_(" in overlay section %s"),
+                                    section->the_bfd_section->name);
+                 }
              }
          }
       }
       break;
 
-    case LOC_HP_THREAD_LOCAL_STATIC:
-      printf_filtered (_("\
-a thread-local variable at offset %ld from the thread base register %s"),
-                      val, REGISTER_NAME (basereg));
-      break;
-
     case LOC_OPTIMIZED_OUT:
       printf_filtered (_("optimized out"));
       break;
@@ -1509,7 +1549,7 @@ do_one_display (struct display *d)
       print_expression (d->exp, gdb_stdout);
       annotate_display_expression_end ();
 
-      if (d->format.count != 1)
+      if (d->format.count != 1 || d->format.format == 'i')
        printf_filtered ("\n");
       else
        printf_filtered ("  ");
@@ -1517,7 +1557,7 @@ do_one_display (struct display *d)
       val = evaluate_expression (d->exp);
       addr = value_as_address (val);
       if (d->format.format == 'i')
-       addr = ADDR_BITS_REMOVE (addr);
+       addr = gdbarch_addr_bits_remove (current_gdbarch, addr);
 
       annotate_display_value ();
 
@@ -1525,6 +1565,8 @@ do_one_display (struct display *d)
     }
   else
     {
+      struct value_print_options opts;
+
       annotate_display_format ();
 
       if (d->format.format)
@@ -1539,8 +1581,9 @@ do_one_display (struct display *d)
 
       annotate_display_expression ();
 
+      get_formatted_print_options (&opts, d->format.format);
       print_formatted (evaluate_expression (d->exp),
-                      d->format.format, d->format.size, gdb_stdout);
+                      d->format.size, &opts, gdb_stdout);
       printf_filtered ("\n");
     }
 
@@ -1688,15 +1731,28 @@ disable_display_command (char *args, int from_tty)
 \f
 
 /* Print the value in stack frame FRAME of a variable specified by a
-   struct symbol.  */
+   struct symbol.  NAME is the name to print; if NULL then VAR's print
+   name will be used.  STREAM is the ui_file on which to print the
+   value.  INDENT specifies the number of indent levels to print
+   before printing the variable name.  */
 
 void
-print_variable_value (struct symbol *var, struct frame_info *frame,
-                     struct ui_file *stream)
+print_variable_and_value (const char *name, struct symbol *var,
+                         struct frame_info *frame,
+                         struct ui_file *stream, int indent)
 {
-  struct value *val = read_var_value (var, frame);
+  struct value *val;
+  struct value_print_options opts;
+
+  if (!name)
+    name = SYMBOL_PRINT_NAME (var);
 
-  value_print (val, stream, 0, Val_pretty_default);
+  fprintf_filtered (stream, "%s%s = ", n_spaces (2 * indent), name);
+
+  val = read_var_value (var, frame);
+  get_user_print_options (&opts);
+  common_val_print (val, stream, indent, &opts, current_language);
+  fprintf_filtered (stream, "\n");
 }
 
 static void
@@ -1807,7 +1863,7 @@ printf_command (char *arg, int from_tty)
     enum argclass
       {
        int_arg, long_arg, long_long_arg, ptr_arg, string_arg,
-       double_arg, long_double_arg
+       double_arg, long_double_arg, decfloat_arg
       };
     enum argclass *argclass;
     enum argclass this_argclass;
@@ -1824,7 +1880,8 @@ printf_command (char *arg, int from_tty)
        {
          int seen_hash = 0, seen_zero = 0, lcount = 0, seen_prec = 0;
          int seen_space = 0, seen_plus = 0;
-         int seen_big_l = 0, seen_h = 0;
+         int seen_big_l = 0, seen_h = 0, seen_big_h = 0;
+         int seen_big_d = 0, seen_double_big_d = 0;
          int bad = 0;
 
          /* Check the validity of the format specifier, and work
@@ -1888,6 +1945,26 @@ printf_command (char *arg, int from_tty)
              seen_big_l = 1;
              f++;
            }
+         /* Decimal32 modifier.  */
+         else if (*f == 'H')
+           {
+             seen_big_h = 1;
+             f++;
+           }
+         /* Decimal64 and Decimal128 modifiers.  */
+         else if (*f == 'D')
+           {
+             f++;
+
+             /* Check for a Decimal128.  */
+             if (*f == 'D')
+               {
+                 f++;
+                 seen_double_big_d = 1;
+               }
+             else
+               seen_big_d = 1;
+           }
 
          switch (*f)
            {
@@ -1945,7 +2022,9 @@ printf_command (char *arg, int from_tty)
            case 'g':
            case 'E':
            case 'G':
-             if (seen_big_l)
+             if (seen_big_h || seen_big_d || seen_double_big_d)
+               this_argclass = decfloat_arg;
+             else if (seen_big_l)
                this_argclass = long_double_arg;
              else
                this_argclass = double_arg;
@@ -1972,8 +2051,23 @@ printf_command (char *arg, int from_tty)
                   *f);
 
          f++;
-         strncpy (current_substring, last_arg, f - last_arg);
-         current_substring += f - last_arg;
+
+         if (lcount > 1 && USE_PRINTF_I64)
+           {
+             /* Windows' printf does support long long, but not the usual way.
+                Convert %lld to %I64d.  */
+             int length_before_ll = f - last_arg - 1 - lcount;
+             strncpy (current_substring, last_arg, length_before_ll);
+             strcpy (current_substring + length_before_ll, "I64");
+             current_substring[length_before_ll + 3] =
+               last_arg[length_before_ll + lcount];
+             current_substring += length_before_ll + 4;
+           }
+         else
+           {
+             strncpy (current_substring, last_arg, f - last_arg);
+             current_substring += f - last_arg;
+           }
          *current_substring++ = '\0';
          last_arg = f;
          argclass[nargs_wanted++] = this_argclass;
@@ -1992,17 +2086,6 @@ printf_command (char *arg, int from_tty)
        s1 = s;
        val_args[nargs] = parse_to_comma_and_eval (&s1);
 
-       /* If format string wants a float, unchecked-convert the value to
-          floating point of the same size */
-
-       if (argclass[nargs] == double_arg)
-         {
-           struct type *type = value_type (val_args[nargs]);
-           if (TYPE_LENGTH (type) == sizeof (float))
-             deprecated_set_value_type (val_args[nargs], builtin_type_float);
-           if (TYPE_LENGTH (type) == sizeof (double))
-             deprecated_set_value_type (val_args[nargs], builtin_type_double);
-         }
        nargs++;
        s = s1;
        if (*s == ',')
@@ -2046,15 +2129,35 @@ printf_command (char *arg, int from_tty)
            break;
          case double_arg:
            {
-             double val = value_as_double (val_args[i]);
-             printf_filtered (current_substring, val);
+             struct type *type = value_type (val_args[i]);
+             DOUBLEST val;
+             int inv;
+
+             /* If format string wants a float, unchecked-convert the value
+                to floating point of the same size.  */
+             type = float_type_from_length (current_gdbarch, type);
+             val = unpack_double (type, value_contents (val_args[i]), &inv);
+             if (inv)
+               error (_("Invalid floating value found in program."));
+
+             printf_filtered (current_substring, (double) val);
              break;
            }
          case long_double_arg:
 #ifdef HAVE_LONG_DOUBLE
            {
-             long double val = value_as_double (val_args[i]);
-             printf_filtered (current_substring, val);
+             struct type *type = value_type (val_args[i]);
+             DOUBLEST val;
+             int inv;
+
+             /* If format string wants a float, unchecked-convert the value
+                to floating point of the same size.  */
+             type = float_type_from_length (current_gdbarch, type);
+             val = unpack_double (type, value_contents (val_args[i]), &inv);
+             if (inv)
+               error (_("Invalid floating value found in program."));
+
+             printf_filtered (current_substring, (long double) val);
              break;
            }
 #else
@@ -2082,9 +2185,168 @@ printf_command (char *arg, int from_tty)
              printf_filtered (current_substring, val);
              break;
            }
+
+         /* Handles decimal floating values.  */
+       case decfloat_arg:
+           {
+             const gdb_byte *param_ptr = value_contents (val_args[i]);
+#if defined (PRINTF_HAS_DECFLOAT)
+             /* If we have native support for Decimal floating
+                printing, handle it here.  */
+             printf_filtered (current_substring, param_ptr);
+#else
+
+             /* As a workaround until vasprintf has native support for DFP
+              we convert the DFP values to string and print them using
+              the %s format specifier.  */
+
+             char *eos, *sos;
+             int nnull_chars = 0;
+
+             /* Parameter data.  */
+             struct type *param_type = value_type (val_args[i]);
+             unsigned int param_len = TYPE_LENGTH (param_type);
+
+             /* DFP output data.  */
+             struct value *dfp_value = NULL;
+             gdb_byte *dfp_ptr;
+             int dfp_len = 16;
+             gdb_byte dec[16];
+             struct type *dfp_type = NULL;
+             char decstr[MAX_DECIMAL_STRING];
+
+             /* Points to the end of the string so that we can go back
+                and check for DFP length modifiers.  */
+             eos = current_substring + strlen (current_substring);
+
+             /* Look for the float/double format specifier.  */
+             while (*eos != 'f' && *eos != 'e' && *eos != 'E'
+                    && *eos != 'g' && *eos != 'G')
+                 eos--;
+
+             sos = eos;
+
+             /* Search for the '%' char and extract the size and type of
+                the output decimal value based on its modifiers
+                (%Hf, %Df, %DDf).  */
+             while (*--sos != '%')
+               {
+                 if (*sos == 'H')
+                   {
+                     dfp_len = 4;
+                     dfp_type = builtin_type (current_gdbarch)->builtin_decfloat;
+                   }
+                 else if (*sos == 'D' && *(sos - 1) == 'D')
+                   {
+                     dfp_len = 16;
+                     dfp_type = builtin_type (current_gdbarch)->builtin_declong;
+                     sos--;
+                   }
+                 else
+                   {
+                     dfp_len = 8;
+                     dfp_type = builtin_type (current_gdbarch)->builtin_decdouble;
+                   }
+               }
+
+             /* Replace %Hf, %Df and %DDf with %s's.  */
+             *++sos = 's';
+
+             /* Go through the whole format string and pull the correct
+                number of chars back to compensate for the change in the
+                format specifier.  */
+             while (nnull_chars < nargs - i)
+               {
+                 if (*eos == '\0')
+                   nnull_chars++;
+
+                 *++sos = *++eos;
+               }
+
+             /* Conversion between different DFP types.  */
+             if (TYPE_CODE (param_type) == TYPE_CODE_DECFLOAT)
+               decimal_convert (param_ptr, param_len, dec, dfp_len);
+             else
+               /* If this is a non-trivial conversion, just output 0.
+                  A correct converted value can be displayed by explicitly
+                  casting to a DFP type.  */
+               decimal_from_string (dec, dfp_len, "0");
+
+             dfp_value = value_from_decfloat (dfp_type, dec);
+
+             dfp_ptr = (gdb_byte *) value_contents (dfp_value);
+
+             decimal_to_string (dfp_ptr, dfp_len, decstr);
+
+             /* Print the DFP value.  */
+             printf_filtered (current_substring, decstr);
+
+             break;
+#endif
+           }
+
+         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;
@@ -2201,7 +2463,7 @@ Call a function in the program.\n\
 The argument is the function name and arguments, in the notation of the\n\
 current working language.  The result is printed and saved in the value\n\
 history, if it is not void."));
-  set_cmd_completer (c, location_completer);
+  set_cmd_completer (c, expression_completer);
 
   add_cmd ("variable", class_vars, set_command, _("\
 Evaluate expression EXP and assign result to variable VAR, using assignment\n\
@@ -2234,13 +2496,13 @@ resides in memory.\n\
 \n\
 EXP may be preceded with /FMT, where FMT is a format letter\n\
 but no count or size letter (see \"x\" command)."));
-  set_cmd_completer (c, location_completer);
+  set_cmd_completer (c, expression_completer);
   add_com_alias ("p", "print", class_vars, 1);
 
   c = add_com ("inspect", class_vars, inspect_command, _("\
 Same as \"print\" command, except that if you are running in the epoch\n\
 environment, the value is printed in its own window."));
-  set_cmd_completer (c, location_completer);
+  set_cmd_completer (c, expression_completer);
 
   add_setshow_uinteger_cmd ("max-symbolic-offset", no_class,
                            &max_symbolic_offset, _("\