Chromium Code Reviews| Index: src/checks.cc |
| diff --git a/src/checks.cc b/src/checks.cc |
| index 7108d18892e37efd8b3e80ede0d539f408c74768..d2a107c227694646c35c0538f26fffdd80cf3921 100644 |
| --- a/src/checks.cc |
| +++ b/src/checks.cc |
| @@ -25,11 +25,48 @@ |
| // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| -#include <stdarg.h> |
| +#include "checks.h" |
| -#include "v8.h" |
| +#if V8_LIBC_GLIBC || V8_OS_BSD |
|
Michael Achenbach
2013/09/23 11:12:50
Does that include !defined(__UCLIBC__)?
Benedikt Meurer
2013/09/23 11:26:40
Jep, our V8_LIBC_* are strict. I.e. V8_LIBC_GLIBC
|
| +# include <cxxabi.h> |
| +# include <execinfo.h> |
| +#endif // V8_LIBC_GLIBC || V8_OS_BSD |
| +#include <stdio.h> |
| #include "platform.h" |
| +#include "v8.h" |
| + |
| + |
| +// Attempts to dump a backtrace (if supported). |
| +static V8_INLINE void DumpBacktrace() { |
| +#if V8_LIBC_GLIBC || V8_OS_BSD |
| + void* trace[100]; |
| + int size = backtrace(trace, ARRAY_SIZE(trace)); |
| + char** symbols = backtrace_symbols(trace, size); |
| + i::OS::PrintError("\n==== C stack trace ===============================\n\n"); |
| + if (size == 0) { |
| + i::OS::PrintError("(empty)\n"); |
| + } else if (symbols == NULL) { |
| + i::OS::PrintError("(no symbols)\n"); |
| + } else { |
| + for (int i = 1; i < size; ++i) { |
| + i::OS::PrintError("%2d: ", i); |
| + char mangled[201]; |
| + if (sscanf(symbols[i], "%*[^(]%*[(]%200[^)+]", mangled) == 1) { // NOLINT |
| + int status; |
| + size_t length; |
| + char* demangled = abi::__cxa_demangle(mangled, NULL, &length, &status); |
| + i::OS::PrintError("%s\n", demangled != NULL ? demangled : mangled); |
| + free(demangled); |
| + } else { |
| + i::OS::PrintError("??\n"); |
| + } |
| + } |
| + } |
| + free(symbols); |
| +#endif // V8_LIBC_GLIBC || V8_OS_BSD |
| +} |
| + |
| // Contains protection against recursive calls (faults while handling faults). |
| extern "C" void V8_Fatal(const char* file, int line, const char* format, ...) { |
| @@ -43,7 +80,8 @@ extern "C" void V8_Fatal(const char* file, int line, const char* format, ...) { |
| i::OS::VPrintError(format, arguments); |
| va_end(arguments); |
| i::OS::PrintError("\n#\n"); |
| - i::OS::DumpBacktrace(); |
| + DumpBacktrace(); |
| + fflush(stderr); |
|
Michael Achenbach
2013/09/23 11:12:50
Why can that not stay within DumpBacktrace()?
Benedikt Meurer
2013/09/23 11:26:40
Because we should flush stderr on either case.
|
| i::OS::Abort(); |
| } |