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. */
24 #include "terminal.h" /* for job_control*/
26 #include "event-loop.h"
28 /* readline include files */
29 #include <readline/readline.h>
30 #include <readline/history.h>
32 /* readline defines this. */
35 extern void _initialize_event_loop PARAMS ((void));
37 static void command_line_handler PARAMS ((char *));
38 static void command_line_handler_continuation PARAMS ((struct continuation_arg *));
39 void gdb_readline2 PARAMS ((void));
40 void pop_prompt PARAMS ((void));
41 void push_prompt PARAMS ((char *, char *, char *));
42 static void change_line_handler PARAMS ((void));
43 static void change_annotation_level PARAMS ((void));
44 static void command_handler PARAMS ((char *));
46 /* Signal handlers. */
47 void handle_sigint PARAMS ((int));
48 static void handle_sigquit PARAMS ((int));
49 static void handle_sighup PARAMS ((int));
50 static void handle_sigfpe PARAMS ((int));
51 static void handle_sigwinch PARAMS ((int));
52 /* Signal to catch ^Z typed while reading a command: SIGTSTP or SIGCONT. */
55 #define STOP_SIGNAL SIGTSTP
56 void handle_stop_sig PARAMS ((int));
60 /* Functions to be invoked by the event loop in response to
62 void async_request_quit PARAMS ((gdb_client_data));
63 static void async_do_nothing PARAMS ((gdb_client_data));
64 static void async_disconnect PARAMS ((gdb_client_data));
65 static void async_float_handler PARAMS ((gdb_client_data));
66 static void async_stop_sig PARAMS ((gdb_client_data));
68 /* If this definition isn't overridden by the header files, assume
69 that isatty and fileno exist on this system. */
71 #define ISATTY(FP) (isatty (fileno (FP)))
74 /* Readline offers an alternate interface, via callback
75 functions. These are all included in the file callback.c in the
76 readline distribution. This file provides (mainly) a function, which
77 the event loop uses as callback (i.e. event handler) whenever an event
78 is detected on the standard input file descriptor.
79 readline_callback_read_char is called (by the GDB event loop) whenever
80 there is a new character ready on the input stream. This function
81 incrementally builds a buffer internal to readline where it
82 accumulates the line read up to the point of invocation. In the
83 special case in which the character read is newline, the function
84 invokes a GDB supplied callback routine, which does the processing of
85 a full command line. This latter routine is the asynchronous analog
86 of the old command_line_input in gdb. Instead of invoking (and waiting
87 for) readline to read the command line and pass it back to
88 command_loop for processing, the new command_line_handler function has
89 the command line already available as its parameter. INPUT_HANDLER is
90 to be set to the function that readline will invoke when a complete
91 line of input is ready. CALL_READLINE is to be set to the function
92 that readline offers as callback to the event_loop. */
94 void (*input_handler) PARAMS ((char *));
95 void (*call_readline) PARAMS ((void));
97 /* Important variables for the event loop. */
99 /* This is used to determine if GDB is using the readline library or
100 its own simplified form of readline. It is used by the asynchronous
101 form of the set editing command.
102 ezannoni: as of 1999-04-29 I expect that this
103 variable will not be used after gdb is changed to use the event
104 loop as default engine, and event-top.c is merged into top.c. */
105 int async_command_editing_p;
107 /* This variable contains the new prompt that the user sets with the
108 set prompt command. */
109 char *new_async_prompt;
111 /* This is the annotation suffix that will be used when the
112 annotation_level is 2. */
113 char *async_annotation_suffix;
115 /* This is the file descriptor for the input stream that GDB uses to
116 read commands from. */
119 /* This is the prompt stack. Prompts will be pushed on the stack as
120 needed by the different 'kinds' of user inputs GDB is asking
121 for. See event-loop.h. */
122 struct prompts the_prompts;
124 /* signal handling variables */
125 /* Each of these is a pointer to a function that the event loop will
126 invoke if the corresponding signal has received. The real signal
127 handlers mark these functions as ready to be executed and the event
128 loop, in a later iteration, calls them. See the function
129 invoke_async_signal_handler. */
136 #if defined(SIGWINCH) && defined(SIGWINCH_HANDLER)
143 void mark_async_signal_handler_wrapper PARAMS ((void *));
145 /* Structure to save a partially entered command. This is used when
146 the user types '\' at the end of a command line. This is necessary
147 because each line of input is handled by a different call to
148 command_line_handler, and normally there is no state retained
149 between different calls. */
150 int more_to_come = 0;
152 struct readline_input_state
155 char *linebuffer_ptr;
157 readline_input_state;
160 /* Initialize all the necessary variables, start the event loop,
161 register readline, and stdin, start the loop. */
167 char *gdb_prompt = get_prompt ();
169 /* If we are using readline, set things up and display the first
170 prompt, otherwise just print the prompt. */
171 if (async_command_editing_p)
173 /* Tell readline what the prompt to display is and what function it
174 will need to call after a whole line is read. This also displays
176 length = strlen (PREFIX (0)) + strlen (gdb_prompt) + strlen (SUFFIX (0)) + 1;
177 a_prompt = (char *) xmalloc (length);
178 strcpy (a_prompt, PREFIX (0));
179 strcat (a_prompt, gdb_prompt);
180 strcat (a_prompt, SUFFIX (0));
181 rl_callback_handler_install (a_prompt, input_handler);
184 display_gdb_prompt (0);
186 /* Now it's time to start the event loop. */
190 /* Change the function to be invoked every time there is a character
191 ready on stdin. This is used when the user sets the editing off,
192 therefore bypassing readline, and letting gdb handle the input
193 itself, via gdb_readline2. Also it is used in the opposite case in
194 which the user sets editing on again, by restoring readline
195 handling of the input. */
197 change_line_handler ()
199 if (async_command_editing_p)
201 /* Turn on editing by using readline. */
202 call_readline = rl_callback_read_char;
203 input_handler = command_line_handler;
207 /* Turn off editing by using gdb_readline2. */
208 rl_callback_handler_remove ();
209 call_readline = gdb_readline2;
211 /* Set up the command handler as well, in case we are called as
212 first thing from .gdbinit. */
213 input_handler = command_line_handler;
216 /* To tell the event loop to change the handler associated with the
217 input file descriptor, we need to create a new event source,
218 corresponding to the same fd, but with a new event handler
220 /* NOTE: this operates on input_fd, not instream. If we are reading
221 commands from a file, instream will point to the file. However in
222 async mode, we always read commands from a file with editing
223 off. This means that the 'set editing on/off' will have effect
224 only on the interactive session. */
225 delete_file_handler (input_fd);
226 add_file_handler (input_fd, (file_handler_func *) call_readline, 0);
229 /* Displays the prompt. The prompt that is displayed is the current
230 top of the prompt stack, if the argument NEW_PROMPT is
231 0. Otherwise, it displays whatever NEW_PROMPT is. This is used
232 after each gdb command has completed, and in the following cases:
233 1. when the user enters a command line which is ended by '\'
234 indicating that the command will continue on the next line.
235 In that case the prompt that is displayed is the empty string.
236 2. When the user is entering 'commands' for a breakpoint, or
237 actions for a tracepoint. In this case the prompt will be '>'
239 FIXME: 2. & 3. not implemented yet for async. */
241 display_gdb_prompt (new_prompt)
244 int prompt_length = 0;
245 char *gdb_prompt = get_prompt ();
249 /* Just use the top of the prompt stack. */
250 prompt_length = strlen (PREFIX (0)) +
251 strlen (SUFFIX (0)) +
252 strlen (gdb_prompt) + 1;
254 new_prompt = (char *) alloca (prompt_length);
256 /* Prefix needs to have new line at end. */
257 strcpy (new_prompt, PREFIX (0));
258 strcat (new_prompt, gdb_prompt);
259 /* Suffix needs to have a new line at end and \032 \032 at
261 strcat (new_prompt, SUFFIX (0));
264 if (async_command_editing_p)
266 rl_callback_handler_remove ();
267 rl_callback_handler_install (new_prompt, input_handler);
271 /* Don't use a _filtered function here. It causes the assumed
272 character position to be off, since the newline we read from
273 the user is not accounted for. */
274 fputs_unfiltered (new_prompt, gdb_stdout);
277 /* Move to a new line so the entered line doesn't have a prompt
278 on the front of it. */
279 fputs_unfiltered ("\n", gdb_stdout);
281 gdb_flush (gdb_stdout);
285 /* Used when the user requests a different annotation level, with
286 'set annotate'. It pushes a new prompt (with prefix and suffix) on top
287 of the prompt stack, if the annotation level desired is 2, otherwise
288 it pops the top of the prompt stack when we want the annotation level
289 to be the normal ones (1 or 2). */
291 change_annotation_level ()
293 char *prefix, *suffix;
295 if (!PREFIX (0) || !PROMPT (0) || !SUFFIX (0))
297 /* The prompt stack has not been initialized to "", we are
298 using gdb w/o the --async switch */
299 warning ("Command has same effect as set annotate");
303 if (annotation_level > 1)
305 if (!strcmp (PREFIX (0), "") && !strcmp (SUFFIX (0), ""))
307 /* Push a new prompt if the previous annotation_level was not >1. */
308 prefix = (char *) alloca (strlen (async_annotation_suffix) + 10);
309 strcpy (prefix, "\n\032\032pre-");
310 strcat (prefix, async_annotation_suffix);
311 strcat (prefix, "\n");
313 suffix = (char *) alloca (strlen (async_annotation_suffix) + 6);
314 strcpy (suffix, "\n\032\032");
315 strcat (suffix, async_annotation_suffix);
316 strcat (suffix, "\n");
318 push_prompt (prefix, (char *) 0, suffix);
323 if (strcmp (PREFIX (0), "") && strcmp (SUFFIX (0), ""))
325 /* Pop the top of the stack, we are going back to annotation < 1. */
331 /* Pushes a new prompt on the prompt stack. Each prompt has three
332 parts: prefix, prompt, suffix. Usually prefix and suffix are empty
333 strings, except when the annotation level is 2. Memory is allocated
334 within savestring for the new prompt. */
336 push_prompt (prefix, prompt, suffix)
342 PREFIX (0) = savestring (prefix, strlen (prefix));
344 /* Note that this function is used by the set annotate 2
345 command. This is why we take care of saving the old prompt
346 in case a new one is not specified. */
348 PROMPT (0) = savestring (prompt, strlen (prompt));
350 PROMPT (0) = savestring (PROMPT (-1), strlen (PROMPT (-1)));
352 SUFFIX (0) = savestring (suffix, strlen (suffix));
355 /* Pops the top of the prompt stack, and frees the memory allocated for it. */
359 /* If we are not during a 'synchronous' execution command, in which
360 case, the top prompt would be empty. */
361 if (strcmp (PROMPT (0), ""))
362 /* This is for the case in which the prompt is set while the
363 annotation level is 2. The top prompt will be changed, but when
364 we return to annotation level < 2, we want that new prompt to be
365 in effect, until the user does another 'set prompt'. */
366 if (strcmp (PROMPT (0), PROMPT (-1)))
369 PROMPT (-1) = savestring (PROMPT (0), strlen (PROMPT (0)));
378 /* Handles a gdb command. This function is called by
379 command_line_handler, which has processed one or more input lines
381 /* NOTE: 1999-04-30 This is the asynchronous version of the command_loop
382 function. The command_loop function will be obsolete when we
383 switch to use the event loop at every execution of gdb. */
385 command_handler (command)
388 struct cleanup *old_chain;
389 int stdin_is_tty = ISATTY (stdin);
390 struct continuation_arg *arg1;
391 struct continuation_arg *arg2;
392 long time_at_cmd_start;
394 long space_at_cmd_start = 0;
396 extern int display_time;
397 extern int display_space;
400 extern int insert_mode;
404 if (instream == stdin && stdin_is_tty)
405 reinitialize_more_filter ();
406 old_chain = make_cleanup ((make_cleanup_func) command_loop_marker, 0);
411 /* If readline returned a NULL command, it means that the
412 connection with the terminal is gone. This happens at the
413 end of a testsuite run, after Expect has hung up
414 but GDB is still alive. In such a case, we just quit gdb
415 killing the inferior program too. */
417 quit_command ((char *) 0, stdin == instream);
419 time_at_cmd_start = get_run_time ();
424 extern char **environ;
425 char *lim = (char *) sbrk (0);
427 space_at_cmd_start = (long) (lim - (char *) &environ);
431 execute_command (command, instream == stdin);
433 /* Set things up for this function to be compete later, once the
434 executin has completed, if we are doing an execution command,
435 otherwise, just go ahead and finish. */
436 if (target_has_async && target_executing)
439 (struct continuation_arg *) xmalloc (sizeof (struct continuation_arg));
441 (struct continuation_arg *) xmalloc (sizeof (struct continuation_arg));
444 arg1->data = (PTR) time_at_cmd_start;
445 arg2->data = (PTR) space_at_cmd_start;
446 add_continuation (command_line_handler_continuation, arg1);
449 /* Do any commands attached to breakpoint we stopped at. Only if we
450 are always running synchronously. Or if we have just executed a
451 command that doesn't start the target. */
452 if (!target_has_async || !target_executing)
454 bpstat_do_actions (&stop_bpstat);
455 do_cleanups (old_chain);
459 long cmd_time = get_run_time () - time_at_cmd_start;
461 printf_unfiltered ("Command execution time: %ld.%06ld\n",
462 cmd_time / 1000000, cmd_time % 1000000);
468 extern char **environ;
469 char *lim = (char *) sbrk (0);
470 long space_now = lim - (char *) &environ;
471 long space_diff = space_now - space_at_cmd_start;
473 printf_unfiltered ("Space used: %ld (%c%ld for this command)\n",
475 (space_diff >= 0 ? '+' : '-'),
482 /* Do any commands attached to breakpoint we stopped at. Only if we
483 are always running synchronously. Or if we have just executed a
484 command that doesn't start the target. */
486 command_line_handler_continuation (arg)
487 struct continuation_arg *arg;
489 extern int display_time;
490 extern int display_space;
492 long time_at_cmd_start = (long) arg->data;
493 long space_at_cmd_start = (long) arg->next->data;
495 bpstat_do_actions (&stop_bpstat);
496 /*do_cleanups (old_chain);*/ /*?????FIXME?????*/
500 long cmd_time = get_run_time () - time_at_cmd_start;
502 printf_unfiltered ("Command execution time: %ld.%06ld\n",
503 cmd_time / 1000000, cmd_time % 1000000);
508 extern char **environ;
509 char *lim = (char *) sbrk (0);
510 long space_now = lim - (char *) &environ;
511 long space_diff = space_now - space_at_cmd_start;
513 printf_unfiltered ("Space used: %ld (%c%ld for this command)\n",
515 (space_diff >= 0 ? '+' : '-'),
521 /* Handle a complete line of input. This is called by the callback
522 mechanism within the readline library. Deal with incomplete commands
523 as well, by saving the partial input in a global buffer. */
525 /* NOTE: 1999-04-30 This is the asynchronous version of the
526 command_line_input function. command_line_input will become
527 obsolete once we use the event loop as the default mechanism in
530 command_line_handler (rl)
533 static char *linebuffer = 0;
534 static unsigned linelength = 0;
537 int change_prompt = 0;
544 int repeat = (instream == stdin);
546 if (annotation_level > 1 && instream == stdin)
548 printf_unfiltered ("\n\032\032post-");
549 printf_unfiltered (async_annotation_suffix);
550 printf_unfiltered ("\n");
556 linebuffer = (char *) xmalloc (linelength);
563 strcpy (linebuffer, readline_input_state.linebuffer);
564 p = readline_input_state.linebuffer_ptr;
565 free (readline_input_state.linebuffer);
572 signal (STOP_SIGNAL, handle_stop_sig);
575 /* Make sure that all output has been output. Some machines may let
576 you get away with leaving out some of the gdb_flush, but not all. */
578 gdb_flush (gdb_stdout);
579 gdb_flush (gdb_stderr);
581 if (source_file_name != NULL)
583 ++source_line_number;
584 sprintf (source_error,
585 "%s%s:%d: Error in sourced command file:\n",
589 error_pre_print = source_error;
592 /* If we are in this case, then command_handler will call quit
593 and exit from gdb. */
594 if (!rl || rl == (char *) EOF)
599 if (strlen (rl) + 1 + (p - linebuffer) > linelength)
601 linelength = strlen (rl) + 1 + (p - linebuffer);
602 nline = (char *) xrealloc (linebuffer, linelength);
603 p += nline - linebuffer;
607 /* Copy line. Don't copy null at end. (Leaves line alone
608 if this was just a newline) */
612 free (rl); /* Allocated in readline. */
614 if (p == linebuffer || *(p - 1) == '\\')
616 /* We come here also if the line entered is empty (just a 'return') */
617 p--; /* Put on top of '\'. */
621 readline_input_state.linebuffer = savestring (linebuffer,
622 strlen (linebuffer));
623 readline_input_state.linebuffer_ptr = p;
625 /* We will not invoke a execute_command if there is more
626 input expected to complete the command. So, we need to
627 print an empty prompt here. */
628 display_gdb_prompt ("");
635 signal (STOP_SIGNAL, SIG_DFL);
638 #define SERVER_COMMAND_LENGTH 7
640 (p - linebuffer > SERVER_COMMAND_LENGTH)
641 && STREQN (linebuffer, "server ", SERVER_COMMAND_LENGTH);
644 /* Note that we don't set `line'. Between this and the check in
645 dont_repeat, this insures that repeating will still do the
648 command_handler (linebuffer + SERVER_COMMAND_LENGTH);
649 display_gdb_prompt (0);
653 /* Do history expansion if that is wished. */
654 if (history_expansion_p && instream == stdin
655 && ISATTY (instream))
660 *p = '\0'; /* Insert null now. */
661 expanded = history_expand (linebuffer, &history_value);
664 /* Print the changes. */
665 printf_unfiltered ("%s\n", history_value);
667 /* If there was an error, call this function again. */
670 free (history_value);
673 if (strlen (history_value) > linelength)
675 linelength = strlen (history_value) + 1;
676 linebuffer = (char *) xrealloc (linebuffer, linelength);
678 strcpy (linebuffer, history_value);
679 p = linebuffer + strlen (linebuffer);
680 free (history_value);
684 /* If we just got an empty line, and that is supposed
685 to repeat the previous command, return the value in the
687 if (repeat && p == linebuffer && *p != '\\')
689 command_handler (line);
690 display_gdb_prompt (0);
694 for (p1 = linebuffer; *p1 == ' ' || *p1 == '\t'; p1++);
697 command_handler (line);
698 display_gdb_prompt (0);
704 /* Add line to history if appropriate. */
705 if (instream == stdin
706 && ISATTY (stdin) && *linebuffer)
707 add_history (linebuffer);
709 /* Note: lines consisting solely of comments are added to the command
710 history. This is useful when you type a command, and then
711 realize you don't want to execute it quite yet. You can comment
712 out the command and then later fetch it from the value history
713 and remove the '#'. The kill ring is probably better, but some
714 people are in the habit of commenting things out. */
716 *p1 = '\0'; /* Found a comment. */
718 /* Save into global buffer if appropriate. */
721 if (linelength > linesize)
723 line = xrealloc (line, linelength);
724 linesize = linelength;
726 strcpy (line, linebuffer);
729 command_handler (line);
730 display_gdb_prompt (0);
735 command_handler (linebuffer);
736 display_gdb_prompt (0);
740 /* Does reading of input from terminal w/o the editing features
741 provided by the readline library. */
743 /* NOTE: 1999-04-30 Asynchronous version of gdb_readline. gdb_readline
744 will become obsolete when the event loop is made the default
745 execution for gdb. */
752 int result_size = 80;
754 result = (char *) xmalloc (result_size);
756 /* We still need the while loop here, even though it would seem
757 obvious to invoke gdb_readline2 at every character entered. If
758 not using the readline library, the terminal is in cooked mode,
759 which sends the characters all at once. Poll will notice that the
760 input fd has changed state only after enter is pressed. At this
761 point we still need to fetch all the chars entered. */
765 /* Read from stdin if we are executing a user defined command.
766 This is the right thing for prompt_for_continue, at least. */
767 c = fgetc (instream ? instream : stdin);
772 /* The last line does not end with a newline. Return it, and
773 if we are called again fgetc will still return EOF and
774 we'll return NULL then. */
777 (*input_handler) (0);
781 #ifndef CRLF_SOURCE_FILES
785 if (input_index > 0 && result[input_index - 1] == '\r')
791 result[input_index++] = c;
792 while (input_index >= result_size)
795 result = (char *) xrealloc (result, result_size);
799 result[input_index++] = '\0';
800 (*input_handler) (result);
804 /* Initialization of signal handlers and tokens. There is a function
805 handle_sig* for each of the signals GDB cares about. Specifically:
806 SIGINT, SIGFPE, SIGQUIT, SIGTSTP, SIGHUP, SIGWINCH. These
807 functions are the actual signal handlers associated to the signals
808 via calls to signal(). The only job for these functions is to
809 enqueue the appropriate event/procedure with the event loop. Such
810 procedures are the old signal handlers. The event loop will take
811 care of invoking the queued procedures to perform the usual tasks
812 associated with the reception of the signal. */
813 /* NOTE: 1999-04-30 This is the asynchronous version of init_signals.
814 init_signals will become obsolete as we move to have to event loop
815 as the default for gdb. */
817 async_init_signals ()
819 signal (SIGINT, handle_sigint);
821 create_async_signal_handler (async_request_quit, NULL);
823 /* If SIGTRAP was set to SIG_IGN, then the SIG_IGN will get passed
824 to the inferior and breakpoints will be ignored. */
826 signal (SIGTRAP, SIG_DFL);
829 /* If we initialize SIGQUIT to SIG_IGN, then the SIG_IGN will get
830 passed to the inferior, which we don't want. It would be
831 possible to do a "signal (SIGQUIT, SIG_DFL)" after we fork, but
832 on BSD4.3 systems using vfork, that can affect the
833 GDB process as well as the inferior (the signal handling tables
834 might be in memory, shared between the two). Since we establish
835 a handler for SIGQUIT, when we call exec it will set the signal
836 to SIG_DFL for us. */
837 signal (SIGQUIT, handle_sigquit);
839 create_async_signal_handler (async_do_nothing, NULL);
841 if (signal (SIGHUP, handle_sighup) != SIG_IGN)
843 create_async_signal_handler (async_disconnect, NULL);
846 create_async_signal_handler (async_do_nothing, NULL);
848 signal (SIGFPE, handle_sigfpe);
850 create_async_signal_handler (async_float_handler, NULL);
852 #if defined(SIGWINCH) && defined(SIGWINCH_HANDLER)
853 signal (SIGWINCH, handle_sigwinch);
855 create_async_signal_handler (SIGWINCH_HANDLER, NULL);
859 create_async_signal_handler (async_stop_sig, NULL);
865 mark_async_signal_handler_wrapper (token)
868 mark_async_signal_handler ((async_signal_handler *) token);
871 /* Tell the event loop what to do if SIGINT is received.
872 See event-signal.c. */
877 signal (sig, handle_sigint);
879 /* If immediate_quit is set, we go ahead and process the SIGINT right
880 away, even if we usually would defer this to the event loop. The
881 assumption here is that it is safe to process ^C immediately if
882 immediate_quit is set. If we didn't, SIGINT would be really
883 processed only the next time through the event loop. To get to
884 that point, though, the command that we want to interrupt needs to
885 finish first, which is unacceptable. */
887 async_request_quit (0);
889 /* If immediate quit is not set, we process SIGINT the next time
890 through the loop, which is fine. */
891 mark_async_signal_handler_wrapper (sigint_token);
894 /* Do the quit. All the checks have been done by the caller. */
896 async_request_quit (arg)
907 /* Tell the event loop what to do if SIGQUIT is received.
908 See event-signal.c. */
913 mark_async_signal_handler_wrapper (sigquit_token);
914 signal (sig, handle_sigquit);
917 /* Called by the event loop in response to a SIGQUIT. */
919 async_do_nothing (arg)
922 /* Empty function body. */
926 /* Tell the event loop what to do if SIGHUP is received.
927 See event-signal.c. */
932 mark_async_signal_handler_wrapper (sighup_token);
933 signal (sig, handle_sighup);
936 /* Called by the event loop to process a SIGHUP */
938 async_disconnect (arg)
941 catch_errors (quit_cover, NULL,
942 "Could not kill the program being debugged",
944 signal (SIGHUP, SIG_DFL); /*FIXME: ??????????? */
945 kill (getpid (), SIGHUP);
950 void handle_stop_sig (sig)
953 mark_async_signal_handler_wrapper (sigtstp_token);
954 signal (sig, handle_stop_sig);
961 char *prompt = get_prompt ();
962 #if STOP_SIGNAL == SIGTSTP
963 signal (SIGTSTP, SIG_DFL);
965 kill (getpid (), SIGTSTP);
966 signal (SIGTSTP, handle_stop_sig);
968 signal (STOP_SIGNAL, handle_stop_sig);
970 printf_unfiltered ("%s", prompt);
971 gdb_flush (gdb_stdout);
973 /* Forget about any previous command -- null line now will do nothing. */
976 #endif /* STOP_SIGNAL */
978 /* Tell the event loop what to do if SIGFPE is received.
979 See event-signal.c. */
984 mark_async_signal_handler_wrapper (sigfpe_token);
985 signal (sig, handle_sigfpe);
988 /* Event loop will call this functin to process a SIGFPE. */
990 async_float_handler (arg)
993 /* This message is based on ANSI C, section 4.7. Note that integer
994 divide by zero causes this, so "float" is a misnomer. */
995 error ("Erroneous arithmetic operation.");
998 /* Tell the event loop what to do if SIGWINCH is received.
999 See event-signal.c. */
1000 #if defined(SIGWINCH) && defined(SIGWINCH_HANDLER)
1002 handle_sigwinch (sig)
1005 mark_async_signal_handler_wrapper (sigwinch_token);
1006 signal (sig, handle_sigwinch);
1011 /* Called by do_setshow_command. */
1014 set_async_editing_command (args, from_tty, c)
1017 struct cmd_list_element *c;
1019 change_line_handler ();
1022 /* Called by do_setshow_command. */
1025 set_async_annotation_level (args, from_tty, c)
1028 struct cmd_list_element *c;
1030 change_annotation_level ();
1033 /* Called by do_setshow_command. */
1036 set_async_prompt (args, from_tty, c)
1039 struct cmd_list_element *c;
1041 PROMPT (0) = savestring (new_async_prompt, strlen (new_async_prompt));
1044 /* Set things up for readline to be invoked via the alternate
1045 interface, i.e. via a callback function (rl_callback_read_char),
1046 and hook up instream to the event loop.*/
1048 _initialize_event_loop ()
1052 /* When a character is detected on instream by select or poll,
1053 readline will be invoked via this callback function. */
1054 call_readline = rl_callback_read_char;
1056 /* When readline has read an end-of-line character, it passes
1057 the complete line to gdb for processing. command_line_handler
1058 is the function that does this. */
1059 input_handler = command_line_handler;
1061 /* Tell readline to use the same input stream that gdb uses. */
1062 rl_instream = instream;
1064 /* Get a file descriptor for the input stream, so that we can
1065 register it with the event loop. */
1066 input_fd = fileno (instream);
1068 /* Tell gdb to use the cli_command_loop as the main loop. */
1069 command_loop_hook = cli_command_loop;
1071 /* Now we need to create the event sources for the input file
1073 /* At this point in time, this is the only event source that we
1074 register with the even loop. Another source is going to be
1075 the target program (inferior), but that must be registered
1076 only when it actually exists (I.e. after we say 'run' or
1077 after we connect to a remote target. */
1078 add_file_handler (input_fd, (file_handler_func *) call_readline, 0);
1080 /* Tell gdb that we will be using the readline library. This
1081 could be overwritten by a command in .gdbinit like 'set
1082 editing on' or 'off'. */
1083 async_command_editing_p = 1;