dbgapi.h 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543
  1. /*++
  2. Copyright (c) 2013 Minoca Corp. All Rights Reserved
  3. Module Name:
  4. dbgapi.h
  5. Abstract:
  6. This header defines the interface to the low level debugger APIs.
  7. Author:
  8. Evan Green 7-May-2013
  9. --*/
  10. //
  11. // ------------------------------------------------------------------- Includes
  12. //
  13. #include <minoca/kernel/ksignals.h>
  14. //
  15. // --------------------------------------------------------------------- Macros
  16. //
  17. //
  18. // This macro returns non-zero if the given loaded module is applicable to the
  19. // current event, which is true if the module's process ID is zero or equal
  20. // to the current process.
  21. //
  22. #define IS_MODULE_IN_CURRENT_PROCESS(_Context, _LoadedModule) \
  23. (((_LoadedModule)->Process == 0) || \
  24. ((_LoadedModule)->Process == \
  25. (_Context)->CurrentEvent.BreakNotification.Process))
  26. //
  27. // ---------------------------------------------------------------- Definitions
  28. //
  29. //
  30. // ------------------------------------------------------ Data Type Definitions
  31. //
  32. typedef enum _DEBUG_CONNECTION_TYPE {
  33. DebugConnectionInvalid,
  34. DebugConnectionKernel,
  35. DebugConnectionUser,
  36. DebugConnectionRemote,
  37. } DEBUG_CONNECTION_TYPE, *PDEBUG_CONNECTION_TYPE;
  38. typedef enum _DEBUGGER_EVENT_TYPE {
  39. DebuggerEventInvalid,
  40. DebuggerEventBreak,
  41. DebuggerEventShutdown,
  42. DebuggerEventProfiler
  43. } DEBUGGER_EVENT_TYPE, *PDEBUGGER_EVENT_TYPE;
  44. /*++
  45. Structure Description:
  46. This structure defines an incoming debugger event.
  47. Members:
  48. Type - Stores the type of debug event, which defines which of the union
  49. members is valid.
  50. BreakNotification - Stores the break notification information.
  51. ShutdownNotification - Stores the shutdown notification information.
  52. ProfilerNotification - Stores a pointer to the profiler notification
  53. information.
  54. SignalParameters - Stores the optional signal parameter information for
  55. debug events of type signal.
  56. --*/
  57. typedef struct _DEBUGGER_EVENT {
  58. DEBUGGER_EVENT_TYPE Type;
  59. union {
  60. BREAK_NOTIFICATION BreakNotification;
  61. SHUTDOWN_NOTIFICATION ShutdownNotification;
  62. PPROFILER_NOTIFICATION ProfilerNotification;
  63. };
  64. SIGNAL_PARAMETERS SignalParameters;
  65. } DEBUGGER_EVENT, *PDEBUGGER_EVENT;
  66. //
  67. // -------------------------------------------------------------------- Globals
  68. //
  69. //
  70. // -------------------------------------------------------- Function Prototypes
  71. //
  72. INT
  73. DbgInitialize (
  74. PDEBUGGER_CONTEXT Context,
  75. DEBUG_CONNECTION_TYPE ConnectionType
  76. );
  77. /*++
  78. Routine Description:
  79. This routine initializes data structures for common debugger API.
  80. Arguments:
  81. Context - Supplies a pointer to the application context.
  82. ConnectionType - Supplies the type of debug connection to set the debugger
  83. up in.
  84. Return Value:
  85. 0 on success.
  86. Returns an error code on failure.
  87. --*/
  88. VOID
  89. DbgDestroy (
  90. PDEBUGGER_CONTEXT Context,
  91. DEBUG_CONNECTION_TYPE ConnectionType
  92. );
  93. /*++
  94. Routine Description:
  95. This routine destroys data structures for common debugger API.
  96. Arguments:
  97. Context - Supplies a pointer to the application context.
  98. ConnectionType - Supplies the type of debug connection for which the
  99. debugger was initialized.
  100. Return Value:
  101. None.
  102. --*/
  103. INT
  104. DbgKdConnect (
  105. PDEBUGGER_CONTEXT Context,
  106. BOOL RequestBreak,
  107. PCONNECTION_RESPONSE *ConnectionDetails,
  108. PULONG BufferSize
  109. );
  110. /*++
  111. Routine Description:
  112. This routine establishes a link with the target. It is assumed that
  113. the underlying communication layer has already been established (COM ports
  114. have been opened and initialized, etc).
  115. Arguments:
  116. Context - Supplies a pointer to the application context.
  117. RequestBreak - Supplies a boolean indicating whether or not the host
  118. should break in.
  119. ConnectionDetails - Supplies a pointer where a pointer to details about the
  120. kernel connection will be returned. The caller is responsible for
  121. freeing this memory when done.
  122. BufferSize - Supplies a pointer where the total size of the connection
  123. details buffer will be returned.
  124. Return Value:
  125. 0 on success.
  126. Non-zero on error.
  127. --*/
  128. INT
  129. DbgContinue (
  130. PDEBUGGER_CONTEXT Context,
  131. ULONG SignalToDeliver
  132. );
  133. /*++
  134. Routine Description:
  135. This routine sends the "go" command to the target, signaling to continue
  136. execution.
  137. Arguments:
  138. Context - Supplies a pointer to the application context.
  139. SignalToDeliver - Supplies the signal number to actually send to the
  140. application. For kernel debugging, this parameter is ignored.
  141. Return Value:
  142. 0 on success.
  143. Non-zero on failure.
  144. --*/
  145. ULONG
  146. DbgGetSignalToDeliver (
  147. PDEBUGGER_CONTEXT Context
  148. );
  149. /*++
  150. Routine Description:
  151. This routine returns the value for the "signal to deliver" parameters when
  152. letting the target continue. For user mode processes, breaks into the
  153. debugger occur because of signal delivery, and the debugger has the choice
  154. of whether or not to actually deliver a signal.
  155. Arguments:
  156. Context - Supplies a pointer to the application context.
  157. Return Value:
  158. Returns the signal to deliver for the upcoming target continuation.
  159. 0 for kernel debugging or if no signal should be delivered to the target.
  160. This value can just be passed through.
  161. --*/
  162. INT
  163. DbgSetRegisters (
  164. PDEBUGGER_CONTEXT Context,
  165. PREGISTERS_UNION Registers
  166. );
  167. /*++
  168. Routine Description:
  169. This routine sets the registers of the target.
  170. Arguments:
  171. Context - Supplies a pointer to the application context.
  172. Registers - Supplies a pointer to the registers to set. All register values
  173. will be written.
  174. Return Value:
  175. 0 on success.
  176. Non-zero on failure.
  177. --*/
  178. INT
  179. DbgGetSpecialRegisters (
  180. PDEBUGGER_CONTEXT Context,
  181. PSPECIAL_REGISTERS_UNION SpecialRegisters
  182. );
  183. /*++
  184. Routine Description:
  185. This routine gets the registers of the target.
  186. Arguments:
  187. Context - Supplies a pointer to the application context.
  188. SpecialRegisters - Supplies a pointer where the registers will be returned.
  189. Return Value:
  190. 0 on success.
  191. Non-zero on failure.
  192. --*/
  193. INT
  194. DbgSetSpecialRegisters (
  195. PDEBUGGER_CONTEXT Context,
  196. PSET_SPECIAL_REGISTERS Command
  197. );
  198. /*++
  199. Routine Description:
  200. This routine sets the special registers from the target.
  201. Arguments:
  202. Context - Supplies a pointer to the application context.
  203. Command - Supplies a pointer to the details of the set special registers
  204. command.
  205. Return Value:
  206. 0 on success.
  207. Non-zero on failure.
  208. --*/
  209. INT
  210. DbgSingleStep (
  211. PDEBUGGER_CONTEXT Context,
  212. ULONG SignalToDeliver
  213. );
  214. /*++
  215. Routine Description:
  216. This routine steps the target by one instruction.
  217. Arguments:
  218. Context - Supplies a pointer to the application context.
  219. SignalToDeliver - Supplies the signal number to actually send to the
  220. application. For kernel debugging, this parameter is ignored.
  221. Return Value:
  222. 0 on success.
  223. Returns an error code on failure.
  224. --*/
  225. INT
  226. DbgWaitForEvent (
  227. PDEBUGGER_CONTEXT Context
  228. );
  229. /*++
  230. Routine Description:
  231. This routine gets an event from the target, such as a break event or other
  232. exception.
  233. Arguments:
  234. Context - Supplies a pointer to the application context.
  235. Return Value:
  236. 0 on success.
  237. Non-zero on failure.
  238. --*/
  239. INT
  240. DbgRangeStep (
  241. PDEBUGGER_CONTEXT Context,
  242. PRANGE_STEP RangeStep,
  243. ULONG SignalToDeliver
  244. );
  245. /*++
  246. Routine Description:
  247. This routine continues execution until a range of execution addresses is
  248. reached.
  249. Arguments:
  250. Context - Supplies the application context.
  251. RangeStep - Supplies a pointer to the range to go to.
  252. SignalToDeliver - Supplies the signal number to actually send to the
  253. application. For kernel debugging, this parameter is ignored.
  254. Return Value:
  255. 0 on success.
  256. Returns an error code on failure.
  257. --*/
  258. INT
  259. DbgSwitchProcessors (
  260. PDEBUGGER_CONTEXT Context,
  261. ULONG ProcessorNumber
  262. );
  263. /*++
  264. Routine Description:
  265. This routine switches the debugger to another processor.
  266. Arguments:
  267. Context - Supplies a pointer to the debugger context.
  268. ProcessorNumber - Supplies the processor number to switch to.
  269. DebuggeeRunning - Supplies a pointer where a boolean will be returned
  270. indicating whether or not the target has continued.
  271. Return Value:
  272. 0 on success.
  273. Returns an error code on failure.
  274. --*/
  275. INT
  276. DbgGetThreadList (
  277. PDEBUGGER_CONTEXT Context,
  278. PULONG ThreadCount,
  279. PULONG *ThreadIds
  280. );
  281. /*++
  282. Routine Description:
  283. This routine gets the list of active threads in the process (or active
  284. processors in the machine for kernel mode).
  285. Arguments:
  286. Context - Supplies a pointer to the application context.
  287. ThreadCount - Supplies a pointer where the number of threads will be
  288. returned on success.
  289. ThreadIds - Supplies a pointer where an array of thread IDs (or processor
  290. numbers) will be returned on success. It is the caller's responsibility
  291. to free this memory.
  292. Return Value:
  293. 0 on success.
  294. Non-zero on failure.
  295. --*/
  296. INT
  297. DbgGetLoadedModuleList (
  298. PDEBUGGER_CONTEXT Context,
  299. PMODULE_LIST_HEADER *ModuleList
  300. );
  301. /*++
  302. Routine Description:
  303. This routine retrieves the list of loaded binaries from the target.
  304. Arguments:
  305. Context - Supplies a pointer to the application context.
  306. ModuleList - Supplies a pointer where a pointer to the loaded module header
  307. and subsequent array of entries will be returned. It is the caller's
  308. responsibility to free this allocated memory when finished.
  309. Return Value:
  310. 0 on success.
  311. Non-zero on failure.
  312. --*/
  313. VOID
  314. DbgRequestBreakIn (
  315. PDEBUGGER_CONTEXT Context
  316. );
  317. /*++
  318. Routine Description:
  319. This routine attempts to stop the running target.
  320. Arguments:
  321. Context - Supplies a pointer to the application context.
  322. Return Value:
  323. None.
  324. --*/
  325. ULONG
  326. DbgGetHostMachineType (
  327. VOID
  328. );
  329. /*++
  330. Routine Description:
  331. This routine returns the machine type for the currently running host (this
  332. machine).
  333. Arguments:
  334. None.
  335. Return Value:
  336. Returns the machine type. See MACHINE_TYPE_* definitions.
  337. --*/