2009-08-06 Michael Snyder <msnyder@vmware.com>

* record.c (cmd_record_dump): Clean up draft version.
	(cmd_record_load): Ditto.
This commit is contained in:
Michael Snyder
2009-08-07 02:53:15 +00:00
parent a77711c5df
commit b8586defc6
2 changed files with 294 additions and 443 deletions

View File

@@ -1,3 +1,8 @@
2009-08-06 Michael Snyder <msnyder@vmware.com>
* record.c (cmd_record_dump): Clean up draft version.
(cmd_record_load): Ditto.
2009-08-06 Hui Zhu <teawater@gmail.com> 2009-08-06 Hui Zhu <teawater@gmail.com>
Michael Snyder <msnyder@vmware.com> Michael Snyder <msnyder@vmware.com>
(Add record dump/load commands: draft version, not ready for release). (Add record dump/load commands: draft version, not ready for release).

View File

@@ -1252,6 +1252,14 @@ cmd_record_dump (char *args, int from_tty)
struct gdbarch *gdbarch; struct gdbarch *gdbarch;
struct cleanup *old_cleanups; struct cleanup *old_cleanups;
struct cleanup *set_cleanups; struct cleanup *set_cleanups;
extern void write_gcore_file (bfd *);
extern bfd *create_gcore_bfd (char *);
bfd *obfd;
int dump_size = 0;
asection *osec = NULL;
struct record_entry *p;
int bfd_offset = 0;
if (current_target.to_stratum != record_stratum) if (current_target.to_stratum != record_stratum)
error (_("Process record is not started.\n")); error (_("Process record is not started.\n"));
@@ -1271,16 +1279,6 @@ cmd_record_dump (char *args, int from_tty)
_("Saving recording to file '%s'\n"), _("Saving recording to file '%s'\n"),
recfilename); recfilename);
/* Michael-style, elf core dump file. */
{
extern void write_gcore_file (bfd *);
extern bfd *create_gcore_bfd (char *);
bfd *obfd;
int dump_size = 0;
asection *osec = NULL;
struct record_entry *p;
int bfd_offset = 0;
/* Open the output file. */ /* Open the output file. */
obfd = create_gcore_bfd (recfilename); obfd = create_gcore_bfd (recfilename);
@@ -1300,9 +1298,7 @@ cmd_record_dump (char *args, int from_tty)
/* Reverse execute to the begin of record list. */ /* Reverse execute to the begin of record list. */
for (; record_list && record_list != &record_first; for (; record_list && record_list != &record_first;
record_list = record_list->prev) record_list = record_list->prev)
{
record_exec_entry (regcache, gdbarch, record_list); record_exec_entry (regcache, gdbarch, record_list);
}
/* Compute the size needed for the extra bfd section. */ /* Compute the size needed for the extra bfd section. */
dump_size = 4; /* magic cookie */ dump_size = 4; /* magic cookie */
@@ -1440,12 +1436,10 @@ cmd_record_dump (char *args, int from_tty)
for (record_list = &record_first; for (record_list = &record_first;
record_list && record_list != cur_record_list; record_list && record_list != cur_record_list;
record_list = record_list->next) record_list = record_list->next)
{
record_exec_entry (regcache, gdbarch, record_list); record_exec_entry (regcache, gdbarch, record_list);
}
/* Clean-ups will close the output file and free malloc memory. */ /* Clean-ups will close the output file and free malloc memory. */
do_cleanups (old_cleanups); do_cleanups (old_cleanups);
}
/* Succeeded. */ /* Succeeded. */
fprintf_filtered (gdb_stdout, "Saved recfile %s.\n", recfilename); fprintf_filtered (gdb_stdout, "Saved recfile %s.\n", recfilename);
@@ -1476,6 +1470,9 @@ cmd_record_load (char *args, int from_tty)
struct cleanup *old_cleanups2; struct cleanup *old_cleanups2;
struct record_entry *rec; struct record_entry *rec;
int insn_number = 0; int insn_number = 0;
bfd *core_bfd;
asection *osec;
extern bfd *load_corefile (char *, int);
if (!args || (args && !*args)) if (!args || (args && !*args))
error (_("Argument for filename required.\n")); error (_("Argument for filename required.\n"));
@@ -1484,12 +1481,6 @@ cmd_record_load (char *args, int from_tty)
if (record_debug) if (record_debug)
fprintf_unfiltered (gdb_stdlog, fprintf_unfiltered (gdb_stdlog,
_("Restoring recording from file '%s'\n"), args); _("Restoring recording from file '%s'\n"), args);
#if 1
/* Michael-style elf core dump file. */
{
bfd *core_bfd;
asection *osec;
extern bfd *load_corefile (char *, int);
/* Restore corefile regs and mem sections. */ /* Restore corefile regs and mem sections. */
core_bfd = load_corefile (args, from_tty); core_bfd = load_corefile (args, from_tty);
@@ -1505,7 +1496,8 @@ cmd_record_load (char *args, int from_tty)
int i, len; int i, len;
int bfd_offset = 0; int bfd_offset = 0;
printf_filtered ("osec name = '%s'\n", if (record_debug)
fprintf_unfiltered (gdb_stdlog, "osec name = '%s'\n",
bfd_section_name (core_bfd, osec)); bfd_section_name (core_bfd, osec));
len = (int) bfd_section_size (core_bfd, osec); len = (int) bfd_section_size (core_bfd, osec);
printf_filtered ("osec size = %d\n", len); printf_filtered ("osec size = %d\n", len);
@@ -1531,12 +1523,11 @@ cmd_record_load (char *args, int from_tty)
printf_unfiltered (_("Auto start process record.\n")); printf_unfiltered (_("Auto start process record.\n"));
} }
/* Load the entries in recfd to the record_arch_list_head and /* Free any existing record log, and load the entries in
record_arch_list_tail. */ core_bfd to the new record log. */
/* FIXME free old records? */
record_list_release (record_arch_list_tail); record_list_release (record_arch_list_tail);
record_arch_list_head = NULL; record_arch_list_head = 0;
record_arch_list_tail = NULL; record_arch_list_tail = 0;
old_cleanups2 = make_cleanup (record_message_cleanups, 0); old_cleanups2 = make_cleanup (record_message_cleanups, 0);
while (1) while (1)
@@ -1544,6 +1535,7 @@ cmd_record_load (char *args, int from_tty)
uint8_t tmpu8; uint8_t tmpu8;
uint64_t tmpu64; uint64_t tmpu64;
/* FIXME: Check offset for end-of-section. */
if (!bfdcore_read (core_bfd, osec, &tmpu8, if (!bfdcore_read (core_bfd, osec, &tmpu8,
sizeof (tmpu8), &bfd_offset)) sizeof (tmpu8), &bfd_offset))
break; break;
@@ -1641,7 +1633,6 @@ cmd_record_load (char *args, int from_tty)
default: default:
error (_("Format of '%s' is not right."), args); error (_("Format of '%s' is not right."), args);
break; break;
} }
} }
} }
@@ -1663,152 +1654,7 @@ cmd_record_load (char *args, int from_tty)
} }
do_cleanups (old_cleanups); do_cleanups (old_cleanups);
}
#endif
#if 0
/* Hui-style binary dump file. */
recfd = open (args, O_RDONLY | O_BINARY);
if (recfd < 0)
error (_("Failed to open '%s' for load."), args);
old_cleanups = make_cleanup (cmd_record_fd_cleanups, &recfd);
/* Check the magic code. */
if (read (recfd, &magic, 4) != 4)
error (_("Failed to read '%s' for load."), args);
if (magic != RECORD_FILE_MAGIC)
error (_("'%s' is not a record dump."), args);
if (record_debug)
fprintf_unfiltered (gdb_stdlog, _("\
Reading 4-byte magic cookie RECORD_FILE_MAGIC (0x%08x)\n"),
magic);
if (current_target.to_stratum != record_stratum)
{
/* FIXME need cleanup! We might error out. */
cmd_record_start (NULL, from_tty);
printf_unfiltered (_("Auto start process record.\n"));
}
/* Load the entries in recfd to the record_arch_list_head and
record_arch_list_tail. */
record_arch_list_head = NULL;
record_arch_list_tail = NULL;
old_cleanups2 = make_cleanup (record_message_cleanups, 0);
while (1)
{
int ret;
uint8_t tmpu8;
uint64_t tmpu64;
ret = read (recfd, &tmpu8, 1);
if (ret < 0)
error (_("Failed to read '%s' for load."), args);
if (ret == 0)
break;
switch (tmpu8)
{
case record_reg: /* reg */
/* FIXME: abstract out into an 'insert' function. */
rec = (struct record_entry *) xmalloc (sizeof (struct record_entry));
rec->u.reg.val = (gdb_byte *) xcalloc (1, MAX_REGISTER_SIZE);
rec->prev = NULL;
rec->next = NULL;
rec->type = record_reg;
/* Get num. */
/* FIXME: register num does not need 8 bytes. */
if (read (recfd, &tmpu64, 8) != 8)
error (_("Failed to read '%s' for load."), args);
if (BYTE_ORDER == LITTLE_ENDIAN)
tmpu64 = bswap_64 (tmpu64);
rec->u.reg.num = tmpu64;
/* Get val. */
if (read (recfd, rec->u.reg.val,
MAX_REGISTER_SIZE) != MAX_REGISTER_SIZE)
error (_("Failed to read '%s' for load."), args);
if (record_debug)
fprintf_unfiltered (gdb_stdlog, _("\
Reading register %d val 0x%016llx (1 plus 8 plus %d bytes)\n"),
rec->u.reg.num,
*(ULONGEST *) rec->u.reg.val,
MAX_REGISTER_SIZE);
record_arch_list_add (rec);
break;
case record_mem: /* mem */
rec = (struct record_entry *) xmalloc (sizeof (struct record_entry));
rec->prev = NULL;
rec->next = NULL;
rec->type = record_mem;
/* Get addr. */
if (read (recfd, &tmpu64, 8) != 8)
error (_("Failed to read '%s' for load."), args);
if (BYTE_ORDER == LITTLE_ENDIAN)
tmpu64 = bswap_64 (tmpu64);
rec->u.mem.addr = tmpu64;
/* Get len. */
/* FIXME: len does not need 8 bytes. */
if (read (recfd, &tmpu64, 8) != 8)
error (_("Failed to read '%s' for load."), args);
if (BYTE_ORDER == LITTLE_ENDIAN)
tmpu64 = bswap_64 (tmpu64);
rec->u.mem.len = tmpu64;
rec->u.mem.mem_entry_not_accessible = 0;
rec->u.mem.val = (gdb_byte *) xmalloc (rec->u.mem.len);
/* Get val. */
if (read (recfd, rec->u.mem.val,
rec->u.mem.len) != rec->u.mem.len)
error (_("Failed to read '%s' for load."), args);
if (record_debug)
fprintf_unfiltered (gdb_stdlog, _("\
Reading memory 0x%08x (1 plus 8 plus %d bytes)\n"),
(unsigned int) rec->u.mem.addr,
rec->u.mem.len);
record_arch_list_add (rec);
break;
case record_end: /* end */
/* FIXME: restore the contents of record_end rec. */
rec = (struct record_entry *) xmalloc (sizeof (struct record_entry));
rec->prev = NULL;
rec->next = NULL;
rec->type = record_end;
if (record_debug)
fprintf_unfiltered (gdb_stdlog, _("\
Reading record_end (one byte)\n"));
record_arch_list_add (rec);
insn_number ++;
break;
default:
error (_("Format of '%s' is not right."), args);
break;
}
}
discard_cleanups (old_cleanups2);
/* Add record_arch_list_head to the end of record list. */
for (rec = record_list; rec->next; rec = rec->next);
rec->next = record_arch_list_head;
record_arch_list_head->prev = rec;
/* Update record_insn_num and record_insn_max_num. */
record_insn_num += insn_number;
if (record_insn_num > record_insn_max_num)
{
record_insn_max_num = record_insn_num;
warning (_("Auto increase record/replay buffer limit to %d."),
record_insn_max_num);
}
do_cleanups (old_cleanups);
#endif
/* Succeeded. */ /* Succeeded. */
fprintf_filtered (gdb_stdout, "Loaded recfile %s.\n", args); fprintf_filtered (gdb_stdout, "Loaded recfile %s.\n", args);
registers_changed (); registers_changed ();