[PATCH] Fix printing destructors with void in parameters for clang programs
Bruno Larsen
blarsen@redhat.com
Fri Sep 23 15:50:14 GMT 2022
When GDB prints the methods of a C++ class, it will always skip the first
parameter, assuming it to be a 'this' pointer. However, when deciding if
it should print "void" for the parameters, it disregards the fact that
the first parameter was skipped, so if the method only had that
parameter, for instance how clang compiles destructors, we'd see
~foo(void) instead of ~foo().
Fix this behavior by explicitly testing if there were 0 arguments.
---
There is another possibility for a fix, which is to stop ignoring the
first parameter, but there is a comment at that part of the code that
says "some compilers may not support artificial parameters".
I'm not sure how true that still is, and I would certainly like a
solution like that more, since (as keiths points out in here:
https://sourceware.org/bugzilla/show_bug.cgi?id=8218) there is no actual
rule saying that compilers must use an artificial 'this' as the first
parameter. If anyone knows, please share with the class :)
---
gdb/c-typeprint.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/gdb/c-typeprint.c b/gdb/c-typeprint.c
index 3a611cdac5d..8e05bdc81fe 100644
--- a/gdb/c-typeprint.c
+++ b/gdb/c-typeprint.c
@@ -300,7 +300,7 @@ cp_type_print_method_args (struct type *mtype, const char *prefix,
}
else if (varargs)
gdb_printf (stream, "...");
- else if (language == language_cplus)
+ else if (language == language_cplus && nargs == 0)
gdb_printf (stream, "void");
gdb_printf (stream, ")");
--
2.37.3
More information about the Gdb-patches
mailing list