1 http://sourceware.org/ml/gdb-patches/2011-02/msg00680.html
2 Subject: [patch 2/3] Fix threading internal error on corrupted memory [rediff]
7 2011-02-24 Jan Kratochvil <jan.kratochvil@redhat.com>
9 * linux-thread-db.c (find_new_threads_callback): Exit on zero TI_TID
10 even if !TARGET_HAS_EXECUTION.
13 2011-02-24 Jan Kratochvil <jan.kratochvil@redhat.com>
15 * gdb.threads/gcore-thread.exp ($core0file): New variable.
16 (clear __stack_user.next, clear stack_used.next)
17 (save a zeroed-threads corefile): New test.
18 Call core_load for $core0file.
19 (zeroed-threads cannot be listed): New test.
21 --- a/gdb/linux-thread-db.c
22 +++ b/gdb/linux-thread-db.c
23 @@ -1335,7 +1335,7 @@ find_new_threads_callback (const td_thrhandle_t *th_p, void *data)
24 if (ti.ti_state == TD_THR_UNKNOWN || ti.ti_state == TD_THR_ZOMBIE)
25 return 0; /* A zombie -- ignore. */
27 - if (ti.ti_tid == 0 && target_has_execution)
30 /* A thread ID of zero means that this is the main thread, but
31 glibc has not yet initialized thread-local storage and the
32 @@ -1347,10 +1347,13 @@ find_new_threads_callback (const td_thrhandle_t *th_p, void *data)
33 need this glibc bug workaround. */
34 info->need_stale_parent_threads_check = 0;
36 - err = info->td_thr_event_enable_p (th_p, 1);
38 - error (_("Cannot enable thread event reporting for LWP %d: %s"),
39 - (int) ti.ti_lid, thread_db_err_str (err));
40 + if (target_has_execution)
42 + err = info->td_thr_event_enable_p (th_p, 1);
44 + error (_("Cannot enable thread event reporting for LWP %d: %s"),
45 + (int) ti.ti_lid, thread_db_err_str (err));
50 --- a/gdb/testsuite/gdb.threads/gcore-thread.exp
51 +++ b/gdb/testsuite/gdb.threads/gcore-thread.exp
52 @@ -26,6 +26,7 @@ set testfile "gcore-thread"
53 set srcfile pthreads.c
54 set binfile ${objdir}/${subdir}/${testfile}
55 set corefile ${objdir}/${subdir}/${testfile}.test
56 +set core0file ${objdir}/${subdir}/${testfile}0.test
58 if [istarget "*-*-linux"] then {
59 set target_cflags "-D_MIT_POSIX_THREADS"
60 @@ -110,6 +111,29 @@ if {!$core_supported} {
64 +# Test the uninitialized thread list.
65 +# Provide the case of glibc td_thr_get_info handling of:
66 +# /* Special case for the main thread before initialization. */
68 +foreach symbol {__stack_user stack_used} {
69 + set test "clear ${symbol}.next"
70 + gdb_test_multiple "p *(void **) &${symbol} = 0" $test {
71 + -re " = \\(void \\*\\) 0x0\r\n$gdb_prompt $" {
74 + -re "No symbol \"${symbol}\" in current context\\.\r\n$gdb_prompt $" {
76 + # Do not do the verification.
82 +if {"$core0file" != ""} {
83 + gdb_test "gcore $core0file" "Saved corefile .*" "save a zeroed-threads corefile"
87 # Now restart gdb and load the corefile.
88 clean_restart ${testfile}
90 @@ -160,3 +184,11 @@ gdb_test "info threads" ".* thread2 .*" \
92 gdb_test "info threads" ".*${nl}\\* ${horiz} thread2 .*" \
93 "thread2 is current thread in corefile"
96 +# Test the uninitialized thread list.
98 +if {"$core0file" != "" && [load_core $core0file]} {
100 + gdb_test "info threads" "Cannot find new threads: .*" "zeroed-threads cannot be listed"