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