1 /* GDB routines for supporting auto-loaded scripts.
3 Copyright (C) 2012-2019 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 /* Standard C includes. */
25 /* Standard C++ includes. */
28 /* Local non-gdb includes. */
29 #include "auto-load.h"
30 #include "cli/cli-cmds.h"
31 #include "cli/cli-decode.h"
32 #include "cli/cli-script.h"
33 #include "cli/cli-setshow.h"
35 #include "common/filestuff.h"
36 #include "common/pathstuff.h"
37 #include "completer.h"
38 #include "extension.h"
39 #include "filenames.h"
41 #include "gdb/section-scripts.h"
42 #include "gdb_regex.h"
45 #include "observable.h"
46 #include "progspace.h"
47 #include "readline/tilde.h"
51 /* The section to look in for auto-loaded scripts (in file formats that
53 Each entry in this section is a record that begins with a leading byte
54 identifying the record type.
55 At the moment we only support one record type: A leading byte of 1,
56 followed by the path of a python script to load. */
57 #define AUTO_SECTION_NAME ".debug_gdb_scripts"
59 static void maybe_print_unsupported_script_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 static void maybe_print_script_not_found_warning
65 (struct auto_load_pspace_info
*, struct objfile
*objfile
,
66 const struct extension_language_defn
*language
,
67 const char *section_name
, unsigned offset
);
69 /* Value of the 'set debug auto-load' configuration variable. */
70 static int debug_auto_load
= 0;
72 /* "show" command for the debug_auto_load configuration variable. */
75 show_debug_auto_load (struct ui_file
*file
, int from_tty
,
76 struct cmd_list_element
*c
, const char *value
)
78 fprintf_filtered (file
, _("Debugging output for files "
79 "of 'set auto-load ...' is %s.\n"),
83 /* User-settable option to enable/disable auto-loading of GDB_AUTO_FILE_NAME
85 set auto-load gdb-scripts on|off
86 This is true if we should auto-load associated scripts when an objfile
87 is opened, false otherwise. */
88 static int auto_load_gdb_scripts
= 1;
90 /* "show" command for the auto_load_gdb_scripts configuration variable. */
93 show_auto_load_gdb_scripts (struct ui_file
*file
, int from_tty
,
94 struct cmd_list_element
*c
, const char *value
)
96 fprintf_filtered (file
, _("Auto-loading of canned sequences of commands "
101 /* Return non-zero if auto-loading gdb scripts is enabled. */
104 auto_load_gdb_scripts_enabled (const struct extension_language_defn
*extlang
)
106 return auto_load_gdb_scripts
;
109 /* Internal-use flag to enable/disable auto-loading.
110 This is true if we should auto-load python code when an objfile is opened,
113 Both auto_load_scripts && global_auto_load must be true to enable
116 This flag exists to facilitate deferring auto-loading during start-up
117 until after ./.gdbinit has been read; it may augment the search directories
118 used to find the scripts. */
119 int global_auto_load
= 1;
121 /* Auto-load .gdbinit file from the current directory? */
122 int auto_load_local_gdbinit
= 1;
124 /* Absolute pathname to the current directory .gdbinit, if it exists. */
125 char *auto_load_local_gdbinit_pathname
= NULL
;
127 /* Boolean value if AUTO_LOAD_LOCAL_GDBINIT_PATHNAME has been loaded. */
128 int auto_load_local_gdbinit_loaded
= 0;
130 /* "show" command for the auto_load_local_gdbinit configuration variable. */
133 show_auto_load_local_gdbinit (struct ui_file
*file
, int from_tty
,
134 struct cmd_list_element
*c
, const char *value
)
136 fprintf_filtered (file
, _("Auto-loading of .gdbinit script from current "
137 "directory is %s.\n"),
141 /* Directory list from which to load auto-loaded scripts. It is not checked
142 for absolute paths but they are strongly recommended. It is initialized by
143 _initialize_auto_load. */
144 static char *auto_load_dir
;
146 /* "set" command for the auto_load_dir configuration variable. */
149 set_auto_load_dir (const char *args
, int from_tty
, struct cmd_list_element
*c
)
151 /* Setting the variable to "" resets it to the compile time defaults. */
152 if (auto_load_dir
[0] == '\0')
154 xfree (auto_load_dir
);
155 auto_load_dir
= xstrdup (AUTO_LOAD_DIR
);
159 /* "show" command for the auto_load_dir configuration variable. */
162 show_auto_load_dir (struct ui_file
*file
, int from_tty
,
163 struct cmd_list_element
*c
, const char *value
)
165 fprintf_filtered (file
, _("List of directories from which to load "
166 "auto-loaded scripts is %s.\n"),
170 /* Directory list safe to hold auto-loaded files. It is not checked for
171 absolute paths but they are strongly recommended. It is initialized by
172 _initialize_auto_load. */
173 static char *auto_load_safe_path
;
175 /* Vector of directory elements of AUTO_LOAD_SAFE_PATH with each one normalized
176 by tilde_expand and possibly each entries has added its gdb_realpath
178 std::vector
<gdb::unique_xmalloc_ptr
<char>> auto_load_safe_path_vec
;
180 /* Expand $datadir and $debugdir in STRING according to the rules of
181 substitute_path_component. */
183 static std::vector
<gdb::unique_xmalloc_ptr
<char>>
184 auto_load_expand_dir_vars (const char *string
)
186 char *s
= xstrdup (string
);
187 substitute_path_component (&s
, "$datadir", gdb_datadir
);
188 substitute_path_component (&s
, "$debugdir", debug_file_directory
);
190 if (debug_auto_load
&& strcmp (s
, string
) != 0)
191 fprintf_unfiltered (gdb_stdlog
,
192 _("auto-load: Expanded $-variables to \"%s\".\n"), s
);
194 std::vector
<gdb::unique_xmalloc_ptr
<char>> dir_vec
195 = dirnames_to_char_ptr_vec (s
);
201 /* Update auto_load_safe_path_vec from current AUTO_LOAD_SAFE_PATH. */
204 auto_load_safe_path_vec_update (void)
207 fprintf_unfiltered (gdb_stdlog
,
208 _("auto-load: Updating directories of \"%s\".\n"),
209 auto_load_safe_path
);
211 auto_load_safe_path_vec
= auto_load_expand_dir_vars (auto_load_safe_path
);
212 size_t len
= auto_load_safe_path_vec
.size ();
214 /* Apply tilde_expand and gdb_realpath to each AUTO_LOAD_SAFE_PATH_VEC
216 for (size_t i
= 0; i
< len
; i
++)
218 gdb::unique_xmalloc_ptr
<char> &in_vec
= auto_load_safe_path_vec
[i
];
219 gdb::unique_xmalloc_ptr
<char> expanded (tilde_expand (in_vec
.get ()));
220 gdb::unique_xmalloc_ptr
<char> real_path
= gdb_realpath (expanded
.get ());
222 /* Ensure the current entry is at least tilde_expand-ed. ORIGINAL makes
223 sure we free the original string. */
224 gdb::unique_xmalloc_ptr
<char> original
= std::move (in_vec
);
225 in_vec
= std::move (expanded
);
229 if (strcmp (in_vec
.get (), original
.get ()) == 0)
230 fprintf_unfiltered (gdb_stdlog
,
231 _("auto-load: Using directory \"%s\".\n"),
234 fprintf_unfiltered (gdb_stdlog
,
235 _("auto-load: Resolved directory \"%s\" "
237 original
.get (), in_vec
.get ());
240 /* If gdb_realpath returns a different content, append it. */
241 if (strcmp (real_path
.get (), in_vec
.get ()) != 0)
244 fprintf_unfiltered (gdb_stdlog
,
245 _("auto-load: And canonicalized as \"%s\".\n"),
248 auto_load_safe_path_vec
.push_back (std::move (real_path
));
253 /* Variable gdb_datadir has been set. Update content depending on $datadir. */
256 auto_load_gdb_datadir_changed (void)
258 auto_load_safe_path_vec_update ();
261 /* "set" command for the auto_load_safe_path configuration variable. */
264 set_auto_load_safe_path (const char *args
,
265 int from_tty
, struct cmd_list_element
*c
)
267 /* Setting the variable to "" resets it to the compile time defaults. */
268 if (auto_load_safe_path
[0] == '\0')
270 xfree (auto_load_safe_path
);
271 auto_load_safe_path
= xstrdup (AUTO_LOAD_SAFE_PATH
);
274 auto_load_safe_path_vec_update ();
277 /* "show" command for the auto_load_safe_path configuration variable. */
280 show_auto_load_safe_path (struct ui_file
*file
, int from_tty
,
281 struct cmd_list_element
*c
, const char *value
)
285 /* Check if user has entered either "/" or for example ":".
286 But while more complicate content like ":/foo" would still also
287 permit any location do not hide those. */
289 for (cs
= value
; *cs
&& (*cs
== DIRNAME_SEPARATOR
|| IS_DIR_SEPARATOR (*cs
));
292 fprintf_filtered (file
, _("Auto-load files are safe to load from any "
295 fprintf_filtered (file
, _("List of directories from which it is safe to "
296 "auto-load files is %s.\n"),
300 /* "add-auto-load-safe-path" command for the auto_load_safe_path configuration
304 add_auto_load_safe_path (const char *args
, int from_tty
)
308 if (args
== NULL
|| *args
== 0)
310 Directory argument required.\n\
311 Use 'set auto-load safe-path /' for disabling the auto-load safe-path security.\
314 s
= xstrprintf ("%s%c%s", auto_load_safe_path
, DIRNAME_SEPARATOR
, args
);
315 xfree (auto_load_safe_path
);
316 auto_load_safe_path
= s
;
318 auto_load_safe_path_vec_update ();
321 /* "add-auto-load-scripts-directory" command for the auto_load_dir configuration
325 add_auto_load_dir (const char *args
, int from_tty
)
329 if (args
== NULL
|| *args
== 0)
330 error (_("Directory argument required."));
332 s
= xstrprintf ("%s%c%s", auto_load_dir
, DIRNAME_SEPARATOR
, args
);
333 xfree (auto_load_dir
);
337 /* Implementation for filename_is_in_pattern overwriting the caller's FILENAME
341 filename_is_in_pattern_1 (char *filename
, char *pattern
)
343 size_t pattern_len
= strlen (pattern
);
344 size_t filename_len
= strlen (filename
);
347 fprintf_unfiltered (gdb_stdlog
, _("auto-load: Matching file \"%s\" "
348 "to pattern \"%s\"\n"),
351 /* Trim trailing slashes ("/") from PATTERN. Even for "d:\" paths as
352 trailing slashes are trimmed also from FILENAME it still matches
354 while (pattern_len
&& IS_DIR_SEPARATOR (pattern
[pattern_len
- 1]))
356 pattern
[pattern_len
] = '\0';
358 /* Ensure auto_load_safe_path "/" matches any FILENAME. On MS-Windows
359 platform FILENAME even after gdb_realpath does not have to start with
360 IS_DIR_SEPARATOR character, such as the 'C:\x.exe' filename. */
361 if (pattern_len
== 0)
364 fprintf_unfiltered (gdb_stdlog
,
365 _("auto-load: Matched - empty pattern\n"));
371 /* Trim trailing slashes ("/"). PATTERN also has slashes trimmed the
372 same way so they will match. */
373 while (filename_len
&& IS_DIR_SEPARATOR (filename
[filename_len
- 1]))
375 filename
[filename_len
] = '\0';
376 if (filename_len
== 0)
379 fprintf_unfiltered (gdb_stdlog
,
380 _("auto-load: Not matched - pattern \"%s\".\n"),
385 if (gdb_filename_fnmatch (pattern
, filename
, FNM_FILE_NAME
| FNM_NOESCAPE
)
389 fprintf_unfiltered (gdb_stdlog
, _("auto-load: Matched - file "
390 "\"%s\" to pattern \"%s\".\n"),
395 /* Trim trailing FILENAME component. */
396 while (filename_len
> 0 && !IS_DIR_SEPARATOR (filename
[filename_len
- 1]))
401 /* Return 1 if FILENAME matches PATTERN or if FILENAME resides in
402 a subdirectory of a directory that matches PATTERN. Return 0 otherwise.
403 gdb_realpath normalization is never done here. */
405 static ATTRIBUTE_PURE
int
406 filename_is_in_pattern (const char *filename
, const char *pattern
)
408 char *filename_copy
, *pattern_copy
;
410 filename_copy
= (char *) alloca (strlen (filename
) + 1);
411 strcpy (filename_copy
, filename
);
412 pattern_copy
= (char *) alloca (strlen (pattern
) + 1);
413 strcpy (pattern_copy
, pattern
);
415 return filename_is_in_pattern_1 (filename_copy
, pattern_copy
);
418 /* Return 1 if FILENAME belongs to one of directory components of
419 AUTO_LOAD_SAFE_PATH_VEC. Return 0 otherwise.
420 auto_load_safe_path_vec_update is never called.
421 *FILENAME_REALP may be updated by gdb_realpath of FILENAME. */
424 filename_is_in_auto_load_safe_path_vec (const char *filename
,
425 gdb::unique_xmalloc_ptr
<char> *filename_realp
)
427 const char *pattern
= NULL
;
429 for (const gdb::unique_xmalloc_ptr
<char> &p
: auto_load_safe_path_vec
)
430 if (*filename_realp
== NULL
&& filename_is_in_pattern (filename
, p
.get ()))
438 if (*filename_realp
== NULL
)
440 *filename_realp
= gdb_realpath (filename
);
441 if (debug_auto_load
&& strcmp (filename_realp
->get (), filename
) != 0)
442 fprintf_unfiltered (gdb_stdlog
,
443 _("auto-load: Resolved "
444 "file \"%s\" as \"%s\".\n"),
445 filename
, filename_realp
->get ());
448 if (strcmp (filename_realp
->get (), filename
) != 0)
449 for (const gdb::unique_xmalloc_ptr
<char> &p
: auto_load_safe_path_vec
)
450 if (filename_is_in_pattern (filename_realp
->get (), p
.get ()))
460 fprintf_unfiltered (gdb_stdlog
, _("auto-load: File \"%s\" matches "
461 "directory \"%s\".\n"),
469 /* Return 1 if FILENAME is located in one of the directories of
470 AUTO_LOAD_SAFE_PATH. Otherwise call warning and return 0. FILENAME does
471 not have to be an absolute path.
473 Existence of FILENAME is not checked. Function will still give a warning
474 even if the caller would quietly skip non-existing file in unsafe
478 file_is_auto_load_safe (const char *filename
, const char *debug_fmt
, ...)
480 gdb::unique_xmalloc_ptr
<char> filename_real
;
481 static int advice_printed
= 0;
487 va_start (debug_args
, debug_fmt
);
488 vfprintf_unfiltered (gdb_stdlog
, debug_fmt
, debug_args
);
492 if (filename_is_in_auto_load_safe_path_vec (filename
, &filename_real
))
495 auto_load_safe_path_vec_update ();
496 if (filename_is_in_auto_load_safe_path_vec (filename
, &filename_real
))
499 warning (_("File \"%s\" auto-loading has been declined by your "
500 "`auto-load safe-path' set to \"%s\"."),
501 filename_real
.get (), auto_load_safe_path
);
505 const char *homedir
= getenv ("HOME");
509 std::string homeinit
= string_printf ("%s/%s", homedir
, gdbinit
);
511 printf_filtered (_("\
512 To enable execution of this file add\n\
513 \tadd-auto-load-safe-path %s\n\
514 line to your configuration file \"%s\".\n\
515 To completely disable this security protection add\n\
516 \tset auto-load safe-path /\n\
517 line to your configuration file \"%s\".\n\
518 For more information about this security protection see the\n\
519 \"Auto-loading safe path\" section in the GDB manual. E.g., run from the shell:\n\
520 \tinfo \"(gdb)Auto-loading safe path\"\n"),
521 filename_real
.get (),
522 homeinit
.c_str (), homeinit
.c_str ());
529 /* For scripts specified in .debug_gdb_scripts, multiple objfiles may load
530 the same script. There's no point in loading the script multiple times,
531 and there can be a lot of objfiles and scripts, so we keep track of scripts
534 struct auto_load_pspace_info
536 /* For each program space we keep track of loaded scripts, both when
537 specified as file names and as scripts to be executed directly. */
538 struct htab
*loaded_script_files
;
539 struct htab
*loaded_script_texts
;
541 /* Non-zero if we've issued the warning about an auto-load script not being
542 supported. We only want to issue this warning once. */
543 int unsupported_script_warning_printed
;
545 /* Non-zero if we've issued the warning about an auto-load script not being
546 found. We only want to issue this warning once. */
547 int script_not_found_warning_printed
;
550 /* Objects of this type are stored in the loaded_script hash table. */
554 /* Name as provided by the objfile. */
557 /* Full path name or NULL if script wasn't found (or was otherwise
558 inaccessible), or NULL for loaded_script_texts. */
559 const char *full_path
;
561 /* Non-zero if this script has been loaded. */
564 const struct extension_language_defn
*language
;
567 /* Per-program-space data key. */
568 static const struct program_space_data
*auto_load_pspace_data
;
571 auto_load_pspace_data_cleanup (struct program_space
*pspace
, void *arg
)
573 struct auto_load_pspace_info
*info
= (struct auto_load_pspace_info
*) arg
;
575 if (info
->loaded_script_files
)
576 htab_delete (info
->loaded_script_files
);
577 if (info
->loaded_script_texts
)
578 htab_delete (info
->loaded_script_texts
);
582 /* Get the current autoload data. If none is found yet, add it now. This
583 function always returns a valid object. */
585 static struct auto_load_pspace_info
*
586 get_auto_load_pspace_data (struct program_space
*pspace
)
588 struct auto_load_pspace_info
*info
;
590 info
= ((struct auto_load_pspace_info
*)
591 program_space_data (pspace
, auto_load_pspace_data
));
594 info
= XCNEW (struct auto_load_pspace_info
);
595 set_program_space_data (pspace
, auto_load_pspace_data
, info
);
601 /* Hash function for the loaded script hash. */
604 hash_loaded_script_entry (const void *data
)
606 const struct loaded_script
*e
= (const struct loaded_script
*) data
;
608 return htab_hash_string (e
->name
) ^ htab_hash_pointer (e
->language
);
611 /* Equality function for the loaded script hash. */
614 eq_loaded_script_entry (const void *a
, const void *b
)
616 const struct loaded_script
*ea
= (const struct loaded_script
*) a
;
617 const struct loaded_script
*eb
= (const struct loaded_script
*) b
;
619 return strcmp (ea
->name
, eb
->name
) == 0 && ea
->language
== eb
->language
;
622 /* Initialize the table to track loaded scripts.
623 Each entry is hashed by the full path name. */
626 init_loaded_scripts_info (struct auto_load_pspace_info
*pspace_info
)
628 /* Choose 31 as the starting size of the hash table, somewhat arbitrarily.
629 Space for each entry is obtained with one malloc so we can free them
632 pspace_info
->loaded_script_files
= htab_create (31,
633 hash_loaded_script_entry
,
634 eq_loaded_script_entry
,
636 pspace_info
->loaded_script_texts
= htab_create (31,
637 hash_loaded_script_entry
,
638 eq_loaded_script_entry
,
641 pspace_info
->unsupported_script_warning_printed
= FALSE
;
642 pspace_info
->script_not_found_warning_printed
= FALSE
;
645 /* Wrapper on get_auto_load_pspace_data to also allocate the hash table
646 for loading scripts. */
648 struct auto_load_pspace_info
*
649 get_auto_load_pspace_data_for_loading (struct program_space
*pspace
)
651 struct auto_load_pspace_info
*info
;
653 info
= get_auto_load_pspace_data (pspace
);
654 if (info
->loaded_script_files
== NULL
)
655 init_loaded_scripts_info (info
);
660 /* Add script file NAME in LANGUAGE to hash table of PSPACE_INFO.
661 LOADED 1 if the script has been (is going to) be loaded, 0 otherwise
662 (such as if it has not been found).
663 FULL_PATH is NULL if the script wasn't found.
664 The result is true if the script was already in the hash table. */
667 maybe_add_script_file (struct auto_load_pspace_info
*pspace_info
, int loaded
,
668 const char *name
, const char *full_path
,
669 const struct extension_language_defn
*language
)
671 struct htab
*htab
= pspace_info
->loaded_script_files
;
672 struct loaded_script
**slot
, entry
;
676 entry
.language
= language
;
677 slot
= (struct loaded_script
**) htab_find_slot (htab
, &entry
, INSERT
);
678 in_hash_table
= *slot
!= NULL
;
680 /* If this script is not in the hash table, add it. */
686 /* Allocate all space in one chunk so it's easier to free. */
687 *slot
= ((struct loaded_script
*)
688 xmalloc (sizeof (**slot
)
690 + (full_path
!= NULL
? (strlen (full_path
) + 1) : 0)));
691 p
= ((char*) *slot
) + sizeof (**slot
);
694 if (full_path
!= NULL
)
697 strcpy (p
, full_path
);
698 (*slot
)->full_path
= p
;
701 (*slot
)->full_path
= NULL
;
702 (*slot
)->loaded
= loaded
;
703 (*slot
)->language
= language
;
706 return in_hash_table
;
709 /* Add script contents NAME in LANGUAGE to hash table of PSPACE_INFO.
710 LOADED 1 if the script has been (is going to) be loaded, 0 otherwise
711 (such as if it has not been found).
712 The result is true if the script was already in the hash table. */
715 maybe_add_script_text (struct auto_load_pspace_info
*pspace_info
,
716 int loaded
, const char *name
,
717 const struct extension_language_defn
*language
)
719 struct htab
*htab
= pspace_info
->loaded_script_texts
;
720 struct loaded_script
**slot
, entry
;
724 entry
.language
= language
;
725 slot
= (struct loaded_script
**) htab_find_slot (htab
, &entry
, INSERT
);
726 in_hash_table
= *slot
!= NULL
;
728 /* If this script is not in the hash table, add it. */
734 /* Allocate all space in one chunk so it's easier to free. */
735 *slot
= ((struct loaded_script
*)
736 xmalloc (sizeof (**slot
) + strlen (name
) + 1));
737 p
= ((char*) *slot
) + sizeof (**slot
);
740 (*slot
)->full_path
= NULL
;
741 (*slot
)->loaded
= loaded
;
742 (*slot
)->language
= language
;
745 return in_hash_table
;
748 /* Clear the table of loaded section scripts. */
751 clear_section_scripts (void)
753 struct program_space
*pspace
= current_program_space
;
754 struct auto_load_pspace_info
*info
;
756 info
= ((struct auto_load_pspace_info
*)
757 program_space_data (pspace
, auto_load_pspace_data
));
758 if (info
!= NULL
&& info
->loaded_script_files
!= NULL
)
760 htab_delete (info
->loaded_script_files
);
761 htab_delete (info
->loaded_script_texts
);
762 info
->loaded_script_files
= NULL
;
763 info
->loaded_script_texts
= NULL
;
764 info
->unsupported_script_warning_printed
= FALSE
;
765 info
->script_not_found_warning_printed
= FALSE
;
769 /* Look for the auto-load script in LANGUAGE associated with OBJFILE where
770 OBJFILE's gdb_realpath is REALNAME and load it. Return 1 if we found any
771 matching script, return 0 otherwise. */
774 auto_load_objfile_script_1 (struct objfile
*objfile
, const char *realname
,
775 const struct extension_language_defn
*language
)
777 const char *debugfile
;
779 const char *suffix
= ext_lang_auto_load_suffix (language
);
781 std::string filename
= std::string (realname
) + suffix
;
783 gdb_file_up input
= gdb_fopen_cloexec (filename
.c_str (), "r");
784 debugfile
= filename
.c_str ();
786 fprintf_unfiltered (gdb_stdlog
, _("auto-load: Attempted file \"%s\" %s.\n"),
787 debugfile
, input
? _("exists") : _("does not exist"));
789 std::string debugfile_holder
;
792 /* Also try the same file in a subdirectory of gdb's data
795 std::vector
<gdb::unique_xmalloc_ptr
<char>> vec
796 = auto_load_expand_dir_vars (auto_load_dir
);
799 fprintf_unfiltered (gdb_stdlog
, _("auto-load: Searching 'set auto-load "
800 "scripts-directory' path \"%s\".\n"),
803 for (const gdb::unique_xmalloc_ptr
<char> &dir
: vec
)
805 /* FILENAME is absolute, so we don't need a "/" here. */
806 debugfile_holder
= dir
.get () + filename
;
807 debugfile
= debugfile_holder
.c_str ();
809 input
= gdb_fopen_cloexec (debugfile
, "r");
811 fprintf_unfiltered (gdb_stdlog
, _("auto-load: Attempted file "
814 input
? _("exists") : _("does not exist"));
823 struct auto_load_pspace_info
*pspace_info
;
826 = file_is_auto_load_safe (debugfile
,
827 _("auto-load: Loading %s script \"%s\""
828 " by extension for objfile \"%s\".\n"),
829 ext_lang_name (language
),
830 debugfile
, objfile_name (objfile
));
832 /* Add this script to the hash table too so
833 "info auto-load ${lang}-scripts" can print it. */
835 = get_auto_load_pspace_data_for_loading (current_program_space
);
836 maybe_add_script_file (pspace_info
, is_safe
, debugfile
, debugfile
,
839 /* To preserve existing behaviour we don't check for whether the
840 script was already in the table, and always load it.
841 It's highly unlikely that we'd ever load it twice,
842 and these scripts are required to be idempotent under multiple
846 objfile_script_sourcer_func
*sourcer
847 = ext_lang_objfile_script_sourcer (language
);
849 /* We shouldn't get here if support for the language isn't
850 compiled in. And the extension language is required to implement
852 gdb_assert (sourcer
!= NULL
);
853 sourcer (language
, objfile
, input
.get (), debugfile
);
864 /* Look for the auto-load script in LANGUAGE associated with OBJFILE and load
868 auto_load_objfile_script (struct objfile
*objfile
,
869 const struct extension_language_defn
*language
)
871 gdb::unique_xmalloc_ptr
<char> realname
872 = gdb_realpath (objfile_name (objfile
));
874 if (!auto_load_objfile_script_1 (objfile
, realname
.get (), language
))
876 /* For Windows/DOS .exe executables, strip the .exe suffix, so that
877 FOO-gdb.gdb could be used for FOO.exe, and try again. */
879 size_t len
= strlen (realname
.get ());
880 const size_t lexe
= sizeof (".exe") - 1;
882 if (len
> lexe
&& strcasecmp (realname
.get () + len
- lexe
, ".exe") == 0)
885 realname
.get ()[len
] = '\0';
887 fprintf_unfiltered (gdb_stdlog
, _("auto-load: Stripped .exe suffix, "
888 "retrying with \"%s\".\n"),
890 auto_load_objfile_script_1 (objfile
, realname
.get (), language
);
895 /* Subroutine of source_section_scripts to simplify it.
896 Load FILE as a script in extension language LANGUAGE.
897 The script is from section SECTION_NAME in OBJFILE at offset OFFSET. */
900 source_script_file (struct auto_load_pspace_info
*pspace_info
,
901 struct objfile
*objfile
,
902 const struct extension_language_defn
*language
,
903 const char *section_name
, unsigned int offset
,
907 objfile_script_sourcer_func
*sourcer
;
909 /* Skip this script if support is not compiled in. */
910 sourcer
= ext_lang_objfile_script_sourcer (language
);
913 /* We don't throw an error, the program is still debuggable. */
914 maybe_print_unsupported_script_warning (pspace_info
, objfile
, language
,
915 section_name
, offset
);
916 /* We *could* still try to open it, but there's no point. */
917 maybe_add_script_file (pspace_info
, 0, file
, NULL
, language
);
921 /* Skip this script if auto-loading it has been disabled. */
922 if (!ext_lang_auto_load_enabled (language
))
924 /* No message is printed, just skip it. */
928 gdb::optional
<open_script
> opened
= find_and_open_script (file
,
933 if (!file_is_auto_load_safe (opened
->full_path
.get (),
934 _("auto-load: Loading %s script "
935 "\"%s\" from section \"%s\" of "
936 "objfile \"%s\".\n"),
937 ext_lang_name (language
),
938 opened
->full_path
.get (),
939 section_name
, objfile_name (objfile
)))
944 /* If one script isn't found it's not uncommon for more to not be
945 found either. We don't want to print a message for each script,
946 too much noise. Instead, we print the warning once and tell the
947 user how to find the list of scripts that weren't loaded.
948 We don't throw an error, the program is still debuggable.
950 IWBN if complaints.c were more general-purpose. */
952 maybe_print_script_not_found_warning (pspace_info
, objfile
, language
,
953 section_name
, offset
);
956 in_hash_table
= maybe_add_script_file (pspace_info
, bool (opened
), file
,
958 ? opened
->full_path
.get ()
962 /* If this file is not currently loaded, load it. */
963 if (opened
&& !in_hash_table
)
964 sourcer (language
, objfile
, opened
->stream
.get (),
965 opened
->full_path
.get ());
968 /* Subroutine of source_section_scripts to simplify it.
969 Execute SCRIPT as a script in extension language LANG.
970 The script is from section SECTION_NAME in OBJFILE at offset OFFSET. */
973 execute_script_contents (struct auto_load_pspace_info
*pspace_info
,
974 struct objfile
*objfile
,
975 const struct extension_language_defn
*language
,
976 const char *section_name
, unsigned int offset
,
979 objfile_script_executor_func
*executor
;
980 const char *newline
, *script_text
;
982 int is_safe
, in_hash_table
;
984 /* The first line of the script is the name of the script.
985 It must not contain any kind of space character. */
987 newline
= strchr (script
, '\n');
988 std::string name_holder
;
993 /* Put the name in a buffer and validate it. */
994 name_holder
= std::string (script
, newline
- script
);
995 buf
= name_holder
.c_str ();
996 for (p
= buf
; *p
!= '\0'; ++p
)
1001 /* We don't allow nameless scripts, they're not helpful to the user. */
1002 if (p
!= buf
&& *p
== '\0')
1007 /* We don't throw an error, the program is still debuggable. */
1009 Missing/bad script name in entry at offset %u in section %s\n\
1011 offset
, section_name
, objfile_name (objfile
));
1014 script_text
= newline
+ 1;
1016 /* Skip this script if support is not compiled in. */
1017 executor
= ext_lang_objfile_script_executor (language
);
1018 if (executor
== NULL
)
1020 /* We don't throw an error, the program is still debuggable. */
1021 maybe_print_unsupported_script_warning (pspace_info
, objfile
, language
,
1022 section_name
, offset
);
1023 maybe_add_script_text (pspace_info
, 0, name
, language
);
1027 /* Skip this script if auto-loading it has been disabled. */
1028 if (!ext_lang_auto_load_enabled (language
))
1030 /* No message is printed, just skip it. */
1034 is_safe
= file_is_auto_load_safe (objfile_name (objfile
),
1035 _("auto-load: Loading %s script "
1036 "\"%s\" from section \"%s\" of "
1037 "objfile \"%s\".\n"),
1038 ext_lang_name (language
), name
,
1039 section_name
, objfile_name (objfile
));
1041 in_hash_table
= maybe_add_script_text (pspace_info
, is_safe
, name
, language
);
1043 /* If this file is not currently loaded, load it. */
1044 if (is_safe
&& !in_hash_table
)
1045 executor (language
, objfile
, name
, script_text
);
1048 /* Load scripts specified in OBJFILE.
1049 START,END delimit a buffer containing a list of nul-terminated
1051 SECTION_NAME is used in error messages.
1053 Scripts specified as file names are found per normal "source -s" command
1054 processing. First the script is looked for in $cwd. If not found there
1055 the source search path is used.
1057 The section contains a list of path names of script files to load or
1058 actual script contents. Each entry is nul-terminated. */
1061 source_section_scripts (struct objfile
*objfile
, const char *section_name
,
1062 const char *start
, const char *end
)
1065 struct auto_load_pspace_info
*pspace_info
;
1067 pspace_info
= get_auto_load_pspace_data_for_loading (current_program_space
);
1069 for (p
= start
; p
< end
; ++p
)
1072 const struct extension_language_defn
*language
;
1073 unsigned int offset
= p
- start
;
1078 case SECTION_SCRIPT_ID_PYTHON_FILE
:
1079 case SECTION_SCRIPT_ID_PYTHON_TEXT
:
1080 language
= get_ext_lang_defn (EXT_LANG_PYTHON
);
1082 case SECTION_SCRIPT_ID_SCHEME_FILE
:
1083 case SECTION_SCRIPT_ID_SCHEME_TEXT
:
1084 language
= get_ext_lang_defn (EXT_LANG_GUILE
);
1087 warning (_("Invalid entry in %s section"), section_name
);
1088 /* We could try various heuristics to find the next valid entry,
1089 but it's safer to just punt. */
1094 while (p
< end
&& *p
!= '\0')
1098 warning (_("Non-nul-terminated entry in %s at offset %u"),
1099 section_name
, offset
);
1100 /* Don't load/execute it. */
1106 case SECTION_SCRIPT_ID_PYTHON_FILE
:
1107 case SECTION_SCRIPT_ID_SCHEME_FILE
:
1110 warning (_("Empty entry in %s at offset %u"),
1111 section_name
, offset
);
1114 source_script_file (pspace_info
, objfile
, language
,
1115 section_name
, offset
, entry
);
1117 case SECTION_SCRIPT_ID_PYTHON_TEXT
:
1118 case SECTION_SCRIPT_ID_SCHEME_TEXT
:
1119 execute_script_contents (pspace_info
, objfile
, language
,
1120 section_name
, offset
, entry
);
1126 /* Load scripts specified in section SECTION_NAME of OBJFILE. */
1129 auto_load_section_scripts (struct objfile
*objfile
, const char *section_name
)
1131 bfd
*abfd
= objfile
->obfd
;
1132 asection
*scripts_sect
;
1133 bfd_byte
*data
= NULL
;
1135 scripts_sect
= bfd_get_section_by_name (abfd
, section_name
);
1136 if (scripts_sect
== NULL
1137 || (bfd_get_section_flags (abfd
, scripts_sect
) & SEC_HAS_CONTENTS
) == 0)
1140 if (!bfd_get_full_section_contents (abfd
, scripts_sect
, &data
))
1141 warning (_("Couldn't read %s section of %s"),
1142 section_name
, bfd_get_filename (abfd
));
1145 gdb::unique_xmalloc_ptr
<bfd_byte
> data_holder (data
);
1147 char *p
= (char *) data
;
1148 source_section_scripts (objfile
, section_name
, p
,
1149 p
+ bfd_get_section_size (scripts_sect
));
1153 /* Load any auto-loaded scripts for OBJFILE. */
1156 load_auto_scripts_for_objfile (struct objfile
*objfile
)
1158 /* Return immediately if auto-loading has been globally disabled.
1159 This is to handle sequencing of operations during gdb startup.
1160 Also return immediately if OBJFILE was not created from a file
1161 on the local filesystem. */
1162 if (!global_auto_load
1163 || (objfile
->flags
& OBJF_NOT_FILENAME
) != 0
1164 || is_target_filename (objfile
->original_name
))
1167 /* Load any extension language scripts for this objfile.
1168 E.g., foo-gdb.gdb, foo-gdb.py. */
1169 auto_load_ext_lang_scripts_for_objfile (objfile
);
1171 /* Load any scripts mentioned in AUTO_SECTION_NAME (.debug_gdb_scripts). */
1172 auto_load_section_scripts (objfile
, AUTO_SECTION_NAME
);
1175 /* This is a new_objfile observer callback to auto-load scripts.
1177 Two flavors of auto-loaded scripts are supported.
1178 1) based on the path to the objfile
1179 2) from .debug_gdb_scripts section */
1182 auto_load_new_objfile (struct objfile
*objfile
)
1186 /* OBJFILE is NULL when loading a new "main" symbol-file. */
1187 clear_section_scripts ();
1191 load_auto_scripts_for_objfile (objfile
);
1194 /* Collect scripts to be printed in a vec. */
1196 struct collect_matching_scripts_data
1198 collect_matching_scripts_data (std::vector
<loaded_script
*> *scripts_p_
,
1199 const extension_language_defn
*language_
)
1200 : scripts_p (scripts_p_
), language (language_
)
1203 std::vector
<loaded_script
*> *scripts_p
;
1204 const struct extension_language_defn
*language
;
1207 /* Traversal function for htab_traverse.
1208 Collect the entry if it matches the regexp. */
1211 collect_matching_scripts (void **slot
, void *info
)
1213 struct loaded_script
*script
= (struct loaded_script
*) *slot
;
1214 struct collect_matching_scripts_data
*data
1215 = (struct collect_matching_scripts_data
*) info
;
1217 if (script
->language
== data
->language
&& re_exec (script
->name
))
1218 data
->scripts_p
->push_back (script
);
1226 print_script (struct loaded_script
*script
)
1228 struct ui_out
*uiout
= current_uiout
;
1230 ui_out_emit_tuple
tuple_emitter (uiout
, NULL
);
1232 uiout
->field_string ("loaded", script
->loaded
? "Yes" : "No");
1233 uiout
->field_string ("script", script
->name
);
1236 /* If the name isn't the full path, print it too. */
1237 if (script
->full_path
!= NULL
1238 && strcmp (script
->name
, script
->full_path
) != 0)
1240 uiout
->text ("\tfull name: ");
1241 uiout
->field_string ("full_path", script
->full_path
);
1246 /* Helper for info_auto_load_scripts to sort the scripts by name. */
1249 sort_scripts_by_name (loaded_script
*a
, loaded_script
*b
)
1251 return FILENAME_CMP (a
->name
, b
->name
) < 0;
1254 /* Special internal GDB value of auto_load_info_scripts's PATTERN identify
1255 the "info auto-load XXX" command has been executed through the general
1256 "info auto-load" invocation. Extra newline will be printed if needed. */
1257 char auto_load_info_scripts_pattern_nl
[] = "";
1259 /* Subroutine of auto_load_info_scripts to simplify it.
1263 print_scripts (const std::vector
<loaded_script
*> &scripts
)
1265 for (loaded_script
*script
: scripts
)
1266 print_script (script
);
1269 /* Implementation for "info auto-load gdb-scripts"
1270 (and "info auto-load python-scripts"). List scripts in LANGUAGE matching
1271 PATTERN. FROM_TTY is the usual GDB boolean for user interactivity. */
1274 auto_load_info_scripts (const char *pattern
, int from_tty
,
1275 const struct extension_language_defn
*language
)
1277 struct ui_out
*uiout
= current_uiout
;
1278 struct auto_load_pspace_info
*pspace_info
;
1282 pspace_info
= get_auto_load_pspace_data (current_program_space
);
1284 if (pattern
&& *pattern
)
1286 char *re_err
= re_comp (pattern
);
1289 error (_("Invalid regexp: %s"), re_err
);
1296 /* We need to know the number of rows before we build the table.
1297 Plus we want to sort the scripts by name.
1298 So first traverse the hash table collecting the matching scripts. */
1300 std::vector
<loaded_script
*> script_files
, script_texts
;
1302 if (pspace_info
!= NULL
&& pspace_info
->loaded_script_files
!= NULL
)
1304 collect_matching_scripts_data
data (&script_files
, language
);
1306 /* Pass a pointer to scripts as VEC_safe_push can realloc space. */
1307 htab_traverse_noresize (pspace_info
->loaded_script_files
,
1308 collect_matching_scripts
, &data
);
1310 std::sort (script_files
.begin (), script_files
.end (),
1311 sort_scripts_by_name
);
1314 if (pspace_info
!= NULL
&& pspace_info
->loaded_script_texts
!= NULL
)
1316 collect_matching_scripts_data
data (&script_texts
, language
);
1318 /* Pass a pointer to scripts as VEC_safe_push can realloc space. */
1319 htab_traverse_noresize (pspace_info
->loaded_script_texts
,
1320 collect_matching_scripts
, &data
);
1322 std::sort (script_texts
.begin (), script_texts
.end (),
1323 sort_scripts_by_name
);
1326 int nr_scripts
= script_files
.size () + script_texts
.size ();
1328 /* Table header shifted right by preceding "gdb-scripts: " would not match
1330 if (nr_scripts
> 0 && pattern
== auto_load_info_scripts_pattern_nl
)
1334 ui_out_emit_table
table_emitter (uiout
, 2, nr_scripts
,
1335 "AutoLoadedScriptsTable");
1337 uiout
->table_header (7, ui_left
, "loaded", "Loaded");
1338 uiout
->table_header (70, ui_left
, "script", "Script");
1339 uiout
->table_body ();
1341 print_scripts (script_files
);
1342 print_scripts (script_texts
);
1345 if (nr_scripts
== 0)
1347 if (pattern
&& *pattern
)
1348 uiout
->message ("No auto-load scripts matching %s.\n", pattern
);
1350 uiout
->message ("No auto-load scripts.\n");
1354 /* Wrapper for "info auto-load gdb-scripts". */
1357 info_auto_load_gdb_scripts (const char *pattern
, int from_tty
)
1359 auto_load_info_scripts (pattern
, from_tty
, &extension_language_gdb
);
1362 /* Implement 'info auto-load local-gdbinit'. */
1365 info_auto_load_local_gdbinit (const char *args
, int from_tty
)
1367 if (auto_load_local_gdbinit_pathname
== NULL
)
1368 printf_filtered (_("Local .gdbinit file was not found.\n"));
1369 else if (auto_load_local_gdbinit_loaded
)
1370 printf_filtered (_("Local .gdbinit file \"%s\" has been loaded.\n"),
1371 auto_load_local_gdbinit_pathname
);
1373 printf_filtered (_("Local .gdbinit file \"%s\" has not been loaded.\n"),
1374 auto_load_local_gdbinit_pathname
);
1377 /* Print an "unsupported script" warning if it has not already been printed.
1378 The script is in language LANGUAGE at offset OFFSET in section SECTION_NAME
1382 maybe_print_unsupported_script_warning
1383 (struct auto_load_pspace_info
*pspace_info
,
1384 struct objfile
*objfile
, const struct extension_language_defn
*language
,
1385 const char *section_name
, unsigned offset
)
1387 if (!pspace_info
->unsupported_script_warning_printed
)
1390 Unsupported auto-load script at offset %u in section %s\n\
1392 Use `info auto-load %s-scripts [REGEXP]' to list them."),
1393 offset
, section_name
, objfile_name (objfile
),
1394 ext_lang_name (language
));
1395 pspace_info
->unsupported_script_warning_printed
= 1;
1399 /* Return non-zero if SCRIPT_NOT_FOUND_WARNING_PRINTED of PSPACE_INFO was unset
1400 before calling this function. Always set SCRIPT_NOT_FOUND_WARNING_PRINTED
1404 maybe_print_script_not_found_warning
1405 (struct auto_load_pspace_info
*pspace_info
,
1406 struct objfile
*objfile
, const struct extension_language_defn
*language
,
1407 const char *section_name
, unsigned offset
)
1409 if (!pspace_info
->script_not_found_warning_printed
)
1412 Missing auto-load script at offset %u in section %s\n\
1414 Use `info auto-load %s-scripts [REGEXP]' to list them."),
1415 offset
, section_name
, objfile_name (objfile
),
1416 ext_lang_name (language
));
1417 pspace_info
->script_not_found_warning_printed
= 1;
1421 /* The only valid "set auto-load" argument is off|0|no|disable. */
1424 set_auto_load_cmd (const char *args
, int from_tty
)
1426 struct cmd_list_element
*list
;
1429 /* See parse_binary_operation in use by the sub-commands. */
1431 length
= args
? strlen (args
) : 0;
1433 while (length
> 0 && (args
[length
- 1] == ' ' || args
[length
- 1] == '\t'))
1436 if (length
== 0 || (strncmp (args
, "off", length
) != 0
1437 && strncmp (args
, "0", length
) != 0
1438 && strncmp (args
, "no", length
) != 0
1439 && strncmp (args
, "disable", length
) != 0))
1440 error (_("Valid is only global 'set auto-load no'; "
1441 "otherwise check the auto-load sub-commands."));
1443 for (list
= *auto_load_set_cmdlist_get (); list
!= NULL
; list
= list
->next
)
1444 if (list
->var_type
== var_boolean
)
1446 gdb_assert (list
->type
== set_cmd
);
1447 do_set_command (args
, from_tty
, list
);
1451 /* Initialize "set auto-load " commands prefix and return it. */
1453 struct cmd_list_element
**
1454 auto_load_set_cmdlist_get (void)
1456 static struct cmd_list_element
*retval
;
1459 add_prefix_cmd ("auto-load", class_maintenance
, set_auto_load_cmd
, _("\
1460 Auto-loading specific settings.\n\
1461 Configure various auto-load-specific variables such as\n\
1462 automatic loading of Python scripts."),
1463 &retval
, "set auto-load ",
1464 1/*allow-unknown*/, &setlist
);
1469 /* Command "show auto-load" displays summary of all the current
1470 "show auto-load " settings. */
1473 show_auto_load_cmd (const char *args
, int from_tty
)
1475 cmd_show_list (*auto_load_show_cmdlist_get (), from_tty
, "");
1478 /* Initialize "show auto-load " commands prefix and return it. */
1480 struct cmd_list_element
**
1481 auto_load_show_cmdlist_get (void)
1483 static struct cmd_list_element
*retval
;
1486 add_prefix_cmd ("auto-load", class_maintenance
, show_auto_load_cmd
, _("\
1487 Show auto-loading specific settings.\n\
1488 Show configuration of various auto-load-specific variables such as\n\
1489 automatic loading of Python scripts."),
1490 &retval
, "show auto-load ",
1491 0/*allow-unknown*/, &showlist
);
1496 /* Command "info auto-load" displays whether the various auto-load files have
1497 been loaded. This is reimplementation of cmd_show_list which inserts
1498 newlines at proper places. */
1501 info_auto_load_cmd (const char *args
, int from_tty
)
1503 struct cmd_list_element
*list
;
1504 struct ui_out
*uiout
= current_uiout
;
1506 ui_out_emit_tuple
tuple_emitter (uiout
, "infolist");
1508 for (list
= *auto_load_info_cmdlist_get (); list
!= NULL
; list
= list
->next
)
1510 ui_out_emit_tuple
option_emitter (uiout
, "option");
1512 gdb_assert (!list
->prefixlist
);
1513 gdb_assert (list
->type
== not_set_cmd
);
1515 uiout
->field_string ("name", list
->name
);
1517 cmd_func (list
, auto_load_info_scripts_pattern_nl
, from_tty
);
1521 /* Initialize "info auto-load " commands prefix and return it. */
1523 struct cmd_list_element
**
1524 auto_load_info_cmdlist_get (void)
1526 static struct cmd_list_element
*retval
;
1529 add_prefix_cmd ("auto-load", class_info
, info_auto_load_cmd
, _("\
1530 Print current status of auto-loaded files.\n\
1531 Print whether various files like Python scripts or .gdbinit files have been\n\
1532 found and/or loaded."),
1533 &retval
, "info auto-load ",
1534 0/*allow-unknown*/, &infolist
);
1540 _initialize_auto_load (void)
1542 struct cmd_list_element
*cmd
;
1543 char *scripts_directory_help
, *gdb_name_help
, *python_name_help
;
1544 char *guile_name_help
;
1547 auto_load_pspace_data
1548 = register_program_space_data_with_cleanup (NULL
,
1549 auto_load_pspace_data_cleanup
);
1551 gdb::observers::new_objfile
.attach (auto_load_new_objfile
);
1553 add_setshow_boolean_cmd ("gdb-scripts", class_support
,
1554 &auto_load_gdb_scripts
, _("\
1555 Enable or disable auto-loading of canned sequences of commands scripts."), _("\
1556 Show whether auto-loading of canned sequences of commands scripts is enabled."),
1558 If enabled, canned sequences of commands are loaded when the debugger reads\n\
1559 an executable or shared library.\n\
1560 This option has security implications for untrusted inferiors."),
1561 NULL
, show_auto_load_gdb_scripts
,
1562 auto_load_set_cmdlist_get (),
1563 auto_load_show_cmdlist_get ());
1565 add_cmd ("gdb-scripts", class_info
, info_auto_load_gdb_scripts
,
1566 _("Print the list of automatically loaded sequences of commands.\n\
1567 Usage: info auto-load gdb-scripts [REGEXP]"),
1568 auto_load_info_cmdlist_get ());
1570 add_setshow_boolean_cmd ("local-gdbinit", class_support
,
1571 &auto_load_local_gdbinit
, _("\
1572 Enable or disable auto-loading of .gdbinit script in current directory."), _("\
1573 Show whether auto-loading .gdbinit script in current directory is enabled."),
1575 If enabled, canned sequences of commands are loaded when debugger starts\n\
1576 from .gdbinit file in current directory. Such files are deprecated,\n\
1577 use a script associated with inferior executable file instead.\n\
1578 This option has security implications for untrusted inferiors."),
1579 NULL
, show_auto_load_local_gdbinit
,
1580 auto_load_set_cmdlist_get (),
1581 auto_load_show_cmdlist_get ());
1583 add_cmd ("local-gdbinit", class_info
, info_auto_load_local_gdbinit
,
1584 _("Print whether current directory .gdbinit file has been loaded.\n\
1585 Usage: info auto-load local-gdbinit"),
1586 auto_load_info_cmdlist_get ());
1588 auto_load_dir
= xstrdup (AUTO_LOAD_DIR
);
1590 suffix
= ext_lang_auto_load_suffix (get_ext_lang_defn (EXT_LANG_GDB
));
1593 GDB scripts: OBJFILE%s\n"),
1595 python_name_help
= NULL
;
1597 suffix
= ext_lang_auto_load_suffix (get_ext_lang_defn (EXT_LANG_PYTHON
));
1600 Python scripts: OBJFILE%s\n"),
1603 guile_name_help
= NULL
;
1605 suffix
= ext_lang_auto_load_suffix (get_ext_lang_defn (EXT_LANG_GUILE
));
1608 Guile scripts: OBJFILE%s\n"),
1611 scripts_directory_help
1613 Automatically loaded scripts are located in one of the directories listed\n\
1619 This option is ignored for the kinds of scripts \
1620 having 'set auto-load ... off'.\n\
1621 Directories listed here need to be present also \
1622 in the 'set auto-load safe-path'\n\
1625 python_name_help
? python_name_help
: "",
1626 guile_name_help
? guile_name_help
: "");
1628 add_setshow_optional_filename_cmd ("scripts-directory", class_support
,
1629 &auto_load_dir
, _("\
1630 Set the list of directories from which to load auto-loaded scripts."), _("\
1631 Show the list of directories from which to load auto-loaded scripts."),
1632 scripts_directory_help
,
1633 set_auto_load_dir
, show_auto_load_dir
,
1634 auto_load_set_cmdlist_get (),
1635 auto_load_show_cmdlist_get ());
1636 xfree (scripts_directory_help
);
1637 xfree (python_name_help
);
1638 xfree (gdb_name_help
);
1639 xfree (guile_name_help
);
1641 auto_load_safe_path
= xstrdup (AUTO_LOAD_SAFE_PATH
);
1642 auto_load_safe_path_vec_update ();
1643 add_setshow_optional_filename_cmd ("safe-path", class_support
,
1644 &auto_load_safe_path
, _("\
1645 Set the list of files and directories that are safe for auto-loading."), _("\
1646 Show the list of files and directories that are safe for auto-loading."), _("\
1647 Various files loaded automatically for the 'set auto-load ...' options must\n\
1648 be located in one of the directories listed by this option. Warning will be\n\
1649 printed and file will not be used otherwise.\n\
1650 You can mix both directory and filename entries.\n\
1651 Setting this parameter to an empty list resets it to its default value.\n\
1652 Setting this parameter to '/' (without the quotes) allows any file\n\
1653 for the 'set auto-load ...' options. Each path entry can be also shell\n\
1654 wildcard pattern; '*' does not match directory separator.\n\
1655 This option is ignored for the kinds of files having 'set auto-load ... off'.\n\
1656 This option has security implications for untrusted inferiors."),
1657 set_auto_load_safe_path
,
1658 show_auto_load_safe_path
,
1659 auto_load_set_cmdlist_get (),
1660 auto_load_show_cmdlist_get ());
1661 gdb::observers::gdb_datadir_changed
.attach (auto_load_gdb_datadir_changed
);
1663 cmd
= add_cmd ("add-auto-load-safe-path", class_support
,
1664 add_auto_load_safe_path
,
1665 _("Add entries to the list of directories from which it is safe "
1666 "to auto-load files.\n\
1667 See the commands 'set auto-load safe-path' and 'show auto-load safe-path' to\n\
1668 access the current full list setting."),
1670 set_cmd_completer (cmd
, filename_completer
);
1672 cmd
= add_cmd ("add-auto-load-scripts-directory", class_support
,
1674 _("Add entries to the list of directories from which to load "
1675 "auto-loaded scripts.\n\
1676 See the commands 'set auto-load scripts-directory' and\n\
1677 'show auto-load scripts-directory' to access the current full list setting."),
1679 set_cmd_completer (cmd
, filename_completer
);
1681 add_setshow_boolean_cmd ("auto-load", class_maintenance
,
1682 &debug_auto_load
, _("\
1683 Set auto-load verifications debugging."), _("\
1684 Show auto-load verifications debugging."), _("\
1685 When non-zero, debugging output for files of 'set auto-load ...'\n\
1687 NULL
, show_debug_auto_load
,
1688 &setdebuglist
, &showdebuglist
);