public inbox for gdb-prs@sourceware.org
help / color / mirror / Atom feed
* [Bug gdb/27899] New: [GNU/Linux, sparc64] GDB crashes when debugging multithreaded programs
@ 2021-05-22 17:22 koachan+sourceware at protonmail dot com
  2021-05-22 17:23 ` [Bug gdb/27899] " koachan+sourceware at protonmail dot com
                   ` (9 more replies)
  0 siblings, 10 replies; 11+ messages in thread
From: koachan+sourceware at protonmail dot com @ 2021-05-22 17:22 UTC (permalink / raw)
  To: gdb-prs

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

            Bug ID: 27899
           Summary: [GNU/Linux, sparc64] GDB crashes when debugging
                    multithreaded programs
           Product: gdb
           Version: HEAD
            Status: UNCONFIRMED
          Severity: normal
          Priority: P2
         Component: gdb
          Assignee: unassigned at sourceware dot org
          Reporter: koachan+sourceware at protonmail dot com
  Target Milestone: ---

Created attachment 13465
  --> https://sourceware.org/bugzilla/attachment.cgi?id=13465&action=edit
Test code to trigger the behavior

On sparc64, GDB 10.2 crashes with the following message when debugging
multithreaded programs:
thread.c:1309: internal-error: void switch_to_thread(thread_info*): Assertion
`thr != NULL' failed.

Steps to reproduce:

- Compile the attached source with `gcc -g3 -o threaded-hello threaded-hello.c
-lpthread -static` on a sparc64 machine.
- Load the file

Expected result (from GDB 9.2 and 10.1):

$ gdb threaded-hello
[... snipped ...]
Reading symbols from threaded-hello...
(gdb) break thread
Breakpoint 1 at 0x100984: file threaded-hello.c, line 18.
(gdb) run
Starting program: /home/k/threaded-hello 
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib64/libthread_db.so.1".
Hello World from the main thread!
[New Thread 0xffff800100805870 (LWP 46440)]
[Switching to Thread 0xffff800100805870 (LWP 46440)]

Thread 2 "threaded-hello" hit Breakpoint 1, thread (
    vargp=<error reading variable: Cannot access memory at address 0x87f>) at
threaded-hello.c:18
18          printf("Hello World from a thread created by the main thread!\n");
(gdb)

Actual result (from GDB 10.2):

$ gdb threaded-hello
[... snipped ...]
Reading symbols from threaded-hello...
(gdb) break thread
Breakpoint 1 at 0x100984: file threaded-hello.c, line 18.
(gdb) run
Starting program: /home/k/threaded-hello 
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib64/libthread_db.so.1".
Hello World from the main thread!
thread.c:1309: internal-error: void switch_to_thread(thread_info*): Assertion
`thr != NULL' failed.
A problem internal to GDB has been detected,
further debugging may prove unreliable.
Quit this debugging session? (y or n) 

I've attached the source and the compiled binary (built with GCC 9.3.0).

-- 
You are receiving this mail because:
You are on the CC list for the bug.

^ permalink raw reply	[flat|nested] 11+ messages in thread

* [Bug gdb/27899] [GNU/Linux, sparc64] GDB crashes when debugging multithreaded programs
  2021-05-22 17:22 [Bug gdb/27899] New: [GNU/Linux, sparc64] GDB crashes when debugging multithreaded programs koachan+sourceware at protonmail dot com
@ 2021-05-22 17:23 ` koachan+sourceware at protonmail dot com
  2021-05-23 11:54 ` simark at simark dot ca
                   ` (8 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: koachan+sourceware at protonmail dot com @ 2021-05-22 17:23 UTC (permalink / raw)
  To: gdb-prs

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

--- Comment #1 from Koakuma <koachan+sourceware at protonmail dot com> ---
Created attachment 13466
  --> https://sourceware.org/bugzilla/attachment.cgi?id=13466&action=edit
Statically-compiled binary of the test case, made with GCC 9.3.0

-- 
You are receiving this mail because:
You are on the CC list for the bug.

^ permalink raw reply	[flat|nested] 11+ messages in thread

* [Bug gdb/27899] [GNU/Linux, sparc64] GDB crashes when debugging multithreaded programs
  2021-05-22 17:22 [Bug gdb/27899] New: [GNU/Linux, sparc64] GDB crashes when debugging multithreaded programs koachan+sourceware at protonmail dot com
  2021-05-22 17:23 ` [Bug gdb/27899] " koachan+sourceware at protonmail dot com
