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