Fix crash printing packed record with packed array.
[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{
1766 int i;
1767 struct expression *const exp = d->exp;
1768
1769 if (d->block != NULL
5fd1a349 1770 && solib_contains_address_p (solib, d->block->startaddr))
a3247a22
PP
1771 return 1;
1772
1773 for (i = 0; i < exp->nelts; )
1774 {
1775 int args, oplen = 0;
1776 const union exp_element *const elts = exp->elts;
1777
1778 if (elts[i].opcode == OP_VAR_VALUE)
1779 {
1780 const struct block *const block = elts[i + 1].block;
1781 const struct symbol *const symbol = elts[i + 2].symbol;
1782 const struct obj_section *const section =
1783 SYMBOL_OBJ_SECTION (symbol);
1784
1785 if (block != NULL
5fd1a349 1786 && solib_contains_address_p (solib, block->startaddr))
a3247a22
PP
1787 return 1;
1788
1789 if (section && section->objfile == solib->objfile)
1790 return 1;
1791 }
1792 exp->language_defn->la_exp_desc->operator_length (exp, i + 1,
1793 &oplen, &args);
1794 gdb_assert (oplen > 0);
1795 i += oplen;
1796 }
1797 return 0;
1798}
1799
1800/* display_chain items point to blocks and expressions. Some expressions in
1801 turn may point to symbols.
1802 Both symbols and blocks are obstack_alloc'd on objfile_stack, and are
1803 obstack_free'd when a shared library is unloaded.
1804 Clear pointers that are about to become dangling.
1805 Both .exp and .block fields will be restored next time we need to display
1806 an item by re-parsing .exp_string field in the new execution context. */
1807
1808static void
1809clear_dangling_display_expressions (struct so_list *solib)
1810{
1811 struct display *d;
1812 struct objfile *objfile = NULL;
1813
1814 for (d = display_chain; d; d = d->next)
1815 {
1816 if (d->exp && display_uses_solib_p (d, solib))
1817 {
1818 xfree (d->exp);
1819 d->exp = NULL;
1820 d->block = NULL;
1821 }
1822 }
1823}
c906108c 1824\f
c5aa993b 1825
675dcf4f 1826/* Print the value in stack frame FRAME of a variable specified by a
aad95b57
TT
1827 struct symbol. NAME is the name to print; if NULL then VAR's print
1828 name will be used. STREAM is the ui_file on which to print the
1829 value. INDENT specifies the number of indent levels to print
1830 before printing the variable name. */
c906108c
SS
1831
1832void
aad95b57
TT
1833print_variable_and_value (const char *name, struct symbol *var,
1834 struct frame_info *frame,
1835 struct ui_file *stream, int indent)
c906108c 1836{
aad95b57 1837 struct value *val;
79a45b7d 1838 struct value_print_options opts;
c906108c 1839
aad95b57
TT
1840 if (!name)
1841 name = SYMBOL_PRINT_NAME (var);
1842
1843 fprintf_filtered (stream, "%s%s = ", n_spaces (2 * indent), name);
1844
1845 val = read_var_value (var, frame);
79a45b7d 1846 get_user_print_options (&opts);
aad95b57
TT
1847 common_val_print (val, stream, indent, &opts, current_language);
1848 fprintf_filtered (stream, "\n");
c906108c
SS
1849}
1850
c906108c 1851static void
fba45db2 1852printf_command (char *arg, int from_tty)
c906108c 1853{
52f0bd74
AC
1854 char *f = NULL;
1855 char *s = arg;
c906108c 1856 char *string = NULL;
3d6d86c6 1857 struct value **val_args;
c906108c
SS
1858 char *substrings;
1859 char *current_substring;
1860 int nargs = 0;
1861 int allocated_args = 20;
1862 struct cleanup *old_cleanups;
1863
675dcf4f 1864 val_args = xmalloc (allocated_args * sizeof (struct value *));
c13c43fd 1865 old_cleanups = make_cleanup (free_current_contents, &val_args);
c906108c
SS
1866
1867 if (s == 0)
e2e0b3e5 1868 error_no_arg (_("format-control string and values to print"));
c906108c
SS
1869
1870 /* Skip white space before format string */
c5aa993b
JM
1871 while (*s == ' ' || *s == '\t')
1872 s++;
c906108c 1873
675dcf4f 1874 /* A format string should follow, enveloped in double quotes. */
c906108c 1875 if (*s++ != '"')
8a3fe4f8 1876 error (_("Bad format string, missing '\"'."));
c906108c
SS
1877
1878 /* Parse the format-control string and copy it into the string STRING,
1879 processing some kinds of escape sequence. */
1880
1881 f = string = (char *) alloca (strlen (s) + 1);
1882
1883 while (*s != '"')
1884 {
1885 int c = *s++;
1886 switch (c)
1887 {
1888 case '\0':
8a3fe4f8 1889 error (_("Bad format string, non-terminated '\"'."));
c906108c
SS
1890
1891 case '\\':
1892 switch (c = *s++)
1893 {
1894 case '\\':
1895 *f++ = '\\';
1896 break;
1897 case 'a':
c906108c 1898 *f++ = '\a';
c906108c
SS
1899 break;
1900 case 'b':
1901 *f++ = '\b';
1902 break;
1903 case 'f':
1904 *f++ = '\f';
1905 break;
1906 case 'n':
1907 *f++ = '\n';
1908 break;
1909 case 'r':
1910 *f++ = '\r';
1911 break;
1912 case 't':
1913 *f++ = '\t';
1914 break;
1915 case 'v':
1916 *f++ = '\v';
1917 break;
1918 case '"':
1919 *f++ = '"';
1920 break;
1921 default:
1922 /* ??? TODO: handle other escape sequences */
8a3fe4f8 1923 error (_("Unrecognized escape character \\%c in format string."),
c906108c
SS
1924 c);
1925 }
1926 break;
1927
1928 default:
1929 *f++ = c;
1930 }
1931 }
1932
1933 /* Skip over " and following space and comma. */
1934 s++;
1935 *f++ = '\0';
c5aa993b
JM
1936 while (*s == ' ' || *s == '\t')
1937 s++;
c906108c
SS
1938
1939 if (*s != ',' && *s != 0)
8a3fe4f8 1940 error (_("Invalid argument syntax"));
c906108c 1941
c5aa993b
JM
1942 if (*s == ',')
1943 s++;
1944 while (*s == ' ' || *s == '\t')
1945 s++;
c906108c
SS
1946
1947 /* Need extra space for the '\0's. Doubling the size is sufficient. */
1948 substrings = alloca (strlen (string) * 2);
1949 current_substring = substrings;
1950
1951 {
1952 /* Now scan the string for %-specs and see what kinds of args they want.
1953 argclass[I] classifies the %-specs so we can give printf_filtered
1954 something of the right size. */
1955
c5aa993b
JM
1956 enum argclass
1957 {
46e9880c 1958 int_arg, long_arg, long_long_arg, ptr_arg, string_arg,
1a619819 1959 double_arg, long_double_arg, decfloat_arg
c5aa993b 1960 };
c906108c
SS
1961 enum argclass *argclass;
1962 enum argclass this_argclass;
1963 char *last_arg;
1964 int nargs_wanted;
c906108c
SS
1965 int i;
1966
1967 argclass = (enum argclass *) alloca (strlen (s) * sizeof *argclass);
1968 nargs_wanted = 0;
1969 f = string;
1970 last_arg = string;
1971 while (*f)
1972 if (*f++ == '%')
1973 {
46e9880c
DJ
1974 int seen_hash = 0, seen_zero = 0, lcount = 0, seen_prec = 0;
1975 int seen_space = 0, seen_plus = 0;
0aea4bf3
LM
1976 int seen_big_l = 0, seen_h = 0, seen_big_h = 0;
1977 int seen_big_d = 0, seen_double_big_d = 0;
46e9880c
DJ
1978 int bad = 0;
1979
1980 /* Check the validity of the format specifier, and work
1981 out what argument it expects. We only accept C89
1982 format strings, with the exception of long long (which
1983 we autoconf for). */
1984
1985 /* Skip over "%%". */
1986 if (*f == '%')
c906108c 1987 {
c906108c 1988 f++;
46e9880c 1989 continue;
c906108c 1990 }
46e9880c
DJ
1991
1992 /* The first part of a format specifier is a set of flag
1993 characters. */
1994 while (strchr ("0-+ #", *f))
1995 {
1996 if (*f == '#')
1997 seen_hash = 1;
1998 else if (*f == '0')
1999 seen_zero = 1;
2000 else if (*f == ' ')
2001 seen_space = 1;
2002 else if (*f == '+')
2003 seen_plus = 1;
2004 f++;
2005 }
2006
2007 /* The next part of a format specifier is a width. */
2008 while (strchr ("0123456789", *f))
2009 f++;
2010
2011 /* The next part of a format specifier is a precision. */
2012 if (*f == '.')
2013 {
2014 seen_prec = 1;
2015 f++;
2016 while (strchr ("0123456789", *f))
2017 f++;
2018 }
2019
2020 /* The next part of a format specifier is a length modifier. */
2021 if (*f == 'h')
2022 {
2023 seen_h = 1;
2024 f++;
2025 }
2026 else if (*f == 'l')
2027 {
2028 f++;
2029 lcount++;
2030 if (*f == 'l')
2031 {
2032 f++;
2033 lcount++;
2034 }
2035 }
2036 else if (*f == 'L')
2037 {
2038 seen_big_l = 1;
2039 f++;
2040 }
0aea4bf3
LM
2041 /* Decimal32 modifier. */
2042 else if (*f == 'H')
2043 {
2044 seen_big_h = 1;
2045 f++;
2046 }
2047 /* Decimal64 and Decimal128 modifiers. */
2048 else if (*f == 'D')
2049 {
2050 f++;
2051
2052 /* Check for a Decimal128. */
2053 if (*f == 'D')
2054 {
2055 f++;
2056 seen_double_big_d = 1;
2057 }
2058 else
2059 seen_big_d = 1;
2060 }
46e9880c 2061
c906108c
SS
2062 switch (*f)
2063 {
46e9880c
DJ
2064 case 'u':
2065 if (seen_hash)
2066 bad = 1;
2067 /* FALLTHROUGH */
2068
2069 case 'o':
2070 case 'x':
2071 case 'X':
2072 if (seen_space || seen_plus)
2073 bad = 1;
2074 /* FALLTHROUGH */
2075
2076 case 'd':
2077 case 'i':
2078 if (lcount == 0)
2079 this_argclass = int_arg;
2080 else if (lcount == 1)
2081 this_argclass = long_arg;
2082 else
2083 this_argclass = long_long_arg;
2084
2085 if (seen_big_l)
2086 bad = 1;
2087 break;
2088
2089 case 'c':
2090 this_argclass = int_arg;
2091 if (lcount || seen_h || seen_big_l)
2092 bad = 1;
2093 if (seen_prec || seen_zero || seen_space || seen_plus)
2094 bad = 1;
2095 break;
2096
2097 case 'p':
2098 this_argclass = ptr_arg;
2099 if (lcount || seen_h || seen_big_l)
2100 bad = 1;
2101 if (seen_prec || seen_zero || seen_space || seen_plus)
2102 bad = 1;
2103 break;
2104
c906108c
SS
2105 case 's':
2106 this_argclass = string_arg;
46e9880c
DJ
2107 if (lcount || seen_h || seen_big_l)
2108 bad = 1;
2109 if (seen_zero || seen_space || seen_plus)
2110 bad = 1;
c906108c
SS
2111 break;
2112
2113 case 'e':
2114 case 'f':
2115 case 'g':
46e9880c
DJ
2116 case 'E':
2117 case 'G':
0aea4bf3
LM
2118 if (seen_big_h || seen_big_d || seen_double_big_d)
2119 this_argclass = decfloat_arg;
2120 else if (seen_big_l)
46e9880c
DJ
2121 this_argclass = long_double_arg;
2122 else
2123 this_argclass = double_arg;
2124
2125 if (lcount || seen_h)
2126 bad = 1;
c906108c
SS
2127 break;
2128
2129 case '*':
8a3fe4f8 2130 error (_("`*' not supported for precision or width in printf"));
c906108c
SS
2131
2132 case 'n':
8a3fe4f8 2133 error (_("Format specifier `n' not supported in printf"));
c906108c 2134
46e9880c
DJ
2135 case '\0':
2136 error (_("Incomplete format specifier at end of format string"));
c906108c
SS
2137
2138 default:
46e9880c 2139 error (_("Unrecognized format specifier '%c' in printf"), *f);
c906108c 2140 }
46e9880c
DJ
2141
2142 if (bad)
2143 error (_("Inappropriate modifiers to format specifier '%c' in printf"),
2144 *f);
2145
c906108c 2146 f++;
09d71d23
AS
2147
2148 if (lcount > 1 && USE_PRINTF_I64)
2149 {
2150 /* Windows' printf does support long long, but not the usual way.
2151 Convert %lld to %I64d. */
2152 int length_before_ll = f - last_arg - 1 - lcount;
2153 strncpy (current_substring, last_arg, length_before_ll);
2154 strcpy (current_substring + length_before_ll, "I64");
2155 current_substring[length_before_ll + 3] =
2156 last_arg[length_before_ll + lcount];
2157 current_substring += length_before_ll + 4;
2158 }
2159 else
2160 {
2161 strncpy (current_substring, last_arg, f - last_arg);
2162 current_substring += f - last_arg;
2163 }
46e9880c
DJ
2164 *current_substring++ = '\0';
2165 last_arg = f;
2166 argclass[nargs_wanted++] = this_argclass;
c906108c
SS
2167 }
2168
2169 /* Now, parse all arguments and evaluate them.
2170 Store the VALUEs in VAL_ARGS. */
2171
2172 while (*s != '\0')
2173 {
2174 char *s1;
2175 if (nargs == allocated_args)
f976f6d4
AC
2176 val_args = (struct value **) xrealloc ((char *) val_args,
2177 (allocated_args *= 2)
2178 * sizeof (struct value *));
c906108c
SS
2179 s1 = s;
2180 val_args[nargs] = parse_to_comma_and_eval (&s1);
c5aa993b 2181
c906108c
SS
2182 nargs++;
2183 s = s1;
2184 if (*s == ',')
2185 s++;
2186 }
c5aa993b 2187
c906108c 2188 if (nargs != nargs_wanted)
8a3fe4f8 2189 error (_("Wrong number of arguments for specified format-string"));
c906108c
SS
2190
2191 /* Now actually print them. */
2192 current_substring = substrings;
2193 for (i = 0; i < nargs; i++)
2194 {
2195 switch (argclass[i])
2196 {
2197 case string_arg:
2198 {
777ea8f1 2199 gdb_byte *str;
c906108c
SS
2200 CORE_ADDR tem;
2201 int j;
1aa20aa8 2202 tem = value_as_address (val_args[i]);
c906108c
SS
2203
2204 /* This is a %s argument. Find the length of the string. */
c5aa993b 2205 for (j = 0;; j++)
c906108c 2206 {
777ea8f1 2207 gdb_byte c;
c906108c 2208 QUIT;
d4b2399a 2209 read_memory (tem + j, &c, 1);
c906108c
SS
2210 if (c == 0)
2211 break;
2212 }
2213
2214 /* Copy the string contents into a string inside GDB. */
777ea8f1 2215 str = (gdb_byte *) alloca (j + 1);
7b92f6e1
MS
2216 if (j != 0)
2217 read_memory (tem, str, j);
c906108c
SS
2218 str[j] = 0;
2219
777ea8f1 2220 printf_filtered (current_substring, (char *) str);
c906108c
SS
2221 }
2222 break;
2223 case double_arg:
2224 {
b806fb9a
UW
2225 struct type *type = value_type (val_args[i]);
2226 DOUBLEST val;
2227 int inv;
2228
2229 /* If format string wants a float, unchecked-convert the value
2230 to floating point of the same size. */
2231 type = float_type_from_length (current_gdbarch, type);
2232 val = unpack_double (type, value_contents (val_args[i]), &inv);
2233 if (inv)
2234 error (_("Invalid floating value found in program."));
2235
2236 printf_filtered (current_substring, (double) val);
c906108c
SS
2237 break;
2238 }
46e9880c
DJ
2239 case long_double_arg:
2240#ifdef HAVE_LONG_DOUBLE
2241 {
b806fb9a
UW
2242 struct type *type = value_type (val_args[i]);
2243 DOUBLEST val;
2244 int inv;
2245
2246 /* If format string wants a float, unchecked-convert the value
2247 to floating point of the same size. */
2248 type = float_type_from_length (current_gdbarch, type);
2249 val = unpack_double (type, value_contents (val_args[i]), &inv);
2250 if (inv)
2251 error (_("Invalid floating value found in program."));
2252
2253 printf_filtered (current_substring, (long double) val);
46e9880c
DJ
2254 break;
2255 }
2256#else
2257 error (_("long double not supported in printf"));
2258#endif
c906108c
SS
2259 case long_long_arg:
2260#if defined (CC_HAS_LONG_LONG) && defined (PRINTF_HAS_LONG_LONG)
2261 {
2262 long long val = value_as_long (val_args[i]);
2263 printf_filtered (current_substring, val);
2264 break;
2265 }
2266#else
8a3fe4f8 2267 error (_("long long not supported in printf"));
c906108c
SS
2268#endif
2269 case int_arg:
2270 {
46e9880c
DJ
2271 int val = value_as_long (val_args[i]);
2272 printf_filtered (current_substring, val);
2273 break;
2274 }
2275 case long_arg:
2276 {
c906108c
SS
2277 long val = value_as_long (val_args[i]);
2278 printf_filtered (current_substring, val);
2279 break;
2280 }
1a619819 2281
0aea4bf3
LM
2282 /* Handles decimal floating values. */
2283 case decfloat_arg:
1a619819 2284 {
0aea4bf3 2285 const gdb_byte *param_ptr = value_contents (val_args[i]);
1a619819 2286#if defined (PRINTF_HAS_DECFLOAT)
0aea4bf3
LM
2287 /* If we have native support for Decimal floating
2288 printing, handle it here. */
2289 printf_filtered (current_substring, param_ptr);
1a619819 2290#else
1a619819
LM
2291
2292 /* As a workaround until vasprintf has native support for DFP
0aea4bf3
LM
2293 we convert the DFP values to string and print them using
2294 the %s format specifier. */
2295
2296 char *eos, *sos;
2297 int nnull_chars = 0;
2298
2299 /* Parameter data. */
2300 struct type *param_type = value_type (val_args[i]);
2301 unsigned int param_len = TYPE_LENGTH (param_type);
2302
2303 /* DFP output data. */
2304 struct value *dfp_value = NULL;
2305 gdb_byte *dfp_ptr;
2306 int dfp_len = 16;
2307 gdb_byte dec[16];
2308 struct type *dfp_type = NULL;
2309 char decstr[MAX_DECIMAL_STRING];
1a619819
LM
2310
2311 /* Points to the end of the string so that we can go back
0aea4bf3 2312 and check for DFP length modifiers. */
1a619819
LM
2313 eos = current_substring + strlen (current_substring);
2314
0aea4bf3
LM
2315 /* Look for the float/double format specifier. */
2316 while (*eos != 'f' && *eos != 'e' && *eos != 'E'
2317 && *eos != 'g' && *eos != 'G')
2318 eos--;
2319
2320 sos = eos;
2321
2322 /* Search for the '%' char and extract the size and type of
2323 the output decimal value based on its modifiers
2324 (%Hf, %Df, %DDf). */
2325 while (*--sos != '%')
2326 {
2327 if (*sos == 'H')
2328 {
2329 dfp_len = 4;
2330 dfp_type = builtin_type (current_gdbarch)->builtin_decfloat;
2331 }
2332 else if (*sos == 'D' && *(sos - 1) == 'D')
2333 {
2334 dfp_len = 16;
2335 dfp_type = builtin_type (current_gdbarch)->builtin_declong;
2336 sos--;
2337 }
2338 else
2339 {
2340 dfp_len = 8;
2341 dfp_type = builtin_type (current_gdbarch)->builtin_decdouble;
2342 }
2343 }
2344
2345 /* Replace %Hf, %Df and %DDf with %s's. */
2346 *++sos = 's';
2347
2348 /* Go through the whole format string and pull the correct
2349 number of chars back to compensate for the change in the
2350 format specifier. */
2351 while (nnull_chars < nargs - i)
2352 {
2353 if (*eos == '\0')
2354 nnull_chars++;
2355
2356 *++sos = *++eos;
2357 }
2358
2359 /* Conversion between different DFP types. */
2360 if (TYPE_CODE (param_type) == TYPE_CODE_DECFLOAT)
2361 decimal_convert (param_ptr, param_len, dec, dfp_len);
2362 else
2363 /* If this is a non-trivial conversion, just output 0.
2364 A correct converted value can be displayed by explicitly
2365 casting to a DFP type. */
2366 decimal_from_string (dec, dfp_len, "0");
2367
2368 dfp_value = value_from_decfloat (dfp_type, dec);
2369
2370 dfp_ptr = (gdb_byte *) value_contents (dfp_value);
2371
2372 decimal_to_string (dfp_ptr, dfp_len, decstr);
1a619819
LM
2373
2374 /* Print the DFP value. */
2375 printf_filtered (current_substring, decstr);
0aea4bf3 2376
1a619819
LM
2377 break;
2378#endif
2379 }
2380
2025a643
DJ
2381 case ptr_arg:
2382 {
2383 /* We avoid the host's %p because pointers are too
2384 likely to be the wrong size. The only interesting
2385 modifier for %p is a width; extract that, and then
2386 handle %p as glibc would: %#x or a literal "(nil)". */
2387
2388 char *p, *fmt, *fmt_p;
2389#if defined (CC_HAS_LONG_LONG) && defined (PRINTF_HAS_LONG_LONG)
2390 long long val = value_as_long (val_args[i]);
2391#else
2392 long val = value_as_long (val_args[i]);
2393#endif
2394
2395 fmt = alloca (strlen (current_substring) + 5);
2396
2397 /* Copy up to the leading %. */
2398 p = current_substring;
2399 fmt_p = fmt;
2400 while (*p)
2401 {
2402 int is_percent = (*p == '%');
2403 *fmt_p++ = *p++;
2404 if (is_percent)
2405 {
2406 if (*p == '%')
2407 *fmt_p++ = *p++;
2408 else
2409 break;
2410 }
2411 }
2412
2413 if (val != 0)
2414 *fmt_p++ = '#';
2415
2416 /* Copy any width. */
2417 while (*p >= '0' && *p < '9')
2418 *fmt_p++ = *p++;
2419
2420 gdb_assert (*p == 'p' && *(p + 1) == '\0');
2421 if (val != 0)
2422 {
2423#if defined (CC_HAS_LONG_LONG) && defined (PRINTF_HAS_LONG_LONG)
2424 *fmt_p++ = 'l';
2425#endif
2426 *fmt_p++ = 'l';
2427 *fmt_p++ = 'x';
2428 *fmt_p++ = '\0';
2429 printf_filtered (fmt, val);
2430 }
2431 else
2432 {
2433 *fmt_p++ = 's';
2434 *fmt_p++ = '\0';
2435 printf_filtered (fmt, "(nil)");
2436 }
2437
2438 break;
2439 }
675dcf4f
MK
2440 default:
2441 internal_error (__FILE__, __LINE__,
2025a643 2442 _("failed internal consistency check"));
c906108c
SS
2443 }
2444 /* Skip to the next substring. */
2445 current_substring += strlen (current_substring) + 1;
2446 }
2447 /* Print the portion of the format string after the last argument. */
306d9ac5 2448 puts_filtered (last_arg);
c906108c
SS
2449 }
2450 do_cleanups (old_cleanups);
2451}
c906108c 2452
c906108c 2453void
fba45db2 2454_initialize_printcmd (void)
c906108c 2455{
c94fdfd0
EZ
2456 struct cmd_list_element *c;
2457
c906108c
SS
2458 current_display_number = -1;
2459
a3247a22
PP
2460 observer_attach_solib_unloaded (clear_dangling_display_expressions);
2461
c906108c 2462 add_info ("address", address_info,
1bedd215 2463 _("Describe where symbol SYM is stored."));
c906108c 2464
1bedd215
AC
2465 add_info ("symbol", sym_info, _("\
2466Describe what symbol is at location ADDR.\n\
2467Only for symbols with fixed locations (global or static scope)."));
c906108c 2468
1bedd215
AC
2469 add_com ("x", class_vars, x_command, _("\
2470Examine memory: x/FMT ADDRESS.\n\
c906108c
SS
2471ADDRESS is an expression for the memory address to examine.\n\
2472FMT is a repeat count followed by a format letter and a size letter.\n\
2473Format letters are o(octal), x(hex), d(decimal), u(unsigned decimal),\n\
1bedd215
AC
2474 t(binary), f(float), a(address), i(instruction), c(char) and s(string).\n\
2475Size letters are b(byte), h(halfword), w(word), g(giant, 8 bytes).\n\
c906108c
SS
2476The specified number of objects of the specified size are printed\n\
2477according to the format.\n\n\
2478Defaults for format and size letters are those previously used.\n\
2479Default count is 1. Default address is following last thing printed\n\
1bedd215 2480with this command or \"print\"."));
c906108c 2481
c906108c
SS
2482#if 0
2483 add_com ("whereis", class_vars, whereis_command,
1bedd215 2484 _("Print line number and file of definition of variable."));
c906108c 2485#endif
c5aa993b 2486
1bedd215
AC
2487 add_info ("display", display_info, _("\
2488Expressions to display when program stops, with code numbers."));
c906108c 2489
1a966eab
AC
2490 add_cmd ("undisplay", class_vars, undisplay_command, _("\
2491Cancel some expressions to be displayed when program stops.\n\
c906108c
SS
2492Arguments are the code numbers of the expressions to stop displaying.\n\
2493No argument means cancel all automatic-display expressions.\n\
2494\"delete display\" has the same effect as this command.\n\
1a966eab 2495Do \"info display\" to see current list of code numbers."),
c5aa993b 2496 &cmdlist);
c906108c 2497
1bedd215
AC
2498 add_com ("display", class_vars, display_command, _("\
2499Print value of expression EXP each time the program stops.\n\
c906108c
SS
2500/FMT may be used before EXP as in the \"print\" command.\n\
2501/FMT \"i\" or \"s\" or including a size-letter is allowed,\n\
2502as in the \"x\" command, and then EXP is used to get the address to examine\n\
2503and examining is done as in the \"x\" command.\n\n\
2504With no argument, display all currently requested auto-display expressions.\n\
1bedd215 2505Use \"undisplay\" to cancel display requests previously made."));
c906108c 2506
1a966eab
AC
2507 add_cmd ("display", class_vars, enable_display, _("\
2508Enable some expressions to be displayed when program stops.\n\
c906108c
SS
2509Arguments are the code numbers of the expressions to resume displaying.\n\
2510No argument means enable all automatic-display expressions.\n\
1a966eab 2511Do \"info display\" to see current list of code numbers."), &enablelist);
c906108c 2512
1a966eab
AC
2513 add_cmd ("display", class_vars, disable_display_command, _("\
2514Disable some expressions to be displayed when program stops.\n\
c906108c
SS
2515Arguments are the code numbers of the expressions to stop displaying.\n\
2516No argument means disable all automatic-display expressions.\n\
1a966eab 2517Do \"info display\" to see current list of code numbers."), &disablelist);
c906108c 2518
1a966eab
AC
2519 add_cmd ("display", class_vars, undisplay_command, _("\
2520Cancel some expressions to be displayed when program stops.\n\
c906108c
SS
2521Arguments are the code numbers of the expressions to stop displaying.\n\
2522No argument means cancel all automatic-display expressions.\n\
1a966eab 2523Do \"info display\" to see current list of code numbers."), &deletelist);
c906108c 2524
1bedd215
AC
2525 add_com ("printf", class_vars, printf_command, _("\
2526printf \"printf format string\", arg1, arg2, arg3, ..., argn\n\
2527This is useful for formatted output in user-defined commands."));
c906108c 2528
1bedd215
AC
2529 add_com ("output", class_vars, output_command, _("\
2530Like \"print\" but don't put in value history and don't print newline.\n\
2531This is useful in user-defined commands."));
c906108c 2532
1bedd215
AC
2533 add_prefix_cmd ("set", class_vars, set_command, _("\
2534Evaluate expression EXP and assign result to variable VAR, using assignment\n\
c906108c
SS
2535syntax appropriate for the current language (VAR = EXP or VAR := EXP for\n\
2536example). VAR may be a debugger \"convenience\" variable (names starting\n\
2537with $), a register (a few standard names starting with $), or an actual\n\
1bedd215
AC
2538variable in the program being debugged. EXP is any valid expression.\n\
2539Use \"set variable\" for variables with names identical to set subcommands.\n\
2540\n\
2541With a subcommand, this command modifies parts of the gdb environment.\n\
2542You can see these environment settings with the \"show\" command."),
c5aa993b 2543 &setlist, "set ", 1, &cmdlist);
c906108c 2544 if (dbx_commands)
1bedd215
AC
2545 add_com ("assign", class_vars, set_command, _("\
2546Evaluate expression EXP and assign result to variable VAR, using assignment\n\
c906108c
SS
2547syntax appropriate for the current language (VAR = EXP or VAR := EXP for\n\
2548example). VAR may be a debugger \"convenience\" variable (names starting\n\
2549with $), a register (a few standard names starting with $), or an actual\n\
1bedd215
AC
2550variable in the program being debugged. EXP is any valid expression.\n\
2551Use \"set variable\" for variables with names identical to set subcommands.\n\
c906108c 2552\nWith a subcommand, this command modifies parts of the gdb environment.\n\
1bedd215 2553You can see these environment settings with the \"show\" command."));
c906108c
SS
2554
2555 /* "call" is the same as "set", but handy for dbx users to call fns. */
1bedd215
AC
2556 c = add_com ("call", class_vars, call_command, _("\
2557Call a function in the program.\n\
c906108c
SS
2558The argument is the function name and arguments, in the notation of the\n\
2559current working language. The result is printed and saved in the value\n\
1bedd215 2560history, if it is not void."));
65d12d83 2561 set_cmd_completer (c, expression_completer);
c906108c 2562
1a966eab
AC
2563 add_cmd ("variable", class_vars, set_command, _("\
2564Evaluate expression EXP and assign result to variable VAR, using assignment\n\
c906108c
SS
2565syntax appropriate for the current language (VAR = EXP or VAR := EXP for\n\
2566example). VAR may be a debugger \"convenience\" variable (names starting\n\
2567with $), a register (a few standard names starting with $), or an actual\n\
2568variable in the program being debugged. EXP is any valid expression.\n\
1a966eab 2569This may usually be abbreviated to simply \"set\"."),
c5aa993b 2570 &setlist);
c906108c 2571
1bedd215
AC
2572 c = add_com ("print", class_vars, print_command, _("\
2573Print value of expression EXP.\n\
c906108c
SS
2574Variables accessible are those of the lexical environment of the selected\n\
2575stack frame, plus all those whose scope is global or an entire file.\n\
2576\n\
2577$NUM gets previous value number NUM. $ and $$ are the last two values.\n\
2578$$NUM refers to NUM'th value back from the last one.\n\
1bedd215
AC
2579Names starting with $ refer to registers (with the values they would have\n\
2580if the program were to return to the stack frame now selected, restoring\n\
c906108c
SS
2581all registers saved by frames farther in) or else to debugger\n\
2582\"convenience\" variables (any such name not a known register).\n\
1bedd215
AC
2583Use assignment expressions to give values to convenience variables.\n\
2584\n\
c906108c
SS
2585{TYPE}ADREXP refers to a datum of data type TYPE, located at address ADREXP.\n\
2586@ is a binary operator for treating consecutive data objects\n\
2587anywhere in memory as an array. FOO@NUM gives an array whose first\n\
2588element is FOO, whose second element is stored in the space following\n\
2589where FOO is stored, etc. FOO must be an expression whose value\n\
1bedd215
AC
2590resides in memory.\n\
2591\n\
c906108c 2592EXP may be preceded with /FMT, where FMT is a format letter\n\
1bedd215 2593but no count or size letter (see \"x\" command)."));
65d12d83 2594 set_cmd_completer (c, expression_completer);
c906108c
SS
2595 add_com_alias ("p", "print", class_vars, 1);
2596
1bedd215
AC
2597 c = add_com ("inspect", class_vars, inspect_command, _("\
2598Same as \"print\" command, except that if you are running in the epoch\n\
2599environment, the value is printed in its own window."));
65d12d83 2600 set_cmd_completer (c, expression_completer);
c906108c 2601
35096d9d
AC
2602 add_setshow_uinteger_cmd ("max-symbolic-offset", no_class,
2603 &max_symbolic_offset, _("\
2604Set the largest offset that will be printed in <symbol+1234> form."), _("\
2605Show the largest offset that will be printed in <symbol+1234> form."), NULL,
2606 NULL,
920d2a44 2607 show_max_symbolic_offset,
35096d9d 2608 &setprintlist, &showprintlist);
5bf193a2
AC
2609 add_setshow_boolean_cmd ("symbol-filename", no_class,
2610 &print_symbol_filename, _("\
2611Set printing of source filename and line number with <symbol>."), _("\
2612Show printing of source filename and line number with <symbol>."), NULL,
2613 NULL,
920d2a44 2614 show_print_symbol_filename,
5bf193a2 2615 &setprintlist, &showprintlist);
c906108c
SS
2616
2617 /* For examine/instruction a single byte quantity is specified as
2618 the data. This avoids problems with value_at_lazy() requiring a
2619 valid data type (and rejecting VOID). */
2620 examine_i_type = init_type (TYPE_CODE_INT, 1, 0, "examine_i_type", NULL);
2621
2622 examine_b_type = init_type (TYPE_CODE_INT, 1, 0, "examine_b_type", NULL);
2623 examine_h_type = init_type (TYPE_CODE_INT, 2, 0, "examine_h_type", NULL);
2624 examine_w_type = init_type (TYPE_CODE_INT, 4, 0, "examine_w_type", NULL);
2625 examine_g_type = init_type (TYPE_CODE_INT, 8, 0, "examine_g_type", NULL);
2626
2627}
This page took 0.929704 seconds and 4 git commands to generate.