jmajors updated this revision to Diff 98691.
jmajors marked an inline comment as done.
jmajors added a comment.

More feedback changes.


https://reviews.llvm.org/D32930

Files:
  unittests/CMakeLists.txt
  unittests/tools/CMakeLists.txt
  unittests/tools/lldb-server/CMakeLists.txt
  unittests/tools/lldb-server/inferior/thread_inferior.cpp
  unittests/tools/lldb-server/tests/CMakeLists.txt
  unittests/tools/lldb-server/tests/MessageObjects.cpp
  unittests/tools/lldb-server/tests/MessageObjects.h
  unittests/tools/lldb-server/tests/TestClient.cpp
  unittests/tools/lldb-server/tests/TestClient.h
  unittests/tools/lldb-server/tests/ThreadIdsInJstopinfoTest.cpp

Index: unittests/tools/lldb-server/tests/ThreadIdsInJstopinfoTest.cpp
===================================================================
--- /dev/null
+++ unittests/tools/lldb-server/tests/ThreadIdsInJstopinfoTest.cpp
@@ -0,0 +1,52 @@
+//===-- ThreadsInJstopinfoTest.cpp ------------------------------*- C++ -*-===//
+//
+//                     The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#include <string>
+
+#include <unistd.h>
+
+#include "gtest/gtest.h"
+#include "TestClient.h"
+
+using namespace CommunicationTests;
+
+TEST(ThreadsInJstopinfoTest, TestStopReplyContainsThreadPcsLlgs) {
+  std::vector<std::string> inferior_args;
+  // This inferior spawns N threads, then forces a break.
+  inferior_args.push_back(THREAD_INFERIOR);
+  inferior_args.push_back("4");
+
+  auto test_info = ::testing::UnitTest::GetInstance()->current_test_info();
+
+  TestClient client(test_info->name(), test_info->test_case_name());
+  client.StartDebugger();
+  client.SetInferior(inferior_args);
+  client.ListThreadsInStopReply();
+  client.Continue();
+  unsigned int pc_reg = client.GetPcRegisterId();
+
+  std::shared_ptr<JThreadsInfo> jthreads_info = client.GetJThreadsInfo();
+  ASSERT_TRUE(jthreads_info.get()) << "Error reading JThreadInfo.";
+
+  auto stop_reply = client.GetLatestStopReply();
+  auto stop_reply_pcs = stop_reply->GetThreadPcs();
+  auto thread_infos = jthreads_info->GetThreadInfos();
+  ASSERT_EQ(stop_reply_pcs.size(), thread_infos.size())
+    << "Thread count mismatch.";
+
+  for (auto stop_reply_pc : stop_reply_pcs) {
+    unsigned long tid = stop_reply_pc.first;
+    ASSERT_TRUE(thread_infos.find(tid) != thread_infos.end())
+      << "Thread ID: " << tid << " not in JThreadsInfo.";
+    ASSERT_EQ(stop_reply_pcs[tid], thread_infos[tid].ReadRegister(pc_reg))
+      << "Mismatched PC for thread: " << tid;
+  }
+
+  client.StopDebugger();
+}
Index: unittests/tools/lldb-server/tests/TestClient.h
===================================================================
--- /dev/null
+++ unittests/tools/lldb-server/tests/TestClient.h
@@ -0,0 +1,55 @@
+//===-- TestClient.h --------------------------------------------*- C++ -*-===//
+//
+//                     The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#include <memory>
+#include <string>
+
+#include "lldb/Core/ArchSpec.h"
+#include "lldb/Target/ProcessLaunchInfo.h"
+
+#include "Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.h"
+
+#include "MessageObjects.h"
+
+namespace CommunicationTests {
+// TODO: Make the test client an abstract base class, with different children
+// for different types of connections: llgs v. debugserver
+class TestClient :
+  public lldb_private::process_gdb_remote::GDBRemoteCommunicationClient {
+public:
+  TestClient(const std::string& test_name, const std::string& test_case_name);
+  virtual ~TestClient();
+  void StartDebugger();
+  void StopDebugger();
+  void SetInferior(llvm::ArrayRef<std::string> inferior_args);
+  void ListThreadsInStopReply();
+  void SetBreakpoint(unsigned long address);
+  void Continue(unsigned long thread_id = 0);
+  std::shared_ptr<ProcessInfo> GetProcessInfo();
+  std::shared_ptr<JThreadsInfo> GetJThreadsInfo();
+  std::shared_ptr<StopReply> GetLatestStopReply();
+  void SendMessage(const std::string& message);
+  void SendMessage(const std::string& message, std::string& response_string);
+  unsigned int GetPcRegisterId();
+
+private:
+  void GenerateConnectionAddress(std::string& address);
+  std::string GenerateLogFileName(const lldb_private::ArchSpec& arch) const;
+  std::string FormatFailedResult(const std::string& message,
+      lldb_private::process_gdb_remote::GDBRemoteCommunication::PacketResult
+      result);
+
+  std::shared_ptr<ProcessInfo> process_info;
+  std::shared_ptr<StopReply> stop_reply;
+  lldb_private::ProcessLaunchInfo server_process_info;
+  std::string test_name;
+  std::string test_case_name;
+  unsigned int pc_register;
+};
+}
Index: unittests/tools/lldb-server/tests/TestClient.cpp
===================================================================
--- /dev/null
+++ unittests/tools/lldb-server/tests/TestClient.cpp
@@ -0,0 +1,231 @@
+//===-- TestClient.cpp ------------------------------------------*- C++ -*-===//
+//
+//                     The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#include <cstdlib>
+#include <iostream>
+#include <sstream>
+#include <string>
+#include <future>
+
+#include <sys/stat.h>
+#include <sys/types.h>
+
+#include "gtest/gtest.h"
+#include "TestClient.h"
+
+#include "lldb/Core/ArchSpec.h"
+#include "lldb/Host/common/TCPSocket.h"
+#include "lldb/Host/HostInfo.h"
+#include "lldb/Host/posix/ConnectionFileDescriptorPosix.h"
+#include "lldb/Host/posix/ProcessLauncherPosix.h"
+#include "lldb/Interpreter/Args.h"
+#include "lldb/Target/ProcessLaunchInfo.h"
+#include "llvm/ADT/StringExtras.h"
+
+using namespace lldb;
+using namespace lldb_private;
+using namespace llvm;
+
+namespace CommunicationTests {
+const char* LOCALHOST = "127.0.0.1";
+
+TestClient::TestClient(const std::string& test_name,
+                       const std::string& test_case_name)
+: test_name(test_name), test_case_name(test_case_name), pc_register(UINT_MAX) {
+  HostInfo::Initialize();
+}
+
+TestClient::~TestClient() {
+}
+
+void TestClient::StartDebugger() {
+  const ArchSpec& arch_spec = HostInfo::GetArchitecture();
+  Args args;
+  args.AppendArgument(LLDB_SERVER);
+  args.AppendArgument("gdbserver");
+  args.AppendArgument("--log-file=" + GenerateLogFileName(arch_spec));
+  args.AppendArgument("--log-channels=gdb-remote packets");
+  args.AppendArgument("--reverse-connect");
+  std::string connectionAddress;
+  GenerateConnectionAddress(connectionAddress);
+
+  args.AppendArgument(connectionAddress);
+  server_process_info.SetArchitecture(arch_spec);
+  server_process_info.SetArguments(args, true);
+  Error error = Host::LaunchProcess(server_process_info);
+  ASSERT_FALSE(error.Fail())
+    << "Failure to launch lldb server: " << error.AsCString();
+
+  sleep(5); // TODO: Sleep is bad. Can I wait for it to start?
+  SendAck(); // Send this as a handshake.
+}
+
+// TODO!!!!!!!!!!!!!!!!!!!!
+// Trace the quit command in the debugger, with a breakpoint at
+// SendPacketAndWaitForResponse() to see what command it sends to
+// the server to stop it.
+void TestClient::StopDebugger() {
+  Host::Kill(server_process_info.GetProcessID(), 15);
+}
+
+void TestClient::SetInferior(llvm::ArrayRef<std::string> inferior_args) {
+  std::stringstream command;
+  command << "A";
+  for (size_t i = 0; i < inferior_args.size(); i++) {
+    if (i > 0) command << ',';
+    std::string hex_encoded = toHex(inferior_args[i]);
+    command << hex_encoded.size() << ',' << i << ',' << hex_encoded;
+  }
+  
+  SendMessage(command.str());
+  SendMessage("qLaunchSuccess");
+  std::string response;
+  SendMessage("qProcessInfo", response);
+  process_info.reset(new ProcessInfo(response));
+}
+
+void TestClient::ListThreadsInStopReply() {
+  SendMessage("QListThreadsInStopReply");
+}
+
+void TestClient::SetBreakpoint(unsigned long address) {
+  std::stringstream command;
+  command << "Z0," << std::hex << address << ",1";
+  SendMessage(command.str());
+}
+
+void TestClient::Continue(unsigned long thread_id) {
+  ASSERT_TRUE(process_info.get())
+    << "Continue() called before process_info initialized.";
+
+  if (thread_id == 0) {
+    thread_id = process_info->GetPid();
+  }
+
+  std::stringstream message;
+  message << "vCont;c:" << std::hex << thread_id;
+  std::string response;
+  SendMessage(message.str(), response);
+  stop_reply = StopReply::Create(response, process_info->GetEndian());
+  ASSERT_TRUE(stop_reply.get()) << "Failure reading stop reply.";
+}
+
+std::shared_ptr<ProcessInfo> TestClient::GetProcessInfo() {
+  return process_info;
+}
+
+std::shared_ptr<JThreadsInfo> TestClient::GetJThreadsInfo() {
+  std::string response;
+  SendMessage("jThreadsInfo", response);
+  return JThreadsInfo::Create(response, process_info->GetEndian());
+}
+
+std::shared_ptr<StopReply> TestClient::GetLatestStopReply() {
+  return stop_reply;
+}
+
+void TestClient::SendMessage(const std::string& message) {
+  std::string dummy_string;
+  SendMessage(message, dummy_string);
+}
+
+void TestClient::SendMessage(const std::string& message,
+                             std::string& response_string) {
+  StringExtractorGDBRemote response;
+  PacketResult result = SendPacketAndWaitForResponse(message, response, false);
+  ASSERT_EQ(result, PacketResult::Success)
+    << FormatFailedResult(message, result);
+
+  response.GetEscapedBinaryData(response_string);
+  ASSERT_NE(response_string[0], 'E')
+    << "Error " << response_string << " while sending message: " << message;
+}
+
+unsigned int TestClient::GetPcRegisterId() {
+  if (pc_register != UINT_MAX) {
+    return pc_register;
+  }
+
+  for (unsigned int register_id = 0; ; register_id++) {
+    std::stringstream message;
+    message << "qRegisterInfo" << std::hex << register_id;
+    // This will throw if we scan all registers and never get the 
+    // expected result. Is that okay? Or is there a situation where
+    // no result is valid?
+    std::string response;
+    SendMessage(message.str(), response);
+    auto elements = SplitPairList(response);
+    if (elements["alt-name"] == "pc" || elements["generic"] == "pc") {
+      pc_register = register_id;
+      break;
+    }
+  }
+
+  return pc_register;
+}
+
+void TestClient::GenerateConnectionAddress(std::string& address) {
+  StartListenThread(LOCALHOST, 0);
+  auto connection = (ConnectionFileDescriptor*)GetConnection();
+  uint16_t listening_port = connection->GetListeningPort(UINT32_MAX);
+  ASSERT_GT(listening_port, 0) << "GetListeningPort failed.";
+
+  raw_string_ostream address_stream(address);
+  address_stream << LOCALHOST << ":" << listening_port;
+  address_stream.str();
+}
+
+std::string TestClient::GenerateLogFileName(const ArchSpec& arch) const {
+  std::string log_file_name;
+  raw_string_ostream log_file(log_file_name);
+  log_file << "lldb-test-traces/lldb-" << test_case_name << '-' << test_name
+           << '-' << arch.GetArchitectureName() << ".log";
+  log_file.str();
+  return log_file_name;
+}
+
+std::string TestClient::FormatFailedResult(const std::string& message,
+                                      PacketResult result) {
+  std::string formatted_error;
+  raw_string_ostream error_stream(formatted_error);
+  error_stream << "Failure sending message: " << message << " Result: ";
+    
+  switch (result) {
+  case PacketResult::ErrorSendFailed:
+    error_stream << "ErrorSendFailed";
+    break;
+  case PacketResult::ErrorSendAck:
+    error_stream << "ErrorSendAck";
+    break;
+  case PacketResult::ErrorReplyFailed:
+    error_stream << "ErrorReplyFailed";
+    break;
+  case PacketResult::ErrorReplyTimeout:
+    error_stream << "ErrorReplyTimeout";
+    break;
+  case PacketResult::ErrorReplyInvalid:
+    error_stream << "ErrorReplyInvalid";
+    break;
+  case PacketResult::ErrorReplyAck:
+    error_stream << "ErrorReplyAck";
+    break;
+  case PacketResult::ErrorDisconnected:
+    error_stream << "ErrorDisconnected";
+    break;
+  case PacketResult::ErrorNoSequenceLock:
+    error_stream << "ErrorNoSequenceLock";
+    break;
+  default:
+    error_stream << "Unknown Error";
+  }
+
+  error_stream.str();
+  return formatted_error;
+}
+}
Index: unittests/tools/lldb-server/tests/MessageObjects.h
===================================================================
--- /dev/null
+++ unittests/tools/lldb-server/tests/MessageObjects.h
@@ -0,0 +1,84 @@
+#include <memory>
+#include <string>
+#include <vector>
+
+#include "lldb/lldb-types.h"
+#include "llvm/Support/Endian.h"
+#include "llvm/ADT/DenseMap.h"
+
+namespace CommunicationTests {
+  class ThreadInfo;
+  typedef llvm::DenseMap<unsigned long, ThreadInfo> ThreadInfoMap;
+  typedef llvm::DenseMap<unsigned long, unsigned long> ULongMap;
+
+class ProcessInfo {
+public:
+  explicit ProcessInfo(llvm::StringRef response);
+  pid_t GetPid() const;
+  llvm::support::endianness GetEndian() const;
+
+private:
+  pid_t pid;
+  pid_t parent_pid;
+  uid_t real_uid;
+  unsigned int real_gid;
+  uid_t effective_uid;
+  unsigned int effective_gid;
+  std::string triple;
+  llvm::SmallString<16> ostype;
+  llvm::support::endianness endian;
+  unsigned int ptrsize;
+};
+
+class ThreadInfo {
+public:
+  ThreadInfo();
+  explicit ThreadInfo(llvm::StringRef name, llvm::StringRef reason,
+                      const ULongMap& registers, unsigned int signal);
+
+  unsigned long ReadRegister(unsigned long register_id) const;
+
+private:
+  llvm::StringRef name;
+  llvm::StringRef reason;
+  ULongMap registers;
+  unsigned int signal;
+};
+
+class JThreadsInfo {
+public:
+  static std::shared_ptr<JThreadsInfo> Create(llvm::StringRef response,
+                                         llvm::support::endianness endian);
+
+  const ThreadInfoMap& GetThreadInfos() const;
+
+protected:
+  JThreadsInfo();
+
+private:
+  ThreadInfoMap thread_infos;
+};
+
+class StopReply {
+public:
+  static std::shared_ptr<StopReply> Create(llvm::StringRef response,
+                                           llvm::support::endianness endian);
+  const ULongMap& GetThreadPcs() const;
+
+protected:
+  StopReply();
+
+private:
+  void ParseResponse(llvm::StringRef response,
+                     llvm::support::endianness endian);
+  unsigned int signal;
+  lldb::tid_t thread;
+  llvm::StringRef name;
+  ULongMap thread_pcs;
+  ULongMap registers;
+  llvm::StringRef reason;
+};
+
+// Common functions for parsing packet data.
+llvm::StringMap<llvm::StringRef> SplitPairList(llvm::StringRef s);
+}
Index: unittests/tools/lldb-server/tests/MessageObjects.cpp
===================================================================
--- /dev/null
+++ unittests/tools/lldb-server/tests/MessageObjects.cpp
@@ -0,0 +1,204 @@
+#include <iomanip>
+#include <sstream>
+
+#include "lldb/Core/StructuredData.h"
+#include "llvm/ADT/StringExtras.h"
+
+#include "gtest/gtest.h"
+#include "MessageObjects.h"
+
+using namespace lldb_private;
+using namespace llvm;
+using namespace llvm::support;
+namespace CommunicationTests {
+ProcessInfo::ProcessInfo(StringRef response) {
+  auto elements = SplitPairList(response);
+  elements["pid"].getAsInteger(16, pid);
+  elements["parent-pid"].getAsInteger(16, parent_pid);
+  elements["real-uid"].getAsInteger(16, real_uid);
+  elements["real-gid"].getAsInteger(16, real_gid);
+  elements["effective-uid"].getAsInteger(16, effective_uid);
+  elements["effective-gid"].getAsInteger(16, effective_gid);
+  triple = fromHex(elements["triple"]);
+  elements["ptrsize"].getAsInteger(10, ptrsize);
+  endian = llvm::StringSwitch<endianness>(elements["endian"])
+    .Case("little", support::little)
+    .Case("big", support::big)
+    .Default(support::native);
+}
+
+pid_t ProcessInfo::GetPid() const {
+  return pid;
+}
+
+endianness ProcessInfo::GetEndian() const {
+  return endian;
+}
+
+//====== ThreadInfo ============================================================
+ThreadInfo::ThreadInfo() {
+  // For map [] operators.
+}
+
+ThreadInfo::ThreadInfo(StringRef name, StringRef reason,
+                       const ULongMap& registers, unsigned int signal) :
+  name(name), reason(reason), registers(registers), signal(signal) {
+}
+
+unsigned long ThreadInfo::ReadRegister(unsigned long register_id) const {
+  return registers.lookup(register_id);
+}
+
+//====== JThreadsInfo ==========================================================
+std::shared_ptr<JThreadsInfo>
+JThreadsInfo::Create(StringRef response, endianness endian) {
+  std::shared_ptr<JThreadsInfo> jthreads_info =
+    std::shared_ptr<JThreadsInfo>(new JThreadsInfo);
+
+  StructuredData::ObjectSP json = StructuredData::ParseJSON(response);
+  StructuredData::Array* array = json->GetAsArray();
+  if (!array) {
+    return std::shared_ptr<JThreadsInfo>(nullptr);
+  }
+
+  for (size_t i = 0; i < array->GetSize(); i++) {
+    StructuredData::Dictionary* thread_info;
+    array->GetItemAtIndexAsDictionary(i, thread_info);
+    if (!thread_info) {
+      return std::shared_ptr<JThreadsInfo>(nullptr);
+    }
+
+    std::string name;
+    thread_info->GetValueForKeyAsString("name", name);
+    std::string reason;
+    thread_info->GetValueForKeyAsString("reason", reason);
+    unsigned long signal;
+    thread_info->GetValueForKeyAsInteger("signal", signal);
+    unsigned long tid;
+    thread_info->GetValueForKeyAsInteger("tid", tid);
+
+    StructuredData::Dictionary* register_dict;
+    thread_info->GetValueForKeyAsDictionary("registers", register_dict);
+    if (!register_dict) {
+      return std::shared_ptr<JThreadsInfo>(nullptr);
+    }
+
+    ULongMap registers;
+
+    auto keys_obj = register_dict->GetKeys();
+    auto keys = keys_obj->GetAsArray();
+    for (size_t i = 0; i < keys->GetSize(); i++) {
+      std::string key_str;
+      keys->GetItemAtIndexAsString(i, key_str);
+      std::string value_str;
+      register_dict->GetValueForKeyAsString(key_str, value_str);
+      StringRef key_str_ref(key_str);
+      StringRef value_str_ref(value_str);
+      unsigned int register_id;
+      if (key_str_ref.getAsInteger(10, register_id)) {
+        return std::shared_ptr<JThreadsInfo>(nullptr);
+      }
+      
+      unsigned long register_value;
+      if (value_str_ref.getAsInteger(16, register_value)) {
+        return std::shared_ptr<JThreadsInfo>(nullptr);
+      }
+      if (endian == little) {
+        sys::swapByteOrder(register_value);
+      }
+
+      registers[register_id] = register_value;
+    }
+
+    jthreads_info->thread_infos[tid] =
+      ThreadInfo(name, reason, registers, signal);
+  }
+
+  return jthreads_info;
+}
+
+const ThreadInfoMap& JThreadsInfo::GetThreadInfos() const {
+  return thread_infos;
+}
+
+JThreadsInfo::JThreadsInfo() {
+}
+
+//====== StopReply =============================================================
+StopReply::StopReply() {
+}
+
+const ULongMap& StopReply::GetThreadPcs() const {
+  return thread_pcs;
+}
+
+std::shared_ptr<StopReply> StopReply::Create(StringRef response,
+    llvm::support::endianness endian) {
+  auto stop_reply = std::shared_ptr<StopReply>(new StopReply());
+
+  auto elements = SplitPairList(response);
+  stop_reply->name = elements["name"];
+  stop_reply->reason = elements["reason"];
+
+  SmallVector<StringRef, 20> threads;
+  SmallVector<StringRef, 20> pcs;
+  elements["threads"].split(threads, ',');
+  elements["thread-pcs"].split(pcs, ',');
+  if (threads.size() != pcs.size()) {
+    return std::shared_ptr<StopReply>(nullptr);
+  }
+
+  for (unsigned int i = 0; i < threads.size(); i++) {
+    lldb::tid_t thread_id;
+    unsigned long pc;
+    threads[i].getAsInteger(16, thread_id);
+    pcs[i].getAsInteger(16, pc);
+    stop_reply->thread_pcs[thread_id] = pc;
+  }
+
+  unsigned int register_id = 0;
+  while (true) {
+    std::stringstream ss;
+    ss << std::hex << std::setw(2) << std::setfill('0') << register_id;
+    std::string hex_id = ss.str();
+    if (elements.find(hex_id) != elements.end()) {
+      unsigned long register_value;
+      if (elements[hex_id].getAsInteger(16, register_value)) {
+        return std::shared_ptr<StopReply>(nullptr);
+      }
+      if (endian == little) {
+        sys::swapByteOrder(register_value);
+      }
+
+      stop_reply->registers[register_id++] = register_value;
+    }
+    else {
+      break;
+    }
+  }
+
+  for (auto i = elements.begin(); i != elements.end(); i++) {
+    StringRef key = i->getKey();
+    StringRef val = i->getValue();
+    if (key.size() >= 9 && key[0] == 'T' && key.substr(3, 6) == "thread") {
+      val.getAsInteger(16, stop_reply->thread);
+      key.substr(1, 2).getAsInteger(16, stop_reply->signal);
+    }
+  }
+
+  return stop_reply;
+}
+
+//====== Globals ===============================================================
+StringMap<StringRef> SplitPairList(StringRef str) {
+  SmallVector<StringRef, 20> elements;
+  str.split(elements, ';');
+
+  StringMap<StringRef> pairs;
+  for (StringRef s : elements) {
+    pairs.insert(s.split(':'));
+  }
+
+  return pairs;
+}
+}
Index: unittests/tools/lldb-server/tests/CMakeLists.txt
===================================================================
--- /dev/null
+++ unittests/tools/lldb-server/tests/CMakeLists.txt
@@ -0,0 +1,15 @@
+add_lldb_unittest(LLDBServerTests
+  TestClient.cpp
+  MessageObjects.cpp
+  ThreadIdsInJstopinfoTest.cpp
+
+  LINK_LIBS
+    lldbHost
+    lldbCore
+    lldbInterpreter
+    lldbTarget
+    lldbPluginPlatformLinux
+    lldbPluginProcessGDBRemote
+  LINK_COMPONENTS
+    Support
+  )
Index: unittests/tools/lldb-server/inferior/thread_inferior.cpp
===================================================================
--- /dev/null
+++ unittests/tools/lldb-server/inferior/thread_inferior.cpp
@@ -0,0 +1,28 @@
+#include <unistd.h>
+#include <string>
+#include <thread>
+#include <vector>
+
+#include "llvm/Support/Compiler.h"
+
+int main(int argc, char* argv[])
+{
+  int thread_count = 2;
+  if (argc > 1) {
+    thread_count = std::stoi(argv[1], nullptr, 10);
+  }
+
+  bool delay = true;
+  std::vector<std::thread> threads;
+  for (int i = 0; i < thread_count; i++) {
+    threads.push_back(std::thread([&delay]{while(delay);}));
+  }
+
+  LLVM_BUILTIN_DEBUGTRAP;
+  delay = false;
+  for (std::thread& t : threads) {
+    t.join();
+  }
+
+  return 0;
+}
Index: unittests/tools/lldb-server/CMakeLists.txt
===================================================================
--- /dev/null
+++ unittests/tools/lldb-server/CMakeLists.txt
@@ -0,0 +1,13 @@
+function(add_lldb_test_executable test_name)
+  set(EXCLUDE_FROM_ALL ON)
+  add_llvm_executable(${test_name} NO_INSTALL_RPATH ${ARGN})
+  set(outdir ${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_CFG_INTDIR})
+  set_output_directory(${test_name} BINARY_DIR ${outdir} LIBRARY_DIR ${outdir})
+endfunction()
+
+add_lldb_test_executable(thread_inferior inferior/thread_inferior.cpp)
+
+add_definitions(-DLLDB_SERVER="$<TARGET_FILE:lldb-server>")
+add_definitions(-DTHREAD_INFERIOR="${CMAKE_CURRENT_BINARY_DIR}/thread_inferior")
+add_subdirectory(tests)
+add_dependencies(LLDBServerTests thread_inferior)
Index: unittests/tools/CMakeLists.txt
===================================================================
--- /dev/null
+++ unittests/tools/CMakeLists.txt
@@ -0,0 +1 @@
+add_subdirectory(lldb-server)
Index: unittests/CMakeLists.txt
===================================================================
--- unittests/CMakeLists.txt
+++ unittests/CMakeLists.txt
@@ -68,9 +68,10 @@
 add_subdirectory(Symbol)
 add_subdirectory(SymbolFile)
 add_subdirectory(Target)
+add_subdirectory(tools)
 add_subdirectory(UnwindAssembly)
 add_subdirectory(Utility)
 
 if(LLDB_CAN_USE_DEBUGSERVER)
   add_subdirectory(debugserver)
-endif()
\ No newline at end of file
+endif()
_______________________________________________
lldb-commits mailing list
lldb-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits

Reply via email to