1 //===-- ThisThread.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/Host/ThisThread.h"
11 #include "lldb/Core/Error.h"
12 #include "lldb/Host/HostInfo.h"
14 #include "llvm/ADT/STLExtras.h"
19 using namespace lldb_private;
21 void ThisThread::SetName(llvm::StringRef name, int max_length) {
22 std::string truncated_name(name.data());
24 // Thread names are coming in like '<lldb.comm.debugger.edit>' and
25 // '<lldb.comm.debugger.editline>'. So just chopping the end of the string
26 // off leads to a lot of similar named threads. Go through the thread name
27 // and search for the last dot and use that.
30 truncated_name.length() > static_cast<size_t>(max_length)) {
31 // First see if we can get lucky by removing any initial or final braces.
32 std::string::size_type begin = truncated_name.find_first_not_of("(<");
33 std::string::size_type end = truncated_name.find_last_not_of(")>.");
34 if (end - begin > static_cast<size_t>(max_length)) {
35 // We're still too long. Since this is a dotted component, use everything
37 // dot, up to a maximum of |length| characters.
38 std::string::size_type last_dot = truncated_name.rfind('.');
39 if (last_dot != std::string::npos)
42 end = std::min(end, begin + max_length);
45 std::string::size_type count = end - begin + 1;
46 truncated_name = truncated_name.substr(begin, count);
49 SetName(truncated_name);