From 922cc93d5da6a6dc422b7e7a09ee745414d67457 Mon Sep 17 00:00:00 2001 From: Simon Marchi Date: Fri, 11 Jun 2021 18:29:33 -0400 Subject: 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 --- gdb/regcache.c | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'gdb/regcache.c') diff --git a/gdb/regcache.c b/gdb/regcache.c index 21fa25d..ac44d71 100644 --- a/gdb/regcache.c +++ b/gdb/regcache.c @@ -2044,8 +2044,13 @@ regcache_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; gdb_assert (regcaches.empty ()); -- cgit v1.1