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 | |
| 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')
17 files changed, 215 insertions, 189 deletions
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 1264398ef26..ba2da2b0e9b 100644 --- a/lldb/source/Plugins/Process/MacOSX-User/source/MacOSX/MachException.cpp +++ b/lldb/source/Plugins/Process/MacOSX-User/source/MacOSX/MachException.cpp @@ -18,6 +18,7 @@ #include "MachException.h" #include "ProcessMacOSXLog.h" +using namespace lldb; using namespace lldb_private; // Routine mach_exception_raise @@ -91,7 +92,7 @@ catch_mach_exception_raise_state mach_msg_type_number_t * new_stateCnt ) { - Log *log = ProcessMacOSXLog::GetLogIfAllCategoriesSet(PD_LOG_EXCEPTIONS); + LogSP log (ProcessMacOSXLog::GetLogIfAllCategoriesSet(PD_LOG_EXCEPTIONS)); if (log) { log->Printf("::%s ( exc_port = 0x%4.4x, exc_type = %d ( %s ), exc_data = " MACH_EXCEPTION_DATA_FMT_HEX ", exc_data_count = %d)", @@ -122,7 +123,7 @@ catch_mach_exception_raise_state_identity ) { kern_return_t kret; - Log * log = ProcessMacOSXLog::GetLogIfAllCategoriesSet(PD_LOG_EXCEPTIONS); + LogSP log (ProcessMacOSXLog::GetLogIfAllCategoriesSet(PD_LOG_EXCEPTIONS)); if (log) { log->Printf("::%s ( exc_port = 0x%4.4x, thd_port = 0x%4.4x, tsk_port = 0x%4.4x, exc_type = %d ( %s ), exc_data[%d] = { " MACH_EXCEPTION_DATA_FMT_HEX ", " MACH_EXCEPTION_DATA_FMT_HEX " })", @@ -152,7 +153,7 @@ catch_mach_exception_raise mach_exception_data_t exc_data, mach_msg_type_number_t exc_data_count) { - Log * log = ProcessMacOSXLog::GetLogIfAllCategoriesSet(PD_LOG_EXCEPTIONS); + LogSP log (ProcessMacOSXLog::GetLogIfAllCategoriesSet(PD_LOG_EXCEPTIONS)); if (log) { log->Printf("::%s ( exc_port = 0x%4.4x, thd_port = 0x%4.4x, tsk_port = 0x%4.4x, exc_type = %d ( %s ), exc_data[%d] = { " MACH_EXCEPTION_DATA_FMT_HEX ", " MACH_EXCEPTION_DATA_FMT_HEX " })", @@ -215,7 +216,7 @@ MachException::Data::GetStopInfo (lldb_private::Thread &thread) const void MachException::Data::DumpStopReason() const { - Log * log = ProcessMacOSXLog::GetLogIfAllCategoriesSet(); + LogSP log (ProcessMacOSXLog::GetLogIfAllCategoriesSet()); if (log) { int signal = SoftSignal(); @@ -236,7 +237,7 @@ kern_return_t MachException::Message::Receive(mach_port_t port, mach_msg_option_t options, mach_msg_timeout_t timeout, mach_port_t notify_port) { Error err; - Log * log = ProcessMacOSXLog::GetLogIfAllCategoriesSet(PD_LOG_EXCEPTIONS); + LogSP log (ProcessMacOSXLog::GetLogIfAllCategoriesSet(PD_LOG_EXCEPTIONS)); mach_msg_timeout_t mach_msg_timeout = options & MACH_RCV_TIMEOUT ? timeout : 0; if (log && ((options & MACH_RCV_TIMEOUT) == 0)) { @@ -313,7 +314,7 @@ MachException::Message::CatchExceptionRaise() } else { - Log * log = ProcessMacOSXLog::GetLogIfAllCategoriesSet(PD_LOG_EXCEPTIONS); + LogSP log (ProcessMacOSXLog::GetLogIfAllCategoriesSet(PD_LOG_EXCEPTIONS)); if (log) log->Printf ("mach_exc_server returned zero..."); } @@ -329,7 +330,7 @@ MachException::Message::Reply(task_t task, pid_t pid, int signal) // Reply to the exception... Error err; - Log *log = ProcessMacOSXLog::GetLogIfAllCategoriesSet(); + LogSP log (ProcessMacOSXLog::GetLogIfAllCategoriesSet()); if (log) log->Printf("MachException::Message::Reply (task = 0x%4.4x, pid = %i, signal = %i)", task, pid, signal); @@ -369,7 +370,7 @@ MachException::Message::Reply(task_t task, pid_t pid, int signal) err.Clear(); if (log && log->GetMask().Test(PD_LOG_EXCEPTIONS) || err.Fail()) - err.PutToLog(log, "::ptrace (request = PT_THUPDATE, pid = %i, tid = 0x%4.4x, signal = %i)", state_pid, state.thread_port, signal); + err.PutToLog(log.get(), "::ptrace (request = PT_THUPDATE, pid = %i, tid = 0x%4.4x, signal = %i)", state_pid, state.thread_port, signal); } err = ::mach_msg ( &reply_msg.hdr, @@ -401,18 +402,18 @@ MachException::Message::Reply(task_t task, pid_t pid, int signal) { if (err.GetError() == MACH_SEND_INTERRUPTED) { - err.PutToLog(log, "::mach_msg() - send interrupted"); + err.PutToLog(log.get(), "::mach_msg() - send interrupted"); } else { if (state.task_port == task) { - err.PutToLog(log, "::mach_msg() - failed (task)"); + err.PutToLog(log.get(), "::mach_msg() - failed (task)"); abort (); } else { - err.PutToLog(log, "::mach_msg() - failed (child of task)"); + err.PutToLog(log.get(), "::mach_msg() - failed (child of task)"); } } } @@ -465,7 +466,7 @@ kern_return_t MachException::PortInfo::Save (task_t task) { count = EXC_TYPES_COUNT; - Log *log = ProcessMacOSXLog::GetLogIfAllCategoriesSet (PD_LOG_EXCEPTIONS); + LogSP log (ProcessMacOSXLog::GetLogIfAllCategoriesSet (PD_LOG_EXCEPTIONS)); if (log) log->Printf ("MachException::PortInfo::Save (task = 0x%4.4x)", task); Error err; @@ -473,7 +474,7 @@ MachException::PortInfo::Save (task_t task) log->Printf("::task_get_exception_ports (task=0x%4.4x, mask=0x%x, maskCnt<=>%u, ports, behaviors, flavors)...", task, EXC_MASK_ALL, count); err = ::task_get_exception_ports (task, EXC_MASK_ALL, masks, &count, ports, behaviors, flavors); if (log || err.Fail()) - err.PutToLog(log, "::task_get_exception_ports (task=0x%4.4x, mask=0x%x, maskCnt<=>%u, ports, behaviors, flavors)", task, EXC_MASK_ALL, count); + err.PutToLog(log.get(), "::task_get_exception_ports (task=0x%4.4x, mask=0x%x, maskCnt<=>%u, ports, behaviors, flavors)", task, EXC_MASK_ALL, count); if (log) { mach_msg_type_number_t i; @@ -490,7 +491,7 @@ MachException::PortInfo::Save (task_t task) kern_return_t MachException::PortInfo::Restore (task_t task) { - Log *log = ProcessMacOSXLog::GetLogIfAllCategoriesSet (PD_LOG_EXCEPTIONS); + LogSP log (ProcessMacOSXLog::GetLogIfAllCategoriesSet (PD_LOG_EXCEPTIONS)); if (log && log->GetMask().Test(PD_LOG_VERBOSE)) log->Printf("MachException::PortInfo::Restore (task = 0x%4.4x)", task); uint32_t i = 0; @@ -501,7 +502,7 @@ MachException::PortInfo::Restore (task_t task) { err = ::task_set_exception_ports (task, masks[i], ports[i], behaviors[i], flavors[i]); if (log || err.Fail()) - err.PutToLog(log, "::task_set_exception_ports ( task = 0x%4.4x, exception_mask = 0x%8.8x, new_port = 0x%4.4x, behavior = 0x%8.8x, new_flavor = 0x%8.8x )", task, masks[i], ports[i], behaviors[i], flavors[i]); + err.PutToLog(log.get(), "::task_set_exception_ports ( task = 0x%4.4x, exception_mask = 0x%8.8x, new_port = 0x%4.4x, behavior = 0x%8.8x, new_flavor = 0x%8.8x )", task, masks[i], ports[i], behaviors[i], flavors[i]); if (err.Fail()) break; 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 4d6d3b1c792..6eec701be2b 100644 --- a/lldb/source/Plugins/Process/MacOSX-User/source/MacOSX/MachTask.cpp +++ b/lldb/source/Plugins/Process/MacOSX-User/source/MacOSX/MachTask.cpp @@ -65,9 +65,9 @@ MachTask::Suspend() Error err; task_t task = GetTaskPort(); err = ::task_suspend (task); - Log *log = ProcessMacOSXLog::GetLogIfAllCategoriesSet (PD_LOG_TASK); + LogSP log (ProcessMacOSXLog::GetLogIfAllCategoriesSet (PD_LOG_TASK)); if (log || err.Fail()) - err.PutToLog(log, "::task_suspend ( target_task = 0x%4.4x )", task); + err.PutToLog(log.get(), "::task_suspend ( target_task = 0x%4.4x )", task); return err.GetError(); } @@ -81,9 +81,9 @@ MachTask::Resume() Error err; task_t task = GetTaskPort(); err = ::task_resume (task); - Log *log = ProcessMacOSXLog::GetLogIfAllCategoriesSet (PD_LOG_TASK); + LogSP log (ProcessMacOSXLog::GetLogIfAllCategoriesSet (PD_LOG_TASK)); if (log || err.Fail()) - err.PutToLog(log, "::task_resume ( target_task = 0x%4.4x )", task); + err.PutToLog(log.get(), "::task_resume ( target_task = 0x%4.4x )", task); return err.GetError(); } @@ -159,14 +159,14 @@ MachTask::ReadMemory (lldb::addr_t addr, void *buf, size_t size, Error& error) if (task != TASK_NULL) { n = m_vm_memory.Read(task, addr, buf, size, error); - Log *log = ProcessMacOSXLog::GetLogIfAllCategoriesSet (PD_LOG_MEMORY); + LogSP log (ProcessMacOSXLog::GetLogIfAllCategoriesSet (PD_LOG_MEMORY)); if (log) { log->Printf ("MachTask::ReadMemory ( addr = 0x%16.16llx, size = %zu, buf = %8.8p) => %u bytes read", (uint64_t)addr, size, buf, n); if (log->GetMask().Test(PD_LOG_MEMORY_DATA_LONG) || (log->GetMask().Test(PD_LOG_MEMORY_DATA_SHORT) && size <= 8)) { DataExtractor data((uint8_t*)buf, n, eByteOrderHost, 4); - data.PutToLog(log, 0, n, addr, 16, DataExtractor::TypeUInt8); + data.PutToLog(log.get(), 0, n, addr, 16, DataExtractor::TypeUInt8); } } } @@ -185,14 +185,14 @@ MachTask::WriteMemory (lldb::addr_t addr, const void *buf, size_t size, Error& e if (task != TASK_NULL) { n = m_vm_memory.Write(task, addr, buf, size, error); - Log *log = ProcessMacOSXLog::GetLogIfAllCategoriesSet (PD_LOG_MEMORY); + LogSP log (ProcessMacOSXLog::GetLogIfAllCategoriesSet (PD_LOG_MEMORY)); if (log) { log->Printf ("MachTask::WriteMemory ( addr = 0x%16.16llx, size = %zu, buf = %8.8p) => %u bytes written", (uint64_t)addr, size, buf, n); if (log->GetMask().Test(PD_LOG_MEMORY_DATA_LONG) || (log->GetMask().Test(PD_LOG_MEMORY_DATA_SHORT) && size <= 8)) { DataExtractor data((uint8_t*)buf, n, eByteOrderHost, 4); - data.PutToLog(log, 0, n, addr, 16, DataExtractor::TypeUInt8); + data.PutToLog(log.get(), 0, n, addr, 16, DataExtractor::TypeUInt8); } } } @@ -212,7 +212,7 @@ MachTask::AllocateMemory (size_t size, uint32_t permissions, Error& error) kern_return_t kret; mach_vm_address_t addr; - Log *log = ProcessMacOSXLog::GetLogIfAllCategoriesSet (PD_LOG_MEMORY); + LogSP log (ProcessMacOSXLog::GetLogIfAllCategoriesSet (PD_LOG_MEMORY)); kret = ::mach_vm_allocate (GetTaskPort(), &addr, size, TRUE); if (kret == KERN_SUCCESS) @@ -295,10 +295,10 @@ MachTask::GetTaskPortForProcessID (lldb::pid_t pid, Error &err) { mach_port_t task_self = mach_task_self (); err = ::task_for_pid ( task_self, pid, &task); - Log *log = ProcessMacOSXLog::GetLogIfAllCategoriesSet (PD_LOG_TASK); + LogSP log (ProcessMacOSXLog::GetLogIfAllCategoriesSet (PD_LOG_TASK)); if (log || err.Fail()) { - err.PutToLog(log, "::task_for_pid ( target_tport = 0x%4.4x, pid = %d, task => 0x%4.4x ) %u/%u %u/%u", task_self, pid, task, getuid(), geteuid(), getgid(), getegid()); + err.PutToLog(log.get(), "::task_for_pid ( target_tport = 0x%4.4x, pid = %d, task => 0x%4.4x ) %u/%u %u/%u", task_self, pid, task, getuid(), geteuid(), getgid(), getegid()); } } return task; @@ -326,9 +326,9 @@ MachTask::BasicInfo(task_t task, struct task_basic_info *info) Error err; mach_msg_type_number_t count = TASK_BASIC_INFO_COUNT; err = ::task_info (task, TASK_BASIC_INFO, (task_info_t)info, &count); - Log *log = ProcessMacOSXLog::GetLogIfAllCategoriesSet (PD_LOG_TASK); + LogSP log (ProcessMacOSXLog::GetLogIfAllCategoriesSet (PD_LOG_TASK)); if (log || err.Fail()) - err.PutToLog(log, "::task_info ( target_task = 0x%4.4x, flavor = TASK_BASIC_INFO, task_info_out => %p, task_info_outCnt => %u )", task, info, count); + err.PutToLog(log.get(), "::task_info ( target_task = 0x%4.4x, flavor = TASK_BASIC_INFO, task_info_out => %p, task_info_outCnt => %u )", task, info, count); if (log && log->GetMask().Test(PD_LOG_VERBOSE) && err.Success()) { float user = (float)info->user_time.seconds + (float)info->user_time.microseconds / 1000000.0f; @@ -371,7 +371,7 @@ MachTask::IsValid (task_t task) bool MachTask::StartExceptionThread(Error &err) { - Log *log = ProcessMacOSXLog::GetLogIfAllCategoriesSet (PD_LOG_EXCEPTIONS); + LogSP log (ProcessMacOSXLog::GetLogIfAllCategoriesSet (PD_LOG_EXCEPTIONS)); if (log) log->Printf ("MachTask::%s ( )", __FUNCTION__); @@ -384,7 +384,7 @@ MachTask::StartExceptionThread(Error &err) // Allocate an exception port that we will use to track our child process err = ::mach_port_allocate (task_self, MACH_PORT_RIGHT_RECEIVE, &m_exception_port); if (log || err.Fail()) - err.PutToLog(log, "::mach_port_allocate (task_self=0x%4.4x, MACH_PORT_RIGHT_RECEIVE, &m_exception_port => 0x%4.4x)", + err.PutToLog(log.get(), "::mach_port_allocate (task_self=0x%4.4x, MACH_PORT_RIGHT_RECEIVE, &m_exception_port => 0x%4.4x)", task_self, m_exception_port); if (err.Fail()) return false; @@ -392,7 +392,7 @@ MachTask::StartExceptionThread(Error &err) // Add the ability to send messages on the new exception port err = ::mach_port_insert_right (task_self, m_exception_port, m_exception_port, MACH_MSG_TYPE_MAKE_SEND); if (log || err.Fail()) - err.PutToLog(log, "::mach_port_insert_right (task_self=0x%4.4x, m_exception_port=0x%4.4x, m_exception_port=0x%4.4x, MACH_MSG_TYPE_MAKE_SEND)", + err.PutToLog(log.get(), "::mach_port_insert_right (task_self=0x%4.4x, m_exception_port=0x%4.4x, m_exception_port=0x%4.4x, MACH_MSG_TYPE_MAKE_SEND)", task_self, m_exception_port, m_exception_port); if (err.Fail()) return false; @@ -403,7 +403,7 @@ MachTask::StartExceptionThread(Error &err) // Set the ability to get all exceptions on this port err = ::task_set_exception_ports (task, EXC_MASK_ALL, m_exception_port, EXCEPTION_DEFAULT | MACH_EXCEPTION_CODES, THREAD_STATE_NONE); if (log || err.Fail()) - err.PutToLog(log, "::task_set_exception_ports (task, EXC_MASK_ALL, m_exception_port, EXCEPTION_DEFAULT | MACH_EXCEPTION_CODES, THREAD_STATE_NONE)"); + err.PutToLog(log.get(), "::task_set_exception_ports (task, EXC_MASK_ALL, m_exception_port, EXCEPTION_DEFAULT | MACH_EXCEPTION_CODES, THREAD_STATE_NONE)"); if (err.Fail()) return false; @@ -427,7 +427,7 @@ MachTask::ShutDownExceptionThread() err = RestoreExceptionPortInfo(); - Log *log = ProcessMacOSXLog::GetLogIfAllCategoriesSet (PD_LOG_EXCEPTIONS); + LogSP log (ProcessMacOSXLog::GetLogIfAllCategoriesSet (PD_LOG_EXCEPTIONS)); // NULL our our exception port and let our exception thread exit mach_port_t exception_port = m_exception_port; @@ -435,17 +435,17 @@ MachTask::ShutDownExceptionThread() Host::ThreadCancel (m_exception_thread, &err); if (log || err.Fail()) - err.PutToLog(log, "Host::ThreadCancel ( thread = %p )", m_exception_thread); + err.PutToLog(log.get(), "Host::ThreadCancel ( thread = %p )", m_exception_thread); Host::ThreadJoin (m_exception_thread, NULL, &err); if (log || err.Fail()) - err.PutToLog(log, "Host::ThreadJoin ( thread = %p, result_ptr = NULL)", m_exception_thread); + err.PutToLog(log.get(), "Host::ThreadJoin ( thread = %p, result_ptr = NULL)", m_exception_thread); // Deallocate our exception port that we used to track our child process mach_port_t task_self = mach_task_self (); err = ::mach_port_deallocate (task_self, exception_port); if (log || err.Fail()) - err.PutToLog(log, "::mach_port_deallocate ( task = 0x%4.4x, name = 0x%4.4x )", task_self, exception_port); + err.PutToLog(log.get(), "::mach_port_deallocate ( task = 0x%4.4x, name = 0x%4.4x )", task_self, exception_port); exception_port = NULL; Clear(); @@ -461,7 +461,7 @@ MachTask::ExceptionThread (void *arg) MachTask *mach_task = (MachTask*) arg; ProcessMacOSX *mach_proc = mach_task->Process(); - Log *log = ProcessMacOSXLog::GetLogIfAllCategoriesSet (PD_LOG_EXCEPTIONS); + LogSP log (ProcessMacOSXLog::GetLogIfAllCategoriesSet (PD_LOG_EXCEPTIONS)); if (log) log->Printf ("MachTask::%s (arg = %p) thread starting...", __FUNCTION__, arg); diff --git a/lldb/source/Plugins/Process/MacOSX-User/source/MacOSX/MachThreadContext_arm.cpp b/lldb/source/Plugins/Process/MacOSX-User/source/MacOSX/MachThreadContext_arm.cpp index 827cd28ca55..b61cd541c73 100644 --- a/lldb/source/Plugins/Process/MacOSX-User/source/MacOSX/MachThreadContext_arm.cpp +++ b/lldb/source/Plugins/Process/MacOSX-User/source/MacOSX/MachThreadContext_arm.cpp @@ -335,7 +335,7 @@ kern_return_t MachThreadContext_arm::EnableHardwareSingleStep (bool enable) { Error err; - Log *log = ProcessMacOSXLog::GetLogIfAllCategoriesSet (PD_LOG_STEP); + LogSP log (ProcessMacOSXLog::GetLogIfAllCategoriesSet (PD_LOG_STEP)); if (log) log->Printf("%s( enable = %d )", __FUNCTION__, enable); diff --git a/lldb/source/Plugins/Process/MacOSX-User/source/MacOSX/MachVMMemory.cpp b/lldb/source/Plugins/Process/MacOSX-User/source/MacOSX/MachVMMemory.cpp index c91af3c3596..59ff66dadc2 100644 --- a/lldb/source/Plugins/Process/MacOSX-User/source/MacOSX/MachVMMemory.cpp +++ b/lldb/source/Plugins/Process/MacOSX-User/source/MacOSX/MachVMMemory.cpp @@ -14,6 +14,7 @@ #include "MachVMRegion.h" #include "ProcessMacOSXLog.h" +using namespace lldb; using namespace lldb_private; MachVMMemory::MachVMMemory() : @@ -73,17 +74,17 @@ MachVMMemory::Read(task_t task, lldb::addr_t address, void *data, size_t data_co mach_msg_type_number_t curr_bytes_read = 0; vm_offset_t vm_memory = NULL; error = ::mach_vm_read (task, curr_addr, curr_size, &vm_memory, &curr_bytes_read); - Log *log = ProcessMacOSXLog::GetLogIfAllCategoriesSet (PD_LOG_MEMORY|PD_LOG_VERBOSE); + LogSP log (ProcessMacOSXLog::GetLogIfAllCategoriesSet (PD_LOG_MEMORY|PD_LOG_VERBOSE)); if (log || error.Fail()) - error.PutToLog (log, "::mach_vm_read (task = 0x%4.4x, addr = 0x%8.8llx, size = %llu, data => %8.8p, dataCnt => %i)", task, (uint64_t)curr_addr, (uint64_t)curr_size, vm_memory, curr_bytes_read); + error.PutToLog (log.get(), "::mach_vm_read (task = 0x%4.4x, addr = 0x%8.8llx, size = %llu, data => %8.8p, dataCnt => %i)", task, (uint64_t)curr_addr, (uint64_t)curr_size, vm_memory, curr_bytes_read); if (error.Success()) { if (curr_bytes_read != curr_size) { if (log) - error.PutToLog (log, "::mach_vm_read (task = 0x%4.4x, addr = 0x%8.8llx, size = %llu, data => %8.8p, dataCnt=>%i) only read %u of %llu bytes", task, (uint64_t)curr_addr, (uint64_t)curr_size, vm_memory, curr_bytes_read, curr_bytes_read, (uint64_t)curr_size); + error.PutToLog (log.get(), "::mach_vm_read (task = 0x%4.4x, addr = 0x%8.8llx, size = %llu, data => %8.8p, dataCnt=>%i) only read %u of %llu bytes", task, (uint64_t)curr_addr, (uint64_t)curr_size, vm_memory, curr_bytes_read, curr_bytes_read, (uint64_t)curr_size); } ::memcpy (curr_data, (void *)vm_memory, curr_bytes_read); ::vm_deallocate (mach_task_self (), vm_memory, curr_bytes_read); @@ -168,16 +169,16 @@ MachVMMemory::WriteRegion(task_t task, const lldb::addr_t address, const void *d { mach_msg_type_number_t curr_data_count = MaxBytesLeftInPage(curr_addr, data_count - total_bytes_written); error = ::mach_vm_write (task, curr_addr, (pointer_t) curr_data, curr_data_count); - Log *log = ProcessMacOSXLog::GetLogIfAllCategoriesSet (PD_LOG_MEMORY); + LogSP log (ProcessMacOSXLog::GetLogIfAllCategoriesSet (PD_LOG_MEMORY)); if (log || error.Fail()) - error.PutToLog (log, "::mach_vm_write ( task = 0x%4.4x, addr = 0x%8.8llx, data = %8.8p, dataCnt = %u )", task, (uint64_t)curr_addr, curr_data, curr_data_count); + error.PutToLog (log.get(), "::mach_vm_write ( task = 0x%4.4x, addr = 0x%8.8llx, data = %8.8p, dataCnt = %u )", task, (uint64_t)curr_addr, curr_data, curr_data_count); #if defined (__powerpc__) || defined (__ppc__) vm_machine_attribute_val_t mattr_value = MATTR_VAL_CACHE_FLUSH; error = ::vm_machine_attribute (task, curr_addr, curr_data_count, MATTR_CACHE, &mattr_value); if (log || error.Fail()) - error.Log(log, "::vm_machine_attribute ( task = 0x%4.4x, addr = 0x%8.8llx, size = %u, attr = MATTR_CACHE, mattr_value => MATTR_VAL_CACHE_FLUSH )", task, (uint64_t)curr_addr, curr_data_count); + error.Log(log.get(), "::vm_machine_attribute ( task = 0x%4.4x, addr = 0x%8.8llx, size = %u, attr = MATTR_CACHE, mattr_value => MATTR_VAL_CACHE_FLUSH )", task, (uint64_t)curr_addr, curr_data_count); #endif if (error.Success()) diff --git a/lldb/source/Plugins/Process/MacOSX-User/source/MacOSX/MachVMRegion.cpp b/lldb/source/Plugins/Process/MacOSX-User/source/MacOSX/MachVMRegion.cpp index fd8636f5786..00a58941a15 100644 --- a/lldb/source/Plugins/Process/MacOSX-User/source/MacOSX/MachVMRegion.cpp +++ b/lldb/source/Plugins/Process/MacOSX-User/source/MacOSX/MachVMRegion.cpp @@ -12,6 +12,7 @@ #include "MachVMRegion.h" #include "ProcessMacOSXLog.h" +using namespace lldb; using namespace lldb_private; MachVMRegion::MachVMRegion(task_t task) : @@ -61,7 +62,7 @@ MachVMRegion::SetProtections(mach_vm_address_t addr, mach_vm_size_t size, vm_pro prot_size = end_addr - addr; - Log *log = ProcessMacOSXLog::GetLogIfAllCategoriesSet (PD_LOG_MEMORY_PROTECTIONS); + LogSP log (ProcessMacOSXLog::GetLogIfAllCategoriesSet (PD_LOG_MEMORY_PROTECTIONS)); if (prot_size > 0) { if (prot == (m_curr_protection & VM_PROT_ALL)) @@ -75,13 +76,13 @@ MachVMRegion::SetProtections(mach_vm_address_t addr, mach_vm_size_t size, vm_pro { m_err = ::mach_vm_protect (m_task, addr, prot_size, 0, prot); if (log || m_err.Fail()) - m_err.PutToLog(log, "::mach_vm_protect ( task = 0x%4.4x, addr = 0x%8.8llx, size = %llu, set_max = %i, prot = %u )", m_task, (uint64_t)addr, (uint64_t)prot_size, 0, prot); + m_err.PutToLog(log.get(), "::mach_vm_protect ( task = 0x%4.4x, addr = 0x%8.8llx, size = %llu, set_max = %i, prot = %u )", m_task, (uint64_t)addr, (uint64_t)prot_size, 0, prot); if (m_err.Fail()) { // Try again with the ability to create a copy on write region m_err = ::mach_vm_protect (m_task, addr, prot_size, 0, prot | VM_PROT_COPY); if (log || m_err.Fail()) - m_err.PutToLog(log, "::mach_vm_protect ( task = 0x%4.4x, addr = 0x%8.8llx, size = %llu, set_max = %i, prot = %u )", m_task, (uint64_t)addr, (uint64_t)prot_size, 0, prot | VM_PROT_COPY); + m_err.PutToLog(log.get(), "::mach_vm_protect ( task = 0x%4.4x, addr = 0x%8.8llx, size = %llu, set_max = %i, prot = %u )", m_task, (uint64_t)addr, (uint64_t)prot_size, 0, prot | VM_PROT_COPY); } if (m_err.Success()) { @@ -106,9 +107,9 @@ MachVMRegion::RestoreProtections() if (m_curr_protection != m_data.protection && m_protection_size > 0) { m_err = ::mach_vm_protect (m_task, m_protection_addr, m_protection_size, 0, m_data.protection); - Log *log = ProcessMacOSXLog::GetLogIfAllCategoriesSet (PD_LOG_MEMORY_PROTECTIONS); + LogSP log (ProcessMacOSXLog::GetLogIfAllCategoriesSet (PD_LOG_MEMORY_PROTECTIONS)); if (log || m_err.Fail()) - m_err.PutToLog(log, "::mach_vm_protect ( task = 0x%4.4x, addr = 0x%8.8llx, size = %llu, set_max = %i, prot = %u )", m_task, (uint64_t)m_protection_addr, (uint64_t)m_protection_size, 0, m_data.protection); + m_err.PutToLog(log.get(), "::mach_vm_protect ( task = 0x%4.4x, addr = 0x%8.8llx, size = %llu, set_max = %i, prot = %u )", m_task, (uint64_t)m_protection_addr, (uint64_t)m_protection_size, 0, m_data.protection); if (m_err.Success()) { m_protection_size = 0; @@ -137,9 +138,9 @@ MachVMRegion::GetRegionForAddress(lldb::addr_t addr) mach_msg_type_number_t info_size = kRegionInfoSize; assert(sizeof(info_size) == 4); m_err = ::mach_vm_region_recurse (m_task, &m_start, &m_size, &m_depth, (vm_region_recurse_info_t)&m_data, &info_size); - Log *log = ProcessMacOSXLog::GetLogIfAllCategoriesSet (PD_LOG_MEMORY_PROTECTIONS); + LogSP log (ProcessMacOSXLog::GetLogIfAllCategoriesSet (PD_LOG_MEMORY_PROTECTIONS)); if (log || m_err.Fail()) - m_err.PutToLog(log, "::mach_vm_region_recurse ( task = 0x%4.4x, address => 0x%8.8llx, size => %llu, nesting_depth => %d, info => %p, infoCnt => %d) addr = 0x%8.8llx ", m_task, (uint64_t)m_start, (uint64_t)m_size, m_depth, &m_data, info_size, (uint64_t)addr); + m_err.PutToLog(log.get(), "::mach_vm_region_recurse ( task = 0x%4.4x, address => 0x%8.8llx, size => %llu, nesting_depth => %d, info => %p, infoCnt => %d) addr = 0x%8.8llx ", m_task, (uint64_t)m_start, (uint64_t)m_size, m_depth, &m_data, info_size, (uint64_t)addr); if (m_err.Fail()) { return false; diff --git a/lldb/source/Plugins/Process/MacOSX-User/source/ProcessMacOSX.cpp b/lldb/source/Plugins/Process/MacOSX-User/source/ProcessMacOSX.cpp index 3288fc80b0d..d20077fb5c6 100644 --- a/lldb/source/Plugins/Process/MacOSX-User/source/ProcessMacOSX.cpp +++ b/lldb/source/Plugins/Process/MacOSX-User/source/ProcessMacOSX.cpp @@ -108,7 +108,7 @@ using namespace lldb_private; //{ // const lldb::pid_t pid = *((lldb::user_id_t *)pid_ptr); // -// Log *log = ProcessMacOSXLog::GetLogIfAllCategoriesSet (PD_LOG_THREAD); +// LogSP log (ProcessMacOSXLog::GetLogIfAllCategoriesSet (PD_LOG_THREAD)); // // if (log) // log->Printf ("ProcessMacOSX::%s (arg = %p) thread starting...", __FUNCTION__, pid_ptr); @@ -357,7 +357,7 @@ ProcessMacOSX::DoAttachToProcessWithID (lldb::pid_t attach_pid) // figure out a good way to determine the arch of what we are attaching to m_arch_spec = m_target.GetArchitecture(); - Log *log = ProcessMacOSXLog::GetLogIfAllCategoriesSet (PD_LOG_PROCESS); + LogSP log (ProcessMacOSXLog::GetLogIfAllCategoriesSet (PD_LOG_PROCESS)); if (attach_pid != LLDB_INVALID_PROCESS_ID) { SetID(attach_pid); @@ -583,7 +583,7 @@ uint32_t ProcessMacOSX::UpdateThreadListIfNeeded () { // locker will keep a mutex locked until it goes out of scope - Log *log = ProcessMacOSXLog::GetLogIfAllCategoriesSet (PD_LOG_THREAD); + LogSP log (ProcessMacOSXLog::GetLogIfAllCategoriesSet (PD_LOG_THREAD)); if (log && log->GetMask().Test(PD_LOG_VERBOSE)) log->Printf ("ProcessMacOSX::%s (pid = %4.4x)", __FUNCTION__, GetID()); @@ -597,7 +597,7 @@ ProcessMacOSX::UpdateThreadListIfNeeded () Error err(::task_threads (task, &thread_list, &thread_list_count), eErrorTypeMachKernel); if (log || err.Fail()) - err.PutToLog(log, "::task_threads ( task = 0x%4.4x, thread_list => %p, thread_list_count => %u )", task, thread_list, thread_list_count); + err.PutToLog(log.get(), "::task_threads ( task = 0x%4.4x, thread_list => %p, thread_list_count => %u )", task, thread_list, thread_list_count); if (err.GetError() == KERN_SUCCESS && thread_list_count > 0) { @@ -651,7 +651,7 @@ ProcessMacOSX::RefreshStateAfterStop () m_thread_list.RefreshStateAfterStop(); // Let each thread know of any exceptions - Log *log = ProcessMacOSXLog::GetLogIfAllCategoriesSet(PD_LOG_EXCEPTIONS); + LogSP log (ProcessMacOSXLog::GetLogIfAllCategoriesSet(PD_LOG_EXCEPTIONS)); task_t task = Task().GetTaskPort(); size_t i; for (i=0; i<m_exception_messages.size(); ++i) @@ -668,7 +668,7 @@ ProcessMacOSX::RefreshStateAfterStop () } } if (log) - m_exception_messages[i].PutToLog(log); + m_exception_messages[i].PutToLog(log.get()); } } @@ -697,7 +697,7 @@ Error ProcessMacOSX::DoSIGSTOP (bool clear_all_breakpoints) { Error error; - Log *log = ProcessMacOSXLog::GetLogIfAllCategoriesSet(PD_LOG_PROCESS); + LogSP log (ProcessMacOSXLog::GetLogIfAllCategoriesSet(PD_LOG_PROCESS)); if (log) log->Printf ("ProcessMacOSX::DoSIGSTOP()"); @@ -730,7 +730,7 @@ ProcessMacOSX::DoSIGSTOP (bool clear_all_breakpoints) error.SetErrorToErrno(); if (error.Fail()) - error.PutToLog(log, "::kill (pid = %i, SIGSTOP)", pid); + error.PutToLog(log.get(), "::kill (pid = %i, SIGSTOP)", pid); timeout_time = TimeValue::Now(); timeout_time.OffsetWithSeconds(2); @@ -781,7 +781,7 @@ ProcessMacOSX::DoSIGSTOP (bool clear_all_breakpoints) log = ProcessMacOSXLog::GetLogIfAllCategoriesSet(PD_LOG_PROCESS); if (log || error.Fail()) - error.PutToLog(log, "ProcessMacOSX::DoSIGSTOP() ::kill (pid = %i, SIGSTOP)", pid); + error.PutToLog(log.get(), "ProcessMacOSX::DoSIGSTOP() ::kill (pid = %i, SIGSTOP)", pid); error = PrivateResume(LLDB_INVALID_THREAD_ID); @@ -823,7 +823,7 @@ Error ProcessMacOSX::DoDestroy () { Error error; - Log *log = ProcessMacOSXLog::GetLogIfAllCategoriesSet(PD_LOG_PROCESS); + LogSP log (ProcessMacOSXLog::GetLogIfAllCategoriesSet(PD_LOG_PROCESS)); if (log) log->Printf ("ProcessMacOSX::DoDestroy()"); @@ -863,7 +863,7 @@ ProcessMacOSX::DoDestroy () error.SetErrorToErrno(); if (log || error.Fail()) - error.PutToLog (log, "::ptrace (PT_KILL, %u, 0, 0)", pid); + error.PutToLog (log.get(), "::ptrace (PT_KILL, %u, 0, 0)", pid); // Resume our task and let the SIGKILL do its thing. The thread named // "ProcessMacOSX::WaitForChildProcessToExit(void*)" will catch the @@ -1003,7 +1003,7 @@ ProcessMacOSX::EnableBreakpoint (BreakpointSite *bp_site) const lldb::addr_t addr = bp_site->GetLoadAddress(); const lldb::user_id_t site_id = bp_site->GetID(); - Log *log = ProcessMacOSXLog::GetLogIfAllCategoriesSet(PD_LOG_BREAKPOINTS); + LogSP log (ProcessMacOSXLog::GetLogIfAllCategoriesSet(PD_LOG_BREAKPOINTS)); if (log) log->Printf ("ProcessMacOSX::EnableBreakpoint (site_id = %d) addr = 0x%8.8llx", site_id, (uint64_t)addr); @@ -1044,7 +1044,7 @@ ProcessMacOSX::DisableBreakpoint (BreakpointSite *bp_site) const lldb::addr_t addr = bp_site->GetLoadAddress(); const lldb::user_id_t site_id = bp_site->GetID(); - Log *log = ProcessMacOSXLog::GetLogIfAllCategoriesSet(PD_LOG_BREAKPOINTS); + LogSP log (ProcessMacOSXLog::GetLogIfAllCategoriesSet(PD_LOG_BREAKPOINTS)); if (log) log->Printf ("ProcessMacOSX::DisableBreakpoint (site_id = %d) addr = 0x%8.8llx", site_id, (uint64_t)addr); @@ -1066,7 +1066,7 @@ ProcessMacOSX::EnableWatchpoint (WatchpointLocation *wp) { lldb::user_id_t watchID = wp->GetID(); lldb::addr_t addr = wp->GetLoadAddress(); - Log *log = ProcessMacOSXLog::GetLogIfAllCategoriesSet(PD_LOG_WATCHPOINTS); + LogSP log (ProcessMacOSXLog::GetLogIfAllCategoriesSet(PD_LOG_WATCHPOINTS)); if (log) log->Printf ("ProcessMacOSX::EnableWatchpoint(watchID = %d)", watchID); if (wp->IsEnabled()) @@ -1092,7 +1092,7 @@ ProcessMacOSX::DisableWatchpoint (WatchpointLocation *wp) { lldb::user_id_t watchID = wp->GetID(); - Log *log = ProcessMacOSXLog::GetLogIfAllCategoriesSet(PD_LOG_WATCHPOINTS); + LogSP log (ProcessMacOSXLog::GetLogIfAllCategoriesSet(PD_LOG_WATCHPOINTS)); lldb::addr_t addr = wp->GetLoadAddress(); if (log) @@ -1222,7 +1222,7 @@ ProcessMacOSX::STDIOThread(void *arg) { ProcessMacOSX *proc = (ProcessMacOSX*) arg; - Log *log = ProcessMacOSXLog::GetLogIfAllCategoriesSet (PD_LOG_PROCESS); + LogSP log (ProcessMacOSXLog::GetLogIfAllCategoriesSet (PD_LOG_PROCESS)); if (log) log->Printf ("ProcessMacOSX::%s (arg = %p) thread starting...", __FUNCTION__, arg); @@ -1270,7 +1270,7 @@ ProcessMacOSX::STDIOThread(void *arg) if (log) { err.SetError (select_errno, eErrorTypePOSIX); - err.LogIfError(log, "select (nfds, &read_fds, NULL, NULL, NULL) => %d", num_set_fds); + err.LogIfError(log.get(), "select (nfds, &read_fds, NULL, NULL, NULL) => %d", num_set_fds); } switch (select_errno) @@ -1359,13 +1359,13 @@ Error ProcessMacOSX::DoSignal (int signal) { Error error; - Log *log = ProcessMacOSXLog::GetLogIfAllCategoriesSet(PD_LOG_PROCESS); + LogSP log (ProcessMacOSXLog::GetLogIfAllCategoriesSet(PD_LOG_PROCESS)); if (log) log->Printf ("ProcessMacOSX::DoSignal (signal = %d)", signal); if (::kill (GetID(), signal) != 0) { error.SetErrorToErrno(); - error.LogIfError(log, "ProcessMacOSX::DoSignal (%d)", signal); + error.LogIfError(log.get(), "ProcessMacOSX::DoSignal (%d)", signal); } return error; } @@ -1374,7 +1374,7 @@ ProcessMacOSX::DoSignal (int signal) Error ProcessMacOSX::DoDetach() { - Log *log = ProcessMacOSXLog::GetLogIfAllCategoriesSet(PD_LOG_PROCESS); + LogSP log (ProcessMacOSXLog::GetLogIfAllCategoriesSet(PD_LOG_PROCESS)); if (log) log->Printf ("ProcessMacOSX::DoDetach()"); @@ -1404,7 +1404,7 @@ ProcessMacOSX::DoDetach() error.SetErrorToErrno(); if (log || error.Fail()) - error.PutToLog(log, "::ptrace (PT_DETACH, %u, (caddr_t)1, 0)", pid); + error.PutToLog(log.get(), "::ptrace (PT_DETACH, %u, (caddr_t)1, 0)", pid); // Resume our task Task().Resume(); @@ -1429,7 +1429,7 @@ ProcessMacOSX::ReplyToAllExceptions() Mutex::Locker locker(m_exception_messages_mutex); if (m_exception_messages.empty() == false) { - Log *log = ProcessMacOSXLog::GetLogIfAllCategoriesSet(PD_LOG_EXCEPTIONS); + LogSP log (ProcessMacOSXLog::GetLogIfAllCategoriesSet(PD_LOG_EXCEPTIONS)); MachException::Message::iterator pos; MachException::Message::iterator begin = m_exception_messages.begin(); @@ -1448,7 +1448,7 @@ ProcessMacOSX::ReplyToAllExceptions() if (curr_error.Fail() && error.Success()) error = curr_error; - error.LogIfError(log, "Error replying to exception"); + error.LogIfError(log.get(), "Error replying to exception"); } // Erase all exception message as we should have used and replied @@ -1577,7 +1577,7 @@ ProcessMacOSX::LaunchForDebug if (launch_type == eLaunchDefault) launch_type = eLaunchPosixSpawn; - Log *log = ProcessMacOSXLog::GetLogIfAllCategoriesSet (PD_LOG_PROCESS); + LogSP log (ProcessMacOSXLog::GetLogIfAllCategoriesSet (PD_LOG_PROCESS)); if (log) log->Printf ("%s( path = '%s', argv = %p, envp = %p, launch_type = %u, flags = %x )", __FUNCTION__, path, argv, envp, launch_type, flags); @@ -1655,7 +1655,7 @@ ProcessMacOSX::LaunchForDebug log = ProcessMacOSXLog::GetLogIfAllCategoriesSet (PD_LOG_PROCESS); if (launch_err.Fail() || log) - launch_err.PutToLog(log, "::ptrace (PT_ATTACHEXC, pid = %i, 0, 0 )", pid); + launch_err.PutToLog(log.get(), "::ptrace (PT_ATTACHEXC, pid = %i, 0, 0 )", pid); if (launch_err.Success()) m_flags.Set (eFlagsAttached); @@ -1698,14 +1698,14 @@ ProcessMacOSX::PosixSpawnChildForPTraceDebugging { posix_spawnattr_t attr; short flags; - Log *log = ProcessMacOSXLog::GetLogIfAllCategoriesSet (PD_LOG_PROCESS); + LogSP log (ProcessMacOSXLog::GetLogIfAllCategoriesSet (PD_LOG_PROCESS)); Error local_err; // Errors that don't affect the spawning. if (log) log->Printf ("%s ( path='%s', argv=%p, envp=%p, process )", __FUNCTION__, path, argv, envp); err.SetError( ::posix_spawnattr_init (&attr), eErrorTypePOSIX); if (err.Fail() || log) - err.PutToLog(log, "::posix_spawnattr_init ( &attr )"); + err.PutToLog(log.get(), "::posix_spawnattr_init ( &attr )"); if (err.Fail()) return LLDB_INVALID_PROCESS_ID; @@ -1715,7 +1715,7 @@ ProcessMacOSX::PosixSpawnChildForPTraceDebugging err.SetError( ::posix_spawnattr_setflags (&attr, flags), eErrorTypePOSIX); if (err.Fail() || log) - err.PutToLog(log, "::posix_spawnattr_setflags ( &attr, POSIX_SPAWN_START_SUSPENDED%s )", disable_aslr ? " | _POSIX_SPAWN_DISABLE_ASLR" : ""); + err.PutToLog(log.get(), "::posix_spawnattr_setflags ( &attr, POSIX_SPAWN_START_SUSPENDED%s )", disable_aslr ? " | _POSIX_SPAWN_DISABLE_ASLR" : ""); if (err.Fail()) return LLDB_INVALID_PROCESS_ID; @@ -1732,7 +1732,7 @@ ProcessMacOSX::PosixSpawnChildForPTraceDebugging size_t ocount = 0; err.SetError( ::posix_spawnattr_setbinpref_np (&attr, 1, &cpu, &ocount), eErrorTypePOSIX); if (err.Fail() || log) - err.PutToLog(log, "::posix_spawnattr_setbinpref_np ( &attr, 1, cpu_type = 0x%8.8x, count => %zu )", cpu, ocount); + err.PutToLog(log.get(), "::posix_spawnattr_setbinpref_np ( &attr, 1, cpu_type = 0x%8.8x, count => %zu )", cpu, ocount); if (err.Fail() != 0 || ocount != 1) return LLDB_INVALID_PROCESS_ID; @@ -1747,7 +1747,7 @@ ProcessMacOSX::PosixSpawnChildForPTraceDebugging err.SetError( ::posix_spawn_file_actions_init (&file_actions), eErrorTypePOSIX); int file_actions_valid = err.Success(); if (!file_actions_valid || log) - err.PutToLog(log, "::posix_spawn_file_actions_init ( &file_actions )"); + err.PutToLog(log.get(), "::posix_spawn_file_actions_init ( &file_actions )"); Error stdio_err; lldb::pid_t pid = LLDB_INVALID_PROCESS_ID; if (file_actions_valid) @@ -1760,21 +1760,21 @@ ProcessMacOSX::PosixSpawnChildForPTraceDebugging { stdio_err.SetError( ::posix_spawn_file_actions_addopen(&file_actions, STDERR_FILENO, stderr_path, O_RDWR, 0), eErrorTypePOSIX); if (stdio_err.Fail() || log) - stdio_err.PutToLog(log, "::posix_spawn_file_actions_addopen ( &file_actions, filedes = STDERR_FILENO, path = '%s', oflag = O_RDWR, mode = 0 )", stderr_path); + stdio_err.PutToLog(log.get(), "::posix_spawn_file_actions_addopen ( &file_actions, filedes = STDERR_FILENO, path = '%s', oflag = O_RDWR, mode = 0 )", stderr_path); } if (stdin_path != NULL && stdin_path[0]) { stdio_err.SetError( ::posix_spawn_file_actions_addopen(&file_actions, STDIN_FILENO, stdin_path, O_RDONLY, 0), eErrorTypePOSIX); if (stdio_err.Fail() || log) - stdio_err.PutToLog(log, "::posix_spawn_file_actions_addopen ( &file_actions, filedes = STDIN_FILENO, path = '%s', oflag = O_RDONLY, mode = 0 )", stdin_path); + stdio_err.PutToLog(log.get(), "::posix_spawn_file_actions_addopen ( &file_actions, filedes = STDIN_FILENO, path = '%s', oflag = O_RDONLY, mode = 0 )", stdin_path); } if (stdout_path != NULL && stdout_path[0]) { stdio_err.SetError( ::posix_spawn_file_actions_addopen(&file_actions, STDOUT_FILENO, stdout_path, O_WRONLY, 0), eErrorTypePOSIX); if (stdio_err.Fail() || log) - stdio_err.PutToLog(log, "::posix_spawn_file_actions_addopen ( &file_actions, filedes = STDOUT_FILENO, path = '%s', oflag = O_WRONLY, mode = 0 )", stdout_path); + stdio_err.PutToLog(log.get(), "::posix_spawn_file_actions_addopen ( &file_actions, filedes = STDOUT_FILENO, path = '%s', oflag = O_WRONLY, mode = 0 )", stdout_path); } } else @@ -1792,15 +1792,15 @@ ProcessMacOSX::PosixSpawnChildForPTraceDebugging slave_name = "/dev/null"; stdio_err.SetError( ::posix_spawn_file_actions_addopen(&file_actions, STDERR_FILENO, slave_name, O_RDWR|O_NOCTTY, 0), eErrorTypePOSIX); if (stdio_err.Fail() || log) - stdio_err.PutToLog(log, "::posix_spawn_file_actions_addopen ( &file_actions, filedes = STDERR_FILENO, path = '%s', oflag = O_RDWR|O_NOCTTY, mode = 0 )", slave_name); + stdio_err.PutToLog(log.get(), "::posix_spawn_file_actions_addopen ( &file_actions, filedes = STDERR_FILENO, path = '%s', oflag = O_RDWR|O_NOCTTY, mode = 0 )", slave_name); stdio_err.SetError( ::posix_spawn_file_actions_addopen(&file_actions, STDIN_FILENO, slave_name, O_RDONLY|O_NOCTTY, 0), eErrorTypePOSIX); if (stdio_err.Fail() || log) - stdio_err.PutToLog(log, "::posix_spawn_file_actions_addopen ( &file_actions, filedes = STDIN_FILENO, path = '%s', oflag = O_RDONLY|O_NOCTTY, mode = 0 )", slave_name); + stdio_err.PutToLog(log.get(), "::posix_spawn_file_actions_addopen ( &file_actions, filedes = STDIN_FILENO, path = '%s', oflag = O_RDONLY|O_NOCTTY, mode = 0 )", slave_name); stdio_err.SetError( ::posix_spawn_file_actions_addopen(&file_actions, STDOUT_FILENO, slave_name, O_WRONLY|O_NOCTTY, 0), eErrorTypePOSIX); if (stdio_err.Fail() || log) - stdio_err.PutToLog(log, "::posix_spawn_file_actions_addopen ( &file_actions, filedes = STDOUT_FILENO, path = '%s', oflag = O_WRONLY|O_NOCTTY, mode = 0 )", slave_name); + stdio_err.PutToLog(log.get(), "::posix_spawn_file_actions_addopen ( &file_actions, filedes = STDOUT_FILENO, path = '%s', oflag = O_WRONLY|O_NOCTTY, mode = 0 )", slave_name); } else { @@ -1813,7 +1813,7 @@ ProcessMacOSX::PosixSpawnChildForPTraceDebugging } err.SetError( ::posix_spawnp (&pid, path, &file_actions, &attr, (char * const*)argv, (char * const*)envp), eErrorTypePOSIX); if (err.Fail() || log) - err.PutToLog(log, "::posix_spawnp ( pid => %i, path = '%s', file_actions = %p, attr = %p, argv = %p, envp = %p )", pid, path, &file_actions, &attr, argv, envp); + err.PutToLog(log.get(), "::posix_spawnp ( pid => %i, path = '%s', file_actions = %p, attr = %p, argv = %p, envp = %p )", pid, path, &file_actions, &attr, argv, envp); if (stdio_err.Success()) { @@ -1831,7 +1831,7 @@ ProcessMacOSX::PosixSpawnChildForPTraceDebugging { err.SetError( ::posix_spawnp (&pid, path, NULL, &attr, (char * const*)argv, (char * const*)envp), eErrorTypePOSIX); if (err.Fail() || log) - err.PutToLog(log, "::posix_spawnp ( pid => %i, path = '%s', file_actions = %p, attr = %p, argv = %p, envp = %p )", pid, path, NULL, &attr, argv, envp); + err.PutToLog(log.get(), "::posix_spawnp ( pid => %i, path = '%s', file_actions = %p, attr = %p, argv = %p, envp = %p )", pid, path, NULL, &attr, argv, envp); } ::posix_spawnattr_destroy (&attr); @@ -1845,7 +1845,7 @@ ProcessMacOSX::PosixSpawnChildForPTraceDebugging { local_err.SetError( ::posix_spawn_file_actions_destroy (&file_actions), eErrorTypePOSIX); if (local_err.Fail() || log) - local_err.PutToLog(log, "::posix_spawn_file_actions_destroy ( &file_actions )"); + local_err.PutToLog(log.get(), "::posix_spawn_file_actions_destroy ( &file_actions )"); } return pid; diff --git a/lldb/source/Plugins/Process/MacOSX-User/source/ProcessMacOSXLog.cpp b/lldb/source/Plugins/Process/MacOSX-User/source/ProcessMacOSXLog.cpp index b0211720871..986989f690a 100644 --- a/lldb/source/Plugins/Process/MacOSX-User/source/ProcessMacOSXLog.cpp +++ b/lldb/source/Plugins/Process/MacOSX-User/source/ProcessMacOSXLog.cpp @@ -17,29 +17,38 @@ using namespace lldb; using namespace lldb_private; +// 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; +} -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 * +LogSP ProcessMacOSXLog::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 ProcessMacOSXLog::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) { @@ -65,28 +74,32 @@ ProcessMacOSXLog::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); } } -void -ProcessMacOSXLog::DeleteLog () +LogSP +ProcessMacOSXLog::EnableLog (StreamSP &log_stream_sp, uint32_t log_options, Args &args, Stream *feedback_strm) { - 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) { - delete g_log; - g_log = NULL; + log = make_shared<Log>(log_stream_sp); + GetLog () = log; } -} -Log * -ProcessMacOSXLog::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) + if (log) { uint32_t flag_bits = 0; bool got_unknown_category = false; @@ -121,10 +134,10 @@ ProcessMacOSXLog::EnableLog (StreamSP &log_stream_sp, uint32_t log_options, Args } if (flag_bits == 0) flag_bits = PD_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 @@ -150,7 +163,7 @@ ProcessMacOSXLog::ListLogCategories (Stream *strm) void ProcessMacOSXLog::LogIf (uint32_t mask, const char *format, ...) { - Log *log = ProcessMacOSXLog::GetLogIfAllCategoriesSet (mask); + LogSP log(ProcessMacOSXLog::GetLogIfAllCategoriesSet (mask)); if (log) { va_list args; diff --git a/lldb/source/Plugins/Process/MacOSX-User/source/ProcessMacOSXLog.h b/lldb/source/Plugins/Process/MacOSX-User/source/ProcessMacOSXLog.h index 74e5278e870..5645a7f6cda 100644 --- a/lldb/source/Plugins/Process/MacOSX-User/source/ProcessMacOSXLog.h +++ b/lldb/source/Plugins/Process/MacOSX-User/source/ProcessMacOSXLog.h @@ -43,7 +43,7 @@ class ProcessMacOSXLog { public: - static lldb_private::Log * + static lldb::LogSP GetLogIfAllCategoriesSet(uint32_t mask = 0); static void @@ -52,7 +52,7 @@ public: 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 diff --git a/lldb/source/Plugins/Process/MacOSX-User/source/RegisterContextMach_i386.cpp b/lldb/source/Plugins/Process/MacOSX-User/source/RegisterContextMach_i386.cpp index 9eef44de36e..fbda8ccb925 100644 --- a/lldb/source/Plugins/Process/MacOSX-User/source/RegisterContextMach_i386.cpp +++ b/lldb/source/Plugins/Process/MacOSX-User/source/RegisterContextMach_i386.cpp @@ -450,7 +450,7 @@ RegisterContextMach_i386::ReadGPR (bool force) { mach_msg_type_number_t count = GPRWordCount; SetError(set, Read, ::thread_get_state(GetThreadID(), set, (thread_state_t)&gpr, &count)); - LogGPR (ProcessMacOSXLog::GetLogIfAllCategoriesSet (PD_LOG_THREAD), "RegisterContextMach_i386::ReadGPR()"); + LogGPR (ProcessMacOSXLog::GetLogIfAllCategoriesSet (PD_LOG_THREAD).get(), "RegisterContextMach_i386::ReadGPR()"); } return GetError(set, Read); } diff --git a/lldb/source/Plugins/Process/MacOSX-User/source/RegisterContextMach_x86_64.cpp b/lldb/source/Plugins/Process/MacOSX-User/source/RegisterContextMach_x86_64.cpp index b520765dbab..507cde586ac 100644 --- a/lldb/source/Plugins/Process/MacOSX-User/source/RegisterContextMach_x86_64.cpp +++ b/lldb/source/Plugins/Process/MacOSX-User/source/RegisterContextMach_x86_64.cpp @@ -494,9 +494,9 @@ RegisterContextMach_x86_64::ReadGPR (bool force) { mach_msg_type_number_t count = GPRWordCount; SetError(GPRRegSet, Read, ::thread_get_state(GetThreadID(), set, (thread_state_t)&gpr, &count)); - Log *log = ProcessMacOSXLog::GetLogIfAllCategoriesSet (PD_LOG_THREAD); + LogSP log (ProcessMacOSXLog::GetLogIfAllCategoriesSet (PD_LOG_THREAD)); if (log) - LogGPR (log, "RegisterContextMach_x86_64::ReadGPR(thread = 0x%4.4x)", GetThreadID()); + LogGPR (log.get(), "RegisterContextMach_x86_64::ReadGPR(thread = 0x%4.4x)", GetThreadID()); } return GetError(GPRRegSet, Read); } @@ -534,9 +534,9 @@ RegisterContextMach_x86_64::WriteGPR () SetError (set, Write, -1); return KERN_INVALID_ARGUMENT; } - Log *log = ProcessMacOSXLog::GetLogIfAllCategoriesSet (PD_LOG_THREAD); + LogSP log (ProcessMacOSXLog::GetLogIfAllCategoriesSet (PD_LOG_THREAD)); if (log) - LogGPR (log, "RegisterContextMach_x86_64::WriteGPR (thread = 0x%4.4x)", GetThreadID()); + LogGPR (log.get(), "RegisterContextMach_x86_64::WriteGPR (thread = 0x%4.4x)", GetThreadID()); SetError (set, Write, ::thread_set_state(GetThreadID(), set, (thread_state_t)&gpr, GPRWordCount)); SetError (set, Read, -1); return GetError (set, Write); diff --git a/lldb/source/Plugins/Process/MacOSX-User/source/ThreadMacOSX.cpp b/lldb/source/Plugins/Process/MacOSX-User/source/ThreadMacOSX.cpp index 07130f89134..2a9754a268f 100644 --- a/lldb/source/Plugins/Process/MacOSX-User/source/ThreadMacOSX.cpp +++ b/lldb/source/Plugins/Process/MacOSX-User/source/ThreadMacOSX.cpp @@ -248,7 +248,7 @@ ThreadMacOSX::ClearStackFrames () int32_t ThreadMacOSX::Suspend() { - Log *log = ProcessMacOSXLog::GetLogIfAllCategoriesSet(PD_LOG_THREAD); + LogSP log (ProcessMacOSXLog::GetLogIfAllCategoriesSet(PD_LOG_THREAD)); if (log && log->GetMask().Test(PD_LOG_VERBOSE)) log->Printf ("ThreadMacOSX::%s ( )", __FUNCTION__); lldb::tid_t tid = GetID (); @@ -259,7 +259,7 @@ ThreadMacOSX::Suspend() m_suspend_count++; log = ProcessMacOSXLog::GetLogIfAllCategoriesSet(PD_LOG_THREAD); if (log || err.Fail()) - err.PutToLog(log, "::thread_suspend (%4.4x)", tid); + err.PutToLog(log.get(), "::thread_suspend (%4.4x)", tid); } return GetSuspendCount(); } @@ -267,7 +267,7 @@ ThreadMacOSX::Suspend() int32_t ThreadMacOSX::Resume() { - Log *log = ProcessMacOSXLog::GetLogIfAllCategoriesSet(PD_LOG_THREAD); + LogSP log (ProcessMacOSXLog::GetLogIfAllCategoriesSet(PD_LOG_THREAD)); if (log && log->GetMask().Test(PD_LOG_VERBOSE)) log->Printf ("ThreadMacOSX::%s ()", __FUNCTION__); lldb::tid_t tid = GetID (); @@ -280,7 +280,7 @@ ThreadMacOSX::Resume() m_suspend_count--; log = ProcessMacOSXLog::GetLogIfAllCategoriesSet(PD_LOG_THREAD); if (log || err.Fail()) - err.PutToLog(log, "::thread_resume (%4.4x)", tid); + err.PutToLog(log.get(), "::thread_resume (%4.4x)", tid); } } return GetSuspendCount(); @@ -289,7 +289,7 @@ ThreadMacOSX::Resume() bool ThreadMacOSX::RestoreSuspendCount() { - Log *log = ProcessMacOSXLog::GetLogIfAllCategoriesSet(PD_LOG_THREAD); + LogSP log (ProcessMacOSXLog::GetLogIfAllCategoriesSet(PD_LOG_THREAD)); if (log && log->GetMask().Test(PD_LOG_VERBOSE)) log->Printf ("ThreadMacOSX::%s ( )", __FUNCTION__); Error err; @@ -305,7 +305,7 @@ ThreadMacOSX::RestoreSuspendCount() --m_suspend_count; log = ProcessMacOSXLog::GetLogIfAllCategoriesSet(PD_LOG_THREAD); if (log || err.Fail()) - err.PutToLog(log, "::thread_resume (%4.4x)", tid); + err.PutToLog(log.get(), "::thread_resume (%4.4x)", tid); } } else if (m_suspend_count < m_basic_info.suspend_count) @@ -317,7 +317,7 @@ ThreadMacOSX::RestoreSuspendCount() --m_suspend_count; log = ProcessMacOSXLog::GetLogIfAllCategoriesSet(PD_LOG_THREAD); if (log || err.Fail()) - err.PutToLog(log, "::thread_suspend (%4.4x)", tid); + err.PutToLog(log.get(), "::thread_suspend (%4.4x)", tid); } } return m_suspend_count == m_basic_info.suspend_count; diff --git a/lldb/source/Plugins/Process/Utility/RegisterContextLLDB.cpp b/lldb/source/Plugins/Process/Utility/RegisterContextLLDB.cpp index 28ef513f49b..dcfb1343297 100644 --- a/lldb/source/Plugins/Process/Utility/RegisterContextLLDB.cpp +++ b/lldb/source/Plugins/Process/Utility/RegisterContextLLDB.cpp @@ -147,7 +147,7 @@ RegisterContextLLDB::InitializeZerothFrame() m_cfa = cfa_regval + cfa_offset; - Log *log = GetLogIfAllCategoriesSet (LIBLLDB_LOG_UNWIND); + LogSP log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_UNWIND)); // A couple of sanity checks.. if (cfa_regval == LLDB_INVALID_ADDRESS || cfa_regval == 0 || cfa_regval == 1) @@ -176,7 +176,7 @@ RegisterContextLLDB::InitializeZerothFrame() void RegisterContextLLDB::InitializeNonZerothFrame() { - Log *log = GetLogIfAllCategoriesSet (LIBLLDB_LOG_UNWIND); + LogSP log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_UNWIND)); if (IsFrameZero ()) { m_frame_type = eNotAValidFrame; @@ -416,7 +416,7 @@ RegisterContextLLDB::GetFastUnwindPlanForFrame () if (fu->GetUnwindPlanFastUnwind (m_thread) && fu->GetUnwindPlanFastUnwind (m_thread)->PlanValidAtAddress (m_current_pc)) { - Log *log = GetLogIfAllCategoriesSet (LIBLLDB_LOG_UNWIND); + LogSP log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_UNWIND)); if (log && IsLogVerbose()) { const char *has_fast = ""; @@ -441,7 +441,7 @@ RegisterContextLLDB::GetFastUnwindPlanForFrame () UnwindPlan * RegisterContextLLDB::GetFullUnwindPlanForFrame () { - Log *log = GetLogIfAllCategoriesSet (LIBLLDB_LOG_UNWIND); + LogSP log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_UNWIND)); UnwindPlan *up; UnwindPlan *arch_default_up = NULL; ArchSpec arch = m_thread.GetProcess().GetTarget().GetArchitecture (); @@ -687,7 +687,7 @@ RegisterContextLLDB::IsValid () const bool RegisterContextLLDB::SavedLocationForRegister (uint32_t lldb_regnum, RegisterLocation ®loc) { - Log *log = GetLogIfAllCategoriesSet (LIBLLDB_LOG_UNWIND); + LogSP log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_UNWIND)); // Have we already found this register location? std::map<uint32_t, RegisterLocation>::const_iterator iterator; @@ -976,7 +976,7 @@ RegisterContextLLDB::ReadGPRValue (int register_kind, uint32_t regnum, addr_t &v bool RegisterContextLLDB::ReadRegisterBytes (uint32_t lldb_reg, DataExtractor& data) { - Log *log = GetLogIfAllCategoriesSet (LIBLLDB_LOG_UNWIND); + LogSP log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_UNWIND)); if (!IsValid()) return false; diff --git a/lldb/source/Plugins/Process/Utility/UnwindLLDB.cpp b/lldb/source/Plugins/Process/Utility/UnwindLLDB.cpp index 8fb7763b287..5847718d4e2 100644 --- a/lldb/source/Plugins/Process/Utility/UnwindLLDB.cpp +++ b/lldb/source/Plugins/Process/Utility/UnwindLLDB.cpp @@ -31,7 +31,7 @@ UnwindLLDB::UnwindLLDB (Thread &thread) : uint32_t UnwindLLDB::GetFrameCount() { - Log *log = GetLogIfAllCategoriesSet (LIBLLDB_LOG_UNWIND); + LogSP log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_UNWIND)); if (m_frames.empty()) { // First, set up the 0th (initial) frame 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 |

