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/gdbtypes.c | |
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/gdbtypes.c')
-rw-r--r-- | gdb/gdbtypes.c | 9 |
1 files changed, 6 insertions, 3 deletions
diff --git a/gdb/gdbtypes.c b/gdb/gdbtypes.c index 4c70c9b..2580b4f 100644 --- a/gdb/gdbtypes.c +++ b/gdb/gdbtypes.c @@ -76,6 +76,7 @@ const struct rank REFERENCE_SEE_THROUGH_BADNESS = {0,1}; const struct rank NULL_POINTER_CONVERSION_BADNESS = {2,0}; const struct rank NS_POINTER_CONVERSION_BADNESS = {10,0}; const struct rank NS_INTEGER_POINTER_CONVERSION_BADNESS = {3,0}; +const struct rank VARARG_BADNESS = {4, 0}; /* Floatformat pairs. */ const struct floatformat *floatformats_ieee_half[BFD_ENDIAN_UNKNOWN] = { @@ -4038,7 +4039,8 @@ compare_badness (const badness_vector &a, const badness_vector &b) badness_vector rank_function (gdb::array_view<type *> parms, - gdb::array_view<value *> args) + gdb::array_view<value *> args, + bool varargs) { /* add 1 for the length-match rank. */ badness_vector bv; @@ -4051,7 +4053,8 @@ rank_function (gdb::array_view<type *> parms, arguments and ellipsis parameter lists, we should consider those and rank the length-match more finely. */ - bv.push_back ((args.size () != parms.size ()) + bv.push_back ((args.size () != parms.size () + && (! varargs || args.size () < parms.size ())) ? LENGTH_MISMATCH_BADNESS : EXACT_MATCH_BADNESS); @@ -4064,7 +4067,7 @@ rank_function (gdb::array_view<type *> parms, /* If more arguments than parameters, add dummy entries. */ for (size_t i = min_len; i < args.size (); i++) - bv.push_back (TOO_FEW_PARAMS_BADNESS); + bv.push_back (varargs ? VARARG_BADNESS : TOO_FEW_PARAMS_BADNESS); return bv; } |