1999-01-19 Fernando Nasser <fnasser@totem.to.cygnus.com>
[deliverable/binutils-gdb.git] / gdb / printcmd.c
index ad1ad37a4a74497a341dc775c50d29105f593b3c..bbc4ba00c0e0286815c6c547462520e6133c1035 100644 (file)
@@ -1,5 +1,5 @@
 /* Print values for GNU debugger GDB.
-   Copyright 1986, 1987, 1988, 1989, 1990, 1991, 1993, 1994, 1995
+   Copyright 1986, 87, 88, 89, 90, 91, 93, 94, 95, 1998
    Free Software Foundation, Inc.
 
 This file is part of GDB.
@@ -121,12 +121,13 @@ static int display_number;
 int (*tm_print_insn) PARAMS ((bfd_vma, disassemble_info *));
 disassemble_info tm_print_insn_info;
 
-/* Functions exported for general use: */
+/* Prototypes for exported functions. */
 
 void output_command PARAMS ((char *, int));
 
+void _initialize_printcmd PARAMS ((void));
 
-/* Prototypes for local functions.  */
+/* Prototypes for local functions. */
 
 static void delete_display PARAMS ((int));
 
@@ -175,6 +176,8 @@ static struct format_data decode_format PARAMS ((char **, int, int));
 
 static int print_insn PARAMS ((CORE_ADDR, GDB_FILE *));
 
+static void sym_info PARAMS ((char *, int));
+
 \f
 /* Decode a format specification.  *STRING_PTR should point to it.
    OFORMAT and OSIZE are used as defaults for the format and size
@@ -293,8 +296,9 @@ print_formatted (val, format, size)
   switch (format)
     {
     case 's':
+      /* FIXME: Need to handle wchar_t's here... */
       next_address = VALUE_ADDRESS (val)
-       + val_print_string (VALUE_ADDRESS (val), 0, gdb_stdout);
+       + val_print_string (VALUE_ADDRESS (val), -1, 1, gdb_stdout);
       next_section = VALUE_BFD_SECTION (val);
       break;
 
@@ -688,6 +692,8 @@ print_address_demangle (addr, stream, do_demangle)
 /* These are the types that $__ will get after an examine command of one
    of these sizes.  */
 
+static struct type *examine_i_type;
+
 static struct type *examine_b_type;
 static struct type *examine_h_type;
 static struct type *examine_w_type;
@@ -720,7 +726,9 @@ do_examine (fmt, addr, sect)
   if (format == 's' || format == 'i')
     size = 'b';
 
-  if (size == 'b')
+  if (format == 'i')
+    val_type = examine_i_type;
+  else if (size == 'b')
     val_type = examine_b_type;
   else if (size == 'h')
     val_type = examine_h_type;
@@ -753,7 +761,16 @@ do_examine (fmt, addr, sect)
          /* Note that print_formatted sets next_address for the next
             object.  */
          last_examine_address = next_address;
-         last_examine_value = value_at (val_type, next_address, sect);
+         /* 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
+             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
+             the disassembler be modified so that LAST_EXAMINE_VALUE
+             is left with the byte sequence from the last complete
+             instruction fetched from memory? */
+         last_examine_value = value_at_lazy (val_type, next_address, sect);
          print_formatted (last_examine_value, format, size);
        }
       printf_filtered ("\n");
@@ -816,7 +833,8 @@ print_command_1 (exp, inspect, voidprint)
       extern int objectprint;
       struct type *type;
       expr = parse_expression (exp);
-      old_chain = make_cleanup (free_current_contents, &expr);
+      old_chain = make_cleanup ((make_cleanup_func) free_current_contents, 
+                                &expr);
       cleanup = 1;
       val = evaluate_expression (expr);
 
@@ -929,7 +947,7 @@ output_command (exp, from_tty)
     }
 
   expr = parse_expression (exp);
