[Lldb-commits] [lldb] WIP: [lldb][test] Workaround older systems that lack gettid (PR #104831)

Will Hawkins via lldb-commits lldb-commits at lists.llvm.org
Mon Aug 19 11:51:38 PDT 2024


https://github.com/hawkinsw updated https://github.com/llvm/llvm-project/pull/104831

>From 76f01132b7667be48967b8d9788f610cf1a539d4 Mon Sep 17 00:00:00 2001
From: Will Hawkins <hawkinsw at obs.cr>
Date: Mon, 19 Aug 2024 14:43:45 -0400
Subject: [PATCH] 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.
---
 lldb/unittests/Process/elf-core/ThreadElfCoreTest.cpp | 10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)

diff --git a/lldb/unittests/Process/elf-core/ThreadElfCoreTest.cpp b/lldb/unittests/Process/elf-core/ThreadElfCoreTest.cpp
index ce146f62b0d826..fc952ff42a91fb 100644
--- a/lldb/unittests/Process/elf-core/ThreadElfCoreTest.cpp
+++ b/lldb/unittests/Process/elf-core/ThreadElfCoreTest.cpp
@@ -23,6 +23,10 @@
 #include <mutex>
 #include <unistd.h>
 
+#include <sys/syscall.h>
+
+pid_t _workaround_gettid() { return ((pid_t)syscall(SYS_gettid)); }
+
 using namespace lldb_private;
 
 namespace {
@@ -91,7 +95,7 @@ lldb::TargetSP CreateTarget(lldb::DebuggerSP &debugger_sp, ArchSpec &arch) {
 
 lldb::ThreadSP CreateThread(lldb::ProcessSP &process_sp) {
   lldb::ThreadSP thread_sp =
-      std::make_shared<DummyThread>(*process_sp.get(), gettid());
+      std::make_shared<DummyThread>(*process_sp.get(), _workaround_gettid());
   if (thread_sp == nullptr) {
     return nullptr;
   }
@@ -167,8 +171,8 @@ TEST_F(ElfCoreTest, PopulatePrStatusTest) {
   ASSERT_EQ(prstatus_opt->pr_cursig, 0);
   ASSERT_EQ(prstatus_opt->pr_sigpend, 0UL);
   ASSERT_EQ(prstatus_opt->pr_sighold, 0UL);
-  ASSERT_EQ(prstatus_opt->pr_pid, static_cast<uint32_t>(gettid()));
+  ASSERT_EQ(prstatus_opt->pr_pid, static_cast<uint32_t>(_workaround_gettid()));
   ASSERT_EQ(prstatus_opt->pr_ppid, static_cast<uint32_t>(getppid()));
   ASSERT_EQ(prstatus_opt->pr_pgrp, static_cast<uint32_t>(getpgrp()));
-  ASSERT_EQ(prstatus_opt->pr_sid, static_cast<uint32_t>(getsid(gettid())));
+  ASSERT_EQ(prstatus_opt->pr_sid, static_cast<uint32_t>(getsid(_workaround_gettid())));
 }



More information about the lldb-commits mailing list