1 /* Native-dependent code for GNU/Linux on LoongArch processors.
3 Copyright (C) 2024 Free Software Foundation, Inc.
4 Contributed by Loongson Ltd.
6 This file is part of GDB.
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 3 of the License, or
11 (at your option) any later version.
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.
18 You should have received a copy of the GNU General Public License
19 along with this program. If not, see <http://www.gnu.org/licenses/>. */
21 #include "gdbsupport/common-defs.h"
22 #include "gdbsupport/break-common.h"
23 #include "nat/linux-nat.h"
24 #include "nat/loongarch-linux-hw-point.h"
25 #include "nat/loongarch-linux.h"
27 #include "elf/common.h"
28 #include "nat/gdb_ptrace.h"
29 #include <asm/ptrace.h>
32 /* Called when resuming a thread LWP.
33 The hardware debug registers are updated when there is any change. */
36 loongarch_linux_prepare_to_resume (struct lwp_info
*lwp
)
38 struct arch_lwp_info
*info
= lwp_arch_private_info (lwp
);
40 /* NULL means this is the main thread still going through the shell,
41 or, no watchpoint has been set yet. In that case, there's
46 if (DR_HAS_CHANGED (info
->dr_changed_bp
)
47 || DR_HAS_CHANGED (info
->dr_changed_wp
))
49 ptid_t ptid
= ptid_of_lwp (lwp
);
50 int tid
= ptid
.lwp ();
51 struct loongarch_debug_reg_state
*state
52 = loongarch_get_debug_reg_state (ptid
.pid ());
55 debug_printf ("prepare_to_resume thread %d\n", tid
);
58 if (DR_HAS_CHANGED (info
->dr_changed_wp
))
60 loongarch_linux_set_debug_regs (state
, tid
, 1);
61 DR_CLEAR_CHANGED (info
->dr_changed_wp
);
65 if (DR_HAS_CHANGED (info
->dr_changed_bp
))
67 loongarch_linux_set_debug_regs (state
, tid
, 0);
68 DR_CLEAR_CHANGED (info
->dr_changed_bp
);
73 /* Function to call when a new thread is detected. */
76 loongarch_linux_new_thread (struct lwp_info
*lwp
)
78 ptid_t ptid
= ptid_of_lwp (lwp
);
79 struct loongarch_debug_reg_state
*state
80 = loongarch_get_debug_reg_state (ptid
.pid ());
81 struct arch_lwp_info
*info
= XCNEW (struct arch_lwp_info
);
83 /* If there are hardware breakpoints/watchpoints in the process then mark that
84 all the hardware breakpoint/watchpoint register pairs for this thread need
85 to be initialized (with data from arch_process_info.debug_reg_state). */
86 if (loongarch_any_set_debug_regs_state (state
, false))
87 DR_MARK_ALL_CHANGED (info
->dr_changed_bp
, loongarch_num_bp_regs
);
88 if (loongarch_any_set_debug_regs_state (state
, true))
89 DR_MARK_ALL_CHANGED (info
->dr_changed_wp
, loongarch_num_wp_regs
);
91 lwp_set_arch_private_info (lwp
, info
);
94 /* See nat/loongarch-linux.h. */
97 loongarch_linux_delete_thread (struct arch_lwp_info
*arch_lwp
)