Update to Squirrel 3.0.6
[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 #include <winsock.h>\r
12 \r
13 typedef std::basic_string<SQChar> SQDBGString;\r
14 \r
15 struct BreakPoint{\r
16         BreakPoint(){_line=0;}\r
17         BreakPoint(SQInteger line, const SQChar *src){ _line = line; _src = src; }\r
18         BreakPoint(const BreakPoint& bp){ _line = bp._line; _src=bp._src; }\r
19         bool operator<(const BreakPoint& bp) const\r
20         {\r
21                 if(_line<bp._line)\r
22                         return true;\r
23                 if(_line==bp._line){\r
24                         if(_src<bp._src){\r
25                                 return true;\r
26                         }\r
27                         return false;\r
28                 }\r
29                 return false;\r
30         }\r
31         bool operator==(const BreakPoint& other)\r
32         {\r
33                 if(_line==other._line\r
34                         && (_src==other._src))\r
35                         return true;\r
36                 return false;\r
37         }\r
38         SQInteger _line;\r
39         SQDBGString _src;\r
40 };\r
41 \r
42 struct Watch{\r
43         Watch() { _id = 0; }\r
44         Watch(SQInteger id,const SQChar *exp) { _id = id; _exp = exp; }\r
45         Watch(const Watch &w) { _id = w._id; _exp = w._exp; }\r
46         bool operator<(const Watch& w) const { return _id<w._id; }\r
47         bool operator==(const Watch& w) const { return _id == w._id; }\r
48         SQInteger _id;\r
49         SQDBGString _exp;\r
50 };\r
51 \r
52 struct VMState {\r
53         VMState() { _nestedcalls = 0;}\r
54         SQInteger _nestedcalls;\r
55 };\r
56 typedef std::map<HSQUIRRELVM,VMState*> VMStateMap;\r
57 typedef std::set<BreakPoint> BreakPointSet;\r
58 typedef BreakPointSet::iterator BreakPointSetItor;\r
59 \r
60 typedef std::set<Watch> WatchSet;\r
61 typedef WatchSet::iterator WatchSetItor;\r
62 \r
63 typedef std::vector<SQChar> SQCharVec;\r
64 struct SQDbgServer{\r
65 public:\r
66         enum eDbgState{\r
67                 eDBG_Running,\r
68                 eDBG_StepOver,\r
69                 eDBG_StepInto,\r
70                 eDBG_StepReturn,\r
71                 eDBG_Suspended,\r
72                 eDBG_Disabled,\r
73         };\r
74 \r
75         SQDbgServer(HSQUIRRELVM v);\r
76         ~SQDbgServer();\r
77         bool Init();\r
78         //returns true if a message has been received\r
79         bool WaitForClient();\r
80         bool ReadMsg();\r
81         void BusyWait();\r
82         void Hook(HSQUIRRELVM v,SQInteger type,SQInteger line,const SQChar *src,const SQChar *func);\r
83         void ParseMsg(const char *msg);\r
84         bool ParseBreakpoint(const char *msg,BreakPoint &out);\r
85         bool ParseWatch(const char *msg,Watch &out);\r
86         bool ParseRemoveWatch(const char *msg,SQInteger &id);\r
87         void Terminated();\r
88         //\r
89         void BreakExecution();\r
90         void Send(const SQChar *s,...);\r
91         void SendChunk(const SQChar *chunk);\r
92         void Break(HSQUIRRELVM v,SQInteger line,const SQChar *src,const SQChar *type,const SQChar *error=NULL);\r
93         \r
94 \r
95         void SerializeState(HSQUIRRELVM v);\r
96         //COMMANDS\r
97         void AddBreakpoint(BreakPoint &bp);\r
98         void AddWatch(Watch &w);\r
99         void RemoveWatch(SQInteger id);\r
100         void RemoveBreakpoint(BreakPoint &bp);\r
101 \r
102         //\r
103         void SetErrorHandlers(HSQUIRRELVM v);\r
104         VMState *GetVMState(HSQUIRRELVM v);\r
105 \r
106         //XML RELATED STUFF///////////////////////\r
107         #define MAX_NESTING 10\r
108         struct XMLElementState {\r
109                 SQChar name[256];\r
110                 bool haschildren;\r
111         };\r
112 \r
113         XMLElementState xmlstate[MAX_NESTING];\r
114         SQInteger _xmlcurrentement;\r
115 \r
116         void BeginDocument();\r
117         void BeginElement(const SQChar *name);\r
118         void Attribute(const SQChar *name, const SQChar *value);\r
119         void EndElement(const SQChar *name);\r
120         void EndDocument();\r
121 \r
122         const SQChar *escape_xml(const SQChar *x);\r
123         //////////////////////////////////////////////\r
124         HSQUIRRELVM _v;\r
125         HSQOBJECT _debugroot;\r
126         eDbgState _state;\r
127         SOCKET _accept;\r
128         SOCKET _endpoint;\r
129         BreakPointSet _breakpoints;\r
130         WatchSet _watches;\r
131         //int _recursionlevel; \r
132         //int _maxrecursion;\r
133         \r
134         bool _ready;\r
135         bool _autoupdate;\r
136         HSQOBJECT _serializefunc;\r
137         SQCharVec _scratchstring;\r
138 \r
139         SQInteger _line;\r
140         SQDBGString _src;\r
141         SQDBGString _break_type;\r
142         VMStateMap _vmstate;    \r
143 };\r
144 \r
145 #ifdef _WIN32\r
146 #define sqdbg_closesocket(x) closesocket((x))\r
147 #else\r
148 #define sqdbg_closesocket(x) close((x))\r
149 #endif\r
150 \r
151 #endif //_SQ_DBGSERVER_H_