GDB (xrefs)
Loading...
Searching...
No Matches
extension.h
Go to the documentation of this file.
1/* Interface between gdb and its extension languages.
2
3 Copyright (C) 2014-2023 Free Software Foundation, Inc.
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"
24#include "gdbsupport/array-view.h"
25#include "gdbsupport/gdb_optional.h"
26
27struct breakpoint;
28struct command_line;
29class frame_info_ptr;
30struct language_defn;
31struct objfile;
33struct type;
34struct ui_file;
35struct ui_out;
36struct value;
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. */
49 (const struct extension_language_defn *,
50 struct objfile *, FILE *stream, const char *filename);
51
52/* A function to execute a script for an objfile.
53 Any exceptions are not caught, and are passed to the caller. */
55 (const struct extension_language_defn *,
56 struct objfile *, const char *name, const char *script);
57
58/* Enum of each extension(/scripting) language. */
59
67
68/* Extension language frame-filter status return values. */
69
71 {
72 /* Return when an error has occurred in processing frame filters,
73 or when printing the stack. */
75
76 /* Return from internal routines to indicate that the function
77 succeeded. */
79
80 /* Return when the frame filter process is complete, but there
81 were no filter registered and enabled to process. */
83 };
84
85/* Flags to pass to apply_extlang_frame_filter. */
86
88 {
89 /* Set this flag if frame level is to be printed. */
90 PRINT_LEVEL = 1 << 0,
91
92 /* Set this flag if frame information is to be printed. */
94
95 /* Set this flag if frame arguments are to be printed. */
96 PRINT_ARGS = 1 << 2,
97
98 /* Set this flag if frame locals are to be printed. */
99 PRINT_LOCALS = 1 << 3,
100
101 /* Set this flag if a "More frames" message is to be printed. */
103
104 /* Set this flag if elided frames should not be printed. */
105 PRINT_HIDE = 1 << 5,
106 };
107
108DEF_ENUM_FLAGS_TYPE (enum frame_filter_flag, frame_filter_flags);
109
110/* A choice of the different frame argument printing strategies that
111 can occur in different cases of frame filter instantiation. */
112
114 {
115 /* Print no values for arguments when invoked from the MI. */
117
119
120 /* Print only simple values (what MI defines as "simple") for
121 arguments when invoked from the MI. */
123
124 /* Print only scalar values for arguments when invoked from the CLI. */
126
127 /* Print all values for arguments when invoked from the CLI. */
129
130 /* Only indicate the presence of arguments when invoked from the CLI. */
132 };
133
134/* The possible results of
135 extension_language_ops.breakpoint_cond_says_stop. */
136
138 {
139 /* No "stop" condition is set. */
141
142 /* A "stop" condition is set, and it says "don't stop". */
144
145 /* A "stop" condition is set, and it says "stop". */
147 };
148
149/* Table of type printers associated with the global typedef table. */
150
152{
155
157
158 /* Type-printers from Python. */
159 void *py_type_printers = nullptr;
160};
161
162/* The return code for some API calls. */
163
165{
166 /* The operation completed successfully. */
168
169 /* The operation was not performed (e.g., no pretty-printer). */
171
172 /* There was an error (e.g., Python error while printing a value).
173 When an error occurs no further extension languages are tried.
174 This is to preserve existing behaviour, and because it's convenient
175 for Python developers.
176 Note: This is different than encountering a memory error trying to read
177 a value for pretty-printing. Here we're referring to, e.g., programming
178 errors that trigger an exception in the extension language. */
181
182/* A type which holds its extension language specific xmethod worker data. */
183
185{
187 : m_extlang (extlang)
188 {}
189
190 virtual ~xmethod_worker () = default;
191
192 /* Invoke the xmethod encapsulated in this worker and return the result.
193 The method is invoked on OBJ with arguments in the ARGS array. */
194
195 virtual value *invoke (value *obj, gdb::array_view<value *> args) = 0;
196
197 /* Return the arg types of the xmethod encapsulated in this worker.
198 The type of the 'this' object is returned as the first element of
199 the vector. */
200
201 std::vector<type *> get_arg_types ();
202
203 /* Return the type of the result of the xmethod encapsulated in this worker.
204 OBJECT and ARGS are the same as for invoke. */
205
206 type *get_result_type (value *object, gdb::array_view<value *> args);
207
208private:
209
210 /* Return the types of the arguments the method takes. The types
211 are returned in TYPE_ARGS, one per argument. */
212
214 (std::vector<type *> *type_args) = 0;
215
216 /* Fetch the type of the result of the method implemented by this
217 worker. OBJECT and ARGS are the same as for the invoked method.
218 The result type is stored in *RESULT_TYPE. */
219
221 (struct value *obj, gdb::array_view<value *> args,
222 struct type **result_type_ptr) = 0;
223
224 /* The language the xmethod worker is implemented in. */
225
227};
228
229typedef std::unique_ptr<xmethod_worker> xmethod_worker_up;
230
231/* The interface for gdb's own extension(/scripting) language. */
233
235 (enum extension_language lang);
236
238 (const char *file);
239
240extern int ext_lang_present_p (const struct extension_language_defn *);
241
242extern int ext_lang_initialized_p (const struct extension_language_defn *);
243
245 (const struct extension_language_defn *);
246
247/* Accessors for "public" attributes of the extension language definition. */
248
250 (const struct extension_language_defn *);
251
252extern const char *ext_lang_name (const struct extension_language_defn *);
253
254extern const char *ext_lang_capitalized_name
255 (const struct extension_language_defn *);
256
257extern const char *ext_lang_suffix (const struct extension_language_defn *);
258
259extern const char *ext_lang_auto_load_suffix
260 (const struct extension_language_defn *);
261
263 (const struct extension_language_defn *);
264
266 (const struct extension_language_defn *);
267
269 (const struct extension_language_defn *);
270
271/* Return true if auto-loading of EXTLANG scripts is enabled.
272 False is returned if support for this language isn't compiled in. */
273
274extern bool ext_lang_auto_load_enabled (const struct extension_language_defn *);
275
276/* Wrappers for each extension language API function that iterate over all
277 extension languages. */
278
279extern void ext_lang_initialization (void);
280
281extern void eval_ext_lang_from_control_command (struct command_line *cmd);
282
284
285extern gdb::unique_xmalloc_ptr<char> apply_ext_lang_type_printers
286 (struct ext_lang_type_printers *, struct type *);
287
289 (struct value *value, struct ui_file *stream, int recurse,
290 const struct value_print_options *options,
291 const struct language_defn *language);
292
294 (frame_info_ptr frame, frame_filter_flags flags,
295 enum ext_lang_frame_args args_type,
296 struct ui_out *out, int frame_low, int frame_high);
297
298extern void preserve_ext_lang_values (struct objfile *, htab_t copied_types);
299
301 (struct breakpoint *b, enum extension_language skip_lang);
302
304
305/* If a method with name METHOD_NAME is to be invoked on an object of type
306 TYPE, then all extension languages are searched for implementations of
307 methods with name METHOD_NAME. All matches found are appended to the WORKERS
308 vector. */
309
311 (struct type *type, const char *method_name,
312 std::vector<xmethod_worker_up> *workers);
313
314/* Try to colorize some source code. FILENAME is the name of the file
315 holding the code. CONTENTS is the source code itself. This will
316 either a colorized (using ANSI terminal escapes) version of the
317 source code, or an empty value if colorizing could not be done. */
318
319extern gdb::optional<std::string> ext_lang_colorize
320 (const std::string &filename, const std::string &contents);
321
322/* Try to colorize a single line of disassembler output, CONTENT for
323 GDBARCH. This will return either a colorized (using ANSI terminal
324 escapes) version of CONTENT, or an empty value if colorizing could not
325 be done. */
326
327extern gdb::optional<std::string> ext_lang_colorize_disasm
328 (const std::string &content, gdbarch *gdbarch);
329
330/* Calls extension_language_ops::print_insn for each extension language,
331 returning the result from the first extension language that returns a
332 non-empty result (any further extension languages are not then called).
333
334 All arguments are forwarded to extension_language_ops::print_insn, see
335 that function for a full description. */
336
337extern gdb::optional<int> ext_lang_print_insn
338 (struct gdbarch *gdbarch, CORE_ADDR address, struct disassemble_info *info);
339
340#if GDB_SELF_TEST
341namespace selftests {
342extern void (*hook_set_active_ext_lang) ();
343}
344#endif
345
346/* Temporarily disable cooperative SIGINT handling. Needed when we
347 don't want a SIGINT to interrupt the currently active extension
348 language. */
361
362#endif /* EXTENSION_H */
const char *const name
DISABLE_COPY_AND_ASSIGN(scoped_disable_cooperative_sigint_handling)
struct active_ext_lang_state * m_prev_active_ext_lang_state
Definition extension.h:358
language
Definition defs.h:211
void throw_ext_lang_unsupported(const struct extension_language_defn *)
Definition extension.c:174
DEF_ENUM_FLAGS_TYPE(enum frame_filter_flag, frame_filter_flags)
gdb::unique_xmalloc_ptr< char > apply_ext_lang_type_printers(struct ext_lang_type_printers *, struct type *)
Definition extension.c:422
const char * ext_lang_capitalized_name(const struct extension_language_defn *)
Definition extension.c:215
bool breakpoint_ext_lang_cond_says_stop(struct breakpoint *)
Definition extension.c:602
void eval_ext_lang_from_control_command(struct command_line *cmd)
Definition extension.c:356
ext_lang_rc
Definition extension.h:165
@ EXT_LANG_RC_NOP
Definition extension.h:170
@ EXT_LANG_RC_OK
Definition extension.h:167
@ EXT_LANG_RC_ERROR
Definition extension.h:179
gdb::optional< int > ext_lang_print_insn(struct gdbarch *gdbarch, CORE_ADDR address, struct disassemble_info *info)
Definition extension.c:983
void ext_lang_initialization(void)
Definition extension.c:331
extension_language
Definition extension.h:61
@ EXT_LANG_NONE
Definition extension.h:62
@ EXT_LANG_PYTHON
Definition extension.h:64
@ EXT_LANG_GUILE
Definition extension.h:65
@ EXT_LANG_GDB
Definition extension.h:63
gdb::optional< std::string > ext_lang_colorize_disasm(const std::string &content, gdbarch *gdbarch)
Definition extension.c:963
bool ext_lang_auto_load_enabled(const struct extension_language_defn *)
Definition extension.c:289
void preserve_ext_lang_values(struct objfile *, htab_t copied_types)
Definition extension.c:563
script_sourcer_func * ext_lang_script_sourcer(const struct extension_language_defn *)
Definition extension.c:243
std::unique_ptr< xmethod_worker > xmethod_worker_up
Definition extension.h:229
const char * ext_lang_suffix(const struct extension_language_defn *)
Definition extension.c:223
const struct extension_language_defn extension_language_gdb
Definition extension.c:53
const struct extension_language_defn * get_breakpoint_cond_ext_lang(struct breakpoint *b, enum extension_language skip_lang)
Definition extension.c:583
const char * ext_lang_name(const struct extension_language_defn *)
Definition extension.c:207
const struct extension_language_defn * get_ext_lang_defn(enum extension_language lang)
Definition extension.c:99
int apply_ext_lang_val_pretty_printer(struct value *value, struct ui_file *stream, int recurse, const struct value_print_options *options, const struct language_defn *language)
Definition extension.c:477
void auto_load_ext_lang_scripts_for_objfile(struct objfile *)
Definition extension.c:383
const struct extension_language_defn * get_ext_lang_of_file(const char *file)
Definition extension.c:132
frame_filter_flag
Definition extension.h:88
@ PRINT_ARGS
Definition extension.h:96
@ PRINT_LOCALS
Definition extension.h:99
@ PRINT_MORE_FRAMES
Definition extension.h:102
@ PRINT_FRAME_INFO
Definition extension.h:93
@ PRINT_HIDE
Definition extension.h:105
@ PRINT_LEVEL
Definition extension.h:90
int ext_lang_present_p(const struct extension_language_defn *)
Definition extension.c:150
ext_lang_bt_status
Definition extension.h:71
@ EXT_LANG_BT_ERROR
Definition extension.h:74
@ EXT_LANG_BT_OK
Definition extension.h:78
@ EXT_LANG_BT_NO_FILTERS
Definition extension.h:82
void script_sourcer_func(const struct extension_language_defn *, FILE *stream, const char *filename)
Definition extension.h:42
enum ext_lang_bt_status apply_ext_lang_frame_filter(frame_info_ptr frame, frame_filter_flags flags, enum ext_lang_frame_args args_type, struct ui_out *out, int frame_low, int frame_high)
Definition extension.c:528
objfile_script_executor_func * ext_lang_objfile_script_executor(const struct extension_language_defn *)
Definition extension.c:278
void get_matching_xmethod_workers(struct type *type, const char *method_name, std::vector< xmethod_worker_up > *workers)
Definition extension.c:886
void objfile_script_sourcer_func(const struct extension_language_defn *, struct objfile *, FILE *stream, const char *filename)
Definition extension.h:49
gdb::optional< std::string > ext_lang_colorize(const std::string &filename, const std::string &contents)
Definition extension.c:943
ext_lang_frame_args
Definition extension.h:114
@ MI_PRINT_ALL_VALUES
Definition extension.h:118
@ MI_PRINT_SIMPLE_VALUES
Definition extension.h:122
@ CLI_PRESENCE
Definition extension.h:131
@ NO_VALUES
Definition extension.h:116
@ CLI_ALL_VALUES
Definition extension.h:128
@ CLI_SCALAR_VALUES
Definition extension.h:125
const char * ext_lang_auto_load_suffix(const struct extension_language_defn *)
Definition extension.c:231
ext_lang_bp_stop
Definition extension.h:138
@ EXT_LANG_BP_STOP_NO
Definition extension.h:143
@ EXT_LANG_BP_STOP_YES
Definition extension.h:146
@ EXT_LANG_BP_STOP_UNSET
Definition extension.h:140
int ext_lang_initialized_p(const struct extension_language_defn *)
Definition extension.c:159
void objfile_script_executor_func(const struct extension_language_defn *, struct objfile *, const char *name, const char *script)
Definition extension.h:55
enum extension_language ext_lang_kind(const struct extension_language_defn *)
objfile_script_sourcer_func * ext_lang_objfile_script_sourcer(const struct extension_language_defn *)
Definition extension.c:260
mach_port_t kern_return_t mach_port_t mach_msg_type_name_t msgportsPoly mach_port_t kern_return_t pid_t pid mach_port_t kern_return_t mach_port_t task mach_port_t kern_return_t int flags
Definition gnu-nat.c:1861
@ PRINT_SIMPLE_VALUES
Definition mi-cmds.h:32
@ PRINT_ALL_VALUES
Definition mi-cmds.h:31
@ PRINT_NO_VALUES
Definition mi-cmds.h:30
DISABLE_COPY_AND_ASSIGN(ext_lang_type_printers)
Definition value.h:130
virtual enum ext_lang_rc do_get_arg_types(std::vector< type * > *type_args)=0
std::vector< type * > get_arg_types()
Definition extension.c:911
const extension_language_defn * m_extlang
Definition extension.h:226
virtual enum ext_lang_rc do_get_result_type(struct value *obj, gdb::array_view< value * > args, struct type **result_type_ptr)=0
virtual value * invoke(value *obj, gdb::array_view< value * > args)=0
type * get_result_type(value *object, gdb::array_view< value * > args)
Definition extension.c:926
virtual ~xmethod_worker()=default
xmethod_worker(const extension_language_defn *extlang)
Definition extension.h:186