~ubuntu-branches/ubuntu/hardy/codeblocks/hardy-backports

« back to all changes in this revision

Viewing changes to src/include/scripting/include/sqdbgserver.h

  • Committer: Bazaar Package Importer
  • Author(s): Michael Casadevall
  • Date: 2008-07-17 04:39:23 UTC
  • Revision ID: james.westby@ubuntu.com-20080717043923-gmsy5cwkdjswghkm
Tags: upstream-8.02
ImportĀ upstreamĀ versionĀ 8.02

Show diffs side-by-side

added added

removed removed

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