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