Add the ability to disable individual log categories, rather

than just the entire log channel.

Add checks, where appropriate, to make sure a log channel/category has 
not been disabled before attempting to write to it.

llvm-svn: 117715
This commit is contained in:
Caroline Tice 2010-10-29 21:48:37 +00:00
parent 4a0c2d73c3
commit 20ad3c40f4
30 changed files with 264 additions and 48 deletions

View File

@ -59,7 +59,7 @@ public:
//------------------------------------------------------------------
// Callback definitions for abstracted plug-in log access.
//------------------------------------------------------------------
typedef void (*DisableCallback) ();
typedef void (*DisableCallback) (Args &args, Stream *feedback_strm);
typedef Log* (*EnableCallback) (lldb::StreamSP &log_stream_sp,
uint32_t log_options,
Args &args,
@ -95,7 +95,7 @@ public:
Stream *feedback_strm);
static void
DisableAllLogChannels ();
DisableAllLogChannels (Stream *feedback_strm);
static void
ListAllLogChannels (Stream *strm);
@ -194,7 +194,7 @@ public:
FindPlugin (const char *plugin_name);
virtual void
Disable () = 0;
Disable (Args &args, Stream *feedback_strm) = 0;
virtual bool
Enable (lldb::StreamSP &log_stream_sp,

View File

@ -69,7 +69,7 @@ bool
IsLogVerbose ();
void
DisableLog ();
DisableLog (Args &args, Stream *feedback_strm);
Log *
EnableLog (lldb::StreamSP &log_stream_sp, uint32_t log_options, Args &args, Stream *feedback_strm);

View File

@ -178,6 +178,7 @@ SBCommunication::ReadThreadStart ()
if (m_opaque)
success = m_opaque->StartReadThread ();
log = lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API);
if (log)
log->Printf ("SBCommunication::ReadThreadStart (this.obj=%p) => '%s'", m_opaque, (success ? "true" : "false"));
@ -188,7 +189,6 @@ SBCommunication::ReadThreadStart ()
bool
SBCommunication::ReadThreadStop ()
{
Log *log = lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API);
//if (log)
// log->Printf ("SBCommunication::ReadThreadStop ()");
@ -197,6 +197,7 @@ SBCommunication::ReadThreadStop ()
if (m_opaque)
success = m_opaque->StopReadThread ();
Log *log = lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API);
if (log)
log->Printf ("SBCommunication::ReadThreadStop (this.obj=%p) => '%s'", m_opaque, (success ? "true" : "false"));

View File

@ -93,6 +93,7 @@ SBListener::StartListeningForEvents (const SBBroadcaster& broadcaster, uint32_t
ret_value = m_opaque_ptr->StartListeningForEvents (broadcaster.get(), event_mask);
}
log = lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API);
if (log)
log->Printf ("SBListener(%p)::StartListeneingForEvents (SBBroadcaster(%p), event_mask=0x%8.8x) => %d",
m_opaque_ptr, broadcaster.get(), event_mask, ret_value);

View File

