Commit Graph

110009 Commits

Author SHA1 Message Date
Tom de Vries
a1aaf801d5 [gdb/testsuite] Fix gdb.cp/casts.exp with -m32
When running test-case gdb.cp/casts.exp with target board unix/-m32, I run
into:
...
(gdb) print (unsigned long long) &gd == gd_value^M
$31 = false^M
(gdb) FAIL: gdb.cp/casts.exp: print (unsigned long long) &gd == gd_value
...

With some additional printing, we can see in more detail why the comparison
fails:
...
(gdb) print /x &gd^M
$31 = 0xffffc5c8^M
(gdb) PASS: gdb.cp/casts.exp: print /x &gd
print /x (unsigned long long)&gd^M
$32 = 0xffffc5c8^M
(gdb) PASS: gdb.cp/casts.exp: print /x (unsigned long long)&gd
print /x gd_value^M
$33 = 0xffffffffffffc5c8^M
(gdb) PASS: gdb.cp/casts.exp: print /x gd_value
print (unsigned long long) &gd == gd_value^M
$34 = false^M
(gdb) FAIL: gdb.cp/casts.exp: print (unsigned long long) &gd == gd_value
...

The gd_value is set by this assignment:
...
  unsigned long long gd_value = (unsigned long long) &gd;
...

The problem here is directly casting from a pointer to a non-pointer-sized
integer.

Fix this by adding an intermediate cast to std::uintptr_t.

Tested on x86_64-linux with native and target board unix/-m32.
2022-05-08 19:38:13 +02:00
Tom de Vries
603df41b46 [gdb/testsuite] Handle init errors in gdb.mi/user-selected-context-sync.exp
In OBS, on aarch64-linux, with a gdb 11.1 based package, I run into:
...
(gdb) builtin_spawn -pty^M
new-ui mi /dev/pts/5^M
New UI allocated^M
(gdb) =thread-group-added,id="i1"^M
(gdb) ERROR: MI channel failed
warning: Error detected on fd 11^M
thread 1.1^M
Unknown thread 1.1.^M
(gdb) UNRESOLVED: gdb.mi/user-selected-context-sync.exp: mode=non-stop: \
  test_cli_inferior: reset selection to thread 1.1
...
with many more UNRESOLVED following.

The ERROR is a common problem, filed as
https://sourceware.org/bugzilla/show_bug.cgi?id=28561 .

But the many UNRESOLVEDs are due to not checking whether the setup as done in
the test_setup function succeeds or not.

Fix this by:
- making test_setup return an error upon failure
- handling test_setup error at the call site
- adding a "setup done" pass/fail to be turned into an unresolved
  in case of error during setup.

Tested on x86_64-linux, by manually triggering the error in
mi_gdb_start_separate_mi_tty.
2022-05-08 18:32:05 +02:00
Tom de Vries
c7dad3e9f9 [gdb/testsuite] Fix gdb.ada/catch_ex_std.exp with remote-gdbserver-on-localhost
When running test-case gdb.ada/catch_ex_std.exp on target board
remote-gdbserver-on-localhost, I run into:
...
(gdb) continue^M
Continuing.^M
[Inferior 1 (process 15656) exited with code 0177]^M
(gdb) FAIL: gdb.ada/catch_ex_std.exp: runto: run to main
Remote debugging from host ::1, port 49780^M
/home/vries/foo: error while loading shared libraries: libsome_package.so: \
  cannot open shared object file: No such file or directory^M
...

Fix this by adding the usual shared-library + remote-target helper
"gdb_load_shlib $sofile".

Tested on x86_64-linux with native and target board
remote-gdbserver-on-localhost.
2022-05-08 14:05:27 +02:00
Tom de Vries
efd1a8512f [gdb/testsuite] Fix gdb.threads/fork-plus-threads.exp with check-readmore
When running test-case gdb.threads/fork-plus-threads.exp with check-readmore,
I run into:
...
[Inferior 11 (process 7029) exited normally]^M
[Inferior 1 (process 6956) exited normally]^M
FAIL: gdb.threads/fork-plus-threads.exp: detach-on-fork=off: \
  inferior 1 exited (timeout)
