aboutsummaryrefslogtreecommitdiff
path: root/gdb/compile/compile.c
diff options
context:
space:
mode:
authorGuinevere Larsen <guinevere@redhat.com>2025-02-13 17:18:18 -0300
committerGuinevere Larsen <guinevere@redhat.com>2025-03-26 11:15:59 -0300
commitc4375bc51c861dfa384a01bdb2e460e115710bf9 (patch)
tree0a2799d53852e7f7927e59638f6b708f9e1b4af6 /gdb/compile/compile.c
parent62c95db2a187a01bbafc6c29a81af53424bce0a3 (diff)
downloadbinutils-c4375bc51c861dfa384a01bdb2e460e115710bf9.zip
binutils-c4375bc51c861dfa384a01bdb2e460e115710bf9.tar.gz
binutils-c4375bc51c861dfa384a01bdb2e460e115710bf9.tar.bz2
gdb: add configure option to disable compile
GDB's compile subsystem is deeply tied to GDB's ability to understand DWARF. A future patch will add the option to disable DWARF at configure time, but for that to work, the compile subsystem will need to be entirely disabled as well, so this patch adds that possibility. I also think there is motive for a security conscious user to disable compile for it's own sake. Considering that the code is quite unmaintained, and depends on an equally unmaintained gcc plugin, there is a case to be made that this is an unnecessary increase in the attack surface if a user knows they won't use the subsystem. Additionally, this can make compilation slightly faster and the final binary is around 3Mb smaller. But these are all secondary to the main goal of being able to disable dwarf at configure time. To be able to achieve optional compilation, some of the code that interfaces with compile had to be changed. All parts that directly called compile things have been wrapped by ifdefs checking for compile support. The file compile/compile.c has been setup in a similar way to how python's and guile's main file has been setup, still being compiled but only for with placeholder command. Finally, to avoid several new errors, a new TCL proc was introduced to gdb.exp, allow_compile_tests, which checks if the "compile" command is recognized before the inferior is started and otherwise skips the compile tests. All tests in the gdb.compile subfolder have been updated to use that, and the test gdb.base/filename-completion also uses this. The proc skip_compile_feature_tests to recognize when the subsystem has been disabled at compile time. Reviewed-By: Eli Zaretskii <eliz@gnu.org> Approved-By: Tom Tromey <tom@tromey.com>
Diffstat (limited to 'gdb/compile/compile.c')
-rw-r--r--gdb/compile/compile.c39
1 files changed, 32 insertions, 7 deletions
diff --git a/gdb/compile/compile.c b/gdb/compile/compile.c
index 43987f9..01f43ad 100644
--- a/gdb/compile/compile.c
+++ b/gdb/compile/compile.c
@@ -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;
@@ -852,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;
@@ -859,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
@@ -973,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 */
}