4
4
5
5
#include " flutter/fml/backtrace.h"
6
6
7
- #include < cxxabi.h>
8
- #include < dlfcn.h>
9
- #include < execinfo.h>
10
-
11
7
#include < csignal>
12
8
#include < sstream>
13
9
14
- #if FML_OS_WIN
15
- #include < crtdbg.h>
16
- #include < debugapi.h>
17
- #endif
18
-
10
+ #include " flutter/fml/build_config.h"
19
11
#include " flutter/fml/logging.h"
20
12
#include " flutter/fml/paths.h"
21
13
#include " third_party/abseil-cpp/absl/debugging/symbolize.h"
22
14
15
+ #ifdef FML_OS_WIN
16
+ #include < Windows.h>
17
+ #include < crtdbg.h>
18
+ #include < debugapi.h>
19
+ #else // FML_OS_WIN
20
+ #include < cxxabi.h>
21
+ #include < dlfcn.h>
22
+ #include < execinfo.h>
23
+ #endif // FML_OS_WIN
24
+
23
25
namespace fml {
24
26
25
27
static std::string kKUnknownFrameName = " Unknown" ;
26
28
27
29
static std::string DemangleSymbolName (const std::string& mangled) {
30
+ #if FML_OS_WIN
31
+ return mangled;
32
+ #else
28
33
if (mangled == kKUnknownFrameName ) {
29
34
return kKUnknownFrameName ;
30
35
}
@@ -44,6 +49,7 @@ static std::string DemangleSymbolName(const std::string& mangled) {
44
49
auto demangled_string = std::string{demangled, length};
45
50
free (demangled);
46
51
return demangled_string;
52
+ #endif // FML_OS_WIN
47
53
}
48
54
49
55
static std::string GetSymbolName (void * symbol) {
@@ -55,10 +61,18 @@ static std::string GetSymbolName(void* symbol) {
55
61
return DemangleSymbolName ({name});
56
62
}
57
63
64
+ static int Backtrace (void ** buffer, int size) {
65
+ #if FML_OS_WIN
66
+ return CaptureStackBackTrace (0 , size, buffer, NULL );
67
+ #else
68
+ return ::backtrace (symbols, kMaxFrames );
69
+ #endif // FML_OS_WIN
70
+ }
71
+
58
72
std::string BacktraceHere (size_t offset) {
59
73
constexpr size_t kMaxFrames = 256 ;
60
74
void * symbols[kMaxFrames ];
61
- const auto available_frames = :: backtrace (symbols, kMaxFrames );
75
+ const auto available_frames = Backtrace (symbols, kMaxFrames );
62
76
if (available_frames <= 0 ) {
63
77
return " " ;
64
78
}
@@ -74,12 +88,15 @@ std::string BacktraceHere(size_t offset) {
74
88
static size_t kKnownSignalHandlers [] = {
75
89
SIGABRT, // abort program
76
90
SIGFPE, // floating-point exception
77
- SIGBUS , // bus error
91
+ SIGTERM , // software termination signal
78
92
SIGSEGV, // segmentation violation
93
+ #if !FML_OS_WIN
94
+ SIGBUS, // bus error
79
95
SIGSYS, // non-existent system call invoked
80
96
SIGPIPE, // write on a pipe with no reader
81
97
SIGALRM, // real-time timer expired
82
- SIGTERM, // software termination signal
98
+
99
+ #endif // !FML_OS_WIN
83
100
};
84
101
85
102
static std::string SignalNameToString (int signal) {
@@ -88,18 +105,20 @@ static std::string SignalNameToString(int signal) {
88
105
return " SIGABRT" ;
89
106
case SIGFPE:
90
107
return " SIGFPE" ;
91
- case SIGBUS:
92
- return " SIGBUS" ;
93
108
case SIGSEGV:
94
109
return " SIGSEGV" ;
110
+ case SIGTERM:
111
+ return " SIGTERM" ;
112
+ #if !FML_OS_WIN
113
+ case SIGBUS:
114
+ return " SIGBUS" ;
95
115
case SIGSYS:
96
116
return " SIGSYS" ;
97
117
case SIGPIPE:
98
118
return " SIGPIPE" ;
99
119
case SIGALRM:
100
120
return " SIGALRM" ;
101
- case SIGTERM:
102
- return " SIGTERM" ;
121
+ #endif // !FML_OS_WIN
103
122
};
104
123
return std::to_string (signal );
105
124
}
0 commit comments