From patchwork Tue Jan 17 13:00:07 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Guinevere Larsen X-Patchwork-Id: 63273 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id AEA673858421 for ; Tue, 17 Jan 2023 14:13:17 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org AEA673858421 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1673964797; bh=SQGpcvY8iUOc7DvS0Es3IPph1LncvWuyvDmXQSU0Qv0=; h=To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From:Reply-To:From; b=PR3l2TpII+3hJtDiKicbI2wPsPf3rt2HJx9iEOREHczvpYJBNo/HjUQrtww2LrEzG nxE38dSo1HohFIu+haVY4F7e5H6Y/SooOkD1NO87WCp6aAIFK4uvLquikx4IxaS53N S5lqlCVpIzTT6XrU2R1j0xNKm55DGPn7gIWNTIzw= X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by sourceware.org (Postfix) with ESMTPS id 0DB753858C2B for ; Tue, 17 Jan 2023 14:12:29 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 0DB753858C2B Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-262-NC1fmXQAMXG1-7u8s55srw-1; Tue, 17 Jan 2023 09:12:26 -0500 X-MC-Unique: NC1fmXQAMXG1-7u8s55srw-1 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.rdu2.redhat.com [10.11.54.2]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id CF028811E6E for ; Tue, 17 Jan 2023 14:12:25 +0000 (UTC) Received: from fedora.redhat.com (unknown [10.43.2.105]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 41B3040C6EC4; Tue, 17 Jan 2023 14:12:25 +0000 (UTC) To: gdb-patches@sourceware.org Cc: Bruno Larsen Subject: [PATCH 1/2] gdb/testsuite: add test with regex for multiple completion patterns Date: Tue, 17 Jan 2023 14:00:07 +0100 Message-Id: <20230117130007.1686917-2-blarsen@redhat.com> In-Reply-To: <20230117130007.1686917-1-blarsen@redhat.com> References: <20230117130007.1686917-1-blarsen@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.2 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-11.6 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_NONE, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Bruno Larsen via Gdb-patches From: Guinevere Larsen Reply-To: Bruno Larsen Errors-To: gdb-patches-bounces+patchwork=sourceware.org@sourceware.org Sender: "Gdb-patches" Currently there is no way to test tab completion on GDB using regexes if you expect multiple suggestions. This commit adds a proc for that, test_gdb_complete_multiple_re, which does just that. To achieve that, test_gdb_complete_cmd_multiple_re and test_gdb_complete_tab_multiple_re are introduced, following a similar logic to the unique tests, which already have an _re version. --- gdb/testsuite/lib/completion-support.exp | 73 +++++++++++++++++++----- 1 file changed, 60 insertions(+), 13 deletions(-) diff --git a/gdb/testsuite/lib/completion-support.exp b/gdb/testsuite/lib/completion-support.exp index bf9c5ad352c..babe802e9a1 100644 --- a/gdb/testsuite/lib/completion-support.exp +++ b/gdb/testsuite/lib/completion-support.exp @@ -47,7 +47,7 @@ proc make_tab_completion_list_re { completion_list } { set completion_list_re "" foreach c $completion_list { - append completion_list_re [string_to_regexp $c] + append completion_list_re $c append completion_list_re $ws } append completion_list_re $ws @@ -58,13 +58,18 @@ proc make_tab_completion_list_re { completion_list } { # Make a regular expression that matches a "complete" command # completion list. CMD_PREFIX is the command prefix added to each # completion match. +# COMPLETION_LIST is expected to already be regexp. This is done so +# we can have regex options in the completion list, to account for +# differences in compiler results. proc make_cmd_completion_list_re { cmd_prefix completion_list start_quote_char end_quote_char } { set completion_list_re "" foreach c $completion_list { # The command prefix is included in all completion matches. - append completion_list_re [string_to_regexp $cmd_prefix$start_quote_char$c$end_quote_char] + append completion_list_re [string_to_regexp $cmd_prefix$start_quote_char] + append completion_list_re $c + append completion_list_re [string_to_regexp $end_quote_char] append completion_list_re "\r\n" } @@ -124,18 +129,18 @@ proc test_gdb_complete_tab_unique { input_line complete_line_re append_char_re } } # Test that completing INPUT_LINE with TAB completes to "INPUT_LINE + -# ADD_COMPLETED_LINE" and that it displays the completion matches in +# ADD_COMPLETED_LINE_RE" and that it displays the completion matches in # COMPLETION_LIST. If MAX_COMPLETIONS then we expect the completion # to hit the max-completions limit. +# ADD_COMPLETED_LINE_RE and EXPECTED_RE must be regular expressions, +# while INPUT_LINE is does is not. -proc test_gdb_complete_tab_multiple { input_line add_completed_line \ - completion_list {max_completions 0}} { +proc test_gdb_complete_tab_multiple_re { input_line add_completed_line_re \ + completion_list_re {max_completions 0}} { global gdb_prompt set input_line_re [string_to_regexp $input_line] - set add_completed_line_re [string_to_regexp $add_completed_line] - - set expected_re [make_tab_completion_list_re $completion_list] + set expected_re [make_tab_completion_list_re $completion_list_re] if {$max_completions} { append expected_re "\r\n" @@ -150,14 +155,14 @@ proc test_gdb_complete_tab_multiple { input_line add_completed_line \ send_gdb "\t" # If we auto-completed to an ambiguous prefix, we need an # extra tab to show the matches list. - if {$add_completed_line != ""} { + if {$add_completed_line_re != ""} { send_gdb "\t" set maybe_bell ${completion::bell_re} } else { set maybe_bell "" } gdb_test_multiple "" "$test (second tab)" { - -re "^${maybe_bell}\r\n$expected_re\r\n$gdb_prompt " { + -re "^$maybe_bell\r\n$expected_re\r\n$gdb_prompt " { gdb_test_multiple "" "$test (second tab)" { -re "^$input_line_re$add_completed_line_re$" { pass "$test" @@ -171,6 +176,21 @@ proc test_gdb_complete_tab_multiple { input_line add_completed_line \ clear_input_line $test } +# Simplified call test completeing an INPUT_LINE using TAB. This just +# turns the given COMPLETION_LIST into regexps and calls the proc +# test_gdb_complete_tab_multiple_re + +proc test_gdb_complete_tab_multiple { input_line add_completed_line \ + completion_list {max_completions 0}} { + set add_completed_line_re [string_to_regexp $add_completed_line] + set completion_list_re "" + foreach c $completion_list { + lappend completion_list_re [string_to_regexp $c] + } + + test_gdb_complete_tab_multiple_re $input_line $add_completed_line_re \ + $completion_list_re $max_completions +} # Test that completing LINE with the complete command completes to # nothing. @@ -195,15 +215,16 @@ proc test_gdb_complete_cmd_unique { input_line complete_line_re } { } # Test that completing "CMD_PREFIX + COMPLETION_WORD" with the -# complete command displays the COMPLETION_LIST completion list. Each +# complete command displays the COMPLETION_LIST_RE completion list. Each # entry in the list should be prefixed by CMD_PREFIX. If # MAX_COMPLETIONS then we expect the completion to hit the # max-completions limit. +# COMPLETION_LIST_RE must already be valid regexes. -proc test_gdb_complete_cmd_multiple { cmd_prefix completion_word completion_list {start_quote_char ""} {end_quote_char ""} {max_completions 0}} { +proc test_gdb_complete_cmd_multiple_re { cmd_prefix completion_word completion_list_re {start_quote_char ""} {end_quote_char ""} {max_completions 0}} { global gdb_prompt - set expected_re [make_cmd_completion_list_re $cmd_prefix $completion_list $start_quote_char $end_quote_char] + set expected_re [make_cmd_completion_list_re $cmd_prefix $completion_list_re $start_quote_char $end_quote_char] if {$max_completions} { set cmd_prefix_re [string_to_regexp $cmd_prefix] @@ -220,6 +241,19 @@ proc test_gdb_complete_cmd_multiple { cmd_prefix completion_word completion_list } } +# Simplified call to test_gdb_complete_cmd_multiple_re, allowing for +# passing completions that are not regular expressions. + +proc test_gdb_complete_cmd_multiple { cmd_prefix completion_word completion_list {start_quote_char ""} {end_quote_char ""} {max_completions 0}} { + set completion_list_re "" + foreach c $completion_list { + lappend completion_list_re [string_to_regexp $c] + } + + test_gdb_complete_cmd_multiple_re $cmd_prefix $completion_word \ + $completion_list_re $start_quote_char $end_quote_char $max_completions +} + # Test that completing LINE completes to nothing. proc test_gdb_complete_none { input_line } { @@ -300,6 +334,19 @@ proc test_gdb_complete_multiple { test_gdb_complete_cmd_multiple $cmd_prefix $completion_word $completion_list $start_quote_char $end_quote_char $max_completions } +# Similar to test_gdb_complete_multiple, but requires regular expressions +# in COMPLETION_LIST_RE. + +proc test_gdb_complete_multiple_re { + cmd_prefix completion_word add_completed_line completion_list_re + {start_quote_char ""} {end_quote_char ""} {max_completions 0} +} { + if { [readline_is_used] } { + test_gdb_complete_tab_multiple_re "$cmd_prefix$completion_word" $add_completed_line $completion_list_re $max_completions + } + test_gdb_complete_cmd_multiple_re $cmd_prefix $completion_word $completion_list_re $start_quote_char $end_quote_char $max_completions +} + # Test that all the substring prefixes of INPUT from [0..START) to # [0..END) complete to COMPLETION_RE (a regular expression). If END # is ommitted, default to the length of INPUT. From patchwork Tue Jan 17 13:00:08 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Guinevere Larsen X-Patchwork-Id: 63274 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 1B4C43858412 for ; Tue, 17 Jan 2023 14:13:45 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 1B4C43858412 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1673964825; bh=n+Y8Cp2vAqT8s1K2mAdoNPdecpf2it3CWvVndKY5NKg=; h=To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From:Reply-To:From; b=fKu31Y74GRBeJfuczr6Ir01A6I/e0Zs2Kd5kLHzRQx8x/dJ2YGR01L9GA1o7rNKDU 7Fvo0ozAo0FXRyVGUVKjeoy56T4F/5B/0cqnEsvFRNCr8cqRTkgMqvdEoXoYh2u+ze KOe5POOH1MNd3sKqzIG26OD1ijIUf4DHIDdb+0mI= X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by sourceware.org (Postfix) with ESMTPS id F01E13858C27 for ; Tue, 17 Jan 2023 14:12:30 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org F01E13858C27 Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-330-XnWeyViKMZWq8Mx33IrUaQ-1; Tue, 17 Jan 2023 09:12:29 -0500 X-MC-Unique: XnWeyViKMZWq8Mx33IrUaQ-1 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.rdu2.redhat.com [10.11.54.2]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 818893C10149 for ; Tue, 17 Jan 2023 14:12:26 +0000 (UTC) Received: from fedora.redhat.com (unknown [10.43.2.105]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 1041D40C6EC4; Tue, 17 Jan 2023 14:12:25 +0000 (UTC) To: gdb-patches@sourceware.org Cc: Bruno Larsen Subject: [PATCH 2/2] gdb/testsuite: fix running gdb.linespec/cp-completion-aliases.exp with clang Date: Tue, 17 Jan 2023 14:00:08 +0100 Message-Id: <20230117130007.1686917-3-blarsen@redhat.com> In-Reply-To: <20230117130007.1686917-1-blarsen@redhat.com> References: <20230117130007.1686917-1-blarsen@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.2 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-12.0 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_NONE, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Bruno Larsen via Gdb-patches From: Guinevere Larsen Reply-To: Bruno Larsen Errors-To: gdb-patches-bounces+patchwork=sourceware.org@sourceware.org Sender: "Gdb-patches" Currently, all important tests in gdb.linespec/cp-completion-aliases.exp are failing when using clang because the wrong type is being suggested for the completion. For example, running with gcc and clang we get the following output respectively: (gdb) break get_value(object_p) <- gcc version (gdb) break get_value(object*) <- clang version Since both suggestions are acceptable on their own, and the original bug was if GDB suggested both at the same time, this commit updates the test to accept both, gcc's and clang's outputs. --- .../gdb.linespec/cp-completion-aliases.exp | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/gdb/testsuite/gdb.linespec/cp-completion-aliases.exp b/gdb/testsuite/gdb.linespec/cp-completion-aliases.exp index 33ad72e6f05..01ec61f4591 100644 --- a/gdb/testsuite/gdb.linespec/cp-completion-aliases.exp +++ b/gdb/testsuite/gdb.linespec/cp-completion-aliases.exp @@ -27,15 +27,15 @@ if {[prepare_for_testing "failed to prepare" $testfile $srcfile {debug}]} { # Disable the completion limit for the whole testcase. gdb_test_no_output "set max-completions unlimited" -test_gdb_complete_unique \ +test_gdb_complete_unique_re \ "break get_v" \ - "break get_value(object_p)" + "break get_value\\(object(_p|\\\*)\\)" -test_gdb_complete_unique \ +test_gdb_complete_unique_re \ "break gr" \ - "break grab_it(int_magic_t*)" + "break grab_it\\((int_magic_t|magic)\\\*\\)" -test_gdb_complete_multiple "break " "get_som" "ething(" { - "get_something(my_string_t)" - "get_something(object_p)" +test_gdb_complete_multiple_re "break " "get_som" "ething\\\(" { + "get_something\\((my_string_t|char\ const\\*)\\)" + "get_something\\(object(_p|\\*)\\)" }