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