@@ -253,48 +253,34 @@ int LocateMacOSXFilesUsingDebugSymbols(const ModuleSpec &module_spec,
253253FileSpec Symbols::FindSymbolFileInBundle (const FileSpec &dsym_bundle_fspec,
254254 const lldb_private::UUID *uuid,
255255 const ArchSpec *arch) {
256- char path[PATH_MAX];
257- if (dsym_bundle_fspec.GetPath (path, sizeof (path)) == 0 )
258- return {};
259-
260- ::strncat (path, " /Contents/Resources/DWARF" , sizeof (path) - strlen(path) - 1);
261-
262- DIR *dirp = opendir (path);
263- if (!dirp)
264- return {};
265-
266- // Make sure we close the directory before exiting this scope.
267- auto cleanup_dir = llvm::make_scope_exit ([&]() { closedir (dirp); });
268-
269- FileSpec dsym_fspec;
270- dsym_fspec.GetDirectory ().SetCString (path);
271- struct dirent *dp;
272- while ((dp = readdir (dirp)) != NULL ) {
273- // Only search directories
274- if (dp->d_type == DT_DIR || dp->d_type == DT_UNKNOWN) {
275- if (dp->d_namlen == 1 && dp->d_name [0 ] == ' .' )
276- continue ;
277-
278- if (dp->d_namlen == 2 && dp->d_name [0 ] == ' .' && dp->d_name [1 ] == ' .' )
279- continue ;
280- }
281-
282- if (dp->d_type == DT_REG || dp->d_type == DT_UNKNOWN) {
283- dsym_fspec.GetFilename ().SetCString (dp->d_name );
284- ModuleSpecList module_specs;
285- if (ObjectFile::GetModuleSpecifications (dsym_fspec, 0 , 0 , module_specs)) {
286- ModuleSpec spec;
287- for (size_t i = 0 ; i < module_specs.GetSize (); ++i) {
288- bool got_spec = module_specs.GetModuleSpecAtIndex (i, spec);
289- UNUSED_IF_ASSERT_DISABLED (got_spec);
290- assert (got_spec);
291- if ((uuid == NULL ||
292- (spec.GetUUIDPtr () && spec.GetUUID () == *uuid)) &&
293- (arch == NULL ||
294- (spec.GetArchitecturePtr () &&
295- spec.GetArchitecture ().IsCompatibleMatch (*arch)))) {
296- return dsym_fspec;
297- }
256+ std::string dsym_bundle_path = dsym_bundle_fspec.GetPath ();
257+ llvm::SmallString<128 > buffer (dsym_bundle_path);
258+ llvm::sys::path::append (buffer, " Contents" , " Resources" , " DWARF" );
259+
260+ std::error_code EC;
261+ llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem> vfs =
262+ FileSystem::Instance ().GetVirtualFileSystem ();
263+ llvm::vfs::recursive_directory_iterator Iter (*vfs, buffer.str (), EC);
264+ llvm::vfs::recursive_directory_iterator End;
265+ for (; Iter != End && !EC; Iter.increment (EC)) {
266+ llvm::ErrorOr<llvm::vfs::Status> Status = vfs->status (Iter->path ());
267+ if (Status->isDirectory ())
268+ continue ;
269+
270+ FileSpec dsym_fspec (Iter->path ());
271+ ModuleSpecList module_specs;
272+ if (ObjectFile::GetModuleSpecifications (dsym_fspec, 0 , 0 , module_specs)) {
273+ ModuleSpec spec;
274+ for (size_t i = 0 ; i < module_specs.GetSize (); ++i) {
275+ bool got_spec = module_specs.GetModuleSpecAtIndex (i, spec);
276+ assert (got_spec); // The call has side-effects so can't be inlined.
277+ UNUSED_IF_ASSERT_DISABLED (got_spec);
278+ if ((uuid == nullptr ||
279+ (spec.GetUUIDPtr () && spec.GetUUID () == *uuid)) &&
280+ (arch == nullptr ||
281+ (spec.GetArchitecturePtr () &&
282+ spec.GetArchitecture ().IsCompatibleMatch (*arch)))) {
283+ return dsym_fspec;
298284 }
299285 }
300286 }
0 commit comments