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 /* 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
PARAMS ((struct frame_info
*, long,
138 int, int, GDB_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
PARAMS ((value_ptr
, int, int));
170 static struct format_data decode_format
PARAMS ((char **, int, int));
172 static int print_insn
PARAMS ((CORE_ADDR
, GDB_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') p
++;
204 /* Now process size or format letters that follow. */
208 if (*p
== 'b' || *p
== 'h' || *p
== 'w' || *p
== 'g')
210 else if (*p
>= 'a' && *p
<= 'z')
216 while (*p
== ' ' || *p
== '\t') p
++;
219 /* Set defaults for format and size if not specified. */
220 if (val
.format
== '?')
224 /* Neither has been specified. */
225 val
.format
= oformat
;
229 /* If a size is specified, any format makes a reasonable
230 default except 'i'. */
231 val
.format
= oformat
== 'i' ? 'x' : oformat
;
233 else if (val
.size
== '?')
238 /* Pick the appropriate size for an address. */
239 if (TARGET_PTR_BIT
== 64)
240 val
.size
= osize
? 'g' : osize
;
241 else if (TARGET_PTR_BIT
== 32)
242 val
.size
= osize
? 'w' : osize
;
243 else if (TARGET_PTR_BIT
== 16)
244 val
.size
= osize
? 'h' : osize
;
246 /* Bad value for TARGET_PTR_BIT */
250 /* Floating point has to be word or giantword. */
251 if (osize
== 'w' || osize
== 'g')
254 /* Default it to giantword if the last used size is not
256 val
.size
= osize
? 'g' : osize
;
259 /* Characters default to one byte. */
260 val
.size
= osize
? 'b' : osize
;
263 /* The default is the size most recently specified. */
270 /* Print value VAL on gdb_stdout according to FORMAT, a letter or 0.
271 Do not end with a newline.
272 0 means print VAL according to its own type.
273 SIZE is the letter for the size of datum being printed.
274 This is used to pad hex numbers so they line up. */
277 print_formatted (val
, format
, size
)
278 register value_ptr val
;
282 struct type
*type
= check_typedef (VALUE_TYPE (val
));
283 int len
= TYPE_LENGTH (type
);
285 if (VALUE_LVAL (val
) == lval_memory
)
287 next_address
= VALUE_ADDRESS (val
) + len
;
288 next_section
= VALUE_BFD_SECTION (val
);
294 /* FIXME: Need to handle wchar_t's here... */
295 next_address
= VALUE_ADDRESS (val
)
296 + val_print_string (VALUE_ADDRESS (val
), -1, 1, gdb_stdout
);
297 next_section
= VALUE_BFD_SECTION (val
);
301 /* The old comment says
302 "Force output out, print_insn not using _filtered".
303 I'm not completely sure what that means, I suspect most print_insn
304 now do use _filtered, so I guess it's obsolete.
305 --Yes, it does filter now, and so this is obsolete. -JB */
307 /* We often wrap here if there are long symbolic names. */
309 next_address
= VALUE_ADDRESS (val
)
310 + print_insn (VALUE_ADDRESS (val
), gdb_stdout
);
311 next_section
= VALUE_BFD_SECTION (val
);
316 || TYPE_CODE (type
) == TYPE_CODE_ARRAY
317 || TYPE_CODE (type
) == TYPE_CODE_STRING
318 || TYPE_CODE (type
) == TYPE_CODE_STRUCT
319 || TYPE_CODE (type
) == TYPE_CODE_UNION
)
320 /* If format is 0, use the 'natural' format for
321 * that type of value. If the type is non-scalar,
322 * we have to use language rules to print it as
323 * a series of scalars.
325 value_print (val
, gdb_stdout
, format
, Val_pretty_default
);
327 /* User specified format, so don't look to the
328 * the type to tell us what to do.
330 print_scalar_formatted (VALUE_CONTENTS (val
), type
,
331 format
, size
, gdb_stdout
);
335 /* Print a scalar of data of type TYPE, pointed to in GDB by VALADDR,
336 according to letters FORMAT and SIZE on STREAM.
337 FORMAT may not be zero. Formats s and i are not supported at this level.
339 This is how the elements of an array or structure are printed
343 print_scalar_formatted (valaddr
, type
, format
, size
, stream
)
351 unsigned int len
= TYPE_LENGTH (type
);
353 if (len
> sizeof (LONGEST
)
361 if (! TYPE_UNSIGNED (type
)
362 || ! extract_long_unsigned_integer (valaddr
, len
, &val_long
))
364 /* We can't print it normally, but we can print it in hex.
365 Printing it in the wrong radix is more useful than saying
366 "use /x, you dummy". */
367 /* FIXME: we could also do octal or binary if that was the
369 /* FIXME: we should be using the size field to give us a
370 minimum field width to print. */
373 print_octal_chars (stream
, valaddr
, len
);
374 else if( format
== 'd' )
375 print_decimal_chars (stream
, valaddr
, len
);
376 else if( format
== 't' )
377 print_binary_chars (stream
, valaddr
, len
);
380 /* replace with call to print_hex_chars? Looks
381 like val_print_type_code_int is redoing
384 val_print_type_code_int (type
, valaddr
, stream
);
389 /* If we get here, extract_long_unsigned_integer set val_long. */
391 else if (format
!= 'f')
392 val_long
= unpack_long (type
, valaddr
);
394 /* If we are printing it as unsigned, truncate it in case it is actually
395 a negative signed value (e.g. "print/u (short)-1" should print 65535
396 (if shorts are 16 bits) instead of 4294967295). */
399 if (len
< sizeof (LONGEST
))
400 val_long
&= ((LONGEST
) 1 << HOST_CHAR_BIT
* len
) - 1;
408 /* no size specified, like in print. Print varying # of digits. */
409 print_longest (stream
, 'x', 1, val_long
);
418 print_longest (stream
, size
, 1, val_long
);
421 error ("Undefined output size \"%c\".", size
);
426 print_longest (stream
, 'd', 1, val_long
);
430 print_longest (stream
, 'u', 0, val_long
);
435 print_longest (stream
, 'o', 1, val_long
);
437 fprintf_filtered (stream
, "0");
441 print_address (unpack_pointer (type
, valaddr
), stream
);
445 value_print (value_from_longest (builtin_type_char
, val_long
), stream
, 0,
450 if (len
== sizeof (float))
451 type
= builtin_type_float
;
452 else if (len
== sizeof (double))
453 type
= builtin_type_double
;
454 print_floating (valaddr
, type
, stream
);
461 /* Binary; 't' stands for "two". */
463 char bits
[8*(sizeof val_long
) + 1];
464 char buf
[8*(sizeof val_long
) + 32];
469 width
= 8*(sizeof val_long
);
486 error ("Undefined output size \"%c\".", size
);
492 bits
[width
] = (val_long
& 1) ? '1' : '0';
497 while (*cp
&& *cp
== '0')
502 strcpy (buf
, local_binary_format_prefix());
504 strcat (buf
, local_binary_format_suffix());
505 fprintf_filtered (stream
, buf
);
510 error ("Undefined output format \"%c\".", format
);
514 /* Specify default address for `x' command.
515 `info lines' uses this. */
518 set_next_address (addr
)
523 /* Make address available to the user as $_. */
524 set_internalvar (lookup_internalvar ("_"),
525 value_from_longest (lookup_pointer_type (builtin_type_void
),
529 /* Optionally print address ADDR symbolically as <SYMBOL+OFFSET> on STREAM,
530 after LEADIN. Print nothing if no symbolic name is found nearby.
531 Optionally also print source file and line number, if available.
532 DO_DEMANGLE controls whether to print a symbol in its native "raw" form,
533 or to interpret it as a possible C++ name and convert it back to source
534 form. However note that DO_DEMANGLE can be overridden by the specific
535 settings of the demangle and asm_demangle variables. */
538 print_address_symbolic (addr
, stream
, do_demangle
, leadin
)
544 struct minimal_symbol
*msymbol
;
545 struct symbol
*symbol
;
546 struct symtab
*symtab
= 0;
547 CORE_ADDR name_location
= 0;
549 asection
*section
= 0;
552 /* Determine if the address is in an overlay, and whether it is mapped. */
553 if (overlay_debugging
)
555 section
= find_pc_overlay (addr
);
556 if (pc_in_unmapped_range (addr
, section
))
559 addr
= overlay_mapped_address (addr
, section
);
563 /* On some targets, add in extra "flag" bits to PC for
564 disassembly. This should ensure that "rounding errors" in
565 symbol addresses that are masked for disassembly favour the
566 the correct symbol. */
568 #ifdef GDB_TARGET_UNMASK_DISAS_PC
569 addr
= GDB_TARGET_UNMASK_DISAS_PC (addr
);
572 /* First try to find the address in the symbol table, then
573 in the minsyms. Take the closest one. */
575 /* This is defective in the sense that it only finds text symbols. So
576 really this is kind of pointless--we should make sure that the
577 minimal symbols have everything we need (by changing that we could
578 save some memory, but for many debug format--ELF/DWARF or
579 anything/stabs--it would be inconvenient to eliminate those minimal
581 msymbol
= lookup_minimal_symbol_by_pc_section (addr
, section
);
582 symbol
= find_pc_sect_function (addr
, section
);
586 name_location
= BLOCK_START (SYMBOL_BLOCK_VALUE (symbol
));
588 name
= SYMBOL_SOURCE_NAME (symbol
);
590 name
= SYMBOL_LINKAGE_NAME (symbol
);
595 if (SYMBOL_VALUE_ADDRESS (msymbol
) > name_location
|| symbol
== NULL
)
597 /* The msymbol is closer to the address than the symbol;
598 use the msymbol instead. */
601 name_location
= SYMBOL_VALUE_ADDRESS (msymbol
);
603 name
= SYMBOL_SOURCE_NAME (msymbol
);
605 name
= SYMBOL_LINKAGE_NAME (msymbol
);
608 if (symbol
== NULL
&& msymbol
== NULL
)
611 /* On some targets, mask out extra "flag" bits from PC for handsome
614 #ifdef GDB_TARGET_MASK_DISAS_PC
615 name_location
= GDB_TARGET_MASK_DISAS_PC (name_location
);
616 addr
= GDB_TARGET_MASK_DISAS_PC (addr
);
619 /* If the nearest symbol is too far away, don't print anything symbolic. */
621 /* For when CORE_ADDR is larger than unsigned int, we do math in
622 CORE_ADDR. But when we detect unsigned wraparound in the
623 CORE_ADDR math, we ignore this test and print the offset,
624 because addr+max_symbolic_offset has wrapped through the end
625 of the address space back to the beginning, giving bogus comparison. */
626 if (addr
> name_location
+ max_symbolic_offset
627 && name_location
+ max_symbolic_offset
> name_location
)
630 fputs_filtered (leadin
, stream
);
632 fputs_filtered ("<*", stream
);
634 fputs_filtered ("<", stream
);
635 fputs_filtered (name
, stream
);
636 if (addr
!= name_location
)
637 fprintf_filtered (stream
, "+%u", (unsigned int)(addr
- name_location
));
639 /* Append source filename and line number if desired. Give specific
640 line # of this addr, if we have it; else line # of the nearest symbol. */
641 if (print_symbol_filename
)
643 struct symtab_and_line sal
;
645 sal
= find_pc_sect_line (addr
, section
, 0);
648 fprintf_filtered (stream
, " at %s:%d", sal
.symtab
->filename
, sal
.line
);
649 else if (symtab
&& symbol
&& symbol
->line
)
650 fprintf_filtered (stream
, " at %s:%d", symtab
->filename
, symbol
->line
);
652 fprintf_filtered (stream
, " in %s", symtab
->filename
);
655 fputs_filtered ("*>", stream
);
657 fputs_filtered (">", stream
);
661 /* Print address ADDR on STREAM. USE_LOCAL means the same thing as for
664 print_address_numeric (addr
, use_local
, stream
)
669 /* This assumes a CORE_ADDR can fit in a LONGEST. Probably a safe
671 print_longest (stream
, 'x', use_local
, (ULONGEST
) addr
);
674 /* Print address ADDR symbolically on STREAM.
675 First print it as a number. Then perhaps print
676 <SYMBOL + OFFSET> after the number. */
679 print_address (addr
, stream
)
683 print_address_numeric (addr
, 1, stream
);
684 print_address_symbolic (addr
, stream
, asm_demangle
, " ");
687 /* Print address ADDR symbolically on STREAM. Parameter DEMANGLE
688 controls whether to print the symbolic name "raw" or demangled.
689 Global setting "addressprint" controls whether to print hex address
693 print_address_demangle (addr
, stream
, do_demangle
)
700 fprintf_filtered (stream
, "0");
702 else if (addressprint
)
704 print_address_numeric (addr
, 1, stream
);
705 print_address_symbolic (addr
, stream
, do_demangle
, " ");
709 print_address_symbolic (addr
, stream
, do_demangle
, "");
714 /* These are the types that $__ will get after an examine command of one
717 static struct type
*examine_i_type
;
719 static struct type
*examine_b_type
;
720 static struct type
*examine_h_type
;
721 static struct type
*examine_w_type
;
722 static struct type
*examine_g_type
;
724 /* Examine data at address ADDR in format FMT.
725 Fetch it from memory and print on gdb_stdout. */
728 do_examine (fmt
, addr
, sect
)
729 struct format_data fmt
;
733 register char format
= 0;
735 register int count
= 1;
736 struct type
*val_type
= NULL
;
738 register int maxelts
;
746 /* String or instruction format implies fetch single bytes
747 regardless of the specified size. */
748 if (format
== 's' || format
== 'i')
752 val_type
= examine_i_type
;
753 else if (size
== 'b')
754 val_type
= examine_b_type
;
755 else if (size
== 'h')
756 val_type
= examine_h_type
;
757 else if (size
== 'w')
758 val_type
= examine_w_type
;
759 else if (size
== 'g')
760 val_type
= examine_g_type
;
767 if (format
== 's' || format
== 'i')
770 /* Print as many objects as specified in COUNT, at most maxelts per line,
771 with the address of the next one at the start of each line. */
776 print_address (next_address
, gdb_stdout
);
777 printf_filtered (":");
782 printf_filtered ("\t");
783 /* Note that print_formatted sets next_address for the next
785 last_examine_address
= next_address
;
787 if (last_examine_value
)
788 value_free (last_examine_value
);
790 /* The value to be displayed is not fetched greedily.
791 Instead, to avoid the posibility of a fetched value not
792 being used, its retreval is delayed until the print code
793 uses it. When examining an instruction stream, the
794 disassembler will perform its own memory fetch using just
795 the address stored in LAST_EXAMINE_VALUE. FIXME: Should
796 the disassembler be modified so that LAST_EXAMINE_VALUE
797 is left with the byte sequence from the last complete
798 instruction fetched from memory? */
799 last_examine_value
= value_at_lazy (val_type
, next_address
, sect
);
801 if (last_examine_value
)
802 release_value (last_examine_value
);
804 print_formatted (last_examine_value
, format
, size
);
806 printf_filtered ("\n");
807 gdb_flush (gdb_stdout
);
812 validate_format (fmt
, cmdname
)
813 struct format_data fmt
;
817 error ("Size letters are meaningless in \"%s\" command.", cmdname
);
819 error ("Item count other than 1 is meaningless in \"%s\" command.",
821 if (fmt
.format
== 'i' || fmt
.format
== 's')
822 error ("Format letter \"%c\" is meaningless in \"%s\" command.",
823 fmt
.format
, cmdname
);
826 /* Evaluate string EXP as an expression in the current language and
827 print the resulting value. EXP may contain a format specifier as the
828 first argument ("/x myvar" for example, to print myvar in hex).
832 print_command_1 (exp
, inspect
, voidprint
)
837 struct expression
*expr
;
838 register struct cleanup
*old_chain
= 0;
839 register char format
= 0;
840 register value_ptr val
;
841 struct format_data fmt
;
844 /* Pass inspect flag to the rest of the print routines in a global (sigh). */
845 inspect_it
= inspect
;
847 if (exp
&& *exp
== '/')
850 fmt
= decode_format (&exp
, last_format
, 0);
851 validate_format (fmt
, "print");
852 last_format
= format
= fmt
.format
;
864 expr
= parse_expression (exp
);
865 old_chain
= make_cleanup ((make_cleanup_func
) free_current_contents
,
868 val
= evaluate_expression (expr
);
870 /* C++: figure out what type we actually want to print it as. */
871 type
= VALUE_TYPE (val
);
874 && ( TYPE_CODE (type
) == TYPE_CODE_PTR
875 || TYPE_CODE (type
) == TYPE_CODE_REF
)
876 && ( TYPE_CODE (TYPE_TARGET_TYPE (type
)) == TYPE_CODE_STRUCT
877 || TYPE_CODE (TYPE_TARGET_TYPE (type
)) == TYPE_CODE_UNION
))
881 v
= value_from_vtable_info (val
, TYPE_TARGET_TYPE (type
));
885 type
= VALUE_TYPE (val
);
890 val
= access_value_history (0);
892 if (voidprint
|| (val
&& VALUE_TYPE (val
) &&
893 TYPE_CODE (VALUE_TYPE (val
)) != TYPE_CODE_VOID
))
895 int histindex
= record_latest_value (val
);
898 annotate_value_history_begin (histindex
, VALUE_TYPE (val
));
900 annotate_value_begin (VALUE_TYPE (val
));
903 printf_unfiltered ("\031(gdb-makebuffer \"%s\" %d '(\"", exp
, histindex
);
905 if (histindex
>= 0) printf_filtered ("$%d = ", histindex
);
908 annotate_value_history_value ();
910 print_formatted (val
, format
, fmt
.size
);
911 printf_filtered ("\n");
914 annotate_value_history_end ();
916 annotate_value_end ();
919 printf_unfiltered("\") )\030");
923 do_cleanups (old_chain
);
924 inspect_it
= 0; /* Reset print routines to normal */
929 print_command (exp
, from_tty
)
933 print_command_1 (exp
, 0, 1);
936 /* Same as print, except in epoch, it gets its own window */
939 inspect_command (exp
, from_tty
)
943 extern int epoch_interface
;
945 print_command_1 (exp
, epoch_interface
, 1);
948 /* Same as print, except it doesn't print void results. */
951 call_command (exp
, from_tty
)
955 print_command_1 (exp
, 0, 0);
960 output_command (exp
, from_tty
)
964 struct expression
*expr
;
965 register struct cleanup
*old_chain
;
966 register char format
= 0;
967 register value_ptr val
;
968 struct format_data fmt
;
970 if (exp
&& *exp
== '/')
973 fmt
= decode_format (&exp
, 0, 0);
974 validate_format (fmt
, "output");
978 expr
= parse_expression (exp
);
979 old_chain
= make_cleanup ((make_cleanup_func
) free_current_contents
, &expr
);
981 val
= evaluate_expression (expr
);
983 annotate_value_begin (VALUE_TYPE (val
));
985 print_formatted (val
, format
, fmt
.size
);
987 annotate_value_end ();
989 do_cleanups (old_chain
);
994 set_command (exp
, from_tty
)
998 struct expression
*expr
= parse_expression (exp
);
999 register struct cleanup
*old_chain
1000 = make_cleanup ((make_cleanup_func
) free_current_contents
, &expr
);
1001 evaluate_expression (expr
);
1002 do_cleanups (old_chain
);
1007 sym_info (arg
, from_tty
)
1011 struct minimal_symbol
*msymbol
;
1012 struct objfile
*objfile
;
1013 struct obj_section
*osect
;
1015 CORE_ADDR addr
, sect_addr
;
1017 unsigned int offset
;
1020 error_no_arg ("address");
1022 addr
= parse_and_eval_address (arg
);
1023 ALL_OBJSECTIONS (objfile
, osect
)
1025 sect
= osect
->the_bfd_section
;
1026 sect_addr
= overlay_mapped_address (addr
, sect
);
1028 if (osect
->addr
<= sect_addr
&& sect_addr
< osect
->endaddr
&&
1029 (msymbol
= lookup_minimal_symbol_by_pc_section (sect_addr
, sect
)))
1032 offset
= sect_addr
- SYMBOL_VALUE_ADDRESS (msymbol
);
1034 printf_filtered ("%s + %u in ",
1035 SYMBOL_SOURCE_NAME (msymbol
), offset
);
1037 printf_filtered ("%s in ",
1038 SYMBOL_SOURCE_NAME (msymbol
));
1039 if (pc_in_unmapped_range (addr
, sect
))
1040 printf_filtered ("load address range of ");
1041 if (section_is_overlay (sect
))
1042 printf_filtered ("%s overlay ",
1043 section_is_mapped (sect
) ? "mapped" : "unmapped");
1044 printf_filtered ("section %s", sect
->name
);
1045 printf_filtered ("\n");
1049 printf_filtered ("No symbol matches %s.\n", arg
);
1054 address_info (exp
, from_tty
)
1058 register struct symbol
*sym
;
1059 register struct minimal_symbol
*msymbol
;
1061 register long basereg
;
1063 CORE_ADDR load_addr
;
1064 int is_a_field_of_this
; /* C++: lookup_symbol sets this to nonzero
1065 if exp is a field of `this'. */
1068 error ("Argument required.");
1070 sym
= lookup_symbol (exp
, get_selected_block (), VAR_NAMESPACE
,
1071 &is_a_field_of_this
, (struct symtab
**)NULL
);
1074 if (is_a_field_of_this
)
1076 printf_filtered ("Symbol \"");
1077 fprintf_symbol_filtered (gdb_stdout
, exp
,
1078 current_language
->la_language
, DMGL_ANSI
);
1079 printf_filtered ("\" is a field of the local class variable `this'\n");
1083 msymbol
= lookup_minimal_symbol (exp
, NULL
, NULL
);
1085 if (msymbol
!= NULL
)
1087 load_addr
= SYMBOL_VALUE_ADDRESS (msymbol
);
1089 printf_filtered ("Symbol \"");
1090 fprintf_symbol_filtered (gdb_stdout
, exp
,
1091 current_language
->la_language
, DMGL_ANSI
);
1092 printf_filtered ("\" is at ");
1093 print_address_numeric (load_addr
, 1, gdb_stdout
);
1094 printf_filtered (" in a file compiled without debugging");
1095 section
= SYMBOL_BFD_SECTION (msymbol
);
1096 if (section_is_overlay (section
))
1098 load_addr
= overlay_unmapped_address (load_addr
, section
);
1099 printf_filtered (",\n -- loaded at ");
1100 print_address_numeric (load_addr
, 1, gdb_stdout
);
1101 printf_filtered (" in overlay section %s", section
->name
);
1103 printf_filtered (".\n");
1106 error ("No symbol \"%s\" in current context.", exp
);
1110 printf_filtered ("Symbol \"");
1111 fprintf_symbol_filtered (gdb_stdout
, SYMBOL_NAME (sym
),
1112 current_language
->la_language
, DMGL_ANSI
);
1113 printf_filtered ("\" is ");
1114 val
= SYMBOL_VALUE (sym
);
1115 basereg
= SYMBOL_BASEREG (sym
);
1116 section
= SYMBOL_BFD_SECTION (sym
);
1118 switch (SYMBOL_CLASS (sym
))
1121 case LOC_CONST_BYTES
:
1122 printf_filtered ("constant");
1126 printf_filtered ("a label at address ");
1127 print_address_numeric (load_addr
= SYMBOL_VALUE_ADDRESS (sym
),
1129 if (section_is_overlay (section
))
1131 load_addr
= overlay_unmapped_address (load_addr
, section
);
1132 printf_filtered (",\n -- loaded at ");
1133 print_address_numeric (load_addr
, 1, gdb_stdout
);
1134 printf_filtered (" in overlay section %s", section
->name
);
1139 printf_filtered ("a variable in register %s", REGISTER_NAME (val
));
1143 printf_filtered ("static storage at address ");
1144 print_address_numeric (load_addr
= SYMBOL_VALUE_ADDRESS (sym
),
1146 if (section_is_overlay (section
))
1148 load_addr
= overlay_unmapped_address (load_addr
, section
);
1149 printf_filtered (",\n -- loaded at ");
1150 print_address_numeric (load_addr
, 1, gdb_stdout
);
1151 printf_filtered (" in overlay section %s", section
->name
);
1156 printf_filtered ("external global (indirect addressing), at address *(");
1157 print_address_numeric (load_addr
= SYMBOL_VALUE_ADDRESS (sym
),
1159 printf_filtered (")");
1160 if (section_is_overlay (section
))
1162 load_addr
= overlay_unmapped_address (load_addr
, section
);
1163 printf_filtered (",\n -- loaded at ");
1164 print_address_numeric (load_addr
, 1, gdb_stdout
);
1165 printf_filtered (" in overlay section %s", section
->name
);
1170 printf_filtered ("an argument in register %s", REGISTER_NAME (val
));
1173 case LOC_REGPARM_ADDR
:
1174 printf_filtered ("address of an argument in register %s", REGISTER_NAME (val
));
1178 printf_filtered ("an argument at offset %ld", val
);
1182 printf_filtered ("an argument at frame offset %ld", val
);
1186 printf_filtered ("a local variable at frame offset %ld", val
);
1190 printf_filtered ("a reference argument at offset %ld", val
);
1194 printf_filtered ("a variable at offset %ld from register %s",
1195 val
, REGISTER_NAME (basereg
));
1198 case LOC_BASEREG_ARG
:
1199 printf_filtered ("an argument at offset %ld from register %s",
1200 val
, REGISTER_NAME (basereg
));
1204 printf_filtered ("a typedef");
1208 printf_filtered ("a function at address ");
1209 #ifdef GDB_TARGET_MASK_DISAS_PC
1210 print_address_numeric
1211 (load_addr
= GDB_TARGET_MASK_DISAS_PC (BLOCK_START (SYMBOL_BLOCK_VALUE (sym
))),
1214 print_address_numeric (load_addr
=BLOCK_START (SYMBOL_BLOCK_VALUE (sym
)),
1217 if (section_is_overlay (section
))
1219 load_addr
= overlay_unmapped_address (load_addr
, section
);
1220 printf_filtered (",\n -- loaded at ");
1221 print_address_numeric (load_addr
, 1, gdb_stdout
);
1222 printf_filtered (" in overlay section %s", section
->name
);
1226 case LOC_UNRESOLVED
:
1228 struct minimal_symbol
*msym
;
1230 msym
= lookup_minimal_symbol (SYMBOL_NAME (sym
), NULL
, NULL
);
1232 printf_filtered ("unresolved");
1235 section
= SYMBOL_BFD_SECTION (msym
);
1236 printf_filtered ("static storage at address ");
1237 print_address_numeric (load_addr
= SYMBOL_VALUE_ADDRESS (msym
),
1239 if (section_is_overlay (section
))
1241 load_addr
= overlay_unmapped_address (load_addr
, section
);
1242 printf_filtered (",\n -- loaded at ");
1243 print_address_numeric (load_addr
, 1, gdb_stdout
);
1244 printf_filtered (" in overlay section %s", section
->name
);
1250 case LOC_THREAD_LOCAL_STATIC
:
1252 "a thread-local variable at offset %ld from the thread base register %s",
1253 val
, REGISTER_NAME (basereg
));
1256 case LOC_OPTIMIZED_OUT
:
1257 printf_filtered ("optimized out");
1261 printf_filtered ("of unknown (botched) type");
1264 printf_filtered (".\n");
1268 x_command (exp
, from_tty
)
1272 struct expression
*expr
;
1273 struct format_data fmt
;
1274 struct cleanup
*old_chain
;
1277 fmt
.format
= last_format
;
1278 fmt
.size
= last_size
;
1281 if (exp
&& *exp
== '/')
1284 fmt
= decode_format (&exp
, last_format
, last_size
);
1287 /* If we have an expression, evaluate it and use it as the address. */
1289 if (exp
!= 0 && *exp
!= 0)
1291 expr
= parse_expression (exp
);
1292 /* Cause expression not to be there any more
1293 if this command is repeated with Newline.
1294 But don't clobber a user-defined command's definition. */
1297 old_chain
= make_cleanup ((make_cleanup_func
) free_current_contents
,
1299 val
= evaluate_expression (expr
);
1300 if (TYPE_CODE (VALUE_TYPE (val
)) == TYPE_CODE_REF
)
1301 val
= value_ind (val
);
1302 /* In rvalue contexts, such as this, functions are coerced into
1303 pointers to functions. This makes "x/i main" work. */
1304 if (/* last_format == 'i'
1305 && */ TYPE_CODE (VALUE_TYPE (val
)) == TYPE_CODE_FUNC
1306 && VALUE_LVAL (val
) == lval_memory
)
1307 next_address
= VALUE_ADDRESS (val
);
1309 next_address
= value_as_pointer (val
);
1310 if (VALUE_BFD_SECTION (val
))
1311 next_section
= VALUE_BFD_SECTION (val
);
1312 do_cleanups (old_chain
);
1315 do_examine (fmt
, next_address
, next_section
);
1317 /* If the examine succeeds, we remember its size and format for next time. */
1318 last_size
= fmt
.size
;
1319 last_format
= fmt
.format
;
1321 /* Set a couple of internal variables if appropriate. */
1322 if (last_examine_value
)
1324 /* Make last address examined available to the user as $_. Use
1325 the correct pointer type. */
1326 set_internalvar (lookup_internalvar ("_"),
1327 value_from_longest (
1328 lookup_pointer_type (VALUE_TYPE (last_examine_value
)),
1329 (LONGEST
) last_examine_address
));
1331 /* Make contents of last address examined available to the user as $__.*/
1332 /* If the last value has not been fetched from memory then don't
1333 fetch it now - instead mark it by voiding the $__ variable. */
1334 if (VALUE_LAZY (last_examine_value
))
1335 set_internalvar (lookup_internalvar ("__"),
1336 allocate_value (builtin_type_void
));
1338 set_internalvar (lookup_internalvar ("__"), last_examine_value
);
1343 /* Add an expression to the auto-display chain.
1344 Specify the expression. */
1347 display_command (exp
, from_tty
)
1351 struct format_data fmt
;
1352 register struct expression
*expr
;
1353 register struct display
*new;
1357 if (tui_version
&& *exp
== '$')
1358 display_it
= ((TuiStatus
)tuiDo(
1359 (TuiOpaqueFuncPtr
)tui_vSetLayoutTo
, exp
) == TUI_FAILURE
);
1373 fmt
= decode_format (&exp
, 0, 0);
1374 if (fmt
.size
&& fmt
.format
== 0)
1376 if (fmt
.format
== 'i' || fmt
.format
== 's')
1386 innermost_block
= 0;
1387 expr
= parse_expression (exp
);
1389 new = (struct display
*) xmalloc (sizeof (struct display
));
1392 new->block
= innermost_block
;
1393 new->next
= display_chain
;
1394 new->number
= ++display_number
;
1396 new->status
= enabled
;
1397 display_chain
= new;
1399 if (from_tty
&& target_has_execution
)
1400 do_one_display (new);
1414 /* Clear out the display_chain.
1415 Done when new symtabs are loaded, since this invalidates
1416 the types stored in many expressions. */
1421 register struct display
*d
;
1423 while ((d
= display_chain
) != NULL
)
1426 display_chain
= d
->next
;
1431 /* Delete the auto-display number NUM. */
1434 delete_display (num
)
1437 register struct display
*d1
, *d
;
1440 error ("No display number %d.", num
);
1442 if (display_chain
->number
== num
)
1445 display_chain
= d1
->next
;
1449 for (d
= display_chain
; ; d
= d
->next
)
1452 error ("No display number %d.", num
);
1453 if (d
->next
->number
== num
)
1463 /* Delete some values from the auto-display chain.
1464 Specify the element numbers. */
1467 undisplay_command (args
, from_tty
)
1471 register char *p
= args
;
1477 if (query ("Delete all auto-display expressions? "))
1486 while (*p1
>= '0' && *p1
<= '9') p1
++;
1487 if (*p1
&& *p1
!= ' ' && *p1
!= '\t')
1488 error ("Arguments must be display numbers.");
1492 delete_display (num
);
1495 while (*p
== ' ' || *p
== '\t') p
++;
1500 /* Display a single auto-display.
1501 Do nothing if the display cannot be printed in the current context,
1502 or if the display is disabled. */
1508 int within_current_scope
;
1510 if (d
->status
== disabled
)
1514 within_current_scope
= contained_in (get_selected_block (), d
->block
);
1516 within_current_scope
= 1;
1517 if (!within_current_scope
)
1520 current_display_number
= d
->number
;
1522 annotate_display_begin ();
1523 printf_filtered ("%d", d
->number
);
1524 annotate_display_number_end ();
1525 printf_filtered (": ");
1531 annotate_display_format ();
1533 printf_filtered ("x/");
1534 if (d
->format
.count
!= 1)
1535 printf_filtered ("%d", d
->format
.count
);
1536 printf_filtered ("%c", d
->format
.format
);
1537 if (d
->format
.format
!= 'i' && d
->format
.format
!= 's')
1538 printf_filtered ("%c", d
->format
.size
);
1539 printf_filtered (" ");
1541 annotate_display_expression ();
1543 print_expression (d
->exp
, gdb_stdout
);
1544 annotate_display_expression_end ();
1546 if (d
->format
.count
!= 1)
1547 printf_filtered ("\n");
1549 printf_filtered (" ");
1551 val
= evaluate_expression (d
->exp
);
1552 addr
= value_as_pointer (val
);
1553 if (d
->format
.format
== 'i')
1554 addr
= ADDR_BITS_REMOVE (addr
);
1556 annotate_display_value ();
1558 do_examine (d
->format
, addr
, VALUE_BFD_SECTION (val
));
1562 annotate_display_format ();
1564 if (d
->format
.format
)
1565 printf_filtered ("/%c ", d
->format
.format
);
1567 annotate_display_expression ();
1569 print_expression (d
->exp
, gdb_stdout
);
1570 annotate_display_expression_end ();
1572 printf_filtered (" = ");
1574 annotate_display_expression ();
1576 print_formatted (evaluate_expression (d
->exp
),
1577 d
->format
.format
, d
->format
.size
);
1578 printf_filtered ("\n");
1581 annotate_display_end ();
1583 gdb_flush (gdb_stdout
);
1584 current_display_number
= -1;
1587 /* Display all of the values on the auto-display chain which can be
1588 evaluated in the current scope. */
1593 register struct display
*d
;
1595 for (d
= display_chain
; d
; d
= d
->next
)
1599 /* Delete the auto-display which we were in the process of displaying.
1600 This is done when there is an error or a signal. */
1603 disable_display (num
)
1606 register struct display
*d
;
1608 for (d
= display_chain
; d
; d
= d
->next
)
1609 if (d
->number
== num
)
1611 d
->status
= disabled
;
1614 printf_unfiltered ("No display number %d.\n", num
);
1618 disable_current_display ()
1620 if (current_display_number
>= 0)
1622 disable_display (current_display_number
);
1623 fprintf_unfiltered (gdb_stderr
, "Disabling display %d to avoid infinite recursion.\n",
1624 current_display_number
);
1626 current_display_number
= -1;
1630 display_info (ignore
, from_tty
)
1634 register struct display
*d
;
1637 printf_unfiltered ("There are no auto-display expressions now.\n");
1639 printf_filtered ("Auto-display expressions now in effect:\n\
1640 Num Enb Expression\n");
1642 for (d
= display_chain
; d
; d
= d
->next
)
1644 printf_filtered ("%d: %c ", d
->number
, "ny"[(int)d
->status
]);
1646 printf_filtered ("/%d%c%c ", d
->format
.count
, d
->format
.size
,
1648 else if (d
->format
.format
)
1649 printf_filtered ("/%c ", d
->format
.format
);
1650 print_expression (d
->exp
, gdb_stdout
);
1651 if (d
->block
&& !contained_in (get_selected_block (), d
->block
))
1652 printf_filtered (" (cannot be evaluated in the current context)");
1653 printf_filtered ("\n");
1654 gdb_flush (gdb_stdout
);
1659 enable_display (args
, from_tty
)
1663 register char *p
= args
;
1666 register struct display
*d
;
1670 for (d
= display_chain
; d
; d
= d
->next
)
1671 d
->status
= enabled
;
1677 while (*p1
>= '0' && *p1
<= '9')
1679 if (*p1
&& *p1
!= ' ' && *p1
!= '\t')
1680 error ("Arguments must be display numbers.");
1684 for (d
= display_chain
; d
; d
= d
->next
)
1685 if (d
->number
== num
)
1687 d
->status
= enabled
;
1690 printf_unfiltered ("No display number %d.\n", num
);
1693 while (*p
== ' ' || *p
== '\t')
1700 disable_display_command (args
, from_tty
)
1704 register char *p
= args
;
1706 register struct display
*d
;
1710 for (d
= display_chain
; d
; d
= d
->next
)
1711 d
->status
= disabled
;
1717 while (*p1
>= '0' && *p1
<= '9')
1719 if (*p1
&& *p1
!= ' ' && *p1
!= '\t')
1720 error ("Arguments must be display numbers.");
1722 disable_display (atoi (p
));
1725 while (*p
== ' ' || *p
== '\t')
1731 /* Print the value in stack frame FRAME of a variable
1732 specified by a struct symbol. */
1735 print_variable_value (var
, frame
, stream
)
1737 struct frame_info
*frame
;
1740 value_ptr val
= read_var_value (var
, frame
);
1742 value_print (val
, stream
, 0, Val_pretty_default
);
1745 /* Print the arguments of a stack frame, given the function FUNC
1746 running in that frame (as a symbol), the info on the frame,
1747 and the number of args according to the stack frame (or -1 if unknown). */
1749 /* References here and elsewhere to "number of args according to the
1750 stack frame" appear in all cases to refer to "number of ints of args
1751 according to the stack frame". At least for VAX, i386, isi. */
1754 print_frame_args (func
, fi
, num
, stream
)
1755 struct symbol
*func
;
1756 struct frame_info
*fi
;
1760 struct block
*b
= NULL
;
1764 register struct symbol
*sym
;
1765 register value_ptr val
;
1766 /* Offset of next stack argument beyond the one we have seen that is
1767 at the highest offset.
1768 -1 if we haven't come to a stack argument yet. */
1769 long highest_offset
= -1;
1771 /* Number of ints of arguments that we have printed so far. */
1772 int args_printed
= 0;
1776 b
= SYMBOL_BLOCK_VALUE (func
);
1777 nsyms
= BLOCK_NSYMS (b
);
1780 for (i
= 0; i
< nsyms
; i
++)
1783 sym
= BLOCK_SYM (b
, i
);
1785 /* Keep track of the highest stack argument offset seen, and
1786 skip over any kinds of symbols we don't care about. */
1788 switch (SYMBOL_CLASS (sym
)) {
1792 long current_offset
= SYMBOL_VALUE (sym
);
1793 arg_size
= TYPE_LENGTH (SYMBOL_TYPE (sym
));
1795 /* Compute address of next argument by adding the size of
1796 this argument and rounding to an int boundary. */
1798 = ((current_offset
+ arg_size
+ sizeof (int) - 1)
1799 & ~(sizeof (int) - 1));
1801 /* If this is the highest offset seen yet, set highest_offset. */
1802 if (highest_offset
== -1
1803 || (current_offset
> highest_offset
))
1804 highest_offset
= current_offset
;
1806 /* Add the number of ints we're about to print to args_printed. */
1807 args_printed
+= (arg_size
+ sizeof (int) - 1) / sizeof (int);
1810 /* We care about types of symbols, but don't need to keep track of
1811 stack offsets in them. */
1813 case LOC_REGPARM_ADDR
:
1815 case LOC_BASEREG_ARG
:
1818 /* Other types of symbols we just skip over. */
1823 /* We have to look up the symbol because arguments can have
1824 two entries (one a parameter, one a local) and the one we
1825 want is the local, which lookup_symbol will find for us.
1826 This includes gcc1 (not gcc2) on the sparc when passing a
1827 small structure and gcc2 when the argument type is float
1828 and it is passed as a double and converted to float by
1829 the prologue (in the latter case the type of the LOC_ARG
1830 symbol is double and the type of the LOC_LOCAL symbol is
1832 /* But if the parameter name is null, don't try it.
1833 Null parameter names occur on the RS/6000, for traceback tables.
1834 FIXME, should we even print them? */
1836 if (*SYMBOL_NAME (sym
))
1838 struct symbol
*nsym
;
1839 nsym
= lookup_symbol
1841 b
, VAR_NAMESPACE
, (int *)NULL
, (struct symtab
**)NULL
);
1842 if (SYMBOL_CLASS (nsym
) == LOC_REGISTER
)
1844 /* There is a LOC_ARG/LOC_REGISTER pair. This means that
1845 it was passed on the stack and loaded into a register,
1846 or passed in a register and stored in a stack slot.
1847 GDB 3.x used the LOC_ARG; GDB 4.0-4.11 used the LOC_REGISTER.
1849 Reasons for using the LOC_ARG:
1850 (1) because find_saved_registers may be slow for remote
1852 (2) because registers are often re-used and stack slots
1853 rarely (never?) are. Therefore using the stack slot is
1854 much less likely to print garbage.
1856 Reasons why we might want to use the LOC_REGISTER:
1857 (1) So that the backtrace prints the same value as
1858 "print foo". I see no compelling reason why this needs
1859 to be the case; having the backtrace print the value which
1860 was passed in, and "print foo" print the value as modified
1861 within the called function, makes perfect sense to me.
1863 Additional note: It might be nice if "info args" displayed
1865 One more note: There is a case with sparc structure passing
1866 where we need to use the LOC_REGISTER, but this is dealt with
1867 by creating a single LOC_REGPARM in symbol reading. */
1869 /* Leave sym (the LOC_ARG) alone. */
1876 /* Print the current arg. */
1878 fprintf_filtered (stream
, ", ");
1881 annotate_arg_begin ();
1883 fprintf_symbol_filtered (stream
, SYMBOL_SOURCE_NAME (sym
),
1884 SYMBOL_LANGUAGE (sym
), DMGL_PARAMS
| DMGL_ANSI
);
1885 annotate_arg_name_end ();
1886 fputs_filtered ("=", stream
);
1888 /* Avoid value_print because it will deref ref parameters. We just
1889 want to print their addresses. Print ??? for args whose address
1890 we do not know. We pass 2 as "recurse" to val_print because our
1891 standard indentation here is 4 spaces, and val_print indents
1892 2 for each recurse. */
1893 val
= read_var_value (sym
, fi
);
1895 annotate_arg_value (val
== NULL
? NULL
: VALUE_TYPE (val
));
1899 if (GDB_TARGET_IS_D10V
1900 && SYMBOL_CLASS(sym
) == LOC_REGPARM
&& TYPE_CODE(VALUE_TYPE(val
)) == TYPE_CODE_PTR
)
1901 TYPE_LENGTH(VALUE_TYPE(val
)) = 2;
1902 val_print (VALUE_TYPE (val
), VALUE_CONTENTS (val
), 0,
1903 VALUE_ADDRESS (val
),
1904 stream
, 0, 0, 2, Val_no_prettyprint
);
1907 fputs_filtered ("???", stream
);
1909 annotate_arg_end ();
1914 /* Don't print nameless args in situations where we don't know
1915 enough about the stack to find them. */
1920 if (highest_offset
== -1)
1921 start
= FRAME_ARGS_SKIP
;
1923 start
= highest_offset
;
1925 print_frame_nameless_args (fi
, start
, num
- args_printed
,
1930 /* Print nameless args on STREAM.
1931 FI is the frameinfo for this frame, START is the offset
1932 of the first nameless arg, and NUM is the number of nameless args to
1933 print. FIRST is nonzero if this is the first argument (not just
1934 the first nameless arg). */
1937 print_frame_nameless_args (fi
, start
, num
, first
, stream
)
1938 struct frame_info
*fi
;
1948 for (i
= 0; i
< num
; i
++)
1951 #ifdef NAMELESS_ARG_VALUE
1952 NAMELESS_ARG_VALUE (fi
, start
, &arg_value
);
1954 argsaddr
= FRAME_ARGS_ADDRESS (fi
);
1958 arg_value
= read_memory_integer (argsaddr
+ start
, sizeof (int));
1962 fprintf_filtered (stream
, ", ");
1964 #ifdef PRINT_NAMELESS_INTEGER
1965 PRINT_NAMELESS_INTEGER (stream
, arg_value
);
1967 #ifdef PRINT_TYPELESS_INTEGER
1968 PRINT_TYPELESS_INTEGER (stream
, builtin_type_int
, (LONGEST
) arg_value
);
1970 fprintf_filtered (stream
, "%ld", arg_value
);
1971 #endif /* PRINT_TYPELESS_INTEGER */
1972 #endif /* PRINT_NAMELESS_INTEGER */
1974 start
+= sizeof (int);
1980 printf_command (arg
, from_tty
)
1984 register char *f
= NULL
;
1985 register char *s
= arg
;
1986 char *string
= NULL
;
1987 value_ptr
*val_args
;
1989 char *current_substring
;
1991 int allocated_args
= 20;
1992 struct cleanup
*old_cleanups
;
1994 val_args
= (value_ptr
*) xmalloc (allocated_args
* sizeof (value_ptr
));
1995 old_cleanups
= make_cleanup ((make_cleanup_func
) free_current_contents
,
1999 error_no_arg ("format-control string and values to print");
2001 /* Skip white space before format string */
2002 while (*s
== ' ' || *s
== '\t') s
++;
2004 /* A format string should follow, enveloped in double quotes */
2006 error ("Bad format string, missing '\"'.");
2008 /* Parse the format-control string and copy it into the string STRING,
2009 processing some kinds of escape sequence. */
2011 f
= string
= (char *) alloca (strlen (s
) + 1);
2019 error ("Bad format string, non-terminated '\"'.");
2031 *f
++ = '\007'; /* Bell */
2056 /* ??? TODO: handle other escape sequences */
2057 error ("Unrecognized escape character \\%c in format string.",
2067 /* Skip over " and following space and comma. */
2070 while (*s
== ' ' || *s
== '\t') s
++;
2072 if (*s
!= ',' && *s
!= 0)
2073 error ("Invalid argument syntax");
2076 while (*s
== ' ' || *s
== '\t') s
++;
2078 /* Need extra space for the '\0's. Doubling the size is sufficient. */
2079 substrings
= alloca (strlen (string
) * 2);
2080 current_substring
= substrings
;
2083 /* Now scan the string for %-specs and see what kinds of args they want.
2084 argclass[I] classifies the %-specs so we can give printf_filtered
2085 something of the right size. */
2087 enum argclass
{no_arg
, int_arg
, string_arg
, double_arg
, long_long_arg
};
2088 enum argclass
*argclass
;
2089 enum argclass this_argclass
;
2095 argclass
= (enum argclass
*) alloca (strlen (s
) * sizeof *argclass
);
2103 while (strchr ("0123456789.hlL-+ #", *f
))
2105 if (*f
== 'l' || *f
== 'L')
2112 this_argclass
= string_arg
;
2118 this_argclass
= double_arg
;
2122 error ("`*' not supported for precision or width in printf");
2125 error ("Format specifier `n' not supported in printf");
2128 this_argclass
= no_arg
;
2133 this_argclass
= long_long_arg
;
2135 this_argclass
= int_arg
;
2139 if (this_argclass
!= no_arg
)
2141 strncpy (current_substring
, last_arg
, f
- last_arg
);
2142 current_substring
+= f
- last_arg
;
2143 *current_substring
++ = '\0';
2145 argclass
[nargs_wanted
++] = this_argclass
;
2149 /* Now, parse all arguments and evaluate them.
2150 Store the VALUEs in VAL_ARGS. */
2155 if (nargs
== allocated_args
)
2156 val_args
= (value_ptr
*) xrealloc ((char *) val_args
,
2157 (allocated_args
*= 2)
2158 * sizeof (value_ptr
));
2160 val_args
[nargs
] = parse_to_comma_and_eval (&s1
);
2162 /* If format string wants a float, unchecked-convert the value to
2163 floating point of the same size */
2165 if (argclass
[nargs
] == double_arg
)
2167 struct type
*type
= VALUE_TYPE (val_args
[nargs
]);
2168 if (TYPE_LENGTH (type
) == sizeof (float))
2169 VALUE_TYPE (val_args
[nargs
]) = builtin_type_float
;
2170 if (TYPE_LENGTH (type
) == sizeof (double))
2171 VALUE_TYPE (val_args
[nargs
]) = builtin_type_double
;
2179 if (nargs
!= nargs_wanted
)
2180 error ("Wrong number of arguments for specified format-string");
2182 /* Now actually print them. */
2183 current_substring
= substrings
;
2184 for (i
= 0; i
< nargs
; i
++)
2186 switch (argclass
[i
])
2193 tem
= value_as_pointer (val_args
[i
]);
2195 /* This is a %s argument. Find the length of the string. */
2200 read_memory_section (tem
+ j
, &c
, 1,
2201 VALUE_BFD_SECTION (val_args
[i
]));
2206 /* Copy the string contents into a string inside GDB. */
2207 str
= (char *) alloca (j
+ 1);
2208 read_memory_section (tem
, str
, j
, VALUE_BFD_SECTION (val_args
[i
]));
2211 printf_filtered (current_substring
, str
);
2216 double val
= value_as_double (val_args
[i
]);
2217 printf_filtered (current_substring
, val
);
2221 #if defined (CC_HAS_LONG_LONG) && defined (PRINTF_HAS_LONG_LONG)
2223 long long val
= value_as_long (val_args
[i
]);
2224 printf_filtered (current_substring
, val
);
2228 error ("long long not supported in printf");
2232 /* FIXME: there should be separate int_arg and long_arg. */
2233 long val
= value_as_long (val_args
[i
]);
2234 printf_filtered (current_substring
, val
);
2237 default: /* purecov: deadcode */
2238 error ("internal error in printf_command"); /* purecov: deadcode */
2240 /* Skip to the next substring. */
2241 current_substring
+= strlen (current_substring
) + 1;
2243 /* Print the portion of the format string after the last argument. */
2244 printf_filtered (last_arg
);
2246 do_cleanups (old_cleanups
);
2249 /* Dump a specified section of assembly code. With no command line
2250 arguments, this command will dump the assembly code for the
2251 function surrounding the pc value in the selected frame. With one
2252 argument, it will dump the assembly code surrounding that pc value.
2253 Two arguments are interpeted as bounds within which to dump
2258 disassemble_command (arg
, from_tty
)
2262 CORE_ADDR low
, high
;
2264 CORE_ADDR pc
, pc_masked
;
2273 if (!selected_frame
)
2274 error ("No frame selected.\n");
2276 pc
= get_frame_pc (selected_frame
);
2277 if (find_pc_partial_function (pc
, &name
, &low
, &high
) == 0)
2278 error ("No function contains program counter for selected frame.\n");
2280 else if (tui_version
)
2281 low
= (CORE_ADDR
)tuiDo((TuiOpaqueFuncPtr
)tui_vGetLowDisassemblyAddress
,
2285 low
+= FUNCTION_START_OFFSET
;
2287 else if (!(space_index
= (char *) strchr (arg
, ' ')))
2290 pc
= parse_and_eval_address (arg
);
2291 if (find_pc_partial_function (pc
, &name
, &low
, &high
) == 0)
2292 error ("No function contains specified address.\n");
2294 else if (tui_version
)
2295 low
= (CORE_ADDR
)tuiDo((TuiOpaqueFuncPtr
)tui_vGetLowDisassemblyAddress
,
2300 if (overlay_debugging
)
2302 section
= find_pc_overlay (pc
);
2303 if (pc_in_unmapped_range (pc
, section
))
2305 /* find_pc_partial_function will have returned low and high
2306 relative to the symbolic (mapped) address range. Need to
2307 translate them back to the unmapped range where PC is. */
2308 low
= overlay_unmapped_address (low
, section
);
2309 high
= overlay_unmapped_address (high
, section
);
2313 low
+= FUNCTION_START_OFFSET
;
2317 /* Two arguments. */
2318 *space_index
= '\0';
2319 low
= parse_and_eval_address (arg
);
2320 high
= parse_and_eval_address (space_index
+ 1);
2325 m_winPtrIsNull(disassemWin
) || !disassemWin
->generic
.isVisible
)
2328 printf_filtered ("Dump of assembler code ");
2331 printf_filtered ("for function %s:\n", name
);
2335 printf_filtered ("from ");
2336 print_address_numeric (low
, 1, gdb_stdout
);
2337 printf_filtered (" to ");
2338 print_address_numeric (high
, 1, gdb_stdout
);
2339 printf_filtered (":\n");
2342 /* Dump the specified range. */
2345 #ifdef GDB_TARGET_MASK_DISAS_PC
2346 pc_masked
= GDB_TARGET_MASK_DISAS_PC (pc
);
2351 while (pc_masked
< high
)
2354 print_address (pc_masked
, gdb_stdout
);
2355 printf_filtered (":\t");
2356 /* We often wrap here if there are long symbolic names. */
2358 pc
+= print_insn (pc
, gdb_stdout
);
2359 printf_filtered ("\n");
2361 #ifdef GDB_TARGET_MASK_DISAS_PC
2362 pc_masked
= GDB_TARGET_MASK_DISAS_PC (pc
);
2367 printf_filtered ("End of assembler dump.\n");
2368 gdb_flush (gdb_stdout
);
2373 tuiDo((TuiOpaqueFuncPtr
)tui_vAddWinToLayout
, DISASSEM_WIN
);
2374 tuiDo((TuiOpaqueFuncPtr
)tui_vUpdateSourceWindowsWithAddr
, low
);
2379 /* Print the instruction at address MEMADDR in debugged memory,
2380 on STREAM. Returns length of the instruction, in bytes. */
2383 print_insn (memaddr
, stream
)
2387 if (TARGET_BYTE_ORDER
== BIG_ENDIAN
)
2388 TARGET_PRINT_INSN_INFO
->endian
= BFD_ENDIAN_BIG
;
2390 TARGET_PRINT_INSN_INFO
->endian
= BFD_ENDIAN_LITTLE
;
2392 if (TARGET_ARCHITECTURE
!= NULL
)
2393 TARGET_PRINT_INSN_INFO
->mach
= TARGET_ARCHITECTURE
->mach
;
2394 /* else: should set .mach=0 but some disassemblers don't grok this */
2396 return TARGET_PRINT_INSN (memaddr
, TARGET_PRINT_INSN_INFO
);
2401 _initialize_printcmd ()
2403 current_display_number
= -1;
2405 add_info ("address", address_info
,
2406 "Describe where symbol SYM is stored.");
2408 add_info ("symbol", sym_info
,
2409 "Describe what symbol is at location ADDR.\n\
2410 Only for symbols with fixed locations (global or static scope).");
2412 add_com ("x", class_vars
, x_command
,
2413 concat ("Examine memory: x/FMT ADDRESS.\n\
2414 ADDRESS is an expression for the memory address to examine.\n\
2415 FMT is a repeat count followed by a format letter and a size letter.\n\
2416 Format letters are o(octal), x(hex), d(decimal), u(unsigned decimal),\n\
2417 t(binary), f(float), a(address), i(instruction), c(char) and s(string).\n",
2418 "Size letters are b(byte), h(halfword), w(word), g(giant, 8 bytes).\n\
2419 The specified number of objects of the specified size are printed\n\
2420 according to the format.\n\n\
2421 Defaults for format and size letters are those previously used.\n\
2422 Default count is 1. Default address is following last thing printed\n\
2423 with this command or \"print\".", NULL
));
2425 add_com ("disassemble", class_vars
, disassemble_command
,
2426 "Disassemble a specified section of memory.\n\
2427 Default is the function surrounding the pc of the selected frame.\n\
2428 With a single argument, the function surrounding that address is dumped.\n\
2429 Two arguments are taken as a range of memory to dump.");
2431 add_com_alias ("va", "disassemble", class_xdb
, 0);
2434 add_com ("whereis", class_vars
, whereis_command
,
2435 "Print line number and file of definition of variable.");
2438 add_info ("display", display_info
,
2439 "Expressions to display when program stops, with code numbers.");
2441 add_cmd ("undisplay", class_vars
, undisplay_command
,
2442 "Cancel some expressions to be displayed when program stops.\n\
2443 Arguments are the code numbers of the expressions to stop displaying.\n\
2444 No argument means cancel all automatic-display expressions.\n\
2445 \"delete display\" has the same effect as this command.\n\
2446 Do \"info display\" to see current list of code numbers.",
2449 add_com ("display", class_vars
, display_command
,
2450 "Print value of expression EXP each time the program stops.\n\
2451 /FMT may be used before EXP as in the \"print\" command.\n\
2452 /FMT \"i\" or \"s\" or including a size-letter is allowed,\n\
2453 as in the \"x\" command, and then EXP is used to get the address to examine\n\
2454 and examining is done as in the \"x\" command.\n\n\
2455 With no argument, display all currently requested auto-display expressions.\n\
2456 Use \"undisplay\" to cancel display requests previously made."
2459 add_cmd ("display", class_vars
, enable_display
,
2460 "Enable some expressions to be displayed when program stops.\n\
2461 Arguments are the code numbers of the expressions to resume displaying.\n\
2462 No argument means enable all automatic-display expressions.\n\
2463 Do \"info display\" to see current list of code numbers.", &enablelist
);
2465 add_cmd ("display", class_vars
, disable_display_command
,
2466 "Disable some expressions to be displayed when program stops.\n\
2467 Arguments are the code numbers of the expressions to stop displaying.\n\
2468 No argument means disable all automatic-display expressions.\n\
2469 Do \"info display\" to see current list of code numbers.", &disablelist
);
2471 add_cmd ("display", class_vars
, undisplay_command
,
2472 "Cancel some expressions to be displayed when program stops.\n\
2473 Arguments are the code numbers of the expressions to stop displaying.\n\
2474 No argument means cancel all automatic-display expressions.\n\
2475 Do \"info display\" to see current list of code numbers.", &deletelist
);
2477 add_com ("printf", class_vars
, printf_command
,
2478 "printf \"printf format string\", arg1, arg2, arg3, ..., argn\n\
2479 This is useful for formatted output in user-defined commands.");
2481 add_com ("output", class_vars
, output_command
,
2482 "Like \"print\" but don't put in value history and don't print newline.\n\
2483 This is useful in user-defined commands.");
2485 add_prefix_cmd ("set", class_vars
, set_command
,
2486 concat ("Evaluate expression EXP and assign result to variable VAR, using assignment\n\
2487 syntax appropriate for the current language (VAR = EXP or VAR := EXP for\n\
2488 example). VAR may be a debugger \"convenience\" variable (names starting\n\
2489 with $), a register (a few standard names starting with $), or an actual\n\
2490 variable in the program being debugged. EXP is any valid expression.\n",
2491 "Use \"set variable\" for variables with names identical to set subcommands.\n\
2492 \nWith a subcommand, this command modifies parts of the gdb environment.\n\
2493 You can see these environment settings with the \"show\" command.", NULL
),
2494 &setlist
, "set ", 1, &cmdlist
);
2496 add_com("assign", class_vars
, set_command
, concat ("Evaluate expression \
2497 EXP and assign result to variable VAR, using assignment\n\
2498 syntax appropriate for the current language (VAR = EXP or VAR := EXP for\n\
2499 example). VAR may be a debugger \"convenience\" variable (names starting\n\
2500 with $), a register (a few standard names starting with $), or an actual\n\
2501 variable in the program being debugged. EXP is any valid expression.\n",
2502 "Use \"set variable\" for variables with names identical to set subcommands.\n\
2503 \nWith a subcommand, this command modifies parts of the gdb environment.\n\
2504 You can see these environment settings with the \"show\" command.", NULL
));
2506 /* "call" is the same as "set", but handy for dbx users to call fns. */
2507 add_com ("call", class_vars
, call_command
,
2508 "Call a function in the program.\n\
2509 The argument is the function name and arguments, in the notation of the\n\
2510 current working language. The result is printed and saved in the value\n\
2511 history, if it is not void.");
2513 add_cmd ("variable", class_vars
, set_command
,
2514 "Evaluate expression EXP and assign result to variable VAR, using assignment\n\
2515 syntax appropriate for the current language (VAR = EXP or VAR := EXP for\n\
2516 example). VAR may be a debugger \"convenience\" variable (names starting\n\
2517 with $), a register (a few standard names starting with $), or an actual\n\
2518 variable in the program being debugged. EXP is any valid expression.\n\
2519 This may usually be abbreviated to simply \"set\".",
2522 add_com ("print", class_vars
, print_command
,
2523 concat ("Print value of expression EXP.\n\
2524 Variables accessible are those of the lexical environment of the selected\n\
2525 stack frame, plus all those whose scope is global or an entire file.\n\
2527 $NUM gets previous value number NUM. $ and $$ are the last two values.\n\
2528 $$NUM refers to NUM'th value back from the last one.\n\
2529 Names starting with $ refer to registers (with the values they would have\n",
2530 "if the program were to return to the stack frame now selected, restoring\n\
2531 all registers saved by frames farther in) or else to debugger\n\
2532 \"convenience\" variables (any such name not a known register).\n\
2533 Use assignment expressions to give values to convenience variables.\n",
2535 {TYPE}ADREXP refers to a datum of data type TYPE, located at address ADREXP.\n\
2536 @ is a binary operator for treating consecutive data objects\n\
2537 anywhere in memory as an array. FOO@NUM gives an array whose first\n\
2538 element is FOO, whose second element is stored in the space following\n\
2539 where FOO is stored, etc. FOO must be an expression whose value\n\
2540 resides in memory.\n",
2542 EXP may be preceded with /FMT, where FMT is a format letter\n\
2543 but no count or size letter (see \"x\" command).", NULL
));
2544 add_com_alias ("p", "print", class_vars
, 1);
2546 add_com ("inspect", class_vars
, inspect_command
,
2547 "Same as \"print\" command, except that if you are running in the epoch\n\
2548 environment, the value is printed in its own window.");
2551 add_set_cmd ("max-symbolic-offset", no_class
, var_uinteger
,
2552 (char *)&max_symbolic_offset
,
2553 "Set the largest offset that will be printed in <symbol+1234> form.",
2557 add_set_cmd ("symbol-filename", no_class
, var_boolean
,
2558 (char *)&print_symbol_filename
,
2559 "Set printing of source filename and line number with <symbol>.",
2563 /* For examine/instruction a single byte quantity is specified as
2564 the data. This avoids problems with value_at_lazy() requiring a
2565 valid data type (and rejecting VOID). */
2566 examine_i_type
= init_type (TYPE_CODE_INT
, 1, 0, "examine_i_type", NULL
);
2568 examine_b_type
= init_type (TYPE_CODE_INT
, 1, 0, "examine_b_type", NULL
);
2569 examine_h_type
= init_type (TYPE_CODE_INT
, 2, 0, "examine_h_type", NULL
);
2570 examine_w_type
= init_type (TYPE_CODE_INT
, 4, 0, "examine_w_type", NULL
);
2571 examine_g_type
= init_type (TYPE_CODE_INT
, 8, 0, "examine_g_type", NULL
);