public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
From: Tom Tromey <tromey@redhat.com>
To: gdb-patches@sourceware.org
Cc: Tom Tromey <tromey@redhat.com>
Subject: [PATCH v2 09/14] split dwarf2_fetch_cfa_info from dwarf2_compile_expr_to_ax
Date: Fri, 20 Jun 2014 15:58:00 -0000	[thread overview]
Message-ID: <1403279874-23781-10-git-send-email-tromey@redhat.com> (raw)
In-Reply-To: <1403279874-23781-1-git-send-email-tromey@redhat.com>

This removes dwarf2_compile_expr_to_ax, replacing it with a utility
function that fetches the CFA data and adding the code to actually
compile to an agent expression directly into
dwarf2_compile_expr_to_ax.  This refactoring lets a later patch reuse
the new dwarf2_fetch_cfa_info.

2014-06-20  Tom Tromey  <tromey@redhat.com>

	* dwarf2loc.c (dwarf2_compile_expr_to_ax) <DW_OP_call_frame_cfa>:
	Update.
	* dwarf2-frame.c (dwarf2_fetch_cfa_info): New function, based on
	dwarf2_compile_cfa_to_ax.
	(dwarf2_compile_cfa_to_ax): Remove.
	* dwarf2-frame.h (dwarf2_fetch_cfa_info): Declare.
	(dwarf2_compile_cfa_to_ax): Remove.
---
 gdb/ChangeLog      | 10 ++++++++++
 gdb/dwarf2-frame.c | 40 +++++++++++++++++++---------------------
 gdb/dwarf2-frame.h | 31 +++++++++++++++++++++----------
 gdb/dwarf2loc.c    | 30 ++++++++++++++++++++++++++++--
 4 files changed, 78 insertions(+), 33 deletions(-)

diff --git a/gdb/dwarf2-frame.c b/gdb/dwarf2-frame.c
index 3e3ba23..bd6a60e 100644
--- a/gdb/dwarf2-frame.c
+++ b/gdb/dwarf2-frame.c
@@ -886,11 +886,15 @@ 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,
-			  struct dwarf2_per_cu_data *data)
+/* 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;
@@ -936,26 +940,20 @@ dwarf2_compile_cfa_to_ax (struct agent_expr *expr, struct axs_value *loc,
 	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);
-	  }
+	*regnum_out = regnum;
+	if (fs.armcc_cfa_offsets_reversed)
+	  *offset_out = -fs.regs.cfa_offset;
+	else
+	  *offset_out = fs.regs.cfa_offset;
+	return 1;
       }
-      break;
 
     case CFA_EXP:
-      ax_const_l (expr, text_offset);
-      dwarf2_compile_expr_to_ax (expr, loc, gdbarch, addr_size,
-				 fs.regs.cfa_exp,
-				 fs.regs.cfa_exp + fs.regs.cfa_exp_len,
-				 data);
-      break;
+      *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."));
diff --git a/gdb/dwarf2-frame.h b/gdb/dwarf2-frame.h
index 0470cac..5ccf0c8 100644
--- a/gdb/dwarf2-frame.h
+++ b/gdb/dwarf2-frame.h
@@ -120,15 +120,26 @@ extern const struct frame_base *
 
 CORE_ADDR dwarf2_frame_cfa (struct frame_info *this_frame);
 
-/* Update the agent expression EXPR with code to compute the CFA for a
-   frame at PC.  GDBARCH is the architecture of the function at PC.
-   This function may call dwarf2_compile_expr_to_ax; DATA is passed
-   through to that function if needed.  */
-
-extern void dwarf2_compile_cfa_to_ax (struct agent_expr *expr,
-				      struct axs_value *loc,
-				      struct gdbarch *gdbarch,
-				      CORE_ADDR pc,
-				      struct dwarf2_per_cu_data *data);
+/* Find the CFA information for PC.
+
+   Return 1 if a register is used for the CFA, or 0 if another
+   expression is used.  Throw an exception on error.
+
+   GDBARCH is the architecture to use.
+   DATA is the per-CU data.
+
+   REGNUM_OUT is an out parameter that is set to the register number.
+   OFFSET_OUT is the offset to use from this register.
+   These are only filled in when 1 is returned.
+
+   TEXT_OFFSET_OUT, CFA_START_OUT, and CFA_END_OUT describe the CFA
+   in other cases.  These are only used when 0 is returned.  */
+
+extern 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);
 
 #endif /* dwarf2-frame.h */
