1 //===-- HostThreadLinux.cpp -------------------------------------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 #include "lldb/Core/DataBuffer.h"
11 #include "lldb/Host/linux/HostThreadLinux.h"
12 #include "Plugins/Process/Linux/ProcFileReader.h"
14 #include "llvm/ADT/SmallVector.h"
18 using namespace lldb_private;
20 HostThreadLinux::HostThreadLinux()
25 HostThreadLinux::HostThreadLinux(lldb::thread_t thread)
26 : HostThreadPosix(thread)
31 HostThreadLinux::SetName(lldb::thread_t thread, llvm::StringRef name)
33 #if (defined(__GLIBC__) && defined(_GNU_SOURCE)) || defined(__ANDROID__)
34 ::pthread_setname_np(thread, name.data());
42 HostThreadLinux::GetName(lldb::thread_t thread, llvm::SmallVectorImpl<char> &name)
44 // Read /proc/$TID/comm file.
45 lldb::DataBufferSP buf_sp = process_linux::ProcFileReader::ReadIntoDataBuffer(thread, "comm");
46 const char *comm_str = (const char *)buf_sp->GetBytes();
47 const char *cr_str = ::strchr(comm_str, '\n');
48 size_t length = cr_str ? (cr_str - comm_str) : strlen(comm_str);
51 name.append(comm_str, comm_str + length);