Print file name and line number to log

96 Views Asked by At

I would like to print file name and line number to log file, similar to __FILE__ and __LINE__ is SV.

  1. Is it possible?
  2. Can I print the stack, as stack() in SV behaves?

Thanks!

1

There are 1 best solutions below

0
Yuri Tsoglin On

In e, there is no "general" syntax to access module name or line number, but there exists a syntax that can be used in define as macros. For example, you can define a macro like this, to print an expression along with the current line and module name:

define <my'action> "out_with_line_number <exp>" as {
    out("<current_line_num> @<current_module_name>: ", <exp>);
};

Regarding the second question, there exists a predefined global method print_stack_trace().