Discussion:
Python debugging in gdb
Dov Grobgeld
2012-09-10 09:50:09 UTC
Permalink
I would like to write some glue functions that allow debugging python
code within gdb. We have an embedded environment that in the call
stack calls back and forth between C++ and python multiple times. It
would be great if it was possible to debug this system in a single
environment.

To do this, I would like to define the following gdb commands:

py-break : Create a break point at line in a python file.
py-step: Step the next python statement.
py-next : Run the next python statement.
py-finish: Finish the current python function.

In a way this would create a relationship between python and C similar
to the current difference between step and stepi, where the former
steps in the compiled language and the latter in assembler language.
So for python I would like to have one higher abstraction layer.

(It would make sense to create a dispatcher that does `py-break` on a
python file and `break` on a C++ file so you can always use the same
command to create break points.)

Is this feasible? Can someone give me some ideas and pointers of how
to go about implementing this?

Regards,
Dov
Tom Tromey
2012-09-10 15:04:41 UTC
Permalink
Dov> To do this, I would like to define the following gdb commands:

Dov> py-break : Create a break point at line in a python file.
Dov> py-step: Step the next python statement.
Dov> py-next : Run the next python statement.
Dov> py-finish: Finish the current python function.

Dov> (It would make sense to create a dispatcher that does `py-break` on a
Dov> python file and `break` on a C++ file so you can always use the same
Dov> command to create break points.)

Eventually I'd like to be able to extend the plain gdb commands like
"break" this way.

Dov> Is this feasible? Can someone give me some ideas and pointers of how
Dov> to go about implementing this?

It is definitely feasible. There may still be some ugly parts; if so
please file bug reports, since this is something we would like to work
nicely.

I don't know exactly how you would implement each command -- a lot
depends on the details of the Python interpreter.

In general though I think each of the above commands would be written in
Python and would use gdb's Python Breakpoint API to set low-level
breakpoints at the appropriate points in the Python interpreter. I
think much of the logic would be in the breakpoint's 'stop' method. For
example, for py-next you would want to stop at a specific source line,
but only in the current frame, so the stop method would have to compare
frames.

Tom
Joel Brobecker
2012-09-10 15:09:27 UTC
Permalink
Post by Tom Tromey
Dov> Is this feasible? Can someone give me some ideas and pointers of how
Dov> to go about implementing this?
It is definitely feasible. There may still be some ugly parts; if so
please file bug reports, since this is something we would like to work
nicely.
Wouldn't the "pdb" module already be doing what Dov is trying to do?
--
Joel
Loading...