@ -385,7 +385,6 @@ SBProcess::WaitUntilProcessHasStopped (SBCommandReturnObject &result)
SBError
SBProcess::Continue ()
{
Log *log = lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API);
SBError sb_error;
if (IsValid())
@ -401,6 +400,7 @@ SBProcess::Continue ()
else
sb_error.SetErrorString ("SBProcess is invalid");
Log *log = lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API);
if (log)
{
SBStream sstr;
@ -428,7 +428,6 @@ SBProcess::Destroy ()
SBError
SBProcess::Stop ()
{
Log *log = lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API);
SBError sb_error;
if (IsValid())
@ -436,6 +435,7 @@ SBProcess::Stop ()
else
sb_error.SetErrorString ("SBProcess is invalid");
Log *log = lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API);
if (log)
{
SBStream sstr;
@ -452,7 +452,6 @@ SBProcess::Stop ()
SBError
SBProcess::Kill ()
{
Log *log = lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API);
SBError sb_error;
if (m_opaque_sp)
@ -460,6 +459,7 @@ SBProcess::Kill ()
else
sb_error.SetErrorString ("SBProcess is invalid");
Log *log = lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API);
if (log)
{
SBStream sstr;

View File

@ -115,12 +115,12 @@ SBTarget::IsValid () const
SBProcess
SBTarget::GetProcess ()
{
Log *log = lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API);
SBProcess sb_process;
if (m_opaque_sp)
sb_process.SetProcess (m_opaque_sp->GetProcessSP());
Log *log = lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API);
if (log)
{
SBStream sstr;
@ -146,13 +146,13 @@ SBTarget::GetDebugger () const
SBProcess
SBTarget::CreateProcess ()
{
Log *log = lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API);
SBProcess sb_process;
if (m_opaque_sp)
sb_process.SetProcess (m_opaque_sp->CreateProcess (m_opaque_sp->GetDebugger().GetListener()));
Log *log = lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API);
if (log)
{
SBStream sstr;
@ -184,6 +184,7 @@ SBTarget::LaunchProcess
SBError sb_error;
SBProcess sb_process = Launch (argv, envp, tty, launch_flags, stop_at_entry, sb_error);
log = lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API);
if (log)
{
SBStream sstr;
@ -263,6 +264,7 @@ SBTarget::Launch
error.SetErrorString ("SBTarget is invalid");
}
log = lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API);
if (log)
{
SBStream sstr;

View File

@ -469,7 +469,6 @@ SBThread::RunToAddress (lldb::addr_t addr)
SBProcess
SBThread::GetProcess ()
{
Log *log = lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API);
SBProcess process;
if (m_opaque_sp)
@ -478,6 +477,7 @@ SBThread::GetProcess ()
process.SetProcess(m_opaque_sp->GetProcess().GetTarget().GetProcessSP());
}
Log *log = lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API);
if (log)
{
SBStream sstr;

View File

@ -231,6 +231,7 @@ BreakpointLocation::ShouldStop (StoppointCallbackContext *context)
if (should_stop)
{
ThreadPlanSP condition_plan_sp(GetThreadPlanToTestCondition(context->exe_ctx, errors));
log = lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_BREAKPOINTS);
if (log && errors.GetSize() > 0)
{
log->Printf("Error evaluating condition: \"%s\".\n", errors.GetData());
@ -244,6 +245,7 @@ BreakpointLocation::ShouldStop (StoppointCallbackContext *context)
if (should_stop)
{
log = lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_BREAKPOINTS);
if (log)
{
StreamString s;

View File

@ -291,31 +291,29 @@ public:
}
else
{
for (size_t i=0; i<argc; ++i)
{
Log::Callbacks log_callbacks;
Log::Callbacks log_callbacks;
std::string channel(args.GetArgumentAtIndex(i));
if (Log::GetLogChannelCallbacks (channel.c_str(), log_callbacks))
std::string channel(args.GetArgumentAtIndex(0));
args.Shift (); // Shift off the channel
if (Log::GetLogChannelCallbacks (channel.c_str(), log_callbacks))
{
log_callbacks.disable (args, &result.GetErrorStream());
result.SetStatus(eReturnStatusSuccessFinishNoResult);
}
else if (channel == "all")
{
Log::DisableAllLogChannels(&result.GetErrorStream());
}
else
{
LogChannelSP log_channel_sp (GetLogChannelPluginForChannel(channel.c_str()));
if (log_channel_sp)
{
log_callbacks.disable ();
log_channel_sp->Disable(args, &result.GetErrorStream());
result.SetStatus(eReturnStatusSuccessFinishNoResult);
}
else if (channel == "all")
{
Log::DisableAllLogChannels();
}
else
{
LogChannelSP log_channel_sp (GetLogChannelPluginForChannel(channel.c_str()));
if (log_channel_sp)
{
log_channel_sp->Disable();
result.SetStatus(eReturnStatusSuccessFinishNoResult);
}
else
result.AppendErrorWithFormat("Invalid log channel '%s'.\n", args.GetArgumentAtIndex(0));
}
result.AppendErrorWithFormat("Invalid log channel '%s'.\n", args.GetArgumentAtIndex(0));
}
}
return result.Succeeded();

View File

@ -338,6 +338,7 @@ Communication::ReadThread (void *p)
break;
}
}
log = lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_COMMUNICATION);
if (log)
log->Printf ("%p Communication::ReadThread () thread exiting...", p);

View File

@ -388,12 +388,14 @@ Listener::WaitForEventsInternal
else if (timed_out)
{
log = lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_EVENTS);
if (log)
log->Printf ("%p Listener::WaitForEvents() timed out for %s", this, m_name.c_str());
break;
}
else
{
log = lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_EVENTS);
if (log)
log->Printf ("%p Listener::WaitForEvents() unknown error for %s", this, m_name.c_str());
break;

View File

@ -28,7 +28,7 @@
#include "lldb/Host/Host.h"
#include "lldb/Host/TimeValue.h"
#include "lldb/Host/Mutex.h"
#include "lldb/Interpreter/Args.h"
using namespace lldb;
using namespace lldb_private;
@ -384,18 +384,19 @@ Log::EnableAllLogChannels
}
void
Log::DisableAllLogChannels ()
Log::DisableAllLogChannels (Stream *feedback_strm)
{
CallbackMap &callback_map = GetCallbackMap ();
CallbackMapIter pos, end = callback_map.end();
Args args ("all");
for (pos = callback_map.begin(); pos != end; ++pos)
pos->second.disable ();
pos->second.disable (args, feedback_strm);
LogChannelMap &channel_map = GetChannelMap ();
LogChannelMapIter channel_pos, channel_end = channel_map.end();
for (channel_pos = channel_map.begin(); channel_pos != channel_end; ++channel_pos)
channel_pos->second->Disable ();
channel_pos->second->Disable (args, feedback_strm);
}
void

