Bug 29245 - [gdb/testsuite, python2] FAIL: gdb.python/py-mi-cmd.exp: -pycmd bk3 (unexpected output)
Summary: [gdb/testsuite, python2] FAIL: gdb.python/py-mi-cmd.exp: -pycmd bk3 (unexpect...
Status: RESOLVED WONTFIX
Alias: None
Product: gdb
Classification: Unclassified
Component: python (show other bugs)
Version: 12.1
: P2 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2022-06-11 16:05 UTC by Tom de Vries
Modified: 2022-06-13 16:14 UTC (History)
0 users

See Also:
Host:
Target:
Build:
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Tom de Vries 2022-06-11 16:05:16 UTC
For a gdb build with python 2, I run into:
...
Expecting: ^(-pycmd bk3[^M
]+)?(&"TypeError: __repr__ returned non-string \(type BadKey\).."^M
\^error,msg="Error occurred in Python: __repr__ returned non-string \(type BadKey\)"[^M
]+[(]gdb[)] ^M
[ ]*)
-pycmd bk3^M
&"TypeError: __repr__ returned non-string (type instance)\n"^M
^error,msg="Error occurred in Python: __repr__ returned non-string (type instance)"^M
(gdb) ^M
...
Comment 1 Tom de Vries 2022-06-11 16:20:04 UTC
Using a standalone reproducer:
...
$ cat test.py
class BadKey:
    def __repr__(self):
        return "Bad Key"


class ReallyBadKey:
    def __repr__(self):
        return BadKey()

a = {"result": {ReallyBadKey(): "world"}}

print (a)
...
we can see the behaviour with python3:
...
$ python3 test.py
Traceback (most recent call last):
  File "test.py", line 12, in <module>
    print (a)
TypeError: __repr__ returned non-string (type BadKey)
...
and python2:
...
$ python2 test.py
{'result': {Traceback (most recent call last):
  File "test.py", line 12, in <module>
    print (a)
TypeError: __repr__ returned non-string (type instance)
...
Comment 2 Tom de Vries 2022-06-13 16:14:29 UTC
This fixes it:
...
diff --git a/gdb/testsuite/gdb.python/py-mi-cmd.exp b/gdb/testsuite/gdb.python/py-mi-cmd.ex
p
index 300ab956892..5e4b6cd076e 100644
--- a/gdb/testsuite/gdb.python/py-mi-cmd.exp
+++ b/gdb/testsuite/gdb.python/py-mi-cmd.exp
@@ -68,8 +68,8 @@ mi_gdb_test "-pycmd bk2" \
 
 mi_gdb_test "-pycmd bk3" \
     [multi_line \
-        "&\"TypeError: __repr__ returned non-string \\(type BadKey\\)..\"" \
-        "\\^error,msg=\"Error occurred in Python: __repr__ returned non-string \\(type BadKey
\\)\""] \
+        "&\"TypeError: __repr__ returned non-string \\(type (BadKey|instance)\\)..\"" \
+        "\\^error,msg=\"Error occurred in Python: __repr__ returned non-string \\(type (B
adKey|instance)\\)\""] \
     "-pycmd bk3"
 
 mi_gdb_test "-pycmd tpl" \
...

I don't see a pressing need to fix this on the gdb-12-branch, so I'm closing this as resolved-wontfix.

Anybody running into this with gdb 12.x and finding it annoying can use the patch posted in this comment.