[r571]: cmajor++ / Cm / Cm.Debugger / DebugInfo.hpp  Maximize  Restore  History

Download this file

270 lines (246 with data), 9.9 kB

  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
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
/*========================================================================
Copyright (c) 2012-2014 Seppo Laakko
http://sourceforge.net/projects/cmajor/
Distributed under the GNU General Public License, version 3 (GPLv3).
(See accompanying LICENSE.txt or http://www.gnu.org/licenses/gpl.html)
========================================================================*/
#ifndef CM_DEBUGGER_DEBUGINFO_INCLUDED
#define CM_DEBUGGER_DEBUGINFO_INCLUDED
#include <Cm.Debugger/Gdb.hpp>
#include <Cm.Core/CDebugInfo.hpp>
#include <Cm.Debugger/Util.hpp>
#include <map>
namespace Cm { namespace Debugger {
class SourceFile;
typedef SourceFile* SourceFilePtr;
class SourceFun;
typedef SourceFun* SourceFunPtr;
class DebugInfo;
class DebugLibrary;
typedef DebugLibrary* DebugLibraryPtr;
class DevEnvCommand
{
public:
DevEnvCommand();
DevEnvCommand(const std::string& str_);
DevEnvCommand(const std::string& str_, const std::string& arg_);
DevEnvCommand(const std::string& str_, const std::string& lib_, bool on_);
std::string ToString() const;
bool IsCommand() const;
private:
std::string str;
std::string arg;
std::string lib;
bool on;
};
class SourcePos
{
public:
SourcePos();
SourcePos(SourceFunPtr fun_, Cm::Core::CfgNodePtr node_, int funIndex_);
SourceFileLine FileLine() const;
SourceFileLine CFileLine() const;
SourceFileLine FunCallCFileLine() const;
SourceFunPtr Fun() const { return fun; }
Cm::Core::CfgNodePtr Node() const { return node; }
std::string ToString() const;
bool IsNull() const { return fun == nullptr; }
std::vector<SourcePos> Next();
int FunIndex() const { return funIndex; }
void IncFunIndex() { ++funIndex; }
bool IsMain() const { return isMain; }
void SetMain() { isMain = true; }
SourcePos GetFunCallPos(const SourcePos& funEntryPos) const;
private:
SourceFunPtr fun;
Cm::Core::CfgNodePtr node;
int funIndex;
bool isMain;
};
bool operator==(const SourcePos& left, const SourcePos& right);
class SourceFun
{
public:
SourceFun(SourceFilePtr sourceFile_, Cm::Core::SharedCFunctionDebugInfoPtr funDebugInfo_);
SourceFilePtr File() const { return sourceFile; }
int StartLine() const { return startLine; }
int EndLine() const { return endLine; }
Cm::Core::SharedCFunctionDebugInfoPtr GetFunDebugInfo() const { return funDebugInfo; }
SourcePos GetEntry();
SourcePos GetPos(const SourceFileLine& sourceFileLine);
SourcePos GetCLinePos(int cline) const;
private:
SourceFilePtr sourceFile;
int startLine;
int endLine;
Cm::Core::SharedCFunctionDebugInfoPtr funDebugInfo;
};
typedef std::shared_ptr<SourceFun> SharedSourceFunPtr;
class SourceFile
{
public:
SourceFile(DebugInfo& debugInfo_, DebugLibraryPtr library_, const std::string& sourceFilePath_, const std::string& cFilePath_, const std::string& cdiFilePath_, Cm::Core::SharedCDebugInfoFilePtr debugInfoFile_);
std::string GetLine(int lineNumber, char tag);
int GetLineCount();
const std::string& SourceFilePath() const { return sourceFilePath; }
const std::string& CFilePath() const { return cFilePath; }
SourcePos GetPos(const SourceFileLine& sourceFileLine);
DebugInfo& GetDebugInfo() { return debugInfo; }
DebugLibraryPtr Library() const { return library; }
private:
DebugInfo& debugInfo;
DebugLibraryPtr library;
std::string sourceFilePath;
std::string cFilePath;
std::vector<std::string> lines;
std::string cdiFilePath;
Cm::Core::SharedCDebugInfoFilePtr debugInfoFile;
std::vector<SharedSourceFunPtr> sourceFunctions;
bool linesRead;
void ReadLines();
};
typedef std::shared_ptr<SourceFile> SharedSourceFilePtr;
enum class BreakpointKind
{
user,
temp,
throw_
};
class Breakpoint;
typedef std::shared_ptr<Breakpoint> BreakpointPtr;
class Breakpoint
{
public:
Breakpoint(BreakpointKind kind_, int number_, const SourcePos& sourcePos_, int gdbbp_, const SourceFileLine& gdbPos_);
BreakpointKind Kind() const { return kind; }
int Number() const { return number; }
void SetNumber(int n) { number = n; }
const SourcePos& Pos() const { return sourcePos; }
int GdbBp() const { return gdbbp; }
const SourceFileLine& GetGdbPos() const { return gdbPos; }
std::string ToString() const;
void SetHidden(BreakpointPtr hidden_) { hidden = hidden_; }
BreakpointPtr Hidden() const { return hidden; }
private:
BreakpointKind kind;
int number;
SourcePos sourcePos;
int gdbbp;
SourceFileLine gdbPos;
BreakpointPtr hidden;
};
enum class State
{
debugging, idle, exit
};
typedef std::vector<BreakpointPtr> BreakpointVec;
class DebugLibrary
{
public:
DebugLibrary(const std::string& name_, const std::string& cmdbFilePath_);
const std::string& Name() const { return name; }
const std::string& CmdbFilePath() const { return cmdbFilePath; }
bool Exists() const { return exists; }
void ResetExists() { exists = false; }
bool Enabled() const { return enabled; }
void SetEnabled() { enabled = true; }
void ResetEnabled() { enabled = false; }
private:
std::string name;
std::string cmdbFilePath;
bool exists;
bool enabled;
};
typedef DebugLibrary* DebugLibraryPtr;
class DebugUnit
{
public:
DebugUnit(const std::string& containingLibrary_, const std::string& sourceFilePath_, const std::string& cdiFilePath_);
const std::string& ContainingLibrary() const { return containingLibrary; }
void SetContainingLibrary(const std::string& containingLibrary_) { containingLibrary = containingLibrary_; }
const std::string& SourceFilePath() const { return sourceFilePath; }
const std::string& CdiFilePath() const { return cdiFilePath; }
private:
std::string containingLibrary;
std::string sourceFilePath;
std::string cdiFilePath;
};
class DebugInfo
{
public:
DebugInfo(const std::string& program);
State GetState() const { return state; }
void SetState(State state_);
SourcePos GetPos(const SourceFileLine& sourceFileLine);
SourceFunPtr GetMainFun() const { return mainFun; }
void AddBreakpoint(BreakpointPtr bp);
BreakpointPtr GetBreakpoint(int bp);
void RemoveBreakpoint(BreakpointPtr bp);
BreakpointVec GetUserBreakpoints() const;
BreakpointVec GetTempBreakpoints() const;
BreakpointVec GetThrowBreakpoints() const;
BreakpointPtr GetBreakpoint(const SourceFileLine& sfl) const;
void ClearTempBreakpoints();
int GetNextUserBreakpointNumber() { return nextUserBreakpointNumber++; }
int GetNextTempBreakpointNumber() { return nextTempBreakpointNumber--; }
BreakpointPtr GetGdbBreakpoint(int gdbbp);
void SetCurrentPos(const SourcePos& currentPos_) { currentPos = currentPos_; }
const SourcePos& CurrentPos() const { return currentPos; }
void AddSourceFun(SourceFunPtr sourceFun);
SourceFunPtr GetSourceFun(const std::string& funName) const;
bool PosStackIsEmpty() { return posStack.empty(); }
void ClearPosStack();
void PushPos(const SourcePos& pos);
void PushRetPos(const GdbFrame& gdbFrame);
SourcePos PopPos();
void SetListPos(const SourceFileLine& listPos_);
const SourceFileLine& GetListPos() const { return listPos; }
std::vector<std::string> GetListLines() const;
std::string GetCurrentSourceLine();
const std::string& GetFunDisplayName(const std::string& funMangledName) const;
void AddDebugLibrary(const DebugLibrary& debugLibrary);
void AddDebugUnit(DebugUnit& debugUnit);
void AddThrowPos(const SourcePos& throwPos);
const std::vector<SourcePos>& ThrowPos() const { return throwPositions; }
void AddCatchPos(const SourcePos& catchPos);
const std::vector<SourcePos>& CatchPos() const { return catchPositions; }
const std::vector<DebugLibrary>& DebugLibraries() const { return debugLibraries; }
DebugLibraryPtr GetDebugLibrary(const std::string& libName) const;
private:
State state;
typedef std::map<std::string, DebugLibraryPtr> DebugLibraryMap;
typedef DebugLibraryMap::const_iterator DebugLibraryMapIt;
DebugLibraryMap debugLibraryMap;
std::vector<SharedSourceFilePtr> sourceFiles;
typedef std::map<std::string, SharedSourceFilePtr> SourceFileMap;
typedef SourceFileMap::const_iterator SourceFileMapIt;
SourceFileMap sourceFileMap;
SourceFunPtr mainFun;
int nextUserBreakpointNumber;
int nextTempBreakpointNumber;
typedef std::map<int, BreakpointPtr> BreakpointMap;
typedef BreakpointMap::const_iterator BreakpointMapIt;
BreakpointMap userBreakpoints;
BreakpointMap tempBreakpoints;
BreakpointMap throwBreakpoints;
BreakpointMap gdbBreakpoints;
typedef std::map<SourceFileLine, BreakpointPtr> SourceFileLineBreakpointMap;
typedef SourceFileLineBreakpointMap::const_iterator SourceFileLineBreakpointMapIt;
SourceFileLineBreakpointMap sourceFileLineBreakpointMap;
typedef std::map<std::string, SourceFunPtr> SourceFunMap;
typedef SourceFunMap::const_iterator SourceFunMapIt;
SourceFunMap sourceFunMap;
typedef std::map<std::string, std::string> FunDisplayNameMap;
typedef FunDisplayNameMap::const_iterator FunDisplayNameMapIt;
FunDisplayNameMap funDisplayNameMap;
SourcePos currentPos;
std::vector<SourcePos> posStack;
SourceFileLine listPos;
std::vector<DebugLibrary> debugLibraries;
std::vector<DebugUnit> debugUnits;
std::vector<SourcePos> throwPositions;
std::vector<SourcePos> catchPositions;
DebugLibraryPtr parsingLibrary;
};
} } // namespace Cm::Debugger
#endif // CM_DEBUGGER_DEBUGINFO_INCLUDED

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:

JavaScript is required for this form.





No, thanks