This is the mail archive of the gdb-patches@sources.redhat.com mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[RFC/RFA] Add hardware watchpoint support for cygwin target.



    Following DJ Delorie's suggestion to use
CONTEXT_DEBUG_REGISTERS, I tested the
use of i386 debug registers to set hardware watchpoints.

   It works successfully on my Win2000 box here.

But te are some annoying things,
the most annoying is that an exception seems to be generated
on read access of the watched area even if you only set a normal
watchpoint (which should use a write-only debug feature).

    This results in lost of garbage written on output due
to the fact that mention function is called for watchpoints
even if the value remains unchanged and thus no stop is done...
    It is unclear to me if this is a bug in the breakpoint code or
if i386 code should take care of this issue.

   To Eli:
    If you test this patch, that contains a call to i386_cleanup_dregs(),
you can test the failure if you comment the call out...

PS:  the patch should be a Dos style text file,
Eudora seems completely unable to send Unix style text file....
Hopefully this will not create other problems.

2001-11-28 Pierre Muller  <muller@ics.u-strasbg.fr>

	* win32-nat.c (CONTEXT_DEBUG_DR macro): Add use of CONTEXT_DEBUG_REGISTERS.
	(dr variable): New static array containing a local copy of debug registers.
	(debug_registers_changed): Non zero whenever the debug registers where changed and
	need to be written to inferior.
	(cygwin_set_dr, cygwin_set_dr7, cygwin_get_dr6): New functions used by i386-nat code.
	(thread_rec): Set dr array if id is the thread of current_event .
	(child_continue, child_resume): Change the debug registers for all threads 
	if debug_registers_changed.
	* config/i386/cygwin.mh: Add use of i386-nat.o file.
	Link nm.h to new nm-cygwin.h file.
	+ config/i386/nm-cygwin.h: New file.





Pierre Muller
Institut Charles Sadron
6,rue Boussingault
F 67083 STRASBOURG CEDEX (France)
mailto:muller@ics.u-strasbg.fr
Phone : (33)-3-88-41-40-07  Fax : (33)-3-88-41-40-99 
Index: win32-nat.c
===================================================================
RCS file: /cvs/src/src/gdb/win32-nat.c,v
retrieving revision 1.40
diff -r1.40 win32-nat.c
71c71,72
< #define CONTEXT_DEBUGGER_DR CONTEXT_DEBUGGER | CONTEXT_EXTENDED_REGISTERS
---
> #define CONTEXT_DEBUGGER_DR CONTEXT_DEBUGGER | CONTEXT_DEBUG_REGISTERS \
> 	| CONTEXT_EXTENDED_REGISTERS
73c74
< #define CONTEXT_DEBUGGER_DR CONTEXT_DEBUGGER
---
> #define CONTEXT_DEBUGGER_DR CONTEXT_DEBUGGER | CONTEXT_DEBUG_REGISTERS
75a77,79
> static unsigned dr[8];
> static int debug_registers_changed = 0;
> 
235a240,249
> 	    if (id == current_event.dwThreadId)
> 	      {
> 		/* Copy dr values from that thread.  */
> 		dr[0] = th->context.Dr0;
> 		dr[1] = th->context.Dr1;
> 		dr[2] = th->context.Dr2;
> 		dr[3] = th->context.Dr3;
> 		dr[6] = th->context.Dr6;
> 		dr[7] = th->context.Dr7;
> 	      }
877a892,904
> 	  if (debug_registers_changed)
>             {
>               /* Only change the value of the debug registers.  */
>               th->context.ContextFlags = CONTEXT_DEBUG_REGISTERS;
>               th->context.Dr0 = dr[0];
>               th->context.Dr1 = dr[1];
>               th->context.Dr2 = dr[2];
>               th->context.Dr3 = dr[3];
>               th->context.Dr6 = dr[6];
>               th->context.Dr7 = dr[7];
> 	      CHECK (SetThreadContext (th->h, &th->context));
>               th->context.ContextFlags = 0;
> 	    }
882a910
>   debug_registers_changed = 0;
1061a1090
>   int i;
1065a1095,1097
>   debug_registers_changed = 0;
>   for (i = 0; i <= 7; i++)
>     dr[i] = 0;
1344a1377
>   i386_cleanup_dregs();
1411a1445
> 
1431a1466,1474
> 	  if (debug_registers_changed)
> 	    {
> 	      th->context.Dr0 = dr[0];
> 	      th->context.Dr1 = dr[1];
> 	      th->context.Dr2 = dr[2];
> 	      th->context.Dr3 = dr[3];
> 	      th->context.Dr6 = dr[6];
> 	      th->context.Dr7 = dr[7];
> 	    }
1563a1607,1641
> 
> /* Hardware watchpoint support, adapted from go32-nat.c code.  */
> 
> /* Pass the address ADDR to the inferior in the I'th debug register.
>    Here we just store the address in dr array, the registers will be
>    actually set up when child_continue is called.  */
> void
> cygwin_set_dr (int i, CORE_ADDR addr)
> {
>   if (i < 0 || i > 3)
>     internal_error (__FILE__, __LINE__,
> 		    "Invalid register %d in cygwin_set_dr.\n", i);
>   dr[i] = (unsigned) addr;
>   debug_registers_changed = 1;
> }
> 
> /* Pass the value VAL to the inferior in the DR7 debug control
>    register.  Here we just store the address in D_REGS, the watchpoint
>    will be actually set up in child_wait.  */
> void
> cygwin_set_dr7 (unsigned val)
> {
>   dr[7] = val;
>   debug_registers_changed = 1;
> }
> 
> /* Get the value of the DR6 debug status register from the inferior.
>    Here we just return the value stored in D_REGS, as we've got it
>    from the last go32_wait call.  */
> unsigned
> cygwin_get_dr6 (void)
> {
>   return dr[6];
> }
> 
Index: config/i386/cygwin.mh
===================================================================
RCS file: /cvs/src/src/gdb/config/i386/cygwin.mh,v
retrieving revision 1.4
diff -r1.4 cygwin.mh
4,5c4,5
< NATDEPFILES= win32-nat.o corelow.o
< NAT_FILE=../none/nm-none.h
---
> NATDEPFILES= i386-nat.o win32-nat.o corelow.o
> NAT_FILE=nm-cygwin.h
/* Native definitions for Intel x86 running CYGWIN.
   Copyright (C) 2001 Free Software Foundation, Inc.

   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 2 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, write to the Free Software
   Foundation, Inc., 59 Temple Place - Suite 330,
   Boston, MA 02111-1307, USA.  */

#define NO_PTRACE_H

#define I386_USE_GENERIC_WATCHPOINTS

#include "i386/nm-i386.h"

/* Support for hardware-assisted breakpoints and watchpoints.  */

#define I386_DR_LOW_SET_CONTROL(VAL)	cygwin_set_dr7 (VAL)
extern void cygwin_set_dr7 (unsigned);

#define I386_DR_LOW_SET_ADDR(N,ADDR)	cygwin_set_dr (N,ADDR)
extern void cygwin_set_dr (int, CORE_ADDR);

#define I386_DR_LOW_RESET_ADDR(N)

#define I386_DR_LOW_GET_STATUS()	cygwin_get_dr6 ()
extern unsigned cygwin_get_dr6 (void);


Pierre Muller
Institut Charles Sadron
6,rue Boussingault
F 67083 STRASBOURG CEDEX (France)
mailto:muller@ics.u-strasbg.fr
Phone : (33)-3-88-41-40-07  Fax : (33)-3-88-41-40-99

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]