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 occurs, 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, int PRINT_FRAME)
     The inferior has stopped for real.  The  BS argument describes the breakpoints were are stopped at, if any.  Second argument PRINT_FRAME non-zero means display the location where the inferior has stopped.

 -- Function: void signal_received (enum gdb_signal SIGGNAL)
     The inferior was stopped by a signal.

 -- Function: void end_stepping_range (void)
     We are done with a step/next/si/ni command.

 -- Function: void signal_exited (enum gdb_signal SIGGNAL)
     The inferior was terminated by a signal.

 -- Function: void exited (int EXITSTATUS)
     The inferior program is finished.

 -- Function: void no_history (void)
     Reverse execution: target ran out of history info.

 -- Function: void sync_execution_done (void)
     A synchronous command finished.

 -- Function: void command_error (void)
     An error was caught while executing a command.

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

 -- Function: void executable_changed (void)
     The executable being debugged by GDB has changed: The user decided to debug a different program, or the program he was debugging has been modified since being loaded by the debugger (by being recompiled, for instance).

 -- 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 record_changed (struct inferior *INFERIOR, int STARTED, const char *METHOD, const char *FORMAT)
     The status of process record for inferior INFERIOR in GDBN has changed.  The process record is started if STARTED is true, and the process record is stopped if STARTED is false.

     When STARTED is true, METHOD indicates the short name of the method used for recording.  If the method supports multiple formats, FORMAT indicates which one is being used, otherwise it is NULL.  When STARTED is false, they are both NULL.

 -- Function: void solib_loaded (struct so_list *SOLIB)
     The shared library specified by SOLIB has been loaded.  Note that when GDBN calls this observer, the library's symbols probably haven't been loaded yet.

 -- Function: void solib_unloaded (struct so_list *SOLIB)
     The shared library specified by SOLIB has been unloaded. Note that when GDBN calls this observer, the library's symbols have not been unloaded yet, and thus are still available.

 -- Function: void new_objfile (struct objfile *OBJFILE)
     The symbol file specified by OBJFILE has been loaded. Called with OBJFILE equal to NULL to indicate previously loaded symbol table data has now been invalidated.

 -- Function: void free_objfile (struct objfile *OBJFILE)
     The object file specified by OBJFILE is about to be freed.

 -- Function: void new_thread (struct thread_info *T)
     The thread specified by T has been created.

 -- Function: void thread_exit (struct thread_info *T, int SILENT)
     The thread specified by T has exited.  The SILENT argument indicates that GDBN is removing the thread from its tables without wanting to notify the user about it.

 -- Function: void thread_stop_requested (ptid_t PTID)
     An explicit stop request was issued to PTID.  If PTID equals MINUS_ONE_PTID, the request applied to all threads.  If ptid_is_pid(ptid) returns true, the request applied to all threads of the process pointed at by PTID.  Otherwise, the request applied to the single thread pointed at by PTID.

 -- Function: void target_resumed (ptid_t PTID)
     The target was resumed.  The PTID parameter specifies which thread was resume, and may be RESUME_ALL if all threads are resumed.

 -- Function: void about_to_proceed (void)
     The target is about to be proceeded.

 -- Function: void breakpoint_created (struct breakpoint *B)
     A new breakpoint B has been created.

 -- Function: void breakpoint_deleted (struct breakpoint *B)
     A breakpoint has been destroyed.  The argument B is the pointer to the destroyed breakpoint.

 -- Function: void breakpoint_modified (struct breakpoint *B)
     A breakpoint has been modified in some way.  The argument B is the modified breakpoint.

 -- Function: void traceframe_changed (int TFNUM, int TPNUM)
     The trace frame is changed to TFNUM (e.g., by using the tfind command).  If TFNUM is negative, it means GDBN resumes live debugging.  The number of the tracepoint associated with this traceframe is TPNUM.

 -- Function: void architecture_changed (struct gdbarch *NEWARCH)
     The current architecture has changed.  The argument NEWARCH is a pointer to the new architecture.

 -- Function: void thread_ptid_changed (ptid_t OLD_PTID, ptid_t NEW_PTID)
     The thread's ptid has changed.  The OLD_PTID parameter specifies the old value, and NEW_PTID specifies the new value.

 -- Function: void inferior_added (struct inferior *INF)
     The inferior INF has been added to the list of inferiors.  At this point, it might not be associated with any process.

 -- Function: void inferior_appeared (struct inferior *INF)
     The inferior identified by INF has been attached to a process.

 -- Function: void inferior_exit (struct inferior *INF)
     Either the inferior associated with INF has been detached from the process, or the process has exited.

 -- Function: void inferior_removed (struct inferior *INF)
     The inferior INF has been removed from the list of inferiors. This method is called immediately before freeing INF.

 -- Function: void memory_changed (struct inferior *INFERIOR, CORE_ADDR ADDR, ssize_t LEN, const bfd_byte *DATA)
     Bytes from DATA to DATA + LEN have been written to the INFERIOR at ADDR.

 -- Function: void before_prompt (const char *CURRENT_PROMPT)
     Called before a top-level prompt is displayed.  CURRENT_PROMPT is the current top-level prompt.

 -- Function: void gdb_datadir_changed (void)
     Variable gdb_datadir has been set.  The value may not necessarily change.

 -- Function: void command_param_changed (const char *PARAM, const char *VALUE)
     The parameter of some set commands in console are changed.  This method is called after a command set PARAM VALUE. PARAM is the parameter of set command, and VALUE is the value of changed parameter.

 -- Function: void tsv_created (const struct trace_state_variable *TSV)
     The new trace state variable TSV is created.

 -- Function: void tsv_deleted (const struct trace_state_variable *TSV)
     The trace state variable TSV is deleted.  If TSV is NULL, all trace state variables are deleted.

 -- Function: void tsv_modified (const struct trace_state_variable *TSV)
     The trace state value TSV is modified.

 -- Function: void inferior_call_pre (ptid_t THREAD, CORE_ADDR ADDRESS)
     An inferior function at ADDRESS is about to be called in thread THREAD.

 -- Function: void inferior_call_post (ptid_t THREAD, CORE_ADDR ADDRESS)
     The inferior function at ADDRESS has just been called.  This observer is called even if the inferior exits during the call.  THREAD is the thread in which the function was called, which may be different from the current thread.

 -- Function: void register_changed (struct frame_info *FRAME, int REGNUM)
     A register in the inferior has been modified by the GDBN user.

 -- Function: void test_notification (int SOMEARG)
     This observer is used for internal testing.  Do not use. See testsuite/gdb.gdb/observer.exp.