[Lldb-commits] [PATCH] D43076: llgs-test: Parse and store register info recieved from lldb-server

2018-02-09 Thread Pavel Labath via Phabricator via lldb-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL324722: llgs-test: Parse and store register info recieved 
from lldb-server (authored by labath, committed by ).
Herald added a subscriber: llvm-commits.

Repository:
  rL LLVM

https://reviews.llvm.org/D43076

Files:
  lldb/trunk/unittests/tools/lldb-server/tests/MessageObjects.cpp
  lldb/trunk/unittests/tools/lldb-server/tests/MessageObjects.h
  lldb/trunk/unittests/tools/lldb-server/tests/TestClient.cpp
  lldb/trunk/unittests/tools/lldb-server/tests/TestClient.h
  lldb/trunk/unittests/tools/lldb-server/tests/ThreadIdsInJstopinfoTest.cpp

Index: lldb/trunk/unittests/tools/lldb-server/tests/ThreadIdsInJstopinfoTest.cpp
===
--- lldb/trunk/unittests/tools/lldb-server/tests/ThreadIdsInJstopinfoTest.cpp
+++ lldb/trunk/unittests/tools/lldb-server/tests/ThreadIdsInJstopinfoTest.cpp
@@ -44,7 +44,7 @@
 << "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)
+ASSERT_EQ(stop_reply_pc.second, *pc_value)
 << "Mismatched PC for thread: " << tid;
   }
 }
Index: lldb/trunk/unittests/tools/lldb-server/tests/TestClient.h
===
--- lldb/trunk/unittests/tools/lldb-server/tests/TestClient.h
+++ lldb/trunk/unittests/tools/lldb-server/tests/TestClient.h
@@ -74,23 +74,38 @@
   std::string _string);
   llvm::Error SendMessage(llvm::StringRef message, std::string _string,
   PacketResult expected_result);
+
+  template 
+  llvm::Expected SendMessage(llvm::StringRef Message);
   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 ,
   lldb_private::process_gdb_remote::GDBRemoteCommunication::PacketResult
   result);
 
   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) {
+  std::string ResponseText;
+  if (llvm::Error E = SendMessage(Message, ResponseText))
+return std::move(E);
+  return P::create(ResponseText);
+}
+
 } // namespace llgs_tests
 
 #endif // LLDB_SERVER_TESTS_TESTCLIENT_H
Index: lldb/trunk/unittests/tools/lldb-server/tests/MessageObjects.h
===
--- lldb/trunk/unittests/tools/lldb-server/tests/MessageObjects.h
+++ lldb/trunk/unittests/tools/lldb-server/tests/MessageObjects.h
@@ -25,9 +25,11 @@
 typedef llvm::DenseMap U64Map;
 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;
 
@@ -73,6 +75,11 @@
   ThreadInfoMap m_thread_infos;
 };
 
+struct RegisterInfoParser : public Parser {
+  static llvm::Expected
+  create(llvm::StringRef Response);
+};
+
 class StopReply {
 public:
   StopReply() = default;
Index: lldb/trunk/unittests/tools/lldb-server/tests/TestClient.cpp
===
--- lldb/trunk/unittests/tools/lldb-server/tests/TestClient.cpp
+++ lldb/trunk/unittests/tools/lldb-server/tests/TestClient.cpp
@@ -25,8 +25,7 @@
 using namespace lldb;
 using namespace lldb_private;
 using namespace llvm;
-
-namespace llgs_tests {
+using namespace llgs_tests;
 
 TestClient::TestClient(std::unique_ptr Conn) {
   SetConnection(Conn.release());
@@ -103,7 +102,7 @@
   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);
   }
 
@@ -128,7 +127,7 @@
 return E;
   if (Error E = SendMessage("qLaunchSuccess"))
 return E;
-  if (Error E = QueryProcessInfo())
+  if (Error E = queryProcess())
 return E;
   return Error::success();
 }
@@ -147,7 +146,9 @@
   return Continue(formatv("vCont;c:{0:x-}", thread_id).str());
 }
 
