From kostik@kib.kiev.ua  Sun May 13 14:48:41 2001
Return-Path: <kostik@kib.kiev.ua>
Received: from smtp.lucky.net (smtp.lucky.net [193.193.193.117])
	by hub.freebsd.org (Postfix) with ESMTP id 52A2237B422
	for <FreeBSD-gnats-submit@freebsd.org>; Sun, 13 May 2001 14:48:38 -0700 (PDT)
	(envelope-from kostik@kib.kiev.ua)
Received: from kozlik.carrier.kiev.ua (kozlik.carrier.kiev.ua [193.193.193.111])
	by smtp.lucky.net (20001217) with ESMTP id 075712C7105
	for <FreeBSD-gnats-submit@freebsd.org>; Mon, 14 May 2001 00:48:34 +0300 (EEST)
Received: (from uucp@localhost)
	by kozlik.carrier.kiev.ua  with UUCP id ASQ79214;
	Mon, 14 May 2001 00:48:27 +0300 (EEST)
	(envelope-from kostik@kib.kiev.ua)
Received: from kib.UUCP (uucp@localhost)
	by kozlik.carrier.kiev.ua (rmail mypid=79213 childpid=79214) with UUCP;
	Sun, 13 May 2001 21:48:27 +0000 GMT
Received: (from kostik@localhost)
	by kib.kiev.ua (8.11.3/8.11.3) id f4DLkZJ12935;
	Mon, 14 May 2001 00:46:35 +0300 (EEST)
	(envelope-from kostik)
Message-Id: <200105132146.f4DLkZJ12935@kib.kiev.ua>
Date: Mon, 14 May 2001 00:46:35 +0300 (EEST)
From: kostik@kieb.kiev.ua
Reply-To: kostya@tessart.kiev.ua
To: FreeBSD-gnats-submit@freebsd.org
Cc: kostya@tessart.kiev.ua
Subject: hw watchpoints work unreliable under gdb
X-Send-Pr-Version: 3.113
X-GNATS-Notify:

>Number:         27306
>Category:       bin
>Synopsis:       [patch] hw watchpoints work unreliable under gdb(1)
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    freebsd-bugs
>State:          open
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Sun May 13 14:50:01 PDT 2001
>Closed-Date:    
>Last-Modified:  Mon Feb 21 18:50:13 UTC 2011
>Originator:     Kostik I. Belousov
>Release:        FreeBSD 4.3-RELEASE i386
>Organization:
@home
>Environment:
System: FreeBSD little.home 4.3-RELEASE FreeBSD 4.3-RELEASE #0: Wed Apr 25 22:39:00 EEST 2001 root@little.home:/usr/src/sys/compile/LITTLE i386

K6-2/266, 64 Mb, ... - not relevant

>Description:

The insert_watchpoint()
in the /usr/src/gnu/usr.bin/binutils/gdb/i386/freebsd-nat.c
contains at least 2 bugs:

1. at line 604, fragment
     if (ptrace(PT_SETDBREGS, pid, (caddr_t)&dbr, 0) == -1)
        {
          perror("ptrace(PT_SETDBREGS) failed");
          return 0;
        }
    }
    does not specify return value.
insert_breakpoints() sometimes is misinformed on the result
of the watch insertion. It seems that the "return 0;" statement is missed.

2. At least on my K6-2, reserved bit 10 of dr7 could be eq 1.
In this case, ptrace(PT_SETDBREGS, ...) fails. Might be,
all reserved bits in the dr7 should be explicitly cleared
after ptrace(PT_GETDBREGS,...) at line 535.

The same is true for remove_watchpoint().

>How-To-Repeat:
	Some attempts of setting hw watchpoint under gdb fail.
>Fix:

The following is the proposed
diff for
/usr/src/gnu/usr.bin/binutils/gdb/i386/freebsd-nat.c

--- freebsd-nat.c.orig	Fri Jan  5 19:51:06 2001
+++ freebsd-nat.c	Mon May 14 00:25:36 2001
@@ -534,4 +534,5 @@
 	  return 0;
 	}
+      dbr.dr7 &= ~0xfc00;
 
       for (i = 0, mask = 0x03; i < 4; i++, mask <<= 2)
@@ -603,4 +604,5 @@
 	  return 0;
 	}
+      return 0;
     }
   else
@@ -634,4 +636,5 @@
 	  return 0;
 	}
+      dbr.dr7 &= ~0xfc00;
 
       for (i = 0, dbregp = &dbr.dr0; i < 4; i++, dbregp++)
@@ -658,4 +661,5 @@
 	  return 0;
 	}
+      return 0;
     }
   else
>Release-Note:
>Audit-Trail:
Responsible-Changed-From-To: freebsd-bugs->obrien 
Responsible-Changed-By: dd 
Responsible-Changed-When: Mon May 14 17:25:05 PDT 2001 
Responsible-Changed-Why:  
Over to in-tree toolchain maintainer. 

http://www.FreeBSD.org/cgi/query-pr.cgi?pr=27306 
Responsible-Changed-From-To: obrien->freebsd-bugs 
Responsible-Changed-By: obrien 
Responsible-Changed-When: Mon Sep 10 09:33:16 PDT 2001 
Responsible-Changed-Why:  
I am not the maintainer. 

http://www.FreeBSD.org/cgi/query-pr.cgi?pr=27306 
Responsible-Changed-From-To: freebsd-bugs->mp 
Responsible-Changed-By: sheldonh 
Responsible-Changed-When: Wed Jan 30 05:15:55 PST 2002 
Responsible-Changed-Why:  
Over to maintainer. 

http://www.FreeBSD.org/cgi/query-pr.cgi?pr=27306 
Responsible-Changed-From-To: mp->marcel 
Responsible-Changed-By: marcel 
Responsible-Changed-When: Sat Jul 17 01:55:20 GMT 2004 
Responsible-Changed-Why:  
It may be too late to worry about this now, but it's a gdb issue 
nontheless. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=27306 
Responsible-Changed-From-To: marcel->freebsd-bugs 
Responsible-Changed-By: marcel 
Responsible-Changed-When: Mon Feb 21 18:49:51 UTC 2011 
Responsible-Changed-Why:  
Assign back to the pool. I haven't been working on it and it's unlikely 
I will in the near future.  

http://www.freebsd.org/cgi/query-pr.cgi?pr=27306 
>Unformatted:
