Implement a StackTrace utility object that can capture stack traces for debugging.
authormark.lam@apple.com <mark.lam@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 10 Mar 2017 01:27:32 +0000 (01:27 +0000)
committermark.lam@apple.com <mark.lam@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 10 Mar 2017 01:27:32 +0000 (01:27 +0000)
commitd28e51d19a2164a6c92ee34197aded9402136592
tree0c902055ee7a16f1701a868ba8754e741d7efbab
parente5fb6d6a44708497d8369ced6a47ef35975e4256
Implement a StackTrace utility object that can capture stack traces for debugging.
https://bugs.webkit.org/show_bug.cgi?id=169454

Reviewed by Michael Saboff.

The underlying implementation is hoisted right out of Assertions.cpp from the
implementations of WTFPrintBacktrace().

The reason we need this StackTrace object is because during heap debugging, we
sometimes want to capture the stack trace that allocated the objects of interest.
Dumping the stack trace directly to stdout (using WTFReportBacktrace()) may
perturb the execution profile sufficiently that an issue may not reproduce,
while alternatively, just capturing the stack trace and deferring printing it
till we actually need it later perturbs the execution profile less.

In addition, just capturing the stack traces (instead of printing them
immediately at each capture site) allows us to avoid polluting stdout with tons
of stack traces that may be irrelevant.

For now, we only capture the native stack trace.  We'll leave capturing and
integrating the JS stack trace as an exercise for the future if we need it then.

Here's an example of how to use this StackTrace utility:

    // Capture a stack trace of the top 10 frames.
    std::unique_ptr<StackTrace> trace(StackTrace::captureStackTrace(10));
    // Print the trace.
    dataLog(*trace);

* CMakeLists.txt:
* JavaScriptCore.xcodeproj/project.pbxproj:
* tools/StackTrace.cpp: Added.
(JSC::StackTrace::instanceSize):
(JSC::StackTrace::captureStackTrace):
(JSC::StackTrace::dump):
* tools/StackTrace.h: Added.
(JSC::StackTrace::StackTrace):
(JSC::StackTrace::size):

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@213695 268f45cc-cd09-0410-ab3c-d52691b4dbfc
Source/JavaScriptCore/CMakeLists.txt
Source/JavaScriptCore/ChangeLog
Source/JavaScriptCore/JavaScriptCore.xcodeproj/project.pbxproj
Source/JavaScriptCore/tools/StackTrace.cpp [new file with mode: 0644]
Source/JavaScriptCore/tools/StackTrace.h [new file with mode: 0644]