symbols.h 37 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526
  1. /*++
  2. Copyright (c) 2012 Minoca Corp. All Rights Reserved
  3. Module Name:
  4. symbols.h
  5. Abstract:
  6. This header contains definitions for the generic debugger symbol
  7. information.
  8. Author:
  9. Evan Green 1-Jul-2012
  10. --*/
  11. //
  12. // ---------------------------------------------------------------- Definitions
  13. //
  14. #define MAX_RANGE_STRING 32
  15. //
  16. // ------------------------------------------------------ Data Type Definitions
  17. //
  18. typedef struct _STRUCTURE_MEMBER STRUCTURE_MEMBER, *PSTRUCTURE_MEMBER;
  19. typedef struct _ENUMERATION_MEMBER ENUMERATION_MEMBER, *PENUMERATION_MEMBER;
  20. typedef struct _DEBUG_SYMBOLS DEBUG_SYMBOLS, *PDEBUG_SYMBOLS;
  21. typedef struct _DATA_SYMBOL DATA_SYMBOL, *PDATA_SYMBOL;
  22. typedef enum _DATA_TYPE_TYPE {
  23. DataTypeInvalid,
  24. DataTypeRelation,
  25. DataTypeNumeric,
  26. DataTypeStructure,
  27. DataTypeEnumeration,
  28. DataTypeFunctionPointer,
  29. DataTypeNumberOfTypes
  30. } DATA_TYPE_TYPE, *PDATA_TYPE_TYPE;
  31. typedef enum _X86_REGISTER {
  32. X86RegisterEax,
  33. X86RegisterEcx,
  34. X86RegisterEdx,
  35. X86RegisterEbx,
  36. X86RegisterEsp,
  37. X86RegisterEbp,
  38. X86RegisterEsi,
  39. X86RegisterEdi,
  40. X86RegisterEip,
  41. X86RegisterEflags,
  42. X86RegisterCs,
  43. X86RegisterSs,
  44. X86RegisterDs,
  45. X86RegisterEs,
  46. X86RegisterFs,
  47. X86RegisterGs,
  48. X86RegisterSt0,
  49. X86RegisterSt1,
  50. X86RegisterSt2,
  51. X86RegisterSt3,
  52. X86RegisterSt4,
  53. X86RegisterSt5,
  54. X86RegisterSt6,
  55. X86RegisterSt7,
  56. X86RegisterCtrl,
  57. X86RegisterStat,
  58. X86RegisterTag,
  59. X86RegisterFpcs,
  60. X86RegisterFpIp,
  61. X86RegisterFpDs,
  62. X86RegisterFpDo
  63. } X86_REGISTER, *PX86_REGISTER;
  64. typedef enum _ARM_REGISTER {
  65. ArmRegisterR0,
  66. ArmRegisterR1,
  67. ArmRegisterR2,
  68. ArmRegisterR3,
  69. ArmRegisterR4,
  70. ArmRegisterR5,
  71. ArmRegisterR6,
  72. ArmRegisterR7,
  73. ArmRegisterR8,
  74. ArmRegisterR9,
  75. ArmRegisterR10,
  76. ArmRegisterR11,
  77. ArmRegisterR12,
  78. ArmRegisterR13,
  79. ArmRegisterR14,
  80. ArmRegisterR15,
  81. ArmRegisterSpsr = 128,
  82. ArmRegisterSpsrFiq,
  83. ArmRegisterSpsrIrq,
  84. ArmRegisterSpsrAbort,
  85. ArmRegisterSpsrUndefined,
  86. ArmRegisterSpsrSvc,
  87. ArmRegisterR8User = 144,
  88. ArmRegisterR9User,
  89. ArmRegisterR10User,
  90. ArmRegisterR11User,
  91. ArmRegisterR12User,
  92. ArmRegisterR13User,
  93. ArmRegisterR14User,
  94. ArmRegisterR8Fiq,
  95. ArmRegisterR9Fiq,
  96. ArmRegisterR10Fiq,
  97. ArmRegisterR11Fiq,
  98. ArmRegisterR12Fiq,
  99. ArmRegisterR13Fiq,
  100. ArmRegisterR14Fiq,
  101. ArmRegisterR8Irq,
  102. ArmRegisterR9Irq,
  103. ArmRegisterR10Irq,
  104. ArmRegisterR11Irq,
  105. ArmRegisterR12Irq,
  106. ArmRegisterR13Irq,
  107. ArmRegisterR14Irq,
  108. ArmRegisterR8Abort,
  109. ArmRegisterR9Abort,
  110. ArmRegisterR10Abort,
  111. ArmRegisterR11Abort,
  112. ArmRegisterR12Abort,
  113. ArmRegisterR13Abort,
  114. ArmRegisterR14Abort,
  115. ArmRegisterR8Undefined,
  116. ArmRegisterR9Undefined,
  117. ArmRegisterR10Undefined,
  118. ArmRegisterR11Undefined,
  119. ArmRegisterR12Undefined,
  120. ArmRegisterR13Undefined,
  121. ArmRegisterR14Undefined,
  122. ArmRegisterR8Svc,
  123. ArmRegisterR9Svc,
  124. ArmRegisterR10Svc,
  125. ArmRegisterR11Svc,
  126. ArmRegisterR12Svc,
  127. ArmRegisterR13Svc,
  128. ArmRegisterR14Svc,
  129. ArmRegisterD0 = 256,
  130. ArmRegisterD1,
  131. ArmRegisterD2,
  132. ArmRegisterD3,
  133. ArmRegisterD4,
  134. ArmRegisterD5,
  135. ArmRegisterD6,
  136. ArmRegisterD7,
  137. ArmRegisterD8,
  138. ArmRegisterD9,
  139. ArmRegisterD10,
  140. ArmRegisterD11,
  141. ArmRegisterD12,
  142. ArmRegisterD13,
  143. ArmRegisterD14,
  144. ArmRegisterD15,
  145. ArmRegisterD16,
  146. ArmRegisterD17,
  147. ArmRegisterD18,
  148. ArmRegisterD19,
  149. ArmRegisterD20,
  150. ArmRegisterD21,
  151. ArmRegisterD22,
  152. ArmRegisterD23,
  153. ArmRegisterD24,
  154. ArmRegisterD25,
  155. ArmRegisterD26,
  156. ArmRegisterD27,
  157. ArmRegisterD28,
  158. ArmRegisterD29,
  159. ArmRegisterD30,
  160. ArmRegisterD31,
  161. } ARM_REGISTER, *PARM_REGISTER;
  162. typedef enum _DATA_SYMBOL_LOCATION_TYPE {
  163. DataLocationInvalid,
  164. DataLocationRegister,
  165. DataLocationIndirect,
  166. DataLocationAbsoluteAddress,
  167. DataLocationComplex
  168. } DATA_SYMBOL_LOCATION_TYPE, *PDATA_SYMBOL_LOCATION_TYPE;
  169. typedef enum _SYMBOL_RESULT_TYPE {
  170. SymbolResultInvalid,
  171. SymbolResultFunction,
  172. SymbolResultType,
  173. SymbolResultData
  174. } SYMBOL_RESULT_TYPE, *PSYMBOL_RESULT_TYPE;
  175. //
  176. // Symbol interface function types.
  177. //
  178. typedef
  179. INT
  180. (*PSYMBOLS_LOAD) (
  181. PSTR Filename,
  182. IMAGE_MACHINE_TYPE MachineType,
  183. ULONG Flags,
  184. PVOID HostContext,
  185. PDEBUG_SYMBOLS *Symbols
  186. );
  187. /*++
  188. Routine Description:
  189. This routine loads debugging symbol information from the specified file.
  190. Arguments:
  191. Filename - Supplies the name of the binary to load symbols from.
  192. MachineType - Supplies the required machine type of the image. Set to
  193. unknown to allow the symbol library to load a file with any machine
  194. type.
  195. Flags - Supplies a bitfield of flags governing the behavior during load.
  196. These flags are specific to each symbol library.
  197. HostContext - Supplies the value to store in the host context field of the
  198. debug symbols.
  199. Symbols - Supplies an optional pointer where a pointer to the symbols will
  200. be returned on success.
  201. Return Value:
  202. 0 on success.
  203. Returns an error number on failure.
  204. --*/
  205. typedef
  206. VOID
  207. (*PSYMBOLS_UNLOAD) (
  208. PDEBUG_SYMBOLS Symbols
  209. );
  210. /*++
  211. Routine Description:
  212. This routine frees all memory associated with an instance of debugging
  213. symbols, including the symbols structure itsefl.
  214. Arguments:
  215. Symbols - Supplies a pointer to the debugging symbols.
  216. Return Value:
  217. None.
  218. --*/
  219. typedef
  220. INT
  221. (*PSYMBOLS_STACK_UNWIND) (
  222. PDEBUG_SYMBOLS Symbols,
  223. ULONGLONG DebasedPc,
  224. PSTACK_FRAME Frame
  225. );
  226. /*++
  227. Routine Description:
  228. This routine attempts to unwind the stack by one frame.
  229. Arguments:
  230. Symbols - Supplies a pointer to the debug symbols.
  231. DebasedPc - Supplies the program counter value, assuming the image were
  232. loaded at its preferred base address (that is, actual PC minus loaded
  233. base difference of the module).
  234. Frame - Supplies a pointer where the basic frame information for this
  235. frame will be returned.
  236. Return Value:
  237. 0 on success.
  238. EOF if there are no more stack frames.
  239. Returns an error code on failure.
  240. --*/
  241. typedef
  242. INT
  243. (*PSYMBOLS_READ_DATA_SYMBOL) (
  244. PDEBUG_SYMBOLS Symbols,
  245. PDATA_SYMBOL Symbol,
  246. ULONGLONG DebasedPc,
  247. PVOID Data,
  248. ULONG DataSize,
  249. PSTR Location,
  250. ULONG LocationSize
  251. );
  252. /*++
  253. Routine Description:
  254. This routine reads the contents of a data symbol.
  255. Arguments:
  256. Symbols - Supplies a pointer to the debug symbols.
  257. Symbol - Supplies a pointer to the data symbol to read.
  258. DebasedPc - Supplies the program counter value, assuming the image were
  259. loaded at its preferred base address (that is, actual PC minus the
  260. loaded base difference of the module).
  261. Data - Supplies a pointer to the buffer where the symbol data will be
  262. returned on success.
  263. DataSize - Supplies the size of the data buffer in bytes.
  264. Location - Supplies a pointer where the symbol location will be described
  265. in text on success.
  266. LocationSize - Supplies the size of the location buffer in bytes.
  267. Return Value:
  268. 0 on success.
  269. Returns an error code on failure.
  270. --*/
  271. typedef
  272. INT
  273. (*PSYMBOLS_GET_ADDRESS_OF_DATA_SYMBOL) (
  274. PDEBUG_SYMBOLS Symbols,
  275. PDATA_SYMBOL Symbol,
  276. ULONGLONG DebasedPc,
  277. PULONGLONG Address
  278. );
  279. /*++
  280. Routine Description:
  281. This routine gets the memory address of a data symbol.
  282. Arguments:
  283. Symbols - Supplies a pointer to the debug symbols.
  284. Symbol - Supplies a pointer to the data symbol to read.
  285. DebasedPc - Supplies the program counter value, assuming the image were
  286. loaded at its preferred base address (that is, actual PC minus the
  287. loaded base difference of the module).
  288. Address - Supplies a pointer where the address of the data symbol will be
  289. returned on success.
  290. Return Value:
  291. 0 on success.
  292. ENOENT if the data symbol is not currently valid.
  293. ERANGE if the data symbol is not stored in memory.
  294. Other error codes on other failures.
  295. --*/
  296. /*++
  297. Structure Description:
  298. This structure defines the interface to a symbol parsing library.
  299. Members:
  300. Load - Stores a pointer to a function that loads symbols.
  301. Unload - Stores a pointer to a function that unloads loaded symbols.
  302. Unwind - Stores an optional pointer to a function that can unwind the
  303. target stack. If not supplied, then traditional frame chaining will be
  304. used.
  305. ReadDataSymbol - Stores an optional pointer to a function that can read
  306. a data symbol value.
  307. GetAddressOfDataSymbol - Stores an optional pointer to a function that
  308. can return the memory address of a data symbol.
  309. --*/
  310. typedef struct _DEBUG_SYMBOL_INTERFACE {
  311. PSYMBOLS_LOAD Load;
  312. PSYMBOLS_UNLOAD Unload;
  313. PSYMBOLS_STACK_UNWIND Unwind;
  314. PSYMBOLS_READ_DATA_SYMBOL ReadDataSymbol;
  315. PSYMBOLS_GET_ADDRESS_OF_DATA_SYMBOL GetAddressOfDataSymbol;
  316. } DEBUG_SYMBOL_INTERFACE, *PDEBUG_SYMBOL_INTERFACE;
  317. /*++
  318. Structure Description:
  319. This structure holds internal information pertaining to a loaded module's
  320. symbols. It stores all symbol information for a given module.
  321. Members:
  322. Filename - Stores the file name of the current module. This will most likely
  323. point to the RawStabStrings buffer, and will not need to be freed
  324. explicitly.
  325. ImageBase - Stores the default base of the image.
  326. Machine - Stores the machine architecture of the file.
  327. ImageFormat - Stores the image format of the file.
  328. RawSymbolTable - Stores a pointer to a buffer containing the symbol table
  329. out of the PE or ELF file.
  330. RawSymbolTableSize - Stores the size of the RawSymbolTable buffer, in bytes.
  331. RawSymbolTableStrings - Stores a pointer to a buffer containing the string
  332. table associated with the symbol table in the PE or ELF file.
  333. RawSymbolTableStringsSize - Stores the size of the RawSymbolTableStrings,
  334. in bytes.
  335. SourcesHead - Stores the list head for a linked list of SOURCE_FILE_SYMBOL
  336. structures. This list contains the symbols for all the source files in
  337. the image.
  338. SymbolContext - Stores an opaque pointer that the symbol parsing library
  339. can use to store global state for this image.
  340. Interface - Stores a pointer to a table of functions used to interact with
  341. the symbol library.
  342. HostContext - Stores a pointer's worth of context for the user of the
  343. debug symbols library. This currently holds a pointer back to the
  344. debugger context.
  345. RegistersContext - Stores an optional pointer's worth of context regarding
  346. which set of registers to access when the symbol library needs to do
  347. accesses.
  348. --*/
  349. struct _DEBUG_SYMBOLS {
  350. PSTR Filename;
  351. ULONGLONG ImageBase;
  352. ULONG Machine;
  353. IMAGE_FORMAT ImageFormat;
  354. LIST_ENTRY SourcesHead;
  355. PVOID SymbolContext;
  356. PDEBUG_SYMBOL_INTERFACE Interface;
  357. PVOID HostContext;
  358. PVOID RegistersContext;
  359. };
  360. /*++
  361. Structure Description:
  362. This structure holds a subrange. This is used in type definitions where a
  363. type will be defined as a subrange of another type. It's also used in array
  364. definitions, specifying the minimum and maximum index in the array.
  365. Members:
  366. Minimum - Stores the minimum value of the range, inclusive.
  367. Maximum - Stores the maximum value of the range.
  368. MaxUlonglong - Stores a boolean indicating if the actual maximum of the
  369. range is maximum value of a 64-bit unsigned integer. If this flag is
  370. set, the Maximum field is undefined.
  371. --*/
  372. typedef struct _DATA_RANGE {
  373. LONGLONG Minimum;
  374. LONGLONG Maximum;
  375. BOOL MaxUlonglong;
  376. } DATA_RANGE, *PDATA_RANGE;
  377. /*++
  378. Structure Description:
  379. This structure stores all of the debug symbols for one source file.
  380. Members:
  381. SourceDirectory - Stores a string of the sources complete directory path.
  382. This will not need to be freed explicitly if it points directly to a
  383. stab string.
  384. SourceFile - Stores a string of the source file name. This will also not
  385. need to be freed explicitly.
  386. ListEntry - Stores links to the next and previous source files in the image.
  387. TypesHead - Stores the list head for all the types defined by this file. The
  388. values for these list entries will be TYPE_SYMBOL structures.
  389. SourceLinesHead - Stores the list head for all the source line symbols
  390. defined in this file. These entries will be of type SOURCE_LINE_SYMBOL.
  391. FunctionsHead - Stores the list head for all the functions defined in this
  392. file. These entries will be of type FUNCTION_SYMBOL.
  393. DataSymbolsHead - Stores the list head for all the data symbols defined in
  394. this source file. These entries will be of type DATA_SYMBOL.
  395. StartAddress - Stores the virtual address of the start of the text section
  396. for this source file. This makes it easy narrow down which file a
  397. symbol is in.
  398. EndAddress - Stores the virtual address of the end of the text section for
  399. this source file.
  400. Identifier - Stores an identifier for the source file, used to match up
  401. future references to the file. For Stabs, this is the value of the
  402. stab, and is used to match N_EXCL references to N_BINCLs.
  403. SymbolContext - Stores a pointer's worth of context reserved for the symbol
  404. parsing library.
  405. --*/
  406. typedef struct _SOURCE_FILE_SYMBOL {
  407. PSTR SourceDirectory;
  408. PSTR SourceFile;
  409. LIST_ENTRY ListEntry;
  410. LIST_ENTRY TypesHead;
  411. LIST_ENTRY SourceLinesHead;
  412. LIST_ENTRY FunctionsHead;
  413. LIST_ENTRY DataSymbolsHead;
  414. ULONGLONG StartAddress;
  415. ULONGLONG EndAddress;
  416. ULONG Identifier;
  417. PVOID SymbolContext;
  418. } SOURCE_FILE_SYMBOL, *PSOURCE_FILE_SYMBOL;
  419. /*++
  420. Structure Description:
  421. This structure stores symbols information pertaining to a function.
  422. Members:
  423. ParentSource - Stores a pointer to the source file this function is defined
  424. in.
  425. Name - Stores a pointer to the name of the function. This buffer will need
  426. to be freed explicitly on destruction.
  427. FunctionNumber - Stores the function number, as referred to by the stab
  428. Description field. This information is stored but currently unused.
  429. ListEntry - Stores links to the next and previous functions in the owning
  430. source file.
  431. ParametersHead - Stores the head of the list of the function's parameters,
  432. in order. The list values will be of type DATA_SYMBOL.
  433. LocalsHead - Stores the head of the list of the function's local variables.
  434. The list will be of type DATA_SYMBOL.
  435. StartAddress - Stores the starting virtual address of the function.
  436. EndAddress - Stores the ending virtual address of the function.
  437. ReturnTypeNumber - Stores the type number of the function's return type.
  438. ReturnTypeOwner - Stores a pointer to the source file where the function's
  439. return type resides.
  440. SymbolContext - Store's a pointer's worth of additional context for the
  441. symbol library.
  442. --*/
  443. typedef struct _FUNCTION_SYMBOL {
  444. PSOURCE_FILE_SYMBOL ParentSource;
  445. PSTR Name;
  446. USHORT FunctionNumber;
  447. LIST_ENTRY ListEntry;
  448. LIST_ENTRY ParametersHead;
  449. LIST_ENTRY LocalsHead;
  450. ULONGLONG StartAddress;
  451. ULONGLONG EndAddress;
  452. LONG ReturnTypeNumber;
  453. PSOURCE_FILE_SYMBOL ReturnTypeOwner;
  454. PVOID SymbolContext;
  455. } FUNCTION_SYMBOL, *PFUNCTION_SYMBOL;
  456. /*++
  457. Structure Description:
  458. This structure stores a single source line symbol.
  459. Members:
  460. ParentSource - Stores a pointer to the source file that this line refers to.
  461. This could point to an include file.
  462. ListEntry - Stores links to the previous and next source lines in this
  463. source file.
  464. LineNumber - Stores the line number of this source line symbol.
  465. Start - Stores the starting address of this line, inclusive.
  466. End - Stores the ending address of this line, exclusive.
  467. --*/
  468. typedef struct _SOURCE_LINE_SYMBOL {
  469. PSOURCE_FILE_SYMBOL ParentSource;
  470. LIST_ENTRY ListEntry;
  471. LONG LineNumber;
  472. ULONGLONG Start;
  473. ULONGLONG End;
  474. } SOURCE_LINE_SYMBOL, *PSOURCE_LINE_SYMBOL;
  475. /*++
  476. Structure Description:
  477. This structure defines a relation type between the type being defined and
  478. another type.
  479. Members:
  480. Pointer - Stores a combination of a flag and a value. If zero, it indicates
  481. this relation is not a pointer. If non-zero it indicates both that this
  482. relation is a pointer type, and the size of a pointer on the machine.
  483. OwningFile - Stores a pointer to the source file that contains the
  484. reference type.
  485. TypeNumber - Stores the number of the reference type.
  486. Array - Stores the allowable array indices of this type. If any of the
  487. values inside this parameter are nonzero, this indicates that this type
  488. is an array of the reference type.
  489. Function - Stores a flag which is set when this type is a function. The type
  490. information then refers to the return type of the function.
  491. --*/
  492. typedef struct _DATA_TYPE_RELATION {
  493. UCHAR Pointer;
  494. PSOURCE_FILE_SYMBOL OwningFile;
  495. LONG TypeNumber;
  496. DATA_RANGE Array;
  497. BOOL Function;
  498. } DATA_TYPE_RELATION, *PDATA_TYPE_RELATION;
  499. /*++
  500. Structure Description:
  501. This structure defines a numeric type.
  502. Members:
  503. Signed - Stores a flag indicating whether this type is signed or unsigned.
  504. Float - Stores a flag indicating whether this type should be interpreted as
  505. a floating point number. If this flag is TRUE, the Signed member is
  506. meaningless.
  507. BitSize - Stores the size of the numeric type, in bits.
  508. --*/
  509. typedef struct _DATA_TYPE_NUMERIC {
  510. BOOL Signed;
  511. BOOL Float;
  512. ULONG BitSize;
  513. } DATA_TYPE_NUMERIC, *PDATA_TYPE_NUMERIC;
  514. /*++
  515. Structure Description:
  516. This structure defines a structure type (ie. the source file defined a
  517. structure of some sort).
  518. Members:
  519. SizeInBytes - Stores the total size of the structure, in bytes.
  520. MemberCount - Stores the number of members in this structure.
  521. FirstMember - Stores a pointer to the first structure member.
  522. --*/
  523. typedef struct _DATA_TYPE_STRUCTURE {
  524. ULONG SizeInBytes;
  525. ULONG MemberCount;
  526. PSTRUCTURE_MEMBER FirstMember;
  527. } DATA_TYPE_STRUCTURE, *PDATA_TYPE_STRUCTURE;
  528. /*++
  529. Structure Description:
  530. This structure defines an enumeration type.
  531. Members:
  532. SizeInBytes - Stores the number of bytes required to hold an instantiation
  533. of this enumeration. This might be zero if the symbol format does not
  534. describe this information.
  535. MemberCount - Stores the number of values defined in this enum.
  536. FirstMember - Stores a pointer to the first enumeration definition.
  537. --*/
  538. typedef struct _DATA_TYPE_ENUMERATION {
  539. ULONG SizeInBytes;
  540. ULONG MemberCount;
  541. PENUMERATION_MEMBER FirstMember;
  542. } DATA_TYPE_ENUMERATION, *PDATA_TYPE_ENUMERATION;
  543. /*++
  544. Structure Description:
  545. This structure defines a function pointer type.
  546. Members:
  547. SizeInBytes - Stores the size of the type (the size of an address in the
  548. target).
  549. --*/
  550. typedef struct _DATA_TYPE_FUNCTION_POINTER {
  551. ULONG SizeInBytes;
  552. } DATA_TYPE_FUNCTION_POINTER, *PDATA_TYPE_FUNCTION_POINTER;
  553. /*++
  554. Structure Description:
  555. This structure defines a new type (such as a bool, int, structure, or enum).
  556. Members:
  557. ListEntry - Stores links to the next and previous types in the owning source
  558. file.
  559. ParentSource - Stores a link to the source file this type was defined in.
  560. This is necessary because types are defined with a type index and
  561. potentially an include file index. This could be an include file.
  562. TypeNumber - Stores the type number, which can be referred to by other
  563. types.
  564. Name - Stores the name of the type. This buffer will need to be freed
  565. explicitly upon destruction.
  566. ParentFunction - Stores a link to the function where this type was defined.
  567. Type - Stores the type of this type, such as whether it is a basic type,
  568. structure, enum, etc.
  569. U - Stores the union of type information. Which structure to reach through
  570. can be determined by the type member above.
  571. --*/
  572. struct _TYPE_SYMBOL {
  573. LIST_ENTRY ListEntry;
  574. PSOURCE_FILE_SYMBOL ParentSource;
  575. LONG TypeNumber;
  576. PSTR Name;
  577. PFUNCTION_SYMBOL ParentFunction;
  578. DATA_TYPE_TYPE Type;
  579. union {
  580. DATA_TYPE_RELATION Relation;
  581. DATA_TYPE_NUMERIC Numeric;
  582. DATA_TYPE_STRUCTURE Structure;
  583. DATA_TYPE_ENUMERATION Enumeration;
  584. DATA_TYPE_FUNCTION_POINTER FunctionPointer;
  585. } U;
  586. };
  587. /*++
  588. Structure Description:
  589. This structure defines a data address that is a register plus an offset.
  590. Members:
  591. Register - Stores the register number.
  592. Offset - Stores the offset in bytes to add to the value at the register.
  593. --*/
  594. typedef struct _DATA_LOCATION_REGISTER_OFFSET {
  595. ULONG Register;
  596. LONGLONG Offset;
  597. } DATA_LOCATION_REGISTER_OFFSET, *PDATA_LOCATION_REGISTER_OFFSET;
  598. /*++
  599. Structure Description:
  600. This union defines the various forms a data symbol location can take.
  601. Members:
  602. Address - Stores the memory address of the symbol.
  603. Register - Stores the register number of the symbol.
  604. Indirect - Stores the register plus offset address of the symbol.
  605. Complex - Stores a context pointer that the symbol library can interpret
  606. to evaluate a more complicated location.
  607. --*/
  608. typedef union _DATA_LOCATION_UNION {
  609. ULONGLONG Address;
  610. ULONG Register;
  611. DATA_LOCATION_REGISTER_OFFSET Indirect;
  612. PVOID Complex;
  613. } DATA_LOCATION_UNION, *PDATA_LOCATION_UNION;
  614. /*++
  615. Structure Description:
  616. This structure defines a general data symbol for a global or local variable
  617. located in a register, stack, or at an absolute address.
  618. Members:
  619. ParentSource - Stores a link to the source file where this symbol was
  620. defined.
  621. ParentFunction - Stores a link to the function where this (potentially
  622. local) variable was defined. Can be NULL.
  623. ListEntry - Stores a link to the next and previous variable in the function
  624. or source file.
  625. Name - Stores a pointer to the name of this variable. This buffer will need
  626. to be explicitly freed upon destruction.
  627. LocationType - Stores a value that indicates the form the location union
  628. should be accessed through.
  629. Location - Stores the location of the symbol.
  630. MinimumValidExecutionAddress - Stores the point in the execution flow when
  631. this variable becomes active. For globals, this will probably be 0. For
  632. stack variables and register variables, this will be somewhere around
  633. where the variable gets initialized.
  634. TypeOwner - Stores a link to the source file where the type of the variable
  635. can be found.
  636. TypeNumber - Stores the type number of this variable.
  637. --*/
  638. struct _DATA_SYMBOL {
  639. PSOURCE_FILE_SYMBOL ParentSource;
  640. PFUNCTION_SYMBOL ParentFunction;
  641. LIST_ENTRY ListEntry;
  642. PSTR Name;
  643. DATA_SYMBOL_LOCATION_TYPE LocationType;
  644. DATA_LOCATION_UNION Location;
  645. ULONGLONG MinimumValidExecutionAddress;
  646. PSOURCE_FILE_SYMBOL TypeOwner;
  647. LONG TypeNumber;
  648. };
  649. /*++
  650. Structure Description:
  651. This structure defines a member in a structure type definition.
  652. Members:
  653. Name - Stores a pointer to the name of this member. This buffer *will* need
  654. to be freed explicitly on destruction.
  655. TypeFile - Stores a pointer to the file where the type of this member is
  656. defined.
  657. TypeNumber - Stores the type number for this structure member.
  658. BitOffset - Stores the offset from the beginning of the structure where this
  659. member begins, in bits. For unions, many members will have the same
  660. value here.
  661. BitSize - Stores the size of this member in bits.
  662. NextMember - Stores a pointer to the next structure member, or NULL if this
  663. is the last structure member.
  664. --*/
  665. struct _STRUCTURE_MEMBER {
  666. PSTR Name;
  667. PSOURCE_FILE_SYMBOL TypeFile;
  668. LONG TypeNumber;
  669. ULONG BitOffset;
  670. ULONG BitSize;
  671. PSTRUCTURE_MEMBER NextMember;
  672. };
  673. /*++
  674. Structure Description:
  675. This structure defines a member in an enumeration type definition.
  676. Members:
  677. Name - Stores a pointer to the name of this enumeration. This buffer *will*
  678. need to be explicitly freed on destruction.
  679. Value - Stores the value that Name enumerates to. On a normal enumeration,
  680. this value will start at 0 and work its way up in subsequent members.
  681. NextMember - Stores a pointer to the next enumeration member, or NULL if
  682. this is the last enumeration.
  683. --*/
  684. struct _ENUMERATION_MEMBER {
  685. PSTR Name;
  686. LONGLONG Value;
  687. PENUMERATION_MEMBER NextMember;
  688. };
  689. /*++
  690. Structure Description:
  691. This structure defines an individual result of searching for a symbol.
  692. Members:
  693. Variety - Stores which member of the union of the union is valid,
  694. depending on the type of symbol returned from the query.
  695. FunctionResult - Stores a pointer to the function symbol,
  696. provided that the variety specifies a function.
  697. TypeResult - Stores a pointer to the data type symbol, provided that
  698. the variety specifies a type.
  699. DataResult - Stores a pointer to the data symbol, provided that the variety
  700. specifies a data result.
  701. --*/
  702. typedef struct _SYMBOL_SEARCH_RESULT {
  703. SYMBOL_RESULT_TYPE Variety;
  704. union {
  705. PFUNCTION_SYMBOL FunctionResult;
  706. PTYPE_SYMBOL TypeResult;
  707. PDATA_SYMBOL DataResult;
  708. } U;
  709. } SYMBOL_SEARCH_RESULT, *PSYMBOL_SEARCH_RESULT;
  710. /*++
  711. Structure Description:
  712. This structure stores a loaded module in the debugger.
  713. Members:
  714. ListEntry - Stores pointers to the next and previous loaded modules in the
  715. list of all loaded modules.
  716. Filename - Stores the name of the file these symbols were loaded from.
  717. ModuleName - Stores the friendly name of the module.
  718. Timestamp - Stores the modification date of this module in seconds since
  719. 2001.
  720. BaseAddress - Stores the base address the file was loaded at. For ELF
  721. images, this is always the same as the base difference.
  722. BaseDifference - Supplies the difference between the preferred load
  723. address of the module and the actual load address of the module.
  724. LowestAddress - Stores the lowest address of the image actually in use,
  725. since this can be lower than the base address.
  726. Size - Stores the lize of the loaded image in memory.
  727. Process - Stores the ID of the process the image is specific to.
  728. Symbols - Stores a pointer to the debug symbols associated with this
  729. module.
  730. Loaded - Stores a boolean indicating if this module is still loaded.
  731. --*/
  732. typedef struct _DEBUGGER_MODULE {
  733. LIST_ENTRY ListEntry;
  734. PSTR Filename;
  735. PSTR ModuleName;
  736. ULONGLONG Timestamp;
  737. ULONGLONG BaseAddress;
  738. ULONGLONG BaseDifference;
  739. ULONGLONG LowestAddress;
  740. ULONGLONG Size;
  741. ULONG Process;
  742. PDEBUG_SYMBOLS Symbols;
  743. BOOL Loaded;
  744. } DEBUGGER_MODULE, *PDEBUGGER_MODULE;
  745. /*++
  746. Structure Description:
  747. This structure stores a list of loaded modules.
  748. Members:
  749. ModuleCount - Stores the number of modules in the list.
  750. Signature - Stores the total of all timestamps and loaded addresses in the
  751. module list.
  752. ModulesHead - Stores the head of the list of DEBUGGER_MODULE structures.
  753. --*/
  754. typedef struct _DEBUGGER_MODULE_LIST {
  755. ULONG ModuleCount;
  756. ULONGLONG Signature;
  757. LIST_ENTRY ModulesHead;
  758. } DEBUGGER_MODULE_LIST, *PDEBUGGER_MODULE_LIST;
  759. //
  760. // -------------------------------------------------------------------- Globals
  761. //
  762. //
  763. // -------------------------------------------------------- Function Prototypes
  764. //
  765. INT
  766. DbgLoadSymbols (
  767. PSTR Filename,
  768. IMAGE_MACHINE_TYPE MachineType,
  769. PVOID HostContext,
  770. PDEBUG_SYMBOLS *Symbols
  771. );
  772. /*++
  773. Routine Description:
  774. This routine loads debugging symbol information from the specified file.
  775. Arguments:
  776. Filename - Supplies the name of the binary to load symbols from.
  777. MachineType - Supplies the required machine type of the image. Set to
  778. unknown to allow the symbol library to load a file with any machine
  779. type.
  780. HostContext - Supplies the value to store in the host context field of the
  781. debug symbols.
  782. Symbols - Supplies an optional pointer where a pointer to the symbols will
  783. be returned on success.
  784. Return Value:
  785. 0 on success.
  786. Returns an error number on failure.
  787. --*/
  788. VOID
  789. DbgUnloadSymbols (
  790. PDEBUG_SYMBOLS Symbols
  791. );
  792. /*++
  793. Routine Description:
  794. This routine frees all memory associated with an instance of debugging
  795. symbols. Once called, the pointer passed in should not be dereferenced
  796. again by the caller.
  797. Arguments:
  798. Symbols - Supplies a pointer to the debugging symbols.
  799. Return Value:
  800. None.
  801. --*/
  802. VOID
  803. DbgPrintFunctionPrototype (
  804. PFUNCTION_SYMBOL Function,
  805. PSTR ModuleName,
  806. ULONGLONG Address
  807. );
  808. /*++
  809. Routine Description:
  810. This routine prints a C function prototype directly to the screen.
  811. Arguments:
  812. Function - Supplies a pointer to the function symbol to print.
  813. ModuleName - Supplies an optional string containing the module name.
  814. Address - Supplies the final address of the function.
  815. Return Value:
  816. None (information is printed directly to the standard output).
  817. --*/
  818. VOID
  819. DbgPrintTypeName (
  820. PTYPE_SYMBOL Type
  821. );
  822. /*++
  823. Routine Description:
  824. This routine prints a type name, formatted with any array an pointer
  825. decorations.
  826. Arguments:
  827. Type - Supplies a pointer to the type to print information about.
  828. Return Value:
  829. None (information is printed directly to the standard output).
  830. --*/
  831. ULONG
  832. DbgGetTypeSize (
  833. PTYPE_SYMBOL Type,
  834. ULONG RecursionDepth
  835. );
  836. /*++
  837. Routine Description:
  838. This routine determines the size in bytes of a given type.
  839. Arguments:
  840. Type - Supplies a pointer to the type to get the size of.
  841. RecursionDepth - Supplies the function recursion depth. Supply zero here.
  842. Return Value:
  843. Returns the size of the type in bytes. On error or on querying a void type,
  844. 0 is returned.
  845. --*/
  846. VOID
  847. DbgPrintTypeDescription (
  848. PTYPE_SYMBOL Type,
  849. ULONG SpaceLevel,
  850. ULONG RecursionDepth
  851. );
  852. /*++
  853. Routine Description:
  854. This routine prints a description of the structure of a given type.
  855. Arguments:
  856. Type - Supplies a pointer to the type to print information about.
  857. SpaceLevel - Supplies the number of spaces to print after every newline.
  858. Used for nesting types.
  859. RecursionDepth - Supplies how many times this should recurse on structure
  860. members. If 0, only the name of the type is printed.
  861. Return Value:
  862. None (information is printed directly to the standard output).
  863. --*/
  864. PTYPE_SYMBOL
  865. DbgSkipTypedefs (
  866. PTYPE_SYMBOL Type
  867. );
  868. /*++
  869. Routine Description:
  870. This routine skips all relation types that aren't pointers or arrays.
  871. Arguments:
  872. Type - Supplies a pointer to the type to get to the bottom of.
  873. Return Value:
  874. NULL if the type ended up being void or not found.
  875. Returns a pointer to the root type on success.
  876. --*/
  877. PTYPE_SYMBOL
  878. DbgGetType (
  879. PSOURCE_FILE_SYMBOL SourceFile,
  880. LONG TypeNumber
  881. );
  882. /*++
  883. Routine Description:
  884. This routine looks up a type symbol based on the type number and the source
  885. file the type is in.
  886. Arguments:
  887. SourceFile - Supplies a pointer to the source file containing the type.
  888. TypeNumber - Supplies the type number to look up.
  889. Return Value:
  890. Returns a pointer to the type on success, or NULL on error.
  891. --*/
  892. PSOURCE_LINE_SYMBOL
  893. DbgLookupSourceLine (
  894. PDEBUG_SYMBOLS Module,
  895. ULONGLONG Address
  896. );
  897. /*++
  898. Routine Description:
  899. This routine looks up a source line in a given module based on the address.
  900. Arguments:
  901. Module - Supplies a pointer to the module which contains the symbols to
  902. search through.
  903. Address - Supplies the query address to search the source line symbols for.
  904. Return Value:
  905. If a successful match is found, returns a pointer to the source line symbol.
  906. If a source line matching the address could not be found or an error
  907. occured, returns NULL.
  908. --*/
  909. PSYMBOL_SEARCH_RESULT
  910. DbgLookupSymbol (
  911. PDEBUG_SYMBOLS Module,
  912. ULONGLONG Address,
  913. PSYMBOL_SEARCH_RESULT Input
  914. );
  915. /*++
  916. Routine Description:
  917. This routine looks up a symbol in a module based on the given address. It
  918. first searches through data symbols, then functions.
  919. Arguments:
  920. Module - Supplies a pointer to the module which contains the symbols to
  921. search through.
  922. Address - Supplies the address of the symbol to look up.
  923. Input - Supplies a pointer to the search result structure. On input, the
  924. parameter contains the search result to start the search from. On
  925. output, contains the new found search result. To signify that the search
  926. should start from the beginning, set the Type member to ResultInvalid.
  927. Return Value:
  928. If a successful match is found, returns Input with the search results filled
  929. into the structure. If no result was found or an error occurred, NULL is
  930. returned.
  931. --*/
  932. PSYMBOL_SEARCH_RESULT
  933. DbgpFindSymbolInModule (
  934. PDEBUG_SYMBOLS Module,
  935. PSTR Query,
  936. PSYMBOL_SEARCH_RESULT Input
  937. );
  938. /*++
  939. Routine Description:
  940. This routine searches for a symbol in a module. It first searches through
  941. types, then data symbols, then functions.
  942. Arguments:
  943. Module - Supplies a pointer to the module which contains the symbols to
  944. search through.
  945. Query - Supplies the search string.
  946. Input - Supplies a pointer to the search result structure. On input, the
  947. parameter contains the search result to start the search from. On
  948. output, contains the new found search result. To signify that the search
  949. should start from the beginning, set the Type member to ResultInvalid.
  950. Return Value:
  951. If a successful match is found, returns Input with the search results filled
  952. into the structure. If no result was found or an error occurred, NULL is
  953. returned.
  954. --*/
  955. PSYMBOL_SEARCH_RESULT
  956. DbgFindTypeSymbol (
  957. PDEBUG_SYMBOLS Module,
  958. PSTR Query,
  959. PSYMBOL_SEARCH_RESULT Input
  960. );
  961. /*++
  962. Routine Description:
  963. This routine searches for a type symbol in a module.
  964. Arguments:
  965. Module - Supplies a pointer to the module which contains the symbols to
  966. search through.
  967. Query - Supplies the search string.
  968. Input - Supplies a pointer to the search result structure. On input, the
  969. parameter contains the search result to start the search from. On
  970. output, contains the new found search result. To signify that the search
  971. should start from the beginning, set the Type member to ResultInvalid.
  972. Return Value:
  973. If a successful match is found, returns Input with the search results filled
  974. into the structure. If no result was found or an error occurred, NULL is
  975. returned.
  976. --*/
  977. PSYMBOL_SEARCH_RESULT
  978. DbgFindDataSymbol (
  979. PDEBUG_SYMBOLS Module,
  980. PSTR Query,
  981. ULONGLONG Address,
  982. PSYMBOL_SEARCH_RESULT Input
  983. );
  984. /*++
  985. Routine Description:
  986. This routine searches for a data symbol in a module based on a query string
  987. or address.
  988. Arguments:
  989. Module - Supplies a pointer to the module which contains the symbols to
  990. search through.
  991. Query - Supplies the search string. This parameter can be NULL if searching
  992. by address.
  993. Address - Supplies the address of the symbol. Can be NULL if search by
  994. query string is desired.
  995. Input - Supplies a pointer to the search result structure. On input, the
  996. parameter contains the search result to start the search from. On
  997. output, contains the new found search result. To signify that the search
  998. should start from the beginning, set the Type member to ResultInvalid.
  999. Return Value:
  1000. If a successful match is found, returns Input with the search results filled
  1001. into the structure. If no result was found or an error occurred, NULL is
  1002. returned.
  1003. --*/
  1004. PSYMBOL_SEARCH_RESULT
  1005. DbgFindFunctionSymbol (
  1006. PDEBUG_SYMBOLS Module,
  1007. PSTR Query,
  1008. ULONGLONG Address,
  1009. PSYMBOL_SEARCH_RESULT Input
  1010. );
  1011. /*++
  1012. Routine Description:
  1013. This routine searches for a function symbol in a module based on a search
  1014. string or an address.
  1015. Arguments:
  1016. Module - Supplies a pointer to the module which contains the symbols to
  1017. search through.
  1018. Query - Supplies the search string. This parameter can be NULL if searching
  1019. by address.
  1020. Address - Supplies the search address. This parameter can be NULL if
  1021. searching by query string.
  1022. Input - Supplies a pointer to the search result structure. On input, the
  1023. parameter contains the search result to start the search from. On
  1024. output, contains the new found search result. To signify that the search
  1025. should start from the beginning, set the Type member to ResultInvalid.
  1026. Return Value:
  1027. If a successful match is found, returns Input with the search results filled
  1028. into the structure. If no result was found or an error occurred, NULL is
  1029. returned.
  1030. --*/
  1031. PSTR
  1032. DbgGetRegisterName (
  1033. IMAGE_MACHINE_TYPE MachineType,
  1034. ULONG Register
  1035. );
  1036. /*++
  1037. Routine Description:
  1038. This routine returns a string containing the name of the given register.
  1039. Arguments:
  1040. MachineType - Supplies the machine type.
  1041. Register - Supplies the register number.
  1042. Return Value:
  1043. Returns a pointer to a constant string containing the name of the register.
  1044. --*/