Line numbers in stack traces

Thomas Lindgren <>
Wed Aug 10 16:40:25 CEST 2005



--- Richard Cameron <> wrote:
> Is there any way to extract enough information from
> a standard erlang  
> stack trace to be able to work out at which line the
> exception was  
> thrown?

I wrote a parse transform that took care of this,
smart_exceptions in jungerl.

Alas, using it in R10 is a hassle since the compiler
warns about generated code (and can't be told to shut
up). And using it has triggered an evil compiler bug,
so perhaps it's not practical anymore. (The compiler
bug probably is fixed by now; I don't recall.)

The key idea is that exceptions are generated only at
certain known points in the code. So the transform
works like this: at every* point where an exception
can be thrown, code is inserted to throw a more
informative exception which indicates the module,
line, reason, involved data and whatnot. 

* Every point I could think of; I missed handling
exceptions thrown when you try to build a binary.

A simple example:

f(a, X) -> g(X).

would become something like this:

f(a,X) -> g(X);
f(T1,T2) -> 
  exit({?MODULE, ?LINE, function_clause, [T1,T2]}).

BIFs were handled by catching exceptions and
rethrowing a more informative one. And so on. Look at
the generated code for details. (The beam compiler
gets rid of redundant code too.)

Having "smart exceptions" has been quite useful for
practical work, but I would prefer an
official/supported solution. That could use the same
technique as above, which is not a huge effort. (It
would be possible to do better too.)

As someone mentioned, adding debugging support
increases object code size (and compile time in this
case). Personally, I have found it well worth the
cost.

Best,
Thomas



		
____________________________________________________
Start your day with Yahoo! - make it your home page 
http://www.yahoo.com/r/hs 
 



More information about the erlang-questions mailing list