dbgdwarf.pas 80 KB

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