aboutsummaryrefslogtreecommitdiff
path: root/gdb/testsuite/gdb.tui
AgeCommit message (Collapse)AuthorFilesLines
2023-07-21[gdb/tui] Fix superfluous newline for long promptTom de Vries1-17/+1
In test-case gdb.tui/long-prompt.exp, with a prompt of 40 chars, the same size as the terminal width, we get a superfluous newline at line 19: ... 16 (gdb) set prompt 123456789A123456789B123 17 456789C123456789> 18 123456789A123456789B123456789C123456789> 19 20 123456789A123456789B123456789C123456789> 21 set prompt (gdb) 22 (gdb) ... as well as a superfluous repetition of the prompt at line 20 once we type the 's' starting "set prompt". I traced the superfluous newline back to readline's readline_internal_setup, that does: ... /* If we're not echoing, we still want to at least print a prompt, because rl_redisplay will not do it for us. If the calling application has a custom redisplay function, though, let that function handle it. */ if (_rl_echoing_p == 0 && rl_redisplay_function == rl_redisplay) ... else { if (rl_prompt && rl_already_prompted) rl_on_new_line_with_prompt (); else rl_on_new_line (); (*rl_redisplay_function) (); ... and then we hit the case that calls rl_on_new_line_with_prompt, which does: ... /* If the prompt length is a multiple of real_screenwidth, we don't know whether the cursor is at the end of the last line, or already at the beginning of the next line. Output a newline just to be safe. */ if (l > 0 && (l % real_screenwidth) == 0) _rl_output_some_chars ("\n", 1); ... This doesn't look like a readline bug, because the behaviour matches the comment. [ And the fact that the output of the newline doesn't happen in the scope of tui_redisplay_readline means it doesn't get the prompt wrap detection treatment, causing start_line to be incorrect, which causes the superfluous repetition of the prompt. ] I looked at ways to work around this, and managed by switching off rl_already_prompted, which we set to 1 in tui_rl_startup_hook: ... /* Readline hook to redisplay ourself the gdb prompt. In the SingleKey mode, the prompt is not printed so that the command window is cleaner. It will be displayed if we temporarily leave the SingleKey mode. */ static int tui_rl_startup_hook (void) { rl_already_prompted = 1; if (tui_current_key_mode != TUI_COMMAND_MODE && !gdb_in_secondary_prompt_p (current_ui)) tui_set_key_mode (TUI_SINGLE_KEY_MODE); tui_redisplay_readline (); return 0; } ... Then I started looking at why rl_already_prompted is set to 1. The use case for rl_already_prompted seems to be: - app (application, the readline user) outputs prompt, - app sets rl_already_prompted to 1, and - app calls readline, which calls rl_on_new_line_with_prompt, which figures out how long the prompt is, and sets a few readline variables accordingly, which can be used in the following call to rl_redisplay_function. AFAICT, TUI does not fit this pattern. It does not output an initial prompt, rather it writes the prompt in every rl_redisplay_function. It doesn't use the variables set by rl_on_new_line_with_prompt, instead it figures stuff out by itself. Fix this by removing the rl_already_prompted setting. Also remove the call to tui_redisplay_readline, it's not necessary, the function is called anyway. Tested on x86_64-linux, no regressions.
2023-06-21[gdb/testsuite] Add have_host_localeTom de Vries1-0/+1
With test-case gdb.tui/pr30056.exp, I run into: ... sh: warning: setlocale: LC_ALL: cannot change locale (C.UTF-8)^M ... and then subsequently into: ... WARNING: timeout in accept_gdb_output FAIL: gdb.tui/pr30056.exp: Control-C ... This is on a CentOS 7 distro for powerpc64le. Either it has no C.UTF-8 support, or it's not installed: ... $ locale -a | grep ^C C $ ... Fix this by: - adding a new proc have_host_locale, and - using it in all test-cases using setenv LC_ALL. Tested on powerpc64le-linux and x86_64-linux.
2023-06-21[gdb/testsuite] Fix gdb.tui/wrap-line.expTom de Vries1-2/+8
PR testsuite/30458 reports the following FAIL: ... PASS: gdb.tui/wrap-line.exp: width-auto-detected: cli: wrap ^CQuit (gdb) WARNING: timeout in accept_gdb_output Screen Dump (size 50 columns x 24 rows, cursor at column 6, row 3): 0 Quit 1 (gdb) 7890123456789012345678901234567890123456789 2 W^CQuit 3 (gdb) ... FAIL: gdb.tui/wrap-line.exp: width-auto-detected: cli: prompt after wrap ... The problem is that the regexp doesn't account for the ^C: ... gdb_assert { [Term::wait_for "^WQuit"] } "prompt after wrap" ... The ^C occurs occasionally. This is something we'd like to fix. It's reported as a readline problem here ( https://lists.gnu.org/archive/html/bug-readline/2023-06/msg00000.html ). For now, fix this by updating the regexp, and likewise in another place in the test-case where we use ^C. Tested on x86_64-linux. Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=30458
2023-06-21[gdb/testsuite] Make Term::wait_for "" match only a promptTom de Vries1-0/+13
The semantics of Term::wait_for is: ... # Accept some output from gdb and update the screen. WAIT_FOR is # a regexp matching the line to wait for. Return 0 on timeout, 1 # on success. proc wait_for {wait_for} { ... Note that besides the regexp, also a subsequent gdb prompt is matched. I recently used wait_for "" in a few test-cases, thinking that this would match just a prompt, but in fact that's not the case. Fix this in wait_for, and add a corresponding test in gdb.tui/tuiterm-2.exp. Tested on x86_64-linux.
2023-06-13[gdb/testsuite] Fix gdb.tui/long-prompt.exp with read1Tom de Vries1-4/+1
When running test-case gdb.tui/long-prompt.exp with check-read1, we get: ... (gdb) FAIL: gdb.tui/long-prompt.exp: prompt size == width + 1: \ end of screen: at last line ... The problem is in these commands: ... Term::command "echo \\n" Term::command "echo \\n" Term::command "echo \\n" Term::command "echo \\n" ... The last one makes the terminal scroll, and the scrolling makes the expected output match on a different line. Fix this by replacing the sequence with a single command: ... Term::command "echo \\n\\n\\n\\n\\n\\n" ... which avoids scrolling. Tested on x86_64-linux.
2023-06-13[gdb/testsuite] Fix and add prompt anchoring in tuitermTom de Vries1-0/+98
There is a test-case that contains a unit test for tuiterm: gdb.tui/tuiterm.exp. However, this only excercises the tuiterm itself, and not the functions that interact with it, like Term::command. Add a new test-case gdb.tui/tuiterm-2.exp that: - overrides proc accept_gdb_output (to be able simulate incorrect responses while avoiding the timeout), - overrides proc send_gdb (to be able to call Term::command without a gdb instance, such that all tuiterm input is generated by the test-case). - issues Term::command calls, and - checks whether they behave correctly. This exposes a problem in Term::command. The "prompt before command" regexp starts with a bit that is supposed to anchor the prompt to the border: ... set str "(^|\|)$gdb_prompt $str" ... but that doesn't work due to insufficient escaping. Fix this by adding the missing escape: ... set str "(^|\\|)$gdb_prompt $str" ... Futhermore, the "prompt after command" regexp in Term::wait_for has no anchoring at all: ... set prompt_wait_for "$gdb_prompt \$" ... so add that as well. Tested on x86_64-linux.
2023-06-09[gdb/tui] Delete line buffer when switching to singlekeyTom de Vries1-0/+40
Say we're in TUI mode, and type "sun": ... (gdb) sun ... After switching to SingleKey mode using C-x s, we have just: ... sun ... After typing "d", we get: ... sun Undefined command: "sundown". Try "help". ... The SingleKey "d" is supposed run the "down" command. Fix this by clearing the readline line buffer when switching to SingleKey mode. Tested on x86_64-linux. PR tui/30522 Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=30522 Reviewed-By: Tom Tromey <tom@tromey.com>
2023-06-09[gdb/testsuite] Add test-case gdb.tui/single-key.expTom de Vries1-0/+60
I noticed that there's no test-case excercising SingleKey mode, so add a test-case. Tested on x86_64-linux. Reviewed-By: Tom Tromey <tom@tromey.com>
2023-06-09[gdb/testsuite] Add test-case gdb.tui/long-prompt.expTom de Vries1-0/+158
I noticed that the test-suite doesn't excercise the case in tui_redisplay_readline that height (initially 1) is changed by this call: ... tui_puts_internal (w, prompt, &height); ... Add a test-case that excercises this. Tested on x86_64-linux.
2023-05-31[gdb/testsuite] Fix gdb.tui/wrap-line.exp with --disable-tuiTom de Vries1-2/+4
When running the test-case gdb.tui/wrap-line.exp with a build configured with --disable-tui, we run into: ... (gdb) PASS: gdb.tui/wrap-line.exp: width-hard-coded: set width 50 tui new-layout command-layout cmd 1^M Undefined command: "tui". Try "help".^M (gdb) ERROR: Undefined command "tui new-layout command-layout cmd 1". ... Fix this by guarding the command with allow_tui_tests. Tested on x86_64-linux.
2023-05-31[gdb/testsuite] Fix gdb.tui/pr30056.exp for native-extended-gdbserverTom de Vries1-0/+31
When running test-case gdb.tui/pr30056.exp with target board native-extended-gdbserver, I run into: ... Quit^[[K^M^[[B(gdb) PASS: gdb.tui/pr30056.exp: Control-C Remote debugging from host ::1, port 38810^M ^M(failed reverse-i-search)`xyz': ^M(gdb) target extended-remote \ localhost:2346^[[7GWARNING: Timed out waiting for EOF in server after \ monitor exit ... This is due to the fact that ^C doesn't abort the reverse-i-search. This appears to be due to a readline problem. A PR is open about this: PR cli/30498. Add a KFAIL for the PR, and ensure that the isearch is aborted by using ^G, such that we have a responsive prompt to handle the "monitor exit" command that native-extended-gdbserver issues. Tested on x86_64-linux.
2023-05-31[gdb/tui] Fix fingerprint for cmd-only layoutTom de Vries1-0/+9
I added a cmd-only layout: ... (gdb) tui new-layout cmd cmd 1 ... and set it: ... (gdb) layout cmd ... which gave me the expect result: only the cmd window in the screen. However, after going back to layout src: ... (gdb) layout src ... I got a source window with only one line in it, and the cmd window taking most of the screen. I traced this back to tui_set_layout, where for both the old and the new layout the fingerprint of the cmd window in the layout is taken. If the fingerprint is the same, an effort will be done to preserve the command window size. The fingerprint is "VC" for both the old (cmd) and new (src) layouts, which explains the behaviour. I think this is essentially a bug in the finger print calculation, and it should be "C" for the cmd layout. Fix this by not adding a V or H in the fingerprint if the list size is one. Tested on x86_64-linux. Reviewed-By: Tom Tromey <tom@tromey.com>
2023-05-30[gdb] Mention --with/without-system-readline for --configurationTom de Vries1-0/+4
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-29[gdb/testsuite] Fix linefeed scrolling in tuitermTom de Vries1-0/+13
I came across a bug in the implementation of line feed in tuiterm, and added a unit test that exposes it. Before sending the line feed we have: ... Screen Dump (size 8 columns x 4 rows, cursor at column 0, row 3): 0 abcdefgh 1 ijklmnop 2 qrstuvwx 3 yz01234 ... and after it we have: ... Screen Dump (size 8 columns x 4 rows, cursor at column 0, row 1): 0 ijklmnop 1 qrstuvwx 2 yz01234 3 yz01234 ... Note how the cursor started at row 3 and after the line feed ended up at row 1, while it should have stayed in row 3. Fix this by moving "incr _cur_row -1" one level up in the loop nest in proc _ctl_0x0a. Tested on x86_64-linux.
2023-05-28[readline] Fix double free in _rl_scxt_disposeTom de Vries1-0/+52
Consider the following scenario. We start gdb in TUI mode: ... $ gdb -q -tui ... and type ^R which gives us the reverse-isearch prompt in the cmd window: ... (reverse-i-search)`': ... and then type "foo", right-arrow-key, and ^C. In TUI mode, gdb uses a custom rl_getc_function tui_getc. When pressing the right-arrow-key, tui_getc: - attempts to scroll the TUI src window, without any effect, and - returns 0. The intention of returning 0 is mentioned here in tui_dispatch_ctrl_char: ... /* We intercepted the control character, so return 0 (which readline will interpret as a no-op). */ return 0; ... However, after this 0 is returned by the rl_read_key () call in _rl_search_getchar, _rl_read_mbstring is called, which incorrectly interprets 0 as the first part of an utf-8 multibyte char, and tries to read the next char. In this state, the ^C takes effect and we run into a double free because _rl_isearch_cleanup is called twice. Both these issues need fixing independently, though after fixing the first we no longer trigger the second. The first issue is caused by the subtle difference between: - a char array containing 0 chars, which is zero-terminated, and - a char array containing 1 char, which is zero. In mbrtowc terms, this is the difference between: ... mbrtowc (&wc, "", 0, &ps); ... which returns -2, and: ... mbrtowc (&wc, "", 1, &ps); ... which returns 0. Note that _rl_read_mbstring calls _rl_get_char_len without passing it an explicit length parameter, and consequently it cannot distinguish between the two, and defaults to the "0 chars" choice. Note that the same problem doesn't exist in _rl_read_mbchar. Fix this by defaulting to the "1 char" choice in _rl_get_char_len: ... - if (_rl_utf8locale && l > 0 && UTF8_SINGLEBYTE(*src)) + if (_rl_utf8locale && l >= 0 && UTF8_SINGLEBYTE(*src)) ... The second problem happens when the call to _rl_search_getchar in _rl_isearch_callback returns. At that point _rl_isearch_cleanup has already been called from the signal handler, but we proceed regardless, using a cxt pointer that has been freed. Fix this by checking for "RL_ISSTATE (RL_STATE_ISEARCH)" after the call to _rl_search_getchar: ... c = _rl_search_getchar (cxt); + if (!RL_ISSTATE (RL_STATE_ISEARCH)) + return 1; ... Tested on x86_64-linux. Approved-By: Chet Ramey <chet.ramey@case.edu> PR tui/30056 Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=30056
2023-05-26[gdb/testsuite] Add test-case gdb.tui/color-prompt.expTom de Vries2-1/+55
Add a test-case that sets a prompt with color in TUI. The line containing the prompt is shown by get_line_with_attrs as follows: ... <fg:31>(gdb) <fg:default> ... The 31 means red, but only for foreground colors, for background colors 41 means red. Make this more readable by using color names for both foreground and background, such that we have instead: .... <fg:red>(gdb) <fg:default> ... Tested on x86_64-linux.
2023-05-26[gdb/testsuite] Add invisible and blinking attributes in tuitermTom de Vries1-0/+8
I noticed curses using the invisible and blinking attributes. Add these in tuiterm. Tested on x86_64-linux.
2023-05-26[gdb/testsuite] Fix reverse attribute in tuitermTom de Vries1-0/+36
I noticed in proc Term::_csi_m arguments that while parameters 7 and 27 are supposed to set the reverse attribute to 1 and 0, in fact it's set to 1 in both cases: ... 7 { set _attrs(reverse) 1 } ... 27 { set _attrs(reverse) 1 } ... Fix this and add a regression test in gdb.tui/tuiterm.exp. Tested on x86_64-linux.
2023-05-22[gdb/testsuite] Add Term::get_line_with_attrsTom de Vries1-0/+8
Add a new proc Term::get_line_with_attrs, similar to Term::get_line, that annotates a tuiterm line with the active attributes. For instance, the line representing the TUI status window with attribute mode standout looks like this with Term::get_line: ... exec No process In: ... L?? PC: ?? ... but like this with Term::get_line_with_attrs: ... <reverse:1>exec No process In: ... L?? PC: ?? <reverse:0> ... Also add Term::dump_screen_with_attrs, a Term::dump_screen variant that uses Term::get_line_with_attrs instead of Term::get_line. Tested by re-running the TUI test-cases (gdb.tui/*.exp and gdb.python/tui*.exp) on x86_64-linux.
2023-05-16[gdb/tui] Don't show line number for lines not in source fileTom de Vries1-16/+12
Currently, for a source file containing only 5 lines, we also show line numbers 6 and 7 if they're in scope of the source window: ... 0 +-compact-source.c----------------+ 1 |___3_{ | 2 |___4_ return 0; | 3 |___5_} | 4 |___6_ | 5 |___7_ | 6 +---------------------------------+ ... Fix this by not showing line numbers not in a source file, such that we have instead: ... 0 +-compact-source.c----------------+ 1 |___3_{ | 2 |___4_ return 0; | 3 |___5_} | 4 | | 5 | | 6 +---------------------------------+ ... Tested on x86_64-linux. Suggested-By: Simon Marchi <simon.marchi@efficios.com> Approved-By: Tom Tromey <tom@tromey.com>
2023-05-12gdb/testsuite: extend special '^' handling to gdb_test_multipleAndrew Burgess1-2/+1
The commit: commit 08ec06d6440745ef9204d39197aa1e732df41056 Date: Wed Mar 29 10:41:07 2023 +0100 gdb/testsuite: special case '^' in gdb_test pattern Added some special handling of '^' to gdb_test -- a leading '^' will cause the command regexp to automatically be included in the expected output pattern. It was pointed out that the '-wrap' flag of gdb_test_multiple is supposed to work in the same way as gdb_test, and that the recent changes for '^' had not been replicated for gdb_test_multiple. This patch addresses this issue. So, after this commit, the following two constructs should have the same meaning: gdb_test "command" "^output" "test name" gdb_test_multiple "command" "test name" { -re -wrap "^output" { pass $gdb_test_name } } In both cases the '^' will case gdb.exp to inject a regexp that matches 'command' after the '^' and before the 'output', this is in addition to adding the $gdb_prompt pattern after 'output' in the normal way. The special '^' handling is only applied when '-wrap' is used, as this is the only mode that aims to mimic gdb_test. While working on this patch I realised that I could actually improve the logic for the special '^' handling in the case where the expected output pattern is empty. I replicated these updates for both gdb_test and gdb_test_multiple in order to keep these two paths in sync. There were a small number of tests that needed adjustment after this change, mostly just removing command regexps that are now added automatically, but the gdb.base/settings.exp case was a little weird as it turns out trying to match a single blank line is probably harder now than it used to be -- still, I suspect this is a pretty rare case, so I think the benefits (improved anchoring) outweigh this small downside (IMHO).
2023-05-12[gdb/cli] Fix wrapping for TERM=ansiTom de Vries1-6/+0
I. Auto-detected width (xterm vs. ansi) Say we have a terminal with a width of 40 chars: ... $ echo $COLUMNS 40 ... With TERM=xterm, we report a width of 40 chars: ... $ TERM=xterm gdb (gdb) show width Number of characters gdb thinks are in a line is 40. ... And with TERM=ansi, a width of 39 chars: ... $ TERM=ansi gdb (gdb) show width Number of characters gdb thinks are in a line is 39. ... Gdb uses readline to auto-detect screen size, and readline decides in the TERM=ansi case that the terminal does not have reliable auto-wrap, and consequently decides to hide the last terminal column from the readline user (in other words GDB), hence we get 39 instead of 40. II. Types of wrapping Looking a bit more in detail inside gdb, it seems there are two types of wrapping: - readline wrapping (in other words, prompt edit wrapping), and - gdb output wrapping (can be observed by issuing "info sources"). This type of wrapping attempts to wrap some of the gdb output earlier than the indicated width, to not break lines in inconvenient places. III. Readline wrapping, auto-detected screen size Let's investigate readline wrapping with the auto-detected screen widths. First, let's try with xterm: ... $ TERM=xterm gdb (gdb) 7890123456789012345678901234567890 123 ... That looks as expected, wrapping occurs after 40 chars. Now, let's try with ansi: ... $ TERM=ansi gdb (gdb) 78901234567890123456789012345678 90123 ... It looks like wrapping occurred after 38, while readline should be capable of wrapping after 39 chars. This is caused by readline hiding the last column, twice. In more detail: - readline detects the screen width: 40, - readline hides the last column, setting the readline screen width to 39, - readline reports 39 to gdb as screen width, - gdb sets its width setting to 39, - gdb sets readline screen width to 39, - readline hides the last column, again, setting the readline screen width to 38. This is reported as PR cli/30346. IV. gdb output wrapping, auto-detected screen size Say we set the terminal width to 56. With TERM=xterm, we have: ... /home/abuild/rpmbuild/BUILD/glibc-2.31/csu/elf-init.c, /data/vries/hello.c, ... but with TERM=ansi: ... /home/abuild/rpmbuild/BUILD/glibc-2.31/csu/elf-init.c, / data/vries/hello.c, ... So what happened here? With TERM=ansi, the width setting is auto-detected to 55, and gdb assumes the terminal inserts a line break there, which it doesn't because the terminal width is 56. This is reported as PR cli/30411. V. Fix PRs Fix both mentioned PRs by taking into account the hidden column when readline reports the screen width in init_page_info, and updating chars_per_line accordingly. Note that now we report the same width for both TERM=xterm and TERM=ansi, which is much clearer. The point where readline respectively expects or ensures wrapping is still indicated by "maint info screen", for xterm: ... Number of characters readline reports are in a line is 40. ... and ansi: ... Number of characters readline reports are in a line is 39. ... VI. Testing PR cli/30346 is covered by existing regression tests gdb.base/wrap-line.exp and gdb.tui/wrap-line.exp, so remove the KFAILs there. I didn't manage to come up with a regression test for PR cli/30411. Perhaps that would be easier if we had a maintenance command that echoes its arguments while applying gdb output wrapping. Tested on x86_64-linux. PR cli/30346 PR cli/30411 Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=30346 Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=30411
2023-05-10[gdb/tui] Fix tui compact-source a bit moreTom de Vries1-15/+28
Andrew pointed out that the behaviour as tested in gdb.tui/compact-source.exp is incorrect: ... 0 +-compact-source.c--------------------------------------------------------+ 1 |___3_{ | 2 |___4_ return 0; | 3 |___5_} | 4 |___6_ | 5 |___7_ | 6 |___8_ | 7 |___9_ | 8 +-------------------------------------------------------------------------+ ... The last line number in the source file is 5, and there are 7 lines to display source lines, so if we'd scroll all the way down, the first line number in the source window would be 5, and the last one would be 11. To represent 11 we'd need 2 digits, so we expect to see ___04_ here instead of ___4_, even though all line numbers currently in the src window (3-9) can be represented with only 1 digit. Fix this in tui_source_window::set_contents, by updating the computation of max_line_nr: ... - int max_line_nr = std::max (lines_in_file, last_line_nr_in_window); + int max_line_nr = lines_in_file + nlines - 1; ... Tested on x86_64-linux. Co-Authored-By: Andrew Burgess <aburgess@redhat.com> Approved-By: Tom Tromey <tom@tromey.com>
2023-05-10[gdb/tui] Fix tui compact-sourceTom de Vries1-0/+61
Consider a hello.c, with less than 10 lines: ... $ wc -l hello.c 8 hello.c ... and compiled with -g into an a.out. With compact-source off: ... $ gdb -q a.out \ -ex "set tui border-kind ascii" \ -ex "maint set tui-left-margin-verbose on" \ -ex "set tui compact-source off" \ -ex "tui enable" ... we get: ... +-./data/hello.c-----------------------+ |___000005_{ | |___000006_ printf ("hello\n"); | |___000007_ return 0; | |___000008_} | |___000009_ | |___000010_ | |___000011_ | ... but with compact-source on: ... +-./data/hello.c-----------------------+ |___5{ | |___6 printf ("hello\n"); | |___7 return 0; | |___8} | |___9 | |___1 | |___1 | ... There are a couple of problems with compact-source. First of all the documentation mentions: ... The default display uses more space for line numbers and starts the source text at the next tab stop; the compact display uses only as much space as is needed for the line numbers in the current file, and only a single space to separate the line numbers from the source. ... The bit about the default display and the next tab stop looks incorrect. The source doesn't start at a tab stop, instead it uses a single space to separate the line numbers from the source. Then the documentation mentions that there's single space in the compact display, but evidently that's missing. Then there's the fact that the line numbers "10" and "11" are both abbreviated to "1" in the compact case. The abbreviation is due to allocating space for <lines in source>, which is 8 for this example, and takes a single digit. The line numbers though continue past the end of the file, so fix this by allocating space for max (<lines in source>, <last line in window>), which in this example takes 2 digits. The missing space is due to some confusion about what the "1" here in tui_source_window::set_contents represent: ... double l = log10 ((double) offsets->size ()); m_digits = 1 + (int) l; ... It could be the trailing space that's mentioned in tui-source.h: ... /* How many digits to use when formatting the line number. This includes the trailing space. */ int m_digits; ... Then again, it could be part of the calculation for the number of digits needed for printing. With this minimal example: ... int main () { for (int i = 8; i <= 11; ++i) { double l = log10 ((double) i); printf ("%d %d\n", i, (int)l); } return 0; } ... we get: ... $ ./a.out 8 0 9 0 10 1 11 1 ... which shows that the number of digits needed for printing i is "1 + (int)log10 ((double) i)". Fix this by introducing named variables needed_digits and trailing_space, each adding 1. With the fixes, we get for compact-source on: ... +-./data/hello.c-----------------------+ |___05_{ | |___06_ printf ("hello\n"); | |___07_ return 0; | |___08_} | |___09_ | |___10_ | |___11_ | |... Also fix the documentation and help text to actually match effect of compact-source. Tested on x86_64-linux.
2023-05-05[gdb/testsuite] Add gdb.tui/wrap-line.expTom de Vries1-0/+163
Add a test-case that tests prompt edit wrapping behaviour in the tuiterm, both for CLI and TUI, both with auto-detected and hard-coded width. In the CLI case with auto-detected width we run into PR cli/30411, so add a KFAIL for that failure mode. Tested on x86_64-linux.
2023-04-30[gdb/tui] Fix TUI resizing for TERM=ansiTom de Vries1-0/+89
With TERM=ansi, when resizing a TUI window from LINES/COLUMNS 31/118 (maximized) to 20/78 (de-maximized), I get a garbled screen (that ^L doesn't fix) and a message: ... @@ resize done 0, size = 77x20 ... with the resulting width being 77 instead of the expected 78. [ The discrepancy also manifests in CLI, filed as PR30346. ] The discrepancy comes from tui_resize_all, where we ask readline for the screen size: ... rl_get_screen_size (&screenheight, &screenwidth); ... As it happens, when TERM is set to ansi, readline decides that the terminal cannot auto-wrap lines, and reserves one column to deal with that, and as a result reports back one less than the actual screen width: ... $ echo $COLUMNS 78 $ TERM=xterm gdb -ex "show width" -ex q Number of characters gdb thinks are in a line is 78. $ TERM=ansi gdb -ex "show width" -ex q Number of characters gdb thinks are in a line is 77. ... In tui_resize_all, we need the actual screen width, and using a screenwidth of one less than the actual value garbles the screen. This is currently not causing trouble in testing because we have a workaround in place in proc Term::resize. If we disable the workaround: ... - stty columns [expr {$_cols + 1}] < $::gdb_tty_name + stty columns $_cols < $::gdb_tty_name ... and dump the screen we get the same type of screen garbling: ... 0 +---------------------------------------+| 1 || 2 || 3 || ... Another way to reproduce the problem is using command "maint info screen". After starting gdb with TERM=ansi, entering TUI, and issuing the command, we get: ... Number of characters curses thinks are in a line is 78. ... and after maximizing and demaximizing the window we get: ... Number of characters curses thinks are in a line is 77. ... If we use TERM=xterm, we do get the expected 78. Fix this by: - detecting when readline will report back less than the actual screen width, - accordingly setting a new variable readline_hidden_cols, - using readline_hidden_cols in tui_resize_all to fix the resize problem, and - removing the workaround in Term::resize. The test-case gdb.tui/empty.exp serves as regression test. I've applied the same fix in tui_async_resize_screen, the new test-case gdb.tui/resize-2.exp serves as a regression test for that change. Without that fix, we have: ... FAIL: gdb.tui/resize-2.exp: again: gdb width 80 ... Tested on x86_64-linux. PR tui/30337 Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=30337
2023-04-29[gdb/testsuite] Fix gdb.tui/main.exp without TUITom de Vries1-0/+2
With a build with --disable-tui, we get: ... (gdb) PASS: gdb.tui/main.exp: set interactive-mode off maint set tui-left-margin-verbose on^M Undefined maintenance set command: "tui-left-margin-verbose on". \ Try "help maintenance set".^M (gdb) FAIL: gdb.tui/main.exp: maint set tui-left-margin-verbose on ... Fix this by adding the missing "require allow_tui_tests". Tested on x86_64-linux.
2023-04-25[gdb/testsuite] Fix timeout in gdb.tui/completion.expTom de Vries1-1/+1
With test-case gdb.tui/completion.exp, we run into: ... WARNING: timeout in accept_gdb_output PASS: gdb.tui/completion.exp: check focus completions ... The timeout happens in this command: ... Term::command "layout src" ... which waits for: - "(gdb) layout src", and then - "(gdb) ". Because the "layout src" command enables the TUI there's just a prompt. Fix this by using Term::command_no_prompt_prefix. Tested on x86_64-linux.
2023-04-25[gdb/testsuite] Fix timeout in gdb.tui/main.expTom de Vries1-1/+2
With test-case gdb.tui/main.exp we run into: ... WARNING: timeout in accept_gdb_output PASS: gdb.tui/main.exp: show main after file ... The problem is that this command: ... Term::command "file [standard_output_file $testfile]" ... tries to match "(gdb) $cmd", but due to the long file name, $cmd is split up over two lines: ... 16 (gdb) file /data/vries/gdb/leap-15-4/build/gdb/testsuite/outputs/gdb.tui/main/ma 17 in 18 Reading symbols from /data/vries/gdb/leap-15-4/build/gdb/testsuite/outputs/gdb.t 19 ui/main/main... 20 (gdb) ... Fix this by matching "Reading symbols from" instead. Tested on x86_64-linux.
2023-04-25[gdb/testsuite] Fix timeout in gdb.tui/corefile-run.expTom de Vries1-1/+2
With test-case gdb.tui/corefile-run.exp we run into: ... WARNING: timeout in accept_gdb_output PASS: gdb.tui/corefile-run.exp: load corefile ... The timeout happens in this command: ... Term::command "core-file $core" ... because it tries to match "(gdb) $cmd" but $cmd is split over two lines: ... 16 (gdb) core-file /data/vries/gdb/leap-15-4/build/gdb/testsuite/outputs/gdb.tui/co 17 refile-run/corefile-run.core 18 [New LWP 5370] 19 Core was generated by `/data/vries/gdb/leap-15-4/build/gdb/testsuite/outputs/gdb 20 .tui/corefile-run/coref'. 21 Program terminated with signal SIGTRAP, Trace/breakpoint trap. 22 #0 main () at tui-layout.c:21 23 (gdb) ... Fix this by using send_gdb "$cmd\n" and wait_for "Program terminated" instead. Tested on x86_64-linux.
2023-04-14[gdb/testsuite] Add regression test for PR30325Tom de Vries2-3/+17
Add regression tests for PR30325, one for the asm window and one for the source window. Use maint set tui-left-margin verbose to make the extend of the left margin clear. Tested on x86_64-linux. Approved-By: Andrew Burgess <aburgess@redhat.com>
2023-03-13[gdb/testsuite] Fix gdb.tui/completion.exp for local-remote-host-nottyTom de Vries1-5/+8
When running test-case gdb.tui/completion.exp with host board local-remote-host-notty and target board native-gdbserver, I get: ... FAIL: gdb.tui/completion.exp: completion of layout names: \ tab completion (timeout) ... The test-case contains a few tests that do tab completion, which requires readline, which is unavailable with host board local-remote-host-notty. Fix this by adding the missing check for readline_is_used. Tested on x86_64-linux.
2023-03-13[gdb/testsuite] Fix gdb.tui/tui-layout.exp for remote hostTom de Vries1-0/+4
When running test-case gdb.tui/tui-layout.exp with host board local-remote-host-notty and target board native-gdbserver, I get: ... FAIL: gdb.tui/tui-layout.exp: terminal=dumb: execution=false: layout=asm: \ layout asm (timeout) ... The problem is that the test-case expects that the default "setenv TERM dumb" has effect, which is not the case for remote host. Fix this by skipping the test for remote host. Tested on x86_64-linux.
2023-03-13[gdb/testsuite] Fix gdb.tui/tui-nl-filtered-output.exp for remote hostTom de Vries1-1/+4
When running test-case gdb.tui/tui-nl-filtered-output.exp with host board local-remote-host-notty and target board native-gdbserver, I get: ... FAIL: gdb.tui/tui-nl-filtered-output.exp: check printf output ... The problem is that Term::enter_tui is returning 0, but the test-case doesn't check for this, and consequently runs unsupported tests. Fix this by adding the missing check. Tested on x86_64-linux.
2023-03-13[gdb/testsuite] Handle USE_TUI in gdb.tui/corefile-run.expTom de Vries1-3/+15
Once in a while I find myself rewriting a TUI test-case into a non-TUI test-case, to better understand whether the problem I'm looking at is related to the TUI or not. I've got the impression that I've done this sufficiently often that it's worth committing the non-TUI version, so having just written a non-TUI version of gdb.tui/corefile-run.exp, let's commit it. The non-TUI version can be enabled by doing: ... $ make check "RUNTESTFLAGS=gdb.tui/corefile-run.exp USE_TUI=0" ... Also remove hard-coding of a source line number. Tested on x86_64-linux.
2023-03-13[gdb/testsuite] Fix untested message in gdb.tui/corefile-run.expTom de Vries1-5/+1
In test-case gdb.tui/corefile-run.exp, we have this bit: ... require !use_gdb_stub if { [target_info gdb_protocol] == "extended-remote" } { untested "not supported" return } ... So with target board native-gdbserver we get: ... UNSUPPORTED: gdb.tui/corefile-run.exp: require failed: !use_gdb_stub ... and with target board native-extended-gdbserver instead: ... UNTESTED: gdb.tui/corefile-run.exp: not supported ... Fix this by: - adding an optional argument target_description to proc target_can_use_run_cmd - handling the target_description == core && [target_info gdb_protocol] == "extended-remote" case in the proc - using require {target_can_use_run_cmd core} such that now in both cases we have: ... UNSUPPORTED: gdb.tui/corefile-run.exp: require failed: \ target_can_use_run_cmd core ... Tested on x86_64-linux.
2023-03-10Use require with target_infoTom Tromey1-3/+1
This changes many tests to use 'require' when checking target_info. In a few spots, the require is hoisted to the top of the file, to avoid doing any extra work when the test is going to be skipped anyway.
2023-01-27gdb/tui: rewrite of tui_source_window_base to handle very long linesAndrew Burgess1-5/+1
This commit addresses an issue that is exposed by the test script gdb.tui/tui-disasm-long-lines.exp, that is, tui_source_window_base does not handle very long lines. The problem can be traced back to the newpad call in tui_source_window_base::show_source_content, this is where we allocate a backing pad to hold the window content. Unfortunately, there appears to be a limit to the size of pad that can be allocated, and the gdb.tui/tui-disasm-long-lines.exp test goes beyond this limit. As a consequence the newpad call fails and returns nullptr. It just so happens that the reset of the tui_source_window_base code can handle the pad being nullptr (this happens anyway when the window is first created, so we already depend on nullptr handling), so all that happens is the source window displays no content. ... well, sort of ... something weird does happen in the command window, we seem to see a whole bunch of blank lines. I've not bothered to track down exactly what's happening there, but it's some consequence of GDB attempting to write content to a WINDOW* that is nullptr. Before explaining my solution, I'll outline how things currently work: Consider we have the following window content to display: aaaaaaaaaa bbbbbbbbbbbbbbbbbbbb ccccccccccccccc the longest line here is 20 characters. If our display window is 10 characters wide, then we will create a pad that is 20 characters wide, and then copy the lines of content into the pad: .--------------------. |aaaaaaaaaa | |bbbbbbbbbbbbbbbbbbbb| |ccccccccccccccc | .--------------------. Now we will copy a 10 character wide view into this pad to the display, our display will then see: .----------. |aaaaaaaaaa| |bbbbbbbbbb| |cccccccccc| .----------. As the user scrolls left and right we adjust m_horizontal_offset and use this to select which part of the pad is copied onto the display. The benefit of this is that we only need to copy the content to the pad once, which includes processing the ansi escape sequences, and then the user can scroll left and right as much as they want relatively cheaply. The problem then, is that if the longest content line is very long, then we try to allocate a very large pad, which can fail. What I propose is that we allow both the pad and the display view to scroll. Once we allow this, then it becomes possible to allocate a pad that is smaller than the longest display line. We then copy part of the content into the pad. As the user scrolls the view left and right GDB will continue to copy content from the pad just as it does right now. But, when the user scrolls to the edge of the pad, GDB will copy a new block of content into the pad, and then update the view as normal. This all works fine so long as the maximum pad size is larger than the current window size - which seems a reasonable restriction, if ncurses can't support a pad of a given size it seems likely it will not support a display window of that size either. If we return to our example above, but this time we assume that the maximum pad size is 15 characters, then initially the pad would be loaded like this: .---------------. |aaaaaaaaaa | |bbbbbbbbbbbbbbb| |ccccccccccccccc| .---------------. Notice that the last 5 characters from the 'b' line are no longer included in the pad. There is still enough content though to fill the 10 character wide display, just as we did before. The pad contents remain unchanged until the user scrolls the display right to this point: .----------. |aaaaa | |bbbbbbbbbb| |cccccccccc| .----------. Now, when the user scrolls right once more GDB spots that the user has reached the end of the pad, and the pad contents are reloaded, like this: .---------------. |aaaaa | |bbbbbbbbbbbbbbb| |cccccccccc | .---------------. The display can now be updated from the pad again just like normal. With this change in place the gdb.tui/tui-disasm-long-lines.exp test now correctly loads the assembler code, and we can scroll around as expected. Most of the changes are pretty mundane, just updating to match the above. One interesting change though is the new member function tui_source_window_base::puts_to_pad_with_skip. This replaces direct calls to tui_puts when copying content to the pad. The content strings contain ansi escape sequences. When these strings are written to the pad these escape sequences are translated into ncurses attribute setting calls. Now however, we sometimes only write a partial string to the pad, skipping some of the leading content. Imagine then that we have a content line like this: "\033[31mABCDEFGHIJKLM\033[0m" Now the escape sequences in this content mean that the actual content (the 'ABCDEFGHIJKLM') will have a red foreground color. If we want to copy this to the pad, but skip the first 3 characters, then what we expect is to have the pad contain 'DEFGHIJKLM', but this text should still have a red foreground color. It is this problem that puts_to_pad_with_skip solves. This function skips some number of printable characters, but processes all the escape sequences. This means that when we do start printing the actual content the content will have the expected attributes. /
2023-01-27gdb/tui: improve errors from tui focus commandAndrew Burgess1-5/+80
This commit improves (I think) the errors from the tui focus command. There are a number of errors that can be triggered by the focus command, they include: (1) Window name "NAME" is ambiguous (2) Unrecognized window name "NAME" (3) Window "NAME" cannot be focused Error (1) is triggered when the user gives a partial window name, and the name matches multiple windows in the current layout. It is worth noting that the ambiguity must be within the current layout; if the partial name matches one window in the current layout, and one or more windows not in the current layout, then this is not ambiguous, and focus will shift to the matching window in the current layout. This error was not previous being tested, but in this commit I make use of the Python API to trigger and test this error. Error (3) is simple enough, and was already being tested. This is triggered by something like 'focus status'. The named window needs to be present in the current layout, and non-focusable in order to trigger the error. Error (2) is what I'd like to improve in this commit. This error triggers if the name the user gives doesn't match any window in the current layout. Even if GDB does know about the window, but the window isn't in the current layout, then GDB will say it doesn't recognize the window name. In this commit I propose to to split this error into three different errors. These will be: (a) Unrecognized window name "NAME" (b) No windows matching "NAME" in the current layout (c) Window "NAME" is not in the current layout Error (a) is the same as before, but will now only trigger if GDB doesn't know about window NAME at all. If the window is known, but not in the current layout then one of the other errors will trigger. Error (b) will trigger if NAME is ambiguous for multiple windows that are not in the current layout. If NAME identifies a single window in the current layout then that window will continue to be selected, just as it currently is. Only in the case where NAME doesn't identify a window in the current layout do we then check all the other known windows, if NAME matches multiple of these, then (b) is triggered. Finally, error (c) is used when NAME uniquely identifies a single window that is not in the current layout. The hope with these new errors is that the user will have a better understanding of what went wrong. Instead of GDB claiming to not know about a window, the mention of the current layout will hint to the user that they should first switch layouts. There are tests included for all the new errors.
2023-01-25gdb/tui: better filtering of tab completion results for focus commandAndrew Burgess1-2/+16
While working on the previous couple of commits, I noticed that the 'focus' command would happily suggest 'status' as a possible focus completion, even though the 'status' window is non-focusable, and, after the previous couple of commits, trying to focus the status window will result in an error. This commit improves the tab-completion results for the focus command so that the status window is not included.
2023-01-25gdb/testsuite/tui: more testing of the 'focus' commandAndrew Burgess2-0/+90
I noticed that we didn't have many tests of the tui 'focus' command, so I started adding some. This exposed a bug in GDB; we are able to focus windows that should not be focusable, e.g. the 'status' window. This is harmless until we then do 'focus next' or 'focus prev', along this code path we assert that the currently focused window is focusable, which obviously, is not always true, so GDB fails with an assertion error. The fix is simple; add a check to the tui_set_focus_command function to ensure that the selected window is focusable. If it is not then an error is thrown. The new tests I've added cover this case.
2023-01-25gdb/testsuite: update gdb.tui/tui-nl-filtered-output.expAndrew Burgess1-21/+16
Following on from the previous commit, in this commit I am updating the test script gdb.tui/tui-nl-filtered-output.exp to take account of the changes in commit: commit 9162a27c5f5828240b53379d735679e2a69a9f41 Date: Tue Nov 13 11:59:03 2018 -0700 Change gdb test suite's TERM setting In the above commit the TERM environment variable was changed to be 'dumb' by default, which means that tests, that previously activated tui mode, no longer do unless TERM is set to 'ansi'. As the gdb.tui/tui-nl-filtered-output.exp script didn't do this, the test stopped working. As the expect patterns in this script were pretty generic no tests actually started failing, and we never noticed. In this commit I update the test script to correctly activate our terminal emulator, the test continues to pass after this update, but now we are testing in tui mode.
2023-01-25gdb/testsuite: update gdb.tui/tui-disasm-long-lines.expAndrew Burgess1-7/+14
Following on from the previous commit, in this commit I am updating the test script gdb.tui/tui-disasm-long-lines.exp to take account of the changes in commit: commit 9162a27c5f5828240b53379d735679e2a69a9f41 Date: Tue Nov 13 11:59:03 2018 -0700 Change gdb test suite's TERM setting In the above commit the TERM environment variable was changed to be 'dumb' by default, which means that tests, that previously activated tui mode, no longer do unless TERM is set to 'ansi'. As the gdb.tui/tui-disasm-long-lines.exp script didn't do this, the test stopped working. As the expect patterns in this script were pretty generic no tests actually started failing, and we never noticed. In this commit I update the script to use Term::clean_restart, which correctly sets TERM to 'ansi'. I've also added a check that the asm box does appear on the screen, which should indicate that tui mode has correctly activated. However, I also notice that GDB doesn't appear to fully work correctly. The test should display the disassembly for the test program, but it doesn't. The test is trying to disassemble some code that (deliberately) uses a very long symbol name, this eventually results in GDB entering tui_source_window_base::show_source_content and trying to allocate an ncurses pad in order to hold the current page of disassembler output. Unfortunately, due to the very long line, the call to newpad fails, meaning that tui_source_window_base::m_pad is nullptr. Luckily non of the following calls appear to crash when passed a nullptr, however, all the output that is written to the pad is lost, which is why we don't see any assembly code written to the screen. As the test history indicates that the script was originally checking for a crash in GDB when the long identifier was encountered, I think there is value in just leaving the test as it is for now, I have a fix for the issue of the newpad call failing, which I'll post in a follow up commit later.
2023-01-25gdb/testsuite: extend gdb.tui/tui-layout.exp test scriptAndrew Burgess1-11/+46
In passing I noticed that the gdb.tui/tui-layout.exp test script was a little strange, it tests the layout command multiple times, but never sets up our ANSI terminal emulator, so every layout command fails with a message about the terminal lacking the required abilities. It turns out that this was caused by this commit: commit 9162a27c5f5828240b53379d735679e2a69a9f41 Date: Tue Nov 13 11:59:03 2018 -0700 Change gdb test suite's TERM setting This was when we changed the testsuite to set the TERM environment variable to "dumb" by default. After this, any tui test that didn't set the terminal mode back to 'ansi' would fail to activate tui mode. For the tui-layout.exp test it just so happens that the test patterns are generic enough that the test continued to pass, even after this change. In this commit I have updated the test so we now check the layout command both with a 'dumb' terminal and with the 'ansi' terminal. When testing with the 'ansi' terminal, I have some limited validation that GDB correctly entered tui mode. I figured that it is probably worth having at least one test in the test suite that deliberately tries to enter tui mode in a dumb terminal, it would be sad if we one day managed to break GDB such that this caused a crash, and never noticed.
2023-01-13Rename to allow_tui_testsTom Tromey4-10/+8
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-13Use require !use_gdb_stubTom Tromey1-1/+2
This changes some tests to use "require !use_gdb_stub".
2023-01-13Change 'require' to accept a list of predicatesTom Tromey1-1/+1
This changes 'require' to accept a list of simple predicates. For now, each predicate is just the name of a proc, optionally prefixed with "!" to indicate that the result should be inverted. It's possible to make this fancier, but so far I haven't done so. One idea I had is to allow a predicate to have associated text to display on failure. Another is to convert the predicates that need a running gdb (e.g., skip_python_tests) to start their own gdb, and then 'require' could enforce the rule that gdb not be running when it is called.
2023-01-01Update copyright year range in header of all files managed by GDBJoel Brobecker26-26/+26
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-08[gdb/testsuite] Require debug info for gdb.tui/tui-layout-asm-short-prog.expTom de Vries1-0/+5
When running test-case gdb.tui/tui-layout-asm-short-prog.exp on SLE-12-SP3 aarch64, I run into: ... FAIL: gdb.tui/tui-layout-asm-short-prog.exp: check asm box contents FAIL: gdb.tui/tui-layout-asm-short-prog.exp: check asm box contents again ... due to: ... (gdb) file tui-layout-asm-short-prog^M Reading symbols from tui-layout-asm-short-prog...^M (No debugging symbols found in tui-layout-asm-short-prog)^M ... I managed to reproduce the same behaviour on openSUSE Leap 15.4 x86_64, by removing the debug option. Fix this by making the test-case unsupported if no debug info is found. Tested on x86_64-linux.
2022-11-28gdb/testsuite: remove use of then keyword from gdb.*/*.exp scriptsAndrew Burgess1-1/+1
The canonical form of 'if' in modern TCL is 'if {} {}'. But there's still a bunch of places in the testsuite where we make use of the 'then' keyword, and sometimes these get copies into new tests, which just spreads poor practice. This commit removes all use of the 'then' keyword from the remaining gdb.*/*.exp scripts. Previous commits have done the bulk of this removal, this commit just handles the remaining directories that each contain a low number of instances. There should be no changes in what is tested after this commit.