View File

@ -543,6 +543,7 @@ ClangFunction::ExecuteFunction (
// Right now this is the only way to tell we've timed out...
// We should interrupt the process here...
// Not really sure what to do if Halt fails here...
log = lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_STEP);
if (log)
if (try_all_threads)
log->Printf ("Running function with timeout: %d timed out, trying with all threads enabled.",
@ -609,6 +610,7 @@ ClangFunction::ExecuteFunction (
}
else
{
log = lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_STEP);
if (log)
{
StreamString s;
@ -675,7 +677,9 @@ ClangFunction::ExecuteFunction (
event_explanation = ts.GetData();
} while (0);
log->Printf("Execution interrupted: %s %s", s.GetData(), event_explanation);
log = lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_STEP);
if (log)
log->Printf("Execution interrupted: %s %s", s.GetData(), event_explanation);
}
return_value = eExecutionInterrupted;

View File

@ -122,6 +122,7 @@ MonitorChildProcessThreadFunction (void *arg)
struct rusage *rusage = NULL;
while (1)
{
log = lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_PROCESS);
if (log)
log->Printf("%s ::wait4 (pid = %i, &status, options = %i, rusage = %p)...", function, pid, options, rusage);
@ -170,6 +171,7 @@ MonitorChildProcessThreadFunction (void *arg)
{
ScopedPThreadCancelDisabler pthread_cancel_disabler;
log = lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_PROCESS);
if (log)
log->Printf ("%s ::wait4 (pid = %i, &status, options = %i, rusage = %p) => pid = %i, status = 0x%8.8x (%s), signal = %i, exit_state = %i",
function,
@ -198,6 +200,7 @@ MonitorChildProcessThreadFunction (void *arg)
}
}
log = lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_PROCESS);
if (log)
log->Printf ("%s (arg = %p) thread exiting...", __FUNCTION__, arg);

View File

