15796c8dcSSimon Schubert@c -*-texinfo-*- 25796c8dcSSimon Schubert 35796c8dcSSimon Schubert@c This file is part of the GDB manual. 45796c8dcSSimon Schubert@c 5*ef5ccd6cSJohn Marino@c Copyright (C) 2003-2013 Free Software Foundation, Inc. 65796c8dcSSimon Schubert@c 75796c8dcSSimon Schubert@c See the file gdbint.texinfo for copying conditions. 85796c8dcSSimon Schubert@c 95796c8dcSSimon Schubert@c Also, the @deftypefun lines from this file are processed into a 105796c8dcSSimon Schubert@c header file during the GDB build process. Permission is granted 115796c8dcSSimon Schubert@c to redistribute and/or modify those lines under the terms of the 125796c8dcSSimon Schubert@c GNU General Public License as published by the Free Software 13cf7f2e2dSJohn Marino@c Foundation; either version 3 of the License, or (at your option) 145796c8dcSSimon Schubert@c any later version. 155796c8dcSSimon Schubert 165796c8dcSSimon Schubert@node GDB Observers 175796c8dcSSimon Schubert@appendix @value{GDBN} Currently available observers 185796c8dcSSimon Schubert 195796c8dcSSimon Schubert@section Implementation rationale 205796c8dcSSimon Schubert@cindex observers implementation rationale 215796c8dcSSimon Schubert 225796c8dcSSimon SchubertAn @dfn{observer} is an entity which is interested in being notified 235796c8dcSSimon Schubertwhen GDB reaches certain states, or certain events occur in GDB. 245796c8dcSSimon SchubertThe entity being observed is called the @dfn{subject}. To receive 255796c8dcSSimon Schubertnotifications, the observer attaches a callback to the subject. 265796c8dcSSimon SchubertOne subject can have several observers. 275796c8dcSSimon Schubert 285796c8dcSSimon Schubert@file{observer.c} implements an internal generic low-level event 295796c8dcSSimon Schubertnotification mechanism. This generic event notification mechanism is 305796c8dcSSimon Schubertthen re-used to implement the exported high-level notification 315796c8dcSSimon Schubertmanagement routines for all possible notifications. 325796c8dcSSimon Schubert 335796c8dcSSimon SchubertThe current implementation of the generic observer provides support 345796c8dcSSimon Schubertfor contextual data. This contextual data is given to the subject 355796c8dcSSimon Schubertwhen attaching the callback. In return, the subject will provide 365796c8dcSSimon Schubertthis contextual data back to the observer as a parameter of the 375796c8dcSSimon Schubertcallback. 385796c8dcSSimon Schubert 395796c8dcSSimon SchubertNote that the current support for the contextual data is only partial, 405796c8dcSSimon Schubertas it lacks a mechanism that would deallocate this data when the 415796c8dcSSimon Schubertcallback is detached. This is not a problem so far, as this contextual 425796c8dcSSimon Schubertdata is only used internally to hold a function pointer. Later on, if 435796c8dcSSimon Schuberta certain observer needs to provide support for user-level contextual 445796c8dcSSimon Schubertdata, then the generic notification mechanism will need to be 455796c8dcSSimon Schubertenhanced to allow the observer to provide a routine to deallocate the 465796c8dcSSimon Schubertdata when attaching the callback. 475796c8dcSSimon Schubert 485796c8dcSSimon SchubertThe observer implementation is also currently not reentrant. 495796c8dcSSimon SchubertIn particular, it is therefore not possible to call the attach 505796c8dcSSimon Schubertor detach routines during a notification. 515796c8dcSSimon Schubert 525796c8dcSSimon Schubert@section Debugging 535796c8dcSSimon SchubertObserver notifications can be traced using the command @samp{set debug 545796c8dcSSimon Schubertobserver 1} (@pxref{Debugging Output, , Optional messages about 555796c8dcSSimon Schubertinternal happenings, gdb, Debugging with @var{GDBN}}). 565796c8dcSSimon Schubert 575796c8dcSSimon Schubert@section @code{normal_stop} Notifications 585796c8dcSSimon Schubert@cindex @code{normal_stop} observer 595796c8dcSSimon Schubert@cindex notification about inferior execution stop 605796c8dcSSimon Schubert 615796c8dcSSimon Schubert@value{GDBN} notifies all @code{normal_stop} observers when the 625796c8dcSSimon Schubertinferior execution has just stopped, the associated messages and 635796c8dcSSimon Schubertannotations have been printed, and the control is about to be returned 645796c8dcSSimon Schubertto the user. 655796c8dcSSimon Schubert 665796c8dcSSimon SchubertNote that the @code{normal_stop} notification is not emitted when 675796c8dcSSimon Schubertthe execution stops due to a breakpoint, and this breakpoint has 685796c8dcSSimon Schuberta condition that is not met. If the breakpoint has any associated 695796c8dcSSimon Schubertcommands list, the commands are executed after the notification 705796c8dcSSimon Schubertis emitted. 715796c8dcSSimon Schubert 725796c8dcSSimon SchubertThe following interfaces are available to manage observers: 735796c8dcSSimon Schubert 745796c8dcSSimon Schubert@deftypefun extern struct observer *observer_attach_@var{event} (observer_@var{event}_ftype *@var{f}) 755796c8dcSSimon SchubertUsing the function @var{f}, create an observer that is notified when 765796c8dcSSimon Schubertever @var{event} occurs, return the observer. 775796c8dcSSimon Schubert@end deftypefun 785796c8dcSSimon Schubert 795796c8dcSSimon Schubert@deftypefun extern void observer_detach_@var{event} (struct observer *@var{observer}); 805796c8dcSSimon SchubertRemove @var{observer} from the list of observers to be notified when 815796c8dcSSimon Schubert@var{event} occurs. 825796c8dcSSimon Schubert@end deftypefun 835796c8dcSSimon Schubert 845796c8dcSSimon Schubert@deftypefun extern void observer_notify_@var{event} (void); 855796c8dcSSimon SchubertSend a notification to all @var{event} observers. 865796c8dcSSimon Schubert@end deftypefun 875796c8dcSSimon Schubert 885796c8dcSSimon SchubertThe following observable events are defined: 895796c8dcSSimon Schubert 905796c8dcSSimon Schubert@deftypefun void normal_stop (struct bpstats *@var{bs}, int @var{print_frame}) 915796c8dcSSimon SchubertThe inferior has stopped for real. The @var{bs} argument describes 925796c8dcSSimon Schubertthe breakpoints were are stopped at, if any. Second argument 935796c8dcSSimon Schubert@var{print_frame} non-zero means display the location where the 945796c8dcSSimon Schubertinferior has stopped. 955796c8dcSSimon Schubert@end deftypefun 965796c8dcSSimon Schubert 975796c8dcSSimon Schubert@deftypefun void target_changed (struct target_ops *@var{target}) 985796c8dcSSimon SchubertThe target's register contents have changed. 995796c8dcSSimon Schubert@end deftypefun 1005796c8dcSSimon Schubert 1015796c8dcSSimon Schubert@deftypefun void executable_changed (void) 1025796c8dcSSimon SchubertThe executable being debugged by GDB has changed: The user decided 1035796c8dcSSimon Schubertto debug a different program, or the program he was debugging has 1045796c8dcSSimon Schubertbeen modified since being loaded by the debugger (by being recompiled, 1055796c8dcSSimon Schubertfor instance). 1065796c8dcSSimon Schubert@end deftypefun 1075796c8dcSSimon Schubert 1085796c8dcSSimon Schubert@deftypefun void inferior_created (struct target_ops *@var{objfile}, int @var{from_tty}) 1095796c8dcSSimon Schubert@value{GDBN} has just connected to an inferior. For @samp{run}, 1105796c8dcSSimon Schubert@value{GDBN} calls this observer while the inferior is still stopped 1115796c8dcSSimon Schubertat the entry-point instruction. For @samp{attach} and @samp{core}, 1125796c8dcSSimon Schubert@value{GDBN} calls this observer immediately after connecting to the 1135796c8dcSSimon Schubertinferior, and before any information on the inferior has been printed. 1145796c8dcSSimon Schubert@end deftypefun 1155796c8dcSSimon Schubert 116*ef5ccd6cSJohn Marino@deftypefun void record_changed (struct inferior *@var{inferior}, int @var{started}) 117*ef5ccd6cSJohn MarinoThe status of process record for inferior @var{inferior} in 118*ef5ccd6cSJohn Marino@value{GDBN} has changed. The process record is started if 119*ef5ccd6cSJohn Marino@var{started} is true, and the process record is stopped if 120*ef5ccd6cSJohn Marino@var{started} is false. 121*ef5ccd6cSJohn Marino@end deftypefun 122*ef5ccd6cSJohn Marino 1235796c8dcSSimon Schubert@deftypefun void solib_loaded (struct so_list *@var{solib}) 1245796c8dcSSimon SchubertThe shared library specified by @var{solib} has been loaded. Note that 1255796c8dcSSimon Schubertwhen @value{GDBN} calls this observer, the library's symbols probably 1265796c8dcSSimon Schuberthaven't been loaded yet. 1275796c8dcSSimon Schubert@end deftypefun 1285796c8dcSSimon Schubert 1295796c8dcSSimon Schubert@deftypefun void solib_unloaded (struct so_list *@var{solib}) 1305796c8dcSSimon SchubertThe shared library specified by @var{solib} has been unloaded. 131cf7f2e2dSJohn MarinoNote that when @value{GDBN} calls this observer, the library's 132cf7f2e2dSJohn Marinosymbols have not been unloaded yet, and thus are still available. 1335796c8dcSSimon Schubert@end deftypefun 1345796c8dcSSimon Schubert 1355796c8dcSSimon Schubert@deftypefun void new_objfile (struct objfile *@var{objfile}) 1365796c8dcSSimon SchubertThe symbol file specified by @var{objfile} has been loaded. 1375796c8dcSSimon SchubertCalled with @var{objfile} equal to @code{NULL} to indicate 1385796c8dcSSimon Schubertpreviously loaded symbol table data has now been invalidated. 1395796c8dcSSimon Schubert@end deftypefun 1405796c8dcSSimon Schubert 1415796c8dcSSimon Schubert@deftypefun void new_thread (struct thread_info *@var{t}) 1425796c8dcSSimon SchubertThe thread specified by @var{t} has been created. 1435796c8dcSSimon Schubert@end deftypefun 1445796c8dcSSimon Schubert 1455796c8dcSSimon Schubert@deftypefun void thread_exit (struct thread_info *@var{t}, int @var{silent}) 1465796c8dcSSimon SchubertThe thread specified by @var{t} has exited. The @var{silent} argument 1475796c8dcSSimon Schubertindicates that @value{GDBN} is removing the thread from its tables 1485796c8dcSSimon Schubertwithout wanting to notify the user about it. 1495796c8dcSSimon Schubert@end deftypefun 1505796c8dcSSimon Schubert 1515796c8dcSSimon Schubert@deftypefun void thread_stop_requested (ptid_t @var{ptid}) 1525796c8dcSSimon SchubertAn explicit stop request was issued to @var{ptid}. If @var{ptid} 1535796c8dcSSimon Schubertequals @var{minus_one_ptid}, the request applied to all threads. If 1545796c8dcSSimon Schubert@code{ptid_is_pid(ptid)} returns true, the request applied to all 1555796c8dcSSimon Schubertthreads of the process pointed at by @var{ptid}. Otherwise, the 1565796c8dcSSimon Schubertrequest applied to the single thread pointed at by @var{ptid}. 1575796c8dcSSimon Schubert@end deftypefun 1585796c8dcSSimon Schubert 1595796c8dcSSimon Schubert@deftypefun void target_resumed (ptid_t @var{ptid}) 1605796c8dcSSimon SchubertThe target was resumed. The @var{ptid} parameter specifies which 1615796c8dcSSimon Schubertthread was resume, and may be RESUME_ALL if all threads are resumed. 1625796c8dcSSimon Schubert@end deftypefun 1635796c8dcSSimon Schubert 1645796c8dcSSimon Schubert@deftypefun void about_to_proceed (void) 1655796c8dcSSimon SchubertThe target is about to be proceeded. 1665796c8dcSSimon Schubert@end deftypefun 1675796c8dcSSimon Schubert 168a45ae5f8SJohn Marino@deftypefun void breakpoint_created (struct breakpoint *@var{b}) 169a45ae5f8SJohn MarinoA new breakpoint @var{b} has been created. 1705796c8dcSSimon Schubert@end deftypefun 1715796c8dcSSimon Schubert 172a45ae5f8SJohn Marino@deftypefun void breakpoint_deleted (struct breakpoint *@var{b}) 173a45ae5f8SJohn MarinoA breakpoint has been destroyed. The argument @var{b} is the 174a45ae5f8SJohn Marinopointer to the destroyed breakpoint. 1755796c8dcSSimon Schubert@end deftypefun 1765796c8dcSSimon Schubert 177a45ae5f8SJohn Marino@deftypefun void breakpoint_modified (struct breakpoint *@var{b}) 178a45ae5f8SJohn MarinoA breakpoint has been modified in some way. The argument @var{b} 179a45ae5f8SJohn Marinois the modified breakpoint. 1805796c8dcSSimon Schubert@end deftypefun 1815796c8dcSSimon Schubert 182*ef5ccd6cSJohn Marino@deftypefun void traceframe_changed (int @var{tfnum}, int @var{tpnum}) 183*ef5ccd6cSJohn MarinoThe trace frame is changed to @var{tfnum} (e.g., by using the 184*ef5ccd6cSJohn Marino@code{tfind} command). If @var{tfnum} is negative, it means 185*ef5ccd6cSJohn Marino@value{GDBN} resumes live debugging. The number of the tracepoint 186*ef5ccd6cSJohn Marinoassociated with this traceframe is @var{tpnum}. 1875796c8dcSSimon Schubert@end deftypefun 1885796c8dcSSimon Schubert 1895796c8dcSSimon Schubert@deftypefun void architecture_changed (struct gdbarch *@var{newarch}) 1905796c8dcSSimon SchubertThe current architecture has changed. The argument @var{newarch} is 1915796c8dcSSimon Schuberta pointer to the new architecture. 1925796c8dcSSimon Schubert@end deftypefun 1935796c8dcSSimon Schubert 1945796c8dcSSimon Schubert@deftypefun void thread_ptid_changed (ptid_t @var{old_ptid}, ptid_t @var{new_ptid}) 1955796c8dcSSimon SchubertThe thread's ptid has changed. The @var{old_ptid} parameter specifies 1965796c8dcSSimon Schubertthe old value, and @var{new_ptid} specifies the new value. 1975796c8dcSSimon Schubert@end deftypefun 1985796c8dcSSimon Schubert 199cf7f2e2dSJohn Marino@deftypefun void inferior_added (struct inferior *@var{inf}) 200cf7f2e2dSJohn MarinoThe inferior @var{inf} has been added to the list of inferiors. At 201cf7f2e2dSJohn Marinothis point, it might not be associated with any process. 2025796c8dcSSimon Schubert@end deftypefun 2035796c8dcSSimon Schubert 204cf7f2e2dSJohn Marino@deftypefun void inferior_appeared (struct inferior *@var{inf}) 205cf7f2e2dSJohn MarinoThe inferior identified by @var{inf} has been attached to a process. 206cf7f2e2dSJohn Marino@end deftypefun 207cf7f2e2dSJohn Marino 208cf7f2e2dSJohn Marino@deftypefun void inferior_exit (struct inferior *@var{inf}) 209cf7f2e2dSJohn MarinoEither the inferior associated with @var{inf} has been detached from the 210cf7f2e2dSJohn Marinoprocess, or the process has exited. 211cf7f2e2dSJohn Marino@end deftypefun 212cf7f2e2dSJohn Marino 213cf7f2e2dSJohn Marino@deftypefun void inferior_removed (struct inferior *@var{inf}) 214cf7f2e2dSJohn MarinoThe inferior @var{inf} has been removed from the list of inferiors. 215cf7f2e2dSJohn MarinoThis method is called immediately before freeing @var{inf}. 216cf7f2e2dSJohn Marino@end deftypefun 217cf7f2e2dSJohn Marino 218*ef5ccd6cSJohn Marino@deftypefun void memory_changed (struct inferior *@var{inferior}, CORE_ADDR @var{addr}, ssize_t @var{len}, const bfd_byte *@var{data}) 219cf7f2e2dSJohn MarinoBytes from @var{data} to @var{data} + @var{len} have been written 220*ef5ccd6cSJohn Marinoto the @var{inferior} at @var{addr}. 2215796c8dcSSimon Schubert@end deftypefun 2225796c8dcSSimon Schubert 223a45ae5f8SJohn Marino@deftypefun void before_prompt (const char *@var{current_prompt}) 224a45ae5f8SJohn MarinoCalled before a top-level prompt is displayed. @var{current_prompt} is 225a45ae5f8SJohn Marinothe current top-level prompt. 226a45ae5f8SJohn Marino@end deftypefun 227a45ae5f8SJohn Marino 228*ef5ccd6cSJohn Marino@deftypefun void gdb_datadir_changed (void) 229*ef5ccd6cSJohn MarinoVariable gdb_datadir has been set. The value may not necessarily change. 230*ef5ccd6cSJohn Marino@end deftypefun 231*ef5ccd6cSJohn Marino 232*ef5ccd6cSJohn Marino@deftypefun void command_param_changed (const char *@var{param}, const char *@var{value}) 233*ef5ccd6cSJohn MarinoThe parameter of some @code{set} commands in console are changed. This 234*ef5ccd6cSJohn Marinomethod is called after a command @code{set @var{param} @var{value}}. 235*ef5ccd6cSJohn Marino@var{param} is the parameter of @code{set} command, and @var{value} 236*ef5ccd6cSJohn Marinois the value of changed parameter. 237*ef5ccd6cSJohn Marino@end deftypefun 238*ef5ccd6cSJohn Marino 239*ef5ccd6cSJohn Marino@deftypefun void tsv_created (const struct trace_state_variable *@var{tsv}) 240*ef5ccd6cSJohn MarinoThe new trace state variable @var{tsv} is created. 241*ef5ccd6cSJohn Marino@end deftypefun 242*ef5ccd6cSJohn Marino 243*ef5ccd6cSJohn Marino@deftypefun void tsv_deleted (const struct trace_state_variable *@var{tsv}) 244*ef5ccd6cSJohn MarinoThe trace state variable @var{tsv} is deleted. If @var{tsv} is 245*ef5ccd6cSJohn Marino@code{NULL}, all trace state variables are deleted. 246*ef5ccd6cSJohn Marino@end deftypefun 247*ef5ccd6cSJohn Marino 248*ef5ccd6cSJohn Marino@deftypefun void tsv_modified (const struct trace_state_variable *@var{tsv}) 249*ef5ccd6cSJohn MarinoThe trace state value @var{tsv} is modified. 250*ef5ccd6cSJohn Marino@end deftypefun 251*ef5ccd6cSJohn Marino 2525796c8dcSSimon Schubert@deftypefun void test_notification (int @var{somearg}) 2535796c8dcSSimon SchubertThis observer is used for internal testing. Do not use. 2545796c8dcSSimon SchubertSee testsuite/gdb.gdb/observer.exp. 2555796c8dcSSimon Schubert@end deftypefun 2565796c8dcSSimon Schubert 257