Home | History | Annotate | Line # | Download | only in gdb
      1 /* Native-dependent code for FreeBSD x86.
      2 
      3    Copyright (C) 2022-2024 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 "x86-fbsd-nat.h"
     21 #ifdef PT_GETXSTATE_INFO
     22 #include "nat/x86-xstate.h"
     23 #endif
     24 
     25 /* Implement the virtual fbsd_nat_target::low_new_fork method.  */
     26 
     27 void
     28 x86_fbsd_nat_target::low_new_fork (ptid_t parent, pid_t child)
     29 {
     30   struct x86_debug_reg_state *parent_state, *child_state;
     31 
     32   /* If there is no parent state, no watchpoints nor breakpoints have
     33      been set, so there is nothing to do.  */
     34   parent_state = x86_lookup_debug_reg_state (parent.pid ());
     35   if (parent_state == nullptr)
     36     return;
     37 
     38   /* The kernel clears debug registers in the new child process after
     39      fork, but GDB core assumes the child inherits the watchpoints/hw
     40      breakpoints of the parent, and will remove them all from the
     41      forked off process.  Copy the debug registers mirrors into the
     42      new process so that all breakpoints and watchpoints can be
     43      removed together.  */
     44 
     45   child_state = x86_debug_reg_state (child);
     46   *child_state = *parent_state;
     47 }
     48 
     49 #ifdef PT_GETXSTATE_INFO
     50 void
     51 x86_fbsd_nat_target::probe_xsave_layout (pid_t pid)
     52 {
     53   if (m_xsave_probed)
     54     return;
     55 
     56   m_xsave_probed = true;
     57 
     58   if (ptrace (PT_GETXSTATE_INFO, pid, (PTRACE_TYPE_ARG3) &m_xsave_info,
     59 	      sizeof (m_xsave_info)) != 0)
     60     return;
     61   if (m_xsave_info.xsave_len != 0)
     62     m_xsave_layout = x86_fetch_xsave_layout (m_xsave_info.xsave_mask,
     63 					     m_xsave_info.xsave_len);
     64 }
     65 #endif
     66