dumpcpp.mjs 2.07 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 8 9 10 11 12 13
export {
    ArgumentsProcessor, UnixCppEntriesProvider, 
    WindowsCppEntriesProvider, MacCppEntriesProvider,
  } from  "./tickprocessor.mjs";
  import { inherits } from  "./tickprocessor.mjs";


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

27 28 29 30 31 32
  /**
   * @override
   */
  printError(str) {
    print(str);
  };
33

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

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

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

58
  dumpCppSymbols() {
59 60 61 62 63 64
    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}"`];
65 66
      print(printValues.join(','));
    }
67
  }
68
}