Simplify ObjectFile::GetArchitecture
Summary:
instead of returning the architecture through by-ref argument and a
boolean value indicating success, we can just return the ArchSpec
directly. Since the ArchSpec already has an invalid state, it can be
used to denote the failure without the additional bool.
Reviewers: clayborg, zturner, espindola
Subscribers: emaste, arichardson, JDevlieghere, lldb-commits
Differential Revision: https://reviews.llvm.org/D56129
llvm-svn: 350291
diff --git a/lldb/source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp b/lldb/source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp
index 95685c2..e3a86f3 100644
--- a/lldb/source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp
+++ b/lldb/source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp
@@ -434,9 +434,8 @@
if (address_size == 4 || address_size == 8) {
std::unique_ptr<ObjectFileELF> objfile_ap(new ObjectFileELF(
module_sp, data_sp, data_offset, file, file_offset, length));
- ArchSpec spec;
- if (objfile_ap->GetArchitecture(spec) &&
- objfile_ap->SetModulesArchitecture(spec))
+ ArchSpec spec = objfile_ap->GetArchitecture();
+ if (spec && objfile_ap->SetModulesArchitecture(spec))
return objfile_ap.release();
}
@@ -453,9 +452,8 @@
if (address_size == 4 || address_size == 8) {
std::unique_ptr<ObjectFileELF> objfile_ap(
new ObjectFileELF(module_sp, data_sp, process_sp, header_addr));
- ArchSpec spec;
- if (objfile_ap->GetArchitecture(spec) &&
- objfile_ap->SetModulesArchitecture(spec))
+ ArchSpec spec = objfile_ap->GetArchitecture();
+ if (spec && objfile_ap->SetModulesArchitecture(spec))
return objfile_ap.release();
}
}
@@ -1957,8 +1955,7 @@
bool skip_oatdata_oatexec = file_extension == ConstString(".oat") ||
file_extension == ConstString(".odex");
- ArchSpec arch;
- GetArchitecture(arch);
+ ArchSpec arch = GetArchitecture();
ModuleSP module_sp(GetModule());
SectionList *module_section_list =
module_sp ? module_sp->GetSectionList() : nullptr;
@@ -2885,8 +2882,7 @@
s->Indent();
s->PutCString("ObjectFileELF");
- ArchSpec header_arch;
- GetArchitecture(header_arch);
+ ArchSpec header_arch = GetArchitecture();
*s << ", file = '" << m_file
<< "', arch = " << header_arch.GetArchitectureName() << "\n";
@@ -3172,9 +3168,9 @@
}
}
-bool ObjectFileELF::GetArchitecture(ArchSpec &arch) {
+ArchSpec ObjectFileELF::GetArchitecture() {
if (!ParseHeader())
- return false;
+ return ArchSpec();
if (m_section_headers.empty()) {
// Allow elf notes to be parsed which may affect the detected architecture.
@@ -3195,8 +3191,7 @@
}
}
}
- arch = m_arch_spec;
- return true;
+ return m_arch_spec;
}
ObjectFile::Type ObjectFileELF::CalculateType() {