+/* See dwarf2-frame.h. */
+
+int
+dwarf2_fetch_cfa_info (struct gdbarch *gdbarch, CORE_ADDR pc,
+ struct dwarf2_per_cu_data *data,
+ int *regnum_out, LONGEST *offset_out,
+ CORE_ADDR *text_offset_out,
+ const gdb_byte **cfa_start_out,
+ const gdb_byte **cfa_end_out)
+{
+ struct dwarf2_fde *fde;
+ CORE_ADDR text_offset;
+ CORE_ADDR pc1 = pc;
+
+ /* Find the correct FDE. */
+ fde = dwarf2_frame_find_fde (&pc1, &text_offset);
+ if (fde == NULL)
+ error (_("Could not compute CFA; needed to translate this expression"));
+
+ dwarf2_frame_state fs (pc1, fde->cie);
+
+ /* Check for "quirks" - known bugs in producers. */
+ dwarf2_frame_find_quirks (&fs, fde);
+
+ /* First decode all the insns in the CIE. */
+ execute_cfa_program (fde, fde->cie->initial_instructions,
+ fde->cie->end, gdbarch, pc, &fs);
+
+ /* Save the initialized register set. */
+ fs.initial = fs.regs;
+
+ /* Then decode the insns in the FDE up to our target PC. */
+ execute_cfa_program (fde, fde->instructions, fde->end, gdbarch, pc, &fs);
+
+ /* Calculate the CFA. */
+ switch (fs.regs.cfa_how)
+ {
+ case CFA_REG_OFFSET:
+ {
+ int regnum = dwarf_reg_to_regnum_or_error (gdbarch, fs.regs.cfa_reg);
+
+ *regnum_out = regnum;
+ if (fs.armcc_cfa_offsets_reversed)
+ *offset_out = -fs.regs.cfa_offset;
+ else
+ *offset_out = fs.regs.cfa_offset;
+ return 1;
+ }
+
+ case CFA_EXP:
+ *text_offset_out = text_offset;
+ *cfa_start_out = fs.regs.cfa_exp;
+ *cfa_end_out = fs.regs.cfa_exp + fs.regs.cfa_exp_len;
+ return 0;
+
+ default:
+ internal_error (__FILE__, __LINE__, _("Unknown CFA rule."));
+ }
+}
+
+\f