From patchwork Tue Nov 27 20:22:46 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pedro Alves X-Patchwork-Id: 30336 Received: (qmail 41766 invoked by alias); 27 Nov 2018 20:23:01 -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 41529 invoked by uid 89); 27 Nov 2018 20:23:00 -0000 Authentication-Results: sourceware.org; auth=none 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, KAM_SHORT, SPF_HELO_PASS autolearn=ham version=3.3.2 spammy=parse.c, parsec, UD:parse.c 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; Tue, 27 Nov 2018 20:22:53 +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 59F53C04959B for ; Tue, 27 Nov 2018 20:22:52 +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 352F55E7AE for ; Tue, 27 Nov 2018 20:22:50 +0000 (UTC) From: Pedro Alves To: gdb-patches@sourceware.org Subject: [PATCH 2/3] Introduce process_stratum_target Date: Tue, 27 Nov 2018 20:22:46 +0000 Message-Id: <20181127202247.7646-3-palves@redhat.com> In-Reply-To: <20181127202247.7646-1-palves@redhat.com> References: <20181127202247.7646-1-palves@redhat.com> This adds a base class that all process_stratum targets inherit from. default_thread_address_space/default_thread_architecture only make sense for process_stratum targets, so they are transformed to process_stratum_target methods/overrides. gdb/ChangeLog: yyyy-mm-dd Pedro Alves * Makefile.in (COMMON_SFILES): Add process-stratum-target.c. * bsd-kvm.c: Include "process-stratum-target.h". (bsd_kvm_target): Now inherits from process_stratum_target. (bsd_kvm_target::bsd_kvm_target): Default it. * corelow.c: Include "process-stratum-target.h". (core_target): Now inherits from process_stratum_target. (core_target::core_target): Don't set to_stratum here. * inf-child.c (inf_child_target::inf_child_target): Delete. * inf-child.h: Include "process-stratum-target.h". (inf_child_target): Inherit from process_stratum_target. (inf_child_target) : Default it. : Delete overrides. * process-stratum-target.c: New file. * process-stratum-target.h: New file. * remote-sim.c: Include "process-stratum-target.h". (gdbsim_target): Inherit from process_stratum_target. : Default it. * remote.c: Include "process-stratum-target.h". (remote_target): Inherit from process_stratum_target. : Default it. * target.c (default_thread_address_space) (default_thread_architecture): Delete. * target.h (target_ops) : Now returns NULL by default. : Ditto. * test-target.h: Include "process-stratum-target.h" instead of "target.h". (test_target_ops): Inherit from process_stratum_target. : Default it. * tracefile.c (tracefile_target::tracefile_target): Delete. * tracefile.h: Include "process-stratum-target.h". (tracefile_target): Inherit from process_stratum_target. : Default it. * target-delegates.c: Regenerate. --- gdb/Makefile.in | 1 + gdb/bsd-kvm.c | 6 ++--- gdb/corelow.c | 5 ++--- gdb/inf-child.c | 5 ----- gdb/inf-child.h | 11 +++------- gdb/process-stratum-target.c | 49 +++++++++++++++++++++++++++++++++++++++++ gdb/process-stratum-target.h | 52 ++++++++++++++++++++++++++++++++++++++++++++ gdb/remote-sim.c | 6 ++--- gdb/remote.c | 8 +++---- gdb/target-delegates.c | 4 ++-- gdb/target.c | 30 ------------------------- gdb/target.h | 13 ++++------- gdb/test-target.h | 10 +++------ gdb/tracefile.c | 5 ----- gdb/tracefile.h | 5 +++-- 15 files changed, 128 insertions(+), 82 deletions(-) create mode 100644 gdb/process-stratum-target.c create mode 100644 gdb/process-stratum-target.h diff --git a/gdb/Makefile.in b/gdb/Makefile.in index 7ec3c0a019..1099d710c9 100644 --- a/gdb/Makefile.in +++ b/gdb/Makefile.in @@ -1075,6 +1075,7 @@ COMMON_SFILES = \ parse.c \ printcmd.c \ probe.c \ + process-stratum-target.c \ producer.c \ progspace.c \ progspace-and-thread.c \ diff --git a/gdb/bsd-kvm.c b/gdb/bsd-kvm.c index af8305f386..977baf9fe9 100644 --- a/gdb/bsd-kvm.c +++ b/gdb/bsd-kvm.c @@ -24,6 +24,7 @@ #include "frame.h" #include "regcache.h" #include "target.h" +#include "process-stratum-target.h" #include "value.h" #include "gdbcore.h" #include "inferior.h" /* for get_exec_file */ @@ -71,11 +72,10 @@ static const target_info bsd_kvm_target_info = { Optionally specify the filename of a core dump.") }; -class bsd_kvm_target final : public target_ops +class bsd_kvm_target final : public process_stratum_target { public: - bsd_kvm_target () - { this->to_stratum = process_stratum; } + bsd_kvm_target () = default; const target_info &info () const override { return bsd_kvm_target_info; } diff --git a/gdb/corelow.c b/gdb/corelow.c index 72f2807640..deabf84def 100644 --- a/gdb/corelow.c +++ b/gdb/corelow.c @@ -31,6 +31,7 @@ #include "command.h" #include "bfd.h" #include "target.h" +#include "process-stratum-target.h" #include "gdbcore.h" #include "gdbthread.h" #include "regcache.h" @@ -61,7 +62,7 @@ static const target_info core_target_info = { N_("Use a core file as a target. Specify the filename of the core file.") }; -class core_target final : public target_ops +class core_target final : public process_stratum_target { public: core_target (); @@ -132,8 +133,6 @@ private: /* per-core data */ core_target::core_target () { - to_stratum = process_stratum; - m_core_gdbarch = gdbarch_from_bfd (core_bfd); /* Find a suitable core file handler to munch on core_bfd */ diff --git a/gdb/inf-child.c b/gdb/inf-child.c index 44aa2f66fb..8cdfa05146 100644 --- a/gdb/inf-child.c +++ b/gdb/inf-child.c @@ -439,11 +439,6 @@ inf_child_target::can_use_agent () return agent_loaded_p (); } -inf_child_target::inf_child_target () -{ - this->to_stratum = process_stratum; -} - /* See inf-child.h. */ void diff --git a/gdb/inf-child.h b/gdb/inf-child.h index 98969bc5fa..d301d398eb 100644 --- a/gdb/inf-child.h +++ b/gdb/inf-child.h @@ -21,15 +21,16 @@ #define INF_CHILD_H #include "target.h" +#include "process-stratum-target.h" /* A prototype child target. The client can override it with local methods. */ class inf_child_target - : public memory_breakpoint_target + : public memory_breakpoint_target { public: - inf_child_target (); + inf_child_target () = default; ~inf_child_target () override = 0; const target_info &info () const override; @@ -69,12 +70,6 @@ public: void post_attach (int) override; - /* We must default these because they must be implemented by any - target that can run. */ - bool can_async_p () override { return false; } - bool supports_non_stop () override { return false; } - bool supports_disable_randomization () override { return false; } - char *pid_to_exec_file (int pid) override; bool has_all_memory () override; diff --git a/gdb/process-stratum-target.c b/gdb/process-stratum-target.c new file mode 100644 index 0000000000..9ce8d3dd47 --- /dev/null +++ b/gdb/process-stratum-target.c @@ -0,0 +1,49 @@ +/* Abstract base class inherited by all process_stratum targets + + Copyright (C) 2018 Free Software Foundation, Inc. + + This file is part of GDB. + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . */ + +#include "defs.h" +#include "process-stratum-target.h" +#include "inferior.h" + +process_stratum_target::~process_stratum_target () +{ +} + +struct address_space * +process_stratum_target::thread_address_space (ptid_t ptid) +{ + /* Fall-back to the "main" address space of the inferior. */ + inferior *inf = find_inferior_ptid (ptid); + + if (inf == NULL || inf->aspace == NULL) + internal_error (__FILE__, __LINE__, + _("Can't determine the current " + "address space of thread %s\n"), + target_pid_to_str (ptid)); + + return inf->aspace; +} + +struct gdbarch * +process_stratum_target::thread_architecture (ptid_t ptid) +{ + inferior *inf = find_inferior_ptid (ptid); + gdb_assert (inf != NULL); + return inf->gdbarch; +} diff --git a/gdb/process-stratum-target.h b/gdb/process-stratum-target.h new file mode 100644 index 0000000000..68f9684378 --- /dev/null +++ b/gdb/process-stratum-target.h @@ -0,0 +1,52 @@ +/* Abstract base class inherited by all process_stratum targets + + Copyright (C) 2018 Free Software Foundation, Inc. + + This file is part of GDB. + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . */ + +#ifndef PROCESS_STRATUM_TARGET_H +#define PROCESS_STRATUM_TARGET_H + +#include "target.h" + +/* Abstract base class inherited by all process_stratum targets. */ + +class process_stratum_target : public target_ops +{ +public: + process_stratum_target () + : target_ops {} + { + to_stratum = process_stratum; + } + + ~process_stratum_target () override = 0; + + /* We must default these because they must be implemented by any + target that can run. */ + bool can_async_p () override { return false; } + bool supports_non_stop () override { return false; } + bool supports_disable_randomization () override { return false; } + + /* This default implementation returns the inferior's address + space. */ + struct address_space *thread_address_space (ptid_t ptid) override; + + /* This default implementation always returns target_gdbarch (). */ + struct gdbarch *thread_architecture (ptid_t ptid) override; +}; + +#endif /* !defined (PROCESS_STRATUM_TARGET_H) */ diff --git a/gdb/remote-sim.c b/gdb/remote-sim.c index 63e41458d7..1ceecaae2c 100644 --- a/gdb/remote-sim.c +++ b/gdb/remote-sim.c @@ -31,6 +31,7 @@ #include #include "terminal.h" #include "target.h" +#include "process-stratum-target.h" #include "gdbcore.h" #include "gdb/callback.h" #include "gdb/remote-sim.h" @@ -82,10 +83,9 @@ static const target_info gdbsim_target_info = { }; struct gdbsim_target final - : public memory_breakpoint_target + : public memory_breakpoint_target { - gdbsim_target () - { to_stratum = process_stratum; } + gdbsim_target () = default; const target_info &info () const override { return gdbsim_target_info; } diff --git a/gdb/remote.c b/gdb/remote.c index 90b5dabc8a..ae35bec451 100644 --- a/gdb/remote.c +++ b/gdb/remote.c @@ -27,6 +27,7 @@ #include "bfd.h" #include "symfile.h" #include "target.h" +#include "process-stratum-target.h" /*#include "terminal.h" */ #include "gdbcmd.h" #include "objfiles.h" @@ -404,13 +405,10 @@ static const target_info remote_target_info = { remote_doc }; -class remote_target : public target_ops +class remote_target : public process_stratum_target { public: - remote_target () - { - to_stratum = process_stratum; - } + remote_target () = default; ~remote_target () override; const target_info &info () const override diff --git a/gdb/target-delegates.c b/gdb/target-delegates.c index eeb5057ce7..1e70823fce 100644 --- a/gdb/target-delegates.c +++ b/gdb/target-delegates.c @@ -2808,7 +2808,7 @@ target_ops::thread_architecture (ptid_t arg0) struct gdbarch * dummy_target::thread_architecture (ptid_t arg0) { - return default_thread_architecture (this, arg0); + return NULL; } struct gdbarch * @@ -2834,7 +2834,7 @@ target_ops::thread_address_space (ptid_t arg0) struct address_space * dummy_target::thread_address_space (ptid_t arg0) { - return default_thread_address_space (this, arg0); + return NULL; } struct address_space * diff --git a/gdb/target.c b/gdb/target.c index 7fad3a9602..8905ce3630 100644 --- a/gdb/target.c +++ b/gdb/target.c @@ -82,16 +82,10 @@ static int default_verify_memory (struct target_ops *self, const gdb_byte *data, CORE_ADDR memaddr, ULONGEST size); -static struct address_space *default_thread_address_space - (struct target_ops *self, ptid_t ptid); - static void tcomplain (void) ATTRIBUTE_NORETURN; static struct target_ops *find_default_run_target (const char *); -static struct gdbarch *default_thread_architecture (struct target_ops *ops, - ptid_t ptid); - static int dummy_find_memory_regions (struct target_ops *self, find_memory_region_ftype ignore1, void *ignore2); @@ -2567,22 +2561,6 @@ target_get_osdata (const char *type) return target_read_stralloc (t, TARGET_OBJECT_OSDATA, type); } -static struct address_space * -default_thread_address_space (struct target_ops *self, ptid_t ptid) -{ - struct inferior *inf; - - /* Fall-back to the "main" address space of the inferior. */ - inf = find_inferior_ptid (ptid); - - if (inf == NULL || inf->aspace == NULL) - internal_error (__FILE__, __LINE__, - _("Can't determine the current " - "address space of thread %s\n"), - target_pid_to_str (ptid)); - - return inf->aspace; -} /* Determine the current address space of thread PTID. */ @@ -3180,14 +3158,6 @@ default_watchpoint_addr_within_range (struct target_ops *target, return addr >= start && addr < start + length; } -static struct gdbarch * -default_thread_architecture (struct target_ops *ops, ptid_t ptid) -{ - inferior *inf = find_inferior_ptid (ptid); - gdb_assert (inf != NULL); - return inf->gdbarch; -} - /* See target.h. */ target_ops * diff --git a/gdb/target.h b/gdb/target.h index e170bbce3c..36f8d5e5a2 100644 --- a/gdb/target.h +++ b/gdb/target.h @@ -882,18 +882,13 @@ struct target_ops to_thread_architecture would return SPU, otherwise PPC32 or PPC64). This is architecture used to perform decr_pc_after_break adjustment, and also determines the frame architecture of the innermost frame. - ptrace operations need to operate according to target_gdbarch (). - - The default implementation always returns target_gdbarch (). */ + ptrace operations need to operate according to target_gdbarch (). */ virtual struct gdbarch *thread_architecture (ptid_t) - TARGET_DEFAULT_FUNC (default_thread_architecture); - - /* Determine current address space of thread PTID. + TARGET_DEFAULT_RETURN (NULL); - The default implementation always returns the inferior's - address space. */ + /* Determine current address space of thread PTID. */ virtual struct address_space *thread_address_space (ptid_t) - TARGET_DEFAULT_FUNC (default_thread_address_space); + TARGET_DEFAULT_RETURN (NULL); /* Target file operations. */ diff --git a/gdb/test-target.h b/gdb/test-target.h index b3170f8265..1286fc1a6e 100644 --- a/gdb/test-target.h +++ b/gdb/test-target.h @@ -20,7 +20,7 @@ #ifndef TEST_TARGET_H #define TEST_TARGET_H -#include "target.h" +#include "process-stratum-target.h" #if GDB_SELF_TEST namespace selftests { @@ -28,14 +28,10 @@ namespace selftests { /* A mock process_stratum target_ops that doesn't read/write registers anywhere. */ -class test_target_ops : public target_ops +class test_target_ops : public process_stratum_target { public: - test_target_ops () - : target_ops {} - { - to_stratum = process_stratum; - } + test_target_ops () = default; const target_info &info () const override; diff --git a/gdb/tracefile.c b/gdb/tracefile.c index b367f6e403..88e79f7958 100644 --- a/gdb/tracefile.c +++ b/gdb/tracefile.c @@ -470,11 +470,6 @@ tracefile_target::get_trace_status (struct trace_status *ts) return -1; } -tracefile_target::tracefile_target () -{ - this->to_stratum = process_stratum; -} - void _initialize_tracefile (void) { diff --git a/gdb/tracefile.h b/gdb/tracefile.h index 47f8bee8f2..3ae3e7d0e5 100644 --- a/gdb/tracefile.h +++ b/gdb/tracefile.h @@ -3,6 +3,7 @@ #include "tracepoint.h" #include "target.h" +#include "process-stratum-target.h" struct trace_file_writer; @@ -116,10 +117,10 @@ extern struct trace_file_writer *tfile_trace_file_writer_new (void); /* Base class for tracefile related targets. */ -class tracefile_target : public target_ops +class tracefile_target : public process_stratum_target { public: - tracefile_target (); + tracefile_target () = default; int get_trace_status (trace_status *ts) override; bool has_all_memory () override;