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