From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 30461 invoked by alias); 20 Apr 2011 14:59:28 -0000 Received: (qmail 30442 invoked by uid 22791); 20 Apr 2011 14:59:25 -0000 X-SWARE-Spam-Status: No, hits=-1.6 required=5.0 tests=AWL,BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,RCVD_IN_DNSWL_LOW,RFC_ABUSE_POST,T_TO_NO_BRKTS_FREEMAIL X-Spam-Check-By: sourceware.org Received: from mail-vw0-f41.google.com (HELO mail-vw0-f41.google.com) (209.85.212.41) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Wed, 20 Apr 2011 14:59:07 +0000 Received: by vws4 with SMTP id 4so861578vws.0 for ; Wed, 20 Apr 2011 07:59:06 -0700 (PDT) Received: by 10.220.187.76 with SMTP id cv12mr2276366vcb.128.1303311546054; Wed, 20 Apr 2011 07:59:06 -0700 (PDT) MIME-Version: 1.0 Received: by 10.220.61.6 with HTTP; Wed, 20 Apr 2011 07:58:46 -0700 (PDT) In-Reply-To: References: From: Kevin Pouget Date: Wed, 20 Apr 2011 14:59:00 -0000 Message-ID: Subject: Re: GDB Python API: stop/continue after breakpoint To: pmuldoon@redhat.com, gdb@sourceware.org Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable 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: 2011-04/txt/msg00111.txt.bz2 Hello, I'm coming back to this post because I've got a bit of an issue here: basically, I need (and I'm looking for to helping for it!) a sharp control of the inferior execution from the python interface, but I'm facing some limitations: * in MyBreakpoint.stop(), I can say continue/stop the inferior, but I can't run "finish" (or "next" or what ever, I guess), because the inferior is still considered as running: > "gdb.error: Cannot execute this command while the selected thread is runn= ing." * in event.stop.connect() that's possible, but I can't `gdb.execute("continue")' the execution because I would miss any "non-python" reasons to stop (ie, a user-breakpoint, a signal ...) let me know if my problem is not clear, and if you have any comment / idea on how to solve it cordially, Kevin On Fri, Mar 11, 2011 at 12:52 PM, Kevin Pouget wro= te: > thanks for your answer, the patch seems to feature what I was looking for. > > I'm a bit surprised that the stop/continue decision can't be done in > this breakpoint_stop handler, but I guess that was too complicated ? > >> On Fri, Mar 11, 2011 at 5:25 PM, Phil Muldoon wrot= e: >>> >>> Kevin Pouget writes: >>> >>> > Hello, >>> > >>> > I've tried the GDB python interface today, which seems quite >>> > efficient, but there is one important thing I couldn't figure out by >>> > myself: >>> > >>> > how to restart GDB when a[n internal] breakpoint is hit ? >>> > from the testsuite I've got this code: >>> >>> >>> You almost can. One part is pending: >>> >>> http://sourceware.org/ml/gdb-patches/2011-03/msg00656.html >>> >>> The implementation of the "stop" API. =A0The idea behind this is that i= f a >>> breakpoint is hit, that is tracked from Python and has an implemented >>> stop method, that method would be called. =A0You can do what you like in >>> that method. =A0If you want the inferior process to continue, return Tr= ue >>> otherwise return False (and print out/do whatever else you need to do in >>> Python). >>> >>> Because internal breakpoints are not tracked by default in the Python >>> Breakpoint API, you would have to create your breakpoint by >>> instantiating a gdb.Breakpoint class, and pass the keyword >>> internal=3DTrue. >>> >>> So, long story short soon. =A0OTOH I'm not sure if there is a unhacky w= ay >>> of doing it now. =A0You could use a convenience function, but that patch >>> is replacing that hacky way. >>> >>> Cheers >>> >>> Phil >>> > >>> > def breakpoint_stop_handler (event): >>> > =A0 =A0 if (isinstance (event, gdb.StopEvent)): >>> > =A0 =A0 =A0 =A0 print "event type: stop" >>> > =A0 =A0 if (isinstance (event, gdb.BreakpointEvent)): >>> > =A0 =A0 =A0 =A0 print "stop reason: breakpoint" >>> > =A0 =A0 =A0 =A0 print "breakpoint number: %s" % (event.breakpoint.num= ber) >>> > =A0 =A0 =A0 =A0 if ( event.inferior_thread is not None) : >>> > =A0 =A0 =A0 =A0 =A0 =A0 print "thread num: %s" % (event.inferior_thre= ad.num); >>> > =A0 =A0 =A0 =A0 else: >>> > =A0 =A0 =A0 =A0 =A0 =A0 print "all threads stopped" >>> > >>> > gdb.events.stop.connect (breakpoint_stop_handler) >>> > >>> > >>> > which where I get the notification of the stop, but I'd to be able to >>> > tell GDB something like >>> > >>> > enum bpstat_what_main_action { >>> > =A0 =A0 /* Remove breakpoints, single step once, then put them back i= n and >>> > =A0 =A0 =A0 =A0go back to what we were doing. =A0It's possible that t= his should >>> > =A0 =A0 =A0 =A0be removed from the main_action and put into a separat= e field, >>> > =A0 =A0 =A0 =A0to more cleanly handle =A0BPSTAT_WHAT_CLEAR_LONGJMP_RE= SUME_SINGLE. =A0*/ >>> > =A0 =A0 BPSTAT_WHAT_SINGLE, >>> > =A0 =A0 /* Stop silently. =A0*/ >>> > =A0 =A0 BPSTAT_WHAT_STOP_SILENT, >>> > >>> > =A0 =A0 /* Stop and print. =A0*/ >>> > =A0 =A0 BPSTAT_WHAT_STOP_NOISY, >>> > ... >>> > } >>> > >>> > to continue silently, stop silently or print the breakpoint hit. >>> > >>> > is it possible at this stage ? >>> > >>> > Thanks, >>> > >>> > Kevin >> >