...

The problem is that the regexp consuming the "Inferior exited normally"
messages:
- consumes more than one of those messages at a time, but
- counts only one of those messages.

Fix this by adopting a line-by-line approach, which deals with those messages
one at a time.

Tested on x86_64-linux with native, check-read1 and check-readmore.
2022-05-08 13:53:41 +02:00
GDB Administrator
07d9774171 Automatic date update in version.in 2022-05-08 00:00:21 +00:00
Tom Tromey
c5eab52dba Fix "catch syscall"
Simon pointed out that some recent patches of mine broke "catch
syscall".  Apparently I forgot to finish the conversion of this code
when removing init_catchpoint.  This patch completes the conversion
and fixes the bug.
2022-05-07 10:07:36 -06:00
Andrew Burgess
8f3babfaf8 gdb/readline: fix extra 'quit' message problem
After these two commits:

  commit 4fb7bc4b14
  Date:   Mon Mar 7 13:49:21 2022 +0000

      readline: back-port changes needed to properly detect EOF

  commit 91395d97d9
  Date:   Tue Feb 15 17:28:03 2022 +0000

      gdb: handle bracketed-paste-mode and EOF correctly

It was observed that, if a previous command is selected at the
readline prompt using the up arrow key, then when the command is
accepted (by pressing return) an unexpected 'quit' message will be
printed by GDB.  Here's an example session:

  (gdb) p 123
  $1 = 123
  (gdb) p 123
  quit
  $2 = 123
  (gdb)

In this session the second 'p 123' was entered not by typing 'p 123',
but by pressing the up arrow key to select the previous command.  It
is important that the up arrow key is used, typing Ctrl-p will not
trigger the bug.

The problem here appears to be readline's EOF detection when handling
multi-character input sequences.  I have raised this issue on the
readline mailing list here:

  https://lists.gnu.org/archive/html/bug-readline/2022-04/msg00012.html

a solution has been proposed here:

  https://lists.gnu.org/archive/html/bug-readline/2022-04/msg00016.html

This patch includes a test for this issue as well as a back-port of
(the important bits of) readline commit:

  commit 2ef9cec8c48ab1ae3a16b1874a49bd1f58eaaca1
  Date:   Wed May 4 11:18:04 2022 -0400

      fix for setting RL_STATE_EOF in callback mode

That commit also includes some updates to the readline documentation
and tests that I have not included in this commit.

With this commit in place the unexpected 'quit' messages are resolved.
2022-05-07 10:49:27 +01:00
Alan Modra
69464d2267 Fix multiple ubsan warnings in i386-dis.c
Commit 39fb369834 "opcodes: Make i386-dis.c thread-safe" introduced
a number of casts to bfd_signed_vma that cause undefined behaviour
with a 32-bit libbfd.  Revert those changes.

	* i386-dis.c (OP_E_memory): Do not cast disp to bfd_signed_vma
	for negation.
	(get32, get32s): Don't use bfd_signed_vma here.
2022-05-07 17:32:25 +09:30
Alan Modra
5a91f93b98 Re: Fix new linker testsuite failures due to rwx segment test problems
Fix it some more.

bfd/
	* elfnn-loongarch.c: Remove commented out elf_backend_* defines.
ld/
	* testsuite/ld-elf/elf.exp (target_defaults_to_execstack): Match
	arm*.  Delete loongarch.
2022-05-07 15:15:20 +09:30
GDB Administrator
29b5074f3a Automatic date update in version.in 2022-05-07 00:00:18 +00:00
Carl Love
29004660c9 PowerPC fix for gdb.server/sysroot.exp
On PowerPC, the stop in the printf function is of the form:

Breakpoint 2, 0x00007ffff7c6ab08 in printf@@GLIBC_2.17 () from /lib64/libc.so.6

On other architectures the output looks like:

Breakpoint 2, 0x0000007fb7ea29ac in printf () from /lib/aarch64-linux-gnu/libc.so.6

The following patch modifies the printf test by matchine any character
starting immediately after the printf.  The test now works for PowerPC
output as well as the output from other architectures.

