From patchwork Sat Apr 14 19:09:50 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pedro Alves X-Patchwork-Id: 26720 Received: (qmail 125961 invoked by alias); 14 Apr 2018 19:10:24 -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 125887 invoked by uid 89); 14 Apr 2018 19:10:23 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-24.6 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, KAM_LAZY_DOMAIN_SECURITY autolearn=ham version=3.3.2 spammy=events X-HELO: mx1.redhat.com Received: from mx3-rdu2.redhat.com (HELO mx1.redhat.com) (66.187.233.73) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Sat, 14 Apr 2018 19:10:21 +0000 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id D96E48DC4F for ; Sat, 14 Apr 2018 19:10:18 +0000 (UTC) Received: from localhost.localdomain (ovpn04.gateway.prod.ext.ams2.redhat.com [10.39.146.4]) by smtp.corp.redhat.com (Postfix) with ESMTP id 89CA3215CDC8 for ; Sat, 14 Apr 2018 19:10:18 +0000 (UTC) From: Pedro Alves To: gdb-patches@sourceware.org Subject: [PATCH 37/40] target_ops/C++: The Hurd Date: Sat, 14 Apr 2018 20:09:50 +0100 Message-Id: <20180414190953.24481-38-palves@redhat.com> In-Reply-To: <20180414190953.24481-1-palves@redhat.com> References: <20180414190953.24481-1-palves@redhat.com> Straightforward conversion. Not tested. --- gdb/gnu-nat.c | 101 ++++++++++++++++++++--------------------------------- gdb/gnu-nat.h | 34 ++++++++++++++++-- gdb/i386-gnu-nat.c | 29 +++++++++------ 3 files changed, 87 insertions(+), 77 deletions(-) diff --git a/gdb/gnu-nat.c b/gdb/gnu-nat.c index 8271565a04..89df55fdde 100644 --- a/gdb/gnu-nat.c +++ b/gdb/gnu-nat.c @@ -1461,9 +1461,10 @@ extern "C" int notify_server (mach_msg_header_t *, mach_msg_header_t *); extern "C" int process_reply_server (mach_msg_header_t *, mach_msg_header_t *); /* Wait for something to happen in the inferior, returning what in STATUS. */ -static ptid_t -gnu_wait (struct target_ops *ops, - ptid_t ptid, struct target_waitstatus *status, int options) + +ptid_t +gnu_nat_target::wait (ptid_t ptid, struct target_waitstatus *status, + int options) { struct msg { @@ -1998,9 +1999,8 @@ port_msgs_queued (mach_port_t port) still unprocessed from the last resume we did (any given resume may result in multiple events returned by wait). */ -static void -gnu_resume (struct target_ops *ops, - ptid_t ptid, int step, enum gdb_signal sig) +void +gnu_nat_target::resume (ptid_t ptid, int step, enum gdb_signal sig) { struct proc *step_thread = 0; int resume_all; @@ -2075,8 +2075,8 @@ gnu_resume (struct target_ops *ops, } -static void -gnu_kill_inferior (struct target_ops *ops) +void +gnu_nat_target::kill () { struct proc *task = gnu_current_inf->task; @@ -2090,12 +2090,12 @@ gnu_kill_inferior (struct target_ops *ops) } /* Clean up after the inferior dies. */ -static void -gnu_mourn_inferior (struct target_ops *ops) +void +gnu_nat_target::mourn_inferior () { inf_debug (gnu_current_inf, "rip"); inf_detach (gnu_current_inf); - inf_child_mourn_inferior (ops); + inf_child_target::mourn_inferior (); } @@ -2131,11 +2131,11 @@ gnu_ptrace_me (void) trace_start_error_with_name ("ptrace"); } -static void -gnu_create_inferior (struct target_ops *ops, - const char *exec_file, const std::string &allargs, - char **env, - int from_tty) +void +gnu_nat_target::create_inferior (const char *exec_file, + const std::string &allargs, + char **env, + int from_tty) { struct inf *inf = cur_inf (); int pid; @@ -2155,7 +2155,7 @@ gnu_create_inferior (struct target_ops *ops, inf_attach (inf, pid); - push_target (ops); + push_target (this); inf->pending_execs = 1; inf->nomsg = 1; @@ -2190,8 +2190,8 @@ gnu_create_inferior (struct target_ops *ops, /* Attach to process PID, then initialize for debugging it and wait for the trace-trap that results from attaching. */ -static void -gnu_attach (struct target_ops *ops, const char *args, int from_tty) +void +gnu_nat_target::attach (const char *args, int from_tty) { int pid; char *exec_file; @@ -2220,7 +2220,7 @@ gnu_attach (struct target_ops *ops, const char *args, int from_tty) inf_attach (inf, pid); - push_target (ops); + push_target (this); inferior = current_inferior (); inferior_appeared (inferior, pid); @@ -2254,8 +2254,8 @@ gnu_attach (struct target_ops *ops, const char *args, int from_tty) to work, it may be necessary for the process to have been previously attached. It *might* work if the program was started via fork. */ -static void -gnu_detach (struct target_ops *ops, inferior *inf, int from_tty) +void +gnu_nat_target::detach (inferior *inf, int from_tty) { int pid; @@ -2282,14 +2282,14 @@ gnu_detach (struct target_ops *ops, inferior *inf, int from_tty) } -static void -gnu_stop (struct target_ops *self, ptid_t ptid) +void +gnu_nat_target::stop (ptid_t ptid) { - error (_("to_stop target function not implemented")); + error (_("stop target function not implemented")); } -static int -gnu_thread_alive (struct target_ops *ops, ptid_t ptid) +int +gnu_nat_target::thread_alive (ptid_t ptid) { inf_update_procs (gnu_current_inf); return !!inf_tid_to_thread (gnu_current_inf, @@ -2599,11 +2599,11 @@ gnu_xfer_auxv (gdb_byte *readbuf, const gdb_byte *writebuf, /* Target to_xfer_partial implementation. */ -static enum target_xfer_status -gnu_xfer_partial (struct target_ops *ops, enum target_object object, - const char *annex, gdb_byte *readbuf, - const gdb_byte *writebuf, ULONGEST offset, ULONGEST len, - ULONGEST *xfered_len) +enum target_xfer_status +gnu_nat_target::xfer_partial (enum target_object object, + const char *annex, gdb_byte *readbuf, + const gdb_byte *writebuf, ULONGEST offset, + ULONGEST len, ULONGEST *xfered_len) { switch (object) { @@ -2617,9 +2617,10 @@ gnu_xfer_partial (struct target_ops *ops, enum target_object object, } /* Call FUNC on each memory region in the task. */ -static int -gnu_find_memory_regions (struct target_ops *self, - find_memory_region_ftype func, void *data) + +int +gnu_nat_target::find_memory_regions (find_memory_region_ftype func, + void *data) { kern_return_t err; task_t task; @@ -2711,8 +2712,8 @@ proc_string (struct proc *proc) return tid_str; } -static const char * -gnu_pid_to_str (struct target_ops *ops, ptid_t ptid) +const char * +gnu_nat_target::pid_to_str (ptid_t ptid) { struct inf *inf = gnu_current_inf; int tid = ptid_get_lwp (ptid); @@ -2730,32 +2731,6 @@ gnu_pid_to_str (struct target_ops *ops, ptid_t ptid) } -/* Create a prototype generic GNU/Hurd target. The client can - override it with local methods. */ - -struct target_ops * -gnu_target (void) -{ - struct target_ops *t = inf_child_target (); - - t->to_attach = gnu_attach; - t->to_attach_no_wait = 1; - t->to_detach = gnu_detach; - t->to_resume = gnu_resume; - t->to_wait = gnu_wait; - t->to_xfer_partial = gnu_xfer_partial; - t->to_find_memory_regions = gnu_find_memory_regions; - t->to_kill = gnu_kill_inferior; - t->to_create_inferior = gnu_create_inferior; - t->to_mourn_inferior = gnu_mourn_inferior; - t->to_thread_alive = gnu_thread_alive; - t->to_pid_to_str = gnu_pid_to_str; - t->to_stop = gnu_stop; - - return t; -} - - /* User task commands. */ static struct cmd_list_element *set_task_cmd_list = 0; diff --git a/gdb/gnu-nat.h b/gdb/gnu-nat.h index fb96b2980d..4189eaf026 100644 --- a/gdb/gnu-nat.h +++ b/gdb/gnu-nat.h @@ -103,8 +103,36 @@ extern int gnu_debug_flag; fprintf_unfiltered (gdb_stdlog, "%s:%d: " msg "\r\n", \ __FILE__ , __LINE__ , ##args); } while (0) -/* Create a prototype generic GNU/Hurd target. The client can - override it with local methods. */ -struct target_ops *gnu_target (void); +/* A prototype generic GNU/Hurd target. The client can override it + with local methods. */ + +struct gnu_nat_target : public inf_child_target +{ + void attach (const char *, int) override; + bool attach_no_wait () override + { return true; } + + void detach (inferior *, int) override; + void resume (ptid_t, int, enum gdb_signal) override; + + ptid_t wait (ptid_t, struct target_waitstatus *, int) override; + enum target_xfer_status xfer_partial (enum target_object object, + const char *annex, + gdb_byte *readbuf, + const gdb_byte *writebuf, + ULONGEST offset, ULONGEST len, + ULONGEST *xfered_len) override; + + int find_memory_regions (find_memory_region_ftype func, void *data) + override; + void kill () override; + + void create_inferior (const char *, const std::string &, + char **, int) override; + void mourn_inferior () override; + int thread_alive (ptid_t ptid) override; + const char *pid_to_str (ptid_t) override; + void stop (ptid_t) override; +}; #endif /* __GNU_NAT_H__ */ diff --git a/gdb/i386-gnu-nat.c b/gdb/i386-gnu-nat.c index f0674158a3..de7d62a269 100644 --- a/gdb/i386-gnu-nat.c +++ b/gdb/i386-gnu-nat.c @@ -54,6 +54,23 @@ static int reg_offset[] = #define REG_ADDR(state, regnum) ((char *)(state) + reg_offset[regnum]) + +/* The i386 GNU Hurd target. */ + +#ifdef i386_DEBUG_STATE +using gnu_base_target = x86_nat_target; +#else +using gnu_base_target = gnu_nat_target; +#endif + +struct i386_gnu_nat_target final : public gnu_base_target +{ + void fetch_registers (struct regcache *, int) override; + void store_registers (struct regcache *, int) override; +}; + +static i386_gnu_nat_target the_i386_gnu_nat_target; + /* Get the whole floating-point state of THREAD and record the values of the corresponding (pseudo) registers. */ @@ -412,14 +429,7 @@ i386_gnu_dr_get_control (void) void _initialize_i386gnu_nat (void) { - struct target_ops *t; - - /* Fill in the generic GNU/Hurd methods. */ - t = gnu_target (); - #ifdef i386_DEBUG_STATE - x86_use_watchpoints (t); - x86_dr_low.set_control = i386_gnu_dr_set_control; gdb_assert (DR_FIRSTADDR == 0 && DR_LASTADDR < i386_DEBUG_STATE_COUNT); x86_dr_low.set_addr = i386_gnu_dr_set_addr; @@ -429,9 +439,6 @@ _initialize_i386gnu_nat (void) x86_set_debug_register_length (4); #endif /* i386_DEBUG_STATE */ - t->to_fetch_registers = gnu_fetch_registers; - t->to_store_registers = gnu_store_registers; - /* Register the target. */ - add_target (t); + add_target (&the_i386_gnu_nat_target); }