virtual Status DisableWatchpoint(Watchpoint *wp, bool notify = true);
// Thread Queries
- virtual bool UpdateThreadList(ThreadList &old_thread_list,
- ThreadList &new_thread_list) = 0;
+
+ /// Update the thread list.
+ ///
+ /// This method performs some general clean up before invoking
+ /// \a DoUpdateThreadList, which should be implemented by each
+ /// process plugin.
+ ///
+ /// \return
+ /// \b true if the new thread list could be generated, \b false otherwise.
+ bool UpdateThreadList(ThreadList &old_thread_list,
+ ThreadList &new_thread_list);
void UpdateThreadListIfNeeded();
bool trap_exceptions = false);
protected:
+ /// Update the thread list following process plug-in's specific logic.
+ ///
+ /// This method should only be invoked by \a UpdateThreadList.
+ ///
+ /// \return
+ /// \b true if the new thread list could be generated, \b false otherwise.
+ virtual bool DoUpdateThreadList(ThreadList &old_thread_list,
+ ThreadList &new_thread_list) = 0;
+
/// Actually do the reading of memory from a process.
///
/// Subclasses must override this function and can return fewer bytes than
protected:
void Clear();
- bool UpdateThreadList(ThreadList &old_thread_list,
- ThreadList &new_thread_list) override;
+ bool DoUpdateThreadList(ThreadList &old_thread_list,
+ ThreadList &new_thread_list) override;
private:
static lldb::ProcessSP CreateInstance(lldb::TargetSP target_sp,
const Target &GetTarget() const;
+ /// Clear the Thread* cache.
+ ///
+ /// This is useful in situations like when a new Thread list is being
+ /// generated.
+ void ClearThreadCache();
+
/// Print a description of this thread to the stream \a s.
/// \a thread. Don't expect that the result of GetThread is valid in
/// the description method. This might get called when the underlying
void WillResume();
+ /// Clear the Thread* cache that each ThreadPlan contains.
+ ///
+ /// This is useful in situations like when a new Thread list is being
+ /// generated.
+ void ClearThreadCache();
+
private:
const PlanStack &GetStackOfKind(ThreadPlanStack::StackKind kind) const;
return &result->second;
}
+ /// Clear the Thread* cache that each ThreadPlan contains.
+ ///
+ /// This is useful in situations like when a new Thread list is being
+ /// generated.
+ void ClearThreadCache() {
+ for (auto &plan_list : m_plans_list)
+ plan_list.second.ClearThreadCache();
+ }
+
void Clear() {
for (auto plan : m_plans_list)
plan.second.ThreadDestroyed(nullptr);
return Status();
}
-bool ProcessFreeBSD::UpdateThreadList(ThreadList &old_thread_list,
- ThreadList &new_thread_list) {
+bool ProcessFreeBSD::DoUpdateThreadList(ThreadList &old_thread_list,
+ ThreadList &new_thread_list) {
Log *log(ProcessPOSIXLog::GetLogIfAllCategoriesSet(POSIX_LOG_PROCESS));
LLDB_LOGF(log, "ProcessFreeBSD::%s (pid = %" PRIu64 ")", __FUNCTION__,
GetID());
virtual uint32_t UpdateThreadListIfNeeded();
- bool UpdateThreadList(lldb_private::ThreadList &old_thread_list,
- lldb_private::ThreadList &new_thread_list) override;
+ bool DoUpdateThreadList(lldb_private::ThreadList &old_thread_list,
+ lldb_private::ThreadList &new_thread_list) override;
virtual lldb::ByteOrder GetByteOrder() const;
return thread_sp;
}
-bool ProcessKDP::UpdateThreadList(ThreadList &old_thread_list,
- ThreadList &new_thread_list) {
+bool ProcessKDP::DoUpdateThreadList(ThreadList &old_thread_list,
+ ThreadList &new_thread_list) {
// locker will keep a mutex locked until it goes out of scope
Log *log(ProcessKDPLog::GetLogIfAllCategoriesSet(KDP_LOG_THREAD));
LLDB_LOGV(log, "pid = {0}", GetID());
void Clear();
- bool UpdateThreadList(lldb_private::ThreadList &old_thread_list,
- lldb_private::ThreadList &new_thread_list) override;
+ bool DoUpdateThreadList(lldb_private::ThreadList &old_thread_list,
+ lldb_private::ThreadList &new_thread_list) override;
enum {
eBroadcastBitAsyncContinue = (1 << 0),
return true;
}
-bool ProcessWindows::UpdateThreadList(ThreadList &old_thread_list,
- ThreadList &new_thread_list) {
+bool ProcessWindows::DoUpdateThreadList(ThreadList &old_thread_list,
+ ThreadList &new_thread_list) {
Log *log = ProcessWindowsLog::GetLogIfAny(WINDOWS_LOG_THREAD);
// Add all the threads that were previously running and for which we did not
// detect a thread exited event.
bool CanDebug(lldb::TargetSP target_sp,
bool plugin_specified_by_name) override;
bool DestroyRequiresHalt() override { return false; }
- bool UpdateThreadList(ThreadList &old_thread_list,
- ThreadList &new_thread_list) override;
+ bool DoUpdateThreadList(ThreadList &old_thread_list,
+ ThreadList &new_thread_list) override;
bool IsAlive() override;
size_t DoReadMemory(lldb::addr_t vm_addr, void *buf, size_t size,
return m_dyld_up.get();
}
-bool ProcessElfCore::UpdateThreadList(ThreadList &old_thread_list,
- ThreadList &new_thread_list) {
+bool ProcessElfCore::DoUpdateThreadList(ThreadList &old_thread_list,
+ ThreadList &new_thread_list) {
const uint32_t num_threads = GetNumThreadContexts();
if (!m_thread_data_valid)
return false;
protected:
void Clear();
- bool UpdateThreadList(lldb_private::ThreadList &old_thread_list,
- lldb_private::ThreadList &new_thread_list) override;
+ bool DoUpdateThreadList(lldb_private::ThreadList &old_thread_list,
+ lldb_private::ThreadList &new_thread_list) override;
private:
struct NT_FILE_Entry {
return true;
}
-bool ProcessGDBRemote::UpdateThreadList(ThreadList &old_thread_list,
- ThreadList &new_thread_list) {
+bool ProcessGDBRemote::DoUpdateThreadList(ThreadList &old_thread_list,
+ ThreadList &new_thread_list) {
// locker will keep a mutex locked until it goes out of scope
Log *log(ProcessGDBRemoteLog::GetLogIfAllCategoriesSet(GDBR_LOG_THREAD));
LLDB_LOGV(log, "pid = {0}", GetID());
void Clear();
- bool UpdateThreadList(ThreadList &old_thread_list,
- ThreadList &new_thread_list) override;
+ bool DoUpdateThreadList(ThreadList &old_thread_list,
+ ThreadList &new_thread_list) override;
Status ConnectToReplayServer();
return m_dyld_up.get();
}
-bool ProcessMachCore::UpdateThreadList(ThreadList &old_thread_list,
- ThreadList &new_thread_list) {
+bool ProcessMachCore::DoUpdateThreadList(ThreadList &old_thread_list,
+ ThreadList &new_thread_list) {
if (old_thread_list.GetSize(false) == 0) {
// Make up the thread the first time this is called so we can setup our one
// and only core thread state.
void Clear();
- bool UpdateThreadList(lldb_private::ThreadList &old_thread_list,
- lldb_private::ThreadList &new_thread_list) override;
+ bool DoUpdateThreadList(lldb_private::ThreadList &old_thread_list,
+ lldb_private::ThreadList &new_thread_list) override;
lldb_private::ObjectFile *GetCoreObjectFile();
void ProcessMinidump::Clear() { Process::m_thread_list.Clear(); }
-bool ProcessMinidump::UpdateThreadList(ThreadList &old_thread_list,
- ThreadList &new_thread_list) {
+bool ProcessMinidump::DoUpdateThreadList(ThreadList &old_thread_list,
+ ThreadList &new_thread_list) {
for (const minidump::Thread &thread : m_thread_list) {
LocationDescriptor context_location = thread.Context;
protected:
void Clear();
- bool UpdateThreadList(ThreadList &old_thread_list,
- ThreadList &new_thread_list) override;
+ bool DoUpdateThreadList(ThreadList &old_thread_list,
+ ThreadList &new_thread_list) override;
void ReadModuleList();
return false;
}
+bool Process::UpdateThreadList(ThreadList &old_thread_list,
+ ThreadList &new_thread_list) {
+ m_thread_plans.ClearThreadCache();
+ return DoUpdateThreadList(old_thread_list, new_thread_list);
+}
+
void Process::UpdateThreadListIfNeeded() {
const uint32_t stop_id = GetStopID();
if (m_thread_list.GetSize(false) == 0 ||
Process::DidAttach(process_arch);
}
-bool ProcessTrace::UpdateThreadList(ThreadList &old_thread_list,
- ThreadList &new_thread_list) {
+bool ProcessTrace::DoUpdateThreadList(ThreadList &old_thread_list,
+ ThreadList &new_thread_list) {
return false;
}
return m_run_vote;
}
+void ThreadPlan::ClearThreadCache() { m_thread = nullptr; }
+
bool ThreadPlan::StopOthers() {
ThreadPlan *prev_plan;
prev_plan = GetPreviousPlan();
}
}
bool success = DoWillResume(resume_state, current_plan);
- m_thread = nullptr; // We don't cache the thread pointer over resumes. This
+ ClearThreadCache(); // We don't cache the thread pointer over resumes. This
// Thread might go away, and another Thread represent
// the same underlying object on a later stop.
return success;
return nullptr;
}
+void ThreadPlanStack::ClearThreadCache() {
+ for (lldb::ThreadPlanSP thread_plan_sp : m_plans)
+ thread_plan_sp->ClearThreadCache();
+}
+
void ThreadPlanStack::WillResume() {
m_completed_plans.clear();
m_discarded_plans.clear();
self.runCmd("bt")
self.assertTrue(len(threads) == 1,
"Stopped at breakpoint in exec'ed process.")
+
+ @expectedFailureAll(archs=['i386'],
+ oslist=no_match(["freebsd"]),
+ bugnumber="rdar://28656532")
+ @expectedFailureAll(oslist=["ios", "tvos", "watchos", "bridgeos"], bugnumber="rdar://problem/34559552") # this exec test has problems on ios systems
+ @expectedFailureNetBSD
+ @skipIfAsan # rdar://problem/43756823
+ @skipIfWindows
+ def test_correct_thread_plan_state_before_exec(self):
+ '''
+ In this test we make sure that the Thread* cache in the ThreadPlans
+ is cleared correctly when performing exec
+ '''
+
+ self.build()
+ exe = self.getBuildArtifact("a.out")
+ target = self.dbg.CreateTarget(exe)
+
+ (target, process, thread, breakpoint1) = lldbutil.run_to_source_breakpoint(
+ self, 'Set breakpoint 1 here', lldb.SBFileSpec('main.cpp', False))
+
+ # The stop reason of the thread should be breakpoint.
+ self.assertTrue(process.GetState() == lldb.eStateStopped,
+ STOPPED_DUE_TO_BREAKPOINT)
+
+ threads = lldbutil.get_threads_stopped_at_breakpoint(process, breakpoint1)
+ self.assertTrue(len(threads) == 1)
+
+ # We perform an instruction step, which effectively sets the cache of the base
+ # thread plan, which should be cleared when a new thread list appears.
+ #
+ # Continuing after this instruction step will trigger a call to
+ # ThreadPlan::ShouldReportRun, which sets the ThreadPlan's Thread cache to
+ # the old Thread* value. In Process::UpdateThreadList we are clearing this
+ # cache in preparation for the new ThreadList.
+ #
+ # Not doing this stepping will cause LLDB to first execute a private single step
+ # past the current breakpoint, which eventually avoids the call to ShouldReportRun,
+ # thus not setting the cache to its invalid value.
+ thread.StepInstruction(False)
+
+ # Run and we should stop due to exec
+ breakpoint2 = target.BreakpointCreateBySourceRegex(
+ 'Set breakpoint 2 here', lldb.SBFileSpec("secondprog.cpp", False))
+
+ process.Continue()
+
+ self.assertFalse(process.GetState() == lldb.eStateExited,
+ "Process should not have exited!")
+ self.assertTrue(process.GetState() == lldb.eStateStopped,
+ "Process should be stopped at __dyld_start")
+
+ threads = lldbutil.get_stopped_threads(
+ process, lldb.eStopReasonExec)
+ self.assertTrue(
+ len(threads) == 1,
+ "We got a thread stopped for exec.")
+
+ # Run and we should stop at breakpoint in main after exec
+ process.Continue()
+
+ threads = lldbutil.get_threads_stopped_at_breakpoint(
+ process, breakpoint2)
+ self.assertTrue(len(threads) == 1,
+ "Stopped at breakpoint in exec'ed process.")
Status &error) {
return 0;
}
- virtual bool UpdateThreadList(ThreadList &old_thread_list,
- ThreadList &new_thread_list) {
+ bool DoUpdateThreadList(ThreadList &old_thread_list,
+ ThreadList &new_thread_list) override {
return false;
}
virtual ConstString GetPluginName() { return ConstString("Dummy"); }
Status &error) {
return 0;
}
- virtual bool UpdateThreadList(ThreadList &old_thread_list,
- ThreadList &new_thread_list) {
+ bool DoUpdateThreadList(ThreadList &old_thread_list,
+ ThreadList &new_thread_list) override {
return false;
}
virtual ConstString GetPluginName() { return ConstString("Dummy"); }
Status &error) {
return 0;
}
- virtual bool UpdateThreadList(ThreadList &old_thread_list,
- ThreadList &new_thread_list) {
+ bool DoUpdateThreadList(ThreadList &old_thread_list,
+ ThreadList &new_thread_list) override {
return false;
}
virtual ConstString GetPluginName() { return ConstString("Dummy"); }