@@ -22,33 +22,46 @@ _LIBCPP_BEGIN_NAMESPACE_STD
22
22
namespace __stacktrace {
23
23
24
24
_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
26
27
win_impl dbghelp{*this };
27
- unwind unwind{*this };
28
28
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 };
30
41
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);
32
45
if (!__entries_.size ()) {
33
46
return ;
34
47
}
35
48
36
- // Associate addrs with binaries (ELF/MachO/etc.)
49
+ # if defined(__APPLE__)
50
+ // Specific to MacOS and other Apple SDKs
37
51
macos macos{*this };
38
- linux linux{*this };
39
- dbghelp.ident_modules ();
40
52
macos.ident_modules ();
41
- linux.ident_modules ();
42
-
43
- // Resolve addresses to symbols, filename, linenumber
44
- spawner pspawn{*this };
45
- dbghelp.resolve_lines ();
46
53
pspawn.resolve_lines ();
47
-
48
- // Populate missing symbols, if any.
49
- dbghelp.symbolize ();
50
54
macos.symbolize ();
55
+
56
+ # else
57
+ // Linux and other other platforms
58
+ linux linux{*this };
59
+ linux.ident_modules ();
60
+ pspawn.resolve_lines ();
51
61
linux.symbolize ();
62
+
63
+ # endif
64
+ #endif
52
65
}
53
66
54
67
} // namespace __stacktrace
0 commit comments