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