1 /* Header file for GDB CLI command implementation library. 2 Copyright (C) 2000-2019 Free Software Foundation, Inc. 3 4 This program is free software; you can redistribute it and/or modify 5 it under the terms of the GNU General Public License as published by 6 the Free Software Foundation; either version 3 of the License, or 7 (at your option) any later version. 8 9 This program is distributed in the hope that it will be useful, 10 but WITHOUT ANY WARRANTY; without even the implied warranty of 11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 GNU General Public License for more details. 13 14 You should have received a copy of the GNU General Public License 15 along with this program. If not, see <http://www.gnu.org/licenses/>. */ 16 17 #ifndef CLI_CLI_SCRIPT_H 18 #define CLI_CLI_SCRIPT_H 19 20 struct ui_file; 21 struct cmd_list_element; 22 23 /* * Control types for commands. */ 24 25 enum misc_command_type 26 { 27 ok_command, 28 end_command, 29 else_command, 30 nop_command 31 }; 32 33 enum command_control_type 34 { 35 simple_control, 36 break_control, 37 continue_control, 38 while_control, 39 if_control, 40 commands_control, 41 python_control, 42 compile_control, 43 guile_control, 44 while_stepping_control, 45 define_control, 46 invalid_control 47 }; 48 49 struct command_line; 50 51 extern void free_command_lines (struct command_line **); 52 53 /* A deleter for command_line that calls free_command_lines. */ 54 55 struct command_lines_deleter 56 { 57 void operator() (command_line *cmd_lines) const 58 { 59 free_command_lines (&cmd_lines); 60 } 61 }; 62 63 /* A reference-counted struct command_line. */ 64 typedef std::shared_ptr<command_line> counted_command_line; 65 66 /* * Structure for saved commands lines (for breakpoints, defined 67 commands, etc). */ 68 69 struct command_line 70 { 71 explicit command_line (command_control_type type_, char *line_ = nullptr) 72 : line (line_), 73 control_type (type_) 74 { 75 memset (&control_u, 0, sizeof (control_u)); 76 } 77 78 DISABLE_COPY_AND_ASSIGN (command_line); 79 80 struct command_line *next = nullptr; 81 char *line; 82 enum command_control_type control_type; 83 union 84 { 85 struct 86 { 87 enum compile_i_scope_types scope; 88 void *scope_data; 89 } 90 compile; 91 } 92 control_u; 93 /* * For composite commands, the nested lists of commands. For 94 example, for "if" command this will contain the then branch and 95 the else branch, if that is available. */ 96 counted_command_line body_list_0; 97 counted_command_line body_list_1; 98 99 private: 100 101 friend void free_command_lines (struct command_line **); 102 103 ~command_line () 104 { 105 xfree (line); 106 } 107 }; 108 109 extern counted_command_line read_command_lines 110 (const char *, int, int, gdb::function_view<void (const char *)>); 111 extern counted_command_line read_command_lines_1 112 (gdb::function_view<const char * ()>, int, 113 gdb::function_view<void (const char *)>); 114 115 116 /* Exported to cli/cli-cmds.c */ 117 118 extern void script_from_file (FILE *stream, const char *file); 119 120 extern void show_user_1 (struct cmd_list_element *c, 121 const char *prefix, 122 const char *name, 123 struct ui_file *stream); 124 125 /* Execute the commands in CMDLINES. */ 126 127 extern void execute_control_commands (struct command_line *cmdlines, 128 int from_tty); 129 130 /* Run execute_control_commands for COMMANDS. Capture its output into 131 the returned string, do not display it to the screen. BATCH_FLAG 132 will be temporarily set to true. */ 133 134 extern std::string execute_control_commands_to_string 135 (struct command_line *commands, int from_tty); 136 137 /* Exported to gdb/breakpoint.c */ 138 139 extern enum command_control_type 140 execute_control_command (struct command_line *cmd, 141 int from_tty = 0); 142 143 extern enum command_control_type 144 execute_control_command_untraced (struct command_line *cmd); 145 146 extern counted_command_line get_command_line (enum command_control_type, 147 const char *); 148 149 extern void print_command_lines (struct ui_out *, 150 struct command_line *, unsigned int); 151 152 /* Exported to gdb/infrun.c */ 153 154 extern void execute_user_command (struct cmd_list_element *c, const char *args); 155 156 /* If we're in a user-defined command, replace any $argc/$argN 157 reference found in LINE with the arguments that were passed to the 158 command. Otherwise, treat $argc/$argN as normal convenience 159 variables. */ 160 extern std::string insert_user_defined_cmd_args (const char *line); 161 162 /* Exported to top.c */ 163 164 extern void print_command_trace (const char *cmd, ...) 165 ATTRIBUTE_PRINTF (1, 2); 166 167 /* Exported to event-top.c */ 168 169 extern void reset_command_nest_depth (void); 170 171 #endif /* CLI_CLI_SCRIPT_H */ 172