dbgdwarf.pas 75 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992
  1. {
  2. Copyright (c) 2003-2006 by Peter Vreman and Florian Klaempfl
  3. This units contains support for DWARF debug info generation
  4. This program is free software; you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation; either version 2 of the License, or
  7. (at your option) any later version.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with this program; if not, write to the Free Software
  14. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  15. ****************************************************************************
  16. }
  17. {
  18. This units contains support for DWARF debug info generation.
  19. Currently a lot of code looks like being mergable with dbgstabs. This might
  20. change however when improved dwarf info is generated, so the stuff shouldn't be
  21. merged yet. (FK)
  22. The easiest way to debug dwarf debug info generation is the usage of
  23. readelf --debug-dump <executable>
  24. This works only with elf targets though.
  25. }
  26. unit dbgdwarf;
  27. {$i fpcdefs.inc}
  28. interface
  29. uses
  30. cclasses,
  31. aasmbase,aasmtai,
  32. symbase,symtype,symdef,
  33. DbgBase;
  34. type
  35. { Tag names and codes. }
  36. tdwarf_tag = (DW_TAG_padding := $00,DW_TAG_array_type := $01,
  37. DW_TAG_class_type := $02,DW_TAG_entry_point := $03,
  38. DW_TAG_enumeration_type := $04,DW_TAG_formal_parameter := $05,
  39. DW_TAG_imported_declaration := $08,DW_TAG_label := $0a,
  40. DW_TAG_lexical_block := $0b,DW_TAG_member := $0d,
  41. DW_TAG_pointer_type := $0f,DW_TAG_reference_type := $10,
  42. DW_TAG_compile_unit := $11,DW_TAG_string_type := $12,
  43. DW_TAG_structure_type := $13,DW_TAG_subroutine_type := $15,
  44. DW_TAG_typedef := $16,DW_TAG_union_type := $17,
  45. DW_TAG_unspecified_parameters := $18,
  46. DW_TAG_variant := $19,DW_TAG_common_block := $1a,
  47. DW_TAG_common_inclusion := $1b,DW_TAG_inheritance := $1c,
  48. DW_TAG_inlined_subroutine := $1d,DW_TAG_module := $1e,
  49. DW_TAG_ptr_to_member_type := $1f,DW_TAG_set_type := $20,
  50. DW_TAG_subrange_type := $21,DW_TAG_with_stmt := $22,
  51. DW_TAG_access_declaration := $23,DW_TAG_base_type := $24,
  52. DW_TAG_catch_block := $25,DW_TAG_const_type := $26,
  53. DW_TAG_constant := $27,DW_TAG_enumerator := $28,
  54. DW_TAG_file_type := $29,DW_TAG_friend := $2a,
  55. DW_TAG_namelist := $2b,DW_TAG_namelist_item := $2c,
  56. DW_TAG_packed_type := $2d,DW_TAG_subprogram := $2e,
  57. DW_TAG_template_type_param := $2f,DW_TAG_template_value_param := $30,
  58. DW_TAG_thrown_type := $31,DW_TAG_try_block := $32,
  59. DW_TAG_variant_part := $33,DW_TAG_variable := $34,
  60. DW_TAG_volatile_type := $35,
  61. { DWARF 3. }
  62. DW_TAG_dwarf_procedure := $36,
  63. DW_TAG_restrict_type := $37,DW_TAG_interface_type := $38,
  64. DW_TAG_namespace := $39,DW_TAG_imported_module := $3a,
  65. DW_TAG_unspecified_type := $3b,DW_TAG_partial_unit := $3c,
  66. DW_TAG_imported_unit := $3d,
  67. { SGI/MIPS Extensions. }
  68. DW_TAG_MIPS_loop := $4081,
  69. { HP extensions. See: ftp://ftp.hp.com/pub/lang/tools/WDB/wdb-4.0.tar.gz . }
  70. DW_TAG_HP_array_descriptor := $4090,
  71. { GNU extensions. }
  72. { For FORTRAN 77 and Fortran 90. }
  73. DW_TAG_format_label := $4101,
  74. { For C++. }
  75. DW_TAG_function_template := $4102,DW_TAG_class_template := $4103,
  76. DW_TAG_GNU_BINCL := $4104,DW_TAG_GNU_EINCL := $4105,
  77. { Extensions for UPC. See: http://upc.gwu.edu/~upc. }
  78. DW_TAG_upc_shared_type := $8765,DW_TAG_upc_strict_type := $8766,
  79. DW_TAG_upc_relaxed_type := $8767,
  80. { PGI (STMicroelectronics) extensions. No documentation available. }
  81. DW_TAG_PGI_kanji_type := $A000,
  82. DW_TAG_PGI_interface_block := $A020);
  83. { Attribute names and codes. }
  84. tdwarf_attribute = (DW_AT_sibling := $01,DW_AT_location := $02,
  85. DW_AT_name := $03,DW_AT_ordering := $09,
  86. DW_AT_subscr_data := $0a,DW_AT_byte_size := $0b,
  87. DW_AT_bit_offset := $0c,DW_AT_bit_size := $0d,
  88. DW_AT_element_list := $0f,DW_AT_stmt_list := $10,
  89. DW_AT_low_pc := $11,DW_AT_high_pc := $12,
  90. DW_AT_language := $13,DW_AT_member := $14,
  91. DW_AT_discr := $15,DW_AT_discr_value := $16,
  92. DW_AT_visibility := $17,DW_AT_import := $18,
  93. DW_AT_string_length := $19,DW_AT_common_reference := $1a,
  94. DW_AT_comp_dir := $1b,DW_AT_const_value := $1c,
  95. DW_AT_containing_type := $1d,DW_AT_default_value := $1e,
  96. DW_AT_inline := $20,DW_AT_is_optional := $21,
  97. DW_AT_lower_bound := $22,DW_AT_producer := $25,
  98. DW_AT_prototyped := $27,DW_AT_return_addr := $2a,
  99. DW_AT_start_scope := $2c,DW_AT_stride_size := $2e,
  100. DW_AT_upper_bound := $2f,DW_AT_abstract_origin := $31,
  101. DW_AT_accessibility := $32,DW_AT_address_class := $33,
  102. DW_AT_artificial := $34,DW_AT_base_types := $35,
  103. DW_AT_calling_convention := $36,DW_AT_count := $37,
  104. DW_AT_data_member_location := $38,DW_AT_decl_column := $39,
  105. DW_AT_decl_file := $3a,DW_AT_decl_line := $3b,
  106. DW_AT_declaration := $3c,DW_AT_discr_list := $3d,
  107. DW_AT_encoding := $3e,DW_AT_external := $3f,
  108. DW_AT_frame_base := $40,DW_AT_friend := $41,
  109. DW_AT_identifier_case := $42,DW_AT_macro_info := $43,
  110. DW_AT_namelist_items := $44,DW_AT_priority := $45,
  111. DW_AT_segment := $46,DW_AT_specification := $47,
  112. DW_AT_static_link := $48,DW_AT_type := $49,
  113. DW_AT_use_location := $4a,DW_AT_variable_parameter := $4b,
  114. DW_AT_virtuality := $4c,DW_AT_vtable_elem_location := $4d,
  115. { DWARF 3 values. }
  116. DW_AT_allocated := $4e,DW_AT_associated := $4f,
  117. DW_AT_data_location := $50,DW_AT_stride := $51,
  118. DW_AT_entry_pc := $52,DW_AT_use_UTF8 := $53,
  119. DW_AT_extension := $54,DW_AT_ranges := $55,
  120. DW_AT_trampoline := $56,DW_AT_call_column := $57,
  121. DW_AT_call_file := $58,DW_AT_call_line := $59,
  122. { SGI/MIPS extensions. }
  123. DW_AT_MIPS_fde := $2001,DW_AT_MIPS_loop_begin := $2002,
  124. DW_AT_MIPS_tail_loop_begin := $2003,DW_AT_MIPS_epilog_begin := $2004,
  125. DW_AT_MIPS_loop_unroll_factor := $2005,
  126. DW_AT_MIPS_software_pipeline_depth := $2006,
  127. DW_AT_MIPS_linkage_name := $2007,DW_AT_MIPS_stride := $2008,
  128. DW_AT_MIPS_abstract_name := $2009,DW_AT_MIPS_clone_origin := $200a,
  129. DW_AT_MIPS_has_inlines := $200b,
  130. { HP extensions. }
  131. DW_AT_HP_block_index := $2000,
  132. DW_AT_HP_unmodifiable := $2001,DW_AT_HP_actuals_stmt_list := $2010,
  133. DW_AT_HP_proc_per_section := $2011,DW_AT_HP_raw_data_ptr := $2012,
  134. DW_AT_HP_pass_by_reference := $2013,DW_AT_HP_opt_level := $2014,
  135. DW_AT_HP_prof_version_id := $2015,DW_AT_HP_opt_flags := $2016,
  136. DW_AT_HP_cold_region_low_pc := $2017,DW_AT_HP_cold_region_high_pc := $2018,
  137. DW_AT_HP_all_variables_modifiable := $2019,
  138. DW_AT_HP_linkage_name := $201a,DW_AT_HP_prof_flags := $201b,
  139. { GNU extensions. }
  140. DW_AT_sf_names := $2101,DW_AT_src_info := $2102,
  141. DW_AT_mac_info := $2103,DW_AT_src_coords := $2104,
  142. DW_AT_body_begin := $2105,DW_AT_body_end := $2106,
  143. DW_AT_GNU_vector := $2107,
  144. { VMS extensions. }
  145. DW_AT_VMS_rtnbeg_pd_address := $2201,
  146. { UPC extension. }
  147. DW_AT_upc_threads_scaled := $3210,
  148. { PGI (STMicroelectronics) extensions. }
  149. DW_AT_PGI_lbase := $3a00,
  150. DW_AT_PGI_soffset := $3a01,DW_AT_PGI_lstride := $3a02
  151. );
  152. { Form names and codes. }
  153. Tdwarf_form = (DW_FORM_addr := $01,DW_FORM_block2 := $03,
  154. DW_FORM_block4 := $04,DW_FORM_data2 := $05,
  155. DW_FORM_data4 := $06,DW_FORM_data8 := $07,
  156. DW_FORM_string := $08,DW_FORM_block := $09,
  157. DW_FORM_block1 := $0a,DW_FORM_data1 := $0b,
  158. DW_FORM_flag := $0c,DW_FORM_sdata := $0d,
  159. DW_FORM_strp := $0e,DW_FORM_udata := $0f,
  160. DW_FORM_ref_addr := $10,DW_FORM_ref1 := $11,
  161. DW_FORM_ref2 := $12,DW_FORM_ref4 := $13,
  162. DW_FORM_ref8 := $14,DW_FORM_ref_udata := $15,
  163. DW_FORM_indirect := $16);
  164. TDebugInfoDwarf = class(TDebugInfo)
  165. private
  166. currabbrevnumber : longint;
  167. { collect all defs in one list so we can reset them easily }
  168. nextdefnumber : longint;
  169. defnumberlist : tlist;
  170. writing_def_dwarf : boolean;
  171. { use this defs to create info for variants and file handles }
  172. vardatadef,
  173. filerecdef,
  174. textrecdef : tdef;
  175. function append_entry(tag : tdwarf_tag;has_children : boolean;data : array of const) : longint;
  176. procedure append_labelentry(attr : tdwarf_attribute;sym : tasmsymbol);
  177. procedure append_labelentry_ref(attr : tdwarf_attribute;sym : tasmsymbol);
  178. procedure append_labelentry_data(attr : tdwarf_attribute;sym : tasmsymbol);
  179. procedure finish_entry;
  180. procedure finish_children;
  181. procedure field_add_dwarftag(p:Tnamedindexitem;arg:pointer);
  182. procedure method_add_dwarftag(p:Tnamedindexitem;arg:pointer);
  183. procedure append_procdef(list:taasmoutput;pd:tprocdef);
  184. procedure append_dwarftag(list:taasmoutput;def:tdef);
  185. procedure insertsym(list:taasmoutput;sym:tsym);
  186. procedure write_symtable_syms(list:taasmoutput;st:tsymtable);
  187. function def_dwarf_lab(def:tdef) : tasmsymbol;
  188. public
  189. procedure insertdef(list:taasmoutput;def:tdef);override;
  190. procedure insertmoduleinfo;override;
  191. procedure inserttypeinfo;override;
  192. procedure referencesections(list:taasmoutput);override;
  193. procedure insertlineinfo(list:taasmoutput);override;
  194. procedure write_symtable_defs(list:taasmoutput;st:tsymtable);override;
  195. end;
  196. implementation
  197. uses
  198. version,
  199. cutils,
  200. globtype,
  201. globals,
  202. verbose,
  203. systems,
  204. cpubase,
  205. cgbase,
  206. finput,
  207. fmodule,
  208. defutil,
  209. symconst,symtable,symsym
  210. ;
  211. const
  212. DW_TAG_lo_user = $4080;
  213. DW_TAG_hi_user = $ffff;
  214. { Flag that tells whether entry has a child or not. }
  215. DW_children_no = 0;
  216. DW_children_yes = 1;
  217. const
  218. { Implementation-defined range start. }
  219. DW_AT_lo_user = $2000;
  220. { Implementation-defined range end. }
  221. DW_AT_hi_user = $3ff0;
  222. type
  223. { Source language names and codes. }
  224. tdwarf_source_language = (DW_LANG_C89 := $0001,DW_LANG_C := $0002,DW_LANG_Ada83 := $0003,
  225. DW_LANG_C_plus_plus := $0004,DW_LANG_Cobol74 := $0005,
  226. DW_LANG_Cobol85 := $0006,DW_LANG_Fortran77 := $0007,
  227. DW_LANG_Fortran90 := $0008,DW_LANG_Pascal83 := $0009,
  228. DW_LANG_Modula2 := $000a,DW_LANG_Java := $000b,
  229. { DWARF 3. }
  230. DW_LANG_C99 := $000c,DW_LANG_Ada95 := $000d,
  231. DW_LANG_Fortran95 := $000e,
  232. { MIPS. }
  233. DW_LANG_Mips_Assembler := $8001,
  234. { UPC. }
  235. DW_LANG_Upc := $8765
  236. );
  237. const
  238. { Implementation-defined range start. }
  239. DW_LANG_lo_user = $8000;
  240. { Implementation-defined range start. }
  241. DW_LANG_hi_user = $ffff;
  242. type
  243. { Names and codes for macro information. }
  244. tdwarf_macinfo_record_type = (DW_MACINFO_define := 1,DW_MACINFO_undef := 2,
  245. DW_MACINFO_start_file := 3,DW_MACINFO_end_file := 4,
  246. DW_MACINFO_vendor_ext := 255);
  247. type
  248. { Type encodings. }
  249. Tdwarf_type = (DW_ATE_void := $0,DW_ATE_address := $1,
  250. DW_ATE_boolean := $2,DW_ATE_complex_float := $3,
  251. DW_ATE_float := $4,DW_ATE_signed := $5,
  252. DW_ATE_signed_char := $6,DW_ATE_unsigned := $7,
  253. DW_ATE_unsigned_char := $8,DW_ATE_imaginary_float := $9,
  254. { HP extensions. }
  255. DW_ATE_HP_float80 := $80,DW_ATE_HP_complex_float80 := $81,
  256. DW_ATE_HP_float128 := $82,DW_ATE_HP_complex_float128 := $83,
  257. DW_ATE_HP_floathpintel := $84,DW_ATE_HP_imaginary_float80 := $85,
  258. DW_ATE_HP_imaginary_float128 := $86
  259. );
  260. const
  261. DW_ATE_lo_user = $80;
  262. DW_ATE_hi_user = $ff;
  263. type
  264. Tdwarf_array_dim_ordering = (DW_ORD_row_major := 0,DW_ORD_col_major := 1
  265. );
  266. { Access attribute. }
  267. Tdwarf_access_attribute = (DW_ACCESS_public := 1,DW_ACCESS_protected := 2,
  268. DW_ACCESS_private := 3);
  269. { Visibility. }
  270. Tdwarf_visibility_attribute = (DW_VIS_local := 1,DW_VIS_exported := 2,
  271. DW_VIS_qualified := 3);
  272. { Virtuality. }
  273. Tdwarf_virtuality_attribute = (DW_VIRTUALITY_none := 0,DW_VIRTUALITY_virtual := 1,
  274. DW_VIRTUALITY_pure_virtual := 2);
  275. { Case sensitivity. }
  276. Tdwarf_id_case = (DW_ID_case_sensitive := 0,DW_ID_up_case := 1,
  277. DW_ID_down_case := 2,DW_ID_case_insensitive := 3
  278. );
  279. { Calling convention. }
  280. Tdwarf_calling_convention = (DW_CC_normal := $1,DW_CC_program := $2,
  281. DW_CC_nocall := $3,DW_CC_GNU_renesas_sh := $40
  282. );
  283. { Location atom names and codes. }
  284. Tdwarf_location_atom = (DW_OP_addr := $03,DW_OP_deref := $06,DW_OP_const1u := $08,
  285. DW_OP_const1s := $09,DW_OP_const2u := $0a,
  286. DW_OP_const2s := $0b,DW_OP_const4u := $0c,
  287. DW_OP_const4s := $0d,DW_OP_const8u := $0e,
  288. DW_OP_const8s := $0f,DW_OP_constu := $10,
  289. DW_OP_consts := $11,DW_OP_dup := $12,DW_OP_drop := $13,
  290. DW_OP_over := $14,DW_OP_pick := $15,DW_OP_swap := $16,
  291. DW_OP_rot := $17,DW_OP_xderef := $18,DW_OP_abs := $19,
  292. DW_OP_and := $1a,DW_OP_div := $1b,DW_OP_minus := $1c,
  293. DW_OP_mod := $1d,DW_OP_mul := $1e,DW_OP_neg := $1f,
  294. DW_OP_not := $20,DW_OP_or := $21,DW_OP_plus := $22,
  295. DW_OP_plus_uconst := $23,DW_OP_shl := $24,
  296. DW_OP_shr := $25,DW_OP_shra := $26,DW_OP_xor := $27,
  297. DW_OP_bra := $28,DW_OP_eq := $29,DW_OP_ge := $2a,
  298. DW_OP_gt := $2b,DW_OP_le := $2c,DW_OP_lt := $2d,
  299. DW_OP_ne := $2e,DW_OP_skip := $2f,DW_OP_lit0 := $30,
  300. DW_OP_lit1 := $31,DW_OP_lit2 := $32,DW_OP_lit3 := $33,
  301. DW_OP_lit4 := $34,DW_OP_lit5 := $35,DW_OP_lit6 := $36,
  302. DW_OP_lit7 := $37,DW_OP_lit8 := $38,DW_OP_lit9 := $39,
  303. DW_OP_lit10 := $3a,DW_OP_lit11 := $3b,
  304. DW_OP_lit12 := $3c,DW_OP_lit13 := $3d,
  305. DW_OP_lit14 := $3e,DW_OP_lit15 := $3f,
  306. DW_OP_lit16 := $40,DW_OP_lit17 := $41,
  307. DW_OP_lit18 := $42,DW_OP_lit19 := $43,
  308. DW_OP_lit20 := $44,DW_OP_lit21 := $45,
  309. DW_OP_lit22 := $46,DW_OP_lit23 := $47,
  310. DW_OP_lit24 := $48,DW_OP_lit25 := $49,
  311. DW_OP_lit26 := $4a,DW_OP_lit27 := $4b,
  312. DW_OP_lit28 := $4c,DW_OP_lit29 := $4d,
  313. DW_OP_lit30 := $4e,DW_OP_lit31 := $4f,
  314. DW_OP_reg0 := $50,DW_OP_reg1 := $51,DW_OP_reg2 := $52,
  315. DW_OP_reg3 := $53,DW_OP_reg4 := $54,DW_OP_reg5 := $55,
  316. DW_OP_reg6 := $56,DW_OP_reg7 := $57,DW_OP_reg8 := $58,
  317. DW_OP_reg9 := $59,DW_OP_reg10 := $5a,DW_OP_reg11 := $5b,
  318. DW_OP_reg12 := $5c,DW_OP_reg13 := $5d,
  319. DW_OP_reg14 := $5e,DW_OP_reg15 := $5f,
  320. DW_OP_reg16 := $60,DW_OP_reg17 := $61,
  321. DW_OP_reg18 := $62,DW_OP_reg19 := $63,
  322. DW_OP_reg20 := $64,DW_OP_reg21 := $65,
  323. DW_OP_reg22 := $66,DW_OP_reg23 := $67,
  324. DW_OP_reg24 := $68,DW_OP_reg25 := $69,
  325. DW_OP_reg26 := $6a,DW_OP_reg27 := $6b,
  326. DW_OP_reg28 := $6c,DW_OP_reg29 := $6d,
  327. DW_OP_reg30 := $6e,DW_OP_reg31 := $6f,
  328. DW_OP_breg0 := $70,DW_OP_breg1 := $71,
  329. DW_OP_breg2 := $72,DW_OP_breg3 := $73,
  330. DW_OP_breg4 := $74,DW_OP_breg5 := $75,
  331. DW_OP_breg6 := $76,DW_OP_breg7 := $77,
  332. DW_OP_breg8 := $78,DW_OP_breg9 := $79,
  333. DW_OP_breg10 := $7a,DW_OP_breg11 := $7b,
  334. DW_OP_breg12 := $7c,DW_OP_breg13 := $7d,
  335. DW_OP_breg14 := $7e,DW_OP_breg15 := $7f,
  336. DW_OP_breg16 := $80,DW_OP_breg17 := $81,
  337. DW_OP_breg18 := $82,DW_OP_breg19 := $83,
  338. DW_OP_breg20 := $84,DW_OP_breg21 := $85,
  339. DW_OP_breg22 := $86,DW_OP_breg23 := $87,
  340. DW_OP_breg24 := $88,DW_OP_breg25 := $89,
  341. DW_OP_breg26 := $8a,DW_OP_breg27 := $8b,
  342. DW_OP_breg28 := $8c,DW_OP_breg29 := $8d,
  343. DW_OP_breg30 := $8e,DW_OP_breg31 := $8f,
  344. DW_OP_regx := $90,DW_OP_fbreg := $91,DW_OP_bregx := $92,
  345. DW_OP_piece := $93,DW_OP_deref_size := $94,
  346. DW_OP_xderef_size := $95,DW_OP_nop := $96,
  347. { DWARF 3 extensions. }
  348. DW_OP_push_object_address := $97,DW_OP_call2 := $98,
  349. DW_OP_call4 := $99,DW_OP_call_ref := $9a,
  350. { GNU extensions. }
  351. DW_OP_GNU_push_tls_address := $e0,
  352. { HP extensions. }
  353. DW_OP_HP_unknown := $e0,
  354. DW_OP_HP_is_value := $e1,DW_OP_HP_fltconst4 := $e2,
  355. DW_OP_HP_fltconst8 := $e3,DW_OP_HP_mod_range := $e4,
  356. DW_OP_HP_unmod_range := $e5,DW_OP_HP_tls := $e6
  357. );
  358. const
  359. { Implementation-defined range start. }
  360. DW_OP_lo_user = $e0;
  361. { Implementation-defined range end. }
  362. DW_OP_hi_user = $ff;
  363. function TDebugInfoDwarf.def_dwarf_lab(def:tdef) : tasmsymbol;
  364. begin
  365. { procdefs only need a number, mark them as already written
  366. so they won't be written implicitly }
  367. if (def.deftype=procdef) then
  368. def.dbg_state:=dbg_state_written;
  369. { dwarf must already be written, or we must be busy writing it }
  370. if writing_def_dwarf and
  371. not(def.dbg_state in [dbg_state_writing,dbg_state_written]) then
  372. internalerror(200601241);
  373. { Keep track of used dwarf entries, this info is only usefull for dwarf entries
  374. referenced by the symbols. Definitions will always include all
  375. required stabs }
  376. if def.dbg_state=dbg_state_unused then
  377. def.dbg_state:=dbg_state_used;
  378. { Need a new label? }
  379. if def.dwarf_lab=nil then
  380. begin
  381. objectlibrary.getdatalabel(def.dwarf_lab);
  382. if nextdefnumber>=defnumberlist.count then
  383. defnumberlist.count:=nextdefnumber+250;
  384. defnumberlist[nextdefnumber]:=def;
  385. inc(nextdefnumber);
  386. end;
  387. result:=def.dwarf_lab;
  388. end;
  389. { writing the data through a few simply procedures allows to create easily extra information
  390. for debugging of debug info }
  391. function TDebugInfoDwarf.append_entry(tag : tdwarf_tag;has_children : boolean;data : array of const) : longint;
  392. var
  393. i : longint;
  394. begin
  395. inc(currabbrevnumber);
  396. asmlist[al_dwarf_abbrev].concat(tai_comment.Create(strpnew('Abbrev '+tostr(currabbrevnumber))));
  397. { abbrev number }
  398. asmlist[al_dwarf_info].concat(tai_const.create_uleb128bit(currabbrevnumber));
  399. asmlist[al_dwarf_abbrev].concat(tai_const.create_uleb128bit(currabbrevnumber));
  400. { tag }
  401. asmlist[al_dwarf_abbrev].concat(tai_const.create_uleb128bit(ord(tag)));
  402. { children? }
  403. asmlist[al_dwarf_abbrev].concat(tai_const.create_8bit(ord(has_children)));
  404. i:=0;
  405. while i<=high(data) do
  406. begin
  407. { attribute }
  408. if data[i].VType=vtInteger then
  409. begin
  410. asmlist[al_dwarf_abbrev].concat(tai_const.create_uleb128bit(data[i].VInteger));
  411. end
  412. else
  413. internalerror(200601261);
  414. inc(i);
  415. { form }
  416. if data[i].VType=vtInteger then
  417. begin
  418. asmlist[al_dwarf_abbrev].concat(tai_const.create_uleb128bit(data[i].VInteger));
  419. end
  420. else
  421. internalerror(200601262);
  422. inc(i);
  423. { info itself }
  424. case tdwarf_form(data[i-1].VInteger) of
  425. DW_FORM_string:
  426. case data[i].VType of
  427. vtChar:
  428. asmlist[al_dwarf_info].concat(tai_string.create(data[i].VChar));
  429. vtString:
  430. asmlist[al_dwarf_info].concat(tai_string.create(data[i].VString^));
  431. vtAnsistring:
  432. asmlist[al_dwarf_info].concat(tai_string.create(Ansistring(data[i].VAnsiString)));
  433. else
  434. internalerror(200601264);
  435. end;
  436. DW_FORM_flag:
  437. asmlist[al_dwarf_info].concat(tai_const.create_8bit(byte(data[i].VBoolean)));
  438. DW_FORM_data1:
  439. asmlist[al_dwarf_info].concat(tai_const.create_8bit(data[i].VInteger));
  440. DW_FORM_data2:
  441. asmlist[al_dwarf_info].concat(tai_const.create_16bit(data[i].VInteger));
  442. DW_FORM_data4:
  443. asmlist[al_dwarf_info].concat(tai_const.create_32bit(data[i].VInteger));
  444. DW_FORM_data8:
  445. asmlist[al_dwarf_info].concat(tai_const.create_64bit(data[i].VInteger));
  446. DW_FORM_sdata:
  447. case data[i].VType of
  448. vtInteger:
  449. asmlist[al_dwarf_info].concat(tai_const.create_sleb128bit(data[i].VInteger));
  450. vtInt64:
  451. asmlist[al_dwarf_info].concat(tai_const.create_sleb128bit(data[i].VInt64^));
  452. vtQWord:
  453. asmlist[al_dwarf_info].concat(tai_const.create_sleb128bit(data[i].VQWord^));
  454. else
  455. internalerror(200601285);
  456. end;
  457. DW_FORM_udata:
  458. case data[i].VType of
  459. vtInteger:
  460. asmlist[al_dwarf_info].concat(tai_const.create_uleb128bit(data[i].VInteger));
  461. vtInt64:
  462. asmlist[al_dwarf_info].concat(tai_const.create_uleb128bit(data[i].VInt64^));
  463. vtQWord:
  464. asmlist[al_dwarf_info].concat(tai_const.create_uleb128bit(data[i].VQWord^));
  465. else
  466. internalerror(200601284);
  467. end;
  468. { block gets only the size, the rest is appended manually by the caller }
  469. DW_FORM_block1:
  470. asmlist[al_dwarf_info].concat(tai_const.create_8bit(data[i].VInteger));
  471. else
  472. internalerror(200601263);
  473. end;
  474. inc(i);
  475. end;
  476. end;
  477. procedure TDebugInfoDwarf.append_labelentry(attr : tdwarf_attribute;sym : tasmsymbol);
  478. begin
  479. asmlist[al_dwarf_abbrev].concat(tai_const.create_uleb128bit(ord(attr)));
  480. asmlist[al_dwarf_abbrev].concat(tai_const.create_uleb128bit(ord(DW_FORM_addr)));
  481. asmlist[al_dwarf_info].concat(tai_const.create_sym(sym));
  482. end;
  483. procedure TDebugInfoDwarf.append_labelentry_ref(attr : tdwarf_attribute;sym : tasmsymbol);
  484. begin
  485. asmlist[al_dwarf_abbrev].concat(tai_const.create_uleb128bit(ord(attr)));
  486. asmlist[al_dwarf_abbrev].concat(tai_const.create_uleb128bit(ord(DW_FORM_ref_addr)));
  487. asmlist[al_dwarf_info].concat(tai_const.create_sym(sym));
  488. end;
  489. procedure TDebugInfoDwarf.append_labelentry_data(attr : tdwarf_attribute;sym : tasmsymbol);
  490. begin
  491. asmlist[al_dwarf_abbrev].concat(tai_const.create_uleb128bit(ord(attr)));
  492. {$ifdef cpu64bit}
  493. asmlist[al_dwarf_abbrev].concat(tai_const.create_uleb128bit(ord(DW_FORM_data8)));
  494. {$else cpu64bit}
  495. asmlist[al_dwarf_abbrev].concat(tai_const.create_uleb128bit(ord(DW_FORM_data4)));
  496. {$endif cpu64bit}
  497. asmlist[al_dwarf_info].concat(tai_const.create_sym(sym));
  498. end;
  499. procedure TDebugInfoDwarf.finish_entry;
  500. begin
  501. asmlist[al_dwarf_abbrev].concat(tai_const.create_8bit(0));
  502. asmlist[al_dwarf_abbrev].concat(tai_const.create_8bit(0));
  503. end;
  504. procedure TDebugInfoDwarf.finish_children;
  505. begin
  506. asmlist[al_dwarf_info].concat(tai_const.create_8bit(0));
  507. end;
  508. procedure TDebugInfoDwarf.field_add_dwarftag(p:Tnamedindexitem;arg:pointer);
  509. begin
  510. { static variables from objects are like global objects }
  511. if (tsym(p).typ=fieldvarsym) and
  512. not(sp_static in Tsym(p).symoptions) then
  513. begin
  514. append_entry(DW_TAG_member,false,[
  515. DW_AT_name,DW_FORM_string,tsym(p).name+#0,
  516. DW_AT_data_member_location,DW_FORM_block1,1+lengthuleb128(tfieldvarsym(p).fieldoffset)
  517. ]);
  518. asmlist[al_dwarf_info].concat(tai_const.create_8bit(ord(DW_OP_plus_uconst)));
  519. asmlist[al_dwarf_info].concat(tai_const.create_uleb128bit(tfieldvarsym(p).fieldoffset));
  520. append_labelentry_ref(DW_AT_type,def_dwarf_lab(tfieldvarsym(p).vartype.def));
  521. finish_entry;
  522. end;
  523. end;
  524. procedure TDebugInfoDwarf.method_add_dwarftag(p:Tnamedindexitem;arg:pointer);
  525. begin
  526. end;
  527. procedure TDebugInfoDwarf.append_dwarftag(list:taasmoutput;def:tdef);
  528. procedure append_dwarftag_orddef(def:torddef);
  529. begin
  530. case def.typ of
  531. s8bit,
  532. s16bit,
  533. s32bit :
  534. begin
  535. { we should generate a subrange type here }
  536. if assigned(def.typesym) then
  537. append_entry(DW_TAG_base_type,false,[
  538. DW_AT_name,DW_FORM_string,def.typesym.name+#0,
  539. DW_AT_encoding,DW_FORM_data1,DW_ATE_signed,
  540. DW_AT_byte_size,DW_FORM_data1,def.size
  541. ])
  542. else
  543. append_entry(DW_TAG_base_type,false,[
  544. DW_AT_encoding,DW_FORM_data1,DW_ATE_signed,
  545. DW_AT_byte_size,DW_FORM_data1,def.size
  546. ]);
  547. finish_entry;
  548. end;
  549. u8bit,
  550. u16bit,
  551. u32bit :
  552. begin
  553. { we should generate a subrange type here }
  554. if assigned(def.typesym) then
  555. append_entry(DW_TAG_base_type,false,[
  556. DW_AT_name,DW_FORM_string,def.typesym.name+#0,
  557. DW_AT_encoding,DW_FORM_data1,DW_ATE_unsigned,
  558. DW_AT_byte_size,DW_FORM_data1,def.size
  559. ])
  560. else
  561. append_entry(DW_TAG_base_type,false,[
  562. DW_AT_encoding,DW_FORM_data1,DW_ATE_unsigned,
  563. DW_AT_byte_size,DW_FORM_data1,def.size
  564. ]);
  565. finish_entry;
  566. end;
  567. uvoid :
  568. begin
  569. { gdb 6.4 doesn't support DW_TAG_unspecified_type so we
  570. replace it with a unsigned type with size 0 (FK)
  571. }
  572. append_entry(DW_TAG_base_type,false,[
  573. DW_AT_name,DW_FORM_string,'Void'#0,
  574. DW_AT_encoding,DW_FORM_data1,DW_ATE_unsigned,
  575. DW_AT_byte_size,DW_FORM_data1,0
  576. ]);
  577. finish_entry;
  578. end;
  579. uchar :
  580. begin
  581. append_entry(DW_TAG_base_type,false,[
  582. DW_AT_name,DW_FORM_string,'Char'#0,
  583. DW_AT_encoding,DW_FORM_data1,DW_ATE_unsigned_char,
  584. DW_AT_byte_size,DW_FORM_data1,1
  585. ]);
  586. finish_entry;
  587. end;
  588. uwidechar :
  589. begin
  590. append_entry(DW_TAG_base_type,false,[
  591. DW_AT_name,DW_FORM_string,'WideChar'#0,
  592. DW_AT_encoding,DW_FORM_data1,DW_ATE_unsigned_char,
  593. DW_AT_byte_size,DW_FORM_data1,2
  594. ]);
  595. finish_entry;
  596. end;
  597. bool8bit :
  598. begin
  599. append_entry(DW_TAG_base_type,false,[
  600. DW_AT_name,DW_FORM_string,'Boolean'#0,
  601. DW_AT_encoding,DW_FORM_data1,DW_ATE_unsigned_char,
  602. DW_AT_byte_size,DW_FORM_data1,1
  603. ]);
  604. finish_entry;
  605. end;
  606. bool16bit :
  607. begin
  608. append_entry(DW_TAG_base_type,false,[
  609. DW_AT_name,DW_FORM_string,'WordBool'#0,
  610. DW_AT_encoding,DW_FORM_data1,DW_ATE_boolean,
  611. DW_AT_byte_size,DW_FORM_data1,2
  612. ]);
  613. finish_entry;
  614. end;
  615. bool32bit :
  616. begin
  617. append_entry(DW_TAG_base_type,false,[
  618. DW_AT_name,DW_FORM_string,'LongBool'#0,
  619. DW_AT_encoding,DW_FORM_data1,DW_ATE_boolean,
  620. DW_AT_byte_size,DW_FORM_data1,4
  621. ]);
  622. finish_entry;
  623. end;
  624. u64bit :
  625. begin
  626. append_entry(DW_TAG_base_type,false,[
  627. DW_AT_name,DW_FORM_string,'QWord'#0,
  628. DW_AT_encoding,DW_FORM_data1,DW_ATE_unsigned,
  629. DW_AT_byte_size,DW_FORM_data1,8
  630. ]);
  631. finish_entry;
  632. end;
  633. s64bit :
  634. begin
  635. append_entry(DW_TAG_base_type,false,[
  636. DW_AT_name,DW_FORM_string,'Int64'#0,
  637. DW_AT_encoding,DW_FORM_data1,DW_ATE_signed,
  638. DW_AT_byte_size,DW_FORM_data1,8
  639. ]);
  640. finish_entry;
  641. end;
  642. else
  643. internalerror(200601287);
  644. end;
  645. end;
  646. procedure append_dwarftag_floatdef(def:tfloatdef);
  647. begin
  648. case def.typ of
  649. s32real,
  650. s64real,
  651. s80real:
  652. if assigned(def.typesym) then
  653. append_entry(DW_TAG_base_type,false,[
  654. DW_AT_name,DW_FORM_string,def.typesym.name+#0,
  655. DW_AT_encoding,DW_FORM_data1,DW_ATE_float,
  656. DW_AT_byte_size,DW_FORM_data1,def.size
  657. ])
  658. else
  659. append_entry(DW_TAG_base_type,false,[
  660. DW_AT_encoding,DW_FORM_data1,DW_ATE_float,
  661. DW_AT_byte_size,DW_FORM_data1,def.size
  662. ]);
  663. s64currency:
  664. { we should use DW_ATE_signed_fixed, however it isn't supported yet by GDB (FK) }
  665. if assigned(def.typesym) then
  666. append_entry(DW_TAG_base_type,false,[
  667. DW_AT_name,DW_FORM_string,def.typesym.name+#0,
  668. DW_AT_encoding,DW_FORM_data1,DW_ATE_signed,
  669. DW_AT_byte_size,DW_FORM_data1,8
  670. ])
  671. else
  672. append_entry(DW_TAG_base_type,false,[
  673. DW_AT_encoding,DW_FORM_data1,DW_ATE_signed,
  674. DW_AT_byte_size,DW_FORM_data1,8
  675. ]);
  676. s64comp:
  677. if assigned(def.typesym) then
  678. append_entry(DW_TAG_base_type,false,[
  679. DW_AT_name,DW_FORM_string,def.typesym.name+#0,
  680. DW_AT_encoding,DW_FORM_data1,DW_ATE_signed,
  681. DW_AT_byte_size,DW_FORM_data1,8
  682. ])
  683. else
  684. append_entry(DW_TAG_base_type,false,[
  685. DW_AT_encoding,DW_FORM_data1,DW_ATE_signed,
  686. DW_AT_byte_size,DW_FORM_data1,8
  687. ]);
  688. else
  689. internalerror(200601289);
  690. end;
  691. finish_entry;
  692. end;
  693. procedure append_dwarftag_enumdef(def:tenumdef);
  694. var
  695. hp : tenumsym;
  696. begin
  697. if assigned(def.typesym) then
  698. append_entry(DW_TAG_enumeration_type,true,[
  699. DW_AT_name,DW_FORM_string,def.typesym.name+#0,
  700. DW_AT_byte_size,DW_FORM_data1,def.size
  701. ])
  702. else
  703. append_entry(DW_TAG_enumeration_type,true,[
  704. DW_AT_byte_size,DW_FORM_data1,def.size
  705. ]);
  706. if assigned(def.basedef) then
  707. append_labelentry_ref(DW_AT_type,def_dwarf_lab(def.basedef));
  708. finish_entry;
  709. { write enum symbols }
  710. hp:=tenumsym(def.firstenum);
  711. while assigned(hp) do
  712. begin
  713. append_entry(DW_TAG_enumerator,false,[
  714. DW_AT_name,DW_FORM_string,hp.name+#0,
  715. DW_AT_const_value,DW_FORM_data4,hp.value
  716. ]);
  717. finish_entry;
  718. hp:=tenumsym(hp).nextenum;
  719. end;
  720. finish_children;
  721. end;
  722. procedure append_dwarftag_arraydef(def:tarraydef);
  723. var
  724. size : aint;
  725. begin
  726. if is_special_array(def) then
  727. size:=def.elesize
  728. else
  729. size:=def.size;
  730. if assigned(def.typesym) then
  731. append_entry(DW_TAG_array_type,true,[
  732. DW_AT_name,DW_FORM_string,def.typesym.name+#0,
  733. DW_AT_byte_size,DW_FORM_udata,size,
  734. DW_AT_stride_size,DW_FORM_udata,def.elesize*8
  735. ])
  736. else
  737. append_entry(DW_TAG_array_type,true,[
  738. DW_AT_byte_size,DW_FORM_udata,size,
  739. DW_AT_stride_size,DW_FORM_udata,def.elesize*8
  740. ]);
  741. append_labelentry_ref(DW_AT_type,def_dwarf_lab(def.elementtype.def));
  742. if def.IsDynamicArray then
  743. begin
  744. { !!! FIXME !!! }
  745. { gdb's dwarf implementation sucks, so we can't use DW_OP_push_object here (FK)
  746. { insert location attribute manually }
  747. asmlist[al_dwarf_abbrev].concat(tai_const.create_uleb128bit(DW_AT_data_location));
  748. asmlist[al_dwarf_abbrev].concat(tai_const.create_uleb128bit(DW_FORM_block1));
  749. asmlist[al_dwarf_info].concat(tai_const.create_8bit(1));
  750. asmlist[al_dwarf_info].concat(tai_const.create_8bit(DW_OP_push_object));
  751. asmlist[al_dwarf_info].concat(tai_const.create_8bit(DW_OP_deref));
  752. }
  753. finish_entry;
  754. { to simplify things, we don't write a multidimensional array here }
  755. append_entry(DW_TAG_subrange_type,false,[
  756. DW_AT_lower_bound,DW_FORM_udata,0,
  757. DW_AT_upper_bound,DW_FORM_udata,0
  758. ]);
  759. append_labelentry_ref(DW_AT_type,def_dwarf_lab(def.rangetype.def));
  760. finish_entry;
  761. end
  762. else
  763. begin
  764. finish_entry;
  765. { to simplify things, we don't write a multidimensional array here }
  766. append_entry(DW_TAG_subrange_type,false,[
  767. DW_AT_lower_bound,DW_FORM_udata,def.lowrange,
  768. DW_AT_upper_bound,DW_FORM_udata,def.highrange
  769. ]);
  770. append_labelentry_ref(DW_AT_type,def_dwarf_lab(def.rangetype.def));
  771. finish_entry;
  772. end;
  773. finish_children;
  774. end;
  775. procedure append_dwarftag_recorddef(def:trecorddef);
  776. begin
  777. if assigned(def.typesym) then
  778. append_entry(DW_TAG_structure_type,true,[
  779. DW_AT_name,DW_FORM_string,def.typesym.name+#0,
  780. DW_AT_byte_size,DW_FORM_udata,def.size
  781. ])
  782. else
  783. append_entry(DW_TAG_structure_type,true,[
  784. DW_AT_byte_size,DW_FORM_udata,def.size
  785. ]);
  786. finish_entry;
  787. def.symtable.foreach(@field_add_dwarftag,nil);
  788. finish_children;
  789. end;
  790. procedure append_dwarftag_objectdef(def:tobjectdef);
  791. procedure doappend;
  792. begin
  793. if assigned(def.objname) then
  794. append_entry(DW_TAG_structure_type,true,[
  795. DW_AT_name,DW_FORM_string,def.objname^+#0,
  796. DW_AT_byte_size,DW_FORM_udata,def.size
  797. ])
  798. else
  799. append_entry(DW_TAG_structure_type,true,[
  800. DW_AT_byte_size,DW_FORM_udata,def.size
  801. ]);
  802. finish_entry;
  803. if assigned(def.childof) then
  804. begin
  805. append_entry(DW_TAG_inheritance,false,[
  806. DW_AT_accessibility,DW_FORM_data1,DW_ACCESS_public,
  807. DW_AT_data_member_location,DW_FORM_block1,1+lengthuleb128(0)
  808. ]);
  809. asmlist[al_dwarf_info].concat(tai_const.create_8bit(ord(DW_OP_plus_uconst)));
  810. asmlist[al_dwarf_info].concat(tai_const.create_uleb128bit(0));
  811. append_labelentry_ref(DW_AT_type,def_dwarf_lab(def.childof));
  812. finish_entry;
  813. end;
  814. def.symtable.foreach(@field_add_dwarftag,nil);
  815. def.symtable.foreach(@method_add_dwarftag,nil);
  816. finish_children;
  817. end;
  818. var
  819. obj : tasmlabel;
  820. begin
  821. case def.objecttype of
  822. odt_cppclass,
  823. odt_object:
  824. doappend;
  825. odt_interfacecom,
  826. odt_interfacecorba,
  827. odt_dispinterface,
  828. odt_class:
  829. begin
  830. objectlibrary.getdatalabel(obj);
  831. { implicit pointer }
  832. append_entry(DW_TAG_pointer_type,false,[]);
  833. append_labelentry_ref(DW_AT_type,obj);
  834. finish_entry;
  835. asmlist[al_dwarf_info].concat(tai_symbol.create(obj,0));
  836. doappend;
  837. end;
  838. else
  839. internalerror(200602041);
  840. end;
  841. end;
  842. procedure append_dwarftag_pointerdef(def:tpointerdef);
  843. begin
  844. append_entry(DW_TAG_pointer_type,false,[]);
  845. if not(is_voidpointer(def)) then
  846. append_labelentry_ref(DW_AT_type,def_dwarf_lab(def.pointertype.def));
  847. finish_entry;
  848. end;
  849. procedure append_dwarftag_stringdef(def:tstringdef);
  850. var
  851. slen : aint;
  852. arr : tasmlabel;
  853. begin
  854. case def.string_typ of
  855. st_shortstring:
  856. begin
  857. { fix length of openshortstring }
  858. slen:=def.len;
  859. if slen=0 then
  860. slen:=255;
  861. { create a structure with two elements }
  862. objectlibrary.getdatalabel(arr);
  863. append_entry(DW_TAG_structure_type,true,[
  864. DW_AT_name,DW_FORM_string,'ShortString'#0,
  865. DW_AT_byte_size,DW_FORM_data1,2*sizeof(aint)
  866. ]);
  867. finish_entry;
  868. { length entry }
  869. append_entry(DW_TAG_member,false,[
  870. DW_AT_name,DW_FORM_string,'Length'#0,
  871. DW_AT_data_member_location,DW_FORM_block1,1+lengthuleb128(0)
  872. ]);
  873. asmlist[al_dwarf_info].concat(tai_const.create_8bit(ord(DW_OP_plus_uconst)));
  874. asmlist[al_dwarf_info].concat(tai_const.create_uleb128bit(0));
  875. append_labelentry_ref(DW_AT_type,def_dwarf_lab(u8inttype.def));
  876. finish_entry;
  877. { string data entry }
  878. append_entry(DW_TAG_member,false,[
  879. DW_AT_name,DW_FORM_string,'Data'#0,
  880. DW_AT_data_member_location,DW_FORM_block1,1+lengthuleb128(1)
  881. ]);
  882. asmlist[al_dwarf_info].concat(tai_const.create_8bit(ord(DW_OP_plus_uconst)));
  883. asmlist[al_dwarf_info].concat(tai_const.create_uleb128bit(1));
  884. append_labelentry_ref(DW_AT_type,arr);
  885. finish_entry;
  886. finish_children;
  887. { now the data array }
  888. asmlist[al_dwarf_info].concat(tai_symbol.create(arr,0));
  889. append_entry(DW_TAG_array_type,true,[
  890. DW_AT_byte_size,DW_FORM_udata,def.size,
  891. DW_AT_stride_size,DW_FORM_udata,1*8
  892. ]);
  893. append_labelentry_ref(DW_AT_type,def_dwarf_lab(cchartype.def));
  894. finish_entry;
  895. append_entry(DW_TAG_subrange_type,false,[
  896. DW_AT_lower_bound,DW_FORM_udata,0,
  897. DW_AT_upper_bound,DW_FORM_udata,slen
  898. ]);
  899. append_labelentry_ref(DW_AT_type,def_dwarf_lab(u8inttype.def));
  900. finish_entry;
  901. finish_children;
  902. end;
  903. st_longstring:
  904. begin
  905. {
  906. charst:=def_stab_number(cchartype.def);
  907. bytest:=def_stab_number(u8inttype.def);
  908. longst:=def_stab_number(u32inttype.def);
  909. result:=def_stabstr_evaluate(def,'s$1length:$2,0,32;dummy:$6,32,8;st:ar$2;1;$3;$4,40,$5;;',
  910. [tostr(def.len+5),longst,tostr(def.len),charst,tostr(def.len*8),bytest]);
  911. }
  912. end;
  913. st_ansistring:
  914. begin
  915. { looks like a pchar }
  916. append_entry(DW_TAG_pointer_type,false,[]);
  917. append_labelentry_ref(DW_AT_type,def_dwarf_lab(cchartype.def));
  918. finish_entry;
  919. end;
  920. st_widestring:
  921. begin
  922. { looks like a pwidechar }
  923. append_entry(DW_TAG_pointer_type,false,[]);
  924. append_labelentry_ref(DW_AT_type,def_dwarf_lab(cwidechartype.def));
  925. finish_entry;
  926. end;
  927. end;
  928. end;
  929. procedure append_dwarftag_procvardef(def:tprocvardef);
  930. procedure doappend;
  931. var
  932. i : longint;
  933. begin
  934. if assigned(def.typesym) then
  935. append_entry(DW_TAG_subroutine_type,true,[
  936. DW_AT_name,DW_FORM_string,def.typesym.name+#0,
  937. DW_AT_prototyped,DW_FORM_flag,true
  938. ])
  939. else
  940. append_entry(DW_TAG_subroutine_type,true,[
  941. DW_AT_prototyped,DW_FORM_flag,true
  942. ]);
  943. if not(is_void(tprocvardef(def).rettype.def)) then
  944. append_labelentry_ref(DW_AT_type,def_dwarf_lab(tprocvardef(def).rettype.def));
  945. finish_entry;
  946. { write parameters }
  947. for i:=0 to def.paras.count-1 do
  948. begin
  949. append_entry(DW_TAG_formal_parameter,false,[
  950. DW_AT_name,DW_FORM_string,tparavarsym(def.paras[i]).name+#0
  951. ]);
  952. append_labelentry_ref(DW_AT_type,def_dwarf_lab(tparavarsym(def.paras[i]).vartype.def));
  953. finish_entry;
  954. end;
  955. finish_children;
  956. end;
  957. var
  958. proc : tasmlabel;
  959. begin
  960. if def.is_methodpointer then
  961. begin
  962. { create a structure with two elements }
  963. objectlibrary.getdatalabel(proc);
  964. append_entry(DW_TAG_structure_type,true,[
  965. DW_AT_byte_size,DW_FORM_data1,2*sizeof(aint)
  966. ]);
  967. finish_entry;
  968. { proc entry }
  969. append_entry(DW_TAG_member,false,[
  970. DW_AT_name,DW_FORM_string,'Proc'#0,
  971. DW_AT_data_member_location,DW_FORM_block1,1+lengthuleb128(0)
  972. ]);
  973. asmlist[al_dwarf_info].concat(tai_const.create_8bit(ord(DW_OP_plus_uconst)));
  974. asmlist[al_dwarf_info].concat(tai_const.create_uleb128bit(0));
  975. append_labelentry_ref(DW_AT_type,proc);
  976. finish_entry;
  977. { self entry }
  978. append_entry(DW_TAG_member,false,[
  979. DW_AT_name,DW_FORM_string,'Self'#0,
  980. DW_AT_data_member_location,DW_FORM_block1,1+lengthuleb128(sizeof(aint))
  981. ]);
  982. asmlist[al_dwarf_info].concat(tai_const.create_8bit(ord(DW_OP_plus_uconst)));
  983. asmlist[al_dwarf_info].concat(tai_const.create_uleb128bit(sizeof(aint)));
  984. append_labelentry_ref(DW_AT_type,def_dwarf_lab(class_tobject));
  985. finish_entry;
  986. finish_children;
  987. asmlist[al_dwarf_info].concat(tai_symbol.create(proc,0));
  988. doappend;
  989. end
  990. else
  991. doappend;
  992. end;
  993. begin
  994. list.concat(tai_symbol.create(def_dwarf_lab(def),0));
  995. case def.deftype of
  996. stringdef :
  997. append_dwarftag_stringdef(tstringdef(def));
  998. enumdef :
  999. append_dwarftag_enumdef(tenumdef(def));
  1000. orddef :
  1001. append_dwarftag_orddef(torddef(def));
  1002. pointerdef :
  1003. append_dwarftag_pointerdef(tpointerdef(def));
  1004. floatdef :
  1005. append_dwarftag_floatdef(tfloatdef(def));
  1006. filedef :
  1007. begin
  1008. { gdb 6.4 doesn't support files so far so we use some fake recorddef
  1009. { file recs. are less than 1k so using data2 is enough }
  1010. if assigned(def.typesym) then
  1011. append_entry(DW_TAG_file_type,false,[
  1012. DW_AT_name,DW_FORM_string,def.typesym.name+#0,
  1013. DW_AT_byte_size,DW_FORM_data2,def.size
  1014. ])
  1015. else
  1016. append_entry(DW_TAG_file_type,false,[
  1017. DW_AT_byte_size,DW_FORM_data2,def.size
  1018. ]);
  1019. if tfiledef(def).filetyp=ft_typed then
  1020. append_labelentry_ref(DW_AT_type,def_dwarf_lab(tfiledef(def).typedfiletype.def));
  1021. }
  1022. if assigned(def.typesym) then
  1023. append_entry(DW_TAG_structure_type,false,[
  1024. DW_AT_name,DW_FORM_string,def.typesym.name+#0,
  1025. DW_AT_byte_size,DW_FORM_udata,def.size
  1026. ])
  1027. else
  1028. append_entry(DW_TAG_structure_type,false,[
  1029. DW_AT_byte_size,DW_FORM_udata,def.size
  1030. ]);
  1031. finish_entry;
  1032. end;
  1033. recorddef :
  1034. append_dwarftag_recorddef(trecorddef(def));
  1035. variantdef :
  1036. { variants aren't known to dwarf but writting tvardata should be enough }
  1037. append_dwarftag_recorddef(trecorddef(vardatadef));
  1038. classrefdef :
  1039. append_dwarftag_pointerdef(tpointerdef(pvmttype.def));
  1040. setdef :
  1041. begin
  1042. { at least gdb up to 6.4 doesn't support sets in dwarf, there is a patch available to fix this:
  1043. http://sources.redhat.com/ml/gdb-patches/2005-05/msg00278.html (FK)
  1044. if assigned(def.typesym) then
  1045. append_entry(DW_TAG_set_type,false,[
  1046. DW_AT_name,DW_FORM_string,def.typesym.name+#0,
  1047. DW_AT_byte_size,DW_FORM_data2,def.size
  1048. ])
  1049. else
  1050. append_entry(DW_TAG_set_type,false,[
  1051. DW_AT_byte_size,DW_FORM_data2,def.size
  1052. ]);
  1053. append_labelentry_ref(DW_AT_type,def_dwarf_lab(tsetdef(def).elementtype.def));
  1054. finish_entry;
  1055. }
  1056. if assigned(def.typesym) then
  1057. append_entry(DW_TAG_base_type,false,[
  1058. DW_AT_name,DW_FORM_string,def.typesym.name+#0,
  1059. DW_AT_encoding,DW_FORM_data1,DW_ATE_unsigned,
  1060. DW_AT_byte_size,DW_FORM_data2,def.size
  1061. ])
  1062. else
  1063. append_entry(DW_TAG_base_type,false,[
  1064. DW_AT_encoding,DW_FORM_data1,DW_ATE_unsigned,
  1065. DW_AT_byte_size,DW_FORM_data2,def.size
  1066. ]);
  1067. finish_entry;
  1068. end;
  1069. formaldef :
  1070. begin
  1071. { gdb 6.4 doesn't support DW_TAG_unspecified_type so we
  1072. replace it with a unsigned type with size 0 (FK)
  1073. }
  1074. append_entry(DW_TAG_base_type,false,[
  1075. DW_AT_name,DW_FORM_string,'FormalDef'#0,
  1076. DW_AT_encoding,DW_FORM_data1,DW_ATE_unsigned,
  1077. DW_AT_byte_size,DW_FORM_data1,0
  1078. ]);
  1079. finish_entry;
  1080. end;
  1081. arraydef :
  1082. append_dwarftag_arraydef(tarraydef(def));
  1083. procvardef :
  1084. append_dwarftag_procvardef(tprocvardef(def));
  1085. objectdef :
  1086. append_dwarftag_objectdef(tobjectdef(def));
  1087. undefineddef :
  1088. begin
  1089. { gdb 6.4 doesn't support DW_TAG_unspecified_type so we
  1090. replace it with a unsigned type with size 0 (FK)
  1091. }
  1092. append_entry(DW_TAG_base_type,false,[
  1093. DW_AT_name,DW_FORM_string,'FormalDef'#0,
  1094. DW_AT_encoding,DW_FORM_data1,DW_ATE_unsigned,
  1095. DW_AT_byte_size,DW_FORM_data1,0
  1096. ]);
  1097. finish_entry;
  1098. end;
  1099. else
  1100. internalerror(200601281);
  1101. end;
  1102. end;
  1103. procedure TDebugInfoDwarf.insertdef(list:taasmoutput;def:tdef);
  1104. var
  1105. anc : tobjectdef;
  1106. oldtypesym : tsym;
  1107. i : longint;
  1108. begin
  1109. if (def.dbg_state in [dbg_state_writing,dbg_state_written]) then
  1110. exit;
  1111. { never write generic template defs }
  1112. if df_generic in def.defoptions then
  1113. begin
  1114. def.dbg_state:=dbg_state_written;
  1115. exit;
  1116. end;
  1117. { to avoid infinite loops }
  1118. def.dbg_state := dbg_state_writing;
  1119. { write dependencies first }
  1120. case def.deftype of
  1121. stringdef :
  1122. begin
  1123. if tstringdef(def).string_typ=st_widestring then
  1124. insertdef(list,cwidechartype.def)
  1125. else
  1126. begin
  1127. insertdef(list,cchartype.def);
  1128. insertdef(list,u8inttype.def);
  1129. end;
  1130. end;
  1131. floatdef :
  1132. insertdef(list,s32inttype.def);
  1133. filedef :
  1134. begin
  1135. insertdef(list,s32inttype.def);
  1136. {$ifdef cpu64bit}
  1137. insertdef(list,s64inttype.def);
  1138. {$endif cpu64bit}
  1139. insertdef(list,u8inttype.def);
  1140. insertdef(list,cchartype.def);
  1141. end;
  1142. classrefdef :
  1143. insertdef(list,pvmttype.def);
  1144. pointerdef :
  1145. insertdef(list,tpointerdef(def).pointertype.def);
  1146. setdef :
  1147. insertdef(list,tsetdef(def).elementtype.def);
  1148. procvardef:
  1149. begin
  1150. insertdef(list,tprocvardef(def).rettype.def);
  1151. if tprocvardef(def).is_methodpointer then
  1152. insertdef(list,class_tobject);
  1153. { parameters }
  1154. for i:=0 to tprocvardef(def).paras.count-1 do
  1155. insertdef(list,tparavarsym(tprocvardef(def).paras[i]).vartype.def);
  1156. end;
  1157. procdef :
  1158. insertdef(list,tprocdef(def).rettype.def);
  1159. arraydef :
  1160. begin
  1161. insertdef(list,tarraydef(def).rangetype.def);
  1162. insertdef(list,tarraydef(def).elementtype.def);
  1163. end;
  1164. recorddef :
  1165. trecorddef(def).symtable.foreach(@field_write_defs,list);
  1166. variantdef :
  1167. trecorddef(vardatadef).symtable.foreach(@field_write_defs,list);
  1168. objectdef :
  1169. begin
  1170. insertdef(list,vmtarraytype.def);
  1171. { first the parents }
  1172. anc:=tobjectdef(def);
  1173. while assigned(anc.childof) do
  1174. begin
  1175. anc:=anc.childof;
  1176. insertdef(list,anc);
  1177. end;
  1178. tobjectdef(def).symtable.foreach(@field_write_defs,list);
  1179. tobjectdef(def).symtable.foreach(@method_write_defs,list);
  1180. end;
  1181. end;
  1182. append_dwarftag(list,def);
  1183. def.dbg_state:=dbg_state_written;
  1184. end;
  1185. procedure TDebugInfoDwarf.write_symtable_defs(list:taasmoutput;st:tsymtable);
  1186. procedure dowritedwarf(list:taasmoutput;st:tsymtable);
  1187. var
  1188. p : tdef;
  1189. begin
  1190. p:=tdef(st.defindex.first);
  1191. while assigned(p) do
  1192. begin
  1193. if (p.dbg_state=dbg_state_used) then
  1194. insertdef(list,p);
  1195. p:=tdef(p.indexnext);
  1196. end;
  1197. end;
  1198. var
  1199. old_writing_def_dwarf : boolean;
  1200. begin
  1201. case st.symtabletype of
  1202. staticsymtable :
  1203. list.concat(tai_comment.Create(strpnew('Defs - Begin Staticsymtable')));
  1204. globalsymtable :
  1205. list.concat(tai_comment.Create(strpnew('Defs - Begin unit '+st.name^+' has index '+tostr(st.moduleid))));
  1206. end;
  1207. old_writing_def_dwarf:=writing_def_dwarf;
  1208. writing_def_dwarf:=true;
  1209. dowritedwarf(list,st);
  1210. writing_def_dwarf:=old_writing_def_dwarf;
  1211. case st.symtabletype of
  1212. staticsymtable :
  1213. list.concat(tai_comment.Create(strpnew('Defs - End Staticsymtable')));
  1214. globalsymtable :
  1215. list.concat(tai_comment.Create(strpnew('Defs - End unit '+st.name^+' has index '+tostr(st.moduleid))));
  1216. end;
  1217. end;
  1218. procedure TDebugInfoDwarf.append_procdef(list:taasmoutput;pd:tprocdef);
  1219. var
  1220. procendlabel : tasmlabel;
  1221. mangled_length : longint;
  1222. p : pchar;
  1223. hs : string;
  1224. begin
  1225. if assigned(pd.procstarttai) then
  1226. begin
  1227. append_entry(DW_TAG_subprogram,true,
  1228. [DW_AT_name,DW_FORM_string,pd.procsym.name+#0
  1229. { data continues below }
  1230. { problem: base reg isn't known here
  1231. DW_AT_frame_base,DW_FORM_block1,1
  1232. }
  1233. ]);
  1234. { append block data }
  1235. { asmlist[al_dwarf_info].concat(tai_const.create_8bit(dwarf_reg(pd.))); }
  1236. if not(is_void(tprocdef(pd).rettype.def)) then
  1237. append_labelentry_ref(DW_AT_type,def_dwarf_lab(tprocdef(pd).rettype.def));
  1238. { mark end of procedure }
  1239. objectlibrary.getlabel(procendlabel,alt_dbgtype);
  1240. asmlist[al_procedures].insertbefore(tai_label.create(procendlabel),pd.procendtai);
  1241. append_labelentry(DW_AT_low_pc,objectlibrary.newasmsymbol(pd.mangledname,AB_LOCAL,AT_DATA));
  1242. append_labelentry(DW_AT_high_pc,procendlabel);
  1243. {
  1244. if assigned(pd.funcretsym) and
  1245. (tabstractnormalvarsym(pd.funcretsym).refs>0) then
  1246. begin
  1247. if tabstractnormalvarsym(pd.funcretsym).localloc.loc=LOC_REFERENCE then
  1248. begin
  1249. {$warning Need to add gdb support for ret in param register calling}
  1250. if paramanager.ret_in_param(pd.rettype.def,pd.proccalloption) then
  1251. hs:='X*'
  1252. else
  1253. hs:='X';
  1254. templist.concat(Tai_stab.create(stab_stabs,strpnew(
  1255. '"'+pd.procsym.name+':'+hs+def_stab_number(pd.rettype.def)+'",'+
  1256. tostr(N_tsym)+',0,0,'+tostr(tabstractnormalvarsym(pd.funcretsym).localloc.reference.offset))));
  1257. if (m_result in aktmodeswitches) then
  1258. templist.concat(Tai_stab.create(stab_stabs,strpnew(
  1259. '"RESULT:'+hs+def_stab_number(pd.rettype.def)+'",'+
  1260. tostr(N_tsym)+',0,0,'+tostr(tabstractnormalvarsym(pd.funcretsym).localloc.reference.offset))));
  1261. end;
  1262. end;
  1263. }
  1264. finish_entry;
  1265. {
  1266. { para types }
  1267. write_def_stabstr(templist,pd);
  1268. }
  1269. if assigned(pd.parast) then
  1270. write_symtable_syms(list,pd.parast);
  1271. { local type defs and vars should not be written
  1272. inside the main proc stab }
  1273. if assigned(pd.localst) and
  1274. (pd.localst.symtabletype=localsymtable) then
  1275. write_symtable_syms(list,pd.localst);
  1276. { last write the types from this procdef }
  1277. if assigned(pd.parast) then
  1278. write_symtable_defs(asmlist[al_dwarf_info],pd.parast);
  1279. if assigned(pd.localst) and
  1280. (pd.localst.symtabletype=localsymtable) then
  1281. write_symtable_defs(asmlist[al_dwarf_info],pd.localst);
  1282. finish_children;
  1283. end;
  1284. end;
  1285. procedure TDebugInfoDwarf.insertsym(list:taasmoutput;sym:tsym);
  1286. procedure append_varsym(sym:tabstractnormalvarsym);
  1287. var
  1288. templist : taasmoutput;
  1289. blocksize : longint;
  1290. regidx : longint;
  1291. tag : tdwarf_tag;
  1292. begin
  1293. { external symbols can't be resolved at link time, so we
  1294. can't generate stabs for them
  1295. not sure if this applies to dwarf as well (FK)
  1296. }
  1297. if vo_is_external in sym.varoptions then
  1298. exit;
  1299. { There is no space allocated for not referenced locals }
  1300. if (sym.owner.symtabletype=localsymtable) and (sym.refs=0) then
  1301. exit;
  1302. templist:=taasmoutput.create;
  1303. case sym.localloc.loc of
  1304. LOC_REGISTER,
  1305. LOC_CREGISTER,
  1306. LOC_MMREGISTER,
  1307. LOC_CMMREGISTER,
  1308. LOC_FPUREGISTER,
  1309. LOC_CFPUREGISTER :
  1310. begin
  1311. regidx:=findreg_by_number(sym.localloc.register);
  1312. templist.concat(tai_const.create_8bit(ord(DW_OP_regx)));
  1313. templist.concat(tai_const.create_uleb128bit(regdwarf_table[regidx]));
  1314. blocksize:=1+Lengthuleb128(regdwarf_table[regidx]);
  1315. end;
  1316. else
  1317. begin
  1318. case sym.typ of
  1319. globalvarsym:
  1320. begin
  1321. if (vo_is_thread_var in sym.varoptions) then
  1322. begin
  1323. {$warning !!! FIXME: dwarf for thread vars !!!}
  1324. blocksize:=0;
  1325. end
  1326. else
  1327. begin
  1328. templist.concat(tai_const.create_8bit(3));
  1329. templist.concat(tai_const.createname(sym.mangledname,AT_DATA,0));
  1330. blocksize:=1+sizeof(aword);
  1331. end;
  1332. end;
  1333. paravarsym,
  1334. localvarsym:
  1335. begin
  1336. regidx:=findreg_by_number(sym.localloc.reference.base);
  1337. templist.concat(tai_const.create_8bit(ord(DW_OP_breg0)+regdwarf_table[regidx]));
  1338. templist.concat(tai_const.create_sleb128bit(sym.localloc.reference.offset));
  1339. blocksize:=1+Lengthsleb128(sym.localloc.reference.offset);
  1340. end
  1341. else
  1342. internalerror(200601288);
  1343. end;
  1344. end;
  1345. end;
  1346. if sym.typ=paravarsym then
  1347. tag:=DW_TAG_formal_parameter
  1348. else
  1349. tag:=DW_TAG_variable;
  1350. append_entry(tag,false,[
  1351. DW_AT_name,DW_FORM_string,sym.name+#0,
  1352. {
  1353. DW_AT_decl_file,DW_FORM_data1,0,
  1354. DW_AT_decl_line,DW_FORM_data1,
  1355. }
  1356. DW_AT_external,DW_FORM_flag,true,
  1357. { data continues below }
  1358. DW_AT_location,DW_FORM_block1,blocksize
  1359. ]);
  1360. { append block data }
  1361. asmlist[al_dwarf_info].concatlist(templist);
  1362. append_labelentry_ref(DW_AT_type,def_dwarf_lab(sym.vartype.def));
  1363. templist.free;
  1364. finish_entry;
  1365. end;
  1366. procedure append_constsym(sym:tconstsym);
  1367. begin
  1368. append_entry(DW_TAG_constant,false,[
  1369. DW_AT_name,DW_FORM_string,sym.name+#0
  1370. ]);
  1371. { for string constants, consttype isn't set because they have no real type }
  1372. if not(sym.consttyp in [conststring,constresourcestring]) then
  1373. append_labelentry_ref(DW_AT_type,def_dwarf_lab(sym.consttype.def));
  1374. asmlist[al_dwarf_abbrev].concat(tai_const.create_uleb128bit(ord(DW_AT_const_value)));
  1375. case sym.consttyp of
  1376. conststring:
  1377. begin
  1378. asmlist[al_dwarf_abbrev].concat(tai_const.create_uleb128bit(ord(DW_FORM_string)));
  1379. asmlist[al_dwarf_info].concat(tai_string.create(strpas(pchar(sym.value.valueptr))));
  1380. asmlist[al_dwarf_info].concat(tai_const.create_8bit(0));
  1381. end;
  1382. constset,
  1383. constwstring,
  1384. constguid,
  1385. constresourcestring:
  1386. begin
  1387. { write dummy for now }
  1388. asmlist[al_dwarf_abbrev].concat(tai_const.create_uleb128bit(ord(DW_FORM_string)));
  1389. asmlist[al_dwarf_info].concat(tai_string.create(''));
  1390. asmlist[al_dwarf_info].concat(tai_const.create_8bit(0));
  1391. end;
  1392. constord:
  1393. begin
  1394. asmlist[al_dwarf_abbrev].concat(tai_const.create_uleb128bit(ord(DW_FORM_sdata)));
  1395. asmlist[al_dwarf_info].concat(tai_const.create_sleb128bit(sym.value.valueord));
  1396. end;
  1397. constnil:
  1398. begin
  1399. {$ifdef cpu64bit}
  1400. asmlist[al_dwarf_abbrev].concat(tai_const.create_uleb128bit(ord(DW_FORM_data8)));
  1401. asmlist[al_dwarf_info].concat(tai_const.create_64bit(0));
  1402. {$else cpu64bit}
  1403. asmlist[al_dwarf_abbrev].concat(tai_const.create_uleb128bit(ord(DW_FORM_data4)));
  1404. asmlist[al_dwarf_info].concat(tai_const.create_32bit(0));
  1405. {$endif cpu64bit}
  1406. end;
  1407. constpointer:
  1408. begin
  1409. {$ifdef cpu64bit}
  1410. asmlist[al_dwarf_abbrev].concat(tai_const.create_uleb128bit(ord(DW_FORM_data8)));
  1411. asmlist[al_dwarf_info].concat(tai_const.create_64bit(sym.value.valueordptr));
  1412. {$else cpu64bit}
  1413. asmlist[al_dwarf_abbrev].concat(tai_const.create_uleb128bit(ord(DW_FORM_data4)));
  1414. asmlist[al_dwarf_info].concat(tai_const.create_32bit(sym.value.valueordptr));
  1415. {$endif cpu64bit}
  1416. end;
  1417. constreal:
  1418. begin
  1419. asmlist[al_dwarf_abbrev].concat(tai_const.create_uleb128bit(ord(DW_FORM_block1)));
  1420. case tfloatdef(sym.consttype.def).typ of
  1421. s32real:
  1422. begin
  1423. asmlist[al_dwarf_info].concat(tai_const.create_8bit(4));
  1424. asmlist[al_dwarf_info].concat(tai_real_32bit.create(psingle(sym.value.valueptr)^));
  1425. end;
  1426. s64comp,
  1427. s64currency,
  1428. s64real:
  1429. begin
  1430. asmlist[al_dwarf_info].concat(tai_const.create_8bit(8));
  1431. asmlist[al_dwarf_info].concat(tai_real_64bit.create(pdouble(sym.value.valueptr)^));
  1432. end;
  1433. s80real:
  1434. begin
  1435. asmlist[al_dwarf_info].concat(tai_const.create_8bit(10));
  1436. asmlist[al_dwarf_info].concat(tai_real_80bit.create(pextended(sym.value.valueptr)^));
  1437. end;
  1438. else
  1439. internalerror(200601291);
  1440. end;
  1441. end;
  1442. else
  1443. internalerror(200601292);
  1444. end;
  1445. finish_entry;
  1446. end;
  1447. procedure append_procsym(sym:tprocsym);
  1448. var
  1449. i : longint;
  1450. begin
  1451. for i:=1 to sym.procdef_count do
  1452. append_procdef(list,sym.procdef[i]);
  1453. end;
  1454. procedure append_absolutesym(sym:tabsolutevarsym);
  1455. var
  1456. templist : taasmoutput;
  1457. blocksize : longint;
  1458. symlist : psymlistitem;
  1459. begin
  1460. templist:=taasmoutput.create;
  1461. case tabsolutevarsym(sym).abstyp of
  1462. toaddr :
  1463. begin
  1464. {$ifdef i386}
  1465. { in theory, we could write a DW_AT_segment entry here for sym.absseg,
  1466. however I doubt that gdb supports this (FK) }
  1467. {$endif i386}
  1468. templist.concat(tai_const.create_8bit(3));
  1469. templist.concat(tai_const.create_aint(sym.addroffset));
  1470. blocksize:=1+sizeof(aword);
  1471. end;
  1472. toasm :
  1473. begin
  1474. templist.concat(tai_const.create_8bit(3));
  1475. templist.concat(tai_const.createname(sym.mangledname,AT_DATA,0));
  1476. blocksize:=1+sizeof(aword);
  1477. end;
  1478. tovar:
  1479. begin
  1480. symlist:=tabsolutevarsym(sym).ref.firstsym;
  1481. { can we insert the symbol? }
  1482. if assigned(symlist) and
  1483. (symlist^.sltype=sl_load) then
  1484. insertsym(list,symlist^.sym);
  1485. templist.free;
  1486. exit;
  1487. end;
  1488. end;
  1489. append_entry(DW_TAG_variable,false,[
  1490. DW_AT_name,DW_FORM_string,sym.name+#0,
  1491. {
  1492. DW_AT_decl_file,DW_FORM_data1,0,
  1493. DW_AT_decl_line,DW_FORM_data1,
  1494. }
  1495. DW_AT_external,DW_FORM_flag,true,
  1496. { data continues below }
  1497. DW_AT_location,DW_FORM_block1,blocksize
  1498. ]);
  1499. { append block data }
  1500. asmlist[al_dwarf_info].concatlist(templist);
  1501. append_labelentry_ref(DW_AT_type,def_dwarf_lab(sym.vartype.def));
  1502. templist.free;
  1503. finish_entry;
  1504. end;
  1505. begin
  1506. case sym.typ of
  1507. globalvarsym :
  1508. append_varsym(tglobalvarsym(sym));
  1509. unitsym:
  1510. { for now, we ignore unit symbols }
  1511. ;
  1512. procsym :
  1513. append_procsym(tprocsym(sym));
  1514. labelsym :
  1515. { ignore label syms for now, the problem is that a label sym
  1516. can have more than one label associated e.g. in case of
  1517. an inline procedure expansion }
  1518. ;
  1519. localvarsym :
  1520. append_varsym(tlocalvarsym(sym));
  1521. paravarsym :
  1522. append_varsym(tparavarsym(sym));
  1523. typedconstsym :
  1524. begin
  1525. append_entry(DW_TAG_variable,false,[
  1526. DW_AT_name,DW_FORM_string,sym.name+#0,
  1527. {
  1528. DW_AT_decl_file,DW_FORM_data1,0,
  1529. DW_AT_decl_line,DW_FORM_data1,
  1530. }
  1531. DW_AT_external,DW_FORM_flag,true,
  1532. { data continues below }
  1533. DW_AT_location,DW_FORM_block1,1+sizeof(aword)
  1534. ]);
  1535. { append block data }
  1536. asmlist[al_dwarf_info].concat(tai_const.create_8bit(3));
  1537. asmlist[al_dwarf_info].concat(tai_const.createname(sym.mangledname,AT_DATA,0));
  1538. append_labelentry_ref(DW_AT_type,def_dwarf_lab(ttypedconstsym(sym).typedconsttype.def));
  1539. finish_entry;
  1540. end;
  1541. constsym :
  1542. append_constsym(tconstsym(sym));
  1543. typesym :
  1544. begin
  1545. append_entry(DW_TAG_typedef,false,[
  1546. DW_AT_name,DW_FORM_string,sym.name+#0
  1547. ]);
  1548. append_labelentry_ref(DW_AT_type,def_dwarf_lab(ttypesym(sym).restype.def));
  1549. finish_entry;
  1550. end;
  1551. enumsym :
  1552. { ignore enum syms, they are written by the owner }
  1553. ;
  1554. rttisym :
  1555. { ignore rtti syms, they are only of internal use }
  1556. ;
  1557. syssym :
  1558. { ignore sys syms, they are only of internal use }
  1559. ;
  1560. absolutevarsym :
  1561. append_absolutesym(tabsolutevarsym(sym));
  1562. propertysym :
  1563. { ignored for now }
  1564. ;
  1565. else
  1566. begin
  1567. writeln(ord(sym.typ));
  1568. internalerror(200601242);
  1569. end;
  1570. end;
  1571. {
  1572. { For object types write also the symtable entries }
  1573. if (sym.typ=typesym) and (ttypesym(sym).restype.def.deftype=objectdef) then
  1574. write_symtable_syms(list,tobjectdef(ttypesym(sym).restype.def).symtable);
  1575. sym.isstabwritten:=true;
  1576. }
  1577. end;
  1578. procedure TDebugInfoDwarf.write_symtable_syms(list:taasmoutput;st:tsymtable);
  1579. var
  1580. p : tsym;
  1581. begin
  1582. case st.symtabletype of
  1583. staticsymtable :
  1584. list.concat(tai_comment.Create(strpnew('Syms - Begin Staticsymtable')));
  1585. globalsymtable :
  1586. list.concat(tai_comment.Create(strpnew('Syms - Begin unit '+st.name^+' has index '+tostr(st.moduleid))));
  1587. end;
  1588. p:=tsym(st.symindex.first);
  1589. while assigned(p) do
  1590. begin
  1591. if (not p.isstabwritten) then
  1592. insertsym(list,p);
  1593. p:=tsym(p.indexnext);
  1594. end;
  1595. case st.symtabletype of
  1596. staticsymtable :
  1597. list.concat(tai_comment.Create(strpnew('Syms - End Staticsymtable')));
  1598. globalsymtable :
  1599. list.concat(tai_comment.Create(strpnew('Syms - End unit '+st.name^+' has index '+tostr(st.moduleid))));
  1600. end;
  1601. end;
  1602. procedure TDebugInfoDwarf.insertmoduleinfo;
  1603. var
  1604. templist : taasmoutput;
  1605. begin
  1606. { insert .Ltext0 label }
  1607. templist:=taasmoutput.create;
  1608. new_section(templist,sec_code,'',0);
  1609. templist.concat(tai_symbol.createname('.Ltext0',AT_DATA,0));
  1610. asmlist[al_start].insertlist(templist);
  1611. templist.free;
  1612. { insert .Letext0 label }
  1613. templist:=taasmoutput.create;
  1614. new_section(templist,sec_code,'',0);
  1615. templist.concat(tai_symbol.createname('.Letext0',AT_DATA,0));
  1616. asmlist[al_end].insertlist(templist);
  1617. templist.free;
  1618. { insert .Ldebug_abbrev0 label }
  1619. templist:=taasmoutput.create;
  1620. new_section(templist,sec_debug_abbrev,'',0);
  1621. templist.concat(tai_symbol.createname('.Ldebug_abbrev0',AT_DATA,0));
  1622. asmlist[al_start].insertlist(templist);
  1623. templist.free;
  1624. { insert .Ldebug_line0 label }
  1625. templist:=taasmoutput.create;
  1626. new_section(templist,sec_debug_line,'',0);
  1627. templist.concat(tai_symbol.createname('.Ldebug_line0',AT_DATA,0));
  1628. asmlist[al_start].insertlist(templist);
  1629. templist.free;
  1630. end;
  1631. procedure TDebugInfoDwarf.inserttypeinfo;
  1632. var
  1633. storefilepos : tfileposinfo;
  1634. lenstartlabel : tasmlabel;
  1635. i : longint;
  1636. begin
  1637. storefilepos:=aktfilepos;
  1638. aktfilepos:=current_module.mainfilepos;
  1639. currabbrevnumber:=0;
  1640. writing_def_dwarf:=false;
  1641. nextdefnumber:=0;
  1642. defnumberlist:=tlist.create;
  1643. vardatadef:=search_system_type('TVARDATA').restype.def;
  1644. { not exported (FK)
  1645. filerecdef:=gettypedef('FILEREC');
  1646. textrecdef:=gettypedef('TEXTREC');
  1647. }
  1648. { write start labels }
  1649. asmlist[al_dwarf_info].concat(tai_section.create(sec_debug_info,'',0));
  1650. asmlist[al_dwarf_info].concat(tai_symbol.createname('.Ldebug_info0',AT_DATA,0));
  1651. { start abbrev section }
  1652. new_section(asmlist[al_dwarf_abbrev],sec_debug_abbrev,'',0);
  1653. { debug info header }
  1654. objectlibrary.getlabel(lenstartlabel,alt_dbgfile);
  1655. { size }
  1656. asmlist[al_dwarf_info].concat(tai_const.create_rel_sym(aitconst_ptr,
  1657. lenstartlabel,tasmsymbol.create('.Ledebug_info0',AB_COMMON,AT_DATA)));
  1658. asmlist[al_dwarf_info].concat(tai_label.create(lenstartlabel));
  1659. { version }
  1660. asmlist[al_dwarf_info].concat(tai_const.create_16bit(2));
  1661. { abbrev table }
  1662. asmlist[al_dwarf_info].concat(tai_const.createname('.Ldebug_abbrev0',AT_DATA,0));
  1663. { address size }
  1664. asmlist[al_dwarf_info].concat(tai_const.create_8bit(sizeof(aint)));
  1665. append_entry(DW_TAG_compile_unit,true,[
  1666. DW_AT_name,DW_FORM_string,FixFileName(current_module.sourcefiles.get_file(1).name^)+#0,
  1667. DW_AT_producer,DW_FORM_string,'Free Pascal '+full_version_string+' '+date_string+#0,
  1668. DW_AT_comp_dir,DW_FORM_string,BsToSlash(FixPath(current_module.sourcefiles.get_file(1).path^,false))+#0,
  1669. DW_AT_language,DW_FORM_data1,DW_LANG_Pascal83,
  1670. DW_AT_identifier_case,DW_FORM_data1,DW_ID_case_insensitive]);
  1671. { reference to line info section }
  1672. append_labelentry_data(DW_AT_stmt_list,objectlibrary.newasmsymbol('.Ldebug_line0',AB_LOCAL,AT_DATA));
  1673. append_labelentry(DW_AT_low_pc,objectlibrary.newasmsymbol('.Ltext0',AB_LOCAL,AT_DATA));
  1674. append_labelentry(DW_AT_high_pc,objectlibrary.newasmsymbol('.Letext0',AB_LOCAL,AT_DATA));
  1675. finish_entry;
  1676. { first write all global/local symbols. This will flag all required tdefs }
  1677. if assigned(current_module.globalsymtable) then
  1678. write_symtable_syms(asmlist[al_dwarf_info],current_module.globalsymtable);
  1679. if assigned(current_module.localsymtable) then
  1680. write_symtable_syms(asmlist[al_dwarf_info],current_module.localsymtable);
  1681. { reset unit type info flag }
  1682. reset_unit_type_info;
  1683. { write used types from the used units }
  1684. write_used_unit_type_info(asmlist[al_dwarf_info],current_module);
  1685. { last write the types from this unit }
  1686. if assigned(current_module.globalsymtable) then
  1687. write_symtable_defs(asmlist[al_dwarf_info],current_module.globalsymtable);
  1688. if assigned(current_module.localsymtable) then
  1689. write_symtable_defs(asmlist[al_dwarf_info],current_module.localsymtable);
  1690. { close compilation unit entry }
  1691. finish_children;
  1692. { end of debug info table }
  1693. asmlist[al_dwarf_info].concat(tai_const.create_8bit(0));
  1694. asmlist[al_dwarf_info].concat(tai_symbol.createname('.Ledebug_info0',AT_DATA,0));
  1695. { reset all def labels }
  1696. for i:=0 to defnumberlist.count-1 do
  1697. begin
  1698. if assigned(defnumberlist[i]) then
  1699. begin
  1700. tdef(defnumberlist[i]).dwarf_lab:=nil;
  1701. tdef(defnumberlist[i]).dbg_state:=dbg_state_unused;
  1702. end;
  1703. end;
  1704. defnumberlist.free;
  1705. defnumberlist:=nil;
  1706. aktfilepos:=storefilepos;
  1707. end;
  1708. procedure TDebugInfoDwarf.referencesections(list:taasmoutput);
  1709. begin
  1710. end;
  1711. procedure TDebugInfoDwarf.insertlineinfo(list:taasmoutput);
  1712. var
  1713. currfileinfo,
  1714. lastfileinfo : tfileposinfo;
  1715. currfuncname : pstring;
  1716. currsectype : tasmsectiontype;
  1717. hlabel : tasmlabel;
  1718. hp : tai;
  1719. infile : tinputfile;
  1720. current_file : tai_file;
  1721. begin
  1722. FillChar(lastfileinfo,sizeof(lastfileinfo),0);
  1723. currfuncname:=nil;
  1724. currsectype:=sec_code;
  1725. hp:=Tai(list.first);
  1726. while assigned(hp) do
  1727. begin
  1728. case hp.typ of
  1729. ait_section :
  1730. currsectype:=tai_section(hp).sectype;
  1731. ait_function_name :
  1732. currfuncname:=tai_function_name(hp).funcname;
  1733. ait_force_line :
  1734. lastfileinfo.line:=-1;
  1735. end;
  1736. if (currsectype=sec_code) and
  1737. (hp.typ=ait_instruction) then
  1738. begin
  1739. currfileinfo:=tailineinfo(hp).fileinfo;
  1740. { file changed ? (must be before line info) }
  1741. if (currfileinfo.fileindex<>0) and
  1742. (lastfileinfo.fileindex<>currfileinfo.fileindex) then
  1743. begin
  1744. infile:=current_module.sourcefiles.get_file(currfileinfo.fileindex);
  1745. if assigned(infile) then
  1746. begin
  1747. if (infile.path^<>'') then
  1748. begin
  1749. current_file:=tai_file.create(BsToSlash(FixPath(infile.path^,false)+FixFileName(infile.name^)));
  1750. list.insertbefore(current_file,hp)
  1751. end
  1752. else
  1753. begin
  1754. current_file:=tai_file.create(FixFileName(infile.name^));
  1755. list.insertbefore(current_file,hp);
  1756. end;
  1757. { force new line info }
  1758. lastfileinfo.line:=-1;
  1759. end;
  1760. end;
  1761. { line changed ? }
  1762. if (lastfileinfo.line<>currfileinfo.line) and (currfileinfo.line<>0) then
  1763. list.insertbefore(tai_loc.create(
  1764. current_file,currfileinfo.line,currfileinfo.column),hp);
  1765. lastfileinfo:=currfileinfo;
  1766. end;
  1767. hp:=tai(hp.next);
  1768. end;
  1769. end;
  1770. const
  1771. dbg_dwarf_info : tdbginfo =
  1772. (
  1773. id : dbg_dwarf;
  1774. idtxt : 'DWARF';
  1775. );
  1776. initialization
  1777. RegisterDebugInfo(dbg_dwarf_info,TDebugInfoDwarf);
  1778. end.