Enable Dwarf2 debug information in offline assembler for clang compiler
https://bugs.webkit.org/show_bug.cgi?id=157364.

Reviewed by Mark Lam.

Added a new function shouldEnableDebugAnnotations() that determines if
we are using clang and a new enough version to support the debug annotations.

* offlineasm/config.rb:
(shouldEnableDebugAnnotations): Added.


git-svn-id: http://svn.webkit.org/repository/webkit/trunk@200447 268f45cc-cd09-0410-ab3c-d52691b4dbfc
diff --git a/Source/JavaScriptCore/ChangeLog b/Source/JavaScriptCore/ChangeLog
index ec4166c..46dcdb7 100644
--- a/Source/JavaScriptCore/ChangeLog
+++ b/Source/JavaScriptCore/ChangeLog
@@ -1,3 +1,16 @@
+2016-05-04  Michael Saboff  <msaboff@apple.com>
+
+        Enable Dwarf2 debug information in offline assembler for clang compiler
+        https://bugs.webkit.org/show_bug.cgi?id=157364.
+
+        Reviewed by Mark Lam.
+
+        Added a new function shouldEnableDebugAnnotations() that determines if
+        we are using clang and a new enough version to support the debug annotations.
+
+        * offlineasm/config.rb:
+        (shouldEnableDebugAnnotations): Added.
+
 2016-05-04  Keith Miller  <keith_miller@apple.com>
 
         Unreviewed, fix test for new ArrayIteratorPrototype.next() error message.
diff --git a/Source/JavaScriptCore/offlineasm/config.rb b/Source/JavaScriptCore/offlineasm/config.rb
index 468c5cd..cfbd3cb 100644
--- a/Source/JavaScriptCore/offlineasm/config.rb
+++ b/Source/JavaScriptCore/offlineasm/config.rb
@@ -59,4 +59,25 @@
 # Turns on generation of DWARF2 debug annotions for file and line numbers.
 # Allows for source level debuging of the original .asm files in a debugger.
 #
-$enableDebugAnnotations = false
+def shouldEnableDebugAnnotations()
+    if ENV['GCC_VERSION'] =~ /\.clang\./ and ENV['TOOLCHAIN_DIR'] != ''
+        clangExecutable = ENV['TOOLCHAIN_DIR'] + '/usr/bin/clang'
+        if File.executable?(clangExecutable)
+            clangVersionOut = %x`#{clangExecutable} --version`
+            if ($? == 0)
+                # clang version 800.0.12 or higher is required for debug annotations
+                versionMatch = /clang-(\d+).(\d+).(\d+)/.match(clangVersionOut)
+                if versionMatch.length >= 4
+                    totalVersion = versionMatch[1].to_i * 1000000 + versionMatch[2].to_i * 1000 + versionMatch[3].to_i
+                    if totalVersion >= 800000012
+                        return true
+                    end
+                end
+            end
+        end
+    end
+
+    false
+end
+
+$enableDebugAnnotations = shouldEnableDebugAnnotations()