X-Git-Url: http://drtracing.org/?a=blobdiff_plain;f=gdb%2Frecord-full.c;h=4d8dd61bcaaa9d18108ec840a60df82f742f7335;hb=a6535de1903d9caad8c10c1d81c51a29612456a6;hp=803c5d4612ed58caac8f18c6f5002d52abc11e5e;hpb=93f9a11fbdb8f09428b17180d51a09a1bda39a52;p=deliverable%2Fbinutils-gdb.git diff --git a/gdb/record-full.c b/gdb/record-full.c index 803c5d4612..4d8dd61bca 100644 --- a/gdb/record-full.c +++ b/gdb/record-full.c @@ -1,6 +1,6 @@ /* Process record and replay target for GDB, the GNU debugger. - Copyright (C) 2013-2016 Free Software Foundation, Inc. + Copyright (C) 2013-2018 Free Software Foundation, Inc. This file is part of GDB. @@ -33,8 +33,10 @@ #include "event-loop.h" #include "inf-loop.h" #include "gdb_bfd.h" -#include "observer.h" +#include "observable.h" #include "infrun.h" +#include "common/gdb_unlinker.h" +#include "common/byte-vector.h" #include @@ -166,7 +168,7 @@ struct record_full_core_buf_entry }; /* Record buf with core target. */ -static gdb_byte *record_full_core_regbuf = NULL; +static detached_regcache *record_full_core_regbuf = NULL; static struct target_section *record_full_core_start; static struct target_section *record_full_core_end; static struct record_full_core_buf_entry *record_full_core_buf_list = NULL; @@ -242,7 +244,7 @@ static inline struct record_full_entry * record_full_reg_alloc (struct regcache *regcache, int regnum) { struct record_full_entry *rec; - struct gdbarch *gdbarch = get_regcache_arch (regcache); + struct gdbarch *gdbarch = regcache->arch (); rec = XCNEW (struct record_full_entry); rec->type = record_full_reg; @@ -563,11 +565,11 @@ record_full_arch_list_cleanups (void *ignore) record the running message of inferior and set them to record_full_arch_list, and add it to record_full_list. */ -static int +static void record_full_message (struct regcache *regcache, enum gdb_signal signal) { int ret; - struct gdbarch *gdbarch = get_regcache_arch (regcache); + struct gdbarch *gdbarch = regcache->arch (); struct cleanup *old_cleanups = make_cleanup (record_full_arch_list_cleanups, 0); @@ -631,36 +633,24 @@ record_full_message (struct regcache *regcache, enum gdb_signal signal) record_full_list_release_first (); else record_full_insn_num++; - - return 1; } -struct record_full_message_args { - struct regcache *regcache; - enum gdb_signal signal; -}; - -static int -record_full_message_wrapper (void *args) -{ - struct record_full_message_args *record_full_args - = (struct record_full_message_args *) args; - - return record_full_message (record_full_args->regcache, - record_full_args->signal); -} - -static int +static bool record_full_message_wrapper_safe (struct regcache *regcache, enum gdb_signal signal) { - struct record_full_message_args args; - - args.regcache = regcache; - args.signal = signal; + TRY + { + record_full_message (regcache, signal); + } + CATCH (ex, RETURN_MASK_ALL) + { + exception_print (gdb_stderr, ex); + return false; + } + END_CATCH - return catch_errors (record_full_message_wrapper, &args, "", - RETURN_MASK_ALL); + return true; } /* Set to 1 if record_full_store_registers and record_full_xfer_partial @@ -668,16 +658,10 @@ record_full_message_wrapper_safe (struct regcache *regcache, static int record_full_gdb_operation_disable = 0; -struct cleanup * +scoped_restore_tmpl record_full_gdb_operation_disable_set (void) { - struct cleanup *old_cleanups = NULL; - - old_cleanups = - make_cleanup_restore_integer (&record_full_gdb_operation_disable); - record_full_gdb_operation_disable = 1; - - return old_cleanups; + return make_scoped_restore (&record_full_gdb_operation_disable, 1); } /* Flag set to TRUE for target_stopped_by_watchpoint. */ @@ -697,7 +681,7 @@ record_full_exec_insn (struct regcache *regcache, { case record_full_reg: /* reg */ { - gdb_byte reg[MAX_REGISTER_SIZE]; + gdb::byte_vector reg (entry->u.reg.len); if (record_debug > 1) fprintf_unfiltered (gdb_stdlog, @@ -706,10 +690,10 @@ record_full_exec_insn (struct regcache *regcache, host_address_to_string (entry), entry->u.reg.num); - regcache_cooked_read (regcache, entry->u.reg.num, reg); + regcache_cooked_read (regcache, entry->u.reg.num, reg.data ()); regcache_cooked_write (regcache, entry->u.reg.num, record_full_get_loc (entry)); - memcpy (record_full_get_loc (entry), reg, entry->u.reg.len); + memcpy (record_full_get_loc (entry), reg.data (), entry->u.reg.len); } break; @@ -718,8 +702,7 @@ record_full_exec_insn (struct regcache *regcache, /* Nothing to do if the entry is flagged not_accessible. */ if (!entry->u.mem.mem_entry_not_accessible) { - gdb_byte *mem = (gdb_byte *) xmalloc (entry->u.mem.len); - struct cleanup *cleanup = make_cleanup (xfree, mem); + gdb::byte_vector mem (entry->u.mem.len); if (record_debug > 1) fprintf_unfiltered (gdb_stdlog, @@ -730,7 +713,8 @@ record_full_exec_insn (struct regcache *regcache, entry->u.mem.len); if (record_read_memory (gdbarch, - entry->u.mem.addr, mem, entry->u.mem.len)) + entry->u.mem.addr, mem.data (), + entry->u.mem.len)) entry->u.mem.mem_entry_not_accessible = 1; else { @@ -747,7 +731,7 @@ record_full_exec_insn (struct regcache *regcache, } else { - memcpy (record_full_get_loc (entry), mem, + memcpy (record_full_get_loc (entry), mem.data (), entry->u.mem.len); /* We've changed memory --- check if a hardware @@ -759,13 +743,11 @@ record_full_exec_insn (struct regcache *regcache, not doing the change at all if the watchpoint traps. */ if (hardware_watchpoint_inserted_in_range - (get_regcache_aspace (regcache), + (regcache->aspace (), entry->u.mem.addr, entry->u.mem.len)) record_full_stop_reason = TARGET_STOPPED_BY_WATCHPOINT; } } - - do_cleanups (cleanup); } } break; @@ -791,21 +773,21 @@ static void record_full_core_open_1 (const char *name, int from_tty) { struct regcache *regcache = get_current_regcache (); - int regnum = gdbarch_num_regs (get_regcache_arch (regcache)); + int regnum = gdbarch_num_regs (regcache->arch ()); int i; /* Get record_full_core_regbuf. */ target_fetch_registers (regcache, -1); - record_full_core_regbuf = (gdb_byte *) xmalloc (MAX_REGISTER_SIZE * regnum); + record_full_core_regbuf = new detached_regcache (regcache->arch (), false); + for (i = 0; i < regnum; i ++) - regcache_raw_collect (regcache, i, - record_full_core_regbuf + MAX_REGISTER_SIZE * i); + record_full_core_regbuf->raw_supply (i, *regcache); /* Get record_full_core_start and record_full_core_end. */ if (build_section_table (core_bfd, &record_full_core_start, &record_full_core_end)) { - xfree (record_full_core_regbuf); + delete record_full_core_regbuf; record_full_core_regbuf = NULL; error (_("\"%s\": Can't find sections: %s"), bfd_get_filename (core_bfd), bfd_errmsg (bfd_get_error ())); @@ -821,7 +803,7 @@ static void record_full_open_1 (const char *name, int from_tty) { if (record_debug) - fprintf_unfiltered (gdb_stdlog, "Process record: record_full_open\n"); + fprintf_unfiltered (gdb_stdlog, "Process record: record_full_open_1\n"); /* check exec */ if (!target_has_execution) @@ -844,8 +826,6 @@ static void record_full_init_record_breakpoints (void); static void record_full_open (const char *name, int from_tty) { - struct target_ops *t; - if (record_debug) fprintf_unfiltered (gdb_stdlog, "Process record: record_full_open\n"); @@ -869,7 +849,7 @@ record_full_open (const char *name, int from_tty) record_full_init_record_breakpoints (); - observer_notify_record_changed (current_inferior (), 1, "full", NULL); + gdb::observers::record_changed.notify (current_inferior (), 1, "full", NULL); } /* "to_close" target method. Close the process record target. */ @@ -887,7 +867,7 @@ record_full_close (struct target_ops *self) /* Release record_full_core_regbuf. */ if (record_full_core_regbuf) { - xfree (record_full_core_regbuf); + delete record_full_core_regbuf; record_full_core_regbuf = NULL; } @@ -969,7 +949,7 @@ record_full_resume (struct target_ops *ops, ptid_t ptid, int step, } else { - /* This arch support soft sigle step. */ + /* This arch supports soft single step. */ if (thread_has_single_step_breakpoints_set (inferior_thread ())) { /* This is a soft single step. */ @@ -1049,7 +1029,8 @@ record_full_wait_1 (struct target_ops *ops, ptid_t ptid, struct target_waitstatus *status, int options) { - struct cleanup *set_cleanups = record_full_gdb_operation_disable_set (); + scoped_restore restore_operation_disable + = record_full_gdb_operation_disable_set (); if (record_debug) fprintf_unfiltered (gdb_stdlog, @@ -1113,7 +1094,6 @@ record_full_wait_1 (struct target_ops *ops, && status->value.sig == GDB_SIGNAL_TRAP) { struct regcache *regcache; - struct address_space *aspace; enum target_stop_reason *stop_reason_p = &record_full_stop_reason; @@ -1124,7 +1104,7 @@ record_full_wait_1 (struct target_ops *ops, registers_changed (); regcache = get_current_regcache (); tmp_pc = regcache_read_pc (regcache); - aspace = get_regcache_aspace (regcache); + const struct address_space *aspace = regcache->aspace (); if (target_stopped_by_watchpoint ()) { @@ -1186,8 +1166,8 @@ record_full_wait_1 (struct target_ops *ops, else { struct regcache *regcache = get_current_regcache (); - struct gdbarch *gdbarch = get_regcache_arch (regcache); - struct address_space *aspace = get_regcache_aspace (regcache); + struct gdbarch *gdbarch = regcache->arch (); + const struct address_space *aspace = regcache->aspace (); int continue_flag = 1; int first_record_full_end = 1; struct cleanup *old_cleanups @@ -1216,7 +1196,7 @@ record_full_wait_1 (struct target_ops *ops, And in GDB replay mode, GDB doesn't need to be in terminal_inferior mode, because inferior will not executed. Then set it to terminal_ours to make GDB get the signal. */ - target_terminal_ours (); + target_terminal::ours (); /* In EXEC_FORWARD mode, record_full_list points to the tail of prev instruction. */ @@ -1332,7 +1312,6 @@ replay_out: signal (SIGINT, handle_sigint); - do_cleanups (set_cleanups); return inferior_ptid; } @@ -1421,7 +1400,7 @@ record_full_registers_change (struct regcache *regcache, int regnum) { int i; - for (i = 0; i < gdbarch_num_regs (get_regcache_arch (regcache)); i++) + for (i = 0; i < gdbarch_num_regs (regcache->arch ()); i++) { if (record_full_arch_list_add_reg (regcache, i)) { @@ -1478,7 +1457,7 @@ record_full_store_registers (struct target_ops *ops, query (_("Because GDB is in replay mode, changing the value " "of a register will make the execution log unusable " "from this point onward. Change register %s?"), - gdbarch_register_name (get_regcache_arch (regcache), + gdbarch_register_name (regcache->arch (), regno)); if (!n) @@ -1490,7 +1469,7 @@ record_full_store_registers (struct target_ops *ops, int i; for (i = 0; - i < gdbarch_num_regs (get_regcache_arch (regcache)); + i < gdbarch_num_regs (regcache->arch ()); i++) regcache_invalidate (regcache, i); } @@ -1651,12 +1630,11 @@ record_full_insert_breakpoint (struct target_ops *ops, However, we do have to insert software single-step breakpoints, in case the target can't hardware step. To keep things simple, we always insert. */ - struct cleanup *old_cleanups; int ret; - old_cleanups = record_full_gdb_operation_disable_set (); + scoped_restore restore_operation_disable + = record_full_gdb_operation_disable_set (); ret = ops->beneath->to_insert_breakpoint (ops->beneath, gdbarch, bp_tgt); - do_cleanups (old_cleanups); if (ret != 0) return ret; @@ -1709,14 +1687,12 @@ record_full_remove_breakpoint (struct target_ops *ops, { if (bp->in_target_beneath) { - struct cleanup *old_cleanups; int ret; - old_cleanups = record_full_gdb_operation_disable_set (); + scoped_restore restore_operation_disable + = record_full_gdb_operation_disable_set (); ret = ops->beneath->to_remove_breakpoint (ops->beneath, gdbarch, bp_tgt, reason); - do_cleanups (old_cleanups); - if (ret != 0) return ret; } @@ -1772,28 +1748,22 @@ record_full_goto_bookmark (struct target_ops *self, const gdb_byte *raw_bookmark, int from_tty) { const char *bookmark = (const char *) raw_bookmark; - struct cleanup *cleanup = make_cleanup (null_cleanup, NULL); if (record_debug) fprintf_unfiltered (gdb_stdlog, "record_full_goto_bookmark receives %s\n", bookmark); + std::string name_holder; if (bookmark[0] == '\'' || bookmark[0] == '\"') { - char *copy; - if (bookmark[strlen (bookmark) - 1] != bookmark[0]) error (_("Unbalanced quotes: %s"), bookmark); - - copy = savestring (bookmark + 1, strlen (bookmark) - 2); - make_cleanup (xfree, copy); - bookmark = copy; + name_holder = std::string (bookmark + 1, strlen (bookmark) - 2); + bookmark = name_holder.c_str (); } record_goto (bookmark); - - do_cleanups (cleanup); } static enum exec_direction_kind @@ -1802,6 +1772,14 @@ record_full_execution_direction (struct target_ops *self) return record_full_execution_dir; } +/* The to_record_method method of target record-full. */ + +enum record_method +record_full_record_method (struct target_ops *self, ptid_t ptid) +{ + return RECORD_METHOD_FULL; +} + static void record_full_info (struct target_ops *self) { @@ -1991,6 +1969,7 @@ init_record_full_ops (void) record_full_ops.to_get_bookmark = record_full_get_bookmark; record_full_ops.to_goto_bookmark = record_full_goto_bookmark; record_full_ops.to_execution_direction = record_full_execution_direction; + record_full_ops.to_record_method = record_full_record_method; record_full_ops.to_info_record = record_full_info; record_full_ops.to_save_record = record_full_save; record_full_ops.to_delete_record = record_full_delete; @@ -2039,16 +2018,14 @@ record_full_core_fetch_registers (struct target_ops *ops, { if (regno < 0) { - int num = gdbarch_num_regs (get_regcache_arch (regcache)); + int num = gdbarch_num_regs (regcache->arch ()); int i; for (i = 0; i < num; i ++) - regcache_raw_supply (regcache, i, - record_full_core_regbuf + MAX_REGISTER_SIZE * i); + regcache->raw_supply (i, *record_full_core_regbuf); } else - regcache_raw_supply (regcache, regno, - record_full_core_regbuf + MAX_REGISTER_SIZE * regno); + regcache->raw_supply (regno, *record_full_core_regbuf); } /* "to_prepare_to_store" method for prec over corefile. */ @@ -2067,8 +2044,7 @@ record_full_core_store_registers (struct target_ops *ops, int regno) { if (record_full_gdb_operation_disable) - regcache_raw_collect (regcache, regno, - record_full_core_regbuf + MAX_REGISTER_SIZE * regno); + record_full_core_regbuf->raw_supply (regno, *regcache); else error (_("You can't do that without a process to debug.")); } @@ -2241,6 +2217,7 @@ init_record_full_core_ops (void) record_full_core_ops.to_goto_bookmark = record_full_goto_bookmark; record_full_core_ops.to_execution_direction = record_full_execution_direction; + record_full_core_ops.to_record_method = record_full_record_method; record_full_core_ops.to_info_record = record_full_info; record_full_core_ops.to_delete_record = record_full_delete; record_full_core_ops.to_record_is_replaying = record_full_is_replaying; @@ -2328,16 +2305,6 @@ netorder32 (uint32_t input) return ret; } -static inline uint16_t -netorder16 (uint16_t input) -{ - uint16_t ret; - - store_unsigned_integer ((gdb_byte *) &ret, sizeof (ret), - BFD_ENDIAN_BIG, input); - return ret; -} - /* Restore the execution log from a core_bfd file. */ static void record_full_restore (void) @@ -2531,23 +2498,12 @@ bfdcore_write (bfd *obfd, asection *osec, void *buf, int len, int *offset) corefile format, with an extra section for our data. */ static void -cmd_record_full_restore (char *args, int from_tty) +cmd_record_full_restore (const char *args, int from_tty) { core_file_command (args, from_tty); record_full_open (args, from_tty); } -static void -record_full_save_cleanups (void *data) -{ - bfd *obfd = (bfd *) data; - char *pathname = xstrdup (bfd_get_filename (obfd)); - - gdb_bfd_unref (obfd); - unlink (pathname); - xfree (pathname); -} - /* Save the execution log to a file. We use a modified elf corefile format, with an extra section for our data. */ @@ -2558,9 +2514,6 @@ record_full_save (struct target_ops *self, const char *recfilename) uint32_t magic; struct regcache *regcache; struct gdbarch *gdbarch; - struct cleanup *old_cleanups; - struct cleanup *set_cleanups; - bfd *obfd; int save_size = 0; asection *osec = NULL; int bfd_offset = 0; @@ -2571,18 +2524,21 @@ record_full_save (struct target_ops *self, const char *recfilename) recfilename); /* Open the output file. */ - obfd = create_gcore_bfd (recfilename); - old_cleanups = make_cleanup (record_full_save_cleanups, obfd); + gdb_bfd_ref_ptr obfd (create_gcore_bfd (recfilename)); + + /* Arrange to remove the output file on failure. */ + gdb::unlinker unlink_file (recfilename); /* Save the current record entry to "cur_record_full_list". */ cur_record_full_list = record_full_list; /* Get the values of regcache and gdbarch. */ regcache = get_current_regcache (); - gdbarch = get_regcache_arch (regcache); + gdbarch = regcache->arch (); /* Disable the GDB operation record. */ - set_cleanups = record_full_gdb_operation_disable_set (); + scoped_restore restore_operation_disable + = record_full_gdb_operation_disable_set (); /* Reverse execute to the begin of record list. */ while (1) @@ -2615,20 +2571,20 @@ record_full_save (struct target_ops *self, const char *recfilename) } /* Make the new bfd section. */ - osec = bfd_make_section_anyway_with_flags (obfd, "precord", + osec = bfd_make_section_anyway_with_flags (obfd.get (), "precord", SEC_HAS_CONTENTS | SEC_READONLY); if (osec == NULL) error (_("Failed to create 'precord' section for corefile %s: %s"), recfilename, bfd_errmsg (bfd_get_error ())); - bfd_set_section_size (obfd, osec, save_size); - bfd_set_section_vma (obfd, osec, 0); - bfd_set_section_alignment (obfd, osec, 0); - bfd_section_lma (obfd, osec) = 0; + bfd_set_section_size (obfd.get (), osec, save_size); + bfd_set_section_vma (obfd.get (), osec, 0); + bfd_set_section_alignment (obfd.get (), osec, 0); + bfd_section_lma (obfd.get (), osec) = 0; /* Save corefile state. */ - write_gcore_file (obfd); + write_gcore_file (obfd.get ()); /* Write out the record log. */ /* Write the magic code. */ @@ -2638,7 +2594,7 @@ record_full_save (struct target_ops *self, const char *recfilename) " Writing 4-byte magic cookie " "RECORD_FULL_FILE_MAGIC (0x%s)\n", phex_nz (magic, 4)); - bfdcore_write (obfd, osec, &magic, sizeof (magic), &bfd_offset); + bfdcore_write (obfd.get (), osec, &magic, sizeof (magic), &bfd_offset); /* Save the entries to recfd and forward execute to the end of record list. */ @@ -2653,7 +2609,7 @@ record_full_save (struct target_ops *self, const char *recfilename) uint64_t addr; type = record_full_list->type; - bfdcore_write (obfd, osec, &type, sizeof (type), &bfd_offset); + bfdcore_write (obfd.get (), osec, &type, sizeof (type), &bfd_offset); switch (record_full_list->type) { @@ -2668,11 +2624,11 @@ record_full_save (struct target_ops *self, const char *recfilename) /* Write regnum. */ regnum = netorder32 (record_full_list->u.reg.num); - bfdcore_write (obfd, osec, ®num, + bfdcore_write (obfd.get (), osec, ®num, sizeof (regnum), &bfd_offset); /* Write regval. */ - bfdcore_write (obfd, osec, + bfdcore_write (obfd.get (), osec, record_full_get_loc (record_full_list), record_full_list->u.reg.len, &bfd_offset); break; @@ -2690,15 +2646,16 @@ record_full_save (struct target_ops *self, const char *recfilename) /* Write memlen. */ len = netorder32 (record_full_list->u.mem.len); - bfdcore_write (obfd, osec, &len, sizeof (len), &bfd_offset); + bfdcore_write (obfd.get (), osec, &len, sizeof (len), + &bfd_offset); /* Write memaddr. */ addr = netorder64 (record_full_list->u.mem.addr); - bfdcore_write (obfd, osec, &addr, + bfdcore_write (obfd.get (), osec, &addr, sizeof (addr), &bfd_offset); /* Write memval. */ - bfdcore_write (obfd, osec, + bfdcore_write (obfd.get (), osec, record_full_get_loc (record_full_list), record_full_list->u.mem.len, &bfd_offset); break; @@ -2712,12 +2669,12 @@ record_full_save (struct target_ops *self, const char *recfilename) (unsigned long) sizeof (count)); /* Write signal value. */ signal = netorder32 (record_full_list->u.end.sigval); - bfdcore_write (obfd, osec, &signal, + bfdcore_write (obfd.get (), osec, &signal, sizeof (signal), &bfd_offset); /* Write insn count. */ count = netorder32 (record_full_list->u.end.insn_num); - bfdcore_write (obfd, osec, &count, + bfdcore_write (obfd.get (), osec, &count, sizeof (count), &bfd_offset); break; } @@ -2745,9 +2702,7 @@ record_full_save (struct target_ops *self, const char *recfilename) record_full_list = record_full_list->prev; } - do_cleanups (set_cleanups); - gdb_bfd_unref (obfd); - discard_cleanups (old_cleanups); + unlink_file.keep (); /* Succeeded. */ printf_filtered (_("Saved core file %s with execution log.\n"), @@ -2762,9 +2717,10 @@ static void record_full_goto_insn (struct record_full_entry *entry, enum exec_direction_kind dir) { - struct cleanup *set_cleanups = record_full_gdb_operation_disable_set (); + scoped_restore restore_operation_disable + = record_full_gdb_operation_disable_set (); struct regcache *regcache = get_current_regcache (); - struct gdbarch *gdbarch = get_regcache_arch (regcache); + struct gdbarch *gdbarch = regcache->arch (); /* Assume everything is valid: we will hit the entry, and we will not hit the end of the recording. */ @@ -2780,19 +2736,18 @@ record_full_goto_insn (struct record_full_entry *entry, else record_full_list = record_full_list->next; } while (record_full_list != entry); - do_cleanups (set_cleanups); } /* Alias for "target record-full". */ static void -cmd_record_full_start (char *args, int from_tty) +cmd_record_full_start (const char *args, int from_tty) { execute_command ("target record-full", from_tty); } static void -set_record_full_insn_max_num (char *args, int from_tty, +set_record_full_insn_max_num (const char *args, int from_tty, struct cmd_list_element *c) { if (record_full_insn_num > record_full_insn_max_num) @@ -2809,10 +2764,10 @@ set_record_full_insn_max_num (char *args, int from_tty, /* The "set record full" command. */ static void -set_record_full_command (char *args, int from_tty) +set_record_full_command (const char *args, int from_tty) { printf_unfiltered (_("\"set record full\" must be followed " - "by an apporpriate subcommand.\n")); + "by an appropriate subcommand.\n")); help_list (set_record_full_cmdlist, "set record full ", all_commands, gdb_stdout); } @@ -2820,14 +2775,11 @@ set_record_full_command (char *args, int from_tty) /* The "show record full" command. */ static void -show_record_full_command (char *args, int from_tty) +show_record_full_command (const char *args, int from_tty) { cmd_show_list (show_record_full_cmdlist, from_tty, ""); } -/* Provide a prototype to silence -Wmissing-prototypes. */ -extern initialize_file_ftype _initialize_record_full; - void _initialize_record_full (void) {