* dsrec.c (load_srec, make_srec): Use bfd_get_section_size instead of
[binutils-gdb.git] / gdb / corelow.c
index d14b3a3455b4eb1faa5955d2c806eb6963f950a1..4c6a40c4c00d4990a1aa19d8f11fcae74f8fb3fc 100644 (file)
@@ -1,7 +1,8 @@
 /* Core dump and executable file functions below target vector, for GDB.
 
    Copyright 1986, 1987, 1989, 1991, 1992, 1993, 1994, 1995, 1996,
-   1997, 1998, 1999, 2000, 2001, 2003 Free Software Foundation, Inc.
+   1997, 1998, 1999, 2000, 2001, 2003, 2004 Free Software Foundation,
+   Inc.
 
    This file is part of GDB.
 
 #include "regset.h"
 #include "symfile.h"
 #include "exec.h"
-#include <readline/readline.h>
-
+#include "readline/readline.h"
+#include "observer.h"
 #include "gdb_assert.h"
 
 #ifndef O_BINARY
 #define O_BINARY 0
 #endif
 
-/* List of all available core_fns.  On gdb startup, each core file register
-   reader calls add_core_fns() to register information on each core format it
-   is prepared to read. */
+/* List of all available core_fns.  On gdb startup, each core file
+   register reader calls deprecated_add_core_fns() to register
+   information on each core format it is prepared to read.  */
 
 static struct core_fns *core_file_fns = NULL;
 
@@ -103,7 +104,7 @@ struct target_ops core_ops;
    handle. */
 
 void
-add_core_fns (struct core_fns *cf)
+deprecated_add_core_fns (struct core_fns *cf)
 {
   cf->next = core_file_fns;
   core_file_fns = cf;
@@ -354,6 +355,10 @@ core_open (char *filename, int from_tty)
   ontop = !push_target (&core_ops);
   discard_cleanups (old_chain);
 
+  /* This is done first, before anything has a chance to query the
+     inferior for information such as symbols.  */
+  observer_notify_inferior_created (&core_ops, from_tty);
+
   p = bfd_core_file_failing_command (core_bfd);
   if (p)
     printf_filtered ("Core was generated by `%s'.\n", p);
@@ -387,8 +392,7 @@ core_open (char *filename, int from_tty)
       /* Now, set up the frame cache, and print the top of stack.  */
       flush_cached_frames ();
       select_frame (get_current_frame ());
-      print_stack_frame (deprecated_selected_frame,
-                        frame_relative_level (deprecated_selected_frame), 1);
+      print_stack_frame (get_selected_frame (), 1, SRC_AND_LOC);
     }
   else
     {
@@ -537,7 +541,7 @@ core_xfer_partial (struct target_ops *ops, enum target_object object,
          /* When the aux vector is stored in core file, BFD
             represents this with a fake section called ".auxv".  */
 
-         sec_ptr section;
+         struct bfd_section *section;
          bfd_size_type size;
          char *contents;
 
@@ -551,9 +555,9 @@ core_xfer_partial (struct target_ops *ops, enum target_object object,
          size -= offset;
          if (size > len)
            size = len;
-         if (size > 0 &&
-             bfd_get_section_contents (core_bfd, section, readbuf,
-                                         (file_ptr) offset, size))
+         if (size > 0
+             && !bfd_get_section_contents (core_bfd, section, readbuf,
+                                           (file_ptr) offset, size))
            {
              warning ("Couldn't read NT_AUXV note in core file.");
              return -1;
@@ -563,6 +567,38 @@ core_xfer_partial (struct target_ops *ops, enum target_object object,
        }
       return -1;
 
+    case TARGET_OBJECT_WCOOKIE:
+      if (readbuf)
+       {
+         /* When the StackGhost cookie is stored in core file, BFD
+            represents this with a fake section called ".wcookie".  */
+
+         struct bfd_section *section;
+         bfd_size_type size;
+         char *contents;
+
+         section = bfd_get_section_by_name (core_bfd, ".wcookie");
+         if (section == NULL)
+           return -1;
+
+         size = bfd_section_size (core_bfd, section);
+         if (offset >= size)
+           return 0;
+         size -= offset;
+         if (size > len)
+           size = len;
+         if (size > 0
+             && !bfd_get_section_contents (core_bfd, section, readbuf,
+                                           (file_ptr) offset, size))
+           {
+             warning ("Couldn't read StackGhost cookie in core file.");
+             return -1;
+           }
+
+         return size;
+       }
+      return -1;
+
     default:
       if (ops->beneath != NULL)
        return ops->beneath->to_xfer_partial (ops->beneath, object, annex,