gdb/add-gdbarch_dwarf2_reg_piece_offset-hook.patch

221 lines
8.8 KiB
Diff
Raw Normal View History

- Maintenance script qa.sh: * Fix 16.0 handling. - Patches added: * gdb-testsuite-fix-gdb.python-py-format-string.exp-wi.patch * gdb-testsuite-fix-gdb.python-py-mi-cmd.exp-with-pyth.patch * gdb-testsuite-fix-gdb.ada-mi_task_arg.exp-on-arm-lin.patch * gdb-testsuite-fix-regexp-in-gdb.ada-mi_var_access.ex.patch * gdb-testsuite-check-gnatmake-version-in-gdb.ada-scal.patch * gdb-testsuite-fix-gdb.arch-arm-pseudo-unwind.exp-wit.patch * gdb-symtab-fix-target-type-of-complex-long-double-on.patch * gdb-testsuite-don-t-use-set-auto-solib-add-off.patch * gdb-tdep-fix-arm-thumb2-hw-breakpoint.patch * gdb-testsuite-fix-gdb.cp-m-static.exp-on-arm.patch * gdb-testsuite-fix-gdb.dwarf2-dw2-fixed-point.exp-on-.patch * gdb-testsuite-fix-gdb.dwarf2-dw2-lines.exp-on-arm-li.patch * gdb-exp-fix-gdb.fortran-intrinsics.exp-fail-on-arm.patch * gdb-tdep-handle-sycall-statx-for-arm-linux.patch * gdb-tdep-fix-recording-of-t1-push.patch * gdb-tdep-handle-syscall-clock_gettime64-for-arm-linu.patch * fix-gdb.dwarf2-shortpiece.exp-on-s390x.patch * handle-address-class-annotation-for-s390x-in-some-te.patch * fix-gdb.dap-step-out.exp-on-s390x.patch * use-setvariable-in-gdb.dap-scopes.exp.patch * fix-gdb.base-finish-pretty.exp-on-s390x.patch * fix-gdb.base-readnever.exp-on-s390x.patch * add-dwarf_expr_piece.op.patch * add-gdbarch_dwarf2_reg_piece_offset-hook.patch * fix-gdb.base-store.exp-on-s390x.patch * fix-gdb.ada-o2_float_param.exp-on-s390x-linux.patch * gdb-testsuite-fix-gdb.base-branch-to-self.exp-on-arm.patch * gdb-tdep-fix-gdb.cp-non-trivial-retval.exp-on-riscv6.patch * gdb-testsuite-fix-gdb.cp-non-trivial-retval.exp-on-a.patch * gdb-testsuite-fix-gdb.rust-completion.exp-timeout-on.patch * gdb-testsuite-require-supports_process_record-in-gdb.patch * gdb-testsuite-fix-regexp-in-gdb.arch-i386-disp-step-.patch * gdb-testsuite-fix-gdb.arch-arm-single-step-kernel-he.patch * gdb-testsuite-fix-gdb.python-py-format-address.exp-o.patch * gdb-testsuite-fix-gdb.arch-riscv-tdesc-regs.exp.patch * gdb-testsuite-fix-gdb.base-list-dot-nodebug-and-make.patch * gdb-testsuite-fix-gdb.base-list-dot-nodebug.exp-on-o.patch * gdb-testsuite-fix-gdb.base-empty-host-env-vars.exp.patch * gdb-prune-inferior-after-switching-inferior.patch * gdb-testsuite-use-nostdlib-in-gdb.base-list-dot-node.patch * gdb-testsuite-fix-timeout-in-gdb.mi-mi-multi-command.patch * gdb-testsuite-require-can_spawn_for_attach-in-gdb.ba.patch * fixup-gdb-6.5-gcore-buffer-limit-test.patch * gdb-testsuite-fix-gdb.ada-big_packed_array.exp-on-s3.patch * gdb-testsuite-fix-gdb.ada-convvar_comp.exp-on-s390x-.patch * gdb-testsuite-fix-regexp-in-gdb.threads-stepi-over-c.patch OBS-URL: https://build.opensuse.org/package/show/devel:gcc/gdb?expand=0&rev=437
2025-02-13 14:36:11 +00:00
From 29b185c531fcd933da62142debcb088321be7c4c Mon Sep 17 00:00:00 2001
From: Tom de Vries <tdevries@suse.de>
Date: Wed, 15 Jan 2025 17:02:00 +0100
Subject: [PATCH 24/46] Add gdbarch_dwarf2_reg_piece_offset hook
In rw_pieced_value, when reading/writing part of a register, DW_OP_piece and
DW_OP_bit_piece are handled the same, but the standard tells us:
- DW_OP_piece: if the piece is located in a register, but does not occupy the
entire register, the placement of the piece within that register is defined
by the ABI.
- DW_OP_bit_piece: if the location is a register, the offset is from the least
significant bit end of the register.
Add a new hook gdbarch_dwarf2_reg_piece_offset that allows us to define the
ABI-specific behaviour for DW_OP_piece.
The default implementation of the hook is the behaviour of DW_OP_bit_piece, so
there should not be any functional changes.
Tested on s390x-linux.
Approved-By: Tom Tromey <tom@tromey.com>
---
gdb/dwarf2/expr.c | 31 +++++++++++++++++++++++++------
gdb/findvar.c | 18 ++++++++++++++++++
gdb/gdbarch-gen.h | 8 ++++++++
gdb/gdbarch.c | 22 ++++++++++++++++++++++
gdb/gdbarch_components.py | 16 ++++++++++++++++
gdb/value.h | 2 ++
6 files changed, 91 insertions(+), 6 deletions(-)
diff --git a/gdb/dwarf2/expr.c b/gdb/dwarf2/expr.c
index 03107f90575..ece713ee7cd 100644
--- a/gdb/dwarf2/expr.c
+++ b/gdb/dwarf2/expr.c
@@ -211,14 +211,33 @@ rw_pieced_value (value *v, value *from, bool check_optimized)
ULONGEST reg_bits = 8 * register_size (arch, gdb_regnum);
int optim, unavail;
- if (gdbarch_byte_order (arch) == BFD_ENDIAN_BIG
- && p->offset + p->size < reg_bits)
+ if (p->offset + p->size < reg_bits)
{
- /* Big-endian, and we want less than full size. */
- bits_to_skip += reg_bits - (p->offset + p->size);
+ /* We want less than full size. */
+
+ if (p->op == DW_OP_piece)
+ {
+ gdb_assert (p->offset == 0);
+
+ /* If the piece is located in a register, but does not
+ occupy the entire register, the placement of the piece
+ within that register is defined by the ABI. */
+ bits_to_skip
+ += 8 * gdbarch_dwarf2_reg_piece_offset (arch, gdb_regnum,
+ p->size / 8);
+ }
+ else if (p->op == DW_OP_bit_piece)
+ {
+ /* If the location is a register, the offset is from the
+ least significant bit end of the register. */
+ if (gdbarch_byte_order (arch) == BFD_ENDIAN_BIG)
+ bits_to_skip += reg_bits - (p->offset + p->size);
+ else
+ bits_to_skip += p->offset;
+ }
+ else
+ error (_("Don't know how to get part of implicit pointer"));
}
- else
- bits_to_skip += p->offset;
this_size = bits_to_bytes (bits_to_skip, this_size_bits);
buffer.resize (this_size);
diff --git a/gdb/findvar.c b/gdb/findvar.c
index df4ab1a28b9..3b20974474a 100644
--- a/gdb/findvar.c
+++ b/gdb/findvar.c
@@ -541,6 +541,24 @@ default_value_from_register (gdbarch *gdbarch, type *type, int regnum,
return value;
}
+/* Default implementation of gdbarch_dwarf2_reg_piece_offset. Implements
+ DW_OP_bits_piece for DW_OP_piece. */
+
+ULONGEST
+default_dwarf2_reg_piece_offset (gdbarch *gdbarch, int gdb_regnum, ULONGEST size)
+{
+ ULONGEST reg_size = register_size (gdbarch, gdb_regnum);
+ gdb_assert (size <= reg_size);
+ if (reg_size == size)
+ return 0;
+
+ if (gdbarch_byte_order (gdbarch) == BFD_ENDIAN_BIG)
+ return reg_size - size;
+
+ return 0;
+}
+
+
/* VALUE must be an lval_register value. If regnum is the value's
associated register number, and len the length of the value's type,
read one or more registers in VALUE's frame, starting with register REGNUM,
diff --git a/gdb/gdbarch-gen.h b/gdb/gdbarch-gen.h
index b982fd7cd09..2e20a9dbccd 100644
--- a/gdb/gdbarch-gen.h
+++ b/gdb/gdbarch-gen.h
@@ -430,6 +430,14 @@ typedef struct value * (gdbarch_value_from_register_ftype) (struct gdbarch *gdba
extern struct value * gdbarch_value_from_register (struct gdbarch *gdbarch, struct type *type, int regnum, const frame_info_ptr &this_frame);
extern void set_gdbarch_value_from_register (struct gdbarch *gdbarch, gdbarch_value_from_register_ftype *value_from_register);
+/* For a DW_OP_piece located in a register, but not occupying the
+ entire register, return the placement of the piece within that
+ register as defined by the ABI. */
+
+typedef ULONGEST (gdbarch_dwarf2_reg_piece_offset_ftype) (struct gdbarch *gdbarch, int regnum, ULONGEST size);
+extern ULONGEST gdbarch_dwarf2_reg_piece_offset (struct gdbarch *gdbarch, int regnum, ULONGEST size);
+extern void set_gdbarch_dwarf2_reg_piece_offset (struct gdbarch *gdbarch, gdbarch_dwarf2_reg_piece_offset_ftype *dwarf2_reg_piece_offset);
+
typedef CORE_ADDR (gdbarch_pointer_to_address_ftype) (struct gdbarch *gdbarch, struct type *type, const gdb_byte *buf);
extern CORE_ADDR gdbarch_pointer_to_address (struct gdbarch *gdbarch, struct type *type, const gdb_byte *buf);
extern void set_gdbarch_pointer_to_address (struct gdbarch *gdbarch, gdbarch_pointer_to_address_ftype *pointer_to_address);
diff --git a/gdb/gdbarch.c b/gdb/gdbarch.c
index 58e9ebbdc59..ed5b5859277 100644
--- a/gdb/gdbarch.c
+++ b/gdb/gdbarch.c
@@ -109,6 +109,7 @@ struct gdbarch
gdbarch_register_to_value_ftype *register_to_value = nullptr;
gdbarch_value_to_register_ftype *value_to_register = nullptr;
gdbarch_value_from_register_ftype *value_from_register = default_value_from_register;
+ gdbarch_dwarf2_reg_piece_offset_ftype *dwarf2_reg_piece_offset = default_dwarf2_reg_piece_offset;
gdbarch_pointer_to_address_ftype *pointer_to_address = unsigned_pointer_to_address;
gdbarch_address_to_pointer_ftype *address_to_pointer = unsigned_address_to_pointer;
gdbarch_integer_to_address_ftype *integer_to_address = nullptr;
@@ -371,6 +372,7 @@ verify_gdbarch (struct gdbarch *gdbarch)
/* Skip verify of value_from_register, invalid_p == 0 */
/* Skip verify of pointer_to_address, invalid_p == 0 */
/* Skip verify of address_to_pointer, invalid_p == 0 */
+ /* Skip verify of dwarf2_reg_piece_offset, invalid_p == 0. */
/* Skip verify of integer_to_address, has predicate. */
/* Skip verify of return_value, invalid_p == 0 */
if ((gdbarch->return_value_as_value == default_gdbarch_return_value) == (gdbarch->return_value == nullptr))
@@ -783,6 +785,9 @@ gdbarch_dump (struct gdbarch *gdbarch, struct ui_file *file)
gdb_printf (file,
"gdbarch_dump: value_from_register = <%s>\n",
host_address_to_string (gdbarch->value_from_register));
+ gdb_printf (file,
+ "gdbarch_dump: dwarf2_reg_piece_offset = <%s>\n",
+ host_address_to_string (gdbarch->dwarf2_reg_piece_offset));
gdb_printf (file,
"gdbarch_dump: pointer_to_address = <%s>\n",
host_address_to_string (gdbarch->pointer_to_address));
@@ -2573,6 +2578,23 @@ set_gdbarch_value_from_register (struct gdbarch *gdbarch,
gdbarch->value_from_register = value_from_register;
}
+ULONGEST
+gdbarch_dwarf2_reg_piece_offset (struct gdbarch *gdbarch, int regnum, ULONGEST size)
+{
+ gdb_assert (gdbarch != NULL);
+ gdb_assert (gdbarch->dwarf2_reg_piece_offset != NULL);
+ if (gdbarch_debug >= 2)
+ gdb_printf (gdb_stdlog, "gdbarch_dwarf2_reg_piece_offset called\n");
+ return gdbarch->dwarf2_reg_piece_offset (gdbarch, regnum, size);
+}
+
+void
+set_gdbarch_dwarf2_reg_piece_offset (struct gdbarch *gdbarch,
+ gdbarch_dwarf2_reg_piece_offset_ftype dwarf2_reg_piece_offset)
+{
+ gdbarch->dwarf2_reg_piece_offset = dwarf2_reg_piece_offset;
+}
+
CORE_ADDR
gdbarch_pointer_to_address (struct gdbarch *gdbarch, struct type *type, const gdb_byte *buf)
{
diff --git a/gdb/gdbarch_components.py b/gdb/gdbarch_components.py
index 4006380076d..4a228b5d27c 100644
--- a/gdb/gdbarch_components.py
+++ b/gdb/gdbarch_components.py
@@ -829,6 +829,22 @@ allocate and return a struct value with all value attributes
invalid=False,
)
+Method(
+ comment="""
+For a DW_OP_piece located in a register, but not occupying the
+entire register, return the placement of the piece within that
+register as defined by the ABI.
+""",
+ type="ULONGEST",
+ name="dwarf2_reg_piece_offset",
+ params=[
+ ("int", "regnum"),
+ ("ULONGEST", "size")
+ ],
+ predefault="default_dwarf2_reg_piece_offset",
+ invalid=False,
+)
+
Method(
type="CORE_ADDR",
name="pointer_to_address",
diff --git a/gdb/value.h b/gdb/value.h
index 9d7e88d9433..47df66e0961 100644
--- a/gdb/value.h
+++ b/gdb/value.h
@@ -1128,6 +1128,8 @@ extern value *default_value_from_register (gdbarch *gdbarch, type *type,
int regnum,
const frame_info_ptr &this_frame);
+extern ULONGEST default_dwarf2_reg_piece_offset (gdbarch *gdbarch, int regnum, ULONGEST size);
+
extern struct value *value_from_register (struct type *type, int regnum,
const frame_info_ptr &frame);
--
2.43.0