The test has been run on a Power 10 system and and Intel x86_64 system.
2022-05-06 23:08:39 +00:00
Nick Clifton
d11c7afad3 Fix new linker testsuite failures due to rwx segment test problems 2022-05-06 20:30:06 +01:00
Tom Tromey
fed1c982de Introduce catchpoint class
This introduces a catchpoint class that is used as the base class for
all catchpoints.  init_catchpoint is rewritten to be a constructor
instead.

This changes the hierarchy a little -- some catchpoints now inherit
from base_breakpoint whereas previously they did not.  This isn't a
problem, as long as re_set is redefined in catchpoint.
2022-05-06 12:03:35 -06:00
Tom Tromey
b68f26dea7 Add initializers to tracepoint
This adds some initializers to tracepoint.  I think right now these
may not be needed, due to obscure rules about zero initialization.
However, this will change in the next patch, and anyway it is clearer
to be explicit.
2022-05-06 12:03:35 -06:00
Tom Tromey
73063f5180 Remove init_raw_breakpoint_without_location
This removes init_raw_breakpoint_without_location, replacing it with a
constructor on 'breakpoint' itself.  The subclasses and callers are
all updated.
2022-05-06 12:03:35 -06:00
Tom Tromey
3101e4a1c5 Disable copying for breakpoint
It seems to me that breakpoint should use DISABLE_COPY_AND_ASSIGN.
This patch does this.
2022-05-06 12:03:35 -06:00
Tom Tromey
1ae43feabb Add constructor to exception_catchpoint
This adds a constructor to exception_catchpoint and simplifies the
caller.
2022-05-06 12:03:35 -06:00
Tom Tromey
6c91c7de20 Add constructor to syscall_catchpoint
This adds a constructor to syscall_catchpoint and simplifies the
caller.
2022-05-06 12:03:34 -06:00
Tom Tromey
e02f53e50e Add constructor to signal_catchpoint
This adds a constructor to signal_catchpoint and simplifies the
caller.
2022-05-06 12:03:34 -06:00
Tom Tromey
4874f776ca Add constructor to solib_catchpoint
This adds a constructor to solib_catchpoint and simplifies the caller.
2022-05-06 12:03:34 -06:00
Tom Tromey
ec79815480 Add constructor to fork_catchpoint
This adds a constructor to fork_catchpoint and simplifies the caller.
2022-05-06 12:03:34 -06:00
Tom Tromey
fb9e637013 Remove unnecessary line from catch_exec_command_1
catch_exec_command_1 clears the new catchpoint's "exec_pathname"
field, but this is already done by virtue of calling "new".
2022-05-06 12:03:34 -06:00
Tom Tromey
4d1ae55893 Constify breakpoint::print_recreate
This constifies breakpoint::print_recreate.
2022-05-06 12:03:34 -06:00
Tom Tromey
b713485d66 Constify breakpoint::print_mention
This constifies breakpoint::print_mention.
2022-05-06 12:03:34 -06:00
Tom Tromey
a67bcaba1c Constify breakpoint::print_one
This constifies breakpoint::print_one.
2022-05-06 12:03:34 -06:00
Tom Tromey
7bd8631327 Constify breakpoint::print_it
This constifies breakpoint::print_it.  Doing this pointed out some
code in ada-lang.c that can be simplified a little as well.
2022-05-06 12:03:34 -06:00
Tom Tromey
5a61e17687 Move works_in_software_mode to watchpoint
works_in_software_mode is only useful for watchpoints.  This patch
moves it from breakpoint to watchpoint, and changes it to return bool.
2022-05-06 12:03:34 -06:00
Tom Tromey
a6860f3ad2 Boolify breakpoint::explains_signal
This changes breakpoint::explains_signal to return bool.
2022-05-06 12:03:34 -06:00
Tom Tromey
9efa3c7fa3 Remove breakpoint::ops
The breakpoint::ops field is set but never used.  This removes it.
2022-05-06 12:03:34 -06:00
Tom Tromey
04d0163c3f Change print_recreate_thread to a method
This changes print_recreate_thread to be a method on breakpoint.  This
function is only used as a helper by print_recreate methods, so I
thought this transformation made sense.
2022-05-06 12:03:34 -06:00
Carl Love
dd9cd55e99 PowerPC: bp-permanent.exp, kill-after-signal fix
The break point after the stepi on Intel is the entry point of the user
signal handler function test_signal_handler.  The code at the break point
looks like:

     0x<hex address> <test_signal_handler>: endbr64

