xref: /dflybsd-src/contrib/gdb-7/gdb/printcmd.c (revision de8e141f24382815c10a4012d209bbbf7abf1112)
15796c8dcSSimon Schubert /* Print values for GNU debugger GDB.
25796c8dcSSimon Schubert 
3*ef5ccd6cSJohn Marino    Copyright (C) 1986-2013 Free Software Foundation, Inc.
45796c8dcSSimon Schubert 
55796c8dcSSimon Schubert    This file is part of GDB.
65796c8dcSSimon Schubert 
75796c8dcSSimon Schubert    This program is free software; you can redistribute it and/or modify
85796c8dcSSimon Schubert    it under the terms of the GNU General Public License as published by
95796c8dcSSimon Schubert    the Free Software Foundation; either version 3 of the License, or
105796c8dcSSimon Schubert    (at your option) any later version.
115796c8dcSSimon Schubert 
125796c8dcSSimon Schubert    This program is distributed in the hope that it will be useful,
135796c8dcSSimon Schubert    but WITHOUT ANY WARRANTY; without even the implied warranty of
145796c8dcSSimon Schubert    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
155796c8dcSSimon Schubert    GNU General Public License for more details.
165796c8dcSSimon Schubert 
175796c8dcSSimon Schubert    You should have received a copy of the GNU General Public License
185796c8dcSSimon Schubert    along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
195796c8dcSSimon Schubert 
205796c8dcSSimon Schubert #include "defs.h"
215796c8dcSSimon Schubert #include "gdb_string.h"
225796c8dcSSimon Schubert #include "frame.h"
235796c8dcSSimon Schubert #include "symtab.h"
245796c8dcSSimon Schubert #include "gdbtypes.h"
255796c8dcSSimon Schubert #include "value.h"
265796c8dcSSimon Schubert #include "language.h"
275796c8dcSSimon Schubert #include "expression.h"
285796c8dcSSimon Schubert #include "gdbcore.h"
295796c8dcSSimon Schubert #include "gdbcmd.h"
305796c8dcSSimon Schubert #include "target.h"
315796c8dcSSimon Schubert #include "breakpoint.h"
325796c8dcSSimon Schubert #include "demangle.h"
33a45ae5f8SJohn Marino #include "gdb-demangle.h"
345796c8dcSSimon Schubert #include "valprint.h"
355796c8dcSSimon Schubert #include "annotate.h"
365796c8dcSSimon Schubert #include "symfile.h"		/* for overlay functions */
375796c8dcSSimon Schubert #include "objfiles.h"		/* ditto */
385796c8dcSSimon Schubert #include "completer.h"		/* for completion functions */
395796c8dcSSimon Schubert #include "ui-out.h"
405796c8dcSSimon Schubert #include "gdb_assert.h"
415796c8dcSSimon Schubert #include "block.h"
425796c8dcSSimon Schubert #include "disasm.h"
435796c8dcSSimon Schubert #include "dfp.h"
445796c8dcSSimon Schubert #include "valprint.h"
455796c8dcSSimon Schubert #include "exceptions.h"
465796c8dcSSimon Schubert #include "observer.h"
475796c8dcSSimon Schubert #include "solist.h"
485796c8dcSSimon Schubert #include "parser-defs.h"
495796c8dcSSimon Schubert #include "charset.h"
50cf7f2e2dSJohn Marino #include "arch-utils.h"
51c50c785cSJohn Marino #include "cli/cli-utils.h"
52*ef5ccd6cSJohn Marino #include "format.h"
53*ef5ccd6cSJohn Marino #include "source.h"
545796c8dcSSimon Schubert 
555796c8dcSSimon Schubert #ifdef TUI
56c50c785cSJohn Marino #include "tui/tui.h"		/* For tui_active et al.   */
575796c8dcSSimon Schubert #endif
585796c8dcSSimon Schubert 
595796c8dcSSimon Schubert struct format_data
605796c8dcSSimon Schubert   {
615796c8dcSSimon Schubert     int count;
625796c8dcSSimon Schubert     char format;
635796c8dcSSimon Schubert     char size;
645796c8dcSSimon Schubert 
655796c8dcSSimon Schubert     /* True if the value should be printed raw -- that is, bypassing
665796c8dcSSimon Schubert        python-based formatters.  */
675796c8dcSSimon Schubert     unsigned char raw;
685796c8dcSSimon Schubert   };
695796c8dcSSimon Schubert 
705796c8dcSSimon Schubert /* Last specified output format.  */
715796c8dcSSimon Schubert 
725796c8dcSSimon Schubert static char last_format = 0;
735796c8dcSSimon Schubert 
745796c8dcSSimon Schubert /* Last specified examination size.  'b', 'h', 'w' or `q'.  */
755796c8dcSSimon Schubert 
765796c8dcSSimon Schubert static char last_size = 'w';
775796c8dcSSimon Schubert 
785796c8dcSSimon Schubert /* Default address to examine next, and associated architecture.  */
795796c8dcSSimon Schubert 
805796c8dcSSimon Schubert static struct gdbarch *next_gdbarch;
815796c8dcSSimon Schubert static CORE_ADDR next_address;
825796c8dcSSimon Schubert 
835796c8dcSSimon Schubert /* Number of delay instructions following current disassembled insn.  */
845796c8dcSSimon Schubert 
855796c8dcSSimon Schubert static int branch_delay_insns;
865796c8dcSSimon Schubert 
875796c8dcSSimon Schubert /* Last address examined.  */
885796c8dcSSimon Schubert 
895796c8dcSSimon Schubert static CORE_ADDR last_examine_address;
905796c8dcSSimon Schubert 
915796c8dcSSimon Schubert /* Contents of last address examined.
925796c8dcSSimon Schubert    This is not valid past the end of the `x' command!  */
935796c8dcSSimon Schubert 
945796c8dcSSimon Schubert static struct value *last_examine_value;
955796c8dcSSimon Schubert 
965796c8dcSSimon Schubert /* Largest offset between a symbolic value and an address, that will be
975796c8dcSSimon Schubert    printed as `0x1234 <symbol+offset>'.  */
985796c8dcSSimon Schubert 
995796c8dcSSimon Schubert static unsigned int max_symbolic_offset = UINT_MAX;
1005796c8dcSSimon Schubert static void
show_max_symbolic_offset(struct ui_file * file,int from_tty,struct cmd_list_element * c,const char * value)1015796c8dcSSimon Schubert show_max_symbolic_offset (struct ui_file *file, int from_tty,
1025796c8dcSSimon Schubert 			  struct cmd_list_element *c, const char *value)
1035796c8dcSSimon Schubert {
104c50c785cSJohn Marino   fprintf_filtered (file,
105c50c785cSJohn Marino 		    _("The largest offset that will be "
106c50c785cSJohn Marino 		      "printed in <symbol+1234> form is %s.\n"),
1075796c8dcSSimon Schubert 		    value);
1085796c8dcSSimon Schubert }
1095796c8dcSSimon Schubert 
1105796c8dcSSimon Schubert /* Append the source filename and linenumber of the symbol when
1115796c8dcSSimon Schubert    printing a symbolic value as `<symbol at filename:linenum>' if set.  */
1125796c8dcSSimon Schubert static int print_symbol_filename = 0;
1135796c8dcSSimon Schubert static void
show_print_symbol_filename(struct ui_file * file,int from_tty,struct cmd_list_element * c,const char * value)1145796c8dcSSimon Schubert show_print_symbol_filename (struct ui_file *file, int from_tty,
1155796c8dcSSimon Schubert 			    struct cmd_list_element *c, const char *value)
1165796c8dcSSimon Schubert {
117c50c785cSJohn Marino   fprintf_filtered (file, _("Printing of source filename and "
118c50c785cSJohn Marino 			    "line number with <symbol> is %s.\n"),
1195796c8dcSSimon Schubert 		    value);
1205796c8dcSSimon Schubert }
1215796c8dcSSimon Schubert 
1225796c8dcSSimon Schubert /* Number of auto-display expression currently being displayed.
123a45ae5f8SJohn Marino    So that we can disable it if we get a signal within it.
1245796c8dcSSimon Schubert    -1 when not doing one.  */
1255796c8dcSSimon Schubert 
126*ef5ccd6cSJohn Marino static int current_display_number;
1275796c8dcSSimon Schubert 
1285796c8dcSSimon Schubert struct display
1295796c8dcSSimon Schubert   {
1305796c8dcSSimon Schubert     /* Chain link to next auto-display item.  */
1315796c8dcSSimon Schubert     struct display *next;
132cf7f2e2dSJohn Marino 
1335796c8dcSSimon Schubert     /* The expression as the user typed it.  */
1345796c8dcSSimon Schubert     char *exp_string;
135cf7f2e2dSJohn Marino 
1365796c8dcSSimon Schubert     /* Expression to be evaluated and displayed.  */
1375796c8dcSSimon Schubert     struct expression *exp;
138cf7f2e2dSJohn Marino 
1395796c8dcSSimon Schubert     /* Item number of this auto-display item.  */
1405796c8dcSSimon Schubert     int number;
141cf7f2e2dSJohn Marino 
1425796c8dcSSimon Schubert     /* Display format specified.  */
1435796c8dcSSimon Schubert     struct format_data format;
144cf7f2e2dSJohn Marino 
145cf7f2e2dSJohn Marino     /* Program space associated with `block'.  */
146cf7f2e2dSJohn Marino     struct program_space *pspace;
147cf7f2e2dSJohn Marino 
148c50c785cSJohn Marino     /* Innermost block required by this expression when evaluated.  */
149*ef5ccd6cSJohn Marino     const struct block *block;
150cf7f2e2dSJohn Marino 
151c50c785cSJohn Marino     /* Status of this display (enabled or disabled).  */
1525796c8dcSSimon Schubert     int enabled_p;
1535796c8dcSSimon Schubert   };
1545796c8dcSSimon Schubert 
1555796c8dcSSimon Schubert /* Chain of expressions whose values should be displayed
1565796c8dcSSimon Schubert    automatically each time the program stops.  */
1575796c8dcSSimon Schubert 
1585796c8dcSSimon Schubert static struct display *display_chain;
1595796c8dcSSimon Schubert 
1605796c8dcSSimon Schubert static int display_number;
1615796c8dcSSimon Schubert 
162c50c785cSJohn Marino /* Walk the following statement or block through all displays.
163c50c785cSJohn Marino    ALL_DISPLAYS_SAFE does so even if the statement deletes the current
164c50c785cSJohn Marino    display.  */
165c50c785cSJohn Marino 
166c50c785cSJohn Marino #define ALL_DISPLAYS(B)				\
167c50c785cSJohn Marino   for (B = display_chain; B; B = B->next)
168c50c785cSJohn Marino 
169c50c785cSJohn Marino #define ALL_DISPLAYS_SAFE(B,TMP)		\
170c50c785cSJohn Marino   for (B = display_chain;			\
171c50c785cSJohn Marino        B ? (TMP = B->next, 1): 0;		\
172c50c785cSJohn Marino        B = TMP)
173c50c785cSJohn Marino 
1745796c8dcSSimon Schubert /* Prototypes for exported functions.  */
1755796c8dcSSimon Schubert 
1765796c8dcSSimon Schubert void _initialize_printcmd (void);
1775796c8dcSSimon Schubert 
1785796c8dcSSimon Schubert /* Prototypes for local functions.  */
1795796c8dcSSimon Schubert 
1805796c8dcSSimon Schubert static void do_one_display (struct display *);
1815796c8dcSSimon Schubert 
1825796c8dcSSimon Schubert 
1835796c8dcSSimon Schubert /* Decode a format specification.  *STRING_PTR should point to it.
1845796c8dcSSimon Schubert    OFORMAT and OSIZE are used as defaults for the format and size
1855796c8dcSSimon Schubert    if none are given in the format specification.
1865796c8dcSSimon Schubert    If OSIZE is zero, then the size field of the returned value
1875796c8dcSSimon Schubert    should be set only if a size is explicitly specified by the
1885796c8dcSSimon Schubert    user.
1895796c8dcSSimon Schubert    The structure returned describes all the data
1905796c8dcSSimon Schubert    found in the specification.  In addition, *STRING_PTR is advanced
1915796c8dcSSimon Schubert    past the specification and past all whitespace following it.  */
1925796c8dcSSimon Schubert 
1935796c8dcSSimon Schubert static struct format_data
decode_format(char ** string_ptr,int oformat,int osize)1945796c8dcSSimon Schubert decode_format (char **string_ptr, int oformat, int osize)
1955796c8dcSSimon Schubert {
1965796c8dcSSimon Schubert   struct format_data val;
1975796c8dcSSimon Schubert   char *p = *string_ptr;
1985796c8dcSSimon Schubert 
1995796c8dcSSimon Schubert   val.format = '?';
2005796c8dcSSimon Schubert   val.size = '?';
2015796c8dcSSimon Schubert   val.count = 1;
2025796c8dcSSimon Schubert   val.raw = 0;
2035796c8dcSSimon Schubert 
2045796c8dcSSimon Schubert   if (*p >= '0' && *p <= '9')
2055796c8dcSSimon Schubert     val.count = atoi (p);
2065796c8dcSSimon Schubert   while (*p >= '0' && *p <= '9')
2075796c8dcSSimon Schubert     p++;
2085796c8dcSSimon Schubert 
2095796c8dcSSimon Schubert   /* Now process size or format letters that follow.  */
2105796c8dcSSimon Schubert 
2115796c8dcSSimon Schubert   while (1)
2125796c8dcSSimon Schubert     {
2135796c8dcSSimon Schubert       if (*p == 'b' || *p == 'h' || *p == 'w' || *p == 'g')
2145796c8dcSSimon Schubert 	val.size = *p++;
2155796c8dcSSimon Schubert       else if (*p == 'r')
2165796c8dcSSimon Schubert 	{
2175796c8dcSSimon Schubert 	  val.raw = 1;
2185796c8dcSSimon Schubert 	  p++;
2195796c8dcSSimon Schubert 	}
2205796c8dcSSimon Schubert       else if (*p >= 'a' && *p <= 'z')
2215796c8dcSSimon Schubert 	val.format = *p++;
2225796c8dcSSimon Schubert       else
2235796c8dcSSimon Schubert 	break;
2245796c8dcSSimon Schubert     }
2255796c8dcSSimon Schubert 
2265796c8dcSSimon Schubert   while (*p == ' ' || *p == '\t')
2275796c8dcSSimon Schubert     p++;
2285796c8dcSSimon Schubert   *string_ptr = p;
2295796c8dcSSimon Schubert 
2305796c8dcSSimon Schubert   /* Set defaults for format and size if not specified.  */
2315796c8dcSSimon Schubert   if (val.format == '?')
2325796c8dcSSimon Schubert     {
2335796c8dcSSimon Schubert       if (val.size == '?')
2345796c8dcSSimon Schubert 	{
2355796c8dcSSimon Schubert 	  /* Neither has been specified.  */
2365796c8dcSSimon Schubert 	  val.format = oformat;
2375796c8dcSSimon Schubert 	  val.size = osize;
2385796c8dcSSimon Schubert 	}
2395796c8dcSSimon Schubert       else
2405796c8dcSSimon Schubert 	/* If a size is specified, any format makes a reasonable
2415796c8dcSSimon Schubert 	   default except 'i'.  */
2425796c8dcSSimon Schubert 	val.format = oformat == 'i' ? 'x' : oformat;
2435796c8dcSSimon Schubert     }
2445796c8dcSSimon Schubert   else if (val.size == '?')
2455796c8dcSSimon Schubert     switch (val.format)
2465796c8dcSSimon Schubert       {
2475796c8dcSSimon Schubert       case 'a':
2485796c8dcSSimon Schubert 	/* Pick the appropriate size for an address.  This is deferred
2495796c8dcSSimon Schubert 	   until do_examine when we know the actual architecture to use.
2505796c8dcSSimon Schubert 	   A special size value of 'a' is used to indicate this case.  */
2515796c8dcSSimon Schubert 	val.size = osize ? 'a' : osize;
2525796c8dcSSimon Schubert 	break;
2535796c8dcSSimon Schubert       case 'f':
2545796c8dcSSimon Schubert 	/* Floating point has to be word or giantword.  */
2555796c8dcSSimon Schubert 	if (osize == 'w' || osize == 'g')
2565796c8dcSSimon Schubert 	  val.size = osize;
2575796c8dcSSimon Schubert 	else
2585796c8dcSSimon Schubert 	  /* Default it to giantword if the last used size is not
2595796c8dcSSimon Schubert 	     appropriate.  */
2605796c8dcSSimon Schubert 	  val.size = osize ? 'g' : osize;
2615796c8dcSSimon Schubert 	break;
2625796c8dcSSimon Schubert       case 'c':
2635796c8dcSSimon Schubert 	/* Characters default to one byte.  */
2645796c8dcSSimon Schubert 	val.size = osize ? 'b' : osize;
2655796c8dcSSimon Schubert 	break;
266cf7f2e2dSJohn Marino       case 's':
267c50c785cSJohn Marino 	/* Display strings with byte size chars unless explicitly
268c50c785cSJohn Marino 	   specified.  */
269cf7f2e2dSJohn Marino 	val.size = '\0';
270cf7f2e2dSJohn Marino 	break;
271cf7f2e2dSJohn Marino 
2725796c8dcSSimon Schubert       default:
2735796c8dcSSimon Schubert 	/* The default is the size most recently specified.  */
2745796c8dcSSimon Schubert 	val.size = osize;
2755796c8dcSSimon Schubert       }
2765796c8dcSSimon Schubert 
2775796c8dcSSimon Schubert   return val;
2785796c8dcSSimon Schubert }
2795796c8dcSSimon Schubert 
2805796c8dcSSimon Schubert /* Print value VAL on stream according to OPTIONS.
2815796c8dcSSimon Schubert    Do not end with a newline.
2825796c8dcSSimon Schubert    SIZE is the letter for the size of datum being printed.
2835796c8dcSSimon Schubert    This is used to pad hex numbers so they line up.  SIZE is 0
2845796c8dcSSimon Schubert    for print / output and set for examine.  */
2855796c8dcSSimon Schubert 
2865796c8dcSSimon Schubert static void
print_formatted(struct value * val,int size,const struct value_print_options * options,struct ui_file * stream)2875796c8dcSSimon Schubert print_formatted (struct value *val, int size,
2885796c8dcSSimon Schubert 		 const struct value_print_options *options,
2895796c8dcSSimon Schubert 		 struct ui_file *stream)
2905796c8dcSSimon Schubert {
2915796c8dcSSimon Schubert   struct type *type = check_typedef (value_type (val));
2925796c8dcSSimon Schubert   int len = TYPE_LENGTH (type);
2935796c8dcSSimon Schubert 
2945796c8dcSSimon Schubert   if (VALUE_LVAL (val) == lval_memory)
2955796c8dcSSimon Schubert     next_address = value_address (val) + len;
2965796c8dcSSimon Schubert 
2975796c8dcSSimon Schubert   if (size)
2985796c8dcSSimon Schubert     {
2995796c8dcSSimon Schubert       switch (options->format)
3005796c8dcSSimon Schubert 	{
3015796c8dcSSimon Schubert 	case 's':
3025796c8dcSSimon Schubert 	  {
3035796c8dcSSimon Schubert 	    struct type *elttype = value_type (val);
304cf7f2e2dSJohn Marino 
3055796c8dcSSimon Schubert 	    next_address = (value_address (val)
306c50c785cSJohn Marino 			    + val_print_string (elttype, NULL,
3075796c8dcSSimon Schubert 						value_address (val), -1,
308cf7f2e2dSJohn Marino 						stream, options) * len);
3095796c8dcSSimon Schubert 	  }
3105796c8dcSSimon Schubert 	  return;
3115796c8dcSSimon Schubert 
3125796c8dcSSimon Schubert 	case 'i':
3135796c8dcSSimon Schubert 	  /* We often wrap here if there are long symbolic names.  */
3145796c8dcSSimon Schubert 	  wrap_here ("    ");
3155796c8dcSSimon Schubert 	  next_address = (value_address (val)
3165796c8dcSSimon Schubert 			  + gdb_print_insn (get_type_arch (type),
3175796c8dcSSimon Schubert 					    value_address (val), stream,
3185796c8dcSSimon Schubert 					    &branch_delay_insns));
3195796c8dcSSimon Schubert 	  return;
3205796c8dcSSimon Schubert 	}
3215796c8dcSSimon Schubert     }
3225796c8dcSSimon Schubert 
3235796c8dcSSimon Schubert   if (options->format == 0 || options->format == 's'
3245796c8dcSSimon Schubert       || TYPE_CODE (type) == TYPE_CODE_REF
3255796c8dcSSimon Schubert       || TYPE_CODE (type) == TYPE_CODE_ARRAY
3265796c8dcSSimon Schubert       || TYPE_CODE (type) == TYPE_CODE_STRING
3275796c8dcSSimon Schubert       || TYPE_CODE (type) == TYPE_CODE_STRUCT
3285796c8dcSSimon Schubert       || TYPE_CODE (type) == TYPE_CODE_UNION
3295796c8dcSSimon Schubert       || TYPE_CODE (type) == TYPE_CODE_NAMESPACE)
3305796c8dcSSimon Schubert     value_print (val, stream, options);
3315796c8dcSSimon Schubert   else
332c50c785cSJohn Marino     /* User specified format, so don't look to the type to tell us
333c50c785cSJohn Marino        what to do.  */
334c50c785cSJohn Marino     val_print_scalar_formatted (type,
335c50c785cSJohn Marino 				value_contents_for_printing (val),
336c50c785cSJohn Marino 				value_embedded_offset (val),
337c50c785cSJohn Marino 				val,
3385796c8dcSSimon Schubert 				options, size, stream);
3395796c8dcSSimon Schubert }
3405796c8dcSSimon Schubert 
3415796c8dcSSimon Schubert /* Return builtin floating point type of same length as TYPE.
3425796c8dcSSimon Schubert    If no such type is found, return TYPE itself.  */
3435796c8dcSSimon Schubert static struct type *
float_type_from_length(struct type * type)3445796c8dcSSimon Schubert float_type_from_length (struct type *type)
3455796c8dcSSimon Schubert {
3465796c8dcSSimon Schubert   struct gdbarch *gdbarch = get_type_arch (type);
3475796c8dcSSimon Schubert   const struct builtin_type *builtin = builtin_type (gdbarch);
3485796c8dcSSimon Schubert 
349*ef5ccd6cSJohn Marino   if (TYPE_LENGTH (type) == TYPE_LENGTH (builtin->builtin_float))
3505796c8dcSSimon Schubert     type = builtin->builtin_float;
351*ef5ccd6cSJohn Marino   else if (TYPE_LENGTH (type) == TYPE_LENGTH (builtin->builtin_double))
3525796c8dcSSimon Schubert     type = builtin->builtin_double;
353*ef5ccd6cSJohn Marino   else if (TYPE_LENGTH (type) == TYPE_LENGTH (builtin->builtin_long_double))
3545796c8dcSSimon Schubert     type = builtin->builtin_long_double;
3555796c8dcSSimon Schubert 
3565796c8dcSSimon Schubert   return type;
3575796c8dcSSimon Schubert }
3585796c8dcSSimon Schubert 
3595796c8dcSSimon Schubert /* Print a scalar of data of type TYPE, pointed to in GDB by VALADDR,
360c50c785cSJohn Marino    according to OPTIONS and SIZE on STREAM.  Formats s and i are not
361c50c785cSJohn Marino    supported at this level.  */
3625796c8dcSSimon Schubert 
3635796c8dcSSimon Schubert void
print_scalar_formatted(const void * valaddr,struct type * type,const struct value_print_options * options,int size,struct ui_file * stream)3645796c8dcSSimon Schubert print_scalar_formatted (const void *valaddr, struct type *type,
3655796c8dcSSimon Schubert 			const struct value_print_options *options,
3665796c8dcSSimon Schubert 			int size, struct ui_file *stream)
3675796c8dcSSimon Schubert {
3685796c8dcSSimon Schubert   struct gdbarch *gdbarch = get_type_arch (type);
3695796c8dcSSimon Schubert   LONGEST val_long = 0;
3705796c8dcSSimon Schubert   unsigned int len = TYPE_LENGTH (type);
3715796c8dcSSimon Schubert   enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
3725796c8dcSSimon Schubert 
373c50c785cSJohn Marino   /* String printing should go through val_print_scalar_formatted.  */
374c50c785cSJohn Marino   gdb_assert (options->format != 's');
3755796c8dcSSimon Schubert 
3765796c8dcSSimon Schubert   if (len > sizeof(LONGEST) &&
3775796c8dcSSimon Schubert       (TYPE_CODE (type) == TYPE_CODE_INT
3785796c8dcSSimon Schubert        || TYPE_CODE (type) == TYPE_CODE_ENUM))
3795796c8dcSSimon Schubert     {
3805796c8dcSSimon Schubert       switch (options->format)
3815796c8dcSSimon Schubert 	{
3825796c8dcSSimon Schubert 	case 'o':
3835796c8dcSSimon Schubert 	  print_octal_chars (stream, valaddr, len, byte_order);
3845796c8dcSSimon Schubert 	  return;
3855796c8dcSSimon Schubert 	case 'u':
3865796c8dcSSimon Schubert 	case 'd':
3875796c8dcSSimon Schubert 	  print_decimal_chars (stream, valaddr, len, byte_order);
3885796c8dcSSimon Schubert 	  return;
3895796c8dcSSimon Schubert 	case 't':
3905796c8dcSSimon Schubert 	  print_binary_chars (stream, valaddr, len, byte_order);
3915796c8dcSSimon Schubert 	  return;
3925796c8dcSSimon Schubert 	case 'x':
3935796c8dcSSimon Schubert 	  print_hex_chars (stream, valaddr, len, byte_order);
3945796c8dcSSimon Schubert 	  return;
3955796c8dcSSimon Schubert 	case 'c':
3965796c8dcSSimon Schubert 	  print_char_chars (stream, type, valaddr, len, byte_order);
3975796c8dcSSimon Schubert 	  return;
3985796c8dcSSimon Schubert 	default:
3995796c8dcSSimon Schubert 	  break;
4005796c8dcSSimon Schubert 	};
4015796c8dcSSimon Schubert     }
4025796c8dcSSimon Schubert 
4035796c8dcSSimon Schubert   if (options->format != 'f')
4045796c8dcSSimon Schubert     val_long = unpack_long (type, valaddr);
4055796c8dcSSimon Schubert 
4065796c8dcSSimon Schubert   /* If the value is a pointer, and pointers and addresses are not the
4075796c8dcSSimon Schubert      same, then at this point, the value's length (in target bytes) is
4085796c8dcSSimon Schubert      gdbarch_addr_bit/TARGET_CHAR_BIT, not TYPE_LENGTH (type).  */
4095796c8dcSSimon Schubert   if (TYPE_CODE (type) == TYPE_CODE_PTR)
4105796c8dcSSimon Schubert     len = gdbarch_addr_bit (gdbarch) / TARGET_CHAR_BIT;
4115796c8dcSSimon Schubert 
4125796c8dcSSimon Schubert   /* If we are printing it as unsigned, truncate it in case it is actually
4135796c8dcSSimon Schubert      a negative signed value (e.g. "print/u (short)-1" should print 65535
4145796c8dcSSimon Schubert      (if shorts are 16 bits) instead of 4294967295).  */
4155796c8dcSSimon Schubert   if (options->format != 'd' || TYPE_UNSIGNED (type))
4165796c8dcSSimon Schubert     {
4175796c8dcSSimon Schubert       if (len < sizeof (LONGEST))
4185796c8dcSSimon Schubert 	val_long &= ((LONGEST) 1 << HOST_CHAR_BIT * len) - 1;
4195796c8dcSSimon Schubert     }
4205796c8dcSSimon Schubert 
4215796c8dcSSimon Schubert   switch (options->format)
4225796c8dcSSimon Schubert     {
4235796c8dcSSimon Schubert     case 'x':
4245796c8dcSSimon Schubert       if (!size)
4255796c8dcSSimon Schubert 	{
4265796c8dcSSimon Schubert 	  /* No size specified, like in print.  Print varying # of digits.  */
4275796c8dcSSimon Schubert 	  print_longest (stream, 'x', 1, val_long);
4285796c8dcSSimon Schubert 	}
4295796c8dcSSimon Schubert       else
4305796c8dcSSimon Schubert 	switch (size)
4315796c8dcSSimon Schubert 	  {
4325796c8dcSSimon Schubert 	  case 'b':
4335796c8dcSSimon Schubert 	  case 'h':
4345796c8dcSSimon Schubert 	  case 'w':
4355796c8dcSSimon Schubert 	  case 'g':
4365796c8dcSSimon Schubert 	    print_longest (stream, size, 1, val_long);
4375796c8dcSSimon Schubert 	    break;
4385796c8dcSSimon Schubert 	  default:
4395796c8dcSSimon Schubert 	    error (_("Undefined output size \"%c\"."), size);
4405796c8dcSSimon Schubert 	  }
4415796c8dcSSimon Schubert       break;
4425796c8dcSSimon Schubert 
4435796c8dcSSimon Schubert     case 'd':
4445796c8dcSSimon Schubert       print_longest (stream, 'd', 1, val_long);
4455796c8dcSSimon Schubert       break;
4465796c8dcSSimon Schubert 
4475796c8dcSSimon Schubert     case 'u':
4485796c8dcSSimon Schubert       print_longest (stream, 'u', 0, val_long);
4495796c8dcSSimon Schubert       break;
4505796c8dcSSimon Schubert 
4515796c8dcSSimon Schubert     case 'o':
4525796c8dcSSimon Schubert       if (val_long)
4535796c8dcSSimon Schubert 	print_longest (stream, 'o', 1, val_long);
4545796c8dcSSimon Schubert       else
4555796c8dcSSimon Schubert 	fprintf_filtered (stream, "0");
4565796c8dcSSimon Schubert       break;
4575796c8dcSSimon Schubert 
4585796c8dcSSimon Schubert     case 'a':
4595796c8dcSSimon Schubert       {
4605796c8dcSSimon Schubert 	CORE_ADDR addr = unpack_pointer (type, valaddr);
461cf7f2e2dSJohn Marino 
4625796c8dcSSimon Schubert 	print_address (gdbarch, addr, stream);
4635796c8dcSSimon Schubert       }
4645796c8dcSSimon Schubert       break;
4655796c8dcSSimon Schubert 
4665796c8dcSSimon Schubert     case 'c':
4675796c8dcSSimon Schubert       {
4685796c8dcSSimon Schubert 	struct value_print_options opts = *options;
4695796c8dcSSimon Schubert 
470cf7f2e2dSJohn Marino 	opts.format = 0;
4715796c8dcSSimon Schubert 	if (TYPE_UNSIGNED (type))
4725796c8dcSSimon Schubert 	  type = builtin_type (gdbarch)->builtin_true_unsigned_char;
4735796c8dcSSimon Schubert  	else
4745796c8dcSSimon Schubert 	  type = builtin_type (gdbarch)->builtin_true_char;
4755796c8dcSSimon Schubert 
4765796c8dcSSimon Schubert 	value_print (value_from_longest (type, val_long), stream, &opts);
4775796c8dcSSimon Schubert       }
4785796c8dcSSimon Schubert       break;
4795796c8dcSSimon Schubert 
4805796c8dcSSimon Schubert     case 'f':
4815796c8dcSSimon Schubert       type = float_type_from_length (type);
4825796c8dcSSimon Schubert       print_floating (valaddr, type, stream);
4835796c8dcSSimon Schubert       break;
4845796c8dcSSimon Schubert 
4855796c8dcSSimon Schubert     case 0:
4865796c8dcSSimon Schubert       internal_error (__FILE__, __LINE__,
4875796c8dcSSimon Schubert 		      _("failed internal consistency check"));
4885796c8dcSSimon Schubert 
4895796c8dcSSimon Schubert     case 't':
4905796c8dcSSimon Schubert       /* Binary; 't' stands for "two".  */
4915796c8dcSSimon Schubert       {
4925796c8dcSSimon Schubert 	char bits[8 * (sizeof val_long) + 1];
4935796c8dcSSimon Schubert 	char buf[8 * (sizeof val_long) + 32];
4945796c8dcSSimon Schubert 	char *cp = bits;
4955796c8dcSSimon Schubert 	int width;
4965796c8dcSSimon Schubert 
4975796c8dcSSimon Schubert 	if (!size)
4985796c8dcSSimon Schubert 	  width = 8 * (sizeof val_long);
4995796c8dcSSimon Schubert 	else
5005796c8dcSSimon Schubert 	  switch (size)
5015796c8dcSSimon Schubert 	    {
5025796c8dcSSimon Schubert 	    case 'b':
5035796c8dcSSimon Schubert 	      width = 8;
5045796c8dcSSimon Schubert 	      break;
5055796c8dcSSimon Schubert 	    case 'h':
5065796c8dcSSimon Schubert 	      width = 16;
5075796c8dcSSimon Schubert 	      break;
5085796c8dcSSimon Schubert 	    case 'w':
5095796c8dcSSimon Schubert 	      width = 32;
5105796c8dcSSimon Schubert 	      break;
5115796c8dcSSimon Schubert 	    case 'g':
5125796c8dcSSimon Schubert 	      width = 64;
5135796c8dcSSimon Schubert 	      break;
5145796c8dcSSimon Schubert 	    default:
5155796c8dcSSimon Schubert 	      error (_("Undefined output size \"%c\"."), size);
5165796c8dcSSimon Schubert 	    }
5175796c8dcSSimon Schubert 
5185796c8dcSSimon Schubert 	bits[width] = '\0';
5195796c8dcSSimon Schubert 	while (width-- > 0)
5205796c8dcSSimon Schubert 	  {
5215796c8dcSSimon Schubert 	    bits[width] = (val_long & 1) ? '1' : '0';
5225796c8dcSSimon Schubert 	    val_long >>= 1;
5235796c8dcSSimon Schubert 	  }
5245796c8dcSSimon Schubert 	if (!size)
5255796c8dcSSimon Schubert 	  {
5265796c8dcSSimon Schubert 	    while (*cp && *cp == '0')
5275796c8dcSSimon Schubert 	      cp++;
5285796c8dcSSimon Schubert 	    if (*cp == '\0')
5295796c8dcSSimon Schubert 	      cp--;
5305796c8dcSSimon Schubert 	  }
531c50c785cSJohn Marino 	strncpy (buf, cp, sizeof (bits));
5325796c8dcSSimon Schubert 	fputs_filtered (buf, stream);
5335796c8dcSSimon Schubert       }
5345796c8dcSSimon Schubert       break;
5355796c8dcSSimon Schubert 
5365796c8dcSSimon Schubert     default:
5375796c8dcSSimon Schubert       error (_("Undefined output format \"%c\"."), options->format);
5385796c8dcSSimon Schubert     }
5395796c8dcSSimon Schubert }
5405796c8dcSSimon Schubert 
5415796c8dcSSimon Schubert /* Specify default address for `x' command.
5425796c8dcSSimon Schubert    The `info lines' command uses this.  */
5435796c8dcSSimon Schubert 
5445796c8dcSSimon Schubert void
set_next_address(struct gdbarch * gdbarch,CORE_ADDR addr)5455796c8dcSSimon Schubert set_next_address (struct gdbarch *gdbarch, CORE_ADDR addr)
5465796c8dcSSimon Schubert {
5475796c8dcSSimon Schubert   struct type *ptr_type = builtin_type (gdbarch)->builtin_data_ptr;
5485796c8dcSSimon Schubert 
5495796c8dcSSimon Schubert   next_gdbarch = gdbarch;
5505796c8dcSSimon Schubert   next_address = addr;
5515796c8dcSSimon Schubert 
5525796c8dcSSimon Schubert   /* Make address available to the user as $_.  */
5535796c8dcSSimon Schubert   set_internalvar (lookup_internalvar ("_"),
5545796c8dcSSimon Schubert 		   value_from_pointer (ptr_type, addr));
5555796c8dcSSimon Schubert }
5565796c8dcSSimon Schubert 
5575796c8dcSSimon Schubert /* Optionally print address ADDR symbolically as <SYMBOL+OFFSET> on STREAM,
5585796c8dcSSimon Schubert    after LEADIN.  Print nothing if no symbolic name is found nearby.
5595796c8dcSSimon Schubert    Optionally also print source file and line number, if available.
5605796c8dcSSimon Schubert    DO_DEMANGLE controls whether to print a symbol in its native "raw" form,
5615796c8dcSSimon Schubert    or to interpret it as a possible C++ name and convert it back to source
5625796c8dcSSimon Schubert    form.  However note that DO_DEMANGLE can be overridden by the specific
563*ef5ccd6cSJohn Marino    settings of the demangle and asm_demangle variables.  Returns
564*ef5ccd6cSJohn Marino    non-zero if anything was printed; zero otherwise.  */
5655796c8dcSSimon Schubert 
566*ef5ccd6cSJohn Marino int
print_address_symbolic(struct gdbarch * gdbarch,CORE_ADDR addr,struct ui_file * stream,int do_demangle,char * leadin)567cf7f2e2dSJohn Marino print_address_symbolic (struct gdbarch *gdbarch, CORE_ADDR addr,
568cf7f2e2dSJohn Marino 			struct ui_file *stream,
5695796c8dcSSimon Schubert 			int do_demangle, char *leadin)
5705796c8dcSSimon Schubert {
5715796c8dcSSimon Schubert   char *name = NULL;
5725796c8dcSSimon Schubert   char *filename = NULL;
5735796c8dcSSimon Schubert   int unmapped = 0;
5745796c8dcSSimon Schubert   int offset = 0;
5755796c8dcSSimon Schubert   int line = 0;
5765796c8dcSSimon Schubert 
5775796c8dcSSimon Schubert   /* Throw away both name and filename.  */
5785796c8dcSSimon Schubert   struct cleanup *cleanup_chain = make_cleanup (free_current_contents, &name);
5795796c8dcSSimon Schubert   make_cleanup (free_current_contents, &filename);
5805796c8dcSSimon Schubert 
581cf7f2e2dSJohn Marino   if (build_address_symbolic (gdbarch, addr, do_demangle, &name, &offset,
5825796c8dcSSimon Schubert 			      &filename, &line, &unmapped))
5835796c8dcSSimon Schubert     {
5845796c8dcSSimon Schubert       do_cleanups (cleanup_chain);
585*ef5ccd6cSJohn Marino       return 0;
5865796c8dcSSimon Schubert     }
5875796c8dcSSimon Schubert 
5885796c8dcSSimon Schubert   fputs_filtered (leadin, stream);
5895796c8dcSSimon Schubert   if (unmapped)
5905796c8dcSSimon Schubert     fputs_filtered ("<*", stream);
5915796c8dcSSimon Schubert   else
5925796c8dcSSimon Schubert     fputs_filtered ("<", stream);
5935796c8dcSSimon Schubert   fputs_filtered (name, stream);
5945796c8dcSSimon Schubert   if (offset != 0)
5955796c8dcSSimon Schubert     fprintf_filtered (stream, "+%u", (unsigned int) offset);
5965796c8dcSSimon Schubert 
5975796c8dcSSimon Schubert   /* Append source filename and line number if desired.  Give specific
5985796c8dcSSimon Schubert      line # of this addr, if we have it; else line # of the nearest symbol.  */
5995796c8dcSSimon Schubert   if (print_symbol_filename && filename != NULL)
6005796c8dcSSimon Schubert     {
6015796c8dcSSimon Schubert       if (line != -1)
6025796c8dcSSimon Schubert 	fprintf_filtered (stream, " at %s:%d", filename, line);
6035796c8dcSSimon Schubert       else
6045796c8dcSSimon Schubert 	fprintf_filtered (stream, " in %s", filename);
6055796c8dcSSimon Schubert     }
6065796c8dcSSimon Schubert   if (unmapped)
6075796c8dcSSimon Schubert     fputs_filtered ("*>", stream);
6085796c8dcSSimon Schubert   else
6095796c8dcSSimon Schubert     fputs_filtered (">", stream);
6105796c8dcSSimon Schubert 
6115796c8dcSSimon Schubert   do_cleanups (cleanup_chain);
612*ef5ccd6cSJohn Marino   return 1;
6135796c8dcSSimon Schubert }
6145796c8dcSSimon Schubert 
6155796c8dcSSimon Schubert /* Given an address ADDR return all the elements needed to print the
6165796c8dcSSimon Schubert    address in a symbolic form.  NAME can be mangled or not depending
6175796c8dcSSimon Schubert    on DO_DEMANGLE (and also on the asm_demangle global variable,
6185796c8dcSSimon Schubert    manipulated via ''set print asm-demangle'').  Return 0 in case of
6195796c8dcSSimon Schubert    success, when all the info in the OUT paramters is valid.  Return 1
6205796c8dcSSimon Schubert    otherwise.  */
6215796c8dcSSimon Schubert int
build_address_symbolic(struct gdbarch * gdbarch,CORE_ADDR addr,int do_demangle,char ** name,int * offset,char ** filename,int * line,int * unmapped)622cf7f2e2dSJohn Marino build_address_symbolic (struct gdbarch *gdbarch,
623cf7f2e2dSJohn Marino 			CORE_ADDR addr,  /* IN */
6245796c8dcSSimon Schubert 			int do_demangle, /* IN */
6255796c8dcSSimon Schubert 			char **name,     /* OUT */
6265796c8dcSSimon Schubert 			int *offset,     /* OUT */
6275796c8dcSSimon Schubert 			char **filename, /* OUT */
6285796c8dcSSimon Schubert 			int *line,       /* OUT */
6295796c8dcSSimon Schubert 			int *unmapped)   /* OUT */
6305796c8dcSSimon Schubert {
6315796c8dcSSimon Schubert   struct minimal_symbol *msymbol;
6325796c8dcSSimon Schubert   struct symbol *symbol;
6335796c8dcSSimon Schubert   CORE_ADDR name_location = 0;
6345796c8dcSSimon Schubert   struct obj_section *section = NULL;
635*ef5ccd6cSJohn Marino   const char *name_temp = "";
6365796c8dcSSimon Schubert 
6375796c8dcSSimon Schubert   /* Let's say it is mapped (not unmapped).  */
6385796c8dcSSimon Schubert   *unmapped = 0;
6395796c8dcSSimon Schubert 
6405796c8dcSSimon Schubert   /* Determine if the address is in an overlay, and whether it is
6415796c8dcSSimon Schubert      mapped.  */
6425796c8dcSSimon Schubert   if (overlay_debugging)
6435796c8dcSSimon Schubert     {
6445796c8dcSSimon Schubert       section = find_pc_overlay (addr);
6455796c8dcSSimon Schubert       if (pc_in_unmapped_range (addr, section))
6465796c8dcSSimon Schubert 	{
6475796c8dcSSimon Schubert 	  *unmapped = 1;
6485796c8dcSSimon Schubert 	  addr = overlay_mapped_address (addr, section);
6495796c8dcSSimon Schubert 	}
6505796c8dcSSimon Schubert     }
6515796c8dcSSimon Schubert 
6525796c8dcSSimon Schubert   /* First try to find the address in the symbol table, then
6535796c8dcSSimon Schubert      in the minsyms.  Take the closest one.  */
6545796c8dcSSimon Schubert 
6555796c8dcSSimon Schubert   /* This is defective in the sense that it only finds text symbols.  So
6565796c8dcSSimon Schubert      really this is kind of pointless--we should make sure that the
6575796c8dcSSimon Schubert      minimal symbols have everything we need (by changing that we could
6585796c8dcSSimon Schubert      save some memory, but for many debug format--ELF/DWARF or
6595796c8dcSSimon Schubert      anything/stabs--it would be inconvenient to eliminate those minimal
6605796c8dcSSimon Schubert      symbols anyway).  */
6615796c8dcSSimon Schubert   msymbol = lookup_minimal_symbol_by_pc_section (addr, section);
6625796c8dcSSimon Schubert   symbol = find_pc_sect_function (addr, section);
6635796c8dcSSimon Schubert 
6645796c8dcSSimon Schubert   if (symbol)
6655796c8dcSSimon Schubert     {
666cf7f2e2dSJohn Marino       /* If this is a function (i.e. a code address), strip out any
667cf7f2e2dSJohn Marino 	 non-address bits.  For instance, display a pointer to the
668cf7f2e2dSJohn Marino 	 first instruction of a Thumb function as <function>; the
669cf7f2e2dSJohn Marino 	 second instruction will be <function+2>, even though the
670cf7f2e2dSJohn Marino 	 pointer is <function+3>.  This matches the ISA behavior.  */
671cf7f2e2dSJohn Marino       addr = gdbarch_addr_bits_remove (gdbarch, addr);
672cf7f2e2dSJohn Marino 
6735796c8dcSSimon Schubert       name_location = BLOCK_START (SYMBOL_BLOCK_VALUE (symbol));
6745796c8dcSSimon Schubert       if (do_demangle || asm_demangle)
6755796c8dcSSimon Schubert 	name_temp = SYMBOL_PRINT_NAME (symbol);
6765796c8dcSSimon Schubert       else
6775796c8dcSSimon Schubert 	name_temp = SYMBOL_LINKAGE_NAME (symbol);
6785796c8dcSSimon Schubert     }
6795796c8dcSSimon Schubert 
680*ef5ccd6cSJohn Marino   if (msymbol != NULL
681*ef5ccd6cSJohn Marino       && MSYMBOL_HAS_SIZE (msymbol)
682*ef5ccd6cSJohn Marino       && MSYMBOL_SIZE (msymbol) == 0
683*ef5ccd6cSJohn Marino       && MSYMBOL_TYPE (msymbol) != mst_text
684*ef5ccd6cSJohn Marino       && MSYMBOL_TYPE (msymbol) != mst_text_gnu_ifunc
685*ef5ccd6cSJohn Marino       && MSYMBOL_TYPE (msymbol) != mst_file_text)
686*ef5ccd6cSJohn Marino     msymbol = NULL;
687*ef5ccd6cSJohn Marino 
6885796c8dcSSimon Schubert   if (msymbol != NULL)
6895796c8dcSSimon Schubert     {
6905796c8dcSSimon Schubert       if (SYMBOL_VALUE_ADDRESS (msymbol) > name_location || symbol == NULL)
6915796c8dcSSimon Schubert 	{
6925796c8dcSSimon Schubert 	  /* The msymbol is closer to the address than the symbol;
6935796c8dcSSimon Schubert 	     use the msymbol instead.  */
6945796c8dcSSimon Schubert 	  symbol = 0;
6955796c8dcSSimon Schubert 	  name_location = SYMBOL_VALUE_ADDRESS (msymbol);
6965796c8dcSSimon Schubert 	  if (do_demangle || asm_demangle)
6975796c8dcSSimon Schubert 	    name_temp = SYMBOL_PRINT_NAME (msymbol);
6985796c8dcSSimon Schubert 	  else
6995796c8dcSSimon Schubert 	    name_temp = SYMBOL_LINKAGE_NAME (msymbol);
7005796c8dcSSimon Schubert 	}
7015796c8dcSSimon Schubert     }
7025796c8dcSSimon Schubert   if (symbol == NULL && msymbol == NULL)
7035796c8dcSSimon Schubert     return 1;
7045796c8dcSSimon Schubert 
7055796c8dcSSimon Schubert   /* If the nearest symbol is too far away, don't print anything symbolic.  */
7065796c8dcSSimon Schubert 
7075796c8dcSSimon Schubert   /* For when CORE_ADDR is larger than unsigned int, we do math in
7085796c8dcSSimon Schubert      CORE_ADDR.  But when we detect unsigned wraparound in the
7095796c8dcSSimon Schubert      CORE_ADDR math, we ignore this test and print the offset,
7105796c8dcSSimon Schubert      because addr+max_symbolic_offset has wrapped through the end
7115796c8dcSSimon Schubert      of the address space back to the beginning, giving bogus comparison.  */
7125796c8dcSSimon Schubert   if (addr > name_location + max_symbolic_offset
7135796c8dcSSimon Schubert       && name_location + max_symbolic_offset > name_location)
7145796c8dcSSimon Schubert     return 1;
7155796c8dcSSimon Schubert 
7165796c8dcSSimon Schubert   *offset = addr - name_location;
7175796c8dcSSimon Schubert 
7185796c8dcSSimon Schubert   *name = xstrdup (name_temp);
7195796c8dcSSimon Schubert 
7205796c8dcSSimon Schubert   if (print_symbol_filename)
7215796c8dcSSimon Schubert     {
7225796c8dcSSimon Schubert       struct symtab_and_line sal;
7235796c8dcSSimon Schubert 
7245796c8dcSSimon Schubert       sal = find_pc_sect_line (addr, section, 0);
7255796c8dcSSimon Schubert 
7265796c8dcSSimon Schubert       if (sal.symtab)
7275796c8dcSSimon Schubert 	{
728*ef5ccd6cSJohn Marino 	  *filename = xstrdup (symtab_to_filename_for_display (sal.symtab));
7295796c8dcSSimon Schubert 	  *line = sal.line;
7305796c8dcSSimon Schubert 	}
7315796c8dcSSimon Schubert     }
7325796c8dcSSimon Schubert   return 0;
7335796c8dcSSimon Schubert }
7345796c8dcSSimon Schubert 
7355796c8dcSSimon Schubert 
7365796c8dcSSimon Schubert /* Print address ADDR symbolically on STREAM.
7375796c8dcSSimon Schubert    First print it as a number.  Then perhaps print
7385796c8dcSSimon Schubert    <SYMBOL + OFFSET> after the number.  */
7395796c8dcSSimon Schubert 
7405796c8dcSSimon Schubert void
print_address(struct gdbarch * gdbarch,CORE_ADDR addr,struct ui_file * stream)7415796c8dcSSimon Schubert print_address (struct gdbarch *gdbarch,
7425796c8dcSSimon Schubert 	       CORE_ADDR addr, struct ui_file *stream)
7435796c8dcSSimon Schubert {
7445796c8dcSSimon Schubert   fputs_filtered (paddress (gdbarch, addr), stream);
745cf7f2e2dSJohn Marino   print_address_symbolic (gdbarch, addr, stream, asm_demangle, " ");
746cf7f2e2dSJohn Marino }
747cf7f2e2dSJohn Marino 
748cf7f2e2dSJohn Marino /* Return a prefix for instruction address:
749cf7f2e2dSJohn Marino    "=> " for current instruction, else "   ".  */
750cf7f2e2dSJohn Marino 
751cf7f2e2dSJohn Marino const char *
pc_prefix(CORE_ADDR addr)752cf7f2e2dSJohn Marino pc_prefix (CORE_ADDR addr)
753cf7f2e2dSJohn Marino {
754cf7f2e2dSJohn Marino   if (has_stack_frames ())
755cf7f2e2dSJohn Marino     {
756cf7f2e2dSJohn Marino       struct frame_info *frame;
757cf7f2e2dSJohn Marino       CORE_ADDR pc;
758cf7f2e2dSJohn Marino 
759cf7f2e2dSJohn Marino       frame = get_selected_frame (NULL);
760c50c785cSJohn Marino       if (get_frame_pc_if_available (frame, &pc) && pc == addr)
761cf7f2e2dSJohn Marino 	return "=> ";
762cf7f2e2dSJohn Marino     }
763cf7f2e2dSJohn Marino   return "   ";
7645796c8dcSSimon Schubert }
7655796c8dcSSimon Schubert 
7665796c8dcSSimon Schubert /* Print address ADDR symbolically on STREAM.  Parameter DEMANGLE
7675796c8dcSSimon Schubert    controls whether to print the symbolic name "raw" or demangled.
768*ef5ccd6cSJohn Marino    Return non-zero if anything was printed; zero otherwise.  */
7695796c8dcSSimon Schubert 
770*ef5ccd6cSJohn Marino int
print_address_demangle(const struct value_print_options * opts,struct gdbarch * gdbarch,CORE_ADDR addr,struct ui_file * stream,int do_demangle)771*ef5ccd6cSJohn Marino print_address_demangle (const struct value_print_options *opts,
772*ef5ccd6cSJohn Marino 			struct gdbarch *gdbarch, CORE_ADDR addr,
7735796c8dcSSimon Schubert 			struct ui_file *stream, int do_demangle)
7745796c8dcSSimon Schubert {
775*ef5ccd6cSJohn Marino   if (opts->addressprint)
7765796c8dcSSimon Schubert     {
7775796c8dcSSimon Schubert       fputs_filtered (paddress (gdbarch, addr), stream);
778cf7f2e2dSJohn Marino       print_address_symbolic (gdbarch, addr, stream, do_demangle, " ");
7795796c8dcSSimon Schubert     }
7805796c8dcSSimon Schubert   else
7815796c8dcSSimon Schubert     {
782*ef5ccd6cSJohn Marino       return print_address_symbolic (gdbarch, addr, stream, do_demangle, "");
7835796c8dcSSimon Schubert     }
784*ef5ccd6cSJohn Marino   return 1;
7855796c8dcSSimon Schubert }
7865796c8dcSSimon Schubert 
7875796c8dcSSimon Schubert 
7885796c8dcSSimon Schubert /* Examine data at address ADDR in format FMT.
7895796c8dcSSimon Schubert    Fetch it from memory and print on gdb_stdout.  */
7905796c8dcSSimon Schubert 
7915796c8dcSSimon Schubert static void
do_examine(struct format_data fmt,struct gdbarch * gdbarch,CORE_ADDR addr)7925796c8dcSSimon Schubert do_examine (struct format_data fmt, struct gdbarch *gdbarch, CORE_ADDR addr)
7935796c8dcSSimon Schubert {
7945796c8dcSSimon Schubert   char format = 0;
7955796c8dcSSimon Schubert   char size;
7965796c8dcSSimon Schubert   int count = 1;
7975796c8dcSSimon Schubert   struct type *val_type = NULL;
7985796c8dcSSimon Schubert   int i;
7995796c8dcSSimon Schubert   int maxelts;
8005796c8dcSSimon Schubert   struct value_print_options opts;
8015796c8dcSSimon Schubert 
8025796c8dcSSimon Schubert   format = fmt.format;
8035796c8dcSSimon Schubert   size = fmt.size;
8045796c8dcSSimon Schubert   count = fmt.count;
8055796c8dcSSimon Schubert   next_gdbarch = gdbarch;
8065796c8dcSSimon Schubert   next_address = addr;
8075796c8dcSSimon Schubert 
808cf7f2e2dSJohn Marino   /* Instruction format implies fetch single bytes
809cf7f2e2dSJohn Marino      regardless of the specified size.
810cf7f2e2dSJohn Marino      The case of strings is handled in decode_format, only explicit
811cf7f2e2dSJohn Marino      size operator are not changed to 'b'.  */
812cf7f2e2dSJohn Marino   if (format == 'i')
8135796c8dcSSimon Schubert     size = 'b';
8145796c8dcSSimon Schubert 
8155796c8dcSSimon Schubert   if (size == 'a')
8165796c8dcSSimon Schubert     {
8175796c8dcSSimon Schubert       /* Pick the appropriate size for an address.  */
8185796c8dcSSimon Schubert       if (gdbarch_ptr_bit (next_gdbarch) == 64)
8195796c8dcSSimon Schubert 	size = 'g';
8205796c8dcSSimon Schubert       else if (gdbarch_ptr_bit (next_gdbarch) == 32)
8215796c8dcSSimon Schubert 	size = 'w';
8225796c8dcSSimon Schubert       else if (gdbarch_ptr_bit (next_gdbarch) == 16)
8235796c8dcSSimon Schubert 	size = 'h';
8245796c8dcSSimon Schubert       else
8255796c8dcSSimon Schubert 	/* Bad value for gdbarch_ptr_bit.  */
8265796c8dcSSimon Schubert 	internal_error (__FILE__, __LINE__,
8275796c8dcSSimon Schubert 			_("failed internal consistency check"));
8285796c8dcSSimon Schubert     }
8295796c8dcSSimon Schubert 
8305796c8dcSSimon Schubert   if (size == 'b')
8315796c8dcSSimon Schubert     val_type = builtin_type (next_gdbarch)->builtin_int8;
8325796c8dcSSimon Schubert   else if (size == 'h')
8335796c8dcSSimon Schubert     val_type = builtin_type (next_gdbarch)->builtin_int16;
8345796c8dcSSimon Schubert   else if (size == 'w')
8355796c8dcSSimon Schubert     val_type = builtin_type (next_gdbarch)->builtin_int32;
8365796c8dcSSimon Schubert   else if (size == 'g')
8375796c8dcSSimon Schubert     val_type = builtin_type (next_gdbarch)->builtin_int64;
8385796c8dcSSimon Schubert 
839cf7f2e2dSJohn Marino   if (format == 's')
840cf7f2e2dSJohn Marino     {
841cf7f2e2dSJohn Marino       struct type *char_type = NULL;
842cf7f2e2dSJohn Marino 
843cf7f2e2dSJohn Marino       /* Search for "char16_t"  or "char32_t" types or fall back to 8-bit char
844cf7f2e2dSJohn Marino 	 if type is not found.  */
845cf7f2e2dSJohn Marino       if (size == 'h')
846cf7f2e2dSJohn Marino 	char_type = builtin_type (next_gdbarch)->builtin_char16;
847cf7f2e2dSJohn Marino       else if (size == 'w')
848cf7f2e2dSJohn Marino 	char_type = builtin_type (next_gdbarch)->builtin_char32;
849cf7f2e2dSJohn Marino       if (char_type)
850cf7f2e2dSJohn Marino         val_type = char_type;
851cf7f2e2dSJohn Marino       else
852cf7f2e2dSJohn Marino         {
853cf7f2e2dSJohn Marino 	  if (size != '\0' && size != 'b')
854c50c785cSJohn Marino 	    warning (_("Unable to display strings with "
855c50c785cSJohn Marino 		       "size '%c', using 'b' instead."), size);
856cf7f2e2dSJohn Marino 	  size = 'b';
857cf7f2e2dSJohn Marino 	  val_type = builtin_type (next_gdbarch)->builtin_int8;
858cf7f2e2dSJohn Marino         }
859cf7f2e2dSJohn Marino     }
860cf7f2e2dSJohn Marino 
8615796c8dcSSimon Schubert   maxelts = 8;
8625796c8dcSSimon Schubert   if (size == 'w')
8635796c8dcSSimon Schubert     maxelts = 4;
8645796c8dcSSimon Schubert   if (size == 'g')
8655796c8dcSSimon Schubert     maxelts = 2;
8665796c8dcSSimon Schubert   if (format == 's' || format == 'i')
8675796c8dcSSimon Schubert     maxelts = 1;
8685796c8dcSSimon Schubert 
8695796c8dcSSimon Schubert   get_formatted_print_options (&opts, format);
8705796c8dcSSimon Schubert 
8715796c8dcSSimon Schubert   /* Print as many objects as specified in COUNT, at most maxelts per line,
8725796c8dcSSimon Schubert      with the address of the next one at the start of each line.  */
8735796c8dcSSimon Schubert 
8745796c8dcSSimon Schubert   while (count > 0)
8755796c8dcSSimon Schubert     {
8765796c8dcSSimon Schubert       QUIT;
877cf7f2e2dSJohn Marino       if (format == 'i')
878cf7f2e2dSJohn Marino 	fputs_filtered (pc_prefix (next_address), gdb_stdout);
8795796c8dcSSimon Schubert       print_address (next_gdbarch, next_address, gdb_stdout);
8805796c8dcSSimon Schubert       printf_filtered (":");
8815796c8dcSSimon Schubert       for (i = maxelts;
8825796c8dcSSimon Schubert 	   i > 0 && count > 0;
8835796c8dcSSimon Schubert 	   i--, count--)
8845796c8dcSSimon Schubert 	{
8855796c8dcSSimon Schubert 	  printf_filtered ("\t");
8865796c8dcSSimon Schubert 	  /* Note that print_formatted sets next_address for the next
8875796c8dcSSimon Schubert 	     object.  */
8885796c8dcSSimon Schubert 	  last_examine_address = next_address;
8895796c8dcSSimon Schubert 
8905796c8dcSSimon Schubert 	  if (last_examine_value)
8915796c8dcSSimon Schubert 	    value_free (last_examine_value);
8925796c8dcSSimon Schubert 
8935796c8dcSSimon Schubert 	  /* The value to be displayed is not fetched greedily.
8945796c8dcSSimon Schubert 	     Instead, to avoid the possibility of a fetched value not
8955796c8dcSSimon Schubert 	     being used, its retrieval is delayed until the print code
8965796c8dcSSimon Schubert 	     uses it.  When examining an instruction stream, the
8975796c8dcSSimon Schubert 	     disassembler will perform its own memory fetch using just
8985796c8dcSSimon Schubert 	     the address stored in LAST_EXAMINE_VALUE.  FIXME: Should
8995796c8dcSSimon Schubert 	     the disassembler be modified so that LAST_EXAMINE_VALUE
9005796c8dcSSimon Schubert 	     is left with the byte sequence from the last complete
9015796c8dcSSimon Schubert 	     instruction fetched from memory?  */
9025796c8dcSSimon Schubert 	  last_examine_value = value_at_lazy (val_type, next_address);
9035796c8dcSSimon Schubert 
9045796c8dcSSimon Schubert 	  if (last_examine_value)
9055796c8dcSSimon Schubert 	    release_value (last_examine_value);
9065796c8dcSSimon Schubert 
9075796c8dcSSimon Schubert 	  print_formatted (last_examine_value, size, &opts, gdb_stdout);
9085796c8dcSSimon Schubert 
9095796c8dcSSimon Schubert 	  /* Display any branch delay slots following the final insn.  */
9105796c8dcSSimon Schubert 	  if (format == 'i' && count == 1)
9115796c8dcSSimon Schubert 	    count += branch_delay_insns;
9125796c8dcSSimon Schubert 	}
9135796c8dcSSimon Schubert       printf_filtered ("\n");
9145796c8dcSSimon Schubert       gdb_flush (gdb_stdout);
9155796c8dcSSimon Schubert     }
9165796c8dcSSimon Schubert }
9175796c8dcSSimon Schubert 
9185796c8dcSSimon Schubert static void
validate_format(struct format_data fmt,char * cmdname)9195796c8dcSSimon Schubert validate_format (struct format_data fmt, char *cmdname)
9205796c8dcSSimon Schubert {
9215796c8dcSSimon Schubert   if (fmt.size != 0)
9225796c8dcSSimon Schubert     error (_("Size letters are meaningless in \"%s\" command."), cmdname);
9235796c8dcSSimon Schubert   if (fmt.count != 1)
9245796c8dcSSimon Schubert     error (_("Item count other than 1 is meaningless in \"%s\" command."),
9255796c8dcSSimon Schubert 	   cmdname);
9265796c8dcSSimon Schubert   if (fmt.format == 'i')
9275796c8dcSSimon Schubert     error (_("Format letter \"%c\" is meaningless in \"%s\" command."),
9285796c8dcSSimon Schubert 	   fmt.format, cmdname);
9295796c8dcSSimon Schubert }
9305796c8dcSSimon Schubert 
9315796c8dcSSimon Schubert /* Evaluate string EXP as an expression in the current language and
9325796c8dcSSimon Schubert    print the resulting value.  EXP may contain a format specifier as the
9335796c8dcSSimon Schubert    first argument ("/x myvar" for example, to print myvar in hex).  */
9345796c8dcSSimon Schubert 
9355796c8dcSSimon Schubert static void
print_command_1(char * exp,int voidprint)936*ef5ccd6cSJohn Marino print_command_1 (char *exp, int voidprint)
9375796c8dcSSimon Schubert {
9385796c8dcSSimon Schubert   struct expression *expr;
9395796c8dcSSimon Schubert   struct cleanup *old_chain = 0;
9405796c8dcSSimon Schubert   char format = 0;
9415796c8dcSSimon Schubert   struct value *val;
9425796c8dcSSimon Schubert   struct format_data fmt;
9435796c8dcSSimon Schubert   int cleanup = 0;
9445796c8dcSSimon Schubert 
9455796c8dcSSimon Schubert   if (exp && *exp == '/')
9465796c8dcSSimon Schubert     {
9475796c8dcSSimon Schubert       exp++;
9485796c8dcSSimon Schubert       fmt = decode_format (&exp, last_format, 0);
9495796c8dcSSimon Schubert       validate_format (fmt, "print");
9505796c8dcSSimon Schubert       last_format = format = fmt.format;
9515796c8dcSSimon Schubert     }
9525796c8dcSSimon Schubert   else
9535796c8dcSSimon Schubert     {
9545796c8dcSSimon Schubert       fmt.count = 1;
9555796c8dcSSimon Schubert       fmt.format = 0;
9565796c8dcSSimon Schubert       fmt.size = 0;
9575796c8dcSSimon Schubert       fmt.raw = 0;
9585796c8dcSSimon Schubert     }
9595796c8dcSSimon Schubert 
9605796c8dcSSimon Schubert   if (exp && *exp)
9615796c8dcSSimon Schubert     {
9625796c8dcSSimon Schubert       expr = parse_expression (exp);
9635796c8dcSSimon Schubert       old_chain = make_cleanup (free_current_contents, &expr);
9645796c8dcSSimon Schubert       cleanup = 1;
9655796c8dcSSimon Schubert       val = evaluate_expression (expr);
9665796c8dcSSimon Schubert     }
9675796c8dcSSimon Schubert   else
9685796c8dcSSimon Schubert     val = access_value_history (0);
9695796c8dcSSimon Schubert 
9705796c8dcSSimon Schubert   if (voidprint || (val && value_type (val) &&
9715796c8dcSSimon Schubert 		    TYPE_CODE (value_type (val)) != TYPE_CODE_VOID))
9725796c8dcSSimon Schubert     {
9735796c8dcSSimon Schubert       struct value_print_options opts;
9745796c8dcSSimon Schubert       int histindex = record_latest_value (val);
9755796c8dcSSimon Schubert 
9765796c8dcSSimon Schubert       if (histindex >= 0)
9775796c8dcSSimon Schubert 	annotate_value_history_begin (histindex, value_type (val));
9785796c8dcSSimon Schubert       else
9795796c8dcSSimon Schubert 	annotate_value_begin (value_type (val));
9805796c8dcSSimon Schubert 
981*ef5ccd6cSJohn Marino       if (histindex >= 0)
9825796c8dcSSimon Schubert 	printf_filtered ("$%d = ", histindex);
9835796c8dcSSimon Schubert 
9845796c8dcSSimon Schubert       if (histindex >= 0)
9855796c8dcSSimon Schubert 	annotate_value_history_value ();
9865796c8dcSSimon Schubert 
9875796c8dcSSimon Schubert       get_formatted_print_options (&opts, format);
9885796c8dcSSimon Schubert       opts.raw = fmt.raw;
9895796c8dcSSimon Schubert 
9905796c8dcSSimon Schubert       print_formatted (val, fmt.size, &opts, gdb_stdout);
9915796c8dcSSimon Schubert       printf_filtered ("\n");
9925796c8dcSSimon Schubert 
9935796c8dcSSimon Schubert       if (histindex >= 0)
9945796c8dcSSimon Schubert 	annotate_value_history_end ();
9955796c8dcSSimon Schubert       else
9965796c8dcSSimon Schubert 	annotate_value_end ();
9975796c8dcSSimon Schubert     }
9985796c8dcSSimon Schubert 
9995796c8dcSSimon Schubert   if (cleanup)
10005796c8dcSSimon Schubert     do_cleanups (old_chain);
10015796c8dcSSimon Schubert }
10025796c8dcSSimon Schubert 
10035796c8dcSSimon Schubert static void
print_command(char * exp,int from_tty)10045796c8dcSSimon Schubert print_command (char *exp, int from_tty)
10055796c8dcSSimon Schubert {
1006*ef5ccd6cSJohn Marino   print_command_1 (exp, 1);
10075796c8dcSSimon Schubert }
10085796c8dcSSimon Schubert 
10095796c8dcSSimon Schubert /* Same as print, except it doesn't print void results.  */
10105796c8dcSSimon Schubert static void
call_command(char * exp,int from_tty)10115796c8dcSSimon Schubert call_command (char *exp, int from_tty)
10125796c8dcSSimon Schubert {
1013*ef5ccd6cSJohn Marino   print_command_1 (exp, 0);
10145796c8dcSSimon Schubert }
10155796c8dcSSimon Schubert 
10165796c8dcSSimon Schubert void
output_command(char * exp,int from_tty)10175796c8dcSSimon Schubert output_command (char *exp, int from_tty)
10185796c8dcSSimon Schubert {
10195796c8dcSSimon Schubert   struct expression *expr;
10205796c8dcSSimon Schubert   struct cleanup *old_chain;
10215796c8dcSSimon Schubert   char format = 0;
10225796c8dcSSimon Schubert   struct value *val;
10235796c8dcSSimon Schubert   struct format_data fmt;
10245796c8dcSSimon Schubert   struct value_print_options opts;
10255796c8dcSSimon Schubert 
10265796c8dcSSimon Schubert   fmt.size = 0;
10275796c8dcSSimon Schubert   fmt.raw = 0;
10285796c8dcSSimon Schubert 
10295796c8dcSSimon Schubert   if (exp && *exp == '/')
10305796c8dcSSimon Schubert     {
10315796c8dcSSimon Schubert       exp++;
10325796c8dcSSimon Schubert       fmt = decode_format (&exp, 0, 0);
10335796c8dcSSimon Schubert       validate_format (fmt, "output");
10345796c8dcSSimon Schubert       format = fmt.format;
10355796c8dcSSimon Schubert     }
10365796c8dcSSimon Schubert 
10375796c8dcSSimon Schubert   expr = parse_expression (exp);
10385796c8dcSSimon Schubert   old_chain = make_cleanup (free_current_contents, &expr);
10395796c8dcSSimon Schubert 
10405796c8dcSSimon Schubert   val = evaluate_expression (expr);
10415796c8dcSSimon Schubert 
10425796c8dcSSimon Schubert   annotate_value_begin (value_type (val));
10435796c8dcSSimon Schubert 
10445796c8dcSSimon Schubert   get_formatted_print_options (&opts, format);
10455796c8dcSSimon Schubert   opts.raw = fmt.raw;
10465796c8dcSSimon Schubert   print_formatted (val, fmt.size, &opts, gdb_stdout);
10475796c8dcSSimon Schubert 
10485796c8dcSSimon Schubert   annotate_value_end ();
10495796c8dcSSimon Schubert 
10505796c8dcSSimon Schubert   wrap_here ("");
10515796c8dcSSimon Schubert   gdb_flush (gdb_stdout);
10525796c8dcSSimon Schubert 
10535796c8dcSSimon Schubert   do_cleanups (old_chain);
10545796c8dcSSimon Schubert }
10555796c8dcSSimon Schubert 
10565796c8dcSSimon Schubert static void
set_command(char * exp,int from_tty)10575796c8dcSSimon Schubert set_command (char *exp, int from_tty)
10585796c8dcSSimon Schubert {
10595796c8dcSSimon Schubert   struct expression *expr = parse_expression (exp);
10605796c8dcSSimon Schubert   struct cleanup *old_chain =
10615796c8dcSSimon Schubert     make_cleanup (free_current_contents, &expr);
1062cf7f2e2dSJohn Marino 
1063*ef5ccd6cSJohn Marino   if (expr->nelts >= 1)
1064*ef5ccd6cSJohn Marino     switch (expr->elts[0].opcode)
1065*ef5ccd6cSJohn Marino       {
1066*ef5ccd6cSJohn Marino       case UNOP_PREINCREMENT:
1067*ef5ccd6cSJohn Marino       case UNOP_POSTINCREMENT:
1068*ef5ccd6cSJohn Marino       case UNOP_PREDECREMENT:
1069*ef5ccd6cSJohn Marino       case UNOP_POSTDECREMENT:
1070*ef5ccd6cSJohn Marino       case BINOP_ASSIGN:
1071*ef5ccd6cSJohn Marino       case BINOP_ASSIGN_MODIFY:
1072*ef5ccd6cSJohn Marino       case BINOP_COMMA:
1073*ef5ccd6cSJohn Marino 	break;
1074*ef5ccd6cSJohn Marino       default:
1075*ef5ccd6cSJohn Marino 	warning
1076*ef5ccd6cSJohn Marino 	  (_("Expression is not an assignment (and might have no effect)"));
1077*ef5ccd6cSJohn Marino       }
1078*ef5ccd6cSJohn Marino 
10795796c8dcSSimon Schubert   evaluate_expression (expr);
10805796c8dcSSimon Schubert   do_cleanups (old_chain);
10815796c8dcSSimon Schubert }
10825796c8dcSSimon Schubert 
10835796c8dcSSimon Schubert static void
sym_info(char * arg,int from_tty)10845796c8dcSSimon Schubert sym_info (char *arg, int from_tty)
10855796c8dcSSimon Schubert {
10865796c8dcSSimon Schubert   struct minimal_symbol *msymbol;
10875796c8dcSSimon Schubert   struct objfile *objfile;
10885796c8dcSSimon Schubert   struct obj_section *osect;
10895796c8dcSSimon Schubert   CORE_ADDR addr, sect_addr;
10905796c8dcSSimon Schubert   int matches = 0;
10915796c8dcSSimon Schubert   unsigned int offset;
10925796c8dcSSimon Schubert 
10935796c8dcSSimon Schubert   if (!arg)
10945796c8dcSSimon Schubert     error_no_arg (_("address"));
10955796c8dcSSimon Schubert 
10965796c8dcSSimon Schubert   addr = parse_and_eval_address (arg);
10975796c8dcSSimon Schubert   ALL_OBJSECTIONS (objfile, osect)
10985796c8dcSSimon Schubert   {
10995796c8dcSSimon Schubert     /* Only process each object file once, even if there's a separate
11005796c8dcSSimon Schubert        debug file.  */
11015796c8dcSSimon Schubert     if (objfile->separate_debug_objfile_backlink)
11025796c8dcSSimon Schubert       continue;
11035796c8dcSSimon Schubert 
11045796c8dcSSimon Schubert     sect_addr = overlay_mapped_address (addr, osect);
11055796c8dcSSimon Schubert 
11065796c8dcSSimon Schubert     if (obj_section_addr (osect) <= sect_addr
11075796c8dcSSimon Schubert 	&& sect_addr < obj_section_endaddr (osect)
11085796c8dcSSimon Schubert 	&& (msymbol = lookup_minimal_symbol_by_pc_section (sect_addr, osect)))
11095796c8dcSSimon Schubert       {
11105796c8dcSSimon Schubert 	const char *obj_name, *mapped, *sec_name, *msym_name;
11115796c8dcSSimon Schubert 	char *loc_string;
11125796c8dcSSimon Schubert 	struct cleanup *old_chain;
11135796c8dcSSimon Schubert 
11145796c8dcSSimon Schubert 	matches = 1;
11155796c8dcSSimon Schubert 	offset = sect_addr - SYMBOL_VALUE_ADDRESS (msymbol);
11165796c8dcSSimon Schubert 	mapped = section_is_mapped (osect) ? _("mapped") : _("unmapped");
11175796c8dcSSimon Schubert 	sec_name = osect->the_bfd_section->name;
11185796c8dcSSimon Schubert 	msym_name = SYMBOL_PRINT_NAME (msymbol);
11195796c8dcSSimon Schubert 
11205796c8dcSSimon Schubert 	/* Don't print the offset if it is zero.
11215796c8dcSSimon Schubert 	   We assume there's no need to handle i18n of "sym + offset".  */
11225796c8dcSSimon Schubert 	if (offset)
11235796c8dcSSimon Schubert 	  loc_string = xstrprintf ("%s + %u", msym_name, offset);
11245796c8dcSSimon Schubert 	else
11255796c8dcSSimon Schubert 	  loc_string = xstrprintf ("%s", msym_name);
11265796c8dcSSimon Schubert 
11275796c8dcSSimon Schubert 	/* Use a cleanup to free loc_string in case the user quits
11285796c8dcSSimon Schubert 	   a pagination request inside printf_filtered.  */
11295796c8dcSSimon Schubert 	old_chain = make_cleanup (xfree, loc_string);
11305796c8dcSSimon Schubert 
11315796c8dcSSimon Schubert 	gdb_assert (osect->objfile && osect->objfile->name);
11325796c8dcSSimon Schubert 	obj_name = osect->objfile->name;
11335796c8dcSSimon Schubert 
11345796c8dcSSimon Schubert 	if (MULTI_OBJFILE_P ())
11355796c8dcSSimon Schubert 	  if (pc_in_unmapped_range (addr, osect))
11365796c8dcSSimon Schubert 	    if (section_is_overlay (osect))
11375796c8dcSSimon Schubert 	      printf_filtered (_("%s in load address range of "
11385796c8dcSSimon Schubert 				 "%s overlay section %s of %s\n"),
11395796c8dcSSimon Schubert 			       loc_string, mapped, sec_name, obj_name);
11405796c8dcSSimon Schubert 	    else
11415796c8dcSSimon Schubert 	      printf_filtered (_("%s in load address range of "
11425796c8dcSSimon Schubert 				 "section %s of %s\n"),
11435796c8dcSSimon Schubert 			       loc_string, sec_name, obj_name);
11445796c8dcSSimon Schubert 	  else
11455796c8dcSSimon Schubert 	    if (section_is_overlay (osect))
11465796c8dcSSimon Schubert 	      printf_filtered (_("%s in %s overlay section %s of %s\n"),
11475796c8dcSSimon Schubert 			       loc_string, mapped, sec_name, obj_name);
11485796c8dcSSimon Schubert 	    else
11495796c8dcSSimon Schubert 	      printf_filtered (_("%s in section %s of %s\n"),
11505796c8dcSSimon Schubert 			       loc_string, sec_name, obj_name);
11515796c8dcSSimon Schubert 	else
11525796c8dcSSimon Schubert 	  if (pc_in_unmapped_range (addr, osect))
11535796c8dcSSimon Schubert 	    if (section_is_overlay (osect))
11545796c8dcSSimon Schubert 	      printf_filtered (_("%s in load address range of %s overlay "
11555796c8dcSSimon Schubert 				 "section %s\n"),
11565796c8dcSSimon Schubert 			       loc_string, mapped, sec_name);
11575796c8dcSSimon Schubert 	    else
11585796c8dcSSimon Schubert 	      printf_filtered (_("%s in load address range of section %s\n"),
11595796c8dcSSimon Schubert 			       loc_string, sec_name);
11605796c8dcSSimon Schubert 	  else
11615796c8dcSSimon Schubert 	    if (section_is_overlay (osect))
11625796c8dcSSimon Schubert 	      printf_filtered (_("%s in %s overlay section %s\n"),
11635796c8dcSSimon Schubert 			       loc_string, mapped, sec_name);
11645796c8dcSSimon Schubert 	    else
11655796c8dcSSimon Schubert 	      printf_filtered (_("%s in section %s\n"),
11665796c8dcSSimon Schubert 			       loc_string, sec_name);
11675796c8dcSSimon Schubert 
11685796c8dcSSimon Schubert 	do_cleanups (old_chain);
11695796c8dcSSimon Schubert       }
11705796c8dcSSimon Schubert   }
11715796c8dcSSimon Schubert   if (matches == 0)
11725796c8dcSSimon Schubert     printf_filtered (_("No symbol matches %s.\n"), arg);
11735796c8dcSSimon Schubert }
11745796c8dcSSimon Schubert 
11755796c8dcSSimon Schubert static void
address_info(char * exp,int from_tty)11765796c8dcSSimon Schubert address_info (char *exp, int from_tty)
11775796c8dcSSimon Schubert {
11785796c8dcSSimon Schubert   struct gdbarch *gdbarch;
11795796c8dcSSimon Schubert   int regno;
11805796c8dcSSimon Schubert   struct symbol *sym;
11815796c8dcSSimon Schubert   struct minimal_symbol *msymbol;
11825796c8dcSSimon Schubert   long val;
11835796c8dcSSimon Schubert   struct obj_section *section;
1184cf7f2e2dSJohn Marino   CORE_ADDR load_addr, context_pc = 0;
1185*ef5ccd6cSJohn Marino   struct field_of_this_result is_a_field_of_this;
11865796c8dcSSimon Schubert 
11875796c8dcSSimon Schubert   if (exp == 0)
11885796c8dcSSimon Schubert     error (_("Argument required."));
11895796c8dcSSimon Schubert 
1190cf7f2e2dSJohn Marino   sym = lookup_symbol (exp, get_selected_block (&context_pc), VAR_DOMAIN,
11915796c8dcSSimon Schubert 		       &is_a_field_of_this);
11925796c8dcSSimon Schubert   if (sym == NULL)
11935796c8dcSSimon Schubert     {
1194*ef5ccd6cSJohn Marino       if (is_a_field_of_this.type != NULL)
11955796c8dcSSimon Schubert 	{
11965796c8dcSSimon Schubert 	  printf_filtered ("Symbol \"");
11975796c8dcSSimon Schubert 	  fprintf_symbol_filtered (gdb_stdout, exp,
11985796c8dcSSimon Schubert 				   current_language->la_language, DMGL_ANSI);
11995796c8dcSSimon Schubert 	  printf_filtered ("\" is a field of the local class variable ");
12005796c8dcSSimon Schubert 	  if (current_language->la_language == language_objc)
12015796c8dcSSimon Schubert 	    printf_filtered ("`self'\n");	/* ObjC equivalent of "this" */
12025796c8dcSSimon Schubert 	  else
12035796c8dcSSimon Schubert 	    printf_filtered ("`this'\n");
12045796c8dcSSimon Schubert 	  return;
12055796c8dcSSimon Schubert 	}
12065796c8dcSSimon Schubert 
12075796c8dcSSimon Schubert       msymbol = lookup_minimal_symbol (exp, NULL, NULL);
12085796c8dcSSimon Schubert 
12095796c8dcSSimon Schubert       if (msymbol != NULL)
12105796c8dcSSimon Schubert 	{
12115796c8dcSSimon Schubert 	  gdbarch = get_objfile_arch (msymbol_objfile (msymbol));
12125796c8dcSSimon Schubert 	  load_addr = SYMBOL_VALUE_ADDRESS (msymbol);
12135796c8dcSSimon Schubert 
12145796c8dcSSimon Schubert 	  printf_filtered ("Symbol \"");
12155796c8dcSSimon Schubert 	  fprintf_symbol_filtered (gdb_stdout, exp,
12165796c8dcSSimon Schubert 				   current_language->la_language, DMGL_ANSI);
12175796c8dcSSimon Schubert 	  printf_filtered ("\" is at ");
12185796c8dcSSimon Schubert 	  fputs_filtered (paddress (gdbarch, load_addr), gdb_stdout);
12195796c8dcSSimon Schubert 	  printf_filtered (" in a file compiled without debugging");
12205796c8dcSSimon Schubert 	  section = SYMBOL_OBJ_SECTION (msymbol);
12215796c8dcSSimon Schubert 	  if (section_is_overlay (section))
12225796c8dcSSimon Schubert 	    {
12235796c8dcSSimon Schubert 	      load_addr = overlay_unmapped_address (load_addr, section);
12245796c8dcSSimon Schubert 	      printf_filtered (",\n -- loaded at ");
12255796c8dcSSimon Schubert 	      fputs_filtered (paddress (gdbarch, load_addr), gdb_stdout);
12265796c8dcSSimon Schubert 	      printf_filtered (" in overlay section %s",
12275796c8dcSSimon Schubert 			       section->the_bfd_section->name);
12285796c8dcSSimon Schubert 	    }
12295796c8dcSSimon Schubert 	  printf_filtered (".\n");
12305796c8dcSSimon Schubert 	}
12315796c8dcSSimon Schubert       else
12325796c8dcSSimon Schubert 	error (_("No symbol \"%s\" in current context."), exp);
12335796c8dcSSimon Schubert       return;
12345796c8dcSSimon Schubert     }
12355796c8dcSSimon Schubert 
12365796c8dcSSimon Schubert   printf_filtered ("Symbol \"");
12375796c8dcSSimon Schubert   fprintf_symbol_filtered (gdb_stdout, SYMBOL_PRINT_NAME (sym),
12385796c8dcSSimon Schubert 			   current_language->la_language, DMGL_ANSI);
12395796c8dcSSimon Schubert   printf_filtered ("\" is ");
12405796c8dcSSimon Schubert   val = SYMBOL_VALUE (sym);
12415796c8dcSSimon Schubert   section = SYMBOL_OBJ_SECTION (sym);
12425796c8dcSSimon Schubert   gdbarch = get_objfile_arch (SYMBOL_SYMTAB (sym)->objfile);
12435796c8dcSSimon Schubert 
12445796c8dcSSimon Schubert   switch (SYMBOL_CLASS (sym))
12455796c8dcSSimon Schubert     {
12465796c8dcSSimon Schubert     case LOC_CONST:
12475796c8dcSSimon Schubert     case LOC_CONST_BYTES:
12485796c8dcSSimon Schubert       printf_filtered ("constant");
12495796c8dcSSimon Schubert       break;
12505796c8dcSSimon Schubert 
12515796c8dcSSimon Schubert     case LOC_LABEL:
12525796c8dcSSimon Schubert       printf_filtered ("a label at address ");
12535796c8dcSSimon Schubert       load_addr = SYMBOL_VALUE_ADDRESS (sym);
12545796c8dcSSimon Schubert       fputs_filtered (paddress (gdbarch, load_addr), gdb_stdout);
12555796c8dcSSimon Schubert       if (section_is_overlay (section))
12565796c8dcSSimon Schubert 	{
12575796c8dcSSimon Schubert 	  load_addr = overlay_unmapped_address (load_addr, section);
12585796c8dcSSimon Schubert 	  printf_filtered (",\n -- loaded at ");
12595796c8dcSSimon Schubert 	  fputs_filtered (paddress (gdbarch, load_addr), gdb_stdout);
12605796c8dcSSimon Schubert 	  printf_filtered (" in overlay section %s",
12615796c8dcSSimon Schubert 			   section->the_bfd_section->name);
12625796c8dcSSimon Schubert 	}
12635796c8dcSSimon Schubert       break;
12645796c8dcSSimon Schubert 
12655796c8dcSSimon Schubert     case LOC_COMPUTED:
12665796c8dcSSimon Schubert       /* FIXME: cagney/2004-01-26: It should be possible to
12675796c8dcSSimon Schubert 	 unconditionally call the SYMBOL_COMPUTED_OPS method when available.
12685796c8dcSSimon Schubert 	 Unfortunately DWARF 2 stores the frame-base (instead of the
12695796c8dcSSimon Schubert 	 function) location in a function's symbol.  Oops!  For the
12705796c8dcSSimon Schubert 	 moment enable this when/where applicable.  */
1271c50c785cSJohn Marino       SYMBOL_COMPUTED_OPS (sym)->describe_location (sym, context_pc,
1272c50c785cSJohn Marino 						    gdb_stdout);
12735796c8dcSSimon Schubert       break;
12745796c8dcSSimon Schubert 
12755796c8dcSSimon Schubert     case LOC_REGISTER:
12765796c8dcSSimon Schubert       /* GDBARCH is the architecture associated with the objfile the symbol
12775796c8dcSSimon Schubert 	 is defined in; the target architecture may be different, and may
12785796c8dcSSimon Schubert 	 provide additional registers.  However, we do not know the target
12795796c8dcSSimon Schubert 	 architecture at this point.  We assume the objfile architecture
12805796c8dcSSimon Schubert 	 will contain all the standard registers that occur in debug info
12815796c8dcSSimon Schubert 	 in that objfile.  */
12825796c8dcSSimon Schubert       regno = SYMBOL_REGISTER_OPS (sym)->register_number (sym, gdbarch);
12835796c8dcSSimon Schubert 
12845796c8dcSSimon Schubert       if (SYMBOL_IS_ARGUMENT (sym))
12855796c8dcSSimon Schubert 	printf_filtered (_("an argument in register %s"),
12865796c8dcSSimon Schubert 			 gdbarch_register_name (gdbarch, regno));
12875796c8dcSSimon Schubert       else
12885796c8dcSSimon Schubert 	printf_filtered (_("a variable in register %s"),
12895796c8dcSSimon Schubert 			 gdbarch_register_name (gdbarch, regno));
12905796c8dcSSimon Schubert       break;
12915796c8dcSSimon Schubert 
12925796c8dcSSimon Schubert     case LOC_STATIC:
12935796c8dcSSimon Schubert       printf_filtered (_("static storage at address "));
12945796c8dcSSimon Schubert       load_addr = SYMBOL_VALUE_ADDRESS (sym);
12955796c8dcSSimon Schubert       fputs_filtered (paddress (gdbarch, load_addr), gdb_stdout);
12965796c8dcSSimon Schubert       if (section_is_overlay (section))
12975796c8dcSSimon Schubert 	{
12985796c8dcSSimon Schubert 	  load_addr = overlay_unmapped_address (load_addr, section);
12995796c8dcSSimon Schubert 	  printf_filtered (_(",\n -- loaded at "));
13005796c8dcSSimon Schubert 	  fputs_filtered (paddress (gdbarch, load_addr), gdb_stdout);
13015796c8dcSSimon Schubert 	  printf_filtered (_(" in overlay section %s"),
13025796c8dcSSimon Schubert 			   section->the_bfd_section->name);
13035796c8dcSSimon Schubert 	}
13045796c8dcSSimon Schubert       break;
13055796c8dcSSimon Schubert 
13065796c8dcSSimon Schubert     case LOC_REGPARM_ADDR:
13075796c8dcSSimon Schubert       /* Note comment at LOC_REGISTER.  */
13085796c8dcSSimon Schubert       regno = SYMBOL_REGISTER_OPS (sym)->register_number (sym, gdbarch);
13095796c8dcSSimon Schubert       printf_filtered (_("address of an argument in register %s"),
13105796c8dcSSimon Schubert 		       gdbarch_register_name (gdbarch, regno));
13115796c8dcSSimon Schubert       break;
13125796c8dcSSimon Schubert 
13135796c8dcSSimon Schubert     case LOC_ARG:
13145796c8dcSSimon Schubert       printf_filtered (_("an argument at offset %ld"), val);
13155796c8dcSSimon Schubert       break;
13165796c8dcSSimon Schubert 
13175796c8dcSSimon Schubert     case LOC_LOCAL:
13185796c8dcSSimon Schubert       printf_filtered (_("a local variable at frame offset %ld"), val);
13195796c8dcSSimon Schubert       break;
13205796c8dcSSimon Schubert 
13215796c8dcSSimon Schubert     case LOC_REF_ARG:
13225796c8dcSSimon Schubert       printf_filtered (_("a reference argument at offset %ld"), val);
13235796c8dcSSimon Schubert       break;
13245796c8dcSSimon Schubert 
13255796c8dcSSimon Schubert     case LOC_TYPEDEF:
13265796c8dcSSimon Schubert       printf_filtered (_("a typedef"));
13275796c8dcSSimon Schubert       break;
13285796c8dcSSimon Schubert 
13295796c8dcSSimon Schubert     case LOC_BLOCK:
13305796c8dcSSimon Schubert       printf_filtered (_("a function at address "));
13315796c8dcSSimon Schubert       load_addr = BLOCK_START (SYMBOL_BLOCK_VALUE (sym));
13325796c8dcSSimon Schubert       fputs_filtered (paddress (gdbarch, load_addr), gdb_stdout);
13335796c8dcSSimon Schubert       if (section_is_overlay (section))
13345796c8dcSSimon Schubert 	{
13355796c8dcSSimon Schubert 	  load_addr = overlay_unmapped_address (load_addr, section);
13365796c8dcSSimon Schubert 	  printf_filtered (_(",\n -- loaded at "));
13375796c8dcSSimon Schubert 	  fputs_filtered (paddress (gdbarch, load_addr), gdb_stdout);
13385796c8dcSSimon Schubert 	  printf_filtered (_(" in overlay section %s"),
13395796c8dcSSimon Schubert 			   section->the_bfd_section->name);
13405796c8dcSSimon Schubert 	}
13415796c8dcSSimon Schubert       break;
13425796c8dcSSimon Schubert 
13435796c8dcSSimon Schubert     case LOC_UNRESOLVED:
13445796c8dcSSimon Schubert       {
13455796c8dcSSimon Schubert 	struct minimal_symbol *msym;
13465796c8dcSSimon Schubert 
13475796c8dcSSimon Schubert 	msym = lookup_minimal_symbol (SYMBOL_LINKAGE_NAME (sym), NULL, NULL);
13485796c8dcSSimon Schubert 	if (msym == NULL)
13495796c8dcSSimon Schubert 	  printf_filtered ("unresolved");
13505796c8dcSSimon Schubert 	else
13515796c8dcSSimon Schubert 	  {
13525796c8dcSSimon Schubert 	    section = SYMBOL_OBJ_SECTION (msym);
13535796c8dcSSimon Schubert 	    load_addr = SYMBOL_VALUE_ADDRESS (msym);
13545796c8dcSSimon Schubert 
13555796c8dcSSimon Schubert 	    if (section
13565796c8dcSSimon Schubert 		&& (section->the_bfd_section->flags & SEC_THREAD_LOCAL) != 0)
13575796c8dcSSimon Schubert 	      printf_filtered (_("a thread-local variable at offset %s "
13585796c8dcSSimon Schubert 				 "in the thread-local storage for `%s'"),
13595796c8dcSSimon Schubert 			       paddress (gdbarch, load_addr),
13605796c8dcSSimon Schubert 			       section->objfile->name);
13615796c8dcSSimon Schubert 	    else
13625796c8dcSSimon Schubert 	      {
13635796c8dcSSimon Schubert 		printf_filtered (_("static storage at address "));
13645796c8dcSSimon Schubert 		fputs_filtered (paddress (gdbarch, load_addr), gdb_stdout);
13655796c8dcSSimon Schubert 		if (section_is_overlay (section))
13665796c8dcSSimon Schubert 		  {
13675796c8dcSSimon Schubert 		    load_addr = overlay_unmapped_address (load_addr, section);
13685796c8dcSSimon Schubert 		    printf_filtered (_(",\n -- loaded at "));
13695796c8dcSSimon Schubert 		    fputs_filtered (paddress (gdbarch, load_addr), gdb_stdout);
13705796c8dcSSimon Schubert 		    printf_filtered (_(" in overlay section %s"),
13715796c8dcSSimon Schubert 				     section->the_bfd_section->name);
13725796c8dcSSimon Schubert 		  }
13735796c8dcSSimon Schubert 	      }
13745796c8dcSSimon Schubert 	  }
13755796c8dcSSimon Schubert       }
13765796c8dcSSimon Schubert       break;
13775796c8dcSSimon Schubert 
13785796c8dcSSimon Schubert     case LOC_OPTIMIZED_OUT:
13795796c8dcSSimon Schubert       printf_filtered (_("optimized out"));
13805796c8dcSSimon Schubert       break;
13815796c8dcSSimon Schubert 
13825796c8dcSSimon Schubert     default:
13835796c8dcSSimon Schubert       printf_filtered (_("of unknown (botched) type"));
13845796c8dcSSimon Schubert       break;
13855796c8dcSSimon Schubert     }
13865796c8dcSSimon Schubert   printf_filtered (".\n");
13875796c8dcSSimon Schubert }
13885796c8dcSSimon Schubert 
13895796c8dcSSimon Schubert 
13905796c8dcSSimon Schubert static void
x_command(char * exp,int from_tty)13915796c8dcSSimon Schubert x_command (char *exp, int from_tty)
13925796c8dcSSimon Schubert {
13935796c8dcSSimon Schubert   struct expression *expr;
13945796c8dcSSimon Schubert   struct format_data fmt;
13955796c8dcSSimon Schubert   struct cleanup *old_chain;
13965796c8dcSSimon Schubert   struct value *val;
13975796c8dcSSimon Schubert 
13985796c8dcSSimon Schubert   fmt.format = last_format ? last_format : 'x';
13995796c8dcSSimon Schubert   fmt.size = last_size;
14005796c8dcSSimon Schubert   fmt.count = 1;
14015796c8dcSSimon Schubert   fmt.raw = 0;
14025796c8dcSSimon Schubert 
14035796c8dcSSimon Schubert   if (exp && *exp == '/')
14045796c8dcSSimon Schubert     {
14055796c8dcSSimon Schubert       exp++;
14065796c8dcSSimon Schubert       fmt = decode_format (&exp, last_format, last_size);
14075796c8dcSSimon Schubert     }
14085796c8dcSSimon Schubert 
14095796c8dcSSimon Schubert   /* If we have an expression, evaluate it and use it as the address.  */
14105796c8dcSSimon Schubert 
14115796c8dcSSimon Schubert   if (exp != 0 && *exp != 0)
14125796c8dcSSimon Schubert     {
14135796c8dcSSimon Schubert       expr = parse_expression (exp);
14145796c8dcSSimon Schubert       /* Cause expression not to be there any more if this command is
14155796c8dcSSimon Schubert          repeated with Newline.  But don't clobber a user-defined
14165796c8dcSSimon Schubert          command's definition.  */
14175796c8dcSSimon Schubert       if (from_tty)
14185796c8dcSSimon Schubert 	*exp = 0;
14195796c8dcSSimon Schubert       old_chain = make_cleanup (free_current_contents, &expr);
14205796c8dcSSimon Schubert       val = evaluate_expression (expr);
14215796c8dcSSimon Schubert       if (TYPE_CODE (value_type (val)) == TYPE_CODE_REF)
1422cf7f2e2dSJohn Marino 	val = coerce_ref (val);
14235796c8dcSSimon Schubert       /* In rvalue contexts, such as this, functions are coerced into
14245796c8dcSSimon Schubert          pointers to functions.  This makes "x/i main" work.  */
14255796c8dcSSimon Schubert       if (/* last_format == 'i'  && */
14265796c8dcSSimon Schubert 	  TYPE_CODE (value_type (val)) == TYPE_CODE_FUNC
14275796c8dcSSimon Schubert 	   && VALUE_LVAL (val) == lval_memory)
14285796c8dcSSimon Schubert 	next_address = value_address (val);
14295796c8dcSSimon Schubert       else
14305796c8dcSSimon Schubert 	next_address = value_as_address (val);
14315796c8dcSSimon Schubert 
14325796c8dcSSimon Schubert       next_gdbarch = expr->gdbarch;
14335796c8dcSSimon Schubert       do_cleanups (old_chain);
14345796c8dcSSimon Schubert     }
14355796c8dcSSimon Schubert 
14365796c8dcSSimon Schubert   if (!next_gdbarch)
14375796c8dcSSimon Schubert     error_no_arg (_("starting display address"));
14385796c8dcSSimon Schubert 
14395796c8dcSSimon Schubert   do_examine (fmt, next_gdbarch, next_address);
14405796c8dcSSimon Schubert 
14415796c8dcSSimon Schubert   /* If the examine succeeds, we remember its size and format for next
1442cf7f2e2dSJohn Marino      time.  Set last_size to 'b' for strings.  */
1443cf7f2e2dSJohn Marino   if (fmt.format == 's')
1444cf7f2e2dSJohn Marino     last_size = 'b';
1445cf7f2e2dSJohn Marino   else
14465796c8dcSSimon Schubert     last_size = fmt.size;
14475796c8dcSSimon Schubert   last_format = fmt.format;
14485796c8dcSSimon Schubert 
14495796c8dcSSimon Schubert   /* Set a couple of internal variables if appropriate.  */
14505796c8dcSSimon Schubert   if (last_examine_value)
14515796c8dcSSimon Schubert     {
14525796c8dcSSimon Schubert       /* Make last address examined available to the user as $_.  Use
14535796c8dcSSimon Schubert          the correct pointer type.  */
14545796c8dcSSimon Schubert       struct type *pointer_type
14555796c8dcSSimon Schubert 	= lookup_pointer_type (value_type (last_examine_value));
14565796c8dcSSimon Schubert       set_internalvar (lookup_internalvar ("_"),
14575796c8dcSSimon Schubert 		       value_from_pointer (pointer_type,
14585796c8dcSSimon Schubert 					   last_examine_address));
14595796c8dcSSimon Schubert 
14605796c8dcSSimon Schubert       /* Make contents of last address examined available to the user
14615796c8dcSSimon Schubert 	 as $__.  If the last value has not been fetched from memory
14625796c8dcSSimon Schubert 	 then don't fetch it now; instead mark it by voiding the $__
14635796c8dcSSimon Schubert 	 variable.  */
14645796c8dcSSimon Schubert       if (value_lazy (last_examine_value))
14655796c8dcSSimon Schubert 	clear_internalvar (lookup_internalvar ("__"));
14665796c8dcSSimon Schubert       else
14675796c8dcSSimon Schubert 	set_internalvar (lookup_internalvar ("__"), last_examine_value);
14685796c8dcSSimon Schubert     }
14695796c8dcSSimon Schubert }
14705796c8dcSSimon Schubert 
14715796c8dcSSimon Schubert 
14725796c8dcSSimon Schubert /* Add an expression to the auto-display chain.
14735796c8dcSSimon Schubert    Specify the expression.  */
14745796c8dcSSimon Schubert 
14755796c8dcSSimon Schubert static void
display_command(char * exp,int from_tty)14765796c8dcSSimon Schubert display_command (char *exp, int from_tty)
14775796c8dcSSimon Schubert {
14785796c8dcSSimon Schubert   struct format_data fmt;
14795796c8dcSSimon Schubert   struct expression *expr;
14805796c8dcSSimon Schubert   struct display *new;
14815796c8dcSSimon Schubert   int display_it = 1;
14825796c8dcSSimon Schubert 
14835796c8dcSSimon Schubert #if defined(TUI)
14845796c8dcSSimon Schubert   /* NOTE: cagney/2003-02-13 The `tui_active' was previously
14855796c8dcSSimon Schubert      `tui_version'.  */
14865796c8dcSSimon Schubert   if (tui_active && exp != NULL && *exp == '$')
14875796c8dcSSimon Schubert     display_it = (tui_set_layout_for_display_command (exp) == TUI_FAILURE);
14885796c8dcSSimon Schubert #endif
14895796c8dcSSimon Schubert 
14905796c8dcSSimon Schubert   if (display_it)
14915796c8dcSSimon Schubert     {
14925796c8dcSSimon Schubert       if (exp == 0)
14935796c8dcSSimon Schubert 	{
14945796c8dcSSimon Schubert 	  do_displays ();
14955796c8dcSSimon Schubert 	  return;
14965796c8dcSSimon Schubert 	}
14975796c8dcSSimon Schubert 
14985796c8dcSSimon Schubert       if (*exp == '/')
14995796c8dcSSimon Schubert 	{
15005796c8dcSSimon Schubert 	  exp++;
15015796c8dcSSimon Schubert 	  fmt = decode_format (&exp, 0, 0);
15025796c8dcSSimon Schubert 	  if (fmt.size && fmt.format == 0)
15035796c8dcSSimon Schubert 	    fmt.format = 'x';
15045796c8dcSSimon Schubert 	  if (fmt.format == 'i' || fmt.format == 's')
15055796c8dcSSimon Schubert 	    fmt.size = 'b';
15065796c8dcSSimon Schubert 	}
15075796c8dcSSimon Schubert       else
15085796c8dcSSimon Schubert 	{
15095796c8dcSSimon Schubert 	  fmt.format = 0;
15105796c8dcSSimon Schubert 	  fmt.size = 0;
15115796c8dcSSimon Schubert 	  fmt.count = 0;
15125796c8dcSSimon Schubert 	  fmt.raw = 0;
15135796c8dcSSimon Schubert 	}
15145796c8dcSSimon Schubert 
15155796c8dcSSimon Schubert       innermost_block = NULL;
15165796c8dcSSimon Schubert       expr = parse_expression (exp);
15175796c8dcSSimon Schubert 
15185796c8dcSSimon Schubert       new = (struct display *) xmalloc (sizeof (struct display));
15195796c8dcSSimon Schubert 
15205796c8dcSSimon Schubert       new->exp_string = xstrdup (exp);
15215796c8dcSSimon Schubert       new->exp = expr;
15225796c8dcSSimon Schubert       new->block = innermost_block;
1523cf7f2e2dSJohn Marino       new->pspace = current_program_space;
15245796c8dcSSimon Schubert       new->next = display_chain;
15255796c8dcSSimon Schubert       new->number = ++display_number;
15265796c8dcSSimon Schubert       new->format = fmt;
15275796c8dcSSimon Schubert       new->enabled_p = 1;
15285796c8dcSSimon Schubert       display_chain = new;
15295796c8dcSSimon Schubert 
15305796c8dcSSimon Schubert       if (from_tty && target_has_execution)
15315796c8dcSSimon Schubert 	do_one_display (new);
15325796c8dcSSimon Schubert 
15335796c8dcSSimon Schubert       dont_repeat ();
15345796c8dcSSimon Schubert     }
15355796c8dcSSimon Schubert }
15365796c8dcSSimon Schubert 
15375796c8dcSSimon Schubert static void
free_display(struct display * d)15385796c8dcSSimon Schubert free_display (struct display *d)
15395796c8dcSSimon Schubert {
15405796c8dcSSimon Schubert   xfree (d->exp_string);
15415796c8dcSSimon Schubert   xfree (d->exp);
15425796c8dcSSimon Schubert   xfree (d);
15435796c8dcSSimon Schubert }
15445796c8dcSSimon Schubert 
15455796c8dcSSimon Schubert /* Clear out the display_chain.  Done when new symtabs are loaded,
15465796c8dcSSimon Schubert    since this invalidates the types stored in many expressions.  */
15475796c8dcSSimon Schubert 
15485796c8dcSSimon Schubert void
clear_displays(void)15495796c8dcSSimon Schubert clear_displays (void)
15505796c8dcSSimon Schubert {
15515796c8dcSSimon Schubert   struct display *d;
15525796c8dcSSimon Schubert 
15535796c8dcSSimon Schubert   while ((d = display_chain) != NULL)
15545796c8dcSSimon Schubert     {
15555796c8dcSSimon Schubert       display_chain = d->next;
15565796c8dcSSimon Schubert       free_display (d);
15575796c8dcSSimon Schubert     }
15585796c8dcSSimon Schubert }
15595796c8dcSSimon Schubert 
1560c50c785cSJohn Marino /* Delete the auto-display DISPLAY.  */
15615796c8dcSSimon Schubert 
15625796c8dcSSimon Schubert static void
delete_display(struct display * display)1563c50c785cSJohn Marino delete_display (struct display *display)
15645796c8dcSSimon Schubert {
1565c50c785cSJohn Marino   struct display *d;
15665796c8dcSSimon Schubert 
1567c50c785cSJohn Marino   gdb_assert (display != NULL);
15685796c8dcSSimon Schubert 
1569c50c785cSJohn Marino   if (display_chain == display)
1570c50c785cSJohn Marino     display_chain = display->next;
1571c50c785cSJohn Marino 
1572c50c785cSJohn Marino   ALL_DISPLAYS (d)
1573c50c785cSJohn Marino     if (d->next == display)
15745796c8dcSSimon Schubert       {
1575c50c785cSJohn Marino 	d->next = display->next;
15765796c8dcSSimon Schubert 	break;
15775796c8dcSSimon Schubert       }
1578c50c785cSJohn Marino 
1579c50c785cSJohn Marino   free_display (display);
1580c50c785cSJohn Marino }
1581c50c785cSJohn Marino 
1582c50c785cSJohn Marino /* Call FUNCTION on each of the displays whose numbers are given in
1583c50c785cSJohn Marino    ARGS.  DATA is passed unmodified to FUNCTION.  */
1584c50c785cSJohn Marino 
1585c50c785cSJohn Marino static void
map_display_numbers(char * args,void (* function)(struct display *,void *),void * data)1586c50c785cSJohn Marino map_display_numbers (char *args,
1587c50c785cSJohn Marino 		     void (*function) (struct display *,
1588c50c785cSJohn Marino 				       void *),
1589c50c785cSJohn Marino 		     void *data)
1590c50c785cSJohn Marino {
1591c50c785cSJohn Marino   struct get_number_or_range_state state;
1592c50c785cSJohn Marino   int num;
1593c50c785cSJohn Marino 
1594c50c785cSJohn Marino   if (args == NULL)
1595c50c785cSJohn Marino     error_no_arg (_("one or more display numbers"));
1596c50c785cSJohn Marino 
1597c50c785cSJohn Marino   init_number_or_range (&state, args);
1598c50c785cSJohn Marino 
1599c50c785cSJohn Marino   while (!state.finished)
1600c50c785cSJohn Marino     {
1601c50c785cSJohn Marino       char *p = state.string;
1602c50c785cSJohn Marino 
1603c50c785cSJohn Marino       num = get_number_or_range (&state);
1604c50c785cSJohn Marino       if (num == 0)
1605c50c785cSJohn Marino 	warning (_("bad display number at or near '%s'"), p);
1606c50c785cSJohn Marino       else
1607c50c785cSJohn Marino 	{
1608c50c785cSJohn Marino 	  struct display *d, *tmp;
1609c50c785cSJohn Marino 
1610c50c785cSJohn Marino 	  ALL_DISPLAYS_SAFE (d, tmp)
1611c50c785cSJohn Marino 	    if (d->number == num)
1612c50c785cSJohn Marino 	      break;
1613c50c785cSJohn Marino 	  if (d == NULL)
1614c50c785cSJohn Marino 	    printf_unfiltered (_("No display number %d.\n"), num);
1615c50c785cSJohn Marino 	  else
1616c50c785cSJohn Marino 	    function (d, data);
1617c50c785cSJohn Marino 	}
16185796c8dcSSimon Schubert     }
16195796c8dcSSimon Schubert }
16205796c8dcSSimon Schubert 
1621c50c785cSJohn Marino /* Callback for map_display_numbers, that deletes a display.  */
1622c50c785cSJohn Marino 
1623c50c785cSJohn Marino static void
do_delete_display(struct display * d,void * data)1624c50c785cSJohn Marino do_delete_display (struct display *d, void *data)
1625c50c785cSJohn Marino {
1626c50c785cSJohn Marino   delete_display (d);
1627c50c785cSJohn Marino }
1628c50c785cSJohn Marino 
1629c50c785cSJohn Marino /* "undisplay" command.  */
16305796c8dcSSimon Schubert 
16315796c8dcSSimon Schubert static void
undisplay_command(char * args,int from_tty)16325796c8dcSSimon Schubert undisplay_command (char *args, int from_tty)
16335796c8dcSSimon Schubert {
1634c50c785cSJohn Marino   if (args == NULL)
16355796c8dcSSimon Schubert     {
16365796c8dcSSimon Schubert       if (query (_("Delete all auto-display expressions? ")))
16375796c8dcSSimon Schubert 	clear_displays ();
16385796c8dcSSimon Schubert       dont_repeat ();
16395796c8dcSSimon Schubert       return;
16405796c8dcSSimon Schubert     }
16415796c8dcSSimon Schubert 
1642c50c785cSJohn Marino   map_display_numbers (args, do_delete_display, NULL);
16435796c8dcSSimon Schubert   dont_repeat ();
16445796c8dcSSimon Schubert }
16455796c8dcSSimon Schubert 
16465796c8dcSSimon Schubert /* Display a single auto-display.
16475796c8dcSSimon Schubert    Do nothing if the display cannot be printed in the current context,
16485796c8dcSSimon Schubert    or if the display is disabled.  */
16495796c8dcSSimon Schubert 
16505796c8dcSSimon Schubert static void
do_one_display(struct display * d)16515796c8dcSSimon Schubert do_one_display (struct display *d)
16525796c8dcSSimon Schubert {
1653a45ae5f8SJohn Marino   struct cleanup *old_chain;
16545796c8dcSSimon Schubert   int within_current_scope;
16555796c8dcSSimon Schubert 
16565796c8dcSSimon Schubert   if (d->enabled_p == 0)
16575796c8dcSSimon Schubert     return;
16585796c8dcSSimon Schubert 
1659cf7f2e2dSJohn Marino   /* The expression carries the architecture that was used at parse time.
1660cf7f2e2dSJohn Marino      This is a problem if the expression depends on architecture features
1661cf7f2e2dSJohn Marino      (e.g. register numbers), and the current architecture is now different.
1662cf7f2e2dSJohn Marino      For example, a display statement like "display/i $pc" is expected to
1663cf7f2e2dSJohn Marino      display the PC register of the current architecture, not the arch at
1664cf7f2e2dSJohn Marino      the time the display command was given.  Therefore, we re-parse the
1665cf7f2e2dSJohn Marino      expression if the current architecture has changed.  */
1666cf7f2e2dSJohn Marino   if (d->exp != NULL && d->exp->gdbarch != get_current_arch ())
1667cf7f2e2dSJohn Marino     {
1668cf7f2e2dSJohn Marino       xfree (d->exp);
1669cf7f2e2dSJohn Marino       d->exp = NULL;
1670cf7f2e2dSJohn Marino       d->block = NULL;
1671cf7f2e2dSJohn Marino     }
1672cf7f2e2dSJohn Marino 
16735796c8dcSSimon Schubert   if (d->exp == NULL)
16745796c8dcSSimon Schubert     {
16755796c8dcSSimon Schubert       volatile struct gdb_exception ex;
1676cf7f2e2dSJohn Marino 
16775796c8dcSSimon Schubert       TRY_CATCH (ex, RETURN_MASK_ALL)
16785796c8dcSSimon Schubert 	{
16795796c8dcSSimon Schubert 	  innermost_block = NULL;
16805796c8dcSSimon Schubert 	  d->exp = parse_expression (d->exp_string);
16815796c8dcSSimon Schubert 	  d->block = innermost_block;
16825796c8dcSSimon Schubert 	}
16835796c8dcSSimon Schubert       if (ex.reason < 0)
16845796c8dcSSimon Schubert 	{
16855796c8dcSSimon Schubert 	  /* Can't re-parse the expression.  Disable this display item.  */
16865796c8dcSSimon Schubert 	  d->enabled_p = 0;
16875796c8dcSSimon Schubert 	  warning (_("Unable to display \"%s\": %s"),
16885796c8dcSSimon Schubert 		   d->exp_string, ex.message);
16895796c8dcSSimon Schubert 	  return;
16905796c8dcSSimon Schubert 	}
16915796c8dcSSimon Schubert     }
16925796c8dcSSimon Schubert 
16935796c8dcSSimon Schubert   if (d->block)
1694cf7f2e2dSJohn Marino     {
1695cf7f2e2dSJohn Marino       if (d->pspace == current_program_space)
16965796c8dcSSimon Schubert 	within_current_scope = contained_in (get_selected_block (0), d->block);
16975796c8dcSSimon Schubert       else
1698cf7f2e2dSJohn Marino 	within_current_scope = 0;
1699cf7f2e2dSJohn Marino     }
1700cf7f2e2dSJohn Marino   else
17015796c8dcSSimon Schubert     within_current_scope = 1;
17025796c8dcSSimon Schubert   if (!within_current_scope)
17035796c8dcSSimon Schubert     return;
17045796c8dcSSimon Schubert 
1705a45ae5f8SJohn Marino   old_chain = make_cleanup_restore_integer (&current_display_number);
17065796c8dcSSimon Schubert   current_display_number = d->number;
17075796c8dcSSimon Schubert 
17085796c8dcSSimon Schubert   annotate_display_begin ();
17095796c8dcSSimon Schubert   printf_filtered ("%d", d->number);
17105796c8dcSSimon Schubert   annotate_display_number_end ();
17115796c8dcSSimon Schubert   printf_filtered (": ");
17125796c8dcSSimon Schubert   if (d->format.size)
17135796c8dcSSimon Schubert     {
1714a45ae5f8SJohn Marino       volatile struct gdb_exception ex;
17155796c8dcSSimon Schubert 
17165796c8dcSSimon Schubert       annotate_display_format ();
17175796c8dcSSimon Schubert 
17185796c8dcSSimon Schubert       printf_filtered ("x/");
17195796c8dcSSimon Schubert       if (d->format.count != 1)
17205796c8dcSSimon Schubert 	printf_filtered ("%d", d->format.count);
17215796c8dcSSimon Schubert       printf_filtered ("%c", d->format.format);
17225796c8dcSSimon Schubert       if (d->format.format != 'i' && d->format.format != 's')
17235796c8dcSSimon Schubert 	printf_filtered ("%c", d->format.size);
17245796c8dcSSimon Schubert       printf_filtered (" ");
17255796c8dcSSimon Schubert 
17265796c8dcSSimon Schubert       annotate_display_expression ();
17275796c8dcSSimon Schubert 
17285796c8dcSSimon Schubert       puts_filtered (d->exp_string);
17295796c8dcSSimon Schubert       annotate_display_expression_end ();
17305796c8dcSSimon Schubert 
17315796c8dcSSimon Schubert       if (d->format.count != 1 || d->format.format == 'i')
17325796c8dcSSimon Schubert 	printf_filtered ("\n");
17335796c8dcSSimon Schubert       else
17345796c8dcSSimon Schubert 	printf_filtered ("  ");
17355796c8dcSSimon Schubert 
1736a45ae5f8SJohn Marino       annotate_display_value ();
1737a45ae5f8SJohn Marino 
1738a45ae5f8SJohn Marino       TRY_CATCH (ex, RETURN_MASK_ERROR)
1739a45ae5f8SJohn Marino         {
1740a45ae5f8SJohn Marino 	  struct value *val;
1741a45ae5f8SJohn Marino 	  CORE_ADDR addr;
1742a45ae5f8SJohn Marino 
17435796c8dcSSimon Schubert 	  val = evaluate_expression (d->exp);
17445796c8dcSSimon Schubert 	  addr = value_as_address (val);
17455796c8dcSSimon Schubert 	  if (d->format.format == 'i')
17465796c8dcSSimon Schubert 	    addr = gdbarch_addr_bits_remove (d->exp->gdbarch, addr);
17475796c8dcSSimon Schubert 	  do_examine (d->format, d->exp->gdbarch, addr);
17485796c8dcSSimon Schubert 	}
1749a45ae5f8SJohn Marino       if (ex.reason < 0)
1750a45ae5f8SJohn Marino 	fprintf_filtered (gdb_stdout, _("<error: %s>\n"), ex.message);
1751a45ae5f8SJohn Marino     }
17525796c8dcSSimon Schubert   else
17535796c8dcSSimon Schubert     {
17545796c8dcSSimon Schubert       struct value_print_options opts;
1755a45ae5f8SJohn Marino       volatile struct gdb_exception ex;
17565796c8dcSSimon Schubert 
17575796c8dcSSimon Schubert       annotate_display_format ();
17585796c8dcSSimon Schubert 
17595796c8dcSSimon Schubert       if (d->format.format)
17605796c8dcSSimon Schubert 	printf_filtered ("/%c ", d->format.format);
17615796c8dcSSimon Schubert 
17625796c8dcSSimon Schubert       annotate_display_expression ();
17635796c8dcSSimon Schubert 
17645796c8dcSSimon Schubert       puts_filtered (d->exp_string);
17655796c8dcSSimon Schubert       annotate_display_expression_end ();
17665796c8dcSSimon Schubert 
17675796c8dcSSimon Schubert       printf_filtered (" = ");
17685796c8dcSSimon Schubert 
17695796c8dcSSimon Schubert       annotate_display_expression ();
17705796c8dcSSimon Schubert 
17715796c8dcSSimon Schubert       get_formatted_print_options (&opts, d->format.format);
17725796c8dcSSimon Schubert       opts.raw = d->format.raw;
1773a45ae5f8SJohn Marino 
1774a45ae5f8SJohn Marino       TRY_CATCH (ex, RETURN_MASK_ERROR)
1775a45ae5f8SJohn Marino         {
1776a45ae5f8SJohn Marino 	  struct value *val;
1777a45ae5f8SJohn Marino 
1778a45ae5f8SJohn Marino 	  val = evaluate_expression (d->exp);
1779a45ae5f8SJohn Marino 	  print_formatted (val, d->format.size, &opts, gdb_stdout);
1780a45ae5f8SJohn Marino 	}
1781a45ae5f8SJohn Marino       if (ex.reason < 0)
1782a45ae5f8SJohn Marino 	fprintf_filtered (gdb_stdout, _("<error: %s>"), ex.message);
17835796c8dcSSimon Schubert       printf_filtered ("\n");
17845796c8dcSSimon Schubert     }
17855796c8dcSSimon Schubert 
17865796c8dcSSimon Schubert   annotate_display_end ();
17875796c8dcSSimon Schubert 
17885796c8dcSSimon Schubert   gdb_flush (gdb_stdout);
1789a45ae5f8SJohn Marino   do_cleanups (old_chain);
17905796c8dcSSimon Schubert }
17915796c8dcSSimon Schubert 
17925796c8dcSSimon Schubert /* Display all of the values on the auto-display chain which can be
17935796c8dcSSimon Schubert    evaluated in the current scope.  */
17945796c8dcSSimon Schubert 
17955796c8dcSSimon Schubert void
do_displays(void)17965796c8dcSSimon Schubert do_displays (void)
17975796c8dcSSimon Schubert {
17985796c8dcSSimon Schubert   struct display *d;
17995796c8dcSSimon Schubert 
18005796c8dcSSimon Schubert   for (d = display_chain; d; d = d->next)
18015796c8dcSSimon Schubert     do_one_display (d);
18025796c8dcSSimon Schubert }
18035796c8dcSSimon Schubert 
18045796c8dcSSimon Schubert /* Delete the auto-display which we were in the process of displaying.
18055796c8dcSSimon Schubert    This is done when there is an error or a signal.  */
18065796c8dcSSimon Schubert 
18075796c8dcSSimon Schubert void
disable_display(int num)18085796c8dcSSimon Schubert disable_display (int num)
18095796c8dcSSimon Schubert {
18105796c8dcSSimon Schubert   struct display *d;
18115796c8dcSSimon Schubert 
18125796c8dcSSimon Schubert   for (d = display_chain; d; d = d->next)
18135796c8dcSSimon Schubert     if (d->number == num)
18145796c8dcSSimon Schubert       {
18155796c8dcSSimon Schubert 	d->enabled_p = 0;
18165796c8dcSSimon Schubert 	return;
18175796c8dcSSimon Schubert       }
18185796c8dcSSimon Schubert   printf_unfiltered (_("No display number %d.\n"), num);
18195796c8dcSSimon Schubert }
18205796c8dcSSimon Schubert 
18215796c8dcSSimon Schubert void
disable_current_display(void)18225796c8dcSSimon Schubert disable_current_display (void)
18235796c8dcSSimon Schubert {
18245796c8dcSSimon Schubert   if (current_display_number >= 0)
18255796c8dcSSimon Schubert     {
18265796c8dcSSimon Schubert       disable_display (current_display_number);
1827c50c785cSJohn Marino       fprintf_unfiltered (gdb_stderr,
1828c50c785cSJohn Marino 			  _("Disabling display %d to "
1829c50c785cSJohn Marino 			    "avoid infinite recursion.\n"),
18305796c8dcSSimon Schubert 			  current_display_number);
18315796c8dcSSimon Schubert     }
18325796c8dcSSimon Schubert   current_display_number = -1;
18335796c8dcSSimon Schubert }
18345796c8dcSSimon Schubert 
18355796c8dcSSimon Schubert static void
display_info(char * ignore,int from_tty)18365796c8dcSSimon Schubert display_info (char *ignore, int from_tty)
18375796c8dcSSimon Schubert {
18385796c8dcSSimon Schubert   struct display *d;
18395796c8dcSSimon Schubert 
18405796c8dcSSimon Schubert   if (!display_chain)
18415796c8dcSSimon Schubert     printf_unfiltered (_("There are no auto-display expressions now.\n"));
18425796c8dcSSimon Schubert   else
18435796c8dcSSimon Schubert     printf_filtered (_("Auto-display expressions now in effect:\n\
18445796c8dcSSimon Schubert Num Enb Expression\n"));
18455796c8dcSSimon Schubert 
18465796c8dcSSimon Schubert   for (d = display_chain; d; d = d->next)
18475796c8dcSSimon Schubert     {
18485796c8dcSSimon Schubert       printf_filtered ("%d:   %c  ", d->number, "ny"[(int) d->enabled_p]);
18495796c8dcSSimon Schubert       if (d->format.size)
18505796c8dcSSimon Schubert 	printf_filtered ("/%d%c%c ", d->format.count, d->format.size,
18515796c8dcSSimon Schubert 			 d->format.format);
18525796c8dcSSimon Schubert       else if (d->format.format)
18535796c8dcSSimon Schubert 	printf_filtered ("/%c ", d->format.format);
18545796c8dcSSimon Schubert       puts_filtered (d->exp_string);
18555796c8dcSSimon Schubert       if (d->block && !contained_in (get_selected_block (0), d->block))
18565796c8dcSSimon Schubert 	printf_filtered (_(" (cannot be evaluated in the current context)"));
18575796c8dcSSimon Schubert       printf_filtered ("\n");
18585796c8dcSSimon Schubert       gdb_flush (gdb_stdout);
18595796c8dcSSimon Schubert     }
18605796c8dcSSimon Schubert }
18615796c8dcSSimon Schubert 
1862c50c785cSJohn Marino /* Callback fo map_display_numbers, that enables or disables the
1863c50c785cSJohn Marino    passed in display D.  */
1864c50c785cSJohn Marino 
18655796c8dcSSimon Schubert static void
do_enable_disable_display(struct display * d,void * data)1866c50c785cSJohn Marino do_enable_disable_display (struct display *d, void *data)
18675796c8dcSSimon Schubert {
1868c50c785cSJohn Marino   d->enabled_p = *(int *) data;
1869c50c785cSJohn Marino }
1870c50c785cSJohn Marino 
1871c50c785cSJohn Marino /* Implamentation of both the "disable display" and "enable display"
1872c50c785cSJohn Marino    commands.  ENABLE decides what to do.  */
1873c50c785cSJohn Marino 
1874c50c785cSJohn Marino static void
enable_disable_display_command(char * args,int from_tty,int enable)1875c50c785cSJohn Marino enable_disable_display_command (char *args, int from_tty, int enable)
1876c50c785cSJohn Marino {
1877c50c785cSJohn Marino   if (args == NULL)
1878c50c785cSJohn Marino     {
18795796c8dcSSimon Schubert       struct display *d;
18805796c8dcSSimon Schubert 
1881c50c785cSJohn Marino       ALL_DISPLAYS (d)
1882c50c785cSJohn Marino 	d->enabled_p = enable;
1883c50c785cSJohn Marino       return;
18845796c8dcSSimon Schubert     }
18855796c8dcSSimon Schubert 
1886c50c785cSJohn Marino   map_display_numbers (args, do_enable_disable_display, &enable);
1887c50c785cSJohn Marino }
18885796c8dcSSimon Schubert 
1889c50c785cSJohn Marino /* The "enable display" command.  */
1890c50c785cSJohn Marino 
1891c50c785cSJohn Marino static void
enable_display_command(char * args,int from_tty)1892c50c785cSJohn Marino enable_display_command (char *args, int from_tty)
18935796c8dcSSimon Schubert {
1894c50c785cSJohn Marino   enable_disable_display_command (args, from_tty, 1);
18955796c8dcSSimon Schubert }
1896c50c785cSJohn Marino 
1897c50c785cSJohn Marino /* The "disable display" command.  */
18985796c8dcSSimon Schubert 
18995796c8dcSSimon Schubert static void
disable_display_command(char * args,int from_tty)19005796c8dcSSimon Schubert disable_display_command (char *args, int from_tty)
19015796c8dcSSimon Schubert {
1902c50c785cSJohn Marino   enable_disable_display_command (args, from_tty, 0);
19035796c8dcSSimon Schubert }
19045796c8dcSSimon Schubert 
19055796c8dcSSimon Schubert /* display_chain items point to blocks and expressions.  Some expressions in
19065796c8dcSSimon Schubert    turn may point to symbols.
19075796c8dcSSimon Schubert    Both symbols and blocks are obstack_alloc'd on objfile_stack, and are
19085796c8dcSSimon Schubert    obstack_free'd when a shared library is unloaded.
19095796c8dcSSimon Schubert    Clear pointers that are about to become dangling.
19105796c8dcSSimon Schubert    Both .exp and .block fields will be restored next time we need to display
19115796c8dcSSimon Schubert    an item by re-parsing .exp_string field in the new execution context.  */
19125796c8dcSSimon Schubert 
19135796c8dcSSimon Schubert static void
clear_dangling_display_expressions(struct so_list * solib)19145796c8dcSSimon Schubert clear_dangling_display_expressions (struct so_list *solib)
19155796c8dcSSimon Schubert {
1916cf7f2e2dSJohn Marino   struct objfile *objfile = solib->objfile;
19175796c8dcSSimon Schubert   struct display *d;
19185796c8dcSSimon Schubert 
1919cf7f2e2dSJohn Marino   /* With no symbol file we cannot have a block or expression from it.  */
1920cf7f2e2dSJohn Marino   if (objfile == NULL)
1921cf7f2e2dSJohn Marino     return;
1922cf7f2e2dSJohn Marino   if (objfile->separate_debug_objfile_backlink)
1923cf7f2e2dSJohn Marino     objfile = objfile->separate_debug_objfile_backlink;
1924cf7f2e2dSJohn Marino   gdb_assert (objfile->pspace == solib->pspace);
1925cf7f2e2dSJohn Marino 
1926cf7f2e2dSJohn Marino   for (d = display_chain; d != NULL; d = d->next)
19275796c8dcSSimon Schubert     {
1928cf7f2e2dSJohn Marino       if (d->pspace != solib->pspace)
1929cf7f2e2dSJohn Marino 	continue;
1930cf7f2e2dSJohn Marino 
1931cf7f2e2dSJohn Marino       if (lookup_objfile_from_block (d->block) == objfile
1932cf7f2e2dSJohn Marino 	  || (d->exp && exp_uses_objfile (d->exp, objfile)))
19335796c8dcSSimon Schubert       {
19345796c8dcSSimon Schubert 	xfree (d->exp);
19355796c8dcSSimon Schubert 	d->exp = NULL;
19365796c8dcSSimon Schubert 	d->block = NULL;
19375796c8dcSSimon Schubert       }
19385796c8dcSSimon Schubert     }
19395796c8dcSSimon Schubert }
19405796c8dcSSimon Schubert 
19415796c8dcSSimon Schubert 
19425796c8dcSSimon Schubert /* Print the value in stack frame FRAME of a variable specified by a
19435796c8dcSSimon Schubert    struct symbol.  NAME is the name to print; if NULL then VAR's print
19445796c8dcSSimon Schubert    name will be used.  STREAM is the ui_file on which to print the
19455796c8dcSSimon Schubert    value.  INDENT specifies the number of indent levels to print
1946*ef5ccd6cSJohn Marino    before printing the variable name.
1947*ef5ccd6cSJohn Marino 
1948*ef5ccd6cSJohn Marino    This function invalidates FRAME.  */
19495796c8dcSSimon Schubert 
19505796c8dcSSimon Schubert void
print_variable_and_value(const char * name,struct symbol * var,struct frame_info * frame,struct ui_file * stream,int indent)19515796c8dcSSimon Schubert print_variable_and_value (const char *name, struct symbol *var,
19525796c8dcSSimon Schubert 			  struct frame_info *frame,
19535796c8dcSSimon Schubert 			  struct ui_file *stream, int indent)
19545796c8dcSSimon Schubert {
1955cf7f2e2dSJohn Marino   volatile struct gdb_exception except;
19565796c8dcSSimon Schubert 
19575796c8dcSSimon Schubert   if (!name)
19585796c8dcSSimon Schubert     name = SYMBOL_PRINT_NAME (var);
19595796c8dcSSimon Schubert 
19605796c8dcSSimon Schubert   fprintf_filtered (stream, "%s%s = ", n_spaces (2 * indent), name);
1961cf7f2e2dSJohn Marino   TRY_CATCH (except, RETURN_MASK_ERROR)
1962cf7f2e2dSJohn Marino     {
1963cf7f2e2dSJohn Marino       struct value *val;
1964cf7f2e2dSJohn Marino       struct value_print_options opts;
19655796c8dcSSimon Schubert 
19665796c8dcSSimon Schubert       val = read_var_value (var, frame);
19675796c8dcSSimon Schubert       get_user_print_options (&opts);
1968a45ae5f8SJohn Marino       opts.deref_ref = 1;
19695796c8dcSSimon Schubert       common_val_print (val, stream, indent, &opts, current_language);
1970*ef5ccd6cSJohn Marino 
1971*ef5ccd6cSJohn Marino       /* common_val_print invalidates FRAME when a pretty printer calls inferior
1972*ef5ccd6cSJohn Marino 	 function.  */
1973*ef5ccd6cSJohn Marino       frame = NULL;
1974cf7f2e2dSJohn Marino     }
1975cf7f2e2dSJohn Marino   if (except.reason < 0)
1976cf7f2e2dSJohn Marino     fprintf_filtered(stream, "<error reading variable %s (%s)>", name,
1977cf7f2e2dSJohn Marino 		     except.message);
19785796c8dcSSimon Schubert   fprintf_filtered (stream, "\n");
19795796c8dcSSimon Schubert }
19805796c8dcSSimon Schubert 
1981*ef5ccd6cSJohn Marino /* Subroutine of ui_printf to simplify it.
1982*ef5ccd6cSJohn Marino    Print VALUE to STREAM using FORMAT.
1983*ef5ccd6cSJohn Marino    VALUE is a C-style string on the target.  */
1984cf7f2e2dSJohn Marino 
19855796c8dcSSimon Schubert static void
printf_c_string(struct ui_file * stream,const char * format,struct value * value)1986*ef5ccd6cSJohn Marino printf_c_string (struct ui_file *stream, const char *format,
1987*ef5ccd6cSJohn Marino 		 struct value *value)
19885796c8dcSSimon Schubert {
19895796c8dcSSimon Schubert   gdb_byte *str;
19905796c8dcSSimon Schubert   CORE_ADDR tem;
19915796c8dcSSimon Schubert   int j;
1992cf7f2e2dSJohn Marino 
1993*ef5ccd6cSJohn Marino   tem = value_as_address (value);
19945796c8dcSSimon Schubert 
19955796c8dcSSimon Schubert   /* This is a %s argument.  Find the length of the string.  */
19965796c8dcSSimon Schubert   for (j = 0;; j++)
19975796c8dcSSimon Schubert     {
19985796c8dcSSimon Schubert       gdb_byte c;
1999cf7f2e2dSJohn Marino 
20005796c8dcSSimon Schubert       QUIT;
20015796c8dcSSimon Schubert       read_memory (tem + j, &c, 1);
20025796c8dcSSimon Schubert       if (c == 0)
20035796c8dcSSimon Schubert 	break;
20045796c8dcSSimon Schubert     }
20055796c8dcSSimon Schubert 
20065796c8dcSSimon Schubert   /* Copy the string contents into a string inside GDB.  */
20075796c8dcSSimon Schubert   str = (gdb_byte *) alloca (j + 1);
20085796c8dcSSimon Schubert   if (j != 0)
20095796c8dcSSimon Schubert     read_memory (tem, str, j);
20105796c8dcSSimon Schubert   str[j] = 0;
20115796c8dcSSimon Schubert 
2012*ef5ccd6cSJohn Marino   fprintf_filtered (stream, format, (char *) str);
20135796c8dcSSimon Schubert }
2014*ef5ccd6cSJohn Marino 
2015*ef5ccd6cSJohn Marino /* Subroutine of ui_printf to simplify it.
2016*ef5ccd6cSJohn Marino    Print VALUE to STREAM using FORMAT.
2017*ef5ccd6cSJohn Marino    VALUE is a wide C-style string on the target.  */
2018*ef5ccd6cSJohn Marino 
2019*ef5ccd6cSJohn Marino static void
printf_wide_c_string(struct ui_file * stream,const char * format,struct value * value)2020*ef5ccd6cSJohn Marino printf_wide_c_string (struct ui_file *stream, const char *format,
2021*ef5ccd6cSJohn Marino 		      struct value *value)
20225796c8dcSSimon Schubert {
20235796c8dcSSimon Schubert   gdb_byte *str;
20245796c8dcSSimon Schubert   CORE_ADDR tem;
20255796c8dcSSimon Schubert   int j;
2026*ef5ccd6cSJohn Marino   struct gdbarch *gdbarch = get_type_arch (value_type (value));
20275796c8dcSSimon Schubert   enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
20285796c8dcSSimon Schubert   struct type *wctype = lookup_typename (current_language, gdbarch,
20295796c8dcSSimon Schubert 					 "wchar_t", NULL, 0);
20305796c8dcSSimon Schubert   int wcwidth = TYPE_LENGTH (wctype);
20315796c8dcSSimon Schubert   gdb_byte *buf = alloca (wcwidth);
20325796c8dcSSimon Schubert   struct obstack output;
20335796c8dcSSimon Schubert   struct cleanup *inner_cleanup;
20345796c8dcSSimon Schubert 
2035*ef5ccd6cSJohn Marino   tem = value_as_address (value);
20365796c8dcSSimon Schubert 
20375796c8dcSSimon Schubert   /* This is a %s argument.  Find the length of the string.  */
20385796c8dcSSimon Schubert   for (j = 0;; j += wcwidth)
20395796c8dcSSimon Schubert     {
20405796c8dcSSimon Schubert       QUIT;
20415796c8dcSSimon Schubert       read_memory (tem + j, buf, wcwidth);
20425796c8dcSSimon Schubert       if (extract_unsigned_integer (buf, wcwidth, byte_order) == 0)
20435796c8dcSSimon Schubert 	break;
20445796c8dcSSimon Schubert     }
20455796c8dcSSimon Schubert 
20465796c8dcSSimon Schubert   /* Copy the string contents into a string inside GDB.  */
20475796c8dcSSimon Schubert   str = (gdb_byte *) alloca (j + wcwidth);
20485796c8dcSSimon Schubert   if (j != 0)
20495796c8dcSSimon Schubert     read_memory (tem, str, j);
20505796c8dcSSimon Schubert   memset (&str[j], 0, wcwidth);
20515796c8dcSSimon Schubert 
20525796c8dcSSimon Schubert   obstack_init (&output);
20535796c8dcSSimon Schubert   inner_cleanup = make_cleanup_obstack_free (&output);
20545796c8dcSSimon Schubert 
2055cf7f2e2dSJohn Marino   convert_between_encodings (target_wide_charset (gdbarch),
20565796c8dcSSimon Schubert 			     host_charset (),
20575796c8dcSSimon Schubert 			     str, j, wcwidth,
20585796c8dcSSimon Schubert 			     &output, translit_char);
20595796c8dcSSimon Schubert   obstack_grow_str0 (&output, "");
20605796c8dcSSimon Schubert 
2061*ef5ccd6cSJohn Marino   fprintf_filtered (stream, format, obstack_base (&output));
20625796c8dcSSimon Schubert   do_cleanups (inner_cleanup);
20635796c8dcSSimon Schubert }
2064*ef5ccd6cSJohn Marino 
2065*ef5ccd6cSJohn Marino /* Subroutine of ui_printf to simplify it.
2066*ef5ccd6cSJohn Marino    Print VALUE, a decimal floating point value, to STREAM using FORMAT.  */
2067*ef5ccd6cSJohn Marino 
2068*ef5ccd6cSJohn Marino static void
printf_decfloat(struct ui_file * stream,const char * format,struct value * value)2069*ef5ccd6cSJohn Marino printf_decfloat (struct ui_file *stream, const char *format,
2070*ef5ccd6cSJohn Marino 		 struct value *value)
2071*ef5ccd6cSJohn Marino {
2072*ef5ccd6cSJohn Marino   const gdb_byte *param_ptr = value_contents (value);
2073*ef5ccd6cSJohn Marino 
2074*ef5ccd6cSJohn Marino #if defined (PRINTF_HAS_DECFLOAT)
2075*ef5ccd6cSJohn Marino   /* If we have native support for Decimal floating
2076*ef5ccd6cSJohn Marino      printing, handle it here.  */
2077*ef5ccd6cSJohn Marino   fprintf_filtered (stream, format, param_ptr);
2078*ef5ccd6cSJohn Marino #else
2079*ef5ccd6cSJohn Marino   /* As a workaround until vasprintf has native support for DFP
2080*ef5ccd6cSJohn Marino      we convert the DFP values to string and print them using
2081*ef5ccd6cSJohn Marino      the %s format specifier.  */
2082*ef5ccd6cSJohn Marino   const char *p;
2083*ef5ccd6cSJohn Marino 
2084*ef5ccd6cSJohn Marino   /* Parameter data.  */
2085*ef5ccd6cSJohn Marino   struct type *param_type = value_type (value);
2086*ef5ccd6cSJohn Marino   struct gdbarch *gdbarch = get_type_arch (param_type);
2087*ef5ccd6cSJohn Marino   enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
2088*ef5ccd6cSJohn Marino 
2089*ef5ccd6cSJohn Marino   /* DFP output data.  */
2090*ef5ccd6cSJohn Marino   struct value *dfp_value = NULL;
2091*ef5ccd6cSJohn Marino   gdb_byte *dfp_ptr;
2092*ef5ccd6cSJohn Marino   int dfp_len = 16;
2093*ef5ccd6cSJohn Marino   gdb_byte dec[16];
2094*ef5ccd6cSJohn Marino   struct type *dfp_type = NULL;
2095*ef5ccd6cSJohn Marino   char decstr[MAX_DECIMAL_STRING];
2096*ef5ccd6cSJohn Marino 
2097*ef5ccd6cSJohn Marino   /* Points to the end of the string so that we can go back
2098*ef5ccd6cSJohn Marino      and check for DFP length modifiers.  */
2099*ef5ccd6cSJohn Marino   p = format + strlen (format);
2100*ef5ccd6cSJohn Marino 
2101*ef5ccd6cSJohn Marino   /* Look for the float/double format specifier.  */
2102*ef5ccd6cSJohn Marino   while (*p != 'f' && *p != 'e' && *p != 'E'
2103*ef5ccd6cSJohn Marino 	 && *p != 'g' && *p != 'G')
2104*ef5ccd6cSJohn Marino     p--;
2105*ef5ccd6cSJohn Marino 
2106*ef5ccd6cSJohn Marino   /* Search for the '%' char and extract the size and type of
2107*ef5ccd6cSJohn Marino      the output decimal value based on its modifiers
2108*ef5ccd6cSJohn Marino      (%Hf, %Df, %DDf).  */
2109*ef5ccd6cSJohn Marino   while (*--p != '%')
2110*ef5ccd6cSJohn Marino     {
2111*ef5ccd6cSJohn Marino       if (*p == 'H')
2112*ef5ccd6cSJohn Marino 	{
2113*ef5ccd6cSJohn Marino 	  dfp_len = 4;
2114*ef5ccd6cSJohn Marino 	  dfp_type = builtin_type (gdbarch)->builtin_decfloat;
2115*ef5ccd6cSJohn Marino 	}
2116*ef5ccd6cSJohn Marino       else if (*p == 'D' && *(p - 1) == 'D')
2117*ef5ccd6cSJohn Marino 	{
2118*ef5ccd6cSJohn Marino 	  dfp_len = 16;
2119*ef5ccd6cSJohn Marino 	  dfp_type = builtin_type (gdbarch)->builtin_declong;
2120*ef5ccd6cSJohn Marino 	  p--;
2121*ef5ccd6cSJohn Marino 	}
2122*ef5ccd6cSJohn Marino       else
2123*ef5ccd6cSJohn Marino 	{
2124*ef5ccd6cSJohn Marino 	  dfp_len = 8;
2125*ef5ccd6cSJohn Marino 	  dfp_type = builtin_type (gdbarch)->builtin_decdouble;
2126*ef5ccd6cSJohn Marino 	}
2127*ef5ccd6cSJohn Marino     }
2128*ef5ccd6cSJohn Marino 
2129*ef5ccd6cSJohn Marino   /* Conversion between different DFP types.  */
2130*ef5ccd6cSJohn Marino   if (TYPE_CODE (param_type) == TYPE_CODE_DECFLOAT)
2131*ef5ccd6cSJohn Marino     decimal_convert (param_ptr, TYPE_LENGTH (param_type),
2132*ef5ccd6cSJohn Marino 		     byte_order, dec, dfp_len, byte_order);
2133*ef5ccd6cSJohn Marino   else
2134*ef5ccd6cSJohn Marino     /* If this is a non-trivial conversion, just output 0.
2135*ef5ccd6cSJohn Marino        A correct converted value can be displayed by explicitly
2136*ef5ccd6cSJohn Marino        casting to a DFP type.  */
2137*ef5ccd6cSJohn Marino     decimal_from_string (dec, dfp_len, byte_order, "0");
2138*ef5ccd6cSJohn Marino 
2139*ef5ccd6cSJohn Marino   dfp_value = value_from_decfloat (dfp_type, dec);
2140*ef5ccd6cSJohn Marino 
2141*ef5ccd6cSJohn Marino   dfp_ptr = (gdb_byte *) value_contents (dfp_value);
2142*ef5ccd6cSJohn Marino 
2143*ef5ccd6cSJohn Marino   decimal_to_string (dfp_ptr, dfp_len, byte_order, decstr);
2144*ef5ccd6cSJohn Marino 
2145*ef5ccd6cSJohn Marino   /* Print the DFP value.  */
2146*ef5ccd6cSJohn Marino   fprintf_filtered (stream, "%s", decstr);
2147*ef5ccd6cSJohn Marino #endif
2148*ef5ccd6cSJohn Marino }
2149*ef5ccd6cSJohn Marino 
2150*ef5ccd6cSJohn Marino /* Subroutine of ui_printf to simplify it.
2151*ef5ccd6cSJohn Marino    Print VALUE, a target pointer, to STREAM using FORMAT.  */
2152*ef5ccd6cSJohn Marino 
2153*ef5ccd6cSJohn Marino static void
printf_pointer(struct ui_file * stream,const char * format,struct value * value)2154*ef5ccd6cSJohn Marino printf_pointer (struct ui_file *stream, const char *format,
2155*ef5ccd6cSJohn Marino 		struct value *value)
2156*ef5ccd6cSJohn Marino {
2157*ef5ccd6cSJohn Marino   /* We avoid the host's %p because pointers are too
2158*ef5ccd6cSJohn Marino      likely to be the wrong size.  The only interesting
2159*ef5ccd6cSJohn Marino      modifier for %p is a width; extract that, and then
2160*ef5ccd6cSJohn Marino      handle %p as glibc would: %#x or a literal "(nil)".  */
2161*ef5ccd6cSJohn Marino 
2162*ef5ccd6cSJohn Marino   const char *p;
2163*ef5ccd6cSJohn Marino   char *fmt, *fmt_p;
2164*ef5ccd6cSJohn Marino #ifdef PRINTF_HAS_LONG_LONG
2165*ef5ccd6cSJohn Marino   long long val = value_as_long (value);
2166*ef5ccd6cSJohn Marino #else
2167*ef5ccd6cSJohn Marino   long val = value_as_long (value);
2168*ef5ccd6cSJohn Marino #endif
2169*ef5ccd6cSJohn Marino 
2170*ef5ccd6cSJohn Marino   fmt = alloca (strlen (format) + 5);
2171*ef5ccd6cSJohn Marino 
2172*ef5ccd6cSJohn Marino   /* Copy up to the leading %.  */
2173*ef5ccd6cSJohn Marino   p = format;
2174*ef5ccd6cSJohn Marino   fmt_p = fmt;
2175*ef5ccd6cSJohn Marino   while (*p)
2176*ef5ccd6cSJohn Marino     {
2177*ef5ccd6cSJohn Marino       int is_percent = (*p == '%');
2178*ef5ccd6cSJohn Marino 
2179*ef5ccd6cSJohn Marino       *fmt_p++ = *p++;
2180*ef5ccd6cSJohn Marino       if (is_percent)
2181*ef5ccd6cSJohn Marino 	{
2182*ef5ccd6cSJohn Marino 	  if (*p == '%')
2183*ef5ccd6cSJohn Marino 	    *fmt_p++ = *p++;
2184*ef5ccd6cSJohn Marino 	  else
2185*ef5ccd6cSJohn Marino 	    break;
2186*ef5ccd6cSJohn Marino 	}
2187*ef5ccd6cSJohn Marino     }
2188*ef5ccd6cSJohn Marino 
2189*ef5ccd6cSJohn Marino   if (val != 0)
2190*ef5ccd6cSJohn Marino     *fmt_p++ = '#';
2191*ef5ccd6cSJohn Marino 
2192*ef5ccd6cSJohn Marino   /* Copy any width.  */
2193*ef5ccd6cSJohn Marino   while (*p >= '0' && *p < '9')
2194*ef5ccd6cSJohn Marino     *fmt_p++ = *p++;
2195*ef5ccd6cSJohn Marino 
2196*ef5ccd6cSJohn Marino   gdb_assert (*p == 'p' && *(p + 1) == '\0');
2197*ef5ccd6cSJohn Marino   if (val != 0)
2198*ef5ccd6cSJohn Marino     {
2199*ef5ccd6cSJohn Marino #ifdef PRINTF_HAS_LONG_LONG
2200*ef5ccd6cSJohn Marino       *fmt_p++ = 'l';
2201*ef5ccd6cSJohn Marino #endif
2202*ef5ccd6cSJohn Marino       *fmt_p++ = 'l';
2203*ef5ccd6cSJohn Marino       *fmt_p++ = 'x';
2204*ef5ccd6cSJohn Marino       *fmt_p++ = '\0';
2205*ef5ccd6cSJohn Marino       fprintf_filtered (stream, fmt, val);
2206*ef5ccd6cSJohn Marino     }
2207*ef5ccd6cSJohn Marino   else
2208*ef5ccd6cSJohn Marino     {
2209*ef5ccd6cSJohn Marino       *fmt_p++ = 's';
2210*ef5ccd6cSJohn Marino       *fmt_p++ = '\0';
2211*ef5ccd6cSJohn Marino       fprintf_filtered (stream, fmt, "(nil)");
2212*ef5ccd6cSJohn Marino     }
2213*ef5ccd6cSJohn Marino }
2214*ef5ccd6cSJohn Marino 
2215*ef5ccd6cSJohn Marino /* printf "printf format string" ARG to STREAM.  */
2216*ef5ccd6cSJohn Marino 
2217*ef5ccd6cSJohn Marino static void
ui_printf(const char * arg,struct ui_file * stream)2218*ef5ccd6cSJohn Marino ui_printf (const char *arg, struct ui_file *stream)
2219*ef5ccd6cSJohn Marino {
2220*ef5ccd6cSJohn Marino   struct format_piece *fpieces;
2221*ef5ccd6cSJohn Marino   const char *s = arg;
2222*ef5ccd6cSJohn Marino   struct value **val_args;
2223*ef5ccd6cSJohn Marino   int allocated_args = 20;
2224*ef5ccd6cSJohn Marino   struct cleanup *old_cleanups;
2225*ef5ccd6cSJohn Marino 
2226*ef5ccd6cSJohn Marino   val_args = xmalloc (allocated_args * sizeof (struct value *));
2227*ef5ccd6cSJohn Marino   old_cleanups = make_cleanup (free_current_contents, &val_args);
2228*ef5ccd6cSJohn Marino 
2229*ef5ccd6cSJohn Marino   if (s == 0)
2230*ef5ccd6cSJohn Marino     error_no_arg (_("format-control string and values to print"));
2231*ef5ccd6cSJohn Marino 
2232*ef5ccd6cSJohn Marino   s = skip_spaces_const (s);
2233*ef5ccd6cSJohn Marino 
2234*ef5ccd6cSJohn Marino   /* A format string should follow, enveloped in double quotes.  */
2235*ef5ccd6cSJohn Marino   if (*s++ != '"')
2236*ef5ccd6cSJohn Marino     error (_("Bad format string, missing '\"'."));
2237*ef5ccd6cSJohn Marino 
2238*ef5ccd6cSJohn Marino   fpieces = parse_format_string (&s);
2239*ef5ccd6cSJohn Marino 
2240*ef5ccd6cSJohn Marino   make_cleanup (free_format_pieces_cleanup, &fpieces);
2241*ef5ccd6cSJohn Marino 
2242*ef5ccd6cSJohn Marino   if (*s++ != '"')
2243*ef5ccd6cSJohn Marino     error (_("Bad format string, non-terminated '\"'."));
2244*ef5ccd6cSJohn Marino 
2245*ef5ccd6cSJohn Marino   s = skip_spaces_const (s);
2246*ef5ccd6cSJohn Marino 
2247*ef5ccd6cSJohn Marino   if (*s != ',' && *s != 0)
2248*ef5ccd6cSJohn Marino     error (_("Invalid argument syntax"));
2249*ef5ccd6cSJohn Marino 
2250*ef5ccd6cSJohn Marino   if (*s == ',')
2251*ef5ccd6cSJohn Marino     s++;
2252*ef5ccd6cSJohn Marino   s = skip_spaces_const (s);
2253*ef5ccd6cSJohn Marino 
2254*ef5ccd6cSJohn Marino   {
2255*ef5ccd6cSJohn Marino     int nargs = 0;
2256*ef5ccd6cSJohn Marino     int nargs_wanted;
2257*ef5ccd6cSJohn Marino     int i, fr;
2258*ef5ccd6cSJohn Marino     char *current_substring;
2259*ef5ccd6cSJohn Marino 
2260*ef5ccd6cSJohn Marino     nargs_wanted = 0;
2261*ef5ccd6cSJohn Marino     for (fr = 0; fpieces[fr].string != NULL; fr++)
2262*ef5ccd6cSJohn Marino       if (fpieces[fr].argclass != literal_piece)
2263*ef5ccd6cSJohn Marino 	++nargs_wanted;
2264*ef5ccd6cSJohn Marino 
2265*ef5ccd6cSJohn Marino     /* Now, parse all arguments and evaluate them.
2266*ef5ccd6cSJohn Marino        Store the VALUEs in VAL_ARGS.  */
2267*ef5ccd6cSJohn Marino 
2268*ef5ccd6cSJohn Marino     while (*s != '\0')
2269*ef5ccd6cSJohn Marino       {
2270*ef5ccd6cSJohn Marino 	const char *s1;
2271*ef5ccd6cSJohn Marino 
2272*ef5ccd6cSJohn Marino 	if (nargs == allocated_args)
2273*ef5ccd6cSJohn Marino 	  val_args = (struct value **) xrealloc ((char *) val_args,
2274*ef5ccd6cSJohn Marino 						 (allocated_args *= 2)
2275*ef5ccd6cSJohn Marino 						 * sizeof (struct value *));
2276*ef5ccd6cSJohn Marino 	s1 = s;
2277*ef5ccd6cSJohn Marino 	val_args[nargs] = parse_to_comma_and_eval (&s1);
2278*ef5ccd6cSJohn Marino 
2279*ef5ccd6cSJohn Marino 	nargs++;
2280*ef5ccd6cSJohn Marino 	s = s1;
2281*ef5ccd6cSJohn Marino 	if (*s == ',')
2282*ef5ccd6cSJohn Marino 	  s++;
2283*ef5ccd6cSJohn Marino       }
2284*ef5ccd6cSJohn Marino 
2285*ef5ccd6cSJohn Marino     if (nargs != nargs_wanted)
2286*ef5ccd6cSJohn Marino       error (_("Wrong number of arguments for specified format-string"));
2287*ef5ccd6cSJohn Marino 
2288*ef5ccd6cSJohn Marino     /* Now actually print them.  */
2289*ef5ccd6cSJohn Marino     i = 0;
2290*ef5ccd6cSJohn Marino     for (fr = 0; fpieces[fr].string != NULL; fr++)
2291*ef5ccd6cSJohn Marino       {
2292*ef5ccd6cSJohn Marino 	current_substring = fpieces[fr].string;
2293*ef5ccd6cSJohn Marino 	switch (fpieces[fr].argclass)
2294*ef5ccd6cSJohn Marino 	  {
2295*ef5ccd6cSJohn Marino 	  case string_arg:
2296*ef5ccd6cSJohn Marino 	    printf_c_string (stream, current_substring, val_args[i]);
2297*ef5ccd6cSJohn Marino 	    break;
2298*ef5ccd6cSJohn Marino 	  case wide_string_arg:
2299*ef5ccd6cSJohn Marino 	    printf_wide_c_string (stream, current_substring, val_args[i]);
23005796c8dcSSimon Schubert 	    break;
23015796c8dcSSimon Schubert 	  case wide_char_arg:
23025796c8dcSSimon Schubert 	    {
23035796c8dcSSimon Schubert 	      struct gdbarch *gdbarch
23045796c8dcSSimon Schubert 		= get_type_arch (value_type (val_args[i]));
23055796c8dcSSimon Schubert 	      struct type *wctype = lookup_typename (current_language, gdbarch,
23065796c8dcSSimon Schubert 						     "wchar_t", NULL, 0);
23075796c8dcSSimon Schubert 	      struct type *valtype;
23085796c8dcSSimon Schubert 	      struct obstack output;
23095796c8dcSSimon Schubert 	      struct cleanup *inner_cleanup;
23105796c8dcSSimon Schubert 	      const gdb_byte *bytes;
23115796c8dcSSimon Schubert 
23125796c8dcSSimon Schubert 	      valtype = value_type (val_args[i]);
23135796c8dcSSimon Schubert 	      if (TYPE_LENGTH (valtype) != TYPE_LENGTH (wctype)
23145796c8dcSSimon Schubert 		  || TYPE_CODE (valtype) != TYPE_CODE_INT)
23155796c8dcSSimon Schubert 		error (_("expected wchar_t argument for %%lc"));
23165796c8dcSSimon Schubert 
23175796c8dcSSimon Schubert 	      bytes = value_contents (val_args[i]);
23185796c8dcSSimon Schubert 
23195796c8dcSSimon Schubert 	      obstack_init (&output);
23205796c8dcSSimon Schubert 	      inner_cleanup = make_cleanup_obstack_free (&output);
23215796c8dcSSimon Schubert 
2322cf7f2e2dSJohn Marino 	      convert_between_encodings (target_wide_charset (gdbarch),
23235796c8dcSSimon Schubert 					 host_charset (),
23245796c8dcSSimon Schubert 					 bytes, TYPE_LENGTH (valtype),
23255796c8dcSSimon Schubert 					 TYPE_LENGTH (valtype),
23265796c8dcSSimon Schubert 					 &output, translit_char);
23275796c8dcSSimon Schubert 	      obstack_grow_str0 (&output, "");
23285796c8dcSSimon Schubert 
2329cf7f2e2dSJohn Marino 	      fprintf_filtered (stream, current_substring,
2330cf7f2e2dSJohn Marino                                 obstack_base (&output));
23315796c8dcSSimon Schubert 	      do_cleanups (inner_cleanup);
23325796c8dcSSimon Schubert 	    }
23335796c8dcSSimon Schubert 	    break;
23345796c8dcSSimon Schubert 	  case double_arg:
23355796c8dcSSimon Schubert 	    {
23365796c8dcSSimon Schubert 	      struct type *type = value_type (val_args[i]);
23375796c8dcSSimon Schubert 	      DOUBLEST val;
23385796c8dcSSimon Schubert 	      int inv;
23395796c8dcSSimon Schubert 
23405796c8dcSSimon Schubert 	      /* If format string wants a float, unchecked-convert the value
23415796c8dcSSimon Schubert 		 to floating point of the same size.  */
23425796c8dcSSimon Schubert 	      type = float_type_from_length (type);
23435796c8dcSSimon Schubert 	      val = unpack_double (type, value_contents (val_args[i]), &inv);
23445796c8dcSSimon Schubert 	      if (inv)
23455796c8dcSSimon Schubert 		error (_("Invalid floating value found in program."));
23465796c8dcSSimon Schubert 
2347cf7f2e2dSJohn Marino               fprintf_filtered (stream, current_substring, (double) val);
23485796c8dcSSimon Schubert 	      break;
23495796c8dcSSimon Schubert 	    }
23505796c8dcSSimon Schubert 	  case long_double_arg:
23515796c8dcSSimon Schubert #ifdef HAVE_LONG_DOUBLE
23525796c8dcSSimon Schubert 	    {
23535796c8dcSSimon Schubert 	      struct type *type = value_type (val_args[i]);
23545796c8dcSSimon Schubert 	      DOUBLEST val;
23555796c8dcSSimon Schubert 	      int inv;
23565796c8dcSSimon Schubert 
23575796c8dcSSimon Schubert 	      /* If format string wants a float, unchecked-convert the value
23585796c8dcSSimon Schubert 		 to floating point of the same size.  */
23595796c8dcSSimon Schubert 	      type = float_type_from_length (type);
23605796c8dcSSimon Schubert 	      val = unpack_double (type, value_contents (val_args[i]), &inv);
23615796c8dcSSimon Schubert 	      if (inv)
23625796c8dcSSimon Schubert 		error (_("Invalid floating value found in program."));
23635796c8dcSSimon Schubert 
2364cf7f2e2dSJohn Marino 	      fprintf_filtered (stream, current_substring,
2365cf7f2e2dSJohn Marino                                 (long double) val);
23665796c8dcSSimon Schubert 	      break;
23675796c8dcSSimon Schubert 	    }
23685796c8dcSSimon Schubert #else
23695796c8dcSSimon Schubert 	    error (_("long double not supported in printf"));
23705796c8dcSSimon Schubert #endif
23715796c8dcSSimon Schubert 	  case long_long_arg:
2372*ef5ccd6cSJohn Marino #ifdef PRINTF_HAS_LONG_LONG
23735796c8dcSSimon Schubert 	    {
23745796c8dcSSimon Schubert 	      long long val = value_as_long (val_args[i]);
2375cf7f2e2dSJohn Marino 
2376cf7f2e2dSJohn Marino               fprintf_filtered (stream, current_substring, val);
23775796c8dcSSimon Schubert 	      break;
23785796c8dcSSimon Schubert 	    }
23795796c8dcSSimon Schubert #else
23805796c8dcSSimon Schubert 	    error (_("long long not supported in printf"));
23815796c8dcSSimon Schubert #endif
23825796c8dcSSimon Schubert 	  case int_arg:
23835796c8dcSSimon Schubert 	    {
23845796c8dcSSimon Schubert 	      int val = value_as_long (val_args[i]);
2385cf7f2e2dSJohn Marino 
2386cf7f2e2dSJohn Marino               fprintf_filtered (stream, current_substring, val);
23875796c8dcSSimon Schubert 	      break;
23885796c8dcSSimon Schubert 	    }
23895796c8dcSSimon Schubert 	  case long_arg:
23905796c8dcSSimon Schubert 	    {
23915796c8dcSSimon Schubert 	      long val = value_as_long (val_args[i]);
2392cf7f2e2dSJohn Marino 
2393cf7f2e2dSJohn Marino               fprintf_filtered (stream, current_substring, val);
23945796c8dcSSimon Schubert 	      break;
23955796c8dcSSimon Schubert 	    }
23965796c8dcSSimon Schubert 	  /* Handles decimal floating values.  */
23975796c8dcSSimon Schubert 	  case decfloat_arg:
2398*ef5ccd6cSJohn Marino 	    printf_decfloat (stream, current_substring, val_args[i]);
23995796c8dcSSimon Schubert 	    break;
24005796c8dcSSimon Schubert 	  case ptr_arg:
2401*ef5ccd6cSJohn Marino 	    printf_pointer (stream, current_substring, val_args[i]);
24025796c8dcSSimon Schubert 	    break;
2403*ef5ccd6cSJohn Marino 	  case literal_piece:
2404*ef5ccd6cSJohn Marino 	    /* Print a portion of the format string that has no
2405*ef5ccd6cSJohn Marino 	       directives.  Note that this will not include any
2406*ef5ccd6cSJohn Marino 	       ordinary %-specs, but it might include "%%".  That is
2407*ef5ccd6cSJohn Marino 	       why we use printf_filtered and not puts_filtered here.
2408*ef5ccd6cSJohn Marino 	       Also, we pass a dummy argument because some platforms
2409*ef5ccd6cSJohn Marino 	       have modified GCC to include -Wformat-security by
2410*ef5ccd6cSJohn Marino 	       default, which will warn here if there is no
2411*ef5ccd6cSJohn Marino 	       argument.  */
2412*ef5ccd6cSJohn Marino 	    fprintf_filtered (stream, current_substring, 0);
24135796c8dcSSimon Schubert 	    break;
24145796c8dcSSimon Schubert 	  default:
24155796c8dcSSimon Schubert 	    internal_error (__FILE__, __LINE__,
24165796c8dcSSimon Schubert 			    _("failed internal consistency check"));
24175796c8dcSSimon Schubert 	  }
2418*ef5ccd6cSJohn Marino 	/* Maybe advance to the next argument.  */
2419*ef5ccd6cSJohn Marino 	if (fpieces[fr].argclass != literal_piece)
2420*ef5ccd6cSJohn Marino 	  ++i;
24215796c8dcSSimon Schubert       }
24225796c8dcSSimon Schubert   }
24235796c8dcSSimon Schubert   do_cleanups (old_cleanups);
24245796c8dcSSimon Schubert }
24255796c8dcSSimon Schubert 
2426cf7f2e2dSJohn Marino /* Implement the "printf" command.  */
2427cf7f2e2dSJohn Marino 
2428cf7f2e2dSJohn Marino static void
printf_command(char * arg,int from_tty)2429cf7f2e2dSJohn Marino printf_command (char *arg, int from_tty)
2430cf7f2e2dSJohn Marino {
2431cf7f2e2dSJohn Marino   ui_printf (arg, gdb_stdout);
2432cf7f2e2dSJohn Marino }
2433cf7f2e2dSJohn Marino 
2434cf7f2e2dSJohn Marino /* Implement the "eval" command.  */
2435cf7f2e2dSJohn Marino 
2436cf7f2e2dSJohn Marino static void
eval_command(char * arg,int from_tty)2437cf7f2e2dSJohn Marino eval_command (char *arg, int from_tty)
2438cf7f2e2dSJohn Marino {
2439cf7f2e2dSJohn Marino   struct ui_file *ui_out = mem_fileopen ();
2440cf7f2e2dSJohn Marino   struct cleanup *cleanups = make_cleanup_ui_file_delete (ui_out);
2441cf7f2e2dSJohn Marino   char *expanded;
2442cf7f2e2dSJohn Marino 
2443cf7f2e2dSJohn Marino   ui_printf (arg, ui_out);
2444cf7f2e2dSJohn Marino 
2445cf7f2e2dSJohn Marino   expanded = ui_file_xstrdup (ui_out, NULL);
2446cf7f2e2dSJohn Marino   make_cleanup (xfree, expanded);
2447cf7f2e2dSJohn Marino 
2448cf7f2e2dSJohn Marino   execute_command (expanded, from_tty);
2449cf7f2e2dSJohn Marino 
2450cf7f2e2dSJohn Marino   do_cleanups (cleanups);
2451cf7f2e2dSJohn Marino }
2452cf7f2e2dSJohn Marino 
24535796c8dcSSimon Schubert void
_initialize_printcmd(void)24545796c8dcSSimon Schubert _initialize_printcmd (void)
24555796c8dcSSimon Schubert {
24565796c8dcSSimon Schubert   struct cmd_list_element *c;
24575796c8dcSSimon Schubert 
24585796c8dcSSimon Schubert   current_display_number = -1;
24595796c8dcSSimon Schubert 
24605796c8dcSSimon Schubert   observer_attach_solib_unloaded (clear_dangling_display_expressions);
24615796c8dcSSimon Schubert 
24625796c8dcSSimon Schubert   add_info ("address", address_info,
24635796c8dcSSimon Schubert 	    _("Describe where symbol SYM is stored."));
24645796c8dcSSimon Schubert 
24655796c8dcSSimon Schubert   add_info ("symbol", sym_info, _("\
24665796c8dcSSimon Schubert Describe what symbol is at location ADDR.\n\
24675796c8dcSSimon Schubert Only for symbols with fixed locations (global or static scope)."));
24685796c8dcSSimon Schubert 
24695796c8dcSSimon Schubert   add_com ("x", class_vars, x_command, _("\
24705796c8dcSSimon Schubert Examine memory: x/FMT ADDRESS.\n\
24715796c8dcSSimon Schubert ADDRESS is an expression for the memory address to examine.\n\
24725796c8dcSSimon Schubert FMT is a repeat count followed by a format letter and a size letter.\n\
24735796c8dcSSimon Schubert Format letters are o(octal), x(hex), d(decimal), u(unsigned decimal),\n\
24745796c8dcSSimon Schubert   t(binary), f(float), a(address), i(instruction), c(char) and s(string).\n\
24755796c8dcSSimon Schubert Size letters are b(byte), h(halfword), w(word), g(giant, 8 bytes).\n\
24765796c8dcSSimon Schubert The specified number of objects of the specified size are printed\n\
24775796c8dcSSimon Schubert according to the format.\n\n\
24785796c8dcSSimon Schubert Defaults for format and size letters are those previously used.\n\
24795796c8dcSSimon Schubert Default count is 1.  Default address is following last thing printed\n\
24805796c8dcSSimon Schubert with this command or \"print\"."));
24815796c8dcSSimon Schubert 
24825796c8dcSSimon Schubert #if 0
24835796c8dcSSimon Schubert   add_com ("whereis", class_vars, whereis_command,
24845796c8dcSSimon Schubert 	   _("Print line number and file of definition of variable."));
24855796c8dcSSimon Schubert #endif
24865796c8dcSSimon Schubert 
24875796c8dcSSimon Schubert   add_info ("display", display_info, _("\
24885796c8dcSSimon Schubert Expressions to display when program stops, with code numbers."));
24895796c8dcSSimon Schubert 
24905796c8dcSSimon Schubert   add_cmd ("undisplay", class_vars, undisplay_command, _("\
24915796c8dcSSimon Schubert Cancel some expressions to be displayed when program stops.\n\
24925796c8dcSSimon Schubert Arguments are the code numbers of the expressions to stop displaying.\n\
24935796c8dcSSimon Schubert No argument means cancel all automatic-display expressions.\n\
24945796c8dcSSimon Schubert \"delete display\" has the same effect as this command.\n\
24955796c8dcSSimon Schubert Do \"info display\" to see current list of code numbers."),
24965796c8dcSSimon Schubert 	   &cmdlist);
24975796c8dcSSimon Schubert 
24985796c8dcSSimon Schubert   add_com ("display", class_vars, display_command, _("\
24995796c8dcSSimon Schubert Print value of expression EXP each time the program stops.\n\
25005796c8dcSSimon Schubert /FMT may be used before EXP as in the \"print\" command.\n\
25015796c8dcSSimon Schubert /FMT \"i\" or \"s\" or including a size-letter is allowed,\n\
25025796c8dcSSimon Schubert as in the \"x\" command, and then EXP is used to get the address to examine\n\
25035796c8dcSSimon Schubert and examining is done as in the \"x\" command.\n\n\
25045796c8dcSSimon Schubert With no argument, display all currently requested auto-display expressions.\n\
25055796c8dcSSimon Schubert Use \"undisplay\" to cancel display requests previously made."));
25065796c8dcSSimon Schubert 
2507c50c785cSJohn Marino   add_cmd ("display", class_vars, enable_display_command, _("\
25085796c8dcSSimon Schubert Enable some expressions to be displayed when program stops.\n\
25095796c8dcSSimon Schubert Arguments are the code numbers of the expressions to resume displaying.\n\
25105796c8dcSSimon Schubert No argument means enable all automatic-display expressions.\n\
25115796c8dcSSimon Schubert Do \"info display\" to see current list of code numbers."), &enablelist);
25125796c8dcSSimon Schubert 
25135796c8dcSSimon Schubert   add_cmd ("display", class_vars, disable_display_command, _("\
25145796c8dcSSimon Schubert Disable some expressions to be displayed when program stops.\n\
25155796c8dcSSimon Schubert Arguments are the code numbers of the expressions to stop displaying.\n\
25165796c8dcSSimon Schubert No argument means disable all automatic-display expressions.\n\
25175796c8dcSSimon Schubert Do \"info display\" to see current list of code numbers."), &disablelist);
25185796c8dcSSimon Schubert 
25195796c8dcSSimon Schubert   add_cmd ("display", class_vars, undisplay_command, _("\
25205796c8dcSSimon Schubert Cancel some expressions to be displayed when program stops.\n\
25215796c8dcSSimon Schubert Arguments are the code numbers of the expressions to stop displaying.\n\
25225796c8dcSSimon Schubert No argument means cancel all automatic-display expressions.\n\
25235796c8dcSSimon Schubert Do \"info display\" to see current list of code numbers."), &deletelist);
25245796c8dcSSimon Schubert 
25255796c8dcSSimon Schubert   add_com ("printf", class_vars, printf_command, _("\
25265796c8dcSSimon Schubert printf \"printf format string\", arg1, arg2, arg3, ..., argn\n\
25275796c8dcSSimon Schubert This is useful for formatted output in user-defined commands."));
25285796c8dcSSimon Schubert 
25295796c8dcSSimon Schubert   add_com ("output", class_vars, output_command, _("\
25305796c8dcSSimon Schubert Like \"print\" but don't put in value history and don't print newline.\n\
25315796c8dcSSimon Schubert This is useful in user-defined commands."));
25325796c8dcSSimon Schubert 
25335796c8dcSSimon Schubert   add_prefix_cmd ("set", class_vars, set_command, _("\
25345796c8dcSSimon Schubert Evaluate expression EXP and assign result to variable VAR, using assignment\n\
25355796c8dcSSimon Schubert syntax appropriate for the current language (VAR = EXP or VAR := EXP for\n\
25365796c8dcSSimon Schubert example).  VAR may be a debugger \"convenience\" variable (names starting\n\
25375796c8dcSSimon Schubert with $), a register (a few standard names starting with $), or an actual\n\
25385796c8dcSSimon Schubert variable in the program being debugged.  EXP is any valid expression.\n\
25395796c8dcSSimon Schubert Use \"set variable\" for variables with names identical to set subcommands.\n\
25405796c8dcSSimon Schubert \n\
25415796c8dcSSimon Schubert With a subcommand, this command modifies parts of the gdb environment.\n\
25425796c8dcSSimon Schubert You can see these environment settings with the \"show\" command."),
25435796c8dcSSimon Schubert 		  &setlist, "set ", 1, &cmdlist);
25445796c8dcSSimon Schubert   if (dbx_commands)
25455796c8dcSSimon Schubert     add_com ("assign", class_vars, set_command, _("\
25465796c8dcSSimon Schubert Evaluate expression EXP and assign result to variable VAR, using assignment\n\
25475796c8dcSSimon Schubert syntax appropriate for the current language (VAR = EXP or VAR := EXP for\n\
25485796c8dcSSimon Schubert example).  VAR may be a debugger \"convenience\" variable (names starting\n\
25495796c8dcSSimon Schubert with $), a register (a few standard names starting with $), or an actual\n\
25505796c8dcSSimon Schubert variable in the program being debugged.  EXP is any valid expression.\n\
25515796c8dcSSimon Schubert Use \"set variable\" for variables with names identical to set subcommands.\n\
25525796c8dcSSimon Schubert \nWith a subcommand, this command modifies parts of the gdb environment.\n\
25535796c8dcSSimon Schubert You can see these environment settings with the \"show\" command."));
25545796c8dcSSimon Schubert 
25555796c8dcSSimon Schubert   /* "call" is the same as "set", but handy for dbx users to call fns.  */
25565796c8dcSSimon Schubert   c = add_com ("call", class_vars, call_command, _("\
25575796c8dcSSimon Schubert Call a function in the program.\n\
25585796c8dcSSimon Schubert The argument is the function name and arguments, in the notation of the\n\
25595796c8dcSSimon Schubert current working language.  The result is printed and saved in the value\n\
25605796c8dcSSimon Schubert history, if it is not void."));
25615796c8dcSSimon Schubert   set_cmd_completer (c, expression_completer);
25625796c8dcSSimon Schubert 
25635796c8dcSSimon Schubert   add_cmd ("variable", class_vars, set_command, _("\
25645796c8dcSSimon Schubert Evaluate expression EXP and assign result to variable VAR, using assignment\n\
25655796c8dcSSimon Schubert syntax appropriate for the current language (VAR = EXP or VAR := EXP for\n\
25665796c8dcSSimon Schubert example).  VAR may be a debugger \"convenience\" variable (names starting\n\
25675796c8dcSSimon Schubert with $), a register (a few standard names starting with $), or an actual\n\
25685796c8dcSSimon Schubert variable in the program being debugged.  EXP is any valid expression.\n\
25695796c8dcSSimon Schubert This may usually be abbreviated to simply \"set\"."),
25705796c8dcSSimon Schubert 	   &setlist);
25715796c8dcSSimon Schubert 
25725796c8dcSSimon Schubert   c = add_com ("print", class_vars, print_command, _("\
25735796c8dcSSimon Schubert Print value of expression EXP.\n\
25745796c8dcSSimon Schubert Variables accessible are those of the lexical environment of the selected\n\
25755796c8dcSSimon Schubert stack frame, plus all those whose scope is global or an entire file.\n\
25765796c8dcSSimon Schubert \n\
25775796c8dcSSimon Schubert $NUM gets previous value number NUM.  $ and $$ are the last two values.\n\
25785796c8dcSSimon Schubert $$NUM refers to NUM'th value back from the last one.\n\
25795796c8dcSSimon Schubert Names starting with $ refer to registers (with the values they would have\n\
25805796c8dcSSimon Schubert if the program were to return to the stack frame now selected, restoring\n\
25815796c8dcSSimon Schubert all registers saved by frames farther in) or else to debugger\n\
25825796c8dcSSimon Schubert \"convenience\" variables (any such name not a known register).\n\
25835796c8dcSSimon Schubert Use assignment expressions to give values to convenience variables.\n\
25845796c8dcSSimon Schubert \n\
25855796c8dcSSimon Schubert {TYPE}ADREXP refers to a datum of data type TYPE, located at address ADREXP.\n\
25865796c8dcSSimon Schubert @ is a binary operator for treating consecutive data objects\n\
25875796c8dcSSimon Schubert anywhere in memory as an array.  FOO@NUM gives an array whose first\n\
25885796c8dcSSimon Schubert element is FOO, whose second element is stored in the space following\n\
25895796c8dcSSimon Schubert where FOO is stored, etc.  FOO must be an expression whose value\n\
25905796c8dcSSimon Schubert resides in memory.\n\
25915796c8dcSSimon Schubert \n\
25925796c8dcSSimon Schubert EXP may be preceded with /FMT, where FMT is a format letter\n\
25935796c8dcSSimon Schubert but no count or size letter (see \"x\" command)."));
25945796c8dcSSimon Schubert   set_cmd_completer (c, expression_completer);
25955796c8dcSSimon Schubert   add_com_alias ("p", "print", class_vars, 1);
2596*ef5ccd6cSJohn Marino   add_com_alias ("inspect", "print", class_vars, 1);
25975796c8dcSSimon Schubert 
25985796c8dcSSimon Schubert   add_setshow_uinteger_cmd ("max-symbolic-offset", no_class,
25995796c8dcSSimon Schubert 			    &max_symbolic_offset, _("\
26005796c8dcSSimon Schubert Set the largest offset that will be printed in <symbol+1234> form."), _("\
26015796c8dcSSimon Schubert Show the largest offset that will be printed in <symbol+1234> form."), NULL,
26025796c8dcSSimon Schubert 			    NULL,
26035796c8dcSSimon Schubert 			    show_max_symbolic_offset,
26045796c8dcSSimon Schubert 			    &setprintlist, &showprintlist);
26055796c8dcSSimon Schubert   add_setshow_boolean_cmd ("symbol-filename", no_class,
26065796c8dcSSimon Schubert 			   &print_symbol_filename, _("\
26075796c8dcSSimon Schubert Set printing of source filename and line number with <symbol>."), _("\
26085796c8dcSSimon Schubert Show printing of source filename and line number with <symbol>."), NULL,
26095796c8dcSSimon Schubert 			   NULL,
26105796c8dcSSimon Schubert 			   show_print_symbol_filename,
26115796c8dcSSimon Schubert 			   &setprintlist, &showprintlist);
2612cf7f2e2dSJohn Marino 
2613cf7f2e2dSJohn Marino   add_com ("eval", no_class, eval_command, _("\
2614cf7f2e2dSJohn Marino Convert \"printf format string\", arg1, arg2, arg3, ..., argn to\n\
2615cf7f2e2dSJohn Marino a command line, and call it."));
26165796c8dcSSimon Schubert }
2617