dbgdwarf.pas 75 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996
  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_special_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. { string data 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. finish_children;
  906. end;
  907. st_longstring:
  908. begin
  909. {
  910. charst:=def_stab_number(cchartype.def);
  911. bytest:=def_stab_number(u8inttype.def);
  912. longst:=def_stab_number(u32inttype.def);
  913. result:=def_stabstr_evaluate(def,'s$1length:$2,0,32;dummy:$6,32,8;st:ar$2;1;$3;$4,40,$5;;',
  914. [tostr(def.len+5),longst,tostr(def.len),charst,tostr(def.len*8),bytest]);
  915. }
  916. end;
  917. st_ansistring:
  918. begin
  919. { looks like a pchar }
  920. append_entry(DW_TAG_pointer_type,false,[]);
  921. append_labelentry_ref(DW_AT_type,def_dwarf_lab(cchartype.def));
  922. finish_entry;
  923. end;
  924. st_widestring:
  925. begin
  926. { looks like a pwidechar }
  927. append_entry(DW_TAG_pointer_type,false,[]);
  928. append_labelentry_ref(DW_AT_type,def_dwarf_lab(cwidechartype.def));
  929. finish_entry;
  930. end;
  931. end;
  932. end;
  933. procedure append_dwarftag_procvardef(def:tprocvardef);
  934. procedure doappend;
  935. var
  936. i : longint;
  937. begin
  938. if assigned(def.typesym) then
  939. append_entry(DW_TAG_subroutine_type,true,[
  940. DW_AT_name,DW_FORM_string,def.typesym.name+#0,
  941. DW_AT_prototyped,DW_FORM_flag,true
  942. ])
  943. else
  944. append_entry(DW_TAG_subroutine_type,true,[
  945. DW_AT_prototyped,DW_FORM_flag,true
  946. ]);
  947. if not(is_void(tprocvardef(def).rettype.def)) then
  948. append_labelentry_ref(DW_AT_type,def_dwarf_lab(tprocvardef(def).rettype.def));
  949. finish_entry;
  950. { write parameters }
  951. for i:=0 to def.paras.count-1 do
  952. begin
  953. append_entry(DW_TAG_formal_parameter,false,[
  954. DW_AT_name,DW_FORM_string,tparavarsym(def.paras[i]).name+#0
  955. ]);
  956. append_labelentry_ref(DW_AT_type,def_dwarf_lab(tparavarsym(def.paras[i]).vartype.def));
  957. finish_entry;
  958. end;
  959. finish_children;
  960. end;
  961. var
  962. proc : tasmlabel;
  963. begin
  964. if def.is_methodpointer then
  965. begin
  966. { create a structure with two elements }
  967. objectlibrary.getdatalabel(proc);
  968. append_entry(DW_TAG_structure_type,true,[
  969. DW_AT_byte_size,DW_FORM_data1,2*sizeof(aint)
  970. ]);
  971. finish_entry;
  972. { proc entry }
  973. append_entry(DW_TAG_member,false,[
  974. DW_AT_name,DW_FORM_string,'Proc'#0,
  975. DW_AT_data_member_location,DW_FORM_block1,1+lengthuleb128(0)
  976. ]);
  977. asmlist[al_dwarf_info].concat(tai_const.create_8bit(ord(DW_OP_plus_uconst)));
  978. asmlist[al_dwarf_info].concat(tai_const.create_uleb128bit(0));
  979. append_labelentry_ref(DW_AT_type,proc);
  980. finish_entry;
  981. { self entry }
  982. append_entry(DW_TAG_member,false,[
  983. DW_AT_name,DW_FORM_string,'Self'#0,
  984. DW_AT_data_member_location,DW_FORM_block1,1+lengthuleb128(sizeof(aint))
  985. ]);
  986. asmlist[al_dwarf_info].concat(tai_const.create_8bit(ord(DW_OP_plus_uconst)));
  987. asmlist[al_dwarf_info].concat(tai_const.create_uleb128bit(sizeof(aint)));
  988. append_labelentry_ref(DW_AT_type,def_dwarf_lab(class_tobject));
  989. finish_entry;
  990. finish_children;
  991. asmlist[al_dwarf_info].concat(tai_symbol.create(proc,0));
  992. doappend;
  993. end
  994. else
  995. doappend;
  996. end;
  997. begin
  998. list.concat(tai_symbol.create(def_dwarf_lab(def),0));
  999. case def.deftype of
  1000. stringdef :
  1001. append_dwarftag_stringdef(tstringdef(def));
  1002. enumdef :
  1003. append_dwarftag_enumdef(tenumdef(def));
  1004. orddef :
  1005. append_dwarftag_orddef(torddef(def));
  1006. pointerdef :
  1007. append_dwarftag_pointerdef(tpointerdef(def));
  1008. floatdef :
  1009. append_dwarftag_floatdef(tfloatdef(def));
  1010. filedef :
  1011. begin
  1012. { gdb 6.4 doesn't support files so far so we use some fake recorddef
  1013. { file recs. are less than 1k so using data2 is enough }
  1014. if assigned(def.typesym) then
  1015. append_entry(DW_TAG_file_type,false,[
  1016. DW_AT_name,DW_FORM_string,def.typesym.name+#0,
  1017. DW_AT_byte_size,DW_FORM_data2,def.size
  1018. ])
  1019. else
  1020. append_entry(DW_TAG_file_type,false,[
  1021. DW_AT_byte_size,DW_FORM_data2,def.size
  1022. ]);
  1023. if tfiledef(def).filetyp=ft_typed then
  1024. append_labelentry_ref(DW_AT_type,def_dwarf_lab(tfiledef(def).typedfiletype.def));
  1025. }
  1026. if assigned(def.typesym) then
  1027. append_entry(DW_TAG_structure_type,false,[
  1028. DW_AT_name,DW_FORM_string,def.typesym.name+#0,
  1029. DW_AT_byte_size,DW_FORM_udata,def.size
  1030. ])
  1031. else
  1032. append_entry(DW_TAG_structure_type,false,[
  1033. DW_AT_byte_size,DW_FORM_udata,def.size
  1034. ]);
  1035. finish_entry;
  1036. end;
  1037. recorddef :
  1038. append_dwarftag_recorddef(trecorddef(def));
  1039. variantdef :
  1040. { variants aren't known to dwarf but writting tvardata should be enough }
  1041. append_dwarftag_recorddef(trecorddef(vardatadef));
  1042. classrefdef :
  1043. append_dwarftag_pointerdef(tpointerdef(pvmttype.def));
  1044. setdef :
  1045. begin
  1046. { at least gdb up to 6.4 doesn't support sets in dwarf, there is a patch available to fix this:
  1047. http://sources.redhat.com/ml/gdb-patches/2005-05/msg00278.html (FK)
  1048. if assigned(def.typesym) then
  1049. append_entry(DW_TAG_set_type,false,[
  1050. DW_AT_name,DW_FORM_string,def.typesym.name+#0,
  1051. DW_AT_byte_size,DW_FORM_data2,def.size
  1052. ])
  1053. else
  1054. append_entry(DW_TAG_set_type,false,[
  1055. DW_AT_byte_size,DW_FORM_data2,def.size
  1056. ]);
  1057. append_labelentry_ref(DW_AT_type,def_dwarf_lab(tsetdef(def).elementtype.def));
  1058. finish_entry;
  1059. }
  1060. if assigned(def.typesym) then
  1061. append_entry(DW_TAG_base_type,false,[
  1062. DW_AT_name,DW_FORM_string,def.typesym.name+#0,
  1063. DW_AT_encoding,DW_FORM_data1,DW_ATE_unsigned,
  1064. DW_AT_byte_size,DW_FORM_data2,def.size
  1065. ])
  1066. else
  1067. append_entry(DW_TAG_base_type,false,[
  1068. DW_AT_encoding,DW_FORM_data1,DW_ATE_unsigned,
  1069. DW_AT_byte_size,DW_FORM_data2,def.size
  1070. ]);
  1071. finish_entry;
  1072. end;
  1073. formaldef :
  1074. begin
  1075. { gdb 6.4 doesn't support DW_TAG_unspecified_type so we
  1076. replace it with a unsigned type with size 0 (FK)
  1077. }
  1078. append_entry(DW_TAG_base_type,false,[
  1079. DW_AT_name,DW_FORM_string,'FormalDef'#0,
  1080. DW_AT_encoding,DW_FORM_data1,DW_ATE_unsigned,
  1081. DW_AT_byte_size,DW_FORM_data1,0
  1082. ]);
  1083. finish_entry;
  1084. end;
  1085. arraydef :
  1086. append_dwarftag_arraydef(tarraydef(def));
  1087. procvardef :
  1088. append_dwarftag_procvardef(tprocvardef(def));
  1089. objectdef :
  1090. append_dwarftag_objectdef(tobjectdef(def));
  1091. undefineddef :
  1092. begin
  1093. { gdb 6.4 doesn't support DW_TAG_unspecified_type so we
  1094. replace it with a unsigned type with size 0 (FK)
  1095. }
  1096. append_entry(DW_TAG_base_type,false,[
  1097. DW_AT_name,DW_FORM_string,'FormalDef'#0,
  1098. DW_AT_encoding,DW_FORM_data1,DW_ATE_unsigned,
  1099. DW_AT_byte_size,DW_FORM_data1,0
  1100. ]);
  1101. finish_entry;
  1102. end;
  1103. else
  1104. internalerror(200601281);
  1105. end;
  1106. end;
  1107. procedure TDebugInfoDwarf.insertdef(list:taasmoutput;def:tdef);
  1108. var
  1109. anc : tobjectdef;
  1110. oldtypesym : tsym;
  1111. i : longint;
  1112. begin
  1113. if (def.dbg_state in [dbg_state_writing,dbg_state_written]) then
  1114. exit;
  1115. { never write generic template defs }
  1116. if df_generic in def.defoptions then
  1117. begin
  1118. def.dbg_state:=dbg_state_written;
  1119. exit;
  1120. end;
  1121. { to avoid infinite loops }
  1122. def.dbg_state := dbg_state_writing;
  1123. { write dependencies first }
  1124. case def.deftype of
  1125. stringdef :
  1126. begin
  1127. if tstringdef(def).string_typ=st_widestring then
  1128. insertdef(list,cwidechartype.def)
  1129. else
  1130. begin
  1131. insertdef(list,cchartype.def);
  1132. insertdef(list,u8inttype.def);
  1133. end;
  1134. end;
  1135. floatdef :
  1136. insertdef(list,s32inttype.def);
  1137. filedef :
  1138. begin
  1139. insertdef(list,s32inttype.def);
  1140. {$ifdef cpu64bit}
  1141. insertdef(list,s64inttype.def);
  1142. {$endif cpu64bit}
  1143. insertdef(list,u8inttype.def);
  1144. insertdef(list,cchartype.def);
  1145. end;
  1146. classrefdef :
  1147. insertdef(list,pvmttype.def);
  1148. pointerdef :
  1149. insertdef(list,tpointerdef(def).pointertype.def);
  1150. setdef :
  1151. insertdef(list,tsetdef(def).elementtype.def);
  1152. procvardef:
  1153. begin
  1154. insertdef(list,tprocvardef(def).rettype.def);
  1155. if tprocvardef(def).is_methodpointer then
  1156. insertdef(list,class_tobject);
  1157. { parameters }
  1158. for i:=0 to tprocvardef(def).paras.count-1 do
  1159. insertdef(list,tparavarsym(tprocvardef(def).paras[i]).vartype.def);
  1160. end;
  1161. procdef :
  1162. insertdef(list,tprocdef(def).rettype.def);
  1163. arraydef :
  1164. begin
  1165. insertdef(list,tarraydef(def).rangetype.def);
  1166. insertdef(list,tarraydef(def).elementtype.def);
  1167. end;
  1168. recorddef :
  1169. trecorddef(def).symtable.foreach(@field_write_defs,list);
  1170. variantdef :
  1171. trecorddef(vardatadef).symtable.foreach(@field_write_defs,list);
  1172. objectdef :
  1173. begin
  1174. insertdef(list,vmtarraytype.def);
  1175. { first the parents }
  1176. anc:=tobjectdef(def);
  1177. while assigned(anc.childof) do
  1178. begin
  1179. anc:=anc.childof;
  1180. insertdef(list,anc);
  1181. end;
  1182. tobjectdef(def).symtable.foreach(@field_write_defs,list);
  1183. tobjectdef(def).symtable.foreach(@method_write_defs,list);
  1184. end;
  1185. end;
  1186. append_dwarftag(list,def);
  1187. def.dbg_state:=dbg_state_written;
  1188. end;
  1189. procedure TDebugInfoDwarf.write_symtable_defs(list:taasmoutput;st:tsymtable);
  1190. procedure dowritedwarf(list:taasmoutput;st:tsymtable);
  1191. var
  1192. p : tdef;
  1193. begin
  1194. p:=tdef(st.defindex.first);
  1195. while assigned(p) do
  1196. begin
  1197. if (p.dbg_state=dbg_state_used) then
  1198. insertdef(list,p);
  1199. p:=tdef(p.indexnext);
  1200. end;
  1201. end;
  1202. var
  1203. old_writing_def_dwarf : boolean;
  1204. begin
  1205. case st.symtabletype of
  1206. staticsymtable :
  1207. list.concat(tai_comment.Create(strpnew('Defs - Begin Staticsymtable')));
  1208. globalsymtable :
  1209. list.concat(tai_comment.Create(strpnew('Defs - Begin unit '+st.name^+' has index '+tostr(st.moduleid))));
  1210. end;
  1211. old_writing_def_dwarf:=writing_def_dwarf;
  1212. writing_def_dwarf:=true;
  1213. dowritedwarf(list,st);
  1214. writing_def_dwarf:=old_writing_def_dwarf;
  1215. case st.symtabletype of
  1216. staticsymtable :
  1217. list.concat(tai_comment.Create(strpnew('Defs - End Staticsymtable')));
  1218. globalsymtable :
  1219. list.concat(tai_comment.Create(strpnew('Defs - End unit '+st.name^+' has index '+tostr(st.moduleid))));
  1220. end;
  1221. end;
  1222. procedure TDebugInfoDwarf.append_procdef(list:taasmoutput;pd:tprocdef);
  1223. var
  1224. procendlabel : tasmlabel;
  1225. mangled_length : longint;
  1226. p : pchar;
  1227. hs : string;
  1228. begin
  1229. if assigned(pd.procstarttai) then
  1230. begin
  1231. append_entry(DW_TAG_subprogram,true,
  1232. [DW_AT_name,DW_FORM_string,pd.procsym.name+#0
  1233. { data continues below }
  1234. { problem: base reg isn't known here
  1235. DW_AT_frame_base,DW_FORM_block1,1
  1236. }
  1237. ]);
  1238. { append block data }
  1239. { asmlist[al_dwarf_info].concat(tai_const.create_8bit(dwarf_reg(pd.))); }
  1240. if not(is_void(tprocdef(pd).rettype.def)) then
  1241. append_labelentry_ref(DW_AT_type,def_dwarf_lab(tprocdef(pd).rettype.def));
  1242. { mark end of procedure }
  1243. objectlibrary.getlabel(procendlabel,alt_dbgtype);
  1244. asmlist[al_procedures].insertbefore(tai_label.create(procendlabel),pd.procendtai);
  1245. append_labelentry(DW_AT_low_pc,objectlibrary.newasmsymbol(pd.mangledname,AB_LOCAL,AT_DATA));
  1246. append_labelentry(DW_AT_high_pc,procendlabel);
  1247. {
  1248. if assigned(pd.funcretsym) and
  1249. (tabstractnormalvarsym(pd.funcretsym).refs>0) then
  1250. begin
  1251. if tabstractnormalvarsym(pd.funcretsym).localloc.loc=LOC_REFERENCE then
  1252. begin
  1253. {$warning Need to add gdb support for ret in param register calling}
  1254. if paramanager.ret_in_param(pd.rettype.def,pd.proccalloption) then
  1255. hs:='X*'
  1256. else
  1257. hs:='X';
  1258. templist.concat(Tai_stab.create(stab_stabs,strpnew(
  1259. '"'+pd.procsym.name+':'+hs+def_stab_number(pd.rettype.def)+'",'+
  1260. tostr(N_tsym)+',0,0,'+tostr(tabstractnormalvarsym(pd.funcretsym).localloc.reference.offset))));
  1261. if (m_result in aktmodeswitches) then
  1262. templist.concat(Tai_stab.create(stab_stabs,strpnew(
  1263. '"RESULT:'+hs+def_stab_number(pd.rettype.def)+'",'+
  1264. tostr(N_tsym)+',0,0,'+tostr(tabstractnormalvarsym(pd.funcretsym).localloc.reference.offset))));
  1265. end;
  1266. end;
  1267. }
  1268. finish_entry;
  1269. {
  1270. { para types }
  1271. write_def_stabstr(templist,pd);
  1272. }
  1273. if assigned(pd.parast) then
  1274. write_symtable_syms(list,pd.parast);
  1275. { local type defs and vars should not be written
  1276. inside the main proc stab }
  1277. if assigned(pd.localst) and
  1278. (pd.localst.symtabletype=localsymtable) then
  1279. write_symtable_syms(list,pd.localst);
  1280. { last write the types from this procdef }
  1281. if assigned(pd.parast) then
  1282. write_symtable_defs(asmlist[al_dwarf_info],pd.parast);
  1283. if assigned(pd.localst) and
  1284. (pd.localst.symtabletype=localsymtable) then
  1285. write_symtable_defs(asmlist[al_dwarf_info],pd.localst);
  1286. finish_children;
  1287. end;
  1288. end;
  1289. procedure TDebugInfoDwarf.insertsym(list:taasmoutput;sym:tsym);
  1290. procedure append_varsym(sym:tabstractnormalvarsym);
  1291. var
  1292. templist : taasmoutput;
  1293. blocksize : longint;
  1294. regidx : longint;
  1295. tag : tdwarf_tag;
  1296. begin
  1297. { external symbols can't be resolved at link time, so we
  1298. can't generate stabs for them
  1299. not sure if this applies to dwarf as well (FK)
  1300. }
  1301. if vo_is_external in sym.varoptions then
  1302. exit;
  1303. { There is no space allocated for not referenced locals }
  1304. if (sym.owner.symtabletype=localsymtable) and (sym.refs=0) then
  1305. exit;
  1306. templist:=taasmoutput.create;
  1307. case sym.localloc.loc of
  1308. LOC_REGISTER,
  1309. LOC_CREGISTER,
  1310. LOC_MMREGISTER,
  1311. LOC_CMMREGISTER,
  1312. LOC_FPUREGISTER,
  1313. LOC_CFPUREGISTER :
  1314. begin
  1315. regidx:=findreg_by_number(sym.localloc.register);
  1316. templist.concat(tai_const.create_8bit(ord(DW_OP_regx)));
  1317. templist.concat(tai_const.create_uleb128bit(regdwarf_table[regidx]));
  1318. blocksize:=1+Lengthuleb128(regdwarf_table[regidx]);
  1319. end;
  1320. else
  1321. begin
  1322. case sym.typ of
  1323. globalvarsym:
  1324. begin
  1325. if (vo_is_thread_var in sym.varoptions) then
  1326. begin
  1327. {$warning !!! FIXME: dwarf for thread vars !!!}
  1328. blocksize:=0;
  1329. end
  1330. else
  1331. begin
  1332. templist.concat(tai_const.create_8bit(3));
  1333. templist.concat(tai_const.createname(sym.mangledname,AT_DATA,0));
  1334. blocksize:=1+sizeof(aword);
  1335. end;
  1336. end;
  1337. paravarsym,
  1338. localvarsym:
  1339. begin
  1340. regidx:=findreg_by_number(sym.localloc.reference.base);
  1341. templist.concat(tai_const.create_8bit(ord(DW_OP_breg0)+regdwarf_table[regidx]));
  1342. templist.concat(tai_const.create_sleb128bit(sym.localloc.reference.offset));
  1343. blocksize:=1+Lengthsleb128(sym.localloc.reference.offset);
  1344. end
  1345. else
  1346. internalerror(200601288);
  1347. end;
  1348. end;
  1349. end;
  1350. if sym.typ=paravarsym then
  1351. tag:=DW_TAG_formal_parameter
  1352. else
  1353. tag:=DW_TAG_variable;
  1354. append_entry(tag,false,[
  1355. DW_AT_name,DW_FORM_string,sym.name+#0,
  1356. {
  1357. DW_AT_decl_file,DW_FORM_data1,0,
  1358. DW_AT_decl_line,DW_FORM_data1,
  1359. }
  1360. DW_AT_external,DW_FORM_flag,true,
  1361. { data continues below }
  1362. DW_AT_location,DW_FORM_block1,blocksize
  1363. ]);
  1364. { append block data }
  1365. asmlist[al_dwarf_info].concatlist(templist);
  1366. append_labelentry_ref(DW_AT_type,def_dwarf_lab(sym.vartype.def));
  1367. templist.free;
  1368. finish_entry;
  1369. end;
  1370. procedure append_constsym(sym:tconstsym);
  1371. begin
  1372. append_entry(DW_TAG_constant,false,[
  1373. DW_AT_name,DW_FORM_string,sym.name+#0
  1374. ]);
  1375. { for string constants, consttype isn't set because they have no real type }
  1376. if not(sym.consttyp in [conststring,constresourcestring]) then
  1377. append_labelentry_ref(DW_AT_type,def_dwarf_lab(sym.consttype.def));
  1378. asmlist[al_dwarf_abbrev].concat(tai_const.create_uleb128bit(ord(DW_AT_const_value)));
  1379. case sym.consttyp of
  1380. conststring:
  1381. begin
  1382. asmlist[al_dwarf_abbrev].concat(tai_const.create_uleb128bit(ord(DW_FORM_string)));
  1383. asmlist[al_dwarf_info].concat(tai_string.create(strpas(pchar(sym.value.valueptr))));
  1384. asmlist[al_dwarf_info].concat(tai_const.create_8bit(0));
  1385. end;
  1386. constset,
  1387. constwstring,
  1388. constguid,
  1389. constresourcestring:
  1390. begin
  1391. { write dummy for now }
  1392. asmlist[al_dwarf_abbrev].concat(tai_const.create_uleb128bit(ord(DW_FORM_string)));
  1393. asmlist[al_dwarf_info].concat(tai_string.create(''));
  1394. asmlist[al_dwarf_info].concat(tai_const.create_8bit(0));
  1395. end;
  1396. constord:
  1397. begin
  1398. asmlist[al_dwarf_abbrev].concat(tai_const.create_uleb128bit(ord(DW_FORM_sdata)));
  1399. asmlist[al_dwarf_info].concat(tai_const.create_sleb128bit(sym.value.valueord));
  1400. end;
  1401. constnil:
  1402. begin
  1403. {$ifdef cpu64bit}
  1404. asmlist[al_dwarf_abbrev].concat(tai_const.create_uleb128bit(ord(DW_FORM_data8)));
  1405. asmlist[al_dwarf_info].concat(tai_const.create_64bit(0));
  1406. {$else cpu64bit}
  1407. asmlist[al_dwarf_abbrev].concat(tai_const.create_uleb128bit(ord(DW_FORM_data4)));
  1408. asmlist[al_dwarf_info].concat(tai_const.create_32bit(0));
  1409. {$endif cpu64bit}
  1410. end;
  1411. constpointer:
  1412. begin
  1413. {$ifdef cpu64bit}
  1414. asmlist[al_dwarf_abbrev].concat(tai_const.create_uleb128bit(ord(DW_FORM_data8)));
  1415. asmlist[al_dwarf_info].concat(tai_const.create_64bit(sym.value.valueordptr));
  1416. {$else cpu64bit}
  1417. asmlist[al_dwarf_abbrev].concat(tai_const.create_uleb128bit(ord(DW_FORM_data4)));
  1418. asmlist[al_dwarf_info].concat(tai_const.create_32bit(sym.value.valueordptr));
  1419. {$endif cpu64bit}
  1420. end;
  1421. constreal:
  1422. begin
  1423. asmlist[al_dwarf_abbrev].concat(tai_const.create_uleb128bit(ord(DW_FORM_block1)));
  1424. case tfloatdef(sym.consttype.def).typ of
  1425. s32real:
  1426. begin
  1427. asmlist[al_dwarf_info].concat(tai_const.create_8bit(4));
  1428. asmlist[al_dwarf_info].concat(tai_real_32bit.create(psingle(sym.value.valueptr)^));
  1429. end;
  1430. s64comp,
  1431. s64currency,
  1432. s64real:
  1433. begin
  1434. asmlist[al_dwarf_info].concat(tai_const.create_8bit(8));
  1435. asmlist[al_dwarf_info].concat(tai_real_64bit.create(pdouble(sym.value.valueptr)^));
  1436. end;
  1437. s80real:
  1438. begin
  1439. asmlist[al_dwarf_info].concat(tai_const.create_8bit(10));
  1440. asmlist[al_dwarf_info].concat(tai_real_80bit.create(pextended(sym.value.valueptr)^));
  1441. end;
  1442. else
  1443. internalerror(200601291);
  1444. end;
  1445. end;
  1446. else
  1447. internalerror(200601292);
  1448. end;
  1449. finish_entry;
  1450. end;
  1451. procedure append_procsym(sym:tprocsym);
  1452. var
  1453. i : longint;
  1454. begin
  1455. for i:=1 to sym.procdef_count do
  1456. append_procdef(list,sym.procdef[i]);
  1457. end;
  1458. procedure append_absolutesym(sym:tabsolutevarsym);
  1459. var
  1460. templist : taasmoutput;
  1461. blocksize : longint;
  1462. symlist : psymlistitem;
  1463. begin
  1464. templist:=taasmoutput.create;
  1465. case tabsolutevarsym(sym).abstyp of
  1466. toaddr :
  1467. begin
  1468. {$ifdef i386}
  1469. { in theory, we could write a DW_AT_segment entry here for sym.absseg,
  1470. however I doubt that gdb supports this (FK) }
  1471. {$endif i386}
  1472. templist.concat(tai_const.create_8bit(3));
  1473. templist.concat(tai_const.create_aint(sym.addroffset));
  1474. blocksize:=1+sizeof(aword);
  1475. end;
  1476. toasm :
  1477. begin
  1478. templist.concat(tai_const.create_8bit(3));
  1479. templist.concat(tai_const.createname(sym.mangledname,AT_DATA,0));
  1480. blocksize:=1+sizeof(aword);
  1481. end;
  1482. tovar:
  1483. begin
  1484. symlist:=tabsolutevarsym(sym).ref.firstsym;
  1485. { can we insert the symbol? }
  1486. if assigned(symlist) and
  1487. (symlist^.sltype=sl_load) then
  1488. insertsym(list,symlist^.sym);
  1489. templist.free;
  1490. exit;
  1491. end;
  1492. end;
  1493. append_entry(DW_TAG_variable,false,[
  1494. DW_AT_name,DW_FORM_string,sym.name+#0,
  1495. {
  1496. DW_AT_decl_file,DW_FORM_data1,0,
  1497. DW_AT_decl_line,DW_FORM_data1,
  1498. }
  1499. DW_AT_external,DW_FORM_flag,true,
  1500. { data continues below }
  1501. DW_AT_location,DW_FORM_block1,blocksize
  1502. ]);
  1503. { append block data }
  1504. asmlist[al_dwarf_info].concatlist(templist);
  1505. append_labelentry_ref(DW_AT_type,def_dwarf_lab(sym.vartype.def));
  1506. templist.free;
  1507. finish_entry;
  1508. end;
  1509. begin
  1510. case sym.typ of
  1511. globalvarsym :
  1512. append_varsym(tglobalvarsym(sym));
  1513. unitsym:
  1514. { for now, we ignore unit symbols }
  1515. ;
  1516. procsym :
  1517. append_procsym(tprocsym(sym));
  1518. labelsym :
  1519. { ignore label syms for now, the problem is that a label sym
  1520. can have more than one label associated e.g. in case of
  1521. an inline procedure expansion }
  1522. ;
  1523. localvarsym :
  1524. append_varsym(tlocalvarsym(sym));
  1525. paravarsym :
  1526. append_varsym(tparavarsym(sym));
  1527. typedconstsym :
  1528. begin
  1529. append_entry(DW_TAG_variable,false,[
  1530. DW_AT_name,DW_FORM_string,sym.name+#0,
  1531. {
  1532. DW_AT_decl_file,DW_FORM_data1,0,
  1533. DW_AT_decl_line,DW_FORM_data1,
  1534. }
  1535. DW_AT_external,DW_FORM_flag,true,
  1536. { data continues below }
  1537. DW_AT_location,DW_FORM_block1,1+sizeof(aword)
  1538. ]);
  1539. { append block data }
  1540. asmlist[al_dwarf_info].concat(tai_const.create_8bit(3));
  1541. asmlist[al_dwarf_info].concat(tai_const.createname(sym.mangledname,AT_DATA,0));
  1542. append_labelentry_ref(DW_AT_type,def_dwarf_lab(ttypedconstsym(sym).typedconsttype.def));
  1543. finish_entry;
  1544. end;
  1545. constsym :
  1546. append_constsym(tconstsym(sym));
  1547. typesym :
  1548. begin
  1549. append_entry(DW_TAG_typedef,false,[
  1550. DW_AT_name,DW_FORM_string,sym.name+#0
  1551. ]);
  1552. append_labelentry_ref(DW_AT_type,def_dwarf_lab(ttypesym(sym).restype.def));
  1553. finish_entry;
  1554. end;
  1555. enumsym :
  1556. { ignore enum syms, they are written by the owner }
  1557. ;
  1558. rttisym :
  1559. { ignore rtti syms, they are only of internal use }
  1560. ;
  1561. syssym :
  1562. { ignore sys syms, they are only of internal use }
  1563. ;
  1564. absolutevarsym :
  1565. append_absolutesym(tabsolutevarsym(sym));
  1566. propertysym :
  1567. { ignored for now }
  1568. ;
  1569. else
  1570. begin
  1571. writeln(ord(sym.typ));
  1572. internalerror(200601242);
  1573. end;
  1574. end;
  1575. {
  1576. { For object types write also the symtable entries }
  1577. if (sym.typ=typesym) and (ttypesym(sym).restype.def.deftype=objectdef) then
  1578. write_symtable_syms(list,tobjectdef(ttypesym(sym).restype.def).symtable);
  1579. sym.isstabwritten:=true;
  1580. }
  1581. end;
  1582. procedure TDebugInfoDwarf.write_symtable_syms(list:taasmoutput;st:tsymtable);
  1583. var
  1584. p : tsym;
  1585. begin
  1586. case st.symtabletype of
  1587. staticsymtable :
  1588. list.concat(tai_comment.Create(strpnew('Syms - Begin Staticsymtable')));
  1589. globalsymtable :
  1590. list.concat(tai_comment.Create(strpnew('Syms - Begin unit '+st.name^+' has index '+tostr(st.moduleid))));
  1591. end;
  1592. p:=tsym(st.symindex.first);
  1593. while assigned(p) do
  1594. begin
  1595. if (not p.isstabwritten) then
  1596. insertsym(list,p);
  1597. p:=tsym(p.indexnext);
  1598. end;
  1599. case st.symtabletype of
  1600. staticsymtable :
  1601. list.concat(tai_comment.Create(strpnew('Syms - End Staticsymtable')));
  1602. globalsymtable :
  1603. list.concat(tai_comment.Create(strpnew('Syms - End unit '+st.name^+' has index '+tostr(st.moduleid))));
  1604. end;
  1605. end;
  1606. procedure TDebugInfoDwarf.insertmoduleinfo;
  1607. var
  1608. templist : taasmoutput;
  1609. begin
  1610. { insert .Ltext0 label }
  1611. templist:=taasmoutput.create;
  1612. new_section(templist,sec_code,'',0);
  1613. templist.concat(tai_symbol.createname('.Ltext0',AT_DATA,0));
  1614. asmlist[al_start].insertlist(templist);
  1615. templist.free;
  1616. { insert .Letext0 label }
  1617. templist:=taasmoutput.create;
  1618. new_section(templist,sec_code,'',0);
  1619. templist.concat(tai_symbol.createname('.Letext0',AT_DATA,0));
  1620. asmlist[al_end].insertlist(templist);
  1621. templist.free;
  1622. { insert .Ldebug_abbrev0 label }
  1623. templist:=taasmoutput.create;
  1624. new_section(templist,sec_debug_abbrev,'',0);
  1625. templist.concat(tai_symbol.createname('.Ldebug_abbrev0',AT_DATA,0));
  1626. asmlist[al_start].insertlist(templist);
  1627. templist.free;
  1628. { insert .Ldebug_line0 label }
  1629. templist:=taasmoutput.create;
  1630. new_section(templist,sec_debug_line,'',0);
  1631. templist.concat(tai_symbol.createname('.Ldebug_line0',AT_DATA,0));
  1632. asmlist[al_start].insertlist(templist);
  1633. templist.free;
  1634. end;
  1635. procedure TDebugInfoDwarf.inserttypeinfo;
  1636. var
  1637. storefilepos : tfileposinfo;
  1638. lenstartlabel : tasmlabel;
  1639. i : longint;
  1640. begin
  1641. storefilepos:=aktfilepos;
  1642. aktfilepos:=current_module.mainfilepos;
  1643. currabbrevnumber:=0;
  1644. writing_def_dwarf:=false;
  1645. nextdefnumber:=0;
  1646. defnumberlist:=tlist.create;
  1647. vardatadef:=search_system_type('TVARDATA').restype.def;
  1648. { not exported (FK)
  1649. filerecdef:=gettypedef('FILEREC');
  1650. textrecdef:=gettypedef('TEXTREC');
  1651. }
  1652. { write start labels }
  1653. asmlist[al_dwarf_info].concat(tai_section.create(sec_debug_info,'',0));
  1654. asmlist[al_dwarf_info].concat(tai_symbol.createname('.Ldebug_info0',AT_DATA,0));
  1655. { start abbrev section }
  1656. new_section(asmlist[al_dwarf_abbrev],sec_debug_abbrev,'',0);
  1657. { debug info header }
  1658. objectlibrary.getlabel(lenstartlabel,alt_dbgfile);
  1659. { size }
  1660. asmlist[al_dwarf_info].concat(tai_const.create_rel_sym(aitconst_ptr,
  1661. lenstartlabel,tasmsymbol.create('.Ledebug_info0',AB_COMMON,AT_DATA)));
  1662. asmlist[al_dwarf_info].concat(tai_label.create(lenstartlabel));
  1663. { version }
  1664. asmlist[al_dwarf_info].concat(tai_const.create_16bit(2));
  1665. { abbrev table }
  1666. asmlist[al_dwarf_info].concat(tai_const.createname('.Ldebug_abbrev0',AT_DATA,0));
  1667. { address size }
  1668. asmlist[al_dwarf_info].concat(tai_const.create_8bit(sizeof(aint)));
  1669. append_entry(DW_TAG_compile_unit,true,[
  1670. DW_AT_name,DW_FORM_string,FixFileName(current_module.sourcefiles.get_file(1).name^)+#0,
  1671. DW_AT_producer,DW_FORM_string,'Free Pascal '+full_version_string+' '+date_string+#0,
  1672. DW_AT_comp_dir,DW_FORM_string,BsToSlash(FixPath(current_module.sourcefiles.get_file(1).path^,false))+#0,
  1673. DW_AT_language,DW_FORM_data1,DW_LANG_Pascal83,
  1674. DW_AT_identifier_case,DW_FORM_data1,DW_ID_case_insensitive]);
  1675. { reference to line info section }
  1676. append_labelentry_data(DW_AT_stmt_list,objectlibrary.newasmsymbol('.Ldebug_line0',AB_LOCAL,AT_DATA));
  1677. append_labelentry(DW_AT_low_pc,objectlibrary.newasmsymbol('.Ltext0',AB_LOCAL,AT_DATA));
  1678. append_labelentry(DW_AT_high_pc,objectlibrary.newasmsymbol('.Letext0',AB_LOCAL,AT_DATA));
  1679. finish_entry;
  1680. { first write all global/local symbols. This will flag all required tdefs }
  1681. if assigned(current_module.globalsymtable) then
  1682. write_symtable_syms(asmlist[al_dwarf_info],current_module.globalsymtable);
  1683. if assigned(current_module.localsymtable) then
  1684. write_symtable_syms(asmlist[al_dwarf_info],current_module.localsymtable);
  1685. { reset unit type info flag }
  1686. reset_unit_type_info;
  1687. { write used types from the used units }
  1688. write_used_unit_type_info(asmlist[al_dwarf_info],current_module);
  1689. { last write the types from this unit }
  1690. if assigned(current_module.globalsymtable) then
  1691. write_symtable_defs(asmlist[al_dwarf_info],current_module.globalsymtable);
  1692. if assigned(current_module.localsymtable) then
  1693. write_symtable_defs(asmlist[al_dwarf_info],current_module.localsymtable);
  1694. { close compilation unit entry }
  1695. finish_children;
  1696. { end of debug info table }
  1697. asmlist[al_dwarf_info].concat(tai_const.create_8bit(0));
  1698. asmlist[al_dwarf_info].concat(tai_symbol.createname('.Ledebug_info0',AT_DATA,0));
  1699. { reset all def labels }
  1700. for i:=0 to defnumberlist.count-1 do
  1701. begin
  1702. if assigned(defnumberlist[i]) then
  1703. begin
  1704. tdef(defnumberlist[i]).dwarf_lab:=nil;
  1705. tdef(defnumberlist[i]).dbg_state:=dbg_state_unused;
  1706. end;
  1707. end;
  1708. defnumberlist.free;
  1709. defnumberlist:=nil;
  1710. aktfilepos:=storefilepos;
  1711. end;
  1712. procedure TDebugInfoDwarf.referencesections(list:taasmoutput);
  1713. begin
  1714. end;
  1715. procedure TDebugInfoDwarf.insertlineinfo(list:taasmoutput);
  1716. var
  1717. currfileinfo,
  1718. lastfileinfo : tfileposinfo;
  1719. currfuncname : pstring;
  1720. currsectype : tasmsectiontype;
  1721. hlabel : tasmlabel;
  1722. hp : tai;
  1723. infile : tinputfile;
  1724. current_file : tai_file;
  1725. begin
  1726. FillChar(lastfileinfo,sizeof(lastfileinfo),0);
  1727. currfuncname:=nil;
  1728. currsectype:=sec_code;
  1729. hp:=Tai(list.first);
  1730. while assigned(hp) do
  1731. begin
  1732. case hp.typ of
  1733. ait_section :
  1734. currsectype:=tai_section(hp).sectype;
  1735. ait_function_name :
  1736. currfuncname:=tai_function_name(hp).funcname;
  1737. ait_force_line :
  1738. lastfileinfo.line:=-1;
  1739. end;
  1740. if (currsectype=sec_code) and
  1741. (hp.typ=ait_instruction) then
  1742. begin
  1743. currfileinfo:=tailineinfo(hp).fileinfo;
  1744. { file changed ? (must be before line info) }
  1745. if (currfileinfo.fileindex<>0) and
  1746. (lastfileinfo.fileindex<>currfileinfo.fileindex) then
  1747. begin
  1748. infile:=current_module.sourcefiles.get_file(currfileinfo.fileindex);
  1749. if assigned(infile) then
  1750. begin
  1751. if (infile.path^<>'') then
  1752. begin
  1753. current_file:=tai_file.create(BsToSlash(FixPath(infile.path^,false)+FixFileName(infile.name^)));
  1754. list.insertbefore(current_file,hp)
  1755. end
  1756. else
  1757. begin
  1758. current_file:=tai_file.create(FixFileName(infile.name^));
  1759. list.insertbefore(current_file,hp);
  1760. end;
  1761. { force new line info }
  1762. lastfileinfo.line:=-1;
  1763. end;
  1764. end;
  1765. { line changed ? }
  1766. if (lastfileinfo.line<>currfileinfo.line) and (currfileinfo.line<>0) then
  1767. list.insertbefore(tai_loc.create(
  1768. current_file,currfileinfo.line,currfileinfo.column),hp);
  1769. lastfileinfo:=currfileinfo;
  1770. end;
  1771. hp:=tai(hp.next);
  1772. end;
  1773. end;
  1774. const
  1775. dbg_dwarf_info : tdbginfo =
  1776. (
  1777. id : dbg_dwarf;
  1778. idtxt : 'DWARF';
  1779. );
  1780. initialization
  1781. RegisterDebugInfo(dbg_dwarf_info,TDebugInfoDwarf);
  1782. end.