From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 32679 invoked by alias); 18 May 2009 23:28:11 -0000 Received: (qmail 32662 invoked by uid 22791); 18 May 2009 23:28:05 -0000 X-SWARE-Spam-Status: No, hits=1.0 required=5.0 tests=AWL,BAYES_05,HK_OBFDOM,HK_OBFDOMREQ,J_CHICKENPOX_12,J_CHICKENPOX_93,SARE_MSGID_LONG40,SPF_PASS X-Spam-Check-By: sourceware.org Received: from smtp-out.google.com (HELO smtp-out.google.com) (216.239.33.17) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Mon, 18 May 2009 23:27:56 +0000 Received: from spaceape9.eur.corp.google.com (spaceape9.eur.corp.google.com [172.28.16.143]) by smtp-out.google.com with ESMTP id n4INRqab009074 for ; Tue, 19 May 2009 00:27:52 +0100 Received: from pzk28 (pzk28.prod.google.com [10.243.19.156]) by spaceape9.eur.corp.google.com with ESMTP id n4INRogb001126 for ; Mon, 18 May 2009 16:27:50 -0700 Received: by pzk28 with SMTP id 28so2223071pzk.20 for ; Mon, 18 May 2009 16:27:49 -0700 (PDT) MIME-Version: 1.0 Received: by 10.142.230.11 with SMTP id c11mr2253525wfh.305.1242689269792; Mon, 18 May 2009 16:27:49 -0700 (PDT) In-Reply-To: References: <20090430071853.99F5584890@localhost> Date: Mon, 18 May 2009 23:28:00 -0000 Message-ID: Subject: Re: [RFA] i386/amd64 h/w watchpoints in gdbserver From: Doug Evans To: gdb-patches@sourceware.org, muller@ics.u-strasbg.fr Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable X-System-Of-Record: true X-IsSubscribed: yes Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org X-SW-Source: 2009-05/txt/msg00383.txt.bz2 Oh, btw, yes I know it needs updating 'cus i386/amd64 gdbserver is now biarch. :-) That part is mechanical. Is there anything that still needs discussing? On Mon, May 18, 2009 at 4:11 PM, Doug Evans wrote: > Ping. > > [for completeness sake, Pierre, I haven't forgotten about win32-i386-low.= c. :-)] > > What can I do so that we can make some progress here? > > On Thu, Apr 30, 2009 at 12:18 AM, Doug Evans wrote: >> Hi. >> >> I took Pierre's patch here >> http://sourceware.org/ml/gdb-patches/2009-02/msg00206.html >> >> and added support for {i386,amd64}-linux. >> Pierre, I _think_ I didn't break win32 support, but it is different >> than what you originally wrote. =A0Can you test it? >> >> This patch assumes the gdbserver memory leak fix has been applied: >> http://sourceware.org/ml/gdb-patches/2009-04/msg00803.html >> >> >> 2009-04-29 =A0Pierre Muller =A0 >> =A0 =A0 =A0 =A0 =A0 =A0Doug Evans =A0 >> >> =A0 =A0 =A0 =A0* Makefile.in (SFILES): Add i386-low.c >> =A0 =A0 =A0 =A0(i386_low_h): Define. >> =A0 =A0 =A0 =A0(i386-low.o): Add dependencies. >> =A0 =A0 =A0 =A0(linux-i386-low.o): Add i386-low.h dependency. >> =A0 =A0 =A0 =A0(linux-x86-64-low.o): Ditto. >> =A0 =A0 =A0 =A0(win32-i386-low.o): Ditto. >> =A0 =A0 =A0 =A0* i386-low.c: New file. >> =A0 =A0 =A0 =A0* i386-low.h: New file. >> =A0 =A0 =A0 =A0* configure.srv (i[34567]86-*-cygwin*): Add i386-low.o to= srv_tgtobj. >> =A0 =A0 =A0 =A0(i[34567]86-*-linux*, i[34567]86-*-mingw*, x86_64-*-linux= *): Ditto. >> =A0 =A0 =A0 =A0* linux-i386-low.c: Include stddef.h, i386-low.h. >> =A0 =A0 =A0 =A0(arch_process_info): New struct. >> =A0 =A0 =A0 =A0(i386_linux_dr_get, i386_linux_dr_set): New functions. >> =A0 =A0 =A0 =A0(i386_dr_low_set_addr, i386_dr_low_set_control): New func= tions. >> =A0 =A0 =A0 =A0(i386_dr_low_get_status): New function. >> =A0 =A0 =A0 =A0(i386_insert_watchpoint, i386_remove_watchpoint): New fun= ctions. >> =A0 =A0 =A0 =A0(i386_stopped_by_watchpoint, i386_stopped_data_address): = New functions. >> =A0 =A0 =A0 =A0(i386_linux_new_process, i386_linux_new_thread): New func= tions. >> =A0 =A0 =A0 =A0(the_low_target): Add entries for insert_watchpoint, remo= ve_watchpoint, >> =A0 =A0 =A0 =A0stopped_by_watchpoint, stopped_data_address, new_process,= new_thread. >> =A0 =A0 =A0 =A0* linux-low.c (linux_add_process): Initialize arch_privat= e. >> =A0 =A0 =A0 =A0(linux_remove_process): Free arch_private. >> =A0 =A0 =A0 =A0(notify_low_target_new_thread): New function. >> =A0 =A0 =A0 =A0(handle_extended_wait): Call it. >> =A0 =A0 =A0 =A0(linux_attach_lwp_1, linux_wait_1): Ditto. >> =A0 =A0 =A0 =A0(linux_insert_watchpoint): Update call to >> =A0 =A0 =A0 =A0the_low_target.insert_watchpoint. >> =A0 =A0 =A0 =A0(linux_remove_watchpoint): Update call to >> =A0 =A0 =A0 =A0the_low_target.remove_watchpoint. >> =A0 =A0 =A0 =A0(linux_stopped_by_watchpoint): Update call to >> =A0 =A0 =A0 =A0the_low_target.stopped_by_watchpoint. >> =A0 =A0 =A0 =A0(linux_stopped_data_address): Update call to >> =A0 =A0 =A0 =A0the_low_target.stopped_data_address. >> =A0 =A0 =A0 =A0* linux-low.h (process_info_private): New member arch_pri= vate. >> =A0 =A0 =A0 =A0(linux_target_ops): Add arch_private parameter to insert_= watchpoint, >> =A0 =A0 =A0 =A0remove_watchpoint, stopped_by_watchpoint, stopped_data_ad= dress. >> =A0 =A0 =A0 =A0New members new_process, new_thread. >> =A0 =A0 =A0 =A0(ptid_of, PIDGET, TIDGET): New macros. >> =A0 =A0 =A0 =A0* linux-x86-64-low.c: Include stddef.h, i386-low.h. >> =A0 =A0 =A0 =A0(arch_process_info): New struct. >> =A0 =A0 =A0 =A0(x86_64_linux_dr_get, x86_64_linux_dr_set): New functions. >> =A0 =A0 =A0 =A0(i386_dr_low_set_addr, i386_dr_low_set_control): New func= tions. >> =A0 =A0 =A0 =A0(i386_dr_low_get_status): New function. >> =A0 =A0 =A0 =A0(x86_64_insert_watchpoint, x86_64_remove_watchpoint): New= functions. >> =A0 =A0 =A0 =A0(x86_64_stopped_by_watchpoint): New function. >> =A0 =A0 =A0 =A0(x86_64_stopped_data_address): New function. >> =A0 =A0 =A0 =A0(x86_64_linux_new_process, x86_64_linux_new_thread): New = functions. >> =A0 =A0 =A0 =A0(the_low_target): Add entries for insert_watchpoint, remo= ve_watchpoint, >> =A0 =A0 =A0 =A0stopped_by_watchpoint, stopped_data_address, new_process,= new_thread. >> =A0 =A0 =A0 =A0* server.h (paddr): Declare. >> =A0 =A0 =A0 =A0* utils.c (NUMCELLS, CELLSIZE): New macros. >> =A0 =A0 =A0 =A0(get_sell, xsnprintf, paddr): New functions. >> =A0 =A0 =A0 =A0* win32-arm-low.c (the_low_target): Add entries for inser= t_watchpoint, >> =A0 =A0 =A0 =A0remove_watchpoint, stopped_by_watchpoint, stopped_data_ad= dress. >> =A0 =A0 =A0 =A0* win32-i386-low.c: Include i386-low.h. >> =A0 =A0 =A0 =A0(i386_dr_low_set_addr, i386_dr_low_set_control): New func= tions. >> =A0 =A0 =A0 =A0(i386_dr_low_get_status): New function. >> =A0 =A0 =A0 =A0(the_low_target): Add entries for insert_watchpoint, >> =A0 =A0 =A0 =A0remove_watchpoint, stopped_by_watchpoint, stopped_data_ad= dress. >> =A0 =A0 =A0 =A0* win32-low.c (win32_insert_watchpoint): New function. >> =A0 =A0 =A0 =A0(win32_remove_watchpoint): New function. >> =A0 =A0 =A0 =A0(win32_stopped_by_watchpoint): New function. >> =A0 =A0 =A0 =A0(win32_stopped_data_address): New function. >> =A0 =A0 =A0 =A0(win32_target_ops): Add entries for insert_watchpoint, >> =A0 =A0 =A0 =A0remove_watchpoint, stopped_by_watchpoint, stopped_data_ad= dress. >> =A0 =A0 =A0 =A0* win32-low.h (win32_target_ops): New members insert_watc= hpoint, >> =A0 =A0 =A0 =A0remove_watchpoint, stopped_by_watchpoint, stopped_data_ad= dress. >> >> Index: Makefile.in >> =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D >> RCS file: /cvs/src/src/gdb/gdbserver/Makefile.in,v >> retrieving revision 1.73 >> diff -u -p -r1.73 Makefile.in >> --- Makefile.in 1 Apr 2009 22:48:05 -0000 =A0 =A0 =A0 1.73 >> +++ Makefile.in 30 Apr 2009 01:23:29 -0000 >> @@ -104,7 +104,7 @@ SFILES=3D =A0 =A0 $(srcdir)/gdbreplay.c $(srcdir)/ >> =A0 =A0 =A0 =A0$(srcdir)/thread-db.c $(srcdir)/utils.c \ >> =A0 =A0 =A0 =A0$(srcdir)/linux-arm-low.c $(srcdir)/linux-cris-low.c \ >> =A0 =A0 =A0 =A0$(srcdir)/linux-crisv32-low.c $(srcdir)/linux-i386-low.c \ >> - =A0 =A0 =A0 $(srcdir)/i387-fp.c \ >> + =A0 =A0 =A0 ${srcdir}/i386-low.c $(srcdir)/i387-fp.c \ >> =A0 =A0 =A0 =A0$(srcdir)/linux-ia64-low.c $(srcdir)/linux-low.c \ >> =A0 =A0 =A0 =A0$(srcdir)/linux-m32r-low.c \ >> =A0 =A0 =A0 =A0$(srcdir)/linux-m68k-low.c $(srcdir)/linux-mips-low.c \ >> @@ -287,6 +287,10 @@ signals.o: ../common/signals.c $(server_ >> =A0memmem.o: ../gnulib/memmem.c >> =A0 =A0 =A0 =A0$(CC) -o memmem.o -c $(CPPFLAGS) $(INTERNAL_CFLAGS) $< >> >> +i386_low_h =3D $(srcdir)/i386-low.h >> + >> +i386-low.o: i386-low.c $(i386_low_h) $(server_h) $(target_h) >> + >> =A0i387-fp.o: i387-fp.c $(server_h) >> >> =A0linux-low.o: linux-low.c $(linux_low_h) $(server_h) >> @@ -297,7 +301,7 @@ linux-arm-low.o: linux-arm-low.c $(linux >> =A0linux-cris-low.o: linux-cris-low.c $(linux_low_h) $(server_h) >> =A0linux-crisv32-low.o: linux-crisv32-low.c $(linux_low_h) $(server_h) >> =A0linux-i386-low.o: linux-i386-low.c $(linux_low_h) $(server_h) \ >> - =A0 =A0 =A0 $(gdb_proc_service_h) >> + =A0 =A0 =A0 $(gdb_proc_service_h) $(i386_low_h) >> =A0linux-ia64-low.o: linux-ia64-low.c $(linux_low_h) $(server_h) >> =A0linux-m32r-low.o: linux-m32r-low.c $(linux_low_h) $(server_h) >> =A0linux-mips-low.o: linux-mips-low.c $(linux_low_h) $(server_h) \ >> @@ -306,7 +310,7 @@ linux-ppc-low.o: linux-ppc-low.c $(linux >> =A0linux-s390-low.o: linux-s390-low.c $(linux_low_h) $(server_h) >> =A0linux-sh-low.o: linux-sh-low.c $(linux_low_h) $(server_h) >> =A0linux-x86-64-low.o: linux-x86-64-low.c $(linux_low_h) $(server_h) \ >> - =A0 =A0 =A0 $(gdb_proc_service_h) >> + =A0 =A0 =A0 $(gdb_proc_service_h) $(i386_low_h) >> =A0linux-xtensa-low.o: linux-xtensa-low.c xtensa-xtregs.c $(linux_low_h)= $(server_h) >> >> =A0win32_low_h =3D $(srcdir)/win32-low.h >> @@ -314,7 +318,7 @@ win32_low_h =3D $(srcdir)/win32-low.h >> =A0win32-low.o: win32-low.c $(win32_low_h) $(server_h) $(regdef_h) $(reg= cache_h) >> >> =A0win32-arm-low.o: win32-arm-low.c $(win32_low_h) $(server_h) >> -win32-i386-low.o: win32-i386-low.c $(win32_low_h) $(server_h) >> +win32-i386-low.o: win32-i386-low.c $(win32_low_h) $(server_h) $(i386_lo= w_h) >> >> =A0spu-low.o: spu-low.c $(server_h) >> >> Index: configure.srv >> =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D >> RCS file: /cvs/src/src/gdb/gdbserver/configure.srv,v >> retrieving revision 1.40 >> diff -u -p -r1.40 configure.srv >> --- configure.srv =A0 =A0 =A0 19 Apr 2009 17:54:52 -0000 =A0 =A0 =A01.40 >> +++ configure.srv =A0 =A0 =A0 30 Apr 2009 01:23:29 -0000 >> @@ -53,10 +53,10 @@ case "${target}" in >> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0srv_linux_thread_db=3Dyes >> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0;; >> =A0 i[34567]86-*-cygwin*) =A0 =A0 =A0 =A0srv_regobj=3Dreg-i386.o >> - =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 srv_tgtobj=3D"win32-low.o = win32-i386-low.o" >> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 srv_tgtobj=3D"i386-low.o w= in32-low.o win32-i386-low.o" >> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0;; >> =A0 i[34567]86-*-linux*) srv_regobj=3Dreg-i386-linux.o >> - =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 srv_tgtobj=3D"linux-low.o = linux-i386-low.o i387-fp.o" >> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 srv_tgtobj=3D"linux-low.o = linux-i386-low.o i386-low.o i387-fp.o" >> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0srv_linux_usrregs=3Dyes >> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0srv_linux_regsets=3Dyes >> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0srv_linux_thread_db=3Dyes >> @@ -71,7 +71,7 @@ case "${target}" in >> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0srv_mingwce=3Dyes >> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0;; >> =A0 i[34567]86-*-mingw*) srv_regobj=3Dreg-i386.o >> - =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 srv_tgtobj=3D"win32-low.o = win32-i386-low.o" >> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 srv_tgtobj=3D"i386-low.o w= in32-low.o win32-i386-low.o" >> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0srv_mingw=3Dyes >> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0;; >> =A0 ia64-*-linux*) =A0 =A0 =A0 srv_regobj=3Dreg-ia64.o >> @@ -170,7 +170,7 @@ case "${target}" in >> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0srv_tgtobj=3D"spu-low.o" >> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0;; >> =A0 x86_64-*-linux*) =A0 =A0 srv_regobj=3Dreg-x86-64-linux.o >> - =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 srv_tgtobj=3D"linux-low.o = linux-x86-64-low.o i387-fp.o" >> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 srv_tgtobj=3D"linux-low.o = linux-x86-64-low.o i386-low.o i387-fp.o" >> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0srv_linux_regsets=3Dyes >> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0srv_linux_thread_db=3Dyes >> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0;; >> Index: i386-low.c >> =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D >> RCS file: i386-low.c >> diff -N i386-low.c >> --- /dev/null =A0 1 Jan 1970 00:00:00 -0000 >> +++ i386-low.c =A030 Apr 2009 01:23:29 -0000 >> @@ -0,0 +1,667 @@ >> +/* Debug register code for the i386. >> + >> + =A0 Copyright (C) 2009 >> + =A0 Free Software Foundation, Inc. >> + >> + =A0 This file is part of GDB. >> + >> + =A0 This program is free software; you can redistribute it and/or modi= fy >> + =A0 it under the terms of the GNU General Public License as published = by >> + =A0 the Free Software Foundation; either version 3 of the License, or >> + =A0 (at your option) any later version. >> + >> + =A0 This program is distributed in the hope that it will be useful, >> + =A0 but WITHOUT ANY WARRANTY; without even the implied warranty of >> + =A0 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. =A0See the >> + =A0 GNU General Public License for more details. >> + >> + =A0 You should have received a copy of the GNU General Public License >> + =A0 along with this program. =A0If not, see . =A0*/ >> + >> +#include "server.h" >> +#include "target.h" >> +#include "i386-low.h" >> + >> +/* Support for 8-byte wide hw watchpoints. =A0*/ >> +#ifndef TARGET_HAS_DR_LEN_8 >> +#define TARGET_HAS_DR_LEN_8 (sizeof (long) =3D=3D 8) >> +#endif >> + >> +enum target_hw_bp_type >> + =A0{ >> + =A0 =A0hw_write =A0 =3D 0, =A0 =A0/* Common =A0HW watchpoint */ >> + =A0 =A0hw_read =A0 =A0=3D 1, =A0 =A0/* Read =A0 =A0HW watchpoint */ >> + =A0 =A0hw_access =A0=3D 2, =A0 =A0/* Access =A0HW watchpoint */ >> + =A0 =A0hw_execute =3D 3 =A0 =A0 /* Execute HW breakpoint */ >> + =A0}; >> + >> +/* DR7 Debug Control register fields. =A0*/ >> + >> +/* How many bits to skip in DR7 to get to R/W and LEN fields. =A0*/ >> +#define DR_CONTROL_SHIFT =A0 =A0 =A0 16 >> +/* How many bits in DR7 per R/W and LEN field for each watchpoint. =A0*/ >> +#define DR_CONTROL_SIZE =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A04 >> + >> +/* Watchpoint/breakpoint read/write fields in DR7. =A0*/ >> +#define DR_RW_EXECUTE =A0(0x0) =A0 /* Break on instruction execution. = =A0*/ >> +#define DR_RW_WRITE =A0 =A0(0x1) =A0 /* Break on data writes. =A0*/ >> +#define DR_RW_READ =A0 =A0 (0x3) =A0 /* Break on data reads or writes. = =A0*/ >> + >> +/* This is here for completeness. =A0No platform supports this >> + =A0 functionality yet (as of March 2001). =A0Note that the DE flag in = the >> + =A0 CR4 register needs to be set to support this. =A0*/ >> +#ifndef DR_RW_IORW >> +#define DR_RW_IORW =A0 =A0 (0x2) =A0 /* Break on I/O reads or writes. = =A0*/ >> +#endif >> + >> +/* Watchpoint/breakpoint length fields in DR7. =A0The 2-bit left shift >> + =A0 is so we could OR this with the read/write field defined above. = =A0*/ >> +#define DR_LEN_1 =A0 =A0 =A0 (0x0 << 2) /* 1-byte region watch or break= point. =A0*/ >> +#define DR_LEN_2 =A0 =A0 =A0 (0x1 << 2) /* 2-byte region watch. =A0*/ >> +#define DR_LEN_4 =A0 =A0 =A0 (0x3 << 2) /* 4-byte region watch. =A0*/ >> +#define DR_LEN_8 =A0 =A0 =A0 (0x2 << 2) /* 8-byte region watch (AMD64).= =A0*/ >> + >> +/* Local and Global Enable flags in DR7. >> + >> + =A0 When the Local Enable flag is set, the breakpoint/watchpoint is >> + =A0 enabled only for the current task; the processor automatically >> + =A0 clears this flag on every task switch. =A0When the Global Enable f= lag >> + =A0 is set, the breakpoint/watchpoint is enabled for all tasks; the >> + =A0 processor never clears this flag. >> + >> + =A0 Currently, all watchpoint are locally enabled. =A0If you need to >> + =A0 enable them globally, read the comment which pertains to this in >> + =A0 i386_insert_aligned_watchpoint below. =A0*/ >> +#define DR_LOCAL_ENABLE_SHIFT =A00 /* Extra shift to the local enable b= it. =A0*/ >> +#define DR_GLOBAL_ENABLE_SHIFT 1 /* Extra shift to the global enable bi= t. =A0*/ >> +#define DR_ENABLE_SIZE =A0 =A0 =A0 =A0 2 /* Two enable bits per debug r= egister. =A0*/ >> + >> +/* Local and global exact breakpoint enable flags (a.k.a. slowdown >> + =A0 flags). =A0These are only required on i386, to allow detection of = the >> + =A0 exact instruction which caused a watchpoint to break; i486 and >> + =A0 later processors do that automatically. =A0We set these flags for >> + =A0 backwards compatibility. =A0*/ >> +#define DR_LOCAL_SLOWDOWN =A0 =A0 =A0(0x100) >> +#define DR_GLOBAL_SLOWDOWN =A0 =A0 =A0 =A0 =A0 =A0 (0x200) >> + >> +/* Fields reserved by Intel. =A0This includes the GD (General Detect >> + =A0 Enable) flag, which causes a debug exception to be generated when a >> + =A0 MOV instruction accesses one of the debug registers. >> + >> + =A0 FIXME: My Intel manual says we should use 0xF800, not 0xFC00. =A0*/ >> +#define DR_CONTROL_RESERVED =A0 =A0(0xFC00) >> + >> +/* Auxiliary helper macros. =A0*/ >> + >> +/* A value that masks all fields in DR7 that are reserved by Intel. =A0= */ >> +#define I386_DR_CONTROL_MASK =A0 (~DR_CONTROL_RESERVED) >> + >> +/* The I'th debug register is vacant if its Local and Global Enable >> + =A0 bits are reset in the Debug Control register. =A0*/ >> +#define I386_DR_VACANT(state, i) \ >> + =A0(((state)->dr_control_mirror & (3 << (DR_ENABLE_SIZE * (i)))) =3D= =3D 0) >> + >> +/* Locally enable the break/watchpoint in the I'th debug register. =A0*/ >> +#define I386_DR_LOCAL_ENABLE(state, i) \ >> + =A0do { \ >> + =A0 =A0(state)->dr_control_mirror |=3D \ >> + =A0 =A0 =A0(1 << (DR_LOCAL_ENABLE_SHIFT + DR_ENABLE_SIZE * (i))); \ >> + =A0} while (0) >> + >> +/* Globally enable the break/watchpoint in the I'th debug register. =A0= */ >> +#define I386_DR_GLOBAL_ENABLE(state, i) \ >> + =A0do { \ >> + =A0 =A0(state)->dr_control_mirror |=3D \ >> + =A0 =A0 =A0(1 << (DR_GLOBAL_ENABLE_SHIFT + DR_ENABLE_SIZE * (i))); \ >> + =A0} while (0) >> + >> +/* Disable the break/watchpoint in the I'th debug register. =A0*/ >> +#define I386_DR_DISABLE(state, i) \ >> + =A0do { \ >> + =A0 =A0(state)->dr_control_mirror &=3D \ >> + =A0 =A0 =A0~(3 << (DR_ENABLE_SIZE * (i))); \ >> + =A0} while (0) >> + >> +/* Set in DR7 the RW and LEN fields for the I'th debug register. =A0*/ >> +#define I386_DR_SET_RW_LEN(state, i,rwlen) \ >> + =A0do { \ >> + =A0 =A0(state)->dr_control_mirror &=3D \ >> + =A0 =A0 =A0~(0x0f << (DR_CONTROL_SHIFT+DR_CONTROL_SIZE*(i))); \ >> + =A0 =A0(state)->dr_control_mirror |=3D \ >> + =A0 =A0 =A0((rwlen) << (DR_CONTROL_SHIFT+DR_CONTROL_SIZE*(i))); \ >> + =A0} while (0) >> + >> +/* Get from DR7 the RW and LEN fields for the I'th debug register. =A0*/ >> +#define I386_DR_GET_RW_LEN(state, i) \ >> + =A0(((state)->dr_control_mirror >> (DR_CONTROL_SHIFT + DR_CONTROL_SIZE= * (i))) & 0x0f) >> + >> +/* Did the watchpoint whose address is in the I'th register break? =A0*/ >> +#define I386_DR_WATCH_HIT(state,i) ((state)->dr_status_mirror & (1 << (= i))) >> + >> +/* A macro to loop over all debug registers. =A0*/ >> +#define ALL_DEBUG_REGISTERS(i) for (i =3D 0; i < DR_NADDR; i++) >> + >> +/* Whether or not to print the mirrored debug registers. =A0*/ >> +static int maint_show_dr =3D 0; >> + >> +/* Types of operations supported by i386_handle_nonaligned_watchpoint. = =A0*/ >> +typedef enum { WP_INSERT, WP_REMOVE, WP_COUNT } i386_wp_op_t; >> + >> +/* Internal functions. =A0*/ >> + >> +/* Return the value of a 4-bit field for DR7 suitable for watching a >> + =A0 region of LEN bytes for accesses of type TYPE. =A0LEN is assumed to >> + =A0 have the value of 1, 2, or 4. =A0*/ >> +static unsigned i386_length_and_rw_bits (int len, enum target_hw_bp_typ= e type); >> + >> +/* Insert a watchpoint at address ADDR, which is assumed to be aligned >> + =A0 according to the length of the region to watch. =A0LEN_RW_BITS is = the >> + =A0 value of the bit-field from DR7 which describes the length and >> + =A0 access type of the region to be watched by this watchpoint. =A0Ret= urn >> + =A0 0 on success, -1 on failure. =A0*/ >> +static int i386_insert_aligned_watchpoint (struct i386_debug_reg_state = *state, >> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 = =A0 =A0 =A0 =A0CORE_ADDR addr, >> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 = =A0 =A0 =A0 =A0unsigned len_rw_bits); >> + >> +/* Remove a watchpoint at address ADDR, which is assumed to be aligned >> + =A0 according to the length of the region to watch. =A0LEN_RW_BITS is = the >> + =A0 value of the bits from DR7 which describes the length and access >> + =A0 type of the region watched by this watchpoint. =A0Return 0 on >> + =A0 success, -1 on failure. =A0*/ >> +static int i386_remove_aligned_watchpoint (struct i386_debug_reg_state = *state, >> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 = =A0 =A0 =A0 =A0CORE_ADDR addr, >> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 = =A0 =A0 =A0 =A0unsigned len_rw_bits); >> + >> +/* Insert or remove a (possibly non-aligned) watchpoint, or count the >> + =A0 number of debug registers required to watch a region at address >> + =A0 ADDR whose length is LEN for accesses of type TYPE. =A0Return 0 on >> + =A0 successful insertion or removal, a positive number when queried >> + =A0 about the number of registers, or -1 on failure. =A0If WHAT is not= a >> + =A0 valid value, bombs through internal_error. =A0*/ >> +static int i386_handle_nonaligned_watchpoint (struct i386_debug_reg_sta= te *state, >> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 = =A0 =A0 =A0 =A0 =A0 i386_wp_op_t what, >> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 = =A0 =A0 =A0 =A0 =A0 CORE_ADDR addr, int len, >> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 = =A0 =A0 =A0 =A0 =A0 enum target_hw_bp_type type); >> + >> +/* Implementation. =A0*/ >> + >> +/* Clear the reference counts and forget everything we knew about the >> + =A0 debug registers. =A0*/ >> + >> +void >> +i386_low_cleanup_dregs (struct i386_debug_reg_state *state) >> +{ >> + =A0int i; >> + >> + =A0ALL_DEBUG_REGISTERS(i) >> + =A0 =A0{ >> + =A0 =A0 =A0state->dr_mirror[i] =3D 0; >> + =A0 =A0 =A0state->dr_ref_count[i] =3D 0; >> + =A0 =A0} >> + =A0state->dr_control_mirror =3D 0; >> + =A0state->dr_status_mirror =A0=3D 0; >> +} >> + >> +/* Print the values of the mirrored debug registers. =A0This is called >> + =A0 when maint_show_dr is non-zero. =A0To set that up, type "maint >> + =A0 show-debug-regs" at GDB's prompt. =A0*/ >> + >> +static void >> +i386_show_dr (struct i386_debug_reg_state *state, >> + =A0 =A0 =A0 =A0 =A0 =A0 const char *func, CORE_ADDR addr, >> + =A0 =A0 =A0 =A0 =A0 =A0 int len, enum target_hw_bp_type type) >> +{ >> + =A0int i; >> + >> + =A0printf (func); >> + =A0if (addr || len) >> + =A0 =A0printf (" (addr=3D%lx, len=3D%d, type=3D%s)", >> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0(unsigned long) addr, len, >> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0type =3D=3D hw_write ? "dat= a-write" >> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0: (type =3D=3D hw_read ? "d= ata-read" >> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 : (type =3D=3D hw_acce= ss ? "data-read/write" >> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0: (type =3D=3D = hw_execute ? "instruction-execute" >> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 /* FIXME: = if/when I/O read/write >> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0wat= chpoints are supported, add them >> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0her= e. =A0*/ >> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 : "??unkno= wn??")))); >> + =A0printf (":\n"); >> + =A0printf ("\tCONTROL (DR7): %08x =A0 =A0 =A0 =A0 =A0STATUS (DR6): %08= x\n", >> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0state->dr_control_mirror, state= ->dr_status_mirror); >> + =A0ALL_DEBUG_REGISTERS (i) >> + =A0 =A0{ >> + =A0 =A0 =A0printf ("\ >> +\tDR%d: addr=3D0x%s, ref.count=3D%d =A0DR%d: addr=3D0x%s, ref.count=3D%= d\n", >> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0i, paddr (state->dr_mir= ror[i]), state->dr_ref_count[i], >> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0i+1, paddr (state->dr_m= irror[i+1]), state->dr_ref_count[i+1]); >> + =A0 =A0 =A0i++; >> + =A0 =A0} >> +} >> + >> +/* Return the value of a 4-bit field for DR7 suitable for watching a >> + =A0 region of LEN bytes for accesses of type TYPE. =A0LEN is assumed to >> + =A0 have the value of 1, 2, or 4. =A0*/ >> + >> +static unsigned >> +i386_length_and_rw_bits (int len, enum target_hw_bp_type type) >> +{ >> + =A0unsigned rw; >> + >> + =A0switch (type) >> + =A0 =A0{ >> + =A0 =A0 =A0case hw_execute: >> + =A0 =A0 =A0 rw =3D DR_RW_EXECUTE; >> + =A0 =A0 =A0 break; >> + =A0 =A0 =A0case hw_write: >> + =A0 =A0 =A0 rw =3D DR_RW_WRITE; >> + =A0 =A0 =A0 break; >> + =A0 =A0 =A0case hw_read: >> + =A0 =A0 =A0 /* The i386 doesn't support data-read watchpoints. =A0*/ >> + =A0 =A0 =A0case hw_access: >> + =A0 =A0 =A0 rw =3D DR_RW_READ; >> + =A0 =A0 =A0 break; >> +#if 0 >> + =A0 =A0 =A0 /* Not yet supported. =A0*/ >> + =A0 =A0 =A0case hw_io_access: >> + =A0 =A0 =A0 rw =3D DR_RW_IORW; >> + =A0 =A0 =A0 break; >> +#endif >> + =A0 =A0 =A0default: >> + =A0 =A0 =A0 error ("\ >> +Invalid hardware breakpoint type %d in i386_length_and_rw_bits.\n", >> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 (int) type); >> + =A0 =A0} >> + >> + =A0switch (len) >> + =A0 =A0{ >> + =A0 =A0 =A0case 1: >> + =A0 =A0 =A0 return (DR_LEN_1 | rw); >> + =A0 =A0 =A0case 2: >> + =A0 =A0 =A0 return (DR_LEN_2 | rw); >> + =A0 =A0 =A0case 4: >> + =A0 =A0 =A0 return (DR_LEN_4 | rw); >> + =A0 =A0 =A0case 8: >> + =A0 =A0 =A0 =A0if (TARGET_HAS_DR_LEN_8) >> + =A0 =A0 =A0 =A0 return (DR_LEN_8 | rw); >> + =A0 =A0 =A0default: >> + =A0 =A0 =A0 error ("\ >> +Invalid hardware breakpoint length %d in i386_length_and_rw_bits.\n", l= en); >> + =A0 =A0} >> +} >> + >> +/* Insert a watchpoint at address ADDR, which is assumed to be aligned >> + =A0 according to the length of the region to watch. =A0LEN_RW_BITS is = the >> + =A0 value of the bits from DR7 which describes the length and access >> + =A0 type of the region to be watched by this watchpoint. =A0Return 0 on >> + =A0 success, -1 on failure. =A0*/ >> + >> +static int >> +i386_insert_aligned_watchpoint (struct i386_debug_reg_state *state, >> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 CORE_ADDR = addr, unsigned len_rw_bits) >> +{ >> + =A0int i; >> + >> + =A0/* First, look for an occupied debug register with the same address >> + =A0 =A0 and the same RW and LEN definitions. =A0If we find one, we can >> + =A0 =A0 reuse it for this watchpoint as well (and save a register). = =A0*/ >> + =A0ALL_DEBUG_REGISTERS(i) >> + =A0 =A0{ >> + =A0 =A0 =A0if (!I386_DR_VACANT (state, i) >> + =A0 =A0 =A0 =A0 && state->dr_mirror[i] =3D=3D addr >> + =A0 =A0 =A0 =A0 && I386_DR_GET_RW_LEN (state, i) =3D=3D len_rw_bits) >> + =A0 =A0 =A0 { >> + =A0 =A0 =A0 =A0 state->dr_ref_count[i]++; >> + =A0 =A0 =A0 =A0 return 0; >> + =A0 =A0 =A0 } >> + =A0 =A0} >> + >> + =A0/* Next, look for a vacant debug register. =A0*/ >> + =A0ALL_DEBUG_REGISTERS(i) >> + =A0 =A0{ >> + =A0 =A0 =A0if (I386_DR_VACANT (state, i)) >> + =A0 =A0 =A0 break; >> + =A0 =A0} >> + >> + =A0/* No more debug registers! =A0*/ >> + =A0if (i >=3D DR_NADDR) >> + =A0 =A0return -1; >> + >> + =A0/* Now set up the register I to watch our region. =A0*/ >> + >> + =A0/* Record the info in our local mirrored array. =A0*/ >> + =A0state->dr_mirror[i] =3D addr; >> + =A0state->dr_ref_count[i] =3D 1; >> + =A0I386_DR_SET_RW_LEN (state, i, len_rw_bits); >> + =A0/* Note: we only enable the watchpoint locally, i.e. in the current >> + =A0 =A0 task. =A0Currently, no i386 target allows or supports global >> + =A0 =A0 watchpoints; however, if any target would want that in the >> + =A0 =A0 future, GDB should probably provide a command to control wheth= er >> + =A0 =A0 to enable watchpoints globally or locally, and the code below >> + =A0 =A0 should use global or local enable and slow-down flags as >> + =A0 =A0 appropriate. =A0*/ >> + =A0I386_DR_LOCAL_ENABLE (state, i); >> + =A0state->dr_control_mirror |=3D DR_LOCAL_SLOWDOWN; >> + =A0state->dr_control_mirror &=3D I386_DR_CONTROL_MASK; >> + >> + =A0/* Finally, actually pass the info to the inferior. =A0*/ >> + =A0i386_dr_low_set_addr (i, addr); >> + =A0i386_dr_low_set_control (state->dr_control_mirror); >> + >> + =A0return 0; >> +} >> + >> +/* Reset a watched address for debug reg DR. >> + =A0 All implementations just do foo_set_addr (addr, 0), so this is a w= rapper >> + =A0 around foo_set_addr to maintain the concept that this is a reset. = =A0*/ >> + >> +static void >> +i386_dr_low_reset_addr (int dr) >> +{ >> + =A0i386_dr_low_set_addr (dr, 0); >> +} >> + >> +/* Remove a watchpoint at address ADDR, which is assumed to be aligned >> + =A0 according to the length of the region to watch. =A0LEN_RW_BITS is = the >> + =A0 value of the bits from DR7 which describes the length and access >> + =A0 type of the region watched by this watchpoint. =A0Return 0 on >> + =A0 success, -1 on failure. =A0*/ >> + >> +static int >> +i386_remove_aligned_watchpoint (struct i386_debug_reg_state *state, >> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 CORE_ADDR = addr, unsigned len_rw_bits) >> +{ >> + =A0int i, retval =3D -1; >> + >> + =A0ALL_DEBUG_REGISTERS(i) >> + =A0 =A0{ >> + =A0 =A0 =A0if (!I386_DR_VACANT (state, i) >> + =A0 =A0 =A0 =A0 && state->dr_mirror[i] =3D=3D addr >> + =A0 =A0 =A0 =A0 && I386_DR_GET_RW_LEN (state, i) =3D=3D len_rw_bits) >> + =A0 =A0 =A0 { >> + =A0 =A0 =A0 =A0 if (--state->dr_ref_count[i] =3D=3D 0) /* no longer in= use? */ >> + =A0 =A0 =A0 =A0 =A0 { >> + =A0 =A0 =A0 =A0 =A0 =A0 /* Reset our mirror. =A0*/ >> + =A0 =A0 =A0 =A0 =A0 =A0 state->dr_mirror[i] =3D 0; >> + =A0 =A0 =A0 =A0 =A0 =A0 I386_DR_DISABLE (state, i); >> + =A0 =A0 =A0 =A0 =A0 =A0 /* Reset it in the inferior. =A0*/ >> + =A0 =A0 =A0 =A0 =A0 =A0 i386_dr_low_set_control (state->dr_control_mir= ror); >> + =A0 =A0 =A0 =A0 =A0 =A0 i386_dr_low_reset_addr (i); >> + =A0 =A0 =A0 =A0 =A0 } >> + =A0 =A0 =A0 =A0 retval =3D 0; >> + =A0 =A0 =A0 } >> + =A0 =A0} >> + >> + =A0return retval; >> +} >> + >> +/* Insert or remove a (possibly non-aligned) watchpoint, or count the >> + =A0 number of debug registers required to watch a region at address >> + =A0 ADDR whose length is LEN for accesses of type TYPE. =A0Return 0 on >> + =A0 successful insertion or removal, a positive number when queried >> + =A0 about the number of registers, or -1 on failure. =A0If WHAT is not= a >> + =A0 valid value, bombs through internal_error. =A0*/ >> + >> +static int >> +i386_handle_nonaligned_watchpoint (struct i386_debug_reg_state *state, >> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0i38= 6_wp_op_t what, CORE_ADDR addr, int len, >> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0enu= m target_hw_bp_type type) >> +{ >> + =A0int retval =3D 0, status =3D 0; >> + =A0int max_wp_len =3D TARGET_HAS_DR_LEN_8 ? 8 : 4; >> + >> + =A0static int size_try_array[8][8] =3D >> + =A0{ >> + =A0 =A0{1, 1, 1, 1, 1, 1, 1, 1}, =A0/* Trying size one. =A0*/ >> + =A0 =A0{2, 1, 2, 1, 2, 1, 2, 1}, =A0/* Trying size two. =A0*/ >> + =A0 =A0{2, 1, 2, 1, 2, 1, 2, 1}, =A0/* Trying size three. =A0*/ >> + =A0 =A0{4, 1, 2, 1, 4, 1, 2, 1}, =A0/* Trying size four. =A0*/ >> + =A0 =A0{4, 1, 2, 1, 4, 1, 2, 1}, =A0/* Trying size five. =A0*/ >> + =A0 =A0{4, 1, 2, 1, 4, 1, 2, 1}, =A0/* Trying size six. =A0*/ >> + =A0 =A0{4, 1, 2, 1, 4, 1, 2, 1}, =A0/* Trying size seven. =A0*/ >> + =A0 =A0{8, 1, 2, 1, 4, 1, 2, 1}, =A0/* Trying size eight. =A0*/ >> + =A0}; >> + >> + =A0while (len > 0) >> + =A0 =A0{ >> + =A0 =A0 =A0int align =3D addr % max_wp_len; >> + =A0 =A0 =A0/* Four (eight on AMD64) is the maximum length a debug regi= ster >> + =A0 =A0 =A0 =A0can watch. =A0*/ >> + =A0 =A0 =A0int try =3D (len > max_wp_len ? (max_wp_len - 1) : len - 1); >> + =A0 =A0 =A0int size =3D size_try_array[try][align]; >> + >> + =A0 =A0 =A0if (what =3D=3D WP_COUNT) >> + =A0 =A0 =A0 { >> + =A0 =A0 =A0 =A0 /* size_try_array[] is defined such that each iteration >> + =A0 =A0 =A0 =A0 =A0 =A0through the loop is guaranteed to produce an ad= dress and a >> + =A0 =A0 =A0 =A0 =A0 =A0size that can be watched with a single debug re= gister. >> + =A0 =A0 =A0 =A0 =A0 =A0Thus, for counting the registers required to wa= tch a >> + =A0 =A0 =A0 =A0 =A0 =A0region, we simply need to increment the count o= n each >> + =A0 =A0 =A0 =A0 =A0 =A0iteration. =A0*/ >> + =A0 =A0 =A0 =A0 retval++; >> + =A0 =A0 =A0 } >> + =A0 =A0 =A0else >> + =A0 =A0 =A0 { >> + =A0 =A0 =A0 =A0 unsigned len_rw =3D i386_length_and_rw_bits (size, typ= e); >> + >> + =A0 =A0 =A0 =A0 if (what =3D=3D WP_INSERT) >> + =A0 =A0 =A0 =A0 =A0 status =3D i386_insert_aligned_watchpoint (state, = addr, len_rw); >> + =A0 =A0 =A0 =A0 else if (what =3D=3D WP_REMOVE) >> + =A0 =A0 =A0 =A0 =A0 status =3D i386_remove_aligned_watchpoint (state, = addr, len_rw); >> +#if 0 >> + =A0 =A0 =A0 =A0 else >> + =A0 =A0 =A0 =A0 =A0 internal_error (__FILE__, __LINE__, _("\ >> +Invalid value %d of operation in i386_handle_nonaligned_watchpoint.\n"), >> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 (int)what); >> +#endif >> + =A0 =A0 =A0 =A0 /* We keep the loop going even after a failure, becaus= e some >> + =A0 =A0 =A0 =A0 =A0 =A0of the other aligned watchpoints might still su= cceed >> + =A0 =A0 =A0 =A0 =A0 =A0(e.g. if they watch addresses that are already = watched, >> + =A0 =A0 =A0 =A0 =A0 =A0in which case we just increment the reference c= ounts of >> + =A0 =A0 =A0 =A0 =A0 =A0occupied debug registers). =A0If we break out o= f the loop >> + =A0 =A0 =A0 =A0 =A0 =A0too early, we could cause those addresses watch= ed by >> + =A0 =A0 =A0 =A0 =A0 =A0other watchpoints to be disabled when breakpoin= t.c reacts >> + =A0 =A0 =A0 =A0 =A0 =A0to our failure to insert this watchpoint and tr= ies to >> + =A0 =A0 =A0 =A0 =A0 =A0remove it. =A0*/ >> + =A0 =A0 =A0 =A0 if (status) >> + =A0 =A0 =A0 =A0 =A0 retval =3D status; >> + =A0 =A0 =A0 } >> + >> + =A0 =A0 =A0addr +=3D size; >> + =A0 =A0 =A0len -=3D size; >> + =A0 =A0} >> + >> + =A0return retval; >> +} >> + >> +#define Z_PACKET_WRITE_WP '2' >> +#define Z_PACKET_READ_WP '3' >> +#define Z_PACKET_ACCESS_WP '4' >> + >> +static int >> +Z_packet_to_hw_type (char type) >> +{ >> + =A0switch (type) >> + =A0 =A0{ >> + =A0 =A0case Z_PACKET_WRITE_WP: =A0return hw_write; >> + =A0 =A0case Z_PACKET_READ_WP: =A0 return hw_read; >> + =A0 =A0case Z_PACKET_ACCESS_WP: return hw_access; >> + =A0 =A0default: >> + =A0 =A0 =A0error ("Z_packet_to_hw_type: bad watchpoint type %c", type); >> + =A0 =A0} >> +} >> + >> +/* Insert a watchpoint to watch a memory region which starts at >> + =A0 address ADDR and whose length is LEN bytes. =A0Watch memory access= es >> + =A0 of the type TYPE_FROM_PACKET. =A0Return 0 on success, -1 on failur= e. =A0*/ >> + >> +int >> +i386_low_insert_watchpoint (struct i386_debug_reg_state *state, >> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 char type_from_pac= ket, CORE_ADDR addr, int len) >> +{ >> + =A0int retval; >> + =A0int type =3D Z_packet_to_hw_type (type_from_packet); >> + >> + =A0if (((len !=3D 1 && len !=3D2 && len !=3D4) && !(TARGET_HAS_DR_LEN_= 8 && len =3D=3D 8)) >> + =A0 =A0 =A0|| addr % len !=3D 0) >> + =A0 =A0{ >> + =A0 =A0 =A0retval =3D i386_handle_nonaligned_watchpoint (state, WP_INS= ERT, >> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 = =A0 =A0 =A0 =A0 =A0 =A0 =A0 addr, len, type); >> + =A0 =A0} >> + =A0else >> + =A0 =A0{ >> + =A0 =A0 =A0unsigned len_rw =3D i386_length_and_rw_bits (len, type); >> + >> + =A0 =A0 =A0retval =3D i386_insert_aligned_watchpoint (state, addr, len= _rw); >> + =A0 =A0} >> + >> + =A0if (maint_show_dr) >> + =A0 =A0i386_show_dr (state, "insert_watchpoint", addr, len, type); >> + >> + =A0return retval; >> +} >> + >> +/* Remove a watchpoint that watched the memory region which starts at >> + =A0 address ADDR, whose length is LEN bytes, and for accesses of the >> + =A0 type TYPE_FROM_PACKET. =A0Return 0 on success, -1 on failure. =A0*/ >> + >> +int >> +i386_low_remove_watchpoint (struct i386_debug_reg_state *state, >> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 char type_from_pac= ket, CORE_ADDR addr, int len) >> +{ >> + =A0int retval; >> + =A0int type =3D Z_packet_to_hw_type (type_from_packet); >> + >> + =A0if (((len !=3D 1 && len !=3D2 && len !=3D4) && !(TARGET_HAS_DR_LEN_= 8 && len =3D=3D 8)) >> + =A0 =A0 =A0|| addr % len !=3D 0) >> + =A0 =A0{ >> + =A0 =A0 =A0retval =3D i386_handle_nonaligned_watchpoint (state, WP_REM= OVE, >> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 = =A0 =A0 =A0 =A0 =A0 =A0 =A0 addr, len, type); >> + =A0 =A0} >> + =A0else >> + =A0 =A0{ >> + =A0 =A0 =A0unsigned len_rw =3D i386_length_and_rw_bits (len, type); >> + >> + =A0 =A0 =A0retval =3D i386_remove_aligned_watchpoint (state, addr, len= _rw); >> + =A0 =A0} >> + =A0if (maint_show_dr) >> + =A0 =A0i386_show_dr (state, "remove_watchpoint", addr, len, type); >> + =A0return retval; >> +} >> + >> +/* Return non-zero if we can watch a memory region that starts at >> + =A0 address ADDR and whose length is LEN bytes. =A0*/ >> + >> +int >> +i386_low_region_ok_for_watchpoint (struct i386_debug_reg_state *state, >> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0COR= E_ADDR addr, int len) >> +{ >> + =A0int nregs; >> + >> + =A0/* Compute how many aligned watchpoints we would need to cover this >> + =A0 =A0 region. =A0*/ >> + =A0nregs =3D i386_handle_nonaligned_watchpoint (state, WP_COUNT, >> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 = =A0 =A0 =A0 =A0 =A0addr, len, hw_write); >> + =A0return nregs <=3D DR_NADDR ? 1 : 0; >> +} >> + >> +/* If the inferior has some watchpoint that triggered, set the >> + =A0 address associated with that watchpoint and return non-zero. >> + =A0 Otherwise, return zero. =A0*/ >> + >> +CORE_ADDR >> +i386_low_stopped_data_address (struct i386_debug_reg_state *state) >> +{ >> + =A0CORE_ADDR addr =3D 0; >> + =A0int i; >> + =A0int rc =3D 0; >> + >> + =A0state->dr_status_mirror =3D i386_dr_low_get_status (); >> + >> + =A0ALL_DEBUG_REGISTERS(i) >> + =A0 =A0{ >> + =A0 =A0 =A0if (I386_DR_WATCH_HIT (state, i) >> + =A0 =A0 =A0 =A0 /* This second condition makes sure DRi is set up for = a data >> + =A0 =A0 =A0 =A0 =A0 =A0watchpoint, not a hardware breakpoint. =A0The r= eason is >> + =A0 =A0 =A0 =A0 =A0 =A0that GDB doesn't call the target_stopped_data_a= ddress >> + =A0 =A0 =A0 =A0 =A0 =A0method except for data watchpoints. =A0In other= words, I'm >> + =A0 =A0 =A0 =A0 =A0 =A0being paranoiac. =A0*/ >> + =A0 =A0 =A0 =A0 && I386_DR_GET_RW_LEN (state, i) !=3D 0) >> + =A0 =A0 =A0 { >> + =A0 =A0 =A0 =A0 addr =3D state->dr_mirror[i]; >> + =A0 =A0 =A0 =A0 rc =3D 1; >> + =A0 =A0 =A0 =A0 if (maint_show_dr) >> + =A0 =A0 =A0 =A0 =A0 i386_show_dr (state, "watchpoint_hit", addr, -1, h= w_write); >> + =A0 =A0 =A0 } >> + =A0 =A0} >> + =A0if (maint_show_dr && addr =3D=3D 0) >> + =A0 =A0i386_show_dr (state, "stopped_data_addr", 0, 0, hw_write); >> + >> + =A0/* NOTE: gdb version checks rc !=3D 0 here. =A0*/ >> + =A0return addr; >> +} >> + >> +int >> +i386_low_stopped_by_watchpoint (struct i386_debug_reg_state *state) >> +{ >> + =A0CORE_ADDR addr =3D 0; >> + =A0/* NOTE: gdb version passes boolean found/not-found result from >> + =A0 =A0 i386_stopped_data_address. =A0*/ >> + =A0addr =3D i386_low_stopped_data_address (state); >> + =A0return (addr !=3D 0); >> +} >> + >> +/* Support for h/w breakpoints. >> + =A0 This support is not currently used, kept for reference. =A0*/ >> + >> +/* Return non-zero if the inferior has some break/watchpoint that >> + =A0 triggered. =A0*/ >> + >> +int >> +i386_low_stopped_by_hwbp (struct i386_debug_reg_state *state) >> +{ >> + =A0int i; >> + >> + =A0state->dr_status_mirror =3D i386_dr_low_get_status (); >> + =A0if (maint_show_dr) >> + =A0 =A0i386_show_dr (state, "stopped_by_hwbp", 0, 0, hw_execute); >> + >> + =A0ALL_DEBUG_REGISTERS(i) >> + =A0 =A0{ >> + =A0 =A0 =A0if (I386_DR_WATCH_HIT (state, i)) >> + =A0 =A0 =A0 return 1; >> + =A0 =A0} >> + >> + =A0return 0; >> +} >> + >> +/* Insert a hardware-assisted breakpoint at ADDR. >> + =A0 Return 0 on success, -1 on failure. =A0*/ >> + >> +int >> +i386_low_insert_hw_breakpoint (struct i386_debug_reg_state *state, >> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0CORE_ADDR a= ddr) >> +{ >> + =A0unsigned len_rw =3D i386_length_and_rw_bits (1, hw_execute); >> + =A0int retval =3D i386_insert_aligned_watchpoint (state, addr, len_rw); >> + >> + =A0if (maint_show_dr) >> + =A0 =A0i386_show_dr (state, "insert_hwbp", addr, 1, hw_execute); >> + >> + =A0return retval; >> +} >> + >> +/* Remove a hardware-assisted breakpoint at ADDR. >> + =A0 Return 0 on success, -1 on failure. =A0*/ >> + >> +int >> +i386_low_remove_hw_breakpoint (struct i386_debug_reg_state *state, >> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0CORE_ADDR a= ddr) >> +{ >> + =A0unsigned len_rw =3D i386_length_and_rw_bits (1, hw_execute); >> + =A0int retval =3D i386_remove_aligned_watchpoint (state, addr, len_rw); >> + >> + =A0if (maint_show_dr) >> + =A0 =A0i386_show_dr (state, "remove_hwbp", addr, 1, hw_execute); >> + >> + =A0return retval; >> +} >> Index: i386-low.h >> =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D >> RCS file: i386-low.h >> diff -N i386-low.h >> --- /dev/null =A0 1 Jan 1970 00:00:00 -0000 >> +++ i386-low.h =A030 Apr 2009 01:23:29 -0000 >> @@ -0,0 +1,118 @@ >> +/* Misc. low level support for i386. >> + >> + =A0 Copyright (C) 2009 >> + =A0 Free Software Foundation, Inc. >> + >> + =A0 This file is part of GDB. >> + >> + =A0 This program is free software; you can redistribute it and/or modi= fy >> + =A0 it under the terms of the GNU General Public License as published = by >> + =A0 the Free Software Foundation; either version 3 of the License, or >> + =A0 (at your option) any later version. >> + >> + =A0 This program is distributed in the hope that it will be useful, >> + =A0 but WITHOUT ANY WARRANTY; without even the implied warranty of >> + =A0 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. =A0See the >> + =A0 GNU General Public License for more details. >> + >> + =A0 You should have received a copy of the GNU General Public License >> + =A0 along with this program. =A0If not, see . =A0*/ >> + >> +/* Support for hardware watchpoints and breakpoints using the i386 >> + =A0 debug registers. >> + >> + =A0 This provides several functions for inserting and removing >> + =A0 hardware-assisted breakpoints and watchpoints, testing if one or >> + =A0 more of the watchpoints triggered and at what address, checking >> + =A0 whether a given region can be watched, etc. >> + >> + =A0 The functions below implement debug registers sharing by reference >> + =A0 counts, and allow to watch regions up to 16 bytes long >> + =A0 (32 bytes on 64 bit hosts). =A0*/ >> + >> + >> +/* Debug registers' indices. =A0*/ >> +#define DR_FIRSTADDR 0 >> +#define DR_LASTADDR =A03 >> +#define DR_NADDR =A0 =A0 4 /* The number of debug address registers. = =A0*/ >> +#define DR_STATUS =A0 =A06 >> +#define DR_CONTROL =A0 7 >> + >> +/* Global state needed to track h/w watchpoints. =A0*/ >> + >> +struct i386_debug_reg_state >> +{ >> + =A0/* Mirror the inferior's DRi registers. =A0We keep the status and >> + =A0 =A0 control registers separated because they don't hold addresses.= =A0*/ >> + =A0CORE_ADDR dr_mirror[DR_NADDR]; >> + =A0unsigned dr_status_mirror, dr_control_mirror; >> + >> + =A0/* Reference counts for each debug register. =A0*/ >> + =A0int dr_ref_count[DR_NADDR]; >> +}; >> + >> +/* Clear the reference counts and forget everything we knew about DRi. = =A0*/ >> +extern void i386_low_cleanup_dregs (struct i386_debug_reg_state *state); >> + >> +/* Insert a watchpoint to watch a memory region which starts at >> + =A0 address ADDR and whose length is LEN bytes. =A0Watch memory access= es >> + =A0 of the type TYPE_FROM_PACKET. =A0Return 0 on success, -1 on failur= e. =A0*/ >> +extern int i386_low_insert_watchpoint (struct i386_debug_reg_state *sta= te, >> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 = =A0 =A0char type_from_packet, CORE_ADDR addr, >> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 = =A0 =A0int len); >> + >> +/* Remove a watchpoint that watched the memory region which starts at >> + =A0 address ADDR, whose length is LEN bytes, and for accesses of the >> + =A0 type TYPE_FROM_PACKET. =A0Return 0 on success, -1 on failure. =A0*/ >> +extern int i386_low_remove_watchpoint (struct i386_debug_reg_state *sta= te, >> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 = =A0 =A0char type_from_packet, CORE_ADDR addr, >> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 = =A0 =A0int len); >> + >> +/* Return non-zero if we can watch a memory region that starts at >> + =A0 address ADDR and whose length is LEN bytes. =A0*/ >> +extern int i386_low_region_ok_for_watchpoint (struct i386_debug_reg_sta= te *state, >> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 = =A0 =A0 =A0 =A0 =A0 CORE_ADDR addr, int len); >> + >> +/* If the inferior has some break/watchpoint that triggered, set >> + =A0 the address associated with that break/watchpoint and return >> + =A0 true. =A0Otherwise, return false. =A0*/ >> +extern CORE_ADDR i386_low_stopped_data_address (struct i386_debug_reg_s= tate *state); >> + >> +extern int i386_low_stopped_by_watchpoint (struct i386_debug_reg_state = *state); >> + >> +/* Return non-zero if the inferior has some break/watchpoint that >> + =A0 triggered. =A0*/ >> +extern int i386_low_stopped_by_hwbp (struct i386_debug_reg_state *state= ); >> + >> +/* Insert a hardware-assisted breakpoint at ADDR. >> + =A0 Return 0 on success, -1 on failure. =A0*/ >> +extern int i386_low_insert_hw_breakpoint (struct i386_debug_reg_state *= state, >> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 = =A0 =A0 =A0 CORE_ADDR addr); >> + >> +/* Remove a hardware-assisted breakpoint at ADDR. >> + =A0 Return 0 on success, -1 on failure. =A0*/ >> +extern int i386_low_remove_hw_breakpoint (struct i386_debug_reg_state *= state, >> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 = =A0 =A0 =A0 CORE_ADDR addr); >> + >> +/* Each target needs to provide several low-level functions >> + =A0 that will be called to insert watchpoints and hardware breakpoints >> + =A0 into the inferior, remove them, and check their status. =A0These >> + =A0 functions are: >> + >> + =A0 =A0 =A0i386_dr_low_set_control =A0-- set the debug control (DR7) >> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 regist= er to a given value >> + >> + =A0 =A0 =A0i386_dr_low_set_addr =A0 =A0 -- put an address into one deb= ug register >> + >> + =A0 =A0 =A0i386_dr_low_get_status =A0 -- return the value of the debug >> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 status= (DR6) register. >> +*/ >> + >> +/* Pass the address ADDR to the inferior in the I'th debug register. = =A0*/ >> +extern void i386_dr_low_set_addr (int i, CORE_ADDR addr); >> + >> +/* Pass the value VAL to the inferior in the DR7 debug control register= . =A0*/ >> +extern void i386_dr_low_set_control (unsigned val); >> + >> +/* Get the value of the DR6 debug status register from the inferior. = =A0*/ >> +extern unsigned i386_dr_low_get_status (void); >> Index: linux-i386-low.c >> =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D >> RCS file: /cvs/src/src/gdb/gdbserver/linux-i386-low.c,v >> retrieving revision 1.19 >> diff -u -p -r1.19 linux-i386-low.c >> --- linux-i386-low.c =A0 =A022 Mar 2009 23:57:10 -0000 =A0 =A0 =A01.19 >> +++ linux-i386-low.c =A0 =A030 Apr 2009 01:23:29 -0000 >> @@ -17,9 +17,11 @@ >> =A0 =A0You should have received a copy of the GNU General Public License >> =A0 =A0along with this program. =A0If not, see . =A0*/ >> >> +#include >> =A0#include "server.h" >> =A0#include "linux-low.h" >> =A0#include "i387-fp.h" >> +#include "i386-low.h" >> >> =A0#include "gdb_proc_service.h" >> >> @@ -33,10 +35,14 @@ >> =A0#define PTRACE_GET_THREAD_AREA 25 >> =A0#endif >> >> +struct arch_process_info >> +{ >> + =A0struct i386_debug_reg_state debug_reg_state; >> +}; >> + >> =A0/* Defined in auto-generated file reg-i386-linux.c. =A0*/ >> =A0void init_registers_i386_linux (void); >> >> - >> =A0/* This module only supports access to the general purpose registers.= =A0*/ >> >> =A0#define i386_num_regs 16 >> @@ -187,6 +193,148 @@ i386_breakpoint_at (CORE_ADDR pc) >> >> =A0 return 0; >> =A0} >> + >> +/* Support for debug registers. =A0*/ >> + >> +static unsigned long >> +i386_linux_dr_get (ptid_t ptid, int regnum) >> +{ >> + =A0int tid; >> + =A0unsigned long value; >> + >> + =A0tid =3D TIDGET (ptid); >> + =A0if (tid =3D=3D 0) >> + =A0 =A0tid =3D PIDGET (ptid); >> + >> + =A0errno =3D 0; >> + =A0value =3D ptrace (PTRACE_PEEKUSER, tid, >> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 offsetof (struct user, u_debugreg[regn= um]), 0); >> + =A0if (errno !=3D 0) >> + =A0 =A0error ("Couldn't read debug register"); >> + >> + =A0return value; >> +} >> + >> +static void >> +i386_linux_dr_set (ptid_t ptid, int regnum, unsigned long value) >> +{ >> + =A0int tid; >> + >> + =A0tid =3D TIDGET (ptid); >> + =A0if (tid =3D=3D 0) >> + =A0 =A0tid =3D PIDGET (ptid); >> + >> + =A0errno =3D 0; >> + =A0ptrace (PTRACE_POKEUSER, tid, >> + =A0 =A0 =A0 =A0 offsetof (struct user, u_debugreg[regnum]), value); >> + =A0if (errno !=3D 0) >> + =A0 =A0error ("Couldn't write debug register"); >> +} >> + >> +/* Pass the address ADDR to the inferior in debug register REGNUM. =A0*/ >> + >> +void >> +i386_dr_low_set_addr (int regnum, CORE_ADDR addr) >> +{ >> + =A0struct inferior_list_entry *lp; >> + >> + =A0if (! (regnum >=3D 0 && regnum <=3D DR_LASTADDR - DR_FIRSTADDR)) >> + =A0 =A0error ("Invalid debug register"); >> + >> + =A0for (lp =3D all_lwps.head; lp; lp =3D lp->next) >> + =A0 =A0{ >> + =A0 =A0 =A0struct lwp_info *lwp =3D (struct lwp_info *) lp; >> + =A0 =A0 =A0i386_linux_dr_set (ptid_of (lwp), DR_FIRSTADDR + regnum, ad= dr); >> + =A0 =A0} >> +} >> + >> +/* Pass the value VAL to the inferior in the DR7 debug control register= . =A0*/ >> + >> +void >> +i386_dr_low_set_control (unsigned control) >> +{ >> + =A0struct inferior_list_entry *lp; >> + >> + =A0for (lp =3D all_lwps.head; lp; lp =3D lp->next) >> + =A0 =A0{ >> + =A0 =A0 =A0struct lwp_info *lwp =3D (struct lwp_info *) lp; >> + =A0 =A0 =A0i386_linux_dr_set (ptid_of (lwp), DR_CONTROL, control); >> + =A0 =A0} >> +} >> + >> +/* Get the value of the DR6 debug status register from the inferior. = =A0*/ >> + >> +unsigned >> +i386_dr_low_get_status (void) >> +{ >> + =A0ptid_t inferior_ptid =3D ptid_of (get_thread_lwp (current_inferior)= ); >> + =A0return i386_linux_dr_get (inferior_ptid, DR_STATUS); >> +} >> + >> +/* Watchpoint support. =A0*/ >> + >> +static int >> +i386_insert_watchpoint (struct arch_process_info *arch_private, >> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 char type, CORE_ADDR addr,= int len) >> +{ >> + =A0return i386_low_insert_watchpoint (&arch_private->debug_reg_state, >> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 = =A0type, addr, len); >> +} >> + >> +static int >> +i386_remove_watchpoint (struct arch_process_info *arch_private, >> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 char type, CORE_ADDR addr,= int len) >> +{ >> + =A0return i386_low_remove_watchpoint (&arch_private->debug_reg_state, >> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 = =A0type, addr, len); >> +} >> + >> +static int >> +i386_stopped_by_watchpoint (struct arch_process_info *arch_private) >> +{ >> + =A0return i386_low_stopped_by_watchpoint (&arch_private->debug_reg_sta= te); >> +} >> + >> +static CORE_ADDR >> +i386_stopped_data_address (struct arch_process_info *arch_private) >> +{ >> + =A0return i386_low_stopped_data_address (&arch_private->debug_reg_stat= e); >> +} >> + >> +/* Called when a new process is created. =A0*/ >> + >> +struct arch_process_info * >> +i386_linux_new_process (int pid, int attached) >> +{ >> + =A0struct arch_process_info *info =3D xcalloc (1, sizeof (*info)); >> + >> + =A0return info; >> +} >> + >> +/* Called when a new thread is detected. >> + =A0 INITIAL is non-zero for the main thread, zero otherwise. =A0*/ >> + >> +static void >> +i386_linux_new_thread (struct lwp_info *lwp, int initial) >> +{ >> + =A0/* The initial thread has debug regs set later during process >> + =A0 =A0 creation/attaching handling. =A0*/ >> + >> + =A0if (! initial) >> + =A0 =A0{ >> + =A0 =A0 =A0int i; >> + =A0 =A0 =A0ptid_t ptid =3D ptid_of (lwp); >> + =A0 =A0 =A0int pid =3D PIDGET (ptid); >> + =A0 =A0 =A0struct process_info *proc =3D find_process_pid (pid); >> + =A0 =A0 =A0struct arch_process_info *arch_private =3D proc->private->a= rch_private; >> + =A0 =A0 =A0struct i386_debug_reg_state *state =3D &arch_private->debug= _reg_state; >> + >> + =A0 =A0 =A0for (i =3D DR_FIRSTADDR; i <=3D DR_LASTADDR; i++) >> + =A0 =A0 =A0 i386_linux_dr_set (ptid, i, state->dr_mirror[i]); >> + >> + =A0 =A0 =A0i386_linux_dr_set (ptid, DR_CONTROL, state->dr_control_mirr= or); >> + =A0 =A0} >> +} >> >> =A0struct linux_target_ops the_low_target =3D { >> =A0 init_registers_i386_linux, >> @@ -201,10 +349,12 @@ struct linux_target_ops the_low_target =3D >> =A0 NULL, >> =A0 1, >> =A0 i386_breakpoint_at, >> + =A0i386_insert_watchpoint, >> + =A0i386_remove_watchpoint, >> + =A0i386_stopped_by_watchpoint, >> + =A0i386_stopped_data_address, >> =A0 NULL, >> =A0 NULL, >> - =A0NULL, >> - =A0NULL, >> - =A0NULL, >> - =A0NULL, >> + =A0i386_linux_new_process, >> + =A0i386_linux_new_thread >> =A0}; >> Index: linux-low.c >> =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D >> RCS file: /cvs/src/src/gdb/gdbserver/linux-low.c,v >> retrieving revision 1.97 >> diff -u -p -r1.97 linux-low.c >> --- linux-low.c 3 Apr 2009 11:40:02 -0000 =A0 =A0 =A0 1.97 >> +++ linux-low.c 30 Apr 2009 06:26:54 -0000 >> @@ -120,6 +120,7 @@ static int must_set_ptrace_flags; >> =A0 =A0control of gdbserver have the same architecture. =A0*/ >> =A0static int new_inferior; >> >> +static void notify_low_target_new_thread (struct lwp_info *lwp, int ini= tial); >> =A0static void linux_resume_one_lwp (struct inferior_list_entry *entry, >> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0int s= tep, int signal, siginfo_t *info); >> =A0static void linux_resume (struct thread_resume *resume_info, size_t n= ); >> @@ -179,6 +180,9 @@ linux_add_process (int pid, int attached >> =A0 proc =3D add_process (pid, attached); >> =A0 proc->private =3D xcalloc (1, sizeof (*proc->private)); >> >> + =A0if (the_low_target.new_process !=3D NULL) >> + =A0 =A0proc->private->arch_private =3D the_low_target.new_process (pid= , attached); >> + >> =A0 return proc; >> =A0} >> >> @@ -188,6 +192,7 @@ linux_add_process (int pid, int attached >> =A0static void >> =A0linux_remove_process (struct process_info *process) >> =A0{ >> + =A0free (process->private->arch_private); >> =A0 free (process->private); >> =A0 remove_process (process); >> =A0} >> @@ -231,6 +236,7 @@ handle_extended_wait (struct lwp_info *e >> =A0 =A0 =A0 ptid =3D ptid_build (pid_of (event_child), new_pid, 0); >> =A0 =A0 =A0 new_lwp =3D (struct lwp_info *) add_lwp (ptid); >> =A0 =A0 =A0 add_thread (ptid, new_lwp); >> + =A0 =A0 =A0notify_low_target_new_thread (new_lwp, 0); >> >> =A0 =A0 =A0 /* Normally we will get the pending SIGSTOP. =A0But in some = cases >> =A0 =A0 =A0 =A0 we might get another signal delivered to the group first. >> @@ -313,6 +319,18 @@ add_lwp (ptid_t ptid) >> =A0 return lwp; >> =A0} >> >> +/* Notify the backend that we have a new thread, be it the main thread >> + =A0 or a later one. >> + =A0 INITIAL is non-zero for the main thread, zero otherwise. >> + =A0 NOTE: This must be called when the thread is stopped. =A0*/ >> + >> +static void >> +notify_low_target_new_thread (struct lwp_info *lwp, int initial) >> +{ >> + =A0if (the_low_target.new_thread !=3D NULL) >> + =A0 =A0the_low_target.new_thread (lwp, initial); >> +} >> + >> =A0/* Start an inferior process and returns its pid. >> =A0 =A0ALLARGS is a vector of program-name and args. */ >> >> @@ -354,6 +372,8 @@ linux_create_inferior (char *program, ch >> =A0 ptid =3D ptid_build (pid, pid, 0); >> =A0 new_lwp =3D add_lwp (ptid); >> =A0 add_thread (ptid, new_lwp); >> + =A0/* We can't call notify_low_target_new_thread there, the thread isn= 't >> + =A0 =A0 stopped. =A0Piggyback on must_set_ptrace_flags and call it the= n. =A0*/ >> =A0 must_set_ptrace_flags =3D 1; >> >> =A0 return pid; >> @@ -401,6 +421,7 @@ linux_attach_lwp_1 (unsigned long lwpid, >> >> =A0 new_lwp =3D (struct lwp_info *) add_lwp (ptid); >> =A0 add_thread (ptid, new_lwp); >> + =A0notify_low_target_new_thread (new_lwp, initial); >> >> =A0 /* The next time we wait for this LWP we'll see a SIGSTOP as PTRACE_= ATTACH >> =A0 =A0 =A0brings it to a halt. >> @@ -1261,6 +1282,7 @@ retry: >> =A0 if (must_set_ptrace_flags) >> =A0 =A0 { >> =A0 =A0 =A0 ptrace (PTRACE_SETOPTIONS, lwpid_of (lwp), 0, PTRACE_O_TRACE= CLONE); >> + =A0 =A0 =A0notify_low_target_new_thread (lwp, 1); >> =A0 =A0 =A0 must_set_ptrace_flags =3D 0; >> =A0 =A0 } >> =A0 /* If we are waiting for a particular child, and it exited, >> @@ -2599,7 +2623,11 @@ static int >> =A0linux_insert_watchpoint (char type, CORE_ADDR addr, int len) >> =A0{ >> =A0 if (the_low_target.insert_watchpoint !=3D NULL) >> - =A0 =A0return the_low_target.insert_watchpoint (type, addr, len); >> + =A0 =A0{ >> + =A0 =A0 =A0struct process_info *proc =3D current_process (); >> + =A0 =A0 =A0return the_low_target.insert_watchpoint (proc->private->arc= h_private, >> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 = =A0 =A0 =A0 =A0 =A0 =A0type, addr, len); >> + =A0 =A0} >> =A0 else >> =A0 =A0 /* Unsupported (see target.h). =A0*/ >> =A0 =A0 return 1; >> @@ -2609,7 +2637,11 @@ static int >> =A0linux_remove_watchpoint (char type, CORE_ADDR addr, int len) >> =A0{ >> =A0 if (the_low_target.remove_watchpoint !=3D NULL) >> - =A0 =A0return the_low_target.remove_watchpoint (type, addr, len); >> + =A0 =A0{ >> + =A0 =A0 =A0struct process_info *proc =3D current_process (); >> + =A0 =A0 =A0return the_low_target.remove_watchpoint (proc->private->arc= h_private, >> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 = =A0 =A0 =A0 =A0 =A0 =A0type, addr, len); >> + =A0 =A0} >> =A0 else >> =A0 =A0 /* Unsupported (see target.h). =A0*/ >> =A0 =A0 return 1; >> @@ -2619,7 +2651,10 @@ static int >> =A0linux_stopped_by_watchpoint (void) >> =A0{ >> =A0 if (the_low_target.stopped_by_watchpoint !=3D NULL) >> - =A0 =A0return the_low_target.stopped_by_watchpoint (); >> + =A0 =A0{ >> + =A0 =A0 =A0struct process_info *proc =3D current_process (); >> + =A0 =A0 =A0return the_low_target.stopped_by_watchpoint (proc->private-= >arch_private); >> + =A0 =A0} >> =A0 else >> =A0 =A0 return 0; >> =A0} >> @@ -2628,7 +2663,10 @@ static CORE_ADDR >> =A0linux_stopped_data_address (void) >> =A0{ >> =A0 if (the_low_target.stopped_data_address !=3D NULL) >> - =A0 =A0return the_low_target.stopped_data_address (); >> + =A0 =A0{ >> + =A0 =A0 =A0struct process_info *proc =3D current_process (); >> + =A0 =A0 =A0return the_low_target.stopped_data_address (proc->private->= arch_private); >> + =A0 =A0} >> =A0 else >> =A0 =A0 return 0; >> =A0} >> Index: linux-low.h >> =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D >> RCS file: /cvs/src/src/gdb/gdbserver/linux-low.h,v >> retrieving revision 1.28 >> diff -u -p -r1.28 linux-low.h >> --- linux-low.h 1 Apr 2009 22:50:24 -0000 =A0 =A0 =A0 1.28 >> +++ linux-low.h 30 Apr 2009 01:23:29 -0000 >> @@ -54,8 +54,13 @@ struct process_info_private >> >> =A0 /* Connection to the libthread_db library. =A0*/ >> =A0 td_thragent_t *thread_agent; >> + >> + =A0/* Target-specific additions. =A0*/ >> + =A0struct arch_process_info *arch_private; >> =A0}; >> >> +struct lwp_info; >> + >> =A0struct linux_target_ops >> =A0{ >> =A0 /* Architecture-specific setup. =A0*/ >> @@ -75,26 +80,37 @@ struct linux_target_ops >> =A0 int breakpoint_len; >> =A0 CORE_ADDR (*breakpoint_reinsert_addr) (void); >> >> - >> =A0 int decr_pc_after_break; >> =A0 int (*breakpoint_at) (CORE_ADDR pc); >> >> =A0 /* Watchpoint related functions. =A0See target.h for comments. =A0*/ >> - =A0int (*insert_watchpoint) (char type, CORE_ADDR addr, int len); >> - =A0int (*remove_watchpoint) (char type, CORE_ADDR addr, int len); >> - =A0int (*stopped_by_watchpoint) (void); >> - =A0CORE_ADDR (*stopped_data_address) (void); >> + =A0int (*insert_watchpoint) (struct arch_process_info *arch_private, >> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 char type, CORE_AD= DR addr, int len); >> + =A0int (*remove_watchpoint) (struct arch_process_info *arch_private, >> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 char type, CORE_AD= DR addr, int len); >> + =A0int (*stopped_by_watchpoint) (struct arch_process_info *arch_privat= e); >> + =A0CORE_ADDR (*stopped_data_address) (struct arch_process_info *arch_p= rivate); >> >> =A0 /* Hooks to reformat register data for PEEKUSR/POKEUSR (in particular >> =A0 =A0 =A0for registers smaller than an xfer unit). =A0*/ >> =A0 void (*collect_ptrace_register) (int regno, char *buf); >> =A0 void (*supply_ptrace_register) (int regno, const char *buf); >> + >> + =A0/* Hook to call when a new process is created or attached to. =A0*/ >> + =A0struct arch_process_info * (*new_process) (int pid, int attached); >> + >> + =A0/* Hook to call when a new thread is detected. >> + =A0 =A0 INITIAL is non-zero for the main thread, zero otherwise. =A0*/ >> + =A0void (*new_thread) (struct lwp_info *, int initial); >> =A0}; >> >> =A0extern struct linux_target_ops the_low_target; >> >> +#define ptid_of(proc) ((proc)->head.id) >> =A0#define pid_of(proc) ptid_get_pid ((proc)->head.id) >> =A0#define lwpid_of(proc) ptid_get_lwp ((proc)->head.id) >> +#define PIDGET(ptid) ptid_get_pid (ptid) >> +#define TIDGET(ptid) ptid_get_lwp (ptid) >> >> =A0#define get_lwp(inf) ((struct lwp_info *)(inf)) >> =A0#define get_thread_lwp(thr) (get_lwp (inferior_target_data (thr))) >> Index: linux-x86-64-low.c >> =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D >> RCS file: /cvs/src/src/gdb/gdbserver/linux-x86-64-low.c,v >> retrieving revision 1.22 >> diff -u -p -r1.22 linux-x86-64-low.c >> --- linux-x86-64-low.c =A022 Mar 2009 23:57:10 -0000 =A0 =A0 =A01.22 >> +++ linux-x86-64-low.c =A030 Apr 2009 01:23:29 -0000 >> @@ -18,9 +18,11 @@ >> =A0 =A0You should have received a copy of the GNU General Public License >> =A0 =A0along with this program. =A0If not, see . =A0*/ >> >> +#include >> =A0#include "server.h" >> =A0#include "linux-low.h" >> =A0#include "i387-fp.h" >> +#include "i386-low.h" >> >> =A0#include "gdb_proc_service.h" >> >> @@ -45,6 +47,11 @@ void init_registers_x86_64_linux (void); >> =A0#define ARCH_GET_GS 0x1004 >> =A0#endif >> >> +struct arch_process_info >> +{ >> + =A0struct i386_debug_reg_state debug_reg_state; >> +}; >> + >> =A0static int x86_64_regmap[] =3D { >> =A0 RAX * 8, RBX * 8, RCX * 8, RDX * 8, >> =A0 RSI * 8, RDI * 8, RBP * 8, RSP * 8, >> @@ -161,6 +168,148 @@ x86_64_breakpoint_at (CORE_ADDR pc) >> >> =A0 return 0; >> =A0} >> + >> +/* Support for debug registers. =A0*/ >> + >> +static unsigned long >> +x86_64_linux_dr_get (ptid_t ptid, int regnum) >> +{ >> + =A0int tid; >> + =A0unsigned long value; >> + >> + =A0tid =3D TIDGET (ptid); >> + =A0if (tid =3D=3D 0) >> + =A0 =A0tid =3D PIDGET (ptid); >> + >> + =A0errno =3D 0; >> + =A0value =3D ptrace (PTRACE_PEEKUSER, tid, >> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 offsetof (struct user, u_debugreg[regn= um]), 0); >> + =A0if (errno !=3D 0) >> + =A0 =A0error ("Couldn't read debug register"); >> + >> + =A0return value; >> +} >> + >> +static void >> +x86_64_linux_dr_set (ptid_t ptid, int regnum, unsigned long value) >> +{ >> + =A0int tid; >> + >> + =A0tid =3D TIDGET (ptid); >> + =A0if (tid =3D=3D 0) >> + =A0 =A0tid =3D PIDGET (ptid); >> + >> + =A0errno =3D 0; >> + =A0ptrace (PTRACE_POKEUSER, tid, >> + =A0 =A0 =A0 =A0 offsetof (struct user, u_debugreg[regnum]), value); >> + =A0if (errno !=3D 0) >> + =A0 =A0error ("Couldn't write debug register"); >> +} >> + >> +/* Pass the address ADDR to the inferior in debug register REGNUM. =A0*/ >> + >> +void >> +i386_dr_low_set_addr (int regnum, CORE_ADDR addr) >> +{ >> + =A0struct inferior_list_entry *lp; >> + >> + =A0if (! (regnum >=3D 0 && regnum <=3D DR_LASTADDR - DR_FIRSTADDR)) >> + =A0 =A0error ("Invalid debug register"); >> + >> + =A0for (lp =3D all_lwps.head; lp; lp =3D lp->next) >> + =A0 =A0{ >> + =A0 =A0 =A0struct lwp_info *lwp =3D (struct lwp_info *) lp; >> + =A0 =A0 =A0x86_64_linux_dr_set (ptid_of (lwp), DR_FIRSTADDR + regnum, = addr); >> + =A0 =A0} >> +} >> + >> +/* Pass the value VAL to the inferior in the DR7 debug control register= . =A0*/ >> + >> +void >> +i386_dr_low_set_control (unsigned control) >> +{ >> + =A0struct inferior_list_entry *lp; >> + >> + =A0for (lp =3D all_lwps.head; lp; lp =3D lp->next) >> + =A0 =A0{ >> + =A0 =A0 =A0struct lwp_info *lwp =3D (struct lwp_info *) lp; >> + =A0 =A0 =A0x86_64_linux_dr_set (ptid_of (lwp), DR_CONTROL, control); >> + =A0 =A0} >> +} >> + >> +/* Get the value of the DR6 debug status register from the inferior. = =A0*/ >> + >> +unsigned >> +i386_dr_low_get_status (void) >> +{ >> + =A0ptid_t inferior_ptid =3D ptid_of (get_thread_lwp (current_inferior)= ); >> + =A0return x86_64_linux_dr_get (inferior_ptid, DR_STATUS); >> +} >> + >> +/* Watchpoint support. =A0*/ >> + >> +static int >> +x86_64_insert_watchpoint (struct arch_process_info *arch_private, >> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 char type, CORE_ADDR a= ddr, int len) >> +{ >> + =A0return i386_low_insert_watchpoint (&arch_private->debug_reg_state, >> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 = =A0type, addr, len); >> +} >> + >> +static int >> +x86_64_remove_watchpoint (struct arch_process_info *arch_private, >> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 char type, CORE_ADDR a= ddr, int len) >> +{ >> + =A0return i386_low_remove_watchpoint (&arch_private->debug_reg_state, >> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 = =A0type, addr, len); >> +} >> + >> +static int >> +x86_64_stopped_by_watchpoint (struct arch_process_info *arch_private) >> +{ >> + =A0return i386_low_stopped_by_watchpoint (&arch_private->debug_reg_sta= te); >> +} >> + >> +static CORE_ADDR >> +x86_64_stopped_data_address (struct arch_process_info *arch_private) >> +{ >> + =A0return i386_low_stopped_data_address (&arch_private->debug_reg_stat= e); >> +} >> + >> +/* Called when a new process is created. =A0*/ >> + >> +struct arch_process_info * >> +x86_64_linux_new_process (int pid, int attached) >> +{ >> + =A0struct arch_process_info *info =3D xcalloc (1, sizeof (*info)); >> + >> + =A0return info; >> +} >> + >> +/* Called when a new thread is detected. >> + =A0 INITIAL is non-zero for the main thread, zero otherwise. =A0*/ >> + >> +static void >> +x86_64_linux_new_thread (struct lwp_info *lwp, int initial) >> +{ >> + =A0/* The initial thread has debug regs set later during process >> + =A0 =A0 creation/attaching handling. =A0*/ >> + >> + =A0if (! initial) >> + =A0 =A0{ >> + =A0 =A0 =A0int i; >> + =A0 =A0 =A0ptid_t ptid =3D ptid_of (lwp); >> + =A0 =A0 =A0int pid =3D PIDGET (ptid); >> + =A0 =A0 =A0struct process_info *proc =3D find_process_pid (pid); >> + =A0 =A0 =A0struct arch_process_info *arch_private =3D proc->private->a= rch_private; >> + =A0 =A0 =A0struct i386_debug_reg_state *state =3D &arch_private->debug= _reg_state; >> + >> + =A0 =A0 =A0for (i =3D DR_FIRSTADDR; i <=3D DR_LASTADDR; i++) >> + =A0 =A0 =A0 x86_64_linux_dr_set (ptid, i, state->dr_mirror[i]); >> + >> + =A0 =A0 =A0x86_64_linux_dr_set (ptid, DR_CONTROL, state->dr_control_mi= rror); >> + =A0 =A0} >> +} >> >> =A0struct linux_target_ops the_low_target =3D { >> =A0 init_registers_x86_64_linux, >> @@ -175,10 +324,12 @@ struct linux_target_ops the_low_target =3D >> =A0 NULL, >> =A0 1, >> =A0 x86_64_breakpoint_at, >> + =A0x86_64_insert_watchpoint, >> + =A0x86_64_remove_watchpoint, >> + =A0x86_64_stopped_by_watchpoint, >> + =A0x86_64_stopped_data_address, >> =A0 NULL, >> =A0 NULL, >> - =A0NULL, >> - =A0NULL, >> - =A0NULL, >> - =A0NULL, >> + =A0x86_64_linux_new_process, >> + =A0x86_64_linux_new_thread >> =A0}; >> Index: server.h >> =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D >> RCS file: /cvs/src/src/gdb/gdbserver/server.h,v >> retrieving revision 1.56 >> diff -u -p -r1.56 server.h >> --- server.h =A0 =A03 Apr 2009 20:15:51 -0000 =A0 =A0 =A0 1.56 >> +++ server.h =A0 =A030 Apr 2009 01:23:29 -0000 >> @@ -405,6 +405,7 @@ void perror_with_name (const char *strin >> =A0void error (const char *string,...) ATTR_NORETURN ATTR_FORMAT (printf= , 1, 2); >> =A0void fatal (const char *string,...) ATTR_NORETURN ATTR_FORMAT (printf= , 1, 2); >> =A0void warning (const char *string,...) ATTR_FORMAT (printf, 1, 2); >> +char *paddr (CORE_ADDR addr); >> >> =A0/* Maximum number of bytes to read/write at once. =A0The value here >> =A0 =A0is chosen to fill up a packet (the headers account for the 32). = =A0*/ >> Index: utils.c >> =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D >> RCS file: /cvs/src/src/gdb/gdbserver/utils.c,v >> retrieving revision 1.18 >> diff -u -p -r1.18 utils.c >> --- utils.c =A0 =A0 19 Jan 2009 00:16:46 -0000 =A0 =A0 =A01.18 >> +++ utils.c =A0 =A0 30 Apr 2009 01:23:29 -0000 >> @@ -170,3 +170,37 @@ warning (const char *string,...) >> =A0 fprintf (stderr, "\n"); >> =A0 va_end (args); >> =A0} >> + >> +/* temporary storage using circular buffer */ >> +#define NUMCELLS 4 >> +#define CELLSIZE 50 >> +static char * >> +get_cell (void) >> +{ >> + =A0static char buf[NUMCELLS][CELLSIZE]; >> + =A0static int cell =3D 0; >> + =A0if (++cell >=3D NUMCELLS) >> + =A0 =A0cell =3D 0; >> + =A0return buf[cell]; >> +} >> + >> +static int >> +xsnprintf (char *str, size_t size, const char *format, ...) >> +{ >> + =A0va_list args; >> + =A0int ret; >> + >> + =A0va_start (args, format); >> + =A0ret =3D vsnprintf (str, size, format, args); >> + =A0va_end (args); >> + >> + =A0return ret; >> +} >> + >> +char * >> +paddr (CORE_ADDR addr) >> +{ >> + =A0char *str =3D get_cell (); >> + =A0xsnprintf (str, CELLSIZE, "%lx", (long) addr); >> + =A0return str; >> +} >> Index: win32-arm-low.c >> =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D >> RCS file: /cvs/src/src/gdb/gdbserver/win32-arm-low.c,v >> retrieving revision 1.8 >> diff -u -p -r1.8 win32-arm-low.c >> --- win32-arm-low.c =A0 =A0 3 Jan 2009 05:57:57 -0000 =A0 =A0 =A0 1.8 >> +++ win32-arm-low.c =A0 =A0 30 Apr 2009 01:23:29 -0000 >> @@ -122,4 +122,9 @@ struct win32_target_ops the_low_target =3D >> =A0 NULL, /* single_step */ >> =A0 (const unsigned char *) &arm_wince_breakpoint, >> =A0 arm_wince_breakpoint_len, >> + =A0/* Watchpoint related functions. =A0See target.h for comments. =A0*/ >> + =A0NULL, /* insert_watchpoint */ >> + =A0NULL, /* remove_watchpoint */ >> + =A0NULL, /* stopped_by_watchpoint */ >> + =A0NULL =A0/* stopped_data_address */ >> =A0}; >> Index: win32-i386-low.c >> =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D >> RCS file: /cvs/src/src/gdb/gdbserver/win32-i386-low.c,v >> retrieving revision 1.14 >> diff -u -p -r1.14 win32-i386-low.c >> --- win32-i386-low.c =A0 =A03 Jan 2009 05:57:57 -0000 =A0 =A0 =A0 1.14 >> +++ win32-i386-low.c =A0 =A030 Apr 2009 01:23:29 -0000 >> @@ -17,6 +17,7 @@ >> >> =A0#include "server.h" >> =A0#include "win32-low.h" >> +#include "i386-low.h" >> >> =A0#define FCS_REGNUM 27 >> =A0#define FOP_REGNUM 31 >> @@ -31,6 +32,42 @@ static unsigned dr[8]; >> =A0static int debug_registers_changed =3D 0; >> =A0static int debug_registers_used =3D 0; >> >> +/* Pass the address ADDR to the inferior in the I'th debug register. >> + =A0 Here we just store the address in dr array, the registers will be >> + =A0 actually set up when windows_continue is called. =A0*/ >> + >> +void >> +i386_dr_low_set_addr (int i, CORE_ADDR addr) >> +{ >> + =A0if (i < 0 || i > 3) >> + =A0 return; >> + =A0dr[i] =3D (unsigned) addr; >> + =A0debug_registers_changed =3D 1; >> + =A0debug_registers_used =3D 1; >> +} >> + >> +/* Pass the value VAL to the inferior in the DR7 debug control register. >> + =A0 Here we just store the address in D_REGS, the watchpoint >> + =A0 will be actually set up in windows_wait. =A0*/ >> + >> +void >> +i386_dr_low_set_control (unsigned val) >> +{ >> + =A0dr[7] =3D val; >> + =A0debug_registers_changed =3D 1; >> + =A0debug_registers_used =3D 1; >> +} >> + >> +/* Get the value of the DR6 debug status register from the inferior. >> + =A0 Here we just return the value stored in dr[6] >> + =A0 by the last call to thread_rec for current_event.dwThreadId id. = =A0*/ >> + >> +unsigned >> +i386_dr_low_get_status (void) >> +{ >> + =A0return dr[6]; >> +} >> + >> =A0static void >> =A0i386_initial_stuff (void) >> =A0{ >> @@ -205,4 +242,8 @@ struct win32_target_ops the_low_target =3D >> =A0 i386_single_step, >> =A0 NULL, /* breakpoint */ >> =A0 0, /* breakpoint_len */ >> + =A0i386_insert_watchpoint, >> + =A0i386_remove_watchpoint, >> + =A0i386_stopped_by_watchpoint, >> + =A0i386_stopped_data_address >> =A0}; >> Index: win32-low.c >> =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D >> RCS file: /cvs/src/src/gdb/gdbserver/win32-low.c,v >> retrieving revision 1.35 >> diff -u -p -r1.35 win32-low.c >> --- win32-low.c 1 Apr 2009 22:50:24 -0000 =A0 =A0 =A0 1.35 >> +++ win32-low.c 30 Apr 2009 01:23:29 -0000 >> @@ -228,6 +228,48 @@ child_delete_thread (DWORD pid, DWORD ti >> =A0 delete_thread_info (thread); >> =A0} >> >> +/* These watchpoint related wrapper functions simply pass on the functi= on call >> + =A0 if the target has registered a corresponding function. =A0*/ >> + >> +static int >> +win32_insert_watchpoint (char type, CORE_ADDR addr, int len) >> +{ >> + =A0if (the_low_target.insert_watchpoint !=3D NULL) >> + =A0 =A0return the_low_target.insert_watchpoint (type, addr, len); >> + =A0else >> + =A0 =A0/* Unsupported (see target.h). =A0*/ >> + =A0 =A0return 1; >> +} >> + >> +static int >> +win32_remove_watchpoint (char type, CORE_ADDR addr, int len) >> +{ >> + =A0if (the_low_target.remove_watchpoint !=3D NULL) >> + =A0 =A0return the_low_target.remove_watchpoint (type, addr, len); >> + =A0else >> + =A0 =A0/* Unsupported (see target.h). =A0*/ >> + =A0 =A0return 1; >> +} >> + >> +static int >> +win32_stopped_by_watchpoint (void) >> +{ >> + =A0if (the_low_target.stopped_by_watchpoint !=3D NULL) >> + =A0 =A0return the_low_target.stopped_by_watchpoint (); >> + =A0else >> + =A0 =A0return 0; >> +} >> + >> +static CORE_ADDR >> +win32_stopped_data_address (void) >> +{ >> + =A0if (the_low_target.stopped_data_address !=3D NULL) >> + =A0 =A0return the_low_target.stopped_data_address (); >> + =A0else >> + =A0 =A0return 0; >> +} >> + >> + >> =A0/* Transfer memory from/to the debugged process. =A0*/ >> =A0static int >> =A0child_xfer_memory (CORE_ADDR memaddr, char *our, int len, >> @@ -1697,10 +1739,10 @@ static struct target_ops win32_target_op >> =A0 NULL, >> =A0 win32_request_interrupt, >> =A0 NULL, >> - =A0NULL, >> - =A0NULL, >> - =A0NULL, >> - =A0NULL, >> + =A0win32_insert_watchpoint, >> + =A0win32_remove_watchpoint, >> + =A0win32_stopped_by_watchpoint, >> + =A0win32_stopped_data_address, >> =A0 NULL, >> =A0 NULL, >> =A0 NULL, >> Index: win32-low.h >> =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D >> RCS file: /cvs/src/src/gdb/gdbserver/win32-low.h,v >> retrieving revision 1.9 >> diff -u -p -r1.9 win32-low.h >> --- win32-low.h 3 Jan 2009 05:57:57 -0000 =A0 =A0 =A0 1.9 >> +++ win32-low.h 30 Apr 2009 01:23:29 -0000 >> @@ -70,6 +70,13 @@ struct win32_target_ops >> >> =A0 const unsigned char *breakpoint; >> =A0 int breakpoint_len; >> + >> + =A0/* Watchpoint related functions. =A0See target.h for comments. =A0*/ >> + =A0int (*insert_watchpoint) (char type, CORE_ADDR addr, int len); >> + =A0int (*remove_watchpoint) (char type, CORE_ADDR addr, int len); >> + =A0int (*stopped_by_watchpoint) (void); >> + =A0CORE_ADDR (*stopped_data_address) (void); >> + >> =A0}; >> >> =A0extern struct win32_target_ops the_low_target; >> >