Files
clang-p2996/lldb/source/Host/linux/HostThreadLinux.cpp
Vasileios Kalintiris 747372b91a Do not use pthread_setname_np() if we don't have GLIBC or Android.
Summary:
pthread_setname_np() is a nonstandard GNU extension and isn't available
in every C library. Check before it's usage that GLIBC is available or
that we are targeting Android.

Reviewers: clayborg, ovyalov

Subscribers: lldb-commits

Differential Revision: http://reviews.llvm.org/D13019

llvm-svn: 248280
2015-09-22 14:52:31 +00:00

53 lines
1.4 KiB
C++

//===-- HostThreadLinux.cpp -------------------------------------*- C++ -*-===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
#include "lldb/Core/DataBuffer.h"
#include "lldb/Host/linux/HostThreadLinux.h"
#include "Plugins/Process/Linux/ProcFileReader.h"
#include "llvm/ADT/SmallVector.h"
#include <pthread.h>
using namespace lldb_private;
HostThreadLinux::HostThreadLinux()
: HostThreadPosix()
{
}
HostThreadLinux::HostThreadLinux(lldb::thread_t thread)
: HostThreadPosix(thread)
{
}
void
HostThreadLinux::SetName(lldb::thread_t thread, llvm::StringRef name)
{
#if (defined(__GLIBC__) && defined(_GNU_SOURCE)) || defined(__ANDROID__)
::pthread_setname_np(thread, name.data());
#else
(void) thread;
(void) name;
#endif
}
void
HostThreadLinux::GetName(lldb::thread_t thread, llvm::SmallVectorImpl<char> &name)
{
// Read /proc/$TID/comm file.
lldb::DataBufferSP buf_sp = process_linux::ProcFileReader::ReadIntoDataBuffer(thread, "comm");
const char *comm_str = (const char *)buf_sp->GetBytes();
const char *cr_str = ::strchr(comm_str, '\n');
size_t length = cr_str ? (cr_str - comm_str) : strlen(comm_str);
name.clear();
name.append(comm_str, comm_str + length);
}