wxldtarg.h

Go to the documentation of this file.
00001 /////////////////////////////////////////////////////////////////////////////
00002 // Purpose:     Implements the client end of wxLua debugging session
00003 // Author:      J. Winwood, John Labenski, Ray Gilbert
00004 // Created:     May 2002
00005 // RCS-ID:      $Id: wxldtarg.h,v 1.26 2007/11/28 22:55:02 jrl1 Exp $
00006 // Copyright:   (c) 2002 Lomtick Software. All rights reserved.
00007 // Licence:     wxWidgets licence
00008 /////////////////////////////////////////////////////////////////////////////
00009 
00010 #ifndef LUA_DEBUG_TARGET_H
00011 #define LUA_DEBUG_TARGET_H
00012 
00013 #include "wx/thread.h"
00014 #include "wxluasocket/include/wxluasocketdefs.h"
00015 #include "wxlua/include/wxlua.h"
00016 #include "wxluadebug/include/wxldebug.h"
00017 #include "wxluasocket/include/wxlsock.h"
00018 
00019 // ----------------------------------------------------------------------------
00020 // wxLuaDebugTarget - a C++ socket target that the wxLuaDebuggerServer run in Lua
00021 //                    communicates with. Handles the Debugger/Debuggee IO
00022 // ----------------------------------------------------------------------------
00023 
00024 class WXDLLIMPEXP_WXLUASOCKET wxLuaDebugTarget : public wxObject
00025 {
00026 protected:
00027     // -----------------------------------------------------------------------
00028     // wxLuaDebugTarget::LuaThread - a wxThread for the wxLuaDebugTarget
00029     // -----------------------------------------------------------------------
00030     class LuaThread : public wxThread
00031     {
00032         public:
00033             LuaThread(wxLuaDebugTarget *pTarget) : wxThread(wxTHREAD_JOINABLE),
00034                                                    m_pTarget(pTarget) {}
00035         protected:
00036             virtual void *Entry();   // thread execution starts here
00037             virtual void OnExit() {} // called when the thread exits
00038 
00039             wxLuaDebugTarget *m_pTarget;
00040     };
00041 
00042 public:
00043     wxLuaDebugTarget(const wxLuaState& wxlState, const wxString &serverName,
00044                                                  int portNumber);
00045     virtual ~wxLuaDebugTarget();
00046 
00047     bool Run();
00048     void Stop();
00049 
00050     void ThreadFunction();
00051     bool HandleDebuggerCmd(int cmd);
00052     void DisplayError(const wxString& errorMsg) { NotifyError(errorMsg); }
00053 
00054 protected:
00055 
00056     enum debugOperations
00057     {
00058         DEBUG_STEP,
00059         DEBUG_STEPOVER,
00060         DEBUG_STEPOUT,
00061         DEBUG_GO
00062     };
00063 
00064     wxLuaState          m_wxlState;
00065     int                 m_port_number;
00066     wxString            m_serverName;
00067     wxSortedArrayString m_breakPointList;
00068     wxMutex             m_debugMutex;
00069     wxCondition         m_debugCondition;
00070     wxLuaSocket         m_clientSocket;
00071     debugOperations     m_nextOperation;
00072     bool                m_forceBreak;
00073     bool                m_resetRequested;
00074     bool                m_fConnected;
00075     bool                m_fRunning;
00076     bool                m_fStopped;
00077     bool                m_fExiting;
00078     bool                m_fErrorsSeen;
00079     int                 m_nFramesUntilBreak;
00080     wxMutex             m_runMutex;
00081     wxCondition         m_runCondition;
00082     wxArrayString       m_bufferArray;
00083     LuaThread          *m_pThread;
00084     wxArrayInt          m_references;
00085     wxCriticalSection   m_luaCriticalSection;
00086     mutable wxCriticalSection m_breakPointListCriticalSection;
00087 
00088     // Enter/Leave critical section for the threaded sockets
00089     void EnterLuaCriticalSection() { m_luaCriticalSection.Enter(); }
00090     void LeaveLuaCriticalSection() { m_luaCriticalSection.Leave(); }
00091 
00092     void ExitThread();
00093 
00094     // Return a string ("%d:%s", lineNumber, fileName) for the breakpoint
00095     wxString CreateBreakPoint(const wxString &fileName, int lineNumber) const;
00096     // Are we at a set breakpoint?
00097     bool AtBreakPoint(const wxString &fileName, int lineNumber) const;
00098 
00099     bool AddBreakPoint(const wxString &fileName, int lineNumber);
00100     bool RemoveBreakPoint(const wxString &fileName, int lineNumber);
00101     bool ClearAllBreakPoints();
00102     bool Run(const wxString &fileName, const wxString &buffer);
00103     bool Step();
00104     bool StepOver();
00105     bool StepOut();
00106     bool Continue();
00107     bool Break();
00108     bool Reset();
00109     bool EnumerateStack();
00110     bool EnumerateStackEntry(int stackRef);
00111     bool EnumerateTable(int tableRef, int nIndex, long itemNode);
00112     bool EvaluateExpr(int exprRef, const wxString &strExpr);
00113 
00114     bool NotifyBreak(const wxString &fileName, int lineNumber);
00115     bool NotifyPrint(const wxString &errorMsg);
00116     bool NotifyError(const wxString &errorMsg);
00117     bool NotifyExit();
00118     bool NotifyStackEnumeration(const wxLuaDebugData& debugData);
00119     bool NotifyStackEntryEnumeration(int stackRef, const wxLuaDebugData& debugData);
00120     bool NotifyTableEnumeration(long itemNode, const wxLuaDebugData& debugData);
00121     bool NotifyEvaluateExpr(int exprRef, const wxString &strResult);
00122 
00123     // Handle events from the static wxLuaDebugTarget::LuaDebugHook
00124     bool DebugHook(int event);
00125 
00126     bool IsConnected(bool wait_for_connect = true) const;
00127 
00128     // Get the wxLuaDebugTarget that was pushed into Lua
00129     static wxLuaDebugTarget* GetDebugTarget(lua_State* L);
00130 
00131     // Handle the events from lua_sethook()
00132     static void LUACALL LuaDebugHook(lua_State *L, lua_Debug *debug);
00133     // Forward the print statements to NotifyPrint()
00134     static int  LUACALL LuaPrint (lua_State *L);
00135 };
00136 
00137 #endif // LUA_DEBUG_TARGET_H
Generated on Tue Jul 13 10:30:39 2010 for wxLua by  doxygen 1.6.3