From 53a89d6e5861d23b2b9ad0c82247daddc117701a Mon Sep 17 00:00:00 2001 From: Simon Marchi Date: Mon, 12 Nov 2018 10:38:44 -0500 Subject: [PATCH] Add completer for skip numbers Add completer to various commands that accept skip numbers: - skip enable - skip disable - skip delete - info skip These commands also accept ranges, the completer works for that but is not very smart. It will suggest invalid ranges, for example when doing "2-" it will suggest "1", which would not result in a valid range. Also, it will keep suggesting when doing "1-2-", even though it's an invalid syntax. A future idea would be to make a re-usable and well-tested completer for numbers and ranges. I think it could at least be re-used for breakpoint and thread numbers (for example with the "enable breakpoints" command). gdb/ChangeLog: * skip.c (complete_skip_number): New function. (_initialize_step_skip): Add completers to some skip commands. gdb/testsuite/ChangeLog: * gdb.base/skip.exp: Add standard_testfile. Add "skip delete" completer tests. --- gdb/ChangeLog | 5 +++++ gdb/skip.c | 35 ++++++++++++++++++++++++++++------- gdb/testsuite/ChangeLog | 5 +++++ gdb/testsuite/gdb.base/skip.exp | 36 ++++++++++++++++++++++++++++++++++++ 4 files changed, 74 insertions(+), 7 deletions(-) diff --git a/gdb/ChangeLog b/gdb/ChangeLog index b8ca2ff..62d7f54 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,3 +1,8 @@ +2018-11-12 Simon Marchi + + * skip.c (complete_skip_number): New function. + (_initialize_step_skip): Add completers to some skip commands. + 2018-11-09 Tom Tromey * remote.c (remote_g_packet_guess_s): Remove typedef and DEF_VEC. diff --git a/gdb/skip.c b/gdb/skip.c index 13db0f6..f2a1df7 100644 --- a/gdb/skip.c +++ b/gdb/skip.c @@ -641,6 +641,23 @@ function_name_is_marked_for_skip (const char *function_name, return false; } +/* Completer for skip numbers. */ + +static void +complete_skip_number (cmd_list_element *cmd, + completion_tracker &completer, + const char *text, const char *word) +{ + size_t word_len = strlen (word); + + for (const skiplist_entry &entry : skiplist_entries) + { + gdb::unique_xmalloc_ptr name (xstrprintf ("%d", entry.number ())); + if (strncmp (word, name.get (), word_len) == 0) + completer.add_completion (std::move (name)); + } +} + void _initialize_step_skip (void) { @@ -676,28 +693,31 @@ If no function name is given, skip the current function."), &skiplist); set_cmd_completer (c, location_completer); - add_cmd ("enable", class_breakpoint, skip_enable_command, _("\ + c = add_cmd ("enable", class_breakpoint, skip_enable_command, _("\ Enable skip entries. You can specify numbers (e.g. \"skip enable 1 3\"), \ ranges (e.g. \"skip enable 4-8\"), or both (e.g. \"skip enable 1 3 4-8\").\n\n\ If you don't specify any numbers or ranges, we'll enable all skip entries.\n\n\ Usage: skip enable [NUMBER | RANGE]..."), - &skiplist); + &skiplist); + set_cmd_completer (c, complete_skip_number); - add_cmd ("disable", class_breakpoint, skip_disable_command, _("\ + c = add_cmd ("disable", class_breakpoint, skip_disable_command, _("\ Disable skip entries. You can specify numbers (e.g. \"skip disable 1 3\"), \ ranges (e.g. \"skip disable 4-8\"), or both (e.g. \"skip disable 1 3 4-8\").\n\n\ If you don't specify any numbers or ranges, we'll disable all skip entries.\n\n\ Usage: skip disable [NUMBER | RANGE]..."), - &skiplist); + &skiplist); + set_cmd_completer (c, complete_skip_number); - add_cmd ("delete", class_breakpoint, skip_delete_command, _("\ + c = add_cmd ("delete", class_breakpoint, skip_delete_command, _("\ Delete skip entries. You can specify numbers (e.g. \"skip delete 1 3\"), \ ranges (e.g. \"skip delete 4-8\"), or both (e.g. \"skip delete 1 3 4-8\").\n\n\ If you don't specify any numbers or ranges, we'll delete all skip entries.\n\n\ Usage: skip delete [NUMBER | RANGES]..."), - &skiplist); + &skiplist); + set_cmd_completer (c, complete_skip_number); - add_info ("skip", info_skip_command, _("\ + c = add_info ("skip", info_skip_command, _("\ Display the status of skips. You can specify numbers (e.g. \"skip info 1 3\"), \ ranges (e.g. \"skip info 4-8\"), or both (e.g. \"skip info 1 3 4-8\").\n\n\ If you don't specify any numbers or ranges, we'll show all skips.\n\n\ @@ -705,6 +725,7 @@ Usage: skip info [NUMBER | RANGES]...\n\ The \"Type\" column indicates one of:\n\ \tfile - ignored file\n\ \tfunction - ignored function")); + set_cmd_completer (c, complete_skip_number); add_setshow_boolean_cmd ("skip", class_maintenance, &debug_skip, _("\ diff --git a/gdb/testsuite/ChangeLog b/gdb/testsuite/ChangeLog index 015028c..90faeda 100644 --- a/gdb/testsuite/ChangeLog +++ b/gdb/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2018-11-12 Simon Marchi + + * gdb.base/skip.exp: Add standard_testfile. Add "skip delete" + completer tests. + 2018-11-09 Tom de Vries * gdb.base/msym-lang.c: New test. diff --git a/gdb/testsuite/gdb.base/skip.exp b/gdb/testsuite/gdb.base/skip.exp index 223c93d..a7ea0b5 100644 --- a/gdb/testsuite/gdb.base/skip.exp +++ b/gdb/testsuite/gdb.base/skip.exp @@ -16,6 +16,10 @@ # This file was written by Justin Lebar. (justin.lebar@gmail.com) # And further hacked on by Doug Evans. (dje@google.com) +load_lib completion-support.exp + +standard_testfile + if { [prepare_for_testing "failed to prepare" "skip" \ {skip.c skip1.c } \ {debug nowarnings}] } { @@ -297,3 +301,35 @@ with_test_prefix "step using -fi + -fu" { gdb_test "step" ".*" "step 4"; # Skip over test_skip() gdb_test "step" "test_skip_file_and_function \\(\\) at.*" "step 5"; # Return from skip1_test_skip_file_and_function() } + +with_test_prefix "skip delete completion" { + global binfile + clean_restart "${binfile}" + if ![runto_main] { + fail "can't run to main" + return + } + + # Create a bunch of skips, don't care what they are. + for {set i 0} {$i < 12} {incr i} { + gdb_test "skip" ".*" "add skip $i" + } + + set all_numbers { "1" "10" "11" "12" "2" "3" "4" "5" "6" "7" "8" "9" } + + # Test completing single numbers. + test_gdb_complete_multiple "skip delete " "" "" $all_numbers + test_gdb_complete_multiple "skip delete " "1" "" { "1" "10" "11" "12" } + test_gdb_complete_multiple "skip delete 2 " "" "" $all_numbers + test_gdb_complete_unique "skip delete 11" "skip delete 11" + + # Test completing ranges. + test_gdb_complete_multiple "skip delete 2-" "" "" $all_numbers + test_gdb_complete_unique "skip delete 2-5" "skip delete 2-5" + + # Test cases with no completion. + test_gdb_complete_none "skip delete 123" + test_gdb_complete_none "skip delete a1" + test_gdb_complete_none "skip delete 2-33" +} + -- 2.7.4