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