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