diff options
author | Guinevere Larsen <guinevere@redhat.com> | 2025-02-13 13:32:25 -0300 |
---|---|---|
committer | Guinevere Larsen <guinevere@redhat.com> | 2025-03-26 11:15:47 -0300 |
commit | 62c95db2a187a01bbafc6c29a81af53424bce0a3 (patch) | |
tree | 3404ca53ba383ac17b0269bf232f55e11fc6409d /gdb | |
parent | ad172865ca67ee66f9a7a2f87f62564c8fda3538 (diff) | |
download | binutils-62c95db2a187a01bbafc6c29a81af53424bce0a3.zip binutils-62c95db2a187a01bbafc6c29a81af53424bce0a3.tar.gz binutils-62c95db2a187a01bbafc6c29a81af53424bce0a3.tar.bz2 |
gdb: Remove compile-related attributes from struct language
The following patch will add a configure option to disable the compile
subsystem at compilation time. To do that, nearly all code that
interfaces with compile should be confined to the compile sub-folder.
This commit is the first step, removing the compile-related method from
the language struct and adding 2 new functions to compile.c that do the
same job in a slightly different way. Adding things to the language
struct is a more extendable way to add support for languages, but
considering compile is quite bit-rotted and questionably supported, I
don't think it will be extended any time soon, and using ifdefs to
handle disabling compile with configure felt like a messier solution.
There should be no visible changes after this commit.
Approved-By: Tom Tromey <tom@tromey.com>
Diffstat (limited to 'gdb')
-rw-r--r-- | gdb/c-lang.c | 32 | ||||
-rw-r--r-- | gdb/c-lang.h | 38 | ||||
-rw-r--r-- | gdb/compile/compile-internal.h | 39 | ||||
-rw-r--r-- | gdb/compile/compile.c | 42 | ||||
-rw-r--r-- | gdb/language.c | 8 | ||||
-rw-r--r-- | gdb/language.h | 32 |
6 files changed, 78 insertions, 113 deletions
diff --git a/gdb/c-lang.c b/gdb/c-lang.c index c28493f..5592234 100644 --- a/gdb/c-lang.c +++ b/gdb/c-lang.c @@ -807,22 +807,6 @@ public: } /* See language.h. */ - std::unique_ptr<compile_instance> get_compile_instance () const override - { - return c_get_compile_context (); - } - - /* See language.h. */ - std::string compute_program (compile_instance *inst, - const char *input, - struct gdbarch *gdbarch, - const struct block *expr_block, - CORE_ADDR expr_pc) const override - { - return c_compute_program (inst, input, gdbarch, expr_block, expr_pc); - } - - /* See language.h. */ bool can_print_type_offsets () const override { @@ -943,22 +927,6 @@ public: } /* See language.h. */ - std::unique_ptr<compile_instance> get_compile_instance () const override - { - return cplus_get_compile_context (); - } - - /* See language.h. */ - std::string compute_program (compile_instance *inst, - const char *input, - struct gdbarch *gdbarch, - const struct block *expr_block, - CORE_ADDR expr_pc) const override - { - return cplus_compute_program (inst, input, gdbarch, expr_block, expr_pc); - } - - /* See language.h. */ unsigned int search_name_hash (const char *name) const override { return cp_search_name_hash (name); diff --git a/gdb/c-lang.h b/gdb/c-lang.h index 0e733d8..06b7ad0 100644 --- a/gdb/c-lang.h +++ b/gdb/c-lang.h @@ -25,7 +25,6 @@ struct ui_file; struct language_arch_info; struct type_print_options; struct parser_state; -struct compile_instance; #include "compile/compile.h" #include "value.h" @@ -132,43 +131,6 @@ extern bool c_is_string_type_p (struct type *type); extern int c_textual_element_type (struct type *, char); -/* Create a new instance of the C compiler and return it. This - function never returns NULL, but rather throws an exception on - failure. This is suitable for use as the - language_defn::get_compile_instance method. */ - -extern std::unique_ptr<compile_instance> c_get_compile_context (); - -/* Create a new instance of the C++ compiler and return it. This - function never returns NULL, but rather throws an exception on - failure. This is suitable for use as the - language_defn::get_compile_instance method. */ - -extern std::unique_ptr<compile_instance> cplus_get_compile_context (); - -/* This takes the user-supplied text and returns a new bit of code to - compile. - - This is used as the compute_program language method; see that - for a description of the arguments. */ - -extern std::string c_compute_program (compile_instance *inst, - const char *input, - struct gdbarch *gdbarch, - const struct block *expr_block, - CORE_ADDR expr_pc); - -/* This takes the user-supplied text and returns a new bit of code to compile. - - This is used as the compute_program language method; see that - for a description of the arguments. */ - -extern std::string cplus_compute_program (compile_instance *inst, - const char *input, - struct gdbarch *gdbarch, - const struct block *expr_block, - CORE_ADDR expr_pc); - /* Return the canonical form of the C symbol NAME. If NAME is already canonical, return nullptr. */ diff --git a/gdb/compile/compile-internal.h b/gdb/compile/compile-internal.h index f4cc9ee..789782d 100644 --- a/gdb/compile/compile-internal.h +++ b/gdb/compile/compile-internal.h @@ -80,4 +80,43 @@ private: std::string m_object_file; }; +struct compile_instance; + +/* Create a new instance of the C compiler and return it. This + function never returns NULL, but rather throws an exception on + failure. This is suitable for use as the + language_defn::get_compile_instance method. */ + +extern std::unique_ptr<compile_instance> c_get_compile_context (); + +/* Create a new instance of the C++ compiler and return it. This + function never returns NULL, but rather throws an exception on + failure. This is suitable for use as the + language_defn::get_compile_instance method. */ + +extern std::unique_ptr<compile_instance> cplus_get_compile_context (); + +/* This takes the user-supplied text and returns a new bit of code to + compile. + + This is used as the compute_program language method; see that + for a description of the arguments. */ + +extern std::string c_compute_program (compile_instance *inst, + const char *input, + struct gdbarch *gdbarch, + const struct block *expr_block, + CORE_ADDR expr_pc); + +/* This takes the user-supplied text and returns a new bit of code to compile. + + This is used as the compute_program language method; see that + for a description of the arguments. */ + +extern std::string cplus_compute_program (compile_instance *inst, + const char *input, + struct gdbarch *gdbarch, + const struct block *expr_block, + CORE_ADDR expr_pc); + #endif /* GDB_COMPILE_COMPILE_INTERNAL_H */ diff --git a/gdb/compile/compile.c b/gdb/compile/compile.c index d6bcc1f..43987f9 100644 --- a/gdb/compile/compile.c +++ b/gdb/compile/compile.c @@ -527,6 +527,41 @@ print_callback (void *ignore, const char *message) gdb_puts (message, gdb_stderr); } +/* Helper for compile_to_object, to find the compile context + based on the current language. */ +static std::unique_ptr<compile_instance> +get_language_compile_context () +{ + switch (current_language->la_language) + { + case language_c: + return c_get_compile_context (); + case language_cplus: + return cplus_get_compile_context (); + default: + return {}; + } +} + +/* Helper for compile_to_object, to call the correct + compute_program based on the current language. */ +static std::string +compute_program_language (compile_instance *inst, const char *input, + struct gdbarch *gdbarch, + const struct block *block, + CORE_ADDR pc) +{ + switch (current_language->la_language) + { + case language_c: + return c_compute_program (inst, input, gdbarch, block, pc); + case language_cplus: + return cplus_compute_program (inst, input, gdbarch, block, pc); + default: + gdb_assert_not_reached ("Unsupported language"); + } +} + /* Process the compilation request. On success it returns the object and source file names. On an error condition, error () is called. */ @@ -550,7 +585,8 @@ compile_to_object (struct command_line *cmd, const char *cmd_string, /* Set up instance and context for the compiler. */ std::unique_ptr<compile_instance> compiler - = current_language->get_compile_instance (); + = get_language_compile_context (); + if (compiler == nullptr) error (_("No compiler support for language %s."), current_language->name ()); @@ -582,8 +618,8 @@ compile_to_object (struct command_line *cmd, const char *cmd_string, error (_("Neither a simple expression, or a multi-line specified.")); std::string code - = current_language->compute_program (compiler.get (), input, gdbarch, - expr_block, expr_pc); + = compute_program_language (compiler.get (), input, gdbarch, + expr_block, expr_pc); if (compile_debug) gdb_printf (gdb_stdlog, "debug output:\n\n%s", code.c_str ()); diff --git a/gdb/language.c b/gdb/language.c index a8548a2..4208c23 100644 --- a/gdb/language.c +++ b/gdb/language.c @@ -677,14 +677,6 @@ language_defn::is_string_type_p (struct type *type) const return c_is_string_type_p (type); } -/* See language.h. */ - -std::unique_ptr<compile_instance> -language_defn::get_compile_instance () const -{ - return {}; -} - /* The default implementation of the get_symbol_name_matcher_inner method from the language_defn class. Matches with strncmp_iw. */ diff --git a/gdb/language.h b/gdb/language.h index e6bfa3c..5e9599d 100644 --- a/gdb/language.h +++ b/gdb/language.h @@ -36,7 +36,6 @@ struct value_print_options; struct type_print_options; struct lang_varobj_ops; struct parser_state; -class compile_instance; struct completion_match_for_lcd; class innermost_block_tracker; @@ -390,37 +389,6 @@ struct language_defn symbol_name_matcher_ftype *get_symbol_name_matcher (const lookup_name_info &lookup_name) const; - /* If this language allows compilation from the gdb command line, - then this method will return an instance of struct gcc_context - appropriate to the language. If compilation for this language is - generally supported, but something goes wrong then an exception - is thrown. If compilation is not supported for this language - then this method returns NULL. */ - - virtual std::unique_ptr<compile_instance> get_compile_instance () const; - - /* This method must be overridden if 'get_compile_instance' is - overridden. - - This takes the user-supplied text and returns a new bit of code - to compile. - - INST is the compiler instance being used. - INPUT is the user's input text. - GDBARCH is the architecture to use. - EXPR_BLOCK is the block in which the expression is being - parsed. - EXPR_PC is the PC at which the expression is being parsed. */ - - virtual std::string compute_program (compile_instance *inst, - const char *input, - struct gdbarch *gdbarch, - const struct block *expr_block, - CORE_ADDR expr_pc) const - { - gdb_assert_not_reached ("language_defn::compute_program"); - } - /* Hash the given symbol search name. */ virtual unsigned int search_name_hash (const char *name) const; |