Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Yao Qi <qiyaoltc@gmail.com>
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	[thread overview]
Message-ID: <1444209985-15829-4-git-send-email-yao.qi@linaro.org> (raw)
In-Reply-To: <1444209985-15829-1-git-send-email-yao.qi@linaro.org>

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  <yao.qi@linaro.org>

	* 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


  parent reply	other threads:[~2015-10-07  9:26 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-10-07  9:26 [PATCH 00/11] Displaced stepping on AArch64 GNU/Linux Yao Qi
2015-10-07  9:26 ` [PATCH 10/11] Rename emit_load_store to aarch64_emit_load_store Yao Qi
2015-10-07  9:26 ` [PATCH 07/11] Support displaced stepping in support_displaced_stepping for aarch64*-*-linux* Yao Qi
2015-10-07  9:26 ` Yao Qi [this message]
2015-10-07  9:26 ` [PATCH 08/11] New test case gdb.arch/disp-step-insn-reloc.exp Yao Qi
2015-10-07  9:26 ` [PATCH 01/11] More tests in gdb.arch/insn-reloc.c Yao Qi
2015-10-07  9:26 ` [PATCH 02/11] Move target_read_uint32 out of aarch64_relocate_instruction Yao Qi
2015-10-07  9:27 ` [PATCH 05/11] Move aarch64_relocate_instruction to arch/aarch64-insn.c Yao Qi
2015-10-07  9:27 ` [PATCH 09/11] Rename emit_insn to aarch64_emit_insn Yao Qi
2015-10-07  9:27 ` [PATCH 04/11] Use visitor in aarch64_relocate_instruction Yao Qi
2015-10-07  9:27 ` [PATCH 11/11] Mention the change in NEWS Yao Qi
2015-10-07 15:38   ` Eli Zaretskii
2015-10-07  9:27 ` [PATCH 06/11] Support displaced stepping in aarch64-linux Yao Qi
2015-10-13 20:26   ` Sergio Durigan Junior
2015-10-14  8:37     ` Yao Qi
2015-10-12 10:35 ` [PATCH 00/11] Displaced stepping on AArch64 GNU/Linux Yao Qi

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=1444209985-15829-4-git-send-email-yao.qi@linaro.org \
    --to=qiyaoltc@gmail.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