- filename = xstrprintf ("%.*s", filename_len, pathname);
- cleanup = make_cleanup (xfree, filename);
- member_name = xstrprintf ("%.*s", path_len - filename_len - 2, sep + 1);
- make_cleanup (xfree, member_name);
-
- archive_bfd = gdb_bfd_open (filename, gnutarget, -1);
+ std::string filename (string_printf ("%.*s", filename_len, pathname));
+ std::string member_name (string_printf ("%.*s", path_len - filename_len - 2,
+ sep + 1));
+
+ /* Calling solib_find makes certain that sysroot path is set properly
+ if program has a dependency on .a archive and sysroot is set via
+ set sysroot command. */
+ gdb::unique_xmalloc_ptr<char> found_pathname
+ = solib_find (filename.c_str (), &found_file);
+ if (found_pathname == NULL)
+ perror_with_name (pathname);
+ gdb_bfd_ref_ptr archive_bfd (solib_bfd_fopen (found_pathname.get (),
+ found_file));