diff options
author | Pedro Alves <palves@redhat.com> | 2018-11-30 14:53:39 +0000 |
---|---|---|
committer | Pedro Alves <palves@redhat.com> | 2018-11-30 16:27:26 +0000 |
commit | 3b3dac9b3fd916d73726c7e5508f057574f74d19 (patch) | |
tree | 5691452d3a2a73ab852822297b1b165c8879a5c3 /gdb | |
parent | c180496d2ac268c06c13600f729d02ca4266e6ea (diff) | |
download | fsf-binutils-gdb-3b3dac9b3fd916d73726c7e5508f057574f74d19.zip fsf-binutils-gdb-3b3dac9b3fd916d73726c7e5508f057574f74d19.tar.gz fsf-binutils-gdb-3b3dac9b3fd916d73726c7e5508f057574f74d19.tar.bz2 |
Introduce process_stratum_target
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:
2018-11-30 Pedro Alves <palves@redhat.com>
* 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) <inf_child_target>: Default it.
<can_async_p, supports_non_stop, supports_disable_randomization>:
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.
<gdbsim_target>: Default it.
* remote.c: Include "process-stratum-target.h".
(remote_target): Inherit from process_stratum_target.
<remote_target>: Default it.
* target.c (default_thread_address_space)
(default_thread_architecture): Delete.
* target.h (target_ops) <thread_architecture>: Now returns NULL by
default.
<thread_address_space>: Ditto.
* test-target.h: Include "process-stratum-target.h" instead of
"target.h".
(test_target_ops): Inherit from process_stratum_target.
<test_target_ops>: Default it.
* tracefile.c (tracefile_target::tracefile_target): Delete.
* tracefile.h: Include "process-stratum-target.h".
(tracefile_target): Inherit from process_stratum_target.
<tracefile_target>: Default it.
* target-delegates.c: Regenerate.
Diffstat (limited to 'gdb')
-rw-r--r-- | gdb/ChangeLog | 38 | ||||
-rw-r--r-- | gdb/Makefile.in | 1 | ||||
-rw-r--r-- | gdb/bsd-kvm.c | 6 | ||||
-rw-r--r-- | gdb/corelow.c | 5 | ||||
-rw-r--r-- | gdb/inf-child.c | 5 | ||||
-rw-r--r-- | gdb/inf-child.h | 11 | ||||
-rw-r--r-- | gdb/process-stratum-target.c | 49 | ||||
-rw-r--r-- | gdb/process-stratum-target.h | 51 | ||||
-rw-r--r-- | gdb/remote-sim.c | 6 | ||||
-rw-r--r-- | gdb/remote.c | 8 | ||||
-rw-r--r-- | gdb/target-delegates.c | 4 | ||||
-rw-r--r-- | gdb/target.c | 30 | ||||
-rw-r--r-- | gdb/target.h | 13 | ||||
-rw-r--r-- | gdb/test-target.h | 10 | ||||
-rw-r--r-- | gdb/tracefile.c | 5 | ||||
-rw-r--r-- | gdb/tracefile.h | 5 |
16 files changed, 165 insertions, 82 deletions
diff --git a/gdb/ChangeLog b/gdb/ChangeLog index 49450e3..faed74b 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,5 +1,43 @@ 2018-11-30 Pedro Alves <palves@redhat.com> + * 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) <inf_child_target>: Default it. + <can_async_p, supports_non_stop, supports_disable_randomization>: + 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. + <gdbsim_target>: Default it. + * remote.c: Include "process-stratum-target.h". + (remote_target): Inherit from process_stratum_target. + <remote_target>: Default it. + * target.c (default_thread_address_space) + (default_thread_architecture): Delete. + * target.h (target_ops) <thread_architecture>: Now returns NULL by + default. + <thread_address_space>: Ditto. + * test-target.h: Include "process-stratum-target.h" instead of + "target.h". + (test_target_ops): Inherit from process_stratum_target. + <test_target_ops>: Default it. + * tracefile.c (tracefile_target::tracefile_target): Delete. + * tracefile.h: Include "process-stratum-target.h". + (tracefile_target): Inherit from process_stratum_target. + <tracefile_target>: Default it. + * target-delegates.c: Regenerate. + +2018-11-30 Pedro Alves <palves@redhat.com> + * Makefile.in (COMMON_SFILES): Add test-target.c. * gdbarch-selftests.c: Include "test-target.h". * regcache.c: Include "test-target.h". diff --git a/gdb/Makefile.in b/gdb/Makefile.in index 7ec3c0a..1099d71 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 af8305f..977baf9 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 72f2807..deabf84 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 44aa2f6..8cdfa05 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 98969bc..d301d39 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<target_ops> + : public memory_breakpoint_target<process_stratum_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 0000000..9ce8d3d --- /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 <http://www.gnu.org/licenses/>. */ + +#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 0000000..0a799f7 --- /dev/null +++ b/gdb/process-stratum-target.h @@ -0,0 +1,51 @@ +/* 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 <http://www.gnu.org/licenses/>. */ + +#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 () + { + 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 63e4145..1ceecaa 100644 --- a/gdb/remote-sim.c +++ b/gdb/remote-sim.c @@ -31,6 +31,7 @@ #include <setjmp.h> #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<target_ops> + : public memory_breakpoint_target<process_stratum_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 90b5dab..ae35bec 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 eeb5057..1e70823 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 7fad3a9..8905ce3 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 e170bbc..36f8d5e 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 b3170f8..1286fc1 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 b367f6e..88e79f7 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 47f8bee..3ae3e7d 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; |