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