@ -265,6 +265,7 @@ MachException::Message::Receive(mach_port_t port, mach_msg_option_t options, mac
notify_port);
// Dump any errors we get
log = ProcessMacOSXLog::GetLogIfAllCategoriesSet(PD_LOG_EXCEPTIONS);
if (log && err.GetError() != MACH_RCV_TIMED_OUT)
{
log->Error("::mach_msg ( msg->{bits = %#x, size = %u remote_port = %#x, local_port = %#x, reserved = 0x%x, id = 0x%x}, option = %#x, send_size = %u, rcv_size = %u, rcv_name = %#x, timeout = %u, notify = %#x)",

View File

@ -547,6 +547,7 @@ MachTask::ExceptionThread (void *arg)
if (err.GetError() == MACH_RCV_INTERRUPTED)
{
log = ProcessMacOSXLog::GetLogIfAllCategoriesSet (PD_LOG_EXCEPTIONS);
// If we have no task port we should exit this thread
if (!mach_task->ExceptionPortIsValid())
{
@ -576,6 +577,8 @@ MachTask::ExceptionThread (void *arg)
{
if (num_exceptions_received > 0)
{
log = ProcessMacOSXLog::GetLogIfAllCategoriesSet (PD_LOG_EXCEPTIONS);
// We were receiving all current exceptions with a timeout of zero
// it is time to go back to our normal looping mode
num_exceptions_received = 0;
@ -619,6 +622,7 @@ MachTask::ExceptionThread (void *arg)
}
else if (err.GetError() != KERN_SUCCESS)
{
log = ProcessMacOSXLog::GetLogIfAllCategoriesSet (PD_LOG_EXCEPTIONS);
if (log)
log->Printf ("got some other error, do something about it??? nah, continuing for now...");
// TODO: notify of error?
@ -645,6 +649,7 @@ MachTask::ExceptionThread (void *arg)
}
#endif // #if defined (__arm__)
log = ProcessMacOSXLog::GetLogIfAllCategoriesSet (PD_LOG_EXCEPTIONS);
if (log)
log->Printf ("MachTask::%s (arg = %p) thread exiting...", __FUNCTION__, arg);
return NULL;

View File

@ -742,6 +742,7 @@ ProcessMacOSX::DoSIGSTOP (bool clear_all_breakpoints)
if (!StateIsStoppedState (state))
{
log = ProcessMacOSXLog::GetLogIfAllCategoriesSet(PD_LOG_PROCESS);
if (log)
log->Printf("ProcessMacOSX::DoSIGSTOP() failed to stop after sending SIGSTOP");
return error;
@ -778,6 +779,7 @@ ProcessMacOSX::DoSIGSTOP (bool clear_all_breakpoints)
else
error.SetErrorToErrno();
log = ProcessMacOSXLog::GetLogIfAllCategoriesSet(PD_LOG_PROCESS);
if (log || error.Fail())
error.PutToLog(log, "ProcessMacOSX::DoSIGSTOP() ::kill (pid = %i, SIGSTOP)", pid);
@ -791,6 +793,7 @@ ProcessMacOSX::DoSIGSTOP (bool clear_all_breakpoints)
// Make sure the process resumed
if (StateIsStoppedState (state))
{
log = ProcessMacOSXLog::GetLogIfAllCategoriesSet(PD_LOG_PROCESS);
if (log)
log->Printf ("ProcessMacOSX::DoSIGSTOP() couldn't resume process, state = %s", StateAsCString(state));
error.SetErrorStringWithFormat("ProcessMacOSX::DoSIGSTOP() couldn't resume process, state = %s", StateAsCString(state));
@ -803,6 +806,7 @@ ProcessMacOSX::DoSIGSTOP (bool clear_all_breakpoints)
state = WaitForStateChangedEventsPrivate (&timeout_time, event_sp);
if (!StateIsStoppedState (state))
{
log = ProcessMacOSXLog::GetLogIfAllCategoriesSet(PD_LOG_PROCESS);
if (log)
log->Printf("ProcessMacOSX::DoSIGSTOP() failed to stop after sending SIGSTOP");
error.SetErrorString("ProcessMacOSX::DoSIGSTOP() failed to stop after sending SIGSTOP");
@ -1256,6 +1260,7 @@ ProcessMacOSX::STDIOThread(void *arg)
int nfds = std::max<int>(stdout_fd, stderr_fd) + 1;
int num_set_fds = select (nfds, &read_fds, NULL, NULL, NULL);
log = ProcessMacOSXLog::GetLogIfAllCategoriesSet (PD_LOG_PROCESS);
if (log)
log->Printf("select (nfds, &read_fds, NULL, NULL, NULL) => %d", num_set_fds);
@ -1343,6 +1348,7 @@ ProcessMacOSX::STDIOThread(void *arg)
}
}
log = ProcessMacOSXLog::GetLogIfAllCategoriesSet (PD_LOG_PROCESS);
if (log)
log->Printf("ProcessMacOSX::%s (%p): thread exiting...", __FUNCTION__, arg);
@ -1647,6 +1653,7 @@ ProcessMacOSX::LaunchForDebug
else
launch_err.SetErrorToErrno();
log = ProcessMacOSXLog::GetLogIfAllCategoriesSet (PD_LOG_PROCESS);
if (launch_err.Fail() || log)
launch_err.PutToLog(log, "::ptrace (PT_ATTACHEXC, pid = %i, 0, 0 )", pid);

View File

@ -35,7 +35,44 @@ ProcessMacOSXLog::GetLogIfAllCategoriesSet (uint32_t mask)
}
void
ProcessMacOSXLog::DisableLog ()
ProcessMacOSXLog::DisableLog (Args &args, Stream *feedback_strm)
{
if (g_log)
{
uint32_t flag_bits = g_log->GetMask().Get();
const size_t argc = args.GetArgumentCount ();
for (size_t i = 0; i < argc; ++i)
{
const char *arg = args.GetArgumentAtIndex (i);
if (::strcasecmp (arg, "all") == 0 ) flag_bits &= ~PD_LOG_ALL;
else if (::strcasestr (arg, "break") == arg ) flag_bits &= ~PD_LOG_BREAKPOINTS;
else if (::strcasecmp (arg, "default") == 0 ) flag_bits &= ~PD_LOG_DEFAULT;
else if (::strcasestr (arg, "exc") == arg ) flag_bits &= ~PD_LOG_EXCEPTIONS;
else if (::strcasecmp (arg, "memory") == 0 ) flag_bits &= ~PD_LOG_MEMORY;
else if (::strcasecmp (arg, "data-short") == 0 ) flag_bits &= ~PD_LOG_MEMORY_DATA_SHORT;
else if (::strcasecmp (arg, "data-long") == 0 ) flag_bits &= ~PD_LOG_MEMORY_DATA_LONG;
else if (::strcasecmp (arg, "protections")== 0 ) flag_bits &= ~PD_LOG_PROCESS;
else if (::strcasecmp (arg, "step") == 0 ) flag_bits &= ~PD_LOG_STEP;
else if (::strcasecmp (arg, "task") == 0 ) flag_bits &= ~PD_LOG_TASK;
else if (::strcasecmp (arg, "thread") == 0 ) flag_bits &= ~PD_LOG_THREAD;
else if (::strcasecmp (arg, "verbose") == 0 ) flag_bits &= ~PD_LOG_VERBOSE;
else if (::strcasestr (arg, "watch") == arg ) flag_bits &= ~PD_LOG_WATCHPOINTS;
else
{
feedback_strm->Printf("error: unrecognized log category '%s'\n", arg);
ListLogCategories (feedback_strm);
}
}
if (flag_bits == 0)
DeleteLog ();
else
g_log->GetMask().Reset (flag_bits);
}
}
void
ProcessMacOSXLog::DeleteLog ()
{
if (g_log)
{
@ -47,7 +84,7 @@ ProcessMacOSXLog::DisableLog ()
Log *
ProcessMacOSXLog::EnableLog (StreamSP &log_stream_sp, uint32_t log_options, Args &args, Stream *feedback_strm)
{
DisableLog ();
DeleteLog ();
g_log = new Log (log_stream_sp);
if (g_log)
{

View File

@ -47,7 +47,10 @@ public:
GetLogIfAllCategoriesSet(uint32_t mask = 0);
static void
DisableLog ();
DisableLog (lldb_private::Args &args, lldb_private::Stream *feedback_strm);
static void
DeleteLog ();
static lldb_private::Log *
EnableLog (lldb::StreamSP &log_stream_sp, uint32_t log_options, lldb_private::Args &args, lldb_private::Stream *feedback_strm);

View File

@ -257,6 +257,7 @@ ThreadMacOSX::Suspend()
Error err(::thread_suspend (tid), eErrorTypeMachKernel);
if (err.Success())
m_suspend_count++;
log = ProcessMacOSXLog::GetLogIfAllCategoriesSet(PD_LOG_THREAD);
if (log || err.Fail())
err.PutToLog(log, "::thread_suspend (%4.4x)", tid);
}
@ -277,6 +278,7 @@ ThreadMacOSX::Resume()
Error err(::thread_resume (tid), eErrorTypeMachKernel);
if (err.Success())
m_suspend_count--;
log = ProcessMacOSXLog::GetLogIfAllCategoriesSet(PD_LOG_THREAD);
if (log || err.Fail())
err.PutToLog(log, "::thread_resume (%4.4x)", tid);
}
@ -301,6 +303,7 @@ ThreadMacOSX::RestoreSuspendCount()
err = ::thread_resume (tid);
if (err.Success())
--m_suspend_count;
log = ProcessMacOSXLog::GetLogIfAllCategoriesSet(PD_LOG_THREAD);
if (log || err.Fail())
err.PutToLog(log, "::thread_resume (%4.4x)", tid);
}
@ -312,6 +315,7 @@ ThreadMacOSX::RestoreSuspendCount()
err = ::thread_suspend (tid);
if (err.Success())
--m_suspend_count;
log = ProcessMacOSXLog::GetLogIfAllCategoriesSet(PD_LOG_THREAD);
if (log || err.Fail())
err.PutToLog(log, "::thread_suspend (%4.4x)", tid);
}

View File

@ -209,11 +209,14 @@ GDBRemoteCommunication::SendContinuePacketAndWaitForResponse
while (state == eStateRunning)
{
log = ProcessGDBRemoteLog::GetLogIfAllCategoriesSet (GDBR_LOG_PROCESS);
if (log)
log->Printf ("GDBRemoteCommunication::%s () WaitForPacket(...)", __FUNCTION__);
if (WaitForPacket (response, (TimeValue*)NULL))
{
log = ProcessGDBRemoteLog::GetLogIfAllCategoriesSet (GDBR_LOG_PROCESS);
async_log = ProcessGDBRemoteLog::GetLogIfAllCategoriesSet (GDBR_LOG_ASYNC);
if (response.Empty())
state = eStateInvalid;
else
@ -344,11 +347,13 @@ GDBRemoteCommunication::SendContinuePacketAndWaitForResponse
}
else
{
log = ProcessGDBRemoteLog::GetLogIfAllCategoriesSet (GDBR_LOG_PROCESS);
if (log)
log->Printf ("GDBRemoteCommunication::%s () WaitForPacket(...) => false", __FUNCTION__);
state = eStateInvalid;
}
}
log = ProcessGDBRemoteLog::GetLogIfAllCategoriesSet (GDBR_LOG_PROCESS);
if (log)
log->Printf ("GDBRemoteCommunication::%s () => %s", __FUNCTION__, StateAsCString(state));
response.SetFilePos(0);

View File

@ -1212,6 +1212,7 @@ ProcessGDBRemote::DoDestroy ()
StringExtractorGDBRemote response;
if (m_gdb_comm.SendPacketAndWaitForResponse("k", response, 2, false))
{
log = ProcessGDBRemoteLog::GetLogIfAllCategoriesSet(GDBR_LOG_PROCESS);
if (log)
{
if (response.IsOKPacket())
@ -2101,6 +2102,7 @@ ProcessGDBRemote::AsyncThread (void *arg)
bool done = false;
while (!done)
{
log = ProcessGDBRemoteLog::GetLogIfAllCategoriesSet (GDBR_LOG_PROCESS);
if (log)
log->Printf ("ProcessGDBRemote::%s (arg = %p, pid = %i) listener.WaitForEvent (NULL, event_sp)...", __FUNCTION__, arg, process->GetID());
if (listener.WaitForEvent (NULL, event_sp))
@ -2116,6 +2118,7 @@ ProcessGDBRemote::AsyncThread (void *arg)
{
const char *continue_cstr = (const char *)continue_packet->GetBytes ();
const size_t continue_cstr_len = continue_packet->GetByteSize ();
log = ProcessGDBRemoteLog::GetLogIfAllCategoriesSet (GDBR_LOG_PROCESS);
if (log)
log->Printf ("ProcessGDBRemote::%s (arg = %p, pid = %i) got eBroadcastBitAsyncContinue: %s", __FUNCTION__, arg, process->GetID(), continue_cstr);
@ -2153,12 +2156,14 @@ ProcessGDBRemote::AsyncThread (void *arg)
break;
case eBroadcastBitAsyncThreadShouldExit:
log = ProcessGDBRemoteLog::GetLogIfAllCategoriesSet (GDBR_LOG_PROCESS);
if (log)
log->Printf ("ProcessGDBRemote::%s (arg = %p, pid = %i) got eBroadcastBitAsyncThreadShouldExit...", __FUNCTION__, arg, process->GetID());
done = true;
break;
default:
log = ProcessGDBRemoteLog::GetLogIfAllCategoriesSet (GDBR_LOG_PROCESS);
if (log)
log->Printf ("ProcessGDBRemote::%s (arg = %p, pid = %i) got unknown event 0x%8.8x", __FUNCTION__, arg, process->GetID(), event_type);
done = true;
@ -2167,6 +2172,7 @@ ProcessGDBRemote::AsyncThread (void *arg)
}
else
{
log = ProcessGDBRemoteLog::GetLogIfAllCategoriesSet (GDBR_LOG_PROCESS);
if (log)
log->Printf ("ProcessGDBRemote::%s (arg = %p, pid = %i) listener.WaitForEvent (NULL, event_sp) => false", __FUNCTION__, arg, process->GetID());
done = true;
@ -2174,6 +2180,7 @@ ProcessGDBRemote::AsyncThread (void *arg)
}
}
log = ProcessGDBRemoteLog::GetLogIfAllCategoriesSet (GDBR_LOG_PROCESS);
if (log)
log->Printf ("ProcessGDBRemote::%s (arg = %p, pid = %i) thread exiting...", __FUNCTION__, arg, process->GetID());

View File

@ -35,7 +35,7 @@ ProcessGDBRemoteLog::GetLogIfAllCategoriesSet (uint32_t mask)
}
void
ProcessGDBRemoteLog::DisableLog ()
ProcessGDBRemoteLog::DeleteLog ()
{
if (g_log)
{
@ -44,10 +44,53 @@ ProcessGDBRemoteLog::DisableLog ()
}
}
void
ProcessGDBRemoteLog::DisableLog (Args &args, Stream *feedback_strm)
{
if (g_log)
{
uint32_t flag_bits = g_log->GetMask().Get();
const size_t argc = args.GetArgumentCount ();
for (size_t i = 0; i < argc; ++i)
{
const char *arg = args.GetArgumentAtIndex (i);
if (::strcasecmp (arg, "all") == 0 ) flag_bits &= ~GDBR_LOG_ALL;
else if (::strcasecmp (arg, "async") == 0 ) flag_bits &= ~GDBR_LOG_ASYNC;
else if (::strcasestr (arg, "break") == arg ) flag_bits &= ~GDBR_LOG_BREAKPOINTS;
else if (::strcasestr (arg, "comm") == arg ) flag_bits &= ~GDBR_LOG_COMM;
else if (::strcasecmp (arg, "default") == 0 ) flag_bits &= ~GDBR_LOG_DEFAULT;
else if (::strcasecmp (arg, "packets") == 0 ) flag_bits &= ~GDBR_LOG_PACKETS;
else if (::strcasecmp (arg, "memory") == 0 ) flag_bits &= ~GDBR_LOG_MEMORY;
else if (::strcasecmp (arg, "data-short") == 0 ) flag_bits &= ~GDBR_LOG_MEMORY_DATA_SHORT;
else if (::strcasecmp (arg, "data-long") == 0 ) flag_bits &= ~GDBR_LOG_MEMORY_DATA_LONG;
else if (::strcasecmp (arg, "process") == 0 ) flag_bits &= ~GDBR_LOG_PROCESS;
else if (::strcasecmp (arg, "step") == 0 ) flag_bits &= ~GDBR_LOG_STEP;
else if (::strcasecmp (arg, "thread") == 0 ) flag_bits &= ~GDBR_LOG_THREAD;
else if (::strcasecmp (arg, "verbose") == 0 ) flag_bits &= ~GDBR_LOG_VERBOSE;
else if (::strcasestr (arg, "watch") == arg ) flag_bits &= ~GDBR_LOG_WATCHPOINTS;
else
{
feedback_strm->Printf("error: unrecognized log category '%s'\n", arg);
ListLogCategories (feedback_strm);
}
}
if (flag_bits == 0)
DeleteLog();
else
g_log->GetMask().Reset (flag_bits);
}
return;
}
Log *
ProcessGDBRemoteLog::EnableLog (StreamSP &log_stream_sp, uint32_t log_options, Args &args, Stream *feedback_strm)
{
DisableLog ();
DeleteLog ();
g_log = new Log (log_stream_sp);
if (g_log)
{

View File

@ -39,8 +39,11 @@ public:
GetLogIfAllCategoriesSet(uint32_t mask = 0);
static void
DisableLog ();
DisableLog (lldb_private::Args &args, lldb_private::Stream *feedback_strm);
static void
DeleteLog ();
static lldb_private::Log *
EnableLog (lldb::StreamSP &log_stream_sp, uint32_t log_options, lldb_private::Args &args, lldb_private::Stream *feedback_strm);

View File

@ -112,12 +112,44 @@ LogChannelDWARF::EnablePluginLogging (Stream *strm, Args &command)
void
LogChannelDWARF::Disable ()
LogChannelDWARF::Delete ()
{
g_log_channel = NULL;
m_log_sp.reset();
}
void
LogChannelDWARF::Disable (Args &categories, Stream *feedback_strm)
{
g_log_channel = this;
uint32_t flag_bits = m_log_sp->GetMask().Get();
const size_t argc = categories.GetArgumentCount();
for (size_t i = 0; i < argc; ++i)
{
const char *arg = categories.GetArgumentAtIndex(i);
if (::strcasecmp (arg, "all") == 0 ) flag_bits &= ~DWARF_LOG_ALL;
else if (::strcasecmp (arg, "info") == 0 ) flag_bits &= ~DWARF_LOG_DEBUG_INFO;
else if (::strcasecmp (arg, "line") == 0 ) flag_bits &= ~DWARF_LOG_DEBUG_LINE;
else if (::strcasecmp (arg, "pubnames") == 0 ) flag_bits &= ~DWARF_LOG_DEBUG_PUBNAMES;
else if (::strcasecmp (arg, "pubtypes") == 0 ) flag_bits &= ~DWARF_LOG_DEBUG_PUBTYPES;
else if (::strcasecmp (arg, "default") == 0 ) flag_bits &= ~DWARF_LOG_DEFAULT;
else
{
feedback_strm->Printf("error: unrecognized log category '%s'\n", arg);
ListCategories (feedback_strm);
}
}
if (flag_bits == 0)
Delete ();
else
m_log_sp->GetMask().Reset (flag_bits);
return;
}
bool
LogChannelDWARF::Enable
(
@ -127,7 +159,7 @@ LogChannelDWARF::Enable
const Args &categories // The categories to enable within this logging stream, if empty, enable default set
)
{
Disable ();
Delete ();
m_log_sp.reset(new Log (log_stream_sp));
g_log_channel = this;

View File

@ -67,7 +67,10 @@ public:
EnablePluginLogging (lldb_private::Stream *strm, lldb_private::Args &command);
virtual void
Disable ();
Disable (lldb_private::Args &args, lldb_private::Stream *feedback_strm);
void
Delete ();
virtual bool
Enable (lldb::StreamSP &log_stream_sp,

View File

@ -249,6 +249,7 @@ Process::WaitForStateChangedEvents (const TimeValue *timeout, EventSP &event_sp)
event_sp))
state = Process::ProcessEventData::GetStateFromEvent(event_sp.get());
log = lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_PROCESS);
if (log)
log->Printf ("Process::%s (timeout = %p, event_sp) => %s",
__FUNCTION__,
@ -268,6 +269,7 @@ Process::PeekAtStateChangedEvents ()
Event *event_ptr;
event_ptr = m_listener.PeekAtNextEventForBroadcasterWithType (this,
eBroadcastBitStateChanged);
log = lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_PROCESS);
if (log)
{
if (event_ptr)
@ -1640,6 +1642,8 @@ Process::RunPrivateStateThread ()
break;
}
// Verify log is still enabled before attempting to write to it...
log = lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_PROCESS);
if (log)
log->Printf ("Process::%s (arg = %p, pid = %i) thread exiting...", __FUNCTION__, this, GetID());

View File

@ -156,6 +156,7 @@ ThreadPlanStepInRange::ShouldStop (Event *event_ptr)
if (bytes_to_skip != 0)
{
func_start_address.Slide (bytes_to_skip);
log = lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_STEP);
if (log)
log->Printf ("Pushing past prologue ");

View File

@ -89,11 +89,13 @@ ThreadPlanTestCondition::ShouldStop (Event *event_ptr)
else
m_did_stop = true;
}
log = lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_STEP);
if (log)
log->Printf("Condition successfully evaluated, result is %s.\n", m_did_stop ? "true" : "false");
}
else
{
log = lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_STEP);
if (log)
log->Printf("Failed to get a result from the expression, error: \"%s\"\n", error_stream.GetData());
m_did_stop = true;
@ -101,6 +103,7 @@ ThreadPlanTestCondition::ShouldStop (Event *event_ptr)
}
else if (m_exe_ctx.thread->WasThreadPlanDiscarded (m_expression_plan_sp.get()))
{
log = lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_STEP);
if (log)
log->Printf("ExecuteExpression thread plan was discarded.\n");
m_did_stop = true;

View File

@ -107,11 +107,54 @@ lldb_private::GetLogIfAnyCategoriesSet (uint32_t mask)
}
void
lldb_private::DisableLog ()
lldb_private::DisableLog (Args &args, Stream *feedback_strm)
{
LogAccessor (false, NULL);
}
Log *log = LogAccessor (true, NULL);
uint32_t flag_bits;
if (log)
{
flag_bits = log->GetMask().Get();
const size_t argc = args.GetArgumentCount ();
for (size_t i = 0; i < argc; ++i)
{
const char *arg = args.GetArgumentAtIndex (i);
if (strcasecmp(arg, "all") == 0 ) flag_bits &= ~LIBLLDB_LOG_ALL;
else if (strcasecmp(arg, "api") == 0) flag_bits &= ~LIBLLDB_LOG_API;
else if (strcasestr(arg, "break") == arg) flag_bits &= ~LIBLLDB_LOG_BREAKPOINTS;
else if (strcasecmp(arg, "default") == 0 ) flag_bits &= ~LIBLLDB_LOG_DEFAULT;
else if (strcasestr(arg, "event") == arg) flag_bits &= ~LIBLLDB_LOG_EVENTS;
else if (strcasestr(arg, "expr") == arg) flag_bits &= ~LIBLLDB_LOG_EXPRESSIONS;
else if (strcasestr(arg, "object") == arg) flag_bits &= ~LIBLLDB_LOG_OBJECT;
else if (strcasecmp(arg, "process") == 0 ) flag_bits &= ~LIBLLDB_LOG_PROCESS;
else if (strcasecmp(arg, "shlib") == 0 ) flag_bits &= ~LIBLLDB_LOG_SHLIB;
else if (strcasecmp(arg, "state") == 0 ) flag_bits &= ~LIBLLDB_LOG_STATE;
else if (strcasecmp(arg, "step") == 0 ) flag_bits &= ~LIBLLDB_LOG_STEP;
else if (strcasecmp(arg, "thread") == 0 ) flag_bits &= ~LIBLLDB_LOG_THREAD;
else if (strcasecmp(arg, "verbose") == 0 ) flag_bits &= ~LIBLLDB_LOG_VERBOSE;
else if (strcasestr(arg, "watch") == arg) flag_bits &= ~LIBLLDB_LOG_WATCHPOINTS;
else if (strcasestr(arg, "temp") == arg) flag_bits &= ~LIBLLDB_LOG_TEMPORARY;
else if (strcasestr(arg, "comm") == arg) flag_bits &= ~LIBLLDB_LOG_COMMUNICATION;
else if (strcasestr(arg, "conn") == arg) flag_bits &= ~LIBLLDB_LOG_CONNECTION;
else if (strcasestr(arg, "host") == arg) flag_bits &= ~LIBLLDB_LOG_HOST;
else if (strcasestr(arg, "unwind") == arg) flag_bits &= ~LIBLLDB_LOG_UNWIND;
else
{
feedback_strm->Printf ("error: unrecognized log category '%s'\n", arg);
ListLogCategories (feedback_strm);
return;
}
}
if (flag_bits == 0)
LogAccessor (false, NULL);
else
log->GetMask().Reset (flag_bits);
}
return;
}
Log *
lldb_private::EnableLog (StreamSP &log_stream_sp, uint32_t log_options, Args &args, Stream *feedback_strm)