Skip to content

Commit 8a4152b

Browse files
committed
Revert "[lldb] Improve error message for unrecognized executables (llvm#97490)"
This reverts commit ed7e468.
1 parent a853fe2 commit 8a4152b

File tree

4 files changed

+44
-55
lines changed

4 files changed

+44
-55
lines changed

lldb/include/lldb/Symbol/ObjectFile.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,6 @@ class ObjectFile : public std::enable_shared_from_this<ObjectFile>,
178178
lldb::offset_t file_offset,
179179
lldb::offset_t file_size,
180180
lldb_private::ModuleSpecList &specs);
181-
static bool IsObjectFile(lldb_private::FileSpec file_spec);
182181
/// Split a path into a file path with object name.
183182
///
184183
/// For paths like "/tmp/foo.a(bar.o)" we often need to split a path up into

lldb/source/Symbol/ObjectFile.cpp

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -184,15 +184,6 @@ ObjectFileSP ObjectFile::FindPlugin(const lldb::ModuleSP &module_sp,
184184
return object_file_sp;
185185
}
186186

187-
bool ObjectFile::IsObjectFile(lldb_private::FileSpec file_spec) {
188-
DataBufferSP data_sp;
189-
offset_t data_offset = 0;
190-
ModuleSP module_sp = std::make_shared<Module>(file_spec);
191-
return static_cast<bool>(ObjectFile::FindPlugin(
192-
module_sp, &file_spec, 0, FileSystem::Instance().GetByteSize(file_spec),
193-
data_sp, data_offset));
194-
}
195-
196187
size_t ObjectFile::GetModuleSpecifications(const FileSpec &file,
197188
lldb::offset_t file_offset,
198189
lldb::offset_t file_size,

lldb/source/Target/Platform.cpp

Lines changed: 43 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -732,6 +732,7 @@ Status
732732
Platform::ResolveExecutable(const ModuleSpec &module_spec,
733733
lldb::ModuleSP &exe_module_sp,
734734
const FileSpecList *module_search_paths_ptr) {
735+
Status error;
735736

736737
// We may connect to a process and use the provided executable (Don't use
737738
// local $PATH).
@@ -740,57 +741,55 @@ Platform::ResolveExecutable(const ModuleSpec &module_spec,
740741
// Resolve any executable within a bundle on MacOSX
741742
Host::ResolveExecutableInBundle(resolved_module_spec.GetFileSpec());
742743

743-
if (!FileSystem::Instance().Exists(resolved_module_spec.GetFileSpec()) &&
744-
!module_spec.GetUUID().IsValid())
745-
return Status::createWithFormat("'{0}' does not exist",
746-
resolved_module_spec.GetFileSpec());
747-
748-
if (resolved_module_spec.GetArchitecture().IsValid() ||
749-
resolved_module_spec.GetUUID().IsValid()) {
750-
Status error =
751-
ModuleList::GetSharedModule(resolved_module_spec, exe_module_sp,
752-
module_search_paths_ptr, nullptr, nullptr);
744+
if (FileSystem::Instance().Exists(resolved_module_spec.GetFileSpec()) ||
745+
module_spec.GetUUID().IsValid()) {
746+
if (resolved_module_spec.GetArchitecture().IsValid() ||
747+
resolved_module_spec.GetUUID().IsValid()) {
748+
error = ModuleList::GetSharedModule(resolved_module_spec, exe_module_sp,
749+
module_search_paths_ptr, nullptr,
750+
nullptr);
753751

754-
if (exe_module_sp && exe_module_sp->GetObjectFile())
755-
return error;
756-
exe_module_sp.reset();
757-
}
758-
// No valid architecture was specified or the exact arch wasn't found.
759-
// Ask the platform for the architectures that we should be using (in the
760-
// correct order) and see if we can find a match that way.
761-
StreamString arch_names;
762-
llvm::ListSeparator LS;
763-
ArchSpec process_host_arch;
764-
Status error;
765-
for (const ArchSpec &arch : GetSupportedArchitectures(process_host_arch)) {
766-
resolved_module_spec.GetArchitecture() = arch;
767-
error =
768-
ModuleList::GetSharedModule(resolved_module_spec, exe_module_sp,
769-
module_search_paths_ptr, nullptr, nullptr);
770-
if (error.Success()) {
771752
if (exe_module_sp && exe_module_sp->GetObjectFile())
772-
break;
773-
error.SetErrorToGenericError();
753+
return error;
754+
exe_module_sp.reset();
774755
}
756+
// No valid architecture was specified or the exact arch wasn't found.
757+
// Ask the platform for the architectures that we should be using (in the
758+
// correct order) and see if we can find a match that way.
759+
StreamString arch_names;
760+
llvm::ListSeparator LS;
761+
ArchSpec process_host_arch;
762+
for (const ArchSpec &arch : GetSupportedArchitectures(process_host_arch)) {
763+
resolved_module_spec.GetArchitecture() = arch;
764+
error = ModuleList::GetSharedModule(resolved_module_spec, exe_module_sp,
765+
module_search_paths_ptr, nullptr,
766+
nullptr);
767+
if (error.Success()) {
768+
if (exe_module_sp && exe_module_sp->GetObjectFile())
769+
break;
770+
error.SetErrorToGenericError();
771+
}
775772

776-
arch_names << LS << arch.GetArchitectureName();
777-
}
778-
779-
if (exe_module_sp && error.Success())
780-
return {};
781-
782-
if (!FileSystem::Instance().Readable(resolved_module_spec.GetFileSpec()))
783-
return Status::createWithFormat("'{0}' is not readable",
784-
resolved_module_spec.GetFileSpec());
773+
arch_names << LS << arch.GetArchitectureName();
774+
}
785775

786-
if (!ObjectFile::IsObjectFile(resolved_module_spec.GetFileSpec()))
787-
return Status::createWithFormat("'{0}' is not a valid executable",
776+
if (error.Fail() || !exe_module_sp) {
777+
if (FileSystem::Instance().Readable(resolved_module_spec.GetFileSpec())) {
778+
error.SetErrorStringWithFormatv(
779+
"'{0}' doesn't contain any '{1}' platform architectures: {2}",
780+
resolved_module_spec.GetFileSpec(), GetPluginName(),
781+
arch_names.GetData());
782+
} else {
783+
error.SetErrorStringWithFormatv("'{0}' is not readable",
784+
resolved_module_spec.GetFileSpec());
785+
}
786+
}
787+
} else {
788+
error.SetErrorStringWithFormatv("'{0}' does not exist",
788789
resolved_module_spec.GetFileSpec());
790+
}
789791

790-
return Status::createWithFormat(
791-
"'{0}' doesn't contain any '{1}' platform architectures: {2}",
792-
resolved_module_spec.GetFileSpec(), GetPluginName(),
793-
arch_names.GetData());
792+
return error;
794793
}
795794

796795
Status Platform::ResolveSymbolFile(Target &target, const ModuleSpec &sym_spec,

lldb/test/Shell/ObjectFile/PECOFF/invalid-export-table.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
# RUN: yaml2obj %s -o %t.exe
55
# RUN: %lldb %t.exe 2>&1 | FileCheck %s
66

7-
# CHECK: error: '{{.*}}' is not a valid executable
7+
# CHECK: error: '{{.*}}' doesn't contain any {{.*}} platform architectures
88
--- !COFF
99
OptionalHeader:
1010
AddressOfEntryPoint: 4096

0 commit comments

Comments
 (0)