Age | Commit message (Collapse) | Author | Files | Lines |
|
With the following patch, which teaches the amd-dbgapi target to handle
inferiors that fork, we end up with target stacks in the following
state, when an inferior that does not use the GPU forks an inferior that
eventually uses the GPU.
inf 1 inf 2
----- -----
amd-dbgapi
linux-nat linux-nat
exec exec
When a GPU thread from inferior 2 hits a breakpoint, the following
sequence of events would happen, if it was not for the current patch.
- we start with inferior 1 as current
- do_target_wait_1 makes inferior 2 current, does a target_wait, which
returns a stop event for an amd-dbgapi wave (thread).
- do_target_wait's scoped_restore_current_thread restores inferior 1 as
current
- fetch_inferior_event calls switch_to_target_no_thread with linux-nat
as the process target, since linux-nat is officially the process
target of inferior 2. This makes inferior 1 the current inferior, as
it's the first inferior with that target.
- In handle_signal_stop, we have:
ecs->event_thread->suspend.stop_pc
= regcache_read_pc (get_thread_regcache (ecs->event_thread));
context_switch (ecs);
regcache_read_pc executes while inferior 1 is still the current one
(because it's before the `context_switch`). This is a problem,
because the regcache is for a ptid managed by the amd-dbgapi target
(e.g. (12345, 1, 1)), a ptid that does not make sense for the
linux-nat target. The fetch_registers target call goes directly
to the linux-nat target, which gets confused.
- We would then get an error like:
Couldn't get extended state status: No such process.
... since linux-nat tries to do a ptrace call on tid 1.
GDB should switch to the inferior the ptid belongs to before doing the
target call to fetch registers, to make sure the call hits the right
target stack (it should be handled by the amd-dbgapi target in this
case). In fact the following patch does this change, and it would be
enough to fix this specific problem.
However, I propose to change regcache to make it switch to the right
inferior, if needed, before doing target calls. That makes the
interface as a whole more independent of the global context.
My first attempt at doing this was to find an inferior using the process
stratum target and the ptid that regcache already knows about:
gdb::optional<scoped_restore_current_thread> restore_thread;
inferior *inf = find_inferior_ptid (this->target (), this->ptid ());
if (inf != current_inferior ())
{
restore_thread.emplace ();
switch_to_inferior_no_thread (inf);
}
However, this caused some failures in fork-related tests and gdbserver
boards. When we detach a fork child, we may create a regcache for the
child, but there is no corresponding inferior. For instance, to restore
the PC after a displaced step over the fork syscall. So
find_inferior_ptid would return nullptr, and
switch_to_inferior_no_thread would hit a failed assertion.
So, this patch adds to regcache the information "the inferior to switch
to to makes target calls". In typical cases, it will be the inferior
that matches the regcache's ptid. But in some cases, like the detached
fork child one, it will be another inferior (in this example, it will be
the fork parent inferior).
The problem that we witnessed was in regcache::raw_update specifically,
but I looked for other regcache methods doing target calls, and added
the same inferior switching code to raw_write too.
In the regcache constructor and in get_thread_arch_aspace_regcache,
"inf_for_target_calls" replaces the process_stratum_target parameter.
We suppose that the process stratum target that would be passed
otherwise is the same that is in inf_for_target_calls's target stack, so
we don't need to pass both in parallel. The process stratum target is
still used as a key in the `target_pid_ptid_regcache_map` map, but
that's it.
There is one spot that needs to be updated outside of the regcache code,
which is the path that handles the "restore PC after a displaced step in
a fork child we're about to detach" case mentioned above.
regcache_test_data needs to be changed to include full-fledged mock
contexts (because there now needs to be inferiors, not just targets).
Change-Id: Id088569ce106e1f194d9ae7240ff436f11c5e123
Reviewed-By: Pedro Alves <pedro@palves.net>
|
|
The regcache class takes a process_stratum_target and then exposes it
through regcache::target. But it doesn't use it itself, suggesting it
doesn't really make sense to put it there. The only user of
regcache::target is record_btrace_target::fetch_registers, but it might
as well just get it from the current target stack. This simplifies a
little bit a patch later in this series.
Change-Id: I8878d875805681c77f469ac1a2bf3a508559a62d
Reviewed-By: Pedro Alves <pedro@palves.net>
|
|
This introduces the set_lval method on value, one step toward removing
deprecated_lval_hack. Ultimately I think the goal should be for some
of these set_* methods to be replaced with constructors; but I haven't
done this, as the series is already too long. Other 'deprecated'
methods can probably be handled the same way.
Approved-By: Simon Marchi <simon.marchi@efficios.com>
|
|
This turns many functions that are related to optimized-out or
availability-checking to be methods of value. The static function
value_entirely_covered_by_range_vector is also converted to be a
private method.
Approved-By: Simon Marchi <simon.marchi@efficios.com>
|
|
This turns value_contents_raw, value_contents_writeable, and
value_contents_all_raw into methods on value. The remaining functions
will be changed later in the series; they were a bit trickier and so I
didn't include them in this patch.
Approved-By: Simon Marchi <simon.marchi@efficios.com>
|
|
This changes allocate_value to be a static "constructor" of value.
Approved-By: Simon Marchi <simon.marchi@efficios.com>
|
|
This changes value_type to be a method of value. Much of this patch
was written by script.
Approved-By: Simon Marchi <simon.marchi@efficios.com>
|
|
This patch adds the foundation for GDB to be able to debug programs
offloaded to AMD GPUs using the AMD ROCm platform [1]. The latest
public release of the ROCm release at the time of writing is 5.4, so
this is what this patch targets.
The ROCm platform allows host programs to schedule bits of code for
execution on GPUs or similar accelerators. The programs running on GPUs
are typically referred to as `kernels` (not related to operating system
kernels).
Programs offloaded with the AMD ROCm platform can be written in the HIP
language [2], OpenCL and OpenMP, but we're going to focus on HIP here.
The HIP language consists of a C++ Runtime API and kernel language.
Here's an example of a very simple HIP program:
#include "hip/hip_runtime.h"
#include <cassert>
__global__ void
do_an_addition (int a, int b, int *out)
{
*out = a + b;
}
int
main ()
{
int *result_ptr, result;
/* Allocate memory for the device to write the result to. */
hipError_t error = hipMalloc (&result_ptr, sizeof (int));
assert (error == hipSuccess);
/* Run `do_an_addition` on one workgroup containing one work item. */
do_an_addition<<<dim3(1), dim3(1), 0, 0>>> (1, 2, result_ptr);
/* Copy result from device to host. Note that this acts as a synchronization
point, waiting for the kernel dispatch to complete. */
error = hipMemcpyDtoH (&result, result_ptr, sizeof (int));
assert (error == hipSuccess);
printf ("result is %d\n", result);
assert (result == 3);
return 0;
}
This program can be compiled with:
$ hipcc simple.cpp -g -O0 -o simple
... where `hipcc` is the HIP compiler, shipped with ROCm releases. This
generates an ELF binary for the host architecture, containing another
ELF binary with the device code. The ELF for the device can be
inspected with:
$ roc-obj-ls simple
1 host-x86_64-unknown-linux file://simple#offset=8192&size=0
1 hipv4-amdgcn-amd-amdhsa--gfx906 file://simple#offset=8192&size=34216
$ roc-obj-extract 'file://simple#offset=8192&size=34216'
$ file simple-offset8192-size34216.co
simple-offset8192-size34216.co: ELF 64-bit LSB shared object, *unknown arch 0xe0* version 1, dynamically linked, with debug_info, not stripped
^
amcgcn architecture that my `file` doesn't know about ----´
Running the program gives the very unimpressive result:
$ ./simple
result is 3
While running, this host program has copied the device program into the
GPU's memory and spawned an execution thread on it. The goal of this
GDB port is to let the user debug host threads and these GPU threads
simultaneously. Here's a sample session using a GDB with this patch
applied:
$ ./gdb -q -nx --data-directory=data-directory ./simple
Reading symbols from ./simple...
(gdb) break do_an_addition
Function "do_an_addition" not defined.
Make breakpoint pending on future shared library load? (y or [n]) y
Breakpoint 1 (do_an_addition) pending.
(gdb) r
Starting program: /home/smarchi/build/binutils-gdb-amdgpu/gdb/simple
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib/x86_64-linux-gnu/libthread_db.so.1".
[New Thread 0x7ffff5db7640 (LWP 1082911)]
[New Thread 0x7ffef53ff640 (LWP 1082913)]
[Thread 0x7ffef53ff640 (LWP 1082913) exited]
[New Thread 0x7ffdecb53640 (LWP 1083185)]
[New Thread 0x7ffff54bf640 (LWP 1083186)]
[Thread 0x7ffdecb53640 (LWP 1083185) exited]
[Switching to AMDGPU Wave 2:2:1:1 (0,0,0)/0]
Thread 6 hit Breakpoint 1, do_an_addition (a=<error reading variable: DWARF-2 expression error: `DW_OP_regx' operations must be used either alone or in conjunction with DW_OP_piece or DW_OP_bit_piece.>,
b=<error reading variable: DWARF-2 expression error: `DW_OP_regx' operations must be used either alone or in conjunction with DW_OP_piece or DW_OP_bit_piece.>,
out=<error reading variable: DWARF-2 expression error: `DW_OP_regx' operations must be used either alone or in conjunction with DW_OP_piece or DW_OP_bit_piece.>) at simple.cpp:24
24 *out = a + b;
(gdb) info inferiors
Num Description Connection Executable
* 1 process 1082907 1 (native) /home/smarchi/build/binutils-gdb-amdgpu/gdb/simple
(gdb) info threads
Id Target Id Frame
1 Thread 0x7ffff5dc9240 (LWP 1082907) "simple" 0x00007ffff5e9410b in ?? () from /opt/rocm-5.4.0/lib/libhsa-runtime64.so.1
2 Thread 0x7ffff5db7640 (LWP 1082911) "simple" __GI___ioctl (fd=3, request=3222817548) at ../sysdeps/unix/sysv/linux/ioctl.c:36
5 Thread 0x7ffff54bf640 (LWP 1083186) "simple" __GI___ioctl (fd=3, request=3222817548) at ../sysdeps/unix/sysv/linux/ioctl.c:36
* 6 AMDGPU Wave 2:2:1:1 (0,0,0)/0 do_an_addition (
a=<error reading variable: DWARF-2 expression error: `DW_OP_regx' operations must be used either alone or in conjunction with DW_OP_piece or DW_OP_bit_piece.>,
b=<error reading variable: DWARF-2 expression error: `DW_OP_regx' operations must be used either alone or in conjunction with DW_OP_piece or DW_OP_bit_piece.>,
out=<error reading variable: DWARF-2 expression error: `DW_OP_regx' operations must be used either alone or in conjunction with DW_OP_piece or DW_OP_bit_piece.>) at simple.cpp:24
(gdb) bt
Python Exception <class 'gdb.error'>: Unhandled dwarf expression opcode 0xe1
#0 do_an_addition (a=<error reading variable: DWARF-2 expression error: `DW_OP_regx' operations must be used either alone or in conjunction with DW_OP_piece or DW_OP_bit_piece.>,
b=<error reading variable: DWARF-2 expression error: `DW_OP_regx' operations must be used either alone or in conjunction with DW_OP_piece or DW_OP_bit_piece.>,
out=<error reading variable: DWARF-2 expression error: `DW_OP_regx' operations must be used either alone or in conjunction with DW_OP_piece or DW_OP_bit_piece.>) at simple.cpp:24
(gdb) continue
Continuing.
result is 3
warning: Temporarily disabling breakpoints for unloaded shared library "file:///home/smarchi/build/binutils-gdb-amdgpu/gdb/simple#offset=8192&size=67208"
[Thread 0x7ffff54bf640 (LWP 1083186) exited]
[Thread 0x7ffff5db7640 (LWP 1082911) exited]
[Inferior 1 (process 1082907) exited normally]
One thing to notice is the host and GPU threads appearing under
the same inferior. This is a design goal for us, as programmers tend to
think of the threads running on the GPU as part of the same program as
the host threads, so showing them in the same inferior in GDB seems
natural. Also, the host and GPU threads share a global memory space,
which fits the inferior model.
Another thing to notice is the error messages when trying to read
variables or printing a backtrace. This is expected for the moment,
since the AMD GPU compiler produces some DWARF that uses some
non-standard extensions:
https://llvm.org/docs/AMDGPUDwarfExtensionsForHeterogeneousDebugging.html
There were already some patches posted by Zoran Zaric earlier to make
GDB support these extensions:
https://inbox.sourceware.org/gdb-patches/20211105113849.118800-1-zoran.zaric@amd.com/
We think it's better to get the basic support for AMD GPU in first,
which will then give a better justification for GDB to support these
extensions.
GPU threads are named `AMDGPU Wave`: a wave is essentially a hardware
thread using the SIMT (single-instruction, multiple-threads) [3]
execution model.
GDB uses the amd-dbgapi library [4], included in the ROCm platform, for
a few things related to AMD GPU threads debugging. Different components
talk to the library, as show on the following diagram:
+---------------------------+ +-------------+ +------------------+
| GDB | amd-dbgapi target | <-> | AMD | | Linux kernel |
| +-------------------+ | Debugger | +--------+ |
| | amdgcn gdbarch | <-> | API | <=> | AMDGPU | |
| +-------------------+ | | | driver | |
| | solib-rocm | <-> | (dbgapi.so) | +--------+---------+
+---------------------------+ +-------------+
- The amd-dbgapi target is a target_ops implementation used to control
execution of GPU threads. While the debugging of host threads works
by using the ptrace / wait Linux kernel interface (as usual), control
of GPU threads is done through a special interface (dubbed `kfd`)
exposed by the `amdgpu` Linux kernel module. GDB doesn't interact
directly with `kfd`, but instead goes through the amd-dbgapi library
(AMD Debugger API on the diagram).
Since it provides execution control, the amd-dbgapi target should
normally be a process_stratum_target, not just a target_ops. More
on that later.
- The amdgcn gdbarch (describing the hardware architecture of the GPU
execution units) offloads some requests to the amd-dbgapi library,
so that knowledge about the various architectures doesn't need to be
duplicated and baked in GDB. This is for example for things like
the list of registers.
- The solib-rocm component is an solib provider that fetches the list of
code objects loaded on the device from the amd-dbgapi library, and
makes GDB read their symbols. This is very similar to other solib
providers that handle shared libraries, except that here the shared
libraries are the pieces of code loaded on the device.
Given that Linux host threads are managed by the linux-nat target, and
the GPU threads are managed by the amd-dbgapi target, having all threads
appear in the same inferior requires the two targets to be in that
inferior's target stack. However, there can only be one
process_stratum_target in a given target stack, since there can be only
one target per slot. To achieve it, we therefore resort the hack^W
solution of placing the amd-dbgapi target in the arch_stratum slot of
the target stack, on top of the linux-nat target. Doing so allows the
amd-dbgapi target to intercept target calls and handle them if they
concern GPU threads, and offload to beneath otherwise. See
amd_dbgapi_target::fetch_registers for a simple example:
void
amd_dbgapi_target::fetch_registers (struct regcache *regcache, int regno)
{
if (!ptid_is_gpu (regcache->ptid ()))
{
beneath ()->fetch_registers (regcache, regno);
return;
}
// handle it
}
ptids of GPU threads are crafted with the following pattern:
(pid, 1, wave id)
Where pid is the inferior's pid and "wave id" is the wave handle handed
to us by the amd-dbgapi library (in practice, a monotonically
incrementing integer). The idea is that on Linux systems, the
combination (pid != 1, lwp == 1) is not possible. lwp == 1 would always
belong to the init process, which would also have pid == 1 (and it's
improbable for the init process to offload work to the GPU and much less
for the user to debug it). We can therefore differentiate GPU and
non-GPU ptids this way. See ptid_is_gpu for more details.
Note that we believe that this scheme could break down in the context of
containers, where the initial process executed in a container has pid 1
(in its own pid namespace). For instance, if you were to execute a ROCm
program in a container, then spawn a GDB in that container and attach to
the process, it will likely not work. This is a known limitation. A
workaround for this is to have a dummy process (like a shell) fork and
execute the program of interest.
The amd-dbgapi target watches native inferiors, and "attaches" to them
using amd_dbgapi_process_attach, which gives it a notifier fd that is
registered in the event loop (see enable_amd_dbgapi). Note that this
isn't the same "attach" as in PTRACE_ATTACH, but being ptrace-attached
is a precondition for amd_dbgapi_process_attach to work. When the
debugged process enables the ROCm runtime, the amd-dbgapi target gets
notified through that fd, and pushes itself on the target stack of the
inferior. The amd-dbgapi target is then able to intercept target_ops
calls. If the debugged process disables the ROCm runtime, the
amd-dbgapi target unpushes itself from the target stack.
This way, the amd-dbgapi target's footprint stays minimal when debugging
a process that doesn't use the AMD ROCm platform, it does not intercept
target calls.
The amd-dbgapi library is found using pkg-config. Since enabling
support for the amdgpu architecture (amdgpu-tdep.c) depends on the
amd-dbgapi library being present, we have the following logic for
the interaction with --target and --enable-targets:
- if the user explicitly asks for amdgcn support with
--target=amdgcn-*-* or --enable-targets=amdgcn-*-*, we probe for
the amd-dbgapi and fail if not found
- if the user uses --enable-targets=all, we probe for amd-dbgapi,
enable amdgcn support if found, disable amdgcn support if not found
- if the user uses --enable-targets=all and --with-amd-dbgapi=yes,
we probe for amd-dbgapi, enable amdgcn if found and fail if not found
- if the user uses --enable-targets=all and --with-amd-dbgapi=no,
we do not probe for amd-dbgapi, disable amdgcn support
- otherwise, amd-dbgapi is not probed for and support for amdgcn is not
enabled
Finally, a simple test is included. It only tests hitting a breakpoint
in device code and resuming execution, pretty much like the example
shown above.
[1] https://docs.amd.com/category/ROCm_v5.4
[2] https://docs.amd.com/bundle/HIP-Programming-Guide-v5.4
[3] https://en.wikipedia.org/wiki/Single_instruction,_multiple_threads
[4] https://docs.amd.com/bundle/ROCDebugger-API-Guide-v5.4
Change-Id: I591edca98b8927b1e49e4b0abe4e304765fed9ee
Co-Authored-By: Zoran Zaric <zoran.zaric@amd.com>
Co-Authored-By: Laurent Morichetti <laurent.morichetti@amd.com>
Co-Authored-By: Tony Tye <Tony.Tye@amd.com>
Co-Authored-By: Lancelot SIX <lancelot.six@amd.com>
Co-Authored-By: Pedro Alves <pedro@palves.net>
|
|
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.
|
|
Some register sets described by an array of regcache_map_entry
structures do not have fixed register numbers in their associated
architecture but do describe a block of registers whose numbers are at
fixed offsets relative to some base register value. An example of
this are the TLS register sets for the ARM and AArch64 architectures.
Currently OS-specific architectures create register maps and register
sets dynamically using the register base number. However, this
requires duplicating the code to create the register map and register
set. To reduce duplication, add variants of the collect_regset and
supply_regset regcache methods which accept a base register number.
For valid register map entries (i.e. not REGCACHE_MAP_SKIP), add this
base register number to the value from the map entry to determine the
final register number.
Approved-By: Simon Marchi <simon.marchi@efficios.com>
|
|
Currently, every internal_error call must be passed __FILE__/__LINE__
explicitly, like:
internal_error (__FILE__, __LINE__, "foo %d", var);
The need to pass in explicit __FILE__/__LINE__ is there probably
because the function predates widespread and portable variadic macros
availability. We can use variadic macros nowadays, and in fact, we
already use them in several places, including the related
gdb_assert_not_reached.
So this patch renames the internal_error function to something else,
and then reimplements internal_error as a variadic macro that expands
__FILE__/__LINE__ itself.
The result is that we now should call internal_error like so:
internal_error ("foo %d", var);
Likewise for internal_warning.
The patch adjusts all calls sites. 99% of the adjustments were done
with a perl/sed script.
The non-mechanical changes are in gdbsupport/errors.h,
gdbsupport/gdb_assert.h, and gdb/gdbarch.py.
Approved-By: Simon Marchi <simon.marchi@efficios.com>
Change-Id: Ia6f372c11550ca876829e8fd85048f4502bdcf06
|
|
I looked at all the spots using value_mark, and converted all the
straightforward ones to use scoped_value_mark instead.
Regression tested on x86-64 Fedora 34.
|
|
After the previous few commit, gdbarch_register_name no longer returns
nullptr. This commit audits all the calls to gdbarch_register_name
and removes any code that checks the result against nullptr.
There should be no visible change after this commit.
|
|
Remove the macro, replace all uses with calls to type::length.
Change-Id: Ib9bdc954576860b21190886534c99103d6a47afb
|
|
gdbarch implements its own registry-like approach. This patch changes
it to instead use registry.h. It's a rather large patch but largely
uninteresting -- it's mostly a straightforward conversion from the old
approach to the new one.
The main benefit of this change is that it introduces type safety to
the gdbarch registry. It also removes a bunch of code.
One possible drawback is that, previously, the gdbarch registry
differentiated between pre- and post-initialization setup. This
doesn't seem very important to me, though.
|
|
With --enable-targets=all we have:
...
$ gdb -q -batch -ex "maint selftest"
...
Running selftest regcache::cooked_read_test::m68hc11.
warning: No frame soft register found in the symbol table.
Stack backtrace will not work.
Running selftest regcache::cooked_read_test::m68hc12.
warning: No frame soft register found in the symbol table.
Stack backtrace will not work.
Running selftest regcache::cooked_read_test::m68hc12:HCS12.
warning: No frame soft register found in the symbol table.
Stack backtrace will not work.
...
Likewise for regcache::cooked_write_test.
The warning has no use in the selftest context.
Fix this by skipping the specific selftests.
Tested on x86_64-linux.
Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=29224
|
|
native-extended-gdbserver board
Running
$ make check TESTS="gdb.gdb/unittest.exp" RUNTESTFLAGS="--target_board=native-extended-gdbserver"
I get some failures:
Running selftest regcache::cooked_write_test::i386.^M
Self test failed: target already pushed^M
Running selftest regcache::cooked_write_test::i386:intel.^M
Self test failed: target already pushed^M
Running selftest regcache::cooked_write_test::i386:x64-32.^M
Self test failed: target already pushed^M
Running selftest regcache::cooked_write_test::i386:x64-32:intel.^M
Self test failed: target already pushed^M
Running selftest regcache::cooked_write_test::i386:x86-64.^M
Self test failed: target already pushed^M
Running selftest regcache::cooked_write_test::i386:x86-64:intel.^M
Self test failed: target already pushed^M
Running selftest regcache::cooked_write_test::i8086.^M
Self test failed: target already pushed^M
This is because the native-extended-gdbserver automatically connects GDB
to a GDBserver on startup, and therefore pushes a remote target on the
initial inferior. cooked_write_test is currently written in a way that
errors out if the current inferior has a process_stratum_target pushed.
Rewrite it to use scoped_mock_context, so it doesn't depend on the
current inferior (the current one upon entering the function).
Change-Id: I0357f989eacbdecc4bf88b043754451b476052ad
|
|
Now that filtered and unfiltered output can be treated identically, we
can unify the printf family of functions. This is done under the name
"gdb_printf". Most of this patch was written by script.
|
|
When registers are supplied via regcache_supply_register from a
register block described by a register map, registers may be stored in
slots smaller than GDB's native register size (e.g. x86 segment
registers are 16 bits, but the GDB registers for those are 32-bits).
regcache_collect_regset is careful to zero-extend slots larger than a
register size, but regcache_supply_regset just used
regcache::raw_supply_part and did not initialize the upper bytes of a
register value.
trad_frame_set_reg_regmap assumes these semantics (zero-extending
short registers). Upcoming patches also require these semantics for
handling x86 segment register values stored in 16-bit slots on
FreeBSD. Note that architecturally x86 segment registers are 16 bits,
but the x86 gdb architectures treat these registers as 32 bits.
|
|
There are several commands that may optionally send their output to a
file -- they take an optional filename argument and open a file. This
patch changes these commands to use filtered output. The rationale
here is that, when printing to gdb_stdout, filtering is appropriate --
it is, and should be, the default for all commands. And, when writing
to a file, paging will not happen anyway (it only happens when the
stream==gdb_stdout), so using the _filtered form will not change
anything.
|
|
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.
|
|
I think it would make sense for extract_integer, extract_signed_integer
and extract_unsigned_integer to take an array_view. This way, when we
extract an integer, we can validate that we don't overflow the buffer
passed by the caller (e.g. ask to extract a 4-byte integer but pass a
2-byte buffer).
- Change extract_integer to take an array_view
- Add overloads of extract_signed_integer and extract_unsigned_integer
that take array_views. Keep the existing versions so we don't
need to change all callers, but make them call the array_view
versions.
This shortens some places like:
result = extract_unsigned_integer (value_contents (result_val).data (),
TYPE_LENGTH (value_type (result_val)),
byte_order);
into
result = extract_unsigned_integer (value_contents (result_val), byte_order);
value_contents returns an array view that is of length
`TYPE_LENGTH (value_type (result_val))` already, so the length is
implicitly communicated through the array view.
Change-Id: Ic1c1f98c88d5c17a8486393af316f982604d6c95
|
|
The bug fixed by this [1] patch was caused by an out-of-bounds access to
a value's content. The code gets the value's content (just a pointer)
and then indexes it with a non-sensical index.
This made me think of changing functions that return value contents to
return array_views instead of a plain pointer. This has the advantage
that when GDB is built with _GLIBCXX_DEBUG, accesses to the array_view
are checked, making bugs more apparent / easier to find.
This patch changes the return types of these functions, and updates
callers to call .data() on the result, meaning it's not changing
anything in practice. Additional work will be needed (which can be done
little by little) to make callers propagate the use of array_view and
reap the benefits.
[1] https://sourceware.org/pipermail/gdb-patches/2021-September/182306.html
Change-Id: I5151f888f169e1c36abe2cbc57620110673816f3
|
|
This helper can be used in the fetch_registers and store_registers
target methods to determine if a register set includes a specific
register.
|
|
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>
|
|
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 <simon.marchi@efficios.com>
Change-Id: I7eb6a8f867d4dcf8b8cd2dcffd118f7270756018
|
|
I spotted some indentation issues where we had some spaces followed by
tabs at beginning of line, that I wanted to fix. So while at it, I did
a quick grep to find and fix all I could find.
gdb/ChangeLog:
* Fix tab after space indentation issues throughout.
Change-Id: I1acb414dd9c593b474ae2b8667496584df4316fd
|
|
The alias creation functions currently accept a name to specify the
target command. They pass this to add_alias_cmd, which needs to lookup
the target command by name.
Given that:
- We don't support creating an alias for a command before that command
exists.
- We always use add_info_alias just after creating that target command,
and therefore have access to the target command's cmd_list_element.
... change add_com_alias to accept the target command as a
cmd_list_element (other functions are done in subsequent patches). This
ensures we don't create the alias before the target command, because you
need to get the cmd_list_element from somewhere when you call the alias
creation function. And it avoids an unecessary command lookup. So it
seems better to me in every aspect.
gdb/ChangeLog:
* command.h (add_com_alias): Accept target as
cmd_list_element. Update callers.
Change-Id: I24bed7da57221cc77606034de3023fedac015150
|
|
The reg_buffer constructor zero-initializes (value-initializes, in C++
speak) the gdb_bytes of the m_registers array. This is not necessary,
as these bytes are only meaningful if the corresponding register_status
is REG_VALID. If the corresponding register_status is REG_VALID, then
they will have been overwritten with the actual register data when
reading the registers from the system into the reg_buffer.
Fix that by removing the empty parenthesis following the new expression,
meaning that the bytes will now be default-initialized, meaning they'll
be left uninitialized. For reference, this is explained here:
https://en.cppreference.com/w/cpp/language/new#Construction
These new expressions were added in 835dcf92618e ("Use std::unique_ptr
in reg_buffer"). As mentioned in that commit message, the use of
value-initialisation was done on purpose to keep existing behavior, but
now there is some data that suggest it would be beneficial not to do it,
which is why I suggest changing it.
This doesn't make a big difference on typical architectures where the
register buffer is not that big. However, on ROCm (AMD GPU), the
register buffer is about 65000 bytes big, so the reg_buffer constructor
shows up in profiling. If you want to make some tests and profile it on
a standard system, it's always possible to change:
- m_registers.reset (new gdb_byte[m_descr->sizeof_raw_registers] ());
+ m_registers.reset (new gdb_byte[65000] ());
and run a program that constantly hits a breakpoint with a false
condition. For example, by doing this change and running the following
program:
static void break_here () {}
int main ()
{
for (int i = 0; i < 100000; i++)
break_here ();
}
with the following GDB incantation:
/usr/bin/time ./gdb -nx --data-directory=data-directory -q test -ex "b break_here if 0" -ex r -batch
I get, for value-intializing:
11.75user 7.68system 0:18.54elapsed 104%CPU (0avgtext+0avgdata 56644maxresident)k
And for default-initializing:
6.83user 8.42system 0:14.12elapsed 108%CPU (0avgtext+0avgdata 56512maxresident)k
gdb/ChangeLog:
* regcache.c (reg_buffer::reg_buffer): Default-initialize
m_registers array.
Change-Id: I5071a4444dee0530ce1bc58ebe712024ddd2b158
|
|
Give a name to each observer, this will help produce more meaningful
debug message.
gdbsupport/ChangeLog:
* observable.h (class observable) <struct observer> <observer>:
Add name parameter.
<name>: New field.
<attach>: Add name parameter, update all callers.
Change-Id: Ie0cc4664925215b8d2b09e026011b7803549fba0
|
|
The current_top_target function is a hidden dependency on the current
inferior. Since I'd like to slowly move towards reducing our dependency
on the global current state, remove this function and make callers use
current_inferior ()->top_target ()
There is no expected change in behavior, but this one step towards
making those callers use the inferior from their context, rather than
refer to the global current inferior.
gdb/ChangeLog:
* target.h (current_top_target): Remove, make callers use the
current inferior instead.
* target.c (current_top_target): Remove.
Change-Id: Iccd457036f84466cdaa3865aa3f9339a24ea001d
|
|
Same as the previous patch, but for the push_target functions.
The implementation of the move variant is moved to a new overload of
inferior::push_target.
gdb/ChangeLog:
* target.h (push_target): Remove, update callers to use
inferior::push_target.
* target.c (push_target): Remove.
* inferior.h (class inferior) <push_target>: New overload.
Change-Id: I5a95496666278b8f3965e5e8aecb76f54a97c185
|
|
I'm trying to enable clang's -Wmissing-variable-declarations warning.
This patch fixes all the obvious spots where we can simply add "static"
(at least, found when building on x86-64 Linux).
gdb/ChangeLog:
* aarch64-linux-tdep.c (aarch64_linux_record_tdep): Make static.
* aarch64-tdep.c (tdesc_aarch64_list, aarch64_prologue_unwind,
aarch64_stub_unwind, aarch64_normal_base, ): Make static.
* arm-linux-tdep.c (arm_prologue_unwind): Make static.
* arm-tdep.c (struct frame_unwind): Make static.
* auto-load.c (auto_load_safe_path_vec): Make static.
* csky-tdep.c (csky_stub_unwind): Make static.
* gdbarch.c (gdbarch_data_registry): Make static.
* gnu-v2-abi.c (gnu_v2_abi_ops): Make static.
* i386-netbsd-tdep.c (i386nbsd_mc_reg_offset): Make static.
* i386-tdep.c (i386_frame_setup_skip_insns,
i386_tramp_chain_in_reg_insns, i386_tramp_chain_on_stack_insns):
Make static.
* infrun.c (observer_mode): Make static.
* linux-nat.c (sigchld_action): Make static.
* linux-thread-db.c (thread_db_list): Make static.
* maint-test-options.c (maintenance_test_options_list):
* mep-tdep.c (mep_csr_registers): Make static.
* mi/mi-cmds.c (struct mi_cmd_stats): Remove struct type name.
(stats): Make static.
* nat/linux-osdata.c (struct osdata_type): Make static.
* ppc-netbsd-tdep.c (ppcnbsd_reg_offsets): Make static.
* progspace.c (last_program_space_num): Make static.
* python/py-param.c (struct parm_constant): Remove struct type
name.
(parm_constants): Make static.
* python/py-record-btrace.c (btpy_list_methods): Make static.
* python/py-record.c (recpy_gap_type): Make static.
* record.c (record_goto_cmdlist): Make static.
* regcache.c (regcache_descr_handle): Make static.
* registry.h (DEFINE_REGISTRY): Make definition static.
* symmisc.c (std_in, std_out, std_err): Make static.
* top.c (previous_saved_command_line): Make static.
* tracepoint.c (trace_user, trace_notes, trace_stop_notes): Make
static.
* unittests/command-def-selftests.c (nr_duplicates,
nr_invalid_prefixcmd, lists): Make static.
* unittests/observable-selftests.c (test_notification): Make
static.
* unittests/optional/assignment/1.cc (counter): Make static.
* unittests/optional/assignment/2.cc (counter): Make static.
* unittests/optional/assignment/3.cc (counter): Make static.
* unittests/optional/assignment/4.cc (counter): Make static.
* unittests/optional/assignment/5.cc (counter): Make static.
* unittests/optional/assignment/6.cc (counter): Make static.
gdbserver/ChangeLog:
* ax.cc (bytecode_address_table): Make static.
* debug.cc (debug_file): Make static.
* linux-low.cc (stopping_threads): Make static.
(step_over_bkpt): Make static.
* linux-x86-low.cc (amd64_emit_ops, i386_emit_ops): Make static.
* tracepoint.cc (stop_tracing_bkpt, flush_trace_buffer_bkpt,
alloced_trace_state_variables, trace_buffer_ctrl,
tracing_start_time, tracing_stop_time, tracing_user_name,
tracing_notes, tracing_stop_note): Make static.
Change-Id: Ic1d8034723b7802502bda23770893be2338ab020
|
|
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.
|
|
We currently have two flushing commands 'flushregs' and 'maint
flush-symbol-cache'. I'm planning to add at least one more so I
thought it might be nice if we bundled these together into one place.
And so I created the 'maint flush ' command prefix. Currently there
are two commands:
(gdb) maint flush symbol-cache
(gdb) maint flush register-cache
Unfortunately, even though both of the existing flush commands are
maintenance commands, I don't know how keen we about deleting existing
commands for fear of breaking things in the wild. So, both of the
existing flush commands 'maint flush-symbol-cache' and 'flushregs' are
still around as deprecated aliases to the new commands.
I've updated the testsuite to use the new command syntax, and updated
the documentation too.
gdb/ChangeLog:
* NEWS: Mention new commands, and that the old commands are now
deprecated.
* cli/cli-cmds.c (maintenanceflushlist): Define.
* cli/cli-cmds.h (maintenanceflushlist): Declare.
* maint.c (_initialize_maint_cmds): Initialise
maintenanceflushlist.
* regcache.c: Add 'cli/cli-cmds.h' include.
(reg_flush_command): Add header comment.
(_initialize_regcache): Create new 'maint flush register-cache'
command, make 'flushregs' an alias.
* symtab.c: Add 'cli/cli-cmds.h' include.
(_initialize_symtab): Create new 'maint flush symbol-cache'
command, make old command an alias.
gdb/doc/ChangeLog:
* gdb.texinfo (Symbols): Document 'maint flush symbol-cache'.
(Maintenance Commands): Document 'maint flush register-cache'.
gdb/testsuite/ChangeLog:
* gdb.base/c-linkage-name.exp: Update to use new 'maint flush ...'
commands.
* gdb.base/killed-outside.exp: Likewise.
* gdb.opt/inline-bt.exp: Likewise.
* gdb.perf/gmonster-null-lookup.py: Likewise.
* gdb.perf/gmonster-print-cerr.py: Likewise.
* gdb.perf/gmonster-ptype-string.py: Likewise.
* gdb.python/py-unwind.exp: Likewise.
|
|
As reported by Tom here [1], commit 888bdb2b7445 ("gdb: change regcache
list to be a map") overlooked an important case, causing a regression.
When registers_changed_ptid is called with a pid-like ptid, it used to
clear all the regcaches for that pid. That commit accidentally removed
that behavior. We need to handle the `ptid.is_pid ()` case in
registers_changed_ptid.
The most trivial way of fixing it would be to iterate on all ptids of a
target and delete the entries where the ptid match the pid. But the
point of that commit was to avoid having to iterate on ptids to
invalidate regcaches, so that would feel like a step backwards.
The only logical solution I see is to add yet another map level, so that
we now have:
target -> (pid -> (ptid -> regcaches))
This patch implements that and adds a test for the case of calling
registers_changed_ptid with a pid-like ptid.
[1] https://sourceware.org/pipermail/gdb-patches/2020-August/171222.html
gdb/ChangeLog:
* regcache.c (pid_ptid_regcache_map): New type.
(target_ptid_regcache_map): Remove.
(target_pid_ptid_regcache_map): New type.
(regcaches): Change type to target_pid_ptid_regcache_map.
(get_thread_arch_aspace_regcache): Update.
(regcache_thread_ptid_changed): Update, handle pid-like ptid
case.
(regcaches_size): Update.
(regcache_count): Update.
(registers_changed_ptid_target_pid_test): New.
(_initialize_regcache): Register new test.
Change-Id: I4c46e26d8225c177dbac9488b549eff4c68fa0d8
|
|
The selftest `regcaches` selftest is a bit too broad for my taste,
testing the behavior of get_thread_arch_aspace_regcache and various
cases of registers_changed_ptid. Since I'll want to test even more
scenarios of registers_changed_ptid, passing different sets of
parameters, it will be difficult to do in a single test case. It is
difficult to change something at some point in the test case while make
sure it doesn't compromise what comes after, that we still test the
scenarios that we intended to test. So, split the test case in multiple
smaller ones.
- Split the test case in multiple, where each test case starts from
scratch and tests one specific scenario.
- Introduce the populate_regcaches_for_test function, which is used by
the various test cases to start with a regcache container populated
with a few regcaches for two different targets.
- populate_regcaches_for_test returns a regcache_test_data object, which
contains the test targets that were used to create the regcaches. It
also takes care to call registers_changed at the beginning and end of
the test to ensure the test isn't influenced by existing regcaches,
and cleans up after itself.
- Move the regcache_count lambda function out of
regcache_thread_ptid_changed, so it can be used in
other tests.
- For get_thread_arch_aspace_regcache, test that getting a regcache that
already exists does not increase the count of existing regcaches.
- For registers_changed_ptid, test the three cases we handle today:
(nullptr, minus_one_ptid), (target, minus_one_ptid) and (target,
ptid). The (target, minus_one_ptid) case was not tested prior to this
patch.
gdb/ChangeLog:
* regcache.c (regcache_count): New.
(struct regcache_test_data): New.
(regcache_test_data_up): New.
(populate_regcaches_for_test): New.
(regcaches_test): Remove.
(get_thread_arch_aspace_regcache_test): New.
(registers_changed_ptid_all_test): New.
(registers_changed_ptid_target_test): New.
(registers_changed_ptid_target_ptid_test): New.
(regcache_thread_ptid_changed): Remove regcache_count lambda.
(_initialize_regcache): Register new tests.
Change-Id: Id4280879fb40ff3aeae49b01b95359e1359c3d4b
|
|
Do these misc changes to test_get_thread_arch_aspace_regcache:
- Rename to get_thread_arch_aspace_regcache_and_check. The following
patch introduces a selftest for get_thread_arch_aspace_regcache, named
get_thread_arch_aspace_regcache_test. To avoid confusion between the
two functions, rename this one to
get_thread_arch_aspace_regcache_and_check, I think it describes better
what it does.
- Remove gdbarch parameter. We always pass the same gdbarch (the
current inferior's gdbarch), so having a parameter is not useful. It
would be interesting to actually test with multiple gdbarches, to
verify that the regcache container can hold multiple regcaches (with
different architectures) for a same (target, ptid). But it's not the
case as of this patch.
- Verify that the regcache's arch is correctly set.
- Remove the aspace parameter. We always pass NULL here, so it's not
useful to have it as a parameter. Also, instead of passing a NULL
aspace to get_thread_arch_aspace_regcache and verifying that we get a
NULL aspace back, pass the current inferior's aspace (just like we use
the current inferior's gdbarch).
gdb/ChangeLog:
* regcache.c (test_get_thread_arch_aspace_regcache): Rename to...
(get_thread_arch_aspace_regcache_and_check): ... this. Remove
gdbarch and aspace parameter. Use current inferior's aspace.
Validate regcache's arch value.
(regcaches_test): Update.
Change-Id: I8b4c2303b4f91f062269043d1f7abe1650232010
|
|
It currently does not work to run the `regcaches` selftest while
debugging something. This is because we expect that there exists no
regcache at the start of the test. If we are debugging something, there
might exist some regcaches.
Fix it by making the test clear regcaches at the start.
While at it, make the test clean up after it self and clear the
regcaches at the end too.
gdb/ChangeLog:
* regcache.c (regcaches_test): Call registers_changed.
Change-Id: I9d4f83ecb0ff9721a71e2c5cbd19e6e6d4e6c30c
|
|
When building gdb on x86_64-linux with --enable-targets riscv64-suse-linux, I
run into:
...
src/gdb/arch/riscv.c:112:45: required from here
/usr/include/c++/4.8/bits/hashtable_policy.h:195:39: error: no matching \
function for call to 'std::pair<const riscv_gdbarch_features, const \
std::unique_ptr<target_desc, target_desc_deleter> >::pair(const \
riscv_gdbarch_features&, target_desc*&)'
: _M_v(std::forward<_Args>(__args)...) { }
^
...
for this code in riscv_lookup_target_description:
...
/* Add to the cache. */
riscv_tdesc_cache.emplace (features, tdesc);
...
Work around this compiler problem (filed as PR gcc/96537), similar to how that
was done in commit 6d0cf4464e "Fix build with gcc-4.8.x":
...
- riscv_tdesc_cache.emplace (features, tdesc);
+ riscv_tdesc_cache.emplace (features, target_desc_up (tdesc));
...
That is, call the target_desc_up constructor explictly instead of implicitly.
Also, work around a similar issue in get_thread_arch_aspace_regcache.
Build on x86_64-linux with --enable-targets riscv64-suse-linux, and
reg-tested.
gdb/ChangeLog:
2020-08-08 Tom de Vries <tdevries@suse.de>
PR build/26344
* arch/riscv.c (riscv_lookup_target_description): Use an explicit
constructor.
* regcache.c (get_thread_arch_aspace_regcache): Same.
|
|
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
|
|
I noticed what I think is a potential bug. I did not observe it nor was
I able to reproduce it using actual debugging. It's quite unlikely,
because it involves multi-target and ptid clashes. I added selftests
that demonstrate it though.
The thread_ptid_changed observer says that thread with OLD_PTID now has
NEW_PTID. Now, if for some reason we happen to have two targets
defining a thread with OLD_PTID, the observers don't know which thread
this is about.
regcache::regcache_thread_ptid_changed changes all regcaches with
OLD_PTID. If there is a regcache for a thread with ptid OLD_PTID, but
that belongs to a different target, this regcache will be erroneously
changed.
Similarly, infrun_thread_ptid_changed updates inferior_ptid if
inferior_ptid matches OLD_PTID. But if inferior_ptid currently refers
not to the thread is being changed, but to a thread with the same ptid
belonging to a different target, then inferior_ptid will erroneously be
changed.
This patch adds a `process_stratum_target *` parameter to the
`thread_ptid_changed` observable and makes the two observers use it.
Tests for both are added, which would fail if the corresponding fix
wasn't done.
gdb/ChangeLog:
* observable.h (thread_ptid_changed): Add parameter
`process_stratum_target *`.
* infrun.c (infrun_thread_ptid_changed): Add parameter
`process_stratum_target *` and use it.
(selftests): New namespace.
(infrun_thread_ptid_changed): New function.
(_initialize_infrun): Register selftest.
* regcache.c (regcache_thread_ptid_changed): Add parameter
`process_stratum_target *` and use it.
(regcache_thread_ptid_changed): New function.
(_initialize_regcache): Register selftest.
* thread.c (thread_change_ptid): Pass target to
thread_ptid_changed observable.
Change-Id: I0599e61224b6d154a7b55088a894cb88298c3c71
|
|
I don't really understand why `regcache_thread_ptid_changed` is a static
method of `struct regcache` instead of being a static free function in
regcache.c. And I don't understand why `current_regcache` is a static
member of `struct regcache` instead of being a static global in
regcache.c. It's not wrong per-se, but there's no other place where we
do it like this in GDB (as far as I remember) and it just exposes things
unnecessarily in the .h.
Move them to be just static in regcache.c. As a result,
registers_changed_ptid doesn't need to be friend of the regcache class
anymore.
Removing the include of forward_list in regcache.h showed that we were
missing an include for it in dwarf2/index-write.c, record-btrace.c and
sparc64-tdep.c.
gdb/ChangeLog:
* regcache.h (class regcache): Remove friend
registers_changed_ptid.
<regcache_thread_ptid_changed>: Remove.
<regcaches>: Remove.
* regcache.c (regcache::regcaches): Rename to...
(regcaches): ... this. Make static.
(get_thread_arch_aspace_regcache): Update.
(regcache::regcache_thread_ptid_changed): Rename to...
(regcache_thread_ptid_changed): ... this. Update.
(class regcache_access): Remove.
(regcaches_test): Update.
(_initialize_regcache): Update.
* sparc64-tdep.c, dwarf2/index-write.c, record-btrace.c: Include
<forward_list>.
Change-Id: Iabc25759848010cfbb7ee7e27f60eaca17d61c12
|
|
The name `current_regcache` for the list of currently-existing regcaches
sounds wrong. The name is singular, but it holds multiple regcaches, so
it could at least be `current_regcaches`.
But in other places in GDB, "current" usually means "the object we are
working with right now". For example, we swap the "current thread" when
we want to operate on a given thread. This is not the case here, this
variable just holds all regcaches that exist at any given time, not "the
regcache we are working with right now".
So, I think calling it `regcaches` is better. I also considered
`regcache_list`, but a subsequent patch will make it a map and not a
list, so it would sound wrong again. `regcaches` sounds right for any
collection of regcache, whatever the type.
Rename a few other things that were related to this `current_regcache`
field. Note that there is a `get_current_regcache` function, which
returns the regcache of the current thread. That one is fine, because
it returns the regcache for the current thread.
gdb/ChangeLog:
* regcache.h (class regcache) <current_regcache>: Rename to...
<regcaches>: ... this. Move doc here.
* regcache.c (regcache::current_regcache) Rename to...
(regcache::regcaches): ... this. Move doc to header.
(get_thread_arch_aspace_regcache): Update.
(regcache::regcache_thread_ptid_changed): Update.
(registers_changed_ptid): Update.
(class regcache_access) <current_regcache_size>: Rename to...
<regcaches_size>: ... this.
(current_regcache_test): Rename to...
(regcaches_test): ... this.
(_initialize_regcache): Update.
Change-Id: I87de67154f5fe17a1f6aee7c4f2036647ee27b99
|
|
This commit:
commit 3922b302645fda04da42a5279399578ae2f6206c
Author: Pedro Alves <palves@redhat.com>
AuthorDate: Thu Jun 18 21:28:37 2020 +0100
Decouple inferior_ptid/inferior_thread(); dup ptids in thread list (PR 25412)
caused a regression for gdb.gdb/unittest.exp when GDB is configured
with --enable-targets=all. The failure is:
gdb/thread.c:95: internal-error: thread_info* inferior_thread(): Assertion `current_thread_ != nullptr' failed.
The problem is in this line in regcache.c:cooked_read_test:
/* Switch to the mock thread. */
scoped_restore restore_inferior_ptid
= make_scoped_restore (&inferior_ptid, mock_ptid);
Both gdbarch-selftest.c and regcache.c set up a similar mock context,
but the series the patch above belongs to only updated the
gdbarch-selftest.c context to not write to inferior_ptid directly, and
missed updating regcache.c's.
Instead of copying the fix over to regcache.c, share the mock context
setup code in a new RAII class, based on gdbarch-selftest.c's version.
Also remove the "target already pushed" error from regcache.c, like it
had been removed from gdbarch-selftest.c in the multi-target series.
That check is unnecessary because each inferior now has its own target
stack, and the unit test pushes a target on a separate (mock)
inferior, not the current inferior on entry.
gdb/ChangeLog:
2020-06-23 Pedro Alves <palves@redhat.com>
* gdbarch-selftests.c: Don't include inferior.h, gdbthread.h or
progspace-and-thread.h. Include scoped-mock-context.h instead.
(register_to_value_test): Use scoped_mock_context.
* regcache.c: Include "scoped-mock-context.h".
(cooked_read_test): Don't error out if a target is already pushed.
Use scoped_mock_context. Adjust.
* scoped-mock-context.h: New file.
|
|
Remove `TYPE_NAME`, changing all the call sites to use `type::name`
directly. This is quite a big diff, but this was mostly done using sed
and coccinelle. A few call sites were done by hand.
gdb/ChangeLog:
* gdbtypes.h (TYPE_NAME): Remove. Change all cal sites to use
type::name instead.
|
|
Remove TYPE_CODE, changing all the call sites to use type::code
directly. This is quite a big diff, but this was mostly done using sed
and coccinelle. A few call sites were done by hand.
gdb/ChangeLog:
* gdbtypes.h (TYPE_CODE): Remove. Change all call sites to use
type::code instead.
|
|
It possible that a thread whose PC we attempt to read is already dead.
In this case, 'regcache_read_pc' errors out. This impacts the
"proceed" execution flow, where GDB quits early before having a chance
to check if there exists a pending event. To remedy, keep going with
a 0 value for the PC if 'regcache_read_pc' fails. Because the value
of PC before resuming a thread is mostly used for storing and checking
the next time the thread stops, this tolerance is expected to be
harmless for a dead thread/process.
gdb/ChangeLog:
2020-05-14 Tankut Baris Aktemur <tankut.baris.aktemur@intel.com>
* regcache.c (regcache_read_pc_protected): New function
implementation that returns 0 if the PC cannot read via
'regcache_read_pc'.
* infrun.c (proceed): Call 'regcache_read_pc_protected'
instead of 'regcache_read_pc'.
(keep_going_pass_signal): Ditto.
gdbsupport/ChangeLog:
2020-05-14 Tankut Baris Aktemur <tankut.baris.aktemur@intel.com>
* common-regcache.h (regcache_read_pc_protected): New function
declaration.
|
|
I'd like to enable the -Wmissing-declarations warning. However, it
warns for every _initialize function, for example:
CXX dcache.o
/home/smarchi/src/binutils-gdb/gdb/dcache.c: In function ‘void _initialize_dcache()’:
/home/smarchi/src/binutils-gdb/gdb/dcache.c:688:1: error: no previous declaration for ‘void _initialize_dcache()’ [-Werror=missing-declarations]
_initialize_dcache (void)
^~~~~~~~~~~~~~~~~~
The only practical way forward I found is to add back the declarations,
which were removed by this commit:
commit 481695ed5f6e0a8a9c9c50bfac1cdd2b3151e6c9
Author: John Baldwin <jhb@FreeBSD.org>
Date: Sat Sep 9 11:02:37 2017 -0700
Remove unnecessary function prototypes.
I don't think it's a big problem to have the declarations for these
functions, but if anybody has a better solution for this, I'll be happy
to use it.
gdb/ChangeLog:
* aarch64-fbsd-nat.c (_initialize_aarch64_fbsd_nat): Add declaration.
* aarch64-fbsd-tdep.c (_initialize_aarch64_fbsd_tdep): Add declaration.
* aarch64-linux-nat.c (_initialize_aarch64_linux_nat): Add declaration.
* aarch64-linux-tdep.c (_initialize_aarch64_linux_tdep): Add declaration.
* aarch64-newlib-tdep.c (_initialize_aarch64_newlib_tdep): Add declaration.
* aarch64-tdep.c (_initialize_aarch64_tdep): Add declaration.
* ada-exp.y (_initialize_ada_exp): Add declaration.
* ada-lang.c (_initialize_ada_language): Add declaration.
* ada-tasks.c (_initialize_tasks): Add declaration.
* agent.c (_initialize_agent): Add declaration.
* aix-thread.c (_initialize_aix_thread): Add declaration.
* alpha-bsd-nat.c (_initialize_alphabsd_nat): Add declaration.
* alpha-linux-nat.c (_initialize_alpha_linux_nat): Add declaration.
* alpha-linux-tdep.c (_initialize_alpha_linux_tdep): Add declaration.
* alpha-nbsd-tdep.c (_initialize_alphanbsd_tdep): Add declaration.
* alpha-obsd-tdep.c (_initialize_alphaobsd_tdep): Add declaration.
* alpha-tdep.c (_initialize_alpha_tdep): Add declaration.
* amd64-darwin-tdep.c (_initialize_amd64_darwin_tdep): Add declaration.
* amd64-dicos-tdep.c (_initialize_amd64_dicos_tdep): Add declaration.
* amd64-fbsd-nat.c (_initialize_amd64fbsd_nat): Add declaration.
* amd64-fbsd-tdep.c (_initialize_amd64fbsd_tdep): Add declaration.
* amd64-linux-nat.c (_initialize_amd64_linux_nat): Add declaration.
* amd64-linux-tdep.c (_initialize_amd64_linux_tdep): Add declaration.
* amd64-nbsd-nat.c (_initialize_amd64nbsd_nat): Add declaration.
* amd64-nbsd-tdep.c (_initialize_amd64nbsd_tdep): Add declaration.
* amd64-obsd-nat.c (_initialize_amd64obsd_nat): Add declaration.
* amd64-obsd-tdep.c (_initialize_amd64obsd_tdep): Add declaration.
* amd64-sol2-tdep.c (_initialize_amd64_sol2_tdep): Add declaration.
* amd64-tdep.c (_initialize_amd64_tdep): Add declaration.
* amd64-windows-nat.c (_initialize_amd64_windows_nat): Add declaration.
* amd64-windows-tdep.c (_initialize_amd64_windows_tdep): Add declaration.
* annotate.c (_initialize_annotate): Add declaration.
* arc-newlib-tdep.c (_initialize_arc_newlib_tdep): Add declaration.
* arc-tdep.c (_initialize_arc_tdep): Add declaration.
* arch-utils.c (_initialize_gdbarch_utils): Add declaration.
* arm-fbsd-nat.c (_initialize_arm_fbsd_nat): Add declaration.
* arm-fbsd-tdep.c (_initialize_arm_fbsd_tdep): Add declaration.
* arm-linux-nat.c (_initialize_arm_linux_nat): Add declaration.
* arm-linux-tdep.c (_initialize_arm_linux_tdep): Add declaration.
* arm-nbsd-nat.c (_initialize_arm_netbsd_nat): Add declaration.
* arm-nbsd-tdep.c (_initialize_arm_netbsd_tdep): Add declaration.
* arm-obsd-tdep.c (_initialize_armobsd_tdep): Add declaration.
* arm-pikeos-tdep.c (_initialize_arm_pikeos_tdep): Add declaration.
* arm-symbian-tdep.c (_initialize_arm_symbian_tdep): Add declaration.
* arm-tdep.c (_initialize_arm_tdep): Add declaration.
* arm-wince-tdep.c (_initialize_arm_wince_tdep): Add declaration.
* auto-load.c (_initialize_auto_load): Add declaration.
* auxv.c (_initialize_auxv): Add declaration.
* avr-tdep.c (_initialize_avr_tdep): Add declaration.
* ax-gdb.c (_initialize_ax_gdb): Add declaration.
* bfin-linux-tdep.c (_initialize_bfin_linux_tdep): Add declaration.
* bfin-tdep.c (_initialize_bfin_tdep): Add declaration.
* break-catch-sig.c (_initialize_break_catch_sig): Add declaration.
* break-catch-syscall.c (_initialize_break_catch_syscall): Add declaration.
* break-catch-throw.c (_initialize_break_catch_throw): Add declaration.
* breakpoint.c (_initialize_breakpoint): Add declaration.
* bsd-uthread.c (_initialize_bsd_uthread): Add declaration.
* btrace.c (_initialize_btrace): Add declaration.
* charset.c (_initialize_charset): Add declaration.
* cli/cli-cmds.c (_initialize_cli_cmds): Add declaration.
* cli/cli-dump.c (_initialize_cli_dump): Add declaration.
* cli/cli-interp.c (_initialize_cli_interp): Add declaration.
* cli/cli-logging.c (_initialize_cli_logging): Add declaration.
* cli/cli-script.c (_initialize_cli_script): Add declaration.
* cli/cli-style.c (_initialize_cli_style): Add declaration.
* coff-pe-read.c (_initialize_coff_pe_read): Add declaration.
* coffread.c (_initialize_coffread): Add declaration.
* compile/compile-cplus-types.c (_initialize_compile_cplus_types): Add declaration.
* compile/compile.c (_initialize_compile): Add declaration.
* complaints.c (_initialize_complaints): Add declaration.
* completer.c (_initialize_completer): Add declaration.
* copying.c (_initialize_copying): Add declaration.
* corefile.c (_initialize_core): Add declaration.
* corelow.c (_initialize_corelow): Add declaration.
* cp-abi.c (_initialize_cp_abi): Add declaration.
* cp-namespace.c (_initialize_cp_namespace): Add declaration.
* cp-support.c (_initialize_cp_support): Add declaration.
* cp-valprint.c (_initialize_cp_valprint): Add declaration.
* cris-linux-tdep.c (_initialize_cris_linux_tdep): Add declaration.
* cris-tdep.c (_initialize_cris_tdep): Add declaration.
* csky-linux-tdep.c (_initialize_csky_linux_tdep): Add declaration.
* csky-tdep.c (_initialize_csky_tdep): Add declaration.
* ctfread.c (_initialize_ctfread): Add declaration.
* d-lang.c (_initialize_d_language): Add declaration.
* darwin-nat-info.c (_initialize_darwin_info_commands): Add declaration.
* darwin-nat.c (_initialize_darwin_nat): Add declaration.
* dbxread.c (_initialize_dbxread): Add declaration.
* dcache.c (_initialize_dcache): Add declaration.
* disasm-selftests.c (_initialize_disasm_selftests): Add declaration.
* disasm.c (_initialize_disasm): Add declaration.
* dtrace-probe.c (_initialize_dtrace_probe): Add declaration.
* dummy-frame.c (_initialize_dummy_frame): Add declaration.
* dwarf-index-cache.c (_initialize_index_cache): Add declaration.
* dwarf-index-write.c (_initialize_dwarf_index_write): Add declaration.
* dwarf2-frame-tailcall.c (_initialize_tailcall_frame): Add declaration.
* dwarf2-frame.c (_initialize_dwarf2_frame): Add declaration.
* dwarf2expr.c (_initialize_dwarf2expr): Add declaration.
* dwarf2loc.c (_initialize_dwarf2loc): Add declaration.
* dwarf2read.c (_initialize_dwarf2_read): Add declaration.
* elfread.c (_initialize_elfread): Add declaration.
* exec.c (_initialize_exec): Add declaration.
* extension.c (_initialize_extension): Add declaration.
* f-lang.c (_initialize_f_language): Add declaration.
* f-valprint.c (_initialize_f_valprint): Add declaration.
* fbsd-nat.c (_initialize_fbsd_nat): Add declaration.
* fbsd-tdep.c (_initialize_fbsd_tdep): Add declaration.
* filesystem.c (_initialize_filesystem): Add declaration.
* findcmd.c (_initialize_mem_search): Add declaration.
* findvar.c (_initialize_findvar): Add declaration.
* fork-child.c (_initialize_fork_child): Add declaration.
* frame-base.c (_initialize_frame_base): Add declaration.
* frame-unwind.c (_initialize_frame_unwind): Add declaration.
* frame.c (_initialize_frame): Add declaration.
* frv-linux-tdep.c (_initialize_frv_linux_tdep): Add declaration.
* frv-tdep.c (_initialize_frv_tdep): Add declaration.
* ft32-tdep.c (_initialize_ft32_tdep): Add declaration.
* gcore.c (_initialize_gcore): Add declaration.
* gdb-demangle.c (_initialize_gdb_demangle): Add declaration.
* gdb_bfd.c (_initialize_gdb_bfd): Add declaration.
* gdbarch-selftests.c (_initialize_gdbarch_selftests): Add declaration.
* gdbarch.c (_initialize_gdbarch): Add declaration.
* gdbtypes.c (_initialize_gdbtypes): Add declaration.
* gnu-nat.c (_initialize_gnu_nat): Add declaration.
* gnu-v2-abi.c (_initialize_gnu_v2_abi): Add declaration.
* gnu-v3-abi.c (_initialize_gnu_v3_abi): Add declaration.
* go-lang.c (_initialize_go_language): Add declaration.
* go32-nat.c (_initialize_go32_nat): Add declaration.
* guile/guile.c (_initialize_guile): Add declaration.
* h8300-tdep.c (_initialize_h8300_tdep): Add declaration.
* hppa-linux-nat.c (_initialize_hppa_linux_nat): Add declaration.
* hppa-linux-tdep.c (_initialize_hppa_linux_tdep): Add declaration.
* hppa-nbsd-nat.c (_initialize_hppanbsd_nat): Add declaration.
* hppa-nbsd-tdep.c (_initialize_hppanbsd_tdep): Add declaration.
* hppa-obsd-nat.c (_initialize_hppaobsd_nat): Add declaration.
* hppa-obsd-tdep.c (_initialize_hppabsd_tdep): Add declaration.
* hppa-tdep.c (_initialize_hppa_tdep): Add declaration.
* i386-bsd-nat.c (_initialize_i386bsd_nat): Add declaration.
* i386-cygwin-tdep.c (_initialize_i386_cygwin_tdep): Add declaration.
* i386-darwin-nat.c (_initialize_i386_darwin_nat): Add declaration.
* i386-darwin-tdep.c (_initialize_i386_darwin_tdep): Add declaration.
* i386-dicos-tdep.c (_initialize_i386_dicos_tdep): Add declaration.
* i386-fbsd-nat.c (_initialize_i386fbsd_nat): Add declaration.
* i386-fbsd-tdep.c (_initialize_i386fbsd_tdep): Add declaration.
* i386-gnu-nat.c (_initialize_i386gnu_nat): Add declaration.
* i386-gnu-tdep.c (_initialize_i386gnu_tdep): Add declaration.
* i386-go32-tdep.c (_initialize_i386_go32_tdep): Add declaration.
* i386-linux-nat.c (_initialize_i386_linux_nat): Add declaration.
* i386-linux-tdep.c (_initialize_i386_linux_tdep): Add declaration.
* i386-nbsd-nat.c (_initialize_i386nbsd_nat): Add declaration.
* i386-nbsd-tdep.c (_initialize_i386nbsd_tdep): Add declaration.
* i386-nto-tdep.c (_initialize_i386nto_tdep): Add declaration.
* i386-obsd-nat.c (_initialize_i386obsd_nat): Add declaration.
* i386-obsd-tdep.c (_initialize_i386obsd_tdep): Add declaration.
* i386-sol2-nat.c (_initialize_amd64_sol2_nat): Add declaration.
* i386-sol2-tdep.c (_initialize_i386_sol2_tdep): Add declaration.
* i386-tdep.c (_initialize_i386_tdep): Add declaration.
* i386-windows-nat.c (_initialize_i386_windows_nat): Add declaration.
* ia64-libunwind-tdep.c (_initialize_libunwind_frame): Add declaration.
* ia64-linux-nat.c (_initialize_ia64_linux_nat): Add declaration.
* ia64-linux-tdep.c (_initialize_ia64_linux_tdep): Add declaration.
* ia64-tdep.c (_initialize_ia64_tdep): Add declaration.
* ia64-vms-tdep.c (_initialize_ia64_vms_tdep): Add declaration.
* infcall.c (_initialize_infcall): Add declaration.
* infcmd.c (_initialize_infcmd): Add declaration.
* inflow.c (_initialize_inflow): Add declaration.
* infrun.c (_initialize_infrun): Add declaration.
* interps.c (_initialize_interpreter): Add declaration.
* iq2000-tdep.c (_initialize_iq2000_tdep): Add declaration.
* jit.c (_initialize_jit): Add declaration.
* language.c (_initialize_language): Add declaration.
* linux-fork.c (_initialize_linux_fork): Add declaration.
* linux-nat.c (_initialize_linux_nat): Add declaration.
* linux-tdep.c (_initialize_linux_tdep): Add declaration.
* linux-thread-db.c (_initialize_thread_db): Add declaration.
* lm32-tdep.c (_initialize_lm32_tdep): Add declaration.
* m2-lang.c (_initialize_m2_language): Add declaration.
* m32c-tdep.c (_initialize_m32c_tdep): Add declaration.
* m32r-linux-nat.c (_initialize_m32r_linux_nat): Add declaration.
* m32r-linux-tdep.c (_initialize_m32r_linux_tdep): Add declaration.
* m32r-tdep.c (_initialize_m32r_tdep): Add declaration.
* m68hc11-tdep.c (_initialize_m68hc11_tdep): Add declaration.
* m68k-bsd-nat.c (_initialize_m68kbsd_nat): Add declaration.
* m68k-bsd-tdep.c (_initialize_m68kbsd_tdep): Add declaration.
* m68k-linux-nat.c (_initialize_m68k_linux_nat): Add declaration.
* m68k-linux-tdep.c (_initialize_m68k_linux_tdep): Add declaration.
* m68k-tdep.c (_initialize_m68k_tdep): Add declaration.
* machoread.c (_initialize_machoread): Add declaration.
* macrocmd.c (_initialize_macrocmd): Add declaration.
* macroscope.c (_initialize_macroscope): Add declaration.
* maint-test-options.c (_initialize_maint_test_options): Add declaration.
* maint-test-settings.c (_initialize_maint_test_settings): Add declaration.
* maint.c (_initialize_maint_cmds): Add declaration.
* mdebugread.c (_initialize_mdebugread): Add declaration.
* memattr.c (_initialize_mem): Add declaration.
* mep-tdep.c (_initialize_mep_tdep): Add declaration.
* mi/mi-cmd-env.c (_initialize_mi_cmd_env): Add declaration.
* mi/mi-cmds.c (_initialize_mi_cmds): Add declaration.
* mi/mi-interp.c (_initialize_mi_interp): Add declaration.
* mi/mi-main.c (_initialize_mi_main): Add declaration.
* microblaze-linux-tdep.c (_initialize_microblaze_linux_tdep): Add declaration.
* microblaze-tdep.c (_initialize_microblaze_tdep): Add declaration.
* mips-fbsd-nat.c (_initialize_mips_fbsd_nat): Add declaration.
* mips-fbsd-tdep.c (_initialize_mips_fbsd_tdep): Add declaration.
* mips-linux-nat.c (_initialize_mips_linux_nat): Add declaration.
* mips-linux-tdep.c (_initialize_mips_linux_tdep): Add declaration.
* mips-nbsd-nat.c (_initialize_mipsnbsd_nat): Add declaration.
* mips-nbsd-tdep.c (_initialize_mipsnbsd_tdep): Add declaration.
* mips-sde-tdep.c (_initialize_mips_sde_tdep): Add declaration.
* mips-tdep.c (_initialize_mips_tdep): Add declaration.
* mips64-obsd-nat.c (_initialize_mips64obsd_nat): Add declaration.
* mips64-obsd-tdep.c (_initialize_mips64obsd_tdep): Add declaration.
* mipsread.c (_initialize_mipsread): Add declaration.
* mn10300-linux-tdep.c (_initialize_mn10300_linux_tdep): Add declaration.
* mn10300-tdep.c (_initialize_mn10300_tdep): Add declaration.
* moxie-tdep.c (_initialize_moxie_tdep): Add declaration.
* msp430-tdep.c (_initialize_msp430_tdep): Add declaration.
* nds32-tdep.c (_initialize_nds32_tdep): Add declaration.
* nios2-linux-tdep.c (_initialize_nios2_linux_tdep): Add declaration.
* nios2-tdep.c (_initialize_nios2_tdep): Add declaration.
* nto-procfs.c (_initialize_procfs): Add declaration.
* objc-lang.c (_initialize_objc_language): Add declaration.
* observable.c (_initialize_observer): Add declaration.
* opencl-lang.c (_initialize_opencl_language): Add declaration.
* or1k-linux-tdep.c (_initialize_or1k_linux_tdep): Add declaration.
* or1k-tdep.c (_initialize_or1k_tdep): Add declaration.
* osabi.c (_initialize_gdb_osabi): Add declaration.
* osdata.c (_initialize_osdata): Add declaration.
* p-valprint.c (_initialize_pascal_valprint): Add declaration.
* parse.c (_initialize_parse): Add declaration.
* ppc-fbsd-nat.c (_initialize_ppcfbsd_nat): Add declaration.
* ppc-fbsd-tdep.c (_initialize_ppcfbsd_tdep): Add declaration.
* ppc-linux-nat.c (_initialize_ppc_linux_nat): Add declaration.
* ppc-linux-tdep.c (_initialize_ppc_linux_tdep): Add declaration.
* ppc-nbsd-nat.c (_initialize_ppcnbsd_nat): Add declaration.
* ppc-nbsd-tdep.c (_initialize_ppcnbsd_tdep): Add declaration.
* ppc-obsd-nat.c (_initialize_ppcobsd_nat): Add declaration.
* ppc-obsd-tdep.c (_initialize_ppcobsd_tdep): Add declaration.
* printcmd.c (_initialize_printcmd): Add declaration.
* probe.c (_initialize_probe): Add declaration.
* proc-api.c (_initialize_proc_api): Add declaration.
* proc-events.c (_initialize_proc_events): Add declaration.
* proc-service.c (_initialize_proc_service): Add declaration.
* procfs.c (_initialize_procfs): Add declaration.
* producer.c (_initialize_producer): Add declaration.
* psymtab.c (_initialize_psymtab): Add declaration.
* python/python.c (_initialize_python): Add declaration.
* ravenscar-thread.c (_initialize_ravenscar): Add declaration.
* record-btrace.c (_initialize_record_btrace): Add declaration.
* record-full.c (_initialize_record_full): Add declaration.
* record.c (_initialize_record): Add declaration.
* regcache-dump.c (_initialize_regcache_dump): Add declaration.
* regcache.c (_initialize_regcache): Add declaration.
* reggroups.c (_initialize_reggroup): Add declaration.
* remote-notif.c (_initialize_notif): Add declaration.
* remote-sim.c (_initialize_remote_sim): Add declaration.
* remote.c (_initialize_remote): Add declaration.
* reverse.c (_initialize_reverse): Add declaration.
* riscv-fbsd-nat.c (_initialize_riscv_fbsd_nat): Add declaration.
* riscv-fbsd-tdep.c (_initialize_riscv_fbsd_tdep): Add declaration.
* riscv-linux-nat.c (_initialize_riscv_linux_nat): Add declaration.
* riscv-linux-tdep.c (_initialize_riscv_linux_tdep): Add declaration.
* riscv-tdep.c (_initialize_riscv_tdep): Add declaration.
* rl78-tdep.c (_initialize_rl78_tdep): Add declaration.
* rs6000-aix-tdep.c (_initialize_rs6000_aix_tdep): Add declaration.
* rs6000-lynx178-tdep.c (_initialize_rs6000_lynx178_tdep):
Add declaration.
* rs6000-nat.c (_initialize_rs6000_nat): Add declaration.
* rs6000-tdep.c (_initialize_rs6000_tdep): Add declaration.
* run-on-main-thread.c (_initialize_run_on_main_thread): Add declaration.
* rust-exp.y (_initialize_rust_exp): Add declaration.
* rx-tdep.c (_initialize_rx_tdep): Add declaration.
* s12z-tdep.c (_initialize_s12z_tdep): Add declaration.
* s390-linux-nat.c (_initialize_s390_nat): Add declaration.
* s390-linux-tdep.c (_initialize_s390_linux_tdep): Add declaration.
* s390-tdep.c (_initialize_s390_tdep): Add declaration.
* score-tdep.c (_initialize_score_tdep): Add declaration.
* ser-go32.c (_initialize_ser_dos): Add declaration.
* ser-mingw.c (_initialize_ser_windows): Add declaration.
* ser-pipe.c (_initialize_ser_pipe): Add declaration.
* ser-tcp.c (_initialize_ser_tcp): Add declaration.
* ser-uds.c (_initialize_ser_socket): Add declaration.
* ser-unix.c (_initialize_ser_hardwire): Add declaration.
* serial.c (_initialize_serial): Add declaration.
* sh-linux-tdep.c (_initialize_sh_linux_tdep): Add declaration.
* sh-nbsd-nat.c (_initialize_shnbsd_nat): Add declaration.
* sh-nbsd-tdep.c (_initialize_shnbsd_tdep): Add declaration.
* sh-tdep.c (_initialize_sh_tdep): Add declaration.
* skip.c (_initialize_step_skip): Add declaration.
* sol-thread.c (_initialize_sol_thread): Add declaration.
* solib-aix.c (_initialize_solib_aix): Add declaration.
* solib-darwin.c (_initialize_darwin_solib): Add declaration.
* solib-dsbt.c (_initialize_dsbt_solib): Add declaration.
* solib-frv.c (_initialize_frv_solib): Add declaration.
* solib-svr4.c (_initialize_svr4_solib): Add declaration.
* solib-target.c (_initialize_solib_target): Add declaration.
* solib.c (_initialize_solib): Add declaration.
* source-cache.c (_initialize_source_cache): Add declaration.
* source.c (_initialize_source): Add declaration.
* sparc-linux-nat.c (_initialize_sparc_linux_nat): Add declaration.
* sparc-linux-tdep.c (_initialize_sparc_linux_tdep): Add declaration.
* sparc-nat.c (_initialize_sparc_nat): Add declaration.
* sparc-nbsd-nat.c (_initialize_sparcnbsd_nat): Add declaration.
* sparc-nbsd-tdep.c (_initialize_sparcnbsd_tdep): Add declaration.
* sparc-obsd-tdep.c (_initialize_sparc32obsd_tdep): Add declaration.
* sparc-sol2-tdep.c (_initialize_sparc_sol2_tdep): Add declaration.
* sparc-tdep.c (_initialize_sparc_tdep): Add declaration.
* sparc64-fbsd-nat.c (_initialize_sparc64fbsd_nat): Add declaration.
* sparc64-fbsd-tdep.c (_initialize_sparc64fbsd_tdep): Add declaration.
* sparc64-linux-nat.c (_initialize_sparc64_linux_nat): Add declaration.
* sparc64-linux-tdep.c (_initialize_sparc64_linux_tdep): Add declaration.
* sparc64-nat.c (_initialize_sparc64_nat): Add declaration.
* sparc64-nbsd-nat.c (_initialize_sparc64nbsd_nat): Add declaration.
* sparc64-nbsd-tdep.c (_initialize_sparc64nbsd_tdep): Add declaration.
* sparc64-obsd-nat.c (_initialize_sparc64obsd_nat): Add declaration.
* sparc64-obsd-tdep.c (_initialize_sparc64obsd_tdep): Add declaration.
* sparc64-sol2-tdep.c (_initialize_sparc64_sol2_tdep): Add declaration.
* sparc64-tdep.c (_initialize_sparc64_adi_tdep): Add declaration.
* stabsread.c (_initialize_stabsread): Add declaration.
* stack.c (_initialize_stack): Add declaration.
* stap-probe.c (_initialize_stap_probe): Add declaration.
* std-regs.c (_initialize_frame_reg): Add declaration.
* symfile-debug.c (_initialize_symfile_debug): Add declaration.
* symfile-mem.c (_initialize_symfile_mem): Add declaration.
* symfile.c (_initialize_symfile): Add declaration.
* symmisc.c (_initialize_symmisc): Add declaration.
* symtab.c (_initialize_symtab): Add declaration.
* target.c (_initialize_target): Add declaration.
* target-connection.c (_initialize_target_connection): Add
declaration.
* target-dcache.c (_initialize_target_dcache): Add declaration.
* target-descriptions.c (_initialize_target_descriptions): Add declaration.
* thread.c (_initialize_thread): Add declaration.
* tic6x-linux-tdep.c (_initialize_tic6x_linux_tdep): Add declaration.
* tic6x-tdep.c (_initialize_tic6x_tdep): Add declaration.
* tilegx-linux-nat.c (_initialize_tile_linux_nat): Add declaration.
* tilegx-linux-tdep.c (_initialize_tilegx_linux_tdep): Add declaration.
* tilegx-tdep.c (_initialize_tilegx_tdep): Add declaration.
* tracectf.c (_initialize_ctf): Add declaration.
* tracefile-tfile.c (_initialize_tracefile_tfile): Add declaration.
* tracefile.c (_initialize_tracefile): Add declaration.
* tracepoint.c (_initialize_tracepoint): Add declaration.
* tui/tui-hooks.c (_initialize_tui_hooks): Add declaration.
* tui/tui-interp.c (_initialize_tui_interp): Add declaration.
* tui/tui-layout.c (_initialize_tui_layout): Add declaration.
* tui/tui-regs.c (_initialize_tui_regs): Add declaration.
* tui/tui-stack.c (_initialize_tui_stack): Add declaration.
* tui/tui-win.c (_initialize_tui_win): Add declaration.
* tui/tui.c (_initialize_tui): Add declaration.
* typeprint.c (_initialize_typeprint): Add declaration.
* ui-style.c (_initialize_ui_style): Add declaration.
* unittests/array-view-selftests.c (_initialize_array_view_selftests): Add declaration.
* unittests/child-path-selftests.c (_initialize_child_path_selftests): Add declaration.
* unittests/cli-utils-selftests.c (_initialize_cli_utils_selftests): Add declaration.
* unittests/common-utils-selftests.c (_initialize_common_utils_selftests): Add declaration.
* unittests/copy_bitwise-selftests.c (_initialize_copy_bitwise_utils_selftests): Add declaration.
* unittests/environ-selftests.c (_initialize_environ_selftests): Add declaration.
* unittests/filtered_iterator-selftests.c
(_initialize_filtered_iterator_selftests): Add declaration.
* unittests/format_pieces-selftests.c (_initialize_format_pieces_selftests): Add declaration.
* unittests/function-view-selftests.c (_initialize_function_view_selftests): Add declaration.
* unittests/help-doc-selftests.c (_initialize_help_doc_selftests): Add declaration.
* unittests/lookup_name_info-selftests.c (_initialize_lookup_name_info_selftests): Add declaration.
* unittests/main-thread-selftests.c
(_initialize_main_thread_selftests): Add declaration.
* unittests/memory-map-selftests.c (_initialize_memory_map_selftests): Add declaration.
* unittests/memrange-selftests.c (_initialize_memrange_selftests): Add declaration.
* unittests/mkdir-recursive-selftests.c (_initialize_mkdir_recursive_selftests): Add declaration.
* unittests/observable-selftests.c (_initialize_observer_selftest): Add declaration.
* unittests/offset-type-selftests.c (_initialize_offset_type_selftests): Add declaration.
* unittests/optional-selftests.c (_initialize_optional_selftests): Add declaration.
* unittests/parse-connection-spec-selftests.c (_initialize_parse_connection_spec_selftests): Add declaration.
* unittests/rsp-low-selftests.c (_initialize_rsp_low_selftests): Add declaration.
* unittests/scoped_fd-selftests.c (_initialize_scoped_fd_selftests): Add declaration.
* unittests/scoped_mmap-selftests.c (_initialize_scoped_mmap_selftests): Add declaration.
* unittests/scoped_restore-selftests.c (_initialize_scoped_restore_selftests): Add declaration.
* unittests/string_view-selftests.c (_initialize_string_view_selftests): Add declaration.
* unittests/style-selftests.c (_initialize_style_selftest): Add declaration.
* unittests/tracepoint-selftests.c (_initialize_tracepoint_selftests): Add declaration.
* unittests/tui-selftests.c (_initialize_tui_selftest): Add
declaration.
* unittests/unpack-selftests.c (_initialize_unpack_selftests): Add declaration.
* unittests/utils-selftests.c (_initialize_utils_selftests): Add declaration.
* unittests/vec-utils-selftests.c (_initialize_vec_utils_selftests): Add declaration.
* unittests/xml-utils-selftests.c (_initialize_xml_utils): Add declaration.
* user-regs.c (_initialize_user_regs): Add declaration.
* utils.c (_initialize_utils): Add declaration.
* v850-tdep.c (_initialize_v850_tdep): Add declaration.
* valops.c (_initialize_valops): Add declaration.
* valprint.c (_initialize_valprint): Add declaration.
* value.c (_initialize_values): Add declaration.
* varobj.c (_initialize_varobj): Add declaration.
* vax-bsd-nat.c (_initialize_vaxbsd_nat): Add declaration.
* vax-nbsd-tdep.c (_initialize_vaxnbsd_tdep): Add declaration.
* vax-tdep.c (_initialize_vax_tdep): Add declaration.
* windows-nat.c (_initialize_windows_nat): Add declaration.
(_initialize_check_for_gdb_ini): Add declaration.
(_initialize_loadable): Add declaration.
* windows-tdep.c (_initialize_windows_tdep): Add declaration.
* x86-bsd-nat.c (_initialize_x86_bsd_nat): Add declaration.
* x86-linux-nat.c (_initialize_x86_linux_nat): Add declaration.
* xcoffread.c (_initialize_xcoffread): Add declaration.
* xml-support.c (_initialize_xml_support): Add declaration.
* xstormy16-tdep.c (_initialize_xstormy16_tdep): Add declaration.
* xtensa-linux-nat.c (_initialize_xtensa_linux_nat): Add declaration.
* xtensa-linux-tdep.c (_initialize_xtensa_linux_tdep): Add declaration.
* xtensa-tdep.c (_initialize_xtensa_tdep): Add declaration.
Change-Id: I13eec7e0ed2b3c427377a7bdb055cf46da64def9
|
|
This commit adds multi-target support to GDB. What this means is that
with this commit, GDB can now be connected to different targets at the
same time. E.g., you can debug a live native process and a core dump
at the same time, connect to multiple gdbservers, etc.
Actually, the word "target" is overloaded in gdb. We already have a
target stack, with pushes several target_ops instances on top of one
another. We also have "info target" already, which means something
completely different to what this patch does.
So from here on, I'll be using the "target connections" term, to mean
an open process_stratum target, pushed on a target stack. This patch
makes gdb have multiple target stacks, and multiple process_stratum
targets open simultaneously. The user-visible changes / commands will
also use this terminology, but of course it's all open to debate.
User-interface-wise, not that much changes. The main difference is
that each inferior may have its own target connection.
A target connection (e.g., a target extended-remote connection) may
support debugging multiple processes, just as before.
Say you're debugging against gdbserver in extended-remote mode, and
you do "add-inferior" to prepare to spawn a new process, like:
(gdb) target extended-remote :9999
...
(gdb) start
...
(gdb) add-inferior
Added inferior 2
(gdb) inferior 2
[Switching to inferior 2 [<null>] (<noexec>)]
(gdb) file a.out
...
(gdb) start
...
At this point, you have two inferiors connected to the same gdbserver.
With this commit, GDB will maintain a target stack per inferior,
instead of a global target stack.
To preserve the behavior above, by default, "add-inferior" makes the
new inferior inherit a copy of the target stack of the current
inferior. Same across a fork - the child inherits a copy of the
target stack of the parent. While the target stacks are copied, the
targets themselves are not. Instead, target_ops is made a
refcounted_object, which means that target_ops instances are
refcounted, which each inferior counting for a reference.
What if you want to create an inferior and connect it to some _other_
target? For that, this commit introduces a new "add-inferior
-no-connection" option that makes the new inferior not share the
current inferior's target. So you could do:
(gdb) target extended-remote :9999
Remote debugging using :9999
...
(gdb) add-inferior -no-connection
[New inferior 2]
Added inferior 2
(gdb) inferior 2
[Switching to inferior 2 [<null>] (<noexec>)]
(gdb) info inferiors
Num Description Executable
1 process 18401 target:/home/pedro/tmp/main
* 2 <null>
(gdb) tar extended-remote :10000
Remote debugging using :10000
...
(gdb) info inferiors
Num Description Executable
1 process 18401 target:/home/pedro/tmp/main
* 2 process 18450 target:/home/pedro/tmp/main
(gdb)
A following patch will extended "info inferiors" to include a column
indicating which connection an inferior is bound to, along with a
couple other UI tweaks.
Other than that, debugging is the same as before. Users interact with
inferiors and threads as before. The only difference is that
inferiors may be bound to processes running in different machines.
That's pretty much all there is to it in terms of noticeable UI
changes.
On to implementation.
Since we can be connected to different systems at the same time, a
ptid_t is no longer a unique identifier. Instead a thread can be
identified by a pair of ptid_t and 'process_stratum_target *', the
later being the instance of the process_stratum target that owns the
process/thread. Note that process_stratum_target inherits from
target_ops, and all process_stratum targets inherit from
process_stratum_target. In earlier patches, many places in gdb were
converted to refer to threads by thread_info pointer instead of
ptid_t, but there are still places in gdb where we start with a
pid/tid and need to find the corresponding inferior or thread_info
objects. So you'll see in the patch many places adding a
process_stratum_target parameter to functions that used to take only a
ptid_t.
Since each inferior has its own target stack now, we can always find
the process_stratum target for an inferior. That is done via a
inf->process_target() convenience method.
Since each inferior has its own target stack, we need to handle the
"beneath" calls when servicing target calls. The solution I settled
with is just to make sure to switch the current inferior to the
inferior you want before making a target call. Not relying on global
context is just not feasible in current GDB. Fortunately, there
aren't that many places that need to do that, because generally most
code that calls target methods already has the current context
pointing to the right inferior/thread. Note, to emphasize -- there's
no method to "switch to this target stack". Instead, you switch the
current inferior, and that implicitly switches the target stack.
In some spots, we need to iterate over all inferiors so that we reach
all target stacks.
Native targets are still singletons. There's always only a single
instance of such targets.
Remote targets however, we'll have one instance per remote connection.
The exec target is still a singleton. There's only one instance. I
did not see the point of instanciating more than one exec_target
object.
After vfork, we need to make sure to push the exec target on the new
inferior. See exec_on_vfork.
For type safety, functions that need a {target, ptid} pair to identify
a thread, take a process_stratum_target pointer for target parameter
instead of target_ops *. Some shared code in gdb/nat/ also need to
gain a target pointer parameter. This poses an issue, since gdbserver
doesn't have process_stratum_target, only target_ops. To fix this,
this commit renames gdbserver's target_ops to process_stratum_target.
I think this makes sense. There's no concept of target stack in
gdbserver, and gdbserver's target_ops really implements a
process_stratum-like target.
The thread and inferior iterator functions also gain
process_stratum_target parameters. These are used to be able to
iterate over threads and inferiors of a given target. Following usual
conventions, if the target pointer is null, then we iterate over
threads and inferiors of all targets.
I tried converting "add-inferior" to the gdb::option framework, as a
preparatory patch, but that stumbled on the fact that gdb::option does
not support file options yet, for "add-inferior -exec". I have a WIP
patchset that adds that, but it's not a trivial patch, mainly due to
need to integrate readline's filename completion, so I deferred that
to some other time.
In infrun.c/infcmd.c, the main change is that we need to poll events
out of all targets. See do_target_wait. Right after collecting an
event, we switch the current inferior to an inferior bound to the
target that reported the event, so that target methods can be used
while handling the event. This makes most of the code transparent to
multi-targets. See fetch_inferior_event.
infrun.c:stop_all_threads is interesting -- in this function we need
to stop all threads of all targets. What the function does is send an
asynchronous stop request to all threads, and then synchronously waits
for events, with target_wait, rinse repeat, until all it finds are
stopped threads. Now that we have multiple targets, it's not
efficient to synchronously block in target_wait waiting for events out
of one target. Instead, we implement a mini event loop, with
interruptible_select, select'ing on one file descriptor per target.
For this to work, we need to be able to ask the target for a waitable
file descriptor. Such file descriptors already exist, they are the
descriptors registered in the main event loop with add_file_handler,
inside the target_async implementations. This commit adds a new
target_async_wait_fd target method that just returns the file
descriptor in question. See wait_one / stop_all_threads in infrun.c.
The 'threads_executing' global is made a per-target variable. Since
it is only relevant to process_stratum_target targets, this is where
it is put, instead of in target_ops.
You'll notice that remote.c includes some FIXME notes. These refer to
the fact that the global arrays that hold data for the remote packets
supported are still globals. For example, if we connect to two
different servers/stubs, then each might support different remote
protocol features. They might even be different architectures, like
e.g., one ARM baremetal stub, and a x86 gdbserver, to debug a
host/controller scenario as a single program. That isn't going to
work correctly today, because of said globals. I'm leaving fixing
that for another pass, since it does not appear to be trivial, and I'd
rather land the base work first. It's already useful to be able to
debug multiple instances of the same server (e.g., a distributed
cluster, where you have full control over the servers installed), so I
think as is it's already reasonable incremental progress.
Current limitations:
- You can only resume more that one target at the same time if all
targets support asynchronous debugging, and support non-stop mode.
It should be possible to support mixed all-stop + non-stop
backends, but that is left for another time. This means that
currently in order to do multi-target with gdbserver you need to
issue "maint set target-non-stop on". I would like to make that
mode be the default, but we're not there yet. Note that I'm
talking about how the target backend works, only. User-visible
all-stop mode works just fine.
- As explained above, connecting to different remote servers at the
same time is likely to produce bad results if they don't support the
exact set of RSP features.
FreeBSD updates courtesy of John Baldwin.
gdb/ChangeLog:
2020-01-10 Pedro Alves <palves@redhat.com>
John Baldwin <jhb@FreeBSD.org>
* aarch64-linux-nat.c
(aarch64_linux_nat_target::thread_architecture): Adjust.
* ada-tasks.c (print_ada_task_info): Adjust find_thread_ptid call.
(task_command_1): Likewise.
* aix-thread.c (sync_threadlists, aix_thread_target::resume)
(aix_thread_target::wait, aix_thread_target::fetch_registers)
(aix_thread_target::store_registers)
(aix_thread_target::thread_alive): Adjust.
* amd64-fbsd-tdep.c: Include "inferior.h".
(amd64fbsd_get_thread_local_address): Pass down target.
* amd64-linux-nat.c (ps_get_thread_area): Use ps_prochandle
thread's gdbarch instead of target_gdbarch.
* break-catch-sig.c (signal_catchpoint_print_it): Adjust call to
get_last_target_status.
* break-catch-syscall.c (print_it_catch_syscall): Likewise.
* breakpoint.c (breakpoints_should_be_inserted_now): Consider all
inferiors.
(update_inserted_breakpoint_locations): Skip if inferiors with no
execution.
(update_global_location_list): When handling moribund locations,
find representative inferior for location's pspace, and use thread
count of its process_stratum target.
* bsd-kvm.c (bsd_kvm_target_open): Pass target down.
* bsd-uthread.c (bsd_uthread_target::wait): Use
as_process_stratum_target and adjust thread_change_ptid and
add_thread calls.
(bsd_uthread_target::update_thread_list): Use
as_process_stratum_target and adjust find_thread_ptid,
thread_change_ptid and add_thread calls.
* btrace.c (maint_btrace_packet_history_cmd): Adjust
find_thread_ptid call.
* corelow.c (add_to_thread_list): Adjust add_thread call.
(core_target_open): Adjust add_thread_silent and thread_count
calls.
(core_target::pid_to_str): Adjust find_inferior_ptid call.
* ctf.c (ctf_target_open): Adjust add_thread_silent call.
* event-top.c (async_disconnect): Pop targets from all inferiors.
* exec.c (add_target_sections): Push exec target on all inferiors
sharing the program space.
(remove_target_sections): Remove the exec target from all
inferiors sharing the program space.
(exec_on_vfork): New.
* exec.h (exec_on_vfork): Declare.
* fbsd-nat.c (fbsd_add_threads): Add fbsd_nat_target parameter.
Pass it down.
(fbsd_nat_target::update_thread_list): Adjust.
(fbsd_nat_target::resume): Adjust.
(fbsd_handle_debug_trap): Add fbsd_nat_target parameter. Pass it
down.
(fbsd_nat_target::wait, fbsd_nat_target::post_attach): Adjust.
* fbsd-tdep.c (fbsd_corefile_thread): Adjust
get_thread_arch_regcache call.
* fork-child.c (gdb_startup_inferior): Pass target down to
startup_inferior and set_executing.
* gdbthread.h (struct process_stratum_target): Forward declare.
(add_thread, add_thread_silent, add_thread_with_info)
(in_thread_list): Add process_stratum_target parameter.
(find_thread_ptid(inferior*, ptid_t)): New overload.
(find_thread_ptid, thread_change_ptid): Add process_stratum_target
parameter.
(all_threads()): Delete overload.
(all_threads, all_non_exited_threads): Add process_stratum_target
parameter.
(all_threads_safe): Use brace initialization.
(thread_count): Add process_stratum_target parameter.
(set_resumed, set_running, set_stop_requested, set_executing)
(threads_are_executing, finish_thread_state): Add
process_stratum_target parameter.
(switch_to_thread): Use is_current_thread.
* i386-fbsd-tdep.c: Include "inferior.h".
(i386fbsd_get_thread_local_address): Pass down target.
* i386-linux-nat.c (i386_linux_nat_target::low_resume): Adjust.
* inf-child.c (inf_child_target::maybe_unpush_target): Remove
have_inferiors check.
* inf-ptrace.c (inf_ptrace_target::create_inferior)
(inf_ptrace_target::attach): Adjust.
* infcall.c (run_inferior_call): Adjust.
* infcmd.c (run_command_1): Pass target to
scoped_finish_thread_state.
(proceed_thread_callback): Skip inferiors with no execution.
(continue_command): Rename 'all_threads' local to avoid hiding
'all_threads' function. Adjust get_last_target_status call.
(prepare_one_step): Adjust set_running call.
(signal_command): Use user_visible_resume_target. Compare thread
pointers instead of inferior_ptid.
(info_program_command): Adjust to pass down target.
(attach_command): Mark target's 'thread_executing' flag.
(stop_current_target_threads_ns): New, factored out from ...
(interrupt_target_1): ... this. Switch inferior before making
target calls.
* inferior-iter.h
(struct all_inferiors_iterator, struct all_inferiors_range)
(struct all_inferiors_safe_range)
(struct all_non_exited_inferiors_range): Filter on
process_stratum_target too. Remove explicit.
* inferior.c (inferior::inferior): Push dummy target on target
stack.
(find_inferior_pid, find_inferior_ptid, number_of_live_inferiors):
Add process_stratum_target parameter, and pass it down.
(have_live_inferiors): Adjust.
(switch_to_inferior_and_push_target): New.
(add_inferior_command, clone_inferior_command): Handle
"-no-connection" parameter. Use
switch_to_inferior_and_push_target.
(_initialize_inferior): Mention "-no-connection" option in
the help of "add-inferior" and "clone-inferior" commands.
* inferior.h: Include "process-stratum-target.h".
(interrupt_target_1): Use bool.
(struct inferior) <push_target, unpush_target, target_is_pushed,
find_target_beneath, top_target, process_target, target_at,
m_stack>: New.
(discard_all_inferiors): Delete.
(find_inferior_pid, find_inferior_ptid, number_of_live_inferiors)
(all_inferiors, all_non_exited_inferiors): Add
process_stratum_target parameter.
* infrun.c: Include "gdb_select.h" and <unordered_map>.
(target_last_proc_target): New global.
(follow_fork_inferior): Push target on new inferior. Pass target
to add_thread_silent. Call exec_on_vfork. Handle target's
reference count.
(follow_fork): Adjust get_last_target_status call. Also consider
target.
(follow_exec): Push target on new inferior.
(struct execution_control_state) <target>: New field.
(user_visible_resume_target): New.
(do_target_resume): Call target_async.
(resume_1): Set target's threads_executing flag. Consider resume
target.
(commit_resume_all_targets): New.
(proceed): Also consider resume target. Skip threads of inferiors
with no execution. Commit resumtion in all targets.
(start_remote): Pass current inferior to wait_for_inferior.
(infrun_thread_stop_requested): Consider target as well. Pass
thread_info pointer to clear_inline_frame_state instead of ptid.
(infrun_thread_thread_exit): Consider target as well.
(random_pending_event_thread): New inferior parameter. Use it.
(do_target_wait): Rename to ...
(do_target_wait_1): ... this. Add inferior parameter, and pass it
down.
(threads_are_resumed_pending_p, do_target_wait): New.
(prepare_for_detach): Adjust calls.
(wait_for_inferior): New inferior parameter. Handle it. Use
do_target_wait_1 instead of do_target_wait.
(fetch_inferior_event): Adjust. Switch to representative
inferior. Pass target down.
(set_last_target_status): Add process_stratum_target parameter.
Save target in global.
(get_last_target_status): Add process_stratum_target parameter and
handle it.
(nullify_last_target_wait_ptid): Clear 'target_last_proc_target'.
(context_switch): Check inferior_ptid == null_ptid before calling
inferior_thread().
(get_inferior_stop_soon): Pass down target.
(wait_one): Rename to ...
(poll_one_curr_target): ... this.
(struct wait_one_event): New.
(wait_one): New.
(stop_all_threads): Adjust.
(handle_no_resumed, handle_inferior_event): Adjust to consider the
event's target.
(switch_back_to_stepped_thread): Also consider target.
(print_stop_event): Update.
(normal_stop): Update. Also consider the resume target.
* infrun.h (wait_for_inferior): Remove declaration.
(user_visible_resume_target): New declaration.
(get_last_target_status, set_last_target_status): New
process_stratum_target parameter.
* inline-frame.c (clear_inline_frame_state(ptid_t)): Add
process_stratum_target parameter, and use it.
(clear_inline_frame_state (thread_info*)): New.
* inline-frame.c (clear_inline_frame_state(ptid_t)): Add
process_stratum_target parameter.
(clear_inline_frame_state (thread_info*)): Declare.
* linux-fork.c (delete_checkpoint_command): Pass target down to
find_thread_ptid.
(checkpoint_command): Adjust.
* linux-nat.c (linux_nat_target::follow_fork): Switch to thread
instead of just tweaking inferior_ptid.
(linux_nat_switch_fork): Pass target down to thread_change_ptid.
(exit_lwp): Pass target down to find_thread_ptid.
(attach_proc_task_lwp_callback): Pass target down to
add_thread/set_running/set_executing.
(linux_nat_target::attach): Pass target down to
thread_change_ptid.
(get_detach_signal): Pass target down to find_thread_ptid.
Consider last target status's target.
(linux_resume_one_lwp_throw, resume_lwp)
(linux_handle_syscall_trap, linux_handle_extended_wait, wait_lwp)
(stop_wait_callback, save_stop_reason, linux_nat_filter_event)
(linux_nat_wait_1, resume_stopped_resumed_lwps): Pass target down.
(linux_nat_target::async_wait_fd): New.
(linux_nat_stop_lwp, linux_nat_target::thread_address_space): Pass
target down.
* linux-nat.h (linux_nat_target::async_wait_fd): Declare.
* linux-tdep.c (get_thread_arch_regcache): Pass target down.
* linux-thread-db.c (struct thread_db_info::process_target): New
field.
(add_thread_db_info): Save target.
(get_thread_db_info): New process_stratum_target parameter. Also
match target.
(delete_thread_db_info): New process_stratum_target parameter.
Also match target.
(thread_from_lwp): Adjust to pass down target.
(thread_db_notice_clone): Pass down target.
(check_thread_db_callback): Pass down target.
(try_thread_db_load_1): Always push the thread_db target.
(try_thread_db_load, record_thread): Pass target down.
(thread_db_target::detach): Pass target down. Always unpush the
thread_db target.
(thread_db_target::wait, thread_db_target::mourn_inferior): Pass
target down. Always unpush the thread_db target.
(find_new_threads_callback, thread_db_find_new_threads_2)
(thread_db_target::update_thread_list): Pass target down.
(thread_db_target::pid_to_str): Pass current inferior down.
(thread_db_target::get_thread_local_address): Pass target down.
(thread_db_target::resume, maintenance_check_libthread_db): Pass
target down.
* nto-procfs.c (nto_procfs_target::update_thread_list): Adjust.
* procfs.c (procfs_target::procfs_init_inferior): Declare.
(proc_set_current_signal, do_attach, procfs_target::wait): Adjust.
(procfs_init_inferior): Rename to ...
(procfs_target::procfs_init_inferior): ... this and adjust.
(procfs_target::create_inferior, procfs_notice_thread)
(procfs_do_thread_registers): Adjust.
* ppc-fbsd-tdep.c: Include "inferior.h".
(ppcfbsd_get_thread_local_address): Pass down target.
* proc-service.c (ps_xfer_memory): Switch current inferior and
program space as well.
(get_ps_regcache): Pass target down.
* process-stratum-target.c
(process_stratum_target::thread_address_space)
(process_stratum_target::thread_architecture): Pass target down.
* process-stratum-target.h
(process_stratum_target::threads_executing): New field.
(as_process_stratum_target): New.
* ravenscar-thread.c
(ravenscar_thread_target::update_inferior_ptid): Pass target down.
(ravenscar_thread_target::wait, ravenscar_add_thread): Pass target
down.
* record-btrace.c (record_btrace_target::info_record): Adjust.
(record_btrace_target::record_method)
(record_btrace_target::record_is_replaying)
(record_btrace_target::fetch_registers)
(get_thread_current_frame_id, record_btrace_target::resume)
(record_btrace_target::wait, record_btrace_target::stop): Pass
target down.
* record-full.c (record_full_wait_1): Switch to event thread.
Pass target down.
* regcache.c (regcache::regcache)
(get_thread_arch_aspace_regcache, get_thread_arch_regcache): Add
process_stratum_target parameter and handle it.
(current_thread_target): New global.
(get_thread_regcache): Add process_stratum_target parameter and
handle it. Switch inferior before calling target method.
(get_thread_regcache): Pass target down.
(get_thread_regcache_for_ptid): Pass target down.
(registers_changed_ptid): Add process_stratum_target parameter and
handle it.
(registers_changed_thread, registers_changed): Pass target down.
(test_get_thread_arch_aspace_regcache): New.
(current_regcache_test): Define a couple local test_target_ops
instances and use them for testing.
(readwrite_regcache): Pass process_stratum_target parameter.
(cooked_read_test, cooked_write_test): Pass mock_target down.
* regcache.h (get_thread_regcache, get_thread_arch_regcache)
(get_thread_arch_aspace_regcache): Add process_stratum_target
parameter.
(regcache::target): New method.
(regcache::regcache, regcache::get_thread_arch_aspace_regcache)
(regcache::registers_changed_ptid): Add process_stratum_target
parameter.
(regcache::m_target): New field.
(registers_changed_ptid): Add process_stratum_target parameter.
* remote.c (remote_state::supports_vCont_probed): New field.
(remote_target::async_wait_fd): New method.
(remote_unpush_and_throw): Add remote_target parameter.
(get_current_remote_target): Adjust.
(remote_target::remote_add_inferior): Push target.
(remote_target::remote_add_thread)
(remote_target::remote_notice_new_inferior)
(get_remote_thread_info): Pass target down.
(remote_target::update_thread_list): Skip threads of inferiors
bound to other targets. (remote_target::close): Don't discard
inferiors. (remote_target::add_current_inferior_and_thread)
(remote_target::process_initial_stop_replies)
(remote_target::start_remote)
(remote_target::remote_serial_quit_handler): Pass down target.
(remote_target::remote_unpush_target): New remote_target
parameter. Unpush the target from all inferiors.
(remote_target::remote_unpush_and_throw): New remote_target
parameter. Pass it down.
(remote_target::open_1): Check whether the current inferior has
execution instead of checking whether any inferior is live. Pass
target down.
(remote_target::remote_detach_1): Pass down target. Use
remote_unpush_target.
(extended_remote_target::attach): Pass down target.
(remote_target::remote_vcont_probe): Set supports_vCont_probed.
(remote_target::append_resumption): Pass down target.
(remote_target::append_pending_thread_resumptions)
(remote_target::remote_resume_with_hc, remote_target::resume)
(remote_target::commit_resume): Pass down target.
(remote_target::remote_stop_ns): Check supports_vCont_probed.
(remote_target::interrupt_query)
(remote_target::remove_new_fork_children)
(remote_target::check_pending_events_prevent_wildcard_vcont)
(remote_target::remote_parse_stop_reply)
(remote_target::process_stop_reply): Pass down target.
(first_remote_resumed_thread): New remote_target parameter. Pass
it down.
(remote_target::wait_as): Pass down target.
(unpush_and_perror): New remote_target parameter. Pass it down.
(remote_target::readchar, remote_target::remote_serial_write)
(remote_target::getpkt_or_notif_sane_1)
(remote_target::kill_new_fork_children, remote_target::kill): Pass
down target.
(remote_target::mourn_inferior): Pass down target. Use
remote_unpush_target.
(remote_target::core_of_thread)
(remote_target::remote_btrace_maybe_reopen): Pass down target.
(remote_target::pid_to_exec_file)
(remote_target::thread_handle_to_thread_info): Pass down target.
(remote_target::async_wait_fd): New.
* riscv-fbsd-tdep.c: Include "inferior.h".
(riscv_fbsd_get_thread_local_address): Pass down target.
* sol2-tdep.c (sol2_core_pid_to_str): Pass down target.
* sol-thread.c (sol_thread_target::wait, ps_lgetregs, ps_lsetregs)
(ps_lgetfpregs, ps_lsetfpregs, sol_update_thread_list_callback):
Adjust.
* solib-spu.c (spu_skip_standalone_loader): Pass down target.
* solib-svr4.c (enable_break): Pass down target.
* spu-multiarch.c (parse_spufs_run): Pass down target.
* spu-tdep.c (spu2ppu_sniffer): Pass down target.
* target-delegates.c: Regenerate.
* target.c (g_target_stack): Delete.
(current_top_target): Return the current inferior's top target.
(target_has_execution_1): Refer to the passed-in inferior's top
target.
(target_supports_terminal_ours): Check whether the initial
inferior was already created.
(decref_target): New.
(target_stack::push): Incref/decref the target.
(push_target, push_target, unpush_target): Adjust.
(target_stack::unpush): Defref target.
(target_is_pushed): Return bool. Adjust to refer to the current
inferior's target stack.
(dispose_inferior): Delete, and inline parts ...
(target_preopen): ... here. Only dispose of the current inferior.
(target_detach): Hold strong target reference while detaching.
Pass target down.
(target_thread_name): Add assertion.
(target_resume): Pass down target.
(target_ops::beneath, find_target_at): Adjust to refer to the
current inferior's target stack.
(get_dummy_target): New.
(target_pass_ctrlc): Pass the Ctrl-C to the first inferior that
has a thread running.
(initialize_targets): Rename to ...
(_initialize_target): ... this.
* target.h: Include "gdbsupport/refcounted-object.h".
(struct target_ops): Inherit refcounted_object.
(target_ops::shortname, target_ops::longname): Make const.
(target_ops::async_wait_fd): New method.
(decref_target): Declare.
(struct target_ops_ref_policy): New.
(target_ops_ref): New typedef.
(get_dummy_target): Declare function.
(target_is_pushed): Return bool.
* thread-iter.c (all_matching_threads_iterator::m_inf_matches)
(all_matching_threads_iterator::all_matching_threads_iterator):
Handle filter target.
* thread-iter.h (struct all_matching_threads_iterator, struct
all_matching_threads_range, class all_non_exited_threads_range):
Filter by target too. Remove explicit.
* thread.c (threads_executing): Delete.
(inferior_thread): Pass down current inferior.
(clear_thread_inferior_resources): Pass down thread pointer
instead of ptid_t.
(add_thread_silent, add_thread_with_info, add_thread): Add
process_stratum_target parameter. Use it for thread and inferior
searches.
(is_current_thread): New.
(thread_info::deletable): Use it.
(find_thread_ptid, thread_count, in_thread_list)
(thread_change_ptid, set_resumed, set_running): New
process_stratum_target parameter. Pass it down.
(set_executing): New process_stratum_target parameter. Pass it
down. Adjust reference to 'threads_executing'.
(threads_are_executing): New process_stratum_target parameter.
Adjust reference to 'threads_executing'.
(set_stop_requested, finish_thread_state): New
process_stratum_target parameter. Pass it down.
(switch_to_thread): Also match inferior.
(switch_to_thread): New process_stratum_target parameter. Pass it
down.
(update_threads_executing): Reimplement.
* top.c (quit_force): Pop targets from all inferior.
(gdb_init): Don't call initialize_targets.
* windows-nat.c (windows_nat_target) <get_windows_debug_event>:
Declare.
(windows_add_thread, windows_delete_thread): Adjust.
(get_windows_debug_event): Rename to ...
(windows_nat_target::get_windows_debug_event): ... this. Adjust.
* tracefile-tfile.c (tfile_target_open): Pass down target.
* gdbsupport/common-gdbthread.h (struct process_stratum_target):
Forward declare.
(switch_to_thread): Add process_stratum_target parameter.
* mi/mi-interp.c (mi_on_resume_1): Add process_stratum_target
parameter. Use it.
(mi_on_resume): Pass target down.
* nat/fork-inferior.c (startup_inferior): Add
process_stratum_target parameter. Pass it down.
* nat/fork-inferior.h (startup_inferior): Add
process_stratum_target parameter.
* python/py-threadevent.c (py_get_event_thread): Pass target down.
gdb/gdbserver/ChangeLog:
2020-01-10 Pedro Alves <palves@redhat.com>
* fork-child.c (post_fork_inferior): Pass target down to
startup_inferior.
* inferiors.c (switch_to_thread): Add process_stratum_target
parameter.
* lynx-low.c (lynx_target_ops): Now a process_stratum_target.
* nto-low.c (nto_target_ops): Now a process_stratum_target.
* linux-low.c (linux_target_ops): Now a process_stratum_target.
* remote-utils.c (prepare_resume_reply): Pass the target to
switch_to_thread.
* target.c (the_target): Now a process_stratum_target.
(done_accessing_memory): Pass the target to switch_to_thread.
(set_target_ops): Ajust to use process_stratum_target.
* target.h (struct target_ops): Rename to ...
(struct process_stratum_target): ... this.
(the_target, set_target_ops): Adjust.
(prepare_to_access_memory): Adjust comment.
* win32-low.c (child_xfer_memory): Adjust to use
process_stratum_target.
(win32_target_ops): Now a process_stratum_target.
|