mib updated this revision to Diff 261775.
mib added a comment.
Add error "consumption" following @labath comment.
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D78712/new/
https://reviews.llvm.org/D78712
Files:
lldb/source/Commands/CommandObjectTarget.cpp
lldb/source/Plugins/Platform/POSIX/PlatformPOSIX.cpp
lldb/test/API/commands/target/basic/TestTargetCommand.py
Index: lldb/test/API/commands/target/basic/TestTargetCommand.py
===================================================================
--- lldb/test/API/commands/target/basic/TestTargetCommand.py
+++ lldb/test/API/commands/target/basic/TestTargetCommand.py
@@ -326,7 +326,7 @@
@no_debug_info_test
def test_target_create_nonexistent_core_file(self):
self.expect("target create -c doesntexist", error=True,
- substrs=["core file 'doesntexist' doesn't exist"])
+ substrs=["Cannot open 'doesntexist': No such file or directory"])
# Write only files don't seem to be supported on Windows.
@skipIfWindows
@@ -335,12 +335,12 @@
tf = tempfile.NamedTemporaryFile()
os.chmod(tf.name, stat.S_IWRITE)
self.expect("target create -c '" + tf.name + "'", error=True,
- substrs=["core file '", "' is not readable"])
+ substrs=["Cannot open '", "': Permission denied"])
@no_debug_info_test
def test_target_create_nonexistent_sym_file(self):
self.expect("target create -s doesntexist doesntexisteither", error=True,
- substrs=["invalid symbol file path 'doesntexist'"])
+ substrs=["Cannot open '", "': No such file or directory"])
@skipIfWindows
@no_debug_info_test
@@ -357,7 +357,7 @@
tf = tempfile.NamedTemporaryFile()
os.chmod(tf.name, stat.S_IWRITE)
self.expect("target create -s '" + tf.name + "' no_exe", error=True,
- substrs=["symbol file '", "' is not readable"])
+ substrs=["Cannot open '", "': Permission denied"])
@no_debug_info_test
def test_target_delete_all(self):
Index: lldb/source/Plugins/Platform/POSIX/PlatformPOSIX.cpp
===================================================================
--- lldb/source/Plugins/Platform/POSIX/PlatformPOSIX.cpp
+++ lldb/source/Plugins/Platform/POSIX/PlatformPOSIX.cpp
@@ -71,14 +71,16 @@
Status error;
// Nothing special to do here, just use the actual file and architecture
- char exe_path[PATH_MAX];
+ std::string exe_path;
ModuleSpec resolved_module_spec(module_spec);
+ auto resolved_module = FileSystem::Instance().Open(
+ resolved_module_spec.GetFileSpec(), lldb_private::File::eOpenOptionRead);
if (IsHost()) {
// If we have "ls" as the exe_file, resolve the executable location based
// on the current path variables
- if (!FileSystem::Instance().Exists(resolved_module_spec.GetFileSpec())) {
- resolved_module_spec.GetFileSpec().GetPath(exe_path, sizeof(exe_path));
+ if (!resolved_module) {
+ exe_path = resolved_module_spec.GetFileSpec().GetPath();
resolved_module_spec.GetFileSpec().SetFile(exe_path,
FileSpec::Style::native);
FileSystem::Instance().Resolve(resolved_module_spec.GetFileSpec());
@@ -91,20 +93,18 @@
// Resolve any executable within a bundle on MacOSX
Host::ResolveExecutableInBundle(resolved_module_spec.GetFileSpec());
- if (FileSystem::Instance().Exists(resolved_module_spec.GetFileSpec()))
- error.Clear();
- else {
- const uint32_t permissions = FileSystem::Instance().GetPermissions(
- resolved_module_spec.GetFileSpec());
- if (permissions && (permissions & eFilePermissionsEveryoneR) == 0)
- error.SetErrorStringWithFormat(
- "executable '%s' is not readable",
- resolved_module_spec.GetFileSpec().GetPath().c_str());
- else
- error.SetErrorStringWithFormat(
- "unable to find executable for '%s'",
- resolved_module_spec.GetFileSpec().GetPath().c_str());
+ llvm::consumeError(resolved_module.takeError());
+ resolved_module =
+ FileSystem::Instance().Open(resolved_module_spec.GetFileSpec(),
+ lldb_private::File::eOpenOptionRead);
+
+ if (!resolved_module) {
+ error.SetErrorStringWithFormatv(
+ "Cannot open '{0}': {1}.", resolved_module_spec.GetFileSpec(),
+ llvm::toString(resolved_module.takeError()));
+ return error;
}
+
} else {
if (m_remote_platform_sp) {
error =
@@ -117,88 +117,90 @@
// Resolve any executable within a bundle on MacOSX
Host::ResolveExecutableInBundle(resolved_module_spec.GetFileSpec());
- if (FileSystem::Instance().Exists(resolved_module_spec.GetFileSpec()))
- error.Clear();
- else
- error.SetErrorStringWithFormat("the platform is not currently "
- "connected, and '%s' doesn't exist in "
- "the system root.",
- exe_path);
+ if (!resolved_module) {
+ error.SetErrorStringWithFormatv("the platform is not currently "
+ "connected, and '{0}' doesn't exist in "
+ "the system root.",
+ exe_path);
+ llvm::consumeError(resolved_module.takeError());
+ return error;
+ }
}
}
- if (error.Success()) {
- if (resolved_module_spec.GetArchitecture().IsValid()) {
- error = ModuleList::GetSharedModule(resolved_module_spec, exe_module_sp,
- module_search_paths_ptr, nullptr, nullptr);
- if (error.Fail()) {
- // If we failed, it may be because the vendor and os aren't known. If
- // that is the case, try setting them to the host architecture and give
- // it another try.
- llvm::Triple &module_triple =
- resolved_module_spec.GetArchitecture().GetTriple();
- bool is_vendor_specified =
- (module_triple.getVendor() != llvm::Triple::UnknownVendor);
- bool is_os_specified =
- (module_triple.getOS() != llvm::Triple::UnknownOS);
- if (!is_vendor_specified || !is_os_specified) {
- const llvm::Triple &host_triple =
- HostInfo::GetArchitecture(HostInfo::eArchKindDefault).GetTriple();
-
- if (!is_vendor_specified)
- module_triple.setVendorName(host_triple.getVendorName());
- if (!is_os_specified)
- module_triple.setOSName(host_triple.getOSName());
-
- error = ModuleList::GetSharedModule(resolved_module_spec,
- exe_module_sp, module_search_paths_ptr, nullptr, nullptr);
- }
- }
+ if (resolved_module_spec.GetArchitecture().IsValid()) {
+ error =
+ ModuleList::GetSharedModule(resolved_module_spec, exe_module_sp,
+ module_search_paths_ptr, nullptr, nullptr);
+ if (error.Fail()) {
+ // If we failed, it may be because the vendor and os aren't known. If
+ // that is the case, try setting them to the host architecture and give
+ // it another try.
+ llvm::Triple &module_triple =
+ resolved_module_spec.GetArchitecture().GetTriple();
+ bool is_vendor_specified =
+ (module_triple.getVendor() != llvm::Triple::UnknownVendor);
+ bool is_os_specified = (module_triple.getOS() != llvm::Triple::UnknownOS);
+ if (!is_vendor_specified || !is_os_specified) {
+ const llvm::Triple &host_triple =
+ HostInfo::GetArchitecture(HostInfo::eArchKindDefault).GetTriple();
+
+ if (!is_vendor_specified)
+ module_triple.setVendorName(host_triple.getVendorName());
+ if (!is_os_specified)
+ module_triple.setOSName(host_triple.getOSName());
- // TODO find out why exe_module_sp might be NULL
- if (error.Fail() || !exe_module_sp || !exe_module_sp->GetObjectFile()) {
- exe_module_sp.reset();
- error.SetErrorStringWithFormat(
- "'%s' doesn't contain the architecture %s",
- resolved_module_spec.GetFileSpec().GetPath().c_str(),
- resolved_module_spec.GetArchitecture().GetArchitectureName());
- }
- } else {
- // No valid architecture was specified, ask the platform for the
- // architectures that we should be using (in the correct order) and see
- // if we can find a match that way
- StreamString arch_names;
- for (uint32_t idx = 0; GetSupportedArchitectureAtIndex(
- idx, resolved_module_spec.GetArchitecture());
- ++idx) {
error = ModuleList::GetSharedModule(resolved_module_spec, exe_module_sp,
- module_search_paths_ptr, nullptr, nullptr);
- // Did we find an executable using one of the
- if (error.Success()) {
- if (exe_module_sp && exe_module_sp->GetObjectFile())
- break;
- else
- error.SetErrorToGenericError();
- }
+ module_search_paths_ptr, nullptr,
+ nullptr);
+ }
+ }
- if (idx > 0)
- arch_names.PutCString(", ");
- arch_names.PutCString(
- resolved_module_spec.GetArchitecture().GetArchitectureName());
+ // TODO find out why exe_module_sp might be NULL
+ if (error.Fail() || !exe_module_sp || !exe_module_sp->GetObjectFile()) {
+ exe_module_sp.reset();
+ error.SetErrorStringWithFormat(
+ "'%s' doesn't contain the architecture %s",
+ resolved_module_spec.GetFileSpec().GetPath().c_str(),
+ resolved_module_spec.GetArchitecture().GetArchitectureName());
+ }
+ } else {
+ // No valid architecture was specified, ask the platform for the
+ // architectures that we should be using (in the correct order) and see
+ // if we can find a match that way
+ StreamString arch_names;
+ for (uint32_t idx = 0; GetSupportedArchitectureAtIndex(
+ idx, resolved_module_spec.GetArchitecture());
+ ++idx) {
+ error = ModuleList::GetSharedModule(resolved_module_spec, exe_module_sp,
+ module_search_paths_ptr, nullptr,
+ nullptr);
+ // Did we find an executable using one of the
+ if (error.Success()) {
+ if (exe_module_sp && exe_module_sp->GetObjectFile())
+ break;
+ else
+ error.SetErrorToGenericError();
}
- if (error.Fail() || !exe_module_sp) {
- if (FileSystem::Instance().Readable(
- resolved_module_spec.GetFileSpec())) {
- error.SetErrorStringWithFormat(
- "'%s' doesn't contain any '%s' platform architectures: %s",
- resolved_module_spec.GetFileSpec().GetPath().c_str(),
- GetPluginName().GetCString(), arch_names.GetData());
- } else {
- error.SetErrorStringWithFormat(
- "'%s' is not readable",
- resolved_module_spec.GetFileSpec().GetPath().c_str());
- }
+ if (idx > 0)
+ arch_names.PutCString(", ");
+ arch_names.PutCString(
+ resolved_module_spec.GetArchitecture().GetArchitectureName());
+ }
+
+ if (error.Fail() || !exe_module_sp) {
+ if (!resolved_module) {
+ error.SetErrorStringWithFormatv(
+ "Cannot open '{0}': {1}.",
+ resolved_module_spec.GetFileSpec().GetPath(),
+ llvm::toString(resolved_module.takeError()));
+ } else {
+ llvm::consumeError(resolved_module.takeError());
+ error.SetErrorStringWithFormatv(
+ "'{0}' doesn't contain any '{1}' platform architectures: {2}",
+ resolved_module_spec.GetFileSpec().GetPath(), GetPluginName(),
+ arch_names.GetData());
}
}
}
Index: lldb/source/Commands/CommandObjectTarget.cpp
===================================================================
--- lldb/source/Commands/CommandObjectTarget.cpp
+++ lldb/source/Commands/CommandObjectTarget.cpp
@@ -271,15 +271,13 @@
FileSpec remote_file(m_remote_file.GetOptionValue().GetCurrentValue());
if (core_file) {
- if (!FileSystem::Instance().Exists(core_file)) {
- result.AppendErrorWithFormat("core file '%s' doesn't exist",
- core_file.GetPath().c_str());
- result.SetStatus(eReturnStatusFailed);
- return false;
- }
- if (!FileSystem::Instance().Readable(core_file)) {
- result.AppendErrorWithFormat("core file '%s' is not readable",
- core_file.GetPath().c_str());
+ auto file = FileSystem::Instance().Open(
+ core_file, lldb_private::File::eOpenOptionRead);
+
+ if (!file) {
+ result.AppendErrorWithFormatv("Cannot open '{0}': {1}.",
+ core_file.GetPath(),
+ llvm::toString(file.takeError()));
result.SetStatus(eReturnStatusFailed);
return false;
}
@@ -288,18 +286,13 @@
if (argc == 1 || core_file || remote_file) {
FileSpec symfile(m_symbol_file.GetOptionValue().GetCurrentValue());
if (symfile) {
- if (FileSystem::Instance().Exists(symfile)) {
- if (!FileSystem::Instance().Readable(symfile)) {
- result.AppendErrorWithFormat("symbol file '%s' is not readable",
- symfile.GetPath().c_str());
- result.SetStatus(eReturnStatusFailed);
- return false;
- }
- } else {
- char symfile_path[PATH_MAX];
- symfile.GetPath(symfile_path, sizeof(symfile_path));
- result.AppendErrorWithFormat("invalid symbol file path '%s'",
- symfile_path);
+ auto file = FileSystem::Instance().Open(
+ symfile, lldb_private::File::eOpenOptionRead);
+
+ if (!file) {
+ result.AppendErrorWithFormatv("Cannot open '{0}': {1}.",
+ symfile.GetPath(),
+ llvm::toString(file.takeError()));
result.SetStatus(eReturnStatusFailed);
return false;
}
@@ -401,48 +394,35 @@
if (module_sp)
module_sp->SetPlatformFileSpec(remote_file);
}
+
if (core_file) {
- char core_path[PATH_MAX];
- core_file.GetPath(core_path, sizeof(core_path));
- if (FileSystem::Instance().Exists(core_file)) {
- if (!FileSystem::Instance().Readable(core_file)) {
- result.AppendMessageWithFormat(
- "Core file '%s' is not readable.\n", core_path);
- result.SetStatus(eReturnStatusFailed);
- return false;
- }
- FileSpec core_file_dir;
- core_file_dir.GetDirectory() = core_file.GetDirectory();
- target_sp->AppendExecutableSearchPaths(core_file_dir);
+ FileSpec core_file_dir;
+ core_file_dir.GetDirectory() = core_file.GetDirectory();
+ target_sp->AppendExecutableSearchPaths(core_file_dir);
- ProcessSP process_sp(target_sp->CreateProcess(
- GetDebugger().GetListener(), llvm::StringRef(), &core_file));
+ ProcessSP process_sp(target_sp->CreateProcess(
+ GetDebugger().GetListener(), llvm::StringRef(), &core_file));
- if (process_sp) {
- // Seems weird that we Launch a core file, but that is what we
- // do!
- error = process_sp->LoadCore();
+ if (process_sp) {
+ // Seems weird that we Launch a core file, but that is what we
+ // do!
+ error = process_sp->LoadCore();
- if (error.Fail()) {
- result.AppendError(
- error.AsCString("can't find plug-in for core file"));
- result.SetStatus(eReturnStatusFailed);
- return false;
- } else {
- result.AppendMessageWithFormat(
- "Core file '%s' (%s) was loaded.\n", core_path,
- target_sp->GetArchitecture().GetArchitectureName());
- result.SetStatus(eReturnStatusSuccessFinishNoResult);
- }
- } else {
- result.AppendErrorWithFormat(
- "Unable to find process plug-in for core file '%s'\n",
- core_path);
+ if (error.Fail()) {
+ result.AppendError(
+ error.AsCString("can't find plug-in for core file"));
result.SetStatus(eReturnStatusFailed);
+ return false;
+ } else {
+ result.AppendErrorWithFormatv(
+ "Core file '{0}' ({1}) was loaded.\n", core_file.GetPath(),
+ target_sp->GetArchitecture().GetArchitectureName());
+ result.SetStatus(eReturnStatusSuccessFinishNoResult);
}
} else {
- result.AppendErrorWithFormat("Core file '%s' does not exist\n",
- core_path);
+ result.AppendErrorWithFormatv(
+ "Unable to find process plug-in for core file '{0}'\n",
+ core_file.GetPath());
result.SetStatus(eReturnStatusFailed);
}
} else {
_______________________________________________
lldb-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits