Skip to content

Commit

Permalink
throw, don't abort
Browse files Browse the repository at this point in the history
  • Loading branch information
peadar committed Jan 1, 2025
1 parent 3ba9a42 commit 9e4728e
Show file tree
Hide file tree
Showing 7 changed files with 31 additions and 42 deletions.
23 changes: 9 additions & 14 deletions dwarf_die.cc
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,7 @@ DIE::containsAddress(Elf::Addr addr) const
start = uintmax_t(low);
break;
default:
abort();
break;
throw (Exception() << "unhandled form " << low.form() << " for DW_AT_low_pc");
}

switch (high.form()) {
Expand All @@ -89,7 +88,7 @@ DIE::containsAddress(Elf::Addr addr) const
end = start + uintmax_t(high);
break;
default:
abort();
throw (Exception() << "unhandled form " << high.form() << " for DW_AT_high_pc");
}
return start <= addr && end > addr ? ContainsAddr::YES : ContainsAddr::NO;
}
Expand Down Expand Up @@ -318,9 +317,7 @@ DIE::Attribute::Value::Value(DWARFReader &r, const FormEntry &forment, Unit *uni
break;

default:
addr = 0;
abort();
break;
throw (Exception() << "unhandled form " << forment.form << " creating value for DIE");
}
}

Expand Down Expand Up @@ -429,7 +426,7 @@ DIE::Attribute::operator intmax_t() const
case DW_FORM_sec_offset:
return value().addr;
default:
abort();
throw (Exception() << "no conversion from form " << formp->form << " to intmax_t");
}
}

Expand Down Expand Up @@ -459,7 +456,7 @@ DIE::Attribute::operator uintmax_t() const
case DW_FORM_rnglistx:
return die.unit->rnglistx(value().udata);
default:
abort();
throw (Exception() << "no conversion from form " << formp->form << " to uintmax_t");
}
}

Expand Down Expand Up @@ -504,8 +501,7 @@ Ranges::Ranges(const DIE &die, uintmax_t base) {
case DW_RLE_startx_endx: {
/* auto startx = */ r.getuleb128();
/* auto endx = */ r.getuleb128();
abort();
break;
throw (Exception() << "DW_RLE_startx_endx is not handled");
}

case DW_RLE_startx_length: {
Expand Down Expand Up @@ -539,7 +535,7 @@ Ranges::Ranges(const DIE &die, uintmax_t base) {
break;
}
default:
abort();
throw (Exception() << "unhandled DW_RLE_ entry " << entryType);
}
}
}
Expand Down Expand Up @@ -579,7 +575,7 @@ DIE::Attribute::operator std::string() const
return die.unit->strx(value().addr);

default:
abort();
throw (Exception() << "no conversion from form " << formp->form << " to string");
}
}

Expand Down Expand Up @@ -609,8 +605,7 @@ DIE::Attribute::operator DIE() const
break;
}
default:
abort();
break;
throw (Exception() << "no conversion from form " << formp->form << " to DIE");
}

// Try this unit first (if we're dealing with the same Info)
Expand Down
10 changes: 4 additions & 6 deletions dwarf_frame.cc
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ CFI::decodeAddress(DWARFReader &f, uint8_t encoding, uintptr_t sectionVa) const
base = f.getint(sizeof (Elf::Word));
break;
default:
__builtin_unreachable();
throw (Exception() << "unhandled encoding " << (encoding & 0xfU) << " while decoding CFI address");
}

switch (encoding & 0xf0U & ~unsigned(DW_EH_PE_indirect)) {
Expand All @@ -60,8 +60,7 @@ CFI::decodeAddress(DWARFReader &f, uint8_t encoding, uintptr_t sectionVa) const
}

default:
abort();
break;
throw (Exception() << "unhandled base encoding inforation " << (encoding & 0xf0U) << " while decoding CFI address");
}
return { base, (encoding & DW_EH_PE_indirect ) != 0 };
}
Expand Down Expand Up @@ -448,13 +447,12 @@ CIE::execInsns(DWARFReader &r, uintmax_t addr, uintmax_t wantAddr) const
case DW_CFA_GNU_window_save:
case DW_CFA_GNU_negative_offset_extended:
default:
abort();
throw (Exception() << "unhandled secondary CFA instruction " << op);
}
break;

default:
abort();
break;
throw (Exception() << "unhandled CFA instruction " << op);
}
}
return frame;
Expand Down
6 changes: 2 additions & 4 deletions dwarf_lines.cc
Original file line number Diff line number Diff line change
Expand Up @@ -180,8 +180,7 @@ LineInfo::build(DWARFReader &r, Unit &unit)
break;
default:
r.skip(len - 1);
abort();
break;
throw (Exception() << "unhandled DW_LNE_ instruction in line data");
}
} else {
/* Standard opcode. */
Expand Down Expand Up @@ -225,11 +224,10 @@ LineInfo::build(DWARFReader &r, Unit &unit)
state.isa = r.getuleb128();
break;
default: {
abort();
int argCount = opcode_lengths[opcode - 1];
for (int i = 0; i < argCount; i++)
r.getuleb128();
break;
throw (Exception() << "unhandled DW_LNS_ instruction in line data");
}
case DW_LNS_none:
break;
Expand Down
11 changes: 6 additions & 5 deletions dwarf_reader.cc
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ DWARFReader::readForm(const Info &info, Unit &unit, Form form)
return;

default:
abort();
throw (Exception() << "unhandled form when reading form " << form);
}
}

