# Is there a \_\_ FILE\_\_, \_\_ LINE\_\_, \_\_FUNCTION\_\_ macro similar to C in kotlin native?

**URL:** <https://discuss.kotlinlang.org/t/is-there-a-file-line-function-macro-similar-to-c-in-kotlin-native/24205>\
**Category:** Native\
**Created:** [February 17, 2022, 7:40am UTC](https://discuss.kotlinlang.org/t/is-there-a-file-line-function-macro-similar-to-c-in-kotlin-native/24205 "2022-02-17T07:40:22Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![xunanmu](https://avatars.discourse-cdn.com/v4/letter/x/3ec8ea/32.png) [@xunanmu](https://discuss.kotlinlang.org/u/xunanmu)\
**Post date:** [February 17, 2022, 7:40am UTC](https://discuss.kotlinlang.org/t/is-there-a-file-line-function-macro-similar-to-c-in-kotlin-native/24205/1 "2022-02-17T07:40:22Z")

</div>

Are there \_ \_ FILE\_\_, \_ \_ LINE\_\_, \_ \_ Function\_\_ macros similar to C in Kotlin native language? I need them to logger on the Linux system.

---

<div class="post-metadata">

**Author:** ![Alexey.Belkov](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.kotlinlang.org/alexey.belkov/32/5215_2.png) [@Alexey.Belkov](https://discuss.kotlinlang.org/u/Alexey.Belkov)\
**Post date:** [February 17, 2022, 7:42am UTC](https://discuss.kotlinlang.org/t/is-there-a-file-line-function-macro-similar-to-c-in-kotlin-native/24205/2 "2022-02-17T07:42:05Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![gidds](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.kotlinlang.org/gidds/32/10865_2.png) [@gidds](https://discuss.kotlinlang.org/u/gidds)\
**Post date:** [February 19, 2022, 4:07pm UTC](https://discuss.kotlinlang.org/t/is-there-a-file-line-function-macro-similar-to-c-in-kotlin-native/24205/3 "2022-02-19T16:07:17Z")

</div>

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`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-throwable/)’s [`stackTrace`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/stack-trace.html) property is only available on Kotlin/JVM, there’s a [`getStackTrace()`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-throwable/get-stack-trace.html) function on Kotlin/Native — does that help?

---

<div class="post-metadata">

**Author:** ![tothiz](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.kotlinlang.org/tothiz/32/10355_2.png) [@tothiz](https://discuss.kotlinlang.org/u/tothiz)\
**Post date:** [February 22, 2022, 11:09am UTC](https://discuss.kotlinlang.org/t/is-there-a-file-line-function-macro-similar-to-c-in-kotlin-native/24205/4 "2022-02-22T11:09:24Z")

</div>

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:

> **[Writing Your Second Kotlin Compiler Plugin, Part 1 — Project Setup](https://blog.bnorm.dev/writing-your-second-compiler-plugin-part-1)**
>
> Project Setup

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

> **[GitHub - toth-istvan-zoltan/kotlin-compiler-plugin-poc](https://github.com/toth-istvan-zoltan/kotlin-compiler-plugin-poc)**
>
> Contribute to toth-istvan-zoltan/kotlin-compiler-plugin-poc development by creating an account on GitHub.

---

<div class="post-metadata">

**Author:** ![zachklipp](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.kotlinlang.org/zachklipp/32/7788_2.png) [@zachklipp](https://discuss.kotlinlang.org/u/zachklipp)\
**Post date:** [November 1, 2024, 8:58pm UTC](https://discuss.kotlinlang.org/t/is-there-a-file-line-function-macro-similar-to-c-in-kotlin-native/24205/5 "2024-11-01T20:58:12Z")

</div>

Jake Wharton built a library for this: [GitHub - JakeWharton/cite: A Kotlin compiler plugin for embedding information about the file being compiled](https://github.com/JakeWharton/cite)
