blob: efc9517bc4b4740df7d902d77a3ebb8b3fa72d71 [file] [log] [blame]
Pavel Labath015f17d2017-06-06 13:40:18 +00001//===-- ThreadsInJstopinfoTest.cpp ------------------------------*- C++ -*-===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9
Pavel Labath671d3e62017-12-15 13:56:22 +000010#include "TestBase.h"
Pavel Labath015f17d2017-06-06 13:40:18 +000011#include "TestClient.h"
Pavel Labath9a9556f2018-02-19 15:42:48 +000012#include "lldb/Utility/DataExtractor.h"
13#include "llvm/Support/FormatVariadic.h"
Pavel Labath671d3e62017-12-15 13:56:22 +000014#include "llvm/Support/Path.h"
Pavel Labath1ebc85f2017-11-09 15:45:09 +000015#include "llvm/Testing/Support/Error.h"
Pavel Labath9a9556f2018-02-19 15:42:48 +000016#include "gmock/gmock.h"
Pavel Labath015f17d2017-06-06 13:40:18 +000017#include "gtest/gtest.h"
18#include <string>
19
20using namespace llgs_tests;
Pavel Labath9a9556f2018-02-19 15:42:48 +000021using namespace lldb_private;
Pavel Labath671d3e62017-12-15 13:56:22 +000022using namespace llvm;
Pavel Labath9a9556f2018-02-19 15:42:48 +000023using namespace lldb;
24using namespace testing;
Pavel Labath015f17d2017-06-06 13:40:18 +000025
Pavel Labath671d3e62017-12-15 13:56:22 +000026TEST_F(StandardStartupTest, TestStopReplyContainsThreadPcs) {
27 // This inferior spawns 4 threads, then forces a break.
28 ASSERT_THAT_ERROR(
29 Client->SetInferior({getInferiorPath("thread_inferior"), "4"}),
30 Succeeded());
Pavel Labath015f17d2017-06-06 13:40:18 +000031
Pavel Labath671d3e62017-12-15 13:56:22 +000032 ASSERT_THAT_ERROR(Client->ListThreadsInStopReply(), Succeeded());
33 ASSERT_THAT_ERROR(Client->ContinueAll(), Succeeded());
34 unsigned int pc_reg = Client->GetPcRegisterId();
Pavel Labath015f17d2017-06-06 13:40:18 +000035 ASSERT_NE(pc_reg, UINT_MAX);
36
Pavel Labath671d3e62017-12-15 13:56:22 +000037 auto jthreads_info = Client->GetJThreadsInfo();
Pavel Labath9a9556f2018-02-19 15:42:48 +000038 ASSERT_THAT_EXPECTED(jthreads_info, Succeeded());
Pavel Labath015f17d2017-06-06 13:40:18 +000039
Pavel Labath93a582c2017-12-15 15:19:45 +000040 auto stop_reply = Client->GetLatestStopReplyAs<StopReplyStop>();
41 ASSERT_THAT_EXPECTED(stop_reply, Succeeded());
42 auto stop_reply_pcs = stop_reply->getThreadPcs();
Pavel Labath015f17d2017-06-06 13:40:18 +000043 auto thread_infos = jthreads_info->GetThreadInfos();
44 ASSERT_EQ(stop_reply_pcs.size(), thread_infos.size())
45 << "Thread count mismatch.";
46
47 for (auto stop_reply_pc : stop_reply_pcs) {
48 unsigned long tid = stop_reply_pc.first;
49 ASSERT_TRUE(thread_infos.find(tid) != thread_infos.end())
50 << "Thread ID: " << tid << " not in JThreadsInfo.";
Pavel Labath9a9556f2018-02-19 15:42:48 +000051 EXPECT_THAT(thread_infos[tid].ReadRegister(pc_reg),
52 Pointee(Eq(stop_reply_pc.second)));
Pavel Labath015f17d2017-06-06 13:40:18 +000053 }
Pavel Labath015f17d2017-06-06 13:40:18 +000054}