debug_doc.h 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709
  1. /*
  2. ** Command & Conquer Generals Zero Hour(tm)
  3. ** Copyright 2025 Electronic Arts Inc.
  4. **
  5. ** This program is free software: you can redistribute it and/or modify
  6. ** it under the terms of the GNU General Public License as published by
  7. ** the Free Software Foundation, either version 3 of the License, or
  8. ** (at your option) any later version.
  9. **
  10. ** This program is distributed in the hope that it will be useful,
  11. ** but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. ** GNU General Public License for more details.
  14. **
  15. ** You should have received a copy of the GNU General Public License
  16. ** along with this program. If not, see <http://www.gnu.org/licenses/>.
  17. */
  18. /////////////////////////////////////////////////////////////////////////EA-V1
  19. // $File: //depot/GeneralsMD/Staging/code/Libraries/Source/debug/debug_doc.h $
  20. // $Author: mhoffe $
  21. // $Revision: #1 $
  22. // $DateTime: 2003/07/03 11:55:26 $
  23. //
  24. // ©2003 Electronic Arts
  25. //
  26. // additional Doxygen module documentation
  27. //////////////////////////////////////////////////////////////////////////////
  28. #ifdef _MSC_VER
  29. # pragma once
  30. #endif
  31. #ifndef DEBUG_DOC_H // Include guard
  32. #define DEBUG_DOC_H
  33. // This generates a small main page for Doxygen if a module only
  34. // documentation is built.
  35. #ifndef DOXYGEN_GLOBAL_DOC
  36. /**
  37. \mainpage %Debug module
  38. The following pages contain the most useful information:
  39. - \ref module_debug
  40. - \ref debug_macros
  41. - \ref debug_stream
  42. - \ref debug_cmd
  43. \internal This is the internal module documentation meant only for
  44. programmers who are working on the module internals.
  45. */
  46. #endif
  47. /**
  48. \page module_debug Debug module overview
  49. \section overview Overview
  50. The Debug module contains all functions necessary to perform debugging related tasks,
  51. e.g. checking assertions or logging.
  52. \section logging Logging
  53. Logging can be sent to a number of different locations:
  54. - a flat log file
  55. - a console window
  56. - a debugger via OutputDebugString
  57. - to a remote program (via a named pipe)
  58. - to a number of separated log files
  59. By default logging is enabled to the flat log file.
  60. \section cmd Commands
  61. The debug module is controlled via extendable commands. Commands are
  62. typically put into logical groups. A command can then be executed
  63. in a number of ways:
  64. - group.command \<param\> (explicitly specifies which group to use)
  65. - command \<param\> (assumes that the command resides in the same group
  66. as the previous one)
  67. - group. (switches the current group)
  68. Every group has to respond to the command 'help'.
  69. See also: \ref debug_cmd
  70. \section dbgcmd .dbgcmd file
  71. On startup the debug module tries to open a file called \<exe\>.dbgcmd -
  72. if found then all lines in this module are directly interpreted as commands.
  73. If the file is not found then default.dbgcmd is tried instead.
  74. This allows for setting up a default environment.
  75. */
  76. /**
  77. \page debug_cmd Debug commands
  78. Notation used:
  79. - [ abc ] means that 'abc' may or may not be specified
  80. - { abc } means that 'abc' may be specified any number of times (or not at all)
  81. - (a|b|c) means that either 'a', 'b' or 'c' must be specified once
  82. The following commands are already build in (group: debug):
  83. <table><tr>
  84. <td><b>Command</b></td>
  85. <td><b>Parameters</b></td>
  86. <td><b>Description</b></td>
  87. </tr><tr>
  88. <!---------------------------------->
  89. <td valign=top>list</td>
  90. <td valign=top>(g|l|d|a|c) [ \<pattern\> ]</td>
  91. <td>
  92. Shows some or all items of a specific type.
  93. The following items are supported:
  94. - g: command groups
  95. - l: log groups (only those encountered yet)
  96. - d: log groups with descriptions (only those that have descriptions)
  97. - a: asserts/crashes (only those hit yet)
  98. - c: checks (only those failed yet)
  99. If a pattern is specified only items matching
  100. that pattern are shown. A pattern can contain
  101. any character, letter, or a wildcard '*'.
  102. Please note that assert, crashes, and check items have
  103. their line number appended to the current file name,
  104. e.g. debug.cpp(13).
  105. Example:
  106. \code
  107. > list g
  108. debug
  109. > list l test*
  110. test
  111. test_log2
  112. > list d test*
  113. test_log2: test log group w/ description
  114. \endcode
  115. </td>
  116. </tr><tr>
  117. <!---------------------------------->
  118. <td valign=top>help</td>
  119. <td valign=top></td>
  120. <td>
  121. Shows help regarding debug group commands.
  122. Example:
  123. \code
  124. > help
  125. Help info debug group:
  126. ...
  127. \endcode
  128. </td>
  129. </tr><tr>
  130. <!---------------------------------->
  131. <td valign=top>io</td>
  132. <td valign=top>[ \<I/O Class\> \<cmd\> { \<param\> }] </td>
  133. <td>
  134. Issues a I/O class command. I/O class commands are used
  135. for determining where all log output should be sent.
  136. Please check the list of \ref debug_ioclasses for a list
  137. of existing I/O classes.
  138. Each existing I/O class must accept at least the
  139. following two commands: 'add' and 'remove'. Parameters
  140. for these commands and additional commands are defined
  141. on this page: \ref debug_ioclasses
  142. If the command is entered without any parameters a list
  143. of active I/O classes is shown. Typing 'io ?' retrieves
  144. a list of possible I/O classes.
  145. Example:
  146. \code
  147. > io
  148. Active:
  149. flat (flat log file)
  150. ods (OutputDebugString)
  151. > io ods remove
  152. > io ?
  153. Possible:
  154. flat (flat/split log file)
  155. con (console window)
  156. ods (OutputDebugString)
  157. net (Network destination via named pipe)
  158. \endcode
  159. </td>
  160. </tr><tr>
  161. <!---------------------------------->
  162. <td valign=top>alwaysflush</td>
  163. <td valign=top>[ (+|-) ]</td>
  164. <td>
  165. Enables/disables flushing after each new entry in
  166. the log file (default: off)
  167. Example:
  168. \code
  169. > alwaysflush +
  170. Flush: on
  171. \endcode
  172. </td>
  173. </tr><tr>
  174. <!---------------------------------->
  175. <td valign=top>timestamp</td>
  176. <td valign=top>[ (+|-) ]</td>
  177. <td>
  178. Enables/disables timestamping each log entry
  179. (default: off).
  180. Example:
  181. \code
  182. > timestamp +
  183. Timestamping: on
  184. \endcode
  185. </td>
  186. </tr><tr>
  187. <!---------------------------------->
  188. <td valign=top>exit</td>
  189. <td valign=top></td>
  190. <td>
  191. Exits program immediately.
  192. </td>
  193. </tr><tr>
  194. <!---------------------------------->
  195. <td valign=top>clear</td>
  196. <td valign=top>(l|a|c)</td>
  197. <td>
  198. Clears the given inclusion/exclusion list
  199. (l=logs, a=asserts/crashes, c=checks).
  200. </td>
  201. </tr><tr>
  202. <!---------------------------------->
  203. <td valign=top>add</td>
  204. <td valign=top>(l|a|c) (+|-) \<pattern\></td>
  205. <td>
  206. Adds a pattern to the given list (l=logs,
  207. a=asserts/crashes, c=checks). By default all
  208. asserts, crashes, and checks are active, all logs
  209. inactive. Each item is then checked
  210. against all pattern in the respective
  211. list. If a match is found the active/inactive
  212. state is modified accordingly (+ for active, -
  213. for inactive). The final state is always
  214. the last match.
  215. Example:
  216. \code
  217. > clear l
  218. > add l + test*
  219. > add l - *45*
  220. \endcode
  221. This would now enable logging on all log groups
  222. that start with 'test' but don't have '45' in
  223. the group name.
  224. </td>
  225. </tr><tr>
  226. <!---------------------------------->
  227. <td valign=top>view</td>
  228. <td valign=top>[ (l|a|c) ]</td>
  229. <td>
  230. Shows the active pattern for the given list
  231. (l=logs, a=asserts/crashes, c=checks).
  232. </td>
  233. <!-- keep this as template for new commands -->
  234. </tr><tr>
  235. <!---------------------------------->
  236. <td valign=top></td>
  237. <td valign=top></td>
  238. <td>
  239. </td>
  240. </tr></table>
  241. */
  242. /**
  243. \addtogroup debug_stream Debug and Logging stream
  244. The Debug class can act as an output stream for debugging and logging purposes.
  245. This is used e.g. for displaying custom messages in a failed DASSERT_MSG statement
  246. or for logging data.
  247. There are a number of reasons why this module implements this in a stream-like
  248. fashion instead of the 'usual' printf method:
  249. - type safety: using a streams-like approach makes logging statements
  250. type safe. No more crashes in an ASSERT or log statement because the
  251. parameter specifiers in the printf format string didn't match with
  252. the values actually given.
  253. - extensibility: new stream operators can be implemented outside of the debug
  254. module
  255. Syntactically the Debug class acts almost like a ostream class:
  256. \code
  257. int n=1;
  258. float f=4;
  259. DLOG( "This is a static string and some other stuff: "
  260. << n << " " << f << "\n" );
  261. \endcode
  262. New types can be added easily, e.g.:
  263. \code
  264. struct Point2D { int x,y; };
  265. inline Debug& operator<<(Debug& debug, const Point2D &pt)
  266. {
  267. debug << "(" << pt.x << ";" << pt.y << ")";
  268. return debug;
  269. }
  270. void test(const Point2D &val)
  271. {
  272. DLOG( "Current point value is " << val << "\n" );
  273. DASSERT_MSG( val.x>=0 && val.y>=0, val << " is invalid");
  274. }
  275. \endcode
  276. Please note that all these operators should not be cluttered with any #ifdef _DEBUG
  277. or similar conditional compile statements. It is not necessary to remove these
  278. operators from the code in release builds (just don't forget to add 'inline' before
  279. the operator though).
  280. In addition there are a number of helper classes declared inside of Debug:
  281. - Debug::MemDump provides functions for inserting a raw memory dump into the Debug stream
  282. - Debug::HResult dumps out a HRESULT value plus additionally calling custom translator functions
  283. */
  284. /**
  285. \page debug_ioclasses Debug I/O classes
  286. The %Debug module defines a number of pre-existing I/O classes. New classes can
  287. be developed and added.
  288. An I/O class can have additional commands and parameters. This section lists
  289. the existing I/O classes and their additional commands and parameters. The
  290. initial part of the command ('io \<class\>') is omitted here.
  291. \section debug_ioc_flat flat (flat or split log file)
  292. By default all data is written into a single flag log file. Optionally the
  293. size of this log file may be limited (implemented by using a memory based
  294. ring buffer).
  295. <table><tr>
  296. <td><b>I/O Command</b></td>
  297. <td><b>Parameters</b></td>
  298. <td><b>Description</b></td>
  299. </tr><tr>
  300. <!---------------------------------->
  301. <td valign=top>add</td>
  302. <td valign=top>[ \<filename\> [ \<size in kb\> ] ]</td>
  303. <td>
  304. Adds the flat I/O class. If a filename is
  305. specified all output is written to that file.
  306. Otherwise the filename \<exe\>-\<machinename\>.log
  307. (resp. \<exe\>-\<machinename\>-\<splitname\>.log)
  308. is automatically used. Any existing files with
  309. that name are overwritten.
  310. Instead of a real file name a 'magic' file name
  311. can be used by starting the file name with a '*'
  312. followed by any number of special characters:
  313. - 'e': inserts EXE name
  314. - 'm': inserts machine name
  315. - 'u': inserts username
  316. - 't': inserts timestamp
  317. - 'n': inserts split name (empty if main log file)
  318. - '-': inserts '-'
  319. - 'E', 'M', 'U', 'T', 'N': same as above but with '-'
  320. in front (for 'N': empty if main log file)
  321. .log is automatically appended if using magic
  322. file names.
  323. So basically 'add' and 'and *eMN' are identical.
  324. If a size is specified then all data is internally written
  325. to a fixed size memory based ring buffer. This data is
  326. flushed out once the program exits.
  327. If no size is given then the size of the log file
  328. is not limited and any log data is written out
  329. immediately.
  330. </td>
  331. </tr><tr>
  332. <!---------------------------------->
  333. <td valign=top>copy</td>
  334. <td valign=top>\<directory\></td>
  335. <td>
  336. Copies generated log file(s) into the given
  337. directory if the program exists or crashes.
  338. If there is already a log file with the same
  339. name a unique number is appended to the
  340. current log files' name.
  341. </td>
  342. </tr><tr>
  343. <!---------------------------------->
  344. <td valign=top>splitadd</td>
  345. <td valign=top>\<types\> \<filter\> \<name\> [ \<size in kb\> ]</td>
  346. <td>
  347. Splits off part of the log data. Multiple
  348. splits can be defined. They are written out
  349. to the first matching split file.
  350. 'types' defines one or more
  351. string types which should be split off:
  352. - a: asserts/crashes
  353. - c: checks
  354. - l: logs
  355. - h: crash
  356. - x: exceptions
  357. - r: replies from commands
  358. - o: other messages
  359. Next a filter is specified that determines
  360. which items are to be filtered (only for string
  361. types a, c and l). Items can be listed with
  362. then 'list' command. The filter is exactly specified
  363. as in that command.
  364. The third parameter defines a name for this
  365. split. If there is already a split with the same name
  366. then both will write to the same destination file.
  367. Note: If splits are used and the filename given
  368. for 'add' is static then the split name is automatically
  369. appended to the log file name (before the extension).
  370. If a size is specified then all data is internally written
  371. to a fixed size memory based ring buffer. This data is
  372. flushed out once the program exits.
  373. If no size is given then the size of the log file
  374. is not limited and any log data is written out
  375. immediately.
  376. </td>
  377. </tr><tr>
  378. <!---------------------------------->
  379. <td valign=top>splitview</td>
  380. <td valign=top></td>
  381. <td>
  382. Shows all existing splits in the order they are
  383. evaluated.
  384. </td>
  385. </tr><tr>
  386. <!---------------------------------->
  387. <td valign=top>splitremove</td>
  388. <td valign=top>\<namepattern\></td>
  389. <td>
  390. Removes all active splits matching the given
  391. name pattern.
  392. </td>
  393. <!-- keep this as template for new commands -->
  394. </tr><tr>
  395. <!---------------------------------->
  396. <td valign=top></td>
  397. <td valign=top></td>
  398. <td>
  399. </td>
  400. </tr></table>
  401. \section debug_ioc_con con (console window)
  402. <table><tr>
  403. <td><b>I/O Command</b></td>
  404. <td><b>Parameters</b></td>
  405. <td><b>Description</b></td>
  406. </tr><tr>
  407. <!---------------------------------->
  408. <td valign=top>add</td>
  409. <td valign=top>%</td>
  410. <td>
  411. Adds the console window as log output. A new
  412. console window is created (if it doesn't
  413. exist already).
  414. </td>
  415. <!-- keep this as template for new commands -->
  416. </tr><tr>
  417. <!---------------------------------->
  418. <td valign=top></td>
  419. <td valign=top></td>
  420. <td>
  421. </td>
  422. </tr></table>
  423. \section debug_ioc_ods ods (OutputDebugString, for use in debugger)
  424. <table><tr>
  425. <td><b>I/O Command</b></td>
  426. <td><b>Parameters</b></td>
  427. <td><b>Description</b></td>
  428. </tr><tr>
  429. <!---------------------------------->
  430. <td valign=top>add</td>
  431. <td valign=top>%</td>
  432. <td>
  433. %Debug output is sent via OutputDebugString.
  434. </td>
  435. <!-- keep this as template for new commands -->
  436. </tr><tr>
  437. <!---------------------------------->
  438. <td valign=top></td>
  439. <td valign=top></td>
  440. <td>
  441. </td>
  442. </tr></table>
  443. \section debug_ioc_net net (Network destination via named pipe)
  444. <table><tr>
  445. <td><b>I/O Command</b></td>
  446. <td><b>Parameters</b></td>
  447. <td><b>Description</b></td>
  448. </tr><tr>
  449. <!---------------------------------->
  450. <td valign=top>add</td>
  451. <td valign=top>\<name\></td>
  452. <td>
  453. Tells system which computer to connect to for
  454. remote logging. By default this is the local
  455. machine. The debug module tries to connect
  456. to a named pipe \\\\\<name\>\\pipe\\ea_debug_v1.
  457. <!-- sorry about all these backslashes but they're used for escaping... -->
  458. </td>
  459. <!-- keep this as template for new commands -->
  460. </tr><tr>
  461. <!---------------------------------->
  462. <td valign=top></td>
  463. <td valign=top></td>
  464. <td>
  465. </td>
  466. </tr></table>
  467. */
  468. /**
  469. \page debug_structcmd Structured command reply
  470. \section debug_structcmd_overview Overview
  471. All commands are capable of returning replies in two differnt forms: A regular
  472. reply or a structured reply.
  473. A structured reply is basically like the regular reply but with three differences:
  474. - Structured reply string type \ref DebugIOInterface::StructuredCmdReply
  475. - There is a 1:1 mapping between command and result i.e. no matter how long a command
  476. result is there will always be only one call to the \ref DebugIOInterface::Write method
  477. for that result.
  478. - The result format is fixed for any given command i.e. it must not change.
  479. A structured reply is given if the command is invoked with a '!' as first character.
  480. The motivation behind having structured command replies is to make it possible
  481. to hide some of the debug command complexity behind a UI.
  482. \section debug_structcmd_list List of structured command replies for debug command group
  483. The reply for a structured command always consists of first repeating the
  484. given command, a CR and then additional optional reply data.
  485. <table><tr>
  486. <td valign=top><b>Command</b></td>
  487. <td><b>Reply</b></td>
  488. </tr><tr>
  489. <!---------------------------------->
  490. <td valign=top>list</td>
  491. <td>
  492. \<item 1\> CR<br>
  493. ...<br>
  494. \<item N\> CR
  495. </td>
  496. </tr><tr>
  497. <!---------------------------------->
  498. <td valign=top>help</td>
  499. <td>
  500. regular reply format (unstructured)
  501. </td>
  502. </tr><tr>
  503. <!---------------------------------->
  504. <td valign=top>io, io ?</td>
  505. <td>
  506. \<item 1\> CR<br>
  507. ...<br>
  508. \<item N\> CR
  509. </td>
  510. </tr><tr>
  511. <!---------------------------------->
  512. <td valign=top>io \<any parameters\></td>
  513. <td>
  514. '1' CR (if command ok) <br>
  515. '0' \<error msg\> CR (if command failed)
  516. </td>
  517. </tr><tr>
  518. <!---------------------------------->
  519. <td valign=top>alwaysflush</td>
  520. <td>
  521. '1' CR (if flush on) <br>
  522. '0' CR (if flush off)
  523. </td>
  524. </tr><tr>
  525. <!---------------------------------->
  526. <td valign=top>timestamp</td>
  527. <td>
  528. '1' CR (if timestamp on) <br>
  529. '0' CR (if timestamp off)
  530. </td>
  531. </tr><tr>
  532. <!---------------------------------->
  533. <td valign=top>exit</td>
  534. <td>
  535. none
  536. </td>
  537. </tr><tr>
  538. <!---------------------------------->
  539. <td valign=top>clear</td>
  540. <td>
  541. none
  542. </td>
  543. </tr><tr>
  544. <!---------------------------------->
  545. <td valign=top>add</td>
  546. <td>
  547. none
  548. </td>
  549. </tr><tr>
  550. <!---------------------------------->
  551. <td valign=top>view</td>
  552. <td>
  553. \<item 1\> CR<br>
  554. ...<br>
  555. \<item N\> CR
  556. </td>
  557. <!-- keep this as template for new commands -->
  558. </tr><tr>
  559. <!---------------------------------->
  560. <td valign=top></td>
  561. <td>
  562. </td>
  563. </tr></table>
  564. */
  565. #endif // DEBUG_DOC_H