gdb/
[deliverable/binutils-gdb.git] / gdb / gdbserver / linux-arm-low.c
1 /* GNU/Linux/ARM specific low level interface, for the remote server for GDB.
2 Copyright (C) 1995, 1996, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005,
3 2006
4 Free Software Foundation, Inc.
5
6 This file is part of GDB.
7
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2 of the License, or
11 (at your option) any later version.
12
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
17
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 51 Franklin Street, Fifth Floor,
21 Boston, MA 02110-1301, USA. */
22
23 #include "server.h"
24 #include "linux-low.h"
25
26 #include <sys/ptrace.h>
27
28 #include "gdb_proc_service.h"
29
30 #ifndef PTRACE_GET_THREAD_AREA
31 #define PTRACE_GET_THREAD_AREA 22
32 #endif
33
34 #ifdef HAVE_SYS_REG_H
35 #include <sys/reg.h>
36 #endif
37
38 #define arm_num_regs 26
39
40 static int arm_regmap[] = {
41 0, 4, 8, 12, 16, 20, 24, 28,
42 32, 36, 40, 44, 48, 52, 56, 60,
43 -1, -1, -1, -1, -1, -1, -1, -1, -1,
44 64
45 };
46
47 static int
48 arm_cannot_store_register (int regno)
49 {
50 return (regno >= arm_num_regs);
51 }
52
53 static int
54 arm_cannot_fetch_register (int regno)
55 {
56 return (regno >= arm_num_regs);
57 }
58
59 extern int debug_threads;
60
61 static CORE_ADDR
62 arm_get_pc ()
63 {
64 unsigned long pc;
65 collect_register_by_name ("pc", &pc);
66 if (debug_threads)
67 fprintf (stderr, "stop pc is %08lx\n", pc);
68 return pc;
69 }
70
71 static void
72 arm_set_pc (CORE_ADDR pc)
73 {
74 unsigned long newpc = pc;
75 supply_register_by_name ("pc", &newpc);
76 }
77
78 /* Correct in either endianness. We do not support Thumb yet. */
79 static const unsigned long arm_breakpoint = 0xef9f0001;
80 #define arm_breakpoint_len 4
81
82 /* For new EABI binaries. We recognize it regardless of which ABI
83 is used for gdbserver, so single threaded debugging should work
84 OK, but for multi-threaded debugging we only insert the current
85 ABI's breakpoint instruction. For now at least. */
86 static const unsigned long arm_eabi_breakpoint = 0xe7f001f0;
87
88 static int
89 arm_breakpoint_at (CORE_ADDR where)
90 {
91 unsigned long insn;
92
93 (*the_target->read_memory) (where, (unsigned char *) &insn, 4);
94 if (insn == arm_breakpoint)
95 return 1;
96
97 if (insn == arm_eabi_breakpoint)
98 return 1;
99
100 /* If necessary, recognize more trap instructions here. GDB only uses the
101 two. */
102
103 return 0;
104 }
105
106 /* We only place breakpoints in empty marker functions, and thread locking
107 is outside of the function. So rather than importing software single-step,
108 we can just run until exit. */
109 static CORE_ADDR
110 arm_reinsert_addr ()
111 {
112 unsigned long pc;
113 collect_register_by_name ("lr", &pc);
114 return pc;
115 }
116
117 /* Fetch the thread-local storage pointer for libthread_db. */
118
119 ps_err_e
120 ps_get_thread_area (const struct ps_prochandle *ph,
121 lwpid_t lwpid, int idx, void **base)
122 {
123 if (ptrace (PTRACE_GET_THREAD_AREA, lwpid, NULL, base) != 0)
124 return PS_ERR;
125
126 /* IDX is the bias from the thread pointer to the beginning of the
127 thread descriptor. It has to be subtracted due to implementation
128 quirks in libthread_db. */
129 *base = (void *) ((char *)*base - idx);
130
131 return PS_OK;
132 }
133
134 struct linux_target_ops the_low_target = {
135 arm_num_regs,
136 arm_regmap,
137 arm_cannot_fetch_register,
138 arm_cannot_store_register,
139 arm_get_pc,
140 arm_set_pc,
141 #ifndef __ARM_EABI__
142 (const unsigned char *) &arm_breakpoint,
143 #else
144 (const unsigned char *) &arm_eabi_breakpoint,
145 #endif
146 arm_breakpoint_len,
147 arm_reinsert_addr,
148 0,
149 arm_breakpoint_at,
150 };
This page took 0.044617 seconds and 5 git commands to generate.