26 #include "filenames.h" 35 #include "readline/tilde.h" 41 #include "gdb/section-scripts.h" 50 #define AUTO_SECTION_NAME ".debug_gdb_scripts" 55 const char *section_name,
unsigned offset);
60 const char *section_name,
unsigned offset);
72 "of 'set auto-load ...' is %s.\n"),
130 "directory is %s.\n"),
159 "auto-loaded scripts is %s.\n"),
178 auto_load_expand_dir_vars (
const char *
string)
183 s = xstrdup (
string);
189 _(
"auto-load: Expanded $-variables to \"%s\".\n"), s);
191 dir_vec = dirnames_to_char_ptr_vec (s);
207 _(
"auto-load: Updating directories of \"%s\".\n"),
217 for (ix = 0; ix < len; ix++)
220 char *expanded = tilde_expand (dir);
228 if (strcmp (expanded, dir) == 0)
230 _(
"auto-load: Using directory \"%s\".\n"),
234 _(
"auto-load: Resolved directory \"%s\" " 241 if (strcmp (real_path.get (), expanded) != 0)
245 _(
"auto-load: And canonicalized as \"%s\".\n"),
249 real_path.release ());
297 "auto-load files is %s.\n"),
309 if (args == NULL || *args == 0)
311 Directory argument required.\n\ 312 Use 'set auto-load safe-path /' for disabling the auto-load safe-path security.\ 330 if (args == NULL || *args == 0)
331 error (
_(
"Directory argument required."));
344 size_t pattern_len = strlen (pattern);
345 size_t filename_len = strlen (filename);
349 "to pattern \"%s\"\n"),
355 while (pattern_len && IS_DIR_SEPARATOR (pattern[pattern_len - 1]))
357 pattern[pattern_len] =
'\0';
362 if (pattern_len == 0)
366 _(
"auto-load: Matched - empty pattern\n"));
374 while (filename_len && IS_DIR_SEPARATOR (filename[filename_len - 1]))
376 filename[filename_len] =
'\0';
377 if (filename_len == 0)
381 _(
"auto-load: Not matched - pattern \"%s\".\n"),
391 "\"%s\" to pattern \"%s\".\n"),
397 while (filename_len > 0 && !IS_DIR_SEPARATOR (filename[filename_len - 1]))
406 static ATTRIBUTE_PURE
int 409 char *filename_copy, *pattern_copy;
411 filename_copy = (
char *) alloca (strlen (filename) + 1);
412 strcpy (filename_copy, filename);
413 pattern_copy = (
char *) alloca (strlen (pattern) + 1);
414 strcpy (pattern_copy, pattern);
438 if (*filename_realp == NULL)
443 _(
"auto-load: Resolved " 444 "file \"%s\" as \"%s\".\n"),
445 filename, filename_realp->get ());
448 if (strcmp (filename_realp->get (), filename) != 0)
459 "directory \"%s\".\n"),
479 static int advice_printed = 0;
485 va_start (debug_args, debug_fmt);
497 warning (
_(
"File \"%s\" auto-loading has been declined by your " 498 "`auto-load safe-path' set to \"%s\"."),
503 const char *homedir = getenv (
"HOME");
510 To enable execution of this file add\n\ 511 \tadd-auto-load-safe-path %s\n\ 512 line to your configuration file \"%s\".\n\ 513 To completely disable this security protection add\n\ 514 \tset auto-load safe-path /\n\ 515 line to your configuration file \"%s\".\n\ 516 For more information about this security protection see the\n\ 517 \"Auto-loading safe path\" section in the GDB manual. E.g., run from the shell:\n\ 518 \tinfo \"(gdb)Auto-loading safe path\"\n"),
519 filename_real.get (),
520 homeinit.c_str (), homeinit.c_str ());
606 return htab_hash_string (e->
name) ^ htab_hash_pointer (e->
language);
666 const char *
name,
const char *full_path,
675 slot = (
struct loaded_script **) htab_find_slot (htab, &entry, INSERT);
676 in_hash_table = *slot != NULL;
689 p = ((
char*) *slot) +
sizeof (**slot);
696 (*slot)->full_path = p;
699 (*slot)->full_path = NULL;
704 return in_hash_table;
723 slot = (
struct loaded_script **) htab_find_slot (htab, &entry, INSERT);
724 in_hash_table = *slot != NULL;
735 p = ((
char*) *slot) +
sizeof (**slot);
738 (*slot)->full_path = NULL;
743 return in_hash_table;
775 char *filename, *debugfile;
780 len = strlen (realname);
781 filename = (
char *)
xmalloc (len + strlen (suffix) + 1);
782 memcpy (filename, realname, len);
783 strcpy (filename + len, suffix);
788 debugfile = filename;
791 debugfile, input ?
_(
"exists") :
_(
"does not exist"));
807 "scripts-directory' path \"%s\".\n"),
812 debugfile = (
char *)
xmalloc (strlen (dir) + strlen (filename) + 1);
813 strcpy (debugfile, dir);
816 strcat (debugfile, filename);
824 input ?
_(
"exists") :
_(
"does not exist"));
837 _(
"auto-load: Loading %s script \"%s\"" 838 " by extension for objfile \"%s\".\n"),
890 size_t len = strlen (realname.get ());
891 const size_t lexe =
sizeof (
".exe") - 1;
893 if (len > lexe && strcasecmp (realname.get () + len - lexe,
".exe") == 0)
896 realname.get ()[len] =
'\0';
899 "retrying with \"%s\".\n"),
914 const char *section_name,
unsigned int offset,
945 _(
"auto-load: Loading %s script " 946 "\"%s\" from section \"%s\" of " 947 "objfile \"%s\".\n"),
974 if (opened && !in_hash_table)
987 const char *section_name,
unsigned int offset,
991 const char *newline, *script_text;
993 int is_safe, in_hash_table;
1001 newline = strchr (script,
'\n');
1002 if (newline != NULL)
1007 buf = xstrndup (script, newline - script);
1009 for (p = buf; *p !=
'\0'; ++p)
1015 if (p != buf && *p ==
'\0')
1022 Missing/bad script name in entry at offset %u in section %s\n\ 1028 script_text = newline + 1;
1032 if (executor == NULL)
1051 _(
"auto-load: Loading %s script " 1052 "\"%s\" from section \"%s\" of " 1053 "objfile \"%s\".\n"),
1060 if (is_safe && !in_hash_table)
1080 const char *start,
const char *end)
1087 for (p = start; p < end; ++p)
1091 unsigned int offset = p - start;
1096 case SECTION_SCRIPT_ID_PYTHON_FILE:
1097 case SECTION_SCRIPT_ID_PYTHON_TEXT:
1100 case SECTION_SCRIPT_ID_SCHEME_FILE:
1101 case SECTION_SCRIPT_ID_SCHEME_TEXT:
1105 warning (
_(
"Invalid entry in %s section"), section_name);
1112 while (p < end && *p !=
'\0')
1116 warning (
_(
"Non-nul-terminated entry in %s at offset %u"),
1124 case SECTION_SCRIPT_ID_PYTHON_FILE:
1125 case SECTION_SCRIPT_ID_SCHEME_FILE:
1128 warning (
_(
"Empty entry in %s at offset %u"),
1133 section_name,
offset, entry);
1135 case SECTION_SCRIPT_ID_PYTHON_TEXT:
1136 case SECTION_SCRIPT_ID_SCHEME_TEXT:
1138 section_name,
offset, entry);
1150 asection *scripts_sect;
1151 bfd_byte *data = NULL;
1153 scripts_sect = bfd_get_section_by_name (abfd, section_name);
1154 if (scripts_sect == NULL
1155 || (bfd_get_section_flags (abfd, scripts_sect) & SEC_HAS_CONTENTS) == 0)
1158 if (!bfd_get_full_section_contents (abfd, scripts_sect, &data))
1159 warning (
_(
"Couldn't read %s section of %s"),
1160 section_name, bfd_get_filename (abfd));
1164 char *p = (
char *) data;
1168 p + bfd_get_section_size (scripts_sect));
1260 uiout->
text (
"\tfull name: ");
1271 return FILENAME_CMP (a->
name, b->
name) < 0;
1304 if (pattern && *pattern)
1306 char *re_err =
re_comp (pattern);
1309 error (
_(
"Invalid regexp: %s"), re_err);
1320 std::vector<loaded_script *> script_files, script_texts;
1330 std::sort (script_files.begin (), script_files.end (),
1342 std::sort (script_texts.begin (), script_texts.end (),
1346 int nr_scripts = script_files.size () + script_texts.size ();
1355 "AutoLoadedScriptsTable");
1365 if (nr_scripts == 0)
1367 if (pattern && *pattern)
1368 uiout->
message (
"No auto-load scripts matching %s.\n", pattern);
1370 uiout->
message (
"No auto-load scripts.\n");
1405 const char *section_name,
unsigned offset)
1410 Unsupported auto-load script at offset %u in section %s\n\ 1412 Use `info auto-load %s-scripts [REGEXP]' to list them."),
1427 const char *section_name,
unsigned offset)
1432 Missing auto-load script at offset %u in section %s\n\ 1434 Use `info auto-load %s-scripts [REGEXP]' to list them."),
1451 length = args ? strlen (args) : 0;
1453 while (length > 0 && (args[length - 1] ==
' ' || args[length - 1] ==
'\t'))
1456 if (length == 0 || (strncmp (args,
"off", length) != 0
1457 && strncmp (args,
"0", length) != 0
1458 && strncmp (args,
"no", length) != 0
1459 && strncmp (args,
"disable", length) != 0))
1460 error (
_(
"Valid is only global 'set auto-load no'; " 1461 "otherwise check the auto-load sub-commands."));
1480 Auto-loading specific settings.\n\ 1481 Configure various auto-load-specific variables such as\n\ 1482 automatic loading of Python scripts."),
1483 &retval,
"set auto-load ",
1507 Show auto-loading specific settings.\n\ 1508 Show configuration of various auto-load-specific variables such as\n\ 1509 automatic loading of Python scripts."),
1510 &retval,
"show auto-load ",
1550 Print current status of auto-loaded files.\n\ 1551 Print whether various files like Python scripts or .gdbinit files have been\n\ 1552 found and/or loaded."),
1553 &retval,
"info auto-load ",
1563 char *scripts_directory_help, *gdb_name_help, *python_name_help;
1564 char *guile_name_help;
1568 = register_program_space_data_with_cleanup (NULL,
1575 Enable or disable auto-loading of canned sequences of commands scripts."),
_(
"\ 1576 Show whether auto-loading of canned sequences of commands scripts is enabled."),
1578 If enabled, canned sequences of commands are loaded when the debugger reads\n\ 1579 an executable or shared library.\n\ 1580 This options has security implications for untrusted inferiors."),
1586 _(
"Print the list of automatically loaded sequences of commands.\n\ 1587 Usage: info auto-load gdb-scripts [REGEXP]"),
1592 Enable or disable auto-loading of .gdbinit script in current directory."),
_(
"\ 1593 Show whether auto-loading .gdbinit script in current directory is enabled."),
1595 If enabled, canned sequences of commands are loaded when debugger starts\n\ 1596 from .gdbinit file in current directory. Such files are deprecated,\n\ 1597 use a script associated with inferior executable file instead.\n\ 1598 This options has security implications for untrusted inferiors."),
1604 _(
"Print whether current directory .gdbinit file has been loaded.\n\ 1605 Usage: info auto-load local-gdbinit"),
1613 GDB scripts: OBJFILE%s\n"),
1615 python_name_help = NULL;
1620 Python scripts: OBJFILE%s\n"),
1623 guile_name_help = NULL;
1628 Guile scripts: OBJFILE%s\n"),
1631 scripts_directory_help
1633 Automatically loaded scripts are located in one of the directories listed\n\ 1639 This option is ignored for the kinds of scripts \ 1640 having 'set auto-load ... off'.\n\ 1641 Directories listed here need to be present also \ 1642 in the 'set auto-load safe-path'\n\ 1645 python_name_help ? python_name_help :
"",
1646 guile_name_help ? guile_name_help :
"");
1650 Set the list of directories from which to load auto-loaded scripts."),
_(
"\ 1651 Show the list of directories from which to load auto-loaded scripts."),
1652 scripts_directory_help,
1656 xfree (scripts_directory_help);
1657 xfree (python_name_help);
1658 xfree (gdb_name_help);
1659 xfree (guile_name_help);
1665 Set the list of files and directories that are safe for auto-loading."),
_(
"\ 1666 Show the list of files and directories that are safe for auto-loading."),
_(
"\ 1667 Various files loaded automatically for the 'set auto-load ...' options must\n\ 1668 be located in one of the directories listed by this option. Warning will be\n\ 1669 printed and file will not be used otherwise.\n\ 1670 You can mix both directory and filename entries.\n\ 1671 Setting this parameter to an empty list resets it to its default value.\n\ 1672 Setting this parameter to '/' (without the quotes) allows any file\n\ 1673 for the 'set auto-load ...' options. Each path entry can be also shell\n\ 1674 wildcard pattern; '*' does not match directory separator.\n\ 1675 This option is ignored for the kinds of files having 'set auto-load ... off'.\n\ 1676 This options has security implications for untrusted inferiors."),
1685 _(
"Add entries to the list of directories from which it is safe " 1686 "to auto-load files.\n\ 1687 See the commands 'set auto-load safe-path' and 'show auto-load safe-path' to\n\ 1688 access the current full list setting."),
1694 _(
"Add entries to the list of directories from which to load " 1695 "auto-loaded scripts.\n\ 1696 See the commands 'set auto-load scripts-directory' and\n\ 1697 'show auto-load scripts-directory' to access the current full list setting."),
1703 Set auto-load verifications debugging."),
_(
"\ 1704 Show auto-load verifications debugging."),
_(
"\ 1705 When non-zero, debugging output for files of 'set auto-load ...'\n\
int unsupported_script_warning_printed
int script_not_found_warning_printed
static void auto_load_safe_path_vec_update(void)
static void show_auto_load_local_gdbinit(struct ui_file *file, int from_tty, struct cmd_list_element *c, const char *value)
struct cmd_list_element * next
static void show_debug_auto_load(struct ui_file *file, int from_tty, struct cmd_list_element *c, const char *value)
#define VEC_replace(T, V, I, O)
void field_string(const char *fldname, const char *string)
const struct extension_language_defn extension_language_gdb
static void execute_script_contents(struct auto_load_pspace_info *pspace_info, struct objfile *objfile, const struct extension_language_defn *language, const char *section_name, unsigned int offset, const char *script)
static void maybe_print_unsupported_script_warning(struct auto_load_pspace_info *, struct objfile *objfile, const struct extension_language_defn *language, const char *section_name, unsigned offset)
static int auto_load_objfile_script_1(struct objfile *objfile, const char *realname, const struct extension_language_defn *language)
__extension__ enum cmd_types type
void warning(const char *fmt,...)
static bool sort_scripts_by_name(loaded_script *a, loaded_script *b)
const struct extension_language_defn * language
int auto_load_local_gdbinit_loaded
void objfile_script_executor_func(const struct extension_language_defn *, struct objfile *, const char *name, const char *script)
std::vector< loaded_script * > * scripts_p
struct cmd_list_element ** auto_load_set_cmdlist_get(void)
void table_header(int width, ui_align align, const std::string &col_name, const std::string &col_hdr)
#define AUTO_LOAD_SAFE_PATH
static void add_auto_load_safe_path(const char *args, int from_tty)
struct cmd_list_element * add_cmd(const char *name, enum command_class theclass, const char *doc, struct cmd_list_element **list)
char auto_load_info_scripts_pattern_nl[]
#define DIRNAME_SEPARATOR
void filename_completer(struct cmd_list_element *ignore, completion_tracker &tracker, const char *text, const char *word)
#define AUTO_SECTION_NAME
static ATTRIBUTE_PURE int filename_is_in_pattern(const char *filename, const char *pattern)
#define VEC_safe_push(T, V, O)
static void add_auto_load_dir(const char *args, int from_tty)
struct cmd_list_element * cmdlist
gdb::unique_xmalloc_ptr< char > gdb_realpath(const char *filename)
char * auto_load_local_gdbinit_pathname
const char * ext_lang_name(const struct extension_language_defn *extlang)
static void info_auto_load_cmd(const char *args, int from_tty)
void substitute_path_component(char **stringp, const char *from, const char *to)
collect_matching_scripts_data(std::vector< loaded_script *> *scripts_p_, const extension_language_defn *language_)
static struct auto_load_pspace_info * get_auto_load_pspace_data(struct program_space *pspace)
void text(const char *string)
char * debug_file_directory
static void show_auto_load_dir(struct ui_file *file, int from_tty, struct cmd_list_element *c, const char *value)
void printf_filtered(const char *format,...)
struct cmd_list_element * add_prefix_cmd(const char *name, enum command_class theclass, cmd_const_cfunc_ftype *fun, const char *doc, struct cmd_list_element **prefixlist, const char *prefixname, int allow_unknown, struct cmd_list_element **list)
void null_cleanup(void *arg)
void auto_load_objfile_script(struct objfile *objfile, const struct extension_language_defn *language)
static void auto_load_new_objfile(struct objfile *objfile)
struct cmd_list_element * infolist
void _initialize_auto_load(void)
struct cmd_list_element * setlist
#define VEC_iterate(T, V, I, P)
static void print_scripts(const std::vector< loaded_script *> &scripts)
struct htab * loaded_script_files
int auto_load_local_gdbinit
std::unique_ptr< FILE, gdb_file_deleter > gdb_file_up
static int debug_auto_load
void objfile_script_sourcer_func(const struct extension_language_defn *, struct objfile *, FILE *stream, const char *filename)
static void source_section_scripts(struct objfile *objfile, const char *section_name, const char *start, const char *end)
std::unique_ptr< T, xfree_deleter< T > > unique_xmalloc_ptr
void load_auto_scripts_for_objfile(struct objfile *objfile)
void cmd_func(struct cmd_list_element *cmd, const char *args, int from_tty)
void fprintf_filtered(struct ui_file *stream, const char *format,...)
static int filename_is_in_pattern_1(char *filename, char *pattern)
const struct extension_language_defn * language
void free_char_ptr_vec(VEC(char_ptr) *char_ptr_vec)
void set_cmd_completer(struct cmd_list_element *cmd, completer_ftype *completer)
void fprintf_unfiltered(struct ui_file *stream, const char *format,...)
static int maybe_add_script_text(struct auto_load_pspace_info *pspace_info, int loaded, const char *name, const struct extension_language_defn *language)
void vfprintf_unfiltered(struct ui_file *stream, const char *format, va_list args)
struct cmd_list_element * showlist
static void show_auto_load_cmd(const char *args, int from_tty)
static void source_script_file(struct auto_load_pspace_info *pspace_info, struct objfile *objfile, const struct extension_language_defn *language, const char *section_name, unsigned int offset, const char *file)
__extension__ enum var_types var_type
struct cleanup * make_cleanup(make_cleanup_ftype *function, void *arg)
static void set_auto_load_dir(const char *args, int from_tty, struct cmd_list_element *c)
#define VEC_index(T, V, I)
static void auto_load_gdb_datadir_changed(void)
static void info_auto_load_local_gdbinit(const char *args, int from_tty)
gdb_file_up gdb_fopen_cloexec(const char *filename, const char *opentype)
static char * auto_load_dir
static int collect_matching_scripts(void **slot, void *info)
static void set_auto_load_safe_path(const char *args, int from_tty, struct cmd_list_element *c)
char * xstrprintf(const char *format,...)
int file_is_auto_load_safe(const char *filename, const char *debug_fmt,...)
struct cmd_list_element * setdebuglist
const char * objfile_name(const struct objfile *objfile)
void cmd_show_list(struct cmd_list_element *list, int from_tty, const char *prefix)
static int maybe_add_script_file(struct auto_load_pspace_info *pspace_info, int loaded, const char *name, const char *full_path, const struct extension_language_defn *language)
const struct extension_language_defn * get_ext_lang_defn(enum extension_language lang)
static void show_auto_load_safe_path(struct ui_file *file, int from_tty, struct cmd_list_element *c, const char *value)
static const struct program_space_data * auto_load_pspace_data
struct auto_load_pspace_info * get_auto_load_pspace_data_for_loading(struct program_space *pspace)
static char * auto_load_safe_path
static int eq_loaded_script_entry(const void *a, const void *b)
static void info_auto_load_gdb_scripts(const char *pattern, int from_tty)
static void init_loaded_scripts_info(struct auto_load_pspace_info *pspace_info)
int auto_load_gdb_scripts_enabled(const struct extension_language_defn *extlang)
const char * ext_lang_auto_load_suffix(const struct extension_language_defn *extlang)
void add_setshow_boolean_cmd(const char *name, enum command_class theclass, int *var, const char *set_doc, const char *show_doc, const char *help_doc, cmd_const_sfunc_ftype *set_func, show_value_ftype *show_func, struct cmd_list_element **set_list, struct cmd_list_element **show_list)
void message(const char *format,...) ATTRIBUTE_PRINTF(2
std::string string_printf(const char *fmt,...)
int gdb_filename_fnmatch(const char *pattern, const char *string, int flags)
static int filename_is_in_auto_load_safe_path_vec(const char *filename, gdb::unique_xmalloc_ptr< char > *filename_realp)
EXTERN_C char * re_comp(const char *)
struct program_space * current_program_space
struct observer * observer_attach_new_objfile(observer_new_objfile_ftype *f)
void add_setshow_optional_filename_cmd(const char *name, enum command_class theclass, char **var, const char *set_doc, const char *show_doc, const char *help_doc, cmd_const_sfunc_ftype *set_func, show_value_ftype *show_func, struct cmd_list_element **set_list, struct cmd_list_element **show_list)
void do_set_command(const char *arg, int from_tty, struct cmd_list_element *c)
void auto_load_ext_lang_scripts_for_objfile(struct objfile *objfile)
struct cmd_list_element ** prefixlist
struct cmd_list_element * showdebuglist
int ext_lang_auto_load_enabled(const struct extension_language_defn *extlang)
struct htab * loaded_script_texts
gdb::unique_xmalloc_ptr< char > full_path
objfile_script_executor_func * ext_lang_objfile_script_executor(const struct extension_language_defn *extlang)
static void set_auto_load_cmd(const char *args, int from_tty)
struct cleanup * make_cleanup_free_char_ptr_vec(VEC(char_ptr) *char_ptr_vec)
static void clear_section_scripts(void)
static int auto_load_gdb_scripts
static void auto_load_section_scripts(struct objfile *objfile, const char *section_name)
objfile_script_sourcer_func * ext_lang_objfile_script_sourcer(const struct extension_language_defn *extlang)
struct observer * observer_attach_gdb_datadir_changed(observer_gdb_datadir_changed_ftype *f)
struct cmd_list_element ** auto_load_show_cmdlist_get(void)
static void auto_load_pspace_data_cleanup(struct program_space *pspace, void *arg)
int is_target_filename(const char *name)
static hashval_t hash_loaded_script_entry(const void *data)
void auto_load_info_scripts(const char *pattern, int from_tty, const struct extension_language_defn *language)
static void print_script(struct loaded_script *script)
void error(const char *fmt,...)
gdb::optional< open_script > find_and_open_script(const char *script_file, int search_path)
void do_cleanups(struct cleanup *old_chain)
static void show_auto_load_gdb_scripts(struct ui_file *file, int from_tty, struct cmd_list_element *c, const char *value)
struct cmd_list_element ** auto_load_info_cmdlist_get(void)
static void maybe_print_script_not_found_warning(struct auto_load_pspace_info *, struct objfile *objfile, const struct extension_language_defn *language, const char *section_name, unsigned offset)