@ 2021-05-23 11:54 ` simark at simark dot ca
  2021-05-23 11:54 ` simark at simark dot ca
                   ` (7 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: simark at simark dot ca @ 2021-05-23 11:54 UTC (permalink / raw)
  To: gdb-prs

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

Simon Marchi <simark at simark dot ca> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |simark at simark dot ca

--- Comment #2 from Simon Marchi <simark at simark dot ca> ---
I can confirm.  Backtrace is:

#0  0xffff8001017dc004 in __GI___poll (fds=0x100012cf730, nfds=4,
timeout=<optimized out>) at ../sysdeps/unix/sysv/linux/poll.c:29
#1  0x0000010000abb004 in gdb_wait_for_event (block=1) at
/home/simark/src/binutils-gdb/gdbsupport/event-loop.cc:613
#2  0x0000010000ab9bbc in gdb_do_one_event () at
/home/simark/src/binutils-gdb/gdbsupport/event-loop.cc:237
#3  0x0000010000834d70 in gdb_readline_wrapper (prompt=0x100012cf620
"/home/simark/src/binutils-gdb/gdb/thread.c:1346: internal-error: void
switch_to_thread(thread_info*): Assertion `thr != NULL' failed.\nA problem
internal to GDB has been detected,\nfurther debugging may"...) at
/home/simark/src/binutils-gdb/gdb/top.c:1110
#4  0x00000100008eac48 in defaulted_query (ctlstr=0x10000c29670 "%s\nQuit this
debugging session? ", defchar=0 '\000', args=0x7feff97cad8) at
/home/simark/src/binutils-gdb/gdb/utils.c:893
#5  0x00000100008eb010 in query (ctlstr=0x10000c29670 "%s\nQuit this debugging
session? ") at /home/simark/src/binutils-gdb/gdb/utils.c:985
#6  0x00000100008e95dc in internal_vproblem (problem=0x10000f8b2d0
<internal_error_problem>, file=0x10000bfca20
"/home/simark/src/binutils-gdb/gdb/thread.c", line=1346, fmt=0x10000bfc918 "%s:
Assertion `%s' failed.", ap=0x7feff97cd78) at
/home/simark/src/binutils-gdb/gdb/utils.c:373
#7  0x00000100008e9a68 in internal_verror (file=0x10000bfca20
"/home/simark/src/binutils-gdb/gdb/thread.c", line=1346, fmt=0x10000bfc918 "%s:
Assertion `%s' failed.", ap=0x7feff97cd78) at
/home/simark/src/binutils-gdb/gdb/utils.c:439
#8  0x0000010000ab9968 in internal_error (file=0x10000bfca20
"/home/simark/src/binutils-gdb/gdb/thread.c", line=1346, fmt=0x10000bfc918 "%s:
Assertion `%s' failed.") at
/home/simark/src/binutils-gdb/gdbsupport/errors.cc:55
#9  0x0000010000827f3c in switch_to_thread (thr=0x0) at
/home/simark/src/binutils-gdb/gdb/thread.c:1346
#10 0x0000010000753444 in sparc_fetch_inferior_registers
(proc_target=0x10000fa8cb0 <the_sparc64_linux_nat_target>,
regcache=0x10000ff03c0, regnum=-1) at
/home/simark/src/binutils-gdb/gdb/sparc-nat.c:175
#11 0x000001000075b908 in sparc64_linux_nat_target::fetch_registers
(this=0x10000fa8cb0 <the_sparc64_linux_nat_target>, regcache=0x10000ff03c0,
regnum=-1) at /home/simark/src/binutils-gdb/gdb/sparc64-linux-nat.c:38
#12 0x00000100007fe6f4 in target_ops::fetch_registers (this=0x10000f7feb0
<the_thread_db_target>, arg0=0x10000ff03c0, arg1=-1) at
/home/simark/src/binutils-gdb/gdb/target-delegates.c:496
#13 0x00000100008162a0 in target_fetch_registers (regcache=0x10000ff03c0,
regno=-1) at /home/simark/src/binutils-gdb/gdb/target.c:3287
#14 0x000001000060a4bc in ps_lgetregs (ph=0x10001264368, lwpid=458727,
gregset=0x7feff97d388) at /home/simark/src/binutils-gdb/gdb/proc-service.c:158
#15 0xffff800103e32420 in __td_ta_lookup_th_unique (ta_arg=0x100012d7080,
lwpid=<optimized out>, th=0x7feff97d7c8) at td_ta_map_lwp2thr.c:119
#16 0xffff800103e32604 in td_ta_map_lwp2thr (ta_arg=0x100012d7080,
lwpid=<optimized out>, th=0x7feff97d7c8) at td_ta_map_lwp2thr.c:207
#17 0x000001000051fee8 in thread_from_lwp (stopped=0x100011a3650, ptid=...) at
/home/simark/src/binutils-gdb/gdb/linux-thread-db.c:415
#18 0x0000010000520150 in thread_db_notice_clone (parent=..., child=...) at
/home/simark/src/binutils-gdb/gdb/linux-thread-db.c:446
#19 0x00000100005068a8 in linux_handle_extended_wait (lp=0x10001230700,
status=4479) at /home/simark/src/binutils-gdb/gdb/linux-nat.c:1978
#20 0x000001000050a278 in linux_nat_filter_event (lwpid=458724, status=198015)
at /home/simark/src/binutils-gdb/gdb/linux-nat.c:2913
#21 0x000001000050b818 in linux_nat_wait_1 (ptid=..., ourstatus=0x7feff97e8d0,
target_options=...) at /home/simark/src/binutils-gdb/gdb/linux-nat.c:3194
#22 0x000001000050ca4c in linux_nat_target::wait (this=0x10000fa8cb0
<the_sparc64_linux_nat_target>, ptid=..., ourstatus=0x7feff97e8d0,
target_options=...) at /home/simark/src/binutils-gdb/gdb/linux-nat.c:3432
#23 0x00000100005237ec in thread_db_target::wait (this=0x10000f7feb0
<the_thread_db_target>, ptid=..., ourstatus=0x7feff97e8d0, options=...) at
/home/simark/src/binutils-gdb/gdb/linux-thread-db.c:1379
#24 0x00000100007fa668 in target_wait (ptid=..., status=0x7feff97e8d0,
options=...) at /home/simark/src/binutils-gdb/gdb/target.c:2000
#25 0x00000100004adb0c in do_target_wait_1 (inf=0x10001173170, ptid=...,
status=0x7feff97e8d0, options=...) at
/home/simark/src/binutils-gdb/gdb/infrun.c:3464
#26 0x00000100004add48 in operator() (__closure=0x7feff97e658,
inf=0x10001173170) at /home/simark/src/binutils-gdb/gdb/infrun.c:3527
#27 0x00000100004ae15c in do_target_wait (wait_ptid=..., ecs=0x7feff97e8a8,
options=...) at /home/simark/src/binutils-gdb/gdb/infrun.c:3540
#28 0x00000100004af254 in fetch_inferior_event () at
/home/simark/src/binutils-gdb/gdb/infrun.c:3880
#29 0x0000010000486ef8 in inferior_event_handler (event_type=INF_REG_EVENT) at
/home/simark/src/binutils-gdb/gdb/inf-loop.c:42
#30 0x000001000050ec10 in handle_target_event (error=0, client_data=0x0) at
/home/simark/src/binutils-gdb/gdb/linux-nat.c:4060
#31 0x0000010000abaed4 in handle_file_event (file_ptr=0x10001259500,
ready_mask=1) at /home/simark/src/binutils-gdb/gdbsupport/event-loop.cc:575
#32 0x0000010000abb57c in gdb_wait_for_event (block=0) at
/home/simark/src/binutils-gdb/gdbsupport/event-loop.cc:701
#33 0x0000010000ab9ac4 in gdb_do_one_event () at
/home/simark/src/binutils-gdb/gdbsupport/event-loop.cc:212
#34 0x0000010000543ee0 in start_event_loop () at
/home/simark/src/binutils-gdb/gdb/main.c:348
#35 0x00000100005440f4 in captured_command_loop () at
/home/simark/src/binutils-gdb/gdb/main.c:408
#36 0x00000100005466fc in captured_main (data=0x7feff97f168) at
/home/simark/src/binutils-gdb/gdb/main.c:1242
#37 0x00000100005467a4 in gdb_main (args=0x7feff97f168) at
/home/simark/src/binutils-gdb/gdb/main.c:1257
#38 0x00000100000c20f4 in main (argc=6, argv=0x7feff97f528) at
/home/simark/src/binutils-gdb/gdb/gdb.c:32

This is cause by my commit here:

    gdb: set current thread in sparc_{fetch,collect}_inferior_registers (PR
gdb/27147)
   
https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=d1e93af64a6b74921cca9bca8a7043855f9da10d

That commit made sparc_{fetch,collect}_inferior_registers look up the
thread_info for the given ptid and switch to that thread.  However, as seen in
the stack trace, sparc_fetch_inferior_registers is called before a thread_info
exists: we are creating a regcache while creating that thread_info.

The only immediate solution I see it to directly set inferior_ptid, instead of
using switch_to_thread.

-- 
You are receiving this mail because:
You are on the CC list for the bug.

^ permalink raw reply	[flat|nested] 11+ messages in thread

* [Bug gdb/27899] [GNU/Linux, sparc64] GDB crashes when debugging multithreaded programs
  2021-05-22 17:22 [Bug gdb/27899] New: [GNU/Linux, sparc64] GDB crashes when debugging multithreaded programs koachan+sourceware at protonmail dot com
  2021-05-22 17:23 ` [Bug gdb/27899] " koachan+sourceware at protonmail dot com
  2021-05-23 11:54 ` simark at simark dot ca
@ 2021-05-23 11:54 ` simark at simark dot ca
  2021-05-23 13:09 ` simark at simark dot ca
                   ` (6 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: simark at simark dot ca @ 2021-05-23 11:54 UTC (permalink / raw)
  To: gdb-prs

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

Simon Marchi <simark at simark dot ca> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
     Ever confirmed|0                           |1
   Last reconfirmed|                            |2021-05-23
             Status|UNCONFIRMED                 |NEW

-- 
You are receiving this mail because:
You are on the CC list for the bug.

^ permalink raw reply	[flat|nested] 11+ messages in thread

* [Bug gdb/27899] [GNU/Linux, sparc64] GDB crashes when debugging multithreaded programs
  2021-05-22 17:22 [Bug gdb/27899] New: [GNU/Linux, sparc64] GDB crashes when debugging multithreaded programs koachan+sourceware at protonmail dot com
                   ` (2 preceding siblings ...)
  2021-05-23 11:54 ` simark at simark dot ca
@ 2021-05-23 13:09 ` simark at simark dot ca
  2021-05-23 15:42 ` koachan+sourceware at protonmail dot com
                   ` (5 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: simark at simark dot ca @ 2021-05-23 13:09 UTC (permalink / raw)
  To: gdb-prs

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

--- Comment #3 from Simon Marchi <simark at simark dot ca> ---
Here's a patch, can you give it a try?

>From 5ba17db11ad88ae2a26183f8dd5c558b696d1c3e Mon Sep 17 00:00:00 2001
From: Simon Marchi <simon.marchi@polymtl.ca>
Date: Sun, 23 May 2021 07:48:34 -0400
Subject: [PATCH] fix

Change-Id: I0b6ddb3af9b11f67b10ee46a734fb82ecc6462d5
---
 gdb/sparc-nat.c | 10 ++++------
 1 file changed, 4 insertions(+), 6 deletions(-)

diff --git a/gdb/sparc-nat.c b/gdb/sparc-nat.c
index fa3b32cee184..7f09a60420db 100644
--- a/gdb/sparc-nat.c
+++ b/gdb/sparc-nat.c
@@ -170,9 +170,8 @@ sparc_fetch_inferior_registers (process_stratum_target
*proc_target,

       /* Deep down, sparc_supply_rwindow reads memory, so needs the global
         thread context to be set.  */
-      thread_info *thread = find_thread_ptid (proc_target, ptid);
-      scoped_restore_current_thread restore_thread;
-      switch_to_thread (thread);
+      scoped_restore restore_inferior_ptid
+       = make_scoped_restore (&inferior_ptid, ptid);

       sparc_supply_gregset (sparc_gregmap, regcache, -1, &regs);
       if (regnum != -1)
@@ -219,9 +218,8 @@ sparc_store_inferior_registers (process_stratum_target
*proc_target,

          /* Deep down, sparc_collect_rwindow writes memory, so needs the
global
             thread context to be set.  */
-         thread_info *thread = find_thread_ptid (proc_target, ptid);
-         scoped_restore_current_thread restore_thread;
-         switch_to_thread (thread);
+         scoped_restore restore_inferior_ptid
+           = make_scoped_restore (&inferior_ptid, ptid);

          sparc_collect_rwindow (regcache, sp, regnum);
        }
-- 
2.31.1

-- 
You are receiving this mail because:
You are on the CC list for the bug.

^ permalink raw reply	[flat|nested] 11+ messages in thread

* [Bug gdb/27899] [GNU/Linux, sparc64] GDB crashes when debugging multithreaded programs
  2021-05-22 17:22 [Bug gdb/27899] New: [GNU/Linux, sparc64] GDB crashes when debugging multithreaded programs koachan+sourceware at protonmail dot com
                   ` (3 preceding siblings ...)
  2021-05-23 13:09 ` simark at simark dot ca
@ 2021-05-23 15:42 ` koachan+sourceware at protonmail dot com
  2021-05-25 14:10 ` koachan+sourceware at protonmail dot com
                   ` (4 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: koachan+sourceware at protonmail dot com @ 2021-05-23 15:42 UTC (permalink / raw)
  To: gdb-prs

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

--- Comment #4 from Koakuma <koachan+sourceware at protonmail dot com> ---
(In reply to Simon Marchi from comment #3)
> Here's a patch, can you give it a try?

Hmm, yeah, the patch works for me, at least for the test case.

-- 
You are receiving this mail because:
You are on the CC list for the bug.

^ permalink raw reply	[flat|nested] 11+ messages in thread

* [Bug gdb/27899] [GNU/Linux, sparc64] GDB crashes when debugging multithreaded programs
  2021-05-22 17:22 [Bug gdb/27899] New: [GNU/Linux, sparc64] GDB crashes when debugging multithreaded programs koachan+sourceware at protonmail dot com
                   ` (4 preceding siblings ...)
  2021-05-23 15:42 ` koachan+sourceware at protonmail dot com
@ 2021-05-25 14:10 ` koachan+sourceware at protonmail dot com
  2021-05-27  2:34 ` simark at simark dot ca
                   ` (3 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: koachan+sourceware at protonmail dot com @ 2021-05-25 14:10 UTC (permalink / raw)
  To: gdb-prs

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

--- Comment #5 from Koakuma <koachan+sourceware at protonmail dot com> ---
I've tried the patch on several other binaries, and it seems to work on them
too, thanks!

-- 
You are receiving this mail because:
You are on the CC list for the bug.

^ permalink raw reply	[flat|nested] 11+ messages in thread

* [Bug gdb/27899] [GNU/Linux, sparc64] GDB crashes when debugging multithreaded programs
  2021-05-22 17:22 [Bug gdb/27899] New: [GNU/Linux, sparc64] GDB crashes when debugging multithreaded programs koachan+sourceware at protonmail dot com
                   ` (5 preceding siblings ...)
  2021-05-25 14:10 ` koachan+sourceware at protonmail dot com
@ 2021-05-27  2:34 ` simark at simark dot ca
  2021-05-31  1:17 ` simark at simark dot ca
                   ` (2 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: simark at simark dot ca @ 2021-05-27  2:34 UTC (permalink / raw)
  To: gdb-prs

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

Simon Marchi <simark at simark dot ca> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Target Milestone|---                         |11.1
             Status|NEW                         |ASSIGNED

--- Comment #6 from Simon Marchi <simark at simark dot ca> ---
Marking target milestone GDB 11 so we remember to fix this for GDB 11.

-- 
You are receiving this mail because:
You are on the CC list for the bug.

^ permalink raw reply	[flat|nested] 11+ messages in thread

* [Bug gdb/27899] [GNU/Linux, sparc64] GDB crashes when debugging multithreaded programs
  2021-05-22 17:22 [Bug gdb/27899] New: [GNU/Linux, sparc64] GDB crashes when debugging multithreaded programs koachan+sourceware at protonmail dot com
                   ` (6 preceding siblings ...)
  2021-05-27  2:34 ` simark at simark dot ca
@ 2021-05-31  1:17 ` simark at simark dot ca
  2021-06-07 15:03 ` cvs-commit at gcc dot gnu.org
  2021-06-07 15:04 ` simark at simark dot ca
  9 siblings, 0 replies; 11+ messages in thread
From: simark at simark dot ca @ 2021-05-31  1:17 UTC (permalink / raw)
  To: gdb-prs

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

--- Comment #7 from Simon Marchi <simark at simark dot ca> ---
Patch posted here:

https://sourceware.org/pipermail/gdb-patches/2021-May/179382.html

-- 
You are receiving this mail because:
You are on the CC list for the bug.

^ permalink raw reply	[flat|nested] 11+ messages in thread

* [Bug gdb/27899] [GNU/Linux, sparc64] GDB crashes when debugging multithreaded programs
  2021-05-22 17:22 [Bug gdb/27899] New: [GNU/Linux, sparc64] GDB crashes when debugging multithreaded programs koachan+sourceware at protonmail dot com
                   ` (7 preceding siblings ...)
  2021-05-31  1:17 ` simark at simark dot ca
@ 2021-06-07 15:03 ` cvs-commit at gcc dot gnu.org
  2021-06-07 15:04 ` simark at simark dot ca
  9 siblings, 0 replies; 11+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2021-06-07 15:03 UTC (permalink / raw)
  To: gdb-prs

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

--- Comment #8 from cvs-commit at gcc dot gnu.org <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by Simon Marchi <simark@sourceware.org>:

https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=cfa8e270c9dce83e89b03bc5d793835027731891

commit cfa8e270c9dce83e89b03bc5d793835027731891
Author: Simon Marchi <simon.marchi@polymtl.ca>
Date:   Mon Jun 7 11:03:04 2021 -0400

    gdb: set only inferior_ptid in sparc_{fetch,store}_inferior_registers

    The past commit d1e93af64a6b ("gdb: set current thread in
    sparc_{fetch,collect}_inferior_registers (PR gdb/27147)") changed
    sparc_fetch_inferior_registers and sparc_store_inferior_registers to
    look up the thread corresponding to the regcache's ptid and make it the
    current thread.  The reason being that down the call chain, some
    functions (like sparc_supply_rwindow) can do some memory reads or write,
    through target_read_memory/target_write_memory, and those rely on the
    current global context.

    There is one small problem with this approach: when debugging a
    multi-threaded program, the regcache for a new thread is created just
    before the corresponding thread_info is created.  In fact, the regcache
    is created somewhere during the call to thread_from_lwp, which is
    responsible for creating the thread_info:

        #8  0x0000010000ab9968 in internal_error (file=0x10000bfca20
"/home/simark/src/binutils-gdb/gdb/thread.c", line=1346, fmt=0x10000bfc918 "%s:
Assertion `%s' failed.") at
/home/simark/src/binutils-gdb/gdbsupport/errors.cc:55
        #9  0x0000010000827f3c in switch_to_thread (thr=0x0) at
/home/simark/src/binutils-gdb/gdb/thread.c:1346
        #10 0x0000010000753444 in sparc_fetch_inferior_registers
(proc_target=0x10000fa8cb0 <the_sparc64_linux_nat_target>,
regcache=0x10000ff03c0, regnum=-1) at
/home/simark/src/binutils-gdb/gdb/sparc-nat.c:175
        #11 0x000001000075b908 in sparc64_linux_nat_target::fetch_registers
(this=0x10000fa8cb0 <the_sparc64_linux_nat_target>, regcache=0x10000ff03c0,
regnum=-1) at /home/simark/src/binutils-gdb/gdb/sparc64-linux-nat.c:38
        #12 0x00000100007fe6f4 in target_ops::fetch_registers
(this=0x10000f7feb0 <the_thread_db_target>, arg0=0x10000ff03c0, arg1=-1) at
/home/simark/src/binutils-gdb/gdb/target-delegates.c:496
        #13 0x00000100008162a0 in target_fetch_registers
(regcache=0x10000ff03c0, regno=-1) at
/home/simark/src/binutils-gdb/gdb/target.c:3287
        #14 0x000001000060a4bc in ps_lgetregs (ph=0x10001264368, lwpid=458727,
gregset=0x7feff97d388) at /home/simark/src/binutils-gdb/gdb/proc-service.c:158
        #15 0xffff800103e32420 in __td_ta_lookup_th_unique
(ta_arg=0x100012d7080, lwpid=<optimized out>, th=0x7feff97d7c8) at
td_ta_map_lwp2thr.c:119
        #16 0xffff800103e32604 in td_ta_map_lwp2thr (ta_arg=0x100012d7080,
lwpid=<optimized out>, th=0x7feff97d7c8) at td_ta_map_lwp2thr.c:207
        #17 0x000001000051fee8 in thread_from_lwp (stopped=0x100011a3650,
ptid=...) at /home/simark/src/binutils-gdb/gdb/linux-thread-db.c:415
        #18 0x0000010000520150 in thread_db_notice_clone (parent=...,
child=...) at /home/simark/src/binutils-gdb/gdb/linux-thread-db.c:446
        #19 0x00000100005068a8 in linux_handle_extended_wait (lp=0x10001230700,
