Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Tom Tromey <tromey@redhat.com>
To: Pedro Alves <pedro@codesourcery.com>
Cc: gdb-patches@sourceware.org, Jan Kratochvil <jan.kratochvil@redhat.com>
Subject: FYI: handle DW_OP_call_frame_cfa in AX compiler (Was: [unavailable values part 1, 16/17] don't merge almost but not quite adjacent memory ranges to collect)
Date: Wed, 16 Feb 2011 21:01:00 -0000	[thread overview]
Message-ID: <m3bp2b4tt1.fsf_-_@fleche.redhat.com> (raw)
In-Reply-To: <m339nn6efy.fsf@fleche.redhat.com> (Tom Tromey's message of "Wed,	16 Feb 2011 11:07:29 -0700")

Here is a patch to implement compilation of DW_OP_call_frame_cfa to
agent expressions.

Let me know what you think.

It at least let collection.exp run here.  I'll do a full regression test
against gdbserver sometime soon.

Tom

2011-02-16  Tom Tromey  <tromey@redhat.com>

	* dwarf2loc.c (compile_dwarf_to_ax) <DW_OP_call_frame_cfa>: Use
	dwarf2_compile_cfa_to_ax.
	* dwarf2-frame.h (dwarf2_compile_ftype): New typedef.
	(dwarf2_compile_cfa_to_ax): Declare.
	* dwarf2-frame.c: Include ax.h.
	(execute_cfa_program): Remove 'this_frame' argument; 'gdbarch' and
	'pc'.
	(dwarf2_compile_cfa_to_ax): New function.
	(dwarf2_frame_cache): Update.

diff --git a/gdb/dwarf2-frame.c b/gdb/dwarf2-frame.c
index 48f47af..014da44 100644
--- a/gdb/dwarf2-frame.c
+++ b/gdb/dwarf2-frame.c
@@ -38,6 +38,7 @@
 
 #include "complaints.h"
 #include "dwarf2-frame.h"
+#include "ax.h"
 
 struct comp_unit;
 
@@ -428,13 +429,11 @@ Not implemented: computing unwound register using explicit value operator"));
 
 static void
 execute_cfa_program (struct dwarf2_fde *fde, const gdb_byte *insn_ptr,
-		     const gdb_byte *insn_end, struct frame_info *this_frame,
-		     struct dwarf2_frame_state *fs)
+		     const gdb_byte *insn_end, struct gdbarch *gdbarch,
+		     CORE_ADDR pc, struct dwarf2_frame_state *fs)
 {
   int eh_frame_p = fde->eh_frame_p;
-  CORE_ADDR pc = get_frame_pc (this_frame);
   int bytes_read;
-  struct gdbarch *gdbarch = get_frame_arch (this_frame);
   enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
 
   while (insn_ptr < insn_end && fs->pc <= pc)
@@ -902,6 +901,85 @@ dwarf2_frame_find_quirks (struct dwarf2_frame_state *fs,
 }
 \f
 
+void
+dwarf2_compile_cfa_to_ax (struct agent_expr *expr, struct axs_value *loc,
+			  struct gdbarch *gdbarch,
+			  CORE_ADDR pc,
+			  dwarf2_compile_ftype compile,
+			  struct dwarf2_per_cu_data *data)
+{
+  const int num_regs = gdbarch_num_regs (gdbarch)
+		       + gdbarch_num_pseudo_regs (gdbarch);
+  struct dwarf2_fde *fde;
+  CORE_ADDR text_offset, cfa;
+  struct dwarf2_frame_state fs;
+  int addr_size;
+
+  memset (&fs, 0, sizeof (struct dwarf2_frame_state));
+
+  fs.pc = pc;
+
+  /* Find the correct FDE.  */
+  fde = dwarf2_frame_find_fde (&fs.pc, &text_offset);
+  if (fde == NULL)
+    error (_("Could not compute CFA; needed to translate this expression"));
+
+  /* Extract any interesting information from the CIE.  */
+  fs.data_align = fde->cie->data_alignment_factor;
+  fs.code_align = fde->cie->code_alignment_factor;
+  fs.retaddr_column = fde->cie->return_address_register;
+  addr_size = fde->cie->addr_size;
+
+  /* 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;
+  fs.initial.reg = dwarf2_frame_state_copy_regs (&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 = gdbarch_dwarf2_reg_to_regnum (gdbarch, fs.regs.cfa_reg);
+
+	if (regnum == -1)
+	  error (_("Unable to access DWARF register number %d"),
+		 (int) fs.regs.cfa_reg); /* FIXME */
+	ax_reg (expr, regnum);
+
+	if (fs.regs.cfa_offset != 0)
+	  {
+	    if (fs.armcc_cfa_offsets_reversed)
+	      ax_const_l (expr, - fs.regs.cfa_offset);
+	    else
+	      ax_const_l (expr, fs.regs.cfa_offset);
+	    ax_simple (expr, aop_add);
+	  }
+      }
+      break;
+
+    case CFA_EXP:
+      ax_const_l (expr, text_offset);
+      (*compile) (expr, loc, gdbarch, addr_size,
+		  fs.regs.cfa_exp, fs.regs.cfa_exp + fs.regs.cfa_exp_len,
+		  data);
+      break;
+
+    default:
+      internal_error (__FILE__, __LINE__, _("Unknown CFA rule."));
+    }
+}
+
+\f
 struct dwarf2_frame_cache
 {
   /* DWARF Call Frame Address.  */
@@ -979,14 +1057,15 @@ dwarf2_frame_cache (struct frame_info *this_frame, void **this_cache)
 
   /* First decode all the insns in the CIE.  */
   execute_cfa_program (fde, fde->cie->initial_instructions,
-		       fde->cie->end, this_frame, fs);
+		       fde->cie->end, gdbarch, get_frame_pc (this_frame), fs);
 
   /* Save the initialized register set.  */
   fs->initial = fs->regs;
   fs->initial.reg = dwarf2_frame_state_copy_regs (&fs->regs);
 
   /* Then decode the insns in the FDE up to our target PC.  */
