This is the mail archive of the gdb-prs@sourceware.org mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug python/14320] New: Strange python script behaviour


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.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]