00001
00002
00003
00004
00005
00006
00007
00008
00009 #ifndef WX_LUA_DEBUG_SERVER_H
00010 #define WX_LUA_DEBUG_SERVER_H
00011
00012 #include "wx/process.h"
00013 #include "wx/thread.h"
00014 #include "wxluasocket/include/wxluasocketdefs.h"
00015 #include "wxluasocket/include/wxlsock.h"
00016 #include "wxluadebug/include/wxldebug.h"
00017 #include "wxluadebug/include/wxlstack.h"
00018
00019 class WXDLLIMPEXP_WXLUASOCKET wxLuaDebuggerBase;
00020 class WXDLLIMPEXP_WXLUASOCKET wxLuaDebuggerEvent;
00021
00022
00023
00024
00025
00026 enum
00027 {
00028 ID_WXLUASOCKET_DEBUGGEE_PROCESS = 1500
00029 };
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039 enum wxLuaSocketDebuggeeEvents_Type
00040 {
00041 wxLUASOCKET_DEBUGGEE_EVENT_NONE = 0,
00042
00043 wxLUASOCKET_DEBUGGEE_EVENT_BREAK,
00044 wxLUASOCKET_DEBUGGEE_EVENT_PRINT,
00045 wxLUASOCKET_DEBUGGEE_EVENT_ERROR,
00046 wxLUASOCKET_DEBUGGEE_EVENT_EXIT,
00047 wxLUASOCKET_DEBUGGEE_EVENT_STACK_ENUM,
00048 wxLUASOCKET_DEBUGGEE_EVENT_STACK_ENTRY_ENUM,
00049 wxLUASOCKET_DEBUGGEE_EVENT_TABLE_ENUM,
00050 wxLUASOCKET_DEBUGGEE_EVENT_EVALUATE_EXPR,
00051
00052 wxLUASOCKET_DEBUGGEE_EVENT__COUNT
00053 };
00054
00055
00056
00057
00058
00059
00060
00061
00062 enum wxLuaSocketDebuggerCommands_Type
00063 {
00064 wxLUASOCKET_DEBUGGER_CMD_NONE = 0,
00065
00066 wxLUASOCKET_DEBUGGER_CMD_ADD_BREAKPOINT = 100,
00067 wxLUASOCKET_DEBUGGER_CMD_REMOVE_BREAKPOINT,
00068 wxLUASOCKET_DEBUGGER_CMD_DISABLE_BREAKPOINT,
00069 wxLUASOCKET_DEBUGGER_CMD_ENABLE_BREAKPOINT,
00070 wxLUASOCKET_DEBUGGER_CMD_CLEAR_ALL_BREAKPOINTS,
00071 wxLUASOCKET_DEBUGGER_CMD_RUN_BUFFER,
00072 wxLUASOCKET_DEBUGGER_CMD_DEBUG_STEP,
00073 wxLUASOCKET_DEBUGGER_CMD_DEBUG_STEPOVER,
00074 wxLUASOCKET_DEBUGGER_CMD_DEBUG_STEPOUT,
00075 wxLUASOCKET_DEBUGGER_CMD_DEBUG_CONTINUE,
00076 wxLUASOCKET_DEBUGGER_CMD_DEBUG_BREAK,
00077 wxLUASOCKET_DEBUGGER_CMD_RESET,
00078 wxLUASOCKET_DEBUGGER_CMD_ENUMERATE_STACK,
00079 wxLUASOCKET_DEBUGGER_CMD_ENUMERATE_STACK_ENTRY,
00080 wxLUASOCKET_DEBUGGER_CMD_ENUMERATE_TABLE_REF,
00081 wxLUASOCKET_DEBUGGER_CMD_CLEAR_DEBUG_REFERENCES,
00082 wxLUASOCKET_DEBUGGER_CMD_EVALUATE_EXPR,
00083 };
00084
00085
00086
00087
00088
00089
00090
00091
00092
00093
00094
00095
00096
00097 class WXDLLIMPEXP_WXLUASOCKET wxLuaDebuggerStackDialog : public wxLuaStackDialog
00098 {
00099 public:
00100 wxLuaDebuggerStackDialog(wxLuaDebuggerBase* luaDebugger,
00101 wxWindow* parent, wxWindowID id = wxID_ANY,
00102 const wxString& title = wxT("wxLua Stack"),
00103 const wxPoint& pos = wxDefaultPosition,
00104 const wxSize& size = wxDefaultSize);
00105
00106 virtual ~wxLuaDebuggerStackDialog();
00107
00108
00109
00110
00111
00112 virtual void EnumerateStack();
00113 virtual void EnumerateStackEntry(int nEntry);
00114 virtual void EnumerateTable(int nRef, int nEntry, long lc_item);
00115 virtual void EnumerateGlobalData(long lc_item);
00116
00117
00118
00119 wxLuaDebuggerBase* m_luaDebugger;
00120
00121 private:
00122 DECLARE_ABSTRACT_CLASS(wxLuaDebuggerStackDialog)
00123 };
00124
00125
00126
00127
00128
00129
00130 class wxLuaDebuggerProcess : public wxProcess
00131 {
00132 public:
00133
00134
00135 wxLuaDebuggerProcess(wxLuaDebuggerBase* debugger, wxWindowID id)
00136 : wxProcess(NULL, id), m_debugger(debugger) {}
00137
00138
00139 virtual void OnTerminate(int pid, int status);
00140
00141 wxLuaDebuggerBase* m_debugger;
00142 };
00143
00144
00145
00146
00147
00148
00149
00150
00151
00152
00153
00154 class WXDLLIMPEXP_WXLUASOCKET wxLuaDebuggerBase : public wxEvtHandler
00155 {
00156 public:
00157 wxLuaDebuggerBase(int port_number);
00158 virtual ~wxLuaDebuggerBase();
00159
00160
00161
00162 virtual bool StartServer() = 0;
00163
00164 virtual bool StopServer() = 0;
00165
00166
00167 virtual long StartClient();
00168
00169
00170
00171
00172 bool AddBreakPoint(const wxString &fileName, int lineNumber);
00173 bool RemoveBreakPoint(const wxString &fileName, int lineNumber);
00174 bool DisableBreakPoint(const wxString &fileName, int lineNumber);
00175 bool EnableBreakPoint(const wxString &fileName, int lineNumber);
00176 bool ClearAllBreakPoints();
00177 bool Run(const wxString &fileName, const wxString &buffer);
00178 bool Step();
00179 bool StepOver();
00180 bool StepOut();
00181 bool Continue();
00182 bool Break();
00183 bool Reset();
00184 bool EnumerateStack();
00185 bool EnumerateStackEntry(int stackEntry);
00186 bool EnumerateTable(int tableRef, int nIndex, long nItemNode);
00187 bool ClearDebugReferences();
00188 bool EvaluateExpr(int exprRef, const wxString &strExpression);
00189
00190
00191
00192
00193
00194 virtual int HandleDebuggeeEvent(int event_type);
00195
00196
00197 virtual wxLuaSocketBase* GetSocketBase() = 0;
00198
00199
00200 virtual bool CheckSocketConnected(bool send_event = true, const wxString& msg = wxEmptyString);
00201
00202
00203 virtual bool CheckSocketRead(bool read_ok, const wxString& msg = wxEmptyString);
00204
00205
00206 virtual bool CheckSocketWrite(bool write_ok, const wxString& msg = wxEmptyString);
00207
00208
00209 virtual wxString GetSocketErrorMsg() = 0;
00210
00211
00212 virtual void SendEvent(wxEvent& event) { AddPendingEvent(event); }
00213
00214
00215 wxLuaStackDialog* GetStackDialog() { return m_stackDialog; }
00216 void SetStackDialog(wxLuaStackDialog *stackDialog) { m_stackDialog = stackDialog; }
00217
00218 bool DisplayStackDialog(wxWindow *parent, wxWindowID id = wxID_ANY);
00219
00220
00221 void OnDebugStackEnum(wxLuaDebuggerEvent &event);
00222 void OnDebugTableEnum(wxLuaDebuggerEvent &event);
00223 void OnDebugStackEntryEnum(wxLuaDebuggerEvent &event);
00224
00225
00226 void OnEndDebugeeProcess(wxProcessEvent& event);
00227
00228
00229 int GetPortNumber() const { return m_port_number; }
00230
00231
00232 wxLuaDebuggerProcess* GetDebuggeeProcess() { return m_debuggeeProcess; }
00233 long GetDebuggeeProcessId() const { return m_debuggeeProcessID; }
00234 bool KillDebuggee();
00235
00236
00237
00238
00239
00240 static void SetProgramName(const wxString& name) { sm_programName = name; }
00241 static wxString GetProgramName() { return sm_programName; }
00242
00243
00244
00245
00246
00247 static void SetNetworkName(const wxString& name) { sm_networkName = name; }
00248 static wxString GetNetworkName() { return sm_networkName; }
00249
00250
00251
00252 int m_port_number;
00253 wxLuaStackDialog *m_stackDialog;
00254 wxLuaDebuggerProcess *m_debuggeeProcess;
00255 long m_debuggeeProcessID;
00256
00257 wxCriticalSection m_acceptSockCritSect;
00258 wxCriticalSection m_processCritSect;
00259
00260 static wxString sm_programName;
00261 static wxString sm_networkName;
00262
00263 friend class wxLuaDebuggerProcess;
00264
00265 private:
00266 DECLARE_EVENT_TABLE();
00267 DECLARE_ABSTRACT_CLASS(wxLuaDebuggerBase)
00268 };
00269
00270 #define WXLUASOCKET_USE_C_SOCKET
00271 #ifdef WXLUASOCKET_USE_C_SOCKET
00272
00273
00274
00275
00276
00277
00278 class WXDLLIMPEXP_WXLUASOCKET wxLuaDebuggerCServer : public wxLuaDebuggerBase
00279 {
00280 protected:
00281
00282
00283
00284 class LuaThread : public wxThread
00285 {
00286 public:
00287 LuaThread(wxLuaDebuggerCServer *pServer) : wxThread(wxTHREAD_JOINABLE),
00288 m_pServer(pServer) {}
00289
00290 virtual void *Entry();
00291 virtual void OnExit();
00292
00293 wxLuaDebuggerCServer *m_pServer;
00294 };
00295
00296 public:
00297 wxLuaDebuggerCServer(int port_number);
00298 virtual ~wxLuaDebuggerCServer();
00299
00300
00301
00302 virtual bool StartServer();
00303
00304 virtual bool StopServer();
00305
00306
00307 virtual long StartClient();
00308
00309 virtual wxLuaSocketBase* GetSocketBase() { return m_acceptedSocket; }
00310
00311 virtual wxString GetSocketErrorMsg();
00312
00313
00314
00315
00316
00317 void ThreadFunction();
00318
00319 bool WaitForConnect(int timeOut);
00320
00321 wxLuaSocket *m_serverSocket;
00322 wxLuaSocket *m_acceptedSocket;
00323 wxLuaDebuggerCServer::LuaThread *m_pThread;
00324 bool m_shutdown;
00325
00326 private:
00327 DECLARE_ABSTRACT_CLASS(wxLuaDebuggerCServer)
00328 };
00329
00330 typedef wxLuaDebuggerCServer wxLuaDebuggerServer;
00331
00332 #else // !WXLUASOCKET_USE_C_SOCKET
00333
00334
00335
00336
00337
00338
00339 class WXDLLIMPEXP_WXLUASOCKET wxLuaDebuggerwxSocketServer : public wxLuaDebuggerBase
00340 {
00341 public:
00342 wxLuaDebuggerwxSocketServer(int port_number);
00343 virtual ~wxLuaDebuggerwxSocketServer();
00344
00345
00346
00347 virtual bool StartServer();
00348
00349 virtual bool StopServer();
00350
00351 virtual long StartClient();
00352
00353 virtual wxLuaSocketBase* GetSocketBase() { return m_acceptedSocket; }
00354
00355 virtual wxString GetSocketErrorMsg();
00356
00357
00358
00359 virtual void SendEvent(wxEvent& event) { ProcessEvent(event); }
00360
00361 void OnServerEvent(wxSocketEvent& event);
00362 void OnSocketEvent(wxSocketEvent& event);
00363
00364 protected:
00365 wxSocketServer *m_serverSocket;
00366 wxLuawxSocket *m_acceptedSocket;
00367
00368 private:
00369 DECLARE_EVENT_TABLE();
00370 DECLARE_ABSTRACT_CLASS(wxLuaDebuggerwxSocketServer)
00371 };
00372
00373 typedef wxLuaDebuggerwxSocketServer wxLuaDebuggerServer;
00374
00375 #endif // WXLUASOCKET_USE_C_SOCKET
00376
00377
00378
00379
00380
00381
00382 class WXDLLIMPEXP_WXLUASOCKET wxLuaDebuggerEvent : public wxEvent
00383 {
00384 public:
00385 wxLuaDebuggerEvent(const wxLuaDebuggerEvent& event);
00386 wxLuaDebuggerEvent(wxEventType eventType = wxEVT_NULL,
00387 wxObject* eventObject = NULL,
00388 int lineNumber = 0,
00389 const wxString &fileName = wxEmptyString,
00390 bool enabledFlag = false);
00391
00392 void SetMessage(const wxString &message);
00393 void SetDebugData(long nReference, const wxLuaDebugData& pDebugData = wxNullLuaDebugData);
00394
00395 int GetLineNumber() const { return m_line_number;}
00396 wxString GetFileName() const { return m_fileName; }
00397 wxString GetMessage() const { return m_strMessage; }
00398 bool HasMessage() const { return m_has_message; }
00399 long GetReference() const { return m_lua_ref; }
00400 wxLuaDebugData GetDebugData() const { return m_debugData; }
00401 bool GetEnabledFlag() const { return m_enabled_flag; }
00402
00403 protected:
00404 virtual wxEvent* Clone() const { return new wxLuaDebuggerEvent(*this); }
00405
00406 int m_line_number;
00407 wxString m_fileName;
00408 wxString m_strMessage;
00409 bool m_has_message;
00410 long m_lua_ref;
00411 wxLuaDebugData m_debugData;
00412 bool m_enabled_flag;
00413
00414 private:
00415 DECLARE_DYNAMIC_CLASS(wxLuaDebuggerEvent)
00416 };
00417
00418 typedef void (wxEvtHandler::*wxLuaDebuggerEventFunction)(wxLuaDebuggerEvent&);
00419
00420 BEGIN_DECLARE_EVENT_TYPES()
00421
00422 DECLARE_EXPORTED_EVENT_TYPE(WXDLLIMPEXP_WXLUASOCKET, wxEVT_WXLUA_DEBUGGER_DEBUGGEE_CONNECTED, 2510)
00423
00424
00425 DECLARE_EXPORTED_EVENT_TYPE(WXDLLIMPEXP_WXLUASOCKET, wxEVT_WXLUA_DEBUGGER_DEBUGGEE_DISCONNECTED, 2510)
00426
00427 DECLARE_EXPORTED_EVENT_TYPE(WXDLLIMPEXP_WXLUASOCKET, wxEVT_WXLUA_DEBUGGER_BREAK, 2511)
00428
00429 DECLARE_EXPORTED_EVENT_TYPE(WXDLLIMPEXP_WXLUASOCKET, wxEVT_WXLUA_DEBUGGER_PRINT, 2512)
00430
00431 DECLARE_EXPORTED_EVENT_TYPE(WXDLLIMPEXP_WXLUASOCKET, wxEVT_WXLUA_DEBUGGER_ERROR, 2513)
00432
00433 DECLARE_EXPORTED_EVENT_TYPE(WXDLLIMPEXP_WXLUASOCKET, wxEVT_WXLUA_DEBUGGER_EXIT, 2514)
00434
00435 DECLARE_EXPORTED_EVENT_TYPE(WXDLLIMPEXP_WXLUASOCKET, wxEVT_WXLUA_DEBUGGER_STACK_ENUM, 2515)
00436
00437 DECLARE_EXPORTED_EVENT_TYPE(WXDLLIMPEXP_WXLUASOCKET, wxEVT_WXLUA_DEBUGGER_STACK_ENTRY_ENUM, 2516)
00438
00439 DECLARE_EXPORTED_EVENT_TYPE(WXDLLIMPEXP_WXLUASOCKET, wxEVT_WXLUA_DEBUGGER_TABLE_ENUM, 2517)
00440
00441 DECLARE_EXPORTED_EVENT_TYPE(WXDLLIMPEXP_WXLUASOCKET, wxEVT_WXLUA_DEBUGGER_EVALUATE_EXPR, 2518)
00442
00443
00444
00445 END_DECLARE_EVENT_TYPES()
00446
00447 #define wxLuaDebuggerEventHandler(func) \
00448 (wxObjectEventFunction)(wxEventFunction)wxStaticCastEvent(wxLuaDebuggerEventFunction, &func)
00449
00450 #define EVT_WXLUA_DEBUGGER_DEBUGGEE_CONNECTED(id, fn) DECLARE_EVENT_TABLE_ENTRY(wxEVT_WXLUA_DEBUGGER_DEBUGGEE_CONNECTED, id, -1, wxLuaDebuggerEventHandler(fn), (wxObject *) NULL),
00451 #define EVT_WXLUA_DEBUGGER_DEBUGGEE_DISCONNECTED(id, fn) DECLARE_EVENT_TABLE_ENTRY(wxEVT_WXLUA_DEBUGGER_DEBUGGEE_DISCONNECTED, id, -1, wxLuaDebuggerEventHandler(fn), (wxObject *) NULL),
00452 #define EVT_WXLUA_DEBUGGER_BREAK(id, fn) DECLARE_EVENT_TABLE_ENTRY(wxEVT_WXLUA_DEBUGGER_BREAK, id, -1, wxLuaDebuggerEventHandler(fn), (wxObject *) NULL),
00453 #define EVT_WXLUA_DEBUGGER_PRINT(id, fn) DECLARE_EVENT_TABLE_ENTRY(wxEVT_WXLUA_DEBUGGER_PRINT, id, -1, wxLuaDebuggerEventHandler(fn), (wxObject *) NULL),
00454 #define EVT_WXLUA_DEBUGGER_ERROR(id, fn) DECLARE_EVENT_TABLE_ENTRY(wxEVT_WXLUA_DEBUGGER_ERROR, id, -1, wxLuaDebuggerEventHandler(fn), (wxObject *) NULL),
00455 #define EVT_WXLUA_DEBUGGER_EXIT(id, fn) DECLARE_EVENT_TABLE_ENTRY(wxEVT_WXLUA_DEBUGGER_EXIT, id, -1, wxLuaDebuggerEventHandler(fn), (wxObject *) NULL),
00456 #define EVT_WXLUA_DEBUGGER_STACK_ENUM(id, fn) DECLARE_EVENT_TABLE_ENTRY(wxEVT_WXLUA_DEBUGGER_STACK_ENUM, id, -1, wxLuaDebuggerEventHandler(fn), (wxObject *) NULL),
00457 #define EVT_WXLUA_DEBUGGER_STACK_ENTRY_ENUM(id, fn) DECLARE_EVENT_TABLE_ENTRY(wxEVT_WXLUA_DEBUGGER_STACK_ENTRY_ENUM, id, -1, wxLuaDebuggerEventHandler(fn), (wxObject *) NULL),
00458 #define EVT_WXLUA_DEBUGGER_TABLE_ENUM(id, fn) DECLARE_EVENT_TABLE_ENTRY(wxEVT_WXLUA_DEBUGGER_TABLE_ENUM, id, -1, wxLuaDebuggerEventHandler(fn), (wxObject *) NULL),
00459 #define EVT_WXLUA_DEBUGGER_EVALUATE_EXPR(id, fn) DECLARE_EVENT_TABLE_ENTRY(wxEVT_WXLUA_DEBUGGER_EVALUATE_EXPR, id, -1, wxLuaDebuggerEventHandler(fn), (wxObject *) NULL),
00460
00461
00462
00463 #endif // WX_LUA_DEBUG_SERVER_H