console.h 15 KB

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