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