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

Side by Side Diff: src/platform-linux.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-freebsd.cc ('k') | src/platform-macos.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 433 matching lines...) Expand 10 before | Expand all | Expand 10 after
444 asm("break"); 444 asm("break");
445 #elif defined(__native_client__) 445 #elif defined(__native_client__)
446 asm("hlt"); 446 asm("hlt");
447 #else 447 #else
448 asm("int $3"); 448 asm("int $3");
449 #endif 449 #endif
450 } 450 }
451 451
452 452
453 void OS::DumpBacktrace() { 453 void OS::DumpBacktrace() {
454 // backtrace is a glibc extension.
454 #if defined(__GLIBC__) && !defined(__UCLIBC__) 455 #if defined(__GLIBC__) && !defined(__UCLIBC__)
455 void* trace[100]; 456 POSIXBacktraceHelper<backtrace, backtrace_symbols>::DumpBacktrace();
456 int size = backtrace(trace, ARRAY_SIZE(trace));
457 char** symbols = backtrace_symbols(trace, size);
458 fprintf(stderr, "\n==== C stack trace ===============================\n\n");
459 if (size == 0) {
460 fprintf(stderr, "(empty)\n");
461 } else if (symbols == NULL) {
462 fprintf(stderr, "(no symbols)\n");
463 } else {
464 for (int i = 1; i < size; ++i) {
465 fprintf(stderr, "%2d: ", i);
466 char mangled[201];
467 if (sscanf(symbols[i], "%*[^(]%*[(]%200[^)+]", mangled) == 1) { // NOLINT
468 int status;
469 size_t length;
470 char* demangled = abi::__cxa_demangle(mangled, NULL, &length, &status);
471 fprintf(stderr, "%s\n", demangled ? demangled : mangled);
472 free(demangled);
473 } else {
474 fprintf(stderr, "??\n");
475 }
476 }
477 }
478 fflush(stderr);
479 free(symbols);
480 #endif 457 #endif
481 } 458 }
482 459
483 460
484 class PosixMemoryMappedFile : public OS::MemoryMappedFile { 461 class PosixMemoryMappedFile : public OS::MemoryMappedFile {
485 public: 462 public:
486 PosixMemoryMappedFile(FILE* file, void* memory, int size) 463 PosixMemoryMappedFile(FILE* file, void* memory, int size)
487 : file_(file), memory_(memory), size_(size) { } 464 : file_(file), memory_(memory), size_(size) { }
488 virtual ~PosixMemoryMappedFile(); 465 virtual ~PosixMemoryMappedFile();
489 virtual void* memory() { return memory_; } 466 virtual void* memory() { return memory_; }
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after
623 0); 600 0);
624 ASSERT(addr != MAP_FAILED); 601 ASSERT(addr != MAP_FAILED);
625 OS::Free(addr, size); 602 OS::Free(addr, size);
626 fclose(f); 603 fclose(f);
627 } 604 }
628 605
629 606
630 int OS::StackWalk(Vector<OS::StackFrame> frames) { 607 int OS::StackWalk(Vector<OS::StackFrame> frames) {
631 // backtrace is a glibc extension. 608 // backtrace is a glibc extension.
632 #if defined(__GLIBC__) && !defined(__UCLIBC__) 609 #if defined(__GLIBC__) && !defined(__UCLIBC__)
633 int frames_size = frames.length(); 610 return POSIXBacktraceHelper<backtrace, backtrace_symbols>::StackWalk(frames);
634 ScopedVector<void*> addresses(frames_size); 611 #else
635
636 int frames_count = backtrace(addresses.start(), frames_size);
637
638 char** symbols = backtrace_symbols(addresses.start(), frames_count);
639 if (symbols == NULL) {
640 return kStackWalkError;
641 }
642
643 for (int i = 0; i < frames_count; i++) {
644 frames[i].address = addresses[i];
645 // Format a text representation of the frame based on the information
646 // available.
647 SNPrintF(MutableCStrVector(frames[i].text, kStackWalkMaxTextLen),
648 "%s",
649 symbols[i]);
650 // Make sure line termination is in place.
651 frames[i].text[kStackWalkMaxTextLen - 1] = '\0';
652 }
653
654 free(symbols);
655
656 return frames_count;
657 #else // defined(__GLIBC__) && !defined(__UCLIBC__)
658 return 0; 612 return 0;
659 #endif // defined(__GLIBC__) && !defined(__UCLIBC__) 613 #endif
660 } 614 }
661 615
662 616
663 // Constants used for mmap. 617 // Constants used for mmap.
664 static const int kMmapFd = -1; 618 static const int kMmapFd = -1;
665 static const int kMmapFdOffset = 0; 619 static const int kMmapFdOffset = 0;
666 620
667 621
668 VirtualMemory::VirtualMemory() : address_(NULL), size_(0) { } 622 VirtualMemory::VirtualMemory() : address_(NULL), size_(0) { }
669 623
(...skipping 300 matching lines...) Expand 10 before | Expand all | Expand 10 after
970 limit_mutex = CreateMutex(); 924 limit_mutex = CreateMutex();
971 } 925 }
972 926
973 927
974 void OS::TearDown() { 928 void OS::TearDown() {
975 delete limit_mutex; 929 delete limit_mutex;
976 } 930 }
977 931
978 932
979 } } // namespace v8::internal 933 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/platform-freebsd.cc ('k') | src/platform-macos.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698