OLD | NEW |
1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 the V8 project authors. All rights reserved. |
2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
4 // met: | 4 // met: |
5 // | 5 // |
6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
(...skipping 10 matching lines...) Expand all Loading... |
21 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | 21 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | 22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | 23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
27 | 27 |
28 #ifndef V8_PLATFORM_POSIX_H_ | 28 #ifndef V8_PLATFORM_POSIX_H_ |
29 #define V8_PLATFORM_POSIX_H_ | 29 #define V8_PLATFORM_POSIX_H_ |
30 | 30 |
| 31 #if !defined(ANDROID) |
31 #include <cxxabi.h> | 32 #include <cxxabi.h> |
| 33 #endif |
32 #include <stdio.h> | 34 #include <stdio.h> |
33 | 35 |
34 #include "platform.h" | 36 #include "platform.h" |
35 | 37 |
36 namespace v8 { | 38 namespace v8 { |
37 namespace internal { | 39 namespace internal { |
38 | 40 |
39 // Used by platform implementation files during OS::PostSetUp(). | 41 // Used by platform implementation files during OS::PostSetUp(). |
40 void POSIXPostSetUp(); | 42 void POSIXPostSetUp(); |
41 | 43 |
42 // Used by platform implementation files during OS::DumpBacktrace() | 44 // Used by platform implementation files during OS::DumpBacktrace() |
43 // and OS::StackWalk(). | 45 // and OS::StackWalk(). |
44 template<int (*backtrace)(void**, int), | 46 template<int (*backtrace)(void**, int), |
45 char** (*backtrace_symbols)(void* const*, int)> | 47 char** (*backtrace_symbols)(void* const*, int)> |
46 struct POSIXBacktraceHelper { | 48 struct POSIXBacktraceHelper { |
47 static void DumpBacktrace() { | 49 static void DumpBacktrace() { |
48 void* trace[100]; | 50 void* trace[100]; |
49 int size = backtrace(trace, ARRAY_SIZE(trace)); | 51 int size = backtrace(trace, ARRAY_SIZE(trace)); |
50 char** symbols = backtrace_symbols(trace, size); | 52 char** symbols = backtrace_symbols(trace, size); |
51 fprintf(stderr, "\n==== C stack trace ===============================\n\n"); | 53 fprintf(stderr, "\n==== C stack trace ===============================\n\n"); |
52 if (size == 0) { | 54 if (size == 0) { |
53 fprintf(stderr, "(empty)\n"); | 55 fprintf(stderr, "(empty)\n"); |
54 } else if (symbols == NULL) { | 56 } else if (symbols == NULL) { |
55 fprintf(stderr, "(no symbols)\n"); | 57 fprintf(stderr, "(no symbols)\n"); |
56 } else { | 58 } else { |
57 for (int i = 1; i < size; ++i) { | 59 for (int i = 1; i < size; ++i) { |
58 fprintf(stderr, "%2d: ", i); | 60 fprintf(stderr, "%2d: ", i); |
59 char mangled[201]; | 61 char mangled[201]; |
60 if (sscanf(symbols[i], "%*[^(]%*[(]%200[^)+]", mangled) == 1) {// NOLINT | 62 if (sscanf(symbols[i], "%*[^(]%*[(]%200[^)+]", mangled) == 1) {// NOLINT |
| 63 char* demangled = NULL; |
| 64 #if !defined(ANDROID) |
61 int status; | 65 int status; |
62 size_t length; | 66 size_t length; |
63 char* demangled = abi::__cxa_demangle( | 67 demangled = abi::__cxa_demangle(mangled, NULL, &length, &status); |
64 mangled, NULL, &length, &status); | 68 #endif |
65 fprintf(stderr, "%s\n", demangled != NULL ? demangled : mangled); | 69 fprintf(stderr, "%s\n", demangled != NULL ? demangled : mangled); |
66 free(demangled); | 70 free(demangled); |
67 } else { | 71 } else { |
68 fprintf(stderr, "??\n"); | 72 fprintf(stderr, "??\n"); |
69 } | 73 } |
70 } | 74 } |
71 } | 75 } |
72 fflush(stderr); | 76 fflush(stderr); |
73 free(symbols); | 77 free(symbols); |
74 } | 78 } |
(...skipping 21 matching lines...) Expand all Loading... |
96 | 100 |
97 free(symbols); | 101 free(symbols); |
98 | 102 |
99 return frames_count; | 103 return frames_count; |
100 } | 104 } |
101 }; | 105 }; |
102 | 106 |
103 } } // namespace v8::internal | 107 } } // namespace v8::internal |
104 | 108 |
105 #endif // V8_PLATFORM_POSIX_H_ | 109 #endif // V8_PLATFORM_POSIX_H_ |
OLD | NEW |