Skip to content

Commit

Permalink
Don't pretend core files might have new LWPs
Browse files Browse the repository at this point in the history
  • Loading branch information
peadar committed Sep 6, 2023
1 parent 95493f6 commit 2365998
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 29 deletions.
48 changes: 20 additions & 28 deletions dead.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,27 @@
#include "libpstack/elf.h"
#include "libpstack/proc.h"

#include <cassert>

#include <iostream>

CoreProcess::CoreProcess(Elf::Object::sptr exec, Elf::Object::sptr core,
const PstackOptions &options, Dwarf::ImageCache &imageCache)
: Process(std::move(exec), std::make_shared<CoreReader>(this, core), options, imageCache)
, coreImage(std::move(core))
{

#ifdef NT_PRSTATUS
for (auto note : coreImage->notes()) {
if (note.name() == "CORE" && note.type() == NT_PRSTATUS) {
tasks.push_back( note.data()->readObj<prstatus_t>(0) );
prstatus_t &task = tasks.back();
(void)lwps[task.pr_pid];
if (verbose)
*debug << "task " << task.pr_pid << " current sig is " << task.pr_cursig << "\n";
}
#endif
}
}

Reader::csptr
Expand Down Expand Up @@ -115,13 +129,11 @@ bool
CoreProcess::getRegs(lwpid_t pid, Elf::CoreRegisters *reg)
{
#ifdef NT_PRSTATUS
for (auto note : coreImage->notes()) {
if (note.name() == "CORE" && note.type() == NT_PRSTATUS) {
const auto &prstatus = note.data()->readObj<prstatus_t>(0);
if (prstatus.pr_pid == pid) {
memcpy(reg, &prstatus.pr_reg, sizeof(*reg));
return true;
}
for (auto &task : tasks) {
static_assert(sizeof task.pr_reg == sizeof *reg);
if (task.pr_pid == pid) {
memcpy(reg, &task.pr_reg, sizeof(*reg));
return true;
}
}
#endif
Expand All @@ -143,32 +155,12 @@ CoreProcess::stop(lwpid_t /* unused */)
void
CoreProcess::stopProcess()
{
// Find LWPs when we attempt to "stop" the process.
findLWPs();
}

pid_t
CoreProcess::getPID() const
{
// Return the PID of the first task in the core.
for (auto note : coreImage->notes())
if (note.name() == "CORE" && note.type() == NT_PRSTATUS)
return note.data()->readObj<prstatus_t>(0).pr_pid;
return -1;
}

void
CoreProcess::findLWPs()
{
for (auto note : coreImage->notes()) {
if (note.name() == "CORE" && note.type() == NT_PRSTATUS) {
auto prstatus = note.data()->readObj<prstatus_t>(0);
(void)lwps[prstatus.pr_pid];
if (verbose) {
*debug << "task " << prstatus.pr_pid << " current sig is " << prstatus.pr_cursig << "\n";
}
}
}
return tasks.size() != 0 ? tasks[0].pr_pid : -1;
}

std::vector<AddressRange>
Expand Down
2 changes: 1 addition & 1 deletion libpstack/proc.h
Original file line number Diff line number Diff line change
Expand Up @@ -323,10 +323,10 @@ class CoreProcess final : public Process {
virtual void resume(lwpid_t) override;
void stopProcess() override;
void resumeProcess() override { }
void findLWPs();
virtual Reader::csptr getAUXV() const override;
virtual pid_t getPID() const override;
protected:
std::vector<prstatus_t> tasks;
bool loadSharedObjectsFromFileNote() override;
std::vector<AddressRange> addressSpace() const override;
};
Expand Down

0 comments on commit 2365998

Please sign in to comment.