-
Notifications
You must be signed in to change notification settings - Fork 6k
Add Windows support for //flutter/fml/backtrace.h
#36202
Changes from 1 commit
760e866
6b26b25
aa92903
1d5b4fc
09649c1
dca3616
dba4017
a5b212c
4fe24c3
f67dcf6
393233e
edfe8c1
30105e7
51eaf5d
8df181b
6d5f7c2
a5a124a
763d211
987eee5
d6c28d9
20b6dc4
ce81ec5
a4f3850
b6c657e
a99f0dc
24b2aa5
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||
|---|---|---|---|---|
|
|
@@ -4,27 +4,32 @@ | |||
|
|
||||
| #include "flutter/fml/backtrace.h" | ||||
|
|
||||
| #include <cxxabi.h> | ||||
| #include <dlfcn.h> | ||||
| #include <execinfo.h> | ||||
|
|
||||
| #include <csignal> | ||||
| #include <sstream> | ||||
|
|
||||
| #if FML_OS_WIN | ||||
| #include <crtdbg.h> | ||||
| #include <debugapi.h> | ||||
| #endif | ||||
|
|
||||
| #include "flutter/fml/build_config.h" | ||||
| #include "flutter/fml/logging.h" | ||||
| #include "flutter/fml/paths.h" | ||||
| #include "third_party/abseil-cpp/absl/debugging/symbolize.h" | ||||
|
|
||||
| #ifdef FML_OS_WIN | ||||
| #include <Windows.h> | ||||
| #include <crtdbg.h> | ||||
| #include <debugapi.h> | ||||
| #else // FML_OS_WIN | ||||
| #include <cxxabi.h> | ||||
| #include <dlfcn.h> | ||||
| #include <execinfo.h> | ||||
| #endif // FML_OS_WIN | ||||
|
|
||||
| namespace fml { | ||||
|
|
||||
| static std::string kKUnknownFrameName = "Unknown"; | ||||
|
|
||||
| static std::string DemangleSymbolName(const std::string& mangled) { | ||||
|
||||
| #if FML_OS_WIN | ||||
|
||||
| return mangled; | ||||
| #else | ||||
| if (mangled == kKUnknownFrameName) { | ||||
| return kKUnknownFrameName; | ||||
| } | ||||
|
|
@@ -44,6 +49,7 @@ static std::string DemangleSymbolName(const std::string& mangled) { | |||
| auto demangled_string = std::string{demangled, length}; | ||||
| free(demangled); | ||||
| return demangled_string; | ||||
| #endif // FML_OS_WIN | ||||
| } | ||||
|
|
||||
| static std::string GetSymbolName(void* symbol) { | ||||
|
|
@@ -55,10 +61,18 @@ static std::string GetSymbolName(void* symbol) { | |||
| return DemangleSymbolName({name}); | ||||
| } | ||||
|
|
||||
| static int Backtrace(void** symbols, int size) { | ||||
| #if FML_OS_WIN | ||||
| return CaptureStackBackTrace(0, size, symbols, NULL); | ||||
| #else | ||||
| return ::backtrace(symbols, size); | ||||
| #endif // FML_OS_WIN | ||||
| } | ||||
|
|
||||
| std::string BacktraceHere(size_t offset) { | ||||
| constexpr size_t kMaxFrames = 256; | ||||
| void* symbols[kMaxFrames]; | ||||
| const auto available_frames = ::backtrace(symbols, kMaxFrames); | ||||
| const auto available_frames = Backtrace(symbols, kMaxFrames); | ||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should/could we use abseil's
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It looks nice! I'm replacing with this. I'll check output on linux...
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I also find
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Source code (prototype): moko256@3ca3f10 Linux: |
||||
| if (available_frames <= 0) { | ||||
| return ""; | ||||
| } | ||||
|
|
@@ -74,12 +88,15 @@ std::string BacktraceHere(size_t offset) { | |||
| static size_t kKnownSignalHandlers[] = { | ||||
| SIGABRT, // abort program | ||||
| SIGFPE, // floating-point exception | ||||
| SIGBUS, // bus error | ||||
| SIGTERM, // software termination signal | ||||
| SIGSEGV, // segmentation violation | ||||
| #if !FML_OS_WIN | ||||
| SIGBUS, // bus error | ||||
| SIGSYS, // non-existent system call invoked | ||||
| SIGPIPE, // write on a pipe with no reader | ||||
| SIGALRM, // real-time timer expired | ||||
| SIGTERM, // software termination signal | ||||
|
|
||||
|
||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Without this line, the formatter makes additional whitespace to the comment below.
SIGALRM, // real-time timer expired
#endif // !FML_OS_WIN
// Here ^^^Should we keep this line to remove these space, or remove this line?
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -19,18 +19,21 @@ TEST(BacktraceTest, CanGatherBacktrace) { | |
| auto trace = BacktraceHere(0); | ||
| ASSERT_GT(trace.size(), 0u); | ||
| ASSERT_NE(trace.find("Frame 0"), std::string::npos); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm curious, could these verify that
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. On master, the frame 0 of offset 0 is actually
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Some CI tests seems to run without symbols. I added skipping the test
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I tried to make all CIs pass, but only on |
||
| std::cout << trace << std::endl; | ||
|
||
| } | ||
|
|
||
| { | ||
| auto trace = BacktraceHere(1); | ||
| ASSERT_GT(trace.size(), 0u); | ||
| ASSERT_NE(trace.find("Frame 0"), std::string::npos); | ||
| std::cout << trace << std::endl; | ||
| } | ||
|
|
||
| { | ||
| auto trace = BacktraceHere(2); | ||
| ASSERT_GT(trace.size(), 0u); | ||
| ASSERT_NE(trace.find("Frame 0"), std::string::npos); | ||
| std::cout << trace << std::endl; | ||
| } | ||
| } | ||
|
|
||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.