Commit | Line | Data |
---|---|---|
c906108c | 1 | /* Print values for GNU debugger GDB. |
e2ad119d | 2 | |
b811d2c2 | 3 | Copyright (C) 1986-2020 Free Software Foundation, Inc. |
c906108c | 4 | |
c5aa993b | 5 | This file is part of GDB. |
c906108c | 6 | |
c5aa993b JM |
7 | This program is free software; you can redistribute it and/or modify |
8 | it under the terms of the GNU General Public License as published by | |
a9762ec7 | 9 | the Free Software Foundation; either version 3 of the License, or |
c5aa993b | 10 | (at your option) any later version. |
c906108c | 11 | |
c5aa993b JM |
12 | This program is distributed in the hope that it will be useful, |
13 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
15 | GNU General Public License for more details. | |
c906108c | 16 | |
c5aa993b | 17 | You should have received a copy of the GNU General Public License |
a9762ec7 | 18 | along with this program. If not, see <http://www.gnu.org/licenses/>. */ |
c906108c SS |
19 | |
20 | #include "defs.h" | |
c906108c SS |
21 | #include "frame.h" |
22 | #include "symtab.h" | |
23 | #include "gdbtypes.h" | |
24 | #include "value.h" | |
25 | #include "language.h" | |
1f6f6e21 | 26 | #include "c-lang.h" |
c906108c SS |
27 | #include "expression.h" |
28 | #include "gdbcore.h" | |
29 | #include "gdbcmd.h" | |
30 | #include "target.h" | |
31 | #include "breakpoint.h" | |
32 | #include "demangle.h" | |
50f182aa | 33 | #include "gdb-demangle.h" |
c906108c SS |
34 | #include "valprint.h" |
35 | #include "annotate.h" | |
c5aa993b JM |
36 | #include "symfile.h" /* for overlay functions */ |
37 | #include "objfiles.h" /* ditto */ | |
c94fdfd0 | 38 | #include "completer.h" /* for completion functions */ |
8b93c638 | 39 | #include "ui-out.h" |
fe898f56 | 40 | #include "block.h" |
92bf2b80 | 41 | #include "disasm.h" |
f69fdf9b | 42 | #include "target-float.h" |
76727919 | 43 | #include "observable.h" |
a3247a22 | 44 | #include "solist.h" |
a3247a22 | 45 | #include "parser-defs.h" |
6c7a06a3 | 46 | #include "charset.h" |
704e9165 | 47 | #include "arch-utils.h" |
e9cafbcc | 48 | #include "cli/cli-utils.h" |
7d8062de | 49 | #include "cli/cli-option.h" |
01770bbd | 50 | #include "cli/cli-script.h" |
80ae2043 | 51 | #include "cli/cli-style.h" |
268a13a5 | 52 | #include "gdbsupport/format.h" |
05cba821 | 53 | #include "source.h" |
268a13a5 TT |
54 | #include "gdbsupport/byte-vector.h" |
55 | #include "gdbsupport/gdb_optional.h" | |
037d7135 | 56 | #include "safe-ctype.h" |
c906108c | 57 | |
c906108c SS |
58 | /* Last specified output format. */ |
59 | ||
a6bac58e | 60 | static char last_format = 0; |
c906108c SS |
61 | |
62 | /* Last specified examination size. 'b', 'h', 'w' or `q'. */ | |
63 | ||
64 | static char last_size = 'w'; | |
65 | ||
9be2ae8f TT |
66 | /* Last specified count for the 'x' command. */ |
67 | ||
68 | static int last_count; | |
69 | ||
5d3729b5 | 70 | /* Default address to examine next, and associated architecture. */ |
c906108c | 71 | |
5d3729b5 | 72 | static struct gdbarch *next_gdbarch; |
c906108c SS |
73 | static CORE_ADDR next_address; |
74 | ||
a4642986 MR |
75 | /* Number of delay instructions following current disassembled insn. */ |
76 | ||
77 | static int branch_delay_insns; | |
78 | ||
c906108c SS |
79 | /* Last address examined. */ |
80 | ||
81 | static CORE_ADDR last_examine_address; | |
82 | ||
83 | /* Contents of last address examined. | |
84 | This is not valid past the end of the `x' command! */ | |
85 | ||
9b558729 | 86 | static value_ref_ptr last_examine_value; |
c906108c SS |
87 | |
88 | /* Largest offset between a symbolic value and an address, that will be | |
89 | printed as `0x1234 <symbol+offset>'. */ | |
90 | ||
91 | static unsigned int max_symbolic_offset = UINT_MAX; | |
920d2a44 AC |
92 | static void |
93 | show_max_symbolic_offset (struct ui_file *file, int from_tty, | |
94 | struct cmd_list_element *c, const char *value) | |
95 | { | |
3e43a32a MS |
96 | fprintf_filtered (file, |
97 | _("The largest offset that will be " | |
98 | "printed in <symbol+1234> form is %s.\n"), | |
920d2a44 AC |
99 | value); |
100 | } | |
c906108c SS |
101 | |
102 | /* Append the source filename and linenumber of the symbol when | |
103 | printing a symbolic value as `<symbol at filename:linenum>' if set. */ | |
491144b5 | 104 | static bool print_symbol_filename = false; |
920d2a44 AC |
105 | static void |
106 | show_print_symbol_filename (struct ui_file *file, int from_tty, | |
107 | struct cmd_list_element *c, const char *value) | |
108 | { | |
3e43a32a MS |
109 | fprintf_filtered (file, _("Printing of source filename and " |
110 | "line number with <symbol> is %s.\n"), | |
920d2a44 AC |
111 | value); |
112 | } | |
c906108c SS |
113 | |
114 | /* Number of auto-display expression currently being displayed. | |
9d8fa392 | 115 | So that we can disable it if we get a signal within it. |
c906108c SS |
116 | -1 when not doing one. */ |
117 | ||
5a18e302 | 118 | static int current_display_number; |
c906108c | 119 | |
8be4b118 TT |
120 | /* Last allocated display number. */ |
121 | ||
122 | static int display_number; | |
123 | ||
c906108c | 124 | struct display |
c5aa993b | 125 | { |
8be4b118 TT |
126 | display (const char *exp_string_, expression_up &&exp_, |
127 | const struct format_data &format_, struct program_space *pspace_, | |
128 | const struct block *block_) | |
129 | : exp_string (exp_string_), | |
130 | exp (std::move (exp_)), | |
131 | number (++display_number), | |
132 | format (format_), | |
133 | pspace (pspace_), | |
134 | block (block_), | |
135 | enabled_p (true) | |
136 | { | |
137 | } | |
6c95b8df | 138 | |
fa8a61dc | 139 | /* The expression as the user typed it. */ |
8be4b118 | 140 | std::string exp_string; |
6c95b8df | 141 | |
c5aa993b | 142 | /* Expression to be evaluated and displayed. */ |
4d01a485 | 143 | expression_up exp; |
6c95b8df | 144 | |
c5aa993b JM |
145 | /* Item number of this auto-display item. */ |
146 | int number; | |
6c95b8df | 147 | |
c5aa993b JM |
148 | /* Display format specified. */ |
149 | struct format_data format; | |
6c95b8df PA |
150 | |
151 | /* Program space associated with `block'. */ | |
152 | struct program_space *pspace; | |
153 | ||
0df8b418 | 154 | /* Innermost block required by this expression when evaluated. */ |
270140bd | 155 | const struct block *block; |
6c95b8df | 156 | |
0df8b418 | 157 | /* Status of this display (enabled or disabled). */ |
8be4b118 | 158 | bool enabled_p; |
c5aa993b | 159 | }; |
c906108c | 160 | |
8be4b118 TT |
161 | /* Expressions whose values should be displayed automatically each |
162 | time the program stops. */ | |
c906108c | 163 | |
8be4b118 | 164 | static std::vector<std::unique_ptr<struct display>> all_displays; |
c9174737 | 165 | |
0df8b418 | 166 | /* Prototypes for local functions. */ |
c906108c | 167 | |
a14ed312 | 168 | static void do_one_display (struct display *); |
c906108c | 169 | \f |
c5aa993b | 170 | |
c906108c SS |
171 | /* Decode a format specification. *STRING_PTR should point to it. |
172 | OFORMAT and OSIZE are used as defaults for the format and size | |
173 | if none are given in the format specification. | |
174 | If OSIZE is zero, then the size field of the returned value | |
175 | should be set only if a size is explicitly specified by the | |
176 | user. | |
177 | The structure returned describes all the data | |
178 | found in the specification. In addition, *STRING_PTR is advanced | |
179 | past the specification and past all whitespace following it. */ | |
180 | ||
181 | static struct format_data | |
6f937416 | 182 | decode_format (const char **string_ptr, int oformat, int osize) |
c906108c SS |
183 | { |
184 | struct format_data val; | |
6f937416 | 185 | const char *p = *string_ptr; |
c906108c SS |
186 | |
187 | val.format = '?'; | |
188 | val.size = '?'; | |
189 | val.count = 1; | |
a6bac58e | 190 | val.raw = 0; |
c906108c | 191 | |
bb556f1f TK |
192 | if (*p == '-') |
193 | { | |
194 | val.count = -1; | |
195 | p++; | |
196 | } | |
c906108c | 197 | if (*p >= '0' && *p <= '9') |
bb556f1f | 198 | val.count *= atoi (p); |
c5aa993b JM |
199 | while (*p >= '0' && *p <= '9') |
200 | p++; | |
c906108c SS |
201 | |
202 | /* Now process size or format letters that follow. */ | |
203 | ||
204 | while (1) | |
205 | { | |
206 | if (*p == 'b' || *p == 'h' || *p == 'w' || *p == 'g') | |
207 | val.size = *p++; | |
a6bac58e TT |
208 | else if (*p == 'r') |
209 | { | |
210 | val.raw = 1; | |
211 | p++; | |
212 | } | |
c906108c SS |
213 | else if (*p >= 'a' && *p <= 'z') |
214 | val.format = *p++; | |
215 | else | |
216 | break; | |
217 | } | |
218 | ||
2f433492 | 219 | *string_ptr = skip_spaces (p); |
c906108c SS |
220 | |
221 | /* Set defaults for format and size if not specified. */ | |
222 | if (val.format == '?') | |
223 | { | |
224 | if (val.size == '?') | |
225 | { | |
226 | /* Neither has been specified. */ | |
227 | val.format = oformat; | |
228 | val.size = osize; | |
229 | } | |
230 | else | |
231 | /* If a size is specified, any format makes a reasonable | |
232 | default except 'i'. */ | |
233 | val.format = oformat == 'i' ? 'x' : oformat; | |
234 | } | |
235 | else if (val.size == '?') | |
236 | switch (val.format) | |
237 | { | |
238 | case 'a': | |
5d3729b5 UW |
239 | /* Pick the appropriate size for an address. This is deferred |
240 | until do_examine when we know the actual architecture to use. | |
241 | A special size value of 'a' is used to indicate this case. */ | |
242 | val.size = osize ? 'a' : osize; | |
c906108c SS |
243 | break; |
244 | case 'f': | |
245 | /* Floating point has to be word or giantword. */ | |
246 | if (osize == 'w' || osize == 'g') | |
247 | val.size = osize; | |
248 | else | |
249 | /* Default it to giantword if the last used size is not | |
250 | appropriate. */ | |
251 | val.size = osize ? 'g' : osize; | |
252 | break; | |
253 | case 'c': | |
254 | /* Characters default to one byte. */ | |
255 | val.size = osize ? 'b' : osize; | |
256 | break; | |
9a22f0d0 | 257 | case 's': |
3e43a32a MS |
258 | /* Display strings with byte size chars unless explicitly |
259 | specified. */ | |
9a22f0d0 PM |
260 | val.size = '\0'; |
261 | break; | |
262 | ||
c906108c SS |
263 | default: |
264 | /* The default is the size most recently specified. */ | |
265 | val.size = osize; | |
266 | } | |
267 | ||
268 | return val; | |
269 | } | |
270 | \f | |
79a45b7d | 271 | /* Print value VAL on stream according to OPTIONS. |
c906108c | 272 | Do not end with a newline. |
c906108c | 273 | SIZE is the letter for the size of datum being printed. |
ea37ba09 DJ |
274 | This is used to pad hex numbers so they line up. SIZE is 0 |
275 | for print / output and set for examine. */ | |
c906108c SS |
276 | |
277 | static void | |
79a45b7d TT |
278 | print_formatted (struct value *val, int size, |
279 | const struct value_print_options *options, | |
fba45db2 | 280 | struct ui_file *stream) |
c906108c | 281 | { |
df407dfe | 282 | struct type *type = check_typedef (value_type (val)); |
c906108c SS |
283 | int len = TYPE_LENGTH (type); |
284 | ||
285 | if (VALUE_LVAL (val) == lval_memory) | |
42ae5230 | 286 | next_address = value_address (val) + len; |
c906108c | 287 | |
ea37ba09 | 288 | if (size) |
c906108c | 289 | { |
79a45b7d | 290 | switch (options->format) |
ea37ba09 DJ |
291 | { |
292 | case 's': | |
6c7a06a3 TT |
293 | { |
294 | struct type *elttype = value_type (val); | |
ad3bbd48 | 295 | |
42ae5230 | 296 | next_address = (value_address (val) |
09ca9e2e | 297 | + val_print_string (elttype, NULL, |
42ae5230 | 298 | value_address (val), -1, |
9a22f0d0 | 299 | stream, options) * len); |
6c7a06a3 | 300 | } |
ea37ba09 | 301 | return; |
c906108c | 302 | |
ea37ba09 DJ |
303 | case 'i': |
304 | /* We often wrap here if there are long symbolic names. */ | |
305 | wrap_here (" "); | |
42ae5230 | 306 | next_address = (value_address (val) |
13274fc3 UW |
307 | + gdb_print_insn (get_type_arch (type), |
308 | value_address (val), stream, | |
ea37ba09 DJ |
309 | &branch_delay_insns)); |
310 | return; | |
311 | } | |
c906108c | 312 | } |
ea37ba09 | 313 | |
79a45b7d | 314 | if (options->format == 0 || options->format == 's' |
3d87245c | 315 | || type->code () == TYPE_CODE_VOID |
78134374 SM |
316 | || type->code () == TYPE_CODE_REF |
317 | || type->code () == TYPE_CODE_ARRAY | |
318 | || type->code () == TYPE_CODE_STRING | |
319 | || type->code () == TYPE_CODE_STRUCT | |
320 | || type->code () == TYPE_CODE_UNION | |
321 | || type->code () == TYPE_CODE_NAMESPACE) | |
79a45b7d | 322 | value_print (val, stream, options); |
ea37ba09 | 323 | else |
b021a221 MS |
324 | /* User specified format, so don't look to the type to tell us |
325 | what to do. */ | |
4dba70ee | 326 | value_print_scalar_formatted (val, options, size, stream); |
c906108c SS |
327 | } |
328 | ||
b806fb9a UW |
329 | /* Return builtin floating point type of same length as TYPE. |
330 | If no such type is found, return TYPE itself. */ | |
331 | static struct type * | |
50810684 | 332 | float_type_from_length (struct type *type) |
b806fb9a | 333 | { |
50810684 | 334 | struct gdbarch *gdbarch = get_type_arch (type); |
b806fb9a | 335 | const struct builtin_type *builtin = builtin_type (gdbarch); |
b806fb9a | 336 | |
744a8059 | 337 | if (TYPE_LENGTH (type) == TYPE_LENGTH (builtin->builtin_float)) |
b806fb9a | 338 | type = builtin->builtin_float; |
744a8059 | 339 | else if (TYPE_LENGTH (type) == TYPE_LENGTH (builtin->builtin_double)) |
b806fb9a | 340 | type = builtin->builtin_double; |
744a8059 | 341 | else if (TYPE_LENGTH (type) == TYPE_LENGTH (builtin->builtin_long_double)) |
b806fb9a UW |
342 | type = builtin->builtin_long_double; |
343 | ||
344 | return type; | |
345 | } | |
346 | ||
c906108c | 347 | /* Print a scalar of data of type TYPE, pointed to in GDB by VALADDR, |
ab2188aa PA |
348 | according to OPTIONS and SIZE on STREAM. Formats s and i are not |
349 | supported at this level. */ | |
c906108c SS |
350 | |
351 | void | |
7c543f7b | 352 | print_scalar_formatted (const gdb_byte *valaddr, struct type *type, |
79a45b7d TT |
353 | const struct value_print_options *options, |
354 | int size, struct ui_file *stream) | |
c906108c | 355 | { |
50810684 | 356 | struct gdbarch *gdbarch = get_type_arch (type); |
c906108c | 357 | unsigned int len = TYPE_LENGTH (type); |
34877895 | 358 | enum bfd_endian byte_order = type_byte_order (type); |
c906108c | 359 | |
ab2188aa PA |
360 | /* String printing should go through val_print_scalar_formatted. */ |
361 | gdb_assert (options->format != 's'); | |
ea37ba09 | 362 | |
ef166cf4 | 363 | /* If the value is a pointer, and pointers and addresses are not the |
d0aee0c4 | 364 | same, then at this point, the value's length (in target bytes) is |
17a912b6 | 365 | gdbarch_addr_bit/TARGET_CHAR_BIT, not TYPE_LENGTH (type). */ |
78134374 | 366 | if (type->code () == TYPE_CODE_PTR) |
69feb676 | 367 | len = gdbarch_addr_bit (gdbarch) / TARGET_CHAR_BIT; |
ef166cf4 | 368 | |
c906108c SS |
369 | /* If we are printing it as unsigned, truncate it in case it is actually |
370 | a negative signed value (e.g. "print/u (short)-1" should print 65535 | |
371 | (if shorts are 16 bits) instead of 4294967295). */ | |
d9109c80 | 372 | if (options->format != 'c' |
c6d940a9 | 373 | && (options->format != 'd' || type->is_unsigned ())) |
c906108c | 374 | { |
d9109c80 TT |
375 | if (len < TYPE_LENGTH (type) && byte_order == BFD_ENDIAN_BIG) |
376 | valaddr += TYPE_LENGTH (type) - len; | |
c906108c SS |
377 | } |
378 | ||
20a5fcbd TT |
379 | /* Allow LEN == 0, and in this case, don't assume that VALADDR is |
380 | valid. */ | |
381 | const gdb_byte zero = 0; | |
382 | if (len == 0) | |
383 | { | |
384 | len = 1; | |
385 | valaddr = &zero; | |
386 | } | |
387 | ||
d9109c80 | 388 | if (size != 0 && (options->format == 'x' || options->format == 't')) |
c906108c | 389 | { |
d9109c80 TT |
390 | /* Truncate to fit. */ |
391 | unsigned newlen; | |
392 | switch (size) | |
c906108c | 393 | { |
d9109c80 TT |
394 | case 'b': |
395 | newlen = 1; | |
396 | break; | |
397 | case 'h': | |
398 | newlen = 2; | |
399 | break; | |
400 | case 'w': | |
401 | newlen = 4; | |
402 | break; | |
403 | case 'g': | |
404 | newlen = 8; | |
405 | break; | |
406 | default: | |
407 | error (_("Undefined output size \"%c\"."), size); | |
c906108c | 408 | } |
d9109c80 TT |
409 | if (newlen < len && byte_order == BFD_ENDIAN_BIG) |
410 | valaddr += len - newlen; | |
411 | len = newlen; | |
412 | } | |
c906108c | 413 | |
d9109c80 TT |
414 | /* Historically gdb has printed floats by first casting them to a |
415 | long, and then printing the long. PR cli/16242 suggests changing | |
4e962e74 TT |
416 | this to using C-style hex float format. |
417 | ||
20a5fcbd TT |
418 | Biased range types and sub-word scalar types must also be handled |
419 | here; the value is correctly computed by unpack_long. */ | |
4e962e74 TT |
420 | gdb::byte_vector converted_bytes; |
421 | /* Some cases below will unpack the value again. In the biased | |
422 | range case, we want to avoid this, so we store the unpacked value | |
423 | here for possible use later. */ | |
424 | gdb::optional<LONGEST> val_long; | |
b26daff9 JB |
425 | if (((type->code () == TYPE_CODE_FLT |
426 | || is_fixed_point_type (type)) | |
4e962e74 TT |
427 | && (options->format == 'o' |
428 | || options->format == 'x' | |
429 | || options->format == 't' | |
430 | || options->format == 'z' | |
431 | || options->format == 'd' | |
432 | || options->format == 'u')) | |
20a5fcbd TT |
433 | || (type->code () == TYPE_CODE_RANGE && type->bounds ()->bias != 0) |
434 | || type->bit_size_differs_p ()) | |
d9109c80 | 435 | { |
4e962e74 TT |
436 | val_long.emplace (unpack_long (type, valaddr)); |
437 | converted_bytes.resize (TYPE_LENGTH (type)); | |
438 | store_signed_integer (converted_bytes.data (), TYPE_LENGTH (type), | |
439 | byte_order, *val_long); | |
440 | valaddr = converted_bytes.data (); | |
d9109c80 | 441 | } |
c906108c | 442 | |
fdf0cbc2 UW |
443 | /* Printing a non-float type as 'f' will interpret the data as if it were |
444 | of a floating-point type of the same length, if that exists. Otherwise, | |
445 | the data is printed as integer. */ | |
446 | char format = options->format; | |
78134374 | 447 | if (format == 'f' && type->code () != TYPE_CODE_FLT) |
fdf0cbc2 UW |
448 | { |
449 | type = float_type_from_length (type); | |
78134374 | 450 | if (type->code () != TYPE_CODE_FLT) |
dda83cd7 | 451 | format = 0; |
fdf0cbc2 UW |
452 | } |
453 | ||
454 | switch (format) | |
d9109c80 TT |
455 | { |
456 | case 'o': | |
457 | print_octal_chars (stream, valaddr, len, byte_order); | |
458 | break; | |
d6382fff TT |
459 | case 'd': |
460 | print_decimal_chars (stream, valaddr, len, true, byte_order); | |
461 | break; | |
c906108c | 462 | case 'u': |
d9109c80 | 463 | print_decimal_chars (stream, valaddr, len, false, byte_order); |
c906108c | 464 | break; |
d9109c80 | 465 | case 0: |
78134374 | 466 | if (type->code () != TYPE_CODE_FLT) |
d9109c80 | 467 | { |
c6d940a9 | 468 | print_decimal_chars (stream, valaddr, len, !type->is_unsigned (), |
d9109c80 TT |
469 | byte_order); |
470 | break; | |
471 | } | |
472 | /* FALLTHROUGH */ | |
473 | case 'f': | |
d9109c80 | 474 | print_floating (valaddr, type, stream); |
c906108c SS |
475 | break; |
476 | ||
d9109c80 TT |
477 | case 't': |
478 | print_binary_chars (stream, valaddr, len, byte_order, size > 0); | |
479 | break; | |
480 | case 'x': | |
481 | print_hex_chars (stream, valaddr, len, byte_order, size > 0); | |
482 | break; | |
483 | case 'z': | |
484 | print_hex_chars (stream, valaddr, len, byte_order, true); | |
c906108c | 485 | break; |
c906108c | 486 | case 'c': |
79a45b7d TT |
487 | { |
488 | struct value_print_options opts = *options; | |
69feb676 | 489 | |
4e962e74 TT |
490 | if (!val_long.has_value ()) |
491 | val_long.emplace (unpack_long (type, valaddr)); | |
d9109c80 | 492 | |
ad3bbd48 | 493 | opts.format = 0; |
c6d940a9 | 494 | if (type->is_unsigned ()) |
69feb676 UW |
495 | type = builtin_type (gdbarch)->builtin_true_unsigned_char; |
496 | else | |
497 | type = builtin_type (gdbarch)->builtin_true_char; | |
498 | ||
4e962e74 | 499 | value_print (value_from_longest (type, *val_long), stream, &opts); |
79a45b7d | 500 | } |
c906108c SS |
501 | break; |
502 | ||
d9109c80 | 503 | case 'a': |
c906108c | 504 | { |
4e962e74 TT |
505 | if (!val_long.has_value ()) |
506 | val_long.emplace (unpack_long (type, valaddr)); | |
507 | print_address (gdbarch, *val_long, stream); | |
c906108c SS |
508 | } |
509 | break; | |
510 | ||
511 | default: | |
fdf0cbc2 | 512 | error (_("Undefined output format \"%c\"."), format); |
c906108c SS |
513 | } |
514 | } | |
515 | ||
516 | /* Specify default address for `x' command. | |
675dcf4f | 517 | The `info lines' command uses this. */ |
c906108c SS |
518 | |
519 | void | |
8b9b9e1a | 520 | set_next_address (struct gdbarch *gdbarch, CORE_ADDR addr) |
c906108c | 521 | { |
8b9b9e1a UW |
522 | struct type *ptr_type = builtin_type (gdbarch)->builtin_data_ptr; |
523 | ||
5d3729b5 | 524 | next_gdbarch = gdbarch; |
c906108c SS |
525 | next_address = addr; |
526 | ||
527 | /* Make address available to the user as $_. */ | |
528 | set_internalvar (lookup_internalvar ("_"), | |
8b9b9e1a | 529 | value_from_pointer (ptr_type, addr)); |
c906108c SS |
530 | } |
531 | ||
532 | /* Optionally print address ADDR symbolically as <SYMBOL+OFFSET> on STREAM, | |
533 | after LEADIN. Print nothing if no symbolic name is found nearby. | |
534 | Optionally also print source file and line number, if available. | |
535 | DO_DEMANGLE controls whether to print a symbol in its native "raw" form, | |
536 | or to interpret it as a possible C++ name and convert it back to source | |
537 | form. However note that DO_DEMANGLE can be overridden by the specific | |
9cb709b6 TT |
538 | settings of the demangle and asm_demangle variables. Returns |
539 | non-zero if anything was printed; zero otherwise. */ | |
c906108c | 540 | |
9cb709b6 | 541 | int |
22e722e1 DJ |
542 | print_address_symbolic (struct gdbarch *gdbarch, CORE_ADDR addr, |
543 | struct ui_file *stream, | |
a121b7c1 | 544 | int do_demangle, const char *leadin) |
dfcd3bfb | 545 | { |
c7110220 | 546 | std::string name, filename; |
dfcd3bfb JM |
547 | int unmapped = 0; |
548 | int offset = 0; | |
549 | int line = 0; | |
550 | ||
2dc80cf8 | 551 | if (build_address_symbolic (gdbarch, addr, do_demangle, false, &name, |
dda83cd7 | 552 | &offset, &filename, &line, &unmapped)) |
c7110220 | 553 | return 0; |
dfcd3bfb JM |
554 | |
555 | fputs_filtered (leadin, stream); | |
556 | if (unmapped) | |
557 | fputs_filtered ("<*", stream); | |
558 | else | |
559 | fputs_filtered ("<", stream); | |
af79b68d | 560 | fputs_styled (name.c_str (), function_name_style.style (), stream); |
dfcd3bfb | 561 | if (offset != 0) |
a1530dc7 | 562 | fprintf_filtered (stream, "%+d", offset); |
dfcd3bfb JM |
563 | |
564 | /* Append source filename and line number if desired. Give specific | |
565 | line # of this addr, if we have it; else line # of the nearest symbol. */ | |
c7110220 | 566 | if (print_symbol_filename && !filename.empty ()) |
dfcd3bfb | 567 | { |
af79b68d TT |
568 | fputs_filtered (line == -1 ? " in " : " at ", stream); |
569 | fputs_styled (filename.c_str (), file_name_style.style (), stream); | |
dfcd3bfb | 570 | if (line != -1) |
af79b68d | 571 | fprintf_filtered (stream, ":%d", line); |
dfcd3bfb JM |
572 | } |
573 | if (unmapped) | |
574 | fputs_filtered ("*>", stream); | |
575 | else | |
576 | fputs_filtered (">", stream); | |
577 | ||
9cb709b6 | 578 | return 1; |
dfcd3bfb JM |
579 | } |
580 | ||
c7110220 TT |
581 | /* See valprint.h. */ |
582 | ||
dfcd3bfb | 583 | int |
22e722e1 DJ |
584 | build_address_symbolic (struct gdbarch *gdbarch, |
585 | CORE_ADDR addr, /* IN */ | |
2dc80cf8 KB |
586 | bool do_demangle, /* IN */ |
587 | bool prefer_sym_over_minsym, /* IN */ | |
c7110220 | 588 | std::string *name, /* OUT */ |
dfcd3bfb | 589 | int *offset, /* OUT */ |
c7110220 | 590 | std::string *filename, /* OUT */ |
dfcd3bfb JM |
591 | int *line, /* OUT */ |
592 | int *unmapped) /* OUT */ | |
c906108c | 593 | { |
77e371c0 | 594 | struct bound_minimal_symbol msymbol; |
c906108c | 595 | struct symbol *symbol; |
c906108c | 596 | CORE_ADDR name_location = 0; |
714835d5 | 597 | struct obj_section *section = NULL; |
0d5cff50 | 598 | const char *name_temp = ""; |
dfcd3bfb | 599 | |
89c83b10 | 600 | /* Let's say it is mapped (not unmapped). */ |
dfcd3bfb | 601 | *unmapped = 0; |
c906108c | 602 | |
dfcd3bfb | 603 | /* Determine if the address is in an overlay, and whether it is |
675dcf4f | 604 | mapped. */ |
c906108c SS |
605 | if (overlay_debugging) |
606 | { | |
607 | section = find_pc_overlay (addr); | |
608 | if (pc_in_unmapped_range (addr, section)) | |
609 | { | |
dfcd3bfb | 610 | *unmapped = 1; |
c906108c SS |
611 | addr = overlay_mapped_address (addr, section); |
612 | } | |
613 | } | |
614 | ||
2dc80cf8 KB |
615 | /* Try to find the address in both the symbol table and the minsyms. |
616 | In most cases, we'll prefer to use the symbol instead of the | |
617 | minsym. However, there are cases (see below) where we'll choose | |
618 | to use the minsym instead. */ | |
c906108c SS |
619 | |
620 | /* This is defective in the sense that it only finds text symbols. So | |
621 | really this is kind of pointless--we should make sure that the | |
622 | minimal symbols have everything we need (by changing that we could | |
623 | save some memory, but for many debug format--ELF/DWARF or | |
624 | anything/stabs--it would be inconvenient to eliminate those minimal | |
625 | symbols anyway). */ | |
77e371c0 | 626 | msymbol = lookup_minimal_symbol_by_pc_section (addr, section); |
c906108c SS |
627 | symbol = find_pc_sect_function (addr, section); |
628 | ||
629 | if (symbol) | |
630 | { | |
22e722e1 DJ |
631 | /* If this is a function (i.e. a code address), strip out any |
632 | non-address bits. For instance, display a pointer to the | |
633 | first instruction of a Thumb function as <function>; the | |
634 | second instruction will be <function+2>, even though the | |
635 | pointer is <function+3>. This matches the ISA behavior. */ | |
636 | addr = gdbarch_addr_bits_remove (gdbarch, addr); | |
637 | ||
2b1ffcfd | 638 | name_location = BLOCK_ENTRY_PC (SYMBOL_BLOCK_VALUE (symbol)); |
406fc7fb | 639 | if (do_demangle || asm_demangle) |
987012b8 | 640 | name_temp = symbol->print_name (); |
c906108c | 641 | else |
987012b8 | 642 | name_temp = symbol->linkage_name (); |
c906108c SS |
643 | } |
644 | ||
77e371c0 TT |
645 | if (msymbol.minsym != NULL |
646 | && MSYMBOL_HAS_SIZE (msymbol.minsym) | |
647 | && MSYMBOL_SIZE (msymbol.minsym) == 0 | |
648 | && MSYMBOL_TYPE (msymbol.minsym) != mst_text | |
649 | && MSYMBOL_TYPE (msymbol.minsym) != mst_text_gnu_ifunc | |
650 | && MSYMBOL_TYPE (msymbol.minsym) != mst_file_text) | |
651 | msymbol.minsym = NULL; | |
9cb709b6 | 652 | |
77e371c0 | 653 | if (msymbol.minsym != NULL) |
c906108c | 654 | { |
2dc80cf8 KB |
655 | /* Use the minsym if no symbol is found. |
656 | ||
657 | Additionally, use the minsym instead of a (found) symbol if | |
658 | the following conditions all hold: | |
659 | 1) The prefer_sym_over_minsym flag is false. | |
660 | 2) The minsym address is identical to that of the address under | |
661 | consideration. | |
662 | 3) The symbol address is not identical to that of the address | |
663 | under consideration. */ | |
664 | if (symbol == NULL || | |
dda83cd7 | 665 | (!prefer_sym_over_minsym |
2dc80cf8 KB |
666 | && BMSYMBOL_VALUE_ADDRESS (msymbol) == addr |
667 | && name_location != addr)) | |
c906108c | 668 | { |
fe8400b4 WN |
669 | /* If this is a function (i.e. a code address), strip out any |
670 | non-address bits. For instance, display a pointer to the | |
671 | first instruction of a Thumb function as <function>; the | |
672 | second instruction will be <function+2>, even though the | |
673 | pointer is <function+3>. This matches the ISA behavior. */ | |
77e371c0 TT |
674 | if (MSYMBOL_TYPE (msymbol.minsym) == mst_text |
675 | || MSYMBOL_TYPE (msymbol.minsym) == mst_text_gnu_ifunc | |
676 | || MSYMBOL_TYPE (msymbol.minsym) == mst_file_text | |
677 | || MSYMBOL_TYPE (msymbol.minsym) == mst_solib_trampoline) | |
fe8400b4 WN |
678 | addr = gdbarch_addr_bits_remove (gdbarch, addr); |
679 | ||
c906108c | 680 | symbol = 0; |
77e371c0 | 681 | name_location = BMSYMBOL_VALUE_ADDRESS (msymbol); |
406fc7fb | 682 | if (do_demangle || asm_demangle) |
c9d95fa3 | 683 | name_temp = msymbol.minsym->print_name (); |
c906108c | 684 | else |
c9d95fa3 | 685 | name_temp = msymbol.minsym->linkage_name (); |
c906108c SS |
686 | } |
687 | } | |
77e371c0 | 688 | if (symbol == NULL && msymbol.minsym == NULL) |
dfcd3bfb | 689 | return 1; |
c906108c | 690 | |
c906108c SS |
691 | /* If the nearest symbol is too far away, don't print anything symbolic. */ |
692 | ||
693 | /* For when CORE_ADDR is larger than unsigned int, we do math in | |
694 | CORE_ADDR. But when we detect unsigned wraparound in the | |
695 | CORE_ADDR math, we ignore this test and print the offset, | |
696 | because addr+max_symbolic_offset has wrapped through the end | |
697 | of the address space back to the beginning, giving bogus comparison. */ | |
698 | if (addr > name_location + max_symbolic_offset | |
699 | && name_location + max_symbolic_offset > name_location) | |
dfcd3bfb | 700 | return 1; |
c906108c | 701 | |
a1530dc7 | 702 | *offset = (LONGEST) addr - name_location; |
dfcd3bfb | 703 | |
c7110220 | 704 | *name = name_temp; |
c906108c | 705 | |
c906108c SS |
706 | if (print_symbol_filename) |
707 | { | |
708 | struct symtab_and_line sal; | |
709 | ||
710 | sal = find_pc_sect_line (addr, section, 0); | |
711 | ||
712 | if (sal.symtab) | |
dfcd3bfb | 713 | { |
c7110220 | 714 | *filename = symtab_to_filename_for_display (sal.symtab); |
dfcd3bfb JM |
715 | *line = sal.line; |
716 | } | |
c906108c | 717 | } |
dfcd3bfb | 718 | return 0; |
c906108c SS |
719 | } |
720 | ||
c906108c SS |
721 | |
722 | /* Print address ADDR symbolically on STREAM. | |
723 | First print it as a number. Then perhaps print | |
724 | <SYMBOL + OFFSET> after the number. */ | |
725 | ||
726 | void | |
5af949e3 UW |
727 | print_address (struct gdbarch *gdbarch, |
728 | CORE_ADDR addr, struct ui_file *stream) | |
c906108c | 729 | { |
35fb8261 | 730 | fputs_styled (paddress (gdbarch, addr), address_style.style (), stream); |
22e722e1 | 731 | print_address_symbolic (gdbarch, addr, stream, asm_demangle, " "); |
c906108c SS |
732 | } |
733 | ||
2b28d209 PP |
734 | /* Return a prefix for instruction address: |
735 | "=> " for current instruction, else " ". */ | |
736 | ||
737 | const char * | |
738 | pc_prefix (CORE_ADDR addr) | |
739 | { | |
740 | if (has_stack_frames ()) | |
741 | { | |
742 | struct frame_info *frame; | |
743 | CORE_ADDR pc; | |
744 | ||
745 | frame = get_selected_frame (NULL); | |
ce406537 | 746 | if (get_frame_pc_if_available (frame, &pc) && pc == addr) |
2b28d209 PP |
747 | return "=> "; |
748 | } | |
749 | return " "; | |
750 | } | |
751 | ||
c906108c SS |
752 | /* Print address ADDR symbolically on STREAM. Parameter DEMANGLE |
753 | controls whether to print the symbolic name "raw" or demangled. | |
9cb709b6 | 754 | Return non-zero if anything was printed; zero otherwise. */ |
c906108c | 755 | |
9cb709b6 | 756 | int |
edf0c1b7 TT |
757 | print_address_demangle (const struct value_print_options *opts, |
758 | struct gdbarch *gdbarch, CORE_ADDR addr, | |
5af949e3 | 759 | struct ui_file *stream, int do_demangle) |
c906108c | 760 | { |
1d51a733 | 761 | if (opts->addressprint) |
c906108c | 762 | { |
35fb8261 | 763 | fputs_styled (paddress (gdbarch, addr), address_style.style (), stream); |
22e722e1 | 764 | print_address_symbolic (gdbarch, addr, stream, do_demangle, " "); |
c906108c SS |
765 | } |
766 | else | |
767 | { | |
9cb709b6 | 768 | return print_address_symbolic (gdbarch, addr, stream, do_demangle, ""); |
c906108c | 769 | } |
9cb709b6 | 770 | return 1; |
c906108c SS |
771 | } |
772 | \f | |
773 | ||
bb556f1f TK |
774 | /* Find the address of the instruction that is INST_COUNT instructions before |
775 | the instruction at ADDR. | |
776 | Since some architectures have variable-length instructions, we can't just | |
777 | simply subtract INST_COUNT * INSN_LEN from ADDR. Instead, we use line | |
778 | number information to locate the nearest known instruction boundary, | |
779 | and disassemble forward from there. If we go out of the symbol range | |
780 | during disassembling, we return the lowest address we've got so far and | |
781 | set the number of instructions read to INST_READ. */ | |
782 | ||
783 | static CORE_ADDR | |
784 | find_instruction_backward (struct gdbarch *gdbarch, CORE_ADDR addr, | |
dda83cd7 | 785 | int inst_count, int *inst_read) |
bb556f1f TK |
786 | { |
787 | /* The vector PCS is used to store instruction addresses within | |
788 | a pc range. */ | |
789 | CORE_ADDR loop_start, loop_end, p; | |
52d214d3 | 790 | std::vector<CORE_ADDR> pcs; |
bb556f1f | 791 | struct symtab_and_line sal; |
bb556f1f TK |
792 | |
793 | *inst_read = 0; | |
794 | loop_start = loop_end = addr; | |
795 | ||
796 | /* In each iteration of the outer loop, we get a pc range that ends before | |
797 | LOOP_START, then we count and store every instruction address of the range | |
798 | iterated in the loop. | |
799 | If the number of instructions counted reaches INST_COUNT, return the | |
800 | stored address that is located INST_COUNT instructions back from ADDR. | |
801 | If INST_COUNT is not reached, we subtract the number of counted | |
802 | instructions from INST_COUNT, and go to the next iteration. */ | |
803 | do | |
804 | { | |
52d214d3 | 805 | pcs.clear (); |
bb556f1f TK |
806 | sal = find_pc_sect_line (loop_start, NULL, 1); |
807 | if (sal.line <= 0) | |
dda83cd7 SM |
808 | { |
809 | /* We reach here when line info is not available. In this case, | |
810 | we print a message and just exit the loop. The return value | |
811 | is calculated after the loop. */ | |
812 | printf_filtered (_("No line number information available " | |
813 | "for address ")); | |
814 | wrap_here (" "); | |
815 | print_address (gdbarch, loop_start - 1, gdb_stdout); | |
816 | printf_filtered ("\n"); | |
817 | break; | |
818 | } | |
bb556f1f TK |
819 | |
820 | loop_end = loop_start; | |
821 | loop_start = sal.pc; | |
822 | ||
823 | /* This loop pushes instruction addresses in the range from | |
dda83cd7 | 824 | LOOP_START to LOOP_END. */ |
bb556f1f | 825 | for (p = loop_start; p < loop_end;) |
dda83cd7 | 826 | { |
52d214d3 | 827 | pcs.push_back (p); |
dda83cd7 SM |
828 | p += gdb_insn_length (gdbarch, p); |
829 | } | |
bb556f1f | 830 | |
52d214d3 TT |
831 | inst_count -= pcs.size (); |
832 | *inst_read += pcs.size (); | |
bb556f1f TK |
833 | } |
834 | while (inst_count > 0); | |
835 | ||
836 | /* After the loop, the vector PCS has instruction addresses of the last | |
837 | source line we processed, and INST_COUNT has a negative value. | |
838 | We return the address at the index of -INST_COUNT in the vector for | |
839 | the reason below. | |
840 | Let's assume the following instruction addresses and run 'x/-4i 0x400e'. | |
841 | Line X of File | |
dda83cd7 SM |
842 | 0x4000 |
843 | 0x4001 | |
844 | 0x4005 | |
bb556f1f | 845 | Line Y of File |
dda83cd7 SM |
846 | 0x4009 |
847 | 0x400c | |
bb556f1f | 848 | => 0x400e |
dda83cd7 | 849 | 0x4011 |
bb556f1f TK |
850 | find_instruction_backward is called with INST_COUNT = 4 and expected to |
851 | return 0x4001. When we reach here, INST_COUNT is set to -1 because | |
852 | it was subtracted by 2 (from Line Y) and 3 (from Line X). The value | |
853 | 4001 is located at the index 1 of the last iterated line (= Line X), | |
854 | which is simply calculated by -INST_COUNT. | |
855 | The case when the length of PCS is 0 means that we reached an area for | |
856 | which line info is not available. In such case, we return LOOP_START, | |
857 | which was the lowest instruction address that had line info. */ | |
52d214d3 | 858 | p = pcs.size () > 0 ? pcs[-inst_count] : loop_start; |
bb556f1f TK |
859 | |
860 | /* INST_READ includes all instruction addresses in a pc range. Need to | |
861 | exclude the beginning part up to the address we're returning. That | |
862 | is, exclude {0x4000} in the example above. */ | |
863 | if (inst_count < 0) | |
864 | *inst_read += inst_count; | |
865 | ||
bb556f1f TK |
866 | return p; |
867 | } | |
868 | ||
869 | /* Backward read LEN bytes of target memory from address MEMADDR + LEN, | |
870 | placing the results in GDB's memory from MYADDR + LEN. Returns | |
871 | a count of the bytes actually read. */ | |
872 | ||
873 | static int | |
874 | read_memory_backward (struct gdbarch *gdbarch, | |
dda83cd7 | 875 | CORE_ADDR memaddr, gdb_byte *myaddr, int len) |
bb556f1f TK |
876 | { |
877 | int errcode; | |
878 | int nread; /* Number of bytes actually read. */ | |
879 | ||
880 | /* First try a complete read. */ | |
881 | errcode = target_read_memory (memaddr, myaddr, len); | |
882 | if (errcode == 0) | |
883 | { | |
884 | /* Got it all. */ | |
885 | nread = len; | |
886 | } | |
887 | else | |
888 | { | |
889 | /* Loop, reading one byte at a time until we get as much as we can. */ | |
890 | memaddr += len; | |
891 | myaddr += len; | |
892 | for (nread = 0; nread < len; ++nread) | |
dda83cd7 SM |
893 | { |
894 | errcode = target_read_memory (--memaddr, --myaddr, 1); | |
895 | if (errcode != 0) | |
896 | { | |
897 | /* The read was unsuccessful, so exit the loop. */ | |
898 | printf_filtered (_("Cannot access memory at address %s\n"), | |
899 | paddress (gdbarch, memaddr)); | |
900 | break; | |
901 | } | |
902 | } | |
bb556f1f TK |
903 | } |
904 | return nread; | |
905 | } | |
906 | ||
907 | /* Returns true if X (which is LEN bytes wide) is the number zero. */ | |
908 | ||
909 | static int | |
910 | integer_is_zero (const gdb_byte *x, int len) | |
911 | { | |
912 | int i = 0; | |
913 | ||
914 | while (i < len && x[i] == 0) | |
915 | ++i; | |
916 | return (i == len); | |
917 | } | |
918 | ||
919 | /* Find the start address of a string in which ADDR is included. | |
920 | Basically we search for '\0' and return the next address, | |
921 | but if OPTIONS->PRINT_MAX is smaller than the length of a string, | |
922 | we stop searching and return the address to print characters as many as | |
923 | PRINT_MAX from the string. */ | |
924 | ||
925 | static CORE_ADDR | |
926 | find_string_backward (struct gdbarch *gdbarch, | |
dda83cd7 SM |
927 | CORE_ADDR addr, int count, int char_size, |
928 | const struct value_print_options *options, | |
929 | int *strings_counted) | |
bb556f1f TK |
930 | { |
931 | const int chunk_size = 0x20; | |
bb556f1f TK |
932 | int read_error = 0; |
933 | int chars_read = 0; | |
934 | int chars_to_read = chunk_size; | |
935 | int chars_counted = 0; | |
936 | int count_original = count; | |
937 | CORE_ADDR string_start_addr = addr; | |
938 | ||
939 | gdb_assert (char_size == 1 || char_size == 2 || char_size == 4); | |
26fcd5d7 | 940 | gdb::byte_vector buffer (chars_to_read * char_size); |
bb556f1f TK |
941 | while (count > 0 && read_error == 0) |
942 | { | |
943 | int i; | |
944 | ||
945 | addr -= chars_to_read * char_size; | |
26fcd5d7 | 946 | chars_read = read_memory_backward (gdbarch, addr, buffer.data (), |
dda83cd7 | 947 | chars_to_read * char_size); |
bb556f1f TK |
948 | chars_read /= char_size; |
949 | read_error = (chars_read == chars_to_read) ? 0 : 1; | |
950 | /* Searching for '\0' from the end of buffer in backward direction. */ | |
951 | for (i = 0; i < chars_read && count > 0 ; ++i, ++chars_counted) | |
dda83cd7 SM |
952 | { |
953 | int offset = (chars_to_read - i - 1) * char_size; | |
954 | ||
955 | if (integer_is_zero (&buffer[offset], char_size) | |
956 | || chars_counted == options->print_max) | |
957 | { | |
958 | /* Found '\0' or reached print_max. As OFFSET is the offset to | |
959 | '\0', we add CHAR_SIZE to return the start address of | |
960 | a string. */ | |
961 | --count; | |
962 | string_start_addr = addr + offset + char_size; | |
963 | chars_counted = 0; | |
964 | } | |
965 | } | |
bb556f1f TK |
966 | } |
967 | ||
968 | /* Update STRINGS_COUNTED with the actual number of loaded strings. */ | |
969 | *strings_counted = count_original - count; | |
970 | ||
971 | if (read_error != 0) | |
972 | { | |
973 | /* In error case, STRING_START_ADDR is pointing to the string that | |
dda83cd7 | 974 | was last successfully loaded. Rewind the partially loaded string. */ |
bb556f1f TK |
975 | string_start_addr -= chars_counted * char_size; |
976 | } | |
977 | ||
bb556f1f TK |
978 | return string_start_addr; |
979 | } | |
980 | ||
c906108c SS |
981 | /* Examine data at address ADDR in format FMT. |
982 | Fetch it from memory and print on gdb_stdout. */ | |
983 | ||
984 | static void | |
5d3729b5 | 985 | do_examine (struct format_data fmt, struct gdbarch *gdbarch, CORE_ADDR addr) |
c906108c | 986 | { |
52f0bd74 AC |
987 | char format = 0; |
988 | char size; | |
989 | int count = 1; | |
c906108c | 990 | struct type *val_type = NULL; |
52f0bd74 AC |
991 | int i; |
992 | int maxelts; | |
79a45b7d | 993 | struct value_print_options opts; |
bb556f1f TK |
994 | int need_to_update_next_address = 0; |
995 | CORE_ADDR addr_rewound = 0; | |
c906108c SS |
996 | |
997 | format = fmt.format; | |
998 | size = fmt.size; | |
999 | count = fmt.count; | |
5d3729b5 | 1000 | next_gdbarch = gdbarch; |
c906108c | 1001 | next_address = addr; |
c906108c | 1002 | |
9a22f0d0 PM |
1003 | /* Instruction format implies fetch single bytes |
1004 | regardless of the specified size. | |
1005 | The case of strings is handled in decode_format, only explicit | |
1006 | size operator are not changed to 'b'. */ | |
1007 | if (format == 'i') | |
c906108c SS |
1008 | size = 'b'; |
1009 | ||
5d3729b5 UW |
1010 | if (size == 'a') |
1011 | { | |
1012 | /* Pick the appropriate size for an address. */ | |
1013 | if (gdbarch_ptr_bit (next_gdbarch) == 64) | |
1014 | size = 'g'; | |
1015 | else if (gdbarch_ptr_bit (next_gdbarch) == 32) | |
1016 | size = 'w'; | |
1017 | else if (gdbarch_ptr_bit (next_gdbarch) == 16) | |
1018 | size = 'h'; | |
1019 | else | |
1020 | /* Bad value for gdbarch_ptr_bit. */ | |
1021 | internal_error (__FILE__, __LINE__, | |
1022 | _("failed internal consistency check")); | |
1023 | } | |
1024 | ||
1025 | if (size == 'b') | |
df4df182 | 1026 | val_type = builtin_type (next_gdbarch)->builtin_int8; |
c906108c | 1027 | else if (size == 'h') |
df4df182 | 1028 | val_type = builtin_type (next_gdbarch)->builtin_int16; |
c906108c | 1029 | else if (size == 'w') |
df4df182 | 1030 | val_type = builtin_type (next_gdbarch)->builtin_int32; |
c906108c | 1031 | else if (size == 'g') |
df4df182 | 1032 | val_type = builtin_type (next_gdbarch)->builtin_int64; |
c906108c | 1033 | |
9a22f0d0 PM |
1034 | if (format == 's') |
1035 | { | |
1036 | struct type *char_type = NULL; | |
ad3bbd48 | 1037 | |
9a22f0d0 PM |
1038 | /* Search for "char16_t" or "char32_t" types or fall back to 8-bit char |
1039 | if type is not found. */ | |
1040 | if (size == 'h') | |
1041 | char_type = builtin_type (next_gdbarch)->builtin_char16; | |
1042 | else if (size == 'w') | |
1043 | char_type = builtin_type (next_gdbarch)->builtin_char32; | |
1044 | if (char_type) | |
dda83cd7 | 1045 | val_type = char_type; |
9a22f0d0 | 1046 | else |
dda83cd7 | 1047 | { |
9a22f0d0 | 1048 | if (size != '\0' && size != 'b') |
0df8b418 MS |
1049 | warning (_("Unable to display strings with " |
1050 | "size '%c', using 'b' instead."), size); | |
9a22f0d0 PM |
1051 | size = 'b'; |
1052 | val_type = builtin_type (next_gdbarch)->builtin_int8; | |
dda83cd7 | 1053 | } |
9a22f0d0 PM |
1054 | } |
1055 | ||
c906108c SS |
1056 | maxelts = 8; |
1057 | if (size == 'w') | |
1058 | maxelts = 4; | |
1059 | if (size == 'g') | |
1060 | maxelts = 2; | |
1061 | if (format == 's' || format == 'i') | |
1062 | maxelts = 1; | |
1063 | ||
79a45b7d TT |
1064 | get_formatted_print_options (&opts, format); |
1065 | ||
bb556f1f TK |
1066 | if (count < 0) |
1067 | { | |
1068 | /* This is the negative repeat count case. | |
dda83cd7 SM |
1069 | We rewind the address based on the given repeat count and format, |
1070 | then examine memory from there in forward direction. */ | |
bb556f1f TK |
1071 | |
1072 | count = -count; | |
1073 | if (format == 'i') | |
dda83cd7 SM |
1074 | { |
1075 | next_address = find_instruction_backward (gdbarch, addr, count, | |
1076 | &count); | |
1077 | } | |
bb556f1f | 1078 | else if (format == 's') |
dda83cd7 SM |
1079 | { |
1080 | next_address = find_string_backward (gdbarch, addr, count, | |
1081 | TYPE_LENGTH (val_type), | |
1082 | &opts, &count); | |
1083 | } | |
bb556f1f | 1084 | else |
dda83cd7 SM |
1085 | { |
1086 | next_address = addr - count * TYPE_LENGTH (val_type); | |
1087 | } | |
bb556f1f TK |
1088 | |
1089 | /* The following call to print_formatted updates next_address in every | |
dda83cd7 SM |
1090 | iteration. In backward case, we store the start address here |
1091 | and update next_address with it before exiting the function. */ | |
bb556f1f | 1092 | addr_rewound = (format == 's' |
dda83cd7 SM |
1093 | ? next_address - TYPE_LENGTH (val_type) |
1094 | : next_address); | |
bb556f1f TK |
1095 | need_to_update_next_address = 1; |
1096 | } | |
1097 | ||
c906108c SS |
1098 | /* Print as many objects as specified in COUNT, at most maxelts per line, |
1099 | with the address of the next one at the start of each line. */ | |
1100 | ||
1101 | while (count > 0) | |
1102 | { | |
1103 | QUIT; | |
2b28d209 PP |
1104 | if (format == 'i') |
1105 | fputs_filtered (pc_prefix (next_address), gdb_stdout); | |
5af949e3 | 1106 | print_address (next_gdbarch, next_address, gdb_stdout); |
c906108c SS |
1107 | printf_filtered (":"); |
1108 | for (i = maxelts; | |
1109 | i > 0 && count > 0; | |
1110 | i--, count--) | |
1111 | { | |
1112 | printf_filtered ("\t"); | |
1113 | /* Note that print_formatted sets next_address for the next | |
1114 | object. */ | |
1115 | last_examine_address = next_address; | |
1116 | ||
c906108c | 1117 | /* The value to be displayed is not fetched greedily. |
5d51a2db MR |
1118 | Instead, to avoid the possibility of a fetched value not |
1119 | being used, its retrieval is delayed until the print code | |
c5aa993b JM |
1120 | uses it. When examining an instruction stream, the |
1121 | disassembler will perform its own memory fetch using just | |
1122 | the address stored in LAST_EXAMINE_VALUE. FIXME: Should | |
1123 | the disassembler be modified so that LAST_EXAMINE_VALUE | |
1124 | is left with the byte sequence from the last complete | |
0df8b418 | 1125 | instruction fetched from memory? */ |
9b558729 TT |
1126 | last_examine_value |
1127 | = release_value (value_at_lazy (val_type, next_address)); | |
c906108c | 1128 | |
9b558729 | 1129 | print_formatted (last_examine_value.get (), size, &opts, gdb_stdout); |
a4642986 MR |
1130 | |
1131 | /* Display any branch delay slots following the final insn. */ | |
1132 | if (format == 'i' && count == 1) | |
1133 | count += branch_delay_insns; | |
c906108c SS |
1134 | } |
1135 | printf_filtered ("\n"); | |
c906108c | 1136 | } |
bb556f1f TK |
1137 | |
1138 | if (need_to_update_next_address) | |
1139 | next_address = addr_rewound; | |
c906108c SS |
1140 | } |
1141 | \f | |
1142 | static void | |
8d89f51a | 1143 | validate_format (struct format_data fmt, const char *cmdname) |
c906108c SS |
1144 | { |
1145 | if (fmt.size != 0) | |
8a3fe4f8 | 1146 | error (_("Size letters are meaningless in \"%s\" command."), cmdname); |
c906108c | 1147 | if (fmt.count != 1) |
8a3fe4f8 | 1148 | error (_("Item count other than 1 is meaningless in \"%s\" command."), |
c906108c | 1149 | cmdname); |
ea37ba09 | 1150 | if (fmt.format == 'i') |
8a3fe4f8 | 1151 | error (_("Format letter \"%c\" is meaningless in \"%s\" command."), |
c906108c SS |
1152 | fmt.format, cmdname); |
1153 | } | |
1154 | ||
7d8062de | 1155 | /* Parse print command format string into *OPTS and update *EXPP. |
1c88ceb1 JK |
1156 | CMDNAME should name the current command. */ |
1157 | ||
1158 | void | |
1159 | print_command_parse_format (const char **expp, const char *cmdname, | |
7d8062de | 1160 | value_print_options *opts) |
1c88ceb1 JK |
1161 | { |
1162 | const char *exp = *expp; | |
1163 | ||
d8edc8b7 PW |
1164 | /* opts->raw value might already have been set by 'set print raw-values' |
1165 | or by using 'print -raw-values'. | |
1166 | So, do not set opts->raw to 0, only set it to 1 if /r is given. */ | |
1c88ceb1 JK |
1167 | if (exp && *exp == '/') |
1168 | { | |
7d8062de PA |
1169 | format_data fmt; |
1170 | ||
1c88ceb1 | 1171 | exp++; |
7d8062de PA |
1172 | fmt = decode_format (&exp, last_format, 0); |
1173 | validate_format (fmt, cmdname); | |
1174 | last_format = fmt.format; | |
1175 | ||
1176 | opts->format = fmt.format; | |
d8edc8b7 | 1177 | opts->raw = opts->raw || fmt.raw; |
1c88ceb1 JK |
1178 | } |
1179 | else | |
1180 | { | |
7d8062de | 1181 | opts->format = 0; |
1c88ceb1 JK |
1182 | } |
1183 | ||
1184 | *expp = exp; | |
1185 | } | |
1186 | ||
7d8062de | 1187 | /* See valprint.h. */ |
1c88ceb1 JK |
1188 | |
1189 | void | |
7d8062de | 1190 | print_value (value *val, const value_print_options &opts) |
1c88ceb1 | 1191 | { |
1c88ceb1 JK |
1192 | int histindex = record_latest_value (val); |
1193 | ||
1194 | annotate_value_history_begin (histindex, value_type (val)); | |
1195 | ||
1196 | printf_filtered ("$%d = ", histindex); | |
1197 | ||
1198 | annotate_value_history_value (); | |
1199 | ||
7d8062de | 1200 | print_formatted (val, 0, &opts, gdb_stdout); |
1c88ceb1 JK |
1201 | printf_filtered ("\n"); |
1202 | ||
1203 | annotate_value_history_end (); | |
1204 | } | |
1205 | ||
7d8062de | 1206 | /* Implementation of the "print" and "call" commands. */ |
c906108c SS |
1207 | |
1208 | static void | |
7d8062de | 1209 | print_command_1 (const char *args, int voidprint) |
c906108c | 1210 | { |
3d6d86c6 | 1211 | struct value *val; |
7d8062de PA |
1212 | value_print_options print_opts; |
1213 | ||
1214 | get_user_print_options (&print_opts); | |
1215 | /* Override global settings with explicit options, if any. */ | |
1216 | auto group = make_value_print_options_def_group (&print_opts); | |
1217 | gdb::option::process_options | |
1218 | (&args, gdb::option::PROCESS_OPTIONS_REQUIRE_DELIMITER, group); | |
1219 | ||
1220 | print_command_parse_format (&args, "print", &print_opts); | |
c906108c | 1221 | |
7d8062de | 1222 | const char *exp = args; |
c906108c | 1223 | |
7d8062de | 1224 | if (exp != nullptr && *exp) |
c906108c | 1225 | { |
4d01a485 PA |
1226 | expression_up expr = parse_expression (exp); |
1227 | val = evaluate_expression (expr.get ()); | |
c906108c SS |
1228 | } |
1229 | else | |
1230 | val = access_value_history (0); | |
1231 | ||
df407dfe | 1232 | if (voidprint || (val && value_type (val) && |
78134374 | 1233 | value_type (val)->code () != TYPE_CODE_VOID)) |
7d8062de PA |
1234 | print_value (val, print_opts); |
1235 | } | |
1236 | ||
037d7135 AB |
1237 | /* Called from command completion function to skip over /FMT |
1238 | specifications, allowing the rest of the line to be completed. Returns | |
1239 | true if the /FMT is at the end of the current line and there is nothing | |
1240 | left to complete, otherwise false is returned. | |
1241 | ||
1242 | In either case *ARGS can be updated to point after any part of /FMT that | |
1243 | is present. | |
1244 | ||
1245 | This function is designed so that trying to complete '/' will offer no | |
1246 | completions, the user needs to insert the format specification | |
1247 | themselves. Trying to complete '/FMT' (where FMT is any non-empty set | |
1248 | of alpha-numeric characters) will cause readline to insert a single | |
1249 | space, setting the user up to enter the expression. */ | |
1250 | ||
1251 | static bool | |
1252 | skip_over_slash_fmt (completion_tracker &tracker, const char **args) | |
1253 | { | |
1254 | const char *text = *args; | |
1255 | ||
1256 | if (text[0] == '/') | |
1257 | { | |
1258 | bool in_fmt; | |
1259 | tracker.set_use_custom_word_point (true); | |
1260 | ||
3df8c6af | 1261 | if (text[1] == '\0') |
037d7135 | 1262 | { |
3df8c6af AB |
1263 | /* The user tried to complete after typing just the '/' character |
1264 | of the /FMT string. Step the completer past the '/', but we | |
1265 | don't offer any completions. */ | |
1266 | in_fmt = true; | |
1267 | ++text; | |
1268 | } | |
1269 | else | |
1270 | { | |
1271 | /* The user has typed some characters after the '/', we assume | |
1272 | this is a complete /FMT string, first skip over it. */ | |
b3ff61f8 | 1273 | text = skip_to_space (text); |
037d7135 AB |
1274 | |
1275 | if (*text == '\0') | |
1276 | { | |
3df8c6af AB |
1277 | /* We're at the end of the input string. The user has typed |
1278 | '/FMT' and asked for a completion. Push an empty | |
1279 | completion string, this will cause readline to insert a | |
1280 | space so the user now has '/FMT '. */ | |
037d7135 AB |
1281 | in_fmt = true; |
1282 | tracker.add_completion (make_unique_xstrdup (text)); | |
1283 | } | |
1284 | else | |
1285 | { | |
3df8c6af AB |
1286 | /* The user has already typed things after the /FMT, skip the |
1287 | whitespace and return false. Whoever called this function | |
1288 | should then try to complete what comes next. */ | |
037d7135 | 1289 | in_fmt = false; |
b3ff61f8 | 1290 | text = skip_spaces (text); |
037d7135 AB |
1291 | } |
1292 | } | |
037d7135 AB |
1293 | |
1294 | tracker.advance_custom_word_point_by (text - *args); | |
1295 | *args = text; | |
1296 | return in_fmt; | |
1297 | } | |
1298 | ||
1299 | return false; | |
1300 | } | |
1301 | ||
7d8062de PA |
1302 | /* See valprint.h. */ |
1303 | ||
1304 | void | |
1305 | print_command_completer (struct cmd_list_element *ignore, | |
1306 | completion_tracker &tracker, | |
1307 | const char *text, const char * /*word*/) | |
1308 | { | |
1309 | const auto group = make_value_print_options_def_group (nullptr); | |
1310 | if (gdb::option::complete_options | |
1311 | (tracker, &text, gdb::option::PROCESS_OPTIONS_REQUIRE_DELIMITER, group)) | |
1312 | return; | |
1313 | ||
037d7135 AB |
1314 | if (skip_over_slash_fmt (tracker, &text)) |
1315 | return; | |
1316 | ||
7d8062de PA |
1317 | const char *word = advance_to_expression_complete_word_point (tracker, text); |
1318 | expression_completer (ignore, tracker, text, word); | |
c906108c SS |
1319 | } |
1320 | ||
c906108c | 1321 | static void |
0b39b52e | 1322 | print_command (const char *exp, int from_tty) |
c906108c | 1323 | { |
e93a8774 | 1324 | print_command_1 (exp, 1); |
c906108c SS |
1325 | } |
1326 | ||
675dcf4f | 1327 | /* Same as print, except it doesn't print void results. */ |
c906108c | 1328 | static void |
0b39b52e | 1329 | call_command (const char *exp, int from_tty) |
c906108c | 1330 | { |
e93a8774 | 1331 | print_command_1 (exp, 0); |
c906108c SS |
1332 | } |
1333 | ||
6f937416 PA |
1334 | /* Implementation of the "output" command. */ |
1335 | ||
6f937416 | 1336 | void |
122b53ea | 1337 | output_command (const char *exp, int from_tty) |
c906108c | 1338 | { |
52f0bd74 | 1339 | char format = 0; |
3d6d86c6 | 1340 | struct value *val; |
c906108c | 1341 | struct format_data fmt; |
79a45b7d | 1342 | struct value_print_options opts; |
c906108c | 1343 | |
777ea8f1 | 1344 | fmt.size = 0; |
a6bac58e | 1345 | fmt.raw = 0; |
777ea8f1 | 1346 | |
c906108c SS |
1347 | if (exp && *exp == '/') |
1348 | { | |
1349 | exp++; | |
1350 | fmt = decode_format (&exp, 0, 0); | |
1351 | validate_format (fmt, "output"); | |
1352 | format = fmt.format; | |
1353 | } | |
1354 | ||
4d01a485 | 1355 | expression_up expr = parse_expression (exp); |
c906108c | 1356 | |
4d01a485 | 1357 | val = evaluate_expression (expr.get ()); |
c906108c | 1358 | |
df407dfe | 1359 | annotate_value_begin (value_type (val)); |
c906108c | 1360 | |
79a45b7d | 1361 | get_formatted_print_options (&opts, format); |
a6bac58e | 1362 | opts.raw = fmt.raw; |
79a45b7d | 1363 | print_formatted (val, fmt.size, &opts, gdb_stdout); |
c906108c SS |
1364 | |
1365 | annotate_value_end (); | |
1366 | ||
2acceee2 JM |
1367 | wrap_here (""); |
1368 | gdb_flush (gdb_stdout); | |
c906108c SS |
1369 | } |
1370 | ||
c906108c | 1371 | static void |
981a3fb3 | 1372 | set_command (const char *exp, int from_tty) |
c906108c | 1373 | { |
4d01a485 | 1374 | expression_up expr = parse_expression (exp); |
ad3bbd48 | 1375 | |
0ece64fd TG |
1376 | if (expr->nelts >= 1) |
1377 | switch (expr->elts[0].opcode) | |
1378 | { | |
1379 | case UNOP_PREINCREMENT: | |
1380 | case UNOP_POSTINCREMENT: | |
1381 | case UNOP_PREDECREMENT: | |
1382 | case UNOP_POSTDECREMENT: | |
1383 | case BINOP_ASSIGN: | |
1384 | case BINOP_ASSIGN_MODIFY: | |
1385 | case BINOP_COMMA: | |
1386 | break; | |
1387 | default: | |
1388 | warning | |
1389 | (_("Expression is not an assignment (and might have no effect)")); | |
1390 | } | |
52b3699b | 1391 | |
4d01a485 | 1392 | evaluate_expression (expr.get ()); |
c906108c SS |
1393 | } |
1394 | ||
c906108c | 1395 | static void |
1d12d88f | 1396 | info_symbol_command (const char *arg, int from_tty) |
c906108c SS |
1397 | { |
1398 | struct minimal_symbol *msymbol; | |
c5aa993b | 1399 | struct obj_section *osect; |
c5aa993b JM |
1400 | CORE_ADDR addr, sect_addr; |
1401 | int matches = 0; | |
1402 | unsigned int offset; | |
c906108c SS |
1403 | |
1404 | if (!arg) | |
e2e0b3e5 | 1405 | error_no_arg (_("address")); |
c906108c SS |
1406 | |
1407 | addr = parse_and_eval_address (arg); | |
2030c079 | 1408 | for (objfile *objfile : current_program_space->objfiles ()) |
3b9d3ac2 | 1409 | ALL_OBJFILE_OSECTIONS (objfile, osect) |
c5aa993b | 1410 | { |
3b9d3ac2 TT |
1411 | /* Only process each object file once, even if there's a separate |
1412 | debug file. */ | |
1413 | if (objfile->separate_debug_objfile_backlink) | |
1414 | continue; | |
1415 | ||
1416 | sect_addr = overlay_mapped_address (addr, osect); | |
1417 | ||
1418 | if (obj_section_addr (osect) <= sect_addr | |
1419 | && sect_addr < obj_section_endaddr (osect) | |
1420 | && (msymbol | |
1421 | = lookup_minimal_symbol_by_pc_section (sect_addr, | |
1422 | osect).minsym)) | |
5178ed48 | 1423 | { |
3b9d3ac2 TT |
1424 | const char *obj_name, *mapped, *sec_name, *msym_name; |
1425 | const char *loc_string; | |
1426 | ||
1427 | matches = 1; | |
1428 | offset = sect_addr - MSYMBOL_VALUE_ADDRESS (objfile, msymbol); | |
1429 | mapped = section_is_mapped (osect) ? _("mapped") : _("unmapped"); | |
1430 | sec_name = osect->the_bfd_section->name; | |
c9d95fa3 | 1431 | msym_name = msymbol->print_name (); |
3b9d3ac2 TT |
1432 | |
1433 | /* Don't print the offset if it is zero. | |
1434 | We assume there's no need to handle i18n of "sym + offset". */ | |
1435 | std::string string_holder; | |
1436 | if (offset) | |
1437 | { | |
1438 | string_holder = string_printf ("%s + %u", msym_name, offset); | |
1439 | loc_string = string_holder.c_str (); | |
1440 | } | |
c14c28ba | 1441 | else |
3b9d3ac2 TT |
1442 | loc_string = msym_name; |
1443 | ||
1444 | gdb_assert (osect->objfile && objfile_name (osect->objfile)); | |
1445 | obj_name = objfile_name (osect->objfile); | |
1446 | ||
deeafabb | 1447 | if (current_program_space->multi_objfile_p ()) |
3b9d3ac2 TT |
1448 | if (pc_in_unmapped_range (addr, osect)) |
1449 | if (section_is_overlay (osect)) | |
1450 | printf_filtered (_("%s in load address range of " | |
1451 | "%s overlay section %s of %s\n"), | |
1452 | loc_string, mapped, sec_name, obj_name); | |
1453 | else | |
1454 | printf_filtered (_("%s in load address range of " | |
1455 | "section %s of %s\n"), | |
1456 | loc_string, sec_name, obj_name); | |
1457 | else | |
1458 | if (section_is_overlay (osect)) | |
1459 | printf_filtered (_("%s in %s overlay section %s of %s\n"), | |
1460 | loc_string, mapped, sec_name, obj_name); | |
1461 | else | |
1462 | printf_filtered (_("%s in section %s of %s\n"), | |
1463 | loc_string, sec_name, obj_name); | |
c14c28ba | 1464 | else |
3b9d3ac2 TT |
1465 | if (pc_in_unmapped_range (addr, osect)) |
1466 | if (section_is_overlay (osect)) | |
1467 | printf_filtered (_("%s in load address range of %s overlay " | |
1468 | "section %s\n"), | |
1469 | loc_string, mapped, sec_name); | |
1470 | else | |
1471 | printf_filtered | |
1472 | (_("%s in load address range of section %s\n"), | |
1473 | loc_string, sec_name); | |
1474 | else | |
1475 | if (section_is_overlay (osect)) | |
1476 | printf_filtered (_("%s in %s overlay section %s\n"), | |
1477 | loc_string, mapped, sec_name); | |
1478 | else | |
1479 | printf_filtered (_("%s in section %s\n"), | |
1480 | loc_string, sec_name); | |
1481 | } | |
c5aa993b | 1482 | } |
c906108c | 1483 | if (matches == 0) |
a3f17187 | 1484 | printf_filtered (_("No symbol matches %s.\n"), arg); |
c906108c SS |
1485 | } |
1486 | ||
c906108c | 1487 | static void |
1d12d88f | 1488 | info_address_command (const char *exp, int from_tty) |
c906108c | 1489 | { |
768a979c UW |
1490 | struct gdbarch *gdbarch; |
1491 | int regno; | |
52f0bd74 | 1492 | struct symbol *sym; |
7c7b6655 | 1493 | struct bound_minimal_symbol msymbol; |
52f0bd74 | 1494 | long val; |
714835d5 | 1495 | struct obj_section *section; |
08922a10 | 1496 | CORE_ADDR load_addr, context_pc = 0; |
1993b719 | 1497 | struct field_of_this_result is_a_field_of_this; |
c906108c SS |
1498 | |
1499 | if (exp == 0) | |
8a3fe4f8 | 1500 | error (_("Argument required.")); |
c906108c | 1501 | |
08922a10 | 1502 | sym = lookup_symbol (exp, get_selected_block (&context_pc), VAR_DOMAIN, |
d12307c1 | 1503 | &is_a_field_of_this).symbol; |
c906108c SS |
1504 | if (sym == NULL) |
1505 | { | |
1993b719 | 1506 | if (is_a_field_of_this.type != NULL) |
c906108c SS |
1507 | { |
1508 | printf_filtered ("Symbol \""); | |
1509 | fprintf_symbol_filtered (gdb_stdout, exp, | |
1510 | current_language->la_language, DMGL_ANSI); | |
e2b23ee9 AF |
1511 | printf_filtered ("\" is a field of the local class variable "); |
1512 | if (current_language->la_language == language_objc) | |
2625d86c | 1513 | printf_filtered ("`self'\n"); /* ObjC equivalent of "this" */ |
e2b23ee9 | 1514 | else |
2625d86c | 1515 | printf_filtered ("`this'\n"); |
c906108c SS |
1516 | return; |
1517 | } | |
1518 | ||
7c7b6655 | 1519 | msymbol = lookup_bound_minimal_symbol (exp); |
c906108c | 1520 | |
7c7b6655 | 1521 | if (msymbol.minsym != NULL) |
c906108c | 1522 | { |
7c7b6655 | 1523 | struct objfile *objfile = msymbol.objfile; |
e27d198c | 1524 | |
08feed99 | 1525 | gdbarch = objfile->arch (); |
77e371c0 | 1526 | load_addr = BMSYMBOL_VALUE_ADDRESS (msymbol); |
c906108c SS |
1527 | |
1528 | printf_filtered ("Symbol \""); | |
1529 | fprintf_symbol_filtered (gdb_stdout, exp, | |
1530 | current_language->la_language, DMGL_ANSI); | |
1531 | printf_filtered ("\" is at "); | |
35fb8261 TT |
1532 | fputs_styled (paddress (gdbarch, load_addr), address_style.style (), |
1533 | gdb_stdout); | |
c906108c | 1534 | printf_filtered (" in a file compiled without debugging"); |
efd66ac6 | 1535 | section = MSYMBOL_OBJ_SECTION (objfile, msymbol.minsym); |
c906108c SS |
1536 | if (section_is_overlay (section)) |
1537 | { | |
1538 | load_addr = overlay_unmapped_address (load_addr, section); | |
1539 | printf_filtered (",\n -- loaded at "); | |
35fb8261 TT |
1540 | fputs_styled (paddress (gdbarch, load_addr), |
1541 | address_style.style (), | |
1542 | gdb_stdout); | |
714835d5 UW |
1543 | printf_filtered (" in overlay section %s", |
1544 | section->the_bfd_section->name); | |
c906108c SS |
1545 | } |
1546 | printf_filtered (".\n"); | |
1547 | } | |
1548 | else | |
8a3fe4f8 | 1549 | error (_("No symbol \"%s\" in current context."), exp); |
c906108c SS |
1550 | return; |
1551 | } | |
1552 | ||
1553 | printf_filtered ("Symbol \""); | |
987012b8 | 1554 | fprintf_symbol_filtered (gdb_stdout, sym->print_name (), |
c906108c SS |
1555 | current_language->la_language, DMGL_ANSI); |
1556 | printf_filtered ("\" is "); | |
c5aa993b | 1557 | val = SYMBOL_VALUE (sym); |
1994afbf DE |
1558 | if (SYMBOL_OBJFILE_OWNED (sym)) |
1559 | section = SYMBOL_OBJ_SECTION (symbol_objfile (sym), sym); | |
1560 | else | |
1561 | section = NULL; | |
08be3fe3 | 1562 | gdbarch = symbol_arch (sym); |
c906108c | 1563 | |
24d6c2a0 TT |
1564 | if (SYMBOL_COMPUTED_OPS (sym) != NULL) |
1565 | { | |
1566 | SYMBOL_COMPUTED_OPS (sym)->describe_location (sym, context_pc, | |
1567 | gdb_stdout); | |
1568 | printf_filtered (".\n"); | |
1569 | return; | |
1570 | } | |
1571 | ||
c906108c SS |
1572 | switch (SYMBOL_CLASS (sym)) |
1573 | { | |
1574 | case LOC_CONST: | |
1575 | case LOC_CONST_BYTES: | |
1576 | printf_filtered ("constant"); | |
1577 | break; | |
1578 | ||
1579 | case LOC_LABEL: | |
1580 | printf_filtered ("a label at address "); | |
5af949e3 | 1581 | load_addr = SYMBOL_VALUE_ADDRESS (sym); |
35fb8261 TT |
1582 | fputs_styled (paddress (gdbarch, load_addr), address_style.style (), |
1583 | gdb_stdout); | |
c906108c SS |
1584 | if (section_is_overlay (section)) |
1585 | { | |
1586 | load_addr = overlay_unmapped_address (load_addr, section); | |
1587 | printf_filtered (",\n -- loaded at "); | |
35fb8261 TT |
1588 | fputs_styled (paddress (gdbarch, load_addr), address_style.style (), |
1589 | gdb_stdout); | |
714835d5 UW |
1590 | printf_filtered (" in overlay section %s", |
1591 | section->the_bfd_section->name); | |
c906108c SS |
1592 | } |
1593 | break; | |
1594 | ||
4c2df51b | 1595 | case LOC_COMPUTED: |
24d6c2a0 | 1596 | gdb_assert_not_reached (_("LOC_COMPUTED variable missing a method")); |
4c2df51b | 1597 | |
c906108c | 1598 | case LOC_REGISTER: |
768a979c UW |
1599 | /* GDBARCH is the architecture associated with the objfile the symbol |
1600 | is defined in; the target architecture may be different, and may | |
1601 | provide additional registers. However, we do not know the target | |
1602 | architecture at this point. We assume the objfile architecture | |
1603 | will contain all the standard registers that occur in debug info | |
1604 | in that objfile. */ | |
1605 | regno = SYMBOL_REGISTER_OPS (sym)->register_number (sym, gdbarch); | |
1606 | ||
2a2d4dc3 AS |
1607 | if (SYMBOL_IS_ARGUMENT (sym)) |
1608 | printf_filtered (_("an argument in register %s"), | |
768a979c | 1609 | gdbarch_register_name (gdbarch, regno)); |
2a2d4dc3 AS |
1610 | else |
1611 | printf_filtered (_("a variable in register %s"), | |
768a979c | 1612 | gdbarch_register_name (gdbarch, regno)); |
c906108c SS |
1613 | break; |
1614 | ||
1615 | case LOC_STATIC: | |
a3f17187 | 1616 | printf_filtered (_("static storage at address ")); |
5af949e3 | 1617 | load_addr = SYMBOL_VALUE_ADDRESS (sym); |
35fb8261 TT |
1618 | fputs_styled (paddress (gdbarch, load_addr), address_style.style (), |
1619 | gdb_stdout); | |
c906108c SS |
1620 | if (section_is_overlay (section)) |
1621 | { | |
1622 | load_addr = overlay_unmapped_address (load_addr, section); | |
a3f17187 | 1623 | printf_filtered (_(",\n -- loaded at ")); |
35fb8261 TT |
1624 | fputs_styled (paddress (gdbarch, load_addr), address_style.style (), |
1625 | gdb_stdout); | |
714835d5 UW |
1626 | printf_filtered (_(" in overlay section %s"), |
1627 | section->the_bfd_section->name); | |
c906108c SS |
1628 | } |
1629 | break; | |
1630 | ||
c906108c | 1631 | case LOC_REGPARM_ADDR: |
768a979c UW |
1632 | /* Note comment at LOC_REGISTER. */ |
1633 | regno = SYMBOL_REGISTER_OPS (sym)->register_number (sym, gdbarch); | |
675dcf4f | 1634 | printf_filtered (_("address of an argument in register %s"), |
768a979c | 1635 | gdbarch_register_name (gdbarch, regno)); |
c906108c SS |
1636 | break; |
1637 | ||
1638 | case LOC_ARG: | |
a3f17187 | 1639 | printf_filtered (_("an argument at offset %ld"), val); |
c906108c SS |
1640 | break; |
1641 | ||
c906108c | 1642 | case LOC_LOCAL: |
a3f17187 | 1643 | printf_filtered (_("a local variable at frame offset %ld"), val); |
c906108c SS |
1644 | break; |
1645 | ||
1646 | case LOC_REF_ARG: | |
a3f17187 | 1647 | printf_filtered (_("a reference argument at offset %ld"), val); |
c906108c SS |
1648 | break; |
1649 | ||
c906108c | 1650 | case LOC_TYPEDEF: |
a3f17187 | 1651 | printf_filtered (_("a typedef")); |
c906108c SS |
1652 | break; |
1653 | ||
1654 | case LOC_BLOCK: | |
a3f17187 | 1655 | printf_filtered (_("a function at address ")); |
2b1ffcfd | 1656 | load_addr = BLOCK_ENTRY_PC (SYMBOL_BLOCK_VALUE (sym)); |
35fb8261 TT |
1657 | fputs_styled (paddress (gdbarch, load_addr), address_style.style (), |
1658 | gdb_stdout); | |
c906108c SS |
1659 | if (section_is_overlay (section)) |
1660 | { | |
1661 | load_addr = overlay_unmapped_address (load_addr, section); | |
a3f17187 | 1662 | printf_filtered (_(",\n -- loaded at ")); |
35fb8261 TT |
1663 | fputs_styled (paddress (gdbarch, load_addr), address_style.style (), |
1664 | gdb_stdout); | |
714835d5 UW |
1665 | printf_filtered (_(" in overlay section %s"), |
1666 | section->the_bfd_section->name); | |
c906108c SS |
1667 | } |
1668 | break; | |
1669 | ||
1670 | case LOC_UNRESOLVED: | |
1671 | { | |
e27d198c | 1672 | struct bound_minimal_symbol msym; |
c906108c | 1673 | |
987012b8 | 1674 | msym = lookup_bound_minimal_symbol (sym->linkage_name ()); |
e27d198c | 1675 | if (msym.minsym == NULL) |
c906108c SS |
1676 | printf_filtered ("unresolved"); |
1677 | else | |
1678 | { | |
efd66ac6 | 1679 | section = MSYMBOL_OBJ_SECTION (msym.objfile, msym.minsym); |
e0740f77 JK |
1680 | |
1681 | if (section | |
1682 | && (section->the_bfd_section->flags & SEC_THREAD_LOCAL) != 0) | |
5382cfab PW |
1683 | { |
1684 | load_addr = MSYMBOL_VALUE_RAW_ADDRESS (msym.minsym); | |
1685 | printf_filtered (_("a thread-local variable at offset %s " | |
1686 | "in the thread-local storage for `%s'"), | |
1687 | paddress (gdbarch, load_addr), | |
1688 | objfile_name (section->objfile)); | |
1689 | } | |
e0740f77 | 1690 | else |
c906108c | 1691 | { |
5382cfab | 1692 | load_addr = BMSYMBOL_VALUE_ADDRESS (msym); |
e0740f77 | 1693 | printf_filtered (_("static storage at address ")); |
35fb8261 TT |
1694 | fputs_styled (paddress (gdbarch, load_addr), |
1695 | address_style.style (), gdb_stdout); | |
e0740f77 JK |
1696 | if (section_is_overlay (section)) |
1697 | { | |
1698 | load_addr = overlay_unmapped_address (load_addr, section); | |
1699 | printf_filtered (_(",\n -- loaded at ")); | |
35fb8261 TT |
1700 | fputs_styled (paddress (gdbarch, load_addr), |
1701 | address_style.style (), | |
1702 | gdb_stdout); | |
e0740f77 JK |
1703 | printf_filtered (_(" in overlay section %s"), |
1704 | section->the_bfd_section->name); | |
1705 | } | |
c906108c SS |
1706 | } |
1707 | } | |
1708 | } | |
1709 | break; | |
1710 | ||
c906108c | 1711 | case LOC_OPTIMIZED_OUT: |
a3f17187 | 1712 | printf_filtered (_("optimized out")); |
c906108c | 1713 | break; |
c5aa993b | 1714 | |
c906108c | 1715 | default: |
a3f17187 | 1716 | printf_filtered (_("of unknown (botched) type")); |
c906108c SS |
1717 | break; |
1718 | } | |
1719 | printf_filtered (".\n"); | |
1720 | } | |
1721 | \f | |
675dcf4f MK |
1722 | |
1723 | static void | |
0b39b52e | 1724 | x_command (const char *exp, int from_tty) |
c906108c | 1725 | { |
c906108c | 1726 | struct format_data fmt; |
c906108c SS |
1727 | struct value *val; |
1728 | ||
a6bac58e | 1729 | fmt.format = last_format ? last_format : 'x'; |
c906108c SS |
1730 | fmt.size = last_size; |
1731 | fmt.count = 1; | |
a6bac58e | 1732 | fmt.raw = 0; |
c906108c | 1733 | |
9be2ae8f TT |
1734 | /* If there is no expression and no format, use the most recent |
1735 | count. */ | |
1736 | if (exp == nullptr && last_count > 0) | |
1737 | fmt.count = last_count; | |
1738 | ||
c906108c SS |
1739 | if (exp && *exp == '/') |
1740 | { | |
6f937416 PA |
1741 | const char *tmp = exp + 1; |
1742 | ||
1743 | fmt = decode_format (&tmp, last_format, last_size); | |
1744 | exp = (char *) tmp; | |
c906108c SS |
1745 | } |
1746 | ||
9be2ae8f TT |
1747 | last_count = fmt.count; |
1748 | ||
c906108c SS |
1749 | /* If we have an expression, evaluate it and use it as the address. */ |
1750 | ||
1751 | if (exp != 0 && *exp != 0) | |
1752 | { | |
4d01a485 | 1753 | expression_up expr = parse_expression (exp); |
675dcf4f | 1754 | /* Cause expression not to be there any more if this command is |
dda83cd7 SM |
1755 | repeated with Newline. But don't clobber a user-defined |
1756 | command's definition. */ | |
c906108c | 1757 | if (from_tty) |
85c4be7c | 1758 | set_repeat_arguments (""); |
4d01a485 | 1759 | val = evaluate_expression (expr.get ()); |
aa006118 | 1760 | if (TYPE_IS_REFERENCE (value_type (val))) |
e1c34c5d | 1761 | val = coerce_ref (val); |
c906108c | 1762 | /* In rvalue contexts, such as this, functions are coerced into |
dda83cd7 | 1763 | pointers to functions. This makes "x/i main" work. */ |
78134374 | 1764 | if (value_type (val)->code () == TYPE_CODE_FUNC |
c5aa993b | 1765 | && VALUE_LVAL (val) == lval_memory) |
42ae5230 | 1766 | next_address = value_address (val); |
c906108c | 1767 | else |
1aa20aa8 | 1768 | next_address = value_as_address (val); |
5d3729b5 UW |
1769 | |
1770 | next_gdbarch = expr->gdbarch; | |
c906108c SS |
1771 | } |
1772 | ||
5d3729b5 UW |
1773 | if (!next_gdbarch) |
1774 | error_no_arg (_("starting display address")); | |
1775 | ||
1776 | do_examine (fmt, next_gdbarch, next_address); | |
c906108c | 1777 | |
675dcf4f | 1778 | /* If the examine succeeds, we remember its size and format for next |
9a22f0d0 PM |
1779 | time. Set last_size to 'b' for strings. */ |
1780 | if (fmt.format == 's') | |
1781 | last_size = 'b'; | |
1782 | else | |
1783 | last_size = fmt.size; | |
c906108c SS |
1784 | last_format = fmt.format; |
1785 | ||
0df8b418 | 1786 | /* Set a couple of internal variables if appropriate. */ |
9b558729 | 1787 | if (last_examine_value != nullptr) |
c906108c SS |
1788 | { |
1789 | /* Make last address examined available to the user as $_. Use | |
dda83cd7 | 1790 | the correct pointer type. */ |
4478b372 | 1791 | struct type *pointer_type |
9b558729 | 1792 | = lookup_pointer_type (value_type (last_examine_value.get ())); |
c906108c | 1793 | set_internalvar (lookup_internalvar ("_"), |
4478b372 JB |
1794 | value_from_pointer (pointer_type, |
1795 | last_examine_address)); | |
c5aa993b | 1796 | |
675dcf4f MK |
1797 | /* Make contents of last address examined available to the user |
1798 | as $__. If the last value has not been fetched from memory | |
1799 | then don't fetch it now; instead mark it by voiding the $__ | |
1800 | variable. */ | |
9b558729 | 1801 | if (value_lazy (last_examine_value.get ())) |
4fa62494 | 1802 | clear_internalvar (lookup_internalvar ("__")); |
c906108c | 1803 | else |
9b558729 | 1804 | set_internalvar (lookup_internalvar ("__"), last_examine_value.get ()); |
c906108c SS |
1805 | } |
1806 | } | |
037d7135 AB |
1807 | |
1808 | /* Command completion for the 'display' and 'x' commands. */ | |
1809 | ||
1810 | static void | |
1811 | display_and_x_command_completer (struct cmd_list_element *ignore, | |
1812 | completion_tracker &tracker, | |
1813 | const char *text, const char * /*word*/) | |
1814 | { | |
1815 | if (skip_over_slash_fmt (tracker, &text)) | |
1816 | return; | |
1817 | ||
1818 | const char *word = advance_to_expression_complete_word_point (tracker, text); | |
1819 | expression_completer (ignore, tracker, text, word); | |
1820 | } | |
1821 | ||
c906108c | 1822 | \f |
c5aa993b | 1823 | |
c906108c SS |
1824 | /* Add an expression to the auto-display chain. |
1825 | Specify the expression. */ | |
1826 | ||
1827 | static void | |
0b39b52e | 1828 | display_command (const char *arg, int from_tty) |
c906108c SS |
1829 | { |
1830 | struct format_data fmt; | |
fe978cb0 | 1831 | struct display *newobj; |
6f937416 | 1832 | const char *exp = arg; |
c906108c | 1833 | |
7bd0be3a | 1834 | if (exp == 0) |
c906108c | 1835 | { |
7bd0be3a AB |
1836 | do_displays (); |
1837 | return; | |
1838 | } | |
c906108c | 1839 | |
7bd0be3a AB |
1840 | if (*exp == '/') |
1841 | { | |
1842 | exp++; | |
1843 | fmt = decode_format (&exp, 0, 0); | |
1844 | if (fmt.size && fmt.format == 0) | |
1845 | fmt.format = 'x'; | |
1846 | if (fmt.format == 'i' || fmt.format == 's') | |
1847 | fmt.size = 'b'; | |
1848 | } | |
1849 | else | |
1850 | { | |
1851 | fmt.format = 0; | |
1852 | fmt.size = 0; | |
1853 | fmt.count = 0; | |
1854 | fmt.raw = 0; | |
1855 | } | |
c906108c | 1856 | |
699bd4cf TT |
1857 | innermost_block_tracker tracker; |
1858 | expression_up expr = parse_expression (exp, &tracker); | |
c906108c | 1859 | |
8be4b118 TT |
1860 | newobj = new display (exp, std::move (expr), fmt, |
1861 | current_program_space, tracker.block ()); | |
1862 | all_displays.emplace_back (newobj); | |
c906108c | 1863 | |
7bd0be3a AB |
1864 | if (from_tty) |
1865 | do_one_display (newobj); | |
c906108c | 1866 | |
7bd0be3a | 1867 | dont_repeat (); |
c906108c SS |
1868 | } |
1869 | ||
675dcf4f MK |
1870 | /* Clear out the display_chain. Done when new symtabs are loaded, |
1871 | since this invalidates the types stored in many expressions. */ | |
c906108c SS |
1872 | |
1873 | void | |
8be4b118 | 1874 | clear_displays () |
c906108c | 1875 | { |
8be4b118 | 1876 | all_displays.clear (); |
c906108c SS |
1877 | } |
1878 | ||
3c3fe74c | 1879 | /* Delete the auto-display DISPLAY. */ |
c906108c SS |
1880 | |
1881 | static void | |
3c3fe74c | 1882 | delete_display (struct display *display) |
c906108c | 1883 | { |
3c3fe74c | 1884 | gdb_assert (display != NULL); |
c906108c | 1885 | |
8be4b118 TT |
1886 | auto iter = std::find_if (all_displays.begin (), |
1887 | all_displays.end (), | |
1888 | [=] (const std::unique_ptr<struct display> &item) | |
1889 | { | |
1890 | return item.get () == display; | |
1891 | }); | |
1892 | gdb_assert (iter != all_displays.end ()); | |
1893 | all_displays.erase (iter); | |
c906108c SS |
1894 | } |
1895 | ||
c9174737 PA |
1896 | /* Call FUNCTION on each of the displays whose numbers are given in |
1897 | ARGS. DATA is passed unmodified to FUNCTION. */ | |
c906108c SS |
1898 | |
1899 | static void | |
77763700 | 1900 | map_display_numbers (const char *args, |
8be4b118 | 1901 | gdb::function_view<void (struct display *)> function) |
c906108c | 1902 | { |
c9174737 | 1903 | int num; |
c906108c | 1904 | |
c9174737 PA |
1905 | if (args == NULL) |
1906 | error_no_arg (_("one or more display numbers")); | |
c906108c | 1907 | |
bfd28288 | 1908 | number_or_range_parser parser (args); |
c9174737 | 1909 | |
bfd28288 | 1910 | while (!parser.finished ()) |
c906108c | 1911 | { |
bfd28288 | 1912 | const char *p = parser.cur_tok (); |
c906108c | 1913 | |
bfd28288 | 1914 | num = parser.get_number (); |
3c3fe74c PA |
1915 | if (num == 0) |
1916 | warning (_("bad display number at or near '%s'"), p); | |
1917 | else | |
1918 | { | |
8be4b118 TT |
1919 | auto iter = std::find_if (all_displays.begin (), |
1920 | all_displays.end (), | |
1921 | [=] (const std::unique_ptr<display> &item) | |
1922 | { | |
1923 | return item->number == num; | |
1924 | }); | |
1925 | if (iter == all_displays.end ()) | |
3c3fe74c PA |
1926 | printf_unfiltered (_("No display number %d.\n"), num); |
1927 | else | |
8be4b118 | 1928 | function (iter->get ()); |
3c3fe74c | 1929 | } |
c906108c | 1930 | } |
c9174737 PA |
1931 | } |
1932 | ||
c9174737 PA |
1933 | /* "undisplay" command. */ |
1934 | ||
1935 | static void | |
77763700 | 1936 | undisplay_command (const char *args, int from_tty) |
c9174737 | 1937 | { |
c9174737 PA |
1938 | if (args == NULL) |
1939 | { | |
1940 | if (query (_("Delete all auto-display expressions? "))) | |
1941 | clear_displays (); | |
1942 | dont_repeat (); | |
1943 | return; | |
1944 | } | |
1945 | ||
8be4b118 | 1946 | map_display_numbers (args, delete_display); |
c906108c SS |
1947 | dont_repeat (); |
1948 | } | |
1949 | ||
1950 | /* Display a single auto-display. | |
1951 | Do nothing if the display cannot be printed in the current context, | |
0df8b418 | 1952 | or if the display is disabled. */ |
c906108c SS |
1953 | |
1954 | static void | |
fba45db2 | 1955 | do_one_display (struct display *d) |
c906108c SS |
1956 | { |
1957 | int within_current_scope; | |
1958 | ||
8be4b118 | 1959 | if (!d->enabled_p) |
c906108c SS |
1960 | return; |
1961 | ||
704e9165 UW |
1962 | /* The expression carries the architecture that was used at parse time. |
1963 | This is a problem if the expression depends on architecture features | |
1964 | (e.g. register numbers), and the current architecture is now different. | |
1965 | For example, a display statement like "display/i $pc" is expected to | |
1966 | display the PC register of the current architecture, not the arch at | |
1967 | the time the display command was given. Therefore, we re-parse the | |
1968 | expression if the current architecture has changed. */ | |
1969 | if (d->exp != NULL && d->exp->gdbarch != get_current_arch ()) | |
1970 | { | |
4d01a485 | 1971 | d->exp.reset (); |
704e9165 UW |
1972 | d->block = NULL; |
1973 | } | |
1974 | ||
a3247a22 PP |
1975 | if (d->exp == NULL) |
1976 | { | |
ad3bbd48 | 1977 | |
a70b8144 | 1978 | try |
a3247a22 | 1979 | { |
699bd4cf | 1980 | innermost_block_tracker tracker; |
8be4b118 | 1981 | d->exp = parse_expression (d->exp_string.c_str (), &tracker); |
699bd4cf | 1982 | d->block = tracker.block (); |
a3247a22 | 1983 | } |
230d2906 | 1984 | catch (const gdb_exception &ex) |
a3247a22 PP |
1985 | { |
1986 | /* Can't re-parse the expression. Disable this display item. */ | |
8be4b118 | 1987 | d->enabled_p = false; |
a3247a22 | 1988 | warning (_("Unable to display \"%s\": %s"), |
8be4b118 | 1989 | d->exp_string.c_str (), ex.what ()); |
a3247a22 PP |
1990 | return; |
1991 | } | |
1992 | } | |
1993 | ||
c906108c | 1994 | if (d->block) |
6c95b8df PA |
1995 | { |
1996 | if (d->pspace == current_program_space) | |
f21c2bd7 TT |
1997 | within_current_scope = contained_in (get_selected_block (0), d->block, |
1998 | true); | |
6c95b8df PA |
1999 | else |
2000 | within_current_scope = 0; | |
2001 | } | |
c906108c SS |
2002 | else |
2003 | within_current_scope = 1; | |
2004 | if (!within_current_scope) | |
2005 | return; | |
2006 | ||
b7b633e9 TT |
2007 | scoped_restore save_display_number |
2008 | = make_scoped_restore (¤t_display_number, d->number); | |
c906108c SS |
2009 | |
2010 | annotate_display_begin (); | |
2011 | printf_filtered ("%d", d->number); | |
2012 | annotate_display_number_end (); | |
2013 | printf_filtered (": "); | |
2014 | if (d->format.size) | |
2015 | { | |
c906108c SS |
2016 | |
2017 | annotate_display_format (); | |
2018 | ||
2019 | printf_filtered ("x/"); | |
2020 | if (d->format.count != 1) | |
2021 | printf_filtered ("%d", d->format.count); | |
2022 | printf_filtered ("%c", d->format.format); | |
2023 | if (d->format.format != 'i' && d->format.format != 's') | |
2024 | printf_filtered ("%c", d->format.size); | |
2025 | printf_filtered (" "); | |
2026 | ||
2027 | annotate_display_expression (); | |
2028 | ||
8be4b118 | 2029 | puts_filtered (d->exp_string.c_str ()); |
c906108c SS |
2030 | annotate_display_expression_end (); |
2031 | ||
6a2eb474 | 2032 | if (d->format.count != 1 || d->format.format == 'i') |
c906108c SS |
2033 | printf_filtered ("\n"); |
2034 | else | |
2035 | printf_filtered (" "); | |
c5aa993b | 2036 | |
c906108c SS |
2037 | annotate_display_value (); |
2038 | ||
a70b8144 | 2039 | try |
dda83cd7 | 2040 | { |
9d8fa392 PA |
2041 | struct value *val; |
2042 | CORE_ADDR addr; | |
2043 | ||
4d01a485 | 2044 | val = evaluate_expression (d->exp.get ()); |
9d8fa392 PA |
2045 | addr = value_as_address (val); |
2046 | if (d->format.format == 'i') | |
2047 | addr = gdbarch_addr_bits_remove (d->exp->gdbarch, addr); | |
2048 | do_examine (d->format, d->exp->gdbarch, addr); | |
2049 | } | |
230d2906 | 2050 | catch (const gdb_exception_error &ex) |
492d29ea | 2051 | { |
7f6aba03 TT |
2052 | fprintf_filtered (gdb_stdout, _("%p[<error: %s>%p]\n"), |
2053 | metadata_style.style ().ptr (), ex.what (), | |
2054 | nullptr); | |
492d29ea | 2055 | } |
c906108c SS |
2056 | } |
2057 | else | |
2058 | { | |
79a45b7d TT |
2059 | struct value_print_options opts; |
2060 | ||
c906108c SS |
2061 | annotate_display_format (); |
2062 | ||
2063 | if (d->format.format) | |
2064 | printf_filtered ("/%c ", d->format.format); | |
2065 | ||
2066 | annotate_display_expression (); | |
2067 | ||
8be4b118 | 2068 | puts_filtered (d->exp_string.c_str ()); |
c906108c SS |
2069 | annotate_display_expression_end (); |
2070 | ||
2071 | printf_filtered (" = "); | |
2072 | ||
2073 | annotate_display_expression (); | |
2074 | ||
79a45b7d | 2075 | get_formatted_print_options (&opts, d->format.format); |
a6bac58e | 2076 | opts.raw = d->format.raw; |
9d8fa392 | 2077 | |
a70b8144 | 2078 | try |
dda83cd7 | 2079 | { |
9d8fa392 PA |
2080 | struct value *val; |
2081 | ||
4d01a485 | 2082 | val = evaluate_expression (d->exp.get ()); |
9d8fa392 PA |
2083 | print_formatted (val, d->format.size, &opts, gdb_stdout); |
2084 | } | |
230d2906 | 2085 | catch (const gdb_exception_error &ex) |
492d29ea | 2086 | { |
7f6aba03 TT |
2087 | fprintf_styled (gdb_stdout, metadata_style.style (), |
2088 | _("<error: %s>"), ex.what ()); | |
492d29ea | 2089 | } |
492d29ea | 2090 | |
c906108c SS |
2091 | printf_filtered ("\n"); |
2092 | } | |
2093 | ||
2094 | annotate_display_end (); | |
2095 | ||
2096 | gdb_flush (gdb_stdout); | |
c906108c SS |
2097 | } |
2098 | ||
2099 | /* Display all of the values on the auto-display chain which can be | |
2100 | evaluated in the current scope. */ | |
2101 | ||
2102 | void | |
fba45db2 | 2103 | do_displays (void) |
c906108c | 2104 | { |
8be4b118 TT |
2105 | for (auto &d : all_displays) |
2106 | do_one_display (d.get ()); | |
c906108c SS |
2107 | } |
2108 | ||
2109 | /* Delete the auto-display which we were in the process of displaying. | |
2110 | This is done when there is an error or a signal. */ | |
2111 | ||
2112 | void | |
fba45db2 | 2113 | disable_display (int num) |
c906108c | 2114 | { |
8be4b118 | 2115 | for (auto &d : all_displays) |
c906108c SS |
2116 | if (d->number == num) |
2117 | { | |
8be4b118 | 2118 | d->enabled_p = false; |
c906108c SS |
2119 | return; |
2120 | } | |
a3f17187 | 2121 | printf_unfiltered (_("No display number %d.\n"), num); |
c906108c | 2122 | } |
c5aa993b | 2123 | |
c906108c | 2124 | void |
fba45db2 | 2125 | disable_current_display (void) |
c906108c SS |
2126 | { |
2127 | if (current_display_number >= 0) | |
2128 | { | |
2129 | disable_display (current_display_number); | |
3e43a32a MS |
2130 | fprintf_unfiltered (gdb_stderr, |
2131 | _("Disabling display %d to " | |
2132 | "avoid infinite recursion.\n"), | |
c5aa993b | 2133 | current_display_number); |
c906108c SS |
2134 | } |
2135 | current_display_number = -1; | |
2136 | } | |
2137 | ||
2138 | static void | |
1d12d88f | 2139 | info_display_command (const char *ignore, int from_tty) |
c906108c | 2140 | { |
8be4b118 | 2141 | if (all_displays.empty ()) |
a3f17187 | 2142 | printf_unfiltered (_("There are no auto-display expressions now.\n")); |
c906108c | 2143 | else |
a3f17187 AC |
2144 | printf_filtered (_("Auto-display expressions now in effect:\n\ |
2145 | Num Enb Expression\n")); | |
c906108c | 2146 | |
8be4b118 | 2147 | for (auto &d : all_displays) |
c906108c | 2148 | { |
b5de0fa7 | 2149 | printf_filtered ("%d: %c ", d->number, "ny"[(int) d->enabled_p]); |
c906108c SS |
2150 | if (d->format.size) |
2151 | printf_filtered ("/%d%c%c ", d->format.count, d->format.size, | |
c5aa993b | 2152 | d->format.format); |
c906108c SS |
2153 | else if (d->format.format) |
2154 | printf_filtered ("/%c ", d->format.format); | |
8be4b118 | 2155 | puts_filtered (d->exp_string.c_str ()); |
f21c2bd7 | 2156 | if (d->block && !contained_in (get_selected_block (0), d->block, true)) |
a3f17187 | 2157 | printf_filtered (_(" (cannot be evaluated in the current context)")); |
c906108c | 2158 | printf_filtered ("\n"); |
c906108c SS |
2159 | } |
2160 | } | |
2161 | ||
85102364 | 2162 | /* Implementation of both the "disable display" and "enable display" |
c9174737 PA |
2163 | commands. ENABLE decides what to do. */ |
2164 | ||
2165 | static void | |
8be4b118 | 2166 | enable_disable_display_command (const char *args, int from_tty, bool enable) |
c9174737 PA |
2167 | { |
2168 | if (args == NULL) | |
c906108c | 2169 | { |
8be4b118 | 2170 | for (auto &d : all_displays) |
c9174737 PA |
2171 | d->enabled_p = enable; |
2172 | return; | |
2173 | } | |
c5aa993b | 2174 | |
8be4b118 TT |
2175 | map_display_numbers (args, |
2176 | [=] (struct display *d) | |
2177 | { | |
2178 | d->enabled_p = enable; | |
2179 | }); | |
c906108c SS |
2180 | } |
2181 | ||
c9174737 PA |
2182 | /* The "enable display" command. */ |
2183 | ||
c906108c | 2184 | static void |
77763700 | 2185 | enable_display_command (const char *args, int from_tty) |
c906108c | 2186 | { |
8be4b118 | 2187 | enable_disable_display_command (args, from_tty, true); |
c9174737 | 2188 | } |
c5aa993b | 2189 | |
c9174737 | 2190 | /* The "disable display" command. */ |
c906108c | 2191 | |
c9174737 | 2192 | static void |
77763700 | 2193 | disable_display_command (const char *args, int from_tty) |
c9174737 | 2194 | { |
8be4b118 | 2195 | enable_disable_display_command (args, from_tty, false); |
c906108c | 2196 | } |
a3247a22 | 2197 | |
a3247a22 PP |
2198 | /* display_chain items point to blocks and expressions. Some expressions in |
2199 | turn may point to symbols. | |
2200 | Both symbols and blocks are obstack_alloc'd on objfile_stack, and are | |
2201 | obstack_free'd when a shared library is unloaded. | |
2202 | Clear pointers that are about to become dangling. | |
2203 | Both .exp and .block fields will be restored next time we need to display | |
2204 | an item by re-parsing .exp_string field in the new execution context. */ | |
2205 | ||
2206 | static void | |
63644780 | 2207 | clear_dangling_display_expressions (struct objfile *objfile) |
a3247a22 | 2208 | { |
63644780 | 2209 | struct program_space *pspace; |
a3247a22 | 2210 | |
c0201579 JK |
2211 | /* With no symbol file we cannot have a block or expression from it. */ |
2212 | if (objfile == NULL) | |
2213 | return; | |
63644780 | 2214 | pspace = objfile->pspace; |
c0201579 | 2215 | if (objfile->separate_debug_objfile_backlink) |
63644780 NB |
2216 | { |
2217 | objfile = objfile->separate_debug_objfile_backlink; | |
2218 | gdb_assert (objfile->pspace == pspace); | |
2219 | } | |
c0201579 | 2220 | |
8be4b118 | 2221 | for (auto &d : all_displays) |
a3247a22 | 2222 | { |
63644780 | 2223 | if (d->pspace != pspace) |
c0201579 JK |
2224 | continue; |
2225 | ||
d6bc0792 TT |
2226 | struct objfile *bl_objf = nullptr; |
2227 | if (d->block != nullptr) | |
2228 | { | |
2229 | bl_objf = block_objfile (d->block); | |
2230 | if (bl_objf->separate_debug_objfile_backlink != nullptr) | |
2231 | bl_objf = bl_objf->separate_debug_objfile_backlink; | |
2232 | } | |
2233 | ||
2234 | if (bl_objf == objfile | |
4d01a485 | 2235 | || (d->exp != NULL && exp_uses_objfile (d->exp.get (), objfile))) |
d6bc0792 TT |
2236 | { |
2237 | d->exp.reset (); | |
2238 | d->block = NULL; | |
2239 | } | |
a3247a22 PP |
2240 | } |
2241 | } | |
c906108c | 2242 | \f |
c5aa993b | 2243 | |
675dcf4f | 2244 | /* Print the value in stack frame FRAME of a variable specified by a |
aad95b57 TT |
2245 | struct symbol. NAME is the name to print; if NULL then VAR's print |
2246 | name will be used. STREAM is the ui_file on which to print the | |
2247 | value. INDENT specifies the number of indent levels to print | |
8f043999 JK |
2248 | before printing the variable name. |
2249 | ||
2250 | This function invalidates FRAME. */ | |
c906108c SS |
2251 | |
2252 | void | |
aad95b57 TT |
2253 | print_variable_and_value (const char *name, struct symbol *var, |
2254 | struct frame_info *frame, | |
2255 | struct ui_file *stream, int indent) | |
c906108c | 2256 | { |
c906108c | 2257 | |
aad95b57 | 2258 | if (!name) |
987012b8 | 2259 | name = var->print_name (); |
aad95b57 | 2260 | |
6a831f06 PA |
2261 | fprintf_filtered (stream, "%s%ps = ", n_spaces (2 * indent), |
2262 | styled_string (variable_name_style.style (), name)); | |
80ae2043 | 2263 | |
a70b8144 | 2264 | try |
0f6a939d PM |
2265 | { |
2266 | struct value *val; | |
2267 | struct value_print_options opts; | |
aad95b57 | 2268 | |
63e43d3a PMR |
2269 | /* READ_VAR_VALUE needs a block in order to deal with non-local |
2270 | references (i.e. to handle nested functions). In this context, we | |
2271 | print variables that are local to this frame, so we can avoid passing | |
2272 | a block to it. */ | |
2273 | val = read_var_value (var, NULL, frame); | |
0f6a939d | 2274 | get_user_print_options (&opts); |
3343315b | 2275 | opts.deref_ref = 1; |
0f6a939d | 2276 | common_val_print (val, stream, indent, &opts, current_language); |
8f043999 JK |
2277 | |
2278 | /* common_val_print invalidates FRAME when a pretty printer calls inferior | |
2279 | function. */ | |
2280 | frame = NULL; | |
0f6a939d | 2281 | } |
230d2906 | 2282 | catch (const gdb_exception_error &except) |
492d29ea | 2283 | { |
7f6aba03 TT |
2284 | fprintf_styled (stream, metadata_style.style (), |
2285 | "<error reading variable %s (%s)>", name, | |
2286 | except.what ()); | |
492d29ea | 2287 | } |
492d29ea | 2288 | |
aad95b57 | 2289 | fprintf_filtered (stream, "\n"); |
c906108c SS |
2290 | } |
2291 | ||
c2792f5a DE |
2292 | /* Subroutine of ui_printf to simplify it. |
2293 | Print VALUE to STREAM using FORMAT. | |
1f6f6e21 PW |
2294 | VALUE is a C-style string either on the target or |
2295 | in a GDB internal variable. */ | |
c2792f5a DE |
2296 | |
2297 | static void | |
2298 | printf_c_string (struct ui_file *stream, const char *format, | |
2299 | struct value *value) | |
2300 | { | |
1f6f6e21 | 2301 | const gdb_byte *str; |
c2792f5a | 2302 | |
78134374 | 2303 | if (value_type (value)->code () != TYPE_CODE_PTR |
7b973adc | 2304 | && VALUE_LVAL (value) == lval_internalvar |
1f6f6e21 | 2305 | && c_is_string_type_p (value_type (value))) |
3ae9ce5d | 2306 | { |
1f6f6e21 | 2307 | size_t len = TYPE_LENGTH (value_type (value)); |
c2792f5a | 2308 | |
1f6f6e21 PW |
2309 | /* Copy the internal var value to TEM_STR and append a terminating null |
2310 | character. This protects against corrupted C-style strings that lack | |
2311 | the terminating null char. It also allows Ada-style strings (not | |
2312 | null terminated) to be printed without problems. */ | |
2313 | gdb_byte *tem_str = (gdb_byte *) alloca (len + 1); | |
c2792f5a | 2314 | |
1f6f6e21 PW |
2315 | memcpy (tem_str, value_contents (value), len); |
2316 | tem_str [len] = 0; | |
2317 | str = tem_str; | |
c2792f5a | 2318 | } |
1f6f6e21 PW |
2319 | else |
2320 | { | |
2321 | CORE_ADDR tem = value_as_address (value);; | |
2322 | ||
2323 | if (tem == 0) | |
2324 | { | |
2325 | DIAGNOSTIC_PUSH | |
2326 | DIAGNOSTIC_IGNORE_FORMAT_NONLITERAL | |
2327 | fprintf_filtered (stream, format, "(null)"); | |
2328 | DIAGNOSTIC_POP | |
2329 | return; | |
2330 | } | |
2331 | ||
2332 | /* This is a %s argument. Find the length of the string. */ | |
2333 | size_t len; | |
2334 | ||
2335 | for (len = 0;; len++) | |
2336 | { | |
2337 | gdb_byte c; | |
c2792f5a | 2338 | |
1f6f6e21 PW |
2339 | QUIT; |
2340 | read_memory (tem + len, &c, 1); | |
2341 | if (c == 0) | |
2342 | break; | |
2343 | } | |
2344 | ||
2345 | /* Copy the string contents into a string inside GDB. */ | |
2346 | gdb_byte *tem_str = (gdb_byte *) alloca (len + 1); | |
2347 | ||
2348 | if (len != 0) | |
2349 | read_memory (tem, tem_str, len); | |
2350 | tem_str[len] = 0; | |
2351 | str = tem_str; | |
2352 | } | |
c2792f5a | 2353 | |
af39b1c2 SM |
2354 | DIAGNOSTIC_PUSH |
2355 | DIAGNOSTIC_IGNORE_FORMAT_NONLITERAL | |
c2792f5a | 2356 | fprintf_filtered (stream, format, (char *) str); |
af39b1c2 | 2357 | DIAGNOSTIC_POP |
c2792f5a DE |
2358 | } |
2359 | ||
2360 | /* Subroutine of ui_printf to simplify it. | |
2361 | Print VALUE to STREAM using FORMAT. | |
1f6f6e21 PW |
2362 | VALUE is a wide C-style string on the target or |
2363 | in a GDB internal variable. */ | |
c2792f5a DE |
2364 | |
2365 | static void | |
2366 | printf_wide_c_string (struct ui_file *stream, const char *format, | |
2367 | struct value *value) | |
2368 | { | |
1f6f6e21 PW |
2369 | const gdb_byte *str; |
2370 | size_t len; | |
c2792f5a | 2371 | struct gdbarch *gdbarch = get_type_arch (value_type (value)); |
b858499d | 2372 | struct type *wctype = lookup_typename (current_language, |
c2792f5a DE |
2373 | "wchar_t", NULL, 0); |
2374 | int wcwidth = TYPE_LENGTH (wctype); | |
c2792f5a | 2375 | |
1f6f6e21 PW |
2376 | if (VALUE_LVAL (value) == lval_internalvar |
2377 | && c_is_string_type_p (value_type (value))) | |
3ae9ce5d | 2378 | { |
1f6f6e21 PW |
2379 | str = value_contents (value); |
2380 | len = TYPE_LENGTH (value_type (value)); | |
3ae9ce5d | 2381 | } |
1f6f6e21 | 2382 | else |
c2792f5a | 2383 | { |
1f6f6e21 | 2384 | CORE_ADDR tem = value_as_address (value); |
c2792f5a | 2385 | |
1f6f6e21 PW |
2386 | if (tem == 0) |
2387 | { | |
2388 | DIAGNOSTIC_PUSH | |
2389 | DIAGNOSTIC_IGNORE_FORMAT_NONLITERAL | |
2390 | fprintf_filtered (stream, format, "(null)"); | |
2391 | DIAGNOSTIC_POP | |
2392 | return; | |
2393 | } | |
2394 | ||
2395 | /* This is a %s argument. Find the length of the string. */ | |
2396 | enum bfd_endian byte_order = gdbarch_byte_order (gdbarch); | |
2397 | gdb_byte *buf = (gdb_byte *) alloca (wcwidth); | |
2398 | ||
2399 | for (len = 0;; len += wcwidth) | |
2400 | { | |
2401 | QUIT; | |
2402 | read_memory (tem + len, buf, wcwidth); | |
2403 | if (extract_unsigned_integer (buf, wcwidth, byte_order) == 0) | |
2404 | break; | |
2405 | } | |
2406 | ||
2407 | /* Copy the string contents into a string inside GDB. */ | |
2408 | gdb_byte *tem_str = (gdb_byte *) alloca (len + wcwidth); | |
2409 | ||
2410 | if (len != 0) | |
2411 | read_memory (tem, tem_str, len); | |
2412 | memset (&tem_str[len], 0, wcwidth); | |
2413 | str = tem_str; | |
2414 | } | |
c2792f5a | 2415 | |
8268c778 | 2416 | auto_obstack output; |
c2792f5a DE |
2417 | |
2418 | convert_between_encodings (target_wide_charset (gdbarch), | |
2419 | host_charset (), | |
1f6f6e21 | 2420 | str, len, wcwidth, |
c2792f5a DE |
2421 | &output, translit_char); |
2422 | obstack_grow_str0 (&output, ""); | |
2423 | ||
af39b1c2 SM |
2424 | DIAGNOSTIC_PUSH |
2425 | DIAGNOSTIC_IGNORE_FORMAT_NONLITERAL | |
c2792f5a | 2426 | fprintf_filtered (stream, format, obstack_base (&output)); |
af39b1c2 | 2427 | DIAGNOSTIC_POP |
c2792f5a DE |
2428 | } |
2429 | ||
2430 | /* Subroutine of ui_printf to simplify it. | |
16e812b2 | 2431 | Print VALUE, a floating point value, to STREAM using FORMAT. */ |
c2792f5a DE |
2432 | |
2433 | static void | |
16e812b2 UW |
2434 | printf_floating (struct ui_file *stream, const char *format, |
2435 | struct value *value, enum argclass argclass) | |
c2792f5a | 2436 | { |
c2792f5a DE |
2437 | /* Parameter data. */ |
2438 | struct type *param_type = value_type (value); | |
2439 | struct gdbarch *gdbarch = get_type_arch (param_type); | |
c2792f5a | 2440 | |
16e812b2 UW |
2441 | /* Determine target type corresponding to the format string. */ |
2442 | struct type *fmt_type; | |
2443 | switch (argclass) | |
c2792f5a | 2444 | { |
16e812b2 UW |
2445 | case double_arg: |
2446 | fmt_type = builtin_type (gdbarch)->builtin_double; | |
2447 | break; | |
2448 | case long_double_arg: | |
2449 | fmt_type = builtin_type (gdbarch)->builtin_long_double; | |
2450 | break; | |
2451 | case dec32float_arg: | |
2452 | fmt_type = builtin_type (gdbarch)->builtin_decfloat; | |
2453 | break; | |
2454 | case dec64float_arg: | |
2455 | fmt_type = builtin_type (gdbarch)->builtin_decdouble; | |
2456 | break; | |
2457 | case dec128float_arg: | |
2458 | fmt_type = builtin_type (gdbarch)->builtin_declong; | |
2459 | break; | |
2460 | default: | |
2461 | gdb_assert_not_reached ("unexpected argument class"); | |
c2792f5a DE |
2462 | } |
2463 | ||
16e812b2 UW |
2464 | /* To match the traditional GDB behavior, the conversion is |
2465 | done differently depending on the type of the parameter: | |
2466 | ||
2467 | - if the parameter has floating-point type, it's value | |
2468 | is converted to the target type; | |
2469 | ||
2470 | - otherwise, if the parameter has a type that is of the | |
2471 | same size as a built-in floating-point type, the value | |
2472 | bytes are interpreted as if they were of that type, and | |
2473 | then converted to the target type (this is not done for | |
2474 | decimal floating-point argument classes); | |
2475 | ||
2476 | - otherwise, if the source value has an integer value, | |
2477 | it's value is converted to the target type; | |
c2792f5a | 2478 | |
16e812b2 | 2479 | - otherwise, an error is raised. |
c2792f5a | 2480 | |
16e812b2 UW |
2481 | In either case, the result of the conversion is a byte buffer |
2482 | formatted in the target format for the target type. */ | |
2483 | ||
78134374 | 2484 | if (fmt_type->code () == TYPE_CODE_FLT) |
16e812b2 UW |
2485 | { |
2486 | param_type = float_type_from_length (param_type); | |
2487 | if (param_type != value_type (value)) | |
2488 | value = value_from_contents (param_type, value_contents (value)); | |
2489 | } | |
2490 | ||
2491 | value = value_cast (fmt_type, value); | |
c2792f5a | 2492 | |
3b4b2f16 | 2493 | /* Convert the value to a string and print it. */ |
f69fdf9b UW |
2494 | std::string str |
2495 | = target_float_to_string (value_contents (value), fmt_type, format); | |
3b4b2f16 | 2496 | fputs_filtered (str.c_str (), stream); |
c2792f5a DE |
2497 | } |
2498 | ||
2499 | /* Subroutine of ui_printf to simplify it. | |
2500 | Print VALUE, a target pointer, to STREAM using FORMAT. */ | |
2501 | ||
2502 | static void | |
2503 | printf_pointer (struct ui_file *stream, const char *format, | |
2504 | struct value *value) | |
2505 | { | |
2506 | /* We avoid the host's %p because pointers are too | |
2507 | likely to be the wrong size. The only interesting | |
2508 | modifier for %p is a width; extract that, and then | |
2509 | handle %p as glibc would: %#x or a literal "(nil)". */ | |
2510 | ||
2511 | const char *p; | |
2512 | char *fmt, *fmt_p; | |
2513 | #ifdef PRINTF_HAS_LONG_LONG | |
2514 | long long val = value_as_long (value); | |
2515 | #else | |
2516 | long val = value_as_long (value); | |
2517 | #endif | |
2518 | ||
224c3ddb | 2519 | fmt = (char *) alloca (strlen (format) + 5); |
c2792f5a DE |
2520 | |
2521 | /* Copy up to the leading %. */ | |
2522 | p = format; | |
2523 | fmt_p = fmt; | |
2524 | while (*p) | |
2525 | { | |
2526 | int is_percent = (*p == '%'); | |
2527 | ||
2528 | *fmt_p++ = *p++; | |
2529 | if (is_percent) | |
2530 | { | |
2531 | if (*p == '%') | |
2532 | *fmt_p++ = *p++; | |
2533 | else | |
2534 | break; | |
2535 | } | |
2536 | } | |
2537 | ||
2538 | if (val != 0) | |
2539 | *fmt_p++ = '#'; | |
2540 | ||
b8c2339b TT |
2541 | /* Copy any width or flags. Only the "-" flag is valid for pointers |
2542 | -- see the format_pieces constructor. */ | |
2543 | while (*p == '-' || (*p >= '0' && *p < '9')) | |
c2792f5a DE |
2544 | *fmt_p++ = *p++; |
2545 | ||
2546 | gdb_assert (*p == 'p' && *(p + 1) == '\0'); | |
2547 | if (val != 0) | |
2548 | { | |
2549 | #ifdef PRINTF_HAS_LONG_LONG | |
2550 | *fmt_p++ = 'l'; | |
2551 | #endif | |
2552 | *fmt_p++ = 'l'; | |
2553 | *fmt_p++ = 'x'; | |
2554 | *fmt_p++ = '\0'; | |
af39b1c2 SM |
2555 | DIAGNOSTIC_PUSH |
2556 | DIAGNOSTIC_IGNORE_FORMAT_NONLITERAL | |
c2792f5a | 2557 | fprintf_filtered (stream, fmt, val); |
af39b1c2 | 2558 | DIAGNOSTIC_POP |
c2792f5a DE |
2559 | } |
2560 | else | |
2561 | { | |
2562 | *fmt_p++ = 's'; | |
2563 | *fmt_p++ = '\0'; | |
af39b1c2 SM |
2564 | DIAGNOSTIC_PUSH |
2565 | DIAGNOSTIC_IGNORE_FORMAT_NONLITERAL | |
c2792f5a | 2566 | fprintf_filtered (stream, fmt, "(nil)"); |
af39b1c2 | 2567 | DIAGNOSTIC_POP |
c2792f5a DE |
2568 | } |
2569 | } | |
2570 | ||
a04b0428 JB |
2571 | /* printf "printf format string" ARG to STREAM. */ |
2572 | ||
2573 | static void | |
bbc13ae3 | 2574 | ui_printf (const char *arg, struct ui_file *stream) |
c906108c | 2575 | { |
bbc13ae3 | 2576 | const char *s = arg; |
8e481c3b | 2577 | std::vector<struct value *> val_args; |
c906108c SS |
2578 | |
2579 | if (s == 0) | |
e2e0b3e5 | 2580 | error_no_arg (_("format-control string and values to print")); |
c906108c | 2581 | |
f1735a53 | 2582 | s = skip_spaces (s); |
c906108c | 2583 | |
675dcf4f | 2584 | /* A format string should follow, enveloped in double quotes. */ |
c906108c | 2585 | if (*s++ != '"') |
8a3fe4f8 | 2586 | error (_("Bad format string, missing '\"'.")); |
c906108c | 2587 | |
8e481c3b | 2588 | format_pieces fpieces (&s); |
c906108c | 2589 | |
d3ce09f5 SS |
2590 | if (*s++ != '"') |
2591 | error (_("Bad format string, non-terminated '\"'.")); | |
2592 | ||
f1735a53 | 2593 | s = skip_spaces (s); |
c906108c SS |
2594 | |
2595 | if (*s != ',' && *s != 0) | |
8a3fe4f8 | 2596 | error (_("Invalid argument syntax")); |
c906108c | 2597 | |
c5aa993b JM |
2598 | if (*s == ',') |
2599 | s++; | |
f1735a53 | 2600 | s = skip_spaces (s); |
c906108c | 2601 | |
c906108c | 2602 | { |
c906108c | 2603 | int nargs_wanted; |
8e481c3b TT |
2604 | int i; |
2605 | const char *current_substring; | |
c906108c | 2606 | |
c906108c | 2607 | nargs_wanted = 0; |
8e481c3b TT |
2608 | for (auto &&piece : fpieces) |
2609 | if (piece.argclass != literal_piece) | |
d3ce09f5 | 2610 | ++nargs_wanted; |
c906108c SS |
2611 | |
2612 | /* Now, parse all arguments and evaluate them. | |
2613 | Store the VALUEs in VAL_ARGS. */ | |
2614 | ||
2615 | while (*s != '\0') | |
2616 | { | |
bbc13ae3 | 2617 | const char *s1; |
ad3bbd48 | 2618 | |
a04b0428 | 2619 | s1 = s; |
8e481c3b | 2620 | val_args.push_back (parse_to_comma_and_eval (&s1)); |
c5aa993b | 2621 | |
c906108c SS |
2622 | s = s1; |
2623 | if (*s == ',') | |
2624 | s++; | |
2625 | } | |
c5aa993b | 2626 | |
8e481c3b | 2627 | if (val_args.size () != nargs_wanted) |
8a3fe4f8 | 2628 | error (_("Wrong number of arguments for specified format-string")); |
c906108c SS |
2629 | |
2630 | /* Now actually print them. */ | |
d3ce09f5 | 2631 | i = 0; |
8e481c3b | 2632 | for (auto &&piece : fpieces) |
c906108c | 2633 | { |
8e481c3b TT |
2634 | current_substring = piece.string; |
2635 | switch (piece.argclass) | |
c906108c SS |
2636 | { |
2637 | case string_arg: | |
c2792f5a | 2638 | printf_c_string (stream, current_substring, val_args[i]); |
c906108c | 2639 | break; |
6c7a06a3 | 2640 | case wide_string_arg: |
c2792f5a | 2641 | printf_wide_c_string (stream, current_substring, val_args[i]); |
6c7a06a3 TT |
2642 | break; |
2643 | case wide_char_arg: | |
2644 | { | |
50810684 UW |
2645 | struct gdbarch *gdbarch |
2646 | = get_type_arch (value_type (val_args[i])); | |
b858499d | 2647 | struct type *wctype = lookup_typename (current_language, |
e6c014f2 | 2648 | "wchar_t", NULL, 0); |
6c7a06a3 | 2649 | struct type *valtype; |
6c7a06a3 TT |
2650 | const gdb_byte *bytes; |
2651 | ||
2652 | valtype = value_type (val_args[i]); | |
2653 | if (TYPE_LENGTH (valtype) != TYPE_LENGTH (wctype) | |
78134374 | 2654 | || valtype->code () != TYPE_CODE_INT) |
6c7a06a3 TT |
2655 | error (_("expected wchar_t argument for %%lc")); |
2656 | ||
2657 | bytes = value_contents (val_args[i]); | |
2658 | ||
8268c778 | 2659 | auto_obstack output; |
6c7a06a3 | 2660 | |
f870a310 | 2661 | convert_between_encodings (target_wide_charset (gdbarch), |
6c7a06a3 TT |
2662 | host_charset (), |
2663 | bytes, TYPE_LENGTH (valtype), | |
2664 | TYPE_LENGTH (valtype), | |
2665 | &output, translit_char); | |
2666 | obstack_grow_str0 (&output, ""); | |
2667 | ||
af39b1c2 SM |
2668 | DIAGNOSTIC_PUSH |
2669 | DIAGNOSTIC_IGNORE_FORMAT_NONLITERAL | |
f1421989 | 2670 | fprintf_filtered (stream, current_substring, |
dda83cd7 | 2671 | obstack_base (&output)); |
af39b1c2 | 2672 | DIAGNOSTIC_POP |
6c7a06a3 TT |
2673 | } |
2674 | break; | |
c906108c | 2675 | case long_long_arg: |
74a0d9f6 | 2676 | #ifdef PRINTF_HAS_LONG_LONG |
c906108c SS |
2677 | { |
2678 | long long val = value_as_long (val_args[i]); | |
ad3bbd48 | 2679 | |
af39b1c2 SM |
2680 | DIAGNOSTIC_PUSH |
2681 | DIAGNOSTIC_IGNORE_FORMAT_NONLITERAL | |
dda83cd7 | 2682 | fprintf_filtered (stream, current_substring, val); |
af39b1c2 | 2683 | DIAGNOSTIC_POP |
c906108c SS |
2684 | break; |
2685 | } | |
2686 | #else | |
8a3fe4f8 | 2687 | error (_("long long not supported in printf")); |
c906108c SS |
2688 | #endif |
2689 | case int_arg: | |
2690 | { | |
46e9880c | 2691 | int val = value_as_long (val_args[i]); |
ad3bbd48 | 2692 | |
af39b1c2 SM |
2693 | DIAGNOSTIC_PUSH |
2694 | DIAGNOSTIC_IGNORE_FORMAT_NONLITERAL | |
dda83cd7 | 2695 | fprintf_filtered (stream, current_substring, val); |
af39b1c2 | 2696 | DIAGNOSTIC_POP |
46e9880c DJ |
2697 | break; |
2698 | } | |
2699 | case long_arg: | |
2700 | { | |
c906108c | 2701 | long val = value_as_long (val_args[i]); |
ad3bbd48 | 2702 | |
e06f3d6e AB |
2703 | DIAGNOSTIC_PUSH |
2704 | DIAGNOSTIC_IGNORE_FORMAT_NONLITERAL | |
dda83cd7 | 2705 | fprintf_filtered (stream, current_substring, val); |
e06f3d6e AB |
2706 | DIAGNOSTIC_POP |
2707 | break; | |
2708 | } | |
2709 | case size_t_arg: | |
2710 | { | |
2711 | size_t val = value_as_long (val_args[i]); | |
2712 | ||
af39b1c2 SM |
2713 | DIAGNOSTIC_PUSH |
2714 | DIAGNOSTIC_IGNORE_FORMAT_NONLITERAL | |
dda83cd7 | 2715 | fprintf_filtered (stream, current_substring, val); |
af39b1c2 | 2716 | DIAGNOSTIC_POP |
c906108c SS |
2717 | break; |
2718 | } | |
16e812b2 UW |
2719 | /* Handles floating-point values. */ |
2720 | case double_arg: | |
2721 | case long_double_arg: | |
2722 | case dec32float_arg: | |
2723 | case dec64float_arg: | |
2724 | case dec128float_arg: | |
2725 | printf_floating (stream, current_substring, val_args[i], | |
8e481c3b | 2726 | piece.argclass); |
c2792f5a | 2727 | break; |
2025a643 | 2728 | case ptr_arg: |
c2792f5a DE |
2729 | printf_pointer (stream, current_substring, val_args[i]); |
2730 | break; | |
d3ce09f5 SS |
2731 | case literal_piece: |
2732 | /* Print a portion of the format string that has no | |
2733 | directives. Note that this will not include any | |
2734 | ordinary %-specs, but it might include "%%". That is | |
2735 | why we use printf_filtered and not puts_filtered here. | |
2736 | Also, we pass a dummy argument because some platforms | |
2737 | have modified GCC to include -Wformat-security by | |
2738 | default, which will warn here if there is no | |
2739 | argument. */ | |
af39b1c2 SM |
2740 | DIAGNOSTIC_PUSH |
2741 | DIAGNOSTIC_IGNORE_FORMAT_NONLITERAL | |
d3ce09f5 | 2742 | fprintf_filtered (stream, current_substring, 0); |
af39b1c2 | 2743 | DIAGNOSTIC_POP |
d3ce09f5 | 2744 | break; |
675dcf4f MK |
2745 | default: |
2746 | internal_error (__FILE__, __LINE__, | |
2025a643 | 2747 | _("failed internal consistency check")); |
c906108c | 2748 | } |
d3ce09f5 | 2749 | /* Maybe advance to the next argument. */ |
8e481c3b | 2750 | if (piece.argclass != literal_piece) |
d3ce09f5 | 2751 | ++i; |
c906108c | 2752 | } |
c906108c | 2753 | } |
c906108c | 2754 | } |
c906108c | 2755 | |
f1421989 HZ |
2756 | /* Implement the "printf" command. */ |
2757 | ||
a04b0428 | 2758 | static void |
0b39b52e | 2759 | printf_command (const char *arg, int from_tty) |
f1421989 | 2760 | { |
a04b0428 | 2761 | ui_printf (arg, gdb_stdout); |
ef1dfa36 TT |
2762 | reset_terminal_style (gdb_stdout); |
2763 | wrap_here (""); | |
da5bd37e | 2764 | gdb_stdout->flush (); |
f1421989 HZ |
2765 | } |
2766 | ||
2767 | /* Implement the "eval" command. */ | |
2768 | ||
2769 | static void | |
0b39b52e | 2770 | eval_command (const char *arg, int from_tty) |
f1421989 | 2771 | { |
d7e74731 | 2772 | string_file stb; |
f1421989 | 2773 | |
d7e74731 | 2774 | ui_printf (arg, &stb); |
f1421989 | 2775 | |
d7e74731 | 2776 | std::string expanded = insert_user_defined_cmd_args (stb.c_str ()); |
01770bbd | 2777 | |
95a6b0a1 | 2778 | execute_command (expanded.c_str (), from_tty); |
f1421989 HZ |
2779 | } |
2780 | ||
6c265988 | 2781 | void _initialize_printcmd (); |
c906108c | 2782 | void |
6c265988 | 2783 | _initialize_printcmd () |
c906108c | 2784 | { |
c94fdfd0 EZ |
2785 | struct cmd_list_element *c; |
2786 | ||
c906108c SS |
2787 | current_display_number = -1; |
2788 | ||
76727919 | 2789 | gdb::observers::free_objfile.attach (clear_dangling_display_expressions); |
a3247a22 | 2790 | |
11db9430 | 2791 | add_info ("address", info_address_command, |
188e1fa9 TT |
2792 | _("Describe where symbol SYM is stored.\n\ |
2793 | Usage: info address SYM")); | |
c906108c | 2794 | |
11db9430 | 2795 | add_info ("symbol", info_symbol_command, _("\ |
1bedd215 | 2796 | Describe what symbol is at location ADDR.\n\ |
188e1fa9 | 2797 | Usage: info symbol ADDR\n\ |
1bedd215 | 2798 | Only for symbols with fixed locations (global or static scope).")); |
c906108c | 2799 | |
037d7135 | 2800 | c = add_com ("x", class_vars, x_command, _("\ |
1bedd215 | 2801 | Examine memory: x/FMT ADDRESS.\n\ |
c906108c SS |
2802 | ADDRESS is an expression for the memory address to examine.\n\ |
2803 | FMT is a repeat count followed by a format letter and a size letter.\n\ | |
2804 | Format letters are o(octal), x(hex), d(decimal), u(unsigned decimal),\n\ | |
6fbe845e AB |
2805 | t(binary), f(float), a(address), i(instruction), c(char), s(string)\n\ |
2806 | and z(hex, zero padded on the left).\n\ | |
1bedd215 | 2807 | Size letters are b(byte), h(halfword), w(word), g(giant, 8 bytes).\n\ |
c906108c | 2808 | The specified number of objects of the specified size are printed\n\ |
bb556f1f TK |
2809 | according to the format. If a negative number is specified, memory is\n\ |
2810 | examined backward from the address.\n\n\ | |
c906108c SS |
2811 | Defaults for format and size letters are those previously used.\n\ |
2812 | Default count is 1. Default address is following last thing printed\n\ | |
1bedd215 | 2813 | with this command or \"print\".")); |
037d7135 | 2814 | set_cmd_completer_handle_brkchars (c, display_and_x_command_completer); |
c906108c | 2815 | |
11db9430 | 2816 | add_info ("display", info_display_command, _("\ |
188e1fa9 TT |
2817 | Expressions to display when program stops, with code numbers.\n\ |
2818 | Usage: info display")); | |
c906108c | 2819 | |
1a966eab AC |
2820 | add_cmd ("undisplay", class_vars, undisplay_command, _("\ |
2821 | Cancel some expressions to be displayed when program stops.\n\ | |
188e1fa9 | 2822 | Usage: undisplay [NUM]...\n\ |
c906108c SS |
2823 | Arguments are the code numbers of the expressions to stop displaying.\n\ |
2824 | No argument means cancel all automatic-display expressions.\n\ | |
2825 | \"delete display\" has the same effect as this command.\n\ | |
1a966eab | 2826 | Do \"info display\" to see current list of code numbers."), |
c5aa993b | 2827 | &cmdlist); |
c906108c | 2828 | |
037d7135 | 2829 | c = add_com ("display", class_vars, display_command, _("\ |
1bedd215 | 2830 | Print value of expression EXP each time the program stops.\n\ |
188e1fa9 | 2831 | Usage: display[/FMT] EXP\n\ |
c906108c SS |
2832 | /FMT may be used before EXP as in the \"print\" command.\n\ |
2833 | /FMT \"i\" or \"s\" or including a size-letter is allowed,\n\ | |
2834 | as in the \"x\" command, and then EXP is used to get the address to examine\n\ | |
2835 | and examining is done as in the \"x\" command.\n\n\ | |
2836 | With no argument, display all currently requested auto-display expressions.\n\ | |
1bedd215 | 2837 | Use \"undisplay\" to cancel display requests previously made.")); |
037d7135 | 2838 | set_cmd_completer_handle_brkchars (c, display_and_x_command_completer); |
c906108c | 2839 | |
c9174737 | 2840 | add_cmd ("display", class_vars, enable_display_command, _("\ |
1a966eab | 2841 | Enable some expressions to be displayed when program stops.\n\ |
188e1fa9 | 2842 | Usage: enable display [NUM]...\n\ |
c906108c SS |
2843 | Arguments are the code numbers of the expressions to resume displaying.\n\ |
2844 | No argument means enable all automatic-display expressions.\n\ | |
1a966eab | 2845 | Do \"info display\" to see current list of code numbers."), &enablelist); |
c906108c | 2846 | |
1a966eab AC |
2847 | add_cmd ("display", class_vars, disable_display_command, _("\ |
2848 | Disable some expressions to be displayed when program stops.\n\ | |
188e1fa9 | 2849 | Usage: disable display [NUM]...\n\ |
c906108c SS |
2850 | Arguments are the code numbers of the expressions to stop displaying.\n\ |
2851 | No argument means disable all automatic-display expressions.\n\ | |
1a966eab | 2852 | Do \"info display\" to see current list of code numbers."), &disablelist); |
c906108c | 2853 | |
1a966eab AC |
2854 | add_cmd ("display", class_vars, undisplay_command, _("\ |
2855 | Cancel some expressions to be displayed when program stops.\n\ | |
188e1fa9 | 2856 | Usage: delete display [NUM]...\n\ |
c906108c SS |
2857 | Arguments are the code numbers of the expressions to stop displaying.\n\ |
2858 | No argument means cancel all automatic-display expressions.\n\ | |
1a966eab | 2859 | Do \"info display\" to see current list of code numbers."), &deletelist); |
c906108c | 2860 | |
1bedd215 | 2861 | add_com ("printf", class_vars, printf_command, _("\ |
80ae639d | 2862 | Formatted printing, like the C \"printf\" function.\n\ |
188e1fa9 | 2863 | Usage: printf \"format string\", ARG1, ARG2, ARG3, ..., ARGN\n\ |
80ae639d | 2864 | This supports most C printf format specifications, like %s, %d, etc.")); |
c906108c | 2865 | |
1bedd215 AC |
2866 | add_com ("output", class_vars, output_command, _("\ |
2867 | Like \"print\" but don't put in value history and don't print newline.\n\ | |
188e1fa9 | 2868 | Usage: output EXP\n\ |
1bedd215 | 2869 | This is useful in user-defined commands.")); |
c906108c | 2870 | |
1bedd215 | 2871 | add_prefix_cmd ("set", class_vars, set_command, _("\ |
590042fc | 2872 | Evaluate expression EXP and assign result to variable VAR.\n\ |
188e1fa9 TT |
2873 | Usage: set VAR = EXP\n\ |
2874 | This uses assignment syntax appropriate for the current language\n\ | |
2875 | (VAR = EXP or VAR := EXP for example).\n\ | |
2876 | VAR may be a debugger \"convenience\" variable (names starting\n\ | |
c906108c | 2877 | with $), a register (a few standard names starting with $), or an actual\n\ |
1bedd215 AC |
2878 | variable in the program being debugged. EXP is any valid expression.\n\ |
2879 | Use \"set variable\" for variables with names identical to set subcommands.\n\ | |
2880 | \n\ | |
2881 | With a subcommand, this command modifies parts of the gdb environment.\n\ | |
2882 | You can see these environment settings with the \"show\" command."), | |
c5aa993b | 2883 | &setlist, "set ", 1, &cmdlist); |
c906108c | 2884 | if (dbx_commands) |
0b39b52e | 2885 | add_com ("assign", class_vars, set_command, _("\ |
590042fc | 2886 | Evaluate expression EXP and assign result to variable VAR.\n\ |
188e1fa9 TT |
2887 | Usage: assign VAR = EXP\n\ |
2888 | This uses assignment syntax appropriate for the current language\n\ | |
2889 | (VAR = EXP or VAR := EXP for example).\n\ | |
2890 | VAR may be a debugger \"convenience\" variable (names starting\n\ | |
c906108c | 2891 | with $), a register (a few standard names starting with $), or an actual\n\ |
1bedd215 AC |
2892 | variable in the program being debugged. EXP is any valid expression.\n\ |
2893 | Use \"set variable\" for variables with names identical to set subcommands.\n\ | |
c906108c | 2894 | \nWith a subcommand, this command modifies parts of the gdb environment.\n\ |
1bedd215 | 2895 | You can see these environment settings with the \"show\" command.")); |
c906108c | 2896 | |
0df8b418 | 2897 | /* "call" is the same as "set", but handy for dbx users to call fns. */ |
1bedd215 AC |
2898 | c = add_com ("call", class_vars, call_command, _("\ |
2899 | Call a function in the program.\n\ | |
188e1fa9 | 2900 | Usage: call EXP\n\ |
c906108c SS |
2901 | The argument is the function name and arguments, in the notation of the\n\ |
2902 | current working language. The result is printed and saved in the value\n\ | |
1bedd215 | 2903 | history, if it is not void.")); |
7d8062de | 2904 | set_cmd_completer_handle_brkchars (c, print_command_completer); |
c906108c | 2905 | |
1a966eab | 2906 | add_cmd ("variable", class_vars, set_command, _("\ |
590042fc | 2907 | Evaluate expression EXP and assign result to variable VAR.\n\ |
188e1fa9 TT |
2908 | Usage: set variable VAR = EXP\n\ |
2909 | This uses assignment syntax appropriate for the current language\n\ | |
2910 | (VAR = EXP or VAR := EXP for example).\n\ | |
2911 | VAR may be a debugger \"convenience\" variable (names starting\n\ | |
c906108c SS |
2912 | with $), a register (a few standard names starting with $), or an actual\n\ |
2913 | variable in the program being debugged. EXP is any valid expression.\n\ | |
1a966eab | 2914 | This may usually be abbreviated to simply \"set\"."), |
c5aa993b | 2915 | &setlist); |
3fcded8f | 2916 | add_alias_cmd ("var", "variable", class_vars, 0, &setlist); |
c906108c | 2917 | |
7d8062de PA |
2918 | const auto print_opts = make_value_print_options_def_group (nullptr); |
2919 | ||
8abfcabc | 2920 | static const std::string print_help = gdb::option::build_help (_("\ |
1bedd215 | 2921 | Print value of expression EXP.\n\ |
7d8062de PA |
2922 | Usage: print [[OPTION]... --] [/FMT] [EXP]\n\ |
2923 | \n\ | |
2924 | Options:\n\ | |
590042fc PW |
2925 | %OPTIONS%\n\ |
2926 | \n\ | |
7d8062de PA |
2927 | Note: because this command accepts arbitrary expressions, if you\n\ |
2928 | specify any command option, you must use a double dash (\"--\")\n\ | |
2929 | to mark the end of option processing. E.g.: \"print -o -- myobj\".\n\ | |
2930 | \n\ | |
c906108c SS |
2931 | Variables accessible are those of the lexical environment of the selected\n\ |
2932 | stack frame, plus all those whose scope is global or an entire file.\n\ | |
2933 | \n\ | |
2934 | $NUM gets previous value number NUM. $ and $$ are the last two values.\n\ | |
2935 | $$NUM refers to NUM'th value back from the last one.\n\ | |
1bedd215 AC |
2936 | Names starting with $ refer to registers (with the values they would have\n\ |
2937 | if the program were to return to the stack frame now selected, restoring\n\ | |
c906108c SS |
2938 | all registers saved by frames farther in) or else to debugger\n\ |
2939 | \"convenience\" variables (any such name not a known register).\n\ | |
1bedd215 AC |
2940 | Use assignment expressions to give values to convenience variables.\n\ |
2941 | \n\ | |
c906108c SS |
2942 | {TYPE}ADREXP refers to a datum of data type TYPE, located at address ADREXP.\n\ |
2943 | @ is a binary operator for treating consecutive data objects\n\ | |
2944 | anywhere in memory as an array. FOO@NUM gives an array whose first\n\ | |
2945 | element is FOO, whose second element is stored in the space following\n\ | |
2946 | where FOO is stored, etc. FOO must be an expression whose value\n\ | |
1bedd215 AC |
2947 | resides in memory.\n\ |
2948 | \n\ | |
c906108c | 2949 | EXP may be preceded with /FMT, where FMT is a format letter\n\ |
7d8062de PA |
2950 | but no count or size letter (see \"x\" command)."), |
2951 | print_opts); | |
2952 | ||
2953 | c = add_com ("print", class_vars, print_command, print_help.c_str ()); | |
2954 | set_cmd_completer_handle_brkchars (c, print_command_completer); | |
c906108c | 2955 | add_com_alias ("p", "print", class_vars, 1); |
e93a8774 | 2956 | add_com_alias ("inspect", "print", class_vars, 1); |
c906108c | 2957 | |
35096d9d AC |
2958 | add_setshow_uinteger_cmd ("max-symbolic-offset", no_class, |
2959 | &max_symbolic_offset, _("\ | |
188e1fa9 TT |
2960 | Set the largest offset that will be printed in <SYMBOL+1234> form."), _("\ |
2961 | Show the largest offset that will be printed in <SYMBOL+1234> form."), _("\ | |
f81d1120 PA |
2962 | Tell GDB to only display the symbolic form of an address if the\n\ |
2963 | offset between the closest earlier symbol and the address is less than\n\ | |
2964 | the specified maximum offset. The default is \"unlimited\", which tells GDB\n\ | |
2965 | to always print the symbolic form of an address if any symbol precedes\n\ | |
2966 | it. Zero is equivalent to \"unlimited\"."), | |
35096d9d | 2967 | NULL, |
920d2a44 | 2968 | show_max_symbolic_offset, |
35096d9d | 2969 | &setprintlist, &showprintlist); |
5bf193a2 AC |
2970 | add_setshow_boolean_cmd ("symbol-filename", no_class, |
2971 | &print_symbol_filename, _("\ | |
188e1fa9 TT |
2972 | Set printing of source filename and line number with <SYMBOL>."), _("\ |
2973 | Show printing of source filename and line number with <SYMBOL>."), NULL, | |
5bf193a2 | 2974 | NULL, |
920d2a44 | 2975 | show_print_symbol_filename, |
5bf193a2 | 2976 | &setprintlist, &showprintlist); |
f1421989 HZ |
2977 | |
2978 | add_com ("eval", no_class, eval_command, _("\ | |
188e1fa9 TT |
2979 | Construct a GDB command and then evaluate it.\n\ |
2980 | Usage: eval \"format string\", ARG1, ARG2, ARG3, ..., ARGN\n\ | |
2981 | Convert the arguments to a string as \"printf\" would, but then\n\ | |
2982 | treat this string as a command line, and evaluate it.")); | |
c906108c | 2983 | } |