From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 8927 invoked by alias); 27 Sep 2007 11:27:36 -0000 Received: (qmail 8917 invoked by uid 22791); 27 Sep 2007 11:27:34 -0000 X-Spam-Check-By: sourceware.org Received: from sibelius.xs4all.nl (HELO brahms.sibelius.xs4all.nl) (82.92.89.47) by sourceware.org (qpsmtpd/0.31) with ESMTP; Thu, 27 Sep 2007 11:27:28 +0000 Received: from brahms.sibelius.xs4all.nl (kettenis@localhost.sibelius.xs4all.nl [127.0.0.1]) by brahms.sibelius.xs4all.nl (8.14.1/8.14.0) with ESMTP id l8RBRNJn026440; Thu, 27 Sep 2007 13:27:23 +0200 (CEST) Received: (from kettenis@localhost) by brahms.sibelius.xs4all.nl (8.14.1/8.14.1/Submit) id l8RBRMPG017896; Thu, 27 Sep 2007 13:27:22 +0200 (CEST) Date: Thu, 27 Sep 2007 12:06:00 -0000 Message-Id: <200709271127.l8RBRMPG017896@brahms.sibelius.xs4all.nl> From: Mark Kettenis To: carl.shapiro@gmail.com CC: gdb@sourceware.org In-reply-to: <4dcb5abd0709260133h10aede86wb60a22094c8d9884@mail.gmail.com> (carl.shapiro@gmail.com) Subject: Re: Problems with hook-stop References: <4dcb5abd0709260133h10aede86wb60a22094c8d9884@mail.gmail.com> 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-09/txt/msg00226.txt.bz2 > Date: Wed, 26 Sep 2007 01:33:11 -0700 > From: "Carl Shapiro" > > Hi, > > I am trying to write a user-defined command hook that automatically > passes a SIGTRAP to my program. Here is the definition I am working > with: > > define hook-stop > if (((* (char *) ($pc - 1)) & 0xff) == 0xcc) > signal SIGTRAP > end > end > > My target architecture is x86. This command fires the first time I > hit an "int3" instruction. The next time I hit an int3, hook-stop is > not executed and I must manually pass a SIGTRAP by evaluating "signal > SIGTRAP". It seems that every other time gdb is stopped with a > SIGTRAP the stop hook is not executed. Here's a program that can be > used to demonstrate this: > > #include > #include > > void handler(int signum) { > fprintf(stderr, "handler(signum=%d)\n", signum); > } > > int main(int argc, char *argv[]) { > struct sigaction sa; > int i; > sa.sa_handler = handler; > for (i = 0;; ++i) { > fprintf(stderr, "i=%d\n", i); > asm("int3"); > } > return 0; > } > > If I remove the "signal SIGTRAP" statement from hook-stop, it fires > every time around the loop. Does anyone know where am I going wrong > wrong? Since SIGTRAP has a very special meaning for debugging, it's probably unwise to play games like this.