Commit | Line | Data |
---|---|---|
618f726f | 1 | # Copyright (C) 2010-2016 Free Software Foundation, Inc. |
c17a9e46 HZ |
2 | |
3 | # This program is free software; you can redistribute it and/or modify | |
4 | # it under the terms of the GNU General Public License as published by | |
5 | # the Free Software Foundation; either version 3 of the License, or | |
6 | # (at your option) any later version. | |
7 | # | |
8 | # This program is distributed in the hope that it will be useful, | |
9 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | |
10 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
11 | # GNU General Public License for more details. | |
12 | # | |
13 | # You should have received a copy of the GNU General Public License | |
14 | # along with this program. If not, see <http://www.gnu.org/licenses/>. | |
15 | ||
16 | # This file is part of the GDB testsuite. It tests python pretty | |
17 | # printers. | |
18 | import gdb | |
19 | ||
20 | def signal_stop_handler (event): | |
21 | if (isinstance (event, gdb.StopEvent)): | |
9325cb04 | 22 | print ("event type: stop") |
c17a9e46 | 23 | if (isinstance (event, gdb.SignalEvent)): |
9325cb04 PK |
24 | print ("stop reason: signal") |
25 | print ("stop signal: %s" % (event.stop_signal)) | |
c17a9e46 | 26 | if ( event.inferior_thread is not None) : |
9325cb04 | 27 | print ("thread num: %s" % (event.inferior_thread.num)) |
c17a9e46 HZ |
28 | |
29 | def breakpoint_stop_handler (event): | |
30 | if (isinstance (event, gdb.StopEvent)): | |
9325cb04 | 31 | print ("event type: stop") |
c17a9e46 | 32 | if (isinstance (event, gdb.BreakpointEvent)): |
9325cb04 PK |
33 | print ("stop reason: breakpoint") |
34 | print ("first breakpoint number: %s" % (event.breakpoint.number)) | |
6839b47f | 35 | for bp in event.breakpoints: |
9325cb04 | 36 | print ("breakpoint number: %s" % (bp.number)) |
c17a9e46 | 37 | if ( event.inferior_thread is not None) : |
9325cb04 | 38 | print ("thread num: %s" % (event.inferior_thread.num)) |
c17a9e46 | 39 | else: |
9325cb04 | 40 | print ("all threads stopped") |
c17a9e46 HZ |
41 | |
42 | def exit_handler (event): | |
314bb8c3 DE |
43 | assert (isinstance (event, gdb.ExitedEvent)) |
44 | print ("event type: exit") | |
9325cb04 PK |
45 | print ("exit code: %d" % (event.exit_code)) |
46 | print ("exit inf: %d" % (event.inferior.num)) | |
47 | print ("dir ok: %s" % str('exit_code' in dir(event))) | |
c17a9e46 HZ |
48 | |
49 | def continue_handler (event): | |
314bb8c3 DE |
50 | assert (isinstance (event, gdb.ContinueEvent)) |
51 | print ("event type: continue") | |
c17a9e46 | 52 | if ( event.inferior_thread is not None) : |
9325cb04 | 53 | print ("thread num: %s" % (event.inferior_thread.num)) |
c17a9e46 | 54 | |
20c168b5 | 55 | def new_objfile_handler (event): |
314bb8c3 DE |
56 | assert (isinstance (event, gdb.NewObjFileEvent)) |
57 | print ("event type: new_objfile") | |
58 | print ("new objfile name: %s" % (event.new_objfile.filename)) | |
20c168b5 | 59 | |
4ffbba72 DE |
60 | def clear_objfiles_handler (event): |
61 | assert (isinstance (event, gdb.ClearObjFilesEvent)) | |
62 | print ("event type: clear_objfiles") | |
63 | print ("progspace: %s" % (event.progspace.filename)) | |
64 | ||
162078c8 NB |
65 | def inferior_call_handler (event): |
66 | if (isinstance (event, gdb.InferiorCallPreEvent)): | |
67 | print ("event type: pre-call") | |
68 | elif (isinstance (event, gdb.InferiorCallPostEvent)): | |
69 | print ("event type: post-call") | |
70 | else: | |
71 | assert False | |
72 | print ("ptid: %s" % (event.ptid,)) | |
73 | print ("address: 0x%x" % (event.address)) | |
74 | ||
75 | def register_changed_handler (event): | |
76 | assert (isinstance (event, gdb.RegisterChangedEvent)) | |
77 | print ("event type: register-changed") | |
78 | assert (isinstance (event.frame, gdb.Frame)) | |
79 | print ("frame: %s" % (event.frame)) | |
80 | print ("num: %s" % (event.regnum)) | |
81 | ||
82 | def memory_changed_handler (event): | |
83 | assert (isinstance (event, gdb.MemoryChangedEvent)) | |
84 | print ("event type: memory-changed") | |
85 | print ("address: %s" % (event.address)) | |
86 | print ("length: %s" % (event.length)) | |
87 | ||
88 | ||
c17a9e46 HZ |
89 | class test_events (gdb.Command): |
90 | """Test events.""" | |
91 | ||
92 | def __init__ (self): | |
314bb8c3 | 93 | gdb.Command.__init__ (self, "test-events", gdb.COMMAND_STACK) |
c17a9e46 HZ |
94 | |
95 | def invoke (self, arg, from_tty): | |
96 | gdb.events.stop.connect (signal_stop_handler) | |
97 | gdb.events.stop.connect (breakpoint_stop_handler) | |
98 | gdb.events.exited.connect (exit_handler) | |
99 | gdb.events.cont.connect (continue_handler) | |
162078c8 NB |
100 | gdb.events.inferior_call.connect (inferior_call_handler) |
101 | gdb.events.memory_changed.connect (memory_changed_handler) | |
102 | gdb.events.register_changed.connect (register_changed_handler) | |
9325cb04 | 103 | print ("Event testers registered.") |
c17a9e46 HZ |
104 | |
105 | test_events () | |
20c168b5 KP |
106 | |
107 | class test_newobj_events (gdb.Command): | |
108 | """NewObj events.""" | |
109 | ||
110 | def __init__ (self): | |
314bb8c3 | 111 | gdb.Command.__init__ (self, "test-objfile-events", gdb.COMMAND_STACK) |
20c168b5 KP |
112 | |
113 | def invoke (self, arg, from_tty): | |
114 | gdb.events.new_objfile.connect (new_objfile_handler) | |
4ffbba72 | 115 | gdb.events.clear_objfiles.connect (clear_objfiles_handler) |
314bb8c3 | 116 | print ("Object file events registered.") |
20c168b5 KP |
117 | |
118 | test_newobj_events () |