aboutsummaryrefslogtreecommitdiff
path: root/gdb/python
AgeCommit message (Collapse)AuthorFilesLines
2023-10-16Have DAP handle non-Value results from 'children'Tom Tromey1-2/+7
A pretty-printer's 'children' method may return values other than a gdb.Value -- it may return any value that can be converted to a gdb.Value. I noticed that this case did not work for DAP. This patch fixes the problem.
2023-10-16Handle gdb.LazyString in DAPTom Tromey2-2/+28
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-16Fix register-setting response from DAPTom Tromey1-1/+7
Andry noticed that given a DAP setExpression request, where the expression to set is a register, DAP will return the wrong value -- it will return the old value, not the updated one. This happens because gdb.Value.assign (which was recently added for DAP) does not update the value. In this patch, I chose to have the assign method update the Value in-place. It's also possible to have it return a new value, but this didn't seem very useful to me.
2023-10-16Add DAP scope cacheTom Tromey1-9/+29
Andry Ogorodnik, a co-worker, noticed that multiple "scopes" requests with the same frame would yield different variableReference values in the response. This patch adds a regression test for this, and adds a scope cache in scopes.py, ensuring that multiple identical requests will get the same response. Tested-By: Alexandra Petlanova Hajkova <ahajkova@redhat.com>
2023-10-16gdb: replace architecture_changed with new_architecture observerAndrew Burgess1-3/+2
This commit replaces the architecture_changed observer with a new_architecture observer. Currently the only user of the architecture_changed observer is the Python code, which uses this observer to register the Python unwinder with the architecture. The problem is that the architecture_changed observer is triggered from inferior::set_arch(), which only sees the inferior-wide gdbarch value. For targets that use thread-specific architectures, these never trigger the architecture_changed observer, and so never have the Python unwinder registered with them. When it comes to unwinding GDB makes use of the frame's gdbarch, which is based on the thread's regcache gdbarch, which is set in get_thread_regcache to the value returned from target_thread_architecture, which is not always the inferiors gdbarch value, it might be a thread-specific gdbarch which has not passed through inferior::set_arch(). The new_architecture observer will be triggered from gdbarch_find_by_info, whenever a new gdbarch is created and initialised. As GDB caches and reuses gdbarch values, we should expect to see each new architecture trigger the new_architecture observer just once. After this commit, targets that make use of thread-specific architectures should be able to make use of Python unwinders. As I don't have access to a machine that makes use of thread-specific architectures right now, I asked Luis to confirm that an AArch64 target that uses SVE/SME can't use the Python unwinders in threads that are using a thread-specific architectures, and he confirmed that this is indeed the case, see this discussion: https://inbox.sourceware.org/gdb/87wmvsat8i.fsf@redhat.com Tested-By: Lancelot Six <lancelot.six@amd.com> Tested-By: Luis Machado <luis.machado@arm.com> Reviewed-By: Luis Machado <luis.machado@arm.com> Approved-By: Simon Marchi <simon.marchi@efficios.com>
2023-10-10gdb: remove target_gdbarchSimon Marchi6-14/+16
This function is just a wrapper around the current inferior's gdbarch. I find that having that wrapper just obscures where the arch is coming from, and that it's often used as "I don't know which arch to use so I'll use this magical target_gdbarch function that gets me an arch" when the arch should in fact come from something in the context (a thread, objfile, symbol, etc). I think that removing it and inlining `current_inferior ()->arch ()` everywhere will make it a bit clearer where that arch comes from and will trigger people into reflecting whether this is the right place to get the arch or not. Change-Id: I79f14b4e4934c88f91ca3a3155f5fc3ea2fadf6b Reviewed-By: John Baldwin <jhb@FreeBSD.org> Approved-By: Andrew Burgess <aburgess@redhat.com>
2023-10-10gdb: add inferior parameter to architecture_changed observableSimon Marchi1-1/+1
This is to make it explicit which inferior's architecture just changed, and that the callbacks should not assume it is the current inferior. Update the only caller, pyuw_on_new_gdbarch, to add the parameter, although it doesn't use it currently. Change-Id: Ieb7f21377e4252cc6e7b1ce2cc812cd1a1840e0e Reviewed-By: John Baldwin <jhb@FreeBSD.org> Approved-By: Andrew Burgess <aburgess@redhat.com>
2023-10-10gdb: add inferior::{arch, set_arch}Simon Marchi2-2/+2
Make the inferior's gdbarch field private, and add getters and setters. This helped me by allowing putting breakpoints on set_arch to know when the inferior's arch was set. A subsequent patch in this series also adds more things in set_arch. Change-Id: I0005bd1ef4cd6b612af501201cec44e457998eec Reviewed-By: John Baldwin <jhb@FreeBSD.org> Approved-By: Andrew Burgess <aburgess@redhat.com>
2023-10-10gdb/python: implement support for sending custom MI async notificationsJan Vrany3-0/+83
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-10gdb/python: generalize serialize_mi_result()Jan Vrany3-176/+181
This commit generalizes serialize_mi_result() to make usable in different contexts than printing result of custom MI command. To do so, the check whether passed Python object is a dictionary has been moved to the caller - at the very least, different uses require different error messages. Also it has been renamed to serialize_mi_results() to better match GDB/MI output syntax (see corresponding section in documentation, in particular rules 'result-record' and 'async-output'. Since it is now more generic function, it has been moved to py-mi.c. This is a preparation for implementing Python support for sending custom MI async events. Approved-By: Andrew Burgess <aburgess@redhat.com>
2023-10-05gdb: add all_objfiles_removed observerSimon Marchi1-13/+17
The new_objfile observer is currently used to indicate both when a new objfile is added to program space (when passed non-nullptr) and when all objfiles of a program space were just removed (when passed nullptr). I think this is confusing (and Andrew apparently thinks so too [1]). Add a new "all_objfiles_removed" observer to remove the second role from "new_objfile". Some existing users of new_objfile do nothing if the passed objfile is nullptr. For them, we can simply drop the nullptr check. For others, add a new all_objfiles_removed callback, and refactor things a bit to keep the existing behavior as much as possible. Some callbacks relied on current_program_space, and following the refactoring now use either objfile->pspace or the pspace passed to all_objfiles_removed. I think this should be relatively safe, and in general a step in the right direction. On the notify side, I found only one call site to change from new_objfile to all_objfiles_removed, in clear_symtab_users. It is not entirely clear to me that this is entirely correct. clear_symtab_users appears to be called in spots that don't remove all objfiles (functions finish_new_objfile, remove_symbol_file_command, reread_symbols, do_module_cleanups). But I think that this patch at least makes the current code clearer. [1] https://gitlab.com/gnutools/binutils-gdb/-/commit/a0a031bce0527b1521788b5dad640e7883b3a252 Change-Id: Icb648f72862e056267f30f44dd439bd4ec766f13 Approved-By: Tom Tromey <tom@tromey.com>
2023-10-05gdb: add program_space parameters to some auto-load functionsSimon Marchi1-1/+2
Make the current_program_space references bubble up a bit. Change-Id: Id047a48cc8d8a45504cdbb5960bafe3e7735d652 Approved-By: Tom Tromey <tom@tromey.com>
2023-10-05gdb: add program_space parameter to emit_clear_objfiles_eventSimon Marchi3-6/+6
Add program_space space parameters to emit_clear_objfiles_event and create_clear_objfiles_event_object, making the reference to current_program_space bubble up a bit. Change-Id: I5fde2071712781e5d45971fa0ab34d85d3a49a71 Approved-By: Tom Tromey <tom@tromey.com>
2023-10-02gdb: add Python events for program space addition and removalAndrew Burgess3-0/+75
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-28gdb/python: make the executable_changed event available from PythonAndrew Burgess3-0/+60
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/+21
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/+23
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-28gdb/doc: extend the description for Progspace.filenameAndrew Burgess1-1/+1
Extend the description for Progspace.filename in the documentation to mention what the returned string is actually the filename for (e.g. that it is the filename passed to the 'symbol-file' or 'file' command). Also document that this attribute will be None if no symbol file is currently loaded. Reviewed-By: Eli Zaretskii <eliz@gnu.org> Approved-By: Tom Tromey <tom@tromey.com>
2023-09-26Remove some unnecessary qualification from printing.pyTom Tromey1-5/+5
printing.py references "gdb.printing" in a few spots, but there's no need for this. I think this is leftover from when this code was (briefly) in some other module. This patch removes the unnecessary qualifications. Tested on x86-64 Fedora 36.
2023-09-26Add two new pretty-printer methodsTom Tromey2-11/+27
This adds two new pretty-printer methods, to support random access to children. The methods are implemented for the no-op array printer, and DAP is updated to use this. Reviewed-By: Eli Zaretskii <eliz@gnu.org>
2023-09-26Introduce gdb.ValuePrinterTom Tromey3-28/+94
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-26[gdb/dap] Fix dap for python < 3.8Tom de Vries1-1/+5
With any gdb.dap test and python 3.6 I run into: ... Error occurred in Python: 'code' object has no attribute 'co_posonlyargcount' ERROR: eof reading json header ... The attribute is not supported before python 3.8, which introduced the "Positional−only Parameters" concept. Fix this by using try/except AttributeError. Tested on x86_64-linux: - openSUSE Leap 15.4 with python 3.6, and - openSUSE Tumbleweed with python 3.11.5. Approved-By: Tom Tromey <tom@tromey.com>
2023-09-20Remove stray trailing "," from DAP breakpoint.pyTom Tromey1-1/+1
The buildbot pointed out that the last DAP series I checked in had an issue. Looking into it, it seems there is a stray trailing "," in breakpoint.py. This patch removes it. This seems to point out a test suite deficiency. I will look into fixing that.
2023-09-20Remove explanatory comments from includesTom Tromey4-4/+4
I noticed a comment by an include and remembered that I think these don't really provide much value -- sometimes they are just editorial, and sometimes they are obsolete. I think it's better to just remove them. Tested by rebuilding. Approved-By: Andrew Burgess <aburgess@redhat.com>
2023-09-20gdb/dap: only include sourceReference if file path does not existGregory Anders1-5/+11
According to the DAP specification if the "sourceReference" field is included in a Source object, then the DAP client _must_ make a "source" request to the debugger to retrieve file contents, even if the Source object also includes path information. If the Source's path field is a valid path that the DAP client is able to read from the filesystem, having to make another request to the debugger to get the file contents is wasteful and leads to incorrect results (DAP clients will try to get the contents from the server and display those contents as a file with the name in "source.path", but this will conflict with the _acutal_ existing file at "source.path"). Instead, only set "sourceReference" if the source file path does not exist. Approved-By: Tom Tromey <tom@tromey.com>
2023-09-20gdb/dap: use breakpoint fullname to resolve sourceGregory Anders1-3/+3
If the breakpoint has a fullname, use that as the source path when resolving the breakpoint source information. This is consistent with other callers of make_source which also use "fullname" if it exists (see e.g. DAPFrameDecorator which returns the symtab's fullname). Approved-By: Tom Tromey <tom@tromey.com>
2023-09-20gdb/dap: ignore unused keyword args in step_outGregory Anders2-1/+8
Some DAP clients may send additional parameters in the stepOut command (e.g. "granularity") which are not used by GDB, but should nonetheless be accepted without error. Approved-By: Tom Tromey <tom@tromey.com>
2023-09-20gdb/dap: check for breakpoint source before unpackingGregory Anders1-8/+12
Not all breakpoints have a source location. For example, a breakpoint set on a raw address will have only the "address" field populated, but "source" will be None, which leads to a RuntimeError when attempting to unpack the filename and line number. Before attempting to unpack the filename and line number from the breakpoint, ensure that the source information is not None. Also populate the source and line information separately from the "instructionReference" field, so that breakpoints that include only an address are still included. Approved-By: Tom Tromey <tom@tromey.com>
2023-09-20Run 'black' on printing.pyTom Tromey1-1/+5
The buildbot pointed out that I neglected to re-run 'black' after making some changes. This patch fixes the oversight.
2023-09-19Handle pointers and references correctly in DAPTom Tromey1-0/+16
A user pointed out that the current DAP variable code does not let the client deference a pointer. Oops! Fixing this oversight is simple enough -- adding a new no-op pretty-printer for pointers and references is quite simple. However, doing this naive caused a regession in scopes.exp, which expected there to be no children of a 'const char *' variable. This problem was fixed by the preceding patches in the series, which ensure that a C type of this kind is recognized as a string. Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=30821
2023-09-19Give a language to a typeTom Tromey1-9/+4
This changes main_type to hold a language, and updates the debug readers to set this field. This is done by adding the language to the type-allocator object. Note that the non-DWARF readers are changed on a "best effort" basis. This patch also reimplements type::is_array_like to use the type's language, and it adds a new type::is_string_like as well. This in turn lets us change the Python implementation of these methods to simply defer to the type.
2023-09-19Use gdb::checked_static_cast for watchpointsTom Tromey1-2/+1
This replaces some casts to 'watchpoint *' with checked_static_cast. In one spot, an unnecessary block is also removed. Approved-By: Simon Marchi <simon.marchi@efficios.com>
2023-09-12Avoid spurious breakpoint-setting failure in DAPTom Tromey1-1/+7
A user pointed out that if a DAP setBreakpoints request has a 'source' field in a SourceBreakpoint object, then the gdb DAP implementation will throw an exception. While SourceBreakpoint does not allow 'source' in the spec, it seems better to me to accept it. I don't think we should fully go down the "Postel's Law" path -- after all, we have the type-checker -- but at the same time, if we do send errors, they should be intentional and not artifacts of the implementation. Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=30820
2023-09-06[gdb/symtab] Fix too many symbols in gdbpy_lookup_static_symbolsTom de Vries1-2/+5
When running test-case gdb.python/py-symbol.exp with target board cc-with-dwz-m, we run into: ... (gdb) python print (len (gdb.lookup_static_symbols ('rr')))^M 4^M (gdb) FAIL: gdb.python/py-symbol.exp: \ print (len (gdb.lookup_static_symbols ('rr'))) ... while with target board unix we have instead: ... (gdb) python print (len (gdb.lookup_static_symbols ('rr')))^M 2^M (gdb) PASS: gdb.python/py-symbol.exp: \ print (len (gdb.lookup_static_symbols ('rr'))) ... The problem is that the loop in gdbpy_lookup_static_symbols loops over compunits representing both CUs and PUs: ... for (compunit_symtab *cust : objfile->compunits ()) ... When doing a lookup on a PU, the user link is followed until we end up at a CU, and the lookup is done in that CU. In other words, when doing a lookup in the loop for a PU we duplicate the lookup for a CU that is already handled by the loop. Fix this by skipping PUs in the loop in gdb.lookup_static_symbols. Tested on x86_64-linux. PR symtab/25261 Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=25261
2023-09-05Handle array- and string-like values in no-op pretty printersTom Tromey1-3/+23
This changes the no-op pretty printers -- used by DAP -- to handle array- and string-like objects known by the gdb core. Two new tests are added, one for Ada and one for Rust.
2023-09-05Add new Python APIs to support DAP value displayTom Tromey2-0/+94
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-09-05Select frame when fetching a frame variable in DAPTom Tromey2-3/+12
Right now, if a program uses multiple languages, DAP value formatting will always use the language of the innermost frame. However, it is better to use the variable's defining frame instead. This patch does this by selecting the frame first. This also fixes a possibly latent bug in the "stepOut" command -- "finish" is sensitive to the selected frame, but the DAP code may already select other frames when convenient. The DAP stepOut request only works on the newest frame, so be sure to select it before invoking "finish".
2023-09-05Use ada_value_subscript in valpy_getitemTom Tromey1-0/+3
Ada has a few complexities when it comes to array handling. Currently these are all handled in Ada-specific code -- but unfortunately that means they aren't really accessible to Python. This patch changes the Python code to defer to Ada when given an Ada array. In order to make this work, one spot in ada-lang.c had to be updated to set the "GNAT-specific" flag on an array type. The test case for this will come in a later patch.
2023-08-31gdb: remove TYPE_FIELD_BITSIZESimon Marchi1-1/+1
Replace with type::field + field::bitsize. Change-Id: I2a24755a33683e4a2775a6d2a7b7a9ae7362e43a Approved-By: Tom Tromey <tom@tromey.com>
2023-08-31gdb: remove TYPE_FIELD_ARTIFICIALSimon Marchi1-1/+1
Replace with type::field + field::is_artificial. Change-Id: Ie3bacae49d9bd02e83e504c1ce01470aba56a081 Approved-By: Tom Tromey <tom@tromey.com>
2023-08-24[gdb/build] Return gdb::array_view in thread_info_to_thread_handleTom de Vries1-2/+2
In remote_target::thread_info_to_thread_handle we return a copy: ... gdb::byte_vector remote_target::thread_info_to_thread_handle (struct thread_info *tp) { remote_thread_info *priv = get_remote_thread_info (tp); return priv->thread_handle; } ... Fix this by returning a gdb::array_view instead: ... gdb::array_view<const gdb_byte> remote_target::thread_info_to_thread_handle (struct thread_info *tp) ... Tested on x86_64-linux. This fixes the build when building with -std=c++20. Approved-By: Pedro Alves <pedro@palves.net>
2023-08-23gdb: centralize "[Thread ...exited]" notificationsPedro Alves1-1/+3
Currently, each target backend is responsible for printing "[Thread ...exited]" before deleting a thread. This leads to unnecessary differences between targets, like e.g. with the remote target, we never print such messages, even though we do print "[New Thread ...]". E.g., debugging the gdb.threads/attach-many-short-lived-threads.exp with gdbserver, letting it run for a bit, and then pressing Ctrl-C, we currently see: (gdb) c Continuing. ^C[New Thread 3850398.3887449] [New Thread 3850398.3887500] [New Thread 3850398.3887551] [New Thread 3850398.3887602] [New Thread 3850398.3887653] ... Thread 1 "attach-many-sho" received signal SIGINT, Interrupt. 0x00007ffff7e6a23f in __GI___clock_nanosleep (clock_id=clock_id@entry=0, flags=flags@entry=0, req=req@entry=0x7fffffffda80, rem=rem@entry=0x7fffffffda80) at ../sysdeps/unix/sysv/linux/clock_nanosleep.c:78 78 in ../sysdeps/unix/sysv/linux/clock_nanosleep.c (gdb) Above, we only see "New Thread" notifications, even though threads were deleted. After this patch, we'll see: (gdb) c Continuing. ^C[Thread 3558643.3577053 exited] [Thread 3558643.3577104 exited] [Thread 3558643.3577155 exited] [Thread 3558643.3579603 exited] ... [New Thread 3558643.3597415] [New Thread 3558643.3600015] [New Thread 3558643.3599965] ... Thread 1 "attach-many-sho" received signal SIGINT, Interrupt. 0x00007ffff7e6a23f in __GI___clock_nanosleep (clock_id=clock_id@entry=0, flags=flags@entry=0, req=req@entry=0x7fffffffda80, rem=rem@entry=0x7fffffffda80) at ../sysdeps/unix/sysv/linux/clock_nanosleep.c:78 78 in ../sysdeps/unix/sysv/linux/clock_nanosleep.c (gdb) q This commit fixes this by moving the thread exit printing to common code instead, triggered from within delete_thread (or rather, set_thread_exited). There's one wrinkle, though. While most targest want to print: [Thread ... exited] the Windows target wants to print: [Thread ... exited with code <exit_code>] ... and sometimes wants to suppress the notification for the main thread. To address that, this commits adds a delete_thread_with_code function, only used by that target (so far). This fix was originally posted as part of a larger series: https://inbox.sourceware.org/gdb-patches/20221212203101.1034916-1-pedro@palves.net/ But didn't really need to be part of that series. In order to get this fix merged sooner, I (Andrew Burgess) have rebased this commit outside of the original series. Any bugs introduced while splitting this patch out and rebasing, are entirely my own. Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=30129 Co-Authored-By: Andrew Burgess <aburgess@redhat.com>
2023-08-23gdb: remove mi_parse::make functionsAndrew Burgess1-2/+2
Remove the static mi_parse::make functions, and instead use the mi_parse constructor. This is a partial revert of the commit: commit fde3f93adb50c9937cd2e1c93561aea2fd167156 Date: Mon Mar 20 10:56:55 2023 -0600 Introduce "static constructor" for mi_parse which introduced the mi_parse::make functions, though after discussion on the list the reasons for seem to have been lost[1]. Given there are no test regressions when moving back to using the constructors, I propose we should do that for now. There should be no user visible changes after this commit. [1] https://inbox.sourceware.org/gdb-patches/20230404-dap-loaded-sources-v2-5-93f229095e03@adacore.com/ Approved-By: Tom Tromey <tom@tromey.com>
2023-08-23gdb: add gdb::make_unique functionAndrew Burgess1-3/+1
While GDB is still C++11, lets add a gdb::make_unique template function that can be used to create std::unique_ptr objects, just like the C++14 std::make_unique. If GDB is being compiled with a C++14 compiler then the new gdb::make_unique function will delegate to the std::make_unique. I checked with gcc, and at -O1 and above gdb::make_unique will be optimised away completely in this case. If C++14 (or later) becomes our minimum, then it will be easy enough to go through the code and replace gdb::make_unique with std::make_unique later on. I've make use of this function in all the places I think this can easily be used, though I'm sure I've probably missed some. Should be no user visible changes after this commit. Approved-By: Tom Tromey <tom@tromey.com>
2023-08-22Remove value::copy call from gdbpy_get_varobj_pretty_printerTom Tromey1-9/+0
I noticed a call to value::copy in gdbpy_get_varobj_pretty_printer, and I couldn't figure out why it was there. I think maybe it came from the time when value_to_value_object would release values from the value chain -- but that was removed in commit f3d3bbbc. This patch removes this call. Regression tested on x86-64 Fedora 36.
2023-08-17gdb: add inferior-specific breakpointsAndrew Burgess2-2/+96
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-16Implement DAP module-removed eventTom Tromey1-0/+13
DAP specifies an event that should be sent when a module is removed. This patch implements this. Tested-By: Alexandra Petlanova Hajkova <ahajkova@redhat.com>
2023-08-14[gdb/build] Fix enum param_types odr violationTom de Vries1-1/+1
When building gdb with -O2 -flto, I run into: ... gdb/guile/scm-param.c:121:6: warning: type 'param_types' violates the C++ \ One Definition Rule [-Wodr] enum param_types ^ gdb/python/py-param.c:33:6: note: an enum with different value name is \ defined in another translation unit enum param_types ^ ... Fix this by renaming to enum scm_param_types and py_param_types. Tested on x86_64-linux. Approved-By: Tom Tromey <tom@tromey.com> PR build/22395 Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=22395
2023-08-14[gdb/build] Remove superfluous variable param_types in gdb/python/py-param.cTom de Vries1-2/+1
In gdb/python/py-param.c we have: ... enum param_types { ... } param_types; ... which declares both an enum param_types, and an unused variable param_types. Fix this by removing the variable. Tested on x86_64-linux. Approved-By: Tom Tromey <tom@tromey.com>
2023-08-03Remove f-string from DAPTom Tromey1-1/+1
One more f-string snuck into the DAP code, in breakpoint.py. Most of them were removed here: https://sourceware.org/pipermail/gdb-patches/2023-June/200023.html but I think this one landed after that patch. While DAP only supports Python 3.5 and later, f-strings were added in 3.6, so remove this. Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=30708