import gdb-1999-07-07 post reformat
[deliverable/binutils-gdb.git] / gdb / printcmd.c
CommitLineData
c906108c
SS
1/* Print values for GNU debugger GDB.
2 Copyright 1986, 87, 88, 89, 90, 91, 93, 94, 95, 1998
3 Free Software Foundation, Inc.
4
5This file is part of GDB.
6
7This program is free software; you can redistribute it and/or modify
8it under the terms of the GNU General Public License as published by
9the Free Software Foundation; either version 2 of the License, or
10(at your option) any later version.
11
12This program is distributed in the hope that it will be useful,
13but WITHOUT ANY WARRANTY; without even the implied warranty of
14MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15GNU General Public License for more details.
16
17You should have received a copy of the GNU General Public License
18along with this program; if not, write to the Free Software
19Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
20
21#include "defs.h"
22#include "gdb_string.h"
23#include "frame.h"
24#include "symtab.h"
25#include "gdbtypes.h"
26#include "value.h"
27#include "language.h"
28#include "expression.h"
29#include "gdbcore.h"
30#include "gdbcmd.h"
31#include "target.h"
32#include "breakpoint.h"
33#include "demangle.h"
34#include "valprint.h"
35#include "annotate.h"
36#include "symfile.h" /* for overlay functions */
37#include "objfiles.h" /* ditto */
38
39extern int asm_demangle; /* Whether to demangle syms in asm printouts */
40extern int addressprint; /* Whether to print hex addresses in HLL " */
41
42struct format_data
43{
44 int count;
45 char format;
46 char size;
47};
48
49/* Last specified output format. */
50
51static char last_format = 'x';
52
53/* Last specified examination size. 'b', 'h', 'w' or `q'. */
54
55static char last_size = 'w';
56
57/* Default address to examine next. */
58
59static CORE_ADDR next_address;
60
61/* Default section to examine next. */
62
63static asection *next_section;
64
65/* Last address examined. */
66
67static CORE_ADDR last_examine_address;
68
69/* Contents of last address examined.
70 This is not valid past the end of the `x' command! */
71
72static value_ptr last_examine_value;
73
74/* Largest offset between a symbolic value and an address, that will be
75 printed as `0x1234 <symbol+offset>'. */
76
77static unsigned int max_symbolic_offset = UINT_MAX;
78
79/* Append the source filename and linenumber of the symbol when
80 printing a symbolic value as `<symbol at filename:linenum>' if set. */
81static int print_symbol_filename = 0;
82
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. */
86
87int current_display_number;
88
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. */
93
94int inspect_it = 0;
95
96struct display
97{
98 /* Chain link to next auto-display item. */
99 struct display *next;
100 /* Expression to be evaluated and displayed. */
101 struct expression *exp;
102 /* Item number of this auto-display item. */
103 int number;
104 /* Display format specified. */
105 struct format_data format;
106 /* Innermost block required by this expression when evaluated */
107 struct block *block;
108 /* Status of this display (enabled or disabled) */
109 enum enable status;
110};
111
112/* Chain of expressions whose values should be displayed
113 automatically each time the program stops. */
114
115static struct display *display_chain;
116
117static int display_number;
118
119/* Prototypes for exported functions. */
120
121void output_command PARAMS ((char *, int));
122
123void _initialize_printcmd PARAMS ((void));
124
125/* Prototypes for local functions. */
126
127static void delete_display PARAMS ((int));
128
129static void enable_display PARAMS ((char *, int));
130
131static void disable_display_command PARAMS ((char *, int));
132
133static void disassemble_command PARAMS ((char *, int));
134
135static void printf_command PARAMS ((char *, int));
136
137static void print_frame_nameless_args PARAMS ((struct frame_info *, long,
138 int, int, GDB_FILE *));
139
140static void display_info PARAMS ((char *, int));
141
142static void do_one_display PARAMS ((struct display *));
143
144static void undisplay_command PARAMS ((char *, int));
145
146static void free_display PARAMS ((struct display *));
147
148static void display_command PARAMS ((char *, int));
149
150void x_command PARAMS ((char *, int));
151
152static void address_info PARAMS ((char *, int));
153
154static void set_command PARAMS ((char *, int));
155
156static void call_command PARAMS ((char *, int));
157
158static void inspect_command PARAMS ((char *, int));
159
160static void print_command PARAMS ((char *, int));
161
162static void print_command_1 PARAMS ((char *, int, int));
163
164static void validate_format PARAMS ((struct format_data, char *));
165
166static void do_examine PARAMS ((struct format_data, CORE_ADDR addr, asection *section));
167
168static void print_formatted PARAMS ((value_ptr, int, int));
169
170static struct format_data decode_format PARAMS ((char **, int, int));
171
172static int print_insn PARAMS ((CORE_ADDR, GDB_FILE *));
173
174static void sym_info PARAMS ((char *, int));
175
176\f
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
182 user.
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. */
186
187static struct format_data
188decode_format (string_ptr, oformat, osize)
189 char **string_ptr;
190 int oformat;
191 int osize;
192{
193 struct format_data val;
194 register char *p = *string_ptr;
195
196 val.format = '?';
197 val.size = '?';
198 val.count = 1;
199
200 if (*p >= '0' && *p <= '9')
201 val.count = atoi (p);
202 while (*p >= '0' && *p <= '9') p++;
203
204 /* Now process size or format letters that follow. */
205
206 while (1)
207 {
208 if (*p == 'b' || *p == 'h' || *p == 'w' || *p == 'g')
209 val.size = *p++;
210 else if (*p >= 'a' && *p <= 'z')
211 val.format = *p++;
212 else
213 break;
214 }
215
216 while (*p == ' ' || *p == '\t') p++;
217 *string_ptr = p;
218
219 /* Set defaults for format and size if not specified. */
220 if (val.format == '?')
221 {
222 if (val.size == '?')
223 {
224 /* Neither has been specified. */
225 val.format = oformat;
226 val.size = osize;
227 }
228 else
229 /* If a size is specified, any format makes a reasonable
230 default except 'i'. */
231 val.format = oformat == 'i' ? 'x' : oformat;
232 }
233 else if (val.size == '?')
234 switch (val.format)
235 {
236 case 'a':
237 case 's':
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;
245 else
246 /* Bad value for TARGET_PTR_BIT */
247 abort ();
248 break;
249 case 'f':
250 /* Floating point has to be word or giantword. */
251 if (osize == 'w' || osize == 'g')
252 val.size = osize;
253 else
254 /* Default it to giantword if the last used size is not
255 appropriate. */
256 val.size = osize ? 'g' : osize;
257 break;
258 case 'c':
259 /* Characters default to one byte. */
260 val.size = osize ? 'b' : osize;
261 break;
262 default:
263 /* The default is the size most recently specified. */
264 val.size = osize;
265 }
266
267 return val;
268}
269\f
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. */
275
276static void
277print_formatted (val, format, size)
278 register value_ptr val;
279 register int format;
280 int size;
281{
282 struct type *type = check_typedef (VALUE_TYPE (val));
283 int len = TYPE_LENGTH (type);
284
285 if (VALUE_LVAL (val) == lval_memory)
286 {
287 next_address = VALUE_ADDRESS (val) + len;
288 next_section = VALUE_BFD_SECTION (val);
289 }
290
291 switch (format)
292 {
293 case 's':
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);
298 break;
299
300 case 'i':
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 */
306
307 /* We often wrap here if there are long symbolic names. */
308 wrap_here (" ");
309 next_address = VALUE_ADDRESS (val)
310 + print_insn (VALUE_ADDRESS (val), gdb_stdout);
311 next_section = VALUE_BFD_SECTION (val);
312 break;
313
314 default:
315 if (format == 0
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.
324 */
325 value_print (val, gdb_stdout, format, Val_pretty_default);
326 else
327 /* User specified format, so don't look to the
328 * the type to tell us what to do.
329 */
330 print_scalar_formatted (VALUE_CONTENTS (val), type,
331 format, size, gdb_stdout);
332 }
333}
334
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.
338
339 This is how the elements of an array or structure are printed
340 with a format. */
341
342void
343print_scalar_formatted (valaddr, type, format, size, stream)
344 char *valaddr;
345 struct type *type;
346 int format;
347 int size;
348 GDB_FILE *stream;
349{
350 LONGEST val_long;
351 unsigned int len = TYPE_LENGTH (type);
352
353 if (len > sizeof (LONGEST)
354 && (format == 't'
355 || format == 'c'
356 || format == 'o'
357 || format == 'u'
358 || format == 'd'
359 || format == 'x'))
360 {
361 if (! TYPE_UNSIGNED (type)
362 || ! extract_long_unsigned_integer (valaddr, len, &val_long))
363 {
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
368 desired format. */
369 /* FIXME: we should be using the size field to give us a
370 minimum field width to print. */
371
372 if( format == 'o' )
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);
378 else
379
380 /* replace with call to print_hex_chars? Looks
381 like val_print_type_code_int is redoing
382 work. - edie */
383
384 val_print_type_code_int (type, valaddr, stream);
385
386 return;
387 }
388
389 /* If we get here, extract_long_unsigned_integer set val_long. */
390 }
391 else if (format != 'f')
392 val_long = unpack_long (type, valaddr);
393
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). */
397 if (format != 'd')
398 {
399 if (len < sizeof (LONGEST))
400 val_long &= ((LONGEST) 1 << HOST_CHAR_BIT * len) - 1;
401 }
402
403 switch (format)
404 {
405 case 'x':
406 if (!size)
407 {
408 /* no size specified, like in print. Print varying # of digits. */
409 print_longest (stream, 'x', 1, val_long);
410 }
411 else
412 switch (size)
413 {
414 case 'b':
415 case 'h':
416 case 'w':
417 case 'g':
418 print_longest (stream, size, 1, val_long);
419 break;
420 default:
421 error ("Undefined output size \"%c\".", size);
422 }
423 break;
424
425 case 'd':
426 print_longest (stream, 'd', 1, val_long);
427 break;
428
429 case 'u':
430 print_longest (stream, 'u', 0, val_long);
431 break;
432
433 case 'o':
434 if (val_long)
435 print_longest (stream, 'o', 1, val_long);
436 else
437 fprintf_filtered (stream, "0");
438 break;
439
440 case 'a':
441 print_address (unpack_pointer (type, valaddr), stream);
442 break;
443
444 case 'c':
9e0b60a8
JM
445 value_print (value_from_longest (builtin_type_true_char, val_long),
446 stream, 0, Val_pretty_default);
c906108c
SS
447 break;
448
449 case 'f':
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);
455 break;
456
457 case 0:
458 abort ();
459
460 case 't':
461 /* Binary; 't' stands for "two". */
462 {
463 char bits[8*(sizeof val_long) + 1];
464 char buf[8*(sizeof val_long) + 32];
465 char *cp = bits;
466 int width;
467
468 if (!size)
469 width = 8*(sizeof val_long);
470 else
471 switch (size)
472 {
473 case 'b':
474 width = 8;
475 break;
476 case 'h':
477 width = 16;
478 break;
479 case 'w':
480 width = 32;
481 break;
482 case 'g':
483 width = 64;
484 break;
485 default:
486 error ("Undefined output size \"%c\".", size);
487 }
488
489 bits[width] = '\0';
490 while (width-- > 0)
491 {
492 bits[width] = (val_long & 1) ? '1' : '0';
493 val_long >>= 1;
494 }
495 if (!size)
496 {
497 while (*cp && *cp == '0')
498 cp++;
499 if (*cp == '\0')
500 cp--;
501 }
502 strcpy (buf, local_binary_format_prefix());
503 strcat (buf, cp);
504 strcat (buf, local_binary_format_suffix());
505 fprintf_filtered (stream, buf);
506 }
507 break;
508
509 default:
510 error ("Undefined output format \"%c\".", format);
511 }
512}
513
514/* Specify default address for `x' command.
515 `info lines' uses this. */
516
517void
518set_next_address (addr)
519 CORE_ADDR addr;
520{
521 next_address = addr;
522
523 /* Make address available to the user as $_. */
524 set_internalvar (lookup_internalvar ("_"),
525 value_from_longest (lookup_pointer_type (builtin_type_void),
526 (LONGEST) addr));
527}
528
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. */
536
537void
538print_address_symbolic (addr, stream, do_demangle, leadin)
539 CORE_ADDR addr;
540 GDB_FILE *stream;
541 int do_demangle;
542 char *leadin;
543{
544 struct minimal_symbol *msymbol;
545 struct symbol *symbol;
546 struct symtab *symtab = 0;
547 CORE_ADDR name_location = 0;
548 char *name = "";
549 asection *section = 0;
550 int unmapped = 0;
551
552 /* Determine if the address is in an overlay, and whether it is mapped. */
553 if (overlay_debugging)
554 {
555 section = find_pc_overlay (addr);
556 if (pc_in_unmapped_range (addr, section))
557 {
558 unmapped = 1;
559 addr = overlay_mapped_address (addr, section);
560 }
561 }
562
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. */
567
568#ifdef GDB_TARGET_UNMASK_DISAS_PC
569 addr = GDB_TARGET_UNMASK_DISAS_PC (addr);
570#endif
571
572 /* First try to find the address in the symbol table, then
573 in the minsyms. Take the closest one. */
574
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
580 symbols anyway). */
581 msymbol = lookup_minimal_symbol_by_pc_section (addr, section);
582 symbol = find_pc_sect_function (addr, section);
583
584 if (symbol)
585 {
586 name_location = BLOCK_START (SYMBOL_BLOCK_VALUE (symbol));
587 if (do_demangle)
588 name = SYMBOL_SOURCE_NAME (symbol);
589 else
590 name = SYMBOL_LINKAGE_NAME (symbol);
591 }
592
593 if (msymbol != NULL)
594 {
595 if (SYMBOL_VALUE_ADDRESS (msymbol) > name_location || symbol == NULL)
596 {
597 /* The msymbol is closer to the address than the symbol;
598 use the msymbol instead. */
599 symbol = 0;
600 symtab = 0;
601 name_location = SYMBOL_VALUE_ADDRESS (msymbol);
602 if (do_demangle)
603 name = SYMBOL_SOURCE_NAME (msymbol);
604 else
605 name = SYMBOL_LINKAGE_NAME (msymbol);
606 }
607 }
608 if (symbol == NULL && msymbol == NULL)
609 return;
610
611 /* On some targets, mask out extra "flag" bits from PC for handsome
612 disassembly. */
613
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);
617#endif
618
619 /* If the nearest symbol is too far away, don't print anything symbolic. */
620
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)
628 return;
629
630 fputs_filtered (leadin, stream);
631 if (unmapped)
632 fputs_filtered ("<*", stream);
633 else
634 fputs_filtered ("<", stream);
635 fputs_filtered (name, stream);
636 if (addr != name_location)
637 fprintf_filtered (stream, "+%u", (unsigned int)(addr - name_location));
638
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)
642 {
643 struct symtab_and_line sal;
644
645 sal = find_pc_sect_line (addr, section, 0);
646
647 if (sal.symtab)
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);
651 else if (symtab)
652 fprintf_filtered (stream, " in %s", symtab->filename);
653 }
654 if (unmapped)
655 fputs_filtered ("*>", stream);
656 else
657 fputs_filtered (">", stream);
658}
659
660
661/* Print address ADDR on STREAM. USE_LOCAL means the same thing as for
662 print_longest. */
663void
664print_address_numeric (addr, use_local, stream)
665 CORE_ADDR addr;
666 int use_local;
667 GDB_FILE *stream;
668{
669 /* This assumes a CORE_ADDR can fit in a LONGEST. Probably a safe
670 assumption. */
671 print_longest (stream, 'x', use_local, (ULONGEST) addr);
672}
673
674/* Print address ADDR symbolically on STREAM.
675 First print it as a number. Then perhaps print
676 <SYMBOL + OFFSET> after the number. */
677
678void
679print_address (addr, stream)
680 CORE_ADDR addr;
681 GDB_FILE *stream;
682{
683 print_address_numeric (addr, 1, stream);
684 print_address_symbolic (addr, stream, asm_demangle, " ");
685}
686
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
690 or not. */
691
692void
693print_address_demangle (addr, stream, do_demangle)
694 CORE_ADDR addr;
695 GDB_FILE *stream;
696 int do_demangle;
697{
698 if (addr == 0)
699 {
700 fprintf_filtered (stream, "0");
701 }
702 else if (addressprint)
703 {
704 print_address_numeric (addr, 1, stream);
705 print_address_symbolic (addr, stream, do_demangle, " ");
706 }
707 else
708 {
709 print_address_symbolic (addr, stream, do_demangle, "");
710 }
711}
712\f
713
714/* These are the types that $__ will get after an examine command of one
715 of these sizes. */
716
717static struct type *examine_i_type;
718
719static struct type *examine_b_type;
720static struct type *examine_h_type;
721static struct type *examine_w_type;
722static struct type *examine_g_type;
723
724/* Examine data at address ADDR in format FMT.
725 Fetch it from memory and print on gdb_stdout. */
726
727static void
728do_examine (fmt, addr, sect)
729 struct format_data fmt;
730 CORE_ADDR addr;
731 asection *sect;
732{
733 register char format = 0;
734 register char size;
735 register int count = 1;
736 struct type *val_type = NULL;
737 register int i;
738 register int maxelts;
739
740 format = fmt.format;
741 size = fmt.size;
742 count = fmt.count;
743 next_address = addr;
744 next_section = sect;
745
746 /* String or instruction format implies fetch single bytes
747 regardless of the specified size. */
748 if (format == 's' || format == 'i')
749 size = 'b';
750
751 if (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;
761
762 maxelts = 8;
763 if (size == 'w')
764 maxelts = 4;
765 if (size == 'g')
766 maxelts = 2;
767 if (format == 's' || format == 'i')
768 maxelts = 1;
769
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. */
772
773 while (count > 0)
774 {
775 QUIT;
776 print_address (next_address, gdb_stdout);
777 printf_filtered (":");
778 for (i = maxelts;
779 i > 0 && count > 0;
780 i--, count--)
781 {
782 printf_filtered ("\t");
783 /* Note that print_formatted sets next_address for the next
784 object. */
785 last_examine_address = next_address;
786
787 if (last_examine_value)
788 value_free (last_examine_value);
789
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);
800
801 if (last_examine_value)
802 release_value (last_examine_value);
803
804 print_formatted (last_examine_value, format, size);
805 }
806 printf_filtered ("\n");
807 gdb_flush (gdb_stdout);
808 }
809}
810\f
811static void
812validate_format (fmt, cmdname)
813 struct format_data fmt;
814 char *cmdname;
815{
816 if (fmt.size != 0)
817 error ("Size letters are meaningless in \"%s\" command.", cmdname);
818 if (fmt.count != 1)
819 error ("Item count other than 1 is meaningless in \"%s\" command.",
820 cmdname);
821 if (fmt.format == 'i' || fmt.format == 's')
822 error ("Format letter \"%c\" is meaningless in \"%s\" command.",
823 fmt.format, cmdname);
824}
825
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).
829 */
830
831static void
832print_command_1 (exp, inspect, voidprint)
833 char *exp;
834 int inspect;
835 int voidprint;
836{
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;
842 int cleanup = 0;
843
844 /* Pass inspect flag to the rest of the print routines in a global (sigh). */
845 inspect_it = inspect;
846
847 if (exp && *exp == '/')
848 {
849 exp++;
850 fmt = decode_format (&exp, last_format, 0);
851 validate_format (fmt, "print");
852 last_format = format = fmt.format;
853 }
854 else
855 {
856 fmt.count = 1;
857 fmt.format = 0;
858 fmt.size = 0;
859 }
860
861 if (exp && *exp)
862 {
c906108c
SS
863 struct type *type;
864 expr = parse_expression (exp);
865 old_chain = make_cleanup ((make_cleanup_func) free_current_contents,
866 &expr);
867 cleanup = 1;
868 val = evaluate_expression (expr);
869
870 /* C++: figure out what type we actually want to print it as. */
871 type = VALUE_TYPE (val);
872
873 if (objectprint
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))
878 {
879 value_ptr v;
880
881 v = value_from_vtable_info (val, TYPE_TARGET_TYPE (type));
882 if (v != 0)
883 {
884 val = v;
885 type = VALUE_TYPE (val);
886 }
887 }
888 }
889 else
890 val = access_value_history (0);
891
892 if (voidprint || (val && VALUE_TYPE (val) &&
893 TYPE_CODE (VALUE_TYPE (val)) != TYPE_CODE_VOID))
894 {
895 int histindex = record_latest_value (val);
896
897 if (histindex >= 0)
898 annotate_value_history_begin (histindex, VALUE_TYPE (val));
899 else
900 annotate_value_begin (VALUE_TYPE (val));
901
902 if (inspect)
903 printf_unfiltered ("\031(gdb-makebuffer \"%s\" %d '(\"", exp, histindex);
904 else
905 if (histindex >= 0) printf_filtered ("$%d = ", histindex);
906
907 if (histindex >= 0)
908 annotate_value_history_value ();
909
910 print_formatted (val, format, fmt.size);
911 printf_filtered ("\n");
912
913 if (histindex >= 0)
914 annotate_value_history_end ();
915 else
916 annotate_value_end ();
917
918 if (inspect)
919 printf_unfiltered("\") )\030");
920 }
921
922 if (cleanup)
923 do_cleanups (old_chain);
924 inspect_it = 0; /* Reset print routines to normal */
925}
926
927/* ARGSUSED */
928static void
929print_command (exp, from_tty)
930 char *exp;
931 int from_tty;
932{
933 print_command_1 (exp, 0, 1);
934}
935
936/* Same as print, except in epoch, it gets its own window */
937/* ARGSUSED */
938static void
939inspect_command (exp, from_tty)
940 char *exp;
941 int from_tty;
942{
943 extern int epoch_interface;
944
945 print_command_1 (exp, epoch_interface, 1);
946}
947
948/* Same as print, except it doesn't print void results. */
949/* ARGSUSED */
950static void
951call_command (exp, from_tty)
952 char *exp;
953 int from_tty;
954{
955 print_command_1 (exp, 0, 0);
956}
957
958/* ARGSUSED */
959void
960output_command (exp, from_tty)
961 char *exp;
962 int from_tty;
963{
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;
969
970 if (exp && *exp == '/')
971 {
972 exp++;
973 fmt = decode_format (&exp, 0, 0);
974 validate_format (fmt, "output");
975 format = fmt.format;
976 }
977
978 expr = parse_expression (exp);
979 old_chain = make_cleanup ((make_cleanup_func) free_current_contents, &expr);
980
981 val = evaluate_expression (expr);
982
983 annotate_value_begin (VALUE_TYPE (val));
984
985 print_formatted (val, format, fmt.size);
986
987 annotate_value_end ();
988
989 do_cleanups (old_chain);
990}
991
992/* ARGSUSED */
993static void
994set_command (exp, from_tty)
995 char *exp;
996 int from_tty;
997{
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);
1003}
1004
1005/* ARGSUSED */
1006static void
1007sym_info (arg, from_tty)
1008 char *arg;
1009 int from_tty;
1010{
1011 struct minimal_symbol *msymbol;
1012 struct objfile *objfile;
1013 struct obj_section *osect;
1014 asection *sect;
1015 CORE_ADDR addr, sect_addr;
1016 int matches = 0;
1017 unsigned int offset;
1018
1019 if (!arg)
1020 error_no_arg ("address");
1021
1022 addr = parse_and_eval_address (arg);
1023 ALL_OBJSECTIONS (objfile, osect)
1024 {
1025 sect = osect->the_bfd_section;
1026 sect_addr = overlay_mapped_address (addr, sect);
1027
1028 if (osect->addr <= sect_addr && sect_addr < osect->endaddr &&
1029 (msymbol = lookup_minimal_symbol_by_pc_section (sect_addr, sect)))
1030 {
1031 matches = 1;
1032 offset = sect_addr - SYMBOL_VALUE_ADDRESS (msymbol);
1033 if (offset)
1034 printf_filtered ("%s + %u in ",
1035 SYMBOL_SOURCE_NAME (msymbol), offset);
1036 else
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");
1046 }
1047 }
1048 if (matches == 0)
1049 printf_filtered ("No symbol matches %s.\n", arg);
1050}
1051
1052/* ARGSUSED */
1053static void
1054address_info (exp, from_tty)
1055 char *exp;
1056 int from_tty;
1057{
1058 register struct symbol *sym;
1059 register struct minimal_symbol *msymbol;
1060 register long val;
1061 register long basereg;
1062 asection *section;
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'. */
1066
1067 if (exp == 0)
1068 error ("Argument required.");
1069
1070 sym = lookup_symbol (exp, get_selected_block (), VAR_NAMESPACE,
1071 &is_a_field_of_this, (struct symtab **)NULL);
1072 if (sym == NULL)
1073 {
1074 if (is_a_field_of_this)
1075 {
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");
1080 return;
1081 }
1082
1083 msymbol = lookup_minimal_symbol (exp, NULL, NULL);
1084
1085 if (msymbol != NULL)
1086 {
1087 load_addr = SYMBOL_VALUE_ADDRESS (msymbol);
1088
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))
1097 {
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);
1102 }
1103 printf_filtered (".\n");
1104 }
1105 else
1106 error ("No symbol \"%s\" in current context.", exp);
1107 return;
1108 }
1109
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);
1117
1118 switch (SYMBOL_CLASS (sym))
1119 {
1120 case LOC_CONST:
1121 case LOC_CONST_BYTES:
1122 printf_filtered ("constant");
1123 break;
1124
1125 case LOC_LABEL:
1126 printf_filtered ("a label at address ");
1127 print_address_numeric (load_addr = SYMBOL_VALUE_ADDRESS (sym),
1128 1, gdb_stdout);
1129 if (section_is_overlay (section))
1130 {
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);
1135 }
1136 break;
1137
1138 case LOC_REGISTER:
1139 printf_filtered ("a variable in register %s", REGISTER_NAME (val));
1140 break;
1141
1142 case LOC_STATIC:
1143 printf_filtered ("static storage at address ");
1144 print_address_numeric (load_addr = SYMBOL_VALUE_ADDRESS (sym),
1145 1, gdb_stdout);
1146 if (section_is_overlay (section))
1147 {
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);
1152 }
1153 break;
1154
1155 case LOC_INDIRECT:
1156 printf_filtered ("external global (indirect addressing), at address *(");
1157 print_address_numeric (load_addr = SYMBOL_VALUE_ADDRESS (sym),
1158 1, gdb_stdout);
1159 printf_filtered (")");
1160 if (section_is_overlay (section))
1161 {
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);
1166 }
1167 break;
1168
1169 case LOC_REGPARM:
1170 printf_filtered ("an argument in register %s", REGISTER_NAME (val));
1171 break;
1172
1173 case LOC_REGPARM_ADDR:
1174 printf_filtered ("address of an argument in register %s", REGISTER_NAME (val));
1175 break;
1176
1177 case LOC_ARG:
1178 printf_filtered ("an argument at offset %ld", val);
1179 break;
1180
1181 case LOC_LOCAL_ARG:
1182 printf_filtered ("an argument at frame offset %ld", val);
1183 break;
1184
1185 case LOC_LOCAL:
1186 printf_filtered ("a local variable at frame offset %ld", val);
1187 break;
1188
1189 case LOC_REF_ARG:
1190 printf_filtered ("a reference argument at offset %ld", val);
1191 break;
1192
1193 case LOC_BASEREG:
1194 printf_filtered ("a variable at offset %ld from register %s",
1195 val, REGISTER_NAME (basereg));
1196 break;
1197
1198 case LOC_BASEREG_ARG:
1199 printf_filtered ("an argument at offset %ld from register %s",
1200 val, REGISTER_NAME (basereg));
1201 break;
1202
1203 case LOC_TYPEDEF:
1204 printf_filtered ("a typedef");
1205 break;
1206
1207 case LOC_BLOCK:
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))),
1212 1, gdb_stdout);
1213#else
1214 print_address_numeric (load_addr=BLOCK_START (SYMBOL_BLOCK_VALUE (sym)),
1215 1, gdb_stdout);
1216#endif
1217 if (section_is_overlay (section))
1218 {
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);
1223 }
1224 break;
1225
1226 case LOC_UNRESOLVED:
1227 {
1228 struct minimal_symbol *msym;
1229
1230 msym = lookup_minimal_symbol (SYMBOL_NAME (sym), NULL, NULL);
1231 if (msym == NULL)
1232 printf_filtered ("unresolved");
1233 else
1234 {
1235 section = SYMBOL_BFD_SECTION (msym);
1236 printf_filtered ("static storage at address ");
1237 print_address_numeric (load_addr = SYMBOL_VALUE_ADDRESS (msym),
1238 1, gdb_stdout);
1239 if (section_is_overlay (section))
1240 {
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);
1245 }
1246 }
1247 }
1248 break;
1249
1250 case LOC_THREAD_LOCAL_STATIC:
1251 printf_filtered (
1252 "a thread-local variable at offset %ld from the thread base register %s",
1253 val, REGISTER_NAME (basereg));
1254 break;
1255
1256 case LOC_OPTIMIZED_OUT:
1257 printf_filtered ("optimized out");
1258 break;
1259
1260 default:
1261 printf_filtered ("of unknown (botched) type");
1262 break;
1263 }
1264 printf_filtered (".\n");
1265}
1266\f
1267void
1268x_command (exp, from_tty)
1269 char *exp;
1270 int from_tty;
1271{
1272 struct expression *expr;
1273 struct format_data fmt;
1274 struct cleanup *old_chain;
1275 struct value *val;
1276
1277 fmt.format = last_format;
1278 fmt.size = last_size;
1279 fmt.count = 1;
1280
1281 if (exp && *exp == '/')
1282 {
1283 exp++;
1284 fmt = decode_format (&exp, last_format, last_size);
1285 }
1286
1287 /* If we have an expression, evaluate it and use it as the address. */
1288
1289 if (exp != 0 && *exp != 0)
1290 {
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. */
1295 if (from_tty)
1296 *exp = 0;
1297 old_chain = make_cleanup ((make_cleanup_func) free_current_contents,
1298 &expr);
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);
1308 else
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);
1313 }
1314
1315 do_examine (fmt, next_address, next_section);
1316
1317 /* If the examine succeeds, we remember its size and format for next time. */
1318 last_size = fmt.size;
1319 last_format = fmt.format;
1320
1321 /* Set a couple of internal variables if appropriate. */
1322 if (last_examine_value)
1323 {
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));
1330
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));
1337 else
1338 set_internalvar (lookup_internalvar ("__"), last_examine_value);
1339 }
1340}
1341
1342\f
1343/* Add an expression to the auto-display chain.
1344 Specify the expression. */
1345
1346static void
1347display_command (exp, from_tty)
1348 char *exp;
1349 int from_tty;
1350{
1351 struct format_data fmt;
1352 register struct expression *expr;
1353 register struct display *new;
1354 int display_it = 1;
1355
1356#if defined(TUI)
1357 if (tui_version && *exp == '$')
1358 display_it = ((TuiStatus)tuiDo(
1359 (TuiOpaqueFuncPtr)tui_vSetLayoutTo, exp) == TUI_FAILURE);
1360#endif
1361
1362 if (display_it)
1363 {
1364 if (exp == 0)
1365 {
1366 do_displays ();
1367 return;
1368 }
1369
1370 if (*exp == '/')
1371 {
1372 exp++;
1373 fmt = decode_format (&exp, 0, 0);
1374 if (fmt.size && fmt.format == 0)
1375 fmt.format = 'x';
1376 if (fmt.format == 'i' || fmt.format == 's')
1377 fmt.size = 'b';
1378 }
1379 else
1380 {
1381 fmt.format = 0;
1382 fmt.size = 0;
1383 fmt.count = 0;
1384 }
1385
1386 innermost_block = 0;
1387 expr = parse_expression (exp);
1388
1389 new = (struct display *) xmalloc (sizeof (struct display));
1390
1391 new->exp = expr;
1392 new->block = innermost_block;
1393 new->next = display_chain;
1394 new->number = ++display_number;
1395 new->format = fmt;
1396 new->status = enabled;
1397 display_chain = new;
1398
1399 if (from_tty && target_has_execution)
1400 do_one_display (new);
1401
1402 dont_repeat ();
1403 }
1404}
1405
1406static void
1407free_display (d)
1408 struct display *d;
1409{
1410 free ((PTR)d->exp);
1411 free ((PTR)d);
1412}
1413
1414/* Clear out the display_chain.
1415 Done when new symtabs are loaded, since this invalidates
1416 the types stored in many expressions. */
1417
1418void
1419clear_displays ()
1420{
1421 register struct display *d;
1422
1423 while ((d = display_chain) != NULL)
1424 {
1425 free ((PTR)d->exp);
1426 display_chain = d->next;
1427 free ((PTR)d);
1428 }
1429}
1430
1431/* Delete the auto-display number NUM. */
1432
1433static void
1434delete_display (num)
1435 int num;
1436{
1437 register struct display *d1, *d;
1438
1439 if (!display_chain)
1440 error ("No display number %d.", num);
1441
1442 if (display_chain->number == num)
1443 {
1444 d1 = display_chain;
1445 display_chain = d1->next;
1446 free_display (d1);
1447 }
1448 else
1449 for (d = display_chain; ; d = d->next)
1450 {
1451 if (d->next == 0)
1452 error ("No display number %d.", num);
1453 if (d->next->number == num)
1454 {
1455 d1 = d->next;
1456 d->next = d1->next;
1457 free_display (d1);
1458 break;
1459 }
1460 }
1461}
1462
1463/* Delete some values from the auto-display chain.
1464 Specify the element numbers. */
1465
1466static void
1467undisplay_command (args, from_tty)
1468 char *args;
1469 int from_tty;
1470{
1471 register char *p = args;
1472 register char *p1;
1473 register int num;
1474
1475 if (args == 0)
1476 {
1477 if (query ("Delete all auto-display expressions? "))
1478 clear_displays ();
1479 dont_repeat ();
1480 return;
1481 }
1482
1483 while (*p)
1484 {
1485 p1 = p;
1486 while (*p1 >= '0' && *p1 <= '9') p1++;
1487 if (*p1 && *p1 != ' ' && *p1 != '\t')
1488 error ("Arguments must be display numbers.");
1489
1490 num = atoi (p);
1491
1492 delete_display (num);
1493
1494 p = p1;
1495 while (*p == ' ' || *p == '\t') p++;
1496 }
1497 dont_repeat ();
1498}
1499
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. */
1503
1504static void
1505do_one_display (d)
1506 struct display *d;
1507{
1508 int within_current_scope;
1509
1510 if (d->status == disabled)
1511 return;
1512
1513 if (d->block)
1514 within_current_scope = contained_in (get_selected_block (), d->block);
1515 else
1516 within_current_scope = 1;
1517 if (!within_current_scope)
1518 return;
1519
1520 current_display_number = d->number;
1521
1522 annotate_display_begin ();
1523 printf_filtered ("%d", d->number);
1524 annotate_display_number_end ();
1525 printf_filtered (": ");
1526 if (d->format.size)
1527 {
1528 CORE_ADDR addr;
1529 value_ptr val;
1530
1531 annotate_display_format ();
1532
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 (" ");
1540
1541 annotate_display_expression ();
1542
1543 print_expression (d->exp, gdb_stdout);
1544 annotate_display_expression_end ();
1545
1546 if (d->format.count != 1)
1547 printf_filtered ("\n");
1548 else
1549 printf_filtered (" ");
1550
1551 val = evaluate_expression (d->exp);
1552 addr = value_as_pointer (val);
1553 if (d->format.format == 'i')
1554 addr = ADDR_BITS_REMOVE (addr);
1555
1556 annotate_display_value ();
1557
1558 do_examine (d->format, addr, VALUE_BFD_SECTION (val));
1559 }
1560 else
1561 {
1562 annotate_display_format ();
1563
1564 if (d->format.format)
1565 printf_filtered ("/%c ", d->format.format);
1566
1567 annotate_display_expression ();
1568
1569 print_expression (d->exp, gdb_stdout);
1570 annotate_display_expression_end ();
1571
1572 printf_filtered (" = ");
1573
1574 annotate_display_expression ();
1575
1576 print_formatted (evaluate_expression (d->exp),
1577 d->format.format, d->format.size);
1578 printf_filtered ("\n");
1579 }
1580
1581 annotate_display_end ();
1582
1583 gdb_flush (gdb_stdout);
1584 current_display_number = -1;
1585}
1586
1587/* Display all of the values on the auto-display chain which can be
1588 evaluated in the current scope. */
1589
1590void
1591do_displays ()
1592{
1593 register struct display *d;
1594
1595 for (d = display_chain; d; d = d->next)
1596 do_one_display (d);
1597}
1598
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. */
1601
1602void
1603disable_display (num)
1604 int num;
1605{
1606 register struct display *d;
1607
1608 for (d = display_chain; d; d = d->next)
1609 if (d->number == num)
1610 {
1611 d->status = disabled;
1612 return;
1613 }
1614 printf_unfiltered ("No display number %d.\n", num);
1615}
1616
1617void
1618disable_current_display ()
1619{
1620 if (current_display_number >= 0)
1621 {
1622 disable_display (current_display_number);
1623 fprintf_unfiltered (gdb_stderr, "Disabling display %d to avoid infinite recursion.\n",
1624 current_display_number);
1625 }
1626 current_display_number = -1;
1627}
1628
1629static void
1630display_info (ignore, from_tty)
1631 char *ignore;
1632 int from_tty;
1633{
1634 register struct display *d;
1635
1636 if (!display_chain)
1637 printf_unfiltered ("There are no auto-display expressions now.\n");
1638 else
1639 printf_filtered ("Auto-display expressions now in effect:\n\
1640Num Enb Expression\n");
1641
1642 for (d = display_chain; d; d = d->next)
1643 {
1644 printf_filtered ("%d: %c ", d->number, "ny"[(int)d->status]);
1645 if (d->format.size)
1646 printf_filtered ("/%d%c%c ", d->format.count, d->format.size,
1647 d->format.format);
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);
1655 }
1656}
1657
1658static void
1659enable_display (args, from_tty)
1660 char *args;
1661 int from_tty;
1662{
1663 register char *p = args;
1664 register char *p1;
1665 register int num;
1666 register struct display *d;
1667
1668 if (p == 0)
1669 {
1670 for (d = display_chain; d; d = d->next)
1671 d->status = enabled;
1672 }
1673 else
1674 while (*p)
1675 {
1676 p1 = p;
1677 while (*p1 >= '0' && *p1 <= '9')
1678 p1++;
1679 if (*p1 && *p1 != ' ' && *p1 != '\t')
1680 error ("Arguments must be display numbers.");
1681
1682 num = atoi (p);
1683
1684 for (d = display_chain; d; d = d->next)
1685 if (d->number == num)
1686 {
1687 d->status = enabled;
1688 goto win;
1689 }
1690 printf_unfiltered ("No display number %d.\n", num);
1691 win:
1692 p = p1;
1693 while (*p == ' ' || *p == '\t')
1694 p++;
1695 }
1696}
1697
1698/* ARGSUSED */
1699static void
1700disable_display_command (args, from_tty)
1701 char *args;
1702 int from_tty;
1703{
1704 register char *p = args;
1705 register char *p1;
1706 register struct display *d;
1707
1708 if (p == 0)
1709 {
1710 for (d = display_chain; d; d = d->next)
1711 d->status = disabled;
1712 }
1713 else
1714 while (*p)
1715 {
1716 p1 = p;
1717 while (*p1 >= '0' && *p1 <= '9')
1718 p1++;
1719 if (*p1 && *p1 != ' ' && *p1 != '\t')
1720 error ("Arguments must be display numbers.");
1721
1722 disable_display (atoi (p));
1723
1724 p = p1;
1725 while (*p == ' ' || *p == '\t')
1726 p++;
1727 }
1728}
1729
1730\f
1731/* Print the value in stack frame FRAME of a variable
1732 specified by a struct symbol. */
1733
1734void
1735print_variable_value (var, frame, stream)
1736 struct symbol *var;
1737 struct frame_info *frame;
1738 GDB_FILE *stream;
1739{
1740 value_ptr val = read_var_value (var, frame);
1741
1742 value_print (val, stream, 0, Val_pretty_default);
1743}
1744
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). */
1748
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. */
1752
1753void
1754print_frame_args (func, fi, num, stream)
1755 struct symbol *func;
1756 struct frame_info *fi;
1757 int num;
1758 GDB_FILE *stream;
1759{
1760 struct block *b = NULL;
1761 int nsyms = 0;
1762 int first = 1;
1763 register int i;
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;
1770 int arg_size;
1771 /* Number of ints of arguments that we have printed so far. */
1772 int args_printed = 0;
1773
1774 if (func)
1775 {
1776 b = SYMBOL_BLOCK_VALUE (func);
1777 nsyms = BLOCK_NSYMS (b);
1778 }
1779
1780 for (i = 0; i < nsyms; i++)
1781 {
1782 QUIT;
1783 sym = BLOCK_SYM (b, i);
1784
1785 /* Keep track of the highest stack argument offset seen, and
1786 skip over any kinds of symbols we don't care about. */
1787
1788 switch (SYMBOL_CLASS (sym)) {
1789 case LOC_ARG:
1790 case LOC_REF_ARG:
1791 {
1792 long current_offset = SYMBOL_VALUE (sym);
1793 arg_size = TYPE_LENGTH (SYMBOL_TYPE (sym));
1794
1795 /* Compute address of next argument by adding the size of
1796 this argument and rounding to an int boundary. */
1797 current_offset
1798 = ((current_offset + arg_size + sizeof (int) - 1)
1799 & ~(sizeof (int) - 1));
1800
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;
1805
1806 /* Add the number of ints we're about to print to args_printed. */
1807 args_printed += (arg_size + sizeof (int) - 1) / sizeof (int);
1808 }
1809
1810 /* We care about types of symbols, but don't need to keep track of
1811 stack offsets in them. */
1812 case LOC_REGPARM:
1813 case LOC_REGPARM_ADDR:
1814 case LOC_LOCAL_ARG:
1815 case LOC_BASEREG_ARG:
1816 break;
1817
1818 /* Other types of symbols we just skip over. */
1819 default:
1820 continue;
1821 }
1822
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
1831 float). */
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? */
1835
1836 if (*SYMBOL_NAME (sym))
1837 {
1838 struct symbol *nsym;
1839 nsym = lookup_symbol
1840 (SYMBOL_NAME (sym),
1841 b, VAR_NAMESPACE, (int *)NULL, (struct symtab **)NULL);
1842 if (SYMBOL_CLASS (nsym) == LOC_REGISTER)
1843 {
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.
1848
1849 Reasons for using the LOC_ARG:
1850 (1) because find_saved_registers may be slow for remote
1851 debugging,
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.
1855
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.
1862
1863 Additional note: It might be nice if "info args" displayed
1864 both values.
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. */
1868
1869 /* Leave sym (the LOC_ARG) alone. */
1870 ;
1871 }
1872 else
1873 sym = nsym;
1874 }
1875
1876 /* Print the current arg. */
1877 if (! first)
1878 fprintf_filtered (stream, ", ");
1879 wrap_here (" ");
1880
1881 annotate_arg_begin ();
1882
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);
1887
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);
1894
1895 annotate_arg_value (val == NULL ? NULL : VALUE_TYPE (val));
1896
1897 if (val)
1898 {
7a292a7a
SS
1899 if (GDB_TARGET_IS_D10V
1900 && SYMBOL_CLASS(sym) == LOC_REGPARM && TYPE_CODE(VALUE_TYPE(val)) == TYPE_CODE_PTR)
c906108c 1901 TYPE_LENGTH(VALUE_TYPE(val)) = 2;
c906108c
SS
1902 val_print (VALUE_TYPE (val), VALUE_CONTENTS (val), 0,
1903 VALUE_ADDRESS (val),
1904 stream, 0, 0, 2, Val_no_prettyprint);
1905 }
1906 else
1907 fputs_filtered ("???", stream);
1908
1909 annotate_arg_end ();
1910
1911 first = 0;
1912 }
1913
1914 /* Don't print nameless args in situations where we don't know
1915 enough about the stack to find them. */
1916 if (num != -1)
1917 {
1918 long start;
1919
1920 if (highest_offset == -1)
1921 start = FRAME_ARGS_SKIP;
1922 else
1923 start = highest_offset;
1924
1925 print_frame_nameless_args (fi, start, num - args_printed,
1926 first, stream);
1927 }
1928}
1929
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). */
1935
1936static void
1937print_frame_nameless_args (fi, start, num, first, stream)
1938 struct frame_info *fi;
1939 long start;
1940 int num;
1941 int first;
1942 GDB_FILE *stream;
1943{
1944 int i;
1945 CORE_ADDR argsaddr;
1946 long arg_value;
1947
1948 for (i = 0; i < num; i++)
1949 {
1950 QUIT;
1951#ifdef NAMELESS_ARG_VALUE
1952 NAMELESS_ARG_VALUE (fi, start, &arg_value);
1953#else
1954 argsaddr = FRAME_ARGS_ADDRESS (fi);
1955 if (!argsaddr)
1956 return;
1957
1958 arg_value = read_memory_integer (argsaddr + start, sizeof (int));
1959#endif
1960
1961 if (!first)
1962 fprintf_filtered (stream, ", ");
1963
1964#ifdef PRINT_NAMELESS_INTEGER
1965 PRINT_NAMELESS_INTEGER (stream, arg_value);
1966#else
1967#ifdef PRINT_TYPELESS_INTEGER
1968 PRINT_TYPELESS_INTEGER (stream, builtin_type_int, (LONGEST) arg_value);
1969#else
1970 fprintf_filtered (stream, "%ld", arg_value);
1971#endif /* PRINT_TYPELESS_INTEGER */
1972#endif /* PRINT_NAMELESS_INTEGER */
1973 first = 0;
1974 start += sizeof (int);
1975 }
1976}
1977\f
1978/* ARGSUSED */
1979static void
1980printf_command (arg, from_tty)
1981 char *arg;
1982 int from_tty;
1983{
1984 register char *f = NULL;
1985 register char *s = arg;
1986 char *string = NULL;
1987 value_ptr *val_args;
1988 char *substrings;
1989 char *current_substring;
1990 int nargs = 0;
1991 int allocated_args = 20;
1992 struct cleanup *old_cleanups;
1993
1994 val_args = (value_ptr *) xmalloc (allocated_args * sizeof (value_ptr));
1995 old_cleanups = make_cleanup ((make_cleanup_func) free_current_contents,
1996 &val_args);
1997
1998 if (s == 0)
1999 error_no_arg ("format-control string and values to print");
2000
2001 /* Skip white space before format string */
2002 while (*s == ' ' || *s == '\t') s++;
2003
2004 /* A format string should follow, enveloped in double quotes */
2005 if (*s++ != '"')
2006 error ("Bad format string, missing '\"'.");
2007
2008 /* Parse the format-control string and copy it into the string STRING,
2009 processing some kinds of escape sequence. */
2010
2011 f = string = (char *) alloca (strlen (s) + 1);
2012
2013 while (*s != '"')
2014 {
2015 int c = *s++;
2016 switch (c)
2017 {
2018 case '\0':
2019 error ("Bad format string, non-terminated '\"'.");
2020
2021 case '\\':
2022 switch (c = *s++)
2023 {
2024 case '\\':
2025 *f++ = '\\';
2026 break;
2027 case 'a':
2028#ifdef __STDC__
2029 *f++ = '\a';
2030#else
2031 *f++ = '\007'; /* Bell */
2032#endif
2033 break;
2034 case 'b':
2035 *f++ = '\b';
2036 break;
2037 case 'f':
2038 *f++ = '\f';
2039 break;
2040 case 'n':
2041 *f++ = '\n';
2042 break;
2043 case 'r':
2044 *f++ = '\r';
2045 break;
2046 case 't':
2047 *f++ = '\t';
2048 break;
2049 case 'v':
2050 *f++ = '\v';
2051 break;
2052 case '"':
2053 *f++ = '"';
2054 break;
2055 default:
2056 /* ??? TODO: handle other escape sequences */
2057 error ("Unrecognized escape character \\%c in format string.",
2058 c);
2059 }
2060 break;
2061
2062 default:
2063 *f++ = c;
2064 }
2065 }
2066
2067 /* Skip over " and following space and comma. */
2068 s++;
2069 *f++ = '\0';
2070 while (*s == ' ' || *s == '\t') s++;
2071
2072 if (*s != ',' && *s != 0)
2073 error ("Invalid argument syntax");
2074
2075 if (*s == ',') s++;
2076 while (*s == ' ' || *s == '\t') s++;
2077
2078 /* Need extra space for the '\0's. Doubling the size is sufficient. */
2079 substrings = alloca (strlen (string) * 2);
2080 current_substring = substrings;
2081
2082 {
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. */
2086
2087 enum argclass {no_arg, int_arg, string_arg, double_arg, long_long_arg};
2088 enum argclass *argclass;
2089 enum argclass this_argclass;
2090 char *last_arg;
2091 int nargs_wanted;
2092 int lcount;
2093 int i;
2094
2095 argclass = (enum argclass *) alloca (strlen (s) * sizeof *argclass);
2096 nargs_wanted = 0;
2097 f = string;
2098 last_arg = string;
2099 while (*f)
2100 if (*f++ == '%')
2101 {
2102 lcount = 0;
2103 while (strchr ("0123456789.hlL-+ #", *f))
2104 {
2105 if (*f == 'l' || *f == 'L')
2106 lcount++;
2107 f++;
2108 }
2109 switch (*f)
2110 {
2111 case 's':
2112 this_argclass = string_arg;
2113 break;
2114
2115 case 'e':
2116 case 'f':
2117 case 'g':
2118 this_argclass = double_arg;
2119 break;
2120
2121 case '*':
2122 error ("`*' not supported for precision or width in printf");
2123
2124 case 'n':
2125 error ("Format specifier `n' not supported in printf");
2126
2127 case '%':
2128 this_argclass = no_arg;
2129 break;
2130
2131 default:
2132 if (lcount > 1)
2133 this_argclass = long_long_arg;
2134 else
2135 this_argclass = int_arg;
2136 break;
2137 }
2138 f++;
2139 if (this_argclass != no_arg)
2140 {
2141 strncpy (current_substring, last_arg, f - last_arg);
2142 current_substring += f - last_arg;
2143 *current_substring++ = '\0';
2144 last_arg = f;
2145 argclass[nargs_wanted++] = this_argclass;
2146 }
2147 }
2148
2149 /* Now, parse all arguments and evaluate them.
2150 Store the VALUEs in VAL_ARGS. */
2151
2152 while (*s != '\0')
2153 {
2154 char *s1;
2155 if (nargs == allocated_args)
2156 val_args = (value_ptr *) xrealloc ((char *) val_args,
2157 (allocated_args *= 2)
2158 * sizeof (value_ptr));
2159 s1 = s;
2160 val_args[nargs] = parse_to_comma_and_eval (&s1);
2161
2162 /* If format string wants a float, unchecked-convert the value to
2163 floating point of the same size */
2164
2165 if (argclass[nargs] == double_arg)
2166 {
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;
2172 }
2173 nargs++;
2174 s = s1;
2175 if (*s == ',')
2176 s++;
2177 }
2178
2179 if (nargs != nargs_wanted)
2180 error ("Wrong number of arguments for specified format-string");
2181
2182 /* Now actually print them. */
2183 current_substring = substrings;
2184 for (i = 0; i < nargs; i++)
2185 {
2186 switch (argclass[i])
2187 {
2188 case string_arg:
2189 {
2190 char *str;
2191 CORE_ADDR tem;
2192 int j;
2193 tem = value_as_pointer (val_args[i]);
2194
2195 /* This is a %s argument. Find the length of the string. */
2196 for (j = 0; ; j++)
2197 {
2198 char c;
2199 QUIT;
2200 read_memory_section (tem + j, &c, 1,
2201 VALUE_BFD_SECTION (val_args[i]));
2202 if (c == 0)
2203 break;
2204 }
2205
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]));
2209 str[j] = 0;
2210
2211 printf_filtered (current_substring, str);
2212 }
2213 break;
2214 case double_arg:
2215 {
2216 double val = value_as_double (val_args[i]);
2217 printf_filtered (current_substring, val);
2218 break;
2219 }
2220 case long_long_arg:
2221#if defined (CC_HAS_LONG_LONG) && defined (PRINTF_HAS_LONG_LONG)
2222 {
2223 long long val = value_as_long (val_args[i]);
2224 printf_filtered (current_substring, val);
2225 break;
2226 }
2227#else
2228 error ("long long not supported in printf");
2229#endif
2230 case int_arg:
2231 {
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);
2235 break;
2236 }
2237 default: /* purecov: deadcode */
2238 error ("internal error in printf_command"); /* purecov: deadcode */
2239 }
2240 /* Skip to the next substring. */
2241 current_substring += strlen (current_substring) + 1;
2242 }
2243 /* Print the portion of the format string after the last argument. */
2244 printf_filtered (last_arg);
2245 }
2246 do_cleanups (old_cleanups);
2247}
2248\f
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
2254 assembly. */
2255
2256/* ARGSUSED */
2257static void
2258disassemble_command (arg, from_tty)
2259 char *arg;
2260 int from_tty;
2261{
2262 CORE_ADDR low, high;
2263 char *name;
2264 CORE_ADDR pc, pc_masked;
2265 char *space_index;
2266#if 0
2267 asection *section;
2268#endif
2269
2270 name = NULL;
2271 if (!arg)
2272 {
2273 if (!selected_frame)
2274 error ("No frame selected.\n");
2275
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");
2279#if defined(TUI)
2280 else if (tui_version)
2281 low = (CORE_ADDR)tuiDo((TuiOpaqueFuncPtr)tui_vGetLowDisassemblyAddress,
2282 (Opaque)low,
2283 (Opaque)pc);
2284#endif
2285 low += FUNCTION_START_OFFSET;
2286 }
2287 else if (!(space_index = (char *) strchr (arg, ' ')))
2288 {
2289 /* One argument. */
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");
2293#if defined(TUI)
2294 else if (tui_version)
2295 low = (CORE_ADDR)tuiDo((TuiOpaqueFuncPtr)tui_vGetLowDisassemblyAddress,
2296 (Opaque)low,
2297 (Opaque)pc);
2298#endif
2299#if 0
2300 if (overlay_debugging)
2301 {
2302 section = find_pc_overlay (pc);
2303 if (pc_in_unmapped_range (pc, section))
2304 {
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);
2310 }
2311 }
2312#endif
2313 low += FUNCTION_START_OFFSET;
2314 }
2315 else
2316 {
2317 /* Two arguments. */
2318 *space_index = '\0';
2319 low = parse_and_eval_address (arg);
2320 high = parse_and_eval_address (space_index + 1);
2321 }
2322
2323#if defined(TUI)
2324 if (!tui_version ||
2325 m_winPtrIsNull(disassemWin) || !disassemWin->generic.isVisible)
2326#endif
2327 {
2328 printf_filtered ("Dump of assembler code ");
2329 if (name != NULL)
2330 {
2331 printf_filtered ("for function %s:\n", name);
2332 }
2333 else
2334 {
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");
2340 }
2341
2342 /* Dump the specified range. */
2343 pc = low;
2344
2345#ifdef GDB_TARGET_MASK_DISAS_PC
2346 pc_masked = GDB_TARGET_MASK_DISAS_PC (pc);
2347#else
2348 pc_masked = pc;
2349#endif
2350
2351 while (pc_masked < high)
2352 {
2353 QUIT;
2354 print_address (pc_masked, gdb_stdout);
2355 printf_filtered (":\t");
2356 /* We often wrap here if there are long symbolic names. */
2357 wrap_here (" ");
2358 pc += print_insn (pc, gdb_stdout);
2359 printf_filtered ("\n");
2360
2361#ifdef GDB_TARGET_MASK_DISAS_PC
2362 pc_masked = GDB_TARGET_MASK_DISAS_PC (pc);
2363#else
2364 pc_masked = pc;
2365#endif
2366 }
2367 printf_filtered ("End of assembler dump.\n");
2368 gdb_flush (gdb_stdout);
2369 }
2370#if defined(TUI)
2371 else
2372 {
2373 tuiDo((TuiOpaqueFuncPtr)tui_vAddWinToLayout, DISASSEM_WIN);
2374 tuiDo((TuiOpaqueFuncPtr)tui_vUpdateSourceWindowsWithAddr, low);
2375 }
2376#endif
2377}
2378
2379/* Print the instruction at address MEMADDR in debugged memory,
2380 on STREAM. Returns length of the instruction, in bytes. */
2381
2382static int
2383print_insn (memaddr, stream)
2384 CORE_ADDR memaddr;
2385 GDB_FILE *stream;
2386{
2387 if (TARGET_BYTE_ORDER == BIG_ENDIAN)
2388 TARGET_PRINT_INSN_INFO->endian = BFD_ENDIAN_BIG;
2389 else
2390 TARGET_PRINT_INSN_INFO->endian = BFD_ENDIAN_LITTLE;
2391
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 */
2395
2396 return TARGET_PRINT_INSN (memaddr, TARGET_PRINT_INSN_INFO);
2397}
2398
2399\f
2400void
2401_initialize_printcmd ()
2402{
2403 current_display_number = -1;
2404
2405 add_info ("address", address_info,
2406 "Describe where symbol SYM is stored.");
2407
2408 add_info ("symbol", sym_info,
2409 "Describe what symbol is at location ADDR.\n\
2410Only for symbols with fixed locations (global or static scope).");
2411
2412 add_com ("x", class_vars, x_command,
2413 concat ("Examine memory: x/FMT ADDRESS.\n\
2414ADDRESS is an expression for the memory address to examine.\n\
2415FMT is a repeat count followed by a format letter and a size letter.\n\
2416Format 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\
2419The specified number of objects of the specified size are printed\n\
2420according to the format.\n\n\
2421Defaults for format and size letters are those previously used.\n\
2422Default count is 1. Default address is following last thing printed\n\
2423with this command or \"print\".", NULL));
2424
2425 add_com ("disassemble", class_vars, disassemble_command,
2426 "Disassemble a specified section of memory.\n\
2427Default is the function surrounding the pc of the selected frame.\n\
2428With a single argument, the function surrounding that address is dumped.\n\
2429Two arguments are taken as a range of memory to dump.");
2430 if (xdb_commands)
2431 add_com_alias ("va", "disassemble", class_xdb, 0);
2432
2433#if 0
2434 add_com ("whereis", class_vars, whereis_command,
2435 "Print line number and file of definition of variable.");
2436#endif
2437
2438 add_info ("display", display_info,
2439 "Expressions to display when program stops, with code numbers.");
2440
2441 add_cmd ("undisplay", class_vars, undisplay_command,
2442 "Cancel some expressions to be displayed when program stops.\n\
2443Arguments are the code numbers of the expressions to stop displaying.\n\
2444No argument means cancel all automatic-display expressions.\n\
2445\"delete display\" has the same effect as this command.\n\
2446Do \"info display\" to see current list of code numbers.",
2447 &cmdlist);
2448
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\
2453as in the \"x\" command, and then EXP is used to get the address to examine\n\
2454and examining is done as in the \"x\" command.\n\n\
2455With no argument, display all currently requested auto-display expressions.\n\
2456Use \"undisplay\" to cancel display requests previously made."
2457);
2458
2459 add_cmd ("display", class_vars, enable_display,
2460 "Enable some expressions to be displayed when program stops.\n\
2461Arguments are the code numbers of the expressions to resume displaying.\n\
2462No argument means enable all automatic-display expressions.\n\
2463Do \"info display\" to see current list of code numbers.", &enablelist);
2464
2465 add_cmd ("display", class_vars, disable_display_command,
2466 "Disable some expressions to be displayed when program stops.\n\
2467Arguments are the code numbers of the expressions to stop displaying.\n\
2468No argument means disable all automatic-display expressions.\n\
2469Do \"info display\" to see current list of code numbers.", &disablelist);
2470
2471 add_cmd ("display", class_vars, undisplay_command,
2472 "Cancel some expressions to be displayed when program stops.\n\
2473Arguments are the code numbers of the expressions to stop displaying.\n\
2474No argument means cancel all automatic-display expressions.\n\
2475Do \"info display\" to see current list of code numbers.", &deletelist);
2476
2477 add_com ("printf", class_vars, printf_command,
2478 "printf \"printf format string\", arg1, arg2, arg3, ..., argn\n\
2479This is useful for formatted output in user-defined commands.");
2480
2481 add_com ("output", class_vars, output_command,
2482 "Like \"print\" but don't put in value history and don't print newline.\n\
2483This is useful in user-defined commands.");
2484
2485 add_prefix_cmd ("set", class_vars, set_command,
2486concat ("Evaluate expression EXP and assign result to variable VAR, using assignment\n\
2487syntax appropriate for the current language (VAR = EXP or VAR := EXP for\n\
2488example). VAR may be a debugger \"convenience\" variable (names starting\n\
2489with $), a register (a few standard names starting with $), or an actual\n\
2490variable 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\
2493You can see these environment settings with the \"show\" command.", NULL),
2494 &setlist, "set ", 1, &cmdlist);
2495 if (dbx_commands)
2496 add_com("assign", class_vars, set_command, concat ("Evaluate expression \
2497EXP and assign result to variable VAR, using assignment\n\
2498syntax appropriate for the current language (VAR = EXP or VAR := EXP for\n\
2499example). VAR may be a debugger \"convenience\" variable (names starting\n\
2500with $), a register (a few standard names starting with $), or an actual\n\
2501variable 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\
2504You can see these environment settings with the \"show\" command.", NULL));
2505
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\
2509The argument is the function name and arguments, in the notation of the\n\
2510current working language. The result is printed and saved in the value\n\
2511history, if it is not void.");
2512
2513 add_cmd ("variable", class_vars, set_command,
2514"Evaluate expression EXP and assign result to variable VAR, using assignment\n\
2515syntax appropriate for the current language (VAR = EXP or VAR := EXP for\n\
2516example). VAR may be a debugger \"convenience\" variable (names starting\n\
2517with $), a register (a few standard names starting with $), or an actual\n\
2518variable in the program being debugged. EXP is any valid expression.\n\
2519This may usually be abbreviated to simply \"set\".",
2520 &setlist);
2521
2522 add_com ("print", class_vars, print_command,
2523 concat ("Print value of expression EXP.\n\
2524Variables accessible are those of the lexical environment of the selected\n\
2525stack frame, plus all those whose scope is global or an entire file.\n\
2526\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\
2529Names 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\
2531all registers saved by frames farther in) or else to debugger\n\
2532\"convenience\" variables (any such name not a known register).\n\
2533Use assignment expressions to give values to convenience variables.\n",
2534 "\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\
2537anywhere in memory as an array. FOO@NUM gives an array whose first\n\
2538element is FOO, whose second element is stored in the space following\n\
2539where FOO is stored, etc. FOO must be an expression whose value\n\
2540resides in memory.\n",
2541 "\n\
2542EXP may be preceded with /FMT, where FMT is a format letter\n\
2543but no count or size letter (see \"x\" command).", NULL));
2544 add_com_alias ("p", "print", class_vars, 1);
2545
2546 add_com ("inspect", class_vars, inspect_command,
2547"Same as \"print\" command, except that if you are running in the epoch\n\
2548environment, the value is printed in its own window.");
2549
2550 add_show_from_set (
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.",
2554 &setprintlist),
2555 &showprintlist);
2556 add_show_from_set (
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>.",
2560 &setprintlist),
2561 &showprintlist);
2562
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);
2567
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);
2572
2573}
This page took 0.190898 seconds and 4 git commands to generate.