Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(5)

Side by Side Diff: src/platform-posix.h

Issue 23703013: remove OS::StackWalk (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: rebase Created 7 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « src/platform-openbsd.cc ('k') | src/platform-solaris.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 21 matching lines...) Expand all
32 #include <cxxabi.h> 32 #include <cxxabi.h>
33 #endif 33 #endif
34 #include <stdio.h> 34 #include <stdio.h>
35 35
36 #include "platform.h" 36 #include "platform.h"
37 37
38 namespace v8 { 38 namespace v8 {
39 namespace internal { 39 namespace internal {
40 40
41 // Used by platform implementation files during OS::DumpBacktrace() 41 // Used by platform implementation files during OS::DumpBacktrace()
42 // and OS::StackWalk().
43 template<int (*backtrace)(void**, int), 42 template<int (*backtrace)(void**, int),
44 char** (*backtrace_symbols)(void* const*, int)> 43 char** (*backtrace_symbols)(void* const*, int)>
45 struct POSIXBacktraceHelper { 44 struct POSIXBacktraceHelper {
46 static void DumpBacktrace() { 45 static void DumpBacktrace() {
47 void* trace[100]; 46 void* trace[100];
48 int size = backtrace(trace, ARRAY_SIZE(trace)); 47 int size = backtrace(trace, ARRAY_SIZE(trace));
49 char** symbols = backtrace_symbols(trace, size); 48 char** symbols = backtrace_symbols(trace, size);
50 fprintf(stderr, "\n==== C stack trace ===============================\n\n"); 49 fprintf(stderr, "\n==== C stack trace ===============================\n\n");
51 if (size == 0) { 50 if (size == 0) {
52 fprintf(stderr, "(empty)\n"); 51 fprintf(stderr, "(empty)\n");
(...skipping 13 matching lines...) Expand all
66 fprintf(stderr, "%s\n", demangled != NULL ? demangled : mangled); 65 fprintf(stderr, "%s\n", demangled != NULL ? demangled : mangled);
67 free(demangled); 66 free(demangled);
68 } else { 67 } else {
69 fprintf(stderr, "??\n"); 68 fprintf(stderr, "??\n");
70 } 69 }
71 } 70 }
72 } 71 }
73 fflush(stderr); 72 fflush(stderr);
74 free(symbols); 73 free(symbols);
75 } 74 }
76
77 static int StackWalk(Vector<OS::StackFrame> frames) {
78 int frames_size = frames.length();
79 ScopedVector<void*> addresses(frames_size);
80
81 int frames_count = backtrace(addresses.start(), frames_size);
82
83 char** symbols = backtrace_symbols(addresses.start(), frames_count);
84 if (symbols == NULL) {
85 return OS::kStackWalkError;
86 }
87
88 for (int i = 0; i < frames_count; i++) {
89 frames[i].address = addresses[i];
90 // Format a text representation of the frame based on the information
91 // available.
92 OS::SNPrintF(MutableCStrVector(frames[i].text, OS::kStackWalkMaxTextLen),
93 "%s", symbols[i]);
94 // Make sure line termination is in place.
95 frames[i].text[OS::kStackWalkMaxTextLen - 1] = '\0';
96 }
97
98 free(symbols);
99
100 return frames_count;
101 }
102 }; 75 };
103 76
104 } } // namespace v8::internal 77 } } // namespace v8::internal
105 78
106 #endif // V8_PLATFORM_POSIX_H_ 79 #endif // V8_PLATFORM_POSIX_H_
OLDNEW
« no previous file with comments | « src/platform-openbsd.cc ('k') | src/platform-solaris.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698