+/* Return the full pathname of the main executable, or NULL if not
+ found. The returned pathname is malloc'ed and must be freed by
+ the caller. If FD is non-NULL, *FD is set to either -1 or an open
+ file handle for the main executable. */
+
+char *
+exec_file_find (const char *in_pathname, int *fd)
+{
+ char *result;
+ const char *fskind = effective_target_file_system_kind ();
+
+ if (in_pathname == NULL)
+ return NULL;
+
+ if (*gdb_sysroot != '\0' && IS_TARGET_ABSOLUTE_PATH (fskind, in_pathname))
+ {
+ result = solib_find_1 (in_pathname, fd, 0);
+
+ if (result == NULL && fskind == file_system_kind_dos_based)
+ {
+ char *new_pathname;
+
+ new_pathname = (char *) alloca (strlen (in_pathname) + 5);
+ strcpy (new_pathname, in_pathname);
+ strcat (new_pathname, ".exe");
+
+ result = solib_find_1 (new_pathname, fd, 0);
+ }
+ }
+ else
+ {
+ /* It's possible we don't have a full path, but rather just a
+ filename. Some targets, such as HP-UX, don't provide the
+ full path, sigh.
+
+ Attempt to qualify the filename against the source path.
+ (If that fails, we'll just fall back on the original
+ filename. Not much more we can do...) */
+
+ if (!source_full_path_of (in_pathname, &result))
+ result = xstrdup (in_pathname);
+ if (fd != NULL)
+ *fd = -1;
+ }
+
+ return result;
+}
+
+/* Return the full pathname of a shared library file, or NULL if not
+ found. The returned pathname is malloc'ed and must be freed by
+ the caller. If FD is non-NULL, *FD is set to either -1 or an open
+ file handle for the shared library.
+
+ The search algorithm used is described in solib_find_1's comment
+ above. */
+
+char *
+solib_find (const char *in_pathname, int *fd)
+{
+ const char *solib_symbols_extension
+ = gdbarch_solib_symbols_extension (target_gdbarch ());
+
+ /* If solib_symbols_extension is set, replace the file's
+ extension. */
+ if (solib_symbols_extension != NULL)
+ {
+ const char *p = in_pathname + strlen (in_pathname);
+
+ while (p > in_pathname && *p != '.')
+ p--;
+
+ if (*p == '.')
+ {
+ char *new_pathname;
+
+ new_pathname
+ = (char *) alloca (p - in_pathname + 1
+ + strlen (solib_symbols_extension) + 1);
+ memcpy (new_pathname, in_pathname, p - in_pathname + 1);
+ strcpy (new_pathname + (p - in_pathname) + 1,
+ solib_symbols_extension);
+
+ in_pathname = new_pathname;
+ }
+ }
+
+ return solib_find_1 (in_pathname, fd, 1);
+}
+