• R/O
  • HTTP
  • SSH
  • HTTPS

提交

標籤
無標籤

Frequently used words (click to add to your profile)

javac++androidlinuxc#windowsobjective-ccocoa誰得qtpythonphprubygameguibathyscaphec計画中(planning stage)翻訳omegatframeworktwitterdomtestvb.netdirectxゲームエンジンbtronarduinopreviewer

GNU Binutils with patches for OS216


Commit MetaInfo

修訂8689682cc375f6f30d65f1583b3aaa3e6a1e4d63 (tree)
時間2015-10-22 00:26:05
作者Antoine Tremblay <antoine.tremblay@eric...>
CommiterAntoine Tremblay

Log Message

Implement breakpoint_kind_from_pc and sw_breakpoint_from_kind for ARM in GDBServer.

ARM can have multiple breakpoint types based on the instruction set
it's currently in: arm, thumb or thumb2.

GDBServer needs to know what breakpoint is to be inserted at location
when inserting a breakpoint.

This is handled by the breakpoint_kind_from_pc and sw_breakpoint_from_kind
target ops introduced in a previous patch, this patch adds the
arm_breakpoint_kind_from_pc and arm_sw_breakpoint_from_kind implementation so
that the proper breakpoint type is returned based on the pc.

Also in order to share some code with GDB a new file called arm.c have been
introduced in arch/.

While this file does not contain much yet future patches will add more
to it thus the inclusion at this stage.

No regressions on Ubuntu 14.04 on ARMv7 and x86.
With gdbserver-{native,extended} / { -marm -mthumb }

gdb/ChangeLog:

* Makefile.in: Add arm.c/o.
* arch/arm.c: New file.
* arch/arm.h: (IS_THUMB_ADDR): Move macro from arm-tdep.c.
(MAKE_THUMB_ADDR): Likewise.
(UNMAKE_THUMB_ADDR): Likewise.
* arm-tdep.c (int thumb_insn_size): Move to arm.c.
(IS_THUMB_ADDR): Move to arm.h.
(MAKE_THUMB_ADDR): Likewise.
(UNMAKE_THUMB_ADDR): Likewise.
* configure.tgt: Add arm.o to all ARM configs.

gdb/gdbserver/ChangeLog:

* Makefile.in: Add arm.c/o.
* configure.srv: Likewise.
* linux-arm-low.c (arm_breakpoint_kinds): New enum.
(arm_breakpoint_kind_from_pc): New function.
(arm_sw_breakpoint_from_kind): Return proper kind.
(struct linux_target_ops) <breakpoint_kind_from_pc>: Initialize.

Change Summary

差異

