This is the mail archive of the gdb-patches@sourceware.org mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

RFC: Fix crash on i386 (%gs-)threaded programs using execve(2)


Hi all,

right now gdb(1) crashes on execve(2) executed by any -lpthread i386 process
on recent %gs based TLS glibc.

https://bugzilla.redhat.com/bugzilla/show_bug.cgi?id=182116

(new test case "gdb.threads/thread-lost")
Currently:

# gcc -o ./testsuite/gdb.threads/thread-lost ./testsuite/gdb.threads/thread-lost.c -Wall -lpthread -ggdb3
# ./gdb -nx ./testsuite/gdb.threads/thread-lost
GNU gdb 6.5.50.20060614-cvs
...
(gdb) run
Starting program: /home/lace/redhat/src/gdb/testsuite/gdb.threads/thread-lost
[Thread debugging using libthread_db enabled]
[New Thread -1208801600 (LWP 17677)]
Cannot find user-level thread for LWP 17677: generic error
(gdb) bt
Cannot fetch general-purpose registers for thread -1208801600: generic error

With the patch:

(gdb) run
Starting program: /home/lace/redhat/src/gdb/testsuite/gdb.threads/thread-lost
[Thread debugging using libthread_db enabled]
[New Thread -1208301888 (LWP 18818)]
warning: Original threaded process got lost, dropping threads
EXECUTED
Program exited normally.


It is only a heuristic as execve(2) destroys %gs and gdb(1) fails to find the
no longer existing threads through TLS. Patch will warn and turn off the gdb(1)
threads support if it finds out %gs==0.

On i386 with %gs based TLS NPTLS gdb calls glibc td_ta_map_lwp2thr() which
calls ta_howto_reg_thread_area() (case ta_howto_reg_thread_area).
After execve(2) it retrieves %gs as 0 and fails to ps_get_thread_area()
as its idx must be 6 (glibc TLS descriptor) - value of the first/glibc Linux
kernel GDT_ENTRY_TLS_MIN.
It is now workarounded as to drop threading support if %gs==0.

Do you have an idea for a cleaner solution than this hack of waiting till the
threads are no longer accessible?  Not aware of some indication which kernel
syscall will replace the whole process memory space and the process registers.

It also fixes 11 gdb testsuite failures but these were not analysed from case
to case regarding possible false positives.


Regards,
Jan Kratochvil

Attachment: gdb-cvs20060614-thread_lost.patch
Description: Patch for i386 GDB as of CVS 2006-06-14

Attachment: thread-lost.c
Description: Minimized bug reproducibility test case


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]