Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

300 lines
6.2 KiB

  1. #ifndef __SVCOBJDEF_H
  2. #define __SVCOBJDEF_H
  3. #include "genthread.h"
  4. #include "evenhand.h"
  5. #include "gencriticalsection.h"
  6. #include "EmErr.h"
  7. typedef struct tagSession {
  8. HRESULT hrDebug;
  9. PGENTHREAD pThread;
  10. PEmObject pEmObj;
  11. } EMSession, *PEMSession, **PPEMSession;
  12. typedef CMap < unsigned char*, unsigned char*, PEMSession, PEMSession > SessionsTable;
  13. // DbgPrompt doesn't allow buffers greater than 512 bytes
  14. // so limit these strings.
  15. #define MAX_COMMAND 512
  16. class CExcepMonSessionManager
  17. {
  18. public:
  19. HRESULT AdoptThisSession( unsigned char *pGuid);
  20. HRESULT
  21. OrphanThisSession
  22. (
  23. IN unsigned char *pGuid
  24. );
  25. HRESULT
  26. IsSessionOrphaned
  27. (
  28. IN unsigned char *pGuid
  29. );
  30. CExcepMonSessionManager ();
  31. ~CExcepMonSessionManager ();
  32. void CleanUp();
  33. HRESULT
  34. AddSession
  35. (
  36. IN PEmObject pEmObj,
  37. OUT PEMSession *ppNewEmSess
  38. );
  39. HRESULT
  40. RemoveSession
  41. (
  42. IN unsigned char *pGuidStream
  43. );
  44. HRESULT
  45. GetSession
  46. (
  47. IN unsigned char *pGuid,
  48. OUT PPEMSession ppEmSess
  49. );
  50. HRESULT
  51. GetSession
  52. (
  53. IN UINT nPid,
  54. IN BSTR bstrImageName,
  55. OUT PEMSession *ppEmSess
  56. );
  57. HRESULT
  58. GetSessionStatus
  59. (
  60. IN unsigned char *pGuid,
  61. OUT LONG *plSessStaus = NULL,
  62. OUT HRESULT *plHr = NULL
  63. );
  64. HRESULT
  65. SetSessionStatus
  66. (
  67. IN unsigned char *pGuid,
  68. IN LONG lSessStaus,
  69. IN HRESULT lHr,
  70. IN LPCTSTR lpszErrText = NULL,
  71. IN bool bRetainOrphanState = true,
  72. IN bool bSetEndTime = false
  73. );
  74. HRESULT StopAllThreads ( void ) ;
  75. HRESULT
  76. UpdateSessObject
  77. (
  78. IN unsigned char *pGuid,
  79. IN PEmObject pEmObj
  80. );
  81. HRESULT
  82. UpdateSessObject
  83. (
  84. IN unsigned char *pGuid,
  85. IN DWORD dwEmObjFlds,
  86. IN PEmObject pEmObj
  87. );
  88. HRESULT
  89. UpdateSessObject
  90. (
  91. IN unsigned char *pGuid,
  92. IN DWORD dwEmObjFlds,
  93. IN short type = EMOBJ_UNKNOWNOBJECT,
  94. IN short type2 = SessType_Automatic,
  95. IN unsigned char *pguidstream = NULL,
  96. IN LONG nId = 0,
  97. IN TCHAR *pszName = NULL,
  98. IN TCHAR *pszSecName = NULL,
  99. IN LONG nStatus = STAT_SESS_NONE_STAT_NONE,
  100. IN DATE dateStart = 0L,
  101. IN DATE dateEnd = 0L,
  102. IN TCHAR *pszBucket1 = NULL,
  103. IN DWORD dwBucket1 = 0L,
  104. IN HRESULT hr = E_FAIL
  105. );
  106. HRESULT IsAlreadyBeingDebugged(PEmObject pEmObj);
  107. HRESULT GetNumberOfStoppedSessions(DWORD *pdwNumOfStoppedSessions);
  108. HRESULT GetNumberOfSessions(DWORD *pdwNumOfSessions);
  109. HRESULT
  110. GetFirstStoppedSession
  111. (
  112. OUT POSITION *ppos,
  113. OUT unsigned char **ppGuid,
  114. OUT PEMSession *ppEmSess
  115. );
  116. HRESULT
  117. GetNextStoppedSession
  118. (
  119. IN OUT POSITION *ppos,
  120. OUT unsigned char **ppGuid,
  121. OUT PEMSession *ppEmSess
  122. );
  123. BOOL
  124. IsPortInUse
  125. (
  126. IN UINT nPort
  127. );
  128. HRESULT
  129. GetFirstSession
  130. (
  131. OUT POSITION *ppos,
  132. OUT PEMSession *ppEmSess
  133. );
  134. HRESULT
  135. GetNextSession
  136. (
  137. IN OUT POSITION *ppos,
  138. OUT PEMSession *ppEmSess
  139. );
  140. HRESULT
  141. PersistSessions
  142. (
  143. IN LPCTSTR lpFilePath
  144. );
  145. HRESULT
  146. InitSessionsFromLog
  147. (
  148. IN LPCTSTR lpFilePath,
  149. IN EmStatusHiWord lStatusHi = STAT_SESS_NONE,
  150. IN EmStatusLoWord lStatusLo = STAT_NONE
  151. );
  152. HRESULT
  153. AddLoggedSession
  154. (
  155. IN PEmObject pEmObj
  156. );
  157. protected:
  158. HRESULT InternalStopAllThreads ( void );
  159. HRESULT InternalRemoveSession ( PEMSession pEMSession );
  160. private:
  161. SessionsTable m_SessTable;
  162. PGenCriticalSection m_pcs;
  163. };
  164. //
  165. // Debug Service
  166. //
  167. typedef enum eDBGServiceRequested {
  168. DBGService_None,
  169. DBGService_CreateMiniDump,
  170. DBGService_CreateUserDump,
  171. DBGService_Stop,
  172. DBGService_Cancel,
  173. DBGService_Go,
  174. DBGService_HandleException,
  175. DBGService_Error
  176. } eDBGServiceRequested;
  177. class CEMSessionThread : public CGenThread {
  178. public:
  179. UINT m_nPort;
  180. SessionType eDBGSessType;
  181. HANDLE m_hEvent;
  182. HANDLE m_hCDBStarted;
  183. eDBGServiceRequested eDBGServie;
  184. // Interface pointers..
  185. IDebugClient *m_pDBGClient;
  186. IDebugControl *m_pDBGControl;
  187. IDebugSymbols *m_pDBGSymbols;
  188. PEmObject m_pEmSessObj;
  189. EventCallbacks m_EventCallbacks;
  190. STARTUPINFO m_sp;
  191. PROCESS_INFORMATION m_pi;
  192. FILE *m_pEcxFile;
  193. CExcepMonSessionManager *m_pASTManager;
  194. public:
  195. HRESULT CancelDebugging();
  196. CEMSessionThread(PEmObject pEmObj);
  197. ~CEMSessionThread();
  198. DWORD Run ( void );
  199. HRESULT CreateDumpFile( BOOL bMiniDump );
  200. HRESULT StopDebugging( );
  201. HRESULT OnException( PEXCEPTION_RECORD64 pException );
  202. HRESULT OnProcessExit( ULONG nExitCode );
  203. HRESULT CanContinue();
  204. HRESULT KeepDebuggeeRunning();
  205. HRESULT BreakIn();
  206. HRESULT Execute();
  207. HRESULT StopServer();
  208. HRESULT InitAutomaticSession(
  209. BOOL bRecursive,
  210. BSTR bstrEcxFilePath,
  211. BSTR bstrNotificationString,
  212. BSTR bstrAltSymPath,
  213. BOOL bGenerateMiniDump,
  214. BOOL bGenerateUserDump
  215. );
  216. HRESULT InitManualSession(
  217. BSTR bstrEcxFilePath,
  218. UINT nPortNumber,
  219. BSTR bstrUserName,
  220. BSTR bstrPassword,
  221. BOOL bBlockIncomingIPConnections,
  222. BSTR bstrAltSymPath
  223. );
  224. protected:
  225. HRESULT GetServerConnectString( LPTSTR, DWORD );
  226. HRESULT GetClientConnectString( LPTSTR, DWORD );
  227. HRESULT StartCDBServer( LPTSTR );
  228. HRESULT StartAutomaticExcepMonitoring( char * );
  229. HRESULT StartManualExcepMonitoring( char * );
  230. HRESULT GetCmd( eDBGServiceRequested, char *,DWORD &);
  231. HRESULT NotifyAdmin(LPCTSTR lpszData);
  232. HRESULT GetDescriptionFromEmObj(const PEmObject pEmObj, LPTSTR lpszDesc, ULONG cchDesc, LPCTSTR lpszHeader = NULL) const;
  233. HRESULT ExecuteCommandsTillGo( DWORD *pdwRes );
  234. private:
  235. BOOL m_bContinueSession;
  236. BOOL m_bRecursive;
  237. BSTR m_bstrEcxFilePath;
  238. BSTR m_bstrNotificationString;
  239. BSTR m_bstrAltSymPath;
  240. BOOL m_bGenerateMiniDump;
  241. BOOL m_bGenerateUserDump;
  242. BOOL m_bBlockIncomingIPConnections;
  243. BSTR m_bstrUserName;
  244. BSTR m_bstrPassword;
  245. };
  246. #endif // __SVCOBJDEF_H