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