forked from Imagelibrary/binutils-gdb
gdb/python: update events test to handle missing exit_code
The test gdb.python/py-events.exp sets up a handler for the gdb.exited event. Unfortunately the handler is slightly broken, it assumes that the exit_code attribute will always be present. This is not always the case. In a later commit I am going to add more tests to py-events.exp test script, and in so doing I expose the bug in our handling of gdb.exited events. Just to be clear, GDB itself is fine, it is the test that is not written correctly according to the Python Events API. So, in this commit I fix the Python code in the test, and extend the test case to exercise more paths through the Python code. Additionally, I noticed that the gdb.exited event is used as an example in the documentation for how to write an event handler. Unfortunately the same bug that we had in our test was also present in the example code in the manual. So I've fixed that too. After this commit there is no functional change to GDB.
This commit is contained in:
@@ -3202,7 +3202,10 @@ Here is an example:
|
||||
@smallexample
|
||||
def exit_handler (event):
|
||||
print ("event type: exit")
|
||||
print ("exit code: %d" % (event.exit_code))
|
||||
if hasattr (event, 'exit_code'):
|
||||
print ("exit code: %d" % (event.exit_code))
|
||||
else:
|
||||
print ("exit code not available")
|
||||
|
||||
gdb.events.exited.connect (exit_handler)
|
||||
@end smallexample
|
||||
|
||||
Reference in New Issue
Block a user