A few quick hacks to get the Squirrel debugger sqdbg to compile on Linux
[supertux.git] / external / squirrel / sqdbg / sqdbgserver.h
1 #ifndef _SQ_DBGSERVER_H_\r
2 #define _SQ_DBGSERVER_H_\r
3 \r
4 #define MAX_BP_PATH 512\r
5 #define MAX_MSG_LEN 2049\r
6 \r
7 #include <set>\r
8 #include <map>\r
9 #include <string>\r
10 #include <vector>\r
11 #ifdef _WIN32\r
12 #  include <winsock.h>\r
13 #else\r
14 #  include <unistd.h>\r
15 #  define SOCKET int\r
16 #  define INVALID_SOCKET (-1)\r
17 #endif\r
18 \r
19 typedef std::basic_string<SQChar> SQDBGString;\r
20 \r
21 struct BreakPoint{\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
26         {\r
27                 if(_line<bp._line)\r
28                         return true;\r
29                 if(_line==bp._line){\r
30                         if(_src<bp._src){\r
31                                 return true;\r
32                         }\r
33                         return false;\r
34                 }\r
35                 return false;\r
36         }\r
37         bool operator==(const BreakPoint& other)\r
38         {\r
39                 if(_line==other._line\r
40                         && (_src==other._src))\r
41                         return true;\r
42                 return false;\r
43         }\r
44         SQInteger _line;\r
45         SQDBGString _src;\r
46 };\r
47 \r
48 struct Watch{\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
54         SQInteger _id;\r
55         SQDBGString _exp;\r
56 };\r
57 \r
58 struct VMState {\r
59         VMState() { _nestedcalls = 0;}\r
60         SQInteger _nestedcalls;\r
61 };\r
62 typedef std::map<HSQUIRRELVM,VMState*> VMStateMap;\r
63 typedef std::set<BreakPoint> BreakPointSet;\r
64 typedef BreakPointSet::iterator BreakPointSetItor;\r
65 \r
66 typedef std::set<Watch> WatchSet;\r
67 typedef WatchSet::iterator WatchSetItor;\r
68 \r
69 typedef std::vector<SQChar> SQCharVec;\r
70 struct SQDbgServer{\r
71 public:\r
72         enum eDbgState{\r
73                 eDBG_Running,\r
74                 eDBG_StepOver,\r
75                 eDBG_StepInto,\r
76                 eDBG_StepReturn,\r
77                 eDBG_Suspended,\r
78                 eDBG_Disabled,\r
79         };\r
80 \r
81         SQDbgServer(HSQUIRRELVM v);\r
82         ~SQDbgServer();\r
83         bool Init();\r
84         //returns true if a message has been received\r
85         bool WaitForClient();\r
86         bool ReadMsg();\r
87         void BusyWait();\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
93         void Terminated();\r
94         //\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
99         \r
100 \r
101         void SerializeState(HSQUIRRELVM v);\r
102         //COMMANDS\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
107 \r
108         //\r
109         void SetErrorHandlers(HSQUIRRELVM v);\r
110         VMState *GetVMState(HSQUIRRELVM v);\r
111 \r
112         //XML RELATED STUFF///////////////////////\r
113         #define MAX_NESTING 10\r
114         struct XMLElementState {\r
115                 SQChar name[256];\r
116                 bool haschildren;\r
117         };\r
118 \r
119         XMLElementState xmlstate[MAX_NESTING];\r
120         SQInteger _xmlcurrentement;\r
121 \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
127 \r
128         const SQChar *escape_xml(const SQChar *x);\r
129         //////////////////////////////////////////////\r
130         HSQUIRRELVM _v;\r
131         HSQOBJECT _debugroot;\r
132         eDbgState _state;\r
133         SOCKET _accept;\r
134         SOCKET _endpoint;\r
135         BreakPointSet _breakpoints;\r
136         WatchSet _watches;\r
137         //int _recursionlevel; \r
138         //int _maxrecursion;\r
139         \r
140         bool _ready;\r
141         bool _autoupdate;\r
142         HSQOBJECT _serializefunc;\r
143         SQCharVec _scratchstring;\r
144 \r
145         SQInteger _line;\r
146         SQDBGString _src;\r
147         SQDBGString _break_type;\r
148         VMStateMap _vmstate;    \r
149 };\r
150 \r
151 #ifdef _WIN32\r
152 #define sqdbg_closesocket(x) closesocket((x))\r
153 #else\r
154 #define sqdbg_closesocket(x) close((x))\r
155 #endif\r
156 \r
157 #endif //_SQ_DBGSERVER_H_ \r