Skip to content

Commit

Permalink
Piles of clang-tidy warning removal.
Browse files Browse the repository at this point in the history
  • Loading branch information
peadar committed May 1, 2024
1 parent 4015298 commit 7d5c652
Show file tree
Hide file tree
Showing 17 changed files with 301 additions and 246 deletions.
42 changes: 23 additions & 19 deletions dead.cc
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ namespace pstack::Procman {
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)
, prpsinfo{}
, coreImage(std::move(core))
{
for (auto note : coreImage->notes()) {
Expand All @@ -21,13 +22,16 @@ CoreProcess::CoreProcess(Elf::Object::sptr exec, Elf::Object::sptr core,
// for an LWP-related note, we start at the index for that LWPs
// NT_PRSTATUS, and consider it a failure if we reach another
// NT_PRSTATUS or the end of the list.
prstatus_t task = note.data()->readObj<prstatus_t>(0);
auto task = note.data()->readObj<prstatus_t>(0);
lwpToPrStatusIdx[task.pr_pid] = notes.size();
break;
}
case NT_PRPSINFO: {
note.data()->readObj(0, &prpsinfo); // hold on to a copy of this
break;
}
default:
break;
}
}
notes.push_back( note );
Expand All @@ -43,7 +47,7 @@ Reader::csptr
CoreProcess::getAUXV() const
{
#ifdef __linux__
for (auto &note : notes) {
for (const auto &note : notes) {
if (note.name() == "CORE" && note.type() == NT_AUXV) {
return note.data();
break;
Expand All @@ -61,7 +65,7 @@ void CoreReader::describe(std::ostream &os) const
os << "no backing core file";
}

static size_t
size_t
readFromHdr(const Elf::Object &obj, const Elf::Phdr *hdr, Elf::Off addr,
char *ptr, Elf::Off size, Elf::Off *toClear)
{
Expand Down Expand Up @@ -111,10 +115,7 @@ CoreReader::read(Off remoteAddr, size_t size, char *ptr) const
}
}
// Either no data in core, or it was incomplete to this point: search loaded objects.
Elf::Off loadAddr;
const Elf::Phdr *hdr;
Elf::Object::sptr obj;
std::tie(loadAddr, obj, hdr) = p->findSegment(remoteAddr);
auto [loadAddr, obj, hdr] = p->findSegment(remoteAddr);
if (hdr != nullptr) {
// header in an object - try reading from here.
size_t rc = readFromHdr(*obj, hdr, remoteAddr - loadAddr, ptr, size, &zeroes);
Expand All @@ -136,7 +137,7 @@ CoreReader::read(Off remoteAddr, size_t size, char *ptr) const
return remoteAddr - start;
}

CoreReader::CoreReader(Process *p_, Elf::Object::sptr core_) : p(p_), core(core_) { }
CoreReader::CoreReader(Process *p_, Elf::Object::sptr core_) : p(p_), core(std::move( core_ ) ) { }

size_t
CoreProcess::getRegs(lwpid_t lwpid, int code, size_t size, void *data)
Expand All @@ -148,12 +149,12 @@ CoreProcess::getRegs(lwpid_t lwpid, int code, size_t size, void *data)
for (size_t i = idx->second;;) {
if (notes[i].type() == code) {
if (code == NT_PRSTATUS) {
prstatus_t prstatus = notes[i].data()->readObj<prstatus_t>(0);
auto prstatus = notes[i].data()->readObj<prstatus_t>(0);
size = std::min(size, sizeof prstatus.pr_reg);
memcpy(data, &prstatus.pr_reg, size);
} else {
size = std::min(size, size_t(notes[i].data()->size()));
notes[i].data()->read(0, size, (char *)data);
notes[i].data()->read(0, size, reinterpret_cast<char *>(data));
}
return size;
}
Expand Down Expand Up @@ -197,7 +198,7 @@ FileEntries::iterator::iterator(const FileEntries &entries, ReaderArray<FileEntr

struct NamedEntry {
std::pair<std::string, FileEntry> content;
int operator < (const NamedEntry &rhs) const {
bool operator < (const NamedEntry &rhs) const {
return content.second.start < rhs.content.second.start;
}
};
Expand Down Expand Up @@ -233,13 +234,14 @@ CoreProcess::addressSpace() const {
name = ub->second.first;
}
std::set<AddressRange::Flags> flags;
if (hdr.p_flags & PF_W)
if ((hdr.p_flags & PF_W) != 0)
flags.insert(AddressRange::Flags::write);
if (hdr.p_flags & PF_R)
if ((hdr.p_flags & PF_R) != 0)
flags.insert(AddressRange::Flags::read);
if (hdr.p_flags & PF_X)
if ((hdr.p_flags & PF_X) != 0)
flags.insert(AddressRange::Flags::exec);
rv.push_back({hdr.p_vaddr, hdr.p_vaddr + hdr.p_memsz, hdr.p_vaddr + hdr.p_filesz, 0, {0, 0, 0, name}, flags});
rv.push_back( { hdr.p_vaddr, hdr.p_vaddr + hdr.p_memsz,
hdr.p_vaddr + hdr.p_filesz, 0, {0, 0, 0, name}, {}});
}
return rv;
}
Expand All @@ -255,18 +257,20 @@ CoreProcess::loadSharedObjectsFromFileNote()
uintptr_t size = entry.end - entry.start;
totalSize += size;
if (verbose > 2)
*debug << "NT_FILE mapping " << name << " " << (void *)entry.start << " " << size << std::endl;
*debug << "NT_FILE mapping " << name << " "
<< (void *)entry.start << " " << size << "\n";
if (entry.fileOff == 0) {
try {
// Just try and load it like an ELF object.
addElfObject(name, nullptr, entry.start);
}
catch (...) {
catch (const std::exception &ex) {
*debug << "failed to add ELF object " << name << ": " << ex.what() << "\n";
}
}
}
if (verbose)
*debug << "total mapped file size: " << totalSize << std::endl;
if (verbose > 0)
*debug << "total mapped file size: " << totalSize << "\n";
return true; // found an NT_FILE note, so success.
}

Expand Down
2 changes: 1 addition & 1 deletion dwarf_cache.cc
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ ImageCache::ImageCache() : dwarfHits(0), dwarfLookups(0) { }
ImageCache::~ImageCache() noexcept {
if (verbose >= 2)
*debug << "DWARF image cache: lookups: " << dwarfLookups << ", hits="
<< dwarfHits << std::endl;
<< dwarfHits << "\n";
}

void
Expand Down
45 changes: 23 additions & 22 deletions dwarf_die.cc
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class DIE::Raw {
Elf::Off firstChild;
Elf::Off nextSibling;
public:
Raw(Unit *, DWARFReader &, size_t, Elf::Off parent);
Raw(Unit *unit, DWARFReader &r, size_t abbr, Elf::Off parent);
~Raw();
// Mostly, Raw DIEs are hidden from everything. DIE needs access though
friend class DIE;
Expand Down Expand Up @@ -99,7 +99,7 @@ DIE::containsAddress(Elf::Addr addr) const
// DW_AT_ranges attr.
auto rangeattr = attribute(DW_AT_ranges);
if (rangeattr.valid()) {
const Ranges *ranges = unit->getRanges(*this, low.valid() ? uintmax_t(low) : 0);
const auto &ranges = unit->getRanges(*this, low.valid() ? uintmax_t(low) : 0);
if (ranges != nullptr) {
// Iterate over the ranges, and see if the address lies inside.
for (const Ranges::value_type &range : *ranges)
Expand Down Expand Up @@ -128,7 +128,7 @@ DIE::attribute(AttrName name, bool local) const
name, cmp());

if (loc != raw->type->attrName2Idx.end() && loc->first == name)
return { *this, &raw->type->forms.at(loc->second) };
return Attribute{ *this, &raw->type->forms.at(loc->second) };

// If we have attributes of any of these types, we can look for other
// attributes in the referenced entry.
Expand Down Expand Up @@ -344,7 +344,8 @@ DIE::Raw::~Raw()
}
}

static void walk(const DIE & die) { for (auto c : die.children()) { walk(c); } };
void walk(const DIE & die) { for (auto c : die.children()) { walk(c); } };

Elf::Off
DIE::getParentOffset() const
{
Expand Down Expand Up @@ -661,7 +662,7 @@ std::pair<AttrName, DIE::Attribute>
DIE::Attributes::const_iterator::operator *() const {
return std::make_pair(
rawIter->first,
Attribute(die, &die.raw->type->forms[rawIter->second]));
Attribute{ die, &die.raw->type->forms[rawIter->second] } );
}

DIE::Attributes::const_iterator
Expand All @@ -687,47 +688,47 @@ bool DIE::hasChildren() const {
}

std::string
DIE::typeName(const DIE &type)
DIE::typeName()
{
if (!*this)
return "void";

const auto &name = type.name();
if (name != "")
return name;
auto base = DIE(type.attribute(DW_AT_type));
const auto &selfname = name();
if (selfname != "")
return selfname;
auto base = DIE(attribute(DW_AT_type));
std::string s, sep;
switch (type.tag()) {
switch (tag()) {
case DW_TAG_pointer_type:
return typeName(base) + " *";
return base.typeName() + " *";
case DW_TAG_const_type:
return typeName(base) + " const";
return base.typeName() + " const";
case DW_TAG_volatile_type:
return typeName(base) + " volatile";
return base.typeName() + " volatile";
case DW_TAG_subroutine_type:
s = typeName(base) + "(";
s = base.typeName() + "(";
sep = "";
for (auto arg : type.children()) {
for (auto arg : children()) {
if (arg.tag() != DW_TAG_formal_parameter)
continue;
s += sep;
s += typeName(DIE(arg.attribute(DW_AT_type)));
s += DIE(arg.attribute(DW_AT_type)).typeName();
sep = ", ";
}
s += ")";
return s;
case DW_TAG_reference_type:
return typeName(base) + "&";
return base.typeName() + "&";
default: {
return stringify("(unhandled tag ", type.tag(), ")");
return stringify("(unhandled tag ", tag(), ")");
}
}
}

const Ranges * DIE::getRanges() const {
const std::unique_ptr<Ranges> &DIE::getRanges() const {
auto ranges = attribute(DW_AT_ranges);
static std::unique_ptr<Ranges> none;
if (!ranges.valid())
return nullptr;
return none;
auto lowpc = attribute(DW_AT_low_pc);
return unit->getRanges(*this, lowpc.valid() ? uintmax_t(lowpc) : 0);
}
Expand Down
24 changes: 12 additions & 12 deletions dwarf_info.cc
Original file line number Diff line number Diff line change
Expand Up @@ -48,14 +48,14 @@ CFI *Info::getCFI() const {
}

Info::Info(Elf::Object::sptr obj, ImageCache &cache_)
: elf(obj)
, debugInfo(obj->getDebugSection(".debug_info", SHT_NULL))
, debugStrings(obj->getDebugSection(".debug_str", SHT_NULL))
, debugLineStrings(obj->getDebugSection(".debug_line_str", SHT_NULL))
, debugRanges(obj->getDebugSection(".debug_ranges", SHT_NULL))
, debugStrOffsets(obj->getDebugSection(".debug_str_offsets", SHT_NULL))
, debugAddr(obj->getDebugSection(".debug_addr", SHT_NULL))
, debugRangelists(obj->getDebugSection(".debug_rnglists", SHT_NULL))
: elf(std::move(obj))
, debugInfo(elf->getDebugSection(".debug_info", SHT_NULL))
, debugStrings(elf->getDebugSection(".debug_str", SHT_NULL))
, debugLineStrings(elf->getDebugSection(".debug_line_str", SHT_NULL))
, debugRanges(elf->getDebugSection(".debug_ranges", SHT_NULL))
, debugStrOffsets(elf->getDebugSection(".debug_str_offsets", SHT_NULL))
, debugAddr(elf->getDebugSection(".debug_addr", SHT_NULL))
, debugRangelists(elf->getDebugSection(".debug_rnglists", SHT_NULL))
, imageCache(cache_)
{
}
Expand Down Expand Up @@ -157,7 +157,7 @@ Info::offsetToDIE(Elf::Off offset) const
Units
Info::getUnits() const
{
return { shared_from_this() };
return Units{ shared_from_this() };
}

void
Expand Down Expand Up @@ -222,7 +222,7 @@ Info::lookupUnit(Elf::Addr addr) const {
(*aranges)[high] = std::make_pair(high - low, u->offset);
}
// do we have ranges for this DIE?
const Ranges *ranges = root.getRanges();
const auto &ranges = root.getRanges();
if (ranges != nullptr)
for (auto r : *ranges)
(*aranges)[r.second] = { r.first, u->offset };
Expand Down Expand Up @@ -259,7 +259,7 @@ std::unique_ptr<LineInfo>
Info::linesAt(intmax_t offset, Unit &unit) const
{
auto lines = std::make_unique<LineInfo>();
auto &lineshdr = elf->getDebugSection(".debug_line", SHT_NULL);
const Elf::Section &lineshdr = elf->getDebugSection(".debug_line", SHT_NULL);
if (lineshdr) {
DWARFReader r(lineshdr.io(), offset);
lines->build(r, unit);
Expand All @@ -270,7 +270,7 @@ Info::linesAt(intmax_t offset, Unit &unit) const
std::string
Info::getAltImageName() const
{
auto &section = elf->getDebugSection(".gnu_debugaltlink", SHT_NULL);
const Elf::Section &section = elf->getDebugSection(".gnu_debugaltlink", SHT_NULL);
const auto &name = section.io()->readString(0);
if (name[0] == '/')
return name;
Expand Down
12 changes: 6 additions & 6 deletions dwarf_lines.cc
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ readEntryFormats(DWARFReader &r) {
auto format_count = r.getu8();
std::vector<std::pair<DW_LNCT, Form>> entry_formats;
for (int i = 0; i < format_count; ++i) {
DW_LNCT typeCode = DW_LNCT(r.getuleb128());
auto typeCode = DW_LNCT(r.getuleb128());
auto formCode = Form(r.getuleb128());
rv.emplace_back(typeCode, formCode);
}
Expand All @@ -33,7 +33,7 @@ LineState::LineState(LineInfo *li)
, discriminator{ 0 }
{}

static void
void
dwarfStateAddRow(LineInfo *li, const LineState &state)
{
li->matrix.push_back(state);
Expand Down Expand Up @@ -187,7 +187,6 @@ LineInfo::build(DWARFReader &r, Unit &unit)
} else {
/* Standard opcode. */
auto opcode = LineSOpcode(c);
int argCount, i;
switch (opcode) {
case DW_LNS_const_add_pc:
state.addr += ((255 - opcode_base) / line_range) * min_insn_length;
Expand Down Expand Up @@ -226,12 +225,13 @@ LineInfo::build(DWARFReader &r, Unit &unit)
case DW_LNS_set_isa:
state.isa = r.getuleb128();
break;
default:
default: {
abort();
argCount = opcode_lengths[opcode - 1];
for (i = 0; i < argCount; i++)
int argCount = opcode_lengths[opcode - 1];
for (int i = 0; i < argCount; i++)
r.getuleb128();
break;
}
case DW_LNS_none:
break;
}
Expand Down
1 change: 1 addition & 0 deletions dwarf_reader.cc
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ DWARFReader::readFormUnsigned(Form form)
intmax_t
DWARFReader::readFormSigned(Form form)
{
(void)this; // avoid warnings about making this static.
switch (form) {
default:
abort();
Expand Down
4 changes: 2 additions & 2 deletions dwarf_unit.cc
Original file line number Diff line number Diff line change
Expand Up @@ -209,12 +209,12 @@ Unit::findAbbreviation(size_t code) const
return it != abbreviations.end() ? &it->second : nullptr;
}

const Ranges *
const std::unique_ptr<Ranges> &
Unit::getRanges(const DIE &die, uintmax_t base) {
auto &ptr = rangesForOffset[die.offset];
if (ptr == nullptr)
ptr = std::make_unique<Ranges>(die, base);
return ptr.get();
return ptr;
}

void
Expand Down
4 changes: 2 additions & 2 deletions dwarfproc.cc
Original file line number Diff line number Diff line change
Expand Up @@ -409,11 +409,11 @@ ExpressionStack::eval(Process &proc, Dwarf::DWARFReader &r, const StackFrame *fr
auto unit = loc.die().getUnit();
auto off = r.getuint(4);
auto die = unit->offsetToDIE(DIE(), off + unit->offset);
std::clog << die << "\n";
std::clog << json(die) << "\n";
auto attr = die.attribute(DW_AT_type);
if (attr) {
auto typeDie = DIE(attr);
std::clog << typeDie << "\n";
std::clog << json(typeDie) << "\n";
}
std::clog << "\n";
return -1;
Expand Down
Loading

0 comments on commit 7d5c652

Please sign in to comment.