From owner-svn-src-vendor@freebsd.org Sat Feb 24 21:28:08 2018 Return-Path: Delivered-To: svn-src-vendor@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 5E771F24018; Sat, 24 Feb 2018 21:28:08 +0000 (UTC) (envelope-from dim@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client CN "mxrelay.nyi.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 68E6677F62; Sat, 24 Feb 2018 21:28:03 +0000 (UTC) (envelope-from dim@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id F07472B068; Sat, 24 Feb 2018 21:28:02 +0000 (UTC) (envelope-from dim@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id w1OLS2RN009271; Sat, 24 Feb 2018 21:28:02 GMT (envelope-from dim@FreeBSD.org) Received: (from dim@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id w1OLS2QO009266; Sat, 24 Feb 2018 21:28:02 GMT (envelope-from dim@FreeBSD.org) Message-Id: <201802242128.w1OLS2QO009266@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: dim set sender to dim@FreeBSD.org using -f From: Dimitry Andric Date: Sat, 24 Feb 2018 21:28:02 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-vendor@freebsd.org Subject: svn commit: r329939 - vendor/lldb/dist-release_60/unittests/tools/lldb-server/tests X-SVN-Group: vendor X-SVN-Commit-Author: dim X-SVN-Commit-Paths: vendor/lldb/dist-release_60/unittests/tools/lldb-server/tests X-SVN-Commit-Revision: 329939 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-vendor@freebsd.org X-Mailman-Version: 2.1.25 Precedence: list List-Id: SVN commit messages for the vendor work area tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 24 Feb 2018 21:28:08 -0000 Author: dim Date: Sat Feb 24 21:28:02 2018 New Revision: 329939 URL: https://svnweb.freebsd.org/changeset/base/329939 Log: Vendor import of lldb release_60 branch r325932: https://llvm.org/svn/llvm-project/lldb/branches/release_60@325932 Modified: vendor/lldb/dist-release_60/unittests/tools/lldb-server/tests/MessageObjects.cpp vendor/lldb/dist-release_60/unittests/tools/lldb-server/tests/MessageObjects.h vendor/lldb/dist-release_60/unittests/tools/lldb-server/tests/TestClient.cpp vendor/lldb/dist-release_60/unittests/tools/lldb-server/tests/TestClient.h vendor/lldb/dist-release_60/unittests/tools/lldb-server/tests/ThreadIdsInJstopinfoTest.cpp Modified: vendor/lldb/dist-release_60/unittests/tools/lldb-server/tests/MessageObjects.cpp ============================================================================== --- vendor/lldb/dist-release_60/unittests/tools/lldb-server/tests/MessageObjects.cpp Sat Feb 24 21:27:59 2018 (r329938) +++ vendor/lldb/dist-release_60/unittests/tools/lldb-server/tests/MessageObjects.cpp Sat Feb 24 21:28:02 2018 (r329939) @@ -8,16 +8,17 @@ //===----------------------------------------------------------------------===// #include "MessageObjects.h" -#include "lldb/Utility/StructuredData.h" +#include "lldb/Interpreter/Args.h" +#include "lldb/Utility/StringExtractor.h" #include "llvm/ADT/StringExtras.h" #include "gtest/gtest.h" using namespace lldb_private; +using namespace lldb; using namespace llvm; -using namespace llvm::support; namespace llgs_tests { -Expected ProcessInfo::Create(StringRef response) { +Expected ProcessInfo::create(StringRef response) { ProcessInfo process_info; auto elements_or_error = SplitUniquePairList("ProcessInfo", response); if (!elements_or_error) @@ -53,36 +54,50 @@ Expected ProcessInfo::Create(StringRef re lldb::pid_t ProcessInfo::GetPid() const { return m_pid; } -endianness ProcessInfo::GetEndian() const { return m_endian; } +support::endianness ProcessInfo::GetEndian() const { return m_endian; } //====== ThreadInfo ============================================================ -ThreadInfo::ThreadInfo(StringRef name, StringRef reason, - const RegisterMap ®isters, unsigned int signal) - : m_name(name.str()), m_reason(reason.str()), m_registers(registers), - m_signal(signal) {} +ThreadInfo::ThreadInfo(StringRef name, StringRef reason, RegisterMap registers, + unsigned int signal) + : m_name(name.str()), m_reason(reason.str()), + m_registers(std::move(registers)), m_signal(signal) {} -StringRef ThreadInfo::ReadRegister(unsigned int register_id) const { - return m_registers.lookup(register_id); +const RegisterValue *ThreadInfo::ReadRegister(unsigned int Id) const { + auto Iter = m_registers.find(Id); + return Iter == m_registers.end() ? nullptr : &Iter->getSecond(); } -Expected -ThreadInfo::ReadRegisterAsUint64(unsigned int register_id) const { - uint64_t value; - std::string value_str(m_registers.lookup(register_id)); - if (!llvm::to_integer(value_str, value, 16)) - return make_parsing_error("ThreadInfo value for register {0}: {1}", - register_id, value_str); +//====== JThreadsInfo ========================================================== - sys::swapByteOrder(value); - return value; +Expected +JThreadsInfo::parseRegisters(const StructuredData::Dictionary &Dict, + ArrayRef RegInfos) { + RegisterMap Result; + + auto KeysObj = Dict.GetKeys(); + auto Keys = KeysObj->GetAsArray(); + for (size_t i = 0; i < Keys->GetSize(); i++) { + StringRef KeyStr, ValueStr; + Keys->GetItemAtIndexAsString(i, KeyStr); + Dict.GetValueForKeyAsString(KeyStr, ValueStr); + unsigned int Register; + if (!llvm::to_integer(KeyStr, Register, 10)) + return make_parsing_error("JThreadsInfo: register key[{0}]", i); + + auto RegValOr = + parseRegisterValue(RegInfos[Register], ValueStr, support::big); + if (!RegValOr) + return RegValOr.takeError(); + Result[Register] = std::move(*RegValOr); + } + return std::move(Result); } -//====== JThreadsInfo ========================================================== -Expected JThreadsInfo::Create(StringRef response, - endianness endian) { +Expected JThreadsInfo::create(StringRef Response, + ArrayRef RegInfos) { JThreadsInfo jthreads_info; - StructuredData::ObjectSP json = StructuredData::ParseJSON(response); + StructuredData::ObjectSP json = StructuredData::ParseJSON(Response); StructuredData::Array *array = json->GetAsArray(); if (!array) return make_parsing_error("JThreadsInfo: JSON array"); @@ -106,23 +121,11 @@ Expected JThreadsInfo::Create(StringRef if (!register_dict) return make_parsing_error("JThreadsInfo: registers JSON obj"); - RegisterMap registers; - - auto keys_obj = register_dict->GetKeys(); - auto keys = keys_obj->GetAsArray(); - for (size_t i = 0; i < keys->GetSize(); i++) { - StringRef key_str, value_str; - keys->GetItemAtIndexAsString(i, key_str); - register_dict->GetValueForKeyAsString(key_str, value_str); - unsigned int register_id; - if (key_str.getAsInteger(10, register_id)) - return make_parsing_error("JThreadsInfo: register key[{0}]", i); - - registers[register_id] = value_str.str(); - } - + auto RegsOr = parseRegisters(*register_dict, RegInfos); + if (!RegsOr) + return RegsOr.takeError(); jthreads_info.m_thread_infos[tid] = - ThreadInfo(name, reason, registers, signal); + ThreadInfo(name, reason, std::move(*RegsOr), signal); } return jthreads_info; @@ -132,20 +135,130 @@ const ThreadInfoMap &JThreadsInfo::GetThreadInfos() co return m_thread_infos; } +Expected RegisterInfoParser::create(StringRef Response) { + auto ElementsOr = SplitUniquePairList("RegisterInfoParser", Response); + if (!ElementsOr) + return ElementsOr.takeError(); + auto &Elements = *ElementsOr; + + RegisterInfo Info = { + nullptr, // Name + nullptr, // Alt name + 0, // byte size + 0, // offset + eEncodingUint, // encoding + eFormatHex, // format + { + LLDB_INVALID_REGNUM, // eh_frame reg num + LLDB_INVALID_REGNUM, // DWARF reg num + LLDB_INVALID_REGNUM, // generic reg num + LLDB_INVALID_REGNUM, // process plugin reg num + LLDB_INVALID_REGNUM // native register number + }, + NULL, + NULL, + NULL, // Dwarf expression opcode bytes pointer + 0 // Dwarf expression opcode bytes length + }; + Info.name = ConstString(Elements["name"]).GetCString(); + if (!Info.name) + return make_parsing_error("qRegisterInfo: name"); + + Info.alt_name = ConstString(Elements["alt-name"]).GetCString(); + + if (!to_integer(Elements["bitsize"], Info.byte_size, 10)) + return make_parsing_error("qRegisterInfo: bit-size"); + Info.byte_size /= CHAR_BIT; + + if (!to_integer(Elements["offset"], Info.byte_offset, 10)) + return make_parsing_error("qRegisterInfo: offset"); + + Info.encoding = Args::StringToEncoding(Elements["encoding"]); + if (Info.encoding == eEncodingInvalid) + return make_parsing_error("qRegisterInfo: encoding"); + + Info.format = StringSwitch(Elements["format"]) + .Case("binary", eFormatBinary) + .Case("decimal", eFormatDecimal) + .Case("hex", eFormatHex) + .Case("float", eFormatFloat) + .Case("vector-sint8", eFormatVectorOfSInt8) + .Case("vector-uint8", eFormatVectorOfUInt8) + .Case("vector-sint16", eFormatVectorOfSInt16) + .Case("vector-uint16", eFormatVectorOfUInt16) + .Case("vector-sint32", eFormatVectorOfSInt32) + .Case("vector-uint32", eFormatVectorOfUInt32) + .Case("vector-float32", eFormatVectorOfFloat32) + .Case("vector-uint64", eFormatVectorOfUInt64) + .Case("vector-uint128", eFormatVectorOfUInt128) + .Default(eFormatInvalid); + if (Info.format == eFormatInvalid) + return make_parsing_error("qRegisterInfo: format"); + + Info.kinds[eRegisterKindGeneric] = + Args::StringToGenericRegister(Elements["generic"]); + + return std::move(Info); +} + +Expected parseRegisterValue(const RegisterInfo &Info, + StringRef HexValue, + llvm::support::endianness Endian) { + SmallVector Bytes(HexValue.size() / 2); + StringExtractor(HexValue).GetHexBytes(Bytes, '\xcc'); + RegisterValue Value; + Status ST; + Value.SetFromMemoryData( + &Info, Bytes.data(), Bytes.size(), + Endian == support::little ? eByteOrderLittle : eByteOrderBig, ST); + if (ST.Fail()) + return ST.ToError(); + return Value; +} + //====== StopReply ============================================================= Expected> -StopReply::create(StringRef Response, llvm::support::endianness Endian) { +StopReply::create(StringRef Response, llvm::support::endianness Endian, + ArrayRef RegInfos) { if (Response.size() < 3) return make_parsing_error("StopReply: Invalid packet"); if (Response.consume_front("T")) - return StopReplyStop::create(Response, Endian); + return StopReplyStop::create(Response, Endian, RegInfos); if (Response.consume_front("W")) return StopReplyExit::create(Response); return make_parsing_error("StopReply: Invalid packet"); } +Expected StopReplyStop::parseRegisters( + const StringMap> &Elements, + support::endianness Endian, ArrayRef RegInfos) { + + RegisterMap Result; + for (const auto &E : Elements) { + StringRef Key = E.getKey(); + const auto &Val = E.getValue(); + if (Key.size() != 2) + continue; + + unsigned int Reg; + if (!to_integer(Key, Reg, 16)) + continue; + + if (Val.size() != 1) + return make_parsing_error( + "StopReplyStop: multiple entries for register field [{0:x}]", Reg); + + auto RegValOr = parseRegisterValue(RegInfos[Reg], Val[0], Endian); + if (!RegValOr) + return RegValOr.takeError(); + Result[Reg] = std::move(*RegValOr); + } + return std::move(Result); +} + Expected> -StopReplyStop::create(StringRef Response, llvm::support::endianness Endian) { +StopReplyStop::create(StringRef Response, support::endianness Endian, + ArrayRef RegInfos) { unsigned int Signal; StringRef SignalStr = Response.take_front(2); Response = Response.drop_front(2); @@ -176,40 +289,31 @@ StopReplyStop::create(StringRef Response, llvm::suppor if (Threads.size() != Pcs.size()) return make_parsing_error("StopReply: thread/PC count mismatch"); - U64Map ThreadPcs; + RegisterMap ThreadPcs; + const RegisterInfo *PcInfo = find_if(RegInfos, [](const RegisterInfo &Info) { + return Info.kinds[eRegisterKindGeneric] == LLDB_REGNUM_GENERIC_PC; + }); + assert(PcInfo); + for (auto ThreadPc : zip(Threads, Pcs)) { lldb::tid_t Id; - uint64_t Pc; if (!to_integer(std::get<0>(ThreadPc), Id, 16)) return make_parsing_error("StopReply: Thread id '{0}'", std::get<0>(ThreadPc)); - if (!to_integer(std::get<1>(ThreadPc), Pc, 16)) - return make_parsing_error("StopReply Thread Pc '{0}'", - std::get<1>(ThreadPc)); - ThreadPcs[Id] = Pc; + auto PcOr = parseRegisterValue(*PcInfo, std::get<1>(ThreadPc), Endian); + if (!PcOr) + return PcOr.takeError(); + ThreadPcs[Id] = std::move(*PcOr); } - RegisterMap Registers; - for (const auto &E : Elements) { - StringRef Key = E.getKey(); - const auto &Val = E.getValue(); - if (Key.size() != 2) - continue; + auto RegistersOr = parseRegisters(Elements, Endian, RegInfos); + if (!RegistersOr) + return RegistersOr.takeError(); - unsigned int Reg; - if (!to_integer(Key, Reg, 16)) - continue; - - if (Val.size() != 1) - return make_parsing_error( - "StopReply: multiple entries for register field [{0:x}]", Reg); - - Registers[Reg] = Val[0].str(); - } - - return llvm::make_unique(Signal, Thread, Name, ThreadPcs, - Registers, Reason); + return llvm::make_unique(Signal, Thread, Name, + std::move(ThreadPcs), + std::move(*RegistersOr), Reason); } Expected> @@ -251,3 +355,12 @@ StringMap> SplitPairList(Str return pairs; } } // namespace llgs_tests + +std::ostream &lldb_private::operator<<(std::ostream &OS, + const RegisterValue &RegVal) { + ArrayRef Bytes(static_cast(RegVal.GetBytes()), + RegVal.GetByteSize()); + return OS << formatv("RegisterValue[{0}]: {1:@[x-2]}", RegVal.GetByteSize(), + make_range(Bytes.begin(), Bytes.end())) + .str(); +} Modified: vendor/lldb/dist-release_60/unittests/tools/lldb-server/tests/MessageObjects.h ============================================================================== --- vendor/lldb/dist-release_60/unittests/tools/lldb-server/tests/MessageObjects.h Sat Feb 24 21:27:59 2018 (r329938) +++ vendor/lldb/dist-release_60/unittests/tools/lldb-server/tests/MessageObjects.h Sat Feb 24 21:28:02 2018 (r329939) @@ -10,7 +10,9 @@ #ifndef LLDB_SERVER_TESTS_MESSAGEOBJECTS_H #define LLDB_SERVER_TESTS_MESSAGEOBJECTS_H +#include "lldb/Core/RegisterValue.h" #include "lldb/Host/Host.h" +#include "lldb/Utility/StructuredData.h" #include "lldb/lldb-types.h" #include "llvm/ADT/DenseMap.h" #include "llvm/ADT/SmallString.h" @@ -22,12 +24,13 @@ namespace llgs_tests { class ThreadInfo; typedef llvm::DenseMap ThreadInfoMap; -typedef llvm::DenseMap U64Map; -typedef llvm::DenseMap RegisterMap; +typedef llvm::DenseMap RegisterMap; -class ProcessInfo { +template struct Parser { using result_type = T; }; + +class ProcessInfo : public Parser { public: - static llvm::Expected Create(llvm::StringRef response); + static llvm::Expected create(llvm::StringRef response); lldb::pid_t GetPid() const; llvm::support::endianness GetEndian() const; @@ -49,10 +52,9 @@ class ThreadInfo { public: ThreadInfo() = default; ThreadInfo(llvm::StringRef name, llvm::StringRef reason, - const RegisterMap ®isters, unsigned int signal); + RegisterMap registers, unsigned int signal); - llvm::StringRef ReadRegister(unsigned int register_id) const; - llvm::Expected ReadRegisterAsUint64(unsigned int register_id) const; + const lldb_private::RegisterValue *ReadRegister(unsigned int Id) const; private: std::string m_name; @@ -61,25 +63,40 @@ class ThreadInfo { unsigned int m_signal; }; -class JThreadsInfo { +class JThreadsInfo : public Parser { public: - static llvm::Expected Create(llvm::StringRef response, - llvm::support::endianness endian); + static llvm::Expected + create(llvm::StringRef Response, + llvm::ArrayRef RegInfos); const ThreadInfoMap &GetThreadInfos() const; private: + static llvm::Expected + parseRegisters(const lldb_private::StructuredData::Dictionary &Dict, + llvm::ArrayRef RegInfos); + JThreadsInfo() = default; ThreadInfoMap m_thread_infos; }; +struct RegisterInfoParser : public Parser { + static llvm::Expected + create(llvm::StringRef Response); +}; + +llvm::Expected +parseRegisterValue(const lldb_private::RegisterInfo &Info, + llvm::StringRef HexValue, llvm::support::endianness Endian); + class StopReply { public: StopReply() = default; virtual ~StopReply() = default; static llvm::Expected> - create(llvm::StringRef response, llvm::support::endianness endian); + create(llvm::StringRef Response, llvm::support::endianness Endian, + llvm::ArrayRef RegInfos); // for llvm::cast<> virtual lldb_private::WaitStatus getKind() const = 0; @@ -91,15 +108,17 @@ class StopReply { (public) class StopReplyStop : public StopReply { public: StopReplyStop(uint8_t Signal, lldb::tid_t ThreadId, llvm::StringRef Name, - U64Map ThreadPcs, RegisterMap Registers, llvm::StringRef Reason) + RegisterMap ThreadPcs, RegisterMap Registers, + llvm::StringRef Reason) : Signal(Signal), ThreadId(ThreadId), Name(Name), ThreadPcs(std::move(ThreadPcs)), Registers(std::move(Registers)), Reason(Reason) {} static llvm::Expected> - create(llvm::StringRef response, llvm::support::endianness endian); + create(llvm::StringRef Response, llvm::support::endianness Endian, + llvm::ArrayRef RegInfos); - const U64Map &getThreadPcs() const { return ThreadPcs; } + const RegisterMap &getThreadPcs() const { return ThreadPcs; } lldb::tid_t getThreadId() const { return ThreadId; } // for llvm::cast<> @@ -111,10 +130,15 @@ class StopReplyStop : public StopReply { (public) } private: + static llvm::Expected parseRegisters( + const llvm::StringMap> &Elements, + llvm::support::endianness Endian, + llvm::ArrayRef RegInfos); + uint8_t Signal; lldb::tid_t ThreadId; std::string Name; - U64Map ThreadPcs; + RegisterMap ThreadPcs; RegisterMap Registers; std::string Reason; }; @@ -155,5 +179,9 @@ llvm::Error make_parsing_error(llvm::StringRef format, } } // namespace llgs_tests + +namespace lldb_private { +std::ostream &operator<<(std::ostream &OS, const RegisterValue &RegVal); +} #endif // LLDB_SERVER_TESTS_MESSAGEOBJECTS_H Modified: vendor/lldb/dist-release_60/unittests/tools/lldb-server/tests/TestClient.cpp ============================================================================== --- vendor/lldb/dist-release_60/unittests/tools/lldb-server/tests/TestClient.cpp Sat Feb 24 21:27:59 2018 (r329938) +++ vendor/lldb/dist-release_60/unittests/tools/lldb-server/tests/TestClient.cpp Sat Feb 24 21:28:02 2018 (r329939) @@ -25,9 +25,8 @@ using namespace lldb; using namespace lldb_private; using namespace llvm; +using namespace llgs_tests; -namespace llgs_tests { - TestClient::TestClient(std::unique_ptr Conn) { SetConnection(Conn.release()); @@ -106,7 +105,7 @@ Expected> TestClient::laun auto Client = std::unique_ptr(new TestClient(std::move(Conn))); if (!InferiorArgs.empty()) { - if (Error E = Client->QueryProcessInfo()) + if (Error E = Client->queryProcess()) return std::move(E); } @@ -136,7 +135,7 @@ Error TestClient::SetInferior(llvm::ArrayRef TestClient::GetJThreadsInfo() { - std::string response; - if (SendMessage("jThreadsInfo", response)) - return llvm::None; - auto creation = JThreadsInfo::Create(response, m_process_info->GetEndian()); - if (auto create_error = creation.takeError()) { - GTEST_LOG_(ERROR) << toString(std::move(create_error)); - return llvm::None; - } - - return std::move(*creation); +Expected TestClient::GetJThreadsInfo() { + return SendMessage("jThreadsInfo", m_register_infos); } const StopReply &TestClient::GetLatestStopReply() { @@ -209,42 +201,42 @@ Error TestClient::SendMessage(StringRef message, std:: } unsigned int TestClient::GetPcRegisterId() { - if (m_pc_register != UINT_MAX) - return m_pc_register; + assert(m_pc_register != LLDB_INVALID_REGNUM); + return m_pc_register; +} - for (unsigned int register_id = 0;; register_id++) { - std::string message = formatv("qRegisterInfo{0:x-}", register_id).str(); - std::string response; - if (SendMessage(message, response)) { - GTEST_LOG_(ERROR) << "Unable to query register ID for PC register."; - return UINT_MAX; - } +Error TestClient::qProcessInfo() { + m_process_info = None; + auto InfoOr = SendMessage("qProcessInfo"); + if (!InfoOr) + return InfoOr.takeError(); + m_process_info = std::move(*InfoOr); + return Error::success(); +} - auto elements_or_error = SplitUniquePairList("GetPcRegisterId", response); - if (auto split_error = elements_or_error.takeError()) { - GTEST_LOG_(ERROR) << "GetPcRegisterId: Error splitting response: " - << response; - return UINT_MAX; - } - - auto elements = *elements_or_error; - if (elements["alt-name"] == "pc" || elements["generic"] == "pc") { - m_pc_register = register_id; +Error TestClient::qRegisterInfos() { + for (unsigned int Reg = 0;; ++Reg) { + std::string Message = formatv("qRegisterInfo{0:x-}", Reg).str(); + Expected InfoOr = SendMessage(Message); + if (!InfoOr) { + consumeError(InfoOr.takeError()); break; } + m_register_infos.emplace_back(std::move(*InfoOr)); + if (m_register_infos[Reg].kinds[eRegisterKindGeneric] == + LLDB_REGNUM_GENERIC_PC) + m_pc_register = Reg; } - - return m_pc_register; + if (m_pc_register == LLDB_INVALID_REGNUM) + return make_parsing_error("qRegisterInfo: generic"); + return Error::success(); } -llvm::Error TestClient::QueryProcessInfo() { - std::string response; - if (Error E = SendMessage("qProcessInfo", response)) +Error TestClient::queryProcess() { + if (Error E = qProcessInfo()) return E; - auto create_or_error = ProcessInfo::Create(response); - if (!create_or_error) - return create_or_error.takeError(); - m_process_info = *create_or_error; + if (Error E = qRegisterInfos()) + return E; return Error::success(); } @@ -254,7 +246,8 @@ Error TestClient::Continue(StringRef message) { std::string response; if (Error E = SendMessage(message, response)) return E; - auto creation = StopReply::create(response, m_process_info->GetEndian()); + auto creation = StopReply::create(response, m_process_info->GetEndian(), + m_register_infos); if (Error E = creation.takeError()) return E; @@ -273,5 +266,3 @@ Error TestClient::Continue(StringRef message) { } return Error::success(); } - -} // namespace llgs_tests Modified: vendor/lldb/dist-release_60/unittests/tools/lldb-server/tests/TestClient.h ============================================================================== --- vendor/lldb/dist-release_60/unittests/tools/lldb-server/tests/TestClient.h Sat Feb 24 21:27:59 2018 (r329938) +++ vendor/lldb/dist-release_60/unittests/tools/lldb-server/tests/TestClient.h Sat Feb 24 21:28:02 2018 (r329939) @@ -59,7 +59,7 @@ class TestClient (public) llvm::Error ContinueAll(); llvm::Error ContinueThread(unsigned long thread_id); const ProcessInfo &GetProcessInfo(); - llvm::Optional GetJThreadsInfo(); + llvm::Expected GetJThreadsInfo(); const StopReply &GetLatestStopReply(); template llvm::Expected GetLatestStopReplyAs() { assert(m_stop_reply); @@ -74,12 +74,18 @@ class TestClient (public) std::string &response_string); llvm::Error SendMessage(llvm::StringRef message, std::string &response_string, PacketResult expected_result); + + template + llvm::Expected SendMessage(llvm::StringRef Message, + CreateArgs &&... Args); unsigned int GetPcRegisterId(); private: TestClient(std::unique_ptr Conn); - llvm::Error QueryProcessInfo(); + llvm::Error qProcessInfo(); + llvm::Error qRegisterInfos(); + llvm::Error queryProcess(); llvm::Error Continue(llvm::StringRef message); std::string FormatFailedResult( const std::string &message, @@ -88,8 +94,18 @@ class TestClient (public) llvm::Optional m_process_info; std::unique_ptr m_stop_reply; - unsigned int m_pc_register = UINT_MAX; + std::vector m_register_infos; + unsigned int m_pc_register = LLDB_INVALID_REGNUM; }; + +template +llvm::Expected +TestClient::SendMessage(llvm::StringRef Message, CreateArgs &&... Args) { + std::string ResponseText; + if (llvm::Error E = SendMessage(Message, ResponseText)) + return std::move(E); + return P::create(ResponseText, std::forward(Args)...); +} } // namespace llgs_tests Modified: vendor/lldb/dist-release_60/unittests/tools/lldb-server/tests/ThreadIdsInJstopinfoTest.cpp ============================================================================== --- vendor/lldb/dist-release_60/unittests/tools/lldb-server/tests/ThreadIdsInJstopinfoTest.cpp Sat Feb 24 21:27:59 2018 (r329938) +++ vendor/lldb/dist-release_60/unittests/tools/lldb-server/tests/ThreadIdsInJstopinfoTest.cpp Sat Feb 24 21:28:02 2018 (r329939) @@ -9,13 +9,19 @@ #include "TestBase.h" #include "TestClient.h" +#include "lldb/Utility/DataExtractor.h" +#include "llvm/Support/FormatVariadic.h" #include "llvm/Support/Path.h" #include "llvm/Testing/Support/Error.h" +#include "gmock/gmock.h" #include "gtest/gtest.h" #include using namespace llgs_tests; +using namespace lldb_private; using namespace llvm; +using namespace lldb; +using namespace testing; TEST_F(StandardStartupTest, TestStopReplyContainsThreadPcs) { // This inferior spawns 4 threads, then forces a break. @@ -29,7 +35,7 @@ TEST_F(StandardStartupTest, TestStopReplyContainsThrea ASSERT_NE(pc_reg, UINT_MAX); auto jthreads_info = Client->GetJThreadsInfo(); - ASSERT_TRUE(jthreads_info); + ASSERT_THAT_EXPECTED(jthreads_info, Succeeded()); auto stop_reply = Client->GetLatestStopReplyAs(); ASSERT_THAT_EXPECTED(stop_reply, Succeeded()); @@ -42,9 +48,7 @@ TEST_F(StandardStartupTest, TestStopReplyContainsThrea 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; + EXPECT_THAT(thread_infos[tid].ReadRegister(pc_reg), + Pointee(Eq(stop_reply_pc.second))); } }