diff options
author | Greg Clayton <gclayton@apple.com> | 2010-11-06 01:53:30 +0000 |
---|---|---|
committer | Greg Clayton <gclayton@apple.com> | 2010-11-06 01:53:30 +0000 |
commit | 2d4edfbc6ad8c8823791dd0285302282d2d2ed03 (patch) | |
tree | c5462c66c46d3ed32bdd6738e948eb410cb0bfde /lldb/source/Plugins/Process/gdb-remote | |
parent | 8e3d95e7dfb44fcd2d7fbf94f104fe821c42268e (diff) | |
download | bcm5719-llvm-2d4edfbc6ad8c8823791dd0285302282d2d2ed03.tar.gz bcm5719-llvm-2d4edfbc6ad8c8823791dd0285302282d2d2ed03.zip |
Modified all logging calls to hand out shared pointers to make sure we
don't crash if we disable logging when some code already has a copy of the
logger. Prior to this fix, logs were handed out as pointers and if they were
held onto while a log got disabled, then it could cause a crash. Now all logs
are handed out as shared pointers so this problem shouldn't happen anymore.
We are also using our new shared pointers that put the shared pointer count
and the object into the same allocation for a tad better performance.
llvm-svn: 118319
Diffstat (limited to 'lldb/source/Plugins/Process/gdb-remote')
4 files changed, 62 insertions, 52 deletions
diff --git a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunication.cpp b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunication.cpp index d53bf8149c2..50a7aec4c17 100644 --- a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunication.cpp +++ b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunication.cpp @@ -193,8 +193,8 @@ GDBRemoteCommunication::SendContinuePacketAndWaitForResponse StringExtractorGDBRemote &response ) { - Log *log = ProcessGDBRemoteLog::GetLogIfAllCategoriesSet (GDBR_LOG_PROCESS); - Log *async_log = ProcessGDBRemoteLog::GetLogIfAllCategoriesSet (GDBR_LOG_ASYNC); + LogSP log (ProcessGDBRemoteLog::GetLogIfAllCategoriesSet (GDBR_LOG_PROCESS)); + LogSP async_log(ProcessGDBRemoteLog::GetLogIfAllCategoriesSet (GDBR_LOG_ASYNC)); if (log) log->Printf ("GDBRemoteCommunication::%s ()", __FUNCTION__); diff --git a/lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp b/lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp index 8d3675d0b7d..7e5c3c935a9 100644 --- a/lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp +++ b/lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp @@ -633,7 +633,7 @@ ProcessGDBRemote::DoAttachToProcessWithID (lldb::pid_t attach_pid) Clear(); ArchSpec arch_spec = GetTarget().GetArchitecture(); - //Log *log = ProcessGDBRemoteLog::GetLogIfAllCategoriesSet (GDBR_LOG_PROCESS); + //LogSP log (ProcessGDBRemoteLog::GetLogIfAllCategoriesSet (GDBR_LOG_PROCESS)); if (attach_pid != LLDB_INVALID_PROCESS_ID) @@ -735,7 +735,7 @@ ProcessGDBRemote::DoAttachToProcessWithName (const char *process_name, bool wait // HACK: require arch be set correctly at the target level until we can // figure out a good way to determine the arch of what we are attaching to - //Log *log = ProcessGDBRemoteLog::GetLogIfAllCategoriesSet (GDBR_LOG_PROCESS); + //LogSP log (ProcessGDBRemoteLog::GetLogIfAllCategoriesSet (GDBR_LOG_PROCESS)); if (process_name && process_name[0]) { char host_port[128]; @@ -948,7 +948,7 @@ uint32_t ProcessGDBRemote::UpdateThreadListIfNeeded () { // locker will keep a mutex locked until it goes out of scope - Log *log = ProcessGDBRemoteLog::GetLogIfAllCategoriesSet (GDBR_LOG_THREAD); + LogSP log (ProcessGDBRemoteLog::GetLogIfAllCategoriesSet (GDBR_LOG_THREAD)); if (log && log->GetMask().Test(GDBR_LOG_VERBOSE)) log->Printf ("ProcessGDBRemote::%s (pid = %i)", __FUNCTION__, GetID()); @@ -1166,7 +1166,7 @@ Error ProcessGDBRemote::DoDetach() { Error error; - Log *log = ProcessGDBRemoteLog::GetLogIfAllCategoriesSet(GDBR_LOG_PROCESS); + LogSP log (ProcessGDBRemoteLog::GetLogIfAllCategoriesSet(GDBR_LOG_PROCESS)); if (log) log->Printf ("ProcessGDBRemote::DoDetach()"); @@ -1199,7 +1199,7 @@ Error ProcessGDBRemote::DoDestroy () { Error error; - Log *log = ProcessGDBRemoteLog::GetLogIfAllCategoriesSet(GDBR_LOG_PROCESS); + LogSP log (ProcessGDBRemoteLog::GetLogIfAllCategoriesSet(GDBR_LOG_PROCESS)); if (log) log->Printf ("ProcessGDBRemote::DoDestroy()"); @@ -1407,7 +1407,7 @@ ProcessGDBRemote::EnableBreakpoint (BreakpointSite *bp_site) Error error; assert (bp_site != NULL); - Log *log = ProcessGDBRemoteLog::GetLogIfAllCategoriesSet(GDBR_LOG_BREAKPOINTS); + LogSP log (ProcessGDBRemoteLog::GetLogIfAllCategoriesSet(GDBR_LOG_BREAKPOINTS)); user_id_t site_id = bp_site->GetID(); const addr_t addr = bp_site->GetLoadAddress(); if (log) @@ -1483,7 +1483,7 @@ ProcessGDBRemote::DisableBreakpoint (BreakpointSite *bp_site) assert (bp_site != NULL); addr_t addr = bp_site->GetLoadAddress(); user_id_t site_id = bp_site->GetID(); - Log *log = ProcessGDBRemoteLog::GetLogIfAllCategoriesSet(GDBR_LOG_BREAKPOINTS); + LogSP log (ProcessGDBRemoteLog::GetLogIfAllCategoriesSet(GDBR_LOG_BREAKPOINTS)); if (log) log->Printf ("ProcessGDBRemote::DisableBreakpoint (site_id = %d) addr = 0x%8.8llx", site_id, (uint64_t)addr); @@ -1550,7 +1550,7 @@ ProcessGDBRemote::EnableWatchpoint (WatchpointLocation *wp) { user_id_t watchID = wp->GetID(); addr_t addr = wp->GetLoadAddress(); - Log *log = ProcessGDBRemoteLog::GetLogIfAllCategoriesSet(GDBR_LOG_WATCHPOINTS); + LogSP log (ProcessGDBRemoteLog::GetLogIfAllCategoriesSet(GDBR_LOG_WATCHPOINTS)); if (log) log->Printf ("ProcessGDBRemote::EnableWatchpoint(watchID = %d)", watchID); if (wp->IsEnabled()) @@ -1582,7 +1582,7 @@ ProcessGDBRemote::DisableWatchpoint (WatchpointLocation *wp) { user_id_t watchID = wp->GetID(); - Log *log = ProcessGDBRemoteLog::GetLogIfAllCategoriesSet(GDBR_LOG_WATCHPOINTS); + LogSP log (ProcessGDBRemoteLog::GetLogIfAllCategoriesSet(GDBR_LOG_WATCHPOINTS)); addr_t addr = wp->GetLoadAddress(); if (log) @@ -1620,7 +1620,7 @@ Error ProcessGDBRemote::DoSignal (int signo) { Error error; - Log *log = ProcessGDBRemoteLog::GetLogIfAllCategoriesSet(GDBR_LOG_PROCESS); + LogSP log (ProcessGDBRemoteLog::GetLogIfAllCategoriesSet(GDBR_LOG_PROCESS)); if (log) log->Printf ("ProcessGDBRemote::DoSignal (signal = %d)", signo); @@ -1706,14 +1706,14 @@ ProcessGDBRemote::StartDebugserverProcess m_stdio_communication.Clear(); posix_spawnattr_t attr; - Log *log = ProcessGDBRemoteLog::GetLogIfAllCategoriesSet (GDBR_LOG_PROCESS); + LogSP log (ProcessGDBRemoteLog::GetLogIfAllCategoriesSet (GDBR_LOG_PROCESS)); Error local_err; // Errors that don't affect the spawning. if (log) log->Printf ("%s ( path='%s', argv=%p, envp=%p, arch=%s )", __FUNCTION__, debugserver_path, inferior_argv, inferior_envp, inferior_arch.AsCString()); error.SetError( ::posix_spawnattr_init (&attr), eErrorTypePOSIX); if (error.Fail() || log) - error.PutToLog(log, "::posix_spawnattr_init ( &attr )"); + error.PutToLog(log.get(), "::posix_spawnattr_init ( &attr )"); if (error.Fail()) return error;; @@ -1730,7 +1730,7 @@ ProcessGDBRemote::StartDebugserverProcess size_t ocount = 0; error.SetError( ::posix_spawnattr_setbinpref_np (&attr, 1, &cpu, &ocount), eErrorTypePOSIX); if (error.Fail() || log) - error.PutToLog(log, "::posix_spawnattr_setbinpref_np ( &attr, 1, cpu_type = 0x%8.8x, count => %zu )", cpu, ocount); + error.PutToLog(log.get(), "::posix_spawnattr_setbinpref_np ( &attr, 1, cpu_type = 0x%8.8x, count => %zu )", cpu, ocount); if (error.Fail() != 0 || ocount != 1) return error; @@ -1879,7 +1879,7 @@ ProcessGDBRemote::StartDebugserverProcess m_debugserver_pid = LLDB_INVALID_PROCESS_ID; if (error.Fail() || log) - error.PutToLog(log, "::posix_spawnp ( pid => %i, path = '%s', file_actions = %p, attr = %p, argv = %p, envp = %p )", m_debugserver_pid, debugserver_path, NULL, &attr, inferior_argv, inferior_envp); + error.PutToLog(log.get(), "::posix_spawnp ( pid => %i, path = '%s', file_actions = %p, attr = %p, argv = %p, envp = %p )", m_debugserver_pid, debugserver_path, NULL, &attr, inferior_argv, inferior_envp); if (m_debugserver_pid != LLDB_INVALID_PROCESS_ID) { @@ -2055,7 +2055,7 @@ ProcessGDBRemote::StartAsyncThread () { ResetGDBRemoteState (); - Log *log = ProcessGDBRemoteLog::GetLogIfAllCategoriesSet(GDBR_LOG_PROCESS); + LogSP log (ProcessGDBRemoteLog::GetLogIfAllCategoriesSet(GDBR_LOG_PROCESS)); if (log) log->Printf ("ProcessGDBRemote::%s ()", __FUNCTION__); @@ -2069,7 +2069,7 @@ ProcessGDBRemote::StartAsyncThread () void ProcessGDBRemote::StopAsyncThread () { - Log *log = ProcessGDBRemoteLog::GetLogIfAllCategoriesSet(GDBR_LOG_PROCESS); + LogSP log (ProcessGDBRemoteLog::GetLogIfAllCategoriesSet(GDBR_LOG_PROCESS)); if (log) log->Printf ("ProcessGDBRemote::%s ()", __FUNCTION__); @@ -2089,7 +2089,7 @@ ProcessGDBRemote::AsyncThread (void *arg) { ProcessGDBRemote *process = (ProcessGDBRemote*) arg; - Log *log = ProcessGDBRemoteLog::GetLogIfAllCategoriesSet (GDBR_LOG_PROCESS); + LogSP log (ProcessGDBRemoteLog::GetLogIfAllCategoriesSet (GDBR_LOG_PROCESS)); if (log) log->Printf ("ProcessGDBRemote::%s (arg = %p, pid = %i) thread starting...", __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 776ffeb36d6..963a468b432 100644 --- a/lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemoteLog.cpp +++ b/lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemoteLog.cpp @@ -18,38 +18,37 @@ using namespace lldb; using namespace lldb_private; -static Log* g_log = NULL; // Leak for now as auto_ptr was being cleaned up - // by global constructors before other threads - // were done with it. -Log * +// We want to avoid global constructors where code needs to be run so here we +// 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 & +GetLog () +{ + static LogSP g_log_sp; + return g_log_sp; +} + +LogSP ProcessGDBRemoteLog::GetLogIfAllCategoriesSet (uint32_t mask) { - Log *log = g_log; + LogSP log(GetLog ()); if (log && mask) { uint32_t log_mask = log->GetMask().Get(); if ((log_mask & mask) != mask) - return NULL; + return LogSP(); } return log; } void -ProcessGDBRemoteLog::DeleteLog () -{ - if (g_log) - { - delete g_log; - g_log = NULL; - } -} - -void ProcessGDBRemoteLog::DisableLog (Args &args, Stream *feedback_strm) { - if (g_log) + LogSP log (GetLog ()); + if (log) { - uint32_t flag_bits = g_log->GetMask().Get(); + uint32_t flag_bits = log->GetMask().Get(); const size_t argc = args.GetArgumentCount (); for (size_t i = 0; i < argc; ++i) { @@ -79,20 +78,34 @@ ProcessGDBRemoteLog::DisableLog (Args &args, Stream *feedback_strm) } if (flag_bits == 0) - DeleteLog(); + GetLog ().reset(); else - g_log->GetMask().Reset (flag_bits); + log->GetMask().Reset (flag_bits); } return; } -Log * +LogSP ProcessGDBRemoteLog::EnableLog (StreamSP &log_stream_sp, uint32_t log_options, Args &args, Stream *feedback_strm) { - DeleteLog (); - g_log = new Log (log_stream_sp); - if (g_log) + // 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; + LogSP log(GetLog ()); + if (log) + flag_bits = log->GetMask().Get(); + else + flag_bits = 0; + + // Now make a new log with this stream if one was provided + if (log_stream_sp) + { + log = make_shared<Log>(log_stream_sp); + GetLog () = log; + } + + if (log) { uint32_t flag_bits = 0; bool got_unknown_category = false; @@ -127,10 +140,10 @@ ProcessGDBRemoteLog::EnableLog (StreamSP &log_stream_sp, uint32_t log_options, A } if (flag_bits == 0) flag_bits = GDBR_LOG_DEFAULT; - g_log->GetMask().Reset(flag_bits); - g_log->GetOptions().Reset(log_options); + log->GetMask().Reset(flag_bits); + log->GetOptions().Reset(log_options); } - return g_log; + return log; } void @@ -157,7 +170,7 @@ ProcessGDBRemoteLog::ListLogCategories (Stream *strm) void ProcessGDBRemoteLog::LogIf (uint32_t mask, const char *format, ...) { - Log *log = ProcessGDBRemoteLog::GetLogIfAllCategoriesSet (mask); + LogSP log (ProcessGDBRemoteLog::GetLogIfAllCategoriesSet (mask)); if (log) { va_list args; diff --git a/lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemoteLog.h b/lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemoteLog.h index 2dbd94fc0ca..5e98403bbfb 100644 --- a/lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemoteLog.h +++ b/lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemoteLog.h @@ -35,16 +35,13 @@ class ProcessGDBRemoteLog { public: - static lldb_private::Log * + static lldb::LogSP GetLogIfAllCategoriesSet(uint32_t mask = 0); static void DisableLog (lldb_private::Args &args, lldb_private::Stream *feedback_strm); - static void - DeleteLog (); - - static lldb_private::Log * + static lldb::LogSP EnableLog (lldb::StreamSP &log_stream_sp, uint32_t log_options, lldb_private::Args &args, lldb_private::Stream *feedback_strm); static void |