aboutsummaryrefslogtreecommitdiff
path: root/gdb/top.c
AgeCommit message (Collapse)AuthorFilesLines
2024-04-25gdb: remove gdbcmd.hSimon Marchi1-1/+0
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 execute function declarations from gdbcmd.h to top.hSimon Marchi1-6/+7
These functions are implemented in top.c, move their declarations to top.h. Change-Id: I8893ef91d955156a6530734fefe8002d78c3e5fc Approved-By: Tom Tromey <tom@tromey.com>
2024-04-16Remove excess whitespace from doc strings of some commandsEli Zaretskii1-1/+1
I've noticed that doc strings of some commands, like "set cwd" and "set inferior-tty", have some excess whitespace, which makes them display with unexpected indentation, at least in a Windows command prompt window. This patch fixes that. * gdb/linux-nat.c (_initialize_linux_nat): * gdb/riscv-tdep.c (riscv_insn): * gdb/top.c (quit_force): * gdb/infcmd.c (_initialize_infcmd): Remove excess whitespace.
2024-03-26gdb, gdbserver, gdbsupport: remove includes of early headersSimon Marchi1-1/+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-03-25gdb: move more completion setup into completer.cAndrew Burgess1-3/+0
Move more setup of the readline global state relating to tab completion into completer.c out of top.c. Lots of the readline setup is done in init_main (top.c). This commit moves those bits of initialisation that relate to completion, and which are only set the one time, into completer.c. This does mean that readline initialisation is now done in multiple locations, some in init_main (top.c) and some in completer.c, but I think this is OK. The work done in init_main is the general readline setup. I think making static what can be made static, and having it all in one file, makes things easier to reason about. So I'm OK with having this split initialisation. The only completion related thing which is still setup in top.c is rl_completion_display_matches_hook. I've left this where it is for now as rl_completion_display_matches_hook is also updated in the tui code, and the display hook functions are not in completer.c anyway, so moving this initialisation to completer.c would not allow anything else to be made static. There should be no user visible changes after this commit.
2024-03-25gdb: fix bug where quote characters would become nullptrAndrew Burgess1-1/+0
In gdb_completion_word_break_characters_throw, after calling complete_line_internal, if the completion function chose to use a custom word point then we set rl_completer_quote_characters to NULL. However, nowhere do we set rl_completer_quote_characters back to its default value, which is setup in init_main (top.c). An example of something that uses a custom word point for its completion is 'thread apply all ...'. An example of something that relies on rl_completer_quote_characters would be completion of a quoted filename that contains white space. Consider this shell and GDB session. The <TAB> markers indicate where I've used tab to trigger completion: $ mkdir /tmp/aaa\ bbb $ touch /tmp/aaa\ bbb/xx\ 11 $ touch /tmp/aaa\ bbb/xx\ 22 $ gdb -q (gdb) file '/tmp/aaa bbb/xx<TAB><TAB> xx 11 xx 22 (gdb) thread apply all hel<TAB> (gdb) thread apply all help (gdb) file '/tmp/aaa bbb/xx<TAB><TAB> First I create a directory structure which uses white space within file and directory names. Then within GDB I use the 'file' command and use a single quote to quote the filename. When I tab complete GDB correctly offers the two files within the directory '/tmp/aaa bbb/'. This works because rl_completer_quote_characters contains the single quote, and so readline knows that it is trying to complete the string that starts after the single quote: /tmp/aaa bbb/xx Next I invoke the completer for the 'thread apply all' command, to do this I type 'thread apply all hel' and hit tab, this expands to the one completion 'thread apply all help'. We can run this command or not, it doesn't matter (there are no threads, so we'll get no output). Now I repeat the original 'file' completion. This time though I don't get offered any completions. The reason is that the 'thread apply all' completer set rl_completer_quote_characters to nullptr. Now, when readline tries to figure out the word to complete it doesn't see the single quote as the start of a quoted word, so instead readline falls back to the word break characters, and in this case spots the white space. As a result readline tries to complete the string 'bbb/xx' which obviously doesn't have any completions. By setting rl_completer_quote_characters each time completion is invoked this problem is resolved and the second 'file' command completes as expected. I've extended gdb.base/filename-completion.exp to also test with quoted filenames, and added a 'thread apply all' completion at the start to expose this bug. As setting of rl_completer_quote_characters is now all done in the completer.c file the function get_gdb_completer_quote_characters() could be made static. However, as this function is only used one time to initialise rl_completer_quote_characters, I've instead just deleted get_gdb_completer_quote_characters() and used gdb_completer_quote_characters directly.
2024-02-27Change finalize_values into a final cleanupTom Tromey1-6/+0
This removes finalize_values in favor of adding a new final cleanup. This is safe now that extension languages are explicitly shut down.
2024-02-27Add extension_language_ops::shutdownTom Tromey1-0/+2
Right now, Python is shut down via a final cleanup. However, it seems to me that it is better for extension languages to be shut down explicitly, after all the ordinary final cleanups are run. The main reason for this is that a subsequent patch adds another case like finalize_values; and rather than add a series of workarounds for Python shutdown, it seemed better to let these be done via final cleanups, and then have Python shutdown itself be the special case.
2024-01-31Fix AIX build break.Aditya Vidyadhar Kamath1-4/+0
A recent commit broke AIX build. The thread_local type defined functions were being considered a weak symbol and hence while creating the binary these symbols were not visible. This patch is a fix for the same.
2024-01-12Update copyright year range in header of all files managed by GDBAndrew Burgess1-2/+2
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.
2024-01-08Refactor complaint thread-safety approachTom Tromey1-1/+1
This patch changes the way complaint works in a background thread. The new approach requires installing a complaint interceptor in each worker, and then the resulting complaints are treated as one of the results of the computation. This change is needed for a subsequent patch, where installing a complaint interceptor around a parallel-for is no longer a viable approach.
2023-11-17gdb: pass address_space to target dcache functionsSimon Marchi1-1/+1
A simple refactor to make the reference to current_program_space bubble up one level. No behavior changes expected. Change-Id: I237cf2f45ae73c35bcb433ce40e3c03cef6b87e2
2023-10-05gdb/configure.ac: Add option --with-additional-debug-dirsThiago Jung Bauermann1-0/+6
If you want to install GDB in a custom prefix, have it look for debug info in that prefix but also in the distro's default location (typically, /usr/lib/debug) and run the GDB testsuite before doing "make install", you have a bit of a problem: Configuring GDB with '--prefix=$PREFIX' sets the GDB 'debug-file-directory' parameter to $PREFIX/lib/debug. Unfortunately this precludes GDB from looking for distro-installed debug info in /usr/lib/debug. For regular GDB use you could set debug-file-directory to $PREFIX:/usr/lib/debug in $PREFIX/etc/gdbinit so that GDB will look in both places, but if you want to run the testsuite then that doesn't help because in that case GDB runs with the '-nx' option. There's the configure option '--with-separate-debug-dir' to set the default value for 'debug-file-directory', but it accepts only one directory and not a list. I considered modifying it to accept a list, but it's not obvious how to do that because its value is also used by BFD, as well as processed for "relocatability". I thought it was simpler to add a new option to specify a list of additional directories that will be appended to the debug-file-directory setting. Reviewed-By: Eli Zaretskii <eliz@gnu.org> Approved-By: Tom Tromey <tom@tromey.com>
2023-09-26Use string_file::release in some placesTom Tromey1-2/+2
I found a few spots like: string_file f; std::string x = f.string (); However, string_file::string returns a 'const std::string &'... so it seems to me that this must be copying the string (? I find it hard to reason about this in C++). This patch changes these spots to use release() instead, which moves the string. Reviewed-by: Keith Seitz <keiths@redhat.com> Reviewed-by: Lancelot Six <lancelot.six@amd.com>
2023-07-26[gdb/tui] Fix secondary promptTom de Vries1-0/+6
With CLI, a session defining a command looks like: ... (gdb) define foo Type commands for definition of "foo". End with a line saying just "end". >bar >end (gdb) ... With TUI however, we get the same secondary prompts, and type the same, but are left with: ... (gdb) define foo Type commands for definition of "foo". End with a line saying just "end". (gdb) ... Fix this by calling tui_inject_newline_into_command_window in gdb_readline_wrapper_line, as is done in tui_command_line_handler. Tested on x86_64-linux. PR tui/30636 Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=30636
2023-05-30[gdb] Mention --with/without-system-readline for --configurationTom de Vries1-0/+10
Simon reported that the new test-case gdb.tui/pr30056.exp fails with system readline. This is because the test-case requires a fix in readline that's present in our in-repo copy of readline, but most likely not in any system readline yet. Fix this by: - mentioning --with-system-readline or --without-system-readline in the configuration string. - adding a new proc with_system_readline that makes this information available in the testsuite. - using this in test-case gdb.tui/pr30056.exp to declare it unsupported for --with-system-readline. Tested on x86_64-linux. Reported-By: Simon Marchi <simon.marchi@efficios.com> Approved-By: Simon Marchi <simon.marchi@efficios.com>
2023-05-19gdb: fix post-hook execution for remote targetsJan Vrany1-1/+3
Commit b5661ff2 ("gdb: fix possible use-after-free when executing commands") attempted to fix possible use-after-free in case command redefines itself. Commit 37e5833d ("gdb: fix command lookup in execute_command ()") updated the previous fix to handle subcommands as well by using the original command string to lookup the command again after its execution. This fixed the test in gdb.base/define.exp but it turned out that it does not work (at least) for "target remote" and "target extended-remote". The problem is that the command buffer P passed to execute_command () gets overwritten in dont_repeat () while executing "target remote" command itself: #0 dont_repeat () at top.c:822 #1 0x000055555730982a in target_preopen (from_tty=1) at target.c:2483 #2 0x000055555711e911 in remote_target::open_1 (name=0x55555881c7fe ":1234", from_tty=1, extended_p=0) at remote.c:5946 #3 0x000055555711d577 in remote_target::open (name=0x55555881c7fe ":1234", from_tty=1) at remote.c:5272 #4 0x00005555573062f2 in open_target (args=0x55555881c7fe ":1234", from_tty=1, command=0x5555589d0490) at target.c:853 #5 0x0000555556ad22fa in cmd_func (cmd=0x5555589d0490, args=0x55555881c7fe ":1234", from_tty=1) at cli/cli-decode.c:2737 #6 0x00005555573487fd in execute_command (p=0x55555881c802 "4", from_tty=1) at top.c:688 Therefore the second call to lookup_cmd () at line 697 fails to find command because the original command string is gone. This commit addresses this particular problem by creating a *copy* of original command string for the sole purpose of using it after command execution to lookup the command again. It may not be the most efficient way but it's safer given that command buffer is shared and overwritten in hard-to-foresee situations. Tested on x86_64-linux. PR 30249 Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=30249 Approved-By: Tom Tromey <tom@tromey.com>
2023-05-01gdb: move struct ui and related things to ui.{c,h}Simon Marchi1-143/+6
I'd like to move some things so they become methods on struct ui. But first, I think that struct ui and the related things are big enough to deserve their own file, instead of being scattered through top.{c,h} and event-top.c. Change-Id: I15594269ace61fd76ef80a7b58f51ff3ab6979bc
2023-03-30PR gdb/30219: Clear sync_quit_force_run in quit_forceKevin Buettner1-0/+8
PR 30219 shows an internal error due to a "Bad switch" in print_exception() in gdb/exceptions.c. The switch in question contains cases for RETURN_QUIT and RETURN_ERROR, but is missing a case for the recently added RETURN_FORCED_QUIT. This commit adds that case. Making the above change allows the errant test case to pass, but does not fix the underlying problem, which I'll describe shortly. Even though the addition of a case for RETURN_FORCED_QUIT isn't the actual fix, I still think it's important to add this case so that other situations which lead to print_exeption() being called won't generate that "Bad switch" internal error. In order to understand the underlying problem, please examine this portion of the backtrace from the bug report: 0x5576e4ff5780 print_exception /home/smarchi/src/binutils-gdb/gdb/exceptions.c:100 0x5576e4ff5930 exception_print(ui_file*, gdb_exception const&) /home/smarchi/src/binutils-gdb/gdb/exceptions.c:110 0x5576e6a896dd quit_force(int*, int) /home/smarchi/src/binutils-gdb/gdb/top.c:1849 The real problem is in quit_force; here's the try/catch which eventually leads to the internal error: /* Get out of tfind mode, and kill or detach all inferiors. */ try { disconnect_tracing (); for (inferior *inf : all_inferiors ()) kill_or_detach (inf, from_tty); } catch (const gdb_exception &ex) { exception_print (gdb_stderr, ex); } While running the calls in the try-block, a QUIT check is being performed. This check finds that sync_quit_force_run is (still) set, causing a gdb_exception_forced_quit to be thrown. The exception gdb_exception_forced_quit is derived from gdb_exception, causing exception_print to be called. As shown by the backtrace, print_exception is then called, leading to the internal error. The actual fix, also implemented by this commit, is to clear sync_quit_force_run along with the quit flag. This will allow the various cleanup code, called by quit_force, to run without triggering a gdb_exception_forced_quit. (Though, if another SIGTERM is sent to the gdb process, these flags will be set again and a QUIT check in the cleanup code will detect it and throw the exception.) Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=30219 Approved-By: Simon Marchi <simon.marchi@efficios.com>
2023-03-09gdb, gdbserver, gdbsupport: fix whitespace issuesSimon Marchi1-1/+1
Replace spaces with tabs in a bunch of places. Change-Id: If0f87180f1d13028dc178e5a8af7882a067868b0
2023-02-24Don't use struct buffer in top.cTom Tromey1-14/+8
This changes top.c to use std::string rather than struct buffer. Like the event-top.c change, this is not completely ideal in that it requires a copy of the string.
2023-02-21gdb: add --with-curses to --configuration outputPhilippe Blain1-0/+10
'gdb --configuration' does not mention if GDB was built with curses. Since b5075fb68d4 (Rename to allow_tui_tests, 2023-01-08) it does show --enable-tui (or --disable-tui), but one might want to know if GDB was built with curses independently of the availability of the TUI. Since configure.ac uses AC_SEARCH_LIBS to check for the curses library, we do not get an automatically defined HAVE_LIBCURSES symbol in config.in. We do have symbols defined by AC_CHECK_HEADERS (HAVE_CURSES_H, etc.) but it would be cumbersome to use those in print_gdb_configuration because we would have to check for all 6 symbols corresponding the 6 headers listed. This would also increase the maintenance burden if support for other variations of curses are added. Instead, define 'HAVE_LIBCURSES' ourselves by adding an 'action-if-found' argument to AC_SEARCH_LIBS, and use it in print_gdb_configuration. While at it, remove the condition on 'ac_cv_search_waddstr' and set 'curses_found' directly in 'action-if-found'. Change-Id: Id90e3d73990e169cee51bcc3e1d52072cfacd5b8 Approved-By: Simon Marchi <simon.marchi@efficios.com>
2023-02-13gdb: 'show config' shows --with[out]-amd-dbgapiLancelot SIX1-0/+10
Ensure that the "show configuration" command and the "--configuration" command line switch shows if GDB was built with the AMDGPU support or not. This will be used in a later patch in this series. Approved-By: Simon Marchi <simon.marchi@efficios.com>
2023-01-13Rename to allow_tui_testsTom Tromey1-0/+10
This changes skip_tui_tests to invert the sense, and renames it to allow_tui_tests. It also rewrites this function to use the output of "gdb --configuration", and it adds a note about the state of the TUI to that output.
2023-01-01Update copyright year in help message of gdb, gdbserver, gdbreplayJoel Brobecker1-2/+2
This commit updates the copyright year displayed by gdb, gdbserver and gdbreplay's help message from 2022 to 2023, as per our Start of New Year procedure. The corresponding source files' copyright header are also updated accordingly.
2022-12-28Fix "set debug timestamp"Tom Tromey1-1/+1
PR cli/29945 points out that "set debug timestamp 1" stopped working -- this is a regression due to commit b8043d27 ("Remove a ui-related memory leak"). This patch fixes the bug and adds a regression test. I think this should probably be backported to the gdb 13 branch. Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=29945
2022-12-21Fix compiling of top.cAndrew Pinski1-1/+0
When I moved my last patch forward, somehow I missed removing the #endif for the HAVE_LIBMPFR case. Committed as obvious after a quick build. gdb/ChangeLog: * top.c: Remove the extra #endif which was missed.
2022-12-21Use toplevel configure for GMP and MPFR for gdbAndrew Pinski1-8/+0
This patch uses the toplevel configure parts for GMP/MPFR for gdb. The only thing is that gdb now requires MPFR for building. Before it was a recommended but not required library. Also this allows building of GMP and MPFR with the toplevel directory just like how it is done for GCC. We now error out in the toplevel configure of the version of GMP and MPFR that is wrong. OK after GDB 13 branches? Build gdb 3 ways: with GMP and MPFR in the toplevel (static library used at that point for both) With only MPFR in the toplevel (GMP distro library used and MPFR built from source) With neither GMP and MPFR in the toplevel (distro libraries used) Changes from v1: * Updated gdb/README and gdb/doc/gdb.texinfo. * Regenerated using unmodified autoconf-2.69 Thanks, Andrew Pinski ChangeLog: * Makefile.def: Add configure-gdb dependencies on all-gmp and all-mpfr. * configure.ac: Split out MPC checking from MPFR. Require GMP and MPFR if the gdb directory exist. * Makefile.in: Regenerate. * configure: Regenerate. gdb/ChangeLog: PR bug/28500 * configure.ac: Remove AC_LIB_HAVE_LINKFLAGS for gmp and mpfr. Use GMPLIBS and GMPINC which is provided by the toplevel configure. * Makefile.in (LIBGMP, LIBMPFR): Remove. (GMPLIBS, GMPINC): Add definition. (INTERNAL_CFLAGS_BASE): Add GMPINC. (CLIBS): Exchange LIBMPFR and LIBGMP for GMPLIBS. * target-float.c: Make the code conditional on HAVE_LIBMPFR unconditional. * top.c: Remove code checking HAVE_LIBMPFR. * configure: Regenerate. * config.in: Regenerate. * README: Update GMP/MPFR section of the config options. * doc/gdb.texinfo: Likewise. Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=28500
2022-12-19gdb: fix command lookup in execute_command ()Jan Vrany1-6/+2
Commit b5661ff2 ("gdb: fix possible use-after-free when executing commands") used lookup_cmd_exact () to lookup command again after its execution to avoid possible use-after-free error. However this change broke test gdb.base/define.exp which defines a post-hook for subcommand ("target testsuite"). In this case, lookup_cmd_exact () returned NULL because there's no command 'testsuite' in top-level commands. This commit fixes this case by looking up the command again using the original command line via lookup_cmd (). Approved-By: Simon Marchi <simon.marchi@efficios.com>
2022-12-15gdb: remove static buffer in command_line_inputSimon Marchi1-26/+13
[I sent this earlier today, but I don't see it in the archives. Resending it through a different computer / SMTP.] The use of the static buffer in command_line_input is becoming problematic, as explained here [1]. In short, with this patch [2] that attempt to fix a post-hook bug, when running gdb.base/commands.exp, we hit a case where we read a "define" command line from a script file using command_command_line_input. The command line is stored in command_line_input's static buffer. Inside the define command's execution, we read the lines inside the define using command_line_input, which overwrites the define command, in command_line_input's static buffer. After the execution of the define command, execute_command does a command look up to see if a post-hook is registered. For that, it uses a now stale pointer that used to point to the define command, in the static buffer, causing a use-after-free. Note that the pointer in execute_command points to the dynamically-allocated buffer help by the static buffer in command_line_input, not to the static object itself, hence why we see a use-after-free. Fix that by removing the static buffer. I initially changed command_line_input and other related functions to return an std::string, which is the obvious but naive solution. The thing is that some callees don't need to return an allocated string, so this this an unnecessary pessimization. I changed it to passing in a reference to an std::string buffer, which the callee can use if it needs to return dynamically-allocated content. It fills the buffer and returns a pointers to the C string inside. The callees that don't need to return dynamically-allocated content simply don't use it. So, it started with modifying command_line_input as described above, all the other changes derive directly from that. One slightly shady thing is in handle_line_of_input, where we now pass a pointer to an std::string's internal buffer to readline's history_value function, which takes a `char *`. I'm pretty sure that this function does not modify the input string, because I was able to change it (with enough massaging) to take a `const char *`. A subtle change is that we now clear a UI's line buffer using a SCOPE_EXIT in command_line_handler, after executing the command. This was previously done by this line in handle_line_of_input: /* We have a complete command line now. Prepare for the next command, but leave ownership of memory to the buffer . */ cmd_line_buffer->used_size = 0; I think the new way is clearer. [1] https://inbox.sourceware.org/gdb-patches/becb8438-81ef-8ad8-cc42-fcbfaea8cddd@simark.ca/ [2] https://inbox.sourceware.org/gdb-patches/20221213112241.621889-1-jan.vrany@labware.com/ Change-Id: I8fc89b1c69870c7fc7ad9c1705724bd493596300 Reviewed-By: Tom Tromey <tom@tromey.com>
2022-12-14gdb: remove the pop_all_targets (and friends) global functionsAndrew Burgess1-2/+1
This commit removes the global functions pop_all_targets, pop_all_targets_above, and pop_all_targets_at_and_above, and makes them methods on the inferior class. As the pop_all_targets functions will unpush each target, which decrements the targets reference count, it is possible that the target might be closed. Right now, closing a target, in some cases, depends on the current inferior being set correctly, that is, to the inferior from which the target was popped. To facilitate this I have used switch_to_inferior_no_thread within the new methods. Previously it was the responsibility of the caller to ensure that the correct inferior was selected. In a couple of places (event-top.c and top.c) I have been able to remove a previous switch_to_inferior_no_thread call. In remote_unpush_target (remote.c) I have left the switch_to_inferior_no_thread call as it is required for the generic_mourn_inferior call.
2022-12-12gdb: fix possible use-after-free when executing commandsJan Vrany1-2/+12
In principle, `execute_command()` does following: struct cmd_list_element *c; c = lookup_cmd ( ... ); ... /* If this command has been pre-hooked, run the hook first. */ execute_cmd_pre_hook (c); ... /* ...execute the command `c` ...*/ ... execute_cmd_post_hook (c); This may lead into use-after-free error. Imagine the command being executed is a user-defined Python command that redefines itself. In that case, struct `cmd_list_element` pointed to by `c` is deallocated during its execution so it is no longer valid when post hook is executed. To fix this case, this commit looks up the command once again after it is executed to get pointer to (possibly newly allocated) `cmd_list_element`.
2022-10-10Change GDB to use frame_info_ptrTom Tromey1-1/+1
This changes GDB to use frame_info_ptr instead of frame_info * The substitution was done with multiple sequential `sed` commands: sed 's/^struct frame_info;/class frame_info_ptr;/' sed 's/struct frame_info \*/frame_info_ptr /g' - which left some issues in a few files, that were manually fixed. sed 's/\<frame_info \*/frame_info_ptr /g' sed 's/frame_info_ptr $/frame_info_ptr/g' - used to remove whitespace problems. The changed files were then manually checked and some 'sed' changes undone, some constructors and some gets were added, according to what made sense, and what Tromey originally did Co-Authored-By: Bruno Larsen <blarsen@redhat.com> Approved-by: Tom Tomey <tom@tromey.com>
2022-08-31Use member initialization in 'struct ui'Tom Tromey1-11/+2
This changes 'struct ui' to use member initialization. This is simpler to understand.
2022-08-31Use ui_out_redirect_pop in more placesTom Tromey1-2/+1
This changes ui_out_redirect_pop to also perform the redirection, and then updates several sites to use this, rather than explicit redirects.
2022-08-31Free ui::line_bufferTom Tromey1-0/+2
A ui initializes its line_buffer, but never calls buffer_free on it. This patch fixes the oversight. I found this by inspection.
2022-08-19Remove two initialization functionsTom Tromey1-16/+7
I noticed a couple of initialization functions that aren't really needed, and that currently require explicit calls in gdb_init. This patch removes these functions, simplifying gdb a little. Regression tested on x86-64 Fedora 34.
2022-07-22Change target_ops::async to accept boolTom Tromey1-2/+2
This changes the parameter of target_ops::async from int to bool. Regression tested on x86-64 Fedora 34.
2022-07-18Replace input_interactive_p with a methodTom Tromey1-9/+9
This replaces the global input_interactive_p function with a new method ui::input_interactive_p.
2022-04-24gdb: move setbuf calls out of gdb_readline_no_editing_callbackAndrew Burgess1-0/+39
After this commit: commit d08cbc5d3203118da5583296e49273cf82378042 Date: Wed Dec 22 12:57:44 2021 +0000 gdb: unbuffer all input streams when not using readline Issues were reported with some MS-Windows hosts, see the thread starting here: https://sourceware.org/pipermail/gdb-patches/2022-March/187004.html Filed in bugzilla as: PR mi/29002 The problem seems to be that calling setbuf on terminal file handles is not always acceptable, see this mail for more details: https://sourceware.org/pipermail/gdb-patches/2022-April/187310.html This commit does two things, first moving the setbuf calls out of gdb_readline_no_editing_callback so that we don't end up calling setbuf so often. Then, for MS-Windows hosts, we don't call setbuf for terminals, this appears to resolve the issues that have been reported. Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=29002
2022-04-22gdb: handle bracketed-paste-mode and EOF correctlyAndrew Burgess1-0/+1
This commit replaces an earlier commit that worked around the issues reported in bug PR gdb/28833. The previous commit just implemented a work around in order to avoid the worst results of the bug, but was not a complete solution. The full solution was considered too risky to merge close to branching GDB 12. This improved fix has been applied after GDB 12 branched. See this thread for more details: https://sourceware.org/pipermail/gdb-patches/2022-March/186391.html This commit replaces this earlier commit: commit 74a159a420d4b466cc81061c16d444568e36740c Date: Fri Mar 11 14:44:03 2022 +0000 gdb: work around prompt corruption caused by bracketed-paste-mode Please read that commit for a full description of the bug, and why is occurs. In this commit I extend GDB to use readline's rl_deprep_term_function hook to call a new function gdb_rl_deprep_term_function. From this new function we can now print the 'quit' message, this replaces the old printing of 'quit' in command_line_handler. Of course, we only print 'quit' in gdb_rl_deprep_term_function when we are handling EOF, but thanks to the previous commit (to readline) we now know when this is. There are two aspects of this commit that are worth further discussion, the first is in the new gdb_rl_deprep_term_function function. In here I have used a scoped_restore_tmpl to disable the readline global variable rl_eof_found. The reason for this is that, in rl_deprep_terminal, readline will print an extra '\n' character before printing the escape sequence to leave bracketed paste mode. You might then think that in the gdb_rl_deprep_term_function function, we could simply print "quit" and rely on rl_deprep_terminal to print the trailing '\n'. However, rl_deprep_terminal only prints the '\n' when bracketed paste mode is on. If the user has turned this feature off, no '\n' is printed. This means that in gdb_rl_deprep_term_function we need to print "quit" when bracketed paste mode is on, and "quit\n" when bracketed paste mode is off. We could absolutely do that, no problem, but given we know how rl_deprep_terminal is implemented, it's easier (I think) to just temporarily clear rl_eof_found, this prevents the '\n' being printed from rl_deprep_terminal, and so in gdb_rl_deprep_term_function, we can now always print "quit\n" and this works for all cases. The second issue that should be discussed is backwards compatibility with older versions of readline. GDB can be built against the system readline, which might be older than the version contained within GDB's tree. If this is the case then the system readline might not contain the fixes needed to support correctly printing the 'quit' string. To handle this situation I have retained the existing code in command_line_handler for printing 'quit', however, this code is only used now if the version of readline we are using doesn't not include the required fixes. And so, if a user is using an older version of readline, and they have bracketed paste mode on, then they will see the 'quit' sting printed on the line below the prompt, like this: (gdb) quit I think this is the best we can do when someone builds GDB against an older version of readline. Using a newer version of readline, or the patched version of readline that is in-tree, will now give a result like this in all cases: (gdb) quit Which is what we want. Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=28833
2022-04-18gdbsupport: make gdb_abspath return an std::stringSimon Marchi1-8/+2
I'm trying to switch these functions to use std::string instead of char arrays, as much as possible. Some callers benefit from it (can avoid doing a copy of the result), while others suffer (have to make one more copy). Change-Id: Iced49b8ee2f189744c5072a3b217aab5af17a993
2022-04-03gdb: fix gdb_print -> gdb_printf typoSimon Marchi1-1/+1
This caused a build failure with !CXX_STD_THREAD. Change-Id: I30f0c89c43a76f85c0db34809192644fa64a9d18
2022-03-31Style URLs in GDB outputTom Tromey1-4/+10
I noticed that GDB will display URLs in a few spots. This changes them to be styled. Originally I thought I'd introduce a new "url" style, but there aren't many places to use this, so I just reused filename styling instead. This patch also changes the debuginfod URL list to be printed one URL per line. I think this is probably a bit easier to read.
2022-03-31gdb: fix use of fprintf_filtered in top.cSimon Marchi1-2/+2
A race condition in how patches were pushed causes this build failure: CXX top.o /home/simark/src/binutils-gdb/gdb/top.c: In function ‘void print_gdb_configuration(ui_file*)’: /home/simark/src/binutils-gdb/gdb/top.c:1622:3: error: ‘fprintf_filtered’ was not declared in this scope; did you mean ‘printf_unfiltered’? 1622 | fprintf_filtered (stream, _("\ | ^~~~~~~~~~~~~~~~ fprintf_filtered has been removed, gdb_printf must be used now. Fix this. Change-Id: I6a172ba0d53dab2e7cc43ed0ed2696c82925245b
2022-03-31* gdb/top.c (print_gdb_configuration): Announce --enable-threading.Eli Zaretskii1-0/+10
This includes the reporting of --enable/disable-threading as part of the GDB configuration description.
2022-03-30Consolidate definition of current_directoryTom Tromey1-4/+0
I noticed that both gdbserver and gdb define current_directory. However, as it is referenced by gdbsupport, it seemed better to define it there as well. This patch also moves the declaration to pathstuff.h. Tested by rebuilding.
2022-03-29Remove unnecessary calls to wrap_here and gdb_flushTom Tromey1-1/+0
Various spots in gdb currently know about the wrap buffer, and so are careful to call wrap_here to be certain that all output has been flushed. Now that the pager is just an ordinary stream, this isn't needed, and a simple call to gdb_flush is enough. Similarly, there are places where gdb prints to gdb_stderr, but first flushes gdb_stdout. stderr_file already flushes gdb_stdout, so these aren't needed.
2022-03-29Unify gdb printf functionsTom Tromey1-104/+104
Now that filtered and unfiltered output can be treated identically, we can unify the printf family of functions. This is done under the name "gdb_printf". Most of this patch was written by script.
2022-03-29Change the pager to a ui_fileTom Tromey1-1/+2
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