aboutsummaryrefslogtreecommitdiff
path: root/gdb/compile
diff options
context:
space:
mode:
Diffstat (limited to 'gdb/compile')
-rw-r--r--gdb/compile/compile-c-support.c2
-rw-r--r--gdb/compile/compile-c-symbols.c2
-rw-r--r--gdb/compile/compile-c-types.c2
-rw-r--r--gdb/compile/compile-c.h2
-rw-r--r--gdb/compile/compile-cplus-symbols.c2
-rw-r--r--gdb/compile/compile-cplus-types.c2
-rw-r--r--gdb/compile/compile-cplus.h2
-rw-r--r--gdb/compile/compile-internal.h41
-rw-r--r--gdb/compile/compile-loc2c.c2
-rw-r--r--gdb/compile/compile-object-load.c2
-rw-r--r--gdb/compile/compile-object-load.h2
-rw-r--r--gdb/compile/compile-object-run.c2
-rw-r--r--gdb/compile/compile-object-run.h2
-rw-r--r--gdb/compile/compile.c83
-rw-r--r--gdb/compile/compile.h2
-rw-r--r--gdb/compile/gcc-c-plugin.h2
-rw-r--r--gdb/compile/gcc-cp-plugin.h2
17 files changed, 127 insertions, 27 deletions
diff --git a/gdb/compile/compile-c-support.c b/gdb/compile/compile-c-support.c
index a152e5a..0d32350 100644
--- a/gdb/compile/compile-c-support.c
+++ b/gdb/compile/compile-c-support.c
@@ -1,6 +1,6 @@
/* C/C++ language support for compilation.
- Copyright (C) 2014-2024 Free Software Foundation, Inc.
+ Copyright (C) 2014-2025 Free Software Foundation, Inc.
This file is part of GDB.
diff --git a/gdb/compile/compile-c-symbols.c b/gdb/compile/compile-c-symbols.c
index 7070e5e..b31592f 100644
--- a/gdb/compile/compile-c-symbols.c
+++ b/gdb/compile/compile-c-symbols.c
@@ -1,6 +1,6 @@
/* Convert symbols from GDB to GCC
- Copyright (C) 2014-2024 Free Software Foundation, Inc.
+ Copyright (C) 2014-2025 Free Software Foundation, Inc.
This file is part of GDB.
diff --git a/gdb/compile/compile-c-types.c b/gdb/compile/compile-c-types.c
index 6407f12..bf1fea5 100644
--- a/gdb/compile/compile-c-types.c
+++ b/gdb/compile/compile-c-types.c
@@ -1,6 +1,6 @@
/* Convert types from GDB to GCC
- Copyright (C) 2014-2024 Free Software Foundation, Inc.
+ Copyright (C) 2014-2025 Free Software Foundation, Inc.
This file is part of GDB.
diff --git a/gdb/compile/compile-c.h b/gdb/compile/compile-c.h
index b77b7aa..1a6b056 100644
--- a/gdb/compile/compile-c.h
+++ b/gdb/compile/compile-c.h
@@ -1,5 +1,5 @@
/* Header file for GDB compile C-language support.
- Copyright (C) 2014-2024 Free Software Foundation, Inc.
+ Copyright (C) 2014-2025 Free Software Foundation, Inc.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
diff --git a/gdb/compile/compile-cplus-symbols.c b/gdb/compile/compile-cplus-symbols.c
index 6c482e7..b03c4b9 100644
--- a/gdb/compile/compile-cplus-symbols.c
+++ b/gdb/compile/compile-cplus-symbols.c
@@ -1,6 +1,6 @@
/* Convert symbols from GDB to GCC
- Copyright (C) 2014-2024 Free Software Foundation, Inc.
+ Copyright (C) 2014-2025 Free Software Foundation, Inc.
This file is part of GDB.
diff --git a/gdb/compile/compile-cplus-types.c b/gdb/compile/compile-cplus-types.c
index 8d14114..56ef033 100644
--- a/gdb/compile/compile-cplus-types.c
+++ b/gdb/compile/compile-cplus-types.c
@@ -1,6 +1,6 @@
/* Convert types from GDB to GCC
- Copyright (C) 2014-2024 Free Software Foundation, Inc.
+ Copyright (C) 2014-2025 Free Software Foundation, Inc.
This file is part of GDB.
diff --git a/gdb/compile/compile-cplus.h b/gdb/compile/compile-cplus.h
index d3b2d3e..d08feea 100644
--- a/gdb/compile/compile-cplus.h
+++ b/gdb/compile/compile-cplus.h
@@ -1,5 +1,5 @@
/* Header file for GDB compile C++ language support.
- Copyright (C) 2016-2024 Free Software Foundation, Inc.
+ Copyright (C) 2016-2025 Free Software Foundation, Inc.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
diff --git a/gdb/compile/compile-internal.h b/gdb/compile/compile-internal.h
index f4cc9ee..46a8ac2 100644
--- a/gdb/compile/compile-internal.h
+++ b/gdb/compile/compile-internal.h
@@ -1,5 +1,5 @@
/* Header file for GDB compile command and supporting functions.
- Copyright (C) 2014-2024 Free Software Foundation, Inc.
+ Copyright (C) 2014-2025 Free Software Foundation, Inc.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -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-loc2c.c b/gdb/compile/compile-loc2c.c
index 2f5d85f..31fd8e2 100644
--- a/gdb/compile/compile-loc2c.c
+++ b/gdb/compile/compile-loc2c.c
@@ -1,6 +1,6 @@
/* Convert a DWARF location expression to C
- Copyright (C) 2014-2024 Free Software Foundation, Inc.
+ Copyright (C) 2014-2025 Free Software Foundation, Inc.
This file is part of GDB.
diff --git a/gdb/compile/compile-object-load.c b/gdb/compile/compile-object-load.c
index 05e5b43..49b967a 100644
--- a/gdb/compile/compile-object-load.c
+++ b/gdb/compile/compile-object-load.c
@@ -1,6 +1,6 @@
/* Load module for 'compile' command.
- Copyright (C) 2014-2024 Free Software Foundation, Inc.
+ Copyright (C) 2014-2025 Free Software Foundation, Inc.
This file is part of GDB.
diff --git a/gdb/compile/compile-object-load.h b/gdb/compile/compile-object-load.h
index 463aa08..5122764 100644
--- a/gdb/compile/compile-object-load.h
+++ b/gdb/compile/compile-object-load.h
@@ -1,5 +1,5 @@
/* Header file to load module for 'compile' command.
- Copyright (C) 2014-2024 Free Software Foundation, Inc.
+ Copyright (C) 2014-2025 Free Software Foundation, Inc.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
diff --git a/gdb/compile/compile-object-run.c b/gdb/compile/compile-object-run.c
index 8316377..30b45dc 100644
--- a/gdb/compile/compile-object-run.c
+++ b/gdb/compile/compile-object-run.c
@@ -1,6 +1,6 @@
/* Call module for 'compile' command.
- Copyright (C) 2014-2024 Free Software Foundation, Inc.
+ Copyright (C) 2014-2025 Free Software Foundation, Inc.
This file is part of GDB.
diff --git a/gdb/compile/compile-object-run.h b/gdb/compile/compile-object-run.h
index 64b2bd9..7515b70 100644
--- a/gdb/compile/compile-object-run.h
+++ b/gdb/compile/compile-object-run.h
@@ -1,5 +1,5 @@
/* Header file to call module for 'compile' command.
- Copyright (C) 2014-2024 Free Software Foundation, Inc.
+ Copyright (C) 2014-2025 Free Software Foundation, Inc.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
diff --git a/gdb/compile/compile.c b/gdb/compile/compile.c
index d6bcc1f..ab4cb0b 100644
--- a/gdb/compile/compile.c
+++ b/gdb/compile/compile.c
@@ -1,6 +1,6 @@
/* General Compile and inject code
- Copyright (C) 2014-2024 Free Software Foundation, Inc.
+ Copyright (C) 2014-2025 Free Software Foundation, Inc.
This file is part of GDB.
@@ -46,16 +46,17 @@
#include "gdbsupport/scoped_ignore_signal.h"
#include "gdbsupport/buildargv.h"
+/* Hold "compile" commands. */
+
+static struct cmd_list_element *compile_command_list;
+
+#ifdef HAVE_COMPILE
/* Initial filename for temporary files. */
#define TMP_PREFIX "/tmp/gdbobj-"
-/* Hold "compile" commands. */
-
-static struct cmd_list_element *compile_command_list;
-
/* Debug flag for "compile" commands. */
bool compile_debug;
@@ -527,6 +528,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 +586,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 +619,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 ());
@@ -816,6 +853,18 @@ compile_instance::compile (const char *filename, int verbose_level)
#undef FORWARD
+#else /* HAVE_COMPILE */
+
+/* The "compile" prefix command, when support was disabled. */
+
+static void
+compile_command (const char *args, int from_tty)
+{
+ error (_("This command is not supported."));
+}
+
+#endif /* HAVE_COMPILE */
+
/* See compile.h. */
cmd_list_element *compile_cmd_element = nullptr;
@@ -823,14 +872,25 @@ void _initialize_compile ();
void
_initialize_compile ()
{
- struct cmd_list_element *c = NULL;
-
compile_cmd_element = add_prefix_cmd ("compile", class_obscure,
- compile_command, _("\
+ compile_command,
+#ifdef HAVE_COMPILE
+ _("\
Command to compile source code and inject it into the inferior."),
+#else /* HAVE_COMPILE */
+ _("\
+Command to compile source code and inject it into the inferior.\n\
+\n\
+Code compilation and injection is not supported in this copy of GDB.\n\
+This command is only a placeholder."),
+#endif /* HAVE_COMPILE */
&compile_command_list, 1, &cmdlist);
add_com_alias ("expression", compile_cmd_element, class_obscure, 0);
+#ifdef HAVE_COMPILE
+
+ struct cmd_list_element *c = NULL;
+
const auto compile_opts = make_compile_options_def_group (nullptr);
static const std::string compile_code_help
@@ -937,4 +997,5 @@ It should be absolute filename of the gcc executable.\n\
If empty the default target triplet will be searched in $PATH."),
NULL, show_compile_gcc, &setlist,
&showlist);
+#endif /* HAVE_COMPILE */
}
diff --git a/gdb/compile/compile.h b/gdb/compile/compile.h
index e18b5bc..9308623 100644
--- a/gdb/compile/compile.h
+++ b/gdb/compile/compile.h
@@ -1,6 +1,6 @@
/* Header file for Compile and inject module.
- Copyright (C) 2014-2024 Free Software Foundation, Inc.
+ Copyright (C) 2014-2025 Free Software Foundation, Inc.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
diff --git a/gdb/compile/gcc-c-plugin.h b/gdb/compile/gcc-c-plugin.h
index d12472f..bc6710e 100644
--- a/gdb/compile/gcc-c-plugin.h
+++ b/gdb/compile/gcc-c-plugin.h
@@ -1,6 +1,6 @@
/* GCC C plug-in wrapper for GDB.
- Copyright (C) 2018-2024 Free Software Foundation, Inc.
+ Copyright (C) 2018-2025 Free Software Foundation, Inc.
This file is part of GDB.
diff --git a/gdb/compile/gcc-cp-plugin.h b/gdb/compile/gcc-cp-plugin.h
index 8f36993..d926355 100644
--- a/gdb/compile/gcc-cp-plugin.h
+++ b/gdb/compile/gcc-cp-plugin.h
@@ -1,6 +1,6 @@
/* GCC C++ plug-in wrapper for GDB.
- Copyright (C) 2018-2024 Free Software Foundation, Inc.
+ Copyright (C) 2018-2025 Free Software Foundation, Inc.
This file is part of GDB.