Issue 241198
Summary [LLDB] DW_OP_piece unit test treats memory locations as immediate values
Labels new issue
Assignees
Reporter MrEven132
    The DW_OP_piece test in [lldb/unittests/_expression_/DWARFExpressionTest.cpp](https://github.com/llvm/llvm-project/blob/main/lldb/unittests/_expression_/DWARFExpressionTest.cpp)

```C++
TEST(DWARFExpression, DW_OP_piece) {
  EXPECT_THAT_EXPECTED(Evaluate({DW_OP_const2u, 0x11, 0x22, DW_OP_piece, 2,
                                 DW_OP_const2u, 0x33, 0x44, DW_OP_piece, 2}),
                       ExpectHostAddress({0x11, 0x22, 0x33, 0x44}));
  EXPECT_THAT_EXPECTED(
      Evaluate({DW_OP_piece, 1, DW_OP_const1u, 0xff, DW_OP_piece, 1}),
      // Note that the "00" should really be "undef", but we can't
      // represent that yet.
 ExpectHostAddress({0x00, 0xff}));

  // This tests if ap_int is extended to the right width.
  // expect 40*8 = 320 bits size.
  std::vector<uint8_t> expected_host_buffer(40, 0);
  expected_host_buffer[0] = 2;

 EXPECT_THAT_EXPECTED(
      Evaluate({{DW_OP_lit2, DW_OP_stack_value, DW_OP_piece, 40}}),
 ExpectHostAddress(expected_host_buffer));
}
```

The first assertion appears to interpret the constants preceding DW_OP_piece as immediate values. However, DW_OP_const2u only pushes a constant onto the _expression_ stack. Without DW_OP_stack_value, each _expression_ preceding DW_OP_piece describes a memory location.

For the little-endian configuration used by this test, the first _expression_ should describe a four-byte object whose:
- Low two bytes reside at address 0x2211.
- High two bytes reside at address 0x4433.

The resulting bytes depend on memory contents at those addresses; they are not necessarily {0x11, 0x22, 0x33, 0x44}.

If the intention is to assemble two immediate values, DW_OP_stack_value should be added before each DW_OP_piece:

```C++
EXPECT_THAT_EXPECTED(
    Evaluate({DW_OP_const2u, 0x11, 0x22, DW_OP_stack_value, DW_OP_piece, 2,
              DW_OP_const2u, 0x33, 0x44, DW_OP_stack_value, DW_OP_piece, 2}),
 ExpectHostAddress({0x11, 0x22, 0x33, 0x44}));
```

The second assertion has the same issue: DW_OP_const1u, 0xff, DW_OP_piece, 1 describes a one-byte piece at address 0xff. It also needs DW_OP_stack_value if the intended piece value is 0xff.
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to