gdb: maintain ptid -> thread map, optimize find_thread_ptid

When debugging a large number of threads (thousands), looking up a
thread by ptid_t using the inferior::thread_list linked list can add up.

Add inferior::thread_map, an std::unordered_map indexed by ptid_t, and
change the find_thread_ptid function to look up a thread using
std::unordered_map::find, instead of iterating on all of the
inferior's threads.  This should make it faster to look up a thread
from its ptid.

Change-Id: I3a8da0a839e18dee5bb98b8b7dbeb7f3dfa8ae1c
Co-Authored-By: Pedro Alves <pedro@palves.net>
This commit is contained in:
Simon Marchi
2021-06-11 18:29:33 -04:00
parent 71a2349005
commit 922cc93d5d
6 changed files with 47 additions and 5 deletions

View File

@@ -9418,8 +9418,13 @@ infrun_thread_ptid_changed ()
target1.mock_inferior.pid = old_ptid.pid ();
target1.mock_thread.ptid = old_ptid;
target1.mock_inferior.ptid_thread_map.clear ();
target1.mock_inferior.ptid_thread_map[old_ptid] = &target1.mock_thread;
target2.mock_inferior.pid = old_ptid.pid ();
target2.mock_thread.ptid = old_ptid;
target2.mock_inferior.ptid_thread_map.clear ();
target2.mock_inferior.ptid_thread_map[old_ptid] = &target2.mock_thread;
auto restore_inferior_ptid = make_scoped_restore (&inferior_ptid, old_ptid);
set_current_inferior (&target1.mock_inferior);
@@ -9442,8 +9447,13 @@ infrun_thread_ptid_changed ()
target1.mock_inferior.pid = old_ptid.pid ();
target1.mock_thread.ptid = old_ptid;
target1.mock_inferior.ptid_thread_map.clear ();
target1.mock_inferior.ptid_thread_map[old_ptid] = &target1.mock_thread;
target2.mock_inferior.pid = old_ptid.pid ();
target2.mock_thread.ptid = old_ptid;
target2.mock_inferior.ptid_thread_map.clear ();
target2.mock_inferior.ptid_thread_map[old_ptid] = &target2.mock_thread;
auto restore_inferior_ptid = make_scoped_restore (&inferior_ptid, old_ptid);
set_current_inferior (&target2.mock_inferior);