X-Git-Url: http://drtracing.org/?a=blobdiff_plain;f=gdb%2Fcli%2Fcli-dump.c;h=34d805cca5a1b1b59bec067528931323239aed45;hb=cdb27c12f30352674694895e06f615fd28ebdbec;hp=295e2eb84ca26a8a5333fe4a8bba6d74ba272b16;hpb=eefe576e605babfb4b79cd52576c395302245604;p=deliverable%2Fbinutils-gdb.git diff --git a/gdb/cli/cli-dump.c b/gdb/cli/cli-dump.c index 295e2eb84c..34d805cca5 100644 --- a/gdb/cli/cli-dump.c +++ b/gdb/cli/cli-dump.c @@ -1,6 +1,7 @@ /* 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. @@ -8,7 +9,7 @@ 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, @@ -17,9 +18,7 @@ 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 . */ #include "defs.h" #include "gdb_string.h" @@ -32,6 +31,7 @@ #include #include "target.h" #include "readline/readline.h" +#include "gdbcore.h" #define XMALLOC(TYPE) ((TYPE*) xmalloc (sizeof (TYPE))) @@ -52,6 +52,7 @@ scan_expression_with_cleanup (char **cmd, const char *def) if ((*cmd) == NULL || (**cmd) == '\0') { char *exp = xstrdup (def); + make_cleanup (xfree, exp); return exp; } @@ -69,19 +70,6 @@ scan_expression_with_cleanup (char **cmd, const char *def) } -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) { @@ -121,6 +109,7 @@ FILE * 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); @@ -218,7 +207,9 @@ dump_bfd_file (const char *filename, const char *mode, bfd_set_section_size (obfd, osection, len); bfd_set_section_vma (obfd, osection, vaddr); bfd_set_section_alignment (obfd, osection, 0); - bfd_set_section_flags (obfd, osection, 0x203); + bfd_set_section_flags (obfd, osection, (SEC_HAS_CONTENTS + | SEC_ALLOC + | SEC_LOAD)); osection->entsize = 0; bfd_set_section_contents (obfd, osection, buf, 0, len); } @@ -234,7 +225,6 @@ dump_memory_to_file (char *cmd, char *mode, char *file_format) void *buf; char *lo_exp; char *hi_exp; - int len; /* Open the file. */ filename = scan_filename_with_cleanup (&cmd, NULL); @@ -259,7 +249,7 @@ dump_memory_to_file (char *cmd, char *mode, char *file_format) 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) @@ -309,7 +299,7 @@ dump_value_to_file (char *cmd, char *mode, char *file_format) if (VALUE_LVAL (val)) { - vaddr = VALUE_ADDRESS (val); + vaddr = value_address (val); } else { @@ -401,6 +391,7 @@ static void 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); } @@ -436,12 +427,12 @@ add_dump_command (char *name, void (*func) (char *args, char *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; }; @@ -461,7 +452,7 @@ restore_section_callback (bfd *ibfd, asection *isec, void *args) bfd_size_type sec_offset = 0; bfd_size_type sec_load_count = size; struct cleanup *old_chain; - char *buf; + gdb_byte *buf; int ret; /* Ignore non-loadable sections, eg. from elf files. */ @@ -501,11 +492,13 @@ restore_section_callback (bfd *ibfd, asection *isec, void *args) (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"); @@ -522,8 +515,7 @@ static void restore_binary_file (char *filename, struct callback_data *data) { FILE *file = fopen_with_cleanup (filename, FOPEN_RB); - int status; - char *buf; + gdb_byte *buf; long len; /* Get the file size for reading. */ @@ -546,8 +538,8 @@ restore_binary_file (char *filename, struct callback_data *data) 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) @@ -597,7 +589,7 @@ restore_command (char *args, int from_tty) /* 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). */ @@ -675,6 +667,7 @@ void _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 ",