From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 9473 invoked by alias); 17 Feb 2011 16:20:41 -0000 Received: (qmail 9436 invoked by uid 22791); 17 Feb 2011 16:20:31 -0000 X-SWARE-Spam-Status: No, hits=-6.8 required=5.0 tests=AWL,BAYES_00,RCVD_IN_DNSWL_HI,SPF_HELO_PASS,TW_DL,T_RP_MATCHES_RCVD X-Spam-Check-By: sourceware.org Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Thu, 17 Feb 2011 16:20:24 +0000 Received: from int-mx02.intmail.prod.int.phx2.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id p1HGKDVT003787 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Thu, 17 Feb 2011 11:20:13 -0500 Received: from ns3.rdu.redhat.com (ns3.rdu.redhat.com [10.11.255.199]) by int-mx02.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id p1HGKD6c028803; Thu, 17 Feb 2011 11:20:13 -0500 Received: from opsy.redhat.com (ovpn01.gateway.prod.ext.phx2.redhat.com [10.5.9.1]) by ns3.rdu.redhat.com (8.13.8/8.13.8) with ESMTP id p1HGKCC1010658; Thu, 17 Feb 2011 11:20:12 -0500 Received: by opsy.redhat.com (Postfix, from userid 500) id 9AAC93784F6; Thu, 17 Feb 2011 09:20:11 -0700 (MST) From: Tom Tromey To: Pedro Alves Cc: gdb-patches@sourceware.org, Jan Kratochvil Subject: Re: FYI: handle DW_OP_call_frame_cfa in AX compiler References: <201102071435.20804.pedro@codesourcery.com> <201102162125.44378.pedro@codesourcery.com> <201102162224.45388.pedro@codesourcery.com> Date: Thu, 17 Feb 2011 16:24:00 -0000 In-Reply-To: <201102162224.45388.pedro@codesourcery.com> (Pedro Alves's message of "Wed, 16 Feb 2011 22:24:45 +0000") Message-ID: User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.2 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org X-SW-Source: 2011-02/txt/msg00424.txt.bz2 Pedro> IMO, that'd be better. Stops everyone else reading the code Pedro> from asking that same question in their minds. :-) Ok, I made this change. The results from gdb.trace are very good now: # of expected passes 822 # of expected failures 16 So, I am committing the appended. Tom 2011-02-17 Tom Tromey * dwarf2loc.h (dwarf2_compile_expr_to_ax): Declare. * dwarf2loc.c (dwarf2_compile_expr_to_ax): Rename from compile_dwarf_to_ax. No longer static. Call dwarf2_compile_cfa_to_ax. (locexpr_tracepoint_var_ref): Update. (loclist_tracepoint_var_ref): Update. * dwarf2-frame.h (dwarf2_compile_cfa_to_ax): Declare. * dwarf2-frame.c (execute_cfa_program): Remove 'this_frame' argument; add 'gdbarch' and 'pc'. (dwarf2_compile_cfa_to_ax): New function. (dwarf2_frame_cache): Update. Index: dwarf2-frame.c =================================================================== RCS file: /cvs/src/src/gdb/dwarf2-frame.c,v retrieving revision 1.119 diff -u -r1.119 dwarf2-frame.c --- dwarf2-frame.c 7 Jan 2011 19:36:16 -0000 1.119 +++ dwarf2-frame.c 17 Feb 2011 16:16:18 -0000 @@ -38,6 +38,8 @@ #include "complaints.h" #include "dwarf2-frame.h" +#include "ax.h" +#include "dwarf2loc.h" struct comp_unit; @@ -428,13 +430,11 @@ 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 +902,85 @@ } +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) +{ + 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); + 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; + + default: + internal_error (__FILE__, __LINE__, _("Unknown CFA rule.")); + } +} + + struct dwarf2_frame_cache { /* DWARF Call Frame Address. */ @@ -979,14 +1058,15 @@ /* 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) Index: dwarf2-frame.h =================================================================== RCS file: /cvs/src/src/gdb/dwarf2-frame.h,v retrieving revision 1.25 diff -u -r1.25 dwarf2-frame.h --- dwarf2-frame.h 1 Jan 2011 15:33:02 -0000 1.25 +++ dwarf2-frame.h 17 Feb 2011 16:16:18 -0000 @@ -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,15 @@ 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); + #endif /* dwarf2-frame.h */ Index: dwarf2loc.c =================================================================== RCS file: /cvs/src/src/gdb/dwarf2loc.c,v retrieving revision 1.106 diff -u -r1.106 dwarf2loc.c --- dwarf2loc.c 16 Feb 2011 21:45:38 -0000 1.106 +++ dwarf2loc.c 17 Feb 2011 16:16:19 -0000 @@ -1426,11 +1426,11 @@ example, if the expression cannot be compiled, or if the expression is invalid. */ -static void -compile_dwarf_to_ax (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 *per_cu) +void +dwarf2_compile_expr_to_ax (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 *per_cu) { struct cleanup *cleanups; int i, *offsets; @@ -1717,8 +1717,8 @@ &datastart, &datalen); op_ptr = read_sleb128 (op_ptr, op_end, &offset); - compile_dwarf_to_ax (expr, loc, arch, addr_size, datastart, - datastart + datalen, per_cu); + dwarf2_compile_expr_to_ax (expr, loc, arch, addr_size, datastart, + datastart + datalen, per_cu); if (offset != 0) { @@ -1955,7 +1955,8 @@ break; case DW_OP_call_frame_cfa: - unimplemented (op); + dwarf2_compile_cfa_to_ax (expr, loc, arch, expr->scope, per_cu); + loc->kind = axs_lvalue_memory; break; case DW_OP_GNU_push_tls_address: @@ -2069,9 +2070,9 @@ /* DW_OP_call_ref is currently not supported. */ gdb_assert (block.per_cu == per_cu); - compile_dwarf_to_ax (expr, loc, arch, addr_size, - block.data, block.data + block.size, - per_cu); + dwarf2_compile_expr_to_ax (expr, loc, arch, addr_size, + block.data, block.data + block.size, + per_cu); } break; @@ -2673,9 +2674,9 @@ if (dlbaton->data == NULL || dlbaton->size == 0) value->optimized_out = 1; else - compile_dwarf_to_ax (ax, value, gdbarch, addr_size, - dlbaton->data, dlbaton->data + dlbaton->size, - dlbaton->per_cu); + dwarf2_compile_expr_to_ax (ax, value, gdbarch, addr_size, + dlbaton->data, dlbaton->data + dlbaton->size, + dlbaton->per_cu); } /* The set of location functions used with the DWARF-2 expression @@ -2826,8 +2827,8 @@ if (data == NULL || size == 0) value->optimized_out = 1; else - compile_dwarf_to_ax (ax, value, gdbarch, addr_size, data, data + size, - dlbaton->per_cu); + dwarf2_compile_expr_to_ax (ax, value, gdbarch, addr_size, data, data + size, + dlbaton->per_cu); } /* The set of location functions used with the DWARF-2 expression Index: dwarf2loc.h =================================================================== RCS file: /cvs/src/src/gdb/dwarf2loc.h,v retrieving revision 1.21 diff -u -r1.21 dwarf2loc.h --- dwarf2loc.h 1 Jan 2011 15:33:02 -0000 1.21 +++ dwarf2loc.h 17 Feb 2011 16:16:20 -0000 @@ -25,6 +25,8 @@ struct objfile; struct dwarf2_per_cu_data; struct dwarf2_loclist_baton; +struct agent_expr; +struct axs_value; /* This header is private to the DWARF-2 reader. It is shared between dwarf2read.c and dwarf2loc.c. */ @@ -106,4 +108,25 @@ extern const struct symbol_computed_ops dwarf2_locexpr_funcs; extern const struct symbol_computed_ops dwarf2_loclist_funcs; +/* Compile a DWARF location expression to an agent expression. + + EXPR is the agent expression we are building. + LOC is the agent value we modify. + ARCH is the architecture. + ADDR_SIZE is the size of addresses, in bytes. + OP_PTR is the start of the location expression. + OP_END is one past the last byte of the location expression. + + This will throw an exception for various kinds of errors -- for + example, if the expression cannot be compiled, or if the expression + is invalid. */ + +extern void dwarf2_compile_expr_to_ax (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 *per_cu); + #endif /* dwarf2loc.h */