forked from google/centipede
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsymbol_table.h
86 lines (70 loc) · 2.83 KB
/
symbol_table.h
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
// Copyright 2022 The Centipede Authors.
//
// 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
//
// https://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.
#ifndef THIRD_PARTY_CENTIPEDE_SYMBOL_TABLE_H_
#define THIRD_PARTY_CENTIPEDE_SYMBOL_TABLE_H_
#include <cstddef>
#include <istream>
#include <string>
#include <string_view>
#include <vector>
#include "./coverage.h"
namespace centipede {
// Maps integer indices in [0, size) to debug symbols:
// function names, file names, line numbers, column numbers.
class SymbolTable {
public:
// Reads the symbols from a stream produced by `llvm-symbolizer --no-inlines`.
// https://llvm.org/docs/CommandGuide/llvm-symbolizer.html.
// The input consists of tuples of 3 lines each:
// FunctionName
// SourceCodeLocation
// <empty line>
void ReadFromLLVMSymbolizer(std::istream &in);
// Invokes `symbolizer_path --no-inlines` on `binary_path`,
// pipes all PCs from pc_table though it,
// and calls ReadFromLLVMSymbolizer() on the output.
// Possibly uses files `tmp_path1` and `tmp_path2` for temporary storage.
void GetSymbolsFromBinary(const Coverage::PCTable &pc_table,
std::string_view binary_path,
std::string_view symbolizer_path,
std::string_view tmp_path1,
std::string_view tmp_path2);
// Sets the table to `size` symbols all of which are unknown.
void SetAllToUnknown(size_t size);
// Returns the number of symbol entries.
size_t size() const { return entries_.size(); }
// Returns "FunctionName" for idx-th entry.
const std::string &func(size_t idx) const { return entries_[idx].func; }
// Returns source code location for idx-th entry,
const std::string &location(size_t idx) const {
return entries_[idx].file_line_col;
}
// Returns a full human-readable description for idx-th entry.
std::string full_description(size_t idx) const {
return func(idx) + " " + location(idx);
}
// Defines a symbol table entry.
struct Entry {
std::string func;
std::string file_line_col;
};
// Add function name and file location to symbol table.
void AddEntry(std::string_view func, std::string_view file_line_col) {
entries_.push_back({std::string(func), std::string(file_line_col)});
}
private:
std::vector<Entry> entries_;
};
} // namespace centipede
#endif // THIRD_PARTY_CENTIPEDE_SYMBOL_TABLE_H_