Mailing List Archive

A Certifiable Very Cool Trick
Just a quick note because this is way too cool not to share. When
python.org came back up today, it almost immediately got cpu slammed
(and has been for at least the last 3 hours). I know what's going on
-- it has to do with performance problems in Mailman that in this case
was triggered by a flood of incoming messages to all the mailing
lists. This Mailman problem has been seen by a few other users, but
it's dang hard to track down. Guido, Jeremy, and I got to talking
about what tools we'd like to have to help debug this problem.

My model was gdb's attach feature where you can attach to, stop and
trace through a running external C program. I would love to be able
to do the same thing at the Python level. We started talking about
remote pdb's with threads listening on sockets, etc. (still cool ideas
but more work). I mentioned that I'd love to be able to just get a
traceback of where the program is currently stopped. Even if it hoses
the interpreter afterwards, it would still be incredibly useful.
Guido and I spent some fun after hours hacking time and came up with
the following trick.

[.This is described in terms of gdb, but you might be able to do
something similar with dbx or other Unix and non-Unix debuggers, I
dunno]

First, get the pid of the running Python process. Start up gdb on the
python executable and at the gdb prompt type "attach XXX" where XXX is
the pid. Now, at the gdb prompt, type the following:

(gdb) call PyRun_SimpleString("import sys, traceback; sys.stderr=open('/tmp/tb','w',0); traceback.print_stack()")

Sitting in /tmp/tb will be the stack trace of where the Python program
was when you stopped it! There's reason to believe this will not
always work, and it could seriously confuse your interpreter depending
on where it stops. But every time I've tried it it /does/ work, and
you can even detach the program and let it continue on!

Chris Tismer, somehow I think your stackless Python might either make
this trick harder or much easier :)

makes-this-geek-quiver-with-joy-but-my-mom-would-just-scratch-her-head-ly y'rs,
-Barry
A Certifiable Very Cool Trick [ In reply to ]
From: "Barry A. Warsaw" <bwarsaw@cnri.reston.va.us>


Just a quick note because this is way too cool not to share. When
python.org came back up today, it almost immediately got cpu slammed
(and has been for at least the last 3 hours). I know what's going on
-- it has to do with performance problems in Mailman that in this case
was triggered by a flood of incoming messages to all the mailing
lists. This Mailman problem has been seen by a few other users, but
it's dang hard to track down. Guido, Jeremy, and I got to talking
about what tools we'd like to have to help debug this problem.

My model was gdb's attach feature where you can attach to, stop and
trace through a running external C program. I would love to be able
to do the same thing at the Python level. We started talking about
remote pdb's with threads listening on sockets, etc. (still cool ideas
but more work). I mentioned that I'd love to be able to just get a
traceback of where the program is currently stopped. Even if it hoses
the interpreter afterwards, it would still be incredibly useful.
Guido and I spent some fun after hours hacking time and came up with
the following trick.

[.This is described in terms of gdb, but you might be able to do
something similar with dbx or other Unix and non-Unix debuggers, I
dunno]

First, get the pid of the running Python process. Start up gdb on the
python executable and at the gdb prompt type "attach XXX" where XXX is
the pid. Now, at the gdb prompt, type the following:

(gdb) call PyRun_SimpleString("import sys, traceback;
sys.stderr=open('/tmp/tb','w',0); traceback.print_stack()")

Sitting in /tmp/tb will be the stack trace of where the Python program
was when you stopped it! There's reason to believe this will not
always work, and it could seriously confuse your interpreter depending
on where it stops. But every time I've tried it it /does/ work, and
you can even detach the program and let it continue on!

Chris Tismer, somehow I think your stackless Python might either make
this trick harder or much easier :)

makes-this-geek-quiver-with-joy-but-my-mom-would-just-scratch-her-head-ly y'rs,
-Barry
A Certifiable Very Cool Trick [ In reply to ]
-->"BAW" == Barry A Warsaw <bwarsaw@cnri.reston.va.us> writes:

BAW> My model was gdb's attach feature where you can attach to, stop
BAW> and trace through a running external C program. I would love
BAW> to be able to do the same thing at the Python level. We
BAW> started talking about remote pdb's with threads listening on
BAW> sockets, etc. (still cool ideas but more work).