On PowerPC with a Linux 5.9 kernel or latter, the address where gdb stops
after the stepi is in the vdso code inserted by the kernel.  The code at the
breakpoint looks like:

  0x<hex address>  <__kernel_start_sigtramp_rt64>:	bctrl

This is different from other architectures.  As discussed below, recent
kernel changes involving the vdso for PowerPC have been made changes to the
signal handler code flow.  PowerPC is now stopping in function
__kernel_start_sigtramp_rt64.  PowerPC now requires an additional stepi to
reach the user signal handler unlike other architectures.

The bp-permanent.exp and kill-after-signal tests run fine on PowerPC with an
kernel that is older than Linux 5.9.

The PowerPC 64 signal handler was updated by the Linux kernel 5.9-rc1:

    commit id: 0138ba5783ae0dcc799ad401a1e8ac8333790df9
    powerpc/64/signal: Balance return predictor stack in signal trampoline

An additional change to the PowerPC 64 signal handler was made in Linux
kernel version 5.11-rc7 :

     commit id: 24321ac668e452a4942598533d267805f291fdc9
     powerpc/64/signal: Fix regression in __kernel_sigtramp_rt64() semantics

The first kernel change, puts code into the user space signal handler (in
the vdso) as a performance optimization to prevent the call/return stack
from getting out of balance.  The patch ensures that the entire
user/kernel/vdso cycle is balanced with the addition of the "brctl"
instruction.

The second patch, fixes the semantics of __kernel_sigtramp_rt64().  A new
symbol is introduced to serve as the jump target from the kernel to the
trampoline which now consists of two parts.

The above changes for PowerPC signal handler, causes gdb to stop in the
kernel code not the user signal handler as expected.  The kernel dispatches
to the vdso code which in turn calls into the signal handler.  PowerPC is
special in that the kernel is using a vdso instruction (bctrl) to enter the
signal handler.

I do not have access to a system with the first patch but not the second.  I did
test on Power 9 with the Linux 5.15.0-27-generic kernel.  Both tests fail on
this Power 9 system.  The two tests also fail on Power 10 with the Linux
5.14.0-70.9.1.el9_0.ppc64le kernel.

The following patch fixes the issue by checking if gdb stopped at "signal
handler called".  If gdb stopped there, the tests verifies gdb is in the kernel
function __kernel_start_sigtramp_rt64 then does an additional stepi to reach the
user signal handler.  With the patch below, the tests run without errors on both
the Power 9 and Power 10 systems with out any failures.
2022-05-06 17:45:58 +00:00
Alan Modra
0ee8858e7a bfd targmatch.h makefile rule
I hit this just now with a make -j build after touching config.bfd.
mv: cannot stat 'targmatch.new': No such file or directory
make[2]: *** [Makefile:2336: targmatch.h] Error 1
make[2]: *** Waiting for unfinished jobs....

Fix that by not removing the target of the rule, a practice that seems
likely to cause parallel running of the rule recipe.  The bug goes
back to 1997, the initial c073470881 commit.

	* Makefile.am (targmatch.h): rm the temp file, not targmatch.h.
	* Makefile.in: Regenerate.
2022-05-06 13:21:26 +09:30
Tom de Vries
2899c914f4 [gdb/testsuite] Fix gdb.dwarf2/locexpr-data-member-location.exp with nopie
When running test-case gdb.dwarf2/locexpr-data-member-location.exp with
target board unix/-fno-PIE/-no-pie/-m32 I run into:
...
(gdb) step^M
26        return 0;^M
(gdb) FAIL: gdb.dwarf2/locexpr-data-member-location.exp: step into foo
...

