aboutsummaryrefslogtreecommitdiff
path: root/gdb
AgeCommit message (Collapse)AuthorFilesLines
2024-03-05gdb/testsuite: fix duplicate test names in gdb.trace/circ.expAndrew Burgess1-31/+45
This fixes some duplicate test names in gdb.trace/circ.exp when using native-gdbserver and native-extended-gdbserver boards. In this test we set the trace buffer size twice. The same test name was used each time the size was adjusted. I've fixed this issue by: 1. Creating a new proc, set_trace_buffer_size, which factors out the code to change the buffer size, and uses test names based on the size we're setting the buffer too, 2. Calling the new proc each time we want to adjust the buffer size. After this the duplicate test names are resolved. There should be no change in what is tested after this commit.
2024-03-05gdb/testsuite: fix some more duplicate test names in gdb.trace/Andrew Burgess2-55/+46
This commit fixes some duplicate test names in the gdb.trace/ directory when run with the native-gdbserver and native-extended-gdbserver boards. In this case the duplicates relate to the calls to gdb_compile_pthreads which emits a fixed PASS message, as there are two calls to gdb_compile_pthreads we get a duplicate PASS message. In both cases the problem is fixed by adding a with_test_prefix around one of the compilations, however, I've made additional changes to clean up the tests a little while I was working on them: 1. Switch to use prepare_for_testing instead of gdb_compile_pthreads. By passing the 'pthreads' option this does call gdb_compile_pthreads under the hood, but using the standard compile function is cleaner, 2. Using prepare_for_testing removes the need to call clean_restart immediately afterwards, so those calls are removed, 3. I removed the unneeded $executable and $expfile globals, where the $executable global was used I've replaced this with $binfile, 4. When we compile two executables I've now given these different names so that both exist at the end of the test run, 5. Removed a gdb_reinitialize_dir call, this is covered by clean_restart, 6. Use gdb_test_no_output where it makes sense. I now see no duplicate test names when running these test scripts. There should be no change in what is being tested after this commit.
2024-03-02gdb: LoongArch: Change LOONGARCH_FIRST_FP_REGNUM to 35Hui Li1-1/+2
There is an assertion error "gdb_assert (n < tdesc->reg_defs.size ())" in find_register_by_number() when gdb connects to gdbserver, this is because the value of LOONGARCH_LINUX_NUM_GREGSET (45, which contains 10 reserved regs) is different with the number of regs (35, which not contains 10 reserved regs) in file gdb/features/loongarch/base64.xml. Add a new macro LOONGARCH_USED_NUM_GREGSET which is defined as 35 to keep consistent with the gdb/features/loongarch/base64.xml, and then define LOONGARCH_FIRST_FP_REGNUM as LOONGARCH_USED_NUM_GREGSET so that all the reg numbers in regcache are consistent with tdesc reg numbers. without this patch: Execute on the target machine: $ gdbserver 192.168.1.123:5678 ./test Execute on the host machine: $ gdb ./test (gdb) target remote 192.168.1.123:5678 Output on the target machine: Process ./test created; pid = 67683 Listening on port 5678 Remote debugging from host 192.168.1.136, port 6789 gdbserver/regcache.cc:205: A problem internal to GDBserver has been detected. find_register_by_number: Assertion 'n < tdesc->reg_defs.size ()' failed. Output on the host machine: Remote debugging using 192.168.1.123:5678 Remote connection closed Signed-off-by: Hui Li <lihui@loongson.cn> Approved-By: John Baldwin <jhb@FreeBSD.org> Signed-off-by: Tiezhu Yang <yangtiezhu@loongson.cn>
2024-03-01Fix TUI text centeringTom Tromey5-37/+26
In a couple of spots, the TUI tries to center some text in the window. Andrew noticed that the calculation is done strangely and the text ends up somewhat to the left of center. This patch fixes the problem. Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=31355
2024-03-01gdb/jit: Fix missing word in commentWill Hawkins1-2/+2
ChangeLog: * gdb/jit.c: Fix missing word in code comment. Signed-off-by: Will Hawkins <hawkinsw@obs.cr>
2024-02-29Use DW_FORM_ref_addr for DIE offset in .debug_namesTom Tromey2-2/+9
Today I realized that while the .debug_names writer uses DW_FORM_udata for the DIE offset, DW_FORM_ref_addr would be more appropriate here. This patch makes this change. Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=31361
2024-02-29[gdb/dap] Fix stray KeyboardInterrupt after cancelTom de Vries1-21/+67
When running test-case gdb.dap/pause.exp 100 times in a loop, it passes 100/100. But if we remove the two "sleep 0.2" from the test-case, we run into (copied from dap.log and edited for readability): ... Traceback (most recent call last): File "startup.py", line 251, in message def message(): KeyboardInterrupt Quit ... This happens as follows. CancellationHandler.cancel calls gdb.interrupt to cancel a request in flight. The idea is that this interrupt triggers while in fn here in message (a nested function of send_gdb_with_response): ... def message(): try: val = fn() result_q.put(val) except (Exception, KeyboardInterrupt) as e: result_q.put(e) ... but instead it triggers outside the try/except. Fix this by: - in CancellationHandler, renaming variable in_flight to in_flight_dap_thread, and adding a variable in_flight_gdb_thread to be able to distinguish when a request is in flight in the dap thread or the gdb thread. - adding a wrapper Cancellable to to deal with cancelling the wrapped event - using Cancellable in send_gdb and send_gdb_with_response to wrap the posted event - in CancellationHandler.cancel, only call gdb.interrupt if req == self.in_flight_gdb_thread. This makes the test-case pass 100/100, also when adding the extra stressor of "taskset -c 0", which makes the fail more likely without the patch. Tested on aarch64-linux. Approved-By: Tom Tromey <tom@tromey.com> PR dap/31275 Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=31275
2024-02-29[gdb/dap] Move send_gdb and send_gdb_with_response to server moduleTom de Vries3-50/+48
Move functions send_gdb and send_gdb_with_response, as well as class Invoker to server module. Separated out to make the following patch easier to read. Tested on aarch64-linux. Approved-By: Tom Tromey <tom@tromey.com>
2024-02-29gdb/arm: Remove tpidruro register from non-FreeBSD target descriptionsThiago Jung Bauermann9-14/+20
Commit 92d48a1e4eac ("Add an arm-tls feature which includes the tpidruro register from CP15.") introduced the org.gnu.gdb.arm.tls feature, which adds the tpidruro register, and unconditionally enabled it in aarch32_create_target_description. In Linux, the tpidruro register isn't available via ptrace in the 32-bit kernel but it is available for an aarch32 program running under an arm64 kernel via the ptrace compat interface. This isn't currently implemented however, which causes GDB on arm-linux with 64-bit kernel to list the register but show it as unavailable, as reported by Tom de Vries: $ gdb -q -batch a.out -ex start -ex 'p $tpidruro' Temporary breakpoint 1 at 0x512 Temporary breakpoint 1, 0xaaaaa512 in main () $1 = <unavailable> Simon Marchi then clarified: > The only time we should be seeing some "unavailable" registers or memory > is in the context of tracepoints, for things that are not collected. > Seeing an unavailable register here is a sign that something is not > right. Therefore, disable the TLS feature in aarch32 target descriptions for Linux and NetBSD targets (the latter also doesn't seem to support accessing tpidruro either, based on a quick look at arm-netbsd-nat.c). This patch fixes the following tests: Running gdb.base/inline-frame-cycle-unwind.exp ... FAIL: gdb.base/inline-frame-cycle-unwind.exp: cycle at level 3: backtrace when the unwind is broken at frame 3 FAIL: gdb.base/inline-frame-cycle-unwind.exp: cycle at level 5: backtrace when the unwind is broken at frame 5 FAIL: gdb.base/inline-frame-cycle-unwind.exp: cycle at level 1: backtrace when the unwind is broken at frame 1 Tested with Ubuntu 22.04.3 on armv8l-linux-gnueabihf in native, native-gdbserver and native-extended-gdbserver targets with no regressions. PR tdep/31418 Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=31418 Approved-By: John Baldwin <jhb@FreeBSD.org>
2024-02-28aarch64: Use aarch64_debug_printf in a few more placesJohn Baldwin1-32/+19
No functional change Approved-By: Simon Marchi <simon.marchi@efficios.com>
2024-02-28Fix gdb.interrupt raceTom Tromey2-0/+43
gdb.interrupt was introduced to implement DAP request cancellation. However, because it can be run from another thread, and because I didn't look deeply enough at the implementation, it turns out to be racy. The fix here is to lock accesses to certain globals in extension.c. Note that this won't work in the case where configure detects that the C++ compiler doesn't provide thread support. This version of the patch disables DAP entirely in this situation. Regression tested on x86-64 Fedora 38. I also ran gdb.dap/pause.exp in a thread-sanitizer build tree to make sure the reported race is gone. Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=31263
2024-02-27Two minor addrmap cleanupsTom Tromey2-2/+0
While working on a different patch, I found a couple of simple addrmap cleanups. In one case, a forward declaration is no longer needed, as the header now includes addrmap.h. In the other, an include of addrmap.h is no longer needed. Tested by rebuilding.
2024-02-27Explicitly quit gdb from DAP server threadTom Tromey2-0/+10
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.
2024-02-27Add final cleanup for runnablesTom Tromey1-0/+11
This changes run-on-main-thread.c to clear 'runnables' in a final cleanup. This avoids an issue where a pending runnable could require Python, but be run after the Python interpreter was finalized. Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=31172
2024-02-27Change finalize_values into a final cleanupTom Tromey3-17/+8
This removes finalize_values in favor of adding a new final cleanup. This is safe now that extension languages are explicitly shut down.
2024-02-27Add extension_language_ops::shutdownTom Tromey6-3/+25
Right now, Python is shut down via a final cleanup. However, it seems to me that it is better for extension languages to be shut down explicitly, after all the ordinary final cleanups are run. The main reason for this is that a subsequent patch adds another case like finalize_values; and rather than add a series of workarounds for Python shutdown, it seemed better to let these be done via final cleanups, and then have Python shutdown itself be the special case.
2024-02-27Rewrite final cleanupsTom Tromey3-30/+18
This patch rewrites final cleanups to use std::function and otherwise be more C++-ish.
2024-02-27Use the .py file in gdb.dap/pause.expTom Tromey1-1/+1
Tom de Vries pointed out that the gdb.dap/pause.exp test writes a Python file but then does not use it. This patch corrects the oversight. Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=31354 Reviewed-By: Tom de Vries <tdevries@suse.de>
2024-02-27Rewrite "python" command exception handlingTom Tromey34-278/+237
The "python" command (and the Python implementation of the gdb "source" command) does not handle Python exceptions in the same way as other gdb-facing Python code. In particular, exceptions are turned into a generic error rather than being routed through gdbpy_handle_exception, which takes care of converting to 'quit' as appropriate. I think this was done this way because PyRun_SimpleFile and friends do not propagate the Python exception -- they simply indicate that one occurred. This patch reimplements these functions to respect the general gdb convention here. As a bonus, some Windows-specific code can be removed, as can the _execute_file function. The bulk of this change is tweaking the test suite to match the new way that exceptions are displayed. These changes are largely uninteresting. However, it's worth pointing out the py-error.exp change. Here, the failure changes because the test changes the host charset to something that isn't supported by Python. This then results in a weird error in the new setup. Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=31354 Acked-By: Tom de Vries <tdevries@suse.de> Reviewed-By: Eli Zaretskii <eliz@gnu.org>
2024-02-27Fix formatting buglet in python.cTom Tromey1-1/+1
python.c has a split string that is missing a space. There's also a stray backslash in this code. Reviewed-By: Tom de Vries <tdevries@suse.de>
2024-02-27[gdb/testsuite] Reset errcnt and warncnt in default_gdb_initTom de Vries1-0/+9
Say we do: ... $ make check RUNTESTFLAGS="gdb.dap/ada-nested.exp gdb.dap/pause.exp" ... and add a perror at the end of pause.exp: ... dap_shutdown + +perror "foo" ... We run into: ... UNRESOLVED: gdb.dap/ada-nested.exp: compilation prog.adb ... This happens because the perror increases the errcnt, which is not reset at the end of the test-case, and consequently the first pass in the following test-case is changed into an unresolved. Version 1.6.3 of dejagnu contains a fix which produces an unresolved at the end of the test-case, which does reset the errcnt, but this is with version 1.6.1. Furthermore, we reset the errcnt in clean_restart, but the pass is produced before, so that doesn't help either. Fix this by resetting errcnt and warncnt in default_gdb_init. Tested on x86_64-linux. Approved-By: Tom Tromey <tom@tromey.com> PR testsuite/31351 Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=31351
2024-02-27[gdb/testsuite] Remove KFAIL for PR ada/30908Tom de Vries2-44/+4
PR ada/30908 turns out to be a duplicate of PR ada/12607, which was fixed by commit d56fdf1b976 ("Refine Ada overload matching"). Remove the KFAILs for PR ada/30908. Tested on x86_64-linux. Approved-By: Tom Tromey <tom@tromey.com> Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=30908
2024-02-27[gdb/testsuite] Fix test in gdb.python/py-finish-breakpoint.expTom de Vries1-1/+2
With test-case gdb.python/py-finish-breakpoint.exp, we run into: ... (gdb) python print (finishbp_default.hit_count) Traceback (most recent call last): File "<string>", line 1, in <module> RuntimeError: Breakpoint 3 is invalid. Error while executing Python code. (gdb) PASS: gdb.python/py-finish-breakpoint.exp: normal conditions: \ check finishBP on default frame has been hit ... The test producing the pass is: ... gdb_test "python print (finishbp_default.hit_count)" "1.*" \ "check finishBP on default frame has been hit" ... so the pass is produced because the 1 in "line 1" matches "1.*". Temporary breakpoints are removed when hit, and consequently accessing the hit_count attribute of a temporary python breakpoint (gdb.Breakpoint class) is not possible, and as per spec we get a RuntimeError. So the RuntimeError is correct, and not specific to finish breakpoints. The test presumably attempts to match: ... (gdb) python print (finishbp_default.hit_count) 1 ... but most likely this output was never produced by any gdb version. Fix this by checking whether the finishbp_default breakpoint has hit by checking that finishbp_default.is_valid() is False. Tested on aarch64-linux. Approved-By: Tom Tromey <tom@tromey.com> PR testsuite/31391 Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=31391
2024-02-27Cygwin: Fix putting inferior in foreground (fix input)Pedro Alves1-4/+22
gdb.base/interrupt.exp reveals that inferior input is broken on Cygwin: (gdb) continue Continuing. talk to me baby Input/output error <<< BAD PASS: gdb.base/interrupt.exp: process is alive a [Thread 10688.0x2590 exited with code 1] [Thread 10688.0x248c exited with code 1] [Thread 10688.0x930 exited with code 1] [Thread 10688.0x2c98 exited with code 1] Program terminated with signal SIGHUP, Hangup. The program no longer exists. (gdb) FAIL: gdb.base/interrupt.exp: child process ate our char a Ambiguous command "a": actions, add-auto-load-safe-path, add-auto-load-scripts-directory, add-inferior... (gdb) ERROR: "" is not a unique command name. The problem is that inflow.c:child_terminal_inferior is failing to put the inferior in the foreground, because we're passing down the inferior's Windows PID instead of the Cygwin PID to Cygwin tcsetpgrp. That is fixed by this commit. Afterwards we will get: (gdb) continue Continuing. talk to me baby PASS: gdb.base/interrupt.exp: process is alive a a <<< GOOD PASS: gdb.base/interrupt.exp: child process ate our char [New Thread 7236.0x1c58] Thread 6 received signal SIGINT, Interrupt. <<< new thread spawned for SIGINT [Switching to Thread 7236.0x1c58] 0x00007ffa6643ea6b in TlsGetValue () from /cygdrive/c/Windows/System32/KERNELBASE.dll (gdb) FAIL: gdb.base/interrupt.exp: send_gdb control C We still have the FAIL seen above because this change has another consequence. By failing to put the inferior in the foreground correctly, Ctrl-C was always reaching GDB first. Now that the inferior is put in the foreground properly, Ctrl-C reaches the inferior first, which results in a Windows Ctrl-C event, which results in Windows injecting a new thread in the inferior to report the Ctrl-C exception => SIGINT. That is, running the test manually: Before patch: (gdb) c Continuing. [New Thread 2352.0x1f5c] [New Thread 2352.0x1988] [New Thread 2352.0x18cc] <<< Ctrl-C pressed. Thread 7 received signal SIGTRAP, Trace/breakpoint trap. [Switching to Thread 2352.0x18cc] 0x00007ffa68930b11 in ntdll!DbgBreakPoint () from /cygdrive/c/Windows/SYSTEM32/ntdll.dll (gdb) Above, GDB got the SIGINT, and it manually passes it down the inferior, which reaches windows_nat_target::interrupt(), which interrupts the inferior with DebugBreakProcess (which injects a new thread in the inferior that executes an int3 instruction). After this patch, we have (with "set debugexceptions on" so DBG_CONTROL_C is visible): (gdb) c Continuing. [New Thread 9940.0x1168] [New Thread 9940.0x5f8] gdb: Target exception MS_VC_EXCEPTION at 0x7ffa6638cf19 gdb: Target exception MS_VC_EXCEPTION at 0x7ffa6638cf19 [New Thread 9940.0x3d8] gdb: Target exception DBG_CONTROL_C at 0x7ffa6643ea6b <<< Ctrl-C Thread 7 received signal SIGINT, Interrupt. <<< new injected thread [Switching to Thread 9940.0x3d8] 0x00007ffa6643ea6b in TlsGetValue () from /cygdrive/c/Windows/System32/KERNELBASE.dll (gdb) This new behavior is exactly the same as what you see with a MinGW GDB build. Also, SIGINT reaching inferior first is what you get on Linux as well currently. I wrote an initial fix for this before I discovered that Cygwin downstream had a similar change, so I then combined the patches. I am adding a Co-Authored-By for that reason. Co-Authored-By: Takashi Yano <takashi.yano@nifty.ne.jp> Approved-By: Tom Tromey <tom@tromey.com> Change-Id: I3a8c3355784c6a817dbd345ba9dac24be06c4b3f
2024-02-27arc: Don't build arc-analyze-prologue.S with -gYuriy Kolerov1-1/+7
arc-analyze-prologue.S test does not contain debug information thus it must be compiled without -g option. Otherwise GDB will try to unwind frames using debug information (which does not exist for .S code!) instead of analyzing frames manually. Approved-By: Shahab Vahedi <shahab@synopsys.com>
2024-02-26gdb/amd-dbgapi: fix indentationSimon Marchi1-1/+1
Change-Id: Ia7a001020758edd2031d0d413d023d2808dd40a0
2024-02-26Remove two unnecessary castsTom Tromey2-2/+2
I noticed a spot in ada-lang.c where the return value of value_as_address was cast to CORE_ADDR -- a no-op cast. I searched and found another. This patch fixes both.
2024-02-26[gdb] Fix heap-use-after-free in select_event_lwpPedro Alves1-9/+25
PR gdb/31259 reveals one scenario where we run into a heap-use-after-free reported by thread sanitizer, while running gdb.base/vfork-follow-parent.exp. The heap-use-after-free happens during the following scenario: - linux_nat_wait_1 is about to return an event for T2. It stops all other threads, and while doing so, stop_wait_callback -> wait_lwp sees T1 exit, and decides to leave the exit event pending. It should have set the lp->stopped flag too, but does not -- this is the bug. - The event for T2 is reported, is processed by infrun, and we're back at linux_nat_wait_1. - linux_nat_wait_1 selects LWP T1 with the pending exit status to report. - it sets variable lp to point to the corresponding lwp_info. - it calls stop_callback and stop_wait_callback for all threads (because !target_is_non_stop_p ()). - it calls select_event_lwp to maybe pick another thread than T1, to prevent starvation. The problem is the following: - while calling stop_wait_callback for all threads, it also does this for T1. While doing so, the corresponding lwp_info is deleted (callstack stop_wait_callback -> wait_lwp -> exit_lwp -> delete_lwp), leaving variable lp as a dangling pointer. - variable lp is passed to select_event_lwp, which derefences it, which causes the heap-use-after-free. Note that the comment here mentions "all other LWP's": ... /* Now stop all other LWP's ... */ iterate_over_lwps (minus_one_ptid, stop_callback); /* ... and wait until all of them have reported back that they're no longer running. */ iterate_over_lwps (minus_one_ptid, stop_wait_callback); ... The reason the comments say "all other LWP's", and doesn't bother filtering out LP is that lp->stopped should be true at this point, and the callbacks (both stop_callback and stop_wait_callback) check that flag, and do nothing if set. I.e., they skip already-stopped threads, so they should skip LP. In this particular scenario, though, we missed setting the stopped flag right in the first step described above, so LP was iterated over incorrectly. The fix is to make wait_lwp set the lp->stopped flag when it decides to leave the exit event pending. However, going a bit further, gdbserver has a mark_lwp_dead function to centralize setting up various lwp flags such that the rest of the code doesn't mishandle them, and it seems like a good idea to do a similar thing in gdb as well. That is what this patch does. PR gdb/31259 Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=31259 Co-Authored-By: Tom de Vries <tdevries@suse.de> Change-Id: I4a6169976f89bf714c478cbb2b7d4c32365e62a9
2024-02-26[gdb/testsuite] Dump dap.log.$n to gdb.log when exceptions foundTom de Vries1-0/+3
For a patch I submitted, the Linaro CI reported a failure: ... FAIL: gdb.dap/attach.exp: exceptions in log file ... I ran the test-case locally, and observed the same FAIL in the gdb.sum file. I then wanted to confirm that I reproduced the exact same problem, but realized that I couldn't because there's no way for me to know what exception occurred, and where, because that information is logged in the dap.log.$n file, and the Linaro CI only saves the gdb.sum and gdb.log files. This issue is even worse if only the CI can reproduce a FAIL. Fix this in dap_check_log_file by dumping dap.log.$n to gdb.log when exceptions are found. Tested on x86_64-linux. Approved-By: Tom Tromey <tom@tromey.com>
2024-02-26[gdb/testsuite] Further handle long filenames in gdb.base/startup-with-shell.expTom de Vries1-0/+1
In commit 52498004a34 ("gdb/testsuite: handle long filenames in gdb.base/startup-with-shell.exp") we fixed a FAIL reported by the Linaro CI: ... (gdb) print argv[1] $1 = 0xfffed978 "<snip>/startup-with-shell/unique-file.unique-e"... (gdb) FAIL: gdb.base/startup-with-shell.exp: startup_with_shell = on; \ run_args = *.unique-extension: first argument expanded ... PR testsuite/31410 reports a similar failure: ... (gdb) print argv[1] $1 = 0xfffeda96 "<snip>/startup-with-shell/*.unique-extens"... (gdb) FAIL: gdb.base/startup-with-shell.exp: startup_with_shell = off; \ run_args = *.unique-extension: first argument not expanded ... Fix this in the same way, using "set print characters unlimited". Tested on x86_64-linux. Approved-By: Tom Tromey <tom@tromey.com> Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=31410
2024-02-26[gdb] Fix "value is not available" with debug frameTom de Vries4-0/+106
On arm-linux, with a started hello world, running "info frame" works fine, but when I set debug frame to on, I run into: ... (gdb) info frame ... [frame] frame_unwind_register_value: exit value is not available (gdb) ... The problem is here in frame_unwind_register_value: ... if (value->lazy ()) gdb_printf (&debug_file, " lazy"); else { int i; gdb::array_view<const gdb_byte> buf = value->contents (); ... where we call value->contents () while !value->entirely_available (). Fix this by checking value->entirely_available () and printing: ... [frame] frame_unwind_register_value: -> register=91 unavailable ... Tested on arm-linux. PR gdb/31369 Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=31369
2024-02-26gdb: Modify the output of "info breakpoints" and "delete breakpoints"Tiezhu Yang43-116/+124
The output of "info breakpoints" includes breakpoint, watchpoint, tracepoint, and catchpoint if they are created, so it should show all the four types are deleted in the output of "info breakpoints" to report empty list after "delete breakpoints". It should also change the output of "delete breakpoints" to make it clear that watchpoints, tracepoints, and catchpoints are also being deleted. This is suggested by Guinevere Larsen, thank you. $ make check-gdb TESTS="gdb.base/access-mem-running.exp" $ gdb/gdb gdb/testsuite/outputs/gdb.base/access-mem-running/access-mem-running [...] (gdb) break main Breakpoint 1 at 0x12000073c: file /home/loongson/gdb.git/gdb/testsuite/gdb.base/access-mem-running.c, line 32. (gdb) watch global_counter Hardware watchpoint 2: global_counter (gdb) trace maybe_stop_here Tracepoint 3 at 0x12000071c: file /home/loongson/gdb.git/gdb/testsuite/gdb.base/access-mem-running.c, line 27. (gdb) catch fork Catchpoint 4 (fork) (gdb) info breakpoints Num Type Disp Enb Address What 1 breakpoint keep y 0x000000012000073c in main at /home/loongson/gdb.git/gdb/testsuite/gdb.base/access-mem-running.c:32 2 hw watchpoint keep y global_counter 3 tracepoint keep y 0x000000012000071c in maybe_stop_here at /home/loongson/gdb.git/gdb/testsuite/gdb.base/access-mem-running.c:27 not installed on target 4 catchpoint keep y fork Without this patch: (gdb) delete breakpoints Delete all breakpoints? (y or n) y (gdb) info breakpoints No breakpoints or watchpoints. (gdb) info breakpoints 3 No breakpoint or watchpoint matching '3'. With this patch: (gdb) delete breakpoints Delete all breakpoints, watchpoints, tracepoints, and catchpoints? (y or n) y (gdb) info breakpoints No breakpoints, watchpoints, tracepoints, or catchpoints. (gdb) info breakpoints 3 No breakpoint, watchpoint, tracepoint, or catchpoint matching '3'. Signed-off-by: Tiezhu Yang <yangtiezhu@loongson.cn> Approved-by: Kevin Buettner <kevinb@redhat.com> Reviewed-By: Eli Zaretskii <eliz@gnu.org>
2024-02-26gdb: s390: Add arch14 record/replay supportAndreas Arnez1-0/+13
Enable recording of the new "arch14" instructions on z/Architecture targets, except for the specialized-function-assist instruction NNPA.
2024-02-24[gdb/build] Fix static cast of virtual baseTom de Vries1-2/+2
With this change in bfd/development.sh: ... -development=true +development=false ... we run into: ... In file included from tui-data.h:28:0, from tui-command.c:24: gdb-checked-static-cast.h: In instantiation of \ ‘T gdb::checked_static_cast(V*) [with T = tui_cmd_window*; V = tui_win_info]’: tui-command.c:65:15: required from here gdb-checked-static-cast.h:63:14: error: cannot convert from pointer to base \ class ‘tui_win_info’ to pointer to derived class ‘tui_cmd_window’ because \ the base is virtual T result = static_cast<T> (v); ^~~~~~~~~~~~~~~~~~ ... Fix this by using dynamic_cast instead of gdb::checked_static_cast in TUI_CMD_WIN and TUI_STATUS_WIN. Tested on x86_64-linux, with development set to false. Reported-By: Robert Xiao <spam_hole@shaw.ca> Reported-By: Simon Marchi <simark@simark.ca> Approved-By: Tom Tromey <tom@tromey.com> PR build/31399 Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=31399
2024-02-23gdb: disable formatting-related flake8 warningsSimon Marchi1-0/+8
Tom Tromey pointed out that flake8 gives some warnings related to formatting, such as: python/lib/gdb/prompt.py:149:43: E203 whitespace before ':' We don't care about those, since all our formatting is handled automatically by black, so ignore these warnings. The list of warnings I put comes from: https://black.readthedocs.io/en/stable/guides/using_black_with_other_tools.html#flake8 Note that since the setup.cfg file is under the gdb directory, it will be picked up if you run flake8 from the gdb directory like this: binutils-gdb/gdb $ flake8 python but not if you do: binutils-gdb $ flake8 gdb/python Change-Id: I1e42aefd388b9c3b6c9d52b4f635ac881db4bbc1 Approved-By: Tom Tromey <tom@tromey.com>
2024-02-23Remove unused importTom Tromey1-1/+1
flake8 points out that dap/io.py does not use send_gdb. This patch removes the unused import.
2024-02-23gdb/linux-nat.c: Add "Accessing inferior memory" sectionPedro Alves1-1/+57
This commit adds a new "Accessing inferior memory" comment section to gdb/linux-nat.c that explains why we prefer /proc/pid/mem over alternatives. Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=30453 Change-Id: I575b21ed697a85f3ff4c0ec58c04812db5005b76
2024-02-23Drop special way of getting inferior context after a Cygwin signalJon Turney1-37/+15
Simplify Cygwin signal handling by dropping the special way of getting inferior context after a Cygwin signal. I think the reason this existed was because previously we were not able to unwind through the alternate stack used by _sigfe frames, so without the hint of the "user" code IP, the backtrace from a signal was unusable. Now we can unwind through _sigfe frames, drop all this complexity. (Restoring this specially obtained context to the inferior (as the code currently does) skips over the actual signal delivery and handling. Cygwin has carried for a long time a patch which clears the ContextFlags in the signal context, so we never attempt to restore it to the inferior, but that interfers with gdb's ability to modify that context e.g. if it decides it wants to turn on FLAG_TRACE_BIT.) Change-Id: I214edd5a99fd17c1a31ad18138d4a6cc420225e3
2024-02-23Teach gdb how to unwind cygwin _sigbe and sigdelayed framesJon Turney4-0/+260
The majority of functions in the cygwin DLL are wrapped by routines which use an an alternate stack to return via a signal handler if a signal occured while inside the function. (See [1],[2]) At present, these frames cannot be correctly unwound by gdb. There doesn't seem to currently be a way to correctly describe these frames using DWARF CFI. So instead, write a custom unwinder for _sigbe and sigdelayed frames, which gets the return address from the alternate stack. The offset of tls::stackptr from TIB.stacktop is determined by analyzing the code in _sigbe or sigdelayed. This can backtrace from _sigbe and from a sighandler through sigdelayed. Implemented for amd64 and i386 Issues: 1. We should detect if we are in the wrapper after the return address has been popped off the alternate stack, and if so, fetch the return address from the register it's been popped into. 2. If there are multiple _sigbe or sigdelayed stack frames to be unwound, this only unwinds the first one correctly, because we don't unwind the value of the alternate stack pointer itself. This is no worse than currently, when we can't even unwind one of these frame correctly, but isn't quite correct. I guess this could be handled by defining a pseudo-register to track its value as we unwind the stack. [1] https://sourceware.org/git/gitweb.cgi?p=newlib-cygwin.git;a=blob;f=winsup/cygwin/gendef [2] https://sourceware.org/git/gitweb.cgi?p=newlib-cygwin.git;a=blob;f=winsup/cygwin/how-signals-work.txt Co-Authored-By: Pedro Alves <pedro@palves.net> Change-Id: I4a0d02c1b85d0aadaab2de3abd584eb4bda5b5cc
2024-02-22gdb: Add XMM16-XMM31 and K0-K1 DWARF register number mappingH.J. Lu1-1/+22
Add XMM16-XMM31 and K0-K1 DWARF register number mapping to amd64_dwarf_regmap. Reviewed-By: Felix Willgerodt <felix.willgerodt@intel.com> Approved-By: John Baldwin <jhb@FreeBSD.org>
2024-02-22Use bool in dynamic type codeTom Tromey2-27/+27
This changes some of the dynamic-type-related code to use bool rather than int. Regression tested on x86-64 Fedora 38. Approved-By: John Baldwin <jhb@FreeBSD.org>
2024-02-22[gdb/testsuite] Fix license text in gdb.reverse/map-to-same-line.{c,exp}Tom de Vries2-2/+2
I noticed in gdb.reverse/map-to-same-line.{c,exp} that the license urls are using some kind of indirection via urldefense.proofpoint.com. Fix this by removing this indirection. Tested on x86_64-linux. PR testsuite/31358 Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=31358
2024-02-22[gdb/dap] Fix race between dap exit and gdb exitTom de Vries2-1/+18
When DAP shuts down due to an EOF event, there's a race between: - gdb's main thread handling a SIGHUP, and - the DAP main thread exiting. Fix this by waiting for DAP's main thread exit during the gdb_exiting event. Tested on aarch64-linux. Approved-By: Tom Tromey <tom@tromey.com> PR dap/31380 Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=31380
2024-02-22[gdb/dap] Fix race between dap startup and dap log fileTom de Vries4-4/+52
In dap_gdb_start we do: ... append GDBFLAGS " -iex \"set debug dap-log-file $logfile\" -q -i=dap" ... While the dap log file setting comes before the dap interpreter setting, the order is the other way around: - first, the dap interpreter is started - second, the -iex commands are executed and the log file is initialized. Consequently, there's a race between dap interpreter startup and dap log file initialization. This cannot be fixed by using -eiex instead. Before the interpreter is started, the "set debug dap-log-file" command is not yet registered. Fix this by postponing the start of the DAP server until GDB has processed all command files. Tested on aarch64-linux. Approved-By: Tom Tromey <tom@tromey.com> PR dap/31386 Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=31386
2024-02-22[gdb/dap] Factor out thread_logTom de Vries1-3/+12
In thread_wrapper I used a style where a message is prefixed with the thread name. Factor this out into a new function thread_log. Also treat the GDB main thread special, because it's usual name is MainThread: ... MainThread: <msg> ... which is the default name assigned by python, so instead use the more explicit: ... GDB main: <msg> ... Tested on aarch64-linux. Approved-By: Tom Tromey <tom@tromey.com>
2024-02-21Don't allow multiple request registrations in DAPTom Tromey1-0/+2
This changes the DAP code to check that a given request or capability is only registered a single time. This is just a precaution against accidentally introducing a second definition of a request somewhere.
2024-02-21gdbsupport: assume that compiler supports ↵Simon Marchi4-14/+0
std::{is_trivially_constructible,is_trivially_copyable} This code was there to support g++ 4, which didn't support std::is_trivially_constructible and std::is_trivially_copyable. Since we now require g++ >= 9, I think it's fair to assume that GDB will always be compiled with a compiler that supports those. Change-Id: Ie7c1649139a2f48bf662cac92d7f3e38fb1f1ba1
2024-02-21gdb: remove some GCC version checksSimon Marchi1-6/+0
Since we now require C++17, and therefore gcc >= 9, it's no longer useful to have gcc version checks for older gcc version. Change-Id: I3a87baa03c475f2b847b422b16b69c5ff7215b54 Reviewed-by: Kevin Buettner <kevinb@redhat.com> Approved-By: Pedro Alves <pedro@palves.net>
2024-02-21[gdb/testsuite] Fix error handling in _dap_read_jsonTom de Vries1-4/+23
In _dap_read_json we have a gdb_expect with clauses that generate errors: ... timeout { error "timeout reading json header" } eof { error "eof reading json header" } ... Proc gdb_expect uses dejagnu's remote_expect, which has some peculiar semantics related to errors: ... # remote_expect works basically the same as standard expect, but it # also takes care of getting the file descriptor from the specified # host and also calling the timeout/eof/default section if there is an # error on the expect call. ..... When a timeout triggers, it generates a timeout error, which is reported by gdb_expect, after which it runs the timeout/eof/default clauses, which generates an eof error, which is reported by runtest. I think the intention here is to generate just a one error, a timeout error. Fix this by postponing generating the error until after gdb_expect. Tested on x86_64-linux, by: - running all the DAP test-cases and observing no regressions, and - modifying the gdb.dap/eof.exp test-case to trigger a timeout error, and observing only a timeout error. PR testsuite/31382 Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=31382
2024-02-21arc: Determine a branch target of DBNZ correctlyYuriy Kolerov3-0/+154
DBNZ instruction was moved from BRANCH class to a separate one - DBNZ. Thus, it must be processed separately in arc_insn_get_branch_target to correctly determine an offset for a possible branch. The testsuite for DBNZ instruction verifies these cases: 1. Check that dbnz does not branch and falls through if its source register is 0 after decrementing. GDB must successfully break on the following instruction after stepping over. 2. Check that dbnz branches to the target correctly if its source register is not 0 after decrementing - GDB must successfully break on the target instruction if a forward branch is performed after stepping over. 3. The same as point 2 but for a backward branching case. Signed-off-by: Yuriy Kolerov <kolerov93@gmail.com>