aboutsummaryrefslogtreecommitdiff
path: root/gdb/cli
AgeCommit message (Collapse)AuthorFilesLines
2025-03-17gdb: make cli_styling static within cli/cli-style.cAndrew Burgess2-5/+26
The cli_styling variable is controlled by 'set style enabled on|off' user setting, and is currently globally visible. In a couple of places we access this variable directly, though in ui-file.c the accesses are all performed through term_cli_styling(), which is a function that wraps checking cli_styling along with a check that GDB's terminal supports styling. In a future commit, I'd plan to add a new parameter to gdb.execute() which will allow styling to be temporarily suppressed. In an earlier proposal, I made gdb.execute() disable styling by changing the value of cli_styling, however, this approach has a problem. If gdb.execute() is used to run 'show style enabled', the changing cli_styling will change what is printed. Similarly, if gdb.execute() is used to execute 'set style enabled on|off' then having gdb.execute() save and restore the value of cli_styling will undo the adjustment from 'set style enabled ...'. So what I plan to do in the future, is add a new control flag which can be used to temporarily disable styling. To make this new control variable easier to add, lets force everyone to call term_cli_styling() to check if styling is enabled or not. To force everyone to use term_cli_styling() this commit makes cli_styling static within gdb/cli/cli-style.c. Approved-By: Tom Tromey <tom@tromey.com>
2025-03-06[gdb/cli] Fix typosTom de Vries2-2/+2
Fix typos: ... gdb/cli/cli-utils.h:85: fuction ==> function gdb/cli/cli-decode.c:2457: Ambigous ==> Ambiguous ...
2025-02-24gdb/styling: only check TERM environment once, during initialisationAndrew Burgess2-0/+57
We currently check the TERM environment variable any time we call one of the ui_file::can_emit_style_escape() functions. This seems excessive. During GDB's startup we also check for the NO_COLOR environment variable and disable styling if this is set. I propose that we combine these two checks, and perform them just once during startup (as the current NO_COLOR check is currently done). As with the NO_COLOR check, if the TERM variable is set to "dumb" indicating that styling is not supported then we should just set cli_styling to false. This does mean that the user can then 'set style enabled on', even for a dumb terminal, which was not possible previously. Before this commit the "dumb" terminal check was separate and would prevent styling even if 'set style enabled on' was in effect. Of course, trying to turn on styling in a dumb terminal might not give the results that a user hope for. And so, I have implemented a check in `set_style_enabled`, so in a dumb terminal a user will see this: (gdb) set style enabled on warning: The current terminal doesn't support styling. Styled output might not appear as expected. After which GDB will try to emit styling. We could, potentially, prevent styling being enabled instead of emitting a warning, but I'm inclined to let the user turn on styling if they really want to. Approved-By: Kevin Buettner <kevinb@redhat.com> Acked-By: Tom Tromey <tom@tromey.com>
2025-02-24gdb/doc: fix help text for 'set style disassembler enabled'Andrew Burgess1-3/+11
The help text for 'set/show style disassembler enable' was output of date. It talks about GDB requiring the Python Pygments library, but for many common architectures this is no longer the case, libopcode is used for styling. The Python Pygments library is still used as a fallback for those architectures that libopcode doesn't currently style. I've updated the help text to try and explain all this. The manual was already updated. Approved-By: Eli Zaretskii <eliz@gnu.org>
2025-02-16gdb: fix color_option_def compile error (clang)Andrew Oates1-1/+1
color_option_def was added in commit 6447969d0 ("Add an option with a color type."), but not used. The color_option_def constructor passes the wrong number of arguments to the option_def constructor. Since color_option_def is a template and never actually instantiated, GCC does not fail to compile this. clang generates an error (see below). This passes nullptr to the extra_literals_ option_def ctor argument, which matches what filename_option_def above it does. clang's generated error: ../../gdb/cli/cli-option.h:343:7: error: no matching constructor for initialization of 'option_def' : option_def (long_option_, var_color, ^ ~~~~~~~~~~~~~~~~~~~~~~~~ ../../gdb/cli/cli-option.h:50:13: note: candidate constructor not viable: requires 8 arguments, but 7 were provided constexpr option_def (const char *name_, ^ ../../gdb/cli/cli-option.h:37:8: note: candidate constructor (the implicit copy constructor) not viable: requires 1 argument, but 7 were provided struct option_def ^ ../../gdb/cli/cli-option.h:37:8: note: candidate constructor (the implicit move constructor) not viable: requires 1 argument, but 7 were provided Approved-By: Tom de Vries <tdevries@suse.de>
2025-02-07[gdb/build] Fix x86_64-w64-mingw32 build by avoiding SCNx8Tom de Vries1-3/+9
With an x86_64-w64-mingw32 targeted cross-build on x86_64-linux, I run into: ... gdb/cli/cli-decode.c: \ In function 'ui_file_style::color parse_cli_var_color(const char**)': gdb/cli/cli-decode.c:2917:41: error: expected ')' before 'SCNx8' int parsed_args = sscanf (*args, "#%2" SCNx8 "%2" SCNx8 "%2" SCNx8 "%n", ... Apparantly, the definition of SCNx8 is missing in inttypes.h. Rewrite the sscanf call to use SCNx32, which is available. Tested by: - completing aforementioned cross-build, and - build & test on x86_64-linux. Suggested-By: Tom Tromey <tom@tromey.com> Approved-By: Tom Tromey <tom@tromey.com>
2025-01-29Use command style in cmd_show_listTom Tromey1-5/+9
cmd_show_list is a bit funny because it shows partial command names -- for a command like "show abc xyz", it will only show "abc xyz". Nevertheless, I think it makes some sense to highlight these with the command style. That is what this patch does.
2025-01-29Use command style in "help" commandTom Tromey3-41/+53
This changes the help command to use the new command style when displaying text like: List of "catch" subcommands: As a side effect, this mildly -- but not hugely -- cleans up some i18n issues in help_list. The header comment for that function is also changed to the gdb style. Finally, this function used to print something like: Type "help catch" followed by catch subcommand name for full documentation. The second "catch" here seems redundant to me, so this patch removes it.
2025-01-15Fix help formatting for string and filename optionsTom Tromey1-2/+2
I happened to notice that "help add-inferior" said: -execFILENAME FILENAME is the file name of the executable to use as the main program. This is missing a space after "-exec". This patch fixes the bug. If ok'd on time I plan to check this in to the gdb-16 branch as well. Approved-by: Kevin Buettner <kevinb@redhat.com>
2025-01-14Use filename style in "show" commandsTom Tromey1-2/+7
I found a few filename-related "show" commands that do not use the filename style when displaying the file. This patch fixes the oversight. Approved-By: Andrew Burgess <aburgess@redhat.com>
2025-01-12Add an option with a color type.Andrei Pikas8-42/+296
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.
2024-12-18Run check-include-guards.pyTom Tromey8-24/+24
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-12Replace uses of "title" style with "command"Tom Tromey2-9/+9
Currently the "title" style is only used when printing command names. The "title" name itself is probably a misnomer, but meanwhile this patch changes the existing uses to instead use the new "command" style for consistency. The "title" style is not removed; see the next patch. Reviewed-By: Keith Seitz <keiths@redhat.com> Approved-By: Andrew Burgess <aburgess@redhat.com>
2024-12-12Introduce "command" stylingTom Tromey3-8/+29
This adds a new "command" style that is used when styling the name of a gdb command. Note that not every instance of a command name that is output by gdb is changed here. There is currently no way to style error() strings, and there is no way to mark up command help strings. Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=31747 Reviewed-By: Eli Zaretskii <eliz@gnu.org> Reviewed-By: Keith Seitz <keiths@redhat.com> Approved-By: Andrew Burgess <aburgess@redhat.com>
2024-11-22[gdbsupport] Add gdb::{waitpid,read,write,close}Tom de Vries1-1/+1
We have gdb::handle_eintr, which allows us to rewrite: ... ssize_t ret; do { errno = 0; ret = ::write (pipe[1], "+", 1); } while (ret == -1 && errno == EINTR); ... into: ... ssize_t ret = gdb::handle_eintr (-1, ::write, pipe[1], "+", 1); ... However, the call to write got a bit mangled, requiring effort to decode it back to its original form. Instead, add a new function gdb::write that allows us to write: ... ssize_t ret = gdb::write (pipe[1], "+", 1); ... Likewise for waitpid, read and close. Tested on x86_64-linux.
2024-11-22gdb/disasm: fix demangling when disassembling the current functionAndrew Burgess1-9/+11
When disassembling function symbols in C++ code, if GDB is asked to disassemble a function by name then the function name in the header line can be demangled by turning on `set print asm-demangle on`, e.g.: (gdb) disassemble foo_type::some_function Dump of assembler code for function _ZN8foo_type13some_functionE7my_type: 0x0000000000401142 <+0>: push %rbp ... etc ... End of assembler dump. (gdb) set print asm-demangle on (gdb) disassemble foo_type::some_function Dump of assembler code for function foo_type::some_function(my_type): 0x0000000000401142 <+0>: push %rbp ... etc ... │ End of assembler dump. │ However, if GDB is disassembling the current function, then this demangling doesn't work, e.g.: (gdb) break foo_type::some_function Breakpoint 1 at 0x401152: file mangle.cc, line 16. (gdb) run Starting program: /tmp/mangle Breakpoint 1, foo_type::some_function (this=0x7fffffffa597, obj=...) at mangle.cc:16 16 obj.update (); (gdb) disassemble Dump of assembler code for function _ZN8foo_type13some_functionE7my_type: 0x0000000000401142 <+0>: push %rbp ... etc ... End of assembler dump. (gdb) set print asm-demangle on (gdb) disassemble Dump of assembler code for function _ZN8foo_type13some_functionE7my_type: 0x0000000000401142 <+0>: push %rbp ... etc ... End of assembler dump. This commit fixes this issue, and extends gdb.cp/disasm-func-name.exp, which was already testing the first case (disassemble by name) to also cover disassembling the current function. Approved-By: Tom Tromey <tom@tromey.com>
2024-11-11Wrap help options when building help stringTom Tromey2-24/+42
When building a help string, it's possible that the resulting options will go over 80 columns. This patch changes this code to add line wrapping where needed. This can most be seen by looking "help bt" and in particular the "-frame-info" help text.
2024-11-11Wrap help strings at 80 columnsTom Tromey2-8/+9
This patch ensures that all ordinary help strings are wrapped at 80 columns. For the most part this consists of changing code like this (note the embedded \n and the trailing backslash without a newline): -Manage the space-separated list of debuginfod server URLs that GDB will query \ -when missing debuginfo, executables or source files.\nThe default value is \ -copied from the DEBUGINFOD_URLS environment variable."), ... to end each line with \n\, like: +Manage the space-separated list of debuginfod server URLs that GDB will\n\ +query when missing debuginfo, executables or source files.\n\ +The default value is copied from the DEBUGINFOD_URLS environment variable."), Approved-By: Eli Zaretskii <eliz@gnu.org>
2024-11-08gdb: fixes and tests for the 'edit' commandAndrew Burgess1-1/+2
This commit was inspired by this mailing list post: https://inbox.sourceware.org/gdb-patches/osmtfvf5xe3yx4n7oirukidym4cik7lehhy4re5mxpset2qgwt@6qlboxhqiwgm When reviewing that patch, the first thing I wanted to do was add some tests for the 'edit' command because, as far as I can tell, there are no real tests right now. The approach I've taken for testing is to override the EDITOR environment variable, setting this to just 'echo'. Now when the 'edit' command is run, instead of entering an interactive editor, the shell instead echos back the arguments that GDB is trying to pass to the editor. The output might look like this: (gdb) edit +22 /tmp/gdb/testsuite/gdb.base/edit-cmd.c (gdb) We can then test this like any other normal command. I then wrote some basic tests covering a few situations like, using 'edit' before the inferior is started. Using 'edit' without any arguments, and using 'edit' with a line number argument. There are plenty of cases that are still not tested, for example, the test program only has a single source file for example. But we can always add more tests later. I then used these tests to validate the fix proposed in the above patch. The patch above does indeed fix some cases, specifically, when GDB stops at a location (e.g. a breakpoint location) and then the 'edit' command without any arguments is fixed. But using the 'list' command to show some other location, and then 'edit' to edit the just listed location broken before and after the above patch. I am instead proposing this alternative patch which I think fixes more cases. When GDB stops at a location then 'edit' with no arguments should correctly edit the current line. And using 'list XX' to list a specific location, followed by 'edit' should also now edit the just listed location. Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=17669 Co-Authored-By: Lluís Batlle i Rossell <viric@viric.name> Approved-By: Tom Tromey <tom@tromey.com>
2024-11-04gdb: add filename option supportAndrew Burgess2-3/+107
This commit adds support for filename options to GDB's option sub-system (see cli/cli-option.{c,h}). The new filename options support quoted and escaped filenames, and tab completion is fully supported. This commit adds the new option, and adds these options to the 'maintenance test-options' command as '-filename', along with some tests that exercise this new option. I've split the -filename testing into two. In gdb.base/options.exp we use the -filename option with some arbitrary strings. This tests that GDB can correctly extract the value from a filename option, and that GDB can complete other options after a filename option. However, these tests don't actually pass real filenames, nor do they test filename completion. In gdb.base/filename-completion.exp I have added some tests that test the -filename option with real filenames, and exercise filename tab completion. This commit doesn't include any real uses of the new filename options, that will come in the next commit.
2024-10-22[gdb] Handle EINTR in run_under_shellTom de Vries1-1/+6
When building gdb with -O2 -fsanitize=thread and running test-case gdb.base/bg-exec-sigint-bp-cond.exp, I run into: ... (gdb) c&^M Continuing.^M (gdb) Quit^M (gdb) quit_count=1 ^M Breakpoint 2, foo () at bg-exec-sigint-bp-cond.c:23^M 23 return 0;^M FAIL: $exp: no force memory write: \ SIGINT does not interrupt background execution ... What happens is that: - the breakpoint hits - while evaluating the condition of the breakpoint, $_shell("kill -INT <pid-of-gdb>") is called, handled by run_under_shell - in run_under_shell, a vfork is issued - in the vfork child, execl executes the kill command - in the vfork parent, waitpid is called to wait for the result of the kill command - waitpid returns -1 with errno set to EINTR - run_under_shell doesn't check the result of waitpid, and returns the value of local variable status. Since waitpid returned -1, status was not assigned a value, so it's uninitialized, and happens to be non-zero - the breakpoint condition evaluates to true, because $_shell("kill -INT <pid-of-gdb>") != 0 - the breakpoint triggers a stop, which the test-case doesn't expect. Fix this by using gdb::handle_eintr to call waitpid in run_under_shell. Also handle the case that waitpid returns an error other than EINTR, using perror_with_name. Tested on x86_64-linux. Approved-By: Tom Tromey <tom@tromey.com> PR gdb/30695 Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=30695
2024-10-20Use std::make_unique in more placesTom Tromey1-1/+1
I searched for spots using ".reset (new ...)" and replaced most of these with std::make_unique. I think this is a bit cleaner and more idiomatic. Regression tested on x86-64 Fedora 40. Reviewed-By: Klaus Gerlicher<klaus.gerlicher@intel.com>
2024-10-08[gdb/contrib] Add more separators in spellcheck.shTom de Vries1-1/+1
Add two more separators in spellcheck.sh: colon and comma. Doing so triggers the "inbetween->between" rule, which gives an incorrect result. Override this with "inbetween->between, in between, in-between" [1], in a new file gdb/contrib/common-misspellings.txt. Fix the following common misspellings: ... everytime -> every time sucess -> success thru -> through transfered -> transferred inbetween -> between, in between, in-between ... Verified with spellcheck.sh. Tested on x86_64-linux. [1] https://www.grammarly.com/blog/commonly-confused-words/in-between-or-inbetween/
2024-10-02gdb: more file name stylingAndrew Burgess1-9/+16
While looking at the recent line number styling commit I noticed a few places where we could add more file name styling. So lets do that. Approved-By: Tom Tromey <tom@tromey.com>
2024-09-30Add line-number stylingTom Tromey3-2/+19
This patch adds separate styling for line numbers. That is, whenever gdb prints a source line number, it uses this style. v2 includes a change to ensure that %ps works in query. Reviewed-By: Eli Zaretskii <eliz@gnu.org> Reviewed-by: Keith Seitz <keiths@redhat.com>
2024-09-30gdb, testsuite: clean duplicate header includesGerlicher, Klaus1-1/+0
Some of the gdb and testsuite files double include some headers. While all headers use include guards, it helps a bit keeping the code base tidy. No functional change. Approved-by: Kevin Buettner <kevinb@redhat.com>
2024-09-24[gdb] Eliminate catch(...) in pipe_commandTom de Vries1-11/+6
Remove duplicate code in pipe_command using SCOPE_EXIT. Tested on aarch64-linux. Approved-By: Tom Tromey <tom@tromey.com>
2024-09-07gdb: move display of completion results into completion_result classAndrew Burgess1-25/+1
This commit moves the printing of the 'complete' command results out of the 'complete_command' function. The printing is now done in a new member function 'completion_result::print_matches'. At this point, this is entirely a refactor. The motivation for this refactor is how 'complete' should print the completion of filename arguments. In some cases the filename results need to have escaping added to the output. This escaping needs to be done immediately prior to printing the result as adding too early will result in multiple 'complete' results potentially being sorted incorrectly. See the subsequent commits for more details. There should be no user visible changes after this commit. Approved-By: Tom Tromey <tom@tromey.com>
2024-09-07gdb: deprecated filename_completer and associated functionsAndrew Burgess3-11/+12
Following on from the previous commit, this commit marks the old unquoted filename completion related functions as deprecated. The aim of doing this is to make it more obvious to someone adding a new command that they should not be using the older unquoted style filename argument handling. I split this change from the previous to make for an easier review. This commit touches more files, but is _just_ function renaming. Check out gdb/completer.{c,h} for what has been renamed. All the other files have just been updated to use the new names. There should be no user visible changes after this commit.
2024-07-15gdb: pass program space to get_current_source_symtab_and_lineSimon Marchi1-5/+9
Make the current program space reference bubble up one level. Change-Id: I6ba6dc4a2cb188720cbb61b84ab5c954aac105c6 Approved-By: Tom Tromey <tom@tromey.com> Reviewed-By: Thiago Jung Bauermann <thiago.bauermann@linaro.org>
2024-07-15gdb: pass program space to have_{full,partial}_symbolsSimon Marchi1-1/+2
Make the current program space reference bubble up one level. Change-Id: I19c4fc2ca955f9c828ef426a077b43983865697b Approved-By: Tom Tromey <tom@tromey.com> Reviewed-By: Thiago Jung Bauermann <thiago.bauermann@linaro.org>
2024-07-15gdb: pass program space to clear_current_source_symtab_and_lineSimon Marchi1-1/+1
Make the current program space reference bubble up one level. Change-Id: I692554474d17e4f4708fd8ad662bf6c0bb964726 Approved-By: Tom Tromey <tom@tromey.com> Reviewed-By: Thiago Jung Bauermann <thiago.bauermann@linaro.org>
2024-05-30gdb: remove unused includes in utils.hSimon Marchi2-0/+2
Remove some includes reported as unused by clangd. Add some includes in other files that were previously relying on the transitive include. Change-Id: Ibdd0a998b04d21362a20d0ca8e5267e21e2e133e
2024-05-17Remove gdb_stdtargerrTom Tromey2-4/+0
This patch removes gdb_stdtargerr. There doesn't seem to be a need for this -- it is always the same as stdtarg, and (I believe) has been for many years. Approved-By: Andrew Burgess <aburgess@redhat.com>
2024-05-08gdb: Change "list ." command's error when no debuginfo is availableGuinevere Larsen1-11/+30
Currently, when a user tries to list the current location, there are 2 different error messages that can happen, either: (gdb) list . No symbol table is loaded. Use the "file" command. or (gdb) list . No debug information available to print source lines. The difference here is if gdb can find any symtabs at all or not, which is not something too important for end-users - and isn't informative at all. This commit changes it so that the error always says that there isn't debug information available, with these two variants: (gdb) list . Insufficient debug info for showing source lines at current PC (0x55555555511d). or (gdb) list . Insufficient debug info for showing source lines at default location. The difference now is if the inferior has started already, which is controlled by the user and may be useful. Unfortunately, it isn't as easy to differentiate if the symtab found for other list parameters is correct, so other invocations, such as "list +" still retain their original error message. Co-Authored-By: Simon Marchi <simark@simark.ca> Reviewed-By: Eli Zaretskii <eliz@gnu.org> Approved-By: Andrew Burgess <aburgess@redhat.com>
2024-04-25gdb: remove gdbcmd.hSimon Marchi3-3/+1
Most files including gdbcmd.h currently rely on it to access things actually declared in cli/cli-cmds.h (setlist, showlist, etc). To make things easy, replace all includes of gdbcmd.h with includes of cli/cli-cmds.h. This might lead to some unused includes of cli/cli-cmds.h, but it's harmless, and much faster than going through the 170 or so files by hand. Change-Id: I11f884d4d616c12c05f395c98bbc2892950fb00f Approved-By: Tom Tromey <tom@tromey.com>
2024-04-25gdb: move style_set_list/style_show_list declarations to cli/cli-style.hSimon Marchi1-0/+4
They are defined in cli/cli-style.c. Change-Id: Ic478a3985ff0fd773bd7ba85bb144c6e914d0be6 Approved-By: Tom Tromey <tom@tromey.com>
2024-04-23gdb: move a bunch of quit-related things to event-top.{c,h}Simon Marchi1-0/+1
Move some declarations related to the "quit" machinery from defs.h to event-top.h. Most of the definitions associated to these declarations are in event-top.c. The exceptions are `quit()` and `maybe_quit()`, that are defined in utils.c. For consistency, move these two definitions to event-top.c. Include "event-top.h" in many files that use these things. Change-Id: I6594f6df9047a9a480e7b9934275d186afb14378 Approved-By: Tom Tromey <tom@tromey.com>
2024-04-22gdb: move `enum compile_i_scope_types` to compile/compile.hSimon Marchi1-0/+1
Move it out of defs.h, adjust the includes here and there. Change-Id: I11901fdce55d54f5e51723e123cef154cfb1bbc5 Approved-By: John Baldwin <jhb@FreeBSD.org>
2024-03-26gdb, gdbserver, gdbsupport: remove includes of early headersSimon Marchi10-10/+0
Now that defs.h, server.h and common-defs.h are included via the `-include` option, it is no longer necessary for source files to include them. Remove all the inclusions of these files I could find. Update the generation scripts where relevant. Change-Id: Ia026cff269c1b7ae7386dd3619bc9bb6a5332837 Approved-By: Pedro Alves <pedro@palves.net>
2024-02-07Raise exception if ambiguous name is used in gdb.parameterHannes Domani2-3/+12
Currently gdb.parameter doesn't raise an exception if an ambiguous name is used, it instead returns the value of the last partly matching parameter: ``` (gdb) show print sym Ambiguous show print command "sym": symbol, symbol-filename, symbol-loading. (gdb) show print symbol-loading Printing of symbol loading messages is "full". (gdb) py print(gdb.parameter("print sym")) full ``` It's because lookup_cmd_composition_1 tries to detect ambigous names by checking the return value of find_cmd for CMD_LIST_AMBIGUOUS, which never happens, since only lookup_cmd_1 returns CMD_LIST_AMBIGUOUS. Instead the nfound argument contains the number of found matches. By using it instead, and by setting *CMD to the special value CMD_LIST_AMBIGUOUS in this case, gdbpy_parameter can now show the appropriate error message: ``` (gdb) py print(gdb.parameter("print sym")) Traceback (most recent call last): File "<string>", line 1, in <module> RuntimeError: Parameter `print sym' is ambiguous. Error while executing Python code. (gdb) py print(gdb.parameter("print symbol")) True (gdb) py print(gdb.parameter("print symbol-")) Traceback (most recent call last): File "<string>", line 1, in <module> RuntimeError: Parameter `print symbol-' is ambiguous. Error while executing Python code. (gdb) py print(gdb.parameter("print symbol-load")) full ``` Since the document command also uses lookup_cmd_composition, it needed to check for CMD_LIST_AMBIGUOUS as well, so it now also shows an "Ambiguous command" error message in this case. Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=14639 Approved-By: Tom Tromey <tom@tromey.com>
2024-01-23gdb: fix "list ." related crashGuinevere Larsen1-0/+2
When a user attempts to use the "list ." command with an inferior that doesn't have debug symbols, GDB would crash. This was reported as PR gdb/31256. The crash would happen when attempting to get the current symtab_and_line for the stop location, because the symtab would return a null pointer and we'd attempt to dereference it to print the line. This commit fixes that by checking for an empty symtab and erroring out of the function if it happens. Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=31256 Approved-By: Tom Tromey <tom@tromey.com>
2024-01-12Update copyright year range in header of all files managed by GDBAndrew Burgess18-18/+18
This commit is the result of the following actions: - Running gdb/copyright.py to update all of the copyright headers to include 2024, - Manually updating a few files the copyright.py script told me to update, these files had copyright headers embedded within the file, - Regenerating gdbsupport/Makefile.in to refresh it's copyright date, - Using grep to find other files that still mentioned 2023. If these files were updated last year from 2022 to 2023 then I've updated them this year to 2024. I'm sure I've probably missed some dates. Feel free to fix them up as you spot them.
2023-12-14gdb/options: fix copy&paste error in string_option_defAndrew Burgess1-1/+1
Spotted what appears to be a copy&paste error in string_option_def, the code for string handling writes the address fetching callback function into the option_def::var_address::enumeration location, rather than option_def::var_address::string. Of course, this works just fine as option_def::var_address is a union, and all of its members are function pointers, so they're going to be the same size on every target GDB cares about. But it doesn't hurt to be correct, so fixed in this commit. There should be no user visible changes after this commit.
2023-11-29Use C++17 [[fallthrough]] attributeTom Tromey1-1/+1
This changes gdb to use the C++17 [[fallthrough]] attribute rather than special comments. This was mostly done by script, but I neglected a few spellings and so also fixed it up by hand. I suspect this fixes the bug mentioned below, by switching to a standard approach that, presumably, clang supports. Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=23159 Approved-By: John Baldwin <jhb@FreeBSD.org> Approved-By: Luis Machado <luis.machado@arm.com> Approved-By: Pedro Alves <pedro@palves.net>
2023-11-21gdb: Use std::string_view instead of gdb::string_viewLancelot Six1-2/+2
Given that GDB now requires a C++17, replace all uses of gdb::string_view with std::string_view. This change has mostly been done automatically: - gdb::string_view -> std::string_view - #include "gdbsupport/gdb_string_view.h" -> #include <string_view> One things which got brought up during review is that gdb::stging_view does support being built from "nullptr" while std::sting_view does not. Two places are manually adjusted to account for this difference: gdb/tui/tui-io.c:tui_getc_1 and gdbsupport/format.h:format_piece::format_piece. The above automatic change transformed "gdb::to_string (const gdb::string_view &)" into "gdb::to_string (const std::string_view &)". The various direct users of this function are now explicitly including "gdbsupport/gdb_string_view.h". A later patch will remove the users of gdb::to_string. The implementation and tests of gdb::string_view are unchanged, they will be removed in a following patch. Change-Id: Ibb806a7e9c79eb16a55c87c6e41ad396fecf0207 Approved-By: Tom Tromey <tom@tromey.com> Approved-By: Pedro Alves <pedro@palves.net>
2023-11-21gdb: Replace gdb::optional with std::optionalLancelot Six6-16/+16
Since GDB now requires C++17, we don't need the internally maintained gdb::optional implementation. This patch does the following replacing: - gdb::optional -> std::optional - gdb::in_place -> std::in_place - #include "gdbsupport/gdb_optional.h" -> #include <optional> This change has mostly been done automatically. One exception is gdbsupport/thread-pool.* which did not use the gdb:: prefix as it already lives in the gdb namespace. Change-Id: I19a92fa03e89637bab136c72e34fd351524f65e9 Approved-By: Tom Tromey <tom@tromey.com> Approved-By: Pedro Alves <pedro@palves.net>
2023-11-08gdb: add a custom command completer for disassemble commandAndrew Burgess1-1/+15
Add a new command completer function for the disassemble command. There are two things that this completion function changes. First, after the previous commit, the new function calls skip_over_slash_fmt, which means that hitting tab after entering a /OPT flag now inserts a space ready to start typing the address to disassemble at: (gdb) disassemble /r<TAB> (gdb) disassemble /r <CURSOR> But also, we now get symbol completion after a /OPT option set, previously this would do nothing: (gdb) disassemble /r mai<TAB> But now: (gdb) disassemble /r mai<TAB> (gdb) disassemble /r main <CURSOR> Which was my main motivation for working on this commit. However, I have made a second change in the completion function. Currently, the disassemble command calls the generic location_completer function, however, the disassemble docs say: Note that the 'disassemble' command's address arguments are specified using expressions in your programming language (*note Expressions: Expressions.), not location specs (*note Location Specifications::). So, for example, if you want to disassemble function 'bar' in file 'foo.c', you must type 'disassemble 'foo.c'::bar' and not 'disassemble foo.c:bar'. And indeed, if I try: (gdb) disassemble hello.c:main No symbol "hello" in current context. (gdb) disassemble hello.c::main No symbol "hello" in current context. (gdb) disassemble 'hello.c'::main Dump of assembler code for function main: ... snip ... But, if I do this: (gdb) disassemble hell<TAB> (gdb) disassemble hello.c:<CURSOR> which is a consequence of using the location_completer function. So in this commit, after calling skip_over_slash_fmt, I forward the bulk of the disassemble command completion to expression_completer. Now when I try this: (gdb) disassemble hell<TAB> gives nothing, which I think is an improvement. There is one slight disappointment, if I do: (gdb) disassemble 'hell<TAB> I still get nothing. I had hoped that this would expand to: 'hello.c':: but I guess this is a limitation of the current expression_completer implementation, however, I don't think this is a regression, the previous expansion was just wrong. Fixing expression_completer is out of scope for this commit. I've added some disassembler command completion tests, and also a test that disassembling using 'FILE'::FUNC syntax works, as I don't think that is tested anywhere.
2023-11-08gdb: error if /r and /b are used with disassemble commandAndrew Burgess1-0/+4
The disassembler gained a new /b flag in this commit: commit d4ce49b7ac077a9882d6a5e689e260300045ca88 Date: Tue Jun 21 20:23:35 2022 +0100 gdb: disassembler opcode display formatting The /b and /r flags result in the instruction opcodes displayed in different formats, so it's not possible to have both at the same time. Currently the /b flag overrides the /r flag. We have a similar situation with the /m and /s flags, but here, if the user tries to use both flags then they will get an error. I think the error is clearer, so in this commit I propose that we add an error if /r and /b are both used. Obviously this change breaks backwards compatibility. I don't have a compelling argument for why we should make the change beyond my feeling that it was a mistake not to add this error from the start, and that the new behaviour is better. Reviewed-By: Eli Zaretskii <eliz@gnu.org>
2023-10-10gdb: remove target_gdbarchSimon Marchi1-2/+3
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>