Debugging a Cython extension for Python3 using cygdb

247 views
Skip to first unread message

Antony Lee

unread,
Aug 22, 2015, 11:51:48 PM8/22/15
to cython...@googlegroups.com
I am trying to debug Python3 extensions with cygdb.  Currently, whether I run

    $ python2 `which cygdb` . -vv -- --args /usr/bin/python3 run.py

or

    $ python3 `which cygdb` . -vv -- --args /usr/bin/python3 run.py

(where run.py is a file that invokes an intentionally crashing cython extension), calling `cy bt` at the gdb CLI results in the following error:

    (gdb) cy bt
    Python Exception <class 'gdb.error'> Cannot convert value to int.:
    Error occurred in Python command: Cannot convert value to int.

Setting `python print-stack` to `full` shows that the error actually happens in the call to `PyObjectPtr.is_null` (in `Cython.Debugger.libpython`); `int` is called on an object of type `gdb.Value` (I cannot locate where this class is defined).

Note that at that point, regardless of the invocation of cygdb, the Python interpreter used by gdb is Python2.

Any help would be welcome.

This is on Arch Linux with gdb 7.9.1, python3 3.4.1, python2 2.7.10, cython{2,3} 0.23.

cross-posted to stackoverflow

Antony Lee

Ralf Stephan

unread,
Sep 21, 2015, 3:40:06 AM9/21/15
to cython-users, anton...@berkeley.edu
On Sunday, August 23, 2015 at 5:51:48 AM UTC+2, Antony Lee wrote:
    (gdb) cy bt
    Python Exception <class 'gdb.error'> Cannot convert value to int.:
 
Any news on that? I'm getting this line several times per frame in
gdb backtraces of my Sage sessions.

Regards,

Stefan Behnel

unread,
Sep 21, 2015, 3:57:22 AM9/21/15
to cython...@googlegroups.com
I'm seeing that in the tests, too. My hypothesis is that values turn up as
literal byte strings somehow (i.e. 'b"123"') and then int() is unable to
parse them.

Does this patch help? If not, could you come up with a fix that solves it
for you?

Stefan

cygdb.patch

Antony Lee

unread,
Sep 21, 2015, 7:22:04 PM9/21/15
to cython...@googlegroups.com
Applying the patch changes the error to

Python Exception <class 'TypeError'> must be str, not bytes:
/tmp/tmpgBBuKz:21: Error in sourced command file:
Error occurred in Python command: must be str, not bytes

Unfortunately I don't know how to get the traceback (of the gdb-command-implemented-in-python) printed by gdb.  That would probably help debugging the debugger :-)

Antony


Stefan

--

---
You received this message because you are subscribed to the Google Groups "cython-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cython-users...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Ralf Stephan

unread,
Aug 24, 2016, 9:57:39 AM8/24/16
to cython-users, stef...@behnel.de
Since there is no clear soluton visible I worked around it
by hacking gdb:

diff --git b/gdb/python/py-value.c.orig a/gdb/python/py-value.c
index 6d04223..65a367a 100644
--- b/gdb/python/py-value.c.orig
+++ a/gdb/python/py-value.c
@@ -1480,7 +1480,7 @@ valpy_int (PyObject *self)
  TRY
    {
      if (!is_integral_type (type))
-       error (_("Cannot convert value to int."));
+       ;//error (_("Cannot convert value to int."));

      l = value_as_long (value);
    }

Reply all
Reply to author
Forward
0 new messages