1 /* Top level stuff for GDB, the GNU debugger.
2 Copyright 1999 Free Software Foundation, Inc.
3 Written by Elena Zannoni <ezannoni@cygnus.com> of Cygnus Solutions.
5 This file is part of GDB.
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
27 #include "terminal.h" /* for job_control*/
29 #include "event-loop.h"
31 /* readline include files */
32 #include <readline/readline.h>
33 #include <readline/history.h>
35 /* readline defines this. */
38 extern void _initialize_event_loop
PARAMS ((void));
40 static void command_line_handler
PARAMS ((char *));
41 static void gdb_readline2
PARAMS ((void));
42 static void pop_prompt
PARAMS ((void));
43 static void push_prompt
PARAMS ((char *, char *, char *));
44 static void change_line_handler
PARAMS ((void));
45 static void change_annotation_level
PARAMS ((void));
46 static void command_handler
PARAMS ((char *));
48 /* Signal handlers. */
49 static void handle_sigint
PARAMS ((int));
50 static void handle_sigquit
PARAMS ((int));
51 static void handle_sighup
PARAMS ((int));
52 static void handle_sigfpe
PARAMS ((int));
53 static void handle_sigwinch
PARAMS ((int));
54 /* Signal to catch ^Z typed while reading a command: SIGTSTP or SIGCONT. */
57 #define STOP_SIGNAL SIGTSTP
58 void handle_stop_sig
PARAMS ((int));
62 /* Functions to be invoked by the event loop in response to
64 void async_request_quit
PARAMS ((gdb_client_data
));
65 static void async_do_nothing
PARAMS ((gdb_client_data
));
66 static void async_disconnect
PARAMS ((gdb_client_data
));
67 static void async_float_handler
PARAMS ((gdb_client_data
));
68 static void async_stop_sig
PARAMS ((gdb_client_data
));
70 /* If this definition isn't overridden by the header files, assume
71 that isatty and fileno exist on this system. */
73 #define ISATTY(FP) (isatty (fileno (FP)))
76 /* Readline offers an alternate interface, via callback
77 functions. These are all included in the file callback.c in the
78 readline distribution. This file provides (mainly) a function, which
79 the event loop uses as callback (i.e. event handler) whenever an event
80 is detected on the standard input file descriptor.
81 readline_callback_read_char is called (by the GDB event loop) whenever
82 there is a new character ready on the input stream. This function
83 incrementally builds a buffer internal to readline where it
84 accumulates the line read up to the point of invocation. In the
85 special case in which the character read is newline, the function
86 invokes a GDB supplied callback routine, which does the processing of
87 a full command line. This latter routine is the asynchronous analog
88 of the old command_line_input in gdb. Instead of invoking (and waiting
89 for) readline to read the command line and pass it back to
90 command_loop for processing, the new command_line_handler function has
91 the command line already available as its parameter. INPUT_HANDLER is
92 to be set to the function that readline will invoke when a complete
93 line of input is ready. CALL_READLINE is to be set to the function
94 that readline offers as callback to the event_loop. */
96 void (*input_handler
) PARAMS ((char *));
97 void (*call_readline
) PARAMS ((void));
99 /* Important variables for the event loop. */
101 /* This is used to determine if GDB is using the readline library or
102 its own simplified form of readline. It is used by the asynchronous
103 form of the set editing command.
104 ezannoni: as of 1999-04-29 I expect that this
105 variable will not be used after gdb is changed to use the event
106 loop as default engine, and event-top.c is merged into top.c. */
107 int async_command_editing_p
;
109 /* This variable contains the new prompt that the user sets with the
110 set prompt command. */
111 char *new_async_prompt
;
113 /* This is the annotation suffix that will be used when the
114 annotation_level is 2. */
115 char *async_annotation_suffix
;
117 /* This is the file descriptor for the input stream that GDB uses to
118 read commands from. */
121 /* This is the prompt stack. Prompts will be pushed on the stack as
122 needed by the different 'kinds' of user inputs GDB is asking
123 for. See event-loop.h. */
124 struct prompts the_prompts
;
126 /* signal handling variables */
127 /* Each of these is a pointer to a function that the event loop will
128 invoke if the corresponding signal has received. The real signal
129 handlers mark these functions as ready to be executed and the event
130 loop, in a later iteration, calls them. See the function
131 invoke_async_signal_handler. */
138 #if defined(SIGWINCH) && defined(SIGWINCH_HANDLER)
145 void mark_async_signal_handler_wrapper
PARAMS ((void *));
147 /* Structure to save a partially entered command. This is used when
148 the user types '\' at the end of a command line. This is necessary
149 because each line of input is handled by a different call to
150 command_line_handler, and normally there is no state retained
151 between different calls. */
152 int more_to_come
= 0;
154 struct readline_input_state
157 char *linebuffer_ptr
;
159 readline_input_state
;
162 /* Initialize all the necessary variables, start the event loop,
163 register readline, and stdin. */
169 char *gdb_prompt
= get_prompt ();
171 /* If we are using readline, set things up and display the first
172 prompt, otherwise just print the prompt. */
173 if (async_command_editing_p
)
175 /* Tell readline what the prompt to display is and what function it
176 will need to call after a whole line is read. This also displays
178 length
= strlen (PREFIX (0)) + strlen (gdb_prompt
) + strlen (SUFFIX (0)) + 1;
179 a_prompt
= (char *) xmalloc (length
);
180 strcpy (a_prompt
, PREFIX (0));
181 strcat (a_prompt
, gdb_prompt
);
182 strcat (a_prompt
, SUFFIX (0));
183 rl_callback_handler_install (a_prompt
, input_handler
);
186 display_gdb_prompt (0);
188 /* Loop until there is something to do. This is the entry point to
189 the event loop engine. gdb_do_one_event will process one event
190 for each invocation. It always returns 1, unless there are no
191 more event sources registered. In this case it returns 0. */
192 while (gdb_do_one_event () != 0)
195 /* We are done with the event loop. There are no more event sources
196 to listen to. So we exit GDB. */
200 /* Change the function to be invoked every time there is a character
201 ready on stdin. This is used when the user sets the editing off,
202 therefore bypassing readline, and letting gdb handle the input
203 itself, via gdb_readline2. Also it is used in the opposite case in
204 which the user sets editing on again, by restoring readline
205 handling of the input. */
207 change_line_handler ()
209 if (async_command_editing_p
)
211 /* Turn on editing by using readline. */
212 call_readline
= rl_callback_read_char
;
213 input_handler
= command_line_handler
;
217 /* Turn off editing by using gdb_readline2. */
218 rl_callback_handler_remove ();
219 call_readline
= gdb_readline2
;
221 /* Set up the command handler as well, in case we are called as
222 first thing from .gdbinit. */
223 input_handler
= command_line_handler
;
226 /* To tell the event loop to change the handler associated with the
227 input file descriptor, we need to create a new event source,
228 corresponding to the same fd, but with a new event handler
230 delete_file_handler (input_fd
);
232 create_file_handler (input_fd
, POLLIN
,
233 (file_handler_func
*) call_readline
, 0);
235 create_file_handler (input_fd
, GDB_READABLE
,
236 (file_handler_func
*) call_readline
, 0);
240 /* Displays the prompt. The prompt that is displayed is the current
241 top of the prompt stack, if the argument NEW_PROMPT is
242 0. Otherwise, it displays whatever NEW_PROMPT is. This is used
243 after each gdb command has completed, and in the following cases:
244 1. when the user enters a command line which is ended by '\'
245 indicating that the command will continue on the next line.
246 In that case the prompt that is displayed is the empty string.
247 2. When the user is entering 'commands' for a breakpoint, or
248 actions for a tracepoint. In this case the prompt will be '>'
250 FIXME: 2. & 3. not implemented yet for async. */
252 display_gdb_prompt (new_prompt
)
255 int prompt_length
= 0;
256 char *gdb_prompt
= get_prompt ();
260 /* Just use the top of the prompt stack. */
261 prompt_length
= strlen (PREFIX (0)) +
262 strlen (SUFFIX (0)) +
263 strlen (gdb_prompt
) + 1;
265 new_prompt
= (char *) alloca (prompt_length
);
267 /* Prefix needs to have new line at end. */
268 strcpy (new_prompt
, PREFIX (0));
269 strcat (new_prompt
, gdb_prompt
);
270 /* Suffix needs to have a new line at end and \032 \032 at
272 strcat (new_prompt
, SUFFIX (0));
275 if (async_command_editing_p
)
277 rl_callback_handler_remove ();
278 rl_callback_handler_install (new_prompt
, input_handler
);
282 /* Don't use a _filtered function here. It causes the assumed
283 character position to be off, since the newline we read from
284 the user is not accounted for. */
285 fputs_unfiltered (new_prompt
, gdb_stdout
);
288 /* Move to a new line so the entered line doesn't have a prompt
289 on the front of it. */
290 fputs_unfiltered ("\n", gdb_stdout
);
292 gdb_flush (gdb_stdout
);
296 /* Used when the user requests a different annotation level, with
297 'set annotate'. It pushes a new prompt (with prefix and suffix) on top
298 of the prompt stack, if the annotation level desired is 2, otherwise
299 it pops the top of the prompt stack when we want the annotation level
300 to be the normal ones (1 or 2). */
302 change_annotation_level ()
304 char *prefix
, *suffix
;
306 if (!PREFIX (0) || !PROMPT (0) || !SUFFIX (0))
308 /* The prompt stack has not been initialized to "", we are
309 using gdb w/o the --async switch */
310 warning ("Command has same effect as set annotate");
314 if (annotation_level
> 1)
316 if (!strcmp (PREFIX (0), "") && !strcmp (SUFFIX (0), ""))
318 /* Push a new prompt if the previous annotation_level was not >1. */
319 prefix
= (char *) alloca (strlen (async_annotation_suffix
) + 10);
320 strcpy (prefix
, "\n\032\032pre-");
321 strcat (prefix
, async_annotation_suffix
);
322 strcat (prefix
, "\n");
324 suffix
= (char *) alloca (strlen (async_annotation_suffix
) + 6);
325 strcpy (suffix
, "\n\032\032");
326 strcat (suffix
, async_annotation_suffix
);
327 strcat (suffix
, "\n");
329 push_prompt (prefix
, (char *) 0, suffix
);
334 if (strcmp (PREFIX (0), "") && strcmp (SUFFIX (0), ""))
336 /* Pop the top of the stack, we are going back to annotation < 1. */
342 /* Pushes a new prompt on the prompt stack. Each prompt has three
343 parts: prefix, prompt, suffix. Usually prefix and suffix are empty
344 strings, except when the annotation level is 2. Memory is allocated
345 within savestring for the new prompt. */
347 push_prompt (prefix
, prompt
, suffix
)
353 PREFIX (0) = savestring (prefix
, strlen (prefix
));
356 PROMPT (0) = savestring (prompt
, strlen (prompt
));
358 PROMPT (0) = savestring (PROMPT (-1), strlen (PROMPT (-1)));
360 SUFFIX (0) = savestring (suffix
, strlen (suffix
));
363 /* Pops the top of the prompt stack, and frees the memory allocated for it. */
367 if (strcmp (PROMPT (0), PROMPT (-1)))
370 PROMPT (-1) = savestring (PROMPT (0), strlen (PROMPT (0)));
379 /* Handles a gdb command. This function is called by
380 command_line_handler, which has processed one or more input lines
382 /* NOTE: 1999-04-30 This is the asynchronous version of the command_loop
383 function. The command_loop function will be obsolete when we
384 switch to use the event loop at every execution of gdb. */
386 command_handler (command
)
389 struct cleanup
*old_chain
;
390 int stdin_is_tty
= ISATTY (stdin
);
391 long time_at_cmd_start
;
393 long space_at_cmd_start
= 0;
395 extern int display_time
;
396 extern int display_space
;
399 extern int insert_mode
;
403 if (instream
== stdin
&& stdin_is_tty
)
404 reinitialize_more_filter ();
405 old_chain
= make_cleanup ((make_cleanup_func
) command_loop_marker
, 0);
410 /* If readline returned a NULL command, it means that the
411 connection with the terminal is gone. This happens at the
412 end of a testsuite run, after Expect has hung up
413 but GDB is still alive. In such a case, we just quit gdb
414 killing the inferior program too. */
416 quit_command ((char *) 0, stdin
== instream
);
418 time_at_cmd_start
= get_run_time ();
423 extern char **environ
;
424 char *lim
= (char *) sbrk (0);
426 space_at_cmd_start
= (long) (lim
- (char *) &environ
);
430 execute_command (command
, instream
== stdin
);
432 /* Do any commands attached to breakpoint we stopped at. */
433 bpstat_do_actions (&stop_bpstat
);
434 do_cleanups (old_chain
);
438 long cmd_time
= get_run_time () - time_at_cmd_start
;
440 printf_unfiltered ("Command execution time: %ld.%06ld\n",
441 cmd_time
/ 1000000, cmd_time
% 1000000);
447 extern char **environ
;
448 char *lim
= (char *) sbrk (0);
449 long space_now
= lim
- (char *) &environ
;
450 long space_diff
= space_now
- space_at_cmd_start
;
452 printf_unfiltered ("Space used: %ld (%c%ld for this command)\n",
454 (space_diff
>= 0 ? '+' : '-'),
460 /* Handle a complete line of input. This is called by the callback
461 mechanism within the readline library. Deal with incomplete commands
462 as well, by saving the partial input in a global buffer. */
464 /* NOTE: 1999-04-30 This is the asynchronous version of the
465 command_line_input function. command_line_input will become
466 obsolete once we use the event loop as the default mechanism in
469 command_line_handler (rl
)
472 static char *linebuffer
= 0;
473 static unsigned linelength
= 0;
476 int change_prompt
= 0;
483 int repeat
= (instream
== stdin
);
485 if (annotation_level
> 1 && instream
== stdin
)
487 printf_unfiltered ("\n\032\032post-");
488 printf_unfiltered (async_annotation_suffix
);
489 printf_unfiltered ("\n");
495 linebuffer
= (char *) xmalloc (linelength
);
502 strcpy (linebuffer
, readline_input_state
.linebuffer
);
503 p
= readline_input_state
.linebuffer_ptr
;
504 free (readline_input_state
.linebuffer
);
511 signal (STOP_SIGNAL
, handle_stop_sig
);
514 /* Make sure that all output has been output. Some machines may let
515 you get away with leaving out some of the gdb_flush, but not all. */
517 gdb_flush (gdb_stdout
);
518 gdb_flush (gdb_stderr
);
520 if (source_file_name
!= NULL
)
522 ++source_line_number
;
523 sprintf (source_error
,
524 "%s%s:%d: Error in sourced command file:\n",
528 error_pre_print
= source_error
;
531 /* If we are in this case, then command_handler will call quit
532 and exit from gdb. */
533 if (!rl
|| rl
== (char *) EOF
)
538 if (strlen (rl
) + 1 + (p
- linebuffer
) > linelength
)
540 linelength
= strlen (rl
) + 1 + (p
- linebuffer
);
541 nline
= (char *) xrealloc (linebuffer
, linelength
);
542 p
+= nline
- linebuffer
;
546 /* Copy line. Don't copy null at end. (Leaves line alone
547 if this was just a newline) */
551 free (rl
); /* Allocated in readline. */
553 if (p
== linebuffer
|| *(p
- 1) == '\\')
555 /* We come here also if the line entered is empty (just a 'return') */
556 p
--; /* Put on top of '\'. */
560 readline_input_state
.linebuffer
= savestring (linebuffer
,
561 strlen (linebuffer
));
562 readline_input_state
.linebuffer_ptr
= p
;
564 /* We will not invoke a execute_command if there is more
565 input expected to complete the command. So, we need to
566 print an empty prompt here. */
567 display_gdb_prompt ("");
574 signal (STOP_SIGNAL
, SIG_DFL
);
577 #define SERVER_COMMAND_LENGTH 7
579 (p
- linebuffer
> SERVER_COMMAND_LENGTH
)
580 && STREQN (linebuffer
, "server ", SERVER_COMMAND_LENGTH
);
583 /* Note that we don't set `line'. Between this and the check in
584 dont_repeat, this insures that repeating will still do the
587 command_handler (linebuffer
+ SERVER_COMMAND_LENGTH
);
588 display_gdb_prompt (0);
592 /* Do history expansion if that is wished. */
593 if (history_expansion_p
&& instream
== stdin
594 && ISATTY (instream
))
599 *p
= '\0'; /* Insert null now. */
600 expanded
= history_expand (linebuffer
, &history_value
);
603 /* Print the changes. */
604 printf_unfiltered ("%s\n", history_value
);
606 /* If there was an error, call this function again. */
609 free (history_value
);
612 if (strlen (history_value
) > linelength
)
614 linelength
= strlen (history_value
) + 1;
615 linebuffer
= (char *) xrealloc (linebuffer
, linelength
);
617 strcpy (linebuffer
, history_value
);
618 p
= linebuffer
+ strlen (linebuffer
);
619 free (history_value
);
623 /* If we just got an empty line, and that is supposed
624 to repeat the previous command, return the value in the
626 if (repeat
&& p
== linebuffer
&& *p
!= '\\')
628 command_handler (line
);
629 display_gdb_prompt (0);
633 for (p1
= linebuffer
; *p1
== ' ' || *p1
== '\t'; p1
++);
636 command_handler (line
);
637 display_gdb_prompt (0);
643 /* Add line to history if appropriate. */
644 if (instream
== stdin
645 && ISATTY (stdin
) && *linebuffer
)
646 add_history (linebuffer
);
648 /* Note: lines consisting solely of comments are added to the command
649 history. This is useful when you type a command, and then
650 realize you don't want to execute it quite yet. You can comment
651 out the command and then later fetch it from the value history
652 and remove the '#'. The kill ring is probably better, but some
653 people are in the habit of commenting things out. */
655 *p1
= '\0'; /* Found a comment. */
657 /* Save into global buffer if appropriate. */
660 if (linelength
> linesize
)
662 line
= xrealloc (line
, linelength
);
663 linesize
= linelength
;
665 strcpy (line
, linebuffer
);
668 command_handler (line
);
669 display_gdb_prompt (0);
674 command_handler (linebuffer
);
675 display_gdb_prompt (0);
679 /* Does reading of input from terminal w/o the editing features
680 provided by the readline library. */
682 /* NOTE: 1999-04-30 Asynchronous version of gdb_readline. gdb_readline
683 will become obsolete when the event loop is made the default
684 execution for gdb. */
691 int result_size
= 80;
693 result
= (char *) xmalloc (result_size
);
695 /* We still need the while loop here, even though it would seem
696 obvious to invoke gdb_readline2 at every character entered. If
697 not using the readline library, the terminal is in cooked mode,
698 which sends the characters all at once. Poll will notice that the
699 input fd has changed state only after enter is pressed. At this
700 point we still need to fetch all the chars entered. */
704 /* Read from stdin if we are executing a user defined command.
705 This is the right thing for prompt_for_continue, at least. */
706 c
= fgetc (instream
? instream
: stdin
);
711 /* The last line does not end with a newline. Return it, and
712 if we are called again fgetc will still return EOF and
713 we'll return NULL then. */
716 (*input_handler
) (0);
720 #ifndef CRLF_SOURCE_FILES
724 if (input_index
> 0 && result
[input_index
- 1] == '\r')
730 result
[input_index
++] = c
;
731 while (input_index
>= result_size
)
734 result
= (char *) xrealloc (result
, result_size
);
738 result
[input_index
++] = '\0';
739 (*input_handler
) (result
);
743 /* Initialization of signal handlers and tokens. There is a function
744 handle_sig* for each of the signals GDB cares about. Specifically:
745 SIGINT, SIGFPE, SIGQUIT, SIGTSTP, SIGHUP, SIGWINCH. These
746 functions are the actual signal handlers associated to the signals
747 via calls to signal(). The only job for these functions is to
748 enqueue the appropriate event/procedure with the event loop. Such
749 procedures are the old signal handlers. The event loop will take
750 care of invoking the queued procedures to perform the usual tasks
751 associated with the reception of the signal. */
752 /* NOTE: 1999-04-30 This is the asynchronous version of init_signals.
753 init_signals will become obsolete as we move to have to event loop
754 as the default for gdb. */
756 async_init_signals ()
758 signal (SIGINT
, handle_sigint
);
760 create_async_signal_handler (async_request_quit
, NULL
);
762 /* If SIGTRAP was set to SIG_IGN, then the SIG_IGN will get passed
763 to the inferior and breakpoints will be ignored. */
765 signal (SIGTRAP
, SIG_DFL
);
768 /* If we initialize SIGQUIT to SIG_IGN, then the SIG_IGN will get
769 passed to the inferior, which we don't want. It would be
770 possible to do a "signal (SIGQUIT, SIG_DFL)" after we fork, but
771 on BSD4.3 systems using vfork, that can affect the
772 GDB process as well as the inferior (the signal handling tables
773 might be in memory, shared between the two). Since we establish
774 a handler for SIGQUIT, when we call exec it will set the signal
775 to SIG_DFL for us. */
776 signal (SIGQUIT
, handle_sigquit
);
778 create_async_signal_handler (async_do_nothing
, NULL
);
780 if (signal (SIGHUP
, handle_sighup
) != SIG_IGN
)
782 create_async_signal_handler (async_disconnect
, NULL
);
785 create_async_signal_handler (async_do_nothing
, NULL
);
787 signal (SIGFPE
, handle_sigfpe
);
789 create_async_signal_handler (async_float_handler
, NULL
);
791 #if defined(SIGWINCH) && defined(SIGWINCH_HANDLER)
792 signal (SIGWINCH
, handle_sigwinch
);
794 create_async_signal_handler (SIGWINCH_HANDLER
, NULL
);
798 create_async_signal_handler (async_stop_sig
, NULL
);
804 mark_async_signal_handler_wrapper (token
)
807 mark_async_signal_handler ((async_signal_handler
*) token
);
810 /* Tell the event loop what to do if SIGINT is received.
811 See event-signal.c. */
816 signal (sig
, handle_sigint
);
818 /* If immediate_quit is set, we go ahead and process the SIGINT right
819 away, even if we usually would defer this to the event loop. The
820 assumption here is that it is safe to process ^C immediately if
821 immediate_quit is set. If we didn't, SIGINT would be really
822 processed only the next time through the event loop. To get to
823 that point, though, the command that we want to interrupt needs to
824 finish first, which is unacceptable. */
826 async_request_quit (0);
828 /* If immediate quit is not set, we process SIGINT the next time
829 through the loop, which is fine. */
830 mark_async_signal_handler_wrapper (sigint_token
);
833 /* Do the quit. All the checks have been done by the caller. */
835 async_request_quit (arg
)
846 /* Tell the event loop what to do if SIGQUIT is received.
847 See event-signal.c. */
852 mark_async_signal_handler_wrapper (sigquit_token
);
853 signal (sig
, handle_sigquit
);
856 /* Called by the event loop in response to a SIGQUIT. */
858 async_do_nothing (arg
)
861 /* Empty function body. */
865 /* Tell the event loop what to do if SIGHUP is received.
866 See event-signal.c. */
871 mark_async_signal_handler_wrapper (sighup_token
);
872 signal (sig
, handle_sighup
);
875 /* Called by the event loop to process a SIGHUP */
877 async_disconnect (arg
)
880 catch_errors (quit_cover
, NULL
,
881 "Could not kill the program being debugged",
883 signal (SIGHUP
, SIG_DFL
); /*FIXME: ??????????? */
884 kill (getpid (), SIGHUP
);
889 void handle_stop_sig (sig
)
892 mark_async_signal_handler_wrapper (sigtstp_token
);
893 signal (sig
, handle_stop_sig
);
900 char *prompt
= get_prompt ();
901 #if STOP_SIGNAL == SIGTSTP
902 signal (SIGTSTP
, SIG_DFL
);
904 kill (getpid (), SIGTSTP
);
905 signal (SIGTSTP
, handle_stop_sig
);
907 signal (STOP_SIGNAL
, handle_stop_sig
);
909 printf_unfiltered ("%s", prompt
);
910 gdb_flush (gdb_stdout
);
912 /* Forget about any previous command -- null line now will do nothing. */
915 #endif /* STOP_SIGNAL */
917 /* Tell the event loop what to do if SIGFPE is received.
918 See event-signal.c. */
923 mark_async_signal_handler_wrapper (sigfpe_token
);
924 signal (sig
, handle_sigfpe
);
927 /* Event loop will call this functin to process a SIGFPE. */
929 async_float_handler (arg
)
932 /* This message is based on ANSI C, section 4.7. Note that integer
933 divide by zero causes this, so "float" is a misnomer. */
934 error ("Erroneous arithmetic operation.");
937 /* Tell the event loop what to do if SIGWINCH is received.
938 See event-signal.c. */
939 #if defined(SIGWINCH) && defined(SIGWINCH_HANDLER)
941 handle_sigwinch (sig
)
944 mark_async_signal_handler_wrapper (sigwinch_token
);
945 signal (sig
, handle_sigwinch
);
950 /* Called by do_setshow_command. */
953 set_async_editing_command (args
, from_tty
, c
)
956 struct cmd_list_element
*c
;
958 change_line_handler ();
961 /* Called by do_setshow_command. */
964 set_async_annotation_level (args
, from_tty
, c
)
967 struct cmd_list_element
*c
;
969 change_annotation_level ();
972 /* Called by do_setshow_command. */
975 set_async_prompt (args
, from_tty
, c
)
978 struct cmd_list_element
*c
;
980 PROMPT (0) = savestring (new_async_prompt
, strlen (new_async_prompt
));
983 /* Set things up for readline to be invoked via the alternate
984 interface, i.e. via a callback function (rl_callback_read_char),
985 and hook up instream to the event loop.*/
987 _initialize_event_loop ()
991 /* When a character is detected on instream by select or poll,
992 readline will be invoked via this callback function. */
993 call_readline
= rl_callback_read_char
;
995 /* When readline has read an end-of-line character, it passes
996 the complete line to gdb for processing. command_line_handler
997 is the function that does this. */
998 input_handler
= command_line_handler
;
1000 /* Tell readline to use the same input stream that gdb uses. */
1001 rl_instream
= instream
;
1003 /* Get a file descriptor for the input stream, so that we can
1004 register it with the event loop. */
1005 input_fd
= fileno (instream
);
1007 /* Now we need to create the event sources for the input file
1009 /* At this point in time, this is the only event source that we
1010 register with the even loop. Another source is going to be
1011 the target program (inferior), but that must be registered
1012 only when it actually exists (I.e. after we say 'run' or
1013 after we connect to a remote target. */
1015 create_file_handler (input_fd
, POLLIN
,
1016 (file_handler_func
*) call_readline
, 0);
1018 create_file_handler (input_fd
, GDB_READABLE
,
1019 (file_handler_func
*) call_readline
, 0);