mirror of
https://github.com/intel/llvm.git
synced 2026-01-15 12:25:46 +08:00
Simplify ObjectFile::GetUUID
instead of returning the UUID through by-ref argument and a boolean value indicating success, we can just return it directly. Since the UUID class already has an invalid state, it can be used to denote the failure without the additional bool. llvm-svn: 353714
This commit is contained in:
@@ -408,10 +408,10 @@ public:
|
||||
/// bytes for the object file (or memory for memory based object files).
|
||||
///
|
||||
/// @return
|
||||
/// Returns \b true if a UUID was successfully extracted into
|
||||
/// \a uuid, \b false otherwise.
|
||||
/// The object file's UUID. In case of an error, an empty UUID is
|
||||
/// returned.
|
||||
//------------------------------------------------------------------
|
||||
virtual bool GetUUID(lldb_private::UUID *uuid) = 0;
|
||||
virtual UUID GetUUID() = 0;
|
||||
|
||||
//------------------------------------------------------------------
|
||||
/// Gets the symbol file spec list for this object file.
|
||||
|
||||
@@ -330,7 +330,7 @@ const lldb_private::UUID &Module::GetUUID() {
|
||||
ObjectFile *obj_file = GetObjectFile();
|
||||
|
||||
if (obj_file != nullptr) {
|
||||
obj_file->GetUUID(&m_uuid);
|
||||
m_uuid = obj_file->GetUUID();
|
||||
m_did_set_uuid = true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -122,11 +122,6 @@ Symtab *ObjectFileBreakpad::GetSymtab() {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
bool ObjectFileBreakpad::GetUUID(UUID *uuid) {
|
||||
*uuid = m_uuid;
|
||||
return true;
|
||||
}
|
||||
|
||||
void ObjectFileBreakpad::CreateSections(SectionList &unified_section_list) {
|
||||
if (m_sections_ap)
|
||||
return;
|
||||
|
||||
@@ -82,7 +82,7 @@ public:
|
||||
|
||||
ArchSpec GetArchitecture() override { return m_arch; }
|
||||
|
||||
bool GetUUID(UUID *uuid) override;
|
||||
UUID GetUUID() override { return m_uuid; }
|
||||
|
||||
FileSpecList GetDebugSymbolFilePaths() override { return FileSpecList(); }
|
||||
|
||||
|
||||
@@ -896,49 +896,43 @@ bool ObjectFileELF::ParseHeader() {
|
||||
return m_header.Parse(m_data, &offset);
|
||||
}
|
||||
|
||||
bool ObjectFileELF::GetUUID(lldb_private::UUID *uuid) {
|
||||
UUID ObjectFileELF::GetUUID() {
|
||||
// Need to parse the section list to get the UUIDs, so make sure that's been
|
||||
// done.
|
||||
if (!ParseSectionHeaders() && GetType() != ObjectFile::eTypeCoreFile)
|
||||
return false;
|
||||
return UUID();
|
||||
|
||||
using u32le = llvm::support::ulittle32_t;
|
||||
if (m_uuid.IsValid()) {
|
||||
// We have the full build id uuid.
|
||||
*uuid = m_uuid;
|
||||
return true;
|
||||
} else if (GetType() == ObjectFile::eTypeCoreFile) {
|
||||
uint32_t core_notes_crc = 0;
|
||||
if (!m_uuid) {
|
||||
using u32le = llvm::support::ulittle32_t;
|
||||
if (GetType() == ObjectFile::eTypeCoreFile) {
|
||||
uint32_t core_notes_crc = 0;
|
||||
|
||||
if (!ParseProgramHeaders())
|
||||
return false;
|
||||
if (!ParseProgramHeaders())
|
||||
return UUID();
|
||||
|
||||
core_notes_crc = CalculateELFNotesSegmentsCRC32(m_program_headers, m_data);
|
||||
core_notes_crc =
|
||||
CalculateELFNotesSegmentsCRC32(m_program_headers, m_data);
|
||||
|
||||
if (core_notes_crc) {
|
||||
// Use 8 bytes - first 4 bytes for *magic* prefix, mainly to make it look
|
||||
// different form .gnu_debuglink crc - followed by 4 bytes of note
|
||||
// segments crc.
|
||||
u32le data[] = {u32le(g_core_uuid_magic), u32le(core_notes_crc)};
|
||||
m_uuid = UUID::fromData(data, sizeof(data));
|
||||
}
|
||||
} else {
|
||||
if (!m_gnu_debuglink_crc)
|
||||
m_gnu_debuglink_crc =
|
||||
calc_gnu_debuglink_crc32(m_data.GetDataStart(), m_data.GetByteSize());
|
||||
if (m_gnu_debuglink_crc) {
|
||||
// Use 4 bytes of crc from the .gnu_debuglink section.
|
||||
u32le data(m_gnu_debuglink_crc);
|
||||
m_uuid = UUID::fromData(&data, sizeof(data));
|
||||
if (core_notes_crc) {
|
||||
// Use 8 bytes - first 4 bytes for *magic* prefix, mainly to make it
|
||||
// look different form .gnu_debuglink crc - followed by 4 bytes of note
|
||||
// segments crc.
|
||||
u32le data[] = {u32le(g_core_uuid_magic), u32le(core_notes_crc)};
|
||||
m_uuid = UUID::fromData(data, sizeof(data));
|
||||
}
|
||||
} else {
|
||||
if (!m_gnu_debuglink_crc)
|
||||
m_gnu_debuglink_crc = calc_gnu_debuglink_crc32(m_data.GetDataStart(),
|
||||
m_data.GetByteSize());
|
||||
if (m_gnu_debuglink_crc) {
|
||||
// Use 4 bytes of crc from the .gnu_debuglink section.
|
||||
u32le data(m_gnu_debuglink_crc);
|
||||
m_uuid = UUID::fromData(&data, sizeof(data));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (m_uuid.IsValid()) {
|
||||
*uuid = m_uuid;
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
return m_uuid;
|
||||
}
|
||||
|
||||
lldb_private::FileSpecList ObjectFileELF::GetDebugSymbolFilePaths() {
|
||||
|
||||
@@ -122,7 +122,7 @@ public:
|
||||
|
||||
lldb_private::ArchSpec GetArchitecture() override;
|
||||
|
||||
bool GetUUID(lldb_private::UUID *uuid) override;
|
||||
lldb_private::UUID GetUUID() override;
|
||||
|
||||
lldb_private::FileSpecList GetDebugSymbolFilePaths() override;
|
||||
|
||||
|
||||
@@ -166,9 +166,9 @@ void ObjectFileJIT::Dump(Stream *s) {
|
||||
}
|
||||
}
|
||||
|
||||
bool ObjectFileJIT::GetUUID(lldb_private::UUID *uuid) {
|
||||
UUID ObjectFileJIT::GetUUID() {
|
||||
// TODO: maybe get from delegate, not needed for first pass
|
||||
return false;
|
||||
return UUID();
|
||||
}
|
||||
|
||||
uint32_t ObjectFileJIT::GetDependentModules(FileSpecList &files) {
|
||||
|
||||
@@ -74,7 +74,7 @@ public:
|
||||
|
||||
lldb_private::ArchSpec GetArchitecture() override;
|
||||
|
||||
bool GetUUID(lldb_private::UUID *uuid) override;
|
||||
lldb_private::UUID GetUUID() override;
|
||||
|
||||
uint32_t GetDependentModules(lldb_private::FileSpecList &files) override;
|
||||
|
||||
|
||||
@@ -916,7 +916,7 @@ size_t ObjectFileMachO::GetModuleSpecifications(
|
||||
|
||||
spec.GetArchitecture() = GetArchitecture(header, data, data_offset);
|
||||
if (spec.GetArchitecture().IsValid()) {
|
||||
GetUUID(header, data, data_offset, spec.GetUUID());
|
||||
spec.GetUUID() = GetUUID(header, data, data_offset);
|
||||
specs.Append(spec);
|
||||
}
|
||||
}
|
||||
@@ -4845,10 +4845,9 @@ void ObjectFileMachO::Dump(Stream *s) {
|
||||
}
|
||||
}
|
||||
|
||||
bool ObjectFileMachO::GetUUID(const llvm::MachO::mach_header &header,
|
||||
UUID ObjectFileMachO::GetUUID(const llvm::MachO::mach_header &header,
|
||||
const lldb_private::DataExtractor &data,
|
||||
lldb::offset_t lc_offset,
|
||||
lldb_private::UUID &uuid) {
|
||||
lldb::offset_t lc_offset) {
|
||||
uint32_t i;
|
||||
struct uuid_command load_cmd;
|
||||
|
||||
@@ -4870,16 +4869,15 @@ bool ObjectFileMachO::GetUUID(const llvm::MachO::mach_header &header,
|
||||
0xbb, 0x14, 0xf0, 0x0d};
|
||||
|
||||
if (!memcmp(uuid_bytes, opencl_uuid, 16))
|
||||
return false;
|
||||
return UUID();
|
||||
|
||||
uuid = UUID::fromOptionalData(uuid_bytes, 16);
|
||||
return true;
|
||||
return UUID::fromOptionalData(uuid_bytes, 16);
|
||||
}
|
||||
return false;
|
||||
return UUID();
|
||||
}
|
||||
offset = cmd_offset + load_cmd.cmdsize;
|
||||
}
|
||||
return false;
|
||||
return UUID();
|
||||
}
|
||||
|
||||
static llvm::StringRef GetOSName(uint32_t cmd) {
|
||||
@@ -5066,14 +5064,14 @@ ObjectFileMachO::GetArchitecture(const llvm::MachO::mach_header &header,
|
||||
return arch;
|
||||
}
|
||||
|
||||
bool ObjectFileMachO::GetUUID(lldb_private::UUID *uuid) {
|
||||
UUID ObjectFileMachO::GetUUID() {
|
||||
ModuleSP module_sp(GetModule());
|
||||
if (module_sp) {
|
||||
std::lock_guard<std::recursive_mutex> guard(module_sp->GetMutex());
|
||||
lldb::offset_t offset = MachHeaderSizeFromMagic(m_header.magic);
|
||||
return GetUUID(m_header, m_data, offset, *uuid);
|
||||
return GetUUID(m_header, m_data, offset);
|
||||
}
|
||||
return false;
|
||||
return UUID();
|
||||
}
|
||||
|
||||
uint32_t ObjectFileMachO::GetDependentModules(FileSpecList &files) {
|
||||
@@ -5553,8 +5551,7 @@ ObjectFile::Type ObjectFileMachO::CalculateType() {
|
||||
if (GetAddressByteSize() == 4) {
|
||||
// 32 bit kexts are just object files, but they do have a valid
|
||||
// UUID load command.
|
||||
UUID uuid;
|
||||
if (GetUUID(&uuid)) {
|
||||
if (GetUUID()) {
|
||||
// this checking for the UUID load command is not enough we could
|
||||
// eventually look for the symbol named "OSKextGetCurrentIdentifier" as
|
||||
// this is required of kexts
|
||||
@@ -5597,8 +5594,7 @@ ObjectFile::Strata ObjectFileMachO::CalculateStrata() {
|
||||
{
|
||||
// 32 bit kexts are just object files, but they do have a valid
|
||||
// UUID load command.
|
||||
UUID uuid;
|
||||
if (GetUUID(&uuid)) {
|
||||
if (GetUUID()) {
|
||||
// this checking for the UUID load command is not enough we could
|
||||
// eventually look for the symbol named "OSKextGetCurrentIdentifier" as
|
||||
// this is required of kexts
|
||||
|
||||
@@ -93,7 +93,7 @@ public:
|
||||
|
||||
lldb_private::ArchSpec GetArchitecture() override;
|
||||
|
||||
bool GetUUID(lldb_private::UUID *uuid) override;
|
||||
lldb_private::UUID GetUUID() override;
|
||||
|
||||
uint32_t GetDependentModules(lldb_private::FileSpecList &files) override;
|
||||
|
||||
@@ -140,11 +140,10 @@ public:
|
||||
uint32_t GetPluginVersion() override;
|
||||
|
||||
protected:
|
||||
static bool
|
||||
static lldb_private::UUID
|
||||
GetUUID(const llvm::MachO::mach_header &header,
|
||||
const lldb_private::DataExtractor &data,
|
||||
lldb::offset_t lc_offset, // Offset to the first load command
|
||||
lldb_private::UUID &uuid);
|
||||
lldb::offset_t lc_offset); // Offset to the first load command
|
||||
|
||||
static lldb_private::ArchSpec
|
||||
GetArchitecture(const llvm::MachO::mach_header &header,
|
||||
|
||||
@@ -837,7 +837,7 @@ void ObjectFilePECOFF::CreateSections(SectionList &unified_section_list) {
|
||||
}
|
||||
}
|
||||
|
||||
bool ObjectFilePECOFF::GetUUID(UUID *uuid) { return false; }
|
||||
UUID ObjectFilePECOFF::GetUUID() { return UUID(); }
|
||||
|
||||
uint32_t ObjectFilePECOFF::ParseDependentModules() {
|
||||
ModuleSP module_sp(GetModule());
|
||||
|
||||
@@ -111,7 +111,7 @@ public:
|
||||
|
||||
lldb_private::ArchSpec GetArchitecture() override;
|
||||
|
||||
bool GetUUID(lldb_private::UUID *uuid) override;
|
||||
lldb_private::UUID GetUUID() override;
|
||||
|
||||
uint32_t GetDependentModules(lldb_private::FileSpecList &files) override;
|
||||
|
||||
|
||||
@@ -75,8 +75,8 @@ SymbolVendorELF::CreateInstance(const lldb::ModuleSP &module_sp,
|
||||
if (obj_name != obj_file_elf)
|
||||
return NULL;
|
||||
|
||||
lldb_private::UUID uuid;
|
||||
if (!obj_file->GetUUID(&uuid))
|
||||
lldb_private::UUID uuid = obj_file->GetUUID();
|
||||
if (!uuid)
|
||||
return NULL;
|
||||
|
||||
// Get the .gnu_debuglink file (if specified).
|
||||
|
||||
Reference in New Issue
Block a user