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