+ struct stat homebuf, cwdbuf;
+ memset (&homebuf, 0, sizeof (struct stat));
+ memset (&cwdbuf, 0, sizeof (struct stat));
+
+ m_home_file = find_gdb_home_config_file (filename, &homebuf);
+
+ if (lookup_local_file && stat (filename, &cwdbuf) == 0)
+ {
+ if (m_home_file.empty ()
+ || memcmp ((char *) &homebuf, (char *) &cwdbuf,
+ sizeof (struct stat)))
+ m_local_file = filename;
+ }
+ }
+
+ DISABLE_COPY_AND_ASSIGN (gdb_initfile_finder);
+
+ /* Return a list of system initialisation files. The list could be
+ empty. */
+ const std::vector<std::string> &system_files () const
+ { return m_system_files; }
+
+ /* Return the path to the home initialisation file. The string can be
+ empty if there is no such file. */
+ const std::string &home_file () const
+ { return m_home_file; }
+
+ /* Return the path to the local initialisation file. The string can be
+ empty if there is no such file. */
+ const std::string &local_file () const
+ { return m_local_file; }
+
+private:
+
+ /* Vector of all system init files in the order they should be processed.
+ Could be empty. */
+ std::vector<std::string> m_system_files;
+
+ /* Initialization file from the home directory. Could be the empty
+ string if there is no such file found. */
+ std::string m_home_file;
+
+ /* Initialization file from the current working directory. Could be the
+ empty string if there is no such file found. */
+ std::string m_local_file;
+};
+
+/* Compute the locations of init files that GDB should source and return
+ them in SYSTEM_GDBINIT, HOME_GDBINIT, LOCAL_GDBINIT. The SYSTEM_GDBINIT
+ can be returned as an empty vector, and HOME_GDBINIT and LOCAL_GDBINIT
+ can be returned as empty strings if there is no init file of that
+ type. */
+
+static void
+get_init_files (std::vector<std::string> *system_gdbinit,
+ std::string *home_gdbinit,
+ std::string *local_gdbinit)
+{
+ /* Cache the file lookup object so we only actually search for the files
+ once. */
+ static gdb::optional<gdb_initfile_finder> init_files;
+ if (!init_files.has_value ())
+ init_files.emplace (GDBINIT, SYSTEM_GDBINIT, SYSTEM_GDBINIT_RELOCATABLE,
+ SYSTEM_GDBINIT_DIR, SYSTEM_GDBINIT_DIR_RELOCATABLE,
+ true);
+
+ *system_gdbinit = init_files->system_files ();
+ *home_gdbinit = init_files->home_file ();
+ *local_gdbinit = init_files->local_file ();
+}
+
+/* Compute the location of the early init file GDB should source and return
+ it in HOME_GDBEARLYINIT. HOME_GDBEARLYINIT could be returned as an
+ empty string if there is no early init file found. */
+
+static void
+get_earlyinit_files (std::string *home_gdbearlyinit)
+{
+ /* Cache the file lookup object so we only actually search for the files
+ once. */
+ static gdb::optional<gdb_initfile_finder> init_files;
+ if (!init_files.has_value ())
+ init_files.emplace (GDBEARLYINIT, nullptr, false, nullptr, false, false);
+
+ *home_gdbearlyinit = init_files->home_file ();
+}
+
+/* Start up the event loop. This is the entry point to the event loop
+ from the command loop. */
+
+static void
+start_event_loop ()
+{
+ /* Loop until there is nothing to do. This is the entry point to
+ the event loop engine. gdb_do_one_event will process one event
+ for each invocation. It blocks waiting for an event and then
+ processes it. */
+ while (1)
+ {
+ int result = 0;