1 /* Definitions used by event-top.c, for GDB, the GNU debugger.
2 
3    Copyright (C) 1999-2024 Free Software Foundation, Inc.
4 
5    Written by Elena Zannoni <ezannoni@cygnus.com> of Cygnus Solutions.
6 
7    This file is part of GDB.
8 
9    This program is free software; you can redistribute it and/or modify
10    it under the terms of the GNU General Public License as published by
11    the Free Software Foundation; either version 3 of the License, or
12    (at your option) any later version.
13 
14    This program is distributed in the hope that it will be useful,
15    but WITHOUT ANY WARRANTY; without even the implied warranty of
16    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17    GNU General Public License for more details.
18 
19    You should have received a copy of the GNU General Public License
20    along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
21 
22 #ifndef EVENT_TOP_H
23 #define EVENT_TOP_H
24 
25 #include <signal.h>
26 
27 struct cmd_list_element;
28 
29 /* The current quit handler (and its type).  This is called from the
30    QUIT macro.  See default_quit_handler below for default behavior.
31    Parts of GDB temporarily override this to e.g., completely suppress
32    Ctrl-C because it would not be safe to throw.  E.g., normally, you
33    wouldn't want to quit between a RSP command and its response, as
34    that would break the communication with the target, but you may
35    still want to intercept the Ctrl-C and offer to disconnect if the
36    user presses Ctrl-C multiple times while the target is stuck
37    waiting for the wedged remote stub.  */
38 typedef void (quit_handler_ftype) ();
39 extern quit_handler_ftype *quit_handler;
40 
41 /* Exported functions from event-top.c.
42    FIXME: these should really go into top.h.  */
43 
44 /* The default quit handler.  Checks whether Ctrl-C was pressed, and
45    if so:
46 
47      - If GDB owns the terminal, throws a quit exception.
48 
49      - If GDB does not own the terminal, forwards the Ctrl-C to the
50        target.
51 */
52 
53 extern void default_quit_handler ();
54 
55 /* Flag that function quit should call quit_force.  */
56 
57 extern volatile bool sync_quit_force_run;
58 
59 /* Set sync_quit_force_run and also call set_quit_flag().  */
60 
61 extern void set_force_quit_flag ();
62 
63 /* Control C eventually causes this to be called, at a convenient time.  */
64 
65 extern void quit ();
66 
67 /* Helper for the QUIT macro.  */
68 
69 extern void maybe_quit ();
70 
71 /* Check whether a Ctrl-C was typed, and if so, call the current quit
72    handler.  */
73 
74 #define QUIT maybe_quit ()
75 
76 /* Set the serial event associated with the quit flag.  */
77 
78 extern void quit_serial_event_set ();
79 
80 /* Clear the serial event associated with the quit flag.  */
81 
82 extern void quit_serial_event_clear ();
83 
84 extern void display_gdb_prompt (const char *new_prompt);
85 extern void gdb_setup_readline (int);
86 extern void gdb_disable_readline (void);
87 extern void gdb_init_signals (void);
88 extern void change_line_handler (int);
89 
90 extern void command_line_handler (gdb::unique_xmalloc_ptr<char> &&rl);
91 extern void command_handler (const char *command);
92 
93 #ifdef SIGTSTP
94 extern void handle_sigtstp (int sig);
95 #endif
96 
97 extern void handle_sigint (int sig);
98 extern void handle_sigterm (int sig);
99 extern void async_request_quit (void *arg);
100 extern void async_disable_stdin (void);
101 extern void async_enable_stdin (void);
102 
103 /* Exported variables from event-top.c.
104    FIXME: these should really go into top.h.  */
105 
106 extern bool set_editing_cmd_var;
107 extern bool exec_done_display_p;
108 extern struct prompts the_prompts;
109 extern void (*after_char_processing_hook) (void);
110 extern int call_stdin_event_handler_again_p;
111 extern void gdb_readline_no_editing_callback (void *client_data);
112 
113 /* Wrappers for rl_callback_handler_remove and
114    rl_callback_handler_install that keep track of whether the callback
115    handler is installed in readline.  Do not call the readline
116    versions directly.  */
117 extern void gdb_rl_callback_handler_remove (void);
118 extern void gdb_rl_callback_handler_install (const char *prompt);
119 
120 /* Reinstall the readline callback handler (with no prompt), if not
121    currently installed.  */
122 extern void gdb_rl_callback_handler_reinstall (void);
123 
124 /* Called by readline after a complete line has been gathered from the
125    user, but before the line is dispatched to back to GDB.  This function
126    is a wrapper around readline's builtin rl_deprep_terminal function, and
127    handles the case where readline received EOF.  */
128 extern void gdb_rl_deprep_term_function (void);
129 
130 typedef void (*segv_handler_t) (int);
131 
132 /* On construction, replaces the current thread's SIGSEGV handler with
133    the provided one.  On destruction, restores the handler to the
134    original one.  */
135 class scoped_segv_handler_restore
136 {
137  public:
138   scoped_segv_handler_restore (segv_handler_t new_handler);
139   ~scoped_segv_handler_restore ();
140 
141  private:
142   segv_handler_t m_old_handler;
143 };
144 
145 #endif
146