1 /* MI Command Set for GDB, the GNU debugger. 2 3 Copyright (C) 2000-2024 Free Software Foundation, Inc. 4 5 Contributed by Cygnus Solutions (a Red Hat company). 6 7 This file is part of GDB. 8 9 This program is free software; you can redistribute it and/or modify 10 it under the terms of the GNU General Public License as published by 11 the Free Software Foundation; either version 3 of the License, or 12 (at your option) any later version. 13 14 This program is distributed in the hope that it will be useful, 15 but WITHOUT ANY WARRANTY; without even the implied warranty of 16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 GNU General Public License for more details. 18 19 You should have received a copy of the GNU General Public License 20 along with this program. If not, see <http://www.gnu.org/licenses/>. */ 21 22 #ifndef MI_MI_CMDS_H 23 #define MI_MI_CMDS_H 24 25 #include "gdbsupport/function-view.h" 26 #include <optional> 27 #include "mi/mi-main.h" 28 29 enum print_values { 30 PRINT_NO_VALUES, 31 PRINT_ALL_VALUES, 32 PRINT_SIMPLE_VALUES 33 }; 34 35 typedef void (mi_cmd_argv_ftype) (const char *command, const char *const *argv, 36 int argc); 37 38 /* Declarations of the functions implementing each command. */ 39 40 extern mi_cmd_argv_ftype mi_cmd_ada_task_info; 41 extern mi_cmd_argv_ftype mi_cmd_add_inferior; 42 extern mi_cmd_argv_ftype mi_cmd_break_insert; 43 extern mi_cmd_argv_ftype mi_cmd_dprintf_insert; 44 extern mi_cmd_argv_ftype mi_cmd_break_condition; 45 extern mi_cmd_argv_ftype mi_cmd_break_commands; 46 extern mi_cmd_argv_ftype mi_cmd_break_passcount; 47 extern mi_cmd_argv_ftype mi_cmd_break_watch; 48 extern mi_cmd_argv_ftype mi_cmd_catch_assert; 49 extern mi_cmd_argv_ftype mi_cmd_catch_exception; 50 extern mi_cmd_argv_ftype mi_cmd_catch_handlers; 51 extern mi_cmd_argv_ftype mi_cmd_catch_load; 52 extern mi_cmd_argv_ftype mi_cmd_catch_unload; 53 extern mi_cmd_argv_ftype mi_cmd_catch_throw; 54 extern mi_cmd_argv_ftype mi_cmd_catch_rethrow; 55 extern mi_cmd_argv_ftype mi_cmd_catch_catch; 56 extern mi_cmd_argv_ftype mi_cmd_disassemble; 57 extern mi_cmd_argv_ftype mi_cmd_data_evaluate_expression; 58 extern mi_cmd_argv_ftype mi_cmd_data_list_register_names; 59 extern mi_cmd_argv_ftype mi_cmd_data_list_register_values; 60 extern mi_cmd_argv_ftype mi_cmd_data_list_changed_registers; 61 extern mi_cmd_argv_ftype mi_cmd_data_read_memory; 62 extern mi_cmd_argv_ftype mi_cmd_data_read_memory_bytes; 63 extern mi_cmd_argv_ftype mi_cmd_data_write_memory; 64 extern mi_cmd_argv_ftype mi_cmd_data_write_memory_bytes; 65 extern mi_cmd_argv_ftype mi_cmd_data_write_register_values; 66 extern mi_cmd_argv_ftype mi_cmd_enable_timings; 67 extern mi_cmd_argv_ftype mi_cmd_env_cd; 68 extern mi_cmd_argv_ftype mi_cmd_env_dir; 69 extern mi_cmd_argv_ftype mi_cmd_env_path; 70 extern mi_cmd_argv_ftype mi_cmd_env_pwd; 71 extern mi_cmd_argv_ftype mi_cmd_exec_continue; 72 extern mi_cmd_argv_ftype mi_cmd_exec_finish; 73 extern mi_cmd_argv_ftype mi_cmd_exec_interrupt; 74 extern mi_cmd_argv_ftype mi_cmd_exec_jump; 75 extern mi_cmd_argv_ftype mi_cmd_exec_next; 76 extern mi_cmd_argv_ftype mi_cmd_exec_next_instruction; 77 extern mi_cmd_argv_ftype mi_cmd_exec_return; 78 extern mi_cmd_argv_ftype mi_cmd_exec_run; 79 extern mi_cmd_argv_ftype mi_cmd_exec_step; 80 extern mi_cmd_argv_ftype mi_cmd_exec_step_instruction; 81 extern mi_cmd_argv_ftype mi_cmd_file_list_exec_source_file; 82 extern mi_cmd_argv_ftype mi_cmd_file_list_exec_source_files; 83 extern mi_cmd_argv_ftype mi_cmd_file_list_shared_libraries; 84 extern mi_cmd_argv_ftype mi_cmd_gdb_exit; 85 extern mi_cmd_argv_ftype mi_cmd_inferior_tty_set; 86 extern mi_cmd_argv_ftype mi_cmd_inferior_tty_show; 87 extern mi_cmd_argv_ftype mi_cmd_info_ada_exceptions; 88 extern mi_cmd_argv_ftype mi_cmd_info_gdb_mi_command; 89 extern mi_cmd_argv_ftype mi_cmd_info_os; 90 extern mi_cmd_argv_ftype mi_cmd_interpreter_exec; 91 extern mi_cmd_argv_ftype mi_cmd_list_features; 92 extern mi_cmd_argv_ftype mi_cmd_list_target_features; 93 extern mi_cmd_argv_ftype mi_cmd_list_thread_groups; 94 extern mi_cmd_argv_ftype mi_cmd_remove_inferior; 95 extern mi_cmd_argv_ftype mi_cmd_stack_info_depth; 96 extern mi_cmd_argv_ftype mi_cmd_stack_info_frame; 97 extern mi_cmd_argv_ftype mi_cmd_stack_list_args; 98 extern mi_cmd_argv_ftype mi_cmd_stack_list_frames; 99 extern mi_cmd_argv_ftype mi_cmd_stack_list_locals; 100 extern mi_cmd_argv_ftype mi_cmd_stack_list_variables; 101 extern mi_cmd_argv_ftype mi_cmd_stack_select_frame; 102 extern mi_cmd_argv_ftype mi_cmd_symbol_list_lines; 103 extern mi_cmd_argv_ftype mi_cmd_symbol_info_functions; 104 extern mi_cmd_argv_ftype mi_cmd_symbol_info_module_functions; 105 extern mi_cmd_argv_ftype mi_cmd_symbol_info_module_variables; 106 extern mi_cmd_argv_ftype mi_cmd_symbol_info_modules; 107 extern mi_cmd_argv_ftype mi_cmd_symbol_info_types; 108 extern mi_cmd_argv_ftype mi_cmd_symbol_info_variables; 109 extern mi_cmd_argv_ftype mi_cmd_target_detach; 110 extern mi_cmd_argv_ftype mi_cmd_target_file_get; 111 extern mi_cmd_argv_ftype mi_cmd_target_file_put; 112 extern mi_cmd_argv_ftype mi_cmd_target_file_delete; 113 extern mi_cmd_argv_ftype mi_cmd_target_flash_erase; 114 extern mi_cmd_argv_ftype mi_cmd_thread_info; 115 extern mi_cmd_argv_ftype mi_cmd_thread_list_ids; 116 extern mi_cmd_argv_ftype mi_cmd_thread_select; 117 extern mi_cmd_argv_ftype mi_cmd_trace_define_variable; 118 extern mi_cmd_argv_ftype mi_cmd_trace_find; 119 extern mi_cmd_argv_ftype mi_cmd_trace_frame_collected; 120 extern mi_cmd_argv_ftype mi_cmd_trace_list_variables; 121 extern mi_cmd_argv_ftype mi_cmd_trace_save; 122 extern mi_cmd_argv_ftype mi_cmd_trace_start; 123 extern mi_cmd_argv_ftype mi_cmd_trace_status; 124 extern mi_cmd_argv_ftype mi_cmd_trace_stop; 125 extern mi_cmd_argv_ftype mi_cmd_var_assign; 126 extern mi_cmd_argv_ftype mi_cmd_var_create; 127 extern mi_cmd_argv_ftype mi_cmd_var_delete; 128 extern mi_cmd_argv_ftype mi_cmd_var_evaluate_expression; 129 extern mi_cmd_argv_ftype mi_cmd_var_info_expression; 130 extern mi_cmd_argv_ftype mi_cmd_var_info_path_expression; 131 extern mi_cmd_argv_ftype mi_cmd_var_info_num_children; 132 extern mi_cmd_argv_ftype mi_cmd_var_info_type; 133 extern mi_cmd_argv_ftype mi_cmd_var_list_children; 134 extern mi_cmd_argv_ftype mi_cmd_var_set_format; 135 extern mi_cmd_argv_ftype mi_cmd_var_set_frozen; 136 extern mi_cmd_argv_ftype mi_cmd_var_set_visualizer; 137 extern mi_cmd_argv_ftype mi_cmd_var_show_attributes; 138 extern mi_cmd_argv_ftype mi_cmd_var_show_format; 139 extern mi_cmd_argv_ftype mi_cmd_var_update; 140 extern mi_cmd_argv_ftype mi_cmd_enable_pretty_printing; 141 extern mi_cmd_argv_ftype mi_cmd_enable_frame_filters; 142 extern mi_cmd_argv_ftype mi_cmd_var_set_update_range; 143 extern mi_cmd_argv_ftype mi_cmd_complete; 144 145 /* The abstract base class for all MI command types. */ 146 147 struct mi_command 148 { 149 /* Constructor. NAME is the name of this MI command, excluding any 150 leading dash, that is the initial string the user will enter to run 151 this command. The SUPPRESS_NOTIFICATION pointer is a flag which will 152 be set to 1 when this command is invoked, and reset to its previous 153 value once the command invocation has completed. */ 154 mi_command (const char *name, int *suppress_notification); 155 156 /* Destructor. */ 157 virtual ~mi_command () = default; 158 159 /* Return the name of this command. This is the command that the user 160 will actually type in, without any arguments, and without the leading 161 dash. */ namemi_command162 const char *name () const 163 { return m_name; } 164 165 /* Execute the MI command. this needs to be overridden in each 166 base class. PARSE is the parsed command line from the user. 167 Can throw an exception if something goes wrong. */ 168 virtual void invoke (struct mi_parse *parse) const = 0; 169 170 /* Return whether this command preserves user selected context (thread 171 and frame). */ preserve_user_selected_contextmi_command172 bool preserve_user_selected_context () const 173 { 174 /* Here we exploit the fact that if MI command is supposed to change 175 user context, then it should not emit change notifications. Therefore if 176 command does not suppress user context change notifications, then it should 177 preserve the context. */ 178 return m_suppress_notification != &mi_suppress_notification.user_selected_context; 179 } 180 181 /* If this command was created with a suppress notifications pointer, 182 then this function will set the suppress flag and return a 183 std::optional with its value set to an object that will restore the 184 previous value of the suppress notifications flag. 185 186 If this command was created without a suppress notifications points, 187 then this function returns an empty std::optional. */ 188 std::optional<scoped_restore_tmpl<int>> do_suppress_notification () const; 189 190 private: 191 192 /* The name of the command. */ 193 const char *m_name; 194 195 /* Pointer to integer to set during command's invocation. */ 196 int *m_suppress_notification; 197 }; 198 199 /* A command held in the global mi_cmd_table. */ 200 201 using mi_command_up = std::unique_ptr<struct mi_command>; 202 203 /* Lookup a command in the MI command table, returns nullptr if COMMAND is 204 not found. */ 205 206 extern mi_command *mi_cmd_lookup (const char *command); 207 208 extern void mi_execute_command (const char *cmd, int from_tty); 209 210 /* Execute an MI command given an already-constructed parse 211 object. */ 212 213 extern void mi_execute_command (mi_parse *context); 214 215 /* Insert COMMAND into the global mi_cmd_table. Return false if 216 COMMAND->name already exists in mi_cmd_table, in which case COMMAND will 217 not have been added to mi_cmd_table. Otherwise, return true, and 218 COMMAND was added to mi_cmd_table. */ 219 220 extern bool insert_mi_cmd_entry (mi_command_up command); 221 222 /* Remove the command called NAME from the global mi_cmd_table. Return 223 true if the removal was a success, otherwise return false, which 224 indicates no command called NAME was found in the mi_cmd_table. */ 225 226 extern bool remove_mi_cmd_entry (const std::string &name); 227 228 /* Call CALLBACK for each registered MI command. Remove commands for which 229 CALLBACK returns true. */ 230 231 using remove_mi_cmd_entries_ftype 232 = gdb::function_view<bool (mi_command *)>; 233 extern void remove_mi_cmd_entries (remove_mi_cmd_entries_ftype callback); 234 235 /* Return true if type is a simple type: that is, neither an array, structure, 236 or union, nor a reference to an array, structure, or union. */ 237 238 extern bool mi_simple_type_p (struct type *type); 239 240 #endif /* MI_MI_CMDS_H */ 241