Discussion:
[Bug gdb/22481] New: Python Exception <class 'gdb.error'> Trying to read string with inappropriate type `int'.:
hi-angel at yandex dot ru
2017-11-23 11:54:45 UTC
Permalink
https://sourceware.org/bugzilla/show_bug.cgi?id=22481

Bug ID: 22481
Summary: Python Exception <class 'gdb.error'> Trying to read
string with inappropriate type `int'.:
Product: gdb
Version: 8.0.1
Status: UNCONFIRMED
Severity: normal
Priority: P2
Component: gdb
Assignee: unassigned at sourceware dot org
Reporter: hi-angel at yandex dot ru
Target Milestone: ---

#Steps to reproduce:

1. Write the following code to ~/gdb.py

class my_print:
def __init__(self, val):
self.val = val
def to_string(self):
return self.val.string()

def lookup_type_my_int (val):
if str(val.type) == 'int':
return my_print(val)
return None

gdb.pretty_printers.append(lookup_type_my_int)

2. Run `gdb -nh`
3. type `source ~/gdb.py`
4. type `print 1`

Expected result: the value of "val" is printed
Actual results: error "$1 = Python Exception <class 'gdb.error'> Trying to read
string with inappropriate type `int'.:".

#Additional info:

python version 3.6.3

Some more results because this issue might be useful for someone coming from
google in attempt to use pretty printers:

Using "return str(self.val)" results in "$1 = Python Exception <class
'RecursionError'> maximum recursion depth exceeded in comparison:
1"

And using simply "return self.val" results in "[1] 29554 segmentation fault
(core dumped) gdb -q -nh"
--
You are receiving this mail because:
You are on the CC list for the bug.
tromey at sourceware dot org
2018-04-01 17:33:11 UTC
Permalink
https://sourceware.org/bugzilla/show_bug.cgi?id=22481

Tom Tromey <tromey at sourceware dot org> changed:

What |Removed |Added
----------------------------------------------------------------------------
CC| |tromey at sourceware dot org
Component|gdb |python
--
You are receiving this mail because:
You are on the CC list for the bug.
tromey at sourceware dot org
2018-09-15 00:04:37 UTC
Permalink
https://sourceware.org/bugzilla/show_bug.cgi?id=22481

Tom Tromey <tromey at sourceware dot org> changed:

What |Removed |Added
----------------------------------------------------------------------------
Status|UNCONFIRMED |RESOLVED
Resolution|--- |INVALID

--- Comment #1 from Tom Tromey <tromey at sourceware dot org> ---
I think these are not really bugs in Python.
Post by hi-angel at yandex dot ru
return self.val.string()
Here, string is a method on gdb.Value that tries to extract
a string from the inferior. It's an error to call this on
an integer value.

The other cases are infinite recursion in that printer,
because the printer returns a value of type int -- which the
printer is accepting.

So, I am going to close this.

Please reopen with some commentary if you think this is in error.
--
You are receiving this mail because:
You are on the CC list for the bug.
Loading...