-  old_chain = make_cleanup (free_current_contents, &expr);
+  old_chain = make_cleanup ((make_cleanup_func) free_current_contents, &expr);
 
   val = evaluate_expression (expr);
 
@@ -950,7 +968,7 @@ set_command (exp, from_tty)
 {
   struct expression *expr = parse_expression (exp);
   register struct cleanup *old_chain
-    = make_cleanup (free_current_contents, &expr);
+    = make_cleanup ((make_cleanup_func) free_current_contents, &expr);
   evaluate_expression (expr);
   do_cleanups (old_chain);
 }
@@ -1089,7 +1107,7 @@ address_info (exp, from_tty)
       break;
 
     case LOC_REGISTER:
-      printf_filtered ("a variable in register %s", reg_names[val]);
+      printf_filtered ("a variable in register %s", REGISTER_NAME (val));
       break;
 
     case LOC_STATIC:
@@ -1106,11 +1124,11 @@ address_info (exp, from_tty)
       break;
 
     case LOC_REGPARM:
-      printf_filtered ("an argument in register %s", reg_names[val]);
+      printf_filtered ("an argument in register %s", REGISTER_NAME (val));
       break;
 
     case LOC_REGPARM_ADDR:
-      printf_filtered ("address of an argument in register %s", reg_names[val]);
+      printf_filtered ("address of an argument in register %s", REGISTER_NAME (val));
       break;
 
     case LOC_ARG:
@@ -1131,12 +1149,12 @@ address_info (exp, from_tty)
 
     case LOC_BASEREG:
       printf_filtered ("a variable at offset %ld from register %s",
-             val, reg_names[basereg]);
+             val, REGISTER_NAME (basereg));
       break;
 
     case LOC_BASEREG_ARG:
       printf_filtered ("an argument at offset %ld from register %s",
-             val, reg_names[basereg]);
+             val, REGISTER_NAME (basereg));
       break;
 
     case LOC_TYPEDEF:
@@ -1227,7 +1245,8 @@ x_command (exp, from_tty)
         But don't clobber a user-defined command's definition.  */
       if (from_tty)
        *exp = 0;
-      old_chain = make_cleanup (free_current_contents, &expr);
+      old_chain = make_cleanup ((make_cleanup_func) free_current_contents, 
+                                &expr);
       val = evaluate_expression (expr);
       if (TYPE_CODE (VALUE_TYPE (val)) == TYPE_CODE_REF)
        val = value_ind (val);
@@ -1261,7 +1280,13 @@ x_command (exp, from_tty)
                                   (LONGEST) last_examine_address));
       
       /* Make contents of last address examined available to the user as $__.*/
-      set_internalvar (lookup_internalvar ("__"), last_examine_value);
+      /* If the last value has not been fetched from memory then don't
+         fetch it now - instead mark it by voiding the $__ variable. */
+      if (VALUE_LAZY (last_examine_value))
+       set_internalvar (lookup_internalvar ("__"),
+                        allocate_value (builtin_type_void));
+      else
+       set_internalvar (lookup_internalvar ("__"), last_examine_value);
     }
 }
 
