* gdbtypes.h (struct builtin_type): Add internal_fn member.
[deliverable/binutils-gdb.git] / gdb / printcmd.c
CommitLineData
c906108c 1/* Print values for GNU debugger GDB.
e2ad119d 2
6aba47ca 3 Copyright (C) 1986, 1987, 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995,
9b254dd1 4 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007,
0fb0cc75 5 2008, 2009 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"
1a619819 44#include "dfp.h"
79a45b7d 45#include "valprint.h"
a3247a22
PP
46#include "exceptions.h"
47#include "observer.h"
48#include "solist.h"
49#include "solib.h"
50#include "parser-defs.h"
6c7a06a3 51#include "charset.h"
c906108c 52
6a83354a
AC
53#ifdef TUI
54#include "tui/tui.h" /* For tui_active et.al. */
55#endif
56
06be140c 57#if defined(__MINGW32__) && !defined(PRINTF_HAS_LONG_LONG)
09d71d23
AS
58# define USE_PRINTF_I64 1
59# define PRINTF_HAS_LONG_LONG
60#else
61# define USE_PRINTF_I64 0
62#endif
63
c906108c 64extern int asm_demangle; /* Whether to demangle syms in asm printouts */
c906108c
SS
65
66struct format_data
c5aa993b
JM
67 {
68 int count;
69 char format;
70 char size;
a6bac58e
TT
71
72 /* True if the value should be printed raw -- that is, bypassing
73 python-based formatters. */
74 unsigned char raw;
c5aa993b 75 };
c906108c
SS
76
77/* Last specified output format. */
78
a6bac58e 79static char last_format = 0;
c906108c
SS
80
81/* Last specified examination size. 'b', 'h', 'w' or `q'. */
82
83static char last_size = 'w';
84
85/* Default address to examine next. */
86
87static CORE_ADDR next_address;
88
a4642986
MR
89/* Number of delay instructions following current disassembled insn. */
90
91static int branch_delay_insns;
92
c906108c
SS
93/* Last address examined. */
94
95static CORE_ADDR last_examine_address;
96
97/* Contents of last address examined.
98 This is not valid past the end of the `x' command! */
99
3d6d86c6 100static struct value *last_examine_value;
c906108c
SS
101
102/* Largest offset between a symbolic value and an address, that will be
103 printed as `0x1234 <symbol+offset>'. */
104
105static unsigned int max_symbolic_offset = UINT_MAX;
920d2a44
AC
106static void
107show_max_symbolic_offset (struct ui_file *file, int from_tty,
108 struct cmd_list_element *c, const char *value)
109{
110 fprintf_filtered (file, _("\
111The largest offset that will be printed in <symbol+1234> form is %s.\n"),
112 value);
113}
c906108c
SS
114
115/* Append the source filename and linenumber of the symbol when
116 printing a symbolic value as `<symbol at filename:linenum>' if set. */
117static int print_symbol_filename = 0;
920d2a44
AC
118static void
119show_print_symbol_filename (struct ui_file *file, int from_tty,
120 struct cmd_list_element *c, const char *value)
121{
122 fprintf_filtered (file, _("\
123Printing of source filename and line number with <symbol> is %s.\n"),
124 value);
125}
c906108c
SS
126
127/* Number of auto-display expression currently being displayed.
128 So that we can disable it if we get an error or a signal within it.
129 -1 when not doing one. */
130
131int current_display_number;
132
c906108c 133struct display
c5aa993b
JM
134 {
135 /* Chain link to next auto-display item. */
136 struct display *next;
fa8a61dc
TT
137 /* The expression as the user typed it. */
138 char *exp_string;
c5aa993b
JM
139 /* Expression to be evaluated and displayed. */
140 struct expression *exp;
141 /* Item number of this auto-display item. */
142 int number;
143 /* Display format specified. */
144 struct format_data format;
145 /* Innermost block required by this expression when evaluated */
146 struct block *block;
147 /* Status of this display (enabled or disabled) */
b5de0fa7 148 int enabled_p;
c5aa993b 149 };
c906108c
SS
150
151/* Chain of expressions whose values should be displayed
152 automatically each time the program stops. */
153
154static struct display *display_chain;
155
156static int display_number;
157
158/* Prototypes for exported functions. */
159
a14ed312 160void output_command (char *, int);
c906108c 161
a14ed312 162void _initialize_printcmd (void);
c906108c
SS
163
164/* Prototypes for local functions. */
165
a14ed312 166static void do_one_display (struct display *);
c906108c 167\f
c5aa993b 168
c906108c
SS
169/* Decode a format specification. *STRING_PTR should point to it.
170 OFORMAT and OSIZE are used as defaults for the format and size
171 if none are given in the format specification.
172 If OSIZE is zero, then the size field of the returned value
173 should be set only if a size is explicitly specified by the
174 user.
175 The structure returned describes all the data
176 found in the specification. In addition, *STRING_PTR is advanced
177 past the specification and past all whitespace following it. */
178
179static struct format_data
fba45db2 180decode_format (char **string_ptr, int oformat, int osize)
c906108c
SS
181{
182 struct format_data val;
52f0bd74 183 char *p = *string_ptr;
c906108c
SS
184
185 val.format = '?';
186 val.size = '?';
187 val.count = 1;
a6bac58e 188 val.raw = 0;
c906108c
SS
189
190 if (*p >= '0' && *p <= '9')
191 val.count = atoi (p);
c5aa993b
JM
192 while (*p >= '0' && *p <= '9')
193 p++;
c906108c
SS
194
195 /* Now process size or format letters that follow. */
196
197 while (1)
198 {
199 if (*p == 'b' || *p == 'h' || *p == 'w' || *p == 'g')
200 val.size = *p++;
a6bac58e
TT
201 else if (*p == 'r')
202 {
203 val.raw = 1;
204 p++;
205 }
c906108c
SS
206 else if (*p >= 'a' && *p <= 'z')
207 val.format = *p++;
208 else
209 break;
210 }
211
c5aa993b
JM
212 while (*p == ' ' || *p == '\t')
213 p++;
c906108c
SS
214 *string_ptr = p;
215
216 /* Set defaults for format and size if not specified. */
217 if (val.format == '?')
218 {
219 if (val.size == '?')
220 {
221 /* Neither has been specified. */
222 val.format = oformat;
223 val.size = osize;
224 }
225 else
226 /* If a size is specified, any format makes a reasonable
227 default except 'i'. */
228 val.format = oformat == 'i' ? 'x' : oformat;
229 }
230 else if (val.size == '?')
231 switch (val.format)
232 {
233 case 'a':
234 case 's':
235 /* Pick the appropriate size for an address. */
819844ad 236 if (gdbarch_ptr_bit (current_gdbarch) == 64)
c906108c 237 val.size = osize ? 'g' : osize;
819844ad 238 else if (gdbarch_ptr_bit (current_gdbarch) == 32)
c906108c 239 val.size = osize ? 'w' : osize;
819844ad 240 else if (gdbarch_ptr_bit (current_gdbarch) == 16)
c906108c
SS
241 val.size = osize ? 'h' : osize;
242 else
819844ad 243 /* Bad value for gdbarch_ptr_bit. */
675dcf4f
MK
244 internal_error (__FILE__, __LINE__,
245 _("failed internal consistency check"));
c906108c
SS
246 break;
247 case 'f':
248 /* Floating point has to be word or giantword. */
249 if (osize == 'w' || osize == 'g')
250 val.size = osize;
251 else
252 /* Default it to giantword if the last used size is not
253 appropriate. */
254 val.size = osize ? 'g' : osize;
255 break;
256 case 'c':
257 /* Characters default to one byte. */
258 val.size = osize ? 'b' : osize;
259 break;
260 default:
261 /* The default is the size most recently specified. */
262 val.size = osize;
263 }
264
265 return val;
266}
267\f
79a45b7d 268/* Print value VAL on stream according to OPTIONS.
c906108c 269 Do not end with a newline.
c906108c 270 SIZE is the letter for the size of datum being printed.
ea37ba09
DJ
271 This is used to pad hex numbers so they line up. SIZE is 0
272 for print / output and set for examine. */
c906108c
SS
273
274static void
79a45b7d
TT
275print_formatted (struct value *val, int size,
276 const struct value_print_options *options,
fba45db2 277 struct ui_file *stream)
c906108c 278{
df407dfe 279 struct type *type = check_typedef (value_type (val));
c906108c
SS
280 int len = TYPE_LENGTH (type);
281
282 if (VALUE_LVAL (val) == lval_memory)
42ae5230 283 next_address = value_address (val) + len;
c906108c 284
ea37ba09 285 if (size)
c906108c 286 {
79a45b7d 287 switch (options->format)
ea37ba09
DJ
288 {
289 case 's':
6c7a06a3
TT
290 {
291 struct type *elttype = value_type (val);
42ae5230 292 next_address = (value_address (val)
6c7a06a3 293 + val_print_string (elttype,
42ae5230 294 value_address (val), -1,
6c7a06a3
TT
295 stream, options));
296 }
ea37ba09 297 return;
c906108c 298
ea37ba09
DJ
299 case 'i':
300 /* We often wrap here if there are long symbolic names. */
301 wrap_here (" ");
42ae5230
TT
302 next_address = (value_address (val)
303 + gdb_print_insn (value_address (val), stream,
ea37ba09
DJ
304 &branch_delay_insns));
305 return;
306 }
c906108c 307 }
ea37ba09 308
79a45b7d 309 if (options->format == 0 || options->format == 's'
4e885b20 310 || TYPE_CODE (type) == TYPE_CODE_REF
ea37ba09
DJ
311 || TYPE_CODE (type) == TYPE_CODE_ARRAY
312 || TYPE_CODE (type) == TYPE_CODE_STRING
313 || TYPE_CODE (type) == TYPE_CODE_STRUCT
314 || TYPE_CODE (type) == TYPE_CODE_UNION
315 || TYPE_CODE (type) == TYPE_CODE_NAMESPACE)
79a45b7d 316 value_print (val, stream, options);
ea37ba09
DJ
317 else
318 /* User specified format, so don't look to the the type to
319 tell us what to do. */
320 print_scalar_formatted (value_contents (val), type,
79a45b7d 321 options, size, stream);
c906108c
SS
322}
323
b806fb9a
UW
324/* Return builtin floating point type of same length as TYPE.
325 If no such type is found, return TYPE itself. */
326static struct type *
327float_type_from_length (struct gdbarch *gdbarch, struct type *type)
328{
329 const struct builtin_type *builtin = builtin_type (gdbarch);
330 unsigned int len = TYPE_LENGTH (type);
331
332 if (len == TYPE_LENGTH (builtin->builtin_float))
333 type = builtin->builtin_float;
334 else if (len == TYPE_LENGTH (builtin->builtin_double))
335 type = builtin->builtin_double;
336 else if (len == TYPE_LENGTH (builtin->builtin_long_double))
337 type = builtin->builtin_long_double;
338
339 return type;
340}
341
c906108c 342/* Print a scalar of data of type TYPE, pointed to in GDB by VALADDR,
79a45b7d
TT
343 according to OPTIONS and SIZE on STREAM.
344 Formats s and i are not supported at this level.
c906108c
SS
345
346 This is how the elements of an array or structure are printed
347 with a format. */
348
349void
366b1cbf 350print_scalar_formatted (const void *valaddr, struct type *type,
79a45b7d
TT
351 const struct value_print_options *options,
352 int size, struct ui_file *stream)
c906108c 353{
81cb7cc9 354 LONGEST val_long = 0;
c906108c 355 unsigned int len = TYPE_LENGTH (type);
d44e8473 356 enum bfd_endian byte_order = gdbarch_byte_order (current_gdbarch);
c906108c 357
ea37ba09
DJ
358 /* If we get here with a string format, try again without it. Go
359 all the way back to the language printers, which may call us
360 again. */
79a45b7d 361 if (options->format == 's')
ea37ba09 362 {
79a45b7d
TT
363 struct value_print_options opts = *options;
364 opts.format = 0;
365 opts.deref_ref = 0;
366 val_print (type, valaddr, 0, 0, stream, 0, &opts,
d8ca156b 367 current_language);
ea37ba09
DJ
368 return;
369 }
370
6b9acc27
JJ
371 if (len > sizeof(LONGEST) &&
372 (TYPE_CODE (type) == TYPE_CODE_INT
373 || TYPE_CODE (type) == TYPE_CODE_ENUM))
374 {
79a45b7d 375 switch (options->format)
6b9acc27
JJ
376 {
377 case 'o':
d44e8473 378 print_octal_chars (stream, valaddr, len, byte_order);
6b9acc27
JJ
379 return;
380 case 'u':
381 case 'd':
d44e8473 382 print_decimal_chars (stream, valaddr, len, byte_order);
6b9acc27
JJ
383 return;
384 case 't':
d44e8473 385 print_binary_chars (stream, valaddr, len, byte_order);
6b9acc27
JJ
386 return;
387 case 'x':
d44e8473 388 print_hex_chars (stream, valaddr, len, byte_order);
6b9acc27
JJ
389 return;
390 case 'c':
6c7a06a3 391 print_char_chars (stream, type, valaddr, len, byte_order);
6b9acc27
JJ
392 return;
393 default:
394 break;
395 };
396 }
397
79a45b7d 398 if (options->format != 'f')
c906108c
SS
399 val_long = unpack_long (type, valaddr);
400
ef166cf4 401 /* If the value is a pointer, and pointers and addresses are not the
d0aee0c4 402 same, then at this point, the value's length (in target bytes) is
17a912b6 403 gdbarch_addr_bit/TARGET_CHAR_BIT, not TYPE_LENGTH (type). */
ef166cf4 404 if (TYPE_CODE (type) == TYPE_CODE_PTR)
17a912b6 405 len = gdbarch_addr_bit (current_gdbarch) / TARGET_CHAR_BIT;
ef166cf4 406
c906108c
SS
407 /* If we are printing it as unsigned, truncate it in case it is actually
408 a negative signed value (e.g. "print/u (short)-1" should print 65535
409 (if shorts are 16 bits) instead of 4294967295). */
1fac167a 410 if (options->format != 'd' || TYPE_UNSIGNED (type))
c906108c
SS
411 {
412 if (len < sizeof (LONGEST))
413 val_long &= ((LONGEST) 1 << HOST_CHAR_BIT * len) - 1;
414 }
415
79a45b7d 416 switch (options->format)
c906108c
SS
417 {
418 case 'x':
419 if (!size)
420 {
675dcf4f 421 /* No size specified, like in print. Print varying # of digits. */
c906108c
SS
422 print_longest (stream, 'x', 1, val_long);
423 }
424 else
425 switch (size)
426 {
427 case 'b':
428 case 'h':
429 case 'w':
430 case 'g':
431 print_longest (stream, size, 1, val_long);
432 break;
433 default:
8a3fe4f8 434 error (_("Undefined output size \"%c\"."), size);
c906108c
SS
435 }
436 break;
437
438 case 'd':
439 print_longest (stream, 'd', 1, val_long);
440 break;
441
442 case 'u':
443 print_longest (stream, 'u', 0, val_long);
444 break;
445
446 case 'o':
447 if (val_long)
448 print_longest (stream, 'o', 1, val_long);
449 else
450 fprintf_filtered (stream, "0");
451 break;
452
453 case 'a':
593de6a6 454 {
593de6a6 455 CORE_ADDR addr = unpack_pointer (type, valaddr);
593de6a6
PS
456 print_address (addr, stream);
457 }
c906108c
SS
458 break;
459
460 case 'c':
79a45b7d
TT
461 {
462 struct value_print_options opts = *options;
463 opts.format = 0;
464 if (TYPE_UNSIGNED (type))
465 value_print (value_from_longest (builtin_type_true_unsigned_char,
466 val_long),
467 stream, &opts);
468 else
469 value_print (value_from_longest (builtin_type_true_char, val_long),
470 stream, &opts);
471 }
c906108c
SS
472 break;
473
474 case 'f':
b806fb9a 475 type = float_type_from_length (current_gdbarch, type);
c906108c
SS
476 print_floating (valaddr, type, stream);
477 break;
478
479 case 0:
675dcf4f
MK
480 internal_error (__FILE__, __LINE__,
481 _("failed internal consistency check"));
c906108c
SS
482
483 case 't':
484 /* Binary; 't' stands for "two". */
485 {
c5aa993b
JM
486 char bits[8 * (sizeof val_long) + 1];
487 char buf[8 * (sizeof val_long) + 32];
c906108c
SS
488 char *cp = bits;
489 int width;
490
c5aa993b
JM
491 if (!size)
492 width = 8 * (sizeof val_long);
493 else
494 switch (size)
c906108c
SS
495 {
496 case 'b':
497 width = 8;
498 break;
499 case 'h':
500 width = 16;
501 break;
502 case 'w':
503 width = 32;
504 break;
505 case 'g':
506 width = 64;
507 break;
508 default:
8a3fe4f8 509 error (_("Undefined output size \"%c\"."), size);
c906108c
SS
510 }
511
c5aa993b
JM
512 bits[width] = '\0';
513 while (width-- > 0)
514 {
515 bits[width] = (val_long & 1) ? '1' : '0';
516 val_long >>= 1;
517 }
c906108c
SS
518 if (!size)
519 {
520 while (*cp && *cp == '0')
521 cp++;
522 if (*cp == '\0')
523 cp--;
524 }
bb599908 525 strcpy (buf, cp);
306d9ac5 526 fputs_filtered (buf, stream);
c906108c
SS
527 }
528 break;
529
530 default:
79a45b7d 531 error (_("Undefined output format \"%c\"."), options->format);
c906108c
SS
532 }
533}
534
535/* Specify default address for `x' command.
675dcf4f 536 The `info lines' command uses this. */
c906108c
SS
537
538void
8b9b9e1a 539set_next_address (struct gdbarch *gdbarch, CORE_ADDR addr)
c906108c 540{
8b9b9e1a
UW
541 struct type *ptr_type = builtin_type (gdbarch)->builtin_data_ptr;
542
c906108c
SS
543 next_address = addr;
544
545 /* Make address available to the user as $_. */
546 set_internalvar (lookup_internalvar ("_"),
8b9b9e1a 547 value_from_pointer (ptr_type, addr));
c906108c
SS
548}
549
550/* Optionally print address ADDR symbolically as <SYMBOL+OFFSET> on STREAM,
551 after LEADIN. Print nothing if no symbolic name is found nearby.
552 Optionally also print source file and line number, if available.
553 DO_DEMANGLE controls whether to print a symbol in its native "raw" form,
554 or to interpret it as a possible C++ name and convert it back to source
555 form. However note that DO_DEMANGLE can be overridden by the specific
556 settings of the demangle and asm_demangle variables. */
557
558void
675dcf4f
MK
559print_address_symbolic (CORE_ADDR addr, struct ui_file *stream,
560 int do_demangle, char *leadin)
dfcd3bfb
JM
561{
562 char *name = NULL;
563 char *filename = NULL;
564 int unmapped = 0;
565 int offset = 0;
566 int line = 0;
567
675dcf4f 568 /* Throw away both name and filename. */
2f9429ae
AC
569 struct cleanup *cleanup_chain = make_cleanup (free_current_contents, &name);
570 make_cleanup (free_current_contents, &filename);
dfcd3bfb 571
675dcf4f
MK
572 if (build_address_symbolic (addr, do_demangle, &name, &offset,
573 &filename, &line, &unmapped))
2f9429ae
AC
574 {
575 do_cleanups (cleanup_chain);
576 return;
577 }
dfcd3bfb
JM
578
579 fputs_filtered (leadin, stream);
580 if (unmapped)
581 fputs_filtered ("<*", stream);
582 else
583 fputs_filtered ("<", stream);
584 fputs_filtered (name, stream);
585 if (offset != 0)
586 fprintf_filtered (stream, "+%u", (unsigned int) offset);
587
588 /* Append source filename and line number if desired. Give specific
589 line # of this addr, if we have it; else line # of the nearest symbol. */
590 if (print_symbol_filename && filename != NULL)
591 {
592 if (line != -1)
593 fprintf_filtered (stream, " at %s:%d", filename, line);
594 else
595 fprintf_filtered (stream, " in %s", filename);
596 }
597 if (unmapped)
598 fputs_filtered ("*>", stream);
599 else
600 fputs_filtered (">", stream);
601
602 do_cleanups (cleanup_chain);
603}
604
605/* Given an address ADDR return all the elements needed to print the
606 address in a symbolic form. NAME can be mangled or not depending
607 on DO_DEMANGLE (and also on the asm_demangle global variable,
608 manipulated via ''set print asm-demangle''). Return 0 in case of
609 success, when all the info in the OUT paramters is valid. Return 1
610 otherwise. */
611int
612build_address_symbolic (CORE_ADDR addr, /* IN */
613 int do_demangle, /* IN */
614 char **name, /* OUT */
615 int *offset, /* OUT */
616 char **filename, /* OUT */
617 int *line, /* OUT */
618 int *unmapped) /* OUT */
c906108c
SS
619{
620 struct minimal_symbol *msymbol;
621 struct symbol *symbol;
c906108c 622 CORE_ADDR name_location = 0;
714835d5 623 struct obj_section *section = NULL;
dfcd3bfb
JM
624 char *name_temp = "";
625
89c83b10 626 /* Let's say it is mapped (not unmapped). */
dfcd3bfb 627 *unmapped = 0;
c906108c 628
dfcd3bfb 629 /* Determine if the address is in an overlay, and whether it is
675dcf4f 630 mapped. */
c906108c
SS
631 if (overlay_debugging)
632 {
633 section = find_pc_overlay (addr);
634 if (pc_in_unmapped_range (addr, section))
635 {
dfcd3bfb 636 *unmapped = 1;
c906108c
SS
637 addr = overlay_mapped_address (addr, section);
638 }
639 }
640
c906108c
SS
641 /* First try to find the address in the symbol table, then
642 in the minsyms. Take the closest one. */
643
644 /* This is defective in the sense that it only finds text symbols. So
645 really this is kind of pointless--we should make sure that the
646 minimal symbols have everything we need (by changing that we could
647 save some memory, but for many debug format--ELF/DWARF or
648 anything/stabs--it would be inconvenient to eliminate those minimal
649 symbols anyway). */
650 msymbol = lookup_minimal_symbol_by_pc_section (addr, section);
651 symbol = find_pc_sect_function (addr, section);
652
653 if (symbol)
654 {
655 name_location = BLOCK_START (SYMBOL_BLOCK_VALUE (symbol));
406fc7fb 656 if (do_demangle || asm_demangle)
de5ad195 657 name_temp = SYMBOL_PRINT_NAME (symbol);
c906108c 658 else
3567439c 659 name_temp = SYMBOL_LINKAGE_NAME (symbol);
c906108c
SS
660 }
661
662 if (msymbol != NULL)
663 {
664 if (SYMBOL_VALUE_ADDRESS (msymbol) > name_location || symbol == NULL)
665 {
666 /* The msymbol is closer to the address than the symbol;
667 use the msymbol instead. */
668 symbol = 0;
c906108c 669 name_location = SYMBOL_VALUE_ADDRESS (msymbol);
406fc7fb 670 if (do_demangle || asm_demangle)
de5ad195 671 name_temp = SYMBOL_PRINT_NAME (msymbol);
c906108c 672 else
3567439c 673 name_temp = SYMBOL_LINKAGE_NAME (msymbol);
c906108c
SS
674 }
675 }
676 if (symbol == NULL && msymbol == NULL)
dfcd3bfb 677 return 1;
c906108c 678
c906108c
SS
679 /* If the nearest symbol is too far away, don't print anything symbolic. */
680
681 /* For when CORE_ADDR is larger than unsigned int, we do math in
682 CORE_ADDR. But when we detect unsigned wraparound in the
683 CORE_ADDR math, we ignore this test and print the offset,
684 because addr+max_symbolic_offset has wrapped through the end
685 of the address space back to the beginning, giving bogus comparison. */
686 if (addr > name_location + max_symbolic_offset
687 && name_location + max_symbolic_offset > name_location)
dfcd3bfb 688 return 1;
c906108c 689
dfcd3bfb
JM
690 *offset = addr - name_location;
691
692 *name = xstrdup (name_temp);
c906108c 693
c906108c
SS
694 if (print_symbol_filename)
695 {
696 struct symtab_and_line sal;
697
698 sal = find_pc_sect_line (addr, section, 0);
699
700 if (sal.symtab)
dfcd3bfb
JM
701 {
702 *filename = xstrdup (sal.symtab->filename);
703 *line = sal.line;
704 }
c906108c 705 }
dfcd3bfb 706 return 0;
c906108c
SS
707}
708
c906108c
SS
709
710/* Print address ADDR symbolically on STREAM.
711 First print it as a number. Then perhaps print
712 <SYMBOL + OFFSET> after the number. */
713
714void
fba45db2 715print_address (CORE_ADDR addr, struct ui_file *stream)
c906108c 716{
ed49a04f 717 fputs_filtered (paddress (addr), stream);
c906108c
SS
718 print_address_symbolic (addr, stream, asm_demangle, " ");
719}
720
721/* Print address ADDR symbolically on STREAM. Parameter DEMANGLE
722 controls whether to print the symbolic name "raw" or demangled.
723 Global setting "addressprint" controls whether to print hex address
724 or not. */
725
726void
675dcf4f
MK
727print_address_demangle (CORE_ADDR addr, struct ui_file *stream,
728 int do_demangle)
c906108c 729{
79a45b7d
TT
730 struct value_print_options opts;
731 get_user_print_options (&opts);
c906108c
SS
732 if (addr == 0)
733 {
734 fprintf_filtered (stream, "0");
735 }
79a45b7d 736 else if (opts.addressprint)
c906108c 737 {
ed49a04f 738 fputs_filtered (paddress (addr), stream);
c906108c
SS
739 print_address_symbolic (addr, stream, do_demangle, " ");
740 }
741 else
742 {
743 print_address_symbolic (addr, stream, do_demangle, "");
744 }
745}
746\f
747
748/* These are the types that $__ will get after an examine command of one
749 of these sizes. */
750
751static struct type *examine_i_type;
752
753static struct type *examine_b_type;
754static struct type *examine_h_type;
755static struct type *examine_w_type;
756static struct type *examine_g_type;
757
758/* Examine data at address ADDR in format FMT.
759 Fetch it from memory and print on gdb_stdout. */
760
761static void
00a4c844 762do_examine (struct format_data fmt, CORE_ADDR addr)
c906108c 763{
52f0bd74
AC
764 char format = 0;
765 char size;
766 int count = 1;
c906108c 767 struct type *val_type = NULL;
52f0bd74
AC
768 int i;
769 int maxelts;
79a45b7d 770 struct value_print_options opts;
c906108c
SS
771
772 format = fmt.format;
773 size = fmt.size;
774 count = fmt.count;
775 next_address = addr;
c906108c
SS
776
777 /* String or instruction format implies fetch single bytes
778 regardless of the specified size. */
779 if (format == 's' || format == 'i')
780 size = 'b';
781
782 if (format == 'i')
783 val_type = examine_i_type;
784 else if (size == 'b')
785 val_type = examine_b_type;
786 else if (size == 'h')
787 val_type = examine_h_type;
788 else if (size == 'w')
789 val_type = examine_w_type;
790 else if (size == 'g')
791 val_type = examine_g_type;
792
793 maxelts = 8;
794 if (size == 'w')
795 maxelts = 4;
796 if (size == 'g')
797 maxelts = 2;
798 if (format == 's' || format == 'i')
799 maxelts = 1;
800
79a45b7d
TT
801 get_formatted_print_options (&opts, format);
802
c906108c
SS
803 /* Print as many objects as specified in COUNT, at most maxelts per line,
804 with the address of the next one at the start of each line. */
805
806 while (count > 0)
807 {
808 QUIT;
809 print_address (next_address, gdb_stdout);
810 printf_filtered (":");
811 for (i = maxelts;
812 i > 0 && count > 0;
813 i--, count--)
814 {
815 printf_filtered ("\t");
816 /* Note that print_formatted sets next_address for the next
817 object. */
818 last_examine_address = next_address;
819
820 if (last_examine_value)
821 value_free (last_examine_value);
822
823 /* The value to be displayed is not fetched greedily.
5d51a2db
MR
824 Instead, to avoid the possibility of a fetched value not
825 being used, its retrieval is delayed until the print code
c5aa993b
JM
826 uses it. When examining an instruction stream, the
827 disassembler will perform its own memory fetch using just
828 the address stored in LAST_EXAMINE_VALUE. FIXME: Should
829 the disassembler be modified so that LAST_EXAMINE_VALUE
830 is left with the byte sequence from the last complete
831 instruction fetched from memory? */
00a4c844 832 last_examine_value = value_at_lazy (val_type, next_address);
c906108c
SS
833
834 if (last_examine_value)
835 release_value (last_examine_value);
836
79a45b7d 837 print_formatted (last_examine_value, size, &opts, gdb_stdout);
a4642986
MR
838
839 /* Display any branch delay slots following the final insn. */
840 if (format == 'i' && count == 1)
841 count += branch_delay_insns;
c906108c
SS
842 }
843 printf_filtered ("\n");
844 gdb_flush (gdb_stdout);
845 }
846}
847\f
848static void
fba45db2 849validate_format (struct format_data fmt, char *cmdname)
c906108c
SS
850{
851 if (fmt.size != 0)
8a3fe4f8 852 error (_("Size letters are meaningless in \"%s\" command."), cmdname);
c906108c 853 if (fmt.count != 1)
8a3fe4f8 854 error (_("Item count other than 1 is meaningless in \"%s\" command."),
c906108c 855 cmdname);
ea37ba09 856 if (fmt.format == 'i')
8a3fe4f8 857 error (_("Format letter \"%c\" is meaningless in \"%s\" command."),
c906108c
SS
858 fmt.format, cmdname);
859}
860
675dcf4f 861/* Evaluate string EXP as an expression in the current language and
c5aa993b 862 print the resulting value. EXP may contain a format specifier as the
675dcf4f 863 first argument ("/x myvar" for example, to print myvar in hex). */
c906108c
SS
864
865static void
fba45db2 866print_command_1 (char *exp, int inspect, int voidprint)
c906108c
SS
867{
868 struct expression *expr;
52f0bd74
AC
869 struct cleanup *old_chain = 0;
870 char format = 0;
3d6d86c6 871 struct value *val;
c906108c
SS
872 struct format_data fmt;
873 int cleanup = 0;
874
c906108c
SS
875 if (exp && *exp == '/')
876 {
877 exp++;
878 fmt = decode_format (&exp, last_format, 0);
879 validate_format (fmt, "print");
880 last_format = format = fmt.format;
881 }
882 else
883 {
884 fmt.count = 1;
885 fmt.format = 0;
886 fmt.size = 0;
a6bac58e 887 fmt.raw = 0;
c906108c
SS
888 }
889
890 if (exp && *exp)
891 {
c906108c
SS
892 struct type *type;
893 expr = parse_expression (exp);
c13c43fd 894 old_chain = make_cleanup (free_current_contents, &expr);
c906108c
SS
895 cleanup = 1;
896 val = evaluate_expression (expr);
c906108c
SS
897 }
898 else
899 val = access_value_history (0);
900
df407dfe
AC
901 if (voidprint || (val && value_type (val) &&
902 TYPE_CODE (value_type (val)) != TYPE_CODE_VOID))
c906108c 903 {
79a45b7d 904 struct value_print_options opts;
c906108c
SS
905 int histindex = record_latest_value (val);
906
907 if (histindex >= 0)
df407dfe 908 annotate_value_history_begin (histindex, value_type (val));
c906108c 909 else
df407dfe 910 annotate_value_begin (value_type (val));
c906108c
SS
911
912 if (inspect)
675dcf4f
MK
913 printf_unfiltered ("\031(gdb-makebuffer \"%s\" %d '(\"",
914 exp, histindex);
c5aa993b
JM
915 else if (histindex >= 0)
916 printf_filtered ("$%d = ", histindex);
c906108c
SS
917
918 if (histindex >= 0)
919 annotate_value_history_value ();
920
79a45b7d
TT
921 get_formatted_print_options (&opts, format);
922 opts.inspect_it = inspect;
a6bac58e 923 opts.raw = fmt.raw;
79a45b7d
TT
924
925 print_formatted (val, fmt.size, &opts, gdb_stdout);
c906108c
SS
926 printf_filtered ("\n");
927
928 if (histindex >= 0)
929 annotate_value_history_end ();
930 else
931 annotate_value_end ();
932
933 if (inspect)
c5aa993b 934 printf_unfiltered ("\") )\030");
c906108c
SS
935 }
936
937 if (cleanup)
938 do_cleanups (old_chain);
c906108c
SS
939}
940
c906108c 941static void
fba45db2 942print_command (char *exp, int from_tty)
c906108c
SS
943{
944 print_command_1 (exp, 0, 1);
945}
946
675dcf4f 947/* Same as print, except in epoch, it gets its own window. */
c906108c 948static void
fba45db2 949inspect_command (char *exp, int from_tty)
c906108c
SS
950{
951 extern int epoch_interface;
952
953 print_command_1 (exp, epoch_interface, 1);
954}
955
675dcf4f 956/* Same as print, except it doesn't print void results. */
c906108c 957static void
fba45db2 958call_command (char *exp, int from_tty)
c906108c
SS
959{
960 print_command_1 (exp, 0, 0);
961}
962
c906108c 963void
fba45db2 964output_command (char *exp, int from_tty)
c906108c
SS
965{
966 struct expression *expr;
52f0bd74
AC
967 struct cleanup *old_chain;
968 char format = 0;
3d6d86c6 969 struct value *val;
c906108c 970 struct format_data fmt;
79a45b7d 971 struct value_print_options opts;
c906108c 972
777ea8f1 973 fmt.size = 0;
a6bac58e 974 fmt.raw = 0;
777ea8f1 975
c906108c
SS
976 if (exp && *exp == '/')
977 {
978 exp++;
979 fmt = decode_format (&exp, 0, 0);
980 validate_format (fmt, "output");
981 format = fmt.format;
982 }
983
984 expr = parse_expression (exp);
c13c43fd 985 old_chain = make_cleanup (free_current_contents, &expr);
c906108c
SS
986
987 val = evaluate_expression (expr);
988
df407dfe 989 annotate_value_begin (value_type (val));
c906108c 990
79a45b7d 991 get_formatted_print_options (&opts, format);
a6bac58e 992 opts.raw = fmt.raw;
79a45b7d 993 print_formatted (val, fmt.size, &opts, gdb_stdout);
c906108c
SS
994
995 annotate_value_end ();
996
2acceee2
JM
997 wrap_here ("");
998 gdb_flush (gdb_stdout);
999
c906108c
SS
1000 do_cleanups (old_chain);
1001}
1002
c906108c 1003static void
fba45db2 1004set_command (char *exp, int from_tty)
c906108c
SS
1005{
1006 struct expression *expr = parse_expression (exp);
52f0bd74 1007 struct cleanup *old_chain =
c13c43fd 1008 make_cleanup (free_current_contents, &expr);
c906108c
SS
1009 evaluate_expression (expr);
1010 do_cleanups (old_chain);
1011}
1012
c906108c 1013static void
fba45db2 1014sym_info (char *arg, int from_tty)
c906108c
SS
1015{
1016 struct minimal_symbol *msymbol;
c5aa993b
JM
1017 struct objfile *objfile;
1018 struct obj_section *osect;
c5aa993b
JM
1019 CORE_ADDR addr, sect_addr;
1020 int matches = 0;
1021 unsigned int offset;
c906108c
SS
1022
1023 if (!arg)
e2e0b3e5 1024 error_no_arg (_("address"));
c906108c
SS
1025
1026 addr = parse_and_eval_address (arg);
1027 ALL_OBJSECTIONS (objfile, osect)
c5aa993b 1028 {
94277a38
DJ
1029 /* Only process each object file once, even if there's a separate
1030 debug file. */
1031 if (objfile->separate_debug_objfile_backlink)
1032 continue;
1033
714835d5 1034 sect_addr = overlay_mapped_address (addr, osect);
c906108c 1035
f1f6aadf
PA
1036 if (obj_section_addr (osect) <= sect_addr
1037 && sect_addr < obj_section_endaddr (osect)
714835d5 1038 && (msymbol = lookup_minimal_symbol_by_pc_section (sect_addr, osect)))
c5aa993b 1039 {
c14c28ba 1040 const char *obj_name, *mapped, *sec_name, *msym_name;
e2fd701e
DE
1041 char *loc_string;
1042 struct cleanup *old_chain;
c14c28ba 1043
c5aa993b
JM
1044 matches = 1;
1045 offset = sect_addr - SYMBOL_VALUE_ADDRESS (msymbol);
c14c28ba
PP
1046 mapped = section_is_mapped (osect) ? _("mapped") : _("unmapped");
1047 sec_name = osect->the_bfd_section->name;
1048 msym_name = SYMBOL_PRINT_NAME (msymbol);
1049
e2fd701e
DE
1050 /* Don't print the offset if it is zero.
1051 We assume there's no need to handle i18n of "sym + offset". */
1052 if (offset)
549ba0f8 1053 loc_string = xstrprintf ("%s + %u", msym_name, offset);
e2fd701e 1054 else
549ba0f8 1055 loc_string = xstrprintf ("%s", msym_name);
e2fd701e
DE
1056
1057 /* Use a cleanup to free loc_string in case the user quits
1058 a pagination request inside printf_filtered. */
1059 old_chain = make_cleanup (xfree, loc_string);
1060
c14c28ba
PP
1061 gdb_assert (osect->objfile && osect->objfile->name);
1062 obj_name = osect->objfile->name;
1063
1064 if (MULTI_OBJFILE_P ())
1065 if (pc_in_unmapped_range (addr, osect))
1066 if (section_is_overlay (osect))
e2fd701e 1067 printf_filtered (_("%s in load address range of "
c14c28ba 1068 "%s overlay section %s of %s\n"),
e2fd701e 1069 loc_string, mapped, sec_name, obj_name);
c14c28ba 1070 else
e2fd701e 1071 printf_filtered (_("%s in load address range of "
c14c28ba 1072 "section %s of %s\n"),
e2fd701e 1073 loc_string, sec_name, obj_name);
c14c28ba
PP
1074 else
1075 if (section_is_overlay (osect))
e2fd701e
DE
1076 printf_filtered (_("%s in %s overlay section %s of %s\n"),
1077 loc_string, mapped, sec_name, obj_name);
c14c28ba 1078 else
e2fd701e
DE
1079 printf_filtered (_("%s in section %s of %s\n"),
1080 loc_string, sec_name, obj_name);
c5aa993b 1081 else
c14c28ba
PP
1082 if (pc_in_unmapped_range (addr, osect))
1083 if (section_is_overlay (osect))
e2fd701e 1084 printf_filtered (_("%s in load address range of %s overlay "
c14c28ba 1085 "section %s\n"),
e2fd701e 1086 loc_string, mapped, sec_name);
c14c28ba 1087 else
e2fd701e
DE
1088 printf_filtered (_("%s in load address range of section %s\n"),
1089 loc_string, sec_name);
c14c28ba
PP
1090 else
1091 if (section_is_overlay (osect))
e2fd701e
DE
1092 printf_filtered (_("%s in %s overlay section %s\n"),
1093 loc_string, mapped, sec_name);
c14c28ba 1094 else
e2fd701e
DE
1095 printf_filtered (_("%s in section %s\n"),
1096 loc_string, sec_name);
1097
1098 do_cleanups (old_chain);
c5aa993b
JM
1099 }
1100 }
c906108c 1101 if (matches == 0)
a3f17187 1102 printf_filtered (_("No symbol matches %s.\n"), arg);
c906108c
SS
1103}
1104
c906108c 1105static void
fba45db2 1106address_info (char *exp, int from_tty)
c906108c 1107{
768a979c
UW
1108 struct gdbarch *gdbarch;
1109 int regno;
52f0bd74
AC
1110 struct symbol *sym;
1111 struct minimal_symbol *msymbol;
1112 long val;
714835d5 1113 struct obj_section *section;
c906108c
SS
1114 CORE_ADDR load_addr;
1115 int is_a_field_of_this; /* C++: lookup_symbol sets this to nonzero
1116 if exp is a field of `this'. */
1117
1118 if (exp == 0)
8a3fe4f8 1119 error (_("Argument required."));
c906108c 1120
176620f1 1121 sym = lookup_symbol (exp, get_selected_block (0), VAR_DOMAIN,
2570f2b7 1122 &is_a_field_of_this);
c906108c
SS
1123 if (sym == NULL)
1124 {
1125 if (is_a_field_of_this)
1126 {
1127 printf_filtered ("Symbol \"");
1128 fprintf_symbol_filtered (gdb_stdout, exp,
1129 current_language->la_language, DMGL_ANSI);
e2b23ee9
AF
1130 printf_filtered ("\" is a field of the local class variable ");
1131 if (current_language->la_language == language_objc)
2625d86c 1132 printf_filtered ("`self'\n"); /* ObjC equivalent of "this" */
e2b23ee9 1133 else
2625d86c 1134 printf_filtered ("`this'\n");
c906108c
SS
1135 return;
1136 }
1137
1138 msymbol = lookup_minimal_symbol (exp, NULL, NULL);
1139
1140 if (msymbol != NULL)
1141 {
1142 load_addr = SYMBOL_VALUE_ADDRESS (msymbol);
1143
1144 printf_filtered ("Symbol \"");
1145 fprintf_symbol_filtered (gdb_stdout, exp,
1146 current_language->la_language, DMGL_ANSI);
1147 printf_filtered ("\" is at ");
ed49a04f 1148 fputs_filtered (paddress (load_addr), gdb_stdout);
c906108c 1149 printf_filtered (" in a file compiled without debugging");
714835d5 1150 section = SYMBOL_OBJ_SECTION (msymbol);
c906108c
SS
1151 if (section_is_overlay (section))
1152 {
1153 load_addr = overlay_unmapped_address (load_addr, section);
1154 printf_filtered (",\n -- loaded at ");
ed49a04f 1155 fputs_filtered (paddress (load_addr), gdb_stdout);
714835d5
UW
1156 printf_filtered (" in overlay section %s",
1157 section->the_bfd_section->name);
c906108c
SS
1158 }
1159 printf_filtered (".\n");
1160 }
1161 else
8a3fe4f8 1162 error (_("No symbol \"%s\" in current context."), exp);
c906108c
SS
1163 return;
1164 }
1165
1166 printf_filtered ("Symbol \"");
3567439c 1167 fprintf_symbol_filtered (gdb_stdout, SYMBOL_PRINT_NAME (sym),
c906108c
SS
1168 current_language->la_language, DMGL_ANSI);
1169 printf_filtered ("\" is ");
c5aa993b 1170 val = SYMBOL_VALUE (sym);
714835d5 1171 section = SYMBOL_OBJ_SECTION (sym);
768a979c 1172 gdbarch = get_objfile_arch (SYMBOL_SYMTAB (sym)->objfile);
c906108c
SS
1173
1174 switch (SYMBOL_CLASS (sym))
1175 {
1176 case LOC_CONST:
1177 case LOC_CONST_BYTES:
1178 printf_filtered ("constant");
1179 break;
1180
1181 case LOC_LABEL:
1182 printf_filtered ("a label at address ");
ed49a04f
MD
1183 fputs_filtered (paddress (load_addr = SYMBOL_VALUE_ADDRESS (sym)),
1184 gdb_stdout);
c906108c
SS
1185 if (section_is_overlay (section))
1186 {
1187 load_addr = overlay_unmapped_address (load_addr, section);
1188 printf_filtered (",\n -- loaded at ");
ed49a04f 1189 fputs_filtered (paddress (load_addr), gdb_stdout);
714835d5
UW
1190 printf_filtered (" in overlay section %s",
1191 section->the_bfd_section->name);
c906108c
SS
1192 }
1193 break;
1194
4c2df51b 1195 case LOC_COMPUTED:
a67af2b9 1196 /* FIXME: cagney/2004-01-26: It should be possible to
768a979c 1197 unconditionally call the SYMBOL_COMPUTED_OPS method when available.
d3efc286 1198 Unfortunately DWARF 2 stores the frame-base (instead of the
a67af2b9
AC
1199 function) location in a function's symbol. Oops! For the
1200 moment enable this when/where applicable. */
768a979c 1201 SYMBOL_COMPUTED_OPS (sym)->describe_location (sym, gdb_stdout);
4c2df51b
DJ
1202 break;
1203
c906108c 1204 case LOC_REGISTER:
768a979c
UW
1205 /* GDBARCH is the architecture associated with the objfile the symbol
1206 is defined in; the target architecture may be different, and may
1207 provide additional registers. However, we do not know the target
1208 architecture at this point. We assume the objfile architecture
1209 will contain all the standard registers that occur in debug info
1210 in that objfile. */
1211 regno = SYMBOL_REGISTER_OPS (sym)->register_number (sym, gdbarch);
1212
2a2d4dc3
AS
1213 if (SYMBOL_IS_ARGUMENT (sym))
1214 printf_filtered (_("an argument in register %s"),
768a979c 1215 gdbarch_register_name (gdbarch, regno));
2a2d4dc3
AS
1216 else
1217 printf_filtered (_("a variable in register %s"),
768a979c 1218 gdbarch_register_name (gdbarch, regno));
c906108c
SS
1219 break;
1220
1221 case LOC_STATIC:
a3f17187 1222 printf_filtered (_("static storage at address "));
ed49a04f
MD
1223 fputs_filtered (paddress (load_addr = SYMBOL_VALUE_ADDRESS (sym)),
1224 gdb_stdout);
c906108c
SS
1225 if (section_is_overlay (section))
1226 {
1227 load_addr = overlay_unmapped_address (load_addr, section);
a3f17187 1228 printf_filtered (_(",\n -- loaded at "));
ed49a04f 1229 fputs_filtered (paddress (load_addr), gdb_stdout);
714835d5
UW
1230 printf_filtered (_(" in overlay section %s"),
1231 section->the_bfd_section->name);
c906108c
SS
1232 }
1233 break;
1234
c906108c 1235 case LOC_REGPARM_ADDR:
768a979c
UW
1236 /* Note comment at LOC_REGISTER. */
1237 regno = SYMBOL_REGISTER_OPS (sym)->register_number (sym, gdbarch);
675dcf4f 1238 printf_filtered (_("address of an argument in register %s"),
768a979c 1239 gdbarch_register_name (gdbarch, regno));
c906108c
SS
1240 break;
1241
1242 case LOC_ARG:
a3f17187 1243 printf_filtered (_("an argument at offset %ld"), val);
c906108c
SS
1244 break;
1245
c906108c 1246 case LOC_LOCAL:
a3f17187 1247 printf_filtered (_("a local variable at frame offset %ld"), val);
c906108c
SS
1248 break;
1249
1250 case LOC_REF_ARG:
a3f17187 1251 printf_filtered (_("a reference argument at offset %ld"), val);
c906108c
SS
1252 break;
1253
c906108c 1254 case LOC_TYPEDEF:
a3f17187 1255 printf_filtered (_("a typedef"));
c906108c
SS
1256 break;
1257
1258 case LOC_BLOCK:
a3f17187 1259 printf_filtered (_("a function at address "));
675dcf4f 1260 load_addr = BLOCK_START (SYMBOL_BLOCK_VALUE (sym));
ed49a04f 1261 fputs_filtered (paddress (load_addr), gdb_stdout);
c906108c
SS
1262 if (section_is_overlay (section))
1263 {
1264 load_addr = overlay_unmapped_address (load_addr, section);
a3f17187 1265 printf_filtered (_(",\n -- loaded at "));
ed49a04f 1266 fputs_filtered (paddress (load_addr), gdb_stdout);
714835d5
UW
1267 printf_filtered (_(" in overlay section %s"),
1268 section->the_bfd_section->name);
c906108c
SS
1269 }
1270 break;
1271
1272 case LOC_UNRESOLVED:
1273 {
1274 struct minimal_symbol *msym;
1275
3567439c 1276 msym = lookup_minimal_symbol (SYMBOL_LINKAGE_NAME (sym), NULL, NULL);
c906108c
SS
1277 if (msym == NULL)
1278 printf_filtered ("unresolved");
1279 else
1280 {
714835d5 1281 section = SYMBOL_OBJ_SECTION (msym);
675dcf4f 1282 load_addr = SYMBOL_VALUE_ADDRESS (msym);
e0740f77
JK
1283
1284 if (section
1285 && (section->the_bfd_section->flags & SEC_THREAD_LOCAL) != 0)
1286 printf_filtered (_("a thread-local variable at offset %s "
1287 "in the thread-local storage for `%s'"),
1288 paddr_nz (load_addr), section->objfile->name);
1289 else
c906108c 1290 {
e0740f77 1291 printf_filtered (_("static storage at address "));
ed49a04f 1292 fputs_filtered (paddress (load_addr), gdb_stdout);
e0740f77
JK
1293 if (section_is_overlay (section))
1294 {
1295 load_addr = overlay_unmapped_address (load_addr, section);
1296 printf_filtered (_(",\n -- loaded at "));
1297 fputs_filtered (paddress (load_addr), gdb_stdout);
1298 printf_filtered (_(" in overlay section %s"),
1299 section->the_bfd_section->name);
1300 }
c906108c
SS
1301 }
1302 }
1303 }
1304 break;
1305
c906108c 1306 case LOC_OPTIMIZED_OUT:
a3f17187 1307 printf_filtered (_("optimized out"));
c906108c 1308 break;
c5aa993b 1309
c906108c 1310 default:
a3f17187 1311 printf_filtered (_("of unknown (botched) type"));
c906108c
SS
1312 break;
1313 }
1314 printf_filtered (".\n");
1315}
1316\f
675dcf4f
MK
1317
1318static void
fba45db2 1319x_command (char *exp, int from_tty)
c906108c
SS
1320{
1321 struct expression *expr;
1322 struct format_data fmt;
1323 struct cleanup *old_chain;
1324 struct value *val;
1325
a6bac58e 1326 fmt.format = last_format ? last_format : 'x';
c906108c
SS
1327 fmt.size = last_size;
1328 fmt.count = 1;
a6bac58e 1329 fmt.raw = 0;
c906108c
SS
1330
1331 if (exp && *exp == '/')
1332 {
1333 exp++;
1334 fmt = decode_format (&exp, last_format, last_size);
1335 }
1336
1337 /* If we have an expression, evaluate it and use it as the address. */
1338
1339 if (exp != 0 && *exp != 0)
1340 {
1341 expr = parse_expression (exp);
675dcf4f
MK
1342 /* Cause expression not to be there any more if this command is
1343 repeated with Newline. But don't clobber a user-defined
1344 command's definition. */
c906108c
SS
1345 if (from_tty)
1346 *exp = 0;
c13c43fd 1347 old_chain = make_cleanup (free_current_contents, &expr);
c906108c 1348 val = evaluate_expression (expr);
df407dfe 1349 if (TYPE_CODE (value_type (val)) == TYPE_CODE_REF)
c906108c
SS
1350 val = value_ind (val);
1351 /* In rvalue contexts, such as this, functions are coerced into
c5aa993b 1352 pointers to functions. This makes "x/i main" work. */
c0d8fd9a 1353 if (/* last_format == 'i' && */
df407dfe 1354 TYPE_CODE (value_type (val)) == TYPE_CODE_FUNC
c5aa993b 1355 && VALUE_LVAL (val) == lval_memory)
42ae5230 1356 next_address = value_address (val);
c906108c 1357 else
1aa20aa8 1358 next_address = value_as_address (val);
c906108c
SS
1359 do_cleanups (old_chain);
1360 }
1361
00a4c844 1362 do_examine (fmt, next_address);
c906108c 1363
675dcf4f
MK
1364 /* If the examine succeeds, we remember its size and format for next
1365 time. */
c906108c
SS
1366 last_size = fmt.size;
1367 last_format = fmt.format;
1368
1369 /* Set a couple of internal variables if appropriate. */
1370 if (last_examine_value)
1371 {
1372 /* Make last address examined available to the user as $_. Use
c5aa993b 1373 the correct pointer type. */
4478b372 1374 struct type *pointer_type
df407dfe 1375 = lookup_pointer_type (value_type (last_examine_value));
c906108c 1376 set_internalvar (lookup_internalvar ("_"),
4478b372
JB
1377 value_from_pointer (pointer_type,
1378 last_examine_address));
c5aa993b 1379
675dcf4f
MK
1380 /* Make contents of last address examined available to the user
1381 as $__. If the last value has not been fetched from memory
1382 then don't fetch it now; instead mark it by voiding the $__
1383 variable. */
d69fe07e 1384 if (value_lazy (last_examine_value))
4fa62494 1385 clear_internalvar (lookup_internalvar ("__"));
c906108c
SS
1386 else
1387 set_internalvar (lookup_internalvar ("__"), last_examine_value);
1388 }
1389}
c906108c 1390\f
c5aa993b 1391
c906108c
SS
1392/* Add an expression to the auto-display chain.
1393 Specify the expression. */
1394
1395static void
fba45db2 1396display_command (char *exp, int from_tty)
c906108c
SS
1397{
1398 struct format_data fmt;
52f0bd74
AC
1399 struct expression *expr;
1400 struct display *new;
c906108c
SS
1401 int display_it = 1;
1402
1403#if defined(TUI)
021e7609
AC
1404 /* NOTE: cagney/2003-02-13 The `tui_active' was previously
1405 `tui_version'. */
fd33e6cb 1406 if (tui_active && exp != NULL && *exp == '$')
080ce8c0 1407 display_it = (tui_set_layout_for_display_command (exp) == TUI_FAILURE);
c906108c
SS
1408#endif
1409
1410 if (display_it)
1411 {
1412 if (exp == 0)
1413 {
1414 do_displays ();
1415 return;
1416 }
1417
1418 if (*exp == '/')
1419 {
1420 exp++;
1421 fmt = decode_format (&exp, 0, 0);
1422 if (fmt.size && fmt.format == 0)
1423 fmt.format = 'x';
1424 if (fmt.format == 'i' || fmt.format == 's')
1425 fmt.size = 'b';
1426 }
1427 else
1428 {
1429 fmt.format = 0;
1430 fmt.size = 0;
1431 fmt.count = 0;
a6bac58e 1432 fmt.raw = 0;
c906108c
SS
1433 }
1434
a3247a22 1435 innermost_block = NULL;
c906108c
SS
1436 expr = parse_expression (exp);
1437
1438 new = (struct display *) xmalloc (sizeof (struct display));
1439
fa8a61dc 1440 new->exp_string = xstrdup (exp);
c906108c
SS
1441 new->exp = expr;
1442 new->block = innermost_block;
1443 new->next = display_chain;
1444 new->number = ++display_number;
1445 new->format = fmt;
b5de0fa7 1446 new->enabled_p = 1;
c906108c
SS
1447 display_chain = new;
1448
1449 if (from_tty && target_has_execution)
1450 do_one_display (new);
1451
1452 dont_repeat ();
1453 }
1454}
1455
1456static void
fba45db2 1457free_display (struct display *d)
c906108c 1458{
fa8a61dc 1459 xfree (d->exp_string);
b8c9b27d
KB
1460 xfree (d->exp);
1461 xfree (d);
c906108c
SS
1462}
1463
675dcf4f
MK
1464/* Clear out the display_chain. Done when new symtabs are loaded,
1465 since this invalidates the types stored in many expressions. */
c906108c
SS
1466
1467void
fba45db2 1468clear_displays (void)
c906108c 1469{
52f0bd74 1470 struct display *d;
c906108c
SS
1471
1472 while ((d = display_chain) != NULL)
1473 {
c906108c 1474 display_chain = d->next;
fa8a61dc 1475 free_display (d);
c906108c
SS
1476 }
1477}
1478
1479/* Delete the auto-display number NUM. */
1480
1481static void
fba45db2 1482delete_display (int num)
c906108c 1483{
52f0bd74 1484 struct display *d1, *d;
c906108c
SS
1485
1486 if (!display_chain)
8a3fe4f8 1487 error (_("No display number %d."), num);
c906108c
SS
1488
1489 if (display_chain->number == num)
1490 {
1491 d1 = display_chain;
1492 display_chain = d1->next;
1493 free_display (d1);
1494 }
1495 else
c5aa993b 1496 for (d = display_chain;; d = d->next)
c906108c
SS
1497 {
1498 if (d->next == 0)
8a3fe4f8 1499 error (_("No display number %d."), num);
c906108c
SS
1500 if (d->next->number == num)
1501 {
1502 d1 = d->next;
1503 d->next = d1->next;
1504 free_display (d1);
1505 break;
1506 }
1507 }
1508}
1509
1510/* Delete some values from the auto-display chain.
1511 Specify the element numbers. */
1512
1513static void
fba45db2 1514undisplay_command (char *args, int from_tty)
c906108c 1515{
52f0bd74
AC
1516 char *p = args;
1517 char *p1;
1518 int num;
c906108c
SS
1519
1520 if (args == 0)
1521 {
9e2f0ad4 1522 if (query (_("Delete all auto-display expressions? ")))
c906108c
SS
1523 clear_displays ();
1524 dont_repeat ();
1525 return;
1526 }
1527
1528 while (*p)
1529 {
1530 p1 = p;
c5aa993b
JM
1531 while (*p1 >= '0' && *p1 <= '9')
1532 p1++;
c906108c 1533 if (*p1 && *p1 != ' ' && *p1 != '\t')
8a3fe4f8 1534 error (_("Arguments must be display numbers."));
c906108c
SS
1535
1536 num = atoi (p);
1537
1538 delete_display (num);
1539
1540 p = p1;
c5aa993b
JM
1541 while (*p == ' ' || *p == '\t')
1542 p++;
c906108c
SS
1543 }
1544 dont_repeat ();
1545}
1546
1547/* Display a single auto-display.
1548 Do nothing if the display cannot be printed in the current context,
1549 or if the display is disabled. */
1550
1551static void
fba45db2 1552do_one_display (struct display *d)
c906108c
SS
1553{
1554 int within_current_scope;
1555
b5de0fa7 1556 if (d->enabled_p == 0)
c906108c
SS
1557 return;
1558
a3247a22
PP
1559 if (d->exp == NULL)
1560 {
1561 volatile struct gdb_exception ex;
1562 TRY_CATCH (ex, RETURN_MASK_ALL)
1563 {
1564 innermost_block = NULL;
1565 d->exp = parse_expression (d->exp_string);
1566 d->block = innermost_block;
1567 }
1568 if (ex.reason < 0)
1569 {
1570 /* Can't re-parse the expression. Disable this display item. */
1571 d->enabled_p = 0;
1572 warning (_("Unable to display \"%s\": %s"),
1573 d->exp_string, ex.message);
1574 return;
1575 }
1576 }
1577
c906108c 1578 if (d->block)
ae767bfb 1579 within_current_scope = contained_in (get_selected_block (0), d->block);
c906108c
SS
1580 else
1581 within_current_scope = 1;
1582 if (!within_current_scope)
1583 return;
1584
1585 current_display_number = d->number;
1586
1587 annotate_display_begin ();
1588 printf_filtered ("%d", d->number);
1589 annotate_display_number_end ();
1590 printf_filtered (": ");
1591 if (d->format.size)
1592 {
1593 CORE_ADDR addr;
3d6d86c6 1594 struct value *val;
c906108c
SS
1595
1596 annotate_display_format ();
1597
1598 printf_filtered ("x/");
1599 if (d->format.count != 1)
1600 printf_filtered ("%d", d->format.count);
1601 printf_filtered ("%c", d->format.format);
1602 if (d->format.format != 'i' && d->format.format != 's')
1603 printf_filtered ("%c", d->format.size);
1604 printf_filtered (" ");
1605
1606 annotate_display_expression ();
1607
fa8a61dc 1608 puts_filtered (d->exp_string);
c906108c
SS
1609 annotate_display_expression_end ();
1610
6a2eb474 1611 if (d->format.count != 1 || d->format.format == 'i')
c906108c
SS
1612 printf_filtered ("\n");
1613 else
1614 printf_filtered (" ");
c5aa993b 1615
c906108c 1616 val = evaluate_expression (d->exp);
1aa20aa8 1617 addr = value_as_address (val);
c906108c 1618 if (d->format.format == 'i')
d80b854b 1619 addr = gdbarch_addr_bits_remove (d->exp->gdbarch, addr);
c906108c
SS
1620
1621 annotate_display_value ();
1622
00a4c844 1623 do_examine (d->format, addr);
c906108c
SS
1624 }
1625 else
1626 {
79a45b7d
TT
1627 struct value_print_options opts;
1628
c906108c
SS
1629 annotate_display_format ();
1630
1631 if (d->format.format)
1632 printf_filtered ("/%c ", d->format.format);
1633
1634 annotate_display_expression ();
1635
fa8a61dc 1636 puts_filtered (d->exp_string);
c906108c
SS
1637 annotate_display_expression_end ();
1638
1639 printf_filtered (" = ");
1640
1641 annotate_display_expression ();
1642
79a45b7d 1643 get_formatted_print_options (&opts, d->format.format);
a6bac58e 1644 opts.raw = d->format.raw;
c906108c 1645 print_formatted (evaluate_expression (d->exp),
79a45b7d 1646 d->format.size, &opts, gdb_stdout);
c906108c
SS
1647 printf_filtered ("\n");
1648 }
1649
1650 annotate_display_end ();
1651
1652 gdb_flush (gdb_stdout);
1653 current_display_number = -1;
1654}
1655
1656/* Display all of the values on the auto-display chain which can be
1657 evaluated in the current scope. */
1658
1659void
fba45db2 1660do_displays (void)
c906108c 1661{
52f0bd74 1662 struct display *d;
c906108c
SS
1663
1664 for (d = display_chain; d; d = d->next)
1665 do_one_display (d);
1666}
1667
1668/* Delete the auto-display which we were in the process of displaying.
1669 This is done when there is an error or a signal. */
1670
1671void
fba45db2 1672disable_display (int num)
c906108c 1673{
52f0bd74 1674 struct display *d;
c906108c
SS
1675
1676 for (d = display_chain; d; d = d->next)
1677 if (d->number == num)
1678 {
b5de0fa7 1679 d->enabled_p = 0;
c906108c
SS
1680 return;
1681 }
a3f17187 1682 printf_unfiltered (_("No display number %d.\n"), num);
c906108c 1683}
c5aa993b 1684
c906108c 1685void
fba45db2 1686disable_current_display (void)
c906108c
SS
1687{
1688 if (current_display_number >= 0)
1689 {
1690 disable_display (current_display_number);
675dcf4f
MK
1691 fprintf_unfiltered (gdb_stderr, _("\
1692Disabling display %d to avoid infinite recursion.\n"),
c5aa993b 1693 current_display_number);
c906108c
SS
1694 }
1695 current_display_number = -1;
1696}
1697
1698static void
fba45db2 1699display_info (char *ignore, int from_tty)
c906108c 1700{
52f0bd74 1701 struct display *d;
c906108c
SS
1702
1703 if (!display_chain)
a3f17187 1704 printf_unfiltered (_("There are no auto-display expressions now.\n"));
c906108c 1705 else
a3f17187
AC
1706 printf_filtered (_("Auto-display expressions now in effect:\n\
1707Num Enb Expression\n"));
c906108c
SS
1708
1709 for (d = display_chain; d; d = d->next)
1710 {
b5de0fa7 1711 printf_filtered ("%d: %c ", d->number, "ny"[(int) d->enabled_p]);
c906108c
SS
1712 if (d->format.size)
1713 printf_filtered ("/%d%c%c ", d->format.count, d->format.size,
c5aa993b 1714 d->format.format);
c906108c
SS
1715 else if (d->format.format)
1716 printf_filtered ("/%c ", d->format.format);
fa8a61dc 1717 puts_filtered (d->exp_string);
ae767bfb 1718 if (d->block && !contained_in (get_selected_block (0), d->block))
a3f17187 1719 printf_filtered (_(" (cannot be evaluated in the current context)"));
c906108c
SS
1720 printf_filtered ("\n");
1721 gdb_flush (gdb_stdout);
1722 }
1723}
1724
1725static void
fba45db2 1726enable_display (char *args, int from_tty)
c906108c 1727{
52f0bd74
AC
1728 char *p = args;
1729 char *p1;
1730 int num;
1731 struct display *d;
c906108c
SS
1732
1733 if (p == 0)
1734 {
1735 for (d = display_chain; d; d = d->next)
b5de0fa7 1736 d->enabled_p = 1;
c906108c
SS
1737 }
1738 else
1739 while (*p)
1740 {
1741 p1 = p;
1742 while (*p1 >= '0' && *p1 <= '9')
1743 p1++;
1744 if (*p1 && *p1 != ' ' && *p1 != '\t')
8a3fe4f8 1745 error (_("Arguments must be display numbers."));
c5aa993b 1746
c906108c 1747 num = atoi (p);
c5aa993b 1748
c906108c
SS
1749 for (d = display_chain; d; d = d->next)
1750 if (d->number == num)
1751 {
b5de0fa7 1752 d->enabled_p = 1;
c906108c
SS
1753 goto win;
1754 }
a3f17187 1755 printf_unfiltered (_("No display number %d.\n"), num);
c906108c
SS
1756 win:
1757 p = p1;
1758 while (*p == ' ' || *p == '\t')
1759 p++;
1760 }
1761}
1762
c906108c 1763static void
fba45db2 1764disable_display_command (char *args, int from_tty)
c906108c 1765{
52f0bd74
AC
1766 char *p = args;
1767 char *p1;
1768 struct display *d;
c906108c
SS
1769
1770 if (p == 0)
1771 {
1772 for (d = display_chain; d; d = d->next)
b5de0fa7 1773 d->enabled_p = 0;
c906108c
SS
1774 }
1775 else
1776 while (*p)
1777 {
1778 p1 = p;
1779 while (*p1 >= '0' && *p1 <= '9')
1780 p1++;
1781 if (*p1 && *p1 != ' ' && *p1 != '\t')
8a3fe4f8 1782 error (_("Arguments must be display numbers."));
c5aa993b 1783
c906108c
SS
1784 disable_display (atoi (p));
1785
1786 p = p1;
1787 while (*p == ' ' || *p == '\t')
1788 p++;
1789 }
1790}
a3247a22
PP
1791
1792/* Return 1 if D uses SOLIB (and will become dangling when SOLIB
1793 is unloaded), otherwise return 0. */
1794
1795static int
1796display_uses_solib_p (const struct display *d,
1797 const struct so_list *solib)
1798{
36dc683c 1799 int endpos;
a3247a22 1800 struct expression *const exp = d->exp;
36dc683c 1801 const union exp_element *const elts = exp->elts;
a3247a22
PP
1802
1803 if (d->block != NULL
5fd1a349 1804 && solib_contains_address_p (solib, d->block->startaddr))
a3247a22
PP
1805 return 1;
1806
36dc683c 1807 for (endpos = exp->nelts; endpos > 0; )
a3247a22 1808 {
36dc683c
DE
1809 int i, args, oplen = 0;
1810
1811 exp->language_defn->la_exp_desc->operator_length (exp, endpos,
1812 &oplen, &args);
1813 gdb_assert (oplen > 0);
a3247a22 1814
36dc683c 1815 i = endpos - oplen;
a3247a22
PP
1816 if (elts[i].opcode == OP_VAR_VALUE)
1817 {
1818 const struct block *const block = elts[i + 1].block;
1819 const struct symbol *const symbol = elts[i + 2].symbol;
1820 const struct obj_section *const section =
1821 SYMBOL_OBJ_SECTION (symbol);
1822
1823 if (block != NULL
5fd1a349 1824 && solib_contains_address_p (solib, block->startaddr))
a3247a22
PP
1825 return 1;
1826
1827 if (section && section->objfile == solib->objfile)
1828 return 1;
1829 }
36dc683c 1830 endpos -= oplen;
a3247a22 1831 }
36dc683c 1832
a3247a22
PP
1833 return 0;
1834}
1835
1836/* display_chain items point to blocks and expressions. Some expressions in
1837 turn may point to symbols.
1838 Both symbols and blocks are obstack_alloc'd on objfile_stack, and are
1839 obstack_free'd when a shared library is unloaded.
1840 Clear pointers that are about to become dangling.
1841 Both .exp and .block fields will be restored next time we need to display
1842 an item by re-parsing .exp_string field in the new execution context. */
1843
1844static void
1845clear_dangling_display_expressions (struct so_list *solib)
1846{
1847 struct display *d;
1848 struct objfile *objfile = NULL;
1849
1850 for (d = display_chain; d; d = d->next)
1851 {
1852 if (d->exp && display_uses_solib_p (d, solib))
1853 {
1854 xfree (d->exp);
1855 d->exp = NULL;
1856 d->block = NULL;
1857 }
1858 }
1859}
c906108c 1860\f
c5aa993b 1861
675dcf4f 1862/* Print the value in stack frame FRAME of a variable specified by a
aad95b57
TT
1863 struct symbol. NAME is the name to print; if NULL then VAR's print
1864 name will be used. STREAM is the ui_file on which to print the
1865 value. INDENT specifies the number of indent levels to print
1866 before printing the variable name. */
c906108c
SS
1867
1868void
aad95b57
TT
1869print_variable_and_value (const char *name, struct symbol *var,
1870 struct frame_info *frame,
1871 struct ui_file *stream, int indent)
c906108c 1872{
aad95b57 1873 struct value *val;
79a45b7d 1874 struct value_print_options opts;
c906108c 1875
aad95b57
TT
1876 if (!name)
1877 name = SYMBOL_PRINT_NAME (var);
1878
1879 fprintf_filtered (stream, "%s%s = ", n_spaces (2 * indent), name);
1880
1881 val = read_var_value (var, frame);
79a45b7d 1882 get_user_print_options (&opts);
aad95b57
TT
1883 common_val_print (val, stream, indent, &opts, current_language);
1884 fprintf_filtered (stream, "\n");
c906108c
SS
1885}
1886
c906108c 1887static void
fba45db2 1888printf_command (char *arg, int from_tty)
c906108c 1889{
52f0bd74
AC
1890 char *f = NULL;
1891 char *s = arg;
c906108c 1892 char *string = NULL;
3d6d86c6 1893 struct value **val_args;
c906108c
SS
1894 char *substrings;
1895 char *current_substring;
1896 int nargs = 0;
1897 int allocated_args = 20;
1898 struct cleanup *old_cleanups;
1899
675dcf4f 1900 val_args = xmalloc (allocated_args * sizeof (struct value *));
c13c43fd 1901 old_cleanups = make_cleanup (free_current_contents, &val_args);
c906108c
SS
1902
1903 if (s == 0)
e2e0b3e5 1904 error_no_arg (_("format-control string and values to print"));
c906108c
SS
1905
1906 /* Skip white space before format string */
c5aa993b
JM
1907 while (*s == ' ' || *s == '\t')
1908 s++;
c906108c 1909
675dcf4f 1910 /* A format string should follow, enveloped in double quotes. */
c906108c 1911 if (*s++ != '"')
8a3fe4f8 1912 error (_("Bad format string, missing '\"'."));
c906108c
SS
1913
1914 /* Parse the format-control string and copy it into the string STRING,
1915 processing some kinds of escape sequence. */
1916
1917 f = string = (char *) alloca (strlen (s) + 1);
1918
1919 while (*s != '"')
1920 {
1921 int c = *s++;
1922 switch (c)
1923 {
1924 case '\0':
8a3fe4f8 1925 error (_("Bad format string, non-terminated '\"'."));
c906108c
SS
1926
1927 case '\\':
1928 switch (c = *s++)
1929 {
1930 case '\\':
1931 *f++ = '\\';
1932 break;
1933 case 'a':
c906108c 1934 *f++ = '\a';
c906108c
SS
1935 break;
1936 case 'b':
1937 *f++ = '\b';
1938 break;
1939 case 'f':
1940 *f++ = '\f';
1941 break;
1942 case 'n':
1943 *f++ = '\n';
1944 break;
1945 case 'r':
1946 *f++ = '\r';
1947 break;
1948 case 't':
1949 *f++ = '\t';
1950 break;
1951 case 'v':
1952 *f++ = '\v';
1953 break;
1954 case '"':
1955 *f++ = '"';
1956 break;
1957 default:
1958 /* ??? TODO: handle other escape sequences */
8a3fe4f8 1959 error (_("Unrecognized escape character \\%c in format string."),
c906108c
SS
1960 c);
1961 }
1962 break;
1963
1964 default:
1965 *f++ = c;
1966 }
1967 }
1968
1969 /* Skip over " and following space and comma. */
1970 s++;
1971 *f++ = '\0';
c5aa993b
JM
1972 while (*s == ' ' || *s == '\t')
1973 s++;
c906108c
SS
1974
1975 if (*s != ',' && *s != 0)
8a3fe4f8 1976 error (_("Invalid argument syntax"));
c906108c 1977
c5aa993b
JM
1978 if (*s == ',')
1979 s++;
1980 while (*s == ' ' || *s == '\t')
1981 s++;
c906108c
SS
1982
1983 /* Need extra space for the '\0's. Doubling the size is sufficient. */
1984 substrings = alloca (strlen (string) * 2);
1985 current_substring = substrings;
1986
1987 {
1988 /* Now scan the string for %-specs and see what kinds of args they want.
1989 argclass[I] classifies the %-specs so we can give printf_filtered
1990 something of the right size. */
1991
c5aa993b
JM
1992 enum argclass
1993 {
6c7a06a3
TT
1994 int_arg, long_arg, long_long_arg, ptr_arg,
1995 string_arg, wide_string_arg, wide_char_arg,
1a619819 1996 double_arg, long_double_arg, decfloat_arg
c5aa993b 1997 };
c906108c
SS
1998 enum argclass *argclass;
1999 enum argclass this_argclass;
2000 char *last_arg;
2001 int nargs_wanted;
c906108c
SS
2002 int i;
2003
2004 argclass = (enum argclass *) alloca (strlen (s) * sizeof *argclass);
2005 nargs_wanted = 0;
2006 f = string;
2007 last_arg = string;
2008 while (*f)
2009 if (*f++ == '%')
2010 {
46e9880c
DJ
2011 int seen_hash = 0, seen_zero = 0, lcount = 0, seen_prec = 0;
2012 int seen_space = 0, seen_plus = 0;
0aea4bf3
LM
2013 int seen_big_l = 0, seen_h = 0, seen_big_h = 0;
2014 int seen_big_d = 0, seen_double_big_d = 0;
46e9880c
DJ
2015 int bad = 0;
2016
2017 /* Check the validity of the format specifier, and work
2018 out what argument it expects. We only accept C89
2019 format strings, with the exception of long long (which
2020 we autoconf for). */
2021
2022 /* Skip over "%%". */
2023 if (*f == '%')
c906108c 2024 {
c906108c 2025 f++;
46e9880c 2026 continue;
c906108c 2027 }
46e9880c
DJ
2028
2029 /* The first part of a format specifier is a set of flag
2030 characters. */
2031 while (strchr ("0-+ #", *f))
2032 {
2033 if (*f == '#')
2034 seen_hash = 1;
2035 else if (*f == '0')
2036 seen_zero = 1;
2037 else if (*f == ' ')
2038 seen_space = 1;
2039 else if (*f == '+')
2040 seen_plus = 1;
2041 f++;
2042 }
2043
2044 /* The next part of a format specifier is a width. */
2045 while (strchr ("0123456789", *f))
2046 f++;
2047
2048 /* The next part of a format specifier is a precision. */
2049 if (*f == '.')
2050 {
2051 seen_prec = 1;
2052 f++;
2053 while (strchr ("0123456789", *f))
2054 f++;
2055 }
2056
2057 /* The next part of a format specifier is a length modifier. */
2058 if (*f == 'h')
2059 {
2060 seen_h = 1;
2061 f++;
2062 }
2063 else if (*f == 'l')
2064 {
2065 f++;
2066 lcount++;
2067 if (*f == 'l')
2068 {
2069 f++;
2070 lcount++;
2071 }
2072 }
2073 else if (*f == 'L')
2074 {
2075 seen_big_l = 1;
2076 f++;
2077 }
0aea4bf3
LM
2078 /* Decimal32 modifier. */
2079 else if (*f == 'H')
2080 {
2081 seen_big_h = 1;
2082 f++;
2083 }
2084 /* Decimal64 and Decimal128 modifiers. */
2085 else if (*f == 'D')
2086 {
2087 f++;
2088
2089 /* Check for a Decimal128. */
2090 if (*f == 'D')
2091 {
2092 f++;
2093 seen_double_big_d = 1;
2094 }
2095 else
2096 seen_big_d = 1;
2097 }
46e9880c 2098
c906108c
SS
2099 switch (*f)
2100 {
46e9880c
DJ
2101 case 'u':
2102 if (seen_hash)
2103 bad = 1;
2104 /* FALLTHROUGH */
2105
2106 case 'o':
2107 case 'x':
2108 case 'X':
2109 if (seen_space || seen_plus)
2110 bad = 1;
2111 /* FALLTHROUGH */
2112
2113 case 'd':
2114 case 'i':
2115 if (lcount == 0)
2116 this_argclass = int_arg;
2117 else if (lcount == 1)
2118 this_argclass = long_arg;
2119 else
2120 this_argclass = long_long_arg;
2121
2122 if (seen_big_l)
2123 bad = 1;
2124 break;
2125
2126 case 'c':
6c7a06a3
TT
2127 this_argclass = lcount == 0 ? int_arg : wide_char_arg;
2128 if (lcount > 1 || seen_h || seen_big_l)
46e9880c
DJ
2129 bad = 1;
2130 if (seen_prec || seen_zero || seen_space || seen_plus)
2131 bad = 1;
2132 break;
2133
2134 case 'p':
2135 this_argclass = ptr_arg;
2136 if (lcount || seen_h || seen_big_l)
2137 bad = 1;
2138 if (seen_prec || seen_zero || seen_space || seen_plus)
2139 bad = 1;
2140 break;
2141
c906108c 2142 case 's':
6c7a06a3
TT
2143 this_argclass = lcount == 0 ? string_arg : wide_string_arg;
2144 if (lcount > 1 || seen_h || seen_big_l)
46e9880c
DJ
2145 bad = 1;
2146 if (seen_zero || seen_space || seen_plus)
2147 bad = 1;
c906108c
SS
2148 break;
2149
2150 case 'e':
2151 case 'f':
2152 case 'g':
46e9880c
DJ
2153 case 'E':
2154 case 'G':
0aea4bf3
LM
2155 if (seen_big_h || seen_big_d || seen_double_big_d)
2156 this_argclass = decfloat_arg;
2157 else if (seen_big_l)
46e9880c
DJ
2158 this_argclass = long_double_arg;
2159 else
2160 this_argclass = double_arg;
2161
2162 if (lcount || seen_h)
2163 bad = 1;
c906108c
SS
2164 break;
2165
2166 case '*':
8a3fe4f8 2167 error (_("`*' not supported for precision or width in printf"));
c906108c
SS
2168
2169 case 'n':
8a3fe4f8 2170 error (_("Format specifier `n' not supported in printf"));
c906108c 2171
46e9880c
DJ
2172 case '\0':
2173 error (_("Incomplete format specifier at end of format string"));
c906108c
SS
2174
2175 default:
46e9880c 2176 error (_("Unrecognized format specifier '%c' in printf"), *f);
c906108c 2177 }
46e9880c
DJ
2178
2179 if (bad)
2180 error (_("Inappropriate modifiers to format specifier '%c' in printf"),
2181 *f);
2182
c906108c 2183 f++;
09d71d23
AS
2184
2185 if (lcount > 1 && USE_PRINTF_I64)
2186 {
2187 /* Windows' printf does support long long, but not the usual way.
2188 Convert %lld to %I64d. */
2189 int length_before_ll = f - last_arg - 1 - lcount;
2190 strncpy (current_substring, last_arg, length_before_ll);
2191 strcpy (current_substring + length_before_ll, "I64");
2192 current_substring[length_before_ll + 3] =
2193 last_arg[length_before_ll + lcount];
2194 current_substring += length_before_ll + 4;
2195 }
6c7a06a3
TT
2196 else if (this_argclass == wide_string_arg
2197 || this_argclass == wide_char_arg)
2198 {
2199 /* Convert %ls or %lc to %s. */
2200 int length_before_ls = f - last_arg - 2;
2201 strncpy (current_substring, last_arg, length_before_ls);
2202 strcpy (current_substring + length_before_ls, "s");
2203 current_substring += length_before_ls + 2;
2204 }
09d71d23
AS
2205 else
2206 {
2207 strncpy (current_substring, last_arg, f - last_arg);
2208 current_substring += f - last_arg;
2209 }
46e9880c
DJ
2210 *current_substring++ = '\0';
2211 last_arg = f;
2212 argclass[nargs_wanted++] = this_argclass;
c906108c
SS
2213 }
2214
2215 /* Now, parse all arguments and evaluate them.
2216 Store the VALUEs in VAL_ARGS. */
2217
2218 while (*s != '\0')
2219 {
2220 char *s1;
2221 if (nargs == allocated_args)
f976f6d4
AC
2222 val_args = (struct value **) xrealloc ((char *) val_args,
2223 (allocated_args *= 2)
2224 * sizeof (struct value *));
c906108c
SS
2225 s1 = s;
2226 val_args[nargs] = parse_to_comma_and_eval (&s1);
c5aa993b 2227
c906108c
SS
2228 nargs++;
2229 s = s1;
2230 if (*s == ',')
2231 s++;
2232 }
c5aa993b 2233
c906108c 2234 if (nargs != nargs_wanted)
8a3fe4f8 2235 error (_("Wrong number of arguments for specified format-string"));
c906108c
SS
2236
2237 /* Now actually print them. */
2238 current_substring = substrings;
2239 for (i = 0; i < nargs; i++)
2240 {
2241 switch (argclass[i])
2242 {
2243 case string_arg:
2244 {
777ea8f1 2245 gdb_byte *str;
c906108c
SS
2246 CORE_ADDR tem;
2247 int j;
1aa20aa8 2248 tem = value_as_address (val_args[i]);
c906108c
SS
2249
2250 /* This is a %s argument. Find the length of the string. */
c5aa993b 2251 for (j = 0;; j++)
c906108c 2252 {
777ea8f1 2253 gdb_byte c;
c906108c 2254 QUIT;
d4b2399a 2255 read_memory (tem + j, &c, 1);
c906108c
SS
2256 if (c == 0)
2257 break;
2258 }
2259
2260 /* Copy the string contents into a string inside GDB. */
777ea8f1 2261 str = (gdb_byte *) alloca (j + 1);
7b92f6e1
MS
2262 if (j != 0)
2263 read_memory (tem, str, j);
c906108c
SS
2264 str[j] = 0;
2265
777ea8f1 2266 printf_filtered (current_substring, (char *) str);
c906108c
SS
2267 }
2268 break;
6c7a06a3
TT
2269 case wide_string_arg:
2270 {
2271 gdb_byte *str;
2272 CORE_ADDR tem;
2273 int j;
e6c014f2
UW
2274 struct type *wctype = lookup_typename (current_language,
2275 current_gdbarch,
2276 "wchar_t", NULL, 0);
6c7a06a3
TT
2277 int wcwidth = TYPE_LENGTH (wctype);
2278 gdb_byte *buf = alloca (wcwidth);
2279 struct obstack output;
2280 struct cleanup *inner_cleanup;
2281
2282 tem = value_as_address (val_args[i]);
2283
2284 /* This is a %s argument. Find the length of the string. */
2285 for (j = 0;; j += wcwidth)
2286 {
2287 QUIT;
2288 read_memory (tem + j, buf, wcwidth);
2289 if (extract_unsigned_integer (buf, wcwidth) == 0)
2290 break;
2291 }
2292
2293 /* Copy the string contents into a string inside GDB. */
2294 str = (gdb_byte *) alloca (j + wcwidth);
2295 if (j != 0)
2296 read_memory (tem, str, j);
2297 memset (&str[j], 0, wcwidth);
2298
2299 obstack_init (&output);
2300 inner_cleanup = make_cleanup_obstack_free (&output);
2301
2302 convert_between_encodings (target_wide_charset (),
2303 host_charset (),
2304 str, j, wcwidth,
2305 &output, translit_char);
2306 obstack_grow_str0 (&output, "");
2307
2308 printf_filtered (current_substring, obstack_base (&output));
2309 do_cleanups (inner_cleanup);
2310 }
2311 break;
2312 case wide_char_arg:
2313 {
e6c014f2
UW
2314 struct type *wctype = lookup_typename (current_language,
2315 current_gdbarch,
2316 "wchar_t", NULL, 0);
6c7a06a3
TT
2317 struct type *valtype;
2318 struct obstack output;
2319 struct cleanup *inner_cleanup;
2320 const gdb_byte *bytes;
2321
2322 valtype = value_type (val_args[i]);
2323 if (TYPE_LENGTH (valtype) != TYPE_LENGTH (wctype)
2324 || TYPE_CODE (valtype) != TYPE_CODE_INT)
2325 error (_("expected wchar_t argument for %%lc"));
2326
2327 bytes = value_contents (val_args[i]);
2328
2329 obstack_init (&output);
2330 inner_cleanup = make_cleanup_obstack_free (&output);
2331
2332 convert_between_encodings (target_wide_charset (),
2333 host_charset (),
2334 bytes, TYPE_LENGTH (valtype),
2335 TYPE_LENGTH (valtype),
2336 &output, translit_char);
2337 obstack_grow_str0 (&output, "");
2338
2339 printf_filtered (current_substring, obstack_base (&output));
2340 do_cleanups (inner_cleanup);
2341 }
2342 break;
c906108c
SS
2343 case double_arg:
2344 {
b806fb9a
UW
2345 struct type *type = value_type (val_args[i]);
2346 DOUBLEST val;
2347 int inv;
2348
2349 /* If format string wants a float, unchecked-convert the value
2350 to floating point of the same size. */
2351 type = float_type_from_length (current_gdbarch, type);
2352 val = unpack_double (type, value_contents (val_args[i]), &inv);
2353 if (inv)
2354 error (_("Invalid floating value found in program."));
2355
2356 printf_filtered (current_substring, (double) val);
c906108c
SS
2357 break;
2358 }
46e9880c
DJ
2359 case long_double_arg:
2360#ifdef HAVE_LONG_DOUBLE
2361 {
b806fb9a
UW
2362 struct type *type = value_type (val_args[i]);
2363 DOUBLEST val;
2364 int inv;
2365
2366 /* If format string wants a float, unchecked-convert the value
2367 to floating point of the same size. */
2368 type = float_type_from_length (current_gdbarch, type);
2369 val = unpack_double (type, value_contents (val_args[i]), &inv);
2370 if (inv)
2371 error (_("Invalid floating value found in program."));
2372
2373 printf_filtered (current_substring, (long double) val);
46e9880c
DJ
2374 break;
2375 }
2376#else
2377 error (_("long double not supported in printf"));
2378#endif
c906108c
SS
2379 case long_long_arg:
2380#if defined (CC_HAS_LONG_LONG) && defined (PRINTF_HAS_LONG_LONG)
2381 {
2382 long long val = value_as_long (val_args[i]);
2383 printf_filtered (current_substring, val);
2384 break;
2385 }
2386#else
8a3fe4f8 2387 error (_("long long not supported in printf"));
c906108c
SS
2388#endif
2389 case int_arg:
2390 {
46e9880c
DJ
2391 int val = value_as_long (val_args[i]);
2392 printf_filtered (current_substring, val);
2393 break;
2394 }
2395 case long_arg:
2396 {
c906108c
SS
2397 long val = value_as_long (val_args[i]);
2398 printf_filtered (current_substring, val);
2399 break;
2400 }
1a619819 2401
0aea4bf3
LM
2402 /* Handles decimal floating values. */
2403 case decfloat_arg:
1a619819 2404 {
0aea4bf3 2405 const gdb_byte *param_ptr = value_contents (val_args[i]);
1a619819 2406#if defined (PRINTF_HAS_DECFLOAT)
0aea4bf3
LM
2407 /* If we have native support for Decimal floating
2408 printing, handle it here. */
2409 printf_filtered (current_substring, param_ptr);
1a619819 2410#else
1a619819
LM
2411
2412 /* As a workaround until vasprintf has native support for DFP
0aea4bf3
LM
2413 we convert the DFP values to string and print them using
2414 the %s format specifier. */
2415
2416 char *eos, *sos;
2417 int nnull_chars = 0;
2418
2419 /* Parameter data. */
2420 struct type *param_type = value_type (val_args[i]);
2421 unsigned int param_len = TYPE_LENGTH (param_type);
2422
2423 /* DFP output data. */
2424 struct value *dfp_value = NULL;
2425 gdb_byte *dfp_ptr;
2426 int dfp_len = 16;
2427 gdb_byte dec[16];
2428 struct type *dfp_type = NULL;
2429 char decstr[MAX_DECIMAL_STRING];
1a619819
LM
2430
2431 /* Points to the end of the string so that we can go back
0aea4bf3 2432 and check for DFP length modifiers. */
1a619819
LM
2433 eos = current_substring + strlen (current_substring);
2434
0aea4bf3
LM
2435 /* Look for the float/double format specifier. */
2436 while (*eos != 'f' && *eos != 'e' && *eos != 'E'
2437 && *eos != 'g' && *eos != 'G')
2438 eos--;
2439
2440 sos = eos;
2441
2442 /* Search for the '%' char and extract the size and type of
2443 the output decimal value based on its modifiers
2444 (%Hf, %Df, %DDf). */
2445 while (*--sos != '%')
2446 {
2447 if (*sos == 'H')
2448 {
2449 dfp_len = 4;
2450 dfp_type = builtin_type (current_gdbarch)->builtin_decfloat;
2451 }
2452 else if (*sos == 'D' && *(sos - 1) == 'D')
2453 {
2454 dfp_len = 16;
2455 dfp_type = builtin_type (current_gdbarch)->builtin_declong;
2456 sos--;
2457 }
2458 else
2459 {
2460 dfp_len = 8;
2461 dfp_type = builtin_type (current_gdbarch)->builtin_decdouble;
2462 }
2463 }
2464
2465 /* Replace %Hf, %Df and %DDf with %s's. */
2466 *++sos = 's';
2467
2468 /* Go through the whole format string and pull the correct
2469 number of chars back to compensate for the change in the
2470 format specifier. */
2471 while (nnull_chars < nargs - i)
2472 {
2473 if (*eos == '\0')
2474 nnull_chars++;
2475
2476 *++sos = *++eos;
2477 }
2478
2479 /* Conversion between different DFP types. */
2480 if (TYPE_CODE (param_type) == TYPE_CODE_DECFLOAT)
2481 decimal_convert (param_ptr, param_len, dec, dfp_len);
2482 else
2483 /* If this is a non-trivial conversion, just output 0.
2484 A correct converted value can be displayed by explicitly
2485 casting to a DFP type. */
2486 decimal_from_string (dec, dfp_len, "0");
2487
2488 dfp_value = value_from_decfloat (dfp_type, dec);
2489
2490 dfp_ptr = (gdb_byte *) value_contents (dfp_value);
2491
2492 decimal_to_string (dfp_ptr, dfp_len, decstr);
1a619819
LM
2493
2494 /* Print the DFP value. */
2495 printf_filtered (current_substring, decstr);
0aea4bf3 2496
1a619819
LM
2497 break;
2498#endif
2499 }
2500
2025a643
DJ
2501 case ptr_arg:
2502 {
2503 /* We avoid the host's %p because pointers are too
2504 likely to be the wrong size. The only interesting
2505 modifier for %p is a width; extract that, and then
2506 handle %p as glibc would: %#x or a literal "(nil)". */
2507
2508 char *p, *fmt, *fmt_p;
2509#if defined (CC_HAS_LONG_LONG) && defined (PRINTF_HAS_LONG_LONG)
2510 long long val = value_as_long (val_args[i]);
2511#else
2512 long val = value_as_long (val_args[i]);
2513#endif
2514
2515 fmt = alloca (strlen (current_substring) + 5);
2516
2517 /* Copy up to the leading %. */
2518 p = current_substring;
2519 fmt_p = fmt;
2520 while (*p)
2521 {
2522 int is_percent = (*p == '%');
2523 *fmt_p++ = *p++;
2524 if (is_percent)
2525 {
2526 if (*p == '%')
2527 *fmt_p++ = *p++;
2528 else
2529 break;
2530 }
2531 }
2532
2533 if (val != 0)
2534 *fmt_p++ = '#';
2535
2536 /* Copy any width. */
2537 while (*p >= '0' && *p < '9')
2538 *fmt_p++ = *p++;
2539
2540 gdb_assert (*p == 'p' && *(p + 1) == '\0');
2541 if (val != 0)
2542 {
2543#if defined (CC_HAS_LONG_LONG) && defined (PRINTF_HAS_LONG_LONG)
2544 *fmt_p++ = 'l';
2545#endif
2546 *fmt_p++ = 'l';
2547 *fmt_p++ = 'x';
2548 *fmt_p++ = '\0';
2549 printf_filtered (fmt, val);
2550 }
2551 else
2552 {
2553 *fmt_p++ = 's';
2554 *fmt_p++ = '\0';
2555 printf_filtered (fmt, "(nil)");
2556 }
2557
2558 break;
2559 }
675dcf4f
MK
2560 default:
2561 internal_error (__FILE__, __LINE__,
2025a643 2562 _("failed internal consistency check"));
c906108c
SS
2563 }
2564 /* Skip to the next substring. */
2565 current_substring += strlen (current_substring) + 1;
2566 }
2567 /* Print the portion of the format string after the last argument. */
306d9ac5 2568 puts_filtered (last_arg);
c906108c
SS
2569 }
2570 do_cleanups (old_cleanups);
2571}
c906108c 2572
c906108c 2573void
fba45db2 2574_initialize_printcmd (void)
c906108c 2575{
c94fdfd0
EZ
2576 struct cmd_list_element *c;
2577
c906108c
SS
2578 current_display_number = -1;
2579
a3247a22
PP
2580 observer_attach_solib_unloaded (clear_dangling_display_expressions);
2581
c906108c 2582 add_info ("address", address_info,
1bedd215 2583 _("Describe where symbol SYM is stored."));
c906108c 2584
1bedd215
AC
2585 add_info ("symbol", sym_info, _("\
2586Describe what symbol is at location ADDR.\n\
2587Only for symbols with fixed locations (global or static scope)."));
c906108c 2588
1bedd215
AC
2589 add_com ("x", class_vars, x_command, _("\
2590Examine memory: x/FMT ADDRESS.\n\
c906108c
SS
2591ADDRESS is an expression for the memory address to examine.\n\
2592FMT is a repeat count followed by a format letter and a size letter.\n\
2593Format letters are o(octal), x(hex), d(decimal), u(unsigned decimal),\n\
1bedd215
AC
2594 t(binary), f(float), a(address), i(instruction), c(char) and s(string).\n\
2595Size letters are b(byte), h(halfword), w(word), g(giant, 8 bytes).\n\
c906108c
SS
2596The specified number of objects of the specified size are printed\n\
2597according to the format.\n\n\
2598Defaults for format and size letters are those previously used.\n\
2599Default count is 1. Default address is following last thing printed\n\
1bedd215 2600with this command or \"print\"."));
c906108c 2601
c906108c
SS
2602#if 0
2603 add_com ("whereis", class_vars, whereis_command,
1bedd215 2604 _("Print line number and file of definition of variable."));
c906108c 2605#endif
c5aa993b 2606
1bedd215
AC
2607 add_info ("display", display_info, _("\
2608Expressions to display when program stops, with code numbers."));
c906108c 2609
1a966eab
AC
2610 add_cmd ("undisplay", class_vars, undisplay_command, _("\
2611Cancel some expressions to be displayed when program stops.\n\
c906108c
SS
2612Arguments are the code numbers of the expressions to stop displaying.\n\
2613No argument means cancel all automatic-display expressions.\n\
2614\"delete display\" has the same effect as this command.\n\
1a966eab 2615Do \"info display\" to see current list of code numbers."),
c5aa993b 2616 &cmdlist);
c906108c 2617
1bedd215
AC
2618 add_com ("display", class_vars, display_command, _("\
2619Print value of expression EXP each time the program stops.\n\
c906108c
SS
2620/FMT may be used before EXP as in the \"print\" command.\n\
2621/FMT \"i\" or \"s\" or including a size-letter is allowed,\n\
2622as in the \"x\" command, and then EXP is used to get the address to examine\n\
2623and examining is done as in the \"x\" command.\n\n\
2624With no argument, display all currently requested auto-display expressions.\n\
1bedd215 2625Use \"undisplay\" to cancel display requests previously made."));
c906108c 2626
1a966eab
AC
2627 add_cmd ("display", class_vars, enable_display, _("\
2628Enable some expressions to be displayed when program stops.\n\
c906108c
SS
2629Arguments are the code numbers of the expressions to resume displaying.\n\
2630No argument means enable all automatic-display expressions.\n\
1a966eab 2631Do \"info display\" to see current list of code numbers."), &enablelist);
c906108c 2632
1a966eab
AC
2633 add_cmd ("display", class_vars, disable_display_command, _("\
2634Disable some expressions to be displayed when program stops.\n\
c906108c
SS
2635Arguments are the code numbers of the expressions to stop displaying.\n\
2636No argument means disable all automatic-display expressions.\n\
1a966eab 2637Do \"info display\" to see current list of code numbers."), &disablelist);
c906108c 2638
1a966eab
AC
2639 add_cmd ("display", class_vars, undisplay_command, _("\
2640Cancel some expressions to be displayed when program stops.\n\
c906108c
SS
2641Arguments are the code numbers of the expressions to stop displaying.\n\
2642No argument means cancel all automatic-display expressions.\n\
1a966eab 2643Do \"info display\" to see current list of code numbers."), &deletelist);
c906108c 2644
1bedd215
AC
2645 add_com ("printf", class_vars, printf_command, _("\
2646printf \"printf format string\", arg1, arg2, arg3, ..., argn\n\
2647This is useful for formatted output in user-defined commands."));
c906108c 2648
1bedd215
AC
2649 add_com ("output", class_vars, output_command, _("\
2650Like \"print\" but don't put in value history and don't print newline.\n\
2651This is useful in user-defined commands."));
c906108c 2652
1bedd215
AC
2653 add_prefix_cmd ("set", class_vars, set_command, _("\
2654Evaluate expression EXP and assign result to variable VAR, using assignment\n\
c906108c
SS
2655syntax appropriate for the current language (VAR = EXP or VAR := EXP for\n\
2656example). VAR may be a debugger \"convenience\" variable (names starting\n\
2657with $), a register (a few standard names starting with $), or an actual\n\
1bedd215
AC
2658variable in the program being debugged. EXP is any valid expression.\n\
2659Use \"set variable\" for variables with names identical to set subcommands.\n\
2660\n\
2661With a subcommand, this command modifies parts of the gdb environment.\n\
2662You can see these environment settings with the \"show\" command."),
c5aa993b 2663 &setlist, "set ", 1, &cmdlist);
c906108c 2664 if (dbx_commands)
1bedd215
AC
2665 add_com ("assign", class_vars, set_command, _("\
2666Evaluate expression EXP and assign result to variable VAR, using assignment\n\
c906108c
SS
2667syntax appropriate for the current language (VAR = EXP or VAR := EXP for\n\
2668example). VAR may be a debugger \"convenience\" variable (names starting\n\
2669with $), a register (a few standard names starting with $), or an actual\n\
1bedd215
AC
2670variable in the program being debugged. EXP is any valid expression.\n\
2671Use \"set variable\" for variables with names identical to set subcommands.\n\
c906108c 2672\nWith a subcommand, this command modifies parts of the gdb environment.\n\
1bedd215 2673You can see these environment settings with the \"show\" command."));
c906108c
SS
2674
2675 /* "call" is the same as "set", but handy for dbx users to call fns. */
1bedd215
AC
2676 c = add_com ("call", class_vars, call_command, _("\
2677Call a function in the program.\n\
c906108c
SS
2678The argument is the function name and arguments, in the notation of the\n\
2679current working language. The result is printed and saved in the value\n\
1bedd215 2680history, if it is not void."));
65d12d83 2681 set_cmd_completer (c, expression_completer);
c906108c 2682
1a966eab
AC
2683 add_cmd ("variable", class_vars, set_command, _("\
2684Evaluate expression EXP and assign result to variable VAR, using assignment\n\
c906108c
SS
2685syntax appropriate for the current language (VAR = EXP or VAR := EXP for\n\
2686example). VAR may be a debugger \"convenience\" variable (names starting\n\
2687with $), a register (a few standard names starting with $), or an actual\n\
2688variable in the program being debugged. EXP is any valid expression.\n\
1a966eab 2689This may usually be abbreviated to simply \"set\"."),
c5aa993b 2690 &setlist);
c906108c 2691
1bedd215
AC
2692 c = add_com ("print", class_vars, print_command, _("\
2693Print value of expression EXP.\n\
c906108c
SS
2694Variables accessible are those of the lexical environment of the selected\n\
2695stack frame, plus all those whose scope is global or an entire file.\n\
2696\n\
2697$NUM gets previous value number NUM. $ and $$ are the last two values.\n\
2698$$NUM refers to NUM'th value back from the last one.\n\
1bedd215
AC
2699Names starting with $ refer to registers (with the values they would have\n\
2700if the program were to return to the stack frame now selected, restoring\n\
c906108c
SS
2701all registers saved by frames farther in) or else to debugger\n\
2702\"convenience\" variables (any such name not a known register).\n\
1bedd215
AC
2703Use assignment expressions to give values to convenience variables.\n\
2704\n\
c906108c
SS
2705{TYPE}ADREXP refers to a datum of data type TYPE, located at address ADREXP.\n\
2706@ is a binary operator for treating consecutive data objects\n\
2707anywhere in memory as an array. FOO@NUM gives an array whose first\n\
2708element is FOO, whose second element is stored in the space following\n\
2709where FOO is stored, etc. FOO must be an expression whose value\n\
1bedd215
AC
2710resides in memory.\n\
2711\n\
c906108c 2712EXP may be preceded with /FMT, where FMT is a format letter\n\
1bedd215 2713but no count or size letter (see \"x\" command)."));
65d12d83 2714 set_cmd_completer (c, expression_completer);
c906108c
SS
2715 add_com_alias ("p", "print", class_vars, 1);
2716
1bedd215
AC
2717 c = add_com ("inspect", class_vars, inspect_command, _("\
2718Same as \"print\" command, except that if you are running in the epoch\n\
2719environment, the value is printed in its own window."));
65d12d83 2720 set_cmd_completer (c, expression_completer);
c906108c 2721
35096d9d
AC
2722 add_setshow_uinteger_cmd ("max-symbolic-offset", no_class,
2723 &max_symbolic_offset, _("\
2724Set the largest offset that will be printed in <symbol+1234> form."), _("\
2725Show the largest offset that will be printed in <symbol+1234> form."), NULL,
2726 NULL,
920d2a44 2727 show_max_symbolic_offset,
35096d9d 2728 &setprintlist, &showprintlist);
5bf193a2
AC
2729 add_setshow_boolean_cmd ("symbol-filename", no_class,
2730 &print_symbol_filename, _("\
2731Set printing of source filename and line number with <symbol>."), _("\
2732Show printing of source filename and line number with <symbol>."), NULL,
2733 NULL,
920d2a44 2734 show_print_symbol_filename,
5bf193a2 2735 &setprintlist, &showprintlist);
c906108c
SS
2736
2737 /* For examine/instruction a single byte quantity is specified as
2738 the data. This avoids problems with value_at_lazy() requiring a
2739 valid data type (and rejecting VOID). */
2740 examine_i_type = init_type (TYPE_CODE_INT, 1, 0, "examine_i_type", NULL);
2741
2742 examine_b_type = init_type (TYPE_CODE_INT, 1, 0, "examine_b_type", NULL);
2743 examine_h_type = init_type (TYPE_CODE_INT, 2, 0, "examine_h_type", NULL);
2744 examine_w_type = init_type (TYPE_CODE_INT, 4, 0, "examine_w_type", NULL);
2745 examine_g_type = init_type (TYPE_CODE_INT, 8, 0, "examine_g_type", NULL);
2746
2747}
This page took 1.016039 seconds and 4 git commands to generate.