public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
From: Valery Khromov <valery.khromov@gmail.com>
To: gdb-patches@sourceware.org
Cc: Valery Khromov <valery.khromov@gmail.com>
Subject: [PATCH] Fix PR gdb/12953: No hardware watchpoints on FreeBSD amd64
Date: Tue, 06 Dec 2011 02:41:00 -0000	[thread overview]
Message-ID: <1323132864-14029-1-git-send-email-valery.khromov@gmail.com> (raw)

This patch provides hardware breakpoint/watchpoint support for
FreeBSD/AMD64.  Most of the code is borrowed from the i386 implementation.

gdb/ChangeLog:
2011-12-05  Valery Khromov  <valery.khromov@gmail.com>

	PR gdb/12953
	* Makefile.in (HFILES_NO_SRCDIR): Add amd64bsd-nat.h.
	* amd64bsd-nat.c: Add support for debug registers (adapted from
	i386bsd-nat.c).
	[HAVE_PT_GETDBREGS] (DBREG_DRX): Define if not already defined.
	[HAVE_PT_GETDBREGS] (amd64bsd_dr_set, amd64bsd_dr_set_control,
	amd64bsd_dr_set_addr, amd64bsd_dr_reset_addr, amd64bsd_dr_get_status):
	New functions.
	* amd64bsd-nat.h: New file (adapted from i386bsd-nat.h).
	* amd64fbsd-nat.c: Include "amd64bsd-nat.h", "i386-nat.h".
	[HAVE_PT_GETDBREGS] (_initialize_amd64fbsd_nat): Add hardware
	watchpoints initialization.
	* config/i386/fbsd64.mh (NATDEPFILES): Add i386-nat.o.

diff --git a/gdb/Makefile.in b/gdb/Makefile.in
index 7db23a7..a0d3010 100644
--- a/gdb/Makefile.in
+++ b/gdb/Makefile.in
@@ -758,7 +758,7 @@ osf-share/cma_stack_int.h osf-share/cma_init.h \
 osf-share/cma_deb_core.h osf-share/AT386/cma_thread_io.h \
 osf-share/cma_sched.h proc-utils.h arm-tdep.h ax-gdb.h ppcnbsd-tdep.h \
 cli-out.h gdb_expat.h breakpoint.h infcall.h obsd-tdep.h \
-exec.h m32r-tdep.h osabi.h gdbcore.h solib-som.h \
+exec.h m32r-tdep.h osabi.h gdbcore.h solib-som.h amd64bsd-nat.h \
 i386bsd-nat.h xml-support.h xml-tdesc.h alphabsd-tdep.h gdb_obstack.h \
 ia64-tdep.h ada-lang.h varobj.h frv-tdep.h nto-tdep.h serial.h \
 c-lang.h d-lang.h frame.h event-loop.h block.h cli/cli-setshow.h	\
diff --git a/gdb/amd64bsd-nat.c b/gdb/amd64bsd-nat.c
index 7821f2b..8b2f678 100644
--- a/gdb/amd64bsd-nat.c
+++ b/gdb/amd64bsd-nat.c
@@ -126,3 +126,80 @@ amd64bsd_target (void)
   t->to_store_registers = amd64bsd_store_inferior_registers;
   return t;
 }
+\f
+
+/* Support for debug registers.  */
+
+#ifdef HAVE_PT_GETDBREGS
+
+/* Not all versions of FreeBSD/amd64 that support the debug registers
+   have this macro.  */
+#ifndef DBREG_DRX
+#define DBREG_DRX(d, x) ((&d->dr0)[x])
+#endif
+
+static void
+amd64bsd_dr_set (int regnum, unsigned long value)
+{
+  struct dbreg dbregs;
+
+  if (ptrace (PT_GETDBREGS, PIDGET (inferior_ptid),
+              (PTRACE_TYPE_ARG3) &dbregs, 0) == -1)
+    perror_with_name (_("Couldn't get debug registers"));
+
+  /* For some mysterious reason, some of the reserved bits in the
+     debug control register get set.  Mask these off, otherwise the
+     ptrace call below will fail.  */
+  DBREG_DRX ((&dbregs), 7) &= ~(0xffffffff0000fc00);
+
+  DBREG_DRX ((&dbregs), regnum) = value;
+
+  if (ptrace (PT_SETDBREGS, PIDGET (inferior_ptid),
+              (PTRACE_TYPE_ARG3) &dbregs, 0) == -1)
+    perror_with_name (_("Couldn't write debug registers"));
+}
+
+void
+amd64bsd_dr_set_control (unsigned long control)
+{
+  amd64bsd_dr_set (7, control);
+}
+
+void
+amd64bsd_dr_set_addr (int regnum, CORE_ADDR addr)
+{
+  gdb_assert (regnum >= 0 && regnum <= 4);
+
+  amd64bsd_dr_set (regnum, addr);
+}
+
+void
+amd64bsd_dr_reset_addr (int regnum)
+{
+  gdb_assert (regnum >= 0 && regnum <= 4);
+
+  amd64bsd_dr_set (regnum, 0);
+}
+
+unsigned long
+amd64bsd_dr_get_status (void)
+{
+  struct dbreg dbregs;
+
+  /* FIXME: kettenis/2001-03-31: Calling perror_with_name if the
+     ptrace call fails breaks debugging remote targets.  The correct
+     way to fix this is to add the hardware breakpoint and watchpoint
+     stuff to the target vector.  For now, just return zero if the
+     ptrace call fails.  */
+  if (ptrace (PT_GETDBREGS, PIDGET (inferior_ptid),
+	      (PTRACE_TYPE_ARG3) &dbregs, 0) == -1)
+#if 0
+    perror_with_name (_("Couldn't read debug registers"));
+#else
+    return 0;
+#endif
+
+  return DBREG_DRX ((&dbregs), 6);
+}
+
+#endif /* PT_GETDBREGS */
diff --git a/gdb/amd64bsd-nat.h b/gdb/amd64bsd-nat.h
new file mode 100644
index 0000000..0048f54
--- /dev/null
+++ b/gdb/amd64bsd-nat.h
@@ -0,0 +1,35 @@
+/* Native-dependent code for modern AMD64 BSD's.
+
+   Copyright (C) 2011
+   Free Software Foundation, Inc.
+   Contributed by Valery Khromov, Yandex.
+
+   This file is part of GDB.
+
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 3 of the License, or
+   (at your option) any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
+
+#ifndef AMD64BSD_NAT_H
+#define AMD64BSD_NAT_H
+
+/* low level amd64 debug register functions used in amd64fbsd-nat.c.  */
+
+extern void amd64bsd_dr_set_control (unsigned long control);
+
+extern void amd64bsd_dr_set_addr (int regnum, CORE_ADDR addr);
+
+extern void amd64bsd_dr_reset_addr (int regnum);
+
+extern unsigned long amd64bsd_dr_get_status (void);
+
+#endif /* amd64bsd-nat.h */
diff --git a/gdb/amd64fbsd-nat.c b/gdb/amd64fbsd-nat.c
index 1663abc..8ffd42b 100644
--- a/gdb/amd64fbsd-nat.c
+++ b/gdb/amd64fbsd-nat.c
@@ -35,6 +35,8 @@
 #include "fbsd-nat.h"
 #include "amd64-tdep.h"
 #include "amd64-nat.h"
