/* GDB routines for supporting auto-loaded scripts.
- Copyright (C) 2012-2021 Free Software Foundation, Inc.
+ Copyright (C) 2012-2022 Free Software Foundation, Inc.
This file is part of GDB.
#include <ctype.h>
#include "auto-load.h"
#include "progspace.h"
-#include "gdb_regex.h"
+#include "gdbsupport/gdb_regex.h"
#include "ui-out.h"
#include "filenames.h"
#include "command.h"
/* Directory list from which to load auto-loaded scripts. It is not checked
for absolute paths but they are strongly recommended. It is initialized by
_initialize_auto_load. */
-static char *auto_load_dir;
+static std::string auto_load_dir = AUTO_LOAD_DIR;
/* "set" command for the auto_load_dir configuration variable. */
set_auto_load_dir (const char *args, int from_tty, struct cmd_list_element *c)
{
/* Setting the variable to "" resets it to the compile time defaults. */
- if (auto_load_dir[0] == '\0')
- {
- xfree (auto_load_dir);
- auto_load_dir = xstrdup (AUTO_LOAD_DIR);
- }
+ if (auto_load_dir.empty ())
+ auto_load_dir = AUTO_LOAD_DIR;
}
/* "show" command for the auto_load_dir configuration variable. */
/* Directory list safe to hold auto-loaded files. It is not checked for
absolute paths but they are strongly recommended. It is initialized by
_initialize_auto_load. */
-static char *auto_load_safe_path;
+static std::string auto_load_safe_path = AUTO_LOAD_SAFE_PATH;
/* Vector of directory elements of AUTO_LOAD_SAFE_PATH with each one normalized
by tilde_expand and possibly each entries has added its gdb_realpath
{
char *s = xstrdup (string);
substitute_path_component (&s, "$datadir", gdb_datadir.c_str ());
- substitute_path_component (&s, "$debugdir", debug_file_directory);
+ substitute_path_component (&s, "$debugdir", debug_file_directory.c_str ());
if (debug_auto_load && strcmp (s, string) != 0)
auto_load_debug_printf ("Expanded $-variables to \"%s\".", s);
auto_load_safe_path_vec_update (void)
{
auto_load_debug_printf ("Updating directories of \"%s\".",
- auto_load_safe_path);
+ auto_load_safe_path.c_str ());
- auto_load_safe_path_vec = auto_load_expand_dir_vars (auto_load_safe_path);
+ auto_load_safe_path_vec
+ = auto_load_expand_dir_vars (auto_load_safe_path.c_str ());
size_t len = auto_load_safe_path_vec.size ();
/* Apply tilde_expand and gdb_realpath to each AUTO_LOAD_SAFE_PATH_VEC
int from_tty, struct cmd_list_element *c)
{
/* Setting the variable to "" resets it to the compile time defaults. */
- if (auto_load_safe_path[0] == '\0')
- {
- xfree (auto_load_safe_path);
- auto_load_safe_path = xstrdup (AUTO_LOAD_SAFE_PATH);
- }
+ if (auto_load_safe_path.empty ())
+ auto_load_safe_path = AUTO_LOAD_SAFE_PATH;
auto_load_safe_path_vec_update ();
}
static void
add_auto_load_safe_path (const char *args, int from_tty)
{
- char *s;
-
if (args == NULL || *args == 0)
error (_("\
Directory argument required.\n\
Use 'set auto-load safe-path /' for disabling the auto-load safe-path security.\
"));
- s = xstrprintf ("%s%c%s", auto_load_safe_path, DIRNAME_SEPARATOR, args);
- xfree (auto_load_safe_path);
- auto_load_safe_path = s;
+ auto_load_safe_path = string_printf ("%s%c%s", auto_load_safe_path.c_str (),
+ DIRNAME_SEPARATOR, args);
auto_load_safe_path_vec_update ();
}
static void
add_auto_load_dir (const char *args, int from_tty)
{
- char *s;
-
if (args == NULL || *args == 0)
error (_("Directory argument required."));
- s = xstrprintf ("%s%c%s", auto_load_dir, DIRNAME_SEPARATOR, args);
- xfree (auto_load_dir);
- auto_load_dir = s;
+ auto_load_dir = string_printf ("%s%c%s", auto_load_dir.c_str (),
+ DIRNAME_SEPARATOR, args);
}
/* Implementation for filename_is_in_pattern overwriting the caller's FILENAME
warning (_("File \"%ps\" auto-loading has been declined by your "
"`auto-load safe-path' set to \"%s\"."),
styled_string (file_name_style.style (), filename_real.get ()),
- auto_load_safe_path);
+ auto_load_safe_path.c_str ());
if (!advice_printed)
{
directory. */
std::vector<gdb::unique_xmalloc_ptr<char>> vec
- = auto_load_expand_dir_vars (auto_load_dir);
+ = auto_load_expand_dir_vars (auto_load_dir.c_str ());
auto_load_debug_printf
("Searching 'set auto-load scripts-directory' path \"%s\".",
- auto_load_dir);
+ auto_load_dir.c_str ());
/* Convert Windows file name from c:/dir/file to /c/dir/file. */
if (HAS_DRIVE_SPEC (debugfile))
"otherwise check the auto-load sub-commands."));
for (list = *auto_load_set_cmdlist_get (); list != NULL; list = list->next)
- if (list->var_type == var_boolean)
+ if (list->var->type () == var_boolean)
{
gdb_assert (list->type == set_cmd);
do_set_command (args, from_tty, list);
{
ui_out_emit_tuple option_emitter (uiout, "option");
- gdb_assert (!list->prefixlist);
+ gdb_assert (!list->is_prefix ());
gdb_assert (list->type == not_set_cmd);
uiout->field_string ("name", list->name);
_initialize_auto_load ()
{
struct cmd_list_element *cmd;
- char *scripts_directory_help, *gdb_name_help, *python_name_help;
- char *guile_name_help;
+ gdb::unique_xmalloc_ptr<char> scripts_directory_help, gdb_name_help,
+ python_name_help, guile_name_help;
const char *suffix;
gdb::observers::new_objfile.attach (auto_load_new_objfile,
Usage: info auto-load local-gdbinit"),
auto_load_info_cmdlist_get ());
- auto_load_dir = xstrdup (AUTO_LOAD_DIR);
-
suffix = ext_lang_auto_load_suffix (get_ext_lang_defn (EXT_LANG_GDB));
gdb_name_help
= xstrprintf (_("\
Directories listed here need to be present also \
in the 'set auto-load safe-path'\n\
option."),
- gdb_name_help,
- python_name_help ? python_name_help : "",
- guile_name_help ? guile_name_help : "");
+ gdb_name_help.get (),
+ python_name_help.get () ? python_name_help.get () : "",
+ guile_name_help.get () ? guile_name_help.get () : "");
add_setshow_optional_filename_cmd ("scripts-directory", class_support,
&auto_load_dir, _("\
Set the list of directories from which to load auto-loaded scripts."), _("\
Show the list of directories from which to load auto-loaded scripts."),
- scripts_directory_help,
+ scripts_directory_help.get (),
set_auto_load_dir, show_auto_load_dir,
auto_load_set_cmdlist_get (),
auto_load_show_cmdlist_get ());
- xfree (scripts_directory_help);
- xfree (python_name_help);
- xfree (gdb_name_help);
- xfree (guile_name_help);
-
- auto_load_safe_path = xstrdup (AUTO_LOAD_SAFE_PATH);
auto_load_safe_path_vec_update ();
add_setshow_optional_filename_cmd ("safe-path", class_support,
&auto_load_safe_path, _("\