Allow defining a user command inside a user command
[deliverable/binutils-gdb.git] / gdb / cli / cli-script.h
1 /* Header file for GDB CLI command implementation library.
2 Copyright (C) 2000-2018 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 #if !defined (CLI_SCRIPT_H)
18 #define CLI_SCRIPT_H 1
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 (const char *, int, int,
110 void (*)(char *, void *),
111 void *);
112 extern counted_command_line read_command_lines_1 (char * (*) (void), int,
113 void (*)(char *, void *),
114 void *);
115
116
117 /* Exported to cli/cli-cmds.c */
118
119 extern void script_from_file (FILE *stream, const char *file);
120
121 extern void show_user_1 (struct cmd_list_element *c,
122 const char *prefix,
123 const char *name,
124 struct ui_file *stream);
125
126 /* Exported to gdb/breakpoint.c */
127
128 extern enum command_control_type
129 execute_control_command (struct command_line *cmd);
130
131 extern enum command_control_type
132 execute_control_command_untraced (struct command_line *cmd);
133
134 extern counted_command_line get_command_line (enum command_control_type,
135 const char *);
136
137 extern void print_command_lines (struct ui_out *,
138 struct command_line *, unsigned int);
139
140 /* Exported to gdb/infrun.c */
141
142 extern void execute_user_command (struct cmd_list_element *c, const char *args);
143
144 /* If we're in a user-defined command, replace any $argc/$argN
145 reference found in LINE with the arguments that were passed to the
146 command. Otherwise, treat $argc/$argN as normal convenience
147 variables. */
148 extern std::string insert_user_defined_cmd_args (const char *line);
149
150 /* Exported to top.c */
151
152 extern void print_command_trace (const char *cmd, ...)
153 ATTRIBUTE_PRINTF (1, 2);
154
155 /* Exported to event-top.c */
156
157 extern void reset_command_nest_depth (void);
158
159 #endif /* !defined (CLI_SCRIPT_H) */
This page took 0.034395 seconds and 5 git commands to generate.