public inbox for gdb-prs@sourceware.org
help / color / mirror / Atom feed
* [Bug python/14320] New: Strange python script behaviour
@ 2012-07-01 18:43 zub at linux dot fjfi.cvut.cz
  2012-07-01 18:47 ` [Bug python/14320] " zub at linux dot fjfi.cvut.cz
                   ` (5 more replies)
  0 siblings, 6 replies; 7+ messages in thread
From: zub at linux dot fjfi.cvut.cz @ 2012-07-01 18:43 UTC (permalink / raw)
  To: gdb-prs

http://sourceware.org/bugzilla/show_bug.cgi?id=14320

             Bug #: 14320
           Summary: Strange python script behaviour
           Product: gdb
           Version: 7.4
            Status: NEW
          Severity: normal
          Priority: P2
         Component: python
        AssignedTo: unassigned@sourceware.org
        ReportedBy: zub@linux.fjfi.cvut.cz
    Classification: Unclassified
            Target: x86, x86_64


Created attachment 6506
  --> http://sourceware.org/bugzilla/attachment.cgi?id=6506
Standalone testcase.

I found a strange behaviour trying to implement a pretty printer. Attached is a
test case (just unpack and run make). The issue is reproducible both with 7.4.1
release and with CVS head as of now (7.4.50.20120701-cvs). (It's also present
in Debian testing and Ubuntu 12.04.)

Assumming a C++ class:

struct Foo
{
    int *m_ptr;
};

the following pretty printing class:

class MyTestPrinter:
    def __init__(self, val):
        self.val = val

    def get_ptr(self):
        return self.val['m_ptr']

    def children(self):
        print "foo"

    def to_string(self):
        return "0x%08x" % self.get_ptr()

causes a strange error message:

$1 = 0x7fffffffe390Traceback (most recent call last):
  File "test-printer.py", line 11, in children
    print "foo"
  File "<string>", line 13, in write
gdb.error: Cannot convert value to int.


The body of MyTestPrinter.to_string() might be wrong (using a gdb.Value for a
pointer with %08x), but the actual error message complains about the 'print
"foo"'. But the print is ok, so the error message is highly confusing.

To make this matter more mysterious, doing any of the following makes the error
disappear:

* remove MyTestPrinter.children()
* add a long cast to MyTestPrinter.to_string(): return "0x%08x" %
long(self.get_ptr())

So, if MyTestPrinter.to_string() is wrong, it should produce an appropriate
error message, and it should be consistent, no matter if there's any
MyTestPrinter.children() or not. Or, if MyTestPrinter.to_string() is correct,
then the print in MyTestPrinter.children() should not cause any error.

It seems that it's not caused by print (in MyTestPrinter.children()) itself,
but by the string literal, as I can get the same kind of error message for
other things involving string literals in MyTestPrinter.children().

-- 
Configure bugmail: http://sourceware.org/bugzilla/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are on the CC list for the bug.


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

* [Bug python/14320] Strange python script behaviour
  2012-07-01 18:43 [Bug python/14320] New: Strange python script behaviour zub at linux dot fjfi.cvut.cz
@ 2012-07-01 18:47 ` zub at linux dot fjfi.cvut.cz
  2012-07-01 19:03 ` zub at linux dot fjfi.cvut.cz
                   ` (4 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: zub at linux dot fjfi.cvut.cz @ 2012-07-01 18:47 UTC (permalink / raw)
  To: gdb-prs

http://sourceware.org/bugzilla/show_bug.cgi?id=14320

David Kozub <zub at linux dot fjfi.cvut.cz> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
               Host|                            |x86, x86_64

-- 
Configure bugmail: http://sourceware.org/bugzilla/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are on the CC list for the bug.


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

* [Bug python/14320] Strange python script behaviour
  2012-07-01 18:43 [Bug python/14320] New: Strange python script behaviour zub at linux dot fjfi.cvut.cz
  2012-07-01 18:47 ` [Bug python/14320] " zub at linux dot fjfi.cvut.cz
