Discussion:
[Bug python/18170] New: Why does valpy_int disallow pointers?
dje at google dot com
2015-03-27 16:52:37 UTC
Permalink
https://sourceware.org/bugzilla/show_bug.cgi?id=18170

Bug ID: 18170
Summary: Why does valpy_int disallow pointers?
Product: gdb
Version: HEAD
Status: NEW
Severity: normal
Priority: P2
Component: python
Assignee: unassigned at sourceware dot org
Reporter: dje at google dot com

This came up on #gdb.

(gdb) py print int(gdb.parse_and_eval('$ebp'))
Traceback (most recent call last):
File "<string>", line 1, in <module>
gdb.error: Cannot convert value to int.
Error while executing Python code.
(gdb) py print long(gdb.parse_and_eval('$ebp'))
4294957336
(gdb)

For python3, we use valpy_long for int conversions:

#ifdef IS_PY3K
valpy_long, /* nb_int */
NULL, /* reserved */
#else
NULL, /* nb_coerce */
valpy_int, /* nb_int */
valpy_long, /* nb_long */
#endif

There's no explanation in the code of why things are the way they are.
If there's a concern about loss of precision such things should be
explicitly caught instead of assuming int(gdb.parse_and_eval('some_pointer'))
won't fit. I'm guessing, however, this is just oversight.
Next step would be to start going through commit logs and emails.
--
You are receiving this mail because:
You are on the CC list for the bug.
tromey at sourceware dot org
2018-09-14 23:52:45 UTC
Permalink
https://sourceware.org/bugzilla/show_bug.cgi?id=18170

Tom Tromey <tromey at sourceware dot org> changed:

What |Removed |Added
----------------------------------------------------------------------------
CC| |tromey at sourceware dot org
Assignee|unassigned at sourceware dot org |tromey at sourceware dot org
--
You are receiving this mail because:
You are on the CC list for the bug.
cvs-commit at gcc dot gnu.org
2018-09-24 05:17:02 UTC
Permalink
https://sourceware.org/bugzilla/show_bug.cgi?id=18170

--- Comment #1 from cvs-commit at gcc dot gnu.org <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by Tom Tromey <***@sourceware.org>:

https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=f5769a2c696affc3ae1274e2329777d7d4d7e8be

commit f5769a2c696affc3ae1274e2329777d7d4d7e8be
Author: Tom Tromey <***@tromey.com>
Date: Fri Sep 14 23:20:58 2018 -0600

Allow conversion of pointers to Python int

PR python/18170 questions why it's not possible to convert a pointer
value to a Python int.

Digging a bit shows that the Python 2.7 int() constructor will happily
return a long in some cases. And, it seems gdb already understands
this in other places -- this is what gdb_py_object_from_longest
handles.

So, this patch simply extends valpy_int to allow pointer conversions,
as valpy_long does.

gdb/ChangeLog
2018-09-23 Tom Tromey <***@tromey.com>

PR python/18170:
* python/py-value.c (valpy_int): Allow conversion from pointer
type.

gdb/testsuite/ChangeLog
2018-09-23 Tom Tromey <***@tromey.com>

PR python/18170:
* gdb.python/py-value.exp (test_value_numeric_ops): Add tests to
convert pointers to int and long.
--
You are receiving this mail because:
You are on the CC list for the bug.
tromey at sourceware dot org
2018-09-23 23:48:08 UTC
Permalink
https://sourceware.org/bugzilla/show_bug.cgi?id=18170

Tom Tromey <tromey at sourceware dot org> changed:

What |Removed |Added
----------------------------------------------------------------------------
Status|NEW |RESOLVED
Resolution|--- |FIXED
Target Milestone|--- |8.3

--- Comment #2 from Tom Tromey <tromey at sourceware dot org> ---
Fixed.
--
You are receiving this mail because:
You are on the CC list for the bug.
Loading...