Print Wasm function index in stack trace
https://bugs.webkit.org/show_bug.cgi?id=171349

Reviewed by JF Bastien.

JSTests:

* wasm/function-tests/stack-trace.js: Added.
(import.Builder.from.string_appeared_here.assert):
(let.imp):
* wasm/function-tests/trap-after-cross-instance-call.js:
(wasmFrameCountFromError):
* wasm/function-tests/trap-load-2.js:
(wasmFrameCountFromError):
* wasm/function-tests/trap-load.js:
(wasmFrameCountFromError):

Source/JavaScriptCore:

This patch prints a Callee's index in the function index
space in Error.stack.

This will lead to stack traces that have lines of text like:
wasm function index: 4@[wasm code]

We don't ascribe indices to everything in wasm. Specifically, the
Wasm->JS call stub callee does not get a name, and neither does
the JS -> Wasm entrypoint.

* interpreter/Interpreter.cpp:
(JSC::GetStackTraceFunctor::operator()):
* interpreter/StackVisitor.cpp:
(JSC::StackVisitor::readNonInlinedFrame):
(JSC::StackVisitor::Frame::functionName):
* interpreter/StackVisitor.h:
(JSC::StackVisitor::Frame::wasmFunctionIndex):
* runtime/StackFrame.cpp:
(JSC::StackFrame::functionName):
* runtime/StackFrame.h:
(JSC::StackFrame::StackFrame):
(JSC::StackFrame::wasm):
(JSC::StackFrame::hasBytecodeOffset):
(JSC::StackFrame::bytecodeOffset):
* wasm/WasmBBQPlanInlines.h:
(JSC::Wasm::BBQPlan::initializeCallees):
* wasm/WasmCallee.cpp:
(JSC::Wasm::Callee::Callee):
* wasm/WasmCallee.h:
(JSC::Wasm::Callee::create):
(JSC::Wasm::Callee::index):
* wasm/WasmOMGPlan.cpp:
(JSC::Wasm::OMGPlan::work):


git-svn-id: http://svn.webkit.org/repository/webkit/trunk@215854 268f45cc-cd09-0410-ab3c-d52691b4dbfc
diff --git a/Source/JavaScriptCore/interpreter/StackVisitor.cpp b/Source/JavaScriptCore/interpreter/StackVisitor.cpp
index 32c1bc0..52eafc9 100644
--- a/Source/JavaScriptCore/interpreter/StackVisitor.cpp
+++ b/Source/JavaScriptCore/interpreter/StackVisitor.cpp
@@ -163,6 +163,11 @@
         m_frame.m_isWasmFrame = true;
         m_frame.m_codeBlock = nullptr;
         m_frame.m_bytecodeOffset = 0;
+#if ENABLE(WEBASSEMBLY)
+        CalleeBits bits = callFrame->callee();
+        if (bits.isWasm())
+            m_frame.m_wasmFunctionIndex = bits.asWasmCallee()->index();
+#endif
     } else {
         m_frame.m_codeBlock = callFrame->codeBlock();
         m_frame.m_bytecodeOffset = !m_frame.codeBlock() ? 0
@@ -278,7 +283,10 @@
 
     switch (codeType()) {
     case CodeType::Wasm:
-        traceLine = ASCIILiteral("wasm code");
+        if (m_wasmFunctionIndex)
+            traceLine = makeString("wasm function index: ", String::number(*m_wasmFunctionIndex));
+        else
+            traceLine = ASCIILiteral("wasm function");
         break;
     case CodeType::Eval:
         traceLine = ASCIILiteral("eval code");