1 /* MI Interpreter Definitions and Commands for GDB, the GNU debugger.
2 
3    Copyright (C) 2017-2024 Free Software Foundation, Inc.
4 
5    This file is part of GDB.
6 
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 3 of the License, or
10    (at your option) any later version.
11 
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.
16 
17    You should have received a copy of the GNU General Public License
18    along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
19 
20 #ifndef MI_MI_INTERP_H
21 #define MI_MI_INTERP_H
22 
23 #include "interps.h"
24 
25 struct mi_console_file;
26 
27 /* An MI interpreter.  */
28 
29 class mi_interp final : public interp
30 {
31 public:
mi_interp(const char * name)32   mi_interp (const char *name)
33     : interp (name)
34   {}
35 
36   void init (bool top_level) override;
37   void resume () override;
38   void suspend () override;
39   void exec (const char *command_str) override;
40   ui_out *interp_ui_out () override;
41   void set_logging (ui_file_up logfile, bool logging_redirect,
42                         bool debug_redirect) override;
43   void pre_command_loop () override;
44 
45   void on_signal_received (gdb_signal sig) override;
46   void on_signal_exited (gdb_signal sig) override;
47   void on_normal_stop (struct bpstat *bs, int print_frame) override;
48   void on_exited (int status) override;
49   void on_no_history () override;
50   void on_sync_execution_done () override;
51   void on_command_error () override;
52   void on_user_selected_context_changed (user_selected_what selection) override;
53   void on_new_thread (thread_info *t) override;
54   void on_thread_exited (thread_info *t, std::optional<ULONGEST> exit_code,
55                                int silent) override;
56   void on_inferior_added (inferior *inf) override;
57   void on_inferior_appeared (inferior *inf) override;
58   void on_inferior_disappeared (inferior *inf) override;
59   void on_inferior_removed (inferior *inf) override;
60   void on_record_changed (inferior *inf, int started, const char *method,
61                                 const char *format) override;
62   void on_target_resumed (ptid_t ptid) override;
63   void on_solib_loaded (const solib &so) override;
64   void on_solib_unloaded (const solib &so) override;
65   void on_about_to_proceed () override;
66   void on_traceframe_changed (int tfnum, int tpnum) override;
67   void on_tsv_created (const trace_state_variable *tsv) override;
68   void on_tsv_deleted (const trace_state_variable *tsv) override;
69   void on_tsv_modified (const trace_state_variable *tsv) override;
70   void on_breakpoint_created (breakpoint *b) override;
71   void on_breakpoint_deleted (breakpoint *b) override;
72   void on_breakpoint_modified (breakpoint *b) override;
73   void on_param_changed (const char *param, const char *value) override;
74   void on_memory_changed (inferior *inf, CORE_ADDR addr, ssize_t len,
75                                 const bfd_byte *data) override;
76 
77   /* MI's output channels */
78   mi_console_file *out;
79   mi_console_file *err;
80   mi_console_file *log;
81   mi_console_file *targ;
82   mi_console_file *event_channel;
83 
84   /* Raw console output.  */
85   struct ui_file *raw_stdout;
86 
87   /* Save the original value of raw_stdout here when logging, and the
88      file which we need to delete, so we can restore correctly when
89      done.  */
90   struct ui_file *saved_raw_stdout;
91   ui_file_up logfile_holder;
92   ui_file_up stdout_holder;
93 
94   /* MI's builder.  */
95   struct ui_out *mi_uiout;
96 
97   /* MI's CLI builder (wraps OUT).  */
98   struct ui_out *cli_uiout;
99 
100   int running_result_record_printed = 1;
101 
102   /* Flag indicating that the target has proceeded since the last
103      command was issued.  */
104   int mi_proceeded;
105 
106   const char *current_token;
107 };
108 
109 /* Output the shared object attributes to UIOUT.  */
110 
111 void mi_output_solib_attribs (ui_out *uiout, const solib &solib);
112 
113 /* Returns the INTERP's data cast as mi_interp if INTERP is an MI, and
114    returns NULL otherwise.  */
115 
116 static inline struct mi_interp *
as_mi_interp(struct interp * interp)117 as_mi_interp (struct interp *interp)
118 {
119   return dynamic_cast<mi_interp *> (interp);
120 }
121 
122 #endif /* MI_MI_INTERP_H */
123