#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>
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));
+ }
}
--- /dev/null
+#!/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
--- /dev/null
+#!/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 $@
}
}
+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);
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 {
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;
'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)']
};