1 /* GDB routines for supporting auto-loaded scripts.
3 Copyright (C) 2012-2022 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 "gdbsupport/gdb_regex.h"
26 #include "filenames.h"
28 #include "observable.h"
30 #include "cli/cli-script.h"
32 #include "cli/cli-cmds.h"
33 #include "cli/cli-decode.h"
34 #include "cli/cli-setshow.h"
35 #include "readline/tilde.h"
36 #include "completer.h"
39 #include "gdbsupport/filestuff.h"
40 #include "extension.h"
41 #include "gdb/section-scripts.h"
43 #include "gdbsupport/pathstuff.h"
44 #include "cli/cli-style.h"
46 /* The section to look in for auto-loaded scripts (in file formats that
48 Each entry in this section is a record that begins with a leading byte
49 identifying the record type.
50 At the moment we only support one record type: A leading byte of 1,
51 followed by the path of a python script to load. */
52 #define AUTO_SECTION_NAME ".debug_gdb_scripts"
54 /* The section to look in for the name of a separate debug file. */
55 #define DEBUGLINK_SECTION_NAME ".gnu_debuglink"
57 static void maybe_print_unsupported_script_warning
58 (struct auto_load_pspace_info
*, struct objfile
*objfile
,
59 const struct extension_language_defn
*language
,
60 const char *section_name
, unsigned offset
);
62 static void maybe_print_script_not_found_warning
63 (struct auto_load_pspace_info
*, struct objfile
*objfile
,
64 const struct extension_language_defn
*language
,
65 const char *section_name
, unsigned offset
);
67 /* See auto-load.h. */
69 bool debug_auto_load
= false;
71 /* "show" command for the debug_auto_load configuration variable. */
74 show_debug_auto_load (struct ui_file
*file
, int from_tty
,
75 struct cmd_list_element
*c
, const char *value
)
77 gdb_printf (file
, _("Debugging output for files "
78 "of 'set auto-load ...' is %s.\n"),
82 /* User-settable option to enable/disable auto-loading of GDB_AUTO_FILE_NAME
84 set auto-load gdb-scripts on|off
85 This is true if we should auto-load associated scripts when an objfile
86 is opened, false otherwise. */
87 static bool auto_load_gdb_scripts
= true;
89 /* "show" command for the auto_load_gdb_scripts configuration variable. */
92 show_auto_load_gdb_scripts (struct ui_file
*file
, int from_tty
,
93 struct cmd_list_element
*c
, const char *value
)
95 gdb_printf (file
, _("Auto-loading of canned sequences of commands "
100 /* See auto-load.h. */
103 auto_load_gdb_scripts_enabled (const struct extension_language_defn
*extlang
)
105 return auto_load_gdb_scripts
;
108 /* Internal-use flag to enable/disable auto-loading.
109 This is true if we should auto-load python code when an objfile is opened,
112 Both auto_load_scripts && global_auto_load must be true to enable
115 This flag exists to facilitate deferring auto-loading during start-up
116 until after ./.gdbinit has been read; it may augment the search directories
117 used to find the scripts. */
118 bool global_auto_load
= true;
120 /* Auto-load .gdbinit file from the current directory? */
121 bool auto_load_local_gdbinit
= true;
123 /* Absolute pathname to the current directory .gdbinit, if it exists. */
124 char *auto_load_local_gdbinit_pathname
= NULL
;
126 /* if AUTO_LOAD_LOCAL_GDBINIT_PATHNAME has been loaded. */
127 bool auto_load_local_gdbinit_loaded
= false;
129 /* "show" command for the auto_load_local_gdbinit configuration variable. */
132 show_auto_load_local_gdbinit (struct ui_file
*file
, int from_tty
,
133 struct cmd_list_element
*c
, const char *value
)
135 gdb_printf (file
, _("Auto-loading of .gdbinit script from current "
136 "directory is %s.\n"),
140 /* Directory list from which to load auto-loaded scripts. It is not checked
141 for absolute paths but they are strongly recommended. It is initialized by
142 _initialize_auto_load. */
143 static std::string auto_load_dir
= AUTO_LOAD_DIR
;
145 /* "set" command for the auto_load_dir configuration variable. */
148 set_auto_load_dir (const char *args
, int from_tty
, struct cmd_list_element
*c
)
150 /* Setting the variable to "" resets it to the compile time defaults. */
151 if (auto_load_dir
.empty ())
152 auto_load_dir
= AUTO_LOAD_DIR
;
155 /* "show" command for the auto_load_dir configuration variable. */
158 show_auto_load_dir (struct ui_file
*file
, int from_tty
,
159 struct cmd_list_element
*c
, const char *value
)
161 gdb_printf (file
, _("List of directories from which to load "
162 "auto-loaded scripts is %s.\n"),
166 /* Directory list safe to hold auto-loaded files. It is not checked for
167 absolute paths but they are strongly recommended. It is initialized by
168 _initialize_auto_load. */
169 static std::string auto_load_safe_path
= AUTO_LOAD_SAFE_PATH
;
171 /* Vector of directory elements of AUTO_LOAD_SAFE_PATH with each one normalized
172 by tilde_expand and possibly each entries has added its gdb_realpath
174 static std::vector
<gdb::unique_xmalloc_ptr
<char>> auto_load_safe_path_vec
;
176 /* Expand $datadir and $debugdir in STRING according to the rules of
177 substitute_path_component. */
179 static std::vector
<gdb::unique_xmalloc_ptr
<char>>
180 auto_load_expand_dir_vars (const char *string
)
182 char *s
= xstrdup (string
);
183 substitute_path_component (&s
, "$datadir", gdb_datadir
.c_str ());
184 substitute_path_component (&s
, "$debugdir", debug_file_directory
.c_str ());
186 if (debug_auto_load
&& strcmp (s
, string
) != 0)
187 auto_load_debug_printf ("Expanded $-variables to \"%s\".", s
);
189 std::vector
<gdb::unique_xmalloc_ptr
<char>> dir_vec
190 = dirnames_to_char_ptr_vec (s
);
196 /* Update auto_load_safe_path_vec from current AUTO_LOAD_SAFE_PATH. */
199 auto_load_safe_path_vec_update (void)
201 auto_load_debug_printf ("Updating directories of \"%s\".",
202 auto_load_safe_path
.c_str ());
204 auto_load_safe_path_vec
205 = auto_load_expand_dir_vars (auto_load_safe_path
.c_str ());
206 size_t len
= auto_load_safe_path_vec
.size ();
208 /* Apply tilde_expand and gdb_realpath to each AUTO_LOAD_SAFE_PATH_VEC
210 for (size_t i
= 0; i
< len
; i
++)
212 gdb::unique_xmalloc_ptr
<char> &in_vec
= auto_load_safe_path_vec
[i
];
213 gdb::unique_xmalloc_ptr
<char> expanded (tilde_expand (in_vec
.get ()));
214 gdb::unique_xmalloc_ptr
<char> real_path
= gdb_realpath (expanded
.get ());
216 /* Ensure the current entry is at least tilde_expand-ed. ORIGINAL makes
217 sure we free the original string. */
218 gdb::unique_xmalloc_ptr
<char> original
= std::move (in_vec
);
219 in_vec
= std::move (expanded
);
223 if (strcmp (in_vec
.get (), original
.get ()) == 0)
224 auto_load_debug_printf ("Using directory \"%s\".",
227 auto_load_debug_printf ("Resolved directory \"%s\" as \"%s\".",
228 original
.get (), in_vec
.get ());
231 /* If gdb_realpath returns a different content, append it. */
232 if (strcmp (real_path
.get (), in_vec
.get ()) != 0)
234 auto_load_debug_printf ("And canonicalized as \"%s\".",
237 auto_load_safe_path_vec
.push_back (std::move (real_path
));
242 /* Variable gdb_datadir has been set. Update content depending on $datadir. */
245 auto_load_gdb_datadir_changed (void)
247 auto_load_safe_path_vec_update ();
250 /* "set" command for the auto_load_safe_path configuration variable. */
253 set_auto_load_safe_path (const char *args
,
254 int from_tty
, struct cmd_list_element
*c
)
256 /* Setting the variable to "" resets it to the compile time defaults. */
257 if (auto_load_safe_path
.empty ())
258 auto_load_safe_path
= AUTO_LOAD_SAFE_PATH
;
260 auto_load_safe_path_vec_update ();
263 /* "show" command for the auto_load_safe_path configuration variable. */
266 show_auto_load_safe_path (struct ui_file
*file
, int from_tty
,
267 struct cmd_list_element
*c
, const char *value
)
271 /* Check if user has entered either "/" or for example ":".
272 But while more complicate content like ":/foo" would still also
273 permit any location do not hide those. */
275 for (cs
= value
; *cs
&& (*cs
== DIRNAME_SEPARATOR
|| IS_DIR_SEPARATOR (*cs
));
278 gdb_printf (file
, _("Auto-load files are safe to load from any "
281 gdb_printf (file
, _("List of directories from which it is safe to "
282 "auto-load files is %s.\n"),
286 /* "add-auto-load-safe-path" command for the auto_load_safe_path configuration
290 add_auto_load_safe_path (const char *args
, int from_tty
)
292 if (args
== NULL
|| *args
== 0)
294 Directory argument required.\n\
295 Use 'set auto-load safe-path /' for disabling the auto-load safe-path security.\
298 auto_load_safe_path
= string_printf ("%s%c%s", auto_load_safe_path
.c_str (),
299 DIRNAME_SEPARATOR
, args
);
301 auto_load_safe_path_vec_update ();
304 /* "add-auto-load-scripts-directory" command for the auto_load_dir configuration
308 add_auto_load_dir (const char *args
, int from_tty
)
310 if (args
== NULL
|| *args
== 0)
311 error (_("Directory argument required."));
313 auto_load_dir
= string_printf ("%s%c%s", auto_load_dir
.c_str (),
314 DIRNAME_SEPARATOR
, args
);
317 /* Implementation for filename_is_in_pattern overwriting the caller's FILENAME
321 filename_is_in_pattern_1 (char *filename
, char *pattern
)
323 size_t pattern_len
= strlen (pattern
);
324 size_t filename_len
= strlen (filename
);
326 auto_load_debug_printf ("Matching file \"%s\" to pattern \"%s\"",
329 /* Trim trailing slashes ("/") from PATTERN. Even for "d:\" paths as
330 trailing slashes are trimmed also from FILENAME it still matches
332 while (pattern_len
&& IS_DIR_SEPARATOR (pattern
[pattern_len
- 1]))
334 pattern
[pattern_len
] = '\0';
336 /* Ensure auto_load_safe_path "/" matches any FILENAME. On MS-Windows
337 platform FILENAME even after gdb_realpath does not have to start with
338 IS_DIR_SEPARATOR character, such as the 'C:\x.exe' filename. */
339 if (pattern_len
== 0)
341 auto_load_debug_printf ("Matched - empty pattern");
347 /* Trim trailing slashes ("/"). PATTERN also has slashes trimmed the
348 same way so they will match. */
349 while (filename_len
&& IS_DIR_SEPARATOR (filename
[filename_len
- 1]))
351 filename
[filename_len
] = '\0';
352 if (filename_len
== 0)
354 auto_load_debug_printf ("Not matched - pattern \"%s\".", pattern
);
358 if (gdb_filename_fnmatch (pattern
, filename
, FNM_FILE_NAME
| FNM_NOESCAPE
)
361 auto_load_debug_printf ("Matched - file \"%s\" to pattern \"%s\".",
366 /* Trim trailing FILENAME component. */
367 while (filename_len
> 0 && !IS_DIR_SEPARATOR (filename
[filename_len
- 1]))
372 /* Return 1 if FILENAME matches PATTERN or if FILENAME resides in
373 a subdirectory of a directory that matches PATTERN. Return 0 otherwise.
374 gdb_realpath normalization is never done here. */
376 static ATTRIBUTE_PURE
int
377 filename_is_in_pattern (const char *filename
, const char *pattern
)
379 char *filename_copy
, *pattern_copy
;
381 filename_copy
= (char *) alloca (strlen (filename
) + 1);
382 strcpy (filename_copy
, filename
);
383 pattern_copy
= (char *) alloca (strlen (pattern
) + 1);
384 strcpy (pattern_copy
, pattern
);
386 return filename_is_in_pattern_1 (filename_copy
, pattern_copy
);
389 /* Return 1 if FILENAME belongs to one of directory components of
390 AUTO_LOAD_SAFE_PATH_VEC. Return 0 otherwise.
391 auto_load_safe_path_vec_update is never called.
392 *FILENAME_REALP may be updated by gdb_realpath of FILENAME. */
395 filename_is_in_auto_load_safe_path_vec (const char *filename
,
396 gdb::unique_xmalloc_ptr
<char> *filename_realp
)
398 const char *pattern
= NULL
;
400 for (const gdb::unique_xmalloc_ptr
<char> &p
: auto_load_safe_path_vec
)
401 if (*filename_realp
== NULL
&& filename_is_in_pattern (filename
, p
.get ()))
409 if (*filename_realp
== NULL
)
411 *filename_realp
= gdb_realpath (filename
);
412 if (debug_auto_load
&& strcmp (filename_realp
->get (), filename
) != 0)
413 auto_load_debug_printf ("Resolved file \"%s\" as \"%s\".",
414 filename
, filename_realp
->get ());
417 if (strcmp (filename_realp
->get (), filename
) != 0)
418 for (const gdb::unique_xmalloc_ptr
<char> &p
: auto_load_safe_path_vec
)
419 if (filename_is_in_pattern (filename_realp
->get (), p
.get ()))
428 auto_load_debug_printf ("File \"%s\" matches directory \"%s\".",
436 /* See auto-load.h. */
439 file_is_auto_load_safe (const char *filename
)
441 gdb::unique_xmalloc_ptr
<char> filename_real
;
442 static bool advice_printed
= false;
444 if (filename_is_in_auto_load_safe_path_vec (filename
, &filename_real
))
447 auto_load_safe_path_vec_update ();
448 if (filename_is_in_auto_load_safe_path_vec (filename
, &filename_real
))
451 warning (_("File \"%ps\" auto-loading has been declined by your "
452 "`auto-load safe-path' set to \"%s\"."),
453 styled_string (file_name_style
.style (), filename_real
.get ()),
454 auto_load_safe_path
.c_str ());
458 /* Find the existing home directory config file. */
460 std::string home_config
= find_gdb_home_config_file (GDBINIT
, &buf
);
461 if (home_config
.empty ())
463 /* The user doesn't have an existing home directory config file,
464 so we should suggest a suitable path for them to use. */
465 std::string config_dir_file
466 = get_standard_config_filename (GDBINIT
);
467 if (!config_dir_file
.empty ())
468 home_config
= config_dir_file
;
471 const char *homedir
= getenv ("HOME");
472 if (homedir
== nullptr)
474 home_config
= (std::string (homedir
) + SLASH_STRING
475 + std::string (GDBINIT
));
480 To enable execution of this file add\n\
481 \tadd-auto-load-safe-path %s\n\
482 line to your configuration file \"%ps\".\n\
483 To completely disable this security protection add\n\
484 \tset auto-load safe-path /\n\
485 line to your configuration file \"%ps\".\n\
486 For more information about this security protection see the\n\
487 \"Auto-loading safe path\" section in the GDB manual. E.g., run from the shell:\n\
488 \tinfo \"(gdb)Auto-loading safe path\"\n"),
489 filename_real
.get (),
490 styled_string (file_name_style
.style (),
491 home_config
.c_str ()),
492 styled_string (file_name_style
.style (),
493 home_config
.c_str ()));
494 advice_printed
= true;
500 /* For scripts specified in .debug_gdb_scripts, multiple objfiles may load
501 the same script. There's no point in loading the script multiple times,
502 and there can be a lot of objfiles and scripts, so we keep track of scripts
505 struct auto_load_pspace_info
507 /* For each program space we keep track of loaded scripts, both when
508 specified as file names and as scripts to be executed directly. */
509 htab_up loaded_script_files
;
510 htab_up loaded_script_texts
;
512 /* Non-zero if we've issued the warning about an auto-load script not being
513 supported. We only want to issue this warning once. */
514 bool unsupported_script_warning_printed
= false;
516 /* Non-zero if we've issued the warning about an auto-load script not being
517 found. We only want to issue this warning once. */
518 bool script_not_found_warning_printed
= false;
521 /* Objects of this type are stored in the loaded_script hash table. */
525 /* Name as provided by the objfile. */
528 /* Full path name or NULL if script wasn't found (or was otherwise
529 inaccessible), or NULL for loaded_script_texts. */
530 const char *full_path
;
532 /* True if this script has been loaded. */
535 const struct extension_language_defn
*language
;
538 /* Per-program-space data key. */
539 static const struct program_space_key
<struct auto_load_pspace_info
>
540 auto_load_pspace_data
;
542 /* Get the current autoload data. If none is found yet, add it now. This
543 function always returns a valid object. */
545 static struct auto_load_pspace_info
*
546 get_auto_load_pspace_data (struct program_space
*pspace
)
548 struct auto_load_pspace_info
*info
;
550 info
= auto_load_pspace_data
.get (pspace
);
552 info
= auto_load_pspace_data
.emplace (pspace
);
557 /* Hash function for the loaded script hash. */
560 hash_loaded_script_entry (const void *data
)
562 const struct loaded_script
*e
= (const struct loaded_script
*) data
;
564 return htab_hash_string (e
->name
) ^ htab_hash_pointer (e
->language
);
567 /* Equality function for the loaded script hash. */
570 eq_loaded_script_entry (const void *a
, const void *b
)
572 const struct loaded_script
*ea
= (const struct loaded_script
*) a
;
573 const struct loaded_script
*eb
= (const struct loaded_script
*) b
;
575 return strcmp (ea
->name
, eb
->name
) == 0 && ea
->language
== eb
->language
;
578 /* Initialize the table to track loaded scripts.
579 Each entry is hashed by the full path name. */
582 init_loaded_scripts_info (struct auto_load_pspace_info
*pspace_info
)
584 /* Choose 31 as the starting size of the hash table, somewhat arbitrarily.
585 Space for each entry is obtained with one malloc so we can free them
588 pspace_info
->loaded_script_files
.reset
590 hash_loaded_script_entry
,
591 eq_loaded_script_entry
,
593 pspace_info
->loaded_script_texts
.reset
595 hash_loaded_script_entry
,
596 eq_loaded_script_entry
,
599 pspace_info
->unsupported_script_warning_printed
= false;
600 pspace_info
->script_not_found_warning_printed
= false;
603 /* Wrapper on get_auto_load_pspace_data to also allocate the hash table
604 for loading scripts. */
606 struct auto_load_pspace_info
*
607 get_auto_load_pspace_data_for_loading (struct program_space
*pspace
)
609 struct auto_load_pspace_info
*info
;
611 info
= get_auto_load_pspace_data (pspace
);
612 if (info
->loaded_script_files
== NULL
)
613 init_loaded_scripts_info (info
);
618 /* Add script file NAME in LANGUAGE to hash table of PSPACE_INFO.
619 LOADED is true if the script has been (is going to) be loaded, false
620 otherwise (such as if it has not been found).
621 FULL_PATH is NULL if the script wasn't found.
623 The result is true if the script was already in the hash table. */
626 maybe_add_script_file (struct auto_load_pspace_info
*pspace_info
, bool loaded
,
627 const char *name
, const char *full_path
,
628 const struct extension_language_defn
*language
)
630 struct htab
*htab
= pspace_info
->loaded_script_files
.get ();
631 struct loaded_script
**slot
, entry
;
634 entry
.language
= language
;
635 slot
= (struct loaded_script
**) htab_find_slot (htab
, &entry
, INSERT
);
636 bool in_hash_table
= *slot
!= NULL
;
638 /* If this script is not in the hash table, add it. */
644 /* Allocate all space in one chunk so it's easier to free. */
645 *slot
= ((struct loaded_script
*)
646 xmalloc (sizeof (**slot
)
648 + (full_path
!= NULL
? (strlen (full_path
) + 1) : 0)));
649 p
= ((char*) *slot
) + sizeof (**slot
);
652 if (full_path
!= NULL
)
655 strcpy (p
, full_path
);
656 (*slot
)->full_path
= p
;
659 (*slot
)->full_path
= NULL
;
660 (*slot
)->loaded
= loaded
;
661 (*slot
)->language
= language
;
664 return in_hash_table
;
667 /* Add script contents NAME in LANGUAGE to hash table of PSPACE_INFO.
668 LOADED is true if the script has been (is going to) be loaded, false
669 otherwise (such as if it has not been found).
671 The result is true if the script was already in the hash table. */
674 maybe_add_script_text (struct auto_load_pspace_info
*pspace_info
,
675 bool loaded
, const char *name
,
676 const struct extension_language_defn
*language
)
678 struct htab
*htab
= pspace_info
->loaded_script_texts
.get ();
679 struct loaded_script
**slot
, entry
;
682 entry
.language
= language
;
683 slot
= (struct loaded_script
**) htab_find_slot (htab
, &entry
, INSERT
);
684 bool in_hash_table
= *slot
!= NULL
;
686 /* If this script is not in the hash table, add it. */
692 /* Allocate all space in one chunk so it's easier to free. */
693 *slot
= ((struct loaded_script
*)
694 xmalloc (sizeof (**slot
) + strlen (name
) + 1));
695 p
= ((char*) *slot
) + sizeof (**slot
);
698 (*slot
)->full_path
= NULL
;
699 (*slot
)->loaded
= loaded
;
700 (*slot
)->language
= language
;
703 return in_hash_table
;
706 /* Clear the table of loaded section scripts. */
709 clear_section_scripts (void)
711 struct program_space
*pspace
= current_program_space
;
712 struct auto_load_pspace_info
*info
;
714 info
= auto_load_pspace_data
.get (pspace
);
715 if (info
!= NULL
&& info
->loaded_script_files
!= NULL
)
716 auto_load_pspace_data
.clear (pspace
);
719 /* Look for the auto-load script in LANGUAGE associated with OBJFILE where
720 OBJFILE's gdb_realpath is REALNAME and load it. Return 1 if we found any
721 matching script, return 0 otherwise. */
724 auto_load_objfile_script_1 (struct objfile
*objfile
, const char *realname
,
725 const struct extension_language_defn
*language
)
727 const char *debugfile
;
729 const char *suffix
= ext_lang_auto_load_suffix (language
);
731 std::string filename
= std::string (realname
) + suffix
;
733 gdb_file_up input
= gdb_fopen_cloexec (filename
.c_str (), "r");
734 debugfile
= filename
.c_str ();
736 auto_load_debug_printf ("Attempted file \"%s\" %s.",
738 input
!= nullptr ? "exists" : "does not exist");
740 std::string debugfile_holder
;
743 /* Also try the same file in a subdirectory of gdb's data
746 std::vector
<gdb::unique_xmalloc_ptr
<char>> vec
747 = auto_load_expand_dir_vars (auto_load_dir
.c_str ());
749 auto_load_debug_printf
750 ("Searching 'set auto-load scripts-directory' path \"%s\".",
751 auto_load_dir
.c_str ());
753 /* Convert Windows file name from c:/dir/file to /c/dir/file. */
754 if (HAS_DRIVE_SPEC (debugfile
))
755 filename
= (std::string("\\") + debugfile
[0]
756 + STRIP_DRIVE_SPEC (debugfile
));
758 for (const gdb::unique_xmalloc_ptr
<char> &dir
: vec
)
760 /* FILENAME is absolute, so we don't need a "/" here. */
761 debugfile_holder
= dir
.get () + filename
;
762 debugfile
= debugfile_holder
.c_str ();
764 input
= gdb_fopen_cloexec (debugfile
, "r");
766 auto_load_debug_printf ("Attempted file \"%s\" %s.",
770 : "does not exist"));
779 struct auto_load_pspace_info
*pspace_info
;
781 auto_load_debug_printf
782 ("Loading %s script \"%s\" by extension for objfile \"%s\".",
783 ext_lang_name (language
), debugfile
, objfile_name (objfile
));
785 bool is_safe
= file_is_auto_load_safe (debugfile
);
787 /* Add this script to the hash table too so
788 "info auto-load ${lang}-scripts" can print it. */
790 = get_auto_load_pspace_data_for_loading (current_program_space
);
791 maybe_add_script_file (pspace_info
, is_safe
, debugfile
, debugfile
,
794 /* To preserve existing behaviour we don't check for whether the
795 script was already in the table, and always load it.
796 It's highly unlikely that we'd ever load it twice,
797 and these scripts are required to be idempotent under multiple
801 objfile_script_sourcer_func
*sourcer
802 = ext_lang_objfile_script_sourcer (language
);
804 /* We shouldn't get here if support for the language isn't
805 compiled in. And the extension language is required to implement
807 gdb_assert (sourcer
!= NULL
);
808 sourcer (language
, objfile
, input
.get (), debugfile
);
819 /* Look for the auto-load script in LANGUAGE associated with OBJFILE and load
823 auto_load_objfile_script (struct objfile
*objfile
,
824 const struct extension_language_defn
*language
)
826 gdb::unique_xmalloc_ptr
<char> realname
827 = gdb_realpath (objfile_name (objfile
));
829 if (auto_load_objfile_script_1 (objfile
, realname
.get (), language
))
832 /* For Windows/DOS .exe executables, strip the .exe suffix, so that
833 FOO-gdb.gdb could be used for FOO.exe, and try again. */
835 size_t len
= strlen (realname
.get ());
836 const size_t lexe
= sizeof (".exe") - 1;
838 if (len
> lexe
&& strcasecmp (realname
.get () + len
- lexe
, ".exe") == 0)
841 realname
.get ()[len
] = '\0';
843 auto_load_debug_printf
844 ("Stripped .exe suffix, retrying with \"%s\".", realname
.get ());
846 auto_load_objfile_script_1 (objfile
, realname
.get (), language
);
850 /* If OBJFILE is a separate debug file and its name does not match
851 the name given in the parent's .gnu_debuglink section, try to
852 find the auto-load script using the parent's path and the
855 struct objfile
*parent
= objfile
->separate_debug_objfile_backlink
;
856 if (parent
!= nullptr)
859 gdb::unique_xmalloc_ptr
<char> debuglink
860 (bfd_get_debug_link_info (parent
->obfd
, &crc32
));
862 if (debuglink
.get () != nullptr
863 && strcmp (debuglink
.get (), lbasename (realname
.get ())) != 0)
865 /* Replace the last component of the parent's path with the
868 std::string p_realname
= gdb_realpath (objfile_name (parent
)).get ();
869 size_t last
= p_realname
.find_last_of ('/');
871 if (last
!= std::string::npos
)
873 p_realname
.replace (last
+ 1, std::string::npos
,
876 auto_load_debug_printf
877 ("Debug filename mismatch, retrying with \"%s\".",
878 p_realname
.c_str ());
880 auto_load_objfile_script_1 (objfile
,
881 p_realname
.c_str (), language
);
887 /* Subroutine of source_section_scripts to simplify it.
888 Load FILE as a script in extension language LANGUAGE.
889 The script is from section SECTION_NAME in OBJFILE at offset OFFSET. */
892 source_script_file (struct auto_load_pspace_info
*pspace_info
,
893 struct objfile
*objfile
,
894 const struct extension_language_defn
*language
,
895 const char *section_name
, unsigned int offset
,
898 objfile_script_sourcer_func
*sourcer
;
900 /* Skip this script if support is not compiled in. */
901 sourcer
= ext_lang_objfile_script_sourcer (language
);
904 /* We don't throw an error, the program is still debuggable. */
905 maybe_print_unsupported_script_warning (pspace_info
, objfile
, language
,
906 section_name
, offset
);
907 /* We *could* still try to open it, but there's no point. */
908 maybe_add_script_file (pspace_info
, 0, file
, NULL
, language
);
912 /* Skip this script if auto-loading it has been disabled. */
913 if (!ext_lang_auto_load_enabled (language
))
915 /* No message is printed, just skip it. */
919 gdb::optional
<open_script
> opened
= find_and_open_script (file
,
924 auto_load_debug_printf
925 ("Loading %s script \"%s\" from section \"%s\" of objfile \"%s\".",
926 ext_lang_name (language
), opened
->full_path
.get (),
927 section_name
, objfile_name (objfile
));
929 if (!file_is_auto_load_safe (opened
->full_path
.get ()))
934 /* If one script isn't found it's not uncommon for more to not be
935 found either. We don't want to print a message for each script,
936 too much noise. Instead, we print the warning once and tell the
937 user how to find the list of scripts that weren't loaded.
938 We don't throw an error, the program is still debuggable.
940 IWBN if complaints.c were more general-purpose. */
942 maybe_print_script_not_found_warning (pspace_info
, objfile
, language
,
943 section_name
, offset
);
947 = maybe_add_script_file (pspace_info
, bool (opened
), file
,
948 (opened
? opened
->full_path
.get (): NULL
),
951 /* If this file is not currently loaded, load it. */
952 if (opened
&& !in_hash_table
)
953 sourcer (language
, objfile
, opened
->stream
.get (),
954 opened
->full_path
.get ());
957 /* Subroutine of source_section_scripts to simplify it.
958 Execute SCRIPT as a script in extension language LANG.
959 The script is from section SECTION_NAME in OBJFILE at offset OFFSET. */
962 execute_script_contents (struct auto_load_pspace_info
*pspace_info
,
963 struct objfile
*objfile
,
964 const struct extension_language_defn
*language
,
965 const char *section_name
, unsigned int offset
,
968 objfile_script_executor_func
*executor
;
969 const char *newline
, *script_text
;
972 /* The first line of the script is the name of the script.
973 It must not contain any kind of space character. */
975 newline
= strchr (script
, '\n');
976 std::string name_holder
;
981 /* Put the name in a buffer and validate it. */
982 name_holder
= std::string (script
, newline
- script
);
983 buf
= name_holder
.c_str ();
984 for (p
= buf
; *p
!= '\0'; ++p
)
989 /* We don't allow nameless scripts, they're not helpful to the user. */
990 if (p
!= buf
&& *p
== '\0')
995 /* We don't throw an error, the program is still debuggable. */
997 Missing/bad script name in entry at offset %u in section %s\n\
999 offset
, section_name
,
1000 styled_string (file_name_style
.style (),
1001 objfile_name (objfile
)));
1004 script_text
= newline
+ 1;
1006 /* Skip this script if support is not compiled in. */
1007 executor
= ext_lang_objfile_script_executor (language
);
1008 if (executor
== NULL
)
1010 /* We don't throw an error, the program is still debuggable. */
1011 maybe_print_unsupported_script_warning (pspace_info
, objfile
, language
,
1012 section_name
, offset
);
1013 maybe_add_script_text (pspace_info
, 0, name
, language
);
1017 /* Skip this script if auto-loading it has been disabled. */
1018 if (!ext_lang_auto_load_enabled (language
))
1020 /* No message is printed, just skip it. */
1024 auto_load_debug_printf
1025 ("Loading %s script \"%s\" from section \"%s\" of objfile \"%s\".",
1026 ext_lang_name (language
), name
, section_name
, objfile_name (objfile
));
1028 bool is_safe
= file_is_auto_load_safe (objfile_name (objfile
));
1031 = maybe_add_script_text (pspace_info
, is_safe
, name
, language
);
1033 /* If this file is not currently loaded, load it. */
1034 if (is_safe
&& !in_hash_table
)
1035 executor (language
, objfile
, name
, script_text
);
1038 /* Load scripts specified in OBJFILE.
1039 START,END delimit a buffer containing a list of nul-terminated
1041 SECTION_NAME is used in error messages.
1043 Scripts specified as file names are found per normal "source -s" command
1044 processing. First the script is looked for in $cwd. If not found there
1045 the source search path is used.
1047 The section contains a list of path names of script files to load or
1048 actual script contents. Each entry is nul-terminated. */
1051 source_section_scripts (struct objfile
*objfile
, const char *section_name
,
1052 const char *start
, const char *end
)
1055 struct auto_load_pspace_info
*pspace_info
;
1057 pspace_info
= get_auto_load_pspace_data_for_loading (current_program_space
);
1059 for (p
= start
; p
< end
; ++p
)
1062 const struct extension_language_defn
*language
;
1063 unsigned int offset
= p
- start
;
1068 case SECTION_SCRIPT_ID_PYTHON_FILE
:
1069 case SECTION_SCRIPT_ID_PYTHON_TEXT
:
1070 language
= get_ext_lang_defn (EXT_LANG_PYTHON
);
1072 case SECTION_SCRIPT_ID_SCHEME_FILE
:
1073 case SECTION_SCRIPT_ID_SCHEME_TEXT
:
1074 language
= get_ext_lang_defn (EXT_LANG_GUILE
);
1077 warning (_("Invalid entry in %s section"), section_name
);
1078 /* We could try various heuristics to find the next valid entry,
1079 but it's safer to just punt. */
1084 while (p
< end
&& *p
!= '\0')
1088 warning (_("Non-nul-terminated entry in %s at offset %u"),
1089 section_name
, offset
);
1090 /* Don't load/execute it. */
1096 case SECTION_SCRIPT_ID_PYTHON_FILE
:
1097 case SECTION_SCRIPT_ID_SCHEME_FILE
:
1100 warning (_("Empty entry in %s at offset %u"),
1101 section_name
, offset
);
1104 source_script_file (pspace_info
, objfile
, language
,
1105 section_name
, offset
, entry
);
1107 case SECTION_SCRIPT_ID_PYTHON_TEXT
:
1108 case SECTION_SCRIPT_ID_SCHEME_TEXT
:
1109 execute_script_contents (pspace_info
, objfile
, language
,
1110 section_name
, offset
, entry
);
1116 /* Load scripts specified in section SECTION_NAME of OBJFILE. */
1119 auto_load_section_scripts (struct objfile
*objfile
, const char *section_name
)
1121 bfd
*abfd
= objfile
->obfd
;
1122 asection
*scripts_sect
;
1123 bfd_byte
*data
= NULL
;
1125 scripts_sect
= bfd_get_section_by_name (abfd
, section_name
);
1126 if (scripts_sect
== NULL
1127 || (bfd_section_flags (scripts_sect
) & SEC_HAS_CONTENTS
) == 0)
1130 if (!bfd_get_full_section_contents (abfd
, scripts_sect
, &data
))
1131 warning (_("Couldn't read %s section of %ps"),
1133 styled_string (file_name_style
.style (),
1134 bfd_get_filename (abfd
)));
1137 gdb::unique_xmalloc_ptr
<bfd_byte
> data_holder (data
);
1139 char *p
= (char *) data
;
1140 source_section_scripts (objfile
, section_name
, p
,
1141 p
+ bfd_section_size (scripts_sect
));
1145 /* Load any auto-loaded scripts for OBJFILE. */
1148 load_auto_scripts_for_objfile (struct objfile
*objfile
)
1150 /* Return immediately if auto-loading has been globally disabled.
1151 This is to handle sequencing of operations during gdb startup.
1152 Also return immediately if OBJFILE was not created from a file
1153 on the local filesystem. */
1154 if (!global_auto_load
1155 || (objfile
->flags
& OBJF_NOT_FILENAME
) != 0
1156 || is_target_filename (objfile
->original_name
))
1159 /* Load any extension language scripts for this objfile.
1160 E.g., foo-gdb.gdb, foo-gdb.py. */
1161 auto_load_ext_lang_scripts_for_objfile (objfile
);
1163 /* Load any scripts mentioned in AUTO_SECTION_NAME (.debug_gdb_scripts). */
1164 auto_load_section_scripts (objfile
, AUTO_SECTION_NAME
);
1167 /* This is a new_objfile observer callback to auto-load scripts.
1169 Two flavors of auto-loaded scripts are supported.
1170 1) based on the path to the objfile
1171 2) from .debug_gdb_scripts section */
1174 auto_load_new_objfile (struct objfile
*objfile
)
1178 /* OBJFILE is NULL when loading a new "main" symbol-file. */
1179 clear_section_scripts ();
1183 load_auto_scripts_for_objfile (objfile
);
1186 /* Collect scripts to be printed in a vec. */
1188 struct collect_matching_scripts_data
1190 collect_matching_scripts_data (std::vector
<loaded_script
*> *scripts_p_
,
1191 const extension_language_defn
*language_
)
1192 : scripts_p (scripts_p_
), language (language_
)
1195 std::vector
<loaded_script
*> *scripts_p
;
1196 const struct extension_language_defn
*language
;
1199 /* Traversal function for htab_traverse.
1200 Collect the entry if it matches the regexp. */
1203 collect_matching_scripts (void **slot
, void *info
)
1205 struct loaded_script
*script
= (struct loaded_script
*) *slot
;
1206 struct collect_matching_scripts_data
*data
1207 = (struct collect_matching_scripts_data
*) info
;
1209 if (script
->language
== data
->language
&& re_exec (script
->name
))
1210 data
->scripts_p
->push_back (script
);
1218 print_script (struct loaded_script
*script
)
1220 struct ui_out
*uiout
= current_uiout
;
1222 ui_out_emit_tuple
tuple_emitter (uiout
, NULL
);
1224 uiout
->field_string ("loaded", script
->loaded
? "Yes" : "No");
1225 uiout
->field_string ("script", script
->name
);
1228 /* If the name isn't the full path, print it too. */
1229 if (script
->full_path
!= NULL
1230 && strcmp (script
->name
, script
->full_path
) != 0)
1232 uiout
->text ("\tfull name: ");
1233 uiout
->field_string ("full_path", script
->full_path
);
1238 /* Helper for info_auto_load_scripts to sort the scripts by name. */
1241 sort_scripts_by_name (loaded_script
*a
, loaded_script
*b
)
1243 return FILENAME_CMP (a
->name
, b
->name
) < 0;
1246 /* Special internal GDB value of auto_load_info_scripts's PATTERN identify
1247 the "info auto-load XXX" command has been executed through the general
1248 "info auto-load" invocation. Extra newline will be printed if needed. */
1249 char auto_load_info_scripts_pattern_nl
[] = "";
1251 /* Subroutine of auto_load_info_scripts to simplify it.
1255 print_scripts (const std::vector
<loaded_script
*> &scripts
)
1257 for (loaded_script
*script
: scripts
)
1258 print_script (script
);
1261 /* Implementation for "info auto-load gdb-scripts"
1262 (and "info auto-load python-scripts"). List scripts in LANGUAGE matching
1263 PATTERN. FROM_TTY is the usual GDB boolean for user interactivity. */
1266 auto_load_info_scripts (const char *pattern
, int from_tty
,
1267 const struct extension_language_defn
*language
)
1269 struct ui_out
*uiout
= current_uiout
;
1270 struct auto_load_pspace_info
*pspace_info
;
1274 pspace_info
= get_auto_load_pspace_data (current_program_space
);
1276 if (pattern
&& *pattern
)
1278 char *re_err
= re_comp (pattern
);
1281 error (_("Invalid regexp: %s"), re_err
);
1288 /* We need to know the number of rows before we build the table.
1289 Plus we want to sort the scripts by name.
1290 So first traverse the hash table collecting the matching scripts. */
1292 std::vector
<loaded_script
*> script_files
, script_texts
;
1294 if (pspace_info
!= NULL
&& pspace_info
->loaded_script_files
!= NULL
)
1296 collect_matching_scripts_data
data (&script_files
, language
);
1298 /* Pass a pointer to scripts as VEC_safe_push can realloc space. */
1299 htab_traverse_noresize (pspace_info
->loaded_script_files
.get (),
1300 collect_matching_scripts
, &data
);
1302 std::sort (script_files
.begin (), script_files
.end (),
1303 sort_scripts_by_name
);
1306 if (pspace_info
!= NULL
&& pspace_info
->loaded_script_texts
!= NULL
)
1308 collect_matching_scripts_data
data (&script_texts
, language
);
1310 /* Pass a pointer to scripts as VEC_safe_push can realloc space. */
1311 htab_traverse_noresize (pspace_info
->loaded_script_texts
.get (),
1312 collect_matching_scripts
, &data
);
1314 std::sort (script_texts
.begin (), script_texts
.end (),
1315 sort_scripts_by_name
);
1318 int nr_scripts
= script_files
.size () + script_texts
.size ();
1320 /* Table header shifted right by preceding "gdb-scripts: " would not match
1322 if (nr_scripts
> 0 && pattern
== auto_load_info_scripts_pattern_nl
)
1326 ui_out_emit_table
table_emitter (uiout
, 2, nr_scripts
,
1327 "AutoLoadedScriptsTable");
1329 uiout
->table_header (7, ui_left
, "loaded", "Loaded");
1330 uiout
->table_header (70, ui_left
, "script", "Script");
1331 uiout
->table_body ();
1333 print_scripts (script_files
);
1334 print_scripts (script_texts
);
1337 if (nr_scripts
== 0)
1339 if (pattern
&& *pattern
)
1340 uiout
->message ("No auto-load scripts matching %s.\n", pattern
);
1342 uiout
->message ("No auto-load scripts.\n");
1346 /* Wrapper for "info auto-load gdb-scripts". */
1349 info_auto_load_gdb_scripts (const char *pattern
, int from_tty
)
1351 auto_load_info_scripts (pattern
, from_tty
, &extension_language_gdb
);
1354 /* Implement 'info auto-load local-gdbinit'. */
1357 info_auto_load_local_gdbinit (const char *args
, int from_tty
)
1359 if (auto_load_local_gdbinit_pathname
== NULL
)
1360 gdb_printf (_("Local .gdbinit file was not found.\n"));
1361 else if (auto_load_local_gdbinit_loaded
)
1362 gdb_printf (_("Local .gdbinit file \"%ps\" has been loaded.\n"),
1363 styled_string (file_name_style
.style (),
1364 auto_load_local_gdbinit_pathname
));
1366 gdb_printf (_("Local .gdbinit file \"%ps\" has not been loaded.\n"),
1367 styled_string (file_name_style
.style (),
1368 auto_load_local_gdbinit_pathname
));
1371 /* Print an "unsupported script" warning if it has not already been printed.
1372 The script is in language LANGUAGE at offset OFFSET in section SECTION_NAME
1376 maybe_print_unsupported_script_warning
1377 (struct auto_load_pspace_info
*pspace_info
,
1378 struct objfile
*objfile
, const struct extension_language_defn
*language
,
1379 const char *section_name
, unsigned offset
)
1381 if (!pspace_info
->unsupported_script_warning_printed
)
1384 Unsupported auto-load script at offset %u in section %s\n\
1386 Use `info auto-load %s-scripts [REGEXP]' to list them."),
1387 offset
, section_name
,
1388 styled_string (file_name_style
.style (),
1389 objfile_name (objfile
)),
1390 ext_lang_name (language
));
1391 pspace_info
->unsupported_script_warning_printed
= true;
1395 /* Return non-zero if SCRIPT_NOT_FOUND_WARNING_PRINTED of PSPACE_INFO was unset
1396 before calling this function. Always set SCRIPT_NOT_FOUND_WARNING_PRINTED
1400 maybe_print_script_not_found_warning
1401 (struct auto_load_pspace_info
*pspace_info
,
1402 struct objfile
*objfile
, const struct extension_language_defn
*language
,
1403 const char *section_name
, unsigned offset
)
1405 if (!pspace_info
->script_not_found_warning_printed
)
1408 Missing auto-load script at offset %u in section %s\n\
1410 Use `info auto-load %s-scripts [REGEXP]' to list them."),
1411 offset
, section_name
,
1412 styled_string (file_name_style
.style (),
1413 objfile_name (objfile
)),
1414 ext_lang_name (language
));
1415 pspace_info
->script_not_found_warning_printed
= true;
1419 /* The only valid "set auto-load" argument is off|0|no|disable. */
1422 set_auto_load_cmd (const char *args
, int from_tty
)
1424 struct cmd_list_element
*list
;
1427 /* See parse_binary_operation in use by the sub-commands. */
1429 length
= args
? strlen (args
) : 0;
1431 while (length
> 0 && (args
[length
- 1] == ' ' || args
[length
- 1] == '\t'))
1434 if (length
== 0 || (strncmp (args
, "off", length
) != 0
1435 && strncmp (args
, "0", length
) != 0
1436 && strncmp (args
, "no", length
) != 0
1437 && strncmp (args
, "disable", length
) != 0))
1438 error (_("Valid is only global 'set auto-load no'; "
1439 "otherwise check the auto-load sub-commands."));
1441 for (list
= *auto_load_set_cmdlist_get (); list
!= NULL
; list
= list
->next
)
1442 if (list
->var
->type () == var_boolean
)
1444 gdb_assert (list
->type
== set_cmd
);
1445 do_set_command (args
, from_tty
, list
);
1449 /* Initialize "set auto-load " commands prefix and return it. */
1451 struct cmd_list_element
**
1452 auto_load_set_cmdlist_get (void)
1454 static struct cmd_list_element
*retval
;
1457 add_prefix_cmd ("auto-load", class_maintenance
, set_auto_load_cmd
, _("\
1458 Auto-loading specific settings.\n\
1459 Configure various auto-load-specific variables such as\n\
1460 automatic loading of Python scripts."),
1461 &retval
, 1/*allow-unknown*/, &setlist
);
1466 /* Initialize "show auto-load " commands prefix and return it. */
1468 struct cmd_list_element
**
1469 auto_load_show_cmdlist_get (void)
1471 static struct cmd_list_element
*retval
;
1474 add_show_prefix_cmd ("auto-load", class_maintenance
, _("\
1475 Show auto-loading specific settings.\n\
1476 Show configuration of various auto-load-specific variables such as\n\
1477 automatic loading of Python scripts."),
1478 &retval
, 0/*allow-unknown*/, &showlist
);
1483 /* Command "info auto-load" displays whether the various auto-load files have
1484 been loaded. This is reimplementation of cmd_show_list which inserts
1485 newlines at proper places. */
1488 info_auto_load_cmd (const char *args
, int from_tty
)
1490 struct cmd_list_element
*list
;
1491 struct ui_out
*uiout
= current_uiout
;
1493 ui_out_emit_tuple
tuple_emitter (uiout
, "infolist");
1495 for (list
= *auto_load_info_cmdlist_get (); list
!= NULL
; list
= list
->next
)
1497 ui_out_emit_tuple
option_emitter (uiout
, "option");
1499 gdb_assert (!list
->is_prefix ());
1500 gdb_assert (list
->type
== not_set_cmd
);
1502 uiout
->field_string ("name", list
->name
);
1504 cmd_func (list
, auto_load_info_scripts_pattern_nl
, from_tty
);
1508 /* Initialize "info auto-load " commands prefix and return it. */
1510 struct cmd_list_element
**
1511 auto_load_info_cmdlist_get (void)
1513 static struct cmd_list_element
*retval
;
1516 add_prefix_cmd ("auto-load", class_info
, info_auto_load_cmd
, _("\
1517 Print current status of auto-loaded files.\n\
1518 Print whether various files like Python scripts or .gdbinit files have been\n\
1519 found and/or loaded."),
1520 &retval
, 0/*allow-unknown*/, &infolist
);
1525 /* See auto-load.h. */
1527 gdb::observers::token auto_load_new_objfile_observer_token
;
1529 void _initialize_auto_load ();
1531 _initialize_auto_load ()
1533 struct cmd_list_element
*cmd
;
1534 gdb::unique_xmalloc_ptr
<char> scripts_directory_help
, gdb_name_help
,
1535 python_name_help
, guile_name_help
;
1538 gdb::observers::new_objfile
.attach (auto_load_new_objfile
,
1539 auto_load_new_objfile_observer_token
,
1541 add_setshow_boolean_cmd ("gdb-scripts", class_support
,
1542 &auto_load_gdb_scripts
, _("\
1543 Enable or disable auto-loading of canned sequences of commands scripts."), _("\
1544 Show whether auto-loading of canned sequences of commands scripts is enabled."),
1546 If enabled, canned sequences of commands are loaded when the debugger reads\n\
1547 an executable or shared library.\n\
1548 This option has security implications for untrusted inferiors."),
1549 NULL
, show_auto_load_gdb_scripts
,
1550 auto_load_set_cmdlist_get (),
1551 auto_load_show_cmdlist_get ());
1553 add_cmd ("gdb-scripts", class_info
, info_auto_load_gdb_scripts
,
1554 _("Print the list of automatically loaded sequences of commands.\n\
1555 Usage: info auto-load gdb-scripts [REGEXP]"),
1556 auto_load_info_cmdlist_get ());
1558 add_setshow_boolean_cmd ("local-gdbinit", class_support
,
1559 &auto_load_local_gdbinit
, _("\
1560 Enable or disable auto-loading of .gdbinit script in current directory."), _("\
1561 Show whether auto-loading .gdbinit script in current directory is enabled."),
1563 If enabled, canned sequences of commands are loaded when debugger starts\n\
1564 from .gdbinit file in current directory. Such files are deprecated,\n\
1565 use a script associated with inferior executable file instead.\n\
1566 This option has security implications for untrusted inferiors."),
1567 NULL
, show_auto_load_local_gdbinit
,
1568 auto_load_set_cmdlist_get (),
1569 auto_load_show_cmdlist_get ());
1571 add_cmd ("local-gdbinit", class_info
, info_auto_load_local_gdbinit
,
1572 _("Print whether current directory .gdbinit file has been loaded.\n\
1573 Usage: info auto-load local-gdbinit"),
1574 auto_load_info_cmdlist_get ());
1576 suffix
= ext_lang_auto_load_suffix (get_ext_lang_defn (EXT_LANG_GDB
));
1579 GDB scripts: OBJFILE%s\n"),
1581 python_name_help
= NULL
;
1583 suffix
= ext_lang_auto_load_suffix (get_ext_lang_defn (EXT_LANG_PYTHON
));
1586 Python scripts: OBJFILE%s\n"),
1589 guile_name_help
= NULL
;
1591 suffix
= ext_lang_auto_load_suffix (get_ext_lang_defn (EXT_LANG_GUILE
));
1594 Guile scripts: OBJFILE%s\n"),
1597 scripts_directory_help
1599 Automatically loaded scripts are located in one of the directories listed\n\
1605 This option is ignored for the kinds of scripts \
1606 having 'set auto-load ... off'.\n\
1607 Directories listed here need to be present also \
1608 in the 'set auto-load safe-path'\n\
1610 gdb_name_help
.get (),
1611 python_name_help
.get () ? python_name_help
.get () : "",
1612 guile_name_help
.get () ? guile_name_help
.get () : "");
1614 add_setshow_optional_filename_cmd ("scripts-directory", class_support
,
1615 &auto_load_dir
, _("\
1616 Set the list of directories from which to load auto-loaded scripts."), _("\
1617 Show the list of directories from which to load auto-loaded scripts."),
1618 scripts_directory_help
.get (),
1619 set_auto_load_dir
, show_auto_load_dir
,
1620 auto_load_set_cmdlist_get (),
1621 auto_load_show_cmdlist_get ());
1622 auto_load_safe_path_vec_update ();
1623 add_setshow_optional_filename_cmd ("safe-path", class_support
,
1624 &auto_load_safe_path
, _("\
1625 Set the list of files and directories that are safe for auto-loading."), _("\
1626 Show the list of files and directories that are safe for auto-loading."), _("\
1627 Various files loaded automatically for the 'set auto-load ...' options must\n\
1628 be located in one of the directories listed by this option. Warning will be\n\
1629 printed and file will not be used otherwise.\n\
1630 You can mix both directory and filename entries.\n\
1631 Setting this parameter to an empty list resets it to its default value.\n\
1632 Setting this parameter to '/' (without the quotes) allows any file\n\
1633 for the 'set auto-load ...' options. Each path entry can be also shell\n\
1634 wildcard pattern; '*' does not match directory separator.\n\
1635 This option is ignored for the kinds of files having 'set auto-load ... off'.\n\
1636 This option has security implications for untrusted inferiors."),
1637 set_auto_load_safe_path
,
1638 show_auto_load_safe_path
,
1639 auto_load_set_cmdlist_get (),
1640 auto_load_show_cmdlist_get ());
1641 gdb::observers::gdb_datadir_changed
.attach (auto_load_gdb_datadir_changed
,
1644 cmd
= add_cmd ("add-auto-load-safe-path", class_support
,
1645 add_auto_load_safe_path
,
1646 _("Add entries to the list of directories from which it is safe "
1647 "to auto-load files.\n\
1648 See the commands 'set auto-load safe-path' and 'show auto-load safe-path' to\n\
1649 access the current full list setting."),
1651 set_cmd_completer (cmd
, filename_completer
);
1653 cmd
= add_cmd ("add-auto-load-scripts-directory", class_support
,
1655 _("Add entries to the list of directories from which to load "
1656 "auto-loaded scripts.\n\
1657 See the commands 'set auto-load scripts-directory' and\n\
1658 'show auto-load scripts-directory' to access the current full list setting."),
1660 set_cmd_completer (cmd
, filename_completer
);
1662 add_setshow_boolean_cmd ("auto-load", class_maintenance
,
1663 &debug_auto_load
, _("\
1664 Set auto-load verifications debugging."), _("\
1665 Show auto-load verifications debugging."), _("\
1666 When non-zero, debugging output for files of 'set auto-load ...'\n\
1668 NULL
, show_debug_auto_load
,
1669 &setdebuglist
, &showdebuglist
);