* breakpoint.c, breakpoint.h (breakpoint_init_inferior): New function
[deliverable/binutils-gdb.git] / gdb / printcmd.c
index 191e573ca9493d291969de23580a41200d27fc55..f6820c49166b604d13198667e88c274545035800 100644 (file)
@@ -32,12 +32,6 @@ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.  */
 #include "breakpoint.h"
 #include "demangle.h"
 
-/* These are just for containing_function_bounds.  It might be better
-   to move containing_function_bounds to blockframe.c or thereabouts.  */
-#include "bfd.h"
-#include "symfile.h"
-#include "objfiles.h"
-
 extern int asm_demangle;       /* Whether to demangle syms in asm printouts */
 extern int addressprint;       /* Whether to print hex addresses in HLL " */
 
@@ -128,9 +122,6 @@ 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));
 
@@ -223,13 +214,6 @@ decode_format (string_ptr, oformat, osize)
     {
       if (*p == 'b' || *p == 'h' || *p == 'w' || *p == 'g')
        val.size = *p++;
-#ifdef CC_HAS_LONG_LONG
-      else if (*p == 'l')
-       {
-         val.size = 'g';
-         p++;
-       }
-#endif
       else if (*p >= 'a' && *p <= 'z')
        val.format = *p++;
       else
@@ -377,15 +361,13 @@ print_scalar_formatted (valaddr, type, format, size, stream)
 
   val_long = unpack_long (type, valaddr);
 
-  /* If value is unsigned, truncate it in case negative.  */
+  /* 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 (len == sizeof (char))
-       val_long &= (1 << 8 * sizeof(char)) - 1;
-      else if (len == sizeof (short))
-       val_long &= (1 << 8 * sizeof(short)) - 1;
-      else if (len == sizeof (long))
-       val_long &= (unsigned long) - 1;
+      if (len < sizeof (LONGEST))
+       val_long &= ((LONGEST) 1 << HOST_CHAR_BIT * len) - 1;
     }
 
   switch (format)
@@ -596,10 +578,13 @@ print_address (addr, stream)
      CORE_ADDR addr;
      FILE *stream;
 {
-#ifdef ADDR_BITS_REMOVE
-  fprintf_filtered (stream, local_hex_format(), ADDR_BITS_REMOVE(addr));
+#if 0 && defined (ADDR_BITS_REMOVE)
+  /* This is wrong for pointer to char, in which we do want to print
+     the low bits.  */
+  fprintf_filtered (stream, local_hex_format(),
+                   (unsigned long) ADDR_BITS_REMOVE(addr));
 #else
-  fprintf_filtered (stream, local_hex_format(), addr);
+  fprintf_filtered (stream, local_hex_format(), (unsigned long) addr);
 #endif
   print_address_symbolic (addr, stream, asm_demangle, " ");
 }
@@ -618,7 +603,7 @@ print_address_demangle (addr, stream, do_demangle)
   if (addr == 0) {
     fprintf_filtered (stream, "0");
   } else if (addressprint) {
-    fprintf_filtered (stream, local_hex_format(), addr);
+    fprintf_filtered (stream, local_hex_format(), (unsigned long) addr);
     print_address_symbolic (addr, stream, do_demangle, " ");
   } else {
     print_address_symbolic (addr, stream, do_demangle, "");
@@ -637,7 +622,7 @@ do_examine (fmt, addr)
   register char format = 0;
   register char size;
   register int count = 1;
-  struct type *val_type;
+  struct type *val_type = NULL;
   register int i;
   register int maxelts;
 
@@ -651,18 +636,17 @@ do_examine (fmt, addr)
   if (format == 's' || format == 'i')
     size = 'b';
 
+  /* I don't think the TYPE_CODE, TYPE_NAME, or TYPE_FLAGS matter.
+     This is just a (fairly twisted) way of telling print_formatted
+     the right length.  */
   if (size == 'b')
-    val_type = builtin_type_char;
+    val_type = init_type (TYPE_CODE_INT, 1, 0, NULL, NULL);
   else if (size == 'h')
-    val_type = builtin_type_short;
+    val_type = init_type (TYPE_CODE_INT, 2, 0, NULL, NULL);
   else if (size == 'w')
-    val_type = builtin_type_long;
+    val_type = init_type (TYPE_CODE_INT, 4, 0, NULL, NULL);
   else if (size == 'g')
-#ifndef CC_HAS_LONG_LONG
-    val_type = builtin_type_double;
-#else
-    val_type = builtin_type_long_long;
-#endif
+    val_type = init_type (TYPE_CODE_INT, 8, 0, NULL, NULL);
 
   maxelts = 8;
   if (size == 'w')
@@ -693,6 +677,7 @@ do_examine (fmt, addr)
       printf_filtered ("\n");
       fflush (stdout);
     }
+  free (val_type);
 }
 \f
 static void
