Skip to content

Commit 76f0113

Browse files
committed
WIP: [lldb][test] Workaround older systems that lack gettid
Older glibc versions do not have `gettid`. Provide our own `gettid` in these cases. Fixes a build failure caused by #104109.
1 parent 6e0fc15 commit 76f0113

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

lldb/unittests/Process/elf-core/ThreadElfCoreTest.cpp

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,10 @@
2323
#include <mutex>
2424
#include <unistd.h>
2525

26+
#include <sys/syscall.h>
27+
28+
pid_t _workaround_gettid() { return ((pid_t)syscall(SYS_gettid)); }
29+
2630
using namespace lldb_private;
2731

2832
namespace {
@@ -91,7 +95,7 @@ lldb::TargetSP CreateTarget(lldb::DebuggerSP &debugger_sp, ArchSpec &arch) {
9195

9296
lldb::ThreadSP CreateThread(lldb::ProcessSP &process_sp) {
9397
lldb::ThreadSP thread_sp =
94-
std::make_shared<DummyThread>(*process_sp.get(), gettid());
98+
std::make_shared<DummyThread>(*process_sp.get(), _workaround_gettid());
9599
if (thread_sp == nullptr) {
96100
return nullptr;
97101
}
@@ -167,8 +171,8 @@ TEST_F(ElfCoreTest, PopulatePrStatusTest) {
167171
ASSERT_EQ(prstatus_opt->pr_cursig, 0);
168172
ASSERT_EQ(prstatus_opt->pr_sigpend, 0UL);
169173
ASSERT_EQ(prstatus_opt->pr_sighold, 0UL);
170-
ASSERT_EQ(prstatus_opt->pr_pid, static_cast<uint32_t>(gettid()));
174+
ASSERT_EQ(prstatus_opt->pr_pid, static_cast<uint32_t>(_workaround_gettid()));
171175
ASSERT_EQ(prstatus_opt->pr_ppid, static_cast<uint32_t>(getppid()));
172176
ASSERT_EQ(prstatus_opt->pr_pgrp, static_cast<uint32_t>(getpgrp()));
173-
ASSERT_EQ(prstatus_opt->pr_sid, static_cast<uint32_t>(getsid(gettid())));
177+
ASSERT_EQ(prstatus_opt->pr_sid, static_cast<uint32_t>(getsid(_workaround_gettid())));
174178
}

0 commit comments

Comments
 (0)