public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
* [PATCH] gdb/testsuite: add regression test for per-objfile typeprinters
@ 2023-02-23 13:13 Bruno Larsen
  2023-02-23 19:06 ` Andrew Burgess
  2023-02-23 19:50 ` Pedro Alves
  0 siblings, 2 replies; 3+ messages in thread
From: Bruno Larsen @ 2023-02-23 13:13 UTC (permalink / raw)
  To: gdb-patches; +Cc: Bruno Larsen

PR python/17136 reported an unhandled exception when using typeprinters
only valid on some objfiles, rather than being a global typeprinter. The
fix was accepted without a regression test, and we've been carrying one
out-of-tree for a while but I think it's worth upstreaming. The code
itself was developed by Jan Kratochvil.

Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=17136
---
 gdb/testsuite/gdb.python/py-typeprint.cc  |  6 ++++++
 gdb/testsuite/gdb.python/py-typeprint.exp |  4 ++++
 gdb/testsuite/gdb.python/py-typeprint.py  | 25 ++++++++++++++++++++---
 3 files changed, 32 insertions(+), 3 deletions(-)

diff --git a/gdb/testsuite/gdb.python/py-typeprint.cc b/gdb/testsuite/gdb.python/py-typeprint.cc
index ccd2ed02db1..3f274a73498 100644
--- a/gdb/testsuite/gdb.python/py-typeprint.cc
+++ b/gdb/testsuite/gdb.python/py-typeprint.cc
@@ -31,6 +31,12 @@ templ<basic_string> s;
 
 basic_string bs;
 
+class Other
+{
+};
+
+Other ovar;
+
 int main()
 {
   return 0;
diff --git a/gdb/testsuite/gdb.python/py-typeprint.exp b/gdb/testsuite/gdb.python/py-typeprint.exp
index 40f7e53847f..778583b9eff 100644
--- a/gdb/testsuite/gdb.python/py-typeprint.exp
+++ b/gdb/testsuite/gdb.python/py-typeprint.exp
@@ -48,3 +48,7 @@ gdb_test_no_output "enable type-printer string"
 gdb_test "whatis bs" "string" "whatis with enabled printer"
 
 gdb_test "whatis s" "templ<string>"
+
+gdb_test "info type-printers" "Type printers for \[^\r\n\]*/py-typeprint:\r\n *other\r\n.*" \
+	 "info type-printers for other"
+gdb_test "whatis ovar" "type = Another"
diff --git a/gdb/testsuite/gdb.python/py-typeprint.py b/gdb/testsuite/gdb.python/py-typeprint.py
index b5ba243889b..aac42a1a99a 100644
--- a/gdb/testsuite/gdb.python/py-typeprint.py
+++ b/gdb/testsuite/gdb.python/py-typeprint.py
@@ -15,8 +15,7 @@
 
 import gdb
 
-
-class Recognizer(object):
+class StringRecognizer(object):
     def __init__(self):
         self.enabled = True
 
@@ -32,7 +31,27 @@ class StringTypePrinter(object):
         self.enabled = True
 
     def instantiate(self):
-        return Recognizer()
+        return StringRecognizer()
 
 
 gdb.type_printers.append(StringTypePrinter())
+
+class OtherRecognizer(object):
+    def __init__(self):
+        self.enabled = True
+
+    def recognize(self, type_obj):
+        if type_obj.tag == 'Other':
+            return 'Another'
+        return None
+
+class OtherTypePrinter(object):
+    def __init__(self):
+        self.name = 'other'
+        self.enabled = True
+
+    def instantiate(self):
+        return OtherRecognizer()
+
+import gdb.types
+gdb.types.register_type_printer(gdb.objfiles()[0], OtherTypePrinter())
-- 
2.39.1


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] gdb/testsuite: add regression test for per-objfile typeprinters
  2023-02-23 13:13 [PATCH] gdb/testsuite: add regression test for per-objfile typeprinters Bruno Larsen
@ 2023-02-23 19:06 ` Andrew Burgess
  2023-02-23 19:50 ` Pedro Alves
  1 sibling, 0 replies; 3+ messages in thread
