Hi Fangrui,

On Mon, 2025-11-10 at 10:03 -0800, Fangrui Song wrote:
> On Mon, Nov 10, 2025 at 9:16 AM Ben Woodard via Dwarf-discuss
> <[email protected]> wrote:
> > > For GDB there might be some assumption it
> > >    would be modulo using floored division.
> > Yes it breaks GDB's current implementation but other consumers have
> > interpreted it as truncated division. If you add DW_OP_modulo, GDB's
> > current implementation could be used for that and DW_OP_mod could be
> > implemented with % like it is in other consumers.
> 
> While gdb's comment mentions Knuth 1.2.4, the implementation actually
> uses truncating remainder when the divisor is not 0
> `v = v1 / v2; v = v1 - (v2 * v);`  (v1/v2 computes the truncating
> quotient with mpz_tdiv_q)
> 
> https://sourceware.org/cgit/binutils-gdb/tree/gdb/valarith.c#n1277

O! Thanks for that. So besides using truncating division it also works
when the divisor is zero. But DW_OP_div raises an error on division by
zero.

Does it make sense to explicitly define what it means when the divisor
is zero? Or is it fine to make the expression "undefined" or error out
in that case?

Cheers,

Mark
-- 
Dwarf-discuss mailing list
[email protected]
https://lists.dwarfstd.org/mailman/listinfo/dwarf-discuss

Reply via email to