summaryrefslogtreecommitdiff
path: root/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerLLGS.cpp
diff options
context:
space:
mode:
authorDimitry Andric <dim@FreeBSD.org>2017-12-18 20:12:36 +0000
committerDimitry Andric <dim@FreeBSD.org>2017-12-18 20:12:36 +0000
commitef5d0b5e97ec8e6fa395d377b09aa7755e345b4f (patch)
tree27916256fdeeb57d10d2f3d6948be5d71a703215 /source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerLLGS.cpp
parent76e0736e7fcfeb179779e49c05604464b1ccd704 (diff)
Notes
Diffstat (limited to 'source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerLLGS.cpp')
-rw-r--r--source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerLLGS.cpp329
1 files changed, 127 insertions, 202 deletions
diff --git a/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerLLGS.cpp b/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerLLGS.cpp
index 9294359dbef1c..32741c2404e22 100644
--- a/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerLLGS.cpp
+++ b/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerLLGS.cpp
@@ -204,21 +204,8 @@ void GDBRemoteCommunicationServerLLGS::RegisterPacketHandlers() {
});
}
-Status
-GDBRemoteCommunicationServerLLGS::SetLaunchArguments(const char *const args[],
- int argc) {
- if ((argc < 1) || !args || !args[0] || !args[0][0])
- return Status("%s: no process command line specified to launch",
- __FUNCTION__);
-
- m_process_launch_info.SetArguments(const_cast<const char **>(args), true);
- return Status();
-}
-
-Status
-GDBRemoteCommunicationServerLLGS::SetLaunchFlags(unsigned int launch_flags) {
- m_process_launch_info.GetFlags().Set(launch_flags);
- return Status();
+void GDBRemoteCommunicationServerLLGS::SetLaunchInfo(const ProcessLaunchInfo &info) {
+ m_process_launch_info = info;
}
Status GDBRemoteCommunicationServerLLGS::LaunchProcess() {
@@ -244,13 +231,8 @@ Status GDBRemoteCommunicationServerLLGS::LaunchProcess() {
"process but one already exists");
auto process_or =
m_process_factory.Launch(m_process_launch_info, *this, m_mainloop);
- if (!process_or) {
- Status status(process_or.takeError());
- llvm::errs() << llvm::formatv(
- "failed to launch executable `{0}`: {1}",
- m_process_launch_info.GetArguments().GetArgumentAtIndex(0), status);
- return status;
- }
+ if (!process_or)
+ return Status(process_or.takeError());
m_debugged_process_up = std::move(*process_or);
}
@@ -396,12 +378,12 @@ static void AppendHexValue(StreamString &response, const uint8_t *buf,
}
static void WriteRegisterValueInHexFixedWidth(
- StreamString &response, NativeRegisterContextSP &reg_ctx_sp,
+ StreamString &response, NativeRegisterContext &reg_ctx,
const RegisterInfo &reg_info, const RegisterValue *reg_value_p,
lldb::ByteOrder byte_order) {
RegisterValue reg_value;
if (!reg_value_p) {
- Status error = reg_ctx_sp->ReadRegister(&reg_info, reg_value);
+ Status error = reg_ctx.ReadRegister(&reg_info, reg_value);
if (error.Success())
reg_value_p = &reg_value;
// else log.
@@ -423,9 +405,7 @@ static void WriteRegisterValueInHexFixedWidth(
static JSONObject::SP GetRegistersAsJSON(NativeThreadProtocol &thread) {
Log *log(GetLogIfAnyCategoriesSet(LIBLLDB_LOG_THREAD));
- NativeRegisterContextSP reg_ctx_sp = thread.GetRegisterContext();
- if (!reg_ctx_sp)
- return nullptr;
+ NativeRegisterContext& reg_ctx = thread.GetRegisterContext();
JSONObject::SP register_object_sp = std::make_shared<JSONObject>();
@@ -448,14 +428,14 @@ static JSONObject::SP GetRegistersAsJSON(NativeThreadProtocol &thread) {
for (const uint32_t *generic_reg_p = k_expedited_registers;
*generic_reg_p != LLDB_INVALID_REGNUM; ++generic_reg_p) {
- uint32_t reg_num = reg_ctx_sp->ConvertRegisterKindToRegisterNumber(
+ uint32_t reg_num = reg_ctx.ConvertRegisterKindToRegisterNumber(
eRegisterKindGeneric, *generic_reg_p);
if (reg_num == LLDB_INVALID_REGNUM)
continue; // Target does not support the given register.
#endif
const RegisterInfo *const reg_info_p =
- reg_ctx_sp->GetRegisterInfoAtIndex(reg_num);
+ reg_ctx.GetRegisterInfoAtIndex(reg_num);
if (reg_info_p == nullptr) {
if (log)
log->Printf(
@@ -469,7 +449,7 @@ static JSONObject::SP GetRegistersAsJSON(NativeThreadProtocol &thread) {
// registers.
RegisterValue reg_value;
- Status error = reg_ctx_sp->ReadRegister(reg_info_p, reg_value);
+ Status error = reg_ctx.ReadRegister(reg_info_p, reg_value);
if (error.Fail()) {
if (log)
log->Printf("%s failed to read register '%s' index %" PRIu32 ": %s",
@@ -480,7 +460,7 @@ static JSONObject::SP GetRegistersAsJSON(NativeThreadProtocol &thread) {
}
StreamString stream;
- WriteRegisterValueInHexFixedWidth(stream, reg_ctx_sp, *reg_info_p,
+ WriteRegisterValueInHexFixedWidth(stream, reg_ctx, *reg_info_p,
&reg_value, lldb::eByteOrderBig);
register_object_sp->SetObject(
@@ -523,16 +503,16 @@ static JSONArray::SP GetJSONThreadsInfo(NativeProcessProtocol &process,
// Ensure we can get info on the given thread.
uint32_t thread_idx = 0;
- for (NativeThreadProtocolSP thread_sp;
- (thread_sp = process.GetThreadAtIndex(thread_idx)) != nullptr;
+ for (NativeThreadProtocol *thread;
+ (thread = process.GetThreadAtIndex(thread_idx)) != nullptr;
++thread_idx) {
- lldb::tid_t tid = thread_sp->GetID();
+ lldb::tid_t tid = thread->GetID();
// Grab the reason this thread stopped.
struct ThreadStopInfo tid_stop_info;
std::string description;
- if (!thread_sp->GetStopReason(tid_stop_info, description))
+ if (!thread->GetStopReason(tid_stop_info, description))
return nullptr;
const int signum = tid_stop_info.details.signal.signo;
@@ -548,7 +528,7 @@ static JSONArray::SP GetJSONThreadsInfo(NativeProcessProtocol &process,
threads_array_sp->AppendObject(thread_obj_sp);
if (!abridged) {
- if (JSONObject::SP registers_sp = GetRegistersAsJSON(*thread_sp))
+ if (JSONObject::SP registers_sp = GetRegistersAsJSON(*thread))
thread_obj_sp->SetObject("registers", registers_sp);
}
@@ -556,7 +536,7 @@ static JSONArray::SP GetJSONThreadsInfo(NativeProcessProtocol &process,
if (signum != 0)
thread_obj_sp->SetObject("signal", std::make_shared<JSONNumber>(signum));
- const std::string thread_name = thread_sp->GetName();
+ const std::string thread_name = thread->GetName();
if (!thread_name.empty())
thread_obj_sp->SetObject("name",
std::make_shared<JSONString>(thread_name));
@@ -604,14 +584,14 @@ GDBRemoteCommunicationServerLLGS::SendStopReplyPacketForThread(
m_debugged_process_up->GetID(), tid);
// Ensure we can get info on the given thread.
- NativeThreadProtocolSP thread_sp(m_debugged_process_up->GetThreadByID(tid));
- if (!thread_sp)
+ NativeThreadProtocol *thread = m_debugged_process_up->GetThreadByID(tid);
+ if (!thread)
return SendErrorResponse(51);
// Grab the reason this thread stopped.
struct ThreadStopInfo tid_stop_info;
std::string description;
- if (!thread_sp->GetStopReason(tid_stop_info, description))
+ if (!thread->GetStopReason(tid_stop_info, description))
return SendErrorResponse(52);
// FIXME implement register handling for exec'd inferiors.
@@ -638,7 +618,7 @@ GDBRemoteCommunicationServerLLGS::SendStopReplyPacketForThread(
response.Printf("thread:%" PRIx64 ";", tid);
// Include the thread name if there is one.
- const std::string thread_name = thread_sp->GetName();
+ const std::string thread_name = thread->GetName();
if (!thread_name.empty()) {
size_t thread_name_len = thread_name.length();
@@ -665,15 +645,13 @@ GDBRemoteCommunicationServerLLGS::SendStopReplyPacketForThread(
response.PutCString("threads:");
uint32_t thread_index = 0;
- NativeThreadProtocolSP listed_thread_sp;
- for (listed_thread_sp =
- m_debugged_process_up->GetThreadAtIndex(thread_index);
- listed_thread_sp; ++thread_index,
- listed_thread_sp = m_debugged_process_up->GetThreadAtIndex(
- thread_index)) {
+ NativeThreadProtocol *listed_thread;
+ for (listed_thread = m_debugged_process_up->GetThreadAtIndex(thread_index);
+ listed_thread; ++thread_index,
+ listed_thread = m_debugged_process_up->GetThreadAtIndex(thread_index)) {
if (thread_index > 0)
response.PutChar(',');
- response.Printf("%" PRIx64, listed_thread_sp->GetID());
+ response.Printf("%" PRIx64, listed_thread->GetID());
}
response.PutChar(';');
@@ -701,20 +679,18 @@ GDBRemoteCommunicationServerLLGS::SendStopReplyPacketForThread(
uint32_t i = 0;
response.PutCString("thread-pcs");
char delimiter = ':';
- for (NativeThreadProtocolSP thread_sp;
- (thread_sp = m_debugged_process_up->GetThreadAtIndex(i)) != nullptr;
+ for (NativeThreadProtocol *thread;
+ (thread = m_debugged_process_up->GetThreadAtIndex(i)) != nullptr;
++i) {
- NativeRegisterContextSP reg_ctx_sp = thread_sp->GetRegisterContext();
- if (!reg_ctx_sp)
- continue;
+ NativeRegisterContext& reg_ctx = thread->GetRegisterContext();
- uint32_t reg_to_read = reg_ctx_sp->ConvertRegisterKindToRegisterNumber(
+ uint32_t reg_to_read = reg_ctx.ConvertRegisterKindToRegisterNumber(
eRegisterKindGeneric, LLDB_REGNUM_GENERIC_PC);
const RegisterInfo *const reg_info_p =
- reg_ctx_sp->GetRegisterInfoAtIndex(reg_to_read);
+ reg_ctx.GetRegisterInfoAtIndex(reg_to_read);
RegisterValue reg_value;
- Status error = reg_ctx_sp->ReadRegister(reg_info_p, reg_value);
+ Status error = reg_ctx.ReadRegister(reg_info_p, reg_value);
if (error.Fail()) {
if (log)
log->Printf("%s failed to read register '%s' index %" PRIu32 ": %s",
@@ -727,7 +703,7 @@ GDBRemoteCommunicationServerLLGS::SendStopReplyPacketForThread(
response.PutChar(delimiter);
delimiter = ',';
- WriteRegisterValueInHexFixedWidth(response, reg_ctx_sp, *reg_info_p,
+ WriteRegisterValueInHexFixedWidth(response, reg_ctx, *reg_info_p,
&reg_value, endian::InlHostByteOrder());
}
@@ -739,49 +715,48 @@ GDBRemoteCommunicationServerLLGS::SendStopReplyPacketForThread(
//
// Grab the register context.
- NativeRegisterContextSP reg_ctx_sp = thread_sp->GetRegisterContext();
- if (reg_ctx_sp) {
- // Expedite all registers in the first register set (i.e. should be GPRs)
- // that are not contained in other registers.
- const RegisterSet *reg_set_p;
- if (reg_ctx_sp->GetRegisterSetCount() > 0 &&
- ((reg_set_p = reg_ctx_sp->GetRegisterSet(0)) != nullptr)) {
- if (log)
- log->Printf("GDBRemoteCommunicationServerLLGS::%s expediting registers "
- "from set '%s' (registers set count: %zu)",
- __FUNCTION__,
- reg_set_p->name ? reg_set_p->name : "<unnamed-set>",
- reg_set_p->num_registers);
-
- for (const uint32_t *reg_num_p = reg_set_p->registers;
- *reg_num_p != LLDB_INVALID_REGNUM; ++reg_num_p) {
- const RegisterInfo *const reg_info_p =
- reg_ctx_sp->GetRegisterInfoAtIndex(*reg_num_p);
- if (reg_info_p == nullptr) {
+ NativeRegisterContext& reg_ctx = thread->GetRegisterContext();
+ // Expedite all registers in the first register set (i.e. should be GPRs)
+ // that are not contained in other registers.
+ const RegisterSet *reg_set_p;
+ if (reg_ctx.GetRegisterSetCount() > 0 &&
+ ((reg_set_p = reg_ctx.GetRegisterSet(0)) != nullptr)) {
+ if (log)
+ log->Printf("GDBRemoteCommunicationServerLLGS::%s expediting registers "
+ "from set '%s' (registers set count: %zu)",
+ __FUNCTION__,
+ reg_set_p->name ? reg_set_p->name : "<unnamed-set>",
+ reg_set_p->num_registers);
+
+ for (const uint32_t *reg_num_p = reg_set_p->registers;
+ *reg_num_p != LLDB_INVALID_REGNUM; ++reg_num_p) {
+ const RegisterInfo *const reg_info_p =
+ reg_ctx.GetRegisterInfoAtIndex(*reg_num_p);
+ if (reg_info_p == nullptr) {
+ if (log)
+ log->Printf("GDBRemoteCommunicationServerLLGS::%s failed to get "
+ "register info for register set '%s', register index "
+ "%" PRIu32,
+ __FUNCTION__,
+ reg_set_p->name ? reg_set_p->name : "<unnamed-set>",
+ *reg_num_p);
+ } else if (reg_info_p->value_regs == nullptr) {
+ // Only expediate registers that are not contained in other registers.
+ RegisterValue reg_value;
+ Status error = reg_ctx.ReadRegister(reg_info_p, reg_value);
+ if (error.Success()) {
+ response.Printf("%.02x:", *reg_num_p);
+ WriteRegisterValueInHexFixedWidth(response, reg_ctx, *reg_info_p,
+ &reg_value, lldb::eByteOrderBig);
+ response.PutChar(';');
+ } else {
if (log)
- log->Printf("GDBRemoteCommunicationServerLLGS::%s failed to get "
- "register info for register set '%s', register index "
- "%" PRIu32,
+ log->Printf("GDBRemoteCommunicationServerLLGS::%s failed to read "
+ "register '%s' index %" PRIu32 ": %s",
__FUNCTION__,
- reg_set_p->name ? reg_set_p->name : "<unnamed-set>",
- *reg_num_p);
- } else if (reg_info_p->value_regs == nullptr) {
- // Only expediate registers that are not contained in other registers.
- RegisterValue reg_value;
- Status error = reg_ctx_sp->ReadRegister(reg_info_p, reg_value);
- if (error.Success()) {
- response.Printf("%.02x:", *reg_num_p);
- WriteRegisterValueInHexFixedWidth(response, reg_ctx_sp, *reg_info_p,
- &reg_value, lldb::eByteOrderBig);
- response.PutChar(';');
- } else {
- if (log)
- log->Printf("GDBRemoteCommunicationServerLLGS::%s failed to read "
- "register '%s' index %" PRIu32 ": %s",
- __FUNCTION__, reg_info_p->name ? reg_info_p->name
- : "<unnamed-register>",
- *reg_num_p, error.AsCString());
- }
+ reg_info_p->name ? reg_info_p->name
+ : "<unnamed-register>",
+ *reg_num_p, error.AsCString());
}
}
}
@@ -837,6 +812,7 @@ void GDBRemoteCommunicationServerLLGS::HandleInferiorState_Exited(
// We are ready to exit the debug monitor.
m_exit_now = true;
+ m_mainloop.RequestTermination();
}
void GDBRemoteCommunicationServerLLGS::HandleInferiorState_Stopped(
@@ -1316,12 +1292,12 @@ GDBRemoteCommunicationServerLLGS::Handle_qC(StringExtractorGDBRemote &packet) {
lldb::tid_t tid = m_debugged_process_up->GetCurrentThreadID();
SetCurrentThreadID(tid);
- NativeThreadProtocolSP thread_sp = m_debugged_process_up->GetCurrentThread();
- if (!thread_sp)
+ NativeThreadProtocol *thread = m_debugged_process_up->GetCurrentThread();
+ if (!thread)
return SendErrorResponse(69);
StreamString response;
- response.Printf("QC%" PRIx64, thread_sp->GetID());
+ response.Printf("QC%" PRIx64, thread->GetID());
return SendPacketNoLock(response.GetString());
}
@@ -1692,14 +1668,12 @@ GDBRemoteCommunicationServerLLGS::Handle_qRegisterInfo(
return SendErrorResponse(68);
// Ensure we have a thread.
- NativeThreadProtocolSP thread_sp(m_debugged_process_up->GetThreadAtIndex(0));
- if (!thread_sp)
+ NativeThreadProtocol *thread = m_debugged_process_up->GetThreadAtIndex(0);
+ if (!thread)
return SendErrorResponse(69);
// Get the register context for the first thread.
- NativeRegisterContextSP reg_context_sp(thread_sp->GetRegisterContext());
- if (!reg_context_sp)
- return SendErrorResponse(69);
+ NativeRegisterContext &reg_context = thread->GetRegisterContext();
// Parse out the register number from the request.
packet.SetFilePos(strlen("qRegisterInfo"));
@@ -1710,11 +1684,10 @@ GDBRemoteCommunicationServerLLGS::Handle_qRegisterInfo(
// Return the end of registers response if we've iterated one past the end of
// the register set.
- if (reg_index >= reg_context_sp->GetUserRegisterCount())
+ if (reg_index >= reg_context.GetUserRegisterCount())
return SendErrorResponse(69);
- const RegisterInfo *reg_info =
- reg_context_sp->GetRegisterInfoAtIndex(reg_index);
+ const RegisterInfo *reg_info = reg_context.GetRegisterInfoAtIndex(reg_index);
if (!reg_info)
return SendErrorResponse(69);
@@ -1796,7 +1769,7 @@ GDBRemoteCommunicationServerLLGS::Handle_qRegisterInfo(
};
const char *const register_set_name =
- reg_context_sp->GetRegisterSetNameForRegisterAtIndex(reg_index);
+ reg_context.GetRegisterSetNameForRegisterAtIndex(reg_index);
if (register_set_name) {
response.PutCString("set:");
response.PutCString(register_set_name);
@@ -1908,18 +1881,17 @@ GDBRemoteCommunicationServerLLGS::Handle_qfThreadInfo(
response.PutChar('m');
LLDB_LOG(log, "starting thread iteration");
- NativeThreadProtocolSP thread_sp;
+ NativeThreadProtocol *thread;
uint32_t thread_index;
for (thread_index = 0,
- thread_sp = m_debugged_process_up->GetThreadAtIndex(thread_index);
- thread_sp; ++thread_index,
- thread_sp = m_debugged_process_up->GetThreadAtIndex(thread_index)) {
- LLDB_LOG(log, "iterated thread {0}({1}, tid={2})", thread_index,
- thread_sp ? "is not null" : "null",
- thread_sp ? thread_sp->GetID() : LLDB_INVALID_THREAD_ID);
+ thread = m_debugged_process_up->GetThreadAtIndex(thread_index);
+ thread; ++thread_index,
+ thread = m_debugged_process_up->GetThreadAtIndex(thread_index)) {
+ LLDB_LOG(log, "iterated thread {0}(tid={2})", thread_index,
+ thread->GetID());
if (thread_index > 0)
response.PutChar(',');
- response.Printf("%" PRIx64, thread_sp->GetID());
+ response.Printf("%" PRIx64, thread->GetID());
}
LLDB_LOG(log, "finished thread iteration");
@@ -1951,38 +1923,27 @@ GDBRemoteCommunicationServerLLGS::Handle_p(StringExtractorGDBRemote &packet) {
}
// Get the thread to use.
- NativeThreadProtocolSP thread_sp = GetThreadFromSuffix(packet);
- if (!thread_sp) {
- if (log)
- log->Printf(
- "GDBRemoteCommunicationServerLLGS::%s failed, no thread available",
- __FUNCTION__);
+ NativeThreadProtocol *thread = GetThreadFromSuffix(packet);
+ if (!thread) {
+ LLDB_LOG(log, "failed, no thread available");
return SendErrorResponse(0x15);
}
// Get the thread's register context.
- NativeRegisterContextSP reg_context_sp(thread_sp->GetRegisterContext());
- if (!reg_context_sp) {
- LLDB_LOG(
- log,
- "pid {0} tid {1} failed, no register context available for the thread",
- m_debugged_process_up->GetID(), thread_sp->GetID());
- return SendErrorResponse(0x15);
- }
+ NativeRegisterContext &reg_context = thread->GetRegisterContext();
// Return the end of registers response if we've iterated one past the end of
// the register set.
- if (reg_index >= reg_context_sp->GetUserRegisterCount()) {
+ if (reg_index >= reg_context.GetUserRegisterCount()) {
if (log)
log->Printf("GDBRemoteCommunicationServerLLGS::%s failed, requested "
"register %" PRIu32 " beyond register count %" PRIu32,
__FUNCTION__, reg_index,
- reg_context_sp->GetUserRegisterCount());
+ reg_context.GetUserRegisterCount());
return SendErrorResponse(0x15);
}
- const RegisterInfo *reg_info =
- reg_context_sp->GetRegisterInfoAtIndex(reg_index);
+ const RegisterInfo *reg_info = reg_context.GetRegisterInfoAtIndex(reg_index);
if (!reg_info) {
if (log)
log->Printf("GDBRemoteCommunicationServerLLGS::%s failed, requested "
@@ -1996,7 +1957,7 @@ GDBRemoteCommunicationServerLLGS::Handle_p(StringExtractorGDBRemote &packet) {
// Retrieve the value
RegisterValue reg_value;
- Status error = reg_context_sp->ReadRegister(reg_info, reg_value);
+ Status error = reg_context.ReadRegister(reg_info, reg_value);
if (error.Fail()) {
if (log)
log->Printf("GDBRemoteCommunicationServerLLGS::%s failed, read of "
@@ -2047,24 +2008,13 @@ GDBRemoteCommunicationServerLLGS::Handle_P(StringExtractorGDBRemote &packet) {
return SendIllFormedResponse(
packet, "P packet missing '=' char after register number");
- // Get process architecture.
- ArchSpec process_arch;
- if (!m_debugged_process_up ||
- !m_debugged_process_up->GetArchitecture(process_arch)) {
- if (log)
- log->Printf("GDBRemoteCommunicationServerLLGS::%s failed to retrieve "
- "inferior architecture",
- __FUNCTION__);
- return SendErrorResponse(0x49);
- }
-
// Parse out the value.
uint8_t reg_bytes[32]; // big enough to support up to 256 bit ymmN register
size_t reg_size = packet.GetHexBytesAvail(reg_bytes);
// Get the thread to use.
- NativeThreadProtocolSP thread_sp = GetThreadFromSuffix(packet);
- if (!thread_sp) {
+ NativeThreadProtocol *thread = GetThreadFromSuffix(packet);
+ if (!thread) {
if (log)
log->Printf("GDBRemoteCommunicationServerLLGS::%s failed, no thread "
"available (thread index 0)",
@@ -2073,18 +2023,8 @@ GDBRemoteCommunicationServerLLGS::Handle_P(StringExtractorGDBRemote &packet) {
}
// Get the thread's register context.
- NativeRegisterContextSP reg_context_sp(thread_sp->GetRegisterContext());
- if (!reg_context_sp) {
- if (log)
- log->Printf(
- "GDBRemoteCommunicationServerLLGS::%s pid %" PRIu64 " tid %" PRIu64
- " failed, no register context available for the thread",
- __FUNCTION__, m_debugged_process_up->GetID(), thread_sp->GetID());
- return SendErrorResponse(0x15);
- }
-
- const RegisterInfo *reg_info =
- reg_context_sp->GetRegisterInfoAtIndex(reg_index);
+ NativeRegisterContext &reg_context = thread->GetRegisterContext();
+ const RegisterInfo *reg_info = reg_context.GetRegisterInfoAtIndex(reg_index);
if (!reg_info) {
if (log)
log->Printf("GDBRemoteCommunicationServerLLGS::%s failed, requested "
@@ -2095,12 +2035,11 @@ GDBRemoteCommunicationServerLLGS::Handle_P(StringExtractorGDBRemote &packet) {
// Return the end of registers response if we've iterated one past the end of
// the register set.
- if (reg_index >= reg_context_sp->GetUserRegisterCount()) {
+ if (reg_index >= reg_context.GetUserRegisterCount()) {
if (log)
log->Printf("GDBRemoteCommunicationServerLLGS::%s failed, requested "
"register %" PRIu32 " beyond register count %" PRIu32,
- __FUNCTION__, reg_index,
- reg_context_sp->GetUserRegisterCount());
+ __FUNCTION__, reg_index, reg_context.GetUserRegisterCount());
return SendErrorResponse(0x47);
}
@@ -2115,8 +2054,10 @@ GDBRemoteCommunicationServerLLGS::Handle_P(StringExtractorGDBRemote &packet) {
// Build the reginfos response.
StreamGDBRemote response;
- RegisterValue reg_value(reg_bytes, reg_size, process_arch.GetByteOrder());
- Status error = reg_context_sp->WriteRegister(reg_info, reg_value);
+ RegisterValue reg_value(
+ reg_bytes, reg_size,
+ m_debugged_process_up->GetArchitecture().GetByteOrder());
+ Status error = reg_context.WriteRegister(reg_info, reg_value);
if (error.Fail()) {
if (log)
log->Printf("GDBRemoteCommunicationServerLLGS::%s failed, write of "
@@ -2177,8 +2118,8 @@ GDBRemoteCommunicationServerLLGS::Handle_H(StringExtractorGDBRemote &packet) {
// Ensure we have the given thread when not specifying -1 (all threads) or 0
// (any thread).
if (tid != LLDB_INVALID_THREAD_ID && tid != 0) {
- NativeThreadProtocolSP thread_sp(m_debugged_process_up->GetThreadByID(tid));
- if (!thread_sp) {
+ NativeThreadProtocol *thread = m_debugged_process_up->GetThreadByID(tid);
+ if (!thread) {
if (log)
log->Printf("GDBRemoteCommunicationServerLLGS::%s failed, tid %" PRIu64
" not found",
@@ -2739,8 +2680,8 @@ GDBRemoteCommunicationServerLLGS::Handle_s(StringExtractorGDBRemote &packet) {
// Double check that we have such a thread.
// TODO investigate: on MacOSX we might need to do an UpdateThreads () here.
- NativeThreadProtocolSP thread_sp = m_debugged_process_up->GetThreadByID(tid);
- if (!thread_sp || thread_sp->GetID() != tid)
+ NativeThreadProtocol *thread = m_debugged_process_up->GetThreadByID(tid);
+ if (!thread)
return SendErrorResponse(0x33);
// Create the step action for the given thread.
@@ -2865,8 +2806,8 @@ GDBRemoteCommunicationServerLLGS::Handle_QSaveRegisterState(
packet.SetFilePos(strlen("QSaveRegisterState"));
// Get the thread to use.
- NativeThreadProtocolSP thread_sp = GetThreadFromSuffix(packet);
- if (!thread_sp) {
+ NativeThreadProtocol *thread = GetThreadFromSuffix(packet);
+ if (!thread) {
if (m_thread_suffix_supported)
return SendIllFormedResponse(
packet, "No thread specified in QSaveRegisterState packet");
@@ -2876,18 +2817,11 @@ GDBRemoteCommunicationServerLLGS::Handle_QSaveRegisterState(
}
// Grab the register context for the thread.
- NativeRegisterContextSP reg_context_sp(thread_sp->GetRegisterContext());
- if (!reg_context_sp) {
- LLDB_LOG(
- log,
- "pid {0} tid {1} failed, no register context available for the thread",
- m_debugged_process_up->GetID(), thread_sp->GetID());
- return SendErrorResponse(0x15);
- }
+ NativeRegisterContext& reg_context = thread->GetRegisterContext();
// Save registers to a buffer.
DataBufferSP register_data_sp;
- Status error = reg_context_sp->ReadAllRegisterValues(register_data_sp);
+ Status error = reg_context.ReadAllRegisterValues(register_data_sp);
if (error.Fail()) {
LLDB_LOG(log, "pid {0} failed to save all register values: {1}",
m_debugged_process_up->GetID(), error);
@@ -2930,8 +2864,8 @@ GDBRemoteCommunicationServerLLGS::Handle_QRestoreRegisterState(
}
// Get the thread to use.
- NativeThreadProtocolSP thread_sp = GetThreadFromSuffix(packet);
- if (!thread_sp) {
+ NativeThreadProtocol *thread = GetThreadFromSuffix(packet);
+ if (!thread) {
if (m_thread_suffix_supported)
return SendIllFormedResponse(
packet, "No thread specified in QRestoreRegisterState packet");
@@ -2941,14 +2875,7 @@ GDBRemoteCommunicationServerLLGS::Handle_QRestoreRegisterState(
}
// Grab the register context for the thread.
- NativeRegisterContextSP reg_context_sp(thread_sp->GetRegisterContext());
- if (!reg_context_sp) {
- LLDB_LOG(
- log,
- "pid {0} tid {1} failed, no register context available for the thread",
- m_debugged_process_up->GetID(), thread_sp->GetID());
- return SendErrorResponse(0x15);
- }
+ NativeRegisterContext &reg_context = thread->GetRegisterContext();
// Retrieve register state buffer, then remove from the list.
DataBufferSP register_data_sp;
@@ -2969,7 +2896,7 @@ GDBRemoteCommunicationServerLLGS::Handle_QRestoreRegisterState(
m_saved_registers_map.erase(it);
}
- Status error = reg_context_sp->WriteAllRegisterValues(register_data_sp);
+ Status error = reg_context.WriteAllRegisterValues(register_data_sp);
if (error.Fail()) {
LLDB_LOG(log, "pid {0} failed to restore all register values: {1}",
m_debugged_process_up->GetID(), error);
@@ -3219,14 +3146,12 @@ void GDBRemoteCommunicationServerLLGS::MaybeCloseInferiorTerminalConnection() {
}
}
-NativeThreadProtocolSP GDBRemoteCommunicationServerLLGS::GetThreadFromSuffix(
+NativeThreadProtocol *GDBRemoteCommunicationServerLLGS::GetThreadFromSuffix(
StringExtractorGDBRemote &packet) {
- NativeThreadProtocolSP thread_sp;
-
// We have no thread if we don't have a process.
if (!m_debugged_process_up ||
m_debugged_process_up->GetID() == LLDB_INVALID_PROCESS_ID)
- return thread_sp;
+ return nullptr;
// If the client hasn't asked for thread suffix support, there will not be a
// thread suffix.
@@ -3234,7 +3159,7 @@ NativeThreadProtocolSP GDBRemoteCommunicationServerLLGS::GetThreadFromSuffix(
if (!m_thread_suffix_supported) {
const lldb::tid_t current_tid = GetCurrentThreadID();
if (current_tid == LLDB_INVALID_THREAD_ID)
- return thread_sp;
+ return nullptr;
else if (current_tid == 0) {
// Pick a thread.
return m_debugged_process_up->GetThreadAtIndex(0);
@@ -3251,11 +3176,11 @@ NativeThreadProtocolSP GDBRemoteCommunicationServerLLGS::GetThreadFromSuffix(
"error: expected ';' prior to start of thread suffix: packet "
"contents = '%s'",
__FUNCTION__, packet.GetStringRef().c_str());
- return thread_sp;
+ return nullptr;
}
if (!packet.GetBytesLeft())
- return thread_sp;
+ return nullptr;
// Parse out thread: portion.
if (strncmp(packet.Peek(), "thread:", strlen("thread:")) != 0) {
@@ -3264,14 +3189,14 @@ NativeThreadProtocolSP GDBRemoteCommunicationServerLLGS::GetThreadFromSuffix(
"error: expected 'thread:' but not found, packet contents = "
"'%s'",
__FUNCTION__, packet.GetStringRef().c_str());
- return thread_sp;
+ return nullptr;
}
packet.SetFilePos(packet.GetFilePos() + strlen("thread:"));
const lldb::tid_t tid = packet.GetHexMaxU64(false, 0);
if (tid != 0)
return m_debugged_process_up->GetThreadByID(tid);
- return thread_sp;
+ return nullptr;
}
lldb::tid_t GDBRemoteCommunicationServerLLGS::GetCurrentThreadID() const {