@@ -901,7 +886,8 @@ address_info (exp, from_tty)
 
       if (msymbol != NULL)
        printf ("Symbol \"%s\" is at %s in a file compiled without debugging.\n",
-               exp, local_hex_string(SYMBOL_VALUE_ADDRESS (msymbol)));
+               exp,
+               local_hex_string((unsigned long) SYMBOL_VALUE_ADDRESS (msymbol)));
       else
        error ("No symbol \"%s\" in current context.", exp);
       return;
@@ -919,7 +905,8 @@ address_info (exp, from_tty)
       break;
 
     case LOC_LABEL:
-      printf ("a label at address %s", local_hex_string(SYMBOL_VALUE_ADDRESS (sym)));
+      printf ("a label at address %s",
+             local_hex_string((unsigned long) SYMBOL_VALUE_ADDRESS (sym)));
       break;
 
     case LOC_REGISTER:
@@ -927,64 +914,51 @@ address_info (exp, from_tty)
       break;
 
     case LOC_STATIC:
-      printf ("static storage at address %s", local_hex_string(SYMBOL_VALUE_ADDRESS (sym)));
+      printf ("static storage at address %s",
+             local_hex_string((unsigned long) SYMBOL_VALUE_ADDRESS (sym)));
       break;
 
     case LOC_REGPARM:
       printf ("an argument in register %s", reg_names[val]);
       break;
 
-   case LOC_REGPARM_ADDR:
-     printf ("address of an argument in register %s", reg_names[val]);
-     break;
-      
+    case LOC_REGPARM_ADDR:
+      printf ("address of an argument in register %s", reg_names[val]);
+      break;
+
     case LOC_ARG:
-      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);
-       }
+      printf ("an argument at offset %ld", val);
       break;
 
     case LOC_LOCAL_ARG:
-      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);
-       }
+      printf ("an argument at frame offset %ld", val);
       break;
 
     case LOC_LOCAL:
-      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);
-       }
+      printf ("a local variable at frame offset %ld", val);
       break;
 
     case LOC_REF_ARG:
       printf ("a reference argument at offset %ld", val);
       break;
 
+    case LOC_BASEREG:
+      printf ("a variable at offset %ld from register %s",
+             val, reg_names[basereg]);
+      break;
+
+    case LOC_BASEREG_ARG:
+      printf ("an argument at offset %ld from register %s",
+             val, reg_names[basereg]);
+      break;
+
     case LOC_TYPEDEF:
       printf ("a typedef");
       break;
 
     case LOC_BLOCK:
       printf ("a function at address %s",
-             local_hex_string(BLOCK_START (SYMBOL_BLOCK_VALUE (sym))));
+             local_hex_string((unsigned long) BLOCK_START (SYMBOL_BLOCK_VALUE (sym))));
       break;
 
     case LOC_OPTIMIZED_OUT:
@@ -1445,7 +1419,7 @@ print_frame_args (func, fi, num, stream)
      int num;
      FILE *stream;
 {
-  struct block *b;
+  struct block *b = NULL;
   int nsyms = 0;
   int first = 1;
   register int i;
@@ -1501,6 +1475,7 @@ print_frame_args (func, fi, num, stream)
       case LOC_REGPARM:
       case LOC_REGPARM_ADDR:
       case LOC_LOCAL_ARG:
+      case LOC_BASEREG_ARG:
        break;
 
       /* Other types of symbols we just skip over.  */
@@ -1612,18 +1587,6 @@ print_frame_nameless_args (fi, start, num, first, stream)
     }
 }
 \f
-/* Make makeva* work on an __INT_VARARGS_H machine.  */
-
-#if defined (__INT_VARARGS_H)
-/* This is used on an 88k.  Not sure whether it is used by anything else.  */
-#define MAKEVA_END(list) \
-  va_list retval; \
-  retval.__va_arg = 0; \
-  retval.__va_stk = (int *) (list)->arg_bytes; \
-  retval.__va_reg = (int *) (list)->arg_bytes; \
-  return retval;
-#endif
-\f
 /* This is an interface which allows to us make a va_list.  */
 typedef struct {
   unsigned int nargs;
@@ -1632,7 +1595,19 @@ typedef struct {
   /* Current position in bytes.  */
   unsigned int argindex;
 
-  char arg_bytes[1];
+#ifdef MAKEVA_EXTRA_INFO
+  /* For host dependent information.  */
+  MAKEVA_EXTRA_INFO
+#endif
+
+  /* Some systems (mips, pa) would like this to be aligned, and it never
+     will hurt.  */
+  union
+    {
+      char arg_bytes[1];
+      double force_double_align;
+      LONGEST force_long_align;
+    } aligner;
 } makeva_list;
 
 /* Tell the caller how many bytes to allocate for a makeva_list with NARGS
@@ -1643,7 +1618,11 @@ makeva_size (nargs, max_arg_size)
      unsigned int nargs;
      unsigned int max_arg_size;
 {
+#if defined (MAKEVA_SIZE)
+  MAKEVA_SIZE (nargs, max_arg_size);
+#else
   return sizeof (makeva_list) + nargs * max_arg_size;
+#endif
 }
 
 /* Start working on LIST with NARGS arguments and whose largest
@@ -1673,7 +1652,7 @@ makeva_arg (list, argaddr, argsize)
 #if defined (MAKEVA_ARG)
   MAKEVA_ARG (list, argaddr, argsize);
 #else
-  memcpy (&list->arg_bytes[list->argindex], argaddr, argsize);
+  memcpy (&list->aligner.arg_bytes[list->argindex], argaddr, argsize);
   list->argindex += argsize;
 #endif
 }
@@ -1688,7 +1667,7 @@ makeva_end (list)
   MAKEVA_END (list);
 #else
   /* This works if a va_list is just a pointer to the arguments.  */
-  return (va_list) list->arg_bytes;
+  return (va_list) list->aligner.arg_bytes;
 #endif
 }
 \f
