From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 1551) id 6BC2F3857831; Wed, 4 May 2022 13:44:28 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 6BC2F3857831 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable From: Pedro Alves To: gdb-cvs@sourceware.org Subject: [binutils-gdb] Fix GDBserver Aarch64 Linux regression X-Act-Checkin: binutils-gdb X-Git-Author: Pedro Alves X-Git-Refname: refs/heads/master X-Git-Oldrev: 901e4e8d5c4f1d32c50e4a31b228bc7ef4210775 X-Git-Newrev: 5890af36e5112bcbb8d7555e63570f68466e6944 Message-Id: <20220504134428.6BC2F3857831@sourceware.org> Date: Wed, 4 May 2022 13:44:28 +0000 (GMT) X-BeenThere: gdb-cvs@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gdb-cvs mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 04 May 2022 13:44:28 -0000 https://sourceware.org/git/gitweb.cgi?p=3Dbinutils-gdb.git;h=3D5890af36e511= 2bcbb8d7555e63570f68466e6944 commit 5890af36e5112bcbb8d7555e63570f68466e6944 Author: Pedro Alves Date: Wed May 4 11:09:07 2022 +0100 Fix GDBserver Aarch64 Linux regression =20 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. =20 We started seeing the following internal error for gdb.multi/multi-target-continue.exp for example: =20 Starting program: binutils-gdb/gdb/testsuite/outputs/gdb.multi/multi-t= arget-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_ !=3D nullptr' failed.^M A problem internal to GDB has been detected,^M further debugging may prove unreliable. =20 A backtrace looks like: =20 #0 thread_regcache_data (thread=3Dthread@entry=3D0x0) at ../../../rep= os/binutils-gdb/gdbserver/inferiors.cc:120 #1 0x0000aaaaaaabf0e8 in get_thread_regcache (thread=3D0x0, fetch=3Df= etch@entry=3D0) 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 (thi= s=3D, kind=3D4, size=3D0xffffffffef04) at ../../../repos/bin= utils-gdb/gdbserver/linux-aarch64-low.cc:3226 #4 0x0000aaaaaaabe220 in bp_size (bp=3D0xaaaaaab6f3d0) at ../../../re= pos/binutils-gdb/gdbserver/mem-break.cc:226 #5 check_mem_read (mem_addr=3D187649984471104, buf=3Dbuf@entry=3D0xaa= aaaab625d0 "\006", mem_len=3Dmem_len@entry=3D56) at ../../../repos/binutils= -gdb/gdbserver/mem-break.cc:1862 #6 0x0000aaaaaaacc660 in read_inferior_memory (memaddr=3D, myaddr=3D0xaaaaaab625d0 "\006", len=3D56) at ../../../repos/binutils-g= db/gdbserver/target.cc:93 #7 0x0000aaaaaaac3d9c in gdb_read_memory (len=3D56, myaddr=3D0xaaaaaa= b625d0 "\006", memaddr=3D187649984471104) at ../../../repos/binutils-gdb/gd= bserver/server.cc:1071 #8 gdb_read_memory (memaddr=3D187649984471104, myaddr=3D0xaaaaaab625d= 0 "\006", len=3D56) at ../../../repos/binutils-gdb/gdbserver/server.cc:1048 #9 0x0000aaaaaaac82a4 in process_serial_event () at ../../../repos/bi= nutils-gdb/gdbserver/server.cc:4307 #10 handle_serial_event (err=3D, client_data=3D) at ../../../repos/binutils-gdb/gdbserver/server.cc:4520 #11 0x0000aaaaaaafbcd0 in gdb_wait_for_event (block=3Dblock@entry=3D1)= at ../../../repos/binutils-gdb/gdbsupport/event-loop.cc:700 #12 0x0000aaaaaaafc0b0 in gdb_wait_for_event (block=3D1) at ../../../r= epos/binutils-gdb/gdbsupport/event-loop.cc:596 #13 gdb_do_one_event () at ../../../repos/binutils-gdb/gdbsupport/even= t-loop.cc:237 #14 0x0000aaaaaaacacb0 in start_event_loop () at ../../../repos/binuti= ls-gdb/gdbserver/server.cc:3518 #15 captured_main (argc=3D4, argv=3D) at ../../../repos= /binutils-gdb/gdbserver/server.cc:3998 #16 0x0000aaaaaaab66dc in main (argc=3D, argv=3D) at ../../../repos/binutils-gdb/gdbserver/server.cc:4084 =20 This sequence of functions is invoked due to a series of conditions: =20 1 - The probe-based breakpoint mechanism failed (for some reason) so .= .. =20 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. =20 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. =20 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. =20 This commit fixes it by tweaking is_64bit_tdesc to look at the current process's tdesc instead of the current thread's tdesc. =20 Note that the thread's tdesc is itself filled from the process's tdesc, so this should be equivalent: =20 struct regcache * get_thread_regcache (struct thread_info *thread, int fetch) { struct regcache *regcache; =20 regcache =3D thread_regcache_data (thread); =20 ... if (regcache =3D=3D NULL) { struct process_info *proc =3D get_thread_process (thread); =20 gdb_assert (proc->tdesc !=3D NULL); =20 regcache =3D new_register_cache (proc->tdesc); set_thread_regcache_data (thread, regcache); } ... =20 Change-Id: Ibc809d7345e70a2f058b522bdc5cdbdca97e2cdc Diff: --- gdbserver/linux-aarch64-low.cc | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/gdbserver/linux-aarch64-low.cc b/gdbserver/linux-aarch64-low.cc index c924821c25c..d1e7acb7b4a 100644 --- a/gdbserver/linux-aarch64-low.cc +++ b/gdbserver/linux-aarch64-low.cc @@ -191,9 +191,9 @@ struct arch_process_info static int is_64bit_tdesc (void) { - struct regcache *regcache =3D get_thread_regcache (current_thread, 0); - - return register_size (regcache->tdesc, 0) =3D=3D 8; + /* We may not have a current thread at this point, so go straight to + the process's target description. */ + return register_size (current_process ()->tdesc) =3D=3D 8; } =20 static void