/* GDB routines for supporting auto-loaded scripts.
- Copyright (C) 2012-2020 Free Software Foundation, Inc.
+ Copyright (C) 2012-2021 Free Software Foundation, Inc.
This file is part of GDB.
value);
}
-/* Return non-zero if auto-loading gdb scripts is enabled. */
+/* See auto-load.h. */
-int
+bool
auto_load_gdb_scripts_enabled (const struct extension_language_defn *extlang)
{
return auto_load_gdb_scripts;
for (;;)
{
/* Trim trailing slashes ("/"). PATTERN also has slashes trimmed the
- same way so they will match. */
+ same way so they will match. */
while (filename_len && IS_DIR_SEPARATOR (filename[filename_len - 1]))
filename_len--;
filename[filename_len] = '\0';
return 0;
}
-/* Return 1 if FILENAME is located in one of the directories of
- AUTO_LOAD_SAFE_PATH. Otherwise call warning and return 0. FILENAME does
- not have to be an absolute path.
+/* See auto-load.h. */
- Existence of FILENAME is not checked. Function will still give a warning
- even if the caller would quietly skip non-existing file in unsafe
- directory. */
-
-int
+bool
file_is_auto_load_safe (const char *filename, const char *debug_fmt, ...)
{
gdb::unique_xmalloc_ptr<char> filename_real;
- static int advice_printed = 0;
+ static bool advice_printed = false;
if (debug_auto_load)
{
}
if (filename_is_in_auto_load_safe_path_vec (filename, &filename_real))
- return 1;
+ return true;
auto_load_safe_path_vec_update ();
if (filename_is_in_auto_load_safe_path_vec (filename, &filename_real))
- return 1;
+ return true;
warning (_("File \"%ps\" auto-loading has been declined by your "
"`auto-load safe-path' set to \"%s\"."),
if (!advice_printed)
{
- const char *homedir = getenv ("HOME");
-
- if (homedir == NULL)
- homedir = "$HOME";
- std::string homeinit = string_printf ("%s/%s", homedir, GDBINIT);
+ /* Find the existing home directory config file. */
+ struct stat buf;
+ std::string home_config = find_gdb_home_config_file (GDBINIT, &buf);
+ if (home_config.empty ())
+ {
+ /* The user doesn't have an existing home directory config file,
+ so we should suggest a suitable path for them to use. */
+ std::string config_dir_file
+ = get_standard_config_filename (GDBINIT);
+ if (!config_dir_file.empty ())
+ home_config = config_dir_file;
+ else
+ {
+ const char *homedir = getenv ("HOME");
+ if (homedir == nullptr)
+ homedir = "$HOME";
+ home_config = (std::string (homedir) + SLASH_STRING
+ + std::string (GDBINIT));
+ }
+ }
printf_filtered (_("\
To enable execution of this file add\n\
\"Auto-loading safe path\" section in the GDB manual. E.g., run from the shell:\n\
\tinfo \"(gdb)Auto-loading safe path\"\n"),
filename_real.get (),
- homeinit.c_str (), homeinit.c_str ());
- advice_printed = 1;
+ home_config.c_str (), home_config.c_str ());
+ advice_printed = true;
}
- return 0;
+ return false;
}
/* For scripts specified in .debug_gdb_scripts, multiple objfiles may load
/* Convert Windows file name from c:/dir/file to /c/dir/file. */
if (HAS_DRIVE_SPEC (debugfile))
- {
- debugfile_holder = STRIP_DRIVE_SPEC (debugfile);
- filename = std::string("\\") + debugfile[0] + debugfile_holder;
- }
+ filename = (std::string("\\") + debugfile[0]
+ + STRIP_DRIVE_SPEC (debugfile));
for (const gdb::unique_xmalloc_ptr<char> &dir : vec)
{