From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 30890 invoked by alias); 4 Dec 2009 16:21:25 -0000 Received: (qmail 30880 invoked by uid 22791); 4 Dec 2009 16:21:23 -0000 X-SWARE-Spam-Status: No, hits=-2.0 required=5.0 tests=AWL,BAYES_00,SARE_MSGID_LONG40,SPF_PASS X-Spam-Check-By: sourceware.org Received: from mail-pw0-f49.google.com (HELO mail-pw0-f49.google.com) (209.85.160.49) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Fri, 04 Dec 2009 16:21:18 +0000 Received: by pwi1 with SMTP id 1so2434196pwi.8 for ; Fri, 04 Dec 2009 08:21:17 -0800 (PST) MIME-Version: 1.0 Received: by 10.115.112.40 with SMTP id p40mr4297891wam.182.1259943677139; Fri, 04 Dec 2009 08:21:17 -0800 (PST) In-Reply-To: <4B18CD92.8000302@codesourcery.com> References: <26eb53620911301516x68ccc0edkf64ba2951c8ce3a3@mail.gmail.com> <26eb53620911301518y13e64bc0g95c6fe3c7b18b0c@mail.gmail.com> <4B18CD92.8000302@codesourcery.com> From: Aravinda Date: Fri, 04 Dec 2009 16:21:00 -0000 Message-ID: <26eb53620912040820y3340ad2fw78bf770754b26c4c@mail.gmail.com> Subject: Re: GDB library to insert and delete watchpoints To: Stan Shebs , jan.kratochvil@redhat.com, ppluzhnikov@google.com, dave.korn.cygwin@googlemail.com Cc: gdb@sourceware.org Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Mailing-List: contact gdb-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-owner@sourceware.org X-SW-Source: 2009-12/txt/msg00030.txt.bz2 Hi, Thank you for all of your replies and suggestions. Yah, Im assuming a simple case for now of only debugging a single thread/process. Also, its actually a little different since Im not trying to have a separate debugging thread to do this job. I have a single threaded application that I want to be safe from buffer overruns all the time, that doesnt have more than 4 levels of nested loops, so 4 debug register should do just good for this. And Im trying to do it automatically by instrumenting GCC to add a call (before array accesses) to a custom library function that inserts a watchpoint. I wanted to write a C library that manages mirror registers and occasionally makes a system call/invokes a driver to put the value in the debug register. I have never used ptrace before and need to lookup on it, but the code that I saw was for a parent process modifying the contents of debug registers for the child. So im assuming I can either call ptrace from the same process to modify the contents or have to write a driver to manipulate debug registers. Thanks, Aravinda On Fri, Dec 4, 2009 at 3:51 AM, Stan Shebs wrote: > > Aravinda wrote: >> >> Hi, >> >> Im working on a project that currently requires inserting and deleting >> watchpoints to monitor buffer overruns. I was looking at the >> gdb-internals documentation which talks about a gdb library that can >> be used to do exactly this. But I couldnt find more info on this. Im >> looking for a ready to use library to be used with a kernel module >> that allows for modifying the debug registers. kindly point me to any >> sources if it can be done. >> > > It just so happens that CodeSourcery recently did this for a customer tha= t was using a debugging stub that ran as one of several threads in the appl= ication. =A0It does need its own driver to modify the debug registers, and = the stub calls it once it has done the bit-twiddling on mirrors of the regi= sters. =A0While it works well enough to have one thread set the debug regis= ters of a different thread in a Linux app, there is some fancy dancing to m= ake this work in nonstop - with all the threads running at once, you can ge= t nasty races all over the place. =A0Unfortunately, this is all CodeSourcer= y proprietary code and intermingled with the customer's app to boot, so I c= an't send you a copy. > > Stan >