aboutsummaryrefslogtreecommitdiff
path: root/gdb/testsuite
AgeCommit message (Collapse)AuthorFilesLines
2023-09-29Support the NO_COLOR environment variableTom Tromey14-47/+49
I ran across this site: https://no-color.org/ ... which lobbies for tools to recognize the NO_COLOR environment variable and disable any terminal styling when it is seen. This patch implements this for gdb. Regression tested on x86-64 Fedora 38. Co-Authored-By: Andrew Burgess <aburgess@redhat.com> Reviewed-by: Kevin Buettner <kevinb@redhat.com> Reviewed-By: Eli Zaretskii <eliz@gnu.org> Approved-By: Andrew Burgess <aburgess@redhat.com>
2023-09-28gdb/testsuite: Add relative versus absolute LD_LIBRARY_PATH testKevin Buettner3-0/+145
At one time, circa 2006, there was a bug, which was presumably fixed without adding a test case: If you provided some relative path to the shared library, such as with export LD_LIBRARY_PATH=. then gdb would fail to match the shared library name during the TLS lookup. I think there may have been a bit more to it than is provided by that explanation, since the test also takes care to split the debug info into a separate file. In any case, this commit is based on one of Red Hat's really old local patches. I've attempted to update it and remove a fair amount of cruft, hopefully without losing any critical elements from the test. Testing on Fedora 38 (correctly) shows 1 unsupported test for native-gdbserver and 5 PASSes for the native target as well as native-extended-gdbserver. In his review of v1 of this patch, Lancelot SIX observed that 'thread_local' could be used in place of '__thread' in the C source files. But it only became available via the standard in C11, so I used additional_flags=-std=c11 for compiling both the shared object and the main program. Also, while testing with CC_FOR_TARGET=clang, I found that 'additional_flags=-Wl,-soname=${binsharedbase}' caused clang to complain that this linker flag was unused when compiling the source file, so I moved this linker option to 'ldflags='. My testing for this v2 patch shows the same results as with v1, but I've done additional testing with CC_FOR_TARGET=clang as well. The results are the same as when gcc is used. Co-Authored-by: Jan Kratochvil <jan@jankratochvil.net> Reviewed-By: Lancelot Six <lancelot.six@amd.com>
2023-09-28gdb: use reopen_exec_file from reread_symbolsAndrew Burgess1-5/+0
This commit fixes an issue that was discovered while writing the tests for the previous commit. I noticed that, when GDB restarts an inferior, the executable_changed event would trigger twice. The first notification would originate from: #0 exec_file_attach (filename=0x4046680 "/tmp/hello.x", from_tty=0) at ../../src/gdb/exec.c:513 #1 0x00000000006f3adb in reopen_exec_file () at ../../src/gdb/corefile.c:122 #2 0x0000000000e6a3f2 in generic_mourn_inferior () at ../../src/gdb/target.c:3682 #3 0x0000000000995121 in inf_child_target::mourn_inferior (this=0x2fe95c0 <the_amd64_linux_nat_target>) at ../../src/gdb/inf-child.c:192 #4 0x0000000000995cff in inf_ptrace_target::mourn_inferior (this=0x2fe95c0 <the_amd64_linux_nat_target>) at ../../src/gdb/inf-ptrace.c:125 #5 0x0000000000a32472 in linux_nat_target::mourn_inferior (this=0x2fe95c0 <the_amd64_linux_nat_target>) at ../../src/gdb/linux-nat.c:3609 #6 0x0000000000e68a40 in target_mourn_inferior (ptid=...) at ../../src/gdb/target.c:2761 #7 0x0000000000a323ec in linux_nat_target::kill (this=0x2fe95c0 <the_amd64_linux_nat_target>) at ../../src/gdb/linux-nat.c:3593 #8 0x0000000000e64d1c in target_kill () at ../../src/gdb/target.c:924 #9 0x00000000009a19bc in kill_if_already_running (from_tty=1) at ../../src/gdb/infcmd.c:328 #10 0x00000000009a1a6f in run_command_1 (args=0x0, from_tty=1, run_how=RUN_STOP_AT_MAIN) at ../../src/gdb/infcmd.c:381 #11 0x00000000009a20a5 in start_command (args=0x0, from_tty=1) at ../../src/gdb/infcmd.c:527 #12 0x000000000068dc5d in do_simple_func (args=0x0, from_tty=1, c=0x35c7200) at ../../src/gdb/cli/cli-decode.c:95 While the second originates from: #0 exec_file_attach (filename=0x3d7a1d0 "/tmp/hello.x", from_tty=0) at ../../src/gdb/exec.c:513 #1 0x0000000000dfe525 in reread_symbols (from_tty=1) at ../../src/gdb/symfile.c:2517 #2 0x00000000009a1a98 in run_command_1 (args=0x0, from_tty=1, run_how=RUN_STOP_AT_MAIN) at ../../src/gdb/infcmd.c:398 #3 0x00000000009a20a5 in start_command (args=0x0, from_tty=1) at ../../src/gdb/infcmd.c:527 #4 0x000000000068dc5d in do_simple_func (args=0x0, from_tty=1, c=0x35c7200) at ../../src/gdb/cli/cli-decode.c:95 In the first case the call to exec_file_attach first passes through reopen_exec_file. The reopen_exec_file performs a modification time check on the executable file, and only calls exec_file_attach if the executable has changed on disk since it was last loaded. However, in the second case things work a little differently. In this case GDB is really trying to reread the debug symbol. As such, we iterate over the objfiles list, and for each of those we check the modification time, if the file on disk has changed then we reload the debug symbols from that file. However, there is an additional check, if the objfile has the same name as the executable then we will call exec_file_attach, but we do so without checking the cached modification time that indicates when the executable was last reloaded, as a result, we reload the executable twice. In this commit I propose that reread_symbols be changed to unconditionally call reopen_exec_file before performing the objfile iteration. This will ensure that, if the executable has changed, then the executable will be reloaded, however, if the executable has already been recently reloaded, we will not reload it for a second time. After handling the executable, GDB can then iterate over the objfiles list and reload them in the normal way. With this done I now see the executable reloaded only once when GDB restarts an inferior, which means I can remove the kfail that I added to the gdb.python/py-exec-file.exp test in the previous commit. Approved-By: Tom Tromey <tom@tromey.com>
2023-09-28gdb/python: make the executable_changed event available from PythonAndrew Burgess1-0/+100
This commit makes the executable_changed observable available through the Python API as an event. There's nothing particularly interesting going on here, it just follows the same pattern as many of the other Python events we support. The new event registry is called events.executable_changed, and this emits an ExecutableChangedEvent object which has two attributes, a gdb.Progspace called 'progspace', this is the program space in which the executable changed, and a Boolean called 'reload', which is True if the same executable changed on disk and has been reloaded, or is False when a new executable has been loaded. One interesting thing did come up during testing though, you'll notice the test contains a setup_kfail call. During testing I observed that the executable_changed event would trigger twice when GDB restarted an inferior. However, the ExecutableChangedEvent object is identical for both calls, so the wrong information is never sent out, we just see one too many events. I tracked this down to how the reload_symbols function (symfile.c) takes care to also reload the executable, however, I've split fixing this into a separate commit, so see the next commit for details. Reviewed-By: Eli Zaretskii <eliz@gnu.org> Approved-By: Tom Tromey <tom@tromey.com>
2023-09-28gdb/python: new Progspace.executable_filename attributeAndrew Burgess2-0/+122
Add a new Progspace.executable_filename attribute that contains the path to the executable for this program space, or None if no executable is set. The path within this attribute will be set by the "exec-file" and/or "file" commands. Accessing this attribute for an invalid program space will raise an exception. This new attribute is similar too, but not the same as the existing gdb.Progspace.filename attribute. If I could change the past, I'd change the 'filename' attribute to 'symbol_filename', which is what it actually represents. The old attribute will be set by the 'symbol-file' command, while the new attribute is set by the 'exec-file' command. Obviously the 'file' command sets both of these attributes. Reviewed-By: Eli Zaretskii <eliz@gnu.org> Approved-By: Tom Tromey <tom@tromey.com>
2023-09-28gdb/python: new Progspace.symbol_file attributeAndrew Burgess1-0/+9
Add a new Progspace.symbol_file attribute. This attribute holds the gdb.Objfile object that corresponds to Progspace.filename, or None if there is no main symbol file currently set. Currently, to get this gdb.Objfile, a user would need to use Progspace.objfiles, and then search for the objfile with a name that matches Progspace.filename -- which should work just fine, but having direct access seems a little nicer. Reviewed-By: Eli Zaretskii <eliz@gnu.org> Approved-By: Tom Tromey <tom@tromey.com>
2023-09-28[gdb/testsuite] Add nopie to gdb.base/unwind-on-each-insn-amd64-2.expTom de Vries5-7/+23
When running test-case gdb.base/unwind-on-each-insn-amd64-2.exp with target board unix/-fPIE/-pie, I run into: ... gdb compile failed, ld: unwind-on-each-insn-amd64-21.o: relocation \ R_X86_64_32S against `.text' can not be used when making a PIE object; \ recompile with -fPIE ld: failed to set dynamic section sizes: bad value ... Fix this by hardcoding nopie in the test-case, and for good measure in the other test-cases that source unwind-on-each-insn.exp.tcl and use a .s file. Tested on x86_64-linux. Approved-by: Kevin Buettner <kevinb@redhat.com>
2023-09-27Adjust gdb.thread/pthreads.exp for CygwinPedro Alves1-7/+7
The Cygwin runtime spawns a few extra threads, so using hardcoded thread numbers in tests rarely works correctly. Thankfully, this testcase already records the ids of the important threads in globals. It just so happens that they are not used in a few tests. This commit fixes that. With this, the test passes cleanly on Cygwin [1]. Still passes cleanly on x86-64 GNU/Linux. [1] - with system GDB. Upstream GDB is missing a couple patches Cygwin carries downstream. Approved-By: Tom Tromey <tom@tromey.com> Change-Id: I01bf71fcb44ceddea8bd16b933b10b964749a6af
2023-09-27In gdb.threads/pthreads.c, handle pthread_attr_setscope ENOTSUPPedro Alves1-1/+2
On Cygwin, I see: (gdb) PASS: gdb.threads/pthreads.exp: break thread1 continue Continuing. pthread_attr_setscope 1: Not supported (134) [Thread 3732.0x265c exited with code 1] [Thread 3732.0x2834 exited with code 1] [Thread 3732.0x2690 exited with code 1] Program terminated with signal SIGHUP, Hangup. The program no longer exists. (gdb) FAIL: gdb.threads/pthreads.exp: Continue to creation of first thread ... and then a set of cascading failures. Fix this by treating ENOTSUP the same way as if PTHREAD_SCOPE_SYSTEM were not defined. I.e., ignore ENOTSUP errors, and proceed with testing. Approved-By: Tom Tromey <tom@tromey.com> Change-Id: Iea68ff8b9937570726154f36610c48ef96101871
2023-09-27Fix gdb.threads/pthreads.exp error handling/printingPedro Alves1-8/+22
On Cygwin, I noticed: (gdb) PASS: gdb.threads/pthreads.exp: break thread1 continue Continuing. pthread_attr_setscope 1: No error [Thread 8732.0x28f8 exited with code 1] [Thread 8732.0xb50 exited with code 1] [Thread 8732.0x17f8 exited with code 1] Program terminated with signal SIGHUP, Hangup. The program no longer exists. (gdb) FAIL: gdb.threads/pthreads.exp: Continue to creation of first thread Note "No error" in "pthread_attr_setscope 1: No error". That is a bug in the test. It is using perror, but that prints errno, while the pthread functions return the error directly. Fix all cases of the same problem, by adding a new print_error function and using it. We now get: ... pthread_attr_setscope 1: Not supported (134) ... Approved-By: Tom Tromey <tom@tromey.com> Change-Id: I972ebc931b157bc0f9084e6ecd8916a5e39238f5
2023-09-27Fix gdb.threads/pthreads.c formattingPedro Alves1-18/+27
Just some GNU formatting fixes throughout. Approved-By: Tom Tromey <tom@tromey.com> Change-Id: Ie851e3815b839e57898263896db0ba8ddfefe09e
2023-09-27gdb.threads/pthreads.c, K&R -> ANSI function stylePedro Alves1-7/+3
gdb.threads/pthreads.c is declaring functions with old K&R style. This commit converts them to ANSI style. Approved-By: Tom Tromey <tom@tromey.com> Change-Id: I1ce007c67bb4ab1e49248c014c7881e46634f8f8
2023-09-26gdb/testsuite: add xfail for gdb/29965 in ↵Simon Marchi1-1/+18
gdb.threads/process-exit-status-is-leader-exit-status.exp Bug 29965 shows on a Linux kernel >= 6.1, that test fails consistently with: FAIL: gdb.threads/process-exit-status-is-leader-exit-status.exp: iteration=0: continue (the program exited) ... FAIL: gdb.threads/process-exit-status-is-leader-exit-status.exp: iteration=9: continue (the program exited) This is due to a change in Linux kernel behavior [1] that affects exactly what this test tests. That is, if multiple threads (including the leader) call SYS_exit, the exit status of the process should be the exit status of the leader. After that change in the kernel, it is no longer the case. Add an xfail in the test, based on the Linux kernel version. The goal is that if a regression is introduced in GDB regarding this feature, it should be caught if running on an older kernel where the behavior was consistent. [1] https://bugzilla.suse.com/show_bug.cgi?id=1206926 Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=29965 Change-Id: If6ab7171c92bfc1a3b961c7179e26611773969eb Approved-By: Tom de Vries <tdevries@suse.de>
2023-09-26[gdb/testsuite] Fix gdb.ada/mi_task_arg.exp with newer gccTom de Vries1-1/+2
When running test-case gdb.ada/mi_task_arg.exp on openSUSE Tumbleweed using gcc 13.2.1, I run into (layout adapted for readability): ... -stack-list-arguments 1^M ^done,stack-args=[ frame={level="0",args=[]}, frame={level="1",args=[{name="<_task>",value="0x464820"}, {name="<_taskL>",value="129"}]}, frame={level="2",args=[{name="self_id",value="0x464840"}]}, frame={level="3",args=[]}, frame={level="4",args=[]} ]^M (gdb) ^M FAIL: gdb.ada/mi_task_arg.exp: -stack-list-arguments 1 (unexpected output) ... On openSUSE Leap 15.4 with gcc 7.5.0 I get instead: ... -stack-list-arguments 1^M ^done,stack-args=[ frame={level="0",args=[]}, frame={level="1",args=[{name="<_task>",value="0x444830"}]}, frame={level="2",args=[{name="self_id",value="0x444850"}]}, frame={level="3",args=[]}, frame={level="4",args=[]}]^M (gdb) ^M PASS: gdb.ada/mi_task_arg.exp: -stack-list-arguments 1 ... The difference in gdb output is due to difference in the dwarf generated by the compiler, so I don't see a problem with gdb here. Fix this by updating the test-case to accept this output. Tested on x86_64-linux. Approved-By: Tom Tromey <tom@tromey.com>
2023-09-26[gdb/testsuite] Fix gdb.server/ext-run.exp in containerTom de Vries1-1/+1
When running the gdb testsuite inside a container, I run into: ... (gdb) gdb_expect_list pattern: /1 +root +[/a-z]*(init|systemd)/ FAIL: gdb.server/ext-run.exp: get process list (pattern 2) ... because there's no process with pid 1 and cmd init or systemd. In the host system (where the test passes), I have: ... $ ps -f 1 UID PID PPID C STIME TTY STAT TIME CMD root 1 0 0 Sep25 ? Ss 0:03 /usr/lib/systemd/systemd ... ... but in the container instead: ... UID PID PPID C STIME TTY STAT TIME CMD root 1 0 0 11:45 pts/0 Ss 0:00 /bin/bash ... Fix this by also accepting bash as a valid cmd. Tested on x86_64-linux. Approved-By: Tom Tromey <tom@tromey.com>
2023-09-20gdb/dap: only include sourceReference if file path does not existGregory Anders1-4/+5
According to the DAP specification if the "sourceReference" field is included in a Source object, then the DAP client _must_ make a "source" request to the debugger to retrieve file contents, even if the Source object also includes path information. If the Source's path field is a valid path that the DAP client is able to read from the filesystem, having to make another request to the debugger to get the file contents is wasteful and leads to incorrect results (DAP clients will try to get the contents from the server and display those contents as a file with the name in "source.path", but this will conflict with the _acutal_ existing file at "source.path"). Instead, only set "sourceReference" if the source file path does not exist. Approved-By: Tom Tromey <tom@tromey.com>
2023-09-20gdb/dap: check for breakpoint source before unpackingGregory Anders1-0/+7
Not all breakpoints have a source location. For example, a breakpoint set on a raw address will have only the "address" field populated, but "source" will be None, which leads to a RuntimeError when attempting to unpack the filename and line number. Before attempting to unpack the filename and line number from the breakpoint, ensure that the source information is not None. Also populate the source and line information separately from the "instructionReference" field, so that breakpoints that include only an address are still included. Approved-By: Tom Tromey <tom@tromey.com>
2023-09-20[gdb/symtab] Error out for .debug_types section in dwz fileTom de Vries1-0/+128
There are two methods to factor out type information in a dwarf4 executable: - use -fdebug-info-types to generate type units in a .debug_types section, and - use dwz to create partial units. The dwz method has an extra benefit: it also allows to factor out information between executables into a newly created .dwz file, pointed to by a .gnu_debugaltlink section. There is nothing prohibiting a .gnu_debugaltlink file to contain a .debug_types section. It's just not generated by dwz or any other tool atm, and consequently gdb has no support for it. Enhancement PR symtab/30838 is open about the lack of support. Make the current situation explicit by emitting a dwarf error: ... (gdb) file struct-with-sig-2^M Reading symbols from struct-with-sig-2...^M Dwarf Error: .debug_types section not supported in dwz file^M ... and add an assert in write_gdbindex: ... + /* See enhancement PR symtab/30838. */ + gdb_assert (!(per_cu->is_dwz && per_cu->is_debug_types)); ... to clarify why we can use: ... data_buf &cu_list = (per_cu->is_debug_types ? types_cu_list : per_cu->is_dwz ? dwz_cu_list : objfile_cu_list); ... The test-case is a modified copy from gdb.dwarf2/struct-with-sig.exp, so it keeps the copyright years range. Tested on x86_64-linux. Tested-By: Guinevere Larsen <blarsen@redhat.com> Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=30838
2023-09-19Handle pointers and references correctly in DAPTom Tromey2-0/+137
A user pointed out that the current DAP variable code does not let the client deference a pointer. Oops! Fixing this oversight is simple enough -- adding a new no-op pretty-printer for pointers and references is quite simple. However, doing this naive caused a regession in scopes.exp, which expected there to be no children of a 'const char *' variable. This problem was fixed by the preceding patches in the series, which ensure that a C type of this kind is recognized as a string. Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=30821
2023-09-19gdb, breakpoint: add a destructor to the watchpoint structMohamed Bouhaouel2-0/+66
Make sure to unlink the related breakpoint when the watchpoint instance is deleted. This prevents having a wp-related breakpoint that is linked to a NULL watchpoint (e.g. the watchpoint instance is being deleted when the 'watch' command fails). With the below scenario, having such a left out breakpoint will lead to a GDB hang, and this is due to an infinite loop when deleting all inferior breakpoints. Scenario: (gdb) set can-use-hw-watchpoints 0 (gdb) awatch <SCOPE VAR> Can't set read/access watchpoint when hardware watchpoints are disabled. (gdb) rwatch <SCOPE VAR> Can't set read/access watchpoint when hardware watchpoints are disabled. (gdb) <continue the program until the end> >> HANG << Signed-off-by: Mohamed Bouhaouel <mohamed.bouhaouel@intel.com> Reviewed-by: Bruno Larsen <blarsen@redhat.com>
2023-09-19gdb/cli: fixes to newly added "list ." commandGuinevere Larsen1-11/+13
After the series that added this command was pushed, Pedro mentioned that the news description could easily be misinterpreted, as well as some code and test improvements that should be made. While fixing the test, I realized that code repetition wasn't happening as it should, so I took care of that too. Approved-By: Andrew Burgess <aburgess@redhat.com> Reviewed-By: Eli Zaretskii <eliz@gnu.org>
2023-09-15gdb/amdgpu: add precise-memory supportSimon Marchi10-0/+466
The amd-dbgapi library exposes a setting called "memory precision" for AMD GPUs [1]. Here's a copy of the description of the setting: The AMD GPU can overlap the execution of memory instructions with other instructions. This can result in a wave stopping due to a memory violation or hardware data watchpoint hit with a program counter beyond the instruction that caused the wave to stop. Some architectures allow the hardware to be configured to always wait for memory operations to complete before continuing. This will result in the wave stopping at the instruction immediately after the one that caused the stop event. Enabling this mode can make execution of waves significantly slower. Expose this option through a new "amdgpu precise-memory" setting. The precise memory setting is per inferior. The setting is transferred from one inferior to another when using the clone-inferior command, or when a new inferior is created following an exec or a fork. It can be set before starting the inferior, in which case GDB will attempt to apply what the user wants when attaching amd-dbgapi. If the user has requested to enable precise memory, but it can't be enabled (not all hardware supports it), GDB prints a warning. If precise memory is disabled, GDB prints a warning when hitting a memory exception (translated into GDB_SIGNAL_SEGV or GDB_SIGNAL_BUS), saying that the stop location may not be precise. Note that the precise memory setting also affects memory watchpoint reporting, but the watchpoint support for AMD GPUs hasn't been upstreamed to GDB yet. When we do upstream watchpoint support, GDB will produce a similar warning message when stopping due to a watchpoint if precise memory is disabled. Add a handful of tests. Add a util proc "hip_devices_support_precise_memory", which indicates if all devices used for testing support that feature. [1] https://github.com/ROCm-Developer-Tools/ROCdbgapi/blob/687374258a27b5aab1309a7e8ded719e2f1ed3b1/include/amd-dbgapi.h.in#L6300-L6317 Change-Id: Ife1a99c0e960513da375ced8f8afaf8e47a61b3f Approved-By: Lancelot Six <lancelot.six@amd.com>
2023-09-15gdb/testsuite: add linux target check in allow_hipcc_testsSimon Marchi1-0/+4
ROCm / HIP tests should only run on Linux for now, existing gdb.rocm tests miss such a check. Add an "istarget linux" check in allow_hipcc_tests. Change-Id: I71f69e510a754f2fdadc32de53b923ebb9835ab5 Approved-By: Lancelot Six <lancelot.six@amd.com>
2023-09-15gdb/testsuite: explicitly test for stderr in gdb.mi/mi-dprintf.expGuinevere Larsen2-3/+22
As mentioned in commit 3f5bbc3e2075ef5061a815c73fdc277218489f22, some compilers such as clang don't add debug information about stderr by default, leaving it to external debug packages. This commit adds a way to check if GDB has access to stderr information when in MI mode, and uses this new mechanism to skip the related section of the test gdb.mi/mi-dprintf.exp. It also fixes an incorrect name for a test in that file. Co-Authored-By: Andrew Burgess <aburgess@redhat.com> Approved-By: Kevin Buettner <kevinb@redhat.com>
2023-09-14[gdb/exp] Clean up asap in value_print_array_elementsTom de Vries7-3/+353
I've been running the test-suite on an i686-linux laptop with 1GB of memory, and 1 GB of swap, and noticed problems after running gdb.base/huge.exp: gdb not being able to spawn for a large number of test-cases afterwards. So I investigated the memory usage, on my usual x86_64-linux development platform. The test-case is compiled with -DCRASH_GDB=2097152, so this: ... static int a[CRASH_GDB], b[CRASH_GDB]; ... with sizeof (int) == 4 represents two arrays of 8MB each. Say we add a loop around the "print a" command and print space usage statistics: ... gdb_test "maint set per-command space on" for {set i 0} {$i < 100} {incr i} { gdb_test "print a" } ... This gets us: ... (gdb) print a^M $1 = {0 <repeats 2097152 times>}^M Space used: 478248960 (+469356544 for this command)^M (gdb) print a^M $2 = {0 <repeats 2097152 times>}^M Space used: 486629376 (+8380416 for this command)^M (gdb) print a^M $3 = {0 <repeats 2097152 times>}^M Space used: 495009792 (+8380416 for this command)^M ... (gdb) print a^M $100 = {0 <repeats 2097152 times>}^M Space used: 1308721152 (+8380416 for this command)^M ... In other words, we start out at 8MB, and the first print costs us about 469MB, and subsequent prints 8MB, which accumulates to 1.3 GB usage. [ On the i686-linux laptop, the first print costs us 335MB. ] The subsequent 8MBs are consistent with the values being saved into the value history, but the usage for the initial print seems somewhat excessive. There is a PR open about needing sparse representation of large arrays (PR8819), but this memory usage points to an independent problem. The function value_print_array_elements contains a scoped_value_mark to free allocated values in the outer loop, but it doesn't prevent the inner loop from allocating a lot of values. Fix this by adding a scoped_value_mark in the inner loop, after which we have: ... (gdb) print a^M $1 = {0 <repeats 2097152 times>}^M Space used: 8892416 (+0 for this command)^M (gdb) print a^M $2 = {0 <repeats 2097152 times>}^M Space used: 8892416 (+0 for this command)^M (gdb) print a^M $3 = {0 <repeats 2097152 times>}^M Space used: 8892416 (+0 for this command)^M ... (gdb) print a^M $100 = {0 <repeats 2097152 times>}^M Space used: 8892416 (+0 for this command)^M ... Note that the +0 here just means that the mallocs did not trigger an sbrk. This is dependent on malloc (which can use either mmap or sbrk or some pre-allocated memory) and will likely vary between different tunings, versions and implementations, so this does not give us a reliable way detect the problem in a minimal way. A more reliable way of detecting the problem is: ... void value_free_to_mark (const struct value *mark) { + size_t before = all_values.size (); auto iter = std::find (all_values.begin (), all_values.end (), mark); if (iter == all_values.end ()) all_values.clear (); else all_values.erase (iter + 1, all_values.end ()); + size_t after = all_values.size (); + if (before - after >= 1024) + fprintf (stderr, "value_free_to_mark freed %zu items\n", before - after); ... which without the fix tells us: ... +print a value_free_to_mark freed 2097152 items $1 = {0 <repeats 2097152 times>} ... Fix a similar problem for Fortran: ... +print array1 value_free_to_mark freed 4194303 items $1 = (0, <repeats 2097152 times>) ... in fortran_array_printer_impl::process_element. The problem also exists for Ada: ... +print Arr value_free_to_mark freed 2097152 items $1 = (0 <repeats 2097152 times>) ... but is fixed by the fix for C. Add Fortran and Ada variants of the test-case. The *.exp files are similar enough to the original to keep the copyright years range. While writing the Fortran test-case, I ran into needing an additional print setting to print the entire array in repeat form, filed as PR exp/30817. I managed to apply the compilation loop for the Ada variant as well, but with a cumbersome repetition style. I noticed no other test-case uses gnateD, so perhaps there's a better way of implementing this. The regression test included in the patch is formulated in its weakest form, to avoid false positive FAILs, which also means that smaller regressions may not get detected. Tested on x86_64-linux. Approved-By: Tom Tromey <tom@tromey.com>
2023-09-14[gdb/testsuite] Modernize gdb.base/huge.expTom de Vries1-18/+33
Rewrite test-case gdb.base/huge.exp: - use build_executable rather than gdb_compile, - use save_vars, - factor out hardcoded loop limits min and max, - handle compilation failure using require, and - avoid using . in regexp to match $, {} and <>. Tested on x86_64-linux. Approved-By: Tom Tromey <tom@tromey.com>
2023-09-12Avoid spurious breakpoint-setting failure in DAPTom Tromey1-2/+7
A user pointed out that if a DAP setBreakpoints request has a 'source' field in a SourceBreakpoint object, then the gdb DAP implementation will throw an exception. While SourceBreakpoint does not allow 'source' in the spec, it seems better to me to accept it. I don't think we should fully go down the "Postel's Law" path -- after all, we have the type-checker -- but at the same time, if we do send errors, they should be intentional and not artifacts of the implementation. Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=30820
2023-09-12gdb/testsuite/rocm: fix rocm-multi-inferior-gpu.cppLancelot Six1-1/+1
The gdb/testsuite/gdb.rocm/multi-inferior-gpu.cpp testcase contains a call to execl which does not have NULL as a last argument. This is an invalid use of execl. This patch fixes this oversight. Change-Id: I03b60abe30468d71ba5089b240c6d00f9b8883b2 Approved-By: Tom Tromey <tom@tromey.com>
2023-09-11gdb/testsuite: use foreach_with_prefix in gdb.guile/scm-ports.expSimon Marchi1-60/+54
Simplify things a bit using foreach_with_prefix. The only expected change is in the naming of tests. Change-Id: Icb5e55207e0209e0d44d9e7c16a2f5e11aa29017 Approved-By: Andrew Burgess <aburgess@redhat.com>
2023-09-11testsuite, fortran: Fix regression due to fix for ifort's 'start' behaviorIjaz, Abdul B1-5/+5
Got a regression email due to merge of commit in CI config tcwg_gdb_check/master-aarch64 : https://sourceware.org/git/?p=binutils-gdb.git;a=commitdiff;h=41439185cd0075bbb1aedf9665685dba0827cfec Begining of test "gdb.fortran/array-slices-bad.exp" was updated in above commit to start the test from running to line with tag "First Breakpoint" instead of "fortran_runto_main". Reason of the regression is shared libraries are still loaded after hitting the breakpoint as "nosharedlibrary" is already called before hitting the breakpoint. So now after this change test is updated accordingly to disable and unload shared libraries symbols after hitting the first breakpoint. Approved-By: Andrew Burgess <aburgess@redhat.com>
2023-09-10gdb/testsuite: fix gdb.arch/amd64-init-x87-values.exp on AMD CPUsSimon Marchi1-1/+1
I see the following failure when running this test on an AMD machine: p/x $fioff^M $24 = 0x0^M (gdb) FAIL: gdb.arch/amd64-init-x87-values.exp: check_x87_regs_around_init: check post FLD1 value of $fioff The register that GDB calls fioff normally contains the address of the last instruction executed by the x87 unit. It is available through the FSAVE/FXSAVE/XSAVE instructions, at offset 0x8 of the FSAVE/FXSAVE/XSAVE area. You can read about it in the Intel manual [1] at section "10.5.1 FXSAVE Area" (and equivalent sections for FSAVE and XSAVE) or in the AMD manual [2] at section "11.4.4 Saving Media and x87 Execution Unit State". The test therefore expects that after executing the FLD1 instruction, the fioff register contains the address of the FLD1 instruction. However, the FXSAVE and XSAVE instructions (which the kernel uses to dump x87 register state which it provides GDB through ptrace) behave differently on AMD CPUs. In section "11.4.4.3 FXSAVE and FXRSTOR Instructions" of the AMD manual, we read: The FXSAVE and FXRSTOR instructions save and restore the entire 128-bit media, 64-bit media, and x87 state. These instructions usually execute faster than FSAVE/FNSAVE and FRSTOR because they do not normally save and restore the x87 exception pointers (last-instruction pointer, last data-operand pointer, and last opcode). The only case in which they do save the exception pointers is the relatively rare case in which the exception-summary bit in the x87 status word (FSW.ES) is set to 1, indicating that an unmasked exception has occurred. So, unless a floating point exception happened and that exception is unmasked in the x87 FPU control register (which isn't by default on Linux, from what I saw), the "last instruction address" register (or fioff as GDB calls it) will always be 0 on an AMD CPU. For this reason, I think it's fine to change the test to accept the value 0 - that's just how the processor works. I toyed with the idea of changing the test program to make it so the CPU would generate a non-zero fioff. That is by unmasking an FPU exception and executing an instruction to raise that kind exception. It worked, but then I would have to change the test more extensively, and it didn't seem to be worth it. [1] https://cdrdv2.intel.com/v1/dl/getContent/671200 [2] https://www.amd.com/content/dam/amd/en/documents/processor-tech-docs/programmer-references/24593.pdf Change-Id: If2e1d932f600ca01b15f30b14b8d38bf08a3e00b Reviewed-by: John Baldwin <jhb@FreeBSD.org>
2023-09-08Run 'black' on recent test caseTom Tromey1-0/+1
The auto-builders pointed out that I neglected to run 'black' after a rest testcase change. This patch fixes the oversight.
2023-09-08[gdb/testsuite] Make gdb.dwarf2/dwzbuildid.exp more robustTom de Vries1-35/+35
I ran test-case gdb.dwarf2/dwzbuildid.exp with target board cc-with-gdb-index, and noticed that compilation failure for one exec prohibited testing of all execs. Fix this by restructuring the test-case, such that we have: ... PASS: gdb.dwarf2/dwzbuildid.exp: testname=ok: set debug-file-directory PASS: gdb.dwarf2/dwzbuildid.exp: testname=ok: print the_int UNSUPPORTED: gdb.dwarf2/dwzbuildid.exp: testname=mismatch: compilation failed UNSUPPORTED: gdb.dwarf2/dwzbuildid.exp: testname=fallback: compilation failed ... Tested on x86_64-linux.
2023-09-08[gdb/testsuite] Add kfail in gdb.dwarf2/dwzbuildid.expTom de Vries1-0/+7
When running test-case gdb.dwarf2/dwzbuildid.exp using target board readnow, I get: ... (gdb) file dwzbuildid-mismatch^M Reading symbols from dwzbuildid-mismatch...^M warning: File "dwzbuildid5.o" has a different build-id, file skipped^M could not find '.gnu_debugaltlink' file for dwzbuildid-mismatch^M (gdb) delete breakpoints^M (gdb) info breakpoints^M No breakpoints or watchpoints.^M (gdb) break -qualified main^M No symbol table is loaded. Use the "file" command.^M Make breakpoint pending on future shared library load? (y or [n]) n^M (gdb) FAIL: gdb.dwarf2/dwzbuildid.exp: mismatch: gdb_breakpoint: set breakpoint at main ... This is PR symtab/26797: when using readnow, a failure in reading the dwarf results in the minimal symbols not being available. Add a corresponding KFAIL. Tested on x86_64-linux.
2023-09-08[gdb/testsuite] Add aranges in gdb.dwarf2/dwzbuildid.expTom de Vries1-2/+9
While investigating the execs of gdb.dwarf2/dwzbuildid.exp using readelf I ran into a warning: ... $ readelf -w dwzbuildid-ok > READELF readelf: Warning: .debug_info offset of 0x2e in .debug_aranges section does not point to a CU header. ... AFAICT, the warning is incorrect, I've filed PR binutils/30835 about that. While looking at the .debug_aranges section, I noticed that the entries for the CUs generated by the dwarf assembler are missing. Fix this by adding the missing .debug_aranges entries. Tested on x86_64-linux.
2023-09-08[gdb/testsuite] Fix build-ids in gdb.dwarf2/dwzbuildid.expTom de Vries1-3/+3
When looking at the execs from test-case gdb.dwarf2/dwzbuildid.exp using readelf, I run into: ... $ readelf -w dwzbuildid-ok > READELF readelf: Warning: Corrupt debuglink section: .gnu_debugaltlink readelf: Warning: Build-ID is too short (0x6 bytes) ... Fix this by ensuring the Build-IDs are the required 20 bytes. Tested on x86_64-linux.
2023-09-08gdb/testsuite: fix gdb.mi/mi-condbreak-throw.exp failureAndrew Burgess1-2/+1
In commit: commit 3ce8f906be7a55d8c0375e6d360cc53b456d86ae Date: Tue Aug 8 10:45:20 2023 +0100 gdb: MI stopped events when unwindonsignal is on a new test, gdb.mi/mi-condbreak-throw.exp, was added. Unfortunately, this test would fail when using the native-gdbserver board (and other similar boards). The problem was that one of the expected output patterns included some output from the inferior. When using the native-gdbserver board, this output is not printed to GDB's tty, but is instead printed to gdbserver's tty, the result is that the expected output no longer matches, and the test fails. Additionally, as the output is actually from the C++ runtime, rather than the test's source file, changes to the C++ runtime could cause the output to change. To solve both of these issues, in this commit, I'm removing the reference to the inferior's output, and replacing it with '.*', which will skip the output if it is present, but is equally happy if the output is not present. After this commit gdb.mi/mi-condbreak-throw.exp now passes on all boards, including native-gdbserver.
2023-09-08testsuite, fortran: make kfail gfortran specificNils-Christian Kempke1-1/+3
The modified test in function-calls.exp actually passes with ifort and ifx. The particular fail seems to be specific to gfortran. When the test was introduced it was only tested with gfortran (actually the whole patch was written with gfortran and the GNU Fortran argument passing convention in mind). Approved-by: Tom Tromey <tom@tromey.com>
2023-09-08testsuite, fortran: adapt tests for ifort's 'start' behaviorNils-Christian Kempke2-16/+8
The modified tests array-slices-bad.exp and vla-type.exp both set a breakpoint at the first real statement in the respective executables. Normally, the expected behavior of fortran_runto_main for these would be the stopping of the debugger at exactly the first statment in the code. Strangely, neither gfortran nor ifx seem to do this for these tests. Instead, issuing 'start' in ifx (for either of the 2 tests) lets GDB stop at the 'program ...' line and gfortran stops at a variable declaration line. E.g. for vla-type it stops at 41 type(five) :: fivearr (2) So, actually, ifort's behavior can be considered to be a bit more 'correct' here. This patch remove the fortran_runto_main in the two tests and instead uses runto to directly run to the first breakpoint set at the first program statement. This works with both compiler behaviors and makes the tests more robust. Approved-by: Kevin Buettner <kevinb@redhat.com>
2023-09-08testsuite, fortran: Remove self assignment non-statementsNils-Christian Kempke3-7/+8
There were a couple of places in the testsuite where instructions like var = var were written in the source code of tests. These were usually dummy statements meant to generate a line table entry at that line on which to break later on. This worked fine for gfortran and ifx, but it seems that, when compiled with ifort (2021.6.0) these statements do not actually create any assmbler instructions and especially no line table entries. Consider the program program test Integer var :: var = 1 var = var end program compiled with gfortran (13.0.0, -O0 -g). The linetable as emitted by 'objdump --dwarf=decodedline ./a.out' looks like test.f90: File name Line number Starting address View Stmt test.f90 1 0x401172 x test.f90 3 0x401176 x test.f90 4 0x401182 x test.f90 4 0x401185 x test.f90 4 0x401194 x test.f90 - 0x4011c0 actually containing line table info for line 3. Running gdb, breaking at 3 and checking the assembly we see 0x0000000000401172 <+0>: push %rbp 0x0000000000401173 <+1>: mov %rsp,%rbp => 0x0000000000401176 <+4>: mov 0x2ebc(%rip),%eax # 0x404038 <var.1> 0x000000000040117c <+10>: mov %eax,0x2eb6(%rip) # 0x404038 <var.1> 0x0000000000401182 <+16>: nop 0x0000000000401183 <+17>: pop %rbp 0x0000000000401184 <+18>: ret so two mov instructions are being issued for this assignment one copying the value into a register and one writing it back to the same memory. Ifort (2021.6.0, -O0 -g) on the other hand does not emit anything here and also has no line table entry: test.f90: File name Line number Starting address View Stmt test.f90 1 0x4040f8 x test.f90 4 0x404109 x test.f90 4 0x40410e x test.f90 - 0x404110 As I do not think that this is really a bug (on either side, gfortran/ifx or ifort), and as I don't think this behavior is covered in the Fortran standard, I changed these lines to become actual value assignments. This removes a few FAILs in the testsuite when ran with ifort. Approved-by: Tom Tromey <tom@tromey.com>
2023-09-08testsuite, fortran: make mixed-lang-stack less compiler dependentNils-Christian Kempke1-1/+8
In the gdb.fortran/mixed-lang-stack.exp test when somewhere deep in a bunch of nested function calls we issue and test a 'info args' command for the mixed_func_1b function (when in that function's frame). The signature of the function looks like subroutine mixed_func_1b(a, b, c, d, e, g) use type_module implicit none integer :: a real(kind=4) :: b real(kind=8) :: c complex(kind=4) :: d character(len=*) :: e character(len=:), allocatable :: f TYPE(MyType) :: g and usually one would expect arguments a, b, c, d, e, and g to be emitted here. However, due to some compiler dependent treatment of the e array the actual output in the test (with gfortran/ifx) is (gdb) info args a = 1 b = 2 c = 3 d = (4,5) e = 'abcdef' g = ( a = 1.5, b = 2.5 ) _e = 6 where the compiler generated '_e' is emitted as the length of e. While ifort also generates an additional length argument, the naming (which is up to the compilers here I think, I could not find anything in the Fortran standard about this) is different and we see (gdb) info args a = 1 b = 2 c = 3 d = (4,5) e = 'abcdef' g = ( a = 1.5, b = 2.5 ) .tmp.E.len_V$4a = 6 To make both outputs pass the test, I kept the additional argument for now and made the regex for the emitted name of the last variable match any arbitrary name. Approved-by: Tom Tromey <tom@tromey.com>
2023-09-07Fix bug in -var-evaluate-expressionTom Tromey3-1/+17
This bug points out that if one uses -var-set-visualizer with "None" -- to disable a pretty-printer for a varobj -- then -var-evaluate-expression will still use pretty-printing. This is a combination of bugs. First, setting the visualizer does not update the display text; and second, computing the display text should use "raw" when Python is available but no visualizer is desired. Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=11738 Reviewed-by: Keith Seitz <keiths@redhat.com>
2023-09-07Allow pretty-printer 'children' method to return stringsTom Tromey3-0/+110
A user noticed that, while a pretty-printer can return Python strings from its "children" method, this does not really work for MI. I tracked this down to my_value_of_variable calling into c_value_of_variable, which specially handles arrays and structures -- not using the actual contents of the string. Now, this part of MI seems bad to me, but rather than change that, this applies the fix to only dynamic varobjs, which is the only scenario where a string like this can really be returned. Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=18282 Reviewed-by: Keith Seitz <keiths@redhat.com>
2023-09-07[gdb/ada] Move identical enums handling laterTom de Vries1-0/+2
When running test-case gdb.ada/arr_acc_idx_w_gap.exp with target board cc-with-dwz, I run into: ... (gdb) print enum_with_gaps'enum_rep(lit3)^M 'Enum_Rep requires argument to have same type as enum^M (gdb) FAIL: gdb.ada/arr_acc_idx_w_gap.exp: enum_rep ... With target_board unix, we have instead: ... (gdb) print enum_with_gaps'enum_rep(lit3)^M $16 = 13^M (gdb) PASS: gdb.ada/arr_acc_idx_w_gap.exp: enum_rep ... Conversely, when I add this test to the test-case: ... gdb_test "print enum_with_gaps'enum_rep(lit3)" " = 13" \ "enum_rep" + gdb_test "print enum_subrange'enum_rep(lit3)" " = 13" \ + "other enum_rep" ... the extra test passes with target board cc-with-dwz, but fails with target board unix. The problem is here in remove_extra_symbols: ... if (symbols_are_identical_enums (syms)) syms.resize (1); ... where one of the two identical enums is picked before the enum_rep handling can resolve lit3 to one of the two. Fix this by moving the code to ada_resolve_variable. Tested on x86_64-linux. Approved-By: Tom Tromey <tom@tromey.com> PR ada/30726 Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=30726
2023-09-06[gdb/testsuite] Fix gdb.ada/same_enum.expTom de Vries2-2/+4
Test-case gdb.ada/same_enum.exp is supposed to be a regression test for this bit of code in remove_extra_symbols: ... if (symbols_are_identical_enums (syms)) syms.resize (1); ... The test-case does "print red" and expects one of these two choices to be picked by remove_extra_symbols: ... type Color is (Black, Red, Green, Blue, White); type RGB_Color is new Color range Red .. Blue; ... but because only the type Color is used: ... FC : Color := Red; SC : Color := Green; ... the RGB_Color type is eliminated from the debug info, and consequently remove_extra_symbols has no effect for the test-case. In other words, we have: ... (gdb) ptype Color ^M type = (black, red, green, blue, white)^M (gdb) ptype RGB_Color^M No definition of "rgb_color" in current context.^M ... Fix this by changing the type of SC to RGB_Color, and add prints of the two types to check that they're both available. With the test-case fixed, if we disable the bit of code in remove_extra_symbols we get: ... (gdb) print red^M Multiple matches for red^M [0] cancel^M [1] pck.color'(pck.red) (enumeral)^M [2] pck.rgb_colorB'(pck.red) (enumeral)^M > FAIL: gdb.ada/same_enum.exp: print red (timeout) ... in other words, the test-case now properly functions as a regression test. Tested on x86_64-linux.
2023-09-05gdb/testsuite: Make hook-stop.exp ignore termination message from GDB stubSandra Loosemore1-1/+1
When a GDB stub is run via "target remote |", it sometimes produces extra output that ends up mixed with GDB's own output. For example, QEMU's built-in GDB stub responds to the vKill packet by printing nios2-elf-qemu-system: QEMU: Terminated via GDBstub before exiting. This patch fixes the regexp in gdb.base/hook-stop.exp to allow such messages between GDB's "continuing" and "Inferior killed" messages. Reviewed-By: Tom Tromey <tom@tromey.com> Approved-By: Tom Tromey <tom@tromey.com>
2023-09-05gdb/testsuite: Disable some tests that are broken on remote Windows hostSandra Loosemore3-0/+9
These testcases assume host==build or that the remote host has a Posix shell to run commands in. Don't try to run them if that's not the case. Reviewed-By: Tom Tromey <tom@tromey.com> Approved-By: Tom Tromey <tom@tromey.com>
2023-09-05gdb/testsuite: Adjust some testcases to allow Windows pathnamesSandra Loosemore4-21/+32
This patch fixes some testcases that formerly had patterns with hardwired "/" pathname separators in them, which broke when testing on (remote) Windows host. Reviewed-By: Tom Tromey <tom@tromey.com> Approved-By: Tom Tromey <tom@tromey.com>
2023-09-05gdb/testsuite: Fix style.exp failures on targets without argc/argv supportSandra Loosemore1-5/+18
Some embedded targets don't have full support for argc/argv. argv may print as "0x0" or as an address with a symbol name following. This causes problems for the regexps in the style.exp line-wrapping tests that assume it always prints as an ordinary address in backtrace output. This patch generalizes the regexps to handle these additional forms and reworks some of the line-wrapping tests to account for the argv address string being shorter or longer than a regular address. Reviewed-By: Tom Tromey <tom@tromey.com> Approved-By: Tom Tromey <tom@tromey.com>
2023-09-05Handle array- and string-like values in no-op pretty printersTom Tromey7-0/+389
This changes the no-op pretty printers -- used by DAP -- to handle array- and string-like objects known by the gdb core. Two new tests are added, one for Ada and one for Rust.