1 /* Interface between gdb and its extension languages.
3 Copyright (C) 2014-2018 Free Software Foundation, Inc.
5 This file is part of GDB.
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.
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.
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/>. */
23 #include "mi/mi-cmds.h" /* For PRINT_NO_VALUES, etc. */
24 #include "common/vec.h"
31 struct extension_language_defn
;
36 struct value_print_options
;
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
);
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
);
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
);
57 /* Enum of each extension(/scripting) language. */
59 enum extension_language
67 /* Extension language frame-filter status return values. */
69 enum ext_lang_bt_status
71 /* Return when an error has occurred in processing frame filters,
72 or when printing the stack. */
73 EXT_LANG_BT_ERROR
= -1,
75 /* Return from internal routines to indicate that the function
79 /* Return when the frame filter process is complete, and all
80 operations have succeeded. */
81 EXT_LANG_BT_COMPLETED
= 2,
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
88 /* Flags to pass to apply_extlang_frame_filter. */
90 enum frame_filter_flag
92 /* Set this flag if frame level is to be printed. */
95 /* Set this flag if frame information is to be printed. */
96 PRINT_FRAME_INFO
= 1 << 1,
98 /* Set this flag if frame arguments are to be printed. */
101 /* Set this flag if frame locals are to be printed. */
102 PRINT_LOCALS
= 1 << 3,
104 /* Set this flag if a "More frames" message is to be printed. */
105 PRINT_MORE_FRAMES
= 1 << 4,
107 /* Set this flag if elided frames should not be printed. */
111 DEF_ENUM_FLAGS_TYPE (enum frame_filter_flag
, frame_filter_flags
);
113 /* A choice of the different frame argument printing strategies that
114 can occur in different cases of frame filter instantiation. */
116 enum ext_lang_frame_args
118 /* Print no values for arguments when invoked from the MI. */
119 NO_VALUES
= PRINT_NO_VALUES
,
121 MI_PRINT_ALL_VALUES
= PRINT_ALL_VALUES
,
123 /* Print only simple values (what MI defines as "simple") for
124 arguments when invoked from the MI. */
125 MI_PRINT_SIMPLE_VALUES
= PRINT_SIMPLE_VALUES
,
127 /* Print only scalar values for arguments when invoked from the CLI. */
130 /* Print all values for arguments when invoked from the CLI. */
134 /* The possible results of
135 extension_language_ops.breakpoint_cond_says_stop. */
137 enum ext_lang_bp_stop
139 /* No "stop" condition is set. */
140 EXT_LANG_BP_STOP_UNSET
,
142 /* A "stop" condition is set, and it says "don't stop". */
145 /* A "stop" condition is set, and it says "stop". */
149 /* Table of type printers associated with the global typedef table. */
151 struct ext_lang_type_printers
153 /* Type-printers from Python. */
154 void *py_type_printers
;
157 /* The return code for some API calls. */
161 /* The operation completed successfully. */
164 /* The operation was not performed (e.g., no pretty-printer). */
167 /* There was an error (e.g., Python error while printing a value).
168 When an error occurs no further extension languages are tried.
169 This is to preserve existing behaviour, and because it's convenient
170 for Python developers.
171 Note: This is different than encountering a memory error trying to read
172 a value for pretty-printing. Here we're referring to, e.g., programming
173 errors that trigger an exception in the extension language. */
177 /* A type which holds its extension language specific xmethod worker data. */
179 struct xmethod_worker
181 xmethod_worker (const extension_language_defn
*extlang
)
182 : m_extlang (extlang
)
185 virtual ~xmethod_worker () = default;
187 /* Invoke the xmethod encapsulated in this worker and return the result.
188 The method is invoked on OBJ with arguments in the ARGS array. NARGS is
189 the length of the this array. */
191 virtual value
*invoke (value
*obj
, value
**args
, int nargs
) = 0;
193 /* Return the arg types of the xmethod encapsulated in this worker.
194 An array of arg types is returned. The length of the array is returned in
195 NARGS. The type of the 'this' object is returned as the first element of
198 type
**get_arg_types (int *nargs
);
200 /* Return the type of the result of the xmethod encapsulated in this worker.
201 OBJECT, ARGS, NARGS are the same as for invoke. */
203 type
*get_result_type (value
*object
, value
**args
, int nargs
);
207 /* Return the types of the arguments the method takes. The number of
208 arguments is returned in NARGS, and their types are returned in the array
211 virtual enum ext_lang_rc do_get_arg_types
212 (int *nargs
, struct type
***arg_types
) = 0;
214 /* Fetch the type of the result of the method implemented by this worker.
215 OBJECT, ARGS, NARGS are the same as for the invoked method. The result
216 type is stored in *RESULT_TYPE. */
218 virtual enum ext_lang_rc do_get_result_type
219 (struct value
*obj
, struct value
**args
, int nargs
,
220 struct type
**result_type_ptr
) = 0;
222 /* The language the xmethod worker is implemented in. */
224 const extension_language_defn
*m_extlang
;
227 typedef std::unique_ptr
<xmethod_worker
> xmethod_worker_up
;
229 /* The interface for gdb's own extension(/scripting) language. */
230 extern const struct extension_language_defn extension_language_gdb
;
232 extern const struct extension_language_defn
*get_ext_lang_defn
233 (enum extension_language lang
);
235 extern const struct extension_language_defn
*get_ext_lang_of_file
238 extern int ext_lang_present_p (const struct extension_language_defn
*);
240 extern int ext_lang_initialized_p (const struct extension_language_defn
*);
242 extern void throw_ext_lang_unsupported
243 (const struct extension_language_defn
*);
245 /* Accessors for "public" attributes of the extension language definition. */
247 extern enum extension_language ext_lang_kind
248 (const struct extension_language_defn
*);
250 extern const char *ext_lang_name (const struct extension_language_defn
*);
252 extern const char *ext_lang_capitalized_name
253 (const struct extension_language_defn
*);
255 extern const char *ext_lang_suffix (const struct extension_language_defn
*);
257 extern const char *ext_lang_auto_load_suffix
258 (const struct extension_language_defn
*);
260 extern script_sourcer_func
*ext_lang_script_sourcer
261 (const struct extension_language_defn
*);
263 extern objfile_script_sourcer_func
*ext_lang_objfile_script_sourcer
264 (const struct extension_language_defn
*);
266 extern objfile_script_executor_func
*ext_lang_objfile_script_executor
267 (const struct extension_language_defn
*);
269 extern int ext_lang_auto_load_enabled (const struct extension_language_defn
*);
271 /* Wrappers for each extension language API function that iterate over all
272 extension languages. */
274 extern void finish_ext_lang_initialization (void);
276 extern void eval_ext_lang_from_control_command (struct command_line
*cmd
);
278 extern void auto_load_ext_lang_scripts_for_objfile (struct objfile
*);
280 extern struct ext_lang_type_printers
*start_ext_lang_type_printers (void);
282 extern char *apply_ext_lang_type_printers (struct ext_lang_type_printers
*,
285 extern void free_ext_lang_type_printers (struct ext_lang_type_printers
*);
287 extern int apply_ext_lang_val_pretty_printer
289 LONGEST embedded_offset
, CORE_ADDR address
,
290 struct ui_file
*stream
, int recurse
,
291 struct value
*val
, const struct value_print_options
*options
,
292 const struct language_defn
*language
);
294 extern enum ext_lang_bt_status apply_ext_lang_frame_filter
295 (struct frame_info
*frame
, frame_filter_flags flags
,
296 enum ext_lang_frame_args args_type
,
297 struct ui_out
*out
, int frame_low
, int frame_high
);
299 extern void preserve_ext_lang_values (struct objfile
*, htab_t copied_types
);
301 extern const struct extension_language_defn
*get_breakpoint_cond_ext_lang
302 (struct breakpoint
*b
, enum extension_language skip_lang
);
304 extern int breakpoint_ext_lang_cond_says_stop (struct breakpoint
*);
306 /* If a method with name METHOD_NAME is to be invoked on an object of type
307 TYPE, then all extension languages are searched for implementations of
308 methods with name METHOD_NAME. All matches found are appended to the WORKERS
311 extern void get_matching_xmethod_workers
312 (struct type
*type
, const char *method_name
,
313 std::vector
<xmethod_worker_up
> *workers
);
315 #endif /* EXTENSION_H */