1 /* GDB routines for supporting auto-loaded scripts.
3 Copyright (C) 2012-2016 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"
30 #include "cli/cli-script.h"
32 #include "cli/cli-cmds.h"
33 #include "cli/cli-decode.h"
34 #include "cli/cli-setshow.h"
36 #include "readline/tilde.h"
37 #include "completer.h"
40 #include "filestuff.h"
41 #include "extension.h"
42 #include "gdb/section-scripts.h"
44 /* The section to look in for auto-loaded scripts (in file formats that
46 Each entry in this section is a record that begins with a leading byte
47 identifying the record type.
48 At the moment we only support one record type: A leading byte of 1,
49 followed by the path of a python script to load. */
50 #define AUTO_SECTION_NAME ".debug_gdb_scripts"
52 static void maybe_print_unsupported_script_warning
53 (struct auto_load_pspace_info *, struct objfile *objfile,
54 const struct extension_language_defn *language,
55 const char *section_name, unsigned offset);
57 static void maybe_print_script_not_found_warning
58 (struct auto_load_pspace_info *, struct objfile *objfile,
59 const struct extension_language_defn *language,
60 const char *section_name, unsigned offset);
62 /* Value of the 'set debug auto-load' configuration variable. */
63 static int debug_auto_load = 0;
65 /* "show" command for the debug_auto_load configuration variable. */
68 show_debug_auto_load (struct ui_file *file, int from_tty,
69 struct cmd_list_element *c, const char *value)
71 fprintf_filtered (file, _("Debugging output for files "
72 "of 'set auto-load ...' is %s.\n"),
76 /* User-settable option to enable/disable auto-loading of GDB_AUTO_FILE_NAME
78 set auto-load gdb-scripts on|off
79 This is true if we should auto-load associated scripts when an objfile
80 is opened, false otherwise. */
81 static int auto_load_gdb_scripts = 1;
83 /* "show" command for the auto_load_gdb_scripts configuration variable. */
86 show_auto_load_gdb_scripts (struct ui_file *file, int from_tty,
87 struct cmd_list_element *c, const char *value)
89 fprintf_filtered (file, _("Auto-loading of canned sequences of commands "
94 /* Return non-zero if auto-loading gdb scripts is enabled. */
97 auto_load_gdb_scripts_enabled (const struct extension_language_defn *extlang)
99 return auto_load_gdb_scripts;
102 /* Internal-use flag to enable/disable auto-loading.
103 This is true if we should auto-load python code when an objfile is opened,
106 Both auto_load_scripts && global_auto_load must be true to enable
109 This flag exists to facilitate deferring auto-loading during start-up
110 until after ./.gdbinit has been read; it may augment the search directories
111 used to find the scripts. */
112 int global_auto_load = 1;
114 /* Auto-load .gdbinit file from the current directory? */
115 int auto_load_local_gdbinit = 1;
117 /* Absolute pathname to the current directory .gdbinit, if it exists. */
118 char *auto_load_local_gdbinit_pathname = NULL;
120 /* Boolean value if AUTO_LOAD_LOCAL_GDBINIT_PATHNAME has been loaded. */
121 int auto_load_local_gdbinit_loaded = 0;
123 /* "show" command for the auto_load_local_gdbinit configuration variable. */
126 show_auto_load_local_gdbinit (struct ui_file *file, int from_tty,
127 struct cmd_list_element *c, const char *value)
129 fprintf_filtered (file, _("Auto-loading of .gdbinit script from current "
130 "directory is %s.\n"),
134 /* Directory list from which to load auto-loaded scripts. It is not checked
135 for absolute paths but they are strongly recommended. It is initialized by
136 _initialize_auto_load. */
137 static char *auto_load_dir;
139 /* "set" command for the auto_load_dir configuration variable. */
142 set_auto_load_dir (char *args, int from_tty, struct cmd_list_element *c)
144 /* Setting the variable to "" resets it to the compile time defaults. */
145 if (auto_load_dir[0] == '\0')
147 xfree (auto_load_dir);
148 auto_load_dir = xstrdup (AUTO_LOAD_DIR);
152 /* "show" command for the auto_load_dir configuration variable. */
155 show_auto_load_dir (struct ui_file *file, int from_tty,
156 struct cmd_list_element *c, const char *value)
158 fprintf_filtered (file, _("List of directories from which to load "
159 "auto-loaded scripts is %s.\n"),
163 /* Directory list safe to hold auto-loaded files. It is not checked for
164 absolute paths but they are strongly recommended. It is initialized by
165 _initialize_auto_load. */
166 static char *auto_load_safe_path;
168 /* Vector of directory elements of AUTO_LOAD_SAFE_PATH with each one normalized
169 by tilde_expand and possibly each entries has added its gdb_realpath
171 static VEC (char_ptr) *auto_load_safe_path_vec;
173 /* Expand $datadir and $debugdir in STRING according to the rules of
174 substitute_path_component. Return vector from dirnames_to_char_ptr_vec,
175 this vector must be freed by free_char_ptr_vec by the caller. */
177 static VEC (char_ptr) *
178 auto_load_expand_dir_vars (const char *string)
180 VEC (char_ptr) *dir_vec;
183 s = xstrdup (string);
184 substitute_path_component (&s, "$datadir", gdb_datadir);
185 substitute_path_component (&s, "$debugdir", debug_file_directory);
187 if (debug_auto_load && strcmp (s, string) != 0)
188 fprintf_unfiltered (gdb_stdlog,
189 _("auto-load: Expanded $-variables to \"%s\".\n"), s);
191 dir_vec = dirnames_to_char_ptr_vec (s);
197 /* Update auto_load_safe_path_vec from current AUTO_LOAD_SAFE_PATH. */
200 auto_load_safe_path_vec_update (void)
206 fprintf_unfiltered (gdb_stdlog,
207 _("auto-load: Updating directories of \"%s\".\n"),
208 auto_load_safe_path);
210 free_char_ptr_vec (auto_load_safe_path_vec);
212 auto_load_safe_path_vec = auto_load_expand_dir_vars (auto_load_safe_path);
213 len = VEC_length (char_ptr, auto_load_safe_path_vec);
215 /* Apply tilde_expand and gdb_realpath to each AUTO_LOAD_SAFE_PATH_VEC
217 for (ix = 0; ix < len; ix++)
219 char *dir = VEC_index (char_ptr, auto_load_safe_path_vec, ix);
220 char *expanded = tilde_expand (dir);
221 char *real_path = gdb_realpath (expanded);
223 /* Ensure the current entry is at least tilde_expand-ed. */
224 VEC_replace (char_ptr, auto_load_safe_path_vec, ix, expanded);
228 if (strcmp (expanded, dir) == 0)
229 fprintf_unfiltered (gdb_stdlog,
230 _("auto-load: Using directory \"%s\".\n"),
233 fprintf_unfiltered (gdb_stdlog,
234 _("auto-load: Resolved directory \"%s\" "
240 /* If gdb_realpath returns a different content, append it. */
241 if (strcmp (real_path, expanded) == 0)
245 VEC_safe_push (char_ptr, auto_load_safe_path_vec, real_path);
248 fprintf_unfiltered (gdb_stdlog,
249 _("auto-load: And canonicalized as \"%s\".\n"),
255 /* Variable gdb_datadir has been set. Update content depending on $datadir. */
258 auto_load_gdb_datadir_changed (void)
260 auto_load_safe_path_vec_update ();
263 /* "set" command for the auto_load_safe_path configuration variable. */
266 set_auto_load_safe_path (char *args, int from_tty, struct cmd_list_element *c)
268 /* Setting the variable to "" resets it to the compile time defaults. */
269 if (auto_load_safe_path[0] == '\0')
271 xfree (auto_load_safe_path);
272 auto_load_safe_path = xstrdup (AUTO_LOAD_SAFE_PATH);
275 auto_load_safe_path_vec_update ();
278 /* "show" command for the auto_load_safe_path configuration variable. */
281 show_auto_load_safe_path (struct ui_file *file, int from_tty,
282 struct cmd_list_element *c, const char *value)
286 /* Check if user has entered either "/" or for example ":".
287 But while more complicate content like ":/foo" would still also
288 permit any location do not hide those. */
290 for (cs = value; *cs && (*cs == DIRNAME_SEPARATOR || IS_DIR_SEPARATOR (*cs));
293 fprintf_filtered (file, _("Auto-load files are safe to load from any "
296 fprintf_filtered (file, _("List of directories from which it is safe to "
297 "auto-load files is %s.\n"),
301 /* "add-auto-load-safe-path" command for the auto_load_safe_path configuration
305 add_auto_load_safe_path (char *args, int from_tty)
309 if (args == NULL || *args == 0)
311 Directory argument required.\n\
312 Use 'set auto-load safe-path /' for disabling the auto-load safe-path security.\
315 s = xstrprintf ("%s%c%s", auto_load_safe_path, DIRNAME_SEPARATOR, args);
316 xfree (auto_load_safe_path);
317 auto_load_safe_path = s;
319 auto_load_safe_path_vec_update ();
322 /* "add-auto-load-scripts-directory" command for the auto_load_dir configuration
326 add_auto_load_dir (char *args, int from_tty)
330 if (args == NULL || *args == 0)
331 error (_("Directory argument required."));
333 s = xstrprintf ("%s%c%s", auto_load_dir, DIRNAME_SEPARATOR, args);
334 xfree (auto_load_dir);
338 /* Implementation for filename_is_in_pattern overwriting the caller's FILENAME
342 filename_is_in_pattern_1 (char *filename, char *pattern)
344 size_t pattern_len = strlen (pattern);
345 size_t filename_len = strlen (filename);
348 fprintf_unfiltered (gdb_stdlog, _("auto-load: Matching file \"%s\" "
349 "to pattern \"%s\"\n"),
352 /* Trim trailing slashes ("/") from PATTERN. Even for "d:\" paths as
353 trailing slashes are trimmed also from FILENAME it still matches
355 while (pattern_len && IS_DIR_SEPARATOR (pattern[pattern_len - 1]))
357 pattern[pattern_len] = '\0';
359 /* Ensure auto_load_safe_path "/" matches any FILENAME. On MS-Windows
360 platform FILENAME even after gdb_realpath does not have to start with
361 IS_DIR_SEPARATOR character, such as the 'C:\x.exe' filename. */
362 if (pattern_len == 0)
365 fprintf_unfiltered (gdb_stdlog,
366 _("auto-load: Matched - empty pattern\n"));
372 /* Trim trailing slashes ("/"). PATTERN also has slashes trimmed the
373 same way so they will match. */
374 while (filename_len && IS_DIR_SEPARATOR (filename[filename_len - 1]))
376 filename[filename_len] = '\0';
377 if (filename_len == 0)
380 fprintf_unfiltered (gdb_stdlog,
381 _("auto-load: Not matched - pattern \"%s\".\n"),
386 if (gdb_filename_fnmatch (pattern, filename, FNM_FILE_NAME | FNM_NOESCAPE)
390 fprintf_unfiltered (gdb_stdlog, _("auto-load: Matched - file "
391 "\"%s\" to pattern \"%s\".\n"),
396 /* Trim trailing FILENAME component. */
397 while (filename_len > 0 && !IS_DIR_SEPARATOR (filename[filename_len - 1]))
402 /* Return 1 if FILENAME matches PATTERN or if FILENAME resides in
403 a subdirectory of a directory that matches PATTERN. Return 0 otherwise.
404 gdb_realpath normalization is never done here. */
406 static ATTRIBUTE_PURE int
407 filename_is_in_pattern (const char *filename, const char *pattern)
409 char *filename_copy, *pattern_copy;
411 filename_copy = (char *) alloca (strlen (filename) + 1);
412 strcpy (filename_copy, filename);
413 pattern_copy = (char *) alloca (strlen (pattern) + 1);
414 strcpy (pattern_copy, pattern);
416 return filename_is_in_pattern_1 (filename_copy, pattern_copy);
419 /* Return 1 if FILENAME belongs to one of directory components of
420 AUTO_LOAD_SAFE_PATH_VEC. Return 0 otherwise.
421 auto_load_safe_path_vec_update is never called.
422 *FILENAME_REALP may be updated by gdb_realpath of FILENAME - it has to be
423 freed by the caller. */
426 filename_is_in_auto_load_safe_path_vec (const char *filename,
427 char **filename_realp)
432 for (ix = 0; VEC_iterate (char_ptr, auto_load_safe_path_vec, ix, pattern);
434 if (*filename_realp == NULL && filename_is_in_pattern (filename, pattern))
439 if (*filename_realp == NULL)
441 *filename_realp = gdb_realpath (filename);
442 if (debug_auto_load && strcmp (*filename_realp, filename) != 0)
443 fprintf_unfiltered (gdb_stdlog,
444 _("auto-load: Resolved "
445 "file \"%s\" as \"%s\".\n"),
446 filename, *filename_realp);
449 if (strcmp (*filename_realp, filename) != 0)
451 VEC_iterate (char_ptr, auto_load_safe_path_vec, ix, pattern); ++ix)
452 if (filename_is_in_pattern (*filename_realp, pattern))
459 fprintf_unfiltered (gdb_stdlog, _("auto-load: File \"%s\" matches "
460 "directory \"%s\".\n"),
468 /* Return 1 if FILENAME is located in one of the directories of
469 AUTO_LOAD_SAFE_PATH. Otherwise call warning and return 0. FILENAME does
470 not have to be an absolute path.
472 Existence of FILENAME is not checked. Function will still give a warning
473 even if the caller would quietly skip non-existing file in unsafe
477 file_is_auto_load_safe (const char *filename, const char *debug_fmt, ...)
479 char *filename_real = NULL;
480 struct cleanup *back_to;
481 static int advice_printed = 0;
487 va_start (debug_args, debug_fmt);
488 vfprintf_unfiltered (gdb_stdlog, debug_fmt, debug_args);
492 back_to = make_cleanup (free_current_contents, &filename_real);
494 if (filename_is_in_auto_load_safe_path_vec (filename, &filename_real))
496 do_cleanups (back_to);
500 auto_load_safe_path_vec_update ();
501 if (filename_is_in_auto_load_safe_path_vec (filename, &filename_real))
503 do_cleanups (back_to);
507 warning (_("File \"%s\" auto-loading has been declined by your "
508 "`auto-load safe-path' set to \"%s\"."),
509 filename_real, auto_load_safe_path);
513 const char *homedir = getenv ("HOME");
518 homeinit = xstrprintf ("%s/%s", homedir, gdbinit);
519 make_cleanup (xfree, homeinit);
521 printf_filtered (_("\
522 To enable execution of this file add\n\
523 \tadd-auto-load-safe-path %s\n\
524 line to your configuration file \"%s\".\n\
525 To completely disable this security protection add\n\
526 \tset auto-load safe-path /\n\
527 line to your configuration file \"%s\".\n\
528 For more information about this security protection see the\n\
529 \"Auto-loading safe path\" section in the GDB manual. E.g., run from the shell:\n\
530 \tinfo \"(gdb)Auto-loading safe path\"\n"),
531 filename_real, homeinit, homeinit);
535 do_cleanups (back_to);
539 /* For scripts specified in .debug_gdb_scripts, multiple objfiles may load
540 the same script. There's no point in loading the script multiple times,
541 and there can be a lot of objfiles and scripts, so we keep track of scripts
544 struct auto_load_pspace_info
546 /* For each program space we keep track of loaded scripts, both when
547 specified as file names and as scripts to be executed directly. */
548 struct htab *loaded_script_files;
549 struct htab *loaded_script_texts;
551 /* Non-zero if we've issued the warning about an auto-load script not being
552 supported. We only want to issue this warning once. */
553 int unsupported_script_warning_printed;
555 /* Non-zero if we've issued the warning about an auto-load script not being
556 found. We only want to issue this warning once. */
557 int script_not_found_warning_printed;
560 /* Objects of this type are stored in the loaded_script hash table. */
564 /* Name as provided by the objfile. */
567 /* Full path name or NULL if script wasn't found (or was otherwise
568 inaccessible), or NULL for loaded_script_texts. */
569 const char *full_path;
571 /* Non-zero if this script has been loaded. */
574 const struct extension_language_defn *language;
577 /* Per-program-space data key. */
578 static const struct program_space_data *auto_load_pspace_data;
581 auto_load_pspace_data_cleanup (struct program_space *pspace, void *arg)
583 struct auto_load_pspace_info *info = (struct auto_load_pspace_info *) arg;
585 if (info->loaded_script_files)
586 htab_delete (info->loaded_script_files);
587 if (info->loaded_script_texts)
588 htab_delete (info->loaded_script_texts);
592 /* Get the current autoload data. If none is found yet, add it now. This
593 function always returns a valid object. */
595 static struct auto_load_pspace_info *
596 get_auto_load_pspace_data (struct program_space *pspace)
598 struct auto_load_pspace_info *info;
600 info = ((struct auto_load_pspace_info *)
601 program_space_data (pspace, auto_load_pspace_data));
604 info = XCNEW (struct auto_load_pspace_info);
605 set_program_space_data (pspace, auto_load_pspace_data, info);
611 /* Hash function for the loaded script hash. */
614 hash_loaded_script_entry (const void *data)
616 const struct loaded_script *e = (const struct loaded_script *) data;
618 return htab_hash_string (e->name) ^ htab_hash_pointer (e->language);
621 /* Equality function for the loaded script hash. */
624 eq_loaded_script_entry (const void *a, const void *b)
626 const struct loaded_script *ea = (const struct loaded_script *) a;
627 const struct loaded_script *eb = (const struct loaded_script *) b;
629 return strcmp (ea->name, eb->name) == 0 && ea->language == eb->language;
632 /* Initialize the table to track loaded scripts.
633 Each entry is hashed by the full path name. */
636 init_loaded_scripts_info (struct auto_load_pspace_info *pspace_info)
638 /* Choose 31 as the starting size of the hash table, somewhat arbitrarily.
639 Space for each entry is obtained with one malloc so we can free them
642 pspace_info->loaded_script_files = htab_create (31,
643 hash_loaded_script_entry,
644 eq_loaded_script_entry,
646 pspace_info->loaded_script_texts = htab_create (31,
647 hash_loaded_script_entry,
648 eq_loaded_script_entry,
651 pspace_info->unsupported_script_warning_printed = FALSE;
652 pspace_info->script_not_found_warning_printed = FALSE;
655 /* Wrapper on get_auto_load_pspace_data to also allocate the hash table
656 for loading scripts. */
658 struct auto_load_pspace_info *
659 get_auto_load_pspace_data_for_loading (struct program_space *pspace)
661 struct auto_load_pspace_info *info;
663 info = get_auto_load_pspace_data (pspace);
664 if (info->loaded_script_files == NULL)
665 init_loaded_scripts_info (info);
670 /* Add script file NAME in LANGUAGE to hash table of PSPACE_INFO.
671 LOADED 1 if the script has been (is going to) be loaded, 0 otherwise
672 (such as if it has not been found).
673 FULL_PATH is NULL if the script wasn't found.
674 The result is true if the script was already in the hash table. */
677 maybe_add_script_file (struct auto_load_pspace_info *pspace_info, int loaded,
678 const char *name, const char *full_path,
679 const struct extension_language_defn *language)
681 struct htab *htab = pspace_info->loaded_script_files;
682 struct loaded_script **slot, entry;
686 entry.language = language;
687 slot = (struct loaded_script **) htab_find_slot (htab, &entry, INSERT);
688 in_hash_table = *slot != NULL;
690 /* If this script is not in the hash table, add it. */
696 /* Allocate all space in one chunk so it's easier to free. */
697 *slot = ((struct loaded_script *)
698 xmalloc (sizeof (**slot)
700 + (full_path != NULL ? (strlen (full_path) + 1) : 0)));
701 p = ((char*) *slot) + sizeof (**slot);
704 if (full_path != NULL)
707 strcpy (p, full_path);
708 (*slot)->full_path = p;
711 (*slot)->full_path = NULL;
712 (*slot)->loaded = loaded;
713 (*slot)->language = language;
716 return in_hash_table;
719 /* Add script contents NAME in LANGUAGE to hash table of PSPACE_INFO.
720 LOADED 1 if the script has been (is going to) be loaded, 0 otherwise
721 (such as if it has not been found).
722 The result is true if the script was already in the hash table. */
725 maybe_add_script_text (struct auto_load_pspace_info *pspace_info,
726 int loaded, const char *name,
727 const struct extension_language_defn *language)
729 struct htab *htab = pspace_info->loaded_script_texts;
730 struct loaded_script **slot, entry;
734 entry.language = language;
735 slot = (struct loaded_script **) htab_find_slot (htab, &entry, INSERT);
736 in_hash_table = *slot != NULL;
738 /* If this script is not in the hash table, add it. */
744 /* Allocate all space in one chunk so it's easier to free. */
745 *slot = ((struct loaded_script *)
746 xmalloc (sizeof (**slot) + strlen (name) + 1));
747 p = ((char*) *slot) + sizeof (**slot);
750 (*slot)->full_path = NULL;
751 (*slot)->loaded = loaded;
752 (*slot)->language = language;
755 return in_hash_table;
758 /* Clear the table of loaded section scripts. */
761 clear_section_scripts (void)
763 struct program_space *pspace = current_program_space;
764 struct auto_load_pspace_info *info;
766 info = ((struct auto_load_pspace_info *)
767 program_space_data (pspace, auto_load_pspace_data));
768 if (info != NULL && info->loaded_script_files != NULL)
770 htab_delete (info->loaded_script_files);
771 htab_delete (info->loaded_script_texts);
772 info->loaded_script_files = NULL;
773 info->loaded_script_texts = NULL;
774 info->unsupported_script_warning_printed = FALSE;
775 info->script_not_found_warning_printed = FALSE;
779 /* Look for the auto-load script in LANGUAGE associated with OBJFILE where
780 OBJFILE's gdb_realpath is REALNAME and load it. Return 1 if we found any
781 matching script, return 0 otherwise. */
784 auto_load_objfile_script_1 (struct objfile *objfile, const char *realname,
785 const struct extension_language_defn *language)
787 char *filename, *debugfile;
790 struct cleanup *cleanups;
791 const char *suffix = ext_lang_auto_load_suffix (language);
793 len = strlen (realname);
794 filename = (char *) xmalloc (len + strlen (suffix) + 1);
795 memcpy (filename, realname, len);
796 strcpy (filename + len, suffix);
798 cleanups = make_cleanup (xfree, filename);
800 input = gdb_fopen_cloexec (filename, "r");
801 debugfile = filename;
803 fprintf_unfiltered (gdb_stdlog, _("auto-load: Attempted file \"%s\" %s.\n"),
804 debugfile, input ? _("exists") : _("does not exist"));
812 /* Also try the same file in a subdirectory of gdb's data
815 vec = auto_load_expand_dir_vars (auto_load_dir);
816 make_cleanup_free_char_ptr_vec (vec);
819 fprintf_unfiltered (gdb_stdlog, _("auto-load: Searching 'set auto-load "
820 "scripts-directory' path \"%s\".\n"),
823 for (ix = 0; VEC_iterate (char_ptr, vec, ix, dir); ++ix)
825 debugfile = (char *) xmalloc (strlen (dir) + strlen (filename) + 1);
826 strcpy (debugfile, dir);
828 /* FILENAME is absolute, so we don't need a "/" here. */
829 strcat (debugfile, filename);
831 make_cleanup (xfree, debugfile);
832 input = gdb_fopen_cloexec (debugfile, "r");
834 fprintf_unfiltered (gdb_stdlog, _("auto-load: Attempted file "
837 input ? _("exists") : _("does not exist"));
846 struct auto_load_pspace_info *pspace_info;
848 make_cleanup_fclose (input);
851 = file_is_auto_load_safe (debugfile,
852 _("auto-load: Loading %s script \"%s\""
853 " by extension for objfile \"%s\".\n"),
854 ext_lang_name (language),
855 debugfile, objfile_name (objfile));
857 /* Add this script to the hash table too so
858 "info auto-load ${lang}-scripts" can print it. */
860 = get_auto_load_pspace_data_for_loading (current_program_space);
861 maybe_add_script_file (pspace_info, is_safe, debugfile, debugfile,
864 /* To preserve existing behaviour we don't check for whether the
865 script was already in the table, and always load it.
866 It's highly unlikely that we'd ever load it twice,
867 and these scripts are required to be idempotent under multiple
871 objfile_script_sourcer_func *sourcer
872 = ext_lang_objfile_script_sourcer (language);
874 /* We shouldn't get here if support for the language isn't
875 compiled in. And the extension language is required to implement
877 gdb_assert (sourcer != NULL);
878 sourcer (language, objfile, input, debugfile);
886 do_cleanups (cleanups);
890 /* Look for the auto-load script in LANGUAGE associated with OBJFILE and load
894 auto_load_objfile_script (struct objfile *objfile,
895 const struct extension_language_defn *language)
897 char *realname = gdb_realpath (objfile_name (objfile));
898 struct cleanup *cleanups = make_cleanup (xfree, realname);
900 if (!auto_load_objfile_script_1 (objfile, realname, language))
902 /* For Windows/DOS .exe executables, strip the .exe suffix, so that
903 FOO-gdb.gdb could be used for FOO.exe, and try again. */
905 size_t len = strlen (realname);
906 const size_t lexe = sizeof (".exe") - 1;
908 if (len > lexe && strcasecmp (realname + len - lexe, ".exe") == 0)
911 realname[len] = '\0';
913 fprintf_unfiltered (gdb_stdlog, _("auto-load: Stripped .exe suffix, "
914 "retrying with \"%s\".\n"),
916 auto_load_objfile_script_1 (objfile, realname, language);
920 do_cleanups (cleanups);
923 /* Subroutine of source_section_scripts to simplify it.
924 Load FILE as a script in extension language LANGUAGE.
925 The script is from section SECTION_NAME in OBJFILE at offset OFFSET. */
928 source_script_file (struct auto_load_pspace_info *pspace_info,
929 struct objfile *objfile,
930 const struct extension_language_defn *language,
931 const char *section_name, unsigned int offset,
936 int opened, in_hash_table;
937 struct cleanup *cleanups;
938 objfile_script_sourcer_func *sourcer;
940 /* Skip this script if support is not compiled in. */
941 sourcer = ext_lang_objfile_script_sourcer (language);
944 /* We don't throw an error, the program is still debuggable. */
945 maybe_print_unsupported_script_warning (pspace_info, objfile, language,
946 section_name, offset);
947 /* We *could* still try to open it, but there's no point. */
948 maybe_add_script_file (pspace_info, 0, file, NULL, language);
952 /* Skip this script if auto-loading it has been disabled. */
953 if (!ext_lang_auto_load_enabled (language))
955 /* No message is printed, just skip it. */
959 opened = find_and_open_script (file, 1 /*search_path*/,
960 &stream, &full_path);
962 cleanups = make_cleanup (null_cleanup, NULL);
965 make_cleanup_fclose (stream);
966 make_cleanup (xfree, full_path);
968 if (!file_is_auto_load_safe (full_path,
969 _("auto-load: Loading %s script "
970 "\"%s\" from section \"%s\" of "
971 "objfile \"%s\".\n"),
972 ext_lang_name (language), full_path,
973 section_name, objfile_name (objfile)))
980 /* If one script isn't found it's not uncommon for more to not be
981 found either. We don't want to print a message for each script,
982 too much noise. Instead, we print the warning once and tell the
983 user how to find the list of scripts that weren't loaded.
984 We don't throw an error, the program is still debuggable.
986 IWBN if complaints.c were more general-purpose. */
988 maybe_print_script_not_found_warning (pspace_info, objfile, language,
989 section_name, offset);
992 in_hash_table = maybe_add_script_file (pspace_info, opened, file, full_path,
995 /* If this file is not currently loaded, load it. */
996 if (opened && !in_hash_table)
997 sourcer (language, objfile, stream, full_path);
999 do_cleanups (cleanups);
1002 /* Subroutine of source_section_scripts to simplify it.
1003 Execute SCRIPT as a script in extension language LANG.
1004 The script is from section SECTION_NAME in OBJFILE at offset OFFSET. */
1007 execute_script_contents (struct auto_load_pspace_info *pspace_info,
1008 struct objfile *objfile,
1009 const struct extension_language_defn *language,
1010 const char *section_name, unsigned int offset,
1013 objfile_script_executor_func *executor;
1014 const char *newline, *script_text;
1016 int is_safe, in_hash_table;
1017 struct cleanup *cleanups;
1019 cleanups = make_cleanup (null_cleanup, NULL);
1021 /* The first line of the script is the name of the script.
1022 It must not contain any kind of space character. */
1024 newline = strchr (script, '\n');
1025 if (newline != NULL)
1029 /* Put the name in a buffer and validate it. */
1030 buf = xstrndup (script, newline - script);
1031 make_cleanup (xfree, buf);
1032 for (p = buf; *p != '\0'; ++p)
1037 /* We don't allow nameless scripts, they're not helpful to the user. */
1038 if (p != buf && *p == '\0')
1043 /* We don't throw an error, the program is still debuggable. */
1045 Missing/bad script name in entry at offset %u in section %s\n\
1047 offset, section_name, objfile_name (objfile));
1048 do_cleanups (cleanups);
1051 script_text = newline + 1;
1053 /* Skip this script if support is not compiled in. */
1054 executor = ext_lang_objfile_script_executor (language);
1055 if (executor == NULL)
1057 /* We don't throw an error, the program is still debuggable. */
1058 maybe_print_unsupported_script_warning (pspace_info, objfile, language,
1059 section_name, offset);
1060 maybe_add_script_text (pspace_info, 0, name, language);
1061 do_cleanups (cleanups);
1065 /* Skip this script if auto-loading it has been disabled. */
1066 if (!ext_lang_auto_load_enabled (language))
1068 /* No message is printed, just skip it. */
1069 do_cleanups (cleanups);
1073 is_safe = file_is_auto_load_safe (objfile_name (objfile),
1074 _("auto-load: Loading %s script "
1075 "\"%s\" from section \"%s\" of "
1076 "objfile \"%s\".\n"),
1077 ext_lang_name (language), name,
1078 section_name, objfile_name (objfile));
1080 in_hash_table = maybe_add_script_text (pspace_info, is_safe, name, language);
1082 /* If this file is not currently loaded, load it. */
1083 if (is_safe && !in_hash_table)
1084 executor (language, objfile, name, script_text);
1086 do_cleanups (cleanups);
1089 /* Load scripts specified in OBJFILE.
1090 START,END delimit a buffer containing a list of nul-terminated
1092 SECTION_NAME is used in error messages.
1094 Scripts specified as file names are found per normal "source -s" command
1095 processing. First the script is looked for in $cwd. If not found there
1096 the source search path is used.
1098 The section contains a list of path names of script files to load or
1099 actual script contents. Each entry is nul-terminated. */
1102 source_section_scripts (struct objfile *objfile, const char *section_name,
1103 const char *start, const char *end)
1106 struct auto_load_pspace_info *pspace_info;
1108 pspace_info = get_auto_load_pspace_data_for_loading (current_program_space);
1110 for (p = start; p < end; ++p)
1113 const struct extension_language_defn *language;
1114 unsigned int offset = p - start;
1119 case SECTION_SCRIPT_ID_PYTHON_FILE:
1120 case SECTION_SCRIPT_ID_PYTHON_TEXT:
1121 language = get_ext_lang_defn (EXT_LANG_PYTHON);
1123 case SECTION_SCRIPT_ID_SCHEME_FILE:
1124 case SECTION_SCRIPT_ID_SCHEME_TEXT:
1125 language = get_ext_lang_defn (EXT_LANG_GUILE);
1128 warning (_("Invalid entry in %s section"), section_name);
1129 /* We could try various heuristics to find the next valid entry,
1130 but it's safer to just punt. */
1135 while (p < end && *p != '\0')
1139 warning (_("Non-nul-terminated entry in %s at offset %u"),
1140 section_name, offset);
1141 /* Don't load/execute it. */
1147 case SECTION_SCRIPT_ID_PYTHON_FILE:
1148 case SECTION_SCRIPT_ID_SCHEME_FILE:
1151 warning (_("Empty entry in %s at offset %u"),
1152 section_name, offset);
1155 source_script_file (pspace_info, objfile, language,
1156 section_name, offset, entry);
1158 case SECTION_SCRIPT_ID_PYTHON_TEXT:
1159 case SECTION_SCRIPT_ID_SCHEME_TEXT:
1160 execute_script_contents (pspace_info, objfile, language,
1161 section_name, offset, entry);
1167 /* Load scripts specified in section SECTION_NAME of OBJFILE. */
1170 auto_load_section_scripts (struct objfile *objfile, const char *section_name)
1172 bfd *abfd = objfile->obfd;
1173 asection *scripts_sect;
1174 bfd_byte *data = NULL;
1176 scripts_sect = bfd_get_section_by_name (abfd, section_name);
1177 if (scripts_sect == NULL)
1180 if (!bfd_get_full_section_contents (abfd, scripts_sect, &data))
1181 warning (_("Couldn't read %s section of %s"),
1182 section_name, bfd_get_filename (abfd));
1185 struct cleanup *cleanups;
1186 char *p = (char *) data;
1188 cleanups = make_cleanup (xfree, p);
1189 source_section_scripts (objfile, section_name, p,
1190 p + bfd_get_section_size (scripts_sect));
1191 do_cleanups (cleanups);
1195 /* Load any auto-loaded scripts for OBJFILE. */
1198 load_auto_scripts_for_objfile (struct objfile *objfile)
1200 /* Return immediately if auto-loading has been globally disabled.
1201 This is to handle sequencing of operations during gdb startup.
1202 Also return immediately if OBJFILE was not created from a file
1203 on the local filesystem. */
1204 if (!global_auto_load
1205 || (objfile->flags & OBJF_NOT_FILENAME) != 0
1206 || is_target_filename (objfile->original_name))
1209 /* Load any extension language scripts for this objfile.
1210 E.g., foo-gdb.gdb, foo-gdb.py. */
1211 auto_load_ext_lang_scripts_for_objfile (objfile);
1213 /* Load any scripts mentioned in AUTO_SECTION_NAME (.debug_gdb_scripts). */
1214 auto_load_section_scripts (objfile, AUTO_SECTION_NAME);
1217 /* This is a new_objfile observer callback to auto-load scripts.
1219 Two flavors of auto-loaded scripts are supported.
1220 1) based on the path to the objfile
1221 2) from .debug_gdb_scripts section */
1224 auto_load_new_objfile (struct objfile *objfile)
1228 /* OBJFILE is NULL when loading a new "main" symbol-file. */
1229 clear_section_scripts ();
1233 load_auto_scripts_for_objfile (objfile);
1236 /* Collect scripts to be printed in a vec. */
1238 typedef struct loaded_script *loaded_script_ptr;
1239 DEF_VEC_P (loaded_script_ptr);
1241 struct collect_matching_scripts_data
1243 VEC (loaded_script_ptr) **scripts_p;
1245 const struct extension_language_defn *language;
1248 /* Traversal function for htab_traverse.
1249 Collect the entry if it matches the regexp. */
1252 collect_matching_scripts (void **slot, void *info)
1254 struct loaded_script *script = (struct loaded_script *) *slot;
1255 struct collect_matching_scripts_data *data
1256 = (struct collect_matching_scripts_data *) info;
1258 if (script->language == data->language && re_exec (script->name))
1259 VEC_safe_push (loaded_script_ptr, *data->scripts_p, script);
1267 print_script (struct loaded_script *script)
1269 struct ui_out *uiout = current_uiout;
1270 struct cleanup *chain;
1272 chain = make_cleanup_ui_out_tuple_begin_end (uiout, NULL);
1274 ui_out_field_string (uiout, "loaded", script->loaded ? "Yes" : "No");
1275 ui_out_field_string (uiout, "script", script->name);
1276 ui_out_text (uiout, "\n");
1278 /* If the name isn't the full path, print it too. */
1279 if (script->full_path != NULL
1280 && strcmp (script->name, script->full_path) != 0)
1282 ui_out_text (uiout, "\tfull name: ");
1283 ui_out_field_string (uiout, "full_path", script->full_path);
1284 ui_out_text (uiout, "\n");
1287 do_cleanups (chain);
1290 /* Helper for info_auto_load_scripts to sort the scripts by name. */
1293 sort_scripts_by_name (const void *ap, const void *bp)
1295 const struct loaded_script *a = *(const struct loaded_script **) ap;
1296 const struct loaded_script *b = *(const struct loaded_script **) bp;
1298 return FILENAME_CMP (a->name, b->name);
1301 /* Special internal GDB value of auto_load_info_scripts's PATTERN identify
1302 the "info auto-load XXX" command has been executed through the general
1303 "info auto-load" invocation. Extra newline will be printed if needed. */
1304 char auto_load_info_scripts_pattern_nl[] = "";
1306 /* Subroutine of auto_load_info_scripts to simplify it.
1310 print_scripts (VEC (loaded_script_ptr) *scripts)
1313 loaded_script_ptr script;
1315 qsort (VEC_address (loaded_script_ptr, scripts),
1316 VEC_length (loaded_script_ptr, scripts),
1317 sizeof (loaded_script_ptr), sort_scripts_by_name);
1318 for (i = 0; VEC_iterate (loaded_script_ptr, scripts, i, script); ++i)
1319 print_script (script);
1322 /* Implementation for "info auto-load gdb-scripts"
1323 (and "info auto-load python-scripts"). List scripts in LANGUAGE matching
1324 PATTERN. FROM_TTY is the usual GDB boolean for user interactivity. */
1327 auto_load_info_scripts (char *pattern, int from_tty,
1328 const struct extension_language_defn *language)
1330 struct ui_out *uiout = current_uiout;
1331 struct auto_load_pspace_info *pspace_info;
1332 struct cleanup *script_chain;
1333 VEC (loaded_script_ptr) *script_files, *script_texts;
1338 pspace_info = get_auto_load_pspace_data (current_program_space);
1340 if (pattern && *pattern)
1342 char *re_err = re_comp (pattern);
1345 error (_("Invalid regexp: %s"), re_err);
1352 /* We need to know the number of rows before we build the table.
1353 Plus we want to sort the scripts by name.
1354 So first traverse the hash table collecting the matching scripts. */
1356 script_files = VEC_alloc (loaded_script_ptr, 10);
1357 script_texts = VEC_alloc (loaded_script_ptr, 10);
1358 script_chain = make_cleanup (VEC_cleanup (loaded_script_ptr), &script_files);
1359 make_cleanup (VEC_cleanup (loaded_script_ptr), &script_texts);
1361 if (pspace_info != NULL && pspace_info->loaded_script_files != NULL)
1363 struct collect_matching_scripts_data data = { &script_files, language };
1365 /* Pass a pointer to scripts as VEC_safe_push can realloc space. */
1366 htab_traverse_noresize (pspace_info->loaded_script_files,
1367 collect_matching_scripts, &data);
1370 if (pspace_info != NULL && pspace_info->loaded_script_texts != NULL)
1372 struct collect_matching_scripts_data data = { &script_texts, language };
1374 /* Pass a pointer to scripts as VEC_safe_push can realloc space. */
1375 htab_traverse_noresize (pspace_info->loaded_script_texts,
1376 collect_matching_scripts, &data);
1379 nr_scripts = (VEC_length (loaded_script_ptr, script_files)
1380 + VEC_length (loaded_script_ptr, script_texts));
1382 /* Table header shifted right by preceding "gdb-scripts: " would not match
1384 if (nr_scripts > 0 && pattern == auto_load_info_scripts_pattern_nl)
1385 ui_out_text (uiout, "\n");
1387 /* Note: This creates a cleanup to output the table end marker. */
1388 make_cleanup_ui_out_table_begin_end (uiout, 2, nr_scripts,
1389 "AutoLoadedScriptsTable");
1391 ui_out_table_header (uiout, 7, ui_left, "loaded", "Loaded");
1392 ui_out_table_header (uiout, 70, ui_left, "script", "Script");
1393 ui_out_table_body (uiout);
1395 print_scripts (script_files);
1396 print_scripts (script_texts);
1398 /* Finish up the table before checking for no matching scripts. */
1399 do_cleanups (script_chain);
1401 if (nr_scripts == 0)
1403 if (pattern && *pattern)
1404 ui_out_message (uiout, 0, "No auto-load scripts matching %s.\n",
1407 ui_out_message (uiout, 0, "No auto-load scripts.\n");
1411 /* Wrapper for "info auto-load gdb-scripts". */
1414 info_auto_load_gdb_scripts (char *pattern, int from_tty)
1416 auto_load_info_scripts (pattern, from_tty, &extension_language_gdb);
1419 /* Implement 'info auto-load local-gdbinit'. */
1422 info_auto_load_local_gdbinit (char *args, int from_tty)
1424 if (auto_load_local_gdbinit_pathname == NULL)
1425 printf_filtered (_("Local .gdbinit file was not found.\n"));
1426 else if (auto_load_local_gdbinit_loaded)
1427 printf_filtered (_("Local .gdbinit file \"%s\" has been loaded.\n"),
1428 auto_load_local_gdbinit_pathname);
1430 printf_filtered (_("Local .gdbinit file \"%s\" has not been loaded.\n"),
1431 auto_load_local_gdbinit_pathname);
1434 /* Print an "unsupported script" warning if it has not already been printed.
1435 The script is in language LANGUAGE at offset OFFSET in section SECTION_NAME
1439 maybe_print_unsupported_script_warning
1440 (struct auto_load_pspace_info *pspace_info,
1441 struct objfile *objfile, const struct extension_language_defn *language,
1442 const char *section_name, unsigned offset)
1444 if (!pspace_info->unsupported_script_warning_printed)
1447 Unsupported auto-load script at offset %u in section %s\n\
1449 Use `info auto-load %s-scripts [REGEXP]' to list them."),
1450 offset, section_name, objfile_name (objfile),
1451 ext_lang_name (language));
1452 pspace_info->unsupported_script_warning_printed = 1;
1456 /* Return non-zero if SCRIPT_NOT_FOUND_WARNING_PRINTED of PSPACE_INFO was unset
1457 before calling this function. Always set SCRIPT_NOT_FOUND_WARNING_PRINTED
1461 maybe_print_script_not_found_warning
1462 (struct auto_load_pspace_info *pspace_info,
1463 struct objfile *objfile, const struct extension_language_defn *language,
1464 const char *section_name, unsigned offset)
1466 if (!pspace_info->script_not_found_warning_printed)
1469 Missing auto-load script at offset %u in section %s\n\
1471 Use `info auto-load %s-scripts [REGEXP]' to list them."),
1472 offset, section_name, objfile_name (objfile),
1473 ext_lang_name (language));
1474 pspace_info->script_not_found_warning_printed = 1;
1478 /* The only valid "set auto-load" argument is off|0|no|disable. */
1481 set_auto_load_cmd (char *args, int from_tty)
1483 struct cmd_list_element *list;
1486 /* See parse_binary_operation in use by the sub-commands. */
1488 length = args ? strlen (args) : 0;
1490 while (length > 0 && (args[length - 1] == ' ' || args[length - 1] == '\t'))
1493 if (length == 0 || (strncmp (args, "off", length) != 0
1494 && strncmp (args, "0", length) != 0
1495 && strncmp (args, "no", length) != 0
1496 && strncmp (args, "disable", length) != 0))
1497 error (_("Valid is only global 'set auto-load no'; "
1498 "otherwise check the auto-load sub-commands."));
1500 for (list = *auto_load_set_cmdlist_get (); list != NULL; list = list->next)
1501 if (list->var_type == var_boolean)
1503 gdb_assert (list->type == set_cmd);
1504 do_set_command (args, from_tty, list);
1508 /* Initialize "set auto-load " commands prefix and return it. */
1510 struct cmd_list_element **
1511 auto_load_set_cmdlist_get (void)
1513 static struct cmd_list_element *retval;
1516 add_prefix_cmd ("auto-load", class_maintenance, set_auto_load_cmd, _("\
1517 Auto-loading specific settings.\n\
1518 Configure various auto-load-specific variables such as\n\
1519 automatic loading of Python scripts."),
1520 &retval, "set auto-load ",
1521 1/*allow-unknown*/, &setlist);
1526 /* Command "show auto-load" displays summary of all the current
1527 "show auto-load " settings. */
1530 show_auto_load_cmd (char *args, int from_tty)
1532 cmd_show_list (*auto_load_show_cmdlist_get (), from_tty, "");
1535 /* Initialize "show auto-load " commands prefix and return it. */
1537 struct cmd_list_element **
1538 auto_load_show_cmdlist_get (void)
1540 static struct cmd_list_element *retval;
1543 add_prefix_cmd ("auto-load", class_maintenance, show_auto_load_cmd, _("\
1544 Show auto-loading specific settings.\n\
1545 Show configuration of various auto-load-specific variables such as\n\
1546 automatic loading of Python scripts."),
1547 &retval, "show auto-load ",
1548 0/*allow-unknown*/, &showlist);
1553 /* Command "info auto-load" displays whether the various auto-load files have
1554 been loaded. This is reimplementation of cmd_show_list which inserts
1555 newlines at proper places. */
1558 info_auto_load_cmd (char *args, int from_tty)
1560 struct cmd_list_element *list;
1561 struct cleanup *infolist_chain;
1562 struct ui_out *uiout = current_uiout;
1564 infolist_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "infolist");
1566 for (list = *auto_load_info_cmdlist_get (); list != NULL; list = list->next)
1568 struct cleanup *option_chain
1569 = make_cleanup_ui_out_tuple_begin_end (uiout, "option");
1571 gdb_assert (!list->prefixlist);
1572 gdb_assert (list->type == not_set_cmd);
1574 ui_out_field_string (uiout, "name", list->name);
1575 ui_out_text (uiout, ": ");
1576 cmd_func (list, auto_load_info_scripts_pattern_nl, from_tty);
1578 /* Close the tuple. */
1579 do_cleanups (option_chain);
1582 /* Close the tuple. */
1583 do_cleanups (infolist_chain);
1586 /* Initialize "info auto-load " commands prefix and return it. */
1588 struct cmd_list_element **
1589 auto_load_info_cmdlist_get (void)
1591 static struct cmd_list_element *retval;
1594 add_prefix_cmd ("auto-load", class_info, info_auto_load_cmd, _("\
1595 Print current status of auto-loaded files.\n\
1596 Print whether various files like Python scripts or .gdbinit files have been\n\
1597 found and/or loaded."),
1598 &retval, "info auto-load ",
1599 0/*allow-unknown*/, &infolist);
1604 void _initialize_auto_load (void);
1607 _initialize_auto_load (void)
1609 struct cmd_list_element *cmd;
1610 char *scripts_directory_help, *gdb_name_help, *python_name_help;
1611 char *guile_name_help;
1614 auto_load_pspace_data
1615 = register_program_space_data_with_cleanup (NULL,
1616 auto_load_pspace_data_cleanup);
1618 observer_attach_new_objfile (auto_load_new_objfile);
1620 add_setshow_boolean_cmd ("gdb-scripts", class_support,
1621 &auto_load_gdb_scripts, _("\
1622 Enable or disable auto-loading of canned sequences of commands scripts."), _("\
1623 Show whether auto-loading of canned sequences of commands scripts is enabled."),
1625 If enabled, canned sequences of commands are loaded when the debugger reads\n\
1626 an executable or shared library.\n\
1627 This options has security implications for untrusted inferiors."),
1628 NULL, show_auto_load_gdb_scripts,
1629 auto_load_set_cmdlist_get (),
1630 auto_load_show_cmdlist_get ());
1632 add_cmd ("gdb-scripts", class_info, info_auto_load_gdb_scripts,
1633 _("Print the list of automatically loaded sequences of commands.\n\
1634 Usage: info auto-load gdb-scripts [REGEXP]"),
1635 auto_load_info_cmdlist_get ());
1637 add_setshow_boolean_cmd ("local-gdbinit", class_support,
1638 &auto_load_local_gdbinit, _("\
1639 Enable or disable auto-loading of .gdbinit script in current directory."), _("\
1640 Show whether auto-loading .gdbinit script in current directory is enabled."),
1642 If enabled, canned sequences of commands are loaded when debugger starts\n\
1643 from .gdbinit file in current directory. Such files are deprecated,\n\
1644 use a script associated with inferior executable file instead.\n\
1645 This options has security implications for untrusted inferiors."),
1646 NULL, show_auto_load_local_gdbinit,
1647 auto_load_set_cmdlist_get (),
1648 auto_load_show_cmdlist_get ());
1650 add_cmd ("local-gdbinit", class_info, info_auto_load_local_gdbinit,
1651 _("Print whether current directory .gdbinit file has been loaded.\n\
1652 Usage: info auto-load local-gdbinit"),
1653 auto_load_info_cmdlist_get ());
1655 auto_load_dir = xstrdup (AUTO_LOAD_DIR);
1657 suffix = ext_lang_auto_load_suffix (get_ext_lang_defn (EXT_LANG_GDB));
1660 GDB scripts: OBJFILE%s\n"),
1662 python_name_help = NULL;
1664 suffix = ext_lang_auto_load_suffix (get_ext_lang_defn (EXT_LANG_PYTHON));
1667 Python scripts: OBJFILE%s\n"),
1670 guile_name_help = NULL;
1672 suffix = ext_lang_auto_load_suffix (get_ext_lang_defn (EXT_LANG_GUILE));
1675 Guile scripts: OBJFILE%s\n"),
1678 scripts_directory_help
1680 Automatically loaded scripts are located in one of the directories listed\n\
1686 This option is ignored for the kinds of scripts \
1687 having 'set auto-load ... off'.\n\
1688 Directories listed here need to be present also \
1689 in the 'set auto-load safe-path'\n\
1692 python_name_help ? python_name_help : "",
1693 guile_name_help ? guile_name_help : "");
1695 add_setshow_optional_filename_cmd ("scripts-directory", class_support,
1696 &auto_load_dir, _("\
1697 Set the list of directories from which to load auto-loaded scripts."), _("\
1698 Show the list of directories from which to load auto-loaded scripts."),
1699 scripts_directory_help,
1700 set_auto_load_dir, show_auto_load_dir,
1701 auto_load_set_cmdlist_get (),
1702 auto_load_show_cmdlist_get ());
1703 xfree (scripts_directory_help);
1704 xfree (python_name_help);
1705 xfree (gdb_name_help);
1706 xfree (guile_name_help);
1708 auto_load_safe_path = xstrdup (AUTO_LOAD_SAFE_PATH);
1709 auto_load_safe_path_vec_update ();
1710 add_setshow_optional_filename_cmd ("safe-path", class_support,
1711 &auto_load_safe_path, _("\
1712 Set the list of files and directories that are safe for auto-loading."), _("\
1713 Show the list of files and directories that are safe for auto-loading."), _("\
1714 Various files loaded automatically for the 'set auto-load ...' options must\n\
1715 be located in one of the directories listed by this option. Warning will be\n\
1716 printed and file will not be used otherwise.\n\
1717 You can mix both directory and filename entries.\n\
1718 Setting this parameter to an empty list resets it to its default value.\n\
1719 Setting this parameter to '/' (without the quotes) allows any file\n\
1720 for the 'set auto-load ...' options. Each path entry can be also shell\n\
1721 wildcard pattern; '*' does not match directory separator.\n\
1722 This option is ignored for the kinds of files having 'set auto-load ... off'.\n\
1723 This options has security implications for untrusted inferiors."),
1724 set_auto_load_safe_path,
1725 show_auto_load_safe_path,
1726 auto_load_set_cmdlist_get (),
1727 auto_load_show_cmdlist_get ());
1728 observer_attach_gdb_datadir_changed (auto_load_gdb_datadir_changed);
1730 cmd = add_cmd ("add-auto-load-safe-path", class_support,
1731 add_auto_load_safe_path,
1732 _("Add entries to the list of directories from which it is safe "
1733 "to auto-load files.\n\
1734 See the commands 'set auto-load safe-path' and 'show auto-load safe-path' to\n\
1735 access the current full list setting."),
1737 set_cmd_completer (cmd, filename_completer);
1739 cmd = add_cmd ("add-auto-load-scripts-directory", class_support,
1741 _("Add entries to the list of directories from which to load "
1742 "auto-loaded scripts.\n\
1743 See the commands 'set auto-load scripts-directory' and\n\
1744 'show auto-load scripts-directory' to access the current full list setting."),
1746 set_cmd_completer (cmd, filename_completer);
1748 add_setshow_boolean_cmd ("auto-load", class_maintenance,
1749 &debug_auto_load, _("\
1750 Set auto-load verifications debugging."), _("\
1751 Show auto-load verifications debugging."), _("\
1752 When non-zero, debugging output for files of 'set auto-load ...'\n\
1754 NULL, show_debug_auto_load,
1755 &setdebuglist, &showdebuglist);