aboutsummaryrefslogtreecommitdiff
path: root/gdb/cli
AgeCommit message (Collapse)AuthorFilesLines
2022-03-29Unify gdb puts functionsTom Tromey4-24/+24
Now that filtered and unfiltered output can be treated identically, we can unify the puts family of functions. This is done under the name "gdb_puts". Most of this patch was written by script.
2022-03-29Unify vprintf functionsTom Tromey2-2/+2
Now that filtered and unfiltered output can be treated identically, we can unify the vprintf family of functions: vprintf_filtered, vprintf_unfiltered, vfprintf_filtered and vfprintf_unfiltered. (For the gdb_stdout variants, recall that only printf_unfiltered gets truly unfiltered output at this point.) This removes one such function and renames the remaining two to "gdb_vprintf". All callers are updated. Much of this patch was written by script.
2022-03-29Change the pager to a ui_fileTom Tromey1-1/+1
This rewrites the output pager as a ui_file implementation. A new header is introduced to declare the pager class. The implementation remains in utils.c for the time being, because there are some static globals there that must be used by this code. (This could be cleaned up at some future date.) I went through all the text output in gdb to ensure that this change should be ok. There are a few cases: * Any existing call to printf_unfiltered is required to be avoid the pager. This is ensured directly in the implementation. * All remaining calls to the f*_unfiltered functions -- the ones that take an explicit ui_file -- either send to an unfiltered stream (e.g., gdb_stderr), which is obviously ok; or conditionally send to gdb_stdout I investigated all such calls by searching for: grep -e '\bf[a-z0-9_]*_unfiltered' *.[chyl] */*.[ch] | grep -v gdb_stdlog | grep -v gdb_stderr This yields a number of candidates to check. * The breakpoint _print_recreate family, and save_trace_state_variables. These are used for "save" commands and so are fine. * Things printing to a temporary stream. Obviously ok. * Disassembly selftests. * print_gdb_help - this is non-obvious, but ok because paging isn't yet enabled at this point during startup. * serial.c - doens't use gdb_stdout * The code in compile/. This is all printing to a file. * DWARF DIE dumping - doesn't reference gdb_stdout. * Calls to the _filtered form -- these are all clearly ok, because if they are using gdb_stdout, then filtering will still apply; and if not, then filtering never applied and still will not. Therefore, at this point, there is no longer any distinction between all the other _filtered and _unfiltered calls, and they can be unified. In this patch, take special note of the vfprintf_maybe_filtered and ui_file::vprintf change. This is one instance of the above idea, erasing the distinction between filtered and unfiltered -- in this part of the change, the "unfiltered_output" flag is never passe to cli_ui_out. Subsequent patches will go much further in this direction. Also note the can_emit_style_escape changes in ui-file.c. Checking against gdb_stdout or gdb_stderr was always a bit of a hack; and now it is no longer needed, because this is decision can be more fully delegated to the particular ui_file implementation. ui_file::can_page is removed, because this patch removed the only call to it. I think this is the main part of fixing PR cli/7234. Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=7234
2022-03-28Switch gdb_stdlog to use timestamped_fileTom Tromey1-1/+5
Currently, timestamps for logging are done by looking for the use of gdb_stdlog in vfprintf_unfiltered. This seems potentially buggy, in that during logging or other redirects (like execute_fn_to_ui_file) we might have gdb_stdout==gdb_stdlog and so, conceivably, wind up with timestamps in a log when they were not desired. It seems better, instead, for timestamps to be a property of the ui_file itself. This patch changes gdb to use the new timestamped_file for gdb_stdlog where appropriate, and removes the special case from vfprintf_unfiltered. Note that this may somewhat change the output in some cases -- in particular, when going through execute_fn_to_ui_file (or the _string variant), timestamps won't be emitted. This could be fixed in those functions, but it wasn't clear to me whether this is really desirable. Note also that this changes the TUI to send gdb_stdlog to gdb_stderr. I imagine that the previous use of gdb_stdout here was inadvertent. (And in any case it probably doesn't matter.)
2022-03-28Use unique_ptr in CLI logging codeTom Tromey1-26/+17
This changes the CLI logging code to avoid manual memory management (to the extent possible) by using unique_ptr in a couple of spots. This will come in handy in a later patch.
2022-03-28Simplify the CLI set_logging logicTom Tromey1-16/+4
The CLI's set_logging logic seemed unnecessarily complicated to me. This patch simplifies it, with an eye toward changing it to use RAII objects in a subsequent patch. I did not touch the corresponding MI code. That code seems incorrect (nothing ever uses raw_stdlog, and nothing ever sets saved_raw_stdlog). I didn't attempt to fix this, because I question whether this is even useful for MI.
2022-02-14gdb: use python to colorize disassembler outputAndrew Burgess2-0/+47
This commit adds styling support to the disassembler output, as such two new commands are added to GDB: set style disassembler enabled on|off show style disassembler enabled In this commit I make use of the Python Pygments package to provide the styling. I did investigate making use of libsource-highlight, however, I found the highlighting results to be inferior to those of Pygments; only some mnemonics were highlighted, and highlighting of register names such as r9d and r8d (on x86-64) was incorrect. To enable disassembler highlighting via Pygments, I've added a new extension language hook, which is then implemented for Python. This hook is very similar to the existing hook for source code colorization. One possibly odd choice I made with the new hook is to pass a gdb.Architecture through, even though this is currently unused. The reason this argument is not used is that, currently, styling is performed identically for all architectures. However, even though the Python function used to perform styling of disassembly output is not part of any documented API, I don't want to close the door on a user overriding this function to provide architecture specific styling. To do this, the user would inevitably require access to the gdb.Architecture, and so I decided to add this field now. The styling is applied within gdb_disassembler::print_insn, to achieve this, gdb_disassembler now writes its output into a temporary buffer, styling is then applied to the contents of this buffer. Finally the gdb_disassembler buffer is copied out to its final destination stream. There's a new test to check that the disassembler output includes some escape sequences, though I don't check for specific colours; the precise colors will depend on which instructions are in the disassembler output, and, I guess, how pygments is configured. The only negative change with this commit is how we currently style addresses in GDB. Currently, when the disassembler wants to print an address, we call back into GDB, and GDB prints the address value using the `address` styling, and the symbol name using `function` styling. After this commit, if pygments is used, then all disassembler styling is done through pygments, and this include the address and symbol name parts of the disassembler output. I don't know how much of an issue this will be for people. There's already some precedent for this in GDB when we look at source styling. For example, function names in styled source listings are not styled using the `function` style, but instead, either GNU Source Highlight, or pygments gets to decide how the function name should be styled. If the Python pygments library is not present then GDB will continue to behave as it always has, the disassembler output is mostly unstyled, but the address and symbols are styled using the `address` and `function` styles, as they are today. However, if the user does `set style disassembler enabled off`, then all disassembler styling is switched off. This obviously covers the use of pygments, but also includes the minimal styling done by GDB when pygments is not available.
2022-02-07gdb: make thread_info::m_thread_fsm a std::unique_ptrLancelot SIX1-3/+3
While working on function calls, I realized that the thread_fsm member of struct thread_info is a raw pointer to a resource it owns. This commit changes the type of the thread_fsm member to a std::unique_ptr in order to signify this ownership relationship and slightly ease resource management (no need to manually call delete). To ensure consistent use, the field is made a private member (m_thread_fsm). The setter method (set_thread_fsm) can then check that it is incorrect to associate a FSM to a thread_info object if another one is already in place. This is ensured by an assertion. The function run_inferior_call takes an argument as a pointer to a call_thread_fsm and installs it in it in a thread_info instance. Also change this function's signature to accept a unique_ptr in order to signify that the ownership of the call_thread_fsm is transferred during the call. No user visible change expected after this commit. Tested on x86_64-linux with no regression observed. Change-Id: Ia1224f72a4afa247801ce6650ce82f90224a9ae8
2022-02-07gdb: add the 'set/show suppress-cli-notifications' commandTankut Baris Aktemur1-0/+39
GDB already has a flag to suppress printing notification events, such as thread and inferior context switches, on the CLI. This is used internally when executing commands. Make the flag available to the user via a new command. This is expected to be useful in scripts. For instance, suppose that when Inferior 1 gets to a certain state, you want to add and set up a new inferior using the commands below, but you also want to have a reduced/clean output. define do-setup printf "Setting up Inferior 2...\n" add-inferior -exec a.out inferior 2 break file.c:3 run inferior 1 printf "Done\n" end Currently, GDB prints (gdb) do-setup Setting up Inferior 2... [New inferior 2] Added inferior 2 on connection 1 (native) [Switching to inferior 2 [<null>] (/tmp/a.out)] Breakpoint 2 at 0x1155: file file.c, line 3. Thread 2.1 "a.out" hit Breakpoint 2, main () at file.c:3 3 return 0; [Switching to inferior 1 [process 7670] (/tmp/test)] [Switching to thread 1.1 (process 7670)] #0 main () at test.c:2 2 int a = 1; Done GDB's Python API make it possible to capture and return GDB's output, but this does not work for all the streams. In particular, CLI notification events are not captured: (gdb) python gdb.execute("do-setup", False, True) [Switching to inferior 2 [<null>] (/tmp/a.out)] Thread 2.1 "a.out" hit Breakpoint 2, main () at file.c:3 3 return 0; [Switching to inferior 1 [process 8263] (/tmp/test)] [Switching to thread 1.1 (process 8263)] #0 main () at test.c:2 2 int a = 1; You can use the new "set suppress-cli-notifications" command to suppress the output: (gdb) set suppress-cli-notifications on (gdb) do-setup Setting up Inferior 2... [New inferior 2] Added inferior 2 on connection 1 (native) Breakpoint 2 at 0x1155: file file.c, line 3. Done
2022-02-07gdb/cli: add a 'normal_stop' option to 'cli_suppress_notification'Tankut Baris Aktemur1-0/+4
Extend the 'cli_suppress_notification' struct with a new field, 'normal_stop', that can be used for checking if printing normal stop events on the CLI should be suppressed. This patch only introduces the flag. The subsequent patch adds a user command to turn the flag off/on.
2022-02-07gdb/cli: convert cli_suppress_notification from int to boolTankut Baris Aktemur3-10/+7
Convert the suppress_notification flag for the CLI from int to bool.
2022-02-06gdb: remove SYMTAB_DIRNAME macroSimon Marchi1-2/+2
Remove the macro, replace with an equivalent method. Change-Id: I46ec36b91bb734331138eb9cd086b2db01635aed
2022-02-06gdb: remove SYMTAB_OBJFILE macroSimon Marchi1-2/+2
Remove the macro, replace with an equivalent method. Change-Id: I8f9ecd290ad28502e53c1ceca5006ba78bf042eb
2022-02-02gdb: handle calls to edit command passing only a linespec conditionAndrew Burgess1-3/+4
While working on the previous commit to fix PR cli/28665, I noticed that the 'edit' command would suffer from the same problem. That is, something like: (gdb) edit task 123 would cause GDB to break. For a full explanation of what's going on here, see the commit message for the previous commit. As with the previous commit, this issue can be prevented by detecting, and throwing, a junk at the end of the line error earlier, before calling decode_line_1. So, that's what this commit does. I've also added some tests for this issue. Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=28665
2022-02-02gdb: handle calls to list command passing only a linespec conditionAndrew Burgess1-0/+12
In PR cli/28665, it was reported that GDB would crash when given a command like: (gdb) list task 123 The problem here is that in cli/cli-cmd.c:list_command, the string 'task 123' is passed to string_to_event_location in find a location specification. However, this location parsing understands about breakpoint conditions, and so, will stop parsing when it sees something that looks like a condition, in this case, the 'task 123' looks like a breakpoint condition. As a result, the location we get back from string_to_event_location has no actual location specification attached to it. The actual call path is: list_command string_to_event_location string_to_event_location_basic new_linespec_location In new_linespec_location we call linespec_lex_to_end, which looks at 'task 123' and decides that there's nothing there that describes a location. As such, in new_linespec_location, the spec_string field of the location is left as nullptr. Back in list_command we then call decode_line_1, which calls event_location_to_sals, which calls parse_linespec, which takes the spec_string we found earlier, and tries to converts this into a list of sals. However, parse_linespec is not intended to be passed a nullptr, for example, calling is_ada_operator will try to access through the nullptr, causing undefined behaviour. But there are other cases within parse_linespec which don't expect to see a nullptr. When looking at how to fix this issue, I first considered having linespec_lex_to_end detect the problem. That function understands when the first thing in the linespec is a condition keyword, and so, could throw an error saying something like: "no linespec before condition keyword", however, this is not going to work, at least, not without additional changes to GDB, it is valid to place a breakpoint like: (gdb) break task 123 This will place a breakpoint at the current location with the condition 'task 123', and changing linespec_lex_to_end breaks this behaviour. So, next, I considered what would happen if I added a condition to an otherwise valid list command, this is what I see: (gdb) list file.c:1 task 123 Junk at end of line specification. (gdb) So, then I wondered, could we just pull the "Junk" detection forward, so that we throw the error earlier, before we call decode_line_1? It turns out that yes we can. Well, sort of. It is simpler, I think, to add a separate check into the list_command function, after calling string_to_event_location, but before calling decode_line_1. We know when we call string_to_event_location that the string in question is not empty, so, after calling string_to_event_location, if non of the string has been consumed, then the content of the string must be junk - it clearly doesn't look like a location specification. I've reused the same "Junk at end of line specification." error for consistency, and added a few tests to cover this issue. While the first version of this patch was on the mailing list, a second bug PR gdb/28797 was raised. This was for a very similar issue, but this time the problem command was: (gdb) list ,, Here the list command understands about the first comma, list can have two arguments separated by a comma, and the first argument can be missing. So we end up trying to parse the second command "," as a linespec. However, in linespec_lex_to_end, we will stop parsing a linespec at a comma, so, in the above case we end up with an empty linespec (between the two commas), and, like above, this results in the spec_string being nullptr. As with the previous case, I've resolved this issue by adding an extra check for junk at the end of the line - after parsing (or failing to parse) the nothing between the two commas, we still have the "," left at the end of the list command line - when we see this we can throw the same "junk at the end of the line" error, and all is good. I've added tests for this case too. Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=28665 Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=28797
2022-01-26Always call the wrap_here methodTom Tromey2-7/+7
This changes all existing calls to wrap_here to call the method on the appropriate ui_file instead. The choice of ui_file is determined by context.
2022-01-26Convert wrap_here to use integer parameterTom Tromey2-7/+7
I think it only really makes sense to call wrap_here with an argument consisting solely of spaces. Given this, it seemed better to me that the argument be an int, rather than a string. This patch is the result. Much of it was written by a script.
2022-01-26gdb/python: improve the auto help text for gdb.ParameterAndrew Burgess2-0/+20
This commit attempts to improve the help text that is generated for gdb.Parameter objects when the user fails to provide their own documentation. Documentation for a gdb.Parameter is currently pulled from two sources: the class documentation string, and the set_doc/show_doc class attributes. Thus, a fully documented parameter might look like this: class Param_All (gdb.Parameter): """This is the class documentation string.""" show_doc = "Show the state of this parameter" set_doc = "Set the state of this parameter" def get_set_string (self): val = "on" if (self.value == False): val = "off" return "Test Parameter has been set to " + val def __init__ (self, name): super (Param_All, self).__init__ (name, gdb.COMMAND_DATA, gdb.PARAM_BOOLEAN) self._value = True Param_All ('param-all') Then in GDB we see this: (gdb) help set param-all Set the state of this parameter This is the class documentation string. Which is fine. But, if the user skips both of the documentation parts like this: class Param_None (gdb.Parameter): def get_set_string (self): val = "on" if (self.value == False): val = "off" return "Test Parameter has been set to " + val def __init__ (self, name): super (Param_None, self).__init__ (name, gdb.COMMAND_DATA, gdb.PARAM_BOOLEAN) self._value = True Param_None ('param-none') Now in GDB we see this: (gdb) help set param-none This command is not documented. This command is not documented. That's not great, the duplicated text looks a bit weird. If we drop different parts we get different results. Here's what we get if the user drops the set_doc and show_doc attributes: (gdb) help set param-doc This command is not documented. This is the class documentation string. That kind of sucks, we say it's undocumented, then proceed to print the documentation. Finally, if we drop the class documentation but keep the set_doc and show_doc: (gdb) help set param-set-show Set the state of this parameter This command is not documented. That seems OK. So, I think there's room for improvement. With this patch, for the four cases above we now see this: # All values provided by the user, no change in this case: (gdb) help set param-all Set the state of this parameter This is the class documentation string. # Nothing provided by the user, the first string is now different: (gdb) help set param-none Set the current value of 'param-none'. This command is not documented. # Only the class documentation is provided, the first string is # changed as in the previous case: (gdb) help set param-doc Set the current value of 'param-doc'. This is the class documentation string. # Only the set_doc and show_doc are provided, this case is unchanged # from before the patch: (gdb) help set param-set-show Set the state of this parameter This command is not documented. The one place where this change might be considered a negative is when dealing with prefix commands. If we create a prefix command but don't supply the set_doc / show_doc strings, then this is what we saw before my patch: (gdb) python Param_None ('print param-none') (gdb) help set print set print, set pr, set p Generic command for setting how things print. List of set print subcommands: ... snip ... set print param-none -- This command is not documented. ... snip ... And after my patch: (gdb) python Param_None ('print param-none') (gdb) help set print set print, set pr, set p Generic command for setting how things print. List of set print subcommands: ... snip ... set print param-none -- Set the current value of 'print param-none'. ... snip ... This seems slightly less helpful than before, but I don't think its terrible. Additionally, I've changed what we print when the get_show_string method is not provided in Python. Back when gdb.Parameter was first added to GDB, we didn't provide a show function when registering the internal command object within GDB. As a result, GDB would make use of its "magic" mangling of the show_doc string to create a sentence that would display the current value (see deprecated_show_value_hack in cli/cli-setshow.c). However, when we added support for the get_show_string method to gdb.Parameter, there was an attempt to maintain backward compatibility by displaying the show_doc string with the current value appended, see get_show_value in py-param.c. Unfortunately, this isn't anywhere close to what deprecated_show_value_hack does, and the results are pretty poor, for example, this is GDB before my patch: (gdb) show param-none This command is not documented. off I think we can all agree that this is pretty bad. After my patch, we how show this: (gdb) show param-none The current value of 'param-none' is "off". Which at least is a real sentence, even if it's not very informative. This patch does change the way that the Python API behaves slightly, but only in the cases when the user has missed providing GDB with some information. In most cases I think the new behaviour is a lot better, there's the one case (noted above) which is a bit iffy, but I think is still OK. I've updated the existing gdb.python/py-parameter.exp test to cover the modified behaviour. Finally, I've updated the documentation to (I hope) make it clearer how the various bits of help text come together.
2022-01-26gdb: add string_file::release methodSimon Marchi1-1/+1
A common pattern for string_file is to want to move out the internal string buffer, because it is the result of the computation that we want to return. It is the reason why string_file::string returns a non-const reference, as explained in the comment. I think it would make sense to have a dedicated method for that instead and make string_file::string return a const reference. This allows removing the explicit std::move in the typical case. Note that compile_program::compute was missing a move, meaning that the resulting string was copied. With the new version, it's not possible to forget to move. Change-Id: Ieaefa35b73daa7930b2f3a26988b6e3b4121bb79
2022-01-26Fix another crash with gdb parameters in PythonTom Tromey1-0/+10
While looking into the language-capturing issue, I found another way to crash gdb using parameters from Python: (gdb) python print(gdb.parameter('endian')) (This is related to PR python/12188, though this patch isn't going to fix what that bug is really about.) The problem here is that the global variable that underlies the "endian" parameter is initialized to NULL. However, that's not a valid value for an "enum" set/show parameter. My understanding is that, in gdb, an "enum" parameter's underlying variable must have a value that is "==" (not just strcmp-equal) to one of the values coming from the enum array. This invariant is relied on in various places. I started this patch by fixing the problem with "endian". Then I added some assertions to add_setshow_enum_cmd to try to catch other problems of the same type. This patch fixes all the problems that I found. I also looked at all the calls to add_setshow_enum_cmd to ensure that they were all included in the gdb I tested. I think they are: there are no calls in nat-* files, or in remote-sim.c; and I was trying a build with all targets, Python, and Guile enabled. Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=12188
2022-01-18Move gdb_regex to gdbsupportTom Tromey3-3/+3
This moves the gdb_regex convenience class to gdbsupport.
2022-01-18Move gdb_argv to gdbsupportTom Tromey1-0/+1
This moves the gdb_argv class to a new header in gdbsupport.
2022-01-05Use filtered output in ordinary commandsTom Tromey2-19/+19
Many otherwise ordinary commands choose to use unfiltered output rather than filtered. I don't think there's any reason for this, so this changes many such commands to use filtered output instead. Note that complete_command is not touched due to a comment there explaining why unfiltered output is believed to be used.
2022-01-05Simplify execute_control_commands_to_stringTom Tromey1-23/+7
execute_control_commands_to_string can be rewritten in terms of execute_fn_to_string, which consolidates some knowledge about which streams to redirect. Regression tested on x86-64 Fedora 34.
2022-01-04[gdb/build] Fix build breaker in gdb/cli/cli-logging.cTom de Vries1-2/+2
Fix build breaker in gdb/cli/cli-logging.c: ... gdb/cli/cli-logging.c: In function \ ‘void show_logging_enabled(ui_file*, int, cmd_list_element*, const char*)’: gdb/gdbsupport/gdb_locale.h:28:28: error: cannot convert ‘char*’ to ‘ui_file*’ 28 | # define _(String) gettext (String) | ~~~~~~~~^~~~~~~~ | | | char* gdb/cli/cli-logging.c:202:25: note: in expansion of macro ‘_’ 202 | fprintf_unfiltered (_("on: Logging is enabled.\n")); | ^ ... Build and tested on x86_64-linux. Fixes: 45aec4e5ed8 ("[gdb/cli] Improve show logging output")
2022-01-03[gdb/cli] Improve show logging outputTom de Vries1-8/+26
Before commit 3b6acaee895 "Update more calls to add_prefix_cmd" we had the following output for "show logging": ... $ gdb -q -batch -ex "set trace-commands on" \ -ex "set logging off" \ -ex "show logging" \ -ex "set logging on" \ -ex "show logging" +set logging off +show logging Future logs will be written to gdb.txt. Logs will be appended to the log file. Output will be logged and displayed. Debug output will be logged and displayed. +set logging on +show logging Currently logging to "gdb.txt". Logs will be appended to the log file. Output will be logged and displayed. Debug output will be logged and displayed. ... After that commit we have instead: ... +set logging off +show logging debugredirect: The logging output mode is off. file: The current logfile is "gdb.txt". overwrite: Whether logging overwrites or appends to the log file is off. redirect: The logging output mode is off. +set logging on +show logging debugredirect: The logging output mode is off. file: The current logfile is "gdb.txt". overwrite: Whether logging overwrites or appends to the log file is off. redirect: The logging output mode is off. ... which gives less clear output for some subcommands. OTOH, it's explicit about whether boolean values are on or off. The new text seems to have been chosen to match the set/show help texts: ... (gdb) help show logging Show logging options. List of show logging subcommands: show logging debugredirect -- Show the logging debug output mode. show logging file -- Show the current logfile. show logging overwrite -- \ Show whether logging overwrites or appends to the log file. show logging redirect -- Show the logging output mode. ... Make the show logging messages more clear, while still keep the boolean values explicit, such that we have: ... $ ./gdb.sh -q -batch -ex "show logging" logging debugredirect: off: \ Debug output will go to both the screen and the log file. logging enabled: off: Logging is disabled. logging file: The current logfile is "gdb.txt". logging overwrite: off: Logging appends to the log file. logging redirect: off: Output will go to both the screen and the log file. ... Tested on x86_64-linux.
2022-01-01Automatic Copyright Year update after running gdb/copyright.pyJoel Brobecker18-18/+18
This commit brings all the changes made by running gdb/copyright.py as per GDB's Start of New Year Procedure. For the avoidance of doubt, all changes in this commits were performed by the script.
2021-12-29Use filtered output in show callbacksTom Tromey1-2/+2
"show" command callbacks, like most ordinary gdb commands, should use filtered output. I found a few that did not, so this patch changes them to use the filtered form.
2021-12-29Consistently Use ui_file parameter to show callbacksTom Tromey1-2/+2
I happened to notice that one "show" callback was printing to gdb_stdout rather than to the passed-in ui_file parameter. I went through all such callbacks and fixed them to consistently use the ui_file. Regression tested on x86-64 Fedora 34.
2021-12-18gdb: add "exit" command as an alias for "quit"Enze Li1-1/+2
This command adds the "exit" command as an alias for the "quit" command, as requested in PR gdb/28406. The documentation is also updated to mention this new command. Tested on x86_64-linux. Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=28406
2021-12-04gdb: don't show deprecated aliasesSimon Marchi1-3/+26
I don't think it's very useful to show deprecated aliases to the user. It encourages the user to use them, when the goal is the opposite. For example, before: (gdb) help set index-cache enabled set index-cache enabled, set index-cache off, set index-cache on alias set index-cache off = set index-cache enabled off alias set index-cache on = set index-cache enabled on Enable the index cache. When on, enable the use of the index cache. (gdb) help set index-cache on Warning: 'set index-cache on', an alias for the command 'set index-cache enabled', is deprecated. Use 'set index-cache enabled on'. set index-cache enabled, set index-cache off, set index-cache on alias set index-cache off = set index-cache enabled off alias set index-cache on = set index-cache enabled on Enable the index cache. When on, enable the use of the index cache. After: (gdb) help set index-cache enabled Enable the index cache. When on, enable the use of the index cache. (gdb) help set index-cache on Warning: 'set index-cache on', an alias for the command 'set index-cache enabled', is deprecated. Use 'set index-cache enabled on'. Enable the index cache. When on, enable the use of the index cache. Change-Id: I989b618a5ad96ba975367e9d16db95523cd57a4c
2021-12-03gdb: change some alias functions parameters to const-referenceSimon Marchi1-32/+32
Now that we use intrusive list to link aliases, it becomes easier to pass cmd_list_element arguments by const-reference rather than by pointer to some functions, change a few. Change-Id: Id0df648ed26e9447da0671fc2c858981cda31df8
2021-12-03gdb: use intrusive_list for cmd_list_element aliases listSimon Marchi2-50/+50
Change the manually-implemented linked list to use intrusive_list. This is not strictly necessary, but it makes the code much simpler. Change-Id: Idd08090ebf2db8bdcf68e85ef72a9635f1584ccc
2021-12-03gdb: make saved_filename an std::stringSimon Marchi1-10/+10
Make this variable an std::string, avoiding manual memory management. Change-Id: Ie7a8d7381449ab9c4dfc4cb8b99e63b9ffa8f947
2021-11-25gdb: rename source_styling_changed observerAndrew Burgess1-1/+1
In a later commit I plan to add disassembler styling. In the same way that we have a source_styling_changed observer I would need to add a disassembler_styling_changed observer. However, currently, these observers would only be notified from cli-style.c:set_style_enabled, and observed in tui-winsource.c, tui_source_window::style_changed, as a result, having two observers seems unnecessary right now, so, in this commit, I plan to rename source_styling_changed to just styling_changed, then, in the later commit, when disassembler styling is added, I can use the same observer for both source styling, and disassembler styling. There should be no user visible changes after this commit.
2021-11-25[gdb/cli] Add "set logging enabled", deprecate "set logging on/off"Tom de Vries1-4/+54
Before commit 3b6acaee895 "Update more calls to add_prefix_cmd" we had the following output for "show logging file": ... $ gdb -q -batch -ex "set trace-commands on" \ -ex "set logging off" \ -ex "show logging file" \ -ex "set logging on" \ -ex "show logging file" +set logging off +show logging file Future logs will be written to gdb.txt. +set logging on +show logging file Currently logging to "gdb.txt". ... After that commit we have instead: ... +set logging off +show logging file The current logfile is "gdb.txt". +set logging on +show logging file The current logfile is "gdb.txt". ... Before the commit, whether logging is enabled or not can be deduced from the output of the command. After the commit, the message is unified and it's no longer clear whether logging is enabled or not. Fix this by: - adding a new command "show logging enabled" - adding a corresponding new command "set logging enabled on/off" - making the commands "set logging on/off" deprecated aliases of the "set logging enabled on/off" command. Update the docs and testsuite to use "set logging enabled". Mention the new and deprecated commands in NEWS. Tested on x86_64-linux.
2021-11-25[gdb/cli] Fix typo in logging overwrite help textTom de Vries1-1/+1
Currently we have: ... $ gdb -q -batch -ex "help set logging overwrite" Set whether logging overwrites or appends to the log file. If set, logging overrides the log file. ... Fix overrides -> overwrites typo.
2021-11-18gdbsupport: make gdb_assert_not_reached accept a format stringSimon Marchi1-2/+2
Change gdb_assert_not_reached to accept a format string plus corresponding arguments. This allows giving more precise messages. Because the format string passed by the caller is prepended with a "%s:" to add the function name, the callers can no longer pass a translated string (`_(...)`). Make the gdb_assert_not_reached include the _(), just like the gdb_assert_fail macro just above. Change-Id: Id0cfda5a57979df6cdaacaba0d55dd91ae9efee7
2021-11-16gdb/gdbsupport: make xstrprintf and xstrvprintf return a unique_ptrAndrew Burgess3-12/+11
The motivation is to reduce the number of places where unmanaged pointers are returned from allocation type routines. All of the callers are updated. There should be no user visible changes after this commit.
2021-11-14[PR gdb/16238] Add completer for the show user commandLancelot SIX1-1/+71
The 'show user' command (which shows the definition of non-python/scheme user defined commands) is currently missing a completer. This is mentioned in PR 16238. Having one can improve the user experience. In this commit I propose an implementation for such completer as well as the associated tests. Tested on x86_64 GNU/Linux. All feedbacks are welcome. Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=16238
2021-11-08gdb: remove bpstat typedef, rename bpstats to bpstatSimon Marchi1-1/+1
I don't find that the bpstat typedef, which hides a pointer, is particularly useful. In fact, it confused me many times, and I just see it as something to remember that adds cognitive load. Also, with C++, we might want to be able to pass bpstats objects by const-reference, not necessarily by pointer. So, remove the bpstat typedef and rename struct bpstats to bpstat (since it represents one bpstat, it makes sense that it is singular). Change-Id: I52e763b6e54ee666a9e045785f686d37b4f5f849
2021-11-05Introduce make_unique_xstrndupTom Tromey1-4/+3
This adds a new make_unique_xstrndup function, which is the "n" analogue of make_unique_xstrdup. It also updates a couple existing places to use this function.
2021-11-04gdb: pass/return setting setter/getter scalar values by valueSimon Marchi1-26/+26
The getter and setter in struct setting always receive and return values by const reference. This is not necessary for scalar values (like bool and int), but more importantly it makes it a bit annoying to write a getter, you have to use a scratch static variable or something similar that you can refer to: const bool & my_getter () { static bool value; value = function_returning_bool (); return value; } Change the getter and setter function signatures to receive and return value by value instead of by reference, when the underlying data type is scalar. This means that string-based settings will still use references, but all others will be by value. The getter above would then be re-written as: bool my_getter () { return function_returning_bool (); } This is useful for a patch later in this series that defines a boolean setting with a getter and a setter. Change-Id: Ieca3a2419fcdb75a6f75948b2c920b548a0af0fd
2021-11-04gdb: remove command_class enum class_deprecatedSimon Marchi1-5/+1
The class_deprecated enumerator isn't assigned anywhere, so remove it. Commands that are deprecated have cmd_list_element::cmd_deprecated set instead. Change-Id: Ib35e540915c52aa65f13bfe9b8e4e22e6007903c
2021-11-04gdb: remove unnecessary cmd_list_element::aliases nullptr checksSimon Marchi1-17/+11
Remove two unnecessary nullptr checks. If aliases is nullptr, then the for loops will simply be skipped. Change-Id: I9132063bb17798391f8d019af305383fa8e0229f
2021-10-28gdb: add add_setshow_prefix_cmdSimon Marchi4-27/+46
There's a common pattern to call add_basic_prefix_cmd and add_show_prefix_cmd to add matching set and show commands. Add the add_setshow_prefix_cmd function to factor that out and use it at a few places. Change-Id: I6e9e90a30e9efb7b255bf839cac27b85d7069cfd
2021-10-25gdb: change functions returning value contents to use gdb::array_viewSimon Marchi2-3/+3
The bug fixed by this [1] patch was caused by an out-of-bounds access to a value's content. The code gets the value's content (just a pointer) and then indexes it with a non-sensical index. This made me think of changing functions that return value contents to return array_views instead of a plain pointer. This has the advantage that when GDB is built with _GLIBCXX_DEBUG, accesses to the array_view are checked, making bugs more apparent / easier to find. This patch changes the return types of these functions, and updates callers to call .data() on the result, meaning it's not changing anything in practice. Additional work will be needed (which can be done little by little) to make callers propagate the use of array_view and reap the benefits. [1] https://sourceware.org/pipermail/gdb-patches/2021-September/182306.html Change-Id: I5151f888f169e1c36abe2cbc57620110673816f3
2021-10-03gdb: Setting setter return a bool to tell if the value changedLancelot SIX1-70/+13
GDB can notify observers when a parameter is changed. To do that, do_set_command (in gdb/cli/cli-setshow.c) compares the new value against the old one before updating it, and based on that notifies observers. This looks like something like: int valuechanged = 0; switch (cmd->var.type ()) { case var_integer: { LONGEST new_val = parse_and_eval_long (arg) if (new_val != cmd->var.get<int> ()) { cmd->var.get<int> (new_val); value_changes = 1; } } case var_uinteger: case var_zuinteger: { unsigned int val = parse_cli_var_uinteger (c->var->type (), &arg, true); if (c->var->get<unsigned int> () != val) { c->var->set<unsigned int> (val); option_changed = true; } } case... /* And so on for all possible var_types. */ } This comparison is done for each possible var_type, which leads to unnecessary logic duplication. In this patch I propose to move all those checks in one place within the setting setter method. This limits the code duplication and simplifies the do_set_command implementation. This patch also changes slightly the way a value change is detected. Instead of comparing the user provided value against the current value of the setting, we compare the value of the setting before and after the set operation. This is meant to handle edge cases where trying to set an unrecognized value would be equivalent to a noop (the actual value remains unchanged). Doing this requires that the original value needs to be copied before the update, which can be non trivial for std::string. There should be no user visible change introduced by this commit. Tested on x86_64 GNU/Linux. [1] https://review.lttng.org/c/binutils-gdb/+/5831/41 Change-Id: If064b9cede3eb56275aacd2b286f74eceb1aed11
2021-10-03gdb: Have setter and getter callbacks for settingsLancelot SIX1-31/+323
The main motivation behind this improvement is to help the implementation of a patch Simon Marchi is preparing to fix a bug when MI or Python try to access parameters that are inferior dependent (see PR/28085). This commit extends the previous ones, which introduces the setting object to represent a static variable whose value can be set or shown with the appropriate commands. This patch proposes that a setting can either contain a pointer to a static variable holding a setting, or pointers to a pair of setter and getter callback functions. The callbacks functions can be used to retrieve or change the value with custom logic. This is useful when the source of truth for a given setting is not contained in the variable pointed to by the setting instance. Given that the callback function call is hidden within the setting abstraction introduced earlier, none of the sites accessing the setting needs to be updated. The registered getter or setter is used whatever the way to access it is (through MI, Python, Guile, the "with" command and the $_gdb_setting / $_gdb_setting_str convenience functions). All the add_setshow_*_cmd are given a new overload that will accept the pair of function pointers (set / get functions) instead of the pointer to a global variable. Tested on GNU/Linux x86_64 with no regression observed. Change-Id: Ieb81fef57550632ff66e6aa85f637372a226be8c Co-authored-by: Simon Marchi <simon.marchi@polymtl.ca>
2021-10-03gdb: make string-like set show commands use std::string variableSimon Marchi6-94/+88
String-like settings (var_string, var_filename, var_optional_filename, var_string_noescape) currently take a pointer to a `char *` storage variable (typically global) that holds the setting's value. I'd like to "mordernize" this by changing them to use an std::string for storage. An obvious reason is that string operations on std::string are often easier to write than with C strings. And they avoid having to do any manual memory management. Another interesting reason is that, with `char *`, nullptr and an empty string often both have the same meaning of "no value". String settings are initially nullptr (unless initialized otherwise). But when doing "set foo" (where `foo` is a string setting), the setting now points to an empty string. For example, solib_search_path is nullptr at startup, but points to an empty string after doing "set solib-search-path". This leads to some code that needs to check for both to check for "no value". Or some code that converts back and forth between NULL and "" when getting or setting the value. I find this very error-prone, because it is very easy to forget one or the other. With std::string, we at least know that the variable is not "NULL". There is only one way of representing an empty string setting, that is with an empty string. I was wondering whether the distinction between NULL and "" would be important for some setting, but it doesn't seem so. If that ever happens, it would be more C++-y and self-descriptive to use optional<string> anyway. Actually, there's one spot where this distinction mattered, it's in init_history, for the test gdb.base/gdbinit-history.exp. init_history sets the history filename to the default ".gdb_history" if it sees that the setting was never set - if history_filename is nullptr. If history_filename is an empty string, it means the setting was explicitly cleared, so it leaves it as-is. With the change to std::string, this distinction doesn't exist anymore. This can be fixed by moving the code that chooses a good default value for history_filename to _initialize_top. This is ran before -ex commands are processed, so an -ex command can then clear that value if needed (what gdb.base/gdbinit-history.exp tests). Another small improvement, in my opinion is that we can now easily give string parameters initial values, by simply initializing the global variables, instead of xstrdup-ing it in the _initialize function. In Python and Guile, when registering a string-like parameter, we allocate (with new) an std::string that is owned by the param_smob (in Guile) and the parmpy_object (in Python) objects. This patch started by changing all relevant add_setshow_* commands to take an `std::string *` instead of a `char **` and fixing everything that failed to build. That includes of course all string setting variable and their uses. string_option_def now uses an std::string also, because there's a connection between options and settings (see add_setshow_cmds_for_options). The add_path function in source.c is really complex and twisted, I'd rather not try to change it to work on an std::string right now. Instead, I added an overload that copies the std:string to a `char *` and back. This means more copying, but this is not used in a hot path at all, so I think it is acceptable. Change-Id: I92c50a1bdd8307141cdbacb388248e4e4fc08c93 Co-authored-by: Lancelot SIX <lsix@lancelotsix.com>