diff options
author | Zachary Turner <zturner@google.com> | 2014-09-09 20:54:56 +0000 |
---|---|---|
committer | Zachary Turner <zturner@google.com> | 2014-09-09 20:54:56 +0000 |
commit | 39de3110712cb4547a835777310dbead46c1a002 (patch) | |
tree | d0f99eb4b7f8ab35272587ad4a0e070675752b54 /lldb/source/Host/linux/HostThreadLinux.cpp | |
parent | 7decae153bdb4b4a98fa48bb27564fa4597d1cfa (diff) | |
download | bcm5719-llvm-39de3110712cb4547a835777310dbead46c1a002.tar.gz bcm5719-llvm-39de3110712cb4547a835777310dbead46c1a002.zip |
Create a HostThread abstraction.
This patch moves creates a thread abstraction that represents a
thread running inside the LLDB process. This is a replacement for
otherwise using lldb::thread_t, and provides a platform agnostic
interface to managing these threads.
Differential Revision: http://reviews.llvm.org/D5198
Reviewed by: Jim Ingham
llvm-svn: 217460
Diffstat (limited to 'lldb/source/Host/linux/HostThreadLinux.cpp')
-rw-r--r-- | lldb/source/Host/linux/HostThreadLinux.cpp | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/lldb/source/Host/linux/HostThreadLinux.cpp b/lldb/source/Host/linux/HostThreadLinux.cpp new file mode 100644 index 00000000000..619bd245ab2 --- /dev/null +++ b/lldb/source/Host/linux/HostThreadLinux.cpp @@ -0,0 +1,47 @@ +//===-- 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) +{ + ::pthread_setname_np(thread, name.data()); +} + +void +HostThreadLinux::GetName(lldb::thread_t thread, llvm::SmallVectorImpl<char> &name) +{ + // Read /proc/$TID/comm file. + lldb::DataBufferSP buf_sp = 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); +} |