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/compile | |
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/compile')
-rw-r--r-- | gdb/compile/compile-internal.h | 39 | ||||
-rw-r--r-- | gdb/compile/compile.c | 42 |
2 files changed, 78 insertions, 3 deletions
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 ()); |