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