-
-
Notifications
You must be signed in to change notification settings - Fork 633
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1626 from mc-server/StackTraceOnFailure
Stack trace on failure
- Loading branch information
Showing
9 changed files
with
105 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
|
||
// StackTrace.cpp | ||
|
||
// Implements the functions to print current stack traces | ||
|
||
#include "Globals.h" | ||
#include "StackTrace.h" | ||
#ifdef _WIN32 | ||
#include "../StackWalker.h" | ||
#else | ||
#include <execinfo.h> | ||
#endif | ||
|
||
|
||
|
||
|
||
|
||
void PrintStackTrace(void) | ||
{ | ||
#ifdef _WIN32 | ||
// Reuse the StackWalker from the LeakFinder project already bound to MCS | ||
// Define a subclass of the StackWalker that outputs everything to stdout | ||
class PrintingStackWalker : | ||
public StackWalker | ||
{ | ||
virtual void OnOutput(LPCSTR szText) override | ||
{ | ||
puts(szText); | ||
} | ||
} sw; | ||
sw.ShowCallstack(); | ||
#else | ||
// Use the backtrace() function to get and output the stackTrace: | ||
// Code adapted from http://stackoverflow.com/questions/77005/how-to-generate-a-stacktrace-when-my-gcc-c-app-crashes | ||
void * stackTrace[30]; | ||
size_t numItems = backtrace(stackTrace, ARRAYCOUNT(stackTrace)); | ||
backtrace_symbols_fd(stackTrace, numItems, STDERR_FILENO); | ||
#endif | ||
} | ||
|
||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
|
||
// StackTrace.h | ||
|
||
// Declares the functions to print current stack trace | ||
|
||
|
||
|
||
|
||
|
||
/** Prints the stacktrace for the current thread. */ | ||
extern void PrintStackTrace(void); | ||
|
||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters