File: instruction_map.h

package info (click to toggle)
autofdo 0.19-2
  • links: PTS
  • area: main
  • in suites: bullseye
  • size: 1,248,592 kB
  • sloc: cpp: 436,213; java: 108,653; objc: 108,251; ansic: 77,107; python: 45,387; cs: 24,942; sh: 16,011; php: 15,368; ruby: 6,255; makefile: 5,807; xml: 2,571; pascal: 388; lisp: 182
file content (87 lines) | stat: -rw-r--r-- 2,524 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
// Copyright 2014 Google Inc. All rights reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//     http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

// Class to build a map from instruction address to its information.

#ifndef AUTOFDO_INSTRUCTION_MAP_H_
#define AUTOFDO_INSTRUCTION_MAP_H_

#include <map>
#include <string>
#include <utility>

#include "base/common.h"
#include "symbol_map.h"


namespace autofdo {

class SampleReader;
class Addr2line;

// InstructionMap stores all the disassembled instructions in
// the binary, and maps it to its information.
class InstructionMap {
 public:
  // Arguments:
  //   addr2line: addr2line class, used to get the source stack.
  //   symbol: the symbol map. This object is not const because
  //           we will update the file name of each symbol
  //           according to the debug info of each instruction.
  InstructionMap(Addr2line *addr2line,
                 SymbolMap *symbol)
      : symbol_map_(symbol), addr2line_(addr2line) {
  }

  // Deletes all the InstInfo, which was allocated in BuildInstMap.
  ~InstructionMap();

  // Returns the size of the instruction map.
  uint64 size() const {
    return inst_map_.size();
  }

  // Builds instruction map for a function.
  void BuildPerFunctionInstructionMap(const string &name, uint64 start_addr,
                                      uint64 end_addr);

  // Contains information about each instruction.
  struct InstInfo {
    const SourceInfo &source(int i) const {
      DCHECK(i >= 0 && source_stack.size() > i);
      return source_stack[i];
    }
    SourceStack source_stack;
  };

  typedef map<uint64, InstInfo *> InstMap;
  const InstMap &inst_map() const {
    return inst_map_;
  }

 private:
  // A map from instruction address to its information.
  InstMap inst_map_;

  // A map from symbol name to symbol data.
  SymbolMap *symbol_map_;

  // Addr2line driver which is used to derive source stack.
  Addr2line *addr2line_;

  DISALLOW_COPY_AND_ASSIGN(InstructionMap);
};
}  // namespace autofdo

#endif  // AUTOFDO_INSTRUCTION_MAP_H_