stabs.h 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443
  1. /*++
  2. Copyright (c) 2012 Minoca Corp.
  3. This file is licensed under the terms of the GNU General Public License
  4. version 3. Alternative licensing terms are available. Contact
  5. info@minocacorp.com for details. See the LICENSE file at the root of this
  6. project for complete licensing information.
  7. Module Name:
  8. stabs.h
  9. Abstract:
  10. This header contains definitions for the STABS debugging symbol information
  11. format.
  12. Author:
  13. Evan Green 26-Jun-2012
  14. --*/
  15. //
  16. // ---------------------------------------------------------------- Definitions
  17. //
  18. #define STAB_GLOBAL_SYMBOL 0x20 // N_GSYM
  19. #define STAB_FUNCTION_NAME 0x22 // N_FNAME (Pascal)
  20. #define STAB_FUNCTION 0x24 // N_FUN
  21. #define STAB_STATIC 0x26 // N_STSYM
  22. #define STAB_BSS_SYMBOL 0x28 // N_LCSYM
  23. #define STAB_MAIN 0x2A // N_MAIN
  24. #define STAB_READONLY_SYMBOL 0x2C // N_ROSYM
  25. #define STAB_PC 0x30 // N_PC (Pascal)
  26. #define STAB_SYMBOL_COUNT 0x32 // N_NSYMS (Ultrix)
  27. #define STAB_NO_MAP 0x34 // N_NOMAP
  28. #define STAB_MACRO_DEFINITION 0x36 // N_MAC_DEFINE
  29. #define STAB_OBJ_FILE 0x38 // N_OBJ (Solaris2)
  30. #define STAB_MACRO_UNDEFINE 0x3A // N_MAC_UNDEF
  31. #define STAB_DEBUGGER_OPTIONS 0x3C // N_OPT (Solaris2)
  32. #define STAB_REGISTER_VARIABLE 0x40 // N_RSYM
  33. #define STAB_MODULA2 0x42 // N_M2C
  34. #define STAB_SOURCE_LINE 0x44 // N_SLINE
  35. #define STAB_DATA_SOURCE_LINE 0x46 // N_DSLINE
  36. #define STAB_BSS_SOURCE_LINE 0x48 // N_BSLINE
  37. #define STAB_SUN_CB_PATH 0x48 // N_BROWS (Sun browser)
  38. #define STAB_DEFINITION_DEPENDENCY 0x4A // N_DEFD (Modula2)
  39. #define STAB_FUNCTION_LINES 0x4C // N_FLINE (Solaris2)
  40. #define STAB_EXCEPTION_VARIABLE 0x50 // N_EHDECL (C++)
  41. #define STAB_FOR_IMC 0x50 // N_MOD2 (Ultrix)
  42. #define STAB_CATCH 0x54 // N_CATCH (C++)
  43. #define STAB_UNION_ELEMENT 0x60 // N_SSYM
  44. #define STAB_END_MODULE 0x62 // N_ENDM (Solaris2)
  45. #define STAB_SOURCE_FILE 0x64 // N_SO
  46. #define STAB_LOCAL_SYMBOL 0x80 // N_LSYM
  47. #define STAB_INCLUDE_BEGIN 0x82 // N_BINCL
  48. #define STAB_INCLUDE_NAME 0x84 // N_SOL
  49. #define STAB_FUNCTION_PARAMETER 0xA0 // N_PSYM
  50. #define STAB_INCLUDE_END 0xA2 // N_EINCL
  51. #define STAB_ALTERNATE_ENTRY 0xA4 // N_ENTRY
  52. #define STAB_LEFT_BRACE 0xC0 // N_LBRAC
  53. #define STAB_INCLUDE_PLACEHOLDER 0xC2 // N_EXCL
  54. #define STAB_SCOPE 0xC4 // N_SCOPE (Modula2)
  55. #define STAB_RIGHT_BRACE 0xE0 // N_RBRAC
  56. #define STAB_COMMON_BLOCK_BEGIN 0xE2 // N_BCOMM
  57. #define STAB_COMMON_BLOCK_END 0xE4 // N_ECOMM
  58. #define STAB_COMMON_BLOCK_MEMBER 0xE8 // N_ECOML
  59. #define STAB_WITH 0xEA // N_WITH (Pascal)
  60. //
  61. // ------------------------------------------------------ Data Type Definitions
  62. //
  63. #define STAB_REGISTER_TO_GENERAL(_StabRegister) (_StabRegister)
  64. typedef struct _INCLUDE_STACK_ELEMENT INCLUDE_STACK_ELEMENT,
  65. *PINCLUDE_STACK_ELEMENT;
  66. /*++
  67. Structure Description:
  68. This structure stores information about include file numbers. Include files
  69. are indexed as they are added, and an individual source file can be located
  70. in multiple places on the stack.
  71. Members:
  72. IncludeFile - Stores a pointer to the source file being referenced.
  73. Index - Stores the position in the include stack.
  74. NextElement - Stores a pointer to the next element on the include stack. The
  75. final element will have a NextElement of NULL.
  76. --*/
  77. struct _INCLUDE_STACK_ELEMENT {
  78. PSOURCE_FILE_SYMBOL IncludeFile;
  79. ULONG Index;
  80. PINCLUDE_STACK_ELEMENT NextElement;
  81. };
  82. /*++
  83. Structure Description:
  84. This structure stores information about an unresolved cross reference. Stabs
  85. can reference structures, unions, an enums by name that may or may not be
  86. defined yet. When these stabs are encountered, a cross reference entry is
  87. created and put onto a list. At the end of parsing a stab file, this list
  88. of cross references is drained and resolved.
  89. Members:
  90. ListEntry - Stores pointers to the next and previous cross reference
  91. entries.
  92. ReferringTypeName - Stores a pointer to the name type that made the
  93. reference and currently has dangling reference information.
  94. ReferringTypeSource - Stores a pointer to the source file that owns the
  95. reference.
  96. ReferringTypeNumber - Stores the type number of the yet-to-be-defined time.
  97. ReferenceString - Stores a pointer to the string that defines the reference.
  98. --*/
  99. typedef struct _CROSS_REFERENCE_ENTRY {
  100. LIST_ENTRY ListEntry;
  101. PSTR ReferringTypeName;
  102. PSOURCE_FILE_SYMBOL ReferringTypeSource;
  103. LONG ReferringTypeNumber;
  104. PSTR ReferenceString;
  105. } CROSS_REFERENCE_ENTRY, *PCROSS_REFERENCE_ENTRY;
  106. /*++
  107. Structure Description:
  108. This structure stores the current STABs specific symbol information. It
  109. is primarily used during parsing.
  110. Members:
  111. RawSymbolTable - Stores a pointer to a buffer containing the symbol table
  112. out of the PE or ELF file.
  113. RawSymbolTableSize - Stores the size of the RawSymbolTable buffer, in bytes.
  114. RawSymbolTableStrings - Stores a pointer to a buffer containing the string
  115. table associated with the symbol table in the PE or ELF file.
  116. RawSymbolTableStringsSize - Stores the size of the RawSymbolTableStrings,
  117. in bytes.
  118. RawStabs - Stores a pointer to a buffer containing the .stab section of
  119. the loaded image.
  120. RawStabsSize - Stores the size of the RawStabs buffer.
  121. RawStabStrings - Stores a pointer to a buffer containing the .stabstr
  122. section of the loaded image.
  123. RawStabStringsSize - Stores the size of the RawStabStrings buffer.
  124. CurrentModule - Stores a pointer back to the current module being parsed.
  125. CurrentSourceDirectory - Stores a pointer to the string containing the last
  126. seen source directory.
  127. CurrentSourceFile - Stores a pointer to the source file currently being
  128. parsed.
  129. CurrentSourceLine - Stores a pointer to the source line currently being
  130. parsed.
  131. CurrentSourceLineFile - Stores a pointer to the source file that source
  132. lines belong to.
  133. CurrentFunction - Stores a pointer to the function currently being parsed.
  134. IncludeStack - Stores a pointer to the list of include files in the current
  135. source file and their positions in the include stack.
  136. CrossReferenceListHead - Stores the list head of every unresolved cross-
  137. reference stab that has been encountered in the current source file.
  138. MaxIncludeIndex - Stores the number of files that have been included by the
  139. current source file. Since types are defined by a type number and an
  140. include index, it's important to keep track of that maximum include
  141. index we expect to see.
  142. MaxBraceAddress - Stores the address of the most recent (innermost) brace.
  143. --*/
  144. typedef struct _STAB_CONTEXT {
  145. PVOID RawSymbolTable;
  146. ULONG RawSymbolTableSize;
  147. PVOID RawSymbolTableStrings;
  148. ULONG RawSymbolTableStringsSize;
  149. PVOID RawStabs;
  150. ULONG RawStabsSize;
  151. PVOID RawStabStrings;
  152. ULONG RawStabStringsSize;
  153. PDEBUG_SYMBOLS CurrentModule;
  154. PSTR CurrentSourceDirectory;
  155. PSOURCE_FILE_SYMBOL CurrentSourceFile;
  156. PSOURCE_LINE_SYMBOL CurrentSourceLine;
  157. PSOURCE_FILE_SYMBOL CurrentSourceLineFile;
  158. PFUNCTION_SYMBOL CurrentFunction;
  159. PINCLUDE_STACK_ELEMENT IncludeStack;
  160. LIST_ENTRY CrossReferenceListHead;
  161. ULONG MaxIncludeIndex;
  162. ULONGLONG MaxBraceAddress;
  163. } STAB_CONTEXT, *PSTAB_CONTEXT;
  164. /*++
  165. Structure Description:
  166. This structure defines the format for the raw stabs in the .stab section.
  167. These structures were generated by the compiler/linker. It's important that
  168. members of this structure not be padded.
  169. Members:
  170. StringIndex - Stores the index from the start of the .stabstr section
  171. where the string for this stab is located.
  172. Type - Stores the stab type, one of the STAB_* definitions
  173. (eg. STAB_LOCAL_SYMBOL).
  174. Other - Usually 0.
  175. Description - Stores a description of the stab. This field has various
  176. uses, for example in a STAB_SOURCE_LINE, the description field holds
  177. the line number.
  178. Value - Stores the value of the symbol. In many cases, this is a virtual
  179. address.
  180. --*/
  181. #pragma pack(push, 1)
  182. typedef struct _RAW_STAB {
  183. ULONG StringIndex;
  184. UCHAR Type;
  185. UCHAR Other;
  186. USHORT Description;
  187. ULONG Value;
  188. } PACKED RAW_STAB, *PRAW_STAB;
  189. #pragma pack(pop)
  190. //
  191. // ----------------------------------------------- Internal Function Prototypes
  192. //
  193. INT
  194. DbgpStabsLoadSymbols (
  195. PSTR Filename,
  196. IMAGE_MACHINE_TYPE MachineType,
  197. ULONG Flags,
  198. PVOID HostContext,
  199. PDEBUG_SYMBOLS *Symbols
  200. );
  201. /*++
  202. Routine Description:
  203. This routine loads debugging symbol information from the specified file.
  204. Arguments:
  205. Filename - Supplies the name of the binary to load symbols from.
  206. MachineType - Supplies the required machine type of the image. Set to
  207. unknown to allow the symbol library to load a file with any machine
  208. type.
  209. Flags - Supplies a bitfield of flags governing the behavior during load.
  210. These flags are specific to each symbol library.
  211. HostContext - Supplies the value to store in the host context field of the
  212. debug symbols.
  213. Symbols - Supplies an optional pointer where a pointer to the symbols will
  214. be returned on success.
  215. Return Value:
  216. 0 on success.
  217. Returns an error number on failure.
  218. --*/
  219. INT
  220. DbgpCoffLoadSymbols (
  221. PSTR Filename,
  222. IMAGE_MACHINE_TYPE MachineType,
  223. ULONG Flags,
  224. PVOID HostContext,
  225. PDEBUG_SYMBOLS *Symbols
  226. );
  227. /*++
  228. Routine Description:
  229. This routine loads debugging symbol information from the specified file.
  230. Arguments:
  231. Filename - Supplies the name of the binary to load symbols from.
  232. MachineType - Supplies the required machine type of the image. Set to
  233. unknown to allow the symbol library to load a file with any machine
  234. type.
  235. Flags - Supplies a bitfield of flags governing the behavior during load.
  236. These flags are specific to each symbol library.
  237. HostContext - Supplies the value to store in the host context field of the
  238. debug symbols.
  239. Symbols - Supplies an optional pointer where a pointer to the symbols will
  240. be returned on success.
  241. Return Value:
  242. 0 on success.
  243. Returns an error number on failure.
  244. --*/
  245. INT
  246. DbgpElfLoadSymbols (
  247. PSTR Filename,
  248. IMAGE_MACHINE_TYPE MachineType,
  249. ULONG Flags,
  250. PVOID HostContext,
  251. PDEBUG_SYMBOLS *Symbols
  252. );
  253. /*++
  254. Routine Description:
  255. This routine loads ELF debugging symbol information from the specified file.
  256. Arguments:
  257. Filename - Supplies the name of the binary to load symbols from.
  258. MachineType - Supplies the required machine type of the image. Set to
  259. unknown to allow the symbol library to load a file with any machine
  260. type.
  261. Flags - Supplies a bitfield of flags governing the behavior during load.
  262. These flags are specific to each symbol library.
  263. HostContext - Supplies the value to store in the host context field of the
  264. debug symbols.
  265. Symbols - Supplies an optional pointer where a pointer to the symbols will
  266. be returned on success.
  267. Return Value:
  268. 0 on success.
  269. Returns an error number on failure.
  270. --*/
  271. //
  272. // Lower level COFF/ELF functions called from within STABs parsing
  273. //
  274. BOOL
  275. DbgpLoadCoffSymbols (
  276. PDEBUG_SYMBOLS Symbols,
  277. PSTR Filename
  278. );
  279. /*++
  280. Routine Description:
  281. This routine loads COFF symbols into a pre-existing set of debug symbols.
  282. Arguments:
  283. Symbols - Supplies a pointer to debug symbols that are assumed to have
  284. already been allocated and initialized.
  285. Filename - Supplies the name of the file to load COFF symbols for.
  286. Return Value:
  287. TRUE on success.
  288. FALSE on failure.
  289. --*/
  290. BOOL
  291. DbgpLoadElfSymbols (
  292. PDEBUG_SYMBOLS Symbols,
  293. PSTR Filename
  294. );
  295. /*++
  296. Routine Description:
  297. This routine loads ELF symbols into a pre-existing set of ELF symbols.
  298. Arguments:
  299. Symbols - Supplies a pointer to debug symbols that are assumed to have
  300. already been allocated and initialized.
  301. Filename - Supplies the name of the file to load ELF symbols for.
  302. Return Value:
  303. TRUE on success.
  304. FALSE on failure.
  305. --*/