Fix issue 427: JS tick processor now works out-of-the-box for Chromium on Windows.
authormikhail.naganov@gmail.com <mikhail.naganov@gmail.com@ce2b1a6d-e550-0410-aec6-3dcde31c8c00>
Mon, 17 Aug 2009 13:45:03 +0000 (13:45 +0000)
committermikhail.naganov@gmail.com <mikhail.naganov@gmail.com@ce2b1a6d-e550-0410-aec6-3dcde31c8c00>
Mon, 17 Aug 2009 13:45:03 +0000 (13:45 +0000)
MSVS names '.map' file using only module's name, so both 'a.exe' and 'a.dll' will have 'a.map' file. To distinguish an originating module, we're now checking for image base which is always 00400000 for .exe files, and not 00400000 for .dlls.

Verified that windows-tick-processor can now process logs from Chromium using .map file generated for 'chrome.dll', an that it still works for V8's 'shell.exe'.

Review URL: http://codereview.chromium.org/172044

git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@2699 ce2b1a6d-e550-0410-aec6-3dcde31c8c00

test/mjsunit/tools/tickprocessor.js
tools/tickprocessor.js

index 00c3fb176bfca35694632d7848273067f893f3fb..83bdac8ab8dee3f61ab2250c8ba867c386904265 100644 (file)
 })();
 
 
+// http://code.google.com/p/v8/issues/detail?id=427
+(function testWindowsProcessExeAndDllMapFile() {
+  function exeSymbols(exeName) {
+    return [
+      ' 0000:00000000       ___ImageBase               00400000     <linker-defined>',
+      ' 0001:00000780       ?RunMain@@YAHHQAPAD@Z      00401780 f   shell.obj',
+      ' 0001:00000ac0       _main                      00401ac0 f   shell.obj',
+      ''
+    ].join('\r\n');
+  }
+
+  function dllSymbols(dllName) {
+    return [
+      ' 0000:00000000       ___ImageBase               01c30000     <linker-defined>',
+      ' 0001:00000780       _DllMain@12                01c31780 f   libcmt:dllmain.obj',
+      ' 0001:00000ac0       ___DllMainCRTStartup       01c31ac0 f   libcmt:dllcrt0.obj',
+      ''
+    ].join('\r\n');
+  }
+
+  var oldRead = read;
+
+  read = exeSymbols;
+  var exe_exe_syms = [];
+  (new WindowsCppEntriesProvider()).parseVmSymbols(
+      'chrome.exe', 0x00400000, 0x00472000,
+      function (name, start, end) {
+        exe_exe_syms.push(Array.prototype.slice.apply(arguments, [0]));
+      });
+  assertEquals(
+      [['RunMain', 0x00401780, 0x00401ac0],
+       ['_main', 0x00401ac0, 0x00472000]],
+      exe_exe_syms, '.exe with .exe symbols');
+
+  read = dllSymbols;
+  var exe_dll_syms = [];
+  (new WindowsCppEntriesProvider()).parseVmSymbols(
+      'chrome.exe', 0x00400000, 0x00472000,
+      function (name, start, end) {
+        exe_dll_syms.push(Array.prototype.slice.apply(arguments, [0]));
+      });
+  assertEquals(
+      [],
+      exe_dll_syms, '.exe with .dll symbols');
+
+  read = dllSymbols;
+  var dll_dll_syms = [];
+  (new WindowsCppEntriesProvider()).parseVmSymbols(
+      'chrome.dll', 0x01c30000, 0x02b80000,
+      function (name, start, end) {
+        dll_dll_syms.push(Array.prototype.slice.apply(arguments, [0]));
+      });
+  assertEquals(
+      [['_DllMain@12', 0x01c31780, 0x01c31ac0],
+       ['___DllMainCRTStartup', 0x01c31ac0, 0x02b80000]],
+      dll_dll_syms, '.dll with .dll symbols');
+
+  read = exeSymbols;
+  var dll_exe_syms = [];
+  (new WindowsCppEntriesProvider()).parseVmSymbols(
+      'chrome.dll', 0x01c30000, 0x02b80000,
+      function (name, start, end) {
+        dll_exe_syms.push(Array.prototype.slice.apply(arguments, [0]));
+      });
+  assertEquals(
+      [],
+      dll_exe_syms, '.dll with .exe symbols');
+
+  read = oldRead;
+})();
+
+
 function CppEntriesProviderMock() {
 };
 
index 34c6195d9a30585de26d921a0639d59a1e070a87..72b3059dcaabf3e1645d2395cfc41cec118eda7d 100644 (file)
@@ -499,19 +499,32 @@ function WindowsCppEntriesProvider() {
 inherits(WindowsCppEntriesProvider, CppEntriesProvider);
 
 
-WindowsCppEntriesProvider.FILENAME_RE = /^(.*)\.exe$/;
+WindowsCppEntriesProvider.FILENAME_RE = /^(.*)\.([^.]+)$/;
 
 
 WindowsCppEntriesProvider.FUNC_RE =
-    /^ 0001:[0-9a-fA-F]{8}\s+([_\?@$0-9a-zA-Z]+)\s+([0-9a-fA-F]{8}).*$/;
+    /^\s+0001:[0-9a-fA-F]{8}\s+([_\?@$0-9a-zA-Z]+)\s+([0-9a-fA-F]{8}).*$/;
+
+
+WindowsCppEntriesProvider.IMAGE_BASE_RE =
+    /^\s+0000:00000000\s+___ImageBase\s+([0-9a-fA-F]{8}).*$/;
+
+
+// This is almost a constant on Windows.
+WindowsCppEntriesProvider.EXE_IMAGE_BASE = 0x00400000;
 
 
 WindowsCppEntriesProvider.prototype.loadSymbols = function(libName) {
   var fileNameFields = libName.match(WindowsCppEntriesProvider.FILENAME_RE);
-  // Only try to load symbols for the .exe file.
   if (!fileNameFields) return;
   var mapFileName = fileNameFields[1] + '.map';
-  this.symbols = readFile(mapFileName);
+  this.moduleType_ = fileNameFields[2].toLowerCase();
+  try {
+    this.symbols = read(mapFileName);
+  } catch (e) {
+    // If .map file cannot be found let's not panic.
+    this.symbols = '';
+  }
 };
 
 
@@ -523,6 +536,18 @@ WindowsCppEntriesProvider.prototype.parseNextLine = function() {
 
   var line = this.symbols.substring(this.parsePos, lineEndPos);
   this.parsePos = lineEndPos + 2;
+
+  // Image base entry is above all other symbols, so we can just
+  // terminate parsing.
+  var imageBaseFields = line.match(WindowsCppEntriesProvider.IMAGE_BASE_RE);
+  if (imageBaseFields) {
+    var imageBase = parseInt(imageBaseFields[1], 16);
+    if ((this.moduleType_ == 'exe') !=
+        (imageBase == WindowsCppEntriesProvider.EXE_IMAGE_BASE)) {
+      return false;
+    }
+  }
+
   var fields = line.match(WindowsCppEntriesProvider.FUNC_RE);
   return fields ?
       { name: this.unmangleName(fields[1]), start: parseInt(fields[2], 16) } :