GDB (xrefs)

aarch64-linux.c
Go to the documentation of this file.
1 /* Copyright (C) 2009-2018 Free Software Foundation, Inc.
2 Contributed by ARM Ltd.
3
4 This file is part of GDB.
5
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 3 of the License, or
9 (at your option) any later version.
10
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with this program. If not, see <http://www.gnu.org/licenses/>. */
18
19 #include "common-defs.h"
20 #include "break-common.h"
21 #include "nat/linux-nat.h"
22 #include "nat/aarch64-linux-hw-point.h"
23 #include "nat/aarch64-linux.h"
24
25 #include "elf/common.h"
26 #include "nat/gdb_ptrace.h"
27 #include <asm/ptrace.h>
28 #include <sys/uio.h>
29
30 /* Called when resuming a thread LWP.
31 The hardware debug registers are updated when there is any change. */
32
33 void
34 aarch64_linux_prepare_to_resume (struct lwp_info *lwp)
35 {
36 struct arch_lwp_info *info = lwp_arch_private_info (lwp);
37
38 /* NULL means this is the main thread still going through the shell,
39 or, no watchpoint has been set yet. In that case, there's
40 nothing to do. */
41 if (info == NULL)
42 return;
43
44 if (DR_HAS_CHANGED (info->dr_changed_bp)
45 || DR_HAS_CHANGED (info->dr_changed_wp))
46 {
47 ptid_t ptid = ptid_of_lwp (lwp);
48 int tid = ptid_get_lwp (ptid);
49 struct aarch64_debug_reg_state *state
50 = aarch64_get_debug_reg_state (ptid_get_pid (ptid));
51
52 if (show_debug_regs)
53 debug_printf ("prepare_to_resume thread %d\n", tid);
54
55 /* Watchpoints. */
56 if (DR_HAS_CHANGED (info->dr_changed_wp))
57 {
58 aarch64_linux_set_debug_regs (state, tid, 1);
59 DR_CLEAR_CHANGED (info->dr_changed_wp);
60 }
61
62 /* Breakpoints. */
63 if (DR_HAS_CHANGED (info->dr_changed_bp))
64 {
65 aarch64_linux_set_debug_regs (state, tid, 0);
66 DR_CLEAR_CHANGED (info->dr_changed_bp);
67 }
68 }
69 }
70
71 /* Function to call when a new thread is detected. */
72
73 void
74 aarch64_linux_new_thread (struct lwp_info *lwp)
75 {
76 struct arch_lwp_info *info = XNEW (struct arch_lwp_info);
77
78 /* Mark that all the hardware breakpoint/watchpoint register pairs
79 for this thread need to be initialized (with data from
80 aarch_process_info.debug_reg_state). */
81 DR_MARK_ALL_CHANGED (info->dr_changed_bp, aarch64_num_bp_regs);
82 DR_MARK_ALL_CHANGED (info->dr_changed_wp, aarch64_num_wp_regs);
83
84 lwp_set_arch_private_info (lwp, info);
85 }
86
87 /* See nat/aarch64-linux.h. */
88
89 void
90 aarch64_linux_delete_thread (struct arch_lwp_info *arch_lwp)
91 {
92 xfree (arch_lwp);
93 }
94
95 /* Convert native siginfo FROM to the siginfo in the layout of the
96 inferior's architecture TO. */
97
98 void
99 aarch64_compat_siginfo_from_siginfo (compat_siginfo_t *to, siginfo_t *from)
100 {
101 memset (to, 0, sizeof (*to));
102
103 to->si_signo = from->si_signo;
104 to->si_errno = from->si_errno;
105 to->si_code = from->si_code;
106
107 if (to->si_code == SI_TIMER)
108 {
109 to->cpt_si_timerid = from->si_timerid;
110 to->cpt_si_overrun = from->si_overrun;
111 to->cpt_si_ptr = (intptr_t) from->si_ptr;
112 }
113 else if (to->si_code == SI_USER)
114 {
115 to->cpt_si_pid = from->si_pid;
116 to->cpt_si_uid = from->si_uid;
117 }
118 else if (to->si_code < 0)
119 {
120 to->cpt_si_pid = from->si_pid;
121 to->cpt_si_uid = from->si_uid;
122 to->cpt_si_ptr = (intptr_t) from->si_ptr;
123 }
124 else
125 {
126 switch (to->si_signo)
127 {
128 case SIGCHLD:
129 to->cpt_si_pid = from->si_pid;
130 to->cpt_si_uid = from->si_uid;
131 to->cpt_si_status = from->si_status;
132 to->cpt_si_utime = from->si_utime;
133 to->cpt_si_stime = from->si_stime;
134 break;
135 case SIGILL:
136 case SIGFPE:
137 case SIGSEGV:
138 case SIGBUS:
139 to->cpt_si_addr = (intptr_t) from->si_addr;
140 break;
141 case SIGPOLL:
142 to->cpt_si_band = from->si_band;
143 to->cpt_si_fd = from->si_fd;
144 break;
145 default:
146 to->cpt_si_pid = from->si_pid;
147 to->cpt_si_uid = from->si_uid;
148 to->cpt_si_ptr = (intptr_t) from->si_ptr;
149 break;
150 }
151 }
152 }
153
154 /* Convert inferior's architecture siginfo FROM to native siginfo TO. */
155
156 void
157 aarch64_siginfo_from_compat_siginfo (siginfo_t *to, compat_siginfo_t *from)
158 {
159 memset (to, 0, sizeof (*to));
160
161 to->si_signo = from->si_signo;
162 to->si_errno = from->si_errno;
163 to->si_code = from->si_code;
164
165 if (to->si_code == SI_TIMER)
166 {
167 to->si_timerid = from->cpt_si_timerid;
168 to->si_overrun = from->cpt_si_overrun;
169 to->si_ptr = (void *) (intptr_t) from->cpt_si_ptr;
170 }
171 else if (to->si_code == SI_USER)
172 {
173 to->si_pid = from->cpt_si_pid;
174 to->si_uid = from->cpt_si_uid;
175 }
176 if (to->si_code < 0)
177 {
178 to->si_pid = from->cpt_si_pid;
179 to->si_uid = from->cpt_si_uid;
180 to->si_ptr = (void *) (intptr_t) from->cpt_si_ptr;
181 }
182 else
183 {
184 switch (to->si_signo)
185 {
186 case SIGCHLD:
187 to->si_pid = from->cpt_si_pid;
188 to->si_uid = from->cpt_si_uid;
189 to->si_status = from->cpt_si_status;
190 to->si_utime = from->cpt_si_utime;
191 to->si_stime = from->cpt_si_stime;
192 break;
193 case SIGILL:
194 case SIGFPE:
195 case SIGSEGV:
196 case SIGBUS:
197 to->si_addr = (void *) (intptr_t) from->cpt_si_addr;
198 break;
199 case SIGPOLL:
200 to->si_band = from->cpt_si_band;
201 to->si_fd = from->cpt_si_fd;
202 break;
203 default:
204 to->si_pid = from->cpt_si_pid;
205 to->si_uid = from->cpt_si_uid;
206 to->si_ptr = (void* ) (intptr_t) from->cpt_si_ptr;
207 break;
208 }
209 }
210 }
211
212 /* Called by libthread_db. Returns a pointer to the thread local
213 storage (or its descriptor). */
214
215 ps_err_e
216 aarch64_ps_get_thread_area (struct ps_prochandle *ph,
217 lwpid_t lwpid, int idx, void **base,
218 int is_64bit_p)
219 {
220 struct iovec iovec;
221 uint64_t reg64;
222 uint32_t reg32;
223
224 if (is_64bit_p)
225 {
226 iovec.iov_base = &reg64;
227 iovec.iov_len = sizeof (reg64);
228 }
229 else
230 {
231 iovec.iov_base = &reg32;
232 iovec.iov_len = sizeof (reg32);
233 }
234
235 if (ptrace (PTRACE_GETREGSET, lwpid, NT_ARM_TLS, &iovec) != 0)
236 return PS_ERR;
237
238 /* IDX is the bias from the thread pointer to the beginning of the
239 thread descriptor. It has to be subtracted due to implementation
240 quirks in libthread_db. */
241 if (is_64bit_p)
242 *base = (void *) (reg64 - idx);
243 else
244 *base = (void *) (uintptr_t) (reg32 - idx);
245
246 return PS_OK;
247 }
lwpid_t
unsigned int lwpid_t
Definition: gdb_proc_service.h:80
aarch64_linux_new_thread
void aarch64_linux_new_thread(struct lwp_info *lwp)
Definition: aarch64-linux.c:74
selftests::ptid::tid
static constexpr ptid_t tid
Definition: ptid-selftests.c:43
DR_CLEAR_CHANGED
#define DR_CLEAR_CHANGED(x)
Definition: aarch64-linux-hw-point.h:126
lwp_arch_private_info
struct arch_lwp_info * lwp_arch_private_info(struct lwp_info *lwp)
Definition: linux-nat.c:340
aarch64_num_wp_regs
int aarch64_num_wp_regs
Definition: aarch64-linux-hw-point.c:35
ptid_get_pid
int ptid_get_pid(const ptid_t &ptid)
Definition: ptid.c:47
xfree
void xfree(void *)
lwp_info
Definition: linux-nat.h:30
aarch64_num_bp_regs
int aarch64_num_bp_regs
Definition: aarch64-linux-hw-point.c:34
aarch64_linux_set_debug_regs
void aarch64_linux_set_debug_regs(const struct aarch64_debug_reg_state *state, int tid, int watchpoint)
Definition: aarch64-linux-hw-point.c:555
ps_prochandle
Definition: gdb_proc_service.h:179
memset
void * memset(T *s, int c, size_t n)=delete
aarch64_linux_delete_thread
void aarch64_linux_delete_thread(struct arch_lwp_info *arch_lwp)
Definition: aarch64-linux.c:90
ps_err_e
ps_err_e
Definition: gdb_proc_service.h:68
DR_MARK_ALL_CHANGED
#define DR_MARK_ALL_CHANGED(x, m)
Definition: aarch64-linux-hw-point.h:113
ptrace
PTRACE_TYPE_RET ptrace()
ptid_of_lwp
ptid_t ptid_of_lwp(struct lwp_info *lwp)
Definition: linux-nat.c:323
DR_HAS_CHANGED
#define DR_HAS_CHANGED(x)
Definition: aarch64-linux-hw-point.h:132
XNEW
#define XNEW(T)
Definition: poison.h:109
arch_lwp_info
Definition: arm-linux-nat.c:731
aarch64_compat_siginfo_from_siginfo
void aarch64_compat_siginfo_from_siginfo(compat_siginfo_t *to, siginfo_t *from)
Definition: aarch64-linux.c:99
linux-nat.h
ptid_t
Definition: ptid.h:35
show_debug_regs
int show_debug_regs
Definition: common-debug.c:25
aarch64_linux_prepare_to_resume
void aarch64_linux_prepare_to_resume(struct lwp_info *lwp)
Definition: aarch64-linux.c:34
break-common.h
common-defs.h
compat_siginfo::si_code
int si_code
Definition: aarch64-linux.h:50
ptid_get_lwp
long ptid_get_lwp(const ptid_t &ptid)
Definition: ptid.c:55
compat_siginfo::si_signo
int si_signo
Definition: aarch64-linux.h:48
PS_ERR
Definition: gdb_proc_service.h:71
PTRACE_GETREGSET
#define PTRACE_GETREGSET
Definition: linux-ptrace.h:47
aarch64-linux.h
aarch64-linux-hw-point.h
aarch64_get_debug_reg_state
struct aarch64_debug_reg_state * aarch64_get_debug_reg_state(pid_t pid)
Definition: aarch64-linux-nat.c:146
aarch64_ps_get_thread_area
ps_err_e aarch64_ps_get_thread_area(struct ps_prochandle *ph, lwpid_t lwpid, int idx, void **base, int is_64bit_p)
Definition: aarch64-linux.c:216
aarch64_debug_reg_state
Definition: aarch64-linux-hw-point.h:142
selftests::ptid::lwp
static constexpr ptid_t lwp
Definition: ptid-selftests.c:42
arch_lwp_info::dr_changed_wp
dr_changed_t dr_changed_wp
Definition: aarch64-linux-hw-point.h:163
PS_OK
Definition: gdb_proc_service.h:70
gdb_ptrace.h
lwp_set_arch_private_info
void lwp_set_arch_private_info(struct lwp_info *lwp, struct arch_lwp_info *info)
Definition: linux-nat.c:331
debug_printf
void debug_printf(const char *fmt,...)
Definition: common-debug.c:30
arch_lwp_info::dr_changed_bp
dr_changed_t dr_changed_bp
Definition: aarch64-linux-hw-point.h:162
aarch64_siginfo_from_compat_siginfo
void aarch64_siginfo_from_compat_siginfo(siginfo_t *to, compat_siginfo_t *from)
Definition: aarch64-linux.c:157
compat_siginfo::si_errno
int si_errno
Definition: aarch64-linux.h:49
compat_siginfo
Definition: aarch64-linux.h:46