GDB (xrefs)

py-auto-load.c
Go to the documentation of this file.
1 /* GDB routines for supporting auto-loaded scripts.
2
3 Copyright (C) 2010-2018 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 "top.h"
22 #include "gdbcmd.h"
23 #include "objfiles.h"
24 #include "python.h"
25 #include "auto-load.h"
26 #include "python-internal.h"
27
28 /* User-settable option to enable/disable auto-loading of Python scripts:
29 set auto-load python-scripts on|off
30 This is true if we should auto-load associated Python scripts when an
31 objfile is opened, false otherwise. */
32 static int auto_load_python_scripts = 1;
33
34 /* "show" command for the auto_load_python_scripts configuration variable. */
35
36 static void
37 show_auto_load_python_scripts (struct ui_file *file, int from_tty,
38 struct cmd_list_element *c, const char *value)
39 {
40 fprintf_filtered (file, _("Auto-loading of Python scripts is %s.\n"), value);
41 }
42
43 /* Return non-zero if auto-loading Python scripts is enabled.
44 This is the extension_language_script_ops.auto_load_enabled "method". */
45
46 int
47 gdbpy_auto_load_enabled (const struct extension_language_defn *extlang)
48 {
49 return auto_load_python_scripts;
50 }
51
52 /* Wrapper for "info auto-load python-scripts". */
53
54 static void
55 info_auto_load_python_scripts (const char *pattern, int from_tty)
56 {
57 auto_load_info_scripts (pattern, from_tty, &extension_language_python);
58 }
59
60 int
61 gdbpy_initialize_auto_load (void)
62 {
63 struct cmd_list_element *cmd;
64 const char *cmd_name;
65
66 add_setshow_boolean_cmd ("python-scripts", class_support,
67 &auto_load_python_scripts, _("\
68 Set the debugger's behaviour regarding auto-loaded Python scripts."), _("\
69 Show the debugger's behaviour regarding auto-loaded Python scripts."), _("\
70 If enabled, auto-loaded Python scripts are loaded when the debugger reads\n\
71 an executable or shared library.\n\
72 This options has security implications for untrusted inferiors."),
73 NULL, show_auto_load_python_scripts,
74 auto_load_set_cmdlist_get (),
75 auto_load_show_cmdlist_get ());
76
77 add_setshow_boolean_cmd ("auto-load-scripts", class_support,
78 &auto_load_python_scripts, _("\
79 Set the debugger's behaviour regarding auto-loaded Python scripts, "
80 "deprecated."),
81 _("\
82 Show the debugger's behaviour regarding auto-loaded Python scripts, "
83 "deprecated."),
84 NULL, NULL, show_auto_load_python_scripts,
85 &setlist, &showlist);
86 cmd_name = "auto-load-scripts";
87 cmd = lookup_cmd (&cmd_name, setlist, "", -1, 1);
88 deprecate_cmd (cmd, "set auto-load python-scripts");
89
90 /* It is needed because lookup_cmd updates the CMD_NAME pointer. */
91 cmd_name = "auto-load-scripts";
92 cmd = lookup_cmd (&cmd_name, showlist, "", -1, 1);
93 deprecate_cmd (cmd, "show auto-load python-scripts");
94
95 add_cmd ("python-scripts", class_info, info_auto_load_python_scripts,
96 _("Print the list of automatically loaded Python scripts.\n\
97 Usage: info auto-load python-scripts [REGEXP]"),
98 auto_load_info_cmdlist_get ());
99
100 cmd = add_info ("auto-load-scripts", info_auto_load_python_scripts, _("\
101 Print the list of automatically loaded Python scripts, deprecated."));
102 deprecate_cmd (cmd, "info auto-load python-scripts");
103
104 return 0;
105 }
top.h
class_support
Definition: command.h:42
cmd_list_element
Definition: cli-decode.h:46
deprecate_cmd
struct cmd_list_element * deprecate_cmd(struct cmd_list_element *cmd, const char *replacement)
Definition: cli-decode.c:292
auto_load_python_scripts
static int auto_load_python_scripts
Definition: py-auto-load.c:32
add_info
struct cmd_list_element * add_info(const char *name, cmd_const_cfunc_ftype *fun, const char *doc)
Definition: cli-decode.c:886
auto_load_set_cmdlist_get
struct cmd_list_element ** auto_load_set_cmdlist_get(void)
Definition: auto-load.c:1474
lookup_cmd
struct cmd_list_element * lookup_cmd(const char **line, struct cmd_list_element *list, const char *cmdtype, int allow_unknown, int ignore_help_classes)
Definition: cli-decode.c:1515
add_cmd
struct cmd_list_element * add_cmd(const char *name, enum command_class theclass, const char *doc, struct cmd_list_element **list)
Definition: cli-decode.c:262
_
#define _(String)
Definition: gdb_locale.h:35
ui_file
Definition: ui-file.h:26
extension_language_python
const struct extension_language_defn extension_language_python
Definition: python.c:68
defs.h
class_info
Definition: command.h:42
objfiles.h
gdbpy_initialize_auto_load
int gdbpy_initialize_auto_load(void)
Definition: py-auto-load.c:61
setlist
struct cmd_list_element * setlist
Definition: cli-cmds.c:111
fprintf_filtered
void fprintf_filtered(struct ui_file *stream, const char *format,...)
Definition: utils.c:2008
showlist
struct cmd_list_element * showlist
Definition: cli-cmds.c:119
info_auto_load_python_scripts
static void info_auto_load_python_scripts(const char *pattern, int from_tty)
Definition: py-auto-load.c:55
python.h
python-internal.h
extension_language_defn
Definition: extension-priv.h:53
gdbpy_auto_load_enabled
int gdbpy_auto_load_enabled(const struct extension_language_defn *extlang)
Definition: py-auto-load.c:47
value
Definition: value.c:169
add_setshow_boolean_cmd
void add_setshow_boolean_cmd(const char *name, enum command_class theclass, int *var, const char *set_doc, const char *show_doc, const char *help_doc, cmd_const_sfunc_ftype *set_func, show_value_ftype *show_func, struct cmd_list_element **set_list, struct cmd_list_element **show_list)
Definition: cli-decode.c:569
show_auto_load_python_scripts
static void show_auto_load_python_scripts(struct ui_file *file, int from_tty, struct cmd_list_element *c, const char *value)
Definition: py-auto-load.c:37
auto-load.h
auto_load_show_cmdlist_get
struct cmd_list_element ** auto_load_show_cmdlist_get(void)
Definition: auto-load.c:1501
gdbcmd.h
auto_load_info_scripts
void auto_load_info_scripts(const char *pattern, int from_tty, const struct extension_language_defn *language)
Definition: auto-load.c:1294
auto_load_info_cmdlist_get
struct cmd_list_element ** auto_load_info_cmdlist_get(void)
Definition: auto-load.c:1544