Author: [email protected]
Date: Mon Jul 13 22:01:06 2009
New Revision: 2452

Added:
    branches/bleeding_edge/tools/mac-nm   (contents, props changed)
    branches/bleeding_edge/tools/mac-tick-processor   (contents, props  
changed)
Modified:
    branches/bleeding_edge/src/platform-macos.cc
    branches/bleeding_edge/tools/tickprocessor-driver.js
    branches/bleeding_edge/tools/tickprocessor.js

Log:
Implement shared libraries logging on Mac OS X, added required support in  
Tick Processor.

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

Modified: branches/bleeding_edge/src/platform-macos.cc
==============================================================================
--- branches/bleeding_edge/src/platform-macos.cc        (original)
+++ branches/bleeding_edge/src/platform-macos.cc        Mon Jul 13 22:01:06 2009
@@ -32,6 +32,8 @@
  #include <unistd.h>
  #include <sys/mman.h>
  #include <mach/mach_init.h>
+#include <mach-o/dyld.h>
+#include <mach-o/getsect.h>

  #include <AvailabilityMacros.h>

@@ -205,7 +207,17 @@


  void OS::LogSharedLibraryAddresses() {
-  // TODO(1233579): Implement.
+  unsigned int images_count = _dyld_image_count();
+  for (unsigned int i = 0; i < images_count; ++i) {
+    const mach_header* header = _dyld_get_image_header(i);
+    if (header == NULL) continue;
+    unsigned int size;
+    char* code_ptr = getsectdatafromheader(header, SEG_TEXT, SECT_TEXT,  
&size);
+    if (code_ptr == NULL) continue;
+    const uintptr_t slide = _dyld_get_image_vmaddr_slide(i);
+    const uintptr_t start = reinterpret_cast<uintptr_t>(code_ptr) + slide;
+    LOG(SharedLibraryEvent(_dyld_get_image_name(i), start, start + size));
+  }
  }



Added: branches/bleeding_edge/tools/mac-nm
==============================================================================
--- (empty file)
+++ branches/bleeding_edge/tools/mac-nm Mon Jul 13 22:01:06 2009
@@ -0,0 +1,18 @@
+#!/bin/sh
+
+# This script is a wrapper for OS X nm(1) tool. nm(1) perform C++ function
+# names demangling, so we're piping its output to c++filt(1) tool which  
does it.
+# But c++filt(1) comes with XCode (as a part of GNU binutils), so it  
doesn't
+# guaranteed to exist on a system.
+#
+# An alternative approach is to perform demangling in tick processor, but
+# for GNU C++ ABI this is a complex process (see cp-demangle.c sources),  
and
+# can't be done partially, because term boundaries are plain text symbols,  
such
+# as 'N', 'E', so one can't just do a search through a function name, it  
really
+# needs to be parsed, which requires a lot of knowledge to be coded in.
+
+if [ "`which c++filt`" == "" ]; then
+  nm $@
+else
+  nm $@ | c++filt -p -i
+fi

Added: branches/bleeding_edge/tools/mac-tick-processor
==============================================================================
--- (empty file)
+++ branches/bleeding_edge/tools/mac-tick-processor     Mon Jul 13 22:01:06 2009
@@ -0,0 +1,6 @@
+#!/bin/sh
+
+# A wrapper script to call 'linux-tick-processor' with Mac-specific  
settings.
+
+tools_path=`cd $(dirname "$0");pwd`
+$tools_path/linux-tick-processor --mac --nm=$tools_path/mac-nm $@

Modified: branches/bleeding_edge/tools/tickprocessor-driver.js
==============================================================================
--- branches/bleeding_edge/tools/tickprocessor-driver.js        (original)
+++ branches/bleeding_edge/tools/tickprocessor-driver.js        Mon Jul 13  
22:01:06 2009
@@ -37,11 +37,15 @@
    }
  }

+var entriesProviders = {
+  'unix': UnixCppEntriesProvider,
+  'windows': WindowsCppEntriesProvider,
+  'mac': MacCppEntriesProvider
+};

  var params = processArguments(arguments);
  var tickProcessor = new TickProcessor(
-  params.platform == 'unix' ? new UnixCppEntriesProvider(params.nm) :
-    new WindowsCppEntriesProvider(),
+  new (entriesProviders[params.platform])(params.nm),
    params.separateIc,
    params.ignoreUnknown,
    params.stateFilter);

Modified: branches/bleeding_edge/tools/tickprocessor.js
==============================================================================
--- branches/bleeding_edge/tools/tickprocessor.js       (original)
+++ branches/bleeding_edge/tools/tickprocessor.js       Mon Jul 13 22:01:06 2009
@@ -420,13 +420,11 @@
    this.symbols = [];
    this.parsePos = 0;
    this.nmExec = nmExec;
+  this.FUNC_RE = /^([0-9a-fA-F]{8}) [tTwW] (.*)$/;
  };
  inherits(UnixCppEntriesProvider, CppEntriesProvider);


-UnixCppEntriesProvider.FUNC_RE = /^([0-9a-fA-F]{8}) [tTwW] (.*)$/;
-
-
  UnixCppEntriesProvider.prototype.loadSymbols = function(libName) {
    this.parsePos = 0;
    try {
@@ -454,11 +452,29 @@

    var line = this.symbols[0].substring(this.parsePos, lineEndPos);
    this.parsePos = lineEndPos + 1;
-  var fields = line.match(UnixCppEntriesProvider.FUNC_RE);
+  var fields = line.match(this.FUNC_RE);
    return fields ? { name: fields[2], start: parseInt(fields[1], 16) } :  
null;
  };


+function MacCppEntriesProvider(nmExec) {
+  UnixCppEntriesProvider.call(this, nmExec);
+  this.FUNC_RE = /^([0-9a-fA-F]{8}) [iItT] (.*)$/;
+};
+inherits(MacCppEntriesProvider, UnixCppEntriesProvider);
+
+
+MacCppEntriesProvider.prototype.loadSymbols = function(libName) {
+  this.parsePos = 0;
+  try {
+    this.symbols = [os.system(this.nmExec, ['-n', '-f', libName], -1,  
-1), ''];
+  } catch (e) {
+    // If the library cannot be found on this system let's not panic.
+    this.symbols = '';
+  }
+};
+
+
  function WindowsCppEntriesProvider() {
    this.symbols = '';
    this.parsePos = 0;
@@ -538,6 +554,8 @@
          'Specify that we are running on *nix platform'],
      '--windows': ['platform', 'windows',
          'Specify that we are running on Windows platform'],
+    '--mac': ['platform', 'mac',
+        'Specify that we are running on Mac OS X platform'],
      '--nm': ['nm', 'nm',
          'Specify the \'nm\' executable to use (e.g. --nm=/my_dir/nm)']
    };

--~--~---------~--~----~------------~-------~--~----~
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev
-~----------~----~----~----~------~----~------~--~---

Reply via email to