From b562aadcc130760a59a5fd9e37371ba5ca19244f Mon Sep 17 00:00:00 2001 From: Peter Edwards Date: Mon, 26 Feb 2024 15:11:27 +0000 Subject: [PATCH] Clean up around LWP stop code. --- libpstack/proc.h | 1 + live.cc | 21 +++++++++++++++------ 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/libpstack/proc.h b/libpstack/proc.h index dfa3ece..ecabd4c 100644 --- a/libpstack/proc.h +++ b/libpstack/proc.h @@ -296,6 +296,7 @@ class LiveProcess final : public Process { public: // attach to existing process. LiveProcess(Elf::Object::sptr &, pid_t, const PstackOptions &, Dwarf::ImageCache &, bool alreadyStopped=false); + ~LiveProcess(); void listLWPs(std::function) override; virtual bool getRegs(lwpid_t pid, Elf::CoreRegisters *reg) override; diff --git a/live.cc b/live.cc index b1c3f28..8f83b7d 100644 --- a/live.cc +++ b/live.cc @@ -112,6 +112,15 @@ LiveProcess::getPID() const return pid; } +LiveProcess::~LiveProcess() { + for (auto &lwp : stoppedLWPs) { + if (lwp.second.stopCount > 0) { + lwp.second.stopCount = 1; // remove all soft "stops". + resume(lwp.first); + } + } +}; + void LiveProcess::stopProcess() { @@ -172,17 +181,17 @@ LiveProcess::stopProcess() void LiveProcess::resumeProcess() { + // this doesn't work on Linux nptl, but it's ok, we'll resume the LWP below. listThreads([] (const td_thrhandle_t *thr) { - if (td_thr_dbresume(thr) == TD_NOCAPAB) { - // this doesn't work in general, but it's ok, we'll suspend the LWP - if (verbose >= 3) - *debug << "can't resume thread " << thr << " (will resume it's LWP)\n"; - }}); + int rc = td_thr_dbresume(thr); + if (rc != 0 && rc != TD_NOCAPAB) + *debug << "can't resume thread " << thr << " (will resume it's LWP)\n"; + }); for (auto &lwp : stoppedLWPs) resume(lwp.first); - /* C++17 - remove all LWPs that are now resumed) */ + // C++17: remove all LWPs that are now resumed) for (auto it = stoppedLWPs.begin(); it != stoppedLWPs.end(); ) if (it->second.stopCount == 0) it = stoppedLWPs.erase(it);