]> git.ipfire.org Git - thirdparty/binutils-gdb.git/log
thirdparty/binutils-gdb.git
18 months agogdb: make get_frame_register_bytes take the next frame
Simon Marchi [Fri, 1 Dec 2023 16:27:25 +0000 (11:27 -0500)] 
gdb: make get_frame_register_bytes take the next frame

Similar to the previous patches, change get_frame_register_bytes to take
the "next frame" instead of "this frame".

Change-Id: Ie8f35042bfa6e93565fcefaee71b6b3903f0fe9f
Reviewed-By: John Baldwin <jhb@FreeBSD.org>
18 months agogdb: make put_frame_register_bytes take the next frame
Simon Marchi [Fri, 1 Dec 2023 16:27:24 +0000 (11:27 -0500)] 
gdb: make put_frame_register_bytes take the next frame

Similar to the previous patches, change put_frame_register_bytes to take
the "next frame" instead of "this frame".

Change-Id: I27bcb26573686d99b231230823cff8db6405a788
Reviewed-By: John Baldwin <jhb@FreeBSD.org>
18 months agogdb: make put_frame_register take the next frame
Simon Marchi [Fri, 1 Dec 2023 16:27:23 +0000 (11:27 -0500)] 
gdb: make put_frame_register take the next frame

Similar to the previous patches, change put_frame_register to take the
"next frame" instead of "this frame".

Change-Id: I062fd4663b8f54f0fc7bbf39c860b7341363821b
Reviewed-By: John Baldwin <jhb@FreeBSD.org>
18 months agogdb: remove frame_register
Simon Marchi [Fri, 1 Dec 2023 16:27:22 +0000 (11:27 -0500)] 
gdb: remove frame_register

I was going to change frame_register to take the "next frame", but I
realized that doing so would make it a useless wrapper around
frame_register_unwind.  So, just remove frame_register and replace uses
with frame_register_unwind.

Change-Id: I185868bc69f8e098124775d0550d069220a4678a
Reviewed-By: John Baldwin <jhb@FreeBSD.org>
18 months agogdb: change value_of_register and value_of_register_lazy to take the next frame
Simon Marchi [Fri, 1 Dec 2023 16:27:21 +0000 (11:27 -0500)] 
gdb: change value_of_register and value_of_register_lazy to take the next frame

Some functions related to the handling of registers in frames accept
"this frame", for which we want to read or write the register values,
while other functions accept "the next frame", which is the frame next
to that.  The later is needed because we sometimes need to read register
values for a frame that does not exist yet (usually when trying to
unwind that frame-to-be).

value_of_register and value_of_register_lazy both take "this frame",
even if what they ultimately want internally is "the next frame".  This
is annoying if you are in a spot that currently has "the next frame" and
need to call one of these functions (which happens later in this
series).  You need to get the previous frame only for those functions to
get the next frame again.  This is more manipulations, more chances of
mistake.

I propose to change these functions (and a few more functions in the
subsequent patches) to operate on "the next frame".  Things become a bit
less awkward when all these functions agree on which frame they take.

So, in this patch, change value_of_register_lazy and value_of_register
to take "the next frame" instead of "this frame".  This adds a lot of
get_next_frame_sentinel_okay, but if we convert the user registers API
to also use "the next frame" instead of "this frame", it will get simple
again.

Change-Id: Iaa24815e648fbe5ae3c214c738758890a91819cd
Reviewed-By: John Baldwin <jhb@FreeBSD.org>
18 months agogdb: make put_frame_register take an array_view
Simon Marchi [Fri, 1 Dec 2023 16:27:20 +0000 (11:27 -0500)] 
gdb: make put_frame_register take an array_view

Change put_frame_register to take an array_view instead of a raw
pointer.

Add an assertion to verify that the number of bytes we try to write
matches the length of the register.

Change-Id: Ib75a9c8a12b47e203097621643eaa2c1830591ae
Reviewed-By: John Baldwin <jhb@FreeBSD.org>
18 months agogdb: fix bugs in {get,put}_frame_register_bytes
Simon Marchi [Fri, 1 Dec 2023 16:27:19 +0000 (11:27 -0500)] 
gdb: fix bugs in {get,put}_frame_register_bytes

I found this only by inspection: the myaddr pointer in
{get,put}_frame_register_bytes is reset to `buffer.data ()` at each
iteration.  This means that we will always use the bytes at the
beginning of `buffer` to read or write to the registers, instead of
progressing in `buffer`.

Fix this by re-writing the functions to chip away the beginning of the
buffer array_view as we progress in reading or writing the data.

These bugs was introduced almost 3 years ago [1], and yet nobody
complained.  I'm wondering which architecture relies on that register
"overflow" behavior (reading or writing multiple consecutive registers
with one {get,put}_frame_register_bytes calls), and in which situation.
I find these functions a bit dangerous, if a caller mis-calculates
things, it could end up silently reading or writing to the next
register, even if it's not the intent.

If I could change it, I would prefer to have functions specifically made
for that ({get,put}_frame_register_bytes_consecutive or something like
that) and make {get,put}_frame_register_bytes only able to write within
a single register (which I presume represents most of the use cases of
the current {get,put}_frame_register_bytes).  If a caller mis-calculates
things and an overflow occurs while calling
{get,put}_frame_register_bytes, it would hit an assert.  The problem is
knowing which callers rely on the overflow behavior and which don't.

[1] https://gitlab.com/gnutools/binutils-gdb/-/commit/bdec2917b1e94c7198ba39919f45060067952f43

Change-Id: I43bd4a9f7fa8419d388a2b20bdc57d652688ddf8
Reviewed-By: John Baldwin <jhb@FreeBSD.org>
Approved-By: Andrew Burgess <aburgess@redhat.com>
18 months agogdb: change regcache interface to use array_view
Simon Marchi [Fri, 1 Dec 2023 16:27:18 +0000 (11:27 -0500)] 
gdb: change regcache interface to use array_view

