diff options
author | Tom Tromey <tom@tromey.com> | 2020-05-08 14:21:22 -0600 |
---|---|---|
committer | Tom Tromey <tromey@adacore.com> | 2020-05-08 14:21:22 -0600 |
commit | 38eae084598a3531bef4b7987a8fe646ae92a988 (patch) | |
tree | 46a7e6828f3775e6b0044e091a8cfd58436977a0 | |
parent | 596dc4adfff347b4d8dc1f7e4eb57b8f2f342281 (diff) | |
download | gdb-38eae084598a3531bef4b7987a8fe646ae92a988.zip gdb-38eae084598a3531bef4b7987a8fe646ae92a988.tar.gz gdb-38eae084598a3531bef4b7987a8fe646ae92a988.tar.bz2 |
Remove ALL_EXTENSION_LANGUAGES and ALL_ENABLED_EXTENSION_LANGUAGES
This removes the ALL_EXTENSION_LANGUAGES and
ALL_ENABLED_EXTENSION_LANGUAGES macros, in favor of ordinary
iterators. For ALL_ENABLED_EXTENSION_LANGUAGES, I chose to simply
inline the check, as that seemed simpler than trying to make
filtered_iterator work for std::array. (As an aside, this sort of
thing will be easier once we can use the ranges library...)
gdb/ChangeLog
2020-05-08 Tom Tromey <tom@tromey.com>
* extension.c (extension_languages): Now a std::array.
(ALL_EXTENSION_LANGUAGES): Remove.
(get_ext_lang_defn, get_ext_lang_of_file)
(eval_ext_lang_from_control_command): Update.
(finish_ext_lang_initialization)
(auto_load_ext_lang_scripts_for_objfile)
(ext_lang_type_printers::ext_lang_type_printers)
(apply_ext_lang_type_printers)
(ext_lang_type_printers::~ext_lang_type_printers)
(apply_ext_lang_val_pretty_printer, apply_ext_lang_frame_filter)
(preserve_ext_lang_values, get_breakpoint_cond_ext_lang)
(breakpoint_ext_lang_cond_says_stop, check_quit_flag)
(get_matching_xmethod_workers, ext_lang_colorize)
(ext_lang_before_prompt): Update.
(ALL_ENABLED_EXTENSION_LANGUAGES): Remove.
-rw-r--r-- | gdb/ChangeLog | 18 | ||||
-rw-r--r-- | gdb/extension.c | 153 |
2 files changed, 69 insertions, 102 deletions
diff --git a/gdb/ChangeLog b/gdb/ChangeLog index dbfc94c..be55c41 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,5 +1,23 @@ 2020-05-08 Tom Tromey <tom@tromey.com> + * extension.c (extension_languages): Now a std::array. + (ALL_EXTENSION_LANGUAGES): Remove. + (get_ext_lang_defn, get_ext_lang_of_file) + (eval_ext_lang_from_control_command): Update. + (finish_ext_lang_initialization) + (auto_load_ext_lang_scripts_for_objfile) + (ext_lang_type_printers::ext_lang_type_printers) + (apply_ext_lang_type_printers) + (ext_lang_type_printers::~ext_lang_type_printers) + (apply_ext_lang_val_pretty_printer, apply_ext_lang_frame_filter) + (preserve_ext_lang_values, get_breakpoint_cond_ext_lang) + (breakpoint_ext_lang_cond_says_stop, check_quit_flag) + (get_matching_xmethod_workers, ext_lang_colorize) + (ext_lang_before_prompt): Update. + (ALL_ENABLED_EXTENSION_LANGUAGES): Remove. + +2020-05-08 Tom Tromey <tom@tromey.com> + * symtab.h (class demangle_result_storage) <set_malloc_ptr>: New overload. <swap_string, m_string>: Remove. diff --git a/gdb/extension.c b/gdb/extension.c index 09aa7d9..e4b3b3c 100644 --- a/gdb/extension.c +++ b/gdb/extension.c @@ -32,24 +32,7 @@ #include "cli/cli-script.h" #include "python/python.h" #include "guile/guile.h" - -/* Iterate over all external extension languages, regardless of whether the - support has been compiled in or not. - This does not include GDB's own scripting language. */ - -#define ALL_EXTENSION_LANGUAGES(i, extlang) \ - for (/*int*/ i = 0, extlang = extension_languages[0]; \ - extlang != NULL; \ - extlang = extension_languages[++i]) - -/* Iterate over all external extension languages that are supported. - This does not include GDB's own scripting language. */ - -#define ALL_ENABLED_EXTENSION_LANGUAGES(i, extlang) \ - for (/*int*/ i = 0, extlang = extension_languages[0]; \ - extlang != NULL; \ - extlang = extension_languages[++i]) \ - if (extlang->ops != NULL) +#include <array> static script_sourcer_func source_gdb_script; static objfile_script_sourcer_func source_gdb_objfile_script; @@ -99,12 +82,11 @@ const struct extension_language_defn extension_language_gdb = pretty-printed value is the one that is used. This algorithm is employed throughout. */ -static const struct extension_language_defn * const extension_languages[] = +static const std::array<const extension_language_defn *, 2> extension_languages { /* To preserve existing behaviour, python should always appear first. */ &extension_language_python, &extension_language_guile, - NULL }; /* Return a pointer to the struct extension_language_defn object of @@ -115,15 +97,12 @@ static const struct extension_language_defn * const extension_languages[] = const struct extension_language_defn * get_ext_lang_defn (enum extension_language lang) { - int i; - const struct extension_language_defn *extlang; - gdb_assert (lang != EXT_LANG_NONE); if (lang == EXT_LANG_GDB) return &extension_language_gdb; - ALL_EXTENSION_LANGUAGES (i, extlang) + for (const struct extension_language_defn *extlang : extension_languages) { if (extlang->language == lang) return extlang; @@ -151,13 +130,10 @@ has_extension (const char *file, const char *extension) const struct extension_language_defn * get_ext_lang_of_file (const char *file) { - int i; - const struct extension_language_defn *extlang; - if (has_extension (file, extension_language_gdb.suffix)) return &extension_language_gdb; - ALL_EXTENSION_LANGUAGES (i, extlang) + for (const struct extension_language_defn *extlang : extension_languages) { if (has_extension (file, extlang->suffix)) return extlang; @@ -331,12 +307,10 @@ ext_lang_auto_load_enabled (const struct extension_language_defn *extlang) void finish_ext_lang_initialization (void) { - int i; - const struct extension_language_defn *extlang; - - ALL_ENABLED_EXTENSION_LANGUAGES (i, extlang) + for (const struct extension_language_defn *extlang : extension_languages) { - if (extlang->ops->finish_initialization != NULL) + if (extlang->ops != nullptr + && extlang->ops->finish_initialization != NULL) extlang->ops->finish_initialization (extlang); } } @@ -355,10 +329,7 @@ finish_ext_lang_initialization (void) void eval_ext_lang_from_control_command (struct command_line *cmd) { - int i; - const struct extension_language_defn *extlang; - - ALL_EXTENSION_LANGUAGES (i, extlang) + for (const struct extension_language_defn *extlang : extension_languages) { if (extlang->cli_control_type == cmd->control_type) { @@ -385,16 +356,14 @@ eval_ext_lang_from_control_command (struct command_line *cmd) void auto_load_ext_lang_scripts_for_objfile (struct objfile *objfile) { - int i; - const struct extension_language_defn *extlang; - - extlang = &extension_language_gdb; - if (ext_lang_auto_load_enabled (extlang)) - auto_load_objfile_script (objfile, extlang); + const struct extension_language_defn *gdb = &extension_language_gdb; + if (ext_lang_auto_load_enabled (gdb)) + auto_load_objfile_script (objfile, gdb); - ALL_ENABLED_EXTENSION_LANGUAGES (i, extlang) + for (const struct extension_language_defn *extlang : extension_languages) { - if (ext_lang_auto_load_enabled (extlang)) + if (extlang->ops != nullptr + && ext_lang_auto_load_enabled (extlang)) auto_load_objfile_script (objfile, extlang); } } @@ -410,12 +379,10 @@ auto_load_ext_lang_scripts_for_objfile (struct objfile *objfile) ext_lang_type_printers::ext_lang_type_printers () { - int i; - const struct extension_language_defn *extlang; - - ALL_ENABLED_EXTENSION_LANGUAGES (i, extlang) + for (const struct extension_language_defn *extlang : extension_languages) { - if (extlang->ops->start_type_printers != NULL) + if (extlang->ops != nullptr + && extlang->ops->start_type_printers != NULL) extlang->ops->start_type_printers (extlang, this); } } @@ -429,15 +396,13 @@ char * apply_ext_lang_type_printers (struct ext_lang_type_printers *printers, struct type *type) { - int i; - const struct extension_language_defn *extlang; - - ALL_ENABLED_EXTENSION_LANGUAGES (i, extlang) + for (const struct extension_language_defn *extlang : extension_languages) { char *result = NULL; enum ext_lang_rc rc; - if (extlang->ops->apply_type_printers == NULL) + if (extlang->ops == nullptr + || extlang->ops->apply_type_printers == NULL) continue; rc = extlang->ops->apply_type_printers (extlang, printers, type, &result); @@ -460,12 +425,10 @@ apply_ext_lang_type_printers (struct ext_lang_type_printers *printers, ext_lang_type_printers::~ext_lang_type_printers () { - int i; - const struct extension_language_defn *extlang; - - ALL_ENABLED_EXTENSION_LANGUAGES (i, extlang) + for (const struct extension_language_defn *extlang : extension_languages) { - if (extlang->ops->free_type_printers != NULL) + if (extlang->ops != nullptr + && extlang->ops->free_type_printers != NULL) extlang->ops->free_type_printers (extlang, this); } } @@ -490,14 +453,12 @@ apply_ext_lang_val_pretty_printer (struct value *val, const struct value_print_options *options, const struct language_defn *language) { - int i; - const struct extension_language_defn *extlang; - - ALL_ENABLED_EXTENSION_LANGUAGES (i, extlang) + for (const struct extension_language_defn *extlang : extension_languages) { enum ext_lang_rc rc; - if (extlang->ops->apply_val_pretty_printer == NULL) + if (extlang->ops == nullptr + || extlang->ops->apply_val_pretty_printer == NULL) continue; rc = extlang->ops->apply_val_pretty_printer (extlang, val, stream, recurse, options, language); @@ -544,14 +505,12 @@ apply_ext_lang_frame_filter (struct frame_info *frame, struct ui_out *out, int frame_low, int frame_high) { - int i; - const struct extension_language_defn *extlang; - - ALL_ENABLED_EXTENSION_LANGUAGES (i, extlang) + for (const struct extension_language_defn *extlang : extension_languages) { enum ext_lang_bt_status status; - if (extlang->ops->apply_frame_filter == NULL) + if (extlang->ops == nullptr + || extlang->ops->apply_frame_filter == NULL) continue; status = extlang->ops->apply_frame_filter (extlang, frame, flags, args_type, out, @@ -577,12 +536,10 @@ apply_ext_lang_frame_filter (struct frame_info *frame, void preserve_ext_lang_values (struct objfile *objfile, htab_t copied_types) { - int i; - const struct extension_language_defn *extlang; - - ALL_ENABLED_EXTENSION_LANGUAGES (i, extlang) + for (const struct extension_language_defn *extlang : extension_languages) { - if (extlang->ops->preserve_values != NULL) + if (extlang->ops != nullptr + && extlang->ops->preserve_values != NULL) extlang->ops->preserve_values (extlang, objfile, copied_types); } } @@ -600,12 +557,10 @@ const struct extension_language_defn * get_breakpoint_cond_ext_lang (struct breakpoint *b, enum extension_language skip_lang) { - int i; - const struct extension_language_defn *extlang; - - ALL_ENABLED_EXTENSION_LANGUAGES (i, extlang) + for (const struct extension_language_defn *extlang : extension_languages) { - if (extlang->language != skip_lang + if (extlang->ops != nullptr + && extlang->language != skip_lang && extlang->ops->breakpoint_has_cond != NULL && extlang->ops->breakpoint_has_cond (extlang, b)) return extlang; @@ -620,18 +575,17 @@ get_breakpoint_cond_ext_lang (struct breakpoint *b, int breakpoint_ext_lang_cond_says_stop (struct breakpoint *b) { - int i; - const struct extension_language_defn *extlang; enum ext_lang_bp_stop stop = EXT_LANG_BP_STOP_UNSET; - ALL_ENABLED_EXTENSION_LANGUAGES (i, extlang) + for (const struct extension_language_defn *extlang : extension_languages) { /* There is a rule that a breakpoint can have at most one of any of a CLI or extension language condition. However, Python hacks in "finish breakpoints" on top of the "stop" check, so we have to call this for every language, even if we could first determine whether a "stop" method exists. */ - if (extlang->ops->breakpoint_cond_says_stop != NULL) + if (extlang->ops != nullptr + && extlang->ops->breakpoint_cond_says_stop != NULL) { enum ext_lang_bp_stop this_stop = extlang->ops->breakpoint_cond_says_stop (extlang, b); @@ -813,12 +767,12 @@ set_quit_flag (void) int check_quit_flag (void) { - int i, result = 0; - const struct extension_language_defn *extlang; + int result = 0; - ALL_ENABLED_EXTENSION_LANGUAGES (i, extlang) + for (const struct extension_language_defn *extlang : extension_languages) { - if (extlang->ops->check_quit_flag != NULL) + if (extlang->ops != nullptr + && extlang->ops->check_quit_flag != NULL) if (extlang->ops->check_quit_flag (extlang) != 0) result = 1; } @@ -843,16 +797,14 @@ void get_matching_xmethod_workers (struct type *type, const char *method_name, std::vector<xmethod_worker_up> *workers) { - int i; - const struct extension_language_defn *extlang; - - ALL_ENABLED_EXTENSION_LANGUAGES (i, extlang) + for (const struct extension_language_defn *extlang : extension_languages) { enum ext_lang_rc rc; /* If an extension language does not support xmethods, ignore it. */ - if (extlang->ops->get_matching_xmethod_workers == NULL) + if (extlang->ops == nullptr + || extlang->ops->get_matching_xmethod_workers == NULL) continue; rc = extlang->ops->get_matching_xmethod_workers (extlang, @@ -901,13 +853,12 @@ xmethod_worker::get_result_type (value *object, gdb::array_view<value *> args) gdb::optional<std::string> ext_lang_colorize (const std::string &filename, const std::string &contents) { - int i; - const struct extension_language_defn *extlang; gdb::optional<std::string> result; - ALL_ENABLED_EXTENSION_LANGUAGES (i, extlang) + for (const struct extension_language_defn *extlang : extension_languages) { - if (extlang->ops->colorize == nullptr) + if (extlang->ops == nullptr + || extlang->ops->colorize == nullptr) continue; result = extlang->ops->colorize (filename, contents); if (result.has_value ()) @@ -925,14 +876,12 @@ ext_lang_colorize (const std::string &filename, const std::string &contents) static void ext_lang_before_prompt (const char *current_gdb_prompt) { - int i; - const struct extension_language_defn *extlang; - - ALL_ENABLED_EXTENSION_LANGUAGES (i, extlang) + for (const struct extension_language_defn *extlang : extension_languages) { enum ext_lang_rc rc; - if (extlang->ops->before_prompt == NULL) + if (extlang->ops == nullptr + || extlang->ops->before_prompt == NULL) continue; rc = extlang->ops->before_prompt (extlang, current_gdb_prompt); switch (rc) |