2002-02-10 Daniel Jacobowitz <drow@mvista.com>
[deliverable/binutils-gdb.git] / gdb / corefile.c
index cc51109c9c4bc2e1b12344dd315b6b963058ce5e..7acbd6eb5670493b2cd44174bf719b62cde975a2 100644 (file)
@@ -1,5 +1,6 @@
 /* Core dump and executable file functions above target vector, for GDB.
-   Copyright 1986, 1987, 1989, 1991-1994, 2000
+   Copyright 1986, 1987, 1989, 1991, 1992, 1993, 1994, 1996, 1997, 1998,
+   1999, 2000, 2001
    Free Software Foundation, Inc.
 
    This file is part of GDB.
 #include <errno.h>
 #include <signal.h>
 #include <fcntl.h>
-#include "frame.h"             /* required by inferior.h */
 #include "inferior.h"
 #include "symtab.h"
 #include "command.h"
 #include "gdbcmd.h"
-#include "symfile.h"
 #include "bfd.h"
 #include "target.h"
 #include "gdbcore.h"
 #include "dis-asm.h"
-#include "language.h"
 #include "gdb_stat.h"
-#include "symfile.h"
-#include "objfiles.h"
 #include "completer.h"
 
 /* Local function declarations.  */
@@ -74,35 +70,13 @@ core_file_command (char *filename, int from_tty)
   dont_repeat ();              /* Either way, seems bogus. */
 
   t = find_core_target ();
-  if (t != NULL)
-    if (!filename)
-      (t->to_detach) (filename, from_tty);
-    else
-      {
-       /* Yes, we were given the path of a core file.  Do we already
-          have a symbol file?  If not, can we determine it from the
-          core file?  If we can, do so.
-        */
-#ifdef HPUXHPPA
-       if (symfile_objfile == NULL)
-         {
-           char *symfile;
-           symfile = t->to_core_file_to_sym_file (filename);
-           if (symfile)
-             {
-               char *symfile_copy = xstrdup (symfile);
-
-               make_cleanup (xfree, symfile_copy);
-               symbol_file_add_main (symfile_copy, from_tty);
-             }
-           else
-             warning ("Unknown symbols for '%s'; use the 'symbol-file' command.", filename);
-         }
-#endif
-       (t->to_open) (filename, from_tty);
-      }
-  else
+  if (t == NULL)
     error ("GDB can't read core files on this machine.");
+
+  if (!filename)
+    (t->to_detach) (filename, from_tty);
+  else
+    (t->to_open) (filename, from_tty);
 }
 \f
 
@@ -286,18 +260,42 @@ dis_asm_print_address (bfd_vma addr, struct disassemble_info *info)
   print_address (addr, info->stream);
 }
 
-/* Same as target_write_memory, but report an error if can't write.  */
-void
-write_memory (CORE_ADDR memaddr, char *myaddr, int len)
+/* Read an integer from debugged memory, given address and number of bytes.  */
+
+struct captured_read_memory_integer_arguments
 {
-  int status;
+  CORE_ADDR memaddr;
+  int len;
+  LONGEST result;
+};
 
-  status = target_write_memory (memaddr, myaddr, len);
-  if (status != 0)
-    memory_error (status, memaddr);
+static int
+do_captured_read_memory_integer (void *data)
+{
+  struct captured_read_memory_integer_arguments *args = (struct captured_read_memory_integer_arguments*) data;
+  CORE_ADDR memaddr = args->memaddr;
+  int len = args->len;
+
+  args->result = read_memory_integer (memaddr, len);
+
+  return 0;
 }
 
-/* Read an integer from debugged memory, given address and number of bytes.  */
+int
+safe_read_memory_integer (CORE_ADDR memaddr, int len, LONGEST *return_value)
+{
+  int status;
+  struct captured_read_memory_integer_arguments args;
+  args.memaddr = memaddr;
+  args.len = len;
+
+  status = catch_errors (do_captured_read_memory_integer, &args,
+                        "", RETURN_MASK_ALL);
+  if (!status)
+    *return_value = args.result;
+
+  return status;
+}
 
 LONGEST
 read_memory_integer (CORE_ADDR memaddr, int len)
@@ -343,6 +341,36 @@ read_memory_string (CORE_ADDR memaddr, char *buffer, int max_len)
        break;
     }
 }
+
+/* Same as target_write_memory, but report an error if can't write.  */
+void
+write_memory (CORE_ADDR memaddr, char *myaddr, int len)
+{
+  int status;
+
+  status = target_write_memory (memaddr, myaddr, len);
+  if (status != 0)
+    memory_error (status, memaddr);
+}
+
+/* Store VALUE at ADDR in the inferior as a LEN-byte unsigned integer.  */
+void
+write_memory_unsigned_integer (CORE_ADDR addr, int len, ULONGEST value)
+{
+  char *buf = alloca (len);
+  store_unsigned_integer (buf, len, value);
+  write_memory (addr, buf, len);
+}
+
+/* Store VALUE at ADDR in the inferior as a LEN-byte signed integer.  */
+void
+write_memory_signed_integer (CORE_ADDR addr, int len, LONGEST value)
+{
+  char *buf = alloca (len);
+  store_signed_integer (buf, len, value);
+  write_memory (addr, buf, len);
+}
+
 \f
 
 #if 0
@@ -420,7 +448,7 @@ No arg means have no core file.  This command has been superseded by the\n\
                   "Set the current BFD target.\n\
 Use `set gnutarget auto' to specify automatic detection.",
                   &setlist);
-  c->function.sfunc = set_gnutarget_command;
+  set_cmd_sfunc (c, set_gnutarget_command);
   add_show_from_set (c, &showlist);
 
   if (getenv ("GNUTARGET"))
This page took 0.028204 seconds and 4 git commands to generate.