[Python-Dev] FW: printing Python stack info from gdb
Daniel Berlin
dan@cgsoftware.com
10 Jun 2001 16:30:24 -0400
"Tim Peters" <tim.one@home.com> writes:
> Fwd'ing this Skip gem from c.l.py, primarily so I can find it again next
> time I'm thrashing on a Unix box. gdb clearly needs to adopt Python as its
> extension language.
HP has patches to do this, actually.
Works quite nicely.
And trust me, i've tried to get them to do it more than once.
As I pointed out to skip, if he can profile gdb and tell me where the
slowness is, it's likely I can make it a ton faster. GDB could use
major optimizations almost everywhere. And i've done quite a lot of
them, they just haven't been reviewed/integrated yet.
--Dan
C++ support maintainer - GDB
DWARF2 reader person - GDB
Symbol table patch submitting weirdo - GDB
etc
>
> but-then-what-doesn't-ly y'rs - tim
>
> -----Original Message-----
> From: python-list-admin@python.org
> [mailto:python-list-admin@python.org]On Behalf Of Skip Montanaro
> Sent: Saturday, June 09, 2001 12:31 AM
> To: python-list@python.org
> Subject: printing Python stack info from gdb
>
>
>>From time to time I've wanted to be able to print the Python stack from gdb.
> Today I broke down and spent some time actually implementing something.
>
> set $__trimpath = 1
> define ppystack
> set $__fr = 0
> select-frame $__fr
> while !($pc > Py_Main && $pc < Py_GetArgcArgv)
> if $pc > eval_code2 && $pc < set_exc_info
> set $__fn = PyString_AsString(co->co_filename)
> set $__n = PyString_AsString(co->co_name)
> if $__n[0] == '?'
> set $__n = "<module code>"
> end
> if $__trimpath
> set $__f = strrchr($__fn, '/')
> if $__f
> set $__fn = $__f + 1
> end
> end
> printf "%s (%d): %s\n", $__fn, f->f_lineno, $__n
> end
> set $__fr = $__fr + 1
> select-frame $__fr
> end
> select-frame 0
> end
>
> Output looks like this (and dribbles out *quite slowly*):
>
> Text_Editor.py (147): apply_tag
> Text_Editor.py (152): apply_tag_by_name
> Script_GUI.py (302): push_help
> Script_GUI.py (113): put_help
> Script_GUI.py (119): focus_enter
> Signal.py (34): handle_signal
> Script_GUI.py (324): main
> Script_GUI.py (338): <module code>
>
> If you don't want to trim the paths from the filenames, set $__trimpath to
> 0.
>
> Warning: I've only tried this with a very recent CVS version of Python on a
> PIII-based Linux system with an interpreter compiled using gcc. I rely on
> the ordering of functions within the while loop to detect when to exit the
> loop and when the frame I'm examining is an eval_code2 frame. I'm sure
> there are plenty of people out there with more gdb experience than me. I
> welcome any feedback on ways to improve this little bit of code.
>
> --
> Skip Montanaro (skip@pobox.com)
> (847)971-7098
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>
>
> _______________________________________________
> Python-Dev mailing list
> Python-Dev@python.org
> http://mail.python.org/mailman/listinfo/python-dev
--
"I saw a man with a wooden leg, and a real foot.
"-Steven Wright