*** empty log message ***
[deliverable/binutils-gdb.git] / gdb / printcmd.c
index bbfef3e044165fb04e8499aca3227dfcd515825b..021e191c63dfaf6bf017aef5972a5a44fad62f6d 100644 (file)
@@ -309,6 +309,24 @@ print_formatted (struct value *val, int format, int size,
                            format, 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.
@@ -425,25 +443,16 @@ print_scalar_formatted (const void *valaddr, struct type *type,
 
     case 'c':
       if (TYPE_UNSIGNED (type))
-       {
-         struct type *utype;
-
-         utype = builtin_type (current_gdbarch)->builtin_true_unsigned_char;
-         value_print (value_from_longest (utype, val_long),
-                      stream, 0, Val_pretty_default);
-       }
+       value_print (value_from_longest (builtin_type_true_unsigned_char,
+                                        val_long),
+                    stream, 0, Val_pretty_default);
       else
        value_print (value_from_longest (builtin_type_true_char, val_long),
                     stream, 0, Val_pretty_default);
       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;
 
@@ -507,14 +516,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,
@@ -590,7 +600,7 @@ build_address_symbolic (CORE_ADDR addr,  /* IN */
   struct minimal_symbol *msymbol;
   struct symbol *symbol;
   CORE_ADDR name_location = 0;
-  asection *section = 0;
+  struct obj_section *section = NULL;
   char *name_temp = "";
   
   /* Let's say it is unmapped.  */
@@ -626,7 +636,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)
@@ -640,7 +650,7 @@ build_address_symbolic (CORE_ADDR addr,  /* IN */
          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)
@@ -976,7 +986,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;
@@ -992,11 +1001,11 @@ 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)))
       {
        matches = 1;
        offset = sect_addr - SYMBOL_VALUE_ADDRESS (msymbol);
@@ -1006,12 +1015,12 @@ sym_info (char *arg, int from_tty)
        else
          printf_filtered ("%s in ",
                           SYMBOL_PRINT_NAME (msymbol));
-       if (pc_in_unmapped_range (addr, sect))
+       if (pc_in_unmapped_range (addr, osect))
          printf_filtered (_("load address range of "));
-       if (section_is_overlay (sect))
+       if (section_is_overlay (osect))
          printf_filtered (_("%s overlay "),
-                          section_is_mapped (sect) ? "mapped" : "unmapped");
-       printf_filtered (_("section %s"), sect->name);
+                          section_is_mapped (osect) ? "mapped" : "unmapped");
+       printf_filtered (_("section %s"), osect->the_bfd_section->name);
        printf_filtered ("\n");
       }
   }
@@ -1025,7 +1034,7 @@ address_info (char *exp, int from_tty)
   struct symbol *sym;
   struct minimal_symbol *msymbol;
   long val;
-  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'. */
@@ -1062,13 +1071,14 @@ address_info (char *exp, int from_tty)
          printf_filtered ("\" is at ");
          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 ");
              fputs_filtered (paddress (load_addr), gdb_stdout);
-             printf_filtered (" in overlay section %s", section->name);
+             printf_filtered (" in overlay section %s",
+                              section->the_bfd_section->name);
            }
          printf_filtered (".\n");
        }
@@ -1078,11 +1088,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);
-  section = SYMBOL_BFD_SECTION (sym);
+  section = SYMBOL_OBJ_SECTION (sym);
 
   switch (SYMBOL_CLASS (sym))
     {
@@ -1100,7 +1110,8 @@ address_info (char *exp, int from_tty)
          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->name);
+         printf_filtered (" in overlay section %s",
+                          section->the_bfd_section->name);
        }
       break;
 
@@ -1131,7 +1142,8 @@ address_info (char *exp, int from_tty)
          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->name);
+         printf_filtered (_(" in overlay section %s"),
+                          section->the_bfd_section->name);
        }
       break;
 
@@ -1165,7 +1177,8 @@ address_info (char *exp, int from_tty)
          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->name);
+         printf_filtered (_(" in overlay section %s"),
+                          section->the_bfd_section->name);
        }
       break;
 
@@ -1173,12 +1186,12 @@ 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);
+           section = SYMBOL_OBJ_SECTION (msym);
            printf_filtered (_("static storage at address "));
            load_addr = SYMBOL_VALUE_ADDRESS (msym);
            fputs_filtered (paddress (load_addr), gdb_stdout);
@@ -1187,7 +1200,8 @@ address_info (char *exp, int from_tty)
                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->name);
+               printf_filtered (_(" in overlay section %s"),
+                                section->the_bfd_section->name);
              }
          }
       }
@@ -1998,17 +2012,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 == ',')
@@ -2052,15 +2055,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
@@ -2366,7 +2389,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\
@@ -2399,13 +2422,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, _("\
This page took 0.028187 seconds and 4 git commands to generate.