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