@@ -1781,6 +1760,11 @@ printf_command (arg, from_tty)
     int nargs_wanted;
     int lcount;
     int i;
+    /* We build up a va_list to pass to vprintf.  This is unnecessary;
+       instead of calling vprintf ("%d%f", <constructed va_list>) we
+       could just call printf ("%d", arg1); printf ("%f", arg2);.  Funny
+       how I thought of that right *after* I got the MAKEVA stuff pretty much
+       working...  */
     makeva_list *args_makeva;
 
     argclass = (enum argclass *) alloca (strlen (s) * sizeof *argclass);
@@ -1806,10 +1790,10 @@ printf_command (arg, from_tty)
            argclass[nargs_wanted++] = int_arg;
          f++;
        }
+
     /* Now, parse all arguments and evaluate them.
        Store the VALUEs in VAL_ARGS.  */
+
     while (*s != '\0')
       {
        char *s1;
@@ -1904,41 +1888,6 @@ printf_command (arg, from_tty)
   vprintf (string, args_to_vprintf);
 }
 \f
-/* Helper function for asdump_command.  Finds the bounds of a function
-   for a specified section of text.  PC is an address within the
-   function which you want bounds for; *LOW and *HIGH are set to the
-   beginning (inclusive) and end (exclusive) of the function.  This
-   function returns 1 on success and 0 on failure.  */
-
-static int
-containing_function_bounds (pc, low, high)
-     CORE_ADDR pc, *low, *high;
-{
-  CORE_ADDR scan;
-  CORE_ADDR limit;
-  struct obj_section *sec;
-
-  if (!find_pc_partial_function (pc, 0, low))
-    return 0;
-
-  sec = find_pc_section (pc);
-  if (sec == NULL)
-    return 0;
-  limit = sec->endaddr;
-  
-  scan = *low;
-  while (scan < limit)
-    {
-      ++scan;
-      if (!find_pc_partial_function (scan, 0, high))
-       return 0;
-      if (*low != *high)
-       return 1;
-    }
-  *high = limit;
-  return 1;
-}
-
 /* Dump a specified section of assembly code.  With no command line
    arguments, this command will dump the assembly code for the
    function surrounding the pc value in the selected frame.  With one
@@ -1953,24 +1902,26 @@ disassemble_command (arg, from_tty)
      int from_tty;
 {
   CORE_ADDR low, high;
+  char *name;
   CORE_ADDR pc;
   char *space_index;
 
+  name = NULL;
   if (!arg)
     {
       if (!selected_frame)
        error ("No frame selected.\n");
 
       pc = get_frame_pc (selected_frame);
-      if (!containing_function_bounds (pc, &low, &high))
-       error ("No function contains pc specified by selected frame.\n");
+      if (find_pc_partial_function (pc, &name, &low, &high) == 0)
+       error ("No function contains program counter for selected frame.\n");
     }
   else if (!(space_index = (char *) strchr (arg, ' ')))
     {
       /* One argument.  */
       pc = parse_and_eval_address (arg);
-      if (!containing_function_bounds (pc, &low, &high))
-       error ("No function contains specified pc.\n");
+      if (find_pc_partial_function (pc, &name, &low, &high) == 0)
+       error ("No function contains specified address.\n");
     }
   else
     {
@@ -1981,16 +1932,14 @@ disassemble_command (arg, from_tty)
     }
 
   printf_filtered ("Dump of assembler code ");
-  if (!space_index)
+  if (name != NULL)
     {
-      char *name;
-      find_pc_partial_function (pc, &name, 0);
       printf_filtered ("for function %s:\n", name);
     }
   else
     {
-      printf_filtered ("from %s ", local_hex_string(low));
-      printf_filtered ("to %s:\n", local_hex_string(high));
+      printf_filtered ("from %s ", local_hex_string((unsigned long) low));
+      printf_filtered ("to %s:\n", local_hex_string((unsigned long) high));
     }
 
   /* Dump the specified range.  */
This page took 0.027935 seconds and 4 git commands to generate.