--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,3 +1,16 @@
1+2015-10-21 Antoine Tremblay <antoine.tremblay@ericsson.com>
2+
3+ * Makefile.in: Add arm.c/o.
4+ * arch/arm.c: New file.
5+ * arch/arm.h: (IS_THUMB_ADDR): Move macro from arm-tdep.c.
6+ (MAKE_THUMB_ADDR): Likewise.
7+ (UNMAKE_THUMB_ADDR): Likewise.
8+ * arm-tdep.c (int thumb_insn_size): Move to arm.c.
9+ (IS_THUMB_ADDR): Move to arm.h.
10+ (MAKE_THUMB_ADDR): Likewise.
11+ (UNMAKE_THUMB_ADDR): Likewise.
12+ * configure.tgt: Add arm.o to all ARM configs.
13+
114 2015-10-21 Yao Qi <yao.qi@linaro.org>
215
316 * lib/range-stepping-support.exp (exec_cmd_expect_vCont_count):
--- a/gdb/Makefile.in
+++ b/gdb/Makefile.in
@@ -657,7 +657,7 @@ ALL_64_TARGET_OBS = \
657657
658658 # All other target-dependent objects files (used with --enable-targets=all).
659659 ALL_TARGET_OBS = \
660- armbsd-tdep.o arm-linux-tdep.o arm-symbian-tdep.o \
660+ armbsd-tdep.o arm.o arm-linux-tdep.o arm-symbian-tdep.o \
661661 armnbsd-tdep.o armobsd-tdep.o \
662662 arm-tdep.o arm-wince-tdep.o \
663663 avr-tdep.o \
@@ -1660,6 +1660,7 @@ ALLDEPFILES = \
16601660 amd64-dicos-tdep.c \
16611661 amd64-linux-nat.c amd64-linux-tdep.c \
16621662 amd64-sol2-tdep.c \
1663+ arm.c \
16631664 arm-linux-nat.c arm-linux-tdep.c arm-symbian-tdep.c arm-tdep.c \
16641665 armnbsd-nat.c armbsd-tdep.c armnbsd-tdep.c armobsd-tdep.c \
16651666 avr-tdep.c \
@@ -2275,6 +2276,16 @@ waitstatus.o: ${srcdir}/target/waitstatus.c
22752276 $(COMPILE) $(srcdir)/target/waitstatus.c
22762277 $(POSTCOMPILE)
22772278
2279+#
2280+# gdb/arch/ dependencies
2281+#
2282+# Need to explicitly specify the compile rule as make will do nothing
2283+# or try to compile the object file into the sub-directory.
2284+
2285+arm.o: ${srcdir}/arch/arm.c
2286+ $(COMPILE) $(srcdir)/arch/arm.c
2287+ $(POSTCOMPILE)
2288+
22782289 # gdb/nat/ dependencies
22792290 #
22802291 # Need to explicitly specify the compile rule as make will do nothing
--- /dev/null
+++ b/gdb/arch/arm.c
@@ -0,0 +1,33 @@
1+/* Common target dependent code for GDB on ARM systems.
2+
3+ Copyright (C) 1988-2015 Free Software Foundation, Inc.
4+
5+ This file is part of GDB.
6+
7+ This program is free software; you can redistribute it and/or modify
8+ it under the terms of the GNU General Public License as published by
9+ the Free Software Foundation; either version 3 of the License, or
10+ (at your option) any later version.
11+
12+ This program is distributed in the hope that it will be useful,
13+ but WITHOUT ANY WARRANTY; without even the implied warranty of
14+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15+ GNU General Public License for more details.
16+
17+ You should have received a copy of the GNU General Public License
18+ along with this program. If not, see <http://www.gnu.org/licenses/>. */
19+
20+#include "common-defs.h"
21+#include "arm.h"
22+
23+/* Return the size in bytes of the complete Thumb instruction whose
24+ first halfword is INST1. */
25+
26+int
27+thumb_insn_size (unsigned short inst1)
28+{
29+ if ((inst1 & 0xe000) == 0xe000 && (inst1 & 0x1800) != 0)
30+ return 4;
31+ else
32+ return 2;
33+}
--- a/gdb/arch/arm.h
+++ b/gdb/arch/arm.h
@@ -1,5 +1,5 @@
11 /* Common target dependent code for GDB on ARM systems.
2- Copyright (C) 2002-2015 Free Software Foundation, Inc.
2+ Copyright (C) 1988-2015 Free Software Foundation, Inc.
33
44 This file is part of GDB.
55
@@ -58,4 +58,14 @@ enum gdb_regnum {
5858 ARM_LAST_FP_ARG_REGNUM = ARM_F3_REGNUM
5959 };
6060
61+/* Addresses for calling Thumb functions have the bit 0 set.
62+ Here are some macros to test, set, or clear bit 0 of addresses. */
63+#define IS_THUMB_ADDR(addr) ((addr) & 1)
64+#define MAKE_THUMB_ADDR(addr) ((addr) | 1)
65+#define UNMAKE_THUMB_ADDR(addr) ((addr) & ~1)
66+
67+/* Return the size in bytes of the complete Thumb instruction whose
68+ first halfword is INST1. */
69+int thumb_insn_size (unsigned short inst1);
70+
6171 #endif
--- a/gdb/arm-tdep.c
+++ b/gdb/arm-tdep.c
@@ -45,6 +45,7 @@
4545 #include "user-regs.h"
4646 #include "observer.h"
4747
48+#include "arch/arm.h"
4849 #include "arm-tdep.h"
4950 #include "gdb/sim-arm.h"
5051
@@ -235,8 +236,6 @@ static void arm_neon_quad_write (struct gdbarch *gdbarch,
235236 struct regcache *regcache,
236237 int regnum, const gdb_byte *buf);
237238
238-static int thumb_insn_size (unsigned short inst1);
239-
240239 struct arm_prologue_cache
241240 {
242241 /* The stack pointer at the time this frame was created; i.e. the
@@ -267,12 +266,6 @@ static CORE_ADDR arm_analyze_prologue (struct gdbarch *gdbarch,
267266
268267 #define DISPLACED_STEPPING_ARCH_VERSION 5
269268
270-/* Addresses for calling Thumb functions have the bit 0 set.
271- Here are some macros to test, set, or clear bit 0 of addresses. */
272-#define IS_THUMB_ADDR(addr) ((addr) & 1)
273-#define MAKE_THUMB_ADDR(addr) ((addr) | 1)
274-#define UNMAKE_THUMB_ADDR(addr) ((addr) & ~1)
275-
276269 /* Set to true if the 32-bit mode is in use. */
277270
278271 int arm_apcs_32 = 1;
@@ -4364,18 +4357,6 @@ bitcount (unsigned long val)
43644357 return nbits;
43654358 }
43664359
4367-/* Return the size in bytes of the complete Thumb instruction whose
4368- first halfword is INST1. */
4369-
4370-static int
4371-thumb_insn_size (unsigned short inst1)
4372-{
4373- if ((inst1 & 0xe000) == 0xe000 && (inst1 & 0x1800) != 0)
4374- return 4;
4375- else
4376- return 2;
4377-}
4378-
43794360 static int
43804361 thumb_advance_itstate (unsigned int itstate)
43814362 {
--- a/gdb/configure.tgt
+++ b/gdb/configure.tgt
@@ -44,7 +44,7 @@ aarch64*-*-elf)
4444 aarch64*-*-linux*)
4545 # Target: AArch64 linux
4646 gdb_target_obs="aarch64-tdep.o aarch64-linux-tdep.o aarch64-insn.o \
47- arm-tdep.o arm-linux-tdep.o \
47+ arm.o arm-tdep.o arm-linux-tdep.o \
4848 glibc-tdep.o linux-tdep.o solib-svr4.o \
4949 symfile-mem.o linux-record.o"
5050 build_gdbserver=yes
@@ -84,31 +84,31 @@ am33_2.0*-*-linux*)
8484
8585 arm*-wince-pe | arm*-*-mingw32ce*)
8686 # Target: ARM based machine running Windows CE (win32)
87- gdb_target_obs="arm-tdep.o arm-wince-tdep.o windows-tdep.o"
87+ gdb_target_obs="arm.o arm-tdep.o arm-wince-tdep.o windows-tdep.o"
8888 build_gdbserver=yes
8989 ;;
9090 arm*-*-linux*)
9191 # Target: ARM based machine running GNU/Linux
92- gdb_target_obs="arm-tdep.o arm-linux-tdep.o glibc-tdep.o \
92+ gdb_target_obs="arm.o arm-tdep.o arm-linux-tdep.o glibc-tdep.o \
9393 solib-svr4.o symfile-mem.o linux-tdep.o linux-record.o"
9494 build_gdbserver=yes
9595 ;;
9696 arm*-*-netbsd* | arm*-*-knetbsd*-gnu)
9797 # Target: NetBSD/arm
98- gdb_target_obs="arm-tdep.o armnbsd-tdep.o solib-svr4.o"
98+ gdb_target_obs="arm.o arm-tdep.o armnbsd-tdep.o solib-svr4.o"
9999 ;;
100100 arm*-*-openbsd*)
101101 # Target: OpenBSD/arm
102- gdb_target_obs="arm-tdep.o armbsd-tdep.o armobsd-tdep.o obsd-tdep.o \
103- solib-svr4.o"
102+ gdb_target_obs="arm.o arm-tdep.o armbsd-tdep.o armobsd-tdep.o \
103+ obsd-tdep.o solib-svr4.o"
104104 ;;
105105 arm*-*-symbianelf*)
106106 # Target: SymbianOS/arm
107- gdb_target_obs="arm-tdep.o arm-symbian-tdep.o"
107+ gdb_target_obs="arm.o arm-tdep.o arm-symbian-tdep.o"
108108 ;;
109109 arm*-*-*)
110110 # Target: ARM embedded system
111- gdb_target_obs="arm-tdep.o"
111+ gdb_target_obs="arm.o arm-tdep.o"
112112 gdb_sim=../sim/arm/libsim.a
113113 ;;
114114
--- a/gdb/gdbserver/ChangeLog
+++ b/gdb/gdbserver/ChangeLog
@@ -1,5 +1,14 @@
11 2015-10-21 Antoine Tremblay <antoine.tremblay@ericsson.com>
22
3+ * Makefile.in: Add arm.c/o.
4+ * configure.srv: Likewise.
5+ * linux-arm-low.c (arm_breakpoint_kinds): New enum.
6+ (arm_breakpoint_kind_from_pc): New function.
7+ (arm_sw_breakpoint_from_kind): Return proper kind.
8+ (struct linux_target_ops) <breakpoint_kind_from_pc>: Initialize.
9+
10+2015-10-21 Antoine Tremblay <antoine.tremblay@ericsson.com>
11+
312 * linux-low.c (initialize_low): Ajdust for breakpoint global variables
413 removal.
514 * mem-break.c : Remove breakpoint_data/breakpoint_len global variables.
--- a/gdb/gdbserver/Makefile.in
+++ b/gdb/gdbserver/Makefile.in
@@ -180,7 +180,8 @@ SFILES= $(srcdir)/gdbreplay.c $(srcdir)/inferiors.c $(srcdir)/dll.c \
180180 $(srcdir)/common/common-debug.c $(srcdir)/common/cleanups.c \
181181 $(srcdir)/common/common-exceptions.c $(srcdir)/symbol.c \
182182 $(srcdir)/common/btrace-common.c \
183- $(srcdir)/common/fileio.c $(srcdir)/nat/linux-namespaces.c
183+ $(srcdir)/common/fileio.c $(srcdir)/nat/linux-namespaces.c \
184+ $(srcdir)/arch/arm.c
184185
185186 DEPFILES = @GDBSERVER_DEPFILES@
186187
@@ -583,6 +584,12 @@ fileio.o: ../common/fileio.c
583584 $(COMPILE) $<
584585 $(POSTCOMPILE)
585586
587+# Arch object files rules form ../arch
588+
589+arm.o: ../arch/arm.c
590+ $(COMPILE) $<
591+ $(POSTCOMPILE)
592+
586593 # Native object files rules from ../nat
587594
588595 x86-dregs.o: ../nat/x86-dregs.c
--- a/gdb/gdbserver/configure.srv
+++ b/gdb/gdbserver/configure.srv
@@ -70,6 +70,7 @@ case "${target}" in
7070 srv_regobj="${srv_regobj} arm-with-neon.o"
7171 srv_tgtobj="$srv_linux_obj linux-arm-low.o"
7272 srv_tgtobj="$srv_tgtobj linux-aarch32-low.o"
73+ srv_tgtobj="${srv_tgtobj} arm.o"
7374 srv_xmlfiles="arm-with-iwmmxt.xml"
7475 srv_xmlfiles="${srv_xmlfiles} arm-with-vfpv2.xml"
7576 srv_xmlfiles="${srv_xmlfiles} arm-with-vfpv3.xml"
--- a/gdb/gdbserver/linux-arm-low.c
+++ b/gdb/gdbserver/linux-arm-low.c
@@ -30,6 +30,8 @@
3030 #include "nat/gdb_ptrace.h"
3131 #include <signal.h>
3232
33+#include "arch/arm.h"
34+
3335 /* Defined in auto-generated files. */
3436 void init_registers_arm (void);
3537 extern const struct target_desc *tdesc_arm;
@@ -80,6 +82,14 @@ typedef enum
8082 arm_hwbp_access = 3
8183 } arm_hwbp_type;
8284
85+/* Enum describing the different kinds of breakpoints. */
86+enum arm_breakpoint_kinds
87+{
88+ ARM_BP_KIND_THUMB = 2,
89+ ARM_BP_KIND_THUMB2 = 3,
90+ ARM_BP_KIND_ARM = 4,
91+};
92+
8393 /* Type describing an ARM Hardware Breakpoint Control register value. */
8494 typedef unsigned int arm_hwbp_control_t;
8595
@@ -237,7 +247,9 @@ arm_set_pc (struct regcache *regcache, CORE_ADDR pc)
237247 static const unsigned long arm_breakpoint = 0xef9f0001;
238248 #define arm_breakpoint_len 4
239249 static const unsigned short thumb_breakpoint = 0xde01;
250+#define thumb_breakpoint_len 2
240251 static const unsigned short thumb2_breakpoint[] = { 0xf7f0, 0xa000 };
252+#define thumb2_breakpoint_len 4
241253
242254 /* For new EABI binaries. We recognize it regardless of which ABI
243255 is used for gdbserver, so single threaded debugging should work
@@ -913,7 +925,39 @@ arm_regs_info (void)
913925 return &regs_info_arm;
914926 }
915927
916-/* Implementation of linux_target_ops method "sw_breakpoint_from_kind". */
928+/* Implementation of linux_target_ops method "breakpoint_kind_from_pc".
929+
930+ Determine the type and size of breakpoint to insert at PCPTR. Uses the
931+ program counter value to determine whether a 16-bit or 32-bit breakpoint
932+ should be used. It returns the breakpoint's kind, and adjusts the program
933+ counter (if necessary) to point to the actual memory location where the
934+ breakpoint should be inserted. */
935+
936+static int
937+arm_breakpoint_kind_from_pc (CORE_ADDR *pcptr)
938+{
939+ if (IS_THUMB_ADDR (*pcptr))
940+ {
941+ gdb_byte buf[2];
942+
943+ *pcptr = UNMAKE_THUMB_ADDR (*pcptr);
944+
945+ /* Check whether we are replacing a thumb2 32-bit instruction. */
946+ if ((*the_target->read_memory) (*pcptr, buf, 2) == 0)
947+ {
948+ unsigned short inst1 = 0;
949+
950+ (*the_target->read_memory) (*pcptr, (gdb_byte *) &inst1, 2);
951+ if (thumb_insn_size (inst1) == 4)
952+ return ARM_BP_KIND_THUMB2;
953+ }
954+ return ARM_BP_KIND_THUMB;
955+ }
956+ else
957+ return ARM_BP_KIND_ARM;
958+}
959+
960+/* Implementation of the linux_target_ops method "sw_breakpoint_from_kind". */
917961
918962 static const gdb_byte *
919963 arm_sw_breakpoint_from_kind (int kind , int *size)
@@ -924,11 +968,25 @@ arm_sw_breakpoint_from_kind (int kind , int *size)
924968 clone events, we will never insert a breakpoint, so even a Thumb
925969 C library will work; so will mixing EABI/non-EABI gdbserver and
926970 application. */
971+ switch (kind)
972+ {
973+ case ARM_BP_KIND_THUMB:
974+ *size = thumb_breakpoint_len;
975+ return (gdb_byte *) &thumb_breakpoint;
976+ case ARM_BP_KIND_THUMB2:
977+ *size = thumb2_breakpoint_len;
978+ return (gdb_byte *) &thumb2_breakpoint;
979+ case ARM_BP_KIND_ARM:
980+ *size = arm_breakpoint_len;
927981 #ifndef __ARM_EABI__
928- return (const gdb_byte *) &arm_breakpoint;
982+ return (const gdb_byte *) &arm_breakpoint;
929983 #else
930- return (const gdb_byte *) &arm_eabi_breakpoint;
984+ return (const gdb_byte *) &arm_eabi_breakpoint;
931985 #endif
986+ default:
987+ return NULL;
988+ }
989+ return NULL;
932990 }
933991
934992 struct linux_target_ops the_low_target = {
@@ -939,7 +997,7 @@ struct linux_target_ops the_low_target = {
939997 NULL, /* fetch_register */
940998 arm_get_pc,
941999 arm_set_pc,
942- NULL, /* breakpoint_kind_from_pc */
1000+ arm_breakpoint_kind_from_pc,
9431001 arm_sw_breakpoint_from_kind,
9441002 arm_reinsert_addr,
9451003 0,