1/* Native-dependent code for FreeBSD x86.
2
3   Copyright (C) 2022-2023 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 "defs.h"
21#include "x86-fbsd-nat.h"
22
23/* Implement the virtual fbsd_nat_target::low_new_fork method.  */
24
25void
26x86_fbsd_nat_target::low_new_fork (ptid_t parent, pid_t child)
27{
28  struct x86_debug_reg_state *parent_state, *child_state;
29
30  /* If there is no parent state, no watchpoints nor breakpoints have
31     been set, so there is nothing to do.  */
32  parent_state = x86_lookup_debug_reg_state (parent.pid ());
33  if (parent_state == nullptr)
34    return;
35
36  /* The kernel clears debug registers in the new child process after
37     fork, but GDB core assumes the child inherits the watchpoints/hw
38     breakpoints of the parent, and will remove them all from the
39     forked off process.  Copy the debug registers mirrors into the
40     new process so that all breakpoints and watchpoints can be
41     removed together.  */
42
43  child_state = x86_debug_reg_state (child);
44  *child_state = *parent_state;
45}
46