aboutsummaryrefslogtreecommitdiff
path: root/gdb/testsuite/gdb.threads
AgeCommit message (Collapse)AuthorFilesLines
2023-01-26Eliminate spurious returns from the test suiteTom Tromey9-18/+0
A number of tests end with "return". However, this is unnecessary. This patch removes all of these.
2023-01-25Use require with is_remoteTom Tromey3-9/+6
This changes some tests to use require with 'is_remote', rather than an explicit test. This adds uniformity helps clean up more spots where a test might exit early without any notification.
2023-01-25Add unsupported calls where neededTom Tromey1-0/+1
A number of tests will exit early without saying why. This patch adds "unsupported" at spots like this that I could readily find. There are definitely more of these; for example dw2-ranges.exp fails silently because a compilation fails. I didn't attempt to address these as that is a much larger task.
2023-01-13Rename to allow_hw_breakpoint_testsTom Tromey1-1/+1
This changes skip_hw_breakpoint_tests to invert the sense, and renames it to allow_hw_breakpoint_tests. This also converts some tests to use "require" -- I missed this particular check in the first series.
2023-01-13Rename to allow_shlib_testsTom Tromey1-1/+1
This changes skip_shlib_tests to invert the sense, and renames it to allow_shlib_tests.
2023-01-13Rename to allow_python_testsTom Tromey1-1/+1
This changes skip_python_tests to invert the sense, and renames it to allow_python_tests.
2023-01-13Rename to allow_hw_watchpoint_testsTom Tromey5-9/+9
This changes skip_hw_watchpoint_tests to invert the sense, and renames it to allow_hw_watchpoint_tests.
2023-01-13Rename to allow_hw_watchpoint_multi_testsTom Tromey3-3/+3
This changes skip_hw_watchpoint_multi_tests to invert the sense, and renames it to allow_hw_watchpoint_multi_tests.
2023-01-13Rename to allow_hw_watchpoint_access_testsTom Tromey1-1/+1
This changes skip_hw_watchpoint_access_tests to invert the sense, and renames it to allow_hw_watchpoint_access_tests.
2023-01-13Use "require" for Python testsTom Tromey1-4/+1
This changes various tests to use "require" for the Python feature.
2023-01-13Use require !gdb_debug_enabledTom Tromey3-11/+3
This changes some tests to use "require !gdb_debug_enabled".
2023-01-13Use require isnativeTom Tromey4-7/+8
This changes some tests to use "require isnative".
2023-01-13Use require can_spawn_for_attachTom Tromey4-12/+4
This changes some tests to use "require can_spawn_for_attach".
2023-01-13Use require !use_gdb_stubTom Tromey4-10/+7
This changes some tests to use "require !use_gdb_stub".
2023-01-13Use require !skip_hw_watchpoint_testsTom Tromey6-18/+7
This changes some tests to use "require !skip_hw_watchpoint_tests".
2023-01-13Use require !skip_shlib_testsTom Tromey1-1/+2
This changes some tests to use "require !skip_shlib_tests".
2023-01-11[gdb/testsuite] Fix regexp in gdb.threads/dlopen-libpthread.expSimon Marchi1-2/+2
Fix regexp in gdb.threads/dlopen-libpthread.exp: 'libpthread\\.so' -> '/libpthread\\.so'. Tested on x86_64-linux.
2023-01-11[gdb/testsuite] Fix gdb.threads/dlopen-libpthread.exp for upstream glibc, againTom de Vries1-6/+24
On an x86_64 laptop running ubuntu 22.04.1 with unity desktop: ... $ echo $XDG_CURRENT_DESKTOP Unity:Unity7:ubuntu ... I have: ... $ echo $LD_PRELOAD libgtk3-nocsd.so.0 ... due to package gtk3-nocsd, a package recommended by unity-session. Consequently, for each exec these dependencies are pulled in, including libpthread.so.0: ... $ lddtree /lib/x86_64-linux-gnu/libgtk3-nocsd.so.0 libgtk3-nocsd.so.0 => /lib/x86_64-linux-gnu/libgtk3-nocsd.so.0 (interpreter => none) libdl.so.2 => /lib/x86_64-linux-gnu/libdl.so.2 libpthread.so.0 => /lib/x86_64-linux-gnu/libpthread.so.0 libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 ld-linux-x86-64.so.2 => /lib/x86_64-linux-gnu/ld-linux-x86-64.so.2 ... So, while test-case gdb.threads/dlopen-libpthread.exp appears to run ok: ... # of expected passes 12 # of unsupported tests 1 ... with LD_PRELOAD="" we have instead: ... (gdb) PASS: gdb.threads/dlopen-libpthread.exp: continue to breakpoint: notify info sharedlibrary^M From To Syms Read Shared Object Library^M $hex $hex Yes /lib64/ld-linux-x86-64.so.2^M $hex $hex Yes /lib/x86_64-linux-gnu/libc.so.6^M $hex $hex Yes dlopen-libpthread.so^M (gdb) FAIL: gdb.threads/dlopen-libpthread.exp: libpthread.so found ... The problem is that libpthread is expected as dependency of dlopen-libpthread.so, but it's missing: ... $ lddtree dlopen-libpthread.so dlopen-libpthread.so => ./dlopen-libpthread.so (interpreter => none) libc.so.6 => $outputs/gdb.threads/dlopen-libpthread/dlopen-libpthread.so.d/libc.so.6 ld-linux-x86-64.so.2 => /lib/x86_64-linux-gnu/ld-linux-x86-64.so.2 ... due to having glibc 2.35, which has libpthread integrated into libc. Fix this by: - adding a proc has_dependency - using [has_dependency $exec libpthread.so] as hint that libpthread may be preloaded - using ![has_dependency $shlib libpthread.so] to detect that the libpthread.so dependency is missing. Also add a missing return after untested "no matching probes". Tested on x86_64-linux, with and without LD_PRELOAD="".
2023-01-01Update copyright year range in header of all files managed by GDBJoel Brobecker230-230/+230
This commit is the result of running the gdb/copyright.py script, which automated the update of the copyright year range for all source files managed by the GDB project to be updated to include year 2023.
2022-12-31[gdb/testsuite] Replace deprecated pthread_yield in ↵Tom de Vries1-5/+5
gdb.threads/watchpoint-fork.exp On Ubuntu 22.04.1 x86_64, with glibc 2.35 I run into: ... watchpoint-fork-mt.c: In function 'start':^M watchpoint-fork-mt.c:67:7: warning: 'pthread_yield' is deprecated: \ pthread_yield is deprecated, use sched_yield instead \ [-Wdeprecated-declarations]^M 67 | i = pthread_yield ();^M | ^^M ... Fix this as suggested, by using sched_yield instead. Tested on x86_64-linux.
2022-12-30[gdb/testsuite] Fix gdb.threads/dlopen-libpthread.exp for upstream glibcTom de Vries1-10/+25
On ubuntu 22.04.1 x86_64, I run into: ... (gdb) info probes all rtld rtld_map_complete^M No probes matched.^M (gdb) XFAIL: gdb.threads/dlopen-libpthread.exp: info probes all rtld rtld_map_complete UNTESTED: gdb.threads/dlopen-libpthread.exp: no matching probes ... This has been filed as PR testsuite/17016. The problem is that the name rtld_map_complete is used, which was only available in Fedora 17, and upstream the name map_complete was used. In the email thread discussing a proposed patch ( https://sourceware.org/legacy-ml/gdb-patches/2014-09/msg00712.html ) it was suggested to make the test-case handle both names. So, handle both names: map_complete and rtld_map_complete. This exposes the following FAIL: ... (gdb) info sharedlibrary^M From To Syms Read Shared Object Library^M $hex $hex Yes /lib64/ld-linux-x86-64.so.2^M $hex $hex Yes (*) /lib/x86_64-linux-gnu/libgtk3-nocsd.so.0^M $hex $hex Yes /lib/x86_64-linux-gnu/libc.so.6^M $hex $hex Yes /lib/x86_64-linux-gnu/libdl.so.2^M $hex $hex Yes /lib/x86_64-linux-gnu/libpthread.so.0^M (*): Shared library is missing debugging information.^M (gdb) FAIL: gdb.threads/dlopen-libpthread.exp: libpthread.so not found ... due to using a glibc (v2.35) that has libpthread integrated into libc. Fix this by changing the FAIL into UNSUPPORTED. Tested on x86_64-linux. Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=17016
2022-12-16[gdb/testsuite] Fix race in gdb.threads/detach-step-over.expTom de Vries1-8/+26
Once in a while I run into: ... FAIL: gdb.threads/detach-step-over.exp: \ breakpoint-condition-evaluation=host: target-non-stop=off: non-stop=off: \ displaced=off: iter 1: all threads running ... In can easily reproduce this by doing: ... # Wait a bit, to give time for the threads to hit the # breakpoint. - sleep 1 return true ... Fix this by counting the running threads in a loop, effectively allowing 10 seconds (instead of 1) for the threads to start running, but only sleeping if needed. Reduces total execution time from 1m27s to 56s. Tested on x86_64-linux.
2022-11-28gdb/testsuite: remove use of then keyword from gdb.threads/*.expAndrew Burgess38-60/+60
The canonical form of 'if' in modern TCL is 'if {} {}'. But there's still a bunch of places in the testsuite where we make use of the 'then' keyword, and sometimes these get copies into new tests, which just spreads poor practice. This commit removes all use of the 'then' keyword from the gdb.threads/ test script directory. There should be no changes in what is tested after this commit.
2022-11-28gdb: fix assert when quitting GDB while a thread is steppingAndrew Burgess1-0/+52
This commit addresses one of the issues identified in PR gdb/28275. Bug gdb/28275 identifies a number of situations in which this assert: Assertion `!proc_target->commit_resumed_state' failed. could be triggered. There's actually a number of similar places where this assert is found in GDB, the two of interest in gdb/28275 are in target_wait and target_stop. In one of the comments: https://sourceware.org/bugzilla/show_bug.cgi?id=28275#c1 steps to trigger the assertion within target_stop were identified when using a modified version of the gdb.threads/detach-step-over.exp test script. In the gdb.threads/detach-step-over.exp test, we attach to a multi-threaded inferior, and continue the inferior in asynchronous (background) mode. Each thread is continuously hitting a conditional breakpoint where the condition is always false. While the inferior is running we detach. The goal is that we detach while GDB is performing a step-over for the conditional breakpoint in at least one thread. While detaching, if a step-over is in progress, then GDB has to complete the step over before we can detach. This involves calling target_stop and target_wait (see prepare_for_detach). As far as gdb/28275 is concerned, the interesting part here, is the the process_stratum_target::commit_resumed_state variable must be false when target_stop and target_wait are called. This is currently ensured because, in detach_command (infrun.c), we create an instance of scoped_disable_commit_resumed, this ensures that when target_detach is called, ::commit_resumed_state will be false. The modification to the test that I propose here, and which exposed the bug, is that, instead of using "detach" to detach from the inferior, we instead use "quit". Quitting GDB after attaching to an inferior will cause GDB to first detach, and then exit. When we quit GDB we end up calling target_detach via a different code path, the stack looks like: #0 target_detach #1 kill_or_detach #2 quit_force #3 quit_command Along this path there is no scoped_disable_commit_resumed created. ::commit_resumed_state can be true when we reach prepare_for_detach, which calls target_wait and target_stop, so the assertion will trigger. In this commit, I propose fixing this by adding the creation of a scoped_disable_commit_resumed into target_detach. This will ensure that ::commit_resumed_state is false when calling prepare_for_detach from within target_detach. I did consider placing the scoped_disable_commit_resumed in prepare_for_detach, however, placing it in target_detach ensures that the target's commit_resumed_state flag is left to false if the detached inferior was the last one for that target. It's the same rationale as for patch "gdb: disable commit resumed in target_kill" that comes later in this series, but for detach instead of kill. detach_command still includes a scoped_disable_commit_resumed too, but I think it is still relevant to cover the resumption at the end of the function. Co-Authored-By: Simon Marchi <simon.marchi@efficios.com> Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=28275 Change-Id: Ie128f7aba6ef0e018859275eca372e6ea738e96f
2022-11-28gdb/testsuite: refactor gdb.threads/detach-step-over.expAndrew Burgess1-100/+138
Factor out some bits of gdb.threads/detach-step-over.exp to procs in preparation to adding some new variations of the test. Rename the existing "test" proc and make it use proc_with_prefix. Co-Authored-By: Simon Marchi <simon.marchi@efficios.com> Change-Id: Ib4412545c81c8556029e0f7bfa9dd48d7a9f3189
2022-11-28gdb/testsuite: remove global declarations in gdb.threads/detach-step-over.expSimon Marchi1-23/+17
Before doing further changes to this file, change to use the :: notation instead of declaring global variables with the `global` keyword. Change-Id: I72301fd8f4693fea61aac054ba17245a1f4442fb Approved-By: Andrew Burgess <aburgess@redhat.com>
2022-11-16[gdb/testsuite] Use gdb_gcore_cmd in gdb.threads/gcore-thread.expTom de Vries1-1/+1
I noticed a plain gcore command in test-case gdb.threads/gcore-thread.exp: ... gdb_test "gcore $core0file" "Saved corefile .*" \ "save a zeroed-threads corefile" ... Use gdb_gcore_cmd instead. Tested on x86_64-linux.
2022-10-18Update tests to use skip_hw_watchpoint_tests to test for HW watchpoint support.Carl Love1-2/+11
The hardware watchpoint check has been updated in a couple of recent patches. This patch updates the hardware watchpoint test in the remaining gdb tests. The issue is the PowerPC processors support hardware watchpoints with the exception of Power 9. The hardware watchpoint support is disabled on Power 9. The test skip_hw_watchpoint_tests must be used to correctly determine if the PowerPC processor supports hardware watchpoints. This patch fixes 6 test failures in test gdb.threads/watchpoint-fork.exp. Test gdb.base/watch-vfork.exp runs with can-use-hw-watchpoints set to true and false. When the test is run with can-use-hw-watchpoints set to true, gdb just falls back to using software watchpoints. The patch reduces the number of expected passes by 2 since because it now only runs once with can-use-hw-watchpoints set to false. Test gdb.mi/mi-watch.exp runs the test with argument hw and sw. If the argument is hw and hardware watchpoints are not supported the test exits. The number of expected passes is cut in half with the patch as it now only runs the test using software breakpoints. Previously the pass to use hardware watchpoints was not skipped and the test actually ran using software watchpoints. The following tests run the same with and without the patch. The tests are supposed to execute the gdb command "set can-use-hw-watchpoints 0" if the processor does not support hardware bwatchpoints. However the command was not being executed and gdb was falling back to using software watchpoints since the Power 9 watchpoint resource check fails. With the patch, the tests now execute the command and the test runs using software watchpoints as it did previously. The tests are: gdb.base/commands.exp gdb.base/cond-eval-mode.exp gdb.base/display.exp gdb.base/gdb11531.exp gdb.base/recurse.exp gdb.base/value-double-free.exp gdb.base/watch-bitfields.exp gdb.base/watch-cond-infcall.exp gdb.base/watch-cond.exp gdb.base/watchpoint-solib.exp gdb.base/watchpoints.exp The following two tests are not supported on the Power 9 system used to test the changes. The patch does not change the tests results for these tests: gdb.python/py-breakpoint.exp gdb.mi/mi-watch-nonstop.exp
2022-10-14[gdb/testsuite] Fix gdb.base/infoline-reloc-main-from-zero.exp with clangTom de Vries1-1/+1
With test-case gdb.base/infoline-reloc-main-from-zero.exp and clang I run into: ... gdb compile failed, clang-13.0: warning: -e main: 'linker' input unused \ [-Wunused-command-line-argument] clang-13.0: warning: -Wl,-Ttext=0x00: 'linker' input unused \ [-Wunused-command-line-argument] clang-13.0: warning: -Wl,-N: 'linker' input unused \ [-Wunused-command-line-argument] UNTESTED: gdb.base/infoline-reloc-main-from-zero.exp: \ infoline-reloc-main-from-zero.exp UNTESTED: gdb.base/infoline-reloc-main-from-zero.exp: failed to compile ... Fix this by using ldflags instead of additional_flags. Likewise, fix all occurrences of: ... $ find gdb/testsuite -name *.exp | xargs grep additional_flags.*Wl ... Tested on x86_64-linux.
2022-10-07gdb/testsuite: fix gdb.threads/linux-dp.exp regexLancelot SIX1-1/+1
On ubuntu 22.04 with the libc6-dbg package installed, I have the following failure: where #0 print_philosopher (n=3, left=33 '!', right=33 '!') at .../gdb/testsuite/gdb.threads/linux-dp.c:105 #1 0x000055555555576a in philosopher (data=0x55555555937c) at .../gdb/testsuite/gdb.threads/linux-dp.c:148 #2 0x00007ffff7e11b43 in start_thread (arg=<optimized out>) at ./nptl/pthread_create.c:442 #3 0x00007ffff7ea3a00 in clone3 () at ../sysdeps/unix/sysv/linux/x86_64/clone3.S:81 (gdb) FAIL: gdb.threads/linux-dp.exp: first thread-specific breakpoint hit The regex for this test accounts for different situations (with / without debug symbol) but assumes that if debug info is present the backtrace shows execution under pthread_create. However, for the implementation under test, we are under start_thread. Update the regex to accept start_thread. Tested on Ubuntu-22.04 x86_64 with and without libc6-dbg debug symbols available. Change-Id: I1e1536279890bca2cd07f038e026b41e46af44e0
2022-10-02[gdb/testsuite] Fix waitpid testing in next-fork-other-thread.cTom de Vries1-1/+1
In next-fork-other-thread.c, there's this loop: ... do { ret = waitpid (pid, &stat, 0); } while (ret == EINTR); ... The loop condition tests for "ret == EINTR" but waitpid signals EINTR by returning -1 and setting errno to EINTR. Fix this by changing the loop condition to "ret == -1 && errno == EINTR". Tested on x86_64-linux.
2022-09-07[gdb/testsuite] Use prototype to call libc functionsTom de Vries1-1/+1
On openSUSE Tumbleweed (using glibc 2.36), I run into: ... (gdb) print /d (int) munmap (4198400, 4096)^M Invalid cast.^M (gdb) FAIL: gdb.base/break-main-file-remove-fail.exp: cmdline: \ get integer valueof "(int) munmap (4198400, 4096)" ... The problem is that after starting the executable, the symbol has type "void (*) (void)": ... (gdb) p munmap $1 = {<text variable, no debug info>} 0x401030 <munmap@plt> (gdb) start ... (gdb) p munmap $2 = {void (void)} 0x7ffff7feb9a0 <__GI_munmap> ... which causes the "Invalid cast" error. Looking at the debug info for glibc for symbol __GI_munmap: ... <0><189683>: Abbrev Number: 1 (DW_TAG_compile_unit) <189691> DW_AT_name : ../sysdeps/unix/syscall-template.S <189699> DW_AT_producer : GNU AS 2.39.0 <1><1896ae>: Abbrev Number: 2 (DW_TAG_subprogram) <1896af> DW_AT_name : __GI___munmap <1896b3> DW_AT_external : 1 <1896b4> DW_AT_low_pc : 0x10cad0 <1896bc> DW_AT_high_pc : 37 ... that's probably caused by this bit (or similar bits for other munmap aliases). This is fixed in gas on trunk by commit 5578fbf672e ("GAS: Add a return type tag to DWARF DIEs generated for function symbols"). Work around this (for say gas 2.39) by explicitly specifying the prototype for munmap. Likewise for getpid in a couple of other test-cases. Tested on x86_64-linux.
2022-07-29[gdb/testsuite] Fix gdb.threads/killed-outside.exp on aarch64Tom de Vries1-1/+2
On aarch64 (and likewise on arm), I run into: ... (gdb) PASS: gdb.threads/killed-outside.exp: get pid of inferior Executing on target: kill -9 11516 (timeout = 300) builtin_spawn -ignore SIGHUP kill -9 11516^M continue^M Continuing.^M Unable to fetch general registers: No such process.^M (gdb) [Thread 0xfffff7d511e0 (LWP 11518) exited]^M ^M Program terminated with signal SIGKILL, Killed.^M The program no longer exists.^M FAIL: gdb.threads/killed-outside.exp: prompt after first continue (timeout) ... due to a mismatch between the actual "No such process" line and the expected one: ... set no_such_process_msg "Couldn't get registers: No such process\." ... Fix this by updating the regexp. Tested on aarch64-linux, and x86_64-linux.
2022-07-20Don't stop all threads prematurely after first step of "step N"Pedro Alves2-0/+110
In all-stop mode, when the target is itself in non-stop mode (like GNU/Linux), if you use the "step N" (or "stepi/next/nexti N") to step a thread a number of times: (gdb) help step step, s Step program until it reaches a different source line. Usage: step [N] Argument N means step N times (or till program stops for another reason). ... GDB prematurely stops all threads after the first step, and doesn't re-resume them for the subsequent N-1 steps. It's as if for the 2nd and subsequent steps, the command was running with scheduler-locking enabled. This can be observed with the testcase added by this commit, which looks like this: static pthread_barrier_t barrier; static void * thread_func (void *arg) { pthread_barrier_wait (&barrier); return NULL; } int main () { pthread_t thread; int ret; pthread_barrier_init (&barrier, NULL, 2); /* We run to this line below, and then issue "next 3". That should step over the 3 lines below and land on the return statement. If GDB prematurely stops the thread_func thread after the first of the 3 nexts (and never resumes it again), then the join won't ever return. */ pthread_create (&thread, NULL, thread_func, NULL); /* set break here */ pthread_barrier_wait (&barrier); pthread_join (thread, NULL); return 0; } The test hangs and times out without the GDB fix: (gdb) next 3 [New Thread 0x7ffff7d89700 (LWP 525772)] FAIL: gdb.threads/step-N-all-progress.exp: non-stop=off: target-non-stop=on: next 3 (timeout) The problem is a core gdb bug. When you do "step/stepi/next/nexti N", GDB internally creates a thread_fsm object and associates it with the stepping thread. For the stepping commands, the FSM's class is step_command_fsm. That object is what keeps track of how many steps are left to make. When one step finishes, handle_inferior_event calls stop_waiting and returns, and then fetch_inferior_event calls the "should_stop" method of the event thread's FSM. The implementation of that method decrements the steps-left counter. If the counter is 0, it returns true and we proceed to presenting the stop to the user. If it isn't 0 yet, then the method returns false, indicating to fetch_inferior_event to "keep going". Focusing now on when the first step finishes -- we're in "all-stop" mode, with the target in non-stop mode. When a step finishes, handle_inferior_event calls stop_waiting, which itself calls stop_all_threads to stop everything. I.e., after the first step completes, all threads are stopped, before handle_inferior_event returns. And after that, now in fetch_inferior_event, we consult the thread's thread_fsm::should_stop, which as we've seen, for the first step returns false -- i.e., we need to keep_going for another step. However, since the target is in non-stop mode, keep_going resumes _only_ the current thread. All the other threads remain stopped, inadvertently. If the target is in non-stop mode, we don't actually need to stop all threads right after each step finishes, and then re-resume them again. We can instead defer stopping all threads until all the steps are completed. So fix this by delaying the stopping of all threads until after we called the FSM's "should_stop" method. I.e., move it from stop_waiting, to handle_inferior_events's callers, fetch_inferior_event and wait_for_inferior. New test included. Tested on x86-64 GNU/Linux native and gdbserver. Change-Id: Iaad50dcfea4464c84bdbac853a89df92ade6ae01
2022-07-13Tighten gdb.threads/no-unwaited-for-left.exp regexpsPedro Alves1-2/+2
A WIP version of a patch (https://sourceware.org/pipermail/gdb-patches/2022-June/190202.html) resulted in a bug that went unnoticed by the testuite, like so: (gdb) PASS: gdb.threads/no-unwaited-for-left.exp: enable scheduler-locking, for main thread continue Continuing. [New Thread 1251861.1251861] No unwaited-for children left. (gdb) PASS: gdb.threads/no-unwaited-for-left.exp: continue stops when the main thread exits info threads Id Target Id Frame 3 Thread 1251861.1251863 "no-unwaited-for" __pthread_clockjoin_ex (threadid=140737351558976, thread_return=0x0, clockid=<optimized out>, abstime=<optimized out>, block=<optimized out>) at pthread_join_common.c:145 4 Thread 1251861.1251861 "no-unwaited-for" <unavailable> in ?? () The current thread <Thread ID 1> has terminated. See `help thread'. (gdb) PASS: gdb.threads/no-unwaited-for-left.exp: only thread 3 left, main thread terminated Somehow, above, GDB re-added the zombie leader back before printing "No unwaited-for children left.". The "only thread 3 left, main thread terminated" test should have caught this, but didn't. That is because the test's regexp has a ".*" after the part that matches thread 3. This commit tightens that regexp to catch such a bug. It also tightens the "only main thread left, thread 2 terminated" test's regexp in the same way. Change-Id: I8744f327a0aa0e2669d1ddda88247e99b91cefff
2022-07-12[gdb/testsuite] Run two test-cases with ASAN_OPTIONS=verify_asan_link_order=0Tom de Vries1-1/+7
When building gdb with -fsanitize=address we run into: ... builtin_spawn gdb -nw -nx -iex set height 0 -iex set width 0 -data-directory \ build/gdb/data-directory^M ==10637==ASan runtime does not come first in initial library list; you \ should either link runtime to your application or manually preload it with \ LD_PRELOAD.^M ERROR: GDB process no longer exists ... Prevent the ASan runtime error by using ASAN_OPTIONS=verify_asan_link_order=0. This makes both test-cases pass. Tested on x86_64-linux. Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=29358
2022-06-24gdb/testsuite: remove unneeded calls to get_compiler_infoAndrew Burgess3-12/+0
It is not necessary to call get_compiler_info before calling test_compiler_info, and, after recent commits that removed setting up the gcc_compiled, true, and false globals from get_compiler_info, there is now no longer any need for any test script to call get_compiler_info directly. As a result every call to get_compiler_info outside of lib/gdb.exp is redundant, and this commit removes them all. There should be no change in what is tested after this commit.
2022-06-24gdb/testsuite: remove global gcc_compiled from gdb.expAndrew Burgess2-12/+0
After this commit the gcc_compiled global is no longer exported from lib/gdb.exp. In theory we could switch over all uses of gcc_compiled to instead call test_compiler_info directly, however, I have instead added a new proc to gdb.exp: 'is_c_compiler_gcc'. I've then updated the testsuite to call this proc instead of using the global. Having a new proc specifically for this task means that we have a single consistent pattern for detecting gcc. By wrapping this logic within a proc that calls test_compiler_info, rather than using the global, means that test scripts don't need to call get_compiler_info before they read the global, simply calling the new proc does everything in one go. As a result I've been able to remove the get_compiler_info calls from all the test scripts that I've touched in this commit. In some of the tests e.g. gdb.dwarf2/*.exp, the $gcc_compiled flag was being checked at the top of the script to decide if the whole script should be skipped or not. In these cases I've called the new proc directly and removed all uses of gcc_compiled. In other cases, e.g. most of the gdb.base scripts, there were many uses of gcc_compiled. In these cases I set a new global gcc_compiled near the top of the script, and leave the rest of the script unchanged. There should be no changes in what is tested after this commit.
2022-06-09gdb/testsuite: resolve duplicate test names in gdb.threads/tls.expAndrew Burgess1-1/+4
While running the gdb.threads/tls.exp test with a GDB configured without Python, I noticed some duplicate test names. This is caused by a call to skip_python_tests that is within a proc that is called multiple times by the test script. Each call to skip_python_tests results in a call to 'unsupported', and this causes the duplicate test names. After this commit we now call skip_python_tests just once and place the result into a variable. Now, instead of calling skip_python_tests multiple times, we just check the variable. There should be no change in what is tested after this commit.
2022-06-04[gdb/testsuite] Fix gdb.threads/manythreads.exp with check-read1Tom de Vries1-15/+19
When running test-case gdb.threads/manythreads.exp with check-read1, I ran into this hard-to-reproduce FAIL: ... [New Thread 0x7ffff7318700 (LWP 31125)]^M [Thread 0x7ffff7321700 (LWP 31124) exited]^M [New T^C^M ^M Thread 769 "manythreads" received signal SIGINT, Interrupt.^M [Switching to Thread 0x7ffff6d66700 (LWP 31287)]^M 0x00007ffff7586a81 in clone () from /lib64/libc.so.6^M (gdb) FAIL: gdb.threads/manythreads.exp: stop threads 1 ... The matching in the failing gdb_test_multiple is done in an intricate way, trying to pass on some order and fail on another order. Fix this by rewriting the regexps to match one line at most, and detecting invalid order by setting and checking state variables. Tested on x86_64-linux. Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=29177
2022-05-25gdb: Fix DUPLICATE and PATH regressions throughoutPedro Alves3-9/+8
The previous patch to add -prompt/-lbl to gdb_test introduced a regression: Before, you could specify an explicit empty message to indicate you didn't want to PASS, like so: gdb_test COMMAND PATTERN "" After said patch, gdb_test no longer distinguishes no-message-specified vs empty-message, so tests that previously would be silent on PASS, now started emitting PASS messages based on COMMAND. This in turn introduced a number of PATH/DUPLICATE violations in the testsuite. This commit fixes all the regressions I could see. This patch uses the new -nopass feature introduced in the previous commit, but tries to avoid it if possible. Most of the patch fixes DUPLICATE issues the usual way, of using with_test_prefix or explicit unique messages. See previous commit's log for more info. In addition to looking for DUPLICATEs, I also looked for cases where we would now end up with an empty message in gdb.sum, due to a gdb_test being passed both no message and empty command. E.g., this in gdb.ada/bp_reset.exp: gdb_run_cmd gdb_test "" "Breakpoint $decimal, foo\\.nested_sub \\(\\).*" was resulting in this in gdb.sum: PASS: gdb.ada/bp_reset.exp: I fixed such cases by passing an explicit message. We may want to make such cases error out. Tested on x86_64 GNU/Linux, native and native-extended-gdbserver. I see zero PATH cases now. I get zero DUPLICATEs with native testing now. I still see some DUPLICATEs with native-extended-gdbserver, but those were preexisting, unrelated to the gdb_test change. Change-Id: I5375f23f073493e0672190a0ec2e847938a580b2
2022-05-22Accept functions with DW_AT_linkage_name presentAlok Kumar Sharma2-0/+100
Currently GDB is not able to debug (Binary generated with Clang) variables present in shared/private clause of OpenMP Task construct. Please note that LLVM debugger LLDB is able to debug. In case of OpenMP, compilers generate artificial functions which are not present in actual program. This is done to apply parallelism to block of code. For non-artifical functions, DW_AT_name attribute should contains the name exactly as present in actual program. (Ref# http://wiki.dwarfstd.org/index.php?title=Best_Practices) Since artificial functions are not present in actual program they not having DW_AT_name and having DW_AT_linkage_name instead should be fine. Currently GDB is invalidating any function not havnig DW_AT_name which is why it is not able to debug OpenMP (Clang). It should be fair to fallback to check DW_AT_linkage_name in case DW_AT_name is absent.
2022-05-16gdb/testsuite: fix "continue outside of loop" TCL errorsBruno Larsen13-14/+14
Many test cases had a few lines in the beginning that look like: if { condition } { continue } Where conditions varied, but were mostly in the form of ![runto_main] or [skip_*_tests], making it quite clear that this code block was supposed to finish the test if it entered the code block. This generates TCL errors, as most of these tests are not inside loops. All cases on which this was an obvious mistake are changed in this patch.
2022-05-08[gdb/testsuite] Fix gdb.threads/fork-plus-threads.exp with check-readmoreTom de Vries1-11/+7
When running test-case gdb.threads/fork-plus-threads.exp with check-readmore, I run into: ... [Inferior 11 (process 7029) exited normally]^M [Inferior 1 (process 6956) exited normally]^M FAIL: gdb.threads/fork-plus-threads.exp: detach-on-fork=off: \ inferior 1 exited (timeout) ... The problem is that the regexp consuming the "Inferior exited normally" messages: - consumes more than one of those messages at a time, but - counts only one of those messages. Fix this by adopting a line-by-line approach, which deals with those messages one at a time. Tested on x86_64-linux with native, check-read1 and check-readmore.
2022-05-03Fix gdb.threads/access-mem-running-thread-exit.exp w/ native-extended-gdbserverPedro Alves1-1/+29
When testing gdb.threads/access-mem-running-thread-exit.exp with --target_board=native-extended-gdbserver, we get: Running gdb.threads/access-mem-running-thread-exit.exp ... FAIL: gdb.threads/access-mem-running-thread-exit.exp: non-stop: second inferior: runto: run to main WARNING: Timed out waiting for EOF in server after monitor exit === gdb Summary === # of expected passes 3 # of unexpected failures 1 # of unsupported tests 1 The problem is that the testcase spawns a second inferior with -no-connection, and then runto_main does "run", which fails like so: (gdb) run Don't know how to run. Try "help target". (gdb) FAIL: gdb.threads/access-mem-running-thread-exit.exp: non-stop: second inferior: runto: run to main That "run" above failed because native-extended-gdbserver forces "set auto-connect-native-target off", to prevent testcases from mistakenly running programs with the native target, which would exactly be the case here. Fix this by letting the second inferior share the first inferior's connection everywhere except on targets that do reload on run (e.g., --target_board=native-gdbserver). Change-Id: Ib57105a238cbc69c57220e71261219fa55d329ed
2022-04-22gdb: prune inferiors at end of fetch_inferior_event, fix intermittent ↵Simon Marchi1-2/+31
failure of gdb.threads/fork-plus-threads.exp This test sometimes fail like this: info threads^M Id Target Id Frame ^M 11.12 process 2270719 Couldn't get registers: No such process.^M (gdb) FAIL: gdb.threads/fork-plus-threads.exp: detach-on-fork=off: no threads left [Inferior 11 (process 2270719) exited normally]^M info inferiors^M Num Description Connection Executable ^M * 1 <null> /home/smarchi/build/binutils-gdb/gdb/testsuite/outputs/gdb.threads/fork-plus-threads/fork-plus-threads ^M 11 <null> /home/smarchi/build/binutils-gdb/gdb/testsuite/outputs/gdb.threads/fork-plus-threads/fork-plus-threads ^M (gdb) FAIL: gdb.threads/fork-plus-threads.exp: detach-on-fork=off: only inferior 1 left (the program exited) I can get it to fail quite reliably by pinning it to a core: $ taskset -c 5 make check TESTS="gdb.threads/fork-plus-threads.exp" The previous attempt at fixing this was: https://sourceware.org/pipermail/gdb-patches/2021-October/182846.html What we see is part due to a possible unfortunate ordering of events given by the kernel, and what could be considered a bug in GDB. The test program makes a number of forks, waits them all, then exits. Most of the time, GDB will get and process the exit event for inferior 1 after the exit events of all the children. But this is not guaranteed. After the last child exits and is waited by the parent, the parent can exit quickly, such that GDB collects from the kernel the exit events for the parent and that child at the same time. It then chooses one event at random, which can be the event for the parent. This will result in the parent appearing to exit before its child. There's not much we can do about it, so I think we have to adjust the test to cope. After expect has seen the "exited normally" notification for inferior 1, it immediately does an "info thread" that it expects to come back empty. But at this point, GDB might not have processed inferior 11's (the last child) exit event, so it will look like there is still a thread. Of course that thread is dead, we just don't know it yet. But that makes the "no thread" test fail. If the test waited just a bit more for the "exited normally" notification for inferior 11, then the list of threads would be empty. So, first change, make the test collect all the "exited normally" notifications for all inferiors before proceeding, that should ensure we see an empty thread list. That would fix the first FAIL above. However, we would still have the second FAIL, as we expect inferior 11 to not be there, it should have been deleted automatically. Inferior 11 is normally deleted when prune_inferiors is called. That is called by normal_stop, which is only called by fetch_inferior_event only if the event thread completed an execution command FSM (thread_fsm). But the FSM for the continue command completed when inferior 1 exited. At that point inferior 11 was not prunable, as it still had a thread. When inferior 11 exits, prune_inferiors is not called. I think that can be considered a GDB bug. From the user point of view, there's no reason why in one case inferior 11 would be deleted and not in the other case. This patch makes the somewhat naive change to call prune_inferiors in fetch_inferior_event, so that it is called in this case. It is placed at this particular point in the function so that it is called after the user inferior / thread selection is restored. If it was called before that, inferior 11 wouldn't be pruned, because it would still be the current inferior. Change-Id: I48a15d118f30b1c72c528a9f805ed4974170484a Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=26272
2022-04-18gdb/testsuite: add text_segment option to gdb_compileVignesh Balasubramanian1-2/+2
LLVM's lld linker doesn't have the "-Ttext-segment" option, but "--image-base" can be used instead. To centralize the logic of checking which option is supported, add the text_segment option to gdb_compile. Change tests that are currently using -Ttext-segment to use that new option instead. This patch fixes only compilation error, for example: Before: $ make check TESTS="gdb.base/jit-elf.exp" RUNTESTFLAGS="CC_FOR_TARGET=clang LDFLAGS_FOR_TARGET=-fuse-ld=ld" Running /home/simark/src/binutils-gdb/gdb/testsuite/gdb.base/jit-elf.exp ... gdb compile failed, clang-13: warning: -Xlinker -Ttext-segment=0x7000000: 'linker' input unused [-Wunused-command-line-argument] After: $ make check TESTS="gdb.base/jit-elf.exp" RUNTESTFLAGS="CC_FOR_TARGET=clang LDFLAGS_FOR_TARGET=-fuse-ld=ld" Running /home/simark/src/binutils-gdb/gdb/testsuite/gdb.base/jit-elf.exp ... FAIL: gdb.base/jit-elf.exp: one_jit_test-1: continue to breakpoint: break here 1 FAIL: gdb.base/jit-elf.exp: one_jit_test-1: continue to breakpoint: break here 2 FAIL: gdb.base/jit-elf.exp: one_jit_test-2: continue to breakpoint: break here 1 FAIL: gdb.base/jit-elf.exp: one_jit_test-2: info function ^jit_function FAIL: gdb.base/jit-elf.exp: one_jit_test-2: continue to breakpoint: break here 2 FAIL: gdb.base/jit-elf.exp: attach: one_jit_test-2: continue to breakpoint: break here 1 FAIL: gdb.base/jit-elf.exp: attach: one_jit_test-2: break here 1: attach FAIL: gdb.base/jit-elf.exp: PIE: one_jit_test-1: continue to breakpoint: break here 1 FAIL: gdb.base/jit-elf.exp: PIE: one_jit_test-1: continue to breakpoint: break here 2 === gdb Summary === # of expected passes 26 # of unexpected failures 9 Change-Id: I3678c5c9bbfc2f80671698e28a038e6b3d14e635
2022-04-04gdb: resume ongoing step after handling fork or vforkSimon Marchi2-0/+208
The test introduced by this patch would fail in this configuration, with the native-gdbserver or native-extended-gdbserver boards: FAIL: gdb.threads/next-fork-other-thread.exp: fork_func=fork: target-non-stop=auto: non-stop=off: displaced-stepping=auto: i=2: next to for loop The problem is that the step operation is forgotten when handling the fork/vfork. With "debug infrun" and "debug remote", it looks like this (some lines omitted for brevity). We do the next: [infrun] proceed: enter [infrun] proceed: addr=0xffffffffffffffff, signal=GDB_SIGNAL_DEFAULT [infrun] resume_1: step=1, signal=GDB_SIGNAL_0, trap_expected=0, current thread [4154304.4154304.0] at 0x5555555553bf [infrun] do_target_resume: resume_ptid=4154304.0.0, step=1, sig=GDB_SIGNAL_0 [remote] Sending packet: $vCont;r5555555553bf,5555555553c4:p3f63c0.3f63c0;c:p3f63c0.-1#cd [infrun] proceed: exit We then handle a fork event: [infrun] fetch_inferior_event: enter [remote] wait: enter [remote] Packet received: T05fork:p3f63ee.3f63ee;06:0100000000000000;07:b08e59f6ff7f0000;10:bf60e8f7ff7f0000;thread:p3f63c0.3f63c6;core:17; [remote] wait: exit [infrun] print_target_wait_results: target_wait (-1.0.0 [process -1], status) = [infrun] print_target_wait_results: 4154304.4154310.0 [Thread 4154304.4154310], [infrun] print_target_wait_results: status->kind = FORKED, child_ptid = 4154350.4154350.0 [infrun] handle_inferior_event: status->kind = FORKED, child_ptid = 4154350.4154350.0 [remote] Sending packet: $D;3f63ee#4b [infrun] resume_1: step=0, signal=GDB_SIGNAL_0, trap_expected=0, current thread [4154304.4154310.0] at 0x7ffff7e860bf [infrun] do_target_resume: resume_ptid=4154304.0.0, step=0, sig=GDB_SIGNAL_0 [remote] Sending packet: $vCont;c:p3f63c0.-1#73 [infrun] fetch_inferior_event: exit In the first snippet, we resume the stepping thread with the range-stepping (r) vCont command. But after handling the fork (detaching the fork child), we resumed the whole process freely. The stepping thread, which was paused by GDBserver while reporting the fork event, was therefore resumed freely, instead of confined to the addresses of the stepped line. Note that since this is a "next", it could be that we have entered a function, installed a step-resume breakpoint, and it's ok to continue freely the stepping thread, but that's not the case here. The two snippets shown above were next to each other in the logs. For the fork case, we can resume stepping right after handling the event. However, for the vfork case, where we are waiting for the external child process to exec or exit, we only resume the thread that called vfork, and keep the others stopped (see patch "gdb: fix handling of vfork by multi-threaded program" prior in this series). So we can't resume the stepping thread right now. Instead, do it after handling the vfork-done event. Change-Id: I92539c970397ce880110e039fe92b87480f816bd
2022-04-04gdb: fix handling of vfork by multi-threaded program ↵Simon Marchi2-0/+184
(follow-fork-mode=parent, detach-on-fork=on) There is a problem with how GDB handles a vfork happening in a multi-threaded program. This problem was reported to me by somebody not using vfork directly, but using system(3) in a multi-threaded program, which may be implemented using vfork. This patch only deals about the follow-fork-mode=parent, detach-on-fork=on case, because it would be too much to chew at once to fix the bugs in the other cases as well (I tried). The problem ----------- When a program vforks, the parent thread is suspended by the kernel until the child process exits or execs. Specifically, in a multi-threaded program, only the thread that called vfork is suspended, other threads keep running freely. This is documented in the vfork(2) man page ("Caveats" section). Let's suppose GDB is handling a vfork and the user's desire is to detach from the child. Before detaching the child, GDB must remove the software breakpoints inserted in the shared parent/child address space, in case there's a breakpoint in the path the child is going to take before exec'ing or exit'ing (unlikely, but possible). Otherwise the child could hit a breakpoint instruction while running outside the control of GDB, which would make it crash. GDB must also avoid re-inserting breakpoints in the parent as long as it didn't receive the "vfork done" event (that is, when the child has exited or execed): since the address space is shared with the child, that would re-insert breakpoints in the child process also. So what GDB does is: 1. Receive "vfork" event for the parent 2. Remove breakpoints from the (shared) address space and set program_space::breakpoints_not_allowed to avoid re-inserting them 3. Detach from the child thread 4. Resume the parent 5. Wait for and receive "vfork done" event for the parent 6. Clean program_space::breakpoints_not_allowed and re-insert breakpoints 7. Resume the parent Resuming the parent at step 4 is necessary in order for the kernel to report the "vfork done" event. The kernel won't report a ptrace event for a thread that is ptrace-stopped. But the theory behind this is that between steps 4 and 5, the parent won't actually do any progress even though it is ptrace-resumed, because the kernel keeps it suspended, waiting for the child to exec or exit. So it doesn't matter for that thread if breakpoints are not inserted. The problem is when the program is multi-threaded. In step 4, GDB resumes all threads of the parent. The thread that did the vfork stays suspended by the kernel, so that's fine. But other threads are running freely while breakpoints are removed, which is a problem because they could miss a breakpoint that they should have hit. The problem is present with all-stop and non-stop targets. The only difference is that with an all-stop targets, the other threads are stopped by the target when it reports the vfork event and are resumed by the target when GDB resumes the parent. With a non-stop target, the other threads are simply never stopped. The fix ------- There many combinations of settings to consider (all-stop/non-stop, target-non-stop on/off, follow-fork-mode parent/child, detach-on-fork on/off, schedule-multiple on/off), but for this patch I restrict the scope to follow-fork-mode=parent, detach-on-fork=on. That's the "default" case, where we detach the child and keep debugging the parent. I tried to fix them all, but it's just too much to do at once. The code paths and behaviors for when we don't detach the child are completely different. The guiding principle for this patch is that all threads of the vforking inferior should be stopped as long as breakpoints are removed. This is similar to handling in-line step-overs, in a way. For non-stop targets (the default on Linux native), this is what happens: - In follow_fork, we call stop_all_threads to stop all threads of the inferior - In follow_fork_inferior, we record the vfork parent thread in inferior::thread_waiting_for_vfork_done - Back in handle_inferior_event, we call keep_going, which resumes only the event thread (this is already the case, with a non-stop target). This is the thread that will be waiting for vfork-done. - When we get the vfork-done event, we go in the (new) handle_vfork_done function to restart the previously stopped threads. In the same scenario, but with an all-stop target: - In follow_fork, no need to stop all threads of the inferior, the target has stopped all threads of all its inferiors before returning the event. - In follow_fork_inferior, we record the vfork parent thread in inferior::thread_waiting_for_vfork_done. - Back in handle_inferior_event, we also call keep_going. However, we only want to resume the event thread here, not all inferior threads. In internal_resume_ptid (called by resume_1), we therefore now check whether one of the inferiors we are about to resume has thread_waiting_for_vfork_done set. If so, we only resume that thread. Note that when resuming multiple inferiors, one vforking and one not non-vforking, we could resume the vforking thread from the vforking inferior plus all threads from the non-vforking inferior. However, this is not implemented, it would require more work. - When we get the vfork-done event, the existing call to keep_going naturally resumes all threads. Testing-wise, add a test that tries to make the main thread hit a breakpoint while a secondary thread calls vfork. Without the fix, the main thread keeps going while breakpoints are removed, resulting in a missed breakpoint and the program exiting. Change-Id: I20eb78e17ca91f93c19c2b89a7e12c382ee814a1
2022-03-31gdb/linux-nat: remove check based on current_inferior in ↵Simon Marchi3-0/+195
linux_handle_extended_wait The check removed by this patch, using current_inferior, looks wrong. When debugging multiple inferiors with the Linux native target and linux_handle_extended_wait is called, there's no guarantee about which is the current inferior. The vfork-done event we receive could be for any inferior. If the vfork-done event is for a non-current inferior, we end up wrongfully ignoring it. As a result, the core never processes a TARGET_WAITKIND_VFORK_DONE event, program_space::breakpoints_not_allowed is never cleared, and breakpoints are never reinserted. However, because the Linux native target decided to ignore the event, it resumed the thread - while breakpoints out. And that's bad. The proposed fix is to remove this check. Always report vfork-done events and let infrun's logic decide if it should be ignored. We don't save much cycles by filtering the event here. Add a test that replicates the situation described above. See comments in the test for more details. Change-Id: Ibe33c1716c3602e847be6c2093120696f2286fbf