1// Copyright 2016 the V8 project authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5import { LogReader, parseString } from "./logreader.mjs";
6import { CodeMap, CodeEntry } from "./codemap.mjs";
7export {
8    ArgumentsProcessor, LinuxCppEntriesProvider,
9    WindowsCppEntriesProvider, MacOSCppEntriesProvider,
10  } from  "./tickprocessor.mjs";
11
12
13export class CppProcessor extends LogReader {
14  constructor(cppEntriesProvider, timedRange, pairwiseTimedRange) {
15    super(timedRange, pairwiseTimedRange);
16    this.setDispatchTable({
17         __proto__: null,
18        'shared-library': {
19          parsers: [parseString, parseInt, parseInt, parseInt],
20          processor: this.processSharedLibrary }
21    });
22    this.cppEntriesProvider_ = cppEntriesProvider;
23    this.codeMap_ = new CodeMap();
24    this.lastLogFileName_ = null;
25  }
26
27  /**
28   * @override
29   */
30  printError(str) {
31    console.log(str);
32  }
33
34  processLogFile(fileName) {
35    this.lastLogFileName_ = fileName;
36    let line;
37    while (line = readline()) {
38      this.processLogLine(line);
39    }
40  }
41
42  processLogFileInTest(fileName) {
43    // Hack file name to avoid dealing with platform specifics.
44    this.lastLogFileName_ = 'v8.log';
45    const contents = d8.file.read(fileName);
46    this.processLogChunk(contents);
47  }
48
49  processSharedLibrary(name, startAddr, endAddr, aslrSlide) {
50    const self = this;
51    const libFuncs = this.cppEntriesProvider_.parseVmSymbols(
52        name, startAddr, endAddr, aslrSlide, function(fName, fStart, fEnd) {
53      const entry = new CodeEntry(fEnd - fStart, fName, 'CPP');
54      self.codeMap_.addStaticCode(fStart, entry);
55    });
56  }
57
58  dumpCppSymbols() {
59    const staticEntries = this.codeMap_.getAllStaticEntriesWithAddresses();
60    const total = staticEntries.length;
61    for (let i = 0; i < total; ++i) {
62      const entry = staticEntries[i];
63      const printValues = ['cpp', `0x${entry[0].toString(16)}`, entry[1].size,
64                        `"${entry[1].name}"`];
65                        console.log(printValues.join(','));
66    }
67  }
68}
69