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