Commit | Line | Data |
---|---|---|
c906108c | 1 | /* Print values for GNU debugger GDB. |
e2ad119d | 2 | |
6aba47ca | 3 | Copyright (C) 1986, 1987, 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, |
9b254dd1 | 4 | 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, |
0fb0cc75 | 5 | 2008, 2009 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 | |
a9762ec7 | 11 | the Free Software Foundation; either version 3 of the License, or |
c5aa993b | 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 | 19 | You should have received a copy of the GNU General Public License |
a9762ec7 | 20 | along with this program. If not, see <http://www.gnu.org/licenses/>. */ |
c906108c SS |
21 | |
22 | #include "defs.h" | |
23 | #include "gdb_string.h" | |
24 | #include "frame.h" | |
25 | #include "symtab.h" | |
26 | #include "gdbtypes.h" | |
27 | #include "value.h" | |
28 | #include "language.h" | |
29 | #include "expression.h" | |
30 | #include "gdbcore.h" | |
31 | #include "gdbcmd.h" | |
32 | #include "target.h" | |
33 | #include "breakpoint.h" | |
34 | #include "demangle.h" | |
35 | #include "valprint.h" | |
36 | #include "annotate.h" | |
c5aa993b JM |
37 | #include "symfile.h" /* for overlay functions */ |
38 | #include "objfiles.h" /* ditto */ | |
c94fdfd0 | 39 | #include "completer.h" /* for completion functions */ |
8b93c638 | 40 | #include "ui-out.h" |
261397f8 | 41 | #include "gdb_assert.h" |
fe898f56 | 42 | #include "block.h" |
92bf2b80 | 43 | #include "disasm.h" |
1a619819 | 44 | #include "dfp.h" |
79a45b7d | 45 | #include "valprint.h" |
a3247a22 PP |
46 | #include "exceptions.h" |
47 | #include "observer.h" | |
48 | #include "solist.h" | |
49 | #include "solib.h" | |
50 | #include "parser-defs.h" | |
6c7a06a3 | 51 | #include "charset.h" |
c906108c | 52 | |
6a83354a AC |
53 | #ifdef TUI |
54 | #include "tui/tui.h" /* For tui_active et.al. */ | |
55 | #endif | |
56 | ||
06be140c | 57 | #if defined(__MINGW32__) && !defined(PRINTF_HAS_LONG_LONG) |
09d71d23 AS |
58 | # define USE_PRINTF_I64 1 |
59 | # define PRINTF_HAS_LONG_LONG | |
60 | #else | |
61 | # define USE_PRINTF_I64 0 | |
62 | #endif | |
63 | ||
c906108c | 64 | extern int asm_demangle; /* Whether to demangle syms in asm printouts */ |
c906108c SS |
65 | |
66 | struct format_data | |
c5aa993b JM |
67 | { |
68 | int count; | |
69 | char format; | |
70 | char size; | |
a6bac58e TT |
71 | |
72 | /* True if the value should be printed raw -- that is, bypassing | |
73 | python-based formatters. */ | |
74 | unsigned char raw; | |
c5aa993b | 75 | }; |
c906108c SS |
76 | |
77 | /* Last specified output format. */ | |
78 | ||
a6bac58e | 79 | static char last_format = 0; |
c906108c SS |
80 | |
81 | /* Last specified examination size. 'b', 'h', 'w' or `q'. */ | |
82 | ||
83 | static char last_size = 'w'; | |
84 | ||
5d3729b5 | 85 | /* Default address to examine next, and associated architecture. */ |
c906108c | 86 | |
5d3729b5 | 87 | static struct gdbarch *next_gdbarch; |
c906108c SS |
88 | static CORE_ADDR next_address; |
89 | ||
a4642986 MR |
90 | /* Number of delay instructions following current disassembled insn. */ |
91 | ||
92 | static int branch_delay_insns; | |
93 | ||
c906108c SS |
94 | /* Last address examined. */ |
95 | ||
96 | static CORE_ADDR last_examine_address; | |
97 | ||
98 | /* Contents of last address examined. | |
99 | This is not valid past the end of the `x' command! */ | |
100 | ||
3d6d86c6 | 101 | static struct value *last_examine_value; |
c906108c SS |
102 | |
103 | /* Largest offset between a symbolic value and an address, that will be | |
104 | printed as `0x1234 <symbol+offset>'. */ | |
105 | ||
106 | static unsigned int max_symbolic_offset = UINT_MAX; | |
920d2a44 AC |
107 | static void |
108 | show_max_symbolic_offset (struct ui_file *file, int from_tty, | |
109 | struct cmd_list_element *c, const char *value) | |
110 | { | |
111 | fprintf_filtered (file, _("\ | |
112 | The largest offset that will be printed in <symbol+1234> form is %s.\n"), | |
113 | value); | |
114 | } | |
c906108c SS |
115 | |
116 | /* Append the source filename and linenumber of the symbol when | |
117 | printing a symbolic value as `<symbol at filename:linenum>' if set. */ | |
118 | static int print_symbol_filename = 0; | |
920d2a44 AC |
119 | static void |
120 | show_print_symbol_filename (struct ui_file *file, int from_tty, | |
121 | struct cmd_list_element *c, const char *value) | |
122 | { | |
123 | fprintf_filtered (file, _("\ | |
124 | Printing of source filename and line number with <symbol> is %s.\n"), | |
125 | value); | |
126 | } | |
c906108c SS |
127 | |
128 | /* Number of auto-display expression currently being displayed. | |
129 | So that we can disable it if we get an error or a signal within it. | |
130 | -1 when not doing one. */ | |
131 | ||
132 | int current_display_number; | |
133 | ||
c906108c | 134 | struct display |
c5aa993b JM |
135 | { |
136 | /* Chain link to next auto-display item. */ | |
137 | struct display *next; | |
fa8a61dc TT |
138 | /* The expression as the user typed it. */ |
139 | char *exp_string; | |
c5aa993b JM |
140 | /* Expression to be evaluated and displayed. */ |
141 | struct expression *exp; | |
142 | /* Item number of this auto-display item. */ | |
143 | int number; | |
144 | /* Display format specified. */ | |
145 | struct format_data format; | |
146 | /* Innermost block required by this expression when evaluated */ | |
147 | struct block *block; | |
148 | /* Status of this display (enabled or disabled) */ | |
b5de0fa7 | 149 | int enabled_p; |
c5aa993b | 150 | }; |
c906108c SS |
151 | |
152 | /* Chain of expressions whose values should be displayed | |
153 | automatically each time the program stops. */ | |
154 | ||
155 | static struct display *display_chain; | |
156 | ||
157 | static int display_number; | |
158 | ||
159 | /* Prototypes for exported functions. */ | |
160 | ||
a14ed312 | 161 | void output_command (char *, int); |
c906108c | 162 | |
a14ed312 | 163 | void _initialize_printcmd (void); |
c906108c SS |
164 | |
165 | /* Prototypes for local functions. */ | |
166 | ||
a14ed312 | 167 | static void do_one_display (struct display *); |
c906108c | 168 | \f |
c5aa993b | 169 | |
c906108c SS |
170 | /* Decode a format specification. *STRING_PTR should point to it. |
171 | OFORMAT and OSIZE are used as defaults for the format and size | |
172 | if none are given in the format specification. | |
173 | If OSIZE is zero, then the size field of the returned value | |
174 | should be set only if a size is explicitly specified by the | |
175 | user. | |
176 | The structure returned describes all the data | |
177 | found in the specification. In addition, *STRING_PTR is advanced | |
178 | past the specification and past all whitespace following it. */ | |
179 | ||
180 | static struct format_data | |
fba45db2 | 181 | decode_format (char **string_ptr, int oformat, int osize) |
c906108c SS |
182 | { |
183 | struct format_data val; | |
52f0bd74 | 184 | char *p = *string_ptr; |
c906108c SS |
185 | |
186 | val.format = '?'; | |
187 | val.size = '?'; | |
188 | val.count = 1; | |
a6bac58e | 189 | val.raw = 0; |
c906108c SS |
190 | |
191 | if (*p >= '0' && *p <= '9') | |
192 | val.count = atoi (p); | |
c5aa993b JM |
193 | while (*p >= '0' && *p <= '9') |
194 | p++; | |
c906108c SS |
195 | |
196 | /* Now process size or format letters that follow. */ | |
197 | ||
198 | while (1) | |
199 | { | |
200 | if (*p == 'b' || *p == 'h' || *p == 'w' || *p == 'g') | |
201 | val.size = *p++; | |
a6bac58e TT |
202 | else if (*p == 'r') |
203 | { | |
204 | val.raw = 1; | |
205 | p++; | |
206 | } | |
c906108c SS |
207 | else if (*p >= 'a' && *p <= 'z') |
208 | val.format = *p++; | |
209 | else | |
210 | break; | |
211 | } | |
212 | ||
c5aa993b JM |
213 | while (*p == ' ' || *p == '\t') |
214 | p++; | |
c906108c SS |
215 | *string_ptr = p; |
216 | ||
217 | /* Set defaults for format and size if not specified. */ | |
218 | if (val.format == '?') | |
219 | { | |
220 | if (val.size == '?') | |
221 | { | |
222 | /* Neither has been specified. */ | |
223 | val.format = oformat; | |
224 | val.size = osize; | |
225 | } | |
226 | else | |
227 | /* If a size is specified, any format makes a reasonable | |
228 | default except 'i'. */ | |
229 | val.format = oformat == 'i' ? 'x' : oformat; | |
230 | } | |
231 | else if (val.size == '?') | |
232 | switch (val.format) | |
233 | { | |
234 | case 'a': | |
5d3729b5 UW |
235 | /* Pick the appropriate size for an address. This is deferred |
236 | until do_examine when we know the actual architecture to use. | |
237 | A special size value of 'a' is used to indicate this case. */ | |
238 | val.size = osize ? 'a' : osize; | |
c906108c SS |
239 | break; |
240 | case 'f': | |
241 | /* Floating point has to be word or giantword. */ | |
242 | if (osize == 'w' || osize == 'g') | |
243 | val.size = osize; | |
244 | else | |
245 | /* Default it to giantword if the last used size is not | |
246 | appropriate. */ | |
247 | val.size = osize ? 'g' : osize; | |
248 | break; | |
249 | case 'c': | |
250 | /* Characters default to one byte. */ | |
251 | val.size = osize ? 'b' : osize; | |
252 | break; | |
253 | default: | |
254 | /* The default is the size most recently specified. */ | |
255 | val.size = osize; | |
256 | } | |
257 | ||
258 | return val; | |
259 | } | |
260 | \f | |
79a45b7d | 261 | /* Print value VAL on stream according to OPTIONS. |
c906108c | 262 | Do not end with a newline. |
c906108c | 263 | SIZE is the letter for the size of datum being printed. |
ea37ba09 DJ |
264 | This is used to pad hex numbers so they line up. SIZE is 0 |
265 | for print / output and set for examine. */ | |
c906108c SS |
266 | |
267 | static void | |
79a45b7d TT |
268 | print_formatted (struct value *val, int size, |
269 | const struct value_print_options *options, | |
fba45db2 | 270 | struct ui_file *stream) |
c906108c | 271 | { |
df407dfe | 272 | struct type *type = check_typedef (value_type (val)); |
c906108c SS |
273 | int len = TYPE_LENGTH (type); |
274 | ||
275 | if (VALUE_LVAL (val) == lval_memory) | |
42ae5230 | 276 | next_address = value_address (val) + len; |
c906108c | 277 | |
ea37ba09 | 278 | if (size) |
c906108c | 279 | { |
79a45b7d | 280 | switch (options->format) |
ea37ba09 DJ |
281 | { |
282 | case 's': | |
6c7a06a3 TT |
283 | { |
284 | struct type *elttype = value_type (val); | |
42ae5230 | 285 | next_address = (value_address (val) |
6c7a06a3 | 286 | + val_print_string (elttype, |
42ae5230 | 287 | value_address (val), -1, |
6c7a06a3 TT |
288 | stream, options)); |
289 | } | |
ea37ba09 | 290 | return; |
c906108c | 291 | |
ea37ba09 DJ |
292 | case 'i': |
293 | /* We often wrap here if there are long symbolic names. */ | |
294 | wrap_here (" "); | |
42ae5230 TT |
295 | next_address = (value_address (val) |
296 | + gdb_print_insn (value_address (val), stream, | |
ea37ba09 DJ |
297 | &branch_delay_insns)); |
298 | return; | |
299 | } | |
c906108c | 300 | } |
ea37ba09 | 301 | |
79a45b7d | 302 | if (options->format == 0 || options->format == 's' |
4e885b20 | 303 | || TYPE_CODE (type) == TYPE_CODE_REF |
ea37ba09 DJ |
304 | || TYPE_CODE (type) == TYPE_CODE_ARRAY |
305 | || TYPE_CODE (type) == TYPE_CODE_STRING | |
306 | || TYPE_CODE (type) == TYPE_CODE_STRUCT | |
307 | || TYPE_CODE (type) == TYPE_CODE_UNION | |
308 | || TYPE_CODE (type) == TYPE_CODE_NAMESPACE) | |
79a45b7d | 309 | value_print (val, stream, options); |
ea37ba09 DJ |
310 | else |
311 | /* User specified format, so don't look to the the type to | |
312 | tell us what to do. */ | |
313 | print_scalar_formatted (value_contents (val), type, | |
79a45b7d | 314 | options, size, stream); |
c906108c SS |
315 | } |
316 | ||
b806fb9a UW |
317 | /* Return builtin floating point type of same length as TYPE. |
318 | If no such type is found, return TYPE itself. */ | |
319 | static struct type * | |
320 | float_type_from_length (struct gdbarch *gdbarch, struct type *type) | |
321 | { | |
322 | const struct builtin_type *builtin = builtin_type (gdbarch); | |
323 | unsigned int len = TYPE_LENGTH (type); | |
324 | ||
325 | if (len == TYPE_LENGTH (builtin->builtin_float)) | |
326 | type = builtin->builtin_float; | |
327 | else if (len == TYPE_LENGTH (builtin->builtin_double)) | |
328 | type = builtin->builtin_double; | |
329 | else if (len == TYPE_LENGTH (builtin->builtin_long_double)) | |
330 | type = builtin->builtin_long_double; | |
331 | ||
332 | return type; | |
333 | } | |
334 | ||
c906108c | 335 | /* Print a scalar of data of type TYPE, pointed to in GDB by VALADDR, |
79a45b7d TT |
336 | according to OPTIONS and SIZE on STREAM. |
337 | Formats s and i are not supported at this level. | |
c906108c SS |
338 | |
339 | This is how the elements of an array or structure are printed | |
340 | with a format. */ | |
341 | ||
342 | void | |
366b1cbf | 343 | print_scalar_formatted (const void *valaddr, struct type *type, |
79a45b7d TT |
344 | const struct value_print_options *options, |
345 | int size, struct ui_file *stream) | |
c906108c | 346 | { |
69feb676 | 347 | struct gdbarch *gdbarch = current_gdbarch; |
81cb7cc9 | 348 | LONGEST val_long = 0; |
c906108c | 349 | unsigned int len = TYPE_LENGTH (type); |
69feb676 | 350 | enum bfd_endian byte_order = gdbarch_byte_order (gdbarch); |
c906108c | 351 | |
ea37ba09 DJ |
352 | /* If we get here with a string format, try again without it. Go |
353 | all the way back to the language printers, which may call us | |
354 | again. */ | |
79a45b7d | 355 | if (options->format == 's') |
ea37ba09 | 356 | { |
79a45b7d TT |
357 | struct value_print_options opts = *options; |
358 | opts.format = 0; | |
359 | opts.deref_ref = 0; | |
360 | val_print (type, valaddr, 0, 0, stream, 0, &opts, | |
d8ca156b | 361 | current_language); |
ea37ba09 DJ |
362 | return; |
363 | } | |
364 | ||
6b9acc27 JJ |
365 | if (len > sizeof(LONGEST) && |
366 | (TYPE_CODE (type) == TYPE_CODE_INT | |
367 | || TYPE_CODE (type) == TYPE_CODE_ENUM)) | |
368 | { | |
79a45b7d | 369 | switch (options->format) |
6b9acc27 JJ |
370 | { |
371 | case 'o': | |
d44e8473 | 372 | print_octal_chars (stream, valaddr, len, byte_order); |
6b9acc27 JJ |
373 | return; |
374 | case 'u': | |
375 | case 'd': | |
d44e8473 | 376 | print_decimal_chars (stream, valaddr, len, byte_order); |
6b9acc27 JJ |
377 | return; |
378 | case 't': | |
d44e8473 | 379 | print_binary_chars (stream, valaddr, len, byte_order); |
6b9acc27 JJ |
380 | return; |
381 | case 'x': | |
d44e8473 | 382 | print_hex_chars (stream, valaddr, len, byte_order); |
6b9acc27 JJ |
383 | return; |
384 | case 'c': | |
6c7a06a3 | 385 | print_char_chars (stream, type, valaddr, len, byte_order); |
6b9acc27 JJ |
386 | return; |
387 | default: | |
388 | break; | |
389 | }; | |
390 | } | |
391 | ||
79a45b7d | 392 | if (options->format != 'f') |
c906108c SS |
393 | val_long = unpack_long (type, valaddr); |
394 | ||
ef166cf4 | 395 | /* If the value is a pointer, and pointers and addresses are not the |
d0aee0c4 | 396 | same, then at this point, the value's length (in target bytes) is |
17a912b6 | 397 | gdbarch_addr_bit/TARGET_CHAR_BIT, not TYPE_LENGTH (type). */ |
ef166cf4 | 398 | if (TYPE_CODE (type) == TYPE_CODE_PTR) |
69feb676 | 399 | len = gdbarch_addr_bit (gdbarch) / TARGET_CHAR_BIT; |
ef166cf4 | 400 | |
c906108c SS |
401 | /* If we are printing it as unsigned, truncate it in case it is actually |
402 | a negative signed value (e.g. "print/u (short)-1" should print 65535 | |
403 | (if shorts are 16 bits) instead of 4294967295). */ | |
1fac167a | 404 | if (options->format != 'd' || TYPE_UNSIGNED (type)) |
c906108c SS |
405 | { |
406 | if (len < sizeof (LONGEST)) | |
407 | val_long &= ((LONGEST) 1 << HOST_CHAR_BIT * len) - 1; | |
408 | } | |
409 | ||
79a45b7d | 410 | switch (options->format) |
c906108c SS |
411 | { |
412 | case 'x': | |
413 | if (!size) | |
414 | { | |
675dcf4f | 415 | /* No size specified, like in print. Print varying # of digits. */ |
c906108c SS |
416 | print_longest (stream, 'x', 1, val_long); |
417 | } | |
418 | else | |
419 | switch (size) | |
420 | { | |
421 | case 'b': | |
422 | case 'h': | |
423 | case 'w': | |
424 | case 'g': | |
425 | print_longest (stream, size, 1, val_long); | |
426 | break; | |
427 | default: | |
8a3fe4f8 | 428 | error (_("Undefined output size \"%c\"."), size); |
c906108c SS |
429 | } |
430 | break; | |
431 | ||
432 | case 'd': | |
433 | print_longest (stream, 'd', 1, val_long); | |
434 | break; | |
435 | ||
436 | case 'u': | |
437 | print_longest (stream, 'u', 0, val_long); | |
438 | break; | |
439 | ||
440 | case 'o': | |
441 | if (val_long) | |
442 | print_longest (stream, 'o', 1, val_long); | |
443 | else | |
444 | fprintf_filtered (stream, "0"); | |
445 | break; | |
446 | ||
447 | case 'a': | |
593de6a6 | 448 | { |
593de6a6 | 449 | CORE_ADDR addr = unpack_pointer (type, valaddr); |
593de6a6 PS |
450 | print_address (addr, stream); |
451 | } | |
c906108c SS |
452 | break; |
453 | ||
454 | case 'c': | |
79a45b7d TT |
455 | { |
456 | struct value_print_options opts = *options; | |
457 | opts.format = 0; | |
69feb676 | 458 | |
79a45b7d | 459 | if (TYPE_UNSIGNED (type)) |
69feb676 UW |
460 | type = builtin_type (gdbarch)->builtin_true_unsigned_char; |
461 | else | |
462 | type = builtin_type (gdbarch)->builtin_true_char; | |
463 | ||
464 | value_print (value_from_longest (type, val_long), stream, &opts); | |
79a45b7d | 465 | } |
c906108c SS |
466 | break; |
467 | ||
468 | case 'f': | |
b806fb9a | 469 | type = float_type_from_length (current_gdbarch, type); |
c906108c SS |
470 | print_floating (valaddr, type, stream); |
471 | break; | |
472 | ||
473 | case 0: | |
675dcf4f MK |
474 | internal_error (__FILE__, __LINE__, |
475 | _("failed internal consistency check")); | |
c906108c SS |
476 | |
477 | case 't': | |
478 | /* Binary; 't' stands for "two". */ | |
479 | { | |
c5aa993b JM |
480 | char bits[8 * (sizeof val_long) + 1]; |
481 | char buf[8 * (sizeof val_long) + 32]; | |
c906108c SS |
482 | char *cp = bits; |
483 | int width; | |
484 | ||
c5aa993b JM |
485 | if (!size) |
486 | width = 8 * (sizeof val_long); | |
487 | else | |
488 | switch (size) | |
c906108c SS |
489 | { |
490 | case 'b': | |
491 | width = 8; | |
492 | break; | |
493 | case 'h': | |
494 | width = 16; | |
495 | break; | |
496 | case 'w': | |
497 | width = 32; | |
498 | break; | |
499 | case 'g': | |
500 | width = 64; | |
501 | break; | |
502 | default: | |
8a3fe4f8 | 503 | error (_("Undefined output size \"%c\"."), size); |
c906108c SS |
504 | } |
505 | ||
c5aa993b JM |
506 | bits[width] = '\0'; |
507 | while (width-- > 0) | |
508 | { | |
509 | bits[width] = (val_long & 1) ? '1' : '0'; | |
510 | val_long >>= 1; | |
511 | } | |
c906108c SS |
512 | if (!size) |
513 | { | |
514 | while (*cp && *cp == '0') | |
515 | cp++; | |
516 | if (*cp == '\0') | |
517 | cp--; | |
518 | } | |
bb599908 | 519 | strcpy (buf, cp); |
306d9ac5 | 520 | fputs_filtered (buf, stream); |
c906108c SS |
521 | } |
522 | break; | |
523 | ||
524 | default: | |
79a45b7d | 525 | error (_("Undefined output format \"%c\"."), options->format); |
c906108c SS |
526 | } |
527 | } | |
528 | ||
529 | /* Specify default address for `x' command. | |
675dcf4f | 530 | The `info lines' command uses this. */ |
c906108c SS |
531 | |
532 | void | |
8b9b9e1a | 533 | set_next_address (struct gdbarch *gdbarch, CORE_ADDR addr) |
c906108c | 534 | { |
8b9b9e1a UW |
535 | struct type *ptr_type = builtin_type (gdbarch)->builtin_data_ptr; |
536 | ||
5d3729b5 | 537 | next_gdbarch = gdbarch; |
c906108c SS |
538 | next_address = addr; |
539 | ||
540 | /* Make address available to the user as $_. */ | |
541 | set_internalvar (lookup_internalvar ("_"), | |
8b9b9e1a | 542 | value_from_pointer (ptr_type, addr)); |
c906108c SS |
543 | } |
544 | ||
545 | /* Optionally print address ADDR symbolically as <SYMBOL+OFFSET> on STREAM, | |
546 | after LEADIN. Print nothing if no symbolic name is found nearby. | |
547 | Optionally also print source file and line number, if available. | |
548 | DO_DEMANGLE controls whether to print a symbol in its native "raw" form, | |
549 | or to interpret it as a possible C++ name and convert it back to source | |
550 | form. However note that DO_DEMANGLE can be overridden by the specific | |
551 | settings of the demangle and asm_demangle variables. */ | |
552 | ||
553 | void | |
675dcf4f MK |
554 | print_address_symbolic (CORE_ADDR addr, struct ui_file *stream, |
555 | int do_demangle, char *leadin) | |
dfcd3bfb JM |
556 | { |
557 | char *name = NULL; | |
558 | char *filename = NULL; | |
559 | int unmapped = 0; | |
560 | int offset = 0; | |
561 | int line = 0; | |
562 | ||
675dcf4f | 563 | /* Throw away both name and filename. */ |
2f9429ae AC |
564 | struct cleanup *cleanup_chain = make_cleanup (free_current_contents, &name); |
565 | make_cleanup (free_current_contents, &filename); | |
dfcd3bfb | 566 | |
675dcf4f MK |
567 | if (build_address_symbolic (addr, do_demangle, &name, &offset, |
568 | &filename, &line, &unmapped)) | |
2f9429ae AC |
569 | { |
570 | do_cleanups (cleanup_chain); | |
571 | return; | |
572 | } | |
dfcd3bfb JM |
573 | |
574 | fputs_filtered (leadin, stream); | |
575 | if (unmapped) | |
576 | fputs_filtered ("<*", stream); | |
577 | else | |
578 | fputs_filtered ("<", stream); | |
579 | fputs_filtered (name, stream); | |
580 | if (offset != 0) | |
581 | fprintf_filtered (stream, "+%u", (unsigned int) offset); | |
582 | ||
583 | /* Append source filename and line number if desired. Give specific | |
584 | line # of this addr, if we have it; else line # of the nearest symbol. */ | |
585 | if (print_symbol_filename && filename != NULL) | |
586 | { | |
587 | if (line != -1) | |
588 | fprintf_filtered (stream, " at %s:%d", filename, line); | |
589 | else | |
590 | fprintf_filtered (stream, " in %s", filename); | |
591 | } | |
592 | if (unmapped) | |
593 | fputs_filtered ("*>", stream); | |
594 | else | |
595 | fputs_filtered (">", stream); | |
596 | ||
597 | do_cleanups (cleanup_chain); | |
598 | } | |
599 | ||
600 | /* Given an address ADDR return all the elements needed to print the | |
601 | address in a symbolic form. NAME can be mangled or not depending | |
602 | on DO_DEMANGLE (and also on the asm_demangle global variable, | |
603 | manipulated via ''set print asm-demangle''). Return 0 in case of | |
604 | success, when all the info in the OUT paramters is valid. Return 1 | |
605 | otherwise. */ | |
606 | int | |
607 | build_address_symbolic (CORE_ADDR addr, /* IN */ | |
608 | int do_demangle, /* IN */ | |
609 | char **name, /* OUT */ | |
610 | int *offset, /* OUT */ | |
611 | char **filename, /* OUT */ | |
612 | int *line, /* OUT */ | |
613 | int *unmapped) /* OUT */ | |
c906108c SS |
614 | { |
615 | struct minimal_symbol *msymbol; | |
616 | struct symbol *symbol; | |
c906108c | 617 | CORE_ADDR name_location = 0; |
714835d5 | 618 | struct obj_section *section = NULL; |
dfcd3bfb JM |
619 | char *name_temp = ""; |
620 | ||
89c83b10 | 621 | /* Let's say it is mapped (not unmapped). */ |
dfcd3bfb | 622 | *unmapped = 0; |
c906108c | 623 | |
dfcd3bfb | 624 | /* Determine if the address is in an overlay, and whether it is |
675dcf4f | 625 | mapped. */ |
c906108c SS |
626 | if (overlay_debugging) |
627 | { | |
628 | section = find_pc_overlay (addr); | |
629 | if (pc_in_unmapped_range (addr, section)) | |
630 | { | |
dfcd3bfb | 631 | *unmapped = 1; |
c906108c SS |
632 | addr = overlay_mapped_address (addr, section); |
633 | } | |
634 | } | |
635 | ||
c906108c SS |
636 | /* First try to find the address in the symbol table, then |
637 | in the minsyms. Take the closest one. */ | |
638 | ||
639 | /* This is defective in the sense that it only finds text symbols. So | |
640 | really this is kind of pointless--we should make sure that the | |
641 | minimal symbols have everything we need (by changing that we could | |
642 | save some memory, but for many debug format--ELF/DWARF or | |
643 | anything/stabs--it would be inconvenient to eliminate those minimal | |
644 | symbols anyway). */ | |
645 | msymbol = lookup_minimal_symbol_by_pc_section (addr, section); | |
646 | symbol = find_pc_sect_function (addr, section); | |
647 | ||
648 | if (symbol) | |
649 | { | |
650 | name_location = BLOCK_START (SYMBOL_BLOCK_VALUE (symbol)); | |
406fc7fb | 651 | if (do_demangle || asm_demangle) |
de5ad195 | 652 | name_temp = SYMBOL_PRINT_NAME (symbol); |
c906108c | 653 | else |
3567439c | 654 | name_temp = SYMBOL_LINKAGE_NAME (symbol); |
c906108c SS |
655 | } |
656 | ||
657 | if (msymbol != NULL) | |
658 | { | |
659 | if (SYMBOL_VALUE_ADDRESS (msymbol) > name_location || symbol == NULL) | |
660 | { | |
661 | /* The msymbol is closer to the address than the symbol; | |
662 | use the msymbol instead. */ | |
663 | symbol = 0; | |
c906108c | 664 | name_location = SYMBOL_VALUE_ADDRESS (msymbol); |
406fc7fb | 665 | if (do_demangle || asm_demangle) |
de5ad195 | 666 | name_temp = SYMBOL_PRINT_NAME (msymbol); |
c906108c | 667 | else |
3567439c | 668 | name_temp = SYMBOL_LINKAGE_NAME (msymbol); |
c906108c SS |
669 | } |
670 | } | |
671 | if (symbol == NULL && msymbol == NULL) | |
dfcd3bfb | 672 | return 1; |
c906108c | 673 | |
c906108c SS |
674 | /* If the nearest symbol is too far away, don't print anything symbolic. */ |
675 | ||
676 | /* For when CORE_ADDR is larger than unsigned int, we do math in | |
677 | CORE_ADDR. But when we detect unsigned wraparound in the | |
678 | CORE_ADDR math, we ignore this test and print the offset, | |
679 | because addr+max_symbolic_offset has wrapped through the end | |
680 | of the address space back to the beginning, giving bogus comparison. */ | |
681 | if (addr > name_location + max_symbolic_offset | |
682 | && name_location + max_symbolic_offset > name_location) | |
dfcd3bfb | 683 | return 1; |
c906108c | 684 | |
dfcd3bfb JM |
685 | *offset = addr - name_location; |
686 | ||
687 | *name = xstrdup (name_temp); | |
c906108c | 688 | |
c906108c SS |
689 | if (print_symbol_filename) |
690 | { | |
691 | struct symtab_and_line sal; | |
692 | ||
693 | sal = find_pc_sect_line (addr, section, 0); | |
694 | ||
695 | if (sal.symtab) | |
dfcd3bfb JM |
696 | { |
697 | *filename = xstrdup (sal.symtab->filename); | |
698 | *line = sal.line; | |
699 | } | |
c906108c | 700 | } |
dfcd3bfb | 701 | return 0; |
c906108c SS |
702 | } |
703 | ||
c906108c SS |
704 | |
705 | /* Print address ADDR symbolically on STREAM. | |
706 | First print it as a number. Then perhaps print | |
707 | <SYMBOL + OFFSET> after the number. */ | |
708 | ||
709 | void | |
fba45db2 | 710 | print_address (CORE_ADDR addr, struct ui_file *stream) |
c906108c | 711 | { |
ed49a04f | 712 | fputs_filtered (paddress (addr), stream); |
c906108c SS |
713 | print_address_symbolic (addr, stream, asm_demangle, " "); |
714 | } | |
715 | ||
716 | /* Print address ADDR symbolically on STREAM. Parameter DEMANGLE | |
717 | controls whether to print the symbolic name "raw" or demangled. | |
718 | Global setting "addressprint" controls whether to print hex address | |
719 | or not. */ | |
720 | ||
721 | void | |
675dcf4f MK |
722 | print_address_demangle (CORE_ADDR addr, struct ui_file *stream, |
723 | int do_demangle) | |
c906108c | 724 | { |
79a45b7d TT |
725 | struct value_print_options opts; |
726 | get_user_print_options (&opts); | |
c906108c SS |
727 | if (addr == 0) |
728 | { | |
729 | fprintf_filtered (stream, "0"); | |
730 | } | |
79a45b7d | 731 | else if (opts.addressprint) |
c906108c | 732 | { |
ed49a04f | 733 | fputs_filtered (paddress (addr), stream); |
c906108c SS |
734 | print_address_symbolic (addr, stream, do_demangle, " "); |
735 | } | |
736 | else | |
737 | { | |
738 | print_address_symbolic (addr, stream, do_demangle, ""); | |
739 | } | |
740 | } | |
741 | \f | |
742 | ||
c906108c SS |
743 | /* Examine data at address ADDR in format FMT. |
744 | Fetch it from memory and print on gdb_stdout. */ | |
745 | ||
746 | static void | |
5d3729b5 | 747 | do_examine (struct format_data fmt, struct gdbarch *gdbarch, CORE_ADDR addr) |
c906108c | 748 | { |
52f0bd74 AC |
749 | char format = 0; |
750 | char size; | |
751 | int count = 1; | |
c906108c | 752 | struct type *val_type = NULL; |
52f0bd74 AC |
753 | int i; |
754 | int maxelts; | |
79a45b7d | 755 | struct value_print_options opts; |
c906108c SS |
756 | |
757 | format = fmt.format; | |
758 | size = fmt.size; | |
759 | count = fmt.count; | |
5d3729b5 | 760 | next_gdbarch = gdbarch; |
c906108c | 761 | next_address = addr; |
c906108c SS |
762 | |
763 | /* String or instruction format implies fetch single bytes | |
764 | regardless of the specified size. */ | |
765 | if (format == 's' || format == 'i') | |
766 | size = 'b'; | |
767 | ||
5d3729b5 UW |
768 | if (size == 'a') |
769 | { | |
770 | /* Pick the appropriate size for an address. */ | |
771 | if (gdbarch_ptr_bit (next_gdbarch) == 64) | |
772 | size = 'g'; | |
773 | else if (gdbarch_ptr_bit (next_gdbarch) == 32) | |
774 | size = 'w'; | |
775 | else if (gdbarch_ptr_bit (next_gdbarch) == 16) | |
776 | size = 'h'; | |
777 | else | |
778 | /* Bad value for gdbarch_ptr_bit. */ | |
779 | internal_error (__FILE__, __LINE__, | |
780 | _("failed internal consistency check")); | |
781 | } | |
782 | ||
783 | if (size == 'b') | |
784 | val_type = builtin_type_int8; | |
c906108c | 785 | else if (size == 'h') |
5d3729b5 | 786 | val_type = builtin_type_int16; |
c906108c | 787 | else if (size == 'w') |
5d3729b5 | 788 | val_type = builtin_type_int32; |
c906108c | 789 | else if (size == 'g') |
5d3729b5 | 790 | val_type = builtin_type_int64; |
c906108c SS |
791 | |
792 | maxelts = 8; | |
793 | if (size == 'w') | |
794 | maxelts = 4; | |
795 | if (size == 'g') | |
796 | maxelts = 2; | |
797 | if (format == 's' || format == 'i') | |
798 | maxelts = 1; | |
799 | ||
79a45b7d TT |
800 | get_formatted_print_options (&opts, format); |
801 | ||
c906108c SS |
802 | /* Print as many objects as specified in COUNT, at most maxelts per line, |
803 | with the address of the next one at the start of each line. */ | |
804 | ||
805 | while (count > 0) | |
806 | { | |
807 | QUIT; | |
808 | print_address (next_address, gdb_stdout); | |
809 | printf_filtered (":"); | |
810 | for (i = maxelts; | |
811 | i > 0 && count > 0; | |
812 | i--, count--) | |
813 | { | |
814 | printf_filtered ("\t"); | |
815 | /* Note that print_formatted sets next_address for the next | |
816 | object. */ | |
817 | last_examine_address = next_address; | |
818 | ||
819 | if (last_examine_value) | |
820 | value_free (last_examine_value); | |
821 | ||
822 | /* The value to be displayed is not fetched greedily. | |
5d51a2db MR |
823 | Instead, to avoid the possibility of a fetched value not |
824 | being used, its retrieval is delayed until the print code | |
c5aa993b JM |
825 | uses it. When examining an instruction stream, the |
826 | disassembler will perform its own memory fetch using just | |
827 | the address stored in LAST_EXAMINE_VALUE. FIXME: Should | |
828 | the disassembler be modified so that LAST_EXAMINE_VALUE | |
829 | is left with the byte sequence from the last complete | |
830 | instruction fetched from memory? */ | |
00a4c844 | 831 | last_examine_value = value_at_lazy (val_type, next_address); |
c906108c SS |
832 | |
833 | if (last_examine_value) | |
834 | release_value (last_examine_value); | |
835 | ||
79a45b7d | 836 | print_formatted (last_examine_value, size, &opts, gdb_stdout); |
a4642986 MR |
837 | |
838 | /* Display any branch delay slots following the final insn. */ | |
839 | if (format == 'i' && count == 1) | |
840 | count += branch_delay_insns; | |
c906108c SS |
841 | } |
842 | printf_filtered ("\n"); | |
843 | gdb_flush (gdb_stdout); | |
844 | } | |
845 | } | |
846 | \f | |
847 | static void | |
fba45db2 | 848 | validate_format (struct format_data fmt, char *cmdname) |
c906108c SS |
849 | { |
850 | if (fmt.size != 0) | |
8a3fe4f8 | 851 | error (_("Size letters are meaningless in \"%s\" command."), cmdname); |
c906108c | 852 | if (fmt.count != 1) |
8a3fe4f8 | 853 | error (_("Item count other than 1 is meaningless in \"%s\" command."), |
c906108c | 854 | cmdname); |
ea37ba09 | 855 | if (fmt.format == 'i') |
8a3fe4f8 | 856 | error (_("Format letter \"%c\" is meaningless in \"%s\" command."), |
c906108c SS |
857 | fmt.format, cmdname); |
858 | } | |
859 | ||
675dcf4f | 860 | /* Evaluate string EXP as an expression in the current language and |
c5aa993b | 861 | print the resulting value. EXP may contain a format specifier as the |
675dcf4f | 862 | first argument ("/x myvar" for example, to print myvar in hex). */ |
c906108c SS |
863 | |
864 | static void | |
fba45db2 | 865 | print_command_1 (char *exp, int inspect, int voidprint) |
c906108c SS |
866 | { |
867 | struct expression *expr; | |
52f0bd74 AC |
868 | struct cleanup *old_chain = 0; |
869 | char format = 0; | |
3d6d86c6 | 870 | struct value *val; |
c906108c SS |
871 | struct format_data fmt; |
872 | int cleanup = 0; | |
873 | ||
c906108c SS |
874 | if (exp && *exp == '/') |
875 | { | |
876 | exp++; | |
877 | fmt = decode_format (&exp, last_format, 0); | |
878 | validate_format (fmt, "print"); | |
879 | last_format = format = fmt.format; | |
880 | } | |
881 | else | |
882 | { | |
883 | fmt.count = 1; | |
884 | fmt.format = 0; | |
885 | fmt.size = 0; | |
a6bac58e | 886 | fmt.raw = 0; |
c906108c SS |
887 | } |
888 | ||
889 | if (exp && *exp) | |
890 | { | |
c906108c SS |
891 | struct type *type; |
892 | expr = parse_expression (exp); | |
c13c43fd | 893 | old_chain = make_cleanup (free_current_contents, &expr); |
c906108c SS |
894 | cleanup = 1; |
895 | val = evaluate_expression (expr); | |
c906108c SS |
896 | } |
897 | else | |
898 | val = access_value_history (0); | |
899 | ||
df407dfe AC |
900 | if (voidprint || (val && value_type (val) && |
901 | TYPE_CODE (value_type (val)) != TYPE_CODE_VOID)) | |
c906108c | 902 | { |
79a45b7d | 903 | struct value_print_options opts; |
c906108c SS |
904 | int histindex = record_latest_value (val); |
905 | ||
906 | if (histindex >= 0) | |
df407dfe | 907 | annotate_value_history_begin (histindex, value_type (val)); |
c906108c | 908 | else |
df407dfe | 909 | annotate_value_begin (value_type (val)); |
c906108c SS |
910 | |
911 | if (inspect) | |
675dcf4f MK |
912 | printf_unfiltered ("\031(gdb-makebuffer \"%s\" %d '(\"", |
913 | exp, histindex); | |
c5aa993b JM |
914 | else if (histindex >= 0) |
915 | printf_filtered ("$%d = ", histindex); | |
c906108c SS |
916 | |
917 | if (histindex >= 0) | |
918 | annotate_value_history_value (); | |
919 | ||
79a45b7d TT |
920 | get_formatted_print_options (&opts, format); |
921 | opts.inspect_it = inspect; | |
a6bac58e | 922 | opts.raw = fmt.raw; |
79a45b7d TT |
923 | |
924 | print_formatted (val, fmt.size, &opts, gdb_stdout); | |
c906108c SS |
925 | printf_filtered ("\n"); |
926 | ||
927 | if (histindex >= 0) | |
928 | annotate_value_history_end (); | |
929 | else | |
930 | annotate_value_end (); | |
931 | ||
932 | if (inspect) | |
c5aa993b | 933 | printf_unfiltered ("\") )\030"); |
c906108c SS |
934 | } |
935 | ||
936 | if (cleanup) | |
937 | do_cleanups (old_chain); | |
c906108c SS |
938 | } |
939 | ||
c906108c | 940 | static void |
fba45db2 | 941 | print_command (char *exp, int from_tty) |
c906108c SS |
942 | { |
943 | print_command_1 (exp, 0, 1); | |
944 | } | |
945 | ||
675dcf4f | 946 | /* Same as print, except in epoch, it gets its own window. */ |
c906108c | 947 | static void |
fba45db2 | 948 | inspect_command (char *exp, int from_tty) |
c906108c SS |
949 | { |
950 | extern int epoch_interface; | |
951 | ||
952 | print_command_1 (exp, epoch_interface, 1); | |
953 | } | |
954 | ||
675dcf4f | 955 | /* Same as print, except it doesn't print void results. */ |
c906108c | 956 | static void |
fba45db2 | 957 | call_command (char *exp, int from_tty) |
c906108c SS |
958 | { |
959 | print_command_1 (exp, 0, 0); | |
960 | } | |
961 | ||
c906108c | 962 | void |
fba45db2 | 963 | output_command (char *exp, int from_tty) |
c906108c SS |
964 | { |
965 | struct expression *expr; | |
52f0bd74 AC |
966 | struct cleanup *old_chain; |
967 | char format = 0; | |
3d6d86c6 | 968 | struct value *val; |
c906108c | 969 | struct format_data fmt; |
79a45b7d | 970 | struct value_print_options opts; |
c906108c | 971 | |
777ea8f1 | 972 | fmt.size = 0; |
a6bac58e | 973 | fmt.raw = 0; |
777ea8f1 | 974 | |
c906108c SS |
975 | if (exp && *exp == '/') |
976 | { | |
977 | exp++; | |
978 | fmt = decode_format (&exp, 0, 0); | |
979 | validate_format (fmt, "output"); | |
980 | format = fmt.format; | |
981 | } | |
982 | ||
983 | expr = parse_expression (exp); | |
c13c43fd | 984 | old_chain = make_cleanup (free_current_contents, &expr); |
c906108c SS |
985 | |
986 | val = evaluate_expression (expr); | |
987 | ||
df407dfe | 988 | annotate_value_begin (value_type (val)); |
c906108c | 989 | |
79a45b7d | 990 | get_formatted_print_options (&opts, format); |
a6bac58e | 991 | opts.raw = fmt.raw; |
79a45b7d | 992 | print_formatted (val, fmt.size, &opts, gdb_stdout); |
c906108c SS |
993 | |
994 | annotate_value_end (); | |
995 | ||
2acceee2 JM |
996 | wrap_here (""); |
997 | gdb_flush (gdb_stdout); | |
998 | ||
c906108c SS |
999 | do_cleanups (old_chain); |
1000 | } | |
1001 | ||
c906108c | 1002 | static void |
fba45db2 | 1003 | set_command (char *exp, int from_tty) |
c906108c SS |
1004 | { |
1005 | struct expression *expr = parse_expression (exp); | |
52f0bd74 | 1006 | struct cleanup *old_chain = |
c13c43fd | 1007 | make_cleanup (free_current_contents, &expr); |
c906108c SS |
1008 | evaluate_expression (expr); |
1009 | do_cleanups (old_chain); | |
1010 | } | |
1011 | ||
c906108c | 1012 | static void |
fba45db2 | 1013 | sym_info (char *arg, int from_tty) |
c906108c SS |
1014 | { |
1015 | struct minimal_symbol *msymbol; | |
c5aa993b JM |
1016 | struct objfile *objfile; |
1017 | struct obj_section *osect; | |
c5aa993b JM |
1018 | CORE_ADDR addr, sect_addr; |
1019 | int matches = 0; | |
1020 | unsigned int offset; | |
c906108c SS |
1021 | |
1022 | if (!arg) | |
e2e0b3e5 | 1023 | error_no_arg (_("address")); |
c906108c SS |
1024 | |
1025 | addr = parse_and_eval_address (arg); | |
1026 | ALL_OBJSECTIONS (objfile, osect) | |
c5aa993b | 1027 | { |
94277a38 DJ |
1028 | /* Only process each object file once, even if there's a separate |
1029 | debug file. */ | |
1030 | if (objfile->separate_debug_objfile_backlink) | |
1031 | continue; | |
1032 | ||
714835d5 | 1033 | sect_addr = overlay_mapped_address (addr, osect); |
c906108c | 1034 | |
f1f6aadf PA |
1035 | if (obj_section_addr (osect) <= sect_addr |
1036 | && sect_addr < obj_section_endaddr (osect) | |
714835d5 | 1037 | && (msymbol = lookup_minimal_symbol_by_pc_section (sect_addr, osect))) |
c5aa993b | 1038 | { |
c14c28ba | 1039 | const char *obj_name, *mapped, *sec_name, *msym_name; |
e2fd701e DE |
1040 | char *loc_string; |
1041 | struct cleanup *old_chain; | |
c14c28ba | 1042 | |
c5aa993b JM |
1043 | matches = 1; |
1044 | offset = sect_addr - SYMBOL_VALUE_ADDRESS (msymbol); | |
c14c28ba PP |
1045 | mapped = section_is_mapped (osect) ? _("mapped") : _("unmapped"); |
1046 | sec_name = osect->the_bfd_section->name; | |
1047 | msym_name = SYMBOL_PRINT_NAME (msymbol); | |
1048 | ||
e2fd701e DE |
1049 | /* Don't print the offset if it is zero. |
1050 | We assume there's no need to handle i18n of "sym + offset". */ | |
1051 | if (offset) | |
549ba0f8 | 1052 | loc_string = xstrprintf ("%s + %u", msym_name, offset); |
e2fd701e | 1053 | else |
549ba0f8 | 1054 | loc_string = xstrprintf ("%s", msym_name); |
e2fd701e DE |
1055 | |
1056 | /* Use a cleanup to free loc_string in case the user quits | |
1057 | a pagination request inside printf_filtered. */ | |
1058 | old_chain = make_cleanup (xfree, loc_string); | |
1059 | ||
c14c28ba PP |
1060 | gdb_assert (osect->objfile && osect->objfile->name); |
1061 | obj_name = osect->objfile->name; | |
1062 | ||
1063 | if (MULTI_OBJFILE_P ()) | |
1064 | if (pc_in_unmapped_range (addr, osect)) | |
1065 | if (section_is_overlay (osect)) | |
e2fd701e | 1066 | printf_filtered (_("%s in load address range of " |
c14c28ba | 1067 | "%s overlay section %s of %s\n"), |
e2fd701e | 1068 | loc_string, mapped, sec_name, obj_name); |
c14c28ba | 1069 | else |
e2fd701e | 1070 | printf_filtered (_("%s in load address range of " |
c14c28ba | 1071 | "section %s of %s\n"), |
e2fd701e | 1072 | loc_string, sec_name, obj_name); |
c14c28ba PP |
1073 | else |
1074 | if (section_is_overlay (osect)) | |
e2fd701e DE |
1075 | printf_filtered (_("%s in %s overlay section %s of %s\n"), |
1076 | loc_string, mapped, sec_name, obj_name); | |
c14c28ba | 1077 | else |
e2fd701e DE |
1078 | printf_filtered (_("%s in section %s of %s\n"), |
1079 | loc_string, sec_name, obj_name); | |
c5aa993b | 1080 | else |
c14c28ba PP |
1081 | if (pc_in_unmapped_range (addr, osect)) |
1082 | if (section_is_overlay (osect)) | |
e2fd701e | 1083 | printf_filtered (_("%s in load address range of %s overlay " |
c14c28ba | 1084 | "section %s\n"), |
e2fd701e | 1085 | loc_string, mapped, sec_name); |
c14c28ba | 1086 | else |
e2fd701e DE |
1087 | printf_filtered (_("%s in load address range of section %s\n"), |
1088 | loc_string, sec_name); | |
c14c28ba PP |
1089 | else |
1090 | if (section_is_overlay (osect)) | |
e2fd701e DE |
1091 | printf_filtered (_("%s in %s overlay section %s\n"), |
1092 | loc_string, mapped, sec_name); | |
c14c28ba | 1093 | else |
e2fd701e DE |
1094 | printf_filtered (_("%s in section %s\n"), |
1095 | loc_string, sec_name); | |
1096 | ||
1097 | do_cleanups (old_chain); | |
c5aa993b JM |
1098 | } |
1099 | } | |
c906108c | 1100 | if (matches == 0) |
a3f17187 | 1101 | printf_filtered (_("No symbol matches %s.\n"), arg); |
c906108c SS |
1102 | } |
1103 | ||
c906108c | 1104 | static void |
fba45db2 | 1105 | address_info (char *exp, int from_tty) |
c906108c | 1106 | { |
768a979c UW |
1107 | struct gdbarch *gdbarch; |
1108 | int regno; | |
52f0bd74 AC |
1109 | struct symbol *sym; |
1110 | struct minimal_symbol *msymbol; | |
1111 | long val; | |
714835d5 | 1112 | struct obj_section *section; |
c906108c SS |
1113 | CORE_ADDR load_addr; |
1114 | int is_a_field_of_this; /* C++: lookup_symbol sets this to nonzero | |
1115 | if exp is a field of `this'. */ | |
1116 | ||
1117 | if (exp == 0) | |
8a3fe4f8 | 1118 | error (_("Argument required.")); |
c906108c | 1119 | |
176620f1 | 1120 | sym = lookup_symbol (exp, get_selected_block (0), VAR_DOMAIN, |
2570f2b7 | 1121 | &is_a_field_of_this); |
c906108c SS |
1122 | if (sym == NULL) |
1123 | { | |
1124 | if (is_a_field_of_this) | |
1125 | { | |
1126 | printf_filtered ("Symbol \""); | |
1127 | fprintf_symbol_filtered (gdb_stdout, exp, | |
1128 | current_language->la_language, DMGL_ANSI); | |
e2b23ee9 AF |
1129 | printf_filtered ("\" is a field of the local class variable "); |
1130 | if (current_language->la_language == language_objc) | |
2625d86c | 1131 | printf_filtered ("`self'\n"); /* ObjC equivalent of "this" */ |
e2b23ee9 | 1132 | else |
2625d86c | 1133 | printf_filtered ("`this'\n"); |
c906108c SS |
1134 | return; |
1135 | } | |
1136 | ||
1137 | msymbol = lookup_minimal_symbol (exp, NULL, NULL); | |
1138 | ||
1139 | if (msymbol != NULL) | |
1140 | { | |
1141 | load_addr = SYMBOL_VALUE_ADDRESS (msymbol); | |
1142 | ||
1143 | printf_filtered ("Symbol \""); | |
1144 | fprintf_symbol_filtered (gdb_stdout, exp, | |
1145 | current_language->la_language, DMGL_ANSI); | |
1146 | printf_filtered ("\" is at "); | |
ed49a04f | 1147 | fputs_filtered (paddress (load_addr), gdb_stdout); |
c906108c | 1148 | printf_filtered (" in a file compiled without debugging"); |
714835d5 | 1149 | section = SYMBOL_OBJ_SECTION (msymbol); |
c906108c SS |
1150 | if (section_is_overlay (section)) |
1151 | { | |
1152 | load_addr = overlay_unmapped_address (load_addr, section); | |
1153 | printf_filtered (",\n -- loaded at "); | |
ed49a04f | 1154 | fputs_filtered (paddress (load_addr), gdb_stdout); |
714835d5 UW |
1155 | printf_filtered (" in overlay section %s", |
1156 | section->the_bfd_section->name); | |
c906108c SS |
1157 | } |
1158 | printf_filtered (".\n"); | |
1159 | } | |
1160 | else | |
8a3fe4f8 | 1161 | error (_("No symbol \"%s\" in current context."), exp); |
c906108c SS |
1162 | return; |
1163 | } | |
1164 | ||
1165 | printf_filtered ("Symbol \""); | |
3567439c | 1166 | fprintf_symbol_filtered (gdb_stdout, SYMBOL_PRINT_NAME (sym), |
c906108c SS |
1167 | current_language->la_language, DMGL_ANSI); |
1168 | printf_filtered ("\" is "); | |
c5aa993b | 1169 | val = SYMBOL_VALUE (sym); |
714835d5 | 1170 | section = SYMBOL_OBJ_SECTION (sym); |
768a979c | 1171 | gdbarch = get_objfile_arch (SYMBOL_SYMTAB (sym)->objfile); |
c906108c SS |
1172 | |
1173 | switch (SYMBOL_CLASS (sym)) | |
1174 | { | |
1175 | case LOC_CONST: | |
1176 | case LOC_CONST_BYTES: | |
1177 | printf_filtered ("constant"); | |
1178 | break; | |
1179 | ||
1180 | case LOC_LABEL: | |
1181 | printf_filtered ("a label at address "); | |
ed49a04f MD |
1182 | fputs_filtered (paddress (load_addr = SYMBOL_VALUE_ADDRESS (sym)), |
1183 | gdb_stdout); | |
c906108c SS |
1184 | if (section_is_overlay (section)) |
1185 | { | |
1186 | load_addr = overlay_unmapped_address (load_addr, section); | |
1187 | printf_filtered (",\n -- loaded at "); | |
ed49a04f | 1188 | fputs_filtered (paddress (load_addr), gdb_stdout); |
714835d5 UW |
1189 | printf_filtered (" in overlay section %s", |
1190 | section->the_bfd_section->name); | |
c906108c SS |
1191 | } |
1192 | break; | |
1193 | ||
4c2df51b | 1194 | case LOC_COMPUTED: |
a67af2b9 | 1195 | /* FIXME: cagney/2004-01-26: It should be possible to |
768a979c | 1196 | unconditionally call the SYMBOL_COMPUTED_OPS method when available. |
d3efc286 | 1197 | Unfortunately DWARF 2 stores the frame-base (instead of the |
a67af2b9 AC |
1198 | function) location in a function's symbol. Oops! For the |
1199 | moment enable this when/where applicable. */ | |
768a979c | 1200 | SYMBOL_COMPUTED_OPS (sym)->describe_location (sym, gdb_stdout); |
4c2df51b DJ |
1201 | break; |
1202 | ||
c906108c | 1203 | case LOC_REGISTER: |
768a979c UW |
1204 | /* GDBARCH is the architecture associated with the objfile the symbol |
1205 | is defined in; the target architecture may be different, and may | |
1206 | provide additional registers. However, we do not know the target | |
1207 | architecture at this point. We assume the objfile architecture | |
1208 | will contain all the standard registers that occur in debug info | |
1209 | in that objfile. */ | |
1210 | regno = SYMBOL_REGISTER_OPS (sym)->register_number (sym, gdbarch); | |
1211 | ||
2a2d4dc3 AS |
1212 | if (SYMBOL_IS_ARGUMENT (sym)) |
1213 | printf_filtered (_("an argument in register %s"), | |
768a979c | 1214 | gdbarch_register_name (gdbarch, regno)); |
2a2d4dc3 AS |
1215 | else |
1216 | printf_filtered (_("a variable in register %s"), | |
768a979c | 1217 | gdbarch_register_name (gdbarch, regno)); |
c906108c SS |
1218 | break; |
1219 | ||
1220 | case LOC_STATIC: | |
a3f17187 | 1221 | printf_filtered (_("static storage at address ")); |
ed49a04f MD |
1222 | fputs_filtered (paddress (load_addr = SYMBOL_VALUE_ADDRESS (sym)), |
1223 | gdb_stdout); | |
c906108c SS |
1224 | if (section_is_overlay (section)) |
1225 | { | |
1226 | load_addr = overlay_unmapped_address (load_addr, section); | |
a3f17187 | 1227 | printf_filtered (_(",\n -- loaded at ")); |
ed49a04f | 1228 | fputs_filtered (paddress (load_addr), gdb_stdout); |
714835d5 UW |
1229 | printf_filtered (_(" in overlay section %s"), |
1230 | section->the_bfd_section->name); | |
c906108c SS |
1231 | } |
1232 | break; | |
1233 | ||
c906108c | 1234 | case LOC_REGPARM_ADDR: |
768a979c UW |
1235 | /* Note comment at LOC_REGISTER. */ |
1236 | regno = SYMBOL_REGISTER_OPS (sym)->register_number (sym, gdbarch); | |
675dcf4f | 1237 | printf_filtered (_("address of an argument in register %s"), |
768a979c | 1238 | gdbarch_register_name (gdbarch, regno)); |
c906108c SS |
1239 | break; |
1240 | ||
1241 | case LOC_ARG: | |
a3f17187 | 1242 | printf_filtered (_("an argument at offset %ld"), val); |
c906108c SS |
1243 | break; |
1244 | ||
c906108c | 1245 | case LOC_LOCAL: |
a3f17187 | 1246 | printf_filtered (_("a local variable at frame offset %ld"), val); |
c906108c SS |
1247 | break; |
1248 | ||
1249 | case LOC_REF_ARG: | |
a3f17187 | 1250 | printf_filtered (_("a reference argument at offset %ld"), val); |
c906108c SS |
1251 | break; |
1252 | ||
c906108c | 1253 | case LOC_TYPEDEF: |
a3f17187 | 1254 | printf_filtered (_("a typedef")); |
c906108c SS |
1255 | break; |
1256 | ||
1257 | case LOC_BLOCK: | |
a3f17187 | 1258 | printf_filtered (_("a function at address ")); |
675dcf4f | 1259 | load_addr = BLOCK_START (SYMBOL_BLOCK_VALUE (sym)); |
ed49a04f | 1260 | fputs_filtered (paddress (load_addr), gdb_stdout); |
c906108c SS |
1261 | if (section_is_overlay (section)) |
1262 | { | |
1263 | load_addr = overlay_unmapped_address (load_addr, section); | |
a3f17187 | 1264 | printf_filtered (_(",\n -- loaded at ")); |
ed49a04f | 1265 | fputs_filtered (paddress (load_addr), gdb_stdout); |
714835d5 UW |
1266 | printf_filtered (_(" in overlay section %s"), |
1267 | section->the_bfd_section->name); | |
c906108c SS |
1268 | } |
1269 | break; | |
1270 | ||
1271 | case LOC_UNRESOLVED: | |
1272 | { | |
1273 | struct minimal_symbol *msym; | |
1274 | ||
3567439c | 1275 | msym = lookup_minimal_symbol (SYMBOL_LINKAGE_NAME (sym), NULL, NULL); |
c906108c SS |
1276 | if (msym == NULL) |
1277 | printf_filtered ("unresolved"); | |
1278 | else | |
1279 | { | |
714835d5 | 1280 | section = SYMBOL_OBJ_SECTION (msym); |
675dcf4f | 1281 | load_addr = SYMBOL_VALUE_ADDRESS (msym); |
e0740f77 JK |
1282 | |
1283 | if (section | |
1284 | && (section->the_bfd_section->flags & SEC_THREAD_LOCAL) != 0) | |
1285 | printf_filtered (_("a thread-local variable at offset %s " | |
1286 | "in the thread-local storage for `%s'"), | |
1287 | paddr_nz (load_addr), section->objfile->name); | |
1288 | else | |
c906108c | 1289 | { |
e0740f77 | 1290 | printf_filtered (_("static storage at address ")); |
ed49a04f | 1291 | fputs_filtered (paddress (load_addr), gdb_stdout); |
e0740f77 JK |
1292 | if (section_is_overlay (section)) |
1293 | { | |
1294 | load_addr = overlay_unmapped_address (load_addr, section); | |
1295 | printf_filtered (_(",\n -- loaded at ")); | |
1296 | fputs_filtered (paddress (load_addr), gdb_stdout); | |
1297 | printf_filtered (_(" in overlay section %s"), | |
1298 | section->the_bfd_section->name); | |
1299 | } | |
c906108c SS |
1300 | } |
1301 | } | |
1302 | } | |
1303 | break; | |
1304 | ||
c906108c | 1305 | case LOC_OPTIMIZED_OUT: |
a3f17187 | 1306 | printf_filtered (_("optimized out")); |
c906108c | 1307 | break; |
c5aa993b | 1308 | |
c906108c | 1309 | default: |
a3f17187 | 1310 | printf_filtered (_("of unknown (botched) type")); |
c906108c SS |
1311 | break; |
1312 | } | |
1313 | printf_filtered (".\n"); | |
1314 | } | |
1315 | \f | |
675dcf4f MK |
1316 | |
1317 | static void | |
fba45db2 | 1318 | x_command (char *exp, int from_tty) |
c906108c SS |
1319 | { |
1320 | struct expression *expr; | |
1321 | struct format_data fmt; | |
1322 | struct cleanup *old_chain; | |
1323 | struct value *val; | |
1324 | ||
a6bac58e | 1325 | fmt.format = last_format ? last_format : 'x'; |
c906108c SS |
1326 | fmt.size = last_size; |
1327 | fmt.count = 1; | |
a6bac58e | 1328 | fmt.raw = 0; |
c906108c SS |
1329 | |
1330 | if (exp && *exp == '/') | |
1331 | { | |
1332 | exp++; | |
1333 | fmt = decode_format (&exp, last_format, last_size); | |
1334 | } | |
1335 | ||
1336 | /* If we have an expression, evaluate it and use it as the address. */ | |
1337 | ||
1338 | if (exp != 0 && *exp != 0) | |
1339 | { | |
1340 | expr = parse_expression (exp); | |
675dcf4f MK |
1341 | /* Cause expression not to be there any more if this command is |
1342 | repeated with Newline. But don't clobber a user-defined | |
1343 | command's definition. */ | |
c906108c SS |
1344 | if (from_tty) |
1345 | *exp = 0; | |
c13c43fd | 1346 | old_chain = make_cleanup (free_current_contents, &expr); |
c906108c | 1347 | val = evaluate_expression (expr); |
df407dfe | 1348 | if (TYPE_CODE (value_type (val)) == TYPE_CODE_REF) |
c906108c SS |
1349 | val = value_ind (val); |
1350 | /* In rvalue contexts, such as this, functions are coerced into | |
c5aa993b | 1351 | pointers to functions. This makes "x/i main" work. */ |
c0d8fd9a | 1352 | if (/* last_format == 'i' && */ |
df407dfe | 1353 | TYPE_CODE (value_type (val)) == TYPE_CODE_FUNC |
c5aa993b | 1354 | && VALUE_LVAL (val) == lval_memory) |
42ae5230 | 1355 | next_address = value_address (val); |
c906108c | 1356 | else |
1aa20aa8 | 1357 | next_address = value_as_address (val); |
5d3729b5 UW |
1358 | |
1359 | next_gdbarch = expr->gdbarch; | |
c906108c SS |
1360 | do_cleanups (old_chain); |
1361 | } | |
1362 | ||
5d3729b5 UW |
1363 | if (!next_gdbarch) |
1364 | error_no_arg (_("starting display address")); | |
1365 | ||
1366 | do_examine (fmt, next_gdbarch, next_address); | |
c906108c | 1367 | |
675dcf4f MK |
1368 | /* If the examine succeeds, we remember its size and format for next |
1369 | time. */ | |
c906108c SS |
1370 | last_size = fmt.size; |
1371 | last_format = fmt.format; | |
1372 | ||
1373 | /* Set a couple of internal variables if appropriate. */ | |
1374 | if (last_examine_value) | |
1375 | { | |
1376 | /* Make last address examined available to the user as $_. Use | |
c5aa993b | 1377 | the correct pointer type. */ |
4478b372 | 1378 | struct type *pointer_type |
df407dfe | 1379 | = lookup_pointer_type (value_type (last_examine_value)); |
c906108c | 1380 | set_internalvar (lookup_internalvar ("_"), |
4478b372 JB |
1381 | value_from_pointer (pointer_type, |
1382 | last_examine_address)); | |
c5aa993b | 1383 | |
675dcf4f MK |
1384 | /* Make contents of last address examined available to the user |
1385 | as $__. If the last value has not been fetched from memory | |
1386 | then don't fetch it now; instead mark it by voiding the $__ | |
1387 | variable. */ | |
d69fe07e | 1388 | if (value_lazy (last_examine_value)) |
4fa62494 | 1389 | clear_internalvar (lookup_internalvar ("__")); |
c906108c SS |
1390 | else |
1391 | set_internalvar (lookup_internalvar ("__"), last_examine_value); | |
1392 | } | |
1393 | } | |
c906108c | 1394 | \f |
c5aa993b | 1395 | |
c906108c SS |
1396 | /* Add an expression to the auto-display chain. |
1397 | Specify the expression. */ | |
1398 | ||
1399 | static void | |
fba45db2 | 1400 | display_command (char *exp, int from_tty) |
c906108c SS |
1401 | { |
1402 | struct format_data fmt; | |
52f0bd74 AC |
1403 | struct expression *expr; |
1404 | struct display *new; | |
c906108c SS |
1405 | int display_it = 1; |
1406 | ||
1407 | #if defined(TUI) | |
021e7609 AC |
1408 | /* NOTE: cagney/2003-02-13 The `tui_active' was previously |
1409 | `tui_version'. */ | |
fd33e6cb | 1410 | if (tui_active && exp != NULL && *exp == '$') |
080ce8c0 | 1411 | display_it = (tui_set_layout_for_display_command (exp) == TUI_FAILURE); |
c906108c SS |
1412 | #endif |
1413 | ||
1414 | if (display_it) | |
1415 | { | |
1416 | if (exp == 0) | |
1417 | { | |
1418 | do_displays (); | |
1419 | return; | |
1420 | } | |
1421 | ||
1422 | if (*exp == '/') | |
1423 | { | |
1424 | exp++; | |
1425 | fmt = decode_format (&exp, 0, 0); | |
1426 | if (fmt.size && fmt.format == 0) | |
1427 | fmt.format = 'x'; | |
1428 | if (fmt.format == 'i' || fmt.format == 's') | |
1429 | fmt.size = 'b'; | |
1430 | } | |
1431 | else | |
1432 | { | |
1433 | fmt.format = 0; | |
1434 | fmt.size = 0; | |
1435 | fmt.count = 0; | |
a6bac58e | 1436 | fmt.raw = 0; |
c906108c SS |
1437 | } |
1438 | ||
a3247a22 | 1439 | innermost_block = NULL; |
c906108c SS |
1440 | expr = parse_expression (exp); |
1441 | ||
1442 | new = (struct display *) xmalloc (sizeof (struct display)); | |
1443 | ||
fa8a61dc | 1444 | new->exp_string = xstrdup (exp); |
c906108c SS |
1445 | new->exp = expr; |
1446 | new->block = innermost_block; | |
1447 | new->next = display_chain; | |
1448 | new->number = ++display_number; | |
1449 | new->format = fmt; | |
b5de0fa7 | 1450 | new->enabled_p = 1; |
c906108c SS |
1451 | display_chain = new; |
1452 | ||
1453 | if (from_tty && target_has_execution) | |
1454 | do_one_display (new); | |
1455 | ||
1456 | dont_repeat (); | |
1457 | } | |
1458 | } | |
1459 | ||
1460 | static void | |
fba45db2 | 1461 | free_display (struct display *d) |
c906108c | 1462 | { |
fa8a61dc | 1463 | xfree (d->exp_string); |
b8c9b27d KB |
1464 | xfree (d->exp); |
1465 | xfree (d); | |
c906108c SS |
1466 | } |
1467 | ||
675dcf4f MK |
1468 | /* Clear out the display_chain. Done when new symtabs are loaded, |
1469 | since this invalidates the types stored in many expressions. */ | |
c906108c SS |
1470 | |
1471 | void | |
fba45db2 | 1472 | clear_displays (void) |
c906108c | 1473 | { |
52f0bd74 | 1474 | struct display *d; |
c906108c SS |
1475 | |
1476 | while ((d = display_chain) != NULL) | |
1477 | { | |
c906108c | 1478 | display_chain = d->next; |
fa8a61dc | 1479 | free_display (d); |
c906108c SS |
1480 | } |
1481 | } | |
1482 | ||
1483 | /* Delete the auto-display number NUM. */ | |
1484 | ||
1485 | static void | |
fba45db2 | 1486 | delete_display (int num) |
c906108c | 1487 | { |
52f0bd74 | 1488 | struct display *d1, *d; |
c906108c SS |
1489 | |
1490 | if (!display_chain) | |
8a3fe4f8 | 1491 | error (_("No display number %d."), num); |
c906108c SS |
1492 | |
1493 | if (display_chain->number == num) | |
1494 | { | |
1495 | d1 = display_chain; | |
1496 | display_chain = d1->next; | |
1497 | free_display (d1); | |
1498 | } | |
1499 | else | |
c5aa993b | 1500 | for (d = display_chain;; d = d->next) |
c906108c SS |
1501 | { |
1502 | if (d->next == 0) | |
8a3fe4f8 | 1503 | error (_("No display number %d."), num); |
c906108c SS |
1504 | if (d->next->number == num) |
1505 | { | |
1506 | d1 = d->next; | |
1507 | d->next = d1->next; | |
1508 | free_display (d1); | |
1509 | break; | |
1510 | } | |
1511 | } | |
1512 | } | |
1513 | ||
1514 | /* Delete some values from the auto-display chain. | |
1515 | Specify the element numbers. */ | |
1516 | ||
1517 | static void | |
fba45db2 | 1518 | undisplay_command (char *args, int from_tty) |
c906108c | 1519 | { |
52f0bd74 AC |
1520 | char *p = args; |
1521 | char *p1; | |
1522 | int num; | |
c906108c SS |
1523 | |
1524 | if (args == 0) | |
1525 | { | |
9e2f0ad4 | 1526 | if (query (_("Delete all auto-display expressions? "))) |
c906108c SS |
1527 | clear_displays (); |
1528 | dont_repeat (); | |
1529 | return; | |
1530 | } | |
1531 | ||
1532 | while (*p) | |
1533 | { | |
1534 | p1 = p; | |
c5aa993b JM |
1535 | while (*p1 >= '0' && *p1 <= '9') |
1536 | p1++; | |
c906108c | 1537 | if (*p1 && *p1 != ' ' && *p1 != '\t') |
8a3fe4f8 | 1538 | error (_("Arguments must be display numbers.")); |
c906108c SS |
1539 | |
1540 | num = atoi (p); | |
1541 | ||
1542 | delete_display (num); | |
1543 | ||
1544 | p = p1; | |
c5aa993b JM |
1545 | while (*p == ' ' || *p == '\t') |
1546 | p++; | |
c906108c SS |
1547 | } |
1548 | dont_repeat (); | |
1549 | } | |
1550 | ||
1551 | /* Display a single auto-display. | |
1552 | Do nothing if the display cannot be printed in the current context, | |
1553 | or if the display is disabled. */ | |
1554 | ||
1555 | static void | |
fba45db2 | 1556 | do_one_display (struct display *d) |
c906108c SS |
1557 | { |
1558 | int within_current_scope; | |
1559 | ||
b5de0fa7 | 1560 | if (d->enabled_p == 0) |
c906108c SS |
1561 | return; |
1562 | ||
a3247a22 PP |
1563 | if (d->exp == NULL) |
1564 | { | |
1565 | volatile struct gdb_exception ex; | |
1566 | TRY_CATCH (ex, RETURN_MASK_ALL) | |
1567 | { | |
1568 | innermost_block = NULL; | |
1569 | d->exp = parse_expression (d->exp_string); | |
1570 | d->block = innermost_block; | |
1571 | } | |
1572 | if (ex.reason < 0) | |
1573 | { | |
1574 | /* Can't re-parse the expression. Disable this display item. */ | |
1575 | d->enabled_p = 0; | |
1576 | warning (_("Unable to display \"%s\": %s"), | |
1577 | d->exp_string, ex.message); | |
1578 | return; | |
1579 | } | |
1580 | } | |
1581 | ||
c906108c | 1582 | if (d->block) |
ae767bfb | 1583 | within_current_scope = contained_in (get_selected_block (0), d->block); |
c906108c SS |
1584 | else |
1585 | within_current_scope = 1; | |
1586 | if (!within_current_scope) | |
1587 | return; | |
1588 | ||
1589 | current_display_number = d->number; | |
1590 | ||
1591 | annotate_display_begin (); | |
1592 | printf_filtered ("%d", d->number); | |
1593 | annotate_display_number_end (); | |
1594 | printf_filtered (": "); | |
1595 | if (d->format.size) | |
1596 | { | |
1597 | CORE_ADDR addr; | |
3d6d86c6 | 1598 | struct value *val; |
c906108c SS |
1599 | |
1600 | annotate_display_format (); | |
1601 | ||
1602 | printf_filtered ("x/"); | |
1603 | if (d->format.count != 1) | |
1604 | printf_filtered ("%d", d->format.count); | |
1605 | printf_filtered ("%c", d->format.format); | |
1606 | if (d->format.format != 'i' && d->format.format != 's') | |
1607 | printf_filtered ("%c", d->format.size); | |
1608 | printf_filtered (" "); | |
1609 | ||
1610 | annotate_display_expression (); | |
1611 | ||
fa8a61dc | 1612 | puts_filtered (d->exp_string); |
c906108c SS |
1613 | annotate_display_expression_end (); |
1614 | ||
6a2eb474 | 1615 | if (d->format.count != 1 || d->format.format == 'i') |
c906108c SS |
1616 | printf_filtered ("\n"); |
1617 | else | |
1618 | printf_filtered (" "); | |
c5aa993b | 1619 | |
c906108c | 1620 | val = evaluate_expression (d->exp); |
1aa20aa8 | 1621 | addr = value_as_address (val); |
c906108c | 1622 | if (d->format.format == 'i') |
d80b854b | 1623 | addr = gdbarch_addr_bits_remove (d->exp->gdbarch, addr); |
c906108c SS |
1624 | |
1625 | annotate_display_value (); | |
1626 | ||
5d3729b5 | 1627 | do_examine (d->format, d->exp->gdbarch, addr); |
c906108c SS |
1628 | } |
1629 | else | |
1630 | { | |
79a45b7d TT |
1631 | struct value_print_options opts; |
1632 | ||
c906108c SS |
1633 | annotate_display_format (); |
1634 | ||
1635 | if (d->format.format) | |
1636 | printf_filtered ("/%c ", d->format.format); | |
1637 | ||
1638 | annotate_display_expression (); | |
1639 | ||
fa8a61dc | 1640 | puts_filtered (d->exp_string); |
c906108c SS |
1641 | annotate_display_expression_end (); |
1642 | ||
1643 | printf_filtered (" = "); | |
1644 | ||
1645 | annotate_display_expression (); | |
1646 | ||
79a45b7d | 1647 | get_formatted_print_options (&opts, d->format.format); |
a6bac58e | 1648 | opts.raw = d->format.raw; |
c906108c | 1649 | print_formatted (evaluate_expression (d->exp), |
79a45b7d | 1650 | d->format.size, &opts, gdb_stdout); |
c906108c SS |
1651 | printf_filtered ("\n"); |
1652 | } | |
1653 | ||
1654 | annotate_display_end (); | |
1655 | ||
1656 | gdb_flush (gdb_stdout); | |
1657 | current_display_number = -1; | |
1658 | } | |
1659 | ||
1660 | /* Display all of the values on the auto-display chain which can be | |
1661 | evaluated in the current scope. */ | |
1662 | ||
1663 | void | |
fba45db2 | 1664 | do_displays (void) |
c906108c | 1665 | { |
52f0bd74 | 1666 | struct display *d; |
c906108c SS |
1667 | |
1668 | for (d = display_chain; d; d = d->next) | |
1669 | do_one_display (d); | |
1670 | } | |
1671 | ||
1672 | /* Delete the auto-display which we were in the process of displaying. | |
1673 | This is done when there is an error or a signal. */ | |
1674 | ||
1675 | void | |
fba45db2 | 1676 | disable_display (int num) |
c906108c | 1677 | { |
52f0bd74 | 1678 | struct display *d; |
c906108c SS |
1679 | |
1680 | for (d = display_chain; d; d = d->next) | |
1681 | if (d->number == num) | |
1682 | { | |
b5de0fa7 | 1683 | d->enabled_p = 0; |
c906108c SS |
1684 | return; |
1685 | } | |
a3f17187 | 1686 | printf_unfiltered (_("No display number %d.\n"), num); |
c906108c | 1687 | } |
c5aa993b | 1688 | |
c906108c | 1689 | void |
fba45db2 | 1690 | disable_current_display (void) |
c906108c SS |
1691 | { |
1692 | if (current_display_number >= 0) | |
1693 | { | |
1694 | disable_display (current_display_number); | |
675dcf4f MK |
1695 | fprintf_unfiltered (gdb_stderr, _("\ |
1696 | Disabling display %d to avoid infinite recursion.\n"), | |
c5aa993b | 1697 | current_display_number); |
c906108c SS |
1698 | } |
1699 | current_display_number = -1; | |
1700 | } | |
1701 | ||
1702 | static void | |
fba45db2 | 1703 | display_info (char *ignore, int from_tty) |
c906108c | 1704 | { |
52f0bd74 | 1705 | struct display *d; |
c906108c SS |
1706 | |
1707 | if (!display_chain) | |
a3f17187 | 1708 | printf_unfiltered (_("There are no auto-display expressions now.\n")); |
c906108c | 1709 | else |
a3f17187 AC |
1710 | printf_filtered (_("Auto-display expressions now in effect:\n\ |
1711 | Num Enb Expression\n")); | |
c906108c SS |
1712 | |
1713 | for (d = display_chain; d; d = d->next) | |
1714 | { | |
b5de0fa7 | 1715 | printf_filtered ("%d: %c ", d->number, "ny"[(int) d->enabled_p]); |
c906108c SS |
1716 | if (d->format.size) |
1717 | printf_filtered ("/%d%c%c ", d->format.count, d->format.size, | |
c5aa993b | 1718 | d->format.format); |
c906108c SS |
1719 | else if (d->format.format) |
1720 | printf_filtered ("/%c ", d->format.format); | |
fa8a61dc | 1721 | puts_filtered (d->exp_string); |
ae767bfb | 1722 | if (d->block && !contained_in (get_selected_block (0), d->block)) |
a3f17187 | 1723 | printf_filtered (_(" (cannot be evaluated in the current context)")); |
c906108c SS |
1724 | printf_filtered ("\n"); |
1725 | gdb_flush (gdb_stdout); | |
1726 | } | |
1727 | } | |
1728 | ||
1729 | static void | |
fba45db2 | 1730 | enable_display (char *args, int from_tty) |
c906108c | 1731 | { |
52f0bd74 AC |
1732 | char *p = args; |
1733 | char *p1; | |
1734 | int num; | |
1735 | struct display *d; | |
c906108c SS |
1736 | |
1737 | if (p == 0) | |
1738 | { | |
1739 | for (d = display_chain; d; d = d->next) | |
b5de0fa7 | 1740 | d->enabled_p = 1; |
c906108c SS |
1741 | } |
1742 | else | |
1743 | while (*p) | |
1744 | { | |
1745 | p1 = p; | |
1746 | while (*p1 >= '0' && *p1 <= '9') | |
1747 | p1++; | |
1748 | if (*p1 && *p1 != ' ' && *p1 != '\t') | |
8a3fe4f8 | 1749 | error (_("Arguments must be display numbers.")); |
c5aa993b | 1750 | |
c906108c | 1751 | num = atoi (p); |
c5aa993b | 1752 | |
c906108c SS |
1753 | for (d = display_chain; d; d = d->next) |
1754 | if (d->number == num) | |
1755 | { | |
b5de0fa7 | 1756 | d->enabled_p = 1; |
c906108c SS |
1757 | goto win; |
1758 | } | |
a3f17187 | 1759 | printf_unfiltered (_("No display number %d.\n"), num); |
c906108c SS |
1760 | win: |
1761 | p = p1; | |
1762 | while (*p == ' ' || *p == '\t') | |
1763 | p++; | |
1764 | } | |
1765 | } | |
1766 | ||
c906108c | 1767 | static void |
fba45db2 | 1768 | disable_display_command (char *args, int from_tty) |
c906108c | 1769 | { |
52f0bd74 AC |
1770 | char *p = args; |
1771 | char *p1; | |
1772 | struct display *d; | |
c906108c SS |
1773 | |
1774 | if (p == 0) | |
1775 | { | |
1776 | for (d = display_chain; d; d = d->next) | |
b5de0fa7 | 1777 | d->enabled_p = 0; |
c906108c SS |
1778 | } |
1779 | else | |
1780 | while (*p) | |
1781 | { | |
1782 | p1 = p; | |
1783 | while (*p1 >= '0' && *p1 <= '9') | |
1784 | p1++; | |
1785 | if (*p1 && *p1 != ' ' && *p1 != '\t') | |
8a3fe4f8 | 1786 | error (_("Arguments must be display numbers.")); |
c5aa993b | 1787 | |
c906108c SS |
1788 | disable_display (atoi (p)); |
1789 | ||
1790 | p = p1; | |
1791 | while (*p == ' ' || *p == '\t') | |
1792 | p++; | |
1793 | } | |
1794 | } | |
a3247a22 PP |
1795 | |
1796 | /* Return 1 if D uses SOLIB (and will become dangling when SOLIB | |
1797 | is unloaded), otherwise return 0. */ | |
1798 | ||
1799 | static int | |
1800 | display_uses_solib_p (const struct display *d, | |
1801 | const struct so_list *solib) | |
1802 | { | |
36dc683c | 1803 | int endpos; |
a3247a22 | 1804 | struct expression *const exp = d->exp; |
36dc683c | 1805 | const union exp_element *const elts = exp->elts; |
a3247a22 PP |
1806 | |
1807 | if (d->block != NULL | |
5fd1a349 | 1808 | && solib_contains_address_p (solib, d->block->startaddr)) |
a3247a22 PP |
1809 | return 1; |
1810 | ||
36dc683c | 1811 | for (endpos = exp->nelts; endpos > 0; ) |
a3247a22 | 1812 | { |
36dc683c DE |
1813 | int i, args, oplen = 0; |
1814 | ||
1815 | exp->language_defn->la_exp_desc->operator_length (exp, endpos, | |
1816 | &oplen, &args); | |
1817 | gdb_assert (oplen > 0); | |
a3247a22 | 1818 | |
36dc683c | 1819 | i = endpos - oplen; |
a3247a22 PP |
1820 | if (elts[i].opcode == OP_VAR_VALUE) |
1821 | { | |
1822 | const struct block *const block = elts[i + 1].block; | |
1823 | const struct symbol *const symbol = elts[i + 2].symbol; | |
1824 | const struct obj_section *const section = | |
1825 | SYMBOL_OBJ_SECTION (symbol); | |
1826 | ||
1827 | if (block != NULL | |
5fd1a349 | 1828 | && solib_contains_address_p (solib, block->startaddr)) |
a3247a22 PP |
1829 | return 1; |
1830 | ||
1831 | if (section && section->objfile == solib->objfile) | |
1832 | return 1; | |
1833 | } | |
36dc683c | 1834 | endpos -= oplen; |
a3247a22 | 1835 | } |
36dc683c | 1836 | |
a3247a22 PP |
1837 | return 0; |
1838 | } | |
1839 | ||
1840 | /* display_chain items point to blocks and expressions. Some expressions in | |
1841 | turn may point to symbols. | |
1842 | Both symbols and blocks are obstack_alloc'd on objfile_stack, and are | |
1843 | obstack_free'd when a shared library is unloaded. | |
1844 | Clear pointers that are about to become dangling. | |
1845 | Both .exp and .block fields will be restored next time we need to display | |
1846 | an item by re-parsing .exp_string field in the new execution context. */ | |
1847 | ||
1848 | static void | |
1849 | clear_dangling_display_expressions (struct so_list *solib) | |
1850 | { | |
1851 | struct display *d; | |
1852 | struct objfile *objfile = NULL; | |
1853 | ||
1854 | for (d = display_chain; d; d = d->next) | |
1855 | { | |
1856 | if (d->exp && display_uses_solib_p (d, solib)) | |
1857 | { | |
1858 | xfree (d->exp); | |
1859 | d->exp = NULL; | |
1860 | d->block = NULL; | |
1861 | } | |
1862 | } | |
1863 | } | |
c906108c | 1864 | \f |
c5aa993b | 1865 | |
675dcf4f | 1866 | /* Print the value in stack frame FRAME of a variable specified by a |
aad95b57 TT |
1867 | struct symbol. NAME is the name to print; if NULL then VAR's print |
1868 | name will be used. STREAM is the ui_file on which to print the | |
1869 | value. INDENT specifies the number of indent levels to print | |
1870 | before printing the variable name. */ | |
c906108c SS |
1871 | |
1872 | void | |
aad95b57 TT |
1873 | print_variable_and_value (const char *name, struct symbol *var, |
1874 | struct frame_info *frame, | |
1875 | struct ui_file *stream, int indent) | |
c906108c | 1876 | { |
aad95b57 | 1877 | struct value *val; |
79a45b7d | 1878 | struct value_print_options opts; |
c906108c | 1879 | |
aad95b57 TT |
1880 | if (!name) |
1881 | name = SYMBOL_PRINT_NAME (var); | |
1882 | ||
1883 | fprintf_filtered (stream, "%s%s = ", n_spaces (2 * indent), name); | |
1884 | ||
1885 | val = read_var_value (var, frame); | |
79a45b7d | 1886 | get_user_print_options (&opts); |
aad95b57 TT |
1887 | common_val_print (val, stream, indent, &opts, current_language); |
1888 | fprintf_filtered (stream, "\n"); | |
c906108c SS |
1889 | } |
1890 | ||
c906108c | 1891 | static void |
fba45db2 | 1892 | printf_command (char *arg, int from_tty) |
c906108c | 1893 | { |
52f0bd74 AC |
1894 | char *f = NULL; |
1895 | char *s = arg; | |
c906108c | 1896 | char *string = NULL; |
3d6d86c6 | 1897 | struct value **val_args; |
c906108c SS |
1898 | char *substrings; |
1899 | char *current_substring; | |
1900 | int nargs = 0; | |
1901 | int allocated_args = 20; | |
1902 | struct cleanup *old_cleanups; | |
1903 | ||
675dcf4f | 1904 | val_args = xmalloc (allocated_args * sizeof (struct value *)); |
c13c43fd | 1905 | old_cleanups = make_cleanup (free_current_contents, &val_args); |
c906108c SS |
1906 | |
1907 | if (s == 0) | |
e2e0b3e5 | 1908 | error_no_arg (_("format-control string and values to print")); |
c906108c SS |
1909 | |
1910 | /* Skip white space before format string */ | |
c5aa993b JM |
1911 | while (*s == ' ' || *s == '\t') |
1912 | s++; | |
c906108c | 1913 | |
675dcf4f | 1914 | /* A format string should follow, enveloped in double quotes. */ |
c906108c | 1915 | if (*s++ != '"') |
8a3fe4f8 | 1916 | error (_("Bad format string, missing '\"'.")); |
c906108c SS |
1917 | |
1918 | /* Parse the format-control string and copy it into the string STRING, | |
1919 | processing some kinds of escape sequence. */ | |
1920 | ||
1921 | f = string = (char *) alloca (strlen (s) + 1); | |
1922 | ||
1923 | while (*s != '"') | |
1924 | { | |
1925 | int c = *s++; | |
1926 | switch (c) | |
1927 | { | |
1928 | case '\0': | |
8a3fe4f8 | 1929 | error (_("Bad format string, non-terminated '\"'.")); |
c906108c SS |
1930 | |
1931 | case '\\': | |
1932 | switch (c = *s++) | |
1933 | { | |
1934 | case '\\': | |
1935 | *f++ = '\\'; | |
1936 | break; | |
1937 | case 'a': | |
c906108c | 1938 | *f++ = '\a'; |
c906108c SS |
1939 | break; |
1940 | case 'b': | |
1941 | *f++ = '\b'; | |
1942 | break; | |
1943 | case 'f': | |
1944 | *f++ = '\f'; | |
1945 | break; | |
1946 | case 'n': | |
1947 | *f++ = '\n'; | |
1948 | break; | |
1949 | case 'r': | |
1950 | *f++ = '\r'; | |
1951 | break; | |
1952 | case 't': | |
1953 | *f++ = '\t'; | |
1954 | break; | |
1955 | case 'v': | |
1956 | *f++ = '\v'; | |
1957 | break; | |
1958 | case '"': | |
1959 | *f++ = '"'; | |
1960 | break; | |
1961 | default: | |
1962 | /* ??? TODO: handle other escape sequences */ | |
8a3fe4f8 | 1963 | error (_("Unrecognized escape character \\%c in format string."), |
c906108c SS |
1964 | c); |
1965 | } | |
1966 | break; | |
1967 | ||
1968 | default: | |
1969 | *f++ = c; | |
1970 | } | |
1971 | } | |
1972 | ||
1973 | /* Skip over " and following space and comma. */ | |
1974 | s++; | |
1975 | *f++ = '\0'; | |
c5aa993b JM |
1976 | while (*s == ' ' || *s == '\t') |
1977 | s++; | |
c906108c SS |
1978 | |
1979 | if (*s != ',' && *s != 0) | |
8a3fe4f8 | 1980 | error (_("Invalid argument syntax")); |
c906108c | 1981 | |
c5aa993b JM |
1982 | if (*s == ',') |
1983 | s++; | |
1984 | while (*s == ' ' || *s == '\t') | |
1985 | s++; | |
c906108c SS |
1986 | |
1987 | /* Need extra space for the '\0's. Doubling the size is sufficient. */ | |
1988 | substrings = alloca (strlen (string) * 2); | |
1989 | current_substring = substrings; | |
1990 | ||
1991 | { | |
1992 | /* Now scan the string for %-specs and see what kinds of args they want. | |
1993 | argclass[I] classifies the %-specs so we can give printf_filtered | |
1994 | something of the right size. */ | |
1995 | ||
c5aa993b JM |
1996 | enum argclass |
1997 | { | |
6c7a06a3 TT |
1998 | int_arg, long_arg, long_long_arg, ptr_arg, |
1999 | string_arg, wide_string_arg, wide_char_arg, | |
1a619819 | 2000 | double_arg, long_double_arg, decfloat_arg |
c5aa993b | 2001 | }; |
c906108c SS |
2002 | enum argclass *argclass; |
2003 | enum argclass this_argclass; | |
2004 | char *last_arg; | |
2005 | int nargs_wanted; | |
c906108c SS |
2006 | int i; |
2007 | ||
2008 | argclass = (enum argclass *) alloca (strlen (s) * sizeof *argclass); | |
2009 | nargs_wanted = 0; | |
2010 | f = string; | |
2011 | last_arg = string; | |
2012 | while (*f) | |
2013 | if (*f++ == '%') | |
2014 | { | |
46e9880c DJ |
2015 | int seen_hash = 0, seen_zero = 0, lcount = 0, seen_prec = 0; |
2016 | int seen_space = 0, seen_plus = 0; | |
0aea4bf3 LM |
2017 | int seen_big_l = 0, seen_h = 0, seen_big_h = 0; |
2018 | int seen_big_d = 0, seen_double_big_d = 0; | |
46e9880c DJ |
2019 | int bad = 0; |
2020 | ||
2021 | /* Check the validity of the format specifier, and work | |
2022 | out what argument it expects. We only accept C89 | |
2023 | format strings, with the exception of long long (which | |
2024 | we autoconf for). */ | |
2025 | ||
2026 | /* Skip over "%%". */ | |
2027 | if (*f == '%') | |
c906108c | 2028 | { |
c906108c | 2029 | f++; |
46e9880c | 2030 | continue; |
c906108c | 2031 | } |
46e9880c DJ |
2032 | |
2033 | /* The first part of a format specifier is a set of flag | |
2034 | characters. */ | |
2035 | while (strchr ("0-+ #", *f)) | |
2036 | { | |
2037 | if (*f == '#') | |
2038 | seen_hash = 1; | |
2039 | else if (*f == '0') | |
2040 | seen_zero = 1; | |
2041 | else if (*f == ' ') | |
2042 | seen_space = 1; | |
2043 | else if (*f == '+') | |
2044 | seen_plus = 1; | |
2045 | f++; | |
2046 | } | |
2047 | ||
2048 | /* The next part of a format specifier is a width. */ | |
2049 | while (strchr ("0123456789", *f)) | |
2050 | f++; | |
2051 | ||
2052 | /* The next part of a format specifier is a precision. */ | |
2053 | if (*f == '.') | |
2054 | { | |
2055 | seen_prec = 1; | |
2056 | f++; | |
2057 | while (strchr ("0123456789", *f)) | |
2058 | f++; | |
2059 | } | |
2060 | ||
2061 | /* The next part of a format specifier is a length modifier. */ | |
2062 | if (*f == 'h') | |
2063 | { | |
2064 | seen_h = 1; | |
2065 | f++; | |
2066 | } | |
2067 | else if (*f == 'l') | |
2068 | { | |
2069 | f++; | |
2070 | lcount++; | |
2071 | if (*f == 'l') | |
2072 | { | |
2073 | f++; | |
2074 | lcount++; | |
2075 | } | |
2076 | } | |
2077 | else if (*f == 'L') | |
2078 | { | |
2079 | seen_big_l = 1; | |
2080 | f++; | |
2081 | } | |
0aea4bf3 LM |
2082 | /* Decimal32 modifier. */ |
2083 | else if (*f == 'H') | |
2084 | { | |
2085 | seen_big_h = 1; | |
2086 | f++; | |
2087 | } | |
2088 | /* Decimal64 and Decimal128 modifiers. */ | |
2089 | else if (*f == 'D') | |
2090 | { | |
2091 | f++; | |
2092 | ||
2093 | /* Check for a Decimal128. */ | |
2094 | if (*f == 'D') | |
2095 | { | |
2096 | f++; | |
2097 | seen_double_big_d = 1; | |
2098 | } | |
2099 | else | |
2100 | seen_big_d = 1; | |
2101 | } | |
46e9880c | 2102 | |
c906108c SS |
2103 | switch (*f) |
2104 | { | |
46e9880c DJ |
2105 | case 'u': |
2106 | if (seen_hash) | |
2107 | bad = 1; | |
2108 | /* FALLTHROUGH */ | |
2109 | ||
2110 | case 'o': | |
2111 | case 'x': | |
2112 | case 'X': | |
2113 | if (seen_space || seen_plus) | |
2114 | bad = 1; | |
2115 | /* FALLTHROUGH */ | |
2116 | ||
2117 | case 'd': | |
2118 | case 'i': | |
2119 | if (lcount == 0) | |
2120 | this_argclass = int_arg; | |
2121 | else if (lcount == 1) | |
2122 | this_argclass = long_arg; | |
2123 | else | |
2124 | this_argclass = long_long_arg; | |
2125 | ||
2126 | if (seen_big_l) | |
2127 | bad = 1; | |
2128 | break; | |
2129 | ||
2130 | case 'c': | |
6c7a06a3 TT |
2131 | this_argclass = lcount == 0 ? int_arg : wide_char_arg; |
2132 | if (lcount > 1 || seen_h || seen_big_l) | |
46e9880c DJ |
2133 | bad = 1; |
2134 | if (seen_prec || seen_zero || seen_space || seen_plus) | |
2135 | bad = 1; | |
2136 | break; | |
2137 | ||
2138 | case 'p': | |
2139 | this_argclass = ptr_arg; | |
2140 | if (lcount || seen_h || seen_big_l) | |
2141 | bad = 1; | |
2142 | if (seen_prec || seen_zero || seen_space || seen_plus) | |
2143 | bad = 1; | |
2144 | break; | |
2145 | ||
c906108c | 2146 | case 's': |
6c7a06a3 TT |
2147 | this_argclass = lcount == 0 ? string_arg : wide_string_arg; |
2148 | if (lcount > 1 || seen_h || seen_big_l) | |
46e9880c DJ |
2149 | bad = 1; |
2150 | if (seen_zero || seen_space || seen_plus) | |
2151 | bad = 1; | |
c906108c SS |
2152 | break; |
2153 | ||
2154 | case 'e': | |
2155 | case 'f': | |
2156 | case 'g': | |
46e9880c DJ |
2157 | case 'E': |
2158 | case 'G': | |
0aea4bf3 LM |
2159 | if (seen_big_h || seen_big_d || seen_double_big_d) |
2160 | this_argclass = decfloat_arg; | |
2161 | else if (seen_big_l) | |
46e9880c DJ |
2162 | this_argclass = long_double_arg; |
2163 | else | |
2164 | this_argclass = double_arg; | |
2165 | ||
2166 | if (lcount || seen_h) | |
2167 | bad = 1; | |
c906108c SS |
2168 | break; |
2169 | ||
2170 | case '*': | |
8a3fe4f8 | 2171 | error (_("`*' not supported for precision or width in printf")); |
c906108c SS |
2172 | |
2173 | case 'n': | |
8a3fe4f8 | 2174 | error (_("Format specifier `n' not supported in printf")); |
c906108c | 2175 | |
46e9880c DJ |
2176 | case '\0': |
2177 | error (_("Incomplete format specifier at end of format string")); | |
c906108c SS |
2178 | |
2179 | default: | |
46e9880c | 2180 | error (_("Unrecognized format specifier '%c' in printf"), *f); |
c906108c | 2181 | } |
46e9880c DJ |
2182 | |
2183 | if (bad) | |
2184 | error (_("Inappropriate modifiers to format specifier '%c' in printf"), | |
2185 | *f); | |
2186 | ||
c906108c | 2187 | f++; |
09d71d23 AS |
2188 | |
2189 | if (lcount > 1 && USE_PRINTF_I64) | |
2190 | { | |
2191 | /* Windows' printf does support long long, but not the usual way. | |
2192 | Convert %lld to %I64d. */ | |
2193 | int length_before_ll = f - last_arg - 1 - lcount; | |
2194 | strncpy (current_substring, last_arg, length_before_ll); | |
2195 | strcpy (current_substring + length_before_ll, "I64"); | |
2196 | current_substring[length_before_ll + 3] = | |
2197 | last_arg[length_before_ll + lcount]; | |
2198 | current_substring += length_before_ll + 4; | |
2199 | } | |
6c7a06a3 TT |
2200 | else if (this_argclass == wide_string_arg |
2201 | || this_argclass == wide_char_arg) | |
2202 | { | |
2203 | /* Convert %ls or %lc to %s. */ | |
2204 | int length_before_ls = f - last_arg - 2; | |
2205 | strncpy (current_substring, last_arg, length_before_ls); | |
2206 | strcpy (current_substring + length_before_ls, "s"); | |
2207 | current_substring += length_before_ls + 2; | |
2208 | } | |
09d71d23 AS |
2209 | else |
2210 | { | |
2211 | strncpy (current_substring, last_arg, f - last_arg); | |
2212 | current_substring += f - last_arg; | |
2213 | } | |
46e9880c DJ |
2214 | *current_substring++ = '\0'; |
2215 | last_arg = f; | |
2216 | argclass[nargs_wanted++] = this_argclass; | |
c906108c SS |
2217 | } |
2218 | ||
2219 | /* Now, parse all arguments and evaluate them. | |
2220 | Store the VALUEs in VAL_ARGS. */ | |
2221 | ||
2222 | while (*s != '\0') | |
2223 | { | |
2224 | char *s1; | |
2225 | if (nargs == allocated_args) | |
f976f6d4 AC |
2226 | val_args = (struct value **) xrealloc ((char *) val_args, |
2227 | (allocated_args *= 2) | |
2228 | * sizeof (struct value *)); | |
c906108c SS |
2229 | s1 = s; |
2230 | val_args[nargs] = parse_to_comma_and_eval (&s1); | |
c5aa993b | 2231 | |
c906108c SS |
2232 | nargs++; |
2233 | s = s1; | |
2234 | if (*s == ',') | |
2235 | s++; | |
2236 | } | |
c5aa993b | 2237 | |
c906108c | 2238 | if (nargs != nargs_wanted) |
8a3fe4f8 | 2239 | error (_("Wrong number of arguments for specified format-string")); |
c906108c SS |
2240 | |
2241 | /* Now actually print them. */ | |
2242 | current_substring = substrings; | |
2243 | for (i = 0; i < nargs; i++) | |
2244 | { | |
2245 | switch (argclass[i]) | |
2246 | { | |
2247 | case string_arg: | |
2248 | { | |
777ea8f1 | 2249 | gdb_byte *str; |
c906108c SS |
2250 | CORE_ADDR tem; |
2251 | int j; | |
1aa20aa8 | 2252 | tem = value_as_address (val_args[i]); |
c906108c SS |
2253 | |
2254 | /* This is a %s argument. Find the length of the string. */ | |
c5aa993b | 2255 | for (j = 0;; j++) |
c906108c | 2256 | { |
777ea8f1 | 2257 | gdb_byte c; |
c906108c | 2258 | QUIT; |
d4b2399a | 2259 | read_memory (tem + j, &c, 1); |
c906108c SS |
2260 | if (c == 0) |
2261 | break; | |
2262 | } | |
2263 | ||
2264 | /* Copy the string contents into a string inside GDB. */ | |
777ea8f1 | 2265 | str = (gdb_byte *) alloca (j + 1); |
7b92f6e1 MS |
2266 | if (j != 0) |
2267 | read_memory (tem, str, j); | |
c906108c SS |
2268 | str[j] = 0; |
2269 | ||
777ea8f1 | 2270 | printf_filtered (current_substring, (char *) str); |
c906108c SS |
2271 | } |
2272 | break; | |
6c7a06a3 TT |
2273 | case wide_string_arg: |
2274 | { | |
2275 | gdb_byte *str; | |
2276 | CORE_ADDR tem; | |
2277 | int j; | |
e6c014f2 UW |
2278 | struct type *wctype = lookup_typename (current_language, |
2279 | current_gdbarch, | |
2280 | "wchar_t", NULL, 0); | |
6c7a06a3 TT |
2281 | int wcwidth = TYPE_LENGTH (wctype); |
2282 | gdb_byte *buf = alloca (wcwidth); | |
2283 | struct obstack output; | |
2284 | struct cleanup *inner_cleanup; | |
2285 | ||
2286 | tem = value_as_address (val_args[i]); | |
2287 | ||
2288 | /* This is a %s argument. Find the length of the string. */ | |
2289 | for (j = 0;; j += wcwidth) | |
2290 | { | |
2291 | QUIT; | |
2292 | read_memory (tem + j, buf, wcwidth); | |
2293 | if (extract_unsigned_integer (buf, wcwidth) == 0) | |
2294 | break; | |
2295 | } | |
2296 | ||
2297 | /* Copy the string contents into a string inside GDB. */ | |
2298 | str = (gdb_byte *) alloca (j + wcwidth); | |
2299 | if (j != 0) | |
2300 | read_memory (tem, str, j); | |
2301 | memset (&str[j], 0, wcwidth); | |
2302 | ||
2303 | obstack_init (&output); | |
2304 | inner_cleanup = make_cleanup_obstack_free (&output); | |
2305 | ||
2306 | convert_between_encodings (target_wide_charset (), | |
2307 | host_charset (), | |
2308 | str, j, wcwidth, | |
2309 | &output, translit_char); | |
2310 | obstack_grow_str0 (&output, ""); | |
2311 | ||
2312 | printf_filtered (current_substring, obstack_base (&output)); | |
2313 | do_cleanups (inner_cleanup); | |
2314 | } | |
2315 | break; | |
2316 | case wide_char_arg: | |
2317 | { | |
e6c014f2 UW |
2318 | struct type *wctype = lookup_typename (current_language, |
2319 | current_gdbarch, | |
2320 | "wchar_t", NULL, 0); | |
6c7a06a3 TT |
2321 | struct type *valtype; |
2322 | struct obstack output; | |
2323 | struct cleanup *inner_cleanup; | |
2324 | const gdb_byte *bytes; | |
2325 | ||
2326 | valtype = value_type (val_args[i]); | |
2327 | if (TYPE_LENGTH (valtype) != TYPE_LENGTH (wctype) | |
2328 | || TYPE_CODE (valtype) != TYPE_CODE_INT) | |
2329 | error (_("expected wchar_t argument for %%lc")); | |
2330 | ||
2331 | bytes = value_contents (val_args[i]); | |
2332 | ||
2333 | obstack_init (&output); | |
2334 | inner_cleanup = make_cleanup_obstack_free (&output); | |
2335 | ||
2336 | convert_between_encodings (target_wide_charset (), | |
2337 | host_charset (), | |
2338 | bytes, TYPE_LENGTH (valtype), | |
2339 | TYPE_LENGTH (valtype), | |
2340 | &output, translit_char); | |
2341 | obstack_grow_str0 (&output, ""); | |
2342 | ||
2343 | printf_filtered (current_substring, obstack_base (&output)); | |
2344 | do_cleanups (inner_cleanup); | |
2345 | } | |
2346 | break; | |
c906108c SS |
2347 | case double_arg: |
2348 | { | |
b806fb9a UW |
2349 | struct type *type = value_type (val_args[i]); |
2350 | DOUBLEST val; | |
2351 | int inv; | |
2352 | ||
2353 | /* If format string wants a float, unchecked-convert the value | |
2354 | to floating point of the same size. */ | |
2355 | type = float_type_from_length (current_gdbarch, type); | |
2356 | val = unpack_double (type, value_contents (val_args[i]), &inv); | |
2357 | if (inv) | |
2358 | error (_("Invalid floating value found in program.")); | |
2359 | ||
2360 | printf_filtered (current_substring, (double) val); | |
c906108c SS |
2361 | break; |
2362 | } | |
46e9880c DJ |
2363 | case long_double_arg: |
2364 | #ifdef HAVE_LONG_DOUBLE | |
2365 | { | |
b806fb9a UW |
2366 | struct type *type = value_type (val_args[i]); |
2367 | DOUBLEST val; | |
2368 | int inv; | |
2369 | ||
2370 | /* If format string wants a float, unchecked-convert the value | |
2371 | to floating point of the same size. */ | |
2372 | type = float_type_from_length (current_gdbarch, type); | |
2373 | val = unpack_double (type, value_contents (val_args[i]), &inv); | |
2374 | if (inv) | |
2375 | error (_("Invalid floating value found in program.")); | |
2376 | ||
2377 | printf_filtered (current_substring, (long double) val); | |
46e9880c DJ |
2378 | break; |
2379 | } | |
2380 | #else | |
2381 | error (_("long double not supported in printf")); | |
2382 | #endif | |
c906108c SS |
2383 | case long_long_arg: |
2384 | #if defined (CC_HAS_LONG_LONG) && defined (PRINTF_HAS_LONG_LONG) | |
2385 | { | |
2386 | long long val = value_as_long (val_args[i]); | |
2387 | printf_filtered (current_substring, val); | |
2388 | break; | |
2389 | } | |
2390 | #else | |
8a3fe4f8 | 2391 | error (_("long long not supported in printf")); |
c906108c SS |
2392 | #endif |
2393 | case int_arg: | |
2394 | { | |
46e9880c DJ |
2395 | int val = value_as_long (val_args[i]); |
2396 | printf_filtered (current_substring, val); | |
2397 | break; | |
2398 | } | |
2399 | case long_arg: | |
2400 | { | |
c906108c SS |
2401 | long val = value_as_long (val_args[i]); |
2402 | printf_filtered (current_substring, val); | |
2403 | break; | |
2404 | } | |
1a619819 | 2405 | |
0aea4bf3 LM |
2406 | /* Handles decimal floating values. */ |
2407 | case decfloat_arg: | |
1a619819 | 2408 | { |
0aea4bf3 | 2409 | const gdb_byte *param_ptr = value_contents (val_args[i]); |
1a619819 | 2410 | #if defined (PRINTF_HAS_DECFLOAT) |
0aea4bf3 LM |
2411 | /* If we have native support for Decimal floating |
2412 | printing, handle it here. */ | |
2413 | printf_filtered (current_substring, param_ptr); | |
1a619819 | 2414 | #else |
1a619819 LM |
2415 | |
2416 | /* As a workaround until vasprintf has native support for DFP | |
0aea4bf3 LM |
2417 | we convert the DFP values to string and print them using |
2418 | the %s format specifier. */ | |
2419 | ||
2420 | char *eos, *sos; | |
2421 | int nnull_chars = 0; | |
2422 | ||
2423 | /* Parameter data. */ | |
2424 | struct type *param_type = value_type (val_args[i]); | |
2425 | unsigned int param_len = TYPE_LENGTH (param_type); | |
2426 | ||
2427 | /* DFP output data. */ | |
2428 | struct value *dfp_value = NULL; | |
2429 | gdb_byte *dfp_ptr; | |
2430 | int dfp_len = 16; | |
2431 | gdb_byte dec[16]; | |
2432 | struct type *dfp_type = NULL; | |
2433 | char decstr[MAX_DECIMAL_STRING]; | |
1a619819 LM |
2434 | |
2435 | /* Points to the end of the string so that we can go back | |
0aea4bf3 | 2436 | and check for DFP length modifiers. */ |
1a619819 LM |
2437 | eos = current_substring + strlen (current_substring); |
2438 | ||
0aea4bf3 LM |
2439 | /* Look for the float/double format specifier. */ |
2440 | while (*eos != 'f' && *eos != 'e' && *eos != 'E' | |
2441 | && *eos != 'g' && *eos != 'G') | |
2442 | eos--; | |
2443 | ||
2444 | sos = eos; | |
2445 | ||
2446 | /* Search for the '%' char and extract the size and type of | |
2447 | the output decimal value based on its modifiers | |
2448 | (%Hf, %Df, %DDf). */ | |
2449 | while (*--sos != '%') | |
2450 | { | |
2451 | if (*sos == 'H') | |
2452 | { | |
2453 | dfp_len = 4; | |
2454 | dfp_type = builtin_type (current_gdbarch)->builtin_decfloat; | |
2455 | } | |
2456 | else if (*sos == 'D' && *(sos - 1) == 'D') | |
2457 | { | |
2458 | dfp_len = 16; | |
2459 | dfp_type = builtin_type (current_gdbarch)->builtin_declong; | |
2460 | sos--; | |
2461 | } | |
2462 | else | |
2463 | { | |
2464 | dfp_len = 8; | |
2465 | dfp_type = builtin_type (current_gdbarch)->builtin_decdouble; | |
2466 | } | |
2467 | } | |
2468 | ||
2469 | /* Replace %Hf, %Df and %DDf with %s's. */ | |
2470 | *++sos = 's'; | |
2471 | ||
2472 | /* Go through the whole format string and pull the correct | |
2473 | number of chars back to compensate for the change in the | |
2474 | format specifier. */ | |
2475 | while (nnull_chars < nargs - i) | |
2476 | { | |
2477 | if (*eos == '\0') | |
2478 | nnull_chars++; | |
2479 | ||
2480 | *++sos = *++eos; | |
2481 | } | |
2482 | ||
2483 | /* Conversion between different DFP types. */ | |
2484 | if (TYPE_CODE (param_type) == TYPE_CODE_DECFLOAT) | |
2485 | decimal_convert (param_ptr, param_len, dec, dfp_len); | |
2486 | else | |
2487 | /* If this is a non-trivial conversion, just output 0. | |
2488 | A correct converted value can be displayed by explicitly | |
2489 | casting to a DFP type. */ | |
2490 | decimal_from_string (dec, dfp_len, "0"); | |
2491 | ||
2492 | dfp_value = value_from_decfloat (dfp_type, dec); | |
2493 | ||
2494 | dfp_ptr = (gdb_byte *) value_contents (dfp_value); | |
2495 | ||
2496 | decimal_to_string (dfp_ptr, dfp_len, decstr); | |
1a619819 LM |
2497 | |
2498 | /* Print the DFP value. */ | |
2499 | printf_filtered (current_substring, decstr); | |
0aea4bf3 | 2500 | |
1a619819 LM |
2501 | break; |
2502 | #endif | |
2503 | } | |
2504 | ||
2025a643 DJ |
2505 | case ptr_arg: |
2506 | { | |
2507 | /* We avoid the host's %p because pointers are too | |
2508 | likely to be the wrong size. The only interesting | |
2509 | modifier for %p is a width; extract that, and then | |
2510 | handle %p as glibc would: %#x or a literal "(nil)". */ | |
2511 | ||
2512 | char *p, *fmt, *fmt_p; | |
2513 | #if defined (CC_HAS_LONG_LONG) && defined (PRINTF_HAS_LONG_LONG) | |
2514 | long long val = value_as_long (val_args[i]); | |
2515 | #else | |
2516 | long val = value_as_long (val_args[i]); | |
2517 | #endif | |
2518 | ||
2519 | fmt = alloca (strlen (current_substring) + 5); | |
2520 | ||
2521 | /* Copy up to the leading %. */ | |
2522 | p = current_substring; | |
2523 | fmt_p = fmt; | |
2524 | while (*p) | |
2525 | { | |
2526 | int is_percent = (*p == '%'); | |
2527 | *fmt_p++ = *p++; | |
2528 | if (is_percent) | |
2529 | { | |
2530 | if (*p == '%') | |
2531 | *fmt_p++ = *p++; | |
2532 | else | |
2533 | break; | |
2534 | } | |
2535 | } | |
2536 | ||
2537 | if (val != 0) | |
2538 | *fmt_p++ = '#'; | |
2539 | ||
2540 | /* Copy any width. */ | |
2541 | while (*p >= '0' && *p < '9') | |
2542 | *fmt_p++ = *p++; | |
2543 | ||
2544 | gdb_assert (*p == 'p' && *(p + 1) == '\0'); | |
2545 | if (val != 0) | |
2546 | { | |
2547 | #if defined (CC_HAS_LONG_LONG) && defined (PRINTF_HAS_LONG_LONG) | |
2548 | *fmt_p++ = 'l'; | |
2549 | #endif | |
2550 | *fmt_p++ = 'l'; | |
2551 | *fmt_p++ = 'x'; | |
2552 | *fmt_p++ = '\0'; | |
2553 | printf_filtered (fmt, val); | |
2554 | } | |
2555 | else | |
2556 | { | |
2557 | *fmt_p++ = 's'; | |
2558 | *fmt_p++ = '\0'; | |
2559 | printf_filtered (fmt, "(nil)"); | |
2560 | } | |
2561 | ||
2562 | break; | |
2563 | } | |
675dcf4f MK |
2564 | default: |
2565 | internal_error (__FILE__, __LINE__, | |
2025a643 | 2566 | _("failed internal consistency check")); |
c906108c SS |
2567 | } |
2568 | /* Skip to the next substring. */ | |
2569 | current_substring += strlen (current_substring) + 1; | |
2570 | } | |
2571 | /* Print the portion of the format string after the last argument. */ | |
306d9ac5 | 2572 | puts_filtered (last_arg); |
c906108c SS |
2573 | } |
2574 | do_cleanups (old_cleanups); | |
2575 | } | |
c906108c | 2576 | |
c906108c | 2577 | void |
fba45db2 | 2578 | _initialize_printcmd (void) |
c906108c | 2579 | { |
c94fdfd0 EZ |
2580 | struct cmd_list_element *c; |
2581 | ||
c906108c SS |
2582 | current_display_number = -1; |
2583 | ||
a3247a22 PP |
2584 | observer_attach_solib_unloaded (clear_dangling_display_expressions); |
2585 | ||
c906108c | 2586 | add_info ("address", address_info, |
1bedd215 | 2587 | _("Describe where symbol SYM is stored.")); |
c906108c | 2588 | |
1bedd215 AC |
2589 | add_info ("symbol", sym_info, _("\ |
2590 | Describe what symbol is at location ADDR.\n\ | |
2591 | Only for symbols with fixed locations (global or static scope).")); | |
c906108c | 2592 | |
1bedd215 AC |
2593 | add_com ("x", class_vars, x_command, _("\ |
2594 | Examine memory: x/FMT ADDRESS.\n\ | |
c906108c SS |
2595 | ADDRESS is an expression for the memory address to examine.\n\ |
2596 | FMT is a repeat count followed by a format letter and a size letter.\n\ | |
2597 | Format letters are o(octal), x(hex), d(decimal), u(unsigned decimal),\n\ | |
1bedd215 AC |
2598 | t(binary), f(float), a(address), i(instruction), c(char) and s(string).\n\ |
2599 | Size letters are b(byte), h(halfword), w(word), g(giant, 8 bytes).\n\ | |
c906108c SS |
2600 | The specified number of objects of the specified size are printed\n\ |
2601 | according to the format.\n\n\ | |
2602 | Defaults for format and size letters are those previously used.\n\ | |
2603 | Default count is 1. Default address is following last thing printed\n\ | |
1bedd215 | 2604 | with this command or \"print\".")); |
c906108c | 2605 | |
c906108c SS |
2606 | #if 0 |
2607 | add_com ("whereis", class_vars, whereis_command, | |
1bedd215 | 2608 | _("Print line number and file of definition of variable.")); |
c906108c | 2609 | #endif |
c5aa993b | 2610 | |
1bedd215 AC |
2611 | add_info ("display", display_info, _("\ |
2612 | Expressions to display when program stops, with code numbers.")); | |
c906108c | 2613 | |
1a966eab AC |
2614 | add_cmd ("undisplay", class_vars, undisplay_command, _("\ |
2615 | Cancel some expressions to be displayed when program stops.\n\ | |
c906108c SS |
2616 | Arguments are the code numbers of the expressions to stop displaying.\n\ |
2617 | No argument means cancel all automatic-display expressions.\n\ | |
2618 | \"delete display\" has the same effect as this command.\n\ | |
1a966eab | 2619 | Do \"info display\" to see current list of code numbers."), |
c5aa993b | 2620 | &cmdlist); |
c906108c | 2621 | |
1bedd215 AC |
2622 | add_com ("display", class_vars, display_command, _("\ |
2623 | Print value of expression EXP each time the program stops.\n\ | |
c906108c SS |
2624 | /FMT may be used before EXP as in the \"print\" command.\n\ |
2625 | /FMT \"i\" or \"s\" or including a size-letter is allowed,\n\ | |
2626 | as in the \"x\" command, and then EXP is used to get the address to examine\n\ | |
2627 | and examining is done as in the \"x\" command.\n\n\ | |
2628 | With no argument, display all currently requested auto-display expressions.\n\ | |
1bedd215 | 2629 | Use \"undisplay\" to cancel display requests previously made.")); |
c906108c | 2630 | |
1a966eab AC |
2631 | add_cmd ("display", class_vars, enable_display, _("\ |
2632 | Enable some expressions to be displayed when program stops.\n\ | |
c906108c SS |
2633 | Arguments are the code numbers of the expressions to resume displaying.\n\ |
2634 | No argument means enable all automatic-display expressions.\n\ | |
1a966eab | 2635 | Do \"info display\" to see current list of code numbers."), &enablelist); |
c906108c | 2636 | |
1a966eab AC |
2637 | add_cmd ("display", class_vars, disable_display_command, _("\ |
2638 | Disable some expressions to be displayed when program stops.\n\ | |
c906108c SS |
2639 | Arguments are the code numbers of the expressions to stop displaying.\n\ |
2640 | No argument means disable all automatic-display expressions.\n\ | |
1a966eab | 2641 | Do \"info display\" to see current list of code numbers."), &disablelist); |
c906108c | 2642 | |
1a966eab AC |
2643 | add_cmd ("display", class_vars, undisplay_command, _("\ |
2644 | Cancel some expressions to be displayed when program stops.\n\ | |
c906108c SS |
2645 | Arguments are the code numbers of the expressions to stop displaying.\n\ |
2646 | No argument means cancel all automatic-display expressions.\n\ | |
1a966eab | 2647 | Do \"info display\" to see current list of code numbers."), &deletelist); |
c906108c | 2648 | |
1bedd215 AC |
2649 | add_com ("printf", class_vars, printf_command, _("\ |
2650 | printf \"printf format string\", arg1, arg2, arg3, ..., argn\n\ | |
2651 | This is useful for formatted output in user-defined commands.")); | |
c906108c | 2652 | |
1bedd215 AC |
2653 | add_com ("output", class_vars, output_command, _("\ |
2654 | Like \"print\" but don't put in value history and don't print newline.\n\ | |
2655 | This is useful in user-defined commands.")); | |
c906108c | 2656 | |
1bedd215 AC |
2657 | add_prefix_cmd ("set", class_vars, set_command, _("\ |
2658 | Evaluate expression EXP and assign result to variable VAR, using assignment\n\ | |
c906108c SS |
2659 | syntax appropriate for the current language (VAR = EXP or VAR := EXP for\n\ |
2660 | example). VAR may be a debugger \"convenience\" variable (names starting\n\ | |
2661 | with $), a register (a few standard names starting with $), or an actual\n\ | |
1bedd215 AC |
2662 | variable in the program being debugged. EXP is any valid expression.\n\ |
2663 | Use \"set variable\" for variables with names identical to set subcommands.\n\ | |
2664 | \n\ | |
2665 | With a subcommand, this command modifies parts of the gdb environment.\n\ | |
2666 | You can see these environment settings with the \"show\" command."), | |
c5aa993b | 2667 | &setlist, "set ", 1, &cmdlist); |
c906108c | 2668 | if (dbx_commands) |
1bedd215 AC |
2669 | add_com ("assign", class_vars, set_command, _("\ |
2670 | Evaluate expression EXP and assign result to variable VAR, using assignment\n\ | |
c906108c SS |
2671 | syntax appropriate for the current language (VAR = EXP or VAR := EXP for\n\ |
2672 | example). VAR may be a debugger \"convenience\" variable (names starting\n\ | |
2673 | with $), a register (a few standard names starting with $), or an actual\n\ | |
1bedd215 AC |
2674 | variable in the program being debugged. EXP is any valid expression.\n\ |
2675 | Use \"set variable\" for variables with names identical to set subcommands.\n\ | |
c906108c | 2676 | \nWith a subcommand, this command modifies parts of the gdb environment.\n\ |
1bedd215 | 2677 | You can see these environment settings with the \"show\" command.")); |
c906108c SS |
2678 | |
2679 | /* "call" is the same as "set", but handy for dbx users to call fns. */ | |
1bedd215 AC |
2680 | c = add_com ("call", class_vars, call_command, _("\ |
2681 | Call a function in the program.\n\ | |
c906108c SS |
2682 | The argument is the function name and arguments, in the notation of the\n\ |
2683 | current working language. The result is printed and saved in the value\n\ | |
1bedd215 | 2684 | history, if it is not void.")); |
65d12d83 | 2685 | set_cmd_completer (c, expression_completer); |
c906108c | 2686 | |
1a966eab AC |
2687 | add_cmd ("variable", class_vars, set_command, _("\ |
2688 | Evaluate expression EXP and assign result to variable VAR, using assignment\n\ | |
c906108c SS |
2689 | syntax appropriate for the current language (VAR = EXP or VAR := EXP for\n\ |
2690 | example). VAR may be a debugger \"convenience\" variable (names starting\n\ | |
2691 | with $), a register (a few standard names starting with $), or an actual\n\ | |
2692 | variable in the program being debugged. EXP is any valid expression.\n\ | |
1a966eab | 2693 | This may usually be abbreviated to simply \"set\"."), |
c5aa993b | 2694 | &setlist); |
c906108c | 2695 | |
1bedd215 AC |
2696 | c = add_com ("print", class_vars, print_command, _("\ |
2697 | Print value of expression EXP.\n\ | |
c906108c SS |
2698 | Variables accessible are those of the lexical environment of the selected\n\ |
2699 | stack frame, plus all those whose scope is global or an entire file.\n\ | |
2700 | \n\ | |
2701 | $NUM gets previous value number NUM. $ and $$ are the last two values.\n\ | |
2702 | $$NUM refers to NUM'th value back from the last one.\n\ | |
1bedd215 AC |
2703 | Names starting with $ refer to registers (with the values they would have\n\ |
2704 | if the program were to return to the stack frame now selected, restoring\n\ | |
c906108c SS |
2705 | all registers saved by frames farther in) or else to debugger\n\ |
2706 | \"convenience\" variables (any such name not a known register).\n\ | |
1bedd215 AC |
2707 | Use assignment expressions to give values to convenience variables.\n\ |
2708 | \n\ | |
c906108c SS |
2709 | {TYPE}ADREXP refers to a datum of data type TYPE, located at address ADREXP.\n\ |
2710 | @ is a binary operator for treating consecutive data objects\n\ | |
2711 | anywhere in memory as an array. FOO@NUM gives an array whose first\n\ | |
2712 | element is FOO, whose second element is stored in the space following\n\ | |
2713 | where FOO is stored, etc. FOO must be an expression whose value\n\ | |
1bedd215 AC |
2714 | resides in memory.\n\ |
2715 | \n\ | |
c906108c | 2716 | EXP may be preceded with /FMT, where FMT is a format letter\n\ |
1bedd215 | 2717 | but no count or size letter (see \"x\" command).")); |
65d12d83 | 2718 | set_cmd_completer (c, expression_completer); |
c906108c SS |
2719 | add_com_alias ("p", "print", class_vars, 1); |
2720 | ||
1bedd215 AC |
2721 | c = add_com ("inspect", class_vars, inspect_command, _("\ |
2722 | Same as \"print\" command, except that if you are running in the epoch\n\ | |
2723 | environment, the value is printed in its own window.")); | |
65d12d83 | 2724 | set_cmd_completer (c, expression_completer); |
c906108c | 2725 | |
35096d9d AC |
2726 | add_setshow_uinteger_cmd ("max-symbolic-offset", no_class, |
2727 | &max_symbolic_offset, _("\ | |
2728 | Set the largest offset that will be printed in <symbol+1234> form."), _("\ | |
2729 | Show the largest offset that will be printed in <symbol+1234> form."), NULL, | |
2730 | NULL, | |
920d2a44 | 2731 | show_max_symbolic_offset, |
35096d9d | 2732 | &setprintlist, &showprintlist); |
5bf193a2 AC |
2733 | add_setshow_boolean_cmd ("symbol-filename", no_class, |
2734 | &print_symbol_filename, _("\ | |
2735 | Set printing of source filename and line number with <symbol>."), _("\ | |
2736 | Show printing of source filename and line number with <symbol>."), NULL, | |
2737 | NULL, | |
920d2a44 | 2738 | show_print_symbol_filename, |
5bf193a2 | 2739 | &setprintlist, &showprintlist); |
c906108c | 2740 | } |