dbgdwarf.pas 78 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061
  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. {$ifdef cpu64bit}
  487. asmlist[al_dwarf_abbrev].concat(tai_const.create_uleb128bit(ord(DW_FORM_ref8)));
  488. {$else cpu64bit}
  489. asmlist[al_dwarf_abbrev].concat(tai_const.create_uleb128bit(ord(DW_FORM_ref4)));
  490. {$endif cpu64bit}
  491. asmlist[al_dwarf_info].concat(tai_const.create_sym(sym));
  492. end;
  493. procedure TDebugInfoDwarf.append_labelentry_data(attr : tdwarf_attribute;sym : tasmsymbol);
  494. begin
  495. asmlist[al_dwarf_abbrev].concat(tai_const.create_uleb128bit(ord(attr)));
  496. {$ifdef cpu64bit}
  497. asmlist[al_dwarf_abbrev].concat(tai_const.create_uleb128bit(ord(DW_FORM_data8)));
  498. {$else cpu64bit}
  499. asmlist[al_dwarf_abbrev].concat(tai_const.create_uleb128bit(ord(DW_FORM_data4)));
  500. {$endif cpu64bit}
  501. asmlist[al_dwarf_info].concat(tai_const.create_sym(sym));
  502. end;
  503. procedure TDebugInfoDwarf.finish_entry;
  504. begin
  505. asmlist[al_dwarf_abbrev].concat(tai_const.create_8bit(0));
  506. asmlist[al_dwarf_abbrev].concat(tai_const.create_8bit(0));
  507. end;
  508. procedure TDebugInfoDwarf.finish_children;
  509. begin
  510. asmlist[al_dwarf_info].concat(tai_const.create_8bit(0));
  511. end;
  512. procedure TDebugInfoDwarf.field_add_dwarftag(p:Tnamedindexitem;arg:pointer);
  513. begin
  514. { static variables from objects are like global objects }
  515. if (tsym(p).typ=fieldvarsym) and
  516. not(sp_static in Tsym(p).symoptions) then
  517. begin
  518. append_entry(DW_TAG_member,false,[
  519. DW_AT_name,DW_FORM_string,tsym(p).name+#0,
  520. DW_AT_data_member_location,DW_FORM_block1,1+lengthuleb128(tfieldvarsym(p).fieldoffset)
  521. ]);
  522. asmlist[al_dwarf_info].concat(tai_const.create_8bit(ord(DW_OP_plus_uconst)));
  523. asmlist[al_dwarf_info].concat(tai_const.create_uleb128bit(tfieldvarsym(p).fieldoffset));
  524. append_labelentry_ref(DW_AT_type,def_dwarf_lab(tfieldvarsym(p).vartype.def));
  525. finish_entry;
  526. end;
  527. end;
  528. procedure TDebugInfoDwarf.method_add_dwarftag(p:Tnamedindexitem;arg:pointer);
  529. begin
  530. end;
  531. procedure TDebugInfoDwarf.append_dwarftag(list:taasmoutput;def:tdef);
  532. procedure append_dwarftag_orddef(def:torddef);
  533. begin
  534. case def.typ of
  535. s8bit,
  536. s16bit,
  537. s32bit :
  538. begin
  539. { we should generate a subrange type here }
  540. if assigned(def.typesym) then
  541. append_entry(DW_TAG_base_type,false,[
  542. DW_AT_name,DW_FORM_string,def.typesym.name+#0,
  543. DW_AT_encoding,DW_FORM_data1,DW_ATE_signed,
  544. DW_AT_byte_size,DW_FORM_data1,def.size
  545. ])
  546. else
  547. append_entry(DW_TAG_base_type,false,[
  548. DW_AT_encoding,DW_FORM_data1,DW_ATE_signed,
  549. DW_AT_byte_size,DW_FORM_data1,def.size
  550. ]);
  551. finish_entry;
  552. end;
  553. u8bit,
  554. u16bit,
  555. u32bit :
  556. begin
  557. { we should generate a subrange type here }
  558. if assigned(def.typesym) then
  559. append_entry(DW_TAG_base_type,false,[
  560. DW_AT_name,DW_FORM_string,def.typesym.name+#0,
  561. DW_AT_encoding,DW_FORM_data1,DW_ATE_unsigned,
  562. DW_AT_byte_size,DW_FORM_data1,def.size
  563. ])
  564. else
  565. append_entry(DW_TAG_base_type,false,[
  566. DW_AT_encoding,DW_FORM_data1,DW_ATE_unsigned,
  567. DW_AT_byte_size,DW_FORM_data1,def.size
  568. ]);
  569. finish_entry;
  570. end;
  571. uvoid :
  572. begin
  573. { gdb 6.4 doesn't support DW_TAG_unspecified_type so we
  574. replace it with a unsigned type with size 0 (FK)
  575. }
  576. append_entry(DW_TAG_base_type,false,[
  577. DW_AT_name,DW_FORM_string,'Void'#0,
  578. DW_AT_encoding,DW_FORM_data1,DW_ATE_unsigned,
  579. DW_AT_byte_size,DW_FORM_data1,0
  580. ]);
  581. finish_entry;
  582. end;
  583. uchar :
  584. begin
  585. append_entry(DW_TAG_base_type,false,[
  586. DW_AT_name,DW_FORM_string,'Char'#0,
  587. DW_AT_encoding,DW_FORM_data1,DW_ATE_unsigned_char,
  588. DW_AT_byte_size,DW_FORM_data1,1
  589. ]);
  590. finish_entry;
  591. end;
  592. uwidechar :
  593. begin
  594. append_entry(DW_TAG_base_type,false,[
  595. DW_AT_name,DW_FORM_string,'WideChar'#0,
  596. DW_AT_encoding,DW_FORM_data1,DW_ATE_unsigned_char,
  597. DW_AT_byte_size,DW_FORM_data1,2
  598. ]);
  599. finish_entry;
  600. end;
  601. bool8bit :
  602. begin
  603. append_entry(DW_TAG_base_type,false,[
  604. DW_AT_name,DW_FORM_string,'Boolean'#0,
  605. DW_AT_encoding,DW_FORM_data1,DW_ATE_unsigned_char,
  606. DW_AT_byte_size,DW_FORM_data1,1
  607. ]);
  608. finish_entry;
  609. end;
  610. bool16bit :
  611. begin
  612. append_entry(DW_TAG_base_type,false,[
  613. DW_AT_name,DW_FORM_string,'WordBool'#0,
  614. DW_AT_encoding,DW_FORM_data1,DW_ATE_boolean,
  615. DW_AT_byte_size,DW_FORM_data1,2
  616. ]);
  617. finish_entry;
  618. end;
  619. bool32bit :
  620. begin
  621. append_entry(DW_TAG_base_type,false,[
  622. DW_AT_name,DW_FORM_string,'LongBool'#0,
  623. DW_AT_encoding,DW_FORM_data1,DW_ATE_boolean,
  624. DW_AT_byte_size,DW_FORM_data1,4
  625. ]);
  626. finish_entry;
  627. end;
  628. u64bit :
  629. begin
  630. append_entry(DW_TAG_base_type,false,[
  631. DW_AT_name,DW_FORM_string,'QWord'#0,
  632. DW_AT_encoding,DW_FORM_data1,DW_ATE_unsigned,
  633. DW_AT_byte_size,DW_FORM_data1,8
  634. ]);
  635. finish_entry;
  636. end;
  637. s64bit :
  638. begin
  639. append_entry(DW_TAG_base_type,false,[
  640. DW_AT_name,DW_FORM_string,'Int64'#0,
  641. DW_AT_encoding,DW_FORM_data1,DW_ATE_signed,
  642. DW_AT_byte_size,DW_FORM_data1,8
  643. ]);
  644. finish_entry;
  645. end;
  646. else
  647. internalerror(200601287);
  648. end;
  649. end;
  650. procedure append_dwarftag_floatdef(def:tfloatdef);
  651. begin
  652. case def.typ of
  653. s32real,
  654. s64real,
  655. s80real:
  656. if assigned(def.typesym) then
  657. append_entry(DW_TAG_base_type,false,[
  658. DW_AT_name,DW_FORM_string,def.typesym.name+#0,
  659. DW_AT_encoding,DW_FORM_data1,DW_ATE_float,
  660. DW_AT_byte_size,DW_FORM_data1,def.size
  661. ])
  662. else
  663. append_entry(DW_TAG_base_type,false,[
  664. DW_AT_encoding,DW_FORM_data1,DW_ATE_float,
  665. DW_AT_byte_size,DW_FORM_data1,def.size
  666. ]);
  667. s64currency:
  668. { we should use DW_ATE_signed_fixed, however it isn't supported yet by GDB (FK) }
  669. if assigned(def.typesym) then
  670. append_entry(DW_TAG_base_type,false,[
  671. DW_AT_name,DW_FORM_string,def.typesym.name+#0,
  672. DW_AT_encoding,DW_FORM_data1,DW_ATE_signed,
  673. DW_AT_byte_size,DW_FORM_data1,8
  674. ])
  675. else
  676. append_entry(DW_TAG_base_type,false,[
  677. DW_AT_encoding,DW_FORM_data1,DW_ATE_signed,
  678. DW_AT_byte_size,DW_FORM_data1,8
  679. ]);
  680. s64comp:
  681. if assigned(def.typesym) then
  682. append_entry(DW_TAG_base_type,false,[
  683. DW_AT_name,DW_FORM_string,def.typesym.name+#0,
  684. DW_AT_encoding,DW_FORM_data1,DW_ATE_signed,
  685. DW_AT_byte_size,DW_FORM_data1,8
  686. ])
  687. else
  688. append_entry(DW_TAG_base_type,false,[
  689. DW_AT_encoding,DW_FORM_data1,DW_ATE_signed,
  690. DW_AT_byte_size,DW_FORM_data1,8
  691. ]);
  692. else
  693. internalerror(200601289);
  694. end;
  695. finish_entry;
  696. end;
  697. procedure append_dwarftag_enumdef(def:tenumdef);
  698. var
  699. hp : tenumsym;
  700. begin
  701. if assigned(def.typesym) then
  702. append_entry(DW_TAG_enumeration_type,true,[
  703. DW_AT_name,DW_FORM_string,def.typesym.name+#0,
  704. DW_AT_byte_size,DW_FORM_data1,def.size
  705. ])
  706. else
  707. append_entry(DW_TAG_enumeration_type,true,[
  708. DW_AT_byte_size,DW_FORM_data1,def.size
  709. ]);
  710. if assigned(def.basedef) then
  711. append_labelentry_ref(DW_AT_type,def_dwarf_lab(def.basedef));
  712. finish_entry;
  713. { write enum symbols }
  714. hp:=tenumsym(def.firstenum);
  715. while assigned(hp) do
  716. begin
  717. append_entry(DW_TAG_enumerator,false,[
  718. DW_AT_name,DW_FORM_string,hp.name+#0,
  719. DW_AT_const_value,DW_FORM_data4,hp.value
  720. ]);
  721. finish_entry;
  722. hp:=tenumsym(hp).nextenum;
  723. end;
  724. finish_children;
  725. end;
  726. procedure append_dwarftag_arraydef(def:tarraydef);
  727. var
  728. size : aint;
  729. begin
  730. if is_open_array(def) then
  731. size:=def.elesize
  732. else
  733. size:=def.size;
  734. if assigned(def.typesym) then
  735. append_entry(DW_TAG_array_type,true,[
  736. DW_AT_name,DW_FORM_string,def.typesym.name+#0,
  737. DW_AT_byte_size,DW_FORM_udata,size,
  738. DW_AT_stride_size,DW_FORM_udata,def.elesize*8
  739. ])
  740. else
  741. append_entry(DW_TAG_array_type,true,[
  742. DW_AT_byte_size,DW_FORM_udata,size,
  743. DW_AT_stride_size,DW_FORM_udata,def.elesize*8
  744. ]);
  745. append_labelentry_ref(DW_AT_type,def_dwarf_lab(def.elementtype.def));
  746. if def.IsDynamicArray then
  747. begin
  748. { !!! FIXME !!! }
  749. { gdb's dwarf implementation sucks, so we can't use DW_OP_push_object here (FK)
  750. { insert location attribute manually }
  751. asmlist[al_dwarf_abbrev].concat(tai_const.create_uleb128bit(DW_AT_data_location));
  752. asmlist[al_dwarf_abbrev].concat(tai_const.create_uleb128bit(DW_FORM_block1));
  753. asmlist[al_dwarf_info].concat(tai_const.create_8bit(1));
  754. asmlist[al_dwarf_info].concat(tai_const.create_8bit(DW_OP_push_object));
  755. asmlist[al_dwarf_info].concat(tai_const.create_8bit(DW_OP_deref));
  756. }
  757. finish_entry;
  758. { to simplify things, we don't write a multidimensional array here }
  759. append_entry(DW_TAG_subrange_type,false,[
  760. DW_AT_lower_bound,DW_FORM_udata,0,
  761. DW_AT_upper_bound,DW_FORM_udata,0
  762. ]);
  763. append_labelentry_ref(DW_AT_type,def_dwarf_lab(def.rangetype.def));
  764. finish_entry;
  765. end
  766. else
  767. begin
  768. finish_entry;
  769. { to simplify things, we don't write a multidimensional array here }
  770. append_entry(DW_TAG_subrange_type,false,[
  771. DW_AT_lower_bound,DW_FORM_udata,def.lowrange,
  772. DW_AT_upper_bound,DW_FORM_udata,def.highrange
  773. ]);
  774. append_labelentry_ref(DW_AT_type,def_dwarf_lab(def.rangetype.def));
  775. finish_entry;
  776. end;
  777. finish_children;
  778. end;
  779. procedure append_dwarftag_recorddef(def:trecorddef);
  780. begin
  781. if assigned(def.typesym) then
  782. append_entry(DW_TAG_structure_type,true,[
  783. DW_AT_name,DW_FORM_string,def.typesym.name+#0,
  784. DW_AT_byte_size,DW_FORM_udata,def.size
  785. ])
  786. else
  787. append_entry(DW_TAG_structure_type,true,[
  788. DW_AT_byte_size,DW_FORM_udata,def.size
  789. ]);
  790. finish_entry;
  791. def.symtable.foreach(@field_add_dwarftag,nil);
  792. finish_children;
  793. end;
  794. procedure append_dwarftag_objectdef(def:tobjectdef);
  795. procedure doappend;
  796. begin
  797. if assigned(def.objname) then
  798. append_entry(DW_TAG_structure_type,true,[
  799. DW_AT_name,DW_FORM_string,def.objname^+#0,
  800. DW_AT_byte_size,DW_FORM_udata,def.size
  801. ])
  802. else
  803. append_entry(DW_TAG_structure_type,true,[
  804. DW_AT_byte_size,DW_FORM_udata,def.size
  805. ]);
  806. finish_entry;
  807. if assigned(def.childof) then
  808. begin
  809. append_entry(DW_TAG_inheritance,false,[
  810. DW_AT_accessibility,DW_FORM_data1,DW_ACCESS_public,
  811. DW_AT_data_member_location,DW_FORM_block1,1+lengthuleb128(0)
  812. ]);
  813. asmlist[al_dwarf_info].concat(tai_const.create_8bit(ord(DW_OP_plus_uconst)));
  814. asmlist[al_dwarf_info].concat(tai_const.create_uleb128bit(0));
  815. append_labelentry_ref(DW_AT_type,def_dwarf_lab(def.childof));
  816. finish_entry;
  817. end;
  818. def.symtable.foreach(@field_add_dwarftag,nil);
  819. def.symtable.foreach(@method_add_dwarftag,nil);
  820. finish_children;
  821. end;
  822. var
  823. obj : tasmlabel;
  824. begin
  825. case def.objecttype of
  826. odt_cppclass,
  827. odt_object:
  828. doappend;
  829. odt_interfacecom,
  830. odt_interfacecorba,
  831. odt_dispinterface,
  832. odt_class:
  833. begin
  834. objectlibrary.getdatalabel(obj);
  835. { implicit pointer }
  836. append_entry(DW_TAG_pointer_type,false,[]);
  837. append_labelentry_ref(DW_AT_type,obj);
  838. finish_entry;
  839. asmlist[al_dwarf_info].concat(tai_symbol.create(obj,0));
  840. doappend;
  841. end;
  842. else
  843. internalerror(200602041);
  844. end;
  845. end;
  846. procedure append_dwarftag_pointerdef(def:tpointerdef);
  847. begin
  848. append_entry(DW_TAG_pointer_type,false,[]);
  849. if not(is_voidpointer(def)) then
  850. append_labelentry_ref(DW_AT_type,def_dwarf_lab(def.pointertype.def));
  851. finish_entry;
  852. end;
  853. procedure append_dwarftag_stringdef(def:tstringdef);
  854. var
  855. slen : aint;
  856. arr : tasmlabel;
  857. begin
  858. case def.string_typ of
  859. st_shortstring:
  860. begin
  861. { fix length of openshortstring }
  862. slen:=def.len;
  863. if slen=0 then
  864. slen:=255;
  865. { create a structure with two elements }
  866. objectlibrary.getdatalabel(arr);
  867. append_entry(DW_TAG_structure_type,true,[
  868. DW_AT_name,DW_FORM_string,'ShortString'#0,
  869. DW_AT_byte_size,DW_FORM_data1,2*sizeof(aint)
  870. ]);
  871. finish_entry;
  872. { length entry }
  873. append_entry(DW_TAG_member,false,[
  874. DW_AT_name,DW_FORM_string,'Length'#0,
  875. DW_AT_data_member_location,DW_FORM_block1,1+lengthuleb128(0)
  876. ]);
  877. asmlist[al_dwarf_info].concat(tai_const.create_8bit(ord(DW_OP_plus_uconst)));
  878. asmlist[al_dwarf_info].concat(tai_const.create_uleb128bit(0));
  879. append_labelentry_ref(DW_AT_type,def_dwarf_lab(u8inttype.def));
  880. finish_entry;
  881. { self entry }
  882. append_entry(DW_TAG_member,false,[
  883. DW_AT_name,DW_FORM_string,'Data'#0,
  884. DW_AT_data_member_location,DW_FORM_block1,1+lengthuleb128(1)
  885. ]);
  886. asmlist[al_dwarf_info].concat(tai_const.create_8bit(ord(DW_OP_plus_uconst)));
  887. asmlist[al_dwarf_info].concat(tai_const.create_uleb128bit(1));
  888. append_labelentry_ref(DW_AT_type,arr);
  889. finish_entry;
  890. finish_children;
  891. { now the data array }
  892. asmlist[al_dwarf_info].concat(tai_symbol.create(arr,0));
  893. append_entry(DW_TAG_array_type,true,[
  894. DW_AT_byte_size,DW_FORM_udata,def.size,
  895. DW_AT_stride_size,DW_FORM_udata,1*8
  896. ]);
  897. append_labelentry_ref(DW_AT_type,def_dwarf_lab(cchartype.def));
  898. finish_entry;
  899. append_entry(DW_TAG_subrange_type,false,[
  900. DW_AT_lower_bound,DW_FORM_udata,0,
  901. DW_AT_upper_bound,DW_FORM_udata,slen
  902. ]);
  903. append_labelentry_ref(DW_AT_type,def_dwarf_lab(u8inttype.def));
  904. finish_entry;
  905. end;
  906. st_longstring:
  907. begin
  908. {
  909. charst:=def_stab_number(cchartype.def);
  910. bytest:=def_stab_number(u8inttype.def);
  911. longst:=def_stab_number(u32inttype.def);
  912. result:=def_stabstr_evaluate(def,'s$1length:$2,0,32;dummy:$6,32,8;st:ar$2;1;$3;$4,40,$5;;',
  913. [tostr(def.len+5),longst,tostr(def.len),charst,tostr(def.len*8),bytest]);
  914. }
  915. end;
  916. st_ansistring:
  917. begin
  918. { looks like a pchar }
  919. append_entry(DW_TAG_pointer_type,false,[]);
  920. append_labelentry_ref(DW_AT_type,def_dwarf_lab(cchartype.def));
  921. finish_entry;
  922. end;
  923. st_widestring:
  924. begin
  925. { looks like a pwidechar }
  926. append_entry(DW_TAG_pointer_type,false,[]);
  927. append_labelentry_ref(DW_AT_type,def_dwarf_lab(cwidechartype.def));
  928. finish_entry;
  929. end;
  930. end;
  931. end;
  932. procedure append_dwarftag_procvardef(def:tprocvardef);
  933. procedure doappend;
  934. var
  935. i : longint;
  936. begin
  937. if assigned(def.typesym) then
  938. append_entry(DW_TAG_subroutine_type,true,[
  939. DW_AT_name,DW_FORM_string,def.typesym.name+#0,
  940. DW_AT_prototyped,DW_FORM_flag,true
  941. ])
  942. else
  943. append_entry(DW_TAG_subroutine_type,true,[
  944. DW_AT_prototyped,DW_FORM_flag,true
  945. ]);
  946. if not(is_void(tprocvardef(def).rettype.def)) then
  947. append_labelentry_ref(DW_AT_type,def_dwarf_lab(tprocvardef(def).rettype.def));
  948. finish_entry;
  949. { write parameters }
  950. for i:=0 to def.paras.count-1 do
  951. begin
  952. append_entry(DW_TAG_formal_parameter,false,[
  953. DW_AT_name,DW_FORM_string,tparavarsym(def.paras[i]).name+#0
  954. ]);
  955. append_labelentry_ref(DW_AT_type,def_dwarf_lab(tparavarsym(def.paras[i]).vartype.def));
  956. finish_entry;
  957. end;
  958. finish_children;
  959. end;
  960. var
  961. proc : tasmlabel;
  962. begin
  963. if def.is_methodpointer then
  964. begin
  965. { create a structure with two elements }
  966. objectlibrary.getdatalabel(proc);
  967. append_entry(DW_TAG_structure_type,true,[
  968. DW_AT_byte_size,DW_FORM_data1,2*sizeof(aint)
  969. ]);
  970. finish_entry;
  971. { proc entry }
  972. append_entry(DW_TAG_member,false,[
  973. DW_AT_name,DW_FORM_string,'Proc'#0,
  974. DW_AT_data_member_location,DW_FORM_block1,1+lengthuleb128(0)
  975. ]);
  976. asmlist[al_dwarf_info].concat(tai_const.create_8bit(ord(DW_OP_plus_uconst)));
  977. asmlist[al_dwarf_info].concat(tai_const.create_uleb128bit(0));
  978. append_labelentry_ref(DW_AT_type,proc);
  979. finish_entry;
  980. { self entry }
  981. append_entry(DW_TAG_member,false,[
  982. DW_AT_name,DW_FORM_string,'Self'#0,
  983. DW_AT_data_member_location,DW_FORM_block1,1+lengthuleb128(sizeof(aint))
  984. ]);
  985. asmlist[al_dwarf_info].concat(tai_const.create_8bit(ord(DW_OP_plus_uconst)));
  986. asmlist[al_dwarf_info].concat(tai_const.create_uleb128bit(sizeof(aint)));
  987. append_labelentry_ref(DW_AT_type,def_dwarf_lab(class_tobject));
  988. finish_entry;
  989. finish_children;
  990. asmlist[al_dwarf_info].concat(tai_symbol.create(proc,0));
  991. doappend;
  992. end
  993. else
  994. doappend;
  995. end;
  996. begin
  997. list.concat(tai_symbol.create(def_dwarf_lab(def),0));
  998. case def.deftype of
  999. stringdef :
  1000. append_dwarftag_stringdef(tstringdef(def));
  1001. enumdef :
  1002. append_dwarftag_enumdef(tenumdef(def));
  1003. orddef :
  1004. append_dwarftag_orddef(torddef(def));
  1005. pointerdef :
  1006. append_dwarftag_pointerdef(tpointerdef(def));
  1007. floatdef :
  1008. append_dwarftag_floatdef(tfloatdef(def));
  1009. filedef :
  1010. begin
  1011. { gdb 6.4 doesn't support files so far so we use some fake recorddef
  1012. { file recs. are less than 1k so using data2 is enough }
  1013. if assigned(def.typesym) then
  1014. append_entry(DW_TAG_file_type,false,[
  1015. DW_AT_name,DW_FORM_string,def.typesym.name+#0,
  1016. DW_AT_byte_size,DW_FORM_data2,def.size
  1017. ])
  1018. else
  1019. append_entry(DW_TAG_file_type,false,[
  1020. DW_AT_byte_size,DW_FORM_data2,def.size
  1021. ]);
  1022. if tfiledef(def).filetyp=ft_typed then
  1023. append_labelentry_ref(DW_AT_type,def_dwarf_lab(tfiledef(def).typedfiletype.def));
  1024. }
  1025. if assigned(def.typesym) then
  1026. append_entry(DW_TAG_structure_type,true,[
  1027. DW_AT_name,DW_FORM_string,def.typesym.name+#0,
  1028. DW_AT_byte_size,DW_FORM_udata,def.size
  1029. ])
  1030. else
  1031. append_entry(DW_TAG_structure_type,true,[
  1032. DW_AT_byte_size,DW_FORM_udata,def.size
  1033. ]);
  1034. finish_entry;
  1035. end;
  1036. recorddef :
  1037. append_dwarftag_recorddef(trecorddef(def));
  1038. variantdef :
  1039. { variants aren't known to dwarf but writting tvardata should be enough }
  1040. append_dwarftag_recorddef(trecorddef(vardatadef));
  1041. classrefdef :
  1042. append_dwarftag_pointerdef(tpointerdef(pvmttype.def));
  1043. setdef :
  1044. begin
  1045. { at least gdb up to 6.4 doesn't support sets in dwarf, there is a patch available to fix this:
  1046. http://sources.redhat.com/ml/gdb-patches/2005-05/msg00278.html (FK)
  1047. if assigned(def.typesym) then
  1048. append_entry(DW_TAG_set_type,false,[
  1049. DW_AT_name,DW_FORM_string,def.typesym.name+#0,
  1050. DW_AT_byte_size,DW_FORM_data2,def.size
  1051. ])
  1052. else
  1053. append_entry(DW_TAG_set_type,false,[
  1054. DW_AT_byte_size,DW_FORM_data2,def.size
  1055. ]);
  1056. append_labelentry_ref(DW_AT_type,def_dwarf_lab(tsetdef(def).elementtype.def));
  1057. finish_entry;
  1058. }
  1059. if assigned(def.typesym) then
  1060. append_entry(DW_TAG_base_type,false,[
  1061. DW_AT_name,DW_FORM_string,def.typesym.name+#0,
  1062. DW_AT_encoding,DW_FORM_data1,DW_ATE_unsigned,
  1063. DW_AT_byte_size,DW_FORM_data2,def.size
  1064. ])
  1065. else
  1066. append_entry(DW_TAG_base_type,false,[
  1067. DW_AT_encoding,DW_FORM_data1,DW_ATE_unsigned,
  1068. DW_AT_byte_size,DW_FORM_data2,def.size
  1069. ]);
  1070. finish_entry;
  1071. end;
  1072. formaldef :
  1073. begin
  1074. { gdb 6.4 doesn't support DW_TAG_unspecified_type so we
  1075. replace it with a unsigned type with size 0 (FK)
  1076. }
  1077. append_entry(DW_TAG_base_type,false,[
  1078. DW_AT_name,DW_FORM_string,'FormalDef'#0,
  1079. DW_AT_encoding,DW_FORM_data1,DW_ATE_unsigned,
  1080. DW_AT_byte_size,DW_FORM_data1,0
  1081. ]);
  1082. finish_entry;
  1083. end;
  1084. arraydef :
  1085. append_dwarftag_arraydef(tarraydef(def));
  1086. procvardef :
  1087. append_dwarftag_procvardef(tprocvardef(def));
  1088. objectdef :
  1089. append_dwarftag_objectdef(tobjectdef(def));
  1090. undefineddef :
  1091. begin
  1092. { gdb 6.4 doesn't support DW_TAG_unspecified_type so we
  1093. replace it with a unsigned type with size 0 (FK)
  1094. }
  1095. append_entry(DW_TAG_base_type,false,[
  1096. DW_AT_name,DW_FORM_string,'FormalDef'#0,
  1097. DW_AT_encoding,DW_FORM_data1,DW_ATE_unsigned,
  1098. DW_AT_byte_size,DW_FORM_data1,0
  1099. ]);
  1100. finish_entry;
  1101. end;
  1102. else
  1103. internalerror(200601281);
  1104. end;
  1105. end;
  1106. procedure TDebugInfoDwarf.insertdef(list:taasmoutput;def:tdef);
  1107. var
  1108. anc : tobjectdef;
  1109. oldtypesym : tsym;
  1110. i : longint;
  1111. begin
  1112. if (def.dbg_state in [dbg_state_writing,dbg_state_written]) then
  1113. exit;
  1114. { never write generic template defs }
  1115. if df_generic in def.defoptions then
  1116. begin
  1117. def.dbg_state:=dbg_state_written;
  1118. exit;
  1119. end;
  1120. { to avoid infinite loops }
  1121. def.dbg_state := dbg_state_writing;
  1122. { write dependencies first }
  1123. case def.deftype of
  1124. stringdef :
  1125. begin
  1126. if tstringdef(def).string_typ=st_widestring then
  1127. insertdef(list,cwidechartype.def)
  1128. else
  1129. begin
  1130. insertdef(list,cchartype.def);
  1131. insertdef(list,u8inttype.def);
  1132. end;
  1133. end;
  1134. floatdef :
  1135. insertdef(list,s32inttype.def);
  1136. filedef :
  1137. begin
  1138. insertdef(list,s32inttype.def);
  1139. {$ifdef cpu64bit}
  1140. insertdef(list,s64inttype.def);
  1141. {$endif cpu64bit}
  1142. insertdef(list,u8inttype.def);
  1143. insertdef(list,cchartype.def);
  1144. end;
  1145. classrefdef :
  1146. insertdef(list,pvmttype.def);
  1147. pointerdef :
  1148. insertdef(list,tpointerdef(def).pointertype.def);
  1149. setdef :
  1150. insertdef(list,tsetdef(def).elementtype.def);
  1151. procvardef:
  1152. begin
  1153. insertdef(list,tprocvardef(def).rettype.def);
  1154. if tprocvardef(def).is_methodpointer then
  1155. insertdef(list,class_tobject);
  1156. { parameters }
  1157. for i:=0 to tprocvardef(def).paras.count-1 do
  1158. insertdef(list,tparavarsym(tprocvardef(def).paras[i]).vartype.def);
  1159. end;
  1160. procdef :
  1161. insertdef(list,tprocdef(def).rettype.def);
  1162. arraydef :
  1163. begin
  1164. insertdef(list,tarraydef(def).rangetype.def);
  1165. insertdef(list,tarraydef(def).elementtype.def);
  1166. end;
  1167. recorddef :
  1168. trecorddef(def).symtable.foreach(@field_write_defs,list);
  1169. variantdef :
  1170. trecorddef(vardatadef).symtable.foreach(@field_write_defs,list);
  1171. objectdef :
  1172. begin
  1173. insertdef(list,vmtarraytype.def);
  1174. { first the parents }
  1175. anc:=tobjectdef(def);
  1176. while assigned(anc.childof) do
  1177. begin
  1178. anc:=anc.childof;
  1179. insertdef(list,anc);
  1180. end;
  1181. tobjectdef(def).symtable.foreach(@field_write_defs,list);
  1182. tobjectdef(def).symtable.foreach(@method_write_defs,list);
  1183. end;
  1184. end;
  1185. append_dwarftag(list,def);
  1186. def.dbg_state:=dbg_state_written;
  1187. end;
  1188. procedure TDebugInfoDwarf.write_symtable_defs(list:taasmoutput;st:tsymtable);
  1189. procedure dowritedwarf(list:taasmoutput;st:tsymtable);
  1190. var
  1191. p : tdef;
  1192. begin
  1193. p:=tdef(st.defindex.first);
  1194. while assigned(p) do
  1195. begin
  1196. if (p.dbg_state=dbg_state_used) then
  1197. insertdef(list,p);
  1198. p:=tdef(p.indexnext);
  1199. end;
  1200. end;
  1201. var
  1202. old_writing_def_dwarf : boolean;
  1203. begin
  1204. case st.symtabletype of
  1205. staticsymtable :
  1206. list.concat(tai_comment.Create(strpnew('Defs - Begin Staticsymtable')));
  1207. globalsymtable :
  1208. list.concat(tai_comment.Create(strpnew('Defs - Begin unit '+st.name^+' has index '+tostr(st.moduleid))));
  1209. end;
  1210. old_writing_def_dwarf:=writing_def_dwarf;
  1211. writing_def_dwarf:=true;
  1212. dowritedwarf(list,st);
  1213. writing_def_dwarf:=old_writing_def_dwarf;
  1214. case st.symtabletype of
  1215. staticsymtable :
  1216. list.concat(tai_comment.Create(strpnew('Defs - End Staticsymtable')));
  1217. globalsymtable :
  1218. list.concat(tai_comment.Create(strpnew('Defs - End unit '+st.name^+' has index '+tostr(st.moduleid))));
  1219. end;
  1220. end;
  1221. procedure TDebugInfoDwarf.append_procdef(list:taasmoutput;pd:tprocdef);
  1222. var
  1223. procendlabel : tasmlabel;
  1224. mangled_length : longint;
  1225. p : pchar;
  1226. hs : string;
  1227. begin
  1228. if assigned(pd.procstarttai) then
  1229. begin
  1230. append_entry(DW_TAG_subprogram,true,
  1231. [DW_AT_name,DW_FORM_string,pd.procsym.name+#0
  1232. { data continues below }
  1233. { problem: base reg isn't known here
  1234. DW_AT_frame_base,DW_FORM_block1,1
  1235. }
  1236. ]);
  1237. { append block data }
  1238. { asmlist[al_dwarf_info].concat(tai_const.create_8bit(dwarf_reg(pd.))); }
  1239. if not(is_void(tprocdef(pd).rettype.def)) then
  1240. append_labelentry_ref(DW_AT_type,def_dwarf_lab(tprocdef(pd).rettype.def));
  1241. { mark end of procedure }
  1242. objectlibrary.getlabel(procendlabel,alt_dbgtype);
  1243. asmlist[al_procedures].insertbefore(tai_label.create(procendlabel),pd.procendtai);
  1244. append_labelentry(DW_AT_low_pc,objectlibrary.newasmsymbol(pd.mangledname,AB_LOCAL,AT_DATA));
  1245. append_labelentry(DW_AT_high_pc,procendlabel);
  1246. {
  1247. if assigned(pd.funcretsym) and
  1248. (tabstractnormalvarsym(pd.funcretsym).refs>0) then
  1249. begin
  1250. if tabstractnormalvarsym(pd.funcretsym).localloc.loc=LOC_REFERENCE then
  1251. begin
  1252. {$warning Need to add gdb support for ret in param register calling}
  1253. if paramanager.ret_in_param(pd.rettype.def,pd.proccalloption) then
  1254. hs:='X*'
  1255. else
  1256. hs:='X';
  1257. templist.concat(Tai_stab.create(stab_stabs,strpnew(
  1258. '"'+pd.procsym.name+':'+hs+def_stab_number(pd.rettype.def)+'",'+
  1259. tostr(N_tsym)+',0,0,'+tostr(tabstractnormalvarsym(pd.funcretsym).localloc.reference.offset))));
  1260. if (m_result in aktmodeswitches) then
  1261. templist.concat(Tai_stab.create(stab_stabs,strpnew(
  1262. '"RESULT:'+hs+def_stab_number(pd.rettype.def)+'",'+
  1263. tostr(N_tsym)+',0,0,'+tostr(tabstractnormalvarsym(pd.funcretsym).localloc.reference.offset))));
  1264. end;
  1265. end;
  1266. }
  1267. finish_entry;
  1268. {
  1269. { para types }
  1270. write_def_stabstr(templist,pd);
  1271. }
  1272. if assigned(pd.parast) then
  1273. write_symtable_syms(list,pd.parast);
  1274. { local type defs and vars should not be written
  1275. inside the main proc stab }
  1276. if assigned(pd.localst) and
  1277. (pd.localst.symtabletype=localsymtable) then
  1278. write_symtable_syms(list,pd.localst);
  1279. finish_children;
  1280. end;
  1281. end;
  1282. procedure TDebugInfoDwarf.insertsym(list:taasmoutput;sym:tsym);
  1283. procedure append_varsym(sym:tabstractnormalvarsym);
  1284. var
  1285. templist : taasmoutput;
  1286. blocksize : longint;
  1287. regidx : longint;
  1288. tag : tdwarf_tag;
  1289. begin
  1290. { external symbols can't be resolved at link time, so we
  1291. can't generate stabs for them
  1292. not sure if this applies to dwarf as well (FK)
  1293. }
  1294. if vo_is_external in sym.varoptions then
  1295. exit;
  1296. { There is no space allocated for not referenced locals }
  1297. if (sym.owner.symtabletype=localsymtable) and (sym.refs=0) then
  1298. exit;
  1299. templist:=taasmoutput.create;
  1300. case sym.localloc.loc of
  1301. LOC_REGISTER,
  1302. LOC_CREGISTER,
  1303. LOC_MMREGISTER,
  1304. LOC_CMMREGISTER,
  1305. LOC_FPUREGISTER,
  1306. LOC_CFPUREGISTER :
  1307. begin
  1308. regidx:=findreg_by_number(sym.localloc.register);
  1309. templist.concat(tai_const.create_8bit(ord(DW_OP_regx)));
  1310. templist.concat(tai_const.create_uleb128bit(regdwarf_table[regidx]));
  1311. blocksize:=Lengthuleb128(regdwarf_table[regidx])+1;
  1312. end;
  1313. else
  1314. begin
  1315. case sym.typ of
  1316. globalvarsym:
  1317. begin
  1318. if (vo_is_thread_var in sym.varoptions) then
  1319. begin
  1320. {$warning !!! FIXME: dwarf for thread vars !!!}
  1321. end
  1322. else
  1323. begin
  1324. templist.concat(tai_const.create_8bit(3));
  1325. templist.concat(tai_const.createname(sym.mangledname,AT_DATA,0));
  1326. blocksize:=1+sizeof(aword);
  1327. end;
  1328. end;
  1329. paravarsym,
  1330. localvarsym:
  1331. begin
  1332. regidx:=findreg_by_number(sym.localloc.reference.base);
  1333. templist.concat(tai_const.create_8bit(ord(DW_OP_breg0)+regdwarf_table[regidx]));
  1334. templist.concat(tai_const.create_sleb128bit(sym.localloc.reference.offset));
  1335. blocksize:=Lengthsleb128(sym.localloc.reference.offset)+1;
  1336. end
  1337. else
  1338. internalerror(200601288);
  1339. end;
  1340. end;
  1341. end;
  1342. if sym.typ=paravarsym then
  1343. tag:=DW_TAG_formal_parameter
  1344. else
  1345. tag:=DW_TAG_variable;
  1346. append_entry(tag,false,[
  1347. DW_AT_name,DW_FORM_string,sym.name+#0,
  1348. {
  1349. DW_AT_decl_file,DW_FORM_data1,0,
  1350. DW_AT_decl_line,DW_FORM_data1,
  1351. }
  1352. DW_AT_external,DW_FORM_flag,true,
  1353. { data continues below }
  1354. DW_AT_location,DW_FORM_block1,blocksize
  1355. ]);
  1356. { append block data }
  1357. asmlist[al_dwarf_info].concatlist(templist);
  1358. append_labelentry_ref(DW_AT_type,def_dwarf_lab(sym.vartype.def));
  1359. templist.free;
  1360. finish_entry;
  1361. end;
  1362. procedure paravarsym_stabstr(sym:tparavarsym);
  1363. begin
  1364. {
  1365. result:=nil;
  1366. { set loc to LOC_REFERENCE to get somewhat usable debugging info for -Or }
  1367. { while stabs aren't adapted for regvars yet }
  1368. if (vo_is_self in sym.varoptions) then
  1369. begin
  1370. case sym.localloc.loc of
  1371. LOC_REGISTER,
  1372. LOC_CREGISTER:
  1373. regidx:=findreg_by_number(sym.localloc.register);
  1374. LOC_REFERENCE: ;
  1375. else
  1376. internalerror(2003091815);
  1377. end;
  1378. if (po_classmethod in tabstractprocdef(sym.owner.defowner).procoptions) or
  1379. (po_staticmethod in tabstractprocdef(sym.owner.defowner).procoptions) then
  1380. begin
  1381. if (sym.localloc.loc=LOC_REFERENCE) then
  1382. result:=sym_stabstr_evaluate(sym,'"pvmt:p$1",${N_TSYM},0,0,$2',
  1383. [def_stab_number(pvmttype.def),tostr(sym.localloc.reference.offset)]);
  1384. (* else
  1385. result:=sym_stabstr_evaluate(sym,'"pvmt:r$1",${N_RSYM},0,0,$2',
  1386. [def_stab_number(pvmttype.def),tostr(regstabs_table[regidx])]) *)
  1387. end
  1388. else
  1389. begin
  1390. if not(is_class(tprocdef(sym.owner.defowner)._class)) then
  1391. c:='v'
  1392. else
  1393. c:='p';
  1394. if (sym.localloc.loc=LOC_REFERENCE) then
  1395. result:=sym_stabstr_evaluate(sym,'"$$t:$1",${N_TSYM},0,0,$2',
  1396. [c+def_stab_number(tprocdef(sym.owner.defowner)._class),tostr(sym.localloc.reference.offset)]);
  1397. (* else
  1398. result:=sym_stabstr_evaluate(sym,'"$$t:r$1",${N_RSYM},0,0,$2',
  1399. [c+def_stab_number(tprocdef(sym.owner.defowner)._class),tostr(regstabs_table[regidx])]); *)
  1400. end;
  1401. end
  1402. else
  1403. begin
  1404. st:=def_stab_number(sym.vartype.def);
  1405. if paramanager.push_addr_param(sym.varspez,sym.vartype.def,tprocdef(sym.owner.defowner).proccalloption) and
  1406. not(vo_has_local_copy in sym.varoptions) and
  1407. not is_open_string(sym.vartype.def) then
  1408. st := 'v'+st { should be 'i' but 'i' doesn't work }
  1409. else
  1410. st := 'p'+st;
  1411. case sym.localloc.loc of
  1412. LOC_REGISTER,
  1413. LOC_CREGISTER,
  1414. LOC_MMREGISTER,
  1415. LOC_CMMREGISTER,
  1416. LOC_FPUREGISTER,
  1417. LOC_CFPUREGISTER :
  1418. begin
  1419. regidx:=findreg_by_number(sym.localloc.register);
  1420. { "eax", "ecx", "edx", "ebx", "esp", "ebp", "esi", "edi", "eip", "ps", "cs", "ss", "ds", "es", "fs", "gs", }
  1421. { this is the register order for GDB}
  1422. if regidx<>0 then
  1423. result:=sym_stabstr_evaluate(sym,'"${name}:r$1",${N_RSYM},0,${line},$2',[st,tostr(longint(regstabs_table[regidx]))]);
  1424. end;
  1425. LOC_REFERENCE :
  1426. { offset to ebp => will not work if the framepointer is esp
  1427. so some optimizing will make things harder to debug }
  1428. result:=sym_stabstr_evaluate(sym,'"${name}:$1",${N_TSYM},0,${line},$2',[st,tostr(sym.localloc.reference.offset)])
  1429. else
  1430. internalerror(2003091814);
  1431. end;
  1432. end;
  1433. }
  1434. end;
  1435. procedure append_constsym(sym:tconstsym);
  1436. begin
  1437. append_entry(DW_TAG_constant,false,[
  1438. DW_AT_name,DW_FORM_string,sym.name+#0
  1439. ]);
  1440. { for string constants, consttype isn't set because they have no real type }
  1441. if not(sym.consttyp in [conststring,constresourcestring]) then
  1442. append_labelentry_ref(DW_AT_type,def_dwarf_lab(sym.consttype.def));
  1443. asmlist[al_dwarf_abbrev].concat(tai_const.create_uleb128bit(ord(DW_AT_const_value)));
  1444. case sym.consttyp of
  1445. conststring:
  1446. begin
  1447. asmlist[al_dwarf_abbrev].concat(tai_const.create_uleb128bit(ord(DW_FORM_string)));
  1448. asmlist[al_dwarf_info].concat(tai_string.create(strpas(pchar(sym.value.valueptr))));
  1449. asmlist[al_dwarf_info].concat(tai_const.create_8bit(0));
  1450. end;
  1451. constset,
  1452. constwstring,
  1453. constguid,
  1454. constresourcestring:
  1455. { ignore for now }
  1456. ;
  1457. constord:
  1458. begin
  1459. asmlist[al_dwarf_abbrev].concat(tai_const.create_uleb128bit(ord(DW_FORM_sdata)));
  1460. asmlist[al_dwarf_info].concat(tai_const.create_sleb128bit(sym.value.valueord));
  1461. end;
  1462. constnil:
  1463. begin
  1464. {$ifdef cpu64bit}
  1465. asmlist[al_dwarf_abbrev].concat(tai_const.create_uleb128bit(ord(DW_FORM_data8)));
  1466. asmlist[al_dwarf_info].concat(tai_const.create_64bit(0));
  1467. {$else cpu64bit}
  1468. asmlist[al_dwarf_abbrev].concat(tai_const.create_uleb128bit(ord(DW_FORM_data4)));
  1469. asmlist[al_dwarf_info].concat(tai_const.create_32bit(0));
  1470. {$endif cpu64bit}
  1471. end;
  1472. constpointer:
  1473. begin
  1474. {$ifdef cpu64bit}
  1475. asmlist[al_dwarf_abbrev].concat(tai_const.create_uleb128bit(ord(DW_FORM_data8)));
  1476. asmlist[al_dwarf_info].concat(tai_const.create_64bit(sym.value.valueordptr));
  1477. {$else cpu64bit}
  1478. asmlist[al_dwarf_abbrev].concat(tai_const.create_uleb128bit(ord(DW_FORM_data4)));
  1479. asmlist[al_dwarf_info].concat(tai_const.create_32bit(sym.value.valueordptr));
  1480. {$endif cpu64bit}
  1481. end;
  1482. constreal:
  1483. begin
  1484. asmlist[al_dwarf_abbrev].concat(tai_const.create_uleb128bit(ord(DW_FORM_block1)));
  1485. case tfloatdef(sym.consttype.def).typ of
  1486. s32real:
  1487. begin
  1488. asmlist[al_dwarf_info].concat(tai_const.create_8bit(4));
  1489. asmlist[al_dwarf_info].concat(tai_real_32bit.create(psingle(sym.value.valueptr)^));
  1490. end;
  1491. s64comp,
  1492. s64currency,
  1493. s64real:
  1494. begin
  1495. asmlist[al_dwarf_info].concat(tai_const.create_8bit(8));
  1496. asmlist[al_dwarf_info].concat(tai_real_64bit.create(pdouble(sym.value.valueptr)^));
  1497. end;
  1498. s80real:
  1499. begin
  1500. asmlist[al_dwarf_info].concat(tai_const.create_8bit(10));
  1501. asmlist[al_dwarf_info].concat(tai_real_80bit.create(pextended(sym.value.valueptr)^));
  1502. end;
  1503. else
  1504. internalerror(200601291);
  1505. end;
  1506. end;
  1507. else
  1508. internalerror(200601292);
  1509. end;
  1510. finish_entry;
  1511. end;
  1512. procedure append_procsym(sym:tprocsym);
  1513. var
  1514. i : longint;
  1515. begin
  1516. for i:=1 to sym.procdef_count do
  1517. append_procdef(list,sym.procdef[i]);
  1518. end;
  1519. procedure append_absolutesym(sym:tabsolutevarsym);
  1520. var
  1521. templist : taasmoutput;
  1522. blocksize : longint;
  1523. symlist : psymlistitem;
  1524. begin
  1525. templist:=taasmoutput.create;
  1526. case tabsolutevarsym(sym).abstyp of
  1527. toaddr :
  1528. begin
  1529. {$ifdef i386}
  1530. { in theory, we could write a DW_AT_segment entry here for sym.absseg,
  1531. however I doubt that gdb supports this (FK) }
  1532. {$endif i386}
  1533. templist.concat(tai_const.create_8bit(3));
  1534. templist.concat(tai_const.create_aint(sym.addroffset));
  1535. blocksize:=1+sizeof(aword);
  1536. end;
  1537. toasm :
  1538. begin
  1539. templist.concat(tai_const.create_8bit(3));
  1540. templist.concat(tai_const.createname(sym.mangledname,AT_DATA,0));
  1541. blocksize:=1+sizeof(aword);
  1542. end;
  1543. tovar:
  1544. begin
  1545. symlist:=tabsolutevarsym(sym).ref.firstsym;
  1546. { can we insert the symbol? }
  1547. if assigned(symlist) and
  1548. (symlist^.sltype=sl_load) then
  1549. insertsym(list,symlist^.sym);
  1550. templist.free;
  1551. exit;
  1552. end;
  1553. end;
  1554. append_entry(DW_TAG_variable,false,[
  1555. DW_AT_name,DW_FORM_string,sym.name+#0,
  1556. {
  1557. DW_AT_decl_file,DW_FORM_data1,0,
  1558. DW_AT_decl_line,DW_FORM_data1,
  1559. }
  1560. DW_AT_external,DW_FORM_flag,true,
  1561. { data continues below }
  1562. DW_AT_location,DW_FORM_block1,blocksize
  1563. ]);
  1564. { append block data }
  1565. asmlist[al_dwarf_info].concatlist(templist);
  1566. append_labelentry_ref(DW_AT_type,def_dwarf_lab(sym.vartype.def));
  1567. templist.free;
  1568. finish_entry;
  1569. end;
  1570. begin
  1571. case sym.typ of
  1572. globalvarsym :
  1573. append_varsym(tglobalvarsym(sym));
  1574. unitsym:
  1575. { for now, we ignore unit symbols }
  1576. ;
  1577. procsym :
  1578. append_procsym(tprocsym(sym));
  1579. labelsym :
  1580. { ignore label syms for now, the problem is that a label sym
  1581. can have more than one label associated e.g. in case of
  1582. an inline procedure expansion }
  1583. ;
  1584. localvarsym :
  1585. append_varsym(tlocalvarsym(sym));
  1586. paravarsym :
  1587. append_varsym(tparavarsym(sym));
  1588. typedconstsym :
  1589. begin
  1590. append_entry(DW_TAG_variable,false,[
  1591. DW_AT_name,DW_FORM_string,sym.name+#0,
  1592. {
  1593. DW_AT_decl_file,DW_FORM_data1,0,
  1594. DW_AT_decl_line,DW_FORM_data1,
  1595. }
  1596. DW_AT_external,DW_FORM_flag,true,
  1597. { data continues below }
  1598. DW_AT_location,DW_FORM_block1,1+sizeof(aword)
  1599. ]);
  1600. { append block data }
  1601. asmlist[al_dwarf_info].concat(tai_const.create_8bit(3));
  1602. asmlist[al_dwarf_info].concat(tai_const.createname(sym.mangledname,AT_DATA,0));
  1603. append_labelentry_ref(DW_AT_type,def_dwarf_lab(ttypedconstsym(sym).typedconsttype.def));
  1604. finish_entry;
  1605. end;
  1606. constsym :
  1607. append_constsym(tconstsym(sym));
  1608. typesym :
  1609. begin
  1610. append_entry(DW_TAG_typedef,false,[
  1611. DW_AT_name,DW_FORM_string,sym.name+#0
  1612. ]);
  1613. append_labelentry_ref(DW_AT_type,def_dwarf_lab(ttypesym(sym).restype.def));
  1614. finish_entry;
  1615. end;
  1616. enumsym :
  1617. { ignore enum syms, they are written by the owner }
  1618. ;
  1619. rttisym :
  1620. { ignore rtti syms, they are only of internal use }
  1621. ;
  1622. syssym :
  1623. { ignore sys syms, they are only of internal use }
  1624. ;
  1625. absolutevarsym :
  1626. append_absolutesym(tabsolutevarsym(sym));
  1627. propertysym :
  1628. { ignored for now }
  1629. ;
  1630. else
  1631. begin
  1632. writeln(ord(sym.typ));
  1633. internalerror(200601242);
  1634. end;
  1635. end;
  1636. {
  1637. { For object types write also the symtable entries }
  1638. if (sym.typ=typesym) and (ttypesym(sym).restype.def.deftype=objectdef) then
  1639. write_symtable_syms(list,tobjectdef(ttypesym(sym).restype.def).symtable);
  1640. sym.isstabwritten:=true;
  1641. }
  1642. end;
  1643. procedure TDebugInfoDwarf.write_symtable_syms(list:taasmoutput;st:tsymtable);
  1644. var
  1645. p : tsym;
  1646. begin
  1647. case st.symtabletype of
  1648. staticsymtable :
  1649. list.concat(tai_comment.Create(strpnew('Syms - Begin Staticsymtable')));
  1650. globalsymtable :
  1651. list.concat(tai_comment.Create(strpnew('Syms - Begin unit '+st.name^+' has index '+tostr(st.moduleid))));
  1652. end;
  1653. p:=tsym(st.symindex.first);
  1654. while assigned(p) do
  1655. begin
  1656. if (not p.isstabwritten) then
  1657. insertsym(list,p);
  1658. p:=tsym(p.indexnext);
  1659. end;
  1660. case st.symtabletype of
  1661. staticsymtable :
  1662. list.concat(tai_comment.Create(strpnew('Syms - End Staticsymtable')));
  1663. globalsymtable :
  1664. list.concat(tai_comment.Create(strpnew('Syms - End unit '+st.name^+' has index '+tostr(st.moduleid))));
  1665. end;
  1666. end;
  1667. procedure TDebugInfoDwarf.insertmoduleinfo;
  1668. var
  1669. templist : taasmoutput;
  1670. begin
  1671. { insert .Ltext0 label }
  1672. templist:=taasmoutput.create;
  1673. new_section(templist,sec_code,'',0);
  1674. templist.concat(tai_symbol.createname('.Ltext0',AT_DATA,0));
  1675. asmlist[al_start].insertlist(templist);
  1676. templist.free;
  1677. { insert .Letext0 label }
  1678. templist:=taasmoutput.create;
  1679. new_section(templist,sec_code,'',0);
  1680. templist.concat(tai_symbol.createname('.Letext0',AT_DATA,0));
  1681. asmlist[al_end].insertlist(templist);
  1682. templist.free;
  1683. { insert .Ldebug_abbrev0 label }
  1684. templist:=taasmoutput.create;
  1685. new_section(templist,sec_debug_abbrev,'',0);
  1686. templist.concat(tai_symbol.createname('.Ldebug_abbrev0',AT_DATA,0));
  1687. asmlist[al_start].insertlist(templist);
  1688. templist.free;
  1689. { insert .Ldebug_line0 label }
  1690. templist:=taasmoutput.create;
  1691. new_section(templist,sec_debug_line,'',0);
  1692. templist.concat(tai_symbol.createname('.Ldebug_line0',AT_DATA,0));
  1693. asmlist[al_start].insertlist(templist);
  1694. templist.free;
  1695. end;
  1696. procedure TDebugInfoDwarf.inserttypeinfo;
  1697. var
  1698. storefilepos : tfileposinfo;
  1699. lenstartlabel : tasmlabel;
  1700. i : longint;
  1701. begin
  1702. storefilepos:=aktfilepos;
  1703. aktfilepos:=current_module.mainfilepos;
  1704. currabbrevnumber:=0;
  1705. writing_def_dwarf:=false;
  1706. nextdefnumber:=0;
  1707. defnumberlist:=tlist.create;
  1708. vardatadef:=search_system_type('TVARDATA').restype.def;
  1709. { not exported (FK)
  1710. filerecdef:=gettypedef('FILEREC');
  1711. textrecdef:=gettypedef('TEXTREC');
  1712. }
  1713. { write start labels }
  1714. asmlist[al_dwarf_info].concat(tai_section.create(sec_debug_info,'',0));
  1715. asmlist[al_dwarf_info].concat(tai_symbol.createname('.Ldebug_info0',AT_DATA,0));
  1716. { start abbrev section }
  1717. new_section(asmlist[al_dwarf_abbrev],sec_debug_abbrev,'',0);
  1718. { debug info header }
  1719. objectlibrary.getlabel(lenstartlabel,alt_dbgfile);
  1720. { size }
  1721. asmlist[al_dwarf_info].concat(tai_const.create_rel_sym(aitconst_ptr,
  1722. lenstartlabel,tasmsymbol.create('.Ledebug_info0',AB_COMMON,AT_DATA)));
  1723. asmlist[al_dwarf_info].concat(tai_label.create(lenstartlabel));
  1724. { version }
  1725. asmlist[al_dwarf_info].concat(tai_const.create_16bit(2));
  1726. { abbrev table }
  1727. asmlist[al_dwarf_info].concat(tai_const.createname('.Ldebug_abbrev0',AT_DATA,0));
  1728. { address size }
  1729. asmlist[al_dwarf_info].concat(tai_const.create_8bit(sizeof(aint)));
  1730. append_entry(DW_TAG_compile_unit,true,[
  1731. DW_AT_name,DW_FORM_string,FixFileName(current_module.sourcefiles.get_file(1).name^)+#0,
  1732. DW_AT_producer,DW_FORM_string,'Free Pascal '+full_version_string+' '+date_string+#0,
  1733. DW_AT_comp_dir,DW_FORM_string,BsToSlash(FixPath(current_module.sourcefiles.get_file(1).path^,false))+#0,
  1734. DW_AT_language,DW_FORM_data1,DW_LANG_Pascal83,
  1735. DW_AT_identifier_case,DW_FORM_data1,DW_ID_case_insensitive]);
  1736. { reference to line info section }
  1737. append_labelentry_data(DW_AT_stmt_list,objectlibrary.newasmsymbol('.Ldebug_line0',AB_LOCAL,AT_DATA));
  1738. append_labelentry(DW_AT_low_pc,objectlibrary.newasmsymbol('.Ltext0',AB_LOCAL,AT_DATA));
  1739. append_labelentry(DW_AT_high_pc,objectlibrary.newasmsymbol('.Letext0',AB_LOCAL,AT_DATA));
  1740. finish_entry;
  1741. { first write all global/local symbols. This will flag all required tdefs }
  1742. if assigned(current_module.globalsymtable) then
  1743. write_symtable_syms(asmlist[al_dwarf_info],current_module.globalsymtable);
  1744. if assigned(current_module.localsymtable) then
  1745. write_symtable_syms(asmlist[al_dwarf_info],current_module.localsymtable);
  1746. { reset unit type info flag }
  1747. reset_unit_type_info;
  1748. { write used types from the used units }
  1749. write_used_unit_type_info(asmlist[al_dwarf_info],current_module);
  1750. { last write the types from this unit }
  1751. if assigned(current_module.globalsymtable) then
  1752. write_symtable_defs(asmlist[al_dwarf_info],current_module.globalsymtable);
  1753. if assigned(current_module.localsymtable) then
  1754. write_symtable_defs(asmlist[al_dwarf_info],current_module.localsymtable);
  1755. { close compilation unit entry }
  1756. finish_children;
  1757. { end of debug info table }
  1758. asmlist[al_dwarf_info].concat(tai_const.create_8bit(0));
  1759. asmlist[al_dwarf_info].concat(tai_symbol.createname('.Ledebug_info0',AT_DATA,0));
  1760. { reset all def labels }
  1761. for i:=0 to defnumberlist.count-1 do
  1762. begin
  1763. if assigned(defnumberlist[i]) then
  1764. begin
  1765. tdef(defnumberlist[i]).dwarf_lab:=nil;
  1766. tdef(defnumberlist[i]).dbg_state:=dbg_state_unused;
  1767. end;
  1768. end;
  1769. defnumberlist.free;
  1770. defnumberlist:=nil;
  1771. aktfilepos:=storefilepos;
  1772. end;
  1773. procedure TDebugInfoDwarf.referencesections(list:taasmoutput);
  1774. begin
  1775. end;
  1776. procedure TDebugInfoDwarf.insertlineinfo(list:taasmoutput);
  1777. var
  1778. currfileinfo,
  1779. lastfileinfo : tfileposinfo;
  1780. currfuncname : pstring;
  1781. currsectype : tasmsectiontype;
  1782. hlabel : tasmlabel;
  1783. hp : tai;
  1784. infile : tinputfile;
  1785. current_file : tai_file;
  1786. begin
  1787. FillChar(lastfileinfo,sizeof(lastfileinfo),0);
  1788. currfuncname:=nil;
  1789. currsectype:=sec_code;
  1790. hp:=Tai(list.first);
  1791. while assigned(hp) do
  1792. begin
  1793. case hp.typ of
  1794. ait_section :
  1795. currsectype:=tai_section(hp).sectype;
  1796. ait_function_name :
  1797. currfuncname:=tai_function_name(hp).funcname;
  1798. ait_force_line :
  1799. lastfileinfo.line:=-1;
  1800. end;
  1801. if (currsectype=sec_code) and
  1802. (hp.typ=ait_instruction) then
  1803. begin
  1804. currfileinfo:=tailineinfo(hp).fileinfo;
  1805. { file changed ? (must be before line info) }
  1806. if (currfileinfo.fileindex<>0) and
  1807. (lastfileinfo.fileindex<>currfileinfo.fileindex) then
  1808. begin
  1809. infile:=current_module.sourcefiles.get_file(currfileinfo.fileindex);
  1810. if assigned(infile) then
  1811. begin
  1812. if (infile.path^<>'') then
  1813. begin
  1814. current_file:=tai_file.create(BsToSlash(FixPath(infile.path^,false)+FixFileName(infile.name^)));
  1815. list.insertbefore(current_file,hp)
  1816. end
  1817. else
  1818. begin
  1819. current_file:=tai_file.create(FixFileName(infile.name^));
  1820. list.insertbefore(current_file,hp);
  1821. end;
  1822. { force new line info }
  1823. lastfileinfo.line:=-1;
  1824. end;
  1825. end;
  1826. { line changed ? }
  1827. if (lastfileinfo.line<>currfileinfo.line) and (currfileinfo.line<>0) then
  1828. list.insertbefore(tai_loc.create(
  1829. current_file,currfileinfo.line,currfileinfo.column),hp);
  1830. lastfileinfo:=currfileinfo;
  1831. end;
  1832. hp:=tai(hp.next);
  1833. end;
  1834. end;
  1835. const
  1836. dbg_dwarf_info : tdbginfo =
  1837. (
  1838. id : dbg_dwarf;
  1839. idtxt : 'DWARF';
  1840. );
  1841. initialization
  1842. RegisterDebugInfo(dbg_dwarf_info,TDebugInfoDwarf);
  1843. end.