From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 7798 invoked by alias); 19 Aug 2009 16:37:59 -0000 Received: (qmail 7786 invoked by uid 22791); 19 Aug 2009 16:37:57 -0000 X-SWARE-Spam-Status: No, hits=-2.0 required=5.0 tests=BAYES_00,SARE_MSGID_LONG40,SPF_PASS X-Spam-Check-By: sourceware.org Received: from ey-out-1920.google.com (HELO ey-out-1920.google.com) (74.125.78.147) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Wed, 19 Aug 2009 16:37:51 +0000 Received: by ey-out-1920.google.com with SMTP id 5so1254972eyb.24 for ; Wed, 19 Aug 2009 09:37:48 -0700 (PDT) MIME-Version: 1.0 Received: by 10.210.87.2 with SMTP id k2mr5961099ebb.32.1250699868432; Wed, 19 Aug 2009 09:37:48 -0700 (PDT) In-Reply-To: <84D22DD1-F4AD-4985-A0EC-AF3B53774D10@gmail.com> References: <84D22DD1-F4AD-4985-A0EC-AF3B53774D10@gmail.com> Date: Wed, 19 Aug 2009 19:13:00 -0000 Message-ID: <27a6661f0908190937vc7323d5ubeea8682b61220d5@mail.gmail.com> Subject: Re: How GDB knows a breakpoint is hit? From: "Satendra..." To: kceiwH Cc: gdb@sourceware.org Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit X-IsSubscribed: yes 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-08/txt/msg00177.txt.bz2 whenever you put a breakpoint at some address using GDB then GDB replaces instruction at that address with a trap, illegal divide, or some other instruction that will cause an exception. So when it's encountered, GDB will take the exception and stop the program. Before you browse the code, go through http://sourceware.org/gdb/current/onlinedocs/gdbint_toc.html once. -Satendra On 19/08/2009, kceiwH wrote: > Hi, > > I wonder how GDB knows it should stop the inferior when a breakpoint > is hit. I try to read the code but only to find how GDB creates a > breakpoint. I thought GDB might change some instructions of inferior > so that when the inferior executes the modified instructions, GDB > should know. But what the function "create_breakpoint" does is to add > a breakpoint to the list "breakpoint_chain". It is not what I thought. > So I am confused. Does GDB monitor each instruction of the inferior > and check whether there is a breakpoint and stop the inferior before > the instruction is executed? If so, how GDB monitor the inferior? And > it will be too slow. Could anybody tell how GDB handle it and plus the > codes. Thanks in advance. > > Regards, > > Mao >