aboutsummaryrefslogtreecommitdiffstats
path: root/source/Plugins/Process/gdb-remote
diff options
context:
space:
mode:
Diffstat (limited to 'source/Plugins/Process/gdb-remote')
-rw-r--r--source/Plugins/Process/gdb-remote/GDBRemoteClientBase.cpp70
-rw-r--r--source/Plugins/Process/gdb-remote/GDBRemoteClientBase.h66
-rw-r--r--source/Plugins/Process/gdb-remote/GDBRemoteCommunication.cpp206
-rw-r--r--source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.cpp184
-rw-r--r--source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.h8
-rw-r--r--source/Plugins/Process/gdb-remote/GDBRemoteCommunicationHistory.cpp75
-rw-r--r--source/Plugins/Process/gdb-remote/GDBRemoteCommunicationHistory.h85
-rw-r--r--source/Plugins/Process/gdb-remote/GDBRemoteCommunicationReplayServer.cpp18
-rw-r--r--source/Plugins/Process/gdb-remote/GDBRemoteCommunicationReplayServer.h2
-rw-r--r--source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServer.cpp12
-rw-r--r--source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerCommon.cpp106
-rw-r--r--source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerLLGS.cpp664
-rw-r--r--source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerLLGS.h2
-rw-r--r--source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerPlatform.cpp56
-rw-r--r--source/Plugins/Process/gdb-remote/GDBRemoteRegisterContext.cpp55
-rw-r--r--source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp781
-rw-r--r--source/Plugins/Process/gdb-remote/ProcessGDBRemote.h10
-rw-r--r--source/Plugins/Process/gdb-remote/ProcessGDBRemoteProperties.td16
-rw-r--r--source/Plugins/Process/gdb-remote/ThreadGDBRemote.cpp8
19 files changed, 1176 insertions, 1248 deletions
diff --git a/source/Plugins/Process/gdb-remote/GDBRemoteClientBase.cpp b/source/Plugins/Process/gdb-remote/GDBRemoteClientBase.cpp
index fe7ef6b3acea..064bbde8442e 100644
--- a/source/Plugins/Process/gdb-remote/GDBRemoteClientBase.cpp
+++ b/source/Plugins/Process/gdb-remote/GDBRemoteClientBase.cpp
@@ -63,18 +63,16 @@ StateType GDBRemoteClientBase::SendContinuePacketAndWaitForResponse(
case PacketResult::Success:
break;
default:
- if (log)
- log->Printf("GDBRemoteClientBase::%s () ReadPacket(...) => false",
- __FUNCTION__);
+ LLDB_LOGF(log, "GDBRemoteClientBase::%s () ReadPacket(...) => false",
+ __FUNCTION__);
return eStateInvalid;
}
if (response.Empty())
return eStateInvalid;
const char stop_type = response.GetChar();
- if (log)
- log->Printf("GDBRemoteClientBase::%s () got packet: %s", __FUNCTION__,
- response.GetStringRef().c_str());
+ LLDB_LOGF(log, "GDBRemoteClientBase::%s () got packet: %s", __FUNCTION__,
+ response.GetStringRef().data());
switch (stop_type) {
case 'W':
@@ -84,9 +82,8 @@ StateType GDBRemoteClientBase::SendContinuePacketAndWaitForResponse(
// ERROR
return eStateInvalid;
default:
- if (log)
- log->Printf("GDBRemoteClientBase::%s () unrecognized async packet",
- __FUNCTION__);
+ LLDB_LOGF(log, "GDBRemoteClientBase::%s () unrecognized async packet",
+ __FUNCTION__);
return eStateInvalid;
case 'O': {
std::string inferior_stdout;
@@ -162,10 +159,10 @@ GDBRemoteClientBase::SendPacketAndWaitForResponse(
if (!lock) {
if (Log *log =
ProcessGDBRemoteLog::GetLogIfAllCategoriesSet(GDBR_LOG_PROCESS))
- log->Printf("GDBRemoteClientBase::%s failed to get mutex, not sending "
- "packet '%.*s' (send_async=%d)",
- __FUNCTION__, int(payload.size()), payload.data(),
- send_async);
+ LLDB_LOGF(log,
+ "GDBRemoteClientBase::%s failed to get mutex, not sending "
+ "packet '%.*s' (send_async=%d)",
+ __FUNCTION__, int(payload.size()), payload.data(), send_async);
return PacketResult::ErrorSendFailed;
}
@@ -181,10 +178,10 @@ GDBRemoteClientBase::SendPacketAndReceiveResponseWithOutputSupport(
if (!lock) {
if (Log *log =
ProcessGDBRemoteLog::GetLogIfAllCategoriesSet(GDBR_LOG_PROCESS))
- log->Printf("GDBRemoteClientBase::%s failed to get mutex, not sending "
- "packet '%.*s' (send_async=%d)",
- __FUNCTION__, int(payload.size()), payload.data(),
- send_async);
+ LLDB_LOGF(log,
+ "GDBRemoteClientBase::%s failed to get mutex, not sending "
+ "packet '%.*s' (send_async=%d)",
+ __FUNCTION__, int(payload.size()), payload.data(), send_async);
return PacketResult::ErrorSendFailed;
}
@@ -214,13 +211,13 @@ GDBRemoteClientBase::SendPacketAndWaitForResponseNoLock(
return packet_result;
// Response says it wasn't valid
Log *log = ProcessGDBRemoteLog::GetLogIfAllCategoriesSet(GDBR_LOG_PACKETS);
- if (log)
- log->Printf(
- "error: packet with payload \"%.*s\" got invalid response \"%s\": %s",
- int(payload.size()), payload.data(), response.GetStringRef().c_str(),
- (i == (max_response_retries - 1))
- ? "using invalid response and giving up"
- : "ignoring response and waiting for another");
+ LLDB_LOGF(
+ log,
+ "error: packet with payload \"%.*s\" got invalid response \"%s\": %s",
+ int(payload.size()), payload.data(), response.GetStringRef().data(),
+ (i == (max_response_retries - 1))
+ ? "using invalid response and giving up"
+ : "ignoring response and waiting for another");
}
return packet_result;
}
@@ -228,16 +225,14 @@ GDBRemoteClientBase::SendPacketAndWaitForResponseNoLock(
bool GDBRemoteClientBase::SendvContPacket(llvm::StringRef payload,
StringExtractorGDBRemote &response) {
Log *log(ProcessGDBRemoteLog::GetLogIfAllCategoriesSet(GDBR_LOG_PROCESS));
- if (log)
- log->Printf("GDBRemoteCommunicationClient::%s ()", __FUNCTION__);
+ LLDB_LOGF(log, "GDBRemoteCommunicationClient::%s ()", __FUNCTION__);
// we want to lock down packet sending while we continue
Lock lock(*this, true);
- if (log)
- log->Printf(
- "GDBRemoteCommunicationClient::%s () sending vCont packet: %.*s",
- __FUNCTION__, int(payload.size()), payload.data());
+ LLDB_LOGF(log,
+ "GDBRemoteCommunicationClient::%s () sending vCont packet: %.*s",
+ __FUNCTION__, int(payload.size()), payload.data());
if (SendPacketNoLock(payload) != PacketResult::Success)
return false;
@@ -315,18 +310,16 @@ void GDBRemoteClientBase::ContinueLock::unlock() {
GDBRemoteClientBase::ContinueLock::LockResult
GDBRemoteClientBase::ContinueLock::lock() {
Log *log = ProcessGDBRemoteLog::GetLogIfAllCategoriesSet(GDBR_LOG_PROCESS);
- if (log)
- log->Printf("GDBRemoteClientBase::ContinueLock::%s() resuming with %s",
- __FUNCTION__, m_comm.m_continue_packet.c_str());
+ LLDB_LOGF(log, "GDBRemoteClientBase::ContinueLock::%s() resuming with %s",
+ __FUNCTION__, m_comm.m_continue_packet.c_str());
lldbassert(!m_acquired);
std::unique_lock<std::mutex> lock(m_comm.m_mutex);
m_comm.m_cv.wait(lock, [this] { return m_comm.m_async_count == 0; });
if (m_comm.m_should_stop) {
m_comm.m_should_stop = false;
- if (log)
- log->Printf("GDBRemoteClientBase::ContinueLock::%s() cancelled",
- __FUNCTION__);
+ LLDB_LOGF(log, "GDBRemoteClientBase::ContinueLock::%s() cancelled",
+ __FUNCTION__);
return LockResult::Cancelled;
}
if (m_comm.SendPacketNoLock(m_comm.m_continue_packet) !=
@@ -368,9 +361,8 @@ void GDBRemoteClientBase::Lock::SyncWithContinueThread(bool interrupt) {
size_t bytes_written = m_comm.Write(&ctrl_c, 1, status, nullptr);
if (bytes_written == 0) {
--m_comm.m_async_count;
- if (log)
- log->Printf("GDBRemoteClientBase::Lock::Lock failed to send "
- "interrupt packet");
+ LLDB_LOGF(log, "GDBRemoteClientBase::Lock::Lock failed to send "
+ "interrupt packet");
return;
}
if (log)
diff --git a/source/Plugins/Process/gdb-remote/GDBRemoteClientBase.h b/source/Plugins/Process/gdb-remote/GDBRemoteClientBase.h
index 54f69e8caac6..ea294ffcef26 100644
--- a/source/Plugins/Process/gdb-remote/GDBRemoteClientBase.h
+++ b/source/Plugins/Process/gdb-remote/GDBRemoteClientBase.h
@@ -24,12 +24,10 @@ public:
virtual void HandleAsyncMisc(llvm::StringRef data) = 0;
virtual void HandleStopReply() = 0;
- // =========================================================================
/// Process asynchronously-received structured data.
///
/// \param[in] data
/// The complete data packet, expected to start with JSON-async.
- // =========================================================================
virtual void HandleAsyncStructuredDataPacket(llvm::StringRef data) = 0;
};
@@ -83,42 +81,48 @@ protected:
virtual void OnRunPacketSent(bool first);
private:
- // Variables handling synchronization between the Continue thread and any
- // other threads
- // wishing to send packets over the connection. Either the continue thread has
- // control over
- // the connection (m_is_running == true) or the connection is free for an
- // arbitrary number of
- // other senders to take which indicate their interest by incrementing
- // m_async_count.
- // Semantics of individual states:
- // - m_continue_packet == false, m_async_count == 0: connection is free
- // - m_continue_packet == true, m_async_count == 0: only continue thread is
- // present
- // - m_continue_packet == true, m_async_count > 0: continue thread has
- // control, async threads
- // should interrupt it and wait for it to set m_continue_packet to false
- // - m_continue_packet == false, m_async_count > 0: async threads have
- // control, continue
- // thread needs to wait for them to finish (m_async_count goes down to 0).
+ /// Variables handling synchronization between the Continue thread and any
+ /// other threads wishing to send packets over the connection. Either the
+ /// continue thread has control over the connection (m_is_running == true) or
+ /// the connection is free for an arbitrary number of other senders to take
+ /// which indicate their interest by incrementing m_async_count.
+ ///
+ /// Semantics of individual states:
+ ///
+ /// - m_continue_packet == false, m_async_count == 0:
+ /// connection is free
+ /// - m_continue_packet == true, m_async_count == 0:
+ /// only continue thread is present
+ /// - m_continue_packet == true, m_async_count > 0:
+ /// continue thread has control, async threads should interrupt it and wait
+ /// for it to set m_continue_packet to false
+ /// - m_continue_packet == false, m_async_count > 0:
+ /// async threads have control, continue thread needs to wait for them to
+ /// finish (m_async_count goes down to 0).
+ /// @{
std::mutex m_mutex;
std::condition_variable m_cv;
- // Packet with which to resume after an async interrupt. Can be changed by an
- // async thread
- // e.g. to inject a signal.
+
+ /// Packet with which to resume after an async interrupt. Can be changed by
+ /// an async thread e.g. to inject a signal.
std::string m_continue_packet;
- // When was the interrupt packet sent. Used to make sure we time out if the
- // stub does not
- // respond to interrupt requests.
+
+ /// When was the interrupt packet sent. Used to make sure we time out if the
+ /// stub does not respond to interrupt requests.
std::chrono::time_point<std::chrono::steady_clock> m_interrupt_time;
+
+ /// Number of threads interested in sending.
uint32_t m_async_count;
+
+ /// Whether the continue thread has control.
bool m_is_running;
- bool m_should_stop; // Whether we should resume after a stop.
- // end of continue thread synchronization block
- // This handles the synchronization between individual async threads. For now
- // they just use a
- // simple mutex.
+ /// Whether we should resume after a stop.
+ bool m_should_stop;
+ /// @}
+
+ /// This handles the synchronization between individual async threads. For
+ /// now they just use a simple mutex.
std::recursive_mutex m_async_mutex;
bool ShouldStop(const UnixSignals &signals,
diff --git a/source/Plugins/Process/gdb-remote/GDBRemoteCommunication.cpp b/source/Plugins/Process/gdb-remote/GDBRemoteCommunication.cpp
index 11052eff948f..144ae103faa4 100644
--- a/source/Plugins/Process/gdb-remote/GDBRemoteCommunication.cpp
+++ b/source/Plugins/Process/gdb-remote/GDBRemoteCommunication.cpp
@@ -14,6 +14,7 @@
#include <sys/stat.h>
#include "lldb/Core/StreamFile.h"
+#include "lldb/Host/Config.h"
#include "lldb/Host/ConnectionFileDescriptor.h"
#include "lldb/Host/FileSystem.h"
#include "lldb/Host/Host.h"
@@ -38,6 +39,8 @@
#if defined(__APPLE__)
#define DEBUGSERVER_BASENAME "debugserver"
+#elif defined(_WIN32)
+#define DEBUGSERVER_BASENAME "lldb-server.exe"
#else
#define DEBUGSERVER_BASENAME "lldb-server"
#endif
@@ -99,10 +102,8 @@ size_t GDBRemoteCommunication::SendAck() {
ConnectionStatus status = eConnectionStatusSuccess;
char ch = '+';
const size_t bytes_written = Write(&ch, 1, status, nullptr);
- if (log)
- log->Printf("<%4" PRIu64 "> send packet: %c", (uint64_t)bytes_written, ch);
- m_history.AddPacket(ch, GDBRemoteCommunicationHistory::ePacketTypeSend,
- bytes_written);
+ LLDB_LOGF(log, "<%4" PRIu64 "> send packet: %c", (uint64_t)bytes_written, ch);
+ m_history.AddPacket(ch, GDBRemotePacket::ePacketTypeSend, bytes_written);
return bytes_written;
}
@@ -111,10 +112,8 @@ size_t GDBRemoteCommunication::SendNack() {
ConnectionStatus status = eConnectionStatusSuccess;
char ch = '-';
const size_t bytes_written = Write(&ch, 1, status, nullptr);
- if (log)
- log->Printf("<%4" PRIu64 "> send packet: %c", (uint64_t)bytes_written, ch);
- m_history.AddPacket(ch, GDBRemoteCommunicationHistory::ePacketTypeSend,
- bytes_written);
+ LLDB_LOGF(log, "<%4" PRIu64 "> send packet: %c", (uint64_t)bytes_written, ch);
+ m_history.AddPacket(ch, GDBRemotePacket::ePacketTypeSend, bytes_written);
return bytes_written;
}
@@ -172,13 +171,12 @@ GDBRemoteCommunication::SendRawPacketNoLock(llvm::StringRef packet,
strm.Printf("%*s", (int)3, p);
log->PutString(strm.GetString());
} else
- log->Printf("<%4" PRIu64 "> send packet: %.*s", (uint64_t)bytes_written,
- (int)packet_length, packet_data);
+ LLDB_LOGF(log, "<%4" PRIu64 "> send packet: %.*s",
+ (uint64_t)bytes_written, (int)packet_length, packet_data);
}
m_history.AddPacket(packet.str(), packet_length,
- GDBRemoteCommunicationHistory::ePacketTypeSend,
- bytes_written);
+ GDBRemotePacket::ePacketTypeSend, bytes_written);
if (bytes_written == packet_length) {
if (!skip_ack && GetSendAcks())
@@ -186,9 +184,8 @@ GDBRemoteCommunication::SendRawPacketNoLock(llvm::StringRef packet,
else
return PacketResult::Success;
} else {
- if (log)
- log->Printf("error: failed to send packet: %.*s", (int)packet_length,
- packet_data);
+ LLDB_LOGF(log, "error: failed to send packet: %.*s", (int)packet_length,
+ packet_data);
}
}
return PacketResult::ErrorSendFailed;
@@ -332,11 +329,12 @@ GDBRemoteCommunication::WaitForPacketNoLock(StringExtractorGDBRemote &packet,
std::string regex_str = "^";
regex_str += echo_packet;
regex_str += "$";
- response_regex.Compile(regex_str);
+ response_regex = RegularExpression(regex_str);
} else {
echo_packet_len =
::snprintf(echo_packet, sizeof(echo_packet), "qC");
- response_regex.Compile(llvm::StringRef("^QC[0-9A-Fa-f]+$"));
+ response_regex =
+ RegularExpression(llvm::StringRef("^QC[0-9A-Fa-f]+$"));
}
PacketResult echo_packet_result =
@@ -489,11 +487,10 @@ bool GDBRemoteCommunication::DecompressPacket() {
llvm::StringRef(m_bytes).substr(1, hash_mark_idx - 1));
bool success = packet_checksum == actual_checksum;
if (!success) {
- if (log)
- log->Printf(
- "error: checksum mismatch: %.*s expected 0x%2.2x, got 0x%2.2x",
- (int)(pkt_size), m_bytes.c_str(), (uint8_t)packet_checksum,
- (uint8_t)actual_checksum);
+ LLDB_LOGF(log,
+ "error: checksum mismatch: %.*s expected 0x%2.2x, got 0x%2.2x",
+ (int)(pkt_size), m_bytes.c_str(), (uint8_t)packet_checksum,
+ (uint8_t)actual_checksum);
}
// Send the ack or nack if needed
if (!success) {
@@ -651,8 +648,8 @@ GDBRemoteCommunication::CheckForPacket(const uint8_t *src, size_t src_len,
if (src && src_len > 0) {
if (log && log->GetVerbose()) {
StreamString s;
- log->Printf("GDBRemoteCommunication::%s adding %u bytes: %.*s",
- __FUNCTION__, (uint32_t)src_len, (uint32_t)src_len, src);
+ LLDB_LOGF(log, "GDBRemoteCommunication::%s adding %u bytes: %.*s",
+ __FUNCTION__, (uint32_t)src_len, (uint32_t)src_len, src);
}
m_bytes.append((const char *)src, src_len);
}
@@ -733,9 +730,8 @@ GDBRemoteCommunication::CheckForPacket(const uint8_t *src, size_t src_len,
break;
}
}
- if (log)
- log->Printf("GDBRemoteCommunication::%s tossing %u junk bytes: '%.*s'",
- __FUNCTION__, idx - 1, idx - 1, m_bytes.c_str());
+ LLDB_LOGF(log, "GDBRemoteCommunication::%s tossing %u junk bytes: '%.*s'",
+ __FUNCTION__, idx - 1, idx - 1, m_bytes.c_str());
m_bytes.erase(0, idx - 1);
} break;
}
@@ -752,7 +748,6 @@ GDBRemoteCommunication::CheckForPacket(const uint8_t *src, size_t src_len,
size_t content_end = content_start + content_length;
bool success = true;
- std::string &packet_str = packet.GetStringRef();
if (log) {
// If logging was just enabled and we have history, then dump out what
// we have to the log so we get the historical context. The Dump() call
@@ -800,25 +795,23 @@ GDBRemoteCommunication::CheckForPacket(const uint8_t *src, size_t src_len,
log->PutString(strm.GetString());
} else {
if (CompressionIsEnabled())
- log->Printf("<%4" PRIu64 ":%" PRIu64 "> read packet: %.*s",
- (uint64_t)original_packet_size, (uint64_t)total_length,
- (int)(total_length), m_bytes.c_str());
+ LLDB_LOGF(log, "<%4" PRIu64 ":%" PRIu64 "> read packet: %.*s",
+ (uint64_t)original_packet_size, (uint64_t)total_length,
+ (int)(total_length), m_bytes.c_str());
else
- log->Printf("<%4" PRIu64 "> read packet: %.*s",
- (uint64_t)total_length, (int)(total_length),
- m_bytes.c_str());
+ LLDB_LOGF(log, "<%4" PRIu64 "> read packet: %.*s",
+ (uint64_t)total_length, (int)(total_length),
+ m_bytes.c_str());
}
}
m_history.AddPacket(m_bytes, total_length,
- GDBRemoteCommunicationHistory::ePacketTypeRecv,
- total_length);
+ GDBRemotePacket::ePacketTypeRecv, total_length);
- // Clear packet_str in case there is some existing data in it.
- packet_str.clear();
// Copy the packet from m_bytes to packet_str expanding the run-length
// encoding in the process. Reserve enough byte for the most common case
// (no RLE used)
+ std ::string packet_str;
packet_str.reserve(m_bytes.length());
for (std::string::const_iterator c = m_bytes.begin() + content_start;
c != m_bytes.begin() + content_end; ++c) {
@@ -841,6 +834,7 @@ GDBRemoteCommunication::CheckForPacket(const uint8_t *src, size_t src_len,
packet_str.push_back(*c);
}
}
+ packet = StringExtractorGDBRemote(packet_str);
if (m_bytes[0] == '$' || m_bytes[0] == '%') {
assert(checksum_idx < m_bytes.size());
@@ -853,11 +847,11 @@ GDBRemoteCommunication::CheckForPacket(const uint8_t *src, size_t src_len,
llvm::StringRef(m_bytes).slice(content_start, content_end));
success = packet_checksum == actual_checksum;
if (!success) {
- if (log)
- log->Printf("error: checksum mismatch: %.*s expected 0x%2.2x, "
- "got 0x%2.2x",
- (int)(total_length), m_bytes.c_str(),
- (uint8_t)packet_checksum, (uint8_t)actual_checksum);
+ LLDB_LOGF(log,
+ "error: checksum mismatch: %.*s expected 0x%2.2x, "
+ "got 0x%2.2x",
+ (int)(total_length), m_bytes.c_str(),
+ (uint8_t)packet_checksum, (uint8_t)actual_checksum);
}
// Send the ack or nack if needed
if (!success)
@@ -867,9 +861,8 @@ GDBRemoteCommunication::CheckForPacket(const uint8_t *src, size_t src_len,
}
} else {
success = false;
- if (log)
- log->Printf("error: invalid checksum in packet: '%s'\n",
- m_bytes.c_str());
+ LLDB_LOGF(log, "error: invalid checksum in packet: '%s'\n",
+ m_bytes.c_str());
}
}
@@ -933,10 +926,8 @@ Status GDBRemoteCommunication::StartDebugserverProcess(
const char *url, Platform *platform, ProcessLaunchInfo &launch_info,
uint16_t *port, const Args *inferior_args, int pass_comm_fd) {
Log *log(ProcessGDBRemoteLog::GetLogIfAllCategoriesSet(GDBR_LOG_PROCESS));
- if (log)
- log->Printf("GDBRemoteCommunication::%s(url=%s, port=%" PRIu16 ")",
- __FUNCTION__, url ? url : "<empty>",
- port ? *port : uint16_t(0));
+ LLDB_LOGF(log, "GDBRemoteCommunication::%s(url=%s, port=%" PRIu16 ")",
+ __FUNCTION__, url ? url : "<empty>", port ? *port : uint16_t(0));
Status error;
// If we locate debugserver, keep that located version around
@@ -953,10 +944,10 @@ Status GDBRemoteCommunication::StartDebugserverProcess(
if (!env_debugserver_path.empty()) {
debugserver_file_spec.SetFile(env_debugserver_path,
FileSpec::Style::native);
- if (log)
- log->Printf("GDBRemoteCommunication::%s() gdb-remote stub exe path set "
- "from environment variable: %s",
- __FUNCTION__, env_debugserver_path.c_str());
+ LLDB_LOGF(log,
+ "GDBRemoteCommunication::%s() gdb-remote stub exe path set "
+ "from environment variable: %s",
+ __FUNCTION__, env_debugserver_path.c_str());
} else
debugserver_file_spec = g_debugserver_file_spec;
bool debugserver_exists =
@@ -968,10 +959,9 @@ Status GDBRemoteCommunication::StartDebugserverProcess(
debugserver_file_spec.AppendPathComponent(DEBUGSERVER_BASENAME);
debugserver_exists = FileSystem::Instance().Exists(debugserver_file_spec);
if (debugserver_exists) {
- if (log)
- log->Printf(
- "GDBRemoteCommunication::%s() found gdb-remote stub exe '%s'",
- __FUNCTION__, debugserver_file_spec.GetPath().c_str());
+ LLDB_LOGF(log,
+ "GDBRemoteCommunication::%s() found gdb-remote stub exe '%s'",
+ __FUNCTION__, debugserver_file_spec.GetPath().c_str());
g_debugserver_file_spec = debugserver_file_spec;
} else {
@@ -985,10 +975,10 @@ Status GDBRemoteCommunication::StartDebugserverProcess(
// exist
debugserver_exists = true;
} else {
- if (log)
- log->Printf("GDBRemoteCommunication::%s() could not find "
- "gdb-remote stub exe '%s'",
- __FUNCTION__, debugserver_file_spec.GetPath().c_str());
+ LLDB_LOGF(log,
+ "GDBRemoteCommunication::%s() could not find "
+ "gdb-remote stub exe '%s'",
+ __FUNCTION__, debugserver_file_spec.GetPath().c_str());
}
// Don't cache the platform specific GDB server binary as it could
// change from platform to platform
@@ -1052,10 +1042,10 @@ Status GDBRemoteCommunication::StartDebugserverProcess(
error = socket_pipe.CreateWithUniqueName("debugserver-named-pipe",
false, named_pipe_path);
if (error.Fail()) {
- if (log)
- log->Printf("GDBRemoteCommunication::%s() "
- "named pipe creation failed: %s",
- __FUNCTION__, error.AsCString());
+ LLDB_LOGF(log,
+ "GDBRemoteCommunication::%s() "
+ "named pipe creation failed: %s",
+ __FUNCTION__, error.AsCString());
return error;
}
debugserver_args.AppendArgument(llvm::StringRef("--named-pipe"));
@@ -1065,10 +1055,10 @@ Status GDBRemoteCommunication::StartDebugserverProcess(
// using using an unnamed pipe...
error = socket_pipe.CreateNew(true);
if (error.Fail()) {
- if (log)
- log->Printf("GDBRemoteCommunication::%s() "
- "unnamed pipe creation failed: %s",
- __FUNCTION__, error.AsCString());
+ LLDB_LOGF(log,
+ "GDBRemoteCommunication::%s() "
+ "unnamed pipe creation failed: %s",
+ __FUNCTION__, error.AsCString());
return error;
}
pipe_t write = socket_pipe.GetWritePipe();
@@ -1081,10 +1071,10 @@ Status GDBRemoteCommunication::StartDebugserverProcess(
// debugserver connect to us..
error = StartListenThread("127.0.0.1", 0);
if (error.Fail()) {
- if (log)
- log->Printf("GDBRemoteCommunication::%s() unable to start listen "
- "thread: %s",
- __FUNCTION__, error.AsCString());
+ LLDB_LOGF(log,
+ "GDBRemoteCommunication::%s() unable to start listen "
+ "thread: %s",
+ __FUNCTION__, error.AsCString());
return error;
}
@@ -1104,9 +1094,8 @@ Status GDBRemoteCommunication::StartDebugserverProcess(
*port = port_;
} else {
error.SetErrorString("failed to bind to port 0 on 127.0.0.1");
- if (log)
- log->Printf("GDBRemoteCommunication::%s() failed: %s", __FUNCTION__,
- error.AsCString());
+ LLDB_LOGF(log, "GDBRemoteCommunication::%s() failed: %s",
+ __FUNCTION__, error.AsCString());
return error;
}
}
@@ -1148,10 +1137,10 @@ Status GDBRemoteCommunication::StartDebugserverProcess(
if (has_env_var) {
debugserver_args.AppendArgument(llvm::StringRef(extra_arg));
- if (log)
- log->Printf("GDBRemoteCommunication::%s adding env var %s contents "
- "to stub command line (%s)",
- __FUNCTION__, env_var_name, extra_arg.c_str());
+ LLDB_LOGF(log,
+ "GDBRemoteCommunication::%s adding env var %s contents "
+ "to stub command line (%s)",
+ __FUNCTION__, env_var_name, extra_arg.c_str());
}
} while (has_env_var);
@@ -1177,8 +1166,8 @@ Status GDBRemoteCommunication::StartDebugserverProcess(
StreamString string_stream;
Platform *const platform = nullptr;
launch_info.Dump(string_stream, platform);
- log->Printf("launch info for gdb-remote stub:\n%s",
- string_stream.GetData());
+ LLDB_LOGF(log, "launch info for gdb-remote stub:\n%s",
+ string_stream.GetData());
}
error = Host::LaunchProcess(launch_info);
@@ -1188,11 +1177,10 @@ Status GDBRemoteCommunication::StartDebugserverProcess(
if (named_pipe_path.size() > 0) {
error = socket_pipe.OpenAsReader(named_pipe_path, false);
if (error.Fail())
- if (log)
- log->Printf("GDBRemoteCommunication::%s() "
- "failed to open named pipe %s for reading: %s",
- __FUNCTION__, named_pipe_path.c_str(),
- error.AsCString());
+ LLDB_LOGF(log,
+ "GDBRemoteCommunication::%s() "
+ "failed to open named pipe %s for reading: %s",
+ __FUNCTION__, named_pipe_path.c_str(), error.AsCString());
}
if (socket_pipe.CanWrite())
@@ -1209,24 +1197,22 @@ Status GDBRemoteCommunication::StartDebugserverProcess(
uint16_t child_port = StringConvert::ToUInt32(port_cstr, 0);
if (*port == 0 || *port == child_port) {
*port = child_port;
- if (log)
- log->Printf("GDBRemoteCommunication::%s() "
- "debugserver listens %u port",
- __FUNCTION__, *port);
+ LLDB_LOGF(log,
+ "GDBRemoteCommunication::%s() "
+ "debugserver listens %u port",
+ __FUNCTION__, *port);
} else {
- if (log)
- log->Printf("GDBRemoteCommunication::%s() "
- "debugserver listening on port "
- "%d but requested port was %d",
- __FUNCTION__, (uint32_t)child_port,
- (uint32_t)(*port));
+ LLDB_LOGF(log,
+ "GDBRemoteCommunication::%s() "
+ "debugserver listening on port "
+ "%d but requested port was %d",
+ __FUNCTION__, (uint32_t)child_port, (uint32_t)(*port));
}
} else {
- if (log)
- log->Printf("GDBRemoteCommunication::%s() "
- "failed to read a port value from pipe %s: %s",
- __FUNCTION__, named_pipe_path.c_str(),
- error.AsCString());
+ LLDB_LOGF(log,
+ "GDBRemoteCommunication::%s() "
+ "failed to read a port value from pipe %s: %s",
+ __FUNCTION__, named_pipe_path.c_str(), error.AsCString());
}
socket_pipe.Close();
}
@@ -1234,10 +1220,9 @@ Status GDBRemoteCommunication::StartDebugserverProcess(
if (named_pipe_path.size() > 0) {
const auto err = socket_pipe.Delete(named_pipe_path);
if (err.Fail()) {
- if (log)
- log->Printf(
- "GDBRemoteCommunication::%s failed to delete pipe %s: %s",
- __FUNCTION__, named_pipe_path.c_str(), err.AsCString());
+ LLDB_LOGF(log,
+ "GDBRemoteCommunication::%s failed to delete pipe %s: %s",
+ __FUNCTION__, named_pipe_path.c_str(), err.AsCString());
}
}
@@ -1249,9 +1234,8 @@ Status GDBRemoteCommunication::StartDebugserverProcess(
}
if (error.Fail()) {
- if (log)
- log->Printf("GDBRemoteCommunication::%s() failed: %s", __FUNCTION__,
- error.AsCString());
+ LLDB_LOGF(log, "GDBRemoteCommunication::%s() failed: %s", __FUNCTION__,
+ error.AsCString());
}
return error;
@@ -1351,7 +1335,7 @@ void GDBRemoteCommunication::AppendBytesToCache(const uint8_t *bytes,
if (type == PacketType::Notify) {
// put this packet into an event
- const char *pdata = packet.GetStringRef().c_str();
+ const char *pdata = packet.GetStringRef().data();
// as the communication class, we are a broadcaster and the async thread
// is tuned to listen to us
diff --git a/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.cpp b/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.cpp
index 9797184026e0..feb9f0589cee 100644
--- a/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.cpp
+++ b/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.cpp
@@ -23,7 +23,6 @@
#include "lldb/Target/UnixSignals.h"
#include "lldb/Utility/Args.h"
#include "lldb/Utility/DataBufferHeap.h"
-#include "lldb/Utility/JSON.h"
#include "lldb/Utility/LLDBAssert.h"
#include "lldb/Utility/Log.h"
#include "lldb/Utility/State.h"
@@ -35,17 +34,15 @@
#include "lldb/Utility/StringExtractorGDBRemote.h"
#include "llvm/ADT/StringSwitch.h"
+#include "llvm/Support/JSON.h"
-#if defined(__APPLE__)
-#ifndef HAVE_LIBCOMPRESSION
-#define HAVE_LIBCOMPRESSION
-#endif
+#if defined(HAVE_LIBCOMPRESSION)
#include <compression.h>
#endif
using namespace lldb;
-using namespace lldb_private;
using namespace lldb_private::process_gdb_remote;
+using namespace lldb_private;
using namespace std::chrono;
// GDBRemoteCommunicationClient constructor
@@ -342,7 +339,7 @@ void GDBRemoteCommunicationClient::GetRemoteQSupported() {
// not, we assume no limit
// build the qSupported packet
- std::vector<std::string> features = {"xmlRegisters=i386,arm,mips"};
+ std::vector<std::string> features = {"xmlRegisters=i386,arm,mips,arc"};
StreamString packet;
packet.PutCString("qSupported");
for (uint32_t i = 0; i < features.size(); ++i) {
@@ -354,7 +351,7 @@ void GDBRemoteCommunicationClient::GetRemoteQSupported() {
if (SendPacketAndWaitForResponse(packet.GetString(), response,
/*send_async=*/false) ==
PacketResult::Success) {
- const char *response_cstr = response.GetStringRef().c_str();
+ const char *response_cstr = response.GetStringRef().data();
// Hang on to the qSupported packet, so that platforms can do custom
// configuration of the transport before attaching/launching the process.
@@ -439,8 +436,7 @@ void GDBRemoteCommunicationClient::GetRemoteQSupported() {
m_max_packet_size = UINT64_MAX; // Must have been a garbled response
Log *log(
ProcessGDBRemoteLog::GetLogIfAllCategoriesSet(GDBR_LOG_PROCESS));
- if (log)
- log->Printf("Garbled PacketSize spec in qSupported response");
+ LLDB_LOGF(log, "Garbled PacketSize spec in qSupported response");
}
}
}
@@ -469,7 +465,7 @@ bool GDBRemoteCommunicationClient::GetVContSupported(char flavor) {
m_supports_vCont_S = eLazyBoolNo;
if (SendPacketAndWaitForResponse("vCont?", response, false) ==
PacketResult::Success) {
- const char *response_cstr = response.GetStringRef().c_str();
+ const char *response_cstr = response.GetStringRef().data();
if (::strstr(response_cstr, ";c"))
m_supports_vCont_c = eLazyBoolYes;
@@ -525,9 +521,10 @@ GDBRemoteCommunicationClient::SendThreadSpecificPacketAndWaitForResponse(
if (!lock) {
if (Log *log = ProcessGDBRemoteLog::GetLogIfAnyCategoryIsSet(
GDBR_LOG_PROCESS | GDBR_LOG_PACKETS))
- log->Printf("GDBRemoteCommunicationClient::%s: Didn't get sequence mutex "
- "for %s packet.",
- __FUNCTION__, payload.GetData());
+ LLDB_LOGF(log,
+ "GDBRemoteCommunicationClient::%s: Didn't get sequence mutex "
+ "for %s packet.",
+ __FUNCTION__, payload.GetData());
return PacketResult::ErrorNoSequenceLock;
}
@@ -660,10 +657,10 @@ GDBRemoteCommunicationClient::SendPacketsAndConcatenateResponses(
if (!lock) {
Log *log(ProcessGDBRemoteLog::GetLogIfAnyCategoryIsSet(GDBR_LOG_PROCESS |
GDBR_LOG_PACKETS));
- if (log)
- log->Printf("error: failed to get packet sequence mutex, not sending "
- "packets with prefix '%s'",
- payload_prefix);
+ LLDB_LOGF(log,
+ "error: failed to get packet sequence mutex, not sending "
+ "packets with prefix '%s'",
+ payload_prefix);
return PacketResult::ErrorNoSequenceLock;
}
@@ -934,6 +931,11 @@ llvm::VersionTuple GDBRemoteCommunicationClient::GetOSVersion() {
return m_os_version;
}
+llvm::VersionTuple GDBRemoteCommunicationClient::GetMacCatalystVersion() {
+ GetHostInfo();
+ return m_maccatalyst_version;
+}
+
bool GDBRemoteCommunicationClient::GetOSBuildString(std::string &s) {
if (GetHostInfo()) {
if (!m_os_build.empty()) {
@@ -1136,6 +1138,7 @@ bool GDBRemoteCommunicationClient::GetHostInfo(bool force) {
uint32_t sub = 0;
std::string arch_name;
std::string os_name;
+ std::string environment;
std::string vendor_name;
std::string triple;
std::string distribution_id;
@@ -1175,7 +1178,11 @@ bool GDBRemoteCommunicationClient::GetHostInfo(bool force) {
extractor.GetHexByteString(m_os_kernel);
++num_keys_decoded;
} else if (name.equals("ostype")) {
- os_name = value;
+ if (value.equals("maccatalyst")) {
+ os_name = "ios";
+ environment = "macabi";
+ } else
+ os_name = value;
++num_keys_decoded;
} else if (name.equals("vendor")) {
vendor_name = value;
@@ -1199,6 +1206,9 @@ bool GDBRemoteCommunicationClient::GetHostInfo(bool force) {
{
if (!m_os_version.tryParse(value))
++num_keys_decoded;
+ } else if (name.equals("maccatalyst_version")) {
+ if (!m_maccatalyst_version.tryParse(value))
+ ++num_keys_decoded;
} else if (name.equals("watchpoint_exceptions_received")) {
m_watchpoints_trigger_after_instruction =
llvm::StringSwitch<LazyBool>(value)
@@ -1236,6 +1246,8 @@ bool GDBRemoteCommunicationClient::GetHostInfo(bool force) {
llvm::StringRef(vendor_name));
if (!os_name.empty())
m_host_arch.GetTriple().setOSName(llvm::StringRef(os_name));
+ if (!environment.empty())
+ m_host_arch.GetTriple().setEnvironmentName(environment);
}
} else {
std::string triple;
@@ -1259,6 +1271,7 @@ bool GDBRemoteCommunicationClient::GetHostInfo(bool force) {
host_triple.getOS() == llvm::Triple::Darwin) {
switch (m_host_arch.GetMachine()) {
case llvm::Triple::aarch64:
+ case llvm::Triple::aarch64_32:
case llvm::Triple::arm:
case llvm::Triple::thumb:
host_triple.setOS(llvm::Triple::IOS);
@@ -1284,14 +1297,15 @@ bool GDBRemoteCommunicationClient::GetHostInfo(bool force) {
assert(byte_order == m_host_arch.GetByteOrder());
}
- if (log)
- log->Printf("GDBRemoteCommunicationClient::%s parsed host "
- "architecture as %s, triple as %s from triple text %s",
- __FUNCTION__, m_host_arch.GetArchitectureName()
- ? m_host_arch.GetArchitectureName()
- : "<null-arch-name>",
- m_host_arch.GetTriple().getTriple().c_str(),
- triple.c_str());
+ LLDB_LOGF(log,
+ "GDBRemoteCommunicationClient::%s parsed host "
+ "architecture as %s, triple as %s from triple text %s",
+ __FUNCTION__,
+ m_host_arch.GetArchitectureName()
+ ? m_host_arch.GetArchitectureName()
+ : "<null-arch-name>",
+ m_host_arch.GetTriple().getTriple().c_str(),
+ triple.c_str());
}
if (!distribution_id.empty())
m_host_arch.SetDistributionId(distribution_id.c_str());
@@ -1893,7 +1907,7 @@ bool GDBRemoteCommunicationClient::DecodeProcessInfoResponse(
} else if (name.equals("euid")) {
uint32_t uid = UINT32_MAX;
value.getAsInteger(0, uid);
- process_info.SetEffectiveGroupID(uid);
+ process_info.SetEffectiveUserID(uid);
} else if (name.equals("gid")) {
uint32_t gid = UINT32_MAX;
value.getAsInteger(0, gid);
@@ -1914,6 +1928,26 @@ bool GDBRemoteCommunicationClient::DecodeProcessInfoResponse(
std::string name;
extractor.GetHexByteString(name);
process_info.GetExecutableFile().SetFile(name, FileSpec::Style::native);
+ } else if (name.equals("args")) {
+ llvm::StringRef encoded_args(value), hex_arg;
+
+ bool is_arg0 = true;
+ while (!encoded_args.empty()) {
+ std::tie(hex_arg, encoded_args) = encoded_args.split('-');
+ std::string arg;
+ StringExtractor extractor(hex_arg);
+ if (extractor.GetHexByteString(arg) * 2 != hex_arg.size()) {
+ // In case of wrong encoding, we discard all the arguments
+ process_info.GetArguments().Clear();
+ process_info.SetArg0("");
+ break;
+ }
+ if (is_arg0)
+ process_info.SetArg0(arg);
+ else
+ process_info.GetArguments().AppendArgument(arg);
+ is_arg0 = false;
+ }
} else if (name.equals("cputype")) {
value.getAsInteger(0, cpu);
} else if (name.equals("cpusubtype")) {
@@ -1987,6 +2021,7 @@ bool GDBRemoteCommunicationClient::GetCurrentProcessInfo(bool allow_lazy) {
uint32_t sub = 0;
std::string arch_name;
std::string os_name;
+ std::string environment;
std::string vendor_name;
std::string triple;
std::string elf_abi;
@@ -2007,7 +2042,11 @@ bool GDBRemoteCommunicationClient::GetCurrentProcessInfo(bool allow_lazy) {
extractor.GetHexByteString(triple);
++num_keys_decoded;
} else if (name.equals("ostype")) {
- os_name = value;
+ if (value.equals("maccatalyst")) {
+ os_name = "ios";
+ environment = "macabi";
+ } else
+ os_name = value;
++num_keys_decoded;
} else if (name.equals("vendor")) {
vendor_name = value;
@@ -2048,6 +2087,8 @@ bool GDBRemoteCommunicationClient::GetCurrentProcessInfo(bool allow_lazy) {
} else if (cpu != LLDB_INVALID_CPUTYPE && !os_name.empty() &&
!vendor_name.empty()) {
llvm::Triple triple(llvm::Twine("-") + vendor_name + "-" + os_name);
+ if (!environment.empty())
+ triple.setEnvironmentName(environment);
assert(triple.getObjectFormat() != llvm::Triple::UnknownObjectFormat);
assert(triple.getObjectFormat() != llvm::Triple::Wasm);
@@ -2064,12 +2105,10 @@ bool GDBRemoteCommunicationClient::GetCurrentProcessInfo(bool allow_lazy) {
break;
case llvm::Triple::Wasm:
case llvm::Triple::XCOFF:
- if (log)
- log->Printf("error: not supported target architecture");
+ LLDB_LOGF(log, "error: not supported target architecture");
return false;
case llvm::Triple::UnknownObjectFormat:
- if (log)
- log->Printf("error: failed to determine target architecture");
+ LLDB_LOGF(log, "error: failed to determine target architecture");
return false;
}
@@ -2081,8 +2120,10 @@ bool GDBRemoteCommunicationClient::GetCurrentProcessInfo(bool allow_lazy) {
}
m_process_arch.GetTriple().setVendorName(llvm::StringRef(vendor_name));
m_process_arch.GetTriple().setOSName(llvm::StringRef(os_name));
+ m_process_arch.GetTriple().setEnvironmentName(llvm::StringRef(environment));
m_host_arch.GetTriple().setVendorName(llvm::StringRef(vendor_name));
m_host_arch.GetTriple().setOSName(llvm::StringRef(os_name));
+ m_host_arch.GetTriple().setEnvironmentName(llvm::StringRef(environment));
}
return true;
}
@@ -2156,8 +2197,7 @@ uint32_t GDBRemoteCommunicationClient::FindProcesses(
if (match_info.GetProcessInfo().EffectiveGroupIDIsValid())
packet.Printf("egid:%u;",
match_info.GetProcessInfo().GetEffectiveGroupID());
- if (match_info.GetProcessInfo().EffectiveGroupIDIsValid())
- packet.Printf("all_users:%u;", match_info.GetMatchAllUsers() ? 1 : 0);
+ packet.Printf("all_users:%u;", match_info.GetMatchAllUsers() ? 1 : 0);
if (match_info.GetProcessInfo().GetArchitecture().IsValid()) {
const ArchSpec &match_arch =
match_info.GetProcessInfo().GetArchitecture();
@@ -2178,8 +2218,7 @@ uint32_t GDBRemoteCommunicationClient::FindProcesses(
if (!DecodeProcessInfoResponse(response, process_info))
break;
process_infos.Append(process_info);
- response.GetStringRef().clear();
- response.SetFilePos(0);
+ response = StringExtractorGDBRemote();
} while (SendPacketAndWaitForResponse("qsProcessInfo", response, false) ==
PacketResult::Success);
} else {
@@ -2641,9 +2680,8 @@ bool GDBRemoteCommunicationClient::GetThreadStopInfo(
uint8_t GDBRemoteCommunicationClient::SendGDBStoppointTypePacket(
GDBStoppointType type, bool insert, addr_t addr, uint32_t length) {
Log *log(GetLogIfAnyCategoriesSet(LIBLLDB_LOG_BREAKPOINTS));
- if (log)
- log->Printf("GDBRemoteCommunicationClient::%s() %s at addr = 0x%" PRIx64,
- __FUNCTION__, insert ? "add" : "remove", addr);
+ LLDB_LOGF(log, "GDBRemoteCommunicationClient::%s() %s at addr = 0x%" PRIx64,
+ __FUNCTION__, insert ? "add" : "remove", addr);
// Check if the stub is known not to support this breakpoint type
if (!SupportsGDBStoppointPacket(type))
@@ -2745,9 +2783,8 @@ size_t GDBRemoteCommunicationClient::GetCurrentThreadIDs(
#if !defined(LLDB_CONFIGURATION_DEBUG)
Log *log(ProcessGDBRemoteLog::GetLogIfAnyCategoryIsSet(GDBR_LOG_PROCESS |
GDBR_LOG_PACKETS));
- if (log)
- log->Printf("error: failed to get packet sequence mutex, not sending "
- "packet 'qfThreadInfo'");
+ LLDB_LOGF(log, "error: failed to get packet sequence mutex, not sending "
+ "packet 'qfThreadInfo'");
#endif
sequence_mutex_unavailable = true;
}
@@ -2879,7 +2916,7 @@ static uint64_t ParseHostIOPacketResponse(StringExtractorGDBRemote &response,
}
lldb::user_id_t
GDBRemoteCommunicationClient::OpenFile(const lldb_private::FileSpec &file_spec,
- uint32_t flags, mode_t mode,
+ File::OpenOptions flags, mode_t mode,
Status &error) {
std::string path(file_spec.GetPath(false));
lldb_private::StreamString stream;
@@ -3146,7 +3183,8 @@ bool GDBRemoteCommunicationClient::AvoidGPackets(ProcessGDBRemote *process) {
if (arch.IsValid() &&
arch.GetTriple().getVendor() == llvm::Triple::Apple &&
arch.GetTriple().getOS() == llvm::Triple::IOS &&
- arch.GetTriple().getArch() == llvm::Triple::aarch64) {
+ (arch.GetTriple().getArch() == llvm::Triple::aarch64 ||
+ arch.GetTriple().getArch() == llvm::Triple::aarch64_32)) {
m_avoid_g_packets = eLazyBoolYes;
uint32_t gdb_server_version = GetGDBServerProgramVersion();
if (gdb_server_version != 0) {
@@ -3592,21 +3630,21 @@ ParseModuleSpec(StructuredData::Dictionary *dict) {
llvm::Optional<std::vector<ModuleSpec>>
GDBRemoteCommunicationClient::GetModulesInfo(
llvm::ArrayRef<FileSpec> module_file_specs, const llvm::Triple &triple) {
+ namespace json = llvm::json;
+
if (!m_supports_jModulesInfo)
return llvm::None;
- JSONArray::SP module_array_sp = std::make_shared<JSONArray>();
+ json::Array module_array;
for (const FileSpec &module_file_spec : module_file_specs) {
- JSONObject::SP module_sp = std::make_shared<JSONObject>();
- module_array_sp->AppendObject(module_sp);
- module_sp->SetObject(
- "file", std::make_shared<JSONString>(module_file_spec.GetPath(false)));
- module_sp->SetObject("triple",
- std::make_shared<JSONString>(triple.getTriple()));
+ module_array.push_back(
+ json::Object{{"file", module_file_spec.GetPath(false)},
+ {"triple", triple.getTriple()}});
}
StreamString unescaped_payload;
unescaped_payload.PutCString("jModulesInfo:");
- module_array_sp->Write(unescaped_payload);
+ unescaped_payload.AsRawOstream() << std::move(module_array);
+
StreamGDBRemote payload;
payload.PutEscapedBytes(unescaped_payload.GetString().data(),
unescaped_payload.GetSize());
@@ -3796,8 +3834,9 @@ void GDBRemoteCommunicationClient::ServeSymbolLookups(
addr_t symbol_load_addr = LLDB_INVALID_ADDRESS;
lldb_private::SymbolContextList sc_list;
- if (process->GetTarget().GetImages().FindSymbolsWithNameAndType(
- ConstString(symbol_name), eSymbolTypeAny, sc_list)) {
+ process->GetTarget().GetImages().FindSymbolsWithNameAndType(
+ ConstString(symbol_name), eSymbolTypeAny, sc_list);
+ if (!sc_list.IsEmpty()) {
const size_t num_scs = sc_list.GetSize();
for (size_t sc_idx = 0;
sc_idx < num_scs &&
@@ -3873,9 +3912,9 @@ void GDBRemoteCommunicationClient::ServeSymbolLookups(
} else if (Log *log = ProcessGDBRemoteLog::GetLogIfAnyCategoryIsSet(
GDBR_LOG_PROCESS | GDBR_LOG_PACKETS)) {
- log->Printf(
- "GDBRemoteCommunicationClient::%s: Didn't get sequence mutex.",
- __FUNCTION__);
+ LLDB_LOGF(log,
+ "GDBRemoteCommunicationClient::%s: Didn't get sequence mutex.",
+ __FUNCTION__);
}
}
}
@@ -3899,26 +3938,27 @@ GDBRemoteCommunicationClient::GetSupportedStructuredDataPlugins() {
!m_supported_async_json_packets_sp->GetAsArray()) {
// We were returned something other than a JSON array. This is
// invalid. Clear it out.
- if (log)
- log->Printf("GDBRemoteCommunicationClient::%s(): "
- "QSupportedAsyncJSONPackets returned invalid "
- "result: %s",
- __FUNCTION__, response.GetStringRef().c_str());
+ LLDB_LOGF(log,
+ "GDBRemoteCommunicationClient::%s(): "
+ "QSupportedAsyncJSONPackets returned invalid "
+ "result: %s",
+ __FUNCTION__, response.GetStringRef().data());
m_supported_async_json_packets_sp.reset();
}
} else {
- if (log)
- log->Printf("GDBRemoteCommunicationClient::%s(): "
- "QSupportedAsyncJSONPackets unsupported",
- __FUNCTION__);
+ LLDB_LOGF(log,
+ "GDBRemoteCommunicationClient::%s(): "
+ "QSupportedAsyncJSONPackets unsupported",
+ __FUNCTION__);
}
if (log && m_supported_async_json_packets_sp) {
StreamString stream;
m_supported_async_json_packets_sp->Dump(stream);
- log->Printf("GDBRemoteCommunicationClient::%s(): supported async "
- "JSON packets: %s",
- __FUNCTION__, stream.GetData());
+ LLDB_LOGF(log,
+ "GDBRemoteCommunicationClient::%s(): supported async "
+ "JSON packets: %s",
+ __FUNCTION__, stream.GetData());
}
}
@@ -3980,14 +4020,14 @@ Status GDBRemoteCommunicationClient::ConfigureRemoteStructuredData(
SendPacketAndWaitForResponse(stream.GetString(), response, send_async);
if (result == PacketResult::Success) {
// We failed if the config result comes back other than OK.
- if (strcmp(response.GetStringRef().c_str(), "OK") == 0) {
+ if (strcmp(response.GetStringRef().data(), "OK") == 0) {
// Okay!
error.Clear();
} else {
error.SetErrorStringWithFormat("configuring StructuredData feature "
"%s failed with error %s",
type_name.AsCString(),
- response.GetStringRef().c_str());
+ response.GetStringRef().data());
}
} else {
// Can we get more data here on the failure?
diff --git a/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.h b/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.h
index de85c9f8b67b..574cd0fd70c5 100644
--- a/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.h
+++ b/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.h
@@ -17,8 +17,9 @@
#include <string>
#include <vector>
+#include "lldb/Host/File.h"
#include "lldb/Utility/ArchSpec.h"
-#include "lldb/Utility/StreamGDBRemote.h"
+#include "lldb/Utility/GDBRemote.h"
#include "lldb/Utility/StructuredData.h"
#if defined(_WIN32)
#include "lldb/Host/windows/PosixApi.h"
@@ -248,6 +249,8 @@ public:
llvm::VersionTuple GetOSVersion();
+ llvm::VersionTuple GetMacCatalystVersion();
+
bool GetOSBuildString(std::string &s);
bool GetOSKernelDescription(std::string &s);
@@ -348,7 +351,7 @@ public:
size_t GetCurrentThreadIDs(std::vector<lldb::tid_t> &thread_ids,
bool &sequence_mutex_unavailable);
- lldb::user_id_t OpenFile(const FileSpec &file_spec, uint32_t flags,
+ lldb::user_id_t OpenFile(const FileSpec &file_spec, File::OpenOptions flags,
mode_t mode, Status &error);
bool CloseFile(lldb::user_id_t fd, Status &error);
@@ -548,6 +551,7 @@ protected:
ArchSpec m_host_arch;
ArchSpec m_process_arch;
llvm::VersionTuple m_os_version;
+ llvm::VersionTuple m_maccatalyst_version;
std::string m_os_build;
std::string m_os_kernel;
std::string m_hostname;
diff --git a/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationHistory.cpp b/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationHistory.cpp
index bcddb4faf863..d2cc32f63f20 100644
--- a/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationHistory.cpp
+++ b/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationHistory.cpp
@@ -18,12 +18,6 @@ using namespace lldb;
using namespace lldb_private;
using namespace lldb_private::process_gdb_remote;
-void GDBRemoteCommunicationHistory::Entry::Serialize(raw_ostream &strm) const {
- yaml::Output yout(strm);
- yout << const_cast<GDBRemoteCommunicationHistory::Entry &>(*this);
- strm.flush();
-}
-
GDBRemoteCommunicationHistory::GDBRemoteCommunicationHistory(uint32_t size)
: m_packets(), m_curr_idx(0), m_total_packet_count(0),
m_dumped_to_log(false) {
@@ -33,7 +27,8 @@ GDBRemoteCommunicationHistory::GDBRemoteCommunicationHistory(uint32_t size)
GDBRemoteCommunicationHistory::~GDBRemoteCommunicationHistory() {}
-void GDBRemoteCommunicationHistory::AddPacket(char packet_char, PacketType type,
+void GDBRemoteCommunicationHistory::AddPacket(char packet_char,
+ GDBRemotePacket::Type type,
uint32_t bytes_transmitted) {
const size_t size = m_packets.size();
if (size == 0)
@@ -50,7 +45,8 @@ void GDBRemoteCommunicationHistory::AddPacket(char packet_char, PacketType type,
}
void GDBRemoteCommunicationHistory::AddPacket(const std::string &src,
- uint32_t src_len, PacketType type,
+ uint32_t src_len,
+ GDBRemotePacket::Type type,
uint32_t bytes_transmitted) {
const size_t size = m_packets.size();
if (size == 0)
@@ -72,13 +68,12 @@ void GDBRemoteCommunicationHistory::Dump(Stream &strm) const {
const uint32_t stop_idx = m_curr_idx + size;
for (uint32_t i = first_idx; i < stop_idx; ++i) {
const uint32_t idx = NormalizeIndex(i);
- const Entry &entry = m_packets[idx];
- if (entry.type == ePacketTypeInvalid || entry.packet.data.empty())
+ const GDBRemotePacket &entry = m_packets[idx];
+ if (entry.type == GDBRemotePacket::ePacketTypeInvalid ||
+ entry.packet.data.empty())
break;
- strm.Printf("history[%u] tid=0x%4.4" PRIx64 " <%4u> %s packet: %s\n",
- entry.packet_idx, entry.tid, entry.bytes_transmitted,
- (entry.type == ePacketTypeSend) ? "send" : "read",
- entry.packet.data.c_str());
+ strm.Printf("history[%u] ", entry.packet_idx);
+ entry.Dump(strm);
}
}
@@ -92,51 +87,15 @@ void GDBRemoteCommunicationHistory::Dump(Log *log) const {
const uint32_t stop_idx = m_curr_idx + size;
for (uint32_t i = first_idx; i < stop_idx; ++i) {
const uint32_t idx = NormalizeIndex(i);
- const Entry &entry = m_packets[idx];
- if (entry.type == ePacketTypeInvalid || entry.packet.data.empty())
+ const GDBRemotePacket &entry = m_packets[idx];
+ if (entry.type == GDBRemotePacket::ePacketTypeInvalid ||
+ entry.packet.data.empty())
break;
- log->Printf("history[%u] tid=0x%4.4" PRIx64 " <%4u> %s packet: %s",
- entry.packet_idx, entry.tid, entry.bytes_transmitted,
- (entry.type == ePacketTypeSend) ? "send" : "read",
- entry.packet.data.c_str());
+ LLDB_LOGF(log, "history[%u] tid=0x%4.4" PRIx64 " <%4u> %s packet: %s",
+ entry.packet_idx, entry.tid, entry.bytes_transmitted,
+ (entry.type == GDBRemotePacket::ePacketTypeSend) ? "send"
+ : "read",
+ entry.packet.data.c_str());
}
}
-void yaml::ScalarEnumerationTraits<GDBRemoteCommunicationHistory::PacketType>::
- enumeration(IO &io, GDBRemoteCommunicationHistory::PacketType &value) {
- io.enumCase(value, "Invalid",
- GDBRemoteCommunicationHistory::ePacketTypeInvalid);
- io.enumCase(value, "Send", GDBRemoteCommunicationHistory::ePacketTypeSend);
- io.enumCase(value, "Recv", GDBRemoteCommunicationHistory::ePacketTypeRecv);
-}
-
-void yaml::ScalarTraits<GDBRemoteCommunicationHistory::Entry::BinaryData>::
- output(const GDBRemoteCommunicationHistory::Entry::BinaryData &Val, void *,
- raw_ostream &Out) {
- Out << toHex(Val.data);
-}
-
-StringRef
-yaml::ScalarTraits<GDBRemoteCommunicationHistory::Entry::BinaryData>::input(
- StringRef Scalar, void *,
- GDBRemoteCommunicationHistory::Entry::BinaryData &Val) {
- Val.data = fromHex(Scalar);
- return {};
-}
-
-void yaml::MappingTraits<GDBRemoteCommunicationHistory::Entry>::mapping(
- IO &io, GDBRemoteCommunicationHistory::Entry &Entry) {
- io.mapRequired("packet", Entry.packet);
- io.mapRequired("type", Entry.type);
- io.mapRequired("bytes", Entry.bytes_transmitted);
- io.mapRequired("index", Entry.packet_idx);
- io.mapRequired("tid", Entry.tid);
-}
-
-StringRef yaml::MappingTraits<GDBRemoteCommunicationHistory::Entry>::validate(
- IO &io, GDBRemoteCommunicationHistory::Entry &Entry) {
- if (Entry.bytes_transmitted != Entry.packet.data.size())
- return "BinaryData size doesn't match bytes transmitted";
-
- return {};
-}
diff --git a/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationHistory.h b/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationHistory.h
index 85f112b50623..c006fbd34a4b 100644
--- a/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationHistory.h
+++ b/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationHistory.h
@@ -12,6 +12,7 @@
#include <string>
#include <vector>
+#include "lldb/Utility/GDBRemote.h"
#include "lldb/lldb-public.h"
#include "llvm/Support/YAMLTraits.h"
#include "llvm/Support/raw_ostream.h"
@@ -25,46 +26,17 @@ class GDBRemoteCommunicationHistory {
public:
friend llvm::yaml::MappingTraits<GDBRemoteCommunicationHistory>;
- enum PacketType { ePacketTypeInvalid = 0, ePacketTypeSend, ePacketTypeRecv };
-
- /// Entry in the ring buffer containing the packet data, its type, size and
- /// index. Entries can be serialized to file.
- struct Entry {
- Entry()
- : packet(), type(ePacketTypeInvalid), bytes_transmitted(0),
- packet_idx(0), tid(LLDB_INVALID_THREAD_ID) {}
-
- void Clear() {
- packet.data.clear();
- type = ePacketTypeInvalid;
- bytes_transmitted = 0;
- packet_idx = 0;
- tid = LLDB_INVALID_THREAD_ID;
- }
-
- struct BinaryData {
- std::string data;
- };
-
- void Serialize(llvm::raw_ostream &strm) const;
-
- BinaryData packet;
- PacketType type;
- uint32_t bytes_transmitted;
- uint32_t packet_idx;
- lldb::tid_t tid;
- };
-
GDBRemoteCommunicationHistory(uint32_t size = 0);
~GDBRemoteCommunicationHistory();
// For single char packets for ack, nack and /x03
- void AddPacket(char packet_char, PacketType type, uint32_t bytes_transmitted);
-
- void AddPacket(const std::string &src, uint32_t src_len, PacketType type,
+ void AddPacket(char packet_char, GDBRemotePacket::Type type,
uint32_t bytes_transmitted);
+ void AddPacket(const std::string &src, uint32_t src_len,
+ GDBRemotePacket::Type type, uint32_t bytes_transmitted);
+
void Dump(Stream &strm) const;
void Dump(Log *log) const;
bool DidDumpToLog() const { return m_dumped_to_log; }
@@ -97,7 +69,7 @@ private:
return m_packets.empty() ? 0 : i % m_packets.size();
}
- std::vector<Entry> m_packets;
+ std::vector<GDBRemotePacket> m_packets;
uint32_t m_curr_idx;
uint32_t m_total_packet_count;
mutable bool m_dumped_to_log;
@@ -107,49 +79,4 @@ private:
} // namespace process_gdb_remote
} // namespace lldb_private
-LLVM_YAML_IS_DOCUMENT_LIST_VECTOR(
- lldb_private::process_gdb_remote::GDBRemoteCommunicationHistory::Entry)
-
-namespace llvm {
-namespace yaml {
-
-template <>
-struct ScalarEnumerationTraits<lldb_private::process_gdb_remote::
- GDBRemoteCommunicationHistory::PacketType> {
- static void enumeration(IO &io,
- lldb_private::process_gdb_remote::
- GDBRemoteCommunicationHistory::PacketType &value);
-};
-
-template <>
-struct ScalarTraits<lldb_private::process_gdb_remote::
- GDBRemoteCommunicationHistory::Entry::BinaryData> {
- static void output(const lldb_private::process_gdb_remote::
- GDBRemoteCommunicationHistory::Entry::BinaryData &,
- void *, raw_ostream &);
-
- static StringRef
- input(StringRef, void *,
- lldb_private::process_gdb_remote::GDBRemoteCommunicationHistory::Entry::
- BinaryData &);
-
- static QuotingType mustQuote(StringRef S) { return QuotingType::None; }
-};
-
-template <>
-struct MappingTraits<
- lldb_private::process_gdb_remote::GDBRemoteCommunicationHistory::Entry> {
- static void
- mapping(IO &io,
- lldb_private::process_gdb_remote::GDBRemoteCommunicationHistory::Entry
- &Entry);
-
- static StringRef validate(
- IO &io,
- lldb_private::process_gdb_remote::GDBRemoteCommunicationHistory::Entry &);
-};
-
-} // namespace yaml
-} // namespace llvm
-
#endif // liblldb_GDBRemoteCommunicationHistory_h_
diff --git a/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationReplayServer.cpp b/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationReplayServer.cpp
index 417f5737a30f..2d26c550dc76 100644
--- a/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationReplayServer.cpp
+++ b/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationReplayServer.cpp
@@ -9,6 +9,7 @@
#include <errno.h>
#include "lldb/Host/Config.h"
+#include "llvm/ADT/ScopeExit.h"
#include "GDBRemoteCommunicationReplayServer.h"
#include "ProcessGDBRemoteLog.h"
@@ -127,7 +128,7 @@ GDBRemoteCommunicationReplayServer::GetPacketAndSendResponse(
Log *log(ProcessGDBRemoteLog::GetLogIfAllCategoriesSet(GDBR_LOG_PROCESS));
while (!m_packet_history.empty()) {
// Pop last packet from the history.
- GDBRemoteCommunicationHistory::Entry entry = m_packet_history.back();
+ GDBRemotePacket entry = m_packet_history.back();
m_packet_history.pop_back();
// We've handled the handshake implicitly before. Skip the packet and move
@@ -135,7 +136,7 @@ GDBRemoteCommunicationReplayServer::GetPacketAndSendResponse(
if (entry.packet.data == "+")
continue;
- if (entry.type == GDBRemoteCommunicationHistory::ePacketTypeSend) {
+ if (entry.type == GDBRemotePacket::ePacketTypeSend) {
if (unexpected(entry.packet.data, packet.GetStringRef())) {
LLDB_LOG(log,
"GDBRemoteCommunicationReplayServer expected packet: '{0}'",
@@ -149,14 +150,14 @@ GDBRemoteCommunicationReplayServer::GetPacketAndSendResponse(
// Ignore QEnvironment packets as they're handled earlier.
if (entry.packet.data.find("QEnvironment") == 1) {
assert(m_packet_history.back().type ==
- GDBRemoteCommunicationHistory::ePacketTypeRecv);
+ GDBRemotePacket::ePacketTypeRecv);
m_packet_history.pop_back();
}
continue;
}
- if (entry.type == GDBRemoteCommunicationHistory::ePacketTypeInvalid) {
+ if (entry.type == GDBRemotePacket::ePacketTypeInvalid) {
LLDB_LOG(
log,
"GDBRemoteCommunicationReplayServer skipped invalid packet: '{0}'",
@@ -175,10 +176,6 @@ GDBRemoteCommunicationReplayServer::GetPacketAndSendResponse(
return packet_result;
}
-LLVM_YAML_IS_DOCUMENT_LIST_VECTOR(
- std::vector<
- lldb_private::process_gdb_remote::GDBRemoteCommunicationHistory::Entry>)
-
llvm::Error
GDBRemoteCommunicationReplayServer::LoadReplayHistory(const FileSpec &path) {
auto error_or_file = MemoryBuffer::getFile(path.GetPath());
@@ -256,11 +253,10 @@ void GDBRemoteCommunicationReplayServer::ReceivePacket(
thread_result_t GDBRemoteCommunicationReplayServer::AsyncThread(void *arg) {
GDBRemoteCommunicationReplayServer *server =
(GDBRemoteCommunicationReplayServer *)arg;
-
+ auto D = make_scope_exit([&]() { server->Disconnect(); });
EventSP event_sp;
bool done = false;
-
- while (true) {
+ while (!done) {
if (server->m_async_listener_sp->GetEvent(event_sp, llvm::None)) {
const uint32_t event_type = event_sp->GetType();
if (event_sp->BroadcasterIs(&server->m_async_broadcaster)) {
diff --git a/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationReplayServer.h b/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationReplayServer.h
index 26d65e265463..0b5e910f7c6a 100644
--- a/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationReplayServer.h
+++ b/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationReplayServer.h
@@ -62,7 +62,7 @@ protected:
static lldb::thread_result_t AsyncThread(void *arg);
/// Replay history with the oldest packet at the end.
- std::vector<GDBRemoteCommunicationHistory::Entry> m_packet_history;
+ std::vector<GDBRemotePacket> m_packet_history;
/// Server thread.
Broadcaster m_async_broadcaster;
diff --git a/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServer.cpp b/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServer.cpp
index 49cbeb023fd5..ac6ecffcf854 100644
--- a/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServer.cpp
+++ b/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServer.cpp
@@ -59,14 +59,13 @@ GDBRemoteCommunicationServer::GetPacketAndSendResponse(
break;
case StringExtractorGDBRemote::eServerPacketType_unimplemented:
- packet_result = SendUnimplementedResponse(packet.GetStringRef().c_str());
+ packet_result = SendUnimplementedResponse(packet.GetStringRef().data());
break;
default:
auto handler_it = m_packet_handlers.find(packet_type);
if (handler_it == m_packet_handlers.end())
- packet_result =
- SendUnimplementedResponse(packet.GetStringRef().c_str());
+ packet_result = SendUnimplementedResponse(packet.GetStringRef().data());
else
packet_result = handler_it->second(packet, error, interrupt, quit);
break;
@@ -139,10 +138,9 @@ GDBRemoteCommunication::PacketResult
GDBRemoteCommunicationServer::SendIllFormedResponse(
const StringExtractorGDBRemote &failed_packet, const char *message) {
Log *log(ProcessGDBRemoteLog::GetLogIfAllCategoriesSet(GDBR_LOG_PACKETS));
- if (log)
- log->Printf("GDBRemoteCommunicationServer::%s: ILLFORMED: '%s' (%s)",
- __FUNCTION__, failed_packet.GetStringRef().c_str(),
- message ? message : "");
+ LLDB_LOGF(log, "GDBRemoteCommunicationServer::%s: ILLFORMED: '%s' (%s)",
+ __FUNCTION__, failed_packet.GetStringRef().data(),
+ message ? message : "");
return SendErrorResponse(0x03);
}
diff --git a/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerCommon.cpp b/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerCommon.cpp
index d095c7a057ad..37980d914dc2 100644
--- a/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerCommon.cpp
+++ b/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerCommon.cpp
@@ -29,12 +29,13 @@
#include "lldb/Symbol/ObjectFile.h"
#include "lldb/Target/Platform.h"
#include "lldb/Utility/Endian.h"
-#include "lldb/Utility/JSON.h"
+#include "lldb/Utility/GDBRemote.h"
#include "lldb/Utility/Log.h"
-#include "lldb/Utility/StreamGDBRemote.h"
#include "lldb/Utility/StreamString.h"
#include "lldb/Utility/StructuredData.h"
+#include "llvm/ADT/StringSwitch.h"
#include "llvm/ADT/Triple.h"
+#include "llvm/Support/JSON.h"
#include "ProcessGDBRemoteLog.h"
#include "lldb/Utility/StringExtractorGDBRemote.h"
@@ -43,11 +44,10 @@
#include "lldb/Host/android/HostInfoAndroid.h"
#endif
-#include "llvm/ADT/StringSwitch.h"
using namespace lldb;
-using namespace lldb_private;
using namespace lldb_private::process_gdb_remote;
+using namespace lldb_private;
#ifdef __ANDROID__
const static uint32_t g_default_packet_timeout_sec = 20; // seconds
@@ -231,6 +231,7 @@ GDBRemoteCommunicationServerCommon::Handle_qHostInfo(
#else
if (host_arch.GetMachine() == llvm::Triple::aarch64 ||
+ host_arch.GetMachine() == llvm::Triple::aarch64_32 ||
host_arch.GetMachine() == llvm::Triple::aarch64_be ||
host_arch.GetMachine() == llvm::Triple::arm ||
host_arch.GetMachine() == llvm::Triple::armeb || host_arch.IsMIPS())
@@ -260,6 +261,15 @@ GDBRemoteCommunicationServerCommon::Handle_qHostInfo(
response.PutChar(';');
}
+#if defined(__APPLE__)
+ llvm::VersionTuple maccatalyst_version = HostInfo::GetMacCatalystVersion();
+ if (!maccatalyst_version.empty()) {
+ response.Format("maccatalyst_version:{0}",
+ maccatalyst_version.getAsString());
+ response.PutChar(';');
+ }
+#endif
+
std::string s;
if (HostInfo::GetOSBuildString(s)) {
response.PutCString("os_build:");
@@ -421,8 +431,7 @@ GDBRemoteCommunicationServerCommon::Handle_qUserName(
StringExtractorGDBRemote &packet) {
#if !defined(LLDB_DISABLE_POSIX)
Log *log(GetLogIfAnyCategoriesSet(LIBLLDB_LOG_PROCESS));
- if (log)
- log->Printf("GDBRemoteCommunicationServerCommon::%s begin", __FUNCTION__);
+ LLDB_LOGF(log, "GDBRemoteCommunicationServerCommon::%s begin", __FUNCTION__);
// Packet format: "qUserName:%i" where %i is the uid
packet.SetFilePos(::strlen("qUserName:"));
@@ -435,8 +444,7 @@ GDBRemoteCommunicationServerCommon::Handle_qUserName(
return SendPacketNoLock(response.GetString());
}
}
- if (log)
- log->Printf("GDBRemoteCommunicationServerCommon::%s end", __FUNCTION__);
+ LLDB_LOGF(log, "GDBRemoteCommunicationServerCommon::%s end", __FUNCTION__);
#endif
return SendErrorResponse(5);
}
@@ -500,19 +508,32 @@ GDBRemoteCommunicationServerCommon::Handle_vFile_Open(
packet.GetHexByteStringTerminatedBy(path, ',');
if (!path.empty()) {
if (packet.GetChar() == ',') {
- uint32_t flags = packet.GetHexMaxU32(false, 0);
+ // FIXME
+ // The flag values for OpenOptions do not match the values used by GDB
+ // * https://sourceware.org/gdb/onlinedocs/gdb/Open-Flags.html#Open-Flags
+ // * rdar://problem/46788934
+ auto flags = File::OpenOptions(packet.GetHexMaxU32(false, 0));
if (packet.GetChar() == ',') {
mode_t mode = packet.GetHexMaxU32(false, 0600);
FileSpec path_spec(path);
FileSystem::Instance().Resolve(path_spec);
- File file;
// Do not close fd.
- Status error =
- FileSystem::Instance().Open(file, path_spec, flags, mode, false);
- const int save_errno = error.GetError();
+ auto file = FileSystem::Instance().Open(path_spec, flags, mode, false);
+
+ int save_errno = 0;
+ int descriptor = File::kInvalidDescriptor;
+ if (file) {
+ descriptor = file.get()->GetDescriptor();
+ } else {
+ std::error_code code = errorToErrorCode(file.takeError());
+ if (code.category() == std::system_category()) {
+ save_errno = code.value();
+ }
+ }
+
StreamString response;
response.PutChar('F');
- response.Printf("%i", file.GetDescriptor());
+ response.Printf("%i", descriptor);
if (save_errno)
response.Printf(",%i", save_errno);
return SendPacketNoLock(response.GetString());
@@ -530,7 +551,7 @@ GDBRemoteCommunicationServerCommon::Handle_vFile_Close(
int err = -1;
int save_errno = 0;
if (fd >= 0) {
- File file(fd, true);
+ NativeFile file(fd, File::OpenOptions(0), true);
Status error = file.Close();
err = 0;
save_errno = error.GetError();
@@ -552,16 +573,16 @@ GDBRemoteCommunicationServerCommon::Handle_vFile_pRead(
packet.SetFilePos(::strlen("vFile:pread:"));
int fd = packet.GetS32(-1);
if (packet.GetChar() == ',') {
- size_t count = packet.GetU64(UINT64_MAX);
+ size_t count = packet.GetU64(SIZE_MAX);
if (packet.GetChar() == ',') {
off_t offset = packet.GetU64(UINT32_MAX);
- if (count == UINT64_MAX) {
+ if (count == SIZE_MAX) {
response.Printf("F-1:%i", EINVAL);
return SendPacketNoLock(response.GetString());
}
std::string buffer(count, 0);
- File file(fd, false);
+ NativeFile file(fd, File::eOpenOptionRead, false);
Status error = file.Read(static_cast<void *>(&buffer[0]), count, offset);
const ssize_t bytes_read = error.Success() ? count : -1;
const int save_errno = error.GetError();
@@ -593,7 +614,7 @@ GDBRemoteCommunicationServerCommon::Handle_vFile_pWrite(
if (packet.GetChar() == ',') {
std::string buffer;
if (packet.GetEscapedBinaryData(buffer)) {
- File file(fd, false);
+ NativeFile file(fd, File::eOpenOptionWrite, false);
size_t count = buffer.size();
Status error =
file.Write(static_cast<const void *>(&buffer[0]), count, offset);
@@ -825,6 +846,7 @@ GDBRemoteCommunicationServerCommon::Handle_qSupported(
#if defined(__linux__) || defined(__NetBSD__)
response.PutCString(";QPassSignals+");
response.PutCString(";qXfer:auxv:read+");
+ response.PutCString(";qXfer:libraries-svr4:read+");
#endif
return SendPacketNoLock(response.GetString());
@@ -1016,9 +1038,8 @@ GDBRemoteCommunicationServerCommon::Handle_A(StringExtractorGDBRemote &packet) {
m_process_launch_info.GetExecutableFile().SetFile(
arg, FileSpec::Style::native);
m_process_launch_info.GetArguments().AppendArgument(arg);
- if (log)
- log->Printf("LLGSPacketHandler::%s added arg %d: \"%s\"",
- __FUNCTION__, actual_arg_index, arg.c_str());
+ LLDB_LOGF(log, "LLGSPacketHandler::%s added arg %d: \"%s\"",
+ __FUNCTION__, actual_arg_index, arg.c_str());
++actual_arg_index;
}
}
@@ -1104,6 +1125,8 @@ GDBRemoteCommunicationServerCommon::Handle_qModuleInfo(
GDBRemoteCommunication::PacketResult
GDBRemoteCommunicationServerCommon::Handle_jModulesInfo(
StringExtractorGDBRemote &packet) {
+ namespace json = llvm::json;
+
packet.SetFilePos(::strlen("jModulesInfo:"));
StructuredData::ObjectSP object_sp = StructuredData::ParseJSON(packet.Peek());
@@ -1114,7 +1137,7 @@ GDBRemoteCommunicationServerCommon::Handle_jModulesInfo(
if (!packet_array)
return SendErrorResponse(2);
- JSONArray::SP response_array_sp = std::make_shared<JSONArray>();
+ json::Array response_array;
for (size_t i = 0; i < packet_array->GetSize(); ++i) {
StructuredData::Dictionary *query =
packet_array->GetItemAtIndex(i)->GetAsDictionary();
@@ -1132,27 +1155,22 @@ GDBRemoteCommunicationServerCommon::Handle_jModulesInfo(
const auto file_offset = matched_module_spec.GetObjectOffset();
const auto file_size = matched_module_spec.GetObjectSize();
const auto uuid_str = matched_module_spec.GetUUID().GetAsString("");
-
if (uuid_str.empty())
continue;
-
- JSONObject::SP response = std::make_shared<JSONObject>();
- response_array_sp->AppendObject(response);
- response->SetObject("uuid", std::make_shared<JSONString>(uuid_str));
- response->SetObject(
- "triple",
- std::make_shared<JSONString>(
- matched_module_spec.GetArchitecture().GetTriple().getTriple()));
- response->SetObject("file_path",
- std::make_shared<JSONString>(
- matched_module_spec.GetFileSpec().GetPath()));
- response->SetObject("file_offset",
- std::make_shared<JSONNumber>(file_offset));
- response->SetObject("file_size", std::make_shared<JSONNumber>(file_size));
+ const auto triple_str =
+ matched_module_spec.GetArchitecture().GetTriple().getTriple();
+ const auto file_path = matched_module_spec.GetFileSpec().GetPath();
+
+ json::Object response{{"uuid", uuid_str},
+ {"triple", triple_str},
+ {"file_path", file_path},
+ {"file_offset", static_cast<int64_t>(file_offset)},
+ {"file_size", static_cast<int64_t>(file_size)}};
+ response_array.push_back(std::move(response));
}
StreamString response;
- response_array_sp->Write(response);
+ response.AsRawOstream() << std::move(response_array);
StreamGDBRemote escaped_response;
escaped_response.PutEscapedBytes(response.GetString().data(),
response.GetSize());
@@ -1168,6 +1186,15 @@ void GDBRemoteCommunicationServerCommon::CreateProcessInfoResponse(
proc_info.GetEffectiveUserID(), proc_info.GetEffectiveGroupID());
response.PutCString("name:");
response.PutStringAsRawHex8(proc_info.GetExecutableFile().GetCString());
+
+ response.PutChar(';');
+ response.PutCString("args:");
+ response.PutStringAsRawHex8(proc_info.GetArg0());
+ for (auto &arg : proc_info.GetArguments()) {
+ response.PutChar('-');
+ response.PutStringAsRawHex8(arg.ref());
+ }
+
response.PutChar(';');
const ArchSpec &proc_arch = proc_info.GetArchitecture();
if (proc_arch.IsValid()) {
@@ -1217,6 +1244,7 @@ void GDBRemoteCommunicationServerCommon::
case llvm::Triple::arm:
case llvm::Triple::thumb:
case llvm::Triple::aarch64:
+ case llvm::Triple::aarch64_32:
ostype = "ios";
break;
default:
diff --git a/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerLLGS.cpp b/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerLLGS.cpp
index 196607665bba..ad1a39b57969 100644
--- a/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerLLGS.cpp
+++ b/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerLLGS.cpp
@@ -11,7 +11,7 @@
#include "lldb/Host/Config.h"
#include "GDBRemoteCommunicationServerLLGS.h"
-#include "lldb/Utility/StreamGDBRemote.h"
+#include "lldb/Utility/GDBRemote.h"
#include <chrono>
#include <cstring>
@@ -32,7 +32,6 @@
#include "lldb/Utility/Args.h"
#include "lldb/Utility/DataBuffer.h"
#include "lldb/Utility/Endian.h"
-#include "lldb/Utility/JSON.h"
#include "lldb/Utility/LLDBAssert.h"
#include "lldb/Utility/Log.h"
#include "lldb/Utility/RegisterValue.h"
@@ -40,6 +39,7 @@
#include "lldb/Utility/StreamString.h"
#include "lldb/Utility/UriParser.h"
#include "llvm/ADT/Triple.h"
+#include "llvm/Support/JSON.h"
#include "llvm/Support/ScopedPrinter.h"
#include "ProcessGDBRemote.h"
@@ -217,8 +217,13 @@ Status GDBRemoteCommunicationServerLLGS::LaunchProcess() {
m_process_launch_info.GetFlags().Set(eLaunchFlagDebug);
if (should_forward_stdio) {
+ // Temporarily relax the following for Windows until we can take advantage
+ // of the recently added pty support. This doesn't really affect the use of
+ // lldb-server on Windows.
+#if !defined(_WIN32)
if (llvm::Error Err = m_process_launch_info.SetUpPtyRedirection())
return Status(std::move(Err));
+#endif
}
{
@@ -249,18 +254,18 @@ Status GDBRemoteCommunicationServerLLGS::LaunchProcess() {
// Setup stdout/stderr mapping from inferior to $O
auto terminal_fd = m_debugged_process_up->GetTerminalFileDescriptor();
if (terminal_fd >= 0) {
- if (log)
- log->Printf("ProcessGDBRemoteCommunicationServerLLGS::%s setting "
- "inferior STDIO fd to %d",
- __FUNCTION__, terminal_fd);
+ LLDB_LOGF(log,
+ "ProcessGDBRemoteCommunicationServerLLGS::%s setting "
+ "inferior STDIO fd to %d",
+ __FUNCTION__, terminal_fd);
Status status = SetSTDIOFileDescriptor(terminal_fd);
if (status.Fail())
return status;
} else {
- if (log)
- log->Printf("ProcessGDBRemoteCommunicationServerLLGS::%s ignoring "
- "inferior STDIO since terminal fd reported as %d",
- __FUNCTION__, terminal_fd);
+ LLDB_LOGF(log,
+ "ProcessGDBRemoteCommunicationServerLLGS::%s ignoring "
+ "inferior STDIO since terminal fd reported as %d",
+ __FUNCTION__, terminal_fd);
}
} else {
LLDB_LOG(log,
@@ -278,9 +283,8 @@ Status GDBRemoteCommunicationServerLLGS::LaunchProcess() {
Status GDBRemoteCommunicationServerLLGS::AttachToProcess(lldb::pid_t pid) {
Log *log(GetLogIfAnyCategoriesSet(LIBLLDB_LOG_PROCESS));
- if (log)
- log->Printf("GDBRemoteCommunicationServerLLGS::%s pid %" PRIu64,
- __FUNCTION__, pid);
+ LLDB_LOGF(log, "GDBRemoteCommunicationServerLLGS::%s pid %" PRIu64,
+ __FUNCTION__, pid);
// Before we try to attach, make sure we aren't already monitoring something
// else.
@@ -304,18 +308,18 @@ Status GDBRemoteCommunicationServerLLGS::AttachToProcess(lldb::pid_t pid) {
// Setup stdout/stderr mapping from inferior.
auto terminal_fd = m_debugged_process_up->GetTerminalFileDescriptor();
if (terminal_fd >= 0) {
- if (log)
- log->Printf("ProcessGDBRemoteCommunicationServerLLGS::%s setting "
- "inferior STDIO fd to %d",
- __FUNCTION__, terminal_fd);
+ LLDB_LOGF(log,
+ "ProcessGDBRemoteCommunicationServerLLGS::%s setting "
+ "inferior STDIO fd to %d",
+ __FUNCTION__, terminal_fd);
Status status = SetSTDIOFileDescriptor(terminal_fd);
if (status.Fail())
return status;
} else {
- if (log)
- log->Printf("ProcessGDBRemoteCommunicationServerLLGS::%s ignoring "
- "inferior STDIO since terminal fd reported as %d",
- __FUNCTION__, terminal_fd);
+ LLDB_LOGF(log,
+ "ProcessGDBRemoteCommunicationServerLLGS::%s ignoring "
+ "inferior STDIO since terminal fd reported as %d",
+ __FUNCTION__, terminal_fd);
}
printf("Attached to process %" PRIu64 "...\n", pid);
@@ -327,10 +331,11 @@ void GDBRemoteCommunicationServerLLGS::InitializeDelegate(
assert(process && "process cannot be NULL");
Log *log(GetLogIfAnyCategoriesSet(LIBLLDB_LOG_PROCESS));
if (log) {
- log->Printf("GDBRemoteCommunicationServerLLGS::%s called with "
- "NativeProcessProtocol pid %" PRIu64 ", current state: %s",
- __FUNCTION__, process->GetID(),
- StateAsCString(process->GetState()));
+ LLDB_LOGF(log,
+ "GDBRemoteCommunicationServerLLGS::%s called with "
+ "NativeProcessProtocol pid %" PRIu64 ", current state: %s",
+ __FUNCTION__, process->GetID(),
+ StateAsCString(process->GetState()));
}
}
@@ -397,19 +402,21 @@ static void WriteRegisterValueInHexFixedWidth(
}
}
-static JSONObject::SP GetRegistersAsJSON(NativeThreadProtocol &thread) {
+static llvm::Expected<json::Object>
+GetRegistersAsJSON(NativeThreadProtocol &thread) {
Log *log(GetLogIfAnyCategoriesSet(LIBLLDB_LOG_THREAD));
NativeRegisterContext& reg_ctx = thread.GetRegisterContext();
- JSONObject::SP register_object_sp = std::make_shared<JSONObject>();
+ json::Object register_object;
#ifdef LLDB_JTHREADSINFO_FULL_REGISTER_SET
// 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 = reg_ctx_sp->GetRegisterSet(0);
if (!reg_set_p)
- return nullptr;
+ return llvm::make_error<llvm::StringError>("failed to get registers",
+ llvm::inconvertibleErrorCode());
for (const uint32_t *reg_num_p = reg_set_p->registers;
*reg_num_p != LLDB_INVALID_REGNUM; ++reg_num_p) {
uint32_t reg_num = *reg_num_p;
@@ -431,10 +438,9 @@ static JSONObject::SP GetRegistersAsJSON(NativeThreadProtocol &thread) {
const RegisterInfo *const reg_info_p =
reg_ctx.GetRegisterInfoAtIndex(reg_num);
if (reg_info_p == nullptr) {
- if (log)
- log->Printf(
- "%s failed to get register info for register index %" PRIu32,
- __FUNCTION__, reg_num);
+ LLDB_LOGF(log,
+ "%s failed to get register info for register index %" PRIu32,
+ __FUNCTION__, reg_num);
continue;
}
@@ -445,11 +451,10 @@ static JSONObject::SP GetRegistersAsJSON(NativeThreadProtocol &thread) {
RegisterValue 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",
- __FUNCTION__,
- reg_info_p->name ? reg_info_p->name : "<unnamed-register>",
- reg_num, error.AsCString());
+ LLDB_LOGF(log, "%s failed to read register '%s' index %" PRIu32 ": %s",
+ __FUNCTION__,
+ reg_info_p->name ? reg_info_p->name : "<unnamed-register>",
+ reg_num, error.AsCString());
continue;
}
@@ -457,12 +462,11 @@ static JSONObject::SP GetRegistersAsJSON(NativeThreadProtocol &thread) {
WriteRegisterValueInHexFixedWidth(stream, reg_ctx, *reg_info_p,
&reg_value, lldb::eByteOrderBig);
- register_object_sp->SetObject(
- llvm::to_string(reg_num),
- std::make_shared<JSONString>(stream.GetString()));
+ register_object.try_emplace(llvm::to_string(reg_num),
+ stream.GetString().str());
}
- return register_object_sp;
+ return register_object;
}
static const char *GetStopReasonString(StopReason stop_reason) {
@@ -489,11 +493,11 @@ static const char *GetStopReasonString(StopReason stop_reason) {
return nullptr;
}
-static JSONArray::SP GetJSONThreadsInfo(NativeProcessProtocol &process,
- bool abridged) {
+static llvm::Expected<json::Array>
+GetJSONThreadsInfo(NativeProcessProtocol &process, bool abridged) {
Log *log(GetLogIfAnyCategoriesSet(LIBLLDB_LOG_PROCESS | LIBLLDB_LOG_THREAD));
- JSONArray::SP threads_array_sp = std::make_shared<JSONArray>();
+ json::Array threads_array;
// Ensure we can get info on the given thread.
uint32_t thread_idx = 0;
@@ -507,61 +511,62 @@ static JSONArray::SP GetJSONThreadsInfo(NativeProcessProtocol &process,
struct ThreadStopInfo tid_stop_info;
std::string description;
if (!thread->GetStopReason(tid_stop_info, description))
- return nullptr;
+ return llvm::make_error<llvm::StringError>(
+ "failed to get stop reason", llvm::inconvertibleErrorCode());
const int signum = tid_stop_info.details.signal.signo;
if (log) {
- log->Printf("GDBRemoteCommunicationServerLLGS::%s pid %" PRIu64
- " tid %" PRIu64
- " got signal signo = %d, reason = %d, exc_type = %" PRIu64,
- __FUNCTION__, process.GetID(), tid, signum,
- tid_stop_info.reason, tid_stop_info.details.exception.type);
+ LLDB_LOGF(log,
+ "GDBRemoteCommunicationServerLLGS::%s pid %" PRIu64
+ " tid %" PRIu64
+ " got signal signo = %d, reason = %d, exc_type = %" PRIu64,
+ __FUNCTION__, process.GetID(), tid, signum,
+ tid_stop_info.reason, tid_stop_info.details.exception.type);
}
- JSONObject::SP thread_obj_sp = std::make_shared<JSONObject>();
- threads_array_sp->AppendObject(thread_obj_sp);
+ json::Object thread_obj;
if (!abridged) {
- if (JSONObject::SP registers_sp = GetRegistersAsJSON(*thread))
- thread_obj_sp->SetObject("registers", registers_sp);
+ if (llvm::Expected<json::Object> registers =
+ GetRegistersAsJSON(*thread)) {
+ thread_obj.try_emplace("registers", std::move(*registers));
+ } else {
+ return registers.takeError();
+ }
}
- thread_obj_sp->SetObject("tid", std::make_shared<JSONNumber>(tid));
+ thread_obj.try_emplace("tid", static_cast<int64_t>(tid));
+
if (signum != 0)
- thread_obj_sp->SetObject("signal", std::make_shared<JSONNumber>(signum));
+ thread_obj.try_emplace("signal", signum);
const std::string thread_name = thread->GetName();
if (!thread_name.empty())
- thread_obj_sp->SetObject("name",
- std::make_shared<JSONString>(thread_name));
+ thread_obj.try_emplace("name", thread_name);
- if (const char *stop_reason_str = GetStopReasonString(tid_stop_info.reason))
- thread_obj_sp->SetObject("reason",
- std::make_shared<JSONString>(stop_reason_str));
+ const char *stop_reason = GetStopReasonString(tid_stop_info.reason);
+ if (stop_reason)
+ thread_obj.try_emplace("reason", stop_reason);
if (!description.empty())
- thread_obj_sp->SetObject("description",
- std::make_shared<JSONString>(description));
+ thread_obj.try_emplace("description", description);
if ((tid_stop_info.reason == eStopReasonException) &&
tid_stop_info.details.exception.type) {
- thread_obj_sp->SetObject(
- "metype",
- std::make_shared<JSONNumber>(tid_stop_info.details.exception.type));
+ thread_obj.try_emplace(
+ "metype", static_cast<int64_t>(tid_stop_info.details.exception.type));
- JSONArray::SP medata_array_sp = std::make_shared<JSONArray>();
+ json::Array medata_array;
for (uint32_t i = 0; i < tid_stop_info.details.exception.data_count;
++i) {
- medata_array_sp->AppendObject(std::make_shared<JSONNumber>(
- tid_stop_info.details.exception.data[i]));
+ medata_array.push_back(
+ static_cast<int64_t>(tid_stop_info.details.exception.data[i]));
}
- thread_obj_sp->SetObject("medata", medata_array_sp);
+ thread_obj.try_emplace("medata", std::move(medata_array));
}
-
- // TODO: Expedite interesting regions of inferior memory
+ threads_array.push_back(std::move(thread_obj));
}
-
- return threads_array_sp;
+ return threads_array;
}
GDBRemoteCommunication::PacketResult
@@ -653,19 +658,21 @@ GDBRemoteCommunicationServerLLGS::SendStopReplyPacketForThread(
// is hex ascii JSON that contains the thread IDs thread stop info only for
// threads that have stop reasons. Only send this if we have more than one
// thread otherwise this packet has all the info it needs.
- if (thread_index > 0) {
+ if (thread_index > 1) {
const bool threads_with_valid_stop_info_only = true;
- JSONArray::SP threads_info_sp = GetJSONThreadsInfo(
+ llvm::Expected<json::Array> threads_info = GetJSONThreadsInfo(
*m_debugged_process_up, threads_with_valid_stop_info_only);
- if (threads_info_sp) {
+ if (threads_info) {
response.PutCString("jstopinfo:");
StreamString unescaped_response;
- threads_info_sp->Write(unescaped_response);
+ unescaped_response.AsRawOstream() << std::move(*threads_info);
response.PutStringAsRawHex8(unescaped_response.GetData());
response.PutChar(';');
- } else
- LLDB_LOG(log, "failed to prepare a jstopinfo field for pid {0}",
- m_debugged_process_up->GetID());
+ } else {
+ LLDB_LOG(log, "failed to prepare a jstopinfo field for pid {0}:",
+ m_debugged_process_up->GetID(),
+ llvm::toString(threads_info.takeError()));
+ }
}
uint32_t i = 0;
@@ -684,12 +691,10 @@ GDBRemoteCommunicationServerLLGS::SendStopReplyPacketForThread(
RegisterValue 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",
- __FUNCTION__,
- reg_info_p->name ? reg_info_p->name
- : "<unnamed-register>",
- reg_to_read, error.AsCString());
+ LLDB_LOGF(log, "%s failed to read register '%s' index %" PRIu32 ": %s",
+ __FUNCTION__,
+ reg_info_p->name ? reg_info_p->name : "<unnamed-register>",
+ reg_to_read, error.AsCString());
continue;
}
@@ -713,25 +718,24 @@ GDBRemoteCommunicationServerLLGS::SendStopReplyPacketForThread(
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);
+ LLDB_LOGF(log,
+ "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);
+ LLDB_LOGF(log,
+ "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;
@@ -742,13 +746,12 @@ GDBRemoteCommunicationServerLLGS::SendStopReplyPacketForThread(
&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());
+ LLDB_LOGF(log,
+ "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());
}
}
}
@@ -787,15 +790,14 @@ void GDBRemoteCommunicationServerLLGS::HandleInferiorState_Exited(
assert(process && "process cannot be NULL");
Log *log(GetLogIfAnyCategoriesSet(LIBLLDB_LOG_PROCESS));
- if (log)
- log->Printf("GDBRemoteCommunicationServerLLGS::%s called", __FUNCTION__);
+ LLDB_LOGF(log, "GDBRemoteCommunicationServerLLGS::%s called", __FUNCTION__);
PacketResult result = SendStopReasonForState(StateType::eStateExited);
if (result != PacketResult::Success) {
- if (log)
- log->Printf("GDBRemoteCommunicationServerLLGS::%s failed to send stop "
- "notification for PID %" PRIu64 ", state: eStateExited",
- __FUNCTION__, process->GetID());
+ LLDB_LOGF(log,
+ "GDBRemoteCommunicationServerLLGS::%s failed to send stop "
+ "notification for PID %" PRIu64 ", state: eStateExited",
+ __FUNCTION__, process->GetID());
}
// Close the pipe to the inferior terminal i/o if we launched it and set one
@@ -812,8 +814,7 @@ void GDBRemoteCommunicationServerLLGS::HandleInferiorState_Stopped(
assert(process && "process cannot be NULL");
Log *log(GetLogIfAnyCategoriesSet(LIBLLDB_LOG_PROCESS));
- if (log)
- log->Printf("GDBRemoteCommunicationServerLLGS::%s called", __FUNCTION__);
+ LLDB_LOGF(log, "GDBRemoteCommunicationServerLLGS::%s called", __FUNCTION__);
// Send the stop reason unless this is the stop after the launch or attach.
switch (m_inferior_prev_state) {
@@ -825,10 +826,10 @@ void GDBRemoteCommunicationServerLLGS::HandleInferiorState_Stopped(
// In all other cases, send the stop reason.
PacketResult result = SendStopReasonForState(StateType::eStateStopped);
if (result != PacketResult::Success) {
- if (log)
- log->Printf("GDBRemoteCommunicationServerLLGS::%s failed to send stop "
- "notification for PID %" PRIu64 ", state: eStateExited",
- __FUNCTION__, process->GetID());
+ LLDB_LOGF(log,
+ "GDBRemoteCommunicationServerLLGS::%s failed to send stop "
+ "notification for PID %" PRIu64 ", state: eStateExited",
+ __FUNCTION__, process->GetID());
}
break;
}
@@ -839,9 +840,10 @@ void GDBRemoteCommunicationServerLLGS::ProcessStateChanged(
assert(process && "process cannot be NULL");
Log *log(GetLogIfAnyCategoriesSet(LIBLLDB_LOG_PROCESS));
if (log) {
- log->Printf("GDBRemoteCommunicationServerLLGS::%s called with "
- "NativeProcessProtocol pid %" PRIu64 ", state: %s",
- __FUNCTION__, process->GetID(), StateAsCString(state));
+ LLDB_LOGF(log,
+ "GDBRemoteCommunicationServerLLGS::%s called with "
+ "NativeProcessProtocol pid %" PRIu64 ", state: %s",
+ __FUNCTION__, process->GetID(), StateAsCString(state));
}
switch (state) {
@@ -868,9 +870,10 @@ void GDBRemoteCommunicationServerLLGS::ProcessStateChanged(
default:
if (log) {
- log->Printf("GDBRemoteCommunicationServerLLGS::%s didn't handle state "
- "change for pid %" PRIu64 ", new state: %s",
- __FUNCTION__, process->GetID(), StateAsCString(state));
+ LLDB_LOGF(log,
+ "GDBRemoteCommunicationServerLLGS::%s didn't handle state "
+ "change for pid %" PRIu64 ", new state: %s",
+ __FUNCTION__, process->GetID(), StateAsCString(state));
}
break;
}
@@ -888,10 +891,10 @@ void GDBRemoteCommunicationServerLLGS::DataAvailableCallback() {
if (!m_handshake_completed) {
if (!HandshakeWithClient()) {
- if (log)
- log->Printf("GDBRemoteCommunicationServerLLGS::%s handshake with "
- "client failed, exiting",
- __FUNCTION__);
+ LLDB_LOGF(log,
+ "GDBRemoteCommunicationServerLLGS::%s handshake with "
+ "client failed, exiting",
+ __FUNCTION__);
m_mainloop.RequestTermination();
return;
}
@@ -908,10 +911,10 @@ void GDBRemoteCommunicationServerLLGS::DataAvailableCallback() {
break; // No more packets in the queue
if ((result != PacketResult::Success)) {
- if (log)
- log->Printf("GDBRemoteCommunicationServerLLGS::%s processing a packet "
- "failed: %s",
- __FUNCTION__, error.AsCString());
+ LLDB_LOGF(log,
+ "GDBRemoteCommunicationServerLLGS::%s processing a packet "
+ "failed: %s",
+ __FUNCTION__, error.AsCString());
m_mainloop.RequestTermination();
break;
}
@@ -982,9 +985,10 @@ void GDBRemoteCommunicationServerLLGS::StartSTDIOForwarding() {
// Not much we can do about the failure. Log it and continue without
// forwarding.
if (Log *log = GetLogIfAnyCategoriesSet(LIBLLDB_LOG_PROCESS))
- log->Printf("GDBRemoteCommunicationServerLLGS::%s Failed to set up stdio "
- "forwarding: %s",
- __FUNCTION__, error.AsCString());
+ LLDB_LOGF(log,
+ "GDBRemoteCommunicationServerLLGS::%s Failed to set up stdio "
+ "forwarding: %s",
+ __FUNCTION__, error.AsCString());
}
}
@@ -1008,10 +1012,11 @@ void GDBRemoteCommunicationServerLLGS::SendProcessOutput() {
case eConnectionStatusError:
case eConnectionStatusNoConnection:
if (Log *log = GetLogIfAnyCategoriesSet(LIBLLDB_LOG_PROCESS))
- log->Printf("GDBRemoteCommunicationServerLLGS::%s Stopping stdio "
- "forwarding as communication returned status %d (error: "
- "%s)",
- __FUNCTION__, status, error.AsCString());
+ LLDB_LOGF(log,
+ "GDBRemoteCommunicationServerLLGS::%s Stopping stdio "
+ "forwarding as communication returned status %d (error: "
+ "%s)",
+ __FUNCTION__, status, error.AsCString());
m_stdio_handle_up.reset();
return;
@@ -1349,15 +1354,14 @@ GDBRemoteCommunicationServerLLGS::Handle_qGetWorkingDir(
GDBRemoteCommunication::PacketResult
GDBRemoteCommunicationServerLLGS::Handle_C(StringExtractorGDBRemote &packet) {
Log *log(GetLogIfAnyCategoriesSet(LIBLLDB_LOG_PROCESS | LIBLLDB_LOG_THREAD));
- if (log)
- log->Printf("GDBRemoteCommunicationServerLLGS::%s called", __FUNCTION__);
+ LLDB_LOGF(log, "GDBRemoteCommunicationServerLLGS::%s called", __FUNCTION__);
// Ensure we have a native process.
if (!m_debugged_process_up) {
- if (log)
- log->Printf("GDBRemoteCommunicationServerLLGS::%s no debugged process "
- "shared pointer",
- __FUNCTION__);
+ LLDB_LOGF(log,
+ "GDBRemoteCommunicationServerLLGS::%s no debugged process "
+ "shared pointer",
+ __FUNCTION__);
return SendErrorResponse(0x36);
}
@@ -1376,13 +1380,14 @@ GDBRemoteCommunicationServerLLGS::Handle_C(StringExtractorGDBRemote &packet) {
if (packet.GetBytesLeft() > 0) {
// FIXME add continue at address support for $C{signo}[;{continue-address}].
if (*packet.Peek() == ';')
- return SendUnimplementedResponse(packet.GetStringRef().c_str());
+ return SendUnimplementedResponse(packet.GetStringRef().data());
else
return SendIllFormedResponse(
packet, "unexpected content after $C{signal-number}");
}
- ResumeActionList resume_actions(StateType::eStateRunning, 0);
+ ResumeActionList resume_actions(StateType::eStateRunning,
+ LLDB_INVALID_SIGNAL_NUMBER);
Status error;
// We have two branches: what to do if a continue thread is specified (in
@@ -1430,8 +1435,7 @@ GDBRemoteCommunicationServerLLGS::Handle_C(StringExtractorGDBRemote &packet) {
GDBRemoteCommunication::PacketResult
GDBRemoteCommunicationServerLLGS::Handle_c(StringExtractorGDBRemote &packet) {
Log *log(GetLogIfAnyCategoriesSet(LIBLLDB_LOG_PROCESS | LIBLLDB_LOG_THREAD));
- if (log)
- log->Printf("GDBRemoteCommunicationServerLLGS::%s called", __FUNCTION__);
+ LLDB_LOGF(log, "GDBRemoteCommunicationServerLLGS::%s called", __FUNCTION__);
packet.SetFilePos(packet.GetFilePos() + ::strlen("c"));
@@ -1440,20 +1444,21 @@ GDBRemoteCommunicationServerLLGS::Handle_c(StringExtractorGDBRemote &packet) {
if (has_continue_address) {
LLDB_LOG(log, "not implemented for c[address] variant [{0} remains]",
packet.Peek());
- return SendUnimplementedResponse(packet.GetStringRef().c_str());
+ return SendUnimplementedResponse(packet.GetStringRef().data());
}
// Ensure we have a native process.
if (!m_debugged_process_up) {
- if (log)
- log->Printf("GDBRemoteCommunicationServerLLGS::%s no debugged process "
- "shared pointer",
- __FUNCTION__);
+ LLDB_LOGF(log,
+ "GDBRemoteCommunicationServerLLGS::%s no debugged process "
+ "shared pointer",
+ __FUNCTION__);
return SendErrorResponse(0x36);
}
// Build the ResumeActionList
- ResumeActionList actions(StateType::eStateRunning, 0);
+ ResumeActionList actions(StateType::eStateRunning,
+ LLDB_INVALID_SIGNAL_NUMBER);
Status error = m_debugged_process_up->Resume(actions);
if (error.Fail()) {
@@ -1480,17 +1485,16 @@ GDBRemoteCommunication::PacketResult
GDBRemoteCommunicationServerLLGS::Handle_vCont(
StringExtractorGDBRemote &packet) {
Log *log(GetLogIfAnyCategoriesSet(LIBLLDB_LOG_PROCESS));
- if (log)
- log->Printf("GDBRemoteCommunicationServerLLGS::%s handling vCont packet",
- __FUNCTION__);
+ LLDB_LOGF(log, "GDBRemoteCommunicationServerLLGS::%s handling vCont packet",
+ __FUNCTION__);
packet.SetFilePos(::strlen("vCont"));
if (packet.GetBytesLeft() == 0) {
- if (log)
- log->Printf("GDBRemoteCommunicationServerLLGS::%s missing action from "
- "vCont package",
- __FUNCTION__);
+ LLDB_LOGF(log,
+ "GDBRemoteCommunicationServerLLGS::%s missing action from "
+ "vCont package",
+ __FUNCTION__);
return SendIllFormedResponse(packet, "Missing action from vCont package");
}
@@ -1521,7 +1525,7 @@ GDBRemoteCommunicationServerLLGS::Handle_vCont(
ResumeAction thread_action;
thread_action.tid = LLDB_INVALID_THREAD_ID;
thread_action.state = eStateInvalid;
- thread_action.signal = 0;
+ thread_action.signal = LLDB_INVALID_SIGNAL_NUMBER;
const char action = packet.GetChar();
switch (action) {
@@ -1958,10 +1962,10 @@ GDBRemoteCommunicationServerLLGS::Handle_p(StringExtractorGDBRemote &packet) {
const uint32_t reg_index =
packet.GetHexMaxU32(false, std::numeric_limits<uint32_t>::max());
if (reg_index == std::numeric_limits<uint32_t>::max()) {
- if (log)
- log->Printf("GDBRemoteCommunicationServerLLGS::%s failed, could not "
- "parse register number from request \"%s\"",
- __FUNCTION__, packet.GetStringRef().c_str());
+ LLDB_LOGF(log,
+ "GDBRemoteCommunicationServerLLGS::%s failed, could not "
+ "parse register number from request \"%s\"",
+ __FUNCTION__, packet.GetStringRef().data());
return SendErrorResponse(0x15);
}
@@ -1978,20 +1982,19 @@ 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.GetUserRegisterCount()) {
- if (log)
- log->Printf("GDBRemoteCommunicationServerLLGS::%s failed, requested "
- "register %" PRIu32 " beyond register count %" PRIu32,
- __FUNCTION__, reg_index,
- reg_context.GetUserRegisterCount());
+ LLDB_LOGF(log,
+ "GDBRemoteCommunicationServerLLGS::%s failed, requested "
+ "register %" PRIu32 " beyond register count %" PRIu32,
+ __FUNCTION__, reg_index, reg_context.GetUserRegisterCount());
return SendErrorResponse(0x15);
}
const RegisterInfo *reg_info = reg_context.GetRegisterInfoAtIndex(reg_index);
if (!reg_info) {
- if (log)
- log->Printf("GDBRemoteCommunicationServerLLGS::%s failed, requested "
- "register %" PRIu32 " returned NULL",
- __FUNCTION__, reg_index);
+ LLDB_LOGF(log,
+ "GDBRemoteCommunicationServerLLGS::%s failed, requested "
+ "register %" PRIu32 " returned NULL",
+ __FUNCTION__, reg_index);
return SendErrorResponse(0x15);
}
@@ -2002,20 +2005,20 @@ GDBRemoteCommunicationServerLLGS::Handle_p(StringExtractorGDBRemote &packet) {
RegisterValue reg_value;
Status error = reg_context.ReadRegister(reg_info, reg_value);
if (error.Fail()) {
- if (log)
- log->Printf("GDBRemoteCommunicationServerLLGS::%s failed, read of "
- "requested register %" PRIu32 " (%s) failed: %s",
- __FUNCTION__, reg_index, reg_info->name, error.AsCString());
+ LLDB_LOGF(log,
+ "GDBRemoteCommunicationServerLLGS::%s failed, read of "
+ "requested register %" PRIu32 " (%s) failed: %s",
+ __FUNCTION__, reg_index, reg_info->name, error.AsCString());
return SendErrorResponse(0x15);
}
const uint8_t *const data =
reinterpret_cast<const uint8_t *>(reg_value.GetBytes());
if (!data) {
- if (log)
- log->Printf("GDBRemoteCommunicationServerLLGS::%s failed to get data "
- "bytes from requested register %" PRIu32,
- __FUNCTION__, reg_index);
+ LLDB_LOGF(log,
+ "GDBRemoteCommunicationServerLLGS::%s failed to get data "
+ "bytes from requested register %" PRIu32,
+ __FUNCTION__, reg_index);
return SendErrorResponse(0x15);
}
@@ -2039,10 +2042,10 @@ GDBRemoteCommunicationServerLLGS::Handle_P(StringExtractorGDBRemote &packet) {
const uint32_t reg_index =
packet.GetHexMaxU32(false, std::numeric_limits<uint32_t>::max());
if (reg_index == std::numeric_limits<uint32_t>::max()) {
- if (log)
- log->Printf("GDBRemoteCommunicationServerLLGS::%s failed, could not "
- "parse register number from request \"%s\"",
- __FUNCTION__, packet.GetStringRef().c_str());
+ LLDB_LOGF(log,
+ "GDBRemoteCommunicationServerLLGS::%s failed, could not "
+ "parse register number from request \"%s\"",
+ __FUNCTION__, packet.GetStringRef().data());
return SendErrorResponse(0x29);
}
@@ -2058,10 +2061,10 @@ GDBRemoteCommunicationServerLLGS::Handle_P(StringExtractorGDBRemote &packet) {
// Get the thread to use.
NativeThreadProtocol *thread = GetThreadFromSuffix(packet);
if (!thread) {
- if (log)
- log->Printf("GDBRemoteCommunicationServerLLGS::%s failed, no thread "
- "available (thread index 0)",
- __FUNCTION__);
+ LLDB_LOGF(log,
+ "GDBRemoteCommunicationServerLLGS::%s failed, no thread "
+ "available (thread index 0)",
+ __FUNCTION__);
return SendErrorResponse(0x28);
}
@@ -2069,20 +2072,20 @@ GDBRemoteCommunicationServerLLGS::Handle_P(StringExtractorGDBRemote &packet) {
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 "
- "register %" PRIu32 " returned NULL",
- __FUNCTION__, reg_index);
+ LLDB_LOGF(log,
+ "GDBRemoteCommunicationServerLLGS::%s failed, requested "
+ "register %" PRIu32 " returned NULL",
+ __FUNCTION__, reg_index);
return SendErrorResponse(0x48);
}
// Return the end of registers response if we've iterated one past the end of
// the register set.
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.GetUserRegisterCount());
+ LLDB_LOGF(log,
+ "GDBRemoteCommunicationServerLLGS::%s failed, requested "
+ "register %" PRIu32 " beyond register count %" PRIu32,
+ __FUNCTION__, reg_index, reg_context.GetUserRegisterCount());
return SendErrorResponse(0x47);
}
@@ -2101,10 +2104,10 @@ GDBRemoteCommunicationServerLLGS::Handle_P(StringExtractorGDBRemote &packet) {
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 "
- "requested register %" PRIu32 " (%s) failed: %s",
- __FUNCTION__, reg_index, reg_info->name, error.AsCString());
+ LLDB_LOGF(log,
+ "GDBRemoteCommunicationServerLLGS::%s failed, write of "
+ "requested register %" PRIu32 " (%s) failed: %s",
+ __FUNCTION__, reg_index, reg_info->name, error.AsCString());
return SendErrorResponse(0x32);
}
@@ -2118,20 +2121,20 @@ GDBRemoteCommunicationServerLLGS::Handle_H(StringExtractorGDBRemote &packet) {
// Fail if we don't have a current process.
if (!m_debugged_process_up ||
(m_debugged_process_up->GetID() == LLDB_INVALID_PROCESS_ID)) {
- if (log)
- log->Printf(
- "GDBRemoteCommunicationServerLLGS::%s failed, no process available",
- __FUNCTION__);
+ LLDB_LOGF(
+ log,
+ "GDBRemoteCommunicationServerLLGS::%s failed, no process available",
+ __FUNCTION__);
return SendErrorResponse(0x15);
}
// Parse out which variant of $H is requested.
packet.SetFilePos(strlen("H"));
if (packet.GetBytesLeft() < 1) {
- if (log)
- log->Printf("GDBRemoteCommunicationServerLLGS::%s failed, H command "
- "missing {g,c} variant",
- __FUNCTION__);
+ LLDB_LOGF(log,
+ "GDBRemoteCommunicationServerLLGS::%s failed, H command "
+ "missing {g,c} variant",
+ __FUNCTION__);
return SendIllFormedResponse(packet, "H command missing {g,c} variant");
}
@@ -2144,10 +2147,10 @@ GDBRemoteCommunicationServerLLGS::Handle_H(StringExtractorGDBRemote &packet) {
break;
default:
- if (log)
- log->Printf(
- "GDBRemoteCommunicationServerLLGS::%s failed, invalid $H variant %c",
- __FUNCTION__, h_variant);
+ LLDB_LOGF(
+ log,
+ "GDBRemoteCommunicationServerLLGS::%s failed, invalid $H variant %c",
+ __FUNCTION__, h_variant);
return SendIllFormedResponse(packet,
"H variant unsupported, should be c or g");
}
@@ -2162,10 +2165,10 @@ GDBRemoteCommunicationServerLLGS::Handle_H(StringExtractorGDBRemote &packet) {
if (tid != LLDB_INVALID_THREAD_ID && tid != 0) {
NativeThreadProtocol *thread = m_debugged_process_up->GetThreadByID(tid);
if (!thread) {
- if (log)
- log->Printf("GDBRemoteCommunicationServerLLGS::%s failed, tid %" PRIu64
- " not found",
- __FUNCTION__, tid);
+ LLDB_LOGF(log,
+ "GDBRemoteCommunicationServerLLGS::%s failed, tid %" PRIu64
+ " not found",
+ __FUNCTION__, tid);
return SendErrorResponse(0x15);
}
}
@@ -2196,10 +2199,10 @@ GDBRemoteCommunicationServerLLGS::Handle_I(StringExtractorGDBRemote &packet) {
// Fail if we don't have a current process.
if (!m_debugged_process_up ||
(m_debugged_process_up->GetID() == LLDB_INVALID_PROCESS_ID)) {
- if (log)
- log->Printf(
- "GDBRemoteCommunicationServerLLGS::%s failed, no process available",
- __FUNCTION__);
+ LLDB_LOGF(
+ log,
+ "GDBRemoteCommunicationServerLLGS::%s failed, no process available",
+ __FUNCTION__);
return SendErrorResponse(0x15);
}
@@ -2257,10 +2260,10 @@ GDBRemoteCommunicationServerLLGS::Handle_memory_read(
if (!m_debugged_process_up ||
(m_debugged_process_up->GetID() == LLDB_INVALID_PROCESS_ID)) {
- if (log)
- log->Printf(
- "GDBRemoteCommunicationServerLLGS::%s failed, no process available",
- __FUNCTION__);
+ LLDB_LOGF(
+ log,
+ "GDBRemoteCommunicationServerLLGS::%s failed, no process available",
+ __FUNCTION__);
return SendErrorResponse(0x15);
}
@@ -2284,10 +2287,10 @@ GDBRemoteCommunicationServerLLGS::Handle_memory_read(
const uint64_t byte_count = packet.GetHexMaxU64(false, 0);
if (byte_count == 0) {
- if (log)
- log->Printf("GDBRemoteCommunicationServerLLGS::%s nothing to read: "
- "zero-length packet",
- __FUNCTION__);
+ LLDB_LOGF(log,
+ "GDBRemoteCommunicationServerLLGS::%s nothing to read: "
+ "zero-length packet",
+ __FUNCTION__);
return SendOKResponse();
}
@@ -2301,20 +2304,20 @@ GDBRemoteCommunicationServerLLGS::Handle_memory_read(
Status error = m_debugged_process_up->ReadMemoryWithoutTrap(
read_addr, &buf[0], byte_count, bytes_read);
if (error.Fail()) {
- if (log)
- log->Printf("GDBRemoteCommunicationServerLLGS::%s pid %" PRIu64
- " mem 0x%" PRIx64 ": failed to read. Error: %s",
- __FUNCTION__, m_debugged_process_up->GetID(), read_addr,
- error.AsCString());
+ LLDB_LOGF(log,
+ "GDBRemoteCommunicationServerLLGS::%s pid %" PRIu64
+ " mem 0x%" PRIx64 ": failed to read. Error: %s",
+ __FUNCTION__, m_debugged_process_up->GetID(), read_addr,
+ error.AsCString());
return SendErrorResponse(0x08);
}
if (bytes_read == 0) {
- if (log)
- log->Printf("GDBRemoteCommunicationServerLLGS::%s pid %" PRIu64
- " mem 0x%" PRIx64 ": read 0 of %" PRIu64 " requested bytes",
- __FUNCTION__, m_debugged_process_up->GetID(), read_addr,
- byte_count);
+ LLDB_LOGF(log,
+ "GDBRemoteCommunicationServerLLGS::%s pid %" PRIu64
+ " mem 0x%" PRIx64 ": read 0 of %" PRIu64 " requested bytes",
+ __FUNCTION__, m_debugged_process_up->GetID(), read_addr,
+ byte_count);
return SendErrorResponse(0x08);
}
@@ -2338,10 +2341,10 @@ GDBRemoteCommunicationServerLLGS::Handle_M(StringExtractorGDBRemote &packet) {
if (!m_debugged_process_up ||
(m_debugged_process_up->GetID() == LLDB_INVALID_PROCESS_ID)) {
- if (log)
- log->Printf(
- "GDBRemoteCommunicationServerLLGS::%s failed, no process available",
- __FUNCTION__);
+ LLDB_LOGF(
+ log,
+ "GDBRemoteCommunicationServerLLGS::%s failed, no process available",
+ __FUNCTION__);
return SendErrorResponse(0x15);
}
@@ -2426,10 +2429,10 @@ GDBRemoteCommunicationServerLLGS::Handle_qMemoryRegionInfoSupported(
// since we won't have a NativeProcessProtocol.
if (!m_debugged_process_up ||
(m_debugged_process_up->GetID() == LLDB_INVALID_PROCESS_ID)) {
- if (log)
- log->Printf(
- "GDBRemoteCommunicationServerLLGS::%s failed, no process available",
- __FUNCTION__);
+ LLDB_LOGF(
+ log,
+ "GDBRemoteCommunicationServerLLGS::%s failed, no process available",
+ __FUNCTION__);
return SendErrorResponse(0x15);
}
@@ -2454,10 +2457,10 @@ GDBRemoteCommunicationServerLLGS::Handle_qMemoryRegionInfo(
// Ensure we have a process.
if (!m_debugged_process_up ||
(m_debugged_process_up->GetID() == LLDB_INVALID_PROCESS_ID)) {
- if (log)
- log->Printf(
- "GDBRemoteCommunicationServerLLGS::%s failed, no process available",
- __FUNCTION__);
+ LLDB_LOGF(
+ log,
+ "GDBRemoteCommunicationServerLLGS::%s failed, no process available",
+ __FUNCTION__);
return SendErrorResponse(0x15);
}
@@ -2703,10 +2706,10 @@ GDBRemoteCommunicationServerLLGS::Handle_s(StringExtractorGDBRemote &packet) {
// Ensure we have a process.
if (!m_debugged_process_up ||
(m_debugged_process_up->GetID() == LLDB_INVALID_PROCESS_ID)) {
- if (log)
- log->Printf(
- "GDBRemoteCommunicationServerLLGS::%s failed, no process available",
- __FUNCTION__);
+ LLDB_LOGF(
+ log,
+ "GDBRemoteCommunicationServerLLGS::%s failed, no process available",
+ __FUNCTION__);
return SendErrorResponse(0x32);
}
@@ -2725,7 +2728,7 @@ GDBRemoteCommunicationServerLLGS::Handle_s(StringExtractorGDBRemote &packet) {
return SendErrorResponse(0x33);
// Create the step action for the given thread.
- ResumeAction action = {tid, eStateStepping, 0};
+ ResumeAction action = {tid, eStateStepping, LLDB_INVALID_SIGNAL_NUMBER};
// Setup the actions list.
ResumeActionList actions;
@@ -2735,11 +2738,11 @@ GDBRemoteCommunicationServerLLGS::Handle_s(StringExtractorGDBRemote &packet) {
actions.SetDefaultThreadActionIfNeeded(eStateStopped, 0);
Status error = m_debugged_process_up->Resume(actions);
if (error.Fail()) {
- if (log)
- log->Printf("GDBRemoteCommunicationServerLLGS::%s pid %" PRIu64
- " tid %" PRIu64 " Resume() failed with error: %s",
- __FUNCTION__, m_debugged_process_up->GetID(), tid,
- error.AsCString());
+ LLDB_LOGF(log,
+ "GDBRemoteCommunicationServerLLGS::%s pid %" PRIu64
+ " tid %" PRIu64 " Resume() failed with error: %s",
+ __FUNCTION__, m_debugged_process_up->GetID(), tid,
+ error.AsCString());
return SendErrorResponse(0x49);
}
@@ -2765,6 +2768,24 @@ GDBRemoteCommunicationServerLLGS::ReadXferObject(llvm::StringRef object,
return std::move(*buffer_or_error);
}
+ if (object == "libraries-svr4") {
+ auto library_list = m_debugged_process_up->GetLoadedSVR4Libraries();
+ if (!library_list)
+ return library_list.takeError();
+
+ StreamString response;
+ response.Printf("<library-list-svr4 version=\"1.0\">");
+ for (auto const &library : *library_list) {
+ response.Printf("<library name=\"%s\" ",
+ XMLEncodeAttributeValue(library.name.c_str()).c_str());
+ response.Printf("lm=\"0x%" PRIx64 "\" ", library.link_map);
+ response.Printf("l_addr=\"0x%" PRIx64 "\" ", library.base_addr);
+ response.Printf("l_ld=\"0x%" PRIx64 "\" />", library.ld_addr);
+ }
+ response.Printf("</library-list-svr4>");
+ return MemoryBuffer::getMemBufferCopy(response.GetString(), __FUNCTION__);
+ }
+
return llvm::make_error<PacketUnimplementedError>(
"Xfer object not supported");
}
@@ -2968,18 +2989,18 @@ GDBRemoteCommunicationServerLLGS::Handle_vAttach(
"vAttach failed to parse the process id");
// Attempt to attach.
- if (log)
- log->Printf("GDBRemoteCommunicationServerLLGS::%s attempting to attach to "
- "pid %" PRIu64,
- __FUNCTION__, pid);
+ LLDB_LOGF(log,
+ "GDBRemoteCommunicationServerLLGS::%s attempting to attach to "
+ "pid %" PRIu64,
+ __FUNCTION__, pid);
Status error = AttachToProcess(pid);
if (error.Fail()) {
- if (log)
- log->Printf("GDBRemoteCommunicationServerLLGS::%s failed to attach to "
- "pid %" PRIu64 ": %s\n",
- __FUNCTION__, pid, error.AsCString());
+ LLDB_LOGF(log,
+ "GDBRemoteCommunicationServerLLGS::%s failed to attach to "
+ "pid %" PRIu64 ": %s\n",
+ __FUNCTION__, pid, error.AsCString());
return SendErrorResponse(error);
}
@@ -2996,10 +3017,10 @@ GDBRemoteCommunicationServerLLGS::Handle_D(StringExtractorGDBRemote &packet) {
// Fail if we don't have a current process.
if (!m_debugged_process_up ||
(m_debugged_process_up->GetID() == LLDB_INVALID_PROCESS_ID)) {
- if (log)
- log->Printf(
- "GDBRemoteCommunicationServerLLGS::%s failed, no process available",
- __FUNCTION__);
+ LLDB_LOGF(
+ log,
+ "GDBRemoteCommunicationServerLLGS::%s failed, no process available",
+ __FUNCTION__);
return SendErrorResponse(0x15);
}
@@ -3023,11 +3044,10 @@ GDBRemoteCommunicationServerLLGS::Handle_D(StringExtractorGDBRemote &packet) {
const Status error = m_debugged_process_up->Detach();
if (error.Fail()) {
- if (log)
- log->Printf("GDBRemoteCommunicationServerLLGS::%s failed to detach from "
- "pid %" PRIu64 ": %s\n",
- __FUNCTION__, m_debugged_process_up->GetID(),
- error.AsCString());
+ LLDB_LOGF(log,
+ "GDBRemoteCommunicationServerLLGS::%s failed to detach from "
+ "pid %" PRIu64 ": %s\n",
+ __FUNCTION__, m_debugged_process_up->GetID(), error.AsCString());
return SendErrorResponse(0x01);
}
@@ -3042,10 +3062,10 @@ GDBRemoteCommunicationServerLLGS::Handle_qThreadStopInfo(
packet.SetFilePos(strlen("qThreadStopInfo"));
const lldb::tid_t tid = packet.GetHexMaxU32(false, LLDB_INVALID_THREAD_ID);
if (tid == LLDB_INVALID_THREAD_ID) {
- if (log)
- log->Printf("GDBRemoteCommunicationServerLLGS::%s failed, could not "
- "parse thread id from request \"%s\"",
- __FUNCTION__, packet.GetStringRef().c_str());
+ LLDB_LOGF(log,
+ "GDBRemoteCommunicationServerLLGS::%s failed, could not "
+ "parse thread id from request \"%s\"",
+ __FUNCTION__, packet.GetStringRef().data());
return SendErrorResponse(0x15);
}
return SendStopReplyPacketForThread(tid);
@@ -3064,15 +3084,16 @@ GDBRemoteCommunicationServerLLGS::Handle_jThreadsInfo(
StreamString response;
const bool threads_with_valid_stop_info_only = false;
- JSONArray::SP threads_array_sp = GetJSONThreadsInfo(
+ llvm::Expected<json::Value> threads_info = GetJSONThreadsInfo(
*m_debugged_process_up, threads_with_valid_stop_info_only);
- if (!threads_array_sp) {
- LLDB_LOG(log, "failed to prepare a packet for pid {0}",
- m_debugged_process_up->GetID());
+ if (!threads_info) {
+ LLDB_LOG(log, "failed to prepare a packet for pid {0}: {1}",
+ m_debugged_process_up->GetID(),
+ llvm::toString(threads_info.takeError()));
return SendErrorResponse(52);
}
- threads_array_sp->Write(response);
+ response.AsRawOstream() << *threads_info;
StreamGDBRemote escaped_response;
escaped_response.PutEscapedBytes(response.GetData(), response.GetSize());
return SendPacketNoLock(escaped_response.GetString());
@@ -3177,15 +3198,15 @@ void GDBRemoteCommunicationServerLLGS::MaybeCloseInferiorTerminalConnection() {
connection->Disconnect(&error);
if (error.Success()) {
- if (log)
- log->Printf("GDBRemoteCommunicationServerLLGS::%s disconnect process "
- "terminal stdio - SUCCESS",
- __FUNCTION__);
+ LLDB_LOGF(log,
+ "GDBRemoteCommunicationServerLLGS::%s disconnect process "
+ "terminal stdio - SUCCESS",
+ __FUNCTION__);
} else {
- if (log)
- log->Printf("GDBRemoteCommunicationServerLLGS::%s disconnect process "
- "terminal stdio - FAIL: %s",
- __FUNCTION__, error.AsCString());
+ LLDB_LOGF(log,
+ "GDBRemoteCommunicationServerLLGS::%s disconnect process "
+ "terminal stdio - FAIL: %s",
+ __FUNCTION__, error.AsCString());
}
}
}
@@ -3215,11 +3236,11 @@ NativeThreadProtocol *GDBRemoteCommunicationServerLLGS::GetThreadFromSuffix(
// Parse out the ';'.
if (packet.GetBytesLeft() < 1 || packet.GetChar() != ';') {
- if (log)
- log->Printf("GDBRemoteCommunicationServerLLGS::%s gdb-remote parse "
- "error: expected ';' prior to start of thread suffix: packet "
- "contents = '%s'",
- __FUNCTION__, packet.GetStringRef().c_str());
+ LLDB_LOGF(log,
+ "GDBRemoteCommunicationServerLLGS::%s gdb-remote parse "
+ "error: expected ';' prior to start of thread suffix: packet "
+ "contents = '%s'",
+ __FUNCTION__, packet.GetStringRef().data());
return nullptr;
}
@@ -3228,11 +3249,11 @@ NativeThreadProtocol *GDBRemoteCommunicationServerLLGS::GetThreadFromSuffix(
// Parse out thread: portion.
if (strncmp(packet.Peek(), "thread:", strlen("thread:")) != 0) {
- if (log)
- log->Printf("GDBRemoteCommunicationServerLLGS::%s gdb-remote parse "
- "error: expected 'thread:' but not found, packet contents = "
- "'%s'",
- __FUNCTION__, packet.GetStringRef().c_str());
+ LLDB_LOGF(log,
+ "GDBRemoteCommunicationServerLLGS::%s gdb-remote parse "
+ "error: expected 'thread:' but not found, packet contents = "
+ "'%s'",
+ __FUNCTION__, packet.GetStringRef().data());
return nullptr;
}
packet.SetFilePos(packet.GetFilePos() + strlen("thread:"));
@@ -3283,3 +3304,28 @@ GDBRemoteCommunicationServerLLGS::FindModuleFile(const std::string &module_path,
return GDBRemoteCommunicationServerCommon::FindModuleFile(module_path, arch);
}
+
+std::string GDBRemoteCommunicationServerLLGS::XMLEncodeAttributeValue(
+ llvm::StringRef value) {
+ std::string result;
+ for (const char &c : value) {
+ switch (c) {
+ case '\'':
+ result += "&apos;";
+ break;
+ case '"':
+ result += "&quot;";
+ break;
+ case '<':
+ result += "&lt;";
+ break;
+ case '>':
+ result += "&gt;";
+ break;
+ default:
+ result += c;
+ break;
+ }
+ }
+ return result;
+}
diff --git a/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerLLGS.h b/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerLLGS.h
index 068ea52caaaf..088ba92ad11a 100644
--- a/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerLLGS.h
+++ b/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerLLGS.h
@@ -196,6 +196,8 @@ protected:
llvm::Expected<std::unique_ptr<llvm::MemoryBuffer>>
ReadXferObject(llvm::StringRef object, llvm::StringRef annex);
+ static std::string XMLEncodeAttributeValue(llvm::StringRef value);
+
private:
void HandleInferiorState_Exited(NativeProcessProtocol *process);
diff --git a/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerPlatform.cpp b/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerPlatform.cpp
index 6deb75f2f021..25cebbba8f7b 100644
--- a/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerPlatform.cpp
+++ b/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerPlatform.cpp
@@ -15,8 +15,10 @@
#include <cstring>
#include <mutex>
#include <sstream>
+#include <thread>
#include "llvm/Support/FileSystem.h"
+#include "llvm/Support/JSON.h"
#include "llvm/Support/Threading.h"
#include "lldb/Host/Config.h"
@@ -26,9 +28,8 @@
#include "lldb/Host/HostInfo.h"
#include "lldb/Target/Platform.h"
#include "lldb/Target/UnixSignals.h"
-#include "lldb/Utility/JSON.h"
+#include "lldb/Utility/GDBRemote.h"
#include "lldb/Utility/Log.h"
-#include "lldb/Utility/StreamGDBRemote.h"
#include "lldb/Utility/StreamString.h"
#include "lldb/Utility/StructuredData.h"
#include "lldb/Utility/UriParser.h"
@@ -36,8 +37,8 @@
#include "lldb/Utility/StringExtractorGDBRemote.h"
using namespace lldb;
-using namespace lldb_private;
using namespace lldb_private::process_gdb_remote;
+using namespace lldb_private;
// GDBRemoteCommunicationServerPlatform constructor
GDBRemoteCommunicationServerPlatform::GDBRemoteCommunicationServerPlatform(
@@ -104,8 +105,8 @@ Status GDBRemoteCommunicationServerPlatform::LaunchGDBServer(
hostname = "127.0.0.1";
Log *log(GetLogIfAnyCategoriesSet(LIBLLDB_LOG_PLATFORM));
- if (log)
- log->Printf("Launching debugserver with: %s:%u...", hostname.c_str(), port);
+ LLDB_LOGF(log, "Launching debugserver with: %s:%u...", hostname.c_str(),
+ port);
// Do not run in a new session so that it can not linger after the platform
// closes.
@@ -161,9 +162,8 @@ GDBRemoteCommunicationServerPlatform::Handle_qLaunchGDBServer(
// process...
Log *log(GetLogIfAnyCategoriesSet(LIBLLDB_LOG_PLATFORM));
- if (log)
- log->Printf("GDBRemoteCommunicationServerPlatform::%s() called",
- __FUNCTION__);
+ LLDB_LOGF(log, "GDBRemoteCommunicationServerPlatform::%s() called",
+ __FUNCTION__);
ConnectionFileDescriptor file_conn;
std::string hostname;
@@ -183,17 +183,17 @@ GDBRemoteCommunicationServerPlatform::Handle_qLaunchGDBServer(
Status error =
LaunchGDBServer(Args(), hostname, debugserver_pid, port, socket_name);
if (error.Fail()) {
- if (log)
- log->Printf("GDBRemoteCommunicationServerPlatform::%s() debugserver "
- "launch failed: %s",
- __FUNCTION__, error.AsCString());
+ LLDB_LOGF(log,
+ "GDBRemoteCommunicationServerPlatform::%s() debugserver "
+ "launch failed: %s",
+ __FUNCTION__, error.AsCString());
return SendErrorResponse(9);
}
- if (log)
- log->Printf("GDBRemoteCommunicationServerPlatform::%s() debugserver "
- "launched successfully as pid %" PRIu64,
- __FUNCTION__, debugserver_pid);
+ LLDB_LOGF(log,
+ "GDBRemoteCommunicationServerPlatform::%s() debugserver "
+ "launched successfully as pid %" PRIu64,
+ __FUNCTION__, debugserver_pid);
StreamGDBRemote response;
response.Printf("pid:%" PRIu64 ";port:%u;", debugserver_pid,
@@ -215,22 +215,21 @@ GDBRemoteCommunicationServerPlatform::Handle_qLaunchGDBServer(
GDBRemoteCommunication::PacketResult
GDBRemoteCommunicationServerPlatform::Handle_qQueryGDBServer(
StringExtractorGDBRemote &packet) {
+ namespace json = llvm::json;
+
if (m_pending_gdb_server.pid == LLDB_INVALID_PROCESS_ID)
return SendErrorResponse(4);
- JSONObject::SP server_sp = std::make_shared<JSONObject>();
- server_sp->SetObject("port",
- std::make_shared<JSONNumber>(m_pending_gdb_server.port));
+ json::Object server{{"port", m_pending_gdb_server.port}};
+
if (!m_pending_gdb_server.socket_name.empty())
- server_sp->SetObject(
- "socket_name",
- std::make_shared<JSONString>(m_pending_gdb_server.socket_name.c_str()));
+ server.try_emplace("socket_name", m_pending_gdb_server.socket_name);
- JSONArray server_list;
- server_list.AppendObject(server_sp);
+ json::Array server_list;
+ server_list.push_back(std::move(server));
StreamGDBRemote response;
- server_list.Write(response);
+ response.AsRawOstream() << std::move(server_list);
StreamGDBRemote escaped_response;
escaped_response.PutEscapedBytes(response.GetString().data(),
@@ -281,10 +280,9 @@ bool GDBRemoteCommunicationServerPlatform::KillSpawnedProcess(lldb::pid_t pid) {
return true;
}
}
- usleep(10000);
+ std::this_thread::sleep_for(std::chrono::milliseconds(10));
}
- // check one more time after the final usleep
{
std::lock_guard<std::recursive_mutex> guard(m_spawned_pids_mutex);
if (m_spawned_pids.find(pid) == m_spawned_pids.end())
@@ -303,10 +301,10 @@ bool GDBRemoteCommunicationServerPlatform::KillSpawnedProcess(lldb::pid_t pid) {
return true;
}
}
- usleep(10000);
+ std::this_thread::sleep_for(std::chrono::milliseconds(10));
}
- // check one more time after the final usleep Scope for locker
+ // check one more time after the final sleep
{
std::lock_guard<std::recursive_mutex> guard(m_spawned_pids_mutex);
if (m_spawned_pids.find(pid) == m_spawned_pids.end())
diff --git a/source/Plugins/Process/gdb-remote/GDBRemoteRegisterContext.cpp b/source/Plugins/Process/gdb-remote/GDBRemoteRegisterContext.cpp
index a77e659a55fa..c06c9527708e 100644
--- a/source/Plugins/Process/gdb-remote/GDBRemoteRegisterContext.cpp
+++ b/source/Plugins/Process/gdb-remote/GDBRemoteRegisterContext.cpp
@@ -206,11 +206,14 @@ bool GDBRemoteRegisterContext::ReadRegisterBytes(const RegisterInfo *reg_info,
} else {
Log *log(ProcessGDBRemoteLog::GetLogIfAnyCategoryIsSet(GDBR_LOG_THREAD |
GDBR_LOG_PACKETS));
- if (log)
- log->Printf ("error: GDBRemoteRegisterContext::ReadRegisterBytes tried to read the "
- "entire register context at once, expected at least %" PRId64 " bytes "
- "but only got %" PRId64 " bytes.", m_reg_data.GetByteSize(),
- buffer_sp->GetByteSize());
+ LLDB_LOGF(
+ log,
+ "error: GDBRemoteRegisterContext::ReadRegisterBytes tried "
+ "to read the "
+ "entire register context at once, expected at least %" PRId64
+ " bytes "
+ "but only got %" PRId64 " bytes.",
+ m_reg_data.GetByteSize(), buffer_sp->GetByteSize());
}
}
return false;
@@ -390,13 +393,15 @@ bool GDBRemoteRegisterContext::WriteRegisterBytes(const RegisterInfo *reg_info,
if (log->GetVerbose()) {
StreamString strm;
gdb_comm.DumpHistory(strm);
- log->Printf("error: failed to get packet sequence mutex, not sending "
- "write register for \"%s\":\n%s",
- reg_info->name, strm.GetData());
+ LLDB_LOGF(log,
+ "error: failed to get packet sequence mutex, not sending "
+ "write register for \"%s\":\n%s",
+ reg_info->name, strm.GetData());
} else
- log->Printf("error: failed to get packet sequence mutex, not sending "
- "write register for \"%s\"",
- reg_info->name);
+ LLDB_LOGF(log,
+ "error: failed to get packet sequence mutex, not sending "
+ "write register for \"%s\"",
+ reg_info->name);
}
}
}
@@ -494,12 +499,14 @@ bool GDBRemoteRegisterContext::ReadAllRegisterValues(
if (log->GetVerbose()) {
StreamString strm;
gdb_comm.DumpHistory(strm);
- log->Printf("error: failed to get packet sequence mutex, not sending "
- "read all registers:\n%s",
- strm.GetData());
+ LLDB_LOGF(log,
+ "error: failed to get packet sequence mutex, not sending "
+ "read all registers:\n%s",
+ strm.GetData());
} else
- log->Printf("error: failed to get packet sequence mutex, not sending "
- "read all registers");
+ LLDB_LOGF(log,
+ "error: failed to get packet sequence mutex, not sending "
+ "read all registers");
}
}
@@ -630,7 +637,9 @@ bool GDBRemoteRegisterContext::WriteAllRegisterValues(
if (m_thread.GetProcess().get()) {
const ArchSpec &arch =
m_thread.GetProcess()->GetTarget().GetArchitecture();
- if (arch.IsValid() && arch.GetMachine() == llvm::Triple::aarch64 &&
+ if (arch.IsValid() &&
+ (arch.GetMachine() == llvm::Triple::aarch64 ||
+ arch.GetMachine() == llvm::Triple::aarch64_32) &&
arch.GetTriple().getVendor() == llvm::Triple::Apple &&
arch.GetTriple().getOS() == llvm::Triple::IOS) {
arm64_debugserver = true;
@@ -667,12 +676,14 @@ bool GDBRemoteRegisterContext::WriteAllRegisterValues(
if (log->GetVerbose()) {
StreamString strm;
gdb_comm.DumpHistory(strm);
- log->Printf("error: failed to get packet sequence mutex, not sending "
- "write all registers:\n%s",
- strm.GetData());
+ LLDB_LOGF(log,
+ "error: failed to get packet sequence mutex, not sending "
+ "write all registers:\n%s",
+ strm.GetData());
} else
- log->Printf("error: failed to get packet sequence mutex, not sending "
- "write all registers");
+ LLDB_LOGF(log,
+ "error: failed to get packet sequence mutex, not sending "
+ "write all registers");
}
}
return false;
diff --git a/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp b/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp
index a6fdd8dd0707..f1762abc55f8 100644
--- a/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp
+++ b/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp
@@ -63,7 +63,6 @@
#include "lldb/Target/TargetList.h"
#include "lldb/Target/ThreadPlanCallFunction.h"
#include "lldb/Utility/Args.h"
-#include "lldb/Utility/CleanUp.h"
#include "lldb/Utility/FileSpec.h"
#include "lldb/Utility/Reproducer.h"
#include "lldb/Utility/State.h"
@@ -81,12 +80,12 @@
#include "lldb/Host/Host.h"
#include "lldb/Utility/StringExtractorGDBRemote.h"
+#include "llvm/ADT/ScopeExit.h"
#include "llvm/ADT/StringSwitch.h"
#include "llvm/Support/Threading.h"
#include "llvm/Support/raw_ostream.h"
#define DEBUGSERVER_BASENAME "debugserver"
-using namespace llvm;
using namespace lldb;
using namespace lldb_private;
using namespace lldb_private::process_gdb_remote;
@@ -99,51 +98,25 @@ namespace lldb {
// namespace. This allows you to attach with a debugger and call this function
// and get the packet history dumped to a file.
void DumpProcessGDBRemotePacketHistory(void *p, const char *path) {
- StreamFile strm;
- Status error = FileSystem::Instance().Open(strm.GetFile(), FileSpec(path),
- File::eOpenOptionWrite |
- File::eOpenOptionCanCreate);
- if (error.Success())
- ((ProcessGDBRemote *)p)->GetGDBRemote().DumpHistory(strm);
+ auto file = FileSystem::Instance().Open(
+ FileSpec(path), File::eOpenOptionWrite | File::eOpenOptionCanCreate);
+ if (!file) {
+ llvm::consumeError(file.takeError());
+ return;
+ }
+ StreamFile stream(std::move(file.get()));
+ ((ProcessGDBRemote *)p)->GetGDBRemote().DumpHistory(stream);
}
} // namespace lldb
namespace {
-static constexpr PropertyDefinition g_properties[] = {
- {"packet-timeout",
- OptionValue::eTypeUInt64,
- true,
- 5
-#if defined(__has_feature)
-#if __has_feature(address_sanitizer)
- * 2
-#endif
-#endif
- ,
- nullptr,
- {},
- "Specify the default packet timeout in seconds."},
- {"target-definition-file",
- OptionValue::eTypeFileSpec,
- true,
- 0,
- nullptr,
- {},
- "The file that provides the description for remote target registers."},
- {"use-libraries-svr4",
- OptionValue::eTypeBoolean,
- true,
- false,
- nullptr,
- {},
- "If true, the libraries-svr4 feature will be used to get a hold of the "
- "process's loaded modules."}};
+#define LLDB_PROPERTIES_processgdbremote
+#include "ProcessGDBRemoteProperties.inc"
enum {
- ePropertyPacketTimeout,
- ePropertyTargetDefinitionFile,
- ePropertyUseSVR4
+#define LLDB_PROPERTIES_processgdbremote
+#include "ProcessGDBRemotePropertiesEnum.inc"
};
class PluginProperties : public Properties {
@@ -154,7 +127,7 @@ public:
PluginProperties() : Properties() {
m_collection_sp = std::make_shared<OptionValueProperties>(GetSettingName());
- m_collection_sp->Initialize(g_properties);
+ m_collection_sp->Initialize(g_processgdbremote_properties);
}
~PluginProperties() override {}
@@ -162,7 +135,7 @@ public:
uint64_t GetPacketTimeout() {
const uint32_t idx = ePropertyPacketTimeout;
return m_collection_sp->GetPropertyAtIndexAsUInt64(
- nullptr, idx, g_properties[idx].default_uint_value);
+ nullptr, idx, g_processgdbremote_properties[idx].default_uint_value);
}
bool SetPacketTimeout(uint64_t timeout) {
@@ -178,7 +151,8 @@ public:
bool GetUseSVR4() const {
const uint32_t idx = ePropertyUseSVR4;
return m_collection_sp->GetPropertyAtIndexAsBoolean(
- nullptr, idx, g_properties[idx].default_uint_value != 0);
+ nullptr, idx,
+ g_processgdbremote_properties[idx].default_uint_value != 0);
}
};
@@ -191,45 +165,6 @@ static const ProcessKDPPropertiesSP &GetGlobalPluginProperties() {
return g_settings_sp;
}
-class ProcessGDBRemoteProvider
- : public repro::Provider<ProcessGDBRemoteProvider> {
-public:
- struct Info {
- static const char *name;
- static const char *file;
- };
-
- ProcessGDBRemoteProvider(const FileSpec &directory) : Provider(directory) {
- }
-
- raw_ostream *GetHistoryStream() {
- FileSpec history_file = GetRoot().CopyByAppendingPathComponent(Info::file);
-
- std::error_code EC;
- m_stream_up = llvm::make_unique<raw_fd_ostream>(history_file.GetPath(), EC,
- sys::fs::OpenFlags::F_Text);
- return m_stream_up.get();
- }
-
- void SetCallback(std::function<void()> callback) {
- m_callback = std::move(callback);
- }
-
- void Keep() override { m_callback(); }
-
- void Discard() override { m_callback(); }
-
- static char ID;
-
-private:
- std::function<void()> m_callback;
- std::unique_ptr<raw_fd_ostream> m_stream_up;
-};
-
-char ProcessGDBRemoteProvider::ID = 0;
-const char *ProcessGDBRemoteProvider::Info::name = "gdb-remote";
-const char *ProcessGDBRemoteProvider::Info::file = "gdb-remote.yaml";
-
} // namespace
// TODO Randomly assigning a port is unsafe. We should get an unused
@@ -339,8 +274,8 @@ ProcessGDBRemote::ProcessGDBRemote(lldb::TargetSP target_sp,
"async thread did exit");
if (repro::Generator *g = repro::Reproducer::Instance().GetGenerator()) {
- ProcessGDBRemoteProvider &provider =
- g->GetOrCreate<ProcessGDBRemoteProvider>();
+ repro::ProcessGDBRemoteProvider &provider =
+ g->GetOrCreate<repro::ProcessGDBRemoteProvider>();
// Set the history stream to the stream owned by the provider.
m_gdb_comm.SetHistoryStream(provider.GetHistoryStream());
// Make sure to clear the stream again when we're finished.
@@ -354,10 +289,10 @@ ProcessGDBRemote::ProcessGDBRemote(lldb::TargetSP target_sp,
if (m_async_listener_sp->StartListeningForEvents(
&m_async_broadcaster, async_event_mask) != async_event_mask) {
- if (log)
- log->Printf("ProcessGDBRemote::%s failed to listen for "
- "m_async_broadcaster events",
- __FUNCTION__);
+ LLDB_LOGF(log,
+ "ProcessGDBRemote::%s failed to listen for "
+ "m_async_broadcaster events",
+ __FUNCTION__);
}
const uint32_t gdb_event_mask =
@@ -365,9 +300,9 @@ ProcessGDBRemote::ProcessGDBRemote(lldb::TargetSP target_sp,
GDBRemoteCommunication::eBroadcastBitGdbReadThreadGotNotify;
if (m_async_listener_sp->StartListeningForEvents(
&m_gdb_comm, gdb_event_mask) != gdb_event_mask) {
- if (log)
- log->Printf("ProcessGDBRemote::%s failed to listen for m_gdb_comm events",
- __FUNCTION__);
+ LLDB_LOGF(log,
+ "ProcessGDBRemote::%s failed to listen for m_gdb_comm events",
+ __FUNCTION__);
}
const uint64_t timeout_seconds =
@@ -785,15 +720,15 @@ Status ProcessGDBRemote::DoConnectRemote(Stream *strm,
pid, remote_url.str().c_str());
}
- if (log)
- log->Printf("ProcessGDBRemote::%s pid %" PRIu64
- ": normalizing target architecture initial triple: %s "
- "(GetTarget().GetArchitecture().IsValid() %s, "
- "m_gdb_comm.GetHostArchitecture().IsValid(): %s)",
- __FUNCTION__, GetID(),
- GetTarget().GetArchitecture().GetTriple().getTriple().c_str(),
- GetTarget().GetArchitecture().IsValid() ? "true" : "false",
- m_gdb_comm.GetHostArchitecture().IsValid() ? "true" : "false");
+ LLDB_LOGF(log,
+ "ProcessGDBRemote::%s pid %" PRIu64
+ ": normalizing target architecture initial triple: %s "
+ "(GetTarget().GetArchitecture().IsValid() %s, "
+ "m_gdb_comm.GetHostArchitecture().IsValid(): %s)",
+ __FUNCTION__, GetID(),
+ GetTarget().GetArchitecture().GetTriple().getTriple().c_str(),
+ GetTarget().GetArchitecture().IsValid() ? "true" : "false",
+ m_gdb_comm.GetHostArchitecture().IsValid() ? "true" : "false");
if (error.Success() && !GetTarget().GetArchitecture().IsValid() &&
m_gdb_comm.GetHostArchitecture().IsValid()) {
@@ -805,11 +740,11 @@ Status ProcessGDBRemote::DoConnectRemote(Stream *strm,
GetTarget().SetArchitecture(m_gdb_comm.GetHostArchitecture());
}
- if (log)
- log->Printf("ProcessGDBRemote::%s pid %" PRIu64
- ": normalized target architecture triple: %s",
- __FUNCTION__, GetID(),
- GetTarget().GetArchitecture().GetTriple().getTriple().c_str());
+ LLDB_LOGF(log,
+ "ProcessGDBRemote::%s pid %" PRIu64
+ ": normalized target architecture triple: %s",
+ __FUNCTION__, GetID(),
+ GetTarget().GetArchitecture().GetTriple().getTriple().c_str());
if (error.Success()) {
PlatformSP platform_sp = GetTarget().GetPlatform();
@@ -834,8 +769,7 @@ Status ProcessGDBRemote::DoLaunch(lldb_private::Module *exe_module,
Log *log(ProcessGDBRemoteLog::GetLogIfAllCategoriesSet(GDBR_LOG_PROCESS));
Status error;
- if (log)
- log->Printf("ProcessGDBRemote::%s() entered", __FUNCTION__);
+ LLDB_LOGF(log, "ProcessGDBRemote::%s() entered", __FUNCTION__);
uint32_t launch_flags = launch_info.GetFlags().Get();
FileSpec stdin_file_spec{};
@@ -862,15 +796,17 @@ Status ProcessGDBRemote::DoLaunch(lldb_private::Module *exe_module,
if (log) {
if (stdin_file_spec || stdout_file_spec || stderr_file_spec)
- log->Printf("ProcessGDBRemote::%s provided with STDIO paths via "
- "launch_info: stdin=%s, stdout=%s, stderr=%s",
- __FUNCTION__,
- stdin_file_spec ? stdin_file_spec.GetCString() : "<null>",
- stdout_file_spec ? stdout_file_spec.GetCString() : "<null>",
- stderr_file_spec ? stderr_file_spec.GetCString() : "<null>");
+ LLDB_LOGF(log,
+ "ProcessGDBRemote::%s provided with STDIO paths via "
+ "launch_info: stdin=%s, stdout=%s, stderr=%s",
+ __FUNCTION__,
+ stdin_file_spec ? stdin_file_spec.GetCString() : "<null>",
+ stdout_file_spec ? stdout_file_spec.GetCString() : "<null>",
+ stderr_file_spec ? stderr_file_spec.GetCString() : "<null>");
else
- log->Printf("ProcessGDBRemote::%s no STDIO paths given via launch_info",
- __FUNCTION__);
+ LLDB_LOGF(log,
+ "ProcessGDBRemote::%s no STDIO paths given via launch_info",
+ __FUNCTION__);
}
const bool disable_stdio = (launch_flags & eLaunchFlagDisableSTDIO) != 0;
@@ -925,24 +861,23 @@ Status ProcessGDBRemote::DoLaunch(lldb_private::Module *exe_module,
if (!stderr_file_spec)
stderr_file_spec = slave_name;
}
- if (log)
- log->Printf(
- "ProcessGDBRemote::%s adjusted STDIO paths for local platform "
- "(IsHost() is true) using slave: stdin=%s, stdout=%s, stderr=%s",
- __FUNCTION__,
- stdin_file_spec ? stdin_file_spec.GetCString() : "<null>",
- stdout_file_spec ? stdout_file_spec.GetCString() : "<null>",
- stderr_file_spec ? stderr_file_spec.GetCString() : "<null>");
+ LLDB_LOGF(
+ log,
+ "ProcessGDBRemote::%s adjusted STDIO paths for local platform "
+ "(IsHost() is true) using slave: stdin=%s, stdout=%s, stderr=%s",
+ __FUNCTION__,
+ stdin_file_spec ? stdin_file_spec.GetCString() : "<null>",
+ stdout_file_spec ? stdout_file_spec.GetCString() : "<null>",
+ stderr_file_spec ? stderr_file_spec.GetCString() : "<null>");
}
- if (log)
- log->Printf("ProcessGDBRemote::%s final STDIO paths after all "
- "adjustments: stdin=%s, stdout=%s, stderr=%s",
- __FUNCTION__,
- stdin_file_spec ? stdin_file_spec.GetCString() : "<null>",
- stdout_file_spec ? stdout_file_spec.GetCString() : "<null>",
- stderr_file_spec ? stderr_file_spec.GetCString()
- : "<null>");
+ LLDB_LOGF(log,
+ "ProcessGDBRemote::%s final STDIO paths after all "
+ "adjustments: stdin=%s, stdout=%s, stderr=%s",
+ __FUNCTION__,
+ stdin_file_spec ? stdin_file_spec.GetCString() : "<null>",
+ stdout_file_spec ? stdout_file_spec.GetCString() : "<null>",
+ stderr_file_spec ? stderr_file_spec.GetCString() : "<null>");
if (stdin_file_spec)
m_gdb_comm.SetSTDIN(stdin_file_spec);
@@ -988,9 +923,8 @@ Status ProcessGDBRemote::DoLaunch(lldb_private::Module *exe_module,
}
if (GetID() == LLDB_INVALID_PROCESS_ID) {
- if (log)
- log->Printf("failed to connect to debugserver: %s",
- error.AsCString());
+ LLDB_LOGF(log, "failed to connect to debugserver: %s",
+ error.AsCString());
KillDebugserverProcess();
return error;
}
@@ -1020,8 +954,7 @@ Status ProcessGDBRemote::DoLaunch(lldb_private::Module *exe_module,
}
}
} else {
- if (log)
- log->Printf("failed to connect to debugserver: %s", error.AsCString());
+ LLDB_LOGF(log, "failed to connect to debugserver: %s", error.AsCString());
}
} else {
// Set our user ID to an invalid process ID.
@@ -1040,9 +973,8 @@ Status ProcessGDBRemote::ConnectToDebugserver(llvm::StringRef connect_url) {
Log *log(ProcessGDBRemoteLog::GetLogIfAllCategoriesSet(GDBR_LOG_PROCESS));
if (!connect_url.empty()) {
- if (log)
- log->Printf("ProcessGDBRemote::%s Connecting to %s", __FUNCTION__,
- connect_url.str().c_str());
+ LLDB_LOGF(log, "ProcessGDBRemote::%s Connecting to %s", __FUNCTION__,
+ connect_url.str().c_str());
std::unique_ptr<ConnectionFileDescriptor> conn_up(
new ConnectionFileDescriptor());
if (conn_up) {
@@ -1062,7 +994,7 @@ Status ProcessGDBRemote::ConnectToDebugserver(llvm::StringRef connect_url) {
if (retry_count >= max_retry_count)
break;
- usleep(100000);
+ std::this_thread::sleep_for(std::chrono::milliseconds(100));
}
}
}
@@ -1116,8 +1048,7 @@ Status ProcessGDBRemote::ConnectToDebugserver(llvm::StringRef connect_url) {
void ProcessGDBRemote::DidLaunchOrAttach(ArchSpec &process_arch) {
Log *log(ProcessGDBRemoteLog::GetLogIfAllCategoriesSet(GDBR_LOG_PROCESS));
- if (log)
- log->Printf("ProcessGDBRemote::%s()", __FUNCTION__);
+ LLDB_LOGF(log, "ProcessGDBRemote::%s()", __FUNCTION__);
if (GetID() != LLDB_INVALID_PROCESS_ID) {
BuildDynamicRegisterInfo(false);
@@ -1130,43 +1061,42 @@ void ProcessGDBRemote::DidLaunchOrAttach(ArchSpec &process_arch) {
const ArchSpec &remote_process_arch = m_gdb_comm.GetProcessArchitecture();
if (remote_process_arch.IsValid()) {
process_arch = remote_process_arch;
- if (log)
- log->Printf("ProcessGDBRemote::%s gdb-remote had process architecture, "
- "using %s %s",
- __FUNCTION__,
- process_arch.GetArchitectureName()
- ? process_arch.GetArchitectureName()
- : "<null>",
- process_arch.GetTriple().getTriple().c_str()
- ? process_arch.GetTriple().getTriple().c_str()
- : "<null>");
+ LLDB_LOGF(log,
+ "ProcessGDBRemote::%s gdb-remote had process architecture, "
+ "using %s %s",
+ __FUNCTION__,
+ process_arch.GetArchitectureName()
+ ? process_arch.GetArchitectureName()
+ : "<null>",
+ process_arch.GetTriple().getTriple().c_str()
+ ? process_arch.GetTriple().getTriple().c_str()
+ : "<null>");
} else {
process_arch = m_gdb_comm.GetHostArchitecture();
- if (log)
- log->Printf("ProcessGDBRemote::%s gdb-remote did not have process "
- "architecture, using gdb-remote host architecture %s %s",
- __FUNCTION__,
- process_arch.GetArchitectureName()
- ? process_arch.GetArchitectureName()
- : "<null>",
- process_arch.GetTriple().getTriple().c_str()
- ? process_arch.GetTriple().getTriple().c_str()
- : "<null>");
+ LLDB_LOGF(log,
+ "ProcessGDBRemote::%s gdb-remote did not have process "
+ "architecture, using gdb-remote host architecture %s %s",
+ __FUNCTION__,
+ process_arch.GetArchitectureName()
+ ? process_arch.GetArchitectureName()
+ : "<null>",
+ process_arch.GetTriple().getTriple().c_str()
+ ? process_arch.GetTriple().getTriple().c_str()
+ : "<null>");
}
if (process_arch.IsValid()) {
const ArchSpec &target_arch = GetTarget().GetArchitecture();
if (target_arch.IsValid()) {
- if (log)
- log->Printf(
- "ProcessGDBRemote::%s analyzing target arch, currently %s %s",
- __FUNCTION__,
- target_arch.GetArchitectureName()
- ? target_arch.GetArchitectureName()
- : "<null>",
- target_arch.GetTriple().getTriple().c_str()
- ? target_arch.GetTriple().getTriple().c_str()
- : "<null>");
+ LLDB_LOGF(log,
+ "ProcessGDBRemote::%s analyzing target arch, currently %s %s",
+ __FUNCTION__,
+ target_arch.GetArchitectureName()
+ ? target_arch.GetArchitectureName()
+ : "<null>",
+ target_arch.GetTriple().getTriple().c_str()
+ ? target_arch.GetTriple().getTriple().c_str()
+ : "<null>");
// If the remote host is ARM and we have apple as the vendor, then
// ARM executables and shared libraries can have mixed ARM
@@ -1180,16 +1110,16 @@ void ProcessGDBRemote::DidLaunchOrAttach(ArchSpec &process_arch) {
process_arch.GetMachine() == llvm::Triple::thumb) &&
process_arch.GetTriple().getVendor() == llvm::Triple::Apple) {
GetTarget().SetArchitecture(process_arch);
- if (log)
- log->Printf("ProcessGDBRemote::%s remote process is ARM/Apple, "
- "setting target arch to %s %s",
- __FUNCTION__,
- process_arch.GetArchitectureName()
- ? process_arch.GetArchitectureName()
- : "<null>",
- process_arch.GetTriple().getTriple().c_str()
- ? process_arch.GetTriple().getTriple().c_str()
- : "<null>");
+ LLDB_LOGF(log,
+ "ProcessGDBRemote::%s remote process is ARM/Apple, "
+ "setting target arch to %s %s",
+ __FUNCTION__,
+ process_arch.GetArchitectureName()
+ ? process_arch.GetArchitectureName()
+ : "<null>",
+ process_arch.GetTriple().getTriple().c_str()
+ ? process_arch.GetTriple().getTriple().c_str()
+ : "<null>");
} else {
// Fill in what is missing in the triple
const llvm::Triple &remote_triple = process_arch.GetTriple();
@@ -1211,16 +1141,16 @@ void ProcessGDBRemote::DidLaunchOrAttach(ArchSpec &process_arch) {
}
}
- if (log)
- log->Printf("ProcessGDBRemote::%s final target arch after "
- "adjustments for remote architecture: %s %s",
- __FUNCTION__,
- target_arch.GetArchitectureName()
- ? target_arch.GetArchitectureName()
- : "<null>",
- target_arch.GetTriple().getTriple().c_str()
- ? target_arch.GetTriple().getTriple().c_str()
- : "<null>");
+ LLDB_LOGF(log,
+ "ProcessGDBRemote::%s final target arch after "
+ "adjustments for remote architecture: %s %s",
+ __FUNCTION__,
+ target_arch.GetArchitectureName()
+ ? target_arch.GetArchitectureName()
+ : "<null>",
+ target_arch.GetTriple().getTriple().c_str()
+ ? target_arch.GetTriple().getTriple().c_str()
+ : "<null>");
} else {
// The target doesn't have a valid architecture yet, set it from the
// architecture we got from the remote GDB server
@@ -1247,8 +1177,7 @@ Status ProcessGDBRemote::DoAttachToProcessWithID(
Log *log(ProcessGDBRemoteLog::GetLogIfAllCategoriesSet(GDBR_LOG_PROCESS));
Status error;
- if (log)
- log->Printf("ProcessGDBRemote::%s()", __FUNCTION__);
+ LLDB_LOGF(log, "ProcessGDBRemote::%s()", __FUNCTION__);
// Clear out and clean up from any current state
Clear();
@@ -1359,8 +1288,7 @@ Status ProcessGDBRemote::WillResume() {
Status ProcessGDBRemote::DoResume() {
Status error;
Log *log(ProcessGDBRemoteLog::GetLogIfAllCategoriesSet(GDBR_LOG_PROCESS));
- if (log)
- log->Printf("ProcessGDBRemote::Resume()");
+ LLDB_LOGF(log, "ProcessGDBRemote::Resume()");
ListenerSP listener_sp(
Listener::MakeListener("gdb-remote.resume-packet-sent"));
@@ -1547,9 +1475,8 @@ Status ProcessGDBRemote::DoResume() {
EventSP event_sp;
if (!m_async_thread.IsJoinable()) {
error.SetErrorString("Trying to resume but the async thread is dead.");
- if (log)
- log->Printf("ProcessGDBRemote::DoResume: Trying to resume but the "
- "async thread is dead.");
+ LLDB_LOGF(log, "ProcessGDBRemote::DoResume: Trying to resume but the "
+ "async thread is dead.");
return error;
}
@@ -1560,14 +1487,13 @@ Status ProcessGDBRemote::DoResume() {
if (!listener_sp->GetEvent(event_sp, std::chrono::seconds(5))) {
error.SetErrorString("Resume timed out.");
- if (log)
- log->Printf("ProcessGDBRemote::DoResume: Resume timed out.");
+ LLDB_LOGF(log, "ProcessGDBRemote::DoResume: Resume timed out.");
} else if (event_sp->BroadcasterIs(&m_async_broadcaster)) {
error.SetErrorString("Broadcast continue, but the async thread was "
"killed before we got an ack back.");
- if (log)
- log->Printf("ProcessGDBRemote::DoResume: Broadcast continue, but the "
- "async thread was killed before we got an ack back.");
+ LLDB_LOGF(log,
+ "ProcessGDBRemote::DoResume: Broadcast continue, but the "
+ "async thread was killed before we got an ack back.");
return error;
}
}
@@ -1864,8 +1790,7 @@ ThreadSP ProcessGDBRemote::SetThreadStopInfo(
}
for (const auto &pair : expedited_register_map) {
- StringExtractor reg_value_extractor;
- reg_value_extractor.GetStringRef() = pair.second;
+ StringExtractor reg_value_extractor(pair.second);
DataBufferSP buffer_sp(new DataBufferHeap(
reg_value_extractor.GetStringRef().size() / 2, 0));
reg_value_extractor.GetHexBytes(buffer_sp->GetData(), '\xcc');
@@ -1979,8 +1904,7 @@ ThreadSP ProcessGDBRemote::SetThreadStopInfo(
if (watch_id == LLDB_INVALID_WATCH_ID) {
Log *log(ProcessGDBRemoteLog::GetLogIfAllCategoriesSet(
GDBR_LOG_WATCHPOINTS));
- if (log)
- log->Printf("failed to find watchpoint");
+ LLDB_LOGF(log, "failed to find watchpoint");
}
thread_sp->SetStopInfo(StopInfo::CreateStopReasonWithWatchpointID(
*thread_sp, watch_id, wp_hit_addr));
@@ -2400,7 +2324,12 @@ StateType ProcessGDBRemote::SetThreadStopInfo(StringExtractor &stop_packet) {
ostr.Printf("%" PRIu64 " %" PRIu32, wp_addr, wp_index);
description = ostr.GetString();
} else if (key.compare("library") == 0) {
- LoadModules();
+ auto error = LoadModules();
+ if (error) {
+ Log *log(
+ ProcessGDBRemoteLog::GetLogIfAllCategoriesSet(GDBR_LOG_PROCESS));
+ LLDB_LOG_ERROR(log, std::move(error), "Failed to load modules: {0}");
+ }
} else if (key.size() == 2 && ::isxdigit(key[0]) && ::isxdigit(key[1])) {
uint32_t reg = UINT32_MAX;
if (!key.getAsInteger(16, reg))
@@ -2474,7 +2403,7 @@ void ProcessGDBRemote::RefreshStateAfterStop() {
// Clear the thread stop stack
m_stop_packet_stack.clear();
}
-
+
// If we have queried for a default thread id
if (m_initial_tid != LLDB_INVALID_THREAD_ID) {
m_thread_list.SetSelectedThreadByID(m_initial_tid);
@@ -2501,8 +2430,7 @@ Status ProcessGDBRemote::DoHalt(bool &caused_stop) {
Status ProcessGDBRemote::DoDetach(bool keep_stopped) {
Status error;
Log *log(ProcessGDBRemoteLog::GetLogIfAllCategoriesSet(GDBR_LOG_PROCESS));
- if (log)
- log->Printf("ProcessGDBRemote::DoDetach(keep_stopped: %i)", keep_stopped);
+ LLDB_LOGF(log, "ProcessGDBRemote::DoDetach(keep_stopped: %i)", keep_stopped);
error = m_gdb_comm.Detach(keep_stopped);
if (log) {
@@ -2510,8 +2438,9 @@ Status ProcessGDBRemote::DoDetach(bool keep_stopped) {
log->PutCString(
"ProcessGDBRemote::DoDetach() detach packet sent successfully");
else
- log->Printf("ProcessGDBRemote::DoDetach() detach packet send failed: %s",
- error.AsCString() ? error.AsCString() : "<unknown error>");
+ LLDB_LOGF(log,
+ "ProcessGDBRemote::DoDetach() detach packet send failed: %s",
+ error.AsCString() ? error.AsCString() : "<unknown error>");
}
if (!error.Success())
@@ -2530,8 +2459,7 @@ Status ProcessGDBRemote::DoDetach(bool keep_stopped) {
Status ProcessGDBRemote::DoDestroy() {
Status error;
Log *log(ProcessGDBRemoteLog::GetLogIfAllCategoriesSet(GDBR_LOG_PROCESS));
- if (log)
- log->Printf("ProcessGDBRemote::DoDestroy()");
+ LLDB_LOGF(log, "ProcessGDBRemote::DoDestroy()");
// There is a bug in older iOS debugservers where they don't shut down the
// process they are debugging properly. If the process is sitting at a
@@ -2586,11 +2514,11 @@ Status ProcessGDBRemote::DoDestroy() {
reason = stop_info_sp->GetStopReason();
if (reason == eStopReasonBreakpoint ||
reason == eStopReasonException) {
- if (log)
- log->Printf(
- "ProcessGDBRemote::DoDestroy() - thread: 0x%4.4" PRIx64
- " stopped with reason: %s.",
- thread_sp->GetProtocolID(), stop_info_sp->GetDescription());
+ LLDB_LOGF(log,
+ "ProcessGDBRemote::DoDestroy() - thread: 0x%4.4" PRIx64
+ " stopped with reason: %s.",
+ thread_sp->GetProtocolID(),
+ stop_info_sp->GetDescription());
stop_looks_like_crash = true;
break;
}
@@ -2622,10 +2550,10 @@ Status ProcessGDBRemote::DoDestroy() {
reason = stop_info_sp->GetStopReason();
if (reason != eStopReasonBreakpoint &&
reason != eStopReasonException) {
- if (log)
- log->Printf("ProcessGDBRemote::DoDestroy() - Suspending "
- "thread: 0x%4.4" PRIx64 " before running.",
- thread_sp->GetProtocolID());
+ LLDB_LOGF(log,
+ "ProcessGDBRemote::DoDestroy() - Suspending "
+ "thread: 0x%4.4" PRIx64 " before running.",
+ thread_sp->GetProtocolID());
thread_sp->SetResumeState(eStateSuspended);
}
}
@@ -2669,30 +2597,28 @@ Status ProcessGDBRemote::DoDestroy() {
int status;
::pid_t reap_pid;
reap_pid = waitpid(GetID(), &status, WNOHANG);
- if (log)
- log->Printf("Reaped pid: %d, status: %d.\n", reap_pid, status);
+ LLDB_LOGF(log, "Reaped pid: %d, status: %d.\n", reap_pid, status);
}
#endif
SetLastStopPacket(response);
ClearThreadIDList();
exit_status = response.GetHexU8();
} else {
- if (log)
- log->Printf("ProcessGDBRemote::DoDestroy - got unexpected response "
- "to k packet: %s",
- response.GetStringRef().c_str());
+ LLDB_LOGF(log,
+ "ProcessGDBRemote::DoDestroy - got unexpected response "
+ "to k packet: %s",
+ response.GetStringRef().data());
exit_string.assign("got unexpected response to k packet: ");
exit_string.append(response.GetStringRef());
}
} else {
- if (log)
- log->Printf("ProcessGDBRemote::DoDestroy - failed to send k packet");
+ LLDB_LOGF(log, "ProcessGDBRemote::DoDestroy - failed to send k packet");
exit_string.assign("failed to send the k packet");
}
} else {
- if (log)
- log->Printf("ProcessGDBRemote::DoDestroy - killed or interrupted while "
- "attaching");
+ LLDB_LOGF(log,
+ "ProcessGDBRemote::DoDestroy - killed or interrupted while "
+ "attaching");
exit_string.assign("killed or interrupted while attaching.");
}
} else {
@@ -2715,8 +2641,7 @@ void ProcessGDBRemote::SetLastStopPacket(
response.GetStringRef().find(";reason:exec;") != std::string::npos;
if (did_exec) {
Log *log(ProcessGDBRemoteLog::GetLogIfAllCategoriesSet(GDBR_LOG_PROCESS));
- if (log)
- log->Printf("ProcessGDBRemote::SetLastStopPacket () - detected exec");
+ LLDB_LOGF(log, "ProcessGDBRemote::SetLastStopPacket () - detected exec");
m_thread_list_real.Clear();
m_thread_list.Clear();
@@ -2756,9 +2681,13 @@ addr_t ProcessGDBRemote::GetImageInfoAddress() {
// the loaded module list can also provides a link map address
if (addr == LLDB_INVALID_ADDRESS) {
- LoadedModuleInfoList list;
- if (GetLoadedModuleList(list).Success())
- addr = list.m_link_map;
+ llvm::Expected<LoadedModuleInfoList> list = GetLoadedModuleList();
+ if (!list) {
+ Log *log(ProcessGDBRemoteLog::GetLogIfAllCategoriesSet(GDBR_LOG_PROCESS));
+ LLDB_LOG_ERROR(log, list.takeError(), "Failed to read module list: {0}");
+ } else {
+ addr = list->m_link_map;
+ }
}
return addr;
@@ -2840,7 +2769,7 @@ size_t ProcessGDBRemote::DoReadMemory(addr_t addr, void *buf, size_t size,
else
error.SetErrorStringWithFormat(
"unexpected response to GDB server memory read packet '%s': '%s'",
- packet, response.GetStringRef().c_str());
+ packet, response.GetStringRef().data());
} else {
error.SetErrorStringWithFormat("failed to send packet: '%s'", packet);
}
@@ -2950,7 +2879,7 @@ Status ProcessGDBRemote::FlashErase(lldb::addr_t addr, size_t size) {
else
status.SetErrorStringWithFormat(
"unexpected response to GDB server flash erase packet '%s': '%s'",
- packet.GetData(), response.GetStringRef().c_str());
+ packet.GetData(), response.GetStringRef().data());
}
} else {
status.SetErrorStringWithFormat("failed to send packet: '%s'",
@@ -2978,7 +2907,7 @@ Status ProcessGDBRemote::FlashDone() {
else
status.SetErrorStringWithFormat(
"unexpected response to GDB server flash done packet: '%s'",
- response.GetStringRef().c_str());
+ response.GetStringRef().data());
}
} else {
status.SetErrorStringWithFormat("failed to send flash done packet");
@@ -3041,7 +2970,7 @@ size_t ProcessGDBRemote::DoWriteMemory(addr_t addr, const void *buf,
else
error.SetErrorStringWithFormat(
"unexpected response to GDB server memory write packet '%s': '%s'",
- packet.GetData(), response.GetStringRef().c_str());
+ packet.GetData(), response.GetStringRef().data());
} else {
error.SetErrorStringWithFormat("failed to send packet: '%s'",
packet.GetData());
@@ -3078,11 +3007,11 @@ lldb::addr_t ProcessGDBRemote::DoAllocateMemory(size_t size,
m_addr_to_mmap_size[allocated_addr] = size;
else {
allocated_addr = LLDB_INVALID_ADDRESS;
- if (log)
- log->Printf("ProcessGDBRemote::%s no direct stub support for memory "
- "allocation, and InferiorCallMmap also failed - is stub "
- "missing register context save/restore capability?",
- __FUNCTION__);
+ LLDB_LOGF(log,
+ "ProcessGDBRemote::%s no direct stub support for memory "
+ "allocation, and InferiorCallMmap also failed - is stub "
+ "missing register context save/restore capability?",
+ __FUNCTION__);
}
}
@@ -3173,17 +3102,17 @@ Status ProcessGDBRemote::EnableBreakpointSite(BreakpointSite *bp_site) {
const addr_t addr = bp_site->GetLoadAddress();
// Log that a breakpoint was requested
- if (log)
- log->Printf("ProcessGDBRemote::EnableBreakpointSite (size_id = %" PRIu64
- ") address = 0x%" PRIx64,
- site_id, (uint64_t)addr);
+ LLDB_LOGF(log,
+ "ProcessGDBRemote::EnableBreakpointSite (size_id = %" PRIu64
+ ") address = 0x%" PRIx64,
+ site_id, (uint64_t)addr);
// Breakpoint already exists and is enabled
if (bp_site->IsEnabled()) {
- if (log)
- log->Printf("ProcessGDBRemote::EnableBreakpointSite (size_id = %" PRIu64
- ") address = 0x%" PRIx64 " -- SUCCESS (already enabled)",
- site_id, (uint64_t)addr);
+ LLDB_LOGF(log,
+ "ProcessGDBRemote::EnableBreakpointSite (size_id = %" PRIu64
+ ") address = 0x%" PRIx64 " -- SUCCESS (already enabled)",
+ site_id, (uint64_t)addr);
return error;
}
@@ -3231,8 +3160,7 @@ Status ProcessGDBRemote::EnableBreakpointSite(BreakpointSite *bp_site) {
// We reach here when software breakpoints have been found to be
// unsupported. For future calls to set a breakpoint, we will not attempt
// to set a breakpoint with a type that is known not to be supported.
- if (log)
- log->Printf("Software breakpoints are unsupported");
+ LLDB_LOGF(log, "Software breakpoints are unsupported");
// So we will fall through and try a hardware breakpoint
}
@@ -3270,8 +3198,7 @@ Status ProcessGDBRemote::EnableBreakpointSite(BreakpointSite *bp_site) {
// We will reach here when the stub gives an unsupported response to a
// hardware breakpoint
- if (log)
- log->Printf("Hardware breakpoints are unsupported");
+ LLDB_LOGF(log, "Hardware breakpoints are unsupported");
// Finally we will falling through to a #trap style breakpoint
}
@@ -3293,10 +3220,10 @@ Status ProcessGDBRemote::DisableBreakpointSite(BreakpointSite *bp_site) {
addr_t addr = bp_site->GetLoadAddress();
user_id_t site_id = bp_site->GetID();
Log *log(ProcessGDBRemoteLog::GetLogIfAllCategoriesSet(GDBR_LOG_BREAKPOINTS));
- if (log)
- log->Printf("ProcessGDBRemote::DisableBreakpointSite (site_id = %" PRIu64
- ") addr = 0x%8.8" PRIx64,
- site_id, (uint64_t)addr);
+ LLDB_LOGF(log,
+ "ProcessGDBRemote::DisableBreakpointSite (site_id = %" PRIu64
+ ") addr = 0x%8.8" PRIx64,
+ site_id, (uint64_t)addr);
if (bp_site->IsEnabled()) {
const size_t bp_op_size = GetSoftwareBreakpointTrapOpcode(bp_site);
@@ -3328,10 +3255,10 @@ Status ProcessGDBRemote::DisableBreakpointSite(BreakpointSite *bp_site) {
if (error.Success())
bp_site->SetEnabled(false);
} else {
- if (log)
- log->Printf("ProcessGDBRemote::DisableBreakpointSite (site_id = %" PRIu64
- ") addr = 0x%8.8" PRIx64 " -- SUCCESS (already disabled)",
- site_id, (uint64_t)addr);
+ LLDB_LOGF(log,
+ "ProcessGDBRemote::DisableBreakpointSite (site_id = %" PRIu64
+ ") addr = 0x%8.8" PRIx64 " -- SUCCESS (already disabled)",
+ site_id, (uint64_t)addr);
return error;
}
@@ -3363,14 +3290,13 @@ Status ProcessGDBRemote::EnableWatchpoint(Watchpoint *wp, bool notify) {
addr_t addr = wp->GetLoadAddress();
Log *log(
ProcessGDBRemoteLog::GetLogIfAllCategoriesSet(GDBR_LOG_WATCHPOINTS));
- if (log)
- log->Printf("ProcessGDBRemote::EnableWatchpoint(watchID = %" PRIu64 ")",
- watchID);
+ LLDB_LOGF(log, "ProcessGDBRemote::EnableWatchpoint(watchID = %" PRIu64 ")",
+ watchID);
if (wp->IsEnabled()) {
- if (log)
- log->Printf("ProcessGDBRemote::EnableWatchpoint(watchID = %" PRIu64
- ") addr = 0x%8.8" PRIx64 ": watchpoint already enabled.",
- watchID, (uint64_t)addr);
+ LLDB_LOGF(log,
+ "ProcessGDBRemote::EnableWatchpoint(watchID = %" PRIu64
+ ") addr = 0x%8.8" PRIx64 ": watchpoint already enabled.",
+ watchID, (uint64_t)addr);
return error;
}
@@ -3403,16 +3329,16 @@ Status ProcessGDBRemote::DisableWatchpoint(Watchpoint *wp, bool notify) {
addr_t addr = wp->GetLoadAddress();
- if (log)
- log->Printf("ProcessGDBRemote::DisableWatchpoint (watchID = %" PRIu64
- ") addr = 0x%8.8" PRIx64,
- watchID, (uint64_t)addr);
+ LLDB_LOGF(log,
+ "ProcessGDBRemote::DisableWatchpoint (watchID = %" PRIu64
+ ") addr = 0x%8.8" PRIx64,
+ watchID, (uint64_t)addr);
if (!wp->IsEnabled()) {
- if (log)
- log->Printf("ProcessGDBRemote::DisableWatchpoint (watchID = %" PRIu64
- ") addr = 0x%8.8" PRIx64 " -- SUCCESS (already disabled)",
- watchID, (uint64_t)addr);
+ LLDB_LOGF(log,
+ "ProcessGDBRemote::DisableWatchpoint (watchID = %" PRIu64
+ ") addr = 0x%8.8" PRIx64 " -- SUCCESS (already disabled)",
+ watchID, (uint64_t)addr);
// See also 'class WatchpointSentry' within StopInfo.cpp. This disabling
// attempt might come from the user-supplied actions, we'll route it in
// order for the watchpoint object to intelligently process this action.
@@ -3447,8 +3373,7 @@ void ProcessGDBRemote::Clear() {
Status ProcessGDBRemote::DoSignal(int signo) {
Status error;
Log *log(ProcessGDBRemoteLog::GetLogIfAllCategoriesSet(GDBR_LOG_PROCESS));
- if (log)
- log->Printf("ProcessGDBRemote::DoSignal (signal = %d)", signo);
+ LLDB_LOGF(log, "ProcessGDBRemote::DoSignal (signal = %d)", signo);
if (!m_gdb_comm.SendAsyncSignal(signo))
error.SetErrorStringWithFormat("failed to send signal %i", signo);
@@ -3460,7 +3385,8 @@ Status ProcessGDBRemote::ConnectToReplayServer(repro::Loader *loader) {
return Status("No loader provided.");
// Construct replay history path.
- FileSpec history_file = loader->GetFile<ProcessGDBRemoteProvider::Info>();
+ FileSpec history_file =
+ loader->GetFile<repro::ProcessGDBRemoteProvider::Info>();
if (!history_file)
return Status("No provider for gdb-remote.");
@@ -3556,8 +3482,8 @@ Status ProcessGDBRemote::LaunchAndConnectToDebugserver(
int our_socket = sockets[0];
int gdb_socket = sockets[1];
- CleanUp cleanup_our(close, our_socket);
- CleanUp cleanup_gdb(close, gdb_socket);
+ auto cleanup_our = llvm::make_scope_exit([&]() { close(our_socket); });
+ auto cleanup_gdb = llvm::make_scope_exit([&]() { close(gdb_socket); });
// Don't let any child processes inherit our communication socket
SetCloexecFlag(our_socket);
@@ -3577,7 +3503,7 @@ Status ProcessGDBRemote::LaunchAndConnectToDebugserver(
#ifdef USE_SOCKETPAIR_FOR_LOCAL_CONNECTION
// Our process spawned correctly, we can now set our connection to use
// our end of the socket pair
- cleanup_our.disable();
+ cleanup_our.release();
m_gdb_comm.SetConnection(new ConnectionFileDescriptor(our_socket, true));
#endif
StartAsyncThread();
@@ -3586,9 +3512,8 @@ Status ProcessGDBRemote::LaunchAndConnectToDebugserver(
if (error.Fail()) {
Log *log(ProcessGDBRemoteLog::GetLogIfAllCategoriesSet(GDBR_LOG_PROCESS));
- if (log)
- log->Printf("failed to start debugserver process: %s",
- error.AsCString());
+ LLDB_LOGF(log, "failed to start debugserver process: %s",
+ error.AsCString());
return error;
}
@@ -3614,22 +3539,22 @@ bool ProcessGDBRemote::MonitorDebugserverProcess(
Log *log(ProcessGDBRemoteLog::GetLogIfAllCategoriesSet(GDBR_LOG_PROCESS));
const bool handled = true;
- if (log)
- log->Printf("ProcessGDBRemote::%s(process_wp, pid=%" PRIu64
- ", signo=%i (0x%x), exit_status=%i)",
- __FUNCTION__, debugserver_pid, signo, signo, exit_status);
+ LLDB_LOGF(log,
+ "ProcessGDBRemote::%s(process_wp, pid=%" PRIu64
+ ", signo=%i (0x%x), exit_status=%i)",
+ __FUNCTION__, debugserver_pid, signo, signo, exit_status);
std::shared_ptr<ProcessGDBRemote> process_sp = process_wp.lock();
- if (log)
- log->Printf("ProcessGDBRemote::%s(process = %p)", __FUNCTION__,
- static_cast<void *>(process_sp.get()));
+ LLDB_LOGF(log, "ProcessGDBRemote::%s(process = %p)", __FUNCTION__,
+ static_cast<void *>(process_sp.get()));
if (!process_sp || process_sp->m_debugserver_pid != debugserver_pid)
return handled;
// Sleep for a half a second to make sure our inferior process has time to
// set its exit status before we set it incorrectly when both the debugserver
// and the inferior process shut down.
- usleep(500000);
+ std::this_thread::sleep_for(std::chrono::milliseconds(500));
+
// If our process hasn't yet exited, debugserver might have died. If the
// process did exit, then we are reaping it.
const StateType state = process_sp->GetState();
@@ -3692,8 +3617,7 @@ void ProcessGDBRemote::DebuggerInitialize(Debugger &debugger) {
bool ProcessGDBRemote::StartAsyncThread() {
Log *log(ProcessGDBRemoteLog::GetLogIfAllCategoriesSet(GDBR_LOG_PROCESS));
- if (log)
- log->Printf("ProcessGDBRemote::%s ()", __FUNCTION__);
+ LLDB_LOGF(log, "ProcessGDBRemote::%s ()", __FUNCTION__);
std::lock_guard<std::recursive_mutex> guard(m_async_thread_state_mutex);
if (!m_async_thread.IsJoinable()) {
@@ -3709,10 +3633,11 @@ bool ProcessGDBRemote::StartAsyncThread() {
return false;
}
m_async_thread = *async_thread;
- } else if (log)
- log->Printf("ProcessGDBRemote::%s () - Called when Async thread was "
- "already running.",
- __FUNCTION__);
+ } else
+ LLDB_LOGF(log,
+ "ProcessGDBRemote::%s () - Called when Async thread was "
+ "already running.",
+ __FUNCTION__);
return m_async_thread.IsJoinable();
}
@@ -3720,8 +3645,7 @@ bool ProcessGDBRemote::StartAsyncThread() {
void ProcessGDBRemote::StopAsyncThread() {
Log *log(ProcessGDBRemoteLog::GetLogIfAllCategoriesSet(GDBR_LOG_PROCESS));
- if (log)
- log->Printf("ProcessGDBRemote::%s ()", __FUNCTION__);
+ LLDB_LOGF(log, "ProcessGDBRemote::%s ()", __FUNCTION__);
std::lock_guard<std::recursive_mutex> guard(m_async_thread_state_mutex);
if (m_async_thread.IsJoinable()) {
@@ -3733,8 +3657,9 @@ void ProcessGDBRemote::StopAsyncThread() {
// Stop the stdio thread
m_async_thread.Join(nullptr);
m_async_thread.Reset();
- } else if (log)
- log->Printf(
+ } else
+ LLDB_LOGF(
+ log,
"ProcessGDBRemote::%s () - Called when Async thread was not running.",
__FUNCTION__);
}
@@ -3768,25 +3693,25 @@ thread_result_t ProcessGDBRemote::AsyncThread(void *arg) {
ProcessGDBRemote *process = (ProcessGDBRemote *)arg;
Log *log(ProcessGDBRemoteLog::GetLogIfAllCategoriesSet(GDBR_LOG_PROCESS));
- if (log)
- log->Printf("ProcessGDBRemote::%s (arg = %p, pid = %" PRIu64
- ") thread starting...",
- __FUNCTION__, arg, process->GetID());
+ LLDB_LOGF(log,
+ "ProcessGDBRemote::%s (arg = %p, pid = %" PRIu64
+ ") thread starting...",
+ __FUNCTION__, arg, process->GetID());
EventSP event_sp;
bool done = false;
while (!done) {
- if (log)
- log->Printf("ProcessGDBRemote::%s (arg = %p, pid = %" PRIu64
- ") listener.WaitForEvent (NULL, event_sp)...",
- __FUNCTION__, arg, process->GetID());
+ LLDB_LOGF(log,
+ "ProcessGDBRemote::%s (arg = %p, pid = %" PRIu64
+ ") listener.WaitForEvent (NULL, event_sp)...",
+ __FUNCTION__, arg, process->GetID());
if (process->m_async_listener_sp->GetEvent(event_sp, llvm::None)) {
const uint32_t event_type = event_sp->GetType();
if (event_sp->BroadcasterIs(&process->m_async_broadcaster)) {
- if (log)
- log->Printf("ProcessGDBRemote::%s (arg = %p, pid = %" PRIu64
- ") Got an event of type: %d...",
- __FUNCTION__, arg, process->GetID(), event_type);
+ LLDB_LOGF(log,
+ "ProcessGDBRemote::%s (arg = %p, pid = %" PRIu64
+ ") Got an event of type: %d...",
+ __FUNCTION__, arg, process->GetID(), event_type);
switch (event_type) {
case eBroadcastBitAsyncContinue: {
@@ -3797,10 +3722,10 @@ thread_result_t ProcessGDBRemote::AsyncThread(void *arg) {
const char *continue_cstr =
(const char *)continue_packet->GetBytes();
const size_t continue_cstr_len = continue_packet->GetByteSize();
- if (log)
- log->Printf("ProcessGDBRemote::%s (arg = %p, pid = %" PRIu64
- ") got eBroadcastBitAsyncContinue: %s",
- __FUNCTION__, arg, process->GetID(), continue_cstr);
+ LLDB_LOGF(log,
+ "ProcessGDBRemote::%s (arg = %p, pid = %" PRIu64
+ ") got eBroadcastBitAsyncContinue: %s",
+ __FUNCTION__, arg, process->GetID(), continue_cstr);
if (::strstr(continue_cstr, "vAttach") == nullptr)
process->SetPrivateState(eStateRunning);
@@ -3891,18 +3816,18 @@ thread_result_t ProcessGDBRemote::AsyncThread(void *arg) {
break;
case eBroadcastBitAsyncThreadShouldExit:
- if (log)
- log->Printf("ProcessGDBRemote::%s (arg = %p, pid = %" PRIu64
- ") got eBroadcastBitAsyncThreadShouldExit...",
- __FUNCTION__, arg, process->GetID());
+ LLDB_LOGF(log,
+ "ProcessGDBRemote::%s (arg = %p, pid = %" PRIu64
+ ") got eBroadcastBitAsyncThreadShouldExit...",
+ __FUNCTION__, arg, process->GetID());
done = true;
break;
default:
- if (log)
- log->Printf("ProcessGDBRemote::%s (arg = %p, pid = %" PRIu64
- ") got unknown event 0x%8.8x",
- __FUNCTION__, arg, process->GetID(), event_type);
+ LLDB_LOGF(log,
+ "ProcessGDBRemote::%s (arg = %p, pid = %" PRIu64
+ ") got unknown event 0x%8.8x",
+ __FUNCTION__, arg, process->GetID(), event_type);
done = true;
break;
}
@@ -3925,27 +3850,27 @@ thread_result_t ProcessGDBRemote::AsyncThread(void *arg) {
}
default:
- if (log)
- log->Printf("ProcessGDBRemote::%s (arg = %p, pid = %" PRIu64
- ") got unknown event 0x%8.8x",
- __FUNCTION__, arg, process->GetID(), event_type);
+ LLDB_LOGF(log,
+ "ProcessGDBRemote::%s (arg = %p, pid = %" PRIu64
+ ") got unknown event 0x%8.8x",
+ __FUNCTION__, arg, process->GetID(), event_type);
done = true;
break;
}
}
} else {
- if (log)
- log->Printf("ProcessGDBRemote::%s (arg = %p, pid = %" PRIu64
- ") listener.WaitForEvent (NULL, event_sp) => false",
- __FUNCTION__, arg, process->GetID());
+ LLDB_LOGF(log,
+ "ProcessGDBRemote::%s (arg = %p, pid = %" PRIu64
+ ") listener.WaitForEvent (NULL, event_sp) => false",
+ __FUNCTION__, arg, process->GetID());
done = true;
}
}
- if (log)
- log->Printf("ProcessGDBRemote::%s (arg = %p, pid = %" PRIu64
- ") thread exiting...",
- __FUNCTION__, arg, process->GetID());
+ LLDB_LOGF(log,
+ "ProcessGDBRemote::%s (arg = %p, pid = %" PRIu64
+ ") thread exiting...",
+ __FUNCTION__, arg, process->GetID());
return {};
}
@@ -3977,8 +3902,7 @@ bool ProcessGDBRemote::NewThreadNotifyBreakpointHit(
// thread when it starts to
// run so I can stop it if that's what I want to do.
Log *log(GetLogIfAllCategoriesSet(LIBLLDB_LOG_STEP));
- if (log)
- log->Printf("Hit New Thread Notification breakpoint.");
+ LLDB_LOGF(log, "Hit New Thread Notification breakpoint.");
return false;
}
@@ -4023,7 +3947,7 @@ bool ProcessGDBRemote::StartNoticingNewThreads() {
Log *log(GetLogIfAllCategoriesSet(LIBLLDB_LOG_STEP));
if (m_thread_create_bp_sp) {
if (log && log->GetVerbose())
- log->Printf("Enabled noticing new thread breakpoint.");
+ LLDB_LOGF(log, "Enabled noticing new thread breakpoint.");
m_thread_create_bp_sp->SetEnabled(true);
} else {
PlatformSP platform_sp(GetTarget().GetPlatform());
@@ -4032,14 +3956,13 @@ bool ProcessGDBRemote::StartNoticingNewThreads() {
platform_sp->SetThreadCreationBreakpoint(GetTarget());
if (m_thread_create_bp_sp) {
if (log && log->GetVerbose())
- log->Printf(
- "Successfully created new thread notification breakpoint %i",
+ LLDB_LOGF(
+ log, "Successfully created new thread notification breakpoint %i",
m_thread_create_bp_sp->GetID());
m_thread_create_bp_sp->SetCallback(
ProcessGDBRemote::NewThreadNotifyBreakpointHit, this, true);
} else {
- if (log)
- log->Printf("Failed to create new thread notification breakpoint.");
+ LLDB_LOGF(log, "Failed to create new thread notification breakpoint.");
}
}
}
@@ -4049,7 +3972,7 @@ bool ProcessGDBRemote::StartNoticingNewThreads() {
bool ProcessGDBRemote::StopNoticingNewThreads() {
Log *log(GetLogIfAllCategoriesSet(LIBLLDB_LOG_STEP));
if (log && log->GetVerbose())
- log->Printf("Disabling new thread notification breakpoint.");
+ LLDB_LOGF(log, "Disabling new thread notification breakpoint.");
if (m_thread_create_bp_sp)
m_thread_create_bp_sp->SetEnabled(false);
@@ -4325,19 +4248,18 @@ bool ProcessGDBRemote::GetModuleSpec(const FileSpec &module_file_spec,
}
if (!m_gdb_comm.GetModuleInfo(module_file_spec, arch, module_spec)) {
- if (log)
- log->Printf("ProcessGDBRemote::%s - failed to get module info for %s:%s",
- __FUNCTION__, module_file_spec.GetPath().c_str(),
- arch.GetTriple().getTriple().c_str());
+ LLDB_LOGF(log, "ProcessGDBRemote::%s - failed to get module info for %s:%s",
+ __FUNCTION__, module_file_spec.GetPath().c_str(),
+ arch.GetTriple().getTriple().c_str());
return false;
}
if (log) {
StreamString stream;
module_spec.Dump(stream);
- log->Printf("ProcessGDBRemote::%s - got module info for (%s:%s) : %s",
- __FUNCTION__, module_file_spec.GetPath().c_str(),
- arch.GetTriple().getTriple().c_str(), stream.GetData());
+ LLDB_LOGF(log, "ProcessGDBRemote::%s - got module info for (%s:%s) : %s",
+ __FUNCTION__, module_file_spec.GetPath().c_str(),
+ arch.GetTriple().getTriple().c_str(), stream.GetData());
}
m_cached_module_specs[key] = module_spec;
@@ -4361,6 +4283,10 @@ llvm::VersionTuple ProcessGDBRemote::GetHostOSVersion() {
return m_gdb_comm.GetOSVersion();
}
+llvm::VersionTuple ProcessGDBRemote::GetHostMacCatalystVersion() {
+ return m_gdb_comm.GetMacCatalystVersion();
+}
+
namespace {
typedef std::vector<std::string> stringVec;
@@ -4492,14 +4418,13 @@ bool ParseRegisters(XMLNode feature_node, GdbServerTargetInfo &target_info,
} else if (name == "invalidate_regnums") {
SplitCommaSeparatedRegisterNumberString(value, invalidate_regs, 0);
} else if (name == "dynamic_size_dwarf_expr_bytes") {
- StringExtractor opcode_extractor;
std::string opcode_string = value.str();
size_t dwarf_opcode_len = opcode_string.length() / 2;
assert(dwarf_opcode_len > 0);
dwarf_opcode_bytes.resize(dwarf_opcode_len);
reg_info.dynamic_size_dwarf_len = dwarf_opcode_len;
- opcode_extractor.GetStringRef().swap(opcode_string);
+ StringExtractor opcode_extractor(opcode_string);
uint32_t ret_val =
opcode_extractor.GetHexBytesAvail(dwarf_opcode_bytes);
assert(dwarf_opcode_len == ret_val);
@@ -4565,16 +4490,15 @@ bool ParseRegisters(XMLNode feature_node, GdbServerTargetInfo &target_info,
// information to the current process. It will call itself recursively
// for nested register definition files. It returns true if it was able
// to fetch and parse an xml file.
-bool ProcessGDBRemote::GetGDBServerRegisterInfoXMLAndProcess(ArchSpec &arch_to_use,
- std::string xml_filename,
- uint32_t &cur_reg_num,
- uint32_t &reg_offset) {
+bool ProcessGDBRemote::GetGDBServerRegisterInfoXMLAndProcess(
+ ArchSpec &arch_to_use, std::string xml_filename, uint32_t &cur_reg_num,
+ uint32_t &reg_offset) {
// request the target xml file
std::string raw;
lldb_private::Status lldberr;
- if (!m_gdb_comm.ReadExtFeature(ConstString("features"),
- ConstString(xml_filename.c_str()),
- raw, lldberr)) {
+ if (!m_gdb_comm.ReadExtFeature(ConstString("features"),
+ ConstString(xml_filename.c_str()), raw,
+ lldberr)) {
return false;
}
@@ -4676,8 +4600,8 @@ bool ProcessGDBRemote::GetGDBServerRegisterInfoXMLAndProcess(ArchSpec &arch_to_u
}
for (const auto &include : target_info.includes) {
- GetGDBServerRegisterInfoXMLAndProcess(arch_to_use, include,
- cur_reg_num, reg_offset);
+ GetGDBServerRegisterInfoXMLAndProcess(arch_to_use, include, cur_reg_num,
+ reg_offset);
}
}
} else {
@@ -4705,41 +4629,43 @@ bool ProcessGDBRemote::GetGDBServerRegisterInfo(ArchSpec &arch_to_use) {
return m_register_info.GetNumRegisters() > 0;
}
-Status ProcessGDBRemote::GetLoadedModuleList(LoadedModuleInfoList &list) {
+llvm::Expected<LoadedModuleInfoList> ProcessGDBRemote::GetLoadedModuleList() {
// Make sure LLDB has an XML parser it can use first
if (!XMLDocument::XMLEnabled())
- return Status(0, ErrorType::eErrorTypeGeneric);
+ return llvm::createStringError(llvm::inconvertibleErrorCode(),
+ "XML parsing not available");
Log *log = GetLogIfAnyCategoriesSet(LIBLLDB_LOG_PROCESS);
- if (log)
- log->Printf("ProcessGDBRemote::%s", __FUNCTION__);
+ LLDB_LOGF(log, "ProcessGDBRemote::%s", __FUNCTION__);
+ LoadedModuleInfoList list;
GDBRemoteCommunicationClient &comm = m_gdb_comm;
bool can_use_svr4 = GetGlobalPluginProperties()->GetUseSVR4();
// check that we have extended feature read support
if (can_use_svr4 && comm.GetQXferLibrariesSVR4ReadSupported()) {
- list.clear();
-
// request the loaded library list
std::string raw;
lldb_private::Status lldberr;
if (!comm.ReadExtFeature(ConstString("libraries-svr4"), ConstString(""),
raw, lldberr))
- return Status(0, ErrorType::eErrorTypeGeneric);
+ return llvm::createStringError(llvm::inconvertibleErrorCode(),
+ "Error in libraries-svr4 packet");
// parse the xml file in memory
- if (log)
- log->Printf("parsing: %s", raw.c_str());
+ LLDB_LOGF(log, "parsing: %s", raw.c_str());
XMLDocument doc;
if (!doc.ParseMemory(raw.c_str(), raw.size(), "noname.xml"))
- return Status(0, ErrorType::eErrorTypeGeneric);
+ return llvm::createStringError(llvm::inconvertibleErrorCode(),
+ "Error reading noname.xml");
XMLNode root_element = doc.GetRootElement("library-list-svr4");
if (!root_element)
- return Status();
+ return llvm::createStringError(
+ llvm::inconvertibleErrorCode(),
+ "Error finding library-list-svr4 xml element");
// main link map structure
llvm::StringRef main_lm = root_element.GetAttributeValue("main-lm");
@@ -4791,10 +4717,11 @@ Status ProcessGDBRemote::GetLoadedModuleList(LoadedModuleInfoList &list) {
module.get_base_is_offset(base_is_offset);
module.get_dynamic(ld);
- log->Printf("found (link_map:0x%08" PRIx64 ", base:0x%08" PRIx64
- "[%s], ld:0x%08" PRIx64 ", name:'%s')",
- lm, base, (base_is_offset ? "offset" : "absolute"), ld,
- name.c_str());
+ LLDB_LOGF(log,
+ "found (link_map:0x%08" PRIx64 ", base:0x%08" PRIx64
+ "[%s], ld:0x%08" PRIx64 ", name:'%s')",
+ lm, base, (base_is_offset ? "offset" : "absolute"), ld,
+ name.c_str());
}
list.add(module);
@@ -4803,29 +4730,30 @@ Status ProcessGDBRemote::GetLoadedModuleList(LoadedModuleInfoList &list) {
});
if (log)
- log->Printf("found %" PRId32 " modules in total",
- (int)list.m_list.size());
+ LLDB_LOGF(log, "found %" PRId32 " modules in total",
+ (int)list.m_list.size());
+ return list;
} else if (comm.GetQXferLibrariesReadSupported()) {
- list.clear();
-
// request the loaded library list
std::string raw;
lldb_private::Status lldberr;
if (!comm.ReadExtFeature(ConstString("libraries"), ConstString(""), raw,
lldberr))
- return Status(0, ErrorType::eErrorTypeGeneric);
+ return llvm::createStringError(llvm::inconvertibleErrorCode(),
+ "Error in libraries packet");
- if (log)
- log->Printf("parsing: %s", raw.c_str());
+ LLDB_LOGF(log, "parsing: %s", raw.c_str());
XMLDocument doc;
if (!doc.ParseMemory(raw.c_str(), raw.size(), "noname.xml"))
- return Status(0, ErrorType::eErrorTypeGeneric);
+ return llvm::createStringError(llvm::inconvertibleErrorCode(),
+ "Error reading noname.xml");
XMLNode root_element = doc.GetRootElement("library-list");
if (!root_element)
- return Status();
+ return llvm::createStringError(llvm::inconvertibleErrorCode(),
+ "Error finding library-list xml element");
root_element.ForEachChildElementWithName(
"library", [log, &list](const XMLNode &library) -> bool {
@@ -4853,8 +4781,8 @@ Status ProcessGDBRemote::GetLoadedModuleList(LoadedModuleInfoList &list) {
module.get_base(base);
module.get_base_is_offset(base_is_offset);
- log->Printf("found (base:0x%08" PRIx64 "[%s], name:'%s')", base,
- (base_is_offset ? "offset" : "absolute"), name.c_str());
+ LLDB_LOGF(log, "found (base:0x%08" PRIx64 "[%s], name:'%s')", base,
+ (base_is_offset ? "offset" : "absolute"), name.c_str());
}
list.add(module);
@@ -4863,13 +4791,13 @@ Status ProcessGDBRemote::GetLoadedModuleList(LoadedModuleInfoList &list) {
});
if (log)
- log->Printf("found %" PRId32 " modules in total",
- (int)list.m_list.size());
+ LLDB_LOGF(log, "found %" PRId32 " modules in total",
+ (int)list.m_list.size());
+ return list;
} else {
- return Status(0, ErrorType::eErrorTypeGeneric);
+ return llvm::createStringError(llvm::inconvertibleErrorCode(),
+ "Remote libraries not supported");
}
-
- return Status();
}
lldb::ModuleSP ProcessGDBRemote::LoadModuleAtAddress(const FileSpec &file,
@@ -4884,17 +4812,18 @@ lldb::ModuleSP ProcessGDBRemote::LoadModuleAtAddress(const FileSpec &file,
value_is_offset);
}
-size_t ProcessGDBRemote::LoadModules(LoadedModuleInfoList &module_list) {
+llvm::Error ProcessGDBRemote::LoadModules() {
using lldb_private::process_gdb_remote::ProcessGDBRemote;
// request a list of loaded libraries from GDBServer
- if (GetLoadedModuleList(module_list).Fail())
- return 0;
+ llvm::Expected<LoadedModuleInfoList> module_list = GetLoadedModuleList();
+ if (!module_list)
+ return module_list.takeError();
// get a list of all the modules
ModuleList new_modules;
- for (LoadedModuleInfoList::LoadedModuleInfo &modInfo : module_list.m_list) {
+ for (LoadedModuleInfoList::LoadedModuleInfo &modInfo : module_list->m_list) {
std::string mod_name;
lldb::addr_t mod_base;
lldb::addr_t link_map;
@@ -4961,12 +4890,7 @@ size_t ProcessGDBRemote::LoadModules(LoadedModuleInfoList &module_list) {
m_process->GetTarget().ModulesDidLoad(new_modules);
}
- return new_modules.GetSize();
-}
-
-size_t ProcessGDBRemote::LoadModules() {
- LoadedModuleInfoList module_list;
- return LoadModules(module_list);
+ return llvm::ErrorSuccess();
}
Status ProcessGDBRemote::GetFileLoadAddress(const FileSpec &file,
@@ -5149,7 +5073,8 @@ ParseStructuredDataPacket(llvm::StringRef packet) {
if (!packet.consume_front(s_async_json_packet_prefix)) {
if (log) {
- log->Printf(
+ LLDB_LOGF(
+ log,
"GDBRemoteCommunicationClientBase::%s() received $J packet "
"but was not a StructuredData packet: packet starts with "
"%s",
@@ -5164,16 +5089,18 @@ ParseStructuredDataPacket(llvm::StringRef packet) {
if (log) {
if (json_sp) {
StreamString json_str;
- json_sp->Dump(json_str);
+ json_sp->Dump(json_str, true);
json_str.Flush();
- log->Printf("ProcessGDBRemote::%s() "
- "received Async StructuredData packet: %s",
- __FUNCTION__, json_str.GetData());
+ LLDB_LOGF(log,
+ "ProcessGDBRemote::%s() "
+ "received Async StructuredData packet: %s",
+ __FUNCTION__, json_str.GetData());
} else {
- log->Printf("ProcessGDBRemote::%s"
- "() received StructuredData packet:"
- " parse failure",
- __FUNCTION__);
+ LLDB_LOGF(log,
+ "ProcessGDBRemote::%s"
+ "() received StructuredData packet:"
+ " parse failure",
+ __FUNCTION__);
}
}
return json_sp;
@@ -5365,7 +5292,7 @@ public:
result.SetStatus(eReturnStatusSuccessFinishResult);
Stream &output_strm = result.GetOutputStream();
output_strm.Printf(" packet: %s\n", packet_cstr);
- std::string &response_str = response.GetStringRef();
+ std::string response_str = response.GetStringRef();
if (strstr(packet_cstr, "qGetProfileData") != nullptr) {
response_str = process->HarmonizeThreadIdsForProfileData(response);
@@ -5374,7 +5301,7 @@ public:
if (response_str.empty())
output_strm.PutCString("response: \nerror: UNIMPLEMENTED\n");
else
- output_strm.Printf("response: %s\n", response.GetStringRef().c_str());
+ output_strm.Printf("response: %s\n", response.GetStringRef().data());
}
}
return true;
@@ -5423,7 +5350,7 @@ public:
if (response_str.empty())
output_strm.PutCString("response: \nerror: UNIMPLEMENTED\n");
else
- output_strm.Printf("response: %s\n", response.GetStringRef().c_str());
+ output_strm.Printf("response: %s\n", response.GetStringRef().data());
}
return true;
}
diff --git a/source/Plugins/Process/gdb-remote/ProcessGDBRemote.h b/source/Plugins/Process/gdb-remote/ProcessGDBRemote.h
index 9c41fc2e5e98..0e3e3b39d9c8 100644
--- a/source/Plugins/Process/gdb-remote/ProcessGDBRemote.h
+++ b/source/Plugins/Process/gdb-remote/ProcessGDBRemote.h
@@ -24,8 +24,8 @@
#include "lldb/Utility/ArchSpec.h"
#include "lldb/Utility/Broadcaster.h"
#include "lldb/Utility/ConstString.h"
+#include "lldb/Utility/GDBRemote.h"
#include "lldb/Utility/Status.h"
-#include "lldb/Utility/StreamGDBRemote.h"
#include "lldb/Utility/StreamString.h"
#include "lldb/Utility/StringExtractor.h"
#include "lldb/Utility/StringList.h"
@@ -199,10 +199,11 @@ public:
const llvm::Triple &triple) override;
llvm::VersionTuple GetHostOSVersion() override;
+ llvm::VersionTuple GetHostMacCatalystVersion() override;
- size_t LoadModules(LoadedModuleInfoList &module_list) override;
+ llvm::Error LoadModules() override;
- size_t LoadModules() override;
+ llvm::Expected<LoadedModuleInfoList> GetLoadedModuleList() override;
Status GetFileLoadAddress(const FileSpec &file, bool &is_loaded,
lldb::addr_t &load_addr) override;
@@ -391,9 +392,6 @@ protected:
// Query remote GDBServer for register information
bool GetGDBServerRegisterInfo(ArchSpec &arch);
- // Query remote GDBServer for a detailed loaded library list
- Status GetLoadedModuleList(LoadedModuleInfoList &);
-
lldb::ModuleSP LoadModuleAtAddress(const FileSpec &file,
lldb::addr_t link_map,
lldb::addr_t base_addr,
diff --git a/source/Plugins/Process/gdb-remote/ProcessGDBRemoteProperties.td b/source/Plugins/Process/gdb-remote/ProcessGDBRemoteProperties.td
new file mode 100644
index 000000000000..16e7723e3061
--- /dev/null
+++ b/source/Plugins/Process/gdb-remote/ProcessGDBRemoteProperties.td
@@ -0,0 +1,16 @@
+include "../../../../include/lldb/Core/PropertiesBase.td"
+
+let Definition = "processgdbremote" in {
+ def PacketTimeout: Property<"packet-timeout", "UInt64">,
+ Global,
+ DefaultUnsignedValue<5>,
+ Desc<"Specify the default packet timeout in seconds.">;
+ def TargetDefinitionFile: Property<"target-definition-file", "FileSpec">,
+ Global,
+ DefaultStringValue<"">,
+ Desc<"The file that provides the description for remote target registers.">;
+ def UseSVR4: Property<"use-libraries-svr4", "Boolean">,
+ Global,
+ DefaultFalse,
+ Desc<"If true, the libraries-svr4 feature will be used to get a hold of the process's loaded modules.">;
+}
diff --git a/source/Plugins/Process/gdb-remote/ThreadGDBRemote.cpp b/source/Plugins/Process/gdb-remote/ThreadGDBRemote.cpp
index 6607bce4488b..8a6a58c55450 100644
--- a/source/Plugins/Process/gdb-remote/ThreadGDBRemote.cpp
+++ b/source/Plugins/Process/gdb-remote/ThreadGDBRemote.cpp
@@ -215,8 +215,7 @@ StructuredData::ObjectSP ThreadGDBRemote::FetchThreadExtendedInfo() {
StructuredData::ObjectSP object_sp;
const lldb::user_id_t tid = GetProtocolID();
Log *log(GetLogIfAnyCategoriesSet(GDBR_LOG_THREAD));
- if (log)
- log->Printf("Fetching extended information for thread %4.4" PRIx64, tid);
+ LLDB_LOGF(log, "Fetching extended information for thread %4.4" PRIx64, tid);
ProcessSP process_sp(GetProcess());
if (process_sp) {
ProcessGDBRemote *gdb_process =
@@ -230,9 +229,8 @@ void ThreadGDBRemote::WillResume(StateType resume_state) {
int signo = GetResumeSignal();
const lldb::user_id_t tid = GetProtocolID();
Log *log(GetLogIfAnyCategoriesSet(GDBR_LOG_THREAD));
- if (log)
- log->Printf("Resuming thread: %4.4" PRIx64 " with state: %s.", tid,
- StateAsCString(resume_state));
+ LLDB_LOGF(log, "Resuming thread: %4.4" PRIx64 " with state: %s.", tid,
+ StateAsCString(resume_state));
ProcessSP process_sp(GetProcess());
if (process_sp) {