Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #58891 > unrolled thread

Conditional breakpoints in ceval.c

Started byDemian Brecht <demianbrecht@gmail.com>
First post2013-11-08 18:03 -0800
Last post2013-11-12 09:44 +0100
Articles 3 — 3 participants

Back to article view | Back to comp.lang.python


Contents

  Conditional breakpoints in ceval.c Demian Brecht <demianbrecht@gmail.com> - 2013-11-08 18:03 -0800
    Re: Conditional breakpoints in ceval.c Ned Batchelder <ned@nedbatchelder.com> - 2013-11-09 05:24 -0800
      Re: Conditional breakpoints in ceval.c David Froger <david.froger@inria.fr> - 2013-11-12 09:44 +0100

#58891 — Conditional breakpoints in ceval.c

FromDemian Brecht <demianbrecht@gmail.com>
Date2013-11-08 18:03 -0800
SubjectConditional breakpoints in ceval.c
Message-ID<mailman.2274.1383962639.18130.python-list@python.org>
Hi all,

I have an .py file with a simple assignment in it:
foo = 'bar'

Now, I want to set a conditional breakpoint in gdb, breaking on that
assignment (I'm guessing the top of the stack would be breaking on the
LOAD_CONST with a value or 'bar'). How would I go about doing that?

b ceval.c:1368 if [?]

Thanks,

-- 
Demian Brecht
http://demianbrecht.github.com

[toc] | [next] | [standalone]


#58935

FromNed Batchelder <ned@nedbatchelder.com>
Date2013-11-09 05:24 -0800
Message-ID<e4e2892f-76a6-43a8-b59d-42ee01dfa023@googlegroups.com>
In reply to#58891
On Friday, November 8, 2013 9:03:51 PM UTC-5, Demian Brecht wrote:
> Hi all,
> 
> I have an .py file with a simple assignment in it:
> foo = 'bar'
> 
> Now, I want to set a conditional breakpoint in gdb, breaking on that
> assignment (I'm guessing the top of the stack would be breaking on the
> LOAD_CONST with a value or 'bar'). How would I go about doing that?
> 
> b ceval.c:1368 if [?]
> 
> Thanks,
> 
> -- 
> Demian Brecht
> http://demianbrecht.github.com

I don't know how to use gdb the way you want, but it sounds like you are on a fascinating journey of discovery.  What are you trying to learn?  Perhaps we can talk about how the interpreter works.

--Ned.

[toc] | [prev] | [next] | [standalone]


#59164

FromDavid Froger <david.froger@inria.fr>
Date2013-11-12 09:44 +0100
Message-ID<mailman.2436.1384246441.18130.python-list@python.org>
In reply to#58935
Quoting Ned Batchelder (2013-11-09 14:24:34)
> On Friday, November 8, 2013 9:03:51 PM UTC-5, Demian Brecht wrote:
> > Hi all,
> > 
> > I have an .py file with a simple assignment in it:
> > foo = 'bar'
> > 
> > Now, I want to set a conditional breakpoint in gdb, breaking on that
> > assignment (I'm guessing the top of the stack would be breaking on the
> > LOAD_CONST with a value or 'bar'). How would I go about doing that?
> > 
> > b ceval.c:1368 if [?]
> > 
> > Thanks,
> > 
> > -- 
> > Demian Brecht
> > http://demianbrecht.github.com
> 
> I don't know how to use gdb the way you want, but it sounds like you are on a fascinating journey of discovery.  What are you trying to learn?  Perhaps we can talk about how the interpreter works.
> 
> --Ned.
> -- 
> https://mail.python.org/mailman/listinfo/python-list

Hi all,

In the purpose of debugging C/C++ Python extensions, I've been also looking for
a way to put a gdb breakpoint on a Python line file, like this:
    (gdb) b foo.py:47
But I have no idea how this could be implemented.

To break in a C/C++ extension with gdb, on can declare a function, for
example 'Py_DebugTrap' [1], and call it call in the C/C++ code where he/she
want to break, then in gdb:
    (gdb) b Py_DebugTrap

So a altenative to break into Python could be to do the same: wrap the
Py_DebugTrap in a Python module, then in the Python file, call the trap
function, for example:
    import gdbbreak
    gdbbreak.breakpoint_here()
    foo = 'bar'

The function gdbbreak.breakpoint_here() would just call the 'Py_DebugTrap'
function, and then in gdb:
    (gdb) b Py_DebugTrap
    (gdb) next # until foo = 'bar' assignement is reach

(I never try this, be it should work.)

[1] http://joyrex.spc.uchicago.edu/bookshelves/python/cookbook/pythoncook-CHP-16-SECT-8.html

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web