dbgdwarf.pas 77 KB

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