-
Notifications
You must be signed in to change notification settings - Fork 22
/
DebugInfo.cpp
221 lines (197 loc) · 5.26 KB
/
DebugInfo.cpp
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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
#include "DebugInfo.hpp"
#include <algorithm>
/**
* @brief Default constructor
*
* Creates an empty debug info object
*/
Pex::DebugInfo::DebugInfo() :
m_ModificationTime(0)
{
}
/**
* @brief Default desctrutor
*
*/
Pex::DebugInfo::~DebugInfo()
{
}
/**
* @brief Retrieve the modification time of the original source file.
*
* The modification time is 0 if no debug information are defined in the PEX file.
*
* @return the original modification time.
*/
const std::time_t &Pex::DebugInfo::getModificationTime() const
{
return m_ModificationTime;
}
/**
* @brief Sets the modification time of the original source file.
*
* @param[in] value Modification time to set.
*/
void Pex::DebugInfo::setModificationTime(const std::time_t &value)
{
m_ModificationTime = value;
}
/**
* @brief Retrieve the function info list.
*
* @return a const FunctionInfo collection.
*/
const Pex::DebugInfo::FunctionInfos &Pex::DebugInfo::getFunctionInfos() const
{
return m_FunctionInfo;
}
/**
* @brief Retrieve the function info list.
*
* @return a modifiable FunctionInfo collection.
*/
Pex::DebugInfo::FunctionInfos &Pex::DebugInfo::getFunctionInfos()
{
return m_FunctionInfo;
}
/**
* @brief Get the function info for a given function.
* @param object Name of the object containing the function.
* @param state Name of the state containing the function.
* @param name Name of the function.
* @param type Type of the function (0 normal function, 1 for property getter, 2 for property setter)
* @return A pointer to the function infos, nulltpr if not found.
*/
const Pex::DebugInfo::FunctionInfo* Pex::DebugInfo::getFunctionInfo(const Pex::StringTable::Index &object, const Pex::StringTable::Index &state, const Pex::StringTable::Index &name, FunctionType type) const
{
auto it = std::find_if(m_FunctionInfo.begin(), m_FunctionInfo.end(), [&] (FunctionInfos::const_reference item) {
return item.getObjectName() == object && item.getStateName() == state && item.getFunctionName() == name && item.getFunctionType() == type;
});
if (it == m_FunctionInfo.end())
{
return nullptr;
}
return &(*it);
}
/**
* @brief Default constructor
*/
Pex::DebugInfo::FunctionInfo::FunctionInfo()
{
}
/**
* @brief Default Destructor.
*/
Pex::DebugInfo::FunctionInfo::~FunctionInfo()
{
}
/**
* @brief Retrieve the object name associated with this function debug info
* @return the string index of the object's name
*/
Pex::StringTable::Index Pex::DebugInfo::FunctionInfo::getObjectName() const
{
return m_ObjectName;
}
/**
* @brief Sets the name of the object associated with this function debug info
*
* @param[in] value String index of the object's name.
*/
void Pex::DebugInfo::FunctionInfo::setObjectName(StringTable::Index value)
{
m_ObjectName = value;
}
/**
* @brief Retrieve the state name associated with this function debug info
* @return the string index of the state's name
*/
Pex::StringTable::Index Pex::DebugInfo::FunctionInfo::getStateName() const
{
return m_StateName;
}
/**
* @brief Sets the name of the state associated with this function debug info
*
* @param[in] value String index of the state's name.
*/
void Pex::DebugInfo::FunctionInfo::setStateName(StringTable::Index value)
{
m_StateName = value;
}
/**
* @brief Retrieve the function name associated with this function debug info
* @return the string index of the function's name
*/
Pex::StringTable::Index Pex::DebugInfo::FunctionInfo::getFunctionName() const
{
return m_FunctionName;
}
/**
* @brief Sets the name of the function associated with this function debug info
*
* @param[in] value String index of the function's name.
*/
void Pex::DebugInfo::FunctionInfo::setFunctionName(StringTable::Index value)
{
m_FunctionName = value;
}
/**
* @brief Retrieve the type of the function
*
* @return the type of the function
*/
Pex::DebugInfo::FunctionType Pex::DebugInfo::FunctionInfo::getFunctionType() const
{
return m_FunctionType;
}
/**
* @brief Sets the type of the function
*
* @param[in] value Type of the function
*
* @todo extract an enum
*/
void Pex::DebugInfo::FunctionInfo::setFunctionType(FunctionType value)
{
m_FunctionType = value;
}
/**
* @brief Retrieve the line number array
* Each entry match a bytecode instruction in the function body.
*
* @return the const line number array;
*/
const Pex::DebugInfo::FunctionInfo::LineNumbers &Pex::DebugInfo::FunctionInfo::getLineNumbers() const
{
return m_LineNumbers;
}
/**
* @brief Retrieve the line number array
* Each entry match a bytecode instruction in the function body.
*
* @return the modifiable line number array;
*/
Pex::DebugInfo::FunctionInfo::LineNumbers &Pex::DebugInfo::FunctionInfo::getLineNumbers()
{
return m_LineNumbers;
}
std::vector<uint16_t> Pex::DebugInfo::FunctionInfo::getLineNumbersForIpRange(int64_t begin, int64_t end) const {
if (begin < 0 || end < 0){
return {};
}
// no debug info
if (m_LineNumbers.empty() || begin > m_LineNumbers.size() - 1) {
return {};
}
std::vector<uint16_t> result;
int64_t line = -1;
for (auto i = begin; i <= end; ++i)
{
if (i < m_LineNumbers.size() && std::find(result.begin(), result.end(), m_LineNumbers[i]) == result.end())
{
result.push_back(m_LineNumbers[i]);
}
}
return result;
}