/* Dump-to-file commands, for GDB, the GNU debugger.
- Copyright (C) 2002-2013 Free Software Foundation, Inc.
+ Copyright (C) 2002-2014 Free Software Foundation, Inc.
Contributed by Red Hat.
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 "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')
}
-char *
+static char *
scan_filename_with_cleanup (char **cmd, const char *defname)
{
char *filename;
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);
d->func (args, d->mode);
}
-void
+static void
add_dump_command (char *name, void (*func) (char *args, char *mode),
char *descr)
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;
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