[erlang-questions] How to get the line number of current executable code?
Sat Aug 16 20:19:12 CEST 2008
Ahmed Ali wrote:
> Hi Richard,
> How about if I compiled the source with debugging enabled? Isn't this
> information supposed to be there (along with function name and other
The problem is that there is no direct line-for-line mapping between the
abstract code in the debugging information, and the executing beam code.
The beam code does contain the info about the current function, but no
line numbers. Using a combination of the two, you could find the line
number for the current function, but figuring out the actual line
within that function (given the current point in the beam code) could
only be approximated using heuristics.
If you're actually running in interpreted mode (debugging mode), you
do get the current line, but it's a couple of orders of magmitude
slower, so you don't want to do that for all your code.
I hope some day someone will find the time to make the compiler
propagate the line number information into a mapping table that could
be included in the beam file at all times, even if the file was not
compiled with debugging enabled. That would make it possible to give
much nicer stacktraces.
More information about the erlang-questions