summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJonas Devlieghere <jonas@devlieghere.com>2019-07-19 00:52:08 +0000
committerJonas Devlieghere <jonas@devlieghere.com>2019-07-19 00:52:08 +0000
commit0288c269689bfa7b6b90da1a1e058c9ebb6fa278 (patch)
tree66979335871349d671b0f979345da8f0a984cb0e
parentcb30520555da15bced842965757b4e0a5ed772d8 (diff)
downloadbcm5719-llvm-0288c269689bfa7b6b90da1a1e058c9ebb6fa278.tar.gz
bcm5719-llvm-0288c269689bfa7b6b90da1a1e058c9ebb6fa278.zip
[Target] Return an llvm::Expected from GetEntryPointAddress (NFC)
Instead of taking a status and potentially returning an invalid address, return an expected which is guaranteed to contain a valid address. llvm-svn: 366521
-rw-r--r--lldb/include/lldb/Target/Target.h6
-rw-r--r--lldb/source/Target/Target.cpp45
-rw-r--r--lldb/source/Target/ThreadPlanCallFunction.cpp18
3 files changed, 33 insertions, 36 deletions
diff --git a/lldb/include/lldb/Target/Target.h b/lldb/include/lldb/Target/Target.h
index b1de1932708..af8090ccad5 100644
--- a/lldb/include/lldb/Target/Target.h
+++ b/lldb/include/lldb/Target/Target.h
@@ -1118,7 +1118,7 @@ public:
/// This method will return the address of the starting function for
/// this binary, e.g. main() or its equivalent. This can be used as
- /// an address of a function that is not called once a binary has
+ /// an address of a function that is not called once a binary has
/// started running - e.g. as a return address for inferior function
/// calls that are unambiguous completion of the function call, not
/// called during the course of the inferior function code running.
@@ -1130,9 +1130,9 @@ public:
/// be found, and may contain a helpful error message.
//
/// \return
- /// Returns the entry address for this program, LLDB_INVALID_ADDRESS
+ /// Returns the entry address for this program, or an error
/// if none can be found.
- lldb_private::Address GetEntryPointAddress(Status &err);
+ llvm::Expected<lldb_private::Address> GetEntryPointAddress();
// Target Stop Hooks
class StopHook : public UserID {
diff --git a/lldb/source/Target/Target.cpp b/lldb/source/Target/Target.cpp
index 290094efc4b..7c12b752ee9 100644
--- a/lldb/source/Target/Target.cpp
+++ b/lldb/source/Target/Target.cpp
@@ -2448,44 +2448,43 @@ lldb::addr_t Target::GetPersistentSymbol(ConstString name) {
return address;
}
-lldb_private::Address Target::GetEntryPointAddress(Status &err) {
- err.Clear();
- Address entry_addr;
+llvm::Expected<lldb_private::Address> Target::GetEntryPointAddress() {
Module *exe_module = GetExecutableModulePointer();
+ llvm::Error error = llvm::Error::success();
+ assert(!error); // Check the success value when assertions are enabled.
if (!exe_module || !exe_module->GetObjectFile()) {
- err.SetErrorStringWithFormat("No primary executable found");
+ error = llvm::make_error<llvm::StringError>("No primary executable found",
+ llvm::inconvertibleErrorCode());
} else {
- entry_addr = exe_module->GetObjectFile()->GetEntryPointAddress();
- if (!entry_addr.IsValid()) {
- err.SetErrorStringWithFormat(
- "Could not find entry point address for executable module \"%s\".",
- exe_module->GetFileSpec().GetFilename().AsCString());
- }
+ Address entry_addr = exe_module->GetObjectFile()->GetEntryPointAddress();
+ if (entry_addr.IsValid())
+ return entry_addr;
+
+ error = llvm::make_error<llvm::StringError>(
+ "Could not find entry point address for executable module \"" +
+ exe_module->GetFileSpec().GetFilename().GetStringRef() + "\"",
+ llvm::inconvertibleErrorCode());
}
- if (!entry_addr.IsValid()) {
const ModuleList &modules = GetImages();
const size_t num_images = modules.GetSize();
for (size_t idx = 0; idx < num_images; ++idx) {
ModuleSP module_sp(modules.GetModuleAtIndex(idx));
- if (module_sp && module_sp->GetObjectFile()) {
- entry_addr = module_sp->GetObjectFile()->GetEntryPointAddress();
- if (entry_addr.IsValid()) {
- // Clear out any old error messages from the original
- // main-executable-binary search; one of the other modules
- // was able to provide an address.
- err.Clear();
- break;
- }
- }
+ if (!module_sp || !module_sp->GetObjectFile())
+ continue;
+
+ Address entry_addr = module_sp->GetObjectFile()->GetEntryPointAddress();
+ if (entry_addr.IsValid()) {
+ // Discard the error.
+ llvm::consumeError(std::move(error));
+ return entry_addr;
}
}
- return entry_addr;
+ return std::move(error);
}
-
lldb::addr_t Target::GetCallableLoadAddress(lldb::addr_t load_addr,
AddressClass addr_class) const {
auto arch_plugin = GetArchitecturePlugin();
diff --git a/lldb/source/Target/ThreadPlanCallFunction.cpp b/lldb/source/Target/ThreadPlanCallFunction.cpp
index 57f4ef5874c..c4cf133a27f 100644
--- a/lldb/source/Target/ThreadPlanCallFunction.cpp
+++ b/lldb/source/Target/ThreadPlanCallFunction.cpp
@@ -65,19 +65,17 @@ bool ThreadPlanCallFunction::ConstructorSetup(
return false;
}
- m_start_addr = GetTarget().GetEntryPointAddress(error);
-
- if (log && error.Fail()) {
- m_constructor_errors.Printf("%s", error.AsCString());
- log->Printf("ThreadPlanCallFunction(%p): %s.", static_cast<void *>(this),
- m_constructor_errors.GetData());
- return false;
- }
-
- if (!m_start_addr.IsValid()) {
+ llvm::Expected<Address> start_address = GetTarget().GetEntryPointAddress();
+ if (!start_address) {
+ m_constructor_errors.Printf(
+ "%s", llvm::toString(start_address.takeError()).c_str());
+ if (log)
+ log->Printf("ThreadPlanCallFunction(%p): %s.", static_cast<void *>(this),
+ m_constructor_errors.GetData());
return false;
}
+ m_start_addr = *start_address;
start_load_addr = m_start_addr.GetLoadAddress(&GetTarget());
// Checkpoint the thread state so we can restore it later.
OpenPOWER on IntegriCloud