status=4479) at /home/simark/src/binutils-gdb/gdb/linux-nat.c:1978
        #20 0x000001000050a278 in linux_nat_filter_event (lwpid=458724,
status=198015) at /home/simark/src/binutils-gdb/gdb/linux-nat.c:2913
        #21 0x000001000050b818 in linux_nat_wait_1 (ptid=...,
ourstatus=0x7feff97e8d0, target_options=...) at
/home/simark/src/binutils-gdb/gdb/linux-nat.c:3194
        #22 0x000001000050ca4c in linux_nat_target::wait (this=0x10000fa8cb0
<the_sparc64_linux_nat_target>, ptid=..., ourstatus=0x7feff97e8d0,
target_options=...) at /home/simark/src/binutils-gdb/gdb/linux-nat.c:3432
        #23 0x00000100005237ec in thread_db_target::wait (this=0x10000f7feb0
<the_thread_db_target>, ptid=..., ourstatus=0x7feff97e8d0, options=...) at
/home/simark/src/binutils-gdb/gdb/linux-thread-db.c:1379
        #24 0x00000100007fa668 in target_wait (ptid=..., status=0x7feff97e8d0,
options=...) at /home/simark/src/binutils-gdb/gdb/target.c:2000
        #25 0x00000100004adb0c in do_target_wait_1 (inf=0x10001173170,
ptid=..., status=0x7feff97e8d0, options=...) at
/home/simark/src/binutils-gdb/gdb/infrun.c:3464
        #26 0x00000100004add48 in operator() (__closure=0x7feff97e658,
inf=0x10001173170) at /home/simark/src/binutils-gdb/gdb/infrun.c:3527
        #27 0x00000100004ae15c in do_target_wait (wait_ptid=...,
ecs=0x7feff97e8a8, options=...) at
/home/simark/src/binutils-gdb/gdb/infrun.c:3540
        #28 0x00000100004af254 in fetch_inferior_event () at
/home/simark/src/binutils-gdb/gdb/infrun.c:3880
        #29 0x0000010000486ef8 in inferior_event_handler
(event_type=INF_REG_EVENT) at /home/simark/src/binutils-gdb/gdb/inf-loop.c:42

    The problem is that while sparc_fetch_inferior_registers runs and is
    asked to read the registers of a given ptid, there isn't a thread_info
    with that ptid yet.  So, find_thread_ptid returns nullptr, and
    switch_to_thread gives an internal error.

    Fix this by only setting inferior_ptid, instead of the whole global
    context, as switch_to_thread does.  This is sufficient for
    target_read_memory / target_write_memory to work down the line.

    Ideally, it would be nice to be able to pass the ptid down the whole
    call chain and to target_read_memory / target_write_memory, so that this
    setting of inferior_ptid would not be necessary.  But this is not going
    to happen soon.

    This fixes running a multi-threaded program, which would hit the
    internal error show in the call stack above.

    gdb/ChangeLog:

            PR gdb/27899
            * sparc-nat.c (sparc_fetch_inferior_registers): Set
            inferior_ptid instead of using switch_to_thread.
            (sparc_store_inferior_registers): Likewise.

    Change-Id: I0b6ddb3af9b11f67b10ee46a734fb82ecc6462d5

