From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 130858 invoked by alias); 7 Oct 2015 09:26:44 -0000 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 Received: (qmail 130784 invoked by uid 89); 7 Oct 2015 09:26:43 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.2 required=5.0 tests=AWL,BAYES_00,FREEMAIL_FROM,RCVD_IN_DNSWL_LOW,SPF_PASS autolearn=ham version=3.3.2 X-HELO: mail-pa0-f49.google.com Received: from mail-pa0-f49.google.com (HELO mail-pa0-f49.google.com) (209.85.220.49) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES128-GCM-SHA256 encrypted) ESMTPS; Wed, 07 Oct 2015 09:26:38 +0000 Received: by pablk4 with SMTP id lk4so16256013pab.3 for ; Wed, 07 Oct 2015 02:26:36 -0700 (PDT) X-Received: by 10.66.121.229 with SMTP id ln5mr51652264pab.133.1444209996839; Wed, 07 Oct 2015 02:26:36 -0700 (PDT) Received: from E107787-LIN.cambridge.arm.com (power-aix.osuosl.org. [140.211.15.154]) by smtp.gmail.com with ESMTPSA id xa4sm38490858pac.28.2015.10.07.02.26.35 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 07 Oct 2015 02:26:36 -0700 (PDT) From: Yao Qi X-Google-Original-From: Yao Qi To: gdb-patches@sourceware.org Subject: [PATCH 03/11] Move append_insns out of aarch64_relocate_instruction Date: Wed, 07 Oct 2015 09:26:00 -0000 Message-Id: <1444209985-15829-4-git-send-email-yao.qi@linaro.org> In-Reply-To: <1444209985-15829-1-git-send-email-yao.qi@linaro.org> References: <1444209985-15829-1-git-send-email-yao.qi@linaro.org> X-IsSubscribed: yes X-SW-Source: 2015-10/txt/msg00063.txt.bz2 aarch64_relocate_instruction should only decode instructions, and other operations should be done out side of it. This patch moves append_insns out of aarch64_relocate_instruction, to its caller. gdb/gdbserver: 2015-10-05 Yao Qi * linux-aarch64-low.c (aarch64_relocate_instruction): Return int. Add argument buf. (aarch64_install_fast_tracepoint_jump_pad): Pass buf to aarch64_relocate_instruction. --- gdb/gdbserver/linux-aarch64-low.c | 37 +++++++++++++++++++------------------ 1 file changed, 19 insertions(+), 18 deletions(-) diff --git a/gdb/gdbserver/linux-aarch64-low.c b/gdb/gdbserver/linux-aarch64-low.c index 909ba65..506fb9e 100644 --- a/gdb/gdbserver/linux-aarch64-low.c +++ b/gdb/gdbserver/linux-aarch64-low.c @@ -1924,8 +1924,8 @@ can_encode_int32 (int32_t val, unsigned bits) return rest == 0 || rest == -1; } -/* Relocate an instruction INSN from OLDLOC to *TO. This function will - also increment TO by the number of bytes the new instruction(s) take(s). +/* Relocate an instruction INSN from OLDLOC to TO and save the relocated + instructions in BUF. The number of instructions in BUF is returned. PC relative instructions need to be handled specifically: @@ -1936,10 +1936,10 @@ can_encode_int32 (int32_t val, unsigned bits) - ADR/ADRP - LDR/LDRSW (literal) */ -static void -aarch64_relocate_instruction (CORE_ADDR *to, CORE_ADDR oldloc, uint32_t insn) +static int +aarch64_relocate_instruction (const CORE_ADDR to, const CORE_ADDR oldloc, + uint32_t insn, uint32_t *buf) { - uint32_t buf[32]; uint32_t *p = buf; int is_bl; @@ -1957,16 +1957,16 @@ aarch64_relocate_instruction (CORE_ADDR *to, CORE_ADDR oldloc, uint32_t insn) if (aarch64_decode_b (oldloc, insn, &is_bl, &offset)) { - offset = (oldloc - *to + offset); + offset = (oldloc - to + offset); if (can_encode_int32 (offset, 28)) p += emit_b (p, is_bl, offset); else - return; + return 0; } else if (aarch64_decode_bcond (oldloc, insn, &cond, &offset)) { - offset = (oldloc - *to + offset); + offset = (oldloc - to + offset); if (can_encode_int32 (offset, 21)) p += emit_bcond (p, cond, offset); @@ -1989,11 +1989,11 @@ aarch64_relocate_instruction (CORE_ADDR *to, CORE_ADDR oldloc, uint32_t insn) p += emit_b (p, 0, offset - 8); } else - return; + return 0; } else if (aarch64_decode_cb (oldloc, insn, &is64, &is_cbnz, &rn, &offset)) { - offset = (oldloc - *to + offset); + offset = (oldloc - to + offset); if (can_encode_int32 (offset, 21)) p += emit_cb (p, is_cbnz, aarch64_register (rn, is64), offset); @@ -2015,11 +2015,11 @@ aarch64_relocate_instruction (CORE_ADDR *to, CORE_ADDR oldloc, uint32_t insn) p += emit_b (p, 0, offset - 8); } else - return; + return 0; } else if (aarch64_decode_tb (oldloc, insn, &is_tbnz, &bit, &rt, &offset)) { - offset = (oldloc - *to + offset); + offset = (oldloc - to + offset); if (can_encode_int32 (offset, 16)) p += emit_tb (p, is_tbnz, bit, aarch64_register (rt, 1), offset); @@ -2041,7 +2041,7 @@ aarch64_relocate_instruction (CORE_ADDR *to, CORE_ADDR oldloc, uint32_t insn) p += emit_b (p, 0, offset - 8); } else - return; + return 0; } else if (aarch64_decode_adr (oldloc, insn, &is_adrp, &rd, &offset)) { @@ -2092,7 +2092,7 @@ aarch64_relocate_instruction (CORE_ADDR *to, CORE_ADDR oldloc, uint32_t insn) p += emit_insn (p, insn); } - append_insns (to, p - buf, buf); + return (int) (p - buf); } /* Implementation of linux_target_ops method @@ -2421,11 +2421,9 @@ aarch64_install_fast_tracepoint_jump_pad (CORE_ADDR tpoint, /* Now emit the relocated instruction. */ *adjusted_insn_addr = buildaddr; target_read_uint32 (tpaddr, &insn); - aarch64_relocate_instruction (&buildaddr, tpaddr, insn); - *adjusted_insn_addr_end = buildaddr; - + i = aarch64_relocate_instruction (buildaddr, tpaddr, insn, buf); /* We may not have been able to relocate the instruction. */ - if (*adjusted_insn_addr == *adjusted_insn_addr_end) + if (i == 0) { sprintf (err, "E.Could not relocate instruction from %s to %s.", @@ -2433,6 +2431,9 @@ aarch64_install_fast_tracepoint_jump_pad (CORE_ADDR tpoint, core_addr_to_string_nz (buildaddr)); return 1; } + else + append_insns (&buildaddr, i, buf); + *adjusted_insn_addr_end = buildaddr; /* Go back to the start of the buffer. */ p = buf; -- 1.9.1