1 /* GDB routines for supporting auto-loaded scripts.
3 Copyright (C) 2012-2018 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"
35 #include "readline/tilde.h"
36 #include "completer.h"
39 #include "filestuff.h"
40 #include "extension.h"
41 #include "gdb/section-scripts.h"
43 #include "common/pathstuff.h"
45 /* The section to look in for auto-loaded scripts (in file formats that
47 Each entry in this section is a record that begins with a leading byte
48 identifying the record type.
49 At the moment we only support one record type: A leading byte of 1,
50 followed by the path of a python script to load. */
51 #define AUTO_SECTION_NAME ".debug_gdb_scripts"
53 static void maybe_print_unsupported_script_warning
54 (struct auto_load_pspace_info
*, struct objfile
*objfile
,
55 const struct extension_language_defn
*language
,
56 const char *section_name
, unsigned offset
);
58 static void maybe_print_script_not_found_warning
59 (struct auto_load_pspace_info
*, struct objfile
*objfile
,
60 const struct extension_language_defn
*language
,
61 const char *section_name
, unsigned offset
);
63 /* Value of the 'set debug auto-load' configuration variable. */
64 static int debug_auto_load
= 0;
66 /* "show" command for the debug_auto_load configuration variable. */
69 show_debug_auto_load (struct ui_file
*file
, int from_tty
,
70 struct cmd_list_element
*c
, const char *value
)
72 fprintf_filtered (file
, _("Debugging output for files "
73 "of 'set auto-load ...' is %s.\n"),
77 /* User-settable option to enable/disable auto-loading of GDB_AUTO_FILE_NAME
79 set auto-load gdb-scripts on|off
80 This is true if we should auto-load associated scripts when an objfile
81 is opened, false otherwise. */
82 static int auto_load_gdb_scripts
= 1;
84 /* "show" command for the auto_load_gdb_scripts configuration variable. */
87 show_auto_load_gdb_scripts (struct ui_file
*file
, int from_tty
,
88 struct cmd_list_element
*c
, const char *value
)
90 fprintf_filtered (file
, _("Auto-loading of canned sequences of commands "
95 /* Return non-zero if auto-loading gdb scripts is enabled. */
98 auto_load_gdb_scripts_enabled (const struct extension_language_defn
*extlang
)
100 return auto_load_gdb_scripts
;
103 /* Internal-use flag to enable/disable auto-loading.
104 This is true if we should auto-load python code when an objfile is opened,
107 Both auto_load_scripts && global_auto_load must be true to enable
110 This flag exists to facilitate deferring auto-loading during start-up
111 until after ./.gdbinit has been read; it may augment the search directories
112 used to find the scripts. */
113 int global_auto_load
= 1;
115 /* Auto-load .gdbinit file from the current directory? */
116 int auto_load_local_gdbinit
= 1;
118 /* Absolute pathname to the current directory .gdbinit, if it exists. */
119 char *auto_load_local_gdbinit_pathname
= NULL
;
121 /* Boolean value if AUTO_LOAD_LOCAL_GDBINIT_PATHNAME has been loaded. */
122 int auto_load_local_gdbinit_loaded
= 0;
124 /* "show" command for the auto_load_local_gdbinit configuration variable. */
127 show_auto_load_local_gdbinit (struct ui_file
*file
, int from_tty
,
128 struct cmd_list_element
*c
, const char *value
)
130 fprintf_filtered (file
, _("Auto-loading of .gdbinit script from current "
131 "directory is %s.\n"),
135 /* Directory list from which to load auto-loaded scripts. It is not checked
136 for absolute paths but they are strongly recommended. It is initialized by
137 _initialize_auto_load. */
138 static char *auto_load_dir
;
140 /* "set" command for the auto_load_dir configuration variable. */
143 set_auto_load_dir (const char *args
, int from_tty
, struct cmd_list_element
*c
)
145 /* Setting the variable to "" resets it to the compile time defaults. */
146 if (auto_load_dir
[0] == '\0')
148 xfree (auto_load_dir
);
149 auto_load_dir
= xstrdup (AUTO_LOAD_DIR
);
153 /* "show" command for the auto_load_dir configuration variable. */
156 show_auto_load_dir (struct ui_file
*file
, int from_tty
,
157 struct cmd_list_element
*c
, const char *value
)
159 fprintf_filtered (file
, _("List of directories from which to load "
160 "auto-loaded scripts is %s.\n"),
164 /* Directory list safe to hold auto-loaded files. It is not checked for
165 absolute paths but they are strongly recommended. It is initialized by
166 _initialize_auto_load. */
167 static char *auto_load_safe_path
;
169 /* Vector of directory elements of AUTO_LOAD_SAFE_PATH with each one normalized
170 by tilde_expand and possibly each entries has added its gdb_realpath
172 static VEC (char_ptr
) *auto_load_safe_path_vec
;
174 /* Expand $datadir and $debugdir in STRING according to the rules of
175 substitute_path_component. Return vector from dirnames_to_char_ptr_vec,
176 this vector must be freed by free_char_ptr_vec by the caller. */
178 static VEC (char_ptr
) *
179 auto_load_expand_dir_vars (const char *string
)
181 VEC (char_ptr
) *dir_vec
;
184 s
= xstrdup (string
);
185 substitute_path_component (&s
, "$datadir", gdb_datadir
);
186 substitute_path_component (&s
, "$debugdir", debug_file_directory
);
188 if (debug_auto_load
&& strcmp (s
, string
) != 0)
189 fprintf_unfiltered (gdb_stdlog
,
190 _("auto-load: Expanded $-variables to \"%s\".\n"), s
);
192 dir_vec
= dirnames_to_char_ptr_vec (s
);
198 /* Update auto_load_safe_path_vec from current AUTO_LOAD_SAFE_PATH. */
201 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 free_char_ptr_vec (auto_load_safe_path_vec
);
213 auto_load_safe_path_vec
= auto_load_expand_dir_vars (auto_load_safe_path
);
214 len
= VEC_length (char_ptr
, auto_load_safe_path_vec
);
216 /* Apply tilde_expand and gdb_realpath to each AUTO_LOAD_SAFE_PATH_VEC
218 for (ix
= 0; ix
< len
; ix
++)
220 char *dir
= VEC_index (char_ptr
, auto_load_safe_path_vec
, ix
);
221 char *expanded
= tilde_expand (dir
);
222 gdb::unique_xmalloc_ptr
<char> real_path
= gdb_realpath (expanded
);
224 /* Ensure the current entry is at least tilde_expand-ed. */
225 VEC_replace (char_ptr
, auto_load_safe_path_vec
, ix
, expanded
);
229 if (strcmp (expanded
, dir
) == 0)
230 fprintf_unfiltered (gdb_stdlog
,
231 _("auto-load: Using directory \"%s\".\n"),
234 fprintf_unfiltered (gdb_stdlog
,
235 _("auto-load: Resolved directory \"%s\" "
241 /* If gdb_realpath returns a different content, append it. */
242 if (strcmp (real_path
.get (), expanded
) != 0)
245 fprintf_unfiltered (gdb_stdlog
,
246 _("auto-load: And canonicalized as \"%s\".\n"),
249 VEC_safe_push (char_ptr
, auto_load_safe_path_vec
,
250 real_path
.release ());
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 (const char *args
,
267 int from_tty
, struct cmd_list_element
*c
)
269 /* Setting the variable to "" resets it to the compile time defaults. */
270 if (auto_load_safe_path
[0] == '\0')
272 xfree (auto_load_safe_path
);
273 auto_load_safe_path
= xstrdup (AUTO_LOAD_SAFE_PATH
);
276 auto_load_safe_path_vec_update ();
279 /* "show" command for the auto_load_safe_path configuration variable. */
282 show_auto_load_safe_path (struct ui_file
*file
, int from_tty
,
283 struct cmd_list_element
*c
, const char *value
)
287 /* Check if user has entered either "/" or for example ":".
288 But while more complicate content like ":/foo" would still also
289 permit any location do not hide those. */
291 for (cs
= value
; *cs
&& (*cs
== DIRNAME_SEPARATOR
|| IS_DIR_SEPARATOR (*cs
));
294 fprintf_filtered (file
, _("Auto-load files are safe to load from any "
297 fprintf_filtered (file
, _("List of directories from which it is safe to "
298 "auto-load files is %s.\n"),
302 /* "add-auto-load-safe-path" command for the auto_load_safe_path configuration
306 add_auto_load_safe_path (const char *args
, int from_tty
)
310 if (args
== NULL
|| *args
== 0)
312 Directory argument required.\n\
313 Use 'set auto-load safe-path /' for disabling the auto-load safe-path security.\
316 s
= xstrprintf ("%s%c%s", auto_load_safe_path
, DIRNAME_SEPARATOR
, args
);
317 xfree (auto_load_safe_path
);
318 auto_load_safe_path
= s
;
320 auto_load_safe_path_vec_update ();
323 /* "add-auto-load-scripts-directory" command for the auto_load_dir configuration
327 add_auto_load_dir (const char *args
, int from_tty
)
331 if (args
== NULL
|| *args
== 0)
332 error (_("Directory argument required."));
334 s
= xstrprintf ("%s%c%s", auto_load_dir
, DIRNAME_SEPARATOR
, args
);
335 xfree (auto_load_dir
);
339 /* Implementation for filename_is_in_pattern overwriting the caller's FILENAME
343 filename_is_in_pattern_1 (char *filename
, char *pattern
)
345 size_t pattern_len
= strlen (pattern
);
346 size_t filename_len
= strlen (filename
);
349 fprintf_unfiltered (gdb_stdlog
, _("auto-load: Matching file \"%s\" "
350 "to pattern \"%s\"\n"),
353 /* Trim trailing slashes ("/") from PATTERN. Even for "d:\" paths as
354 trailing slashes are trimmed also from FILENAME it still matches
356 while (pattern_len
&& IS_DIR_SEPARATOR (pattern
[pattern_len
- 1]))
358 pattern
[pattern_len
] = '\0';
360 /* Ensure auto_load_safe_path "/" matches any FILENAME. On MS-Windows
361 platform FILENAME even after gdb_realpath does not have to start with
362 IS_DIR_SEPARATOR character, such as the 'C:\x.exe' filename. */
363 if (pattern_len
== 0)
366 fprintf_unfiltered (gdb_stdlog
,
367 _("auto-load: Matched - empty pattern\n"));
373 /* Trim trailing slashes ("/"). PATTERN also has slashes trimmed the
374 same way so they will match. */
375 while (filename_len
&& IS_DIR_SEPARATOR (filename
[filename_len
- 1]))
377 filename
[filename_len
] = '\0';
378 if (filename_len
== 0)
381 fprintf_unfiltered (gdb_stdlog
,
382 _("auto-load: Not matched - pattern \"%s\".\n"),
387 if (gdb_filename_fnmatch (pattern
, filename
, FNM_FILE_NAME
| FNM_NOESCAPE
)
391 fprintf_unfiltered (gdb_stdlog
, _("auto-load: Matched - file "
392 "\"%s\" to pattern \"%s\".\n"),
397 /* Trim trailing FILENAME component. */
398 while (filename_len
> 0 && !IS_DIR_SEPARATOR (filename
[filename_len
- 1]))
403 /* Return 1 if FILENAME matches PATTERN or if FILENAME resides in
404 a subdirectory of a directory that matches PATTERN. Return 0 otherwise.
405 gdb_realpath normalization is never done here. */
407 static ATTRIBUTE_PURE
int
408 filename_is_in_pattern (const char *filename
, const char *pattern
)
410 char *filename_copy
, *pattern_copy
;
412 filename_copy
= (char *) alloca (strlen (filename
) + 1);
413 strcpy (filename_copy
, filename
);
414 pattern_copy
= (char *) alloca (strlen (pattern
) + 1);
415 strcpy (pattern_copy
, pattern
);
417 return filename_is_in_pattern_1 (filename_copy
, pattern_copy
);
420 /* Return 1 if FILENAME belongs to one of directory components of
421 AUTO_LOAD_SAFE_PATH_VEC. Return 0 otherwise.
422 auto_load_safe_path_vec_update is never called.
423 *FILENAME_REALP may be updated by gdb_realpath of FILENAME. */
426 filename_is_in_auto_load_safe_path_vec (const char *filename
,
427 gdb::unique_xmalloc_ptr
<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
->get (), filename
) != 0)
443 fprintf_unfiltered (gdb_stdlog
,
444 _("auto-load: Resolved "
445 "file \"%s\" as \"%s\".\n"),
446 filename
, filename_realp
->get ());
449 if (strcmp (filename_realp
->get (), filename
) != 0)
451 VEC_iterate (char_ptr
, auto_load_safe_path_vec
, ix
, pattern
); ++ix
)
452 if (filename_is_in_pattern (filename_realp
->get (), 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 gdb::unique_xmalloc_ptr
<char> filename_real
;
480 static int advice_printed
= 0;
486 va_start (debug_args
, debug_fmt
);
487 vfprintf_unfiltered (gdb_stdlog
, debug_fmt
, debug_args
);
491 if (filename_is_in_auto_load_safe_path_vec (filename
, &filename_real
))
494 auto_load_safe_path_vec_update ();
495 if (filename_is_in_auto_load_safe_path_vec (filename
, &filename_real
))
498 warning (_("File \"%s\" auto-loading has been declined by your "
499 "`auto-load safe-path' set to \"%s\"."),
500 filename_real
.get (), auto_load_safe_path
);
504 const char *homedir
= getenv ("HOME");
508 std::string homeinit
= string_printf ("%s/%s", homedir
, gdbinit
);
510 printf_filtered (_("\
511 To enable execution of this file add\n\
512 \tadd-auto-load-safe-path %s\n\
513 line to your configuration file \"%s\".\n\
514 To completely disable this security protection add\n\
515 \tset auto-load safe-path /\n\
516 line to your configuration file \"%s\".\n\
517 For more information about this security protection see the\n\
518 \"Auto-loading safe path\" section in the GDB manual. E.g., run from the shell:\n\
519 \tinfo \"(gdb)Auto-loading safe path\"\n"),
520 filename_real
.get (),
521 homeinit
.c_str (), homeinit
.c_str ());
528 /* For scripts specified in .debug_gdb_scripts, multiple objfiles may load
529 the same script. There's no point in loading the script multiple times,
530 and there can be a lot of objfiles and scripts, so we keep track of scripts
533 struct auto_load_pspace_info
535 /* For each program space we keep track of loaded scripts, both when
536 specified as file names and as scripts to be executed directly. */
537 struct htab
*loaded_script_files
;
538 struct htab
*loaded_script_texts
;
540 /* Non-zero if we've issued the warning about an auto-load script not being
541 supported. We only want to issue this warning once. */
542 int unsupported_script_warning_printed
;
544 /* Non-zero if we've issued the warning about an auto-load script not being
545 found. We only want to issue this warning once. */
546 int script_not_found_warning_printed
;
549 /* Objects of this type are stored in the loaded_script hash table. */
553 /* Name as provided by the objfile. */
556 /* Full path name or NULL if script wasn't found (or was otherwise
557 inaccessible), or NULL for loaded_script_texts. */
558 const char *full_path
;
560 /* Non-zero if this script has been loaded. */
563 const struct extension_language_defn
*language
;
566 /* Per-program-space data key. */
567 static const struct program_space_data
*auto_load_pspace_data
;
570 auto_load_pspace_data_cleanup (struct program_space
*pspace
, void *arg
)
572 struct auto_load_pspace_info
*info
= (struct auto_load_pspace_info
*) arg
;
574 if (info
->loaded_script_files
)
575 htab_delete (info
->loaded_script_files
);
576 if (info
->loaded_script_texts
)
577 htab_delete (info
->loaded_script_texts
);
581 /* Get the current autoload data. If none is found yet, add it now. This
582 function always returns a valid object. */
584 static struct auto_load_pspace_info
*
585 get_auto_load_pspace_data (struct program_space
*pspace
)
587 struct auto_load_pspace_info
*info
;
589 info
= ((struct auto_load_pspace_info
*)
590 program_space_data (pspace
, auto_load_pspace_data
));
593 info
= XCNEW (struct auto_load_pspace_info
);
594 set_program_space_data (pspace
, auto_load_pspace_data
, info
);
600 /* Hash function for the loaded script hash. */
603 hash_loaded_script_entry (const void *data
)
605 const struct loaded_script
*e
= (const struct loaded_script
*) data
;
607 return htab_hash_string (e
->name
) ^ htab_hash_pointer (e
->language
);
610 /* Equality function for the loaded script hash. */
613 eq_loaded_script_entry (const void *a
, const void *b
)
615 const struct loaded_script
*ea
= (const struct loaded_script
*) a
;
616 const struct loaded_script
*eb
= (const struct loaded_script
*) b
;
618 return strcmp (ea
->name
, eb
->name
) == 0 && ea
->language
== eb
->language
;
621 /* Initialize the table to track loaded scripts.
622 Each entry is hashed by the full path name. */
625 init_loaded_scripts_info (struct auto_load_pspace_info
*pspace_info
)
627 /* Choose 31 as the starting size of the hash table, somewhat arbitrarily.
628 Space for each entry is obtained with one malloc so we can free them
631 pspace_info
->loaded_script_files
= htab_create (31,
632 hash_loaded_script_entry
,
633 eq_loaded_script_entry
,
635 pspace_info
->loaded_script_texts
= htab_create (31,
636 hash_loaded_script_entry
,
637 eq_loaded_script_entry
,
640 pspace_info
->unsupported_script_warning_printed
= FALSE
;
641 pspace_info
->script_not_found_warning_printed
= FALSE
;
644 /* Wrapper on get_auto_load_pspace_data to also allocate the hash table
645 for loading scripts. */
647 struct auto_load_pspace_info
*
648 get_auto_load_pspace_data_for_loading (struct program_space
*pspace
)
650 struct auto_load_pspace_info
*info
;
652 info
= get_auto_load_pspace_data (pspace
);
653 if (info
->loaded_script_files
== NULL
)
654 init_loaded_scripts_info (info
);
659 /* Add script file NAME in LANGUAGE to hash table of PSPACE_INFO.
660 LOADED 1 if the script has been (is going to) be loaded, 0 otherwise
661 (such as if it has not been found).
662 FULL_PATH is NULL if the script wasn't found.
663 The result is true if the script was already in the hash table. */
666 maybe_add_script_file (struct auto_load_pspace_info
*pspace_info
, int loaded
,
667 const char *name
, const char *full_path
,
668 const struct extension_language_defn
*language
)
670 struct htab
*htab
= pspace_info
->loaded_script_files
;
671 struct loaded_script
**slot
, entry
;
675 entry
.language
= language
;
676 slot
= (struct loaded_script
**) htab_find_slot (htab
, &entry
, INSERT
);
677 in_hash_table
= *slot
!= NULL
;
679 /* If this script is not in the hash table, add it. */
685 /* Allocate all space in one chunk so it's easier to free. */
686 *slot
= ((struct loaded_script
*)
687 xmalloc (sizeof (**slot
)
689 + (full_path
!= NULL
? (strlen (full_path
) + 1) : 0)));
690 p
= ((char*) *slot
) + sizeof (**slot
);
693 if (full_path
!= NULL
)
696 strcpy (p
, full_path
);
697 (*slot
)->full_path
= p
;
700 (*slot
)->full_path
= NULL
;
701 (*slot
)->loaded
= loaded
;
702 (*slot
)->language
= language
;
705 return in_hash_table
;
708 /* Add script contents NAME in LANGUAGE to hash table of PSPACE_INFO.
709 LOADED 1 if the script has been (is going to) be loaded, 0 otherwise
710 (such as if it has not been found).
711 The result is true if the script was already in the hash table. */
714 maybe_add_script_text (struct auto_load_pspace_info
*pspace_info
,
715 int loaded
, const char *name
,
716 const struct extension_language_defn
*language
)
718 struct htab
*htab
= pspace_info
->loaded_script_texts
;
719 struct loaded_script
**slot
, entry
;
723 entry
.language
= language
;
724 slot
= (struct loaded_script
**) htab_find_slot (htab
, &entry
, INSERT
);
725 in_hash_table
= *slot
!= NULL
;
727 /* If this script is not in the hash table, add it. */
733 /* Allocate all space in one chunk so it's easier to free. */
734 *slot
= ((struct loaded_script
*)
735 xmalloc (sizeof (**slot
) + strlen (name
) + 1));
736 p
= ((char*) *slot
) + sizeof (**slot
);
739 (*slot
)->full_path
= NULL
;
740 (*slot
)->loaded
= loaded
;
741 (*slot
)->language
= language
;
744 return in_hash_table
;
747 /* Clear the table of loaded section scripts. */
750 clear_section_scripts (void)
752 struct program_space
*pspace
= current_program_space
;
753 struct auto_load_pspace_info
*info
;
755 info
= ((struct auto_load_pspace_info
*)
756 program_space_data (pspace
, auto_load_pspace_data
));
757 if (info
!= NULL
&& info
->loaded_script_files
!= NULL
)
759 htab_delete (info
->loaded_script_files
);
760 htab_delete (info
->loaded_script_texts
);
761 info
->loaded_script_files
= NULL
;
762 info
->loaded_script_texts
= NULL
;
763 info
->unsupported_script_warning_printed
= FALSE
;
764 info
->script_not_found_warning_printed
= FALSE
;
768 /* Look for the auto-load script in LANGUAGE associated with OBJFILE where
769 OBJFILE's gdb_realpath is REALNAME and load it. Return 1 if we found any
770 matching script, return 0 otherwise. */
773 auto_load_objfile_script_1 (struct objfile
*objfile
, const char *realname
,
774 const struct extension_language_defn
*language
)
776 char *filename
, *debugfile
;
778 struct cleanup
*cleanups
;
779 const char *suffix
= ext_lang_auto_load_suffix (language
);
781 len
= strlen (realname
);
782 filename
= (char *) xmalloc (len
+ strlen (suffix
) + 1);
783 memcpy (filename
, realname
, len
);
784 strcpy (filename
+ len
, suffix
);
786 cleanups
= make_cleanup (xfree
, filename
);
788 gdb_file_up input
= gdb_fopen_cloexec (filename
, "r");
789 debugfile
= filename
;
791 fprintf_unfiltered (gdb_stdlog
, _("auto-load: Attempted file \"%s\" %s.\n"),
792 debugfile
, input
? _("exists") : _("does not exist"));
800 /* Also try the same file in a subdirectory of gdb's data
803 vec
= auto_load_expand_dir_vars (auto_load_dir
);
804 make_cleanup_free_char_ptr_vec (vec
);
807 fprintf_unfiltered (gdb_stdlog
, _("auto-load: Searching 'set auto-load "
808 "scripts-directory' path \"%s\".\n"),
811 for (ix
= 0; VEC_iterate (char_ptr
, vec
, ix
, dir
); ++ix
)
813 debugfile
= (char *) xmalloc (strlen (dir
) + strlen (filename
) + 1);
814 strcpy (debugfile
, dir
);
816 /* FILENAME is absolute, so we don't need a "/" here. */
817 strcat (debugfile
, filename
);
819 make_cleanup (xfree
, debugfile
);
820 input
= gdb_fopen_cloexec (debugfile
, "r");
822 fprintf_unfiltered (gdb_stdlog
, _("auto-load: Attempted file "
825 input
? _("exists") : _("does not exist"));
834 struct auto_load_pspace_info
*pspace_info
;
837 = file_is_auto_load_safe (debugfile
,
838 _("auto-load: Loading %s script \"%s\""
839 " by extension for objfile \"%s\".\n"),
840 ext_lang_name (language
),
841 debugfile
, objfile_name (objfile
));
843 /* Add this script to the hash table too so
844 "info auto-load ${lang}-scripts" can print it. */
846 = get_auto_load_pspace_data_for_loading (current_program_space
);
847 maybe_add_script_file (pspace_info
, is_safe
, debugfile
, debugfile
,
850 /* To preserve existing behaviour we don't check for whether the
851 script was already in the table, and always load it.
852 It's highly unlikely that we'd ever load it twice,
853 and these scripts are required to be idempotent under multiple
857 objfile_script_sourcer_func
*sourcer
858 = ext_lang_objfile_script_sourcer (language
);
860 /* We shouldn't get here if support for the language isn't
861 compiled in. And the extension language is required to implement
863 gdb_assert (sourcer
!= NULL
);
864 sourcer (language
, objfile
, input
.get (), debugfile
);
872 do_cleanups (cleanups
);
876 /* Look for the auto-load script in LANGUAGE associated with OBJFILE and load
880 auto_load_objfile_script (struct objfile
*objfile
,
881 const struct extension_language_defn
*language
)
883 gdb::unique_xmalloc_ptr
<char> realname
884 = gdb_realpath (objfile_name (objfile
));
886 if (!auto_load_objfile_script_1 (objfile
, realname
.get (), language
))
888 /* For Windows/DOS .exe executables, strip the .exe suffix, so that
889 FOO-gdb.gdb could be used for FOO.exe, and try again. */
891 size_t len
= strlen (realname
.get ());
892 const size_t lexe
= sizeof (".exe") - 1;
894 if (len
> lexe
&& strcasecmp (realname
.get () + len
- lexe
, ".exe") == 0)
897 realname
.get ()[len
] = '\0';
899 fprintf_unfiltered (gdb_stdlog
, _("auto-load: Stripped .exe suffix, "
900 "retrying with \"%s\".\n"),
902 auto_load_objfile_script_1 (objfile
, realname
.get (), language
);
907 /* Subroutine of source_section_scripts to simplify it.
908 Load FILE as a script in extension language LANGUAGE.
909 The script is from section SECTION_NAME in OBJFILE at offset OFFSET. */
912 source_script_file (struct auto_load_pspace_info
*pspace_info
,
913 struct objfile
*objfile
,
914 const struct extension_language_defn
*language
,
915 const char *section_name
, unsigned int offset
,
919 objfile_script_sourcer_func
*sourcer
;
921 /* Skip this script if support is not compiled in. */
922 sourcer
= ext_lang_objfile_script_sourcer (language
);
925 /* We don't throw an error, the program is still debuggable. */
926 maybe_print_unsupported_script_warning (pspace_info
, objfile
, language
,
927 section_name
, offset
);
928 /* We *could* still try to open it, but there's no point. */
929 maybe_add_script_file (pspace_info
, 0, file
, NULL
, language
);
933 /* Skip this script if auto-loading it has been disabled. */
934 if (!ext_lang_auto_load_enabled (language
))
936 /* No message is printed, just skip it. */
940 gdb::optional
<open_script
> opened
= find_and_open_script (file
,
945 if (!file_is_auto_load_safe (opened
->full_path
.get (),
946 _("auto-load: Loading %s script "
947 "\"%s\" from section \"%s\" of "
948 "objfile \"%s\".\n"),
949 ext_lang_name (language
),
950 opened
->full_path
.get (),
951 section_name
, objfile_name (objfile
)))
956 /* If one script isn't found it's not uncommon for more to not be
957 found either. We don't want to print a message for each script,
958 too much noise. Instead, we print the warning once and tell the
959 user how to find the list of scripts that weren't loaded.
960 We don't throw an error, the program is still debuggable.
962 IWBN if complaints.c were more general-purpose. */
964 maybe_print_script_not_found_warning (pspace_info
, objfile
, language
,
965 section_name
, offset
);
968 in_hash_table
= maybe_add_script_file (pspace_info
, bool (opened
), file
,
970 ? opened
->full_path
.get ()
974 /* If this file is not currently loaded, load it. */
975 if (opened
&& !in_hash_table
)
976 sourcer (language
, objfile
, opened
->stream
.get (),
977 opened
->full_path
.get ());
980 /* Subroutine of source_section_scripts to simplify it.
981 Execute SCRIPT as a script in extension language LANG.
982 The script is from section SECTION_NAME in OBJFILE at offset OFFSET. */
985 execute_script_contents (struct auto_load_pspace_info
*pspace_info
,
986 struct objfile
*objfile
,
987 const struct extension_language_defn
*language
,
988 const char *section_name
, unsigned int offset
,
991 objfile_script_executor_func
*executor
;
992 const char *newline
, *script_text
;
994 int is_safe
, in_hash_table
;
996 /* The first line of the script is the name of the script.
997 It must not contain any kind of space character. */
999 newline
= strchr (script
, '\n');
1000 std::string name_holder
;
1001 if (newline
!= NULL
)
1003 const char *buf
, *p
;
1005 /* Put the name in a buffer and validate it. */
1006 name_holder
= std::string (script
, newline
- script
);
1007 buf
= name_holder
.c_str ();
1008 for (p
= buf
; *p
!= '\0'; ++p
)
1013 /* We don't allow nameless scripts, they're not helpful to the user. */
1014 if (p
!= buf
&& *p
== '\0')
1019 /* We don't throw an error, the program is still debuggable. */
1021 Missing/bad script name in entry at offset %u in section %s\n\
1023 offset
, section_name
, objfile_name (objfile
));
1026 script_text
= newline
+ 1;
1028 /* Skip this script if support is not compiled in. */
1029 executor
= ext_lang_objfile_script_executor (language
);
1030 if (executor
== NULL
)
1032 /* We don't throw an error, the program is still debuggable. */
1033 maybe_print_unsupported_script_warning (pspace_info
, objfile
, language
,
1034 section_name
, offset
);
1035 maybe_add_script_text (pspace_info
, 0, name
, language
);
1039 /* Skip this script if auto-loading it has been disabled. */
1040 if (!ext_lang_auto_load_enabled (language
))
1042 /* No message is printed, just skip it. */
1046 is_safe
= file_is_auto_load_safe (objfile_name (objfile
),
1047 _("auto-load: Loading %s script "
1048 "\"%s\" from section \"%s\" of "
1049 "objfile \"%s\".\n"),
1050 ext_lang_name (language
), name
,
1051 section_name
, objfile_name (objfile
));
1053 in_hash_table
= maybe_add_script_text (pspace_info
, is_safe
, name
, language
);
1055 /* If this file is not currently loaded, load it. */
1056 if (is_safe
&& !in_hash_table
)
1057 executor (language
, objfile
, name
, script_text
);
1060 /* Load scripts specified in OBJFILE.
1061 START,END delimit a buffer containing a list of nul-terminated
1063 SECTION_NAME is used in error messages.
1065 Scripts specified as file names are found per normal "source -s" command
1066 processing. First the script is looked for in $cwd. If not found there
1067 the source search path is used.
1069 The section contains a list of path names of script files to load or
1070 actual script contents. Each entry is nul-terminated. */
1073 source_section_scripts (struct objfile
*objfile
, const char *section_name
,
1074 const char *start
, const char *end
)
1077 struct auto_load_pspace_info
*pspace_info
;
1079 pspace_info
= get_auto_load_pspace_data_for_loading (current_program_space
);
1081 for (p
= start
; p
< end
; ++p
)
1084 const struct extension_language_defn
*language
;
1085 unsigned int offset
= p
- start
;
1090 case SECTION_SCRIPT_ID_PYTHON_FILE
:
1091 case SECTION_SCRIPT_ID_PYTHON_TEXT
:
1092 language
= get_ext_lang_defn (EXT_LANG_PYTHON
);
1094 case SECTION_SCRIPT_ID_SCHEME_FILE
:
1095 case SECTION_SCRIPT_ID_SCHEME_TEXT
:
1096 language
= get_ext_lang_defn (EXT_LANG_GUILE
);
1099 warning (_("Invalid entry in %s section"), section_name
);
1100 /* We could try various heuristics to find the next valid entry,
1101 but it's safer to just punt. */
1106 while (p
< end
&& *p
!= '\0')
1110 warning (_("Non-nul-terminated entry in %s at offset %u"),
1111 section_name
, offset
);
1112 /* Don't load/execute it. */
1118 case SECTION_SCRIPT_ID_PYTHON_FILE
:
1119 case SECTION_SCRIPT_ID_SCHEME_FILE
:
1122 warning (_("Empty entry in %s at offset %u"),
1123 section_name
, offset
);
1126 source_script_file (pspace_info
, objfile
, language
,
1127 section_name
, offset
, entry
);
1129 case SECTION_SCRIPT_ID_PYTHON_TEXT
:
1130 case SECTION_SCRIPT_ID_SCHEME_TEXT
:
1131 execute_script_contents (pspace_info
, objfile
, language
,
1132 section_name
, offset
, entry
);
1138 /* Load scripts specified in section SECTION_NAME of OBJFILE. */
1141 auto_load_section_scripts (struct objfile
*objfile
, const char *section_name
)
1143 bfd
*abfd
= objfile
->obfd
;
1144 asection
*scripts_sect
;
1145 bfd_byte
*data
= NULL
;
1147 scripts_sect
= bfd_get_section_by_name (abfd
, section_name
);
1148 if (scripts_sect
== NULL
1149 || (bfd_get_section_flags (abfd
, scripts_sect
) & SEC_HAS_CONTENTS
) == 0)
1152 if (!bfd_get_full_section_contents (abfd
, scripts_sect
, &data
))
1153 warning (_("Couldn't read %s section of %s"),
1154 section_name
, bfd_get_filename (abfd
));
1157 gdb::unique_xmalloc_ptr
<bfd_byte
> data_holder (data
);
1159 char *p
= (char *) data
;
1160 source_section_scripts (objfile
, section_name
, p
,
1161 p
+ bfd_get_section_size (scripts_sect
));
1165 /* Load any auto-loaded scripts for OBJFILE. */
1168 load_auto_scripts_for_objfile (struct objfile
*objfile
)
1170 /* Return immediately if auto-loading has been globally disabled.
1171 This is to handle sequencing of operations during gdb startup.
1172 Also return immediately if OBJFILE was not created from a file
1173 on the local filesystem. */
1174 if (!global_auto_load
1175 || (objfile
->flags
& OBJF_NOT_FILENAME
) != 0
1176 || is_target_filename (objfile
->original_name
))
1179 /* Load any extension language scripts for this objfile.
1180 E.g., foo-gdb.gdb, foo-gdb.py. */
1181 auto_load_ext_lang_scripts_for_objfile (objfile
);
1183 /* Load any scripts mentioned in AUTO_SECTION_NAME (.debug_gdb_scripts). */
1184 auto_load_section_scripts (objfile
, AUTO_SECTION_NAME
);
1187 /* This is a new_objfile observer callback to auto-load scripts.
1189 Two flavors of auto-loaded scripts are supported.
1190 1) based on the path to the objfile
1191 2) from .debug_gdb_scripts section */
1194 auto_load_new_objfile (struct objfile
*objfile
)
1198 /* OBJFILE is NULL when loading a new "main" symbol-file. */
1199 clear_section_scripts ();
1203 load_auto_scripts_for_objfile (objfile
);
1206 /* Collect scripts to be printed in a vec. */
1208 struct collect_matching_scripts_data
1210 collect_matching_scripts_data (std::vector
<loaded_script
*> *scripts_p_
,
1211 const extension_language_defn
*language_
)
1212 : scripts_p (scripts_p_
), language (language_
)
1215 std::vector
<loaded_script
*> *scripts_p
;
1216 const struct extension_language_defn
*language
;
1219 /* Traversal function for htab_traverse.
1220 Collect the entry if it matches the regexp. */
1223 collect_matching_scripts (void **slot
, void *info
)
1225 struct loaded_script
*script
= (struct loaded_script
*) *slot
;
1226 struct collect_matching_scripts_data
*data
1227 = (struct collect_matching_scripts_data
*) info
;
1229 if (script
->language
== data
->language
&& re_exec (script
->name
))
1230 data
->scripts_p
->push_back (script
);
1238 print_script (struct loaded_script
*script
)
1240 struct ui_out
*uiout
= current_uiout
;
1242 ui_out_emit_tuple
tuple_emitter (uiout
, NULL
);
1244 uiout
->field_string ("loaded", script
->loaded
? "Yes" : "No");
1245 uiout
->field_string ("script", script
->name
);
1248 /* If the name isn't the full path, print it too. */
1249 if (script
->full_path
!= NULL
1250 && strcmp (script
->name
, script
->full_path
) != 0)
1252 uiout
->text ("\tfull name: ");
1253 uiout
->field_string ("full_path", script
->full_path
);
1258 /* Helper for info_auto_load_scripts to sort the scripts by name. */
1261 sort_scripts_by_name (loaded_script
*a
, loaded_script
*b
)
1263 return FILENAME_CMP (a
->name
, b
->name
) < 0;
1266 /* Special internal GDB value of auto_load_info_scripts's PATTERN identify
1267 the "info auto-load XXX" command has been executed through the general
1268 "info auto-load" invocation. Extra newline will be printed if needed. */
1269 char auto_load_info_scripts_pattern_nl
[] = "";
1271 /* Subroutine of auto_load_info_scripts to simplify it.
1275 print_scripts (const std::vector
<loaded_script
*> &scripts
)
1277 for (loaded_script
*script
: scripts
)
1278 print_script (script
);
1281 /* Implementation for "info auto-load gdb-scripts"
1282 (and "info auto-load python-scripts"). List scripts in LANGUAGE matching
1283 PATTERN. FROM_TTY is the usual GDB boolean for user interactivity. */
1286 auto_load_info_scripts (const char *pattern
, int from_tty
,
1287 const struct extension_language_defn
*language
)
1289 struct ui_out
*uiout
= current_uiout
;
1290 struct auto_load_pspace_info
*pspace_info
;
1294 pspace_info
= get_auto_load_pspace_data (current_program_space
);
1296 if (pattern
&& *pattern
)
1298 char *re_err
= re_comp (pattern
);
1301 error (_("Invalid regexp: %s"), re_err
);
1308 /* We need to know the number of rows before we build the table.
1309 Plus we want to sort the scripts by name.
1310 So first traverse the hash table collecting the matching scripts. */
1312 std::vector
<loaded_script
*> script_files
, script_texts
;
1314 if (pspace_info
!= NULL
&& pspace_info
->loaded_script_files
!= NULL
)
1316 collect_matching_scripts_data
data (&script_files
, language
);
1318 /* Pass a pointer to scripts as VEC_safe_push can realloc space. */
1319 htab_traverse_noresize (pspace_info
->loaded_script_files
,
1320 collect_matching_scripts
, &data
);
1322 std::sort (script_files
.begin (), script_files
.end (),
1323 sort_scripts_by_name
);
1326 if (pspace_info
!= NULL
&& pspace_info
->loaded_script_texts
!= NULL
)
1328 collect_matching_scripts_data
data (&script_texts
, language
);
1330 /* Pass a pointer to scripts as VEC_safe_push can realloc space. */
1331 htab_traverse_noresize (pspace_info
->loaded_script_texts
,
1332 collect_matching_scripts
, &data
);
1334 std::sort (script_texts
.begin (), script_texts
.end (),
1335 sort_scripts_by_name
);
1338 int nr_scripts
= script_files
.size () + script_texts
.size ();
1340 /* Table header shifted right by preceding "gdb-scripts: " would not match
1342 if (nr_scripts
> 0 && pattern
== auto_load_info_scripts_pattern_nl
)
1346 ui_out_emit_table
table_emitter (uiout
, 2, nr_scripts
,
1347 "AutoLoadedScriptsTable");
1349 uiout
->table_header (7, ui_left
, "loaded", "Loaded");
1350 uiout
->table_header (70, ui_left
, "script", "Script");
1351 uiout
->table_body ();
1353 print_scripts (script_files
);
1354 print_scripts (script_texts
);
1357 if (nr_scripts
== 0)
1359 if (pattern
&& *pattern
)
1360 uiout
->message ("No auto-load scripts matching %s.\n", pattern
);
1362 uiout
->message ("No auto-load scripts.\n");
1366 /* Wrapper for "info auto-load gdb-scripts". */
1369 info_auto_load_gdb_scripts (const char *pattern
, int from_tty
)
1371 auto_load_info_scripts (pattern
, from_tty
, &extension_language_gdb
);
1374 /* Implement 'info auto-load local-gdbinit'. */
1377 info_auto_load_local_gdbinit (const char *args
, int from_tty
)
1379 if (auto_load_local_gdbinit_pathname
== NULL
)
1380 printf_filtered (_("Local .gdbinit file was not found.\n"));
1381 else if (auto_load_local_gdbinit_loaded
)
1382 printf_filtered (_("Local .gdbinit file \"%s\" has been loaded.\n"),
1383 auto_load_local_gdbinit_pathname
);
1385 printf_filtered (_("Local .gdbinit file \"%s\" has not been loaded.\n"),
1386 auto_load_local_gdbinit_pathname
);
1389 /* Print an "unsupported script" warning if it has not already been printed.
1390 The script is in language LANGUAGE at offset OFFSET in section SECTION_NAME
1394 maybe_print_unsupported_script_warning
1395 (struct auto_load_pspace_info
*pspace_info
,
1396 struct objfile
*objfile
, const struct extension_language_defn
*language
,
1397 const char *section_name
, unsigned offset
)
1399 if (!pspace_info
->unsupported_script_warning_printed
)
1402 Unsupported auto-load script at offset %u in section %s\n\
1404 Use `info auto-load %s-scripts [REGEXP]' to list them."),
1405 offset
, section_name
, objfile_name (objfile
),
1406 ext_lang_name (language
));
1407 pspace_info
->unsupported_script_warning_printed
= 1;
1411 /* Return non-zero if SCRIPT_NOT_FOUND_WARNING_PRINTED of PSPACE_INFO was unset
1412 before calling this function. Always set SCRIPT_NOT_FOUND_WARNING_PRINTED
1416 maybe_print_script_not_found_warning
1417 (struct auto_load_pspace_info
*pspace_info
,
1418 struct objfile
*objfile
, const struct extension_language_defn
*language
,
1419 const char *section_name
, unsigned offset
)
1421 if (!pspace_info
->script_not_found_warning_printed
)
1424 Missing auto-load script at offset %u in section %s\n\
1426 Use `info auto-load %s-scripts [REGEXP]' to list them."),
1427 offset
, section_name
, objfile_name (objfile
),
1428 ext_lang_name (language
));
1429 pspace_info
->script_not_found_warning_printed
= 1;
1433 /* The only valid "set auto-load" argument is off|0|no|disable. */
1436 set_auto_load_cmd (const char *args
, int from_tty
)
1438 struct cmd_list_element
*list
;
1441 /* See parse_binary_operation in use by the sub-commands. */
1443 length
= args
? strlen (args
) : 0;
1445 while (length
> 0 && (args
[length
- 1] == ' ' || args
[length
- 1] == '\t'))
1448 if (length
== 0 || (strncmp (args
, "off", length
) != 0
1449 && strncmp (args
, "0", length
) != 0
1450 && strncmp (args
, "no", length
) != 0
1451 && strncmp (args
, "disable", length
) != 0))
1452 error (_("Valid is only global 'set auto-load no'; "
1453 "otherwise check the auto-load sub-commands."));
1455 for (list
= *auto_load_set_cmdlist_get (); list
!= NULL
; list
= list
->next
)
1456 if (list
->var_type
== var_boolean
)
1458 gdb_assert (list
->type
== set_cmd
);
1459 do_set_command (args
, from_tty
, list
);
1463 /* Initialize "set auto-load " commands prefix and return it. */
1465 struct cmd_list_element
**
1466 auto_load_set_cmdlist_get (void)
1468 static struct cmd_list_element
*retval
;
1471 add_prefix_cmd ("auto-load", class_maintenance
, set_auto_load_cmd
, _("\
1472 Auto-loading specific settings.\n\
1473 Configure various auto-load-specific variables such as\n\
1474 automatic loading of Python scripts."),
1475 &retval
, "set auto-load ",
1476 1/*allow-unknown*/, &setlist
);
1481 /* Command "show auto-load" displays summary of all the current
1482 "show auto-load " settings. */
1485 show_auto_load_cmd (const char *args
, int from_tty
)
1487 cmd_show_list (*auto_load_show_cmdlist_get (), from_tty
, "");
1490 /* Initialize "show auto-load " commands prefix and return it. */
1492 struct cmd_list_element
**
1493 auto_load_show_cmdlist_get (void)
1495 static struct cmd_list_element
*retval
;
1498 add_prefix_cmd ("auto-load", class_maintenance
, show_auto_load_cmd
, _("\
1499 Show auto-loading specific settings.\n\
1500 Show configuration of various auto-load-specific variables such as\n\
1501 automatic loading of Python scripts."),
1502 &retval
, "show auto-load ",
1503 0/*allow-unknown*/, &showlist
);
1508 /* Command "info auto-load" displays whether the various auto-load files have
1509 been loaded. This is reimplementation of cmd_show_list which inserts
1510 newlines at proper places. */
1513 info_auto_load_cmd (const char *args
, int from_tty
)
1515 struct cmd_list_element
*list
;
1516 struct ui_out
*uiout
= current_uiout
;
1518 ui_out_emit_tuple
tuple_emitter (uiout
, "infolist");
1520 for (list
= *auto_load_info_cmdlist_get (); list
!= NULL
; list
= list
->next
)
1522 ui_out_emit_tuple
option_emitter (uiout
, "option");
1524 gdb_assert (!list
->prefixlist
);
1525 gdb_assert (list
->type
== not_set_cmd
);
1527 uiout
->field_string ("name", list
->name
);
1529 cmd_func (list
, auto_load_info_scripts_pattern_nl
, from_tty
);
1533 /* Initialize "info auto-load " commands prefix and return it. */
1535 struct cmd_list_element
**
1536 auto_load_info_cmdlist_get (void)
1538 static struct cmd_list_element
*retval
;
1541 add_prefix_cmd ("auto-load", class_info
, info_auto_load_cmd
, _("\
1542 Print current status of auto-loaded files.\n\
1543 Print whether various files like Python scripts or .gdbinit files have been\n\
1544 found and/or loaded."),
1545 &retval
, "info auto-load ",
1546 0/*allow-unknown*/, &infolist
);
1552 _initialize_auto_load (void)
1554 struct cmd_list_element
*cmd
;
1555 char *scripts_directory_help
, *gdb_name_help
, *python_name_help
;
1556 char *guile_name_help
;
1559 auto_load_pspace_data
1560 = register_program_space_data_with_cleanup (NULL
,
1561 auto_load_pspace_data_cleanup
);
1563 observer_attach_new_objfile (auto_load_new_objfile
);
1565 add_setshow_boolean_cmd ("gdb-scripts", class_support
,
1566 &auto_load_gdb_scripts
, _("\
1567 Enable or disable auto-loading of canned sequences of commands scripts."), _("\
1568 Show whether auto-loading of canned sequences of commands scripts is enabled."),
1570 If enabled, canned sequences of commands are loaded when the debugger reads\n\
1571 an executable or shared library.\n\
1572 This options has security implications for untrusted inferiors."),
1573 NULL
, show_auto_load_gdb_scripts
,
1574 auto_load_set_cmdlist_get (),
1575 auto_load_show_cmdlist_get ());
1577 add_cmd ("gdb-scripts", class_info
, info_auto_load_gdb_scripts
,
1578 _("Print the list of automatically loaded sequences of commands.\n\
1579 Usage: info auto-load gdb-scripts [REGEXP]"),
1580 auto_load_info_cmdlist_get ());
1582 add_setshow_boolean_cmd ("local-gdbinit", class_support
,
1583 &auto_load_local_gdbinit
, _("\
1584 Enable or disable auto-loading of .gdbinit script in current directory."), _("\
1585 Show whether auto-loading .gdbinit script in current directory is enabled."),
1587 If enabled, canned sequences of commands are loaded when debugger starts\n\
1588 from .gdbinit file in current directory. Such files are deprecated,\n\
1589 use a script associated with inferior executable file instead.\n\
1590 This options has security implications for untrusted inferiors."),
1591 NULL
, show_auto_load_local_gdbinit
,
1592 auto_load_set_cmdlist_get (),
1593 auto_load_show_cmdlist_get ());
1595 add_cmd ("local-gdbinit", class_info
, info_auto_load_local_gdbinit
,
1596 _("Print whether current directory .gdbinit file has been loaded.\n\
1597 Usage: info auto-load local-gdbinit"),
1598 auto_load_info_cmdlist_get ());
1600 auto_load_dir
= xstrdup (AUTO_LOAD_DIR
);
1602 suffix
= ext_lang_auto_load_suffix (get_ext_lang_defn (EXT_LANG_GDB
));
1605 GDB scripts: OBJFILE%s\n"),
1607 python_name_help
= NULL
;
1609 suffix
= ext_lang_auto_load_suffix (get_ext_lang_defn (EXT_LANG_PYTHON
));
1612 Python scripts: OBJFILE%s\n"),
1615 guile_name_help
= NULL
;
1617 suffix
= ext_lang_auto_load_suffix (get_ext_lang_defn (EXT_LANG_GUILE
));
1620 Guile scripts: OBJFILE%s\n"),
1623 scripts_directory_help
1625 Automatically loaded scripts are located in one of the directories listed\n\
1631 This option is ignored for the kinds of scripts \
1632 having 'set auto-load ... off'.\n\
1633 Directories listed here need to be present also \
1634 in the 'set auto-load safe-path'\n\
1637 python_name_help
? python_name_help
: "",
1638 guile_name_help
? guile_name_help
: "");
1640 add_setshow_optional_filename_cmd ("scripts-directory", class_support
,
1641 &auto_load_dir
, _("\
1642 Set the list of directories from which to load auto-loaded scripts."), _("\
1643 Show the list of directories from which to load auto-loaded scripts."),
1644 scripts_directory_help
,
1645 set_auto_load_dir
, show_auto_load_dir
,
1646 auto_load_set_cmdlist_get (),
1647 auto_load_show_cmdlist_get ());
1648 xfree (scripts_directory_help
);
1649 xfree (python_name_help
);
1650 xfree (gdb_name_help
);
1651 xfree (guile_name_help
);
1653 auto_load_safe_path
= xstrdup (AUTO_LOAD_SAFE_PATH
);
1654 auto_load_safe_path_vec_update ();
1655 add_setshow_optional_filename_cmd ("safe-path", class_support
,
1656 &auto_load_safe_path
, _("\
1657 Set the list of files and directories that are safe for auto-loading."), _("\
1658 Show the list of files and directories that are safe for auto-loading."), _("\
1659 Various files loaded automatically for the 'set auto-load ...' options must\n\
1660 be located in one of the directories listed by this option. Warning will be\n\
1661 printed and file will not be used otherwise.\n\
1662 You can mix both directory and filename entries.\n\
1663 Setting this parameter to an empty list resets it to its default value.\n\
1664 Setting this parameter to '/' (without the quotes) allows any file\n\
1665 for the 'set auto-load ...' options. Each path entry can be also shell\n\
1666 wildcard pattern; '*' does not match directory separator.\n\
1667 This option is ignored for the kinds of files having 'set auto-load ... off'.\n\
1668 This options has security implications for untrusted inferiors."),
1669 set_auto_load_safe_path
,
1670 show_auto_load_safe_path
,
1671 auto_load_set_cmdlist_get (),
1672 auto_load_show_cmdlist_get ());
1673 observer_attach_gdb_datadir_changed (auto_load_gdb_datadir_changed
);
1675 cmd
= add_cmd ("add-auto-load-safe-path", class_support
,
1676 add_auto_load_safe_path
,
1677 _("Add entries to the list of directories from which it is safe "
1678 "to auto-load files.\n\
1679 See the commands 'set auto-load safe-path' and 'show auto-load safe-path' to\n\
1680 access the current full list setting."),
1682 set_cmd_completer (cmd
, filename_completer
);
1684 cmd
= add_cmd ("add-auto-load-scripts-directory", class_support
,
1686 _("Add entries to the list of directories from which to load "
1687 "auto-loaded scripts.\n\
1688 See the commands 'set auto-load scripts-directory' and\n\
1689 'show auto-load scripts-directory' to access the current full list setting."),
1691 set_cmd_completer (cmd
, filename_completer
);
1693 add_setshow_boolean_cmd ("auto-load", class_maintenance
,
1694 &debug_auto_load
, _("\
1695 Set auto-load verifications debugging."), _("\
1696 Show auto-load verifications debugging."), _("\
1697 When non-zero, debugging output for files of 'set auto-load ...'\n\
1699 NULL
, show_debug_auto_load
,
1700 &setdebuglist
, &showdebuglist
);