Index: gdb/cli/cli-dump.c |
diff --git a/gdb/cli/cli-dump.c b/gdb/cli/cli-dump.c |
index 4a8b5d13b276c07ebf8da8ceba15cd87042d3345..440c7305312dd405b961e199e97aaf6796e89bd7 100644 |
--- a/gdb/cli/cli-dump.c |
+++ b/gdb/cli/cli-dump.c |
@@ -1,6 +1,6 @@ |
/* Dump-to-file commands, for GDB, the GNU debugger. |
- Copyright (c) 2002, 2005, 2007-2012 Free Software Foundation, Inc. |
+ Copyright (C) 2002-2013 Free Software Foundation, Inc. |
Contributed by Red Hat. |
@@ -20,23 +20,22 @@ |
along with this program. If not, see <http://www.gnu.org/licenses/>. */ |
#include "defs.h" |
-#include "gdb_string.h" |
+#include <string.h> |
#include "cli/cli-decode.h" |
#include "cli/cli-cmds.h" |
#include "value.h" |
#include "completer.h" |
-#include "cli/cli-dump.h" |
#include "gdb_assert.h" |
#include <ctype.h> |
#include "target.h" |
#include "readline/readline.h" |
#include "gdbcore.h" |
#include "cli/cli-utils.h" |
+#include "gdb_bfd.h" |
+#include "filestuff.h" |
-#define XMALLOC(TYPE) ((TYPE*) xmalloc (sizeof (TYPE))) |
- |
-char * |
+static char * |
scan_expression_with_cleanup (char **cmd, const char *def) |
{ |
if ((*cmd) == NULL || (**cmd) == '\0') |
@@ -60,7 +59,7 @@ scan_expression_with_cleanup (char **cmd, const char *def) |
} |
-char * |
+static char * |
scan_filename_with_cleanup (char **cmd, const char *defname) |
{ |
char *filename; |
@@ -95,10 +94,10 @@ scan_filename_with_cleanup (char **cmd, const char *defname) |
return fullname; |
} |
-FILE * |
+static FILE * |
fopen_with_cleanup (const char *filename, const char *mode) |
{ |
- FILE *file = fopen (filename, mode); |
+ FILE *file = gdb_fopen_cloexec (filename, mode); |
if (file == NULL) |
perror_with_name (filename); |
@@ -111,12 +110,12 @@ bfd_openr_with_cleanup (const char *filename, const char *target) |
{ |
bfd *ibfd; |
- ibfd = bfd_openr (filename, target); |
+ ibfd = gdb_bfd_openr (filename, target); |
if (ibfd == NULL) |
error (_("Failed to open %s: %s."), filename, |
bfd_errmsg (bfd_get_error ())); |
- make_cleanup_bfd_close (ibfd); |
+ make_cleanup_bfd_unref (ibfd); |
if (!bfd_check_format (ibfd, bfd_object)) |
error (_("'%s' is not a recognized file format."), filename); |
@@ -131,11 +130,11 @@ bfd_openw_with_cleanup (const char *filename, const char *target, |
if (*mode == 'w') /* Write: create new file */ |
{ |
- obfd = bfd_openw (filename, target); |
+ obfd = gdb_bfd_openw (filename, target); |
if (obfd == NULL) |
error (_("Failed to open %s: %s."), filename, |
bfd_errmsg (bfd_get_error ())); |
- make_cleanup_bfd_close (obfd); |
+ make_cleanup_bfd_unref (obfd); |
if (!bfd_set_format (obfd, bfd_object)) |
error (_("bfd_openw_with_cleanup: %s."), bfd_errmsg (bfd_get_error ())); |
} |
@@ -149,13 +148,13 @@ bfd_openw_with_cleanup (const char *filename, const char *target, |
return obfd; |
} |
-struct cmd_list_element *dump_cmdlist; |
-struct cmd_list_element *append_cmdlist; |
-struct cmd_list_element *srec_cmdlist; |
-struct cmd_list_element *ihex_cmdlist; |
-struct cmd_list_element *tekhex_cmdlist; |
-struct cmd_list_element *binary_dump_cmdlist; |
-struct cmd_list_element *binary_append_cmdlist; |
+static struct cmd_list_element *dump_cmdlist; |
+static struct cmd_list_element *append_cmdlist; |
+static struct cmd_list_element *srec_cmdlist; |
+static struct cmd_list_element *ihex_cmdlist; |
+static struct cmd_list_element *tekhex_cmdlist; |
+static struct cmd_list_element *binary_dump_cmdlist; |
+static struct cmd_list_element *binary_append_cmdlist; |
static void |
dump_command (char *cmd, int from_tty) |
@@ -387,7 +386,7 @@ call_dump_func (struct cmd_list_element *c, char *args, int from_tty) |
d->func (args, d->mode); |
} |
-void |
+static void |
add_dump_command (char *name, void (*func) (char *args, char *mode), |
char *descr) |
@@ -485,10 +484,10 @@ restore_section_callback (bfd *ibfd, asection *isec, void *args) |
if (data->load_offset != 0 || data->load_start != 0 || data->load_end != 0) |
printf_filtered (" into memory (%s to %s)\n", |
- paddress (target_gdbarch, |
+ paddress (target_gdbarch (), |
(unsigned long) sec_start |
+ sec_offset + data->load_offset), |
- paddress (target_gdbarch, |
+ paddress (target_gdbarch (), |
(unsigned long) sec_start + sec_offset |
+ data->load_offset + sec_load_count)); |
else |
@@ -506,6 +505,7 @@ restore_section_callback (bfd *ibfd, asection *isec, void *args) |
static void |
restore_binary_file (char *filename, struct callback_data *data) |
{ |
+ struct cleanup *cleanup = make_cleanup (null_cleanup, NULL); |
FILE *file = fopen_with_cleanup (filename, FOPEN_RB); |
gdb_byte *buf; |
long len; |
@@ -551,7 +551,7 @@ restore_binary_file (char *filename, struct callback_data *data) |
len = target_write_memory (data->load_start + data->load_offset, buf, len); |
if (len != 0) |
warning (_("restore: memory write failed (%s)."), safe_strerror (len)); |
- return; |
+ do_cleanups (cleanup); |
} |
static void |