-const ProcessInfo ::GetProcessInfo() { return *m_process_info; }
+const llgs_tests::ProcessInfo ::GetProcessInfo() {
+  return *m_process_info;
+}
 
 Optional TestClient::GetJThreadsInfo() {
   std::string response;
@@ -201,42 +202,42 @@
 }
 
 unsigned int 

[Lldb-commits] [PATCH] D43076: llgs-test: Parse and store register info recieved from lldb-server

2018-02-08 Thread Pavel Labath via Phabricator via lldb-commits
labath created this revision.
labath added reviewers: eugene, davide.

Right now the test client is not parsing register values correctly,
which is manifesting itself in one test failing on 32-bit architectures
(pr36013). This parses the information from the qRegisterInfo packets
and stores it in the client, which will enable fixing the parsing in a
follow up commit.

I am also adding a new templated SendMessage overload, which enables one
to send a message get a parsed response in a single call.


https://reviews.llvm.org/D43076

Files:
  unittests/tools/lldb-server/tests/MessageObjects.cpp
  unittests/tools/lldb-server/tests/MessageObjects.h
  unittests/tools/lldb-server/tests/TestClient.cpp
  unittests/tools/lldb-server/tests/TestClient.h
  unittests/tools/lldb-server/tests/ThreadIdsInJstopinfoTest.cpp

Index: unittests/tools/lldb-server/tests/ThreadIdsInJstopinfoTest.cpp
===
--- unittests/tools/lldb-server/tests/ThreadIdsInJstopinfoTest.cpp
+++ unittests/tools/lldb-server/tests/ThreadIdsInJstopinfoTest.cpp
@@ -44,7 +44,7 @@
 << "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)
+ASSERT_EQ(stop_reply_pc.second, *pc_value)
 << "Mismatched PC for thread: " << tid;
   }
 }
Index: unittests/tools/lldb-server/tests/TestClient.h
===
--- unittests/tools/lldb-server/tests/TestClient.h
+++ unittests/tools/lldb-server/tests/TestClient.h
@@ -74,23 +74,38 @@
   std::string _string);
   llvm::Error SendMessage(llvm::StringRef message, std::string _string,
   PacketResult expected_result);
+
+  template 
+  llvm::Expected SendMessage(llvm::StringRef Message);
   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 ,
   lldb_private::process_gdb_remote::GDBRemoteCommunication::PacketResult
   result);
 
   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) {
+  std::string ResponseText;
+  if (llvm::Error E = SendMessage(Message, ResponseText))
+return std::move(E);
+  return P::create(ResponseText);
+}
+
 } // namespace llgs_tests
 
 #endif // LLDB_SERVER_TESTS_TESTCLIENT_H
Index: unittests/tools/lldb-server/tests/TestClient.cpp
===
--- unittests/tools/lldb-server/tests/TestClient.cpp
+++ unittests/tools/lldb-server/tests/TestClient.cpp
@@ -25,8 +25,7 @@
 using namespace lldb;
 using namespace lldb_private;
 using namespace llvm;
-
-namespace llgs_tests {
+using namespace llgs_tests;
 
 TestClient::TestClient(std::unique_ptr Conn) {
   SetConnection(Conn.release());
@@ -103,7 +102,7 @@
   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);
   }
 
@@ -128,7 +127,7 @@
 return E;
   if (Error E = SendMessage("qLaunchSuccess"))
 return E;
-  if (Error E = QueryProcessInfo())
+  if (Error E = queryProcess())
 return E;
   return Error::success();
 }
@@ -147,7 +146,9 @@
   return Continue(formatv("vCont;c:{0:x-}", thread_id).str());
 }
 
-const ProcessInfo ::GetProcessInfo() { return *m_process_info; }
+const llgs_tests::ProcessInfo ::GetProcessInfo() {
+  return *m_process_info;
+}
 
 Optional TestClient::GetJThreadsInfo() {
   std::string response;
@@ -201,42 +202,42 @@
 }
 
 unsigned int TestClient::GetPcRegisterId() {
-  if (m_pc_register != UINT_MAX)
-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;
-}
+  assert(m_pc_register != LLDB_INVALID_REGNUM);
+  return m_pc_register;
+}
 
-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;
-}
+Error TestClient::qProcessInfo() {
+  m_process_info = None;
+  auto InfoOr =