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