The problem is that the test-case tries to mimic some gdb_compile_shlib
behaviour using:
...
set flags {additional_flags=-fpic debug}
get_func_info foo $flags
...
but this doesn't work with the target board setting, because we end up doing:
...
gcc locexpr-data-member-location-lib.c -fpic -g -lm -fno-PIE -no-pie -m32 \
  -o func_addr23029.x
...
while gdb_compile_shlib properly filters out the -fno-PIE -no-pie.

Consequently, the address for foo determined by get_func_info doesn't match
the actual address of foo.

Fix this by printing the address of foo using the result of gdb_compile_shlib.
2022-05-06 04:51:43 +02:00
GDB Administrator
2392dc0f8e Automatic date update in version.in 2022-05-06 00:00:21 +00:00
Simon Marchi
6e9cd73eb5 gdb: use gdb::function_view for gdbarch_iterate_over_objfiles_in_search_order callback
A rather straightforward patch to change an instance of callback +
void pointer to gdb::function_view, allowing pasing lambdas that
capture, and eliminating the need for the untyped pointer.

Change-Id: I73ed644e7849945265a2c763f79f5456695b0037
2022-05-05 15:27:26 -04:00
Vladimir Mezentsev
1653ae5b84 gprofng: use $host instead $target
By mistake, $target was used instead of $host to configure the gprogng build.

gprofng/ChangeLog
2022-04-28  Vladimir Mezentsev  <vladimir.mezentsev@oracle.com>

	PR gprofng/29113
	PR gprofng/29116
	* configure.ac: Use $host instead $target.
	* libcollector/configure.ac: Likewise.
	* configure: Rebuild.
	* libcollector/configure: Rebuild.
2022-05-05 10:12:12 -07:00
Simon Marchi
d890c720b8 gdb: make regcache's cooked_write_test selftest work with 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
2022-05-05 10:09:22 -04:00
Luis Machado
8e1ada9e0b Move TILE-Gx files to TARGET64_LIBOPCODES_CFILES
TILE-Gx is a 64-bit core, so we should include those files in the
TARGET64_LIBOPCODES_CFILES as opposed to TARGET32_LIBOPCODES_CFILES.
2022-05-05 10:03:39 +01:00
Luis Machado
e4e883c09b Don't define ARCH_cris for BFD64
I believe it is a mistake to define ARCH_cris when BFD64 is defined. It is
a 32-bit architecture, so should be placed outside of the BFD64 block.
2022-05-05 09:59:45 +01:00
Xi Ruoyao
83c5f3aea9 loongarch: Don't check ABI flags if no code section
Various packages (glib and gtk4 for example) produces data-only objects
using `ld -r -b binary` or `objcopy`, with no elf header flags set.  But
these files also have no code sections, so they should be compatible
with all ABIs.

bfd/
	* elfnn-loongarch.c (elfNN_loongarch_merge_private_bfd_data):
	Skip ABI checks if the input has no code sections.

Reported-by: Wu Xiaotian <yetist@gmail.com>
Suggested-by: Wang Xuerui <i@xen0n.name>
Signed-off-by: Xi Ruoyao <xry111@mengyan1223.wang>
2022-05-05 16:00:34 +08:00
Andreas Krebbel
c54a62119a IBM zSystems: mgrk, mg first operand requires register pair
opcodes/

	* s390-opc.c (INSTR_RRF_R0RER): New instruction type.
	(MASK_RRF_R0RER): Define mask for new instruction type.
	* s390-opc.txt: Use RRF_R0RER for mgrk and RXY_RERRD for mg.
2022-05-05 07:57:13 +02:00
H.J. Lu
18e60f7c8a bfd: Check NULL pointer before setting ref_real
PR ld/29086
	* linker.c (bfd_wrapped_link_hash_lookup): Check NULL pointer
	before setting ref_real.
2022-05-04 17:57:58 -07:00
GDB Administrator
4a947dc62f Automatic date update in version.in 2022-05-05 00:00:07 +00:00
H.J. Lu
da422fa49d LTO: Handle __real_SYM reference in IR
When an IR symbol SYM is referenced in IR via __real_SYM, its resolution
should be LDPR_PREVAILING_DEF, not PREVAILING_DEF_IRONLY, since LTO
doesn't know that __real_SYM should be resolved by SYM.

