dbgdwarf.pas 78 KB

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