[Ada] Fix completion for multiple function matches
authorPierre-Marie de Rodat <derodat@adacore.com>
Mon, 31 Aug 2015 14:04:07 +0000 (16:04 +0200)
committerPierre-Marie de Rodat <derodat@adacore.com>
Tue, 1 Sep 2015 12:54:19 +0000 (14:54 +0200)
Before this change, trying to complete an expression ending with an
ambiguous function name (i.e. for which there are multiple matches)
would display a menu with a prompt for the user to pick one. For
instance:

    (gdb) p func<tab>Multiple matches for func
    [0] cancel
    [1] pack2.func at pack2.adb:5
    [2] pack.func at pack.adb:5
    >

This is not user friendly and actually triggered a segmentation fault
after the user did pick one. It is not clear whether the segmentation
fault needs a separate fix, but this is the only known case which
exhibits it at the moment, and this case must be fixed itself.

The problem lies in ada-lang.c (ada_resolve_function): when we got
multiple matches, we should not display the menu if we are in completion
mode. This patch adjusts the corresponding condition accordingly.

gdb/ChangeLog:

* ada-lang.c (ada_resolve_function): Do not ask the user what
match to use when in completion mode.

gdb/testsuite/ChangeLog:

* gdb.ada/complete.exp: Add "pck.ambiguous_func" to the relevant
expected outputs.  Add two testcases for completing ambiguous
functions.
* gdb.ada/complete/aux_pck.adb: New file.
* gdb.ada/complete/aux_pck.ads: New file.
* gdb.ada/complete/foo.adb: Pull Aux_Pck and call the two
Ambiguous_Func functions.
* gdb.ada/complete/pck.ads: Add an Ambiguous_Func function.
* gdb.ada/complete/pck.adb: Likewise.

Tested on x86_64-linux, no regression.

gdb/ChangeLog
gdb/ada-lang.c
gdb/testsuite/ChangeLog
gdb/testsuite/gdb.ada/complete.exp
gdb/testsuite/gdb.ada/complete/aux_pck.adb [new file with mode: 0644]
gdb/testsuite/gdb.ada/complete/aux_pck.ads [new file with mode: 0644]
gdb/testsuite/gdb.ada/complete/foo.adb
gdb/testsuite/gdb.ada/complete/pck.adb
gdb/testsuite/gdb.ada/complete/pck.ads

index ddb8e78cbb75ba36c4c1ff49b06202c61635a6a9..008fc93638665492de3297b82c74af01aa58afb7 100644 (file)
@@ -1,3 +1,8 @@
+2015-09-01  Pierre-Marie de Rodat  <derodat@adacore.com>
+
+       * ada-lang.c (ada_resolve_function): Do not ask the user what
+       match to use when in completion mode.
+
 2015-08-31  Andrew Burgess  <andrew.burgess@embecosm.com>
 
        * tui/tui-data.c (tui_win_name): Make local variable const, remove
index 7e6b6dcaeb03c59c679e7aed558fbe34104dc433..a7809ffc2c05d74416ee0dea14bf4e91775323e6 100644 (file)
@@ -3655,9 +3655,13 @@ ada_resolve_function (struct block_symbol syms[],
         }
     }
 
+  /* If we got multiple matches, ask the user which one to use.  Don't do this
+     interactive thing during completion, though, as the purpose of the
+     completion is providing a list of all possible matches.  Prompting the
+     user to filter it down would be completely unexpected in this case.  */
   if (m == 0)
     return -1;
-  else if (m > 1)
+  else if (m > 1 && !parse_completion)
     {
       printf_filtered (_("Multiple matches for %s\n"), name);
       user_select_syms (syms, m, 1);
index e5de0a3a4121ba7bd9dfa7876c3287cdf569c6bb..4eaf1d131176d8d1c468cb8fdaf311da7f4a3f21 100644 (file)
@@ -1,3 +1,15 @@
+2015-09-01  Pierre-Marie de Rodat  <derodat@adacore.com>
+
+       * gdb.ada/complete.exp: Add "pck.ambiguous_func" to the relevant
+       expected outputs.  Add two testcases for completing ambiguous
+       functions.
+       * gdb.ada/complete/aux_pck.adb: New file.
+       * gdb.ada/complete/aux_pck.ads: New file.
+       * gdb.ada/complete/foo.adb: Pull Aux_Pck and call the two
+       Ambiguous_Func functions.
+       * gdb.ada/complete/pck.ads: Add an Ambiguous_Func function.
+       * gdb.ada/complete/pck.adb: Likewise.
+
 2015-08-27  Ulrich Weigand  <uweigand@de.ibm.com>
 
        * lib/cell.exp (skip_cell_tests): Report UNRESOLVED on unexpected
index 9919bdf9ef3e8b6629fc0d723c65a25243857159..0c4f03f4e1bc4274bc2d7254d6d952ba383534d3 100644 (file)
@@ -140,6 +140,7 @@ test_gdb_complete "external_ident" \
 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.local_identical_one" \
@@ -151,6 +152,7 @@ test_gdb_complete "pck" \
 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.local_identical_one" \
@@ -181,3 +183,14 @@ if { [readline_is_used] } {
        }
     }
 }
