1 /* Print values for GNU debugger GDB.
3 Copyright 1986, 1987, 1988, 1989, 1990, 1991, 1992, 1993, 1994,
4 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003 Free Software
7 This file is part of GDB.
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 2 of the License, or
12 (at your option) any later version.
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.
19 You should have received a copy of the GNU General Public License
20 along with this program; if not, write to the Free Software
21 Foundation, Inc., 59 Temple Place - Suite 330,
22 Boston, MA 02111-1307, USA. */
25 #include "gdb_string.h"
31 #include "expression.h"
35 #include "breakpoint.h"
39 #include "symfile.h" /* for overlay functions */
40 #include "objfiles.h" /* ditto */
41 #include "completer.h" /* for completion functions */
43 #include "gdb_assert.h"
48 #include "tui/tui.h" /* For tui_active et.al. */
51 extern int asm_demangle
; /* Whether to demangle syms in asm printouts */
52 extern int addressprint
; /* Whether to print hex addresses in HLL " */
61 /* Last specified output format. */
63 static char last_format
= 'x';
65 /* Last specified examination size. 'b', 'h', 'w' or `q'. */
67 static char last_size
= 'w';
69 /* Default address to examine next. */
71 static CORE_ADDR next_address
;
73 /* Default section to examine next. */
75 static asection
*next_section
;
77 /* Last address examined. */
79 static CORE_ADDR last_examine_address
;
81 /* Contents of last address examined.
82 This is not valid past the end of the `x' command! */
84 static struct value
*last_examine_value
;
86 /* Largest offset between a symbolic value and an address, that will be
87 printed as `0x1234 <symbol+offset>'. */
89 static unsigned int max_symbolic_offset
= UINT_MAX
;
91 /* Append the source filename and linenumber of the symbol when
92 printing a symbolic value as `<symbol at filename:linenum>' if set. */
93 static int print_symbol_filename
= 0;
95 /* Number of auto-display expression currently being displayed.
96 So that we can disable it if we get an error or a signal within it.
97 -1 when not doing one. */
99 int current_display_number
;
101 /* Flag to low-level print routines that this value is being printed
102 in an epoch window. We'd like to pass this as a parameter, but
103 every routine would need to take it. Perhaps we can encapsulate
104 this in the I/O stream once we have GNU stdio. */
110 /* Chain link to next auto-display item. */
111 struct display
*next
;
112 /* Expression to be evaluated and displayed. */
113 struct expression
*exp
;
114 /* Item number of this auto-display item. */
116 /* Display format specified. */
117 struct format_data format
;
118 /* Innermost block required by this expression when evaluated */
120 /* Status of this display (enabled or disabled) */
124 /* Chain of expressions whose values should be displayed
125 automatically each time the program stops. */
127 static struct display
*display_chain
;
129 static int display_number
;
131 /* Prototypes for exported functions. */
133 void output_command (char *, int);
135 void _initialize_printcmd (void);
137 /* Prototypes for local functions. */
139 static void delete_display (int);
141 static void enable_display (char *, int);
143 static void disable_display_command (char *, int);
145 static void printf_command (char *, int);
147 static void display_info (char *, int);
149 static void do_one_display (struct display
*);
151 static void undisplay_command (char *, int);
153 static void free_display (struct display
*);
155 static void display_command (char *, int);
157 void x_command (char *, int);
159 static void address_info (char *, int);
161 static void set_command (char *, int);
163 static void call_command (char *, int);
165 static void inspect_command (char *, int);
167 static void print_command (char *, int);
169 static void print_command_1 (char *, int, int);
171 static void validate_format (struct format_data
, char *);
173 static void do_examine (struct format_data
, CORE_ADDR addr
,
176 static void print_formatted (struct value
*, int, int, struct ui_file
*);
178 static struct format_data
decode_format (char **, int, int);
180 static void sym_info (char *, int);
183 /* Decode a format specification. *STRING_PTR should point to it.
184 OFORMAT and OSIZE are used as defaults for the format and size
185 if none are given in the format specification.
186 If OSIZE is zero, then the size field of the returned value
187 should be set only if a size is explicitly specified by the
189 The structure returned describes all the data
190 found in the specification. In addition, *STRING_PTR is advanced
191 past the specification and past all whitespace following it. */
193 static struct format_data
194 decode_format (char **string_ptr
, int oformat
, int osize
)
196 struct format_data val
;
197 char *p
= *string_ptr
;
203 if (*p
>= '0' && *p
<= '9')
204 val
.count
= atoi (p
);
205 while (*p
>= '0' && *p
<= '9')
208 /* Now process size or format letters that follow. */
212 if (*p
== 'b' || *p
== 'h' || *p
== 'w' || *p
== 'g')
214 else if (*p
>= 'a' && *p
<= 'z')
220 while (*p
== ' ' || *p
== '\t')
224 /* Set defaults for format and size if not specified. */
225 if (val
.format
== '?')
229 /* Neither has been specified. */
230 val
.format
= oformat
;
234 /* If a size is specified, any format makes a reasonable
235 default except 'i'. */
236 val
.format
= oformat
== 'i' ? 'x' : oformat
;
238 else if (val
.size
== '?')
243 /* Pick the appropriate size for an address. */
244 if (TARGET_PTR_BIT
== 64)
245 val
.size
= osize
? 'g' : osize
;
246 else if (TARGET_PTR_BIT
== 32)
247 val
.size
= osize
? 'w' : osize
;
248 else if (TARGET_PTR_BIT
== 16)
249 val
.size
= osize
? 'h' : osize
;
251 /* Bad value for TARGET_PTR_BIT */
252 internal_error (__FILE__
, __LINE__
, "failed internal consistency check");
255 /* Floating point has to be word or giantword. */
256 if (osize
== 'w' || osize
== 'g')
259 /* Default it to giantword if the last used size is not
261 val
.size
= osize
? 'g' : osize
;
264 /* Characters default to one byte. */
265 val
.size
= osize
? 'b' : osize
;
268 /* The default is the size most recently specified. */
275 /* Print value VAL on stream according to FORMAT, a letter or 0.
276 Do not end with a newline.
277 0 means print VAL according to its own type.
278 SIZE is the letter for the size of datum being printed.
279 This is used to pad hex numbers so they line up. */
282 print_formatted (struct value
*val
, int format
, int size
,
283 struct ui_file
*stream
)
285 struct type
*type
= check_typedef (VALUE_TYPE (val
));
286 int len
= TYPE_LENGTH (type
);
288 if (VALUE_LVAL (val
) == lval_memory
)
290 next_address
= VALUE_ADDRESS (val
) + len
;
291 next_section
= VALUE_BFD_SECTION (val
);
297 /* FIXME: Need to handle wchar_t's here... */
298 next_address
= VALUE_ADDRESS (val
)
299 + val_print_string (VALUE_ADDRESS (val
), -1, 1, stream
);
300 next_section
= VALUE_BFD_SECTION (val
);
304 /* The old comment says
305 "Force output out, print_insn not using _filtered".
306 I'm not completely sure what that means, I suspect most print_insn
307 now do use _filtered, so I guess it's obsolete.
308 --Yes, it does filter now, and so this is obsolete. -JB */
310 /* We often wrap here if there are long symbolic names. */
312 next_address
= VALUE_ADDRESS (val
)
313 + gdb_print_insn (VALUE_ADDRESS (val
), stream
);
314 next_section
= VALUE_BFD_SECTION (val
);
319 || TYPE_CODE (type
) == TYPE_CODE_ARRAY
320 || TYPE_CODE (type
) == TYPE_CODE_STRING
321 || TYPE_CODE (type
) == TYPE_CODE_STRUCT
322 || TYPE_CODE (type
) == TYPE_CODE_UNION
323 || TYPE_CODE (type
) == TYPE_CODE_NAMESPACE
)
324 /* If format is 0, use the 'natural' format for
325 * that type of value. If the type is non-scalar,
326 * we have to use language rules to print it as
327 * a series of scalars.
329 value_print (val
, stream
, format
, Val_pretty_default
);
331 /* User specified format, so don't look to the
332 * the type to tell us what to do.
334 print_scalar_formatted (VALUE_CONTENTS (val
), type
,
335 format
, size
, stream
);
339 /* Print a scalar of data of type TYPE, pointed to in GDB by VALADDR,
340 according to letters FORMAT and SIZE on STREAM.
341 FORMAT may not be zero. Formats s and i are not supported at this level.
343 This is how the elements of an array or structure are printed
347 print_scalar_formatted (void *valaddr
, struct type
*type
, int format
, int size
,
348 struct ui_file
*stream
)
351 unsigned int len
= TYPE_LENGTH (type
);
353 if (len
> sizeof (LONGEST
)
361 if (!TYPE_UNSIGNED (type
)
362 || !extract_long_unsigned_integer (valaddr
, len
, &val_long
))
364 /* We can't print it normally, but we can print it in hex.
365 Printing it in the wrong radix is more useful than saying
366 "use /x, you dummy". */
367 /* FIXME: we could also do octal or binary if that was the
369 /* FIXME: we should be using the size field to give us a
370 minimum field width to print. */
373 print_octal_chars (stream
, valaddr
, len
);
374 else if (format
== 'd')
375 print_decimal_chars (stream
, valaddr
, len
);
376 else if (format
== 't')
377 print_binary_chars (stream
, valaddr
, len
);
379 /* replace with call to print_hex_chars? Looks
380 like val_print_type_code_int is redoing
383 val_print_type_code_int (type
, valaddr
, stream
);
388 /* If we get here, extract_long_unsigned_integer set val_long. */
390 else if (format
!= 'f')
391 val_long
= unpack_long (type
, valaddr
);
393 /* If the value is a pointer, and pointers and addresses are not the
394 same, then at this point, the value's length (in target bytes) is
395 TARGET_ADDR_BIT/TARGET_CHAR_BIT, not TYPE_LENGTH (type). */
396 if (TYPE_CODE (type
) == TYPE_CODE_PTR
)
397 len
= TARGET_ADDR_BIT
/ TARGET_CHAR_BIT
;
399 /* If we are printing it as unsigned, truncate it in case it is actually
400 a negative signed value (e.g. "print/u (short)-1" should print 65535
401 (if shorts are 16 bits) instead of 4294967295). */
404 if (len
< sizeof (LONGEST
))
405 val_long
&= ((LONGEST
) 1 << HOST_CHAR_BIT
* len
) - 1;
413 /* no size specified, like in print. Print varying # of digits. */
414 print_longest (stream
, 'x', 1, val_long
);
423 print_longest (stream
, size
, 1, val_long
);
426 error ("Undefined output size \"%c\".", size
);
431 print_longest (stream
, 'd', 1, val_long
);
435 print_longest (stream
, 'u', 0, val_long
);
440 print_longest (stream
, 'o', 1, val_long
);
442 fprintf_filtered (stream
, "0");
447 CORE_ADDR addr
= unpack_pointer (type
, valaddr
);
448 print_address (addr
, stream
);
453 value_print (value_from_longest (builtin_type_true_char
, val_long
),
454 stream
, 0, Val_pretty_default
);
458 if (len
== TYPE_LENGTH (builtin_type_float
))
459 type
= builtin_type_float
;
460 else if (len
== TYPE_LENGTH (builtin_type_double
))
461 type
= builtin_type_double
;
462 else if (len
== TYPE_LENGTH (builtin_type_long_double
))
463 type
= builtin_type_long_double
;
464 print_floating (valaddr
, type
, stream
);
468 internal_error (__FILE__
, __LINE__
, "failed internal consistency check");
471 /* Binary; 't' stands for "two". */
473 char bits
[8 * (sizeof val_long
) + 1];
474 char buf
[8 * (sizeof val_long
) + 32];
479 width
= 8 * (sizeof val_long
);
496 error ("Undefined output size \"%c\".", size
);
502 bits
[width
] = (val_long
& 1) ? '1' : '0';
507 while (*cp
&& *cp
== '0')
512 strcpy (buf
, local_binary_format_prefix ());
514 strcat (buf
, local_binary_format_suffix ());
515 fputs_filtered (buf
, stream
);
520 error ("Undefined output format \"%c\".", format
);
524 /* Specify default address for `x' command.
525 `info lines' uses this. */
528 set_next_address (CORE_ADDR addr
)
532 /* Make address available to the user as $_. */
533 set_internalvar (lookup_internalvar ("_"),
534 value_from_pointer (lookup_pointer_type (builtin_type_void
),
538 /* Optionally print address ADDR symbolically as <SYMBOL+OFFSET> on STREAM,
539 after LEADIN. Print nothing if no symbolic name is found nearby.
540 Optionally also print source file and line number, if available.
541 DO_DEMANGLE controls whether to print a symbol in its native "raw" form,
542 or to interpret it as a possible C++ name and convert it back to source
543 form. However note that DO_DEMANGLE can be overridden by the specific
544 settings of the demangle and asm_demangle variables. */
547 print_address_symbolic (CORE_ADDR addr
, struct ui_file
*stream
, int do_demangle
,
551 char *filename
= NULL
;
556 /* throw away both name and filename */
557 struct cleanup
*cleanup_chain
= make_cleanup (free_current_contents
, &name
);
558 make_cleanup (free_current_contents
, &filename
);
560 if (build_address_symbolic (addr
, do_demangle
, &name
, &offset
, &filename
, &line
, &unmapped
))
562 do_cleanups (cleanup_chain
);
566 fputs_filtered (leadin
, stream
);
568 fputs_filtered ("<*", stream
);
570 fputs_filtered ("<", stream
);
571 fputs_filtered (name
, stream
);
573 fprintf_filtered (stream
, "+%u", (unsigned int) offset
);
575 /* Append source filename and line number if desired. Give specific
576 line # of this addr, if we have it; else line # of the nearest symbol. */
577 if (print_symbol_filename
&& filename
!= NULL
)
580 fprintf_filtered (stream
, " at %s:%d", filename
, line
);
582 fprintf_filtered (stream
, " in %s", filename
);
585 fputs_filtered ("*>", stream
);
587 fputs_filtered (">", stream
);
589 do_cleanups (cleanup_chain
);
592 /* Given an address ADDR return all the elements needed to print the
593 address in a symbolic form. NAME can be mangled or not depending
594 on DO_DEMANGLE (and also on the asm_demangle global variable,
595 manipulated via ''set print asm-demangle''). Return 0 in case of
596 success, when all the info in the OUT paramters is valid. Return 1
599 build_address_symbolic (CORE_ADDR addr
, /* IN */
600 int do_demangle
, /* IN */
601 char **name
, /* OUT */
602 int *offset
, /* OUT */
603 char **filename
, /* OUT */
605 int *unmapped
) /* OUT */
607 struct minimal_symbol
*msymbol
;
608 struct symbol
*symbol
;
609 struct symtab
*symtab
= 0;
610 CORE_ADDR name_location
= 0;
611 asection
*section
= 0;
612 char *name_temp
= "";
614 /* Let's say it is unmapped. */
617 /* Determine if the address is in an overlay, and whether it is
619 if (overlay_debugging
)
621 section
= find_pc_overlay (addr
);
622 if (pc_in_unmapped_range (addr
, section
))
625 addr
= overlay_mapped_address (addr
, section
);
629 /* First try to find the address in the symbol table, then
630 in the minsyms. Take the closest one. */
632 /* This is defective in the sense that it only finds text symbols. So
633 really this is kind of pointless--we should make sure that the
634 minimal symbols have everything we need (by changing that we could
635 save some memory, but for many debug format--ELF/DWARF or
636 anything/stabs--it would be inconvenient to eliminate those minimal
638 msymbol
= lookup_minimal_symbol_by_pc_section (addr
, section
);
639 symbol
= find_pc_sect_function (addr
, section
);
643 name_location
= BLOCK_START (SYMBOL_BLOCK_VALUE (symbol
));
644 if (do_demangle
|| asm_demangle
)
645 name_temp
= SYMBOL_PRINT_NAME (symbol
);
647 name_temp
= DEPRECATED_SYMBOL_NAME (symbol
);
652 if (SYMBOL_VALUE_ADDRESS (msymbol
) > name_location
|| symbol
== NULL
)
654 /* The msymbol is closer to the address than the symbol;
655 use the msymbol instead. */
658 name_location
= SYMBOL_VALUE_ADDRESS (msymbol
);
659 if (do_demangle
|| asm_demangle
)
660 name_temp
= SYMBOL_PRINT_NAME (msymbol
);
662 name_temp
= DEPRECATED_SYMBOL_NAME (msymbol
);
665 if (symbol
== NULL
&& msymbol
== NULL
)
668 /* If the nearest symbol is too far away, don't print anything symbolic. */
670 /* For when CORE_ADDR is larger than unsigned int, we do math in
671 CORE_ADDR. But when we detect unsigned wraparound in the
672 CORE_ADDR math, we ignore this test and print the offset,
673 because addr+max_symbolic_offset has wrapped through the end
674 of the address space back to the beginning, giving bogus comparison. */
675 if (addr
> name_location
+ max_symbolic_offset
676 && name_location
+ max_symbolic_offset
> name_location
)
679 *offset
= addr
- name_location
;
681 *name
= xstrdup (name_temp
);
683 if (print_symbol_filename
)
685 struct symtab_and_line sal
;
687 sal
= find_pc_sect_line (addr
, section
, 0);
691 *filename
= xstrdup (sal
.symtab
->filename
);
694 else if (symtab
&& symbol
&& symbol
->line
)
696 *filename
= xstrdup (symtab
->filename
);
697 *line
= symbol
->line
;
701 *filename
= xstrdup (symtab
->filename
);
708 /* Print address ADDR on STREAM. USE_LOCAL means the same thing as for
711 print_address_numeric (CORE_ADDR addr
, int use_local
, struct ui_file
*stream
)
713 /* Truncate address to the size of a target address, avoiding shifts
714 larger or equal than the width of a CORE_ADDR. The local
715 variable ADDR_BIT stops the compiler reporting a shift overflow
716 when it won't occur. */
717 /* NOTE: This assumes that the significant address information is
718 kept in the least significant bits of ADDR - the upper bits were
719 either zero or sign extended. Should ADDRESS_TO_POINTER() or
720 some ADDRESS_TO_PRINTABLE() be used to do the conversion? */
722 int addr_bit
= TARGET_ADDR_BIT
;
724 if (addr_bit
< (sizeof (CORE_ADDR
) * HOST_CHAR_BIT
))
725 addr
&= ((CORE_ADDR
) 1 << addr_bit
) - 1;
726 print_longest (stream
, 'x', use_local
, (ULONGEST
) addr
);
729 /* Print address ADDR symbolically on STREAM.
730 First print it as a number. Then perhaps print
731 <SYMBOL + OFFSET> after the number. */
734 print_address (CORE_ADDR addr
, struct ui_file
*stream
)
736 print_address_numeric (addr
, 1, stream
);
737 print_address_symbolic (addr
, stream
, asm_demangle
, " ");
740 /* Print address ADDR symbolically on STREAM. Parameter DEMANGLE
741 controls whether to print the symbolic name "raw" or demangled.
742 Global setting "addressprint" controls whether to print hex address
746 print_address_demangle (CORE_ADDR addr
, struct ui_file
*stream
, int do_demangle
)
750 fprintf_filtered (stream
, "0");
752 else if (addressprint
)
754 print_address_numeric (addr
, 1, stream
);
755 print_address_symbolic (addr
, stream
, do_demangle
, " ");
759 print_address_symbolic (addr
, stream
, do_demangle
, "");
764 /* These are the types that $__ will get after an examine command of one
767 static struct type
*examine_i_type
;
769 static struct type
*examine_b_type
;
770 static struct type
*examine_h_type
;
771 static struct type
*examine_w_type
;
772 static struct type
*examine_g_type
;
774 /* Examine data at address ADDR in format FMT.
775 Fetch it from memory and print on gdb_stdout. */
778 do_examine (struct format_data fmt
, CORE_ADDR addr
, asection
*sect
)
783 struct type
*val_type
= NULL
;
793 /* String or instruction format implies fetch single bytes
794 regardless of the specified size. */
795 if (format
== 's' || format
== 'i')
799 val_type
= examine_i_type
;
800 else if (size
== 'b')
801 val_type
= examine_b_type
;
802 else if (size
== 'h')
803 val_type
= examine_h_type
;
804 else if (size
== 'w')
805 val_type
= examine_w_type
;
806 else if (size
== 'g')
807 val_type
= examine_g_type
;
814 if (format
== 's' || format
== 'i')
817 /* Print as many objects as specified in COUNT, at most maxelts per line,
818 with the address of the next one at the start of each line. */
823 print_address (next_address
, gdb_stdout
);
824 printf_filtered (":");
829 printf_filtered ("\t");
830 /* Note that print_formatted sets next_address for the next
832 last_examine_address
= next_address
;
834 if (last_examine_value
)
835 value_free (last_examine_value
);
837 /* The value to be displayed is not fetched greedily.
838 Instead, to avoid the posibility of a fetched value not
839 being used, its retreval is delayed until the print code
840 uses it. When examining an instruction stream, the
841 disassembler will perform its own memory fetch using just
842 the address stored in LAST_EXAMINE_VALUE. FIXME: Should
843 the disassembler be modified so that LAST_EXAMINE_VALUE
844 is left with the byte sequence from the last complete
845 instruction fetched from memory? */
846 last_examine_value
= value_at_lazy (val_type
, next_address
, sect
);
848 if (last_examine_value
)
849 release_value (last_examine_value
);
851 print_formatted (last_examine_value
, format
, size
, gdb_stdout
);
853 printf_filtered ("\n");
854 gdb_flush (gdb_stdout
);
859 validate_format (struct format_data fmt
, char *cmdname
)
862 error ("Size letters are meaningless in \"%s\" command.", cmdname
);
864 error ("Item count other than 1 is meaningless in \"%s\" command.",
866 if (fmt
.format
== 'i' || fmt
.format
== 's')
867 error ("Format letter \"%c\" is meaningless in \"%s\" command.",
868 fmt
.format
, cmdname
);
871 /* Evaluate string EXP as an expression in the current language and
872 print the resulting value. EXP may contain a format specifier as the
873 first argument ("/x myvar" for example, to print myvar in hex).
877 print_command_1 (char *exp
, int inspect
, int voidprint
)
879 struct expression
*expr
;
880 struct cleanup
*old_chain
= 0;
883 struct format_data fmt
;
886 /* Pass inspect flag to the rest of the print routines in a global (sigh). */
887 inspect_it
= inspect
;
889 if (exp
&& *exp
== '/')
892 fmt
= decode_format (&exp
, last_format
, 0);
893 validate_format (fmt
, "print");
894 last_format
= format
= fmt
.format
;
906 expr
= parse_expression (exp
);
907 old_chain
= make_cleanup (free_current_contents
, &expr
);
909 val
= evaluate_expression (expr
);
912 val
= access_value_history (0);
914 if (voidprint
|| (val
&& VALUE_TYPE (val
) &&
915 TYPE_CODE (VALUE_TYPE (val
)) != TYPE_CODE_VOID
))
917 int histindex
= record_latest_value (val
);
920 annotate_value_history_begin (histindex
, VALUE_TYPE (val
));
922 annotate_value_begin (VALUE_TYPE (val
));
925 printf_unfiltered ("\031(gdb-makebuffer \"%s\" %d '(\"", exp
, histindex
);
926 else if (histindex
>= 0)
927 printf_filtered ("$%d = ", histindex
);
930 annotate_value_history_value ();
932 print_formatted (val
, format
, fmt
.size
, gdb_stdout
);
933 printf_filtered ("\n");
936 annotate_value_history_end ();
938 annotate_value_end ();
941 printf_unfiltered ("\") )\030");
945 do_cleanups (old_chain
);
946 inspect_it
= 0; /* Reset print routines to normal */
950 print_command (char *exp
, int from_tty
)
952 print_command_1 (exp
, 0, 1);
955 /* Same as print, except in epoch, it gets its own window */
957 inspect_command (char *exp
, int from_tty
)
959 extern int epoch_interface
;
961 print_command_1 (exp
, epoch_interface
, 1);
964 /* Same as print, except it doesn't print void results. */
966 call_command (char *exp
, int from_tty
)
968 print_command_1 (exp
, 0, 0);
972 output_command (char *exp
, int from_tty
)
974 struct expression
*expr
;
975 struct cleanup
*old_chain
;
978 struct format_data fmt
;
980 if (exp
&& *exp
== '/')
983 fmt
= decode_format (&exp
, 0, 0);
984 validate_format (fmt
, "output");
988 expr
= parse_expression (exp
);
989 old_chain
= make_cleanup (free_current_contents
, &expr
);
991 val
= evaluate_expression (expr
);
993 annotate_value_begin (VALUE_TYPE (val
));
995 print_formatted (val
, format
, fmt
.size
, gdb_stdout
);
997 annotate_value_end ();
1000 gdb_flush (gdb_stdout
);
1002 do_cleanups (old_chain
);
1006 set_command (char *exp
, int from_tty
)
1008 struct expression
*expr
= parse_expression (exp
);
1009 struct cleanup
*old_chain
=
1010 make_cleanup (free_current_contents
, &expr
);
1011 evaluate_expression (expr
);
1012 do_cleanups (old_chain
);
1016 sym_info (char *arg
, int from_tty
)
1018 struct minimal_symbol
*msymbol
;
1019 struct objfile
*objfile
;
1020 struct obj_section
*osect
;
1022 CORE_ADDR addr
, sect_addr
;
1024 unsigned int offset
;
1027 error_no_arg ("address");
1029 addr
= parse_and_eval_address (arg
);
1030 ALL_OBJSECTIONS (objfile
, osect
)
1032 sect
= osect
->the_bfd_section
;
1033 sect_addr
= overlay_mapped_address (addr
, sect
);
1035 if (osect
->addr
<= sect_addr
&& sect_addr
< osect
->endaddr
&&
1036 (msymbol
= lookup_minimal_symbol_by_pc_section (sect_addr
, sect
)))
1039 offset
= sect_addr
- SYMBOL_VALUE_ADDRESS (msymbol
);
1041 printf_filtered ("%s + %u in ",
1042 SYMBOL_PRINT_NAME (msymbol
), offset
);
1044 printf_filtered ("%s in ",
1045 SYMBOL_PRINT_NAME (msymbol
));
1046 if (pc_in_unmapped_range (addr
, sect
))
1047 printf_filtered ("load address range of ");
1048 if (section_is_overlay (sect
))
1049 printf_filtered ("%s overlay ",
1050 section_is_mapped (sect
) ? "mapped" : "unmapped");
1051 printf_filtered ("section %s", sect
->name
);
1052 printf_filtered ("\n");
1056 printf_filtered ("No symbol matches %s.\n", arg
);
1060 address_info (char *exp
, int from_tty
)
1063 struct minimal_symbol
*msymbol
;
1067 CORE_ADDR load_addr
;
1068 int is_a_field_of_this
; /* C++: lookup_symbol sets this to nonzero
1069 if exp is a field of `this'. */
1072 error ("Argument required.");
1074 sym
= lookup_symbol (exp
, get_selected_block (0), VAR_DOMAIN
,
1075 &is_a_field_of_this
, (struct symtab
**) NULL
);
1078 if (is_a_field_of_this
)
1080 printf_filtered ("Symbol \"");
1081 fprintf_symbol_filtered (gdb_stdout
, exp
,
1082 current_language
->la_language
, DMGL_ANSI
);
1083 printf_filtered ("\" is a field of the local class variable ");
1084 if (current_language
->la_language
== language_objc
)
1085 printf_filtered ("`self'\n"); /* ObjC equivalent of "this" */
1087 printf_filtered ("`this'\n");
1091 msymbol
= lookup_minimal_symbol (exp
, NULL
, NULL
);
1093 if (msymbol
!= NULL
)
1095 load_addr
= SYMBOL_VALUE_ADDRESS (msymbol
);
1097 printf_filtered ("Symbol \"");
1098 fprintf_symbol_filtered (gdb_stdout
, exp
,
1099 current_language
->la_language
, DMGL_ANSI
);
1100 printf_filtered ("\" is at ");
1101 print_address_numeric (load_addr
, 1, gdb_stdout
);
1102 printf_filtered (" in a file compiled without debugging");
1103 section
= SYMBOL_BFD_SECTION (msymbol
);
1104 if (section_is_overlay (section
))
1106 load_addr
= overlay_unmapped_address (load_addr
, section
);
1107 printf_filtered (",\n -- loaded at ");
1108 print_address_numeric (load_addr
, 1, gdb_stdout
);
1109 printf_filtered (" in overlay section %s", section
->name
);
1111 printf_filtered (".\n");
1114 error ("No symbol \"%s\" in current context.", exp
);
1118 printf_filtered ("Symbol \"");
1119 fprintf_symbol_filtered (gdb_stdout
, DEPRECATED_SYMBOL_NAME (sym
),
1120 current_language
->la_language
, DMGL_ANSI
);
1121 printf_filtered ("\" is ");
1122 val
= SYMBOL_VALUE (sym
);
1123 basereg
= SYMBOL_BASEREG (sym
);
1124 section
= SYMBOL_BFD_SECTION (sym
);
1126 switch (SYMBOL_CLASS (sym
))
1129 case LOC_CONST_BYTES
:
1130 printf_filtered ("constant");
1134 printf_filtered ("a label at address ");
1135 print_address_numeric (load_addr
= SYMBOL_VALUE_ADDRESS (sym
),
1137 if (section_is_overlay (section
))
1139 load_addr
= overlay_unmapped_address (load_addr
, section
);
1140 printf_filtered (",\n -- loaded at ");
1141 print_address_numeric (load_addr
, 1, gdb_stdout
);
1142 printf_filtered (" in overlay section %s", section
->name
);
1147 case LOC_COMPUTED_ARG
:
1148 /* FIXME: cagney/2004-01-26: It should be possible to
1149 unconditionally call the SYMBOL_OPS method when available.
1150 Unfortunately DWARF 2 stores the frame-base (instead of the
1151 function) location in a function's symbol. Oops! For the
1152 moment enable this when/where applicable. */
1153 SYMBOL_OPS (sym
)->describe_location (sym
, gdb_stdout
);
1157 printf_filtered ("a variable in register %s", REGISTER_NAME (val
));
1161 printf_filtered ("static storage at address ");
1162 print_address_numeric (load_addr
= SYMBOL_VALUE_ADDRESS (sym
),
1164 if (section_is_overlay (section
))
1166 load_addr
= overlay_unmapped_address (load_addr
, section
);
1167 printf_filtered (",\n -- loaded at ");
1168 print_address_numeric (load_addr
, 1, gdb_stdout
);
1169 printf_filtered (" in overlay section %s", section
->name
);
1174 printf_filtered ("external global (indirect addressing), at address *(");
1175 print_address_numeric (load_addr
= SYMBOL_VALUE_ADDRESS (sym
),
1177 printf_filtered (")");
1178 if (section_is_overlay (section
))
1180 load_addr
= overlay_unmapped_address (load_addr
, section
);
1181 printf_filtered (",\n -- loaded at ");
1182 print_address_numeric (load_addr
, 1, gdb_stdout
);
1183 printf_filtered (" in overlay section %s", section
->name
);
1188 printf_filtered ("an argument in register %s", REGISTER_NAME (val
));
1191 case LOC_REGPARM_ADDR
:
1192 printf_filtered ("address of an argument in register %s", REGISTER_NAME (val
));
1196 printf_filtered ("an argument at offset %ld", val
);
1200 printf_filtered ("an argument at frame offset %ld", val
);
1204 printf_filtered ("a local variable at frame offset %ld", val
);
1208 printf_filtered ("a reference argument at offset %ld", val
);
1212 printf_filtered ("a variable at offset %ld from register %s",
1213 val
, REGISTER_NAME (basereg
));
1216 case LOC_BASEREG_ARG
:
1217 printf_filtered ("an argument at offset %ld from register %s",
1218 val
, REGISTER_NAME (basereg
));
1222 printf_filtered ("a typedef");
1226 printf_filtered ("a function at address ");
1227 print_address_numeric (load_addr
= BLOCK_START (SYMBOL_BLOCK_VALUE (sym
)),
1229 if (section_is_overlay (section
))
1231 load_addr
= overlay_unmapped_address (load_addr
, section
);
1232 printf_filtered (",\n -- loaded at ");
1233 print_address_numeric (load_addr
, 1, gdb_stdout
);
1234 printf_filtered (" in overlay section %s", section
->name
);
1238 case LOC_UNRESOLVED
:
1240 struct minimal_symbol
*msym
;
1242 msym
= lookup_minimal_symbol (DEPRECATED_SYMBOL_NAME (sym
), NULL
, NULL
);
1244 printf_filtered ("unresolved");
1247 section
= SYMBOL_BFD_SECTION (msym
);
1248 printf_filtered ("static storage at address ");
1249 print_address_numeric (load_addr
= SYMBOL_VALUE_ADDRESS (msym
),
1251 if (section_is_overlay (section
))
1253 load_addr
= overlay_unmapped_address (load_addr
, section
);
1254 printf_filtered (",\n -- loaded at ");
1255 print_address_numeric (load_addr
, 1, gdb_stdout
);
1256 printf_filtered (" in overlay section %s", section
->name
);
1262 case LOC_HP_THREAD_LOCAL_STATIC
:
1264 "a thread-local variable at offset %ld from the thread base register %s",
1265 val
, REGISTER_NAME (basereg
));
1268 case LOC_OPTIMIZED_OUT
:
1269 printf_filtered ("optimized out");
1273 printf_filtered ("of unknown (botched) type");
1276 printf_filtered (".\n");
1280 x_command (char *exp
, int from_tty
)
1282 struct expression
*expr
;
1283 struct format_data fmt
;
1284 struct cleanup
*old_chain
;
1287 fmt
.format
= last_format
;
1288 fmt
.size
= last_size
;
1291 if (exp
&& *exp
== '/')
1294 fmt
= decode_format (&exp
, last_format
, last_size
);
1297 /* If we have an expression, evaluate it and use it as the address. */
1299 if (exp
!= 0 && *exp
!= 0)
1301 expr
= parse_expression (exp
);
1302 /* Cause expression not to be there any more
1303 if this command is repeated with Newline.
1304 But don't clobber a user-defined command's definition. */
1307 old_chain
= make_cleanup (free_current_contents
, &expr
);
1308 val
= evaluate_expression (expr
);
1309 if (TYPE_CODE (VALUE_TYPE (val
)) == TYPE_CODE_REF
)
1310 val
= value_ind (val
);
1311 /* In rvalue contexts, such as this, functions are coerced into
1312 pointers to functions. This makes "x/i main" work. */
1313 if (/* last_format == 'i' && */
1314 TYPE_CODE (VALUE_TYPE (val
)) == TYPE_CODE_FUNC
1315 && VALUE_LVAL (val
) == lval_memory
)
1316 next_address
= VALUE_ADDRESS (val
);
1318 next_address
= value_as_address (val
);
1319 if (VALUE_BFD_SECTION (val
))
1320 next_section
= VALUE_BFD_SECTION (val
);
1321 do_cleanups (old_chain
);
1324 do_examine (fmt
, next_address
, next_section
);
1326 /* If the examine succeeds, we remember its size and format for next time. */
1327 last_size
= fmt
.size
;
1328 last_format
= fmt
.format
;
1330 /* Set a couple of internal variables if appropriate. */
1331 if (last_examine_value
)
1333 /* Make last address examined available to the user as $_. Use
1334 the correct pointer type. */
1335 struct type
*pointer_type
1336 = lookup_pointer_type (VALUE_TYPE (last_examine_value
));
1337 set_internalvar (lookup_internalvar ("_"),
1338 value_from_pointer (pointer_type
,
1339 last_examine_address
));
1341 /* Make contents of last address examined available to the user as $__. */
1342 /* If the last value has not been fetched from memory then don't
1343 fetch it now - instead mark it by voiding the $__ variable. */
1344 if (VALUE_LAZY (last_examine_value
))
1345 set_internalvar (lookup_internalvar ("__"),
1346 allocate_value (builtin_type_void
));
1348 set_internalvar (lookup_internalvar ("__"), last_examine_value
);
1353 /* Add an expression to the auto-display chain.
1354 Specify the expression. */
1357 display_command (char *exp
, int from_tty
)
1359 struct format_data fmt
;
1360 struct expression
*expr
;
1361 struct display
*new;
1365 /* NOTE: cagney/2003-02-13 The `tui_active' was previously
1367 if (tui_active
&& *exp
== '$')
1368 display_it
= (tui_set_layout_for_display_command (exp
) == TUI_FAILURE
);
1382 fmt
= decode_format (&exp
, 0, 0);
1383 if (fmt
.size
&& fmt
.format
== 0)
1385 if (fmt
.format
== 'i' || fmt
.format
== 's')
1395 innermost_block
= 0;
1396 expr
= parse_expression (exp
);
1398 new = (struct display
*) xmalloc (sizeof (struct display
));
1401 new->block
= innermost_block
;
1402 new->next
= display_chain
;
1403 new->number
= ++display_number
;
1406 display_chain
= new;
1408 if (from_tty
&& target_has_execution
)
1409 do_one_display (new);
1416 free_display (struct display
*d
)
1422 /* Clear out the display_chain.
1423 Done when new symtabs are loaded, since this invalidates
1424 the types stored in many expressions. */
1427 clear_displays (void)
1431 while ((d
= display_chain
) != NULL
)
1434 display_chain
= d
->next
;
1439 /* Delete the auto-display number NUM. */
1442 delete_display (int num
)
1444 struct display
*d1
, *d
;
1447 error ("No display number %d.", num
);
1449 if (display_chain
->number
== num
)
1452 display_chain
= d1
->next
;
1456 for (d
= display_chain
;; d
= d
->next
)
1459 error ("No display number %d.", num
);
1460 if (d
->next
->number
== num
)
1470 /* Delete some values from the auto-display chain.
1471 Specify the element numbers. */
1474 undisplay_command (char *args
, int from_tty
)
1482 if (query ("Delete all auto-display expressions? "))
1491 while (*p1
>= '0' && *p1
<= '9')
1493 if (*p1
&& *p1
!= ' ' && *p1
!= '\t')
1494 error ("Arguments must be display numbers.");
1498 delete_display (num
);
1501 while (*p
== ' ' || *p
== '\t')
1507 /* Display a single auto-display.
1508 Do nothing if the display cannot be printed in the current context,
1509 or if the display is disabled. */
1512 do_one_display (struct display
*d
)
1514 int within_current_scope
;
1516 if (d
->enabled_p
== 0)
1520 within_current_scope
= contained_in (get_selected_block (0), d
->block
);
1522 within_current_scope
= 1;
1523 if (!within_current_scope
)
1526 current_display_number
= d
->number
;
1528 annotate_display_begin ();
1529 printf_filtered ("%d", d
->number
);
1530 annotate_display_number_end ();
1531 printf_filtered (": ");
1537 annotate_display_format ();
1539 printf_filtered ("x/");
1540 if (d
->format
.count
!= 1)
1541 printf_filtered ("%d", d
->format
.count
);
1542 printf_filtered ("%c", d
->format
.format
);
1543 if (d
->format
.format
!= 'i' && d
->format
.format
!= 's')
1544 printf_filtered ("%c", d
->format
.size
);
1545 printf_filtered (" ");
1547 annotate_display_expression ();
1549 print_expression (d
->exp
, gdb_stdout
);
1550 annotate_display_expression_end ();
1552 if (d
->format
.count
!= 1)
1553 printf_filtered ("\n");
1555 printf_filtered (" ");
1557 val
= evaluate_expression (d
->exp
);
1558 addr
= value_as_address (val
);
1559 if (d
->format
.format
== 'i')
1560 addr
= ADDR_BITS_REMOVE (addr
);
1562 annotate_display_value ();
1564 do_examine (d
->format
, addr
, VALUE_BFD_SECTION (val
));
1568 annotate_display_format ();
1570 if (d
->format
.format
)
1571 printf_filtered ("/%c ", d
->format
.format
);
1573 annotate_display_expression ();
1575 print_expression (d
->exp
, gdb_stdout
);
1576 annotate_display_expression_end ();
1578 printf_filtered (" = ");
1580 annotate_display_expression ();
1582 print_formatted (evaluate_expression (d
->exp
),
1583 d
->format
.format
, d
->format
.size
, gdb_stdout
);
1584 printf_filtered ("\n");
1587 annotate_display_end ();
1589 gdb_flush (gdb_stdout
);
1590 current_display_number
= -1;
1593 /* Display all of the values on the auto-display chain which can be
1594 evaluated in the current scope. */
1601 for (d
= display_chain
; d
; d
= d
->next
)
1605 /* Delete the auto-display which we were in the process of displaying.
1606 This is done when there is an error or a signal. */
1609 disable_display (int num
)
1613 for (d
= display_chain
; d
; d
= d
->next
)
1614 if (d
->number
== num
)
1619 printf_unfiltered ("No display number %d.\n", num
);
1623 disable_current_display (void)
1625 if (current_display_number
>= 0)
1627 disable_display (current_display_number
);
1628 fprintf_unfiltered (gdb_stderr
, "Disabling display %d to avoid infinite recursion.\n",
1629 current_display_number
);
1631 current_display_number
= -1;
1635 display_info (char *ignore
, int from_tty
)
1640 printf_unfiltered ("There are no auto-display expressions now.\n");
1642 printf_filtered ("Auto-display expressions now in effect:\n\
1643 Num Enb Expression\n");
1645 for (d
= display_chain
; d
; d
= d
->next
)
1647 printf_filtered ("%d: %c ", d
->number
, "ny"[(int) d
->enabled_p
]);
1649 printf_filtered ("/%d%c%c ", d
->format
.count
, d
->format
.size
,
1651 else if (d
->format
.format
)
1652 printf_filtered ("/%c ", d
->format
.format
);
1653 print_expression (d
->exp
, gdb_stdout
);
1654 if (d
->block
&& !contained_in (get_selected_block (0), d
->block
))
1655 printf_filtered (" (cannot be evaluated in the current context)");
1656 printf_filtered ("\n");
1657 gdb_flush (gdb_stdout
);
1662 enable_display (char *args
, int from_tty
)
1671 for (d
= display_chain
; d
; d
= d
->next
)
1678 while (*p1
>= '0' && *p1
<= '9')
1680 if (*p1
&& *p1
!= ' ' && *p1
!= '\t')
1681 error ("Arguments must be display numbers.");
1685 for (d
= display_chain
; d
; d
= d
->next
)
1686 if (d
->number
== num
)
1691 printf_unfiltered ("No display number %d.\n", num
);
1694 while (*p
== ' ' || *p
== '\t')
1700 disable_display_command (char *args
, int from_tty
)
1708 for (d
= display_chain
; d
; d
= d
->next
)
1715 while (*p1
>= '0' && *p1
<= '9')
1717 if (*p1
&& *p1
!= ' ' && *p1
!= '\t')
1718 error ("Arguments must be display numbers.");
1720 disable_display (atoi (p
));
1723 while (*p
== ' ' || *p
== '\t')
1729 /* Print the value in stack frame FRAME of a variable
1730 specified by a struct symbol. */
1733 print_variable_value (struct symbol
*var
, struct frame_info
*frame
,
1734 struct ui_file
*stream
)
1736 struct value
*val
= read_var_value (var
, frame
);
1738 value_print (val
, stream
, 0, Val_pretty_default
);
1742 printf_command (char *arg
, int from_tty
)
1746 char *string
= NULL
;
1747 struct value
**val_args
;
1749 char *current_substring
;
1751 int allocated_args
= 20;
1752 struct cleanup
*old_cleanups
;
1754 val_args
= (struct value
**) xmalloc (allocated_args
1755 * sizeof (struct value
*));
1756 old_cleanups
= make_cleanup (free_current_contents
, &val_args
);
1759 error_no_arg ("format-control string and values to print");
1761 /* Skip white space before format string */
1762 while (*s
== ' ' || *s
== '\t')
1765 /* A format string should follow, enveloped in double quotes */
1767 error ("Bad format string, missing '\"'.");
1769 /* Parse the format-control string and copy it into the string STRING,
1770 processing some kinds of escape sequence. */
1772 f
= string
= (char *) alloca (strlen (s
) + 1);
1780 error ("Bad format string, non-terminated '\"'.");
1813 /* ??? TODO: handle other escape sequences */
1814 error ("Unrecognized escape character \\%c in format string.",
1824 /* Skip over " and following space and comma. */
1827 while (*s
== ' ' || *s
== '\t')
1830 if (*s
!= ',' && *s
!= 0)
1831 error ("Invalid argument syntax");
1835 while (*s
== ' ' || *s
== '\t')
1838 /* Need extra space for the '\0's. Doubling the size is sufficient. */
1839 substrings
= alloca (strlen (string
) * 2);
1840 current_substring
= substrings
;
1843 /* Now scan the string for %-specs and see what kinds of args they want.
1844 argclass[I] classifies the %-specs so we can give printf_filtered
1845 something of the right size. */
1849 no_arg
, int_arg
, string_arg
, double_arg
, long_long_arg
1851 enum argclass
*argclass
;
1852 enum argclass this_argclass
;
1858 argclass
= (enum argclass
*) alloca (strlen (s
) * sizeof *argclass
);
1866 while (strchr ("0123456789.hlL-+ #", *f
))
1868 if (*f
== 'l' || *f
== 'L')
1875 this_argclass
= string_arg
;
1881 this_argclass
= double_arg
;
1885 error ("`*' not supported for precision or width in printf");
1888 error ("Format specifier `n' not supported in printf");
1891 this_argclass
= no_arg
;
1896 this_argclass
= long_long_arg
;
1898 this_argclass
= int_arg
;
1902 if (this_argclass
!= no_arg
)
1904 strncpy (current_substring
, last_arg
, f
- last_arg
);
1905 current_substring
+= f
- last_arg
;
1906 *current_substring
++ = '\0';
1908 argclass
[nargs_wanted
++] = this_argclass
;
1912 /* Now, parse all arguments and evaluate them.
1913 Store the VALUEs in VAL_ARGS. */
1918 if (nargs
== allocated_args
)
1919 val_args
= (struct value
**) xrealloc ((char *) val_args
,
1920 (allocated_args
*= 2)
1921 * sizeof (struct value
*));
1923 val_args
[nargs
] = parse_to_comma_and_eval (&s1
);
1925 /* If format string wants a float, unchecked-convert the value to
1926 floating point of the same size */
1928 if (argclass
[nargs
] == double_arg
)
1930 struct type
*type
= VALUE_TYPE (val_args
[nargs
]);
1931 if (TYPE_LENGTH (type
) == sizeof (float))
1932 VALUE_TYPE (val_args
[nargs
]) = builtin_type_float
;
1933 if (TYPE_LENGTH (type
) == sizeof (double))
1934 VALUE_TYPE (val_args
[nargs
]) = builtin_type_double
;
1942 if (nargs
!= nargs_wanted
)
1943 error ("Wrong number of arguments for specified format-string");
1945 /* Now actually print them. */
1946 current_substring
= substrings
;
1947 for (i
= 0; i
< nargs
; i
++)
1949 switch (argclass
[i
])
1956 tem
= value_as_address (val_args
[i
]);
1958 /* This is a %s argument. Find the length of the string. */
1963 read_memory (tem
+ j
, &c
, 1);
1968 /* Copy the string contents into a string inside GDB. */
1969 str
= (char *) alloca (j
+ 1);
1971 read_memory (tem
, str
, j
);
1974 printf_filtered (current_substring
, str
);
1979 double val
= value_as_double (val_args
[i
]);
1980 printf_filtered (current_substring
, val
);
1984 #if defined (CC_HAS_LONG_LONG) && defined (PRINTF_HAS_LONG_LONG)
1986 long long val
= value_as_long (val_args
[i
]);
1987 printf_filtered (current_substring
, val
);
1991 error ("long long not supported in printf");
1995 /* FIXME: there should be separate int_arg and long_arg. */
1996 long val
= value_as_long (val_args
[i
]);
1997 printf_filtered (current_substring
, val
);
2000 default: /* purecov: deadcode */
2001 error ("internal error in printf_command"); /* purecov: deadcode */
2003 /* Skip to the next substring. */
2004 current_substring
+= strlen (current_substring
) + 1;
2006 /* Print the portion of the format string after the last argument. */
2007 puts_filtered (last_arg
);
2009 do_cleanups (old_cleanups
);
2013 _initialize_printcmd (void)
2015 struct cmd_list_element
*c
;
2017 current_display_number
= -1;
2019 add_info ("address", address_info
,
2020 "Describe where symbol SYM is stored.");
2022 add_info ("symbol", sym_info
,
2023 "Describe what symbol is at location ADDR.\n\
2024 Only for symbols with fixed locations (global or static scope).");
2026 add_com ("x", class_vars
, x_command
,
2027 concat ("Examine memory: x/FMT ADDRESS.\n\
2028 ADDRESS is an expression for the memory address to examine.\n\
2029 FMT is a repeat count followed by a format letter and a size letter.\n\
2030 Format letters are o(octal), x(hex), d(decimal), u(unsigned decimal),\n\
2031 t(binary), f(float), a(address), i(instruction), c(char) and s(string).\n",
2032 "Size letters are b(byte), h(halfword), w(word), g(giant, 8 bytes).\n\
2033 The specified number of objects of the specified size are printed\n\
2034 according to the format.\n\n\
2035 Defaults for format and size letters are those previously used.\n\
2036 Default count is 1. Default address is following last thing printed\n\
2037 with this command or \"print\".", NULL
));
2040 add_com ("whereis", class_vars
, whereis_command
,
2041 "Print line number and file of definition of variable.");
2044 add_info ("display", display_info
,
2045 "Expressions to display when program stops, with code numbers.");
2047 add_cmd ("undisplay", class_vars
, undisplay_command
,
2048 "Cancel some expressions to be displayed when program stops.\n\
2049 Arguments are the code numbers of the expressions to stop displaying.\n\
2050 No argument means cancel all automatic-display expressions.\n\
2051 \"delete display\" has the same effect as this command.\n\
2052 Do \"info display\" to see current list of code numbers.",
2055 add_com ("display", class_vars
, display_command
,
2056 "Print value of expression EXP each time the program stops.\n\
2057 /FMT may be used before EXP as in the \"print\" command.\n\
2058 /FMT \"i\" or \"s\" or including a size-letter is allowed,\n\
2059 as in the \"x\" command, and then EXP is used to get the address to examine\n\
2060 and examining is done as in the \"x\" command.\n\n\
2061 With no argument, display all currently requested auto-display expressions.\n\
2062 Use \"undisplay\" to cancel display requests previously made."
2065 add_cmd ("display", class_vars
, enable_display
,
2066 "Enable some expressions to be displayed when program stops.\n\
2067 Arguments are the code numbers of the expressions to resume displaying.\n\
2068 No argument means enable all automatic-display expressions.\n\
2069 Do \"info display\" to see current list of code numbers.", &enablelist
);
2071 add_cmd ("display", class_vars
, disable_display_command
,
2072 "Disable some expressions to be displayed when program stops.\n\
2073 Arguments are the code numbers of the expressions to stop displaying.\n\
2074 No argument means disable all automatic-display expressions.\n\
2075 Do \"info display\" to see current list of code numbers.", &disablelist
);
2077 add_cmd ("display", class_vars
, undisplay_command
,
2078 "Cancel some expressions to be displayed when program stops.\n\
2079 Arguments are the code numbers of the expressions to stop displaying.\n\
2080 No argument means cancel all automatic-display expressions.\n\
2081 Do \"info display\" to see current list of code numbers.", &deletelist
);
2083 add_com ("printf", class_vars
, printf_command
,
2084 "printf \"printf format string\", arg1, arg2, arg3, ..., argn\n\
2085 This is useful for formatted output in user-defined commands.");
2087 add_com ("output", class_vars
, output_command
,
2088 "Like \"print\" but don't put in value history and don't print newline.\n\
2089 This is useful in user-defined commands.");
2091 add_prefix_cmd ("set", class_vars
, set_command
,
2092 concat ("Evaluate expression EXP and assign result to variable VAR, using assignment\n\
2093 syntax appropriate for the current language (VAR = EXP or VAR := EXP for\n\
2094 example). VAR may be a debugger \"convenience\" variable (names starting\n\
2095 with $), a register (a few standard names starting with $), or an actual\n\
2096 variable in the program being debugged. EXP is any valid expression.\n",
2097 "Use \"set variable\" for variables with names identical to set subcommands.\n\
2098 \nWith a subcommand, this command modifies parts of the gdb environment.\n\
2099 You can see these environment settings with the \"show\" command.", NULL
),
2100 &setlist
, "set ", 1, &cmdlist
);
2102 add_com ("assign", class_vars
, set_command
, concat ("Evaluate expression \
2103 EXP and assign result to variable VAR, using assignment\n\
2104 syntax appropriate for the current language (VAR = EXP or VAR := EXP for\n\
2105 example). VAR may be a debugger \"convenience\" variable (names starting\n\
2106 with $), a register (a few standard names starting with $), or an actual\n\
2107 variable in the program being debugged. EXP is any valid expression.\n",
2108 "Use \"set variable\" for variables with names identical to set subcommands.\n\
2109 \nWith a subcommand, this command modifies parts of the gdb environment.\n\
2110 You can see these environment settings with the \"show\" command.", NULL
));
2112 /* "call" is the same as "set", but handy for dbx users to call fns. */
2113 c
= add_com ("call", class_vars
, call_command
,
2114 "Call a function in the program.\n\
2115 The argument is the function name and arguments, in the notation of the\n\
2116 current working language. The result is printed and saved in the value\n\
2117 history, if it is not void.");
2118 set_cmd_completer (c
, location_completer
);
2120 add_cmd ("variable", class_vars
, set_command
,
2121 "Evaluate expression EXP and assign result to variable VAR, using assignment\n\
2122 syntax appropriate for the current language (VAR = EXP or VAR := EXP for\n\
2123 example). VAR may be a debugger \"convenience\" variable (names starting\n\
2124 with $), a register (a few standard names starting with $), or an actual\n\
2125 variable in the program being debugged. EXP is any valid expression.\n\
2126 This may usually be abbreviated to simply \"set\".",
2129 c
= add_com ("print", class_vars
, print_command
,
2130 concat ("Print value of expression EXP.\n\
2131 Variables accessible are those of the lexical environment of the selected\n\
2132 stack frame, plus all those whose scope is global or an entire file.\n\
2134 $NUM gets previous value number NUM. $ and $$ are the last two values.\n\
2135 $$NUM refers to NUM'th value back from the last one.\n\
2136 Names starting with $ refer to registers (with the values they would have\n",
2137 "if the program were to return to the stack frame now selected, restoring\n\
2138 all registers saved by frames farther in) or else to debugger\n\
2139 \"convenience\" variables (any such name not a known register).\n\
2140 Use assignment expressions to give values to convenience variables.\n",
2142 {TYPE}ADREXP refers to a datum of data type TYPE, located at address ADREXP.\n\
2143 @ is a binary operator for treating consecutive data objects\n\
2144 anywhere in memory as an array. FOO@NUM gives an array whose first\n\
2145 element is FOO, whose second element is stored in the space following\n\
2146 where FOO is stored, etc. FOO must be an expression whose value\n\
2147 resides in memory.\n",
2149 EXP may be preceded with /FMT, where FMT is a format letter\n\
2150 but no count or size letter (see \"x\" command).", NULL
));
2151 set_cmd_completer (c
, location_completer
);
2152 add_com_alias ("p", "print", class_vars
, 1);
2154 c
= add_com ("inspect", class_vars
, inspect_command
,
2155 "Same as \"print\" command, except that if you are running in the epoch\n\
2156 environment, the value is printed in its own window.");
2157 set_cmd_completer (c
, location_completer
);
2160 add_set_cmd ("max-symbolic-offset", no_class
, var_uinteger
,
2161 (char *) &max_symbolic_offset
,
2162 "Set the largest offset that will be printed in <symbol+1234> form.",
2166 add_set_cmd ("symbol-filename", no_class
, var_boolean
,
2167 (char *) &print_symbol_filename
,
2168 "Set printing of source filename and line number with <symbol>.",
2172 /* For examine/instruction a single byte quantity is specified as
2173 the data. This avoids problems with value_at_lazy() requiring a
2174 valid data type (and rejecting VOID). */
2175 examine_i_type
= init_type (TYPE_CODE_INT
, 1, 0, "examine_i_type", NULL
);
2177 examine_b_type
= init_type (TYPE_CODE_INT
, 1, 0, "examine_b_type", NULL
);
2178 examine_h_type
= init_type (TYPE_CODE_INT
, 2, 0, "examine_h_type", NULL
);
2179 examine_w_type
= init_type (TYPE_CODE_INT
, 4, 0, "examine_w_type", NULL
);
2180 examine_g_type
= init_type (TYPE_CODE_INT
, 8, 0, "examine_g_type", NULL
);