OLD | NEW |
---|---|
(Empty) | |
1 // Copyright 2016 the V8 project authors. All rights reserved. | |
Michael Achenbach
2016/04/26 12:16:10
nit: Use short copyright header for new files.
lpy
2016/04/26 17:57:58
Done.
| |
2 // Redistribution and use in source and binary forms, with or without | |
3 // modification, are permitted provided that the following conditions are | |
4 // met: | |
5 // | |
6 // * Redistributions of source code must retain the above copyright | |
7 // notice, this list of conditions and the following disclaimer. | |
8 // * Redistributions in binary form must reproduce the above | |
9 // copyright notice, this list of conditions and the following | |
10 // disclaimer in the documentation and/or other materials provided | |
11 // with the distribution. | |
12 // * Neither the name of Google Inc. nor the names of its | |
13 // contributors may be used to endorse or promote products derived | |
14 // from this software without specific prior written permission. | |
15 // | |
16 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | |
17 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | |
18 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | |
19 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | |
20 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | |
21 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | |
22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | |
23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | |
24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | |
25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | |
26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |
27 | |
28 | |
29 // Dump C++ symbols of shared library if possible | |
30 | |
31 function processArguments(args) { | |
32 var processor = new ArgumentsProcessor(args); | |
33 if (processor.parse()) { | |
34 return processor.result(); | |
35 } else { | |
36 processor.printUsageAndExit(); | |
37 } | |
38 } | |
39 | |
40 function initSourceMapSupport() { | |
41 // Pull dev tools source maps into our name space. | |
Yang
2016/04/26 12:52:51
weird whitespace between "maps" and "into"
lpy
2016/04/26 17:57:58
Done.
| |
42 SourceMap = WebInspector.SourceMap; | |
43 | |
44 // Overwrite the load function to load scripts synchronously. | |
45 SourceMap.load = function(sourceMapURL) { | |
46 var content = readFile(sourceMapURL); | |
47 var sourceMapObject = (JSON.parse(content)); | |
48 return new SourceMap(sourceMapURL, sourceMapObject); | |
49 }; | |
50 } | |
51 | |
52 var entriesProviders = { | |
53 'unix': UnixCppEntriesProvider, | |
54 'windows': WindowsCppEntriesProvider, | |
55 'mac': MacCppEntriesProvider | |
56 }; | |
57 | |
58 var params = processArguments(arguments); | |
59 var sourceMap = null; | |
60 if (params.sourceMap) { | |
61 initSourceMapSupport(); | |
62 sourceMap = SourceMap.load(params.sourceMap); | |
63 } | |
64 | |
65 function CppProcessor(cppEntriesProvider, timedRange, pairwiseTimedRange) { | |
66 LogReader.call(this, { | |
67 'shared-library': { parsers: [null, parseInt, parseInt], | |
68 processor: this.processSharedLibrary } | |
69 }, timedRange, pairwiseTimedRange); | |
70 | |
71 this.cppEntriesProvider_ = cppEntriesProvider; | |
72 this.codeMap_ = new CodeMap(); | |
73 this.lastLogFileName_ = null; | |
74 } | |
75 inherits(CppProcessor, LogReader); | |
76 | |
77 /** | |
78 * @override | |
79 */ | |
80 CppProcessor.prototype.printError = function(str) { | |
81 print(str); | |
82 }; | |
83 | |
84 CppProcessor.prototype.processLogFile = function(fileName) { | |
85 this.lastLogFileName_ = fileName; | |
86 var line; | |
87 while (line = readline()) { | |
88 this.processLogLine(line); | |
89 } | |
90 }; | |
91 | |
92 CppProcessor.prototype.processLogFileInTest = function(fileName) { | |
93 // Hack file name to avoid dealing with platform specifics. | |
94 this.lastLogFileName_ = 'v8.log'; | |
95 var contents = readFile(fileName); | |
96 this.processLogChunk(contents); | |
97 }; | |
98 | |
99 CppProcessor.prototype.processSharedLibrary = function( | |
100 name, startAddr, endAddr) { | |
101 var self = this; | |
102 var libFuncs = this.cppEntriesProvider_.parseVmSymbols( | |
103 name, startAddr, endAddr, function(fName, fStart, fEnd) { | |
104 var entry = new CodeMap.CodeEntry(fEnd - fStart, fName, 'CPP'); | |
105 self.codeMap_.addStaticCode(fStart, entry); | |
106 }); | |
107 }; | |
108 | |
109 CppProcessor.prototype.dumpCppSymbols = function() { | |
110 var staticEntries = this.codeMap_.getAllStaticEntriesWithAddresses(); | |
111 var total = staticEntries.length; | |
112 for (var i = 0; i < total; ++i) { | |
113 var entry = staticEntries[i]; | |
114 var printValues = ['cpp', '0x' + entry[0].toString(16), entry[1].size, | |
115 '"' + entry[1].name + '"']; | |
116 print(printValues.join(',')); | |
117 } | |
118 }; | |
119 | |
120 var cppProcessor = new CppProcessor( | |
121 new (entriesProviders[params.platform])(params.nm, params.targetRootFS), | |
122 params.timedRange, params.pairwiseTimedRange); | |
123 cppProcessor.processLogFile(params.logFileName); | |
124 cppProcessor.dumpCppSymbols(); | |
OLD | NEW |