Bug 12802 - Delete breakpoint from Breakpoint.stop
Summary: Delete breakpoint from Breakpoint.stop
Status: RESOLVED WONTFIX
Alias: None
Product: gdb
Classification: Unclassified
Component: python (show other bugs)
Version: HEAD
: P2 normal
Target Milestone: ---
Assignee: Phil Muldoon
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2011-05-24 13:20 UTC by Kevin Pouget
Modified: 2011-10-10 19:06 UTC (History)
3 users (show)

See Also:
Host:
Target:
Build:
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Kevin Pouget 2011-05-24 13:20:12 UTC
an internal error occurs when you try to `delete' a breakpoint during `stop' callback:

class MyBP(gdb.Breakpoint):
        def stop(self):
                self.delete()

(gdb) python MyBP(spec="main")
(gdb) run
Starting program: /home/kevin/a.out 
/home/kevin/travail/srcs/git/gdb/gdb/breakpoint.c:4573: internal-error: bpstat_what: unhandled bptype -1120308712
A problem internal to GDB has been detected,
further debugging may prove unreliable.
Quit this debugging session? (y or n)
Comment 1 Phil Muldoon 2011-10-06 14:00:55 UTC
I cannot replicate this, can you still replicate it Kevin?

(gdb) file ~/simple
(gdb) python
>class b(gdb.Breakpoint):
>   def stop(self):
>      print "hello"
>      self.delete()
>end
(gdb) py bp = b("main")
Breakpoint 1 at 0x400c48: file simple.c, line 4.
(gdb) r
hello
[Inferior 1 (process 715) exited normally]
(gdb) info breakpoints 
No breakpoints or watchpoints.
Comment 2 Kevin Pouget 2011-10-06 14:10:47 UTC
> I cannot replicate this, can you still replicate it Kevin?

no :)

I double checked, GNU gdb (GDB) Fedora (7.3-43.fc15) does have the bug, so it was solved by the magic of time! Thanks for looking at it
Comment 3 Phil Muldoon 2011-10-07 10:17:25 UTC
I'm going to change this to wontfix.  Because there may be other stop() callbacks yet to be processed on that breakpoint, you should not alter or delete the state of breakpoints.  I've submitted a manual patch to explain what you can, or cannot do.
Comment 4 Kevin Pouget 2011-10-07 12:14:44 UTC
is this a good alternative ?

class MyBP(gdb.Breakpoint):
    def stop(self):
        gdb.post_event(self.delete)


the documentation of gdb.post_event seems not very clear if you don't look at what is done internally -- I didn't -- but I think it should be safe to do it this way
Comment 5 cvs-commit@gcc.gnu.org 2011-10-07 13:23:24 UTC
CVSROOT:	/cvs/src
Module name:	src
Changes by:	pmuldoon@sourceware.org	2011-10-07 13:23:19

Modified files:
	gdb/doc        : ChangeLog gdb.texinfo 

Log message:
	2011-10-07  Phil Muldoon  <pmuldoon@redhat.com>
	
	PR python/12930
	PR python/12802
	
	* gdb.texinfo (Breakpoints In Python): Clarify behavior in the
	stop method.

Patches:
http://sourceware.org/cgi-bin/cvsweb.cgi/src/gdb/doc/ChangeLog.diff?cvsroot=src&r1=1.1221&r2=1.1222
http://sourceware.org/cgi-bin/cvsweb.cgi/src/gdb/doc/gdb.texinfo.diff?cvsroot=src&r1=1.870&r2=1.871
Comment 6 Phil Muldoon 2011-10-07 13:58:42 UTC
Yes, I believe so.  But you are still in very dangerous waters.  What happened if you deleted the breakpoint, but returned "True" from that function.  At the very least any breakpoint event notification would be broken.  GDB would call breakpoint stopped observers, but would not have a breakpoint to reference.  There is nothing to stop you doing it in your scripts, but I would really be very careful.
Comment 7 Tom Tromey 2011-10-10 19:06:23 UTC
(In reply to comment #4)
> is this a good alternative ?
> 
> class MyBP(gdb.Breakpoint):
>     def stop(self):
>         gdb.post_event(self.delete)

I think so.

> the documentation of gdb.post_event seems not very clear if you don't look at
> what is done internally -- I didn't -- but I think it should be safe to do it
> this way

Can you suggest how to fix the docs?