Skip to content

Commit b495f1c

Browse files
Implement shared libraries logging on Mac OS X, added required support 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
1 parent 6365113 commit b495f1c

File tree

5 files changed

+65
-7
lines changed

5 files changed

+65
-7
lines changed

src/platform-macos.cc

+13-1
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@
3232
#include <unistd.h>
3333
#include <sys/mman.h>
3434
#include <mach/mach_init.h>
35+
#include <mach-o/dyld.h>
36+
#include <mach-o/getsect.h>
3537

3638
#include <AvailabilityMacros.h>
3739

@@ -205,7 +207,17 @@ PosixMemoryMappedFile::~PosixMemoryMappedFile() {
205207

206208

207209
void OS::LogSharedLibraryAddresses() {
208-
// TODO(1233579): Implement.
210+
unsigned int images_count = _dyld_image_count();
211+
for (unsigned int i = 0; i < images_count; ++i) {
212+
const mach_header* header = _dyld_get_image_header(i);
213+
if (header == NULL) continue;
214+
unsigned int size;
215+
char* code_ptr = getsectdatafromheader(header, SEG_TEXT, SECT_TEXT, &size);
216+
if (code_ptr == NULL) continue;
217+
const uintptr_t slide = _dyld_get_image_vmaddr_slide(i);
218+
const uintptr_t start = reinterpret_cast<uintptr_t>(code_ptr) + slide;
219+
LOG(SharedLibraryEvent(_dyld_get_image_name(i), start, start + size));
220+
}
209221
}
210222

211223

tools/mac-nm

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#!/bin/sh
2+
3+
# This script is a wrapper for OS X nm(1) tool. nm(1) perform C++ function
4+
# names demangling, so we're piping its output to c++filt(1) tool which does it.
5+
# But c++filt(1) comes with XCode (as a part of GNU binutils), so it doesn't
6+
# guaranteed to exist on a system.
7+
#
8+
# An alternative approach is to perform demangling in tick processor, but
9+
# for GNU C++ ABI this is a complex process (see cp-demangle.c sources), and
10+
# can't be done partially, because term boundaries are plain text symbols, such
11+
# as 'N', 'E', so one can't just do a search through a function name, it really
12+
# needs to be parsed, which requires a lot of knowledge to be coded in.
13+
14+
if [ "`which c++filt`" == "" ]; then
15+
nm $@
16+
else
17+
nm $@ | c++filt -p -i
18+
fi

tools/mac-tick-processor

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#!/bin/sh
2+
3+
# A wrapper script to call 'linux-tick-processor' with Mac-specific settings.
4+
5+
tools_path=`cd $(dirname "$0");pwd`
6+
$tools_path/linux-tick-processor --mac --nm=$tools_path/mac-nm $@

tools/tickprocessor-driver.js

+6-2
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,15 @@ function processArguments(args) {
3737
}
3838
}
3939

40+
var entriesProviders = {
41+
'unix': UnixCppEntriesProvider,
42+
'windows': WindowsCppEntriesProvider,
43+
'mac': MacCppEntriesProvider
44+
};
4045

4146
var params = processArguments(arguments);
4247
var tickProcessor = new TickProcessor(
43-
params.platform == 'unix' ? new UnixCppEntriesProvider(params.nm) :
44-
new WindowsCppEntriesProvider(),
48+
new (entriesProviders[params.platform])(params.nm),
4549
params.separateIc,
4650
params.ignoreUnknown,
4751
params.stateFilter);

tools/tickprocessor.js

+22-4
Original file line numberDiff line numberDiff line change
@@ -420,13 +420,11 @@ function UnixCppEntriesProvider(nmExec) {
420420
this.symbols = [];
421421
this.parsePos = 0;
422422
this.nmExec = nmExec;
423+
this.FUNC_RE = /^([0-9a-fA-F]{8}) [tTwW] (.*)$/;
423424
};
424425
inherits(UnixCppEntriesProvider, CppEntriesProvider);
425426

426427

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

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

461459

460+
function MacCppEntriesProvider(nmExec) {
461+
UnixCppEntriesProvider.call(this, nmExec);
462+
this.FUNC_RE = /^([0-9a-fA-F]{8}) [iItT] (.*)$/;
463+
};
464+
inherits(MacCppEntriesProvider, UnixCppEntriesProvider);
465+
466+
467+
MacCppEntriesProvider.prototype.loadSymbols = function(libName) {
468+
this.parsePos = 0;
469+
try {
470+
this.symbols = [os.system(this.nmExec, ['-n', '-f', libName], -1, -1), ''];
471+
} catch (e) {
472+
// If the library cannot be found on this system let's not panic.
473+
this.symbols = '';
474+
}
475+
};
476+
477+
462478
function WindowsCppEntriesProvider() {
463479
this.symbols = '';
464480
this.parsePos = 0;
@@ -538,6 +554,8 @@ function ArgumentsProcessor(args) {
538554
'Specify that we are running on *nix platform'],
539555
'--windows': ['platform', 'windows',
540556
'Specify that we are running on Windows platform'],
557+
'--mac': ['platform', 'mac',
558+
'Specify that we are running on Mac OS X platform'],
541559
'--nm': ['nm', 'nm',
542560
'Specify the \'nm\' executable to use (e.g. --nm=/my_dir/nm)']
543561
};

0 commit comments

Comments
 (0)