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