Is there a _ _ FILE__, _ _ LINE__,__FUNCTION__ macro similar to C in kotlin native?

Are there _ _ FILE__, _ _ LINE__, _ _ Function__ macros similar to C in Kotlin native language? I need them to logger on the Linux system.

Please vote for the feature request https://youtrack.jetbrains.com/issue/KT-34553

In Kotlin/JVM, exception stack traces provide class, function, file, and line info; and some logging frameworks display all that automatically.

(I guess that may be why a Kotlin/Native alternative hasn’t been a priority.)

However, I notice that although kotin.Throwable’s stackTrace property is only available on Kotlin/JVM, there’s a getStackTrace() function on Kotlin/Native — does that help?

1 Like

I think you can implement it “easily” with a compiler plugin.

  1. You define those variables as global variables.
  2. You replace the getter of the global variable in the compiler plugin with the actual call-site data.

Compose does something similar as it needs the call site for decisions about recomposition.

You need IR for this to work, but that should be fine.

It took me a few days to write a proof-of-concept plugin that adds a synthetic parameter to specific functions. This synthetic parameter contains the call site (offset in my case) where that given function call originated from.

There starting point for writing a point is:

My proof-of-concept (based on the article above, pretty far from finished):