* i386b-nat.c: Comment changes.
[deliverable/binutils-gdb.git] / gdb / printcmd.c
index ec96d4919c7863af3d90a7db595a33ce0288987a..0434df4a8b49490237d3cb346b1b4c314817af20 100644 (file)
@@ -1,5 +1,5 @@
 /* Print values for GNU debugger GDB.
-   Copyright (C) 1986-1991 Free Software Foundation, Inc.
+   Copyright 1986, 1987, 1988, 1989, 1990, 1991 Free Software Foundation, Inc.
 
 This file is part of GDB.
 
@@ -17,26 +17,23 @@ 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., 675 Mass Ave, Cambridge, MA 02139, USA.  */
 
-#include <stdio.h>
-#include <string.h>
 #include "defs.h"
-#include "param.h"
+#include <string.h>
 #include "frame.h"
 #include "symtab.h"
+#include "gdbtypes.h"
 #include "value.h"
 #include "language.h"
 #include "expression.h"
 #include "gdbcore.h"
 #include "gdbcmd.h"
 #include "target.h"
+#include "breakpoint.h"
+#include "demangle.h"
 
 extern int asm_demangle;       /* Whether to demangle syms in asm printouts */
 extern int addressprint;       /* Whether to print hex addresses in HLL " */
 
-extern struct block *get_current_block ();
-
-static void print_frame_nameless_args ();
-
 struct format_data
 {
   int count;
@@ -78,10 +75,114 @@ int current_display_number;
 
 int inspect_it = 0;
 
-static void do_one_display ();
+struct display
+{
+  /* Chain link to next auto-display item.  */
+  struct display *next;
+  /* Expression to be evaluated and displayed.  */
+  struct expression *exp;
+  /* Item number of this auto-display item.  */
+  int number;
+  /* Display format specified.  */
+  struct format_data format;
+  /* Innermost block required by this expression when evaluated */
+  struct block *block;
+  /* Status of this display (enabled or disabled) */
+  enum enable status;
+};
+
+/* Chain of expressions whose values should be displayed
+   automatically each time the program stops.  */
+
+static struct display *display_chain;
+
+static int display_number;
+
+/* Prototypes for local functions */
+
+static void
+delete_display PARAMS ((int));
+
+static void
+enable_display PARAMS ((char *, int));
+
+static void
+disable_display_command PARAMS ((char *, int));
+
+static void
+disassemble_command PARAMS ((char *, int));
+
+static int
+containing_function_bounds PARAMS ((CORE_ADDR, CORE_ADDR *, CORE_ADDR *));
+
+static void
+printf_command PARAMS ((char *, int));
+
+static void
+print_frame_nameless_args PARAMS ((CORE_ADDR, long, int, int, FILE *));
+
+static void
+display_info PARAMS ((char *, int));
+
+static void
+do_one_display PARAMS ((struct display *));
+
+static void
+undisplay_command PARAMS ((char *, int));
+
+static void
+free_display PARAMS ((struct display *));
+
+static void
+display_command PARAMS ((char *, int));
+
+static void
+ptype_command PARAMS ((char *, int));
+
+static struct type *
+ptype_eval PARAMS ((struct expression *));
+
+static void
+whatis_command PARAMS ((char *, int));
+
+static void
+whatis_exp PARAMS ((char *, int));
+
+static void
+x_command PARAMS ((char *, int));
+
+static void
+address_info PARAMS ((char *, int));
+
+static void
+set_command PARAMS ((char *, int));
+
+static void
+output_command PARAMS ((char *, int));
+
+static void
+call_command PARAMS ((char *, int));
+
+static void
+inspect_command PARAMS ((char *, int));
 
-void do_displays ();
-void print_scalar_formatted ();
+static void
+print_command PARAMS ((char *, int));
+
+static void
+print_command_1 PARAMS ((char *, int, int));
+
+static void
+validate_format PARAMS ((struct format_data, char *));
+
+static void
+do_examine PARAMS ((struct format_data, CORE_ADDR));
+
+static void
+print_formatted PARAMS ((value, int, int));
+
+static struct format_data
+decode_format PARAMS ((char **, int, int));
 
 \f
 /* Decode a format specification.  *STRING_PTR should point to it.
@@ -94,11 +195,11 @@ void print_scalar_formatted ();
    found in the specification.  In addition, *STRING_PTR is advanced
    past the specification and past all whitespace following it.  */
 
-struct format_data
+static struct format_data
 decode_format (string_ptr, oformat, osize)
      char **string_ptr;
-     char oformat;
-     char osize;
+     int oformat;
+     int osize;
 {
   struct format_data val;
   register char *p = *string_ptr;
@@ -192,8 +293,8 @@ decode_format (string_ptr, oformat, osize)
 static void
 print_formatted (val, format, size)
      register value val;
-     register char format;
-     char size;
+     register int format;
+     int size;
 {
   int len = TYPE_LENGTH (VALUE_TYPE (val));
 
@@ -237,7 +338,7 @@ void
 print_scalar_formatted (valaddr, type, format, size, stream)
      char *valaddr;
      struct type *type;
-     char format;
+     int format;
      int size;
      FILE *stream;
 {
@@ -468,20 +569,20 @@ print_address_symbolic (addr, stream, do_demangle, leadin)
      char *leadin;
 {
   int name_location;
-  register int i = find_pc_misc_function (addr);
+  register struct minimal_symbol *msymbol = lookup_minimal_symbol_by_pc (addr);
 
   /* If nothing comes out, don't print anything symbolic.  */
   
-  if (i < 0)
+  if (msymbol == NULL)
     return;
 
   fputs_filtered (leadin, stream);
   fputs_filtered ("<", stream);
   if (do_demangle)
-    fputs_demangled (misc_function_vector[i].name, stream, 1);
+    fputs_demangled (msymbol -> name, stream, DMGL_ANSI | DMGL_PARAMS);
   else
-    fputs_filtered (misc_function_vector[i].name, stream);
-  name_location = misc_function_vector[i].address;
+    fputs_filtered (msymbol -> name, stream);
+  name_location = msymbol -> address;
   if (addr - name_location)
     fprintf_filtered (stream, "+%d>", addr - name_location);
   else
@@ -497,7 +598,11 @@ print_address (addr, stream)
      CORE_ADDR addr;
      FILE *stream;
 {
+#ifdef ADDR_BITS_REMOVE
+  fprintf_filtered (stream, local_hex_format(), ADDR_BITS_REMOVE(addr));
+#else
   fprintf_filtered (stream, local_hex_format(), addr);
+#endif
   print_address_symbolic (addr, stream, asm_demangle, " ");
 }
 
@@ -650,9 +755,10 @@ print_command_1 (exp, inspect, voidprint)
       type = VALUE_TYPE (val);
 
       if (objectprint
-         && (TYPE_CODE (type) == TYPE_CODE_PTR
+         && (   TYPE_CODE (type) == TYPE_CODE_PTR
              || TYPE_CODE (type) == TYPE_CODE_REF)
-         && TYPE_CODE (TYPE_TARGET_TYPE (type)) == TYPE_CODE_STRUCT)
+         && (   TYPE_CODE (TYPE_TARGET_TYPE (type)) == TYPE_CODE_STRUCT
+             || TYPE_CODE (TYPE_TARGET_TYPE (type)) == TYPE_CODE_UNION))
        {
          value v;
 
@@ -735,7 +841,7 @@ output_command (exp, from_tty)
     {
       exp++;
       fmt = decode_format (&exp, 0, 0);
-      validate_format (fmt, "print");
+      validate_format (fmt, "output");
       format = fmt.format;
     }
 
@@ -769,7 +875,9 @@ address_info (exp, from_tty)
      int from_tty;
 {
   register struct symbol *sym;
+  register struct minimal_symbol *msymbol;
   register long val;
+  register long basereg;
   int is_a_field_of_this;      /* C++: lookup_symbol sets this to nonzero
                                   if exp is a field of `this'. */
 
@@ -780,21 +888,17 @@ address_info (exp, from_tty)
                       &is_a_field_of_this, (struct symtab **)NULL);
   if (sym == 0)
     {
-      register int i;
-
       if (is_a_field_of_this)
        {
          printf ("Symbol \"%s\" is a field of the local class variable `this'\n", exp);
          return;
        }
 
-      for (i = 0; i < misc_function_count; i++)
-       if (!strcmp (misc_function_vector[i].name, exp))
-         break;
+      msymbol = lookup_minimal_symbol (exp, (struct objfile *) NULL);
 
-      if (i < misc_function_count)
+      if (msymbol != NULL)
        printf ("Symbol \"%s\" is at %s in a file compiled without debugging.\n",
-               exp, local_hex_string(misc_function_vector[i].address));
+               exp, local_hex_string(msymbol -> address));
       else
        error ("No symbol \"%s\" in current context.", exp);
       return;
@@ -802,6 +906,7 @@ address_info (exp, from_tty)
 
   printf ("Symbol \"%s\" is ", SYMBOL_NAME (sym));
   val = SYMBOL_VALUE (sym);
+  basereg = SYMBOL_BASEREG (sym);
 
   switch (SYMBOL_CLASS (sym))
     {
@@ -827,15 +932,39 @@ address_info (exp, from_tty)
       break;
       
     case LOC_ARG:
-      printf ("an argument at offset %ld", val);
+      if (SYMBOL_BASEREG_VALID (sym))
+       {
+         printf ("an argument at offset %ld from register %s",
+                 val, reg_names[basereg]);
+       }
+      else
+       {
+         printf ("an argument at offset %ld", val);
+       }
       break;
 
     case LOC_LOCAL_ARG:
-      printf ("an argument at frame offset %ld", val);
+      if (SYMBOL_BASEREG_VALID (sym))
+       {
+         printf ("an argument at offset %ld from register %s",
+                 val, reg_names[basereg]);
+       }
+      else
+       {
+         printf ("an argument at frame offset %ld", val);
+       }
       break;
 
     case LOC_LOCAL:
-      printf ("a local variable at frame offset %ld", val);
+      if (SYMBOL_BASEREG_VALID (sym))
+       {
+         printf ("a local variable at offset %ld from register %s",
+                 val, reg_names[basereg]);
+       }
+      else
+       {
+         printf ("a local variable at frame offset %ld", val);
+       }
       break;
 
     case LOC_REF_ARG:
@@ -876,8 +1005,6 @@ x_command (exp, from_tty)
     {
       exp++;
       fmt = decode_format (&exp, last_format, last_size);
-      last_size = fmt.size;
-      last_format = fmt.format;
     }
 
   /* If we have an expression, evaluate it and use it as the address.  */
@@ -907,6 +1034,10 @@ x_command (exp, from_tty)
 
   do_examine (fmt, next_address);
 
+  /* If the examine succeeds, we remember its size and format for next time.  */
+  last_size = fmt.size;
+  last_format = fmt.format;
+
   /* Set a couple of internal variables if appropriate. */
   if (last_examine_value)
     {
@@ -1010,31 +1141,6 @@ ptype_command (typename, from_tty)
      whatis_exp (typename, 1);
 }
 \f
-enum display_status {disabled, enabled};
-
-struct display
-{
-  /* Chain link to next auto-display item.  */
-  struct display *next;
-  /* Expression to be evaluated and displayed.  */
-  struct expression *exp;
-  /* Item number of this auto-display item.  */
-  int number;
-  /* Display format specified.  */
-  struct format_data format;
-  /* Innermost block required by this expression when evaluated */
-  struct block *block;
-  /* Status of this display (enabled or disabled) */
-  enum display_status status;
-};
-
-/* Chain of expressions whose values should be displayed
-   automatically each time the program stops.  */
-
-static struct display *display_chain;
-
-static int display_number;
-
 /* Add an expression to the auto-display chain.
    Specify the expression.  */
 
@@ -1092,8 +1198,8 @@ static void
 free_display (d)
      struct display *d;
 {
-  free (d->exp);
-  free (d);
+  free ((PTR)d->exp);
+  free ((PTR)d);
 }
 
 /* Clear out the display_chain.
@@ -1107,15 +1213,15 @@ clear_displays ()
 
   while (d = display_chain)
     {
-      free (d->exp);
+      free ((PTR)d->exp);
       display_chain = d->next;
-      free (d);
+      free ((PTR)d);
     }
 }
 
 /* Delete the auto-display number NUM.  */
 
-void
+static void
 delete_display (num)
      int num;
 {
@@ -1149,8 +1255,9 @@ delete_display (num)
    Specify the element numbers.  */
 
 static void
-undisplay_command (args)
+undisplay_command (args, from_tty)
      char *args;
+     int from_tty;
 {
   register char *p = args;
   register char *p1;
@@ -1285,7 +1392,9 @@ disable_current_display ()
 }
 
 static void
-display_info ()
+display_info (ignore, from_tty)
+     char *ignore;
+     int from_tty;
 {
   register struct display *d;
 
@@ -1311,9 +1420,10 @@ Num Enb Expression\n");
     }
 }
 
-void
-enable_display (args)
+static void
+enable_display (args, from_tty)
      char *args;
+     int from_tty;
 {
   register char *p = args;
   register char *p1;
@@ -1351,7 +1461,7 @@ enable_display (args)
 }
 
 /* ARGSUSED */
-void
+static void
 disable_display_command (args, from_tty)
      char *args;
      int from_tty;
@@ -1477,6 +1587,13 @@ print_frame_args (func, fi, num, stream)
         two entries (one a parameter, one a register or local), and the one
         we want is the non-parm, which lookup_symbol will find for
         us.  After this, sym could be any SYMBOL_CLASS...  */
+#ifdef IBM6000_TARGET
+      /* AIX/RS6000 implements a concept of traceback tables, in which case
+         it creates nameless parameters. Looking for those parameter symbols
+        will result in an error. */
+
+      if ( *SYMBOL_NAME (sym))
+#endif
       sym = lookup_symbol (SYMBOL_NAME (sym),
                    b, VAR_NAMESPACE, (int *)NULL, (struct symtab **)NULL);
 
@@ -1675,7 +1792,7 @@ printf_command (arg, from_tty)
       {
        char *s1;
        if (nargs == allocated_args)
-         val_args = (value *) xrealloc (val_args,
+         val_args = (value *) xrealloc ((char *) val_args,
                                         (allocated_args *= 2)
                                         * sizeof (value));
        s1 = s;
@@ -1994,7 +2111,7 @@ where FOO is stored, etc.  FOO must be an expression whose value\n\
 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)."));
+but no count or size letter (see \"x\" command).", NULL));
   add_com_alias ("p", "print", class_vars, 1);
 
   add_com ("inspect", class_vars, inspect_command,
This page took 0.030179 seconds and 4 git commands to generate.