Make Interpreter::getStackTrace be able to generate the line number for the top callf...
authoroliver@apple.com <oliver@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 23 Feb 2012 23:18:05 +0000 (23:18 +0000)
committeroliver@apple.com <oliver@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 23 Feb 2012 23:18:05 +0000 (23:18 +0000)
https://bugs.webkit.org/show_bug.cgi?id=79407

Reviewed by Gavin Barraclough.

Outside of exception handling, we don't know what our source line number is.  This
change allows us to pass -1 is as the initial line number, and get the correct line
number in the resultant stack trace.  We can't completely elide the initial line
number (yet) due to some idiosyncrasies of the exception handling machinery.

* interpreter/Interpreter.cpp:
(JSC::getLineNumberForCallFrame):
(JSC):
(JSC::Interpreter::getStackTrace):

git-svn-id: http://svn.webkit.org/repository/webkit/trunk@108681 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Source/JavaScriptCore/ChangeLog
Source/JavaScriptCore/interpreter/Interpreter.cpp

index 8099f61..cb388cb 100644 (file)
@@ -1,3 +1,20 @@
+2012-02-23  Oliver Hunt  <oliver@apple.com>
+
+        Make Interpreter::getStackTrace be able to generate the line number for the top callframe if none is provided
+        https://bugs.webkit.org/show_bug.cgi?id=79407
+
+        Reviewed by Gavin Barraclough.
+
+        Outside of exception handling, we don't know what our source line number is.  This
+        change allows us to pass -1 is as the initial line number, and get the correct line
+        number in the resultant stack trace.  We can't completely elide the initial line
+        number (yet) due to some idiosyncrasies of the exception handling machinery.
+
+        * interpreter/Interpreter.cpp:
+        (JSC::getLineNumberForCallFrame):
+        (JSC):
+        (JSC::Interpreter::getStackTrace):
+
 2012-02-22  Filip Pizlo  <fpizlo@apple.com>
 
         DFG OSR exit value profiling should have graceful handling of local variables and arguments
index eb6a29d..336f109 100644 (file)
@@ -817,6 +817,25 @@ static void appendSourceToError(CallFrame* callFrame, ErrorInstance* exception,
     exception->putDirect(*globalData, globalData->propertyNames->message, jsString(globalData, message));
 }
 
+static int getLineNumberForCallFrame(CallFrame* callFrame)
+{
+    callFrame = callFrame->removeHostCallFrameFlag();
+    CodeBlock* codeBlock = callFrame->codeBlock();
+    if (!codeBlock)
+        return -1;
+#if ENABLE(INTERPRETER)
+    if (!globalData->canUseJIT())
+        return codeBlock->lineNumberForBytecodeOffset(callFrame->bytecodeOffsetForNonDFGCode() - 1);
+#endif
+#if ENABLE(JIT)
+#if ENABLE(DFG_JIT)
+    if (codeBlock->getJITType() == JITCode::DFGJIT)
+        return codeBlock->lineNumberForBytecodeOffset(codeBlock->codeOrigin(callFrame->codeOriginIndexForDFG()).bytecodeIndex);
+#endif
+    return codeBlock->lineNumberForBytecodeOffset(callFrame->bytecodeOffsetForNonDFGCode());
+#endif
+}
+
 static CallFrame* getCallerInfo(JSGlobalData* globalData, CallFrame* callFrame, int& lineNumber)
 {
     UNUSED_PARAM(globalData);
@@ -929,6 +948,9 @@ void Interpreter::getStackTrace(JSGlobalData* globalData, int line, Vector<Stack
     if (!callFrame || callFrame == CallFrame::noCaller()) 
         return;
 
+    if (line == -1)
+        line = getLineNumberForCallFrame(callFrame);
+    
     while (callFrame && callFrame != CallFrame::noCaller()) {
         UString sourceURL;
         if (callFrame->codeBlock()) {