aboutsummaryrefslogtreecommitdiff
path: root/gdb/tui
AgeCommit message (Collapse)AuthorFilesLines
2023-01-01Update copyright year range in header of all files managed by GDBJoel Brobecker33-33/+33
This commit is the result of running the gdb/copyright.py script, which automated the update of the copyright year range for all source files managed by the GDB project to be updated to include year 2023.
2022-12-15Remove subset_compareTom Tromey1-2/+2
I stumbled across subset_compare today, and after looking at the callers I realized it could be removed and replaced with calls to startswith. Approved-By: Simon Marchi <simon.marchi@efficios.com>
2022-11-17Use boolean literals for pagination_enabledTom Tromey1-1/+1
I noticed a couple of spots that used '0' rather than 'false' when modifying pagination_enabled. This patch cleans these up.
2022-11-16gdb: add "set style tui-current-position on|off", default to offPedro Alves3-1/+53
As discussed at: https://sourceware.org/pipermail/gdb-patches/2020-June/169519.html this patch disables source and assembly code highlighting for the text highlighted by the TUI's current position indicator, and adds a command to enable it back.
2022-10-25gdb: remove spurious spaces after frame_info_ptrSimon Marchi1-1/+1
Fix some whitespace issues introduced with the frame_info_ptr patch. Change-Id: I158d30d8108c97564276c647fc98283ff7b12163
2022-10-19internal_error: remove need to pass __FILE__/__LINE__Pedro Alves1-1/+1
Currently, every internal_error call must be passed __FILE__/__LINE__ explicitly, like: internal_error (__FILE__, __LINE__, "foo %d", var); The need to pass in explicit __FILE__/__LINE__ is there probably because the function predates widespread and portable variadic macros availability. We can use variadic macros nowadays, and in fact, we already use them in several places, including the related gdb_assert_not_reached. So this patch renames the internal_error function to something else, and then reimplements internal_error as a variadic macro that expands __FILE__/__LINE__ itself. The result is that we now should call internal_error like so: internal_error ("foo %d", var); Likewise for internal_warning. The patch adjusts all calls sites. 99% of the adjustments were done with a perl/sed script. The non-mechanical changes are in gdbsupport/errors.h, gdbsupport/gdb_assert.h, and gdb/gdbarch.py. Approved-By: Simon Marchi <simon.marchi@efficios.com> Change-Id: Ia6f372c11550ca876829e8fd85048f4502bdcf06
2022-10-10Change GDB to use frame_info_ptrTom Tromey11-21/+21
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-10-02gdb: update now gdbarch_register_name doesn't return nullptrAndrew Burgess1-2/+2
After the previous few commit, gdbarch_register_name no longer returns nullptr. This commit audits all the calls to gdbarch_register_name and removes any code that checks the result against nullptr. There should be no visible change after this commit.
2022-09-22gdb/python: restrict the names accepted by gdb.register_window_typeAndrew Burgess1-0/+13
I noticed that, from Python, I could register a new TUI window that had whitespace in its name, like this: gdb.register_window_type('my window', MyWindowType) however, it is not possible to then use this window in a new TUI layout, e.g.: (gdb) tui new-layout foo my window 1 cmd 1 Unknown window "my" (gdb) tui new-layout foo "my window" 1 cmd 1 Unknown window ""my" (gdb) tui new-layout foo my\ window 1 cmd 1 Unknown window "my\" GDB clearly uses the whitespace to split the incoming command line. I could fix this by trying to add a mechanism by which we can use whitespace within a window name, but it seems like an easier solution if we just forbid whitespace within a window name. Not only is this easier, but I think this is probably the better solution, identifier names with spaces in would mean we'd need to audit all the places a window name could be printed and ensure that the use of a space didn't make the output ambiguous. So, having decided to disallow whitespace, I then thought about other special characters. We currently accept anything as a window name, and I wondered if this was a good idea. My concerns were about how special characters used in a window name might cause confusion, for example, we allow '$' in window names, which is maybe fine now, but what if one day we wanted to allow variable expansion when creating new layouts? Or what about starting a window name with '-'? We already support a '-horizontal' option, what if we want to add more in the future? Or use of the special character '{' which has special meaning within a new layout? In the end I figured it might make sense to place some restrictive rules in place, and then relax the rules later if/when users complain, we can consider each relaxation as its requested. So, I propose that window names should match this regular expression: [a-zA-Z][-_.a-zA-Z0-9]* There is a chance that there is user code in the wild which will break with the addition of this change, but hopefully adapting to the new restrictions shouldn't be too difficult.
2022-09-12Use checked_static_cast in more placesTom Tromey1-2/+2
I went through all the uses of dynamic_cast<> in gdb, looking for ones that could be replaced with checked_static_cast. This patch is the result. Regression tested on x86-64 Fedora 34.
2022-08-31Fix "source" with interpreter-execTom Tromey1-0/+1
PR mi/15811 points out that "source"ing a file that uses interpreter-exec will put gdb in a weird state, where the CLI stops working. The bug is that tui_interp::suspend does not unregister the event file descriptor. The test case is from Andrew Burgess. Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=15811
2022-08-31TUI stdout buffering cleanupTom Tromey3-23/+14
The TUI checks against gdb_stdout to decide when to buffer. It seems much cleaner to me to simply record this as an attribute of the stream itself.
2022-08-31Remove tui_out_newTom Tromey3-9/+1
tui_out_new is just a simple wrapper for 'new' and can be removed, simplifying gdb a tiny bit.
2022-08-31Remove the "for moment" commentsTom Tromey1-4/+4
A few spots setting some gdb output stream variables have a "for moment" comment. These comments aren't useful and I think the moment has passed -- these are permanent now.
2022-07-18Remove cli_out_newTom Tromey1-1/+1
cli_out_new is just a small wrapper around 'new'. This patch removes it, replacing it with uses of 'new' instead.
2022-06-24Eliminate TUI/CLI observers duplicationPedro Alves1-187/+3
For historical reasons, the CLI and the TUI observers are basically exact duplicates, except for the downcast: cli: struct cli_interp *cli = as_cli_interp (interp); tui: struct interp *tui = as_tui_interp (interp); and how they get at the interpreter's ui_out: cli: cli->cli_uiout tui: tui->interp_ui_out () Since interp_ui_out() is a virtual method that also works for the CLI interpreter, and, both the CLI and the TUI interpreters inherit from the same base class (cli_interp_base), we can convert the CLI observers to cast to cli_interp_base instead and use interp_ui_out() too. With that, the CLI observers will work for the TUI interpreter as well. This lets us completely eliminate the TUI observers. That's what this commit does. Change-Id: Iaf6cf12dfa200ed3ab203a895a72b69dfedbd6e0
2022-06-22Use std::string for interpreter_pTom Tromey1-6/+3
The global interpreter_p is a manually-managed 'char *'. This patch changes it to be a std::string instead, and removes some erroneous comments.
2022-04-11gdb: remove symbol value macrosSimon Marchi1-3/+3
Remove all macros related to getting and setting some symbol value: #define SYMBOL_VALUE(symbol) (symbol)->value.ivalue #define SYMBOL_VALUE_ADDRESS(symbol) \ #define SET_SYMBOL_VALUE_ADDRESS(symbol, new_value) \ #define SYMBOL_VALUE_BYTES(symbol) (symbol)->value.bytes #define SYMBOL_VALUE_COMMON_BLOCK(symbol) (symbol)->value.common_block #define SYMBOL_BLOCK_VALUE(symbol) (symbol)->value.block #define SYMBOL_VALUE_CHAIN(symbol) (symbol)->value.chain #define MSYMBOL_VALUE(symbol) (symbol)->value.ivalue #define MSYMBOL_VALUE_RAW_ADDRESS(symbol) ((symbol)->value.address + 0) #define MSYMBOL_VALUE_ADDRESS(objfile, symbol) \ #define BMSYMBOL_VALUE_ADDRESS(symbol) \ #define SET_MSYMBOL_VALUE_ADDRESS(symbol, new_value) \ #define MSYMBOL_VALUE_BYTES(symbol) (symbol)->value.bytes #define MSYMBOL_BLOCK_VALUE(symbol) (symbol)->value.block Replace them with equivalent methods on the appropriate objects. Change-Id: Iafdab3b8eefc6dc2fd895aa955bf64fafc59ed50
2022-04-07gdb: remove symtab::objfileSimon Marchi2-2/+2
Same idea as previous patch, but for symtab::objfile. I find it clearer without this wrapper, as it shows that the objfile is common to all symtabs of a given compunit. Otherwise, you could think that each symtab (of a given compunit) can have a specific objfile. Change-Id: Ifc0dbc7ec31a06eefa2787c921196949d5a6fcc6
2022-04-07gdb: move struct reggroup into reggroups.h headerAndrew Burgess1-3/+3
Move 'struct reggroup' into the reggroups.h header. Remove the reggroup_name and reggroup_type accessor functions, and just use the name/type member functions within 'struct reggroup', update all uses of these removed functions. There should be no user visible changes after this commit.
2022-04-07gdb: remove reggroup_next and reggroup_prevAndrew Burgess1-28/+37
Add a new function gdbarch_reggroups that returns a reference to a vector containing all the reggroups for an architecture. Make use of this function throughout GDB instead of the existing reggroup_next and reggroup_prev functions. Finally, delete the reggroup_next and reggroup_prev functions. Most of these changes are pretty straight forward, using range based for loops instead of the old style look using reggroup_next. There are two places where the changes are less straight forward. In gdb/python/py-registers.c, the register group iterator needed to change slightly. As the iterator is tightly coupled to the gdbarch, I just fetch the register group vector from the gdbarch when needed, and use an index counter to find the next item from the vector when needed. In gdb/tui/tui-regs.c the tui_reg_next and tui_reg_prev functions are just wrappers around reggroup_next and reggroup_prev respectively. I've just inlined the logic of the old functions into the tui functions. As the tui function had its own special twist (wrap around behaviour) I think this is OK. There should be no user visible changes after this commit.
2022-04-07gdb/tui: fix 'tui reg next/prev' command when data window is hiddenAndrew Burgess1-20/+14
Start GDB like: $ gdb -q executable (gdb) start (gdb) layout src ... tui windows are now displayed ... (gdb) tui reg next At this point the data (register) window should be displayed, but will contain the message 'Register Values Unavailable', and at the console you'll see the message "unknown register group 'next'". The same happens with 'tui reg prev' (but the error message is slightly different). At this point you can continue to use 'tui reg next' and/or 'tui reg prev' and you'll keep getting the error message. The problem is that when the data (register) window is first displayed, it's current register group is nullptr. As a consequence tui_reg_next and tui_reg_prev (tui/tui-regs.c) will always just return nullptr, which triggers an error in tui_reg_command. In this commit I change tui_reg_next and tui_reg_prev so that they instead return the first and last register group respectively if the current register group is nullptr. So, after this, using 'tui reg next' will (in the above case) show the first register group, while 'tui reg prev' will display the last register group.
2022-04-07gdb/tui: avoid theoretical bug with 'tui reg' commandAndrew Burgess1-11/+13
While looking at the 'tui reg' command as part of another patch, I spotted a theoretical bug. The 'tui reg' command takes the name of a register group, but also handles partial register group matches, though the partial match has to be unique. The current command logic goes: With the code as currently written, if a target description named a register group either 'prev' or 'next' then GDB would see this as an ambiguous register name, and refuse to switch groups. Naming a register group 'prev' or 'next' seems pretty unlikely, but, by adding a single else block we can prevent this problem. Now, if there's a 'prev' or 'next' register group, the user will not be able to select the group directly, the 'prev' and 'next' names will always iterate through the available groups instead. But at least the user could select their groups by iteration, rather than direct selection.
2022-04-07gdb: switch to using 'const reggroup *' in tui-regs.{c,h}Andrew Burgess2-15/+16
Make uses of 'reggroup *' const throughout tui-regs.{c,h}. There should be no user visible changes after this commit.
2022-04-03gdb/tui: fair split of delta after a resizeAndrew Burgess1-12/+25
Currently, in master gdb, when a tui window is changed in size, the screen delta is mostly just added to the next available window. We do take care to respect the min/max size, but in most cases, these limits are just "the terminal size", and so, we end up placing the whole delta on the next window. Consider these steps in an 80 column, 24 line terminal: (gdb) tui enable (gdb) layout src (gdb) layout split (gdb) info win Name Lines Columns Focus src 8 80 (has focus) asm 8 80 status 1 80 cmd 8 80 (gdb) winheight cmd +2 (gdb) info win Name Lines Columns Focus src 6 80 (has focus) asm 8 80 status 1 80 cmd 10 80 Notice that initially, the windows were balanced, 8 lines each for the major windows. Then, when the cmd window was adjusted, the extra two lines were given to the asm window. I think it would be nicer if the delta was spread more evenly over the available windows. In the example above, after the adjustment the layout now looks like: (gdb) info win Name Lines Columns Focus src 7 80 (has focus) asm 7 80 status 1 80 cmd 10 80 This is achieved within tui_layout_split::set_size, by just handing out the delta in increments of 1 to each window (except for the window the user adjusted), until there's no more delta left. Of course, we continue to respect the min/max window sizes.
2022-04-03gdb/tui: relax restrictions on window max height and widthAndrew Burgess3-10/+2
This commit removes some arbitrary adjustments made in tui_cmd_window::max_height, tui_win_info::max_height, and tui_win_info::max_width. These member functions all subtract some constant from the theoretical maximum height or width. I've looked back through the history a little and can see no real reason why these adjustments should be needed, with these adjustments removed all the existing tui tests still pass. However, retaining these restrictions causes some bugs, consider: (gdb) tui new-layout hsrc {-horizontal src 1 cmd 1} 1 When this layout is selected with current master, gdb will leave a 4 line gap at the bottom of the terminal. The problem is that the maximum height is restricted, for the cmd window, to 4 less than the terminal height. By removing this restriction gdb is able to size the windows to the complete terminal height, and the layout is done correctly. This 4 line restriction is also what prevents this layout from working correctly: (gdb) tui new-layout conly cmd 1 Previously, this layout would present a cmd window only, but there would be a 4 line gap at the bottom of the terminal. This issue was mentioned in an earlier commit in this series (when a different bug was fixed), but with this commit, the above layout now correctly fills the terminal. The associated test is updated. After removing the adjustment in tui_cmd_window::max_height, the implementation is now the same as the implementation in the parent class tui_win_info, so I've completely removed the max_height call from tui_cmd_window.
2022-04-03gdb/tui: support placing the cmd window into a horizontal layoutAndrew Burgess3-25/+97
This commit allows the user to place the cmd window within horizontal tui layouts. Consider this set of steps, carried out in an 80 columns by 24 lines terminal, using current master gdb: (gdb) tui new-layout hsrc { -horizontal src 1 cmd 1 } 1 status 1 (gdb) tui layout hsrc What you end up with is a full width cmd window with the status bar beneath. Where's the src window gone? We then try: (gdb) info win Name Lines Columns Focus src 23 3 (has focus) cmd 23 80 status 1 80 (gdb) Something weird has gone on, gdb has overlapped the cmd window with the src window. If we trigger the src window to redraw is content, for example, 'list main', then we see corruption in the cmd window as the src window overwrites it. So, what's going on? The problem is some code in tui_layout_split::apply, in tui-layout.c. Within 'Step 1', there is a loop that calculates the min/max window sizes for all windows within a tui_layout_split. However, there's a special case for the cmd window. This special case is trying to have the cmd window retain its current size when a layout is re-applied, or a new layout is applied. This makes sense, consider moving from the 'src' layout to the 'asm' layout, this looks something like this (status window removed): .-------. .-------. | src | | asm | |-------| ====> |-------| | cmd | | cmd | '-------' '-------' If the user has gone to the effort of adjusting the cmd window size, then, the thinking goes, we shouldn't reset the cmd window size when switching layouts like this. The problem though, is that when we do a switch more like this: .-----------. .-----------. | src | | | | |-----------| ====> | asm | cmd | | cmd | | | | '-----------' '-----------' Now retaining the cmd window width makes no sense; the new layout has a completely different placement for the cmd window, instead of sizing by height, we're now sizing by width. The existing code doesn't understand this though, and tried to retain the full width for the cmd window. To solve this problem, I propose we introduce the idea of a layout "fingerprint". The fingerprint tries to capture, in an abstract way, where the cmd window lives within the layout. Only when two layouts have the same fingerprint will we attempt to retain the cmd window size. The fingerprint for a layout is represented as a string, the string is a series of 'V' or 'H' characters, ending with a single 'C' character. The series of 'V' and 'H' characters represent the vertical or horizontal layouts that must be passed through to find the cmd window. Here are a few examples: # This layout is equivalent to the builtin 'src' layout. # Fingerprint: VC tui new-layout example1 src 2 status 0 cmd 1 # This layout is equivalent to the builtin 'split' layout. # Fingerprint: VC tui new-layout example2 src 1 asm 1 status 0 cmd 1 # This is the same layout that was given at the top. # Fingerprint: VHC tui new-layout hsrc { -horizontal src 1 cmd 1 } 1 status 1 And so, when switching between example1 and example2, gdb knows that the cmd window is, basically, in the same sort of position within the layout, and will retain the cmd window size. In contrast, when switching to the hsrc layout, gdb understands that the position of the cmd window is different, and does not try to retain the cmd window size.
2022-04-03gdb/tui: allow cmd window to change size in tui_layout_split::applyAndrew Burgess1-8/+87
When we switch layouts we call the tui_layout_split::apply member function to reapply the layout, and recalculate all the window sizes. One special case is the cmd window, which we try to keep at its existing size. However, in some cases it is not appropriate to keep the cmd window at its existing size. I will describe two such cases here, in one, we want the cmd window to reduce in size, and in the other, we want the cmd window to grow in size. Try these steps in a 80 columns, by 24 lines terminal: (gdb) tui enable (gdb) layout src (gdb) winheight cmd 20 (gdb) layout split You should see that the status window is missing from the new layout, and that the cmd window has been placed over the border of the asm window. The 'info win' output is: (gdb) info win Name Lines Columns Focus src 3 80 (has focus) asm 3 80 status 1 80 cmd 20 80 Notice that gdb has assigned 27 lines of screen space, even with the border overlap between the src and asm windows, this is still 2 lines too many. The problem here is that after switching layouts, gdb has forced the cmd window to retain its 20 line height. Really, we want the cmd window to reduce in height so that the src and asm windows can occupy their minimum required space. This commit allows this (details on how are below). After this commit, in the above situation, we now see the status window displayed correctly, and the 'info win' output is: (gdb) info win Name Lines Columns Focus src 3 80 (has focus) asm 3 80 status 1 80 cmd 18 80 The cmd window has been reduced in size by 2 lines so that everything can fit on the screen. The second example is one which was discussed in a recent commit, consider this case (still in the 80 column, 24 line terminal): (gdb) tui enable (gdb) tui new-layout conly cmd 1 (gdb) layout conly (gdb) info win Name Lines Columns Focus cmd 8 80 (has focus) (gdb) This layout only contains a cmd window, which we would expect to occupy the entire terminal. But instead, the cmd window only occupies the first 8 lines, and the rest of the terminal is unused! The reason is, again, that the cmd window is keeping its previous size (8 lines). After this commit things are slightly different, the 'info win' output is now: (gdb) info win Name Lines Columns Focus cmd 20 80 (has focus) Which is a little better, but why only 20 lines? Turns out there's yet another bug hitting this case. That bug will be addressed in a later commit, so, for now, we're accepting the 20 lines. What this commit does is modify the phase of tui_layout_split::apply that handles any left over space. Usually, in "Step 2", each sub-layout has a size calculated. As the size is an integer, then, when all sizes are calculated we may have some space left over. This extra space is then distributed between all the windows fairly until all the space is used up. When we consider windows minimum size, or fixed size windows, then it is possible that we might try to use more space than is available, this was our first example above. The same code that added extra space to the windows, can also be used to reclaim space (in the over allocation case) to allow all windows to fit. The problem then is the cmd window, which we often force to a fixed size. Inside the loop that handles the allocation of excess space, if we find that we have tried every window, and still have space either left to give, or we need to claim back more space, then, if the cmd window was changed to a fixed size, we can change the cmd window back to a non-fixed-size window, and proceed to either give, or take space from the cmd window as needed.
2022-04-03gdb/tui: fairer distribution of excess space during applyAndrew Burgess1-7/+31
When applying layouts gdb computes the size of each window (or rather, each sub-layout within a layout) using integer arithmetic. As this rounds down the results, then, when all sub-layouts are sized, there is the possibility that we have some space left over. Currently, this space is just assigned to an arbitrary sub-layout. This can result in some unbalanced results. Consider this set of steps with current master: (gdb) tui enable (gdb) layout regs (gdb) info win Name Lines Columns Focus regs 7 80 src 9 80 (has focus) status 1 80 cmd 8 80 Notice the weird split between the src and regs windows, the original layout specification has these windows given equal weight. The problem is that, with rounding, both the regs and src windows are initially sized to 7, the extra 2 lines are then arbitrarily added to the src window. In this commit, rather than add all the extra space to one single window, I instead hand out the extra space 1 line at a time, looping over all the sub-layouts. We take care to respect the min/max sizes, and so, we now get this result: (gdb) tui enable (gdb) layout regs (gdb) info win Name Lines Columns Focus regs 8 80 src 8 80 (has focus) status 1 80 cmd 8 80 This looks more natural to me. This is obviously a change in behaviour, and so, lots of the existing tests need to be updated to take this into account. None of the changes are huge, it's just a line or two (or column for width) moved between windows.
2022-04-03gdb/tui: avoid fp exception when applying layoutsAndrew Burgess1-11/+19
Consider: (gdb) tui enable (gdb) layout src (gdb) tui new-layout conly cmd 1 (gdb) layout conly After this, with current master, gdb crashes with a floating-point exception. The problem is that in tui_layout_split::apply, when we switch from 'src' to 'conly', we will try to retain the cmd window height. As such, the cmd window will become a fixed size window, which decreases the available_size, but doesn't count towards the total_weight. As the cmd window is the only window, the total_weight stays at zero, and, when we move into step 2, where we attempt to size the windows, we perform a divide by zero, and crash. After this commit we avoid the divide by zero, and just directly set the window size based on the fixed size. There is still a problem after this commit, when the conly layout is selected the cmd window retains its original height, which will only be part of the terminal. The rest of the terminal is left unused. This issue will be addressed in a later commit, this commit is just about the floating-point exception.
2022-04-03gdb/tui: add left_boxed_p and right_boxed_p member functionsAndrew Burgess2-16/+18
When I initially saw this code in tui_layout_split::apply, I assumed that this must be a bug: /* Two adjacent boxed windows will share a border, making a bit more size available. */ if (i > 0 && m_splits[i - 1].layout->bottom_boxed_p () && m_splits[i].layout->top_boxed_p ()) ... After all, the apply might be laying out a horizontal layout, right? So checking bottom_boxed_p and top_boxed_p is clearly wrong. Well, it turns on, that due to the implementations of these things, bottom_boxed_p is equivalent to an imagined right_boxed_p, and top_boxed_p is equivalent to an imagined left_boxed_p. In this commit I've renamed both top_boxed_p and bottom_boxed_p to first_edge_has_border_p and last_edge_has_border_p respectively, and extended the comments in tui_layout_base to mention that these methods handle both horizontal and vertical layouts. Now, hopefully, the code shouldn't look like it only applies for vertical layouts. There should be no user visible changes after this commit.
2022-04-03gdb/tui: add a tui debugging flagAndrew Burgess4-11/+153
This commit adds 'set debug tui on|off' and 'show debug tui'. This commit adds the control variable, and the printing macros in tui/tui.h. I've then added some uses of these in tui.c and tui-layout.c. To help produce more useful debug output in tui-layout.c, I've added some helper member functions in the class tui_layout_split, and also moved the size_info struct out of tui_layout_split::apply into the tui_layout_split class. If tui debug is not turned on, then there should be no user visible changes after this commit. One thing to note is that, due to the way that the tui terminal is often cleared, the only way I've found this useful is when I do: (gdb) tui enable (gdb) set logging file /path/to/file (gdb) set logging debugredirect on (gdb) set logging enable on Additionally, gdb has some quirks when it comes to setting up logging redirect and switching interpreters. Thus, the above only really works if the logging is enabled after the tui is enabled, and disabled again before the tui is disabled. Enabling logging and switching interpreters can cause undefined results, including crashes. This is an existing bug in gdb[1], and has nothing directly to do with tui debug, but it is worth mentioning here I think. [1] https://sourceware.org/bugzilla/show_bug.cgi?id=28948
2022-04-03gdb/tui: add new 'tui window width' command and 'winwidth' aliasAndrew Burgess3-16/+119
This commit adds a new command 'tui window width', and an alias 'winwidth'. This command is equivalent to the old 'winheight' command (which was recently renamed 'tui window height'). Even though I recently moved the old tui commands under the tui namespace, and I would strongly encourage all new tui commands to be added as 'tui ....' only (users can create their own top-level aliases if they want), I'm breaking that suggestion here, and adding a 'winwidth' alias. Given that we already have 'winheight' and have done for years, it just didn't seem right to no have the matching 'winwidth'. You might notice in the test that the window resizing doesn't quite work right. I setup a horizontal layout, then grow and shrink the windows. At the end of the test the windows should be back to their original size... ... they are not. This isn't my fault, honest! GDB's window resizing is a little ... temperamental, and is prone to getting things slightly wrong during resizes, off by 1 type things. This is true for height resizing, as well as the new width resizing. Later patches in this series will rework the resizing algorithm, which should improve things in this area. For now, I'm happy that the width resizing is as good as the height resizing, given the existing quirks. For the docs side I include a paragraph that explains how multiple windows are required before the width can be adjusted. For completeness, I've added the same paragraph to the winheight description. With the predefined layouts this extra paragraph is not really needed for winheight, as there are always multiple windows on the screen. However, with custom layouts, this might not be true, so adding the paragraph seems like a good idea. As for the changes in gdb itself, I've mostly just taken the existing height adjustment code, changed the name to make it generic 'size' adjustment, and added a boolean flag to indicate if we are adjusting the width or the height.
2022-04-03gdb/tui: rename tui_layout_split:set_weights_from_heightsAndrew Burgess2-6/+8
In a following commit I'm going to add the ability to change the width of a tui window (when in a horizontal layout). As a result, some of the places where we currently hard-code references to height need to be changed to handle either height, or width, based on whether we are in a vertical, or horizontal layout. This commit renames set_weights_from_heights to set_weights_from_sizes, and makes the function use either the height, or width as appropriate. Currently, the only place that we call this function is from the tui_layout_split::set_height function, in a part of the code we will only reach for vertical layouts, so the new code is not actually being used, but, this small change will help make later patches smaller, so I'm proposing this as a stand alone change. There should be no user visible changes after this commit.
2022-04-03gdb/tui: rename tui_layout_base::adjust_size to ::set_heightAndrew Burgess2-7/+7
Rename tui_layout_base::adjust_size to tui_layout_base::set_height, the new name more accurately reflects what this member function does, and makes it easier for a later commit to add a new tui_layout_base::set_width member function. There should be no user visible changes after this commit.
2022-04-03gdb: move some commands into the tui namespaceAndrew Burgess2-11/+45
There are a lot of tui related commands that live in the top-level command name space, e.g. layout, focus, refresh, winheight. Having them at the top level means less typing for the user, which is good, but, I think, makes command discovery harder. In this commit, I propose moving all of the above mentioned commands into the tui namespace, so 'layout' becomes 'tui layout', etc. But I will then add aliases so that the old commands will still work, e.g. I'll make 'layout' an alias for 'tui layout'. The benefit I see in this work is that tui related commands can be more easily discovered by typing 'tui ' and then tab-completing. Also the "official" command is now a tui-sub-command, this is visible in, for example, the help output, e.g.: (gdb) help layout tui layout, layout Change the layout of windows. Usage: tui layout prev | next | LAYOUT-NAME List of tui layout subcommands: tui layout asm -- Apply the "asm" layout. tui layout next -- Apply the next TUI layout. tui layout prev -- Apply the previous TUI layout. tui layout regs -- Apply the TUI register layout. tui layout split -- Apply the "split" layout. tui layout src -- Apply the "src" layout. Which I think is a good thing, it makes it clearer that this is a tui command. I've added a NEWS entry and updated the docs to mention the new and old command names, with the new name being mentioned first.
2022-03-29Unify gdb printf functionsTom Tromey3-19/+19
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-29Unify gdb puts functionsTom Tromey1-5/+5
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-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
2022-03-28Switch gdb_stdlog to use timestamped_fileTom Tromey1-2/+6
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-02-16gdb/tui: add a missing white space characterAndrew Burgess1-1/+1
Just adds a missing space. There should be no user visible changes after this commit.
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-06gdb: remove SYMTAB_OBJFILE macroSimon Marchi2-2/+2
Remove the macro, replace with an equivalent method. Change-Id: I8f9ecd290ad28502e53c1ceca5006ba78bf042eb
2022-02-06gdb/tui: add window width information to 'info win' outputAndrew Burgess1-1/+3
Now that we support horizontal window placement in the tui, it makes sense to have 'info win' include the width, as well as the height, of the currently visible windows. That's what this commit does. Example output is now: (gdb) info win Name Lines Columns Focus src 12 40 (has focus) asm 12 41 status 1 80 cmd 11 80 I've added a NEWS entry, but the documentation was already suitably vague, it just says that 'info win' displays the size of the visible windows, so I don't think anything needs to be added there. I've also added some tests, as far as I could find, the 'info win' command was previously untested.
2022-01-28gdb/build: Fix Wpessimizing-move in clang buildEnze Li1-1/+1
When building with clang, I run into an error: ... tui/tui-disasm.c:138:25: error: moving a temporary object prevents copy elision [-Werror,-Wpessimizing-move] tal.addr_string = std::move (gdb_dis_out.release ()); ^ tui/tui-disasm.c:138:25: note: remove std::move call here tal.addr_string = std::move (gdb_dis_out.release ()); ^~~~~~~~~~~ ~ ... The error above is caused by the recent commit 5d10a2041eb8 ("gdb: add string_file::release method"). Fix this by removing std::move. Build on x86_64-linux with clang 13.0.0.
2022-01-26gdb: add string_file::release methodSimon Marchi3-8/+8
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-05Use filtered output in ordinary commandsTom Tromey1-6/+6
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-01Automatic Copyright Year update after running gdb/copyright.pyJoel Brobecker33-33/+33
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-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-17gdb/tui: install SIGWINCH only when connected to a TTYLancelot SIX1-2/+8
PR26056 reports that when GDB is connected to non-TTY stdin/stdout, it crashes when it receives a SIGWINCH signal. This can be reproduced as follows: $ gdb/gdb -nx -batch -ex 'run' --args sleep 60 </dev/null 2>&1 | cat # from another terminal: $ kill -WINCH %(pidof gdb) When doing so, the process crashes in a call to rl_resize_terminal: void rl_resize_terminal (void) { _rl_get_screen_size (fileno (rl_instream), 1); ... } The problem is that at this point rl_instream has the value NULL. The rl_instream variable is supposed to be initialized during a call to readline_initialize_everything, which in a normal startup sequence is called under this call chain: tui_interp::init tui_ensure_readline_initialized rl_initialize readline_initialize_everything In tui_interp::init, we have the following sequence: tui_initialize_io (); tui_initialize_win (); // <- Installs SIGWINCH if (gdb_stdout->isatty ()) tui_ensure_readline_initialized (); // <- Initializes rl_instream This function unconditionally installs the SIGWINCH signal handler (this is done by tui_initialize_win), and then if gdb_stdout is a TTY it initializes readline. Therefore, if stdout is not a TTY, SIGWINCH is installed but readline is not initialized. In such situation rl_instream stays NULL, and when GDB receives a SIGWINCH it calls its handler and in fine tries to access rl_instream leading to the crash. This patch proposes to fix this issue by installing the SIGWINCH signal handler only if GDB is connected to a TTY. Given that this initialization it the only task of tui_initialize_win, this patch moves tui_initialize_win just after the call to tui_ensure_readline_initialized. Tested on x86_64-linux. Co-authored-by: Pedro Alves <pedro@palves.net> Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=26056 Change-Id: I6458acef7b0d9beda2a10715d0345f02361076d9