1 /* Print values for GNU debugger GDB.
2 Copyright 1986, 87, 88, 89, 90, 91, 93, 94, 95, 1998
3 Free Software Foundation, Inc.
5 This file is part of GDB.
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
22 #include "gdb_string.h"
28 #include "expression.h"
32 #include "breakpoint.h"
36 #include "symfile.h" /* for overlay functions */
37 #include "objfiles.h" /* ditto */
39 extern int asm_demangle
; /* Whether to demangle syms in asm printouts */
40 extern int addressprint
; /* Whether to print hex addresses in HLL " */
49 /* Last specified output format. */
51 static char last_format
= 'x';
53 /* Last specified examination size. 'b', 'h', 'w' or `q'. */
55 static char last_size
= 'w';
57 /* Default address to examine next. */
59 static CORE_ADDR next_address
;
61 /* Default section to examine next. */
63 static asection
*next_section
;
65 /* Last address examined. */
67 static CORE_ADDR last_examine_address
;
69 /* Contents of last address examined.
70 This is not valid past the end of the `x' command! */
72 static value_ptr last_examine_value
;
74 /* Largest offset between a symbolic value and an address, that will be
75 printed as `0x1234 <symbol+offset>'. */
77 static unsigned int max_symbolic_offset
= UINT_MAX
;
79 /* Append the source filename and linenumber of the symbol when
80 printing a symbolic value as `<symbol at filename:linenum>' if set. */
81 static int print_symbol_filename
= 0;
83 /* Number of auto-display expression currently being displayed.
84 So that we can disable it if we get an error or a signal within it.
85 -1 when not doing one. */
87 int current_display_number
;
89 /* Flag to low-level print routines that this value is being printed
90 in an epoch window. We'd like to pass this as a parameter, but
91 every routine would need to take it. Perhaps we can encapsulate
92 this in the I/O stream once we have GNU stdio. */
98 /* Chain link to next auto-display item. */
100 /* Expression to be evaluated and displayed. */
101 struct expression
*exp
;
102 /* Item number of this auto-display item. */
104 /* Display format specified. */
105 struct format_data format
;
106 /* Innermost block required by this expression when evaluated */
108 /* Status of this display (enabled or disabled) */
112 /* Chain of expressions whose values should be displayed
113 automatically each time the program stops. */
115 static struct display
*display_chain
;
117 static int display_number
;
119 /* Pointer to the target-dependent disassembly function. */
121 int (*tm_print_insn
) PARAMS ((bfd_vma
, disassemble_info
*));
122 disassemble_info tm_print_insn_info
;
124 /* Prototypes for exported functions. */
126 void output_command
PARAMS ((char *, int));
128 void _initialize_printcmd
PARAMS ((void));
130 /* Prototypes for local functions. */
132 static void delete_display
PARAMS ((int));
134 static void enable_display
PARAMS ((char *, int));
136 static void disable_display_command
PARAMS ((char *, int));
138 static void disassemble_command
PARAMS ((char *, int));
140 static void printf_command
PARAMS ((char *, int));
142 static void print_frame_nameless_args
PARAMS ((struct frame_info
*, long,
143 int, int, GDB_FILE
*));
145 static void display_info
PARAMS ((char *, int));
147 static void do_one_display
PARAMS ((struct display
*));
149 static void undisplay_command
PARAMS ((char *, int));
151 static void free_display
PARAMS ((struct display
*));
153 static void display_command
PARAMS ((char *, int));
155 void x_command
PARAMS ((char *, int));
157 static void address_info
PARAMS ((char *, int));
159 static void set_command
PARAMS ((char *, int));
161 static void call_command
PARAMS ((char *, int));
163 static void inspect_command
PARAMS ((char *, int));
165 static void print_command
PARAMS ((char *, int));
167 static void print_command_1
PARAMS ((char *, int, int));
169 static void validate_format
PARAMS ((struct format_data
, char *));
171 static void do_examine
PARAMS ((struct format_data
, CORE_ADDR addr
, asection
*section
));
173 static void print_formatted
PARAMS ((value_ptr
, int, int));
175 static struct format_data decode_format
PARAMS ((char **, int, int));
177 static int print_insn
PARAMS ((CORE_ADDR
, GDB_FILE
*));
179 static void sym_info
PARAMS ((char *, int));
182 /* Decode a format specification. *STRING_PTR should point to it.
183 OFORMAT and OSIZE are used as defaults for the format and size
184 if none are given in the format specification.
185 If OSIZE is zero, then the size field of the returned value
186 should be set only if a size is explicitly specified by the
188 The structure returned describes all the data
189 found in the specification. In addition, *STRING_PTR is advanced
190 past the specification and past all whitespace following it. */
192 static struct format_data
193 decode_format (string_ptr
, oformat
, osize
)
198 struct format_data val
;
199 register char *p
= *string_ptr
;
205 if (*p
>= '0' && *p
<= '9')
206 val
.count
= atoi (p
);
207 while (*p
>= '0' && *p
<= '9') p
++;
209 /* Now process size or format letters that follow. */
213 if (*p
== 'b' || *p
== 'h' || *p
== 'w' || *p
== 'g')
215 else if (*p
>= 'a' && *p
<= 'z')
221 while (*p
== ' ' || *p
== '\t') p
++;
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 */
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 gdb_stdout 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 (val
, format
, size
)
283 register value_ptr val
;
287 struct type
*type
= check_typedef (VALUE_TYPE (val
));
288 int len
= TYPE_LENGTH (type
);
290 if (VALUE_LVAL (val
) == lval_memory
)
292 next_address
= VALUE_ADDRESS (val
) + len
;
293 next_section
= VALUE_BFD_SECTION (val
);
299 /* FIXME: Need to handle wchar_t's here... */
300 next_address
= VALUE_ADDRESS (val
)
301 + val_print_string (VALUE_ADDRESS (val
), -1, 1, gdb_stdout
);
302 next_section
= VALUE_BFD_SECTION (val
);
306 /* The old comment says
307 "Force output out, print_insn not using _filtered".
308 I'm not completely sure what that means, I suspect most print_insn
309 now do use _filtered, so I guess it's obsolete. */
310 /* We often wrap here if there are long symbolic names. */
312 next_address
= VALUE_ADDRESS (val
)
313 + print_insn (VALUE_ADDRESS (val
), gdb_stdout
);
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 value_print (val
, gdb_stdout
, format
, Val_pretty_default
);
325 print_scalar_formatted (VALUE_CONTENTS (val
), type
,
326 format
, size
, gdb_stdout
);
330 /* Print a scalar of data of type TYPE, pointed to in GDB by VALADDR,
331 according to letters FORMAT and SIZE on STREAM.
332 FORMAT may not be zero. Formats s and i are not supported at this level.
334 This is how the elements of an array or structure are printed
338 print_scalar_formatted (valaddr
, type
, format
, size
, stream
)
346 unsigned int len
= TYPE_LENGTH (type
);
348 if (len
> sizeof (LONGEST
)
356 if (! TYPE_UNSIGNED (type
)
357 || ! extract_long_unsigned_integer (valaddr
, len
, &val_long
))
359 /* We can't print it normally, but we can print it in hex.
360 Printing it in the wrong radix is more useful than saying
361 "use /x, you dummy". */
362 /* FIXME: we could also do octal or binary if that was the
364 /* FIXME: we should be using the size field to give us a
365 minimum field width to print. */
366 val_print_type_code_int (type
, valaddr
, stream
);
370 /* If we get here, extract_long_unsigned_integer set val_long. */
372 else if (format
!= 'f')
373 val_long
= unpack_long (type
, valaddr
);
375 /* If we are printing it as unsigned, truncate it in case it is actually
376 a negative signed value (e.g. "print/u (short)-1" should print 65535
377 (if shorts are 16 bits) instead of 4294967295). */
380 if (len
< sizeof (LONGEST
))
381 val_long
&= ((LONGEST
) 1 << HOST_CHAR_BIT
* len
) - 1;
389 /* no size specified, like in print. Print varying # of digits. */
390 print_longest (stream
, 'x', 1, val_long
);
399 print_longest (stream
, size
, 1, val_long
);
402 error ("Undefined output size \"%c\".", size
);
407 print_longest (stream
, 'd', 1, val_long
);
411 print_longest (stream
, 'u', 0, val_long
);
416 print_longest (stream
, 'o', 1, val_long
);
418 fprintf_filtered (stream
, "0");
422 print_address (unpack_pointer (type
, valaddr
), stream
);
426 value_print (value_from_longest (builtin_type_char
, val_long
), stream
, 0,
431 if (len
== sizeof (float))
432 type
= builtin_type_float
;
433 else if (len
== sizeof (double))
434 type
= builtin_type_double
;
435 print_floating (valaddr
, type
, stream
);
442 /* Binary; 't' stands for "two". */
444 char bits
[8*(sizeof val_long
) + 1];
449 width
= 8*(sizeof val_long
);
466 error ("Undefined output size \"%c\".", size
);
472 bits
[width
] = (val_long
& 1) ? '1' : '0';
477 while (*cp
&& *cp
== '0')
482 fprintf_filtered (stream
, local_binary_format_prefix());
483 fprintf_filtered (stream
, cp
);
484 fprintf_filtered (stream
, local_binary_format_suffix());
489 error ("Undefined output format \"%c\".", format
);
493 /* Specify default address for `x' command.
494 `info lines' uses this. */
497 set_next_address (addr
)
502 /* Make address available to the user as $_. */
503 set_internalvar (lookup_internalvar ("_"),
504 value_from_longest (lookup_pointer_type (builtin_type_void
),
508 /* Optionally print address ADDR symbolically as <SYMBOL+OFFSET> on STREAM,
509 after LEADIN. Print nothing if no symbolic name is found nearby.
510 Optionally also print source file and line number, if available.
511 DO_DEMANGLE controls whether to print a symbol in its native "raw" form,
512 or to interpret it as a possible C++ name and convert it back to source
513 form. However note that DO_DEMANGLE can be overridden by the specific
514 settings of the demangle and asm_demangle variables. */
517 print_address_symbolic (addr
, stream
, do_demangle
, leadin
)
523 struct minimal_symbol
*msymbol
;
524 struct symbol
*symbol
;
525 struct symtab
*symtab
= 0;
526 CORE_ADDR name_location
= 0;
528 asection
*section
= 0;
531 /* Determine if the address is in an overlay, and whether it is mapped. */
532 if (overlay_debugging
)
534 section
= find_pc_overlay (addr
);
535 if (pc_in_unmapped_range (addr
, section
))
538 addr
= overlay_mapped_address (addr
, section
);
542 /* On some targets, add in extra "flag" bits to PC for
543 disassembly. This should ensure that "rounding errors" in
544 symbol addresses that are masked for disassembly favour the
545 the correct symbol. */
547 #ifdef GDB_TARGET_UNMASK_DISAS_PC
548 addr
= GDB_TARGET_UNMASK_DISAS_PC (addr
);
551 /* First try to find the address in the symbol table, then
552 in the minsyms. Take the closest one. */
554 /* This is defective in the sense that it only finds text symbols. So
555 really this is kind of pointless--we should make sure that the
556 minimal symbols have everything we need (by changing that we could
557 save some memory, but for many debug format--ELF/DWARF or
558 anything/stabs--it would be inconvenient to eliminate those minimal
560 msymbol
= lookup_minimal_symbol_by_pc_section (addr
, section
);
561 symbol
= find_pc_sect_function (addr
, section
);
565 name_location
= BLOCK_START (SYMBOL_BLOCK_VALUE (symbol
));
567 name
= SYMBOL_SOURCE_NAME (symbol
);
569 name
= SYMBOL_LINKAGE_NAME (symbol
);
574 if (SYMBOL_VALUE_ADDRESS (msymbol
) > name_location
|| symbol
== NULL
)
576 /* The msymbol is closer to the address than the symbol;
577 use the msymbol instead. */
580 name_location
= SYMBOL_VALUE_ADDRESS (msymbol
);
582 name
= SYMBOL_SOURCE_NAME (msymbol
);
584 name
= SYMBOL_LINKAGE_NAME (msymbol
);
587 if (symbol
== NULL
&& msymbol
== NULL
)
590 /* On some targets, mask out extra "flag" bits from PC for handsome
593 #ifdef GDB_TARGET_MASK_DISAS_PC
594 name_location
= GDB_TARGET_MASK_DISAS_PC (name_location
);
595 addr
= GDB_TARGET_MASK_DISAS_PC (addr
);
598 /* If the nearest symbol is too far away, don't print anything symbolic. */
600 /* For when CORE_ADDR is larger than unsigned int, we do math in
601 CORE_ADDR. But when we detect unsigned wraparound in the
602 CORE_ADDR math, we ignore this test and print the offset,
603 because addr+max_symbolic_offset has wrapped through the end
604 of the address space back to the beginning, giving bogus comparison. */
605 if (addr
> name_location
+ max_symbolic_offset
606 && name_location
+ max_symbolic_offset
> name_location
)
609 fputs_filtered (leadin
, stream
);
611 fputs_filtered ("<*", stream
);
613 fputs_filtered ("<", stream
);
614 fputs_filtered (name
, stream
);
615 if (addr
!= name_location
)
616 fprintf_filtered (stream
, "+%u", (unsigned int)(addr
- name_location
));
618 /* Append source filename and line number if desired. Give specific
619 line # of this addr, if we have it; else line # of the nearest symbol. */
620 if (print_symbol_filename
)
622 struct symtab_and_line sal
;
624 sal
= find_pc_sect_line (addr
, section
, 0);
627 fprintf_filtered (stream
, " at %s:%d", sal
.symtab
->filename
, sal
.line
);
628 else if (symtab
&& symbol
&& symbol
->line
)
629 fprintf_filtered (stream
, " at %s:%d", symtab
->filename
, symbol
->line
);
631 fprintf_filtered (stream
, " in %s", symtab
->filename
);
634 fputs_filtered ("*>", stream
);
636 fputs_filtered (">", stream
);
639 /* Print address ADDR on STREAM. USE_LOCAL means the same thing as for
642 print_address_numeric (addr
, use_local
, stream
)
647 /* This assumes a CORE_ADDR can fit in a LONGEST. Probably a safe
649 print_longest (stream
, 'x', use_local
, (ULONGEST
) addr
);
652 /* Print address ADDR symbolically on STREAM.
653 First print it as a number. Then perhaps print
654 <SYMBOL + OFFSET> after the number. */
657 print_address (addr
, stream
)
661 print_address_numeric (addr
, 1, stream
);
662 print_address_symbolic (addr
, stream
, asm_demangle
, " ");
665 /* Print address ADDR symbolically on STREAM. Parameter DEMANGLE
666 controls whether to print the symbolic name "raw" or demangled.
667 Global setting "addressprint" controls whether to print hex address
671 print_address_demangle (addr
, stream
, do_demangle
)
678 fprintf_filtered (stream
, "0");
680 else if (addressprint
)
682 print_address_numeric (addr
, 1, stream
);
683 print_address_symbolic (addr
, stream
, do_demangle
, " ");
687 print_address_symbolic (addr
, stream
, do_demangle
, "");
692 /* These are the types that $__ will get after an examine command of one
695 static struct type
*examine_i_type
;
697 static struct type
*examine_b_type
;
698 static struct type
*examine_h_type
;
699 static struct type
*examine_w_type
;
700 static struct type
*examine_g_type
;
702 /* Examine data at address ADDR in format FMT.
703 Fetch it from memory and print on gdb_stdout. */
706 do_examine (fmt
, addr
, sect
)
707 struct format_data fmt
;
711 register char format
= 0;
713 register int count
= 1;
714 struct type
*val_type
= NULL
;
716 register int maxelts
;
724 /* String or instruction format implies fetch single bytes
725 regardless of the specified size. */
726 if (format
== 's' || format
== 'i')
730 val_type
= examine_i_type
;
731 else if (size
== 'b')
732 val_type
= examine_b_type
;
733 else if (size
== 'h')
734 val_type
= examine_h_type
;
735 else if (size
== 'w')
736 val_type
= examine_w_type
;
737 else if (size
== 'g')
738 val_type
= examine_g_type
;
745 if (format
== 's' || format
== 'i')
748 /* Print as many objects as specified in COUNT, at most maxelts per line,
749 with the address of the next one at the start of each line. */
754 print_address (next_address
, gdb_stdout
);
755 printf_filtered (":");
760 printf_filtered ("\t");
761 /* Note that print_formatted sets next_address for the next
763 last_examine_address
= next_address
;
764 /* The value to be displayed is not fetched greedily.
765 Instead, to avoid the posibility of a fetched value not
766 being used, its retreval is delayed until the print code
767 uses it. When examining an instruction stream, the
768 disassembler will perform its own memory fetch using just
769 the address stored in LAST_EXAMINE_VALUE. FIXME: Should
770 the disassembler be modified so that LAST_EXAMINE_VALUE
771 is left with the byte sequence from the last complete
772 instruction fetched from memory? */
773 last_examine_value
= value_at_lazy (val_type
, next_address
, sect
);
774 print_formatted (last_examine_value
, format
, size
);
776 printf_filtered ("\n");
777 gdb_flush (gdb_stdout
);
782 validate_format (fmt
, cmdname
)
783 struct format_data fmt
;
787 error ("Size letters are meaningless in \"%s\" command.", cmdname
);
789 error ("Item count other than 1 is meaningless in \"%s\" command.",
791 if (fmt
.format
== 'i' || fmt
.format
== 's')
792 error ("Format letter \"%c\" is meaningless in \"%s\" command.",
793 fmt
.format
, cmdname
);
796 /* Evaluate string EXP as an expression in the current language and
797 print the resulting value. EXP may contain a format specifier as the
798 first argument ("/x myvar" for example, to print myvar in hex).
802 print_command_1 (exp
, inspect
, voidprint
)
807 struct expression
*expr
;
808 register struct cleanup
*old_chain
= 0;
809 register char format
= 0;
810 register value_ptr val
;
811 struct format_data fmt
;
814 /* Pass inspect flag to the rest of the print routines in a global (sigh). */
815 inspect_it
= inspect
;
817 if (exp
&& *exp
== '/')
820 fmt
= decode_format (&exp
, last_format
, 0);
821 validate_format (fmt
, "print");
822 last_format
= format
= fmt
.format
;
833 extern int objectprint
;
835 expr
= parse_expression (exp
);
836 old_chain
= make_cleanup ((make_cleanup_func
) free_current_contents
,
839 val
= evaluate_expression (expr
);
841 /* C++: figure out what type we actually want to print it as. */
842 type
= VALUE_TYPE (val
);
845 && ( TYPE_CODE (type
) == TYPE_CODE_PTR
846 || TYPE_CODE (type
) == TYPE_CODE_REF
)
847 && ( TYPE_CODE (TYPE_TARGET_TYPE (type
)) == TYPE_CODE_STRUCT
848 || TYPE_CODE (TYPE_TARGET_TYPE (type
)) == TYPE_CODE_UNION
))
852 v
= value_from_vtable_info (val
, TYPE_TARGET_TYPE (type
));
856 type
= VALUE_TYPE (val
);
861 val
= access_value_history (0);
863 if (voidprint
|| (val
&& VALUE_TYPE (val
) &&
864 TYPE_CODE (VALUE_TYPE (val
)) != TYPE_CODE_VOID
))
866 int histindex
= record_latest_value (val
);
869 annotate_value_history_begin (histindex
, VALUE_TYPE (val
));
871 annotate_value_begin (VALUE_TYPE (val
));
874 printf_unfiltered ("\031(gdb-makebuffer \"%s\" %d '(\"", exp
, histindex
);
876 if (histindex
>= 0) printf_filtered ("$%d = ", histindex
);
879 annotate_value_history_value ();
881 print_formatted (val
, format
, fmt
.size
);
882 printf_filtered ("\n");
885 annotate_value_history_end ();
887 annotate_value_end ();
890 printf_unfiltered("\") )\030");
894 do_cleanups (old_chain
);
895 inspect_it
= 0; /* Reset print routines to normal */
900 print_command (exp
, from_tty
)
904 print_command_1 (exp
, 0, 1);
907 /* Same as print, except in epoch, it gets its own window */
910 inspect_command (exp
, from_tty
)
914 extern int epoch_interface
;
916 print_command_1 (exp
, epoch_interface
, 1);
919 /* Same as print, except it doesn't print void results. */
922 call_command (exp
, from_tty
)
926 print_command_1 (exp
, 0, 0);
931 output_command (exp
, from_tty
)
935 struct expression
*expr
;
936 register struct cleanup
*old_chain
;
937 register char format
= 0;
938 register value_ptr val
;
939 struct format_data fmt
;
941 if (exp
&& *exp
== '/')
944 fmt
= decode_format (&exp
, 0, 0);
945 validate_format (fmt
, "output");
949 expr
= parse_expression (exp
);
950 old_chain
= make_cleanup ((make_cleanup_func
) free_current_contents
, &expr
);
952 val
= evaluate_expression (expr
);
954 annotate_value_begin (VALUE_TYPE (val
));
956 print_formatted (val
, format
, fmt
.size
);
958 annotate_value_end ();
960 do_cleanups (old_chain
);
965 set_command (exp
, from_tty
)
969 struct expression
*expr
= parse_expression (exp
);
970 register struct cleanup
*old_chain
971 = make_cleanup ((make_cleanup_func
) free_current_contents
, &expr
);
972 evaluate_expression (expr
);
973 do_cleanups (old_chain
);
978 sym_info (arg
, from_tty
)
982 struct minimal_symbol
*msymbol
;
983 struct objfile
*objfile
;
984 struct obj_section
*osect
;
986 CORE_ADDR addr
, sect_addr
;
991 error_no_arg ("address");
993 addr
= parse_and_eval_address (arg
);
994 ALL_OBJSECTIONS (objfile
, osect
)
996 sect
= osect
->the_bfd_section
;
997 sect_addr
= overlay_mapped_address (addr
, sect
);
999 if (osect
->addr
<= sect_addr
&& sect_addr
< osect
->endaddr
&&
1000 (msymbol
= lookup_minimal_symbol_by_pc_section (sect_addr
, sect
)))
1003 offset
= sect_addr
- SYMBOL_VALUE_ADDRESS (msymbol
);
1005 printf_filtered ("%s + %u in ",
1006 SYMBOL_SOURCE_NAME (msymbol
), offset
);
1008 printf_filtered ("%s in ",
1009 SYMBOL_SOURCE_NAME (msymbol
));
1010 if (pc_in_unmapped_range (addr
, sect
))
1011 printf_filtered ("load address range of ");
1012 if (section_is_overlay (sect
))
1013 printf_filtered ("%s overlay ",
1014 section_is_mapped (sect
) ? "mapped" : "unmapped");
1015 printf_filtered ("section %s", sect
->name
);
1016 printf_filtered ("\n");
1020 printf_filtered ("No symbol matches %s.\n", arg
);
1025 address_info (exp
, from_tty
)
1029 register struct symbol
*sym
;
1030 register struct minimal_symbol
*msymbol
;
1032 register long basereg
;
1034 CORE_ADDR load_addr
;
1035 int is_a_field_of_this
; /* C++: lookup_symbol sets this to nonzero
1036 if exp is a field of `this'. */
1039 error ("Argument required.");
1041 sym
= lookup_symbol (exp
, get_selected_block (), VAR_NAMESPACE
,
1042 &is_a_field_of_this
, (struct symtab
**)NULL
);
1045 if (is_a_field_of_this
)
1047 printf_filtered ("Symbol \"");
1048 fprintf_symbol_filtered (gdb_stdout
, exp
,
1049 current_language
->la_language
, DMGL_ANSI
);
1050 printf_filtered ("\" is a field of the local class variable `this'\n");
1054 msymbol
= lookup_minimal_symbol (exp
, NULL
, NULL
);
1056 if (msymbol
!= NULL
)
1058 load_addr
= SYMBOL_VALUE_ADDRESS (msymbol
);
1060 printf_filtered ("Symbol \"");
1061 fprintf_symbol_filtered (gdb_stdout
, exp
,
1062 current_language
->la_language
, DMGL_ANSI
);
1063 printf_filtered ("\" is at ");
1064 print_address_numeric (load_addr
, 1, gdb_stdout
);
1065 printf_filtered (" in a file compiled without debugging");
1066 section
= SYMBOL_BFD_SECTION (msymbol
);
1067 if (section_is_overlay (section
))
1069 load_addr
= overlay_unmapped_address (load_addr
, section
);
1070 printf_filtered (",\n -- loaded at ");
1071 print_address_numeric (load_addr
, 1, gdb_stdout
);
1072 printf_filtered (" in overlay section %s", section
->name
);
1074 printf_filtered (".\n");
1077 error ("No symbol \"%s\" in current context.", exp
);
1081 printf_filtered ("Symbol \"");
1082 fprintf_symbol_filtered (gdb_stdout
, SYMBOL_NAME (sym
),
1083 current_language
->la_language
, DMGL_ANSI
);
1084 printf_filtered ("\" is ");
1085 val
= SYMBOL_VALUE (sym
);
1086 basereg
= SYMBOL_BASEREG (sym
);
1087 section
= SYMBOL_BFD_SECTION (sym
);
1089 switch (SYMBOL_CLASS (sym
))
1092 case LOC_CONST_BYTES
:
1093 printf_filtered ("constant");
1097 printf_filtered ("a label at address ");
1098 print_address_numeric (load_addr
= SYMBOL_VALUE_ADDRESS (sym
),
1100 if (section_is_overlay (section
))
1102 load_addr
= overlay_unmapped_address (load_addr
, section
);
1103 printf_filtered (",\n -- loaded at ");
1104 print_address_numeric (load_addr
, 1, gdb_stdout
);
1105 printf_filtered (" in overlay section %s", section
->name
);
1110 printf_filtered ("a variable in register %s", REGISTER_NAME (val
));
1114 printf_filtered ("static storage at address ");
1115 print_address_numeric (load_addr
= SYMBOL_VALUE_ADDRESS (sym
),
1117 if (section_is_overlay (section
))
1119 load_addr
= overlay_unmapped_address (load_addr
, section
);
1120 printf_filtered (",\n -- loaded at ");
1121 print_address_numeric (load_addr
, 1, gdb_stdout
);
1122 printf_filtered (" in overlay section %s", section
->name
);
1127 printf_filtered ("an argument in register %s", REGISTER_NAME (val
));
1130 case LOC_REGPARM_ADDR
:
1131 printf_filtered ("address of an argument in register %s", REGISTER_NAME (val
));
1135 printf_filtered ("an argument at offset %ld", val
);
1139 printf_filtered ("an argument at frame offset %ld", val
);
1143 printf_filtered ("a local variable at frame offset %ld", val
);
1147 printf_filtered ("a reference argument at offset %ld", val
);
1151 printf_filtered ("a variable at offset %ld from register %s",
1152 val
, REGISTER_NAME (basereg
));
1155 case LOC_BASEREG_ARG
:
1156 printf_filtered ("an argument at offset %ld from register %s",
1157 val
, REGISTER_NAME (basereg
));
1161 printf_filtered ("a typedef");
1165 printf_filtered ("a function at address ");
1166 #ifdef GDB_TARGET_MASK_DISAS_PC
1167 print_address_numeric
1168 (load_addr
= GDB_TARGET_MASK_DISAS_PC (BLOCK_START (SYMBOL_BLOCK_VALUE (sym
))),
1171 print_address_numeric (load_addr
=BLOCK_START (SYMBOL_BLOCK_VALUE (sym
)),
1174 if (section_is_overlay (section
))
1176 load_addr
= overlay_unmapped_address (load_addr
, section
);
1177 printf_filtered (",\n -- loaded at ");
1178 print_address_numeric (load_addr
, 1, gdb_stdout
);
1179 printf_filtered (" in overlay section %s", section
->name
);
1183 case LOC_UNRESOLVED
:
1185 struct minimal_symbol
*msym
;
1187 msym
= lookup_minimal_symbol (SYMBOL_NAME (sym
), NULL
, NULL
);
1189 printf_filtered ("unresolved");
1192 section
= SYMBOL_BFD_SECTION (msym
);
1193 printf_filtered ("static storage at address ");
1194 print_address_numeric (load_addr
= SYMBOL_VALUE_ADDRESS (msym
),
1196 if (section_is_overlay (section
))
1198 load_addr
= overlay_unmapped_address (load_addr
, section
);
1199 printf_filtered (",\n -- loaded at ");
1200 print_address_numeric (load_addr
, 1, gdb_stdout
);
1201 printf_filtered (" in overlay section %s", section
->name
);
1207 case LOC_OPTIMIZED_OUT
:
1208 printf_filtered ("optimized out");
1212 printf_filtered ("of unknown (botched) type");
1215 printf_filtered (".\n");
1219 x_command (exp
, from_tty
)
1223 struct expression
*expr
;
1224 struct format_data fmt
;
1225 struct cleanup
*old_chain
;
1228 fmt
.format
= last_format
;
1229 fmt
.size
= last_size
;
1232 if (exp
&& *exp
== '/')
1235 fmt
= decode_format (&exp
, last_format
, last_size
);
1238 /* If we have an expression, evaluate it and use it as the address. */
1240 if (exp
!= 0 && *exp
!= 0)
1242 expr
= parse_expression (exp
);
1243 /* Cause expression not to be there any more
1244 if this command is repeated with Newline.
1245 But don't clobber a user-defined command's definition. */
1248 old_chain
= make_cleanup ((make_cleanup_func
) free_current_contents
,
1250 val
= evaluate_expression (expr
);
1251 if (TYPE_CODE (VALUE_TYPE (val
)) == TYPE_CODE_REF
)
1252 val
= value_ind (val
);
1253 /* In rvalue contexts, such as this, functions are coerced into
1254 pointers to functions. This makes "x/i main" work. */
1255 if (/* last_format == 'i'
1256 && */ TYPE_CODE (VALUE_TYPE (val
)) == TYPE_CODE_FUNC
1257 && VALUE_LVAL (val
) == lval_memory
)
1258 next_address
= VALUE_ADDRESS (val
);
1260 next_address
= value_as_pointer (val
);
1261 if (VALUE_BFD_SECTION (val
))
1262 next_section
= VALUE_BFD_SECTION (val
);
1263 do_cleanups (old_chain
);
1266 do_examine (fmt
, next_address
, next_section
);
1268 /* If the examine succeeds, we remember its size and format for next time. */
1269 last_size
= fmt
.size
;
1270 last_format
= fmt
.format
;
1272 /* Set a couple of internal variables if appropriate. */
1273 if (last_examine_value
)
1275 /* Make last address examined available to the user as $_. Use
1276 the correct pointer type. */
1277 set_internalvar (lookup_internalvar ("_"),
1278 value_from_longest (
1279 lookup_pointer_type (VALUE_TYPE (last_examine_value
)),
1280 (LONGEST
) last_examine_address
));
1282 /* Make contents of last address examined available to the user as $__.*/
1283 /* If the last value has not been fetched from memory then don't
1284 fetch it now - instead mark it by voiding the $__ variable. */
1285 if (VALUE_LAZY (last_examine_value
))
1286 set_internalvar (lookup_internalvar ("__"),
1287 allocate_value (builtin_type_void
));
1289 set_internalvar (lookup_internalvar ("__"), last_examine_value
);
1294 /* Add an expression to the auto-display chain.
1295 Specify the expression. */
1298 display_command (exp
, from_tty
)
1302 struct format_data fmt
;
1303 register struct expression
*expr
;
1304 register struct display
*new;
1315 fmt
= decode_format (&exp
, 0, 0);
1316 if (fmt
.size
&& fmt
.format
== 0)
1318 if (fmt
.format
== 'i' || fmt
.format
== 's')
1328 innermost_block
= 0;
1329 expr
= parse_expression (exp
);
1331 new = (struct display
*) xmalloc (sizeof (struct display
));
1334 new->block
= innermost_block
;
1335 new->next
= display_chain
;
1336 new->number
= ++display_number
;
1338 new->status
= enabled
;
1339 display_chain
= new;
1341 if (from_tty
&& target_has_execution
)
1342 do_one_display (new);
1355 /* Clear out the display_chain.
1356 Done when new symtabs are loaded, since this invalidates
1357 the types stored in many expressions. */
1362 register struct display
*d
;
1364 while ((d
= display_chain
) != NULL
)
1367 display_chain
= d
->next
;
1372 /* Delete the auto-display number NUM. */
1375 delete_display (num
)
1378 register struct display
*d1
, *d
;
1381 error ("No display number %d.", num
);
1383 if (display_chain
->number
== num
)
1386 display_chain
= d1
->next
;
1390 for (d
= display_chain
; ; d
= d
->next
)
1393 error ("No display number %d.", num
);
1394 if (d
->next
->number
== num
)
1404 /* Delete some values from the auto-display chain.
1405 Specify the element numbers. */
1408 undisplay_command (args
, from_tty
)
1412 register char *p
= args
;
1418 if (query ("Delete all auto-display expressions? "))
1427 while (*p1
>= '0' && *p1
<= '9') p1
++;
1428 if (*p1
&& *p1
!= ' ' && *p1
!= '\t')
1429 error ("Arguments must be display numbers.");
1433 delete_display (num
);
1436 while (*p
== ' ' || *p
== '\t') p
++;
1441 /* Display a single auto-display.
1442 Do nothing if the display cannot be printed in the current context,
1443 or if the display is disabled. */
1449 int within_current_scope
;
1451 if (d
->status
== disabled
)
1455 within_current_scope
= contained_in (get_selected_block (), d
->block
);
1457 within_current_scope
= 1;
1458 if (!within_current_scope
)
1461 current_display_number
= d
->number
;
1463 annotate_display_begin ();
1464 printf_filtered ("%d", d
->number
);
1465 annotate_display_number_end ();
1466 printf_filtered (": ");
1472 annotate_display_format ();
1474 printf_filtered ("x/");
1475 if (d
->format
.count
!= 1)
1476 printf_filtered ("%d", d
->format
.count
);
1477 printf_filtered ("%c", d
->format
.format
);
1478 if (d
->format
.format
!= 'i' && d
->format
.format
!= 's')
1479 printf_filtered ("%c", d
->format
.size
);
1480 printf_filtered (" ");
1482 annotate_display_expression ();
1484 print_expression (d
->exp
, gdb_stdout
);
1485 annotate_display_expression_end ();
1487 if (d
->format
.count
!= 1)
1488 printf_filtered ("\n");
1490 printf_filtered (" ");
1492 val
= evaluate_expression (d
->exp
);
1493 addr
= value_as_pointer (val
);
1494 if (d
->format
.format
== 'i')
1495 addr
= ADDR_BITS_REMOVE (addr
);
1497 annotate_display_value ();
1499 do_examine (d
->format
, addr
, VALUE_BFD_SECTION (val
));
1503 annotate_display_format ();
1505 if (d
->format
.format
)
1506 printf_filtered ("/%c ", d
->format
.format
);
1508 annotate_display_expression ();
1510 print_expression (d
->exp
, gdb_stdout
);
1511 annotate_display_expression_end ();
1513 printf_filtered (" = ");
1515 annotate_display_expression ();
1517 print_formatted (evaluate_expression (d
->exp
),
1518 d
->format
.format
, d
->format
.size
);
1519 printf_filtered ("\n");
1522 annotate_display_end ();
1524 gdb_flush (gdb_stdout
);
1525 current_display_number
= -1;
1528 /* Display all of the values on the auto-display chain which can be
1529 evaluated in the current scope. */
1534 register struct display
*d
;
1536 for (d
= display_chain
; d
; d
= d
->next
)
1540 /* Delete the auto-display which we were in the process of displaying.
1541 This is done when there is an error or a signal. */
1544 disable_display (num
)
1547 register struct display
*d
;
1549 for (d
= display_chain
; d
; d
= d
->next
)
1550 if (d
->number
== num
)
1552 d
->status
= disabled
;
1555 printf_unfiltered ("No display number %d.\n", num
);
1559 disable_current_display ()
1561 if (current_display_number
>= 0)
1563 disable_display (current_display_number
);
1564 fprintf_unfiltered (gdb_stderr
, "Disabling display %d to avoid infinite recursion.\n",
1565 current_display_number
);
1567 current_display_number
= -1;
1571 display_info (ignore
, from_tty
)
1575 register struct display
*d
;
1578 printf_unfiltered ("There are no auto-display expressions now.\n");
1580 printf_filtered ("Auto-display expressions now in effect:\n\
1581 Num Enb Expression\n");
1583 for (d
= display_chain
; d
; d
= d
->next
)
1585 printf_filtered ("%d: %c ", d
->number
, "ny"[(int)d
->status
]);
1587 printf_filtered ("/%d%c%c ", d
->format
.count
, d
->format
.size
,
1589 else if (d
->format
.format
)
1590 printf_filtered ("/%c ", d
->format
.format
);
1591 print_expression (d
->exp
, gdb_stdout
);
1592 if (d
->block
&& !contained_in (get_selected_block (), d
->block
))
1593 printf_filtered (" (cannot be evaluated in the current context)");
1594 printf_filtered ("\n");
1595 gdb_flush (gdb_stdout
);
1600 enable_display (args
, from_tty
)
1604 register char *p
= args
;
1607 register struct display
*d
;
1611 for (d
= display_chain
; d
; d
= d
->next
)
1612 d
->status
= enabled
;
1618 while (*p1
>= '0' && *p1
<= '9')
1620 if (*p1
&& *p1
!= ' ' && *p1
!= '\t')
1621 error ("Arguments must be display numbers.");
1625 for (d
= display_chain
; d
; d
= d
->next
)
1626 if (d
->number
== num
)
1628 d
->status
= enabled
;
1631 printf_unfiltered ("No display number %d.\n", num
);
1634 while (*p
== ' ' || *p
== '\t')
1641 disable_display_command (args
, from_tty
)
1645 register char *p
= args
;
1647 register struct display
*d
;
1651 for (d
= display_chain
; d
; d
= d
->next
)
1652 d
->status
= disabled
;
1658 while (*p1
>= '0' && *p1
<= '9')
1660 if (*p1
&& *p1
!= ' ' && *p1
!= '\t')
1661 error ("Arguments must be display numbers.");
1663 disable_display (atoi (p
));
1666 while (*p
== ' ' || *p
== '\t')
1672 /* Print the value in stack frame FRAME of a variable
1673 specified by a struct symbol. */
1676 print_variable_value (var
, frame
, stream
)
1678 struct frame_info
*frame
;
1681 value_ptr val
= read_var_value (var
, frame
);
1683 value_print (val
, stream
, 0, Val_pretty_default
);
1686 /* Print the arguments of a stack frame, given the function FUNC
1687 running in that frame (as a symbol), the info on the frame,
1688 and the number of args according to the stack frame (or -1 if unknown). */
1690 /* References here and elsewhere to "number of args according to the
1691 stack frame" appear in all cases to refer to "number of ints of args
1692 according to the stack frame". At least for VAX, i386, isi. */
1695 print_frame_args (func
, fi
, num
, stream
)
1696 struct symbol
*func
;
1697 struct frame_info
*fi
;
1701 struct block
*b
= NULL
;
1705 register struct symbol
*sym
;
1706 register value_ptr val
;
1707 /* Offset of next stack argument beyond the one we have seen that is
1708 at the highest offset.
1709 -1 if we haven't come to a stack argument yet. */
1710 long highest_offset
= -1;
1712 /* Number of ints of arguments that we have printed so far. */
1713 int args_printed
= 0;
1717 b
= SYMBOL_BLOCK_VALUE (func
);
1718 nsyms
= BLOCK_NSYMS (b
);
1721 for (i
= 0; i
< nsyms
; i
++)
1724 sym
= BLOCK_SYM (b
, i
);
1726 /* Keep track of the highest stack argument offset seen, and
1727 skip over any kinds of symbols we don't care about. */
1729 switch (SYMBOL_CLASS (sym
)) {
1733 long current_offset
= SYMBOL_VALUE (sym
);
1734 arg_size
= TYPE_LENGTH (SYMBOL_TYPE (sym
));
1736 /* Compute address of next argument by adding the size of
1737 this argument and rounding to an int boundary. */
1739 = ((current_offset
+ arg_size
+ sizeof (int) - 1)
1740 & ~(sizeof (int) - 1));
1742 /* If this is the highest offset seen yet, set highest_offset. */
1743 if (highest_offset
== -1
1744 || (current_offset
> highest_offset
))
1745 highest_offset
= current_offset
;
1747 /* Add the number of ints we're about to print to args_printed. */
1748 args_printed
+= (arg_size
+ sizeof (int) - 1) / sizeof (int);
1751 /* We care about types of symbols, but don't need to keep track of
1752 stack offsets in them. */
1754 case LOC_REGPARM_ADDR
:
1756 case LOC_BASEREG_ARG
:
1759 /* Other types of symbols we just skip over. */
1764 /* We have to look up the symbol because arguments can have
1765 two entries (one a parameter, one a local) and the one we
1766 want is the local, which lookup_symbol will find for us.
1767 This includes gcc1 (not gcc2) on the sparc when passing a
1768 small structure and gcc2 when the argument type is float
1769 and it is passed as a double and converted to float by
1770 the prologue (in the latter case the type of the LOC_ARG
1771 symbol is double and the type of the LOC_LOCAL symbol is
1773 /* But if the parameter name is null, don't try it.
1774 Null parameter names occur on the RS/6000, for traceback tables.
1775 FIXME, should we even print them? */
1777 if (*SYMBOL_NAME (sym
))
1779 struct symbol
*nsym
;
1780 nsym
= lookup_symbol
1782 b
, VAR_NAMESPACE
, (int *)NULL
, (struct symtab
**)NULL
);
1783 if (SYMBOL_CLASS (nsym
) == LOC_REGISTER
)
1785 /* There is a LOC_ARG/LOC_REGISTER pair. This means that
1786 it was passed on the stack and loaded into a register,
1787 or passed in a register and stored in a stack slot.
1788 GDB 3.x used the LOC_ARG; GDB 4.0-4.11 used the LOC_REGISTER.
1790 Reasons for using the LOC_ARG:
1791 (1) because find_saved_registers may be slow for remote
1793 (2) because registers are often re-used and stack slots
1794 rarely (never?) are. Therefore using the stack slot is
1795 much less likely to print garbage.
1797 Reasons why we might want to use the LOC_REGISTER:
1798 (1) So that the backtrace prints the same value as
1799 "print foo". I see no compelling reason why this needs
1800 to be the case; having the backtrace print the value which
1801 was passed in, and "print foo" print the value as modified
1802 within the called function, makes perfect sense to me.
1804 Additional note: It might be nice if "info args" displayed
1806 One more note: There is a case with sparc structure passing
1807 where we need to use the LOC_REGISTER, but this is dealt with
1808 by creating a single LOC_REGPARM in symbol reading. */
1810 /* Leave sym (the LOC_ARG) alone. */
1817 /* Print the current arg. */
1819 fprintf_filtered (stream
, ", ");
1822 annotate_arg_begin ();
1824 fprintf_symbol_filtered (stream
, SYMBOL_SOURCE_NAME (sym
),
1825 SYMBOL_LANGUAGE (sym
), DMGL_PARAMS
| DMGL_ANSI
);
1826 annotate_arg_name_end ();
1827 fputs_filtered ("=", stream
);
1829 /* Avoid value_print because it will deref ref parameters. We just
1830 want to print their addresses. Print ??? for args whose address
1831 we do not know. We pass 2 as "recurse" to val_print because our
1832 standard indentation here is 4 spaces, and val_print indents
1833 2 for each recurse. */
1834 val
= read_var_value (sym
, fi
);
1836 annotate_arg_value (val
== NULL
? NULL
: VALUE_TYPE (val
));
1840 #ifdef GDB_TARGET_IS_D10V
1841 if (SYMBOL_CLASS(sym
) == LOC_REGPARM
&& TYPE_CODE(VALUE_TYPE(val
)) == TYPE_CODE_PTR
)
1842 TYPE_LENGTH(VALUE_TYPE(val
)) = 2;
1844 val_print (VALUE_TYPE (val
), VALUE_CONTENTS (val
), VALUE_ADDRESS (val
),
1845 stream
, 0, 0, 2, Val_no_prettyprint
);
1848 fputs_filtered ("???", stream
);
1850 annotate_arg_end ();
1855 /* Don't print nameless args in situations where we don't know
1856 enough about the stack to find them. */
1861 if (highest_offset
== -1)
1862 start
= FRAME_ARGS_SKIP
;
1864 start
= highest_offset
;
1866 print_frame_nameless_args (fi
, start
, num
- args_printed
,
1871 /* Print nameless args on STREAM.
1872 FI is the frameinfo for this frame, START is the offset
1873 of the first nameless arg, and NUM is the number of nameless args to
1874 print. FIRST is nonzero if this is the first argument (not just
1875 the first nameless arg). */
1878 print_frame_nameless_args (fi
, start
, num
, first
, stream
)
1879 struct frame_info
*fi
;
1889 for (i
= 0; i
< num
; i
++)
1892 #ifdef NAMELESS_ARG_VALUE
1893 NAMELESS_ARG_VALUE (fi
, start
, &arg_value
);
1895 argsaddr
= FRAME_ARGS_ADDRESS (fi
);
1899 arg_value
= read_memory_integer (argsaddr
+ start
, sizeof (int));
1903 fprintf_filtered (stream
, ", ");
1905 #ifdef PRINT_NAMELESS_INTEGER
1906 PRINT_NAMELESS_INTEGER (stream
, arg_value
);
1908 #ifdef PRINT_TYPELESS_INTEGER
1909 PRINT_TYPELESS_INTEGER (stream
, builtin_type_int
, (LONGEST
) arg_value
);
1911 fprintf_filtered (stream
, "%ld", arg_value
);
1912 #endif /* PRINT_TYPELESS_INTEGER */
1913 #endif /* PRINT_NAMELESS_INTEGER */
1915 start
+= sizeof (int);
1921 printf_command (arg
, from_tty
)
1925 register char *f
= NULL
;
1926 register char *s
= arg
;
1927 char *string
= NULL
;
1928 value_ptr
*val_args
;
1930 char *current_substring
;
1932 int allocated_args
= 20;
1933 struct cleanup
*old_cleanups
;
1935 val_args
= (value_ptr
*) xmalloc (allocated_args
* sizeof (value_ptr
));
1936 old_cleanups
= make_cleanup ((make_cleanup_func
) free_current_contents
,
1940 error_no_arg ("format-control string and values to print");
1942 /* Skip white space before format string */
1943 while (*s
== ' ' || *s
== '\t') s
++;
1945 /* A format string should follow, enveloped in double quotes */
1947 error ("Bad format string, missing '\"'.");
1949 /* Parse the format-control string and copy it into the string STRING,
1950 processing some kinds of escape sequence. */
1952 f
= string
= (char *) alloca (strlen (s
) + 1);
1960 error ("Bad format string, non-terminated '\"'.");
1972 *f
++ = '\007'; /* Bell */
1997 /* ??? TODO: handle other escape sequences */
1998 error ("Unrecognized escape character \\%c in format string.",
2008 /* Skip over " and following space and comma. */
2011 while (*s
== ' ' || *s
== '\t') s
++;
2013 if (*s
!= ',' && *s
!= 0)
2014 error ("Invalid argument syntax");
2017 while (*s
== ' ' || *s
== '\t') s
++;
2019 /* Need extra space for the '\0's. Doubling the size is sufficient. */
2020 substrings
= alloca (strlen (string
) * 2);
2021 current_substring
= substrings
;
2024 /* Now scan the string for %-specs and see what kinds of args they want.
2025 argclass[I] classifies the %-specs so we can give printf_filtered
2026 something of the right size. */
2028 enum argclass
{no_arg
, int_arg
, string_arg
, double_arg
, long_long_arg
};
2029 enum argclass
*argclass
;
2030 enum argclass this_argclass
;
2036 argclass
= (enum argclass
*) alloca (strlen (s
) * sizeof *argclass
);
2044 while (strchr ("0123456789.hlL-+ #", *f
))
2046 if (*f
== 'l' || *f
== 'L')
2053 this_argclass
= string_arg
;
2059 this_argclass
= double_arg
;
2063 error ("`*' not supported for precision or width in printf");
2066 error ("Format specifier `n' not supported in printf");
2069 this_argclass
= no_arg
;
2074 this_argclass
= long_long_arg
;
2076 this_argclass
= int_arg
;
2080 if (this_argclass
!= no_arg
)
2082 strncpy (current_substring
, last_arg
, f
- last_arg
);
2083 current_substring
+= f
- last_arg
;
2084 *current_substring
++ = '\0';
2086 argclass
[nargs_wanted
++] = this_argclass
;
2090 /* Now, parse all arguments and evaluate them.
2091 Store the VALUEs in VAL_ARGS. */
2096 if (nargs
== allocated_args
)
2097 val_args
= (value_ptr
*) xrealloc ((char *) val_args
,
2098 (allocated_args
*= 2)
2099 * sizeof (value_ptr
));
2101 val_args
[nargs
] = parse_to_comma_and_eval (&s1
);
2103 /* If format string wants a float, unchecked-convert the value to
2104 floating point of the same size */
2106 if (argclass
[nargs
] == double_arg
)
2108 struct type
*type
= VALUE_TYPE (val_args
[nargs
]);
2109 if (TYPE_LENGTH (type
) == sizeof (float))
2110 VALUE_TYPE (val_args
[nargs
]) = builtin_type_float
;
2111 if (TYPE_LENGTH (type
) == sizeof (double))
2112 VALUE_TYPE (val_args
[nargs
]) = builtin_type_double
;
2120 if (nargs
!= nargs_wanted
)
2121 error ("Wrong number of arguments for specified format-string");
2123 /* Now actually print them. */
2124 current_substring
= substrings
;
2125 for (i
= 0; i
< nargs
; i
++)
2127 switch (argclass
[i
])
2134 tem
= value_as_pointer (val_args
[i
]);
2136 /* This is a %s argument. Find the length of the string. */
2141 read_memory_section (tem
+ j
, &c
, 1,
2142 VALUE_BFD_SECTION (val_args
[i
]));
2147 /* Copy the string contents into a string inside GDB. */
2148 str
= (char *) alloca (j
+ 1);
2149 read_memory_section (tem
, str
, j
, VALUE_BFD_SECTION (val_args
[i
]));
2152 printf_filtered (current_substring
, str
);
2157 double val
= value_as_double (val_args
[i
]);
2158 printf_filtered (current_substring
, val
);
2162 #if defined (CC_HAS_LONG_LONG) && defined (PRINTF_HAS_LONG_LONG)
2164 long long val
= value_as_long (val_args
[i
]);
2165 printf_filtered (current_substring
, val
);
2169 error ("long long not supported in printf");
2173 /* FIXME: there should be separate int_arg and long_arg. */
2174 long val
= value_as_long (val_args
[i
]);
2175 printf_filtered (current_substring
, val
);
2179 error ("internal error in printf_command");
2181 /* Skip to the next substring. */
2182 current_substring
+= strlen (current_substring
) + 1;
2184 /* Print the portion of the format string after the last argument. */
2185 printf_filtered (last_arg
);
2187 do_cleanups (old_cleanups
);
2190 /* Dump a specified section of assembly code. With no command line
2191 arguments, this command will dump the assembly code for the
2192 function surrounding the pc value in the selected frame. With one
2193 argument, it will dump the assembly code surrounding that pc value.
2194 Two arguments are interpeted as bounds within which to dump
2199 disassemble_command (arg
, from_tty
)
2203 CORE_ADDR low
, high
;
2205 CORE_ADDR pc
, pc_masked
;
2211 if (!selected_frame
)
2212 error ("No frame selected.\n");
2214 pc
= get_frame_pc (selected_frame
);
2215 if (find_pc_partial_function (pc
, &name
, &low
, &high
) == 0)
2216 error ("No function contains program counter for selected frame.\n");
2217 low
+= FUNCTION_START_OFFSET
;
2219 else if (!(space_index
= (char *) strchr (arg
, ' ')))
2222 pc
= parse_and_eval_address (arg
);
2223 if (find_pc_partial_function (pc
, &name
, &low
, &high
) == 0)
2224 error ("No function contains specified address.\n");
2225 low
+= FUNCTION_START_OFFSET
;
2229 /* Two arguments. */
2230 *space_index
= '\0';
2231 low
= parse_and_eval_address (arg
);
2232 high
= parse_and_eval_address (space_index
+ 1);
2235 printf_filtered ("Dump of assembler code ");
2238 printf_filtered ("for function %s:\n", name
);
2242 printf_filtered ("from ");
2243 print_address_numeric (low
, 1, gdb_stdout
);
2244 printf_filtered (" to ");
2245 print_address_numeric (high
, 1, gdb_stdout
);
2246 printf_filtered (":\n");
2249 /* Dump the specified range. */
2252 #ifdef GDB_TARGET_MASK_DISAS_PC
2253 pc_masked
= GDB_TARGET_MASK_DISAS_PC (pc
);
2258 while (pc_masked
< high
)
2261 print_address (pc_masked
, gdb_stdout
);
2262 printf_filtered (":\t");
2263 /* We often wrap here if there are long symbolic names. */
2265 pc
+= print_insn (pc
, gdb_stdout
);
2266 printf_filtered ("\n");
2268 #ifdef GDB_TARGET_MASK_DISAS_PC
2269 pc_masked
= GDB_TARGET_MASK_DISAS_PC (pc
);
2274 printf_filtered ("End of assembler dump.\n");
2275 gdb_flush (gdb_stdout
);
2278 /* Print the instruction at address MEMADDR in debugged memory,
2279 on STREAM. Returns length of the instruction, in bytes. */
2282 print_insn (memaddr
, stream
)
2286 if (TARGET_BYTE_ORDER
== BIG_ENDIAN
)
2287 TARGET_PRINT_INSN_INFO
->endian
= BFD_ENDIAN_BIG
;
2289 TARGET_PRINT_INSN_INFO
->endian
= BFD_ENDIAN_LITTLE
;
2291 if (TARGET_ARCHITECTURE
!= NULL
)
2292 TARGET_PRINT_INSN_INFO
->mach
= TARGET_ARCHITECTURE
->mach
;
2293 /* else: should set .mach=0 but some disassemblers don't grok this */
2295 return TARGET_PRINT_INSN (memaddr
, TARGET_PRINT_INSN_INFO
);
2300 _initialize_printcmd ()
2302 current_display_number
= -1;
2304 add_info ("address", address_info
,
2305 "Describe where symbol SYM is stored.");
2307 add_info ("symbol", sym_info
,
2308 "Describe what symbol is at location ADDR.\n\
2309 Only for symbols with fixed locations (global or static scope).");
2311 add_com ("x", class_vars
, x_command
,
2312 concat ("Examine memory: x/FMT ADDRESS.\n\
2313 ADDRESS is an expression for the memory address to examine.\n\
2314 FMT is a repeat count followed by a format letter and a size letter.\n\
2315 Format letters are o(octal), x(hex), d(decimal), u(unsigned decimal),\n\
2316 t(binary), f(float), a(address), i(instruction), c(char) and s(string).\n",
2317 "Size letters are b(byte), h(halfword), w(word), g(giant, 8 bytes).\n\
2318 The specified number of objects of the specified size are printed\n\
2319 according to the format.\n\n\
2320 Defaults for format and size letters are those previously used.\n\
2321 Default count is 1. Default address is following last thing printed\n\
2322 with this command or \"print\".", NULL
));
2324 add_com ("disassemble", class_vars
, disassemble_command
,
2325 "Disassemble a specified section of memory.\n\
2326 Default is the function surrounding the pc of the selected frame.\n\
2327 With a single argument, the function surrounding that address is dumped.\n\
2328 Two arguments are taken as a range of memory to dump.");
2331 add_com ("whereis", class_vars
, whereis_command
,
2332 "Print line number and file of definition of variable.");
2335 add_info ("display", display_info
,
2336 "Expressions to display when program stops, with code numbers.");
2338 add_cmd ("undisplay", class_vars
, undisplay_command
,
2339 "Cancel some expressions to be displayed when program stops.\n\
2340 Arguments are the code numbers of the expressions to stop displaying.\n\
2341 No argument means cancel all automatic-display expressions.\n\
2342 \"delete display\" has the same effect as this command.\n\
2343 Do \"info display\" to see current list of code numbers.",
2346 add_com ("display", class_vars
, display_command
,
2347 "Print value of expression EXP each time the program stops.\n\
2348 /FMT may be used before EXP as in the \"print\" command.\n\
2349 /FMT \"i\" or \"s\" or including a size-letter is allowed,\n\
2350 as in the \"x\" command, and then EXP is used to get the address to examine\n\
2351 and examining is done as in the \"x\" command.\n\n\
2352 With no argument, display all currently requested auto-display expressions.\n\
2353 Use \"undisplay\" to cancel display requests previously made."
2356 add_cmd ("display", class_vars
, enable_display
,
2357 "Enable some expressions to be displayed when program stops.\n\
2358 Arguments are the code numbers of the expressions to resume displaying.\n\
2359 No argument means enable all automatic-display expressions.\n\
2360 Do \"info display\" to see current list of code numbers.", &enablelist
);
2362 add_cmd ("display", class_vars
, disable_display_command
,
2363 "Disable some expressions to be displayed when program stops.\n\
2364 Arguments are the code numbers of the expressions to stop displaying.\n\
2365 No argument means disable all automatic-display expressions.\n\
2366 Do \"info display\" to see current list of code numbers.", &disablelist
);
2368 add_cmd ("display", class_vars
, undisplay_command
,
2369 "Cancel some expressions to be displayed when program stops.\n\
2370 Arguments are the code numbers of the expressions to stop displaying.\n\
2371 No argument means cancel all automatic-display expressions.\n\
2372 Do \"info display\" to see current list of code numbers.", &deletelist
);
2374 add_com ("printf", class_vars
, printf_command
,
2375 "printf \"printf format string\", arg1, arg2, arg3, ..., argn\n\
2376 This is useful for formatted output in user-defined commands.");
2378 add_com ("output", class_vars
, output_command
,
2379 "Like \"print\" but don't put in value history and don't print newline.\n\
2380 This is useful in user-defined commands.");
2382 add_prefix_cmd ("set", class_vars
, set_command
,
2383 concat ("Evaluate expression EXP and assign result to variable VAR, using assignment\n\
2384 syntax appropriate for the current language (VAR = EXP or VAR := EXP for\n\
2385 example). VAR may be a debugger \"convenience\" variable (names starting\n\
2386 with $), a register (a few standard names starting with $), or an actual\n\
2387 variable in the program being debugged. EXP is any valid expression.\n",
2388 "Use \"set variable\" for variables with names identical to set subcommands.\n\
2389 \nWith a subcommand, this command modifies parts of the gdb environment.\n\
2390 You can see these environment settings with the \"show\" command.", NULL
),
2391 &setlist
, "set ", 1, &cmdlist
);
2393 /* "call" is the same as "set", but handy for dbx users to call fns. */
2394 add_com ("call", class_vars
, call_command
,
2395 "Call a function in the program.\n\
2396 The argument is the function name and arguments, in the notation of the\n\
2397 current working language. The result is printed and saved in the value\n\
2398 history, if it is not void.");
2400 add_cmd ("variable", class_vars
, set_command
,
2401 "Evaluate expression EXP and assign result to variable VAR, using assignment\n\
2402 syntax appropriate for the current language (VAR = EXP or VAR := EXP for\n\
2403 example). VAR may be a debugger \"convenience\" variable (names starting\n\
2404 with $), a register (a few standard names starting with $), or an actual\n\
2405 variable in the program being debugged. EXP is any valid expression.\n\
2406 This may usually be abbreviated to simply \"set\".",
2409 add_com ("print", class_vars
, print_command
,
2410 concat ("Print value of expression EXP.\n\
2411 Variables accessible are those of the lexical environment of the selected\n\
2412 stack frame, plus all those whose scope is global or an entire file.\n\
2414 $NUM gets previous value number NUM. $ and $$ are the last two values.\n\
2415 $$NUM refers to NUM'th value back from the last one.\n\
2416 Names starting with $ refer to registers (with the values they would have\n",
2417 "if the program were to return to the stack frame now selected, restoring\n\
2418 all registers saved by frames farther in) or else to debugger\n\
2419 \"convenience\" variables (any such name not a known register).\n\
2420 Use assignment expressions to give values to convenience variables.\n",
2422 {TYPE}ADREXP refers to a datum of data type TYPE, located at address ADREXP.\n\
2423 @ is a binary operator for treating consecutive data objects\n\
2424 anywhere in memory as an array. FOO@NUM gives an array whose first\n\
2425 element is FOO, whose second element is stored in the space following\n\
2426 where FOO is stored, etc. FOO must be an expression whose value\n\
2427 resides in memory.\n",
2429 EXP may be preceded with /FMT, where FMT is a format letter\n\
2430 but no count or size letter (see \"x\" command).", NULL
));
2431 add_com_alias ("p", "print", class_vars
, 1);
2433 add_com ("inspect", class_vars
, inspect_command
,
2434 "Same as \"print\" command, except that if you are running in the epoch\n\
2435 environment, the value is printed in its own window.");
2438 add_set_cmd ("max-symbolic-offset", no_class
, var_uinteger
,
2439 (char *)&max_symbolic_offset
,
2440 "Set the largest offset that will be printed in <symbol+1234> form.",
2444 add_set_cmd ("symbol-filename", no_class
, var_boolean
,
2445 (char *)&print_symbol_filename
,
2446 "Set printing of source filename and line number with <symbol>.",
2450 /* For examine/instruction a single byte quantity is specified as
2451 the data. This avoids problems with value_at_lazy() requiring a
2452 valid data type (and rejecting VOID). */
2453 examine_i_type
= init_type (TYPE_CODE_INT
, 1, 0, "examine_i_type", NULL
);
2455 examine_b_type
= init_type (TYPE_CODE_INT
, 1, 0, "examine_b_type", NULL
);
2456 examine_h_type
= init_type (TYPE_CODE_INT
, 2, 0, "examine_h_type", NULL
);
2457 examine_w_type
= init_type (TYPE_CODE_INT
, 4, 0, "examine_w_type", NULL
);
2458 examine_g_type
= init_type (TYPE_CODE_INT
, 8, 0, "examine_g_type", NULL
);
2460 INIT_DISASSEMBLE_INFO_NO_ARCH (tm_print_insn_info
, gdb_stdout
, (fprintf_ftype
)fprintf_filtered
);
2461 tm_print_insn_info
.flavour
= bfd_target_unknown_flavour
;
2462 tm_print_insn_info
.read_memory_func
= dis_asm_read_memory
;
2463 tm_print_insn_info
.memory_error_func
= dis_asm_memory_error
;
2464 tm_print_insn_info
.print_address_func
= dis_asm_print_address
;