Skip to content

Commit

Permalink
gdb/testsuite: Reduce gdb.threads/threadcrash.exp reliance on libc sy…
Browse files Browse the repository at this point in the history
…mbols

The test gdb.threads/threadcrash.exp demanded GDB to fully unwind and
print the names of all functions. However, some of the functions are
from the libc library, and so the test implicitly demanded libc symbols
to be available, and would fail otherwise, as was raised in PR
gdb/31293.

This commit changes it so we only explicitly check for functions that
are not provided by threadcrash.c if they are indeed available.

Tested on arm-linux and x86_64-linux.

Approved-By: Tom de Vries <[email protected]>
Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=31293
  • Loading branch information
GwenTheKween authored and vries committed Mar 11, 2024
1 parent 623840f commit f215d2d
Showing 1 changed file with 41 additions and 7 deletions.
48 changes: 41 additions & 7 deletions gdb/testsuite/gdb.threads/threadcrash.exp
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,18 @@
# a gcore.


set have_sleep -1
set have_pthread_kill -1

# Use 'thread apply all backtrace' to check if all expected threads
# are present, and stopped in the expected locations. Set the global
# TEST_LIST to be the a list of regexps expected to match all the
# threads. We generate it now so that the list is in the order that
# GDB sees the threads.

proc thread_apply_all {} {
global have_sleep
global have_pthread_kill
global test_list

set test_list { }
Expand Down Expand Up @@ -73,6 +78,14 @@ proc thread_apply_all {} {
lappend test_list 7
exp_continue
}
-re "^\r\n${hs} in sleep $hs$eol" {
set have_sleep 1
exp_continue
}
-re "^\r\n${hs} in pthread_kill $hs$eol" {
set have_pthread_kill 1
exp_continue
}
-re "^\r\n$hs$eol" {
exp_continue
}
Expand All @@ -82,6 +95,13 @@ proc thread_apply_all {} {
}

gdb_assert {$unwind_fail == false}

if { $have_sleep == -1 } {
set have_sleep 0
}
if { $have_pthread_kill == -1 } {
set have_pthread_kill 0
}
}

# Perform all the tests we're interested in. They are:
Expand All @@ -90,6 +110,8 @@ proc thread_apply_all {} {
# * testing if GDB recreated the full backtrace we expect for all threads

proc do_full_test {} {
global have_sleep
global have_pthread_kill
global test_list
set thread_count [get_valueof "" "\$_inferior_thread_count" 0]
gdb_assert {$thread_count == 7}
Expand All @@ -98,32 +120,44 @@ proc do_full_test {} {

gdb_assert {$thread_count == [llength $test_list]}

if { $have_sleep } {
set sleep ".*sleep.*"
} else {
set sleep ".*"
}

if { $have_pthread_kill } {
set pthread_kill ".*pthread_kill.*"
} else {
set pthread_kill ".*"
}

for {set i 0} {$i < $thread_count } {incr i} {
set thread_num [expr [llength $test_list] - $i]

set type [lindex $test_list $i]
if { $type == 1 } {
set re \
[multi_line \
".sleep.*" \
$sleep \
".*do_syscall_task .location=SIGNAL_ALT_STACK.*" \
".*signal_handler.*" \
".*signal handler called.*" \
".*pthread_kill.*" \
$pthread_kill \
".*thread_function.*"]
} elseif { $type == 2 } {
set re \
[multi_line \
".*sleep.*" \
$sleep \
".*do_syscall_task .location=SIGNAL_HANDLER.*" \
".*signal_handler.*" \
".*signal handler called.*" \
".*pthread_kill.*" \
$pthread_kill \
".*thread_function.*"]
} elseif { $type == 3 } {
set re \
[multi_line \
".*sleep.*" \
$sleep \
".*do_syscall_task .location=NORMAL.*" \
".*thread_function.*"]
} elseif { $type == 4 } {
Expand All @@ -132,15 +166,15 @@ proc do_full_test {} {
".*do_spin_task .location=SIGNAL_ALT_STACK.*" \
".*signal_handler.*" \
".*signal handler called.*" \
".*pthread_kill.*" \
$pthread_kill \
".*thread_function.*"]
} elseif { $type == 5 } {
set re \
[multi_line \
".*do_spin_task .location=SIGNAL_HANDLER.*" \
".*signal_handler.*" \
".*signal handler called.*" \
".*pthread_kill.*" \
$pthread_kill \
".*thread_function.*"]
} elseif { $type == 6 } {
set re \
Expand Down

0 comments on commit f215d2d

Please sign in to comment.