[Bug gdb/34424] New: [gdb] DW_OP_bra incorrectly narrows typed conditions before zero test

firmiana402 at gmail dot com via Gdb-prs <[email protected]>
Newsgroups gmane.comp.gdb.bugs.discuss
Message-ID <[email protected]/bugzilla/>
https://sourceware.org/bugzilla/show_bug.cgi?id=34424

            Bug ID: 34424
           Summary: [gdb] DW_OP_bra incorrectly narrows typed conditions
                    before zero test
           Product: gdb
           Version: HEAD
            Status: UNCONFIRMED
          Severity: normal
          Priority: P2
         Component: gdb
          Assignee: unassigned at sourceware dot org
          Reporter: firmiana402 at gmail dot com
  Target Milestone: ---

DWARF v5 Section 2.5.1.5 defines DW_OP_bra as branching when the
popped stack value is not the constant zero.  It does not restrict
the condition to the generic type.  The operation requires only a
zero/nonzero test, not conversion to an 8-byte integer.

GDB currently implements the condition as:

    case DW_OP_bra:
      ...
      val = fetch (0);
      dwarf_require_integral (val->type ());
      if (value_as_long (val) != 0)
        op_ptr += offset;
      pop ();

For example, this expression uses an unsigned 128-bit condition equal
to 2^64 on little-endian x86_64:

    DW_OP_const_type <unsigned __int128>, 16,
        [00 00 00 00 00 00 00 00 01 00 00 00 00 00 00 00]
    DW_OP_bra +5
    DW_OP_const1u 0
    DW_OP_skip +2
    DW_OP_const1u 42
    DW_OP_stack_value

The +5 target is DW_OP_const1u 42.  The condition is unambiguously
nonzero, so the branch must be taken and the final value must be 42.
Instead, value_as_long enters GDB's 8-byte unsigned-integer
extraction path, which rejects the significant ninth byte:

    Value cannot be represented as integer of 8 bytes.

This is specific to the DW_OP_bra condition path.  GDB correctly
evaluates DW_OP_ne on the same 16-byte type: 2^64 != 2^64 produces 0,
while (2^64 + 1) != 2^64 produces 1.  That comparison uses
value_as_mpz rather than narrowing either operand to 8 bytes.

DW_OP_bra should likewise test the condition for zero through a
width-independent integer path instead of value_as_long.

-- 
You are receiving this mail because:
You are on the CC list for the bug.
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.