2010-05-17 Michael Snyder <msnyder@vmware.com>
[deliverable/binutils-gdb.git] / gdb / cli / cli-dump.c
index e855c4c4d2793fa9d083fc972c550908e7b709b0..34d805cca5a1b1b59bec067528931323239aed45 100644 (file)
@@ -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 <http://www.gnu.org/licenses/>.  */
 
 #include "defs.h"
 #include "gdb_string.h"
@@ -32,6 +31,7 @@
 #include <ctype.h>
 #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);
@@ -236,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);
@@ -261,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)
@@ -311,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
        {
@@ -403,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);
 }
 
@@ -438,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;
 };
@@ -503,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");
 
@@ -524,7 +515,6 @@ static void
 restore_binary_file (char *filename, struct callback_data *data)
 {
   FILE *file = fopen_with_cleanup (filename, FOPEN_RB);
-  int status;
   gdb_byte *buf;
   long len;
 
@@ -548,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)
@@ -599,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). */
@@ -677,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 ",
This page took 0.03907 seconds and 4 git commands to generate.