1 #ifndef _SQ_DBGSERVER_H_
\r
2 #define _SQ_DBGSERVER_H_
\r
4 #define MAX_BP_PATH 512
\r
5 #define MAX_MSG_LEN 2049
\r
12 # include <winsock.h>
\r
14 # include <unistd.h>
\r
16 # define INVALID_SOCKET (-1)
\r
19 typedef std::basic_string<SQChar> SQDBGString;
\r
22 BreakPoint(){_line=0;}
\r
23 BreakPoint(SQInteger line, const SQChar *src){ _line = line; _src = src; }
\r
24 BreakPoint(const BreakPoint& bp){ _line = bp._line; _src=bp._src; }
\r
25 bool operator<(const BreakPoint& bp) const
\r
29 if(_line==bp._line){
\r
37 bool operator==(const BreakPoint& other)
\r
39 if(_line==other._line
\r
40 && (_src==other._src))
\r
49 Watch() { _id = 0; }
\r
50 Watch(SQInteger id,const SQChar *exp) { _id = id; _exp = exp; }
\r
51 Watch(const Watch &w) { _id = w._id; _exp = w._exp; }
\r
52 bool operator<(const Watch& w) const { return _id<w._id; }
\r
53 bool operator==(const Watch& w) const { return _id == w._id; }
\r
59 VMState() { _nestedcalls = 0;}
\r
60 SQInteger _nestedcalls;
\r
62 typedef std::map<HSQUIRRELVM,VMState*> VMStateMap;
\r
63 typedef std::set<BreakPoint> BreakPointSet;
\r
64 typedef BreakPointSet::iterator BreakPointSetItor;
\r
66 typedef std::set<Watch> WatchSet;
\r
67 typedef WatchSet::iterator WatchSetItor;
\r
69 typedef std::vector<SQChar> SQCharVec;
\r
81 SQDbgServer(HSQUIRRELVM v);
\r
84 //returns true if a message has been received
\r
85 bool WaitForClient();
\r
88 void Hook(HSQUIRRELVM v,SQInteger type,SQInteger line,const SQChar *src,const SQChar *func);
\r
89 void ParseMsg(const char *msg);
\r
90 bool ParseBreakpoint(const char *msg,BreakPoint &out);
\r
91 bool ParseWatch(const char *msg,Watch &out);
\r
92 bool ParseRemoveWatch(const char *msg,SQInteger &id);
\r
95 void BreakExecution();
\r
96 void Send(const SQChar *s,...);
\r
97 void SendChunk(const SQChar *chunk);
\r
98 void Break(HSQUIRRELVM v,SQInteger line,const SQChar *src,const SQChar *type,const SQChar *error=NULL);
\r
101 void SerializeState(HSQUIRRELVM v);
\r
103 void AddBreakpoint(BreakPoint &bp);
\r
104 void AddWatch(Watch &w);
\r
105 void RemoveWatch(SQInteger id);
\r
106 void RemoveBreakpoint(BreakPoint &bp);
\r
109 void SetErrorHandlers(HSQUIRRELVM v);
\r
110 VMState *GetVMState(HSQUIRRELVM v);
\r
112 //XML RELATED STUFF///////////////////////
\r
113 #define MAX_NESTING 10
\r
114 struct XMLElementState {
\r
119 XMLElementState xmlstate[MAX_NESTING];
\r
120 SQInteger _xmlcurrentement;
\r
122 void BeginDocument();
\r
123 void BeginElement(const SQChar *name);
\r
124 void Attribute(const SQChar *name, const SQChar *value);
\r
125 void EndElement(const SQChar *name);
\r
126 void EndDocument();
\r
128 const SQChar *escape_xml(const SQChar *x);
\r
129 //////////////////////////////////////////////
\r
131 HSQOBJECT _debugroot;
\r
135 BreakPointSet _breakpoints;
\r
137 //int _recursionlevel;
\r
138 //int _maxrecursion;
\r
142 HSQOBJECT _serializefunc;
\r
143 SQCharVec _scratchstring;
\r
147 SQDBGString _break_type;
\r
148 VMStateMap _vmstate;
\r
152 #define sqdbg_closesocket(x) closesocket((x))
\r
154 #define sqdbg_closesocket(x) close((x))
\r
157 #endif //_SQ_DBGSERVER_H_
\r