OpenClonk
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros
C4AulDebug.h
Go to the documentation of this file.
1 /*
2  * OpenClonk, http://www.openclonk.org
3  *
4  * Copyright (c) 2009-2016, The OpenClonk Team and contributors
5  *
6  * Distributed under the terms of the ISC license; see accompanying file
7  * "COPYING" for details.
8  *
9  * "Clonk" is a registered trademark of Matthes Bender, used with permission.
10  * See accompanying file "TRADEMARK" for details.
11  *
12  * To redistribute this file separately, substitute the full license texts
13  * for the above references.
14  */
15 
16 #ifndef C4AULDEBUG_H
17 #define C4AULDEBUG_H
18 
19 #ifndef NOAULDEBUG
20 
21 #include "network/C4NetIO.h"
22 
23 // manages a debugging interface
24 class C4AulDebug : public C4NetIOTCP, private C4NetIO::CBClass
25 {
26 public:
27  C4AulDebug();
28  ~C4AulDebug();
29  static bool InitDebug(const char *szPassword, const char *szHost);
30  bool Listen(uint16_t iPort, bool fWait);
31  static inline C4AulDebug *GetDebugger() { return pDebug; }
32 
33 private:
34  bool fInit, fConnected;
35  C4AulExec *pExec;
36  static C4AulDebug *pDebug;
37  C4NetIO::addr_t PeerAddr, AllowedAddr;
38  StdCopyStrBuf Password;
39 
40  enum DebugState
41  {
42  DS_Go, // execute until next break point
43  DS_Stop, // execution stopped
44  DS_Step, // executing until next step point
45  DS_StepOver, // executung until next step point on same level or above (or break point)
46  DS_StepOut // executing until next step point above (or break point)
47  };
48  DebugState eState;
49  int iStepCallDepth;
50 
51  // temporary stuff
52  std::list<StdStrBuf*> StackTrace;
53 
54  void ObtainStackTrace(C4AulScriptContext* pCtx, C4AulBCC* pCPos);
55  const char* RelativePath(StdStrBuf &path);
56 
57 private:
58 
59  // Overridden
60  virtual void PackPacket(const C4NetIOPacket &rPacket, StdBuf &rOutBuf);
61  virtual size_t UnpackPacket(const StdBuf &rInBuf, const C4NetIO::addr_t &addr);
62 
63  // Callbacks
64  bool OnConn(const C4NetIO::addr_t &AddrPeer, const C4NetIO::addr_t &AddrConnect, const addr_t *pOwnAddr, C4NetIO *pNetIO);
65  void OnDisconn(const C4NetIO::addr_t &AddrPeer, C4NetIO *pNetIO, const char *szReason);
66  void OnPacket(const class C4NetIOPacket &rPacket, C4NetIO *pNetIO);
67 
68 public:
69  bool isConnected() const { return fConnected; }
70 
71  void SetPassword(const char *szPassword) { Password = szPassword; }
72  bool SetAllowed(const char *szHost);
73  void SetEngine(class C4AulExec *pnExec) { pExec = pnExec; }
74 
75  bool Init(uint16_t iPort);
76  virtual bool Close();
77  virtual bool Close(const addr_t &addr);
78 
79  void ControlScriptEvaluated(const char* script, const char* result);
80 
81  void OnLog(const char *szLine);
82  void DebugStep(C4AulBCC *pCPos, C4Value* stackTop);
83 
84 private:
85  struct ProcessLineResult
86  {
87  bool okay;
88  std::string answer;
89  ProcessLineResult(bool okay, const std::string answer)
90  : okay(okay), answer(answer) {}
91  };
92 
93  StdStrBuf FormatCodePos(C4AulScriptContext *pCtx, C4AulBCC *pCPos);
94 
95  ProcessLineResult ProcessLine(const StdStrBuf &Line);
96 
97  bool SendLine(const char *szType, const char *szData = nullptr);
98 };
99 
100 #endif
101 #endif
Definition: StdBuf.h:37
void SetEngine(class C4AulExec *pnExec)
Definition: C4AulDebug.h:73
void OnLog(const char *szLine)
Definition: C4AulDebug.cpp:199
bool Listen(uint16_t iPort, bool fWait)
Definition: C4AulDebug.cpp:56
bool SetAllowed(const char *szHost)
Definition: C4AulDebug.cpp:154
void SetPassword(const char *szPassword)
Definition: C4AulDebug.h:71
virtual bool Close()
Definition: C4AulDebug.cpp:183
void ControlScriptEvaluated(const char *script, const char *result)
Definition: C4AulDebug.cpp:440
static C4AulDebug * GetDebugger()
Definition: C4AulDebug.h:31
bool Init(uint16_t iPort)
Definition: C4AulDebug.cpp:165
static bool InitDebug(const char *szPassword, const char *szHost)
Definition: C4AulDebug.cpp:45
EndpointAddress addr_t
Definition: C4NetIO.h:212
void DebugStep(C4AulBCC *pCPos, C4Value *stackTop)
Definition: C4AulDebug.cpp:356
bool isConnected() const
Definition: C4AulDebug.h:69