3 @c This file is part of the GDB manual.
5 @c Copyright (C) 2003, 2004, 2005, 2006
6 @c Free Software Foundation, Inc.
8 @c See the file gdbint.texinfo for copying conditions.
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)
18 @appendix @value{GDBN} Currently available observers
20 @section Implementation rationale
21 @cindex observers implementation rationale
23 An @dfn{observer} is an entity which is interested in being notified
24 when GDB reaches certain states, or certain events occur in GDB.
25 The entity being observed is called the @dfn{subject}. To receive
26 notifications, the observer attaches a callback to the subject.
27 One subject can have several observers.
29 @file{observer.c} implements an internal generic low-level event
30 notification mechanism. This generic event notification mechanism is
31 then re-used to implement the exported high-level notification
32 management routines for all possible notifications.
34 The current implementation of the generic observer provides support
35 for contextual data. This contextual data is given to the subject
36 when attaching the callback. In return, the subject will provide
37 this contextual data back to the observer as a parameter of the
40 Note that the current support for the contextual data is only partial,
41 as it lacks a mechanism that would deallocate this data when the
42 callback is detached. This is not a problem so far, as this contextual
43 data is only used internally to hold a function pointer. Later on, if
44 a certain observer needs to provide support for user-level contextual
45 data, then the generic notification mechanism will need to be
46 enhanced to allow the observer to provide a routine to deallocate the
47 data when attaching the callback.
49 The observer implementation is also currently not reentrant.
50 In particular, it is therefore not possible to call the attach
51 or detach routines during a notification.
54 Observer notifications can be traced using the command @samp{set debug
55 observer 1} (@pxref{Debugging Output, , Optional messages about
56 internal happenings, gdb, Debugging with @var{GDBN}}).
58 @section @code{normal_stop} Notifications
59 @cindex @code{normal_stop} observer
60 @cindex notification about inferior execution stop
62 @value{GDBN} notifies all @code{normal_stop} observers when the
63 inferior execution has just stopped, the associated messages and
64 annotations have been printed, and the control is about to be returned
67 Note that the @code{normal_stop} notification is not emitted when
68 the execution stops due to a breakpoint, and this breakpoint has
69 a condition that is not met. If the breakpoint has any associated
70 commands list, the commands are executed after the notification
73 The following interfaces are available to manage observers:
75 @deftypefun extern struct observer *observer_attach_@var{event} (observer_@var{event}_ftype *@var{f})
76 Using the function @var{f}, create an observer that is notified when
77 ever @var{event} occures, return the observer.
80 @deftypefun extern void observer_detach_@var{event} (struct observer *@var{observer});
81 Remove @var{observer} from the list of observers to be notified when
85 @deftypefun extern void observer_notify_@var{event} (void);
86 Send a notification to all @var{event} observers.
89 The following observable events are defined:
91 @c note: all events must take at least one parameter.
93 @deftypefun void normal_stop (struct bpstats *@var{bs})
94 The inferior has stopped for real.
97 @deftypefun void target_changed (struct target_ops *@var{target})
98 The target's register contents have changed.
101 @deftypefun void executable_changed (void *@var{unused_args})
102 The executable being debugged by GDB has changed: The user decided
103 to debug a different program, or the program he was debugging has
104 been modified since being loaded by the debugger (by being recompiled,
108 @deftypefun void inferior_created (struct target_ops *@var{objfile}, int @var{from_tty})
109 @value{GDBN} has just connected to an inferior. For @samp{run},
110 @value{GDBN} calls this observer while the inferior is still stopped
111 at the entry-point instruction. For @samp{attach} and @samp{core},
112 @value{GDBN} calls this observer immediately after connecting to the
113 inferior, and before any information on the inferior has been printed.
116 @deftypefun void solib_loaded (struct so_list *@var{solib})
117 The shared library specified by @var{solib} has been loaded. Note that
118 when @value{GDBN} calls this observer, the library's symbols probably
119 haven't been loaded yet.
122 @deftypefun void solib_unloaded (struct so_list *@var{solib})
123 The shared library specified by @var{solib} has been unloaded.