GDB (xrefs)
Loading...
Searching...
No Matches
extension.c
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/* 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. */
22
23#include "defs.h"
24#include <signal.h>
25#include "target.h"
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"
35#include <array>
36#include "inferior.h"
37
40
41/* GDB's own scripting language.
42 This exists, in part, to support auto-loading ${prog}-gdb.gdb scripts. */
43
44static const struct extension_language_script_ops
52
54{
56 "gdb",
57 "GDB",
58
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. */
62 ".gdb",
63 "-gdb.gdb",
64
65 /* cli_control_type: This is never used: GDB's own scripting language
66 has a variety of control types (if, while, etc.). */
68
70
71 /* The rest of the extension language interface isn't supported by GDB's own
72 extension/scripting language. */
73 NULL
74};
75
76/* NULL-terminated table of all external (non-native) extension languages.
77
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
84 throughout. */
85
86static const std::array<const extension_language_defn *, 2> extension_languages
87{
88 /* To preserve existing behaviour, python should always appear first. */
91};
92
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. */
97
98const struct extension_language_defn *
100{
101 gdb_assert (lang != EXT_LANG_NONE);
102
103 if (lang == EXT_LANG_GDB)
105
106 for (const struct extension_language_defn *extlang : extension_languages)
107 {
108 if (extlang->language == lang)
109 return extlang;
110 }
111
112 gdb_assert_not_reached ("unable to find extension_language_defn");
113}
114
115/* Return TRUE if FILE has extension EXTENSION. */
116
117static int
118has_extension (const char *file, const char *extension)
119{
120 int file_len = strlen (file);
121 int extension_len = strlen (extension);
122
123 return (file_len > extension_len
124 && strcmp (&file[file_len - extension_len], extension) == 0);
125}
126
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. */
130
131const struct extension_language_defn *
132get_ext_lang_of_file (const char *file)
133{
136
137 for (const struct extension_language_defn *extlang : extension_languages)
138 {
139 if (has_extension (file, extlang->suffix))
140 return extlang;
141 }
142
143 return NULL;
144}
145
146/* Return non-zero if support for the specified extension language
147 is compiled in. */
148
149int
151{
152 return extlang->script_ops != NULL;
153}
154
155/* Return non-zero if the specified extension language has successfully
156 initialized. */
157
158int
160{
161 if (extlang->ops != NULL)
162 {
163 /* This method is required. */
164 gdb_assert (extlang->ops->initialized != NULL);
165 return extlang->ops->initialized (extlang);
166 }
167
168 return 0;
169}
170
171/* Throw an error indicating EXTLANG is not supported in this copy of GDB. */
172
173void
175{
176 error (_("Scripting in the \"%s\" language is not supported"
177 " in this copy of GDB."),
178 ext_lang_capitalized_name (extlang));
179}
180
181/* Methods for GDB's own extension/scripting language. */
182
183/* The extension_language_script_ops.script_sourcer "method". */
184
185static void
187 FILE *stream, const char *file)
188{
189 script_from_file (stream, file);
190}
191
192/* The extension_language_script_ops.objfile_script_sourcer "method". */
193
194static void
196 struct objfile *objfile,
197 FILE *stream, const char *file)
198{
199 script_from_file (stream, file);
200}
201
202/* Accessors for "public" attributes of struct extension_language. */
203
204/* Return the "name" field of EXTLANG. */
205
206const char *
208{
209 return extlang->name;
210}
211
212/* Return the "capitalized_name" field of EXTLANG. */
213
214const char *
216{
217 return extlang->capitalized_name;
218}
219
220/* Return the "suffix" field of EXTLANG. */
221
222const char *
224{
225 return extlang->suffix;
226}
227
228/* Return the "auto_load_suffix" field of EXTLANG. */
229
230const char *
232{
233 return extlang->auto_load_suffix;
234}
235
236/* extension_language_script_ops wrappers. */
237
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. */
241
244{
245 if (extlang->script_ops == NULL)
246 return NULL;
247
248 /* The extension language is required to implement this function. */
249 gdb_assert (extlang->script_ops->script_sourcer != NULL);
250
251 return extlang->script_ops->script_sourcer;
252}
253
254/* Return the objfile script "sourcer" function for EXTLANG.
255 This is the function that loads and processes a script for a particular
256 objfile.
257 If support for this language isn't compiled in, NULL is returned. */
258
261{
262 if (extlang->script_ops == NULL)
263 return NULL;
264
265 /* The extension language is required to implement this function. */
266 gdb_assert (extlang->script_ops->objfile_script_sourcer != NULL);
267
268 return extlang->script_ops->objfile_script_sourcer;
269}
270
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. */
275
278 (const struct extension_language_defn *extlang)
279{
280 if (extlang->script_ops == NULL)
281 return NULL;
282
283 return extlang->script_ops->objfile_script_executor;
284}
285
286/* See extension.h. */
287
288bool
290{
291 if (extlang->script_ops == NULL)
292 return false;
293
294 /* The extension language is required to implement this function. */
295 gdb_assert (extlang->script_ops->auto_load_enabled != NULL);
296
297 return extlang->script_ops->auto_load_enabled (extlang);
298}
299
300
301/* RAII class used to temporarily return SIG to its default handler. */
302
303template<int SIG>
305{
307 { m_old_sig_handler = signal (SIG, SIG_DFL); }
308
310 { signal (SIG, m_old_sig_handler); }
311
313
314private:
315 /* The previous signal handler that needs to be restored. */
316 sighandler_t m_old_sig_handler;
317};
318
319/* Class to temporarily return SIGINT to its default handler. */
320
322
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. */
326
327/* Wrapper to call the extension_language_ops.initialize "method" for each
328 compiled-in extension language. */
329
330void
332{
333 for (const struct extension_language_defn *extlang : extension_languages)
334 {
335 if (extlang->ops != nullptr
336 && extlang->ops->initialize != NULL)
337 {
338 scoped_default_sigint set_sigint_to_default_handler;
339 extlang->ops->initialize (extlang);
340 }
341 }
342}
343
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.
346
347 This function is what implements, for example:
348
349 python
350 print 42
351 end
352
353 in a GDB script. */
354
355void
357{
358 for (const struct extension_language_defn *extlang : extension_languages)
359 {
360 if (extlang->cli_control_type == cmd->control_type)
361 {
362 if (extlang->ops != NULL
363 && extlang->ops->eval_from_control_command != NULL)
364 {
365 extlang->ops->eval_from_control_command (extlang, cmd);
366 return;
367 }
368 /* The requested extension language is not supported in this GDB. */
370 }
371 }
372
373 gdb_assert_not_reached ("unknown extension language in command_line");
374}
375
376/* Search for and load scripts for OBJFILE written in extension languages.
377 This includes GDB's own scripting language.
378
379 This function is what implements the loading of OBJFILE-gdb.py and
380 OBJFILE-gdb.gdb. */
381
382void
384{
388
389 for (const struct extension_language_defn *extlang : extension_languages)
390 {
391 if (extlang->ops != nullptr
392 && ext_lang_auto_load_enabled (extlang))
394 }
395}
396
397/* Interface to type pretty-printers implemented in an extension language. */
398
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.
402
403 We don't know in advance which extension language will provide a
404 pretty-printer for the type, so all are initialized. */
405
407{
408 for (const struct extension_language_defn *extlang : extension_languages)
409 {
410 if (extlang->ops != nullptr
411 && extlang->ops->start_type_printers != NULL)
412 extlang->ops->start_type_printers (extlang, this);
413 }
414}
415
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. */
420
421gdb::unique_xmalloc_ptr<char>
423 struct type *type)
424{
425 for (const struct extension_language_defn *extlang : extension_languages)
426 {
427 gdb::unique_xmalloc_ptr<char> result;
428 enum ext_lang_rc rc;
429
430 if (extlang->ops == nullptr
431 || extlang->ops->apply_type_printers == NULL)
432 continue;
433 rc = extlang->ops->apply_type_printers (extlang, printers, type,
434 &result);
435 switch (rc)
436 {
437 case EXT_LANG_RC_OK:
438 gdb_assert (result != nullptr);
439 return result;
441 return NULL;
442 case EXT_LANG_RC_NOP:
443 break;
444 default:
445 gdb_assert_not_reached ("bad return from apply_type_printers");
446 }
447 }
448
449 return NULL;
450}
451
453{
454 for (const struct extension_language_defn *extlang : extension_languages)
455 {
456 if (extlang->ops != nullptr
457 && extlang->ops->free_type_printers != NULL)
458 extlang->ops->free_type_printers (extlang, this);
459 }
460}
461
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.
465
466 Extension languages are tried in the order specified by
467 extension_languages. The first one to provide a pretty-printed
468 value "wins".
469
470 If an error is encountered in a pretty-printer, no further extension
471 languages are tried.
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. */
475
476int
478 struct ui_file *stream, int recurse,
479 const struct value_print_options *options,
480 const struct language_defn *language)
481{
482 for (const struct extension_language_defn *extlang : extension_languages)
483 {
484 enum ext_lang_rc rc;
485
486 if (extlang->ops == nullptr
487 || extlang->ops->apply_val_pretty_printer == NULL)
488 continue;
489 rc = extlang->ops->apply_val_pretty_printer (extlang, val, stream,
490 recurse, options, language);
491 switch (rc)
492 {
493 case EXT_LANG_RC_OK:
494 return 1;
496 return 0;
497 case EXT_LANG_RC_NOP:
498 break;
499 default:
500 gdb_assert_not_reached ("bad return from apply_val_pretty_printer");
501 }
502 }
503
504 return 0;
505}
506
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.
521
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. */
526
529 frame_filter_flags flags,
530 enum ext_lang_frame_args args_type,
531 struct ui_out *out,
532 int frame_low, int frame_high)
533{
534 for (const struct extension_language_defn *extlang : extension_languages)
535 {
537
538 if (extlang->ops == nullptr
539 || extlang->ops->apply_frame_filter == NULL)
540 continue;
541 status = extlang->ops->apply_frame_filter (extlang, frame, flags,
542 args_type, out,
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. */
548 return status;
549 }
550
552}
553
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. */
561
562void
563preserve_ext_lang_values (struct objfile *objfile, htab_t copied_types)
564{
565 for (const struct extension_language_defn *extlang : extension_languages)
566 {
567 if (extlang->ops != nullptr
568 && extlang->ops->preserve_values != NULL)
569 extlang->ops->preserve_values (extlang, objfile, copied_types);
570 }
571}
572
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. */
581
582const struct extension_language_defn *
584 enum extension_language skip_lang)
585{
586 for (const struct extension_language_defn *extlang : extension_languages)
587 {
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))
592 return extlang;
593 }
594
595 return NULL;
596}
597
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. */
600
601bool
603{
605
606 for (const struct extension_language_defn *extlang : extension_languages)
607 {
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"
612 method exists. */
613 if (extlang->ops != nullptr
614 && extlang->ops->breakpoint_cond_says_stop != NULL)
615 {
616 enum ext_lang_bp_stop this_stop
617 = extlang->ops->breakpoint_cond_says_stop (extlang, b);
618
619 if (this_stop != EXT_LANG_BP_STOP_UNSET)
620 {
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);
625 stop = this_stop;
626 }
627 }
628 }
629
630 return stop != EXT_LANG_BP_STOP_NO;
631}
632
633/* ^C/SIGINT support.
634 This requires cooperation with the extension languages so the support
635 is defined here. */
636
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. */
640static int quit_flag;
641
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. */
649
650/* Install a SIGINT handler. */
651
652static void
653install_ext_sigint_handler (const struct signal_handler *handler_state)
654{
655 gdb_assert (handler_state->handler_saved);
656
657 install_sigint_handler (handler_state->handler);
658}
659
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
663 be restored. */
664
665static void
667{
668 /* Save here to simplify comparison. */
669 sighandler_t handle_sigint_for_compare = handle_sigint;
670
672 if (previous->handler != handle_sigint_for_compare)
673 previous->handler_saved = 1;
674 else
675 previous->handler_saved = 0;
676}
677
678#if GDB_SELF_TEST
679namespace selftests {
680void (*hook_set_active_ext_lang) () = nullptr;
681}
682#endif
683
684/* True if cooperative SIGINT handling is disabled. This is needed so
685 that calls to set_active_ext_lang do not re-enable cooperative
686 handling, which if enabled would make set_quit_flag store the
687 SIGINT in an extension language. */
689
691{
692 /* Force the active extension language to the GDB scripting
693 language. This ensures that a previously saved SIGINT is moved
694 to the quit_flag global, as well as ensures that future SIGINTs
695 are also saved in the global. */
698
699 /* Set the "cooperative SIGINT handling disabled" global flag, so
700 that a future call to set_active_ext_lang does not re-enable
701 cooperative mode. */
705}
706
712
713/* Set the currently active extension language to NOW_ACTIVE.
714 The result is a pointer to a malloc'd block of memory to pass to
715 restore_active_ext_lang.
716
717 N.B. This function must be called every time we call out to an extension
718 language, and the result must be passed to restore_active_ext_lang
719 afterwards.
720
721 If there is a pending SIGINT it is "moved" to the now active extension
722 language, if it supports cooperative SIGINT handling (i.e., it provides
723 {clear,set,check}_quit_flag methods). If the extension language does not
724 support cooperative SIGINT handling, then the SIGINT is left queued and
725 we require the non-cooperative extension language to call check_quit_flag
726 at appropriate times.
727 It is important for the extension language to call check_quit_flag if it
728 installs its own SIGINT handler to prevent the situation where a SIGINT
729 is queued on entry, extension language code runs for a "long" time possibly
730 serving one or more SIGINTs, and then returns. Upon return, if
731 check_quit_flag is not called, the original SIGINT will be thrown.
732 Non-cooperative extension languages are free to install their own SIGINT
733 handler but the original must be restored upon return, either itself
734 or via restore_active_ext_lang.
735
736 If cooperative SIGINT handling is force-disabled (e.g., we're in
737 the middle of handling an inferior event), then we don't actually
738 record NOW_ACTIVE as the current active extension language, so that
739 set_quit_flag saves the SIGINT in the global quit flag instead of
740 in the extension language. The caller does not need to concern
741 itself about this, though. The currently active extension language
742 concept only exists for cooperative SIGINT handling. */
743
746{
747#if GDB_SELF_TEST
748 if (selftests::hook_set_active_ext_lang)
749 selftests::hook_set_active_ext_lang ();
750#endif
751
752 /* If cooperative SIGINT handling was previously force-disabled,
753 make sure to not re-enable it (as NOW_ACTIVE could be a language
754 that supports cooperative SIGINT handling). */
756 {
757 /* Ensure set_quit_flag saves SIGINT in the quit_flag
758 global. */
759 gdb_assert (active_ext_lang->ops == nullptr
760 || active_ext_lang->ops->check_quit_flag == nullptr);
761
762 /* The only thing the caller can do with the result is pass it
763 to restore_active_ext_lang, which expects NULL when
764 cooperative SIGINT handling is disabled. */
765 return nullptr;
766 }
767
768 struct active_ext_lang_state *previous
769 = XCNEW (struct active_ext_lang_state);
770
771 previous->ext_lang = active_ext_lang;
772 previous->sigint_handler.handler_saved = 0;
773 active_ext_lang = now_active;
774
776 {
777 /* If the newly active extension language uses cooperative SIGINT
778 handling then ensure GDB's SIGINT handler is installed. */
779 if (now_active->language == EXT_LANG_GDB
780 || now_active->ops->check_quit_flag != NULL)
782
783 /* If there's a SIGINT recorded in the cooperative extension languages,
784 move it to the new language, or save it in GDB's global flag if the
785 newly active extension language doesn't use cooperative SIGINT
786 handling. */
787 if (check_quit_flag ())
788 set_quit_flag ();
789 }
790
791 return previous;
792}
793
794/* Restore active extension language from PREVIOUS. */
795
796void
798{
800 {
801 /* See set_active_ext_lang. */
802 gdb_assert (previous == nullptr);
803 return;
804 }
805
806 active_ext_lang = previous->ext_lang;
807
809 {
810 /* Restore the previous SIGINT handler if one was saved. */
811 if (previous->sigint_handler.handler_saved)
813
814 /* If there's a SIGINT recorded in the cooperative extension languages,
815 move it to the new language, or save it in GDB's global flag if the
816 newly active extension language doesn't use cooperative SIGINT
817 handling. */
818 if (check_quit_flag ())
819 set_quit_flag ();
820 }
821 xfree (previous);
822}
823
824/* Set the quit flag.
825 This only sets the flag in the currently active extension language.
826 If the currently active extension language does not have cooperative
827 SIGINT handling, then GDB's global flag is set, and it is up to the
828 extension language to call check_quit_flag. The extension language
829 is free to install its own SIGINT handler, but we still need to handle
830 the transition. */
831
832void
834{
835 if (active_ext_lang->ops != NULL
836 && active_ext_lang->ops->set_quit_flag != NULL)
838 else
839 {
840 quit_flag = 1;
841
842 /* Now wake up the event loop, or any interruptible_select. Do
843 this after setting the flag, because signals on Windows
844 actually run on a separate thread, and thus otherwise the
845 main code could be woken up and find quit_flag still
846 clear. */
848 }
849}
850
851/* Return true if the quit flag has been set, false otherwise.
852 Note: The flag is cleared as a side-effect.
853 The flag is checked in all extension languages that support cooperative
854 SIGINT handling, not just the current one. This simplifies transitions. */
855
856int
858{
859 int result = 0;
860
861 for (const struct extension_language_defn *extlang : extension_languages)
862 {
863 if (extlang->ops != nullptr
864 && extlang->ops->check_quit_flag != NULL)
865 if (extlang->ops->check_quit_flag (extlang) != 0)
866 result = 1;
867 }
868
869 /* This is written in a particular way to avoid races. */
870 if (quit_flag)
871 {
872 /* No longer need to wake up the event loop or any
873 interruptible_select. The caller handles the quit
874 request. */
876 quit_flag = 0;
877 result = 1;
878 }
879
880 return result;
881}
882
883/* See extension.h. */
884
885void
886get_matching_xmethod_workers (struct type *type, const char *method_name,
887 std::vector<xmethod_worker_up> *workers)
888{
889 for (const struct extension_language_defn *extlang : extension_languages)
890 {
891 enum ext_lang_rc rc;
892
893 /* If an extension language does not support xmethods, ignore
894 it. */
895 if (extlang->ops == nullptr
896 || extlang->ops->get_matching_xmethod_workers == NULL)
897 continue;
898
899 rc = extlang->ops->get_matching_xmethod_workers (extlang,
900 type, method_name,
901 workers);
902 if (rc == EXT_LANG_RC_ERROR)
903 error (_("Error while looking for matching xmethod workers "
904 "defined in %s."), extlang->capitalized_name);
905 }
906}
907
908/* See extension.h. */
909
910std::vector<type *>
912{
913 std::vector<type *> type_array;
914
915 ext_lang_rc rc = do_get_arg_types (&type_array);
916 if (rc == EXT_LANG_RC_ERROR)
917 error (_("Error while looking for arg types of a xmethod worker "
918 "defined in %s."), m_extlang->capitalized_name);
919
920 return type_array;
921}
922
923/* See extension.h. */
924
925struct type *
926xmethod_worker::get_result_type (value *object, gdb::array_view<value *> args)
927{
928 type *result_type;
929
930 ext_lang_rc rc = do_get_result_type (object, args, &result_type);
931 if (rc == EXT_LANG_RC_ERROR)
932 {
933 error (_("Error while fetching result type of an xmethod worker "
934 "defined in %s."), m_extlang->capitalized_name);
935 }
936
937 return result_type;
938}
939
940/* See extension.h. */
941
942gdb::optional<std::string>
943ext_lang_colorize (const std::string &filename, const std::string &contents)
944{
945 gdb::optional<std::string> result;
946
947 for (const struct extension_language_defn *extlang : extension_languages)
948 {
949 if (extlang->ops == nullptr
950 || extlang->ops->colorize == nullptr)
951 continue;
952 result = extlang->ops->colorize (filename, contents);
953 if (result.has_value ())
954 return result;
955 }
956
957 return result;
958}
959
960/* See extension.h. */
961
962gdb::optional<std::string>
963ext_lang_colorize_disasm (const std::string &content, gdbarch *gdbarch)
964{
965 gdb::optional<std::string> result;
966
967 for (const struct extension_language_defn *extlang : extension_languages)
968 {
969 if (extlang->ops == nullptr
970 || extlang->ops->colorize_disasm == nullptr)
971 continue;
972 result = extlang->ops->colorize_disasm (content, gdbarch);
973 if (result.has_value ())
974 return result;
975 }
976
977 return result;
978}
979
980/* See extension.h. */
981
982gdb::optional<int>
983ext_lang_print_insn (struct gdbarch *gdbarch, CORE_ADDR address,
984 struct disassemble_info *info)
985{
986 for (const struct extension_language_defn *extlang : extension_languages)
987 {
988 if (extlang->ops == nullptr
989 || extlang->ops->print_insn == nullptr)
990 continue;
991 gdb::optional<int> length
992 = extlang->ops->print_insn (gdbarch, address, info);
993 if (length.has_value ())
994 return length;
995 }
996
997 return {};
998}
999
1000/* Called via an observer before gdb prints its prompt.
1001 Iterate over the extension languages giving them a chance to
1002 change the prompt. The first one to change the prompt wins,
1003 and no further languages are tried. */
1004
1005static void
1006ext_lang_before_prompt (const char *current_gdb_prompt)
1007{
1008 for (const struct extension_language_defn *extlang : extension_languages)
1009 {
1010 enum ext_lang_rc rc;
1011
1012 if (extlang->ops == nullptr
1013 || extlang->ops->before_prompt == NULL)
1014 continue;
1015 rc = extlang->ops->before_prompt (extlang, current_gdb_prompt);
1016 switch (rc)
1017 {
1018 case EXT_LANG_RC_OK:
1019 case EXT_LANG_RC_ERROR:
1020 return;
1021 case EXT_LANG_RC_NOP:
1022 break;
1023 default:
1024 gdb_assert_not_reached ("bad return from before_prompt");
1025 }
1026 }
1027}
1028
1029void _initialize_extension ();
1030void
void xfree(void *)
bool auto_load_gdb_scripts_enabled(const struct extension_language_defn *extlang)
Definition auto-load.c:103
void auto_load_objfile_script(struct objfile *objfile, const struct extension_language_defn *language)
Definition auto-load.c:821
struct active_ext_lang_state * m_prev_active_ext_lang_state
Definition extension.h:358
static bool is_ours()
Definition target.h:189
void script_from_file(FILE *stream, const char *file)
@ commands_control
Definition cli-script.h:42
language
Definition defs.h:211
void quit_serial_event_clear(void)
Definition event-top.c:1051
void quit_serial_event_set(void)
Definition event-top.c:1043
void handle_sigint(int sig)
Definition event-top.c:1085
struct active_ext_lang_state * set_active_ext_lang(const struct extension_language_defn *)
Definition extension.c:745
void restore_active_ext_lang(struct active_ext_lang_state *previous)
Definition extension.c:797
int ext_lang_present_p(const struct extension_language_defn *extlang)
Definition extension.c:150
void _initialize_extension()
Definition extension.c:1031
void eval_ext_lang_from_control_command(struct command_line *cmd)
Definition extension.c:356
int check_quit_flag(void)
Definition extension.c:857
void preserve_ext_lang_values(struct objfile *objfile, htab_t copied_types)
Definition extension.c:563
static const std::array< const extension_language_defn *, 2 > extension_languages
Definition extension.c:87
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
gdb::optional< std::string > ext_lang_colorize_disasm(const std::string &content, gdbarch *gdbarch)
Definition extension.c:963
const char * ext_lang_suffix(const struct extension_language_defn *extlang)
Definition extension.c:223
objfile_script_sourcer_func * ext_lang_objfile_script_sourcer(const struct extension_language_defn *extlang)
Definition extension.c:260
script_sourcer_func * ext_lang_script_sourcer(const struct extension_language_defn *extlang)
Definition extension.c:243
static int quit_flag
Definition extension.c:640
static void install_gdb_sigint_handler(struct signal_handler *previous)
Definition extension.c:666
static objfile_script_sourcer_func source_gdb_objfile_script
Definition extension.c:39
void set_quit_flag(void)
Definition extension.c:833
const char * ext_lang_name(const struct extension_language_defn *extlang)
Definition extension.c:207
static bool cooperative_sigint_handling_disabled
Definition extension.c:688
void restore_active_ext_lang(struct active_ext_lang_state *previous)
Definition extension.c:797
bool ext_lang_auto_load_enabled(const struct extension_language_defn *extlang)
Definition extension.c:289
int ext_lang_initialized_p(const struct extension_language_defn *extlang)
Definition extension.c:159
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 struct extension_language_defn * get_ext_lang_defn(enum extension_language lang)
Definition extension.c:99
static int has_extension(const char *file, const char *extension)
Definition extension.c:118
const char * ext_lang_capitalized_name(const struct extension_language_defn *extlang)
Definition extension.c:215
static void install_ext_sigint_handler(const struct signal_handler *handler_state)
Definition extension.c:653
void throw_ext_lang_unsupported(const struct extension_language_defn *extlang)
Definition extension.c:174
const struct extension_language_defn * get_ext_lang_of_file(const char *file)
Definition extension.c:132
static const struct extension_language_script_ops extension_language_gdb_script_ops
Definition extension.c:45
void auto_load_ext_lang_scripts_for_objfile(struct objfile *objfile)
Definition extension.c:383
static void ext_lang_before_prompt(const char *current_gdb_prompt)
Definition extension.c:1006
static script_sourcer_func source_gdb_script
Definition extension.c:38
const char * ext_lang_auto_load_suffix(const struct extension_language_defn *extlang)
Definition extension.c:231
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
bool breakpoint_ext_lang_cond_says_stop(struct breakpoint *b)
Definition extension.c:602
void get_matching_xmethod_workers(struct type *type, const char *method_name, std::vector< xmethod_worker_up > *workers)
Definition extension.c:886
gdb::unique_xmalloc_ptr< char > apply_ext_lang_type_printers(struct ext_lang_type_printers *printers, struct type *type)
Definition extension.c:422
int apply_ext_lang_val_pretty_printer(struct value *val, struct ui_file *stream, int recurse, const struct value_print_options *options, const struct language_defn *language)
Definition extension.c:477
gdb::optional< std::string > ext_lang_colorize(const std::string &filename, const std::string &contents)
Definition extension.c:943
struct active_ext_lang_state * set_active_ext_lang(const struct extension_language_defn *now_active)
Definition extension.c:745
objfile_script_executor_func * ext_lang_objfile_script_executor(const struct extension_language_defn *extlang)
Definition extension.c:278
static const struct extension_language_defn * active_ext_lang
Definition extension.c:648
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
extension_language
Definition extension.h:61
@ EXT_LANG_NONE
Definition extension.h:62
@ EXT_LANG_GDB
Definition extension.h:63
const struct extension_language_defn extension_language_gdb
Definition extension.c:53
ext_lang_bt_status
Definition extension.h:71
@ 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
void objfile_script_sourcer_func(const struct extension_language_defn *, struct objfile *, FILE *stream, const char *filename)
Definition extension.h:49
ext_lang_frame_args
Definition extension.h:114
ext_lang_bp_stop
Definition extension.h:138
@ EXT_LANG_BP_STOP_NO
Definition extension.h:143
@ EXT_LANG_BP_STOP_UNSET
Definition extension.h:140
void objfile_script_executor_func(const struct extension_language_defn *, struct objfile *, const char *name, const char *script)
Definition extension.h:55
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
mach_port_t mach_port_t name mach_port_t mach_port_t name kern_return_t int status
Definition gnu-nat.c:1790
const struct extension_language_defn extension_language_guile
c_c_handler_ftype * install_sigint_handler(c_c_handler_ftype *fn)
Definition mingw-hdep.c:425
observable< const char * > before_prompt
const struct extension_language_defn extension_language_python
Definition python.c:179
struct signal_handler sigint_handler
const struct extension_language_defn * ext_lang
enum command_control_type control_type
Definition cli-script.h:88
enum extension_language language
const char * auto_load_suffix
const char * capitalized_name
const struct extension_language_script_ops * script_ops
const struct extension_language_ops * ops
enum ext_lang_bp_stop(* breakpoint_cond_says_stop)(const struct extension_language_defn *, struct breakpoint *)
void(* set_quit_flag)(const struct extension_language_defn *)
int(* initialized)(const struct extension_language_defn *)
int(* check_quit_flag)(const struct extension_language_defn *)
bool(* auto_load_enabled)(const struct extension_language_defn *)
script_sourcer_func * script_sourcer
objfile_script_executor_func * objfile_script_executor
objfile_script_sourcer_func * objfile_script_sourcer
DISABLE_COPY_AND_ASSIGN(scoped_default_signal)
sighandler_t m_old_sig_handler
Definition extension.c:316
sighandler_t handler
ULONGEST length() const
Definition gdbtypes.h:983
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
type * get_result_type(value *object, gdb::array_view< value * > args)
Definition extension.c:926