1 /* GDB routines for supporting auto-loaded scripts.
3 Copyright (C) 2012-2020 Free Software Foundation, Inc.
5 This file is part of GDB.
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.
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.
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/>. */
22 #include "auto-load.h"
23 #include "progspace.h"
24 #include "gdb_regex.h"
26 #include "filenames.h"
28 #include "observable.h"
30 #include "cli/cli-script.h"
32 #include "cli/cli-cmds.h"
33 #include "cli/cli-decode.h"
34 #include "cli/cli-setshow.h"
35 #include "readline/tilde.h"
36 #include "completer.h"
39 #include "gdbsupport/filestuff.h"
40 #include "extension.h"
41 #include "gdb/section-scripts.h"
43 #include "gdbsupport/pathstuff.h"
44 #include "cli/cli-style.h"
46 /* The section to look in for auto-loaded scripts (in file formats that
48 Each entry in this section is a record that begins with a leading byte
49 identifying the record type.
50 At the moment we only support one record type: A leading byte of 1,
51 followed by the path of a python script to load. */
52 #define AUTO_SECTION_NAME ".debug_gdb_scripts"
54 static void maybe_print_unsupported_script_warning
55 (struct auto_load_pspace_info
*, struct objfile
*objfile
,
56 const struct extension_language_defn
*language
,
57 const char *section_name
, unsigned offset
);
59 static void maybe_print_script_not_found_warning
60 (struct auto_load_pspace_info
*, struct objfile
*objfile
,
61 const struct extension_language_defn
*language
,
62 const char *section_name
, unsigned offset
);
64 /* Value of the 'set debug auto-load' configuration variable. */
65 static bool debug_auto_load
= false;
67 /* "show" command for the debug_auto_load configuration variable. */
70 show_debug_auto_load (struct ui_file
*file
, int from_tty
,
71 struct cmd_list_element
*c
, const char *value
)
73 fprintf_filtered (file
, _("Debugging output for files "
74 "of 'set auto-load ...' is %s.\n"),
78 /* User-settable option to enable/disable auto-loading of GDB_AUTO_FILE_NAME
80 set auto-load gdb-scripts on|off
81 This is true if we should auto-load associated scripts when an objfile
82 is opened, false otherwise. */
83 static bool auto_load_gdb_scripts
= true;
85 /* "show" command for the auto_load_gdb_scripts configuration variable. */
88 show_auto_load_gdb_scripts (struct ui_file
*file
, int from_tty
,
89 struct cmd_list_element
*c
, const char *value
)
91 fprintf_filtered (file
, _("Auto-loading of canned sequences of commands "
96 /* Return non-zero if auto-loading gdb scripts is enabled. */
99 auto_load_gdb_scripts_enabled (const struct extension_language_defn
*extlang
)
101 return auto_load_gdb_scripts
;
104 /* Internal-use flag to enable/disable auto-loading.
105 This is true if we should auto-load python code when an objfile is opened,
108 Both auto_load_scripts && global_auto_load must be true to enable
111 This flag exists to facilitate deferring auto-loading during start-up
112 until after ./.gdbinit has been read; it may augment the search directories
113 used to find the scripts. */
114 bool global_auto_load
= true;
116 /* Auto-load .gdbinit file from the current directory? */
117 bool auto_load_local_gdbinit
= true;
119 /* Absolute pathname to the current directory .gdbinit, if it exists. */
120 char *auto_load_local_gdbinit_pathname
= NULL
;
122 /* if AUTO_LOAD_LOCAL_GDBINIT_PATHNAME has been loaded. */
123 bool auto_load_local_gdbinit_loaded
= false;
125 /* "show" command for the auto_load_local_gdbinit configuration variable. */
128 show_auto_load_local_gdbinit (struct ui_file
*file
, int from_tty
,
129 struct cmd_list_element
*c
, const char *value
)
131 fprintf_filtered (file
, _("Auto-loading of .gdbinit script from current "
132 "directory is %s.\n"),
136 /* Directory list from which to load auto-loaded scripts. It is not checked
137 for absolute paths but they are strongly recommended. It is initialized by
138 _initialize_auto_load. */
139 static char *auto_load_dir
;
141 /* "set" command for the auto_load_dir configuration variable. */
144 set_auto_load_dir (const char *args
, int from_tty
, struct cmd_list_element
*c
)
146 /* Setting the variable to "" resets it to the compile time defaults. */
147 if (auto_load_dir
[0] == '\0')
149 xfree (auto_load_dir
);
150 auto_load_dir
= xstrdup (AUTO_LOAD_DIR
);
154 /* "show" command for the auto_load_dir configuration variable. */
157 show_auto_load_dir (struct ui_file
*file
, int from_tty
,
158 struct cmd_list_element
*c
, const char *value
)
160 fprintf_filtered (file
, _("List of directories from which to load "
161 "auto-loaded scripts is %s.\n"),
165 /* Directory list safe to hold auto-loaded files. It is not checked for
166 absolute paths but they are strongly recommended. It is initialized by
167 _initialize_auto_load. */
168 static char *auto_load_safe_path
;
170 /* Vector of directory elements of AUTO_LOAD_SAFE_PATH with each one normalized
171 by tilde_expand and possibly each entries has added its gdb_realpath
173 std::vector
<gdb::unique_xmalloc_ptr
<char>> auto_load_safe_path_vec
;
175 /* Expand $datadir and $debugdir in STRING according to the rules of
176 substitute_path_component. */
178 static std::vector
<gdb::unique_xmalloc_ptr
<char>>
179 auto_load_expand_dir_vars (const char *string
)
181 char *s
= xstrdup (string
);
182 substitute_path_component (&s
, "$datadir", gdb_datadir
.c_str ());
183 substitute_path_component (&s
, "$debugdir", debug_file_directory
);
185 if (debug_auto_load
&& strcmp (s
, string
) != 0)
186 fprintf_unfiltered (gdb_stdlog
,
187 _("auto-load: Expanded $-variables to \"%s\".\n"), s
);
189 std::vector
<gdb::unique_xmalloc_ptr
<char>> dir_vec
190 = dirnames_to_char_ptr_vec (s
);
196 /* Update auto_load_safe_path_vec from current AUTO_LOAD_SAFE_PATH. */
199 auto_load_safe_path_vec_update (void)
202 fprintf_unfiltered (gdb_stdlog
,
203 _("auto-load: Updating directories of \"%s\".\n"),
204 auto_load_safe_path
);
206 auto_load_safe_path_vec
= auto_load_expand_dir_vars (auto_load_safe_path
);
207 size_t len
= auto_load_safe_path_vec
.size ();
209 /* Apply tilde_expand and gdb_realpath to each AUTO_LOAD_SAFE_PATH_VEC
211 for (size_t i
= 0; i
< len
; i
++)
213 gdb::unique_xmalloc_ptr
<char> &in_vec
= auto_load_safe_path_vec
[i
];
214 gdb::unique_xmalloc_ptr
<char> expanded (tilde_expand (in_vec
.get ()));
215 gdb::unique_xmalloc_ptr
<char> real_path
= gdb_realpath (expanded
.get ());
217 /* Ensure the current entry is at least tilde_expand-ed. ORIGINAL makes
218 sure we free the original string. */
219 gdb::unique_xmalloc_ptr
<char> original
= std::move (in_vec
);
220 in_vec
= std::move (expanded
);
224 if (strcmp (in_vec
.get (), original
.get ()) == 0)
225 fprintf_unfiltered (gdb_stdlog
,
226 _("auto-load: Using directory \"%s\".\n"),
229 fprintf_unfiltered (gdb_stdlog
,
230 _("auto-load: Resolved directory \"%s\" "
232 original
.get (), in_vec
.get ());
235 /* If gdb_realpath returns a different content, append it. */
236 if (strcmp (real_path
.get (), in_vec
.get ()) != 0)
239 fprintf_unfiltered (gdb_stdlog
,
240 _("auto-load: And canonicalized as \"%s\".\n"),
243 auto_load_safe_path_vec
.push_back (std::move (real_path
));
248 /* Variable gdb_datadir has been set. Update content depending on $datadir. */
251 auto_load_gdb_datadir_changed (void)
253 auto_load_safe_path_vec_update ();
256 /* "set" command for the auto_load_safe_path configuration variable. */
259 set_auto_load_safe_path (const char *args
,
260 int from_tty
, struct cmd_list_element
*c
)
262 /* Setting the variable to "" resets it to the compile time defaults. */
263 if (auto_load_safe_path
[0] == '\0')
265 xfree (auto_load_safe_path
);
266 auto_load_safe_path
= xstrdup (AUTO_LOAD_SAFE_PATH
);
269 auto_load_safe_path_vec_update ();
272 /* "show" command for the auto_load_safe_path configuration variable. */
275 show_auto_load_safe_path (struct ui_file
*file
, int from_tty
,
276 struct cmd_list_element
*c
, const char *value
)
280 /* Check if user has entered either "/" or for example ":".
281 But while more complicate content like ":/foo" would still also
282 permit any location do not hide those. */
284 for (cs
= value
; *cs
&& (*cs
== DIRNAME_SEPARATOR
|| IS_DIR_SEPARATOR (*cs
));
287 fprintf_filtered (file
, _("Auto-load files are safe to load from any "
290 fprintf_filtered (file
, _("List of directories from which it is safe to "
291 "auto-load files is %s.\n"),
295 /* "add-auto-load-safe-path" command for the auto_load_safe_path configuration
299 add_auto_load_safe_path (const char *args
, int from_tty
)
303 if (args
== NULL
|| *args
== 0)
305 Directory argument required.\n\
306 Use 'set auto-load safe-path /' for disabling the auto-load safe-path security.\
309 s
= xstrprintf ("%s%c%s", auto_load_safe_path
, DIRNAME_SEPARATOR
, args
);
310 xfree (auto_load_safe_path
);
311 auto_load_safe_path
= s
;
313 auto_load_safe_path_vec_update ();
316 /* "add-auto-load-scripts-directory" command for the auto_load_dir configuration
320 add_auto_load_dir (const char *args
, int from_tty
)
324 if (args
== NULL
|| *args
== 0)
325 error (_("Directory argument required."));
327 s
= xstrprintf ("%s%c%s", auto_load_dir
, DIRNAME_SEPARATOR
, args
);
328 xfree (auto_load_dir
);
332 /* Implementation for filename_is_in_pattern overwriting the caller's FILENAME
336 filename_is_in_pattern_1 (char *filename
, char *pattern
)
338 size_t pattern_len
= strlen (pattern
);
339 size_t filename_len
= strlen (filename
);
342 fprintf_unfiltered (gdb_stdlog
, _("auto-load: Matching file \"%s\" "
343 "to pattern \"%s\"\n"),
346 /* Trim trailing slashes ("/") from PATTERN. Even for "d:\" paths as
347 trailing slashes are trimmed also from FILENAME it still matches
349 while (pattern_len
&& IS_DIR_SEPARATOR (pattern
[pattern_len
- 1]))
351 pattern
[pattern_len
] = '\0';
353 /* Ensure auto_load_safe_path "/" matches any FILENAME. On MS-Windows
354 platform FILENAME even after gdb_realpath does not have to start with
355 IS_DIR_SEPARATOR character, such as the 'C:\x.exe' filename. */
356 if (pattern_len
== 0)
359 fprintf_unfiltered (gdb_stdlog
,
360 _("auto-load: Matched - empty pattern\n"));
366 /* Trim trailing slashes ("/"). PATTERN also has slashes trimmed the
367 same way so they will match. */
368 while (filename_len
&& IS_DIR_SEPARATOR (filename
[filename_len
- 1]))
370 filename
[filename_len
] = '\0';
371 if (filename_len
== 0)
374 fprintf_unfiltered (gdb_stdlog
,
375 _("auto-load: Not matched - pattern \"%s\".\n"),
380 if (gdb_filename_fnmatch (pattern
, filename
, FNM_FILE_NAME
| FNM_NOESCAPE
)
384 fprintf_unfiltered (gdb_stdlog
, _("auto-load: Matched - file "
385 "\"%s\" to pattern \"%s\".\n"),
390 /* Trim trailing FILENAME component. */
391 while (filename_len
> 0 && !IS_DIR_SEPARATOR (filename
[filename_len
- 1]))
396 /* Return 1 if FILENAME matches PATTERN or if FILENAME resides in
397 a subdirectory of a directory that matches PATTERN. Return 0 otherwise.
398 gdb_realpath normalization is never done here. */
400 static ATTRIBUTE_PURE
int
401 filename_is_in_pattern (const char *filename
, const char *pattern
)
403 char *filename_copy
, *pattern_copy
;
405 filename_copy
= (char *) alloca (strlen (filename
) + 1);
406 strcpy (filename_copy
, filename
);
407 pattern_copy
= (char *) alloca (strlen (pattern
) + 1);
408 strcpy (pattern_copy
, pattern
);
410 return filename_is_in_pattern_1 (filename_copy
, pattern_copy
);
413 /* Return 1 if FILENAME belongs to one of directory components of
414 AUTO_LOAD_SAFE_PATH_VEC. Return 0 otherwise.
415 auto_load_safe_path_vec_update is never called.
416 *FILENAME_REALP may be updated by gdb_realpath of FILENAME. */
419 filename_is_in_auto_load_safe_path_vec (const char *filename
,
420 gdb::unique_xmalloc_ptr
<char> *filename_realp
)
422 const char *pattern
= NULL
;
424 for (const gdb::unique_xmalloc_ptr
<char> &p
: auto_load_safe_path_vec
)
425 if (*filename_realp
== NULL
&& filename_is_in_pattern (filename
, p
.get ()))
433 if (*filename_realp
== NULL
)
435 *filename_realp
= gdb_realpath (filename
);
436 if (debug_auto_load
&& strcmp (filename_realp
->get (), filename
) != 0)
437 fprintf_unfiltered (gdb_stdlog
,
438 _("auto-load: Resolved "
439 "file \"%s\" as \"%s\".\n"),
440 filename
, filename_realp
->get ());
443 if (strcmp (filename_realp
->get (), filename
) != 0)
444 for (const gdb::unique_xmalloc_ptr
<char> &p
: auto_load_safe_path_vec
)
445 if (filename_is_in_pattern (filename_realp
->get (), p
.get ()))
455 fprintf_unfiltered (gdb_stdlog
, _("auto-load: File \"%s\" matches "
456 "directory \"%s\".\n"),
464 /* Return 1 if FILENAME is located in one of the directories of
465 AUTO_LOAD_SAFE_PATH. Otherwise call warning and return 0. FILENAME does
466 not have to be an absolute path.
468 Existence of FILENAME is not checked. Function will still give a warning
469 even if the caller would quietly skip non-existing file in unsafe
473 file_is_auto_load_safe (const char *filename
, const char *debug_fmt
, ...)
475 gdb::unique_xmalloc_ptr
<char> filename_real
;
476 static int advice_printed
= 0;
482 va_start (debug_args
, debug_fmt
);
483 vfprintf_unfiltered (gdb_stdlog
, debug_fmt
, debug_args
);
487 if (filename_is_in_auto_load_safe_path_vec (filename
, &filename_real
))
490 auto_load_safe_path_vec_update ();
491 if (filename_is_in_auto_load_safe_path_vec (filename
, &filename_real
))
494 warning (_("File \"%ps\" auto-loading has been declined by your "
495 "`auto-load safe-path' set to \"%s\"."),
496 styled_string (file_name_style
.style (), filename_real
.get ()),
497 auto_load_safe_path
);
501 const char *homedir
= getenv ("HOME");
505 std::string homeinit
= string_printf ("%s/%s", homedir
, GDBINIT
);
507 printf_filtered (_("\
508 To enable execution of this file add\n\
509 \tadd-auto-load-safe-path %s\n\
510 line to your configuration file \"%s\".\n\
511 To completely disable this security protection add\n\
512 \tset auto-load safe-path /\n\
513 line to your configuration file \"%s\".\n\
514 For more information about this security protection see the\n\
515 \"Auto-loading safe path\" section in the GDB manual. E.g., run from the shell:\n\
516 \tinfo \"(gdb)Auto-loading safe path\"\n"),
517 filename_real
.get (),
518 homeinit
.c_str (), homeinit
.c_str ());
525 /* For scripts specified in .debug_gdb_scripts, multiple objfiles may load
526 the same script. There's no point in loading the script multiple times,
527 and there can be a lot of objfiles and scripts, so we keep track of scripts
530 struct auto_load_pspace_info
532 /* For each program space we keep track of loaded scripts, both when
533 specified as file names and as scripts to be executed directly. */
534 htab_up loaded_script_files
;
535 htab_up loaded_script_texts
;
537 /* Non-zero if we've issued the warning about an auto-load script not being
538 supported. We only want to issue this warning once. */
539 bool unsupported_script_warning_printed
= false;
541 /* Non-zero if we've issued the warning about an auto-load script not being
542 found. We only want to issue this warning once. */
543 bool script_not_found_warning_printed
= false;
546 /* Objects of this type are stored in the loaded_script hash table. */
550 /* Name as provided by the objfile. */
553 /* Full path name or NULL if script wasn't found (or was otherwise
554 inaccessible), or NULL for loaded_script_texts. */
555 const char *full_path
;
557 /* Non-zero if this script has been loaded. */
560 const struct extension_language_defn
*language
;
563 /* Per-program-space data key. */
564 static const struct program_space_key
<struct auto_load_pspace_info
>
565 auto_load_pspace_data
;
567 /* Get the current autoload data. If none is found yet, add it now. This
568 function always returns a valid object. */
570 static struct auto_load_pspace_info
*
571 get_auto_load_pspace_data (struct program_space
*pspace
)
573 struct auto_load_pspace_info
*info
;
575 info
= auto_load_pspace_data
.get (pspace
);
577 info
= auto_load_pspace_data
.emplace (pspace
);
582 /* Hash function for the loaded script hash. */
585 hash_loaded_script_entry (const void *data
)
587 const struct loaded_script
*e
= (const struct loaded_script
*) data
;
589 return htab_hash_string (e
->name
) ^ htab_hash_pointer (e
->language
);
592 /* Equality function for the loaded script hash. */
595 eq_loaded_script_entry (const void *a
, const void *b
)
597 const struct loaded_script
*ea
= (const struct loaded_script
*) a
;
598 const struct loaded_script
*eb
= (const struct loaded_script
*) b
;
600 return strcmp (ea
->name
, eb
->name
) == 0 && ea
->language
== eb
->language
;
603 /* Initialize the table to track loaded scripts.
604 Each entry is hashed by the full path name. */
607 init_loaded_scripts_info (struct auto_load_pspace_info
*pspace_info
)
609 /* Choose 31 as the starting size of the hash table, somewhat arbitrarily.
610 Space for each entry is obtained with one malloc so we can free them
613 pspace_info
->loaded_script_files
.reset
615 hash_loaded_script_entry
,
616 eq_loaded_script_entry
,
618 pspace_info
->loaded_script_texts
.reset
620 hash_loaded_script_entry
,
621 eq_loaded_script_entry
,
624 pspace_info
->unsupported_script_warning_printed
= false;
625 pspace_info
->script_not_found_warning_printed
= false;
628 /* Wrapper on get_auto_load_pspace_data to also allocate the hash table
629 for loading scripts. */
631 struct auto_load_pspace_info
*
632 get_auto_load_pspace_data_for_loading (struct program_space
*pspace
)
634 struct auto_load_pspace_info
*info
;
636 info
= get_auto_load_pspace_data (pspace
);
637 if (info
->loaded_script_files
== NULL
)
638 init_loaded_scripts_info (info
);
643 /* Add script file NAME in LANGUAGE to hash table of PSPACE_INFO.
644 LOADED 1 if the script has been (is going to) be loaded, 0 otherwise
645 (such as if it has not been found).
646 FULL_PATH is NULL if the script wasn't found.
647 The result is true if the script was already in the hash table. */
650 maybe_add_script_file (struct auto_load_pspace_info
*pspace_info
, int loaded
,
651 const char *name
, const char *full_path
,
652 const struct extension_language_defn
*language
)
654 struct htab
*htab
= pspace_info
->loaded_script_files
.get ();
655 struct loaded_script
**slot
, entry
;
659 entry
.language
= language
;
660 slot
= (struct loaded_script
**) htab_find_slot (htab
, &entry
, INSERT
);
661 in_hash_table
= *slot
!= NULL
;
663 /* If this script is not in the hash table, add it. */
669 /* Allocate all space in one chunk so it's easier to free. */
670 *slot
= ((struct loaded_script
*)
671 xmalloc (sizeof (**slot
)
673 + (full_path
!= NULL
? (strlen (full_path
) + 1) : 0)));
674 p
= ((char*) *slot
) + sizeof (**slot
);
677 if (full_path
!= NULL
)
680 strcpy (p
, full_path
);
681 (*slot
)->full_path
= p
;
684 (*slot
)->full_path
= NULL
;
685 (*slot
)->loaded
= loaded
;
686 (*slot
)->language
= language
;
689 return in_hash_table
;
692 /* Add script contents NAME in LANGUAGE to hash table of PSPACE_INFO.
693 LOADED 1 if the script has been (is going to) be loaded, 0 otherwise
694 (such as if it has not been found).
695 The result is true if the script was already in the hash table. */
698 maybe_add_script_text (struct auto_load_pspace_info
*pspace_info
,
699 int loaded
, const char *name
,
700 const struct extension_language_defn
*language
)
702 struct htab
*htab
= pspace_info
->loaded_script_texts
.get ();
703 struct loaded_script
**slot
, entry
;
707 entry
.language
= language
;
708 slot
= (struct loaded_script
**) htab_find_slot (htab
, &entry
, INSERT
);
709 in_hash_table
= *slot
!= NULL
;
711 /* If this script is not in the hash table, add it. */
717 /* Allocate all space in one chunk so it's easier to free. */
718 *slot
= ((struct loaded_script
*)
719 xmalloc (sizeof (**slot
) + strlen (name
) + 1));
720 p
= ((char*) *slot
) + sizeof (**slot
);
723 (*slot
)->full_path
= NULL
;
724 (*slot
)->loaded
= loaded
;
725 (*slot
)->language
= language
;
728 return in_hash_table
;
731 /* Clear the table of loaded section scripts. */
734 clear_section_scripts (void)
736 struct program_space
*pspace
= current_program_space
;
737 struct auto_load_pspace_info
*info
;
739 info
= auto_load_pspace_data
.get (pspace
);
740 if (info
!= NULL
&& info
->loaded_script_files
!= NULL
)
741 auto_load_pspace_data
.clear (pspace
);
744 /* Look for the auto-load script in LANGUAGE associated with OBJFILE where
745 OBJFILE's gdb_realpath is REALNAME and load it. Return 1 if we found any
746 matching script, return 0 otherwise. */
749 auto_load_objfile_script_1 (struct objfile
*objfile
, const char *realname
,
750 const struct extension_language_defn
*language
)
752 const char *debugfile
;
754 const char *suffix
= ext_lang_auto_load_suffix (language
);
756 std::string filename
= std::string (realname
) + suffix
;
758 gdb_file_up input
= gdb_fopen_cloexec (filename
.c_str (), "r");
759 debugfile
= filename
.c_str ();
761 fprintf_unfiltered (gdb_stdlog
, _("auto-load: Attempted file \"%s\" %s.\n"),
762 debugfile
, input
? _("exists") : _("does not exist"));
764 std::string debugfile_holder
;
767 /* Also try the same file in a subdirectory of gdb's data
770 std::vector
<gdb::unique_xmalloc_ptr
<char>> vec
771 = auto_load_expand_dir_vars (auto_load_dir
);
774 fprintf_unfiltered (gdb_stdlog
, _("auto-load: Searching 'set auto-load "
775 "scripts-directory' path \"%s\".\n"),
778 /* Convert Windows file name from c:/dir/file to /c/dir/file. */
779 if (HAS_DRIVE_SPEC (debugfile
))
781 debugfile_holder
= STRIP_DRIVE_SPEC (debugfile
);
782 filename
= std::string("\\") + debugfile
[0] + debugfile_holder
;
785 for (const gdb::unique_xmalloc_ptr
<char> &dir
: vec
)
787 /* FILENAME is absolute, so we don't need a "/" here. */
788 debugfile_holder
= dir
.get () + filename
;
789 debugfile
= debugfile_holder
.c_str ();
791 input
= gdb_fopen_cloexec (debugfile
, "r");
793 fprintf_unfiltered (gdb_stdlog
, _("auto-load: Attempted file "
796 input
? _("exists") : _("does not exist"));
805 struct auto_load_pspace_info
*pspace_info
;
808 = file_is_auto_load_safe (debugfile
,
809 _("auto-load: Loading %s script \"%s\""
810 " by extension for objfile \"%s\".\n"),
811 ext_lang_name (language
),
812 debugfile
, objfile_name (objfile
));
814 /* Add this script to the hash table too so
815 "info auto-load ${lang}-scripts" can print it. */
817 = get_auto_load_pspace_data_for_loading (current_program_space
);
818 maybe_add_script_file (pspace_info
, is_safe
, debugfile
, debugfile
,
821 /* To preserve existing behaviour we don't check for whether the
822 script was already in the table, and always load it.
823 It's highly unlikely that we'd ever load it twice,
824 and these scripts are required to be idempotent under multiple
828 objfile_script_sourcer_func
*sourcer
829 = ext_lang_objfile_script_sourcer (language
);
831 /* We shouldn't get here if support for the language isn't
832 compiled in. And the extension language is required to implement
834 gdb_assert (sourcer
!= NULL
);
835 sourcer (language
, objfile
, input
.get (), debugfile
);
846 /* Look for the auto-load script in LANGUAGE associated with OBJFILE and load
850 auto_load_objfile_script (struct objfile
*objfile
,
851 const struct extension_language_defn
*language
)
853 gdb::unique_xmalloc_ptr
<char> realname
854 = gdb_realpath (objfile_name (objfile
));
856 if (!auto_load_objfile_script_1 (objfile
, realname
.get (), language
))
858 /* For Windows/DOS .exe executables, strip the .exe suffix, so that
859 FOO-gdb.gdb could be used for FOO.exe, and try again. */
861 size_t len
= strlen (realname
.get ());
862 const size_t lexe
= sizeof (".exe") - 1;
864 if (len
> lexe
&& strcasecmp (realname
.get () + len
- lexe
, ".exe") == 0)
867 realname
.get ()[len
] = '\0';
869 fprintf_unfiltered (gdb_stdlog
, _("auto-load: Stripped .exe suffix, "
870 "retrying with \"%s\".\n"),
872 auto_load_objfile_script_1 (objfile
, realname
.get (), language
);
877 /* Subroutine of source_section_scripts to simplify it.
878 Load FILE as a script in extension language LANGUAGE.
879 The script is from section SECTION_NAME in OBJFILE at offset OFFSET. */
882 source_script_file (struct auto_load_pspace_info
*pspace_info
,
883 struct objfile
*objfile
,
884 const struct extension_language_defn
*language
,
885 const char *section_name
, unsigned int offset
,
889 objfile_script_sourcer_func
*sourcer
;
891 /* Skip this script if support is not compiled in. */
892 sourcer
= ext_lang_objfile_script_sourcer (language
);
895 /* We don't throw an error, the program is still debuggable. */
896 maybe_print_unsupported_script_warning (pspace_info
, objfile
, language
,
897 section_name
, offset
);
898 /* We *could* still try to open it, but there's no point. */
899 maybe_add_script_file (pspace_info
, 0, file
, NULL
, language
);
903 /* Skip this script if auto-loading it has been disabled. */
904 if (!ext_lang_auto_load_enabled (language
))
906 /* No message is printed, just skip it. */
910 gdb::optional
<open_script
> opened
= find_and_open_script (file
,
915 if (!file_is_auto_load_safe (opened
->full_path
.get (),
916 _("auto-load: Loading %s script "
917 "\"%s\" from section \"%s\" of "
918 "objfile \"%s\".\n"),
919 ext_lang_name (language
),
920 opened
->full_path
.get (),
921 section_name
, objfile_name (objfile
)))
926 /* If one script isn't found it's not uncommon for more to not be
927 found either. We don't want to print a message for each script,
928 too much noise. Instead, we print the warning once and tell the
929 user how to find the list of scripts that weren't loaded.
930 We don't throw an error, the program is still debuggable.
932 IWBN if complaints.c were more general-purpose. */
934 maybe_print_script_not_found_warning (pspace_info
, objfile
, language
,
935 section_name
, offset
);
938 in_hash_table
= maybe_add_script_file (pspace_info
, bool (opened
), file
,
940 ? opened
->full_path
.get ()
944 /* If this file is not currently loaded, load it. */
945 if (opened
&& !in_hash_table
)
946 sourcer (language
, objfile
, opened
->stream
.get (),
947 opened
->full_path
.get ());
950 /* Subroutine of source_section_scripts to simplify it.
951 Execute SCRIPT as a script in extension language LANG.
952 The script is from section SECTION_NAME in OBJFILE at offset OFFSET. */
955 execute_script_contents (struct auto_load_pspace_info
*pspace_info
,
956 struct objfile
*objfile
,
957 const struct extension_language_defn
*language
,
958 const char *section_name
, unsigned int offset
,
961 objfile_script_executor_func
*executor
;
962 const char *newline
, *script_text
;
964 int is_safe
, in_hash_table
;
966 /* The first line of the script is the name of the script.
967 It must not contain any kind of space character. */
969 newline
= strchr (script
, '\n');
970 std::string name_holder
;
975 /* Put the name in a buffer and validate it. */
976 name_holder
= std::string (script
, newline
- script
);
977 buf
= name_holder
.c_str ();
978 for (p
= buf
; *p
!= '\0'; ++p
)
983 /* We don't allow nameless scripts, they're not helpful to the user. */
984 if (p
!= buf
&& *p
== '\0')
989 /* We don't throw an error, the program is still debuggable. */
991 Missing/bad script name in entry at offset %u in section %s\n\
993 offset
, section_name
,
994 styled_string (file_name_style
.style (),
995 objfile_name (objfile
)));
998 script_text
= newline
+ 1;
1000 /* Skip this script if support is not compiled in. */
1001 executor
= ext_lang_objfile_script_executor (language
);
1002 if (executor
== NULL
)
1004 /* We don't throw an error, the program is still debuggable. */
1005 maybe_print_unsupported_script_warning (pspace_info
, objfile
, language
,
1006 section_name
, offset
);
1007 maybe_add_script_text (pspace_info
, 0, name
, language
);
1011 /* Skip this script if auto-loading it has been disabled. */
1012 if (!ext_lang_auto_load_enabled (language
))
1014 /* No message is printed, just skip it. */
1018 is_safe
= file_is_auto_load_safe (objfile_name (objfile
),
1019 _("auto-load: Loading %s script "
1020 "\"%s\" from section \"%s\" of "
1021 "objfile \"%s\".\n"),
1022 ext_lang_name (language
), name
,
1023 section_name
, objfile_name (objfile
));
1025 in_hash_table
= maybe_add_script_text (pspace_info
, is_safe
, name
, language
);
1027 /* If this file is not currently loaded, load it. */
1028 if (is_safe
&& !in_hash_table
)
1029 executor (language
, objfile
, name
, script_text
);
1032 /* Load scripts specified in OBJFILE.
1033 START,END delimit a buffer containing a list of nul-terminated
1035 SECTION_NAME is used in error messages.
1037 Scripts specified as file names are found per normal "source -s" command
1038 processing. First the script is looked for in $cwd. If not found there
1039 the source search path is used.
1041 The section contains a list of path names of script files to load or
1042 actual script contents. Each entry is nul-terminated. */
1045 source_section_scripts (struct objfile
*objfile
, const char *section_name
,
1046 const char *start
, const char *end
)
1049 struct auto_load_pspace_info
*pspace_info
;
1051 pspace_info
= get_auto_load_pspace_data_for_loading (current_program_space
);
1053 for (p
= start
; p
< end
; ++p
)
1056 const struct extension_language_defn
*language
;
1057 unsigned int offset
= p
- start
;
1062 case SECTION_SCRIPT_ID_PYTHON_FILE
:
1063 case SECTION_SCRIPT_ID_PYTHON_TEXT
:
1064 language
= get_ext_lang_defn (EXT_LANG_PYTHON
);
1066 case SECTION_SCRIPT_ID_SCHEME_FILE
:
1067 case SECTION_SCRIPT_ID_SCHEME_TEXT
:
1068 language
= get_ext_lang_defn (EXT_LANG_GUILE
);
1071 warning (_("Invalid entry in %s section"), section_name
);
1072 /* We could try various heuristics to find the next valid entry,
1073 but it's safer to just punt. */
1078 while (p
< end
&& *p
!= '\0')
1082 warning (_("Non-nul-terminated entry in %s at offset %u"),
1083 section_name
, offset
);
1084 /* Don't load/execute it. */
1090 case SECTION_SCRIPT_ID_PYTHON_FILE
:
1091 case SECTION_SCRIPT_ID_SCHEME_FILE
:
1094 warning (_("Empty entry in %s at offset %u"),
1095 section_name
, offset
);
1098 source_script_file (pspace_info
, objfile
, language
,
1099 section_name
, offset
, entry
);
1101 case SECTION_SCRIPT_ID_PYTHON_TEXT
:
1102 case SECTION_SCRIPT_ID_SCHEME_TEXT
:
1103 execute_script_contents (pspace_info
, objfile
, language
,
1104 section_name
, offset
, entry
);
1110 /* Load scripts specified in section SECTION_NAME of OBJFILE. */
1113 auto_load_section_scripts (struct objfile
*objfile
, const char *section_name
)
1115 bfd
*abfd
= objfile
->obfd
;
1116 asection
*scripts_sect
;
1117 bfd_byte
*data
= NULL
;
1119 scripts_sect
= bfd_get_section_by_name (abfd
, section_name
);
1120 if (scripts_sect
== NULL
1121 || (bfd_section_flags (scripts_sect
) & SEC_HAS_CONTENTS
) == 0)
1124 if (!bfd_get_full_section_contents (abfd
, scripts_sect
, &data
))
1125 warning (_("Couldn't read %s section of %ps"),
1127 styled_string (file_name_style
.style (),
1128 bfd_get_filename (abfd
)));
1131 gdb::unique_xmalloc_ptr
<bfd_byte
> data_holder (data
);
1133 char *p
= (char *) data
;
1134 source_section_scripts (objfile
, section_name
, p
,
1135 p
+ bfd_section_size (scripts_sect
));
1139 /* Load any auto-loaded scripts for OBJFILE. */
1142 load_auto_scripts_for_objfile (struct objfile
*objfile
)
1144 /* Return immediately if auto-loading has been globally disabled.
1145 This is to handle sequencing of operations during gdb startup.
1146 Also return immediately if OBJFILE was not created from a file
1147 on the local filesystem. */
1148 if (!global_auto_load
1149 || (objfile
->flags
& OBJF_NOT_FILENAME
) != 0
1150 || is_target_filename (objfile
->original_name
))
1153 /* Load any extension language scripts for this objfile.
1154 E.g., foo-gdb.gdb, foo-gdb.py. */
1155 auto_load_ext_lang_scripts_for_objfile (objfile
);
1157 /* Load any scripts mentioned in AUTO_SECTION_NAME (.debug_gdb_scripts). */
1158 auto_load_section_scripts (objfile
, AUTO_SECTION_NAME
);
1161 /* This is a new_objfile observer callback to auto-load scripts.
1163 Two flavors of auto-loaded scripts are supported.
1164 1) based on the path to the objfile
1165 2) from .debug_gdb_scripts section */
1168 auto_load_new_objfile (struct objfile
*objfile
)
1172 /* OBJFILE is NULL when loading a new "main" symbol-file. */
1173 clear_section_scripts ();
1177 load_auto_scripts_for_objfile (objfile
);
1180 /* Collect scripts to be printed in a vec. */
1182 struct collect_matching_scripts_data
1184 collect_matching_scripts_data (std::vector
<loaded_script
*> *scripts_p_
,
1185 const extension_language_defn
*language_
)
1186 : scripts_p (scripts_p_
), language (language_
)
1189 std::vector
<loaded_script
*> *scripts_p
;
1190 const struct extension_language_defn
*language
;
1193 /* Traversal function for htab_traverse.
1194 Collect the entry if it matches the regexp. */
1197 collect_matching_scripts (void **slot
, void *info
)
1199 struct loaded_script
*script
= (struct loaded_script
*) *slot
;
1200 struct collect_matching_scripts_data
*data
1201 = (struct collect_matching_scripts_data
*) info
;
1203 if (script
->language
== data
->language
&& re_exec (script
->name
))
1204 data
->scripts_p
->push_back (script
);
1212 print_script (struct loaded_script
*script
)
1214 struct ui_out
*uiout
= current_uiout
;
1216 ui_out_emit_tuple
tuple_emitter (uiout
, NULL
);
1218 uiout
->field_string ("loaded", script
->loaded
? "Yes" : "No");
1219 uiout
->field_string ("script", script
->name
);
1222 /* If the name isn't the full path, print it too. */
1223 if (script
->full_path
!= NULL
1224 && strcmp (script
->name
, script
->full_path
) != 0)
1226 uiout
->text ("\tfull name: ");
1227 uiout
->field_string ("full_path", script
->full_path
);
1232 /* Helper for info_auto_load_scripts to sort the scripts by name. */
1235 sort_scripts_by_name (loaded_script
*a
, loaded_script
*b
)
1237 return FILENAME_CMP (a
->name
, b
->name
) < 0;
1240 /* Special internal GDB value of auto_load_info_scripts's PATTERN identify
1241 the "info auto-load XXX" command has been executed through the general
1242 "info auto-load" invocation. Extra newline will be printed if needed. */
1243 char auto_load_info_scripts_pattern_nl
[] = "";
1245 /* Subroutine of auto_load_info_scripts to simplify it.
1249 print_scripts (const std::vector
<loaded_script
*> &scripts
)
1251 for (loaded_script
*script
: scripts
)
1252 print_script (script
);
1255 /* Implementation for "info auto-load gdb-scripts"
1256 (and "info auto-load python-scripts"). List scripts in LANGUAGE matching
1257 PATTERN. FROM_TTY is the usual GDB boolean for user interactivity. */
1260 auto_load_info_scripts (const char *pattern
, int from_tty
,
1261 const struct extension_language_defn
*language
)
1263 struct ui_out
*uiout
= current_uiout
;
1264 struct auto_load_pspace_info
*pspace_info
;
1268 pspace_info
= get_auto_load_pspace_data (current_program_space
);
1270 if (pattern
&& *pattern
)
1272 char *re_err
= re_comp (pattern
);
1275 error (_("Invalid regexp: %s"), re_err
);
1282 /* We need to know the number of rows before we build the table.
1283 Plus we want to sort the scripts by name.
1284 So first traverse the hash table collecting the matching scripts. */
1286 std::vector
<loaded_script
*> script_files
, script_texts
;
1288 if (pspace_info
!= NULL
&& pspace_info
->loaded_script_files
!= NULL
)
1290 collect_matching_scripts_data
data (&script_files
, language
);
1292 /* Pass a pointer to scripts as VEC_safe_push can realloc space. */
1293 htab_traverse_noresize (pspace_info
->loaded_script_files
.get (),
1294 collect_matching_scripts
, &data
);
1296 std::sort (script_files
.begin (), script_files
.end (),
1297 sort_scripts_by_name
);
1300 if (pspace_info
!= NULL
&& pspace_info
->loaded_script_texts
!= NULL
)
1302 collect_matching_scripts_data
data (&script_texts
, language
);
1304 /* Pass a pointer to scripts as VEC_safe_push can realloc space. */
1305 htab_traverse_noresize (pspace_info
->loaded_script_texts
.get (),
1306 collect_matching_scripts
, &data
);
1308 std::sort (script_texts
.begin (), script_texts
.end (),
1309 sort_scripts_by_name
);
1312 int nr_scripts
= script_files
.size () + script_texts
.size ();
1314 /* Table header shifted right by preceding "gdb-scripts: " would not match
1316 if (nr_scripts
> 0 && pattern
== auto_load_info_scripts_pattern_nl
)
1320 ui_out_emit_table
table_emitter (uiout
, 2, nr_scripts
,
1321 "AutoLoadedScriptsTable");
1323 uiout
->table_header (7, ui_left
, "loaded", "Loaded");
1324 uiout
->table_header (70, ui_left
, "script", "Script");
1325 uiout
->table_body ();
1327 print_scripts (script_files
);
1328 print_scripts (script_texts
);
1331 if (nr_scripts
== 0)
1333 if (pattern
&& *pattern
)
1334 uiout
->message ("No auto-load scripts matching %s.\n", pattern
);
1336 uiout
->message ("No auto-load scripts.\n");
1340 /* Wrapper for "info auto-load gdb-scripts". */
1343 info_auto_load_gdb_scripts (const char *pattern
, int from_tty
)
1345 auto_load_info_scripts (pattern
, from_tty
, &extension_language_gdb
);
1348 /* Implement 'info auto-load local-gdbinit'. */
1351 info_auto_load_local_gdbinit (const char *args
, int from_tty
)
1353 if (auto_load_local_gdbinit_pathname
== NULL
)
1354 printf_filtered (_("Local .gdbinit file was not found.\n"));
1355 else if (auto_load_local_gdbinit_loaded
)
1356 printf_filtered (_("Local .gdbinit file \"%ps\" has been loaded.\n"),
1357 styled_string (file_name_style
.style (),
1358 auto_load_local_gdbinit_pathname
));
1360 printf_filtered (_("Local .gdbinit file \"%ps\" has not been loaded.\n"),
1361 styled_string (file_name_style
.style (),
1362 auto_load_local_gdbinit_pathname
));
1365 /* Print an "unsupported script" warning if it has not already been printed.
1366 The script is in language LANGUAGE at offset OFFSET in section SECTION_NAME
1370 maybe_print_unsupported_script_warning
1371 (struct auto_load_pspace_info
*pspace_info
,
1372 struct objfile
*objfile
, const struct extension_language_defn
*language
,
1373 const char *section_name
, unsigned offset
)
1375 if (!pspace_info
->unsupported_script_warning_printed
)
1378 Unsupported auto-load script at offset %u in section %s\n\
1380 Use `info auto-load %s-scripts [REGEXP]' to list them."),
1381 offset
, section_name
,
1382 styled_string (file_name_style
.style (),
1383 objfile_name (objfile
)),
1384 ext_lang_name (language
));
1385 pspace_info
->unsupported_script_warning_printed
= true;
1389 /* Return non-zero if SCRIPT_NOT_FOUND_WARNING_PRINTED of PSPACE_INFO was unset
1390 before calling this function. Always set SCRIPT_NOT_FOUND_WARNING_PRINTED
1394 maybe_print_script_not_found_warning
1395 (struct auto_load_pspace_info
*pspace_info
,
1396 struct objfile
*objfile
, const struct extension_language_defn
*language
,
1397 const char *section_name
, unsigned offset
)
1399 if (!pspace_info
->script_not_found_warning_printed
)
1402 Missing auto-load script at offset %u in section %s\n\
1404 Use `info auto-load %s-scripts [REGEXP]' to list them."),
1405 offset
, section_name
,
1406 styled_string (file_name_style
.style (),
1407 objfile_name (objfile
)),
1408 ext_lang_name (language
));
1409 pspace_info
->script_not_found_warning_printed
= true;
1413 /* The only valid "set auto-load" argument is off|0|no|disable. */
1416 set_auto_load_cmd (const char *args
, int from_tty
)
1418 struct cmd_list_element
*list
;
1421 /* See parse_binary_operation in use by the sub-commands. */
1423 length
= args
? strlen (args
) : 0;
1425 while (length
> 0 && (args
[length
- 1] == ' ' || args
[length
- 1] == '\t'))
1428 if (length
== 0 || (strncmp (args
, "off", length
) != 0
1429 && strncmp (args
, "0", length
) != 0
1430 && strncmp (args
, "no", length
) != 0
1431 && strncmp (args
, "disable", length
) != 0))
1432 error (_("Valid is only global 'set auto-load no'; "
1433 "otherwise check the auto-load sub-commands."));
1435 for (list
= *auto_load_set_cmdlist_get (); list
!= NULL
; list
= list
->next
)
1436 if (list
->var_type
== var_boolean
)
1438 gdb_assert (list
->type
== set_cmd
);
1439 do_set_command (args
, from_tty
, list
);
1443 /* Initialize "set auto-load " commands prefix and return it. */
1445 struct cmd_list_element
**
1446 auto_load_set_cmdlist_get (void)
1448 static struct cmd_list_element
*retval
;
1451 add_prefix_cmd ("auto-load", class_maintenance
, set_auto_load_cmd
, _("\
1452 Auto-loading specific settings.\n\
1453 Configure various auto-load-specific variables such as\n\
1454 automatic loading of Python scripts."),
1455 &retval
, "set auto-load ",
1456 1/*allow-unknown*/, &setlist
);
1461 /* Initialize "show auto-load " commands prefix and return it. */
1463 struct cmd_list_element
**
1464 auto_load_show_cmdlist_get (void)
1466 static struct cmd_list_element
*retval
;
1469 add_show_prefix_cmd ("auto-load", class_maintenance
, _("\
1470 Show auto-loading specific settings.\n\
1471 Show configuration of various auto-load-specific variables such as\n\
1472 automatic loading of Python scripts."),
1473 &retval
, "show auto-load ",
1474 0/*allow-unknown*/, &showlist
);
1479 /* Command "info auto-load" displays whether the various auto-load files have
1480 been loaded. This is reimplementation of cmd_show_list which inserts
1481 newlines at proper places. */
1484 info_auto_load_cmd (const char *args
, int from_tty
)
1486 struct cmd_list_element
*list
;
1487 struct ui_out
*uiout
= current_uiout
;
1489 ui_out_emit_tuple
tuple_emitter (uiout
, "infolist");
1491 for (list
= *auto_load_info_cmdlist_get (); list
!= NULL
; list
= list
->next
)
1493 ui_out_emit_tuple
option_emitter (uiout
, "option");
1495 gdb_assert (!list
->prefixlist
);
1496 gdb_assert (list
->type
== not_set_cmd
);
1498 uiout
->field_string ("name", list
->name
);
1500 cmd_func (list
, auto_load_info_scripts_pattern_nl
, from_tty
);
1504 /* Initialize "info auto-load " commands prefix and return it. */
1506 struct cmd_list_element
**
1507 auto_load_info_cmdlist_get (void)
1509 static struct cmd_list_element
*retval
;
1512 add_prefix_cmd ("auto-load", class_info
, info_auto_load_cmd
, _("\
1513 Print current status of auto-loaded files.\n\
1514 Print whether various files like Python scripts or .gdbinit files have been\n\
1515 found and/or loaded."),
1516 &retval
, "info auto-load ",
1517 0/*allow-unknown*/, &infolist
);
1522 void _initialize_auto_load ();
1524 _initialize_auto_load ()
1526 struct cmd_list_element
*cmd
;
1527 char *scripts_directory_help
, *gdb_name_help
, *python_name_help
;
1528 char *guile_name_help
;
1531 gdb::observers::new_objfile
.attach (auto_load_new_objfile
);
1533 add_setshow_boolean_cmd ("gdb-scripts", class_support
,
1534 &auto_load_gdb_scripts
, _("\
1535 Enable or disable auto-loading of canned sequences of commands scripts."), _("\
1536 Show whether auto-loading of canned sequences of commands scripts is enabled."),
1538 If enabled, canned sequences of commands are loaded when the debugger reads\n\
1539 an executable or shared library.\n\
1540 This option has security implications for untrusted inferiors."),
1541 NULL
, show_auto_load_gdb_scripts
,
1542 auto_load_set_cmdlist_get (),
1543 auto_load_show_cmdlist_get ());
1545 add_cmd ("gdb-scripts", class_info
, info_auto_load_gdb_scripts
,
1546 _("Print the list of automatically loaded sequences of commands.\n\
1547 Usage: info auto-load gdb-scripts [REGEXP]"),
1548 auto_load_info_cmdlist_get ());
1550 add_setshow_boolean_cmd ("local-gdbinit", class_support
,
1551 &auto_load_local_gdbinit
, _("\
1552 Enable or disable auto-loading of .gdbinit script in current directory."), _("\
1553 Show whether auto-loading .gdbinit script in current directory is enabled."),
1555 If enabled, canned sequences of commands are loaded when debugger starts\n\
1556 from .gdbinit file in current directory. Such files are deprecated,\n\
1557 use a script associated with inferior executable file instead.\n\
1558 This option has security implications for untrusted inferiors."),
1559 NULL
, show_auto_load_local_gdbinit
,
1560 auto_load_set_cmdlist_get (),
1561 auto_load_show_cmdlist_get ());
1563 add_cmd ("local-gdbinit", class_info
, info_auto_load_local_gdbinit
,
1564 _("Print whether current directory .gdbinit file has been loaded.\n\
1565 Usage: info auto-load local-gdbinit"),
1566 auto_load_info_cmdlist_get ());
1568 auto_load_dir
= xstrdup (AUTO_LOAD_DIR
);
1570 suffix
= ext_lang_auto_load_suffix (get_ext_lang_defn (EXT_LANG_GDB
));
1573 GDB scripts: OBJFILE%s\n"),
1575 python_name_help
= NULL
;
1577 suffix
= ext_lang_auto_load_suffix (get_ext_lang_defn (EXT_LANG_PYTHON
));
1580 Python scripts: OBJFILE%s\n"),
1583 guile_name_help
= NULL
;
1585 suffix
= ext_lang_auto_load_suffix (get_ext_lang_defn (EXT_LANG_GUILE
));
1588 Guile scripts: OBJFILE%s\n"),
1591 scripts_directory_help
1593 Automatically loaded scripts are located in one of the directories listed\n\
1599 This option is ignored for the kinds of scripts \
1600 having 'set auto-load ... off'.\n\
1601 Directories listed here need to be present also \
1602 in the 'set auto-load safe-path'\n\
1605 python_name_help
? python_name_help
: "",
1606 guile_name_help
? guile_name_help
: "");
1608 add_setshow_optional_filename_cmd ("scripts-directory", class_support
,
1609 &auto_load_dir
, _("\
1610 Set the list of directories from which to load auto-loaded scripts."), _("\
1611 Show the list of directories from which to load auto-loaded scripts."),
1612 scripts_directory_help
,
1613 set_auto_load_dir
, show_auto_load_dir
,
1614 auto_load_set_cmdlist_get (),
1615 auto_load_show_cmdlist_get ());
1616 xfree (scripts_directory_help
);
1617 xfree (python_name_help
);
1618 xfree (gdb_name_help
);
1619 xfree (guile_name_help
);
1621 auto_load_safe_path
= xstrdup (AUTO_LOAD_SAFE_PATH
);
1622 auto_load_safe_path_vec_update ();
1623 add_setshow_optional_filename_cmd ("safe-path", class_support
,
1624 &auto_load_safe_path
, _("\
1625 Set the list of files and directories that are safe for auto-loading."), _("\
1626 Show the list of files and directories that are safe for auto-loading."), _("\
1627 Various files loaded automatically for the 'set auto-load ...' options must\n\
1628 be located in one of the directories listed by this option. Warning will be\n\
1629 printed and file will not be used otherwise.\n\
1630 You can mix both directory and filename entries.\n\
1631 Setting this parameter to an empty list resets it to its default value.\n\
1632 Setting this parameter to '/' (without the quotes) allows any file\n\
1633 for the 'set auto-load ...' options. Each path entry can be also shell\n\
1634 wildcard pattern; '*' does not match directory separator.\n\
1635 This option is ignored for the kinds of files having 'set auto-load ... off'.\n\
1636 This option has security implications for untrusted inferiors."),
1637 set_auto_load_safe_path
,
1638 show_auto_load_safe_path
,
1639 auto_load_set_cmdlist_get (),
1640 auto_load_show_cmdlist_get ());
1641 gdb::observers::gdb_datadir_changed
.attach (auto_load_gdb_datadir_changed
);
1643 cmd
= add_cmd ("add-auto-load-safe-path", class_support
,
1644 add_auto_load_safe_path
,
1645 _("Add entries to the list of directories from which it is safe "
1646 "to auto-load files.\n\
1647 See the commands 'set auto-load safe-path' and 'show auto-load safe-path' to\n\
1648 access the current full list setting."),
1650 set_cmd_completer (cmd
, filename_completer
);
1652 cmd
= add_cmd ("add-auto-load-scripts-directory", class_support
,
1654 _("Add entries to the list of directories from which to load "
1655 "auto-loaded scripts.\n\
1656 See the commands 'set auto-load scripts-directory' and\n\
1657 'show auto-load scripts-directory' to access the current full list setting."),
1659 set_cmd_completer (cmd
, filename_completer
);
1661 add_setshow_boolean_cmd ("auto-load", class_maintenance
,
1662 &debug_auto_load
, _("\
1663 Set auto-load verifications debugging."), _("\
1664 Show auto-load verifications debugging."), _("\
1665 When non-zero, debugging output for files of 'set auto-load ...'\n\
1667 NULL
, show_debug_auto_load
,
1668 &setdebuglist
, &showdebuglist
);