aboutsummaryrefslogtreecommitdiff
path: root/gdb
AgeCommit message (Collapse)AuthorFilesLines
2023-11-16gdb/NEWS: merge two 'New commands' sectionsAndrew Burgess1-10/+8
Spotted that we'd gained two 'New commands' sections in our 'Changes since GDB 14' NEWS file block. I've merged them together. Also, one of these two sections was actually called 'New Commands', however, all the other places in the NEWS file use 'New commands', so I've changed to use that.
2023-11-16gdb: mips: Change E_MIPS_* to EF_MIPS_*Ying Huang1-8/+8
According to we have changed all E_MIPS_* to EF_MIPS_* in binutils and glibc, we also need to change it here to keep same style. We can refer to this commit record: https://sourceware.org/pipermail/binutils/2023-October/129904.html Approved-By: Pedro Alves <pedro@palves.net>
2023-11-15Fix gdb.threads/threads-after-exec.exp racePedro Alves1-3/+7
Simon noticed that gdb.threads/threads-after-exec.exp was racy. You can consistenly reproduce it (at git hash 319b460545dc79280e2904dcc280057cf71fb753), with: $ taskset -c 0 make check TESTS="gdb.threads/threads-after-exec.exp" gdb.log shows: (...) Thread 3 "threads-after-e" hit Catchpoint 2 (exec'd .../gdb.threads/threads-after-exec/threads-after-exec), 0x00007ffff7fe3290 in _start () from /lib64/ld-linux-x86-64.so.2 (gdb) PASS: gdb.threads/threads-after-exec.exp: continue until exec info threads Id Target Id Frame * 3 process 1443269 "threads-after-e" 0x00007ffff7fe3290 in _start () from /lib64/ld-linux-x86-64.so.2 (gdb) FAIL: gdb.threads/threads-after-exec.exp: info threads (...) maint info linux-lwps LWP Ptid Thread ID 1443269.1443269.0 1.3 (gdb) FAIL: gdb.threads/threads-after-exec.exp: maint info linux-lwps The FAILs happen because the .exp file expects that after the exec, the only thread has GDB thread number 1, but it has instead 3. This is yet another case of zombie leader detection making things a bit fuzzy. In the passing case, we have: continue Continuing. [New Thread 0x7ffff7bff640 (LWP 603183)] [Thread 0x7ffff7bff640 (LWP 603183) exited] process 603180 is executing new program: .../gdb.threads/threads-after-exec/threads-after-exec While in the failing case, we have (note remarks on the rhs): continue Continuing. [New Thread 0x7ffff7bff640 (LWP 600205)] [Thread 0x7ffff7f95740 (LWP 600202) exited] <<< gdb deletes leader thread, thread 1. [New LWP 600202] <<< gdb adds it back -- this is now thread 3. [Thread 0x7ffff7bff640 (LWP 600205) exited] process 600202 is executing new program: .../threads-after-exec/threads-after-exec The testcase only has two threads, yet GDB presented the exec for thread 3. This is GDB deleting the leader (the backend detected it was zombie, due to the exec), and then adding the leader back when it saw the exec event. I've recorded some thoughts about this in PR gdb/31069. For now, this commit just makes the testcase cope with the non-one thread number, as the number is not important for what this test is exercising. Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=31069 Change-Id: Id80b5c73f09c9e0005efeb494cca5d066ac3bbae
2023-11-15Check gdb_python_module in gdbpy_handle_missing_debuginfoTom Tromey1-1/+1
If you run gdb in the build tree without --data-directory, on a program that does not have debug info, it will crash, because gdbpy_handle_missing_debuginfo unconditionally uses gdb_python_module. Other code in gdb using gdb_python_module checks it first and it seemes harmless to do the same thing here. (gdb_python_initialized does not cover this case so that python can be partially initialized and still somewhat work.)
2023-11-15Minor cleanups in ada-nested.expTom Tromey1-5/+9
This changes ada-nested.exp to fix a test name (the test expects three variables but is named "two"), and to iterate over all the variables that are found. It also adds a workaround to a problem Tom de Vries found with an older version of GNAT -- it emits a duplicate "x".
2023-11-15Finalized intl-update patches (trois)Sam James1-5/+5
Doing this on behalf of Arsen as obvious. Hopefully the last fixup. * gdb: Regenerate. * gnulib: Regenerate.
2023-11-15Finalized intl-update patches (deux)Sam James1-5/+5
Doing this on behalf of Arsen as obvious. * gdb: Regenerate. * gdbserver: Regenerate. * gprofng: Regenerate.
2023-11-15Finalized intl-update patchesArsen Arsenovi?4-759/+2432
* intl: Remove directory. Replaced with out-of-tree GNU gettext. * .gitignore: Add '/gettext*'. * configure.ac (host_libs): Replace intl with gettext. (hbaseargs, bbaseargs, baseargs): Split baseargs into {h,b}baseargs. (skip_barg): New flag. Skips appending current flag to bbaseargs. <library exemptions>: Exempt --with-libintl-{type,prefix} from target and build machine argument passing. * configure: Regenerate. * Makefile.def (host_modules): Replace intl module with gettext module. (configure-ld): Depend on configure-gettext. * Makefile.in: Regenerate. * src-release.sh: Remove references to the intl/ directory.
2023-11-14Remove path name from test caseTom Tromey1-1/+2
'runtest' complains about a path in a test name, from the new test case py-missing-debug.exp. This patch fixes the problem by providing an explicit test name to gdb_test. I chose something very basic because the block in question is already wrapped in with_test_prefix.
2023-11-14Remove some redundant "break"sTom Tromey1-4/+0
I found some "break" statements that follow "return" or a call to a noreturn function. These aren't needed, and the compiler would warn if they were. So, this patch removes them. Tested by rebuilding.
2023-11-14Update gdb.Symbol.is_variable documentationTom Tromey1-1/+3
Kévin found a bug in an earlier version of this series that was based on a misconception I had about Symbol.is_variable. This patch fixes the documentation to explain the method a bit better. Approved-By: Eli Zaretskii <eliz@gnu.org>
2023-11-14Handle the static link in FrameDecoratorTom Tromey3-13/+174
A co-worker requested that the DAP scope for a nested function's frame also show the variables from outer frames. DAP doesn't directly support this notion, so this patch arranges to put these variables into the inner frames "Locals" scope. I chose to do this only for DAP. For CLI and MI, gdb currently does not do this, so this preserves the behavior. Note that an earlier patch (see commit 4a1311ba) removed some code that seemed to do something similar. However, that code did not actually work.
2023-11-14Fix a bug in DAP scopes codeTom Tromey1-2/+6
While working on static links, I noticed that the DAP scopes code does not handle the scenario where a frame decorator returns None. This situation should be handled identically to a frame decorator returning an empty iterator.
2023-11-14Add gdb.Frame.static_link methodTom Tromey3-0/+39
This adds a new gdb.Frame.static_link method to the gdb Python layer. This can be used to find the static link frame for a given frame. Reviewed-By: Eli Zaretskii <eliz@gnu.org>
2023-11-14Move follow_static_link to frame.cTom Tromey3-53/+53
This moves the follow_static_link function to frame.c and exports it for use elsewhere. The API is changed slightly to make it more generically useful.
2023-11-14Add block::function_blockTom Tromey2-0/+19
This adds the method block::function_block, to easily access a block's enclosing function block.
2023-11-14Add two convenience methods to blockTom Tromey2-3/+17
This adds a couple of convenience methods, block::is_static_block and block::is_global_block.
2023-11-14gdb/MAINTAINERS: add Guinevere Larsen as record-full maintainerSimon Marchi1-0/+1
Change-Id: I67d8361560ce0fa553b2983184c9d18df8dbeb4a
2023-11-14gdb/MAINTAINERS: add Luis Machado as global maintainerSimon Marchi1-1/+1
Change-Id: I211d64393f5c0da3c9ce1fcf5486504d34ed38f4
2023-11-14gdb/MAINTAINERS: add John Baldwin as global maintainerSimon Marchi1-1/+1
Change-Id: Ic9164fd19c3da1381302a17176e8f0f814e9ac6c
2023-11-14gdb: normalize whitespaces in MAINTAINERSSimon Marchi1-13/+13
Replace some spaces with tabs. Change-Id: I89bbabd6610219649e7e99cd0dd7b0ed66d69b09
2023-11-14[gdb/tui] Factor out tui_noscroll_window et alTom de Vries3-66/+93
I noticed that tui_locator_window has an empty do_scroll_vertical and do_scroll_horizontal, like tui_cmd_window, but unlike tui_cmd_window doesn't have: ... bool can_scroll () const override { return false; } ... I suspect that it probably doesn't matter, but regardless it's good to have the same implementations of basic properties in all windows. Ensure this by adding a class tui_noscroll_window, that has: - an empty do_scroll_vertical and do_scroll_horizontal, and - a can_scroll returning false which both tui_locator_window and tui_cmd_window inherit. Make all methods final to ensure no accidental overrides are left in the inheriting classes. Likewise add new classes representing basic window properties: - tui_nofocus_window, - tui_oneline_window, - tui_nobox_window, - tui_norefresh_window, and - tui_always_visible_window. The changes are only a refactoring, apart from adding the "final", which does limit the range of behaviours for subclasses. Tested on x86_64-linux. Approved-By: Tom Tromey <tom@tromey.com>
2023-11-14gdb: refactor make-target-delegates.py's ARGTYPESTankut Baris Aktemur1-6/+7
Refactor the ARGTYPES regular expression in make-target-delegates.py to eliminate '.*' for better control on what is matched. Also, simplify the "E" match group, for which the optional SYMBOL becomes redundant because that case can be matched by the "T" group. After applying this patch, running './make-target-delegates.py' does not change anything in 'target-delegates.c'. Approved-By: Pedro Alves <pedro@palves.net>
2023-11-14gdb: regenerate target-delegates.cTankut Baris Aktemur1-2/+2
I ran './make-target-delegates.py' and there is one minor difference, where an older style declaration is converted to a newer initialization style. Add this change. Approved-By: Pedro Alves <pedro@palves.net>
2023-11-14[gdb/testsuite] Fix gdb.threads/stepi-over-clone.exp regexpTom de Vries1-5/+9
I ran into the following FAIL: ... (gdb) PASS: gdb.threads/stepi-over-clone.exp: catch process syscalls continue^M Continuing.^M ^M Catchpoint 2 (call to syscall clone), clone () at \ ../sysdeps/unix/sysv/linux/x86_64/clone.S:78^M warning: 78 ../sysdeps/unix/sysv/linux/x86_64/clone.S: \ No such file or directory^M (gdb) FAIL: gdb.threads/stepi-over-clone.exp: continue ... All but one regexps in the .exp file use "clone\[23\]?" with "?" to also accept "clone", except the failing case. This commit fixes that case to also use "?". Furthermore, there are FAILs like this: ... (gdb) PASS: gdb.threads/stepi-over-clone.exp: third_thread=false: \ non-stop=on: displaced=off: i=0: continue stepi^M [New Thread 0x7ffff7ff8700 (LWP 15301)]^M Hello from the first thread.^M 78 in ../sysdeps/unix/sysv/linux/x86_64/clone.S^M (gdb) XXX: Consume the initial command XXX: Consume new thread line XXX: Consume first worker thread message FAIL: gdb.threads/stepi-over-clone.exp: third_thread=false: non-stop=on: \ displaced=off: i=0: stepi ... because this output is expected instead: ... Hello from the first thread.^M 0x00000000004212cd in clone3 ()^M ... The root cause for the difference is the presence of .debug_line info for clone. Fix this by updating the relevant regexps. Tested on x86_64-linux, specifically: - openSUSE Leap 15.4 (where the FAILs where observed), and - openSUSE Tumbleweed (where the FAILs where not observed). Co-Authored-By: Pedro Alves <pedro@palves.net> Approved-By: Pedro Alves <pedro@palves.net> Change-Id: I74ca9e7d4cfe6af294fd50e8c509fcbad289b78c
2023-11-14gdb: implement missing debug handler hook for PythonAndrew Burgess11-1/+1352
This commit builds on the previous commit, and implements the extension_language_ops::handle_missing_debuginfo function for Python. This hook will give user supplied Python code a chance to help find missing debug information. The implementation of the new hook is pretty minimal within GDB's C++ code; most of the work is out-sourced to a Python implementation which is modelled heavily on how GDB's Python frame unwinders are implemented. The following new commands are added as commands implemented in Python, this is similar to how the Python unwinder commands are implemented: info missing-debug-handlers enable missing-debug-handler LOCUS HANDLER disable missing-debug-handler LOCUS HANDLER To make use of this extension hook a user will create missing debug information handler objects, and registers these handlers with GDB. When GDB encounters an objfile that is missing debug information, each handler is called in turn until one is able to help. Here is a minimal handler that does nothing useful: import gdb import gdb.missing_debug class MyFirstHandler(gdb.missing_debug.MissingDebugHandler): def __init__(self): super().__init__("my_first_handler") def __call__(self, objfile): # This handler does nothing useful. return None gdb.missing_debug.register_handler(None, MyFirstHandler()) Returning None from the __call__ method tells GDB that this handler was unable to find the missing debug information, and GDB should ask any other registered handlers. By extending the __call__ method it is possible for the Python extension to locate the debug information for objfile and return a value that tells GDB how to use the information that has been located. Possible return values from a handler: - None: This means the handler couldn't help. GDB will call other registered handlers to see if they can help instead. - False: The handler has done all it can, but the debug information for the objfile still couldn't be found. GDB will not call any other handlers, and will continue without the debug information for objfile. - True: The handler has installed the debug information into a location where GDB would normally expect to find it. GDB should look again for the debug information. - A string: The handler can return a filename, which is the file containing the missing debug information. GDB will load this file. When a handler returns True, GDB will look again for the debug information, but only using the standard built-in build-id and .gnu_debuglink based lookup strategies. It is not possible for an extension to trigger another debuginfod lookup; the assumption is that the debuginfod server is remote, and out of the control of extensions running within GDB. Handlers can be registered globally, or per program space. GDB checks the handlers for the current program space first, and then all of the global handles. The first handler that returns a value that is not None, has "handled" the objfile, at which point GDB continues. Reviewed-By: Eli Zaretskii <eliz@gnu.org> Approved-By: Tom Tromey <tom@tromey.com>
2023-11-14gdb: add an extension language hook for missing debug infoAndrew Burgess4-28/+166
This commit adds a new extension_language_ops hook which allows an extension to handle the case where GDB can't find a separate debug information file for a particular objfile. This commit doesn't actually implement the hook for any of GDB's extension languages, the next commit will do that. This commit just adds support for the hook to extension-priv.h and extension.[ch], and then reworks symfile-debug.c to call the hook. Right now the hook will always return its default value, which means GDB should do nothing different. As such, there should be no user visible changes after this commit. I'll give a brief description of what the hook does here so that we can understand the changes in symfile-debug.c. The next commit adds a Python implementation for this new hook, and gives a fuller description of the new functionality. Currently, when looking for separate debug information GDB tries three things, in this order: 1. Use the build-id to find the required debug information, 2. Check for .gnu_debuglink section and use that to look up the required debug information, 3. Check with debuginfod to see if it can supply the required information. The new extension_language_ops::handle_missing_debuginfo hook is called if all three steps fail to find any debug information. The hook has three possible return values: a. Nothing, no debug information is found, GDB continues without the debug information for this objfile. This matches the current behaviour of GDB, and is the default if nothing is implementing this new hook, b. Install debug information into a location that step #1 or #2 above would normally check, and then request that GDB repeats steps #1 and #2 in the hope that GDB will now find the debug information. If the debug information is still not found then GDB carries on without the debug information. If the debug information is found the GDB loads it and carries on, c. Return a filename for a file containing the required debug information. GDB loads the contents of this file and carries on. The changes in this commit mostly involve placing the core of objfile::find_and_add_separate_symbol_file into a loop which allows for steps #1 and #2 to be repeated. We take care to ensure that debuginfod is only queried once, the first time through. The assumption is that no extension is going to be able to control the replies from debuginfod, so there's no point making a second request -- and as these requests go over the network, they could potentially be slow. The warnings that find_and_add_separate_symbol_file collects are displayed only once assuming that no debug information is found. If debug information is found, even after the extension has operated, then the warnings are not shown; remember, these are warnings from GDB about failure to find any suitable debug information, so it makes sense to hide these if debug information is found. Approved-By: Tom Tromey <tom@tromey.com>
2023-11-14gdb: refactor objfile::find_and_add_separate_symbol_fileAndrew Burgess1-47/+88
This is purely a refactoring commit. This commit splits objfile::find_and_add_separate_symbol_file into some separate helper functions. My hope is that the steps for looking up separate debug information are now clearer. In a later commit I'm going to extend objfile::find_and_add_separate_symbol_file, with some additional logic, so starting with a simpler function will make the following changes easier. When reading objfile::find_and_add_separate_symbol_file after this commit, you might be tempted to think that removing the `has_dwarf` local variable would be a good additional cleanup. After the next commit though it makes more sense to retain this local, so I've left this in place for now. There should be no user visible changes after this commit. Approved-By: Tom Tromey <tom@tromey.com>
2023-11-14gdb: merge debug symbol file lookup code from coffread & elfread pathsAndrew Burgess4-76/+81
This commit merges the code that looks for and loads the separate debug symbol files from coffread.c and elfread.c. The factored out code is moved into a new objfile::find_and_add_separate_symbol_file() method. For the elfread.c path there should be no user visible changes after this commit. For the coffread.c path GDB will now attempt to perform a debuginfod lookup for the missing debug information, assuming that GDB can find a build-id in the COFF file. I don't know if COFF files can include a build-id, but I the existing coffread.c code already includes a call to find_separate_debug_file_by_build-id, so I know that it is at least OK for GDB to ask a COFF file for a build-id. If the COFF file doesn't include a build-id then the debuginfod lookup code will not trigger and the new code is harmless. If the COFF file does include a build-id, then we're going to end up asking debuginfod for the debug file. As build-ids should be unique, this should be harmless, even if debuginfod doesn't contain any suitable debug data, it just costs us one debuginfod lookup, so I'm not too worried about this for now. As with the previous commit, I've done some minimal testing using the mingw toolchain on a Linux machine, GDB seems to still access the split debug information just fine. Approved-By: Tom Tromey <tom@tromey.com>
2023-11-14gdb/coffread: bring separate debug file logic into line with elfread.cAndrew Burgess1-1/+3
In this commit: commit 8a92335bfca80cc9b4cd217505ea0dcbfdefbf07 Date: Fri Feb 1 19:39:04 2013 +0000 the logic for when we try to load a separate debug file in elfread.c was extended. The new code checks that the objfile doesn't already have a separate debug objfile linked to it, and that the objfile isn't itself a separate debug objfile for some other objfile. The coffread code wasn't extended at the same time. I don't know if it's possible for the coffread code to get into the same state where these checks are needed, but I don't see why having these checks would be a problem. In a later commit I plan to merge this part of the elfread and coffread code, so bringing these two pieces of code into line first makes that job easier. I've tested this with a simple test binary compiled with the mingw toolchain on a Linux host. After compiling the binary and splitting out the debug info GDB still finds and loads the separate debug info. Approved-By: Tom Tromey <tom@tromey.com>
2023-11-13[gdb/tui] Don't include border_width in left_marginTom de Vries2-3/+3
Currently left_margin does not match its documentation: ... /* Return the size of the left margin space, this is the space used to display things like breakpoint markers. */ int left_margin () const { return box_width () + TUI_EXECINFO_SIZE + extra_margin (); } ... It is stated that the left margin is reserved to display things, but the box_width is not used for that. Fix this by dropping box_width () from the left_margin calculation. Tested on x86_64-linux. Approved-By: Tom Tromey <tom@tromey.com>
2023-11-13[gdb/tui] Add tui_win_info::{box_width,box_size}Tom de Vries7-19/+35
In tui_source_window::set_contents we have: ... /* Take hilite (window border) into account, when calculating the number of lines. */ int nlines = height - 2; ... The '2' represents the total size of the window border (or box, in can_box terms), in this case one line at the top and one line at the bottom. Likewise, '1' is used to represent the width of the window border. Introduce new functions: - tui_win_info::box_width () and - tui_win_info::box_size () that can be used instead instead of these hardcoded constants. Implement these such that they return 0 when can_box () == false. Tested patch completeness by making all windows unboxed: ... @@ -85,7 +85,7 @@ struct tui_win_info /* Return true if this window can be boxed. */ virtual bool can_box () const { - return true; + return false; } int box_width () const ... and test-driving TUI. This required eliminating an assert in tui_source_window_base::show_source_content, I've included that part as well. Tested on x86_64-linux. Approved-By: Tom Tromey <tom@tromey.com>
2023-11-13[gdb/tui] Refactor prefresh call in tui_source_window_base::refresh_windowTom de Vries1-2/+5
Currently the call to prefresh in tui_source_window_base::refresh_window looks like: ... prefresh (m_pad.get (), 0, pad_x, y + 1, x + left_margin, y + m_content.size (), x + left_margin + view_width - 1); ... This is hard to parse. It's not obvious what the arguments mean, and there's repetition in the argument calculation. Fix this by rewriting the call as follows: - use sminrow, smincol, smaxrow and smaxcol variables for the last 4 arguments, and - calculate the smaxrow and smaxcol variables based on the sminrow and smincol variables. Tested on x86_64-linux. Approved-By: Tom Tromey <tom@tromey.com>
2023-11-13Fix the gdb.ada/inline-section-gc.exp testCarl Love2-4/+20
The original intention of the test appears to be checking to make sure setting a breakpoint in an inlined function didn't set multiple breakpoints where one of them was at address 0. The gdb.ada/inline-section-gc.exp test may pass or fail depending on the version of gnat. Per the discussion on IRC, the ada inlining appears to have some target dependencies. In this test there are two functions, callee and caller. Function calee is inlined into caller. The test sets a breakpoint in function callee. The reported location where the breakpoint is set may be at the requested location in callee or the location in caller after callee has been inlined. The test needs to accept either location as correct provided the breakpoint address is not zero. This patch checks to see if the reported breakpoint is in function callee or function caller and fails if the breakpoint address is 0x0. The line number where the breakpoint is set will match the requested line if the breakpoint location is reported is callee.adb. If the breakpoint is reported in caller.adb, the line number in caller is the breakpoint location in callee where it is inlined into caller. This patch fixes the single regression failure for the test on PowerPC. It does not introduce any failures on X86-64.
2023-11-13Cancel execution command on thread exit, when stepping, nexting, etc.Pedro Alves2-36/+118
If your target has no support for TARGET_WAITKIND_NO_RESUMED events (and no way to support them, such as the yet-unsubmitted AMDGPU target), and you step over thread exit with scheduler-locking on, this is what you get: (gdb) n [Thread ... exited] *hang* Getting back the prompt by typing Ctrl-C may not even work, since no inferior thread is running to receive the SIGINT. Even if it works, it seems unnecessarily harsh. If you started an execution command for which there's a clear thread of interest (step, next, until, etc.), and that thread disappears, then I think it's more user friendly if GDB just detects the situation and aborts the command, giving back the prompt. That is what this commit implements. It does this by explicitly requesting the target to report thread exit events whenever the main resumed thread has a thread_fsm. Note that unlike stepping over a breakpoint, we don't need to enable clone events in this case. With this patch, we get: (gdb) n [Thread 0x7ffff7d89700 (LWP 3961883) exited] Command aborted, thread exited. (gdb) Reviewed-By: Andrew Burgess <aburgess@redhat.com> Change-Id: I901ab64c91d10830590b2dac217b5264635a2b95
2023-11-13Document remote clone events, and QThreadOptions packetPedro Alves2-3/+145
This commit documents in both manual and NEWS: - the new remote clone event stop reply, - the new QThreadOptions packet and its current defined options, - the associated "set/show remote thread-events-packet" command, - and the associated QThreadOptions qSupported feature. Approved-By: Eli Zaretskii <eliz@gnu.org> Change-Id: Ic1c8de1fefba95729bbd242969284265de42427e
2023-11-13Testcases for stepping over thread exit syscall (PR gdb/27338)Simon Marchi6-0/+333
Add new gdb.threads/step-over-thread-exit.exp and gdb.threads/step-over-thread-exit-while-stop-all-threads.exp testcases, exercising stepping over thread exit syscall. These make use of lib/my-syscalls.S to define the exit syscall. Co-authored-by: Pedro Alves <pedro@palves.net> Reviewed-By: Andrew Burgess <aburgess@redhat.com> Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=27338 Change-Id: Ie8b2c5747db99b7023463a897a8390d9e814a9c9
2023-11-13gdb/testsuite/lib/my-syscalls.S: Refactor new SYSCALL macroPedro Alves1-18/+32
Refactor the syscall assembly code in gdb/testsuite/lib/my-syscalls.S behind a SYSCALL macro so that it's easy to add new syscalls without duplicating code. Note that the way the macro is implemented, it only works correctly for syscalls with up to 3 arguments, and, if the syscall doesn't return (the macro doesn't bother to save/restore callee-saved registers). The following patch will want to use the macro to define a wrapper for the "exit" syscall, so the limitations continue to be sufficient. Change-Id: I8acf1463b11a084d6b4579aaffb49b5d0dea3bba Reviewed-By: Andrew Burgess <aburgess@redhat.com>
2023-11-13Don't resume new threads if scheduler-locking is in effectPedro Alves5-9/+164
If scheduler-locking is in effect, e.g., with "set scheduler-locking on", and you step over a function that spawns a new thread, the new thread is allowed to run free, at least until some event is hit, at which point, whether the new thread is re-resumed depends on a number of seemingly random factors. E.g., if the target is all-stop, and the parent thread hits a breakpoint, and GDB decides the breakpoint isn't interesting to report to the user, then the parent thread is resumed, but the new thread is left stopped. I think that letting the new threads run with scheduler-locking enabled is a defect. This commit fixes that, making use of the new clone events on Linux, and of target_thread_events() on targets where new threads have no connection to the thread that spawned them. Testcase and documentation changes included. Approved-By: Eli Zaretskii <eliz@gnu.org> Reviewed-By: Andrew Burgess <aburgess@redhat.com> Change-Id: Ie12140138b37534b7fc1d904da34f0f174aa11ce
2023-11-13stop_all_threads: (re-)enable async before waiting for stopsPedro Alves1-0/+81
Running the gdb.threads/step-over-thread-exit-while-stop-all-threads.exp testcase added later in the series against gdbserver, after the TARGET_WAITKIND_NO_RESUMED fix from the following patch, would run into an infinite loop in stop_all_threads, leading to a timeout: FAIL: gdb.threads/step-over-thread-exit-while-stop-all-threads.exp: displaced-stepping=off: target-non-stop=on: iter 0: continue (timeout) The is really a latent bug, and it is about the fact that stop_all_threads stops listening to events from a target as soon as it sees a TARGET_WAITKIND_NO_RESUMED, ignoring that TARGET_WAITKIND_NO_RESUMED may be delayed. handle_no_resumed knows how to handle delayed no-resumed events, but stop_all_threads was never taught to. In more detail, here's what happens with that testcase: #1 - Multiple threads report breakpoint hits to gdb. #2 - gdb picks one events, and it's for thread 1. All other stops are left pending. thread 1 needs to move past a breakpoint, so gdb stops all threads to start an inline step over for thread 1. While stopping threads, some of the threads that were still running report events that are also left pending. #2 - gdb steps thread 1 #3 - Thread 1 exits while stepping (it steps over an exit syscall), gdbserver reports thread exit for thread 1 #4 - Thread 1 was the last resumed thread, so gdbserver also reports no-resumed: [remote] Notification received: Stop:w0;p3445d0.3445d3 [remote] Sending packet: $vStopped#55 [remote] Packet received: N [remote] Sending packet: $vStopped#55 [remote] Packet received: OK #5 - gdb processes the thread exit for thread 1, finishes the step over and restarts threads. #6 - gdb picks the next event to process out of one of the resumed threads with pending events: [infrun] random_resumed_with_pending_wait_status: Found 32 events, selecting #11 #7 - This is again a breakpoint hit and the breakpoint needs to be stepped over too, so gdb starts a step-over dance again. #8 - We reach stop_all_threads, which finds that some threads need to be stopped. #9 - wait_one finally consumes the no-resumed event queue by #4. Seeing this, wait_one disable target async, to stop listening for events out of the remote target. #10 - We still haven't seen all the stops expected, so stop_all_threads tries another iteration. #11 - Because the remote target is no longer async, and there are no other targets, wait_one return no-resumed immediately without polling the remote target. #12 - We still haven't seen all the stops expected, so stop_all_threads tries another iteration. goto #11, looping forever. Fix this by explicitly enabling/re-enabling target async on targets that can async, before waiting for stops. Reviewed-By: Andrew Burgess <aburgess@redhat.com> Change-Id: Ie3ffb0df89635585a6631aa842689cecc989e33f
2023-11-13gdb: clear step over information on thread exit (PR gdb/27338)Pedro Alves5-17/+174
GDB doesn't handle correctly the case where a thread steps over a breakpoint (using either in-line or displaced stepping), and the executed instruction causes the thread to exit. Using the test program included later in the series, this is what it looks like with displaced-stepping, on x86-64 Linux, where we have two displaced-step buffers: $ ./gdb -q -nx --data-directory=data-directory build/binutils-gdb/gdb/testsuite/outputs/gdb.threads/step-over-thread-exit/step-over-thread-exit -ex "b my_exit_syscall" -ex r Reading symbols from build/binutils-gdb/gdb/testsuite/outputs/gdb.threads/step-over-thread-exit/step-over-thread-exit... Breakpoint 1 at 0x123c: file src/binutils-gdb/gdb/testsuite/lib/my-syscalls.S, line 68. Starting program: build/binutils-gdb/gdb/testsuite/outputs/gdb.threads/step-over-thread-exit/step-over-thread-exit [Thread debugging using libthread_db enabled] Using host libthread_db library "/usr/lib/../lib/libthread_db.so.1". [New Thread 0x7ffff7c5f640 (LWP 2915510)] [Switching to Thread 0x7ffff7c5f640 (LWP 2915510)] Thread 2 "step-over-threa" hit Breakpoint 1, my_exit_syscall () at src/binutils-gdb/gdb/testsuite/lib/my-syscalls.S:68 68 syscall (gdb) c Continuing. [New Thread 0x7ffff7c5f640 (LWP 2915524)] [Thread 0x7ffff7c5f640 (LWP 2915510) exited] [Switching to Thread 0x7ffff7c5f640 (LWP 2915524)] Thread 3 "step-over-threa" hit Breakpoint 1, my_exit_syscall () at src/binutils-gdb/gdb/testsuite/lib/my-syscalls.S:68 68 syscall (gdb) c Continuing. [New Thread 0x7ffff7c5f640 (LWP 2915616)] [Thread 0x7ffff7c5f640 (LWP 2915524) exited] [Switching to Thread 0x7ffff7c5f640 (LWP 2915616)] Thread 4 "step-over-threa" hit Breakpoint 1, my_exit_syscall () at src/binutils-gdb/gdb/testsuite/lib/my-syscalls.S:68 68 syscall (gdb) c Continuing. ... hangs ... The first two times we do "continue", we displaced-step the syscall instruction that causes the thread to exit. When the thread exits, the main thread, waiting on pthread_join, is unblocked. It spawns a new thread, which hits the breakpoint on the syscall again. However, infrun was never notified that the displaced-stepping threads are done using the displaced-step buffer, so now both buffers are marked as used. So when we do the third continue, there are no buffers available to displaced-step the syscall, so the thread waits forever for its turn. When trying the same but with in-line step over (displaced-stepping disabled): $ ./gdb -q -nx --data-directory=data-directory \ build/binutils-gdb/gdb/testsuite/outputs/gdb.threads/step-over-thread-exit/step-over-thread-exit \ -ex "b my_exit_syscall" -ex "set displaced-stepping off" -ex r Reading symbols from build/binutils-gdb/gdb/testsuite/outputs/gdb.threads/step-over-thread-exit/step-over-thread-exit... Breakpoint 1 at 0x123c: file src/binutils-gdb/gdb/testsuite/lib/my-syscalls.S, line 68. Starting program: build/binutils-gdb/gdb/testsuite/outputs/gdb.threads/step-over-thread-exit/step-over-thread-exit [Thread debugging using libthread_db enabled] Using host libthread_db library "/usr/lib/../lib/libthread_db.so.1". [New Thread 0x7ffff7c5f640 (LWP 2928290)] [Switching to Thread 0x7ffff7c5f640 (LWP 2928290)] Thread 2 "step-over-threa" hit Breakpoint 1, my_exit_syscall () at src/binutils-gdb/gdb/testsuite/lib/my-syscalls.S:68 68 syscall (gdb) c Continuing. [Thread 0x7ffff7c5f640 (LWP 2928290) exited] No unwaited-for children left. (gdb) i th Id Target Id Frame 1 Thread 0x7ffff7c60740 (LWP 2928285) "step-over-threa" 0x00007ffff7f7c9b7 in __pthread_clockjoin_ex () from /usr/lib/libpthread.so.0 The current thread <Thread ID 2> has terminated. See `help thread'. (gdb) thread 1 [Switching to thread 1 (Thread 0x7ffff7c60740 (LWP 2928285))] #0 0x00007ffff7f7c9b7 in __pthread_clockjoin_ex () from /usr/lib/libpthread.so.0 (gdb) c Continuing. ^C^C ... hangs ... The "continue" causes an in-line step to occur, meaning the main thread is stopped while we step the syscall. The stepped thread exits when executing the syscall, the linux-nat target notices there are no more resumed threads to be waited for, so returns TARGET_WAITKIND_NO_RESUMED, which causes the prompt to return. But infrun never clears the in-line step over info. So if we try continuing the main thread, GDB doesn't resume it, because it thinks there's an in-line step in progress that we need to wait for to finish, and we are stuck there. To fix this, infrun needs to be informed when a thread doing a displaced or in-line step over exits. We can do that with the new target_set_thread_options mechanism which is optimal for only enabling exit events of the thread that needs it; or, if that is not supported, by using target_thread_events, which enables thread exit events for all threads. This is done by this commit. This patch then modifies handle_inferior_event in infrun.c to clean up any step-over the exiting thread might have been doing at the time of the exit. The cases to consider are: - the exiting thread was doing an in-line step-over with an all-stop target - the exiting thread was doing an in-line step-over with a non-stop target - the exiting thread was doing a displaced step-over with a non-stop target The displaced-stepping buffer implementation in displaced-stepping.c is modified to account for the fact that it's possible that we "finish" a displaced step after a thread exit event. The buffer that the exiting thread was using is marked as available again and the original instructions under the scratch pad are restored. However, it skips applying the fixup, which wouldn't make sense since the thread does not exist anymore. Another case that needs handling is if a displaced-stepping thread exits, and the event is reported while we are in stop_all_threads. We should call displaced_step_finish in the handle_one function, in that case. It was already called in other code paths, just not the "thread exited" path. This commit doesn't make infrun ask the target to report the TARGET_WAITKIND_THREAD_EXITED events yet, that'll be done later in the series. Note that "stop_print_frame = false;" line is moved to normal_stop, because TARGET_WAITKIND_THREAD_EXITED can also end up with the event transmorphed into TARGET_WAITKIND_NO_RESUMED. Moving it to normal_stop keeps it centralized. Co-authored-by: Simon Marchi <simon.marchi@efficios.com> Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=27338 Reviewed-By: Andrew Burgess <aburgess@redhat.com> Change-Id: I745c6955d7ef90beb83bcf0ff1d1ac8b9b6285a5
2023-11-13Implement GDB_THREAD_OPTION_EXIT support for native LinuxPedro Alves1-13/+31
This implements support for the new GDB_THREAD_OPTION_EXIT thread option for native Linux. Reviewed-By: Andrew Burgess <aburgess@redhat.com> Change-Id: Ia69fc0b9b96f9af7de7cefc1ddb1fba9bbb0bb90 Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=27338
2023-11-13Introduce GDB_THREAD_OPTION_EXIT thread option, fix step-over-thread-exitPedro Alves4-5/+24
When stepping over a breakpoint with displaced stepping, GDB needs to be informed if the stepped thread exits, otherwise the displaced stepping buffer that was allocated to that thread leaks, and this can result in deadlock, with other threads waiting for their turn to displaced step, but their turn never comes. Similarly, when stepping over a breakpoint in line, GDB also needs to be informed if the stepped thread exits, so that is can clear the step over state and re-resume threads. This commit makes it possible for GDB to ask the target to report thread exit events for a given thread, using the new "thread options" mechanism introduced by a previous patch. This only adds the core bits. Following patches in the series will teach the Linux backends (native & gdbserver) to handle the GDB_THREAD_OPTION_EXIT option, and then a later patch will make use of these thread exit events to clean up displaced stepping and inline stepping state properly. Reviewed-By: Andrew Burgess <aburgess@redhat.com> Change-Id: I96b719fdf7fee94709e98bb3a90751d8134f3a38 Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=27338
2023-11-13Move deleting thread on TARGET_WAITKIND_THREAD_EXITED to corePedro Alves2-12/+41
Currently, infrun assumes that when TARGET_WAITKIND_THREAD_EXITED is reported, the corresponding GDB thread has already been removed from the GDB thread list. Later in the series, that will no longer work, as infrun will need to refer to the thread's thread_info when it processes TARGET_WAITKIND_THREAD_EXITED. As preparation, this patch makes deleting the GDB thread responsibility of infrun, instead of the target. Reviewed-By: Andrew Burgess <aburgess@redhat.com> Change-Id: I013d87f61ffc9aaca49f0d6ce2a43e3ea69274de
2023-11-13all-stop/synchronous RSP support thread-exit eventsPedro Alves1-1/+6
Currently, GDB does not understand the THREAD_EXITED stop reply in remote all-stop mode. There's no good reason for this, it just happened that THREAD_EXITED was only ever reported in non-stop mode so far. This patch teaches GDB to parse that event in all-stop RSP too. There is no need to add a qSupported feature for this, because the server won't send a THREAD_EXITED event unless GDB explicitly asks for it, with QThreadEvents, or with the GDB_THREAD_OPTION_EXIT QThreadOptions option added in the next patch. Change-Id: Ide5d12391adf432779fe4c79526801c4a5630966
2023-11-13Remove gdb/19675 kfails (displaced stepping + clone)Pedro Alves1-41/+3
Now that gdb/19675 is fixed for both native and gdbserver GNU/Linux, remove the gdb/19675 kfails. Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=19675 Reviewed-By: Andrew Burgess <aburgess@redhat.com> Change-Id: I95c1c38ca370100675d303cd3c8995860bef465d
2023-11-13Thread options & clone events (Linux GDBserver)Pedro Alves1-6/+0
This patch teaches the Linux GDBserver backend to report clone events to GDB, when GDB has requested them with the GDB_THREAD_OPTION_CLONE thread option, via the new QThreadOptions packet. This shuffles code in linux_process_target::handle_extended_wait around to a more logical order when we now have to handle and potentially report all of fork/vfork/clone. Raname lwp_info::fork_relative -> lwp_info::relative as the field is no longer only about (v)fork. With this, gdb.threads/stepi-over-clone.exp now cleanly passes against GDBserver, so remove the native-target-only requirement from that testcase. Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=19675 Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=27830 Reviewed-By: Andrew Burgess <aburgess@redhat.com> Change-Id: I3a19bc98801ec31e5c6fdbe1ebe17df855142bb2
2023-11-13Thread options & clone events (native Linux)Pedro Alves2-0/+9
This commit teaches the native Linux target about the GDB_THREAD_OPTION_CLONE thread option. It's actually simpler to just continue reporting all clone events unconditionally to the core. There's never any harm in reporting a clone event when the option is disabled. All we need to do is to report support for the option, otherwise GDB falls back to use target_thread_events(). Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=19675 Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=27830 Reviewed-By: Andrew Burgess <aburgess@redhat.com> Change-Id: If90316e2dcd0c61d0fefa0d463c046011698acf9
2023-11-13Thread options & clone events (core + remote)Pedro Alves10-2/+348
A previous patch taught GDB about a new TARGET_WAITKIND_THREAD_CLONED event kind, and made the Linux target report clone events. A following patch will teach Linux GDBserver to do the same thing. However, for remote debugging, it wouldn't be ideal for GDBserver to report every clone event to GDB, when GDB only cares about such events in some specific situations. Reporting clone events all the time would be potentially chatty. We don't enable thread create/exit events all the time for the same reason. Instead we have the QThreadEvents packet. QThreadEvents is target-wide, though. This patch makes GDB instead explicitly request that the target reports clone events or not, on a per-thread basis. In order to be able to do that with GDBserver, we need a new remote protocol feature. Since a following patch will want to enable thread exit events on per-thread basis too, the packet introduced here is more generic than just for clone events. It lets you enable/disable a set of options at once, modelled on Linux ptrace's PTRACE_SETOPTIONS. IOW, this commit introduces a new QThreadOptions packet, that lets you specify a set of per-thread event options you want to enable. The packet accepts a list of options/thread-id pairs, similarly to vCont, processed left to right, with the options field being a number interpreted as a bit mask of options. The only option defined in this commit is GDB_THREAD_OPTION_CLONE (0x1), which ask the remote target to report clone events. Another patch later in the series will introduce another option. For example, this packet sets option "1" (clone events) on thread p1000.2345: QThreadOptions;1:p1000.2345 and this clears options for all threads of process 1000, and then sets option "1" (clone events) on thread p1000.2345: QThreadOptions;0:p1000.-1;1:p1000.2345 This clears options of all threads of all processes: QThreadOptions;0 The target reports the set of supported options by including "QThreadOptions=<supported options>" in its qSupported response. infrun is then tweaked to enable GDB_THREAD_OPTION_CLONE when stepping over a breakpoint. Unlike PTRACE_SETOPTIONS, fork/vfork/clone children do NOT inherit their parent's thread options. This is so that GDB can send e.g., "QThreadOptions;0;1:TID" without worrying about threads it doesn't know about yet. Documentation for this new remote protocol feature is included in a documentation patch later in the series. Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=19675 Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=27830 Reviewed-By: Andrew Burgess <aburgess@redhat.com> Change-Id: Ie41e5093b2573f14cf6ac41b0b5804eba75be37e
2023-11-13Avoid duplicate QThreadEvents packetsPedro Alves1-0/+8
Similarly to QProgramSignals and QPassSignals, avoid sending duplicate QThreadEvents packets. Approved-By: Andrew Burgess <aburgess@redhat.com> Change-Id: Iaf5babb0b64e1527ba4db31aac8674d82b17e8b4