* valprint.c (print_hex_chars, print_octal_chars, print_decimal_chars,
[external/binutils.git] / gdb / printcmd.c
1 /* Print values for GNU debugger GDB.
2
3    Copyright (C) 1986, 1987, 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995,
4    1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007,
5    2008 Free Software Foundation, Inc.
6
7    This file is part of GDB.
8
9    This program is free software; you can redistribute it and/or modify
10    it under the terms of the GNU General Public License as published by
11    the Free Software Foundation; either version 3 of the License, or
12    (at your option) any later version.
13
14    This program is distributed in the hope that it will be useful,
15    but WITHOUT ANY WARRANTY; without even the implied warranty of
16    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17    GNU General Public License for more details.
18
19    You should have received a copy of the GNU General Public License
20    along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
21
22 #include "defs.h"
23 #include "gdb_string.h"
24 #include "frame.h"
25 #include "symtab.h"
26 #include "gdbtypes.h"
27 #include "value.h"
28 #include "language.h"
29 #include "expression.h"
30 #include "gdbcore.h"
31 #include "gdbcmd.h"
32 #include "target.h"
33 #include "breakpoint.h"
34 #include "demangle.h"
35 #include "valprint.h"
36 #include "annotate.h"
37 #include "symfile.h"            /* for overlay functions */
38 #include "objfiles.h"           /* ditto */
39 #include "completer.h"          /* for completion functions */
40 #include "ui-out.h"
41 #include "gdb_assert.h"
42 #include "block.h"
43 #include "disasm.h"
44 #include "dfp.h"
45
46 #ifdef TUI
47 #include "tui/tui.h"            /* For tui_active et.al.   */
48 #endif
49
50 #if defined(__MINGW32__)
51 # define USE_PRINTF_I64 1
52 # define PRINTF_HAS_LONG_LONG
53 #else
54 # define USE_PRINTF_I64 0
55 #endif
56
57 extern int asm_demangle;        /* Whether to demangle syms in asm printouts */
58 extern int addressprint;        /* Whether to print hex addresses in HLL " */
59
60 struct format_data
61   {
62     int count;
63     char format;
64     char size;
65   };
66
67 /* Last specified output format.  */
68
69 static char last_format = 'x';
70
71 /* Last specified examination size.  'b', 'h', 'w' or `q'.  */
72
73 static char last_size = 'w';
74
75 /* Default address to examine next.  */
76
77 static CORE_ADDR next_address;
78
79 /* Number of delay instructions following current disassembled insn.  */
80
81 static int branch_delay_insns;
82
83 /* Last address examined.  */
84
85 static CORE_ADDR last_examine_address;
86
87 /* Contents of last address examined.
88    This is not valid past the end of the `x' command!  */
89
90 static struct value *last_examine_value;
91
92 /* Largest offset between a symbolic value and an address, that will be
93    printed as `0x1234 <symbol+offset>'.  */
94
95 static unsigned int max_symbolic_offset = UINT_MAX;
96 static void
97 show_max_symbolic_offset (struct ui_file *file, int from_tty,
98                           struct cmd_list_element *c, const char *value)
99 {
100   fprintf_filtered (file, _("\
101 The largest offset that will be printed in <symbol+1234> form is %s.\n"),
102                     value);
103 }
104
105 /* Append the source filename and linenumber of the symbol when
106    printing a symbolic value as `<symbol at filename:linenum>' if set.  */
107 static int print_symbol_filename = 0;
108 static void
109 show_print_symbol_filename (struct ui_file *file, int from_tty,
110                             struct cmd_list_element *c, const char *value)
111 {
112   fprintf_filtered (file, _("\
113 Printing of source filename and line number with <symbol> is %s.\n"),
114                     value);
115 }
116
117 /* Number of auto-display expression currently being displayed.
118    So that we can disable it if we get an error or a signal within it.
119    -1 when not doing one.  */
120
121 int current_display_number;
122
123 /* Flag to low-level print routines that this value is being printed
124    in an epoch window.  We'd like to pass this as a parameter, but
125    every routine would need to take it.  Perhaps we can encapsulate
126    this in the I/O stream once we have GNU stdio. */
127
128 int inspect_it = 0;
129
130 struct display
131   {
132     /* Chain link to next auto-display item.  */
133     struct display *next;
134     /* Expression to be evaluated and displayed.  */
135     struct expression *exp;
136     /* Item number of this auto-display item.  */
137     int number;
138     /* Display format specified.  */
139     struct format_data format;
140     /* Innermost block required by this expression when evaluated */
141     struct block *block;
142     /* Status of this display (enabled or disabled) */
143     int enabled_p;
144   };
145
146 /* Chain of expressions whose values should be displayed
147    automatically each time the program stops.  */
148
149 static struct display *display_chain;
150
151 static int display_number;
152
153 /* Prototypes for exported functions. */
154
155 void output_command (char *, int);
156
157 void _initialize_printcmd (void);
158
159 /* Prototypes for local functions. */
160
161 static void do_one_display (struct display *);
162 \f
163
164 /* Decode a format specification.  *STRING_PTR should point to it.
165    OFORMAT and OSIZE are used as defaults for the format and size
166    if none are given in the format specification.
167    If OSIZE is zero, then the size field of the returned value
168    should be set only if a size is explicitly specified by the
169    user.
170    The structure returned describes all the data
171    found in the specification.  In addition, *STRING_PTR is advanced
172    past the specification and past all whitespace following it.  */
173
174 static struct format_data
175 decode_format (char **string_ptr, int oformat, int osize)
176 {
177   struct format_data val;
178   char *p = *string_ptr;
179
180   val.format = '?';
181   val.size = '?';
182   val.count = 1;
183
184   if (*p >= '0' && *p <= '9')
185     val.count = atoi (p);
186   while (*p >= '0' && *p <= '9')
187     p++;
188
189   /* Now process size or format letters that follow.  */
190
191   while (1)
192     {
193       if (*p == 'b' || *p == 'h' || *p == 'w' || *p == 'g')
194         val.size = *p++;
195       else if (*p >= 'a' && *p <= 'z')
196         val.format = *p++;
197       else
198         break;
199     }
200
201   while (*p == ' ' || *p == '\t')
202     p++;
203   *string_ptr = p;
204
205   /* Set defaults for format and size if not specified.  */
206   if (val.format == '?')
207     {
208       if (val.size == '?')
209         {
210           /* Neither has been specified.  */
211           val.format = oformat;
212           val.size = osize;
213         }
214       else
215         /* If a size is specified, any format makes a reasonable
216            default except 'i'.  */
217         val.format = oformat == 'i' ? 'x' : oformat;
218     }
219   else if (val.size == '?')
220     switch (val.format)
221       {
222       case 'a':
223       case 's':
224         /* Pick the appropriate size for an address.  */
225         if (gdbarch_ptr_bit (current_gdbarch) == 64)
226           val.size = osize ? 'g' : osize;
227         else if (gdbarch_ptr_bit (current_gdbarch) == 32)
228           val.size = osize ? 'w' : osize;
229         else if (gdbarch_ptr_bit (current_gdbarch) == 16)
230           val.size = osize ? 'h' : osize;
231         else
232           /* Bad value for gdbarch_ptr_bit.  */
233           internal_error (__FILE__, __LINE__,
234                           _("failed internal consistency check"));
235         break;
236       case 'f':
237         /* Floating point has to be word or giantword.  */
238         if (osize == 'w' || osize == 'g')
239           val.size = osize;
240         else
241           /* Default it to giantword if the last used size is not
242              appropriate.  */
243           val.size = osize ? 'g' : osize;
244         break;
245       case 'c':
246         /* Characters default to one byte.  */
247         val.size = osize ? 'b' : osize;
248         break;
249       default:
250         /* The default is the size most recently specified.  */
251         val.size = osize;
252       }
253
254   return val;
255 }
256 \f
257 /* Print value VAL on stream according to FORMAT, a letter or 0.
258    Do not end with a newline.
259    0 means print VAL according to its own type.
260    SIZE is the letter for the size of datum being printed.
261    This is used to pad hex numbers so they line up.  SIZE is 0
262    for print / output and set for examine.  */
263
264 static void
265 print_formatted (struct value *val, int format, int size,
266                  struct ui_file *stream)
267 {
268   struct type *type = check_typedef (value_type (val));
269   int len = TYPE_LENGTH (type);
270
271   if (VALUE_LVAL (val) == lval_memory)
272     next_address = VALUE_ADDRESS (val) + len;
273
274   if (size)
275     {
276       switch (format)
277         {
278         case 's':
279           /* FIXME: Need to handle wchar_t's here... */
280           next_address = VALUE_ADDRESS (val)
281             + val_print_string (VALUE_ADDRESS (val), -1, 1, stream);
282           return;
283
284         case 'i':
285           /* We often wrap here if there are long symbolic names.  */
286           wrap_here ("    ");
287           next_address = (VALUE_ADDRESS (val)
288                           + gdb_print_insn (VALUE_ADDRESS (val), stream,
289                                             &branch_delay_insns));
290           return;
291         }
292     }
293
294   if (format == 0 || format == 's'
295       || TYPE_CODE (type) == TYPE_CODE_REF
296       || TYPE_CODE (type) == TYPE_CODE_ARRAY
297       || TYPE_CODE (type) == TYPE_CODE_STRING
298       || TYPE_CODE (type) == TYPE_CODE_STRUCT
299       || TYPE_CODE (type) == TYPE_CODE_UNION
300       || TYPE_CODE (type) == TYPE_CODE_NAMESPACE)
301     /* If format is 0, use the 'natural' format for that type of
302        value.  If the type is non-scalar, we have to use language
303        rules to print it as a series of scalars.  */
304     value_print (val, stream, format, Val_pretty_default);
305   else
306     /* User specified format, so don't look to the the type to
307        tell us what to do.  */
308     print_scalar_formatted (value_contents (val), type,
309                             format, size, stream);
310 }
311
312 /* Print a scalar of data of type TYPE, pointed to in GDB by VALADDR,
313    according to letters FORMAT and SIZE on STREAM.
314    FORMAT may not be zero.  Formats s and i are not supported at this level.
315
316    This is how the elements of an array or structure are printed
317    with a format.  */
318
319 void
320 print_scalar_formatted (const void *valaddr, struct type *type,
321                         int format, int size, struct ui_file *stream)
322 {
323   LONGEST val_long = 0;
324   unsigned int len = TYPE_LENGTH (type);
325   enum bfd_endian byte_order = gdbarch_byte_order (current_gdbarch);
326
327   /* If we get here with a string format, try again without it.  Go
328      all the way back to the language printers, which may call us
329      again.  */
330   if (format == 's')
331     {
332       val_print (type, valaddr, 0, 0, stream, 0, 0, 0, Val_pretty_default,
333                  current_language);
334       return;
335     }
336
337   if (len > sizeof(LONGEST) &&
338       (TYPE_CODE (type) == TYPE_CODE_INT
339        || TYPE_CODE (type) == TYPE_CODE_ENUM))
340     {
341       switch (format)
342         {
343         case 'o':
344           print_octal_chars (stream, valaddr, len, byte_order);
345           return;
346         case 'u':
347         case 'd':
348           print_decimal_chars (stream, valaddr, len, byte_order);
349           return;
350         case 't':
351           print_binary_chars (stream, valaddr, len, byte_order);
352           return;
353         case 'x':
354           print_hex_chars (stream, valaddr, len, byte_order);
355           return;
356         case 'c':
357           print_char_chars (stream, valaddr, len, byte_order);
358           return;
359         default:
360           break;
361         };
362     }
363
364   if (format != 'f')
365     val_long = unpack_long (type, valaddr);
366
367   /* If the value is a pointer, and pointers and addresses are not the
368      same, then at this point, the value's length (in target bytes) is
369      gdbarch_addr_bit/TARGET_CHAR_BIT, not TYPE_LENGTH (type).  */
370   if (TYPE_CODE (type) == TYPE_CODE_PTR)
371     len = gdbarch_addr_bit (current_gdbarch) / TARGET_CHAR_BIT;
372
373   /* If we are printing it as unsigned, truncate it in case it is actually
374      a negative signed value (e.g. "print/u (short)-1" should print 65535
375      (if shorts are 16 bits) instead of 4294967295).  */
376   if (format != 'd')
377     {
378       if (len < sizeof (LONGEST))
379         val_long &= ((LONGEST) 1 << HOST_CHAR_BIT * len) - 1;
380     }
381
382   switch (format)
383     {
384     case 'x':
385       if (!size)
386         {
387           /* No size specified, like in print.  Print varying # of digits.  */
388           print_longest (stream, 'x', 1, val_long);
389         }
390       else
391         switch (size)
392           {
393           case 'b':
394           case 'h':
395           case 'w':
396           case 'g':
397             print_longest (stream, size, 1, val_long);
398             break;
399           default:
400             error (_("Undefined output size \"%c\"."), size);
401           }
402       break;
403
404     case 'd':
405       print_longest (stream, 'd', 1, val_long);
406       break;
407
408     case 'u':
409       print_longest (stream, 'u', 0, val_long);
410       break;
411
412     case 'o':
413       if (val_long)
414         print_longest (stream, 'o', 1, val_long);
415       else
416         fprintf_filtered (stream, "0");
417       break;
418
419     case 'a':
420       {
421         CORE_ADDR addr = unpack_pointer (type, valaddr);
422         print_address (addr, stream);
423       }
424       break;
425
426     case 'c':
427       if (TYPE_UNSIGNED (type))
428         {
429           struct type *utype;
430
431           utype = builtin_type (current_gdbarch)->builtin_true_unsigned_char;
432           value_print (value_from_longest (utype, val_long),
433                        stream, 0, Val_pretty_default);
434         }
435       else
436         value_print (value_from_longest (builtin_type_true_char, val_long),
437                      stream, 0, Val_pretty_default);
438       break;
439
440     case 'f':
441       if (len == TYPE_LENGTH (builtin_type_float))
442         type = builtin_type_float;
443       else if (len == TYPE_LENGTH (builtin_type_double))
444         type = builtin_type_double;
445       else if (len == TYPE_LENGTH (builtin_type_long_double))
446         type = builtin_type_long_double;
447       print_floating (valaddr, type, stream);
448       break;
449
450     case 0:
451       internal_error (__FILE__, __LINE__,
452                       _("failed internal consistency check"));
453
454     case 't':
455       /* Binary; 't' stands for "two".  */
456       {
457         char bits[8 * (sizeof val_long) + 1];
458         char buf[8 * (sizeof val_long) + 32];
459         char *cp = bits;
460         int width;
461
462         if (!size)
463           width = 8 * (sizeof val_long);
464         else
465           switch (size)
466             {
467             case 'b':
468               width = 8;
469               break;
470             case 'h':
471               width = 16;
472               break;
473             case 'w':
474               width = 32;
475               break;
476             case 'g':
477               width = 64;
478               break;
479             default:
480               error (_("Undefined output size \"%c\"."), size);
481             }
482
483         bits[width] = '\0';
484         while (width-- > 0)
485           {
486             bits[width] = (val_long & 1) ? '1' : '0';
487             val_long >>= 1;
488           }
489         if (!size)
490           {
491             while (*cp && *cp == '0')
492               cp++;
493             if (*cp == '\0')
494               cp--;
495           }
496         strcpy (buf, cp);
497         fputs_filtered (buf, stream);
498       }
499       break;
500
501     default:
502       error (_("Undefined output format \"%c\"."), format);
503     }
504 }
505
506 /* Specify default address for `x' command.
507    The `info lines' command uses this.  */
508
509 void
510 set_next_address (CORE_ADDR addr)
511 {
512   next_address = addr;
513
514   /* Make address available to the user as $_.  */
515   set_internalvar (lookup_internalvar ("_"),
516                    value_from_pointer (lookup_pointer_type (builtin_type_void),
517                                        addr));
518 }
519
520 /* Optionally print address ADDR symbolically as <SYMBOL+OFFSET> on STREAM,
521    after LEADIN.  Print nothing if no symbolic name is found nearby.
522    Optionally also print source file and line number, if available.
523    DO_DEMANGLE controls whether to print a symbol in its native "raw" form,
524    or to interpret it as a possible C++ name and convert it back to source
525    form.  However note that DO_DEMANGLE can be overridden by the specific
526    settings of the demangle and asm_demangle variables.  */
527
528 void
529 print_address_symbolic (CORE_ADDR addr, struct ui_file *stream,
530                         int do_demangle, char *leadin)
531 {
532   char *name = NULL;
533   char *filename = NULL;
534   int unmapped = 0;
535   int offset = 0;
536   int line = 0;
537
538   /* Throw away both name and filename.  */
539   struct cleanup *cleanup_chain = make_cleanup (free_current_contents, &name);
540   make_cleanup (free_current_contents, &filename);
541
542   if (build_address_symbolic (addr, do_demangle, &name, &offset,
543                               &filename, &line, &unmapped))
544     {
545       do_cleanups (cleanup_chain);
546       return;
547     }
548
549   fputs_filtered (leadin, stream);
550   if (unmapped)
551     fputs_filtered ("<*", stream);
552   else
553     fputs_filtered ("<", stream);
554   fputs_filtered (name, stream);
555   if (offset != 0)
556     fprintf_filtered (stream, "+%u", (unsigned int) offset);
557
558   /* Append source filename and line number if desired.  Give specific
559      line # of this addr, if we have it; else line # of the nearest symbol.  */
560   if (print_symbol_filename && filename != NULL)
561     {
562       if (line != -1)
563         fprintf_filtered (stream, " at %s:%d", filename, line);
564       else
565         fprintf_filtered (stream, " in %s", filename);
566     }
567   if (unmapped)
568     fputs_filtered ("*>", stream);
569   else
570     fputs_filtered (">", stream);
571
572   do_cleanups (cleanup_chain);
573 }
574
575 /* Given an address ADDR return all the elements needed to print the
576    address in a symbolic form. NAME can be mangled or not depending
577    on DO_DEMANGLE (and also on the asm_demangle global variable,
578    manipulated via ''set print asm-demangle''). Return 0 in case of
579    success, when all the info in the OUT paramters is valid. Return 1
580    otherwise. */
581 int
582 build_address_symbolic (CORE_ADDR addr,  /* IN */
583                         int do_demangle, /* IN */
584                         char **name,     /* OUT */
585                         int *offset,     /* OUT */
586                         char **filename, /* OUT */
587                         int *line,       /* OUT */
588                         int *unmapped)   /* OUT */
589 {
590   struct minimal_symbol *msymbol;
591   struct symbol *symbol;
592   CORE_ADDR name_location = 0;
593   asection *section = 0;
594   char *name_temp = "";
595   
596   /* Let's say it is unmapped.  */
597   *unmapped = 0;
598
599   /* Determine if the address is in an overlay, and whether it is
600      mapped.  */
601   if (overlay_debugging)
602     {
603       section = find_pc_overlay (addr);
604       if (pc_in_unmapped_range (addr, section))
605         {
606           *unmapped = 1;
607           addr = overlay_mapped_address (addr, section);
608         }
609     }
610
611   /* First try to find the address in the symbol table, then
612      in the minsyms.  Take the closest one.  */
613
614   /* This is defective in the sense that it only finds text symbols.  So
615      really this is kind of pointless--we should make sure that the
616      minimal symbols have everything we need (by changing that we could
617      save some memory, but for many debug format--ELF/DWARF or
618      anything/stabs--it would be inconvenient to eliminate those minimal
619      symbols anyway).  */
620   msymbol = lookup_minimal_symbol_by_pc_section (addr, section);
621   symbol = find_pc_sect_function (addr, section);
622
623   if (symbol)
624     {
625       name_location = BLOCK_START (SYMBOL_BLOCK_VALUE (symbol));
626       if (do_demangle || asm_demangle)
627         name_temp = SYMBOL_PRINT_NAME (symbol);
628       else
629         name_temp = DEPRECATED_SYMBOL_NAME (symbol);
630     }
631
632   if (msymbol != NULL)
633     {
634       if (SYMBOL_VALUE_ADDRESS (msymbol) > name_location || symbol == NULL)
635         {
636           /* The msymbol is closer to the address than the symbol;
637              use the msymbol instead.  */
638           symbol = 0;
639           name_location = SYMBOL_VALUE_ADDRESS (msymbol);
640           if (do_demangle || asm_demangle)
641             name_temp = SYMBOL_PRINT_NAME (msymbol);
642           else
643             name_temp = DEPRECATED_SYMBOL_NAME (msymbol);
644         }
645     }
646   if (symbol == NULL && msymbol == NULL)
647     return 1;
648
649   /* If the nearest symbol is too far away, don't print anything symbolic.  */
650
651   /* For when CORE_ADDR is larger than unsigned int, we do math in
652      CORE_ADDR.  But when we detect unsigned wraparound in the
653      CORE_ADDR math, we ignore this test and print the offset,
654      because addr+max_symbolic_offset has wrapped through the end
655      of the address space back to the beginning, giving bogus comparison.  */
656   if (addr > name_location + max_symbolic_offset
657       && name_location + max_symbolic_offset > name_location)
658     return 1;
659
660   *offset = addr - name_location;
661
662   *name = xstrdup (name_temp);
663
664   if (print_symbol_filename)
665     {
666       struct symtab_and_line sal;
667
668       sal = find_pc_sect_line (addr, section, 0);
669
670       if (sal.symtab)
671         {
672           *filename = xstrdup (sal.symtab->filename);
673           *line = sal.line;
674         }
675     }
676   return 0;
677 }
678
679 /* Print address ADDR on STREAM.  USE_LOCAL means the same thing as for
680    print_longest.  */
681 void
682 deprecated_print_address_numeric (CORE_ADDR addr, int use_local,
683                                   struct ui_file *stream)
684 {
685   if (use_local)
686     fputs_filtered (paddress (addr), stream);
687   else
688     {
689       int addr_bit = gdbarch_addr_bit (current_gdbarch);
690
691       if (addr_bit < (sizeof (CORE_ADDR) * HOST_CHAR_BIT))
692         addr &= ((CORE_ADDR) 1 << addr_bit) - 1;
693       print_longest (stream, 'x', 0, (ULONGEST) addr);
694     }
695 }
696
697 /* Print address ADDR symbolically on STREAM.
698    First print it as a number.  Then perhaps print
699    <SYMBOL + OFFSET> after the number.  */
700
701 void
702 print_address (CORE_ADDR addr, struct ui_file *stream)
703 {
704   fputs_filtered (paddress (addr), stream);
705   print_address_symbolic (addr, stream, asm_demangle, " ");
706 }
707
708 /* Print address ADDR symbolically on STREAM.  Parameter DEMANGLE
709    controls whether to print the symbolic name "raw" or demangled.
710    Global setting "addressprint" controls whether to print hex address
711    or not.  */
712
713 void
714 print_address_demangle (CORE_ADDR addr, struct ui_file *stream,
715                         int do_demangle)
716 {
717   if (addr == 0)
718     {
719       fprintf_filtered (stream, "0");
720     }
721   else if (addressprint)
722     {
723       fputs_filtered (paddress (addr), stream);
724       print_address_symbolic (addr, stream, do_demangle, " ");
725     }
726   else
727     {
728       print_address_symbolic (addr, stream, do_demangle, "");
729     }
730 }
731 \f
732
733 /* These are the types that $__ will get after an examine command of one
734    of these sizes.  */
735
736 static struct type *examine_i_type;
737
738 static struct type *examine_b_type;
739 static struct type *examine_h_type;
740 static struct type *examine_w_type;
741 static struct type *examine_g_type;
742
743 /* Examine data at address ADDR in format FMT.
744    Fetch it from memory and print on gdb_stdout.  */
745
746 static void
747 do_examine (struct format_data fmt, CORE_ADDR addr)
748 {
749   char format = 0;
750   char size;
751   int count = 1;
752   struct type *val_type = NULL;
753   int i;
754   int maxelts;
755
756   format = fmt.format;
757   size = fmt.size;
758   count = fmt.count;
759   next_address = addr;
760
761   /* String or instruction format implies fetch single bytes
762      regardless of the specified size.  */
763   if (format == 's' || format == 'i')
764     size = 'b';
765
766   if (format == 'i')
767     val_type = examine_i_type;
768   else if (size == 'b')
769     val_type = examine_b_type;
770   else if (size == 'h')
771     val_type = examine_h_type;
772   else if (size == 'w')
773     val_type = examine_w_type;
774   else if (size == 'g')
775     val_type = examine_g_type;
776
777   maxelts = 8;
778   if (size == 'w')
779     maxelts = 4;
780   if (size == 'g')
781     maxelts = 2;
782   if (format == 's' || format == 'i')
783     maxelts = 1;
784
785   /* Print as many objects as specified in COUNT, at most maxelts per line,
786      with the address of the next one at the start of each line.  */
787
788   while (count > 0)
789     {
790       QUIT;
791       print_address (next_address, gdb_stdout);
792       printf_filtered (":");
793       for (i = maxelts;
794            i > 0 && count > 0;
795            i--, count--)
796         {
797           printf_filtered ("\t");
798           /* Note that print_formatted sets next_address for the next
799              object.  */
800           last_examine_address = next_address;
801
802           if (last_examine_value)
803             value_free (last_examine_value);
804
805           /* The value to be displayed is not fetched greedily.
806              Instead, to avoid the possibility of a fetched value not
807              being used, its retrieval is delayed until the print code
808              uses it.  When examining an instruction stream, the
809              disassembler will perform its own memory fetch using just
810              the address stored in LAST_EXAMINE_VALUE.  FIXME: Should
811              the disassembler be modified so that LAST_EXAMINE_VALUE
812              is left with the byte sequence from the last complete
813              instruction fetched from memory? */
814           last_examine_value = value_at_lazy (val_type, next_address);
815
816           if (last_examine_value)
817             release_value (last_examine_value);
818
819           print_formatted (last_examine_value, format, size, gdb_stdout);
820
821           /* Display any branch delay slots following the final insn.  */
822           if (format == 'i' && count == 1)
823             count += branch_delay_insns;
824         }
825       printf_filtered ("\n");
826       gdb_flush (gdb_stdout);
827     }
828 }
829 \f
830 static void
831 validate_format (struct format_data fmt, char *cmdname)
832 {
833   if (fmt.size != 0)
834     error (_("Size letters are meaningless in \"%s\" command."), cmdname);
835   if (fmt.count != 1)
836     error (_("Item count other than 1 is meaningless in \"%s\" command."),
837            cmdname);
838   if (fmt.format == 'i')
839     error (_("Format letter \"%c\" is meaningless in \"%s\" command."),
840            fmt.format, cmdname);
841 }
842
843 /* Evaluate string EXP as an expression in the current language and
844    print the resulting value.  EXP may contain a format specifier as the
845    first argument ("/x myvar" for example, to print myvar in hex).  */
846
847 static void
848 print_command_1 (char *exp, int inspect, int voidprint)
849 {
850   struct expression *expr;
851   struct cleanup *old_chain = 0;
852   char format = 0;
853   struct value *val;
854   struct format_data fmt;
855   int cleanup = 0;
856
857   /* Pass inspect flag to the rest of the print routines in a global
858      (sigh).  */
859   inspect_it = inspect;
860
861   if (exp && *exp == '/')
862     {
863       exp++;
864       fmt = decode_format (&exp, last_format, 0);
865       validate_format (fmt, "print");
866       last_format = format = fmt.format;
867     }
868   else
869     {
870       fmt.count = 1;
871       fmt.format = 0;
872       fmt.size = 0;
873     }
874
875   if (exp && *exp)
876     {
877       struct type *type;
878       expr = parse_expression (exp);
879       old_chain = make_cleanup (free_current_contents, &expr);
880       cleanup = 1;
881       val = evaluate_expression (expr);
882     }
883   else
884     val = access_value_history (0);
885
886   if (voidprint || (val && value_type (val) &&
887                     TYPE_CODE (value_type (val)) != TYPE_CODE_VOID))
888     {
889       int histindex = record_latest_value (val);
890
891       if (histindex >= 0)
892         annotate_value_history_begin (histindex, value_type (val));
893       else
894         annotate_value_begin (value_type (val));
895
896       if (inspect)
897         printf_unfiltered ("\031(gdb-makebuffer \"%s\"  %d '(\"",
898                            exp, histindex);
899       else if (histindex >= 0)
900         printf_filtered ("$%d = ", histindex);
901
902       if (histindex >= 0)
903         annotate_value_history_value ();
904
905       print_formatted (val, format, fmt.size, gdb_stdout);
906       printf_filtered ("\n");
907
908       if (histindex >= 0)
909         annotate_value_history_end ();
910       else
911         annotate_value_end ();
912
913       if (inspect)
914         printf_unfiltered ("\") )\030");
915     }
916
917   if (cleanup)
918     do_cleanups (old_chain);
919   inspect_it = 0;               /* Reset print routines to normal.  */
920 }
921
922 static void
923 print_command (char *exp, int from_tty)
924 {
925   print_command_1 (exp, 0, 1);
926 }
927
928 /* Same as print, except in epoch, it gets its own window.  */
929 static void
930 inspect_command (char *exp, int from_tty)
931 {
932   extern int epoch_interface;
933
934   print_command_1 (exp, epoch_interface, 1);
935 }
936
937 /* Same as print, except it doesn't print void results.  */
938 static void
939 call_command (char *exp, int from_tty)
940 {
941   print_command_1 (exp, 0, 0);
942 }
943
944 void
945 output_command (char *exp, int from_tty)
946 {
947   struct expression *expr;
948   struct cleanup *old_chain;
949   char format = 0;
950   struct value *val;
951   struct format_data fmt;
952
953   fmt.size = 0;
954
955   if (exp && *exp == '/')
956     {
957       exp++;
958       fmt = decode_format (&exp, 0, 0);
959       validate_format (fmt, "output");
960       format = fmt.format;
961     }
962
963   expr = parse_expression (exp);
964   old_chain = make_cleanup (free_current_contents, &expr);
965
966   val = evaluate_expression (expr);
967
968   annotate_value_begin (value_type (val));
969
970   print_formatted (val, format, fmt.size, gdb_stdout);
971
972   annotate_value_end ();
973
974   wrap_here ("");
975   gdb_flush (gdb_stdout);
976
977   do_cleanups (old_chain);
978 }
979
980 static void
981 set_command (char *exp, int from_tty)
982 {
983   struct expression *expr = parse_expression (exp);
984   struct cleanup *old_chain =
985     make_cleanup (free_current_contents, &expr);
986   evaluate_expression (expr);
987   do_cleanups (old_chain);
988 }
989
990 static void
991 sym_info (char *arg, int from_tty)
992 {
993   struct minimal_symbol *msymbol;
994   struct objfile *objfile;
995   struct obj_section *osect;
996   asection *sect;
997   CORE_ADDR addr, sect_addr;
998   int matches = 0;
999   unsigned int offset;
1000
1001   if (!arg)
1002     error_no_arg (_("address"));
1003
1004   addr = parse_and_eval_address (arg);
1005   ALL_OBJSECTIONS (objfile, osect)
1006   {
1007     /* Only process each object file once, even if there's a separate
1008        debug file.  */
1009     if (objfile->separate_debug_objfile_backlink)
1010       continue;
1011
1012     sect = osect->the_bfd_section;
1013     sect_addr = overlay_mapped_address (addr, sect);
1014
1015     if (osect->addr <= sect_addr && sect_addr < osect->endaddr &&
1016         (msymbol = lookup_minimal_symbol_by_pc_section (sect_addr, sect)))
1017       {
1018         matches = 1;
1019         offset = sect_addr - SYMBOL_VALUE_ADDRESS (msymbol);
1020         if (offset)
1021           printf_filtered ("%s + %u in ",
1022                            SYMBOL_PRINT_NAME (msymbol), offset);
1023         else
1024           printf_filtered ("%s in ",
1025                            SYMBOL_PRINT_NAME (msymbol));
1026         if (pc_in_unmapped_range (addr, sect))
1027           printf_filtered (_("load address range of "));
1028         if (section_is_overlay (sect))
1029           printf_filtered (_("%s overlay "),
1030                            section_is_mapped (sect) ? "mapped" : "unmapped");
1031         printf_filtered (_("section %s"), sect->name);
1032         printf_filtered ("\n");
1033       }
1034   }
1035   if (matches == 0)
1036     printf_filtered (_("No symbol matches %s.\n"), arg);
1037 }
1038
1039 static void
1040 address_info (char *exp, int from_tty)
1041 {
1042   struct symbol *sym;
1043   struct minimal_symbol *msymbol;
1044   long val;
1045   asection *section;
1046   CORE_ADDR load_addr;
1047   int is_a_field_of_this;       /* C++: lookup_symbol sets this to nonzero
1048                                    if exp is a field of `this'. */
1049
1050   if (exp == 0)
1051     error (_("Argument required."));
1052
1053   sym = lookup_symbol (exp, get_selected_block (0), VAR_DOMAIN,
1054                        &is_a_field_of_this);
1055   if (sym == NULL)
1056     {
1057       if (is_a_field_of_this)
1058         {
1059           printf_filtered ("Symbol \"");
1060           fprintf_symbol_filtered (gdb_stdout, exp,
1061                                    current_language->la_language, DMGL_ANSI);
1062           printf_filtered ("\" is a field of the local class variable ");
1063           if (current_language->la_language == language_objc)
1064             printf_filtered ("`self'\n");       /* ObjC equivalent of "this" */
1065           else
1066             printf_filtered ("`this'\n");
1067           return;
1068         }
1069
1070       msymbol = lookup_minimal_symbol (exp, NULL, NULL);
1071
1072       if (msymbol != NULL)
1073         {
1074           load_addr = SYMBOL_VALUE_ADDRESS (msymbol);
1075
1076           printf_filtered ("Symbol \"");
1077           fprintf_symbol_filtered (gdb_stdout, exp,
1078                                    current_language->la_language, DMGL_ANSI);
1079           printf_filtered ("\" is at ");
1080           fputs_filtered (paddress (load_addr), gdb_stdout);
1081           printf_filtered (" in a file compiled without debugging");
1082           section = SYMBOL_BFD_SECTION (msymbol);
1083           if (section_is_overlay (section))
1084             {
1085               load_addr = overlay_unmapped_address (load_addr, section);
1086               printf_filtered (",\n -- loaded at ");
1087               fputs_filtered (paddress (load_addr), gdb_stdout);
1088               printf_filtered (" in overlay section %s", section->name);
1089             }
1090           printf_filtered (".\n");
1091         }
1092       else
1093         error (_("No symbol \"%s\" in current context."), exp);
1094       return;
1095     }
1096
1097   printf_filtered ("Symbol \"");
1098   fprintf_symbol_filtered (gdb_stdout, DEPRECATED_SYMBOL_NAME (sym),
1099                            current_language->la_language, DMGL_ANSI);
1100   printf_filtered ("\" is ");
1101   val = SYMBOL_VALUE (sym);
1102   section = SYMBOL_BFD_SECTION (sym);
1103
1104   switch (SYMBOL_CLASS (sym))
1105     {
1106     case LOC_CONST:
1107     case LOC_CONST_BYTES:
1108       printf_filtered ("constant");
1109       break;
1110
1111     case LOC_LABEL:
1112       printf_filtered ("a label at address ");
1113       fputs_filtered (paddress (load_addr = SYMBOL_VALUE_ADDRESS (sym)),
1114                       gdb_stdout);
1115       if (section_is_overlay (section))
1116         {
1117           load_addr = overlay_unmapped_address (load_addr, section);
1118           printf_filtered (",\n -- loaded at ");
1119           fputs_filtered (paddress (load_addr), gdb_stdout);
1120           printf_filtered (" in overlay section %s", section->name);
1121         }
1122       break;
1123
1124     case LOC_COMPUTED:
1125     case LOC_COMPUTED_ARG:
1126       /* FIXME: cagney/2004-01-26: It should be possible to
1127          unconditionally call the SYMBOL_OPS method when available.
1128          Unfortunately DWARF 2 stores the frame-base (instead of the
1129          function) location in a function's symbol.  Oops!  For the
1130          moment enable this when/where applicable.  */
1131       SYMBOL_OPS (sym)->describe_location (sym, gdb_stdout);
1132       break;
1133
1134     case LOC_REGISTER:
1135       printf_filtered (_("a variable in register %s"),
1136                          gdbarch_register_name (current_gdbarch, val));
1137       break;
1138
1139     case LOC_STATIC:
1140       printf_filtered (_("static storage at address "));
1141      fputs_filtered (paddress (load_addr = SYMBOL_VALUE_ADDRESS (sym)),
1142                      gdb_stdout);
1143       if (section_is_overlay (section))
1144         {
1145           load_addr = overlay_unmapped_address (load_addr, section);
1146           printf_filtered (_(",\n -- loaded at "));
1147           fputs_filtered (paddress (load_addr), gdb_stdout);
1148           printf_filtered (_(" in overlay section %s"), section->name);
1149         }
1150       break;
1151
1152     case LOC_REGPARM:
1153       printf_filtered (_("an argument in register %s"),
1154                          gdbarch_register_name (current_gdbarch, val));
1155       break;
1156
1157     case LOC_REGPARM_ADDR:
1158       printf_filtered (_("address of an argument in register %s"),
1159                        gdbarch_register_name (current_gdbarch, val));
1160       break;
1161
1162     case LOC_ARG:
1163       printf_filtered (_("an argument at offset %ld"), val);
1164       break;
1165
1166     case LOC_LOCAL:
1167       printf_filtered (_("a local variable at frame offset %ld"), val);
1168       break;
1169
1170     case LOC_REF_ARG:
1171       printf_filtered (_("a reference argument at offset %ld"), val);
1172       break;
1173
1174     case LOC_TYPEDEF:
1175       printf_filtered (_("a typedef"));
1176       break;
1177
1178     case LOC_BLOCK:
1179       printf_filtered (_("a function at address "));
1180       load_addr = BLOCK_START (SYMBOL_BLOCK_VALUE (sym));
1181       fputs_filtered (paddress (load_addr), gdb_stdout);
1182       if (section_is_overlay (section))
1183         {
1184           load_addr = overlay_unmapped_address (load_addr, section);
1185           printf_filtered (_(",\n -- loaded at "));
1186           fputs_filtered (paddress (load_addr), gdb_stdout);
1187           printf_filtered (_(" in overlay section %s"), section->name);
1188         }
1189       break;
1190
1191     case LOC_UNRESOLVED:
1192       {
1193         struct minimal_symbol *msym;
1194
1195         msym = lookup_minimal_symbol (DEPRECATED_SYMBOL_NAME (sym), NULL, NULL);
1196         if (msym == NULL)
1197           printf_filtered ("unresolved");
1198         else
1199           {
1200             section = SYMBOL_BFD_SECTION (msym);
1201             printf_filtered (_("static storage at address "));
1202             load_addr = SYMBOL_VALUE_ADDRESS (msym);
1203             fputs_filtered (paddress (load_addr), gdb_stdout);
1204             if (section_is_overlay (section))
1205               {
1206                 load_addr = overlay_unmapped_address (load_addr, section);
1207                 printf_filtered (_(",\n -- loaded at "));
1208                 fputs_filtered (paddress (load_addr), gdb_stdout);
1209                 printf_filtered (_(" in overlay section %s"), section->name);
1210               }
1211           }
1212       }
1213       break;
1214
1215     case LOC_OPTIMIZED_OUT:
1216       printf_filtered (_("optimized out"));
1217       break;
1218
1219     default:
1220       printf_filtered (_("of unknown (botched) type"));
1221       break;
1222     }
1223   printf_filtered (".\n");
1224 }
1225 \f
1226
1227 static void
1228 x_command (char *exp, int from_tty)
1229 {
1230   struct expression *expr;
1231   struct format_data fmt;
1232   struct cleanup *old_chain;
1233   struct value *val;
1234
1235   fmt.format = last_format;
1236   fmt.size = last_size;
1237   fmt.count = 1;
1238
1239   if (exp && *exp == '/')
1240     {
1241       exp++;
1242       fmt = decode_format (&exp, last_format, last_size);
1243     }
1244
1245   /* If we have an expression, evaluate it and use it as the address.  */
1246
1247   if (exp != 0 && *exp != 0)
1248     {
1249       expr = parse_expression (exp);
1250       /* Cause expression not to be there any more if this command is
1251          repeated with Newline.  But don't clobber a user-defined
1252          command's definition.  */
1253       if (from_tty)
1254         *exp = 0;
1255       old_chain = make_cleanup (free_current_contents, &expr);
1256       val = evaluate_expression (expr);
1257       if (TYPE_CODE (value_type (val)) == TYPE_CODE_REF)
1258         val = value_ind (val);
1259       /* In rvalue contexts, such as this, functions are coerced into
1260          pointers to functions.  This makes "x/i main" work.  */
1261       if (/* last_format == 'i'  && */ 
1262           TYPE_CODE (value_type (val)) == TYPE_CODE_FUNC
1263            && VALUE_LVAL (val) == lval_memory)
1264         next_address = VALUE_ADDRESS (val);
1265       else
1266         next_address = value_as_address (val);
1267       do_cleanups (old_chain);
1268     }
1269
1270   do_examine (fmt, next_address);
1271
1272   /* If the examine succeeds, we remember its size and format for next
1273      time.  */
1274   last_size = fmt.size;
1275   last_format = fmt.format;
1276
1277   /* Set a couple of internal variables if appropriate. */
1278   if (last_examine_value)
1279     {
1280       /* Make last address examined available to the user as $_.  Use
1281          the correct pointer type.  */
1282       struct type *pointer_type
1283         = lookup_pointer_type (value_type (last_examine_value));
1284       set_internalvar (lookup_internalvar ("_"),
1285                        value_from_pointer (pointer_type,
1286                                            last_examine_address));
1287
1288       /* Make contents of last address examined available to the user
1289          as $__.  If the last value has not been fetched from memory
1290          then don't fetch it now; instead mark it by voiding the $__
1291          variable.  */
1292       if (value_lazy (last_examine_value))
1293         set_internalvar (lookup_internalvar ("__"),
1294                          allocate_value (builtin_type_void));
1295       else
1296         set_internalvar (lookup_internalvar ("__"), last_examine_value);
1297     }
1298 }
1299 \f
1300
1301 /* Add an expression to the auto-display chain.
1302    Specify the expression.  */
1303
1304 static void
1305 display_command (char *exp, int from_tty)
1306 {
1307   struct format_data fmt;
1308   struct expression *expr;
1309   struct display *new;
1310   int display_it = 1;
1311
1312 #if defined(TUI)
1313   /* NOTE: cagney/2003-02-13 The `tui_active' was previously
1314      `tui_version'.  */
1315   if (tui_active && exp != NULL && *exp == '$')
1316     display_it = (tui_set_layout_for_display_command (exp) == TUI_FAILURE);
1317 #endif
1318
1319   if (display_it)
1320     {
1321       if (exp == 0)
1322         {
1323           do_displays ();
1324           return;
1325         }
1326
1327       if (*exp == '/')
1328         {
1329           exp++;
1330           fmt = decode_format (&exp, 0, 0);
1331           if (fmt.size && fmt.format == 0)
1332             fmt.format = 'x';
1333           if (fmt.format == 'i' || fmt.format == 's')
1334             fmt.size = 'b';
1335         }
1336       else
1337         {
1338           fmt.format = 0;
1339           fmt.size = 0;
1340           fmt.count = 0;
1341         }
1342
1343       innermost_block = 0;
1344       expr = parse_expression (exp);
1345
1346       new = (struct display *) xmalloc (sizeof (struct display));
1347
1348       new->exp = expr;
1349       new->block = innermost_block;
1350       new->next = display_chain;
1351       new->number = ++display_number;
1352       new->format = fmt;
1353       new->enabled_p = 1;
1354       display_chain = new;
1355
1356       if (from_tty && target_has_execution)
1357         do_one_display (new);
1358
1359       dont_repeat ();
1360     }
1361 }
1362
1363 static void
1364 free_display (struct display *d)
1365 {
1366   xfree (d->exp);
1367   xfree (d);
1368 }
1369
1370 /* Clear out the display_chain.  Done when new symtabs are loaded,
1371    since this invalidates the types stored in many expressions.  */
1372
1373 void
1374 clear_displays (void)
1375 {
1376   struct display *d;
1377
1378   while ((d = display_chain) != NULL)
1379     {
1380       xfree (d->exp);
1381       display_chain = d->next;
1382       xfree (d);
1383     }
1384 }
1385
1386 /* Delete the auto-display number NUM.  */
1387
1388 static void
1389 delete_display (int num)
1390 {
1391   struct display *d1, *d;
1392
1393   if (!display_chain)
1394     error (_("No display number %d."), num);
1395
1396   if (display_chain->number == num)
1397     {
1398       d1 = display_chain;
1399       display_chain = d1->next;
1400       free_display (d1);
1401     }
1402   else
1403     for (d = display_chain;; d = d->next)
1404       {
1405         if (d->next == 0)
1406           error (_("No display number %d."), num);
1407         if (d->next->number == num)
1408           {
1409             d1 = d->next;
1410             d->next = d1->next;
1411             free_display (d1);
1412             break;
1413           }
1414       }
1415 }
1416
1417 /* Delete some values from the auto-display chain.
1418    Specify the element numbers.  */
1419
1420 static void
1421 undisplay_command (char *args, int from_tty)
1422 {
1423   char *p = args;
1424   char *p1;
1425   int num;
1426
1427   if (args == 0)
1428     {
1429       if (query ("Delete all auto-display expressions? "))
1430         clear_displays ();
1431       dont_repeat ();
1432       return;
1433     }
1434
1435   while (*p)
1436     {
1437       p1 = p;
1438       while (*p1 >= '0' && *p1 <= '9')
1439         p1++;
1440       if (*p1 && *p1 != ' ' && *p1 != '\t')
1441         error (_("Arguments must be display numbers."));
1442
1443       num = atoi (p);
1444
1445       delete_display (num);
1446
1447       p = p1;
1448       while (*p == ' ' || *p == '\t')
1449         p++;
1450     }
1451   dont_repeat ();
1452 }
1453
1454 /* Display a single auto-display.  
1455    Do nothing if the display cannot be printed in the current context,
1456    or if the display is disabled. */
1457
1458 static void
1459 do_one_display (struct display *d)
1460 {
1461   int within_current_scope;
1462
1463   if (d->enabled_p == 0)
1464     return;
1465
1466   if (d->block)
1467     within_current_scope = contained_in (get_selected_block (0), d->block);
1468   else
1469     within_current_scope = 1;
1470   if (!within_current_scope)
1471     return;
1472
1473   current_display_number = d->number;
1474
1475   annotate_display_begin ();
1476   printf_filtered ("%d", d->number);
1477   annotate_display_number_end ();
1478   printf_filtered (": ");
1479   if (d->format.size)
1480     {
1481       CORE_ADDR addr;
1482       struct value *val;
1483
1484       annotate_display_format ();
1485
1486       printf_filtered ("x/");
1487       if (d->format.count != 1)
1488         printf_filtered ("%d", d->format.count);
1489       printf_filtered ("%c", d->format.format);
1490       if (d->format.format != 'i' && d->format.format != 's')
1491         printf_filtered ("%c", d->format.size);
1492       printf_filtered (" ");
1493
1494       annotate_display_expression ();
1495
1496       print_expression (d->exp, gdb_stdout);
1497       annotate_display_expression_end ();
1498
1499       if (d->format.count != 1 || d->format.format == 'i')
1500         printf_filtered ("\n");
1501       else
1502         printf_filtered ("  ");
1503
1504       val = evaluate_expression (d->exp);
1505       addr = value_as_address (val);
1506       if (d->format.format == 'i')
1507         addr = gdbarch_addr_bits_remove (current_gdbarch, addr);
1508
1509       annotate_display_value ();
1510
1511       do_examine (d->format, addr);
1512     }
1513   else
1514     {
1515       annotate_display_format ();
1516
1517       if (d->format.format)
1518         printf_filtered ("/%c ", d->format.format);
1519
1520       annotate_display_expression ();
1521
1522       print_expression (d->exp, gdb_stdout);
1523       annotate_display_expression_end ();
1524
1525       printf_filtered (" = ");
1526
1527       annotate_display_expression ();
1528
1529       print_formatted (evaluate_expression (d->exp),
1530                        d->format.format, d->format.size, gdb_stdout);
1531       printf_filtered ("\n");
1532     }
1533
1534   annotate_display_end ();
1535
1536   gdb_flush (gdb_stdout);
1537   current_display_number = -1;
1538 }
1539
1540 /* Display all of the values on the auto-display chain which can be
1541    evaluated in the current scope.  */
1542
1543 void
1544 do_displays (void)
1545 {
1546   struct display *d;
1547
1548   for (d = display_chain; d; d = d->next)
1549     do_one_display (d);
1550 }
1551
1552 /* Delete the auto-display which we were in the process of displaying.
1553    This is done when there is an error or a signal.  */
1554
1555 void
1556 disable_display (int num)
1557 {
1558   struct display *d;
1559
1560   for (d = display_chain; d; d = d->next)
1561     if (d->number == num)
1562       {
1563         d->enabled_p = 0;
1564         return;
1565       }
1566   printf_unfiltered (_("No display number %d.\n"), num);
1567 }
1568
1569 void
1570 disable_current_display (void)
1571 {
1572   if (current_display_number >= 0)
1573     {
1574       disable_display (current_display_number);
1575       fprintf_unfiltered (gdb_stderr, _("\
1576 Disabling display %d to avoid infinite recursion.\n"),
1577                           current_display_number);
1578     }
1579   current_display_number = -1;
1580 }
1581
1582 static void
1583 display_info (char *ignore, int from_tty)
1584 {
1585   struct display *d;
1586
1587   if (!display_chain)
1588     printf_unfiltered (_("There are no auto-display expressions now.\n"));
1589   else
1590     printf_filtered (_("Auto-display expressions now in effect:\n\
1591 Num Enb Expression\n"));
1592
1593   for (d = display_chain; d; d = d->next)
1594     {
1595       printf_filtered ("%d:   %c  ", d->number, "ny"[(int) d->enabled_p]);
1596       if (d->format.size)
1597         printf_filtered ("/%d%c%c ", d->format.count, d->format.size,
1598                          d->format.format);
1599       else if (d->format.format)
1600         printf_filtered ("/%c ", d->format.format);
1601       print_expression (d->exp, gdb_stdout);
1602       if (d->block && !contained_in (get_selected_block (0), d->block))
1603         printf_filtered (_(" (cannot be evaluated in the current context)"));
1604       printf_filtered ("\n");
1605       gdb_flush (gdb_stdout);
1606     }
1607 }
1608
1609 static void
1610 enable_display (char *args, int from_tty)
1611 {
1612   char *p = args;
1613   char *p1;
1614   int num;
1615   struct display *d;
1616
1617   if (p == 0)
1618     {
1619       for (d = display_chain; d; d = d->next)
1620         d->enabled_p = 1;
1621     }
1622   else
1623     while (*p)
1624       {
1625         p1 = p;
1626         while (*p1 >= '0' && *p1 <= '9')
1627           p1++;
1628         if (*p1 && *p1 != ' ' && *p1 != '\t')
1629           error (_("Arguments must be display numbers."));
1630
1631         num = atoi (p);
1632
1633         for (d = display_chain; d; d = d->next)
1634           if (d->number == num)
1635             {
1636               d->enabled_p = 1;
1637               goto win;
1638             }
1639         printf_unfiltered (_("No display number %d.\n"), num);
1640       win:
1641         p = p1;
1642         while (*p == ' ' || *p == '\t')
1643           p++;
1644       }
1645 }
1646
1647 static void
1648 disable_display_command (char *args, int from_tty)
1649 {
1650   char *p = args;
1651   char *p1;
1652   struct display *d;
1653
1654   if (p == 0)
1655     {
1656       for (d = display_chain; d; d = d->next)
1657         d->enabled_p = 0;
1658     }
1659   else
1660     while (*p)
1661       {
1662         p1 = p;
1663         while (*p1 >= '0' && *p1 <= '9')
1664           p1++;
1665         if (*p1 && *p1 != ' ' && *p1 != '\t')
1666           error (_("Arguments must be display numbers."));
1667
1668         disable_display (atoi (p));
1669
1670         p = p1;
1671         while (*p == ' ' || *p == '\t')
1672           p++;
1673       }
1674 }
1675 \f
1676
1677 /* Print the value in stack frame FRAME of a variable specified by a
1678    struct symbol.  */
1679
1680 void
1681 print_variable_value (struct symbol *var, struct frame_info *frame,
1682                       struct ui_file *stream)
1683 {
1684   struct value *val = read_var_value (var, frame);
1685
1686   value_print (val, stream, 0, Val_pretty_default);
1687 }
1688
1689 static void
1690 printf_command (char *arg, int from_tty)
1691 {
1692   char *f = NULL;
1693   char *s = arg;
1694   char *string = NULL;
1695   struct value **val_args;
1696   char *substrings;
1697   char *current_substring;
1698   int nargs = 0;
1699   int allocated_args = 20;
1700   struct cleanup *old_cleanups;
1701
1702   val_args = xmalloc (allocated_args * sizeof (struct value *));
1703   old_cleanups = make_cleanup (free_current_contents, &val_args);
1704
1705   if (s == 0)
1706     error_no_arg (_("format-control string and values to print"));
1707
1708   /* Skip white space before format string */
1709   while (*s == ' ' || *s == '\t')
1710     s++;
1711
1712   /* A format string should follow, enveloped in double quotes.  */
1713   if (*s++ != '"')
1714     error (_("Bad format string, missing '\"'."));
1715
1716   /* Parse the format-control string and copy it into the string STRING,
1717      processing some kinds of escape sequence.  */
1718
1719   f = string = (char *) alloca (strlen (s) + 1);
1720
1721   while (*s != '"')
1722     {
1723       int c = *s++;
1724       switch (c)
1725         {
1726         case '\0':
1727           error (_("Bad format string, non-terminated '\"'."));
1728
1729         case '\\':
1730           switch (c = *s++)
1731             {
1732             case '\\':
1733               *f++ = '\\';
1734               break;
1735             case 'a':
1736               *f++ = '\a';
1737               break;
1738             case 'b':
1739               *f++ = '\b';
1740               break;
1741             case 'f':
1742               *f++ = '\f';
1743               break;
1744             case 'n':
1745               *f++ = '\n';
1746               break;
1747             case 'r':
1748               *f++ = '\r';
1749               break;
1750             case 't':
1751               *f++ = '\t';
1752               break;
1753             case 'v':
1754               *f++ = '\v';
1755               break;
1756             case '"':
1757               *f++ = '"';
1758               break;
1759             default:
1760               /* ??? TODO: handle other escape sequences */
1761               error (_("Unrecognized escape character \\%c in format string."),
1762                      c);
1763             }
1764           break;
1765
1766         default:
1767           *f++ = c;
1768         }
1769     }
1770
1771   /* Skip over " and following space and comma.  */
1772   s++;
1773   *f++ = '\0';
1774   while (*s == ' ' || *s == '\t')
1775     s++;
1776
1777   if (*s != ',' && *s != 0)
1778     error (_("Invalid argument syntax"));
1779
1780   if (*s == ',')
1781     s++;
1782   while (*s == ' ' || *s == '\t')
1783     s++;
1784
1785   /* Need extra space for the '\0's.  Doubling the size is sufficient.  */
1786   substrings = alloca (strlen (string) * 2);
1787   current_substring = substrings;
1788
1789   {
1790     /* Now scan the string for %-specs and see what kinds of args they want.
1791        argclass[I] classifies the %-specs so we can give printf_filtered
1792        something of the right size.  */
1793
1794     enum argclass
1795       {
1796         int_arg, long_arg, long_long_arg, ptr_arg, string_arg,
1797         double_arg, long_double_arg, decfloat_arg
1798       };
1799     enum argclass *argclass;
1800     enum argclass this_argclass;
1801     char *last_arg;
1802     int nargs_wanted;
1803     int i;
1804
1805     argclass = (enum argclass *) alloca (strlen (s) * sizeof *argclass);
1806     nargs_wanted = 0;
1807     f = string;
1808     last_arg = string;
1809     while (*f)
1810       if (*f++ == '%')
1811         {
1812           int seen_hash = 0, seen_zero = 0, lcount = 0, seen_prec = 0;
1813           int seen_space = 0, seen_plus = 0;
1814           int seen_big_l = 0, seen_h = 0, seen_big_h = 0;
1815           int seen_big_d = 0, seen_double_big_d = 0;
1816           int bad = 0;
1817
1818           /* Check the validity of the format specifier, and work
1819              out what argument it expects.  We only accept C89
1820              format strings, with the exception of long long (which
1821              we autoconf for).  */
1822
1823           /* Skip over "%%".  */
1824           if (*f == '%')
1825             {
1826               f++;
1827               continue;
1828             }
1829
1830           /* The first part of a format specifier is a set of flag
1831              characters.  */
1832           while (strchr ("0-+ #", *f))
1833             {
1834               if (*f == '#')
1835                 seen_hash = 1;
1836               else if (*f == '0')
1837                 seen_zero = 1;
1838               else if (*f == ' ')
1839                 seen_space = 1;
1840               else if (*f == '+')
1841                 seen_plus = 1;
1842               f++;
1843             }
1844
1845           /* The next part of a format specifier is a width.  */
1846           while (strchr ("0123456789", *f))
1847             f++;
1848
1849           /* The next part of a format specifier is a precision.  */
1850           if (*f == '.')
1851             {
1852               seen_prec = 1;
1853               f++;
1854               while (strchr ("0123456789", *f))
1855                 f++;
1856             }
1857
1858           /* The next part of a format specifier is a length modifier.  */
1859           if (*f == 'h')
1860             {
1861               seen_h = 1;
1862               f++;
1863             }
1864           else if (*f == 'l')
1865             {
1866               f++;
1867               lcount++;
1868               if (*f == 'l')
1869                 {
1870                   f++;
1871                   lcount++;
1872                 }
1873             }
1874           else if (*f == 'L')
1875             {
1876               seen_big_l = 1;
1877               f++;
1878             }
1879           /* Decimal32 modifier.  */
1880           else if (*f == 'H')
1881             {
1882               seen_big_h = 1;
1883               f++;
1884             }
1885           /* Decimal64 and Decimal128 modifiers.  */
1886           else if (*f == 'D')
1887             {
1888               f++;
1889
1890               /* Check for a Decimal128.  */
1891               if (*f == 'D')
1892                 {
1893                   f++;
1894                   seen_double_big_d = 1;
1895                 }
1896               else
1897                 seen_big_d = 1;
1898             }
1899
1900           switch (*f)
1901             {
1902             case 'u':
1903               if (seen_hash)
1904                 bad = 1;
1905               /* FALLTHROUGH */
1906
1907             case 'o':
1908             case 'x':
1909             case 'X':
1910               if (seen_space || seen_plus)
1911                 bad = 1;
1912               /* FALLTHROUGH */
1913
1914             case 'd':
1915             case 'i':
1916               if (lcount == 0)
1917                 this_argclass = int_arg;
1918               else if (lcount == 1)
1919                 this_argclass = long_arg;
1920               else
1921                 this_argclass = long_long_arg;
1922
1923               if (seen_big_l)
1924                 bad = 1;
1925               break;
1926
1927             case 'c':
1928               this_argclass = int_arg;
1929               if (lcount || seen_h || seen_big_l)
1930                 bad = 1;
1931               if (seen_prec || seen_zero || seen_space || seen_plus)
1932                 bad = 1;
1933               break;
1934
1935             case 'p':
1936               this_argclass = ptr_arg;
1937               if (lcount || seen_h || seen_big_l)
1938                 bad = 1;
1939               if (seen_prec || seen_zero || seen_space || seen_plus)
1940                 bad = 1;
1941               break;
1942
1943             case 's':
1944               this_argclass = string_arg;
1945               if (lcount || seen_h || seen_big_l)
1946                 bad = 1;
1947               if (seen_zero || seen_space || seen_plus)
1948                 bad = 1;
1949               break;
1950
1951             case 'e':
1952             case 'f':
1953             case 'g':
1954             case 'E':
1955             case 'G':
1956               if (seen_big_h || seen_big_d || seen_double_big_d)
1957                 this_argclass = decfloat_arg;
1958               else if (seen_big_l)
1959                 this_argclass = long_double_arg;
1960               else
1961                 this_argclass = double_arg;
1962
1963               if (lcount || seen_h)
1964                 bad = 1;
1965               break;
1966
1967             case '*':
1968               error (_("`*' not supported for precision or width in printf"));
1969
1970             case 'n':
1971               error (_("Format specifier `n' not supported in printf"));
1972
1973             case '\0':
1974               error (_("Incomplete format specifier at end of format string"));
1975
1976             default:
1977               error (_("Unrecognized format specifier '%c' in printf"), *f);
1978             }
1979
1980           if (bad)
1981             error (_("Inappropriate modifiers to format specifier '%c' in printf"),
1982                    *f);
1983
1984           f++;
1985
1986           if (lcount > 1 && USE_PRINTF_I64)
1987             {
1988               /* Windows' printf does support long long, but not the usual way.
1989                  Convert %lld to %I64d.  */
1990               int length_before_ll = f - last_arg - 1 - lcount;
1991               strncpy (current_substring, last_arg, length_before_ll);
1992               strcpy (current_substring + length_before_ll, "I64");
1993               current_substring[length_before_ll + 3] =
1994                 last_arg[length_before_ll + lcount];
1995               current_substring += length_before_ll + 4;
1996             }
1997           else
1998             {
1999               strncpy (current_substring, last_arg, f - last_arg);
2000               current_substring += f - last_arg;
2001             }
2002           *current_substring++ = '\0';
2003           last_arg = f;
2004           argclass[nargs_wanted++] = this_argclass;
2005         }
2006
2007     /* Now, parse all arguments and evaluate them.
2008        Store the VALUEs in VAL_ARGS.  */
2009
2010     while (*s != '\0')
2011       {
2012         char *s1;
2013         if (nargs == allocated_args)
2014           val_args = (struct value **) xrealloc ((char *) val_args,
2015                                                  (allocated_args *= 2)
2016                                                  * sizeof (struct value *));
2017         s1 = s;
2018         val_args[nargs] = parse_to_comma_and_eval (&s1);
2019
2020         /* If format string wants a float, unchecked-convert the value to
2021            floating point of the same size */
2022
2023         if (argclass[nargs] == double_arg)
2024           {
2025             struct type *type = value_type (val_args[nargs]);
2026             if (TYPE_LENGTH (type) == sizeof (float))
2027               deprecated_set_value_type (val_args[nargs], builtin_type_float);
2028             if (TYPE_LENGTH (type) == sizeof (double))
2029               deprecated_set_value_type (val_args[nargs], builtin_type_double);
2030           }
2031         nargs++;
2032         s = s1;
2033         if (*s == ',')
2034           s++;
2035       }
2036
2037     if (nargs != nargs_wanted)
2038       error (_("Wrong number of arguments for specified format-string"));
2039
2040     /* Now actually print them.  */
2041     current_substring = substrings;
2042     for (i = 0; i < nargs; i++)
2043       {
2044         switch (argclass[i])
2045           {
2046           case string_arg:
2047             {
2048               gdb_byte *str;
2049               CORE_ADDR tem;
2050               int j;
2051               tem = value_as_address (val_args[i]);
2052
2053               /* This is a %s argument.  Find the length of the string.  */
2054               for (j = 0;; j++)
2055                 {
2056                   gdb_byte c;
2057                   QUIT;
2058                   read_memory (tem + j, &c, 1);
2059                   if (c == 0)
2060                     break;
2061                 }
2062
2063               /* Copy the string contents into a string inside GDB.  */
2064               str = (gdb_byte *) alloca (j + 1);
2065               if (j != 0)
2066                 read_memory (tem, str, j);
2067               str[j] = 0;
2068
2069               printf_filtered (current_substring, (char *) str);
2070             }
2071             break;
2072           case double_arg:
2073             {
2074               double val = value_as_double (val_args[i]);
2075               printf_filtered (current_substring, val);
2076               break;
2077             }
2078           case long_double_arg:
2079 #ifdef HAVE_LONG_DOUBLE
2080             {
2081               long double val = value_as_double (val_args[i]);
2082               printf_filtered (current_substring, val);
2083               break;
2084             }
2085 #else
2086             error (_("long double not supported in printf"));
2087 #endif
2088           case long_long_arg:
2089 #if defined (CC_HAS_LONG_LONG) && defined (PRINTF_HAS_LONG_LONG)
2090             {
2091               long long val = value_as_long (val_args[i]);
2092               printf_filtered (current_substring, val);
2093               break;
2094             }
2095 #else
2096             error (_("long long not supported in printf"));
2097 #endif
2098           case int_arg:
2099             {
2100               int val = value_as_long (val_args[i]);
2101               printf_filtered (current_substring, val);
2102               break;
2103             }
2104           case long_arg:
2105             {
2106               long val = value_as_long (val_args[i]);
2107               printf_filtered (current_substring, val);
2108               break;
2109             }
2110
2111           /* Handles decimal floating values.  */
2112         case decfloat_arg:
2113             {
2114               const gdb_byte *param_ptr = value_contents (val_args[i]);
2115 #if defined (PRINTF_HAS_DECFLOAT)
2116               /* If we have native support for Decimal floating
2117                  printing, handle it here.  */
2118               printf_filtered (current_substring, param_ptr);
2119 #else
2120
2121               /* As a workaround until vasprintf has native support for DFP
2122                we convert the DFP values to string and print them using
2123                the %s format specifier.  */
2124
2125               char *eos, *sos;
2126               int nnull_chars = 0;
2127
2128               /* Parameter data.  */
2129               struct type *param_type = value_type (val_args[i]);
2130               unsigned int param_len = TYPE_LENGTH (param_type);
2131
2132               /* DFP output data.  */
2133               struct value *dfp_value = NULL;
2134               gdb_byte *dfp_ptr;
2135               int dfp_len = 16;
2136               gdb_byte dec[16];
2137               struct type *dfp_type = NULL;
2138               char decstr[MAX_DECIMAL_STRING];
2139
2140               /* Points to the end of the string so that we can go back
2141                  and check for DFP length modifiers.  */
2142               eos = current_substring + strlen (current_substring);
2143
2144               /* Look for the float/double format specifier.  */
2145               while (*eos != 'f' && *eos != 'e' && *eos != 'E'
2146                      && *eos != 'g' && *eos != 'G')
2147                   eos--;
2148
2149               sos = eos;
2150
2151               /* Search for the '%' char and extract the size and type of
2152                  the output decimal value based on its modifiers
2153                  (%Hf, %Df, %DDf).  */
2154               while (*--sos != '%')
2155                 {
2156                   if (*sos == 'H')
2157                     {
2158                       dfp_len = 4;
2159                       dfp_type = builtin_type (current_gdbarch)->builtin_decfloat;
2160                     }
2161                   else if (*sos == 'D' && *(sos - 1) == 'D')
2162                     {
2163                       dfp_len = 16;
2164                       dfp_type = builtin_type (current_gdbarch)->builtin_declong;
2165                       sos--;
2166                     }
2167                   else
2168                     {
2169                       dfp_len = 8;
2170                       dfp_type = builtin_type (current_gdbarch)->builtin_decdouble;
2171                     }
2172                 }
2173
2174               /* Replace %Hf, %Df and %DDf with %s's.  */
2175               *++sos = 's';
2176
2177               /* Go through the whole format string and pull the correct
2178                  number of chars back to compensate for the change in the
2179                  format specifier.  */
2180               while (nnull_chars < nargs - i)
2181                 {
2182                   if (*eos == '\0')
2183                     nnull_chars++;
2184
2185                   *++sos = *++eos;
2186                 }
2187
2188               /* Conversion between different DFP types.  */
2189               if (TYPE_CODE (param_type) == TYPE_CODE_DECFLOAT)
2190                 decimal_convert (param_ptr, param_len, dec, dfp_len);
2191               else
2192                 /* If this is a non-trivial conversion, just output 0.
2193                    A correct converted value can be displayed by explicitly
2194                    casting to a DFP type.  */
2195                 decimal_from_string (dec, dfp_len, "0");
2196
2197               dfp_value = value_from_decfloat (dfp_type, dec);
2198
2199               dfp_ptr = (gdb_byte *) value_contents (dfp_value);
2200
2201               decimal_to_string (dfp_ptr, dfp_len, decstr);
2202
2203               /* Print the DFP value.  */
2204               printf_filtered (current_substring, decstr);
2205
2206               break;
2207 #endif
2208             }
2209
2210           case ptr_arg:
2211             {
2212               /* We avoid the host's %p because pointers are too
2213                  likely to be the wrong size.  The only interesting
2214                  modifier for %p is a width; extract that, and then
2215                  handle %p as glibc would: %#x or a literal "(nil)".  */
2216
2217               char *p, *fmt, *fmt_p;
2218 #if defined (CC_HAS_LONG_LONG) && defined (PRINTF_HAS_LONG_LONG)
2219               long long val = value_as_long (val_args[i]);
2220 #else
2221               long val = value_as_long (val_args[i]);
2222 #endif
2223
2224               fmt = alloca (strlen (current_substring) + 5);
2225
2226               /* Copy up to the leading %.  */
2227               p = current_substring;
2228               fmt_p = fmt;
2229               while (*p)
2230                 {
2231                   int is_percent = (*p == '%');
2232                   *fmt_p++ = *p++;
2233                   if (is_percent)
2234                     {
2235                       if (*p == '%')
2236                         *fmt_p++ = *p++;
2237                       else
2238                         break;
2239                     }
2240                 }
2241
2242               if (val != 0)
2243                 *fmt_p++ = '#';
2244
2245               /* Copy any width.  */
2246               while (*p >= '0' && *p < '9')
2247                 *fmt_p++ = *p++;
2248
2249               gdb_assert (*p == 'p' && *(p + 1) == '\0');
2250               if (val != 0)
2251                 {
2252 #if defined (CC_HAS_LONG_LONG) && defined (PRINTF_HAS_LONG_LONG)
2253                   *fmt_p++ = 'l';
2254 #endif
2255                   *fmt_p++ = 'l';
2256                   *fmt_p++ = 'x';
2257                   *fmt_p++ = '\0';
2258                   printf_filtered (fmt, val);
2259                 }
2260               else
2261                 {
2262                   *fmt_p++ = 's';
2263                   *fmt_p++ = '\0';
2264                   printf_filtered (fmt, "(nil)");
2265                 }
2266
2267               break;
2268             }
2269           default:
2270             internal_error (__FILE__, __LINE__,
2271                             _("failed internal consistency check"));
2272           }
2273         /* Skip to the next substring.  */
2274         current_substring += strlen (current_substring) + 1;
2275       }
2276     /* Print the portion of the format string after the last argument.  */
2277     puts_filtered (last_arg);
2278   }
2279   do_cleanups (old_cleanups);
2280 }
2281
2282 void
2283 _initialize_printcmd (void)
2284 {
2285   struct cmd_list_element *c;
2286
2287   current_display_number = -1;
2288
2289   add_info ("address", address_info,
2290             _("Describe where symbol SYM is stored."));
2291
2292   add_info ("symbol", sym_info, _("\
2293 Describe what symbol is at location ADDR.\n\
2294 Only for symbols with fixed locations (global or static scope)."));
2295
2296   add_com ("x", class_vars, x_command, _("\
2297 Examine memory: x/FMT ADDRESS.\n\
2298 ADDRESS is an expression for the memory address to examine.\n\
2299 FMT is a repeat count followed by a format letter and a size letter.\n\
2300 Format letters are o(octal), x(hex), d(decimal), u(unsigned decimal),\n\
2301   t(binary), f(float), a(address), i(instruction), c(char) and s(string).\n\
2302 Size letters are b(byte), h(halfword), w(word), g(giant, 8 bytes).\n\
2303 The specified number of objects of the specified size are printed\n\
2304 according to the format.\n\n\
2305 Defaults for format and size letters are those previously used.\n\
2306 Default count is 1.  Default address is following last thing printed\n\
2307 with this command or \"print\"."));
2308
2309 #if 0
2310   add_com ("whereis", class_vars, whereis_command,
2311            _("Print line number and file of definition of variable."));
2312 #endif
2313
2314   add_info ("display", display_info, _("\
2315 Expressions to display when program stops, with code numbers."));
2316
2317   add_cmd ("undisplay", class_vars, undisplay_command, _("\
2318 Cancel some expressions to be displayed when program stops.\n\
2319 Arguments are the code numbers of the expressions to stop displaying.\n\
2320 No argument means cancel all automatic-display expressions.\n\
2321 \"delete display\" has the same effect as this command.\n\
2322 Do \"info display\" to see current list of code numbers."),
2323            &cmdlist);
2324
2325   add_com ("display", class_vars, display_command, _("\
2326 Print value of expression EXP each time the program stops.\n\
2327 /FMT may be used before EXP as in the \"print\" command.\n\
2328 /FMT \"i\" or \"s\" or including a size-letter is allowed,\n\
2329 as in the \"x\" command, and then EXP is used to get the address to examine\n\
2330 and examining is done as in the \"x\" command.\n\n\
2331 With no argument, display all currently requested auto-display expressions.\n\
2332 Use \"undisplay\" to cancel display requests previously made."));
2333
2334   add_cmd ("display", class_vars, enable_display, _("\
2335 Enable some expressions to be displayed when program stops.\n\
2336 Arguments are the code numbers of the expressions to resume displaying.\n\
2337 No argument means enable all automatic-display expressions.\n\
2338 Do \"info display\" to see current list of code numbers."), &enablelist);
2339
2340   add_cmd ("display", class_vars, disable_display_command, _("\
2341 Disable some expressions to be displayed when program stops.\n\
2342 Arguments are the code numbers of the expressions to stop displaying.\n\
2343 No argument means disable all automatic-display expressions.\n\
2344 Do \"info display\" to see current list of code numbers."), &disablelist);
2345
2346   add_cmd ("display", class_vars, undisplay_command, _("\
2347 Cancel some expressions to be displayed when program stops.\n\
2348 Arguments are the code numbers of the expressions to stop displaying.\n\
2349 No argument means cancel all automatic-display expressions.\n\
2350 Do \"info display\" to see current list of code numbers."), &deletelist);
2351
2352   add_com ("printf", class_vars, printf_command, _("\
2353 printf \"printf format string\", arg1, arg2, arg3, ..., argn\n\
2354 This is useful for formatted output in user-defined commands."));
2355
2356   add_com ("output", class_vars, output_command, _("\
2357 Like \"print\" but don't put in value history and don't print newline.\n\
2358 This is useful in user-defined commands."));
2359
2360   add_prefix_cmd ("set", class_vars, set_command, _("\
2361 Evaluate expression EXP and assign result to variable VAR, using assignment\n\
2362 syntax appropriate for the current language (VAR = EXP or VAR := EXP for\n\
2363 example).  VAR may be a debugger \"convenience\" variable (names starting\n\
2364 with $), a register (a few standard names starting with $), or an actual\n\
2365 variable in the program being debugged.  EXP is any valid expression.\n\
2366 Use \"set variable\" for variables with names identical to set subcommands.\n\
2367 \n\
2368 With a subcommand, this command modifies parts of the gdb environment.\n\
2369 You can see these environment settings with the \"show\" command."),
2370                   &setlist, "set ", 1, &cmdlist);
2371   if (dbx_commands)
2372     add_com ("assign", class_vars, set_command, _("\
2373 Evaluate expression EXP and assign result to variable VAR, using assignment\n\
2374 syntax appropriate for the current language (VAR = EXP or VAR := EXP for\n\
2375 example).  VAR may be a debugger \"convenience\" variable (names starting\n\
2376 with $), a register (a few standard names starting with $), or an actual\n\
2377 variable in the program being debugged.  EXP is any valid expression.\n\
2378 Use \"set variable\" for variables with names identical to set subcommands.\n\
2379 \nWith a subcommand, this command modifies parts of the gdb environment.\n\
2380 You can see these environment settings with the \"show\" command."));
2381
2382   /* "call" is the same as "set", but handy for dbx users to call fns. */
2383   c = add_com ("call", class_vars, call_command, _("\
2384 Call a function in the program.\n\
2385 The argument is the function name and arguments, in the notation of the\n\
2386 current working language.  The result is printed and saved in the value\n\
2387 history, if it is not void."));
2388   set_cmd_completer (c, location_completer);
2389
2390   add_cmd ("variable", class_vars, set_command, _("\
2391 Evaluate expression EXP and assign result to variable VAR, using assignment\n\
2392 syntax appropriate for the current language (VAR = EXP or VAR := EXP for\n\
2393 example).  VAR may be a debugger \"convenience\" variable (names starting\n\
2394 with $), a register (a few standard names starting with $), or an actual\n\
2395 variable in the program being debugged.  EXP is any valid expression.\n\
2396 This may usually be abbreviated to simply \"set\"."),
2397            &setlist);
2398
2399   c = add_com ("print", class_vars, print_command, _("\
2400 Print value of expression EXP.\n\
2401 Variables accessible are those of the lexical environment of the selected\n\
2402 stack frame, plus all those whose scope is global or an entire file.\n\
2403 \n\
2404 $NUM gets previous value number NUM.  $ and $$ are the last two values.\n\
2405 $$NUM refers to NUM'th value back from the last one.\n\
2406 Names starting with $ refer to registers (with the values they would have\n\
2407 if the program were to return to the stack frame now selected, restoring\n\
2408 all registers saved by frames farther in) or else to debugger\n\
2409 \"convenience\" variables (any such name not a known register).\n\
2410 Use assignment expressions to give values to convenience variables.\n\
2411 \n\
2412 {TYPE}ADREXP refers to a datum of data type TYPE, located at address ADREXP.\n\
2413 @ is a binary operator for treating consecutive data objects\n\
2414 anywhere in memory as an array.  FOO@NUM gives an array whose first\n\
2415 element is FOO, whose second element is stored in the space following\n\
2416 where FOO is stored, etc.  FOO must be an expression whose value\n\
2417 resides in memory.\n\
2418 \n\
2419 EXP may be preceded with /FMT, where FMT is a format letter\n\
2420 but no count or size letter (see \"x\" command)."));
2421   set_cmd_completer (c, location_completer);
2422   add_com_alias ("p", "print", class_vars, 1);
2423
2424   c = add_com ("inspect", class_vars, inspect_command, _("\
2425 Same as \"print\" command, except that if you are running in the epoch\n\
2426 environment, the value is printed in its own window."));
2427   set_cmd_completer (c, location_completer);
2428
2429   add_setshow_uinteger_cmd ("max-symbolic-offset", no_class,
2430                             &max_symbolic_offset, _("\
2431 Set the largest offset that will be printed in <symbol+1234> form."), _("\
2432 Show the largest offset that will be printed in <symbol+1234> form."), NULL,
2433                             NULL,
2434                             show_max_symbolic_offset,
2435                             &setprintlist, &showprintlist);
2436   add_setshow_boolean_cmd ("symbol-filename", no_class,
2437                            &print_symbol_filename, _("\
2438 Set printing of source filename and line number with <symbol>."), _("\
2439 Show printing of source filename and line number with <symbol>."), NULL,
2440                            NULL,
2441                            show_print_symbol_filename,
2442                            &setprintlist, &showprintlist);
2443
2444   /* For examine/instruction a single byte quantity is specified as
2445      the data.  This avoids problems with value_at_lazy() requiring a
2446      valid data type (and rejecting VOID). */
2447   examine_i_type = init_type (TYPE_CODE_INT, 1, 0, "examine_i_type", NULL);
2448
2449   examine_b_type = init_type (TYPE_CODE_INT, 1, 0, "examine_b_type", NULL);
2450   examine_h_type = init_type (TYPE_CODE_INT, 2, 0, "examine_h_type", NULL);
2451   examine_w_type = init_type (TYPE_CODE_INT, 4, 0, "examine_w_type", NULL);
2452   examine_g_type = init_type (TYPE_CODE_INT, 8, 0, "examine_g_type", NULL);
2453
2454 }