-#ifndef _SQ_DBGSERVER_H_\r
-#define _SQ_DBGSERVER_H_\r
-\r
-#define MAX_BP_PATH 512\r
-#define MAX_MSG_LEN 2049\r
-\r
-#include <set>\r
-#include <string>\r
-#include <vector>\r
-\r
-#ifdef _WIN32\r
-#include <winsock.h>\r
-#define sqdbg_closesocket(x) closesocket((x))\r
-typedef socklen_t int;\r
-#else\r
-#include <unistd.h>\r
-#include <errno.h>\r
-#include <sys/socket.h>\r
-#include <sys/types.h>\r
-#include <netinet/in.h>\r
-#include <arpa/inet.h>\r
-#include <netdb.h>\r
-#include <fcntl.h>\r
-\r
-#define sqdbg_closesocket(x) close((x))\r
-typedef int SOCKET;\r
-typedef struct timeval TIMEVAL;\r
-#define SOCKET_ERROR -1\r
-#define INVALID_SOCKET -1\r
-#endif\r
-\r
-typedef std::basic_string<SQChar> SQDBGString;\r
-\r
-inline bool dbg_less(const SQChar *x,const SQChar *y)\r
-{\r
- int n = 0;\r
- do {\r
- int xl = *x == '\\' ? '/' : tolower(*x);\r
- int yl = *y == '\\' ? '/' : tolower(*y);\r
- int diff = xl - yl;\r
- if(diff != 0)\r
- return diff > 0?true:false;\r
- x++; y++;\r
- }while(*x != 0 && *y != 0);\r
- return false;\r
-}\r
-\r
-struct BreakPoint{\r
- BreakPoint(){_line=0;}\r
- BreakPoint(int line, const SQChar *src){ _line = line; _src = src; }\r
- BreakPoint(const BreakPoint& bp){ _line = bp._line; _src=bp._src; }\r
- inline bool operator<(const BreakPoint& bp) const\r
- {\r
- if(_line<bp._line)\r
- return true;\r
- if(_line==bp._line){\r
- return dbg_less(_src.c_str(),bp._src.c_str());\r
- }\r
- return false;\r
- }\r
- \r
- int _line;\r
- SQDBGString _src;\r
-};\r
-\r
-struct Watch{\r
- Watch() { _id = 0; }\r
- Watch(int id,const SQChar *exp) { _id = id; _exp = exp; }\r
- Watch(const Watch &w) { _id = w._id; _exp = w._exp; }\r
- bool operator<(const Watch& w) const { return _id<w._id; }\r
- bool operator==(const Watch& w) const { return _id == w._id; }\r
- int _id;\r
- SQDBGString _exp;\r
-};\r
-\r
-typedef std::set<BreakPoint> BreakPointSet;\r
-typedef BreakPointSet::iterator BreakPointSetItor;\r
-\r
-typedef std::set<Watch> WatchSet;\r
-typedef WatchSet::iterator WatchSetItor;\r
-\r
-typedef std::vector<SQChar> SQCharVec;\r
-struct SQDbgServer{\r
-public:\r
- enum eDbgState{\r
- eDBG_Running,\r
- eDBG_StepOver,\r
- eDBG_StepInto,\r
- eDBG_StepReturn,\r
- eDBG_Suspended,\r
- eDBG_Disabled,\r
- };\r
-\r
- SQDbgServer(HSQUIRRELVM v);\r
- ~SQDbgServer();\r
- bool Init();\r
- //returns true if a message has been received\r
- bool WaitForClient();\r
- bool ReadMsg();\r
- void BusyWait();\r
- void Hook(int type,int line,const SQChar *src,const SQChar *func);\r
- void ParseMsg(const char *msg);\r
- bool ParseBreakpoint(const char *msg,BreakPoint &out);\r
- bool ParseWatch(const char *msg,Watch &out);\r
- bool ParseRemoveWatch(const char *msg,int &id);\r
- void Terminated();\r
- //\r
- void BreakExecution();\r
- void Send(const SQChar *s,...);\r
- void SendChunk(const SQChar *chunk);\r
- void Break(int line,const SQChar *src,const SQChar *type,const SQChar *error=NULL);\r
- \r
-\r
- void SerializeState();\r
- //COMMANDS\r
- void AddBreakpoint(BreakPoint &bp);\r
- void AddWatch(Watch &w);\r
- void RemoveWatch(int id);\r
- void RemoveBreakpoint(BreakPoint &bp);\r
-\r
- //\r
- void SetErrorHandlers();\r
-\r
- //XML RELATED STUFF///////////////////////\r
- #define MAX_NESTING 10\r
- struct XMLElementState {\r
- SQChar name[256];\r
- bool haschildren;\r
- };\r
-\r
- XMLElementState xmlstate[MAX_NESTING];\r
- int _xmlcurrentement;\r
-\r
- void BeginDocument() { _xmlcurrentement = -1; }\r
- void BeginElement(const SQChar *name);\r
- void Attribute(const SQChar *name, const SQChar *value);\r
- void EndElement(const SQChar *name);\r
- void EndDocument();\r
-\r
- const SQChar *escape_xml(const SQChar *x);\r
- //////////////////////////////////////////////\r
- HSQUIRRELVM _v;\r
- HSQOBJECT _debugroot;\r
- eDbgState _state;\r
- SOCKET _accept;\r
- SOCKET _endpoint;\r
- BreakPointSet _breakpoints;\r
- WatchSet _watches;\r
- int _recursionlevel; \r
- int _maxrecursion;\r
- int _nestedcalls;\r
- bool _ready;\r
- bool _autoupdate;\r
- HSQOBJECT _serializefunc;\r
- SQCharVec _scratchstring;\r
- \r
-};\r
-\r
-#endif //_SQ_DBGSERVER_H_ \r
+#ifndef _SQ_DBGSERVER_H_
+#define _SQ_DBGSERVER_H_
+
+#define MAX_BP_PATH 512
+#define MAX_MSG_LEN 2049
+
+#include <set>
+#include <string>
+#include <vector>
+
+#ifdef _WIN32
+#include <winsock.h>
+#define sqdbg_closesocket(x) closesocket((x))
+typedef socklen_t int;
+#else
+#include <unistd.h>
+#include <errno.h>
+#include <sys/socket.h>
+#include <sys/types.h>
+#include <netinet/in.h>
+#include <arpa/inet.h>
+#include <netdb.h>
+#include <fcntl.h>
+
+#define sqdbg_closesocket(x) close((x))
+typedef int SOCKET;
+typedef struct timeval TIMEVAL;
+#define SOCKET_ERROR -1
+#define INVALID_SOCKET -1
+#endif
+
+typedef std::basic_string<SQChar> SQDBGString;
+
+inline bool dbg_less(const SQChar *x,const SQChar *y)
+{
+ int n = 0;
+ do {
+ int xl = *x == '\\' ? '/' : tolower(*x);
+ int yl = *y == '\\' ? '/' : tolower(*y);
+ int diff = xl - yl;
+ if(diff != 0)
+ return diff > 0?true:false;
+ x++; y++;
+ }while(*x != 0 && *y != 0);
+ return false;
+}
+
+struct BreakPoint{
+ BreakPoint(){_line=0;}
+ BreakPoint(int line, const SQChar *src){ _line = line; _src = src; }
+ BreakPoint(const BreakPoint& bp){ _line = bp._line; _src=bp._src; }
+ inline bool operator<(const BreakPoint& bp) const
+ {
+ if(_line<bp._line)
+ return true;
+ if(_line==bp._line){
+ return dbg_less(_src.c_str(),bp._src.c_str());
+ }
+ return false;
+ }
+
+ int _line;
+ SQDBGString _src;
+};
+
+struct Watch{
+ Watch() { _id = 0; }
+ Watch(int id,const SQChar *exp) { _id = id; _exp = exp; }
+ Watch(const Watch &w) { _id = w._id; _exp = w._exp; }
+ bool operator<(const Watch& w) const { return _id<w._id; }
+ bool operator==(const Watch& w) const { return _id == w._id; }
+ int _id;
+ SQDBGString _exp;
+};
+
+typedef std::set<BreakPoint> BreakPointSet;
+typedef BreakPointSet::iterator BreakPointSetItor;
+
+typedef std::set<Watch> WatchSet;
+typedef WatchSet::iterator WatchSetItor;
+
+typedef std::vector<SQChar> SQCharVec;
+struct SQDbgServer{
+public:
+ enum eDbgState{
+ eDBG_Running,
+ eDBG_StepOver,
+ eDBG_StepInto,
+ eDBG_StepReturn,
+ eDBG_Suspended,
+ eDBG_Disabled,
+ };
+
+ SQDbgServer(HSQUIRRELVM v);
+ ~SQDbgServer();
+ bool Init();
+ //returns true if a message has been received
+ bool WaitForClient();
+ bool ReadMsg();
+ void BusyWait();
+ void Hook(int type,int line,const SQChar *src,const SQChar *func);
+ void ParseMsg(const char *msg);
+ bool ParseBreakpoint(const char *msg,BreakPoint &out);
+ bool ParseWatch(const char *msg,Watch &out);
+ bool ParseRemoveWatch(const char *msg,int &id);
+ void Terminated();
+ //
+ void BreakExecution();
+ void Send(const SQChar *s,...);
+ void SendChunk(const SQChar *chunk);
+ void Break(int line,const SQChar *src,const SQChar *type,const SQChar *error=NULL);
+
+
+ void SerializeState();
+ //COMMANDS
+ void AddBreakpoint(BreakPoint &bp);
+ void AddWatch(Watch &w);
+ void RemoveWatch(int id);
+ void RemoveBreakpoint(BreakPoint &bp);
+
+ //
+ void SetErrorHandlers();
+
+ //XML RELATED STUFF///////////////////////
+ #define MAX_NESTING 10
+ struct XMLElementState {
+ SQChar name[256];
+ bool haschildren;
+ };
+
+ XMLElementState xmlstate[MAX_NESTING];
+ int _xmlcurrentement;
+
+ void BeginDocument() { _xmlcurrentement = -1; }
+ void BeginElement(const SQChar *name);
+ void Attribute(const SQChar *name, const SQChar *value);
+ void EndElement(const SQChar *name);
+ void EndDocument();
+
+ const SQChar *escape_xml(const SQChar *x);
+ //////////////////////////////////////////////
+ HSQUIRRELVM _v;
+ HSQOBJECT _debugroot;
+ eDbgState _state;
+ SOCKET _accept;
+ SOCKET _endpoint;
+ BreakPointSet _breakpoints;
+ WatchSet _watches;
+ int _recursionlevel;
+ int _maxrecursion;
+ int _nestedcalls;
+ bool _ready;
+ bool _autoupdate;
+ HSQOBJECT _serializefunc;
+ SQCharVec _scratchstring;
+
+};
+
+#endif //_SQ_DBGSERVER_H_