dbgdwarf.pas 78 KB

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