blob: 8a3dac37dd95ba5cb0affa30ba94b50f5124158b [file] [log] [blame]
Pavel Labath015f17d2017-06-06 13:40:18 +00001//===-- ThreadsInJstopinfoTest.cpp ------------------------------*- C++ -*-===//
2//
Chandler Carruth2946cd72019-01-19 08:50:56 +00003// 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
Pavel Labath015f17d2017-06-06 13:40:18 +00006//
7//===----------------------------------------------------------------------===//
8
Pavel Labath671d3e62017-12-15 13:56:22 +00009#include "TestBase.h"
Pavel Labath015f17d2017-06-06 13:40:18 +000010#include "TestClient.h"
Pavel Labath9a9556f2018-02-19 15:42:48 +000011#include "lldb/Utility/DataExtractor.h"
12#include "llvm/Support/FormatVariadic.h"
Pavel Labath671d3e62017-12-15 13:56:22 +000013#include "llvm/Support/Path.h"
Pavel Labath1ebc85f2017-11-09 15:45:09 +000014#include "llvm/Testing/Support/Error.h"
Pavel Labath9a9556f2018-02-19 15:42:48 +000015#include "gmock/gmock.h"
Pavel Labath015f17d2017-06-06 13:40:18 +000016#include "gtest/gtest.h"
17#include <string>
18
19using namespace llgs_tests;
Pavel Labath9a9556f2018-02-19 15:42:48 +000020using namespace lldb_private;
Pavel Labath671d3e62017-12-15 13:56:22 +000021using namespace llvm;
Pavel Labath9a9556f2018-02-19 15:42:48 +000022using namespace lldb;
23using namespace testing;
Pavel Labath015f17d2017-06-06 13:40:18 +000024
Pavel Labath671d3e62017-12-15 13:56:22 +000025TEST_F(StandardStartupTest, TestStopReplyContainsThreadPcs) {
26 // This inferior spawns 4 threads, then forces a break.
27 ASSERT_THAT_ERROR(
28 Client->SetInferior({getInferiorPath("thread_inferior"), "4"}),
29 Succeeded());
Pavel Labath015f17d2017-06-06 13:40:18 +000030
Pavel Labath671d3e62017-12-15 13:56:22 +000031 ASSERT_THAT_ERROR(Client->ListThreadsInStopReply(), Succeeded());
32 ASSERT_THAT_ERROR(Client->ContinueAll(), Succeeded());
33 unsigned int pc_reg = Client->GetPcRegisterId();
Pavel Labath015f17d2017-06-06 13:40:18 +000034 ASSERT_NE(pc_reg, UINT_MAX);
35
Pavel Labath671d3e62017-12-15 13:56:22 +000036 auto jthreads_info = Client->GetJThreadsInfo();
Pavel Labath9a9556f2018-02-19 15:42:48 +000037 ASSERT_THAT_EXPECTED(jthreads_info, Succeeded());
Pavel Labath015f17d2017-06-06 13:40:18 +000038
Pavel Labath93a582c2017-12-15 15:19:45 +000039 auto stop_reply = Client->GetLatestStopReplyAs<StopReplyStop>();
40 ASSERT_THAT_EXPECTED(stop_reply, Succeeded());
41 auto stop_reply_pcs = stop_reply->getThreadPcs();
Pavel Labath015f17d2017-06-06 13:40:18 +000042 auto thread_infos = jthreads_info->GetThreadInfos();
43 ASSERT_EQ(stop_reply_pcs.size(), thread_infos.size())
44 << "Thread count mismatch.";
45
46 for (auto stop_reply_pc : stop_reply_pcs) {
47 unsigned long tid = stop_reply_pc.first;
48 ASSERT_TRUE(thread_infos.find(tid) != thread_infos.end())
49 << "Thread ID: " << tid << " not in JThreadsInfo.";
Pavel Labath9a9556f2018-02-19 15:42:48 +000050 EXPECT_THAT(thread_infos[tid].ReadRegister(pc_reg),
51 Pointee(Eq(stop_reply_pc.second)));
Pavel Labath015f17d2017-06-06 13:40:18 +000052 }
Pavel Labath015f17d2017-06-06 13:40:18 +000053}