Ejemplo n.º 1
0
/* FIXME: needs comment: */
static void
dump_memory_to_file(const char *cmd, const char *mode, const char *file_format)
{
  struct cleanup *old_cleanups = make_cleanup(null_cleanup, NULL);
  CORE_ADDR lo;
  CORE_ADDR hi;
  ULONGEST count;
  char *filename;
  void *buf;
  char *lo_exp;
  const char *hi_exp;

  /* Open the file: */
  filename = scan_filename_with_cleanup(&cmd, NULL);

  /* Find the low address: */
  if ((cmd == NULL) || (*cmd == '\0'))
    error(_("Missing start address."));
  lo_exp = scan_expression_with_cleanup(&cmd, NULL);

  /* Find the second address - rest of line: */
  if ((cmd == NULL) || (*cmd == '\0'))
    error(_("Missing stop address."));
  hi_exp = cmd;

  lo = parse_and_eval_address(lo_exp);
  hi = parse_and_eval_address(hi_exp);
  if (hi <= lo)
    error(_("Invalid memory address range (start >= end)."));
  count = (hi - lo);

  /* FIXME: Should use read_memory_partial() and a magic blocking
   * value here: */
  buf = xmalloc((size_t)count);
  make_cleanup(xfree, buf);
  target_read_memory(lo, (gdb_byte *)buf, (int)count);

  /* Have everything.  Open/write the data: */
  if ((file_format == NULL) || (strcmp(file_format, "binary") == 0))
    {
      dump_binary_file(filename, mode, (const bfd_byte *)buf, (int)count);
    }
  else
    {
      dump_bfd_file(filename, mode, file_format, lo,
                    (const bfd_byte *)buf, (int)count);
    }

  do_cleanups(old_cleanups);
}
Ejemplo n.º 2
0
/* FIXME: needs comment: */
static void
dump_value_to_file(const char *cmd, const char *mode, const char *file_format)
{
  struct cleanup *old_cleanups = make_cleanup(null_cleanup, NULL);
  struct value *val;
  char *filename;

  /* Open the file.  */
  filename = scan_filename_with_cleanup(&cmd, NULL);

  /* Find the value: */
  if ((cmd == NULL) || (*cmd == '\0'))
    error(_("No value to %s."), ((*mode == 'a') ? "append" : "dump"));
  val = parse_and_eval(cmd);
  if (val == NULL)
    error(_("Invalid expression."));

  /* Have everything.  Open/write the data: */
  if ((file_format == NULL) || (strcmp(file_format, "binary") == 0))
    {
      dump_binary_file(filename, mode, value_contents(val),
                       TYPE_LENGTH(value_type(val)));
    }
  else
    {
      CORE_ADDR vaddr;

      if (VALUE_LVAL(val))
	{
	  vaddr = VALUE_ADDRESS(val);
	}
      else
	{
	  vaddr = 0;
	  warning(_("value is not an lval: address assumed to be zero"));
	}

      dump_bfd_file(filename, mode, file_format, vaddr,
		    value_contents(val),
		    TYPE_LENGTH(value_type(val)));
    }

  do_cleanups(old_cleanups);
}
Ejemplo n.º 3
0
int main(void)
{
	dump_bfd_file(0, 0, 0, (CORE_ADDR)0xdeadbeef, hello, (int)0x1eadbeef);
	exit(0);
}