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

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