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