Skip to content

Commit

Permalink
[lldb][AIX] 1. Avoid namespace collision on other platforms (llvm#104679
Browse files Browse the repository at this point in the history
)

This PR is in reference to porting LLDB on AIX.

Link to discussions on llvm discourse and github:
1.  https://discourse.llvm.org/t/port-lldb-to-ibm-aix/80640
2.  llvm#101657 

The complete changes for porting are present in this draft PR:
llvm#102601

The changes on this PR are intended to avoid namespace collision for
certain typedefs between lldb and other platforms:
1. tid_t --> lldb::tid_t
2. offset_t --> lldb::offset_t
  • Loading branch information
DhruvSrivastavaX authored Aug 20, 2024
1 parent a6d81cd commit b804516
Show file tree
Hide file tree
Showing 19 changed files with 51 additions and 47 deletions.
6 changes: 3 additions & 3 deletions lldb/source/API/SBBreakpoint.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -342,7 +342,7 @@ uint32_t SBBreakpoint::GetIgnoreCount() const {
return count;
}

void SBBreakpoint::SetThreadID(tid_t tid) {
void SBBreakpoint::SetThreadID(lldb::tid_t tid) {
LLDB_INSTRUMENT_VA(this, tid);

BreakpointSP bkpt_sp = GetSP();
Expand All @@ -353,10 +353,10 @@ void SBBreakpoint::SetThreadID(tid_t tid) {
}
}

tid_t SBBreakpoint::GetThreadID() {
lldb::tid_t SBBreakpoint::GetThreadID() {
LLDB_INSTRUMENT_VA(this);

tid_t tid = LLDB_INVALID_THREAD_ID;
lldb::tid_t tid = LLDB_INVALID_THREAD_ID;
BreakpointSP bkpt_sp = GetSP();
if (bkpt_sp) {
std::lock_guard<std::recursive_mutex> guard(
Expand Down
6 changes: 3 additions & 3 deletions lldb/source/API/SBBreakpointLocation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,7 @@ bool SBBreakpointLocation::GetCommandLineCommands(SBStringList &commands) {
return has_commands;
}

void SBBreakpointLocation::SetThreadID(tid_t thread_id) {
void SBBreakpointLocation::SetThreadID(lldb::tid_t thread_id) {
LLDB_INSTRUMENT_VA(this, thread_id);

BreakpointLocationSP loc_sp = GetSP();
Expand All @@ -313,10 +313,10 @@ void SBBreakpointLocation::SetThreadID(tid_t thread_id) {
}
}

tid_t SBBreakpointLocation::GetThreadID() {
lldb::tid_t SBBreakpointLocation::GetThreadID() {
LLDB_INSTRUMENT_VA(this);

tid_t tid = LLDB_INVALID_THREAD_ID;
lldb::tid_t tid = LLDB_INVALID_THREAD_ID;
BreakpointLocationSP loc_sp = GetSP();
if (loc_sp) {
std::lock_guard<std::recursive_mutex> guard(
Expand Down
4 changes: 2 additions & 2 deletions lldb/source/API/SBBreakpointName.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,7 @@ bool SBBreakpointName::GetAutoContinue() {
return bp_name->GetOptions().IsAutoContinue();
}

void SBBreakpointName::SetThreadID(tid_t tid) {
void SBBreakpointName::SetThreadID(lldb::tid_t tid) {
LLDB_INSTRUMENT_VA(this, tid);

BreakpointName *bp_name = GetBreakpointName();
Expand All @@ -361,7 +361,7 @@ void SBBreakpointName::SetThreadID(tid_t tid) {
UpdateName(*bp_name);
}

tid_t SBBreakpointName::GetThreadID() {
lldb::tid_t SBBreakpointName::GetThreadID() {
LLDB_INSTRUMENT_VA(this);

BreakpointName *bp_name = GetBreakpointName();
Expand Down
15 changes: 8 additions & 7 deletions lldb/source/Expression/DWARFExpression.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -130,9 +130,10 @@ static llvm::Error ReadRegisterValueAsScalar(RegisterContext *reg_ctx,

/// Return the length in bytes of the set of operands for \p op. No guarantees
/// are made on the state of \p data after this call.
static offset_t GetOpcodeDataSize(const DataExtractor &data,
const lldb::offset_t data_offset,
const uint8_t op, const DWARFUnit *dwarf_cu) {
static lldb::offset_t GetOpcodeDataSize(const DataExtractor &data,
const lldb::offset_t data_offset,
const uint8_t op,
const DWARFUnit *dwarf_cu) {
lldb::offset_t offset = data_offset;
switch (op) {
case DW_OP_addr:
Expand Down Expand Up @@ -358,7 +359,7 @@ lldb::addr_t DWARFExpression::GetLocation_DW_OP_addr(const DWARFUnit *dwarf_cu,
error = true;
break;
}
const offset_t op_arg_size =
const lldb::offset_t op_arg_size =
GetOpcodeDataSize(m_data, offset, op, dwarf_cu);
if (op_arg_size == LLDB_INVALID_OFFSET) {
error = true;
Expand Down Expand Up @@ -418,7 +419,7 @@ bool DWARFExpression::Update_DW_OP_addr(const DWARFUnit *dwarf_cu,
m_data.SetData(encoder.GetDataBuffer());
return true;
}
const offset_t op_arg_size =
const lldb::offset_t op_arg_size =
GetOpcodeDataSize(m_data, offset, op, dwarf_cu);
if (op_arg_size == LLDB_INVALID_OFFSET)
break;
Expand All @@ -435,7 +436,7 @@ bool DWARFExpression::ContainsThreadLocalStorage(

if (op == DW_OP_form_tls_address || op == DW_OP_GNU_push_tls_address)
return true;
const offset_t op_arg_size =
const lldb::offset_t op_arg_size =
GetOpcodeDataSize(m_data, offset, op, dwarf_cu);
if (op_arg_size == LLDB_INVALID_OFFSET)
return false;
Expand Down Expand Up @@ -515,7 +516,7 @@ bool DWARFExpression::LinkThreadLocalStorage(
}

if (!decoded_data) {
const offset_t op_arg_size =
const lldb::offset_t op_arg_size =
GetOpcodeDataSize(m_data, offset, op, dwarf_cu);
if (op_arg_size == LLDB_INVALID_OFFSET)
return false;
Expand Down
2 changes: 1 addition & 1 deletion lldb/source/Plugins/ABI/PowerPC/ABISysV_ppc64.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -641,7 +641,7 @@ class ReturnValueExtractor {

DataExtractor de(&raw_data, sizeof(raw_data), m_byte_order, m_addr_size);

offset_t offset = 0;
lldb::offset_t offset = 0;
std::optional<uint64_t> byte_size = type.GetByteSize(m_process_sp.get());
if (!byte_size)
return {};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ DynamicLoaderDarwinKernel::SearchForKernelWithDebugHints(Process *process) {
if (process->ReadMemoryFromInferior (kernel_addresses_64[i], uval, 8, read_err) == 8)
{
DataExtractor data (&uval, 8, process->GetByteOrder(), process->GetAddressByteSize());
offset_t offset = 0;
lldb::offset_t offset = 0;
uint64_t addr = data.GetU64 (&offset);
if (CheckForKernelImageAtAddress(addr, process).IsValid()) {
return addr;
Expand All @@ -270,7 +270,7 @@ DynamicLoaderDarwinKernel::SearchForKernelWithDebugHints(Process *process) {
if (process->ReadMemoryFromInferior (kernel_addresses_32[i], uval, 4, read_err) == 4)
{
DataExtractor data (&uval, 4, process->GetByteOrder(), process->GetAddressByteSize());
offset_t offset = 0;
lldb::offset_t offset = 0;
uint32_t addr = data.GetU32 (&offset);
if (CheckForKernelImageAtAddress(addr, process).IsValid()) {
return addr;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1151,7 +1151,7 @@ DynamicLoaderDarwin::GetThreadLocalData(const lldb::ModuleSP module_sp,
// TLS data for the pthread_key on a specific thread yet. If we have we
// can re-use it since its location will not change unless the process
// execs.
const tid_t tid = thread_sp->GetID();
const lldb::tid_t tid = thread_sp->GetID();
auto tid_pos = m_tid_to_tls_map.find(tid);
if (tid_pos != m_tid_to_tls_map.end()) {
auto tls_pos = tid_pos->second.find(key);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,8 @@ InstrumentationRuntimeMainThreadChecker::GetBacktracesFromExtendedStopInfo(

StructuredData::ObjectSP thread_id_obj =
info->GetObjectForDotSeparatedPath("tid");
tid_t tid = thread_id_obj ? thread_id_obj->GetUnsignedIntegerValue() : 0;
lldb::tid_t tid =
thread_id_obj ? thread_id_obj->GetUnsignedIntegerValue() : 0;

// We gather symbolication addresses above, so no need for HistoryThread to
// try to infer the call addresses.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -770,15 +770,15 @@ std::string InstrumentationRuntimeTSan::GetLocationDescription(
Sprintf("Location is a %ld-byte heap object at 0x%llx", size, addr);
}
} else if (type == "stack") {
tid_t tid = loc->GetAsDictionary()
->GetValueForKey("thread_id")
->GetUnsignedIntegerValue();
lldb::tid_t tid = loc->GetAsDictionary()
->GetValueForKey("thread_id")
->GetUnsignedIntegerValue();

result = Sprintf("Location is stack of thread %d", tid);
} else if (type == "tls") {
tid_t tid = loc->GetAsDictionary()
->GetValueForKey("thread_id")
->GetUnsignedIntegerValue();
lldb::tid_t tid = loc->GetAsDictionary()
->GetValueForKey("thread_id")
->GetUnsignedIntegerValue();

result = Sprintf("Location is TLS of thread %d", tid);
} else if (type == "fd") {
Expand Down Expand Up @@ -948,7 +948,7 @@ static std::string GenerateThreadName(const std::string &path,
if (path == "mops") {
size_t size =
o->GetObjectForDotSeparatedPath("size")->GetUnsignedIntegerValue();
tid_t thread_id =
lldb::tid_t thread_id =
o->GetObjectForDotSeparatedPath("thread_id")->GetUnsignedIntegerValue();
bool is_write =
o->GetObjectForDotSeparatedPath("is_write")->GetBooleanValue();
Expand Down Expand Up @@ -979,15 +979,15 @@ static std::string GenerateThreadName(const std::string &path,
}

if (path == "threads") {
tid_t thread_id =
lldb::tid_t thread_id =
o->GetObjectForDotSeparatedPath("thread_id")->GetUnsignedIntegerValue();
result = Sprintf("Thread %zu created", thread_id);
}

if (path == "locs") {
std::string type = std::string(
o->GetAsDictionary()->GetValueForKey("type")->GetStringValue());
tid_t thread_id =
lldb::tid_t thread_id =
o->GetObjectForDotSeparatedPath("thread_id")->GetUnsignedIntegerValue();
int fd = o->GetObjectForDotSeparatedPath("file_descriptor")
->GetSignedIntegerValue();
Expand All @@ -1007,7 +1007,7 @@ static std::string GenerateThreadName(const std::string &path,
}

if (path == "stacks") {
tid_t thread_id =
lldb::tid_t thread_id =
o->GetObjectForDotSeparatedPath("thread_id")->GetUnsignedIntegerValue();
result = Sprintf("Thread %" PRIu64, thread_id);
}
Expand All @@ -1034,7 +1034,7 @@ static void AddThreadsForPath(const std::string &path,

StructuredData::ObjectSP thread_id_obj =
o->GetObjectForDotSeparatedPath("thread_os_id");
tid_t tid =
lldb::tid_t tid =
thread_id_obj ? thread_id_obj->GetUnsignedIntegerValue() : 0;

ThreadSP new_thread_sp =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,8 @@ InstrumentationRuntimeUBSan::GetBacktracesFromExtendedStopInfo(

StructuredData::ObjectSP thread_id_obj =
info->GetObjectForDotSeparatedPath("tid");
tid_t tid = thread_id_obj ? thread_id_obj->GetUnsignedIntegerValue() : 0;
lldb::tid_t tid =
thread_id_obj ? thread_id_obj->GetUnsignedIntegerValue() : 0;

// We gather symbolication addresses above, so no need for HistoryThread to
// try to infer the call addresses.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ static void CreateHistoryThreadFromValueObject(ProcessSP process_sp,
return;

int count = count_sp->GetValueAsUnsigned(0);
tid_t tid = tid_sp->GetValueAsUnsigned(0) + 1;
lldb::tid_t tid = tid_sp->GetValueAsUnsigned(0) + 1;

if (count <= 0)
return;
Expand Down
7 changes: 4 additions & 3 deletions lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5673,7 +5673,8 @@ bool ObjectFileMachO::GetCorefileMainBinaryInfo(addr_t &value,
return false;
}

bool ObjectFileMachO::GetCorefileThreadExtraInfos(std::vector<tid_t> &tids) {
bool ObjectFileMachO::GetCorefileThreadExtraInfos(
std::vector<lldb::tid_t> &tids) {
tids.clear();
ModuleSP module_sp(GetModule());
if (module_sp) {
Expand Down Expand Up @@ -5724,8 +5725,8 @@ bool ObjectFileMachO::GetCorefileThreadExtraInfos(std::vector<tid_t> &tids) {
return false;
}
StructuredData::Dictionary *thread = *maybe_thread;
tid_t tid = LLDB_INVALID_THREAD_ID;
if (thread->GetValueForKeyAsInteger<tid_t>("thread_id", tid))
lldb::tid_t tid = LLDB_INVALID_THREAD_ID;
if (thread->GetValueForKeyAsInteger<lldb::tid_t>("thread_id", tid))
if (tid == 0)
tid = LLDB_INVALID_THREAD_ID;
tids.push_back(tid);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ ThreadSP OperatingSystemPython::CreateThreadFromThreadInfo(
ThreadList &old_thread_list, std::vector<bool> &core_used_map,
bool *did_create_ptr) {
ThreadSP thread_sp;
tid_t tid = LLDB_INVALID_THREAD_ID;
lldb::tid_t tid = LLDB_INVALID_THREAD_ID;
if (!thread_dict.GetValueForKeyAsInteger("tid", tid))
return ThreadSP();

Expand Down
2 changes: 1 addition & 1 deletion lldb/source/Plugins/Process/Utility/ThreadMemory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
using namespace lldb;
using namespace lldb_private;

ThreadMemory::ThreadMemory(Process &process, tid_t tid,
ThreadMemory::ThreadMemory(Process &process, lldb::tid_t tid,
const ValueObjectSP &thread_info_valobj_sp)
: Thread(process, tid), m_backing_thread_sp(),
m_thread_info_valobj_sp(thread_info_valobj_sp), m_name(), m_queue(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1513,7 +1513,7 @@ bool ProcessGDBRemote::DoUpdateThreadList(ThreadList &old_thread_list,
ThreadList old_thread_list_copy(old_thread_list);
if (num_thread_ids > 0) {
for (size_t i = 0; i < num_thread_ids; ++i) {
tid_t tid = m_thread_ids[i];
lldb::tid_t tid = m_thread_ids[i];
ThreadSP thread_sp(
old_thread_list_copy.RemoveThreadByProtocolID(tid, false));
if (!thread_sp) {
Expand Down
8 changes: 4 additions & 4 deletions lldb/source/Plugins/Process/mach-core/ProcessMachCore.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -593,19 +593,19 @@ bool ProcessMachCore::DoUpdateThreadList(ThreadList &old_thread_list,
ObjectFile *core_objfile = m_core_module_sp->GetObjectFile();

if (core_objfile) {
std::set<tid_t> used_tids;
std::set<lldb::tid_t> used_tids;
const uint32_t num_threads = core_objfile->GetNumThreadContexts();
std::vector<tid_t> tids;
std::vector<lldb::tid_t> tids;
if (core_objfile->GetCorefileThreadExtraInfos(tids)) {
assert(tids.size() == num_threads);

// Find highest tid value.
tid_t highest_tid = 0;
lldb::tid_t highest_tid = 0;
for (uint32_t i = 0; i < num_threads; i++) {
if (tids[i] != LLDB_INVALID_THREAD_ID && tids[i] > highest_tid)
highest_tid = tids[i];
}
tid_t current_unused_tid = highest_tid + 1;
lldb::tid_t current_unused_tid = highest_tid + 1;
for (uint32_t i = 0; i < num_threads; i++) {
if (tids[i] == LLDB_INVALID_THREAD_ID) {
tids[i] = current_unused_tid++;
Expand Down
2 changes: 1 addition & 1 deletion lldb/source/Plugins/SymbolFile/DWARF/DWARFUnit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1023,7 +1023,7 @@ uint32_t DWARFUnit::GetHeaderByteSize() const {

std::optional<uint64_t>
DWARFUnit::GetStringOffsetSectionItem(uint32_t index) const {
offset_t offset = GetStrOffsetsBase() + index * 4;
lldb::offset_t offset = GetStrOffsetsBase() + index * 4;
return m_dwarf.GetDWARFContext().getOrLoadStrOffsetsData().GetU32(&offset);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ lldb::addr_t AppleGetThreadItemInfoHandler::SetupGetThreadItemInfoFunction(

AppleGetThreadItemInfoHandler::GetThreadItemInfoReturnInfo
AppleGetThreadItemInfoHandler::GetThreadItemInfo(Thread &thread,
tid_t thread_id,
lldb::tid_t thread_id,
addr_t page_to_free,
uint64_t page_to_free_size,
Status &error) {
Expand Down
4 changes: 2 additions & 2 deletions lldb/source/Symbol/DWARFCallFrameInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ using namespace lldb_private::dwarf;
// Used for calls when the value type is specified by a DWARF EH Frame pointer
// encoding.
static uint64_t
GetGNUEHPointer(const DataExtractor &DE, offset_t *offset_ptr,
GetGNUEHPointer(const DataExtractor &DE, lldb::offset_t *offset_ptr,
uint32_t eh_ptr_enc, addr_t pc_rel_addr, addr_t text_addr,
addr_t data_addr) //, BSDRelocs *data_relocs) const
{
Expand Down Expand Up @@ -588,7 +588,7 @@ bool DWARFCallFrameInfo::FDEToUnwindPlan(dw_offset_t dwarf_offset,
if (cie->augmentation[0] == 'z') {
uint32_t aug_data_len = (uint32_t)m_cfi_data.GetULEB128(&offset);
if (aug_data_len != 0 && cie->lsda_addr_encoding != DW_EH_PE_omit) {
offset_t saved_offset = offset;
lldb::offset_t saved_offset = offset;
lsda_data_file_address =
GetGNUEHPointer(m_cfi_data, &offset, cie->lsda_addr_encoding,
pc_rel_addr, text_addr, data_addr);
Expand Down

0 comments on commit b804516

Please sign in to comment.