From: Andrew Burgess @ 2023-02-23 19:06 UTC (permalink / raw)
  To: Bruno Larsen via Gdb-patches, gdb-patches; +Cc: Bruno Larsen

Bruno Larsen via Gdb-patches <gdb-patches@sourceware.org> writes:

> PR python/17136 reported an unhandled exception when using typeprinters
> only valid on some objfiles, rather than being a global typeprinter. The
> fix was accepted without a regression test, and we've been carrying one
> out-of-tree for a while but I think it's worth upstreaming. The code
> itself was developed by Jan Kratochvil.

LGTM.

Reviewed-By: Andrew Burgess <aburgess@redhat.com>

Thanks,
Andrew

>
> Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=17136
> ---
>  gdb/testsuite/gdb.python/py-typeprint.cc  |  6 ++++++
>  gdb/testsuite/gdb.python/py-typeprint.exp |  4 ++++
>  gdb/testsuite/gdb.python/py-typeprint.py  | 25 ++++++++++++++++++++---
>  3 files changed, 32 insertions(+), 3 deletions(-)
>
> diff --git a/gdb/testsuite/gdb.python/py-typeprint.cc b/gdb/testsuite/gdb.python/py-typeprint.cc
> index ccd2ed02db1..3f274a73498 100644
> --- a/gdb/testsuite/gdb.python/py-typeprint.cc
> +++ b/gdb/testsuite/gdb.python/py-typeprint.cc
> @@ -31,6 +31,12 @@ templ<basic_string> s;
>  
>  basic_string bs;
>  
> +class Other
> +{
> +};
> +
> +Other ovar;
> +
>  int main()
>  {
>    return 0;
> diff --git a/gdb/testsuite/gdb.python/py-typeprint.exp b/gdb/testsuite/gdb.python/py-typeprint.exp
> index 40f7e53847f..778583b9eff 100644
> --- a/gdb/testsuite/gdb.python/py-typeprint.exp
> +++ b/gdb/testsuite/gdb.python/py-typeprint.exp
> @@ -48,3 +48,7 @@ gdb_test_no_output "enable type-printer string"
>  gdb_test "whatis bs" "string" "whatis with enabled printer"
>  
>  gdb_test "whatis s" "templ<string>"
> +
> +gdb_test "info type-printers" "Type printers for \[^\r\n\]*/py-typeprint:\r\n *other\r\n.*" \
> +	 "info type-printers for other"
> +gdb_test "whatis ovar" "type = Another"
> diff --git a/gdb/testsuite/gdb.python/py-typeprint.py b/gdb/testsuite/gdb.python/py-typeprint.py
> index b5ba243889b..aac42a1a99a 100644
> --- a/gdb/testsuite/gdb.python/py-typeprint.py
> +++ b/gdb/testsuite/gdb.python/py-typeprint.py
> @@ -15,8 +15,7 @@
>  
>  import gdb
>  
> -
> -class Recognizer(object):
> +class StringRecognizer(object):
>      def __init__(self):
>          self.enabled = True
>  
> @@ -32,7 +31,27 @@ class StringTypePrinter(object):
>          self.enabled = True
>  
>      def instantiate(self):
> -        return Recognizer()
> +        return StringRecognizer()
>  
>  
>  gdb.type_printers.append(StringTypePrinter())
> +
> +class OtherRecognizer(object):
> +    def __init__(self):
> +        self.enabled = True
> +
> +    def recognize(self, type_obj):
> +        if type_obj.tag == 'Other':
> +            return 'Another'
> +        return None
> +
> +class OtherTypePrinter(object):
> +    def __init__(self):
> +        self.name = 'other'
> +        self.enabled = True
> +
> +    def instantiate(self):
> +        return OtherRecognizer()
> +
> +import gdb.types
> +gdb.types.register_type_printer(gdb.objfiles()[0], OtherTypePrinter())
> -- 
> 2.39.1


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] gdb/testsuite: add regression test for per-objfile typeprinters
  2023-02-23 13:13 [PATCH] gdb/testsuite: add regression test for per-objfile typeprinters Bruno Larsen
  2023-02-23 19:06 ` Andrew Burgess
@ 2023-02-23 19:50 ` Pedro Alves
  1 sibling, 0 replies; 3+ messages in thread
