summaryrefslogtreecommitdiffstats
path: root/lldb/source/Plugins/Process/MacOSX-Kernel/ProcessKDPLog.cpp
diff options
context:
space:
mode:
authorGreg Clayton <gclayton@apple.com>2013-03-27 23:08:40 +0000
committerGreg Clayton <gclayton@apple.com>2013-03-27 23:08:40 +0000
commit5160ce5c72e5f55c2e83ca9914cd0f02e0c5ceb3 (patch)
treeb24bb5959b40d8f0e99ed6d8b13271270dbf08e3 /lldb/source/Plugins/Process/MacOSX-Kernel/ProcessKDPLog.cpp
parentccc266559f5c028442b6393362da14d866d9b32b (diff)
downloadbcm5719-llvm-5160ce5c72e5f55c2e83ca9914cd0f02e0c5ceb3.tar.gz
bcm5719-llvm-5160ce5c72e5f55c2e83ca9914cd0f02e0c5ceb3.zip
<rdar://problem/13521159>
LLDB is crashing when logging is enabled from lldb-perf-clang. This has to do with the global destructor chain as the process and its threads are being torn down. All logging channels now make one and only one instance that is kept in a global pointer which is never freed. This guarantees that logging can correctly continue as the process tears itself down. llvm-svn: 178191
Diffstat (limited to 'lldb/source/Plugins/Process/MacOSX-Kernel/ProcessKDPLog.cpp')
-rw-r--r--lldb/source/Plugins/Process/MacOSX-Kernel/ProcessKDPLog.cpp46
1 files changed, 25 insertions, 21 deletions
diff --git a/lldb/source/Plugins/Process/MacOSX-Kernel/ProcessKDPLog.cpp b/lldb/source/Plugins/Process/MacOSX-Kernel/ProcessKDPLog.cpp
index ff3c46ece3f..53b08d53c24 100644
--- a/lldb/source/Plugins/Process/MacOSX-Kernel/ProcessKDPLog.cpp
+++ b/lldb/source/Plugins/Process/MacOSX-Kernel/ProcessKDPLog.cpp
@@ -22,22 +22,25 @@ using namespace lldb_private;
// control access to our static g_log_sp by hiding it in a singleton function
// that will construct the static g_lob_sp the first time this function is
// called.
-static LogSP &
+static bool g_log_enabled = false;
+static Log * g_log = NULL;
+static Log *
GetLog ()
{
- static LogSP g_log_sp;
- return g_log_sp;
+ if (!g_log_enabled)
+ return NULL;
+ return g_log;
}
-LogSP
+Log *
ProcessKDPLog::GetLogIfAllCategoriesSet (uint32_t mask)
{
- LogSP log(GetLog ());
+ Log *log(GetLog ());
if (log && mask)
{
uint32_t log_mask = log->GetMask().Get();
if ((log_mask & mask) != mask)
- return LogSP();
+ return NULL;
}
return log;
}
@@ -45,7 +48,7 @@ ProcessKDPLog::GetLogIfAllCategoriesSet (uint32_t mask)
void
ProcessKDPLog::DisableLog (const char **categories, Stream *feedback_strm)
{
- LogSP log (GetLog ());
+ Log *log (GetLog ());
if (log)
{
uint32_t flag_bits = 0;
@@ -81,33 +84,33 @@ ProcessKDPLog::DisableLog (const char **categories, Stream *feedback_strm)
}
}
+ log->GetMask().Reset (flag_bits);
if (flag_bits == 0)
- GetLog ().reset();
- else
- log->GetMask().Reset (flag_bits);
+ g_log_enabled = false;
}
return;
}
-LogSP
+Log *
ProcessKDPLog::EnableLog (StreamSP &log_stream_sp, uint32_t log_options, const char **categories, Stream *feedback_strm)
{
// Try see if there already is a log - that way we can reuse its settings.
// We could reuse the log in toto, but we don't know that the stream is the same.
uint32_t flag_bits = 0;
- LogSP log(GetLog ());
- if (log)
- flag_bits = log->GetMask().Get();
+ if (g_log)
+ flag_bits = g_log->GetMask().Get();
// Now make a new log with this stream if one was provided
if (log_stream_sp)
{
- log.reset (new Log(log_stream_sp));
- GetLog () = log;
+ if (g_log)
+ g_log->SetStream(log_stream_sp);
+ else
+ g_log = new Log(log_stream_sp);
}
- if (log)
+ if (g_log)
{
bool got_unknown_category = false;
for (size_t i=0; categories[i] != NULL; ++i)
@@ -140,10 +143,11 @@ ProcessKDPLog::EnableLog (StreamSP &log_stream_sp, uint32_t log_options, const c
}
if (flag_bits == 0)
flag_bits = KDP_LOG_DEFAULT;
- log->GetMask().Reset(flag_bits);
- log->GetOptions().Reset(log_options);
+ g_log->GetMask().Reset(flag_bits);
+ g_log->GetOptions().Reset(log_options);
}
- return log;
+ g_log_enabled = true;
+ return g_log;
}
void
@@ -170,7 +174,7 @@ ProcessKDPLog::ListLogCategories (Stream *strm)
void
ProcessKDPLog::LogIf (uint32_t mask, const char *format, ...)
{
- LogSP log (ProcessKDPLog::GetLogIfAllCategoriesSet (mask));
+ Log *log (ProcessKDPLog::GetLogIfAllCategoriesSet (mask));
if (log)
{
va_list args;
OpenPOWER on IntegriCloud