console.h 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965
  1. /*++
  2. Copyright (c) 2012 Minoca Corp.
  3. This file is licensed under the terms of the GNU General Public License
  4. version 3. Alternative licensing terms are available. Contact
  5. info@minocacorp.com for details. See the LICENSE file at the root of this
  6. project for complete licensing information.
  7. Module Name:
  8. console.h
  9. Abstract:
  10. This header contains definitions for the generic console functions required
  11. by the debugger.
  12. Author:
  13. Evan Green 2-Jul-2012
  14. --*/
  15. //
  16. // ---------------------------------------------------------------- Definitions
  17. //
  18. #define KEY_RETURN 0x10
  19. #define KEY_UP 0x01
  20. #define KEY_DOWN 0x02
  21. #define KEY_ESCAPE 0x03
  22. #define KEY_REMOTE 0x04
  23. //
  24. // ------------------------------------------------------ Data Type Definitions
  25. //
  26. typedef
  27. PVOID
  28. (*PDBGR_THREAD_ROUTINE) (
  29. PVOID Parameter
  30. );
  31. /*++
  32. Routine Description:
  33. This routine is the entry point prototype for a new thread.
  34. Arguments:
  35. Parameter - Supplies a pointer supplied by the creator of the thread.
  36. Return Value:
  37. Returns a pointer value.
  38. --*/
  39. //
  40. // -------------------------------------------------------- Function Prototypes
  41. //
  42. //
  43. // Functions callable by the OS support layer.
  44. //
  45. INT
  46. DbgrMain (
  47. INT ArgumentCount,
  48. CHAR **Arguments
  49. );
  50. /*++
  51. Routine Description:
  52. This routine is the main entry point for the debugger.
  53. Arguments:
  54. ArgumentCount - Supplies the number of arguments on the command line.
  55. Arguments - Supplies an array of strings representing the arguments.
  56. Return Value:
  57. Returns 0 on success, nonzero on failure.
  58. --*/
  59. VOID
  60. DbgrRequestBreakIn (
  61. VOID
  62. );
  63. /*++
  64. Routine Description:
  65. This routine sends a break-in request to the target.
  66. Arguments:
  67. None.
  68. Return Value:
  69. None.
  70. --*/
  71. VOID
  72. DbgrDisplayCommandLineProfilerData (
  73. PROFILER_DATA_TYPE DataType,
  74. PROFILER_DISPLAY_REQUEST DisplayRequest,
  75. ULONG Threshold
  76. );
  77. /*++
  78. Routine Description:
  79. This routine displays the profiler data collected by the core debugging
  80. infrastructure to standard out.
  81. Arguments:
  82. DataType - Supplies the type of profiler data that is to be displayed.
  83. DisplayRequest - Supplies a value requesting a display action, which can
  84. either be to display data once, continually, or to stop continually
  85. displaying data.
  86. Threshold - Supplies the minimum percentage a stack entry hit must be in
  87. order to be displayed.
  88. Return Value:
  89. None.
  90. --*/
  91. BOOL
  92. DbgrGetProfilerStackData (
  93. PSTACK_DATA_ENTRY *StackTreeRoot
  94. );
  95. /*++
  96. Routine Description:
  97. This routine processes and returns any pending profiling stack data. It
  98. will add it to the provided stack tree root. The caller is responsible for
  99. destroying the tree.
  100. Arguments:
  101. StackTreeRoot - Supplies a pointer to a pointer to the root of the stack
  102. data tree. Upon return from the routine it will be updated with all the
  103. newly parsed data. If the root is null, a new root will be allocated.
  104. Return Value:
  105. Returns TRUE when data is successfully returned, or FALSE on failure.
  106. --*/
  107. VOID
  108. DbgrDestroyProfilerStackData (
  109. PSTACK_DATA_ENTRY Root
  110. );
  111. /*++
  112. Routine Description:
  113. This routine destroys a profiler stack data tree.
  114. Arguments:
  115. Root - Supplies a pointer to the root element of the tree.
  116. Return Value:
  117. None.
  118. --*/
  119. VOID
  120. DbgrPrintProfilerStackData (
  121. PSTACK_DATA_ENTRY Root,
  122. ULONG Threshold
  123. );
  124. /*++
  125. Routine Description:
  126. This routine prints profiler stack data to standard out.
  127. Arguments:
  128. Root - Supplies a pointer to the root of the profiler stack data tree.
  129. Threshold - Supplies the minimum percentage a stack entry hit must be in
  130. order to be displayed.
  131. Return Value:
  132. None.
  133. --*/
  134. VOID
  135. DbgrProfilerStackEntrySelected (
  136. PSTACK_DATA_ENTRY Root
  137. );
  138. /*++
  139. Routine Description:
  140. This routine is called when a profiler stack data entry is selected by the
  141. user.
  142. Arguments:
  143. Root - Supplies a pointer to the root of the profiler stack data tree.
  144. Return Value:
  145. None.
  146. --*/
  147. BOOL
  148. DbgrGetProfilerMemoryData (
  149. PLIST_ENTRY *MemoryPoolListHead
  150. );
  151. /*++
  152. Routine Description:
  153. This routine processes and returns any pending profiling memory data.
  154. Arguments:
  155. MemoryPoolListHead - Supplies a pointer to head of the memory pool list
  156. that is to be populated with the most up to date pool data.
  157. Return Value:
  158. Returns TRUE when data is successfully returned, or FALSE on failure.
  159. --*/
  160. VOID
  161. DbgrDestroyProfilerMemoryData (
  162. PLIST_ENTRY PoolListHead
  163. );
  164. /*++
  165. Routine Description:
  166. This routine destroys a profiler memory data list.
  167. Arguments:
  168. PoolListHead - Supplies a pointer to the head of the memory pool list
  169. that is to be destroyed.
  170. Return Value:
  171. None.
  172. --*/
  173. VOID
  174. DbgrPrintProfilerMemoryData (
  175. PLIST_ENTRY MemoryPoolListHead,
  176. BOOL DeltaMode,
  177. ULONG ActiveCountThreshold
  178. );
  179. /*++
  180. Routine Description:
  181. This routine prints the statistics from the given memory pool list to the
  182. debugger console.
  183. Arguments:
  184. MemoryPoolListHead - Supplies a pointer to the head of the memory pool
  185. list.
  186. DeltaMode - Supplies a boolean indicating whether or not the memory pool
  187. list represents a delta from a previous point in time.
  188. ActiveCountThreshold - Supplies the active count threshold. No statistics
  189. will be displayed for tags with an active count less than this
  190. threshold.
  191. Return Value:
  192. None.
  193. --*/
  194. PLIST_ENTRY
  195. DbgrSubtractMemoryStatistics (
  196. PLIST_ENTRY CurrentListHead,
  197. PLIST_ENTRY BaseListHead
  198. );
  199. /*++
  200. Routine Description:
  201. This routine subtracts the given current memory list from the base memory
  202. list, returning a list that contains the deltas for memory pool statistics.
  203. If this routine ever fails, it just returns the current list.
  204. Arguments:
  205. CurrentListHead - Supplies a pointer to the head of the current list of
  206. memory pool data.
  207. BaseListHead - supplies a pointer to the head of the base line memory list
  208. from which the deltas are created.
  209. Return Value:
  210. Returns a new memory pool list if possible. If the routine fails or there
  211. is no base line, then the current memory list is returned.
  212. --*/
  213. //
  214. // Functions implemented by the OS support layer.
  215. //
  216. BOOL
  217. DbgrOsInitializeConsole (
  218. PBOOL EchoCommands
  219. );
  220. /*++
  221. Routine Description:
  222. This routine performs any initialization steps necessary before the console
  223. can be used.
  224. Arguments:
  225. EchoCommands - Supplies a pointer where a boolean will be returned
  226. indicating if the debugger should echo commands received (TRUE) or if
  227. the console has already echoed the command (FALSE).
  228. Return Value:
  229. Returns TRUE on success, FALSE on failure.
  230. --*/
  231. VOID
  232. DbgrOsDestroyConsole (
  233. VOID
  234. );
  235. /*++
  236. Routine Description:
  237. This routine cleans up anything related to console functionality as a
  238. debugger is exiting.
  239. Arguments:
  240. None.
  241. Return Value:
  242. None.
  243. --*/
  244. INT
  245. DbgrOsCreateThread (
  246. PDBGR_THREAD_ROUTINE ThreadRoutine,
  247. PVOID Parameter
  248. );
  249. /*++
  250. Routine Description:
  251. This routine creates a new thread.
  252. Arguments:
  253. ThreadRoutine - Supplies a pointer to the routine to run in the new thread.
  254. The thread is destroyed when the supplied routine returns.
  255. Parameter - Supplies a pointer to a parameter to pass to the thread.
  256. Return Value:
  257. 0 on success.
  258. Returns an error code on failure.
  259. --*/
  260. int
  261. DbgrOsCreatePipe (
  262. int FileDescriptors[2]
  263. );
  264. /*++
  265. Routine Description:
  266. This routine creates an anonymous pipe.
  267. Arguments:
  268. FileDescriptors - Supplies a pointer where handles will be returned
  269. representing the read and write ends of the pipe.
  270. Return Value:
  271. 0 on success.
  272. -1 on failure. The errno variable will be set to indicate the error.
  273. --*/
  274. char *
  275. DbgrOsGetUserName (
  276. void
  277. );
  278. /*++
  279. Routine Description:
  280. This routine returns the user name of the current process.
  281. Arguments:
  282. None.
  283. Return Value:
  284. Returns a pointer to a string containing the user name if it can be found.
  285. The caller should not free or modify this memory, and it may be reused on
  286. subsequent calls.
  287. --*/
  288. char *
  289. DbgrOsGetHostName (
  290. void
  291. );
  292. /*++
  293. Routine Description:
  294. This routine returns the host name of the current machine.
  295. Arguments:
  296. None.
  297. Return Value:
  298. Returns a pointer to a string containing the user name if it can be found.
  299. The caller is responsible for freeing this memory.
  300. --*/
  301. VOID
  302. DbgrOsPrepareToReadInput (
  303. VOID
  304. );
  305. /*++
  306. Routine Description:
  307. This routine is called before the debugger begins to read a line of input
  308. from the user.
  309. Arguments:
  310. None.
  311. Return Value:
  312. None.
  313. --*/
  314. BOOL
  315. DbgrOsGetCharacter (
  316. PUCHAR Key,
  317. PUCHAR ControlKey
  318. );
  319. /*++
  320. Routine Description:
  321. This routine gets one character from the standard input console.
  322. Arguments:
  323. Key - Supplies a pointer that receives the printable character. If this
  324. parameter is NULL, printing characters will be discarded from the input
  325. buffer.
  326. ControlKey - Supplies a pointer that receives the non-printable character.
  327. If this parameter is NULL, non-printing characters will be discarded
  328. from the input buffer.
  329. Return Value:
  330. Returns TRUE on success, FALSE on failure.
  331. --*/
  332. VOID
  333. DbgrOsRemoteInputAdded (
  334. VOID
  335. );
  336. /*++
  337. Routine Description:
  338. This routine is called after a remote command is received and placed on the
  339. standard input remote command list. It wakes up a thread blocked on local
  340. user input in an OS-dependent fashion.
  341. Arguments:
  342. None.
  343. Return Value:
  344. None.
  345. --*/
  346. VOID
  347. DbgrOsPostInputCallback (
  348. VOID
  349. );
  350. /*++
  351. Routine Description:
  352. This routine is called after a line of input is read from the user, giving
  353. the OS specific code a chance to restore anything it did in the prepare
  354. to read input function.
  355. Arguments:
  356. None.
  357. Return Value:
  358. None.
  359. --*/
  360. BOOL
  361. InitializeCommunications (
  362. PSTR Channel,
  363. ULONG Baudrate
  364. );
  365. /*++
  366. Routine Description:
  367. This routine initializes the communication medium the debugger uses to
  368. communicate with the target.
  369. Arguments:
  370. Channel - Supplies a description of the communication medium.
  371. Baudrate - Supplies the baudrate to use for serial based communications.
  372. Return Value:
  373. Returns TRUE on success, FALSE on failure.
  374. --*/
  375. VOID
  376. DestroyCommunications (
  377. VOID
  378. );
  379. /*++
  380. Routine Description:
  381. This routine tears down the debug communication channel.
  382. Arguments:
  383. None.
  384. Return Value:
  385. None.
  386. --*/
  387. BOOL
  388. CommReceive (
  389. PVOID Buffer,
  390. ULONG BytesToRead
  391. );
  392. /*++
  393. Routine Description:
  394. This routine receives a number of bytes from the debugger/debuggee
  395. connection.
  396. Arguments:
  397. Buffer - Supplies a pointer to the buffer where the data should be returned.
  398. BytesToRead - Supplies the number of bytes that should be received into the
  399. buffer.
  400. Return Value:
  401. Returns TRUE on success, FALSE on failure.
  402. --*/
  403. BOOL
  404. CommSend (
  405. PVOID Buffer,
  406. ULONG BytesToSend
  407. );
  408. /*++
  409. Routine Description:
  410. This routine sends a number of bytes through the debugger/debuggee
  411. connection.
  412. Arguments:
  413. Buffer - Supplies a pointer to the buffer where the data to be sent resides.
  414. BytesToSend - Supplies the number of bytes that should be sent.
  415. Return Value:
  416. Returns TRUE on success, FALSE on failure.
  417. --*/
  418. BOOL
  419. CommReceiveBytesReady (
  420. VOID
  421. );
  422. /*++
  423. Routine Description:
  424. This routine determines whether or not bytes can be read from the
  425. debugger connection.
  426. Arguments:
  427. None.
  428. Return Value:
  429. TRUE if there are bytes ready to be read.
  430. FALSE if no bytes are ready at this time.
  431. --*/
  432. VOID
  433. CommStall (
  434. ULONG Milliseconds
  435. );
  436. /*++
  437. Routine Description:
  438. This routine pauses for the given amount of time.
  439. Arguments:
  440. Milliseconds - Supplies the amount of time, in milliseconds, to stall the
  441. current thread for.
  442. Return Value:
  443. None.
  444. --*/
  445. BOOL
  446. UiLoadSourceFile (
  447. PSTR Path,
  448. PVOID Contents,
  449. ULONGLONG Size
  450. );
  451. /*++
  452. Routine Description:
  453. This routine loads the contents of a file into the source window.
  454. Arguments:
  455. Path - Supplies the path of the file being loaded. If this is NULL, then
  456. the source window should be cleared.
  457. Contents - Supplies the source file data. This can be NULL.
  458. Size - Supplies the size of the source file data in bytes.
  459. Return Value:
  460. Returns TRUE if there was no error, or FALSE if there was an error.
  461. --*/
  462. BOOL
  463. UiHighlightExecutingLine (
  464. LONG LineNumber,
  465. BOOL Enable
  466. );
  467. /*++
  468. Routine Description:
  469. This routine highlights the currently executing source line and scrolls to
  470. it.
  471. Arguments:
  472. LineNumber - Supplies the 1-based line number to highlight (ie the first
  473. line in the source file is line 1).
  474. Enable - Supplies a flag indicating whether to highlight this line (TRUE)
  475. or restore the line to its original color (FALSE).
  476. Return Value:
  477. Returns TRUE if there was no error, or FALSE if there was an error.
  478. --*/
  479. VOID
  480. UiEnableCommands (
  481. BOOL Enable
  482. );
  483. /*++
  484. Routine Description:
  485. This routine enables or disables the command edit control from being
  486. enabled. If disabled, the edit control will be made read only.
  487. Arguments:
  488. Enable - Supplies a flag indicating whether or not to enable (TRUE) or
  489. disable (FALSE) the command box.
  490. Return Value:
  491. None.
  492. --*/
  493. VOID
  494. UiSetCommandText (
  495. PSTR Text
  496. );
  497. /*++
  498. Routine Description:
  499. This routine sets the text inside the command edit box.
  500. Arguments:
  501. Text - Supplies a pointer to a null terminated string to set the command
  502. text to.
  503. Return Value:
  504. None.
  505. --*/
  506. VOID
  507. UiSetPromptText (
  508. PSTR Text
  509. );
  510. /*++
  511. Routine Description:
  512. This routine sets the text inside the prompt edit box.
  513. Arguments:
  514. Text - Supplies a pointer to a null terminated string to set the prompt
  515. text to.
  516. Return Value:
  517. None.
  518. --*/
  519. VOID
  520. UiDisplayProfilerData (
  521. PROFILER_DATA_TYPE DataType,
  522. PROFILER_DISPLAY_REQUEST DisplayRequest,
  523. ULONG Threshold
  524. );
  525. /*++
  526. Routine Description:
  527. This routine displays the profiler data collected by the core debugging
  528. infrastructure.
  529. Arguments:
  530. DataType - Supplies the type of profiler data that is to be displayed.
  531. DisplayRequest - Supplies a value requesting a display action, which can
  532. either be to display data once, continually, or to stop continually
  533. displaying data.
  534. Threshold - Supplies the minimum percentage a stack entry hit must be in
  535. order to be displayed.
  536. Return Value:
  537. None.
  538. --*/
  539. HANDLE
  540. CreateDebuggerLock (
  541. VOID
  542. );
  543. /*++
  544. Routine Description:
  545. This routine creates a debugger lock.
  546. Arguments:
  547. None.
  548. Return Value:
  549. Returns a handle to a debugger lock on success, or NULL on failure.
  550. --*/
  551. VOID
  552. AcquireDebuggerLock (
  553. HANDLE Lock
  554. );
  555. /*++
  556. Routine Description:
  557. This routine acquires a debugger lock. This routine does not return until
  558. the lock is required.
  559. Arguments:
  560. Lock - Supplies a handle to the lock that is to be acquired.
  561. Return Value:
  562. None.
  563. --*/
  564. VOID
  565. ReleaseDebuggerLock (
  566. HANDLE Lock
  567. );
  568. /*++
  569. Routine Description:
  570. This routine releases a debugger lock.
  571. Arguments:
  572. Lock - Supplies a handle to the lock that is to be released.
  573. Return Value:
  574. None.
  575. --*/
  576. VOID
  577. DestroyDebuggerLock (
  578. HANDLE Lock
  579. );
  580. /*++
  581. Routine Description:
  582. This routine destroys a debugger lock.
  583. Arguments:
  584. Lock - Supplies a handle to the lock that is to be destroyed.
  585. Return Value:
  586. None.
  587. --*/