@@ -1897,9 +1922,9 @@ printf_command (arg, from_tty)
      char *arg;
      int from_tty;
 {
-  register char *f;
+  register char *f = NULL;
   register char *s = arg;
-  char *string;
+  char *string = NULL;
   value_ptr *val_args;
   char *substrings;
   char *current_substring;
@@ -1908,7 +1933,8 @@ printf_command (arg, from_tty)
   struct cleanup *old_cleanups;
 
   val_args = (value_ptr *) xmalloc (allocated_args * sizeof (value_ptr));
-  old_cleanups = make_cleanup (free_current_contents, &val_args);
+  old_cleanups = make_cleanup ((make_cleanup_func) free_current_contents, 
+                               &val_args);
 
   if (s == 0)
     error_no_arg ("format-control string and values to print");
@@ -2178,7 +2204,6 @@ disassemble_command (arg, from_tty)
   char *name;
   CORE_ADDR pc, pc_masked;
   char *space_index;
-  asection *section;
 
   name = NULL;
   if (!arg)
@@ -2190,7 +2215,6 @@ disassemble_command (arg, from_tty)
       if (find_pc_partial_function (pc, &name, &low, &high) == 0)
        error ("No function contains program counter for selected frame.\n");
       low += FUNCTION_START_OFFSET;
-      high -= 1;
     }
   else if (!(space_index = (char *) strchr (arg, ' ')))
     {
@@ -2199,20 +2223,6 @@ disassemble_command (arg, from_tty)
       if (find_pc_partial_function (pc, &name, &low, &high) == 0)
        error ("No function contains specified address.\n");
       low += FUNCTION_START_OFFSET;
-      high -= 1;
-      if (overlay_debugging)
-       {
-         section = find_pc_overlay (pc);
-         if (pc_in_unmapped_range (pc, section))
-           {
-             /* find_pc_partial_function will have returned low and high
-                relative to the symbolic (mapped) address range.  Need to
-                translate them back to the unmapped range where PC is.  */
-
-             low  = overlay_unmapped_address (low, section);
-             high = overlay_unmapped_address (high, section);
-           }
-       }
     }
   else
     {
@@ -2220,7 +2230,6 @@ disassemble_command (arg, from_tty)
       *space_index = '\0';
       low = parse_and_eval_address (arg);
       high = parse_and_eval_address (space_index + 1);
-      high -= 1;
     }
 
   printf_filtered ("Dump of assembler code ");
@@ -2246,7 +2255,7 @@ disassemble_command (arg, from_tty)
   pc_masked = pc;
 #endif
 
-  while (pc_masked <= high)
+  while (pc_masked < high)
     {
       QUIT;
       print_address (pc_masked, gdb_stdout);
@@ -2274,20 +2283,16 @@ print_insn (memaddr, stream)
      CORE_ADDR memaddr;
      GDB_FILE *stream;
 {
-  /* If there's no disassembler, something is very wrong.  */
-  if (tm_print_insn == NULL)
-    abort ();
-
   if (TARGET_BYTE_ORDER == BIG_ENDIAN)
-    tm_print_insn_info.endian = BFD_ENDIAN_BIG;
+    TARGET_PRINT_INSN_INFO->endian = BFD_ENDIAN_BIG;
   else
-    tm_print_insn_info.endian = BFD_ENDIAN_LITTLE;
+    TARGET_PRINT_INSN_INFO->endian = BFD_ENDIAN_LITTLE;
 
-  if (target_architecture != NULL)
-    tm_print_insn_info.mach = target_architecture->mach;
+  if (TARGET_ARCHITECTURE != NULL)
+    TARGET_PRINT_INSN_INFO->mach = TARGET_ARCHITECTURE->mach;
   /* else: should set .mach=0 but some disassemblers don't grok this */
 
-  return (*tm_print_insn) (memaddr, &tm_print_insn_info);
+  return TARGET_PRINT_INSN (memaddr, TARGET_PRINT_INSN_INFO);
 }
 
 \f
@@ -2442,6 +2447,11 @@ environment, the value is printed in its own window.");
                   &setprintlist),
       &showprintlist);
 
+  /* For examine/instruction a single byte quantity is specified as
+     the data.  This avoids problems with value_at_lazy() requiring a
+     valid data type (and rejecting VOID). */
+  examine_i_type = init_type (TYPE_CODE_INT, 1, 0, "examine_i_type", NULL);
+
   examine_b_type = init_type (TYPE_CODE_INT, 1, 0, "examine_b_type", NULL);
   examine_h_type = init_type (TYPE_CODE_INT, 2, 0, "examine_h_type", NULL);
   examine_w_type = init_type (TYPE_CODE_INT, 4, 0, "examine_w_type", NULL);
This page took 0.026957 seconds and 4 git commands to generate.