1 /* Interface between gdb and its extension languages.
3 Copyright (C) 2014-2023 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/>. */
20 /* Note: With few exceptions, external functions and variables in this file
21 have "ext_lang" in the name, and no other symbol in gdb does. */
26 #include "auto-load.h"
27 #include "breakpoint.h"
28 #include "event-top.h"
29 #include "extension.h"
30 #include "extension-priv.h"
31 #include "observable.h"
32 #include "cli/cli-script.h"
33 #include "python/python.h"
34 #include "guile/guile.h"
38 static script_sourcer_func source_gdb_script
;
39 static objfile_script_sourcer_func source_gdb_objfile_script
;
41 /* GDB's own scripting language.
42 This exists, in part, to support auto-loading ${prog}-gdb.gdb scripts. */
44 static const struct extension_language_script_ops
45 extension_language_gdb_script_ops
=
48 source_gdb_objfile_script
,
49 NULL
, /* objfile_script_executor */
50 auto_load_gdb_scripts_enabled
53 const struct extension_language_defn extension_language_gdb
=
59 /* We fall back to interpreting a script as a GDB script if it doesn't
60 match the other scripting languages, but for consistency's sake
61 give it a formal suffix. */
65 /* cli_control_type: This is never used: GDB's own scripting language
66 has a variety of control types (if, while, etc.). */
69 &extension_language_gdb_script_ops
,
71 /* The rest of the extension language interface isn't supported by GDB's own
72 extension/scripting language. */
76 /* NULL-terminated table of all external (non-native) extension languages.
78 The order of appearance in the table is important.
79 When multiple extension languages provide the same feature, for example
80 a pretty-printer for a particular type, which one gets used?
81 The algorithm employed here is "the first one wins". For example, in
82 the case of pretty-printers this means the first one to provide a
83 pretty-printed value is the one that is used. This algorithm is employed
86 static const std::array
<const extension_language_defn
*, 2> extension_languages
88 /* To preserve existing behaviour, python should always appear first. */
89 &extension_language_python
,
90 &extension_language_guile
,
93 /* Return a pointer to the struct extension_language_defn object of
94 extension language LANG.
95 This always returns a non-NULL pointer, even if support for the language
96 is not compiled into this copy of GDB. */
98 const struct extension_language_defn
*
99 get_ext_lang_defn (enum extension_language lang
)
101 gdb_assert (lang
!= EXT_LANG_NONE
);
103 if (lang
== EXT_LANG_GDB
)
104 return &extension_language_gdb
;
106 for (const struct extension_language_defn
*extlang
: extension_languages
)
108 if (extlang
->language
== lang
)
112 gdb_assert_not_reached ("unable to find extension_language_defn");
115 /* Return TRUE if FILE has extension EXTENSION. */
118 has_extension (const char *file
, const char *extension
)
120 int file_len
= strlen (file
);
121 int extension_len
= strlen (extension
);
123 return (file_len
> extension_len
124 && strcmp (&file
[file_len
- extension_len
], extension
) == 0);
127 /* Return the extension language of FILE, or NULL if
128 the extension language of FILE is not recognized.
129 This is done by looking at the file's suffix. */
131 const struct extension_language_defn
*
132 get_ext_lang_of_file (const char *file
)
134 if (has_extension (file
, extension_language_gdb
.suffix
))
135 return &extension_language_gdb
;
137 for (const struct extension_language_defn
*extlang
: extension_languages
)
139 if (has_extension (file
, extlang
->suffix
))
146 /* Return non-zero if support for the specified extension language
150 ext_lang_present_p (const struct extension_language_defn
*extlang
)
152 return extlang
->script_ops
!= NULL
;
155 /* Return non-zero if the specified extension language has successfully
159 ext_lang_initialized_p (const struct extension_language_defn
*extlang
)
161 if (extlang
->ops
!= NULL
)
163 /* This method is required. */
164 gdb_assert (extlang
->ops
->initialized
!= NULL
);
165 return extlang
->ops
->initialized (extlang
);
171 /* Throw an error indicating EXTLANG is not supported in this copy of GDB. */
174 throw_ext_lang_unsupported (const struct extension_language_defn
*extlang
)
176 error (_("Scripting in the \"%s\" language is not supported"
177 " in this copy of GDB."),
178 ext_lang_capitalized_name (extlang
));
181 /* Methods for GDB's own extension/scripting language. */
183 /* The extension_language_script_ops.script_sourcer "method". */
186 source_gdb_script (const struct extension_language_defn
*extlang
,
187 FILE *stream
, const char *file
)
189 script_from_file (stream
, file
);
192 /* The extension_language_script_ops.objfile_script_sourcer "method". */
195 source_gdb_objfile_script (const struct extension_language_defn
*extlang
,
196 struct objfile
*objfile
,
197 FILE *stream
, const char *file
)
199 script_from_file (stream
, file
);
202 /* Accessors for "public" attributes of struct extension_language. */
204 /* Return the "name" field of EXTLANG. */
207 ext_lang_name (const struct extension_language_defn
*extlang
)
209 return extlang
->name
;
212 /* Return the "capitalized_name" field of EXTLANG. */
215 ext_lang_capitalized_name (const struct extension_language_defn
*extlang
)
217 return extlang
->capitalized_name
;
220 /* Return the "suffix" field of EXTLANG. */
223 ext_lang_suffix (const struct extension_language_defn
*extlang
)
225 return extlang
->suffix
;
228 /* Return the "auto_load_suffix" field of EXTLANG. */
231 ext_lang_auto_load_suffix (const struct extension_language_defn
*extlang
)
233 return extlang
->auto_load_suffix
;
236 /* extension_language_script_ops wrappers. */
238 /* Return the script "sourcer" function for EXTLANG.
239 This is the function that loads and processes a script.
240 If support for this language isn't compiled in, NULL is returned. */
242 script_sourcer_func
*
243 ext_lang_script_sourcer (const struct extension_language_defn
*extlang
)
245 if (extlang
->script_ops
== NULL
)
248 /* The extension language is required to implement this function. */
249 gdb_assert (extlang
->script_ops
->script_sourcer
!= NULL
);
251 return extlang
->script_ops
->script_sourcer
;
254 /* Return the objfile script "sourcer" function for EXTLANG.
255 This is the function that loads and processes a script for a particular
257 If support for this language isn't compiled in, NULL is returned. */
259 objfile_script_sourcer_func
*
260 ext_lang_objfile_script_sourcer (const struct extension_language_defn
*extlang
)
262 if (extlang
->script_ops
== NULL
)
265 /* The extension language is required to implement this function. */
266 gdb_assert (extlang
->script_ops
->objfile_script_sourcer
!= NULL
);
268 return extlang
->script_ops
->objfile_script_sourcer
;
271 /* Return the objfile script "executor" function for EXTLANG.
272 This is the function that executes a script for a particular objfile.
273 If support for this language isn't compiled in, NULL is returned.
274 The extension language is not required to implement this function. */
276 objfile_script_executor_func
*
277 ext_lang_objfile_script_executor
278 (const struct extension_language_defn
*extlang
)
280 if (extlang
->script_ops
== NULL
)
283 return extlang
->script_ops
->objfile_script_executor
;
286 /* See extension.h. */
289 ext_lang_auto_load_enabled (const struct extension_language_defn
*extlang
)
291 if (extlang
->script_ops
== NULL
)
294 /* The extension language is required to implement this function. */
295 gdb_assert (extlang
->script_ops
->auto_load_enabled
!= NULL
);
297 return extlang
->script_ops
->auto_load_enabled (extlang
);
301 /* RAII class used to temporarily return SIG to its default handler. */
304 struct scoped_default_signal
306 scoped_default_signal ()
307 { m_old_sig_handler
= signal (SIG
, SIG_DFL
); }
309 ~scoped_default_signal ()
310 { signal (SIG
, m_old_sig_handler
); }
312 DISABLE_COPY_AND_ASSIGN (scoped_default_signal
);
315 /* The previous signal handler that needs to be restored. */
316 sighandler_t m_old_sig_handler
;
319 /* Class to temporarily return SIGINT to its default handler. */
321 using scoped_default_sigint
= scoped_default_signal
<SIGINT
>;
323 /* Functions that iterate over all extension languages.
324 These only iterate over external extension languages, not including
325 GDB's own extension/scripting language, unless otherwise indicated. */
327 /* Wrapper to call the extension_language_ops.initialize "method" for each
328 compiled-in extension language. */
331 ext_lang_initialization (void)
333 for (const struct extension_language_defn
*extlang
: extension_languages
)
335 if (extlang
->ops
!= nullptr
336 && extlang
->ops
->initialize
!= NULL
)
338 scoped_default_sigint set_sigint_to_default_handler
;
339 extlang
->ops
->initialize (extlang
);
344 /* Invoke the appropriate extension_language_ops.eval_from_control_command
345 method to perform CMD, which is a list of commands in an extension language.
347 This function is what implements, for example:
356 eval_ext_lang_from_control_command (struct command_line
*cmd
)
358 for (const struct extension_language_defn
*extlang
: extension_languages
)
360 if (extlang
->cli_control_type
== cmd
->control_type
)
362 if (extlang
->ops
!= NULL
363 && extlang
->ops
->eval_from_control_command
!= NULL
)
365 extlang
->ops
->eval_from_control_command (extlang
, cmd
);
368 /* The requested extension language is not supported in this GDB. */
369 throw_ext_lang_unsupported (extlang
);
373 gdb_assert_not_reached ("unknown extension language in command_line");
376 /* Search for and load scripts for OBJFILE written in extension languages.
377 This includes GDB's own scripting language.
379 This function is what implements the loading of OBJFILE-gdb.py and
383 auto_load_ext_lang_scripts_for_objfile (struct objfile
*objfile
)
385 const struct extension_language_defn
*gdb
= &extension_language_gdb
;
386 if (ext_lang_auto_load_enabled (gdb
))
387 auto_load_objfile_script (objfile
, gdb
);
389 for (const struct extension_language_defn
*extlang
: extension_languages
)
391 if (extlang
->ops
!= nullptr
392 && ext_lang_auto_load_enabled (extlang
))
393 auto_load_objfile_script (objfile
, extlang
);
397 /* Interface to type pretty-printers implemented in an extension language. */
399 /* Call this at the start when preparing to pretty-print a type.
400 The result is a pointer to an opaque object (to the caller) to be passed
401 to apply_ext_lang_type_printers and free_ext_lang_type_printers.
403 We don't know in advance which extension language will provide a
404 pretty-printer for the type, so all are initialized. */
406 ext_lang_type_printers::ext_lang_type_printers ()
408 for (const struct extension_language_defn
*extlang
: extension_languages
)
410 if (extlang
->ops
!= nullptr
411 && extlang
->ops
->start_type_printers
!= NULL
)
412 extlang
->ops
->start_type_printers (extlang
, this);
416 /* Iteratively try the type pretty-printers specified by PRINTERS
417 according to the standard search order (specified by extension_languages),
418 returning the result of the first one that succeeds.
419 If there was an error, or if no printer succeeds, then NULL is returned. */
422 apply_ext_lang_type_printers (struct ext_lang_type_printers
*printers
,
425 for (const struct extension_language_defn
*extlang
: extension_languages
)
430 if (extlang
->ops
== nullptr
431 || extlang
->ops
->apply_type_printers
== NULL
)
433 rc
= extlang
->ops
->apply_type_printers (extlang
, printers
, type
,
438 gdb_assert (result
!= NULL
);
440 case EXT_LANG_RC_ERROR
:
442 case EXT_LANG_RC_NOP
:
445 gdb_assert_not_reached ("bad return from apply_type_printers");
452 ext_lang_type_printers::~ext_lang_type_printers ()
454 for (const struct extension_language_defn
*extlang
: extension_languages
)
456 if (extlang
->ops
!= nullptr
457 && extlang
->ops
->free_type_printers
!= NULL
)
458 extlang
->ops
->free_type_printers (extlang
, this);
462 /* Try to pretty-print a value onto stdio stream STREAM according to
463 OPTIONS. VAL is the object to print. Returns non-zero if the
464 value was successfully pretty-printed.
466 Extension languages are tried in the order specified by
467 extension_languages. The first one to provide a pretty-printed
470 If an error is encountered in a pretty-printer, no further extension
472 Note: This is different than encountering a memory error trying to read a
473 value for pretty-printing. Here we're referring to, e.g., programming
474 errors that trigger an exception in the extension language. */
477 apply_ext_lang_val_pretty_printer (struct value
*val
,
478 struct ui_file
*stream
, int recurse
,
479 const struct value_print_options
*options
,
480 const struct language_defn
*language
)
482 for (const struct extension_language_defn
*extlang
: extension_languages
)
486 if (extlang
->ops
== nullptr
487 || extlang
->ops
->apply_val_pretty_printer
== NULL
)
489 rc
= extlang
->ops
->apply_val_pretty_printer (extlang
, val
, stream
,
490 recurse
, options
, language
);
495 case EXT_LANG_RC_ERROR
:
497 case EXT_LANG_RC_NOP
:
500 gdb_assert_not_reached ("bad return from apply_val_pretty_printer");
507 /* GDB access to the "frame filter" feature.
508 FRAME is the source frame to start frame-filter invocation. FLAGS is an
509 integer holding the flags for printing. The following elements of
510 the FRAME_FILTER_FLAGS enum denotes the make-up of FLAGS:
511 PRINT_LEVEL is a flag indicating whether to print the frame's
512 relative level in the output. PRINT_FRAME_INFO is a flag that
513 indicates whether this function should print the frame
514 information, PRINT_ARGS is a flag that indicates whether to print
515 frame arguments, and PRINT_LOCALS, likewise, with frame local
516 variables. ARGS_TYPE is an enumerator describing the argument
517 format, OUT is the output stream to print. FRAME_LOW is the
518 beginning of the slice of frames to print, and FRAME_HIGH is the
519 upper limit of the frames to count. Returns EXT_LANG_BT_ERROR on error,
520 or EXT_LANG_BT_COMPLETED on success.
522 Extension languages are tried in the order specified by
523 extension_languages. The first one to provide a filter "wins".
524 If there is an error (EXT_LANG_BT_ERROR) it is reported immediately
525 rather than trying filters in other extension languages. */
527 enum ext_lang_bt_status
528 apply_ext_lang_frame_filter (frame_info_ptr frame
,
529 frame_filter_flags flags
,
530 enum ext_lang_frame_args args_type
,
532 int frame_low
, int frame_high
)
534 for (const struct extension_language_defn
*extlang
: extension_languages
)
536 enum ext_lang_bt_status status
;
538 if (extlang
->ops
== nullptr
539 || extlang
->ops
->apply_frame_filter
== NULL
)
541 status
= extlang
->ops
->apply_frame_filter (extlang
, frame
, flags
,
543 frame_low
, frame_high
);
544 /* We use the filters from the first extension language that has
545 applicable filters. Also, an error is reported immediately
546 rather than continue trying. */
547 if (status
!= EXT_LANG_BT_NO_FILTERS
)
551 return EXT_LANG_BT_NO_FILTERS
;
554 /* Update values held by the extension language when OBJFILE is discarded.
555 New global types must be created for every such value, which must then be
556 updated to use the new types.
557 The function typically just iterates over all appropriate values and
558 calls preserve_one_value for each one.
559 COPIED_TYPES is used to prevent cycles / duplicates and is passed to
560 preserve_one_value. */
563 preserve_ext_lang_values (struct objfile
*objfile
, htab_t copied_types
)
565 for (const struct extension_language_defn
*extlang
: extension_languages
)
567 if (extlang
->ops
!= nullptr
568 && extlang
->ops
->preserve_values
!= NULL
)
569 extlang
->ops
->preserve_values (extlang
, objfile
, copied_types
);
573 /* If there is a stop condition implemented in an extension language for
574 breakpoint B, return a pointer to the extension language's definition.
575 Otherwise return NULL.
576 If SKIP_LANG is not EXT_LANG_NONE, skip checking this language.
577 This is for the case where we're setting a new condition: Only one
578 condition is allowed, so when setting a condition for any particular
579 extension language, we need to check if any other extension language
580 already has a condition set. */
582 const struct extension_language_defn
*
583 get_breakpoint_cond_ext_lang (struct breakpoint
*b
,
584 enum extension_language skip_lang
)
586 for (const struct extension_language_defn
*extlang
: extension_languages
)
588 if (extlang
->ops
!= nullptr
589 && extlang
->language
!= skip_lang
590 && extlang
->ops
->breakpoint_has_cond
!= NULL
591 && extlang
->ops
->breakpoint_has_cond (extlang
, b
))
598 /* Return whether a stop condition for breakpoint B says to stop.
599 True is also returned if there is no stop condition for B. */
602 breakpoint_ext_lang_cond_says_stop (struct breakpoint
*b
)
604 enum ext_lang_bp_stop stop
= EXT_LANG_BP_STOP_UNSET
;
606 for (const struct extension_language_defn
*extlang
: extension_languages
)
608 /* There is a rule that a breakpoint can have at most one of any of a
609 CLI or extension language condition. However, Python hacks in "finish
610 breakpoints" on top of the "stop" check, so we have to call this for
611 every language, even if we could first determine whether a "stop"
613 if (extlang
->ops
!= nullptr
614 && extlang
->ops
->breakpoint_cond_says_stop
!= NULL
)
616 enum ext_lang_bp_stop this_stop
617 = extlang
->ops
->breakpoint_cond_says_stop (extlang
, b
);
619 if (this_stop
!= EXT_LANG_BP_STOP_UNSET
)
621 /* Even though we have to check every extension language, only
622 one of them can return yes/no (because only one of them
623 can have a "stop" condition). */
624 gdb_assert (stop
== EXT_LANG_BP_STOP_UNSET
);
630 return stop
!= EXT_LANG_BP_STOP_NO
;
633 /* ^C/SIGINT support.
634 This requires cooperation with the extension languages so the support
637 /* This flag tracks quit requests when we haven't called out to an
638 extension language. it also holds quit requests when we transition to
639 an extension language that doesn't have cooperative SIGINT handling. */
640 static int quit_flag
;
642 /* The current extension language we've called out to, or
643 extension_language_gdb if there isn't one.
644 This must be set everytime we call out to an extension language, and reset
645 to the previous value when it returns. Note that the previous value may
646 be a different (or the same) extension language. */
647 static const struct extension_language_defn
*active_ext_lang
648 = &extension_language_gdb
;
650 /* Install a SIGINT handler. */
653 install_ext_sigint_handler (const struct signal_handler
*handler_state
)
655 gdb_assert (handler_state
->handler_saved
);
657 install_sigint_handler (handler_state
->handler
);
660 /* Install GDB's SIGINT handler, storing the previous version in *PREVIOUS.
661 As a simple optimization, if the previous version was GDB's SIGINT handler
662 then mark the previous handler as not having been saved, and thus it won't
666 install_gdb_sigint_handler (struct signal_handler
*previous
)
668 /* Save here to simplify comparison. */
669 sighandler_t handle_sigint_for_compare
= handle_sigint
;
671 previous
->handler
= install_sigint_handler (handle_sigint
);
672 if (previous
->handler
!= handle_sigint_for_compare
)
673 previous
->handler_saved
= 1;
675 previous
->handler_saved
= 0;
679 namespace selftests
{
680 void (*hook_set_active_ext_lang
) () = nullptr;
684 /* Set the currently active extension language to NOW_ACTIVE.
685 The result is a pointer to a malloc'd block of memory to pass to
686 restore_active_ext_lang.
688 N.B. This function must be called every time we call out to an extension
689 language, and the result must be passed to restore_active_ext_lang
692 If there is a pending SIGINT it is "moved" to the now active extension
693 language, if it supports cooperative SIGINT handling (i.e., it provides
694 {clear,set,check}_quit_flag methods). If the extension language does not
695 support cooperative SIGINT handling, then the SIGINT is left queued and
696 we require the non-cooperative extension language to call check_quit_flag
697 at appropriate times.
698 It is important for the extension language to call check_quit_flag if it
699 installs its own SIGINT handler to prevent the situation where a SIGINT
700 is queued on entry, extension language code runs for a "long" time possibly
701 serving one or more SIGINTs, and then returns. Upon return, if
702 check_quit_flag is not called, the original SIGINT will be thrown.
703 Non-cooperative extension languages are free to install their own SIGINT
704 handler but the original must be restored upon return, either itself
705 or via restore_active_ext_lang. */
707 struct active_ext_lang_state
*
708 set_active_ext_lang (const struct extension_language_defn
*now_active
)
711 if (selftests::hook_set_active_ext_lang
)
712 selftests::hook_set_active_ext_lang ();
715 struct active_ext_lang_state
*previous
716 = XCNEW (struct active_ext_lang_state
);
718 previous
->ext_lang
= active_ext_lang
;
719 previous
->sigint_handler
.handler_saved
= 0;
720 active_ext_lang
= now_active
;
722 if (target_terminal::is_ours ())
724 /* If the newly active extension language uses cooperative SIGINT
725 handling then ensure GDB's SIGINT handler is installed. */
726 if (now_active
->language
== EXT_LANG_GDB
727 || now_active
->ops
->check_quit_flag
!= NULL
)
728 install_gdb_sigint_handler (&previous
->sigint_handler
);
730 /* If there's a SIGINT recorded in the cooperative extension languages,
731 move it to the new language, or save it in GDB's global flag if the
732 newly active extension language doesn't use cooperative SIGINT
734 if (check_quit_flag ())
741 /* Restore active extension language from PREVIOUS. */
744 restore_active_ext_lang (struct active_ext_lang_state
*previous
)
746 active_ext_lang
= previous
->ext_lang
;
748 if (target_terminal::is_ours ())
750 /* Restore the previous SIGINT handler if one was saved. */
751 if (previous
->sigint_handler
.handler_saved
)
752 install_ext_sigint_handler (&previous
->sigint_handler
);
754 /* If there's a SIGINT recorded in the cooperative extension languages,
755 move it to the new language, or save it in GDB's global flag if the
756 newly active extension language doesn't use cooperative SIGINT
758 if (check_quit_flag ())
764 /* Set the quit flag.
765 This only sets the flag in the currently active extension language.
766 If the currently active extension language does not have cooperative
767 SIGINT handling, then GDB's global flag is set, and it is up to the
768 extension language to call check_quit_flag. The extension language
769 is free to install its own SIGINT handler, but we still need to handle
775 if (active_ext_lang
->ops
!= NULL
776 && active_ext_lang
->ops
->set_quit_flag
!= NULL
)
777 active_ext_lang
->ops
->set_quit_flag (active_ext_lang
);
782 /* Now wake up the event loop, or any interruptible_select. Do
783 this after setting the flag, because signals on Windows
784 actually run on a separate thread, and thus otherwise the
785 main code could be woken up and find quit_flag still
787 quit_serial_event_set ();
791 /* Return true if the quit flag has been set, false otherwise.
792 Note: The flag is cleared as a side-effect.
793 The flag is checked in all extension languages that support cooperative
794 SIGINT handling, not just the current one. This simplifies transitions. */
797 check_quit_flag (void)
801 for (const struct extension_language_defn
*extlang
: extension_languages
)
803 if (extlang
->ops
!= nullptr
804 && extlang
->ops
->check_quit_flag
!= NULL
)
805 if (extlang
->ops
->check_quit_flag (extlang
) != 0)
809 /* This is written in a particular way to avoid races. */
812 /* No longer need to wake up the event loop or any
813 interruptible_select. The caller handles the quit
815 quit_serial_event_clear ();
823 /* See extension.h. */
826 get_matching_xmethod_workers (struct type
*type
, const char *method_name
,
827 std::vector
<xmethod_worker_up
> *workers
)
829 for (const struct extension_language_defn
*extlang
: extension_languages
)
833 /* If an extension language does not support xmethods, ignore
835 if (extlang
->ops
== nullptr
836 || extlang
->ops
->get_matching_xmethod_workers
== NULL
)
839 rc
= extlang
->ops
->get_matching_xmethod_workers (extlang
,
842 if (rc
== EXT_LANG_RC_ERROR
)
843 error (_("Error while looking for matching xmethod workers "
844 "defined in %s."), extlang
->capitalized_name
);
848 /* See extension.h. */
851 xmethod_worker::get_arg_types ()
853 std::vector
<type
*> type_array
;
855 ext_lang_rc rc
= do_get_arg_types (&type_array
);
856 if (rc
== EXT_LANG_RC_ERROR
)
857 error (_("Error while looking for arg types of a xmethod worker "
858 "defined in %s."), m_extlang
->capitalized_name
);
863 /* See extension.h. */
866 xmethod_worker::get_result_type (value
*object
, gdb::array_view
<value
*> args
)
870 ext_lang_rc rc
= do_get_result_type (object
, args
, &result_type
);
871 if (rc
== EXT_LANG_RC_ERROR
)
873 error (_("Error while fetching result type of an xmethod worker "
874 "defined in %s."), m_extlang
->capitalized_name
);
880 /* See extension.h. */
882 gdb::optional
<std::string
>
883 ext_lang_colorize (const std::string
&filename
, const std::string
&contents
)
885 gdb::optional
<std::string
> result
;
887 for (const struct extension_language_defn
*extlang
: extension_languages
)
889 if (extlang
->ops
== nullptr
890 || extlang
->ops
->colorize
== nullptr)
892 result
= extlang
->ops
->colorize (filename
, contents
);
893 if (result
.has_value ())
900 /* See extension.h. */
902 gdb::optional
<std::string
>
903 ext_lang_colorize_disasm (const std::string
&content
, gdbarch
*gdbarch
)
905 gdb::optional
<std::string
> result
;
907 for (const struct extension_language_defn
*extlang
: extension_languages
)
909 if (extlang
->ops
== nullptr
910 || extlang
->ops
->colorize_disasm
== nullptr)
912 result
= extlang
->ops
->colorize_disasm (content
, gdbarch
);
913 if (result
.has_value ())
920 /* See extension.h. */
923 ext_lang_print_insn (struct gdbarch
*gdbarch
, CORE_ADDR address
,
924 struct disassemble_info
*info
)
926 for (const struct extension_language_defn
*extlang
: extension_languages
)
928 if (extlang
->ops
== nullptr
929 || extlang
->ops
->print_insn
== nullptr)
931 gdb::optional
<int> length
932 = extlang
->ops
->print_insn (gdbarch
, address
, info
);
933 if (length
.has_value ())
940 /* Called via an observer before gdb prints its prompt.
941 Iterate over the extension languages giving them a chance to
942 change the prompt. The first one to change the prompt wins,
943 and no further languages are tried. */
946 ext_lang_before_prompt (const char *current_gdb_prompt
)
948 for (const struct extension_language_defn
*extlang
: extension_languages
)
952 if (extlang
->ops
== nullptr
953 || extlang
->ops
->before_prompt
== NULL
)
955 rc
= extlang
->ops
->before_prompt (extlang
, current_gdb_prompt
);
959 case EXT_LANG_RC_ERROR
:
961 case EXT_LANG_RC_NOP
:
964 gdb_assert_not_reached ("bad return from before_prompt");
969 void _initialize_extension ();
971 _initialize_extension ()
973 gdb::observers::before_prompt
.attach (ext_lang_before_prompt
, "extension");