]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commit
gdb/dwarf: use offset in dwarf_expr_context::read_mem
authorSimon Marchi <simon.marchi@polymtl.ca>
Tue, 18 Nov 2025 03:38:23 +0000 (22:38 -0500)
committerSimon Marchi <simon.marchi@polymtl.ca>
Wed, 19 Nov 2025 19:41:57 +0000 (14:41 -0500)
commitcc4c8e4ca8b9fe7f04e2ee4614cca96e9cc90044
tree3dd3977ccad9f107fe7c88421a8b3bc5ed95eaf0
parentbf6187c92e596ef4bf934d430c570fa68a7f7176
gdb/dwarf: use offset in dwarf_expr_context::read_mem

The `offset` variable is the offset within the passed-in object where
`addr` falls.  We use it to verify whether `addr` falls within that
object's bounds, but then the memcpy fails to consider it, meaning that
we always copy from the beginning of the passed-in object, even if
`addr` lands in the middle of the object.  Fix that by adding `offset`
to the source argument of the memcpy.  I caught this by writing a patch
later in this series, so this fix is covered by the test added in that
later patch.

Also, I find it a bit odd to compute the offset of `addr` within the
passed-in object, before knowing if `addr` even lands within the
passed-in object's address range.  If `addr` is before the object's
address, it does an unsigned underflow, which I guess works, but is not
really intuitive.  Change it to check whether `addr` falls within the
object first, and if so, compute the offset of `addr` within the object.

Change-Id: Ibbacab6d57e693e02e2bdfec4f3a7d42d9a1bd4b
Approved-By: Tom Tromey <tom@tromey.com>
gdb/dwarf2/expr.c