]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blob - gdb/python/py-auto-load.c
Update Copyright year range in all files maintained by GDB.
[thirdparty/binutils-gdb.git] / gdb / python / py-auto-load.c
1 /* GDB routines for supporting auto-loaded scripts.
2
3 Copyright (C) 2010-2014 Free Software Foundation, Inc.
4
5 This file is part of GDB.
6
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 3 of the License, or
10 (at your option) any later version.
11
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with this program. If not, see <http://www.gnu.org/licenses/>. */
19
20 #include "defs.h"
21 #include <string.h>
22 #include "top.h"
23 #include "exceptions.h"
24 #include "gdbcmd.h"
25 #include "objfiles.h"
26 #include "python.h"
27 #include "auto-load.h"
28
29 #ifdef HAVE_PYTHON
30
31 #include "python-internal.h"
32
33 /* User-settable option to enable/disable auto-loading of Python scripts:
34 set auto-load python-scripts on|off
35 This is true if we should auto-load associated Python scripts when an
36 objfile is opened, false otherwise. */
37 static int auto_load_python_scripts = 1;
38
39 /* "show" command for the auto_load_python_scripts configuration variable. */
40
41 static void
42 show_auto_load_python_scripts (struct ui_file *file, int from_tty,
43 struct cmd_list_element *c, const char *value)
44 {
45 fprintf_filtered (file, _("Auto-loading of Python scripts is %s.\n"), value);
46 }
47
48 /* Return non-zero if auto-loading Python scripts is enabled. */
49
50 static int
51 auto_load_python_scripts_enabled (void)
52 {
53 return auto_load_python_scripts;
54 }
55
56 /* Definition of script language for Python scripts. */
57
58 static const struct script_language script_language_python =
59 {
60 "python",
61 GDBPY_AUTO_FILE_NAME,
62 auto_load_python_scripts_enabled,
63 source_python_script_for_objfile
64 };
65
66 /* Return the Python script language definition. */
67
68 const struct script_language *
69 gdbpy_script_language_defn (void)
70 {
71 return &script_language_python;
72 }
73
74 /* Wrapper for "info auto-load python-scripts". */
75
76 static void
77 info_auto_load_python_scripts (char *pattern, int from_tty)
78 {
79 auto_load_info_scripts (pattern, from_tty, &script_language_python);
80 }
81 \f
82 int
83 gdbpy_initialize_auto_load (void)
84 {
85 struct cmd_list_element *cmd;
86 const char *cmd_name;
87
88 add_setshow_boolean_cmd ("python-scripts", class_support,
89 &auto_load_python_scripts, _("\
90 Set the debugger's behaviour regarding auto-loaded Python scripts."), _("\
91 Show the debugger's behaviour regarding auto-loaded Python scripts."), _("\
92 If enabled, auto-loaded Python scripts are loaded when the debugger reads\n\
93 an executable or shared library.\n\
94 This options has security implications for untrusted inferiors."),
95 NULL, show_auto_load_python_scripts,
96 auto_load_set_cmdlist_get (),
97 auto_load_show_cmdlist_get ());
98
99 add_setshow_boolean_cmd ("auto-load-scripts", class_support,
100 &auto_load_python_scripts, _("\
101 Set the debugger's behaviour regarding auto-loaded Python scripts, "
102 "deprecated."),
103 _("\
104 Show the debugger's behaviour regarding auto-loaded Python scripts, "
105 "deprecated."),
106 NULL, NULL, show_auto_load_python_scripts,
107 &setlist, &showlist);
108 cmd_name = "auto-load-scripts";
109 cmd = lookup_cmd (&cmd_name, setlist, "", -1, 1);
110 deprecate_cmd (cmd, "set auto-load python-scripts");
111
112 /* It is needed because lookup_cmd updates the CMD_NAME pointer. */
113 cmd_name = "auto-load-scripts";
114 cmd = lookup_cmd (&cmd_name, showlist, "", -1, 1);
115 deprecate_cmd (cmd, "show auto-load python-scripts");
116
117 add_cmd ("python-scripts", class_info, info_auto_load_python_scripts,
118 _("Print the list of automatically loaded Python scripts.\n\
119 Usage: info auto-load python-scripts [REGEXP]"),
120 auto_load_info_cmdlist_get ());
121
122 cmd = add_info ("auto-load-scripts", info_auto_load_python_scripts, _("\
123 Print the list of automatically loaded Python scripts, deprecated."));
124 deprecate_cmd (cmd, "info auto-load python-scripts");
125
126 return 0;
127 }
128
129 #else /* ! HAVE_PYTHON */
130
131 /* Return the Python script language definition.
132 Since support isn't compiled in, return NULL. */
133
134 const struct script_language *
135 gdbpy_script_language_defn (void)
136 {
137 return NULL;
138 }
139
140 #endif /* ! HAVE_PYTHON */