-  execute_cfa_program (fde, fde->instructions, fde->end, this_frame, fs);
+  execute_cfa_program (fde, fde->instructions, fde->end, gdbarch,
+		       get_frame_pc (this_frame), fs);
 
   /* Calculate the CFA.  */
   switch (fs->regs.cfa_how)
diff --git a/gdb/dwarf2-frame.h b/gdb/dwarf2-frame.h
index bf7134d..e8a3e85 100644
--- a/gdb/dwarf2-frame.h
+++ b/gdb/dwarf2-frame.h
@@ -26,6 +26,9 @@
 struct gdbarch;
 struct objfile;
 struct frame_info;
+struct dwarf2_per_cu_data;
+struct agent_expr;
+struct axs_value;
 
 /* Register rule.  */
 
@@ -118,4 +121,26 @@ extern const struct frame_base *
 
 CORE_ADDR dwarf2_frame_cfa (struct frame_info *this_frame);
 
+/* Type of the compilation function for dwarf2_compile_cfa_to_ax.  */
+
+typedef void (*dwarf2_compile_ftype) (struct agent_expr *expr,
+				      struct axs_value *loc,
+				      struct gdbarch *arch,
+				      unsigned int addr_size,
+				      const gdb_byte *op_ptr,
+				      const gdb_byte *op_end,
+				      struct dwarf2_per_cu_data *data);
+
+/* Update the agent expression EXPR with code to compute the CFA for a
+   frame at PC.  GDBARCH is the frame architecture.  The COMPILE
+   function can be used to compile a location expression into EXPR.
+   DATA is passed to COMPILE if needed.  */
+
+extern void dwarf2_compile_cfa_to_ax (struct agent_expr *expr,
+				      struct axs_value *loc,
+				      struct gdbarch *gdbarch,
+				      CORE_ADDR pc,
+				      dwarf2_compile_ftype compile,
+				      struct dwarf2_per_cu_data *data);
+
 #endif /* dwarf2-frame.h */
diff --git a/gdb/dwarf2loc.c b/gdb/dwarf2loc.c
index ac786e4..8840a81 100644
--- a/gdb/dwarf2loc.c
+++ b/gdb/dwarf2loc.c
@@ -1926,7 +1926,9 @@ compile_dwarf_to_ax (struct agent_expr *expr, struct axs_value *loc,
 	  break;
 
 	case DW_OP_call_frame_cfa:
-	  unimplemented (op);
+	  dwarf2_compile_cfa_to_ax (expr, loc, arch, expr->scope,
+				    compile_dwarf_to_ax, per_cu);
+	  loc->kind = axs_lvalue_memory;
 	  break;
 
 	case DW_OP_GNU_push_tls_address:


  reply	other threads:[~2011-02-16 20:18 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-02-07 14:35 [unavailable values part 1, 16/17] don't merge almost but not quite adjacent memory ranges to collect Pedro Alves
2011-02-14 12:01 ` Jan Kratochvil
2011-02-16 13:10   ` Pedro Alves
2011-02-16 18:00     ` Tom Tromey
2011-02-16 18:03       ` Pedro Alves
2011-02-16 18:07         ` Tom Tromey
2011-02-16 18:09           ` Pedro Alves
2011-02-16 18:09       ` Tom Tromey
2011-02-16 21:01         ` Tom Tromey [this message]
2011-02-16 21:31           ` FYI: handle DW_OP_call_frame_cfa in AX compiler Pedro Alves
2011-02-16 21:40             ` Tom Tromey
2011-02-16 23:27               ` Pedro Alves
2011-02-17 16:24                 ` Tom Tromey

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=m3bp2b4tt1.fsf_-_@fleche.redhat.com \
    --to=tromey@redhat.com \
    --cc=gdb-patches@sourceware.org \
    --cc=jan.kratochvil@redhat.com \
    --cc=pedro@codesourcery.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox