From patchwork Thu Jun 8 09:15:38 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gary Benson X-Patchwork-Id: 20843 Received: (qmail 103838 invoked by alias); 8 Jun 2017 09:24:23 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Delivered-To: mailing list gdb-patches@sourceware.org Received: (qmail 95187 invoked by uid 89); 8 Jun 2017 09:24:04 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-26.9 required=5.0 tests=BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, SPF_HELO_PASS, T_RP_MATCHES_RCVD autolearn=ham version=3.3.2 spammy= X-Spam-User: qpsmtpd, 2 recipients X-HELO: mx1.redhat.com Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Thu, 08 Jun 2017 09:24:02 +0000 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 5601AC057FA7; Thu, 8 Jun 2017 09:15:48 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 5601AC057FA7 Authentication-Results: ext-mx08.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx08.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=gbenson@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 5601AC057FA7 Received: from blade.nx (unknown [10.33.36.53]) by smtp.corp.redhat.com (Postfix) with ESMTP id C7ADD89C4C; Thu, 8 Jun 2017 09:15:47 +0000 (UTC) Received: from blade.com (localhost [127.0.0.1]) by blade.nx (Postfix) with ESMTP id C93848157434; Thu, 8 Jun 2017 10:15:44 +0100 (BST) From: Gary Benson To: gdb-patches@sourceware.org Cc: infinity@sourceware.org Subject: [RFC 5/5] Implement Infinity proc_service functions in GDB Date: Thu, 8 Jun 2017 10:15:38 +0100 Message-Id: <1496913338-22195-6-git-send-email-gbenson@redhat.com> In-Reply-To: <1496913338-22195-1-git-send-email-gbenson@redhat.com> References: <1496913338-22195-1-git-send-email-gbenson@redhat.com> X-IsSubscribed: yes 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; };