on a (vaguely) related note, i was talking to Mark Hammond the other
day (hi Mark) about MS's ActiveDebugging(TM) (sp?) stuff.

as i understood it, each interpreter presents a set of COM APIs which
provide an abstract view of stack frames, etc, suitable for use by a
symbolic script debugger. you can thus debug across scripting
languages using a single tool, watching calls between interpreters,
etc etc.

all very cool, and so i started thinking about doing the same thing
for Unix via gdb (for C) and the Python interpreter (what other
languages are there? oh -- ELisp, yeah -- we can do that!)

of course, attaching to a running process should still be possible,
and thus the round-about relationship to the thread.

ahhhhh. now, where's that spare time again?




d
A Certifiable Very Cool Trick [ In reply to ]
From: David Arnold <arnold@dstc.edu.au>

-->"BAW" == Barry A Warsaw <bwarsaw@cnri.reston.va.us> writes:

BAW> My model was gdb's attach feature where you can attach to, stop
BAW> and trace through a running external C program. I would love
BAW> to be able to do the same thing at the Python level. We
BAW> started talking about remote pdb's with threads listening on
BAW> sockets, etc. (still cool ideas but more work).

on a (vaguely) related note, i was talking to Mark Hammond the other
day (hi Mark) about MS's ActiveDebugging(TM) (sp?) stuff.

as i understood it, each interpreter presents a set of COM APIs which
provide an abstract view of stack frames, etc, suitable for use by a
symbolic script debugger. you can thus debug across scripting
languages using a single tool, watching calls between interpreters,
etc etc.

all very cool, and so i started thinking about doing the same thing
for Unix via gdb (for C) and the Python interpreter (what other
languages are there? oh -- ELisp, yeah -- we can do that!)

of course, attaching to a running process should still be possible,
and thus the round-about relationship to the thread.

ahhhhh. now, where's that spare time again?




d
A Certifiable Very Cool Trick [ In reply to ]
From: "Barry A. Warsaw" <bwarsaw@cnri.reston.va.us>


>>>>> "DA" == David Arnold <arnold@dstc.edu.au> writes:

DA> as i understood it, each interpreter presents a set of COM
DA> APIs which provide an abstract view of stack frames, etc,
DA> suitable for use by a symbolic script debugger. you can thus
DA> debug across scripting languages using a single tool, watching
DA> calls between interpreters, etc etc.

Another thing that would be really cool, would be a debugging tool
that could cross the implementation language barrier. E.g. stepping
through Python, I could then drop down into the C or Java at that
point. Having the ability to move between even those two abstraction
levels would be pretty useful. Really cool would be the ability to
also drop into the bytecode level (either under the Java source in the
case of JPython, or between the Python and C code in the case of
CPython).

DA> all very cool, and so i started thinking about doing the same
DA> thing for Unix via gdb (for C) and the Python interpreter
DA> (what other languages are there? oh -- ELisp, yeah -- we can
DA> do that!)

Ah, so our dream of scripting XEmacs with Python isn't so far away...

DA> ahhhhh. now, where's that spare time again?

...or is it? :) Fun to think about at least.

-Barry
A Certifiable Very Cool Trick [ In reply to ]
>>>>> "DA" == David Arnold <arnold@dstc.edu.au> writes:

DA> as i understood it, each interpreter presents a set of COM
DA> APIs which provide an abstract view of stack frames, etc,
DA> suitable for use by a symbolic script debugger. you can thus
DA> debug across scripting languages using a single tool, watching
DA> calls between interpreters, etc etc.

Another thing that would be really cool, would be a debugging tool
that could cross the implementation language barrier. E.g. stepping
through Python, I could then drop down into the C or Java at that
point. Having the ability to move between even those two abstraction
levels would be pretty useful. Really cool would be the ability to
also drop into the bytecode level (either under the Java source in the
case of JPython, or between the Python and C code in the case of
CPython).

DA> all very cool, and so i started thinking about doing the same
DA> thing for Unix via gdb (for C) and the Python interpreter
DA> (what other languages are there? oh -- ELisp, yeah -- we can
DA> do that!)

Ah, so our dream of scripting XEmacs with Python isn't so far away...

DA> ahhhhh. now, where's that spare time again?

...or is it? :) Fun to think about at least.

-Barry