This comes from: https://lists.dwarfstd.org/pipermail/dwarf-discuss/2024-February/002375.html https://dwarfstd.org/issues/181205.1.html gdb should reset the DWARF expression stack after a piece operation. Apparently nobody noticed this text in 2.6.1 "Single Location Descriptions": Each simple location description that is a DWARF expression is evaluated independently of any others. Also an empty first piece is ok.
I'm not sure there's a valid expression that would give a different result if values were left on the stack between pieces. Maybe it can only be done in the situation where an initial value must be pushed. Presumably in the pieced case, the initial value must be pushed before each piece is evaluated.
The empty first piece part works, according to a test case I wrote: (gdb) print s1 $1 = {a = <optimized out>, b = 23}
(In reply to Tom Tromey from comment #1) > Maybe it can only be done in the situation where an initial > value must be pushed. Presumably in the pieced case, > the initial value must be pushed before each piece is > evaluated. It's hard to imagine this even being useful, as the cases where a value is pushed on the stack aren't really ones where a pieced result would be useful or expected. I'll attach my test case here but I think this bug is probably only of pedantic interest; and the bug in the rust support pointed out in those links is, I think, a problem in rust-lang.c. I'll file a separate bug for that.
Created attachment 15382 [details] test case