Remove Stream
[folly.git] / folly / experimental / symbolizer / Symbolizer.h
1 /*
2  * Copyright 2012 Facebook, Inc.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *   http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17
18 #ifndef FOLLY_EXPERIMENTAL_SYMBOLIZER_SYMBOLIZER_H_
19 #define FOLLY_EXPERIMENTAL_SYMBOLIZER_SYMBOLIZER_H_
20
21 #include <cstdint>
22 #include <string>
23 #include <unordered_map>
24
25 #include "folly/Range.h"
26 #include "folly/experimental/symbolizer/Elf.h"
27 #include "folly/experimental/symbolizer/Dwarf.h"
28
29 namespace folly {
30 namespace symbolizer {
31
32 /**
33  * Convert an address to symbol name and source location.
34  */
35 class Symbolizer {
36  public:
37   /**
38    * Symbolize an instruction pointer address, returning the symbol name
39    * and file/line number information.
40    *
41    * The returned StringPiece objects are valid for the lifetime of
42    * this Symbolizer object.
43    */
44   bool symbolize(uintptr_t address, folly::StringPiece& symbolName,
45                  Dwarf::LocationInfo& location);
46
47   static void write(std::ostream& out, uintptr_t address,
48                     folly::StringPiece symbolName,
49                     const Dwarf::LocationInfo& location);
50
51  private:
52   ElfFile& getFile(const std::string& name);
53   // cache open ELF files
54   std::unordered_map<std::string, ElfFile> elfFiles_;
55 };
56
57 }  // namespace symbolizer
58 }  // namespace folly
59
60 #endif /* FOLLY_EXPERIMENTAL_SYMBOLIZER_SYMBOLIZER_H_ */
61