binutils-gdb/gdb/python
Simon Marchi 10e3ed9029 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().
2016-01-19 11:07:07 -05:00
..
lib/gdb Fix enum flag with Python 3 2016-01-19 11:07:07 -05:00
py-arch.c
py-auto-load.c
py-block.c
py-bpevent.c
py-breakpoint.c Per-inferior/Inferior-qualified thread IDs 2016-01-13 10:59:43 +00:00
py-cmd.c
py-continueevent.c
py-event.c
py-event.h
py-events.h
py-evtregistry.c
py-evts.c
py-exitedevent.c
py-finishbreakpoint.c Per-inferior/Inferior-qualified thread IDs 2016-01-13 10:59:43 +00:00
py-frame.c
py-framefilter.c
py-function.c
py-gdb-readline.c
py-inferior.c
py-infevents.c
py-infthread.c Add Python InferiorThread.global_num attribute 2016-01-13 11:00:54 +00:00
py-lazy-string.c
py-linetable.c
py-newobjfileevent.c
py-objfile.c
py-param.c
py-prettyprint.c
py-progspace.c
py-signalevent.c
py-stopevent.c
py-stopevent.h
py-symbol.c
py-symtab.c
py-threadevent.c
py-type.c
py-unwind.c
py-utils.c
py-value.c
py-varobj.c
py-xmethods.c
python-config.py
python-internal.h
python.c Limit breakpoint re-set to the current program space 2016-01-19 12:18:14 +00:00
python.h