aboutsummaryrefslogtreecommitdiff
path: root/gdb/testsuite/lib
AgeCommit message (Collapse)AuthorFilesLines
10 days[gdb/testsuite] Fix trailing-text-in-parentheses duplicatesTom de Vries1-15/+22
Fix all trailing-text-in-parentheses duplicates exposed by previous patch. Tested on x86_64-linux and aarch64-linux.
10 days[gdb/testsuite] Detect trailing-text-in-parentheses duplicatesTom de Vries2-5/+39
When using a duplicate test name: ... fail foo fail foo ... we get: ... FAIL: $exp: foo FAIL: $exp: foo DUPLICATE: $exp: foo ... But when we do: ... fail foo fail "foo (timeout)" ... we get only: ... FAIL: $exp: foo FAIL: $exp: foo (timeout) ... Trailing text between parentheses prefixed with a space is interpreted as extra information, and not as part of the test name [1]. Consequently, "foo" and "foo (timeout)" do count as duplicate test names, which should have been detected. This is PR testsuite/29772. Fix this in CheckTestNames::_check_duplicates, such that we get: ... FAIL: $exp: foo FAIL: $exp: foo (timeout) DUPLICATE: $exp: foo (timeout) ... [ One note on the implementation: I used the regexp { \([^()]*\)$}. I don't know whether that covers all required cases, due to the fact that those are not unambiguousely specified. It might be possible to reverse-engineer that information by reading or running the "regression analysis tools" mentioned on the wiki page [1], but I haven't been able to. Regardless, the current regexp covers a large amount of cases, which IMO should be sufficient to be acceptable. ] Doing so shows many new duplicates in the testsuite. A significant number of those is due to using a message which is a copy of the command: ... gdb_test "print (1)" ... Fix this by handling those cases using test names "gdb-command<print (1)>" and "gdb-command<print (2)>. Fix the remaining duplicates manually (split off as follow-up patch for readability of this patch). Tested on x86_64-linux and aarch64-linux. Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=29772 [1] https://sourceware.org/gdb/wiki/GDBTestcaseCookbook#Do_not_use_.22tail_parentheses.22_on_test_messages
12 daysAdd a test for the gcore scriptAlexandra Hájková1-0/+17
It also tests the gcore script being run without its accessible terminal. This test was written by Jan Kratochvil a long time ago. I modernized the test making it use various procs from lib/gdb.exp, reorganizing it and added some comments. Modify the gcore script to make it possible to pass the --data-directory to it. This prevents a lot of these warnings: Python Exception <class 'AttributeError'>: module 'gdb' has no attribute '_handle_missing_debuginfo' Tested by using make check-all-boards. Co-Authored-By: Jan Kratochvil <jan.kratochvil@redhat.com> Reviewed-By: Eli Zaretskii <eliz@gnu.org>
13 daysgdb/testsuite: track if a caching proc calls gdb_exit or notAndrew Burgess2-74/+135
After a recent patch review I asked myself why can_spawn_for_attach exists. This proc currently does some checks, and then calls can_spawn_for_attach_1 which is an actual caching proc. The answer is that can_spawn_for_attach exists in order to call gdb_exit the first time can_spawn_for_attach is called within any test script. The reason this is useful is that can_spawn_for_attach_1 calls gdb_exit. If the user calls can_spawn_for_attach_1 directly then a problem might exist. Imagine a test written like this: gdb_start if { [can_spawn_for_attach_1] } { ... do stuff that assumes GDB is running ... } If this test is NOT the first test run, and if an earlier test calls can_spawn_for_attach_1, then when the above test is run the can_spawn_for_attach_1 call will return the cached value and gdb_exit will not be called. But, if the above test IS the first test run then can_spawn_for_attach_1 will not return the cached value, but will instead compute the cached value, a process that ends up calling gdb_exit. When can_spawn_for_attach_1 returns GDB will have exited and the test might fail if it is written assuming that GDB is running. So can_spawn_for_attach was added which ensures that we _always_ call gdb_exit the first time can_spawn_for_attach is called within a single test script, this ensures that in the above case, even if the above is not the first test script run, gdb_exit will still be called. This ensures consistent behaviour and avoids some hidden bugs in the testsuite. The split between can_spawn_for_attach and can_spawn_for_attach_1 was introduced in this commit: commit 147fe7f9fb9a89b217d11d73053f53e8edacf90f Date: Mon May 6 14:27:09 2024 +0200 [gdb/testsuite] Handle ptrace operation not permitted in can_spawn_for_attach However, I observe that can_spawn_for_attach is not the only caching proc that calls gdb_exit. Why does can_spawn_for_attach get special treatment when surely the same issue exists for any other caching proc that calls gdb_exit? I think a better solution is to move the logic from can_spawn_for_attach into cache.exp and generalise it so that it applies to all caching procs. This commit does this by: 1. When the underlying caching proc is executed we track calls to gdb_exit. If a caching proc calls gdb_exit then this information is stored in gdb_data_cache (using a ',exit' suffix), and also written to the cache file if appropriate. 2. When a cached value is returned from gdb_do_cache, if the underlying proc would have called gdb_exit, and if this is the first use of the caching proc in this test script, then we call gdb_exit. When storing the ',exit' value into the on-disk cache file, the flag value is stored on a second line. Currently every cached value only occupies a single line, and a check is added to ensure this remains true in the future. To track calls to gdb_exit I eventually settled on using TCL's trace mechanism. We already make use of this in lib/gdb.exp so I figure this is OK to use. This should be fine, so long as non of the caching procs use 'with_override' to replace gdb_exit, or do any other proc replacement to change gdb_exit, however, I think that is pretty unlikely. One issue did come up in testing, a FAIL in gdb.base/break-interp.exp, prior to this commit can_spawn_for_attach would call gdb_exit before calling the underlying caching proc. After this call we call gdb_exit after calling the caching proc. The underlying caching proc relies on gdb_exit having been called. To resolve this issue I just added a call to gdb_exit into can_spawn_for_attach. With this done can_spawn_for_attach_1 can be renamed to can_spawn_for_attach, and the existing can_spawn_for_attach can be deleted.
13 daysgdb/testsuite: restructure gdb_data_cache (lib/cache.exp)Andrew Burgess1-9/+9
In the next commit I want to add more information to gdb_data_cache (see lib/cache.exp). Specifically I want to track if the underlying function of a caching proc calls gdb_exit or not. Currently gdb_data_cache is an associative array, the keys of which are the name of the caching proc. In this commit I add a ',value' suffix to the gdb_data_cache keys. In the next commit I'll add additional entries with a different suffix. There should be no noticable changes after this commit, this is just a restructuring.
2024-07-26gdb/testsuite: fix build-id compile option when used with clangAndrew Burgess1-2/+2
It was pointed out in this message: https://inbox.sourceware.org/gdb-patches/5d7a514b-5dad-446f-a021-444ea88ecf07@redhat.com That the test gdb.base/build-id-seqno.exp I added recently was FAILing when using Clang as the compiler. The problem was that I had failed to add 'build-id' as a compile option in the call to build_executable within the test script. For GCC this is fine as build-ids are included by default. For Clang though this meant the build-id was not included and the test would fail. So I added build-id to the compiler options.... and the test still didn't pass! Now the test fails to compile and I see this error from the compiler: gdb compile failed, clang-15: warning: -Wl,--build-id: 'linker' \ input unused [-Wunused-command-line-argument] It turns out that the build-id compile option causes our gdb.exp to add the '-Wl,--build-id' option into the compiler flags, which means its used when building the object file AND during the final link. However this option is unnecessary when creating the object file and Clang warns about this, which causes the build to fail. The solution is to change gdb.exp, instead of adding the build-id flags like this: lappend new_options "additional_flags=-Wl,--build-id" we should instead add them like: lappend new_options "ldflags=-Wl,--build-id" Now the flag is only appended during the link phase and Clang is happy. The gdb.base/build-id-seqno.exp test now passes with Clang. The same problem (adding to additional_flags instead of ldflags) exists for the no-build-id compile option, so I've fixed that too. While investigating this I also spotted two test scripts, gdb.base/index-cache.exp and gdb.dwarf2/per-bfd-sharing.exp which were setting ldflag directly rather than using the build-id compile option so I've updated these two tests to use the compile option which I think is neater. I've checked that all these tests still pass with both GCC and Clang. There should be no changes in what is actually tested after this commit. Approved-By: Simon Marchi <simon.marchi@efficios.com>
2024-07-24[gdb/testsuite] Fix gdb.cp/m-static.exp on armTom de Vries1-0/+8
With test-case gdb.cp/m-static.exp on arm-linux, I get: ... (gdb) ptype test5.single_constructor^M type = class single_constructor {^M ^M public:^M single_constructor(void);^M ~single_constructor(void);^M } *(single_constructor * const)^M (gdb) FAIL: gdb.cp/m-static.exp: simple object instance, ptype constructor ... The test-case expects: - no empty line before "public:", and - no "~single_constructor(void)", but "~single_constructor()" The latter is due to commit 137c886e9a6 ("[gdb/c++] Print destructor the same for gcc and clang"). The failing test is in a part only enabled for is_aarch32_target == 1, so it looks like it was left behind. I'm assuming the same happened for the other difference. Fix this by updating the regexps to match the observed output. Tested on arm-linux. Approved-By: Andrew Burgess <aburgess@redhat.com>
2024-06-19[gdb/testsuite] Add string cat for tcl version < 8.6.2Tom de Vries1-7/+30
I noticed that we started using "string cat", which has been available since tcl version 8.6.2. Add a local implementation for use with older tcl versions. Tested on x86_64-linux. Approved-By: Andrew Burgess <aburgess@redhat.com>
2024-06-15[gdb/testsuite] Clean up lib/dg-add-core-file-count.shTom de Vries1-1/+1
Fix shellcheck warnings in script lib/dg-add-core-file-count.sh. Tested on x86_64-linux. Approved-by: Kevin Buettner <kevinb@redhat.com>
2024-06-07gdb/aarch64: Disable displaced single-step for MOPS instructionsThiago Jung Bauermann1-0/+99
The AArch64 MOPS (Memory Operation) instructions provide a standardised instruction sequence to perform a memset, memcpy or memmove. A sequence is always composed of three instructions: a prologue instruction, a main instruction and an epilogue instruction. As an illustration, here are the implementations of these memory operations in glibc 2.39: (gdb) disassemble/r Dump of assembler code for function __memset_mops: => 0x0000fffff7e8d780 <+0>: d503201f nop 0x0000fffff7e8d784 <+4>: aa0003e3 mov x3, x0 0x0000fffff7e8d788 <+8>: 19c10443 setp [x3]!, x2!, x1 0x0000fffff7e8d78c <+12>: 19c14443 setm [x3]!, x2!, x1 0x0000fffff7e8d790 <+16>: 19c18443 sete [x3]!, x2!, x1 0x0000fffff7e8d794 <+20>: d65f03c0 ret End of assembler dump. (gdb) disassemble/r Dump of assembler code for function __memcpy_mops: => 0x0000fffff7e8c580 <+0>: d503201f nop 0x0000fffff7e8c584 <+4>: aa0003e3 mov x3, x0 0x0000fffff7e8c588 <+8>: 19010443 cpyfp [x3]!, [x1]!, x2! 0x0000fffff7e8c58c <+12>: 19410443 cpyfm [x3]!, [x1]!, x2! 0x0000fffff7e8c590 <+16>: 19810443 cpyfe [x3]!, [x1]!, x2! 0x0000fffff7e8c594 <+20>: d65f03c0 ret End of assembler dump. (gdb) disassemble/r Dump of assembler code for function __memmove_mops: => 0x0000fffff7e8d180 <+0>: d503201f nop 0x0000fffff7e8d184 <+4>: aa0003e3 mov x3, x0 0x0000fffff7e8d188 <+8>: 1d010443 cpyp [x3]!, [x1]!, x2! 0x0000fffff7e8d18c <+12>: 1d410443 cpym [x3]!, [x1]!, x2! 0x0000fffff7e8d190 <+16>: 1d810443 cpye [x3]!, [x1]!, x2! 0x0000fffff7e8d194 <+20>: d65f03c0 ret End of assembler dump. The Arm Architecture Reference Manual says that "the prologue, main, and epilogue instructions are expected to be run in succession and to appear consecutively in memory". Therefore this patch disables displaced stepping on them. The testcase verifies that MOPS sequences are correctly single-stepped. PR tdep/31666 Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=31666 Approved-By: Luis Machado <luis.machado@arm.com> Tested-By: Luis Machado <luis.machado@arm.com>
2024-06-05gdb/testsuite: remove trailing \r from rust_llvm_version resultAndrew Burgess1-1/+2
I noticed that the value returned by rust_llvm_version had a trailing carriage return. I don't think this is causing any problems right now, but looking at the code I don't think this was the desired behaviour. The current code runs 'rustc --version --verbose', splits the output at each '\n' and then loops over every line looking for the line that contains the LLVM version. There are two problems here. First, at the end of each captured line we have '\r\n', so when we split the lines on '\n', each of the lines will still end with a '\r' character. Second, though we loop over the lines, when we try to compare the line contents we actually compare the unsplit full output. Luckily this still finds the match, but this renders the loop over lines redundant. This commit makes two fixes: 1. I use regsub to convert all '\r\n' sequences to '\n'; now when we split on '\n' the lines will not end in '\r'. 2. Within the loop over lines block I now check the line contents rather than the unsplit full output; now we capture a value without a trailing '\r'. There's only one test (gdb.rust/simple.exp) that uses rust_llvm_version, and it doesn't care if there's a trailing '\r' or not, so this change should make no difference there. Approved-By: Tom Tromey <tom@tromey.com>
2024-06-04gdb/testsuite: tests for debug lookup within the sysrootAndrew Burgess1-0/+13
Add tests for looking up debug information within the sysroot via both build-id and gnu_debuglink. I wanted to ensure that the gnu_debuglink test couldn't make use of build-ids, so I added the 'no-build-id' flag to gdb_compile. As these tests rely on setting the sysroot, if I'm running a dynamically linked executable, GDB will try to find all shared libraries within the sysroot. This would mean I'd have to figure out and copy all shared libraries the executable uses, certainly possible, but a bit of a pain. So instead, I've just compiled the test executable as a static binary. Now there are no shared library dependencies. I can now split the debug information out from the test binary, and place it within the sysroot. When GDB is started and the executable loaded, we can check that GDB is finding the debug information within the sysroot. Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=31804 Approved-By: Tom de Vries <tdevries@suse.de>
2024-06-04gdb/testsuite: make gdb_gnu_strip_debug consistentAndrew Burgess1-9/+16
While writing a test I realised that the default behaviour of gdb_gnu_strip_debug doesn't match its comment. The comment says that the function takes a FILENAME, and splits the file into FILENAME.stripped and FILENAME.debug, leaving FILENAME unchanged. The comment says that a .gnu_debuglink will be added to FILENAME.stripped. However, this is not true, FILENAME.stripped is created, with no debug information. FILENAME.debug is created containing the debug information. But, when adding the .gnu_debuglink we take FILENAME.stripped as the input, and then overwrite FILENAME with the output. As a result, FILENAME.stripped does not include a .gnu_debuglink, while FILENAME contains the .gnu_debuglink and no debug information! The users of gdb_gnu_strip_debug can be split into two groups, those who are using the .gnu_debuglink, these tests are all written assuming that FILENAME is updated. Then there are some tests that only rely on gdb_gnu_strip_debug's ability to split out the debug information, these tests are then going to do a lookup based on the build-id, these tests don't require the .gnu_debuglink. These tests use the FILENAME.stripped output file. This all seems too confused to me. As most uses of gdb_gnu_strip_debug assume that FILENAME is updated, I propose that we just make that the actual, advertised behaviour of this proc. So now, gdb_gnu_strip_debug will take FILENAME, and will split the debug information out into FILENAME.debug. The debug information will then be stripped from FILENAME, and by default a .gnu_debuglink will be added to FILENAME pointing to FILENAME.debug. I've updated the two tests that actually relied on FILENAME.stripped to instead just use FILENAME. One of the tests was doing a build-id based lookup, but was still allowing the .gnu_debuglink to be added to FILENAME, I've updated this test to pass the no-debuglink flag to gdb_gnu_strip_debug, which stops the .gnu_debuglink from being added. All of the tests that call gdb_gnu_strip_debug still pass for me. Acked-By: Tom de Vries <tdevries@suse.de>
2024-05-23gdb/testsuite: Restore libc_has_debug_info's less strict behaviourThiago Jung Bauermann1-11/+10
The code that was factored out from gdb.base/relativedebug.exp assumed that libc has debug info and only determined that it doesn't if it saw a specific message from GDB to that effect. In the process of factoring it into a require predicate, I made it stricter by trying to make a specific determination of whether or not debug info is available. Pedro noticed that "It'll disable the testcase on systems that link with their libc statically (even if has debug info), or systems that name their libc something else." Which is something I hadn't considered. This patch returns libc_has_debug_info to the original behaviour. Also, remove a verbose message that is redundant with the $message variable. Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=31700 Approved-By: Tom Tromey <tom@tromey.com>
2024-05-20[gdb/testsuite] Fix can_spawn_for_attach_1 consistency checkTom de Vries1-0/+7
When running test-case gdb.testsuite/gdb-caching-proc-consistency.exp with target board native-gdbserver, we run into: ... (gdb) ERROR: tcl error sourcing gdb.testsuite/gdb-caching-proc-consistency.exp. ERROR: gdbserver does not support attach 4827 without extended-remote while executing "error "gdbserver does not support $command without extended-remote"" (procedure "gdb_test_multiple" line 51) invoked from within "gdb_test_multiple "attach $test_pid" "can spawn for attach" { -re -wrap "$attaching_re\r\n.*ptrace: Operation not permitted\\." { # Not permitte..." (procedure "gdb_real__can_spawn_for_attach_1" line 27) invoked from within "gdb_real__can_spawn_for_attach_1" ... The problem is that: - can_spawn_for_attach_1 is a helper function for can_spawn_for_attach, designed to be called only from that function, and - can_spawn_for_attach_1 is a gdb_caching_proc, and consequently test-case gdb.testsuite/gdb-caching-proc-consistency.exp calls can_spawn_for_attach_1 directly. Fix this by copying the early-outs from can_spawn_for_attach to can_spawn_for_attach_1. Tested on x86_64-linux. Reported-By: Simon Marchi <simark@simark.ca> Reviewed-By: Alexandra Petlanova Hajkova <ahajkova@redhat.com>
2024-05-16[gdb/testsuite] Add missing terminator in Dwarf::_macro_unitTom de Vries1-0/+2
When printing complaints with one of the execs from test-case gdb.dwarf2/macro-source-path.exp, we run into: ... $ gdb -q -batch \ -iex "set complaints 100" \ macro-source-path-clang14-dw4-absolute-cwd-32 \ -ex "p main" During symbol reading: debug info runs off end of .debug_macro section \ [in module macro-source-path-clang14-dw4-absolute-cwd-32] $1 = {int ()} 0x4004b7 <main> ... and readelf complains more specifically: ... Contents of the .debug_macro section: Offset: 0 Version: 5 Offset size: 4 Offset into .debug_line: 0xe3 DW_MACRO_define - lineno : 0 macro : ONE 1 DW_MACRO_define_strp - lineno : 0 macro : THREE 3 DW_MACRO_start_file - lineno: 0 filenum: 1 filename: test.c DW_MACRO_define - lineno : 1 macro : TWO 2 DW_MACRO_end_file readelf: Error: .debug_macro section not zero terminated ... Fix this by adding the missing terminator in Dwarf::_macro_unit. Tested on x86_64-linux. Approved-By: Tom Tromey <tom@tromey.com>
2024-05-16gdb, testsuite: Handle unused compiler option fdiagnostics-color=never.Ijaz, Abdul B1-10/+44
The 'univeral_compile_options' in gdb.exp file only verifies the support of '-fdiagnostics-color=never' for the "C" source file. So while running tests with assembly source file (.s), many of them are not able to run on icx/clang compilers because '-fdiagnostics-color=never' option is not supported. This problem is not seen for the ".S" assembly source files so these files are not handled separately. After this change, this function is split into multiple functions to check the support for different type of sources individually. Before this change, in the case of clang and ICX compiler, this error is shown for assembly source files (.s): ''' icx -fdiagnostics-color=never -Wno-unknown-warning-option -fno-pie -c -O0 -o amd64-entry-value0.o gdb/testsuite/gdb.arch/amd64-entry-value.s (timeout = 300) icx: warning: argument unused during compilation: '-fdiagnostics-color=never' [-Wunused-command-line-argument] gdb compile failed, icx: warning: argument unused during compilation: '-fdiagnostics-color=never' [-Wunused-command-line-argument] UNTESTED: gdb.arch/amd64-entry-value.exp: failed to prepare ''' Similarly this error is shown for the clang compiler: ''' clang -fdiagnostics-color=never -Wno-unknown-warning-option -fno-pie -c -O0 -o amd64-entry-value0.o gdb/testsuite/gdb.arch/amd64-entry-value.s clang: warning: argument unused during compilation: '-fdiagnostics-color=never' [-Wunused-command-line-argument] ''' Approved-By: Tom Tromey <tom@tromey.com>
2024-05-16[gdb/testsuite] Generate DW_MACRO_define_strp in dwarf assemblyTom de Vries1-1/+27
Add support for DW_MACRO_define_strp in dwarf assembly, and use it in test-case gdb.dwarf2/macro-source-path.exp. Tested on x86_64-linux. Approved-By: Tom Tromey <tom@tromey.com>
2024-05-07gdb/testsuite/lib/rocm: Fix with_rocm_gpu_lockLancelot SIX1-1/+1
A recent commit refactored with_rocm_gpu_lock: commit fbb0edfe60edf4ca01884151e6d9b1353aaa0a7e Date: Sat May 4 10:41:09 2024 +0200 [gdb/testsuite] Factor out proc with_lock Factor out proc with_lock from with_rocm_gpu_lock, and move required procs lock_file_acquire and lock_file_release to lib/gdb-utils.exp. This causes regressions in gdb.rocm/*.exp (as well as in downstream rocgdb). The issue can be reproduced in the following minimal test: load_lib rocm.exp set foo hello with_rocm_gpu_lock { verbose -logs $foo } The issue is that the body to execute under the lock is executed in the context of with_rocm_gpu_lock (uplevel 1 used in with_lock) instead of in the context of the "original" caller. This patch adjusted with_rocm_gpu_lock to account for the new extra frame in the call stack between the caller of with_rocm_gpu_lock and where the code execution is triggered. Approved-By: Tom de Vries <tdevries@suse.de> Change-Id: I79ce2c9615012215867ed5bb60144abe7dce28fe
2024-05-06[gdb/testsuite] Handle ptrace operation not permitted in can_spawn_for_attachTom de Vries1-14/+98
When running the testsuite on a system with kernel.yama.ptrace_scope set to 1, we run into attach failures. Fix this by recognizing "ptrace: Operation not permitted" in can_spawn_for_attach. Tested on aarch64-linux and x86_64-linux. Approved-By: Pedro Alves <pedro@palves.net>
2024-05-04[gdb/testsuite] Use unique portnum in parallel testing (check//% case)Tom de Vries1-0/+5
Make target check//% is the gdb variant of a similar gcc make target [1]. When running tests using check//%: ... $ cd build/gdb $ make check//unix/{-fPIE/-pie,-fno-PIE/-no-pie} -j2 TESTS=gdb.server/*.exp ... we get: ... $ cat build/gdb/testsuite.unix.-fPIE.-pie/cache/portnum 2427 $ cat build/gdb/testsuite.unix.-fno-PIE.-no-pie/cache/portnum 2423 ... The problem is that there are two portnum files used in parallel. Fix this by: - creating a common lockdir build/gdb/testsuite.lockdir for make target check//%, - passing this down to the runtests invocations using variable GDB_LOCK_DIR, and - using GDB_LOCK_DIR in lock_dir. Tested on aarch64-linux. Approved-By: Tom Tromey <tom@tromey.com> PR testsuite/31632 Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=31632 [1] https://gcc.gnu.org/install/test.html
2024-05-04[gdb/testsuite] Use unique portnum in parallel testingTom de Vries1-9/+38
When instrumenting get_portnum using: ... puts "PORTNUM: $res" ... and running: ... $ cd build/gdb $ make check-parallel -j2 TESTS=gdb.server/*.exp ... we run into: ... Running gdb.server/abspath.exp ... PORTNUM: 2345 ... and: ... Running gdb.server/bkpt-other-inferior.exp ... PORTNUM: 2345 ... This is because the test-cases are run in independent runtest invocations. Fix this by handling the parallel case in get_portnum using: - a file $objdir/cache/portnum to keep the portnum variable, and - a file $objdir/cache/portnum.lock to serialize access to it. Tested on aarch64-linux. Approved-By: Tom Tromey <tom@tromey.com>
2024-05-04[gdb/testsuite] Move gpu-parallel.lock to cache dirTom de Vries1-1/+1
The lock directory returned by lock_dir is currently $objdir. It seems possible to leave a stale lock file that blocks progress in a following run. Fix this by using a directory that is guaranteed to be initially empty when using GDB_PARALLEL, like temp or cache. In gdb/testsuite/README I found: ... cache in particular is used to share data across invocations of runtest ... which seems appropriate, so let's use cache for this. Tested on aarch64-linux. Approved-By: Tom Tromey <tom@tromey.com>
2024-05-04[gdb/testsuite] Factor out proc lock_dirTom de Vries2-1/+8
In lib/rocm.exp we have: ... set gpu_lock_filename $objdir/gpu-parallel.lock ... This decides both the lock file name and directory. Factor out a new proc lock_dir that decides on the directory, leaving just: ... set gpu_lock_filename gpu-parallel.lock ... Tested on aarch64-linux. Approved-By: Tom Tromey <tom@tromey.com>
2024-05-04[gdb/testsuite] Factor out proc with_lockTom de Vries2-54/+60
Factor out proc with_lock from with_rocm_gpu_lock, and move required procs lock_file_acquire and lock_file_release to lib/gdb-utils.exp. Tested on aarch64-linux. Approved-By: Tom Tromey <tom@tromey.com>
2024-05-04[gdb/testsuite] Make portnum a persistent globalTom de Vries1-1/+1
When instrumenting get_portnum using: ... puts "PORTNUM: $res" ... and running: ... $ cd build/gdb $ make check TESTS=gdb.server/*.exp ... we get: ... Running gdb.server/target-exec-file.exp ... PORTNUM: 2345 Running gdb.server/stop-reply-no-thread-multi.exp ... PORTNUM: 2345 PORTNUM: 2346 PORTNUM: 2347 PORTNUM: 2348 PORTNUM: 2349 PORTNUM: 2350 ... So, while get_portnum does return increasing numbers in a single test-case, it restarts at each test-case. This is a regression since the introduction of persistent globals. Fix this by using "gdb_persistent_global portnum", such that we get: ... Running gdb.server/target-exec-file.exp ... PORTNUM: 2345 Running gdb.server/stop-reply-no-thread-multi.exp ... PORTNUM: 2346 PORTNUM: 2347 PORTNUM: 2348 PORTNUM: 2349 PORTNUM: 2350 PORTNUM: 2351 ... Tested on aarch64-linux. Approved-By: Tom Tromey <tom@tromey.com>
2024-05-04[gdb/testsuite] Factor out proc get_portnumTom de Vries1-11/+29
In gdbserver_start, we have some code that determines what port number to use: ... # Port id -- either specified in baseboard file, or managed here. if [target_info exists gdb,socketport] { set portnum [target_info gdb,socketport] } else { # Bump the port number to avoid conflicts with hung ports. incr portnum } ... Factor this out into a new proc get_portnum. Tested on aarch64-linux. Approved-By: Tom Tromey <tom@tromey.com>
2024-05-03Adjust gdb_continue_to_end for WindowsPedro Alves1-0/+15
On Cygwin, supposely single-threaded programs are always multi-threaded, due to the extra threads spawned by the Cygwin runtime. Because of that, any gdb_continue_to_end call that doesn't specify "allow_extra" fails, like so: (gdb) PASS: gdb.base/langs.exp: show language at main continue Continuing. [Thread 16140.0x1fbc exited with code 0] [Thread 16140.0x2458 exited with code 0] [Thread 16140.0x3494 exited with code 0] [Inferior 1 (process 16140) exited normally] (gdb) FAIL: gdb.base/langs.exp: continue until exit at first session (the program exited) Similarly, with this simple program compiled with MinGW: $ cat ~/sleeper.c #include <windows.h> int main () { Sleep (2000); return 0; } and with a MinGW GDB, I see: (gdb) start ... (gdb) info threads Id Target Id Frame * 1 Thread 15292.0x3850 main () at /home/alves/sleeper.c:5 2 Thread 15292.0x3048 0x00007ff9630d2fb7 in ntdll!ZwWaitForWorkViaWorkerFactory () from C:\Windows\SYSTEM32\ntdll.dll (gdb) c Continuing. [Thread 15292.0x3850 exited with code 0] [Inferior 1 (process 15292) exited normally] (gdb) This commit adjusts gdb_continue_to_end to expect the thread exited messages, on Cygwin and MinGW. Change-Id: I5e410a7252c11cd9ecea632f1e00c2a7fcd69098 Approved-By: Andrew Burgess <aburgess@redhat.com>
2024-05-03[gdb/testsuite] Use save_vars to restore GDBFLAGSTom de Vries1-8/+6
There's a pattern of using: ... set saved_gdbflags $GDBFLAGS set GDBFLAGS "$GDBFLAGS ..." <do something with GDBFLAGS> set GDBFLAGS $saved_gdbflags ... Simplify this by using save_vars: ... save_vars { GDBFLAGS } { set GDBFLAGS "$GDBFLAGS ..." <do something with GDBFLAGS> } ... Tested on x86_64-linux.
2024-05-03[gdb/testsuite] Remove superfluous -quiet and -ex set width/height 0Tom de Vries1-2/+2
INTERNAL_GDBFLAGS contains: - -quiet - -iex "set width 0" - -iex "set height 0" There are test-cases that add these once more. Clean this up. Tested on x86_64-linux. PR testsuite/31649 Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=31649
2024-05-01[gdb/testsuite] Fix stray file in get_compiler_infoTom de Vries1-1/+1
When running test-case gdb.dwarf2/gdb-index-nodebug.exp with host board local-remote-host and target board remote-gdbserver-on-localhost, I get: ... $ ls build/gdb/testsuite cache compiler.i config.log config.status gdb.log gdb.sum lib Makefile outputs site.bak site.exp temp ... The file compiler.i is there because get_compiler_info uses: ... set ppout "$outdir/compiler.i" ... The file is a temporary, and as such belongs in a temp dir. Fix this by using standard_temp_file, moving the file to build/gdb/testsuite/temp/<pid>/compiler.i. Tested on x86_64-linux.
2024-04-26Eliminate gdb_is_target_remote / gdb_is_target_native & friendsPedro Alves2-77/+0
After the previous patches, gdb_is_target_remote, gdb_is_target_native, and mi_is_target_remote aren't used anywhere. This commit eliminates them, along with now unnecessary helpers. Change-Id: I54f9ae1f5aed3f640e5758731cf4954e6dbb1bee Approved-By: Tom Tromey <tom@tromey.com>
2024-04-26gdb_is_target_remote -> gdb_protocol_is_remotePedro Alves1-1/+10
This is similar to the previous patch, but for gdb_protocol_is_remote. gdb_is_target_remote and its MI cousin mi_is_target_remote, use "maint print target-stack", which is unnecessary when checking whether gdb_protocol is "remote" or "extended-remote" would do. Checking gdb_protocol is more efficient, and can be done before starting GDB and running to main, unlike gdb_is_target_remote/mi_is_target_remote. This adds a new gdb_protocol_is_remote procedure, and uses it in place of gdb_is_target_remote/mi_is_target_remote throughout. There are no uses of gdb_is_target_remote/mi_is_target_remote left after this. Those will be eliminated in a following patch. In some spots, we no longer need to defer the check until after starting GDB, so the patch adjusts accordingly. Change-Id: I90267c132f942f63426f46dbca0b77dbfdf9d2ef Approved-By: Tom Tromey <tom@tromey.com>
2024-04-26gdb_is_target_native -> gdb_protocol_is_nativePedro Alves1-0/+15
gdb_is_target_native uses "maint print target-stack", which is unnecessary when checking whether gdb_protocol is empty would do. Checking gdb_protocol is more efficient, and can be done before starting GDB and running to main, unlike gdb_is_target_native. This adds a new gdb_protocol_is_native procedure, and uses it in place of gdb_is_target_native. At first, I thought that we'd end up with a few testcases needing to use gdb_is_target_native still, especially multi-target tests that connect to targets different from the default board target, but no, actually all uses of gdb_is_target_native could be converted. gdb_is_target_native will be eliminated in a following patch. In some spots, we no longer need to defer the check until after starting GDB, so the patch adjusts accordingly. Change-Id: Ia706232dbffac70f9d9740bcb89c609dbee5cee3 Approved-By: Tom Tromey <tom@tromey.com>
2024-04-24gdb/testsuite: Add libc_has_debug_info require helperThiago Jung Bauermann1-0/+56
Factor the test for libc debug info out of gdb.base/relativedebug.exp to a new procedure. Also, change the "info sharedlibrary" test to explicitly detect when libc has debug info. Approved-by: Kevin Buettner <kevinb@redhat.com>
2024-04-24Handle two-linetable function in find_epilogue_using_linetableBernd Edlinger1-2/+3
Consider the following test-case: ... $ cat hello.c int main() { printf("hello "); #include "world.inc" $ cat world.inc printf("world\n"); return 0; } $ gcc -g hello.c ... The line table for the compilation unit, consisting just of function main, is translated into these two gdb line tables, one for hello.c and one for world.inc: ... compunit_symtab: hello.c symtab: hello.c INDEX LINE REL-ADDRESS UNREL-ADDRESS IS-STMT PROLOGUE-END EPILOGUE-BEGIN 0 3 0x400557 0x400557 Y 1 4 0x40055b 0x40055b Y 2 END 0x40056a 0x40056a Y compunit_symtab: hello.c symtab: world.inc INDEX LINE REL-ADDRESS UNREL-ADDRESS IS-STMT PROLOGUE-END EPILOGUE-BEGIN 0 1 0x40056a 0x40056a Y 1 2 0x400574 0x400574 Y 2 3 0x400579 0x400579 Y 3 END 0x40057b 0x40057b Y ... The epilogue of main starts at 0x400579: ... 400579: 5d pop %rbp 40057a: c3 ret ... Now, say we have an epilogue_begin marker in the line table at 0x400579. We won't find it using find_epilogue_using_linetable, because it does: ... const struct symtab_and_line sal = find_pc_line (start_pc, 0); ... which gets us the line table for hello.c. Fix this by using "find_pc_line (end_pc - 1, 0)" instead. Tested on x86_64-linux. Co-Authored-By: Tom de Vries <tdevries@suse.de> PR symtab/31622 Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=31622
2024-04-22gdb/testsuite: Use default gdb_expect timeout in runtoThiago Jung Bauermann1-1/+1
runto uses a hard-coded timeout of 30s in its invocation of gdb_expect. This is normally fine, but for very a slow system (e.g., an emulator) it may not be enough time for GDB to reach the intended breakpoint. gdb_expect can obtain a timeout value from user-configurable variables when it's not given one explicitly, so use that mechanism instead since the user will have already adjusted the timeout variable to account for the slow system. Approved-By: Tom Tromey <tom@tromey.com>
2024-04-18[gdb/testsuite] Use find_gnatmake instead of gdb_find_gnatmakeTom de Vries2-1/+16
On SLE-11, with an older dejagnu version, I ran into: ... Running gdb.ada/mi_prot.exp ... UNRESOLVED: gdb.ada/mi_prot.exp: \ testcase aborted due to invalid command name: gdb_find_gnatmake ERROR: tcl error sourcing gdb.ada/mi_prot.exp. ERROR: invalid command name "gdb_find_gnatmake" while executing "::gdb_tcl_unknown gdb_find_gnatmake" ("uplevel" body line 1) invoked from within "uplevel 1 ::gdb_tcl_unknown $args" (procedure "::unknown" line 5) invoked from within "gdb_find_gnatmake" (procedure "gnatmake_version_at_least" line 2) invoked from within ... Proc gdb_find_gnatmake is actually a backup for find_gnatmake: ... if {[info procs find_gnatmake] == ""} { rename gdb_find_gnatmake find_gnatmake ... so gnatmake_version_at_least should use find_gnatmake instead. For a recent dejagnu with find_gnatmake, gdb_find_gnatmake is kept, and we don't run into this error. For an older dejagnu without find_gnatmake, gdb_find_gnatmake is renamed to find_gnatmake, and we do run into the error. It's confusing that we're using the gdb_ prefix for gdb_find_gnatmake, it seems something legitimate to use. Maybe we should use future_ or gdb_future_ prefix instead to make this more clear, but I've left that alone for now. Fix this by: - triggering the same error with a recent dejagnu by removing gdb_find_gnatmake unless used (and likewise for other procs in future.exp), and - using find_gnatmake in gnatmake_version_at_least. Tested on x86_64-linux. Approved-By: Tom Tromey <tom@tromey.com> PR testsuite/31647 Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=31647
2024-04-18[gdb/testsuite] Use allocator_may_return_null=1 in two test-casesTom de Vries1-3/+15
Simon reported [1] that recent commit 06e967dbc9b ("[gdb/python] Throw MemoryError in inferior.read_memory if malloc fails") introduced AddressSanitizer allocation-size-too-big errors in the two test-cases affected by this commit. Fix this by suppressing the error in the two test-cases using allocator_may_return_null=1. Tested on aarch64-linux. Approved-By: Tom Tromey <tom@tromey.com> [1] https://sourceware.org/pipermail/gdb-patches/2024-April/208171.html
2024-04-18Add DW_TAG_compile_unit DIE to Dummy CUsWill Hawkins1-0/+1
Dummy CUs help detect errors and are very helpful. However, the DWARF spec seems to indicate the CUs need a DW_TAG_compile_unit in addition to the header. This patch adds that. Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=31650 Signed-off-by: Will Hawkins <hawkinsw@obs.cr> Approved-By: Tom de Vries <tdevries@suse.de> Tested-By: Tom de Vries <tdevries@suse.de>
2024-04-17[gdb/testsuite] Require DW_LNE_end_sequenceTom de Vries1-0/+26
The dwarf standard requires that every line number program sequence ends with a DW_LNE_end_sequence instruction. Enforce this in the dwarf assembler for the last sequence in a line number program (we have no means to enforce this for earlier sequences), and fix a few test-case that don't have it. Tested on aarch64-linux. PR testsuite/31618 Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=31618
2024-04-17[gdb/testsuite] Require address update for DW_LNS_copyTom de Vries1-0/+3
No address update before a DW_LNS_copy might mean an incorrect dwarf assembly test-case. Try to catch such incorrect dwarf assembly test-cases by: - requiring an explicit address update for each DW_LNS_copy, and - handling the cases where an update is indeed not needed, by adding "DW_LNS_advance_pc 0". Tested on aarch64-linux.
2024-04-17[gdb/testsuite] Require address update for DW_LNE_end_sequenceTom de Vries1-0/+13
With test-case gdb.dwarf2/dw2-epilogue-begin.exp, we have an end_sequence entry with the same address as the line entry before it: ... File name Line number Starting address View Stmt dw2-epilogue-begin.c 44 0x4101e8 x dw2-epilogue-begin.c 47 0x4101ec x dw2-epilogue-begin.c - 0x4101ec ... and consequently the line entry is removed by gdb: ... INDEX LINE REL-ADDRESS UNREL-ADDRESS IS-STMT PRO EPI 0 20 0x00000000004101a8 0x00000000004101a8 Y Y Y 1 27 0x00000000004101b0 0x00000000004101b0 Y 2 32 0x00000000004101b8 0x00000000004101b8 Y Y 3 34 0x00000000004101c0 0x00000000004101c0 Y Y 4 35 0x00000000004101c8 0x00000000004101c8 Y 5 40 0x00000000004101d4 0x00000000004101d4 Y Y 6 44 0x00000000004101e8 0x00000000004101e8 Y 7 END 0x00000000004101ec 0x00000000004101ec Y ... This is a common mistake in dwarf assembly test-cases. Fix this by: - requiring an address update for each DW_LNE_end_sequence, and - fixing the test-cases where that triggers an error. I also encountered the error in test-case gdb.dwarf2/dw2-bad-elf.exp, and in this case I worked around it using "DW_LNS_advance_pc 0". Tested on aarch64-linux. PR testsuite/31592 Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=31592
2024-03-26[gdb/testsuite] Fix valgrind tests on debianTom de Vries1-1/+2
On debian 12, I run into: ... (gdb) target remote | vgdb --wait=2 --max-invoke-ms=2500 --pid=618591^M Remote debugging using | vgdb --wait=2 --max-invoke-ms=2500 --pid=618591^M relaying data between gdb and process 618591^M warning: remote target does not support file transfer, \ attempting to access files from local filesystem.^M Reading symbols from /lib/ld-linux-aarch64.so.1...^M (No debugging symbols found in /lib/ld-linux-aarch64.so.1)^M 0x000000000401a980 in ?? () from /lib/ld-linux-aarch64.so.1^M (gdb) FAIL: gdb.base/valgrind-infcall.exp: target remote for vgdb ... The problem is that we're expecting to match either of these regexps: ... set start_re1 " in \\.?_start " set start_re2 "\\.?_start \\(\\) at " ... but there are no dwarf or elf symbols present. Fix this by also allowing: ... set start_re3 "$::hex in \\?\\? \\(\\) from " ... Tested on aarch64-linux. Approved-By: Tom Tromey <tom@tromey.com>
2024-03-25gdb/testsuite: Fix set_unbuffered_mode.o handling in parallel modePedro Alves1-2/+19
Cygwin/MinGW testing links in a set_unbuffered_mode.o object to all test programs. When running the testsuite in parallel mode, on Cygwin, I noticed errors like: ERROR: remote_download to host of ..../build/set_unbuffered_mode.o to ..../build/set_unbuffered_mode_saved.o: cp: cannot open '..../build/set_unbuffered_mode.o' for reading: No such file or directory ... ERROR: remote_download to host of ..../build/set_unbuffered_mode.o to ..../build/set_unbuffered_mode_saved.o: cp: cannot stat '..../build/set_unbuffered_mode.o': No such file or directory ... ERROR: remote_download to host of ..../build/set_unbuffered_mode.o to ..../build/set_unbuffered_mode_saved.o: cp: skipping file '..../build/set_unbuffered_mode.o', as it was replaced while being copied (Absolute paths elided above.) The problem is that gdb_compile's unbuffered_mode_obj cache isn't parallel safe. This is fixed in this commit. Reviewed-by: Kevin Buettner <kevinb@redhat.com> Change-Id: I67a289473c14ce0603d4b0beb755b124588f18d2
2024-03-22gdb tests: Allow for "LWP" or "process" in thread IDs from info threadsJohn Baldwin1-0/+4
Several tests assume that the first word after a thread ID in 'info threads' output is "Thread". However, several targets use "LWP" instead such as the FreeBSD and NetBSD native targets. The Linux native target also uses "LWP" if libthread_db is not being used. Targets that do not support threads use "process" as the first word via normal_pid_to_str. Add a tdlabel_re global variable as a regular-expression for a thread label in `info threads' that matches either "process", "Thread", or "LWP". Some other tests in the tree don't require a specific word, and some targets may use other first words (e.g. OpenBSD uses "thread" and Ravenscar threads use "Ravenscar Thread").
2024-03-20[gdb/testsuite] Fix gdb.server/server-connect.exp for missing ipv6Tom de Vries1-0/+3
On a system without ipv6 support enabled, when running test-case gdb.server/server-connect.exp, it takes about 4 minutes, and I get: ... builtin_spawn gdbserver --once ::1:2347 server-connect^M Can't open socket: Address family not supported by protocol.^M Exiting^M PASS: gdb.server/server-connect.exp: tcp6: start gdbserver target remote tcp6:::1:2347^M A program is being debugged already. Kill it? (y or n) y^M could not connect: Address family not supported by protocol.^M (gdb) FAIL: gdb.server/server-connect.exp: tcp6: connect to gdbserver using tcp6:::1 ... Fix this by: - recognizing the error message in gdbserver_start, and returning an empty list to signal unsupported, and - handling the unsupported response in the test-case. This brings testing time down to 2 seconds, and gets me: ... UNSUPPORTED: gdb.server/server-connect.exp: tcp6: start gdbserver UNSUPPORTED: gdb.server/server-connect.exp: tcp6-with-brackets: start gdbserver UNSUPPORTED: gdb.server/server-connect.exp: udp6: start gdbserver UNSUPPORTED: gdb.server/server-connect.exp: udp6-with-brackets: start gdbserver ... Tested on aarch64-linux. Approved-By: Tom Tromey <tom@tromey.com> PR testsuite/31502 Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=31502
2024-03-20[gdb/testsuite] Add PR gdb/26967 KFAIL in two more test-casesTom de Vries1-0/+19
On aarch64-linux (debian 12), when running test-case gdb.base/longjmp-until-in-main.exp, I run into: ... (gdb) until 33^M warning: Breakpoint address adjusted from 0x70f727c678928489 to 0xfff727c678928489.^M Warning:^M Cannot insert breakpoint 0.^M Cannot access memory at address 0xfff727c678928489^M ^M 0x0000fffff7e3a580 in siglongjmp () from /lib/aarch64-linux-gnu/libc.so.6^M (gdb) FAIL: gdb.base/longjmp-until-in-main.exp: until $line, in main ... This is PR gdb/26967: no longjmp probe is available: ... (gdb) info probes stap libc ^longjmp$^M No probes matched.^M ... and glibc applies pointer mangling which makes it fairly difficult for gdb to get the longjmp target. There's a KFAIL for this in test-case gdb.base/longjmp.exp, added in commit b5e7cd5cd3d ("[gdb/testsuite] Add KFAILs in gdb.base/longjmp.exp"). Factor out new proc have_longjmp_probe, and use it to add similar KFAIL in this and one more test-case. Tested on aarch64-linux. Approved-By: Tom Tromey <tom@tromey.com>
2024-03-18Clear board_info entry after waiting for processTom Tromey2-0/+16
When certain DAP tests are run in a certain order, dejagnu will throw an exception during shutdown. After adding many logging statements, I tracked this down to kill_wait_spawned_process not clearing the 'fileid' board_info entry, causing dejagnu to try to wait for the process a second time -- and fail. Tom de Vries then pointed out a second instance of this, which I tracked down to the same problem occurring when spawning gdbserver. This version of the patch fixes this by adding a new proc that can be used to clean up board_info after waiting for a process to exit. I'm not sure why this problem hasn't affected the test suite in the past. Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=31435 Approved-By: Andrew Burgess <aburgess@redhat.com>
2024-02-27Explicitly quit gdb from DAP server threadTom Tromey1-0/+9
This changes the DAP code to explicitly request that gdb exit. Previously this could cause crashes, but with the previous cleanups, this should no longer happen. This also adds a tests that ensures that gdb exits with status 0.