Skip to content

Commit 42cb643

Browse files
update build_stacktrace
1 parent 524373c commit 42cb643

File tree

1 file changed

+28
-15
lines changed

1 file changed

+28
-15
lines changed

libcxx/src/stacktrace/builder.cpp

Lines changed: 28 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -22,33 +22,46 @@ _LIBCPP_BEGIN_NAMESPACE_STD
2222
namespace __stacktrace {
2323

2424
_LIBCPP_NO_TAIL_CALLS _LIBCPP_NOINLINE void builder::build_stacktrace(size_t skip, size_t max_depth) {
25-
// First get the instruction addresses, populate __entries_
25+
#if defined(_LIBCPP_WIN32API)
26+
// Windows implementation
2627
win_impl dbghelp{*this};
27-
unwind unwind{*this};
2828
dbghelp.collect(skip + 1, max_depth);
29-
unwind.collect(skip + 1, max_depth);
29+
if (!__entries_.size()) {
30+
return;
31+
}
32+
dbghelp.ident_modules();
33+
dbghelp.resolve_lines();
34+
dbghelp.symbolize();
35+
36+
#else
37+
// Non-Windows; assume Unix-like.
38+
39+
// For spawning `addr2line` or similar external process
40+
spawner pspawn{*this};
3041

31-
// (Can't proceed if empty)
42+
// `Unwind.h` or `libunwind.h` often available on Linux/OSX etc.
43+
unwind unwind{*this};
44+
unwind.collect(skip + 1, max_depth);
3245
if (!__entries_.size()) {
3346
return;
3447
}
3548

36-
// Associate addrs with binaries (ELF/MachO/etc.)
49+
# if defined(__APPLE__)
50+
// Specific to MacOS and other Apple SDKs
3751
macos macos{*this};
38-
linux linux{*this};
39-
dbghelp.ident_modules();
4052
macos.ident_modules();
41-
linux.ident_modules();
42-
43-
// Resolve addresses to symbols, filename, linenumber
44-
spawner pspawn{*this};
45-
dbghelp.resolve_lines();
4653
pspawn.resolve_lines();
47-
48-
// Populate missing symbols, if any.
49-
dbghelp.symbolize();
5054
macos.symbolize();
55+
56+
# else
57+
// Linux and other other platforms
58+
linux linux{*this};
59+
linux.ident_modules();
60+
pspawn.resolve_lines();
5161
linux.symbolize();
62+
63+
# endif
64+
#endif
5265
}
5366

5467
} // namespace __stacktrace

0 commit comments

Comments
 (0)