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