-- 
You are receiving this mail because:
You are on the CC list for the bug.

^ permalink raw reply	[flat|nested] 11+ messages in thread

* [Bug gdb/27899] [GNU/Linux, sparc64] GDB crashes when debugging multithreaded programs
  2021-05-22 17:22 [Bug gdb/27899] New: [GNU/Linux, sparc64] GDB crashes when debugging multithreaded programs koachan+sourceware at protonmail dot com
                   ` (8 preceding siblings ...)
  2021-06-07 15:03 ` cvs-commit at gcc dot gnu.org
@ 2021-06-07 15:04 ` simark at simark dot ca
  9 siblings, 0 replies; 11+ messages in thread
From: simark at simark dot ca @ 2021-06-07 15:04 UTC (permalink / raw)
  To: gdb-prs

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

Simon Marchi <simark at simark dot ca> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|ASSIGNED                    |RESOLVED
         Resolution|---                         |FIXED

--- Comment #9 from Simon Marchi <simark at simark dot ca> ---
Fixed in master.

-- 
You are receiving this mail because:
You are on the CC list for the bug.

^ permalink raw reply	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2021-06-07 15:04 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-05-22 17:22 [Bug gdb/27899] New: [GNU/Linux, sparc64] GDB crashes when debugging multithreaded programs koachan+sourceware at protonmail dot com
2021-05-22 17:23 ` [Bug gdb/27899] " koachan+sourceware at protonmail dot com
2021-05-23 11:54 ` simark at simark dot ca
2021-05-23 11:54 ` simark at simark dot ca
2021-05-23 13:09 ` simark at simark dot ca
2021-05-23 15:42 ` koachan+sourceware at protonmail dot com
2021-05-25 14:10 ` koachan+sourceware at protonmail dot com
2021-05-27  2:34 ` simark at simark dot ca
2021-05-31  1:17 ` simark at simark dot ca
2021-06-07 15:03 ` cvs-commit at gcc dot gnu.org
2021-06-07 15:04 ` simark at simark dot ca

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).