binutils-gdb/gdb/python/lib/gdb
Simon Marchi 5f5dfff63f Fix sorting of enum values in FlagEnumerationPrinter
The lambda function used to sort the enumerator list does not work
properly.  This list consists of tuples, (enum label, enum value).  The
key function returns x.enumval.  enumval not being defined for a tuple,
we see this exception in the test log:

  Python Exception <class 'AttributeError'> 'tuple' object has no attribute 'enumval'

The function should return the second item of the tuple, which is the
enumval.

The pretty-printer still worked mostly correctly, except that the
enumeration values were not sorted.  The test still passed because the
enumeration values are already sorted where they are defined.  The test
also passed despite the exception being printed, because the right output
was printed after the exception:

  print (enum flag_enum) (FLAG_1)
  Python Exception <type 'exceptions.AttributeError'> 'tuple' objecthas no attribute 'enumval':M
  $7 = 0x1 [FLAG_1]
  (gdb) PASS: gdb.python/py-pp-maint.exp: print FLAG_1

New in v2:

- Improved test case, I stole Pedro's example directly.  It verifies
  that the sorting of enumerators by value works, by checking that
  printing FOO_MASK appears as FOO_1 | FOO_2 | FOO_3.

  I noticed that I could change the regexps to almost anything and the
  tests would still pass.  I think it was because of the | in there.  I
  made them more robust by using string_to_regexp.  I used curly braces
  { } instead of quoting marks " " for strings, so that I could use
  square brackets [ ] in them without having to escape them all.  I also
  removed the "message" part of the tests, since they are redundant with
  the command, and it's just more maintenance to have to update them.

  Tested with Python 2.7 and 3.5.

gdb/ChangeLog:

	* python/lib/gdb/printing.py (FlagEnumerationPrinter.__call__):
	Fix enumerators sort key function.

gdb/testsuite/ChangeLog:

	* gdb.python/py-pp-maint.exp: Change/add enum flag tests.
	* gdb.python/py-pp-maint.c (enum flag_enum): Use more complex
	enum flag values.
2016-01-20 13:44:33 -05:00
..
command GDB copyright headers update after running GDB's copyright.py script. 2016-01-01 08:43:22 +04:00
function GDB copyright headers update after running GDB's copyright.py script. 2016-01-01 08:43:22 +04:00
printer GDB copyright headers update after running GDB's copyright.py script. 2016-01-01 08:43:22 +04:00
FrameDecorator.py GDB copyright headers update after running GDB's copyright.py script. 2016-01-01 08:43:22 +04:00
FrameIterator.py GDB copyright headers update after running GDB's copyright.py script. 2016-01-01 08:43:22 +04:00
__init__.py GDB copyright headers update after running GDB's copyright.py script. 2016-01-01 08:43:22 +04:00
frames.py GDB copyright headers update after running GDB's copyright.py script. 2016-01-01 08:43:22 +04:00
printing.py Fix sorting of enum values in FlagEnumerationPrinter 2016-01-20 13:44:33 -05:00
prompt.py GDB copyright headers update after running GDB's copyright.py script. 2016-01-01 08:43:22 +04:00
types.py GDB copyright headers update after running GDB's copyright.py script. 2016-01-01 08:43:22 +04:00
unwinder.py GDB copyright headers update after running GDB's copyright.py script. 2016-01-01 08:43:22 +04:00
xmethod.py GDB copyright headers update after running GDB's copyright.py script. 2016-01-01 08:43:22 +04:00