Skip to content

Commit

Permalink
add some previously-unimplemented DW_OP_'s
Browse files Browse the repository at this point in the history
  • Loading branch information
peadar committed Jan 2, 2025
1 parent 9e4728e commit 6e58a97
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 1 deletion.
62 changes: 62 additions & 0 deletions dwarfproc.cc
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,13 @@ ExpressionStack::eval(Process &proc, Dwarf::DWARFReader &r, const StackFrame *fr
break;
}

case DW_OP_plus_uconst: {
auto arg = r.getuleb128();
auto tos = poptop();
push(arg + tos);
break;
}

case DW_OP_breg0: case DW_OP_breg1: case DW_OP_breg2: case DW_OP_breg3:
case DW_OP_breg4: case DW_OP_breg5: case DW_OP_breg6: case DW_OP_breg7:
case DW_OP_breg8: case DW_OP_breg9: case DW_OP_breg10: case DW_OP_breg11:
Expand All @@ -278,20 +285,67 @@ ExpressionStack::eval(Process &proc, Dwarf::DWARFReader &r, const StackFrame *fr
push(op - DW_OP_lit0);
break;

case DW_OP_not: {
auto arg = poptop();
push(~arg);
break;
}

case DW_OP_abs: {
auto arg = intmax_t(poptop());
push(std::abs(arg));
break;
}

case DW_OP_neg: {
auto arg = intmax_t(poptop());
push(-arg);
break;
}

case DW_OP_and: {
auto lhs = poptop();
auto rhs = poptop();
push(lhs & rhs);
break;
}

case DW_OP_div: {
auto denom = intmax_t(poptop());
auto num = intmax_t(poptop());
push(num/denom);
break;
}

case DW_OP_mul: {
auto a = intmax_t(poptop());
auto b = intmax_t(poptop());
push(a*b);
break;
}


case DW_OP_mod: {
auto denom = intmax_t(poptop());
auto num = intmax_t(poptop());
push(num%denom);
break;
}

case DW_OP_or: {
auto lhs = poptop();
auto rhs = poptop();
push(lhs | rhs);
break;
}

case DW_OP_xor: {
auto lhs = poptop();
auto rhs = poptop();
push(lhs ^ rhs);
break;
}

case DW_OP_le: {
auto rhs = poptop();
auto lhs = poptop();
Expand Down Expand Up @@ -347,6 +401,14 @@ ExpressionStack::eval(Process &proc, Dwarf::DWARFReader &r, const StackFrame *fr
push(lhs >> rhs);
break;
}

case DW_OP_shra: {
auto rhs = intmax_t(poptop());
auto lhs = intmax_t(poptop());
push(lhs >> rhs);
break;
}

case DW_OP_addr: {
auto value = r.getuint(r.addrLen);
push(value + reloc);
Expand Down
2 changes: 1 addition & 1 deletion libpstack/dwarf/ops.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ DWARF_OP(DW_OP_rot, 0x17, 0)
DWARF_OP(DW_OP_xderef, 0x18, 0)
DWARF_OP(DW_OP_abs, 0x19, 0)
DWARF_OP(DW_OP_and, 0x1a, 0)
DWARF_OP(DW_OP_div0, 0x1b, 0)
DWARF_OP(DW_OP_div, 0x1b, 0)
DWARF_OP(DW_OP_minus, 0x1c, 0)
DWARF_OP(DW_OP_mod, 0x1d, 0)
DWARF_OP(DW_OP_mul, 0x1e, 0)
Expand Down

0 comments on commit 6e58a97

Please sign in to comment.