aboutsummaryrefslogtreecommitdiff
path: root/gdb/python
AgeCommit message (Collapse)AuthorFilesLines
2025-03-20[gdb/build] Fix build with gcc 9Tom de Vries1-1/+1
Since commit a691853148f ("gdb/python: introduce gdbpy_registry"), when building gdb with gcc 9, I run into: ... In file included from gdb/varobj.c:38:0: gdb/python/python-internal.h:1211:47: error: expected ‘;’ before ‘<’ token using StorageKey = typename registry<O>::key<Storage>; ^ ... due to this code: ... template <typename Storage> class gdbpy_registry { ... template<typename O> using StorageKey = typename registry<O>::key<Storage>; template<typename O> Storage *get_storage (O *owner, const StorageKey<O> &key) const { ... } ... } ... As an experiment, I tried out eliminating the type alias: ... template<typename O> Storage *get_storage (O *owner, const typename registry<O>::key<Storage> &key) const { ... } ... and got instead: ... In file included from gdb/varobj.c:38:0: gdb/python/python-internal.h:1211:63: error: non-template ‘key’ used as template Storage *get_storage (O *owner, const typename registry<O>::key<Storage> &key) const ^~~ gdb/python/python-internal.h:1211:63: note: use ‘registry<O>::template key’ \ to indicate that it is a template ... Following that suggestion, I tried: ... template<typename O> Storage * get_storage (O *owner, const typename registry<O>::template key<Storage> &key) const { ... } ... which fixed the problem. Likewise, adding the template keyword in the type alias fixes the original problem, so fix it like that. Tested on x86_64-linux.
2025-03-19gdb/python: convert gdb.Symtab_and_line to use gdbpy_registryJan Vrany1-36/+11
This commit converts gdb.Symtab_and_line to use gdbpy_registry for lifecycle management. Approved-By: Tom Tromey <tom@tromey.com>
2025-03-19gdb/python: convert gdb.Symtab to use gdbpy_registryJan Vrany1-59/+14
This commit converts gdb.Symtab to use gdbpy_registry for lifecycle management. Since gdb.Symtab only holds on the struct symtab * (and prev/next links) the default invalidator can be used. Approved-By: Tom Tromey <tom@tromey.com>
2025-03-19gdb/python: convert gdb.Type to use gdbpy_registryJan Vrany1-92/+21
This commit converts gdb.Type to use gdbpy_registry for lifecycle management. Approved-By: Tom Tromey <tom@tromey.com>
2025-03-19gdb/python: convert gdb.Symbol to use gdbpy_registryJan Vrany1-67/+12
This commit converts gdb.Symbol to use gdbpy_registry for lifecycle management. Since gdb.Symbol only holds on the struct symbol * (and prev/next links) the default invalidator can be used. Approved-By: Tom Tromey <tom@tromey.com>
2025-03-19gdb/python: introduce gdbpy_registryJan Vrany1-0/+195
This commit introduces new template class gdbpy_registry to simplify Python object lifecycle management. As of now, each of the Python object implementations contain its own (copy of) lifecycle management code that is largely very similar. The aim of gdbpy_registry is to factor out this code into a common (template) class in order to simplify the code. Approved-By: Tom Tromey <tom@tromey.com>
2025-03-19gdb/python: do not hold on gdb.Type object from gdb.ValueJan Vrany1-33/+7
Previous commit changed type_to_type_object() so each time it is called with particular struct value* it returns the same object. Therefore there's no longer need to hold on type objects (gdb.Type) from struct value_object in order to preserve identity of gdb.Type objects held in value_object::type and value_object::dynamic_type members. This in turn allowed for some simplification in various functions. While at it I changed a couple of NULLs to nullptrs. Approved-By: Tom Tromey <tom@tromey.com>
2025-03-19gdb/python: preserve identity for gdb.Type objectsJan Vrany1-15/+76
This commit changes type_to_type_object() so that each it is called with a particular struct type * it returns the very same gdb.Type object. This is done in the same way as for gdb.Symtab objects in earlier commit ("gdb/python: preserve identity for gdb.Symtab objects") except that types may be either objfile-owned or arch-owned. Prior this commit, arch-owned objects we not put into any list (like objfile-owned ones) so they could not be easily looked up. This commit changes the code so arch-owned list are put into per-architecture list which is then used (solely) for looking up arch-owned gdb.Type. Another complication comes from the fact that when objfile is about to be freed, associated gdb.Type instances are not merely invalidated (like it is done with gdb.Symtab or gdb.Symbol objects) but instead the type is copied and the copy is arch-owned. So we need two different "deleters", one for objfile-owned types that copies the type (as before) and then insert the object to per-architecture list and another one for arch-owned types. Approved-By: Tom Tromey <tom@tromey.com>
2025-03-19gdb/python: do not hold on gdb.Symtab object from gdb.Symtab_and_lineJan Vrany2-53/+22
Previous commit changed symtab_to_symtab_object() so each time it is called with particula struct symtab* it returns the same object. Therefore there's no longer need to hold on symtab object (gdb.Symtab) from struct sal_object in order to preserve identity of Symtab object held in gdb.Symtab_and_line.symtab property. This in turn allowed for some simplification in various functions. While at it I changed a couple of NULLs to nullptrs. Approved-By: Tom Tromey <tom@tromey.com>
2025-03-19gdb/python: preserve identity for gdb.Symbol objectsJan Vrany1-12/+50
This commit changes symbol_to_symbol_object() so that each it is called with a particular struct symbol * it returns the very same gdb.Symbol object. This is done in the same way as for gdb.Symtab objects in earlier commit ("gdb/python: preserve identity for gdb.Symtab objects") except that symbols may be either objfile-owned or arch-owned. Prior this commit, arch-owned objects we not put into any list (like objfile-owned ones) so they could not be easily looked up. This commit changes the code so arch-owned list are put into per-architecture list which is then used (solely) for looking up arch-owned gdb.Symbol. Approved-By: Tom Tromey <tom@tromey.com>
2025-03-19gdb/python: preserve identity for gdb.Symtab objectsJan Vrany1-1/+17
This commit changes symtab_to_symtab_object() so that each it is called with a particular struct symtab * it returns the very same gdb.Symtab object. This is done by searching per-objfile linked list of instances and - if found - return it rather than creating new gdb.Symtab. Approved-By: Tom Tromey <tom@tromey.com>
2025-03-19gdb/python: new styling argument to gdb.executeAndrew Burgess1-6/+33
Currently, gdb.execute emits styled output when the command is sending its output to GDB's stdout, and produces unstyled output when the output is going to a string. But it is not unreasonable that a user might wish to capture styled output from a gdb.execute call, for example, the user might want to display the styled output are part of some larger UI output block. At the same time, I don't think it makes sense to always produce styled output when capturing the output in a string; if what the user wants is to parse the output, then the style escape sequences make this far harder. I propose that gdb.execute gain a new argument 'styling'. When False we would always produce unstyled output, and when True we would produce styled output if styling is not disabled by some other means. For example, if GDB's 'set style enabled' is off, then I think gdb.execute() should respect that. My assumption here is that gdb.execute() might be executed by some extension. If the extension thinks "styled output world work here", but the user hates styled output, and has turned it off, then the extension should not be forcing styled output on the user. I chose 'styling' instead of 'styled' as the Python argument name because we already use 'styling' in gdb.Value.format_string, and we don't use 'styled' anywhere else. This is only a little bit of consistency, but I still think it's a good thing. The default for 'styling' will change depending on where the output is going. When gdb.execute is sending the output to GDB's stdout then the default for 'styling' is True. When the output is going to a string, then the default for 'styling' will be False. Not only does this match the existing behaviour, but I think this makes sense. By default we assume that output captured in a string is going to be parsed, and therefore styling markup is unhelpful, while output going to stdout should receive styling. This fixes part of the problem described in PR gdb/32676. That bug tries to capture styled source listing in a string, which wasn't previously possible. There are some additional issues with capturing source code; GDB caches the source code in the source code cache. However, GDB doesn't check if the cached content is styled or not. As a consequence, if the first time the source of a file is shown it is unstyled, then the cached will hold the unstyled source code, and future requests will return that unstyled source. I'll address this issue in a separate patch. Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=32676 Approved-By: Tom Tromey <tom@tromey.com>
2025-03-18gdb: split up construct_inferior_argumentsAndrew Burgess1-1/+1
The function construct_inferior_arguments (gdbsupport/common-inferior.cc) currently escapes all special shell characters. After this commit there will be two "levels" of quoting: 1. The current "full" quoting, where all posix shell special characters are quoted, and 2. a new "reduced" quoting, where only the characters that GDB sees as special (quotes and whitespace) are quoted. After this, almost all construct_inferior_arguments calls will use the "full" quoting, which is the current quoting. The "reduced" quoting will be used in this commit to restore the behaviour that was lost in the previous commit (more details below). In the future, the reduced quoting will be useful for some additional inferior argument that I have planned. I already posted my full inferior argument work here: https://inbox.sourceware.org/gdb-patches/cover.1730731085.git.aburgess@redhat.com But that series is pretty long, and wasn't getting reviewed, so I'm posted the series in parts now. Before the previous commit, GDB behaved like this: $ gdb -eiex 'set startup-with-shell off' --args /tmp/exec '$FOO' (gdb) show args Argument list to give program being debugged when it is started is "$FOO". Notice that with 'startup-with-shell' off, the argument was left as just '$FOO'. But after the previous commit, this changed to: $ gdb -eiex 'set startup-with-shell off' --args /tmp/exec '$FOO' (gdb) show args Argument list to give program being debugged when it is started is "\$FOO". Now the '$' is escaped with a backslash. This commit restores the original behaviour, as this is (currently) the only way to unquoted shell special characters into arguments from the GDB command line. The series that I listed above includes a new command line option for GDB which provides a better approach for controlling the quoting of special shell characters, but that work requires these patches to be merged first. I've split out the core of construct_inferior_arguments into the new function escape_characters, which takes a set of characters to escape. Then the two functions escape_shell_characters and escape_gdb_characters call escape_characters with the appropriate character sets. Finally, construct_inferior_arguments, now takes a boolean which indicates if we should perform full shell escaping, or just perform the reduced escaping. I've updated all uses of construct_inferior_arguments to pass a suitable value to indicate what escaping to perform (mostly just 'true', but one case in main.c is different), also I've updated inferior::set_args to take the same boolean flag, and pass it through to construct_inferior_arguments. Tested-By: Guinevere Larsen <guinevere@redhat.com>
2025-03-18Use gdb unordered set and map in Python layerTom Tromey2-4/+4
This changes a couple of files in the Python layer to use gdb:unordered_set and gdb::unordered_map. Another use exists but I think it is being handled by Jan's series. Approved-By: Simon Marchi <simon.marchi@efficios.com>
2025-03-15gdb/python: remove unused argument from builtin_disassembleAndrew Burgess1-19/+10
This commit: commit 15e15b2d9cd3b1db68f99cd3b047352142ddfd1c Date: Fri Sep 17 18:12:34 2021 +0100 gdb/python: implement the print_insn extension language hook added the gdb.disassembler.builtin_disassemble Python API function. By mistake, the implementation accepted two arguments, the second being a "memory_source". However, this second argument was never used, it was left over from an earlier proposed version of the API. Luckily, the only place the unused argument was documented was in the NEWS file and in the output of `help(gdb.builtin_disassemble)`, and neither of these locations really describe what the argument was, or how it would be used. The manual only describes the first (actually used) argument, so I think we are safe enough to delete the unused argument. This allows some additional cleanup, with the store for the argument also being deleted. As the NEWS file did originally document the second argument, I have added a NEWS entry to explain the argument has now been removed. This could potentially break users code if they somehow decided to pass a second argument, however, fixing things is as simple as removing the second (unused) argument. Approved-By: Simon Marchi <simon.marchi@efficios.com>
2025-03-15gdb/python: handle non-utf-8 character from gdb.execute()Andrew Burgess1-1/+2
I noticed that it was not possible to return a string containing non utf-8 characters using gdb.execute(). For example, using the binary from the gdb.python/py-source-styling.exp test: (gdb) file ./gdb/testsuite/outputs/gdb.python/py-source-styling/py-source-styling Reading symbols from ./gdb/testsuite/outputs/gdb.python/py-source-styling/py-source-styling... (gdb) set style enabled off (gdb) list 26 21 int some_variable = 1234; 22 23 /* The following line contains a character that is non-utf-8. This is a 24 critical part of the test as Python 3 can't convert this into a string 25 using its default mechanism. */ 26 char c[] = "�"; /* List this line. */ 27 28 return 0; 29 } (gdb) python print(gdb.execute('list 26', to_string=True)) Python Exception <class 'UnicodeDecodeError'>: 'utf-8' codec can't decode byte 0xc0 in position 250: invalid start byte Error occurred in Python: 'utf-8' codec can't decode byte 0xc0 in position 250: invalid start byte It is necessary to disable styling before the initial 'list 26', otherwise the source will be passed through GNU source highlight, and GNU source highlight seems to be smart enough to figure out the character encoding, and convert it to UTF-8. This conversion is then cached in the source cache, and the later Python gdb.execute call will get back a pure UTF-8 string. If source styling is disabled, then GDB caches the string without the conversion to UTF-8, now the gdb.execute call gets back the string with a non-UTF-8 character within it, and Python throws an error during its attempt to create a string object. I'm not, at this point, proposing a solution that tries to guess the source file encoding, though I guess such a thing could be done. Instead, I think we should make use of the host_charset(), as set by the user with 'set host-charset ....' during the creation of the Python string. To do this, in execute_gdb_command, we should switch from PyUnicode_FromString, which requires the input be a UTF-8 string, to using PyUnicode_Decode, which allows GDB to specify the string encoding. We will use host_charset(). With this done, it is now possible to list the file contents using gdb.execute(), with the contents passing through a string: (gdb) set host-charset ISO-8859-1 (gdb) python print(gdb.execute('list 26', to_string=True), end='') 21 int some_variable = 1234; 22 23 /* The following line contains a character that is non-utf-8. This is a 24 critical part of the test as Python 3 can't convert this into a string 25 using its default mechanism. */ 26 char c[] = "À"; /* List this line. */ 27 28 return 0; 29 } (gdb) There are already plenty of other places in GDB's Python code where we use PyUnicode_Decode to create a string from something that might contain user generated content, so I believe this is the correct approach.
2025-03-11Use gdb map in py-connection.cTom Tromey1-4/+3
This changes py-connection.c to use gdb::unordered_map. Approved-By: Simon Marchi <simon.marchi@efficios.com>
2025-03-10Fix check-include-guards.pyTom Tromey1-3/+3
I noticed that check-include-guards.py doesn't error in certain situations -- but in situations where the --update flag would cause a file to be changed. This patch changes the script to issue an error for any discrepancy. It also fixes the headers that weren't correct. Approved-By: Simon Marchi <simon.marchi@efficios.com>
2025-03-06[gdb/python] Fix typosTom de Vries3-5/+5
Fix typos: ... gdb/python/py-framefilter.c:749: indention ==> indentation gdb/python/py-framefilter.c:837: indention ==> indentation gdb/python/py-lazy-string.c:35: sting ==> string gdb/python/py-progspace.c:119: Retun ==> Return gdb/python/py-progspace.c:139: Retun ==> Return ...
2025-03-06[gdb/python] Fix typos in libTom de Vries2-2/+2
Fix typos: ... gdb/python/lib/gdb/disassembler.py:84: dissables ==> disables gdb/python/lib/gdb/command/xmethods.py:40: experession ==> expression ...
2025-03-03Bploc should try to return full pathSimon Farre1-3/+22
Compilers often emit relative paths in the line number program, relative to the build directory for that compilation unit (if it's DWARF>=4 I think). Therefore use symtab->fullname() when not null as this seemingly has attempted path normalization for the symtab and only fall back on symtab->filename which will never be null if that fails. This has a much better UX. Applications may choose to expose this name as a clickable link to some file, at which point a non-normalized and non-absolute path would lead nowhere. When I wrote this feature the first time, I don't think this relative-to-cu-scheme was as prevalent in the output of gcc/clang for DWARF. Approved-By: Tom Tromey <tom@tromey.com>
2025-02-27gdb, gdbserver, gdbsupport: fix some namespace comment formattingSimon Marchi1-1/+1
I noticed a // namespace selftests comment, which doesn't follow our comment formatting convention. I did a find & replace to fix all the offenders. Change-Id: Idf8fe9833caf1c3d99e15330db000e4bab4ec66c
2025-02-18[gdb] Fix some typosTom de Vries1-1/+1
Fix typos: ... overriden -> overridden reate -> create ... Tested on x86_64-linux. I
2025-02-14gdb/python/dap: prefix internal attributes with underscoreSimon Marchi7-118/+116
I'm currently reading the DAP code, and I think this would help. This is pretty much standard Python style, we do it as some places but not others. I think it helps readability, by saying that this attribute isn't mean to be accessed outside the class. A similar pass could be done for internal methods, I haven't done that. Change-Id: I8e8789b39adafe62d14404d19f7fc75e2a364e01 Approved-By: Tom Tromey <tom@tromey.com>
2025-02-04gdb/python: add void_type () method to gdb.Architecture objectJan Vrany1-1/+15
This commit adds a new method to Python architecture objects that returns a void type for that architecture. This will be useful later to create types for function symbols created using Python extension code. Reviewed-By: Eli Zaretskii <eliz@gnu.org> Approved-By: Andrew Burgess <aburgess@redhat.com>
2025-02-04gdb/python: add domain property to gdb.SymbolJan Vrany1-1/+15
Reviewed-By: Eli Zaretskii <eliz@gnu.org> Approved-By: Andrew Burgess <aburgess@redhat.com>
2025-02-04gdb/python: add subblocks property to gdb.BlockJan Vrany1-1/+34
This commit adds new propery "subblocks" to gdb.Block objects. This allows Python to traverse block tree starting with global block. Reviewed-By: Eli Zaretskii <eliz@gnu.org> Approved-By: Andrew Burgess <aburgess@redhat.com>
2025-02-03pre-commit autoupdateSimon Marchi1-1/+1
Run `pre-commit autoupdate`. This picks up a fresh Black version from 2025, and with it comes a small but welcome formatting change. There is a new version of isort as well, but no formatting change there. Change-Id: Ie654a9c14c3a4096893011082668efb57c166fa4
2025-01-17gdb: Migrate frame unwinders to use C++ classesGuinevere Larsen1-23/+39
Frame unwinders have historically been a structure populated with callback pointers, so that architectures (or other specific unwinders) could install their own way to handle the inferior. However, since moving to C++, we could use polymorphism to get the same functionality in a more readable way. Polymorphism also makes it simpler to add new functionality to all frame unwinders, since all that's required is adding it to the base class. As part of the changes to add support to disabling frame unwinders, this commit makes the first baby step in using polymorphism for the frame unwinders, by making frame_unwind a virtual class, and adds a couple of new classes. The main class added is frame_unwind_legacy, which works the same as the previous structs, using function pointers as callbacks. This class was added to allow the transition to happen piecemeal. New unwinders should instead follow the lead of the other classes implemented. 2 of the others, frame_unwind_python and frame_unwind_trampoline, were added because it seemed simpler at the moment to do that instead of reworking the dynamic allocation to work with the legacy class, and can be used as an example to future implementations. Finally, the cygwin unwinder was converted to a class since it was most of the way there already. Reviewed-by: Thiago Jung Bauermann <thiago.bauermann@linaro.org> Approved-By: Simon Marchi <simon.marchi@efficios.com> Approved-By: Andrew Burgess <aburgess@redhat.com>
2025-01-17gdb: add "unwinder class" to frame unwindersGuinevere Larsen1-0/+1
A future patch will add a way to disable certain unwinders based on different characteristics. This patch aims to make it more convenient to disable related unwinders in bulk, such as architecture specific ones, by identifying all unwinders by which part of the code adds it. The classes, and explanations, are as follows: * GDB: An internal unwinder, added by GDB core, such as the unwinder for dummy frames; * EXTENSION: Unwinders added by extension languages; * DEBUGINFO: Unwinders installed by the debug info reader; * ARCH: Unwinders installed by the architecture specific code. Reviewed-By: Eli Zaretskii <eliz@gnu.org> Reviewed-by: Thiago Jung Bauermann <thiago.bauermann@linaro.org> Approved-By: Simon Marchi <simon.marchi@efficios.com> Approved-By: Andrew Burgess <aburgess@redhat.com>
2025-01-13Fix AIX CI build break.Aditya Vidyadhar Kamath1-1/+1
In AIX a recent commit caused a build break with the error as shown below. In file included from python/py-color.h:23, from python/python.c:39: python/python-internal.h:86:10: fatal error: Python.h: No such file or directory 86 | #include <Python.h> In AIX, we run builds with and without python for our internal CI's. A feature development made by the recent commit https://sourceware.org/git/?p=binutils-gdb.git;a=commitdiff;h=6447969d0ac774b6dec0f95a0d3d27c27d158690 missed to guard Python.h in HAVE_PYTHON macro. This commit is a fix for the same. Approved-By: Tom Tromey <tom@tromey.com>
2025-01-13Handle case where DAP line can be NoneTom Tromey1-2/+2
A comment in bugzilla pointed out a bug in my earlier patch to handle the DAP "linesStartAt1" setting. In particular, in the backtrace code, "line" can be None, which would lead to an exception from export_line. This patch fixes the problem. Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=32468
2025-01-12Add an option with a color type.Andrei Pikas4-3/+415
Colors can be specified as "none" for terminal's default color, as a name of one of the eight standard colors of ISO/IEC 6429 "black", "red", "green", etc., as an RGB hexadecimal tripplet #RRGGBB for 24-bit TrueColor, or as an integer from 0 to 255. Integers 0 to 7 are the synonyms for the standard colors. Integers 8-15 are used for the so-called bright colors from the aixterm extended 16-color palette. Integers 16-255 are the indexes into xterm extended 256-color palette (usually 6x6x6 cube plus gray ramp). In general, 256-color palette is terminal dependent and sometimes can be changed with OSC 4 sequences, e.g. "\033]4;1;rgb:00/FF/00\033\\". It is the responsibility of the user to verify that the terminal supports the specified colors. PATCH v5 changes: documentation fixed. PATCH v6 changes: documentation fixed. PATCH v7 changes: rebase onto master and fixes after review. PATCH v8 changes: fixes after review.
2025-01-09GDB: trad-frame: Store length of value_bytes in trad_frame_saved_regThiago Jung Bauermann1-3/+4
The goal is to ensure that it is available in frame_unwind_got_bytes () to make sure that the provided buf isn't larger than the size of the register being provisioned. In the process, regcache's cached_reg_t::data also needed to be converted to a gdb::byte_vector, so that the register contents' size can be tracked. Approved-By: Simon Marchi <simon.marchi@efficios.com>
2025-01-06Handle linesStartAt1 in DAPTom Tromey6-14/+50
The DAP initialize request has a "linesStartAt1" option, where the client can indicate that it prefers whether line numbers be 0-based or 1-based. This patch implements this. I audited all the line-related code in the DAP implementation. Note that while a similar option exists for column numbers, gdb doesn't handle these yet, so nothing is done here. Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=32468
2024-12-31Use 'flags' when expanding symtabs in gdbpy_lookup_static_symbolsTom Tromey1-2/+1
This changes gdbpy_lookup_static_symbols to pass the 'flags' parameter to expand_symtabs_matching. This should refine the search somewhat. Note this is "just" a performance improvement, as the loop over symtabs already checks 'flags'. v2 also removes 'SEARCH_GLOBAL_BLOCK' and updates py-symbol.exp to verify that this works properly. Thanks to Tom for this insight. Co-Authored-By: Tom de Vries <tdevries@suse.de>
2024-12-20Fix latent bug in gdbpy_lookup_static_symbolsTom Tromey1-3/+4
gdbpy_lookup_static_symbols is missing an error check for the case where symbol_to_symbol_object returns NULL. Approved-By: Tom de Vries <tdevries@suse.de>
2024-12-18Run check-include-guards.pyTom Tromey10-30/+30
This patch is the result of running check-include-guards.py on the current tree. Running it a second time causes no changes. Reviewed-By: Tom de Vries <tdevries@suse.de>
2024-12-16Re-run isortTom Tromey1-1/+1
I noticed that an earlier commit caused a change in the isort output. This patch repairs the problem.
2024-12-14[gdb/dap] Fix regressions with python 3.6Tom de Vries1-1/+2
With test-case gdb.dap/ada-arrays.exp, on Leap openSUSE 15.6 with python 3.6, I run into: ... Python Exception <class 'TypeError'>: 'type' object is not subscriptable Error occurred in Python: 'type' object is not subscriptable ERROR: tcl error sourcing ada-arrays.exp. ... This is due to using a python 3.9 construct: ... thread_ids: dict[int, int] = {} ... Fix this by using typing.Dict instead. Tested on x86_64-linux.
2024-12-13gdb/dap: allow some requests when the process is runningoltolm2-2/+2
It is impossible to set a breakpoint when the process is running, which I find annoying. LLDB does not have this restriction. I made `setBreakpoints` and `breakpointLocations` work when the process is running. Probably more requests can be changed, but I only need these two at the moment. Approved-By: Tom Tromey <tom@tromey.com>
2024-12-13gdb-dap: fix gdb.error: Frame is invalid.Oleg Tolmatcev2-18/+34
When you try to use a frame on one thread and it was created on another you get an error. I fixed it by creating a map from a frame ID to a thread ID. When a frame is created it is added to the map. When you try to find a frame for an id it checks if it is on the correct thread and if not switches to that thread. I had to store the frame id instead of the frame itself in a "_ScopeReference". Signed-off-by: Oleg Tolmatcev <oleg.tolmatcev@gmail.com> Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=32133 Approved-By: Tom Tromey <tom@tromey.com>
2024-12-09Introduce NoOpStringPrinterTom Tromey1-1/+39
We discovered that attempting to print a very large string-like array would succeed on the CLI, but in DAP would cause the "variables" request to fail with: value requires 67038491 bytes, which is more than max-value-size This turns out to be a limitation in Value.format_string, which de-lazy-ifies the value. This patch fixes this problem by introducing a new NoOpStringPrinter class, and then using it for string-like values. This printer returns a lazy string, which solves the problem. Note there are some special cases where we do not want to return a lazy string. I've documented these in the code. I considered making gdb.Value.lazy_string handle these cases -- for example it could return 'self' rather than a lazy string in some situations -- but this approach was simpler.
2024-12-09Clean up 0-length handling in gdbpy_create_lazy_string_objectTom Tromey1-8/+17
gdbpy_create_lazy_string_object will throw an exception if you pass it a NULL pointer without also setting length=0 -- the default, length==-1, will fail. This seems bizarre. Furthermore, it doesn't make sense to do this check for array types, as an array can have a zero length. This patch cleans up the check and makes it specific to TYPE_CODE_PTR.
2024-12-09Reject non-string types in gdb.Value.lazy_stringTom Tromey2-14/+3
Currently, gdb.Value.lazy_string will allow the conversion of any object to a "lazy string". However, this was never the intent and is weird besides. This patch changes this code to correctly throw an exception in the non-matching cases. Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=20769
2024-12-09Omit artificial symbols from DAP variables responseTom Tromey3-1/+18
While testing DAP, we found a situation where a compiler-generated variable caused the "variables" request to fail -- the variable in question being an apparent 67-megabyte string. It seems to me that artificial variables like this aren't interesting to DAP users, and the gdb CLI omits these as well. This patch changes DAP to omit these variables, adding a new gdb.Symbol.is_artificial attribute to make this possible.
2024-12-09Defer DAP launch command until after configurationDoneTom Tromey1-38/+114
PR dap/32090 points out that gdb's DAP "launch" sequencing is incorrect. The current approach (which is itself a 2nd implementation...) was based on a misreading of the spec. The spec has since been clarified here: https://github.com/microsoft/debug-adapter-protocol/issues/497 The clarification here is that a client is free to send the "launch" (or "attach") request at any point after the "initialized" event has been sent by gdb. However, the "launch" does not cause any action to be taken -- and does not send a response -- until after "configurationDone" has been seen. This patch implements this by arranging for the launch and attach commands to return a DeferredRequest object. All the tests needed updates. I've also added a new test that checks that the deferred "launch" request can be cancelled. (Note that the cancellation is lazy -- it also waits until configurationDone is seen. This could be fixed, but I was not sure whether it is important to do so.) Finally, the "launch" command has a somewhat funny sequencing now. Simply sending the command and waiting for a response yielded strange results if the inferior did not stop -- in this case, the repsonse was never sent. So now, the command is split into two parts, with some setup being done synchronously (for better error propagation) and the actual "run" being done async. Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=32090 Reviewed-by: Kévin Le Gouguec <legouguec@adacore.com>
2024-12-09Add DAP deferred requestsTom Tromey1-24/+136
This adds a new "deferred request" capability to DAP. The idea here is that if a request returns a DeferredRequest object, then no response is sent immediately to the client. Instead, the request is pending until the deferred request is rescheduled. Some minor refactorings, particularly in cancellation, were needed to make this work. There's no use of this in the tree yet -- that is the next patch. Reviewed-by: Kévin Le Gouguec <legouguec@adacore.com>
2024-12-09Allow cancellation of DAP-thread requestsTom Tromey1-6/+18
This patch started as an attempt to fix the comment in CancellationHandler.cancel, but while working on it I found that the code could be improved as well. The current DAP cancellation code only handles the case where work is done on the gdb thread -- by checking for cancellation in interruptable_region. This means that if a request is handled completely in tthe DAP thread, then cancellation will never work. Now, this isn't a bug per se. DAP doesn't actually require that cancellation succeed. In fact, I think it can't, because cancellation is inherently racy. However, a coming patch will add a sort of "pending" request, and it would be nice if that were cancellable before any commands are sent to the gdb thread. No test in this patch, but one will arrive at the end of the series. Reviewed-by: Kévin Le Gouguec <legouguec@adacore.com>
2024-12-09Refactor CancellationHandler in DAPTom Tromey1-18/+15
This refactors the DAP CancellationHandler to be a context manager, and reorganizes the caller to use this. This is a bit more robust and also simplifies a subsequent patch in this series. Reviewed-by: Kévin Le Gouguec <legouguec@adacore.com>