| 1 | /* Memory-access and commands for "inferior" process, for GDB. |
| 2 | Copyright 1986, 87, 88, 89, 91, 92, 95, 96, 1998 |
| 3 | Free Software Foundation, Inc. |
| 4 | |
| 5 | This file is part of GDB. |
| 6 | |
| 7 | This program is free software; you can redistribute it and/or modify |
| 8 | it under the terms of the GNU General Public License as published by |
| 9 | the Free Software Foundation; either version 2 of the License, or |
| 10 | (at your option) any later version. |
| 11 | |
| 12 | This program is distributed in the hope that it will be useful, |
| 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 15 | GNU General Public License for more details. |
| 16 | |
| 17 | You should have received a copy of the GNU General Public License |
| 18 | along with this program; if not, write to the Free Software |
| 19 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ |
| 20 | |
| 21 | #include "defs.h" |
| 22 | #include <signal.h> |
| 23 | #include "gdb_string.h" |
| 24 | #include "symtab.h" |
| 25 | #include "gdbtypes.h" |
| 26 | #include "frame.h" |
| 27 | #include "inferior.h" |
| 28 | #include "environ.h" |
| 29 | #include "value.h" |
| 30 | #include "gdbcmd.h" |
| 31 | #include "gdbcore.h" |
| 32 | #include "target.h" |
| 33 | #include "language.h" |
| 34 | #include "symfile.h" |
| 35 | #include "objfiles.h" |
| 36 | |
| 37 | /* Functions exported for general use: */ |
| 38 | |
| 39 | void nofp_registers_info PARAMS ((char *, int)); |
| 40 | |
| 41 | void all_registers_info PARAMS ((char *, int)); |
| 42 | |
| 43 | void registers_info PARAMS ((char *, int)); |
| 44 | |
| 45 | /* Local functions: */ |
| 46 | |
| 47 | void continue_command PARAMS ((char *, int)); |
| 48 | |
| 49 | static void until_next_command PARAMS ((int)); |
| 50 | |
| 51 | static void until_command PARAMS ((char *, int)); |
| 52 | |
| 53 | static void path_info PARAMS ((char *, int)); |
| 54 | |
| 55 | static void path_command PARAMS ((char *, int)); |
| 56 | |
| 57 | static void unset_command PARAMS ((char *, int)); |
| 58 | |
| 59 | static void float_info PARAMS ((char *, int)); |
| 60 | |
| 61 | static void detach_command PARAMS ((char *, int)); |
| 62 | |
| 63 | #if !defined (DO_REGISTERS_INFO) |
| 64 | static void do_registers_info PARAMS ((int, int)); |
| 65 | #endif |
| 66 | |
| 67 | static void unset_environment_command PARAMS ((char *, int)); |
| 68 | |
| 69 | static void set_environment_command PARAMS ((char *, int)); |
| 70 | |
| 71 | static void environment_info PARAMS ((char *, int)); |
| 72 | |
| 73 | static void program_info PARAMS ((char *, int)); |
| 74 | |
| 75 | static void finish_command PARAMS ((char *, int)); |
| 76 | |
| 77 | static void signal_command PARAMS ((char *, int)); |
| 78 | |
| 79 | static void jump_command PARAMS ((char *, int)); |
| 80 | |
| 81 | static void step_1 PARAMS ((int, int, char *)); |
| 82 | |
| 83 | void nexti_command PARAMS ((char *, int)); |
| 84 | |
| 85 | void stepi_command PARAMS ((char *, int)); |
| 86 | |
| 87 | static void next_command PARAMS ((char *, int)); |
| 88 | |
| 89 | static void step_command PARAMS ((char *, int)); |
| 90 | |
| 91 | static void run_command PARAMS ((char *, int)); |
| 92 | |
| 93 | static void run_no_args_command PARAMS ((char *args, int from_tty)); |
| 94 | |
| 95 | static void go_command PARAMS ((char *line_no, int from_tty)); |
| 96 | |
| 97 | void _initialize_infcmd PARAMS ((void)); |
| 98 | |
| 99 | #define GO_USAGE "Usage: go <location>\n" |
| 100 | |
| 101 | static void breakpoint_auto_delete_contents PARAMS ((PTR)); |
| 102 | |
| 103 | #define ERROR_NO_INFERIOR \ |
| 104 | if (!target_has_execution) error ("The program is not being run."); |
| 105 | |
| 106 | /* String containing arguments to give to the program, separated by spaces. |
| 107 | Empty string (pointer to '\0') means no args. */ |
| 108 | |
| 109 | static char *inferior_args; |
| 110 | |
| 111 | /* File name for default use for standard in/out in the inferior. */ |
| 112 | |
| 113 | char *inferior_io_terminal; |
| 114 | |
| 115 | /* Pid of our debugged inferior, or 0 if no inferior now. |
| 116 | Since various parts of infrun.c test this to see whether there is a program |
| 117 | being debugged it should be nonzero (currently 3 is used) for remote |
| 118 | debugging. */ |
| 119 | |
| 120 | int inferior_pid; |
| 121 | |
| 122 | /* Last signal that the inferior received (why it stopped). */ |
| 123 | |
| 124 | enum target_signal stop_signal; |
| 125 | |
| 126 | /* Address at which inferior stopped. */ |
| 127 | |
| 128 | CORE_ADDR stop_pc; |
| 129 | |
| 130 | /* Chain containing status of breakpoint(s) that we have stopped at. */ |
| 131 | |
| 132 | bpstat stop_bpstat; |
| 133 | |
| 134 | /* Flag indicating that a command has proceeded the inferior past the |
| 135 | current breakpoint. */ |
| 136 | |
| 137 | int breakpoint_proceeded; |
| 138 | |
| 139 | /* Nonzero if stopped due to a step command. */ |
| 140 | |
| 141 | int stop_step; |
| 142 | |
| 143 | /* Nonzero if stopped due to completion of a stack dummy routine. */ |
| 144 | |
| 145 | int stop_stack_dummy; |
| 146 | |
| 147 | /* Nonzero if stopped due to a random (unexpected) signal in inferior |
| 148 | process. */ |
| 149 | |
| 150 | int stopped_by_random_signal; |
| 151 | |
| 152 | /* Range to single step within. |
| 153 | If this is nonzero, respond to a single-step signal |
| 154 | by continuing to step if the pc is in this range. */ |
| 155 | |
| 156 | CORE_ADDR step_range_start; /* Inclusive */ |
| 157 | CORE_ADDR step_range_end; /* Exclusive */ |
| 158 | |
| 159 | /* Stack frame address as of when stepping command was issued. |
| 160 | This is how we know when we step into a subroutine call, |
| 161 | and how to set the frame for the breakpoint used to step out. */ |
| 162 | |
| 163 | CORE_ADDR step_frame_address; |
| 164 | |
| 165 | /* Our notion of the current stack pointer. */ |
| 166 | |
| 167 | CORE_ADDR step_sp; |
| 168 | |
| 169 | /* 1 means step over all subroutine calls. |
| 170 | 0 means don't step over calls (used by stepi). |
| 171 | -1 means step over calls to undebuggable functions. */ |
| 172 | |
| 173 | int step_over_calls; |
| 174 | |
| 175 | /* If stepping, nonzero means step count is > 1 |
| 176 | so don't print frame next time inferior stops |
| 177 | if it stops due to stepping. */ |
| 178 | |
| 179 | int step_multi; |
| 180 | |
| 181 | /* Environment to use for running inferior, |
| 182 | in format described in environ.h. */ |
| 183 | |
| 184 | struct environ *inferior_environ; |
| 185 | |
| 186 | \f |
| 187 | /* ARGSUSED */ |
| 188 | void |
| 189 | tty_command (file, from_tty) |
| 190 | char *file; |
| 191 | int from_tty; |
| 192 | { |
| 193 | if (file == 0) |
| 194 | error_no_arg ("terminal name for running target process"); |
| 195 | |
| 196 | inferior_io_terminal = savestring (file, strlen (file)); |
| 197 | } |
| 198 | |
| 199 | static void |
| 200 | run_command (args, from_tty) |
| 201 | char *args; |
| 202 | int from_tty; |
| 203 | { |
| 204 | char *exec_file; |
| 205 | |
| 206 | dont_repeat (); |
| 207 | |
| 208 | if (inferior_pid != 0 && target_has_execution) |
| 209 | { |
| 210 | if ( |
| 211 | !query ("The program being debugged has been started already.\n\ |
| 212 | Start it from the beginning? ")) |
| 213 | error ("Program not restarted."); |
| 214 | target_kill (); |
| 215 | #if defined(SOLIB_RESTART) |
| 216 | SOLIB_RESTART (); |
| 217 | #endif |
| 218 | init_wait_for_inferior (); |
| 219 | } |
| 220 | |
| 221 | clear_breakpoint_hit_counts (); |
| 222 | |
| 223 | exec_file = (char *) get_exec_file (0); |
| 224 | |
| 225 | /* Purge old solib objfiles. */ |
| 226 | objfile_purge_solibs (); |
| 227 | |
| 228 | do_run_cleanups (NULL); |
| 229 | |
| 230 | /* The exec file is re-read every time we do a generic_mourn_inferior, so |
| 231 | we just have to worry about the symbol file. */ |
| 232 | reread_symbols (); |
| 233 | |
| 234 | /* We keep symbols from add-symbol-file, on the grounds that the |
| 235 | user might want to add some symbols before running the program |
| 236 | (right?). But sometimes (dynamic loading where the user manually |
| 237 | introduces the new symbols with add-symbol-file), the code which |
| 238 | the symbols describe does not persist between runs. Currently |
| 239 | the user has to manually nuke all symbols between runs if they |
| 240 | want them to go away (PR 2207). This is probably reasonable. */ |
| 241 | |
| 242 | if (args) |
| 243 | { |
| 244 | char *cmd; |
| 245 | cmd = concat ("set args ", args, NULL); |
| 246 | make_cleanup (free, cmd); |
| 247 | execute_command (cmd, from_tty); |
| 248 | } |
| 249 | |
| 250 | if (from_tty) |
| 251 | { |
| 252 | puts_filtered("Starting program: "); |
| 253 | if (exec_file) |
| 254 | puts_filtered(exec_file); |
| 255 | puts_filtered(" "); |
| 256 | puts_filtered(inferior_args); |
| 257 | puts_filtered("\n"); |
| 258 | gdb_flush (gdb_stdout); |
| 259 | } |
| 260 | |
| 261 | target_create_inferior (exec_file, inferior_args, |
| 262 | environ_vector (inferior_environ)); |
| 263 | } |
| 264 | |
| 265 | |
| 266 | static void |
| 267 | run_no_args_command (args, from_tty) |
| 268 | char *args; |
| 269 | int from_tty; |
| 270 | { |
| 271 | execute_command("set args", from_tty); |
| 272 | run_command((char *)NULL, from_tty); |
| 273 | } |
| 274 | |
| 275 | \f |
| 276 | void |
| 277 | continue_command (proc_count_exp, from_tty) |
| 278 | char *proc_count_exp; |
| 279 | int from_tty; |
| 280 | { |
| 281 | ERROR_NO_INFERIOR; |
| 282 | |
| 283 | /* If have argument, set proceed count of breakpoint we stopped at. */ |
| 284 | |
| 285 | if (proc_count_exp != NULL) |
| 286 | { |
| 287 | bpstat bs = stop_bpstat; |
| 288 | int num = bpstat_num (&bs); |
| 289 | if (num == 0 && from_tty) |
| 290 | { |
| 291 | printf_filtered |
| 292 | ("Not stopped at any breakpoint; argument ignored.\n"); |
| 293 | } |
| 294 | while (num != 0) |
| 295 | { |
| 296 | set_ignore_count (num, |
| 297 | parse_and_eval_address (proc_count_exp) - 1, |
| 298 | from_tty); |
| 299 | /* set_ignore_count prints a message ending with a period. |
| 300 | So print two spaces before "Continuing.". */ |
| 301 | if (from_tty) |
| 302 | printf_filtered (" "); |
| 303 | num = bpstat_num (&bs); |
| 304 | } |
| 305 | } |
| 306 | |
| 307 | if (from_tty) |
| 308 | printf_filtered ("Continuing.\n"); |
| 309 | |
| 310 | clear_proceed_status (); |
| 311 | |
| 312 | proceed ((CORE_ADDR) -1, TARGET_SIGNAL_DEFAULT, 0); |
| 313 | } |
| 314 | \f |
| 315 | /* Step until outside of current statement. */ |
| 316 | |
| 317 | /* ARGSUSED */ |
| 318 | static void |
| 319 | step_command (count_string, from_tty) |
| 320 | char *count_string; |
| 321 | int from_tty; |
| 322 | { |
| 323 | step_1 (0, 0, count_string); |
| 324 | } |
| 325 | |
| 326 | /* Likewise, but skip over subroutine calls as if single instructions. */ |
| 327 | |
| 328 | /* ARGSUSED */ |
| 329 | static void |
| 330 | next_command (count_string, from_tty) |
| 331 | char *count_string; |
| 332 | int from_tty; |
| 333 | { |
| 334 | step_1 (1, 0, count_string); |
| 335 | } |
| 336 | |
| 337 | /* Likewise, but step only one instruction. */ |
| 338 | |
| 339 | /* ARGSUSED */ |
| 340 | void |
| 341 | stepi_command (count_string, from_tty) |
| 342 | char *count_string; |
| 343 | int from_tty; |
| 344 | { |
| 345 | step_1 (0, 1, count_string); |
| 346 | } |
| 347 | |
| 348 | /* ARGSUSED */ |
| 349 | void |
| 350 | nexti_command (count_string, from_tty) |
| 351 | char *count_string; |
| 352 | int from_tty; |
| 353 | { |
| 354 | step_1 (1, 1, count_string); |
| 355 | } |
| 356 | |
| 357 | static void |
| 358 | step_1 (skip_subroutines, single_inst, count_string) |
| 359 | int skip_subroutines; |
| 360 | int single_inst; |
| 361 | char *count_string; |
| 362 | { |
| 363 | register int count = 1; |
| 364 | struct frame_info *frame; |
| 365 | struct cleanup *cleanups = 0; |
| 366 | |
| 367 | ERROR_NO_INFERIOR; |
| 368 | count = count_string ? parse_and_eval_address (count_string) : 1; |
| 369 | |
| 370 | if (!single_inst || skip_subroutines) /* leave si command alone */ |
| 371 | { |
| 372 | enable_longjmp_breakpoint(); |
| 373 | cleanups = make_cleanup ((make_cleanup_func) disable_longjmp_breakpoint, |
| 374 | 0); |
| 375 | } |
| 376 | |
| 377 | for (; count > 0; count--) |
| 378 | { |
| 379 | clear_proceed_status (); |
| 380 | |
| 381 | frame = get_current_frame (); |
| 382 | if (!frame) /* Avoid coredump here. Why tho? */ |
| 383 | error ("No current frame"); |
| 384 | step_frame_address = FRAME_FP (frame); |
| 385 | step_sp = read_sp (); |
| 386 | |
| 387 | if (! single_inst) |
| 388 | { |
| 389 | find_pc_line_pc_range (stop_pc, &step_range_start, &step_range_end); |
| 390 | if (step_range_end == 0) |
| 391 | { |
| 392 | char *name; |
| 393 | if (find_pc_partial_function (stop_pc, &name, &step_range_start, |
| 394 | &step_range_end) == 0) |
| 395 | error ("Cannot find bounds of current function"); |
| 396 | |
| 397 | target_terminal_ours (); |
| 398 | printf_filtered ("\ |
| 399 | Single stepping until exit from function %s, \n\ |
| 400 | which has no line number information.\n", name); |
| 401 | } |
| 402 | } |
| 403 | else |
| 404 | { |
| 405 | /* Say we are stepping, but stop after one insn whatever it does. */ |
| 406 | step_range_start = step_range_end = 1; |
| 407 | if (!skip_subroutines) |
| 408 | /* It is stepi. |
| 409 | Don't step over function calls, not even to functions lacking |
| 410 | line numbers. */ |
| 411 | step_over_calls = 0; |
| 412 | } |
| 413 | |
| 414 | if (skip_subroutines) |
| 415 | step_over_calls = 1; |
| 416 | |
| 417 | step_multi = (count > 1); |
| 418 | proceed ((CORE_ADDR) -1, TARGET_SIGNAL_DEFAULT, 1); |
| 419 | if (! stop_step) |
| 420 | break; |
| 421 | |
| 422 | /* FIXME: On nexti, this may have already been done (when we hit the |
| 423 | step resume break, I think). Probably this should be moved to |
| 424 | wait_for_inferior (near the top). */ |
| 425 | #if defined (SHIFT_INST_REGS) |
| 426 | SHIFT_INST_REGS(); |
| 427 | #endif |
| 428 | } |
| 429 | |
| 430 | if (!single_inst || skip_subroutines) |
| 431 | do_cleanups(cleanups); |
| 432 | } |
| 433 | \f |
| 434 | /* Continue program at specified address. */ |
| 435 | |
| 436 | static void |
| 437 | jump_command (arg, from_tty) |
| 438 | char *arg; |
| 439 | int from_tty; |
| 440 | { |
| 441 | register CORE_ADDR addr; |
| 442 | struct symtabs_and_lines sals; |
| 443 | struct symtab_and_line sal; |
| 444 | struct symbol *fn; |
| 445 | struct symbol *sfn; |
| 446 | |
| 447 | ERROR_NO_INFERIOR; |
| 448 | |
| 449 | if (!arg) |
| 450 | error_no_arg ("starting address"); |
| 451 | |
| 452 | sals = decode_line_spec_1 (arg, 1); |
| 453 | if (sals.nelts != 1) |
| 454 | { |
| 455 | error ("Unreasonable jump request"); |
| 456 | } |
| 457 | |
| 458 | sal = sals.sals[0]; |
| 459 | free ((PTR)sals.sals); |
| 460 | |
| 461 | if (sal.symtab == 0 && sal.pc == 0) |
| 462 | error ("No source file has been specified."); |
| 463 | |
| 464 | resolve_sal_pc (&sal); /* May error out */ |
| 465 | |
| 466 | /* See if we are trying to jump to another function. */ |
| 467 | fn = get_frame_function (get_current_frame ()); |
| 468 | sfn = find_pc_function (sal.pc); |
| 469 | if (fn != NULL && sfn != fn) |
| 470 | { |
| 471 | if (!query ("Line %d is not in `%s'. Jump anyway? ", sal.line, |
| 472 | SYMBOL_SOURCE_NAME (fn))) |
| 473 | { |
| 474 | error ("Not confirmed."); |
| 475 | /* NOTREACHED */ |
| 476 | } |
| 477 | } |
| 478 | |
| 479 | if (sfn != NULL) |
| 480 | { |
| 481 | fixup_symbol_section (sfn, 0); |
| 482 | if (section_is_overlay (SYMBOL_BFD_SECTION (sfn)) && |
| 483 | !section_is_mapped (SYMBOL_BFD_SECTION (sfn))) |
| 484 | { |
| 485 | if (!query ("WARNING!!! Destination is in unmapped overlay! Jump anyway? ")) |
| 486 | { |
| 487 | error ("Not confirmed."); |
| 488 | /* NOTREACHED */ |
| 489 | } |
| 490 | } |
| 491 | } |
| 492 | |
| 493 | |
| 494 | addr = sal.pc; |
| 495 | |
| 496 | if (from_tty) |
| 497 | { |
| 498 | printf_filtered ("Continuing at "); |
| 499 | print_address_numeric (addr, 1, gdb_stdout); |
| 500 | printf_filtered (".\n"); |
| 501 | } |
| 502 | |
| 503 | clear_proceed_status (); |
| 504 | proceed (addr, TARGET_SIGNAL_0, 0); |
| 505 | } |
| 506 | |
| 507 | \f |
| 508 | /* Go to line or address in current procedure */ |
| 509 | static void |
| 510 | go_command (line_no, from_tty) |
| 511 | char *line_no; |
| 512 | int from_tty; |
| 513 | { |
| 514 | if (line_no == (char *)NULL || !*line_no) |
| 515 | printf_filtered (GO_USAGE); |
| 516 | else |
| 517 | { |
| 518 | tbreak_command (line_no, from_tty); |
| 519 | jump_command (line_no, from_tty); |
| 520 | } |
| 521 | } |
| 522 | |
| 523 | \f |
| 524 | /* Continue program giving it specified signal. */ |
| 525 | |
| 526 | static void |
| 527 | signal_command (signum_exp, from_tty) |
| 528 | char *signum_exp; |
| 529 | int from_tty; |
| 530 | { |
| 531 | enum target_signal oursig; |
| 532 | |
| 533 | dont_repeat (); /* Too dangerous. */ |
| 534 | ERROR_NO_INFERIOR; |
| 535 | |
| 536 | if (!signum_exp) |
| 537 | error_no_arg ("signal number"); |
| 538 | |
| 539 | /* It would be even slicker to make signal names be valid expressions, |
| 540 | (the type could be "enum $signal" or some such), then the user could |
| 541 | assign them to convenience variables. */ |
| 542 | oursig = target_signal_from_name (signum_exp); |
| 543 | |
| 544 | if (oursig == TARGET_SIGNAL_UNKNOWN) |
| 545 | { |
| 546 | /* No, try numeric. */ |
| 547 | int num = parse_and_eval_address (signum_exp); |
| 548 | |
| 549 | if (num == 0) |
| 550 | oursig = TARGET_SIGNAL_0; |
| 551 | else |
| 552 | oursig = target_signal_from_command (num); |
| 553 | } |
| 554 | |
| 555 | if (from_tty) |
| 556 | { |
| 557 | if (oursig == TARGET_SIGNAL_0) |
| 558 | printf_filtered ("Continuing with no signal.\n"); |
| 559 | else |
| 560 | printf_filtered ("Continuing with signal %s.\n", |
| 561 | target_signal_to_name (oursig)); |
| 562 | } |
| 563 | |
| 564 | clear_proceed_status (); |
| 565 | /* "signal 0" should not get stuck if we are stopped at a breakpoint. |
| 566 | FIXME: Neither should "signal foo" but when I tried passing |
| 567 | (CORE_ADDR)-1 unconditionally I got a testsuite failure which I haven't |
| 568 | tried to track down yet. */ |
| 569 | proceed (oursig == TARGET_SIGNAL_0 ? (CORE_ADDR) -1 : stop_pc, oursig, 0); |
| 570 | } |
| 571 | |
| 572 | /* Call breakpoint_auto_delete on the current contents of the bpstat |
| 573 | pointed to by arg (which is really a bpstat *). */ |
| 574 | |
| 575 | static void |
| 576 | breakpoint_auto_delete_contents (arg) |
| 577 | PTR arg; |
| 578 | { |
| 579 | breakpoint_auto_delete (*(bpstat *)arg); |
| 580 | } |
| 581 | |
| 582 | |
| 583 | /* Execute a "stack dummy", a piece of code stored in the stack |
| 584 | by the debugger to be executed in the inferior. |
| 585 | |
| 586 | To call: first, do PUSH_DUMMY_FRAME. |
| 587 | Then push the contents of the dummy. It should end with a breakpoint insn. |
| 588 | Then call here, passing address at which to start the dummy. |
| 589 | |
| 590 | The contents of all registers are saved before the dummy frame is popped |
| 591 | and copied into the buffer BUFFER. |
| 592 | |
| 593 | The dummy's frame is automatically popped whenever that break is hit. |
| 594 | If that is the first time the program stops, run_stack_dummy |
| 595 | returns to its caller with that frame already gone and returns 0. |
| 596 | Otherwise, run_stack-dummy returns 1 (the frame will eventually be popped |
| 597 | when we do hit that breakpoint). */ |
| 598 | |
| 599 | /* DEBUG HOOK: 4 => return instead of letting the stack dummy run. */ |
| 600 | |
| 601 | static int stack_dummy_testing = 0; |
| 602 | |
| 603 | int |
| 604 | run_stack_dummy (addr, buffer) |
| 605 | CORE_ADDR addr; |
| 606 | char *buffer; |
| 607 | { |
| 608 | struct cleanup *old_cleanups = make_cleanup (null_cleanup, 0); |
| 609 | |
| 610 | /* Now proceed, having reached the desired place. */ |
| 611 | clear_proceed_status (); |
| 612 | if (stack_dummy_testing & 4) |
| 613 | { |
| 614 | POP_FRAME; |
| 615 | return(0); |
| 616 | } |
| 617 | if (CALL_DUMMY_BREAKPOINT_OFFSET_P) |
| 618 | { |
| 619 | struct breakpoint *bpt; |
| 620 | struct symtab_and_line sal; |
| 621 | |
| 622 | INIT_SAL (&sal); /* initialize to zeroes */ |
| 623 | if (CALL_DUMMY_LOCATION == AT_ENTRY_POINT) |
| 624 | { |
| 625 | sal.pc = CALL_DUMMY_ADDRESS (); |
| 626 | } |
| 627 | else |
| 628 | { |
| 629 | sal.pc = addr - CALL_DUMMY_START_OFFSET + CALL_DUMMY_BREAKPOINT_OFFSET; |
| 630 | } |
| 631 | sal.section = find_pc_overlay (sal.pc); |
| 632 | |
| 633 | /* Set up a FRAME for the dummy frame so we can pass it to |
| 634 | set_momentary_breakpoint. We need to give the breakpoint a |
| 635 | frame in case there is only one copy of the dummy (e.g. |
| 636 | CALL_DUMMY_LOCATION == AFTER_TEXT_END). */ |
| 637 | flush_cached_frames (); |
| 638 | set_current_frame (create_new_frame (read_fp (), sal.pc)); |
| 639 | |
| 640 | /* If defined, CALL_DUMMY_BREAKPOINT_OFFSET is where we need to put |
| 641 | a breakpoint instruction. If not, the call dummy already has the |
| 642 | breakpoint instruction in it. |
| 643 | |
| 644 | addr is the address of the call dummy plus the CALL_DUMMY_START_OFFSET, |
| 645 | so we need to subtract the CALL_DUMMY_START_OFFSET. */ |
| 646 | bpt = set_momentary_breakpoint (sal, |
| 647 | get_current_frame (), |
| 648 | bp_call_dummy); |
| 649 | bpt->disposition = del; |
| 650 | |
| 651 | /* If all error()s out of proceed ended up calling normal_stop (and |
| 652 | perhaps they should; it already does in the special case of error |
| 653 | out of resume()), then we wouldn't need this. */ |
| 654 | make_cleanup (breakpoint_auto_delete_contents, &stop_bpstat); |
| 655 | } |
| 656 | |
| 657 | disable_watchpoints_before_interactive_call_start (); |
| 658 | proceed_to_finish = 1; /* We want stop_registers, please... */ |
| 659 | proceed (addr, TARGET_SIGNAL_0, 0); |
| 660 | enable_watchpoints_after_interactive_call_stop (); |
| 661 | |
| 662 | discard_cleanups (old_cleanups); |
| 663 | |
| 664 | if (!stop_stack_dummy) |
| 665 | return 1; |
| 666 | |
| 667 | /* On return, the stack dummy has been popped already. */ |
| 668 | |
| 669 | memcpy (buffer, stop_registers, REGISTER_BYTES); |
| 670 | return 0; |
| 671 | } |
| 672 | \f |
| 673 | /* Proceed until we reach a different source line with pc greater than |
| 674 | our current one or exit the function. We skip calls in both cases. |
| 675 | |
| 676 | Note that eventually this command should probably be changed so |
| 677 | that only source lines are printed out when we hit the breakpoint |
| 678 | we set. This may involve changes to wait_for_inferior and the |
| 679 | proceed status code. */ |
| 680 | |
| 681 | /* ARGSUSED */ |
| 682 | static void |
| 683 | until_next_command (from_tty) |
| 684 | int from_tty; |
| 685 | { |
| 686 | struct frame_info *frame; |
| 687 | CORE_ADDR pc; |
| 688 | struct symbol *func; |
| 689 | struct symtab_and_line sal; |
| 690 | |
| 691 | clear_proceed_status (); |
| 692 | |
| 693 | frame = get_current_frame (); |
| 694 | |
| 695 | /* Step until either exited from this function or greater |
| 696 | than the current line (if in symbolic section) or pc (if |
| 697 | not). */ |
| 698 | |
| 699 | pc = read_pc (); |
| 700 | func = find_pc_function (pc); |
| 701 | |
| 702 | if (!func) |
| 703 | { |
| 704 | struct minimal_symbol *msymbol = lookup_minimal_symbol_by_pc (pc); |
| 705 | |
| 706 | if (msymbol == NULL) |
| 707 | error ("Execution is not within a known function."); |
| 708 | |
| 709 | step_range_start = SYMBOL_VALUE_ADDRESS (msymbol); |
| 710 | step_range_end = pc; |
| 711 | } |
| 712 | else |
| 713 | { |
| 714 | sal = find_pc_line (pc, 0); |
| 715 | |
| 716 | step_range_start = BLOCK_START (SYMBOL_BLOCK_VALUE (func)); |
| 717 | step_range_end = sal.end; |
| 718 | } |
| 719 | |
| 720 | step_over_calls = 1; |
| 721 | step_frame_address = FRAME_FP (frame); |
| 722 | step_sp = read_sp (); |
| 723 | |
| 724 | step_multi = 0; /* Only one call to proceed */ |
| 725 | |
| 726 | proceed ((CORE_ADDR) -1, TARGET_SIGNAL_DEFAULT, 1); |
| 727 | } |
| 728 | |
| 729 | static void |
| 730 | until_command (arg, from_tty) |
| 731 | char *arg; |
| 732 | int from_tty; |
| 733 | { |
| 734 | if (!target_has_execution) |
| 735 | error ("The program is not running."); |
| 736 | if (arg) |
| 737 | until_break_command (arg, from_tty); |
| 738 | else |
| 739 | until_next_command (from_tty); |
| 740 | } |
| 741 | \f |
| 742 | /* "finish": Set a temporary breakpoint at the place |
| 743 | the selected frame will return to, then continue. */ |
| 744 | |
| 745 | static void |
| 746 | finish_command (arg, from_tty) |
| 747 | char *arg; |
| 748 | int from_tty; |
| 749 | { |
| 750 | struct symtab_and_line sal; |
| 751 | register struct frame_info *frame; |
| 752 | register struct symbol *function; |
| 753 | struct breakpoint *breakpoint; |
| 754 | struct cleanup *old_chain; |
| 755 | |
| 756 | if (arg) |
| 757 | error ("The \"finish\" command does not take any arguments."); |
| 758 | if (!target_has_execution) |
| 759 | error ("The program is not running."); |
| 760 | if (selected_frame == NULL) |
| 761 | error ("No selected frame."); |
| 762 | |
| 763 | frame = get_prev_frame (selected_frame); |
| 764 | if (frame == 0) |
| 765 | error ("\"finish\" not meaningful in the outermost frame."); |
| 766 | |
| 767 | clear_proceed_status (); |
| 768 | |
| 769 | sal = find_pc_line (frame->pc, 0); |
| 770 | sal.pc = frame->pc; |
| 771 | |
| 772 | breakpoint = set_momentary_breakpoint (sal, frame, bp_finish); |
| 773 | |
| 774 | old_chain = make_cleanup ((make_cleanup_func) delete_breakpoint, breakpoint); |
| 775 | |
| 776 | /* Find the function we will return from. */ |
| 777 | |
| 778 | function = find_pc_function (selected_frame->pc); |
| 779 | |
| 780 | /* Print info on the selected frame, including level number |
| 781 | but not source. */ |
| 782 | if (from_tty) |
| 783 | { |
| 784 | printf_filtered ("Run till exit from "); |
| 785 | print_stack_frame (selected_frame, selected_frame_level, 0); |
| 786 | } |
| 787 | |
| 788 | proceed_to_finish = 1; /* We want stop_registers, please... */ |
| 789 | proceed ((CORE_ADDR) -1, TARGET_SIGNAL_DEFAULT, 0); |
| 790 | |
| 791 | /* Did we stop at our breakpoint? */ |
| 792 | if (bpstat_find_breakpoint(stop_bpstat, breakpoint) != NULL |
| 793 | && function != 0) |
| 794 | { |
| 795 | struct type *value_type; |
| 796 | register value_ptr val; |
| 797 | CORE_ADDR funcaddr; |
| 798 | int struct_return; |
| 799 | |
| 800 | value_type = TYPE_TARGET_TYPE (SYMBOL_TYPE (function)); |
| 801 | if (!value_type) |
| 802 | fatal ("internal: finish_command: function has no target type"); |
| 803 | |
| 804 | if (TYPE_CODE (value_type) == TYPE_CODE_VOID) |
| 805 | return; |
| 806 | |
| 807 | funcaddr = BLOCK_START (SYMBOL_BLOCK_VALUE (function)); |
| 808 | |
| 809 | struct_return = using_struct_return (value_of_variable (function, NULL), |
| 810 | |
| 811 | funcaddr, |
| 812 | check_typedef (value_type), |
| 813 | BLOCK_GCC_COMPILED (SYMBOL_BLOCK_VALUE (function))); |
| 814 | |
| 815 | if (!struct_return) |
| 816 | { |
| 817 | val = value_being_returned (value_type, stop_registers, struct_return); |
| 818 | printf_filtered ("Value returned is $%d = ", record_latest_value (val)); |
| 819 | value_print (val, gdb_stdout, 0, Val_no_prettyprint); |
| 820 | printf_filtered ("\n"); |
| 821 | } |
| 822 | else |
| 823 | { |
| 824 | /* elz: we cannot determine the contents of the structure because |
| 825 | it is on the stack, and we don't know where, since we did not |
| 826 | initiate the call, as opposed to the call_function_by_hand case */ |
| 827 | #ifdef VALUE_RETURNED_FROM_STACK |
| 828 | val = 0; |
| 829 | printf_filtered ("Value returned has type: %s.", |
| 830 | TYPE_NAME (value_type)); |
| 831 | printf_filtered (" Cannot determine contents\n"); |
| 832 | #else |
| 833 | val = value_being_returned (value_type, stop_registers, |
| 834 | struct_return); |
| 835 | printf_filtered ("Value returned is $%d = ", |
| 836 | record_latest_value (val)); |
| 837 | value_print (val, gdb_stdout, 0, Val_no_prettyprint); |
| 838 | printf_filtered ("\n"); |
| 839 | #endif |
| 840 | |
| 841 | } |
| 842 | } |
| 843 | do_cleanups(old_chain); |
| 844 | } |
| 845 | \f |
| 846 | /* ARGSUSED */ |
| 847 | static void |
| 848 | program_info (args, from_tty) |
| 849 | char *args; |
| 850 | int from_tty; |
| 851 | { |
| 852 | bpstat bs = stop_bpstat; |
| 853 | int num = bpstat_num (&bs); |
| 854 | |
| 855 | if (!target_has_execution) |
| 856 | { |
| 857 | printf_filtered ("The program being debugged is not being run.\n"); |
| 858 | return; |
| 859 | } |
| 860 | |
| 861 | target_files_info (); |
| 862 | printf_filtered ("Program stopped at %s.\n", |
| 863 | local_hex_string((unsigned long) stop_pc)); |
| 864 | if (stop_step) |
| 865 | printf_filtered ("It stopped after being stepped.\n"); |
| 866 | else if (num != 0) |
| 867 | { |
| 868 | /* There may be several breakpoints in the same place, so this |
| 869 | isn't as strange as it seems. */ |
| 870 | while (num != 0) |
| 871 | { |
| 872 | if (num < 0) |
| 873 | { |
| 874 | printf_filtered ("It stopped at a breakpoint that has "); |
| 875 | printf_filtered ("since been deleted.\n"); |
| 876 | } |
| 877 | else |
| 878 | printf_filtered ("It stopped at breakpoint %d.\n", num); |
| 879 | num = bpstat_num (&bs); |
| 880 | } |
| 881 | } |
| 882 | else if (stop_signal != TARGET_SIGNAL_0) |
| 883 | { |
| 884 | printf_filtered ("It stopped with signal %s, %s.\n", |
| 885 | target_signal_to_name (stop_signal), |
| 886 | target_signal_to_string (stop_signal)); |
| 887 | } |
| 888 | |
| 889 | if (!from_tty) |
| 890 | { |
| 891 | printf_filtered ("Type \"info stack\" or \"info registers\" "); |
| 892 | printf_filtered ("for more information.\n"); |
| 893 | } |
| 894 | } |
| 895 | \f |
| 896 | static void |
| 897 | environment_info (var, from_tty) |
| 898 | char *var; |
| 899 | int from_tty; |
| 900 | { |
| 901 | if (var) |
| 902 | { |
| 903 | register char *val = get_in_environ (inferior_environ, var); |
| 904 | if (val) |
| 905 | { |
| 906 | puts_filtered (var); |
| 907 | puts_filtered (" = "); |
| 908 | puts_filtered (val); |
| 909 | puts_filtered ("\n"); |
| 910 | } |
| 911 | else |
| 912 | { |
| 913 | puts_filtered ("Environment variable \""); |
| 914 | puts_filtered (var); |
| 915 | puts_filtered ("\" not defined.\n"); |
| 916 | } |
| 917 | } |
| 918 | else |
| 919 | { |
| 920 | register char **vector = environ_vector (inferior_environ); |
| 921 | while (*vector) |
| 922 | { |
| 923 | puts_filtered (*vector++); |
| 924 | puts_filtered ("\n"); |
| 925 | } |
| 926 | } |
| 927 | } |
| 928 | |
| 929 | static void |
| 930 | set_environment_command (arg, from_tty) |
| 931 | char *arg; |
| 932 | int from_tty; |
| 933 | { |
| 934 | register char *p, *val, *var; |
| 935 | int nullset = 0; |
| 936 | |
| 937 | if (arg == 0) |
| 938 | error_no_arg ("environment variable and value"); |
| 939 | |
| 940 | /* Find seperation between variable name and value */ |
| 941 | p = (char *) strchr (arg, '='); |
| 942 | val = (char *) strchr (arg, ' '); |
| 943 | |
| 944 | if (p != 0 && val != 0) |
| 945 | { |
| 946 | /* We have both a space and an equals. If the space is before the |
| 947 | equals, walk forward over the spaces til we see a nonspace |
| 948 | (possibly the equals). */ |
| 949 | if (p > val) |
| 950 | while (*val == ' ') |
| 951 | val++; |
| 952 | |
| 953 | /* Now if the = is after the char following the spaces, |
| 954 | take the char following the spaces. */ |
| 955 | if (p > val) |
| 956 | p = val - 1; |
| 957 | } |
| 958 | else if (val != 0 && p == 0) |
| 959 | p = val; |
| 960 | |
| 961 | if (p == arg) |
| 962 | error_no_arg ("environment variable to set"); |
| 963 | |
| 964 | if (p == 0 || p[1] == 0) |
| 965 | { |
| 966 | nullset = 1; |
| 967 | if (p == 0) |
| 968 | p = arg + strlen (arg); /* So that savestring below will work */ |
| 969 | } |
| 970 | else |
| 971 | { |
| 972 | /* Not setting variable value to null */ |
| 973 | val = p + 1; |
| 974 | while (*val == ' ' || *val == '\t') |
| 975 | val++; |
| 976 | } |
| 977 | |
| 978 | while (p != arg && (p[-1] == ' ' || p[-1] == '\t')) p--; |
| 979 | |
| 980 | var = savestring (arg, p - arg); |
| 981 | if (nullset) |
| 982 | { |
| 983 | printf_filtered ("Setting environment variable "); |
| 984 | printf_filtered ("\"%s\" to null value.\n", var); |
| 985 | set_in_environ (inferior_environ, var, ""); |
| 986 | } |
| 987 | else |
| 988 | set_in_environ (inferior_environ, var, val); |
| 989 | free (var); |
| 990 | } |
| 991 | |
| 992 | static void |
| 993 | unset_environment_command (var, from_tty) |
| 994 | char *var; |
| 995 | int from_tty; |
| 996 | { |
| 997 | if (var == 0) |
| 998 | { |
| 999 | /* If there is no argument, delete all environment variables. |
| 1000 | Ask for confirmation if reading from the terminal. */ |
| 1001 | if (!from_tty || query ("Delete all environment variables? ")) |
| 1002 | { |
| 1003 | free_environ (inferior_environ); |
| 1004 | inferior_environ = make_environ (); |
| 1005 | } |
| 1006 | } |
| 1007 | else |
| 1008 | unset_in_environ (inferior_environ, var); |
| 1009 | } |
| 1010 | |
| 1011 | /* Handle the execution path (PATH variable) */ |
| 1012 | |
| 1013 | static const char path_var_name[] = "PATH"; |
| 1014 | |
| 1015 | /* ARGSUSED */ |
| 1016 | static void |
| 1017 | path_info (args, from_tty) |
| 1018 | char *args; |
| 1019 | int from_tty; |
| 1020 | { |
| 1021 | puts_filtered ("Executable and object file path: "); |
| 1022 | puts_filtered (get_in_environ (inferior_environ, path_var_name)); |
| 1023 | puts_filtered ("\n"); |
| 1024 | } |
| 1025 | |
| 1026 | /* Add zero or more directories to the front of the execution path. */ |
| 1027 | |
| 1028 | static void |
| 1029 | path_command (dirname, from_tty) |
| 1030 | char *dirname; |
| 1031 | int from_tty; |
| 1032 | { |
| 1033 | char *exec_path; |
| 1034 | char *env; |
| 1035 | dont_repeat (); |
| 1036 | env = get_in_environ (inferior_environ, path_var_name); |
| 1037 | /* Can be null if path is not set */ |
| 1038 | if (!env) |
| 1039 | env = ""; |
| 1040 | exec_path = strsave (env); |
| 1041 | mod_path (dirname, &exec_path); |
| 1042 | set_in_environ (inferior_environ, path_var_name, exec_path); |
| 1043 | free (exec_path); |
| 1044 | if (from_tty) |
| 1045 | path_info ((char *)NULL, from_tty); |
| 1046 | } |
| 1047 | |
| 1048 | \f |
| 1049 | #ifdef REGISTER_NAMES |
| 1050 | char *gdb_register_names[] = REGISTER_NAMES; |
| 1051 | #endif |
| 1052 | /* Print out the machine register regnum. If regnum is -1, |
| 1053 | print all registers (fpregs == 1) or all non-float registers |
| 1054 | (fpregs == 0). |
| 1055 | |
| 1056 | For most machines, having all_registers_info() print the |
| 1057 | register(s) one per line is good enough. If a different format |
| 1058 | is required, (eg, for MIPS or Pyramid 90x, which both have |
| 1059 | lots of regs), or there is an existing convention for showing |
| 1060 | all the registers, define the macro DO_REGISTERS_INFO(regnum, fp) |
| 1061 | to provide that format. */ |
| 1062 | |
| 1063 | #if !defined (DO_REGISTERS_INFO) |
| 1064 | |
| 1065 | #define DO_REGISTERS_INFO(regnum, fp) do_registers_info(regnum, fp) |
| 1066 | |
| 1067 | static void |
| 1068 | do_registers_info (regnum, fpregs) |
| 1069 | int regnum; |
| 1070 | int fpregs; |
| 1071 | { |
| 1072 | register int i; |
| 1073 | int numregs = ARCH_NUM_REGS; |
| 1074 | |
| 1075 | for (i = 0; i < numregs; i++) |
| 1076 | { |
| 1077 | char raw_buffer[MAX_REGISTER_RAW_SIZE]; |
| 1078 | char virtual_buffer[MAX_REGISTER_VIRTUAL_SIZE]; |
| 1079 | |
| 1080 | /* Decide between printing all regs, nonfloat regs, or specific reg. */ |
| 1081 | if (regnum == -1) { |
| 1082 | if (TYPE_CODE (REGISTER_VIRTUAL_TYPE (i)) == TYPE_CODE_FLT && !fpregs) |
| 1083 | continue; |
| 1084 | } else { |
| 1085 | if (i != regnum) |
| 1086 | continue; |
| 1087 | } |
| 1088 | |
| 1089 | /* If the register name is empty, it is undefined for this |
| 1090 | processor, so don't display anything. */ |
| 1091 | if (REGISTER_NAME (i) == NULL || *(REGISTER_NAME (i)) == '\0') |
| 1092 | continue; |
| 1093 | |
| 1094 | fputs_filtered (REGISTER_NAME (i), gdb_stdout); |
| 1095 | print_spaces_filtered (15 - strlen (REGISTER_NAME (i)), gdb_stdout); |
| 1096 | |
| 1097 | /* Get the data in raw format. */ |
| 1098 | if (read_relative_register_raw_bytes (i, raw_buffer)) |
| 1099 | { |
| 1100 | printf_filtered ("*value not available*\n"); |
| 1101 | continue; |
| 1102 | } |
| 1103 | |
| 1104 | /* Convert raw data to virtual format if necessary. */ |
| 1105 | if (REGISTER_CONVERTIBLE (i)) |
| 1106 | { |
| 1107 | REGISTER_CONVERT_TO_VIRTUAL (i, REGISTER_VIRTUAL_TYPE (i), |
| 1108 | raw_buffer, virtual_buffer); |
| 1109 | } |
| 1110 | else |
| 1111 | { |
| 1112 | memcpy (virtual_buffer, raw_buffer, |
| 1113 | REGISTER_VIRTUAL_SIZE (i)); |
| 1114 | } |
| 1115 | |
| 1116 | /* If virtual format is floating, print it that way, and in raw hex. */ |
| 1117 | if (TYPE_CODE (REGISTER_VIRTUAL_TYPE (i)) == TYPE_CODE_FLT) |
| 1118 | { |
| 1119 | register int j; |
| 1120 | |
| 1121 | #ifdef INVALID_FLOAT |
| 1122 | if (INVALID_FLOAT (virtual_buffer, REGISTER_VIRTUAL_SIZE (i))) |
| 1123 | printf_filtered ("<invalid float>"); |
| 1124 | else |
| 1125 | #endif |
| 1126 | val_print (REGISTER_VIRTUAL_TYPE (i), virtual_buffer, 0, 0, |
| 1127 | gdb_stdout, 0, 1, 0, Val_pretty_default); |
| 1128 | |
| 1129 | printf_filtered ("\t(raw 0x"); |
| 1130 | for (j = 0; j < REGISTER_RAW_SIZE (i); j++) |
| 1131 | { |
| 1132 | register int idx = TARGET_BYTE_ORDER == BIG_ENDIAN ? j |
| 1133 | : REGISTER_RAW_SIZE (i) - 1 - j; |
| 1134 | printf_filtered ("%02x", (unsigned char)raw_buffer[idx]); |
| 1135 | } |
| 1136 | printf_filtered (")"); |
| 1137 | } |
| 1138 | |
| 1139 | /* FIXME! val_print probably can handle all of these cases now... */ |
| 1140 | |
| 1141 | /* Else if virtual format is too long for printf, |
| 1142 | print in hex a byte at a time. */ |
| 1143 | else if (REGISTER_VIRTUAL_SIZE (i) > (int) sizeof (long)) |
| 1144 | { |
| 1145 | register int j; |
| 1146 | printf_filtered ("0x"); |
| 1147 | for (j = 0; j < REGISTER_VIRTUAL_SIZE (i); j++) |
| 1148 | printf_filtered ("%02x", (unsigned char)virtual_buffer[j]); |
| 1149 | } |
| 1150 | /* Else print as integer in hex and in decimal. */ |
| 1151 | else |
| 1152 | { |
| 1153 | val_print (REGISTER_VIRTUAL_TYPE (i), virtual_buffer, 0, 0, |
| 1154 | gdb_stdout, 'x', 1, 0, Val_pretty_default); |
| 1155 | printf_filtered ("\t"); |
| 1156 | val_print (REGISTER_VIRTUAL_TYPE (i), virtual_buffer, 0, 0, |
| 1157 | gdb_stdout, 0, 1, 0, Val_pretty_default); |
| 1158 | } |
| 1159 | |
| 1160 | /* The SPARC wants to print even-numbered float regs as doubles |
| 1161 | in addition to printing them as floats. */ |
| 1162 | #ifdef PRINT_REGISTER_HOOK |
| 1163 | PRINT_REGISTER_HOOK (i); |
| 1164 | #endif |
| 1165 | |
| 1166 | printf_filtered ("\n"); |
| 1167 | } |
| 1168 | } |
| 1169 | #endif /* no DO_REGISTERS_INFO. */ |
| 1170 | |
| 1171 | void |
| 1172 | registers_info (addr_exp, fpregs) |
| 1173 | char *addr_exp; |
| 1174 | int fpregs; |
| 1175 | { |
| 1176 | int regnum, numregs; |
| 1177 | register char *end; |
| 1178 | |
| 1179 | if (!target_has_registers) |
| 1180 | error ("The program has no registers now."); |
| 1181 | if (selected_frame == NULL) |
| 1182 | error ("No selected frame."); |
| 1183 | |
| 1184 | if (!addr_exp) |
| 1185 | { |
| 1186 | DO_REGISTERS_INFO(-1, fpregs); |
| 1187 | return; |
| 1188 | } |
| 1189 | |
| 1190 | do |
| 1191 | { |
| 1192 | if (addr_exp[0] == '$') |
| 1193 | addr_exp++; |
| 1194 | end = addr_exp; |
| 1195 | while (*end != '\0' && *end != ' ' && *end != '\t') |
| 1196 | ++end; |
| 1197 | numregs = ARCH_NUM_REGS; |
| 1198 | |
| 1199 | regnum = target_map_name_to_register (addr_exp, end - addr_exp); |
| 1200 | if (regnum >= 0) |
| 1201 | goto found; |
| 1202 | |
| 1203 | regnum = numregs; |
| 1204 | |
| 1205 | if (*addr_exp >= '0' && *addr_exp <= '9') |
| 1206 | regnum = atoi (addr_exp); /* Take a number */ |
| 1207 | if (regnum >= numregs) /* Bad name, or bad number */ |
| 1208 | error ("%.*s: invalid register", end - addr_exp, addr_exp); |
| 1209 | |
| 1210 | found: |
| 1211 | DO_REGISTERS_INFO(regnum, fpregs); |
| 1212 | |
| 1213 | addr_exp = end; |
| 1214 | while (*addr_exp == ' ' || *addr_exp == '\t') |
| 1215 | ++addr_exp; |
| 1216 | } while (*addr_exp != '\0'); |
| 1217 | } |
| 1218 | |
| 1219 | void |
| 1220 | all_registers_info (addr_exp, from_tty) |
| 1221 | char *addr_exp; |
| 1222 | int from_tty; |
| 1223 | { |
| 1224 | registers_info (addr_exp, 1); |
| 1225 | } |
| 1226 | |
| 1227 | void |
| 1228 | nofp_registers_info (addr_exp, from_tty) |
| 1229 | char *addr_exp; |
| 1230 | int from_tty; |
| 1231 | { |
| 1232 | registers_info (addr_exp, 0); |
| 1233 | } |
| 1234 | |
| 1235 | \f |
| 1236 | /* |
| 1237 | * TODO: |
| 1238 | * Should save/restore the tty state since it might be that the |
| 1239 | * program to be debugged was started on this tty and it wants |
| 1240 | * the tty in some state other than what we want. If it's running |
| 1241 | * on another terminal or without a terminal, then saving and |
| 1242 | * restoring the tty state is a harmless no-op. |
| 1243 | * This only needs to be done if we are attaching to a process. |
| 1244 | */ |
| 1245 | |
| 1246 | /* |
| 1247 | attach_command -- |
| 1248 | takes a program started up outside of gdb and ``attaches'' to it. |
| 1249 | This stops it cold in its tracks and allows us to start debugging it. |
| 1250 | and wait for the trace-trap that results from attaching. */ |
| 1251 | |
| 1252 | void |
| 1253 | attach_command (args, from_tty) |
| 1254 | char *args; |
| 1255 | int from_tty; |
| 1256 | { |
| 1257 | #ifdef SOLIB_ADD |
| 1258 | extern int auto_solib_add; |
| 1259 | #endif |
| 1260 | |
| 1261 | char * exec_file; |
| 1262 | char * full_exec_path = NULL; |
| 1263 | |
| 1264 | dont_repeat (); /* Not for the faint of heart */ |
| 1265 | |
| 1266 | if (target_has_execution) |
| 1267 | { |
| 1268 | if (query ("A program is being debugged already. Kill it? ")) |
| 1269 | target_kill (); |
| 1270 | else |
| 1271 | error ("Not killed."); |
| 1272 | } |
| 1273 | |
| 1274 | target_attach (args, from_tty); |
| 1275 | |
| 1276 | /* Set up the "saved terminal modes" of the inferior |
| 1277 | based on what modes we are starting it with. */ |
| 1278 | target_terminal_init (); |
| 1279 | |
| 1280 | /* Install inferior's terminal modes. */ |
| 1281 | target_terminal_inferior (); |
| 1282 | |
| 1283 | /* Set up execution context to know that we should return from |
| 1284 | wait_for_inferior as soon as the target reports a stop. */ |
| 1285 | init_wait_for_inferior (); |
| 1286 | clear_proceed_status (); |
| 1287 | stop_soon_quietly = 1; |
| 1288 | |
| 1289 | /* No traps are generated when attaching to inferior under Mach 3 |
| 1290 | or GNU hurd. */ |
| 1291 | #ifndef ATTACH_NO_WAIT |
| 1292 | wait_for_inferior (); |
| 1293 | #endif |
| 1294 | |
| 1295 | /* |
| 1296 | * If no exec file is yet known, try to determine it from the |
| 1297 | * process itself. |
| 1298 | */ |
| 1299 | exec_file = (char *) get_exec_file (0); |
| 1300 | if (! exec_file) { |
| 1301 | exec_file = target_pid_to_exec_file (inferior_pid); |
| 1302 | if (exec_file) { |
| 1303 | /* It's possible we don't have a full path, but rather just a |
| 1304 | filename. Some targets, such as HP-UX, don't provide the |
| 1305 | full path, sigh. |
| 1306 | |
| 1307 | Attempt to qualify the filename against the source path. |
| 1308 | (If that fails, we'll just fall back on the original |
| 1309 | filename. Not much more we can do...) |
| 1310 | */ |
| 1311 | if (!source_full_path_of (exec_file, &full_exec_path)) |
| 1312 | full_exec_path = savestring (exec_file, strlen (exec_file)); |
| 1313 | |
| 1314 | exec_file_attach (full_exec_path, from_tty); |
| 1315 | symbol_file_command (full_exec_path, from_tty); |
| 1316 | } |
| 1317 | } |
| 1318 | |
| 1319 | #ifdef SOLIB_ADD |
| 1320 | if (auto_solib_add) |
| 1321 | { |
| 1322 | /* Add shared library symbols from the newly attached process, if any. */ |
| 1323 | SOLIB_ADD ((char *)0, from_tty, ¤t_target); |
| 1324 | re_enable_breakpoints_in_shlibs (); |
| 1325 | } |
| 1326 | #endif |
| 1327 | |
| 1328 | /* Take any necessary post-attaching actions for this platform. |
| 1329 | */ |
| 1330 | target_post_attach (inferior_pid); |
| 1331 | |
| 1332 | normal_stop (); |
| 1333 | } |
| 1334 | |
| 1335 | /* |
| 1336 | * detach_command -- |
| 1337 | * takes a program previously attached to and detaches it. |
| 1338 | * The program resumes execution and will no longer stop |
| 1339 | * on signals, etc. We better not have left any breakpoints |
| 1340 | * in the program or it'll die when it hits one. For this |
| 1341 | * to work, it may be necessary for the process to have been |
| 1342 | * previously attached. It *might* work if the program was |
| 1343 | * started via the normal ptrace (PTRACE_TRACEME). |
| 1344 | */ |
| 1345 | |
| 1346 | static void |
| 1347 | detach_command (args, from_tty) |
| 1348 | char *args; |
| 1349 | int from_tty; |
| 1350 | { |
| 1351 | dont_repeat (); /* Not for the faint of heart */ |
| 1352 | target_detach (args, from_tty); |
| 1353 | #if defined(SOLIB_RESTART) |
| 1354 | SOLIB_RESTART (); |
| 1355 | #endif |
| 1356 | } |
| 1357 | |
| 1358 | /* ARGSUSED */ |
| 1359 | static void |
| 1360 | float_info (addr_exp, from_tty) |
| 1361 | char *addr_exp; |
| 1362 | int from_tty; |
| 1363 | { |
| 1364 | #ifdef FLOAT_INFO |
| 1365 | FLOAT_INFO; |
| 1366 | #else |
| 1367 | printf_filtered ("No floating point info available for this processor.\n"); |
| 1368 | #endif |
| 1369 | } |
| 1370 | \f |
| 1371 | /* ARGSUSED */ |
| 1372 | static void |
| 1373 | unset_command (args, from_tty) |
| 1374 | char *args; |
| 1375 | int from_tty; |
| 1376 | { |
| 1377 | printf_filtered ("\"unset\" must be followed by the name of "); |
| 1378 | printf_filtered ("an unset subcommand.\n"); |
| 1379 | help_list (unsetlist, "unset ", -1, gdb_stdout); |
| 1380 | } |
| 1381 | |
| 1382 | void |
| 1383 | _initialize_infcmd () |
| 1384 | { |
| 1385 | struct cmd_list_element *c; |
| 1386 | |
| 1387 | add_com ("tty", class_run, tty_command, |
| 1388 | "Set terminal for future runs of program being debugged."); |
| 1389 | |
| 1390 | add_show_from_set |
| 1391 | (add_set_cmd ("args", class_run, var_string_noescape, |
| 1392 | (char *)&inferior_args, |
| 1393 | "Set argument list to give program being debugged when it is started.\n\ |
| 1394 | Follow this command with any number of args, to be passed to the program.", |
| 1395 | &setlist), |
| 1396 | &showlist); |
| 1397 | |
| 1398 | c = add_cmd |
| 1399 | ("environment", no_class, environment_info, |
| 1400 | "The environment to give the program, or one variable's value.\n\ |
| 1401 | With an argument VAR, prints the value of environment variable VAR to\n\ |
| 1402 | give the program being debugged. With no arguments, prints the entire\n\ |
| 1403 | environment to be given to the program.", &showlist); |
| 1404 | c->completer = noop_completer; |
| 1405 | |
| 1406 | add_prefix_cmd ("unset", no_class, unset_command, |
| 1407 | "Complement to certain \"set\" commands", |
| 1408 | &unsetlist, "unset ", 0, &cmdlist); |
| 1409 | |
| 1410 | c = add_cmd ("environment", class_run, unset_environment_command, |
| 1411 | "Cancel environment variable VAR for the program.\n\ |
| 1412 | This does not affect the program until the next \"run\" command.", |
| 1413 | &unsetlist); |
| 1414 | c->completer = noop_completer; |
| 1415 | |
| 1416 | c = add_cmd ("environment", class_run, set_environment_command, |
| 1417 | "Set environment variable value to give the program.\n\ |
| 1418 | Arguments are VAR VALUE where VAR is variable name and VALUE is value.\n\ |
| 1419 | VALUES of environment variables are uninterpreted strings.\n\ |
| 1420 | This does not affect the program until the next \"run\" command.", |
| 1421 | &setlist); |
| 1422 | c->completer = noop_completer; |
| 1423 | |
| 1424 | add_com ("path", class_files, path_command, |
| 1425 | "Add directory DIR(s) to beginning of search path for object files.\n\ |
| 1426 | $cwd in the path means the current working directory.\n\ |
| 1427 | This path is equivalent to the $PATH shell variable. It is a list of\n\ |
| 1428 | directories, separated by colons. These directories are searched to find\n\ |
| 1429 | fully linked executable files and separately compiled object files as needed."); |
| 1430 | |
| 1431 | c = add_cmd ("paths", no_class, path_info, |
| 1432 | "Current search path for finding object files.\n\ |
| 1433 | $cwd in the path means the current working directory.\n\ |
| 1434 | This path is equivalent to the $PATH shell variable. It is a list of\n\ |
| 1435 | directories, separated by colons. These directories are searched to find\n\ |
| 1436 | fully linked executable files and separately compiled object files as needed.", |
| 1437 | &showlist); |
| 1438 | c->completer = noop_completer; |
| 1439 | |
| 1440 | add_com ("attach", class_run, attach_command, |
| 1441 | "Attach to a process or file outside of GDB.\n\ |
| 1442 | This command attaches to another target, of the same type as your last\n\ |
| 1443 | \"target\" command (\"info files\" will show your target stack).\n\ |
| 1444 | The command may take as argument a process id or a device file.\n\ |
| 1445 | For a process id, you must have permission to send the process a signal,\n\ |
| 1446 | and it must have the same effective uid as the debugger.\n\ |
| 1447 | When using \"attach\" with a process id, the debugger finds the\n\ |
| 1448 | program running in the process, looking first in the current working\n\ |
| 1449 | directory, or (if not found there) using the source file search path\n\ |
| 1450 | (see the \"directory\" command). You can also use the \"file\" command\n\ |
| 1451 | to specify the program, and to load its symbol table."); |
| 1452 | |
| 1453 | add_com ("detach", class_run, detach_command, |
| 1454 | "Detach a process or file previously attached.\n\ |
| 1455 | If a process, it is no longer traced, and it continues its execution. If\n\ |
| 1456 | you were debugging a file, the file is closed and gdb no longer accesses it."); |
| 1457 | |
| 1458 | add_com ("signal", class_run, signal_command, |
| 1459 | "Continue program giving it signal specified by the argument.\n\ |
| 1460 | An argument of \"0\" means continue program without giving it a signal."); |
| 1461 | |
| 1462 | add_com ("stepi", class_run, stepi_command, |
| 1463 | "Step one instruction exactly.\n\ |
| 1464 | Argument N means do this N times (or till program stops for another reason)."); |
| 1465 | add_com_alias ("si", "stepi", class_alias, 0); |
| 1466 | |
| 1467 | add_com ("nexti", class_run, nexti_command, |
| 1468 | "Step one instruction, but proceed through subroutine calls.\n\ |
| 1469 | Argument N means do this N times (or till program stops for another reason)."); |
| 1470 | add_com_alias ("ni", "nexti", class_alias, 0); |
| 1471 | |
| 1472 | add_com ("finish", class_run, finish_command, |
| 1473 | "Execute until selected stack frame returns.\n\ |
| 1474 | Upon return, the value returned is printed and put in the value history."); |
| 1475 | |
| 1476 | add_com ("next", class_run, next_command, |
| 1477 | "Step program, proceeding through subroutine calls.\n\ |
| 1478 | Like the \"step\" command as long as subroutine calls do not happen;\n\ |
| 1479 | when they do, the call is treated as one instruction.\n\ |
| 1480 | Argument N means do this N times (or till program stops for another reason)."); |
| 1481 | add_com_alias ("n", "next", class_run, 1); |
| 1482 | if (xdb_commands) |
| 1483 | add_com_alias("S", "next", class_run, 1); |
| 1484 | |
| 1485 | add_com ("step", class_run, step_command, |
| 1486 | "Step program until it reaches a different source line.\n\ |
| 1487 | Argument N means do this N times (or till program stops for another reason)."); |
| 1488 | add_com_alias ("s", "step", class_run, 1); |
| 1489 | |
| 1490 | add_com ("until", class_run, until_command, |
| 1491 | "Execute until the program reaches a source line greater than the current\n\ |
| 1492 | or a specified line or address or function (same args as break command).\n\ |
| 1493 | Execution will also stop upon exit from the current stack frame."); |
| 1494 | add_com_alias ("u", "until", class_run, 1); |
| 1495 | |
| 1496 | add_com ("jump", class_run, jump_command, |
| 1497 | "Continue program being debugged at specified line or address.\n\ |
| 1498 | Give as argument either LINENUM or *ADDR, where ADDR is an expression\n\ |
| 1499 | for an address to start at."); |
| 1500 | |
| 1501 | if (xdb_commands) |
| 1502 | add_com ("go", class_run, go_command, |
| 1503 | "Usage: go <location>\n\ |
| 1504 | Continue program being debugged, stopping at specified line or \n\ |
| 1505 | address.\n\ |
| 1506 | Give as argument either LINENUM or *ADDR, where ADDR is an \n\ |
| 1507 | expression for an address to start at.\n\ |
| 1508 | This command is a combination of tbreak and jump."); |
| 1509 | |
| 1510 | if (xdb_commands) |
| 1511 | add_com_alias("g", "go", class_run, 1); |
| 1512 | |
| 1513 | add_com ("continue", class_run, continue_command, |
| 1514 | "Continue program being debugged, after signal or breakpoint.\n\ |
| 1515 | If proceeding from breakpoint, a number N may be used as an argument,\n\ |
| 1516 | which means to set the ignore count of that breakpoint to N - 1 (so that\n\ |
| 1517 | the breakpoint won't break until the Nth time it is reached)."); |
| 1518 | add_com_alias ("c", "cont", class_run, 1); |
| 1519 | add_com_alias ("fg", "cont", class_run, 1); |
| 1520 | |
| 1521 | add_com ("run", class_run, run_command, |
| 1522 | "Start debugged program. You may specify arguments to give it.\n\ |
| 1523 | Args may include \"*\", or \"[...]\"; they are expanded using \"sh\".\n\ |
| 1524 | Input and output redirection with \">\", \"<\", or \">>\" are also allowed.\n\n\ |
| 1525 | With no arguments, uses arguments last specified (with \"run\" or \"set args\").\n\ |
| 1526 | To cancel previous arguments and run with no arguments,\n\ |
| 1527 | use \"set args\" without arguments."); |
| 1528 | add_com_alias ("r", "run", class_run, 1); |
| 1529 | if (xdb_commands) |
| 1530 | add_com ("R", class_run, run_no_args_command, |
| 1531 | "Start debugged program with no arguments."); |
| 1532 | |
| 1533 | add_info ("registers", nofp_registers_info, |
| 1534 | "List of integer registers and their contents, for selected stack frame.\n\ |
| 1535 | Register name as argument means describe only that register."); |
| 1536 | |
| 1537 | if (xdb_commands) |
| 1538 | add_com("lr", class_info, nofp_registers_info, |
| 1539 | "List of integer registers and their contents, for selected stack frame.\n\ |
| 1540 | Register name as argument means describe only that register."); |
| 1541 | add_info ("all-registers", all_registers_info, |
| 1542 | "List of all registers and their contents, for selected stack frame.\n\ |
| 1543 | Register name as argument means describe only that register."); |
| 1544 | |
| 1545 | add_info ("program", program_info, |
| 1546 | "Execution status of the program."); |
| 1547 | |
| 1548 | add_info ("float", float_info, |
| 1549 | "Print the status of the floating point unit\n"); |
| 1550 | |
| 1551 | inferior_args = savestring ("", 1); /* Initially no args */ |
| 1552 | inferior_environ = make_environ (); |
| 1553 | init_environ (inferior_environ); |
| 1554 | } |