Fix a bug when using a StructuredData darwin-log plugin

where we would insert a breakpoint into a system library
but never remove it, so the second time we ran the binary
there would be two breakpoints and the debugger would
stop there.

<rdar://problem/29654974> 

llvm-svn: 289913
This commit is contained in:
Jason Molenda 2016-12-16 02:48:39 +00:00
parent 519de4b692
commit 3826727453
3 changed files with 21 additions and 1 deletions

View File

@ -1405,6 +1405,20 @@ void StructuredDataDarwinLog::ModulesDidLoad(Process &process,
EnableNow();
}
// -----------------------------------------------------------------------------
// public destructor
// -----------------------------------------------------------------------------
StructuredDataDarwinLog::~StructuredDataDarwinLog() {
if (m_breakpoint_id != LLDB_INVALID_BREAK_ID) {
ProcessSP process_sp(GetProcess());
if (process_sp) {
process_sp->GetTarget().RemoveBreakpointByID(m_breakpoint_id);
m_breakpoint_id = LLDB_INVALID_BREAK_ID;
}
}
}
#pragma mark -
#pragma mark Private instance methods
@ -1415,7 +1429,8 @@ void StructuredDataDarwinLog::ModulesDidLoad(Process &process,
StructuredDataDarwinLog::StructuredDataDarwinLog(const ProcessWP &process_wp)
: StructuredDataPlugin(process_wp), m_recorded_first_timestamp(false),
m_first_timestamp_seen(0), m_is_enabled(false),
m_added_breakpoint_mutex(), m_added_breakpoint() {}
m_added_breakpoint_mutex(), m_added_breakpoint(),
m_breakpoint_id(LLDB_INVALID_BREAK_ID) {}
// -----------------------------------------------------------------------------
// Private static methods
@ -1734,6 +1749,7 @@ void StructuredDataDarwinLog::AddInitCompletionHook(Process &process) {
// Set our callback.
breakpoint_sp->SetCallback(InitCompletionHookCallback, nullptr);
m_breakpoint_id = breakpoint_sp->GetID();
if (log)
log->Printf("StructuredDataDarwinLog::%s() breakpoint set in module %s,"
"function %s (process uid %u)",

View File

@ -74,6 +74,8 @@ public:
void ModulesDidLoad(Process &process, ModuleList &module_list) override;
~StructuredDataDarwinLog();
private:
// -------------------------------------------------------------------------
// Private constructors
@ -129,6 +131,7 @@ private:
bool m_is_enabled;
std::mutex m_added_breakpoint_mutex;
bool m_added_breakpoint;
lldb::user_id_t m_breakpoint_id;
};
}

View File

@ -889,6 +889,7 @@ void Process::Finalize() {
m_public_run_lock.SetStopped();
m_private_run_lock.TrySetRunning(); // This will do nothing if already locked
m_private_run_lock.SetStopped();
m_structured_data_plugin_map.clear();
m_finalize_called = true;
}