From: Tom Tromey Date: Thu, 5 Sep 2024 18:09:43 +0000 (-0600) Subject: Handle optional lines correctly in gdb.ada/complete.exp X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=be6adf5b7597cb2eb1e7f07fbfd766a9d6ac42bb;p=thirdparty%2Fbinutils-gdb.git Handle optional lines correctly in gdb.ada/complete.exp While working on another series, I discovered that the existing code in gdb.ada/complete.exp that conditionally accepts a completion does not work correctly. The code assumes that wrapping a line in "(...)?" will make the entire line optional, but really this will only match a blank line. Meanwhile, I needed this same patch for a second series I'm working on, so I've pulled this out. As it only affects Ada, I am going to check it in. --- diff --git a/gdb/testsuite/gdb.ada/complete.exp b/gdb/testsuite/gdb.ada/complete.exp index 6263c4e849a..70d4945f8c8 100644 --- a/gdb/testsuite/gdb.ada/complete.exp +++ b/gdb/testsuite/gdb.ada/complete.exp @@ -30,6 +30,17 @@ runto "foo.adb:$bp_location" set eol "\r\n" +# Like multi_line, but if a line is optional (like "(mumble)?"), then +# insert the \r\n into the optional part. +proc multi_line_with_optional {args} { + set result "" + foreach line $args { + append result [regsub -- "(\\)\\?)?$" $line "\r\n\\1"] + } + # Remove the final \r\n. + return [string range $result 0 end-2] +} + # A convenience function that verifies that the "complete EXPR" command # returns the EXPECTED_OUTPUT. @@ -155,29 +166,35 @@ test_gdb_complete "external_ident" \ # Complete on the name of package. test_gdb_complete "pck" \ - [multi_line "(p pck\\.ad\[sb\])?" \ - "(p pck\\.ad\[sb\])?" \ - "p pck.ambiguous_func" \ - "p pck.external_identical_one" \ - "p pck.inner.inside_variable" \ - "p pck.internal_capitalized" \ - "p pck.local_identical_one" \ - "p pck.local_identical_two" \ - "p pck.my_global_variable" \ - "p pck.proc" ] + [multi_line_with_optional \ + "(p pck)?" \ + "(p pck\\.ad\[sb\])?" \ + "(p pck\\.ad\[sb\])?" \ + "p pck.ambiguous_func" \ + "p pck.external_identical_one" \ + "(p pck.inner)?" \ + "p pck.inner.inside_variable" \ + "p pck.internal_capitalized" \ + "p pck.local_identical_one" \ + "p pck.local_identical_two" \ + "p pck.my_global_variable" \ + "p pck.proc" ] # Complete on the name of a package followed by a dot: test_gdb_complete "pck." \ - [multi_line "(p pck\\.ad\[sb\])?" \ - "(p pck\\.ad\[sb\])?" \ - "p pck.ambiguous_func" \ - "p pck.external_identical_one" \ - "p pck.inner.inside_variable" \ - "p pck.internal_capitalized" \ - "p pck.local_identical_one" \ - "p pck.local_identical_two" \ - "p pck.my_global_variable" \ - "p pck.proc" ] + [multi_line_with_optional \ + "(p pck\\.)?" \ + "(p pck\\.ad\[sb\])?" \ + "(p pck\\.ad\[sb\])?" \ + "p pck.ambiguous_func" \ + "p pck.external_identical_one" \ + "(p pck.inner)?" \ + "p pck.inner.inside_variable" \ + "p pck.internal_capitalized" \ + "p pck.local_identical_one" \ + "p pck.local_identical_two" \ + "p pck.my_global_variable" \ + "p pck.proc" ] # Complete a mangled symbol name, but using the '<...>' notation. test_gdb_complete "