Skip to content

Commit 8fcf69e

Browse files
Some Updates
1 parent c7d4eab commit 8fcf69e

File tree

4 files changed

+50
-124
lines changed

4 files changed

+50
-124
lines changed

lldb/include/lldb/Host/aix/HostInfoAIX.h

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,14 @@
66
//
77
//===----------------------------------------------------------------------===//
88

9-
#ifndef lldb_Host_aix_HostInfoAIX_h_
10-
#define lldb_Host_aix_HostInfoAIX_h_
9+
#ifndef LLDB_HOST_AIX_HOSTINFOAIX_H_
10+
#define LLDB_HOST_AIX_HOSTINFOAIX_H_
1111

1212
#include "lldb/Host/posix/HostInfoPosix.h"
1313
#include "lldb/Utility/FileSpec.h"
1414
#include "llvm/ADT/StringRef.h"
1515
#include "llvm/Support/VersionTuple.h"
1616

17-
#include <string>
18-
1917
namespace lldb_private {
2018

2119
class HostInfoAIX : public HostInfoPosix {
@@ -25,15 +23,10 @@ class HostInfoAIX : public HostInfoPosix {
2523
static void Initialize(SharedLibraryDirectoryHelper *helper = nullptr);
2624
static void Terminate();
2725

28-
static llvm::VersionTuple GetOSVersion();
29-
static std::optional<std::string> GetOSBuildString();
3026
static llvm::StringRef GetDistributionId();
3127
static FileSpec GetProgramFileSpec();
3228

3329
protected:
34-
static bool ComputeSupportExeDirectory(FileSpec &file_spec);
35-
static bool ComputeSystemPluginsDirectory(FileSpec &file_spec);
36-
static bool ComputeUserPluginsDirectory(FileSpec &file_spec);
3730
static void ComputeHostArchitectureSupport(ArchSpec &arch_32,
3831
ArchSpec &arch_64);
3932
};

lldb/source/Host/aix/HostInfoAIX.cpp

Lines changed: 2 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,6 @@ namespace {
2929
struct HostInfoAIXFields {
3030
llvm::once_flag m_distribution_once_flag;
3131
std::string m_distribution_id;
32-
llvm::once_flag m_os_version_once_flag;
33-
llvm::VersionTuple m_os_version;
3432
};
3533
} // namespace
3634

@@ -49,33 +47,6 @@ void HostInfoAIX::Terminate() {
4947
HostInfoBase::Terminate();
5048
}
5149

52-
llvm::VersionTuple HostInfoAIX::GetOSVersion() {
53-
assert(g_fields && "Missing call to Initialize?");
54-
llvm::call_once(g_fields->m_os_version_once_flag, []() {
55-
struct utsname un;
56-
if (uname(&un) != 0)
57-
return;
58-
59-
llvm::StringRef release = un.release;
60-
// The kernel release string can include a lot of stuff (e.g.
61-
// 4.9.0-6-amd64). We're only interested in the numbered prefix.
62-
release = release.substr(0, release.find_first_not_of("0123456789."));
63-
g_fields->m_os_version.tryParse(release);
64-
});
65-
66-
return g_fields->m_os_version;
67-
}
68-
69-
std::optional<std::string> HostInfoAIX::GetOSBuildString() {
70-
struct utsname un;
71-
::memset(&un, 0, sizeof(utsname));
72-
73-
if (uname(&un) < 0)
74-
return std::nullopt;
75-
76-
return std::string(un.release);
77-
}
78-
7950
llvm::StringRef HostInfoAIX::GetDistributionId() {
8051
assert(g_fields && "Missing call to Initialize?");
8152
// Try to run 'lbs_release -i', and use that response for the distribution
@@ -122,8 +93,7 @@ llvm::StringRef HostInfoAIX::GetDistributionId() {
12293
if (strstr(distribution_id, distributor_id_key)) {
12394
// strip newlines
12495
std::string id_string(distribution_id + strlen(distributor_id_key));
125-
id_string.erase(std::remove(id_string.begin(), id_string.end(), '\n'),
126-
id_string.end());
96+
llvm::erase(id_string, '\n');
12797

12898
// lower case it and convert whitespace to underscores
12999
std::transform(
@@ -167,42 +137,11 @@ FileSpec HostInfoAIX::GetProgramFileSpec() {
167137
return g_program_filespec;
168138
}
169139

170-
bool HostInfoAIX::ComputeSupportExeDirectory(FileSpec &file_spec) {
171-
if (HostInfoPosix::ComputeSupportExeDirectory(file_spec) &&
172-
file_spec.IsAbsolute() && FileSystem::Instance().Exists(file_spec))
173-
return true;
174-
file_spec.SetDirectory(GetProgramFileSpec().GetDirectory());
175-
return !file_spec.GetDirectory().IsEmpty();
176-
}
177-
178-
bool HostInfoAIX::ComputeSystemPluginsDirectory(FileSpec &file_spec) {
179-
FileSpec temp_file("/usr/" LLDB_INSTALL_LIBDIR_BASENAME "/lldb/plugins");
180-
FileSystem::Instance().Resolve(temp_file);
181-
file_spec.SetDirectory(temp_file.GetPath());
182-
return true;
183-
}
184-
185-
bool HostInfoAIX::ComputeUserPluginsDirectory(FileSpec &file_spec) {
186-
// XDG Base Directory Specification
187-
// http://standards.freedesktop.org/basedir-spec/basedir-spec-latest.html If
188-
// XDG_DATA_HOME exists, use that, otherwise use ~/.local/share/lldb.
189-
const char *xdg_data_home = getenv("XDG_DATA_HOME");
190-
if (xdg_data_home && xdg_data_home[0]) {
191-
std::string user_plugin_dir(xdg_data_home);
192-
user_plugin_dir += "/lldb";
193-
file_spec.SetDirectory(user_plugin_dir.c_str());
194-
} else
195-
file_spec.SetDirectory("~/.local/share/lldb");
196-
return true;
197-
}
198-
199140
void HostInfoAIX::ComputeHostArchitectureSupport(ArchSpec &arch_32,
200141
ArchSpec &arch_64) {
201142
HostInfoPosix::ComputeHostArchitectureSupport(arch_32, arch_64);
202143

203-
const char *distribution_id = GetDistributionId().data();
204-
205-
// On Linux, "unknown" in the vendor slot isn't what we want for the default
144+
// "unknown" in the vendor slot isn't what we want for the default
206145
// triple. It's probably an artifact of config.guess.
207146
if (arch_32.IsValid()) {
208147
if (arch_32.GetTriple().getVendor() == llvm::Triple::UnknownVendor)

lldb/source/Plugins/ObjectFile/XCOFF/ObjectFileXCOFF.cpp

Lines changed: 41 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
//===-- ObjectFileXCOFF.cpp -------------------------------------------------===//
1+
//===-- ObjectFileXCOFF.cpp
2+
//-------------------------------------------------===//
23
//
34
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
45
// See https://llvm.org/LICENSE.txt for license information.
@@ -7,13 +8,6 @@
78
//===----------------------------------------------------------------------===//
89

910
#include "ObjectFileXCOFF.h"
10-
11-
#include <algorithm>
12-
#include <cassert>
13-
#include <unordered_map>
14-
#include <string.h>
15-
16-
#include "lldb/Utility/FileSpecList.h"
1711
#include "lldb/Core/Module.h"
1812
#include "lldb/Core/ModuleSpec.h"
1913
#include "lldb/Core/PluginManager.h"
@@ -28,6 +22,7 @@
2822
#include "lldb/Target/Target.h"
2923
#include "lldb/Utility/ArchSpec.h"
3024
#include "lldb/Utility/DataBufferHeap.h"
25+
#include "lldb/Utility/FileSpecList.h"
3126
#include "lldb/Utility/LLDBLog.h"
3227
#include "lldb/Utility/Log.h"
3328
#include "lldb/Utility/RangeMap.h"
@@ -38,12 +33,16 @@
3833
#include "llvm/ADT/PointerUnion.h"
3934
#include "llvm/ADT/StringRef.h"
4035
#include "llvm/BinaryFormat/XCOFF.h"
36+
#include "llvm/Object/XCOFFObjectFile.h"
4137
#include "llvm/Object/Decompressor.h"
4238
#include "llvm/Support/CRC.h"
4339
#include "llvm/Support/FormatVariadic.h"
4440
#include "llvm/Support/MathExtras.h"
4541
#include "llvm/Support/MemoryBuffer.h"
46-
#include "llvm/Object/XCOFFObjectFile.h"
42+
#include <algorithm>
43+
#include <cassert>
44+
#include <cstring>
45+
#include <unordered_map>
4746

4847
using namespace llvm;
4948
using namespace lldb;
@@ -69,21 +68,19 @@ void ObjectFileXCOFF::Terminate() {
6968
bool UGLY_FLAG_FOR_AIX __attribute__((weak)) = false;
7069

7170
ObjectFile *ObjectFileXCOFF::CreateInstance(const lldb::ModuleSP &module_sp,
72-
DataBufferSP data_sp,
73-
lldb::offset_t data_offset,
74-
const lldb_private::FileSpec *file,
75-
lldb::offset_t file_offset,
76-
lldb::offset_t length) {
71+
DataBufferSP data_sp,
72+
lldb::offset_t data_offset,
73+
const lldb_private::FileSpec *file,
74+
lldb::offset_t file_offset,
75+
lldb::offset_t length) {
7776
if (!data_sp) {
7877
data_sp = MapFileData(*file, length, file_offset);
7978
if (!data_sp)
8079
return nullptr;
8180
data_offset = 0;
8281
}
83-
8482
if (!ObjectFileXCOFF::MagicBytesMatch(data_sp, data_offset, length))
8583
return nullptr;
86-
8784
// Update the data to contain the entire file if it doesn't already
8885
if (data_sp->GetByteSize() < length) {
8986
data_sp = MapFileData(*file, length, file_offset);
@@ -114,15 +111,15 @@ bool ObjectFileXCOFF::CreateBinary() {
114111

115112
Log *log = GetLog(LLDBLog::Object);
116113

117-
auto binary = llvm::object::XCOFFObjectFile::createObjectFile(llvm::MemoryBufferRef(
118-
toStringRef(m_data.GetData()), m_file.GetFilename().GetStringRef()),
119-
file_magic::xcoff_object_64);
114+
auto binary = llvm::object::ObjectFile::createObjectFile(
115+
llvm::MemoryBufferRef(toStringRef(m_data.GetData()),
116+
m_file.GetFilename().GetStringRef()),
117+
file_magic::xcoff_object_64);
120118
if (!binary) {
121119
LLDB_LOG_ERROR(log, binary.takeError(),
122120
"Failed to create binary for file ({1}): {0}", m_file);
123121
return false;
124122
}
125-
126123
// Make sure we only handle COFF format.
127124
m_binary =
128125
llvm::unique_dyn_cast<llvm::object::XCOFFObjectFile>(std::move(*binary));
@@ -132,6 +129,7 @@ bool ObjectFileXCOFF::CreateBinary() {
132129
LLDB_LOG(log, "this = {0}, module = {1} ({2}), file = {3}, binary = {4}",
133130
this, GetModule().get(), GetModule()->GetSpecificationDescription(),
134131
m_file.GetPath(), m_binary.get());
132+
135133
return true;
136134
}
137135

@@ -148,21 +146,22 @@ size_t ObjectFileXCOFF::GetModuleSpecifications(
148146
const size_t initial_count = specs.GetSize();
149147

150148
if (ObjectFileXCOFF::MagicBytesMatch(data_sp, 0, data_sp->GetByteSize())) {
151-
ArchSpec arch_spec = ArchSpec(eArchTypeXCOFF, XCOFF::TCPU_PPC64, LLDB_INVALID_CPUTYPE);
149+
ArchSpec arch_spec =
150+
ArchSpec(eArchTypeXCOFF, XCOFF::TCPU_PPC64, LLDB_INVALID_CPUTYPE);
152151
ModuleSpec spec(file, arch_spec);
153-
spec.GetArchitecture().SetArchitecture(eArchTypeXCOFF, XCOFF::TCPU_PPC64, LLDB_INVALID_CPUTYPE, llvm::Triple::AIX);
152+
spec.GetArchitecture().SetArchitecture(eArchTypeXCOFF, XCOFF::TCPU_PPC64,
153+
LLDB_INVALID_CPUTYPE,
154+
llvm::Triple::AIX);
154155
specs.Append(spec);
155156
}
156157
return specs.GetSize() - initial_count;
157158
}
158159

159160
static uint32_t XCOFFHeaderSizeFromMagic(uint32_t magic) {
160161
switch (magic) {
161-
/* TODO: 32bit not supported yet
162-
case XCOFF::XCOFF32:
163-
return sizeof(struct llvm::object::XCOFFFileHeader32);
164-
*/
165-
162+
// TODO: 32bit not supported.
163+
// case XCOFF::XCOFF32:
164+
// return sizeof(struct llvm::object::XCOFFFileHeader32);
166165
case XCOFF::XCOFF64:
167166
return sizeof(struct llvm::object::XCOFFFileHeader64);
168167
break;
@@ -174,10 +173,12 @@ static uint32_t XCOFFHeaderSizeFromMagic(uint32_t magic) {
174173
}
175174

176175
bool ObjectFileXCOFF::MagicBytesMatch(DataBufferSP &data_sp,
177-
lldb::addr_t data_offset,
178-
lldb::addr_t data_length) {
179-
lldb_private::DataExtractor data;
176+
lldb::addr_t data_offset,
177+
lldb::addr_t data_length) {
178+
lldb_private::DataExtractor data;
180179
data.SetData(data_sp, data_offset, data_length);
180+
// Need to set this as XCOFF is only compatible with Big Endian
181+
data.SetByteOrder(eByteOrderBig);
181182
lldb::offset_t offset = 0;
182183
uint16_t magic = data.GetU16(&offset);
183184
return XCOFFHeaderSizeFromMagic(magic) != 0;
@@ -386,13 +387,10 @@ bool ObjectFileXCOFF::SetLoadAddressByType(Target &target, lldb::addr_t value,
386387
return changed;
387388
}
388389

389-
ByteOrder ObjectFileXCOFF::GetByteOrder() const {
390-
return eByteOrderBig;
391-
}
392390

393-
bool ObjectFileXCOFF::IsExecutable() const {
394-
return true;
395-
}
391+
ByteOrder ObjectFileXCOFF::GetByteOrder() const { return eByteOrderBig; }
392+
393+
bool ObjectFileXCOFF::IsExecutable() const { return true; }
396394

397395
uint32_t ObjectFileXCOFF::GetAddressByteSize() const {
398396
if (m_xcoff_header.magic == XCOFF::XCOFF64)
@@ -592,13 +590,12 @@ void ObjectFileXCOFF::Dump(Stream *s) {
592590
}
593591

594592
ArchSpec ObjectFileXCOFF::GetArchitecture() {
595-
ArchSpec arch_spec = ArchSpec(eArchTypeXCOFF, XCOFF::TCPU_PPC64, LLDB_INVALID_CPUTYPE);
593+
ArchSpec arch_spec =
594+
ArchSpec(eArchTypeXCOFF, XCOFF::TCPU_PPC64, LLDB_INVALID_CPUTYPE);
596595
return arch_spec;
597596
}
598597

599-
UUID ObjectFileXCOFF::GetUUID() {
600-
return UUID();
601-
}
598+
UUID ObjectFileXCOFF::GetUUID() { return UUID(); }
602599

603600
std::optional<FileSpec> ObjectFileXCOFF::GetDebugLink() {
604601
return std::nullopt;
@@ -724,16 +721,14 @@ lldb_private::Address ObjectFileXCOFF::GetBaseAddress() {
724721
}
725722

726723
ObjectFile::Type ObjectFileXCOFF::CalculateType() {
727-
if (m_xcoff_header.flags & XCOFF::F_EXEC)
724+
if (m_binary->fileHeader64()->Flags & XCOFF::F_EXEC)
728725
return eTypeExecutable;
729-
else if (m_xcoff_header.flags & XCOFF::F_SHROBJ)
726+
else if (m_binary->fileHeader64()->Flags & XCOFF::F_SHROBJ)
730727
return eTypeSharedLibrary;
731728
return eTypeUnknown;
732729
}
733730

734-
ObjectFile::Strata ObjectFileXCOFF::CalculateStrata() {
735-
return eStrataUnknown;
736-
}
731+
ObjectFile::Strata ObjectFileXCOFF::CalculateStrata() { return eStrataUnknown; }
737732

738733
llvm::StringRef
739734
ObjectFileXCOFF::StripLinkerSymbolAnnotations(llvm::StringRef symbol_name) const {
@@ -752,7 +747,7 @@ ObjectFileXCOFF::GetLoadableData(Target &target) {
752747

753748
lldb::WritableDataBufferSP
754749
ObjectFileXCOFF::MapFileDataWritable(const FileSpec &file, uint64_t Size,
755-
uint64_t Offset) {
750+
uint64_t Offset) {
756751
return FileSystem::Instance().CreateWritableDataBuffer(file.GetPath(), Size,
757752
Offset);
758753
}

lldb/source/Plugins/ObjectFile/XCOFF/ObjectFileXCOFF.h

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
//===-- ObjectFileXCOFF.h --------------------------------------- -*- C++ -*-===//
1+
//===-- ObjectFileXCOFF.h --------------------------------------- -*- C++
2+
//-*-===//
23
//
34
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
45
// See https://llvm.org/LICENSE.txt for license information.
@@ -9,16 +10,14 @@
910
#ifndef LLDB_SOURCE_PLUGINS_OBJECTFILE_XCOFF_OBJECTFILEXCOFF_H
1011
#define LLDB_SOURCE_PLUGINS_OBJECTFILE_XCOFF_OBJECTFILEXCOFF_H
1112

12-
#include <cstdint>
13-
14-
#include <vector>
15-
1613
#include "lldb/Symbol/ObjectFile.h"
1714
#include "lldb/Utility/ArchSpec.h"
1815
#include "lldb/Utility/FileSpec.h"
1916
#include "lldb/Utility/UUID.h"
2017
#include "lldb/lldb-private.h"
2118
#include "llvm/Object/XCOFFObjectFile.h"
19+
#include <cstdint>
20+
#include <vector>
2221

2322
/// \class ObjectFileXCOFF
2423
/// Generic XCOFF object file reader.
@@ -240,4 +239,4 @@ class ObjectFileXCOFF : public lldb_private::ObjectFile {
240239
std::map<std::string, std::vector<std::string>> m_deps_base_members;
241240
};
242241

243-
#endif // LLDB_SOURCE_PLUGINS_OBJECTFILE_ELF_OBJECTFILEELF_H
242+
#endif // LLDB_SOURCE_PLUGINS_OBJECTFILE_XCOFF_OBJECTFILE_H

0 commit comments

Comments
 (0)