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