]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
gdb: Remove compile-related attributes from struct language
authorGuinevere Larsen <guinevere@redhat.com>
Thu, 13 Feb 2025 16:32:25 +0000 (13:32 -0300)
committerGuinevere Larsen <guinevere@redhat.com>
Wed, 26 Mar 2025 14:15:47 +0000 (11:15 -0300)
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>
gdb/c-lang.c
gdb/c-lang.h
gdb/compile/compile-internal.h
gdb/compile/compile.c
gdb/language.c
gdb/language.h

index c28493fc66bbd5a920f61745bced45782b98e869..55922344bfc13575b08b89547e85f471d2ae3432 100644 (file)
@@ -806,22 +806,6 @@ public:
     c_language_arch_info (gdbarch, lai);
   }
 
-  /* 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
@@ -942,22 +926,6 @@ public:
     return cp_lookup_transparent_type (name, flags);
   }
 
-  /* 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
   {
index 0e733d810d8d473593d33b323f2975ceb15dfc8c..06b7ad0b8f4de2e64c5bc0452840eefd68c60ae9 100644 (file)
@@ -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.  */
 
index f4cc9ee498456307041728d5c099957bcab0e0b0..789782dccaf0574fa339e82b99f842ba3b440d1c 100644 (file)
@@ -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 */
index d6bcc1f61f11198fd6ecbbb51e96cd5fd442669c..43987f9b2b70f28667693b6bd752edf1f9ffbc5e 100644 (file)
@@ -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 ());
 
index a8548a2e82fdc9d8508b65e1a8e489ef5d0beb8b..4208c23b7232e85ff3fd3879b05d9fc8974fa5fe 100644 (file)
@@ -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.  */
 
index e6bfa3c68f1229dc344e079b531d857b185a2ffd..5e9599df25cb46901e96d131502347f6ab52f928 100644 (file)
@@ -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;