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

Side by Side Diff: src/platform-freebsd.cc

Issue 18431004: Common implementation of OS::DumpBacktrace() and OS::StackWalk(). (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Templatized POSIX backtrace Created 7 years, 5 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 | « no previous file | src/platform-linux.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 178 matching lines...) Expand 10 before | Expand all | Expand 10 after
189 void OS::DebugBreak() { 189 void OS::DebugBreak() {
190 #if (defined(__arm__) || defined(__thumb__)) 190 #if (defined(__arm__) || defined(__thumb__))
191 asm("bkpt 0"); 191 asm("bkpt 0");
192 #else 192 #else
193 asm("int $3"); 193 asm("int $3");
194 #endif 194 #endif
195 } 195 }
196 196
197 197
198 void OS::DumpBacktrace() { 198 void OS::DumpBacktrace() {
199 void* trace[100]; 199 POSIXBacktraceHelper<backtrace, backtrace_symbols>::DumpBacktrace();
200 int size = backtrace(trace, ARRAY_SIZE(trace));
201 char** symbols = backtrace_symbols(trace, size);
202 fprintf(stderr, "\n==== C stack trace ===============================\n\n");
203 if (size == 0) {
204 fprintf(stderr, "(empty)\n");
205 } else if (symbols == NULL) {
206 fprintf(stderr, "(no symbols)\n");
207 } else {
208 for (int i = 1; i < size; ++i) {
209 fprintf(stderr, "%2d: ", i);
210 char mangled[201];
211 if (sscanf(symbols[i], "%*[^(]%*[(]%200[^)+]", mangled) == 1) { // NOLINT
212 fprintf(stderr, "%s\n", mangled);
213 } else {
214 fprintf(stderr, "??\n");
215 }
216 }
217 }
218 fflush(stderr);
219 free(symbols);
220 } 200 }
221 201
222 202
223 class PosixMemoryMappedFile : public OS::MemoryMappedFile { 203 class PosixMemoryMappedFile : public OS::MemoryMappedFile {
224 public: 204 public:
225 PosixMemoryMappedFile(FILE* file, void* memory, int size) 205 PosixMemoryMappedFile(FILE* file, void* memory, int size)
226 : file_(file), memory_(memory), size_(size) { } 206 : file_(file), memory_(memory), size_(size) { }
227 virtual ~PosixMemoryMappedFile(); 207 virtual ~PosixMemoryMappedFile();
228 virtual void* memory() { return memory_; } 208 virtual void* memory() { return memory_; }
229 virtual int size() { return size_; } 209 virtual int size() { return size_; }
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
311 } 291 }
312 close(fd); 292 close(fd);
313 } 293 }
314 294
315 295
316 void OS::SignalCodeMovingGC() { 296 void OS::SignalCodeMovingGC() {
317 } 297 }
318 298
319 299
320 int OS::StackWalk(Vector<OS::StackFrame> frames) { 300 int OS::StackWalk(Vector<OS::StackFrame> frames) {
321 int frames_size = frames.length(); 301 return POSIXBacktraceHelper<backtrace, backtrace_symbols>::StackWalk(frames);
322 ScopedVector<void*> addresses(frames_size);
323
324 int frames_count = backtrace(addresses.start(), frames_size);
325
326 char** symbols = backtrace_symbols(addresses.start(), frames_count);
327 if (symbols == NULL) {
328 return kStackWalkError;
329 }
330
331 for (int i = 0; i < frames_count; i++) {
332 frames[i].address = addresses[i];
333 // Format a text representation of the frame based on the information
334 // available.
335 SNPrintF(MutableCStrVector(frames[i].text, kStackWalkMaxTextLen),
336 "%s",
337 symbols[i]);
338 // Make sure line termination is in place.
339 frames[i].text[kStackWalkMaxTextLen - 1] = '\0';
340 }
341
342 free(symbols);
343
344 return frames_count;
345 } 302 }
346 303
347 304
348 // Constants used for mmap. 305 // Constants used for mmap.
349 static const int kMmapFd = -1; 306 static const int kMmapFd = -1;
350 static const int kMmapFdOffset = 0; 307 static const int kMmapFdOffset = 0;
351 308
352 309
353 VirtualMemory::VirtualMemory() : address_(NULL), size_(0) { } 310 VirtualMemory::VirtualMemory() : address_(NULL), size_(0) { }
354 311
(...skipping 280 matching lines...) Expand 10 before | Expand all | Expand 10 after
635 limit_mutex = CreateMutex(); 592 limit_mutex = CreateMutex();
636 } 593 }
637 594
638 595
639 void OS::TearDown() { 596 void OS::TearDown() {
640 delete limit_mutex; 597 delete limit_mutex;
641 } 598 }
642 599
643 600
644 } } // namespace v8::internal 601 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « no previous file | src/platform-linux.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698