aboutsummaryrefslogtreecommitdiffstats
path: root/unittests/tools/lldb-server/tests/ThreadIdsInJstopinfoTest.cpp
blob: 6ff777bd17abf428e12c8307c7bc7530587b97f8 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
//===-- 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 "TestBase.h"
#include "TestClient.h"
#include "llvm/Support/Path.h"
#include "llvm/Testing/Support/Error.h"
#include "gtest/gtest.h"
#include <string>

using namespace llgs_tests;
using namespace llvm;

TEST_F(StandardStartupTest, TestStopReplyContainsThreadPcs) {
  // This inferior spawns 4 threads, then forces a break.
  ASSERT_THAT_ERROR(
      Client->SetInferior({getInferiorPath("thread_inferior"), "4"}),
      Succeeded());

  ASSERT_THAT_ERROR(Client->ListThreadsInStopReply(), Succeeded());
  ASSERT_THAT_ERROR(Client->ContinueAll(), Succeeded());
  unsigned int pc_reg = Client->GetPcRegisterId();
  ASSERT_NE(pc_reg, UINT_MAX);

  auto jthreads_info = Client->GetJThreadsInfo();
  ASSERT_TRUE(jthreads_info);

  auto stop_reply = Client->GetLatestStopReplyAs<StopReplyStop>();
  ASSERT_THAT_EXPECTED(stop_reply, Succeeded());
  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.";
    auto pc_value = thread_infos[tid].ReadRegisterAsUint64(pc_reg);
    ASSERT_THAT_EXPECTED(pc_value, Succeeded());
    ASSERT_EQ(stop_reply_pcs[tid], *pc_value)
        << "Mismatched PC for thread: " << tid;
  }
}