[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:46:41 PDT 2024


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

Only Linux systems do not have gettid. Provide our own gettid in these cases.

Fixes a build failure caused by #104109.

>From 10bc5a512b56238328b025303345e47708927d6e 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

Only Linux systems do not have gettid. Provide our own gettid in these
cases.

Fixes a build failure caused by #104109.
---
 .../unittests/Process/elf-core/ThreadElfCoreTest.cpp | 12 +++++++++---
 1 file changed, 9 insertions(+), 3 deletions(-)

diff --git a/lldb/unittests/Process/elf-core/ThreadElfCoreTest.cpp b/lldb/unittests/Process/elf-core/ThreadElfCoreTest.cpp
index ce146f62b0d826..5cf5f9718252d5 100644
--- a/lldb/unittests/Process/elf-core/ThreadElfCoreTest.cpp
+++ b/lldb/unittests/Process/elf-core/ThreadElfCoreTest.cpp
@@ -23,6 +23,12 @@
 #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 +97,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 +173,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