From 08bdefb58b78621f50b30f64170e2cdc31c1b2cf Mon Sep 17 00:00:00 2001 From: Pedro Alves Date: Sun, 14 Jun 2020 20:57:04 +0100 Subject: gdb: make inferior_list use intrusive_list Change inferior_list, the global list of inferiors, to use intrusive_list. I think most other changes are somewhat obvious fallouts from this change. There is a small change in behavior in scoped_mock_context. Before this patch, constructing a scoped_mock_context would replace the whole inferior list with only the new mock inferior. Tests using two scoped_mock_contexts therefore needed to manually link the two inferiors together, as the second scoped_mock_context would bump the first mock inferior from the thread list. With this patch, a scoped_mock_context adds its mock inferior to the inferior list on construction, and removes it on destruction. This means that tests run with mock inferiors in the inferior list in addition to any pre-existing inferiors (there is always at least one). There is no possible pid clash problem, since each scoped mock inferior uses its own process target, and pids are per process target. Co-Authored-By: Simon Marchi Change-Id: I7eb6a8f867d4dcf8b8cd2dcffd118f7270756018 --- gdb/infrun.c | 30 +++++++++++++++++++----------- 1 file changed, 19 insertions(+), 11 deletions(-) (limited to 'gdb/infrun.c') diff --git a/gdb/infrun.c b/gdb/infrun.c index 8cfd58b..300d627 100644 --- a/gdb/infrun.c +++ b/gdb/infrun.c @@ -3730,18 +3730,28 @@ do_target_wait (execution_control_state *ecs, target_wait_flags options) reported the stop to the user, polling for events. */ scoped_restore_current_thread restore_thread; - int inf_num = selected->num; - for (inferior *inf = selected; inf != NULL; inf = inf->next) - if (inferior_matches (inf)) - if (do_wait (inf)) + intrusive_list_iterator start + = inferior_list.iterator_to (*selected); + + for (intrusive_list_iterator it = start; + it != inferior_list.end (); + ++it) + { + inferior *inf = &*it; + + if (inferior_matches (inf) && do_wait (inf)) return true; + } - for (inferior *inf = inferior_list; - inf != NULL && inf->num < inf_num; - inf = inf->next) - if (inferior_matches (inf)) - if (do_wait (inf)) + for (intrusive_list_iterator it = inferior_list.begin (); + it != start; + ++it) + { + inferior *inf = &*it; + + if (inferior_matches (inf) && do_wait (inf)) return true; + } ecs->ws.kind = TARGET_WAITKIND_IGNORE; return false; @@ -9452,7 +9462,6 @@ infrun_thread_ptid_changed () scoped_mock_context target1 (arch); scoped_mock_context target2 (arch); - target2.mock_inferior.next = &target1.mock_inferior; ptid_t old_ptid (111, 222); ptid_t new_ptid (111, 333); @@ -9477,7 +9486,6 @@ infrun_thread_ptid_changed () scoped_mock_context target1 (arch); scoped_mock_context target2 (arch); - target2.mock_inferior.next = &target1.mock_inferior; ptid_t old_ptid (111, 222); ptid_t new_ptid (111, 333); -- cgit v1.1