From patchwork Thu May 12 16:18:29 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yao Qi X-Patchwork-Id: 12222 Received: (qmail 111206 invoked by alias); 12 May 2016 16:18:56 -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 111126 invoked by uid 89); 12 May 2016 16:18:56 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.6 required=5.0 tests=AWL, BAYES_00, FREEMAIL_FROM, RCVD_IN_DNSWL_LOW, SPF_PASS autolearn=ham version=3.3.2 spammy=him, ending X-HELO: mail-pa0-f68.google.com Received: from mail-pa0-f68.google.com (HELO mail-pa0-f68.google.com) (209.85.220.68) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES128-GCM-SHA256 encrypted) ESMTPS; Thu, 12 May 2016 16:18:41 +0000 Received: by mail-pa0-f68.google.com with SMTP id gh9so6506505pac.0 for ; Thu, 12 May 2016 09:18:41 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references; bh=5edOMXd5pA6G4UZh6qB+H920bG8GeZD9fOd+VmkQDq8=; b=UjhbhVA3ukhtRRJsuFOpEc38nEKZiTCOKqa67OgNK0gIiF2gKqRLp6mDxe066ZsSzt SZTXiz+eFdKHmloA9Ni4FbUDX/wT33Ns/4+pEcvWxZbxc8wZEZ6Uk47fmdtai5cuZEcq 6SPhOFJ6kWmMk4ENuY8MdYagQsocfptSdfuIHIu+xng316EACJD5dea9e5hdmzLnUdPq iS5FobSTIchEQRSqEI/wUo8BUfU1Na4t2Swq3yv3cCgZIcB/kU1cc4OLbpSQDrMTYyVl IAr92BRGZLJwT6zrZ7AJIxJQa42qyP1xI6o0ePo45HmlZePgEmunk1U72IUYwLpyI444 pJjw== X-Gm-Message-State: AOPr4FXhRL6VeQccL58Dueq2YGBE7+XJNDavt656BpYNPNicjVaYJb14+lrCvHTCzq2oqQ== X-Received: by 10.66.222.100 with SMTP id ql4mr15212662pac.137.1463069919565; Thu, 12 May 2016 09:18:39 -0700 (PDT) Received: from E107787-LIN.cambridge.arm.com (gcc113.osuosl.org. [140.211.9.71]) by smtp.gmail.com with ESMTPSA id m86sm13238672pfj.77.2016.05.12.09.18.37 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 12 May 2016 09:18:38 -0700 (PDT) From: Yao Qi X-Google-Original-From: Yao Qi To: gdb-patches@sourceware.org Subject: [PATCH 1/4] Remove arm_override_mode Date: Thu, 12 May 2016 17:18:29 +0100 Message-Id: <1463069912-23472-2-git-send-email-yao.qi@linaro.org> In-Reply-To: <1463069912-23472-1-git-send-email-yao.qi@linaro.org> References: <1463069912-23472-1-git-send-email-yao.qi@linaro.org> X-IsSubscribed: yes This patch removes global variable arm_override_mode. The rationale is that if the address is the next address of current pc, we can get the thumb/arm mode from dest address computed by software single step code. gdb: 2016-05-12 Yao Qi * arm-tdep.c: Include "gdbthread.h". (arm_override_mode): Remove. (arm_pc_is_thumb): Remove arm_override_mode. If MEMADDR is the dest address of current pc, get thumb mode by dest address. (arm_insert_single_step_breakpoint): Remove arm_override_mode and cleanup. --- gdb/arm-tdep.c | 57 +++++++++++++++++++++++++++++++++++++++++---------------- 1 file changed, 41 insertions(+), 16 deletions(-) diff --git a/gdb/arm-tdep.c b/gdb/arm-tdep.c index 0412f71..d529481 100644 --- a/gdb/arm-tdep.c +++ b/gdb/arm-tdep.c @@ -55,6 +55,7 @@ #include "elf/arm.h" #include "vec.h" +#include "gdbthread.h" #include "record.h" #include "record-full.h" @@ -143,13 +144,6 @@ static const char *const arm_mode_strings[] = static const char *arm_fallback_mode_string = "auto"; static const char *arm_force_mode_string = "auto"; -/* Internal override of the execution mode. -1 means no override, - 0 means override to ARM mode, 1 means override to Thumb mode. - The effect is the same as if arm_force_mode has been set by the - user (except the internal override has precedence over a user's - arm_force_mode override). */ -static int arm_override_mode = -1; - /* Number of different reg name sets (options). */ static int num_disassembly_options; @@ -422,9 +416,46 @@ arm_pc_is_thumb (struct gdbarch *gdbarch, CORE_ADDR memaddr) if (IS_THUMB_ADDR (memaddr)) return 1; - /* Respect internal mode override if active. */ - if (arm_override_mode != -1) - return arm_override_mode; + if (target_has_execution && !is_executing (inferior_ptid)) + { + gdb_byte buf[4]; + struct regcache *regcache = get_current_regcache (); + + /* Check the memory pointed by PC is readable. */ + if (target_read_memory (regcache_read_pc (regcache), buf, 4) == 0) + { + struct arm_get_next_pcs next_pcs_ctx; + CORE_ADDR pc; + int i; + VEC (CORE_ADDR) *next_pcs = NULL; + struct cleanup *old_chain + = make_cleanup (VEC_cleanup (CORE_ADDR), &next_pcs); + + arm_get_next_pcs_ctor (&next_pcs_ctx, + &arm_get_next_pcs_ops, + gdbarch_byte_order (gdbarch), + gdbarch_byte_order_for_code (gdbarch), + 0, + regcache); + + next_pcs = arm_get_next_pcs (&next_pcs_ctx); + + /* If MEMADDR is the next instruction of current pc, do the + software single step computation, and get the thumb mode by + the destination address. */ + for (i = 0; VEC_iterate (CORE_ADDR, next_pcs, i, pc); i++) + { + if (UNMAKE_THUMB_ADDR (pc) == memaddr) + { + do_cleanups (old_chain); + + return IS_THUMB_ADDR (pc); + } + } + + do_cleanups (old_chain); + } + } /* If the user wants to override the symbol table, let him. */ if (strcmp (arm_force_mode_string, "arm") == 0) @@ -4205,15 +4236,9 @@ arm_insert_single_step_breakpoint (struct gdbarch *gdbarch, struct address_space *aspace, CORE_ADDR pc) { - struct cleanup *old_chain - = make_cleanup_restore_integer (&arm_override_mode); - - arm_override_mode = IS_THUMB_ADDR (pc); pc = gdbarch_addr_bits_remove (gdbarch, pc); insert_single_step_breakpoint (gdbarch, aspace, pc); - - do_cleanups (old_chain); } /* Given BUF, which is OLD_LEN bytes ending at ENDADDR, expand