dbgsym.h 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404
  1. /*++
  2. Copyright (c) 2013 Minoca Corp. All Rights Reserved
  3. Module Name:
  4. dbgsym.h
  5. Abstract:
  6. This header contains definitions for the higher level debugger symbol
  7. support.
  8. Author:
  9. Evan Green 7-May-2013
  10. --*/
  11. //
  12. // ---------------------------------------------------------------- Definitions
  13. //
  14. //
  15. // ------------------------------------------------------ Data Type Definitions
  16. //
  17. //
  18. // -------------------------------------------------------------------- Globals
  19. //
  20. //
  21. // ------------------------------------------------------------------ Functions
  22. //
  23. PDEBUGGER_MODULE
  24. DbgpFindModuleFromAddress (
  25. PDEBUGGER_CONTEXT Context,
  26. ULONGLONG Address,
  27. PULONGLONG DebasedAddress
  28. );
  29. /*++
  30. Routine Description:
  31. This routine attempts to locate a loaded module that corresponds to a
  32. virtual address in the target.
  33. Arguments:
  34. Context - Supplies a pointer to the application context.
  35. Address - Supplies an address somewhere in one of the loaded modules.
  36. DebasedAddress - Supplies an optional pointer where the address minus the
  37. loaded base difference from where the module would have preferred to
  38. have been loaded will be returned. This will be the address from the
  39. symbols' perspective.
  40. Return Value:
  41. Returns a pointer to the module that the address is contained in, or NULL if
  42. one cannot be found.
  43. --*/
  44. PDEBUGGER_MODULE
  45. DbgpGetModule (
  46. PDEBUGGER_CONTEXT Context,
  47. PSTR ModuleName,
  48. ULONG MaxLength
  49. );
  50. /*++
  51. Routine Description:
  52. This routine gets a module given the module name.
  53. Arguments:
  54. Context - Supplies a pointer to the application context.
  55. ModuleName - Supplies a null terminated string specifying the module name.
  56. MaxLength - Supplies the maximum length of the module name.
  57. Return Value:
  58. Returns a pointer to the module, or NULL if one could not be found.
  59. --*/
  60. ULONGLONG
  61. DbgpGetFunctionStartAddress (
  62. PDEBUGGER_CONTEXT Context,
  63. ULONGLONG Address
  64. );
  65. /*++
  66. Routine Description:
  67. This routine looks up the address for the beginning of the function given
  68. an address somewhere in the function.
  69. Arguments:
  70. Context - Supplies a pointer to the application context.
  71. Address - Supplies a virtual address somewhere inside the function.
  72. Return Value:
  73. Returns the address of the first instruction of the current function, or 0
  74. if the funtion could not be found.
  75. --*/
  76. BOOL
  77. DbgpFindSymbol (
  78. PDEBUGGER_CONTEXT Context,
  79. PSTR SearchString,
  80. PSYMBOL_SEARCH_RESULT SearchResult
  81. );
  82. /*++
  83. Routine Description:
  84. This routine searches for symbols. Wildcards are accepted. If the search
  85. string is preceded by "modulename!" then only that module will be searched.
  86. Arguments:
  87. Context - Supplies a pointer to the application context.
  88. SearchString - Supplies the string to search for.
  89. SearchResult - Supplies a pointer that receives symbol search result data.
  90. Return Value:
  91. Returns TRUE on success, or FALSE on failure.
  92. --*/
  93. PDEBUGGER_MODULE
  94. DbgpFindModuleFromEntry (
  95. PDEBUGGER_CONTEXT Context,
  96. PLOADED_MODULE_ENTRY TargetEntry
  97. );
  98. /*++
  99. Routine Description:
  100. This routine attempts to locate a loaded module that corresponds to the
  101. target's description of a loaded module.
  102. Arguments:
  103. Context - Supplies a pointer to the application context.
  104. TargetEntry - Supplies the target's module description.
  105. Return Value:
  106. Returns a pointer to the existing loaded module if one exists, or NULL if
  107. one cannot be found.
  108. --*/
  109. INT
  110. DbgpFindLocal (
  111. PDEBUGGER_CONTEXT Context,
  112. PREGISTERS_UNION Registers,
  113. PSTR LocalName,
  114. PDEBUG_SYMBOLS *ModuleSymbols,
  115. PDATA_SYMBOL *Local,
  116. PULONGLONG DebasedPc
  117. );
  118. /*++
  119. Routine Description:
  120. This routine searches the local variables and parameters in the function
  121. containing the given address for a variable matching the given name.
  122. Arguments:
  123. Context - Supplies a pointer to the application context.
  124. Registers - Supplies a pointer to the registers to use for the search.
  125. LocalName - Supplies a case insensitive string of the local name.
  126. ModuleSymbols - Supplies a pointer where the symbols for the module will be
  127. returned on success.
  128. Local - Supplies a pointer where the local symbol will be returned on
  129. success.
  130. DebasedPc - Supplies a pointer where the PC will be returned, adjusted by
  131. the amount the image load was adjusted by.
  132. Return Value:
  133. 0 on success.
  134. ENOENT if no local by that name could be found.
  135. Returns an error number on other failures.
  136. --*/
  137. PDATA_SYMBOL
  138. DbgpGetLocal (
  139. PFUNCTION_SYMBOL Function,
  140. PSTR LocalName,
  141. ULONGLONG ExecutionAddress
  142. );
  143. /*++
  144. Routine Description:
  145. This routine gets the most up to date version of a local variable symbol.
  146. Arguments:
  147. Function - Supplies a pointer to the function with the desired local
  148. variables.
  149. LocalName - Supplies a case sensitive string of the local name.
  150. ExecutionAddress - Supplies the current execution address. This function
  151. will attempt to find the local variable matching the LocalName whose
  152. minimum execution address is as close to ExecutionAddress as possible.
  153. It is assumed that this address has already been de-based (the current
  154. base address has been subtracted from it).
  155. Return Value:
  156. Returns a pointer to the local variable symbol, or NULL if one could not
  157. be found.
  158. --*/
  159. VOID
  160. DbgpGetFriendlyName (
  161. PSTR FullName,
  162. ULONG FullNameLength,
  163. PSTR *NameBegin,
  164. PULONG NameLength
  165. );
  166. /*++
  167. Routine Description:
  168. This routine determines the portion of the given binary name to use as the
  169. friendly name.
  170. Arguments:
  171. FullName - Supplies a pointer to the full path of the binary, null
  172. terminated.
  173. FullNameLength - Supplies the length of the full name buffer in bytes
  174. including the null terminator.
  175. NameBegin - Supplies a pointer where the beginning of the friendly name
  176. will be returned. This will point inside the full name.
  177. NameLength - Supplies a pointer where the number of characters in the
  178. friendly name will be returned, not including the null terminator.
  179. Return Value:
  180. Returns TRUE on success, or FALSE on failure.
  181. --*/
  182. INT
  183. DbgpPrintNumeric (
  184. PTYPE_SYMBOL Type,
  185. PVOID Data,
  186. UINTN DataSize
  187. );
  188. /*++
  189. Routine Description:
  190. This routine prints a numeric type's contents.
  191. Arguments:
  192. Type - Supplies a pointer to the type symbol to print.
  193. Data - Supplies a pointer to the data contents.
  194. DataSize - Supplies the size of the data in bytes.
  195. Return Value:
  196. 0 on success.
  197. ENOBUFS if the provided buffer is not large enough to accomodate the given
  198. type.
  199. --*/
  200. INT
  201. DbgpGetStructureMember (
  202. PDEBUGGER_CONTEXT Context,
  203. PTYPE_SYMBOL Type,
  204. PSTR MemberName,
  205. ULONGLONG Address,
  206. PVOID Data,
  207. UINTN DataSize,
  208. PVOID *ShiftedData,
  209. PUINTN ShiftedDataSize,
  210. PTYPE_SYMBOL *FinalType
  211. );
  212. /*++
  213. Routine Description:
  214. This routine returns a shifted form of the given data for accessing
  215. specific members of a structure.
  216. Arguments:
  217. Context - Supplies a pointer to the application context.
  218. Type - Supplies a pointer to the structure type.
  219. MemberName - Supplies a pointer to the member name string, which can
  220. contain dot '.' notation for accessing members, and array [] notation
  221. for access sub-elements and dereferencing.
  222. Address - Supplies the address the read data is located at.
  223. Data - Supplies a pointer to the read in data.
  224. DataSize - Supplies the size of the read data in bytes.
  225. ShiftedData - Supplies a pointer where the shifted data will be returned on
  226. success. The caller is responsible for freeing this data when finished.
  227. ShiftedDataSize - Supplies a pointer where the size of the shifted data
  228. will be returned on success.
  229. FinalType - Supplies an optional pointer where the final type of the
  230. data will be returned on success.
  231. Return Value:
  232. 0 on success.
  233. Returns an error number on failure.
  234. --*/
  235. PVOID
  236. DbgpShiftBufferRight (
  237. PVOID Buffer,
  238. UINTN DataSize,
  239. UINTN Bits,
  240. UINTN BitSize
  241. );
  242. /*++
  243. Routine Description:
  244. This routine shifts a buffer right by a given number of bits. Zero bits
  245. will be shifted in from the left.
  246. Arguments:
  247. Buffer - Supplies a pointer to the buffer contents to shift. This buffer
  248. will remain untouched.
  249. DataSize - Supplies the size of the data in bytes.
  250. Bits - Supplies the number of bits to shift.
  251. BitSize - Supplies an optional number of bits to keep after shifting, all
  252. others will be masked. Supply 0 to perform no masking.
  253. Return Value:
  254. Returns a pointer to a newly allocated and shifted buffer on success.
  255. NULL on allocation failure.
  256. --*/