aboutsummaryrefslogtreecommitdiff
path: root/gdb/target.c
diff options
context:
space:
mode:
authorPedro Alves <palves@redhat.com>2018-11-30 17:49:49 +0000
committerPedro Alves <palves@redhat.com>2018-11-30 17:49:49 +0000
commit66b4deae03e7a503f8c543aa198a8c010863135a (patch)
tree41030b08bd4b97e6d50004867b2a0bd20d0e9c73 /gdb/target.c
parent20a71194793bfa791b9090db2d47a67388650d93 (diff)
downloadgdb-66b4deae03e7a503f8c543aa198a8c010863135a.zip
gdb-66b4deae03e7a503f8c543aa198a8c010863135a.tar.gz
gdb-66b4deae03e7a503f8c543aa198a8c010863135a.tar.bz2
target_ops::to_stratum -> target_ops::stratum() virtual method
Given that a target's stratum is a property of the type, and not of an instance of the type, get rid of to_stratum data field and replace it with a virtual method. I.e., when we have e.g., 10 target remote instances active, there's no need for each of the instances to have their own to_stratum copy. gdb/ChangeLog: 2018-11-30 Pedro Alves <palves@redhat.com> * aix-thread.c (aix_thread_target) <aix_thread_target>: Delete. <stratum>: New override. * bfd-target.c (aix_thread_target) <aix_thread_target>: Delete. <stratum>: New override. * bsd-uthread.c (bsd_uthread_target) <bsd_uthread_target>: Delete. <stratum>: New override. * exec.c (exec_target) <exec_target>: Delete. <stratum>: New override. * gdbarch-selftests.c (register_to_value_test): Adjust to use the stratum method instead of the to_stratum field. * linux-thread-db.c (thread_db_target) <thread_db_target>: Delete. <stratum>: New override. (thread_db_target::thread_db_target): Delete. * make-target-delegates (print_class): Don't print a ctor declaration. Print a stratum method override declaration. * process-stratum-target.h (process_stratum_target) <process_stratum_target>: Delete. <stratum>: New override. * ravenscar-thread.c (ravenscar_thread_target) <ravenscar_thread_target>: Delete. <stratum>: New override. * record-btrace.c (record_btrace_target) <record_btrace_target>: Delete. <stratum>: New override. * record-full.c (record_full_base_target) <record_full_base_target>: Delete. <stratum>: New override. * record.c (record_disconnect, record_detach) (record_mourn_inferior, record_kill): Adjust to use the stratum method instead of the to_stratum field. * regcache.c (cooked_read_test, cooked_write_test): Likewise. * sol-thread.c (sol_thread_target) <sol_thread_target>: Delete. <stratum>: New override. * spu-multiarch.c (spu_multiarch_target) <spu_multiarch_target>: Delete. <stratum>: New override. * target-delegates.c: Regenerate. * target.c (target_stack::push, target_stack::unpush) (pop_all_targets_above, pop_all_targets_at_and_above) (info_target_command, target_require_runnable) (target_stack::find_beneath): Adjust to use the stratum method instead of the to_stratum field. (dummy_target::dummy_target): Delete. (dummy_target::stratum): New. (debug_target::debug_target): Delete. (debug_target::stratum): New. (maintenance_print_target_stack): Adjust to use the stratum method instead of the to_stratum field. * target.h (struct target_ops) <stratum>: New method. <to_stratum>: Delete. <is_pushed>: Adjust to use the stratum method instead of the to_stratum field.
Diffstat (limited to 'gdb/target.c')
-rw-r--r--gdb/target.c48
1 files changed, 27 insertions, 21 deletions
diff --git a/gdb/target.c b/gdb/target.c
index ecfdde9..80b8453 100644
--- a/gdb/target.c
+++ b/gdb/target.c
@@ -562,18 +562,20 @@ void
target_stack::push (target_ops *t)
{
/* If there's already a target at this stratum, remove it. */
- if (m_stack[t->to_stratum] != NULL)
+ strata stratum = t->stratum ();
+
+ if (m_stack[stratum] != NULL)
{
- target_ops *prev = m_stack[t->to_stratum];
- m_stack[t->to_stratum] = NULL;
+ target_ops *prev = m_stack[stratum];
+ m_stack[stratum] = NULL;
target_close (prev);
}
/* Now add the new one. */
- m_stack[t->to_stratum] = t;
+ m_stack[stratum] = t;
- if (m_top < t->to_stratum)
- m_top = t->to_stratum;
+ if (m_top < stratum)
+ m_top = stratum;
}
/* See target.h. */
@@ -597,7 +599,9 @@ unpush_target (struct target_ops *t)
bool
target_stack::unpush (target_ops *t)
{
- if (t->to_stratum == dummy_stratum)
+ strata stratum = t->stratum ();
+
+ if (stratum == dummy_stratum)
internal_error (__FILE__, __LINE__,
_("Attempt to unpush the dummy target"));
@@ -606,7 +610,7 @@ target_stack::unpush (target_ops *t)
/* Look for the specified target. Note that a target can only occur
once in the target stack. */
- if (m_stack[t->to_stratum] != t)
+ if (m_stack[stratum] != t)
{
/* If T wasn't pushed, quit. Only open targets should be
closed. */
@@ -614,10 +618,10 @@ target_stack::unpush (target_ops *t)
}
/* Unchain the target. */
- m_stack[t->to_stratum] = NULL;
+ m_stack[stratum] = NULL;
- if (m_top == t->to_stratum)
- m_top = t->beneath ()->to_stratum;
+ if (m_top == stratum)
+ m_top = t->beneath ()->stratum ();
/* Finally close the target. Note we do this after unchaining, so
any target method calls from within the target_close
@@ -645,7 +649,7 @@ unpush_target_and_assert (struct target_ops *target)
void
pop_all_targets_above (enum strata above_stratum)
{
- while ((int) (current_top_target ()->to_stratum) > (int) above_stratum)
+ while ((int) (current_top_target ()->stratum ()) > (int) above_stratum)
unpush_target_and_assert (current_top_target ());
}
@@ -654,7 +658,7 @@ pop_all_targets_above (enum strata above_stratum)
void
pop_all_targets_at_and_above (enum strata stratum)
{
- while ((int) (current_top_target ()->to_stratum) >= (int) stratum)
+ while ((int) (current_top_target ()->stratum ()) >= (int) stratum)
unpush_target_and_assert (current_top_target ());
}
@@ -1881,7 +1885,7 @@ info_target_command (const char *args, int from_tty)
if (!t->has_memory ())
continue;
- if ((int) (t->to_stratum) <= (int) dummy_stratum)
+ if ((int) (t->stratum ()) <= (int) dummy_stratum)
continue;
if (has_all_mem)
printf_unfiltered (_("\tWhile running this, "
@@ -2323,7 +2327,7 @@ target_require_runnable (void)
/* Do not worry about targets at certain strata that can not
create inferiors. Assume they will be pushed again if
necessary, and continue to the process_stratum. */
- if (t->to_stratum > process_stratum)
+ if (t->stratum () > process_stratum)
continue;
error (_("The \"%s\" target does not support \"run\". "
@@ -3110,7 +3114,7 @@ target_ops *
target_stack::find_beneath (const target_ops *t) const
{
/* Look for a non-empty slot at stratum levels beneath T's. */
- for (int stratum = t->to_stratum - 1; stratum >= 0; --stratum)
+ for (int stratum = t->stratum () - 1; stratum >= 0; --stratum)
if (m_stack[stratum] != NULL)
return m_stack[stratum];
@@ -3224,14 +3228,16 @@ static const target_info dummy_target_info = {
""
};
-dummy_target::dummy_target ()
+strata
+dummy_target::stratum () const
{
- to_stratum = dummy_stratum;
+ return dummy_stratum;
}
-debug_target::debug_target ()
+strata
+debug_target::stratum () const
{
- to_stratum = debug_stratum;
+ return debug_stratum;
}
const target_info &
@@ -3779,7 +3785,7 @@ maintenance_print_target_stack (const char *cmd, int from_tty)
for (target_ops *t = current_top_target (); t != NULL; t = t->beneath ())
{
- if (t->to_stratum == debug_stratum)
+ if (t->stratum () == debug_stratum)
continue;
printf_filtered (" - %s (%s)\n", t->shortname (), t->longname ());
}