@ 2012-07-01 19:03 ` zub at linux dot fjfi.cvut.cz
  2012-07-01 19:22 ` zub at linux dot fjfi.cvut.cz
                   ` (3 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: zub at linux dot fjfi.cvut.cz @ 2012-07-01 19:03 UTC (permalink / raw)
  To: gdb-prs

http://sourceware.org/bugzilla/show_bug.cgi?id=14320

--- Comment #1 from David Kozub <zub at linux dot fjfi.cvut.cz> 2012-07-01 19:02:17 UTC ---
Just to clarify: MyTestPrinter.children() is wrong in not returning an
iterable. But the strange error happens even before MyTestPrinter.children()
returns, so I believe it's not related to this.

The attached testcase is just a bare minimum code to trigger this.

-- 
Configure bugmail: http://sourceware.org/bugzilla/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are on the CC list for the bug.


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

* [Bug python/14320] Strange python script behaviour
  2012-07-01 18:43 [Bug python/14320] New: Strange python script behaviour zub at linux dot fjfi.cvut.cz
  2012-07-01 18:47 ` [Bug python/14320] " zub at linux dot fjfi.cvut.cz
  2012-07-01 19:03 ` zub at linux dot fjfi.cvut.cz
@ 2012-07-01 19:22 ` zub at linux dot fjfi.cvut.cz
  2012-07-31 16:50 ` tromey at redhat dot com
                   ` (2 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: zub at linux dot fjfi.cvut.cz @ 2012-07-01 19:22 UTC (permalink / raw)
  To: gdb-prs

http://sourceware.org/bugzilla/show_bug.cgi?id=14320

David Kozub <zub at linux dot fjfi.cvut.cz> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Target|x86, x86_64                 |x86-linux-gnu,
                   |                            |x86_64-linux-gnu
               Host|x86, x86_64                 |x86-linux-gnu,
                   |                            |x86_64-linux-gnu

-- 
Configure bugmail: http://sourceware.org/bugzilla/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are on the CC list for the bug.


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

* [Bug python/14320] Strange python script behaviour
  2012-07-01 18:43 [Bug python/14320] New: Strange python script behaviour zub at linux dot fjfi.cvut.cz
                   ` (2 preceding siblings ...)
  2012-07-01 19:22 ` zub at linux dot fjfi.cvut.cz
@ 2012-07-31 16:50 ` tromey at redhat dot com
  2012-07-31 20:01 ` tromey at redhat dot com
  2012-08-01 16:54 ` tromey at redhat dot com
  5 siblings, 0 replies; 7+ messages in thread
From: tromey at redhat dot com @ 2012-07-31 16:50 UTC (permalink / raw)
  To: gdb-prs

http://sourceware.org/bugzilla/show_bug.cgi?id=14320

Tom Tromey <tromey at redhat dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |tromey at redhat dot com

--- Comment #2 from Tom Tromey <tromey at redhat dot com> 2012-07-31 16:50:15 UTC ---
I believe this is a bug in Python.
I'm going to file a bug there.

The pretty-printer does:

    def to_string(self):
        return "0x%08x" % self.get_ptr()

but in gdb, one cannot convert a pointer-valued gdb.Value
to a Python integer.

Python tries to convert it to a long:

                        iobj = PyNumber_Int(v);
                        if (iobj==NULL) iobj = PyNumber_Long(v);

... but I think it ought to be clearing the exception here
before calling PyNumber_Long.

-- 
Configure bugmail: http://sourceware.org/bugzilla/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are on the CC list for the bug.


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

* [Bug python/14320] Strange python script behaviour
  2012-07-01 18:43 [Bug python/14320] New: Strange python script behaviour zub at linux dot fjfi.cvut.cz
                   ` (3 preceding siblings ...)
  2012-07-31 16:50 ` tromey at redhat dot com
@ 2012-07-31 20:01 ` tromey at redhat dot com
  2012-08-01 16:54 ` tromey at redhat dot com
  5 siblings, 0 replies; 7+ messages in thread
From: tromey at redhat dot com @ 2012-07-31 20:01 UTC (permalink / raw)
  To: gdb-prs

http://sourceware.org/bugzilla/show_bug.cgi?id=14320

--- Comment #3 from Tom Tromey <tromey at redhat dot com> 2012-07-31 20:00:53 UTC ---
This is now http://bugs.python.org/issue15516

-- 
Configure bugmail: http://sourceware.org/bugzilla/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are on the CC list for the bug.


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

* [Bug python/14320] Strange python script behaviour
  2012-07-01 18:43 [Bug python/14320] New: Strange python script behaviour zub at linux dot fjfi.cvut.cz
                   ` (4 preceding siblings ...)
  2012-07-31 20:01 ` tromey at redhat dot com
@ 2012-08-01 16:54 ` tromey at redhat dot com
  5 siblings, 0 replies; 7+ messages in thread
From: tromey at redhat dot com @ 2012-08-01 16:54 UTC (permalink / raw)
  To: gdb-prs

http://sourceware.org/bugzilla/show_bug.cgi?id=14320

Tom Tromey <tromey at redhat dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|                            |MOVED

--- Comment #4 from Tom Tromey <tromey at redhat dot com> 2012-08-01 16:53:55 UTC ---
Not a gdb bug; and I don't think there's a reasonable
workaround in gdb.

-- 
Configure bugmail: http://sourceware.org/bugzilla/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are on the CC list for the bug.


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

end of thread, other threads:[~2012-08-01 16:54 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-07-01 18:43 [Bug python/14320] New: Strange python script behaviour zub at linux dot fjfi.cvut.cz
2012-07-01 18:47 ` [Bug python/14320] " zub at linux dot fjfi.cvut.cz
2012-07-01 19:03 ` zub at linux dot fjfi.cvut.cz
2012-07-01 19:22 ` zub at linux dot fjfi.cvut.cz
2012-07-31 16:50 ` tromey at redhat dot com
2012-07-31 20:01 ` tromey at redhat dot com
2012-08-01 16:54 ` tromey at redhat dot com

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