Path: csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!news.albasani.net!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail From: Neil Cerutti Newsgroups: comp.lang.python Subject: Re: Function call arguments in stack trace? Date: 7 Jun 2011 20:29:47 GMT Organization: Norwich University Lines: 47 Message-ID: <957g1rF32aU1@mid.individual.net> References: <9d344c45-8017-4c80-9a17-bc7accd81047@l26g2000yqm.googlegroups.com> <9578lmFl76U1@mid.individual.net> <6c3c9ab9-7880-4988-8258-8f8b2d4d7f72@m21g2000yqc.googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Trace: individual.net 7ZTH2I1J2EU/+/1SBlvLcgSe4eFepHOYIChaiIQRtRnBSPKqFR Cancel-Lock: sha1:4NSnahNJtjrcasfDHacs83lYtLw= User-Agent: slrn/0.9.9p1/mm/ao (Win32) Xref: x330-a1.tempe.blueboxinc.net comp.lang.python:7183 On 2011-06-07, Dun Peal wrote: > On Jun 7, 1:23?pm, Neil Cerutti wrote: >> Use pdb. > > Neil, thanks for the tip; `pdb` is indeed a great debugging > tool. > > Still, it doesn't obviate the need for arguments in the stack > trace. For example: > > 1) Arguments in stack trace can expedite a debugging session, and even > obviate it completely: "Why did `foo()` fail? Oh, because it got `-1` > as its first argument, while I only coded for positive integers!". > 2) In some environments, it's very hard to recreate a rare exception > and analyze it with `pdb`. For instance, on a web application that > emails the stack traces of unhandled exceptions, it's very important > for that stack trace to be as informative as possible, since often > that's the only debugging feedback you will get. > > Hope that makes sense, D. The locals should be in the frame object of the traceback. Here's a sketch of a decorator to print them out before your program bombs: import sys def report_arg_info(fn): def wrapper(*arg, **kw): try: return fn(*arg, **kw) except: frame = sys.exc_info()[2].tb_next.tb_frame print(frame.f_locals) raise return wrapper Use it as usual: @report_arg_info def my_func(bombs) raise ValueError You could log the local arguments instead. -- Neil Cerutti