aboutsummaryrefslogtreecommitdiffstats
path: root/unittests/tools/lldb-server/tests/TestClient.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'unittests/tools/lldb-server/tests/TestClient.cpp')
-rw-r--r--unittests/tools/lldb-server/tests/TestClient.cpp85
1 files changed, 38 insertions, 47 deletions
diff --git a/unittests/tools/lldb-server/tests/TestClient.cpp b/unittests/tools/lldb-server/tests/TestClient.cpp
index 4653c2df1ce9..9396c23139a1 100644
--- a/unittests/tools/lldb-server/tests/TestClient.cpp
+++ b/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<Connection> Conn) {
SetConnection(Conn.release());
@@ -106,7 +105,7 @@ Expected<std::unique_ptr<TestClient>> TestClient::launchCustom(StringRef Log, Ar
auto Client = std::unique_ptr<TestClient>(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<std::string> inferior_args) {
return E;
if (Error E = SendMessage("qLaunchSuccess"))
return E;
- if (Error E = QueryProcessInfo())
+ if (Error E = queryProcess())
return E;
return Error::success();
}
@@ -155,19 +154,12 @@ Error TestClient::ContinueThread(unsigned long thread_id) {
return Continue(formatv("vCont;c:{0:x-}", thread_id).str());
}
-const ProcessInfo &TestClient::GetProcessInfo() { return *m_process_info; }
-
-Optional<JThreadsInfo> 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;
- }
+const llgs_tests::ProcessInfo &TestClient::GetProcessInfo() {
+ return *m_process_info;
+}
- return std::move(*creation);
+Expected<JThreadsInfo> TestClient::GetJThreadsInfo() {
+ return SendMessage<JThreadsInfo>("jThreadsInfo", m_register_infos);
}
const StopReply &TestClient::GetLatestStopReply() {
@@ -209,42 +201,42 @@ Error TestClient::SendMessage(StringRef message, std::string &response_string,
}
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 = SendMessage<ProcessInfo>("qProcessInfo");
+ if (!InfoOr)
+ return InfoOr.takeError();
+ m_process_info = std::move(*InfoOr);
+ return Error::success();
+}
- 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<RegisterInfo> InfoOr = SendMessage<RegisterInfoParser>(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;
+ if (Error E = qRegisterInfos())
return E;
- auto create_or_error = ProcessInfo::Create(response);
- if (!create_or_error)
- return create_or_error.takeError();
- m_process_info = *create_or_error;
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