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