public inbox for infinity@sourceware.org
 help / color / mirror / Atom feed
From: Gary Benson <gbenson@redhat.com>
To: gdb-patches@sourceware.org
Cc: infinity@sourceware.org
Subject: [RFC 5/5] Implement Infinity proc_service functions in GDB
Date: Thu, 08 Jun 2017 09:24:00 -0000	[thread overview]
Message-ID: <1496913338-22195-6-git-send-email-gbenson@redhat.com> (raw)
In-Reply-To: <1496913338-22195-1-git-send-email-gbenson@redhat.com>

This commit implements the two new Infinity proc-service functions in
GDB.

gdb/ChangeLog:

	* proc-service.c (ps_get_register): New function.
	(ps_foreach_infinity_note): Likewise.
	(ps_infinity_relocate_addr): New static function.
	* proc-service.list: Add ps_get_register and
	ps_foreach_infinity_note.
---
 gdb/ChangeLog         |  8 +++++
 gdb/proc-service.c    | 94 +++++++++++++++++++++++++++++++++++++++++++++++++++
 gdb/proc-service.list |  2 ++
 3 files changed, 104 insertions(+)

diff --git a/gdb/proc-service.c b/gdb/proc-service.c
index 415ba0a..c3f5b013 100644
--- a/gdb/proc-service.c
+++ b/gdb/proc-service.c
@@ -25,6 +25,7 @@
 #include "target.h"
 #include "regcache.h"
 #include "objfiles.h"
+#include "elf-bfd.h"
 
 #include "gdb_proc_service.h"
 
@@ -218,6 +219,31 @@ ps_lsetfpregs (gdb_ps_prochandle_t ph, lwpid_t lwpid,
   return PS_OK;
 }
 
+/* See gdb_proc_service.h.  */
+
+ps_err_e
+ps_get_register (struct ps_prochandle *ph, lwpid_t lwpid,
+		 int dwarf_reg, psaddr_t *result)
+{
+  struct gdbarch *gdbarch = target_gdbarch ();
+  ptid_t lwp_ptid;
+  struct regcache *regcache;
+  int reg;enum register_status status;
+
+  reg = gdbarch_dwarf2_reg_to_regnum (gdbarch, dwarf_reg);
+  if (reg == -1)
+    {
+      warning (_("Bad DWARF register number %d"), dwarf_reg);
+      return PS_ERR;
+    }
+
+  lwp_ptid = ptid_build (ptid_get_pid (ph->ptid), lwpid, 0);
+  regcache = get_thread_arch_regcache (lwp_ptid, gdbarch);
+  status = regcache_raw_read (regcache, reg, (gdb_byte *) result);
+
+  return status == REG_VALID ? PS_OK : PS_ERR;
+}
+
 /* Return overall process id of the target PH.  Special for GNU/Linux
    -- not used on Solaris.  */
 
@@ -227,6 +253,74 @@ ps_getpid (gdb_ps_prochandle_t ph)
   return ptid_get_pid (ph->ptid);
 }
 
+/* Callback for ps_foreach_infinity_note to relocate addresses in
+   Infinity notes.  */
+
+static ps_err_e
+ps_infinity_relocate_addr (void *objfile_p, psaddr_t unrelocated_p,
+			   psaddr_t *result_p)
+{
+  struct objfile *objfile = (struct objfile *) objfile_p;
+  CORE_ADDR unrelocated = ps_addr_to_core_addr (unrelocated_p);
+  struct obj_section *osect;
+
+  ALL_OBJFILE_OSECTIONS (objfile, osect)
+    {
+      struct bfd_section *sect = osect->the_bfd_section;
+      bfd_vma section_vma = bfd_get_section_vma (objfile->obfd, sect);
+
+      if (unrelocated < section_vma
+	  || unrelocated >= (section_vma + bfd_get_section_size (sect)))
+	continue;
+
+      *result_p = core_addr_to_ps_addr (unrelocated - section_vma
+					+ obj_section_addr (osect));
+
+      return PS_OK;
+    }
+
+  return PS_ERR;
+}
+
+/* See gdb_proc_service.h.  */
+
+ps_err_e
+ps_foreach_infinity_note (struct ps_prochandle *ph,
+			  ps_visit_infinity_note_f *callback,
+			  void *cb_arg)
+{
+  struct cleanup *old_chain = save_current_program_space ();
+  struct inferior *inf = find_inferior_ptid (ph->ptid);
+  struct objfile *objfile;
+  ps_err_e result = PS_OK;
+
+  set_current_program_space (inf->pspace);
+
+  ALL_OBJFILES (objfile)
+    {
+      struct elf_infinity_note *note;
+
+      if (objfile->obfd == NULL
+	  || bfd_get_flavour (objfile->obfd) != bfd_target_elf_flavour)
+	continue;
+
+	for (note = elf_tdata (objfile->obfd)->infinity_note_head;
+	     note != NULL; note = note->next)
+	  {
+	    result = callback (cb_arg,
+			       (const char *) note->data, note->size,
+			       objfile_name (objfile), note->fileoffset,
+			       ps_infinity_relocate_addr, objfile);
+
+	    if (result != PS_OK)
+	      break;
+	  }
+    }
+
+  do_cleanups (old_chain);
+  return result;
+}
+
 /* Provide a prototype to silence -Wmissing-prototypes.  */
 extern initialize_file_ftype _initialize_proc_service;
 
diff --git a/gdb/proc-service.list b/gdb/proc-service.list
index 79c2e5b..903c0d5 100644
--- a/gdb/proc-service.list
+++ b/gdb/proc-service.list
@@ -37,4 +37,6 @@
   ps_pstop;
   ps_ptread;
   ps_ptwrite;
+  ps_foreach_infinity_note;
+  ps_get_register;
 };
-- 
1.8.3.1

  parent reply	other threads:[~2017-06-08  9:24 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-06-08  9:15 [RFC 0/5] New proc_service functionality for Infinity Gary Benson
2017-06-08  9:15 ` [RFC 2/5] Add NT_GNU_INFINITY Gary Benson
2017-06-08  9:15 ` [RFC 1/5] Add FS_BASE and GS_BASE to DWARF register table on amd64 Gary Benson
2017-06-08  9:15 ` [RFC 3/5] Support ELF Infinity notes Gary Benson
2017-06-08  9:24 ` Gary Benson [this message]
2017-06-08  9:24 ` [RFC 4/5] Declare Infinity proc_service functions in gdb_proc_service.h Gary Benson

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1496913338-22195-6-git-send-email-gbenson@redhat.com \
    --to=gbenson@redhat.com \
    --cc=gdb-patches@sourceware.org \
    --cc=infinity@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).