+
+# Usually, parsing a function name that is ambiguous yields a menu through
+# which users can select a specific function.  This should not happen during
+# completion, though.
+test_gdb_complete "ambig" \
+                  [multi_line "p ambiguous_func" \
+                              "p ambiguous_proc" ]
+test_gdb_complete "ambiguous_f" \
+                  "p ambiguous_func"
+test_gdb_complete "ambiguous_func" \
+                  "p ambiguous_func"
diff --git a/gdb/testsuite/gdb.ada/complete/aux_pck.adb b/gdb/testsuite/gdb.ada/complete/aux_pck.adb
new file mode 100644 (file)
index 0000000..b15912a
--- /dev/null
@@ -0,0 +1,28 @@
+--  Copyright 2015 Free Software Foundation, Inc.
+--
+--  This program is free software; you can redistribute it and/or modify
+--  it under the terms of the GNU General Public License as published by
+--  the Free Software Foundation; either version 3 of the License, or
+--  (at your option) any later version.
+--
+--  This program is distributed in the hope that it will be useful,
+--  but WITHOUT ANY WARRANTY; without even the implied warranty of
+--  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+--  GNU General Public License for more details.
+--
+--  You should have received a copy of the GNU General Public License
+--  along with this program.  If not, see <http://www.gnu.org/licenses/>.
+
+package body Aux_Pck is
+
+   procedure Ambiguous_Func is
+   begin
+      null;
+   end Ambiguous_Func;
+
+   procedure Ambiguous_Proc is
+   begin
+      null;
+   end Ambiguous_Proc;
+
+end Aux_Pck;
diff --git a/gdb/testsuite/gdb.ada/complete/aux_pck.ads b/gdb/testsuite/gdb.ada/complete/aux_pck.ads
new file mode 100644 (file)
index 0000000..f3476c6
--- /dev/null
@@ -0,0 +1,21 @@
+--  Copyright 2015 Free Software Foundation, Inc.
+--
+--  This program is free software; you can redistribute it and/or modify
+--  it under the terms of the GNU General Public License as published by
+--  the Free Software Foundation; either version 3 of the License, or
+--  (at your option) any later version.
+--
+--  This program is distributed in the hope that it will be useful,
+--  but WITHOUT ANY WARRANTY; without even the implied warranty of
+--  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+--  GNU General Public License for more details.
+--
+--  You should have received a copy of the GNU General Public License
+--  along with this program.  If not, see <http://www.gnu.org/licenses/>.
+
+package Aux_Pck is
+
+   procedure Ambiguous_Func;
+   procedure Ambiguous_Proc;
+
+end Aux_Pck;
index 58d0ee327019060e69cc4ea3ef24cd2c654f441b..98f1c1ebadbd90d9ae5c9e45eba986790e799352 100644 (file)
@@ -13,7 +13,8 @@
 --  You should have received a copy of the GNU General Public License
 --  along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
-with Pck; use Pck;
+with Aux_Pck; use Aux_Pck;
+with Pck;     use Pck;
 
 procedure Foo is
    Some_Local_Variable : Integer := 1;
@@ -21,5 +22,8 @@ procedure Foo is
 begin
    My_Global_Variable := Some_Local_Variable + 1; -- START
    Proc (External_Identical_Two);
+   Aux_Pck.Ambiguous_Func;
+   Aux_Pck.Ambiguous_Proc;
+   Pck.Ambiguous_Func;
 end Foo;
 
index 51dd725dbe9e294691d98e0861db44b9129c7bf3..10680dcf30709ddad795dae0b7ab642e8029dc36 100644 (file)
@@ -21,4 +21,9 @@ package body Pck is
       Inner.Inside_Variable := Not_In_Scope + I;
    end Proc;
 
+   procedure Ambiguous_Func is
+   begin
+      null;
+   end Ambiguous_Func;
+
 end Pck;
index ab2c47ba2f89cd08578dfcb8e880c02eda917504..e85f5663b8a82d6dc2a1c3335d36e7077e6349dc 100644 (file)
@@ -31,4 +31,6 @@ package Pck is
 
    procedure Proc (I : Integer);
 
+   procedure Ambiguous_Func;
+
 end Pck;