dumpcpp.mjs 2.06 KB
Newer Older
1 2 3 4
// Copyright 2016 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

5
import { LogReader, parseString } from "./logreader.mjs";
6
import { CodeMap, CodeEntry } from "./codemap.mjs";
7
export {
8 9
    ArgumentsProcessor, LinuxCppEntriesProvider,
    WindowsCppEntriesProvider, MacOSCppEntriesProvider,
10 11 12
  } from  "./tickprocessor.mjs";


13 14 15 16 17 18
export class CppProcessor extends LogReader {
  constructor(cppEntriesProvider, timedRange, pairwiseTimedRange) {
    super({}, timedRange, pairwiseTimedRange);
    this.dispatchTable_ = {
        'shared-library': {
          parsers: [parseString, parseInt, parseInt, parseInt],
19
          processor: this.processSharedLibrary }
20 21 22 23 24
    };
    this.cppEntriesProvider_ = cppEntriesProvider;
    this.codeMap_ = new CodeMap();
    this.lastLogFileName_ = null;
  }
25

26 27 28 29
  /**
   * @override
   */
  printError(str) {
30
    console.log(str);
31
  }
32

33 34
  processLogFile(fileName) {
    this.lastLogFileName_ = fileName;
35
    let line;
36 37 38
    while (line = readline()) {
      this.processLogLine(line);
    }
39
  }
40

41 42 43
  processLogFileInTest(fileName) {
    // Hack file name to avoid dealing with platform specifics.
    this.lastLogFileName_ = 'v8.log';
44
    const contents = d8.file.read(fileName);
45
    this.processLogChunk(contents);
46
  }
47

48
  processSharedLibrary(name, startAddr, endAddr, aslrSlide) {
49 50
    const self = this;
    const libFuncs = this.cppEntriesProvider_.parseVmSymbols(
51
        name, startAddr, endAddr, aslrSlide, function(fName, fStart, fEnd) {
52
      const entry = new CodeEntry(fEnd - fStart, fName, 'CPP');
53 54
      self.codeMap_.addStaticCode(fStart, entry);
    });
55
  }
56

57
  dumpCppSymbols() {
58 59 60 61 62 63
    const staticEntries = this.codeMap_.getAllStaticEntriesWithAddresses();
    const total = staticEntries.length;
    for (let i = 0; i < total; ++i) {
      const entry = staticEntries[i];
      const printValues = ['cpp', `0x${entry[0].toString(16)}`, entry[1].size,
                        `"${entry[1].name}"`];
64
                        console.log(printValues.join(','));
65
    }
66
  }
67
}