GDBN Currently available observers
**********************************

Implementation rationale
========================

An observer is an entity which is interested in being notified when GDB reaches certain states, or certain events occur in GDB. The entity being observed is called the subject.  To receive notifications, the observer attaches a callback to the subject. One subject can have several observers.

observer.c implements an internal generic low-level event notification mechanism.  This generic event notification mechanism is then re-used to implement the exported high-level notification management routines for all possible notifications.

The current implementation of the generic observer provides support for contextual data.  This contextual data is given to the subject when attaching the callback.  In return, the subject will provide this contextual data back to the observer as a parameter of the callback.

Note that the current support for the contextual data is only partial, as it lacks a mechanism that would deallocate this data when the callback is detached.  This is not a problem so far, as this contextual data is only used internally to hold a function pointer.  Later on, if a certain observer needs to provide support for user-level contextual data, then the generic notification mechanism will need to be enhanced to allow the observer to provide a routine to deallocate the data when attaching the callback.

The observer implementation is also currently not reentrant. In particular, it is therefore not possible to call the attach or detach routines during a notification.

Debugging
=========

Observer notifications can be traced using the command set debug observer 1 (see Optional messages about internal happenings (Debugging with GDBN)).

normal_stop Notifications
=========================

GDBN notifies all normal_stop observers when the inferior execution has just stopped, the associated messages and annotations have been printed, and the control is about to be returned to the user.

Note that the normal_stop notification is not emitted when the execution stops due to a breakpoint, and this breakpoint has a condition that is not met.  If the breakpoint has any associated commands list, the commands are executed after the notification is emitted.

The following interfaces are available to manage observers:

 -- Function: extern struct observer *observer_attach_EVENT (observer_EVENT_ftype *F)
     Using the function F, create an observer that is notified when ever EVENT occures, return the observer.

 -- Function: extern void observer_detach_EVENT (struct observer *OBSERVER);
     Remove OBSERVER from the list of observers to be notified when EVENT occurs.

 -- Function: extern void observer_notify_EVENT (void);
     Send a notification to all EVENT observers.

The following observable events are defined:

 -- Function: void normal_stop (struct bpstats *BS)
     The inferior has stopped for real.

 -- Function: void target_changed (struct target_ops *TARGET)
     The target's register contents have changed.

 -- Function: void inferior_created (struct target_ops *OBJFILE, int FROM_TTY)
     GDBN has just connected to an inferior.  For run, GDBN calls this observer while the inferior is still stopped at the entry-point instruction.  For attach and core, GDBN calls this observer immediately after connecting to the inferior, and before any information on the inferior has been printed.

 -- Function: void solib_unloaded (struct so_list *SOLIB)
     The specified shared library has been discovered to be unloaded.