1 //===-- ThreadsInJstopinfoTest.cpp ----------------------------------------===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 
9 #include "TestBase.h"
10 #include "TestClient.h"
11 #include "lldb/Utility/DataExtractor.h"
12 #include "llvm/Support/FormatVariadic.h"
13 #include "llvm/Support/Path.h"
14 #include "llvm/Testing/Support/Error.h"
15 #include "gmock/gmock.h"
16 #include "gtest/gtest.h"
17 #include <string>
18 
19 using namespace llgs_tests;
20 using namespace lldb_private;
21 using namespace llvm;
22 using namespace lldb;
23 using namespace testing;
24 
25 #ifdef __NetBSD__
26 #define SKIP_ON_NETBSD(x) DISABLED_ ## x
27 #else
28 #define SKIP_ON_NETBSD(x) x
29 #endif
30 
TEST_F(StandardStartupTest,SKIP_ON_NETBSD (TestStopReplyContainsThreadPcs))31 TEST_F(StandardStartupTest, SKIP_ON_NETBSD(TestStopReplyContainsThreadPcs)) {
32   // This inferior spawns 4 threads, then forces a break.
33   ASSERT_THAT_ERROR(
34       Client->SetInferior({getInferiorPath("thread_inferior"), "4"}),
35       Succeeded());
36 
37   ASSERT_THAT_ERROR(Client->ListThreadsInStopReply(), Succeeded());
38   ASSERT_THAT_ERROR(Client->ContinueAll(), Succeeded());
39   unsigned int pc_reg = Client->GetPcRegisterId();
40   ASSERT_NE(pc_reg, UINT_MAX);
41 
42   auto jthreads_info = Client->GetJThreadsInfo();
43   ASSERT_THAT_EXPECTED(jthreads_info, Succeeded());
44 
45   auto stop_reply = Client->GetLatestStopReplyAs<StopReplyStop>();
46   ASSERT_THAT_EXPECTED(stop_reply, Succeeded());
47   auto stop_reply_pcs = stop_reply->getThreadPcs();
48   auto thread_infos = jthreads_info->GetThreadInfos();
49   ASSERT_EQ(stop_reply_pcs.size(), thread_infos.size())
50       << "Thread count mismatch.";
51 
52   for (auto stop_reply_pc : stop_reply_pcs) {
53     unsigned long tid = stop_reply_pc.first;
54     ASSERT_TRUE(thread_infos.find(tid) != thread_infos.end())
55         << "Thread ID: " << tid << " not in JThreadsInfo.";
56     EXPECT_THAT(thread_infos[tid].ReadRegister(pc_reg),
57                 Pointee(Eq(stop_reply_pc.second)));
58   }
59 }
60