http://sourceware.org/git/?p=systemtap.git;a=commit;h=fa2e3415185a28542d419a641ecd6cddd52e3cd9 diff -Naurp systemtap-1.2/loc2c.c systemtap-1.2.oden/loc2c.c --- systemtap-1.2/loc2c.c 2010-03-22 21:51:49.000000000 +0000 +++ systemtap-1.2.oden/loc2c.c 2011-10-17 14:35:02.000000000 +0000 @@ -480,7 +480,6 @@ translate (struct obstack *pool, int ind UNOP (abs, op_abs); BINOP (and, &); BINOP (minus, -); - BINOP (mod, %); BINOP (mul, *); UNOP (neg, -); UNOP (not, ~); @@ -515,9 +514,21 @@ translate (struct obstack *pool, int ind { POP (b); POP (a); - push ("(%s) " STACKFMT " / (%s)" STACKFMT, + push ("dwarf_div_op((%s) " STACKFMT ", (%s) " STACKFMT ")", stack_slot_type (loc, true), a, stack_slot_type (loc, true), b); + used_deref = true; + break; + } + + case DW_OP_mod: + { + POP (b); + POP (a); + push ("dwarf_mod_op((%s) " STACKFMT ", (%s) " STACKFMT ")", + stack_slot_type (loc, false), a, + stack_slot_type (loc, false), b); + used_deref = true; break; } diff -Naurp systemtap-1.2/runtime/loc2c-runtime.h systemtap-1.2.oden/runtime/loc2c-runtime.h --- systemtap-1.2/runtime/loc2c-runtime.h 2010-03-22 21:51:49.000000000 +0000 +++ systemtap-1.2.oden/runtime/loc2c-runtime.h 2011-10-17 14:35:02.000000000 +0000 @@ -82,6 +82,28 @@ }) #endif +/* dwarf_div_op and dwarf_mod_op do division and modulo operations catching any + divide by zero issues. When they detect div_by_zero they "fault" + by jumping to the (slightly misnamed) deref_fault label. */ +#define dwarf_div_op(a,b) ({ \ + if (b == 0) { \ + snprintf(c->error_buffer, sizeof(c->error_buffer), \ + "divide by zero in DWARF operand (DW_OP_div)"); \ + c->last_error = c->error_buffer; \ + goto deref_fault; \ + } \ + a / b; \ +}) +#define dwarf_mod_op(a,b) ({ \ + if (b == 0) { \ + snprintf(c->error_buffer, sizeof(c->error_buffer), \ + "divide by zero in DWARF operand (DW_OP_mod)"); \ + c->last_error = c->error_buffer; \ + goto deref_fault; \ + } \ + a % b; \ +}) + /* PR 10601: user-space (user_regset) register access. */ #if defined(STAPCONF_REGSET) #include <linux/regset.h>