[Lldb-commits] [lldb] r366521 - [Target] Return an llvm::Expected from GetEntryPointAddress (NFC)
Jonas Devlieghere via lldb-commits
lldb-commits at lists.llvm.org
Thu Jul 18 17:52:09 PDT 2019
Author: jdevlieghere
Date: Thu Jul 18 17:52:08 2019
New Revision: 366521
URL: http://llvm.org/viewvc/llvm-project?rev=366521&view=rev
Log:
[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.
Modified:
lldb/trunk/include/lldb/Target/Target.h
lldb/trunk/source/Target/Target.cpp
lldb/trunk/source/Target/ThreadPlanCallFunction.cpp
Modified: lldb/trunk/include/lldb/Target/Target.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Target/Target.h?rev=366521&r1=366520&r2=366521&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Target/Target.h (original)
+++ lldb/trunk/include/lldb/Target/Target.h Thu Jul 18 17:52:08 2019
@@ -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 {
Modified: lldb/trunk/source/Target/Target.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Target/Target.cpp?rev=366521&r1=366520&r2=366521&view=diff
==============================================================================
--- lldb/trunk/source/Target/Target.cpp (original)
+++ lldb/trunk/source/Target/Target.cpp Thu Jul 18 17:52:08 2019
@@ -2448,44 +2448,43 @@ lldb::addr_t Target::GetPersistentSymbol
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();
Modified: lldb/trunk/source/Target/ThreadPlanCallFunction.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Target/ThreadPlanCallFunction.cpp?rev=366521&r1=366520&r2=366521&view=diff
==============================================================================
--- lldb/trunk/source/Target/ThreadPlanCallFunction.cpp (original)
+++ lldb/trunk/source/Target/ThreadPlanCallFunction.cpp Thu Jul 18 17:52:08 2019
@@ -65,19 +65,17 @@ bool ThreadPlanCallFunction::Constructor
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.
More information about the lldb-commits
mailing list