aboutsummaryrefslogtreecommitdiff
path: root/gdb
AgeCommit message (Collapse)AuthorFilesLines
2025-05-16Update comment for find_field_create_batonTom Tromey1-7/+3
Andrew pointed out that a recent commit neglected to update the comment for find_field_create_baton. This patch fixes the oversight.
2025-05-15Fix regression with dynamic array boundsTom Tromey6-81/+154
Kévin discovered that commit ba005d32b0f ("Handle dynamic field properties") regressed a test in the internal AdaCore test suite. The problem here is that, when writing that patch, I did not consider the case where an array type's bounds might come from a member of a structure -- but where the array is not defined in the structure's scope. In this scenario the field-resolution logic would trip this condition: /* Defensive programming in case we see unusual DWARF. */ if (fi == nullptr) return nullptr; This patch reworks this area, partly backing out that commit, and fixes the problem. In the new code, I chose to simply duplicate the field's location information. This isn't totally ideal, in that it might result in multiple copies of a baton. However, this seemed nicer than tracking the DIE/field correspondence for every field in every CU -- my thinking here is that this particular dynamic scenario is relatively rare overall. Also, if the baton cost does prove onerous, we could intern the batons somewhere. Regression tested on x86-64 Fedora 41. I also tested this using the AdaCore internal test suite. Tested-By: Simon Marchi <simon.marchi@efficios.com>
2025-05-15gdb: rename ldirname to gdb_ldirnameAndreas Schwab10-13/+13
It conflicts with the ldirname function that will be added in the next libiberty sync.
2025-05-14testsuite: fix gdb_exit for MinGW targetRohr, Stephan1-1/+2
GDB is not properly exited via 'remote_close host' when running the testsuite in a MinGW environment. Use the 'quit' command to properly exit the GDB debugging session. Approved-By: Tom Tromey <tom@tromey.com>
2025-05-14testsuite: get windows PID on MinGW targetRohr, Stephan1-1/+1
Also translate the MinGW PID to the Windows PID when running on a MinGW target. Approved-By: Tom Tromey <tom@tromey.com>
2025-05-14Fix create_breakpoint_parse_arg_string self-testTom Tromey1-8/+5
The emoji patch broke the create_breakpoint_parse_arg_string self-test when gdb is running on a suitable terminal. The problem is that the test case doesn't take the error prefix string into account. This patch fixes the test by having it compare the exception message directly, rather than relying on the result of exception_print. I did try a different approach, of having the test mimic exception_print, but this one seemed cleaner to me. Approved-By: Simon Marchi <simon.marchi@efficios.com>
2025-05-14Add initializers to field_of_this_resultTom Tromey3-14/+3
This adds initializers to field_of_this_result, so that certain spots don't have to memset it. This approach seems safer and cleaner. Approved-By: Simon Marchi <simon.marchi@efficios.com>
2025-05-14Fix some pre-commit nits in gdb/__init__.pyTom Tromey1-3/+3
I noticed that pre-commit has some complaints (flake8 and codespell) about gdb/__init__.py. This patch fixes these. Approved-By: Tom de Vries <tdevries@suse.de>
2025-05-13gdb/python: new gdb.ParameterPrefix classAndrew Burgess4-0/+502
This commit adds a new gdb.ParameterPrefix class to GDB's Python API. When creating multiple gdb.Parameters, it is often desirable to group these together under a sub-command, for example, 'set print' has lots of parameters nested under it, like 'set print address', and 'set print symbol'. In the Python API the 'print' part of these commands are called prefix commands, and are created using gdb.Command objects. However, as parameters are set via the 'set ....' command list, and shown through the 'show ....' command list, creating a prefix for a parameter usually requires two prefix commands to be created, one for the 'set' command, and one for the 'show' command. This often leads to some duplication, or at the very least, each user will end up creating their own helper class to simplify creation of the two prefix commands. This commit adds a new gdb.ParameterPrefix class. Creating a single instance of this class will create both the 'set' and 'show' prefix commands, which can then be used while creating the gdb.Parameter. Here is an example of it in use: gdb.ParameterPrefix('my-prefix', gdb.COMMAND_NONE) This adds 'set my-prefix' and 'show my-prefix', both of which are prefix commands. The user can then add gdb.Parameter objects under these prefixes. The gdb.ParameterPrefix initialise method also supports documentation strings, so we can write: gdb.ParameterPrefix('my-prefix', gdb.COMMAND_NONE, "Configuration setting relating to my special extension.") which will set the documentation string for the prefix command. Also, it is possible to support prefix commands that use the `invoke` functionality to handle unknown sub-commands. This is done by sub-classing gdb.ParameterPrefix and overriding either 'invoke_set' or 'invoke_show' to handle the 'set' or 'show' prefix command respectively. Reviewed-By: Eli Zaretskii <eliz@gnu.org>
2025-05-13gdb/guile: generate general description string for parametersAndrew Burgess4-18/+71
This commit builds on the previous one, and auto-generates a general description string for parameters defined via the Guile API. This brings the Guile API closer inline with the Python API. It is worth reading the previous commit to see some motivating examples. This commit updates get_doc_string in guile/scm-param.c to allow for the generation of a general description string. Then in gdbscm_make_parameter, if '#:doc' was not given, get_doc_string is used to generate a suitable default. This does invalidate (and so the commit removes) this comment that was in gdbscm_make_parameter: /* If doc is NULL, leave it NULL. See add_setshow_cmd_full. */ First, Python already does exactly what I'm proposing here, and has done for a while, with no issues reported. And second, I've gone and read add_setshow_cmd_full, and some of the functions it calls, and can see no reasoning behind this comment... ... well, there is one reason that I can think of, but I'll discuss that more below. With this commit, if I define a parameter like this: (use-modules (gdb)) (register-parameter! (make-parameter "print test" #:command-class COMMAND_NONE #:parameter-type PARAM_BOOLEAN)) Then, in GDB, I now see this behaviour: (gdb) help show print test Show the current value of 'print test'. This command is not documented. (gdb) help set print test Set the current value of 'print test'. This command is not documented. (gdb) The two 'This command is not documented.' lines are new. This output is what we get from a similarly defined parameter using the Python API (see the previous commit for an example). I mentioned above that I can think of one reason for the (now deleted) comment in gdbscm_make_parameter about leaving the doc field as NULL, and that is this: consider the following GDB behaviour: (gdb) help show style filename foreground Show the foreground color for this property. (gdb) Notice there is only a single line of output. If I want to get the same behaviour from a parameter defined in Guile, I might try skipping the #:doc argument, but (after this commit), if I do that, GDB will auto-generate some text for me, giving two lines of output (see above). So, next, maybe I try setting #:doc to the empty string, but if I do that, then I get this: (use-modules (gdb)) (register-parameter! (make-parameter "print test" #:doc "" #:command-class COMMAND_NONE #:parameter-type PARAM_BOOLEAN)) (gdb) help show print test Show the current value of 'print test'. (gdb) Notice the blank line, that's not what I wanted. In fact, the only way to get rid of the second line is to leave the 'doc' variable as NULL in gdbscm_make_parameter, which, due to the new auto-generation, is no longer possible. This issue also existed in the Python API, and was addressed in commit: commit 4b68d4ac98aec7cb73a4b276ac7dd38d112786b4 Date: Fri Apr 11 23:45:51 2025 +0100 gdb/python: allow empty gdb.Parameter.__doc__ string After this commit, an empty __doc__ string for a gdb.Parameter is translated into a NULL pointer passed to the add_setshow_* command, which means the second line of output is completely skipped. And this commit includes the same solution for the Guile API. Now, with this commit, and the Guile parameter using an empty '#:doc' string, GDB has the following behaviour: (gdb) help show print test Show the current value of 'print test'. (gdb) This matches the output for a similarly defined parameter in Python.
2025-05-13gdb/guile: improve auto-generated strings for parametersAndrew Burgess2-14/+40
Consider this user defined parameter created in Python: class test_param(gdb.Parameter): def __init__(self, name): super ().__init__(name, gdb.COMMAND_NONE, gdb.PARAM_BOOLEAN) self.value = True test_param('print test') If this is loaded into GDB, then we observe the following behaviour: (gdb) show print test The current value of 'print test' is "on". (gdb) help show print test Show the current value of 'print test'. This command is not documented. (gdb) help set print test Set the current value of 'print test'. This command is not documented. (gdb) If we now define the same parameter using Guile: (use-modules (gdb)) (register-parameter! (make-parameter "print test" #:command-class COMMAND_NONE #:parameter-type PARAM_BOOLEAN)) And load this into a fresh GDB session, we see the following: (gdb) show print test Command is not documented is off. (gdb) help show print test This command is not documented. (gdb) help set print test This command is not documented. (gdb) The output of 'show print test' doesn't make much sense, and is certainly worse than the Python equivalent. For both the 'help' commands it appears as if the first line is missing, but what is actually happening is that the first line has become 'This command is not documented.', and the second line is then missing. The problems can all be traced back to 'get_doc_string' in guile/scm-param.c. This is the guile version of this function. There is a similar function in python/py-param.c, however, the Python version returns one of three different strings depending on the use case. In contrast, the Guile version just returns 'This command is not documented.' in all cases. The three cases that the Python code handles are, the 'set' string, the 'show' string, and the general 'description' string. Right now the Guile get_doc_string only returns the general 'description' string, which is funny, because, in gdbscm_make_parameter, where get_doc_string is used, the one case that we currently don't need is the general 'description' string. Instead, right now, the general 'description' string is used for both the 'set' and 'show' cases. In this commit I plan to bring the Guile API a little more inline with the Python API. I will update get_doc_string (in scm-param.c) to return either a 'set' or 'show' string, and gdbscm_make_parameter will make use of these strings. The changes to the Guile get_doc_string are modelled on the Python version of this function. It is also worth checking out the next commit, which is related, and helps motivate how the changes have been implemented in this commit. After this commit, the same Guile parameter description shown above, now gives this behaviour: (gdb) show print test The current value of 'print test' is off. (gdb) help show print test Show the current value of 'print test'. (gdb) help set print test Set the current value of 'print test'. (gdb) The 'show print test' output now matches the Python behaviour, and is much more descriptive. The set and show 'help' output are now missing the second line when compared to the Python output, but the first line is now correct, and I think this is better than the previous Guile output. In the next commit I'll address the problem of the missing second line. Existing tests have been updated to expect the new output.
2025-05-13gdb/python: allow empty gdb.Parameter.__doc__ stringAndrew Burgess4-2/+111
I was recently attempting to create some parameters via the Python API. I wanted these parameters to appear similar to how GDB handles the existing 'style' parameters. Specifically, I was interested in this behaviour: (gdb) help show style filename foreground Show the foreground color for this property. (gdb) help set style filename foreground Set the foreground color for this property. (gdb) Notice how each 'help' command only gets a single line of output. I tried to reproduce this behaviour via the Python API and was unable. The problem is that, in order to get just a single line of output like this, the style parameters are registered with a call to add_setshow_color_cmd with the 'help_doc' being passed as nullptr. On the Python side, when parameters are created, the 'help_doc' is obtained with a call to get_doc_string (python/py-param.c). This function either returns the __doc__ string, or a default string: "This command is not documented.". To avoid returning the default we could try setting __doc__ to an empty string, but setting this field to any string means that GDB prints a line for that string, like this: class test_param(gdb.Parameter): __doc__ = "" def __init__(self, name): super ().__init__(name, gdb.COMMAND_NONE, gdb.PARAM_BOOLEAN) self.value = True test_param('print test') Then in GDB: (gdb) help set print test Set the current value of 'print test'. (gdb) The blank line is the problem I'd like to solve. This commit makes a couple of changes to how parameter doc strings are handled. If the doc string is set to an empty string, then GDB now converts this to nullptr, which removes the blank line problem, the new behaviour in GDB (for the above `test_param`) is: (gdb) help set print test Set the current value of 'print test'. (gdb) Next, I noticed that if the set/show docs are set to empty strings, then the results are less than ideal: class test_param(gdb.Parameter): set_doc = "" def __init__(self, name): super ().__init__(name, gdb.COMMAND_NONE, gdb.PARAM_BOOLEAN) self.value = True test_param('print test') And in GDB: (gdb) help set print test This command is not documented. (gdb) So, if the set/show docs are the empty string, GDB now forces these to be the default string instead, the new behaviour in GDB is: (gdb) help set print test Set the current value of 'print test'. This command is not documented. (gdb) I've added some additional asserts; the set/show docs should always be non-empty strings, which I believe is the case after this commit. And the 'doc' string returned from get_doc_string should never nullptr, but could be empty. There are new tests to cover all these changes.
2025-05-13gdb/python/guile: check for invalid prefixes in Command/Parameter creationAndrew Burgess6-2/+171
The manual for gdb.Parameter says: If NAME consists of multiple words, and no prefix parameter group can be found, an exception is raised. This makes sense; we cannot create a parameter within a prefix group, if the prefix doesn't exist. And this almost works, so: (gdb) python gdb.Parameter("xxx foo", gdb.COMMAND_NONE, gdb.PARAM_BOOLEAN) Python Exception <class 'RuntimeError'>: Could not find command prefix xxx. Error occurred in Python: Could not find command prefix xxx. The prefix 'xxx' doesn't exist, and we get an error. But, if we try multiple levels of prefix: (gdb) python gdb.Parameter("print xxx foo", gdb.COMMAND_NONE, gdb.PARAM_BOOLEAN) This completes without error, however, we didn't get what we were maybe expecting: (gdb) show print xxx foo Undefined show print command: "xxx foo". Try "help show print". But we did get: (gdb) show print foo The current value of 'print foo' is "off". GDB stopped scanning the prefix string at the unknown 'xxx', and just created the parameter there. I don't think this makes sense, nor is it inline with the manual. An identical problem exists with gdb.Command creation; GDB stops parsing the prefix at the first unknown prefix, and just creates the command there. The manual for gdb.Command says: NAME is the name of the command. If NAME consists of multiple words, then the initial words are looked for as prefix commands. In this case, if one of the prefix commands does not exist, an exception is raised. So again, the correct action is, I believe, to raise an exception. The problem is in gdbpy_parse_command_name (python/py-cmd.c), GDB calls lookup_cmd_1 to look through the prefix string and return the last prefix group. If the very first prefix word is invalid then lookup_cmd_1 returns NULL, and this case is handled. However, if there is a valid prefix, followed by an invalid prefix, then lookup_cmd_1 will return a pointer to the last valid prefix list, and will update the input argument to point to the start of the invalid prefix word. This final case, where the input is left pointing to an unknown prefix, was previously not handled. I've fixed gdbpy_parse_command_name, and added tests for command and parameter creation to cover this case. The exact same error is present in the guile API too. The guile documentation for make-parameter and make-command says the same things about unknown prefixes resulting in an exception, but the same error is present in gdbscm_parse_command_name (guile/scm-cmd.c), so I've fixed that too, and added some tests.
2025-05-12gdb/dwarf: skip broken .debug_macro.dwoSimon Marchi1-1/+19
Running gdb.base/errno.exp with gcc <= 13 with split DWARF results in: $ make check TESTS="gdb.base/errno.exp" RUNTESTFLAGS="CC_FOR_TARGET=gcc-13 --target_board=fission" (gdb) break -qualified main /home/smarchi/src/binutils-gdb/gdb/dwarf2/read.c:7549: internal-error: locate_dwo_sections: Assertion `!dw_sect->readin' failed. A problem internal to GDB has been detected, further debugging may prove unreliable. ... FAIL: gdb.base/errno.exp: macros: gdb_breakpoint: set breakpoint at main (GDB internal error) The assert being hit has been added in 28f15782adab ("gdb/dwarf: read multiple .debug_info.dwo sections"), but it merely exposed an existing problem. gcc versions <= 13 are affected by this bug: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=111409 Basically, it produces .dwo files with multiple .debug_macro.dwo sections, with some unresolved links between them. I think that this macro debug info is unusable, and all we can do is ignore it. In locate_dwo_sections, if we detect a second .debug_macro.dwo section, forget about the previous .debug_macro.dwo and any subsequent one. This will effectively make it as if the macro debug info wasn't there at all. The errno test seems happy with it: # of expected passes 84 # of expected failures 8 Change-Id: I6489b4713954669bf69f6e91865063ddcd1ac2c8 Approved-By: Tom Tromey <tom@tromey.com>
2025-05-12gdb/dwarf: move loops into locate_dw{o,z}_sectionsSimon Marchi3-69/+69
For a subsequent patch, it would be easier if the loop over sections inside locate_dwo_sections (I want to maintain some state for the duration of the loop). Move the for loop in there. And because locate_dwz_sections is very similar, modify that one too, to keep both in sync. Change-Id: I90b3d44184910cc2d86af265bb4b41828a5d2c2e Approved-By: Tom Tromey <tom@tromey.com>
2025-05-12gdb/dap: fix decode_sourceoltolm1-3/+3
The documentation for the Source interface says * The path of the source to be shown in the UI. * It is only used to locate and load the content of the source if no * `sourceReference` is specified (or its value is 0). but the code used `path` first. I fixed it to use `sourceReference` first. Approved-By: Tom Tromey <tom@tromey.com>
2025-05-12[PATCH] Add syscall tests when following/detaching from forkKeith Seitz2-0/+177
breakpoints/13457 discusses issues with syscall catchpoints when following forks, lamenting that there is no coverage for the various permutations of `follow-fork-mode' and `detach-on-fork'. This is an attempt to try and cover some of this ground. Unfortunately the state of syscall support when detaching after the fork is very, very inconsistent across various architectures. [I've tested extensively Fedora/RHEL platforms.] Right now, the only reliable platform to run tests on is x86_64/i?86 for the specific case where we do not detach from the fork. Consequently, this patch limits testing to those architectures. I have updated breakpoints/13457 with my findings on failures with the detaching case. Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=13457 Approved-By: Andrew Burgess <aburgess@redhat.com>
2025-05-12gdb: pass std::string from linux_find_memory_regions_fullAndrew Burgess1-6/+6
Update linux_find_memory_region_ftype to take 'const std::string &' instead of 'const char *', update the two functions which are passed as callbacks to linux_find_memory_regions_full. There should be no user visible changes after this commit. Approved-By: Simon Marchi <simon.marchi@efficios.com>
2025-05-12gdb: remove unnecessary function declarationAndrew Burgess1-2/+0
There's no need to declare a function immediately before its definition. Lets not do that. There should be no user visible changes after this commit. Approved-By: Simon Marchi <simon.marchi@efficios.com>
2025-05-12gdb: move extra checks into dump_note_entry_pAndrew Burgess1-6/+13
Now that dump_note_entry_p is always called (see previous commit), we can move some of the checks out of linux_make_mappings_callback into dump_note_entry_p. The checks only exist in linux_make_mappings_callback because, before the previous commit, we couldn't be sure that dump_note_entry_p would be called or not, so linux_make_mappings_callback had to run its own checks. Now that dump_note_entry_p is always called we can rely on that function to filter out which mappings should result in an NT_FILE entry, and linux_make_mappings_callback can just create an entry for everything it is passed. As a result of this change I was able to remove the inode argument from linux_make_mappings_callback and linux_find_memory_regions_thunk. The inode check has now moved to dump_note_entry_p. There should be no user visible changes after this commit. Approved-By: Simon Marchi <simon.marchi@efficios.com>
2025-05-12gdb: always call should_dump_mapping_p during core file creationAndrew Burgess1-12/+6
This commit moves the logic for whether should_dump_mapping_p is called out of linux_find_memory_regions_full and pushes it down into the two callback functions that are used as the should_dump_mapping_p callback; `dump_mapping_p` and `dump_note_entry_p`. Older Linux kernels don't make the 'Anonymous' information available in the smaps file, and currently, GDB handles this by not calling the should_dump_mapping_p callback in linux_find_memory_regions_full, instead the answer is hard-coded to true. This is (maybe) fine for dump_mapping_p, but for dump_note_entry_p, this choice makes little sense. The dump_note_entry_p function doesn't even use the anonymous mapping information. I propose that the 'has_anonymous' check should be moved out of linux_find_memory_regions_full, and pushed into dump_mapping_p. Then in dump_note_entry_p there will be no has_anonymous check; it just isn't needed. This allows linux_find_memory_regions_full to be simplified a little, and will allow some additional clean ups in linux_make_mappings_callback, which is the partner function to dump_note_entry_p (see linux_make_mappings_corefile_notes), now that we know dump_note_entry_p is always called. This follow on clean up will be done in a later commit in this series. Looking at dump_mapping_p, I do wonder if the ::has_anonymous check could be moved later in the function. The first few checks in dump_mapping_p don't rely on the anonymous information, so running them might give better results. However, the lack of the anonymous information is only for older kernels, so testing any changes in this area would likely require spinning up an older kernel, and as the years pass, we likely care about this case less. So for now I've left the ::has_anonymous check as the first thing in dump_mapping_p as this keeps the existing behaviour. There should be no user visible changes after this commit. Approved-By: Simon Marchi <simon.marchi@efficios.com>
2025-05-12gdb: pass struct smaps_data to linux_dump_mapping_p_ftypeAndrew Burgess1-38/+19
Simplify the argument passing in linux_find_memory_regions_full when calling the should_dump_mapping_p callback. Instead of pulling all the components from the smaps_data object and passing them separately, just pass the smaps_data object. I think this change is justified on its own; the code seems cleaner, and easier to read to my eye. But additionally, in a later commit in this series I want to pass smaps_data::has_anonymous to the should_dump_mapping_p callback, which would mean adding yet another argument, and I think the argument list is already long enough. Changing the function now to pass the smaps_data object means that I will already have the ::has_anonymous field available in the later commit. There should be no user visible changes after this commit. Approved-By: Simon Marchi <simon.marchi@efficios.com>
2025-05-12gdb: use bool more in linux-tdep.cAndrew Burgess1-23/+23
Convert linux_dump_mapping_p_ftype to return a bool, and then update everything that is needed to handle the fallout from this change. There should be no user visible changes from this commit. Approved-By: Simon Marchi <simon.marchi@efficios.com>
2025-05-12gdb: add '-stopped' and '-running' options to "info threads"Tankut Baris Aktemur6-14/+272
Add two options to "info threads": `-stopped` and `-running`. The purpose of these options is to filter the output of the command. The `-stopped` option means "print stopped threads only" and, similarly, `-running` means "print the running threads only". When both options are provided by the user, the indication is that the user wants the union. That is, the output contains both stopped and running threads. Suppose we have an application with 5 threads, 2 of which have hit a breakpoint. The "info threads" command in the non-stop mode gives: (gdb) info threads Id Target Id Frame * 1 Thread 0x7ffff7d99740 (running) 2 Thread 0x7ffff7d98700 something () at file.c:30 3 Thread 0x7ffff7597700 (running) 4 Thread 0x7ffff6d96700 something () at file.c:30 5 Thread 0x7ffff6595700 (running) (gdb) Using the "-stopped" flag, we get (gdb) info threads -stopped Id Target Id Frame 2 Thread 0x7ffff7d98700 something () at file.c:30 4 Thread 0x7ffff6d96700 something () at file.c:30 (gdb) Using the "-running" flag, we get (gdb) info threads -running Id Target Id Frame * 1 Thread 0x7ffff7d99740 (running) 3 Thread 0x7ffff7597700 (running) 5 Thread 0x7ffff6595700 (running) (gdb) Using both flags prints all: (gdb) info threads -stopped -running Id Target Id Frame * 1 Thread 0x7ffff7d99740 (running) 2 Thread 0x7ffff7d98700 something () at file.c:30 3 Thread 0x7ffff7597700 (running) 4 Thread 0x7ffff6d96700 something () at file.c:30 5 Thread 0x7ffff6595700 (running) (gdb) When combined with a thread ID, filtering applies to those threads that are matched by the ID. (gdb) info threads 3 Id Target Id Frame 3 Thread 0x7ffff7597700 (running) (gdb) info threads -stopped 3 No threads matched. (gdb) Regression-tested on X86_64 Linux. Reviewed-By: Eli Zaretskii <eliz@gnu.org> Reviewed-By: Guinevere Larsen <guinevere@redhat.com> Approved-by: Pedro Alves <pedro@palves.net
2025-05-12gdb: update "info threads" output when no threads match the argumentsTankut Baris Aktemur5-6/+12
If "info threads" is provided with the thread ID argument but no such threads matching the thread ID(s) are found, GDB prints No threads match '<ID...>'. Update this output to the more generalized No threads matched. The intention is that the next patch, and potentially future ones, will extend the command with more filter/match arguments. We cannot customize the output to each such argument. Hence, be more generic. Reviewed-By: Eli Zaretskii <eliz@gnu.org> Approved-by: Pedro Alves <pedro@palves.net
2025-05-12gdb: pass info_threads_opts to print_thread_info_1Tankut Baris Aktemur1-39/+41
The "info threads" command tracks its options in a struct named 'info_threads_opts', which currently has only one option. Pass the whole options object to helper functions, instead of passing the option value individually. This is a refactoring to make adding more options easier. Reviewed-By: Guinevere Larsen <guinevere@redhat.com> Approved-by: Pedro Alves <pedro@palves.net
2025-05-10gdb: LoongArch: Emulate floating-point branch instructionsTiezhu Yang1-1/+17
Add bceqz and bcnez cases in loongarch_insn_is_cond_branch() and loongarch_next_pc() to emulate floating-point branch instructions. Here are the references: https://loongson.github.io/LoongArch-Documentation/LoongArch-Vol1-EN.html#_bceqz_bcnez https://loongson.github.io/LoongArch-Documentation/LoongArch-Vol1-EN.html#table-table-of-instruction-encoding Approved-by: Kevin Buettner <kevinb@redhat.com> Signed-off-by: Tiezhu Yang <yangtiezhu@loongson.cn>
2025-05-09Fix two comments in cli-style.cTom Tromey1-2/+2
I noticed that a couple of new comments in cli-style.c mentioned the wrong command name. This patch fixes the comments.
2025-05-09Move "show style sources" documentationTom Tromey1-3/+3
I noticed that I had inadvertently put the "set style warning-prefix" documentation between the paragraph for "set style sources" and the paragraph for "show style sources". This patch moves the latter up a bit to clean this up.
2025-05-08Change substitute_path_component to use std::stringTom Tromey1-43/+24
This changes substitute_path_component to use std::string and std::string_view, simplifying it greatly and removing some manual memory management. Approved-By: Simon Marchi <simon.marchi@efficios.com>
2025-05-08Move substitute_path_componentTom Tromey5-108/+85
This moves substitute_path_component out of utils.c. I considered making a new file for this (still could if someone wants that), but since the only caller is in auto-load.c, I moved it there instead. I've also moved the tests into auto-load.c as well. This way substitute_path_component can be static. Approved-By: Simon Marchi <simon.marchi@efficios.com>
2025-05-06Do not set yydebug in cp-name-parser.yTom Tromey1-3/+5
This reverts the change to cp-name-parser.y, avoiding a TSan report. Approved-By: Simon Marchi <simon.marchi@efficios.com>
2025-05-06Remove kfail from templates.expTom Tromey1-4/+1
templates.exp has one remaining kfail. However, the output in question has been stabilized ever since the cp-name-parser.y work -- the test just wasn't updated. Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=8617 Reviewed-By: Keith Seitz <keiths@redhat.com>
2025-05-06Rewrite bug references in templates.expTom Tromey1-22/+22
templates.exp has many kfails that refer to old GNATS bug numbers. This patch updates them to refer to Bugzilla instead. Reviewed-By: Keith Seitz <keiths@redhat.com>
2025-05-06Revert "gdb: support zero inode in generate-core-file command"Andrew Burgess1-1/+1
This reverts commit 1e21c846c275fc6e387ca903a129096be2a53d0b. This change was causing unexpected mappings to be included in the core files generated by GDB, which was triggering warnings when GDB opened a core file, like this: warning: Can't open file [stack] during file-backed mapping note processing warning: Can't open file [vvar] during file-backed mapping note processing For now I'm reverting the above commit and will come to the list again when I have a solution that addresses the original issue without also including the unexpected mappings.
2025-05-06Handle field with dynamic bit offsetTom Tromey5-22/+161
I discovered that GCC emitted incorrect DWARF for the test case included in this patch. Eric wrote a fix for GCC, but then he found that gdb crashed on the resulting file. This test has a field that is at a non-constant bit offset from the start of the type. DWARF 5 does not allow for this situation (I've sent a report to the DWARF list), but DWARF 3 did allow for this via a combination of an expression for the byte offset and then the use of DW_AT_bit_offset. This looks like: <5><117a>: Abbrev Number: 17 (DW_TAG_member) <117b> DW_AT_name : (indirect string, offset: 0x1959): another_field ... <1188> DW_AT_bit_offset : 6 <1189> DW_AT_data_member_location: 6 byte block: 99 3d 1 0 0 22 (DW_OP_call4: <0x1193>; DW_OP_plus) ... <3><1193>: Abbrev Number: 2 (DW_TAG_dwarf_procedure) <1194> DW_AT_location : 15 byte block: 97 94 1 37 1a 32 1e 23 7 38 1b 31 1c 23 3 (DW_OP_push_object_address; DW_OP_deref_size: 1; DW_OP_lit7; DW_OP_and; DW_OP_lit2; DW_OP_mul; DW_OP_plus_uconst: 7; DW_OP_lit8; DW_OP_div; DW_OP_lit1; DW_OP_minus; DW_OP_plus_uconst: 3) Now, that combination is not fully general, in that the bit offset must be a constant -- only the byte offset may really vary. However, I couldn't come up with a situation where full generality is needed, mainly because GNAT won't seem to pack fields into the padding of a variable-length array. Meanwhile, the reason for the gdb crash is that the code handling DW_AT_bit_offset assumes that the byte offset is a constant. This causes an assertion failure. This patch arranges for DW_AT_bit_offset to be applied during field resolution, when needed.
2025-05-06Introduce apply_bit_offset_to_field helper functionTom Tromey3-40/+72
This patch makes a new function, apply_bit_offset_to_field, that is used to handle the logic of DW_AT_bit_offset. Currently there is just a single caller, but the next patch will change this.
2025-05-06Use OBSTACK_ZALLOC when allocating batonsTom Tromey1-6/+9
I found some places in dwarf2/read.c that allocate a location baton, but fail to initialize one of the fields. It seems safer to me to use OBSTACK_ZALLOC here, so this patch makes this change. This will be useful in a subsequent patch as well, where a new field is added to one of the batons.
2025-05-06Clean up handle_member_locationTom Tromey1-3/+2
This removes a redundant check from handle_member_location, and also changes the complaint -- currently it will issue the "complex location" complaint, but really what is happening here is an unrecognized form.
2025-05-06Handle dynamic field propertiesTom Tromey9-91/+237
I found a situation where gdb could not properly decode an Ada type. In this first scenario, the discriminant of a type is a bit-field. PROP_ADDR_OFFSET does not handle this situation, because it only allows an offset -- not a bit-size. My original approach to this just added a bit size as well, but after some discussion with Eric Botcazou, we found another failing case: a tagged type can have a second discriminant that appears at a variable offset. So, this patch changes this code to accept a general 'struct field' instead of trying to replicate the field-finding machinery by itself. This is handled at property-evaluation time by simply using a 'field' and resolving its dynamic properties. Then the usual field-extraction function is called to get the value. Because the baton now just holds a field, I renamed PROP_ADDR_OFFSET to PROP_FIELD. The DWARF reader now defers filling in the property baton until the fields have been attached to the type. Finally, I noticed that if the discriminant field has a biased representation, then unpack_field_as_long would not handle this either. This bug is also fixed here, and the test case checks this. Regression tested on x86-64 Fedora 41.
2025-05-06Add new unpack_field_as_long overloadTom Tromey2-6/+22
This introduces a new unpack_field_as_long that takes the field object directly, rather than a type and an index. This will be used in the next patch.
2025-05-06Add resolve_dynamic_fieldTom Tromey2-42/+62
The final patch in this series will change one dynamic property approach to use a struct field rather than an offset and a field type. This is convenient because the reference in DWARF is indeed to a field -- and this approach lets us reuse the field-extraction logic that already exists in gdb. However, the field in question may have dynamic properties which must be resolved before it can be used. This patch prepares for this by introducing a separate resolve_dynamic_field function. This patch should cause no visible changes to behavior.
2025-05-06Constify property_addr_infoTom Tromey2-14/+14
This changes most places to use a const property_addr_info. This seems more correct to me because normally the user of a property_addr_info should not modify it. Furthermore, some functions already take a const object, and for a subsequent patch it is convenient if other functions do as well.
2025-05-06gdb/testsuite: Add require allow_hipcc_tests in gdb.rocm/mi-attach.expLancelot SIX1-1/+2
The gdb.rocm/mi-attach.exp test is missing a proper `require` check to ensure that the current configuration can run ROCm tests. This issue has been reported by Baris. This patch adds the missing `allow_hipcc_tests` requirement, and also adds `load_lib rocm.exp` to enable this test. Change-Id: Ie136adfc2d0854268b92af5c4df2dd0334dce259 Reviewed-By: Tankut Baris Aktemur <tankut.baris.aktemur@intel.com> Approved-By: Tom Tromey <tom@tromey.com>
2025-05-06gdb: support zero inode in generate-core-file commandAndrew Burgess1-1/+1
It is possible, when creating a shared memory segment (i.e. with shmget), that the id of the segment will be zero. When looking at the segment in /proc/PID/smaps, the inode field of the entry holds the shared memory segment id. And so, it can be the case that an entry (in the smaps file) will have an inode of zero. When GDB generates a core file, with the generate-core-file (or its gcore alias) command, the shared memory segment should be written into the core file. Fedora GDB has, since 2008, carried a patch that tests this case. There is no fix for GDB associated with the test, and unfortunately, the motivation for the test has been lost to the mists of time. This likely means that a fix was merged upstream without a suitable test, but I've not been able to find and relevant commit. The test seems to be checking that the shared memory segment with id zero, is being written to the core file. While looking at this test and trying to work out if it should be posted upstream, I saw that GDB does appear to write the shared memory segment into the core file (as expected), which is good. However, GDB still isn't getting this case exactly right. In gcore_memory_sections (gcore.c) we call back into linux-tdep.c (via the gdbarch_find_memory_regions call) to correctly write the shared memory segment into the core file, however, in linux_make_mappings_corefile_notes, when we use linux_find_memory_regions_full to create the NT_FILE note, we call back into linux_make_mappings_callback for each mapping, and in here we reject any mapping with a zero inode. The result of this, is that, for a shared memory segment with a non-zero id, after loading the core file, the shared memory segment will appear in the 'proc info mappings' output. But, for a shared memory segment with a zero id, the segment will not appear in the 'proc info mappings' output. I propose fixing this by not checking the inode in linux_make_mappings_callback. The inode check was in place since the code was originally added in commit 451b7c33cb3c9ec6272c36870 (in 2012). The test for this bug, based on the original Fedora patch, can be found on the mailing list here: https://inbox.sourceware.org/gdb-patches/0d389b435cbb0924335adbc9eba6cf30b4a2c4ee.1741776651.git.aburgess@redhat.com I have not committed this test into the tree though because the test was just too unreliable. User space doesn't have any control over the shared memory id, so all we can do is spam out requests for new shared memory segments and hope that we eventually get the zero id. Obviously, this can fail; the zero id might already be in use by some long running process, or the kernel, for whatever reason, might choose to never allocate the zero id. The test I posted (see above thread) did work more than 50% of the time, but it was far closer to a 50% success rate than 100%, and I really don't like introducing unreliable tests.
2025-05-06gdb/testsuite: add gcore_cmd_available predicate procAndrew Burgess7-4/+25
Add a new gcore_cmd_available predicate proc that can be used in a 'requires' line, and make use of it in a few tests. All of the tests I have modified call gdb_gcore_cmd as one of their first actions and exit if the gcore command is not available, so it makes sense (I think) to move the gcore command check into a requires call. There should be no change in what is actually run after this commit.
2025-05-06gdb/python/guile: check if styling is disabled in Color.escape_sequenceAndrew Burgess6-7/+41
I noticed that the gdb.Color.escape_sequence() method would produce an escape sequence even when styling is disabled. I think this is the wrong choice. Ideally, when styling is disabled (e.g. with 'set style enabled off'), GDB should not be producing styled output. If a GDB extension is using gdb.Color to apply styling to the output, then currently, the extension should be checking 'show style enabled' any time Color.escape_sequence() is used. This means lots of code duplication, and the possibility that some locations will be missed, which means disabling styling no longer does what it says. I propose that Color.escape_sequence() should return the empty string if styling is disabled. A Python extension can then do: python c_none = gdb.Color('none') c_red = gdb.Color('red') print(c_red.escape_sequence(True) + "Text in red." + c_none.escape_sequence(True)) end If styling is enable this will print some red text. And if styling is disabled, then it will print text in the terminal's default color. I have applied the same fix to the guile API. I have extended the tests to cover this case. Approved-By: Tom Tromey <tom@tromey.com>
2025-05-05Fix sign of Ada rational constantsTom Tromey3-6/+18
My earlier patch commit 0c03db90 ("Use correct sign in get_mpz") was (very) incorrect. It changed get_mpz to check for a strict sign when examining part of an Ada rational constant. However, in Ada the "delta" for a fixed-point type must be positive, and so the components of the rational representation will be positive. This patch corrects the error. It also renames the get_mpz function, in case anyone is tempted to reuse this code for another purpose. Finally, this pulls over the test from the internal AdaCore test suite that found this issue.
2025-05-02[gdb/testsuite] Simplify gdb.tui/tui-layout-asm.expTom de Vries1-37/+69
On x86_64-cygwin, with test-case gdb.tui/tui-layout-asm.exp I run into: ... WARNING: The following failure is probably due to the TUI window width. See the comments in the test script for more details. FAIL: $exp: scroll to end of assembler (scroll failed) ... The problem is as follows. On the TUI screen, we have: 1 | 0x1004010ff <__gdb_set_unbuffered_output+95> nop | 2 | 0x100401100 <__cxa_atexit> jmp *0x6fc2(%rip) # 0x10040 | ... We send the down key, which should have the effect of scrolling up. So, we expect that the second line moves to the first line. That seems to be the case indeed: ... 1 | 0x100401100 <__cxa_atexit> jmp *0x6fc2(%rip) # 0x1004080c8 <__imp___cxa_ | ... but the line has changed somewhat, so the matching fails. We could increase the width of the screen, as suggested in the test-case, but I think that approach is fragile. Instead, fix this by relaxing the matching: just check that the line before scrolling is fully contained in the line after scrolling, or the other way around. Doing so gets us the next failure: ... FAIL: $exp: scroll to end of assembler (too much assembler) ... The test-case states: ... if { $down_count > 250 } { # Maybe we should accept this as a pass in case a target # really does have loads of assembler to scroll through. fail "$testname (too much assembler)" ... and I agree, so fix this by issuing a pass. This results in the test-case taking ~20 seconds, so reduce the maximum number of scrolls from 250 to 25, bringing that down to ~10 seconds. Tested on x86_64-cygwin and x86_64-linux. PR testsuite/32898 Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=32898
2025-05-02[gdb/symtab] Throw DWARF error on out-of-bounds DW_FORM_strxTom de Vries2-3/+45
With the test-case contained in the patch, and gdb build with -fsanitize=address we get: ... ==23678==ERROR: AddressSanitizer: heap-buffer-overflow ...^M READ of size 1 at 0x6020000c30dc thread T3^[[1m^[[0m^M ptype global_var^M #0 0x2c6a40b in bfd_getl32 bfd/libbfd.c:846^M #1 0x168f96c in read_str_index gdb/dwarf2/read.c:15349^M ... The executable contains an out-of-bounds DW_FORM_strx attribute: ... $ readelf -wi $exec <2eb> DW_AT_name :readelf: Warning: string index of 1 converts to \ an offset of 0xc which is too big for section .debug_str (indexed string: 0x1): <string index too big> ... and read_str_index doesn't check for this: ... info_ptr = (str_offsets_section->buffer + str_offsets_base + str_index * offset_size); if (offset_size == 4) str_offset = bfd_get_32 (abfd, info_ptr); ... and consequently reads out-of-bounds. Fix this in read_str_index by checking for the out-of-bounds condition and throwing a DWARF error: ... (gdb) ptype global_var DWARF Error: Offset from DW_FORM_GNU_str_index or DW_FORM_strx pointing \ outside of .debug_str_offsets section in CU at offset 0x2d7 \ [in module dw-form-strx-out-of-bounds] No symbol "global_var" in current context. (gdb) ... Tested on x86_64-linux. Approved-By: Tom Tromey <tom@tromey.com>