gdb
[deliverable/binutils-gdb.git] / gdb / doc / observer.texi
CommitLineData
bcd7e15f 1@c -*-texinfo-*-
16d1a084
DJ
2
3@c This file is part of the GDB manual.
4@c
5@c Copyright (C) 2003, 2004, 2005, 2006
6@c Free Software Foundation, Inc.
7@c
8@c See the file gdbint.texinfo for copying conditions.
9@c
10@c Also, the @deftypefun lines from this file are processed into a
11@c header file during the GDB build process. Permission is granted
12@c to redistribute and/or modify those lines under the terms of the
13@c GNU General Public License as published by the Free Software
14@c Foundation; either version 2 of the License, or (at your option)
15@c any later version.
16
bcd7e15f
JB
17@node GDB Observers
18@appendix @value{GDBN} Currently available observers
19
20@section Implementation rationale
21@cindex observers implementation rationale
22
23An @dfn{observer} is an entity which is interested in being notified
24when GDB reaches certain states, or certain events occur in GDB.
25The entity being observed is called the @dfn{subject}. To receive
26notifications, the observer attaches a callback to the subject.
27One subject can have several observers.
28
29@file{observer.c} implements an internal generic low-level event
6be67e67 30notification mechanism. This generic event notification mechanism is
bcd7e15f
JB
31then re-used to implement the exported high-level notification
32management routines for all possible notifications.
33
34The current implementation of the generic observer provides support
35for contextual data. This contextual data is given to the subject
36when attaching the callback. In return, the subject will provide
37this contextual data back to the observer as a parameter of the
38callback.
39
40Note that the current support for the contextual data is only partial,
41as it lacks a mechanism that would deallocate this data when the
42callback is detached. This is not a problem so far, as this contextual
43data is only used internally to hold a function pointer. Later on, if
44a certain observer needs to provide support for user-level contextual
6be67e67 45data, then the generic notification mechanism will need to be
bcd7e15f
JB
46enhanced to allow the observer to provide a routine to deallocate the
47data when attaching the callback.
48
49The observer implementation is also currently not reentrant.
50In particular, it is therefore not possible to call the attach
51or detach routines during a notification.
52
2b4855ab
AC
53@section Debugging
54Observer notifications can be traced using the command @samp{set debug
55observer 1} (@pxref{Debugging Output, , Optional messages about
56internal happenings, gdb, Debugging with @var{GDBN}}).
57
bcd7e15f
JB
58@section @code{normal_stop} Notifications
59@cindex @code{normal_stop} observer
60@cindex notification about inferior execution stop
61
6be67e67
JB
62@value{GDBN} notifies all @code{normal_stop} observers when the
63inferior execution has just stopped, the associated messages and
64annotations have been printed, and the control is about to be returned
16d1a084 65to the user.
6be67e67
JB
66
67Note that the @code{normal_stop} notification is not emitted when
68the execution stops due to a breakpoint, and this breakpoint has
69a condition that is not met. If the breakpoint has any associated
70commands list, the commands are executed after the notification
71is emitted.
bcd7e15f 72
7a464420 73The following interfaces are available to manage observers:
bcd7e15f 74
7a464420
AC
75@deftypefun extern struct observer *observer_attach_@var{event} (observer_@var{event}_ftype *@var{f})
76Using the function @var{f}, create an observer that is notified when
d3e8051b 77ever @var{event} occurs, return the observer.
bcd7e15f
JB
78@end deftypefun
79
7a464420 80@deftypefun extern void observer_detach_@var{event} (struct observer *@var{observer});
bcd7e15f 81Remove @var{observer} from the list of observers to be notified when
7a464420 82@var{event} occurs.
bcd7e15f
JB
83@end deftypefun
84
7a464420
AC
85@deftypefun extern void observer_notify_@var{event} (void);
86Send a notification to all @var{event} observers.
bcd7e15f
JB
87@end deftypefun
88
7a464420 89The following observable events are defined:
bcd7e15f 90
7a464420
AC
91@deftypefun void normal_stop (struct bpstats *@var{bs})
92The inferior has stopped for real.
93@end deftypefun
79346bcb
OF
94
95@deftypefun void target_changed (struct target_ops *@var{target})
67ab9a76 96The target's register contents have changed.
79346bcb 97@end deftypefun
59caf092 98
781b42b0 99@deftypefun void executable_changed (void)
ea53e89f
JB
100The executable being debugged by GDB has changed: The user decided
101to debug a different program, or the program he was debugging has
102been modified since being loaded by the debugger (by being recompiled,
103for instance).
104@end deftypefun
105
59caf092
AC
106@deftypefun void inferior_created (struct target_ops *@var{objfile}, int @var{from_tty})
107@value{GDBN} has just connected to an inferior. For @samp{run},
108@value{GDBN} calls this observer while the inferior is still stopped
109at the entry-point instruction. For @samp{attach} and @samp{core},
110@value{GDBN} calls this observer immediately after connecting to the
111inferior, and before any information on the inferior has been printed.
112@end deftypefun
f3bb6704 113
fbd1b305
MK
114@deftypefun void solib_loaded (struct so_list *@var{solib})
115The shared library specified by @var{solib} has been loaded. Note that
116when @value{GDBN} calls this observer, the library's symbols probably
117haven't been loaded yet.
f3bb6704
JJ
118@end deftypefun
119
fbd1b305
MK
120@deftypefun void solib_unloaded (struct so_list *@var{solib})
121The shared library specified by @var{solib} has been unloaded.
122@end deftypefun
06d3b283
UW
123
124@deftypefun void new_objfile (struct objfile *@var{objfile})
125The symbol file specified by @var{objfile} has been loaded.
126Called with @var{objfile} equal to @code{NULL} to indicate
127previously loaded symbol table data has now been invalidated.
128@end deftypefun
129
683f2885
VP
130@deftypefun void new_thread (struct thread_info *@var{t})
131The thread specified by @var{t} has been created.
132@end deftypefun
133
063bfe2e
VP
134@deftypefun void thread_exit (struct thread_info *@var{t})
135The thread specified by @var{t} has exited.
136@end deftypefun
137
e1ac3328
VP
138@deftypefun void target_resumed (ptid_t @var{ptid})
139The target was resumed. The @var{ptid} parameter specifies which
140thread was resume, and may be RESUME_ALL if all threads are resumed.
141@end deftypefun
This page took 0.333771 seconds and 4 git commands to generate.