From: Pedro Alves @ 2023-02-23 19:50 UTC (permalink / raw)
  To: Bruno Larsen, gdb-patches

On 2023-02-23 1:13 p.m., Bruno Larsen via Gdb-patches wrote:
> PR python/17136 reported an unhandled exception when using typeprinters
> only valid on some objfiles, rather than being a global typeprinter. The
> fix was accepted without a regression test, and we've been carrying one
> out-of-tree for a while but I think it's worth upstreaming. The code
> itself was developed by Jan Kratochvil.

That suggests that the patch should have Author: Jan, or Co-Authored-By: Jan.

Pedro Alves

> 
> Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=17136
> ---
>  gdb/testsuite/gdb.python/py-typeprint.cc  |  6 ++++++
>  gdb/testsuite/gdb.python/py-typeprint.exp |  4 ++++
>  gdb/testsuite/gdb.python/py-typeprint.py  | 25 ++++++++++++++++++++---
>  3 files changed, 32 insertions(+), 3 deletions(-)
> 
> diff --git a/gdb/testsuite/gdb.python/py-typeprint.cc b/gdb/testsuite/gdb.python/py-typeprint.cc
> index ccd2ed02db1..3f274a73498 100644
> --- a/gdb/testsuite/gdb.python/py-typeprint.cc
> +++ b/gdb/testsuite/gdb.python/py-typeprint.cc
> @@ -31,6 +31,12 @@ templ<basic_string> s;
>  
>  basic_string bs;
>  
> +class Other
> +{
> +};
> +
> +Other ovar;
> +
>  int main()
>  {
>    return 0;
> diff --git a/gdb/testsuite/gdb.python/py-typeprint.exp b/gdb/testsuite/gdb.python/py-typeprint.exp
> index 40f7e53847f..778583b9eff 100644
> --- a/gdb/testsuite/gdb.python/py-typeprint.exp
> +++ b/gdb/testsuite/gdb.python/py-typeprint.exp
> @@ -48,3 +48,7 @@ gdb_test_no_output "enable type-printer string"
>  gdb_test "whatis bs" "string" "whatis with enabled printer"
>  
>  gdb_test "whatis s" "templ<string>"
> +
> +gdb_test "info type-printers" "Type printers for \[^\r\n\]*/py-typeprint:\r\n *other\r\n.*" \
> +	 "info type-printers for other"
> +gdb_test "whatis ovar" "type = Another"
> diff --git a/gdb/testsuite/gdb.python/py-typeprint.py b/gdb/testsuite/gdb.python/py-typeprint.py
> index b5ba243889b..aac42a1a99a 100644
> --- a/gdb/testsuite/gdb.python/py-typeprint.py
> +++ b/gdb/testsuite/gdb.python/py-typeprint.py
> @@ -15,8 +15,7 @@
>  
>  import gdb
>  
> -
> -class Recognizer(object):
> +class StringRecognizer(object):
>      def __init__(self):
>          self.enabled = True
>  
> @@ -32,7 +31,27 @@ class StringTypePrinter(object):
>          self.enabled = True
>  
>      def instantiate(self):
> -        return Recognizer()
> +        return StringRecognizer()
>  
>  
>  gdb.type_printers.append(StringTypePrinter())
> +
> +class OtherRecognizer(object):
> +    def __init__(self):
> +        self.enabled = True
> +
> +    def recognize(self, type_obj):
> +        if type_obj.tag == 'Other':
> +            return 'Another'
> +        return None
> +
> +class OtherTypePrinter(object):
> +    def __init__(self):
> +        self.name = 'other'
> +        self.enabled = True
> +
> +    def instantiate(self):
> +        return OtherRecognizer()
> +
> +import gdb.types
> +gdb.types.register_type_printer(gdb.objfiles()[0], OtherTypePrinter())
> 


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2023-02-23 19:50 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-02-23 13:13 [PATCH] gdb/testsuite: add regression test for per-objfile typeprinters Bruno Larsen
2023-02-23 19:06 ` Andrew Burgess
2023-02-23 19:50 ` Pedro Alves

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).