Skip to content

Commit

Permalink
Clean up around LWP stop code.
Browse files Browse the repository at this point in the history
  • Loading branch information
peadar committed Feb 26, 2024
1 parent abbca2c commit b562aad
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 6 deletions.
1 change: 1 addition & 0 deletions libpstack/proc.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<void(lwpid_t)>) override;
virtual bool getRegs(lwpid_t pid, Elf::CoreRegisters *reg) override;
Expand Down
21 changes: 15 additions & 6 deletions live.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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()
{
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit b562aad

Please sign in to comment.