aboutsummaryrefslogtreecommitdiff
path: root/gdb/python/python.c
diff options
context:
space:
mode:
Diffstat (limited to 'gdb/python/python.c')
-rw-r--r--gdb/python/python.c98
1 files changed, 98 insertions, 0 deletions
diff --git a/gdb/python/python.c b/gdb/python/python.c
index 1d0d86d..c46d68b 100644
--- a/gdb/python/python.c
+++ b/gdb/python/python.c
@@ -1578,6 +1578,80 @@ python_command (const char *arg, int from_tty)
#endif /* HAVE_PYTHON */
+/* When this is turned on before Python is initialised then Python will
+ ignore any environment variables related to Python. This is equivalent
+ to passing `-E' to the python program. */
+static bool python_ignore_environment = false;
+
+/* Implement 'show python ignore-environment'. */
+
+static void
+show_python_ignore_environment (struct ui_file *file, int from_tty,
+ struct cmd_list_element *c, const char *value)
+{
+ fprintf_filtered (file, _("Python's ignore-environment setting is %s.\n"),
+ value);
+}
+
+/* Implement 'set python ignore-environment'. This sets Python's internal
+ flag no matter when the command is issued, however, if this is used
+ after Py_Initialize has been called then most of the environment will
+ already have been read. */
+
+static void
+set_python_ignore_environment (const char *args, int from_tty,
+ struct cmd_list_element *c)
+{
+#ifdef HAVE_PYTHON
+ Py_IgnoreEnvironmentFlag = python_ignore_environment ? 1 : 0;
+#endif
+}
+
+/* When this is turned on before Python is initialised then Python will
+ not write `.pyc' files on import of a module. */
+static enum auto_boolean python_dont_write_bytecode = AUTO_BOOLEAN_AUTO;
+
+/* Implement 'show python dont-write-bytecode'. */
+
+static void
+show_python_dont_write_bytecode (struct ui_file *file, int from_tty,
+ struct cmd_list_element *c, const char *value)
+{
+ if (python_dont_write_bytecode == AUTO_BOOLEAN_AUTO)
+ {
+ const char *auto_string
+ = (python_ignore_environment
+ || getenv ("PYTHONDONTWRITEBYTECODE") == nullptr) ? "off" : "on";
+
+ fprintf_filtered (file,
+ _("Python's dont-write-bytecode setting is %s (currently %s).\n"),
+ value, auto_string);
+ }
+ else
+ fprintf_filtered (file, _("Python's dont-write-bytecode setting is %s.\n"),
+ value);
+}
+
+/* Implement 'set python dont-write-bytecode'. This sets Python's internal
+ flag no matter when the command is issued, however, if this is used
+ after Py_Initialize has been called then many modules could already
+ have been imported and their byte code written out. */
+
+static void
+set_python_dont_write_bytecode (const char *args, int from_tty,
+ struct cmd_list_element *c)
+{
+#ifdef HAVE_PYTHON
+ if (python_dont_write_bytecode == AUTO_BOOLEAN_AUTO)
+ Py_DontWriteBytecodeFlag
+ = (!python_ignore_environment
+ && getenv ("PYTHONDONTWRITEBYTECODE") != nullptr) ? 1 : 0;
+ else
+ Py_DontWriteBytecodeFlag
+ = python_dont_write_bytecode == AUTO_BOOLEAN_TRUE ? 1 : 0;
+#endif /* HAVE_PYTHON */
+}
+
/* Lists for 'set python' commands. */
@@ -1880,6 +1954,30 @@ message == an error message without a stack will be printed."),
NULL, NULL,
&user_set_python_list,
&user_show_python_list);
+
+ add_setshow_boolean_cmd ("ignore-environment", no_class,
+ &python_ignore_environment, _("\
+Set whether the Python interpreter should ignore environment variables."), _(" \
+Show whether the Python interpreter showlist ignore environment variables."), _(" \
+When enabled GDB's Python interpreter will ignore any Python related\n \
+flags in the environment. This is equivalent to passing `-E' to a\n \
+python executable."),
+ set_python_ignore_environment,
+ show_python_ignore_environment,
+ &user_set_python_list,
+ &user_show_python_list);
+
+ add_setshow_auto_boolean_cmd ("dont-write-bytecode", no_class,
+ &python_dont_write_bytecode, _("\
+Set whether the Python interpreter should ignore environment variables."), _(" \
+Show whether the Python interpreter showlist ignore environment variables."), _(" \
+When enabled GDB's Python interpreter will ignore any Python related\n \
+flags in the environment. This is equivalent to passing `-E' to a\n \
+python executable."),
+ set_python_dont_write_bytecode,
+ show_python_dont_write_bytecode,
+ &user_set_python_list,
+ &user_show_python_list);
}
#ifdef HAVE_PYTHON