Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(538)

Side by Side Diff: gdb/remote-sim.c

Issue 124383005: GDB 7.6.50 (Closed) Base URL: http://git.chromium.org/native_client/nacl-gdb.git@upstream
Patch Set: Created 6 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « gdb/remote-notif.c ('k') | gdb/reply_mig_hack.awk » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* Generic remote debugging interface for simulators. 1 /* Generic remote debugging interface for simulators.
2 2
3 Copyright (C) 1993-2002, 2004-2012 Free Software Foundation, Inc. 3 Copyright (C) 1993-2013 Free Software Foundation, Inc.
4 4
5 Contributed by Cygnus Support. 5 Contributed by Cygnus Support.
6 Steve Chamberlain (sac@cygnus.com). 6 Steve Chamberlain (sac@cygnus.com).
7 7
8 This file is part of GDB. 8 This file is part of GDB.
9 9
10 This program is free software; you can redistribute it and/or modify 10 This program is free software; you can redistribute it and/or modify
11 it under the terms of the GNU General Public License as published by 11 it under the terms of the GNU General Public License as published by
12 the Free Software Foundation; either version 3 of the License, or 12 the Free Software Foundation; either version 3 of the License, or
13 (at your option) any later version. 13 (at your option) any later version.
14 14
15 This program is distributed in the hope that it will be useful, 15 This program is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of 16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License for more details. 18 GNU General Public License for more details.
19 19
20 You should have received a copy of the GNU General Public License 20 You should have received a copy of the GNU General Public License
21 along with this program. If not, see <http://www.gnu.org/licenses/>. */ 21 along with this program. If not, see <http://www.gnu.org/licenses/>. */
22 22
23 #include "defs.h" 23 #include "defs.h"
24 #include "inferior.h" 24 #include "inferior.h"
25 #include "value.h" 25 #include "value.h"
26 #include "gdb_string.h" 26 #include <string.h>
27 #include <ctype.h> 27 #include <ctype.h>
28 #include <fcntl.h> 28 #include <fcntl.h>
29 #include <signal.h> 29 #include <signal.h>
30 #include <setjmp.h> 30 #include <setjmp.h>
31 #include <errno.h> 31 #include <errno.h>
32 #include "terminal.h" 32 #include "terminal.h"
33 #include "target.h" 33 #include "target.h"
34 #include "gdbcore.h" 34 #include "gdbcore.h"
35 #include "gdb/callback.h" 35 #include "gdb/callback.h"
36 #include "gdb/remote-sim.h" 36 #include "gdb/remote-sim.h"
37 #include "command.h" 37 #include "command.h"
38 #include "regcache.h" 38 #include "regcache.h"
39 #include "gdb_assert.h" 39 #include "gdb_assert.h"
40 #include "sim-regno.h" 40 #include "sim-regno.h"
41 #include "arch-utils.h" 41 #include "arch-utils.h"
42 #include "readline/readline.h" 42 #include "readline/readline.h"
43 #include "gdbthread.h" 43 #include "gdbthread.h"
44 44
45 /* Prototypes */ 45 /* Prototypes */
46 46
47 extern void _initialize_remote_sim (void); 47 extern void _initialize_remote_sim (void);
48 48
49 static void dump_mem (char *buf, int len);
50
51 static void init_callbacks (void); 49 static void init_callbacks (void);
52 50
53 static void end_callbacks (void); 51 static void end_callbacks (void);
54 52
55 static int gdb_os_write_stdout (host_callback *, const char *, int); 53 static int gdb_os_write_stdout (host_callback *, const char *, int);
56 54
57 static void gdb_os_flush_stdout (host_callback *); 55 static void gdb_os_flush_stdout (host_callback *);
58 56
59 static int gdb_os_write_stderr (host_callback *, const char *, int); 57 static int gdb_os_write_stderr (host_callback *, const char *, int);
60 58
(...skipping 10 matching lines...) Expand all
71 69
72 static void gdb_os_error (host_callback *, const char *, ...) 70 static void gdb_os_error (host_callback *, const char *, ...)
73 ATTRIBUTE_NORETURN; 71 ATTRIBUTE_NORETURN;
74 72
75 static void gdbsim_kill (struct target_ops *); 73 static void gdbsim_kill (struct target_ops *);
76 74
77 static void gdbsim_load (char *prog, int fromtty); 75 static void gdbsim_load (char *prog, int fromtty);
78 76
79 static void gdbsim_open (char *args, int from_tty); 77 static void gdbsim_open (char *args, int from_tty);
80 78
81 static void gdbsim_close (int quitting); 79 static void gdbsim_close (void);
82 80
83 static void gdbsim_detach (struct target_ops *ops, char *args, int from_tty); 81 static void gdbsim_detach (struct target_ops *ops, const char *args,
82 » » » int from_tty);
84 83
85 static void gdbsim_prepare_to_store (struct regcache *regcache); 84 static void gdbsim_prepare_to_store (struct regcache *regcache);
86 85
87 static void gdbsim_files_info (struct target_ops *target); 86 static void gdbsim_files_info (struct target_ops *target);
88 87
89 static void gdbsim_mourn_inferior (struct target_ops *target); 88 static void gdbsim_mourn_inferior (struct target_ops *target);
90 89
91 static void gdbsim_stop (ptid_t ptid); 90 static void gdbsim_stop (ptid_t ptid);
92 91
93 void simulator_command (char *args, int from_tty); 92 void simulator_command (char *args, int from_tty);
(...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after
264 if (sim_data->gdbsim_desc) 263 if (sim_data->gdbsim_desc)
265 { 264 {
266 sim_close (sim_data->gdbsim_desc, 0); 265 sim_close (sim_data->gdbsim_desc, 0);
267 sim_data->gdbsim_desc = NULL; 266 sim_data->gdbsim_desc = NULL;
268 } 267 }
269 xfree (sim_data); 268 xfree (sim_data);
270 } 269 }
271 } 270 }
272 271
273 static void 272 static void
274 dump_mem (char *buf, int len) 273 dump_mem (const gdb_byte *buf, int len)
275 { 274 {
276 if (len <= 8) 275 fputs_unfiltered ("\t", gdb_stdlog);
276
277 if (len == 8 || len == 4)
277 { 278 {
278 if (len == 8 || len == 4) 279 uint32_t l[2];
279 » {
280 » long l[2];
281 280
282 » memcpy (l, buf, len); 281 memcpy (l, buf, len);
283 » printf_filtered ("\t0x%lx", l[0]); 282 fprintf_unfiltered (gdb_stdlog, "0x%08x", l[0]);
284 » if (len == 8) 283 if (len == 8)
285 » printf_filtered (" 0x%lx", l[1]); 284 » fprintf_unfiltered (gdb_stdlog, " 0x%08x", l[1]);
286 » printf_filtered ("\n"); 285 }
287 » } 286 else
288 else 287 {
289 » { 288 int i;
290 » int i;
291 289
292 » printf_filtered ("\t"); 290 for (i = 0; i < len; i++)
293 » for (i = 0; i < len; i++) 291 » fprintf_unfiltered (gdb_stdlog, "0x%02x ", buf[i]);
294 » printf_filtered ("0x%x ", buf[i]);
295 » printf_filtered ("\n");
296 » }
297 } 292 }
293
294 fputs_unfiltered ("\n", gdb_stdlog);
298 } 295 }
299 296
300 /* Initialize gdb_callback. */ 297 /* Initialize gdb_callback. */
301 298
302 static void 299 static void
303 init_callbacks (void) 300 init_callbacks (void)
304 { 301 {
305 if (!callbacks_initialized) 302 if (!callbacks_initialized)
306 { 303 {
307 gdb_callback = default_callback; 304 gdb_callback = default_callback;
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after
441 } 438 }
442 439
443 switch (gdbarch_register_sim_regno (gdbarch, regno)) 440 switch (gdbarch_register_sim_regno (gdbarch, regno))
444 { 441 {
445 case LEGACY_SIM_REGNO_IGNORE: 442 case LEGACY_SIM_REGNO_IGNORE:
446 break; 443 break;
447 case SIM_REGNO_DOES_NOT_EXIST: 444 case SIM_REGNO_DOES_NOT_EXIST:
448 { 445 {
449 /* For moment treat a `does not exist' register the same way 446 /* For moment treat a `does not exist' register the same way
450 as an ``unavailable'' register. */ 447 as an ``unavailable'' register. */
451 » char buf[MAX_REGISTER_SIZE]; 448 » gdb_byte buf[MAX_REGISTER_SIZE];
452 int nr_bytes; 449 int nr_bytes;
453 450
454 memset (buf, 0, MAX_REGISTER_SIZE); 451 memset (buf, 0, MAX_REGISTER_SIZE);
455 regcache_raw_supply (regcache, regno, buf); 452 regcache_raw_supply (regcache, regno, buf);
456 break; 453 break;
457 } 454 }
458 455
459 default: 456 default:
460 { 457 {
461 static int warn_user = 1; 458 static int warn_user = 1;
462 » char buf[MAX_REGISTER_SIZE]; 459 » gdb_byte buf[MAX_REGISTER_SIZE];
463 int nr_bytes; 460 int nr_bytes;
464 461
465 gdb_assert (regno >= 0 && regno < gdbarch_num_regs (gdbarch)); 462 gdb_assert (regno >= 0 && regno < gdbarch_num_regs (gdbarch));
466 memset (buf, 0, MAX_REGISTER_SIZE); 463 memset (buf, 0, MAX_REGISTER_SIZE);
467 nr_bytes = sim_fetch_register (sim_data->gdbsim_desc, 464 nr_bytes = sim_fetch_register (sim_data->gdbsim_desc,
468 gdbarch_register_sim_regno 465 gdbarch_register_sim_regno
469 (gdbarch, regno), 466 (gdbarch, regno),
470 buf, 467 buf,
471 register_size (gdbarch, regno)); 468 register_size (gdbarch, regno));
472 if (nr_bytes > 0 469 if (nr_bytes > 0
(...skipping 10 matching lines...) Expand all
483 warn_user = 0; 480 warn_user = 0;
484 } 481 }
485 /* FIXME: cagney/2002-05-27: Should check `nr_bytes == 0' 482 /* FIXME: cagney/2002-05-27: Should check `nr_bytes == 0'
486 indicating that GDB and the SIM have different ideas about 483 indicating that GDB and the SIM have different ideas about
487 which registers are fetchable. */ 484 which registers are fetchable. */
488 /* Else if (nr_bytes < 0): an old simulator, that doesn't 485 /* Else if (nr_bytes < 0): an old simulator, that doesn't
489 think to return the register size. Just assume all is ok. */ 486 think to return the register size. Just assume all is ok. */
490 regcache_raw_supply (regcache, regno, buf); 487 regcache_raw_supply (regcache, regno, buf);
491 if (remote_debug) 488 if (remote_debug)
492 { 489 {
493 » printf_filtered ("gdbsim_fetch_register: %d", regno); 490 » fprintf_unfiltered (gdb_stdlog,
491 » » » » "gdbsim_fetch_register: %d", regno);
494 /* FIXME: We could print something more intelligible. */ 492 /* FIXME: We could print something more intelligible. */
495 dump_mem (buf, register_size (gdbarch, regno)); 493 dump_mem (buf, register_size (gdbarch, regno));
496 } 494 }
497 break; 495 break;
498 } 496 }
499 } 497 }
500 } 498 }
501 499
502 500
503 static void 501 static void
504 gdbsim_store_register (struct target_ops *ops, 502 gdbsim_store_register (struct target_ops *ops,
505 struct regcache *regcache, int regno) 503 struct regcache *regcache, int regno)
506 { 504 {
507 struct gdbarch *gdbarch = get_regcache_arch (regcache); 505 struct gdbarch *gdbarch = get_regcache_arch (regcache);
508 struct sim_inferior_data *sim_data 506 struct sim_inferior_data *sim_data
509 = get_sim_inferior_data (current_inferior (), SIM_INSTANCE_NEEDED); 507 = get_sim_inferior_data (current_inferior (), SIM_INSTANCE_NEEDED);
510 508
511 if (regno == -1) 509 if (regno == -1)
512 { 510 {
513 for (regno = 0; regno < gdbarch_num_regs (gdbarch); regno++) 511 for (regno = 0; regno < gdbarch_num_regs (gdbarch); regno++)
514 gdbsim_store_register (ops, regcache, regno); 512 gdbsim_store_register (ops, regcache, regno);
515 return; 513 return;
516 } 514 }
517 else if (gdbarch_register_sim_regno (gdbarch, regno) >= 0) 515 else if (gdbarch_register_sim_regno (gdbarch, regno) >= 0)
518 { 516 {
519 char tmp[MAX_REGISTER_SIZE]; 517 gdb_byte tmp[MAX_REGISTER_SIZE];
520 int nr_bytes; 518 int nr_bytes;
521 519
522 regcache_cooked_read (regcache, regno, tmp); 520 regcache_cooked_read (regcache, regno, tmp);
523 nr_bytes = sim_store_register (sim_data->gdbsim_desc, 521 nr_bytes = sim_store_register (sim_data->gdbsim_desc,
524 gdbarch_register_sim_regno 522 gdbarch_register_sim_regno
525 (gdbarch, regno), 523 (gdbarch, regno),
526 tmp, register_size (gdbarch, regno)); 524 tmp, register_size (gdbarch, regno));
527 if (nr_bytes > 0 && nr_bytes != register_size (gdbarch, regno)) 525 if (nr_bytes > 0 && nr_bytes != register_size (gdbarch, regno))
528 internal_error (__FILE__, __LINE__, 526 internal_error (__FILE__, __LINE__,
529 _("Register size different to expected")); 527 _("Register size different to expected"));
530 if (nr_bytes < 0) 528 if (nr_bytes < 0)
531 internal_error (__FILE__, __LINE__, 529 internal_error (__FILE__, __LINE__,
532 _("Register %d not updated"), regno); 530 _("Register %d not updated"), regno);
533 if (nr_bytes == 0) 531 if (nr_bytes == 0)
534 warning (_("Register %s not updated"), 532 warning (_("Register %s not updated"),
535 gdbarch_register_name (gdbarch, regno)); 533 gdbarch_register_name (gdbarch, regno));
536 534
537 if (remote_debug) 535 if (remote_debug)
538 { 536 {
539 » printf_filtered ("gdbsim_store_register: %d", regno); 537 » fprintf_unfiltered (gdb_stdlog, "gdbsim_store_register: %d", regno);
540 /* FIXME: We could print something more intelligible. */ 538 /* FIXME: We could print something more intelligible. */
541 dump_mem (tmp, register_size (gdbarch, regno)); 539 dump_mem (tmp, register_size (gdbarch, regno));
542 } 540 }
543 } 541 }
544 } 542 }
545 543
546 /* Kill the running program. This may involve closing any open files 544 /* Kill the running program. This may involve closing any open files
547 and releasing other resources acquired by the simulated program. */ 545 and releasing other resources acquired by the simulated program. */
548 546
549 static void 547 static void
550 gdbsim_kill (struct target_ops *ops) 548 gdbsim_kill (struct target_ops *ops)
551 { 549 {
552 if (remote_debug) 550 if (remote_debug)
553 printf_filtered ("gdbsim_kill\n"); 551 fprintf_unfiltered (gdb_stdlog, "gdbsim_kill\n");
554 552
555 /* There is no need to `kill' running simulator - the simulator is 553 /* There is no need to `kill' running simulator - the simulator is
556 not running. Mourning it is enough. */ 554 not running. Mourning it is enough. */
557 target_mourn_inferior (); 555 target_mourn_inferior ();
558 } 556 }
559 557
560 /* Load an executable file into the target process. This is expected to 558 /* Load an executable file into the target process. This is expected to
561 not only bring new code into the target process, but also to update 559 not only bring new code into the target process, but also to update
562 GDB's symbol tables to match. */ 560 GDB's symbol tables to match. */
563 561
(...skipping 10 matching lines...) Expand all
574 572
575 argv = gdb_buildargv (args); 573 argv = gdb_buildargv (args);
576 make_cleanup_freeargv (argv); 574 make_cleanup_freeargv (argv);
577 575
578 prog = tilde_expand (argv[0]); 576 prog = tilde_expand (argv[0]);
579 577
580 if (argv[1] != NULL) 578 if (argv[1] != NULL)
581 error (_("GDB sim does not yet support a load offset.")); 579 error (_("GDB sim does not yet support a load offset."));
582 580
583 if (remote_debug) 581 if (remote_debug)
584 printf_filtered ("gdbsim_load: prog \"%s\"\n", prog); 582 fprintf_unfiltered (gdb_stdlog, "gdbsim_load: prog \"%s\"\n", prog);
585 583
586 /* FIXME: We will print two messages on error. 584 /* FIXME: We will print two messages on error.
587 Need error to either not print anything if passed NULL or need 585 Need error to either not print anything if passed NULL or need
588 another routine that doesn't take any arguments. */ 586 another routine that doesn't take any arguments. */
589 if (sim_load (sim_data->gdbsim_desc, prog, NULL, fromtty) == SIM_RC_FAIL) 587 if (sim_load (sim_data->gdbsim_desc, prog, NULL, fromtty) == SIM_RC_FAIL)
590 error (_("unable to load program")); 588 error (_("unable to load program"));
591 589
592 /* FIXME: If a load command should reset the targets registers then 590 /* FIXME: If a load command should reset the targets registers then
593 a call to sim_create_inferior() should go here. */ 591 a call to sim_create_inferior() should go here. */
594 592
(...skipping 17 matching lines...) Expand all
612 = get_sim_inferior_data (current_inferior (), SIM_INSTANCE_NEEDED); 610 = get_sim_inferior_data (current_inferior (), SIM_INSTANCE_NEEDED);
613 int len; 611 int len;
614 char *arg_buf, **argv; 612 char *arg_buf, **argv;
615 613
616 if (exec_file == 0 || exec_bfd == 0) 614 if (exec_file == 0 || exec_bfd == 0)
617 warning (_("No executable file specified.")); 615 warning (_("No executable file specified."));
618 if (!sim_data->program_loaded) 616 if (!sim_data->program_loaded)
619 warning (_("No program loaded.")); 617 warning (_("No program loaded."));
620 618
621 if (remote_debug) 619 if (remote_debug)
622 printf_filtered ("gdbsim_create_inferior: exec_file \"%s\", args \"%s\"\n", 620 fprintf_unfiltered (gdb_stdlog,
623 » » (exec_file ? exec_file : "(NULL)"), 621 » » » "gdbsim_create_inferior: exec_file \"%s\", args \"%s\"\n ",
624 » » args); 622 » » » (exec_file ? exec_file : "(NULL)"),
623 » » » args);
625 624
626 if (ptid_equal (inferior_ptid, sim_data->remote_sim_ptid)) 625 if (ptid_equal (inferior_ptid, sim_data->remote_sim_ptid))
627 gdbsim_kill (target); 626 gdbsim_kill (target);
628 remove_breakpoints (); 627 remove_breakpoints ();
629 init_wait_for_inferior (); 628 init_wait_for_inferior ();
630 629
631 if (exec_file != NULL) 630 if (exec_file != NULL)
632 { 631 {
633 len = strlen (exec_file) + 1 + strlen (args) + 1 + /*slop */ 10; 632 len = strlen (exec_file) + 1 + strlen (args) + 1 + /*slop */ 10;
634 arg_buf = (char *) alloca (len); 633 arg_buf = (char *) alloca (len);
635 arg_buf[0] = '\0'; 634 arg_buf[0] = '\0';
636 strcat (arg_buf, exec_file); 635 strcat (arg_buf, exec_file);
637 strcat (arg_buf, " "); 636 strcat (arg_buf, " ");
638 strcat (arg_buf, args); 637 strcat (arg_buf, args);
639 argv = gdb_buildargv (arg_buf); 638 argv = gdb_buildargv (arg_buf);
640 make_cleanup_freeargv (argv); 639 make_cleanup_freeargv (argv);
641 } 640 }
642 else 641 else
643 argv = NULL; 642 argv = NULL;
644 643
644 if (!have_inferiors ())
645 init_thread_list ();
646
645 if (sim_create_inferior (sim_data->gdbsim_desc, exec_bfd, argv, env) 647 if (sim_create_inferior (sim_data->gdbsim_desc, exec_bfd, argv, env)
646 != SIM_RC_OK) 648 != SIM_RC_OK)
647 error (_("Unable to create sim inferior.")); 649 error (_("Unable to create sim inferior."));
648 650
649 inferior_ptid = sim_data->remote_sim_ptid; 651 inferior_ptid = sim_data->remote_sim_ptid;
650 inferior_appeared (current_inferior (), ptid_get_pid (inferior_ptid)); 652 inferior_appeared (current_inferior (), ptid_get_pid (inferior_ptid));
651 add_thread_silent (inferior_ptid); 653 add_thread_silent (inferior_ptid);
652 654
653 insert_breakpoints (); /* Needed to get correct instruction 655 insert_breakpoints (); /* Needed to get correct instruction
654 in cache. */ 656 in cache. */
655 657
656 clear_proceed_status (); 658 clear_proceed_status ();
657 } 659 }
658 660
659 /* The open routine takes the rest of the parameters from the command, 661 /* The open routine takes the rest of the parameters from the command,
660 and (if successful) pushes a new target onto the stack. 662 and (if successful) pushes a new target onto the stack.
661 Targets should supply this routine, if only to provide an error message. */ 663 Targets should supply this routine, if only to provide an error message. */
662 /* Called when selecting the simulator. E.g. (gdb) target sim name. */ 664 /* Called when selecting the simulator. E.g. (gdb) target sim name. */
663 665
664 static void 666 static void
665 gdbsim_open (char *args, int from_tty) 667 gdbsim_open (char *args, int from_tty)
666 { 668 {
667 int len; 669 int len;
668 char *arg_buf; 670 char *arg_buf;
669 struct sim_inferior_data *sim_data; 671 struct sim_inferior_data *sim_data;
670 SIM_DESC gdbsim_desc; 672 SIM_DESC gdbsim_desc;
671 673
672 if (remote_debug) 674 if (remote_debug)
673 printf_filtered ("gdbsim_open: args \"%s\"\n", args ? args : "(null)"); 675 fprintf_unfiltered (gdb_stdlog,
676 » » » "gdbsim_open: args \"%s\"\n", args ? args : "(null)");
674 677
675 /* Ensure that the sim target is not on the target stack. This is 678 /* Ensure that the sim target is not on the target stack. This is
676 necessary, because if it is on the target stack, the call to 679 necessary, because if it is on the target stack, the call to
677 push_target below will invoke sim_close(), thus freeing various 680 push_target below will invoke sim_close(), thus freeing various
678 state (including a sim instance) that we allocate prior to 681 state (including a sim instance) that we allocate prior to
679 invoking push_target(). We want to delay the push_target() 682 invoking push_target(). We want to delay the push_target()
680 operation until after we complete those operations which could 683 operation until after we complete those operations which could
681 error out. */ 684 error out. */
682 if (gdbsim_is_open) 685 if (gdbsim_is_open)
683 unpush_target (&gdbsim_ops); 686 unpush_target (&gdbsim_ops);
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
774 if (find_inferior_pid (ptid_get_pid (ptid)) != NULL) 777 if (find_inferior_pid (ptid_get_pid (ptid)) != NULL)
775 { 778 {
776 switch_to_thread (ptid); 779 switch_to_thread (ptid);
777 generic_mourn_inferior (); 780 generic_mourn_inferior ();
778 } 781 }
779 } 782 }
780 783
781 return 0; 784 return 0;
782 } 785 }
783 786
784 /* Does whatever cleanup is required for a target that we are no longer
785 going to be calling. Argument says whether we are quitting gdb and
786 should not get hung in case of errors, or whether we want a clean
787 termination even if it takes a while. This routine is automatically
788 always called just before a routine is popped off the target stack.
789 Closing file descriptors and freeing memory are typical things it should
790 do. */
791 /* Close out all files and local state before this target loses control. */ 787 /* Close out all files and local state before this target loses control. */
792 788
793 static void 789 static void
794 gdbsim_close (int quitting) 790 gdbsim_close (void)
795 { 791 {
796 struct sim_inferior_data *sim_data 792 struct sim_inferior_data *sim_data
797 = get_sim_inferior_data (current_inferior (), SIM_INSTANCE_NOT_NEEDED); 793 = get_sim_inferior_data (current_inferior (), SIM_INSTANCE_NOT_NEEDED);
798 794
799 if (remote_debug) 795 if (remote_debug)
800 printf_filtered ("gdbsim_close: quitting %d\n", quitting); 796 fprintf_unfiltered (gdb_stdlog, "gdbsim_close\n");
801 797
802 iterate_over_inferiors (gdbsim_close_inferior, NULL); 798 iterate_over_inferiors (gdbsim_close_inferior, NULL);
803 799
804 if (sim_argv != NULL) 800 if (sim_argv != NULL)
805 { 801 {
806 freeargv (sim_argv); 802 freeargv (sim_argv);
807 sim_argv = NULL; 803 sim_argv = NULL;
808 } 804 }
809 805
810 end_callbacks (); 806 end_callbacks ();
811 807
812 gdbsim_is_open = 0; 808 gdbsim_is_open = 0;
813 } 809 }
814 810
815 /* Takes a program previously attached to and detaches it. 811 /* Takes a program previously attached to and detaches it.
816 The program may resume execution (some targets do, some don't) and will 812 The program may resume execution (some targets do, some don't) and will
817 no longer stop on signals, etc. We better not have left any breakpoints 813 no longer stop on signals, etc. We better not have left any breakpoints
818 in the program or it'll die when it hits one. ARGS is arguments 814 in the program or it'll die when it hits one. ARGS is arguments
819 typed by the user (e.g. a signal to send the process). FROM_TTY 815 typed by the user (e.g. a signal to send the process). FROM_TTY
820 says whether to be verbose or not. */ 816 says whether to be verbose or not. */
821 /* Terminate the open connection to the remote debugger. 817 /* Terminate the open connection to the remote debugger.
822 Use this when you want to detach and do something else with your gdb. */ 818 Use this when you want to detach and do something else with your gdb. */
823 819
824 static void 820 static void
825 gdbsim_detach (struct target_ops *ops, char *args, int from_tty) 821 gdbsim_detach (struct target_ops *ops, const char *args, int from_tty)
826 { 822 {
827 if (remote_debug) 823 if (remote_debug)
828 printf_filtered ("gdbsim_detach: args \"%s\"\n", args); 824 fprintf_unfiltered (gdb_stdlog, "gdbsim_detach: args \"%s\"\n", args);
829 825
830 pop_target ();» » /* calls gdbsim_close to do the real work */ 826 unpush_target (ops);» » /* calls gdbsim_close to do the real work */
831 if (from_tty) 827 if (from_tty)
832 printf_filtered ("Ending simulator %s debugging\n", target_shortname); 828 printf_filtered ("Ending simulator %s debugging\n", target_shortname);
833 } 829 }
834 830
835 /* Resume execution of the target process. STEP says whether to single-step 831 /* Resume execution of the target process. STEP says whether to single-step
836 or to run free; SIGGNAL is the signal value (e.g. SIGINT) to be given 832 or to run free; SIGGNAL is the signal value (e.g. SIGINT) to be given
837 to the target, or zero for no signal. */ 833 to the target, or zero for no signal. */
838 834
839 struct resume_data 835 struct resume_data
840 { 836 {
841 enum gdb_signal siggnal; 837 enum gdb_signal siggnal;
842 int step; 838 int step;
843 }; 839 };
844 840
845 static int 841 static int
846 gdbsim_resume_inferior (struct inferior *inf, void *arg) 842 gdbsim_resume_inferior (struct inferior *inf, void *arg)
847 { 843 {
848 struct sim_inferior_data *sim_data 844 struct sim_inferior_data *sim_data
849 = get_sim_inferior_data (inf, SIM_INSTANCE_NOT_NEEDED); 845 = get_sim_inferior_data (inf, SIM_INSTANCE_NOT_NEEDED);
850 struct resume_data *rd = arg; 846 struct resume_data *rd = arg;
851 847
852 if (sim_data) 848 if (sim_data)
853 { 849 {
854 sim_data->resume_siggnal = rd->siggnal; 850 sim_data->resume_siggnal = rd->siggnal;
855 sim_data->resume_step = rd->step; 851 sim_data->resume_step = rd->step;
856 852
857 if (remote_debug) 853 if (remote_debug)
858 » printf_filtered (_("gdbsim_resume: pid %d, step %d, signal %d\n"), 854 » fprintf_unfiltered (gdb_stdlog,
859 » inf->pid, rd->step, rd->siggnal); 855 » » » _("gdbsim_resume: pid %d, step %d, signal %d\n"),
856 » » » inf->pid, rd->step, rd->siggnal);
860 } 857 }
861 858
862 /* When called from iterate_over_inferiors, a zero return causes the 859 /* When called from iterate_over_inferiors, a zero return causes the
863 iteration process to proceed until there are no more inferiors to 860 iteration process to proceed until there are no more inferiors to
864 consider. */ 861 consider. */
865 return 0; 862 return 0;
866 } 863 }
867 864
868 static void 865 static void
869 gdbsim_resume (struct target_ops *ops, 866 gdbsim_resume (struct target_ops *ops,
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
943 940
944 /* GDB version of os_poll_quit callback. 941 /* GDB version of os_poll_quit callback.
945 Taken from gdb/util.c - should be in a library. */ 942 Taken from gdb/util.c - should be in a library. */
946 943
947 static int 944 static int
948 gdb_os_poll_quit (host_callback *p) 945 gdb_os_poll_quit (host_callback *p)
949 { 946 {
950 if (deprecated_ui_loop_hook != NULL) 947 if (deprecated_ui_loop_hook != NULL)
951 deprecated_ui_loop_hook (0); 948 deprecated_ui_loop_hook (0);
952 949
953 if (quit_flag)» » /* gdb's idea of quit */ 950 if (check_quit_flag ())» /* gdb's idea of quit */
954 { 951 {
955 quit_flag = 0;» » /* we've stolen it */ 952 clear_quit_flag ();» /* we've stolen it */
956 return 1;
957 }
958 else if (immediate_quit)
959 {
960 return 1; 953 return 1;
961 } 954 }
962 return 0; 955 return 0;
963 } 956 }
964 957
965 /* Wait for inferior process to do something. Return pid of child, 958 /* Wait for inferior process to do something. Return pid of child,
966 or -1 in case of error; store status through argument pointer STATUS, 959 or -1 in case of error; store status through argument pointer STATUS,
967 just as `wait' would. */ 960 just as `wait' would. */
968 961
969 static void 962 static void
(...skipping 20 matching lines...) Expand all
990 else 983 else
991 { 984 {
992 sim_data = get_sim_inferior_data_by_ptid (ptid, SIM_INSTANCE_NEEDED); 985 sim_data = get_sim_inferior_data_by_ptid (ptid, SIM_INSTANCE_NEEDED);
993 if (sim_data == NULL) 986 if (sim_data == NULL)
994 error (_("Unable to wait for pid %d. Inferior not found."), 987 error (_("Unable to wait for pid %d. Inferior not found."),
995 ptid_get_pid (ptid)); 988 ptid_get_pid (ptid));
996 inferior_ptid = ptid; 989 inferior_ptid = ptid;
997 } 990 }
998 991
999 if (remote_debug) 992 if (remote_debug)
1000 printf_filtered ("gdbsim_wait\n"); 993 fprintf_unfiltered (gdb_stdlog, "gdbsim_wait\n");
1001 994
1002 #if defined (HAVE_SIGACTION) && defined (SA_RESTART) 995 #if defined (HAVE_SIGACTION) && defined (SA_RESTART)
1003 { 996 {
1004 struct sigaction sa, osa; 997 struct sigaction sa, osa;
1005 sa.sa_handler = gdbsim_cntrl_c; 998 sa.sa_handler = gdbsim_cntrl_c;
1006 sigemptyset (&sa.sa_mask); 999 sigemptyset (&sa.sa_mask);
1007 sa.sa_flags = 0; 1000 sa.sa_flags = 0;
1008 sigaction (SIGINT, &sa, &osa); 1001 sigaction (SIGINT, &sa, &osa);
1009 prev_sigint = osa.sa_handler; 1002 prev_sigint = osa.sa_handler;
1010 } 1003 }
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
1057 which store all the registers in one fell swoop, this makes sure 1050 which store all the registers in one fell swoop, this makes sure
1058 that registers contains all the registers from the program being 1051 that registers contains all the registers from the program being
1059 debugged. */ 1052 debugged. */
1060 1053
1061 static void 1054 static void
1062 gdbsim_prepare_to_store (struct regcache *regcache) 1055 gdbsim_prepare_to_store (struct regcache *regcache)
1063 { 1056 {
1064 /* Do nothing, since we can store individual regs. */ 1057 /* Do nothing, since we can store individual regs. */
1065 } 1058 }
1066 1059
1067 /* Transfer LEN bytes between GDB address MYADDR and target address 1060 /* Helper for gdbsim_xfer_partial that handles memory transfers.
1068 MEMADDR. If WRITE is non-zero, transfer them to the target, 1061 Arguments are like target_xfer_partial. */
1069 otherwise transfer them from the target. TARGET is unused.
1070 1062
1071 Returns the number of bytes transferred. */ 1063 static LONGEST
1072 1064 gdbsim_xfer_memory (struct target_ops *target,
1073 static int 1065 » » gdb_byte *readbuf, const gdb_byte *writebuf,
1074 gdbsim_xfer_inferior_memory (CORE_ADDR memaddr, gdb_byte *myaddr, int len, 1066 » » ULONGEST memaddr, LONGEST len)
1075 » » » int write, struct mem_attrib *attrib,
1076 » » » struct target_ops *target)
1077 { 1067 {
1078 struct sim_inferior_data *sim_data 1068 struct sim_inferior_data *sim_data
1079 = get_sim_inferior_data (current_inferior (), SIM_INSTANCE_NOT_NEEDED); 1069 = get_sim_inferior_data (current_inferior (), SIM_INSTANCE_NOT_NEEDED);
1080 1070
1081 /* If this target doesn't have memory yet, return 0 causing the 1071 /* If this target doesn't have memory yet, return 0 causing the
1082 request to be passed to a lower target, hopefully an exec 1072 request to be passed to a lower target, hopefully an exec
1083 file. */ 1073 file. */
1084 if (!target->to_has_memory (target)) 1074 if (!target->to_has_memory (target))
1085 return 0; 1075 return 0;
1086 1076
1087 if (!sim_data->program_loaded) 1077 if (!sim_data->program_loaded)
1088 error (_("No program loaded.")); 1078 error (_("No program loaded."));
1089 1079
1090 /* Note that we obtained the sim_data pointer above using 1080 /* Note that we obtained the sim_data pointer above using
1091 SIM_INSTANCE_NOT_NEEDED. We do this so that we don't needlessly 1081 SIM_INSTANCE_NOT_NEEDED. We do this so that we don't needlessly
1092 allocate a sim instance prior to loading a program. If we 1082 allocate a sim instance prior to loading a program. If we
1093 get to this point in the code though, gdbsim_desc should be 1083 get to this point in the code though, gdbsim_desc should be
1094 non-NULL. (Note that a sim instance is needed in order to load 1084 non-NULL. (Note that a sim instance is needed in order to load
1095 the program...) */ 1085 the program...) */
1096 gdb_assert (sim_data->gdbsim_desc != NULL); 1086 gdb_assert (sim_data->gdbsim_desc != NULL);
1097 1087
1098 if (remote_debug) 1088 if (remote_debug)
1089 fprintf_unfiltered (gdb_stdlog,
1090 "gdbsim_xfer_memory: readbuf %s, writebuf %s, "
1091 "memaddr %s, len %s\n",
1092 host_address_to_string (readbuf),
1093 host_address_to_string (writebuf),
1094 paddress (target_gdbarch (), memaddr),
1095 plongest (len));
1096
1097 if (writebuf)
1099 { 1098 {
1100 /* FIXME: Send to something other than STDOUT? */ 1099 if (remote_debug && len > 0)
1101 printf_filtered ("gdbsim_xfer_inferior_memory: myaddr 0x"); 1100 » dump_mem (writebuf, len);
1102 gdb_print_host_address (myaddr, gdb_stdout); 1101 len = sim_write (sim_data->gdbsim_desc, memaddr, writebuf, len);
1103 printf_filtered (", memaddr %s, len %d, write %d\n",
1104 » » paddress (target_gdbarch, memaddr), len, write);
1105 if (remote_debug && write)
1106 » dump_mem (myaddr, len);
1107 }
1108
1109 if (write)
1110 {
1111 len = sim_write (sim_data->gdbsim_desc, memaddr, myaddr, len);
1112 } 1102 }
1113 else 1103 else
1114 { 1104 {
1115 len = sim_read (sim_data->gdbsim_desc, memaddr, myaddr, len); 1105 len = sim_read (sim_data->gdbsim_desc, memaddr, readbuf, len);
1116 if (remote_debug && len > 0) 1106 if (remote_debug && len > 0)
1117 » dump_mem (myaddr, len); 1107 » dump_mem (readbuf, len);
1118 } 1108 }
1119 return len; 1109 return len;
1120 } 1110 }
1121 1111
1112 /* Target to_xfer_partial implementation. */
1113
1114 static LONGEST
1115 gdbsim_xfer_partial (struct target_ops *ops, enum target_object object,
1116 const char *annex, gdb_byte *readbuf,
1117 const gdb_byte *writebuf, ULONGEST offset, LONGEST len)
1118 {
1119 switch (object)
1120 {
1121 case TARGET_OBJECT_MEMORY:
1122 return gdbsim_xfer_memory (ops, readbuf, writebuf, offset, len);
1123
1124 default:
1125 return -1;
1126 }
1127 }
1128
1122 static void 1129 static void
1123 gdbsim_files_info (struct target_ops *target) 1130 gdbsim_files_info (struct target_ops *target)
1124 { 1131 {
1125 struct sim_inferior_data *sim_data 1132 struct sim_inferior_data *sim_data
1126 = get_sim_inferior_data (current_inferior (), SIM_INSTANCE_NEEDED); 1133 = get_sim_inferior_data (current_inferior (), SIM_INSTANCE_NEEDED);
1127 const char *file = "nothing"; 1134 const char *file = "nothing";
1128 1135
1129 if (exec_bfd) 1136 if (exec_bfd)
1130 file = bfd_get_filename (exec_bfd); 1137 file = bfd_get_filename (exec_bfd);
1131 1138
1132 if (remote_debug) 1139 if (remote_debug)
1133 printf_filtered ("gdbsim_files_info: file \"%s\"\n", file); 1140 fprintf_unfiltered (gdb_stdlog, "gdbsim_files_info: file \"%s\"\n", file);
1134 1141
1135 if (exec_bfd) 1142 if (exec_bfd)
1136 { 1143 {
1137 printf_filtered ("\tAttached to %s running program %s\n", 1144 fprintf_unfiltered (gdb_stdlog, "\tAttached to %s running program %s\n",
1138 » » target_shortname, file); 1145 » » » target_shortname, file);
1139 sim_info (sim_data->gdbsim_desc, 0); 1146 sim_info (sim_data->gdbsim_desc, 0);
1140 } 1147 }
1141 } 1148 }
1142 1149
1143 /* Clear the simulator's notion of what the break points are. */ 1150 /* Clear the simulator's notion of what the break points are. */
1144 1151
1145 static void 1152 static void
1146 gdbsim_mourn_inferior (struct target_ops *target) 1153 gdbsim_mourn_inferior (struct target_ops *target)
1147 { 1154 {
1148 struct sim_inferior_data *sim_data 1155 struct sim_inferior_data *sim_data
1149 = get_sim_inferior_data (current_inferior (), SIM_INSTANCE_NOT_NEEDED); 1156 = get_sim_inferior_data (current_inferior (), SIM_INSTANCE_NOT_NEEDED);
1150 1157
1151 if (remote_debug) 1158 if (remote_debug)
1152 printf_filtered ("gdbsim_mourn_inferior:\n"); 1159 fprintf_unfiltered (gdb_stdlog, "gdbsim_mourn_inferior:\n");
1153 1160
1154 remove_breakpoints (); 1161 remove_breakpoints ();
1155 generic_mourn_inferior (); 1162 generic_mourn_inferior ();
1156 delete_thread_silent (sim_data->remote_sim_ptid); 1163 delete_thread_silent (sim_data->remote_sim_ptid);
1157 } 1164 }
1158 1165
1159 /* Pass the command argument through to the simulator verbatim. The 1166 /* Pass the command argument through to the simulator verbatim. The
1160 simulator must do any command interpretation work. */ 1167 simulator must do any command interpretation work. */
1161 1168
1162 void 1169 void
(...skipping 29 matching lines...) Expand all
1192 } 1199 }
1193 1200
1194 sim_do_command (sim_data->gdbsim_desc, args); 1201 sim_do_command (sim_data->gdbsim_desc, args);
1195 1202
1196 /* Invalidate the register cache, in case the simulator command does 1203 /* Invalidate the register cache, in case the simulator command does
1197 something funny. */ 1204 something funny. */
1198 registers_changed (); 1205 registers_changed ();
1199 } 1206 }
1200 1207
1201 static VEC (char_ptr) * 1208 static VEC (char_ptr) *
1202 sim_command_completer (struct cmd_list_element *ignore, char *text, char *word) 1209 sim_command_completer (struct cmd_list_element *ignore, const char *text,
1210 » » const char *word)
1203 { 1211 {
1204 struct sim_inferior_data *sim_data; 1212 struct sim_inferior_data *sim_data;
1205 char **tmp; 1213 char **tmp;
1206 int i; 1214 int i;
1207 VEC (char_ptr) *result = NULL; 1215 VEC (char_ptr) *result = NULL;
1208 1216
1209 sim_data = inferior_data (current_inferior (), sim_inferior_data_key); 1217 sim_data = inferior_data (current_inferior (), sim_inferior_data_key);
1210 if (sim_data == NULL || sim_data->gdbsim_desc == NULL) 1218 if (sim_data == NULL || sim_data->gdbsim_desc == NULL)
1211 return NULL; 1219 return NULL;
1212 1220
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
1286 gdbsim_ops.to_longname = "simulator"; 1294 gdbsim_ops.to_longname = "simulator";
1287 gdbsim_ops.to_doc = "Use the compiled-in simulator."; 1295 gdbsim_ops.to_doc = "Use the compiled-in simulator.";
1288 gdbsim_ops.to_open = gdbsim_open; 1296 gdbsim_ops.to_open = gdbsim_open;
1289 gdbsim_ops.to_close = gdbsim_close; 1297 gdbsim_ops.to_close = gdbsim_close;
1290 gdbsim_ops.to_detach = gdbsim_detach; 1298 gdbsim_ops.to_detach = gdbsim_detach;
1291 gdbsim_ops.to_resume = gdbsim_resume; 1299 gdbsim_ops.to_resume = gdbsim_resume;
1292 gdbsim_ops.to_wait = gdbsim_wait; 1300 gdbsim_ops.to_wait = gdbsim_wait;
1293 gdbsim_ops.to_fetch_registers = gdbsim_fetch_register; 1301 gdbsim_ops.to_fetch_registers = gdbsim_fetch_register;
1294 gdbsim_ops.to_store_registers = gdbsim_store_register; 1302 gdbsim_ops.to_store_registers = gdbsim_store_register;
1295 gdbsim_ops.to_prepare_to_store = gdbsim_prepare_to_store; 1303 gdbsim_ops.to_prepare_to_store = gdbsim_prepare_to_store;
1296 gdbsim_ops.deprecated_xfer_memory = gdbsim_xfer_inferior_memory; 1304 gdbsim_ops.to_xfer_partial = gdbsim_xfer_partial;
1297 gdbsim_ops.to_files_info = gdbsim_files_info; 1305 gdbsim_ops.to_files_info = gdbsim_files_info;
1298 gdbsim_ops.to_insert_breakpoint = memory_insert_breakpoint; 1306 gdbsim_ops.to_insert_breakpoint = memory_insert_breakpoint;
1299 gdbsim_ops.to_remove_breakpoint = memory_remove_breakpoint; 1307 gdbsim_ops.to_remove_breakpoint = memory_remove_breakpoint;
1300 gdbsim_ops.to_kill = gdbsim_kill; 1308 gdbsim_ops.to_kill = gdbsim_kill;
1301 gdbsim_ops.to_load = gdbsim_load; 1309 gdbsim_ops.to_load = gdbsim_load;
1302 gdbsim_ops.to_create_inferior = gdbsim_create_inferior; 1310 gdbsim_ops.to_create_inferior = gdbsim_create_inferior;
1303 gdbsim_ops.to_mourn_inferior = gdbsim_mourn_inferior; 1311 gdbsim_ops.to_mourn_inferior = gdbsim_mourn_inferior;
1304 gdbsim_ops.to_stop = gdbsim_stop; 1312 gdbsim_ops.to_stop = gdbsim_stop;
1305 gdbsim_ops.to_thread_alive = gdbsim_thread_alive; 1313 gdbsim_ops.to_thread_alive = gdbsim_thread_alive;
1306 gdbsim_ops.to_pid_to_str = gdbsim_pid_to_str; 1314 gdbsim_ops.to_pid_to_str = gdbsim_pid_to_str;
(...skipping 12 matching lines...) Expand all
1319 struct cmd_list_element *c; 1327 struct cmd_list_element *c;
1320 1328
1321 init_gdbsim_ops (); 1329 init_gdbsim_ops ();
1322 add_target (&gdbsim_ops); 1330 add_target (&gdbsim_ops);
1323 1331
1324 c = add_com ("sim", class_obscure, simulator_command, 1332 c = add_com ("sim", class_obscure, simulator_command,
1325 _("Send a command to the simulator.")); 1333 _("Send a command to the simulator."));
1326 set_cmd_completer (c, sim_command_completer); 1334 set_cmd_completer (c, sim_command_completer);
1327 1335
1328 sim_inferior_data_key 1336 sim_inferior_data_key
1329 = register_inferior_data_with_cleanup (sim_inferior_data_cleanup); 1337 = register_inferior_data_with_cleanup (NULL, sim_inferior_data_cleanup);
1330 } 1338 }
OLDNEW
« no previous file with comments | « gdb/remote-notif.c ('k') | gdb/reply_mig_hack.awk » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698