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