diff --git a/gdb/dwarf2loc.c b/gdb/dwarf2loc.c
index fcab9b9..4275864 100644
--- a/gdb/dwarf2loc.c
+++ b/gdb/dwarf2loc.c
@@ -3308,8 +3308,34 @@ dwarf2_compile_expr_to_ax (struct agent_expr *expr, struct axs_value *loc,
 	  break;
 
 	case DW_OP_call_frame_cfa:
-	  dwarf2_compile_cfa_to_ax (expr, loc, arch, expr->scope, per_cu);
-	  loc->kind = axs_lvalue_memory;
+	  {
+	    int regnum;
+	    CORE_ADDR text_offset;
+	    LONGEST off;
+	    const gdb_byte *cfa_start, *cfa_end;
+
+	    if (dwarf2_fetch_cfa_info (arch, expr->scope, per_cu,
+				       &regnum, &off,
+				       &text_offset, &cfa_start, &cfa_end))
+	      {
+		/* Register.  */
+		ax_reg (expr, regnum);
+		if (off != 0)
+		  {
+		    ax_const_l (expr, off);
+		    ax_simple (expr, aop_add);
+		  }
+	      }
+	    else
+	      {
+		/* Another expression.  */
+		ax_const_l (expr, text_offset);
+		dwarf2_compile_expr_to_ax (expr, loc, arch, addr_size,
+					   cfa_start, cfa_end, per_cu);
+	      }
+
+	    loc->kind = axs_lvalue_memory;
+	  }
 	  break;
 
 	case DW_OP_GNU_push_tls_address:
-- 
1.9.3

  parent reply	other threads:[~2014-06-20 15:58 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-06-20 15:58 [PATCH v2 00/15] let gdb reuse gcc's C compiler Tom Tromey
2014-06-20 15:58 ` [PATCH v2 02/14] add gcc/gdb interface files Tom Tromey
2014-06-20 15:58 ` [PATCH v2 01/14] introduce ui_file_write_for_put Tom Tromey
2014-06-20 15:58 ` [PATCH v2 03/14] add some missing ops to DWARF assembler Tom Tromey
2014-06-20 15:58 ` [PATCH v2 14/14] the "compile" command Tom Tromey
2014-06-20 19:17   ` Eli Zaretskii
2014-10-08 17:45     ` Jan Kratochvil
2014-10-08 18:42       ` Eli Zaretskii
2014-10-08 19:42         ` Jan Kratochvil
2014-06-20 15:58 ` Tom Tromey [this message]
2014-06-20 15:58 ` [PATCH v2 04/14] add make_unqualified_type Tom Tromey
2014-06-20 15:58 ` [PATCH v2 11/14] export dwarf2_reg_to_regnum_or_error Tom Tromey
2014-06-20 16:26 ` [PATCH v2 13/14] add s390_gcc_target_options Tom Tromey
2014-06-20 16:32 ` [PATCH v2 07/14] add gnu_triplet_regexp gdbarch method Tom Tromey
2014-06-20 16:32 ` [PATCH v2 12/14] add linux_infcall_mmap Tom Tromey
2014-06-20 16:32 ` [PATCH v2 05/14] add dummy frame destructor Tom Tromey
2014-06-20 16:33 ` [PATCH v2 10/14] make dwarf_expr_frame_base_1 public Tom Tromey
2014-06-20 20:05   ` Doug Evans
2014-06-23  8:18     ` Gary Benson
2014-06-23 14:57       ` Eli Zaretskii
2014-06-24 10:18         ` Gary Benson
2014-06-24 13:04           ` Pedro Alves
2014-10-08 16:57             ` Jan Kratochvil
2014-06-20 16:39 ` [PATCH v2 08/14] introduce call_function_by_hand_dummy Tom Tromey
2014-06-20 16:51 ` [PATCH v2 06/14] add infcall_mmap and gcc_target_options gdbarch methods 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=1403279874-23781-10-git-send-email-tromey@redhat.com \
    --to=tromey@redhat.com \
    --cc=gdb-patches@sourceware.org \
    /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;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).