/* Dump-to-file commands, for GDB, the GNU debugger.
- Copyright 2002, 2005 Free Software Foundation, Inc.
+ Copyright (c) 2002, 2005, 2007, 2008, 2009, 2010
+ Free Software Foundation, Inc.
Contributed by Red Hat.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 2 of the License, or
+ the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
- along with this program; if not, write to the Free Software
- Foundation, Inc., 59 Temple Place - Suite 330,
- Boston, MA 02111-1307, USA. */
+ along with this program. If not, see <http://www.gnu.org/licenses/>. */
#include "defs.h"
#include "gdb_string.h"
#include <ctype.h>
#include "target.h"
#include "readline/readline.h"
+#include "gdbcore.h"
#define XMALLOC(TYPE) ((TYPE*) xmalloc (sizeof (TYPE)))
if ((*cmd) == NULL || (**cmd) == '\0')
{
char *exp = xstrdup (def);
+
make_cleanup (xfree, exp);
return exp;
}
}
-static void
-do_fclose_cleanup (void *arg)
-{
- FILE *file = arg;
- fclose (arg);
-}
-
-static struct cleanup *
-make_cleanup_fclose (FILE *file)
-{
- return make_cleanup (do_fclose_cleanup, file);
-}
-
char *
scan_filename_with_cleanup (char **cmd, const char *defname)
{
fopen_with_cleanup (const char *filename, const char *mode)
{
FILE *file = fopen (filename, mode);
+
if (file == NULL)
perror_with_name (filename);
make_cleanup_fclose (file);
void *buf;
char *lo_exp;
char *hi_exp;
- int len;
/* Open the file. */
filename = scan_filename_with_cleanup (&cmd, NULL);
value. */
buf = xmalloc (count);
make_cleanup (xfree, buf);
- target_read_memory (lo, buf, count);
+ read_memory (lo, buf, count);
/* Have everything. Open/write the data. */
if (file_format == NULL || strcmp (file_format, "binary") == 0)
if (VALUE_LVAL (val))
{
- vaddr = VALUE_ADDRESS (val);
+ vaddr = value_address (val);
}
else
{
call_dump_func (struct cmd_list_element *c, char *args, int from_tty)
{
struct dump_context *d = get_cmd_context (c);
+
d->func (args, d->mode);
}
&& c->doc[3] == 't'
&& c->doc[4] == 'e'
&& c->doc[5] == ' ')
- c->doc = concat ("Append ", c->doc + 6, NULL);
+ c->doc = concat ("Append ", c->doc + 6, (char *)NULL);
}
/* Opaque data for restore_section_callback. */
struct callback_data {
- unsigned long load_offset;
+ CORE_ADDR load_offset;
CORE_ADDR load_start;
CORE_ADDR load_end;
};
(unsigned long) sec_end);
if (data->load_offset != 0 || data->load_start != 0 || data->load_end != 0)
- printf_filtered (" into memory (0x%s to 0x%s)\n",
- paddr_nz ((unsigned long) sec_start
+ printf_filtered (" into memory (%s to %s)\n",
+ paddress (target_gdbarch,
+ (unsigned long) sec_start
+ sec_offset + data->load_offset),
- paddr_nz ((unsigned long) sec_start + sec_offset
- + data->load_offset + sec_load_count));
+ paddress (target_gdbarch,
+ (unsigned long) sec_start + sec_offset
+ + data->load_offset + sec_load_count));
else
puts_filtered ("\n");
restore_binary_file (char *filename, struct callback_data *data)
{
FILE *file = fopen_with_cleanup (filename, FOPEN_RB);
- int status;
gdb_byte *buf;
long len;
printf_filtered
("Restoring binary file %s into memory (0x%lx to 0x%lx)\n",
filename,
- (unsigned long) data->load_start + data->load_offset,
- (unsigned long) data->load_start + data->load_offset + len);
+ (unsigned long) (data->load_start + data->load_offset),
+ (unsigned long) (data->load_start + data->load_offset + len));
/* Now set the file pos to the requested load start pos. */
if (fseek (file, data->load_start, SEEK_SET) != 0)
/* Parse offset (optional). */
if (args != NULL && *args != '\0')
data.load_offset =
- parse_and_eval_long (scan_expression_with_cleanup (&args, NULL));
+ parse_and_eval_address (scan_expression_with_cleanup (&args, NULL));
if (args != NULL && *args != '\0')
{
/* Parse start address (optional). */
_initialize_cli_dump (void)
{
struct cmd_list_element *c;
+
add_prefix_cmd ("dump", class_vars, dump_command, _("\
Dump target code/data to a local file."),
&dump_cmdlist, "dump ",