+ {
+ set_current_program_space (ss);
+ clear_section_table (current_target_sections);
+ exec_close ();
+ }
+}
+
+/* See gdbcore.h. */
+
+void
+try_open_exec_file (const char *exec_file_host, struct inferior *inf,
+ symfile_add_flags add_flags)
+{
+ struct gdb_exception prev_err;
+
+ /* exec_file_attach and symbol_file_add_main may throw an error if the file
+ cannot be opened either locally or remotely.
+
+ This happens for example, when the file is first found in the local
+ sysroot (above), and then disappears (a TOCTOU race), or when it doesn't
+ exist in the target filesystem, or when the file does exist, but
+ is not readable.
+
+ Even without a symbol file, the remote-based debugging session should
+ continue normally instead of ending abruptly. Hence we catch thrown
+ errors/exceptions in the following code. */
+ try
+ {
+ /* We must do this step even if exec_file_host is NULL, so that
+ exec_file_attach will clear state. */
+ exec_file_attach (exec_file_host, add_flags & SYMFILE_VERBOSE);
+ }
+ catch (gdb_exception_error &err)
+ {
+ if (err.message != NULL)
+ warning ("%s", err.what ());
+
+ prev_err = std::move (err);
+ }