bfd/

	PR ld/29086
	* linker.c (bfd_wrapped_link_hash_lookup): Mark SYM is referenced
	via __real_SYM.

include/

	PR ld/29086
	* bfdlink.h (bfd_link_hash_entry): Add ref_real.

ld/

	PR ld/29086
	* plugin.c (get_symbols): Resolve SYM definition to
	LDPR_PREVAILING_DEF for __real_SYM reference.
	* testsuite/ld-plugin/lto.exp: Run PR ld/29086 test.
	* testsuite/ld-plugin/pr29086.c: New file.
2022-05-04 16:26:51 -07:00
Alan Modra
40ae4abe44 cris bfd config
cris support will be built into a 32-bit bfd if using --enable-targets=all
on a 32-bit host, so we may as well make targmatch.h include cris.

	* config.bfd (cris): Remove #idef BFD64.
2022-05-05 08:00:14 +09:30
Alan Modra
c99d782d9c PowerPC64 check_relocs
Tidy the dynamic reloc handling code in check_relocs, removing
leftover comments and code from when check_relocs was called as each
object file was read in.

	* elf64-ppc.c (ppc64_elf_check_relocs): Tidy dynamic reloc
	handling code.
	(dec_dynrel_count): Do the same here.
2022-05-05 08:00:10 +09:30
Tom Tromey
758ffab46b Fix crash when creating index from index
My patches yesterday to unify the DWARF index base classes had a bug
-- namely, I did the wholesale dynamic_cast-to-static_cast too hastily
and introduced a crash.  This can be seen by trying to add an index to
a file that has an index, or by running a test like gdb-index-cxx.exp
using the cc-with-debug-names.exp target board.

This patch fixes the crash by introducing a new virtual method and
removing some of the static casts.
2022-05-04 08:38:05 -06:00
Luis Machado
d8a7353308 Fix build failure for aarch64 gdbserver
We're missing an argument.
2022-05-04 15:36:47 +01:00
Mark Wielaard
716e54731f gdb: Workaround stringop-overread warning in debuginfod-support.c on s390x
For some reason g++ 11.2.1 on s390x produces a spurious warning for
stringop-overread in debuginfod_is_enabled for url_view. Add a new
DIAGNOSTIC_IGNORE_STRINGOP_OVERREAD macro to suppress this warning.

include/ChangeLog:

	* diagnostics.h (DIAGNOSTIC_IGNORE_STRINGOP_OVERREAD): New
	macro.

gdb/ChangeLog:

	* debuginfod-support.c (debuginfod_is_enabled): Use
	DIAGNOSTIC_IGNORE_STRINGOP_OVERREAD on s390x.
