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