summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSimon Marchi <simon.marchi@polymtl.ca>2016-01-19 11:07:07 -0500
committerSimon Marchi <simon.marchi@ericsson.com>2016-01-19 11:07:07 -0500
commit10e3ed9029dc0b6eafcd991d9f292fc079f80cf5 (patch)
tree90471041d197089071fe50eb448de4a6a4354559
parent41d1845edace3cf5dabd0aa7fa376b801fd5f675 (diff)
downloadbinutils-gdb-10e3ed9029dc0b6eafcd991d9f292fc079f80cf5.tar.gz
Fix enum flag with Python 3
Using Python 3.5 (I assume it's the same with 3.4 and lower, but I didn't test), I see this: print (enum flag_enum) (FLAG_1)^M Python Exception <class 'TypeError'> %x format: an integer is required, not gdb.Value: ^M $7 = ^M (gdb) FAIL: gdb.python/py-pp-maint.exp: print FLAG_1 Apparently, this idiom, where v is a gdb.Value, was possible with Python 2, but not with Python 3: '%x' % v In Python 2, it would automatically get converted to an integer. To solve it, I simply added wrapped v in a call to int(). '%x' % int(v) In Python 2, the int type is implemented with a "long" in C, so on x86-32 it's 32-bits. I was worried that doing int(v) would truncate the value and give wrong results for enum values > 32-bits. However, the int type != the int function. The int function does the right thing, selecting the right integer type for the given value. I tested with large enum values on x86-32 and Python 2, and everything works as expected. gdb/ChangeLog: * python/lib/gdb/printing.py (_EnumInstance.to_string): Explicitly convert gdb.Value to integer type using int().
-rw-r--r--gdb/ChangeLog5
-rw-r--r--gdb/python/lib/gdb/printing.py2
2 files changed, 6 insertions, 1 deletions
diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index 2e171238597..40b5deb518e 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,3 +1,8 @@
+2016-01-19 Simon Marchi <simon.marchi@polymtl.ca>
+
+ * python/lib/gdb/printing.py (_EnumInstance.to_string): Explicitly
+ convert gdb.Value to integer type using int().
+
2016-01-19 John Baldwin <jhb@FreeBSD.org>
* configure.ac: Include <sys/types.h when checking for "r_fs" in
diff --git a/gdb/python/lib/gdb/printing.py b/gdb/python/lib/gdb/printing.py
index 263d3ba8995..5160581a5b2 100644
--- a/gdb/python/lib/gdb/printing.py
+++ b/gdb/python/lib/gdb/printing.py
@@ -239,7 +239,7 @@ class _EnumInstance:
if not any_found or v != 0:
# Leftover value.
flag_list.append('<unknown: 0x%x>' % v)
- return "0x%x [%s]" % (self.val, " | ".join(flag_list))
+ return "0x%x [%s]" % (int(self.val), " | ".join(flag_list))
class FlagEnumerationPrinter(PrettyPrinter):
"""A pretty-printer which can be used to print a flag-style enumeration.