]>
Commit | Line | Data |
---|---|---|
3666a048 | 1 | # Copyright (C) 2010-2021 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 | ||
13123da8 SM |
20 | |
21 | def signal_stop_handler(event): | |
22 | if isinstance(event, gdb.StopEvent): | |
23 | print("event type: stop") | |
24 | if isinstance(event, gdb.SignalEvent): | |
25 | print("stop reason: signal") | |
26 | print("stop signal: %s" % (event.stop_signal)) | |
27 | if event.inferior_thread is not None: | |
28 | print("thread num: %s" % (event.inferior_thread.num)) | |
29 | ||
30 | ||
31 | def breakpoint_stop_handler(event): | |
32 | if isinstance(event, gdb.StopEvent): | |
33 | print("event type: stop") | |
34 | if isinstance(event, gdb.BreakpointEvent): | |
35 | print("stop reason: breakpoint") | |
36 | print("first breakpoint number: %s" % (event.breakpoint.number)) | |
6839b47f | 37 | for bp in event.breakpoints: |
13123da8 SM |
38 | print("breakpoint number: %s" % (bp.number)) |
39 | if event.inferior_thread is not None: | |
40 | print("thread num: %s" % (event.inferior_thread.num)) | |
c17a9e46 | 41 | else: |
13123da8 SM |
42 | print("all threads stopped") |
43 | ||
44 | ||
45 | def exit_handler(event): | |
46 | assert isinstance(event, gdb.ExitedEvent) | |
47 | print("event type: exit") | |
48 | print("exit code: %d" % (event.exit_code)) | |
49 | print("exit inf: %d" % (event.inferior.num)) | |
df5bc734 | 50 | print("exit pid: %d" % (event.inferior.pid)) |
13123da8 SM |
51 | print("dir ok: %s" % str("exit_code" in dir(event))) |
52 | ||
53 | ||
54 | def continue_handler(event): | |
55 | assert isinstance(event, gdb.ContinueEvent) | |
56 | print("event type: continue") | |
57 | if event.inferior_thread is not None: | |
58 | print("thread num: %s" % (event.inferior_thread.num)) | |
59 | ||
60 | ||
61 | def new_objfile_handler(event): | |
62 | assert isinstance(event, gdb.NewObjFileEvent) | |
63 | print("event type: new_objfile") | |
64 | print("new objfile name: %s" % (event.new_objfile.filename)) | |
65 | ||
66 | ||
67 | def clear_objfiles_handler(event): | |
68 | assert isinstance(event, gdb.ClearObjFilesEvent) | |
69 | print("event type: clear_objfiles") | |
70 | print("progspace: %s" % (event.progspace.filename)) | |
71 | ||
72 | ||
73 | def inferior_call_handler(event): | |
74 | if isinstance(event, gdb.InferiorCallPreEvent): | |
75 | print("event type: pre-call") | |
76 | elif isinstance(event, gdb.InferiorCallPostEvent): | |
77 | print("event type: post-call") | |
162078c8 NB |
78 | else: |
79 | assert False | |
13123da8 SM |
80 | print("ptid: %s" % (event.ptid,)) |
81 | print("address: 0x%x" % (event.address)) | |
82 | ||
162078c8 | 83 | |
13123da8 SM |
84 | def register_changed_handler(event): |
85 | assert isinstance(event, gdb.RegisterChangedEvent) | |
86 | print("event type: register-changed") | |
87 | assert isinstance(event.frame, gdb.Frame) | |
88 | print("frame: %s" % (event.frame)) | |
89 | print("num: %s" % (event.regnum)) | |
162078c8 | 90 | |
162078c8 | 91 | |
13123da8 SM |
92 | def memory_changed_handler(event): |
93 | assert isinstance(event, gdb.MemoryChangedEvent) | |
94 | print("event type: memory-changed") | |
95 | print("address: %s" % (event.address)) | |
96 | print("length: %s" % (event.length)) | |
162078c8 | 97 | |
13123da8 SM |
98 | |
99 | class test_events(gdb.Command): | |
c17a9e46 HZ |
100 | """Test events.""" |
101 | ||
13123da8 SM |
102 | def __init__(self): |
103 | gdb.Command.__init__(self, "test-events", gdb.COMMAND_STACK) | |
104 | ||
105 | def invoke(self, arg, from_tty): | |
106 | gdb.events.stop.connect(signal_stop_handler) | |
107 | gdb.events.stop.connect(breakpoint_stop_handler) | |
108 | gdb.events.exited.connect(exit_handler) | |
109 | gdb.events.cont.connect(continue_handler) | |
110 | gdb.events.inferior_call.connect(inferior_call_handler) | |
111 | gdb.events.memory_changed.connect(memory_changed_handler) | |
112 | gdb.events.register_changed.connect(register_changed_handler) | |
113 | print("Event testers registered.") | |
c17a9e46 | 114 | |
c17a9e46 | 115 | |
13123da8 | 116 | test_events() |
20c168b5 | 117 | |
13123da8 SM |
118 | |
119 | class test_newobj_events(gdb.Command): | |
20c168b5 KP |
120 | """NewObj events.""" |
121 | ||
13123da8 SM |
122 | def __init__(self): |
123 | gdb.Command.__init__(self, "test-objfile-events", gdb.COMMAND_STACK) | |
124 | ||
125 | def invoke(self, arg, from_tty): | |
126 | gdb.events.new_objfile.connect(new_objfile_handler) | |
127 | gdb.events.clear_objfiles.connect(clear_objfiles_handler) | |
128 | print("Object file events registered.") | |
20c168b5 | 129 | |
20c168b5 | 130 | |
13123da8 | 131 | test_newobj_events() |