diff --git a/lldb/include/lldb/Core/Log.h b/lldb/include/lldb/Core/Log.h index 75cbac94d2cc..919045dc6171 100644 --- a/lldb/include/lldb/Core/Log.h +++ b/lldb/include/lldb/Core/Log.h @@ -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, diff --git a/lldb/include/lldb/lldb-private-log.h b/lldb/include/lldb/lldb-private-log.h index d7bcc01515ff..0c451d14695c 100644 --- a/lldb/include/lldb/lldb-private-log.h +++ b/lldb/include/lldb/lldb-private-log.h @@ -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); diff --git a/lldb/source/API/SBCommunication.cpp b/lldb/source/API/SBCommunication.cpp index 9ac65087b26a..45c4a4c4f9d2 100644 --- a/lldb/source/API/SBCommunication.cpp +++ b/lldb/source/API/SBCommunication.cpp @@ -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")); diff --git a/lldb/source/API/SBListener.cpp b/lldb/source/API/SBListener.cpp index ebadd003070c..d4f9101dfb28 100644 --- a/lldb/source/API/SBListener.cpp +++ b/lldb/source/API/SBListener.cpp @@ -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); diff --git a/lldb/source/API/SBProcess.cpp b/lldb/source/API/SBProcess.cpp index eb007fcfa773..000854d97136 100644 --- a/lldb/source/API/SBProcess.cpp +++ b/lldb/source/API/SBProcess.cpp @@ -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; diff --git a/lldb/source/API/SBTarget.cpp b/lldb/source/API/SBTarget.cpp index 24c78f4294bf..8cd41ad58172 100644 --- a/lldb/source/API/SBTarget.cpp +++ b/lldb/source/API/SBTarget.cpp @@ -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; diff --git a/lldb/source/API/SBThread.cpp b/lldb/source/API/SBThread.cpp index 810b114045c3..b28a379f1a69 100644 --- a/lldb/source/API/SBThread.cpp +++ b/lldb/source/API/SBThread.cpp @@ -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; diff --git a/lldb/source/Breakpoint/BreakpointLocation.cpp b/lldb/source/Breakpoint/BreakpointLocation.cpp index 525efd36ea16..3ee4d61bf49f 100644 --- a/lldb/source/Breakpoint/BreakpointLocation.cpp +++ b/lldb/source/Breakpoint/BreakpointLocation.cpp @@ -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; diff --git a/lldb/source/Commands/CommandObjectLog.cpp b/lldb/source/Commands/CommandObjectLog.cpp index 56630c9068c8..f814dd2e3b40 100644 --- a/lldb/source/Commands/CommandObjectLog.cpp +++ b/lldb/source/Commands/CommandObjectLog.cpp @@ -291,31 +291,29 @@ public: } else { - for (size_t i=0; iDisable(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(); diff --git a/lldb/source/Core/Communication.cpp b/lldb/source/Core/Communication.cpp index 5234024a2730..2fb9cba3ff5e 100644 --- a/lldb/source/Core/Communication.cpp +++ b/lldb/source/Core/Communication.cpp @@ -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); diff --git a/lldb/source/Core/Listener.cpp b/lldb/source/Core/Listener.cpp index 717e4ad2778d..ac4f46488aa7 100644 --- a/lldb/source/Core/Listener.cpp +++ b/lldb/source/Core/Listener.cpp @@ -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; diff --git a/lldb/source/Core/Log.cpp b/lldb/source/Core/Log.cpp index a612b6500cfa..16063e483af5 100644 --- a/lldb/source/Core/Log.cpp +++ b/lldb/source/Core/Log.cpp @@ -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 diff --git a/lldb/source/Expression/ClangFunction.cpp b/lldb/source/Expression/ClangFunction.cpp index b7f3d0d23621..bfde5fd73f70 100644 --- a/lldb/source/Expression/ClangFunction.cpp +++ b/lldb/source/Expression/ClangFunction.cpp @@ -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; diff --git a/lldb/source/Host/common/Host.cpp b/lldb/source/Host/common/Host.cpp index ed6a2746099f..51702d0e2511 100644 --- a/lldb/source/Host/common/Host.cpp +++ b/lldb/source/Host/common/Host.cpp @@ -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); diff --git a/lldb/source/Plugins/Process/MacOSX-User/source/MacOSX/MachException.cpp b/lldb/source/Plugins/Process/MacOSX-User/source/MacOSX/MachException.cpp index 483cca2fd657..1264398ef267 100644 --- a/lldb/source/Plugins/Process/MacOSX-User/source/MacOSX/MachException.cpp +++ b/lldb/source/Plugins/Process/MacOSX-User/source/MacOSX/MachException.cpp @@ -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)", diff --git a/lldb/source/Plugins/Process/MacOSX-User/source/MacOSX/MachTask.cpp b/lldb/source/Plugins/Process/MacOSX-User/source/MacOSX/MachTask.cpp index a315fddcc725..4d6d3b1c792b 100644 --- a/lldb/source/Plugins/Process/MacOSX-User/source/MacOSX/MachTask.cpp +++ b/lldb/source/Plugins/Process/MacOSX-User/source/MacOSX/MachTask.cpp @@ -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; diff --git a/lldb/source/Plugins/Process/MacOSX-User/source/ProcessMacOSX.cpp b/lldb/source/Plugins/Process/MacOSX-User/source/ProcessMacOSX.cpp index 96bb7d44e872..3288fc80b0d6 100644 --- a/lldb/source/Plugins/Process/MacOSX-User/source/ProcessMacOSX.cpp +++ b/lldb/source/Plugins/Process/MacOSX-User/source/ProcessMacOSX.cpp @@ -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(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); diff --git a/lldb/source/Plugins/Process/MacOSX-User/source/ProcessMacOSXLog.cpp b/lldb/source/Plugins/Process/MacOSX-User/source/ProcessMacOSXLog.cpp index 1fcb9cce58ce..b02117208713 100644 --- a/lldb/source/Plugins/Process/MacOSX-User/source/ProcessMacOSXLog.cpp +++ b/lldb/source/Plugins/Process/MacOSX-User/source/ProcessMacOSXLog.cpp @@ -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) { diff --git a/lldb/source/Plugins/Process/MacOSX-User/source/ProcessMacOSXLog.h b/lldb/source/Plugins/Process/MacOSX-User/source/ProcessMacOSXLog.h index cb2a4e8ee982..74e5278e870d 100644 --- a/lldb/source/Plugins/Process/MacOSX-User/source/ProcessMacOSXLog.h +++ b/lldb/source/Plugins/Process/MacOSX-User/source/ProcessMacOSXLog.h @@ -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); diff --git a/lldb/source/Plugins/Process/MacOSX-User/source/ThreadMacOSX.cpp b/lldb/source/Plugins/Process/MacOSX-User/source/ThreadMacOSX.cpp index c400ef6eaee6..07130f891347 100644 --- a/lldb/source/Plugins/Process/MacOSX-User/source/ThreadMacOSX.cpp +++ b/lldb/source/Plugins/Process/MacOSX-User/source/ThreadMacOSX.cpp @@ -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); } diff --git a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunication.cpp b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunication.cpp index be8aaf7ccd64..d53bf8149c24 100644 --- a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunication.cpp +++ b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunication.cpp @@ -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); diff --git a/lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp b/lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp index 4fca6f06d13d..2cc9e0aa3a1b 100644 --- a/lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp +++ b/lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp @@ -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()); diff --git a/lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemoteLog.cpp b/lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemoteLog.cpp index 5a7348636e40..776ffeb36d64 100644 --- a/lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemoteLog.cpp +++ b/lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemoteLog.cpp @@ -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) { diff --git a/lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemoteLog.h b/lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemoteLog.h index c053d2933550..2dbd94fc0caf 100644 --- a/lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemoteLog.h +++ b/lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemoteLog.h @@ -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); diff --git a/lldb/source/Plugins/SymbolFile/DWARF/LogChannelDWARF.cpp b/lldb/source/Plugins/SymbolFile/DWARF/LogChannelDWARF.cpp index 22c2bf150215..db81ca808304 100644 --- a/lldb/source/Plugins/SymbolFile/DWARF/LogChannelDWARF.cpp +++ b/lldb/source/Plugins/SymbolFile/DWARF/LogChannelDWARF.cpp @@ -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; diff --git a/lldb/source/Plugins/SymbolFile/DWARF/LogChannelDWARF.h b/lldb/source/Plugins/SymbolFile/DWARF/LogChannelDWARF.h index 943d1da194f6..6105651f348e 100644 --- a/lldb/source/Plugins/SymbolFile/DWARF/LogChannelDWARF.h +++ b/lldb/source/Plugins/SymbolFile/DWARF/LogChannelDWARF.h @@ -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, diff --git a/lldb/source/Target/Process.cpp b/lldb/source/Target/Process.cpp index ce072ed8cb42..b6537276ffac 100644 --- a/lldb/source/Target/Process.cpp +++ b/lldb/source/Target/Process.cpp @@ -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()); diff --git a/lldb/source/Target/ThreadPlanStepInRange.cpp b/lldb/source/Target/ThreadPlanStepInRange.cpp index 92f78bbd14b0..2be93808f2a0 100644 --- a/lldb/source/Target/ThreadPlanStepInRange.cpp +++ b/lldb/source/Target/ThreadPlanStepInRange.cpp @@ -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 "); diff --git a/lldb/source/Target/ThreadPlanTestCondition.cpp b/lldb/source/Target/ThreadPlanTestCondition.cpp index d66fff7bca54..68d4a8af9d6b 100644 --- a/lldb/source/Target/ThreadPlanTestCondition.cpp +++ b/lldb/source/Target/ThreadPlanTestCondition.cpp @@ -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; diff --git a/lldb/source/lldb-log.cpp b/lldb/source/lldb-log.cpp index 4d4f9f5851bd..a7ba32801f16 100644 --- a/lldb/source/lldb-log.cpp +++ b/lldb/source/lldb-log.cpp @@ -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)