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

Side by Side Diff: src/platform-macos.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 | « src/platform-linux.cc ('k') | src/platform-posix.h » ('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 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
46 #include <mach/task.h> 46 #include <mach/task.h>
47 #include <mach/vm_statistics.h> 47 #include <mach/vm_statistics.h>
48 #include <sys/time.h> 48 #include <sys/time.h>
49 #include <sys/resource.h> 49 #include <sys/resource.h>
50 #include <sys/types.h> 50 #include <sys/types.h>
51 #include <sys/sysctl.h> 51 #include <sys/sysctl.h>
52 #include <stdarg.h> 52 #include <stdarg.h>
53 #include <stdlib.h> 53 #include <stdlib.h>
54 #include <string.h> 54 #include <string.h>
55 #include <errno.h> 55 #include <errno.h>
56 #include <cxxabi.h>
56 57
57 #undef MAP_TYPE 58 #undef MAP_TYPE
58 59
59 #include "v8.h" 60 #include "v8.h"
60 61
61 #include "platform-posix.h" 62 #include "platform-posix.h"
62 #include "platform.h" 63 #include "platform.h"
63 #include "simulator.h" 64 #include "simulator.h"
64 #include "vm-state-inl.h" 65 #include "vm-state-inl.h"
65 66
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after
182 abort(); 183 abort();
183 } 184 }
184 185
185 186
186 void OS::DebugBreak() { 187 void OS::DebugBreak() {
187 asm("int $3"); 188 asm("int $3");
188 } 189 }
189 190
190 191
191 void OS::DumpBacktrace() { 192 void OS::DumpBacktrace() {
192 // Currently unsupported. 193 // If weak link to execinfo lib has failed, ie because we are on 10.4, abort.
194 if (backtrace == NULL) return;
195
196 POSIXBacktraceHelper<backtrace, backtrace_symbols>::DumpBacktrace();
193 } 197 }
194 198
195 199
196 class PosixMemoryMappedFile : public OS::MemoryMappedFile { 200 class PosixMemoryMappedFile : public OS::MemoryMappedFile {
197 public: 201 public:
198 PosixMemoryMappedFile(FILE* file, void* memory, int size) 202 PosixMemoryMappedFile(FILE* file, void* memory, int size)
199 : file_(file), memory_(memory), size_(size) { } 203 : file_(file), memory_(memory), size_(size) { }
200 virtual ~PosixMemoryMappedFile(); 204 virtual ~PosixMemoryMappedFile();
201 virtual void* memory() { return memory_; } 205 virtual void* memory() { return memory_; }
202 virtual int size() { return size_; } 206 virtual int size() { return size_; }
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after
308 time_t tv = time(NULL); 312 time_t tv = time(NULL);
309 struct tm* t = localtime(&tv); 313 struct tm* t = localtime(&tv);
310 // tm_gmtoff includes any daylight savings offset, so subtract it. 314 // tm_gmtoff includes any daylight savings offset, so subtract it.
311 return static_cast<double>(t->tm_gmtoff * msPerSecond - 315 return static_cast<double>(t->tm_gmtoff * msPerSecond -
312 (t->tm_isdst > 0 ? 3600 * msPerSecond : 0)); 316 (t->tm_isdst > 0 ? 3600 * msPerSecond : 0));
313 } 317 }
314 318
315 319
316 int OS::StackWalk(Vector<StackFrame> frames) { 320 int OS::StackWalk(Vector<StackFrame> frames) {
317 // If weak link to execinfo lib has failed, ie because we are on 10.4, abort. 321 // If weak link to execinfo lib has failed, ie because we are on 10.4, abort.
318 if (backtrace == NULL) 322 if (backtrace == NULL) return 0;
319 return 0;
320 323
321 int frames_size = frames.length(); 324 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,
336 kStackWalkMaxTextLen),
337 "%s",
338 symbols[i]);
339 // Make sure line termination is in place.
340 frames[i].text[kStackWalkMaxTextLen - 1] = '\0';
341 }
342
343 free(symbols);
344
345 return frames_count;
346 } 325 }
347 326
348 327
349 VirtualMemory::VirtualMemory() : address_(NULL), size_(0) { } 328 VirtualMemory::VirtualMemory() : address_(NULL), size_(0) { }
350 329
351 330
352 VirtualMemory::VirtualMemory(size_t size) 331 VirtualMemory::VirtualMemory(size_t size)
353 : address_(ReserveRegion(size)), size_(size) { } 332 : address_(ReserveRegion(size)), size_(size) { }
354 333
355 334
(...skipping 350 matching lines...) Expand 10 before | Expand all | Expand 10 after
706 limit_mutex = CreateMutex(); 685 limit_mutex = CreateMutex();
707 } 686 }
708 687
709 688
710 void OS::TearDown() { 689 void OS::TearDown() {
711 delete limit_mutex; 690 delete limit_mutex;
712 } 691 }
713 692
714 693
715 } } // namespace v8::internal 694 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/platform-linux.cc ('k') | src/platform-posix.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698