aboutsummaryrefslogtreecommitdiff
path: root/gdb/NEWS
AgeCommit message (Collapse)AuthorFilesLines
2024-01-12gdb/python: Add gdb.InferiorThread.__dict__ attributeAndrew Burgess1-0/+4
The gdb.Objfile, gdb.Progspace, gdb.Type, and gdb.Inferior Python types already have a __dict__ attribute, which allows users to create user defined attributes within the objects. This is useful if the user wants to cache information within an object. This commit adds the same functionality to the gdb.InferiorThread type. After this commit there is a new gdb.InferiorThread.__dict__ attribute, which is a dictionary. A user can, for example, do this: (gdb) pi >>> t = gdb.selected_thread() >>> t._user_attribute = 123 >>> t._user_attribute 123 >>> There's a new test included. Reviewed-By: Eli Zaretskii <eliz@gnu.org> Approved-By: Tom Tromey <tom@tromey.com>
2024-01-12gdb/python: Add gdb.Inferior.__dict__ attributeAndrew Burgess1-0/+4
The gdb.Objfile, gdb.Progspace, and gdb.Type Python types already have a __dict__ attribute, which allows users to create user defined attributes within the objects. This is useful if the user wants to cache information within an object. This commit adds the same functionality to the gdb.Inferior type. After this commit there is a new gdb.Inferior.__dict__ attribute, which is a dictionary. A user can, for example, do this: (gdb) pi >>> i = gdb.selected_inferior() >>> i._user_attribute = 123 >>> i._user_attribute 123 >>> There's a new test included. Reviewed-By: Eli Zaretskii <eliz@gnu.org> Approved-By: Tom Tromey <tom@tromey.com>
2024-01-12gdb/python: remove users ability to create gdb.Progspace objectsAndrew Burgess1-0/+5
I noticed that it is possible for the user to create a new gdb.Progspace object, like this: (gdb) pi >>> p = gdb.Progspace() >>> p <gdb.Progspace object at 0x7ffad4219c10> >>> p.is_valid() False As the new gdb.Progspace object is not associated with an actual C++ program_space object within GDB core, then the new gdb.Progspace is created invalid, and there is no way in which the new object can ever become valid. Nor do I believe there's anywhere in the Python API where it makes sense to consume an invalid gdb.Progspace created in this way, for example, the gdb.Progspace could be passed as the locus to register_type_printer, but all that would happen is that the registered printer would never be used. In this commit I propose to remove the ability to create new gdb.Progspace objects. Attempting to do so now gives an error, like this: (gdb) pi >>> gdb.Progspace() Traceback (most recent call last): File "<stdin>", line 1, in <module> TypeError: cannot create 'gdb.Progspace' instances Of course, there is a small risk here that some existing user code might break ... but if that happens I don't believe the user code can have been doing anything useful, so I see this as a small risk. Reviewed-By: Eli Zaretskii <eliz@gnu.org> Approved-By: Tom Tromey <tom@tromey.com>
2024-01-12gdb/python: New InferiorThread.ptid_string attributeAndrew Burgess1-0/+4
This commit adds a new InferiorThread.ptid_string attribute. This read-only attribute contains the string returned by target_pid_to_str, which actually converts a ptid (not pid) to a string. This is the string that appears (at least in part) in the output of 'info threads' in the 'Target Id' column, but also in the thread exited message that GDB prints. Having access to this string from Python is useful for allowing extensions identify threads in a similar way to how GDB core would identify the thread. Reviewed-By: Eli Zaretskii <eliz@gnu.org> Approved-By: Tom Tromey <tom@tromey.com>
2024-01-08Add "maint set dwarf synchronous"Tom Tromey1-0/+4
For testing, it's sometimes convenient to be able to request that DWARF reading be done synchronously. This patch adds a new "maint" setting for this purpose. Reviewed-By: Eli Zaretskii <eliz@gnu.org>
2024-01-02gdb/dwarf2: Add support for DW_LNS_set_epilogue_begin in line-tableGuinevere Larsen1-0/+5
This commit adds a mechanism for GDB to detect the linetable opcode DW_LNS_set_epilogue_begin. This opcode is set by compilers to indicate that a certain instruction marks the point where the frame is destroyed. While the standard allows for multiple points marked with epilogue_begin in the same function, for performance reasons, the function that searches for the epilogue address will only find the last address that sets this flag for a given block. This commit also changes amd64_stack_frame_destroyed_p_1 to attempt to use the epilogue begin directly, and only if an epilogue can't be found will it attempt heuristics based on the current instruction. Finally, this commit also changes the dwarf assembler to be able to emit epilogue-begin instructions, to make it easier to test this patch Approved-By: Tom Tromey <tom@tromey.com>
2023-12-22Add DAP log level parameterTom Tromey1-0/+5
This adds a new parameter to control the DAP logging level. By default, "expected" exceptions are not logged, but the parameter lets the user change this when more logging is desired. This also changes a couple of spots to avoid logging the stack trace for a DAPException. This patch also documents the existing DAP logging parameter. I forgot to document this before. Reviewed-By: Eli Zaretskii <eliz@gnu.org> Reviewed-By: Kévin Le Gouguec <legouguec@adacore.com>
2023-12-22Add 'program' to DAP 'attach' requestTom Tromey1-0/+2
In many cases, it's not possible for gdb to discover the executable when a DAP 'attach' request is used. This patch lets the IDE supply this information. Reviewed-By: Eli Zaretskii <eliz@gnu.org>
2023-12-11Implement DAP cancellationTom Tromey1-0/+2
This implements DAP cancellation. A new object is introduced that handles the details of cancellation. While cancellation is inherently racy, this code attempts to make it so that gdb doesn't inadvertently cancel the wrong request. Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=30472 Approved-By: Eli Zaretskii <eliz@gnu.org> Reviewed-By: Kévin Le Gouguec <legouguec@adacore.com>
2023-12-11Introduce gdb.interruptTom Tromey1-0/+3
DAP cancellation needs a way to interrupt whatever is happening on gdb's main thread -- whether that is the inferior, a gdb CLI command, or Python code. This patch adds a new gdb.interrupt() function for this purpose. It simply sets the quit flag and lets gdb do the rest. No tests in this patch -- instead this is tested via the DAP cancellation tests. Reviewed-By: Eli Zaretskii <eliz@gnu.org> Reviewed-By: Kévin Le Gouguec <legouguec@adacore.com>
2023-12-11Emit stop reason details in Python stop eventsTom Tromey1-0/+4
This changes Python stop events to carry a "details" dictionary, that holds any relevant information about the stop. The details are constructed using more or less the same procedure as is done for MI. Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=13587 Reviewed-By: Eli Zaretskii <eliz@gnu.org>
2023-12-11Add DAP items to NEWSTom Tromey1-0/+4
Now that DAP is in GDB 14, significant changes to it should be noted in NEWS. This patch adds a note for a fix that's already gone in. I started a new section in NEWS because more changes are coming. Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=30473 Approved-By: Eli Zaretskii <eliz@gnu.org>
2023-12-08gdbserver: allow for general 'monitor set debug COMPONENT VALUE' useAndrew Burgess1-0/+8
Building on the last commit, which added a general --debug=COMPONENT option to the gdbserver command line, this commit updates the monitor command to allow for general: (gdb) monitor set debug COMPONENT off|on style commands. Just like with the previous commit, the COMPONENT can be any one of all, threads, remote, event-loop, and correspond to the same set of global debug flags. While on the command line it is possible to do: --debug=remote,event-loop,threads the components have to be entered one at a time with the monitor command. I guess there's no reason why we couldn't allow component grouping within the monitor command, but (to me) what I have here seemed more in the spirit of GDB's existing 'set debug ...' commands. If people want it then we can always add component grouping later. Notice in the above that I use 'off' and 'on' instead of '0' and '1', which is what the 'monitor set debug' command used to use. The 0/1 can still be used, but I now advertise off/on in all the docs and help text, again, this feels more inline with GDB's existing boolean settings. I have removed the two existing monitor commands: monitor set remote-debug 0|1 monitor set event-loop-debug 0|1 These are replaced by: monitor set debug remote off|on monitor set debug event-loop off|on respectively. Approved-By: Tom Tromey <tom@tromey.com> Reviewed-By: Eli Zaretskii <eliz@gnu.org>
2023-12-08gdbserver: allow the --debug command line option to take a valueAndrew Burgess1-0/+10
Currently, gdbserver has the following command line options related to debugging output: --debug --remote-debug --event-loop-debug This doesn't scale well. If I want an extra debug component I need to add another command line flag. This commit changes --debug to take a list of components. The currently supported components are: all, threads, remote, and event-loop. The 'threads' component represents the debug we currently get from the --debug option. And if --debug is used without a component list then the threads component is assumed as the default. Currently the threads component actually includes a lot of output that is not really threads related. In the future I'd like to split this up into some new, separate components. But that is not part of this commit, or even this series. The special component 'all' does what you'd expect: enables debug output from all supported components. The component list is parsed left to write, and you can prefix a component with '-' to disable that component, so I can write: target> gdbserver --debug=all,-event-loop to get debug for all components except the event-loop component. I've removed the existing --remote-debug and --event-loop-debug command line options, these are equivalent to --debug=remote and --debug=event-loop respectively, or --debug=remote,event-loop to enable both components. In this commit I've only update the command line options, in the next commit I'll update the monitor commands to support a similar interface. Reviewed-By: Eli Zaretskii <eliz@gnu.org> Approved-By: Tom Tromey <tom@tromey.com>
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-14Add gdb.Frame.static_link methodTom Tromey1-0/+3
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-14gdb: implement missing debug handler hook for PythonAndrew Burgess1-0/+26
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-13Document remote clone events, and QThreadOptions packetPedro Alves1-0/+20
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-13Don't resume new threads if scheduler-locking is in effectPedro Alves1-0/+7
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-13Add "maint info linux-lwps" commandAndrew Burgess1-0/+5
This adds a maintenance command that lets you list all the LWPs under control of the linux-nat target. For example: (gdb) maint info linux-lwps LWP Ptid Thread ID 560948.561047.0 None 560948.560948.0 1.1 This shows that "560948.561047.0" LWP doesn't map to any thread_info object, which is bogus. We'll be using this in a testcase in a following patch. Co-Authored-By: Pedro Alves <pedro@palves.net> Change-Id: Ic4e9e123385976e5cd054391990124b7a20fb3f5
2023-11-08gdb: error if /r and /b are used with disassemble commandAndrew Burgess1-0/+7
The disassembler gained a new /b flag in this commit: commit d4ce49b7ac077a9882d6a5e689e260300045ca88 Date: Tue Jun 21 20:23:35 2022 +0100 gdb: disassembler opcode display formatting The /b and /r flags result in the instruction opcodes displayed in different formats, so it's not possible to have both at the same time. Currently the /b flag overrides the /r flag. We have a similar situation with the /m and /s flags, but here, if the user tries to use both flags then they will get an error. I think the error is clearer, so in this commit I propose that we add an error if /r and /b are both used. Obviously this change breaks backwards compatibility. I don't have a compelling argument for why we should make the change beyond my feeling that it was a mistake not to add this error from the start, and that the new behaviour is better. Reviewed-By: Eli Zaretskii <eliz@gnu.org>
2023-10-28gdb/gdbsupport/gdbserver: Require c++17Lancelot Six1-0/+3
This patch proposes to require a C++17 compiler to build gdb / gdbsupport / gdbserver. Before this patch, GDB required a C++11 compiler. The general policy regarding bumping C++ language requirement in GDB (as stated in [1]) is: Our general policy is to wait until the oldest compiler that supports C++NN is at least 3 years old. Rationale: We want to ensure reasonably widespread compiler availability, to lower barrier of entry to GDB contributions, and to make it easy for users to easily build new GDB on currently supported stable distributions themselves. 3 years should be sufficient for latest stable releases of distributions to include a compiler for the standard, and/or for new compilers to appear as easily installable optional packages. Requiring everyone to build a compiler first before building GDB, which would happen if we required a too-new compiler, would cause too much inconvenience. See the policy proposal and discussion [here](https://sourceware.org/ml/gdb-patches/2016-10/msg00616.html). The first GCC release which with full C++17 support is GCC-9[2], released in 2019[3], which is over 4 years ago. Clang has had C++17 support since Clang-5[4] released in 2018[5]. A discussions with many distros showed that a C++17-able compiler is always available, meaning that this no hard requirement preventing us to require it going forward. [1] https://sourceware.org/gdb/wiki/Internals%20GDB-C-Coding-Standards#When_is_GDB_going_to_start_requiring_C.2B-.2B-NN_.3F [2] https://gcc.gnu.org/projects/cxx-status.html#cxx17 [3] https://gcc.gnu.org/gcc-9/ [4] https://clang.llvm.org/cxx_status.html [5] https://releases.llvm.org/ Change-Id: Id596f5db17ea346e8a978668825787b3a9a443fd Reviewed-By: Eli Zaretskii <eliz@gnu.org> Approved-By: Tom Tromey <tom@tromey.com> Approved-By: Pedro Alves <pedro@palves.net>
2023-10-26gdb/python: Add new gdb.Value.bytes attributeAndrew Burgess1-0/+3
Add a gdb.Value.bytes attribute. This attribute contains the bytes of the value (assuming the complete bytes of the value are available). If the bytes of the gdb.Value are not available then accessing this attribute raises an exception. The bytes object returned from gdb.Value.bytes is cached within GDB so that the same bytes object is returned each time. The bytes object is created on-demand though to reduce unnecessary work. For some values we can of course obtain the same information by reading inferior memory based on gdb.Value.address and gdb.Value.type.sizeof, however, not every value is in memory, so we don't always have an address. The gdb.Value.bytes attribute will convert any value to a bytes object, so long as the contents are available. The value can be one created purely in Python code, the value could be in a register, or (of course) the value could be in memory. The Value.bytes attribute can also be assigned too. Assigning to this attribute is similar to calling Value.assign, the value of the underlying value is updated within the inferior. The value assigned to Value.bytes must be a buffer which contains exactly the correct number of bytes (i.e. unlike value creation, we don't allow oversized buffers). To support this assignment like behaviour I've factored out the core of valpy_assign. I've also updated convert_buffer_and_type_to_value so that it can (for my use case) check the exact buffer length. The restrictions for when the Value.bytes can or cannot be written too are exactly the same as for Value.assign. Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=13267 Reviewed-By: Eli Zaretskii <eliz@gnu.org> Approved-By: Tom Tromey <tom@tromey.com>
2023-10-20[gdb/symtab] Fix more style issues in v9 .gdb_index section supportTom de Vries1-1/+1
I noticed a few more style issues in commit 8b9c08eddac ("[gdb/symtab] Add name_of_main and language_of_main to the DWARF index"), after checking it with gcc's check_GNU_style.{sh,py}. Fix these. Build on x86_64-linux.
2023-10-16Handle gdb.LazyString in DAPTom Tromey1-0/+2
Andry pointed out that the DAP code did not properly handle gdb.LazyString results from a pretty-printer, yielding: TypeError: Object of type LazyString is not JSON serializable This patch fixes the problem, partly with a small patch in varref.py, but mainly by implementing tp_str for LazyString. Reviewed-By: Eli Zaretskii <eliz@gnu.org>
2023-10-10gdb/python: implement support for sending custom MI async notificationsJan Vrany1-0/+5
This commit adds a new Python function, gdb.notify_mi, that can be used to emit custom async notification to MI channel. This can be used, among other things, to implement notifications about events MI does not support, such as remote connection closed or register change. Reviewed-By: Eli Zaretskii <eliz@gnu.org> Approved-By: Andrew Burgess <aburgess@redhat.com>
2023-10-10[gdb/symtab] Add name_of_main and language_of_main to the DWARF indexMatheus Branco Borella1-0/+3
This patch adds a new section to the DWARF index containing the name and the language of the main function symbol, gathered from `cooked_index::get_main`, if available. Currently, for lack of a better name, this section is called the "shortcut table". The way this name is both saved and applied upon an index being loaded in mirrors how it is done in `cooked_index_functions`, more specifically, the full name of the main function symbol is saved and `set_objfile_main_name` is used to apply it after it is loaded. The main use case for this patch is in improving startup times when dealing with large binaries. Currently, when an index is used, GDB has to expand symtabs until it finds out what the language of the main function symbol is. For some large executables, this may take a considerable amount of time to complete, slowing down startup. This patch bypasses that operation by having both the name and language of the main function symbol be provided ahead of time by the index. In my testing (a binary with about 1.8GB worth of DWARF data) this change brings startup time down from about 34 seconds to about 1.5 seconds. When testing the patch with target board cc-with-gdb-index, test-case gdb.fortran/nested-funcs-2.exp starts failing, but this is due to a pre-existing issue, filed as PR symtab/30946. Tested on x86_64-linux, with target board unix and cc-with-gdb-index. PR symtab/24549 Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=24549 Approved-By: Tom de Vries <tdevries@suse.de>
2023-10-08Update gdb/NEWS after GDB 14 branch creation.Joel Brobecker1-1/+3
This commit a new section for the next release branch, and renames the section of the current branch, now that it has been cut.
2023-10-06gdb/NEWS: reorder some entries in the NEWS fileAndrew Burgess1-12/+12
I spotted two entries in the NEWS file that I believe are in the wrong place, these are: - An entry about MI v1 being deprecated, this feels like it should be the first entry under the 'MI changes' heading, and - An entry for the $_shell convenience function which is currently under the 'New commands' heading (sort of), when I think this should be listed in the general news section.
2023-10-05gdb/configure.ac: Add option --with-additional-debug-dirsThiago Jung Bauermann1-0/+8
If you want to install GDB in a custom prefix, have it look for debug info in that prefix but also in the distro's default location (typically, /usr/lib/debug) and run the GDB testsuite before doing "make install", you have a bit of a problem: Configuring GDB with '--prefix=$PREFIX' sets the GDB 'debug-file-directory' parameter to $PREFIX/lib/debug. Unfortunately this precludes GDB from looking for distro-installed debug info in /usr/lib/debug. For regular GDB use you could set debug-file-directory to $PREFIX:/usr/lib/debug in $PREFIX/etc/gdbinit so that GDB will look in both places, but if you want to run the testsuite then that doesn't help because in that case GDB runs with the '-nx' option. There's the configure option '--with-separate-debug-dir' to set the default value for 'debug-file-directory', but it accepts only one directory and not a list. I considered modifying it to accept a list, but it's not obvious how to do that because its value is also used by BFD, as well as processed for "relocatability". I thought it was simpler to add a new option to specify a list of additional directories that will be appended to the debug-file-directory setting. Reviewed-By: Eli Zaretskii <eliz@gnu.org> Approved-By: Tom Tromey <tom@tromey.com>
2023-10-04sme2: Document SME2 registers and featuresLuis Machado1-0/+3
Document changes introduced by gdb's SME2 support. Reviewed-By: Eli Zaretskii <eliz@gnu.org> Reviewed-by: Thiago Jung Bauermann <thiago.bauermann@linaro.org>
2023-10-04sme: Document SME registers and featuresLuis Machado1-0/+11
Provide documentation for the SME feature and other information that should be useful for users that need to debug a SME-capable target. Reviewed-By: Eli Zaretskii <eliz@gnu.org> Reviewed-by: Thiago Jung Bauermann <thiago.bauermann@linaro.org>
2023-10-02gdb: add Python events for program space addition and removalAndrew Burgess1-0/+7
Initially I just wanted a Python event for when GDB removes a program space, I'm writing a Python extension that caches information for each program space, and need to know when I should discard entries for a particular program space. But, it seemed easy enough to also add an event for when GDB adds a new program space, so I went ahead and added both new events. Of course, we don't currently have an observable for program space addition or removal, so I first needed to add these. After that it's pretty simple to add two new Python events and have these trigger. The two new event registries are: events.new_progspace events.free_progspace These emit NewProgspaceEvent and FreeProgspaceEvent objects respectively, each of these new event types has a 'progspace' attribute that contains the relevant gdb.Progspace object. There's a couple of things to be mindful of. First, it is not possible to catch the NewProgspaceEvent for the very first program space, the one that is created when GDB first starts, as this program space is created before any Python scripts are sourced. In order to allow this event to be caught we would need to defer creating the first program space, and as a consequence the first inferior, until some later time. But, existing scripts could easily depend on there being an initial inferior, so I really don't think we should change that -- and so, we end up with the consequence that we can't catch the event for the first program space. The second, I think minor, issue, is that GDB doesn't clean up its program spaces upon exit -- or at least, they are not cleaned up before Python is shut down. As a result, any program spaces in use at the time GDB exits don't generate a FreeProgspaceEvent. I'm not particularly worried about this for my use case, I'm using the event to ensure that a cache doesn't hold stale entries within a single GDB session. It's also easy enough to add a Python at-exit callback which can do any final cleanup if needed. Finally, when testing, I did hit a slightly weird issue with some of the remote boards (e.g. remote-stdio-gdbserver). As a consequence of this issue I see some output like this in the gdb.log: (gdb) PASS: gdb.python/py-progspace-events.exp: inferior 1 step FreeProgspaceEvent: <gdb.Progspace object at 0x7fb7e1d19c10> warning: cannot close "target:/lib64/libm.so.6": Cannot execute this command while the target is running. Use the "interrupt" command to stop the target and then try again. warning: cannot close "target:/lib64/libc.so.6": Cannot execute this command while the target is running. Use the "interrupt" command to stop the target and then try again. warning: cannot close "target:/lib64/ld-linux-x86-64.so.2": Cannot execute this command while the target is running. Use the "interrupt" command to stop the target and then try again. do_parent_stuff () at py-progspace-events.c:41 41 ++global_var; (gdb) PASS: gdb.python/py-progspace-events.exp: step The 'FreeProgspaceEvent ...' line is expected, that's my test Python extension logging the event. What isn't expected are all the blocks like: warning: cannot close "target:/lib64/libm.so.6": Cannot execute this command while the target is running. Use the "interrupt" command to stop the target and then try again. It turns out that this has nothing to do with my changes, this is just a consequence of reading files over the remote protocol. The test forks a child process which GDB stays attached too. When the child exits, GDB cleans up by calling prune_inferiors, which in turn can result in GDB trying to close some files that are open because of the inferior being deleted. If the prune_inferiors call occurs when the remote target is running (and in non-async mode) then GDB will try to send a fileio packet while the remote target is waiting for a stop reply, and the remote target will throw an error, see remote_target::putpkt_binary in remote.c for details. I'm going to look at fixing this, but, as I said, this is nothing to do with this change, I just mention it because I ended up needing to account for these warning messages in one of my tests, and it all looks a bit weird. Approved-By: Tom Tromey <tom@tromey.com> Reviewed-By: Eli Zaretskii <eliz@gnu.org>
2023-09-29Support the NO_COLOR environment variableTom Tromey1-0/+4
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/python: make the executable_changed event available from PythonAndrew Burgess1-0/+5
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 Burgess1-0/+7
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/+5
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-26Introduce gdb.ValuePrinterTom Tromey1-0/+5
There was an earlier thread about adding new methods to pretty-printers: https://sourceware.org/pipermail/gdb-patches/2023-June/200503.html We've known about the need for printer extensibility for a while, but have been hampered by backward-compatibilty concerns: gdb never documented that printers might acquire new methods, and so existing printers may have attribute name clashes. To solve this problem, this patch adds a new pretty-printer tag class that signals to gdb that the printer follows new extensibility rules. Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=30816 Reviewed-By: Eli Zaretskii <eliz@gnu.org>
2023-09-20gdb/tui: add 'set tui mouse-events off' to restore mouse selectionMatthew "strager" Glazar1-0/+6
Rationale: I use the mouse with my terminal to select and copy text. In gdb, I use the mouse to select a function name to set a breakpoint, or a variable name to print, for example. When gdb is compiled with ncurses mouse support, gdb's TUI mode intercepts mouse events. Left-clicking and dragging, which would normally select text, seems to do nothing. This means I cannot select text using my mouse anymore. This makes it harder to set breakpoints, print variables, etc. Solution: I tried to fix this issue by editing the 'mousemask' call to only enable buttons 4 and 5. However, this still caused my terminal (gnome-terminal) to not allow text to be selected. The only way I could make it work is by calling 'mousemask (0, NULL);'. But doing so disables the mouse code entirely, which other people might want. I therefore decided to make a setting in gdb called 'tui mouse-events'. If enabled (the default), the behavior is as it is now: terminal mouse events are given to gdb, disabling the terminal's default behavior. If disabled (opt-in), the behavior is as it was before the year 2020: terminal mouse events are not given to gdb, therefore the mouse can be used to select and copy text. Notes: I am not attached to the setting name or its description. Feel free to suggest better wording. Testing: I tested this change in gnome-terminal by performing the following steps manually: 1. Run: gdb --args ./myprogram 2. Enable TUI: press ctrl-x ctrl-a 3. Click and drag text with the mouse. Observe no selection. 4. Input: set tui mouse-events off 5. Click and drag text with the mouse. Observe that selection works now. 6. Input: set tui mouse-events on. 7. Click and drag text with the mouse. Observe no selection.
2023-09-19gdb/cli: fixes to newly added "list ." commandGuinevere Larsen1-2/+3
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-05Add new Python APIs to support DAP value displayTom Tromey1-0/+8
gdb's language code may know how to display values specially. For example, the Rust code understands that &str is a string-like type, or Ada knows how to handle unconstrained arrays. This knowledge is exposed via val-print, and via varobj -- but currently not via DAP. This patch adds some support code to let DAP also handle these cases, though in a somewhat more generic way. Type.is_array_like and Value.to_array are added to make Python aware of the cases where gdb knows that a structure type is really "array-like". Type.is_string_like is added to make Python aware of cases where gdb's language code knows that a type is string-like. Unlike Value.string, these cases are handled by the type's language, rather than the current language. Reviewed-By: Eli Zaretskii <eliz@gnu.org>
2023-08-17gdb: add inferior-specific breakpointsAndrew Burgess1-0/+21
This commit extends the breakpoint mechanism to allow for inferior specific breakpoints (but not watchpoints in this commit). As GDB gains better support for multiple connections, and so for running multiple (possibly unrelated) inferiors, then it is not hard to imagine that a user might wish to create breakpoints that apply to any thread in a single inferior. To achieve this currently, the user would need to create a condition possibly making use of the $_inferior convenience variable, which, though functional, isn't the most user friendly. This commit adds a new 'inferior' keyword that allows for the creation of inferior specific breakpoints. Inferior specific breakpoints are automatically deleted when the associated inferior is removed from GDB, this is similar to how thread-specific breakpoints are deleted when the associated thread is deleted. Watchpoints are already per-program-space, which in most cases mean watchpoints are already inferior specific. There is a small window where inferior-specific watchpoints might make sense, which is after a vfork, when two processes are sharing the same address space. However, I'm leaving that as an exercise for another day. For now, attempting to use the inferior keyword with a watchpoint will give an error, like this: (gdb) watch a8 inferior 1 Cannot use 'inferior' keyword with watchpoints A final note on the implementation: currently, inferior specific breakpoints, like thread-specific breakpoints, are inserted into every inferior, GDB then checks once the inferior stops if we are in the correct thread or inferior, and resumes automatically if we stopped in the wrong thread/inferior. An obvious optimisation here is to only insert breakpoint locations into the specific program space (which mostly means inferior) that contains either the inferior or thread we are interested in. This would reduce the number times GDB has to stop and then resume again in a multi-inferior setup. I have a series on the mailing list[1] that implements this optimisation for thread-specific breakpoints. Once this series has landed I'll update that series to also handle inferior specific breakpoints in the same way. For now, inferior specific breakpoints are just slightly less optimal, but this is no different to thread-specific breakpoints in a multi-inferior debug session, so I don't see this as a huge problem. [1] https://inbox.sourceware.org/gdb-patches/cover.1685479504.git.aburgess@redhat.com/
2023-08-09gdb, breakpoint: add breakpoint location debugging logsMihails Strasuns1-0/+4
Add new commands: set debug breakpoint on|off show debug breakpoint This patch introduces new debugging information that prints breakpoint location insertion and removal flow. The debug output looks like: ~~~ (gdb) set debug breakpoint on (gdb) disassemble main Dump of assembler code for function main: 0x0000555555555129 <+0>: endbr64 0x000055555555512d <+4>: push %rbp 0x000055555555512e <+5>: mov %rsp,%rbp => 0x0000555555555131 <+8>: mov $0x0,%eax 0x0000555555555136 <+13>: pop %rbp 0x0000555555555137 <+14>: ret End of assembler dump. (gdb) break *0x0000555555555137 Breakpoint 2 at 0x555555555137: file main.c, line 4. [breakpoint] update_global_location_list: insert_mode = UGLL_MAY_INSERT (gdb) c Continuing. [breakpoint] update_global_location_list: insert_mode = UGLL_INSERT [breakpoint] insert_bp_location: Breakpoint 2 (0x5565daddb1e0) at address 0x555555555137 in main at main.c:4 [breakpoint] insert_bp_location: Breakpoint -2 (0x5565dab51c10) at address 0x7ffff7fd37b5 [breakpoint] insert_bp_location: Breakpoint -5 (0x5565dab68f30) at address 0x7ffff7fe509e [breakpoint] insert_bp_location: Breakpoint -7 (0x5565dab694f0) at address 0x7ffff7fe63f4 [breakpoint] remove_breakpoint_1: Breakpoint 2 (0x5565daddb1e0) at address 0x555555555137 in main at main.c:4 due to regular remove [breakpoint] remove_breakpoint_1: Breakpoint -2 (0x5565dab51c10) at address 0x7ffff7fd37b5 due to regular remove [breakpoint] remove_breakpoint_1: Breakpoint -5 (0x5565dab68f30) at address 0x7ffff7fe509e due to regular remove [breakpoint] remove_breakpoint_1: Breakpoint -7 (0x5565dab694f0) at address 0x7ffff7fe63f4 due to regular remove Breakpoint 2, 0x0000555555555137 in main () at main.c:4 4 } ~~~ Co-Authored-By: Christina Schimpe <christina.schimpe@intel.com>
2023-07-23Export gdb.block_signals and create gdb.ThreadTom Tromey1-0/+6
While working on an experiment, I realized that I needed the DAP block_signals function. I figured other developers may need it as well, so this patch moves it from DAP to the gdb module and exports it. I also added a new subclass of threading.Thread that ensures that signals are blocked in the new thread. Finally, this patch slightly rearranges the documentation so that gdb-side threading issues and functions are all discussed in a single node.
2023-07-21Add Progspace.objfile_for_addressTom Tromey1-0/+3
This adds a new objfile_for_address method to gdb.Progspace. This makes it easy to find the objfile for a given address. There's a related PR; and while this change would have been sufficient for my original need, it's not clear to me whether I should close the bug. Nevertheless I think it makes sense to at least mention it here. Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=19288 Reviewed-By: Eli Zaretskii <eliz@gnu.org>
2023-07-21Implement Ada target name symbolTom Tromey1-0/+3
Ada 2022 adds the "target name symbol", which can be used on the right hand side of an assignment to refer to the left hand side. This allows for convenient updates. This patch implements this for gdb's Ada expression parser. Reviewed-By: Eli Zaretskii <eliz@gnu.org>
2023-07-14gdb/cli: Improve UX when using list with no argsBruno Larsen1-0/+5
When using "list" with no arguments, GDB will first print the lines around where the inferior is stopped, then print the next N lines until reaching the end of file, at which point it warns the user "Line X out of range, file Y only has X-1 lines.". This is usually desirable, but if the user can no longer see the original line, they may have forgotten the current line or that a list command was used at all, making GDB's error message look cryptic. It was reported in bugzilla as PR cli/30497. This commit improves the user experience by changing the behavior of "list" slightly when a user passes no arguments. It now prints that the end of the file has been reached and recommends that the user use the command "list ." instead. Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=30497 Reviewed-By: Eli Zaretskii <eliz@gnu.org> Approved-By: Tom Tromey <tom@tromey.com>
2023-07-14gdb/cli: add '.' as an argument for 'list' commandBruno Larsen1-0/+4
Currently, after the user has used the list command once, there is no self-contained way to ask GDB to print the location where the inferior is stopped. The current best options require either using a separate command to scope out where the inferior is stopped, or using "list *$pc" requiring knowledge of GDB standard registers. This commit adds a way to do that using '.' as a new argument for the 'list' command. If the inferior isn't running, the command prints around the main function. Because this necessitated having the inferior running and the test was (seemingly unnecessarily) using printf in a non-essential way and it would make the resulting log harder to read for no benefit, it was replaced by a different statement. Reviewed-By: Eli Zaretskii <eliz@gnu.org> Approved-By: Tom Tromey <tom@tromey.com>
2023-07-13Implement 'Enum_Val and 'Enum_RepTom Tromey1-0/+2
This patch implements the Ada 2022 attributes 'Enum_Val and 'Enum_Rep. Reviewed-By: Eli Zaretskii <eliz@gnu.org>
2023-07-07gdb: check max-value-size when reading strings for printfAndrew Burgess1-0/+6
I noticed that the printf code for strings, printf_c_string and printf_wide_c_string, don't take max-value-size into account, but do load a complete string from the inferior into a GDB buffer. As such it would be possible for an badly behaved inferior to cause GDB to try and allocate an excessively large buffer, potentially crashing GDB, or at least causing GDB to swap lots, which isn't great. We already have a setting to protect against this sort of thing, the 'max-value-size'. So this commit updates the two function mentioned above to check the max-value-size and give an error if the max-value-size is exceeded. If the max-value-size is exceeded, I chose to continue reading inferior memory to figure out how long the string actually is, we just don't store the results. The benefit of this is that when we give the user an error we can tell the user how big the string actually is, which would allow them to correctly adjust max-value-size, if that's what they choose to do. The default for max-value-size is 64k so there should be no user visible changes after this commit, unless the user was previously printing very large strings. If that is the case then the user will now need to increase max-value-size.