/* Dump-to-file commands, for GDB, the GNU debugger.
- Copyright 2002 Free Software Foundation, Inc.
+ Copyright 2002, 2005 Free Software Foundation, Inc.
Contributed by Red Hat.
#include "gdb_assert.h"
#include <ctype.h>
#include "target.h"
+#include "readline/readline.h"
#define XMALLOC(TYPE) ((TYPE*) xmalloc (sizeof (TYPE)))
}
FILE *
-fopen_with_cleanup (char *filename, const char *mode)
+fopen_with_cleanup (const char *filename, const char *mode)
{
FILE *file = fopen (filename, mode);
if (file == NULL)
{
bfd *ibfd;
- if ((ibfd = bfd_openr (filename, target)) == NULL)
+ ibfd = bfd_openr (filename, target);
+ if (ibfd == NULL)
error ("Failed to open %s: %s.", filename,
bfd_errmsg (bfd_get_error ()));
}
static bfd *
-bfd_openw_with_cleanup (char *filename, const char *target, char *mode)
+bfd_openw_with_cleanup (const char *filename, const char *target,
+ const char *mode)
{
bfd *obfd;
if (*mode == 'w') /* Write: create new file */
{
- if ((obfd = bfd_openw (filename, target)) == NULL)
+ obfd = bfd_openw (filename, target);
+ if (obfd == NULL)
error ("Failed to open %s: %s.", filename,
bfd_errmsg (bfd_get_error ()));
make_cleanup_bfd_close (obfd);
}
static void
-dump_binary_file (char *filename, char *mode,
- char *buf, int len)
+dump_binary_file (const char *filename, const char *mode,
+ const bfd_byte *buf, int len)
{
FILE *file;
int status;
}
static void
-dump_bfd_file (char *filename, char *mode,
- char *target, CORE_ADDR vaddr,
- char *buf, int len)
+dump_bfd_file (const char *filename, const char *mode,
+ const char *target, CORE_ADDR vaddr,
+ const bfd_byte *buf, int len)
{
bfd *obfd;
asection *osection;
/* 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)));
+ dump_binary_file (filename, mode, value_contents (val),
+ TYPE_LENGTH (value_type (val)));
}
else
{
}
dump_bfd_file (filename, mode, file_format, vaddr,
- VALUE_CONTENTS (val),
- TYPE_LENGTH (VALUE_TYPE (val)));
+ value_contents (val),
+ TYPE_LENGTH (value_type (val)));
}
do_cleanups (old_cleanups);
dump_value_to_file (cmd, mode, "binary");
}
-static void
-dump_filetype (char *cmd, char *mode, char *filetype)
-{
- char *suffix = cmd;
-
- if (cmd == NULL || *cmd == '\0')
- error ("Missing subcommand: try 'help %s %s'.",
- mode[0] == 'a' ? "append" : "dump",
- filetype);
-
- suffix += strcspn (cmd, " \t");
-
- if (suffix != cmd)
- {
- if (strncmp ("memory", cmd, suffix - cmd) == 0)
- {
- dump_memory_to_file (suffix, mode, filetype);
- return;
- }
- else if (strncmp ("value", cmd, suffix - cmd) == 0)
- {
- dump_value_to_file (suffix, mode, filetype);
- return;
- }
- }
-
- error ("dump %s: unknown subcommand '%s' -- try 'value' or 'memory'.",
- filetype, cmd);
-}
-
static void
dump_srec_memory (char *args, int from_tty)
{
- dump_memory_to_file (args, "w", "srec");
+ dump_memory_to_file (args, FOPEN_WB, "srec");
}
static void
dump_srec_value (char *args, int from_tty)
{
- dump_value_to_file (args, "w", "srec");
+ dump_value_to_file (args, FOPEN_WB, "srec");
}
static void
dump_ihex_memory (char *args, int from_tty)
{
- dump_memory_to_file (args, "w", "ihex");
+ dump_memory_to_file (args, FOPEN_WB, "ihex");
}
static void
dump_ihex_value (char *args, int from_tty)
{
- dump_value_to_file (args, "w", "ihex");
+ dump_value_to_file (args, FOPEN_WB, "ihex");
}
static void
dump_tekhex_memory (char *args, int from_tty)
{
- dump_memory_to_file (args, "w", "tekhex");
+ dump_memory_to_file (args, FOPEN_WB, "tekhex");
}
static void
dump_tekhex_value (char *args, int from_tty)
{
- dump_value_to_file (args, "w", "tekhex");
+ dump_value_to_file (args, FOPEN_WB, "tekhex");
}
static void
dump_binary_memory (char *args, int from_tty)
{
- dump_memory_to_file (args, "w", "binary");
+ dump_memory_to_file (args, FOPEN_WB, "binary");
}
static void
dump_binary_value (char *args, int from_tty)
{
- dump_value_to_file (args, "w", "binary");
+ dump_value_to_file (args, FOPEN_WB, "binary");
}
static void
append_binary_memory (char *args, int from_tty)
{
- dump_memory_to_file (args, "a", "binary");
+ dump_memory_to_file (args, FOPEN_AB, "binary");
}
static void
append_binary_value (char *args, int from_tty)
{
- dump_value_to_file (args, "a", "binary");
+ dump_value_to_file (args, FOPEN_AB, "binary");
}
struct dump_context
c->completer = filename_completer;
d = XMALLOC (struct dump_context);
d->func = func;
- d->mode = "w";
+ d->mode = FOPEN_WB;
set_cmd_context (c, d);
c->func = call_dump_func;
c->completer = filename_completer;
d = XMALLOC (struct dump_context);
d->func = func;
- d->mode = "a";
+ d->mode = FOPEN_AB;
set_cmd_context (c, d);
c->func = call_dump_func;
- /* Replace "Dump " at start of docstring with "Append "
- (borrowed from add_show_from_set). */
+ /* Replace "Dump " at start of docstring with "Append " (borrowed
+ from deprecated_add_show_from_set). */
if ( c->doc[0] == 'W'
&& c->doc[1] == 'r'
&& c->doc[2] == 'i'
(unsigned long) sec_end);
if (data->load_offset != 0 || data->load_start != 0 || data->load_end != 0)
- printf_filtered (" into memory (0x%lx to 0x%lx)\n",
- (unsigned long) sec_start
- + sec_offset + data->load_offset,
- (unsigned long) sec_start + sec_offset
- + data->load_offset + sec_load_count);
+ printf_filtered (" into memory (0x%s to 0x%s)\n",
+ paddr_nz ((unsigned long) sec_start
+ + sec_offset + data->load_offset),
+ paddr_nz ((unsigned long) sec_start + sec_offset
+ + data->load_offset + sec_load_count));
else
puts_filtered ("\n");
static void
restore_binary_file (char *filename, struct callback_data *data)
{
- FILE *file = fopen_with_cleanup (filename, "r");
+ FILE *file = fopen_with_cleanup (filename, FOPEN_RB);
int status;
char *buf;
long len;
/* Parse offset (optional). */
if (args != NULL && *args != '\0')
data.load_offset =
- parse_and_eval_address (scan_expression_with_cleanup (&args,
- NULL));
+ parse_and_eval_long (scan_expression_with_cleanup (&args, NULL));
if (args != NULL && *args != '\0')
{
/* Parse start address (optional). */
data.load_start =
- parse_and_eval_address (scan_expression_with_cleanup (&args,
- NULL));
+ parse_and_eval_long (scan_expression_with_cleanup (&args, NULL));
if (args != NULL && *args != '\0')
{
/* Parse end address (optional). */
- data.load_end = parse_and_eval_address (args);
+ data.load_end = parse_and_eval_long (args);
if (data.load_end <= data.load_start)
error ("Start must be less than end.");
}
help_list (binary_append_cmdlist, "append binary ", -1, gdb_stdout);
}
+extern initialize_file_ftype _initialize_cli_dump; /* -Wmissing-prototypes */
+
void
_initialize_cli_dump (void)
{