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)
36 // [SuperTux] commented out to avoid compiler warning
39 int xl = *x == '\\' ? '/' : tolower(*x);
40 int yl = *y == '\\' ? '/' : tolower(*y);
43 return diff > 0?true:false;
45 }while(*x != 0 && *y != 0);
50 BreakPoint(){_line=0;}
51 BreakPoint(int line, const SQChar *src){ _line = line; _src = src; }
52 BreakPoint(const BreakPoint& bp){ _line = bp._line; _src=bp._src; }
53 inline bool operator<(const BreakPoint& bp) const
58 return dbg_less(_src.c_str(),bp._src.c_str());
69 Watch(int id,const SQChar *exp) { _id = id; _exp = exp; }
70 Watch(const Watch &w) { _id = w._id; _exp = w._exp; }
71 bool operator<(const Watch& w) const { return _id<w._id; }
72 bool operator==(const Watch& w) const { return _id == w._id; }
77 typedef std::set<BreakPoint> BreakPointSet;
78 typedef BreakPointSet::iterator BreakPointSetItor;
80 typedef std::set<Watch> WatchSet;
81 typedef WatchSet::iterator WatchSetItor;
83 typedef std::vector<SQChar> SQCharVec;
95 SQDbgServer(HSQUIRRELVM v);
98 //returns true if a message has been received
102 void Hook(int type,int line,const SQChar *src,const SQChar *func);
103 void ParseMsg(const char *msg);
104 bool ParseBreakpoint(const char *msg,BreakPoint &out);
105 bool ParseWatch(const char *msg,Watch &out);
106 bool ParseRemoveWatch(const char *msg,int &id);
109 void BreakExecution();
110 void Send(const SQChar *s,...);
111 void SendChunk(const SQChar *chunk);
112 void Break(int line,const SQChar *src,const SQChar *type,const SQChar *error=NULL);
115 void SerializeState();
117 void AddBreakpoint(BreakPoint &bp);
118 void AddWatch(Watch &w);
119 void RemoveWatch(int id);
120 void RemoveBreakpoint(BreakPoint &bp);
123 void SetErrorHandlers();
125 //XML RELATED STUFF///////////////////////
126 #define MAX_NESTING 10
127 struct XMLElementState {
132 XMLElementState xmlstate[MAX_NESTING];
133 int _xmlcurrentement;
135 void BeginDocument() { _xmlcurrentement = -1; }
136 void BeginElement(const SQChar *name);
137 void Attribute(const SQChar *name, const SQChar *value);
138 void EndElement(const SQChar *name);
141 const SQChar *escape_xml(const SQChar *x);
142 //////////////////////////////////////////////
144 HSQOBJECT _debugroot;
148 BreakPointSet _breakpoints;
155 HSQOBJECT _serializefunc;
156 SQCharVec _scratchstring;
160 #endif //_SQ_DBGSERVER_H_