diff options
Diffstat (limited to 'gdb')
-rw-r--r-- | gdb/arch/arc.c | 1 | ||||
-rw-r--r-- | gdb/arch/loongarch.c | 1 | ||||
-rw-r--r-- | gdb/arch/riscv.c | 1 | ||||
-rw-r--r-- | gdb/completer.c | 6 | ||||
-rw-r--r-- | gdb/corelow.c | 5 | ||||
-rw-r--r-- | gdb/dictionary.c | 26 | ||||
-rw-r--r-- | gdb/dwarf2/read.c | 63 | ||||
-rw-r--r-- | gdb/i386-tdep.c | 2 | ||||
-rw-r--r-- | gdb/infrun.c | 1 | ||||
-rw-r--r-- | gdb/linux-nat.c | 4 | ||||
-rw-r--r-- | gdb/main.c | 1 | ||||
-rw-r--r-- | gdb/solib-svr4.c | 19 | ||||
-rw-r--r-- | gdb/solib.c | 13 | ||||
-rw-r--r-- | gdb/symtab.c | 13 | ||||
-rw-r--r-- | gdb/symtab.h | 3 | ||||
-rw-r--r-- | gdb/testsuite/gdb.base/command-line-input.exp | 60 | ||||
-rw-r--r-- | gdb/testsuite/gdb.reverse/i386-avx-reverse.c | 4 | ||||
-rw-r--r-- | gdb/testsuite/gdb.reverse/i386-avx-reverse.exp | 2 | ||||
-rw-r--r-- | gdb/testsuite/gdb.tui/main-2.exp | 2 | ||||
-rw-r--r-- | gdb/testsuite/gdb.tui/tuiterm.exp | 46 | ||||
-rw-r--r-- | gdb/testsuite/lib/tuiterm.exp | 91 |
21 files changed, 245 insertions, 119 deletions
diff --git a/gdb/arch/arc.c b/gdb/arch/arc.c index efe7111..b7de1da 100644 --- a/gdb/arch/arc.c +++ b/gdb/arch/arc.c @@ -17,7 +17,6 @@ #include "arc.h" -#include <stdlib.h> #include <unordered_map> #include <string> diff --git a/gdb/arch/loongarch.c b/gdb/arch/loongarch.c index 07c6d4d..25e698d 100644 --- a/gdb/arch/loongarch.c +++ b/gdb/arch/loongarch.c @@ -16,7 +16,6 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. */ #include "loongarch.h" -#include <stdlib.h> #include <unordered_map> /* Target description features. */ diff --git a/gdb/arch/riscv.c b/gdb/arch/riscv.c index a6188ea..c698fa2 100644 --- a/gdb/arch/riscv.c +++ b/gdb/arch/riscv.c @@ -16,7 +16,6 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. */ #include "riscv.h" -#include <stdlib.h> #include <unordered_map> #include "../features/riscv/32bit-cpu.c" diff --git a/gdb/completer.c b/gdb/completer.c index 0d68e76..deecbc2 100644 --- a/gdb/completer.c +++ b/gdb/completer.c @@ -1008,7 +1008,7 @@ complete_files_symbols (completion_tracker &tracker, name, they cannot be asking for completion on files. */ if (strcspn (text, gdb_completer_file_name_break_characters) == text_len) - fn_list = make_source_files_completion_list (text, text); + fn_list = make_source_files_completion_list (text); } if (!fn_list.empty () && !tracker.have_completions ()) @@ -1059,7 +1059,7 @@ complete_source_filenames (const char *text) the user cannot be asking for completion on files. */ if (strcspn (text, gdb_completer_file_name_break_characters) == text_len) - return make_source_files_completion_list (text, text); + return make_source_files_completion_list (text); return {}; } @@ -1142,7 +1142,7 @@ collect_explicit_location_matches (completion_tracker &tracker, const char *source = string_or_empty (explicit_loc->source_filename.get ()); completion_list matches - = make_source_files_completion_list (source, source); + = make_source_files_completion_list (source); tracker.add_completions (std::move (matches)); } break; diff --git a/gdb/corelow.c b/gdb/corelow.c index 24b949b..a74cb05 100644 --- a/gdb/corelow.c +++ b/gdb/corelow.c @@ -451,11 +451,8 @@ core_target::build_file_mappings () const bfd_build_id *core_build_id = build_id_bfd_get (current_program_space->core_bfd ()); - for (const auto &iter : mapped_files) + for (const auto &[filename, file_data] : mapped_files) { - const std::string &filename = iter.first; - const mapped_file &file_data = iter.second; - /* If this mapped file has the same build-id as was discovered for the core-file itself, then we assume this is the main executable. Record the filename as we can use this later. */ diff --git a/gdb/dictionary.c b/gdb/dictionary.c index 91dafd1..28e900d 100644 --- a/gdb/dictionary.c +++ b/gdb/dictionary.c @@ -952,14 +952,9 @@ mdict_create_hashed (struct obstack *obstack, retval->n_allocated_dictionaries = nsyms.size (); int idx = 0; - for (const auto &pair : nsyms) - { - enum language language = pair.first; - std::vector<symbol *> symlist = pair.second; - - retval->dictionaries[idx++] - = dict_create_hashed (obstack, language, symlist); - } + for (const auto &[language, symlist] : nsyms) + retval->dictionaries[idx++] = dict_create_hashed (obstack, language, + symlist); return retval; } @@ -997,14 +992,9 @@ mdict_create_linear (struct obstack *obstack, retval->n_allocated_dictionaries = nsyms.size (); int idx = 0; - for (const auto &pair : nsyms) - { - enum language language = pair.first; - std::vector<symbol *> symlist = pair.second; - - retval->dictionaries[idx++] - = dict_create_linear (obstack, language, symlist); - } + for (const auto &[language, symlist] : nsyms) + retval->dictionaries[idx++] = dict_create_linear (obstack, language, + symlist); return retval; } @@ -1135,10 +1125,8 @@ mdict_add_pending (struct multidictionary *mdict, gdb::unordered_map<enum language, std::vector<symbol *>> nsyms = collate_pending_symbols_by_language (symbol_list); - for (const auto &pair : nsyms) + for (const auto &[language, symlist] : nsyms) { - enum language language = pair.first; - std::vector<symbol *> symlist = pair.second; struct dictionary *dict = find_language_dictionary (mdict, language); if (dict == nullptr) diff --git a/gdb/dwarf2/read.c b/gdb/dwarf2/read.c index 5e18e45..634d67a 100644 --- a/gdb/dwarf2/read.c +++ b/gdb/dwarf2/read.c @@ -9918,33 +9918,37 @@ static void handle_member_location (struct die_info *die, struct dwarf2_cu *cu, struct field *field) { - struct attribute *attr; + const auto data_member_location_attr + = dwarf2_attr (die, DW_AT_data_member_location, cu); - attr = dwarf2_attr (die, DW_AT_data_member_location, cu); - if (attr != NULL) + if (data_member_location_attr != nullptr) { bool has_bit_offset = false; LONGEST bit_offset = 0; LONGEST anonymous_size = 0; + const auto bit_offset_attr = dwarf2_attr (die, DW_AT_bit_offset, cu); - attribute *attr2 = dwarf2_attr (die, DW_AT_bit_offset, cu); - if (attr2 != nullptr && attr2->form_is_constant ()) + if (bit_offset_attr != nullptr && bit_offset_attr->form_is_constant ()) { has_bit_offset = true; - bit_offset = attr2->confused_constant ().value_or (0); - attr2 = dwarf2_attr (die, DW_AT_byte_size, cu); - if (attr2 != nullptr && attr2->form_is_constant ()) + bit_offset = bit_offset_attr->confused_constant ().value_or (0); + + const auto byte_size_attr = dwarf2_attr (die, DW_AT_byte_size, cu); + + if (byte_size_attr != nullptr && byte_size_attr->form_is_constant ()) { /* The size of the anonymous object containing the bit field is explicit, so use the indicated size (in bytes). */ - anonymous_size = attr2->unsigned_constant ().value_or (0); + anonymous_size + = byte_size_attr->unsigned_constant ().value_or (0); } } - if (attr->form_is_constant ()) + if (data_member_location_attr->form_is_constant ()) { - LONGEST offset = attr->confused_constant ().value_or (0); + LONGEST offset + = data_member_location_attr->confused_constant ().value_or (0); /* Work around this GCC 11 bug, where it would erroneously use -1 data member locations, instead of 0: @@ -9962,11 +9966,17 @@ handle_member_location (struct die_info *die, struct dwarf2_cu *cu, if (has_bit_offset) apply_bit_offset_to_field (*field, bit_offset, anonymous_size); } - else if (attr->form_is_block ()) + else if (data_member_location_attr->form_is_block ()) { CORE_ADDR offset; - if (decode_locdesc (attr->as_block (), cu, &offset)) - field->set_loc_bitpos (offset * bits_per_byte); + if (decode_locdesc (data_member_location_attr->as_block (), cu, + &offset)) + { + field->set_loc_bitpos (offset * bits_per_byte); + + if (has_bit_offset) + apply_bit_offset_to_field (*field, bit_offset, anonymous_size); + } else { dwarf2_per_objfile *per_objfile = cu->per_objfile; @@ -9985,8 +9995,8 @@ handle_member_location (struct die_info *die, struct dwarf2_cu *cu, else dlbaton = OBSTACK_ZALLOC (&objfile->objfile_obstack, struct dwarf2_locexpr_baton); - dlbaton->data = attr->as_block ()->data; - dlbaton->size = attr->as_block ()->size; + dlbaton->data = data_member_location_attr->as_block ()->data; + dlbaton->size = data_member_location_attr->as_block ()->size; /* When using this baton, we want to compute the address of the field, not the value. This is why is_reference is set to false here. */ @@ -9999,16 +10009,19 @@ handle_member_location (struct die_info *die, struct dwarf2_cu *cu, } else complaint (_("Unsupported form %s for DW_AT_data_member_location"), - dwarf_form_name (attr->form)); + dwarf_form_name (data_member_location_attr->form)); } else { - attr = dwarf2_attr (die, DW_AT_data_bit_offset, cu); - if (attr != nullptr) + const auto data_bit_offset_attr + = dwarf2_attr (die, DW_AT_data_bit_offset, cu); + + if (data_bit_offset_attr != nullptr) { - if (attr->form_is_constant ()) - field->set_loc_bitpos (attr->unsigned_constant ().value_or (0)); - else if (attr->form_is_block ()) + if (data_bit_offset_attr->form_is_constant ()) + field->set_loc_bitpos (data_bit_offset_attr->unsigned_constant () + .value_or (0)); + else if (data_bit_offset_attr->form_is_block ()) { /* This is a DWARF extension. See https://dwarfstd.org/issues/250501.1.html. */ @@ -10016,8 +10029,8 @@ handle_member_location (struct die_info *die, struct dwarf2_cu *cu, dwarf2_locexpr_baton *dlbaton = OBSTACK_ZALLOC (&per_objfile->objfile->objfile_obstack, dwarf2_locexpr_baton); - dlbaton->data = attr->as_block ()->data; - dlbaton->size = attr->as_block ()->size; + dlbaton->data = data_bit_offset_attr->as_block ()->data; + dlbaton->size = data_bit_offset_attr->as_block ()->size; dlbaton->per_objfile = per_objfile; dlbaton->per_cu = cu->per_cu; @@ -10025,7 +10038,7 @@ handle_member_location (struct die_info *die, struct dwarf2_cu *cu, } else complaint (_("Unsupported form %s for DW_AT_data_bit_offset"), - dwarf_form_name (attr->form)); + dwarf_form_name (data_bit_offset_attr->form)); } } } diff --git a/gdb/i386-tdep.c b/gdb/i386-tdep.c index b50a7c3..f97c98e 100644 --- a/gdb/i386-tdep.c +++ b/gdb/i386-tdep.c @@ -60,9 +60,7 @@ #include "stap-probe.h" #include "user-regs.h" -#include "cli/cli-utils.h" #include "expression.h" -#include "parser-defs.h" #include <ctype.h> #include <algorithm> #include <unordered_set> diff --git a/gdb/infrun.c b/gdb/infrun.c index 05bf6ab..9d3e1b7 100644 --- a/gdb/infrun.c +++ b/gdb/infrun.c @@ -67,7 +67,6 @@ #include "gdbsupport/scope-exit.h" #include "gdbsupport/forward-scope-exit.h" #include "gdbsupport/gdb_select.h" -#include <unordered_map> #include "async-event.h" #include "gdbsupport/selftest.h" #include "scoped-mock-context.h" diff --git a/gdb/linux-nat.c b/gdb/linux-nat.c index 70f77fd..f317927 100644 --- a/gdb/linux-nat.c +++ b/gdb/linux-nat.c @@ -51,17 +51,13 @@ #include <pwd.h> #include <sys/types.h> #include <dirent.h> -#include "xml-support.h" #include <sys/vfs.h> -#include "solib.h" #include "nat/linux-osdata.h" #include "linux-tdep.h" -#include "symfile.h" #include "gdbsupport/agent.h" #include "tracepoint.h" #include "target-descriptions.h" #include "gdbsupport/filestuff.h" -#include "objfiles.h" #include "nat/linux-namespaces.h" #include "gdbsupport/block-signals.h" #include "gdbsupport/fileio.h" @@ -420,6 +420,7 @@ start_event_loop () get around to resetting the prompt, which leaves readline in a messed-up state. Reset it here. */ current_ui->prompt_state = PROMPT_NEEDED; + current_ui->line_buffer.clear (); top_level_interpreter ()->on_command_error (); /* This call looks bizarre, but it is required. If the user entered a command that caused an error, diff --git a/gdb/solib-svr4.c b/gdb/solib-svr4.c index fab84c9..af08b75 100644 --- a/gdb/solib-svr4.c +++ b/gdb/solib-svr4.c @@ -2715,8 +2715,8 @@ svr4_solib_ops::enable_break (svr4_info *info, int from_tty) const linker. Warn and drop into the old code. */ bkpt_at_symbol: warning (_("Unable to find dynamic linker breakpoint function.\n" - "GDB will be unable to debug shared library initializers\n" - "and track explicitly loaded dynamic code.")); + "GDB will be unable to debug shared library initializers\n" + "and track explicitly loaded dynamic code.")); } /* Scan through the lists of symbols, trying to look up the symbol and @@ -3591,16 +3591,11 @@ find_debug_base_for_solib (const solib *solib) auto *lm_info = gdb::checked_static_cast<const lm_info_svr4 *> (solib->lm_info.get ()); - for (const auto &tuple : info->solib_lists) - { - CORE_ADDR debug_base = tuple.first; - const std::vector<svr4_so> &sos = tuple.second; - - for (const svr4_so &so : sos) - if (svr4_same (solib->original_name.c_str (), so.name.c_str (), - *lm_info, *so.lm_info)) - return debug_base; - } + for (const auto &[debug_base, sos] : info->solib_lists) + for (const svr4_so &so : sos) + if (svr4_same (solib->original_name.c_str (), so.name.c_str (), *lm_info, + *so.lm_info)) + return debug_base; return 0; } diff --git a/gdb/solib.c b/gdb/solib.c index 6d0fded..3ec2032 100644 --- a/gdb/solib.c +++ b/gdb/solib.c @@ -1167,9 +1167,7 @@ info_linker_namespace_command (const char *pattern, int from_tty) struct ui_out *uiout = current_uiout; std::vector<std::pair<int, std::vector<const solib *>>> all_solibs_to_print; - if (pattern != nullptr) - while (*pattern == ' ') - pattern++; + pattern = skip_spaces (pattern); if (pattern == nullptr || pattern[0] == '\0') { @@ -1197,10 +1195,10 @@ info_linker_namespace_command (const char *pattern, int from_tty) escape sequence must be doubled to survive the compiler pass. */ re_comp ("^\\[\\[[0-9]\\+\\]\\]$"); if (re_exec (pattern)) - ns = strtol (pattern+2, nullptr, 10); + ns = strtol (pattern + 2, nullptr, 10); else { - char * end = nullptr; + char *end = nullptr; ns = strtol (pattern, &end, 10); if (end[0] != '\0') error (_("Invalid linker namespace identifier: %s"), pattern); @@ -1212,14 +1210,13 @@ info_linker_namespace_command (const char *pattern, int from_tty) bool ns_separator = false; - for (auto &solibs_pair : all_solibs_to_print) + for (const auto &[ns, solibs_to_print] : all_solibs_to_print) { if (ns_separator) uiout->message ("\n\n"); else ns_separator = true; - int ns = solibs_pair.first; - std::vector<const solib *> solibs_to_print = solibs_pair.second; + if (solibs_to_print.size () == 0) { uiout->message (_("Linker namespace [[%d]] is not active.\n"), ns); diff --git a/gdb/symtab.c b/gdb/symtab.c index 7d1a0b0..302f4eb 100644 --- a/gdb/symtab.c +++ b/gdb/symtab.c @@ -6402,7 +6402,7 @@ add_partial_filename_data::operator() (const char *filename, program. */ completion_list -make_source_files_completion_list (const char *text, const char *word) +make_source_files_completion_list (const char *text) { size_t text_len = strlen (text); completion_list list; @@ -6428,7 +6428,7 @@ make_source_files_completion_list (const char *text, const char *word) { /* This file matches for a completion; add it to the current list of matches. */ - add_filename_to_list (s->filename, text, word, &list); + add_filename_to_list (s->filename, text, text, &list); } else { @@ -6440,7 +6440,7 @@ make_source_files_completion_list (const char *text, const char *word) if (base_name != s->filename && !filenames_seen.seen (base_name) && filename_ncmp (base_name, text, text_len) == 0) - add_filename_to_list (base_name, text, word, &list); + add_filename_to_list (base_name, text, text, &list); } } } @@ -6448,7 +6448,7 @@ make_source_files_completion_list (const char *text, const char *word) datum.filename_seen_cache = &filenames_seen; datum.text = text; - datum.word = word; + datum.word = text; datum.text_len = text_len; datum.list = &list; map_symbol_filenames (datum, false /*need_fullname*/); @@ -6986,11 +6986,8 @@ info_module_subcommand (bool quiet, const char *module_regexp, const char *last_filename = ""; const symbol *last_module_symbol = nullptr; - for (const module_symbol_search &ms : module_symbols) + for (const auto &[p, q] : module_symbols) { - const symbol_search &p = ms.first; - const symbol_search &q = ms.second; - gdb_assert (q.symbol != nullptr); if (last_module_symbol != p.symbol) diff --git a/gdb/symtab.h b/gdb/symtab.h index 0a57be5..a711953 100644 --- a/gdb/symtab.h +++ b/gdb/symtab.h @@ -2482,8 +2482,7 @@ extern void collect_file_symbol_completion_matches symbol_name_match_type name_match_type, const char *, const char *, const char *); -extern completion_list - make_source_files_completion_list (const char *, const char *); +extern completion_list make_source_files_completion_list (const char *); /* Return whether SYM is a function/method, as opposed to a data symbol. */ diff --git a/gdb/testsuite/gdb.base/command-line-input.exp b/gdb/testsuite/gdb.base/command-line-input.exp index af228dc..9760f1a 100644 --- a/gdb/testsuite/gdb.base/command-line-input.exp +++ b/gdb/testsuite/gdb.base/command-line-input.exp @@ -18,19 +18,59 @@ # Test issuing a command split in multiple lines with continuation # characters. -gdb_exit -gdb_start +clean_restart -set test "print 1\\\\n + 2" -gdb_test_multiple "print 1\\\n + 2" $test { - -re "^print 1\\\\\r\n \\+ 2\r\n\\\$$decimal = 3\r\n$gdb_prompt $" { - pass $test +set bs "\\" +set re_bs [string_to_regexp $bs] +set re_dollar [string_to_regexp $] + +set re \ + [multi_line \ + ^[string_to_regexp "print 1$bs"] \ + [string_to_regexp " + 2"] \ + "$re_dollar$decimal = 3" \ + "$gdb_prompt $"] +gdb_test_multiple "print 1$bs\n + 2" "print 1$bs${bs}n + 2" { + -re $re { + pass $gdb_test_name + } +} + +set re \ + [multi_line \ + ^[string_to_regexp "print 1$bs"] \ + "2" \ + "$re_dollar$decimal = 12" \ + "$gdb_prompt $"] +gdb_test_multiple "print 1$bs\n2" "print 1$bs${bs}n2" { + -re $re { + pass $gdb_test_name } } -set test "print 1\\\\n2" -gdb_test_multiple "print 1\\\n2" $test { - -re "^print 1\\\\\r\n2\r\n\\\$$decimal = 12\r\n$gdb_prompt $" { - pass $test +with_test_prefix "cancel multiline" { + send_gdb "print$bs\n 1" + gdb_test_multiple "" "setup" { + -re "print$re_bs\r\n 1" { + pass $gdb_test_name + } + } + + send_gdb "\003" + gdb_test_multiple "" "cancel" { + -re -wrap "" { + pass $gdb_test_name + } + } + + # Regression test for PR cli/33063. + gdb_test_multiple "print 2" "command after cancel" { + -re -wrap " = 2" { + pass $gdb_test_name + } + -re -wrap "" { + # Avoid undefined command error. + fail $gdb_test_name + } } } diff --git a/gdb/testsuite/gdb.reverse/i386-avx-reverse.c b/gdb/testsuite/gdb.reverse/i386-avx-reverse.c index a3d6427..bf6cb77 100644 --- a/gdb/testsuite/gdb.reverse/i386-avx-reverse.c +++ b/gdb/testsuite/gdb.reverse/i386-avx-reverse.c @@ -299,10 +299,10 @@ vpbroadcast_test () asm volatile ("vbroadcastss %xmm1, %xmm0"); asm volatile ("vbroadcastss %xmm1, %ymm15"); asm volatile ("vbroadcastss %0, %%ymm0" : : "m" (global_buf0)); - asm volatile ("vbroadcastss %0, %%xmm15": : "m" (dyn_buf0)); + asm volatile ("vbroadcastss %0, %%xmm15": : "m" (*dyn_buf0)); asm volatile ("vbroadcastsd %xmm1, %ymm0"); asm volatile ("vbroadcastsd %0, %%ymm15": : "m" (global_buf0)); - asm volatile ("vbroadcastf128 %0, %%ymm0" : : "m" (dyn_buf0)); + asm volatile ("vbroadcastf128 %0, %%ymm0" : : "m" (*dyn_buf0)); /* We have a return statement to deal with epilogue in different compilers. */ diff --git a/gdb/testsuite/gdb.reverse/i386-avx-reverse.exp b/gdb/testsuite/gdb.reverse/i386-avx-reverse.exp index 7e75542..fb04260 100644 --- a/gdb/testsuite/gdb.reverse/i386-avx-reverse.exp +++ b/gdb/testsuite/gdb.reverse/i386-avx-reverse.exp @@ -395,7 +395,7 @@ if {[record_full_function "vpbroadcast"] == true} { test_one_register "vbroadcastf128" "ymm0" \ "0x17161514131211101716151413121110, 0x17161514131211101716151413121110" test_one_register "vbroadcastsd" "ymm15" \ - "0x404060004040600040406000404060, 0x0" + "0x23222120232221202322212023222120, 0x0" test_one_register "vbroadcastsd" "ymm0" \ "0x13121110131211101312111013121110, 0x13121110131211101312111013121110" diff --git a/gdb/testsuite/gdb.tui/main-2.exp b/gdb/testsuite/gdb.tui/main-2.exp index 2b0fb6b..71ad03b 100644 --- a/gdb/testsuite/gdb.tui/main-2.exp +++ b/gdb/testsuite/gdb.tui/main-2.exp @@ -41,7 +41,7 @@ if {![Term::enter_tui]} { set line " return 0;" set nr [gdb_get_line_number $line] -set screen_line [Term::get_line_with_attrs 6] +set screen_line [Term::get_string_with_attrs 6 1 79] verbose -log "screen line 6: '$screen_line'" gdb_assert { [regexp "$nr <reverse:1>$line<reverse:0>" $screen_line] } \ "highlighted line in middle of source window" diff --git a/gdb/testsuite/gdb.tui/tuiterm.exp b/gdb/testsuite/gdb.tui/tuiterm.exp index 9dc2402..6cd65f3 100644 --- a/gdb/testsuite/gdb.tui/tuiterm.exp +++ b/gdb/testsuite/gdb.tui/tuiterm.exp @@ -102,7 +102,7 @@ proc test_backspace {} { Term::_move_cursor 1 2 - Term::_ctl_0x08 + Term::_ctl_0x08 0 check "backspace one" { "abcdefgh" "ijklmnop" @@ -111,13 +111,22 @@ proc test_backspace {} { } 0 2 # Cursor should not move if it is already at column 0. - Term::_ctl_0x08 + Term::_ctl_0x08 0 check "backspace 2" { "abcdefgh" "ijklmnop" "qrstuvwx" "yz01234 " } 0 2 + + # Cursor should wrap to previous line. + Term::_ctl_0x08 1 + check "backspace 3" { + "abcdefgh" + "ijklmnop" + "qrstuvwx" + "yz01234 " + } 7 1 } proc test_linefeed { } { @@ -435,6 +444,30 @@ proc test_horizontal_absolute { } { "qrstuvwx" "yz01234 " } 3 2 + + Term::_csi_G 8 + check "cursor horizontal absolute 3" { + "abcdefgh" + "ijklmnop" + "qrstuvwx" + "yz01234 " + } 7 2 + + Term::_csi_G 9 + check "cursor horizontal absolute 4" { + "abcdefgh" + "ijklmnop" + "qrstuvwx" + "yz01234 " + } 7 2 + + Term::_csi_` + check "horizontal position absolute 1" { + "abcdefgh" + "ijklmnop" + "qrstuvwx" + "yz01234 " + } 0 2 } proc test_cursor_position { } { @@ -750,6 +783,15 @@ proc test_attrs {} { set line [Term::get_line_with_attrs 0] gdb_assert { [regexp $re $line] } "attribute: $attr" } + + # Regression test: Check that _csi_m works without arguments. + setup_terminal 4 1 + Term::_csi_m 7 + Term::_insert "a" + Term::_csi_m + Term::_insert "a" + set line [Term::get_line_with_attrs 0] + gdb_assert { [string equal $line "<reverse:1>a<reverse:0>a "] } } # Run proc TEST_PROC_NAME with a "small" terminal. diff --git a/gdb/testsuite/lib/tuiterm.exp b/gdb/testsuite/lib/tuiterm.exp index a0cd199..cc8e852 100644 --- a/gdb/testsuite/lib/tuiterm.exp +++ b/gdb/testsuite/lib/tuiterm.exp @@ -45,9 +45,16 @@ namespace eval Term { set orig_cur_row $_cur_row set orig_cur_col $_cur_col - uplevel $body + set code [catch {uplevel $body} result] _log "$what, cursor: ($orig_cur_row, $orig_cur_col) -> ($_cur_row, $_cur_col)" + + if { $code == 1 } { + global errorInfo errorCode + return -code $code -errorinfo $errorInfo -errorcode $errorCode $result + } else { + return -code $code $result + } } # If ARG is empty, return DEF: otherwise ARG. This is useful for @@ -83,14 +90,40 @@ namespace eval Term { proc _ctl_0x07 {} { } + # Return 1 if tuiterm has the bw/auto_left_margin enabled. + proc _have_bw {} { + return [string equal $Term::_TERM "ansiw"] + } + # Backspace. - proc _ctl_0x08 {} { - _log_cur "Backspace" { + proc _ctl_0x08 { {bw -1} } { + if { $bw == -1 } { + set bw [_have_bw] + } + _log_cur "Backspace, bw == $bw" { variable _cur_col + variable _cur_row + variable _cols - if {$_cur_col > 0} { + if { $_cur_col > 0 } { + # No wrapping needed. incr _cur_col -1 + return + } + + if { ! $bw } { + # Wrapping not enabled. + return } + + if { $_cur_row == 0 } { + # Can't wrap. + return + } + + # Wrap to previous line. + set _cur_col [expr $_cols - 1] + incr _cur_row -1 } } @@ -155,6 +188,14 @@ namespace eval Term { } } + # Horizontal Position Absolute. + # + # https://vt100.net/docs/vt510-rm/HPA.html + proc _csi_` {args} { + # Same as Cursor Horizontal Absolute. + return [Term::_csi_G {*}$args] + } + # Cursor Up. # # https://vt100.net/docs/vt510-rm/CUU.html @@ -251,7 +292,7 @@ namespace eval Term { variable _cur_col variable _cols - set _cur_col [expr {min ($arg - 1, $_cols)}] + set _cur_col [expr {min ($arg, $_cols)} - 1] } } @@ -597,6 +638,11 @@ namespace eval Term { # # https://vt100.net/docs/vt510-rm/SGR.html proc _csi_m {args} { + if { [llength $args] == 0 } { + # Apply default. + set args [list 0] + } + _log_cur "Select Graphic Rendition ([join $args {, }])" { variable _attrs @@ -740,7 +786,7 @@ namespace eval Term { _log "wait_for: unsupported escape" error "unsupported escape" } - -re "^\x1b\\\[(\[0-9;\]*)(\[a-zA-Z@\])" { + -re "^\x1b\\\[(\[0-9;\]*)(\[a-zA-Z@`\])" { set cmd $expect_out(2,string) set params [split $expect_out(1,string) ";"] _log "wait_for: _csi_$cmd <<<$expect_out(1,string)>>>" @@ -844,8 +890,16 @@ namespace eval Term { # BODY. proc with_tuiterm {rows cols body} { global env stty_init + variable _TERM save_vars {env(TERM) env(NO_COLOR) stty_init} { - setenv TERM ansi + if { [ishost *-*-*bsd*] } { + setenv TERM ansiw + } else { + setenv TERM ansi + } + # Save active TERM variable. + set Term::_TERM $env(TERM) + setenv NO_COLOR "" _setup $rows $cols @@ -955,10 +1009,10 @@ namespace eval Term { return $res } - # Return the text of screen line N. Lines are 0-based. If C is given, - # stop before column C. Columns are also zero-based. If ATTRS, annotate - # with attributes. - proc get_line_1 {n c attrs} { + # Return the text of screen line N. Lines are 0-based. Start at column + # X. If C is non-empty, stop before column C. Columns are also + # zero-based. If ATTRS, annotate with attributes. + proc get_string {n x c {attrs 0}} { variable _rows # This can happen during resizing, if the cursor seems to # temporarily be off-screen. @@ -970,7 +1024,6 @@ namespace eval Term { variable _cols variable _chars set c [_default $c $_cols] - set x 0 if { $attrs } { _reset_attrs line_attrs } @@ -990,6 +1043,20 @@ namespace eval Term { return $result } + # Return the text of screen line N. Lines are 0-based. Start at column + # X. If C is non-empty, stop before column C. Columns are also + # zero-based. Annotate with attributes. + proc get_string_with_attrs { n x c } { + return [get_string $n $x $c 1] + } + + # Return the text of screen line N. Lines are 0-based. If C is + # non-empty, stop before column C. Columns are also zero-based. If + # ATTRS, annotate with attributes. + proc get_line_1 {n c attrs} { + return [get_string $n 0 $c $attrs] + } + # Return the text of screen line N, without attributes. Lines are # 0-based. If C is given, stop before column C. Columns are also # zero-based. |