Integrate backtrace refactoring and fixes for libunwind#192
Integrate backtrace refactoring and fixes for libunwind#192kinke merged 11 commits intoldc-developers:ldcfrom
Conversation
This makes it reusable by other backtrace providers, and just generally makes the code easier to follow.
So that it can be called from another overload of `traceHandlerOpApplyImpl`.
The execinfo functionality really only concerns itself with backtrace, which provide addresses and function names. However, the general ability to iterate over locations and fill them with file/line informations, as well as the utilities tied to it (e.g. TraceInfoBuffer) can be used by other implementations.
|
Thanks! Had to follow-up with a little fixup: diff --git a/src/core/internal/backtrace/dwarf.d b/src/core/internal/backtrace/dwarf.d
index 76d5b4d3..4775c61b 100644
--- a/src/core/internal/backtrace/dwarf.d
+++ b/src/core/internal/backtrace/dwarf.d
@@ -52,6 +52,13 @@ module core.internal.backtrace.dwarf;
import core.internal.execinfo;
import core.internal.string;
+version (DRuntime_Use_Libunwind)
+ private enum hasLibunwind = true;
+else
+ private enum hasLibunwind = false;
+
+static if (hasExecinfo || hasLibunwind):
+
version (OSX)
version = Darwin;
else version (iOS)
@@ -165,6 +172,9 @@ static if (hasExecinfo)
import core.stdc.stdio : snprintf;
import core.sys.posix.stdlib : free;
+ const char** frameList = backtrace_symbols(callstack.ptr, cast(int) callstack.length);
+ scope(exit) free(cast(void*) frameList);
+
auto image = Image.openSelf();
// find address -> file, line mapping using dwarf debug_line
diff --git a/src/core/internal/backtrace/libunwind.d b/src/core/internal/backtrace/libunwind.d
index fff25bb1..b0fd6ec2 100644
--- a/src/core/internal/backtrace/libunwind.d
+++ b/src/core/internal/backtrace/libunwind.d
@@ -181,6 +181,7 @@ else version (AArch64)
version (linux)
{
+ import core.stdc.config : c_ulong;
import core.sys.posix.signal : sigset_t, stack_t;
// libunwind has some special tweaking to reduce
@@ -226,6 +227,8 @@ else version (ARM)
}
else
{
+ import core.stdc.config : c_ulong;
+
struct unw_tdep_context_t
{
c_ulong[16] regs;There are still compile errors for Android wrt. missing Should the compiler predefine Edit: Oh and does the C compiler need an explicit |
I was planning on patching it in the package until it's fully tested and upstreamed, but that works too. For reference, this is what I have for DMD (it's using the old implementation, before I dropped non-LLVM libunwind). But since Alpine is the main (only?) target for Musl at the moment, might as well do it in LDC.
I don't know. But since I'm patching the config file anyway, I can take care of that when I update the packages. |
So what's the |
As mentioned in the module DDOC, those bindings are only intended to be used internally for the backtracing code, hence only a couple functions and the related types were added.
libunwind is a portable, lightweight, widely adopted library to unwind the stack. It is part of GCC via libiberty, and LLVM as well. It is an alternative to the `backtrace` approach, which is not always available, e.g. Musl libc does not provide a `backtrace` implementation, and the alternative, libexecinfo, is known to have some bugs. This is currently hidden behind a version, meaning only packagers or power users will get access to it, so it can be properly tested.
c3c0b92 to
302f9a0
Compare
Cherry picked from the wrong branch 🤦
Fixed: I needed to add the skip code in |
This idea was suggested during the review of the new libunwind feature, and is already used in LDC. Thanks to the recent refactoring, we can improve on LDC's version by skipping the double demangling/iteration.
302f9a0 to
b1e8e33
Compare
|
Okay, I've pushed 2 new commits. |
|
@kinke : Thanks! Anything else you need from my side ? Are you interested in upstreaming the additional commits ? |
I'll do it at one point unless you're keen on cherry-picking it yourself. ;)
I'm now predefining the version and linking |
822b767 to
5a41c0b
Compare
This cherry-picks commits from the following PRs, in order:
(not merged yet)