digitalmars.D.learn - BetterC stack traces?
- IchorDev (5/5) Sep 04 2022 I'm trying to implement a custom exception system in BetterC.
- Paul Backus (4/9) Sep 04 2022 You can use `libunwind` for this:
- IchorDev (9/12) Sep 05 2022 Ah, I'm actually trying to create my own implementation of this,
- Paul Backus (3/11) Sep 05 2022 I think this is what you are looking for:
- Paul Backus (14/26) Sep 05 2022 Digging in a little deeper, it looks like the druntime
- IchorDev (4/9) Sep 06 2022 It even uses libunwind, it seems!
I'm trying to implement a custom exception system in BetterC. Does anyone know how I'd go about getting a stack trace so that I can print it to stdout? :) I was thinking of utilising UDAs & `__LINE__` but it turns out that UDAs don't let you inject code, which is a shame!
Sep 04 2022
On Sunday, 4 September 2022 at 17:43:01 UTC, IchorDev wrote:I'm trying to implement a custom exception system in BetterC. Does anyone know how I'd go about getting a stack trace so that I can print it to stdout? :) I was thinking of utilising UDAs & `__LINE__` but it turns out that UDAs don't let you inject code, which is a shame!You can use `libunwind` for this: https://www.nongnu.org/libunwind/ It's a C library, but it should work for D too.
Sep 04 2022
On Sunday, 4 September 2022 at 18:49:37 UTC, Paul Backus wrote:You can use `libunwind` for this: https://www.nongnu.org/libunwind/ It's a C library, but it should work for D too.Ah, I'm actually trying to create my own implementation of this, so the goal would be to not rely on a dependency. I can't exactly make head nor tail of the library's source other than that it seems to have a unique implementation on each processor/OS type. I'm sure there must be something hidden in `core.internal.` for this. I'll look at the implementation of `rt.trace` and see if I can find anything.
Sep 05 2022
On Monday, 5 September 2022 at 10:47:38 UTC, IchorDev wrote:Ah, I'm actually trying to create my own implementation of this, so the goal would be to not rely on a dependency. I can't exactly make head nor tail of the library's source other than that it seems to have a unique implementation on each processor/OS type. I'm sure there must be something hidden in `core.internal.` for this. I'll look at the implementation of `rt.trace` and see if I can find anything.I think this is what you are looking for: https://github.com/dlang/dmd/blob/master/druntime/src/rt/deh.d
Sep 05 2022
On Monday, 5 September 2022 at 12:07:35 UTC, Paul Backus wrote:On Monday, 5 September 2022 at 10:47:38 UTC, IchorDev wrote:Digging in a little deeper, it looks like the druntime implementation ultimately depends on the [C++ exception handling ABI][1], via its platform-independent library interface. Bindings are defined in [`core.internal.backtrace.unwind`][2]. There is also what looks like a from-scratch implementation of table-based exception handling in [`rt.deh_win64_posix`][3], but according to a comment it is no longer used. Might be educational to read, though. [1]: https://itanium-cxx-abi.github.io/cxx-abi/abi-eh.html [2]: https://github.com/dlang/dmd/blob/master/druntime/src/core/internal/backtrace/unwind.d [3]: https://github.com/dlang/dmd/blob/master/druntime/src/rt/deh_win64_posix.dAh, I'm actually trying to create my own implementation of this, so the goal would be to not rely on a dependency. I can't exactly make head nor tail of the library's source other than that it seems to have a unique implementation on each processor/OS type. I'm sure there must be something hidden in `core.internal.` for this. I'll look at the implementation of `rt.trace` and see if I can find anything.I think this is what you are looking for: https://github.com/dlang/dmd/blob/master/druntime/src/rt/deh.d
Sep 05 2022
On Monday, 5 September 2022 at 12:35:10 UTC, Paul Backus wrote:Digging in a little deeper, it looks like the druntime implementation ultimately depends on the C++ exception handling ABI, via its platform-independent library interface. Bindings are defined in `core.internal.backtrace.unwind` ...It even uses libunwind, it seems! [https://github.com/dlang/dmd/blob/master/druntime/src/core/internal/backtrace/handler.d](https://github.com/dlang/dmd/blob/master/druntime/src/core/internal/backtrace/handler.d) Thanks for the pointers, too. :)
Sep 06 2022