1 /* Print values for GNU debugger GDB.
2 Copyright 1986-1991, 1993-1995, 1998, 2000 Free Software Foundation, Inc.
4 This file is part of GDB.
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 59 Temple Place - Suite 330,
19 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 /* Prototypes for exported functions. */
121 void output_command
PARAMS ((char *, int));
123 void _initialize_printcmd
PARAMS ((void));
125 /* Prototypes for local functions. */
127 static void delete_display
PARAMS ((int));
129 static void enable_display
PARAMS ((char *, int));
131 static void disable_display_command
PARAMS ((char *, int));
133 static void disassemble_command
PARAMS ((char *, int));
135 static void printf_command
PARAMS ((char *, int));
137 static void print_frame_nameless_args (struct frame_info
*, long,
138 int, int, struct ui_file
*);
140 static void display_info
PARAMS ((char *, int));
142 static void do_one_display
PARAMS ((struct display
*));
144 static void undisplay_command
PARAMS ((char *, int));
146 static void free_display
PARAMS ((struct display
*));
148 static void display_command
PARAMS ((char *, int));
150 void x_command
PARAMS ((char *, int));
152 static void address_info
PARAMS ((char *, int));
154 static void set_command
PARAMS ((char *, int));
156 static void call_command
PARAMS ((char *, int));
158 static void inspect_command
PARAMS ((char *, int));
160 static void print_command
PARAMS ((char *, int));
162 static void print_command_1
PARAMS ((char *, int, int));
164 static void validate_format
PARAMS ((struct format_data
, char *));
166 static void do_examine
PARAMS ((struct format_data
, CORE_ADDR addr
, asection
* section
));
168 static void print_formatted (value_ptr
, int, int, struct ui_file
*);
170 static struct format_data decode_format
PARAMS ((char **, int, int));
172 static int print_insn (CORE_ADDR
, struct ui_file
*);
174 static void sym_info
PARAMS ((char *, int));
177 /* Decode a format specification. *STRING_PTR should point to it.
178 OFORMAT and OSIZE are used as defaults for the format and size
179 if none are given in the format specification.
180 If OSIZE is zero, then the size field of the returned value
181 should be set only if a size is explicitly specified by the
183 The structure returned describes all the data
184 found in the specification. In addition, *STRING_PTR is advanced
185 past the specification and past all whitespace following it. */
187 static struct format_data
188 decode_format (string_ptr
, oformat
, osize
)
193 struct format_data val
;
194 register char *p
= *string_ptr
;
200 if (*p
>= '0' && *p
<= '9')
201 val
.count
= atoi (p
);
202 while (*p
>= '0' && *p
<= '9')
205 /* Now process size or format letters that follow. */
209 if (*p
== 'b' || *p
== 'h' || *p
== 'w' || *p
== 'g')
211 else if (*p
>= 'a' && *p
<= 'z')
217 while (*p
== ' ' || *p
== '\t')
221 /* Set defaults for format and size if not specified. */
222 if (val
.format
== '?')
226 /* Neither has been specified. */
227 val
.format
= oformat
;
231 /* If a size is specified, any format makes a reasonable
232 default except 'i'. */
233 val
.format
= oformat
== 'i' ? 'x' : oformat
;
235 else if (val
.size
== '?')
240 /* Pick the appropriate size for an address. */
241 if (TARGET_PTR_BIT
== 64)
242 val
.size
= osize
? 'g' : osize
;
243 else if (TARGET_PTR_BIT
== 32)
244 val
.size
= osize
? 'w' : osize
;
245 else if (TARGET_PTR_BIT
== 16)
246 val
.size
= osize
? 'h' : osize
;
248 /* Bad value for TARGET_PTR_BIT */
252 /* Floating point has to be word or giantword. */
253 if (osize
== 'w' || osize
== 'g')
256 /* Default it to giantword if the last used size is not
258 val
.size
= osize
? 'g' : osize
;
261 /* Characters default to one byte. */
262 val
.size
= osize
? 'b' : osize
;
265 /* The default is the size most recently specified. */
272 /* Print value VAL on stream according to FORMAT, a letter or 0.
273 Do not end with a newline.
274 0 means print VAL according to its own type.
275 SIZE is the letter for the size of datum being printed.
276 This is used to pad hex numbers so they line up. */
279 print_formatted (val
, format
, size
, stream
)
280 register value_ptr val
;
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 + 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 /* If format is 0, use the 'natural' format for
324 * that type of value. If the type is non-scalar,
325 * we have to use language rules to print it as
326 * a series of scalars.
328 value_print (val
, stream
, format
, Val_pretty_default
);
330 /* User specified format, so don't look to the
331 * the type to tell us what to do.
333 print_scalar_formatted (VALUE_CONTENTS (val
), type
,
334 format
, size
, stream
);
338 /* Print a scalar of data of type TYPE, pointed to in GDB by VALADDR,
339 according to letters FORMAT and SIZE on STREAM.
340 FORMAT may not be zero. Formats s and i are not supported at this level.
342 This is how the elements of an array or structure are printed
346 print_scalar_formatted (valaddr
, type
, format
, size
, stream
)
351 struct ui_file
*stream
;
354 unsigned int len
= TYPE_LENGTH (type
);
356 if (len
> sizeof (LONGEST
)
364 if (!TYPE_UNSIGNED (type
)
365 || !extract_long_unsigned_integer (valaddr
, len
, &val_long
))
367 /* We can't print it normally, but we can print it in hex.
368 Printing it in the wrong radix is more useful than saying
369 "use /x, you dummy". */
370 /* FIXME: we could also do octal or binary if that was the
372 /* FIXME: we should be using the size field to give us a
373 minimum field width to print. */
376 print_octal_chars (stream
, valaddr
, len
);
377 else if (format
== 'd')
378 print_decimal_chars (stream
, valaddr
, len
);
379 else if (format
== 't')
380 print_binary_chars (stream
, valaddr
, len
);
382 /* replace with call to print_hex_chars? Looks
383 like val_print_type_code_int is redoing
386 val_print_type_code_int (type
, valaddr
, stream
);
391 /* If we get here, extract_long_unsigned_integer set val_long. */
393 else if (format
!= 'f')
394 val_long
= unpack_long (type
, valaddr
);
396 /* If we are printing it as unsigned, truncate it in case it is actually
397 a negative signed value (e.g. "print/u (short)-1" should print 65535
398 (if shorts are 16 bits) instead of 4294967295). */
401 if (len
< sizeof (LONGEST
))
402 val_long
&= ((LONGEST
) 1 << HOST_CHAR_BIT
* len
) - 1;
410 /* no size specified, like in print. Print varying # of digits. */
411 print_longest (stream
, 'x', 1, val_long
);
420 print_longest (stream
, size
, 1, val_long
);
423 error ("Undefined output size \"%c\".", size
);
428 print_longest (stream
, 'd', 1, val_long
);
432 print_longest (stream
, 'u', 0, val_long
);
437 print_longest (stream
, 'o', 1, val_long
);
439 fprintf_filtered (stream
, "0");
443 print_address (unpack_pointer (type
, valaddr
), stream
);
447 value_print (value_from_longest (builtin_type_true_char
, val_long
),
448 stream
, 0, Val_pretty_default
);
452 if (len
== sizeof (float))
453 type
= builtin_type_float
;
454 else if (len
== sizeof (double))
455 type
= builtin_type_double
;
456 print_floating (valaddr
, type
, stream
);
463 /* Binary; 't' stands for "two". */
465 char bits
[8 * (sizeof val_long
) + 1];
466 char buf
[8 * (sizeof val_long
) + 32];
471 width
= 8 * (sizeof val_long
);
488 error ("Undefined output size \"%c\".", size
);
494 bits
[width
] = (val_long
& 1) ? '1' : '0';
499 while (*cp
&& *cp
== '0')
504 strcpy (buf
, local_binary_format_prefix ());
506 strcat (buf
, local_binary_format_suffix ());
507 fprintf_filtered (stream
, buf
);
512 error ("Undefined output format \"%c\".", format
);
516 /* Specify default address for `x' command.
517 `info lines' uses this. */
520 set_next_address (addr
)
525 /* Make address available to the user as $_. */
526 set_internalvar (lookup_internalvar ("_"),
527 value_from_longest (lookup_pointer_type (builtin_type_void
),
531 /* Optionally print address ADDR symbolically as <SYMBOL+OFFSET> on STREAM,
532 after LEADIN. Print nothing if no symbolic name is found nearby.
533 Optionally also print source file and line number, if available.
534 DO_DEMANGLE controls whether to print a symbol in its native "raw" form,
535 or to interpret it as a possible C++ name and convert it back to source
536 form. However note that DO_DEMANGLE can be overridden by the specific
537 settings of the demangle and asm_demangle variables. */
540 print_address_symbolic (addr
, stream
, do_demangle
, leadin
)
542 struct ui_file
*stream
;
546 struct minimal_symbol
*msymbol
;
547 struct symbol
*symbol
;
548 struct symtab
*symtab
= 0;
549 CORE_ADDR name_location
= 0;
551 asection
*section
= 0;
554 /* Determine if the address is in an overlay, and whether it is mapped. */
555 if (overlay_debugging
)
557 section
= find_pc_overlay (addr
);
558 if (pc_in_unmapped_range (addr
, section
))
561 addr
= overlay_mapped_address (addr
, section
);
565 /* On some targets, add in extra "flag" bits to PC for
566 disassembly. This should ensure that "rounding errors" in
567 symbol addresses that are masked for disassembly favour the
568 the correct symbol. */
570 #ifdef GDB_TARGET_UNMASK_DISAS_PC
571 addr
= GDB_TARGET_UNMASK_DISAS_PC (addr
);
574 /* First try to find the address in the symbol table, then
575 in the minsyms. Take the closest one. */
577 /* This is defective in the sense that it only finds text symbols. So
578 really this is kind of pointless--we should make sure that the
579 minimal symbols have everything we need (by changing that we could
580 save some memory, but for many debug format--ELF/DWARF or
581 anything/stabs--it would be inconvenient to eliminate those minimal
583 msymbol
= lookup_minimal_symbol_by_pc_section (addr
, section
);
584 symbol
= find_pc_sect_function (addr
, section
);
588 name_location
= BLOCK_START (SYMBOL_BLOCK_VALUE (symbol
));
590 name
= SYMBOL_SOURCE_NAME (symbol
);
592 name
= SYMBOL_LINKAGE_NAME (symbol
);
597 if (SYMBOL_VALUE_ADDRESS (msymbol
) > name_location
|| symbol
== NULL
)
599 /* The msymbol is closer to the address than the symbol;
600 use the msymbol instead. */
603 name_location
= SYMBOL_VALUE_ADDRESS (msymbol
);
605 name
= SYMBOL_SOURCE_NAME (msymbol
);
607 name
= SYMBOL_LINKAGE_NAME (msymbol
);
610 if (symbol
== NULL
&& msymbol
== NULL
)
613 /* On some targets, mask out extra "flag" bits from PC for handsome
616 #ifdef GDB_TARGET_MASK_DISAS_PC
617 name_location
= GDB_TARGET_MASK_DISAS_PC (name_location
);
618 addr
= GDB_TARGET_MASK_DISAS_PC (addr
);
621 /* If the nearest symbol is too far away, don't print anything symbolic. */
623 /* For when CORE_ADDR is larger than unsigned int, we do math in
624 CORE_ADDR. But when we detect unsigned wraparound in the
625 CORE_ADDR math, we ignore this test and print the offset,
626 because addr+max_symbolic_offset has wrapped through the end
627 of the address space back to the beginning, giving bogus comparison. */
628 if (addr
> name_location
+ max_symbolic_offset
629 && name_location
+ max_symbolic_offset
> name_location
)
632 fputs_filtered (leadin
, stream
);
634 fputs_filtered ("<*", stream
);
636 fputs_filtered ("<", stream
);
637 fputs_filtered (name
, stream
);
638 if (addr
!= name_location
)
639 fprintf_filtered (stream
, "+%u", (unsigned int) (addr
- name_location
));
641 /* Append source filename and line number if desired. Give specific
642 line # of this addr, if we have it; else line # of the nearest symbol. */
643 if (print_symbol_filename
)
645 struct symtab_and_line sal
;
647 sal
= find_pc_sect_line (addr
, section
, 0);
650 fprintf_filtered (stream
, " at %s:%d", sal
.symtab
->filename
, sal
.line
);
651 else if (symtab
&& symbol
&& symbol
->line
)
652 fprintf_filtered (stream
, " at %s:%d", symtab
->filename
, symbol
->line
);
654 fprintf_filtered (stream
, " in %s", symtab
->filename
);
657 fputs_filtered ("*>", stream
);
659 fputs_filtered (">", stream
);
663 /* Print address ADDR on STREAM. USE_LOCAL means the same thing as for
666 print_address_numeric (addr
, use_local
, stream
)
669 struct ui_file
*stream
;
671 /* This assumes a CORE_ADDR can fit in a LONGEST. Probably a safe
673 print_longest (stream
, 'x', use_local
, (ULONGEST
) addr
);
676 /* Print address ADDR symbolically on STREAM.
677 First print it as a number. Then perhaps print
678 <SYMBOL + OFFSET> after the number. */
681 print_address (addr
, stream
)
683 struct ui_file
*stream
;
685 print_address_numeric (addr
, 1, stream
);
686 print_address_symbolic (addr
, stream
, asm_demangle
, " ");
689 /* Print address ADDR symbolically on STREAM. Parameter DEMANGLE
690 controls whether to print the symbolic name "raw" or demangled.
691 Global setting "addressprint" controls whether to print hex address
695 print_address_demangle (addr
, stream
, do_demangle
)
697 struct ui_file
*stream
;
702 fprintf_filtered (stream
, "0");
704 else if (addressprint
)
706 print_address_numeric (addr
, 1, stream
);
707 print_address_symbolic (addr
, stream
, do_demangle
, " ");
711 print_address_symbolic (addr
, stream
, do_demangle
, "");
716 /* These are the types that $__ will get after an examine command of one
719 static struct type
*examine_i_type
;
721 static struct type
*examine_b_type
;
722 static struct type
*examine_h_type
;
723 static struct type
*examine_w_type
;
724 static struct type
*examine_g_type
;
726 /* Examine data at address ADDR in format FMT.
727 Fetch it from memory and print on gdb_stdout. */
730 do_examine (fmt
, addr
, sect
)
731 struct format_data fmt
;
735 register char format
= 0;
737 register int count
= 1;
738 struct type
*val_type
= NULL
;
740 register int maxelts
;
748 /* String or instruction format implies fetch single bytes
749 regardless of the specified size. */
750 if (format
== 's' || format
== 'i')
754 val_type
= examine_i_type
;
755 else if (size
== 'b')
756 val_type
= examine_b_type
;
757 else if (size
== 'h')
758 val_type
= examine_h_type
;
759 else if (size
== 'w')
760 val_type
= examine_w_type
;
761 else if (size
== 'g')
762 val_type
= examine_g_type
;
769 if (format
== 's' || format
== 'i')
772 /* Print as many objects as specified in COUNT, at most maxelts per line,
773 with the address of the next one at the start of each line. */
778 print_address (next_address
, gdb_stdout
);
779 printf_filtered (":");
784 printf_filtered ("\t");
785 /* Note that print_formatted sets next_address for the next
787 last_examine_address
= next_address
;
789 if (last_examine_value
)
790 value_free (last_examine_value
);
792 /* The value to be displayed is not fetched greedily.
793 Instead, to avoid the posibility of a fetched value not
794 being used, its retreval is delayed until the print code
795 uses it. When examining an instruction stream, the
796 disassembler will perform its own memory fetch using just
797 the address stored in LAST_EXAMINE_VALUE. FIXME: Should
798 the disassembler be modified so that LAST_EXAMINE_VALUE
799 is left with the byte sequence from the last complete
800 instruction fetched from memory? */
801 last_examine_value
= value_at_lazy (val_type
, next_address
, sect
);
803 if (last_examine_value
)
804 release_value (last_examine_value
);
806 print_formatted (last_examine_value
, format
, size
, gdb_stdout
);
808 printf_filtered ("\n");
809 gdb_flush (gdb_stdout
);
814 validate_format (fmt
, cmdname
)
815 struct format_data fmt
;
819 error ("Size letters are meaningless in \"%s\" command.", cmdname
);
821 error ("Item count other than 1 is meaningless in \"%s\" command.",
823 if (fmt
.format
== 'i' || fmt
.format
== 's')
824 error ("Format letter \"%c\" is meaningless in \"%s\" command.",
825 fmt
.format
, cmdname
);
828 /* Evaluate string EXP as an expression in the current language and
829 print the resulting value. EXP may contain a format specifier as the
830 first argument ("/x myvar" for example, to print myvar in hex).
834 print_command_1 (exp
, inspect
, voidprint
)
839 struct expression
*expr
;
840 register struct cleanup
*old_chain
= 0;
841 register char format
= 0;
842 register value_ptr val
;
843 struct format_data fmt
;
846 /* Pass inspect flag to the rest of the print routines in a global (sigh). */
847 inspect_it
= inspect
;
849 if (exp
&& *exp
== '/')
852 fmt
= decode_format (&exp
, last_format
, 0);
853 validate_format (fmt
, "print");
854 last_format
= format
= fmt
.format
;
866 expr
= parse_expression (exp
);
867 old_chain
= make_cleanup ((make_cleanup_func
) free_current_contents
,
870 val
= evaluate_expression (expr
);
872 /* C++: figure out what type we actually want to print it as. */
873 type
= VALUE_TYPE (val
);
876 && (TYPE_CODE (type
) == TYPE_CODE_PTR
877 || TYPE_CODE (type
) == TYPE_CODE_REF
)
878 && (TYPE_CODE (TYPE_TARGET_TYPE (type
)) == TYPE_CODE_STRUCT
879 || TYPE_CODE (TYPE_TARGET_TYPE (type
)) == TYPE_CODE_UNION
))
883 v
= value_from_vtable_info (val
, TYPE_TARGET_TYPE (type
));
887 type
= VALUE_TYPE (val
);
892 val
= access_value_history (0);
894 if (voidprint
|| (val
&& VALUE_TYPE (val
) &&
895 TYPE_CODE (VALUE_TYPE (val
)) != TYPE_CODE_VOID
))
897 int histindex
= record_latest_value (val
);
900 annotate_value_history_begin (histindex
, VALUE_TYPE (val
));
902 annotate_value_begin (VALUE_TYPE (val
));
905 printf_unfiltered ("\031(gdb-makebuffer \"%s\" %d '(\"", exp
, histindex
);
906 else if (histindex
>= 0)
907 printf_filtered ("$%d = ", histindex
);
910 annotate_value_history_value ();
912 print_formatted (val
, format
, fmt
.size
, gdb_stdout
);
913 printf_filtered ("\n");
916 annotate_value_history_end ();
918 annotate_value_end ();
921 printf_unfiltered ("\") )\030");
925 do_cleanups (old_chain
);
926 inspect_it
= 0; /* Reset print routines to normal */
931 print_command (exp
, from_tty
)
935 print_command_1 (exp
, 0, 1);
938 /* Same as print, except in epoch, it gets its own window */
941 inspect_command (exp
, from_tty
)
945 extern int epoch_interface
;
947 print_command_1 (exp
, epoch_interface
, 1);
950 /* Same as print, except it doesn't print void results. */
953 call_command (exp
, from_tty
)
957 print_command_1 (exp
, 0, 0);
962 output_command (exp
, from_tty
)
966 struct expression
*expr
;
967 register struct cleanup
*old_chain
;
968 register char format
= 0;
969 register value_ptr val
;
970 struct format_data fmt
;
972 if (exp
&& *exp
== '/')
975 fmt
= decode_format (&exp
, 0, 0);
976 validate_format (fmt
, "output");
980 expr
= parse_expression (exp
);
981 old_chain
= make_cleanup ((make_cleanup_func
) free_current_contents
, &expr
);
983 val
= evaluate_expression (expr
);
985 annotate_value_begin (VALUE_TYPE (val
));
987 print_formatted (val
, format
, fmt
.size
, gdb_stdout
);
989 annotate_value_end ();
992 gdb_flush (gdb_stdout
);
994 do_cleanups (old_chain
);
999 set_command (exp
, from_tty
)
1003 struct expression
*expr
= parse_expression (exp
);
1004 register struct cleanup
*old_chain
1005 = make_cleanup ((make_cleanup_func
) free_current_contents
, &expr
);
1006 evaluate_expression (expr
);
1007 do_cleanups (old_chain
);
1012 sym_info (arg
, from_tty
)
1016 struct minimal_symbol
*msymbol
;
1017 struct objfile
*objfile
;
1018 struct obj_section
*osect
;
1020 CORE_ADDR addr
, sect_addr
;
1022 unsigned int offset
;
1025 error_no_arg ("address");
1027 addr
= parse_and_eval_address (arg
);
1028 ALL_OBJSECTIONS (objfile
, osect
)
1030 sect
= osect
->the_bfd_section
;
1031 sect_addr
= overlay_mapped_address (addr
, sect
);
1033 if (osect
->addr
<= sect_addr
&& sect_addr
< osect
->endaddr
&&
1034 (msymbol
= lookup_minimal_symbol_by_pc_section (sect_addr
, sect
)))
1037 offset
= sect_addr
- SYMBOL_VALUE_ADDRESS (msymbol
);
1039 printf_filtered ("%s + %u in ",
1040 SYMBOL_SOURCE_NAME (msymbol
), offset
);
1042 printf_filtered ("%s in ",
1043 SYMBOL_SOURCE_NAME (msymbol
));
1044 if (pc_in_unmapped_range (addr
, sect
))
1045 printf_filtered ("load address range of ");
1046 if (section_is_overlay (sect
))
1047 printf_filtered ("%s overlay ",
1048 section_is_mapped (sect
) ? "mapped" : "unmapped");
1049 printf_filtered ("section %s", sect
->name
);
1050 printf_filtered ("\n");
1054 printf_filtered ("No symbol matches %s.\n", arg
);
1059 address_info (exp
, from_tty
)
1063 register struct symbol
*sym
;
1064 register struct minimal_symbol
*msymbol
;
1066 register long basereg
;
1068 CORE_ADDR load_addr
;
1069 int is_a_field_of_this
; /* C++: lookup_symbol sets this to nonzero
1070 if exp is a field of `this'. */
1073 error ("Argument required.");
1075 sym
= lookup_symbol (exp
, get_selected_block (), VAR_NAMESPACE
,
1076 &is_a_field_of_this
, (struct symtab
**) NULL
);
1079 if (is_a_field_of_this
)
1081 printf_filtered ("Symbol \"");
1082 fprintf_symbol_filtered (gdb_stdout
, exp
,
1083 current_language
->la_language
, DMGL_ANSI
);
1084 printf_filtered ("\" is a field of the local class variable `this'\n");
1088 msymbol
= lookup_minimal_symbol (exp
, NULL
, NULL
);
1090 if (msymbol
!= NULL
)
1092 load_addr
= SYMBOL_VALUE_ADDRESS (msymbol
);
1094 printf_filtered ("Symbol \"");
1095 fprintf_symbol_filtered (gdb_stdout
, exp
,
1096 current_language
->la_language
, DMGL_ANSI
);
1097 printf_filtered ("\" is at ");
1098 print_address_numeric (load_addr
, 1, gdb_stdout
);
1099 printf_filtered (" in a file compiled without debugging");
1100 section
= SYMBOL_BFD_SECTION (msymbol
);
1101 if (section_is_overlay (section
))
1103 load_addr
= overlay_unmapped_address (load_addr
, section
);
1104 printf_filtered (",\n -- loaded at ");
1105 print_address_numeric (load_addr
, 1, gdb_stdout
);
1106 printf_filtered (" in overlay section %s", section
->name
);
1108 printf_filtered (".\n");
1111 error ("No symbol \"%s\" in current context.", exp
);
1115 printf_filtered ("Symbol \"");
1116 fprintf_symbol_filtered (gdb_stdout
, SYMBOL_NAME (sym
),
1117 current_language
->la_language
, DMGL_ANSI
);
1118 printf_filtered ("\" is ");
1119 val
= SYMBOL_VALUE (sym
);
1120 basereg
= SYMBOL_BASEREG (sym
);
1121 section
= SYMBOL_BFD_SECTION (sym
);
1123 switch (SYMBOL_CLASS (sym
))
1126 case LOC_CONST_BYTES
:
1127 printf_filtered ("constant");
1131 printf_filtered ("a label at address ");
1132 print_address_numeric (load_addr
= SYMBOL_VALUE_ADDRESS (sym
),
1134 if (section_is_overlay (section
))
1136 load_addr
= overlay_unmapped_address (load_addr
, section
);
1137 printf_filtered (",\n -- loaded at ");
1138 print_address_numeric (load_addr
, 1, gdb_stdout
);
1139 printf_filtered (" in overlay section %s", section
->name
);
1144 printf_filtered ("a variable in register %s", REGISTER_NAME (val
));
1148 printf_filtered ("static storage at address ");
1149 print_address_numeric (load_addr
= SYMBOL_VALUE_ADDRESS (sym
),
1151 if (section_is_overlay (section
))
1153 load_addr
= overlay_unmapped_address (load_addr
, section
);
1154 printf_filtered (",\n -- loaded at ");
1155 print_address_numeric (load_addr
, 1, gdb_stdout
);
1156 printf_filtered (" in overlay section %s", section
->name
);
1161 printf_filtered ("external global (indirect addressing), at address *(");
1162 print_address_numeric (load_addr
= SYMBOL_VALUE_ADDRESS (sym
),
1164 printf_filtered (")");
1165 if (section_is_overlay (section
))
1167 load_addr
= overlay_unmapped_address (load_addr
, section
);
1168 printf_filtered (",\n -- loaded at ");
1169 print_address_numeric (load_addr
, 1, gdb_stdout
);
1170 printf_filtered (" in overlay section %s", section
->name
);
1175 printf_filtered ("an argument in register %s", REGISTER_NAME (val
));
1178 case LOC_REGPARM_ADDR
:
1179 printf_filtered ("address of an argument in register %s", REGISTER_NAME (val
));
1183 printf_filtered ("an argument at offset %ld", val
);
1187 printf_filtered ("an argument at frame offset %ld", val
);
1191 printf_filtered ("a local variable at frame offset %ld", val
);
1195 printf_filtered ("a reference argument at offset %ld", val
);
1199 printf_filtered ("a variable at offset %ld from register %s",
1200 val
, REGISTER_NAME (basereg
));
1203 case LOC_BASEREG_ARG
:
1204 printf_filtered ("an argument at offset %ld from register %s",
1205 val
, REGISTER_NAME (basereg
));
1209 printf_filtered ("a typedef");
1213 printf_filtered ("a function at address ");
1214 #ifdef GDB_TARGET_MASK_DISAS_PC
1215 print_address_numeric
1216 (load_addr
= GDB_TARGET_MASK_DISAS_PC (BLOCK_START (SYMBOL_BLOCK_VALUE (sym
))),
1219 print_address_numeric (load_addr
= BLOCK_START (SYMBOL_BLOCK_VALUE (sym
)),
1222 if (section_is_overlay (section
))
1224 load_addr
= overlay_unmapped_address (load_addr
, section
);
1225 printf_filtered (",\n -- loaded at ");
1226 print_address_numeric (load_addr
, 1, gdb_stdout
);
1227 printf_filtered (" in overlay section %s", section
->name
);
1231 case LOC_UNRESOLVED
:
1233 struct minimal_symbol
*msym
;
1235 msym
= lookup_minimal_symbol (SYMBOL_NAME (sym
), NULL
, NULL
);
1237 printf_filtered ("unresolved");
1240 section
= SYMBOL_BFD_SECTION (msym
);
1241 printf_filtered ("static storage at address ");
1242 print_address_numeric (load_addr
= SYMBOL_VALUE_ADDRESS (msym
),
1244 if (section_is_overlay (section
))
1246 load_addr
= overlay_unmapped_address (load_addr
, section
);
1247 printf_filtered (",\n -- loaded at ");
1248 print_address_numeric (load_addr
, 1, gdb_stdout
);
1249 printf_filtered (" in overlay section %s", section
->name
);
1255 case LOC_THREAD_LOCAL_STATIC
:
1257 "a thread-local variable at offset %ld from the thread base register %s",
1258 val
, REGISTER_NAME (basereg
));
1261 case LOC_OPTIMIZED_OUT
:
1262 printf_filtered ("optimized out");
1266 printf_filtered ("of unknown (botched) type");
1269 printf_filtered (".\n");
1273 x_command (exp
, from_tty
)
1277 struct expression
*expr
;
1278 struct format_data fmt
;
1279 struct cleanup
*old_chain
;
1282 fmt
.format
= last_format
;
1283 fmt
.size
= last_size
;
1286 if (exp
&& *exp
== '/')
1289 fmt
= decode_format (&exp
, last_format
, last_size
);
1292 /* If we have an expression, evaluate it and use it as the address. */
1294 if (exp
!= 0 && *exp
!= 0)
1296 expr
= parse_expression (exp
);
1297 /* Cause expression not to be there any more
1298 if this command is repeated with Newline.
1299 But don't clobber a user-defined command's definition. */
1302 old_chain
= make_cleanup ((make_cleanup_func
) free_current_contents
,
1304 val
= evaluate_expression (expr
);
1305 if (TYPE_CODE (VALUE_TYPE (val
)) == TYPE_CODE_REF
)
1306 val
= value_ind (val
);
1307 /* In rvalue contexts, such as this, functions are coerced into
1308 pointers to functions. This makes "x/i main" work. */
1309 if ( /* last_format == 'i'
1310 && */ TYPE_CODE (VALUE_TYPE (val
)) == TYPE_CODE_FUNC
1311 && VALUE_LVAL (val
) == lval_memory
)
1312 next_address
= VALUE_ADDRESS (val
);
1314 next_address
= value_as_pointer (val
);
1315 if (VALUE_BFD_SECTION (val
))
1316 next_section
= VALUE_BFD_SECTION (val
);
1317 do_cleanups (old_chain
);
1320 do_examine (fmt
, next_address
, next_section
);
1322 /* If the examine succeeds, we remember its size and format for next time. */
1323 last_size
= fmt
.size
;
1324 last_format
= fmt
.format
;
1326 /* Set a couple of internal variables if appropriate. */
1327 if (last_examine_value
)
1329 /* Make last address examined available to the user as $_. Use
1330 the correct pointer type. */
1331 set_internalvar (lookup_internalvar ("_"),
1332 value_from_longest (
1333 lookup_pointer_type (VALUE_TYPE (last_examine_value
)),
1334 (LONGEST
) last_examine_address
));
1336 /* Make contents of last address examined available to the user as $__. */
1337 /* If the last value has not been fetched from memory then don't
1338 fetch it now - instead mark it by voiding the $__ variable. */
1339 if (VALUE_LAZY (last_examine_value
))
1340 set_internalvar (lookup_internalvar ("__"),
1341 allocate_value (builtin_type_void
));
1343 set_internalvar (lookup_internalvar ("__"), last_examine_value
);
1348 /* Add an expression to the auto-display chain.
1349 Specify the expression. */
1352 display_command (exp
, from_tty
)
1356 struct format_data fmt
;
1357 register struct expression
*expr
;
1358 register struct display
*new;
1362 if (tui_version
&& *exp
== '$')
1363 display_it
= ((TuiStatus
) tuiDo (
1364 (TuiOpaqueFuncPtr
) tui_vSetLayoutTo
, exp
) == TUI_FAILURE
);
1378 fmt
= decode_format (&exp
, 0, 0);
1379 if (fmt
.size
&& fmt
.format
== 0)
1381 if (fmt
.format
== 'i' || fmt
.format
== 's')
1391 innermost_block
= 0;
1392 expr
= parse_expression (exp
);
1394 new = (struct display
*) xmalloc (sizeof (struct display
));
1397 new->block
= innermost_block
;
1398 new->next
= display_chain
;
1399 new->number
= ++display_number
;
1401 new->status
= enabled
;
1402 display_chain
= new;
1404 if (from_tty
&& target_has_execution
)
1405 do_one_display (new);
1415 free ((PTR
) d
->exp
);
1419 /* Clear out the display_chain.
1420 Done when new symtabs are loaded, since this invalidates
1421 the types stored in many expressions. */
1426 register struct display
*d
;
1428 while ((d
= display_chain
) != NULL
)
1430 free ((PTR
) d
->exp
);
1431 display_chain
= d
->next
;
1436 /* Delete the auto-display number NUM. */
1439 delete_display (num
)
1442 register struct display
*d1
, *d
;
1445 error ("No display number %d.", num
);
1447 if (display_chain
->number
== num
)
1450 display_chain
= d1
->next
;
1454 for (d
= display_chain
;; d
= d
->next
)
1457 error ("No display number %d.", num
);
1458 if (d
->next
->number
== num
)
1468 /* Delete some values from the auto-display chain.
1469 Specify the element numbers. */
1472 undisplay_command (args
, from_tty
)
1476 register char *p
= args
;
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. */
1515 int within_current_scope
;
1517 if (d
->status
== disabled
)
1521 within_current_scope
= contained_in (get_selected_block (), d
->block
);
1523 within_current_scope
= 1;
1524 if (!within_current_scope
)
1527 current_display_number
= d
->number
;
1529 annotate_display_begin ();
1530 printf_filtered ("%d", d
->number
);
1531 annotate_display_number_end ();
1532 printf_filtered (": ");
1538 annotate_display_format ();
1540 printf_filtered ("x/");
1541 if (d
->format
.count
!= 1)
1542 printf_filtered ("%d", d
->format
.count
);
1543 printf_filtered ("%c", d
->format
.format
);
1544 if (d
->format
.format
!= 'i' && d
->format
.format
!= 's')
1545 printf_filtered ("%c", d
->format
.size
);
1546 printf_filtered (" ");
1548 annotate_display_expression ();
1550 print_expression (d
->exp
, gdb_stdout
);
1551 annotate_display_expression_end ();
1553 if (d
->format
.count
!= 1)
1554 printf_filtered ("\n");
1556 printf_filtered (" ");
1558 val
= evaluate_expression (d
->exp
);
1559 addr
= value_as_pointer (val
);
1560 if (d
->format
.format
== 'i')
1561 addr
= ADDR_BITS_REMOVE (addr
);
1563 annotate_display_value ();
1565 do_examine (d
->format
, addr
, VALUE_BFD_SECTION (val
));
1569 annotate_display_format ();
1571 if (d
->format
.format
)
1572 printf_filtered ("/%c ", d
->format
.format
);
1574 annotate_display_expression ();
1576 print_expression (d
->exp
, gdb_stdout
);
1577 annotate_display_expression_end ();
1579 printf_filtered (" = ");
1581 annotate_display_expression ();
1583 print_formatted (evaluate_expression (d
->exp
),
1584 d
->format
.format
, d
->format
.size
, gdb_stdout
);
1585 printf_filtered ("\n");
1588 annotate_display_end ();
1590 gdb_flush (gdb_stdout
);
1591 current_display_number
= -1;
1594 /* Display all of the values on the auto-display chain which can be
1595 evaluated in the current scope. */
1600 register struct display
*d
;
1602 for (d
= display_chain
; d
; d
= d
->next
)
1606 /* Delete the auto-display which we were in the process of displaying.
1607 This is done when there is an error or a signal. */
1610 disable_display (num
)
1613 register struct display
*d
;
1615 for (d
= display_chain
; d
; d
= d
->next
)
1616 if (d
->number
== num
)
1618 d
->status
= disabled
;
1621 printf_unfiltered ("No display number %d.\n", num
);
1625 disable_current_display ()
1627 if (current_display_number
>= 0)
1629 disable_display (current_display_number
);
1630 fprintf_unfiltered (gdb_stderr
, "Disabling display %d to avoid infinite recursion.\n",
1631 current_display_number
);
1633 current_display_number
= -1;
1637 display_info (ignore
, from_tty
)
1641 register struct display
*d
;
1644 printf_unfiltered ("There are no auto-display expressions now.\n");
1646 printf_filtered ("Auto-display expressions now in effect:\n\
1647 Num Enb Expression\n");
1649 for (d
= display_chain
; d
; d
= d
->next
)
1651 printf_filtered ("%d: %c ", d
->number
, "ny"[(int) d
->status
]);
1653 printf_filtered ("/%d%c%c ", d
->format
.count
, d
->format
.size
,
1655 else if (d
->format
.format
)
1656 printf_filtered ("/%c ", d
->format
.format
);
1657 print_expression (d
->exp
, gdb_stdout
);
1658 if (d
->block
&& !contained_in (get_selected_block (), d
->block
))
1659 printf_filtered (" (cannot be evaluated in the current context)");
1660 printf_filtered ("\n");
1661 gdb_flush (gdb_stdout
);
1666 enable_display (args
, from_tty
)
1670 register char *p
= args
;
1673 register struct display
*d
;
1677 for (d
= display_chain
; d
; d
= d
->next
)
1678 d
->status
= enabled
;
1684 while (*p1
>= '0' && *p1
<= '9')
1686 if (*p1
&& *p1
!= ' ' && *p1
!= '\t')
1687 error ("Arguments must be display numbers.");
1691 for (d
= display_chain
; d
; d
= d
->next
)
1692 if (d
->number
== num
)
1694 d
->status
= enabled
;
1697 printf_unfiltered ("No display number %d.\n", num
);
1700 while (*p
== ' ' || *p
== '\t')
1707 disable_display_command (args
, from_tty
)
1711 register char *p
= args
;
1713 register struct display
*d
;
1717 for (d
= display_chain
; d
; d
= d
->next
)
1718 d
->status
= disabled
;
1724 while (*p1
>= '0' && *p1
<= '9')
1726 if (*p1
&& *p1
!= ' ' && *p1
!= '\t')
1727 error ("Arguments must be display numbers.");
1729 disable_display (atoi (p
));
1732 while (*p
== ' ' || *p
== '\t')
1738 /* Print the value in stack frame FRAME of a variable
1739 specified by a struct symbol. */
1742 print_variable_value (var
, frame
, stream
)
1744 struct frame_info
*frame
;
1745 struct ui_file
*stream
;
1747 value_ptr val
= read_var_value (var
, frame
);
1749 value_print (val
, stream
, 0, Val_pretty_default
);
1752 /* Print the arguments of a stack frame, given the function FUNC
1753 running in that frame (as a symbol), the info on the frame,
1754 and the number of args according to the stack frame (or -1 if unknown). */
1756 /* References here and elsewhere to "number of args according to the
1757 stack frame" appear in all cases to refer to "number of ints of args
1758 according to the stack frame". At least for VAX, i386, isi. */
1761 print_frame_args (func
, fi
, num
, stream
)
1762 struct symbol
*func
;
1763 struct frame_info
*fi
;
1765 struct ui_file
*stream
;
1767 struct block
*b
= NULL
;
1771 register struct symbol
*sym
;
1772 register value_ptr val
;
1773 /* Offset of next stack argument beyond the one we have seen that is
1774 at the highest offset.
1775 -1 if we haven't come to a stack argument yet. */
1776 long highest_offset
= -1;
1778 /* Number of ints of arguments that we have printed so far. */
1779 int args_printed
= 0;
1783 b
= SYMBOL_BLOCK_VALUE (func
);
1784 nsyms
= BLOCK_NSYMS (b
);
1787 for (i
= 0; i
< nsyms
; i
++)
1790 sym
= BLOCK_SYM (b
, i
);
1792 /* Keep track of the highest stack argument offset seen, and
1793 skip over any kinds of symbols we don't care about. */
1795 switch (SYMBOL_CLASS (sym
))
1800 long current_offset
= SYMBOL_VALUE (sym
);
1801 arg_size
= TYPE_LENGTH (SYMBOL_TYPE (sym
));
1803 /* Compute address of next argument by adding the size of
1804 this argument and rounding to an int boundary. */
1806 = ((current_offset
+ arg_size
+ sizeof (int) - 1)
1807 & ~(sizeof (int) - 1));
1809 /* If this is the highest offset seen yet, set highest_offset. */
1810 if (highest_offset
== -1
1811 || (current_offset
> highest_offset
))
1812 highest_offset
= current_offset
;
1814 /* Add the number of ints we're about to print to args_printed. */
1815 args_printed
+= (arg_size
+ sizeof (int) - 1) / sizeof (int);
1818 /* We care about types of symbols, but don't need to keep track of
1819 stack offsets in them. */
1821 case LOC_REGPARM_ADDR
:
1823 case LOC_BASEREG_ARG
:
1826 /* Other types of symbols we just skip over. */
1831 /* We have to look up the symbol because arguments can have
1832 two entries (one a parameter, one a local) and the one we
1833 want is the local, which lookup_symbol will find for us.
1834 This includes gcc1 (not gcc2) on the sparc when passing a
1835 small structure and gcc2 when the argument type is float
1836 and it is passed as a double and converted to float by
1837 the prologue (in the latter case the type of the LOC_ARG
1838 symbol is double and the type of the LOC_LOCAL symbol is
1840 /* But if the parameter name is null, don't try it.
1841 Null parameter names occur on the RS/6000, for traceback tables.
1842 FIXME, should we even print them? */
1844 if (*SYMBOL_NAME (sym
))
1846 struct symbol
*nsym
;
1847 nsym
= lookup_symbol
1849 b
, VAR_NAMESPACE
, (int *) NULL
, (struct symtab
**) NULL
);
1850 if (SYMBOL_CLASS (nsym
) == LOC_REGISTER
)
1852 /* There is a LOC_ARG/LOC_REGISTER pair. This means that
1853 it was passed on the stack and loaded into a register,
1854 or passed in a register and stored in a stack slot.
1855 GDB 3.x used the LOC_ARG; GDB 4.0-4.11 used the LOC_REGISTER.
1857 Reasons for using the LOC_ARG:
1858 (1) because find_saved_registers may be slow for remote
1860 (2) because registers are often re-used and stack slots
1861 rarely (never?) are. Therefore using the stack slot is
1862 much less likely to print garbage.
1864 Reasons why we might want to use the LOC_REGISTER:
1865 (1) So that the backtrace prints the same value as
1866 "print foo". I see no compelling reason why this needs
1867 to be the case; having the backtrace print the value which
1868 was passed in, and "print foo" print the value as modified
1869 within the called function, makes perfect sense to me.
1871 Additional note: It might be nice if "info args" displayed
1873 One more note: There is a case with sparc structure passing
1874 where we need to use the LOC_REGISTER, but this is dealt with
1875 by creating a single LOC_REGPARM in symbol reading. */
1877 /* Leave sym (the LOC_ARG) alone. */
1884 /* Print the current arg. */
1886 fprintf_filtered (stream
, ", ");
1889 annotate_arg_begin ();
1891 fprintf_symbol_filtered (stream
, SYMBOL_SOURCE_NAME (sym
),
1892 SYMBOL_LANGUAGE (sym
), DMGL_PARAMS
| DMGL_ANSI
);
1893 annotate_arg_name_end ();
1894 fputs_filtered ("=", stream
);
1896 /* Avoid value_print because it will deref ref parameters. We just
1897 want to print their addresses. Print ??? for args whose address
1898 we do not know. We pass 2 as "recurse" to val_print because our
1899 standard indentation here is 4 spaces, and val_print indents
1900 2 for each recurse. */
1901 val
= read_var_value (sym
, fi
);
1903 annotate_arg_value (val
== NULL
? NULL
: VALUE_TYPE (val
));
1907 if (GDB_TARGET_IS_D10V
1908 && SYMBOL_CLASS (sym
) == LOC_REGPARM
&& TYPE_CODE (VALUE_TYPE (val
)) == TYPE_CODE_PTR
)
1909 TYPE_LENGTH (VALUE_TYPE (val
)) = 2;
1910 val_print (VALUE_TYPE (val
), VALUE_CONTENTS (val
), 0,
1911 VALUE_ADDRESS (val
),
1912 stream
, 0, 0, 2, Val_no_prettyprint
);
1915 fputs_filtered ("???", stream
);
1917 annotate_arg_end ();
1922 /* Don't print nameless args in situations where we don't know
1923 enough about the stack to find them. */
1928 if (highest_offset
== -1)
1929 start
= FRAME_ARGS_SKIP
;
1931 start
= highest_offset
;
1933 print_frame_nameless_args (fi
, start
, num
- args_printed
,
1938 /* Print nameless args on STREAM.
1939 FI is the frameinfo for this frame, START is the offset
1940 of the first nameless arg, and NUM is the number of nameless args to
1941 print. FIRST is nonzero if this is the first argument (not just
1942 the first nameless arg). */
1945 print_frame_nameless_args (fi
, start
, num
, first
, stream
)
1946 struct frame_info
*fi
;
1950 struct ui_file
*stream
;
1956 for (i
= 0; i
< num
; i
++)
1959 #ifdef NAMELESS_ARG_VALUE
1960 NAMELESS_ARG_VALUE (fi
, start
, &arg_value
);
1962 argsaddr
= FRAME_ARGS_ADDRESS (fi
);
1966 arg_value
= read_memory_integer (argsaddr
+ start
, sizeof (int));
1970 fprintf_filtered (stream
, ", ");
1972 #ifdef PRINT_NAMELESS_INTEGER
1973 PRINT_NAMELESS_INTEGER (stream
, arg_value
);
1975 #ifdef PRINT_TYPELESS_INTEGER
1976 PRINT_TYPELESS_INTEGER (stream
, builtin_type_int
, (LONGEST
) arg_value
);
1978 fprintf_filtered (stream
, "%ld", arg_value
);
1979 #endif /* PRINT_TYPELESS_INTEGER */
1980 #endif /* PRINT_NAMELESS_INTEGER */
1982 start
+= sizeof (int);
1988 printf_command (arg
, from_tty
)
1992 register char *f
= NULL
;
1993 register char *s
= arg
;
1994 char *string
= NULL
;
1995 value_ptr
*val_args
;
1997 char *current_substring
;
1999 int allocated_args
= 20;
2000 struct cleanup
*old_cleanups
;
2002 val_args
= (value_ptr
*) xmalloc (allocated_args
* sizeof (value_ptr
));
2003 old_cleanups
= make_cleanup ((make_cleanup_func
) free_current_contents
,
2007 error_no_arg ("format-control string and values to print");
2009 /* Skip white space before format string */
2010 while (*s
== ' ' || *s
== '\t')
2013 /* A format string should follow, enveloped in double quotes */
2015 error ("Bad format string, missing '\"'.");
2017 /* Parse the format-control string and copy it into the string STRING,
2018 processing some kinds of escape sequence. */
2020 f
= string
= (char *) alloca (strlen (s
) + 1);
2028 error ("Bad format string, non-terminated '\"'.");
2040 *f
++ = '\007'; /* Bell */
2065 /* ??? TODO: handle other escape sequences */
2066 error ("Unrecognized escape character \\%c in format string.",
2076 /* Skip over " and following space and comma. */
2079 while (*s
== ' ' || *s
== '\t')
2082 if (*s
!= ',' && *s
!= 0)
2083 error ("Invalid argument syntax");
2087 while (*s
== ' ' || *s
== '\t')
2090 /* Need extra space for the '\0's. Doubling the size is sufficient. */
2091 substrings
= alloca (strlen (string
) * 2);
2092 current_substring
= substrings
;
2095 /* Now scan the string for %-specs and see what kinds of args they want.
2096 argclass[I] classifies the %-specs so we can give printf_filtered
2097 something of the right size. */
2101 no_arg
, int_arg
, string_arg
, double_arg
, long_long_arg
2103 enum argclass
*argclass
;
2104 enum argclass this_argclass
;
2110 argclass
= (enum argclass
*) alloca (strlen (s
) * sizeof *argclass
);
2118 while (strchr ("0123456789.hlL-+ #", *f
))
2120 if (*f
== 'l' || *f
== 'L')
2127 this_argclass
= string_arg
;
2133 this_argclass
= double_arg
;
2137 error ("`*' not supported for precision or width in printf");
2140 error ("Format specifier `n' not supported in printf");
2143 this_argclass
= no_arg
;
2148 this_argclass
= long_long_arg
;
2150 this_argclass
= int_arg
;
2154 if (this_argclass
!= no_arg
)
2156 strncpy (current_substring
, last_arg
, f
- last_arg
);
2157 current_substring
+= f
- last_arg
;
2158 *current_substring
++ = '\0';
2160 argclass
[nargs_wanted
++] = this_argclass
;
2164 /* Now, parse all arguments and evaluate them.
2165 Store the VALUEs in VAL_ARGS. */
2170 if (nargs
== allocated_args
)
2171 val_args
= (value_ptr
*) xrealloc ((char *) val_args
,
2172 (allocated_args
*= 2)
2173 * sizeof (value_ptr
));
2175 val_args
[nargs
] = parse_to_comma_and_eval (&s1
);
2177 /* If format string wants a float, unchecked-convert the value to
2178 floating point of the same size */
2180 if (argclass
[nargs
] == double_arg
)
2182 struct type
*type
= VALUE_TYPE (val_args
[nargs
]);
2183 if (TYPE_LENGTH (type
) == sizeof (float))
2184 VALUE_TYPE (val_args
[nargs
]) = builtin_type_float
;
2185 if (TYPE_LENGTH (type
) == sizeof (double))
2186 VALUE_TYPE (val_args
[nargs
]) = builtin_type_double
;
2194 if (nargs
!= nargs_wanted
)
2195 error ("Wrong number of arguments for specified format-string");
2197 /* Now actually print them. */
2198 current_substring
= substrings
;
2199 for (i
= 0; i
< nargs
; i
++)
2201 switch (argclass
[i
])
2208 tem
= value_as_pointer (val_args
[i
]);
2210 /* This is a %s argument. Find the length of the string. */
2215 read_memory_section (tem
+ j
, &c
, 1,
2216 VALUE_BFD_SECTION (val_args
[i
]));
2221 /* Copy the string contents into a string inside GDB. */
2222 str
= (char *) alloca (j
+ 1);
2223 read_memory_section (tem
, str
, j
, VALUE_BFD_SECTION (val_args
[i
]));
2226 printf_filtered (current_substring
, str
);
2231 double val
= value_as_double (val_args
[i
]);
2232 printf_filtered (current_substring
, val
);
2236 #if defined (CC_HAS_LONG_LONG) && defined (PRINTF_HAS_LONG_LONG)
2238 long long val
= value_as_long (val_args
[i
]);
2239 printf_filtered (current_substring
, val
);
2243 error ("long long not supported in printf");
2247 /* FIXME: there should be separate int_arg and long_arg. */
2248 long val
= value_as_long (val_args
[i
]);
2249 printf_filtered (current_substring
, val
);
2252 default: /* purecov: deadcode */
2253 error ("internal error in printf_command"); /* purecov: deadcode */
2255 /* Skip to the next substring. */
2256 current_substring
+= strlen (current_substring
) + 1;
2258 /* Print the portion of the format string after the last argument. */
2259 printf_filtered (last_arg
);
2261 do_cleanups (old_cleanups
);
2264 /* Dump a specified section of assembly code. With no command line
2265 arguments, this command will dump the assembly code for the
2266 function surrounding the pc value in the selected frame. With one
2267 argument, it will dump the assembly code surrounding that pc value.
2268 Two arguments are interpeted as bounds within which to dump
2273 disassemble_command (arg
, from_tty
)
2277 CORE_ADDR low
, high
;
2279 CORE_ADDR pc
, pc_masked
;
2288 if (!selected_frame
)
2289 error ("No frame selected.\n");
2291 pc
= get_frame_pc (selected_frame
);
2292 if (find_pc_partial_function (pc
, &name
, &low
, &high
) == 0)
2293 error ("No function contains program counter for selected frame.\n");
2295 else if (tui_version
)
2296 low
= (CORE_ADDR
) tuiDo ((TuiOpaqueFuncPtr
) tui_vGetLowDisassemblyAddress
,
2300 low
+= FUNCTION_START_OFFSET
;
2302 else if (!(space_index
= (char *) strchr (arg
, ' ')))
2305 pc
= parse_and_eval_address (arg
);
2306 if (find_pc_partial_function (pc
, &name
, &low
, &high
) == 0)
2307 error ("No function contains specified address.\n");
2309 else if (tui_version
)
2310 low
= (CORE_ADDR
) tuiDo ((TuiOpaqueFuncPtr
) tui_vGetLowDisassemblyAddress
,
2315 if (overlay_debugging
)
2317 section
= find_pc_overlay (pc
);
2318 if (pc_in_unmapped_range (pc
, section
))
2320 /* find_pc_partial_function will have returned low and high
2321 relative to the symbolic (mapped) address range. Need to
2322 translate them back to the unmapped range where PC is. */
2323 low
= overlay_unmapped_address (low
, section
);
2324 high
= overlay_unmapped_address (high
, section
);
2328 low
+= FUNCTION_START_OFFSET
;
2332 /* Two arguments. */
2333 *space_index
= '\0';
2334 low
= parse_and_eval_address (arg
);
2335 high
= parse_and_eval_address (space_index
+ 1);
2340 m_winPtrIsNull (disassemWin
) || !disassemWin
->generic
.isVisible
)
2343 printf_filtered ("Dump of assembler code ");
2346 printf_filtered ("for function %s:\n", name
);
2350 printf_filtered ("from ");
2351 print_address_numeric (low
, 1, gdb_stdout
);
2352 printf_filtered (" to ");
2353 print_address_numeric (high
, 1, gdb_stdout
);
2354 printf_filtered (":\n");
2357 /* Dump the specified range. */
2360 #ifdef GDB_TARGET_MASK_DISAS_PC
2361 pc_masked
= GDB_TARGET_MASK_DISAS_PC (pc
);
2366 while (pc_masked
< high
)
2369 print_address (pc_masked
, gdb_stdout
);
2370 printf_filtered (":\t");
2371 /* We often wrap here if there are long symbolic names. */
2373 pc
+= print_insn (pc
, gdb_stdout
);
2374 printf_filtered ("\n");
2376 #ifdef GDB_TARGET_MASK_DISAS_PC
2377 pc_masked
= GDB_TARGET_MASK_DISAS_PC (pc
);
2382 printf_filtered ("End of assembler dump.\n");
2383 gdb_flush (gdb_stdout
);
2388 tuiDo ((TuiOpaqueFuncPtr
) tui_vAddWinToLayout
, DISASSEM_WIN
);
2389 tuiDo ((TuiOpaqueFuncPtr
) tui_vUpdateSourceWindowsWithAddr
, low
);
2394 /* Print the instruction at address MEMADDR in debugged memory,
2395 on STREAM. Returns length of the instruction, in bytes. */
2398 print_insn (memaddr
, stream
)
2400 struct ui_file
*stream
;
2402 if (TARGET_BYTE_ORDER
== BIG_ENDIAN
)
2403 TARGET_PRINT_INSN_INFO
->endian
= BFD_ENDIAN_BIG
;
2405 TARGET_PRINT_INSN_INFO
->endian
= BFD_ENDIAN_LITTLE
;
2407 if (TARGET_ARCHITECTURE
!= NULL
)
2408 TARGET_PRINT_INSN_INFO
->mach
= TARGET_ARCHITECTURE
->mach
;
2409 /* else: should set .mach=0 but some disassemblers don't grok this */
2411 return TARGET_PRINT_INSN (memaddr
, TARGET_PRINT_INSN_INFO
);
2416 _initialize_printcmd ()
2418 current_display_number
= -1;
2420 add_info ("address", address_info
,
2421 "Describe where symbol SYM is stored.");
2423 add_info ("symbol", sym_info
,
2424 "Describe what symbol is at location ADDR.\n\
2425 Only for symbols with fixed locations (global or static scope).");
2427 add_com ("x", class_vars
, x_command
,
2428 concat ("Examine memory: x/FMT ADDRESS.\n\
2429 ADDRESS is an expression for the memory address to examine.\n\
2430 FMT is a repeat count followed by a format letter and a size letter.\n\
2431 Format letters are o(octal), x(hex), d(decimal), u(unsigned decimal),\n\
2432 t(binary), f(float), a(address), i(instruction), c(char) and s(string).\n",
2433 "Size letters are b(byte), h(halfword), w(word), g(giant, 8 bytes).\n\
2434 The specified number of objects of the specified size are printed\n\
2435 according to the format.\n\n\
2436 Defaults for format and size letters are those previously used.\n\
2437 Default count is 1. Default address is following last thing printed\n\
2438 with this command or \"print\".", NULL
));
2440 add_com ("disassemble", class_vars
, disassemble_command
,
2441 "Disassemble a specified section of memory.\n\
2442 Default is the function surrounding the pc of the selected frame.\n\
2443 With a single argument, the function surrounding that address is dumped.\n\
2444 Two arguments are taken as a range of memory to dump.");
2446 add_com_alias ("va", "disassemble", class_xdb
, 0);
2449 add_com ("whereis", class_vars
, whereis_command
,
2450 "Print line number and file of definition of variable.");
2453 add_info ("display", display_info
,
2454 "Expressions to display when program stops, with code numbers.");
2456 add_cmd ("undisplay", class_vars
, undisplay_command
,
2457 "Cancel some expressions to be displayed when program stops.\n\
2458 Arguments are the code numbers of the expressions to stop displaying.\n\
2459 No argument means cancel all automatic-display expressions.\n\
2460 \"delete display\" has the same effect as this command.\n\
2461 Do \"info display\" to see current list of code numbers.",
2464 add_com ("display", class_vars
, display_command
,
2465 "Print value of expression EXP each time the program stops.\n\
2466 /FMT may be used before EXP as in the \"print\" command.\n\
2467 /FMT \"i\" or \"s\" or including a size-letter is allowed,\n\
2468 as in the \"x\" command, and then EXP is used to get the address to examine\n\
2469 and examining is done as in the \"x\" command.\n\n\
2470 With no argument, display all currently requested auto-display expressions.\n\
2471 Use \"undisplay\" to cancel display requests previously made."
2474 add_cmd ("display", class_vars
, enable_display
,
2475 "Enable some expressions to be displayed when program stops.\n\
2476 Arguments are the code numbers of the expressions to resume displaying.\n\
2477 No argument means enable all automatic-display expressions.\n\
2478 Do \"info display\" to see current list of code numbers.", &enablelist
);
2480 add_cmd ("display", class_vars
, disable_display_command
,
2481 "Disable some expressions to be displayed when program stops.\n\
2482 Arguments are the code numbers of the expressions to stop displaying.\n\
2483 No argument means disable all automatic-display expressions.\n\
2484 Do \"info display\" to see current list of code numbers.", &disablelist
);
2486 add_cmd ("display", class_vars
, undisplay_command
,
2487 "Cancel some expressions to be displayed when program stops.\n\
2488 Arguments are the code numbers of the expressions to stop displaying.\n\
2489 No argument means cancel all automatic-display expressions.\n\
2490 Do \"info display\" to see current list of code numbers.", &deletelist
);
2492 add_com ("printf", class_vars
, printf_command
,
2493 "printf \"printf format string\", arg1, arg2, arg3, ..., argn\n\
2494 This is useful for formatted output in user-defined commands.");
2496 add_com ("output", class_vars
, output_command
,
2497 "Like \"print\" but don't put in value history and don't print newline.\n\
2498 This is useful in user-defined commands.");
2500 add_prefix_cmd ("set", class_vars
, set_command
,
2501 concat ("Evaluate expression EXP and assign result to variable VAR, using assignment\n\
2502 syntax appropriate for the current language (VAR = EXP or VAR := EXP for\n\
2503 example). VAR may be a debugger \"convenience\" variable (names starting\n\
2504 with $), a register (a few standard names starting with $), or an actual\n\
2505 variable in the program being debugged. EXP is any valid expression.\n",
2506 "Use \"set variable\" for variables with names identical to set subcommands.\n\
2507 \nWith a subcommand, this command modifies parts of the gdb environment.\n\
2508 You can see these environment settings with the \"show\" command.", NULL
),
2509 &setlist
, "set ", 1, &cmdlist
);
2511 add_com ("assign", class_vars
, set_command
, concat ("Evaluate expression \
2512 EXP and assign result to variable VAR, using assignment\n\
2513 syntax appropriate for the current language (VAR = EXP or VAR := EXP for\n\
2514 example). VAR may be a debugger \"convenience\" variable (names starting\n\
2515 with $), a register (a few standard names starting with $), or an actual\n\
2516 variable in the program being debugged. EXP is any valid expression.\n",
2517 "Use \"set variable\" for variables with names identical to set subcommands.\n\
2518 \nWith a subcommand, this command modifies parts of the gdb environment.\n\
2519 You can see these environment settings with the \"show\" command.", NULL
));
2521 /* "call" is the same as "set", but handy for dbx users to call fns. */
2522 add_com ("call", class_vars
, call_command
,
2523 "Call a function in the program.\n\
2524 The argument is the function name and arguments, in the notation of the\n\
2525 current working language. The result is printed and saved in the value\n\
2526 history, if it is not void.");
2528 add_cmd ("variable", class_vars
, set_command
,
2529 "Evaluate expression EXP and assign result to variable VAR, using assignment\n\
2530 syntax appropriate for the current language (VAR = EXP or VAR := EXP for\n\
2531 example). VAR may be a debugger \"convenience\" variable (names starting\n\
2532 with $), a register (a few standard names starting with $), or an actual\n\
2533 variable in the program being debugged. EXP is any valid expression.\n\
2534 This may usually be abbreviated to simply \"set\".",
2537 add_com ("print", class_vars
, print_command
,
2538 concat ("Print value of expression EXP.\n\
2539 Variables accessible are those of the lexical environment of the selected\n\
2540 stack frame, plus all those whose scope is global or an entire file.\n\
2542 $NUM gets previous value number NUM. $ and $$ are the last two values.\n\
2543 $$NUM refers to NUM'th value back from the last one.\n\
2544 Names starting with $ refer to registers (with the values they would have\n",
2545 "if the program were to return to the stack frame now selected, restoring\n\
2546 all registers saved by frames farther in) or else to debugger\n\
2547 \"convenience\" variables (any such name not a known register).\n\
2548 Use assignment expressions to give values to convenience variables.\n",
2550 {TYPE}ADREXP refers to a datum of data type TYPE, located at address ADREXP.\n\
2551 @ is a binary operator for treating consecutive data objects\n\
2552 anywhere in memory as an array. FOO@NUM gives an array whose first\n\
2553 element is FOO, whose second element is stored in the space following\n\
2554 where FOO is stored, etc. FOO must be an expression whose value\n\
2555 resides in memory.\n",
2557 EXP may be preceded with /FMT, where FMT is a format letter\n\
2558 but no count or size letter (see \"x\" command).", NULL
));
2559 add_com_alias ("p", "print", class_vars
, 1);
2561 add_com ("inspect", class_vars
, inspect_command
,
2562 "Same as \"print\" command, except that if you are running in the epoch\n\
2563 environment, the value is printed in its own window.");
2566 add_set_cmd ("max-symbolic-offset", no_class
, var_uinteger
,
2567 (char *) &max_symbolic_offset
,
2568 "Set the largest offset that will be printed in <symbol+1234> form.",
2572 add_set_cmd ("symbol-filename", no_class
, var_boolean
,
2573 (char *) &print_symbol_filename
,
2574 "Set printing of source filename and line number with <symbol>.",
2578 /* For examine/instruction a single byte quantity is specified as
2579 the data. This avoids problems with value_at_lazy() requiring a
2580 valid data type (and rejecting VOID). */
2581 examine_i_type
= init_type (TYPE_CODE_INT
, 1, 0, "examine_i_type", NULL
);
2583 examine_b_type
= init_type (TYPE_CODE_INT
, 1, 0, "examine_b_type", NULL
);
2584 examine_h_type
= init_type (TYPE_CODE_INT
, 2, 0, "examine_h_type", NULL
);
2585 examine_w_type
= init_type (TYPE_CODE_INT
, 4, 0, "examine_w_type", NULL
);
2586 examine_g_type
= init_type (TYPE_CODE_INT
, 8, 0, "examine_g_type", NULL
);