GDB (xrefs)
Loading...
Searching...
No Matches
event-top.c
Go to the documentation of this file.
1/* Top level stuff for GDB, the GNU debugger.
2
3 Copyright (C) 1999-2023 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#include "defs.h"
23#include "top.h"
24#include "inferior.h"
25#include "infrun.h"
26#include "target.h"
27#include "terminal.h"
28#include "gdbsupport/event-loop.h"
29#include "event-top.h"
30#include "interps.h"
31#include <signal.h>
32#include "cli/cli-script.h" /* for reset_command_nest_depth */
33#include "main.h"
34#include "gdbthread.h"
35#include "observable.h"
36#include "gdbcmd.h" /* for dont_repeat() */
37#include "annotate.h"
38#include "maint.h"
39#include "gdbsupport/buffer.h"
40#include "ser-event.h"
41#include "gdbsupport/gdb_select.h"
42#include "gdbsupport/gdb-sigmask.h"
43#include "async-event.h"
44#include "bt-utils.h"
45#include "pager.h"
46
47/* readline include files. */
48#include "readline/readline.h"
49#include "readline/history.h"
50
51/* readline defines this. */
52#undef savestring
53
54static std::string top_level_prompt ();
55
56/* Signal handlers. */
57#ifdef SIGQUIT
58static void handle_sigquit (int sig);
59#endif
60#ifdef SIGHUP
61static void handle_sighup (int sig);
62#endif
63
64/* Functions to be invoked by the event loop in response to
65 signals. */
66#if defined (SIGQUIT) || defined (SIGHUP)
67static void async_do_nothing (gdb_client_data);
68#endif
69#ifdef SIGHUP
70static void async_disconnect (gdb_client_data);
71#endif
72#ifdef SIGTSTP
73static void async_sigtstp_handler (gdb_client_data);
74#endif
75static void async_sigterm_handler (gdb_client_data arg);
76
77/* Instead of invoking (and waiting for) readline to read the command
78 line and pass it back for processing, we use readline's alternate
79 interface, via callback functions, so that the event loop can react
80 to other event sources while we wait for input. */
81
82/* Important variables for the event loop. */
83
84/* This is used to determine if GDB is using the readline library or
85 its own simplified form of readline. It is used by the asynchronous
86 form of the set editing command.
87 ezannoni: as of 1999-04-29 I expect that this
88 variable will not be used after gdb is changed to use the event
89 loop as default engine, and event-top.c is merged into top.c. */
91
92/* This is used to display the notification of the completion of an
93 asynchronous execution command. */
95
96/* Used by the stdin event handler to compensate for missed stdin events.
97 Setting this to a non-zero value inside an stdin callback makes the callback
98 run again. */
100
101/* When true GDB will produce a minimal backtrace when a fatal signal is
102 reached (within GDB code). */
104
105/* Implement 'maintenance show backtrace-on-fatal-signal'. */
106
107static void
108show_bt_on_fatal_signal (struct ui_file *file, int from_tty,
109 struct cmd_list_element *cmd, const char *value)
110{
111 gdb_printf (file, _("Backtrace on a fatal signal is %s.\n"), value);
112}
113
114/* Signal handling variables. */
115/* Each of these is a pointer to a function that the event loop will
116 invoke if the corresponding signal has received. The real signal
117 handlers mark these functions as ready to be executed and the event
118 loop, in a later iteration, calls them. See the function
119 invoke_async_signal_handler. */
121#ifdef SIGHUP
122static struct async_signal_handler *sighup_token;
123#endif
124#ifdef SIGQUIT
125static struct async_signal_handler *sigquit_token;
126#endif
127#ifdef SIGTSTP
128static struct async_signal_handler *sigtstp_token;
129#endif
131
132/* This hook is called by gdb_rl_callback_read_char_wrapper after each
133 character is processed. */
135
136
137/* Wrapper function for calling into the readline library. This takes
138 care of a couple things:
139
140 - The event loop expects the callback function to have a parameter,
141 while readline expects none.
142
143 - Propagation of GDB exceptions/errors thrown from INPUT_HANDLER
144 across readline requires special handling.
145
146 On the exceptions issue:
147
148 DWARF-based unwinding cannot cross code built without -fexceptions.
149 Any exception that tries to propagate through such code will fail
150 and the result is a call to std::terminate. While some ABIs, such
151 as x86-64, require all code to be built with exception tables,
152 others don't.
153
154 This is a problem when GDB calls some non-EH-aware C library code,
155 that calls into GDB again through a callback, and that GDB callback
156 code throws a C++ exception. Turns out this is exactly what
157 happens with GDB's readline callback.
158
159 In such cases, we must catch and save any C++ exception that might
160 be thrown from the GDB callback before returning to the
161 non-EH-aware code. When the non-EH-aware function itself returns
162 back to GDB, we then rethrow the original C++ exception.
163
164 In the readline case however, the right thing to do is to longjmp
165 out of the callback, rather than do a normal return -- there's no
166 way for the callback to return to readline an indication that an
167 error happened, so a normal return would have rl_callback_read_char
168 potentially continue processing further input, redisplay the
169 prompt, etc. Instead of raw setjmp/longjmp however, we use our
170 sjlj-based TRY/CATCH mechanism, which knows to handle multiple
171 levels of active setjmp/longjmp frames, needed in order to handle
172 the readline callback recursing, as happens with e.g., secondary
173 prompts / queries, through gdb_readline_wrapper. This must be
174 noexcept in order to avoid problems with mixing sjlj and
175 (sjlj-based) C++ exceptions. */
176
177static struct gdb_exception
179{
180 struct gdb_exception gdb_expt;
181
182 /* C++ exceptions can't normally be thrown across readline (unless
183 it is built with -fexceptions, but it won't by default on many
184 ABIs). So we instead wrap the readline call with a sjlj-based
185 TRY/CATCH, and rethrow the GDB exception once back in GDB. */
186 TRY_SJLJ
187 {
188 rl_callback_read_char ();
189#if RL_VERSION_MAJOR >= 8
190 /* It can happen that readline (while in rl_callback_read_char)
191 received a signal, but didn't handle it yet. Make sure it's handled
192 now. If we don't do that we run into two related problems:
193 - we have to wait for another event triggering
194 rl_callback_read_char before the signal is handled
195 - there's no guarantee that the signal will be processed before the
196 event. */
197 while (rl_pending_signal () != 0)
198 /* Do this in a while loop, in case rl_check_signals also leaves a
199 pending signal. I'm not sure if that's possible, but it seems
200 better to handle the scenario than to assert. */
201 rl_check_signals ();
202#else
203 /* Unfortunately, rl_check_signals is not available. */
204#endif
206 (*after_char_processing_hook) ();
207 }
208 CATCH_SJLJ (ex, RETURN_MASK_ALL)
209 {
210 gdb_expt = std::move (ex);
211 }
212 END_CATCH_SJLJ
213
214 return gdb_expt;
215}
216
217static void
218gdb_rl_callback_read_char_wrapper (gdb_client_data client_data)
219{
220 struct gdb_exception gdb_expt
222
223 /* Rethrow using the normal EH mechanism. */
224 if (gdb_expt.reason < 0)
225 throw_exception (std::move (gdb_expt));
226}
227
228/* GDB's readline callback handler. Calls the current INPUT_HANDLER,
229 and propagates GDB exceptions/errors thrown from INPUT_HANDLER back
230 across readline. See gdb_rl_callback_read_char_wrapper. This must
231 be noexcept in order to avoid problems with mixing sjlj and
232 (sjlj-based) C++ exceptions. */
233
234static void
235gdb_rl_callback_handler (char *rl) noexcept
236{
237 /* This is static to avoid undefined behavior when calling longjmp
238 -- gdb_exception has a destructor with side effects. */
239 static struct gdb_exception gdb_rl_expt;
240 struct ui *ui = current_ui;
241
242 try
243 {
244 /* Ensure the exception is reset on each call. */
245 gdb_rl_expt = {};
246 ui->input_handler (gdb::unique_xmalloc_ptr<char> (rl));
247 }
248 catch (gdb_exception &ex)
249 {
250 gdb_rl_expt = std::move (ex);
251 }
252
253 /* If we caught a GDB exception, longjmp out of the readline
254 callback. There's no other way for the callback to signal to
255 readline that an error happened. A normal return would have
256 readline potentially continue processing further input, redisplay
257 the prompt, etc. (This is what GDB historically did when it was
258 a C program.) Note that since we're long jumping, local variable
259 dtors are NOT run automatically. */
260 if (gdb_rl_expt.reason < 0)
261 throw_exception_sjlj (gdb_rl_expt);
262}
263
264/* Change the function to be invoked every time there is a character
265 ready on stdin. This is used when the user sets the editing off,
266 therefore bypassing readline, and letting gdb handle the input
267 itself, via gdb_readline_no_editing_callback. Also it is used in
268 the opposite case in which the user sets editing on again, by
269 restoring readline handling of the input.
270
271 NOTE: this operates on input_fd, not instream. If we are reading
272 commands from a file, instream will point to the file. However, we
273 always read commands from a file with editing off. This means that
274 the 'set editing on/off' will have effect only on the interactive
275 session. */
276
277void
279{
280 struct ui *ui = current_ui;
281
282 /* We can only have one instance of readline, so we only allow
283 editing on the main UI. */
284 if (ui != main_ui)
285 return;
286
287 /* Don't try enabling editing if the interpreter doesn't support it
288 (e.g., MI). */
291 return;
292
293 if (editing)
294 {
295 gdb_assert (ui == main_ui);
296
297 /* Turn on editing by using readline. */
299 }
300 else
301 {
302 /* Turn off editing by using gdb_readline_no_editing_callback. */
303 if (ui->command_editing)
306 }
307 ui->command_editing = editing;
308}
309
310/* The functions below are wrappers for rl_callback_handler_remove and
311 rl_callback_handler_install that keep track of whether the callback
312 handler is installed in readline. This is necessary because after
313 handling a target event of a background execution command, we may
314 need to reinstall the callback handler if it was removed due to a
315 secondary prompt. See gdb_readline_wrapper_line. We don't
316 unconditionally install the handler for every target event because
317 that also clears the line buffer, thus installing it while the user
318 is typing would lose input. */
319
320/* Whether we've registered a callback handler with readline. */
322
323/* See event-top.h, and above. */
324
325void
327{
328 gdb_assert (current_ui == main_ui);
329
330 rl_callback_handler_remove ();
332}
333
334/* See event-top.h, and above. Note this wrapper doesn't have an
335 actual callback parameter because we always install
336 INPUT_HANDLER. */
337
338void
340{
341 gdb_assert (current_ui == main_ui);
342
343 /* Calling rl_callback_handler_install resets readline's input
344 buffer. Calling this when we were already processing input
345 therefore loses input. */
346 gdb_assert (!callback_handler_installed);
347
348 rl_callback_handler_install (prompt, gdb_rl_callback_handler);
350}
351
352/* See event-top.h, and above. */
353
354void
356{
357 gdb_assert (current_ui == main_ui);
358
360 {
361 /* Passing NULL as prompt argument tells readline to not display
362 a prompt. */
364 }
365}
366
367/* Displays the prompt. If the argument NEW_PROMPT is NULL, the
368 prompt that is displayed is the current top level prompt.
369 Otherwise, it displays whatever NEW_PROMPT is as a local/secondary
370 prompt.
371
372 This is used after each gdb command has completed, and in the
373 following cases:
374
375 1. When the user enters a command line which is ended by '\'
376 indicating that the command will continue on the next line. In
377 that case the prompt that is displayed is the empty string.
378
379 2. When the user is entering 'commands' for a breakpoint, or
380 actions for a tracepoint. In this case the prompt will be '>'
381
382 3. On prompting for pagination. */
383
384void
385display_gdb_prompt (const char *new_prompt)
386{
387 std::string actual_gdb_prompt;
388
390
391 /* Reset the nesting depth used when trace-commands is set. */
393
394 /* Do not call the python hook on an explicit prompt change as
395 passed to this function, as this forms a secondary/local prompt,
396 IE, displayed but not set. */
397 if (! new_prompt)
398 {
399 struct ui *ui = current_ui;
400
401 if (ui->prompt_state == PROMPTED)
402 internal_error (_("double prompt"));
403 else if (ui->prompt_state == PROMPT_BLOCKED)
404 {
405 /* This is to trick readline into not trying to display the
406 prompt. Even though we display the prompt using this
407 function, readline still tries to do its own display if
408 we don't call rl_callback_handler_install and
409 rl_callback_handler_remove (which readline detects
410 because a global variable is not set). If readline did
411 that, it could mess up gdb signal handlers for SIGINT.
412 Readline assumes that between calls to rl_set_signals and
413 rl_clear_signals gdb doesn't do anything with the signal
414 handlers. Well, that's not the case, because when the
415 target executes we change the SIGINT signal handler. If
416 we allowed readline to display the prompt, the signal
417 handler change would happen exactly between the calls to
418 the above two functions. Calling
419 rl_callback_handler_remove(), does the job. */
420
423 return;
424 }
425 else if (ui->prompt_state == PROMPT_NEEDED)
426 {
427 /* Display the top level prompt. */
428 actual_gdb_prompt = top_level_prompt ();
430 }
431 }
432 else
433 actual_gdb_prompt = new_prompt;
434
436 {
438 gdb_rl_callback_handler_install (actual_gdb_prompt.c_str ());
439 }
440 /* new_prompt at this point can be the top of the stack or the one
441 passed in. It can't be NULL. */
442 else
443 {
444 /* Don't use a _filtered function here. It causes the assumed
445 character position to be off, since the newline we read from
446 the user is not accounted for. */
447 printf_unfiltered ("%s", actual_gdb_prompt.c_str ());
449 }
450}
451
452/* Return the top level prompt, as specified by "set prompt", possibly
453 overridden by the python gdb.prompt_hook hook, and then composed
454 with the prompt prefix and suffix (annotations). */
455
456static std::string
458{
459 /* Give observers a chance of changing the prompt. E.g., the python
460 `gdb.prompt_hook' is installed as an observer. */
461 gdb::observers::before_prompt.notify (get_prompt ().c_str ());
462
463 const std::string &prompt = get_prompt ();
464
465 if (annotation_level >= 2)
466 {
467 /* Prefix needs to have new line at end. */
468 const char prefix[] = "\n\032\032pre-prompt\n";
469
470 /* Suffix needs to have a new line at end and \032 \032 at
471 beginning. */
472 const char suffix[] = "\n\032\032prompt\n";
473
474 return std::string (prefix) + prompt.c_str () + suffix;
475 }
476
477 return prompt;
478}
479
480/* See top.h. */
481
482struct ui *main_ui;
484struct ui *ui_list;
485
486/* Get a reference to the current UI's line buffer. This is used to
487 construct a whole line of input from partial input. */
488
489static std::string &
491{
492 return current_ui->line_buffer;
493}
494
495/* When there is an event ready on the stdin file descriptor, instead
496 of calling readline directly throught the callback function, or
497 instead of calling gdb_readline_no_editing_callback, give gdb a
498 chance to detect errors and do something. */
499
500static void
501stdin_event_handler (int error, gdb_client_data client_data)
502{
503 struct ui *ui = (struct ui *) client_data;
504
505 if (error)
506 {
507 /* Switch to the main UI, so diagnostics always go there. */
509
511 if (main_ui == ui)
512 {
513 /* If stdin died, we may as well kill gdb. */
514 gdb_printf (gdb_stderr, _("error detected on stdin\n"));
515 quit_command ((char *) 0, 0);
516 }
517 else
518 {
519 /* Simply delete the UI. */
520 delete ui;
521 }
522 }
523 else
524 {
525 /* Switch to the UI whose input descriptor woke up the event
526 loop. */
527 current_ui = ui;
528
529 /* This makes sure a ^C immediately followed by further input is
530 always processed in that order. E.g,. with input like
531 "^Cprint 1\n", the SIGINT handler runs, marks the async
532 signal handler, and then select/poll may return with stdin
533 ready, instead of -1/EINTR. The
534 gdb.base/double-prompt-target-event-error.exp test exercises
535 this. */
536 QUIT;
537
538 do
539 {
541 ui->call_readline (client_data);
542 }
544 }
545}
546
547/* See top.h. */
548
549void
551{
552 if (input_fd != -1)
553 add_file_handler (input_fd, stdin_event_handler, this,
554 string_printf ("ui-%d", num), true);
555}
556
557/* See top.h. */
558
559void
561{
562 if (input_fd != -1)
563 delete_file_handler (input_fd);
564}
565
566/* Re-enable stdin after the end of an execution command in
567 synchronous mode, or after an error from the target, and we aborted
568 the exec operation. */
569
570void
572{
573 struct ui *ui = current_ui;
574
576 {
580 }
581}
582
583/* Disable reads from stdin (the console) marking the command as
584 synchronous. */
585
586void
588{
589 struct ui *ui = current_ui;
590
593}
594
595
596/* Handle a gdb command line. This function is called when
597 handle_line_of_input has concatenated one or more input lines into
598 a whole command. */
599
600void
601command_handler (const char *command)
602{
603 struct ui *ui = current_ui;
604 const char *c;
605
606 if (ui->instream == ui->stdin_stream)
608
609 scoped_command_stats stat_reporter (true);
610
611 /* Do not execute commented lines. */
612 for (c = command; *c == ' ' || *c == '\t'; c++)
613 ;
614 if (c[0] != '#')
615 {
616 execute_command (command, ui->instream == ui->stdin_stream);
617
618 /* Do any commands attached to breakpoint we stopped at. */
620 }
621}
622
623/* Append RL, an input line returned by readline or one of its emulations, to
624 CMD_LINE_BUFFER. Return true if we have a whole command line ready to be
625 processed by the command interpreter or false if the command line isn't
626 complete yet (input line ends in a backslash). */
627
628static bool
629command_line_append_input_line (std::string &cmd_line_buffer, const char *rl)
630{
631 size_t len = strlen (rl);
632
633 if (len > 0 && rl[len - 1] == '\\')
634 {
635 /* Don't copy the backslash and wait for more. */
636 cmd_line_buffer.append (rl, len - 1);
637 return false;
638 }
639 else
640 {
641 /* Copy whole line including terminating null, and we're
642 done. */
643 cmd_line_buffer.append (rl, len + 1);
644 return true;
645 }
646}
647
648/* Handle a line of input coming from readline.
649
650 If the read line ends with a continuation character (backslash), return
651 nullptr. Otherwise, return a pointer to the command line, indicating a whole
652 command line is ready to be executed.
653
654 The returned pointer may or may not point to CMD_LINE_BUFFER's internal
655 buffer.
656
657 Return EOF on end of file.
658
659 If REPEAT, handle command repetitions:
660
661 - If the input command line is NOT empty, the command returned is
662 saved using save_command_line () so that it can be repeated later.
663
664 - OTOH, if the input command line IS empty, return the saved
665 command instead of the empty input line.
666*/
667
668const char *
669handle_line_of_input (std::string &cmd_line_buffer,
670 const char *rl, int repeat,
671 const char *annotation_suffix)
672{
673 struct ui *ui = current_ui;
674 int from_tty = ui->instream == ui->stdin_stream;
675
676 if (rl == NULL)
677 return (char *) EOF;
678
679 bool complete = command_line_append_input_line (cmd_line_buffer, rl);
680 if (!complete)
681 return NULL;
682
683 if (from_tty && annotation_level > 1)
684 printf_unfiltered (("\n\032\032post-%s\n"), annotation_suffix);
685
686#define SERVER_COMMAND_PREFIX "server "
687 server_command = startswith (cmd_line_buffer.c_str (), SERVER_COMMAND_PREFIX);
688 if (server_command)
689 {
690 /* Note that we don't call `save_command_line'. Between this
691 and the check in dont_repeat, this insures that repeating
692 will still do the right thing. */
693 return cmd_line_buffer.c_str () + strlen (SERVER_COMMAND_PREFIX);
694 }
695
696 /* Do history expansion if that is wished. */
698 {
699 char *cmd_expansion;
700 int expanded;
701
702 /* Note: here, we pass a pointer to the std::string's internal buffer as
703 a `char *`. At the time of writing, readline's history_expand does
704 not modify the passed-in string. Ideally, readline should be modified
705 to make that parameter `const char *`. */
706 expanded = history_expand (&cmd_line_buffer[0], &cmd_expansion);
707 gdb::unique_xmalloc_ptr<char> history_value (cmd_expansion);
708 if (expanded)
709 {
710 /* Print the changes. */
711 printf_unfiltered ("%s\n", history_value.get ());
712
713 /* If there was an error, call this function again. */
714 if (expanded < 0)
715 return cmd_line_buffer.c_str ();
716
717 cmd_line_buffer = history_value.get ();
718 }
719 }
720
721 /* If we just got an empty line, and that is supposed to repeat the
722 previous command, return the previously saved command. */
723 const char *p1;
724 for (p1 = cmd_line_buffer.c_str (); *p1 == ' ' || *p1 == '\t'; p1++)
725 ;
726 if (repeat && *p1 == '\0')
727 return get_saved_command_line ();
728
729 /* Add command to history if appropriate. Note: lines consisting
730 solely of comments are also added to the command history. This
731 is useful when you type a command, and then realize you don't
732 want to execute it quite yet. You can comment out the command
733 and then later fetch it from the value history and remove the
734 '#'. The kill ring is probably better, but some people are in
735 the habit of commenting things out. */
736 if (cmd_line_buffer[0] != '\0' && from_tty && current_ui->input_interactive_p ())
737 gdb_add_history (cmd_line_buffer.c_str ());
738
739 /* Save into global buffer if appropriate. */
740 if (repeat)
741 {
742 save_command_line (cmd_line_buffer.c_str ());
743
744 /* It is important that we return a pointer to the saved command line
745 here, for the `cmd_start == saved_command_line` check in
746 execute_command to work. */
747 return get_saved_command_line ();
748 }
749
750 return cmd_line_buffer.c_str ();
751}
752
753/* See event-top.h. */
754
755void
757{
758#ifdef RL_STATE_EOF
759 gdb::optional<scoped_restore_tmpl<int>> restore_eof_found;
760
761 if (RL_ISSTATE (RL_STATE_EOF))
762 {
763 printf_unfiltered ("quit\n");
764 restore_eof_found.emplace (&rl_eof_found, 0);
765 }
766
767#endif /* RL_STATE_EOF */
768
769 rl_deprep_terminal ();
770}
771
772/* Handle a complete line of input. This is called by the callback
773 mechanism within the readline library. Deal with incomplete
774 commands as well, by saving the partial input in a global
775 buffer.
776
777 NOTE: This is the asynchronous version of the command_line_input
778 function. */
779
780void
781command_line_handler (gdb::unique_xmalloc_ptr<char> &&rl)
782{
783 std::string &line_buffer = get_command_line_buffer ();
784 struct ui *ui = current_ui;
785
786 const char *cmd = handle_line_of_input (line_buffer, rl.get (), 1, "prompt");
787 if (cmd == (char *) EOF)
788 {
789 /* stdin closed. The connection with the terminal is gone.
790 This happens at the end of a testsuite run, after Expect has
791 hung up but GDB is still alive. In such a case, we just quit
792 gdb killing the inferior program too. This also happens if the
793 user sends EOF, which is usually bound to ctrl+d. */
794
795#ifndef RL_STATE_EOF
796 /* When readline is using bracketed paste mode, then, when eof is
797 received, readline will emit the control sequence to leave
798 bracketed paste mode.
799
800 This control sequence ends with \r, which means that the "quit" we
801 are about to print will overwrite the prompt on this line.
802
803 The solution to this problem is to actually print the "quit"
804 message from gdb_rl_deprep_term_function (see above), however, we
805 can only do that if we can know, in that function, when eof was
806 received.
807
808 Unfortunately, with older versions of readline, it is not possible
809 in the gdb_rl_deprep_term_function to know if eof was received or
810 not, and, as GDB can be built against the system readline, which
811 could be older than the readline in GDB's repository, then we
812 can't be sure that we can work around this prompt corruption in
813 the gdb_rl_deprep_term_function function.
814
815 If we get here, RL_STATE_EOF is not defined. This indicates that
816 we are using an older readline, and couldn't print the quit
817 message in gdb_rl_deprep_term_function. So, what we do here is
818 check to see if bracketed paste mode is on or not. If it's on
819 then we print a \n and then the quit, this means the user will
820 see:
821
822 (gdb)
823 quit
824
825 Rather than the usual:
826
827 (gdb) quit
828
829 Which we will get with a newer readline, but this really is the
830 best we can do with older versions of readline. */
831 const char *value = rl_variable_value ("enable-bracketed-paste");
832 if (value != nullptr && strcmp (value, "on") == 0
833 && ((rl_readline_version >> 8) & 0xff) > 0x07)
834 printf_unfiltered ("\n");
835 printf_unfiltered ("quit\n");
836#endif
837
838 execute_command ("quit", 1);
839 }
840 else if (cmd == NULL)
841 {
842 /* We don't have a full line yet. Print an empty prompt. */
844 }
845 else
846 {
848
849 /* Ensure the UI's line buffer is empty for the next command. */
850 SCOPE_EXIT { line_buffer.clear (); };
851
852 command_handler (cmd);
853
854 if (ui->prompt_state != PROMPTED)
856 }
857}
858
859/* Does reading of input from terminal w/o the editing features
860 provided by the readline library. Calls the line input handler
861 once we have a whole input line. */
862
863void
864gdb_readline_no_editing_callback (gdb_client_data client_data)
865{
866 int c;
867 char *result;
868 struct buffer line_buffer;
869 struct ui *ui = current_ui;
870
871 buffer_init (&line_buffer);
872
873 FILE *stream = ui->instream != nullptr ? ui->instream : ui->stdin_stream;
874 gdb_assert (stream != nullptr);
875
876 /* We still need the while loop here, even though it would seem
877 obvious to invoke gdb_readline_no_editing_callback at every
878 character entered. If not using the readline library, the
879 terminal is in cooked mode, which sends the characters all at
880 once. Poll will notice that the input fd has changed state only
881 after enter is pressed. At this point we still need to fetch all
882 the chars entered. */
883
884 while (1)
885 {
886 /* Read from stdin if we are executing a user defined command.
887 This is the right thing for prompt_for_continue, at least. */
888 c = fgetc (stream);
889
890 if (c == EOF)
891 {
892 if (line_buffer.used_size > 0)
893 {
894 /* The last line does not end with a newline. Return it, and
895 if we are called again fgetc will still return EOF and
896 we'll return NULL then. */
897 break;
898 }
899 xfree (buffer_finish (&line_buffer));
900 ui->input_handler (NULL);
901 return;
902 }
903
904 if (c == '\n')
905 {
906 if (line_buffer.used_size > 0
907 && line_buffer.buffer[line_buffer.used_size - 1] == '\r')
908 line_buffer.used_size--;
909 break;
910 }
911
912 buffer_grow_char (&line_buffer, c);
913 }
914
915 buffer_grow_char (&line_buffer, '\0');
916 result = buffer_finish (&line_buffer);
917 ui->input_handler (gdb::unique_xmalloc_ptr<char> (result));
918}
919
920
921/* Attempt to unblock signal SIG, return true if the signal was unblocked,
922 otherwise, return false. */
923
924static bool
926{
927#if HAVE_SIGPROCMASK
928 sigset_t sigset;
929 sigemptyset (&sigset);
930 sigaddset (&sigset, sig);
931 gdb_sigmask (SIG_UNBLOCK, &sigset, 0);
932 return true;
933#endif
934
935 return false;
936}
937
938/* Called to handle fatal signals. SIG is the signal number. */
939
940static void ATTRIBUTE_NORETURN
942{
943#ifdef GDB_PRINT_INTERNAL_BACKTRACE
944 const auto sig_write = [] (const char *msg) -> void
945 {
946 gdb_stderr->write_async_safe (msg, strlen (msg));
947 };
948
950 {
951 sig_write ("\n\n");
952 sig_write (_("Fatal signal: "));
953 sig_write (strsignal (sig));
954 sig_write ("\n");
955
957
958 sig_write (_("A fatal error internal to GDB has been detected, "
959 "further\ndebugging is not possible. GDB will now "
960 "terminate.\n\n"));
961 sig_write (_("This is a bug, please report it."));
962 if (REPORT_BUGS_TO[0] != '\0')
963 {
964 sig_write (_(" For instructions, see:\n"));
965 sig_write (REPORT_BUGS_TO);
966 sig_write (".");
967 }
968 sig_write ("\n\n");
969
970 gdb_stderr->flush ();
971 }
972#endif
973
974 /* If possible arrange for SIG to have its default behaviour (which
975 should be to terminate the current process), unblock SIG, and reraise
976 the signal. This ensures GDB terminates with the expected signal. */
977 if (signal (sig, SIG_DFL) != SIG_ERR
978 && unblock_signal (sig))
979 raise (sig);
980
981 /* The above failed, so try to use SIGABRT to terminate GDB. */
982#ifdef SIGABRT
983 signal (SIGABRT, SIG_DFL);
984#endif
985 abort (); /* ARI: abort */
986}
987
988/* The SIGSEGV handler for this thread, or NULL if there is none. GDB
989 always installs a global SIGSEGV handler, and then lets threads
990 indicate their interest in handling the signal by setting this
991 thread-local variable.
992
993 This is a static variable instead of extern because on various platforms
994 (notably Cygwin) extern thread_local variables cause link errors. So
995 instead, we have scoped_segv_handler_restore, which also makes it impossible
996 to accidentally forget to restore it to the original value. */
997
998static thread_local void (*thread_local_segv_handler) (int);
999
1000static void handle_sigsegv (int sig);
1001
1002/* Install the SIGSEGV handler. */
1003static void
1005{
1006#if defined (HAVE_SIGACTION)
1007 struct sigaction sa;
1008 sa.sa_handler = handle_sigsegv;
1009 sigemptyset (&sa.sa_mask);
1010#ifdef HAVE_SIGALTSTACK
1011 sa.sa_flags = SA_ONSTACK;
1012#else
1013 sa.sa_flags = 0;
1014#endif
1015 sigaction (SIGSEGV, &sa, nullptr);
1016#else
1017 signal (SIGSEGV, handle_sigsegv);
1018#endif
1019}
1020
1021/* Handler for SIGSEGV. */
1022
1023static void
1025{
1027
1028 if (thread_local_segv_handler == nullptr)
1029 handle_fatal_signal (sig);
1031}
1032
1033
1034
1035/* The serial event associated with the QUIT flag. set_quit_flag sets
1036 this, and check_quit_flag clears it. Used by interruptible_select
1037 to be able to do interruptible I/O with no race with the SIGINT
1038 handler. */
1039static struct serial_event *quit_serial_event;
1040
1041/* Initialization of signal handlers and tokens. There are a number of
1042 different strategies for handling different signals here.
1043
1044 For SIGINT, SIGTERM, SIGQUIT, SIGHUP, SIGTSTP, there is a function
1045 handle_sig* for each of these signals. These functions are the actual
1046 signal handlers associated to the signals via calls to signal(). The
1047 only job for these functions is to enqueue the appropriate
1048 event/procedure with the event loop. The event loop will take care of
1049 invoking the queued procedures to perform the usual tasks associated
1050 with the reception of the signal.
1051
1052 For SIGSEGV the handle_sig* function does all the work for handling this
1053 signal.
1054
1055 For SIGFPE, SIGBUS, and SIGABRT, these signals will all cause GDB to
1056 terminate immediately. */
1057void
1059{
1061
1063
1064 sigint_token =
1067
1070 signal (SIGTERM, handle_sigterm);
1071
1072#ifdef SIGQUIT
1073 sigquit_token =
1074 create_async_signal_handler (async_do_nothing, NULL, "sigquit");
1075 signal (SIGQUIT, handle_sigquit);
1076#endif
1077
1078#ifdef SIGHUP
1079 if (signal (SIGHUP, handle_sighup) != SIG_IGN)
1080 sighup_token =
1081 create_async_signal_handler (async_disconnect, NULL, "sighup");
1082 else
1083 sighup_token =
1084 create_async_signal_handler (async_do_nothing, NULL, "sighup");
1085#endif
1086
1087#ifdef SIGTSTP
1088 sigtstp_token =
1089 create_async_signal_handler (async_sigtstp_handler, NULL, "sigtstp");
1090#endif
1091
1092#ifdef SIGFPE
1093 signal (SIGFPE, handle_fatal_signal);
1094#endif
1095
1096#ifdef SIGBUS
1097 signal (SIGBUS, handle_fatal_signal);
1098#endif
1099
1100#ifdef SIGABRT
1101 signal (SIGABRT, handle_fatal_signal);
1102#endif
1103
1105}
1106
1107/* See defs.h. */
1108
1109void
1111{
1113}
1114
1115/* See defs.h. */
1116
1117void
1119{
1121}
1122
1123/* Return the selectable file descriptor of the serial event
1124 associated with the quit flag. */
1125
1126static int
1128{
1130}
1131
1132/* See defs.h. */
1133
1134void
1136{
1137 if (check_quit_flag ())
1138 {
1140 quit ();
1141 else
1143 }
1144}
1145
1146/* See defs.h. */
1148
1149/* Handle a SIGINT. */
1150
1151void
1153{
1154 signal (sig, handle_sigint);
1155
1156 /* We could be running in a loop reading in symfiles or something so
1157 it may be quite a while before we get back to the event loop. So
1158 set quit_flag to 1 here. Then if QUIT is called before we get to
1159 the event loop, we will unwind as expected. */
1160 set_quit_flag ();
1161
1162 /* In case nothing calls QUIT before the event loop is reached, the
1163 event loop handles it. */
1165}
1166
1167/* See gdb_select.h. */
1168
1169int
1171 fd_set *readfds, fd_set *writefds, fd_set *exceptfds,
1172 struct timeval *timeout)
1173{
1174 fd_set my_readfds;
1175 int fd;
1176 int res;
1177
1178 if (readfds == NULL)
1179 {
1180 readfds = &my_readfds;
1181 FD_ZERO (&my_readfds);
1182 }
1183
1184 fd = quit_serial_event_fd ();
1185 FD_SET (fd, readfds);
1186 if (n <= fd)
1187 n = fd + 1;
1188
1189 do
1190 {
1191 res = gdb_select (n, readfds, writefds, exceptfds, timeout);
1192 }
1193 while (res == -1 && errno == EINTR);
1194
1195 if (res == 1 && FD_ISSET (fd, readfds))
1196 {
1197 errno = EINTR;
1198 return -1;
1199 }
1200 return res;
1201}
1202
1203/* Handle GDB exit upon receiving SIGTERM if target_can_async_p (). */
1204
1205static void
1206async_sigterm_handler (gdb_client_data arg)
1207{
1208 quit_force (NULL, 0);
1209}
1210
1211/* See defs.h. */
1213
1214/* Quit GDB if SIGTERM is received.
1215 GDB would quit anyway, but this way it will clean up properly. */
1216void
1218{
1219 signal (sig, handle_sigterm);
1220
1222 set_quit_flag ();
1223
1225}
1226
1227/* Do the quit. All the checks have been done by the caller. */
1228void
1229async_request_quit (gdb_client_data arg)
1230{
1231 /* If the quit_flag has gotten reset back to 0 by the time we get
1232 back here, that means that an exception was thrown to unwind the
1233 current command before we got back to the event loop. So there
1234 is no reason to call quit again here. */
1235 QUIT;
1236}
1237
1238#ifdef SIGQUIT
1239/* Tell the event loop what to do if SIGQUIT is received.
1240 See event-signal.c. */
1241static void
1242handle_sigquit (int sig)
1243{
1244 mark_async_signal_handler (sigquit_token);
1245 signal (sig, handle_sigquit);
1246}
1247#endif
1248
1249#if defined (SIGQUIT) || defined (SIGHUP)
1250/* Called by the event loop in response to a SIGQUIT or an
1251 ignored SIGHUP. */
1252static void
1253async_do_nothing (gdb_client_data arg)
1254{
1255 /* Empty function body. */
1256}
1257#endif
1258
1259#ifdef SIGHUP
1260/* Tell the event loop what to do if SIGHUP is received.
1261 See event-signal.c. */
1262static void
1263handle_sighup (int sig)
1264{
1265 mark_async_signal_handler (sighup_token);
1266 signal (sig, handle_sighup);
1267}
1268
1269/* Called by the event loop to process a SIGHUP. */
1270static void
1271async_disconnect (gdb_client_data arg)
1272{
1273
1274 try
1275 {
1276 quit_cover ();
1277 }
1278
1279 catch (const gdb_exception &exception)
1280 {
1281 gdb_puts ("Could not kill the program being debugged",
1282 gdb_stderr);
1283 exception_print (gdb_stderr, exception);
1284 }
1285
1286 for (inferior *inf : all_inferiors ())
1287 {
1288 try
1289 {
1290 inf->pop_all_targets ();
1291 }
1292 catch (const gdb_exception &exception)
1293 {
1294 }
1295 }
1296
1297 signal (SIGHUP, SIG_DFL); /*FIXME: ??????????? */
1298 raise (SIGHUP);
1299}
1300#endif
1301
1302#ifdef SIGTSTP
1303void
1304handle_sigtstp (int sig)
1305{
1306 mark_async_signal_handler (sigtstp_token);
1307 signal (sig, handle_sigtstp);
1308}
1309
1310static void
1311async_sigtstp_handler (gdb_client_data arg)
1312{
1313 const std::string &prompt = get_prompt ();
1314
1315 signal (SIGTSTP, SIG_DFL);
1316 unblock_signal (SIGTSTP);
1317 raise (SIGTSTP);
1318 signal (SIGTSTP, handle_sigtstp);
1319 printf_unfiltered ("%s", prompt.c_str ());
1321
1322 /* Forget about any previous command -- null line now will do
1323 nothing. */
1324 dont_repeat ();
1325}
1326#endif /* SIGTSTP */
1327
1328
1329
1330/* Set things up for readline to be invoked via the alternate
1331 interface, i.e. via a callback function
1332 (gdb_rl_callback_read_char), and hook up instream to the event
1333 loop. */
1334
1335void
1337{
1338 struct ui *ui = current_ui;
1339
1340 /* If the input stream is connected to a terminal, turn on editing.
1341 However, that is only allowed on the main UI, as we can only have
1342 one instance of readline. Also, INSTREAM might be nullptr when
1343 executing a user-defined command. */
1344 if (ui->instream != nullptr && ISATTY (ui->instream)
1345 && editing && ui == main_ui)
1346 {
1347 /* Tell gdb that we will be using the readline library. This
1348 could be overwritten by a command in .gdbinit like 'set
1349 editing on' or 'off'. */
1350 ui->command_editing = 1;
1351
1352 /* When a character is detected on instream by select or poll,
1353 readline will be invoked via this callback function. */
1355
1356 /* Tell readline to use the same input stream that gdb uses. */
1357 rl_instream = ui->instream;
1358 }
1359 else
1360 {
1361 ui->command_editing = 0;
1363 }
1364
1365 /* Now create the event source for this UI's input file descriptor.
1366 Another source is going to be the target program (inferior), but
1367 that must be registered only when it actually exists (I.e. after
1368 we say 'run' or after we connect to a remote target. */
1370}
1371
1372/* Disable command input through the standard CLI channels. Used in
1373 the suspend proc for interpreters that use the standard gdb readline
1374 interface, like the cli & the mi. */
1375
1376void
1378{
1379 struct ui *ui = current_ui;
1380
1381 if (ui->command_editing)
1384}
1385
1387{
1389 thread_local_segv_handler = new_handler;
1390}
1391
1393{
1395}
1396
1397static const char debug_event_loop_off[] = "off";
1398static const char debug_event_loop_all_except_ui[] = "all-except-ui";
1399static const char debug_event_loop_all[] = "all";
1400
1401static const char *debug_event_loop_enum[] = {
1405 nullptr
1406};
1407
1409
1410static void
1411set_debug_event_loop_command (const char *args, int from_tty,
1413{
1415 debug_event_loop = debug_event_loop_kind::OFF;
1417 debug_event_loop = debug_event_loop_kind::ALL_EXCEPT_UI;
1419 debug_event_loop = debug_event_loop_kind::ALL;
1420 else
1421 gdb_assert_not_reached ("Invalid debug event look kind value.");
1422}
1423
1424static void
1425show_debug_event_loop_command (struct ui_file *file, int from_tty,
1426 struct cmd_list_element *cmd, const char *value)
1427{
1428 gdb_printf (file, _("Event loop debugging is %s.\n"), value);
1429}
1430
1431void _initialize_event_top ();
1432void
1434{
1438 _("Set event-loop debugging."),
1439 _("Show event-loop debugging."),
1440 _("\
1441Control whether to show event loop-related debug messages."),
1445
1446 add_setshow_boolean_cmd ("backtrace-on-fatal-signal", class_maintenance,
1447 &bt_on_fatal_signal, _("\
1448Set whether to produce a backtrace if GDB receives a fatal signal."), _("\
1449Show whether GDB will produce a backtrace if it receives a fatal signal."), _("\
1450Use \"on\" to enable, \"off\" to disable.\n\
1451If enabled, GDB will produce a minimal backtrace if it encounters a fatal\n\
1452signal from within GDB itself. This is a mechanism to help diagnose\n\
1453crashes within GDB, not a mechanism for debugging inferiors."),
1458}
void xfree(void *)
void annotate_display_prompt(void)
Definition annotate.c:611
async_signal_handler * create_async_signal_handler(sig_handler_func *proc, gdb_client_data client_data, const char *name)
void initialize_async_signal_handlers(void)
void mark_async_signal_handler(async_signal_handler *async_handler_ptr)
void bpstat_do_actions(void)
void gdb_internal_backtrace_set_cmd(const char *args, int from_tty, cmd_list_element *c)
Definition bt-utils.c:28
void gdb_internal_backtrace()
Definition bt-utils.c:154
#define GDB_PRINT_INTERNAL_BACKTRACE_INIT_ON
Definition bt-utils.h:51
segv_handler_t m_old_handler
Definition event-top.h:90
scoped_segv_handler_restore(segv_handler_t new_handler)
Definition event-top.c:1386
static bool is_ours()
Definition target.h:189
static void ours()
Definition target.c:1065
struct cmd_list_element * showdebuglist
Definition cli-cmds.c:165
struct cmd_list_element * setdebuglist
Definition cli-cmds.c:163
void quit_command(const char *args, int from_tty)
Definition cli-cmds.c:475
struct cmd_list_element * maintenance_show_cmdlist
Definition maint.c:752
struct cmd_list_element * maintenance_set_cmdlist
Definition maint.c:751
set_show_commands add_setshow_enum_cmd(const char *name, enum command_class theclass, const char *const *enumlist, const char **var, const char *set_doc, const char *show_doc, const char *help_doc, cmd_func_ftype *set_func, show_value_ftype *show_func, struct cmd_list_element **set_list, struct cmd_list_element **show_list)
Definition cli-decode.c:618
set_show_commands add_setshow_boolean_cmd(const char *name, enum command_class theclass, bool *var, const char *set_doc, const char *show_doc, const char *help_doc, cmd_func_ftype *set_func, show_value_ftype *show_func, struct cmd_list_element **set_list, struct cmd_list_element **show_list)
Definition cli-decode.c:739
void reset_command_nest_depth(void)
Definition cli-script.c:467
void save_command_line(const char *cmd)
Definition top.c:864
void dont_repeat()
Definition top.c:809
char * get_saved_command_line()
Definition top.c:856
@ class_maintenance
Definition command.h:65
completion_result complete(const char *line, char const **word, int *quote_char)
Definition completer.c:1670
#define REPORT_BUGS_TO
Definition config.h:685
void quit(void)
Definition utils.c:671
int check_quit_flag(void)
Definition extension.c:805
void set_quit_flag(void)
Definition extension.c:781
#define ISATTY(FP)
Definition defs.h:616
int annotation_level
Definition stack.c:237
#define QUIT
Definition defs.h:186
void() quit_handler_ftype(void)
Definition defs.h:162
static const char * debug_event_loop_enum[]
Definition event-top.c:1401
void gdb_rl_deprep_term_function(void)
Definition event-top.c:756
bool set_editing_cmd_var
Definition event-top.c:90
static bool unblock_signal(int sig)
Definition event-top.c:925
static void show_bt_on_fatal_signal(struct ui_file *file, int from_tty, struct cmd_list_element *cmd, const char *value)
Definition event-top.c:108
void display_gdb_prompt(const char *new_prompt)
Definition event-top.c:385
struct ui * ui_list
Definition event-top.c:484
static void install_handle_sigsegv()
Definition event-top.c:1004
void gdb_setup_readline(int editing)
Definition event-top.c:1336
void async_enable_stdin(void)
Definition event-top.c:571
volatile int sync_quit_force_run
Definition event-top.c:1212
void _initialize_event_top()
Definition event-top.c:1433
void(* after_char_processing_hook)(void)
Definition event-top.c:134
void command_handler(const char *command)
Definition event-top.c:601
const char * handle_line_of_input(std::string &cmd_line_buffer, const char *rl, int repeat, const char *annotation_suffix)
Definition event-top.c:669
static void set_debug_event_loop_command(const char *args, int from_tty, cmd_list_element *c)
Definition event-top.c:1411
static bool bt_on_fatal_signal
Definition event-top.c:103
int call_stdin_event_handler_again_p
Definition event-top.c:99
bool exec_done_display_p
Definition event-top.c:94
quit_handler_ftype * quit_handler
Definition event-top.c:1147
static bool command_line_append_input_line(std::string &cmd_line_buffer, const char *rl)
Definition event-top.c:629
static struct async_signal_handler * sigint_token
Definition event-top.c:120
void gdb_rl_callback_handler_install(const char *prompt)
Definition event-top.c:339
static std::string & get_command_line_buffer(void)
Definition event-top.c:490
static struct async_signal_handler * async_sigterm_token
Definition event-top.c:130
void gdb_rl_callback_handler_remove(void)
Definition event-top.c:326
int interruptible_select(int n, fd_set *readfds, fd_set *writefds, fd_set *exceptfds, struct timeval *timeout)
Definition event-top.c:1170
struct ui * main_ui
Definition event-top.c:482
void gdb_init_signals(void)
Definition event-top.c:1058
void async_request_quit(gdb_client_data arg)
Definition event-top.c:1229
void gdb_disable_readline(void)
Definition event-top.c:1377
static void ATTRIBUTE_NORETURN handle_fatal_signal(int sig)
Definition event-top.c:941
static void stdin_event_handler(int error, gdb_client_data client_data)
Definition event-top.c:501
static struct gdb_exception gdb_rl_callback_read_char_wrapper_noexcept() noexcept
Definition event-top.c:178
void handle_sigint(int sig)
Definition event-top.c:1152
static const char debug_event_loop_all_except_ui[]
Definition event-top.c:1398
static thread_local void(* thread_local_segv_handler)(int)
Definition event-top.c:998
static const char * debug_event_loop_value
Definition event-top.c:1408
void handle_sigterm(int sig)
Definition event-top.c:1217
static int quit_serial_event_fd(void)
Definition event-top.c:1127
void command_line_handler(gdb::unique_xmalloc_ptr< char > &&rl)
Definition event-top.c:781
struct ui * current_ui
Definition event-top.c:483
void gdb_rl_callback_handler_reinstall(void)
Definition event-top.c:355
void default_quit_handler(void)
Definition event-top.c:1135
static bool callback_handler_installed
Definition event-top.c:321
static const char debug_event_loop_all[]
Definition event-top.c:1399
void quit_serial_event_clear(void)
Definition event-top.c:1118
static const char debug_event_loop_off[]
Definition event-top.c:1397
void async_disable_stdin(void)
Definition event-top.c:587
static void async_sigterm_handler(gdb_client_data arg)
Definition event-top.c:1206
static void gdb_rl_callback_handler(char *rl) noexcept
Definition event-top.c:235
static void show_debug_event_loop_command(struct ui_file *file, int from_tty, struct cmd_list_element *cmd, const char *value)
Definition event-top.c:1425
void quit_serial_event_set(void)
Definition event-top.c:1110
static struct serial_event * quit_serial_event
Definition event-top.c:1039
#define SERVER_COMMAND_PREFIX
static void gdb_rl_callback_read_char_wrapper(gdb_client_data client_data)
Definition event-top.c:218
static void handle_sigsegv(int sig)
Definition event-top.c:1024
void gdb_readline_no_editing_callback(gdb_client_data client_data)
Definition event-top.c:864
void change_line_handler(int editing)
Definition event-top.c:278
static std::string top_level_prompt()
Definition event-top.c:457
void(* segv_handler_t)(int)
Definition event-top.h:78
void exception_print(struct ui_file *file, const struct gdb_exception &e)
Definition exceptions.c:105
void execute_command(const char *, int)
Definition top.c:574
all_inferiors_range all_inferiors(process_stratum_target *proc_target=nullptr)
Definition inferior.h:758
c_c_handler_ftype * install_sigint_handler(c_c_handler_ftype *fn)
Definition mingw-hdep.c:425
struct interp * top_level_interpreter(void)
Definition interps.c:431
struct interp * command_interp(void)
Definition interps.c:304
int interp_supports_command_editing(struct interp *interp)
Definition interps.c:327
int gdb_select(int n, fd_set *readfds, fd_set *writefds, fd_set *exceptfds, struct timeval *timeout)
Definition mingw-hdep.c:51
observable< const char * > before_prompt
#define prefix(a, b, R, do)
Definition ppc64-tdep.c:52
void serial_event_set(struct serial_event *event)
Definition ser-event.c:180
void serial_event_clear(struct serial_event *event)
Definition ser-event.c:201
struct serial_event * make_serial_event(void)
Definition ser-event.c:162
int serial_event_fd(struct serial_event *event)
Definition ser-event.c:170
Definition gnu-nat.c:154
Definition top.h:56
int command_editing
Definition top.h:88
int num
Definition top.h:67
void(* input_handler)(gdb::unique_xmalloc_ptr< char > &&)
Definition top.h:83
enum prompt_state prompt_state
Definition top.h:131
bool input_interactive_p() const
Definition top.c:1918
int input_fd
Definition top.h:123
FILE * stdin_stream
Definition top.h:108
std::string line_buffer
Definition top.h:71
void unregister_file_handler()
Definition event-top.c:560
void(* call_readline)(gdb_client_data)
Definition top.h:79
void register_file_handler()
Definition event-top.c:550
FILE * instream
Definition top.h:114
Definition value.c:181
void target_pass_ctrlc(void)
Definition target.c:3805
void quit_force(int *exit_arg, int from_tty)
Definition top.c:1808
bool history_expansion_p
Definition top.c:961
bool server_command
Definition top.c:172
const std::string & get_prompt()
Definition top.c:1703
void gdb_add_history(const char *command)
Definition top.c:1233
void quit_cover(void)
@ PROMPT_BLOCKED
Definition top.h:36
@ PROMPTED
Definition top.h:43
@ PROMPT_NEEDED
Definition top.h:40
void reinitialize_more_filter(void)
Definition utils.c:1450
void gdb_printf(struct ui_file *stream, const char *format,...)
Definition utils.c:1865
void gdb_flush(struct ui_file *stream)
Definition utils.c:1477
void printf_unfiltered(const char *format,...)
Definition utils.c:1901
void gdb_puts(const char *linebuffer, struct ui_file *stream)
Definition utils.c:1788
#define gdb_stderr
Definition utils.h:193
#define gdb_stdout
Definition utils.h:188