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