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.
+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.
parse.c \
printcmd.c \
probe.c \
+ process-stratum-target.c \
producer.c \
progspace.c \
progspace-and-thread.c \
#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 */
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; }
#include "command.h"
#include "bfd.h"
#include "target.h"
+#include "process-stratum-target.h"
#include "gdbcore.h"
#include "gdbthread.h"
#include "regcache.h"
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 ();
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 */
return agent_loaded_p ();
}
-inf_child_target::inf_child_target ()
-{
- this->to_stratum = process_stratum;
-}
-
/* See inf-child.h. */
void
#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;
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;
--- /dev/null
+/* 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;
+}
--- /dev/null
+/* 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) */
#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"
};
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; }
#include "bfd.h"
#include "symfile.h"
#include "target.h"
+#include "process-stratum-target.h"
/*#include "terminal.h" */
#include "gdbcmd.h"
#include "objfiles.h"
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
struct gdbarch *
dummy_target::thread_architecture (ptid_t arg0)
{
- return default_thread_architecture (this, arg0);
+ return NULL;
}
struct gdbarch *
struct address_space *
dummy_target::thread_address_space (ptid_t arg0)
{
- return default_thread_address_space (this, arg0);
+ return NULL;
}
struct address_space *
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);
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. */
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 *
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. */
#ifndef TEST_TARGET_H
#define TEST_TARGET_H
-#include "target.h"
+#include "process-stratum-target.h"
#if GDB_SELF_TEST
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;
return -1;
}
-tracefile_target::tracefile_target ()
-{
- this->to_stratum = process_stratum;
-}
-
void
_initialize_tracefile (void)
{
#include "tracepoint.h"
#include "target.h"
+#include "process-stratum-target.h"
struct trace_file_writer;
/* 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;