Change most of regcache (and base classes) to use array_view when
possible, instead of raw pointers.  By propagating the use of array_view
further, it enables having some runtime checks to make sure the what we
read from or write to regcaches has the expected length (such as the one
in the `copy(array_view, array_view)` function.  It also integrates well
when connecting with other APIs already using gdb::array_view.

Add some overloads of the methods using raw pointers to avoid having to
change all call sites at once (which is both a lot of work and risky).

I tried to do this change in small increments, but since many of these
functions use each other, it ended up simpler to do it in one shot than
having a lot of intermediary / transient changes.

This change extends into gdbserver as well, because there is some part
of the regcache interface that is shared.

Changing the reg_buffer_common interface to use array_view caused some
build failures in nat/aarch64-scalable-linux-ptrace.c.  That file
currently "takes advantage" of the fact that
reg_buffer_common::{raw_supply,raw_collect} operates on `void *`, which
IMO is dangerous.  It uses raw_supply/raw_collect directly on
uint64_t's, which I guess is fine because it is expected that native
code will have the same endianness as the debugged process.  To
accomodate that, add some overloads of raw_collect and raw_supply that
work on uint64_t.

This file also uses raw_collect and raw_supply on `char` pointers.
Change it to use `gdb_byte` pointers instead.  Add overloads of
raw_collect and raw_supply that work on `gdb_byte *` and make an
array_view on the fly using the register's size.  Those call sites could
be converted to use array_view with not much work, in which case these
overloads could be removed, but I didn't want to do it in this patch, to
avoid starting to dig in arch-specific code.

During development, I inadvertently changed reg_buffer::raw_compare's
behavior to not accept an offset equal to the register size.  This
behavior (effectively comparing 0 bytes, returning true) change was
caught by the AArch64 SME core tests.  Add a selftest to make sure that
this raw_compare behavior is preserved in the future.

Change-Id: I9005f04114543ddff738949e12d85a31855304c2
Reviewed-By: John Baldwin <jhb@FreeBSD.org>
18 months agogdb: simplify conditions in regcache::{read,write,raw_collect,raw_supply}_part
Simon Marchi [Fri, 1 Dec 2023 16:27:17 +0000 (11:27 -0500)] 
gdb: simplify conditions in regcache::{read,write,raw_collect,raw_supply}_part

Make a few simplifications in these functions.

1. When checking if we need to do nothing, if the length is 0, we don't
   need to do anything, regardless of the value of offset.  Remove the
   offset check.

2. When check if transferring the whole register, if the length is equal
   to the register size, then we transfer the whole register, no need to
   check the offset.  Remove the offset check.

3. In the gdb_asserts, it is unnecessary to check for:

     offset <= reg_size

   given that right after we check for:

     len >= 0 && offset + len <= reg_size

   If `offset + len` is <= reg_size and len is >= 0, then necessarily
   offset is <= reg_size.  Remove the `offset <= reg_size` check.

Change-Id: I30a73acdc7bf432c45a07f5f177224d1cdc298e8
Reviewed-By: John Baldwin <jhb@FreeBSD.org>
18 months agogdb: make store_integer take an array_view
Simon Marchi [Fri, 1 Dec 2023 16:27:16 +0000 (11:27 -0500)] 
gdb: make store_integer take an array_view

Change store_integer, store_signed_integer and store_unsigned_integer to
accept an array_view.  Add some backwards compatibility overloads to
avoid changing all callers at once.

Change-Id: Ibb1381228ab1cb65fc7e2e4b92cf9ab1047cdc03
Reviewed-By: John Baldwin <jhb@FreeBSD.org>
18 months agogdb: use reg_buffer_common throughout gdbsupport/common-regcache.h
Simon Marchi [Fri, 1 Dec 2023 16:27:15 +0000 (11:27 -0500)] 
gdb: use reg_buffer_common throughout gdbsupport/common-regcache.h

Right now, gdbsupport/common-regcache.h contains two abstractons for a
regcache.  An opaque type `regcache` (gdb and gdbserver both have their
own regcache that is the concrete version of this) and an abstract base
class `reg_buffer_common`, that is the base of regcaches on both sides.
These abstractions allow code to be written for both gdb and gdbserver,
for instance in the gdb/arch sub-directory.

However, having two
different abstractions is impractical.  If some common code has a regcache,
and wants to use an operation defined on reg_buffer_common, it can't.
It would be better to have just one.  Change all instances of `regcache
*` in gdbsupport/common-regcache.h to be `reg_buffer_common *`, then fix
fallouts.

Implementations in gdb and gdbserver now need to down-cast (using
gdb::checked_static_cast) from reg_buffer_common to their concrete
regcache type.  Some of them could be avoided by changing free functions
(like regcache_register_size) to be virtual methods on
reg_buffer_common.  I tried it, it seems to work, but I did not include
it in this series to avoid adding unnecessary changes.

Change-Id: Ia5503adb6b5509a0f4604bd2a68b4642cc5283fd
Reviewed-by: John Baldwin <jhb@FreeBSD.org>
18 months agogdb: don't handle i386 k registers as pseudo registers
Simon Marchi [Fri, 1 Dec 2023 16:27:14 +0000 (11:27 -0500)] 
gdb: don't handle i386 k registers as pseudo registers

I think that i386 k registers are raw registers, and therefore shouldn't
be handled in the various functions handling pseudo registers.

What tipped me off is the code in i386_pseudo_register_read_into_value:

      else if (i386_k_regnum_p (gdbarch, regnum))
{
  regnum -= tdep->k0_regnum;

  /* Extract (always little endian).  */
  status = regcache->raw_read (tdep->k0_regnum + regnum, raw_buf);

We take regnum (the pseudo register number we want to read), subtract
k0_regnum, add k0_regnum, and pass the result to raw_read.  So we would
end up calling raw_read with the same regnum as the function received
which is supposedly a pseudo register number.

Other hints are:

 - The command `maint print raw-registers` shows the k registers.
 - Printing $k0 doesn't cause i386_pseudo_register_read_into_value to be
   called.
 - There's code in i387-tdep.c to save/restore the k registers.

Remove handling of the k registers from:

 - i386_pseudo_register_read_into_value
 - i386_pseudo_register_write
 - i386_ax_pseudo_register_collect

Change-Id: Ic97956ed59af6099fef6d36a0b61464172694562
Reviewed-by: John Baldwin <jhb@FreeBSD.org>
18 months agoAllow calling of variadic C++ functions
Hannes Domani [Sun, 14 Nov 2021 15:19:31 +0000 (16:19 +0100)] 
Allow calling of variadic C++ functions

Currently, it's not possible to call a variadic C++ function:
```
(gdb) print sum_vararg_int(1, 10)
Cannot resolve function sum_vararg_int to any overloaded instance
(gdb) print sum_vararg_int(2, 20, 30)
Cannot resolve function sum_vararg_int to any overloaded instance
```

It's because all additional arguments get the TOO_FEW_PARAMS_BADNESS
rank by rank_function, which disqualifies the function.

To fix this, I've created the new VARARG_BADNESS rank, which is
used only for additional arguments of variadic functions, allowing
them to be called:
```
(gdb) print sum_vararg_int(1, 10)
$1 = 10
(gdb) print sum_vararg_int(2, 20, 30)
$2 = 50
```

Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=28589
Approved-By: Tom Tromey <tom@tromey.com>
18 months agoRISC-V: Fix the wrong encoding and operand of the XTheadFmv extension.
Jin Ma [Fri, 17 Nov 2023 06:20:53 +0000 (14:20 +0800)] 
RISC-V: Fix the wrong encoding and operand of the XTheadFmv extension.

The description of instructions 'th.fmv.hw.x' and 'th.fmv.x.hw' of the
XTheadFmv extension in T-Head specific is incorrect, and it also has
some impact on the implementation of the binutils, so this patch
corrects this.

For details see:
https://github.com/T-head-Semi/thead-extension-spec/pull/34

gas/ChangeLog:

* testsuite/gas/riscv/x-thead-fmv.d: Correct test.
* testsuite/gas/riscv/x-thead-fmv.s: Likewise.

include/ChangeLog:

* opcode/riscv-opc.h (MATCH_TH_FMV_HW_X): Correct coding.
(MASK_TH_FMV_HW_X): Likewise.
(MATCH_TH_FMV_X_HW): Likewise.
(MASK_TH_FMV_X_HW): Likewise.

opcodes/ChangeLog:

* riscv-opc.c: Correct operands.

18 months agoRemove redundant Byte, Word, Dword and Qword from insn templates.
Cui, Lili [Wed, 13 Dec 2023 12:56:46 +0000 (12:56 +0000)] 
Remove redundant Byte, Word, Dword and Qword from insn templates.

opcodes/ChangeLog:

* i386-opc.tbl: Remove redundant Byte, Word, Dword and Qword.

18 months agoAutomatic date update in version.in
GDB Administrator [Thu, 14 Dec 2023 00:00:23 +0000 (00:00 +0000)] 
Automatic date update in version.in

18 months agoUse unique_xmalloc_ptr in explicit_location_spec
Tom Tromey [Sun, 10 Dec 2023 14:45:24 +0000 (07:45 -0700)] 
Use unique_xmalloc_ptr in explicit_location_spec

This changes explicit_location_spec to use unique_xmalloc_ptr,
removing some manual memory management.

Reviewed-By: John Baldwin <jhb@FreeBSD.org>
18 months agoUse unique_xmalloc_ptr in linespec_location_spec
Tom Tromey [Sun, 10 Dec 2023 14:22:07 +0000 (07:22 -0700)] 
Use unique_xmalloc_ptr in linespec_location_spec

This changes linespec_location_spec to use unique_xmalloc_ptr,
removing some manual memory management.

Reviewed-By: John Baldwin <jhb@FreeBSD.org>
18 months agoUpdate Make const_1_mode print $1 in AT&T syntax
H.J. Lu [Wed, 13 Dec 2023 17:19:47 +0000 (09:19 -0800)] 
Update Make const_1_mode print $1 in AT&T syntax

commit b70a487d5945b13e5ab503be4fc37b964819ec0e
Author: Cui, Lili <lili.cui@intel.com>
Date:   Wed Dec 13 06:07:36 2023 +0000

    Make const_1_mode print $1 in AT&T syntax

changes disassembler output from

d1 f8                   sar    %eax

to

d1 f8                   sar    $1,%eax

Adjust pe-x86-64-6.od accordingly.

* testsuite/ld-x86-64/pe-x86-64-6.od: Adjusted.

18 months ago[gdb/tui] add SingleKey bindings for reverse execution commands
Magne Hov [Wed, 13 Dec 2023 11:45:49 +0000 (11:45 +0000)] 
[gdb/tui] add SingleKey bindings for reverse execution commands

The bindings for the reverse execution commands are the same letters
as the forward execution command, but with the opposite case. This way
one can simply hold down the Shift modifier key or tap the Caps Lock key
to change the direction of execution.

Reviewed-By: Eli Zaretskii <eliz@gnu.org>
Approved-By: Tom Tromey <tom@tromey.com>
18 months agogdb/python: avoid use of _PyOS_ReadlineTState
Andrew Burgess [Wed, 6 Dec 2023 15:57:11 +0000 (16:57 +0100)] 
gdb/python: avoid use of _PyOS_ReadlineTState

In python/py-gdb-readline.c we make use of _PyOS_ReadlineTState,
however, this variable is no longer public in Python 3.13, and so GDB
no longer builds.

We are making use of _PyOS_ReadlineTState in order to re-acquire the
Python Global Interpreter Lock (GIL).  The _PyOS_ReadlineTState
variable is set in Python's outer readline code prior to calling the
user (GDB) supplied readline callback function, which for us is
gdbpy_readline_wrapper.  The gdbpy_readline_wrapper function is called
without the GIL held.

Instead of using _PyOS_ReadlineTState, I propose that we switch to
calling PyGILState_Ensure() and PyGILState_Release().  These functions
will acquire the GIL based on the current thread.  I think this should
be sufficient; I can't imagine why we'd be running
gdbpy_readline_wrapper on one thread on behalf of a different Python
thread.... that would be unexpected I think.

Approved-By: Tom Tromey <tom@tromey.com>
18 months agogdb: move gdbpy_gil into python-internal.h
Alexandra Hájková [Wed, 6 Dec 2023 16:17:25 +0000 (17:17 +0100)] 
gdb: move gdbpy_gil into python-internal.h

Move gdbpy_gil class into python-internal.h, the next
commit wants to make use of this class from a file other
than python.c.

Approved-By: Tom Tromey <tom@tromey.com>
18 months agogdb: improve error reporting for 'save gdb-index'
Andrew Burgess [Sat, 2 Dec 2023 11:36:43 +0000 (11:36 +0000)] 
gdb: improve error reporting for 'save gdb-index'

While making recent changes to 'save gdb-index' command I triggered
some errors -- of the kind a user might be expected to trigger if they
do something wrong -- and I didn't find GDB's output as helpful as it
might be.

For example:

  $ gdb -q /tmp/hello.x
  ...
  (gdb) save gdb-index /non_existing_dir
  Error while writing index for `/tmp/hello': mkstemp: No such file or directory.

That the error message mentions '/tmp/hello', which does exist, but
doesn't mention '/non_existing_dir', which doesn't is, I think,
confusing.

Also, I find the 'mkstemp' in the error message confusing for a user
facing error.  A user might not know what mkstemp means, and even if
they do, that it appears in the error message is an internal GDB
detail.  The user doesn't care what function failed, but wants to know
what was wrong with their input, and what they should do to fix
things.

Similarly, for a directory that does exist, but can't be written to:

  (gdb) save gdb-index /no_access_dir
  Error while writing index for `/tmp/hello': mkstemp: Permission denied.

In this case, the 'Permission denied' might make the user thing there
is a permissions issue with '/tmp/hello', which is not the case.

After this patch, the new errors are:

  (gdb) save gdb-index /non_existing_dir
  Error while writing index for `/tmp/hello': `/non_existing_dir': No such file or directory.

and:

  (gdb) save gdb-index /no_access_dir
  Error while writing index for `/tmp/hello': `/no_access_dir': Permission denied.

we also have:

  (gdb) save gdb-index /tmp/not_a_directory
  Error while writing index for `/tmp/hello': `/tmp/not_a_directory': Is not a directory.

I think these do a better job of guiding the user towards fixing the
problem.

I've added a new test that exercises all of these cases, and also
checks the case where a user tries to use an executable that already
contains an index in order to generate an index.  As part of the new
test I've factored out some code from ensure_gdb_index (lib/gdb.exp)
into a new proc (get_index_type), which I've then used in the new
test.  I've confirmed that all the tests that use ensure_gdb_index
still pass.

During review it was pointed out that the testsuite proc
have_index (lib/gdb.exp) is similar to the new get_index_type proc, so
I've rewritten have_index to also use get_index_type, I've confirmed
that all the tests that use have_index still pass.

Nothing that worked correctly before this patch should give an error
after this patch; I've only changed the output when the user was going
to get an error anyway.

Reviewed-By: Tom de Vries <tdevries@suse.de>
Reviewed-By: Tom Tromey <tom@tromey.com>
Approved-By: Tom Tromey <tom@tromey.com>
18 months agoMake const_1_mode print $1 in AT&T syntax
Cui, Lili [Wed, 13 Dec 2023 06:07:36 +0000 (06:07 +0000)] 
Make const_1_mode print $1 in AT&T syntax

Make const_1_mode print $1 in AT&T syntax, otherwise
there will be correctness issues when it is extended
to support APX NDD,

gas/ChangeLog:

        * testsuite/gas/i386/intel.d: Adjust testcase.
        * testsuite/gas/i386/lfence-load.d: Ditto.
        * testsuite/gas/i386/noreg16-data32.d: Ditto.
        * testsuite/gas/i386/noreg16.d: Ditto.
        * testsuite/gas/i386/noreg32-data16.d: Ditto.
        * testsuite/gas/i386/noreg32.d: Ditto.
        * testsuite/gas/i386/noreg64-data16.d: Ditto.
        * testsuite/gas/i386/noreg64-rex64.d: Ditto.
        * testsuite/gas/i386/noreg64.d: Ditto.
        * testsuite/gas/i386/opcode-suffix.d: Ditto.
        * testsuite/gas/i386/opcode.d: Ditto.
        * testsuite/gas/i386/x86-64-lfence-load.d: Ditto.
        * testsuite/gas/i386/x86-64-opcode.d: Ditto.

opcodes/ChangeLog:

        * i386-dis.c (OP_I): Make const_1_mode print $1 in AT&T syntax.

18 months agoClean base_reg and assign correct values to regs for input_output_operand (%dx).
Cui, Lili [Wed, 13 Dec 2023 06:04:15 +0000 (06:04 +0000)] 
Clean base_reg and assign correct values to regs for input_output_operand (%dx).

For special processing of input and output operands (%dx),
the state of some variables needs to be cleaned.

gas/ChangeLog:

* config/tc-i386.c (i386_att_operand): Assign values to regs and
clean i.base_reg for input output operand (%dx).

18 months agoAutomatic date update in version.in
GDB Administrator [Wed, 13 Dec 2023 00:00:20 +0000 (00:00 +0000)] 
Automatic date update in version.in

18 months agogdbserver/win32: fix crash on detach
Stefano Moioli [Wed, 6 Dec 2023 00:42:19 +0000 (01:42 +0100)] 
gdbserver/win32: fix crash on detach

this patch fixes a crash in gdbserver whenever a process is detached.
the crash is caused by `detach` calling `remove_process` before `win32_clear_inferiors`

error message:

Detaching from process 184
../../gdbserver/inferiors.cc:160: A problem internal to GDBserver has been detec
ted.
remove_process: Assertion `find_thread_process (process) == NULL' failed.

This application has requested the Runtime to terminate it in an unusual way.
Please contact the application's support team for more information.

Approved-By: Tom Tromey <tom@tromey.com>
18 months agoFix gdb.FinishBreakpoint when returning to an inlined function
Hannes Domani [Tue, 12 Dec 2023 14:57:14 +0000 (15:57 +0100)] 
Fix gdb.FinishBreakpoint when returning to an inlined function

Currently, when creating a gdb.FinishBreakpoint in a function
called from an inline frame, it will never be hit:
```
(gdb) py fb=gdb.FinishBreakpoint()
Temporary breakpoint 1 at 0x13f1917b4: file C:/src/repos/binutils-gdb.git/gdb/testsuite/gdb.python/py-finish-breakpoint.c, line 47.
(gdb) c
Continuing.
Thread-specific breakpoint 1 deleted - thread 1 no longer in the thread list.
[Inferior 1 (process 1208) exited normally]
```

The reason is that the frame_id of a breakpoint has to be the
ID of a real frame, ignoring any inline frames.

With this fixed, it's working correctly:
```
(gdb) py fb=gdb.FinishBreakpoint()
Temporary breakpoint 1 at 0x13f5617b4: file C:/src/repos/binutils-gdb.git/gdb/testsuite/gdb.python/py-finish-breakpoint.c, line 47.
(gdb) c
Continuing.

Breakpoint 1, increase_inlined (a=0x40fa5c) at C:/src/repos/binutils-gdb.git/gdb/testsuite/gdb.python/py-finish-breakpoint.c:47
(gdb) py print(fb.return_value)
-8
```

Approved-By: Tom Tromey <tom@tromey.com>
18 months agoSupport dynamically computed convenience variables in get_internalvar_integer
Hannes Domani [Tue, 12 Dec 2023 14:53:12 +0000 (15:53 +0100)] 
Support dynamically computed convenience variables in get_internalvar_integer

When using $_thread in info threads to showonly the current thread,
you get this error:
```
(gdb) info thread $_thread
Convenience variable must have integer value.
Args must be numbers or '$' variables.
```

It's because $_thread is a dynamically computed convenience
variable, which isn't supported yet by get_internalvar_integer.

Now the output looks like this:
```
(gdb) info threads $_thread
  Id   Target Id           Frame
* 1    Thread 10640.0x2680 main () at C:/src/repos/binutils-gdb.git/gdb/testsuite/gdb.base/gdbvars.c:21
```

Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=17600
Approved-By: Tom Tromey <tom@tromey.com>
18 months agoSupport rodata in flash for more AVR devices
Georg-Johann Lay [Tue, 12 Dec 2023 11:29:16 +0000 (11:29 +0000)] 
Support rodata in flash for more AVR devices

  PR 31124
  * Makefile.am (ALL_EMULATION_SOURCES): Add eavrxmega2_flmap.c and eavrxmega4_flmap.c.
  * Makefile.in: Regenerate.
  * configure.tgt: Add eavrxmega2_flmap and eavrxmega4_flmap to avr's targ_extra_emuls list.
  * emulparams/avrxmega2.sh (MAYBE_FLMAP): Define.
  * emulparams/avrxmega2_flmap.sh: New file.
  * emulparams/avrxmega4.sh (MAYBE_FLMAP): Define.
  * emulparams/avrxmega4_flmap.sh: New file.
  * scripttempl/avr.sc: Add support for HAVE_FLMAP.

18 months agoFix whitespace snafu in tc-riscv.c
Nick Clifton [Tue, 12 Dec 2023 10:02:54 +0000 (10:02 +0000)] 
Fix whitespace snafu in tc-riscv.c

18 months agoRISC-V: Emit R_RISCV_RELAX for the la/lga pseudo instruction
Rui Ueyama [Wed, 20 Sep 2023 08:31:26 +0000 (17:31 +0900)] 
RISC-V: Emit R_RISCV_RELAX for the la/lga pseudo instruction

Some psABIs define a relaxation to turn a GOT load into a PC-relative
address materialization.  For example, the AArch64's psABI allows
adrp+ldr to be rewritten to nop+adr to eliminate the memory load.
This patch is part of the effort to make such optimization possible
for RISC-V.

For RISC-V, we use the la assembly pseudo instruction to load a symbol
address from the GOT. The pseudo instruction is expanded to auipc+ld.
If the address loaded by the instruction pair is actually a PC-relative
link-time constant, we want the linker to rewrite the instruction pair
with auipc+addi.

We can't rewrite all existing auipc+ld pairs with auipc+addi in the
linker because there might be code that jumps to the middle of the
instruction pair.  That should be extremely rare, if ever exists, but
you can at least in theory write a program in assembly that jumps to
the ld instruction of the instruction pair.  We need a marker to
identify that an auipc+ld can be safely relaxed (i.e. they are emitted
for la).

This patch is to annotate R_RISCV_GOT_HI20 with R_RISCV_RELAX only
when the relocation is emitted for the la pseudo instruction.  The
linker will use it as a signal that the instruction pair can be safely
relaxed.

Proposal to the RISC-V psABI:
https://github.com/riscv-non-isa/riscv-elf-psabi-doc/pull/397

gas/
* config/tc-riscv.c (source_macro): New static int variable.
The identifier of the assembler macro we are expanding, if any.
(append_insn): Updated source_macro to tc_fix_data, to record
which macro expands, if any.
(macro): Record which macro expands into source_macro.  Reset
source_macro to -1 at the end.
(md_apply_fix): Apply R_RISCV_RELAX if pcrel_got_hi is expanded
from macro LA/LGA.
* config/tc-riscv.h (struct riscv_fix, TC_FIX_TYPE, TC_INIT_FIX_DATA):
Defined to record source_macro into fixups for riscv target.
* testsuite/gas/riscv/la-variants.d: Updated.

18 months agoRISC-V: Resolve PCREL_HI20/LO12_I/S fixups with local symbols while `-mno-relax'
Lifang Xia [Wed, 29 Nov 2023 09:17:22 +0000 (17:17 +0800)] 
RISC-V: Resolve PCREL_HI20/LO12_I/S fixups with local symbols while `-mno-relax'

In the scenario of generating .ko files, the kernel does not relax the .ko
files.  However, due to the large amount of relax and local relocation
information, this increases the size of the .ko files.  In this patch, it
will finish the fixup of the local relocations while with `-mno-relax' option.
This can reduce the size of the relocation table.

The implemntation is based on the code from bfd/elfnn-riscv.c.  We probably
can move the code to bfd/elfxx-riscv.c, so that can reduce duplicate code,
just like what we did for the architecture parser.

Besides, maybe not only pcrel_hi/lo12 relocation with local symbols can be
resolved at assembler time.  Other pc-relative relocation, like branch,
may also be able to perform related optimizations.

Passed the gcc/binutils regressions of riscv-gnu-toolchain.

gas/
* config/tc-riscv.c (riscv_pcrel_hi_reloc): New structure.  Record all
PC-relative high-part relocation that we have encountered to help us
resolve the corresponding low-part relocation later.
(riscv_pcrel_hi_fixup_hash): The hash table to record pcrel_hi fixups.
(riscv_pcrel_fixup_hash): New function.  Likewise.
(riscv_pcrel_fixup_eq): Likewise.
(riscv_record_pcrel_fixup): Likewise.
(md_begin): Init pcrel_hi hash table.
(md_apply_fix):  For PCREL_HI20 relocation, do fixup and record
the pcrel_hi relocs, mark as done while with `-mno-relax'.  For
PCREL_LO12_I/S relocation, do fixup and mark as done while with
`-mno-relax'.
(riscv_md_end): New function.  Free pcrel_hi hash table.
* config/tc-riscv.h (md_end): Define md_end with riscv_md_end.
gas/
* testsuite/gas/riscv/fixup-local*: New tests.

18 months agoAutomatic date update in version.in
GDB Administrator [Tue, 12 Dec 2023 00:00:14 +0000 (00:00 +0000)] 
Automatic date update in version.in

18 months agoImplement DAP cancellation
Tom Tromey [Tue, 7 Nov 2023 17:56:07 +0000 (10:56 -0700)] 
Implement DAP cancellation

This implements DAP cancellation.  A new object is introduced that
handles the details of cancellation.  While cancellation is inherently
racy, this code attempts to make it so that gdb doesn't inadvertently
cancel the wrong request.

Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=30472
Approved-By: Eli Zaretskii <eliz@gnu.org>
Reviewed-By: Kévin Le Gouguec <legouguec@adacore.com>
18 months agoCatch KeyboardInterrupt in send_gdb_with_response
Tom Tromey [Thu, 30 Nov 2023 20:57:09 +0000 (13:57 -0700)] 
Catch KeyboardInterrupt in send_gdb_with_response

Cancellation will generally be seen by the DAP code as a
KeyboardInterrupt.  However, this derives from BaseException and not
Exception, so a small change is needed to send_gdb_with_response, to
forward the exception to the DAP server thread.

Reviewed-By: Kévin Le Gouguec <legouguec@adacore.com>
18 months agoRename a couple of DAP procs in the testsuite
Tom Tromey [Thu, 30 Nov 2023 20:28:48 +0000 (13:28 -0700)] 
Rename a couple of DAP procs in the testsuite

This renames a couple of DAP procs in the testsuite, to clarify that
they are now exported.  The cancellation test will need these.

Reviewed-By: Kévin Le Gouguec <legouguec@adacore.com>
18 months agoIntroduce gdb.interrupt
Tom Tromey [Thu, 16 Nov 2023 17:44:42 +0000 (10:44 -0700)] 
Introduce gdb.interrupt

DAP cancellation needs a way to interrupt whatever is happening on
gdb's main thread -- whether that is the inferior, a gdb CLI command,
or Python code.

This patch adds a new gdb.interrupt() function for this purpose.  It
simply sets the quit flag and lets gdb do the rest.

No tests in this patch -- instead this is tested via the DAP
cancellation tests.

Reviewed-By: Eli Zaretskii <eliz@gnu.org>
Reviewed-By: Kévin Le Gouguec <legouguec@adacore.com>
18 months agoMove DAP JSON reader to its own thread
Tom Tromey [Tue, 7 Nov 2023 16:23:47 +0000 (09:23 -0700)] 
Move DAP JSON reader to its own thread

This changes the DAP server to move the JSON reader to a new thread.
This is key to implementing request cancellation, as now requests can
be read while an earlier one is being serviced.

Reviewed-By: Kévin Le Gouguec <legouguec@adacore.com>
18 months agoClean up handling of DAP not-stopped response
Tom Tromey [Thu, 30 Nov 2023 20:53:23 +0000 (13:53 -0700)] 
Clean up handling of DAP not-stopped response

This patch introduces a new NotStoppedException type and changes the
DAP implementation of "not stopped" to use it.  I was already touching
some code in this area and I thought this looked a little cleaner.
This also has the advantage that we can now choose not to log the
exception -- previously I was sometimes a bit alarmed when seeing this
in the logs, even though it is harmless.

Reviewed-By: Kévin Le Gouguec <legouguec@adacore.com>
18 months agoSimplify DAP stop-reason code
Tom Tromey [Fri, 3 Nov 2023 19:59:10 +0000 (13:59 -0600)] 
Simplify DAP stop-reason code

Now that gdb adds stop-reason details to stop events, we can simplify
the DAP code to emit correct stop reasons in its own events.  For the
most part a simple renaming of gdb reasons is sufficient; however,
"pause" must still be handled specially.

18 months agoEmit stop reason details in Python stop events
Tom Tromey [Fri, 3 Nov 2023 19:23:41 +0000 (13:23 -0600)] 
Emit stop reason details in Python stop events

This changes Python stop events to carry a "details" dictionary, that
holds any relevant information about the stop.  The details are
constructed using more or less the same procedure as is done for MI.

Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=13587
Reviewed-By: Eli Zaretskii <eliz@gnu.org>
18 months agoMove py_ui_out to a new header
Tom Tromey [Tue, 14 Nov 2023 17:47:54 +0000 (10:47 -0700)] 
Move py_ui_out to a new header

This moves the declaration of py_ui_out to a new header, so that it
can more readily be used by other code.

18 months ago[gdb/testsuite] Fix $eol regexp usage in some test-cases
Tom de Vries [Mon, 11 Dec 2023 16:15:17 +0000 (17:15 +0100)] 
[gdb/testsuite] Fix $eol regexp usage in some test-cases

Commit cff71358132 ("gdb/testsuite: tighten up some end-of-line patterns") replaced:
...
set eol "\[\r\n\]+"
...
with the more strict:
...
set eol "\r\n"
...
in a few test-cases, but didn't update all uses of eol accordingly.

Fix this in three gdb.ada test-cases.

Tested on x86_64-linux.

Approved-By: Andrew Burgess <aburgess@redhat.com>
18 months agoUse TARGET_SYSROOT_PREFIX in more places
Tom Tromey [Sun, 10 Dec 2023 22:37:34 +0000 (15:37 -0700)] 
Use TARGET_SYSROOT_PREFIX in more places

I found some spots using "target:"; I think it's better to use the
define everywhere, so this changes these to use TARGET_SYSROOT_PREFIX.
In some spots, is_target_filename is used rather than an explicit
check.

Approved-By: Andrew Burgess <aburgess@redhat.com>
18 months agoAdd DAP items to NEWS
Tom Tromey [Mon, 11 Dec 2023 14:50:46 +0000 (07:50 -0700)] 
Add DAP items to NEWS

Now that DAP is in GDB 14, significant changes to it should be noted
in NEWS.  This patch adds a note for a fix that's already gone in.  I
started a new section in NEWS because more changes are coming.

Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=30473
Approved-By: Eli Zaretskii <eliz@gnu.org>
18 months agoFix dynamic_cast
Hannes Domani [Tue, 29 Mar 2022 18:05:06 +0000 (20:05 +0200)] 
Fix dynamic_cast

PR29011 notes that dynamic_cast does not work correctly if
classes with virtual methods are involved, some of the results
wrongly point into the vtable of the derived class:
```
(gdb) p vlr
$1 = (VirtualLeftRight *) 0x162240
(gdb) p vl
$2 = (VirtualLeft *) 0x162240
(gdb) p vr
$3 = (VirtualRight *) 0x162250
(gdb) p dynamic_cast<VirtualLeftRight*>(vlr)
$4 = (VirtualLeftRight *) 0x13fab89b0 <vtable for VirtualLeftRight+16>
(gdb) p dynamic_cast<VirtualLeftRight*>(vl)
$5 = (VirtualLeftRight *) 0x13fab89b0 <vtable for VirtualLeftRight+16>
(gdb) p dynamic_cast<VirtualLeftRight*>(vr)
$6 = (VirtualLeftRight *) 0x13fab89b0 <vtable for VirtualLeftRight+16>
(gdb) p dynamic_cast<VirtualLeft*>(vlr)
$7 = (VirtualLeft *) 0x162240
(gdb) p dynamic_cast<VirtualLeft*>(vl)
$8 = (VirtualLeft *) 0x13fab89b0 <vtable for VirtualLeftRight+16>
(gdb) p dynamic_cast<VirtualLeft*>(vr)
$9 = (VirtualLeft *) 0x162240
(gdb) p dynamic_cast<VirtualRight*>(vlr)
$10 = (VirtualRight *) 0x162250
(gdb) p dynamic_cast<VirtualRight*>(vl)
$11 = (VirtualRight *) 0x162250
(gdb) p dynamic_cast<VirtualRight*>(vr)
$12 = (VirtualRight *) 0x13fab89b0 <vtable for VirtualLeftRight+16>
```

For the cases where the dynamic_cast type is the same as the
original type, it used the ARG value for the result, which in
case of pointer types was already the dereferenced value.

And the TEM value at the value address was created with the
pointer/reference type, not the actual class type.

With these fixed, the dynamic_cast results make more sense:
```
(gdb) p vlr
$1 = (VirtualLeftRight *) 0x692240
(gdb) p vl
$2 = (VirtualLeft *) 0x692240
(gdb) p vr
$3 = (VirtualRight *) 0x692250
(gdb) p dynamic_cast<VirtualLeftRight*>(vlr)
$4 = (VirtualLeftRight *) 0x692240
(gdb) p dynamic_cast<VirtualLeftRight*>(vl)
$5 = (VirtualLeftRight *) 0x692240
(gdb) p dynamic_cast<VirtualLeftRight*>(vr)
$6 = (VirtualLeftRight *) 0x692240
(gdb) p dynamic_cast<VirtualLeft*>(vlr)
$7 = (VirtualLeft *) 0x692240
(gdb) p dynamic_cast<VirtualLeft*>(vl)
$8 = (VirtualLeft *) 0x692240
(gdb) p dynamic_cast<VirtualLeft*>(vr)
$9 = (VirtualLeft *) 0x692240
(gdb) p dynamic_cast<VirtualRight*>(vlr)
$10 = (VirtualRight *) 0x692250
(gdb) p dynamic_cast<VirtualRight*>(vl)
$11 = (VirtualRight *) 0x692250
(gdb) p dynamic_cast<VirtualRight*>(vr)
$12 = (VirtualRight *) 0x692250
```

Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=29011
Approved-By: Tom Tromey <tom@tromey.com>
18 months agoLoongArch: Add support for <b ".L1"> and <beq, $t0, $t1, ".L1">
mengqinggang [Sun, 10 Dec 2023 09:41:32 +0000 (17:41 +0800)] 
LoongArch: Add support for <b ".L1"> and <beq, $t0, $t1, ".L1">

Support symbol names enclosed in double quotation marks.

18 months agobfd_find_nearest_line leaks dwarf_rnglists_buffer
Konstantin Isakov [Mon, 11 Dec 2023 00:45:32 +0000 (21:45 -0300)] 
bfd_find_nearest_line leaks dwarf_rnglists_buffer

* dwarf2.c (_bfd_dwarf2_cleanup_debug_info): Free dwarf_rnglists_buffer.

18 months agoregen bfd POTFILES
Alan Modra [Mon, 11 Dec 2023 04:15:54 +0000 (14:45 +1030)] 
regen bfd POTFILES

18 months agoRISC-V/gas: Clarify the definition of `relaxable' in md_apply_fix
Nelson Chu [Mon, 11 Dec 2023 03:07:35 +0000 (11:07 +0800)] 
RISC-V/gas: Clarify the definition of `relaxable' in md_apply_fix

The `relaxable' in md_apply_fix means if the relocation can be relaxed or not
in link-time generally.  We can use `.option relax/norelax' to enable/disable
relaxations for some specific areas, so the value of `riscv_opts.relax'
will be changed dynamically.  The `fixP->fx_tcbit' records the correct value
of `riscv_opts.relax' for every relocation.  Therefore, set `relaxable' to
`riscv_opts.relax' will cause unexpected behavior for the following case,

.option norelax
lla a1, foo1
.option relax
lla a2, foo2
.option norelax
lla a3, foo3

For the current assembler, the final value of `riscv_opts.relax' is false, so
the second `lla a2, foo2' won't have R_RISCV_RELAX relocation, but should have.

gas/
* config/tc-riscv.c (md_apply_fix): Set the value of `relaxable' to
`riscv_opts.relax' is wrong.  It should be `true' generally.

18 months agoR_MICROMIPS_GPREL7_S2
Alan Modra [Wed, 18 Oct 2023 22:21:47 +0000 (08:51 +1030)] 
R_MICROMIPS_GPREL7_S2

This reloc is meant for the 16-bit LWGP instruction, 0x6400/0xfc00
match/mask encoding in `micromips_opcodes'.  It is correctly specified
to operate on a half-word by the howtos in elf32-mips.c, elfn32-mips.c
and elf64-mips.c, but is incorrectly subject to shuffle/unshuffle in
code like _bfd_mips_elf32_gprel16_reloc.

Current behaviour when applying the reloc to .byte 0x11,0x22,0x33,0x44
is to apply the reloc to byte 0x22 when big-endian, and to byte 0x33
when little-endian.  Big-endian behaviour is unchanged after this
patch and little-endian correctly applies the reloc to byte 0x11.

The patch also corrects REL addend extraction from section contents,
and overflow checking.  gold had all of the bfd problems with this
reloc and additionally did not apply the rightshift by two.

bfd/
* elfxx-mips.c (micromips_reloc_shuffle_p): Return false for
R_MICROMIPS_GPREL7_S2.
(mips_elf_calculate_relocation): Correct sign extension and
overflow calculation for R_MICROMIPS_GPREL7_S2.
(_bfd_mips_elf_relocate_section): Update small-data overflow
message.
gold/
* mips.cc (Mips_relocate_functions::should_shuffle_micromips_reloc):
Return false for R_MICROMIPS_GPREL7_S2.
(Mips_relocate_functions::mips_reloc_unshuffle): Update comment.
(Mips_relocate_functions::relgprel): Remove R_MICROMIPS_GPREL7_S2
handling.
(Mips_relocate_functions::relgprel7): New function.
(Target_mips::Relocate::relocate): Adjust to suit.
ld/
* testsuite/ld-mips-elf/reloc-4.d: Adjust expected error.
* testsuite/ld-mips-elf/reloc-5.d: Likewise.

18 months agoAutomatic date update in version.in
GDB Administrator [Mon, 11 Dec 2023 00:00:14 +0000 (00:00 +0000)] 
Automatic date update in version.in

18 months agoFix "not not" in Python documentation
Tom Tromey [Sun, 10 Dec 2023 22:26:46 +0000 (15:26 -0700)] 
Fix "not not" in Python documentation

I noticed a "not not" in the Python documentation where just "not" was
meant.  This patch fixes the error.

18 months agoAdd some new DW_IDX_* constants
Tom Tromey [Sat, 9 Dec 2023 16:19:30 +0000 (09:19 -0700)] 
Add some new DW_IDX_* constants

I've reimplemented the .debug_names code in GDB -- it was quite far
from being correct, and the new implementation is much closer to what
is specified by DWARF.

However, the new writer in GDB needs to emit some symbol properties,
so that the reader can be fully functional.  This patch adds a few new
DW_IDX_* constants, and tries to document the existing extensions as
well.  (My patch series add more documentation of these to the GDB
manual as well.)

2023-12-10  Tom Tromey  <tom@tromey.com>

* dwarf2.def (DW_IDX_GNU_internal, DW_IDX_GNU_external): Comment.
(DW_IDX_GNU_main, DW_IDX_GNU_language, DW_IDX_GNU_linkage_name):
New constants.

18 months agoImprove performance of the H8 simulator
Jeff Law [Sun, 10 Dec 2023 20:24:59 +0000 (13:24 -0700)] 
Improve performance of the H8 simulator

Running the H8 port through the GCC testsuite currently takes 4h 30m on my
fastest server -- that's roughly 1.5hrs per multilib tested and many tests are
disabled for various reasons.

To put that 1.5hr/multilib in perspective, that's roughly 3X the time for other
embedded targets.  Clearly something isn't working as well as it should.

A bit of digging with perf shows that we're spending a crazy amount of time
decoding instructions in the H8 simulator.  It's not hard to see why --
basically we take a blob of instruction data, then try to match it to every
instruction in the H8 opcode table starting at the beginning.  That table has
~8000 entries (each different addressing mode is considered a different
instruction in the table).

Naturally my first thought was to sort the table and use a binary search to
find the right entry.  That's made excessively complex due to the encoding on
the H8.  Just getting the sort right would be much more complex than I'd
consider advisable.

Another thought was to build a mapping to the right entry for all the
instructions that can be disambiguated based on the first nibble (4 bits) of
instruction data and a mapping for those which can be disambiguated based on
the first byte of instruction data.

That seemed feasible until I realized that the H8/SX did some truly horrid
things with encoding branches in the 0x4XYY opcode space.  It uses an "always
zero" bit in the offset to encode new semantic information.  So we can't select
on just 0x4X.  Ugh!

We could always to a custom decoder.  I've done several through the years, they
can be very fast.  But no way I can justify the time to do that.

So what I settled on was to first sort the opcode table by the first nibble,
then find the index of the first instruction for each nibble. Decoding uses
that index to start its search.  This cuts the overall build/test by more than
half.

Next I adjusted the sort so that instructions that are not available on the
current sub architecture are put at the end of the table.   This shaves another
~15% off the total cycle time.

The net of the two changes is on my fastest server we've gone from 4:30 to 1:40
running the GCC testsuite.  Same test results before/after, of course.  It's
still not fast, but it's a hell of a lot better.

18 months agoAutomatic date update in version.in
GDB Administrator [Sun, 10 Dec 2023 00:00:10 +0000 (00:00 +0000)] 
Automatic date update in version.in

18 months ago[gdb/tui] Handle shared border in fixed-sized layout
Tom de Vries [Sat, 9 Dec 2023 13:44:49 +0000 (14:44 +0100)] 
[gdb/tui] Handle shared border in fixed-sized layout

In tui_layout_split::apply I noticed that for variable-size layouts we take
share_box into account by decreasing used_size:
...
          used_size += info[i].size;
          if (info[i].share_box)
    --used_size;
...
but not for fixed-size layouts:
...
      if (info[i].min_size == info[i].max_size)
available_size -= info[i].min_size;
...

Fix this by increasing available_size for fixed-size layouts with shared box.

Tested on x86_64-linux.

Approved-By: Tom Tromey <tom@tromey.com>
18 months agoAutomatic date update in version.in
GDB Administrator [Sat, 9 Dec 2023 00:00:17 +0000 (00:00 +0000)] 
Automatic date update in version.in

18 months ago[gdb/tui] Show focus window in status line
Tom de Vries [Fri, 8 Dec 2023 22:02:31 +0000 (23:02 +0100)] 
[gdb/tui] Show focus window in status line

The focused window is highlighted by using active-border-kind instead of
border-kind.

But if the focused window is the cmd window (which is an unboxed window), then
no highlighting is done, and it's not obvious from looking at the screen which
window has the focus.  Instead, you have to notice the absence of highlighting
on boxed windows, and then infer that the focus is on the unboxed window.

That approach stops working if there are multiple unboxed windows.

Likewise if highlighting is switched off by setting active-border-kind to the
same value as border-kind.

Make it more explicit which window has the focus by mentioning it in the status
window, like so:
...
native process 8282 (src) In: main                      L7    PC: 0x400525
...

Tested on x86_64-linux and ppc64le-linux.

Tested-By: Alexandra Petlanova Hajkova <ahajkova@redhat.com>
Reviewed-By: Eli Zaretskii <eliz@gnu.org>
Approved-By: Tom Tromey <tom@tromey.com>
18 months agoFix printing of global variable stubs if no inferior is running
Hannes Domani [Fri, 8 Dec 2023 18:06:14 +0000 (19:06 +0100)] 
Fix printing of global variable stubs if no inferior is running

Since 3c45e9f915ae4aeab7312d6fc55a947859057572 gdb crashes when trying
to print a global variable stub without a running inferior, because of
a missing nullptr-check (the block_scope function took care of that
check before it was converted to a method).

With this check it works again:
```
(gdb) print s
$1 = <incomplete type>
```

Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=31128
Approved-By: Tom Tromey <tom@tromey.com>
18 months agogdb/testsuite: tighten up some end-of-line patterns
Andrew Burgess [Wed, 29 Nov 2023 16:10:46 +0000 (16:10 +0000)] 
gdb/testsuite: tighten up some end-of-line patterns

Following on from the previous commit, I searched the testsuite for
places where we did:

  set eol "<some pattern>"

in most cases the <some pattern> could be replaced with "\r\n" though
in the stabs test I've switched to using the multi_line proc as that
seemed like a better choice.

In gdb.ada/info_types.exp I did need to add an extra use of $eol as
the previous pattern would match multiple newlines, and in this one
place we were actually expecting to match multiple newlines.  The
tighter pattern only matches a single newline, so we now need to be
explicit when multiple newlines are expected -- I think this is a good
thing.

All the tests are still passing for me after these changes.

Approved-By: Tom Tromey <tom@tromey.com>
18 months agogdb/testsuite: fix gdb.ada/complete.exp timeout in READ1 mode
Andrew Burgess [Wed, 29 Nov 2023 15:26:18 +0000 (15:26 +0000)] 
gdb/testsuite: fix gdb.ada/complete.exp timeout in READ1 mode

While reviewing another patch I spotted a timeout in
gdb.ada/complete.exp when testing in READ1 mode, e.g.:

  $ make check-read1 TESTS="gdb.ada/complete.exp"
  ...
  FAIL: gdb.ada/complete.exp: complete break ada (timeout)
  ...

The problem is an attempt to match the entire output from GDB within a
single gdb_test_multiple pattern, for a completion command that
returns a large number of completions.

This commit changes the gdb_test_multiple to process the output line
by line.  I don't use the gdb_test_multiple -lbl option, as I've
always found that option backward -- it checks for the \r\n at the
start of each line rather than the end, I think it's much clearer to
use '^' at the start of each pattern, and '\r\n' at the end, so that's
what I've done here.

.... Or I would, if this test didn't already define $eol as the end of
line regexp ... except that $eol was set to '[\r\n]*', which isn't
that helpful, so I've updated $eol to be just '\r\n' the actual end of
line regexp.

And now, the test passes without a timeout when using READ1.

There should be no change in what is tested after this commit.

Approved-By: Tom Tromey <tom@tromey.com>
18 months agogdbserver: allow for general 'monitor set debug COMPONENT VALUE' use
Andrew Burgess [Tue, 7 Nov 2023 16:46:34 +0000 (16:46 +0000)] 
gdbserver: allow for general 'monitor set debug COMPONENT VALUE' use

Building on the last commit, which added a general --debug=COMPONENT
option to the gdbserver command line, this commit updates the monitor
command to allow for general:

  (gdb) monitor set debug COMPONENT off|on

style commands.  Just like with the previous commit, the COMPONENT can
be any one of all, threads, remote, event-loop, and correspond to the
same set of global debug flags.

While on the command line it is possible to do:

  --debug=remote,event-loop,threads

the components have to be entered one at a time with the monitor
command.  I guess there's no reason why we couldn't allow component
grouping within the monitor command, but (to me) what I have here
seemed more in the spirit of GDB's existing 'set debug ...' commands.
If people want it then we can always add component grouping later.

Notice in the above that I use 'off' and 'on' instead of '0' and '1',
which is what the 'monitor set debug' command used to use.  The 0/1
can still be used, but I now advertise off/on in all the docs and help
text, again, this feels more inline with GDB's existing boolean
settings.

I have removed the two existing monitor commands:

  monitor set remote-debug 0|1
  monitor set event-loop-debug 0|1

These are replaced by:

  monitor set debug remote off|on
  monitor set debug event-loop off|on

respectively.

Approved-By: Tom Tromey <tom@tromey.com>
Reviewed-By: Eli Zaretskii <eliz@gnu.org>
18 months agogdbserver: allow the --debug command line option to take a value
Andrew Burgess [Sun, 5 Nov 2023 21:02:03 +0000 (21:02 +0000)] 
gdbserver: allow the --debug command line option to take a value

Currently, gdbserver has the following command line options related to
debugging output:

  --debug
  --remote-debug
  --event-loop-debug

This doesn't scale well.  If I want an extra debug component I need to
add another command line flag.

This commit changes --debug to take a list of components.

The currently supported components are: all, threads, remote, and
event-loop.  The 'threads' component represents the debug we currently
get from the --debug option.  And if --debug is used without a
component list then the threads component is assumed as the default.

Currently the threads component actually includes a lot of output that
is not really threads related.  In the future I'd like to split this
up into some new, separate components.  But that is not part of this
commit, or even this series.

The special component 'all' does what you'd expect: enables debug
output from all supported components.

The component list is parsed left to write, and you can prefix a
component with '-' to disable that component, so I can write:

  target> gdbserver --debug=all,-event-loop

to get debug for all components except the event-loop component.

I've removed the existing --remote-debug and --event-loop-debug
command line options, these are equivalent to --debug=remote and
--debug=event-loop respectively, or --debug=remote,event-loop to
enable both components.

In this commit I've only update the command line options, in the next
commit I'll update the monitor commands to support a similar
interface.

Reviewed-By: Eli Zaretskii <eliz@gnu.org>
Approved-By: Tom Tromey <tom@tromey.com>
18 months agogdb: fix GDB_DEBUG and GDBSERVER_DEBUG Makefile variables
Andrew Burgess [Wed, 22 Nov 2023 15:57:56 +0000 (15:57 +0000)] 
gdb: fix GDB_DEBUG and GDBSERVER_DEBUG Makefile variables

The gdb/testsuite/README file documents GDB_DEBUG and GDBSERVER_DEBUG
flags, which can be passed to make in order to enable debugging within
GDB or gdbserver respectively.

However, when I do:

  make check-gdb GDB_DEBUG=infrun

I don't see the corresponding debug feature within GDB being enabled.
Nor does:

  make check-gdb GDBSERVER_DEBUG=debug  \
       RUNTESTFLAGS="--target_board=native-extended-gdbserver"

Appear to enable gdbserver debugging.

I tracked this down to the GDB_DEBUG and GDBSERVER_DEBUG flags being
missing from the TARGET_FLAGS_TO_PASS variable in gdb/Makefile.  This
variable already contains lots of testing related flags, like
RUNTESTFLAGS and TESTS, so I think it makes sense to add GDB_DEBUG and
GDBSERVER_DEBUG here too.

With this done, this debug feature is now working as expected.

Approved-By: Tom Tromey <tom@tromey.com>
18 months agoUse pretty printers for struct member stubs
Hannes Domani [Fri, 8 Dec 2023 17:19:42 +0000 (18:19 +0100)] 
Use pretty printers for struct member stubs

PR29079 shows that pretty printers can be used for an incomplete
type (stub), but only when printing it directly, not if it's
part of another struct:
```
(gdb) p s
$1 = {pp m_i = 5}
(gdb) p s2
$2 = {m_s = <incomplete type>, m_l = 20}
```

The reason is simply that in common_val_print the check for stubs
is before any pretty printer is tried.
It works if the pretty printer is tried before the stub check:
```
(gdb) p s
$1 = {pp m_i = 5}
(gdb) p s2
$2 = {m_s = {pp m_i = 10}, m_l = 20}
```

Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=29079
Approved-By: Tom Tromey <tom@tromey.com>
18 months ago[gdb/tui] Fix displaying main after resizing
Tom de Vries [Fri, 8 Dec 2023 16:36:35 +0000 (17:36 +0100)] 
[gdb/tui] Fix displaying main after resizing

A TUI src window is displaying either:
- the source for the current frame,
- the source for main, or
- the string "[ No Source Available ]".

Since commit 03893ce67b5 ("[gdb/tui] Fix resizing of terminal to 1 or 2 lines")
we're able to resize the TUI to 1 line without crashing.

I noticed that if TUI is displaying main, and we resize to 1 line (destroying
the src window) and then back to a larger terminal (reconstructing the src
window), the TUI displays "[ No Source Available ]" instead of main.

Fix this by moving the responsibility for showing main from tui_enable to
tui_source_window_base::rerender.

Tested on x86_64-linux.

Approved-By: Tom Tromey <tom@tromey.com>
18 months agoAllow cast of 128-bit integer to pointer
Tom Tromey [Fri, 24 Nov 2023 19:10:53 +0000 (12:10 -0700)] 
Allow cast of 128-bit integer to pointer

PR rust/31082 points out that casting a 128-bit integer to a pointer
will fail.  This happens because a case in value_cast was not
converted to use GMP.

This patch fixes the problem.  I am not really sure that testing
against the negative value here makes sense, but I opted to just
preserve the existing behavior rather than change it.

Regression tested on x86-64 Fedora 38.

Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=31082

18 months agoFix dynamic type resolution for LOC_CONST and LOC_CONST_BYTES symbols
Tom Tromey [Mon, 27 Nov 2023 23:44:22 +0000 (16:44 -0700)] 
Fix dynamic type resolution for LOC_CONST and LOC_CONST_BYTES symbols

PR rust/31005 points out that dynamic type resolution of a LOC_CONST
or LOC_CONST_BYTES symbol will fail, leading to output like:

    from_index=<error reading variable: Cannot access memory at address 0x0>

This patch fixes the problem by using the constant value or bytes when
performing type resolution.

Thanks to tpzker@thepuzzlemaker.info for a first version of this
patch.

I also tested this on a big-endian PPC system (cfarm203).

Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=31005

18 months agogdb: Guarantee that an SAL's end is right before the next statement
Guinevere Larsen [Thu, 26 Oct 2023 14:28:54 +0000 (16:28 +0200)] 
gdb: Guarantee that an SAL's end is right before the next statement

When examining a failure that happens when testing
gdb.python/py-symtab.c with clang, I noticed that it was going wrong
because the test assumed that whenever we get an SAL, its end would
always be right before statement in the line table. This is true for GCC
compiled binaries, since gcc only adds statements to the line table, but
not true for clang compiled binaries.

This is the second time I run into a problem where GDB doesn't handle
non-statement line table entries correctly. The other was eventually
committed as 9ab50efc463ff723b8e9102f1f68a6983d320517: "gdb: fix until
behavior with trailing !is_stmt lines", but that commit only changes the
behavior for the 'until' command. In this patch I propose a more general
solution, making it so every time we generate the SAL for a given pc, we
set the end of the SAL to before the next statement or the first
instruciton in the next line, instead of naively assuming that to be the
case.

With this new change, the edge case is removed from the processing of
the 'until' command without regressing the accompanying test case, and
no other regressions were observed in the testsuite.

Approved-By: Tom Tromey <tom@tromey.com>
18 months agosim: aarch64: fix -Wunused-but-set-variable warnings
Mike Frysinger [Thu, 7 Dec 2023 04:07:50 +0000 (21:07 -0700)] 
sim: aarch64: fix -Wunused-but-set-variable warnings

18 months agosim: common: fix -Wunused-but-set-variable warnings
Mike Frysinger [Thu, 7 Dec 2023 04:05:51 +0000 (21:05 -0700)] 
sim: common: fix -Wunused-but-set-variable warnings

18 months agosim: ppc: fix -Wunused-but-set-variable warnings
Mike Frysinger [Thu, 7 Dec 2023 04:05:19 +0000 (21:05 -0700)] 
sim: ppc: fix -Wunused-but-set-variable warnings

18 months agosim: v850: fix -Wunused-but-set-variable warnings
Mike Frysinger [Thu, 7 Dec 2023 03:08:19 +0000 (20:08 -0700)] 
sim: v850: fix -Wunused-but-set-variable warnings

18 months agosim: sh: fix -Wunused-but-set-variable warnings
Mike Frysinger [Thu, 7 Dec 2023 03:08:13 +0000 (20:08 -0700)] 
sim: sh: fix -Wunused-but-set-variable warnings

18 months agosim: msp430: fix -Wunused-but-set-variable warnings
Mike Frysinger [Thu, 7 Dec 2023 03:08:07 +0000 (20:08 -0700)] 
sim: msp430: fix -Wunused-but-set-variable warnings

18 months agosim: mips: fix -Wunused-but-set-variable warnings
Mike Frysinger [Thu, 7 Dec 2023 03:07:56 +0000 (20:07 -0700)] 
sim: mips: fix -Wunused-but-set-variable warnings

18 months agosim: mcore: fix -Wunused-but-set-variable warnings
Mike Frysinger [Thu, 7 Dec 2023 03:07:50 +0000 (20:07 -0700)] 
sim: mcore: fix -Wunused-but-set-variable warnings

18 months agosim: m68hc11: fix -Wunused-but-set-variable warnings
Mike Frysinger [Thu, 7 Dec 2023 03:07:44 +0000 (20:07 -0700)] 
sim: m68hc11: fix -Wunused-but-set-variable warnings

18 months agosim: h8300: fix -Wunused-but-set-variable warnings
Mike Frysinger [Thu, 7 Dec 2023 03:07:34 +0000 (20:07 -0700)] 
sim: h8300: fix -Wunused-but-set-variable warnings

18 months agosim: ft32: fix -Wunused-but-set-variable warnings
Mike Frysinger [Thu, 7 Dec 2023 03:07:32 +0000 (20:07 -0700)] 
sim: ft32: fix -Wunused-but-set-variable warnings

18 months agosim: frv: fix -Wunused-but-set-variable warnings
Mike Frysinger [Thu, 7 Dec 2023 03:07:22 +0000 (20:07 -0700)] 
sim: frv: fix -Wunused-but-set-variable warnings

18 months agosim: erc32: fix -Wunused-but-set-variable warnings
Mike Frysinger [Thu, 7 Dec 2023 03:07:11 +0000 (20:07 -0700)] 
sim: erc32: fix -Wunused-but-set-variable warnings

18 months agosim: d10v: fix -Wunused-but-set-variable warnings
Mike Frysinger [Thu, 7 Dec 2023 03:07:06 +0000 (20:07 -0700)] 
sim: d10v: fix -Wunused-but-set-variable warnings

18 months agosim: cris: fix -Wunused-but-set-variable warnings
Mike Frysinger [Thu, 7 Dec 2023 03:06:07 +0000 (20:06 -0700)] 
sim: cris: fix -Wunused-but-set-variable warnings

We suppress the warning in the generated switch file because the cris
cpu file has a hack to workaround a cgen bug, but that generates a set
but unused variable which makes the compiler upset.

18 months agosim: bfin: fix -Wunused-but-set-variable warnings
Mike Frysinger [Wed, 6 Dec 2023 13:38:29 +0000 (06:38 -0700)] 
sim: bfin: fix -Wunused-but-set-variable warnings

18 months agosim: bfin: gui: fix -Wunused-but-set-variable warnings
Mike Frysinger [Wed, 6 Dec 2023 13:36:15 +0000 (06:36 -0700)] 
sim: bfin: gui: fix -Wunused-but-set-variable warnings

Rework the code to use static inline functions when it's disabled
rather than macros so the compiler knows the various function args
are always used.  The ifdef macros are a bit ugly, but get the job
done without duplicating the function prototypes.

18 months agosim: arm: fix -Wunused-but-set-variable warnings
Mike Frysinger [Wed, 6 Dec 2023 13:34:44 +0000 (06:34 -0700)] 
sim: arm: fix -Wunused-but-set-variable warnings

18 months agosim: m32r: fix syslog call
Mike Frysinger [Fri, 8 Dec 2023 04:40:00 +0000 (21:40 -0700)] 
sim: m32r: fix syslog call

The function returns void, not int.  We only pass one argument to
syslog (the format), so use %s as the static format instead since
the emulation layer doesn't handle passing additional arguments.

18 months agosim: m32r: include more glibc headers for the funcs we use [PR sim/29752]
Mike Frysinger [Fri, 8 Dec 2023 04:38:56 +0000 (21:38 -0700)] 
sim: m32r: include more glibc headers for the funcs we use [PR sim/29752]

Not exactly portable, but doesn't make the situation worse here, and
fixes a lot of implicit function warnings.

Bug: https://sourceware.org/PR29752

18 months agosim: m32r: add more cgen prototypes for traps
Mike Frysinger [Fri, 8 Dec 2023 04:38:11 +0000 (21:38 -0700)] 
sim: m32r: add more cgen prototypes for traps

The traps file uses a bunch of functions directly without prototypes,
and we can't safely include the relevant cpu*.h files for them.

18 months agoAutomatic date update in version.in
GDB Administrator [Fri, 8 Dec 2023 00:00:18 +0000 (00:00 +0000)] 
Automatic date update in version.in

18 months agosim: m32r: add more cgen prototypes to enable -Werror in most files
Mike Frysinger [Thu, 7 Dec 2023 13:22:32 +0000 (06:22 -0700)] 
sim: m32r: add more cgen prototypes to enable -Werror in most files

18 months agosim: warnings: disable -Wenum-conversion fow now [PR sim/29752]
Mike Frysinger [Thu, 7 Dec 2023 04:16:17 +0000 (21:16 -0700)] 
sim: warnings: disable -Wenum-conversion fow now [PR sim/29752]

The cgen code mixes virtual insn enums with insn enums, and there isn't
an obvious (to me) way to unravel this atm, so disable the warning.

sim/lm32/decode.c:45:5: error:
implicit conversion from enumeration type 'CGEN_INSN_VIRTUAL_TYPE'
to different enumeration type 'CGEN_INSN_TYPE' (aka 'enum cgen_insn_type')
[-Werror,-Wenum-conversion]
   45 |   { VIRTUAL_INSN_X_INVALID, LM32BF_INSN_X_INVALID, LM32BF_SFMT_EMPTY },
      |   ~ ^~~~~~~~~~~~~~~~~~~~~~

Bug: https://sourceware.org/PR29752

18 months agogdb/record: Support for rdtscp in i386_process_record.
Cupertino Miranda [Tue, 5 Dec 2023 23:09:57 +0000 (23:09 +0000)] 
gdb/record: Support for rdtscp in i386_process_record.

This patch adds support for process recording of the instruction rdtscp in
x86 architecture.
Debugging applications with "record full" fail to record with the error
message "Process record does not support instruction 0xf01f9".

Approved-by: Guinevere Larsen <blarsen@redhat.com>
18 months agosim: support dlopen in -lc
Mike Frysinger [Thu, 7 Dec 2023 03:28:40 +0000 (20:28 -0700)] 
sim: support dlopen in -lc

Stop assuming that dlopen is only available via -ldl.  Newer versions
of glibc have merged it into -lc which broke this configure test.

18 months agosim: cris: move generated file to right place
Mike Frysinger [Thu, 7 Dec 2023 02:52:48 +0000 (19:52 -0700)] 
sim: cris: move generated file to right place

Not sure why this ended up in the topdir, but it belongs under cris/.

18 months agosim: warnings: add more flags
Mike Frysinger [Wed, 6 Dec 2023 06:13:50 +0000 (23:13 -0700)] 
sim: warnings: add more flags

Sync with the list of flags from gdbsupport, and add a few more of
our own to catch recent issues.  Comment out the C++-specific flags
as we don't build with C++.

18 months agoAdd more 'step' tests to gdb.base/watchpoint.exp
Kevin Buettner [Thu, 7 Dec 2023 03:08:53 +0000 (20:08 -0700)] 
Add more 'step' tests to gdb.base/watchpoint.exp

The test gdb.base/watchpoint.exp has a proc named 'test_stepping'
which claims to "Test stepping and other mundane operations with
watchpoints enabled".  It sets a watchpoint on ival2, performs an
inferior function call (which is not at all mundane), and uses 'next',
'until', and, finally, does a 'step'.

However, that final 'step' command steps to (but not over/through) the
line at which the assignment to ival2 takes place.  At no time while
performing these operations is a watchpoint hit.

This commit adds a test to see what happens when stepping over/through
the assignment to ival2.  The watchpoint on ival2 should be triggered
during this step.  I've added another 'step' to make sure that the
correct statement is reached after performing the watchpoint-hitting
step.

After running the 'test_stepping' proc, gdb.base/watchpoint.exp does
a clean_restart before doing further tests, so nothing depends upon
'test_stepping' to stop at the particular statement at which it had
been stopping.

I've examined all tests which set watchpoints and step.  I haven't
been able to identify a(nother) test case which tests what happens
when stepping over/through a statement which triggers a watchpoint.
Therefore, adding these new 'step' tests is testing something which
hasn't being tested elsewhere.

Reviewed-By: John Baldwin <jhb@FreeBSD.org>