* printcmd.c (print_address_symbolic): Make it search the
[deliverable/binutils-gdb.git] / gdb / printcmd.c
CommitLineData
bd5635a1 1/* Print values for GNU debugger GDB.
314e6bf3
JG
2 Copyright 1986, 1987, 1988, 1989, 1990, 1991, 1993, 1994
3 Free Software Foundation, Inc.
bd5635a1
RP
4
5This file is part of GDB.
6
36b9d39c 7This program is free software; you can redistribute it and/or modify
bd5635a1 8it under the terms of the GNU General Public License as published by
36b9d39c
JG
9the Free Software Foundation; either version 2 of the License, or
10(at your option) any later version.
bd5635a1 11
36b9d39c 12This program is distributed in the hope that it will be useful,
bd5635a1
RP
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
36b9d39c
JG
18along with this program; if not, write to the Free Software
19Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
bd5635a1 20
bd5635a1 21#include "defs.h"
1eeba686 22#include <string.h>
19bdd57f 23#include <varargs.h>
bd5635a1
RP
24#include "frame.h"
25#include "symtab.h"
93fe4e33 26#include "gdbtypes.h"
bd5635a1 27#include "value.h"
c4668207 28#include "language.h"
bd5635a1
RP
29#include "expression.h"
30#include "gdbcore.h"
31#include "gdbcmd.h"
32#include "target.h"
93fe4e33 33#include "breakpoint.h"
4d38b5a8 34#include "demangle.h"
199b2450 35#include "valprint.h"
bd5635a1
RP
36
37extern int asm_demangle; /* Whether to demangle syms in asm printouts */
36b9d39c 38extern int addressprint; /* Whether to print hex addresses in HLL " */
bd5635a1 39
bd5635a1
RP
40struct format_data
41{
42 int count;
43 char format;
44 char size;
45};
46
47/* Last specified output format. */
48
49static char last_format = 'x';
50
51/* Last specified examination size. 'b', 'h', 'w' or `q'. */
52
53static char last_size = 'w';
54
55/* Default address to examine next. */
56
57static CORE_ADDR next_address;
58
59/* Last address examined. */
60
61static CORE_ADDR last_examine_address;
62
63/* Contents of last address examined.
64 This is not valid past the end of the `x' command! */
65
66static value last_examine_value;
67
f77ad505
FF
68/* Largest offset between a symbolic value and an address, that will be
69 printed as `0x1234 <symbol+offset>'. */
70
71static unsigned int max_symbolic_offset = UINT_MAX;
72
b7ccd8e0
PS
73/* Append the source filename and linenumber of the symbol when
74 printing a symbolic value as `<symbol at filename:linenum>' if set. */
75static int print_symbol_filename = 0;
76
314e6bf3
JG
77/* Switch for quick display of symbolic addresses -- only uses minsyms,
78 not full search of symtabs. */
79
80int fast_symbolic_addr = 1;
81
bd5635a1 82/* Number of auto-display expression currently being displayed.
f77ad505 83 So that we can disable it if we get an error or a signal within it.
bd5635a1
RP
84 -1 when not doing one. */
85
86int current_display_number;
87
88/* Flag to low-level print routines that this value is being printed
89 in an epoch window. We'd like to pass this as a parameter, but
90 every routine would need to take it. Perhaps we can encapsulate
91 this in the I/O stream once we have GNU stdio. */
92
93int inspect_it = 0;
94
93fe4e33
JG
95struct display
96{
97 /* Chain link to next auto-display item. */
98 struct display *next;
99 /* Expression to be evaluated and displayed. */
100 struct expression *exp;
101 /* Item number of this auto-display item. */
102 int number;
103 /* Display format specified. */
104 struct format_data format;
105 /* Innermost block required by this expression when evaluated */
106 struct block *block;
107 /* Status of this display (enabled or disabled) */
8f869b45 108 enum enable status;
93fe4e33
JG
109};
110
111/* Chain of expressions whose values should be displayed
112 automatically each time the program stops. */
113
114static struct display *display_chain;
115
116static int display_number;
117
118/* Prototypes for local functions */
119
120static void
121delete_display PARAMS ((int));
122
123static void
4d38b5a8 124enable_display PARAMS ((char *, int));
93fe4e33
JG
125
126static void
127disable_display_command PARAMS ((char *, int));
128
129static void
130disassemble_command PARAMS ((char *, int));
131
93fe4e33
JG
132static void
133printf_command PARAMS ((char *, int));
134
135static void
f77ad505 136print_frame_nameless_args PARAMS ((struct frame_info *, long, int, int,
199b2450 137 GDB_FILE *));
93fe4e33
JG
138
139static void
4d38b5a8 140display_info PARAMS ((char *, int));
93fe4e33
JG
141
142static void
143do_one_display PARAMS ((struct display *));
144
145static void
4d38b5a8 146undisplay_command PARAMS ((char *, int));
93fe4e33
JG
147
148static void
149free_display PARAMS ((struct display *));
150
151static void
152display_command PARAMS ((char *, int));
153
93fe4e33
JG
154static void
155x_command PARAMS ((char *, int));
156
157static void
158address_info PARAMS ((char *, int));
159
160static void
161set_command PARAMS ((char *, int));
162
163static void
164output_command PARAMS ((char *, int));
bd5635a1 165
93fe4e33
JG
166static void
167call_command PARAMS ((char *, int));
168
169static void
170inspect_command PARAMS ((char *, int));
171
172static void
173print_command PARAMS ((char *, int));
174
175static void
176print_command_1 PARAMS ((char *, int, int));
177
178static void
179validate_format PARAMS ((struct format_data, char *));
180
181static void
182do_examine PARAMS ((struct format_data, CORE_ADDR));
183
184static void
185print_formatted PARAMS ((value, int, int));
186
187static struct format_data
188decode_format PARAMS ((char **, int, int));
bd5635a1
RP
189
190\f
191/* Decode a format specification. *STRING_PTR should point to it.
192 OFORMAT and OSIZE are used as defaults for the format and size
193 if none are given in the format specification.
194 If OSIZE is zero, then the size field of the returned value
195 should be set only if a size is explicitly specified by the
196 user.
197 The structure returned describes all the data
198 found in the specification. In addition, *STRING_PTR is advanced
199 past the specification and past all whitespace following it. */
200
93fe4e33 201static struct format_data
bd5635a1
RP
202decode_format (string_ptr, oformat, osize)
203 char **string_ptr;
93fe4e33
JG
204 int oformat;
205 int osize;
bd5635a1
RP
206{
207 struct format_data val;
208 register char *p = *string_ptr;
209
210 val.format = '?';
211 val.size = '?';
212 val.count = 1;
213
214 if (*p >= '0' && *p <= '9')
215 val.count = atoi (p);
216 while (*p >= '0' && *p <= '9') p++;
217
218 /* Now process size or format letters that follow. */
219
220 while (1)
221 {
222 if (*p == 'b' || *p == 'h' || *p == 'w' || *p == 'g')
223 val.size = *p++;
bd5635a1
RP
224 else if (*p >= 'a' && *p <= 'z')
225 val.format = *p++;
226 else
227 break;
228 }
229
6fe90fc8 230#ifndef CC_HAS_LONG_LONG
bd5635a1
RP
231 /* Make sure 'g' size is not used on integer types.
232 Well, actually, we can handle hex. */
233 if (val.size == 'g' && val.format != 'f' && val.format != 'x')
234 val.size = 'w';
235#endif
236
237 while (*p == ' ' || *p == '\t') p++;
238 *string_ptr = p;
239
240 /* Set defaults for format and size if not specified. */
241 if (val.format == '?')
242 {
243 if (val.size == '?')
244 {
245 /* Neither has been specified. */
246 val.format = oformat;
247 val.size = osize;
248 }
249 else
250 /* If a size is specified, any format makes a reasonable
251 default except 'i'. */
252 val.format = oformat == 'i' ? 'x' : oformat;
253 }
254 else if (val.size == '?')
255 switch (val.format)
256 {
257 case 'a':
258 case 's':
259 /* Addresses must be words. */
260 val.size = osize ? 'w' : osize;
261 break;
262 case 'f':
263 /* Floating point has to be word or giantword. */
264 if (osize == 'w' || osize == 'g')
265 val.size = osize;
266 else
267 /* Default it to giantword if the last used size is not
268 appropriate. */
269 val.size = osize ? 'g' : osize;
270 break;
271 case 'c':
272 /* Characters default to one byte. */
273 val.size = osize ? 'b' : osize;
274 break;
275 default:
276 /* The default is the size most recently specified. */
277 val.size = osize;
278 }
279
280 return val;
281}
282\f
199b2450 283/* Print value VAL on gdb_stdout according to FORMAT, a letter or 0.
bd5635a1
RP
284 Do not end with a newline.
285 0 means print VAL according to its own type.
286 SIZE is the letter for the size of datum being printed.
287 This is used to pad hex numbers so they line up. */
288
289static void
290print_formatted (val, format, size)
291 register value val;
93fe4e33
JG
292 register int format;
293 int size;
bd5635a1
RP
294{
295 int len = TYPE_LENGTH (VALUE_TYPE (val));
296
297 if (VALUE_LVAL (val) == lval_memory)
298 next_address = VALUE_ADDRESS (val) + len;
299
300 switch (format)
301 {
302 case 's':
303 next_address = VALUE_ADDRESS (val)
199b2450 304 + value_print (value_addr (val), gdb_stdout, format, Val_pretty_default);
bd5635a1
RP
305 break;
306
307 case 'i':
43795ece
JK
308 /* The old comment says
309 "Force output out, print_insn not using _filtered".
310 I'm not completely sure what that means, I suspect most print_insn
311 now do use _filtered, so I guess it's obsolete. */
312 /* We often wrap here if there are long symbolic names. */
19bdd57f 313 wrap_here (" ");
bd5635a1 314 next_address = VALUE_ADDRESS (val)
199b2450 315 + print_insn (VALUE_ADDRESS (val), gdb_stdout);
bd5635a1
RP
316 break;
317
318 default:
319 if (format == 0
320 || TYPE_CODE (VALUE_TYPE (val)) == TYPE_CODE_ARRAY
7dc15bb7 321 || TYPE_CODE (VALUE_TYPE (val)) == TYPE_CODE_STRING
bd5635a1
RP
322 || TYPE_CODE (VALUE_TYPE (val)) == TYPE_CODE_STRUCT
323 || TYPE_CODE (VALUE_TYPE (val)) == TYPE_CODE_UNION
324 || VALUE_REPEATED (val))
199b2450 325 value_print (val, gdb_stdout, format, Val_pretty_default);
bd5635a1
RP
326 else
327 print_scalar_formatted (VALUE_CONTENTS (val), VALUE_TYPE (val),
199b2450 328 format, size, gdb_stdout);
bd5635a1
RP
329 }
330}
331
332/* Print a scalar of data of type TYPE, pointed to in GDB by VALADDR,
333 according to letters FORMAT and SIZE on STREAM.
334 FORMAT may not be zero. Formats s and i are not supported at this level.
335
336 This is how the elements of an array or structure are printed
337 with a format. */
338
339void
340print_scalar_formatted (valaddr, type, format, size, stream)
341 char *valaddr;
342 struct type *type;
93fe4e33 343 int format;
bd5635a1 344 int size;
199b2450 345 GDB_FILE *stream;
bd5635a1
RP
346{
347 LONGEST val_long;
348 int len = TYPE_LENGTH (type);
349
b0f61d04
JK
350 if (len > sizeof (LONGEST)
351 && (format == 't'
352 || format == 'c'
353 || format == 'o'
354 || format == 'u'
355 || format == 'd'
356 || format == 'x'))
bd5635a1 357 {
b0f61d04
JK
358 /* We can't print it normally, but we can print it in hex.
359 Printing it in the wrong radix is more useful than saying
360 "use /x, you dummy". */
361 /* FIXME: we could also do octal or binary if that was the
362 desired format. */
363 /* FIXME: we should be using the size field to give us a minimum
364 field width to print. */
365 val_print_type_code_int (type, valaddr, stream);
bd5635a1
RP
366 return;
367 }
b0f61d04 368
bd5635a1
RP
369 val_long = unpack_long (type, valaddr);
370
f73b07c9
JK
371 /* If we are printing it as unsigned, truncate it in case it is actually
372 a negative signed value (e.g. "print/u (short)-1" should print 65535
373 (if shorts are 16 bits) instead of 4294967295). */
bd5635a1
RP
374 if (format != 'd')
375 {
f73b07c9
JK
376 if (len < sizeof (LONGEST))
377 val_long &= ((LONGEST) 1 << HOST_CHAR_BIT * len) - 1;
bd5635a1
RP
378 }
379
380 switch (format)
381 {
382 case 'x':
383 if (!size)
384 {
385 /* no size specified, like in print. Print varying # of digits. */
6fe90fc8 386 print_longest (stream, 'x', 1, val_long);
bd5635a1
RP
387 }
388 else
6fe90fc8
JK
389 switch (size)
390 {
391 case 'b':
392 case 'h':
393 case 'w':
394 case 'g':
395 print_longest (stream, size, 1, val_long);
396 break;
397 default:
398 error ("Undefined output size \"%c\".", size);
399 }
bd5635a1
RP
400 break;
401
402 case 'd':
6fe90fc8 403 print_longest (stream, 'd', 1, val_long);
bd5635a1
RP
404 break;
405
406 case 'u':
6fe90fc8 407 print_longest (stream, 'u', 0, val_long);
bd5635a1
RP
408 break;
409
410 case 'o':
411 if (val_long)
6fe90fc8 412 print_longest (stream, 'o', 1, val_long);
bd5635a1
RP
413 else
414 fprintf_filtered (stream, "0");
415 break;
416
417 case 'a':
e1ce8aa5 418 print_address (unpack_pointer (type, valaddr), stream);
bd5635a1
RP
419 break;
420
421 case 'c':
c4668207 422 value_print (value_from_longest (builtin_type_char, val_long), stream, 0,
bd5635a1
RP
423 Val_pretty_default);
424 break;
425
426 case 'f':
427 if (len == sizeof (float))
428 type = builtin_type_float;
429 else if (len == sizeof (double))
430 type = builtin_type_double;
431 print_floating (valaddr, type, stream);
432 break;
433
434 case 0:
435 abort ();
436
19b7c2a4
JK
437 case 't':
438 /* Binary; 't' stands for "two". */
439 {
440 char bits[8*(sizeof val_long) + 1];
441 char *cp = bits;
442 int width;
443
444 if (!size)
445 width = 8*(sizeof val_long);
446 else
447 switch (size)
448 {
449 case 'b':
450 width = 8;
451 break;
452 case 'h':
453 width = 16;
454 break;
455 case 'w':
456 width = 32;
457 break;
458 case 'g':
459 width = 64;
460 break;
461 default:
462 error ("Undefined output size \"%c\".", size);
463 }
464
465 bits[width] = '\0';
466 while (width-- > 0)
467 {
468 bits[width] = (val_long & 1) ? '1' : '0';
469 val_long >>= 1;
470 }
471 if (!size)
472 {
473 while (*cp && *cp == '0')
474 cp++;
475 if (*cp == '\0')
476 cp--;
477 }
a8a69e63 478 fprintf_filtered (stream, local_binary_format_prefix());
19b7c2a4 479 fprintf_filtered (stream, cp);
a8a69e63 480 fprintf_filtered (stream, local_binary_format_suffix());
19b7c2a4
JK
481 }
482 break;
483
bd5635a1
RP
484 default:
485 error ("Undefined output format \"%c\".", format);
486 }
487}
488
489/* Specify default address for `x' command.
490 `info lines' uses this. */
491
492void
493set_next_address (addr)
494 CORE_ADDR addr;
495{
496 next_address = addr;
497
498 /* Make address available to the user as $_. */
499 set_internalvar (lookup_internalvar ("_"),
c4668207
JG
500 value_from_longest (lookup_pointer_type (builtin_type_void),
501 (LONGEST) addr));
bd5635a1
RP
502}
503
36b9d39c
JG
504/* Optionally print address ADDR symbolically as <SYMBOL+OFFSET> on STREAM,
505 after LEADIN. Print nothing if no symbolic name is found nearby.
314e6bf3 506 Optionally also print source file and line number, if available.
bd5635a1
RP
507 DO_DEMANGLE controls whether to print a symbol in its native "raw" form,
508 or to interpret it as a possible C++ name and convert it back to source
2e4964ad 509 form. However note that DO_DEMANGLE can be overridden by the specific
314e6bf3 510 settings of the demangle and asm_demangle variables. */
bd5635a1
RP
511
512void
36b9d39c 513print_address_symbolic (addr, stream, do_demangle, leadin)
bd5635a1 514 CORE_ADDR addr;
199b2450 515 GDB_FILE *stream;
bd5635a1 516 int do_demangle;
36b9d39c 517 char *leadin;
bd5635a1 518{
314e6bf3
JG
519 struct minimal_symbol *msymbol;
520 struct symbol *symbol;
521 struct symtab *symtab = 0;
f77ad505 522 CORE_ADDR name_location;
7586127f 523 char *name;
bd5635a1 524
314e6bf3
JG
525 /* First try to find the address in the symbol table, then
526 in the minsyms. Take the closest one. */
527
528 symbol = fast_symbolic_addr? 0:
529 find_addr_symbol (addr, &symtab, &name_location);
7586127f
PS
530 if (symbol)
531 {
314e6bf3
JG
532 if (do_demangle)
533 name = SYMBOL_SOURCE_NAME (symbol);
534 else
535 name = SYMBOL_LINKAGE_NAME (symbol);
7586127f 536 }
bd5635a1 537
314e6bf3
JG
538 msymbol = lookup_minimal_symbol_by_pc (addr);
539 if (msymbol != NULL)
540 {
541 if (SYMBOL_VALUE_ADDRESS (msymbol) > name_location)
542 {
543 /* The msymbol is closer to the address than the symbol;
544 use the msymbol instead. */
545 symbol = 0;
546 symtab = 0;
547 name_location = SYMBOL_VALUE_ADDRESS (msymbol);
548 if (do_demangle)
549 name = SYMBOL_SOURCE_NAME (msymbol);
550 else
551 name = SYMBOL_LINKAGE_NAME (msymbol);
552 }
7586127f 553 }
f77ad505 554
7586127f 555 /* If the nearest symbol is too far away, don't print anything symbolic. */
f77ad505
FF
556
557 /* For when CORE_ADDR is larger than unsigned int, we do math in
558 CORE_ADDR. But when we detect unsigned wraparound in the
559 CORE_ADDR math, we ignore this test and print the offset,
560 because addr+max_symbolic_offset has wrapped through the end
561 of the address space back to the beginning, giving bogus comparison. */
562 if (addr > name_location + max_symbolic_offset
563 && name_location + max_symbolic_offset > name_location)
564 return;
565
36b9d39c
JG
566 fputs_filtered (leadin, stream);
567 fputs_filtered ("<", stream);
7586127f 568 fputs_filtered (name, stream);
f77ad505 569 if (addr != name_location)
b7ccd8e0
PS
570 fprintf_filtered (stream, "+%u", (unsigned int)(addr - name_location));
571
314e6bf3
JG
572 /* Append source filename and line number if desired. Give specific
573 line # of this addr, if we have it; else line # of the nearest symbol. */
574 if (print_symbol_filename)
b7ccd8e0 575 {
633c8b0a
DZ
576 struct symtab_and_line sal;
577
578 sal = find_pc_line (addr, 0);
b7ccd8e0
PS
579 if (sal.symtab)
580 fprintf_filtered (stream, " at %s:%d", sal.symtab->filename, sal.line);
314e6bf3
JG
581 else if (symtab && symbol && symbol->line)
582 fprintf_filtered (stream, " at %s:%d", symtab->filename, symbol->line);
583 else if (symtab)
584 fprintf_filtered (stream, " in %s", symtab->filename);
b7ccd8e0
PS
585 }
586 fputs_filtered (">", stream);
bd5635a1
RP
587}
588
314e6bf3 589
bd5635a1
RP
590/* Print address ADDR symbolically on STREAM.
591 First print it as a number. Then perhaps print
592 <SYMBOL + OFFSET> after the number. */
593
594void
595print_address (addr, stream)
596 CORE_ADDR addr;
199b2450 597 GDB_FILE *stream;
bd5635a1 598{
b2ccb6a4
JK
599#if 0 && defined (ADDR_BITS_REMOVE)
600 /* This is wrong for pointer to char, in which we do want to print
601 the low bits. */
f73b07c9
JK
602 fprintf_filtered (stream, local_hex_format(),
603 (unsigned long) ADDR_BITS_REMOVE(addr));
8f869b45 604#else
f73b07c9 605 fprintf_filtered (stream, local_hex_format(), (unsigned long) addr);
8f869b45 606#endif
36b9d39c 607 print_address_symbolic (addr, stream, asm_demangle, " ");
bd5635a1
RP
608}
609
610/* Print address ADDR symbolically on STREAM. Parameter DEMANGLE
36b9d39c
JG
611 controls whether to print the symbolic name "raw" or demangled.
612 Global setting "addressprint" controls whether to print hex address
613 or not. */
bd5635a1
RP
614
615void
616print_address_demangle (addr, stream, do_demangle)
617 CORE_ADDR addr;
199b2450 618 GDB_FILE *stream;
bd5635a1
RP
619 int do_demangle;
620{
36b9d39c
JG
621 if (addr == 0) {
622 fprintf_filtered (stream, "0");
623 } else if (addressprint) {
f73b07c9 624 fprintf_filtered (stream, local_hex_format(), (unsigned long) addr);
36b9d39c
JG
625 print_address_symbolic (addr, stream, do_demangle, " ");
626 } else {
627 print_address_symbolic (addr, stream, do_demangle, "");
628 }
bd5635a1 629}
bd5635a1
RP
630\f
631
199b2450
TL
632/* These are the types that $__ will get after an examine command of one
633 of these sizes. */
634
635static struct type *examine_b_type;
636static struct type *examine_h_type;
637static struct type *examine_w_type;
638static struct type *examine_g_type;
639
bd5635a1 640/* Examine data at address ADDR in format FMT.
199b2450 641 Fetch it from memory and print on gdb_stdout. */
bd5635a1
RP
642
643static void
644do_examine (fmt, addr)
645 struct format_data fmt;
646 CORE_ADDR addr;
647{
648 register char format = 0;
649 register char size;
650 register int count = 1;
f73b07c9 651 struct type *val_type = NULL;
bd5635a1
RP
652 register int i;
653 register int maxelts;
654
655 format = fmt.format;
656 size = fmt.size;
657 count = fmt.count;
658 next_address = addr;
659
660 /* String or instruction format implies fetch single bytes
661 regardless of the specified size. */
662 if (format == 's' || format == 'i')
663 size = 'b';
664
665 if (size == 'b')
199b2450 666 val_type = examine_b_type;
bd5635a1 667 else if (size == 'h')
199b2450 668 val_type = examine_h_type;
bd5635a1 669 else if (size == 'w')
199b2450 670 val_type = examine_w_type;
bd5635a1 671 else if (size == 'g')
199b2450 672 val_type = examine_g_type;
bd5635a1
RP
673
674 maxelts = 8;
675 if (size == 'w')
676 maxelts = 4;
677 if (size == 'g')
678 maxelts = 2;
679 if (format == 's' || format == 'i')
680 maxelts = 1;
681
682 /* Print as many objects as specified in COUNT, at most maxelts per line,
683 with the address of the next one at the start of each line. */
684
685 while (count > 0)
686 {
199b2450 687 print_address (next_address, gdb_stdout);
bd5635a1
RP
688 printf_filtered (":");
689 for (i = maxelts;
690 i > 0 && count > 0;
691 i--, count--)
692 {
693 printf_filtered ("\t");
694 /* Note that print_formatted sets next_address for the next
695 object. */
696 last_examine_address = next_address;
697 last_examine_value = value_at (val_type, next_address);
698 print_formatted (last_examine_value, format, size);
699 }
700 printf_filtered ("\n");
199b2450 701 gdb_flush (gdb_stdout);
bd5635a1
RP
702 }
703}
704\f
705static void
706validate_format (fmt, cmdname)
707 struct format_data fmt;
708 char *cmdname;
709{
710 if (fmt.size != 0)
711 error ("Size letters are meaningless in \"%s\" command.", cmdname);
712 if (fmt.count != 1)
713 error ("Item count other than 1 is meaningless in \"%s\" command.",
714 cmdname);
715 if (fmt.format == 'i' || fmt.format == 's')
716 error ("Format letter \"%c\" is meaningless in \"%s\" command.",
717 fmt.format, cmdname);
718}
719
7dc15bb7
JG
720/* Evaluate string EXP as an expression in the current language and
721 print the resulting value. EXP may contain a format specifier as the
722 first argument ("/x myvar" for example, to print myvar in hex).
723 */
724
bd5635a1
RP
725static void
726print_command_1 (exp, inspect, voidprint)
727 char *exp;
728 int inspect;
729 int voidprint;
730{
731 struct expression *expr;
732 register struct cleanup *old_chain = 0;
733 register char format = 0;
734 register value val;
735 struct format_data fmt;
736 int cleanup = 0;
737
738 /* Pass inspect flag to the rest of the print routines in a global (sigh). */
739 inspect_it = inspect;
740
741 if (exp && *exp == '/')
742 {
743 exp++;
744 fmt = decode_format (&exp, last_format, 0);
745 validate_format (fmt, "print");
746 last_format = format = fmt.format;
747 }
748 else
749 {
750 fmt.count = 1;
751 fmt.format = 0;
752 fmt.size = 0;
753 }
754
755 if (exp && *exp)
756 {
3577f9b4
JK
757 extern int objectprint;
758 struct type *type;
c4668207 759 expr = parse_expression (exp);
bd5635a1
RP
760 old_chain = make_cleanup (free_current_contents, &expr);
761 cleanup = 1;
762 val = evaluate_expression (expr);
3577f9b4
JK
763
764 /* C++: figure out what type we actually want to print it as. */
765 type = VALUE_TYPE (val);
766
767 if (objectprint
93fe4e33 768 && ( TYPE_CODE (type) == TYPE_CODE_PTR
3577f9b4 769 || TYPE_CODE (type) == TYPE_CODE_REF)
93fe4e33
JG
770 && ( TYPE_CODE (TYPE_TARGET_TYPE (type)) == TYPE_CODE_STRUCT
771 || TYPE_CODE (TYPE_TARGET_TYPE (type)) == TYPE_CODE_UNION))
3577f9b4
JK
772 {
773 value v;
774
775 v = value_from_vtable_info (val, TYPE_TARGET_TYPE (type));
776 if (v != 0)
777 {
778 val = v;
779 type = VALUE_TYPE (val);
780 }
781 }
bd5635a1
RP
782 }
783 else
784 val = access_value_history (0);
785
786 if (voidprint || (val && VALUE_TYPE (val) &&
787 TYPE_CODE (VALUE_TYPE (val)) != TYPE_CODE_VOID))
788 {
789 int histindex = record_latest_value (val);
790
791 if (inspect)
199b2450 792 printf_unfiltered ("\031(gdb-makebuffer \"%s\" %d '(\"", exp, histindex);
bd5635a1
RP
793 else
794 if (histindex >= 0) printf_filtered ("$%d = ", histindex);
795
796 print_formatted (val, format, fmt.size);
797 printf_filtered ("\n");
798 if (inspect)
199b2450 799 printf_unfiltered("\") )\030");
bd5635a1
RP
800 }
801
802 if (cleanup)
803 do_cleanups (old_chain);
804 inspect_it = 0; /* Reset print routines to normal */
805}
806
e1ce8aa5 807/* ARGSUSED */
bd5635a1
RP
808static void
809print_command (exp, from_tty)
810 char *exp;
811 int from_tty;
812{
813 print_command_1 (exp, 0, 1);
814}
815
816/* Same as print, except in epoch, it gets its own window */
e1ce8aa5 817/* ARGSUSED */
bd5635a1
RP
818static void
819inspect_command (exp, from_tty)
820 char *exp;
821 int from_tty;
822{
823 extern int epoch_interface;
824
825 print_command_1 (exp, epoch_interface, 1);
826}
827
828/* Same as print, except it doesn't print void results. */
e1ce8aa5 829/* ARGSUSED */
bd5635a1
RP
830static void
831call_command (exp, from_tty)
832 char *exp;
833 int from_tty;
834{
835 print_command_1 (exp, 0, 0);
836}
837
e1ce8aa5 838/* ARGSUSED */
bd5635a1
RP
839static void
840output_command (exp, from_tty)
841 char *exp;
842 int from_tty;
843{
844 struct expression *expr;
845 register struct cleanup *old_chain;
846 register char format = 0;
847 register value val;
848 struct format_data fmt;
849
850 if (exp && *exp == '/')
851 {
852 exp++;
853 fmt = decode_format (&exp, 0, 0);
4d38b5a8 854 validate_format (fmt, "output");
bd5635a1
RP
855 format = fmt.format;
856 }
857
c4668207 858 expr = parse_expression (exp);
bd5635a1
RP
859 old_chain = make_cleanup (free_current_contents, &expr);
860
861 val = evaluate_expression (expr);
862
863 print_formatted (val, format, fmt.size);
864
865 do_cleanups (old_chain);
866}
867
e1ce8aa5 868/* ARGSUSED */
bd5635a1
RP
869static void
870set_command (exp, from_tty)
871 char *exp;
872 int from_tty;
873{
c4668207 874 struct expression *expr = parse_expression (exp);
bd5635a1
RP
875 register struct cleanup *old_chain
876 = make_cleanup (free_current_contents, &expr);
877 evaluate_expression (expr);
878 do_cleanups (old_chain);
879}
880
e1ce8aa5 881/* ARGSUSED */
bd5635a1
RP
882static void
883address_info (exp, from_tty)
884 char *exp;
885 int from_tty;
886{
887 register struct symbol *sym;
93fe4e33 888 register struct minimal_symbol *msymbol;
e1ce8aa5 889 register long val;
4d38b5a8 890 register long basereg;
bd5635a1
RP
891 int is_a_field_of_this; /* C++: lookup_symbol sets this to nonzero
892 if exp is a field of `this'. */
893
894 if (exp == 0)
895 error ("Argument required.");
896
897 sym = lookup_symbol (exp, get_selected_block (), VAR_NAMESPACE,
898 &is_a_field_of_this, (struct symtab **)NULL);
2e4964ad 899 if (sym == NULL)
bd5635a1 900 {
bd5635a1
RP
901 if (is_a_field_of_this)
902 {
ca603cff 903 printf_filtered ("Symbol \"");
91f87016
JL
904 fprintf_symbol_filtered (gdb_stdout, exp,
905 current_language->la_language, DMGL_ANSI);
ca603cff 906 printf_filtered ("\" is a field of the local class variable `this'\n");
bd5635a1
RP
907 return;
908 }
909
93fe4e33 910 msymbol = lookup_minimal_symbol (exp, (struct objfile *) NULL);
bd5635a1 911
93fe4e33 912 if (msymbol != NULL)
91f87016 913 {
ca603cff 914 printf_filtered ("Symbol \"");
91f87016
JL
915 fprintf_symbol_filtered (gdb_stdout, exp,
916 current_language->la_language, DMGL_ANSI);
ca603cff 917 printf_filtered ("\" is at %s in a file compiled without debugging.\n",
91f87016
JL
918 local_hex_string((unsigned long) SYMBOL_VALUE_ADDRESS (msymbol)));
919 }
bd5635a1
RP
920 else
921 error ("No symbol \"%s\" in current context.", exp);
922 return;
923 }
924
ca603cff 925 printf_filtered ("Symbol \"");
91f87016
JL
926 fprintf_symbol_filtered (gdb_stdout, SYMBOL_NAME (sym),
927 current_language->la_language, DMGL_ANSI);
ca603cff 928 printf_filtered ("\" is ", SYMBOL_NAME (sym));
bd5635a1 929 val = SYMBOL_VALUE (sym);
4d38b5a8 930 basereg = SYMBOL_BASEREG (sym);
bd5635a1
RP
931
932 switch (SYMBOL_CLASS (sym))
933 {
934 case LOC_CONST:
935 case LOC_CONST_BYTES:
ca603cff 936 printf_filtered ("constant");
bd5635a1
RP
937 break;
938
939 case LOC_LABEL:
ca603cff 940 printf_filtered ("a label at address %s",
f73b07c9 941 local_hex_string((unsigned long) SYMBOL_VALUE_ADDRESS (sym)));
bd5635a1
RP
942 break;
943
944 case LOC_REGISTER:
ca603cff 945 printf_filtered ("a variable in register %s", reg_names[val]);
bd5635a1
RP
946 break;
947
948 case LOC_STATIC:
ca603cff 949 printf_filtered ("static storage at address %s",
f73b07c9 950 local_hex_string((unsigned long) SYMBOL_VALUE_ADDRESS (sym)));
bd5635a1
RP
951 break;
952
953 case LOC_REGPARM:
ca603cff 954 printf_filtered ("an argument in register %s", reg_names[val]);
bd5635a1 955 break;
5afa2040 956
a1c8d76e 957 case LOC_REGPARM_ADDR:
ca603cff 958 printf_filtered ("address of an argument in register %s", reg_names[val]);
a1c8d76e
JK
959 break;
960
bd5635a1 961 case LOC_ARG:
ca603cff 962 printf_filtered ("an argument at offset %ld", val);
bd5635a1
RP
963 break;
964
965 case LOC_LOCAL_ARG:
ca603cff 966 printf_filtered ("an argument at frame offset %ld", val);
bd5635a1
RP
967 break;
968
969 case LOC_LOCAL:
ca603cff 970 printf_filtered ("a local variable at frame offset %ld", val);
bd5635a1
RP
971 break;
972
973 case LOC_REF_ARG:
ca603cff 974 printf_filtered ("a reference argument at offset %ld", val);
bd5635a1
RP
975 break;
976
a1c8d76e 977 case LOC_BASEREG:
ca603cff 978 printf_filtered ("a variable at offset %ld from register %s",
a1c8d76e
JK
979 val, reg_names[basereg]);
980 break;
981
982 case LOC_BASEREG_ARG:
ca603cff 983 printf_filtered ("an argument at offset %ld from register %s",
a1c8d76e
JK
984 val, reg_names[basereg]);
985 break;
986
bd5635a1 987 case LOC_TYPEDEF:
ca603cff 988 printf_filtered ("a typedef");
bd5635a1
RP
989 break;
990
991 case LOC_BLOCK:
ca603cff 992 printf_filtered ("a function at address %s",
f73b07c9 993 local_hex_string((unsigned long) BLOCK_START (SYMBOL_BLOCK_VALUE (sym))));
bd5635a1
RP
994 break;
995
31258e4f
JK
996 case LOC_OPTIMIZED_OUT:
997 printf_filtered ("optimized out");
998 break;
999
bd5635a1 1000 default:
ca603cff 1001 printf_filtered ("of unknown (botched) type");
bd5635a1
RP
1002 break;
1003 }
ca603cff 1004 printf_filtered (".\n");
bd5635a1
RP
1005}
1006\f
1007static void
1008x_command (exp, from_tty)
1009 char *exp;
1010 int from_tty;
1011{
1012 struct expression *expr;
1013 struct format_data fmt;
1014 struct cleanup *old_chain;
1015 struct value *val;
1016
1017 fmt.format = last_format;
1018 fmt.size = last_size;
1019 fmt.count = 1;
1020
1021 if (exp && *exp == '/')
1022 {
1023 exp++;
1024 fmt = decode_format (&exp, last_format, last_size);
bd5635a1
RP
1025 }
1026
1027 /* If we have an expression, evaluate it and use it as the address. */
1028
1029 if (exp != 0 && *exp != 0)
1030 {
c4668207 1031 expr = parse_expression (exp);
bd5635a1
RP
1032 /* Cause expression not to be there any more
1033 if this command is repeated with Newline.
1034 But don't clobber a user-defined command's definition. */
1035 if (from_tty)
1036 *exp = 0;
1037 old_chain = make_cleanup (free_current_contents, &expr);
1038 val = evaluate_expression (expr);
3577f9b4
JK
1039 if (TYPE_CODE (VALUE_TYPE (val)) == TYPE_CODE_REF)
1040 val = value_ind (val);
bd5635a1
RP
1041 /* In rvalue contexts, such as this, functions are coerced into
1042 pointers to functions. This makes "x/i main" work. */
1043 if (/* last_format == 'i'
1044 && */ TYPE_CODE (VALUE_TYPE (val)) == TYPE_CODE_FUNC
1045 && VALUE_LVAL (val) == lval_memory)
1046 next_address = VALUE_ADDRESS (val);
1047 else
e1ce8aa5 1048 next_address = value_as_pointer (val);
bd5635a1
RP
1049 do_cleanups (old_chain);
1050 }
1051
1052 do_examine (fmt, next_address);
1053
4d38b5a8
JG
1054 /* If the examine succeeds, we remember its size and format for next time. */
1055 last_size = fmt.size;
1056 last_format = fmt.format;
1057
bd5635a1
RP
1058 /* Set a couple of internal variables if appropriate. */
1059 if (last_examine_value)
1060 {
c4668207
JG
1061 /* Make last address examined available to the user as $_. Use
1062 the correct pointer type. */
bd5635a1 1063 set_internalvar (lookup_internalvar ("_"),
c4668207
JG
1064 value_from_longest (
1065 lookup_pointer_type (VALUE_TYPE (last_examine_value)),
1066 (LONGEST) last_examine_address));
bd5635a1
RP
1067
1068 /* Make contents of last address examined available to the user as $__.*/
1069 set_internalvar (lookup_internalvar ("__"), last_examine_value);
1070 }
1071}
bd5635a1 1072
bd5635a1 1073\f
bd5635a1
RP
1074/* Add an expression to the auto-display chain.
1075 Specify the expression. */
1076
1077static void
1078display_command (exp, from_tty)
1079 char *exp;
1080 int from_tty;
1081{
1082 struct format_data fmt;
1083 register struct expression *expr;
1084 register struct display *new;
1085
1086 if (exp == 0)
1087 {
1088 do_displays ();
1089 return;
1090 }
1091
1092 if (*exp == '/')
1093 {
1094 exp++;
1095 fmt = decode_format (&exp, 0, 0);
1096 if (fmt.size && fmt.format == 0)
1097 fmt.format = 'x';
1098 if (fmt.format == 'i' || fmt.format == 's')
1099 fmt.size = 'b';
1100 }
1101 else
1102 {
1103 fmt.format = 0;
1104 fmt.size = 0;
1105 fmt.count = 0;
1106 }
1107
1108 innermost_block = 0;
c4668207 1109 expr = parse_expression (exp);
bd5635a1
RP
1110
1111 new = (struct display *) xmalloc (sizeof (struct display));
1112
1113 new->exp = expr;
1114 new->block = innermost_block;
1115 new->next = display_chain;
1116 new->number = ++display_number;
1117 new->format = fmt;
1118 new->status = enabled;
1119 display_chain = new;
1120
1121 if (from_tty && target_has_execution)
1122 do_one_display (new);
1123
1124 dont_repeat ();
1125}
1126
1127static void
1128free_display (d)
1129 struct display *d;
1130{
4d38b5a8
JG
1131 free ((PTR)d->exp);
1132 free ((PTR)d);
bd5635a1
RP
1133}
1134
1135/* Clear out the display_chain.
1136 Done when new symtabs are loaded, since this invalidates
1137 the types stored in many expressions. */
1138
1139void
1140clear_displays ()
1141{
1142 register struct display *d;
1143
a8a69e63 1144 while ((d = display_chain) != NULL)
bd5635a1 1145 {
4d38b5a8 1146 free ((PTR)d->exp);
bd5635a1 1147 display_chain = d->next;
4d38b5a8 1148 free ((PTR)d);
bd5635a1
RP
1149 }
1150}
1151
1152/* Delete the auto-display number NUM. */
1153
93fe4e33 1154static void
bd5635a1
RP
1155delete_display (num)
1156 int num;
1157{
1158 register struct display *d1, *d;
1159
1160 if (!display_chain)
1161 error ("No display number %d.", num);
1162
1163 if (display_chain->number == num)
1164 {
1165 d1 = display_chain;
1166 display_chain = d1->next;
1167 free_display (d1);
1168 }
1169 else
1170 for (d = display_chain; ; d = d->next)
1171 {
1172 if (d->next == 0)
1173 error ("No display number %d.", num);
1174 if (d->next->number == num)
1175 {
1176 d1 = d->next;
1177 d->next = d1->next;
1178 free_display (d1);
1179 break;
1180 }
1181 }
1182}
1183
1184/* Delete some values from the auto-display chain.
1185 Specify the element numbers. */
1186
1187static void
4d38b5a8 1188undisplay_command (args, from_tty)
bd5635a1 1189 char *args;
4d38b5a8 1190 int from_tty;
bd5635a1
RP
1191{
1192 register char *p = args;
1193 register char *p1;
1194 register int num;
1195
1196 if (args == 0)
1197 {
1198 if (query ("Delete all auto-display expressions? "))
1199 clear_displays ();
1200 dont_repeat ();
1201 return;
1202 }
1203
1204 while (*p)
1205 {
1206 p1 = p;
1207 while (*p1 >= '0' && *p1 <= '9') p1++;
1208 if (*p1 && *p1 != ' ' && *p1 != '\t')
1209 error ("Arguments must be display numbers.");
1210
1211 num = atoi (p);
1212
1213 delete_display (num);
1214
1215 p = p1;
1216 while (*p == ' ' || *p == '\t') p++;
1217 }
1218 dont_repeat ();
1219}
1220
1221/* Display a single auto-display.
1222 Do nothing if the display cannot be printed in the current context,
1223 or if the display is disabled. */
1224
1225static void
1226do_one_display (d)
1227 struct display *d;
1228{
1229 int within_current_scope;
1230
1231 if (d->status == disabled)
1232 return;
1233
1234 if (d->block)
1235 within_current_scope = contained_in (get_selected_block (), d->block);
1236 else
1237 within_current_scope = 1;
1238 if (!within_current_scope)
1239 return;
1240
1241 current_display_number = d->number;
1242
1243 printf_filtered ("%d: ", d->number);
1244 if (d->format.size)
1245 {
1246 CORE_ADDR addr;
1247
1248 printf_filtered ("x/");
1249 if (d->format.count != 1)
1250 printf_filtered ("%d", d->format.count);
1251 printf_filtered ("%c", d->format.format);
1252 if (d->format.format != 'i' && d->format.format != 's')
1253 printf_filtered ("%c", d->format.size);
1254 printf_filtered (" ");
199b2450 1255 print_expression (d->exp, gdb_stdout);
bd5635a1
RP
1256 if (d->format.count != 1)
1257 printf_filtered ("\n");
1258 else
1259 printf_filtered (" ");
1260
e1ce8aa5 1261 addr = value_as_pointer (evaluate_expression (d->exp));
bd5635a1
RP
1262 if (d->format.format == 'i')
1263 addr = ADDR_BITS_REMOVE (addr);
1264
1265 do_examine (d->format, addr);
1266 }
1267 else
1268 {
1269 if (d->format.format)
1270 printf_filtered ("/%c ", d->format.format);
199b2450 1271 print_expression (d->exp, gdb_stdout);
bd5635a1
RP
1272 printf_filtered (" = ");
1273 print_formatted (evaluate_expression (d->exp),
1274 d->format.format, d->format.size);
1275 printf_filtered ("\n");
1276 }
1277
199b2450 1278 gdb_flush (gdb_stdout);
bd5635a1
RP
1279 current_display_number = -1;
1280}
1281
1282/* Display all of the values on the auto-display chain which can be
1283 evaluated in the current scope. */
1284
1285void
1286do_displays ()
1287{
1288 register struct display *d;
1289
1290 for (d = display_chain; d; d = d->next)
1291 do_one_display (d);
1292}
1293
1294/* Delete the auto-display which we were in the process of displaying.
1295 This is done when there is an error or a signal. */
1296
1297void
1298disable_display (num)
1299 int num;
1300{
1301 register struct display *d;
1302
1303 for (d = display_chain; d; d = d->next)
1304 if (d->number == num)
1305 {
1306 d->status = disabled;
1307 return;
1308 }
199b2450 1309 printf_unfiltered ("No display number %d.\n", num);
bd5635a1
RP
1310}
1311
1312void
1313disable_current_display ()
1314{
1315 if (current_display_number >= 0)
1316 {
1317 disable_display (current_display_number);
199b2450 1318 fprintf_unfiltered (gdb_stderr, "Disabling display %d to avoid infinite recursion.\n",
bd5635a1
RP
1319 current_display_number);
1320 }
1321 current_display_number = -1;
1322}
1323
1324static void
4d38b5a8
JG
1325display_info (ignore, from_tty)
1326 char *ignore;
1327 int from_tty;
bd5635a1
RP
1328{
1329 register struct display *d;
1330
1331 if (!display_chain)
199b2450 1332 printf_unfiltered ("There are no auto-display expressions now.\n");
bd5635a1
RP
1333 else
1334 printf_filtered ("Auto-display expressions now in effect:\n\
1335Num Enb Expression\n");
1336
1337 for (d = display_chain; d; d = d->next)
1338 {
1339 printf_filtered ("%d: %c ", d->number, "ny"[(int)d->status]);
1340 if (d->format.size)
1341 printf_filtered ("/%d%c%c ", d->format.count, d->format.size,
1342 d->format.format);
1343 else if (d->format.format)
1344 printf_filtered ("/%c ", d->format.format);
199b2450 1345 print_expression (d->exp, gdb_stdout);
bd5635a1
RP
1346 if (d->block && !contained_in (get_selected_block (), d->block))
1347 printf_filtered (" (cannot be evaluated in the current context)");
1348 printf_filtered ("\n");
199b2450 1349 gdb_flush (gdb_stdout);
bd5635a1
RP
1350 }
1351}
1352
93fe4e33 1353static void
4d38b5a8 1354enable_display (args, from_tty)
bd5635a1 1355 char *args;
4d38b5a8 1356 int from_tty;
bd5635a1
RP
1357{
1358 register char *p = args;
1359 register char *p1;
1360 register int num;
1361 register struct display *d;
1362
1363 if (p == 0)
1364 {
1365 for (d = display_chain; d; d = d->next)
1366 d->status = enabled;
1367 }
1368 else
1369 while (*p)
1370 {
1371 p1 = p;
1372 while (*p1 >= '0' && *p1 <= '9')
1373 p1++;
1374 if (*p1 && *p1 != ' ' && *p1 != '\t')
1375 error ("Arguments must be display numbers.");
1376
1377 num = atoi (p);
1378
1379 for (d = display_chain; d; d = d->next)
1380 if (d->number == num)
1381 {
1382 d->status = enabled;
1383 goto win;
1384 }
199b2450 1385 printf_unfiltered ("No display number %d.\n", num);
bd5635a1
RP
1386 win:
1387 p = p1;
1388 while (*p == ' ' || *p == '\t')
1389 p++;
1390 }
1391}
1392
e1ce8aa5 1393/* ARGSUSED */
93fe4e33 1394static void
bd5635a1
RP
1395disable_display_command (args, from_tty)
1396 char *args;
1397 int from_tty;
1398{
1399 register char *p = args;
1400 register char *p1;
1401 register struct display *d;
1402
1403 if (p == 0)
1404 {
1405 for (d = display_chain; d; d = d->next)
1406 d->status = disabled;
1407 }
1408 else
1409 while (*p)
1410 {
1411 p1 = p;
1412 while (*p1 >= '0' && *p1 <= '9')
1413 p1++;
1414 if (*p1 && *p1 != ' ' && *p1 != '\t')
1415 error ("Arguments must be display numbers.");
1416
1417 disable_display (atoi (p));
1418
1419 p = p1;
1420 while (*p == ' ' || *p == '\t')
1421 p++;
1422 }
1423}
1424
1425\f
1426/* Print the value in stack frame FRAME of a variable
1427 specified by a struct symbol. */
1428
1429void
1430print_variable_value (var, frame, stream)
1431 struct symbol *var;
1432 FRAME frame;
199b2450 1433 GDB_FILE *stream;
bd5635a1
RP
1434{
1435 value val = read_var_value (var, frame);
1436 value_print (val, stream, 0, Val_pretty_default);
1437}
1438
1439/* Print the arguments of a stack frame, given the function FUNC
1440 running in that frame (as a symbol), the info on the frame,
1441 and the number of args according to the stack frame (or -1 if unknown). */
1442
1443/* References here and elsewhere to "number of args according to the
1444 stack frame" appear in all cases to refer to "number of ints of args
1445 according to the stack frame". At least for VAX, i386, isi. */
1446
1447void
1448print_frame_args (func, fi, num, stream)
1449 struct symbol *func;
1450 struct frame_info *fi;
1451 int num;
199b2450 1452 GDB_FILE *stream;
bd5635a1 1453{
f73b07c9 1454 struct block *b = NULL;
bd5635a1
RP
1455 int nsyms = 0;
1456 int first = 1;
1457 register int i;
1458 register struct symbol *sym;
1459 register value val;
1460 /* Offset of next stack argument beyond the one we have seen that is
1461 at the highest offset.
1462 -1 if we haven't come to a stack argument yet. */
e1ce8aa5 1463 long highest_offset = -1;
bd5635a1
RP
1464 int arg_size;
1465 /* Number of ints of arguments that we have printed so far. */
1466 int args_printed = 0;
1467
1468 if (func)
1469 {
1470 b = SYMBOL_BLOCK_VALUE (func);
1471 nsyms = BLOCK_NSYMS (b);
1472 }
1473
1474 for (i = 0; i < nsyms; i++)
1475 {
1476 QUIT;
1477 sym = BLOCK_SYM (b, i);
1478
c4668207
JG
1479 /* Keep track of the highest stack argument offset seen, and
1480 skip over any kinds of symbols we don't care about. */
bd5635a1
RP
1481
1482 switch (SYMBOL_CLASS (sym)) {
bd5635a1
RP
1483 case LOC_ARG:
1484 case LOC_REF_ARG:
1485 {
e1ce8aa5 1486 long current_offset = SYMBOL_VALUE (sym);
bd5635a1
RP
1487
1488 arg_size = TYPE_LENGTH (SYMBOL_TYPE (sym));
1489
1490 /* Compute address of next argument by adding the size of
1491 this argument and rounding to an int boundary. */
1492 current_offset
1493 = ((current_offset + arg_size + sizeof (int) - 1)
1494 & ~(sizeof (int) - 1));
1495
1496 /* If this is the highest offset seen yet, set highest_offset. */
1497 if (highest_offset == -1
1498 || (current_offset > highest_offset))
1499 highest_offset = current_offset;
1500
1501 /* Add the number of ints we're about to print to args_printed. */
1502 args_printed += (arg_size + sizeof (int) - 1) / sizeof (int);
1503 }
1504
c4668207
JG
1505 /* We care about types of symbols, but don't need to keep track of
1506 stack offsets in them. */
1507 case LOC_REGPARM:
5afa2040 1508 case LOC_REGPARM_ADDR:
c4668207 1509 case LOC_LOCAL_ARG:
a1c8d76e 1510 case LOC_BASEREG_ARG:
bd5635a1 1511 break;
c4668207
JG
1512
1513 /* Other types of symbols we just skip over. */
1514 default:
1515 continue;
bd5635a1
RP
1516 }
1517
31258e4f
JK
1518 /* We have to look up the symbol because arguments can have
1519 two entries (one a parameter, one a local) and the one we
1520 want is the local, which lookup_symbol will find for us.
1521 This includes gcc1 (not gcc2) on the sparc when passing a
1522 small structure and gcc2 when the argument type is float
1523 and it is passed as a double and converted to float by
1524 the prologue (in the latter case the type of the LOC_ARG
1525 symbol is double and the type of the LOC_LOCAL symbol is
314e6bf3 1526 float). */
31258e4f 1527 /* But if the parameter name is null, don't try it.
a8a69e63
FF
1528 Null parameter names occur on the RS/6000, for traceback tables.
1529 FIXME, should we even print them? */
1530
1531 if (*SYMBOL_NAME (sym))
314e6bf3
JG
1532 {
1533 struct symbol *nsym;
1534 nsym = lookup_symbol
1535 (SYMBOL_NAME (sym),
1536 b, VAR_NAMESPACE, (int *)NULL, (struct symtab **)NULL);
1537 if (SYMBOL_CLASS (nsym) == LOC_REGISTER)
1538 {
1539 /* There is a LOC_ARG/LOC_REGISTER pair. This means that
1540 it was passed on the stack and loaded into a register,
1541 or passed in a register and stored in a stack slot.
1542 GDB 3.x used the LOC_ARG; GDB 4.0-4.11 used the LOC_REGISTER.
1543
1544 Reasons for using the LOC_ARG:
1545 (1) because find_saved_registers may be slow for remote
1546 debugging,
1547 (2) because registers are often re-used and stack slots
1548 rarely (never?) are. Therefore using the stack slot is
1549 much less likely to print garbage.
1550
1551 Reasons why we might want to use the LOC_REGISTER:
1552 (1) So that the backtrace prints the same value as
1553 "print foo". I see no compelling reason why this needs
1554 to be the case; having the backtrace print the value which
1555 was passed in, and "print foo" print the value as modified
1556 within the called function, makes perfect sense to me.
1557
1558 Additional note: It might be nice if "info args" displayed
1559 both values.
1560 One more note: There is a case with sparc sturcture passing
1561 where we need to use the LOC_REGISTER, but this is dealt with
1562 by creating a single LOC_REGPARM in symbol reading. */
1563
1564 /* Leave sym (the LOC_ARG) alone. */
1565 ;
1566 }
1567 else
1568 sym = nsym;
1569 }
c4668207 1570
bd5635a1
RP
1571 /* Print the current arg. */
1572 if (! first)
1573 fprintf_filtered (stream, ", ");
1574 wrap_here (" ");
31258e4f
JK
1575 fprintf_symbol_filtered (stream, SYMBOL_SOURCE_NAME (sym),
1576 SYMBOL_LANGUAGE (sym), DMGL_PARAMS | DMGL_ANSI);
bd5635a1
RP
1577 fputs_filtered ("=", stream);
1578
1579 /* Avoid value_print because it will deref ref parameters. We just
1580 want to print their addresses. Print ??? for args whose address
d11c44f1
JG
1581 we do not know. We pass 2 as "recurse" to val_print because our
1582 standard indentation here is 4 spaces, and val_print indents
1583 2 for each recurse. */
bd5635a1
RP
1584 val = read_var_value (sym, FRAME_INFO_ID (fi));
1585 if (val)
1586 val_print (VALUE_TYPE (val), VALUE_CONTENTS (val), VALUE_ADDRESS (val),
d11c44f1 1587 stream, 0, 0, 2, Val_no_prettyprint);
bd5635a1
RP
1588 else
1589 fputs_filtered ("???", stream);
1590 first = 0;
1591 }
1592
1593 /* Don't print nameless args in situations where we don't know
1594 enough about the stack to find them. */
1595 if (num != -1)
1596 {
e1ce8aa5 1597 long start;
bd5635a1
RP
1598
1599 if (highest_offset == -1)
1600 start = FRAME_ARGS_SKIP;
1601 else
1602 start = highest_offset;
1603
7dc15bb7
JG
1604 print_frame_nameless_args (fi, start, num - args_printed,
1605 first, stream);
bd5635a1
RP
1606 }
1607}
1608
1609/* Print nameless args on STREAM.
7dc15bb7 1610 FI is the frameinfo for this frame, START is the offset
bd5635a1
RP
1611 of the first nameless arg, and NUM is the number of nameless args to
1612 print. FIRST is nonzero if this is the first argument (not just
1613 the first nameless arg). */
1614static void
7dc15bb7
JG
1615print_frame_nameless_args (fi, start, num, first, stream)
1616 struct frame_info *fi;
e1ce8aa5 1617 long start;
bd5635a1
RP
1618 int num;
1619 int first;
199b2450 1620 GDB_FILE *stream;
bd5635a1
RP
1621{
1622 int i;
7dc15bb7
JG
1623 CORE_ADDR argsaddr;
1624 long arg_value;
1625
bd5635a1
RP
1626 for (i = 0; i < num; i++)
1627 {
1628 QUIT;
7dc15bb7
JG
1629#ifdef NAMELESS_ARG_VALUE
1630 NAMELESS_ARG_VALUE (fi, start, &arg_value);
1631#else
1632 argsaddr = FRAME_ARGS_ADDRESS (fi);
1633 if (!argsaddr)
1634 return;
1635
1636 arg_value = read_memory_integer (argsaddr + start, sizeof (int));
1637#endif
1638
bd5635a1
RP
1639 if (!first)
1640 fprintf_filtered (stream, ", ");
7dc15bb7
JG
1641
1642#ifdef PRINT_NAMELESS_INTEGER
1643 PRINT_NAMELESS_INTEGER (stream, arg_value);
bd5635a1 1644#else
7dc15bb7
JG
1645#ifdef PRINT_TYPELESS_INTEGER
1646 PRINT_TYPELESS_INTEGER (stream, builtin_type_int, (LONGEST) arg_value);
1647#else
1648 fprintf_filtered (stream, "%d", arg_value);
1649#endif /* PRINT_TYPELESS_INTEGER */
1650#endif /* PRINT_NAMELESS_INTEGER */
bd5635a1
RP
1651 first = 0;
1652 start += sizeof (int);
1653 }
1654}
1655\f
e1ce8aa5 1656/* ARGSUSED */
bd5635a1
RP
1657static void
1658printf_command (arg, from_tty)
1659 char *arg;
1660 int from_tty;
1661{
1662 register char *f;
1663 register char *s = arg;
1664 char *string;
1665 value *val_args;
199b2450
TL
1666 char *substrings;
1667 char *current_substring;
bd5635a1
RP
1668 int nargs = 0;
1669 int allocated_args = 20;
199b2450 1670 struct cleanup *old_cleanups;
bd5635a1
RP
1671
1672 val_args = (value *) xmalloc (allocated_args * sizeof (value));
199b2450 1673 old_cleanups = make_cleanup (free_current_contents, &val_args);
bd5635a1
RP
1674
1675 if (s == 0)
1676 error_no_arg ("format-control string and values to print");
1677
1678 /* Skip white space before format string */
1679 while (*s == ' ' || *s == '\t') s++;
1680
1681 /* A format string should follow, enveloped in double quotes */
1682 if (*s++ != '"')
1683 error ("Bad format string, missing '\"'.");
1684
1685 /* Parse the format-control string and copy it into the string STRING,
1686 processing some kinds of escape sequence. */
1687
1688 f = string = (char *) alloca (strlen (s) + 1);
199b2450 1689
bd5635a1
RP
1690 while (*s != '"')
1691 {
1692 int c = *s++;
1693 switch (c)
1694 {
1695 case '\0':
1696 error ("Bad format string, non-terminated '\"'.");
bd5635a1
RP
1697
1698 case '\\':
1699 switch (c = *s++)
1700 {
1701 case '\\':
1702 *f++ = '\\';
1703 break;
1704 case 'n':
1705 *f++ = '\n';
1706 break;
1707 case 't':
1708 *f++ = '\t';
1709 break;
1710 case 'r':
1711 *f++ = '\r';
1712 break;
1713 case '"':
1714 *f++ = '"';
1715 break;
1716 default:
1717 /* ??? TODO: handle other escape sequences */
1718 error ("Unrecognized \\ escape character in format string.");
1719 }
1720 break;
1721
1722 default:
1723 *f++ = c;
1724 }
1725 }
1726
1727 /* Skip over " and following space and comma. */
1728 s++;
1729 *f++ = '\0';
1730 while (*s == ' ' || *s == '\t') s++;
1731
1732 if (*s != ',' && *s != 0)
1733 error ("Invalid argument syntax");
1734
1735 if (*s == ',') s++;
1736 while (*s == ' ' || *s == '\t') s++;
1737
199b2450
TL
1738 /* Need extra space for the '\0's. Doubling the size is sufficient. */
1739 substrings = alloca (strlen (string) * 2);
1740 current_substring = substrings;
1741
bd5635a1
RP
1742 {
1743 /* Now scan the string for %-specs and see what kinds of args they want.
199b2450 1744 argclass[I] classifies the %-specs so we can give vprintf_unfiltered something
bd5635a1 1745 of the right size. */
199b2450
TL
1746
1747 enum argclass {no_arg, int_arg, string_arg, double_arg, long_long_arg};
bd5635a1 1748 enum argclass *argclass;
199b2450
TL
1749 enum argclass this_argclass;
1750 char *last_arg;
bd5635a1 1751 int nargs_wanted;
bd5635a1
RP
1752 int lcount;
1753 int i;
19bdd57f 1754
bd5635a1
RP
1755 argclass = (enum argclass *) alloca (strlen (s) * sizeof *argclass);
1756 nargs_wanted = 0;
1757 f = string;
199b2450 1758 last_arg = string;
bd5635a1
RP
1759 while (*f)
1760 if (*f++ == '%')
1761 {
1762 lcount = 0;
1763 while (strchr ("0123456789.hlL-+ #", *f))
1764 {
1765 if (*f == 'l' || *f == 'L')
1766 lcount++;
1767 f++;
1768 }
199b2450
TL
1769 switch (*f)
1770 {
1771 case 's':
1772 this_argclass = string_arg;
1773 break;
1774
1775 case 'e':
1776 case 'f':
1777 case 'g':
1778 this_argclass = double_arg;
1779 break;
1780
1781 case '*':
1782 error ("`*' not supported for precision or width in printf");
1783
1784 case 'n':
1785 error ("Format specifier `n' not supported in printf");
1786
1787 case '%':
1788 this_argclass = no_arg;
1789 break;
1790
1791 default:
1792 if (lcount > 1)
1793 this_argclass = long_long_arg;
1794 else
1795 this_argclass = int_arg;
1796 break;
1797 }
bd5635a1 1798 f++;
199b2450
TL
1799 if (this_argclass != no_arg)
1800 {
1801 strncpy (current_substring, last_arg, f - last_arg);
1802 current_substring += f - last_arg;
1803 *current_substring++ = '\0';
1804 last_arg = f;
1805 argclass[nargs_wanted++] = this_argclass;
1806 }
bd5635a1 1807 }
8acf767c 1808
bd5635a1
RP
1809 /* Now, parse all arguments and evaluate them.
1810 Store the VALUEs in VAL_ARGS. */
8acf767c 1811
bd5635a1
RP
1812 while (*s != '\0')
1813 {
1814 char *s1;
1815 if (nargs == allocated_args)
93fe4e33 1816 val_args = (value *) xrealloc ((char *) val_args,
bd5635a1
RP
1817 (allocated_args *= 2)
1818 * sizeof (value));
1819 s1 = s;
1820 val_args[nargs] = parse_to_comma_and_eval (&s1);
1821
1822 /* If format string wants a float, unchecked-convert the value to
1823 floating point of the same size */
1824
1825 if (argclass[nargs] == double_arg)
1826 {
1827 if (TYPE_LENGTH (VALUE_TYPE (val_args[nargs])) == sizeof (float))
1828 VALUE_TYPE (val_args[nargs]) = builtin_type_float;
1829 if (TYPE_LENGTH (VALUE_TYPE (val_args[nargs])) == sizeof (double))
1830 VALUE_TYPE (val_args[nargs]) = builtin_type_double;
1831 }
1832 nargs++;
1833 s = s1;
1834 if (*s == ',')
1835 s++;
1836 }
1837
1838 if (nargs != nargs_wanted)
1839 error ("Wrong number of arguments for specified format-string");
19bdd57f 1840
199b2450
TL
1841 /* FIXME: We should be using vprintf_filtered, but as long as it
1842 has an arbitrary limit that is unacceptable. Correct fix is
1843 for vprintf_filtered to scan down the format string so it knows
1844 how big a buffer it needs (perhaps by putting a vasprintf (see
1845 GNU C library) in libiberty).
1846
1847 But for now, just force out any pending output, so at least the output
1848 appears in the correct order. */
1849 wrap_here ((char *)NULL);
19bdd57f 1850
199b2450
TL
1851 /* Now actually print them. */
1852 current_substring = substrings;
bd5635a1
RP
1853 for (i = 0; i < nargs; i++)
1854 {
199b2450 1855 switch (argclass[i])
bd5635a1 1856 {
199b2450
TL
1857 case string_arg:
1858 {
1859 char *str;
1860 CORE_ADDR tem;
1861 int j;
1862 tem = value_as_pointer (val_args[i]);
1863
1864 /* This is a %s argument. Find the length of the string. */
1865 for (j = 0; ; j++)
1866 {
1867 char c;
1868 QUIT;
1869 read_memory (tem + j, &c, 1);
1870 if (c == 0)
1871 break;
1872 }
1873
1874 /* Copy the string contents into a string inside GDB. */
1875 str = (char *) alloca (j + 1);
1876 read_memory (tem, str, j);
1877 str[j] = 0;
1878
1879 /* Don't use printf_filtered because of arbitrary limit. */
1880 printf_unfiltered (current_substring, str);
1881 }
1882 break;
1883 case double_arg:
1884 {
1885 double val = value_as_double (val_args[i]);
1886 /* Don't use printf_filtered because of arbitrary limit. */
1887 printf_unfiltered (current_substring, val);
1888 break;
1889 }
1890 case long_long_arg:
1891#if defined (CC_HAS_LONG_LONG) && defined (PRINTF_HAS_LONG_LONG)
bd5635a1 1892 {
19bdd57f 1893 long long val = value_as_long (val_args[i]);
199b2450
TL
1894 /* Don't use printf_filtered because of arbitrary limit. */
1895 printf_unfiltered (current_substring, val);
1896 break;
bd5635a1 1897 }
199b2450
TL
1898#else
1899 error ("long long not supported in printf");
bd5635a1 1900#endif
199b2450 1901 case int_arg:
bd5635a1 1902 {
199b2450 1903 /* FIXME: there should be separate int_arg and long_arg. */
19bdd57f 1904 long val = value_as_long (val_args[i]);
199b2450
TL
1905 /* Don't use printf_filtered because of arbitrary limit. */
1906 printf_unfiltered (current_substring, val);
1907 break;
bd5635a1 1908 }
199b2450
TL
1909 default:
1910 error ("internal error in printf_command");
1911 }
1912 /* Skip to the next substring. */
1913 current_substring += strlen (current_substring) + 1;
bd5635a1 1914 }
199b2450
TL
1915 /* Print the portion of the format string after the last argument. */
1916 /* It would be OK to use printf_filtered here. */
1917 printf (last_arg);
bd5635a1 1918 }
199b2450 1919 do_cleanups (old_cleanups);
bd5635a1
RP
1920}
1921\f
bd5635a1
RP
1922/* Dump a specified section of assembly code. With no command line
1923 arguments, this command will dump the assembly code for the
1924 function surrounding the pc value in the selected frame. With one
1925 argument, it will dump the assembly code surrounding that pc value.
1926 Two arguments are interpeted as bounds within which to dump
1927 assembly. */
1928
e1ce8aa5 1929/* ARGSUSED */
bd5635a1
RP
1930static void
1931disassemble_command (arg, from_tty)
1932 char *arg;
1933 int from_tty;
1934{
1935 CORE_ADDR low, high;
f1ed4330 1936 char *name;
bd5635a1
RP
1937 CORE_ADDR pc;
1938 char *space_index;
1939
f1ed4330 1940 name = NULL;
bd5635a1
RP
1941 if (!arg)
1942 {
1943 if (!selected_frame)
1944 error ("No frame selected.\n");
1945
1946 pc = get_frame_pc (selected_frame);
f1ed4330
JK
1947 if (find_pc_partial_function (pc, &name, &low, &high) == 0)
1948 error ("No function contains program counter for selected frame.\n");
bd5635a1
RP
1949 }
1950 else if (!(space_index = (char *) strchr (arg, ' ')))
1951 {
1952 /* One argument. */
1953 pc = parse_and_eval_address (arg);
f1ed4330
JK
1954 if (find_pc_partial_function (pc, &name, &low, &high) == 0)
1955 error ("No function contains specified address.\n");
bd5635a1
RP
1956 }
1957 else
1958 {
1959 /* Two arguments. */
1960 *space_index = '\0';
1961 low = parse_and_eval_address (arg);
1962 high = parse_and_eval_address (space_index + 1);
1963 }
1964
1965 printf_filtered ("Dump of assembler code ");
f1ed4330 1966 if (name != NULL)
bd5635a1 1967 {
bd5635a1
RP
1968 printf_filtered ("for function %s:\n", name);
1969 }
1970 else
f77ad505 1971 {
f73b07c9
JK
1972 printf_filtered ("from %s ", local_hex_string((unsigned long) low));
1973 printf_filtered ("to %s:\n", local_hex_string((unsigned long) high));
f77ad505 1974 }
bd5635a1
RP
1975
1976 /* Dump the specified range. */
1977 for (pc = low; pc < high; )
1978 {
1979 QUIT;
199b2450 1980 print_address (pc, gdb_stdout);
bd5635a1 1981 printf_filtered (":\t");
ca603cff
JK
1982 /* We often wrap here if there are long symbolic names. */
1983 wrap_here (" ");
199b2450 1984 pc += print_insn (pc, gdb_stdout);
bd5635a1
RP
1985 printf_filtered ("\n");
1986 }
1987 printf_filtered ("End of assembler dump.\n");
199b2450 1988 gdb_flush (gdb_stdout);
bd5635a1
RP
1989}
1990
1991\f
1992void
1993_initialize_printcmd ()
1994{
1995 current_display_number = -1;
1996
1997 add_info ("address", address_info,
1998 "Describe where variable VAR is stored.");
1999
2000 add_com ("x", class_vars, x_command,
2001 "Examine memory: x/FMT ADDRESS.\n\
2002ADDRESS is an expression for the memory address to examine.\n\
2003FMT is a repeat count followed by a format letter and a size letter.\n\
2004Format letters are o(octal), x(hex), d(decimal), u(unsigned decimal),\n\
31258e4f 2005 t(binary), f(float), a(address), i(instruction), c(char) and s(string).\n\
bd5635a1 2006Size letters are b(byte), h(halfword), w(word), g(giant, 8 bytes).\n\
bd5635a1
RP
2007The specified number of objects of the specified size are printed\n\
2008according to the format.\n\n\
2009Defaults for format and size letters are those previously used.\n\
2010Default count is 1. Default address is following last thing printed\n\
2011with this command or \"print\".");
2012
2013 add_com ("disassemble", class_vars, disassemble_command,
2014 "Disassemble a specified section of memory.\n\
2015Default is the function surrounding the pc of the selected frame.\n\
2016With a single argument, the function surrounding that address is dumped.\n\
2017Two arguments are taken as a range of memory to dump.");
2018
bd5635a1
RP
2019#if 0
2020 add_com ("whereis", class_vars, whereis_command,
2021 "Print line number and file of definition of variable.");
2022#endif
2023
2024 add_info ("display", display_info,
2025 "Expressions to display when program stops, with code numbers.");
2026
2027 add_cmd ("undisplay", class_vars, undisplay_command,
2028 "Cancel some expressions to be displayed when program stops.\n\
2029Arguments are the code numbers of the expressions to stop displaying.\n\
2030No argument means cancel all automatic-display expressions.\n\
2031\"delete display\" has the same effect as this command.\n\
2032Do \"info display\" to see current list of code numbers.",
2033 &cmdlist);
2034
2035 add_com ("display", class_vars, display_command,
2036 "Print value of expression EXP each time the program stops.\n\
2037/FMT may be used before EXP as in the \"print\" command.\n\
2038/FMT \"i\" or \"s\" or including a size-letter is allowed,\n\
2039as in the \"x\" command, and then EXP is used to get the address to examine\n\
2040and examining is done as in the \"x\" command.\n\n\
2041With no argument, display all currently requested auto-display expressions.\n\
2042Use \"undisplay\" to cancel display requests previously made.");
2043
2044 add_cmd ("display", class_vars, enable_display,
2045 "Enable some expressions to be displayed when program stops.\n\
2046Arguments are the code numbers of the expressions to resume displaying.\n\
2047No argument means enable all automatic-display expressions.\n\
2048Do \"info display\" to see current list of code numbers.", &enablelist);
2049
2050 add_cmd ("display", class_vars, disable_display_command,
2051 "Disable some expressions to be displayed when program stops.\n\
2052Arguments are the code numbers of the expressions to stop displaying.\n\
2053No argument means disable all automatic-display expressions.\n\
2054Do \"info display\" to see current list of code numbers.", &disablelist);
2055
2056 add_cmd ("display", class_vars, undisplay_command,
2057 "Cancel some expressions to be displayed when program stops.\n\
2058Arguments are the code numbers of the expressions to stop displaying.\n\
2059No argument means cancel all automatic-display expressions.\n\
2060Do \"info display\" to see current list of code numbers.", &deletelist);
2061
2062 add_com ("printf", class_vars, printf_command,
2063 "printf \"printf format string\", arg1, arg2, arg3, ..., argn\n\
2064This is useful for formatted output in user-defined commands.");
2065 add_com ("output", class_vars, output_command,
2066 "Like \"print\" but don't put in value history and don't print newline.\n\
2067This is useful in user-defined commands.");
2068
2069 add_prefix_cmd ("set", class_vars, set_command,
45fe3db4
FF
2070"Evaluate expression EXP and assign result to variable VAR, using assignment\n\
2071syntax appropriate for the current language (VAR = EXP or VAR := EXP for\n\
2072example). VAR may be a debugger \"convenience\" variable (names starting\n\
2073with $), a register (a few standard names starting with $), or an actual\n\
2074variable in the program being debugged. EXP is any valid expression.\n\
bd5635a1
RP
2075Use \"set variable\" for variables with names identical to set subcommands.\n\
2076\nWith a subcommand, this command modifies parts of the gdb environment.\n\
2077You can see these environment settings with the \"show\" command.",
2078 &setlist, "set ", 1, &cmdlist);
2079
2080 /* "call" is the same as "set", but handy for dbx users to call fns. */
2081 add_com ("call", class_vars, call_command,
6fe90fc8 2082 "Call a function in the program.\n\
c4668207
JG
2083The argument is the function name and arguments, in the notation of the\n\
2084current working language. The result is printed and saved in the value\n\
2085history, if it is not void.");
bd5635a1
RP
2086
2087 add_cmd ("variable", class_vars, set_command,
45fe3db4
FF
2088"Evaluate expression EXP and assign result to variable VAR, using assignment\n\
2089syntax appropriate for the current language (VAR = EXP or VAR := EXP for\n\
2090example). VAR may be a debugger \"convenience\" variable (names starting\n\
2091with $), a register (a few standard names starting with $), or an actual\n\
2092variable in the program being debugged. EXP is any valid expression.\n\
bd5635a1
RP
2093This may usually be abbreviated to simply \"set\".",
2094 &setlist);
2095
2096 add_com ("print", class_vars, print_command,
2097 concat ("Print value of expression EXP.\n\
2098Variables accessible are those of the lexical environment of the selected\n\
2099stack frame, plus all those whose scope is global or an entire file.\n\
2100\n\
2101$NUM gets previous value number NUM. $ and $$ are the last two values.\n\
2102$$NUM refers to NUM'th value back from the last one.\n\
2103Names starting with $ refer to registers (with the values they would have\n\
2104if the program were to return to the stack frame now selected, restoring\n\
2105all registers saved by frames farther in) or else to debugger\n\
2106\"convenience\" variables (any such name not a known register).\n\
2107Use assignment expressions to give values to convenience variables.\n",
2108 "\n\
2109{TYPE}ADREXP refers to a datum of data type TYPE, located at address ADREXP.\n\
2110@ is a binary operator for treating consecutive data objects\n\
2111anywhere in memory as an array. FOO@NUM gives an array whose first\n\
2112element is FOO, whose second element is stored in the space following\n\
2113where FOO is stored, etc. FOO must be an expression whose value\n\
2114resides in memory.\n",
2115 "\n\
2116EXP may be preceded with /FMT, where FMT is a format letter\n\
7d9884b9 2117but no count or size letter (see \"x\" command).", NULL));
bd5635a1
RP
2118 add_com_alias ("p", "print", class_vars, 1);
2119
2120 add_com ("inspect", class_vars, inspect_command,
2121"Same as \"print\" command, except that if you are running in the epoch\n\
2122environment, the value is printed in its own window.");
f77ad505
FF
2123
2124 add_show_from_set (
2125 add_set_cmd ("max-symbolic-offset", no_class, var_uinteger,
2126 (char *)&max_symbolic_offset,
2127 "Set the largest offset that will be printed in <symbol+1234> form.",
2128 &setprintlist),
2129 &showprintlist);
b7ccd8e0
PS
2130 add_show_from_set (
2131 add_set_cmd ("symbol-filename", no_class, var_boolean,
2132 (char *)&print_symbol_filename,
2133 "Set printing of source filename and line number with <symbol>.",
2134 &setprintlist),
2135 &showprintlist);
199b2450 2136
314e6bf3
JG
2137 add_show_from_set (
2138 add_set_cmd ("fast-symbolic-addr", no_class, var_boolean,
2139 (char *)&fast_symbolic_addr,
2140 "Set fast printing of symbolic addresses (using minimal symbols).",
2141 &setprintlist),
2142 &showprintlist);
2143
199b2450
TL
2144 examine_b_type = init_type (TYPE_CODE_INT, 1, 0, NULL, NULL);
2145 examine_h_type = init_type (TYPE_CODE_INT, 2, 0, NULL, NULL);
2146 examine_w_type = init_type (TYPE_CODE_INT, 4, 0, NULL, NULL);
2147 examine_g_type = init_type (TYPE_CODE_INT, 8, 0, NULL, NULL);
bd5635a1 2148}
This page took 0.244396 seconds and 4 git commands to generate.