1
0

extimp.h 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774
  1. /*++
  2. Copyright (c) 2013 Minoca Corp. All Rights Reserved
  3. Module Name:
  4. extimp.h
  5. Abstract:
  6. This header contains definitions for the debug client import interface.
  7. Author:
  8. Evan Green 8-May-2013
  9. --*/
  10. //
  11. // ------------------------------------------------------------------- Includes
  12. //
  13. //
  14. // ---------------------------------------------------------------- Definitions
  15. //
  16. #define EXTENSION_ENTRY_NAME "ExtensionEntry"
  17. #define DEBUG_EXTENSION_INTERFACE_VERSION 2
  18. //
  19. // ------------------------------------------------------ Data Type Definitions
  20. //
  21. typedef
  22. INT
  23. (*PDBG_REGISTER_EXTENSION) (
  24. PDEBUGGER_CONTEXT Context,
  25. PVOID Token,
  26. PSTR ExtensionName,
  27. PSTR OneLineDescription,
  28. PEXTENSION_PROTOTYPE Routine
  29. );
  30. /*++
  31. Routine Description:
  32. This routine registers a debugger extension with the client.
  33. Arguments:
  34. Context - Supplies a pointer to the application context.
  35. Token - Supplies the unique token provided to the extension library upon
  36. initialization.
  37. ExtensionName - Supplies the name of the extension to register. This name
  38. must not already be registered by the current extension or any other.
  39. OneLineDescription - Supplies a quick description of the extension, no
  40. longer than 60 characters. This parameter is not optional.
  41. Routine - Supplies the routine to call when the given extension is
  42. invoked.
  43. Return Value:
  44. 0 on success.
  45. Returns an error code on failure.
  46. --*/
  47. typedef
  48. INT
  49. (*PDBG_OUT_VA_LIST) (
  50. PDEBUGGER_CONTEXT Context,
  51. const char *Format,
  52. va_list Arguments
  53. );
  54. /*++
  55. Routine Description:
  56. This routine prints a formatted string to the given debugger console.
  57. Arguments:
  58. Context - Supplies a pointer to the debugger context to output to.
  59. Format - Supplies the printf format string.
  60. Arguments - Supplies the argument list to the format string. The va_end
  61. macro is not invoked on this list.
  62. Return Value:
  63. Returns the number of bytes successfully converted. A null terminator is
  64. not written.
  65. Returns a negative number if an error was encountered.
  66. --*/
  67. typedef
  68. INT
  69. (*PDBG_EVALUATE) (
  70. PDEBUGGER_CONTEXT Context,
  71. PSTR String,
  72. PULONGLONG Result
  73. );
  74. /*++
  75. Routine Description:
  76. This routine evaluates a mathematical expression. The following operators
  77. are supported: +, -, *, /, (, ). No spaces are permitted. Module symbols
  78. are permitted and will be translated into their corresponding address.
  79. Arguments:
  80. Context - Supplies a pointer to the debugger application context.
  81. String - Supplies the string to evaluate.
  82. Result - Supplies a pointer to the 64-bit unsigned integer where the result
  83. will be stored.
  84. Return Value:
  85. 0 if the expression was successfully evaluated.
  86. Returns an error code on failure.
  87. --*/
  88. typedef
  89. INT
  90. (*PDBG_PRINT_ADDRESS_SYMBOL) (
  91. PDEBUGGER_CONTEXT Context,
  92. ULONGLONG Address
  93. );
  94. /*++
  95. Routine Description:
  96. This routine prints a descriptive version of the given address, including
  97. the module and function name if possible.
  98. Arguments:
  99. Address - Supplies the virtual address of the target to print information
  100. about.
  101. Return Value:
  102. 0 if information was successfully printed.
  103. Returns an error code on failure.
  104. --*/
  105. typedef
  106. INT
  107. (*PDBG_READ_MEMORY) (
  108. PDEBUGGER_CONTEXT Context,
  109. BOOL VirtualMemory,
  110. ULONGLONG Address,
  111. ULONG BytesToRead,
  112. PVOID Buffer,
  113. PULONG BytesRead
  114. );
  115. /*++
  116. Routine Description:
  117. This routine retrieves the debuggee's memory.
  118. Arguments:
  119. Context - Supplies a pointer to the application context.
  120. VirtualMemory - Supplies a flag indicating whether the read should be
  121. virtual or physical.
  122. Address - Supplies the address to read from the target's memory.
  123. BytesToRead - Supplies the number of bytes to be read.
  124. Buffer - Supplies a pointer to the buffer where the memory contents will be
  125. returned.
  126. BytesRead - Supplies a pointer that receive the number of bytes that were
  127. actually read from the target.
  128. Return Value:
  129. 0 on success.
  130. Returns an error code on failure.
  131. --*/
  132. typedef
  133. INT
  134. (*PDBG_WRITE_MEMORY) (
  135. PDEBUGGER_CONTEXT Context,
  136. BOOL VirtualMemory,
  137. ULONGLONG Address,
  138. ULONG BytesToWrite,
  139. PVOID Buffer,
  140. PULONG BytesWritten
  141. );
  142. /*++
  143. Routine Description:
  144. This routine writes to the debuggee's memory.
  145. Arguments:
  146. Context - Supplies a pointer to the application context.
  147. VirtualMemory - Supplies a flag indicating whether the read should be
  148. virtual or physical.
  149. Address - Supplies the address to write to the target's memory.
  150. BytesToWrite - Supplies the number of bytes to be written.
  151. Buffer - Supplies a pointer to the buffer containing the values to write.
  152. BytesWritten - Supplies a pointer that receives the number of bytes that
  153. were actually written to the target.
  154. Return Value:
  155. 0 if the write was successful.
  156. Returns an error code on failure.
  157. --*/
  158. typedef
  159. INT
  160. (*PDBG_REBOOT) (
  161. PDEBUGGER_CONTEXT Context,
  162. ULONG RebootType
  163. );
  164. /*++
  165. Routine Description:
  166. This routine attempts to reboot the target machine.
  167. Arguments:
  168. Context - Supplies a pointer to the application context.
  169. RebootType - Supplies the type of reboot to perform. See the
  170. DEBUG_REBOOT_TYPE enumeration.
  171. Return Value:
  172. 0 if the write was successful.
  173. Returns an error code on failure.
  174. --*/
  175. typedef
  176. INT
  177. (*PDBG_GET_CALL_STACK) (
  178. PDEBUGGER_CONTEXT Context,
  179. PREGISTERS_UNION Registers,
  180. PSTACK_FRAME Frames,
  181. PULONG FrameCount
  182. );
  183. /*++
  184. Routine Description:
  185. This routine attempts to unwind the call stack starting at the given
  186. machine state.
  187. Arguments:
  188. Context - Supplies a pointer to the application context.
  189. Registers - Supplies an optional pointer to the registers on input. On
  190. output, these registers will be updated with the unwound value. If this
  191. is NULL, then the current break notification registers will be used.
  192. Frames - Supplies a pointer where the array of stack frames will be
  193. returned.
  194. FrameCount - Supplies the number of frames allocated in the frames
  195. argument, representing the maximum number of frames to get. On output,
  196. returns the number of valid frames in the array.
  197. Return Value:
  198. 0 on success.
  199. Returns an error code on failure.
  200. --*/
  201. typedef
  202. INT
  203. (*PDBG_PRINT_CALL_STACK) (
  204. PDEBUGGER_CONTEXT Context,
  205. PREGISTERS_UNION Registers,
  206. BOOL PrintFrameNumbers
  207. );
  208. /*++
  209. Routine Description:
  210. This routine prints a call stack starting with the given registers.
  211. Arguments:
  212. Context - Supplies a pointer to the application context.
  213. Registers - Supplies an optional pointer to the registers to use when
  214. unwinding.
  215. PrintFrameNumbers - Supplies a boolean indicating whether or not frame
  216. numbers should be printed to the left of every frame.
  217. Return Value:
  218. 0 on success.
  219. Returns an error code on failure.
  220. --*/
  221. typedef
  222. INT
  223. (*PDBG_GET_TARGET_INFORMATION) (
  224. PDEBUGGER_CONTEXT Context,
  225. PDEBUG_TARGET_INFORMATION TargetInformation,
  226. ULONG TargetInformationSize
  227. );
  228. /*++
  229. Routine Description:
  230. This routine returns information about the machine being debugged.
  231. Arguments:
  232. Context - Supplies a pointer to the application context.
  233. TargetInformation - Supplies a pointer where the target information will
  234. be returned.
  235. TargetInformationSize - Supplies the size of the target information buffer.
  236. This must be the size of a debug target information structure.
  237. Return Value:
  238. 0 on success.
  239. Returns an error code on failure.
  240. --*/
  241. typedef
  242. ULONG
  243. (*PDBG_GET_TARGET_POINTER_SIZE) (
  244. PDEBUGGER_CONTEXT Context
  245. );
  246. /*++
  247. Routine Description:
  248. This routine returns the size of a pointer on the target machine, in bytes.
  249. Arguments:
  250. Context - Supplies a pointer to the application context.
  251. Return Value:
  252. The size of a pointer on the target system, in bytes.
  253. --*/
  254. typedef
  255. INT
  256. (*PDBG_GET_MEMBER_OFFSET) (
  257. PTYPE_SYMBOL StructureType,
  258. PSTR FieldName,
  259. PULONG FieldOffset,
  260. PULONG FieldSize
  261. );
  262. /*++
  263. Routine Description:
  264. This routine returns the given field's offset (in bits) within the
  265. given structure.
  266. Arguments:
  267. StructureType - Supplies a pointer to a symbol structure type.
  268. FieldName - Supplies a string containing the name of the field whose offset
  269. will be returned.
  270. FieldOffset - Supplies a pointer that will receive the bit offset of the
  271. given field name within the given structure.
  272. FieldSize - Supplies a pointer that will receive the size of the field in
  273. bits.
  274. Return Value:
  275. 0 on success.
  276. ENOENT if no such field name exists.
  277. Other error codes on other errors.
  278. --*/
  279. typedef
  280. INT
  281. (*PDBG_GET_TYPE_BY_NAME) (
  282. PDEBUGGER_CONTEXT Context,
  283. PSTR TypeName,
  284. PTYPE_SYMBOL *Type
  285. );
  286. /*++
  287. Routine Description:
  288. This routine finds a type symbol object by its type name.
  289. Arguments:
  290. Context - Supplies a pointer to the application context.
  291. TypeName - Supplies a pointer to the string containing the name of the
  292. type to find. This can be prefixed with an module name if needed.
  293. Type - Supplies a pointer where a pointer to the type will be returned.
  294. Return Value:
  295. 0 on success.
  296. ENOENT if no type with the given name was found.
  297. Returns an error number on failure.
  298. --*/
  299. typedef
  300. INT
  301. (*PDBG_READ_INTEGER_MEMBER) (
  302. PDEBUGGER_CONTEXT Context,
  303. PTYPE_SYMBOL Type,
  304. PSTR MemberName,
  305. ULONGLONG Address,
  306. PVOID Data,
  307. ULONG DataSize,
  308. PULONGLONG Value
  309. );
  310. /*++
  311. Routine Description:
  312. This routine reads an integer sized member out of an already read-in
  313. structure.
  314. Arguments:
  315. Context - Supplies a pointer to the application context.
  316. Type - Supplies a pointer to the type of the data.
  317. MemberName - Supplies a pointer to the member name.
  318. Address - Supplies the address where the data was obtained.
  319. Data - Supplies a pointer to the data contents.
  320. DataSize - Supplies the size of the data buffer in bytes.
  321. Value - Supplies a pointer where the value will be returned on success.
  322. Return Value:
  323. 0 on success.
  324. Returns an error number on failure.
  325. --*/
  326. typedef
  327. INT
  328. (*PDBG_READ_TYPE_BY_NAME) (
  329. PDEBUGGER_CONTEXT Context,
  330. ULONGLONG Address,
  331. PSTR TypeName,
  332. PTYPE_SYMBOL *FinalType,
  333. PVOID *Data,
  334. PULONG DataSize
  335. );
  336. /*++
  337. Routine Description:
  338. This routine reads in data from the target for a specified type, which is
  339. given as a string.
  340. Arguments:
  341. Context - Supplies a pointer to the application context.
  342. Address - Supplies a target address pointer where the data resides.
  343. TypeName - Supplies a pointer to a string containing the type name to get.
  344. This should start with a type name, and can use dot '.' notation to
  345. specify field members, and array[] notation to specify dereferences.
  346. FinalType - Supplies a pointer where the final type symbol will be returned
  347. on success.
  348. Data - Supplies a pointer where the data will be returned on success. The
  349. caller is responsible for freeing this data when finished.
  350. DataSize - Supplies a pointer where the size of the data in bytes will be
  351. returned.
  352. Return Value:
  353. 0 on success.
  354. Returns an error number on failure.
  355. --*/
  356. typedef
  357. INT
  358. (*PDBG_READ_TYPE) (
  359. PDEBUGGER_CONTEXT Context,
  360. ULONGLONG Address,
  361. PTYPE_SYMBOL Type,
  362. PVOID *Data,
  363. PULONG DataSize
  364. );
  365. /*++
  366. Routine Description:
  367. This routine reads in data from the target for a specified type.
  368. Arguments:
  369. Context - Supplies a pointer to the application context.
  370. Address - Supplies a target address pointer where the data resides.
  371. Type - Supplies a pointer to the type symbol to get.
  372. Data - Supplies a pointer where the data will be returned on success. The
  373. caller is responsible for freeing this data when finished.
  374. DataSize - Supplies a pointer where the size of the data in bytes will be
  375. returned.
  376. Return Value:
  377. 0 on success.
  378. Returns an error number on failure.
  379. --*/
  380. typedef
  381. INT
  382. (*PDBG_PRINT_TYPE_MEMBER) (
  383. PDEBUGGER_CONTEXT Context,
  384. ULONGLONG Address,
  385. PVOID Data,
  386. ULONG DataSize,
  387. PTYPE_SYMBOL Type,
  388. PSTR MemberName,
  389. ULONG SpaceLevel,
  390. ULONG RecursionCount
  391. );
  392. /*++
  393. Routine Description:
  394. This routine prints a member of a structure or union whose contents have
  395. already been read in.
  396. Arguments:
  397. Context - Supplies a pointer to the application context.
  398. Address - Supplies the address where this data came from.
  399. Data - Supplies a pointer to the data contents.
  400. DataSize - Supplies the size of the data contents buffer in bytes.
  401. Type - Supplies a pointer to the structure type.
  402. MemberName - Supplies the name of the member to print.
  403. SpaceLevel - Supplies the number of spaces worth of indentation to print
  404. for subsequent lines.
  405. RecursionCount - Supplies the number of substructures to recurse into.
  406. Return Value:
  407. 0 on success.
  408. Returns an error number on failure.
  409. --*/
  410. /*++
  411. Structure Description:
  412. This structure stores pointers to the set of functions callable from in a
  413. debugger extension.
  414. Members:
  415. Version - Stores the table version. Set to
  416. DEBUG_EXTENSION_INTERFACE_VERSION.
  417. RegisterExtension - Stores a pointer to a function used to register a new
  418. debugger extension.
  419. Out - Stores a pointer to a function that can print to the console.
  420. OutVaList - Stores a pointer to a function that can print to the console
  421. with a va list argument.
  422. Evaluate - Stores a pointer to a function that can evaluate strings of
  423. addresses and debug symbols into a numeric value.
  424. PrintAddressSymbol - Stores a pointer to a function that will print the
  425. symbolic value of an address pointer.
  426. ReadMemory - Stores a pointer to a function that can read memory from the
  427. debugging target.
  428. WriteMemory - Stores a pointer to a function that can write memory to the
  429. debugging target.
  430. Reboot - Stores a pointer to a function that resets the target system.
  431. GetTargetInformation - Stores a pointer to a function that will return
  432. information about the debugging target.
  433. GetTargetPointerSize - Stores a pointer to a function that will return the
  434. pointer size for the debugging target.
  435. GetMemberOffset - Stores a pointer to a function used to determine the
  436. offset of a structure's member from its base.
  437. GetTypeByName - Stores a pointer to a function that looks up a type symbol
  438. by its name.
  439. ReadIntegerMember - Stores a pointer to a function used to read an
  440. integer or address sized portion of a structure.
  441. ReadTypeByName - Stores a pointer to a function used to read a structure
  442. type specified by a string.
  443. ReadType - Stores a pointer to a function usd to read a type from target
  444. memory.
  445. PrintTypeMember - Stores a pointer to a function used to print a portion
  446. of a previously read-in structure.
  447. --*/
  448. typedef struct _DEBUG_EXTENSION_IMPORT_INTERFACE {
  449. ULONG Version;
  450. PDBG_REGISTER_EXTENSION RegisterExtension;
  451. PDBG_OUT_VA_LIST OutVaList;
  452. PDBG_EVALUATE Evaluate;
  453. PDBG_PRINT_ADDRESS_SYMBOL PrintAddressSymbol;
  454. PDBG_READ_MEMORY ReadMemory;
  455. PDBG_WRITE_MEMORY WriteMemory;
  456. PDBG_REBOOT Reboot;
  457. PDBG_GET_CALL_STACK GetCallStack;
  458. PDBG_PRINT_CALL_STACK PrintCallStack;
  459. PDBG_GET_TARGET_INFORMATION GetTargetInformation;
  460. PDBG_GET_TARGET_POINTER_SIZE GetTargetPointerSize;
  461. PDBG_GET_MEMBER_OFFSET GetMemberOffset;
  462. PDBG_GET_TYPE_BY_NAME GetTypeByName;
  463. PDBG_READ_INTEGER_MEMBER ReadIntegerMember;
  464. PDBG_READ_TYPE_BY_NAME ReadTypeByName;
  465. PDBG_READ_TYPE ReadType;
  466. PDBG_PRINT_TYPE_MEMBER PrintTypeMember;
  467. } DEBUG_EXTENSION_IMPORT_INTERFACE, *PDEBUG_EXTENSION_IMPORT_INTERFACE;
  468. typedef
  469. INT
  470. (*PEXTENSION_ENTRY_INTERNAL) (
  471. ULONG ExtensionApiVersion,
  472. PDEBUGGER_CONTEXT ApplicationContext,
  473. PVOID Token,
  474. PDEBUG_EXTENSION_IMPORT_INTERFACE ImportInterface
  475. );
  476. /*++
  477. Routine Description:
  478. This routine defines the extension's internal entry point. This routine will
  479. get called when the extension is loaded. It is responsible for saving off
  480. the interface and then calling the debugger extension entry point.
  481. Arguments:
  482. ExtensionApiVersion - Supplies the revision of the debugger extension API.
  483. ApplicationContext - Supplies a pointer that represents the debugger
  484. application instance.
  485. Token - Supplies a token that uniquely idenfies the extension. This is used
  486. when registering extensions.
  487. ImportInterface - Supplies a pointer to the functions that the extension
  488. can call. This buffer will be constant, the extension does not need
  489. to make a copy of it.
  490. Return Value:
  491. 0 on success.
  492. Returns an error code on failure. The extension will be unloaded if it
  493. returns non-zero.
  494. --*/
  495. //
  496. // -------------------------------------------------------------------- Globals
  497. //
  498. //
  499. // -------------------------------------------------------- Function Prototypes
  500. //