diff options
author | Hannes Domani <ssbssa@yahoo.de> | 2021-11-14 16:19:31 +0100 |
---|---|---|
committer | Hannes Domani <ssbssa@yahoo.de> | 2023-12-14 16:18:25 +0100 |
commit | 1d2f86b6b74e6caae77951353a4c353ce9816374 (patch) | |
tree | 18726cba53da75f6b9d1d4fba100dd7071c5f59a /gdb/testsuite/gdb.cp | |
parent | 8cb16b68584e14aade8de166c75e1d85e38507bd (diff) | |
download | gdb-1d2f86b6b74e6caae77951353a4c353ce9816374.zip gdb-1d2f86b6b74e6caae77951353a4c353ce9816374.tar.gz gdb-1d2f86b6b74e6caae77951353a4c353ce9816374.tar.bz2 |
Allow calling of variadic C++ functions
Currently, it's not possible to call a variadic C++ function:
```
(gdb) print sum_vararg_int(1, 10)
Cannot resolve function sum_vararg_int to any overloaded instance
(gdb) print sum_vararg_int(2, 20, 30)
Cannot resolve function sum_vararg_int to any overloaded instance
```
It's because all additional arguments get the TOO_FEW_PARAMS_BADNESS
rank by rank_function, which disqualifies the function.
To fix this, I've created the new VARARG_BADNESS rank, which is
used only for additional arguments of variadic functions, allowing
them to be called:
```
(gdb) print sum_vararg_int(1, 10)
$1 = 10
(gdb) print sum_vararg_int(2, 20, 30)
$2 = 50
```
Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=28589
Approved-By: Tom Tromey <tom@tromey.com>
Diffstat (limited to 'gdb/testsuite/gdb.cp')
-rw-r--r-- | gdb/testsuite/gdb.cp/call-c.cc | 26 | ||||
-rw-r--r-- | gdb/testsuite/gdb.cp/call-c.exp | 13 |
2 files changed, 39 insertions, 0 deletions
diff --git a/gdb/testsuite/gdb.cp/call-c.cc b/gdb/testsuite/gdb.cp/call-c.cc index 4362bbf..1677755 100644 --- a/gdb/testsuite/gdb.cp/call-c.cc +++ b/gdb/testsuite/gdb.cp/call-c.cc @@ -15,6 +15,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/>. */ +#include <stdarg.h> + int func(int x) { return x; @@ -33,6 +35,29 @@ extern "C" { int foo(int); } +int sum_vararg_int (int count, ...) +{ + va_list va; + int sum = 0; + + va_start (va, count); + for (int i = 0; i < count; i++) + sum += va_arg (va, int); + va_end (va); + + return sum; +} + +int vararg_func (int a, ...) +{ + return 1; +} + +int vararg_func (int a, int b, ...) +{ + return 2; +} + int main() { Foo f; @@ -41,5 +66,6 @@ int main() FooHandle handle = pf; rf->func(); /* set breakpoint here */ foo(0); + sum_vararg_int (1, 5); return func(0); } diff --git a/gdb/testsuite/gdb.cp/call-c.exp b/gdb/testsuite/gdb.cp/call-c.exp index b20bc86..36c0c1e 100644 --- a/gdb/testsuite/gdb.cp/call-c.exp +++ b/gdb/testsuite/gdb.cp/call-c.exp @@ -38,5 +38,18 @@ gdb_test "print foo(1)" "\\\$$decimal = 1" gdb_test "continue" ".*breakpoint here.*" "continue to bp" gdb_test "print rf->func()" "\\\$$decimal = 1" +gdb_test "print sum_vararg_int(0)" "0" +gdb_test "print sum_vararg_int(1, 10)" "10" +gdb_test "print sum_vararg_int(2, 20, 30)" "50" +gdb_test "print sum_vararg_int(5, 20, 30, 40, 50, 60)" "200" + +gdb_test "print vararg_func(1)" "1" +gdb_test "print vararg_func(2, 3)" "2" +gdb_test "print vararg_func(4, 5.5)" "2" +gdb_test "print vararg_func(6, \"7\")" "1" +gdb_test "print vararg_func(8, 9, 10)" "2" +gdb_test "print vararg_func(11, 12, 13.5)" "2" +gdb_test "print vararg_func(14, 15, \"16\")" "2" + # Regression test for method call via a typedef. gdb_test "print handle->func()" "\\\$$decimal = 1" |