Move aarch64_linux_new_thread to nat/aarch64-linux.c
[external/binutils.git] / gdb / nat / aarch64-linux.c
1 /* Copyright (C) 2009-2015 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 /* Called when resuming a thread LWP.
26    The hardware debug registers are updated when there is any change.  */
27
28 void
29 aarch64_linux_prepare_to_resume (struct lwp_info *lwp)
30 {
31   struct arch_lwp_info *info = lwp_arch_private_info (lwp);
32
33   /* NULL means this is the main thread still going through the shell,
34      or, no watchpoint has been set yet.  In that case, there's
35      nothing to do.  */
36   if (info == NULL)
37     return;
38
39   if (DR_HAS_CHANGED (info->dr_changed_bp)
40       || DR_HAS_CHANGED (info->dr_changed_wp))
41     {
42       ptid_t ptid = ptid_of_lwp (lwp);
43       int tid = ptid_get_lwp (ptid);
44       struct aarch64_debug_reg_state *state
45         = aarch64_get_debug_reg_state (ptid_get_pid (ptid));
46
47       if (show_debug_regs)
48         debug_printf ("prepare_to_resume thread %d\n", tid);
49
50       /* Watchpoints.  */
51       if (DR_HAS_CHANGED (info->dr_changed_wp))
52         {
53           aarch64_linux_set_debug_regs (state, tid, 1);
54           DR_CLEAR_CHANGED (info->dr_changed_wp);
55         }
56
57       /* Breakpoints.  */
58       if (DR_HAS_CHANGED (info->dr_changed_bp))
59         {
60           aarch64_linux_set_debug_regs (state, tid, 0);
61           DR_CLEAR_CHANGED (info->dr_changed_bp);
62         }
63     }
64 }
65
66 /* Function to call when a new thread is detected.  */
67
68 void
69 aarch64_linux_new_thread (struct lwp_info *lwp)
70 {
71   struct arch_lwp_info *info = xcalloc (1, sizeof (*info));
72
73   /* Mark that all the hardware breakpoint/watchpoint register pairs
74      for this thread need to be initialized (with data from
75      aarch_process_info.debug_reg_state).  */
76   DR_MARK_ALL_CHANGED (info->dr_changed_bp, aarch64_num_bp_regs);
77   DR_MARK_ALL_CHANGED (info->dr_changed_wp, aarch64_num_wp_regs);
78
79   lwp_set_arch_private_info (lwp, info);
80 }