dumpcpp.mjs 2.08 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
export class CppProcessor extends LogReader {
  constructor(cppEntriesProvider, timedRange, pairwiseTimedRange) {
15 16
    super(timedRange, pairwiseTimedRange);
    this.setDispatchTable({
17
         __proto__: null,
18 19
        '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
  /**
   * @override
   */
  printError(str) {
31
    console.log(str);
32
  }
33

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

42 43 44
  processLogFileInTest(fileName) {
    // Hack file name to avoid dealing with platform specifics.
    this.lastLogFileName_ = 'v8.log';
45
    const contents = d8.file.read(fileName);
46
    this.processLogChunk(contents);
47
  }
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
      self.codeMap_.addStaticCode(fStart, entry);
    });
56
  }
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
                        console.log(printValues.join(','));
66
    }
67
  }
68
}