remsrv.h 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408
  1. /*++
  2. Copyright (c) 2014 Minoca Corp. All Rights Reserved
  3. Module Name:
  4. remsrv.h
  5. Abstract:
  6. This header contains definitions for remote debug server functionality.
  7. Author:
  8. Evan Green 27-Aug-2014
  9. --*/
  10. //
  11. // ------------------------------------------------------------------- Includes
  12. //
  13. //
  14. // --------------------------------------------------------------------- Macros
  15. //
  16. //
  17. // These macros return the major and minor versions from the debug remote
  18. // protocol version.
  19. //
  20. #define DEBUG_REMOTE_PROTOCOL_MAJOR(_ProtocolVersion) \
  21. (((_ProtocolVersion) >> 16) & 0x0000FFFF)
  22. #define DEBUG_REMOTE_PROTOCOL_MINOR(_ProtocolVersion) \
  23. ((_ProtocolVersion) & 0x0000FFFF)
  24. //
  25. // ---------------------------------------------------------------- Definitions
  26. //
  27. //
  28. // Define the magic value for the debug remote packet: 'Dbg:'.
  29. //
  30. #define DEBUG_REMOTE_HEADER_MAGIC 0x3A676244
  31. //
  32. // Define the current remote protocol version.
  33. //
  34. #define DEBUG_REMOTE_PROTOCOL_VERSION 0x00010000
  35. //
  36. // Define the size of the user and host strings.
  37. //
  38. #define DEBUG_REMOTE_USER_SIZE 48
  39. #define DEBUG_REMOTE_HOST_SIZE 48
  40. //
  41. // ------------------------------------------------------ Data Type Definitions
  42. //
  43. //
  44. // Define the command types sent between remote clients and servers.
  45. //
  46. typedef enum _DEBUG_REMOTE_COMMAND_TYPE {
  47. DebugRemoteCommandInvalid,
  48. DebugRemoteClientInformation,
  49. DebugRemoteServerInformation,
  50. DebugRemoteOutput,
  51. DebugRemotePrompt,
  52. DebugRemoteInput,
  53. DebugRemoteBreakRequest,
  54. DebugRemoteSourceInformation,
  55. DebugRemoteSourceDataRequest,
  56. DebugRemoteSourceData,
  57. } DEBUG_REMOTE_COMMAND_TYPE, *PDEBUG_REMOTE_COMMAND_TYPE;
  58. //
  59. // Define the various states the receive thread can be in.
  60. //
  61. typedef enum _DEBUGGER_SERVER_RECEIVE_STATE {
  62. DebuggerServerReceiveNotStarted,
  63. DebuggerServerReceiveRunning,
  64. DebuggerServerReceiveShutDownRequested,
  65. DebuggerServerReceiveShutDown
  66. } DEBUGGER_SERVER_RECEIVE_STATE, *PDEBUGGER_SERVER_RECEIVE_STATE;
  67. /*++
  68. Structure Description:
  69. This structure stores the common header that goes on each remote packet.
  70. Members:
  71. Magic - Stores the magic value. Set this to DEBUG_REMOTE_HEADER_MAGIC.
  72. Command - Stores the command. See the DEBUG_REMOTE_COMMAND_TYPE enum.
  73. HeaderCrc32 - Stores the CRC32 of the header. The data CRC32 is filled in,
  74. but the header CRC32 is set to zero when computing the checksum.
  75. Length - Stores the length of the data payload, in bytes.
  76. DataCrc32 - Stores the CRC32 of the data portion of the payload.
  77. --*/
  78. typedef struct _DEBUG_REMOTE_HEADER {
  79. ULONG Magic;
  80. ULONG Command;
  81. ULONG HeaderCrc32;
  82. ULONGLONG Length;
  83. ULONG DataCrc32;
  84. } PACKED DEBUG_REMOTE_HEADER, *PDEBUG_REMOTE_HEADER;
  85. /*++
  86. Structure Description:
  87. This structure stores debugger remote client information. The client sends
  88. this information immediately after connecting.
  89. Members:
  90. Header - Stores the standard packet header.
  91. ProtocolVersion - Stores the protocol version number of the client.
  92. User - Stores the name of the remote client user.
  93. Host - Stores the name of the remote client host.
  94. --*/
  95. typedef struct _DEBUG_REMOTE_CLIENT_INFORMATION {
  96. DEBUG_REMOTE_HEADER Header;
  97. ULONG ProtocolVersion;
  98. CHAR User[DEBUG_REMOTE_USER_SIZE];
  99. CHAR Host[DEBUG_REMOTE_HOST_SIZE];
  100. } PACKED DEBUG_REMOTE_CLIENT_INFORMATION, *PDEBUG_REMOTE_CLIENT_INFORMATION;
  101. /*++
  102. Structure Description:
  103. This structure stores debugger remote server information. It is sent in
  104. response to remote client information.
  105. Members:
  106. Header - Stores the standard packet header.
  107. ProtocolVersion - Stores the protocol version number of the client.
  108. --*/
  109. typedef struct _DEBUG_REMOTE_SERVER_INFORMATION {
  110. DEBUG_REMOTE_HEADER Header;
  111. ULONG ProtocolVersion;
  112. } PACKED DEBUG_REMOTE_SERVER_INFORMATION, *PDEBUG_REMOTE_SERVER_INFORMATION;
  113. /*++
  114. Structure Description:
  115. This structure stores debugger source file and line information. It is sent
  116. whenever the source file or line changes. The source file string follows
  117. immediately after this structure, and consumes the remainder of the payload.
  118. Members:
  119. Header - Stores the standard packet header.
  120. LineNumber - Stores the line number.
  121. SourceAvailable - Stores a boolean indicating whether or not the server has
  122. the source for the given file.
  123. --*/
  124. typedef struct _DEBUG_REMOTE_SOURCE_INFORMATION {
  125. DEBUG_REMOTE_HEADER Header;
  126. ULONGLONG LineNumber;
  127. ULONG SourceAvailable;
  128. } PACKED DEBUG_REMOTE_SOURCE_INFORMATION, *PDEBUG_REMOTE_SOURCE_INFORMATION;
  129. /*++
  130. Structure Description:
  131. This structure stores debugger source data. It is sent when requested by
  132. the client. The source data comes immediately after the structure and is
  133. the length of the rest of the payload.
  134. Members:
  135. Header - Stores the standard packet header.
  136. FileNameCrc32 - Stores the CRC32 of the file path. This can be used by the
  137. client to ensure the correct data is being received.
  138. --*/
  139. typedef struct _DEBUG_REMOTE_SOURCE_DATA {
  140. DEBUG_REMOTE_HEADER Header;
  141. ULONG FileNameCrc32;
  142. } PACKED DEBUG_REMOTE_SOURCE_DATA, *PDEBUG_REMOTE_SOURCE_DATA;
  143. /*++
  144. Structure Description:
  145. This structure stores information pertaining to managing a remote debug
  146. server.
  147. Members:
  148. ListEntry - Stores pointers to the next and previous client connections
  149. that the debug server is maintaining.
  150. Context - Stores a pointer to the applicaton context this connection
  151. belongs to.
  152. Socket - Stores the socket representing the connection between the server
  153. and its client.
  154. Pipe - Stores the pipe used to communicate to the thread managing the
  155. client connection.
  156. Update - Stores a boolean indicating whether or not there is a pending
  157. update the client thread should send along to the client.
  158. Host - Stores a pointer to the host string of the client.
  159. Port - Stores a pointer to the client remote port.
  160. HostName - Stores the name of the remote machine as reported by the client.
  161. UserName - Stores the name of the remote user as reporeted by the client.
  162. Prompt - Stores the last prompt sent to the client.
  163. SourceFile - Stores the last source file name send to the client.
  164. SourceLine - Stores the last source line sent to the client.
  165. ReceiveState - Stores the current state of the receive thread.
  166. --*/
  167. typedef struct _DEBUGGER_SERVER_CLIENT {
  168. LIST_ENTRY ListEntry;
  169. PDEBUGGER_CONTEXT Context;
  170. int Socket;
  171. int Pipe[2];
  172. volatile int Update;
  173. char *Host;
  174. int Port;
  175. char *HostName;
  176. char *UserName;
  177. char *Prompt;
  178. char *SourceFile;
  179. ULONGLONG SourceLine;
  180. volatile DEBUGGER_SERVER_RECEIVE_STATE ReceiveState;
  181. } DEBUGGER_SERVER_CLIENT, *PDEBUGGER_SERVER_CLIENT;
  182. /*++
  183. Structure Description:
  184. This structure stores a complete remote command.
  185. Members:
  186. ListEntry - Stores pointers to the next and previous remote commands in the
  187. queue.
  188. Command - Stores a pointer to the null terminated string containing the
  189. command to run. This must be freed.
  190. Host - Stores a pointer to a null terminated string containing the host
  191. that requests the command. This must be freed.
  192. User - Stores a pointer to a null terminated string containing the user
  193. that requests the command. This must be freed.
  194. --*/
  195. typedef struct _DEBUGGER_REMOTE_COMMAND {
  196. LIST_ENTRY ListEntry;
  197. PSTR Command;
  198. PSTR Host;
  199. PSTR User;
  200. } DEBUGGER_REMOTE_COMMAND, *PDEBUGGER_REMOTE_COMMAND;
  201. //
  202. // -------------------------------------------------------------------- Globals
  203. //
  204. //
  205. // -------------------------------------------------------- Function Prototypes
  206. //
  207. INT
  208. DbgrClientMainLoop (
  209. PDEBUGGER_CONTEXT Context,
  210. PSTR RemoteString,
  211. BOOL ReverseRemote
  212. );
  213. /*++
  214. Routine Description:
  215. This routine implements the main loop of the debugger when connected to a
  216. remote server.
  217. Arguments:
  218. Context - Supplies a pointer to the debugger context.
  219. RemoteString - Supplies a pointer to the remote host to connect to.
  220. ReverseRemote - Supplies a boolean indicating whether or not the client
  221. should act in "reverse": opening up a port and waiting for the server
  222. to connect. This is useful in situations where the server cannot
  223. accept incoming connections.
  224. Return Value:
  225. 0 on success.
  226. Returns an error number on failure.
  227. --*/
  228. INT
  229. DbgrpClientRequestBreakIn (
  230. PDEBUGGER_CONTEXT Context
  231. );
  232. /*++
  233. Routine Description:
  234. This routine sends a break request across to the debug server.
  235. Arguments:
  236. Context - Supplies a pointer to the debugger context.
  237. Return Value:
  238. 0 on success.
  239. Non-zero on error.
  240. --*/
  241. VOID
  242. DbgrpServerNotifyClients (
  243. PDEBUGGER_CONTEXT Context
  244. );
  245. /*++
  246. Routine Description:
  247. This routine notifies all debug clients connected to the given server that
  248. there is new activity to send off to the clients.
  249. Arguments:
  250. Context - Supplies a pointer to the debugger context.
  251. Return Value:
  252. None.
  253. --*/
  254. VOID
  255. DbgrpServerDestroy (
  256. PDEBUGGER_CONTEXT Context
  257. );
  258. /*++
  259. Routine Description:
  260. This routine tears down the debug server and all its connections.
  261. Arguments:
  262. Context - Supplies a pointer to the debugger context.
  263. Return Value:
  264. None.
  265. --*/