2022-05-04 16:07:59 +02:00
Pedro Alves
5890af36e5 Fix GDBserver Aarch64 Linux regression
Luis noticed that the recent changes to gdbserver to make it track
process and threads independently regressed a few gdb.multi/*.exp
tests for aarch64-linux.

We started seeing the following internal error for
gdb.multi/multi-target-continue.exp for example:

 Starting program: binutils-gdb/gdb/testsuite/outputs/gdb.multi/multi-target-continue/multi-target-continue ^M
 Error in re-setting breakpoint 2: Remote connection closed^M
 ../../../repos/binutils-gdb/gdb/thread.c:85: internal-error: inferior_thread: Assertion `current_thread_ != nullptr' failed.^M
 A problem internal to GDB has been detected,^M
 further debugging may prove unreliable.

A backtrace looks like:

 #0  thread_regcache_data (thread=thread@entry=0x0) at ../../../repos/binutils-gdb/gdbserver/inferiors.cc:120
 #1  0x0000aaaaaaabf0e8 in get_thread_regcache (thread=0x0, fetch=fetch@entry=0) at ../../../repos/binutils-gdb/gdbserver/regcache.cc:31
 #2  0x0000aaaaaaad785c in is_64bit_tdesc () at ../../../repos/binutils-gdb/gdbserver/linux-aarch64-low.cc:194
 #3  0x0000aaaaaaad8a48 in aarch64_target::sw_breakpoint_from_kind (this=<optimized out>, kind=4, size=0xffffffffef04) at ../../../repos/binutils-gdb/gdbserver/linux-aarch64-low.cc:3226
 #4  0x0000aaaaaaabe220 in bp_size (bp=0xaaaaaab6f3d0) at ../../../repos/binutils-gdb/gdbserver/mem-break.cc:226
 #5  check_mem_read (mem_addr=187649984471104, buf=buf@entry=0xaaaaaab625d0 "\006", mem_len=mem_len@entry=56) at ../../../repos/binutils-gdb/gdbserver/mem-break.cc:1862
 #6  0x0000aaaaaaacc660 in read_inferior_memory (memaddr=<optimized out>, myaddr=0xaaaaaab625d0 "\006", len=56) at ../../../repos/binutils-gdb/gdbserver/target.cc:93
 #7  0x0000aaaaaaac3d9c in gdb_read_memory (len=56, myaddr=0xaaaaaab625d0 "\006", memaddr=187649984471104) at ../../../repos/binutils-gdb/gdbserver/server.cc:1071
 #8  gdb_read_memory (memaddr=187649984471104, myaddr=0xaaaaaab625d0 "\006", len=56) at ../../../repos/binutils-gdb/gdbserver/server.cc:1048
 #9  0x0000aaaaaaac82a4 in process_serial_event () at ../../../repos/binutils-gdb/gdbserver/server.cc:4307
 #10 handle_serial_event (err=<optimized out>, client_data=<optimized out>) at ../../../repos/binutils-gdb/gdbserver/server.cc:4520
 #11 0x0000aaaaaaafbcd0 in gdb_wait_for_event (block=block@entry=1) at ../../../repos/binutils-gdb/gdbsupport/event-loop.cc:700
 #12 0x0000aaaaaaafc0b0 in gdb_wait_for_event (block=1) at ../../../repos/binutils-gdb/gdbsupport/event-loop.cc:596
 #13 gdb_do_one_event () at ../../../repos/binutils-gdb/gdbsupport/event-loop.cc:237
 #14 0x0000aaaaaaacacb0 in start_event_loop () at ../../../repos/binutils-gdb/gdbserver/server.cc:3518
 #15 captured_main (argc=4, argv=<optimized out>) at ../../../repos/binutils-gdb/gdbserver/server.cc:3998
 #16 0x0000aaaaaaab66dc in main (argc=<optimized out>, argv=<optimized out>) at ../../../repos/binutils-gdb/gdbserver/server.cc:4084

This sequence of functions is invoked due to a series of conditions:

 1 - The probe-based breakpoint mechanism failed (for some reason) so ...

 2 - ... gdbserver has to know what type of architecture it is dealing
     with so it can pick the right breakpoint kind, so it wants to
     check if we have a 64-bit target.

 3 - To determine the size of a register, we currently fetch the
     current thread's register cache, and the current thread pointer
     is now nullptr.

In #3, the current thread is nullptr because gdb_read_memory clears it
on purpose, via set_desired_process, exactly to expose code relying on
the current thread when it shouldn't.  It was always possible to end
up in this situation (when the current thread exits), but it was
harder to reproduce before.

This commit fixes it by tweaking is_64bit_tdesc to look at the current
process's tdesc instead of the current thread's tdesc.

Note that the thread's tdesc is itself filled from the process's
tdesc, so this should be equivalent:

 struct regcache *
 get_thread_regcache (struct thread_info *thread, int fetch)
 {
   struct regcache *regcache;

   regcache = thread_regcache_data (thread);

 ...
   if (regcache == NULL)
     {
       struct process_info *proc = get_thread_process (thread);

       gdb_assert (proc->tdesc != NULL);

       regcache = new_register_cache (proc->tdesc);
       set_thread_regcache_data (thread, regcache);
     }
 ...

Change-Id: Ibc809d7345e70a2f058b522bdc5cdbdca97e2cdc
2022-05-04 14:42:58 +01:00