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