Automatic date update in version.in
[deliverable/binutils-gdb.git] / gdb / corelow.c
index b32fa955fdab305a812636518e3b7758db57f8f6..5cd058d5993d51fd5abdcdbbf76b92c909b4881a 100644 (file)
@@ -1,6 +1,6 @@
 /* Core dump and executable file functions below target vector, for GDB.
 
-   Copyright (C) 1986-2019 Free Software Foundation, Inc.
+   Copyright (C) 1986-2020 Free Software Foundation, Inc.
 
    This file is part of GDB.
 
@@ -35,7 +35,7 @@
 #include "regset.h"
 #include "symfile.h"
 #include "exec.h"
-#include "readline/readline.h"
+#include "readline/tilde.h"
 #include "solib.h"
 #include "filenames.h"
 #include "progspace.h"
@@ -43,6 +43,8 @@
 #include "gdb_bfd.h"
 #include "completer.h"
 #include "gdbsupport/filestuff.h"
+#include "build-id.h"
+#include "gdbsupport/pathstuff.h"
 
 #ifndef O_LARGEFILE
 #define O_LARGEFILE 0
@@ -92,7 +94,7 @@ public:
   bool has_memory () override;
   bool has_stack () override;
   bool has_registers () override;
-  bool has_execution (ptid_t) override { return false; }
+  bool has_execution (inferior *inf) override { return false; }
 
   bool info_proc (const char *, enum info_proc_what) override;
 
@@ -312,7 +314,7 @@ add_to_thread_list (bfd *abfd, asection *asect, void *reg_sect_arg)
 
   ptid = ptid_t (pid, lwpid, 0);
 
-  add_thread (ptid);
+  add_thread (inf->process_target (), ptid);
 
 /* Warning, Will Robinson, looking at BFD private data! */
 
@@ -351,6 +353,27 @@ core_file_command (const char *filename, int from_tty)
     core_target_open (filename, from_tty);
 }
 
+/* Locate (and load) an executable file (and symbols) given the core file
+   BFD ABFD.  */
+
+static void
+locate_exec_from_corefile_build_id (bfd *abfd, int from_tty)
+{
+  const bfd_build_id *build_id = build_id_bfd_get (abfd);
+  if (build_id == nullptr)
+    return;
+
+  gdb_bfd_ref_ptr execbfd
+    = build_id_to_exec_bfd (build_id->size, build_id->data);
+
+  if (execbfd != nullptr)
+    {
+      exec_file_attach (bfd_get_filename (execbfd.get ()), from_tty);
+      symbol_file_add_main (bfd_get_filename (execbfd.get ()),
+                           symfile_add_flag (from_tty ? SYMFILE_VERBOSE : 0));
+    }
+}
+
 /* See gdbcore.h.  */
 
 void
@@ -373,8 +396,7 @@ core_target_open (const char *arg, int from_tty)
 
   gdb::unique_xmalloc_ptr<char> filename (tilde_expand (arg));
   if (!IS_ABSOLUTE_PATH (filename.get ()))
-    filename.reset (concat (current_directory, "/",
-                           filename.get (), (char *) NULL));
+    filename = gdb_abspath (filename.get ());
 
   flags = O_BINARY | O_LARGEFILE;
   if (write_files)
@@ -450,12 +472,15 @@ core_target_open (const char *arg, int from_tty)
        {
          inferior_appeared (current_inferior (), CORELOW_PID);
          inferior_ptid = ptid_t (CORELOW_PID);
-         add_thread_silent (inferior_ptid);
+         add_thread_silent (target, inferior_ptid);
        }
       else
        switch_to_thread (thread);
     }
 
+  if (exec_bfd == nullptr)
+    locate_exec_from_corefile_build_id (core_bfd, from_tty);
+
   post_create_inferior (target, from_tty);
 
   /* Now go through the target stack looking for threads since there
@@ -515,7 +540,7 @@ core_target_open (const char *arg, int from_tty)
   /* Current thread should be NUM 1 but the user does not know that.
      If a program is single threaded gdb in general does not mention
      anything about threads.  That is why the test is >= 2.  */
-  if (thread_count () >= 2)
+  if (thread_count (target) >= 2)
     {
       try
        {
@@ -569,7 +594,6 @@ core_target::get_core_register_section (struct regcache *regcache,
 {
   struct bfd_section *section;
   bfd_size_type size;
-  char *contents;
   bool variable_size_section = (regset != NULL
                                && regset->flags & REGSET_VARIABLE_SIZE);
 
@@ -597,9 +621,9 @@ core_target::get_core_register_section (struct regcache *regcache,
               section_name.c_str ());
     }
 
-  contents = (char *) alloca (size);
-  if (! bfd_get_section_contents (core_bfd, section, contents,
-                                 (file_ptr) 0, size))
+  gdb::byte_vector contents (size);
+  if (!bfd_get_section_contents (core_bfd, section, contents.data (),
+                                (file_ptr) 0, size))
     {
       warning (_("Couldn't read %s registers from `%s' section in core file."),
               human_name, section_name.c_str ());
@@ -608,12 +632,12 @@ core_target::get_core_register_section (struct regcache *regcache,
 
   if (regset != NULL)
     {
-      regset->supply_regset (regset, regcache, -1, contents, size);
+      regset->supply_regset (regset, regcache, -1, contents.data (), size);
       return;
     }
 
   gdb_assert (m_core_vec != nullptr);
-  m_core_vec->core_read_registers (regcache, contents, size, which,
+  m_core_vec->core_read_registers (regcache, contents.data (), size, which,
                                   (CORE_ADDR) bfd_section_vma (section));
 }
 
@@ -919,7 +943,7 @@ core_target::pid_to_str (ptid_t ptid)
 
   /* Otherwise, this isn't a "threaded" core -- use the PID field, but
      only if it isn't a fake PID.  */
-  inf = find_inferior_ptid (ptid);
+  inf = find_inferior_ptid (this, ptid);
   if (inf != NULL && !inf->fake_pid_p)
     return normal_pid_to_str (ptid);
 
@@ -969,8 +993,9 @@ core_target::info_proc (const char *args, enum info_proc_what request)
   return true;
 }
 
+void _initialize_corelow ();
 void
-_initialize_corelow (void)
+_initialize_corelow ()
 {
   add_target (core_target_info, core_target_open, filename_completer);
 }
This page took 0.032017 seconds and 4 git commands to generate.