Path: csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!gegeweb.org!de-l.enfer-du-nord.net!feeder1.enfer-du-nord.net!feeder.news-service.com!newsfeed.xs4all.nl!newsfeed6.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.000 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'arguments': 0.05; 'attributes': 0.05; 'exception,': 0.07; 'names.': 0.07; 'raised': 0.07; 'tue': 0.07; 'python': 0.08; 'attribute': 0.09; 'foo': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:80.91.229.12': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'received:lo.gmane.org': 0.09; 'subject:Function': 0.09; 'undefined': 0.09; 'output': 0.11; 'def': 0.12; 'exception': 0.12; 'debugging': 0.14; '"""this': 0.16; '...]': 0.16; 'baz': 0.16; 'docstring': 0.16; 'from:addr:yahoo.com.ar': 0.16; 'occurred.': 0.16; 'read:': 0.16; 'stack': 0.16; 'traceback': 0.16; '(most': 0.16; 'tue,': 0.17; 'occurred': 0.19; 'script.': 0.19; 'trace': 0.19; 'last):': 0.23; 'somehow': 0.23; '"this': 0.25; 'function': 0.25; 'modules': 0.26; 'object': 0.26; 'problem': 0.28; 'subject:?': 0.29; 'import': 0.29; 'instead': 0.29; 'module': 0.30; 'header:X-Complaints-To:1': 0.32; 'does': 0.33; 'to:addr:python-list': 0.33; 'file': 0.34; 'example,': 0.35; 'header:User-Agent:1': 0.35; 'test': 0.35; 'similar': 0.37; 'despite': 0.37; 'sequence': 0.37; 'third-party': 0.37; 'received:org': 0.38; 'but': 0.38; 'subject:: ': 0.38; 'some': 0.38; 'skip:s 20': 0.39; 'called': 0.39; 'header:Mime- Version:1': 0.39; 'to:addr:python.org': 0.39; 'order': 0.62; 'here': 0.66; 'offer': 0.71; 'received:190': 0.74; '-0300,': 0.84; 'cgitb': 0.84; 'genellina': 0.84; 'gabriel': 0.91; 'subject:call': 0.91 X-Injected-Via-Gmane: http://gmane.org/ To: python-list@python.org From: "Gabriel Genellina" Subject: Re: Function call arguments in stack trace? Date: Tue, 07 Jun 2011 23:45:15 -0300 References: <9d344c45-8017-4c80-9a17-bc7accd81047@l26g2000yqm.googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1; format=flowed; delsp=yes Content-Transfer-Encoding: 8bit X-Gmane-NNTP-Posting-Host: 190.2.4.25 User-Agent: Opera Mail/11.11 (Win32) X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.12 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 117 NNTP-Posting-Host: 82.94.164.166 X-Trace: 1307500925 news.xs4all.nl 49180 [::ffff:82.94.164.166]:48798 X-Complaints-To: abuse@xs4all.nl Xref: x330-a1.tempe.blueboxinc.net comp.lang.python:7208 En Tue, 07 Jun 2011 15:09:54 -0300, Dun Peal escribió: > In a stack trace, is it possible to somehow get the arguments with > which each function was called? > > So for example, if function `foo` in module `bar` was called with > arguments `(1, [2])` when it raised an exception, then instead of: > > Traceback (most recent call last): > File "bar.py", line 123, in foo > build_rpms() > > The stack trace would read: > > Traceback (most recent call last): > File "bar.py", line 123, in foo(1, [2]) > build_rpms() > > This would save a lot of debugging time! The cgitb module does exactly that; some third-party modules offer similar functionality, but I don't remember any names. Despite its name, cgitb works with any script. Given this test script: # begin test_traceback.py import cgitb cgitb.enable(format="text") spam = [] def a(x, y): "This is function a" z = x+y return b(z) def b(z, n=3): """This is function b. Its docstring is longer.""" if n!=3: just(to_consume_space) w = c(foo=z*n) return w def c(foo=0, bar=1): "This is function c" baz = foo+bar spam.somenamethatdoesnotexist(foo+bar) anotherglobal("thatdoesnotexisteither") a(10, 20) # end test_traceback.py the output is: AttributeError Python 3.2: d:\apps\Python32\python.exe Tue Jun 7 23:36:36 2011 A problem occurred in a Python script. Here is the sequence of function calls leading up to the error, in the order they occurred. D:\TEMP\test_traceback.py in () 27 baz = foo+bar 28 spam.somenamethatdoesnotexist(foo+bar) 29 anotherglobal("thatdoesnotexisteither") 30 31 a(10, 20) a = D:\TEMP\test_traceback.py in a(x=10, y=20) 7 "This is function a" 8 z = x+y 9 return b(z) 10 11 global b = z = 30 D:\TEMP\test_traceback.py in b(z=30, n=3) 18 just(to_consume_space) 19 20 w = c(foo=z*n) 21 22 return w w undefined global c = foo undefined z = 30 n = 3 D:\TEMP\test_traceback.py in c(foo=90, bar=1) 26 "This is function c" 27 baz = foo+bar 28 spam.somenamethatdoesnotexist(foo+bar) 29 anotherglobal("thatdoesnotexisteither") 30 global spam = [] spam.somenamethatdoesnotexist undefined foo = 90 bar = 1 AttributeError: 'list' object has no attribute 'somenamethatdoesnotexist' [... exception attributes ...] [... original traceback ...] -- Gabriel Genellina