+ /* Skip this script if auto-loading it has been disabled. */
+ if (!ext_lang_auto_load_enabled (language))
+ {
+ /* No message is printed, just skip it. */
+ return;
+ }
+
+ gdb::optional<open_script> opened = find_and_open_script (file,
+ 1 /*search_path*/);
+
+ if (opened)
+ {
+ if (!file_is_auto_load_safe (opened->full_path.get (),
+ _("auto-load: Loading %s script "
+ "\"%s\" from section \"%s\" of "
+ "objfile \"%s\".\n"),
+ ext_lang_name (language),
+ opened->full_path.get (),
+ section_name, objfile_name (objfile)))
+ opened.reset ();
+ }
+ else
+ {
+ /* If one script isn't found it's not uncommon for more to not be
+ found either. We don't want to print a message for each script,
+ too much noise. Instead, we print the warning once and tell the
+ user how to find the list of scripts that weren't loaded.
+ We don't throw an error, the program is still debuggable.
+
+ IWBN if complaints.c were more general-purpose. */
+
+ maybe_print_script_not_found_warning (pspace_info, objfile, language,
+ section_name, offset);
+ }
+
+ in_hash_table = maybe_add_script_file (pspace_info, bool (opened), file,
+ (opened
+ ? opened->full_path.get ()
+ : NULL),
+ language);
+
+ /* If this file is not currently loaded, load it. */
+ if (opened && !in_hash_table)
+ sourcer (language, objfile, opened->stream.get (),
+ opened->full_path.get ());
+}
+
+/* Subroutine of source_section_scripts to simplify it.
+ Execute SCRIPT as a script in extension language LANG.
+ The script is from section SECTION_NAME in OBJFILE at offset OFFSET. */
+
+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)
+{
+ objfile_script_executor_func *executor;
+ const char *newline, *script_text;
+ const char *name;
+ int is_safe, in_hash_table;
+
+ /* The first line of the script is the name of the script.
+ It must not contain any kind of space character. */
+ name = NULL;
+ newline = strchr (script, '\n');
+ std::string name_holder;
+ if (newline != NULL)
+ {
+ const char *buf, *p;
+
+ /* Put the name in a buffer and validate it. */
+ name_holder = std::string (script, newline - script);
+ buf = name_holder.c_str ();
+ for (p = buf; *p != '\0'; ++p)
+ {
+ if (isspace (*p))
+ break;
+ }
+ /* We don't allow nameless scripts, they're not helpful to the user. */
+ if (p != buf && *p == '\0')
+ name = buf;
+ }
+ if (name == NULL)
+ {
+ /* We don't throw an error, the program is still debuggable. */
+ warning (_("\
+Missing/bad script name in entry at offset %u in section %s\n\
+of file %ps."),
+ offset, section_name,
+ styled_string (file_name_style.style (),
+ objfile_name (objfile)));
+ return;
+ }
+ script_text = newline + 1;
+
+ /* Skip this script if support is not compiled in. */
+ executor = ext_lang_objfile_script_executor (language);
+ if (executor == NULL)
+ {
+ /* We don't throw an error, the program is still debuggable. */
+ maybe_print_unsupported_script_warning (pspace_info, objfile, language,
+ section_name, offset);
+ maybe_add_script_text (pspace_info, 0, name, language);
+ return;
+ }
+
+ /* Skip this script if auto-loading it has been disabled. */
+ if (!ext_lang_auto_load_enabled (language))
+ {
+ /* No message is printed, just skip it. */
+ return;
+ }
+
+ is_safe = file_is_auto_load_safe (objfile_name (objfile),
+ _("auto-load: Loading %s script "
+ "\"%s\" from section \"%s\" of "
+ "objfile \"%s\".\n"),
+ ext_lang_name (language), name,
+ section_name, objfile_name (objfile));
+
+ in_hash_table = maybe_add_script_text (pspace_info, is_safe, name, language);
+
+ /* If this file is not currently loaded, load it. */
+ if (is_safe && !in_hash_table)
+ executor (language, objfile, name, script_text);