gmDebug.h 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. /*
  2. _____ __ ___ __ ____ _ __
  3. / ___/__ ___ _ ___ / |/ /__ ___ / /_____ __ __/ __/_______(_)__ / /_
  4. / (_ / _ `/ ' \/ -_) /|_/ / _ \/ _ \/ '_/ -_) // /\ \/ __/ __/ / _ \/ __/
  5. \___/\_,_/_/_/_/\__/_/ /_/\___/_//_/_/\_\\__/\_, /___/\__/_/ /_/ .__/\__/
  6. /___/ /_/
  7. See Copyright Notice in gmMachine.h
  8. */
  9. #ifndef _GMDEBUG_H_
  10. #define _GMDEBUG_H_
  11. #include "gmConfig.h"
  12. #include "gmStreamBuffer.h"
  13. #include "gmHash.h"
  14. class gmMachine;
  15. class gmDebugSession;
  16. // bind debug lib
  17. void gmBindDebugLib(gmMachine * a_machine);
  18. // callbacks used to hook up comms
  19. typedef void (GM_CDECL *gmSendDebuggerMessage)(gmDebugSession * a_session, const void * a_command, int a_len);
  20. typedef const void * (GM_CDECL *gmPumpDebuggerMessage)(gmDebugSession * a_session, int &a_len);
  21. #if GMDEBUG_SUPPORT
  22. /// \class gmDebugSession
  23. class gmDebugSession
  24. {
  25. public:
  26. gmDebugSession();
  27. ~gmDebugSession();
  28. /// \brief Update() must be called to pump messages
  29. void Update();
  30. /// \brief Open() will start debugging on a_machine
  31. bool Open(gmMachine * a_machine);
  32. /// \brief Close() will stop debugging
  33. bool Close();
  34. /// \brief GetMachine()
  35. inline gmMachine * GetMachine() const { return m_machine; }
  36. gmSendDebuggerMessage m_sendMessage;
  37. gmPumpDebuggerMessage m_pumpMessage;
  38. void * m_user;
  39. // send message helpers
  40. gmDebugSession &Pack(int a_val);
  41. #ifdef GT_PTR_SIZE_64 // Only needed if types gmptr != gmint
  42. gmDebugSession &Pack(gmint64 a_val);
  43. #endif //GT_PTR_SIZE_64
  44. gmDebugSession &Pack(const char * a_val);
  45. void Send();
  46. // rcv message helpers
  47. gmDebugSession &Unpack(int &a_val);
  48. #ifdef GT_PTR_SIZE_64 // Only needed if types gmptr != gmint
  49. gmDebugSession &Unpack(gmint64 &a_val);
  50. #endif //GT_PTR_SIZE_64
  51. gmDebugSession &Unpack(const char * &a_val);
  52. // helpers
  53. bool AddBreakPoint(const void * a_bp, int a_threadId);
  54. int * FindBreakPoint(const void * a_bp); // return thread id
  55. bool RemoveBreakPoint(const void * a_bp);
  56. private:
  57. class BreakPoint : public gmHashNode<void *, BreakPoint>
  58. {
  59. public:
  60. inline const void * GetKey() const { return m_bp; }
  61. const void * m_bp;
  62. int m_threadId;
  63. };
  64. gmMachine * m_machine;
  65. gmHash<void *, BreakPoint> m_breaks;
  66. gmStreamBufferDynamic m_out;
  67. gmStreamBufferStatic m_in;
  68. };
  69. #endif
  70. #endif // _GMDEBUG_H_