diff options
author | Jiong Wang <jiong.wang@arm.com> | 2017-04-26 14:05:03 +0100 |
---|---|---|
committer | Jiong Wang <jiong.wang@arm.com> | 2017-04-26 14:05:03 +0100 |
commit | b41c5a85a734b9ca813d4a314b66ef4b4b4d1b11 (patch) | |
tree | 2203099a235d7fbec6066ef8896d4d4ebab0292b /gdb/dwarf2-frame.c | |
parent | 23ec1e32b1ab714649a7c25e49b5d721fe3bd3db (diff) | |
download | gdb-b41c5a85a734b9ca813d4a314b66ef4b4b4d1b11.zip gdb-b41c5a85a734b9ca813d4a314b66ef4b4b4d1b11.tar.gz gdb-b41c5a85a734b9ca813d4a314b66ef4b4b4d1b11.tar.bz2 |
[gdbarch] New method "execute_dwarf_cfa_vendor_op" and migrate SPARC to it
Recently a feature called "return address signing" has been added to GCC to
prevent stack smash stack on AArch64. For details please refer:
https://gcc.gnu.org/ml/gcc-patches/2017-01/msg00376.html
GDB needs to be aware of this feature so it can restore the original return
address which is critical for unwinding.
On compiler side, whenever return address, i.e. LR register, is mangled or
restored by hardware instruction, compiler is expected to generate a
DW_CFA_AARCH64_negate_ra_state to toggle return address signing status.
DW_CFA_AARCH64_negate_ra_state is using the same CFI number and
therefore need to be multiplexed with DW_CFA_GNU_window_save which was designed
for SPARC.
A new gdbarch method "execute_dwarf_cfa_vendor_op" is introduced by this patch.
It's parameters has been restricted to those only needed by SPARC and AArch64
for multiplexing DW_CFA_GNU_window_save which is a CFI operation takes none
operand. Should any further DWARF CFI operation want to be multiplexed in the
future, the parameter list can be extended. Below is the current function
prototype.
typedef int (gdbarch_execute_dwarf_cfa_vendor_op_ftype)
(struct gdbarch *gdbarch, gdb_byte op, struct dwarf2_frame_state *fs);
DW_CFA_GNU_window_save support for SPARC is migrated to this new gdbarch
method by this patch.
gdb/
* gdbarch.sh: New gdbarch method execute_dwarf_cfa_vendor_op.
* gdbarch.c: Regenerated.
* gdbarch.h: Regenerated.
* dwarf2-frame.c (dwarf2_frame_state_alloc_regs): Made the
visibility external.
(execute_cfa_program): Call execute_dwarf_cfa_vendor_op for CFI
between DW_CFA_lo_user and DW_CFA_high_user inclusive.
(enum cfa_how_kind): Move to ...
(struct dwarf2_frame_state_reg_info): Likewise.
(struct dwarf2_frame_state): Likewise.
* dwarf2-frame.h: ... here.
(dwarf2_frame_state_alloc_regs): New declaration.
* sparc-tdep.c (sparc_execute_dwarf_cfa_vendor_op): New function.
(sparc32_gdbarch_init): Register execute_dwarf_cfa_vendor_op hook.
Diffstat (limited to 'gdb/dwarf2-frame.c')
-rw-r--r-- | gdb/dwarf2-frame.c | 92 |
1 files changed, 12 insertions, 80 deletions
diff --git a/gdb/dwarf2-frame.c b/gdb/dwarf2-frame.c index f8dd1df..d7f985b 100644 --- a/gdb/dwarf2-frame.c +++ b/gdb/dwarf2-frame.c @@ -165,58 +165,6 @@ static CORE_ADDR read_encoded_value (struct comp_unit *unit, gdb_byte encoding, CORE_ADDR func_base); -enum cfa_how_kind -{ - CFA_UNSET, - CFA_REG_OFFSET, - CFA_EXP -}; - -struct dwarf2_frame_state_reg_info -{ - struct dwarf2_frame_state_reg *reg; - int num_regs; - - LONGEST cfa_offset; - ULONGEST cfa_reg; - enum cfa_how_kind cfa_how; - const gdb_byte *cfa_exp; - - /* Used to implement DW_CFA_remember_state. */ - struct dwarf2_frame_state_reg_info *prev; -}; - -/* Structure describing a frame state. */ - -struct dwarf2_frame_state -{ - /* Each register save state can be described in terms of a CFA slot, - another register, or a location expression. */ - struct dwarf2_frame_state_reg_info regs; - - /* The PC described by the current frame state. */ - CORE_ADDR pc; - - /* Initial register set from the CIE. - Used to implement DW_CFA_restore. */ - struct dwarf2_frame_state_reg_info initial; - - /* The information we care about from the CIE. */ - LONGEST data_align; - ULONGEST code_align; - ULONGEST retaddr_column; - - /* Flags for known producer quirks. */ - - /* The ARM compilers, in DWARF2 mode, assume that DW_CFA_def_cfa - and DW_CFA_def_cfa_offset takes a factored offset. */ - int armcc_cfa_offsets_sf; - - /* The ARM compilers, in DWARF2 or DWARF3 mode, may assume that - the CFA is defined as REG - OFFSET rather than REG + OFFSET. */ - int armcc_cfa_offsets_reversed; -}; - /* Store the length the expression for the CFA in the `cfa_reg' field, which is unused in that case. */ #define cfa_exp_len cfa_reg @@ -224,7 +172,7 @@ struct dwarf2_frame_state /* Assert that the register set RS is large enough to store gdbarch_num_regs columns. If necessary, enlarge the register set. */ -static void +void dwarf2_frame_state_alloc_regs (struct dwarf2_frame_state_reg_info *rs, int num_regs) { @@ -672,31 +620,6 @@ bad CFI data; mismatched DW_CFA_restore_state at %s"), /* cfa_how deliberately not set. */ break; - case DW_CFA_GNU_window_save: - /* This is SPARC-specific code, and contains hard-coded - constants for the register numbering scheme used by - GCC. Rather than having a architecture-specific - operation that's only ever used by a single - architecture, we provide the implementation here. - Incidentally that's what GCC does too in its - unwinder. */ - { - int size = register_size (gdbarch, 0); - - dwarf2_frame_state_alloc_regs (&fs->regs, 32); - for (reg = 8; reg < 16; reg++) - { - fs->regs.reg[reg].how = DWARF2_FRAME_REG_SAVED_REG; - fs->regs.reg[reg].loc.reg = reg + 16; - } - for (reg = 16; reg < 32; reg++) - { - fs->regs.reg[reg].how = DWARF2_FRAME_REG_SAVED_OFFSET; - fs->regs.reg[reg].loc.offset = (reg - 16) * size; - } - } - break; - case DW_CFA_GNU_args_size: /* Ignored. */ insn_ptr = safe_read_uleb128 (insn_ptr, insn_end, &utmp); @@ -713,8 +636,17 @@ bad CFI data; mismatched DW_CFA_restore_state at %s"), break; default: - internal_error (__FILE__, __LINE__, - _("Unknown CFI encountered.")); + if (insn >= DW_CFA_lo_user && insn <= DW_CFA_hi_user) + { + /* Handle vendor-specific CFI for different architectures. */ + if (!gdbarch_execute_dwarf_cfa_vendor_op (gdbarch, insn, fs)) + error (_("Call Frame Instruction op %d in vendor extension " + "space is not handled on this architecture."), + insn); + } + else + internal_error (__FILE__, __LINE__, + _("Unknown CFI encountered.")); } } } |