+#include "amd64bsd-nat.h"
+#include "i386-nat.h"
 \f
 
 /* Offset in `struct reg' where MEMBER is stored.  */
@@ -197,6 +199,19 @@ _initialize_amd64fbsd_nat (void)
 
   /* Add some extra features to the common *BSD/i386 target.  */
   t = amd64bsd_target ();
+
+#ifdef HAVE_PT_GETDBREGS
+
+  i386_use_watchpoints (t);
+
+  i386_dr_low.set_control = amd64bsd_dr_set_control;
+  i386_dr_low.set_addr = amd64bsd_dr_set_addr;
+  i386_dr_low.reset_addr = amd64bsd_dr_reset_addr;
+  i386_dr_low.get_status = amd64bsd_dr_get_status;
+  i386_set_debug_register_length (8);
+
+#endif /* HAVE_PT_GETDBREGS */
+
   t->to_pid_to_exec_file = fbsd_pid_to_exec_file;
   t->to_find_memory_regions = fbsd_find_memory_regions;
   t->to_make_corefile_notes = fbsd_make_corefile_notes;
diff --git a/gdb/config/i386/fbsd64.mh b/gdb/config/i386/fbsd64.mh
index 2266def..24a87bf 100644
--- a/gdb/config/i386/fbsd64.mh
+++ b/gdb/config/i386/fbsd64.mh
@@ -1,6 +1,6 @@
 # Host: FreeBSD/amd64
 NATDEPFILES= fork-child.o inf-ptrace.o \
-	fbsd-nat.o amd64-nat.o amd64bsd-nat.o amd64fbsd-nat.o \
+	fbsd-nat.o i386-nat.o amd64-nat.o amd64bsd-nat.o amd64fbsd-nat.o \
 	bsd-kvm.o
 
 LOADLIBES= -lkvm
-- 
WBR,
Valery Khromov

             reply	other threads:[~2011-12-06  0:54 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-12-06  2:41 Valery Khromov [this message]
2011-12-20 14:52 ` Tom Tromey
2011-12-20 18:30   ` Valery Khromov
2011-12-21  6:45     ` Joel Brobecker
2011-12-20 15:04 ` Mark Kettenis
2011-12-20 16:12   ` Pedro Alves
2011-12-20 17:52     ` Valery Khromov
2011-12-20 17:53       ` [PATCH 1/2] FreeBSD/amd64: Updates for the recent changes that Pedro Alves made Valery Khromov
2011-12-20 17:56       ` [PATCH 2/2] FreeBSD: Removed definition of DBREG_DRX macro because it is already in FreeBSD Valery Khromov
2011-12-20 19:44       ` [PATCH] Fix PR gdb/12953: No hardware watchpoints on FreeBSD amd64 Mark Kettenis
2011-12-20 20:38         ` [PATCH v2] " Valery Khromov
2012-01-31 17:50           ` Valery Khromov
2012-02-01 20:27             ` Tom Tromey
2012-02-02  9:03               ` Valery Khromov
2012-02-11 18:51                 ` Mark Kettenis
2012-02-11 21:03                   ` Valery Khromov
2012-02-09 16:10           ` Pedro Alves
2011-12-20 16:05 ` [PATCH] " Pedro Alves

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1323132864-14029-1-git-send-email-valery.khromov@gmail.com \
    --to=valery.khromov@gmail.com \
    --cc=gdb-patches@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).