Fix latent bug in test_gdb_complete_cmd_multiple
[deliverable/binutils-gdb.git] / gdb / extension.h
CommitLineData
6dddc817
DE
1/* Interface between gdb and its extension languages.
2
42a4f53d 3 Copyright (C) 2014-2019 Free Software Foundation, Inc.
6dddc817
DE
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 EXTENSION_H
21#define EXTENSION_H
22
4de283e4 23#include "mi/mi-cmds.h" /* For PRINT_NO_VALUES, etc. */
d55e5aa6 24#include "common/vec.h"
4de283e4 25#include "common/array-view.h"
6dddc817
DE
26
27struct breakpoint;
28struct command_line;
29struct frame_info;
30struct language_defn;
31struct objfile;
32struct extension_language_defn;
33struct type;
34struct ui_file;
35struct ui_out;
36struct value;
37struct value_print_options;
38
39/* A function to load and process a script file.
40 The file has been opened and is ready to be read from the beginning.
41 Any exceptions are not caught, and are passed to the caller. */
42typedef void script_sourcer_func (const struct extension_language_defn *,
43 FILE *stream, const char *filename);
44
45/* A function to load and process a script for an objfile.
46 The file has been opened and is ready to be read from the beginning.
47 Any exceptions are not caught, and are passed to the caller. */
48typedef void objfile_script_sourcer_func
49 (const struct extension_language_defn *,
50 struct objfile *, FILE *stream, const char *filename);
51
9f050062
DE
52/* A function to execute a script for an objfile.
53 Any exceptions are not caught, and are passed to the caller. */
54typedef void objfile_script_executor_func
55 (const struct extension_language_defn *,
56 struct objfile *, const char *name, const char *script);
57
6dddc817
DE
58/* Enum of each extension(/scripting) language. */
59
60enum extension_language
61 {
62 EXT_LANG_NONE,
63 EXT_LANG_GDB,
ed3ef339
DE
64 EXT_LANG_PYTHON,
65 EXT_LANG_GUILE
6dddc817
DE
66 };
67
68/* Extension language frame-filter status return values. */
69
70enum ext_lang_bt_status
71 {
72 /* Return when an error has occurred in processing frame filters,
73 or when printing the stack. */
74 EXT_LANG_BT_ERROR = -1,
75
76 /* Return from internal routines to indicate that the function
77 succeeded. */
78 EXT_LANG_BT_OK = 1,
79
6dddc817
DE
80 /* Return when the frame filter process is complete, but there
81 were no filter registered and enabled to process. */
63283d4a 82 EXT_LANG_BT_NO_FILTERS = 2
6dddc817
DE
83 };
84
85/* Flags to pass to apply_extlang_frame_filter. */
86
d4dd3282 87enum frame_filter_flag
6dddc817
DE
88 {
89 /* Set this flag if frame level is to be printed. */
d4dd3282 90 PRINT_LEVEL = 1 << 0,
6dddc817
DE
91
92 /* Set this flag if frame information is to be printed. */
d4dd3282 93 PRINT_FRAME_INFO = 1 << 1,
6dddc817
DE
94
95 /* Set this flag if frame arguments are to be printed. */
d4dd3282 96 PRINT_ARGS = 1 << 2,
6dddc817
DE
97
98 /* Set this flag if frame locals are to be printed. */
d4dd3282 99 PRINT_LOCALS = 1 << 3,
6893c19a
TT
100
101 /* Set this flag if a "More frames" message is to be printed. */
d4dd3282 102 PRINT_MORE_FRAMES = 1 << 4,
978d6c75
TT
103
104 /* Set this flag if elided frames should not be printed. */
105 PRINT_HIDE = 1 << 5,
6dddc817
DE
106 };
107
d4dd3282
TT
108DEF_ENUM_FLAGS_TYPE (enum frame_filter_flag, frame_filter_flags);
109
6dddc817
DE
110/* A choice of the different frame argument printing strategies that
111 can occur in different cases of frame filter instantiation. */
112
113enum ext_lang_frame_args
114 {
115 /* Print no values for arguments when invoked from the MI. */
116 NO_VALUES = PRINT_NO_VALUES,
117
118 MI_PRINT_ALL_VALUES = PRINT_ALL_VALUES,
119
120 /* Print only simple values (what MI defines as "simple") for
121 arguments when invoked from the MI. */
122 MI_PRINT_SIMPLE_VALUES = PRINT_SIMPLE_VALUES,
123
124 /* Print only scalar values for arguments when invoked from the CLI. */
125 CLI_SCALAR_VALUES,
126
127 /* Print all values for arguments when invoked from the CLI. */
128 CLI_ALL_VALUES
129 };
130
131/* The possible results of
132 extension_language_ops.breakpoint_cond_says_stop. */
133
134enum ext_lang_bp_stop
135 {
136 /* No "stop" condition is set. */
137 EXT_LANG_BP_STOP_UNSET,
138
139 /* A "stop" condition is set, and it says "don't stop". */
140 EXT_LANG_BP_STOP_NO,
141
142 /* A "stop" condition is set, and it says "stop". */
143 EXT_LANG_BP_STOP_YES
144 };
145
146/* Table of type printers associated with the global typedef table. */
147
148struct ext_lang_type_printers
149{
c819b2c0
TT
150 ext_lang_type_printers ();
151 ~ext_lang_type_printers ();
152
153 DISABLE_COPY_AND_ASSIGN (ext_lang_type_printers);
154
6dddc817 155 /* Type-printers from Python. */
fe10fe31 156 void *py_type_printers = nullptr;
6dddc817 157};
e81e7f5e 158
ba18742c
SM
159/* The return code for some API calls. */
160
161enum ext_lang_rc
162{
163 /* The operation completed successfully. */
164 EXT_LANG_RC_OK,
165
166 /* The operation was not performed (e.g., no pretty-printer). */
167 EXT_LANG_RC_NOP,
168
169 /* There was an error (e.g., Python error while printing a value).
170 When an error occurs no further extension languages are tried.
171 This is to preserve existing behaviour, and because it's convenient
172 for Python developers.
173 Note: This is different than encountering a memory error trying to read
174 a value for pretty-printing. Here we're referring to, e.g., programming
175 errors that trigger an exception in the extension language. */
176 EXT_LANG_RC_ERROR
177};
178
e81e7f5e
SC
179/* A type which holds its extension language specific xmethod worker data. */
180
181struct xmethod_worker
182{
ba18742c
SM
183 xmethod_worker (const extension_language_defn *extlang)
184 : m_extlang (extlang)
185 {}
186
187 virtual ~xmethod_worker () = default;
188
189 /* Invoke the xmethod encapsulated in this worker and return the result.
6b1747cd 190 The method is invoked on OBJ with arguments in the ARGS array. */
ba18742c 191
6b1747cd 192 virtual value *invoke (value *obj, gdb::array_view<value *> args) = 0;
ba18742c 193
ba18742c 194 /* Return the arg types of the xmethod encapsulated in this worker.
6b1747cd
PA
195 The type of the 'this' object is returned as the first element of
196 the vector. */
ba18742c 197
6b1747cd 198 std::vector<type *> get_arg_types ();
ba18742c
SM
199
200 /* Return the type of the result of the xmethod encapsulated in this worker.
6b1747cd 201 OBJECT and ARGS are the same as for invoke. */
e81e7f5e 202
6b1747cd 203 type *get_result_type (value *object, gdb::array_view<value *> args);
e81e7f5e 204
ba18742c
SM
205private:
206
6b1747cd
PA
207 /* Return the types of the arguments the method takes. The types
208 are returned in TYPE_ARGS, one per argument. */
ba18742c
SM
209
210 virtual enum ext_lang_rc do_get_arg_types
6b1747cd 211 (std::vector<type *> *type_args) = 0;
ba18742c 212
6b1747cd
PA
213 /* Fetch the type of the result of the method implemented by this
214 worker. OBJECT and ARGS are the same as for the invoked method.
215 The result type is stored in *RESULT_TYPE. */
ba18742c
SM
216
217 virtual enum ext_lang_rc do_get_result_type
6b1747cd 218 (struct value *obj, gdb::array_view<value *> args,
ba18742c
SM
219 struct type **result_type_ptr) = 0;
220
221 /* The language the xmethod worker is implemented in. */
222
223 const extension_language_defn *m_extlang;
e81e7f5e
SC
224};
225
ba18742c 226typedef std::unique_ptr<xmethod_worker> xmethod_worker_up;
e81e7f5e 227
6dddc817
DE
228/* The interface for gdb's own extension(/scripting) language. */
229extern const struct extension_language_defn extension_language_gdb;
230
231extern const struct extension_language_defn *get_ext_lang_defn
232 (enum extension_language lang);
233
234extern const struct extension_language_defn *get_ext_lang_of_file
235 (const char *file);
236
237extern int ext_lang_present_p (const struct extension_language_defn *);
238
239extern int ext_lang_initialized_p (const struct extension_language_defn *);
240
241extern void throw_ext_lang_unsupported
242 (const struct extension_language_defn *);
243
244/* Accessors for "public" attributes of the extension language definition. */
245
246extern enum extension_language ext_lang_kind
247 (const struct extension_language_defn *);
248
249extern const char *ext_lang_name (const struct extension_language_defn *);
250
251extern const char *ext_lang_capitalized_name
252 (const struct extension_language_defn *);
253
254extern const char *ext_lang_suffix (const struct extension_language_defn *);
255
256extern const char *ext_lang_auto_load_suffix
257 (const struct extension_language_defn *);
258
259extern script_sourcer_func *ext_lang_script_sourcer
260 (const struct extension_language_defn *);
261
262extern objfile_script_sourcer_func *ext_lang_objfile_script_sourcer
263 (const struct extension_language_defn *);
9f050062
DE
264
265extern objfile_script_executor_func *ext_lang_objfile_script_executor
266 (const struct extension_language_defn *);
6dddc817
DE
267
268extern int ext_lang_auto_load_enabled (const struct extension_language_defn *);
269
270/* Wrappers for each extension language API function that iterate over all
271 extension languages. */
272
273extern void finish_ext_lang_initialization (void);
274
275extern void eval_ext_lang_from_control_command (struct command_line *cmd);
276
277extern void auto_load_ext_lang_scripts_for_objfile (struct objfile *);
278
6dddc817
DE
279extern char *apply_ext_lang_type_printers (struct ext_lang_type_printers *,
280 struct type *);
281
6dddc817 282extern int apply_ext_lang_val_pretty_printer
668e1674 283 (struct type *type,
6b850546 284 LONGEST embedded_offset, CORE_ADDR address,
6dddc817 285 struct ui_file *stream, int recurse,
668e1674 286 struct value *val, const struct value_print_options *options,
6dddc817
DE
287 const struct language_defn *language);
288
289extern enum ext_lang_bt_status apply_ext_lang_frame_filter
d4dd3282
TT
290 (struct frame_info *frame, frame_filter_flags flags,
291 enum ext_lang_frame_args args_type,
6dddc817
DE
292 struct ui_out *out, int frame_low, int frame_high);
293
294extern void preserve_ext_lang_values (struct objfile *, htab_t copied_types);
295
296extern const struct extension_language_defn *get_breakpoint_cond_ext_lang
297 (struct breakpoint *b, enum extension_language skip_lang);
298
299extern int breakpoint_ext_lang_cond_says_stop (struct breakpoint *);
300
ba18742c
SM
301/* If a method with name METHOD_NAME is to be invoked on an object of type
302 TYPE, then all extension languages are searched for implementations of
303 methods with name METHOD_NAME. All matches found are appended to the WORKERS
304 vector. */
e81e7f5e 305
ba18742c
SM
306extern void get_matching_xmethod_workers
307 (struct type *type, const char *method_name,
308 std::vector<xmethod_worker_up> *workers);
2ce1cdbf 309
6dddc817 310#endif /* EXTENSION_H */
This page took 0.448496 seconds and 4 git commands to generate.