aboutsummaryrefslogtreecommitdiff
path: root/gdb
diff options
context:
space:
mode:
authorBruno Larsen <blarsen@redhat.com>2023-02-23 13:56:32 +0100
committerBruno Larsen <blarsen@redhat.com>2023-03-13 14:40:33 +0100
commit83b755117d7a13e75877c3f166dfef1d8b69ec75 (patch)
treefb7dffba8635514e76e66f8aa9389d0fc2f741a2 /gdb
parent349a125d16bec4a894e01494df10a2825195178e (diff)
downloadgdb-83b755117d7a13e75877c3f166dfef1d8b69ec75.zip
gdb-83b755117d7a13e75877c3f166dfef1d8b69ec75.tar.gz
gdb-83b755117d7a13e75877c3f166dfef1d8b69ec75.tar.bz2
gdb/testsuite: add regression test for per-objfile typeprinters
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. Co-Authored-By: Jan Kratochvil <jkratochvil@azul.com> Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=17136 Reviewed-By: Andrew Burgess <aburgess@redhat.com> Approved-By: Tom Tromey <tom@tromey.com>
Diffstat (limited to 'gdb')
-rw-r--r--gdb/testsuite/gdb.python/py-typeprint.cc6
-rw-r--r--gdb/testsuite/gdb.python/py-typeprint.exp4
-rw-r--r--gdb/testsuite/gdb.python/py-typeprint.py25
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 ccd2ed0..3f274a7 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 40f7e53..778583b 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 b5ba2438..aac42a1 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())