[lldb] Convert Process KDP Log to the new API

This commit is contained in:
Pavel Labath 2022-01-31 08:22:31 +01:00
parent 081cff628a
commit c8fbf8037d
4 changed files with 15 additions and 30 deletions

View File

@ -65,7 +65,7 @@ bool CommunicationKDP::SendRequestAndGetReply(
const CommandType command, const PacketStreamType &request_packet,
DataExtractor &reply_packet) {
if (IsRunning()) {
Log *log(ProcessKDPLog::GetLogIfAllCategoriesSet(KDP_LOG_PACKETS));
Log *log = GetLog(KDPLog::Packets);
if (log) {
PacketStreamType log_strm;
DumpPacket(log_strm, request_packet.GetData(), request_packet.GetSize());
@ -133,7 +133,7 @@ bool CommunicationKDP::SendRequestPacketNoLock(
const char *packet_data = request_packet.GetData();
const size_t packet_size = request_packet.GetSize();
Log *log(ProcessKDPLog::GetLogIfAllCategoriesSet(KDP_LOG_PACKETS));
Log *log = GetLog(KDPLog::Packets);
if (log) {
PacketStreamType log_strm;
DumpPacket(log_strm, packet_data, packet_size);
@ -178,7 +178,7 @@ size_t CommunicationKDP::WaitForPacketWithTimeoutMicroSecondsNoLock(
uint8_t buffer[8192];
Status error;
Log *log(ProcessKDPLog::GetLogIfAllCategoriesSet(KDP_LOG_PACKETS));
Log *log = GetLog(KDPLog::Packets);
// Check for a packet from our cache first without trying any reading...
if (CheckForPacket(NULL, 0, packet))
@ -231,7 +231,7 @@ bool CommunicationKDP::CheckForPacket(const uint8_t *src, size_t src_len,
// Put the packet data into the buffer in a thread safe fashion
std::lock_guard<std::recursive_mutex> guard(m_bytes_mutex);
Log *log(ProcessKDPLog::GetLogIfAllCategoriesSet(KDP_LOG_PACKETS));
Log *log = GetLog(KDPLog::Packets);
if (src && src_len > 0) {
if (log && log->GetVerbose()) {

View File

@ -381,7 +381,7 @@ ProcessKDP::DoAttachToProcessWithName(const char *process_name,
void ProcessKDP::DidAttach(ArchSpec &process_arch) {
Process::DidAttach(process_arch);
Log *log(ProcessKDPLog::GetLogIfAllCategoriesSet(KDP_LOG_PROCESS));
Log *log = GetLog(KDPLog::Process);
LLDB_LOGF(log, "ProcessKDP::DidAttach()");
if (GetID() != LLDB_INVALID_PROCESS_ID) {
GetHostArchitecture(process_arch);
@ -400,7 +400,7 @@ Status ProcessKDP::WillResume() { return Status(); }
Status ProcessKDP::DoResume() {
Status error;
Log *log(ProcessKDPLog::GetLogIfAllCategoriesSet(KDP_LOG_PROCESS));
Log *log = GetLog(KDPLog::Process);
// Only start the async thread if we try to do any process control
if (!m_async_thread.IsJoinable())
StartAsyncThread();
@ -492,7 +492,7 @@ lldb::ThreadSP ProcessKDP::GetKernelThread() {
bool ProcessKDP::DoUpdateThreadList(ThreadList &old_thread_list,
ThreadList &new_thread_list) {
// locker will keep a mutex locked until it goes out of scope
Log *log(ProcessKDPLog::GetLogIfAllCategoriesSet(KDP_LOG_THREAD));
Log *log = GetLog(KDPLog::Thread);
LLDB_LOGV(log, "pid = {0}", GetID());
// Even though there is a CPU mask, it doesn't mean we can see each CPU
@ -530,7 +530,7 @@ Status ProcessKDP::DoHalt(bool &caused_stop) {
Status ProcessKDP::DoDetach(bool keep_stopped) {
Status error;
Log *log(ProcessKDPLog::GetLogIfAllCategoriesSet(KDP_LOG_PROCESS));
Log *log = GetLog(KDPLog::Process);
LLDB_LOGF(log, "ProcessKDP::DoDetach(keep_stopped = %i)", keep_stopped);
if (m_comm.IsRunning()) {
@ -715,7 +715,7 @@ void ProcessKDP::DebuggerInitialize(lldb_private::Debugger &debugger) {
}
bool ProcessKDP::StartAsyncThread() {
Log *log(ProcessKDPLog::GetLogIfAllCategoriesSet(KDP_LOG_PROCESS));
Log *log = GetLog(KDPLog::Process);
LLDB_LOGF(log, "ProcessKDP::StartAsyncThread ()");
@ -725,9 +725,8 @@ bool ProcessKDP::StartAsyncThread() {
llvm::Expected<HostThread> async_thread = ThreadLauncher::LaunchThread(
"<lldb.process.kdp-remote.async>", ProcessKDP::AsyncThread, this);
if (!async_thread) {
LLDB_LOG(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_HOST),
"failed to launch host thread: {}",
llvm::toString(async_thread.takeError()));
LLDB_LOG_ERROR(GetLog(LLDBLog::Host), async_thread.takeError(),
"failed to launch host thread: {}");
return false;
}
m_async_thread = *async_thread;
@ -735,7 +734,7 @@ bool ProcessKDP::StartAsyncThread() {
}
void ProcessKDP::StopAsyncThread() {
Log *log(ProcessKDPLog::GetLogIfAllCategoriesSet(KDP_LOG_PROCESS));
Log *log = GetLog(KDPLog::Process);
LLDB_LOGF(log, "ProcessKDP::StopAsyncThread ()");
@ -751,7 +750,7 @@ void *ProcessKDP::AsyncThread(void *arg) {
const lldb::pid_t pid = process->GetID();
Log *log(ProcessKDPLog::GetLogIfAllCategoriesSet(KDP_LOG_PROCESS));
Log *log = GetLog(KDPLog::Process);
LLDB_LOGF(log,
"ProcessKDP::AsyncThread (arg = %p, pid = %" PRIu64
") thread starting...",

View File

@ -28,24 +28,10 @@ enum class KDPLog : Log::MaskType {
Watchpoints = Log::ChannelFlag<10>,
LLVM_MARK_AS_BITMASK_ENUM(Watchpoints)
};
#define KDP_LOG_PROCESS ::lldb_private::KDPLog::Process
#define KDP_LOG_THREAD ::lldb_private::KDPLog::Thread
#define KDP_LOG_PACKETS ::lldb_private::KDPLog::Packets
#define KDP_LOG_MEMORY ::lldb_private::KDPLog::Memory
#define KDP_LOG_MEMORY_DATA_SHORT ::lldb_private::KDPLog::MemoryDataShort
#define KDP_LOG_MEMORY_DATA_LONG ::lldb_private::KDPLog::MemoryDataLong
#define KDP_LOG_BREAKPOINTS ::lldb_private::KDPLog::Breakpoints
#define KDP_LOG_WATCHPOINTS ::lldb_private::KDPLog::Watchpoints
#define KDP_LOG_STEP ::lldb_private::KDPLog::Step
#define KDP_LOG_COMM ::lldb_private::KDPLog::Comm
#define KDP_LOG_ASYNC ::lldb_private::KDPLog::Async
#define KDP_LOG_DEFAULT KDP_LOG_PACKETS
class ProcessKDPLog {
public:
static void Initialize();
static Log *GetLogIfAllCategoriesSet(KDPLog mask) { return GetLog(mask); }
};
template <> Log::Channel &LogChannelFor<KDPLog>();

View File

@ -39,12 +39,12 @@ using namespace lldb_private;
ThreadKDP::ThreadKDP(Process &process, lldb::tid_t tid)
: Thread(process, tid), m_thread_name(), m_dispatch_queue_name(),
m_thread_dispatch_qaddr(LLDB_INVALID_ADDRESS) {
Log *log = ProcessKDPLog::GetLogIfAllCategoriesSet(KDP_LOG_THREAD);
Log *log = GetLog(KDPLog::Thread);
LLDB_LOG(log, "this = {0}, tid = {1:x}", this, GetID());
}
ThreadKDP::~ThreadKDP() {
Log *log = ProcessKDPLog::GetLogIfAllCategoriesSet(KDP_LOG_THREAD);
Log *log = GetLog(KDPLog::Thread);
LLDB_LOG(log, "this = {0}, tid = {1:x}", this, GetID());
DestroyThread();
}