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