From patchwork Wed Oct 14 11:14:28 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: henrik.wallin@windriver.com X-Patchwork-Id: 9110 Received: (qmail 87692 invoked by alias); 14 Oct 2015 15:07:53 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Delivered-To: mailing list gdb-patches@sourceware.org Received: (qmail 87636 invoked by uid 89); 14 Oct 2015 15:07:52 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-0.2 required=5.0 tests=AWL, BAYES_00, KAM_LAZY_DOMAIN_SECURITY, T_RP_MATCHES_RCVD autolearn=no version=3.3.2 X-HELO: mail.windriver.com Received: from mail.windriver.com (HELO mail.windriver.com) (147.11.1.11) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES256-SHA encrypted) ESMTPS; Wed, 14 Oct 2015 15:07:50 +0000 Received: from arn-build2.wrs.com (arn-build2.wrs.com [128.224.95.15]) by mail.windriver.com (8.15.2/8.15.1) with ESMTP id t9EBEZnu010722 for ; Wed, 14 Oct 2015 04:14:35 -0700 (PDT) Received: by arn-build2.wrs.com (Postfix, from userid 18580) id EB970220B3B; Wed, 14 Oct 2015 13:14:33 +0200 (CEST) From: henrik.wallin@windriver.com To: gdb-patches@sourceware.org Subject: [RFC][PATCH 10/15] gdb: Add arm_fast_tracepoint_valid_at Date: Wed, 14 Oct 2015 13:14:28 +0200 Message-Id: <3a55070efb60b203fc73e0529a586d16f794ac26.1444820235.git.henrik.wallin@windriver.com> In-Reply-To: References: In-Reply-To: References: From: Henrik Wallin This adds the function. No users yet. A 4 byte jump instruction will be used and the code need to handle multiple cases as the instruction can be 2, or 4 bytes long and the mode can be either arm or thumb. gdb/ChangeLog: * arm-tdep.c (arm_fast_tracepoint_valid_at): New function. Signed-off-by: Henrik Wallin --- gdb/arm-tdep.c | 47 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) diff --git a/gdb/arm-tdep.c b/gdb/arm-tdep.c index b277c3ef405c..601d589b8a89 100644 --- a/gdb/arm-tdep.c +++ b/gdb/arm-tdep.c @@ -22,6 +22,7 @@ #include /* XXX for isupper (). */ #include "frame.h" +#include "disasm.h" #include "inferior.h" #include "infrun.h" #include "gdbcmd.h" @@ -10506,6 +10507,52 @@ arm_relocate_instruction (struct gdbarch *gdbarch, arm_relocate_instruction_func (&rel); } +static int +arm_fast_tracepoint_valid_at (struct gdbarch *gdbarch, + CORE_ADDR addr, char **msg) +{ + static struct ui_file *gdb_null = NULL; + int len; + + /* Check if the instruction is relocatable. */ + if (arm_check_relocate_instruction (gdbarch, addr, msg) == -1) + return 0; + + /* Dummy file descriptor for the disassembler. */ + if (!gdb_null) + gdb_null = ui_file_new (); + + /* A branch instruction used for fast tracepoint takes 4 bytes. + (A 2 bytes branch instruction only gets us 4k away, + so will not be enough.) + + target gdbserver will validate that the relative branch + distance will fit in the instructions. + (16M for Thumb, 32M for ARM) + + We only allow to replace one instuction. (4 bytes) + Replacing 2 instructions is not safe. Consider + the case where code wants to jump to the 2nd instruction - it + will jump into the middle of a branch instruction. */ + + if (arm_pc_is_thumb (gdbarch, addr)) + { + len = gdb_print_insn (gdbarch, addr, gdb_null, NULL); + if (len == 2) + { + if (msg) + *msg = xstrprintf (_("; instruction is only 2 bytes long, " + "need 4 bytes for the jump")); + return 0; + } + } + + if (msg) + *msg = NULL; + + return 1; +} + /* Initialize the current architecture based on INFO. If possible, re-use an architecture from ARCHES, which is a list of