* [PATCH] Fix regression in pointer-to-member printing
@ 2022-10-18 17:53 Tom Tromey
2022-10-29 18:48 ` Joel Brobecker
0 siblings, 1 reply; 2+ messages in thread
From: Tom Tromey @ 2022-10-18 17:53 UTC (permalink / raw)
To: gdb-patches; +Cc: Tom Tromey
PR c++/29243 points out that "info func" on a certain C++ executable
will cause an infinite loop in gdb.
I tracked this down to a bug introduced by commit 6b5a7bc76 ("Handle
member pointers directly in generic_value_print"). Before this
commit, the C++ code to print a member pointer would wind up calling
value_print_scalar_formatted; but afterward it simply calls
generic_value_print and gets into a loop.
This patch restores the previous behavior and adds a regression test.
---
gdb/testsuite/gdb.cp/member-ptr.cc | 8 ++++++++
gdb/testsuite/gdb.cp/member-ptr.exp | 4 ++++
gdb/valprint.c | 2 +-
3 files changed, 13 insertions(+), 1 deletion(-)
diff --git a/gdb/testsuite/gdb.cp/member-ptr.cc b/gdb/testsuite/gdb.cp/member-ptr.cc
index 22ffcc58d39..a563d2e6af3 100644
--- a/gdb/testsuite/gdb.cp/member-ptr.cc
+++ b/gdb/testsuite/gdb.cp/member-ptr.cc
@@ -142,6 +142,11 @@ int Diamond::vget_base ()
return this->Left::x + 2000;
}
+struct Container
+{
+ PMI member;
+};
+
int
func (int x)
{
@@ -205,6 +210,9 @@ int main ()
null_pmi = NULL;
null_pmf = NULL;
+ Container contain;
+ contain.member = &A::j;
+
pmi = NULL; /* Breakpoint 1 here. */
(diamond.*diamond_pfunc_ptr) (20);
diff --git a/gdb/testsuite/gdb.cp/member-ptr.exp b/gdb/testsuite/gdb.cp/member-ptr.exp
index 110497b893b..5b91bcb493a 100644
--- a/gdb/testsuite/gdb.cp/member-ptr.exp
+++ b/gdb/testsuite/gdb.cp/member-ptr.exp
@@ -628,3 +628,7 @@ gdb_test "print null_pmi = 0" "$vhn = NULL"
gdb_test "print null_pmf" "$vhn = NULL"
gdb_test "print null_pmf = &A::foo" "$vhn = \\(int \\(A::\\*\\)\\(A \\*( const)?, int\\)\\) $hex <A::foo ?\\(int\\)>"
gdb_test "print null_pmf = 0" "$vhn = NULL"
+
+# Print with a format, bypassing the direct call to the scalar
+# printer. See PR c++/29243.
+gdb_test "print/x contain" " = {member = $hex}"
diff --git a/gdb/valprint.c b/gdb/valprint.c
index f079f31fa7b..585af69cb27 100644
--- a/gdb/valprint.c
+++ b/gdb/valprint.c
@@ -879,7 +879,7 @@ generic_value_print_memberptr
cp_print_class_member (valaddr, type, stream, "&");
}
else
- generic_value_print (val, stream, recurse, options, decorations);
+ value_print_scalar_formatted (val, options, 0, stream);
}
/* See valprint.h. */
--
2.34.3
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [PATCH] Fix regression in pointer-to-member printing
2022-10-18 17:53 [PATCH] Fix regression in pointer-to-member printing Tom Tromey
@ 2022-10-29 18:48 ` Joel Brobecker
0 siblings, 0 replies; 2+ messages in thread
From: Joel Brobecker @ 2022-10-29 18:48 UTC (permalink / raw)
To: Tom Tromey via Gdb-patches; +Cc: Tom Tromey, Joel Brobecker
Hi Tom,
On Tue, Oct 18, 2022 at 11:53:04AM -0600, Tom Tromey via Gdb-patches wrote:
> PR c++/29243 points out that "info func" on a certain C++ executable
> will cause an infinite loop in gdb.
>
> I tracked this down to a bug introduced by commit 6b5a7bc76 ("Handle
> member pointers directly in generic_value_print"). Before this
> commit, the C++ code to print a member pointer would wind up calling
> value_print_scalar_formatted; but afterward it simply calls
> generic_value_print and gets into a loop.
Thanks for the fix :-).
The patch looks good to me. Thanks also for including a regression
test!
> This patch restores the previous behavior and adds a regression test.
> ---
> gdb/testsuite/gdb.cp/member-ptr.cc | 8 ++++++++
> gdb/testsuite/gdb.cp/member-ptr.exp | 4 ++++
> gdb/valprint.c | 2 +-
> 3 files changed, 13 insertions(+), 1 deletion(-)
>
> diff --git a/gdb/testsuite/gdb.cp/member-ptr.cc b/gdb/testsuite/gdb.cp/member-ptr.cc
> index 22ffcc58d39..a563d2e6af3 100644
> --- a/gdb/testsuite/gdb.cp/member-ptr.cc
> +++ b/gdb/testsuite/gdb.cp/member-ptr.cc
> @@ -142,6 +142,11 @@ int Diamond::vget_base ()
> return this->Left::x + 2000;
> }
>
> +struct Container
> +{
> + PMI member;
> +};
> +
> int
> func (int x)
> {
> @@ -205,6 +210,9 @@ int main ()
> null_pmi = NULL;
> null_pmf = NULL;
>
> + Container contain;
> + contain.member = &A::j;
> +
> pmi = NULL; /* Breakpoint 1 here. */
>
> (diamond.*diamond_pfunc_ptr) (20);
> diff --git a/gdb/testsuite/gdb.cp/member-ptr.exp b/gdb/testsuite/gdb.cp/member-ptr.exp
> index 110497b893b..5b91bcb493a 100644
> --- a/gdb/testsuite/gdb.cp/member-ptr.exp
> +++ b/gdb/testsuite/gdb.cp/member-ptr.exp
> @@ -628,3 +628,7 @@ gdb_test "print null_pmi = 0" "$vhn = NULL"
> gdb_test "print null_pmf" "$vhn = NULL"
> gdb_test "print null_pmf = &A::foo" "$vhn = \\(int \\(A::\\*\\)\\(A \\*( const)?, int\\)\\) $hex <A::foo ?\\(int\\)>"
> gdb_test "print null_pmf = 0" "$vhn = NULL"
> +
> +# Print with a format, bypassing the direct call to the scalar
> +# printer. See PR c++/29243.
> +gdb_test "print/x contain" " = {member = $hex}"
> diff --git a/gdb/valprint.c b/gdb/valprint.c
> index f079f31fa7b..585af69cb27 100644
> --- a/gdb/valprint.c
> +++ b/gdb/valprint.c
> @@ -879,7 +879,7 @@ generic_value_print_memberptr
> cp_print_class_member (valaddr, type, stream, "&");
> }
> else
> - generic_value_print (val, stream, recurse, options, decorations);
> + value_print_scalar_formatted (val, options, 0, stream);
> }
>
> /* See valprint.h. */
> --
> 2.34.3
>
--
Joel
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2022-10-29 18:48 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-10-18 17:53 [PATCH] Fix regression in pointer-to-member printing Tom Tromey
2022-10-29 18:48 ` Joel Brobecker
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).