aboutsummaryrefslogtreecommitdiff
path: root/gdbsupport/ptid.h
AgeCommit message (Collapse)AuthorFilesLines
2023-09-15Fix build failure with GCC 4.8Tom Tromey1-1/+4
A user pointed out that the build failed with GCC 4.8. The problem was that the form used by the std::hash specialization of ptid_t was not accepted. This patch rewrites this code into a form that is acceptable to the older compiler. Approved-By: Simon Marchi <simon.marchi@efficios.com>
2023-09-11Specialize std::hash for ptid_tTom Tromey1-3/+2
This changes hash_ptid to instead be a specialization of std::hash. This makes it a little easier to use with standard containers. Approved-By: Simon Marchi <simon.marchi@efficios.com>
2023-02-02gdbsupport: add type definitions for pid, lwp and tidSimon Marchi1-7/+11
A following patch will want to declare variables of the same type as some ptid_t components. To make that easy (and avoid harcoding those types everywhere), define some type definitions in the ptid_t struct for each of them. Use them throughout ptid.h. I initially used pid_t, lwp_t and tid_t, but there is the risk of some system defining the pid_t type using a macro instead of a typedef, which would break things. So, use the _type suffix instead. Change-Id: I820b0bea9dafcb4914f1c9ba4bb96b5c666c8dec Approved-By: Andrew Burgess <aburgess@redhat.com>
2023-01-01Update copyright year range in header of all files managed by GDBJoel Brobecker1-1/+1
This commit is the result of running the gdb/copyright.py script, which automated the update of the copyright year range for all source files managed by the GDB project to be updated to include year 2023.
2022-01-01Automatic Copyright Year update after running gdb/copyright.pyJoel Brobecker1-1/+1
This commit brings all the changes made by running gdb/copyright.py as per GDB's Start of New Year Procedure. For the avoidance of doubt, all changes in this commits were performed by the script.
2021-09-23Change ptid_t::tid to ULONGESTTom Tromey1-3/+4
The ptid_t 'tid' member is normally used as an address in gdb -- both bsd-uthread and ravenscar-thread use it this way. However, because the type is 'long', this can cause problems with sign extension. This patch changes the type to ULONGEST to ensure that sign extension does not occur.
2021-07-12gdb: maintain per-process-target list of resumed threads with pending wait ↵Simon Marchi1-0/+7
status Looking up threads that are both resumed and have a pending wait status to report is something that we do quite often in the fast path and is expensive if there are many threads, since it currently requires walking whole thread lists. The first instance is in maybe_set_commit_resumed_all_targets. This is called after handling each event in fetch_inferior_event, to see if we should ask targets to commit their resumed threads or not. If at least one thread is resumed but has a pending wait status, we don't ask the targets to commit their resumed threads, because we want to consume and handle the pending wait status first. The second instance is in random_pending_event_thread, where we want to select a random thread among all those that are resumed and have a pending wait status. This is called every time we try to consume events, to see if there are any pending events that we we want to consume, before asking the targets for more events. To allow optimizing these cases, maintain a per-process-target list of threads that are resumed and have a pending wait status. In maybe_set_commit_resumed_all_targets, we'll be able to check in O(1) if there are any such threads simply by checking whether the list is empty. In random_pending_event_thread, we'll be able to use that list, which will be quicker than iterating the list of threads, especially when there are no resumed with pending wait status threads. About implementation details: using the new setters on class thread_info, it's relatively easy to maintain that list. Any time the "resumed" or "pending wait status" property is changed, we check whether that should cause the thread to be added or removed from the list. In set_thread_exited, we try to remove the thread from the list, because keeping an exited thread in that list would make no sense (especially if the thread is freed). My first implementation assumed that a process stratum target was always present when set_thread_exited is called. That's however, not the case: in some cases, targets unpush themselves from an inferior and then call "exit_inferior", which exits all the threads. If the target is unpushed before set_thread_exited is called on the threads, it means we could mistakenly leave some threads in the list. I tried to see how hard it would be to make it such that targets have to exit all threads before unpushing themselves from the inferior (that would seem logical to me, we don't want threads belonging to an inferior that has no process target). That seemed quite difficult and not worth the time at the moment. Instead, I changed inferior::unpush_target to remove all threads of that inferior from the list. As of this patch, the list is not used, this is done in the subsequent patches. The debug messages in process-stratum-target.c need to print some ptids. However, they can't use target_pid_to_str to print them without introducing a dependency on the current inferior (the current inferior is used to get the current target stack). For debug messages, I find it clearer to print the spelled out ptid anyway (the pid, lwp and tid values). Add a ptid_t::to_string method that returns a string representation of the ptid that is meant for debug messages, a bit like we already have frame_id::to_string. Change-Id: Iad8f93db2d13984dd5aa5867db940ed1169dbb67
2021-01-01Update copyright year range in all GDB filesJoel Brobecker1-1/+1
This commits the result of running gdb/copyright.py as per our Start of New Year procedure... gdb/ChangeLog Update copyright year range in copyright header of all GDB files.
2020-08-07gdb: change regcache list to be a mapSimon Marchi1-0/+16
One regcache object is created for each stopped thread and is stored in the regcache::regcaches linked list. Looking up a regcache for a given thread is therefore in O(number of threads). Stopping all threads then becomes O((number of threads) ^ 2). Same goes for resuming a thread (need to delete the regcache of a given ptid) and resuming all threads. It becomes noticeable when debugging thousands of threads, which is typical with GPU targets. This patch replaces the linked list with some maps to reduce that complexity. The first design was using an std::unordered_map with (target, ptid, arch) as the key, because that's how lookups are done (in get_thread_arch_aspace_regcache). However, the registers_changed_ptid function, also somewhat on the hot path (it is used when resuming threads), needs to delete all regcaches associated to a given (target, ptid) tuple. If the key of the map is (target, ptid, arch), we have to walk all items of the map, not good. The second design was therefore using an std::unordered_multimap with (target, ptid) as the key. One key could be associated to multiple regcaches, all with different gdbarches. When looking up, we would have to walk all these regcaches. This would be ok, because there will usually be actually one matching regcache. In the exceptional multi-arch thread cases, there will be maybe two. However, in registers_changed_ptid, we sometimes need to remove all regcaches matching a given target. We would then have to talk all items of the map again, not good. The design as implemented in this patch therefore uses two levels of map. One std::unordered_map uses the target as the key. The value type is an std::unordered_multimap that itself uses the ptid as the key. The values of the multimap are the regcaches themselves. Again, we expect to have one or very few regcaches per (target, ptid). So, in summary: * The lookups (in get_thread_arch_aspace_regcache), become faster when the number of threads grows, compared to the linked list. With a small number of threads, it will probably be a bit slower to do map lookups than to walk a few linked list nodes, but I don't think it will be noticeable in practice. * The function registers_changed_ptid deletes all regcaches related to a given (target, ptid). It must now handle the different cases separately: - NULL target and minus_one_ptid: we delete all the entries - NULL target and non-minus_one_ptid: invalid (checked by assert) - non-NULL target and non-minus_one_ptid: we delete all the entries associated to that tuple - a non-NULL target and minus_one_ptid: we delete all the entries associated to that target * The function regcache_thread_ptid_changed is called when a thread changes ptid. It is implemented efficiently using the map, although that's not very important: it is not called often, mostly when creating an inferior, on some specific platforms. This patch is a tiny bit from ROCm GDB [1] we would like to merge upstream. Laurent Morichetti gave be these performance numbers: The benchmark used is: time ./gdb --data-directory=data-directory /extra/lmoriche/hip/samples/0_Intro/bit_extract/bit_extract -ex "set pagination off" -ex "set breakpoint pending on" -ex "b bit_extract_kernel if \$_thread == 5" -ex run -ex c -batch It measures the time it takes to continue from a conditional breakpoint with 2048 threads at that breakpoint, one of them reporting the breakpoint. baseline: real 0m10.227s real 0m10.177s real 0m10.362s with patch: real 0m8.356s real 0m8.424s real 0m8.494s [1] https://github.com/ROCm-Developer-Tools/ROCgdb gdb/ChangeLog: * regcache.c (ptid_regcache_map): New type. (target_ptid_regcache_map): New type. (regcaches): Change type to target_ptid_regcache_map. (get_thread_arch_aspace_regcache): Update to regcaches' new type. (regcache_thread_ptid_changed): Likewise. (registers_changed_ptid): Likewise. (regcaches_size): Likewise. (regcaches_test): Update. (regcache_thread_ptid_changed): Update. * regcache.h (regcache_up): New type. * gdbsupport/ptid.h (hash_ptid): New struct. Change-Id: Iabb0a1111707936ca111ddb13f3b09efa83d3402
2020-01-14Move gdbsupport to the top levelTom Tromey1-0/+155
This patch moves the gdbsupport directory to the top level. This is the next step in the ongoing project to move gdbserver to the top level. The bulk of this patch was created by "git mv gdb/gdbsupport gdbsupport". This patch then adds a build system to gdbsupport and wires it into the top level. Then it changes gdb to use the top-level build. gdbserver, on the other hand, is not yet changed. It still does its own build of gdbsupport. ChangeLog 2020-01-14 Tom Tromey <tom@tromey.com> * src-release.sh (GDB_SUPPORT_DIRS): Add gdbsupport. * MAINTAINERS: Add gdbsupport. * configure: Rebuild. * configure.ac (configdirs): Add gdbsupport. * gdbsupport: New directory, move from gdb/gdbsupport. * Makefile.def (host_modules, dependencies): Add gnulib. * Makefile.in: Rebuild. gdb/ChangeLog 2020-01-14 Tom Tromey <tom@tromey.com> * nat/x86-linux-dregs.c: Include configh.h. * nat/linux-ptrace.c: Include configh.h. * nat/linux-btrace.c: Include configh.h. * defs.h: Include config.h, bfd.h. * configure.ac: Don't source common.host. (CONFIG_OBS, CONFIG_SRCS): Remove gdbsupport files. * configure: Rebuild. * acinclude.m4: Update path. * Makefile.in (SUPPORT, LIBSUPPORT, INCSUPPORT): New variables. (CONFIG_SRC_SUBDIR): Remove gdbsupport. (INTERNAL_CFLAGS_BASE): Add INCSUPPORT. (CLIBS): Add LIBSUPPORT. (CDEPS): Likewise. (COMMON_SFILES): Remove gdbsupport files. (HFILES_NO_SRCDIR): Likewise. (stamp-version): Update path to create-version.sh. (ALLDEPFILES): Remove gdbsupport files. gdb/gdbserver/ChangeLog 2020-01-14 Tom Tromey <tom@tromey.com> * server.h: Include config.h. * gdbreplay.c: Include config.h. * configure: Rebuild. * configure.ac: Don't source common.host. * acinclude.m4: Update path. * Makefile.in (INCSUPPORT): New variable. (INCLUDE_CFLAGS): Add INCSUPPORT. (SFILES): Update paths. (version-generated.c): Update path to create-version.sh. (gdbsupport/%-ipa.o, gdbsupport/%.o): Update paths. gdbsupport/ChangeLog 2020-01-14 Tom Tromey <tom@tromey.com> * common-defs.h: Add GDBSERVER case. Update includes. * acinclude.m4, aclocal.m4, config.in, configure, configure.ac, Makefile.am, Makefile.in, README: New files. * Moved from ../gdb/gdbsupport/ Change-Id: I07632e7798635c1bab389bf885971e584fb4bb78