Expand All @@ -27,8 +27,6 @@ DWARFReader::readFormString(const Info &dwarf, Unit &unit, Form form)
switch (form) {
case DW_FORM_string:
return getstring();
default:
abort();
case DW_FORM_line_strp: {
auto off = getuint(unit.dwarfLen);
return dwarf.debugLineStrings.io()->readString(off);
Expand All @@ -41,6 +39,9 @@ DWARFReader::readFormString(const Info &dwarf, Unit &unit, Form form)
size_t off = getuleb128();
return unit.strx(off);
}
default: {
throw (Exception() << "unhandled form " << form << " when reading string");
}
}
}

Expand All @@ -57,7 +58,7 @@ DWARFReader::readFormUnsigned(Form form)
case DW_FORM_data4:
return getu32();
default:
abort();
throw (Exception() << "unhandled form " << form << " when reading unsigned");
}
}

Expand All @@ -67,7 +68,7 @@ DWARFReader::readFormSigned(Form form)
(void)this; // avoid warnings about making this static.
switch (form) {
default:
abort();
throw (Exception() << "unhandled form " << form << " when reading signed");
}
}

Expand Down
2 changes: 1 addition & 1 deletion dwarf_unit.cc
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ Unit::Unit(const Info *di, DWARFReader &r)
r.getBytes(sizeof id, &id[0]);
break;
default:
abort();
throw (Exception() << "unhandled DW_UT_ unit type value " << unitType);
}
} else {
abbrevOffset = r.getuint(version <= 2 ? 4 : dwarfLen);
Expand Down
15 changes: 5 additions & 10 deletions dwarfproc.cc
Original file line number Diff line number Diff line change
Expand Up @@ -163,9 +163,8 @@ ExpressionStack::eval(Process &proc, const Dwarf::DIE::Attribute &attr,
r.skip(len);
break;
}

default:
abort(); // can implement it when we see it.
throw (Exception() << "unhandled DW_LLE_" << lle);
}
}
} else {
Expand All @@ -187,7 +186,7 @@ ExpressionStack::eval(Process &proc, const Dwarf::DIE::Attribute &attr,
r.skip(len);
}
}
abort();
throw (Exception() << ".debug_loc search failed");

case Dwarf::DW_FORM_block1:
case Dwarf::DW_FORM_block:
Expand All @@ -197,7 +196,7 @@ ExpressionStack::eval(Process &proc, const Dwarf::DIE::Attribute &attr,
return eval(proc, r, frame, reloc);
}
default:
abort();
throw (Exception() << "unhandled attribute form " << attr.form() << " evaluating expression");
}
}

Expand Down Expand Up @@ -425,10 +424,7 @@ ExpressionStack::eval(Process &proc, Dwarf::DWARFReader &r, const StackFrame *fr
// FALLTHROUGH

default:
abort();
if (proc.context.debug)
*proc.context.debug << "error evaluating DWARF OP " << op << " (" << int(op) << ")\n";
return -1;
throw (Exception() << "error evaluating DWARF OP " << op << " (" << int(op) << ")");
}
}
return poptop();
Expand Down Expand Up @@ -481,8 +477,7 @@ std::optional<Elf::CoreRegisters> StackFrame::unwind(Process &p) {
case VAL_OFFSET:
case VAL_EXPRESSION:
case REG:
abort();
break;
throw (Exception() << "unhandled CFA value type " << dcf.cfaValue.type);

case OFFSET:
cfa = Elf::getReg(regs, dcf.cfaReg) + dcf.cfaValue.u.offset;
Expand Down
6 changes: 4 additions & 2 deletions process.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

#include <link.h>
#include <unistd.h>
#include <charconv>

#include <iomanip>
#include <iostream>
Expand Down Expand Up @@ -1038,9 +1039,10 @@ ThreadStack::unwind(Process &p, Elf::CoreRegisters &regs)
std::shared_ptr<Process>
Process::load(Context &context, Elf::Object::sptr exec, std::string id) {
pid_t pid;
std::istringstream(id) >> pid;
auto [ ptr, ec ] = std::from_chars(id.data(), id.data() + id.size(), pid);

std::shared_ptr<Process> proc;
if (pid != 0) {
if (ec == std::errc() && ptr == id.data() + id.size()) {
if (kill(pid, 0) != 0)
throw Exception() << "process " << pid << ": " << strerror(errno);
proc = std::make_shared<LiveProcess>(context, exec, pid);
Expand Down

0 comments on commit 9e4728e

Please sign in to comment.