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
13 #define sqdbg_closesocket(x) closesocket((x))
\r
14 typedef socklen_t int;
\r
18 #include <sys/socket.h>
\r
19 #include <sys/types.h>
\r
20 #include <netinet/in.h>
\r
21 #include <arpa/inet.h>
\r
25 #define sqdbg_closesocket(x) close((x))
\r
27 typedef struct timeval TIMEVAL;
\r
28 #define SOCKET_ERROR -1
\r
29 #define INVALID_SOCKET -1
\r
32 typedef std::basic_string<SQChar> SQDBGString;
\r
34 inline bool dbg_less(const SQChar *x,const SQChar *y)
\r
38 int xl = *x == '\\' ? '/' : tolower(*x);
\r
39 int yl = *y == '\\' ? '/' : tolower(*y);
\r
42 return diff > 0?true:false;
\r
44 }while(*x != 0 && *y != 0);
\r
49 BreakPoint(){_line=0;}
\r
50 BreakPoint(int line, const SQChar *src){ _line = line; _src = src; }
\r
51 BreakPoint(const BreakPoint& bp){ _line = bp._line; _src=bp._src; }
\r
52 inline bool operator<(const BreakPoint& bp) const
\r
56 if(_line==bp._line){
\r
57 return dbg_less(_src.c_str(),bp._src.c_str());
\r
67 Watch() { _id = 0; }
\r
68 Watch(int id,const SQChar *exp) { _id = id; _exp = exp; }
\r
69 Watch(const Watch &w) { _id = w._id; _exp = w._exp; }
\r
70 bool operator<(const Watch& w) const { return _id<w._id; }
\r
71 bool operator==(const Watch& w) const { return _id == w._id; }
\r
76 typedef std::set<BreakPoint> BreakPointSet;
\r
77 typedef BreakPointSet::iterator BreakPointSetItor;
\r
79 typedef std::set<Watch> WatchSet;
\r
80 typedef WatchSet::iterator WatchSetItor;
\r
82 typedef std::vector<SQChar> SQCharVec;
\r
94 SQDbgServer(HSQUIRRELVM v);
\r
97 //returns true if a message has been received
\r
98 bool WaitForClient();
\r
101 void Hook(int type,int line,const SQChar *src,const SQChar *func);
\r
102 void ParseMsg(const char *msg);
\r
103 bool ParseBreakpoint(const char *msg,BreakPoint &out);
\r
104 bool ParseWatch(const char *msg,Watch &out);
\r
105 bool ParseRemoveWatch(const char *msg,int &id);
\r
108 void BreakExecution();
\r
109 void Send(const SQChar *s,...);
\r
110 void SendChunk(const SQChar *chunk);
\r
111 void Break(int line,const SQChar *src,const SQChar *type,const SQChar *error=NULL);
\r
114 void SerializeState();
\r
116 void AddBreakpoint(BreakPoint &bp);
\r
117 void AddWatch(Watch &w);
\r
118 void RemoveWatch(int id);
\r
119 void RemoveBreakpoint(BreakPoint &bp);
\r
122 void SetErrorHandlers();
\r
124 //XML RELATED STUFF///////////////////////
\r
125 #define MAX_NESTING 10
\r
126 struct XMLElementState {
\r
131 XMLElementState xmlstate[MAX_NESTING];
\r
132 int _xmlcurrentement;
\r
134 void BeginDocument() { _xmlcurrentement = -1; }
\r
135 void BeginElement(const SQChar *name);
\r
136 void Attribute(const SQChar *name, const SQChar *value);
\r
137 void EndElement(const SQChar *name);
\r
138 void EndDocument();
\r
140 const SQChar *escape_xml(const SQChar *x);
\r
141 //////////////////////////////////////////////
\r
143 HSQOBJECT _debugroot;
\r
147 BreakPointSet _breakpoints;
\r
149 int _recursionlevel;
\r
154 HSQOBJECT _serializefunc;
\r
155 SQCharVec _scratchstring;
\r
159 #endif //_SQ_DBGSERVER_H_
\r