Conditional breakpoints in ceval.c

D

Demian Brecht

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,
 
N

Ned Batchelder

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,

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.
 
D

David Froger

Quoting Ned Batchelder (2013-11-09 14:24:34)
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,

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.

Hi all,

In the purpose of debugging C/C++ Python extensions, I've been also lookingfor
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,989
Messages
2,570,207
Members
46,782
Latest member
ThomasGex

Latest Threads

Top