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 < execinfo.h>
21
+ #endif // FML_OS_WIN
22
+
23
23
namespace fml {
24
24
25
25
static std::string kKUnknownFrameName = " Unknown" ;
26
26
27
- static std::string DemangleSymbolName (const std::string& mangled) {
28
- if (mangled == kKUnknownFrameName ) {
29
- return kKUnknownFrameName ;
30
- }
31
-
32
- int status = 0 ;
33
- size_t length = 0 ;
34
- char * demangled = __cxxabiv1::__cxa_demangle (
35
- mangled.data (), // mangled name
36
- nullptr , // output buffer (malloc-ed if nullptr)
37
- &length, // demangled length
38
- &status);
39
-
40
- if (demangled == nullptr || status != 0 ) {
41
- return mangled;
42
- }
43
-
44
- auto demangled_string = std::string{demangled, length};
45
- free (demangled);
46
- return demangled_string;
47
- }
48
-
49
27
static std::string GetSymbolName (void * symbol) {
50
28
char name[1024 ];
51
29
if (!absl::Symbolize (symbol, name, sizeof (name))) {
52
30
return kKUnknownFrameName ;
53
31
}
32
+ return name;
33
+ }
54
34
55
- return DemangleSymbolName ({name});
35
+ static int Backtrace (void ** symbols, int size) {
36
+ #if FML_OS_WIN
37
+ return CaptureStackBackTrace (0 , size, symbols, NULL );
38
+ #else
39
+ return ::backtrace (symbols, size);
40
+ #endif // FML_OS_WIN
56
41
}
57
42
58
43
std::string BacktraceHere (size_t offset) {
59
44
constexpr size_t kMaxFrames = 256 ;
60
45
void * symbols[kMaxFrames ];
61
- const auto available_frames = :: backtrace (symbols, kMaxFrames );
46
+ const auto available_frames = Backtrace (symbols, kMaxFrames );
62
47
if (available_frames <= 0 ) {
63
48
return " " ;
64
49
}
65
50
51
+ // Exclude here.
52
+ offset += 2 ;
53
+
66
54
std::stringstream stream;
67
- for (int i = 1 + offset; i < available_frames; ++i) {
68
- stream << " Frame " << i - 1 - offset << " : " << symbols[i] << " "
55
+ for (int i = offset; i < available_frames; ++i) {
56
+ stream << " Frame " << i - offset << " : " << symbols[i] << " "
69
57
<< GetSymbolName (symbols[i]) << std::endl;
70
58
}
71
59
return stream.str ();
@@ -74,12 +62,14 @@ std::string BacktraceHere(size_t offset) {
74
62
static size_t kKnownSignalHandlers [] = {
75
63
SIGABRT, // abort program
76
64
SIGFPE, // floating-point exception
77
- SIGBUS , // bus error
65
+ SIGTERM , // software termination signal
78
66
SIGSEGV, // segmentation violation
67
+ #if !FML_OS_WIN
68
+ SIGBUS, // bus error
79
69
SIGSYS, // non-existent system call invoked
80
70
SIGPIPE, // write on a pipe with no reader
81
71
SIGALRM, // real-time timer expired
82
- SIGTERM, // software termination signal
72
+ # endif // !FML_OS_WIN
83
73
};
84
74
85
75
static std::string SignalNameToString (int signal) {
@@ -88,18 +78,20 @@ static std::string SignalNameToString(int signal) {
88
78
return " SIGABRT" ;
89
79
case SIGFPE:
90
80
return " SIGFPE" ;
91
- case SIGBUS:
92
- return " SIGBUS" ;
93
81
case SIGSEGV:
94
82
return " SIGSEGV" ;
83
+ case SIGTERM:
84
+ return " SIGTERM" ;
85
+ #if !FML_OS_WIN
86
+ case SIGBUS:
87
+ return " SIGBUS" ;
95
88
case SIGSYS:
96
89
return " SIGSYS" ;
97
90
case SIGPIPE:
98
91
return " SIGPIPE" ;
99
92
case SIGALRM:
100
93
return " SIGALRM" ;
101
- case SIGTERM:
102
- return " SIGTERM" ;
94
+ #endif // !FML_OS_WIN
103
95
};
104
96
return std::to_string (signal );
105
97
}
0 commit comments