From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 11188 invoked by alias); 3 Apr 2007 19:52:15 -0000 Received: (qmail 11179 invoked by uid 22791); 3 Apr 2007 19:52:14 -0000 X-Spam-Check-By: sourceware.org Received: from mx1.palmsource.com (HELO mx1.palmsource.com) (12.7.175.13) by sourceware.org (qpsmtpd/0.31) with ESMTP; Tue, 03 Apr 2007 20:52:13 +0100 Received: from localhost (localhost [127.0.0.1]) by localhost.domain.tld (Postfix) with ESMTP id AEC295F00A; Tue, 3 Apr 2007 12:52:11 -0700 (PDT) Received: from mx1.palmsource.com ([127.0.0.1]) by localhost (mx1.palmsource.com [127.0.0.1]) (amavisd-new, port 10024) with LMTP id 06783-05-4; Tue, 3 Apr 2007 12:52:10 -0700 (PDT) Received: from ussunex03.svl.access-company.com (ussunm001.palmsource.com [192.168.101.12]) by mx1.palmsource.com (Postfix) with ESMTP id A9E1E5EFEE; Tue, 3 Apr 2007 12:52:10 -0700 (PDT) Received: from 192.168.92.56 ([192.168.92.56]) by ussunex03.svl.access-company.com ([192.168.101.12]) via Exchange Front-End Server owa.access-company.com ([10.0.20.19]) with Microsoft Exchange Server HTTP-DAV ; Tue, 3 Apr 2007 19:53:30 +0000 Received: from svmsnyderlnx by owa.access-company.com; 03 Apr 2007 12:52:11 -0700 Subject: Re: Use debug registers directly in programs? From: Michael Snyder To: Mathieu Lacage Cc: Wang Yi , gdb@sourceware.org In-Reply-To: <1175585450.3988.167.camel@garfield.inria.fr> References: <1175585450.3988.167.camel@garfield.inria.fr> Content-Type: text/plain Content-Transfer-Encoding: 7bit Date: Tue, 03 Apr 2007 19:52:00 -0000 Message-Id: <1175629931.11945.15.camel@svmsnyderlnx.palmsource.com> Mime-Version: 1.0 X-Mailer: Evolution 2.8.1 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: 2007-04/txt/msg00024.txt.bz2 On Tue, 2007-04-03 at 09:30 +0200, Mathieu Lacage wrote: > On Tue, 2007-04-03 at 15:13 +0800, Wang Yi wrote: > > > 1. Is that feasible to use debug registers in the programs to > > debug themselves? I think yes, any confirm? > > 2. How to use the debug registers? The IA32 manual talks about > > these registers but doesn't tell how to use them, the gdb internals > > covers many areas but it is too complex for those who have not written > > or read a debugger before. Should I read the gdb source? > > The only way I know of to set the debug registers is to use ptrace and a > program cannot ptrace itself so, you will always need a third-party > program if only to control the debug registers on your behalf. Yes, instructions to access the debug registers are almost always privileged instructions. User programs cannot use them. Even gdb cannot access them directly, it has to ask the Kernel to do it. Hence the ptrace interface, and as Mathieu says, a program cannot ptrace itself.