Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Implement shared libraries logging on Mac OS X, added required suppor…

…t in Tick Processor.

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

git-svn-id: https://v8.googlecode.com/svn/branches/bleeding_edge@2452 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
  • Loading branch information...
commit b495f1ce55432bc461992af81e95d35122a8c4e6 1 parent 6365113
mikhail.naganov@gmail.com authored
View
14 src/platform-macos.cc
@@ -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 @@ PosixMemoryMappedFile::~PosixMemoryMappedFile() {
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));
+ }
}
View
18 tools/mac-nm
@@ -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
View
6 tools/mac-tick-processor
@@ -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 $@
View
8 tools/tickprocessor-driver.js
@@ -37,11 +37,15 @@ function processArguments(args) {
}
}
+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);
View
26 tools/tickprocessor.js
@@ -420,13 +420,11 @@ function UnixCppEntriesProvider(nmExec) {
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 @@ UnixCppEntriesProvider.prototype.parseNextLine = function() {
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 @@ function ArgumentsProcessor(args) {
'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)']
};
Please sign in to comment.
Something went wrong with that request. Please try again.