dbgdwarf.pas 106 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861
  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,symsym,
  33. finput,
  34. DbgBase;
  35. type
  36. { Tag names and codes. }
  37. tdwarf_tag = (DW_TAG_padding := $00,DW_TAG_array_type := $01,
  38. DW_TAG_class_type := $02,DW_TAG_entry_point := $03,
  39. DW_TAG_enumeration_type := $04,DW_TAG_formal_parameter := $05,
  40. DW_TAG_imported_declaration := $08,DW_TAG_label := $0a,
  41. DW_TAG_lexical_block := $0b,DW_TAG_member := $0d,
  42. DW_TAG_pointer_type := $0f,DW_TAG_reference_type := $10,
  43. DW_TAG_compile_unit := $11,DW_TAG_string_type := $12,
  44. DW_TAG_structure_type := $13,DW_TAG_subroutine_type := $15,
  45. DW_TAG_typedef := $16,DW_TAG_union_type := $17,
  46. DW_TAG_unspecified_parameters := $18,
  47. DW_TAG_variant := $19,DW_TAG_common_block := $1a,
  48. DW_TAG_common_inclusion := $1b,DW_TAG_inheritance := $1c,
  49. DW_TAG_inlined_subroutine := $1d,DW_TAG_module := $1e,
  50. DW_TAG_ptr_to_member_type := $1f,DW_TAG_set_type := $20,
  51. DW_TAG_subrange_type := $21,DW_TAG_with_stmt := $22,
  52. DW_TAG_access_declaration := $23,DW_TAG_base_type := $24,
  53. DW_TAG_catch_block := $25,DW_TAG_const_type := $26,
  54. DW_TAG_constant := $27,DW_TAG_enumerator := $28,
  55. DW_TAG_file_type := $29,DW_TAG_friend := $2a,
  56. DW_TAG_namelist := $2b,DW_TAG_namelist_item := $2c,
  57. DW_TAG_packed_type := $2d,DW_TAG_subprogram := $2e,
  58. DW_TAG_template_type_param := $2f,DW_TAG_template_value_param := $30,
  59. DW_TAG_thrown_type := $31,DW_TAG_try_block := $32,
  60. DW_TAG_variant_part := $33,DW_TAG_variable := $34,
  61. DW_TAG_volatile_type := $35,
  62. { DWARF 3. }
  63. DW_TAG_dwarf_procedure := $36,
  64. DW_TAG_restrict_type := $37,DW_TAG_interface_type := $38,
  65. DW_TAG_namespace := $39,DW_TAG_imported_module := $3a,
  66. DW_TAG_unspecified_type := $3b,DW_TAG_partial_unit := $3c,
  67. DW_TAG_imported_unit := $3d,
  68. { SGI/MIPS Extensions. }
  69. DW_TAG_MIPS_loop := $4081,
  70. { HP extensions. See: ftp://ftp.hp.com/pub/lang/tools/WDB/wdb-4.0.tar.gz . }
  71. DW_TAG_HP_array_descriptor := $4090,
  72. { GNU extensions. }
  73. { For FORTRAN 77 and Fortran 90. }
  74. DW_TAG_format_label := $4101,
  75. { For C++. }
  76. DW_TAG_function_template := $4102,DW_TAG_class_template := $4103,
  77. DW_TAG_GNU_BINCL := $4104,DW_TAG_GNU_EINCL := $4105,
  78. { Extensions for UPC. See: http://upc.gwu.edu/~upc. }
  79. DW_TAG_upc_shared_type := $8765,DW_TAG_upc_strict_type := $8766,
  80. DW_TAG_upc_relaxed_type := $8767,
  81. { PGI (STMicroelectronics) extensions. No documentation available. }
  82. DW_TAG_PGI_kanji_type := $A000,
  83. DW_TAG_PGI_interface_block := $A020);
  84. { Attribute names and codes. }
  85. tdwarf_attribute = (DW_AT_sibling := $01,DW_AT_location := $02,
  86. DW_AT_name := $03,DW_AT_ordering := $09,
  87. DW_AT_subscr_data := $0a,DW_AT_byte_size := $0b,
  88. DW_AT_bit_offset := $0c,DW_AT_bit_size := $0d,
  89. DW_AT_element_list := $0f,DW_AT_stmt_list := $10,
  90. DW_AT_low_pc := $11,DW_AT_high_pc := $12,
  91. DW_AT_language := $13,DW_AT_member := $14,
  92. DW_AT_discr := $15,DW_AT_discr_value := $16,
  93. DW_AT_visibility := $17,DW_AT_import := $18,
  94. DW_AT_string_length := $19,DW_AT_common_reference := $1a,
  95. DW_AT_comp_dir := $1b,DW_AT_const_value := $1c,
  96. DW_AT_containing_type := $1d,DW_AT_default_value := $1e,
  97. DW_AT_inline := $20,DW_AT_is_optional := $21,
  98. DW_AT_lower_bound := $22,DW_AT_producer := $25,
  99. DW_AT_prototyped := $27,DW_AT_return_addr := $2a,
  100. DW_AT_start_scope := $2c,DW_AT_stride_size := $2e,
  101. DW_AT_upper_bound := $2f,DW_AT_abstract_origin := $31,
  102. DW_AT_accessibility := $32,DW_AT_address_class := $33,
  103. DW_AT_artificial := $34,DW_AT_base_types := $35,
  104. DW_AT_calling_convention := $36,DW_AT_count := $37,
  105. DW_AT_data_member_location := $38,DW_AT_decl_column := $39,
  106. DW_AT_decl_file := $3a,DW_AT_decl_line := $3b,
  107. DW_AT_declaration := $3c,DW_AT_discr_list := $3d,
  108. DW_AT_encoding := $3e,DW_AT_external := $3f,
  109. DW_AT_frame_base := $40,DW_AT_friend := $41,
  110. DW_AT_identifier_case := $42,DW_AT_macro_info := $43,
  111. DW_AT_namelist_items := $44,DW_AT_priority := $45,
  112. DW_AT_segment := $46,DW_AT_specification := $47,
  113. DW_AT_static_link := $48,DW_AT_type := $49,
  114. DW_AT_use_location := $4a,DW_AT_variable_parameter := $4b,
  115. DW_AT_virtuality := $4c,DW_AT_vtable_elem_location := $4d,
  116. { DWARF 3 values. }
  117. DW_AT_allocated := $4e,DW_AT_associated := $4f,
  118. DW_AT_data_location := $50,DW_AT_stride := $51,
  119. DW_AT_entry_pc := $52,DW_AT_use_UTF8 := $53,
  120. DW_AT_extension := $54,DW_AT_ranges := $55,
  121. DW_AT_trampoline := $56,DW_AT_call_column := $57,
  122. DW_AT_call_file := $58,DW_AT_call_line := $59,
  123. { SGI/MIPS extensions. }
  124. DW_AT_MIPS_fde := $2001,DW_AT_MIPS_loop_begin := $2002,
  125. DW_AT_MIPS_tail_loop_begin := $2003,DW_AT_MIPS_epilog_begin := $2004,
  126. DW_AT_MIPS_loop_unroll_factor := $2005,
  127. DW_AT_MIPS_software_pipeline_depth := $2006,
  128. DW_AT_MIPS_linkage_name := $2007,DW_AT_MIPS_stride := $2008,
  129. DW_AT_MIPS_abstract_name := $2009,DW_AT_MIPS_clone_origin := $200a,
  130. DW_AT_MIPS_has_inlines := $200b,
  131. { HP extensions. }
  132. DW_AT_HP_block_index := $2000,
  133. DW_AT_HP_unmodifiable := $2001,DW_AT_HP_actuals_stmt_list := $2010,
  134. DW_AT_HP_proc_per_section := $2011,DW_AT_HP_raw_data_ptr := $2012,
  135. DW_AT_HP_pass_by_reference := $2013,DW_AT_HP_opt_level := $2014,
  136. DW_AT_HP_prof_version_id := $2015,DW_AT_HP_opt_flags := $2016,
  137. DW_AT_HP_cold_region_low_pc := $2017,DW_AT_HP_cold_region_high_pc := $2018,
  138. DW_AT_HP_all_variables_modifiable := $2019,
  139. DW_AT_HP_linkage_name := $201a,DW_AT_HP_prof_flags := $201b,
  140. { GNU extensions. }
  141. DW_AT_sf_names := $2101,DW_AT_src_info := $2102,
  142. DW_AT_mac_info := $2103,DW_AT_src_coords := $2104,
  143. DW_AT_body_begin := $2105,DW_AT_body_end := $2106,
  144. DW_AT_GNU_vector := $2107,
  145. { VMS extensions. }
  146. DW_AT_VMS_rtnbeg_pd_address := $2201,
  147. { UPC extension. }
  148. DW_AT_upc_threads_scaled := $3210,
  149. { PGI (STMicroelectronics) extensions. }
  150. DW_AT_PGI_lbase := $3a00,
  151. DW_AT_PGI_soffset := $3a01,DW_AT_PGI_lstride := $3a02
  152. );
  153. { Form names and codes. }
  154. Tdwarf_form = (DW_FORM_addr := $01,DW_FORM_block2 := $03,
  155. DW_FORM_block4 := $04,DW_FORM_data2 := $05,
  156. DW_FORM_data4 := $06,DW_FORM_data8 := $07,
  157. DW_FORM_string := $08,DW_FORM_block := $09,
  158. DW_FORM_block1 := $0a,DW_FORM_data1 := $0b,
  159. DW_FORM_flag := $0c,DW_FORM_sdata := $0d,
  160. DW_FORM_strp := $0e,DW_FORM_udata := $0f,
  161. DW_FORM_ref_addr := $10,DW_FORM_ref1 := $11,
  162. DW_FORM_ref2 := $12,DW_FORM_ref4 := $13,
  163. DW_FORM_ref8 := $14,DW_FORM_ref_udata := $15,
  164. DW_FORM_indirect := $16);
  165. TDwarfFile = record
  166. Index: integer;
  167. Name: PChar;
  168. end;
  169. { TDebugInfoDwarf }
  170. TDebugInfoDwarf = class(TDebugInfo)
  171. private
  172. currabbrevnumber : longint;
  173. { collect all defs in one list so we can reset them easily }
  174. nextdefnumber : longint;
  175. defnumberlist : TFPObjectList;
  176. writing_def_dwarf : boolean;
  177. { use this defs to create info for variants and file handles }
  178. { unused (MWE)
  179. filerecdef,
  180. textrecdef : tdef;
  181. }
  182. dirlist: Tdictionary;
  183. filesequence: Integer;
  184. loclist: tdynamicarray;
  185. asmline: TAsmList;
  186. function get_file_index(afile: tinputfile): Integer;
  187. procedure write_symtable_syms(st:tsymtable);
  188. function def_dwarf_lab(def:tdef) : tasmsymbol;
  189. protected
  190. isdwarf64: Boolean;
  191. vardatadef: trecorddef;
  192. procedure append_entry(tag : tdwarf_tag;has_children : boolean;data : array of const);
  193. procedure append_labelentry(attr : tdwarf_attribute;sym : tasmsymbol);
  194. procedure append_labelentry_ref(attr : tdwarf_attribute;sym : tasmsymbol);
  195. procedure append_labelentry_data(attr : tdwarf_attribute;sym : tasmsymbol);
  196. procedure appendtag(list:TAsmList;def:tdef);
  197. procedure appendtag_orddef(def:torddef); virtual;
  198. procedure appendtag_floatdef(def:tfloatdef); virtual;
  199. procedure appendtag_filedef(def:tfiledef); virtual;
  200. procedure appendtag_enumdef(def:tenumdef); virtual;
  201. procedure appendtag_arraydef(def:tarraydef); virtual;
  202. procedure appendtag_recorddef(def:trecorddef); virtual;
  203. procedure appendtag_objectdef(def:tobjectdef); virtual; abstract;
  204. procedure appendtag_pointerdef(def:tpointerdef); virtual;
  205. procedure appendtag_stringdef(def:tstringdef); virtual;
  206. procedure appendtag_procvardef(def:tprocvardef); virtual;
  207. procedure appendtag_variantdef(def:tvariantdef); virtual; abstract;
  208. procedure appendtag_setdef(def:tsetdef); virtual; abstract;
  209. procedure appendtag_formaldef(def:tformaldef); virtual;
  210. procedure appendtag_undefineddef(def:tundefineddef); virtual; abstract;
  211. procedure appendsym(sym:tsym);
  212. procedure appendsym_var(sym:tabstractnormalvarsym); virtual;
  213. procedure appendsym_fieldvar(sym:tfieldvarsym); virtual;
  214. procedure appendsym_unit(sym:tunitsym); virtual;
  215. procedure appendsym_const(sym:tconstsym); virtual;
  216. procedure appendsym_type(sym:ttypesym); virtual;
  217. procedure appendsym_typedconst(sym:ttypedconstsym); virtual;
  218. procedure appendsym_label(sym:tlabelsym); virtual;
  219. procedure appendsym_absolute(sym:tabsolutevarsym); virtual;
  220. procedure appendsym_property(sym:tpropertysym); virtual;
  221. procedure appendsym_proc(sym:tprocsym); virtual;
  222. procedure appendprocdef(pd:tprocdef); virtual;
  223. procedure enum_members_callback(p:Tnamedindexitem;arg:pointer);
  224. procedure finish_children;
  225. procedure finish_entry;
  226. procedure insertdef_dependency(list:TAsmList;def:tdef); virtual;
  227. public
  228. constructor Create;override;
  229. destructor Destroy;override;
  230. procedure insertdef(list:TAsmList;def:tdef);override;
  231. procedure insertmoduleinfo;override;
  232. procedure inserttypeinfo;override;
  233. procedure referencesections(list:TAsmList);override;
  234. procedure insertlineinfo(list:TAsmList);override;
  235. function dwarf_version: Word; virtual; abstract;
  236. procedure write_symtable_defs(list:TAsmList;st:tsymtable);override;
  237. end;
  238. { TDebugInfoDwarf2 }
  239. TDebugInfoDwarf2 = class(TDebugInfoDwarf)
  240. private
  241. protected
  242. procedure appendtag_filedef(def:tfiledef); override;
  243. procedure appendtag_formaldef(def:tformaldef); override;
  244. procedure appendtag_objectdef(def:tobjectdef); override;
  245. procedure appendtag_setdef(def:tsetdef); override;
  246. procedure appendtag_undefineddef(def:tundefineddef); override;
  247. procedure appendtag_variantdef(def:tvariantdef); override;
  248. public
  249. function dwarf_version: Word; override;
  250. end;
  251. { TDebugInfoDwarf3 }
  252. TDebugInfoDwarf3 = class(TDebugInfoDwarf)
  253. private
  254. procedure property_write_defs(p :tnamedindexitem;arg:pointer);
  255. protected
  256. procedure appendtag_filedef(def:tfiledef); override;
  257. procedure appendtag_formaldef(def:tformaldef); override;
  258. procedure appendtag_objectdef(def:tobjectdef); override;
  259. procedure appendtag_setdef(def:tsetdef); override;
  260. procedure appendtag_undefineddef(def:tundefineddef); override;
  261. procedure appendtag_variantdef(def:tvariantdef); override;
  262. procedure insertdef_dependency(list:TAsmList;def:tdef); override;
  263. public
  264. function dwarf_version: Word; override;
  265. end;
  266. implementation
  267. uses
  268. version,
  269. cutils,
  270. globtype,
  271. globals,
  272. verbose,
  273. systems,
  274. cpubase,
  275. cgbase,
  276. fmodule,
  277. defutil,
  278. symconst,symtable
  279. ;
  280. const
  281. LINE_BASE = 1;
  282. OPCODE_BASE = 13;
  283. const
  284. DW_TAG_lo_user = $4080;
  285. DW_TAG_hi_user = $ffff;
  286. { Flag that tells whether entry has a child or not. }
  287. DW_children_no = 0;
  288. DW_children_yes = 1;
  289. const
  290. { Implementation-defined range start. }
  291. DW_AT_lo_user = $2000;
  292. { Implementation-defined range end. }
  293. DW_AT_hi_user = $3ff0;
  294. type
  295. { Source language names and codes. }
  296. tdwarf_source_language = (DW_LANG_C89 := $0001,DW_LANG_C := $0002,DW_LANG_Ada83 := $0003,
  297. DW_LANG_C_plus_plus := $0004,DW_LANG_Cobol74 := $0005,
  298. DW_LANG_Cobol85 := $0006,DW_LANG_Fortran77 := $0007,
  299. DW_LANG_Fortran90 := $0008,DW_LANG_Pascal83 := $0009,
  300. DW_LANG_Modula2 := $000a,DW_LANG_Java := $000b,
  301. { DWARF 3. }
  302. DW_LANG_C99 := $000c,DW_LANG_Ada95 := $000d,
  303. DW_LANG_Fortran95 := $000e,
  304. { MIPS. }
  305. DW_LANG_Mips_Assembler := $8001,
  306. { UPC. }
  307. DW_LANG_Upc := $8765
  308. );
  309. const
  310. { Implementation-defined range start. }
  311. DW_LANG_lo_user = $8000;
  312. { Implementation-defined range start. }
  313. DW_LANG_hi_user = $ffff;
  314. type
  315. { Names and codes for macro information. }
  316. tdwarf_macinfo_record_type = (DW_MACINFO_define := 1,DW_MACINFO_undef := 2,
  317. DW_MACINFO_start_file := 3,DW_MACINFO_end_file := 4,
  318. DW_MACINFO_vendor_ext := 255);
  319. type
  320. { Type encodings. }
  321. Tdwarf_type = (DW_ATE_void := $0,DW_ATE_address := $1,
  322. DW_ATE_boolean := $2,DW_ATE_complex_float := $3,
  323. DW_ATE_float := $4,DW_ATE_signed := $5,
  324. DW_ATE_signed_char := $6,DW_ATE_unsigned := $7,
  325. DW_ATE_unsigned_char := $8,DW_ATE_imaginary_float := $9,
  326. { HP extensions. }
  327. DW_ATE_HP_float80 := $80,DW_ATE_HP_complex_float80 := $81,
  328. DW_ATE_HP_float128 := $82,DW_ATE_HP_complex_float128 := $83,
  329. DW_ATE_HP_floathpintel := $84,DW_ATE_HP_imaginary_float80 := $85,
  330. DW_ATE_HP_imaginary_float128 := $86
  331. );
  332. const
  333. DW_ATE_lo_user = $80;
  334. DW_ATE_hi_user = $ff;
  335. type
  336. Tdwarf_array_dim_ordering = (DW_ORD_row_major := 0,DW_ORD_col_major := 1
  337. );
  338. { Access attribute. }
  339. Tdwarf_access_attribute = (DW_ACCESS_public := 1,DW_ACCESS_protected := 2,
  340. DW_ACCESS_private := 3);
  341. { Visibility. }
  342. Tdwarf_visibility_attribute = (DW_VIS_local := 1,DW_VIS_exported := 2,
  343. DW_VIS_qualified := 3);
  344. { Virtuality. }
  345. Tdwarf_virtuality_attribute = (DW_VIRTUALITY_none := 0,DW_VIRTUALITY_virtual := 1,
  346. DW_VIRTUALITY_pure_virtual := 2);
  347. { Case sensitivity. }
  348. Tdwarf_id_case = (DW_ID_case_sensitive := 0,DW_ID_up_case := 1,
  349. DW_ID_down_case := 2,DW_ID_case_insensitive := 3
  350. );
  351. { Calling convention. }
  352. Tdwarf_calling_convention = (DW_CC_normal := $1,DW_CC_program := $2,
  353. DW_CC_nocall := $3,DW_CC_GNU_renesas_sh := $40
  354. );
  355. { Location atom names and codes. }
  356. Tdwarf_location_atom = (DW_OP_addr := $03,DW_OP_deref := $06,DW_OP_const1u := $08,
  357. DW_OP_const1s := $09,DW_OP_const2u := $0a,
  358. DW_OP_const2s := $0b,DW_OP_const4u := $0c,
  359. DW_OP_const4s := $0d,DW_OP_const8u := $0e,
  360. DW_OP_const8s := $0f,DW_OP_constu := $10,
  361. DW_OP_consts := $11,DW_OP_dup := $12,DW_OP_drop := $13,
  362. DW_OP_over := $14,DW_OP_pick := $15,DW_OP_swap := $16,
  363. DW_OP_rot := $17,DW_OP_xderef := $18,DW_OP_abs := $19,
  364. DW_OP_and := $1a,DW_OP_div := $1b,DW_OP_minus := $1c,
  365. DW_OP_mod := $1d,DW_OP_mul := $1e,DW_OP_neg := $1f,
  366. DW_OP_not := $20,DW_OP_or := $21,DW_OP_plus := $22,
  367. DW_OP_plus_uconst := $23,DW_OP_shl := $24,
  368. DW_OP_shr := $25,DW_OP_shra := $26,DW_OP_xor := $27,
  369. DW_OP_bra := $28,DW_OP_eq := $29,DW_OP_ge := $2a,
  370. DW_OP_gt := $2b,DW_OP_le := $2c,DW_OP_lt := $2d,
  371. DW_OP_ne := $2e,DW_OP_skip := $2f,DW_OP_lit0 := $30,
  372. DW_OP_lit1 := $31,DW_OP_lit2 := $32,DW_OP_lit3 := $33,
  373. DW_OP_lit4 := $34,DW_OP_lit5 := $35,DW_OP_lit6 := $36,
  374. DW_OP_lit7 := $37,DW_OP_lit8 := $38,DW_OP_lit9 := $39,
  375. DW_OP_lit10 := $3a,DW_OP_lit11 := $3b,
  376. DW_OP_lit12 := $3c,DW_OP_lit13 := $3d,
  377. DW_OP_lit14 := $3e,DW_OP_lit15 := $3f,
  378. DW_OP_lit16 := $40,DW_OP_lit17 := $41,
  379. DW_OP_lit18 := $42,DW_OP_lit19 := $43,
  380. DW_OP_lit20 := $44,DW_OP_lit21 := $45,
  381. DW_OP_lit22 := $46,DW_OP_lit23 := $47,
  382. DW_OP_lit24 := $48,DW_OP_lit25 := $49,
  383. DW_OP_lit26 := $4a,DW_OP_lit27 := $4b,
  384. DW_OP_lit28 := $4c,DW_OP_lit29 := $4d,
  385. DW_OP_lit30 := $4e,DW_OP_lit31 := $4f,
  386. DW_OP_reg0 := $50,DW_OP_reg1 := $51,DW_OP_reg2 := $52,
  387. DW_OP_reg3 := $53,DW_OP_reg4 := $54,DW_OP_reg5 := $55,
  388. DW_OP_reg6 := $56,DW_OP_reg7 := $57,DW_OP_reg8 := $58,
  389. DW_OP_reg9 := $59,DW_OP_reg10 := $5a,DW_OP_reg11 := $5b,
  390. DW_OP_reg12 := $5c,DW_OP_reg13 := $5d,
  391. DW_OP_reg14 := $5e,DW_OP_reg15 := $5f,
  392. DW_OP_reg16 := $60,DW_OP_reg17 := $61,
  393. DW_OP_reg18 := $62,DW_OP_reg19 := $63,
  394. DW_OP_reg20 := $64,DW_OP_reg21 := $65,
  395. DW_OP_reg22 := $66,DW_OP_reg23 := $67,
  396. DW_OP_reg24 := $68,DW_OP_reg25 := $69,
  397. DW_OP_reg26 := $6a,DW_OP_reg27 := $6b,
  398. DW_OP_reg28 := $6c,DW_OP_reg29 := $6d,
  399. DW_OP_reg30 := $6e,DW_OP_reg31 := $6f,
  400. DW_OP_breg0 := $70,DW_OP_breg1 := $71,
  401. DW_OP_breg2 := $72,DW_OP_breg3 := $73,
  402. DW_OP_breg4 := $74,DW_OP_breg5 := $75,
  403. DW_OP_breg6 := $76,DW_OP_breg7 := $77,
  404. DW_OP_breg8 := $78,DW_OP_breg9 := $79,
  405. DW_OP_breg10 := $7a,DW_OP_breg11 := $7b,
  406. DW_OP_breg12 := $7c,DW_OP_breg13 := $7d,
  407. DW_OP_breg14 := $7e,DW_OP_breg15 := $7f,
  408. DW_OP_breg16 := $80,DW_OP_breg17 := $81,
  409. DW_OP_breg18 := $82,DW_OP_breg19 := $83,
  410. DW_OP_breg20 := $84,DW_OP_breg21 := $85,
  411. DW_OP_breg22 := $86,DW_OP_breg23 := $87,
  412. DW_OP_breg24 := $88,DW_OP_breg25 := $89,
  413. DW_OP_breg26 := $8a,DW_OP_breg27 := $8b,
  414. DW_OP_breg28 := $8c,DW_OP_breg29 := $8d,
  415. DW_OP_breg30 := $8e,DW_OP_breg31 := $8f,
  416. DW_OP_regx := $90,DW_OP_fbreg := $91,DW_OP_bregx := $92,
  417. DW_OP_piece := $93,DW_OP_deref_size := $94,
  418. DW_OP_xderef_size := $95,DW_OP_nop := $96,
  419. { DWARF 3 extensions. }
  420. DW_OP_push_object_address := $97,DW_OP_call2 := $98,
  421. DW_OP_call4 := $99,DW_OP_call_ref := $9a,
  422. { GNU extensions. }
  423. DW_OP_GNU_push_tls_address := $e0,
  424. { HP extensions. }
  425. DW_OP_HP_unknown := $e0,
  426. DW_OP_HP_is_value := $e1,DW_OP_HP_fltconst4 := $e2,
  427. DW_OP_HP_fltconst8 := $e3,DW_OP_HP_mod_range := $e4,
  428. DW_OP_HP_unmod_range := $e5,DW_OP_HP_tls := $e6
  429. );
  430. const
  431. { Implementation-defined range start. }
  432. DW_OP_lo_user = $e0;
  433. { Implementation-defined range end. }
  434. DW_OP_hi_user = $ff;
  435. const
  436. DW_LNS_extended_op = $00;
  437. { next copied from cfidwarf, need to go to something shared }
  438. DW_LNS_copy = $01;
  439. DW_LNS_advance_pc = $02;
  440. DW_LNS_advance_line = $03;
  441. DW_LNS_set_file = $04;
  442. DW_LNS_set_column = $05;
  443. DW_LNS_negate_stmt = $06;
  444. DW_LNS_set_basic_block = $07;
  445. DW_LNS_const_add_pc = $08;
  446. DW_LNS_fixed_advance_pc = $09;
  447. DW_LNS_set_prologue_end = $0a;
  448. DW_LNS_set_epilogue_begin = $0b;
  449. DW_LNS_set_isa = $0c;
  450. DW_LNE_end_sequence = $01;
  451. DW_LNE_set_address = $02;
  452. DW_LNE_define_file = $03;
  453. DW_LNE_lo_user = $80;
  454. DW_LNE_hi_user = $ff;
  455. type
  456. { TDirIndexItem }
  457. TDirIndexItem = class(TNamedIndexItem)
  458. private
  459. FFiles: TDictionary;
  460. public
  461. constructor Create(const AName: String; AIndex: Integer);
  462. destructor Destroy;override;
  463. property Files: TDictionary read FFiles;
  464. end;
  465. { TFileIndexItem }
  466. TFileIndexItem = class(TNamedIndexItem)
  467. private
  468. FDirIndex: Integer;
  469. public
  470. constructor Create(const AName: String; ADirIndex, AIndex: Integer);
  471. property DirIndex: Integer read FDirIndex;
  472. end;
  473. {****************************************************************************
  474. procs
  475. ****************************************************************************}
  476. procedure AddNamedIndexToList(p:TNamedIndexItem; arg:pointer);
  477. begin
  478. TFPList(Arg).Add(p);
  479. end;
  480. function DirListSortCompare(AItem1, AItem2: Pointer): Integer;
  481. begin
  482. Result := TDirIndexItem(AItem1).IndexNr - TDirIndexItem(AItem2).IndexNr;
  483. end;
  484. function FileListSortCompare(AItem1, AItem2: Pointer): Integer;
  485. begin
  486. Result := TFileIndexItem(AItem1).IndexNr - TFileIndexItem(AItem2).IndexNr;
  487. end;
  488. {****************************************************************************
  489. TDirIndexItem
  490. ****************************************************************************}
  491. constructor TDirIndexItem.Create(const AName: String; AIndex: Integer);
  492. begin
  493. inherited CreateName(AName);
  494. FFiles := TDictionary.Create;
  495. IndexNr := AIndex;
  496. end;
  497. destructor TDirIndexItem.Destroy;
  498. begin
  499. FFiles.Free;
  500. FFiles := nil;
  501. inherited Destroy;
  502. end;
  503. {****************************************************************************
  504. TFileIndexItem
  505. ****************************************************************************}
  506. constructor TFileIndexItem.Create(const AName: String; ADirIndex, AIndex: Integer);
  507. begin
  508. inherited CreateName(Aname);
  509. FDirIndex := ADirIndex;
  510. IndexNr := AIndex;
  511. end;
  512. {****************************************************************************
  513. TDebugInfoDwarf
  514. ****************************************************************************}
  515. function TDebugInfoDwarf.def_dwarf_lab(def:tdef) : tasmsymbol;
  516. begin
  517. { dwarf must already be written, or we must be busy writing it }
  518. if writing_def_dwarf and
  519. not(def.dbg_state in [dbg_state_writing,dbg_state_written]) then
  520. internalerror(200601241);
  521. { Keep track of used dwarf entries, this info is only usefull for dwarf entries
  522. referenced by the symbols. Definitions will always include all
  523. required stabs }
  524. if def.dbg_state=dbg_state_unused then
  525. def.dbg_state:=dbg_state_used;
  526. { Need a new label? }
  527. if not assigned(def.dwarf_lab) then
  528. begin
  529. if (df_has_dwarf_dbg_info in def.defoptions) then
  530. begin
  531. if not assigned(def.typesym) then
  532. internalerror(200610011);
  533. def.dwarf_lab:=current_asmdata.RefAsmSymbol(make_mangledname('DBG',def.owner,def.typesym.name));
  534. def.dbg_state:=dbg_state_written;
  535. end
  536. else
  537. begin
  538. { Create an exported DBG symbol if we are generating a def defined in the
  539. globalsymtable of the current unit }
  540. if assigned(def.typesym) and
  541. (def.owner.symtabletype=globalsymtable) and
  542. (def.owner.iscurrentunit) then
  543. begin
  544. def.dwarf_lab:=current_asmdata.DefineAsmSymbol(make_mangledname('DBG',def.owner,def.typesym.name),AB_GLOBAL,AT_DATA);
  545. include(def.defoptions,df_has_dwarf_dbg_info);
  546. end
  547. else
  548. current_asmdata.getdatalabel(TAsmLabel(def.dwarf_lab));
  549. end;
  550. defnumberlist.Add(def);
  551. end;
  552. result:=def.dwarf_lab;
  553. end;
  554. constructor TDebugInfoDwarf.Create;
  555. begin
  556. inherited Create;
  557. isdwarf64 := target_cpu in [cpu_iA64,cpu_x86_64,cpu_powerpc64];
  558. dirlist := tdictionary.Create;
  559. { add current dir as first item (index=0) }
  560. dirlist.insert(TDirIndexItem.Create('.', 0));
  561. asmline := TAsmList.create;
  562. loclist := tdynamicarray.Create(4096);
  563. end;
  564. destructor TDebugInfoDwarf.Destroy;
  565. begin
  566. dirlist.Free;
  567. dirlist := nil;
  568. loclist.Free;
  569. loclist := nil;
  570. inherited Destroy;
  571. end;
  572. function TDebugInfoDwarf.get_file_index(afile: tinputfile): Integer;
  573. var
  574. dirname: String;
  575. diritem: TDirIndexItem;
  576. diridx: Integer;
  577. fileitem: TFileIndexItem;
  578. begin
  579. if afile.path^ = '' then
  580. dirname := '.'
  581. else
  582. dirname := afile.path^;
  583. diritem := TDirIndexItem(dirlist.search(dirname));
  584. if diritem = nil then
  585. begin
  586. diritem := TDirIndexItem.Create(dirname, dirlist.Count);
  587. diritem := TDirIndexItem(dirlist.insert(diritem));
  588. end;
  589. diridx := diritem.IndexNr;
  590. fileitem := TFileIndexItem(diritem.files.search(afile.name^));
  591. if fileitem = nil then
  592. begin
  593. Inc(filesequence);
  594. fileitem := TFileIndexItem.Create(afile.name^, diridx, filesequence);
  595. fileitem := TFileIndexItem(diritem.files.insert(fileitem));
  596. end;
  597. Result := fileitem.IndexNr;
  598. end;
  599. { writing the data through a few simply procedures allows to create easily extra information
  600. for debugging of debug info }
  601. procedure TDebugInfoDwarf.append_entry(tag : tdwarf_tag;has_children : boolean;data : array of const);
  602. var
  603. i : longint;
  604. begin
  605. { todo: store defined abbrevs, so you have to define tehm only once (for this unit) (MWE) }
  606. inc(currabbrevnumber);
  607. current_asmdata.asmlists[al_dwarf_abbrev].concat(tai_comment.Create(strpnew('Abbrev '+tostr(currabbrevnumber))));
  608. { abbrev number }
  609. current_asmdata.asmlists[al_dwarf_info].concat(tai_const.create_uleb128bit(currabbrevnumber));
  610. current_asmdata.asmlists[al_dwarf_abbrev].concat(tai_const.create_uleb128bit(currabbrevnumber));
  611. { tag }
  612. current_asmdata.asmlists[al_dwarf_abbrev].concat(tai_const.create_uleb128bit(ord(tag)));
  613. { children? }
  614. current_asmdata.asmlists[al_dwarf_abbrev].concat(tai_const.create_8bit(ord(has_children)));
  615. i:=0;
  616. while i<=high(data) do
  617. begin
  618. { attribute }
  619. if data[i].VType=vtInteger then
  620. begin
  621. current_asmdata.asmlists[al_dwarf_abbrev].concat(tai_const.create_uleb128bit(data[i].VInteger));
  622. end
  623. else
  624. internalerror(200601261);
  625. inc(i);
  626. { form }
  627. if data[i].VType=vtInteger then
  628. begin
  629. current_asmdata.asmlists[al_dwarf_abbrev].concat(tai_const.create_uleb128bit(data[i].VInteger));
  630. end
  631. else
  632. internalerror(200601262);
  633. inc(i);
  634. { info itself }
  635. case tdwarf_form(data[i-1].VInteger) of
  636. DW_FORM_string:
  637. case data[i].VType of
  638. vtChar:
  639. current_asmdata.asmlists[al_dwarf_info].concat(tai_string.create(data[i].VChar));
  640. vtString:
  641. current_asmdata.asmlists[al_dwarf_info].concat(tai_string.create(data[i].VString^));
  642. vtAnsistring:
  643. current_asmdata.asmlists[al_dwarf_info].concat(tai_string.create(Ansistring(data[i].VAnsiString)));
  644. else
  645. internalerror(200601264);
  646. end;
  647. DW_FORM_flag:
  648. current_asmdata.asmlists[al_dwarf_info].concat(tai_const.create_8bit(byte(data[i].VBoolean)));
  649. DW_FORM_data1:
  650. case data[i].VType of
  651. vtInteger:
  652. current_asmdata.asmlists[al_dwarf_info].concat(tai_const.create_8bit(data[i].VInteger));
  653. vtInt64:
  654. current_asmdata.asmlists[al_dwarf_info].concat(tai_const.create_8bit(data[i].VInt64^));
  655. vtQWord:
  656. current_asmdata.asmlists[al_dwarf_info].concat(tai_const.create_8bit(data[i].VQWord^));
  657. else
  658. internalerror(200602143);
  659. end;
  660. DW_FORM_data2:
  661. case data[i].VType of
  662. vtInteger:
  663. current_asmdata.asmlists[al_dwarf_info].concat(tai_const.create_16bit(data[i].VInteger));
  664. vtInt64:
  665. current_asmdata.asmlists[al_dwarf_info].concat(tai_const.create_16bit(data[i].VInt64^));
  666. vtQWord:
  667. current_asmdata.asmlists[al_dwarf_info].concat(tai_const.create_16bit(data[i].VQWord^));
  668. else
  669. internalerror(200602144);
  670. end;
  671. DW_FORM_data4:
  672. case data[i].VType of
  673. vtInteger:
  674. current_asmdata.asmlists[al_dwarf_info].concat(tai_const.create_32bit(data[i].VInteger));
  675. vtInt64:
  676. current_asmdata.asmlists[al_dwarf_info].concat(tai_const.create_32bit(data[i].VInt64^));
  677. vtQWord:
  678. current_asmdata.asmlists[al_dwarf_info].concat(tai_const.create_32bit(data[i].VQWord^));
  679. else
  680. internalerror(200602145);
  681. end;
  682. DW_FORM_data8:
  683. case data[i].VType of
  684. vtInteger:
  685. current_asmdata.asmlists[al_dwarf_info].concat(tai_const.create_64bit(data[i].VInteger));
  686. vtInt64:
  687. current_asmdata.asmlists[al_dwarf_info].concat(tai_const.create_64bit(data[i].VInt64^));
  688. vtQWord:
  689. current_asmdata.asmlists[al_dwarf_info].concat(tai_const.create_64bit(data[i].VQWord^));
  690. else
  691. internalerror(200602146);
  692. end;
  693. DW_FORM_sdata:
  694. case data[i].VType of
  695. vtInteger:
  696. current_asmdata.asmlists[al_dwarf_info].concat(tai_const.create_sleb128bit(data[i].VInteger));
  697. vtInt64:
  698. current_asmdata.asmlists[al_dwarf_info].concat(tai_const.create_sleb128bit(data[i].VInt64^));
  699. vtQWord:
  700. current_asmdata.asmlists[al_dwarf_info].concat(tai_const.create_sleb128bit(data[i].VQWord^));
  701. else
  702. internalerror(200601285);
  703. end;
  704. DW_FORM_udata:
  705. case data[i].VType of
  706. vtInteger:
  707. current_asmdata.asmlists[al_dwarf_info].concat(tai_const.create_uleb128bit(data[i].VInteger));
  708. vtInt64:
  709. current_asmdata.asmlists[al_dwarf_info].concat(tai_const.create_uleb128bit(data[i].VInt64^));
  710. vtQWord:
  711. current_asmdata.asmlists[al_dwarf_info].concat(tai_const.create_uleb128bit(data[i].VQWord^));
  712. else
  713. internalerror(200601284);
  714. end;
  715. { block gets only the size, the rest is appended manually by the caller }
  716. DW_FORM_block1:
  717. case data[i].VType of
  718. vtInteger:
  719. current_asmdata.asmlists[al_dwarf_info].concat(tai_const.create_8bit(data[i].VInteger));
  720. vtInt64:
  721. current_asmdata.asmlists[al_dwarf_info].concat(tai_const.create_8bit(data[i].VInt64^));
  722. vtQWord:
  723. current_asmdata.asmlists[al_dwarf_info].concat(tai_const.create_8bit(data[i].VQWord^));
  724. else
  725. internalerror(200602141);
  726. end;
  727. else
  728. internalerror(200601263);
  729. end;
  730. inc(i);
  731. end;
  732. end;
  733. procedure TDebugInfoDwarf.append_labelentry(attr : tdwarf_attribute;sym : tasmsymbol);
  734. begin
  735. current_asmdata.asmlists[al_dwarf_abbrev].concat(tai_const.create_uleb128bit(ord(attr)));
  736. current_asmdata.asmlists[al_dwarf_abbrev].concat(tai_const.create_uleb128bit(ord(DW_FORM_addr)));
  737. current_asmdata.asmlists[al_dwarf_info].concat(tai_const.create_sym(sym));
  738. end;
  739. procedure TDebugInfoDwarf.append_labelentry_ref(attr : tdwarf_attribute;sym : tasmsymbol);
  740. begin
  741. current_asmdata.asmlists[al_dwarf_abbrev].concat(tai_const.create_uleb128bit(ord(attr)));
  742. current_asmdata.asmlists[al_dwarf_abbrev].concat(tai_const.create_uleb128bit(ord(DW_FORM_ref_addr)));
  743. current_asmdata.asmlists[al_dwarf_info].concat(tai_const.create_sym(sym));
  744. end;
  745. procedure TDebugInfoDwarf.append_labelentry_data(attr : tdwarf_attribute;sym : tasmsymbol);
  746. begin
  747. current_asmdata.asmlists[al_dwarf_abbrev].concat(tai_const.create_uleb128bit(ord(attr)));
  748. if isdwarf64 then
  749. current_asmdata.asmlists[al_dwarf_abbrev].concat(tai_const.create_uleb128bit(ord(DW_FORM_data8)))
  750. else
  751. current_asmdata.asmlists[al_dwarf_abbrev].concat(tai_const.create_uleb128bit(ord(DW_FORM_data4)));
  752. current_asmdata.asmlists[al_dwarf_info].concat(tai_const.create_sym(sym));
  753. end;
  754. procedure TDebugInfoDwarf.finish_entry;
  755. begin
  756. current_asmdata.asmlists[al_dwarf_abbrev].concat(tai_const.create_8bit(0));
  757. current_asmdata.asmlists[al_dwarf_abbrev].concat(tai_const.create_8bit(0));
  758. end;
  759. procedure TDebugInfoDwarf.finish_children;
  760. begin
  761. current_asmdata.asmlists[al_dwarf_info].concat(tai_const.create_8bit(0));
  762. end;
  763. procedure TDebugInfoDwarf.enum_members_callback(p: Tnamedindexitem; arg: pointer);
  764. begin
  765. case tsym(p).typ of
  766. fieldvarsym:
  767. appendsym_fieldvar(tfieldvarsym(p));
  768. propertysym:
  769. appendsym_property(tpropertysym(p));
  770. procsym:
  771. appendsym_proc(tprocsym(p));
  772. end;
  773. end;
  774. procedure TDebugInfoDwarf.appendtag_orddef(def:torddef);
  775. begin
  776. case def.typ of
  777. s8bit,
  778. s16bit,
  779. s32bit :
  780. begin
  781. { we should generate a subrange type here }
  782. if assigned(def.typesym) then
  783. append_entry(DW_TAG_base_type,false,[
  784. DW_AT_name,DW_FORM_string,def.typesym.name+#0,
  785. DW_AT_encoding,DW_FORM_data1,DW_ATE_signed,
  786. DW_AT_byte_size,DW_FORM_data1,def.size
  787. ])
  788. else
  789. append_entry(DW_TAG_base_type,false,[
  790. DW_AT_encoding,DW_FORM_data1,DW_ATE_signed,
  791. DW_AT_byte_size,DW_FORM_data1,def.size
  792. ]);
  793. finish_entry;
  794. end;
  795. u8bit,
  796. u16bit,
  797. u32bit :
  798. begin
  799. { we should generate a subrange type here }
  800. if assigned(def.typesym) then
  801. append_entry(DW_TAG_base_type,false,[
  802. DW_AT_name,DW_FORM_string,def.typesym.name+#0,
  803. DW_AT_encoding,DW_FORM_data1,DW_ATE_unsigned,
  804. DW_AT_byte_size,DW_FORM_data1,def.size
  805. ])
  806. else
  807. append_entry(DW_TAG_base_type,false,[
  808. DW_AT_encoding,DW_FORM_data1,DW_ATE_unsigned,
  809. DW_AT_byte_size,DW_FORM_data1,def.size
  810. ]);
  811. finish_entry;
  812. end;
  813. uvoid :
  814. begin
  815. { gdb 6.4 doesn't support DW_TAG_unspecified_type so we
  816. replace it with a unsigned type with size 0 (FK)
  817. }
  818. append_entry(DW_TAG_base_type,false,[
  819. DW_AT_name,DW_FORM_string,'Void'#0,
  820. DW_AT_encoding,DW_FORM_data1,DW_ATE_unsigned,
  821. DW_AT_byte_size,DW_FORM_data1,0
  822. ]);
  823. finish_entry;
  824. end;
  825. uchar :
  826. begin
  827. append_entry(DW_TAG_base_type,false,[
  828. DW_AT_name,DW_FORM_string,'Char'#0,
  829. DW_AT_encoding,DW_FORM_data1,DW_ATE_unsigned_char,
  830. DW_AT_byte_size,DW_FORM_data1,1
  831. ]);
  832. finish_entry;
  833. end;
  834. uwidechar :
  835. begin
  836. append_entry(DW_TAG_base_type,false,[
  837. DW_AT_name,DW_FORM_string,'WideChar'#0,
  838. DW_AT_encoding,DW_FORM_data1,DW_ATE_unsigned_char,
  839. DW_AT_byte_size,DW_FORM_data1,2
  840. ]);
  841. finish_entry;
  842. end;
  843. bool8bit :
  844. begin
  845. append_entry(DW_TAG_base_type,false,[
  846. DW_AT_name,DW_FORM_string,'Boolean'#0,
  847. DW_AT_encoding,DW_FORM_data1,DW_ATE_unsigned_char,
  848. DW_AT_byte_size,DW_FORM_data1,1
  849. ]);
  850. finish_entry;
  851. end;
  852. bool16bit :
  853. begin
  854. append_entry(DW_TAG_base_type,false,[
  855. DW_AT_name,DW_FORM_string,'WordBool'#0,
  856. DW_AT_encoding,DW_FORM_data1,DW_ATE_boolean,
  857. DW_AT_byte_size,DW_FORM_data1,2
  858. ]);
  859. finish_entry;
  860. end;
  861. bool32bit :
  862. begin
  863. append_entry(DW_TAG_base_type,false,[
  864. DW_AT_name,DW_FORM_string,'LongBool'#0,
  865. DW_AT_encoding,DW_FORM_data1,DW_ATE_boolean,
  866. DW_AT_byte_size,DW_FORM_data1,4
  867. ]);
  868. finish_entry;
  869. end;
  870. bool64bit :
  871. begin
  872. append_entry(DW_TAG_base_type,false,[
  873. DW_AT_name,DW_FORM_string,'QWordBool'#0,
  874. DW_AT_encoding,DW_FORM_data1,DW_ATE_boolean,
  875. DW_AT_byte_size,DW_FORM_data1,8
  876. ]);
  877. finish_entry;
  878. end;
  879. u64bit :
  880. begin
  881. append_entry(DW_TAG_base_type,false,[
  882. DW_AT_name,DW_FORM_string,'QWord'#0,
  883. DW_AT_encoding,DW_FORM_data1,DW_ATE_unsigned,
  884. DW_AT_byte_size,DW_FORM_data1,8
  885. ]);
  886. finish_entry;
  887. end;
  888. scurrency :
  889. begin
  890. { we should use DW_ATE_signed_fixed, however it isn't supported yet by GDB (FK) }
  891. append_entry(DW_TAG_base_type,false,[
  892. DW_AT_name,DW_FORM_string,'Currency'#0,
  893. DW_AT_encoding,DW_FORM_data1,DW_ATE_signed,
  894. DW_AT_byte_size,DW_FORM_data1,8
  895. ]);
  896. finish_entry;
  897. end;
  898. s64bit :
  899. begin
  900. append_entry(DW_TAG_base_type,false,[
  901. DW_AT_name,DW_FORM_string,'Int64'#0,
  902. DW_AT_encoding,DW_FORM_data1,DW_ATE_signed,
  903. DW_AT_byte_size,DW_FORM_data1,8
  904. ]);
  905. finish_entry;
  906. end;
  907. else
  908. internalerror(200601287);
  909. end;
  910. end;
  911. procedure TDebugInfoDwarf.appendtag_floatdef(def:tfloatdef);
  912. begin
  913. case def.typ of
  914. s32real,
  915. s64real,
  916. s80real:
  917. if assigned(def.typesym) then
  918. append_entry(DW_TAG_base_type,false,[
  919. DW_AT_name,DW_FORM_string,def.typesym.name+#0,
  920. DW_AT_encoding,DW_FORM_data1,DW_ATE_float,
  921. DW_AT_byte_size,DW_FORM_data1,def.size
  922. ])
  923. else
  924. append_entry(DW_TAG_base_type,false,[
  925. DW_AT_encoding,DW_FORM_data1,DW_ATE_float,
  926. DW_AT_byte_size,DW_FORM_data1,def.size
  927. ]);
  928. s64currency:
  929. { we should use DW_ATE_signed_fixed, however it isn't supported yet by GDB (FK) }
  930. if assigned(def.typesym) then
  931. append_entry(DW_TAG_base_type,false,[
  932. DW_AT_name,DW_FORM_string,def.typesym.name+#0,
  933. DW_AT_encoding,DW_FORM_data1,DW_ATE_signed,
  934. DW_AT_byte_size,DW_FORM_data1,8
  935. ])
  936. else
  937. append_entry(DW_TAG_base_type,false,[
  938. DW_AT_encoding,DW_FORM_data1,DW_ATE_signed,
  939. DW_AT_byte_size,DW_FORM_data1,8
  940. ]);
  941. s64comp:
  942. if assigned(def.typesym) then
  943. append_entry(DW_TAG_base_type,false,[
  944. DW_AT_name,DW_FORM_string,def.typesym.name+#0,
  945. DW_AT_encoding,DW_FORM_data1,DW_ATE_signed,
  946. DW_AT_byte_size,DW_FORM_data1,8
  947. ])
  948. else
  949. append_entry(DW_TAG_base_type,false,[
  950. DW_AT_encoding,DW_FORM_data1,DW_ATE_signed,
  951. DW_AT_byte_size,DW_FORM_data1,8
  952. ]);
  953. else
  954. internalerror(200601289);
  955. end;
  956. finish_entry;
  957. end;
  958. procedure TDebugInfoDwarf.appendtag_formaldef(def: tformaldef);
  959. begin
  960. { implemented in derived classes }
  961. end;
  962. procedure TDebugInfoDwarf.appendtag_enumdef(def:tenumdef);
  963. var
  964. hp : tenumsym;
  965. begin
  966. if assigned(def.typesym) then
  967. append_entry(DW_TAG_enumeration_type,true,[
  968. DW_AT_name,DW_FORM_string,def.typesym.name+#0,
  969. DW_AT_byte_size,DW_FORM_data1,def.size
  970. ])
  971. else
  972. append_entry(DW_TAG_enumeration_type,true,[
  973. DW_AT_byte_size,DW_FORM_data1,def.size
  974. ]);
  975. if assigned(def.basedef) then
  976. append_labelentry_ref(DW_AT_type,def_dwarf_lab(def.basedef));
  977. finish_entry;
  978. { write enum symbols }
  979. hp:=tenumsym(def.firstenum);
  980. while assigned(hp) do
  981. begin
  982. append_entry(DW_TAG_enumerator,false,[
  983. DW_AT_name,DW_FORM_string,hp.name+#0,
  984. DW_AT_const_value,DW_FORM_data4,hp.value
  985. ]);
  986. finish_entry;
  987. hp:=tenumsym(hp).nextenum;
  988. end;
  989. finish_children;
  990. end;
  991. procedure TDebugInfoDwarf.appendtag_filedef(def: tfiledef);
  992. begin
  993. { implemented in derived classes }
  994. end;
  995. procedure TDebugInfoDwarf.appendtag_arraydef(def:tarraydef);
  996. var
  997. size : aint;
  998. elesize : aint;
  999. begin
  1000. if is_special_array(def) then
  1001. size:=def.elesize
  1002. else
  1003. size:=def.size;
  1004. if not is_packed_array(def) then
  1005. elesize := def.elesize*8
  1006. else
  1007. elesize := def.elepackedbitsize;
  1008. if assigned(def.typesym) then
  1009. append_entry(DW_TAG_array_type,true,[
  1010. DW_AT_name,DW_FORM_string,def.typesym.name+#0,
  1011. DW_AT_byte_size,DW_FORM_udata,size,
  1012. DW_AT_stride_size,DW_FORM_udata,elesize
  1013. ])
  1014. else
  1015. append_entry(DW_TAG_array_type,true,[
  1016. DW_AT_byte_size,DW_FORM_udata,size,
  1017. DW_AT_stride_size,DW_FORM_udata,elesize
  1018. ]);
  1019. append_labelentry_ref(DW_AT_type,def_dwarf_lab(def.elementtype.def));
  1020. if is_dynamic_array(def) then
  1021. begin
  1022. { !!! FIXME !!! }
  1023. { gdb's dwarf implementation sucks, so we can't use DW_OP_push_object here (FK)
  1024. { insert location attribute manually }
  1025. current_asmdata.asmlists[al_dwarf_abbrev].concat(tai_const.create_uleb128bit(DW_AT_data_location));
  1026. current_asmdata.asmlists[al_dwarf_abbrev].concat(tai_const.create_uleb128bit(DW_FORM_block1));
  1027. current_asmdata.asmlists[al_dwarf_info].concat(tai_const.create_8bit(1));
  1028. current_asmdata.asmlists[al_dwarf_info].concat(tai_const.create_8bit(DW_OP_push_object));
  1029. current_asmdata.asmlists[al_dwarf_info].concat(tai_const.create_8bit(DW_OP_deref));
  1030. }
  1031. finish_entry;
  1032. { to simplify things, we don't write a multidimensional array here }
  1033. append_entry(DW_TAG_subrange_type,false,[
  1034. DW_AT_lower_bound,DW_FORM_udata,0,
  1035. DW_AT_upper_bound,DW_FORM_udata,0
  1036. ]);
  1037. append_labelentry_ref(DW_AT_type,def_dwarf_lab(def.rangetype.def));
  1038. finish_entry;
  1039. end
  1040. else
  1041. begin
  1042. finish_entry;
  1043. { to simplify things, we don't write a multidimensional array here }
  1044. append_entry(DW_TAG_subrange_type,false,[
  1045. DW_AT_lower_bound,DW_FORM_sdata,def.lowrange,
  1046. DW_AT_upper_bound,DW_FORM_sdata,def.highrange
  1047. ]);
  1048. append_labelentry_ref(DW_AT_type,def_dwarf_lab(def.rangetype.def));
  1049. finish_entry;
  1050. end;
  1051. finish_children;
  1052. end;
  1053. procedure TDebugInfoDwarf.appendtag_recorddef(def:trecorddef);
  1054. begin
  1055. if assigned(def.typesym) then
  1056. append_entry(DW_TAG_structure_type,true,[
  1057. DW_AT_name,DW_FORM_string,def.typesym.name+#0,
  1058. DW_AT_byte_size,DW_FORM_udata,def.size
  1059. ])
  1060. else
  1061. append_entry(DW_TAG_structure_type,true,[
  1062. DW_AT_byte_size,DW_FORM_udata,def.size
  1063. ]);
  1064. finish_entry;
  1065. def.symtable.foreach(@enum_members_callback,nil);
  1066. finish_children;
  1067. end;
  1068. procedure TDebugInfoDwarf.appendtag_pointerdef(def:tpointerdef);
  1069. begin
  1070. append_entry(DW_TAG_pointer_type,false,[]);
  1071. if not(is_voidpointer(def)) then
  1072. append_labelentry_ref(DW_AT_type,def_dwarf_lab(def.pointertype.def));
  1073. finish_entry;
  1074. end;
  1075. procedure TDebugInfoDwarf.appendtag_stringdef(def:tstringdef);
  1076. var
  1077. slen : aint;
  1078. arr : tasmlabel;
  1079. begin
  1080. case def.string_typ of
  1081. st_shortstring:
  1082. begin
  1083. { fix length of openshortstring }
  1084. slen:=def.len;
  1085. if slen=0 then
  1086. slen:=255;
  1087. { create a structure with two elements }
  1088. current_asmdata.getdatalabel(arr);
  1089. append_entry(DW_TAG_structure_type,true,[
  1090. DW_AT_name,DW_FORM_string,'ShortString'#0,
  1091. DW_AT_byte_size,DW_FORM_data1,2*sizeof(aint)
  1092. ]);
  1093. finish_entry;
  1094. { length entry }
  1095. append_entry(DW_TAG_member,false,[
  1096. DW_AT_name,DW_FORM_string,'Length'#0,
  1097. DW_AT_data_member_location,DW_FORM_block1,1+lengthuleb128(0)
  1098. ]);
  1099. current_asmdata.asmlists[al_dwarf_info].concat(tai_const.create_8bit(ord(DW_OP_plus_uconst)));
  1100. current_asmdata.asmlists[al_dwarf_info].concat(tai_const.create_uleb128bit(0));
  1101. append_labelentry_ref(DW_AT_type,def_dwarf_lab(u8inttype.def));
  1102. finish_entry;
  1103. { string data entry }
  1104. append_entry(DW_TAG_member,false,[
  1105. DW_AT_name,DW_FORM_string,'Data'#0,
  1106. DW_AT_data_member_location,DW_FORM_block1,1+lengthuleb128(1)
  1107. ]);
  1108. current_asmdata.asmlists[al_dwarf_info].concat(tai_const.create_8bit(ord(DW_OP_plus_uconst)));
  1109. current_asmdata.asmlists[al_dwarf_info].concat(tai_const.create_uleb128bit(1));
  1110. append_labelentry_ref(DW_AT_type,arr);
  1111. finish_entry;
  1112. finish_children;
  1113. { now the data array }
  1114. current_asmdata.asmlists[al_dwarf_info].concat(tai_symbol.create(arr,0));
  1115. append_entry(DW_TAG_array_type,true,[
  1116. DW_AT_byte_size,DW_FORM_udata,def.size,
  1117. DW_AT_stride_size,DW_FORM_udata,1*8
  1118. ]);
  1119. append_labelentry_ref(DW_AT_type,def_dwarf_lab(cchartype.def));
  1120. finish_entry;
  1121. append_entry(DW_TAG_subrange_type,false,[
  1122. DW_AT_lower_bound,DW_FORM_udata,0,
  1123. DW_AT_upper_bound,DW_FORM_udata,slen
  1124. ]);
  1125. append_labelentry_ref(DW_AT_type,def_dwarf_lab(u8inttype.def));
  1126. finish_entry;
  1127. finish_children;
  1128. end;
  1129. st_longstring:
  1130. begin
  1131. {
  1132. charst:=def_stab_number(cchartype.def);
  1133. bytest:=def_stab_number(u8inttype.def);
  1134. longst:=def_stab_number(u32inttype.def);
  1135. result:=def_stabstr_evaluate(def,'s$1length:$2,0,32;dummy:$6,32,8;st:ar$2;1;$3;$4,40,$5;;',
  1136. [tostr(def.len+5),longst,tostr(def.len),charst,tostr(def.len*8),bytest]);
  1137. }
  1138. end;
  1139. st_ansistring:
  1140. begin
  1141. { looks like a pchar }
  1142. append_entry(DW_TAG_pointer_type,false,[]);
  1143. append_labelentry_ref(DW_AT_type,def_dwarf_lab(cchartype.def));
  1144. finish_entry;
  1145. end;
  1146. st_widestring:
  1147. begin
  1148. { looks like a pwidechar }
  1149. append_entry(DW_TAG_pointer_type,false,[]);
  1150. append_labelentry_ref(DW_AT_type,def_dwarf_lab(cwidechartype.def));
  1151. finish_entry;
  1152. end;
  1153. end;
  1154. end;
  1155. procedure TDebugInfoDwarf.appendtag_procvardef(def:tprocvardef);
  1156. procedure doappend;
  1157. var
  1158. i : longint;
  1159. begin
  1160. if assigned(def.typesym) then
  1161. append_entry(DW_TAG_subroutine_type,true,[
  1162. DW_AT_name,DW_FORM_string,def.typesym.name+#0,
  1163. DW_AT_prototyped,DW_FORM_flag,true
  1164. ])
  1165. else
  1166. append_entry(DW_TAG_subroutine_type,true,[
  1167. DW_AT_prototyped,DW_FORM_flag,true
  1168. ]);
  1169. if not(is_void(tprocvardef(def).rettype.def)) then
  1170. append_labelentry_ref(DW_AT_type,def_dwarf_lab(tprocvardef(def).rettype.def));
  1171. finish_entry;
  1172. { write parameters }
  1173. for i:=0 to def.paras.count-1 do
  1174. begin
  1175. append_entry(DW_TAG_formal_parameter,false,[
  1176. DW_AT_name,DW_FORM_string,tparavarsym(def.paras[i]).name+#0
  1177. ]);
  1178. append_labelentry_ref(DW_AT_type,def_dwarf_lab(tparavarsym(def.paras[i]).vartype.def));
  1179. finish_entry;
  1180. end;
  1181. finish_children;
  1182. end;
  1183. var
  1184. proc : tasmlabel;
  1185. begin
  1186. if def.is_methodpointer then
  1187. begin
  1188. { create a structure with two elements }
  1189. current_asmdata.getdatalabel(proc);
  1190. append_entry(DW_TAG_structure_type,true,[
  1191. DW_AT_byte_size,DW_FORM_data1,2*sizeof(aint)
  1192. ]);
  1193. finish_entry;
  1194. { proc entry }
  1195. append_entry(DW_TAG_member,false,[
  1196. DW_AT_name,DW_FORM_string,'Proc'#0,
  1197. DW_AT_data_member_location,DW_FORM_block1,1+lengthuleb128(0)
  1198. ]);
  1199. current_asmdata.asmlists[al_dwarf_info].concat(tai_const.create_8bit(ord(DW_OP_plus_uconst)));
  1200. current_asmdata.asmlists[al_dwarf_info].concat(tai_const.create_uleb128bit(0));
  1201. append_labelentry_ref(DW_AT_type,proc);
  1202. finish_entry;
  1203. { self entry }
  1204. append_entry(DW_TAG_member,false,[
  1205. DW_AT_name,DW_FORM_string,'Self'#0,
  1206. DW_AT_data_member_location,DW_FORM_block1,1+lengthuleb128(sizeof(aint))
  1207. ]);
  1208. current_asmdata.asmlists[al_dwarf_info].concat(tai_const.create_8bit(ord(DW_OP_plus_uconst)));
  1209. current_asmdata.asmlists[al_dwarf_info].concat(tai_const.create_uleb128bit(sizeof(aint)));
  1210. append_labelentry_ref(DW_AT_type,def_dwarf_lab(class_tobject));
  1211. finish_entry;
  1212. finish_children;
  1213. current_asmdata.asmlists[al_dwarf_info].concat(tai_symbol.create(proc,0));
  1214. doappend;
  1215. end
  1216. else
  1217. doappend;
  1218. end;
  1219. procedure TDebugInfoDwarf.appendtag(list:TAsmList;def:tdef);
  1220. var
  1221. labsym : tasmsymbol;
  1222. begin
  1223. current_asmdata.asmlists[al_dwarf_info].concat(tai_comment.Create(strpnew('Definition '+def.typename)));
  1224. labsym:=def_dwarf_lab(def);
  1225. if df_has_dwarf_dbg_info in def.defoptions then
  1226. list.concat(tai_symbol.create_global(labsym,0))
  1227. else
  1228. list.concat(tai_symbol.create(labsym,0));
  1229. case def.deftype of
  1230. stringdef :
  1231. appendtag_stringdef(tstringdef(def));
  1232. enumdef :
  1233. appendtag_enumdef(tenumdef(def));
  1234. orddef :
  1235. appendtag_orddef(torddef(def));
  1236. pointerdef :
  1237. appendtag_pointerdef(tpointerdef(def));
  1238. floatdef :
  1239. appendtag_floatdef(tfloatdef(def));
  1240. filedef :
  1241. appendtag_filedef(tfiledef(def));
  1242. recorddef :
  1243. appendtag_recorddef(trecorddef(def));
  1244. variantdef :
  1245. appendtag_variantdef(tvariantdef(def));
  1246. classrefdef :
  1247. appendtag_pointerdef(tpointerdef(pvmttype.def));
  1248. setdef :
  1249. appendtag_setdef(tsetdef(def));
  1250. formaldef :
  1251. appendtag_formaldef(tformaldef(def));
  1252. arraydef :
  1253. appendtag_arraydef(tarraydef(def));
  1254. procvardef :
  1255. appendtag_procvardef(tprocvardef(def));
  1256. objectdef :
  1257. appendtag_objectdef(tobjectdef(def));
  1258. undefineddef :
  1259. appendtag_undefineddef(tundefineddef(def));
  1260. else
  1261. internalerror(200601281);
  1262. end;
  1263. end;
  1264. procedure TDebugInfoDwarf.insertdef(list:TAsmList;def:tdef);
  1265. begin
  1266. if (def.dbg_state in [dbg_state_writing,dbg_state_written]) then
  1267. exit;
  1268. { never write generic template defs }
  1269. if df_generic in def.defoptions then
  1270. begin
  1271. def.dbg_state:=dbg_state_written;
  1272. exit;
  1273. end;
  1274. { to avoid infinite loops }
  1275. def.dbg_state := dbg_state_writing;
  1276. { write dependencies first }
  1277. insertdef_dependency(list, def);
  1278. appendtag(list,def);
  1279. def.dbg_state:=dbg_state_written;
  1280. end;
  1281. procedure TDebugInfoDwarf.insertdef_dependency(list: TAsmList; def: tdef);
  1282. var
  1283. anc : tobjectdef;
  1284. oldtypesym : tsym;
  1285. i : longint;
  1286. begin
  1287. case def.deftype of
  1288. stringdef :
  1289. begin
  1290. { todo: check if these are needed or valid for dwarf3 (MWE)}
  1291. if tstringdef(def).string_typ=st_widestring then
  1292. insertdef(list,cwidechartype.def)
  1293. else
  1294. begin
  1295. insertdef(list,cchartype.def);
  1296. insertdef(list,u8inttype.def);
  1297. end;
  1298. end;
  1299. floatdef :
  1300. insertdef(list,s32inttype.def);
  1301. filedef :
  1302. begin
  1303. { todo: check if these are needed or valid for dwarf3 (MWE)}
  1304. insertdef(list,s32inttype.def);
  1305. if isdwarf64 then
  1306. insertdef(list,s64inttype.def);
  1307. insertdef(list,u8inttype.def);
  1308. insertdef(list,cchartype.def);
  1309. end;
  1310. classrefdef :
  1311. insertdef(list,pvmttype.def);
  1312. pointerdef :
  1313. insertdef(list,tpointerdef(def).pointertype.def);
  1314. setdef :
  1315. if assigned(tsetdef(def).elementtype.def) then
  1316. insertdef(list,tsetdef(def).elementtype.def);
  1317. procvardef:
  1318. begin
  1319. insertdef(list,tprocvardef(def).rettype.def);
  1320. if tprocvardef(def).is_methodpointer then
  1321. insertdef(list,class_tobject);
  1322. { parameters }
  1323. for i:=0 to tprocvardef(def).paras.count-1 do
  1324. insertdef(list,tparavarsym(tprocvardef(def).paras[i]).vartype.def);
  1325. end;
  1326. procdef :
  1327. insertdef(list,tprocdef(def).rettype.def);
  1328. enumdef :
  1329. if assigned(tenumdef(def).basedef) then
  1330. insertdef(list,tenumdef(def).basedef);
  1331. arraydef :
  1332. begin
  1333. insertdef(list,tarraydef(def).rangetype.def);
  1334. insertdef(list,tarraydef(def).elementtype.def);
  1335. end;
  1336. recorddef :
  1337. trecorddef(def).symtable.foreach(@field_write_defs,list);
  1338. variantdef :
  1339. trecorddef(vardatadef).symtable.foreach(@field_write_defs,list);
  1340. objectdef :
  1341. begin
  1342. { todo: check if vmtarraytype is needed or valid for dwarf3 (MWE)}
  1343. insertdef(list,vmtarraytype.def);
  1344. { first the parents }
  1345. anc:=tobjectdef(def);
  1346. while assigned(anc.childof) do
  1347. begin
  1348. anc:=anc.childof;
  1349. insertdef(list,anc);
  1350. end;
  1351. tobjectdef(def).symtable.foreach(@field_write_defs,list);
  1352. tobjectdef(def).symtable.foreach(@method_write_defs,list);
  1353. end;
  1354. end;
  1355. end;
  1356. procedure TDebugInfoDwarf.write_symtable_defs(list:TAsmList;st:tsymtable);
  1357. procedure dowritedwarf(list:TAsmList;st:tsymtable);
  1358. var
  1359. p : tdef;
  1360. begin
  1361. p:=tdef(st.defindex.first);
  1362. while assigned(p) do
  1363. begin
  1364. if (p.dbg_state=dbg_state_used) then
  1365. insertdef(list,p);
  1366. p:=tdef(p.indexnext);
  1367. end;
  1368. end;
  1369. var
  1370. old_writing_def_dwarf : boolean;
  1371. begin
  1372. case st.symtabletype of
  1373. staticsymtable :
  1374. list.concat(tai_comment.Create(strpnew('Defs - Begin Staticsymtable')));
  1375. globalsymtable :
  1376. list.concat(tai_comment.Create(strpnew('Defs - Begin unit '+st.name^+' has index '+tostr(st.moduleid))));
  1377. end;
  1378. old_writing_def_dwarf:=writing_def_dwarf;
  1379. writing_def_dwarf:=true;
  1380. dowritedwarf(list,st);
  1381. writing_def_dwarf:=old_writing_def_dwarf;
  1382. case st.symtabletype of
  1383. staticsymtable :
  1384. list.concat(tai_comment.Create(strpnew('Defs - End Staticsymtable')));
  1385. globalsymtable :
  1386. list.concat(tai_comment.Create(strpnew('Defs - End unit '+st.name^+' has index '+tostr(st.moduleid))));
  1387. end;
  1388. end;
  1389. procedure TDebugInfoDwarf.appendprocdef(pd:tprocdef);
  1390. var
  1391. procendlabel : tasmlabel;
  1392. mangled_length : longint;
  1393. p : pchar;
  1394. hs : string;
  1395. begin
  1396. if assigned(pd.procstarttai) then
  1397. begin
  1398. current_asmdata.asmlists[al_dwarf_info].concat(tai_comment.Create(strpnew('Procdef '+pd.fullprocname(true))));
  1399. append_entry(DW_TAG_subprogram,true,
  1400. [DW_AT_name,DW_FORM_string,pd.procsym.name+#0
  1401. { data continues below }
  1402. { problem: base reg isn't known here
  1403. DW_AT_frame_base,DW_FORM_block1,1
  1404. }
  1405. ]);
  1406. { append block data }
  1407. { current_asmdata.asmlists[al_dwarf_info].concat(tai_const.create_8bit(dwarf_reg(pd.))); }
  1408. if not(is_void(tprocdef(pd).rettype.def)) then
  1409. append_labelentry_ref(DW_AT_type,def_dwarf_lab(tprocdef(pd).rettype.def));
  1410. { mark end of procedure }
  1411. current_asmdata.getlabel(procendlabel,alt_dbgtype);
  1412. current_asmdata.asmlists[al_procedures].insertbefore(tai_label.create(procendlabel),pd.procendtai);
  1413. append_labelentry(DW_AT_low_pc,current_asmdata.RefAsmSymbol(pd.mangledname));
  1414. append_labelentry(DW_AT_high_pc,procendlabel);
  1415. {
  1416. if assigned(pd.funcretsym) and
  1417. (tabstractnormalvarsym(pd.funcretsym).refs>0) then
  1418. begin
  1419. if tabstractnormalvarsym(pd.funcretsym).localloc.loc=LOC_REFERENCE then
  1420. begin
  1421. {$warning Need to add gdb support for ret in param register calling}
  1422. if paramanager.ret_in_param(pd.rettype.def,pd.proccalloption) then
  1423. hs:='X*'
  1424. else
  1425. hs:='X';
  1426. templist.concat(Tai_stab.create(stab_stabs,strpnew(
  1427. '"'+pd.procsym.name+':'+hs+def_stab_number(pd.rettype.def)+'",'+
  1428. tostr(N_tsym)+',0,0,'+tostr(tabstractnormalvarsym(pd.funcretsym).localloc.reference.offset))));
  1429. if (m_result in aktmodeswitches) then
  1430. templist.concat(Tai_stab.create(stab_stabs,strpnew(
  1431. '"RESULT:'+hs+def_stab_number(pd.rettype.def)+'",'+
  1432. tostr(N_tsym)+',0,0,'+tostr(tabstractnormalvarsym(pd.funcretsym).localloc.reference.offset))));
  1433. end;
  1434. end;
  1435. }
  1436. finish_entry;
  1437. {
  1438. { para types }
  1439. write_def_stabstr(templist,pd);
  1440. }
  1441. if assigned(pd.parast) then
  1442. write_symtable_syms(pd.parast);
  1443. { local type defs and vars should not be written
  1444. inside the main proc stab }
  1445. if assigned(pd.localst) and
  1446. (pd.localst.symtabletype=localsymtable) then
  1447. write_symtable_syms(pd.localst);
  1448. { last write the types from this procdef }
  1449. if assigned(pd.parast) then
  1450. write_symtable_defs(current_asmdata.asmlists[al_dwarf_info],pd.parast);
  1451. if assigned(pd.localst) and
  1452. (pd.localst.symtabletype=localsymtable) then
  1453. write_symtable_defs(current_asmdata.asmlists[al_dwarf_info],pd.localst);
  1454. finish_children;
  1455. end;
  1456. end;
  1457. procedure TDebugInfoDwarf.appendsym_var(sym:tabstractnormalvarsym);
  1458. var
  1459. templist : TAsmList;
  1460. blocksize : longint;
  1461. tag : tdwarf_tag;
  1462. dreg : byte;
  1463. begin
  1464. { external symbols can't be resolved at link time, so we
  1465. can't generate stabs for them
  1466. not sure if this applies to dwarf as well (FK)
  1467. }
  1468. if vo_is_external in sym.varoptions then
  1469. exit;
  1470. { There is no space allocated for not referenced locals }
  1471. if (sym.owner.symtabletype=localsymtable) and (sym.refs=0) then
  1472. exit;
  1473. templist:=TAsmList.create;
  1474. case sym.localloc.loc of
  1475. LOC_REGISTER,
  1476. LOC_CREGISTER,
  1477. LOC_MMREGISTER,
  1478. LOC_CMMREGISTER,
  1479. LOC_FPUREGISTER,
  1480. LOC_CFPUREGISTER :
  1481. begin
  1482. templist.concat(tai_const.create_8bit(ord(DW_OP_regx)));
  1483. dreg:=dwarf_reg(sym.localloc.register);
  1484. templist.concat(tai_const.create_uleb128bit(dreg));
  1485. blocksize:=1+Lengthuleb128(dreg);
  1486. end;
  1487. else
  1488. begin
  1489. case sym.typ of
  1490. globalvarsym:
  1491. begin
  1492. if (vo_is_thread_var in sym.varoptions) then
  1493. begin
  1494. {$warning !!! FIXME: dwarf for thread vars !!!}
  1495. blocksize:=0;
  1496. end
  1497. else
  1498. begin
  1499. templist.concat(tai_const.create_8bit(3));
  1500. templist.concat(tai_const.createname(sym.mangledname,0));
  1501. blocksize:=1+sizeof(aword);
  1502. end;
  1503. end;
  1504. paravarsym,
  1505. localvarsym:
  1506. begin
  1507. dreg:=dwarf_reg(sym.localloc.reference.base);
  1508. templist.concat(tai_const.create_8bit(ord(DW_OP_breg0)+dreg));
  1509. templist.concat(tai_const.create_sleb128bit(sym.localloc.reference.offset));
  1510. blocksize:=1+Lengthsleb128(sym.localloc.reference.offset);
  1511. end
  1512. else
  1513. internalerror(200601288);
  1514. end;
  1515. end;
  1516. end;
  1517. if sym.typ=paravarsym then
  1518. tag:=DW_TAG_formal_parameter
  1519. else
  1520. tag:=DW_TAG_variable;
  1521. append_entry(tag,false,[
  1522. DW_AT_name,DW_FORM_string,sym.name+#0,
  1523. {
  1524. DW_AT_decl_file,DW_FORM_data1,0,
  1525. DW_AT_decl_line,DW_FORM_data1,
  1526. }
  1527. DW_AT_external,DW_FORM_flag,true,
  1528. { data continues below }
  1529. DW_AT_location,DW_FORM_block1,blocksize
  1530. ]);
  1531. { append block data }
  1532. current_asmdata.asmlists[al_dwarf_info].concatlist(templist);
  1533. append_labelentry_ref(DW_AT_type,def_dwarf_lab(sym.vartype.def));
  1534. templist.free;
  1535. finish_entry;
  1536. end;
  1537. procedure TDebugInfoDwarf.appendsym_fieldvar(sym: tfieldvarsym);
  1538. begin
  1539. if sp_static in sym.symoptions then Exit;
  1540. append_entry(DW_TAG_member,false,[
  1541. DW_AT_name,DW_FORM_string,sym.name+#0,
  1542. DW_AT_data_member_location,DW_FORM_block1,1+lengthuleb128(sym.fieldoffset)
  1543. ]);
  1544. current_asmdata.asmlists[al_dwarf_info].concat(tai_const.create_8bit(ord(DW_OP_plus_uconst)));
  1545. current_asmdata.asmlists[al_dwarf_info].concat(tai_const.create_uleb128bit(sym.fieldoffset));
  1546. append_labelentry_ref(DW_AT_type,def_dwarf_lab(sym.vartype.def));
  1547. finish_entry;
  1548. end;
  1549. procedure TDebugInfoDwarf.appendsym_const(sym:tconstsym);
  1550. begin
  1551. append_entry(DW_TAG_constant,false,[
  1552. DW_AT_name,DW_FORM_string,sym.name+#0
  1553. ]);
  1554. { for string constants, consttype isn't set because they have no real type }
  1555. if not(sym.consttyp in [conststring,constresourcestring]) then
  1556. append_labelentry_ref(DW_AT_type,def_dwarf_lab(sym.consttype.def));
  1557. current_asmdata.asmlists[al_dwarf_abbrev].concat(tai_const.create_uleb128bit(ord(DW_AT_const_value)));
  1558. case sym.consttyp of
  1559. conststring:
  1560. begin
  1561. current_asmdata.asmlists[al_dwarf_abbrev].concat(tai_const.create_uleb128bit(ord(DW_FORM_string)));
  1562. current_asmdata.asmlists[al_dwarf_info].concat(tai_string.create(strpas(pchar(sym.value.valueptr))));
  1563. current_asmdata.asmlists[al_dwarf_info].concat(tai_const.create_8bit(0));
  1564. end;
  1565. constset,
  1566. constwstring,
  1567. constguid,
  1568. constresourcestring:
  1569. begin
  1570. { write dummy for now }
  1571. current_asmdata.asmlists[al_dwarf_abbrev].concat(tai_const.create_uleb128bit(ord(DW_FORM_string)));
  1572. current_asmdata.asmlists[al_dwarf_info].concat(tai_string.create(''));
  1573. current_asmdata.asmlists[al_dwarf_info].concat(tai_const.create_8bit(0));
  1574. end;
  1575. constord:
  1576. begin
  1577. current_asmdata.asmlists[al_dwarf_abbrev].concat(tai_const.create_uleb128bit(ord(DW_FORM_sdata)));
  1578. current_asmdata.asmlists[al_dwarf_info].concat(tai_const.create_sleb128bit(sym.value.valueord));
  1579. end;
  1580. constnil:
  1581. begin
  1582. if isdwarf64 then
  1583. begin
  1584. current_asmdata.asmlists[al_dwarf_abbrev].concat(tai_const.create_uleb128bit(ord(DW_FORM_data8)));
  1585. current_asmdata.asmlists[al_dwarf_info].concat(tai_const.create_64bit(0));
  1586. end
  1587. else
  1588. begin
  1589. current_asmdata.asmlists[al_dwarf_abbrev].concat(tai_const.create_uleb128bit(ord(DW_FORM_data4)));
  1590. current_asmdata.asmlists[al_dwarf_info].concat(tai_const.create_32bit(0));
  1591. end;
  1592. end;
  1593. constpointer:
  1594. begin
  1595. if isdwarf64 then
  1596. begin
  1597. current_asmdata.asmlists[al_dwarf_abbrev].concat(tai_const.create_uleb128bit(ord(DW_FORM_data8)));
  1598. current_asmdata.asmlists[al_dwarf_info].concat(tai_const.create_64bit(sym.value.valueordptr));
  1599. end
  1600. else
  1601. begin
  1602. current_asmdata.asmlists[al_dwarf_abbrev].concat(tai_const.create_uleb128bit(ord(DW_FORM_data4)));
  1603. current_asmdata.asmlists[al_dwarf_info].concat(tai_const.create_32bit(sym.value.valueordptr));
  1604. end;
  1605. end;
  1606. constreal:
  1607. begin
  1608. current_asmdata.asmlists[al_dwarf_abbrev].concat(tai_const.create_uleb128bit(ord(DW_FORM_block1)));
  1609. case tfloatdef(sym.consttype.def).typ of
  1610. s32real:
  1611. begin
  1612. current_asmdata.asmlists[al_dwarf_info].concat(tai_const.create_8bit(4));
  1613. current_asmdata.asmlists[al_dwarf_info].concat(tai_real_32bit.create(psingle(sym.value.valueptr)^));
  1614. end;
  1615. s64comp,
  1616. s64currency,
  1617. s64real:
  1618. begin
  1619. current_asmdata.asmlists[al_dwarf_info].concat(tai_const.create_8bit(8));
  1620. current_asmdata.asmlists[al_dwarf_info].concat(tai_real_64bit.create(pdouble(sym.value.valueptr)^));
  1621. end;
  1622. s80real:
  1623. begin
  1624. current_asmdata.asmlists[al_dwarf_info].concat(tai_const.create_8bit(10));
  1625. current_asmdata.asmlists[al_dwarf_info].concat(tai_real_80bit.create(pextended(sym.value.valueptr)^));
  1626. end;
  1627. else
  1628. internalerror(200601291);
  1629. end;
  1630. end;
  1631. else
  1632. internalerror(200601292);
  1633. end;
  1634. finish_entry;
  1635. end;
  1636. procedure TDebugInfoDwarf.appendsym_typedconst(sym: ttypedconstsym);
  1637. begin
  1638. append_entry(DW_TAG_variable,false,[
  1639. DW_AT_name,DW_FORM_string,sym.name+#0,
  1640. {
  1641. DW_AT_decl_file,DW_FORM_data1,0,
  1642. DW_AT_decl_line,DW_FORM_data1,
  1643. }
  1644. DW_AT_external,DW_FORM_flag,true,
  1645. { data continues below }
  1646. DW_AT_location,DW_FORM_block1,1+sizeof(aword)
  1647. ]);
  1648. { append block data }
  1649. current_asmdata.asmlists[al_dwarf_info].concat(tai_const.create_8bit(3));
  1650. current_asmdata.asmlists[al_dwarf_info].concat(tai_const.createname(sym.mangledname,0));
  1651. append_labelentry_ref(DW_AT_type,def_dwarf_lab(sym.typedconsttype.def));
  1652. finish_entry;
  1653. end;
  1654. procedure TDebugInfoDwarf.appendsym_label(sym: tlabelsym);
  1655. begin
  1656. { ignore label syms for now, the problem is that a label sym
  1657. can have more than one label associated e.g. in case of
  1658. an inline procedure expansion }
  1659. end;
  1660. procedure TDebugInfoDwarf.appendsym_proc(sym:tprocsym);
  1661. var
  1662. i : longint;
  1663. begin
  1664. for i:=1 to sym.procdef_count do
  1665. appendprocdef(sym.procdef[i]);
  1666. end;
  1667. procedure TDebugInfoDwarf.appendsym_property(sym: tpropertysym);
  1668. begin
  1669. { ignored for now }
  1670. end;
  1671. procedure TDebugInfoDwarf.appendsym_type(sym: ttypesym);
  1672. begin
  1673. append_entry(DW_TAG_typedef,false,[
  1674. DW_AT_name,DW_FORM_string,sym.name+#0
  1675. ]);
  1676. append_labelentry_ref(DW_AT_type,def_dwarf_lab(sym.restype.def));
  1677. finish_entry;
  1678. end;
  1679. procedure TDebugInfoDwarf.appendsym_unit(sym: tunitsym);
  1680. begin
  1681. { for now, we ignore unit symbols }
  1682. end;
  1683. procedure TDebugInfoDwarf.appendsym_absolute(sym:tabsolutevarsym);
  1684. var
  1685. templist : TAsmList;
  1686. blocksize : longint;
  1687. symlist : psymlistitem;
  1688. begin
  1689. templist:=TAsmList.create;
  1690. case tabsolutevarsym(sym).abstyp of
  1691. toaddr :
  1692. begin
  1693. { MWE: replaced ifdef i368 }
  1694. {
  1695. if target_cpu = cpu_i386 then
  1696. begin
  1697. { in theory, we could write a DW_AT_segment entry here for sym.absseg,
  1698. however I doubt that gdb supports this (FK) }
  1699. end;
  1700. }
  1701. templist.concat(tai_const.create_8bit(3));
  1702. templist.concat(tai_const.create_aint(sym.addroffset));
  1703. blocksize:=1+sizeof(aword);
  1704. end;
  1705. toasm :
  1706. begin
  1707. templist.concat(tai_const.create_8bit(3));
  1708. templist.concat(tai_const.createname(sym.mangledname,0));
  1709. blocksize:=1+sizeof(aword);
  1710. end;
  1711. tovar:
  1712. begin
  1713. symlist:=tabsolutevarsym(sym).ref.firstsym;
  1714. { can we insert the symbol? }
  1715. if assigned(symlist) and
  1716. (symlist^.sltype=sl_load) then
  1717. appendsym(symlist^.sym);
  1718. templist.free;
  1719. exit;
  1720. end;
  1721. end;
  1722. append_entry(DW_TAG_variable,false,[
  1723. DW_AT_name,DW_FORM_string,sym.name+#0,
  1724. {
  1725. DW_AT_decl_file,DW_FORM_data1,0,
  1726. DW_AT_decl_line,DW_FORM_data1,
  1727. }
  1728. DW_AT_external,DW_FORM_flag,true,
  1729. { data continues below }
  1730. DW_AT_location,DW_FORM_block1,blocksize
  1731. ]);
  1732. { append block data }
  1733. current_asmdata.asmlists[al_dwarf_info].concatlist(templist);
  1734. append_labelentry_ref(DW_AT_type,def_dwarf_lab(sym.vartype.def));
  1735. templist.free;
  1736. finish_entry;
  1737. end;
  1738. procedure TDebugInfoDwarf.appendsym(sym:tsym);
  1739. begin
  1740. current_asmdata.asmlists[al_dwarf_info].concat(tai_comment.Create(strpnew('Symbol '+sym.name)));
  1741. case sym.typ of
  1742. globalvarsym :
  1743. appendsym_var(tglobalvarsym(sym));
  1744. unitsym:
  1745. appendsym_unit(tunitsym(sym));
  1746. procsym :
  1747. appendsym_proc(tprocsym(sym));
  1748. labelsym :
  1749. appendsym_label(tlabelsym(sym));
  1750. localvarsym :
  1751. appendsym_var(tlocalvarsym(sym));
  1752. paravarsym :
  1753. appendsym_var(tparavarsym(sym));
  1754. typedconstsym :
  1755. appendsym_typedconst(ttypedconstsym(sym));
  1756. constsym :
  1757. appendsym_const(tconstsym(sym));
  1758. typesym :
  1759. appendsym_type(ttypesym(sym));
  1760. enumsym :
  1761. { ignore enum syms, they are written by the owner }
  1762. ;
  1763. rttisym :
  1764. { ignore rtti syms, they are only of internal use }
  1765. ;
  1766. syssym :
  1767. { ignore sys syms, they are only of internal use }
  1768. ;
  1769. absolutevarsym :
  1770. appendsym_absolute(tabsolutevarsym(sym));
  1771. propertysym :
  1772. appendsym_property(tpropertysym(sym));
  1773. else
  1774. begin
  1775. writeln(ord(sym.typ));
  1776. internalerror(200601242);
  1777. end;
  1778. end;
  1779. {
  1780. { For object types write also the symtable entries }
  1781. if (sym.typ=typesym) and (ttypesym(sym).restype.def.deftype=objectdef) then
  1782. write_symtable_syms(list,tobjectdef(ttypesym(sym).restype.def).symtable);
  1783. sym.isstabwritten:=true;
  1784. }
  1785. end;
  1786. procedure TDebugInfoDwarf.write_symtable_syms(st:tsymtable);
  1787. var
  1788. p : tsym;
  1789. old_writing_def_dwarf : boolean;
  1790. begin
  1791. old_writing_def_dwarf:=writing_def_dwarf;
  1792. writing_def_dwarf:=false;
  1793. p:=tsym(st.symindex.first);
  1794. while assigned(p) do
  1795. begin
  1796. if (not p.isstabwritten) then
  1797. appendsym(p);
  1798. p:=tsym(p.indexnext);
  1799. end;
  1800. writing_def_dwarf:=old_writing_def_dwarf;
  1801. end;
  1802. procedure TDebugInfoDwarf.insertmoduleinfo;
  1803. var
  1804. templist: TAsmList;
  1805. linelist: TAsmList;
  1806. lbl: tasmlabel;
  1807. n: Integer;
  1808. ditem: TDirIndexItem;
  1809. fitem: TFileIndexItem;
  1810. dlist, flist: TFPList;
  1811. begin
  1812. { insert .Ltext0 label }
  1813. templist:=TAsmList.create;
  1814. new_section(templist,sec_code,'',0);
  1815. templist.concat(tai_symbol.createname('.Ltext0',AT_DATA,0));
  1816. current_asmdata.asmlists[al_start].insertlist(templist);
  1817. templist.free;
  1818. { insert .Letext0 label }
  1819. templist:=TAsmList.create;
  1820. new_section(templist,sec_code,'',0);
  1821. templist.concat(tai_symbol.createname('.Letext0',AT_DATA,0));
  1822. current_asmdata.asmlists[al_end].insertlist(templist);
  1823. templist.free;
  1824. { insert .Ldebug_abbrev0 label }
  1825. templist:=TAsmList.create;
  1826. new_section(templist,sec_debug_abbrev,'',0);
  1827. templist.concat(tai_symbol.createname('.Ldebug_abbrev0',AT_DATA,0));
  1828. current_asmdata.asmlists[al_start].insertlist(templist);
  1829. templist.free;
  1830. { insert .Ldebug_line0 label }
  1831. templist:=TAsmList.create;
  1832. new_section(templist,sec_debug_line,'',0);
  1833. templist.concat(tai_symbol.createname('.Ldebug_line0',AT_DATA,0));
  1834. current_asmdata.asmlists[al_start].insertlist(templist);
  1835. templist.free;
  1836. { debug line header }
  1837. linelist := current_asmdata.asmlists[al_dwarf_line];
  1838. new_section(linelist,sec_debug_line,'',0);
  1839. linelist.concat(tai_comment.Create(strpnew('=== header start ===')));
  1840. { size }
  1841. current_asmdata.getlabel(lbl,alt_dbgfile);
  1842. { currently we create only 32 bit dwarf }
  1843. linelist.concat(tai_const.create_rel_sym(aitconst_32bit,
  1844. lbl,tasmsymbol.create('.Ledebug_line0',AB_COMMON,AT_DATA)));
  1845. linelist.concat(tai_label.create(lbl));
  1846. { version }
  1847. linelist.concat(tai_const.create_16bit(dwarf_version));
  1848. { header length }
  1849. current_asmdata.getlabel(lbl,alt_dbgfile);
  1850. { currently we create only 32 bit dwarf }
  1851. linelist.concat(tai_const.create_rel_sym(aitconst_32bit,
  1852. lbl,tasmsymbol.create('.Lehdebug_line0',AB_COMMON,AT_DATA)));
  1853. linelist.concat(tai_label.create(lbl));
  1854. { minimum_instruction_length }
  1855. linelist.concat(tai_const.create_8bit(1));
  1856. { default_is_stmt }
  1857. linelist.concat(tai_const.create_8bit(1));
  1858. { line_base }
  1859. linelist.concat(tai_const.create_8bit(LINE_BASE));
  1860. { line_range }
  1861. { only line increase, no adress }
  1862. linelist.concat(tai_const.create_8bit(255));
  1863. { opcode_base }
  1864. linelist.concat(tai_const.create_8bit(OPCODE_BASE));
  1865. { standard_opcode_lengths }
  1866. { MWE: sigh... why adding the default lengths (and make those sizes sense with LEB encoding) }
  1867. { DW_LNS_copy }
  1868. linelist.concat(tai_const.create_8bit(0));
  1869. { DW_LNS_advance_pc }
  1870. linelist.concat(tai_const.create_8bit(1));
  1871. { DW_LNS_advance_line }
  1872. linelist.concat(tai_const.create_8bit(1));
  1873. { DW_LNS_set_file }
  1874. linelist.concat(tai_const.create_8bit(1));
  1875. { DW_LNS_set_column }
  1876. linelist.concat(tai_const.create_8bit(1));
  1877. { DW_LNS_negate_stmt }
  1878. linelist.concat(tai_const.create_8bit(0));
  1879. { DW_LNS_set_basic_block }
  1880. linelist.concat(tai_const.create_8bit(0));
  1881. { DW_LNS_const_add_pc }
  1882. linelist.concat(tai_const.create_8bit(0));
  1883. { DW_LNS_fixed_advance_pc }
  1884. linelist.concat(tai_const.create_8bit(1));
  1885. { DW_LNS_set_prologue_end }
  1886. linelist.concat(tai_const.create_8bit(0));
  1887. { DW_LNS_set_epilogue_begin }
  1888. linelist.concat(tai_const.create_8bit(0));
  1889. { DW_LNS_set_isa }
  1890. linelist.concat(tai_const.create_8bit(1));
  1891. { generate directory and filelist}
  1892. dlist := TFPList.Create;
  1893. flist := TFPList.Create;
  1894. dirlist.foreach_static(@AddNamedIndexToList, dlist);
  1895. dlist.Sort(@DirListSortCompare);
  1896. { include_directories }
  1897. linelist.concat(tai_comment.Create(strpnew('include_directories')));
  1898. { list }
  1899. for n := 0 to dlist.Count - 1 do
  1900. begin
  1901. ditem := TDirIndexItem(dlist[n]);
  1902. ditem.Files.foreach_static(@AddNamedIndexToList, flist);
  1903. if ditem.Name = '.' then Continue;
  1904. linelist.concat(tai_string.create(ditem.Name+#0));
  1905. end;
  1906. { end of list }
  1907. linelist.concat(tai_const.create_8bit(0));
  1908. { file_names }
  1909. linelist.concat(tai_comment.Create(strpnew('file_names')));
  1910. { list }
  1911. flist.Sort(@FileListSortCompare);
  1912. for n := 0 to flist.Count - 1 do
  1913. begin
  1914. fitem := TFileIndexItem(flist[n]);
  1915. { file name }
  1916. linelist.concat(tai_string.create(fitem.Name+#0));
  1917. { directory index }
  1918. linelist.concat(tai_const.create_uleb128bit(fitem.DirIndex));
  1919. { last modification }
  1920. linelist.concat(tai_const.create_uleb128bit(0));
  1921. { file length }
  1922. linelist.concat(tai_const.create_uleb128bit(0));
  1923. end;
  1924. { end of list }
  1925. linelist.concat(tai_const.create_8bit(0));
  1926. dlist.free;
  1927. flist.free;
  1928. { end of debug line header }
  1929. linelist.concat(tai_symbol.createname('.Lehdebug_line0',AT_DATA,0));
  1930. linelist.concat(tai_comment.Create(strpnew('=== header end ===')));
  1931. { add line program }
  1932. linelist.concatList(asmline);
  1933. { end of debug line table }
  1934. linelist.concat(tai_symbol.createname('.Ledebug_line0',AT_DATA,0));
  1935. end;
  1936. procedure TDebugInfoDwarf.inserttypeinfo;
  1937. var
  1938. storefilepos : tfileposinfo;
  1939. lenstartlabel : tasmlabel;
  1940. i : longint;
  1941. begin
  1942. storefilepos:=aktfilepos;
  1943. aktfilepos:=current_module.mainfilepos;
  1944. currabbrevnumber:=0;
  1945. writing_def_dwarf:=false;
  1946. nextdefnumber:=0;
  1947. defnumberlist:=TFPObjectList.create(false);
  1948. { not exported (FK)
  1949. filerecdef:=gettypedef('FILEREC');
  1950. textrecdef:=gettypedef('TEXTREC');
  1951. }
  1952. vardatadef:=trecorddef(search_system_type('TVARDATA').restype.def);
  1953. { write start labels }
  1954. current_asmdata.asmlists[al_dwarf_info].concat(tai_section.create(sec_debug_info,'',0));
  1955. current_asmdata.asmlists[al_dwarf_info].concat(tai_symbol.createname('.Ldebug_info0',AT_DATA,0));
  1956. { start abbrev section }
  1957. new_section(current_asmdata.asmlists[al_dwarf_abbrev],sec_debug_abbrev,'',0);
  1958. { debug info header }
  1959. current_asmdata.getlabel(lenstartlabel,alt_dbgfile);
  1960. { size }
  1961. { currently we create only 32 bit dwarf }
  1962. current_asmdata.asmlists[al_dwarf_info].concat(tai_const.create_rel_sym(aitconst_32bit,
  1963. lenstartlabel,tasmsymbol.create('.Ledebug_info0',AB_COMMON,AT_DATA)));
  1964. current_asmdata.asmlists[al_dwarf_info].concat(tai_label.create(lenstartlabel));
  1965. { version }
  1966. current_asmdata.asmlists[al_dwarf_info].concat(tai_const.create_16bit(dwarf_version));
  1967. { abbrev table (=relative from section start)}
  1968. if isdwarf64 then
  1969. current_asmdata.asmlists[al_dwarf_info].concat(tai_const.create_type_sym(aitconst_64bit,
  1970. current_asmdata.RefAsmSymbol('.Ldebug_abbrev0')))
  1971. else
  1972. current_asmdata.asmlists[al_dwarf_info].concat(tai_const.create_type_sym(aitconst_32bit,
  1973. current_asmdata.RefAsmSymbol('.Ldebug_abbrev0')));
  1974. { address size }
  1975. current_asmdata.asmlists[al_dwarf_info].concat(tai_const.create_8bit(sizeof(aint)));
  1976. append_entry(DW_TAG_compile_unit,true,[
  1977. DW_AT_name,DW_FORM_string,FixFileName(current_module.sourcefiles.get_file(1).name^)+#0,
  1978. DW_AT_producer,DW_FORM_string,'Free Pascal '+full_version_string+' '+date_string+#0,
  1979. DW_AT_comp_dir,DW_FORM_string,BsToSlash(FixPath(current_module.sourcefiles.get_file(1).path^,false))+#0,
  1980. DW_AT_language,DW_FORM_data1,DW_LANG_Pascal83,
  1981. DW_AT_identifier_case,DW_FORM_data1,DW_ID_case_insensitive]);
  1982. { reference to line info section }
  1983. append_labelentry_data(DW_AT_stmt_list,current_asmdata.RefAsmSymbol('.Ldebug_line0'));
  1984. append_labelentry(DW_AT_low_pc,current_asmdata.RefAsmSymbol('.Ltext0'));
  1985. append_labelentry(DW_AT_high_pc,current_asmdata.RefAsmSymbol('.Letext0'));
  1986. finish_entry;
  1987. { first write all global/local symbols. This will flag all required tdefs }
  1988. if assigned(current_module.globalsymtable) then
  1989. begin
  1990. current_asmdata.asmlists[al_dwarf_info].concat(tai_comment.Create(strpnew('Syms - Begin unit '+current_module.globalsymtable.name^+' has index '+tostr(current_module.globalsymtable.moduleid))));
  1991. write_symtable_syms(current_module.globalsymtable);
  1992. current_asmdata.asmlists[al_dwarf_info].concat(tai_comment.Create(strpnew('Syms - End unit '+current_module.globalsymtable.name^+' has index '+tostr(current_module.globalsymtable.moduleid))));
  1993. end;
  1994. if assigned(current_module.localsymtable) then
  1995. begin
  1996. current_asmdata.asmlists[al_dwarf_info].concat(tai_comment.Create(strpnew('Syms - Begin Staticsymtable')));
  1997. write_symtable_syms(current_module.localsymtable);
  1998. current_asmdata.asmlists[al_dwarf_info].concat(tai_comment.Create(strpnew('Syms - End Staticsymtable')));
  1999. end;
  2000. { reset unit type info flag }
  2001. reset_unit_type_info;
  2002. { write used types from the used units }
  2003. write_used_unit_type_info(current_asmdata.asmlists[al_dwarf_info],current_module);
  2004. { last write the types from this unit }
  2005. if assigned(current_module.globalsymtable) then
  2006. write_symtable_defs(current_asmdata.asmlists[al_dwarf_info],current_module.globalsymtable);
  2007. if assigned(current_module.localsymtable) then
  2008. write_symtable_defs(current_asmdata.asmlists[al_dwarf_info],current_module.localsymtable);
  2009. { close compilation unit entry }
  2010. finish_children;
  2011. { end of debug info table }
  2012. current_asmdata.asmlists[al_dwarf_info].concat(tai_const.create_8bit(0));
  2013. current_asmdata.asmlists[al_dwarf_info].concat(tai_symbol.createname('.Ledebug_info0',AT_DATA,0));
  2014. { end of abbrev table }
  2015. current_asmdata.asmlists[al_dwarf_abbrev].concat(tai_const.create_8bit(0));
  2016. { reset all def labels }
  2017. for i:=0 to defnumberlist.count-1 do
  2018. begin
  2019. if assigned(defnumberlist[i]) then
  2020. begin
  2021. tdef(defnumberlist[i]).dwarf_lab:=nil;
  2022. tdef(defnumberlist[i]).dbg_state:=dbg_state_unused;
  2023. end;
  2024. end;
  2025. defnumberlist.free;
  2026. defnumberlist:=nil;
  2027. aktfilepos:=storefilepos;
  2028. end;
  2029. procedure TDebugInfoDwarf.referencesections(list:TAsmList);
  2030. begin
  2031. end;
  2032. procedure TDebugInfoDwarf.insertlineinfo(list:TAsmList);
  2033. var
  2034. currfileinfo,
  2035. lastfileinfo : tfileposinfo;
  2036. currfuncname : pstring;
  2037. currsectype : TAsmSectiontype;
  2038. hlabel : tasmlabel;
  2039. hp : tai;
  2040. infile : tinputfile;
  2041. current_file : tai_file;
  2042. prevcolumn,
  2043. diffline,
  2044. prevline,
  2045. prevfileidx,
  2046. currfileidx: Integer;
  2047. prevlabel,
  2048. currlabel : tasmlabel;
  2049. begin
  2050. FillChar(lastfileinfo,sizeof(lastfileinfo),0);
  2051. currfuncname:=nil;
  2052. currsectype:=sec_code;
  2053. hp:=Tai(list.first);
  2054. prevcolumn := 0;
  2055. prevline := 1;
  2056. prevfileidx := 1;
  2057. prevlabel := nil;
  2058. while assigned(hp) do
  2059. begin
  2060. case hp.typ of
  2061. ait_section :
  2062. currsectype:=tai_section(hp).sectype;
  2063. ait_function_name :
  2064. begin
  2065. currfuncname:=tai_function_name(hp).funcname;
  2066. asmline.concat(tai_comment.Create(strpnew('function: '+currfuncname^)));
  2067. end;
  2068. ait_force_line : begin
  2069. lastfileinfo.line:=-1;
  2070. end;
  2071. end;
  2072. if (currsectype=sec_code) and
  2073. (hp.typ=ait_instruction) then
  2074. begin
  2075. currfileinfo:=tailineinfo(hp).fileinfo;
  2076. { file changed ? (must be before line info) }
  2077. if (currfileinfo.fileindex<>0) and
  2078. (lastfileinfo.fileindex<>currfileinfo.fileindex) then
  2079. begin
  2080. infile:=current_module.sourcefiles.get_file(currfileinfo.fileindex);
  2081. if assigned(infile) then
  2082. begin
  2083. currfileidx := get_file_index(infile);
  2084. if prevfileidx <> currfileidx then
  2085. begin
  2086. list.insertbefore(tai_comment.Create(strpnew('path: '+infile.path^)), hp);
  2087. list.insertbefore(tai_comment.Create(strpnew('file: '+infile.name^)), hp);
  2088. list.insertbefore(tai_comment.Create(strpnew('indx: '+tostr(currfileidx))), hp);
  2089. { set file }
  2090. asmline.concat(tai_comment.Create(strpnew('path: '+infile.path^)));
  2091. asmline.concat(tai_comment.Create(strpnew('file: '+infile.name^)));
  2092. asmline.concat(tai_const.create_8bit(DW_LNS_set_file));
  2093. asmline.concat(tai_const.create_uleb128bit(currfileidx));
  2094. prevfileidx := currfileidx;
  2095. end;
  2096. { force new line info }
  2097. lastfileinfo.line:=-1;
  2098. end;
  2099. end;
  2100. { line changed ? }
  2101. if (lastfileinfo.line<>currfileinfo.line) and (currfileinfo.line<>0) then
  2102. begin
  2103. { set address }
  2104. current_asmdata.getlabel(currlabel, alt_dbgline);
  2105. list.insertbefore(tai_label.create(currlabel), hp);
  2106. asmline.concat(tai_comment.Create(strpnew('['+tostr(currfileinfo.line)+':'+tostr(currfileinfo.column)+']')));
  2107. if prevlabel = nil then
  2108. begin
  2109. asmline.concat(tai_const.create_8bit(DW_LNS_extended_op));
  2110. if isdwarf64 then
  2111. asmline.concat(tai_const.create_uleb128bit(9)) { 1 + 8 }
  2112. else
  2113. asmline.concat(tai_const.create_uleb128bit(5)); { 1 + 4 }
  2114. asmline.concat(tai_const.create_8bit(DW_LNE_set_address));
  2115. if isdwarf64 then
  2116. asmline.concat(tai_const.create_type_sym(aitconst_64bit, currlabel))
  2117. else
  2118. asmline.concat(tai_const.create_type_sym(aitconst_32bit, currlabel));
  2119. end
  2120. else
  2121. begin
  2122. asmline.concat(tai_const.create_8bit(DW_LNS_advance_pc));
  2123. asmline.concat(tai_const.create_rel_sym(aitconst_uleb128bit, prevlabel, currlabel));
  2124. end;
  2125. prevlabel := currlabel;
  2126. { set column }
  2127. if prevcolumn <> currfileinfo.column then
  2128. begin
  2129. asmline.concat(tai_const.create_8bit(DW_LNS_set_column));
  2130. asmline.concat(tai_const.create_uleb128bit(currfileinfo.column));
  2131. prevcolumn := currfileinfo.column;
  2132. end;
  2133. { set line }
  2134. diffline := currfileinfo.line - prevline;
  2135. if (diffline >= LINE_BASE) and (OPCODE_BASE + diffline - LINE_BASE <= 255) then
  2136. begin
  2137. { use special opcode, this also adds a row }
  2138. asmline.concat(tai_const.create_8bit(OPCODE_BASE + diffline - LINE_BASE));
  2139. end
  2140. else
  2141. begin
  2142. if diffline <> 0 then
  2143. begin
  2144. asmline.concat(tai_const.create_8bit(DW_LNS_advance_line));
  2145. asmline.concat(tai_const.create_sleb128bit(diffline));
  2146. end;
  2147. { no row added yet, do it manually }
  2148. asmline.concat(tai_const.create_8bit(DW_LNS_copy));
  2149. end;
  2150. prevline := currfileinfo.line;
  2151. end;
  2152. lastfileinfo:=currfileinfo;
  2153. end;
  2154. hp:=tai(hp.next);
  2155. end;
  2156. { end sequence }
  2157. asmline.concat(tai_const.Create_8bit(DW_LNS_extended_op));
  2158. asmline.concat(tai_const.Create_8bit(1));
  2159. asmline.concat(tai_const.Create_8bit(DW_LNE_end_sequence));
  2160. asmline.concat(tai_comment.Create(strpnew('###################')));
  2161. end;
  2162. {****************************************************************************
  2163. TDebugInfoDwarf2
  2164. ****************************************************************************}
  2165. procedure TDebugInfoDwarf2.appendtag_filedef(def: tfiledef);
  2166. begin
  2167. { gdb 6.4 doesn't support files so far so we use some fake recorddef
  2168. file recs. are less than 1k so using data2 is enough }
  2169. if assigned(def.typesym) then
  2170. append_entry(DW_TAG_structure_type,false,[
  2171. DW_AT_name,DW_FORM_string,def.typesym.name+#0,
  2172. DW_AT_byte_size,DW_FORM_udata,def.size
  2173. ])
  2174. else
  2175. append_entry(DW_TAG_structure_type,false,[
  2176. DW_AT_byte_size,DW_FORM_udata,def.size
  2177. ]);
  2178. finish_entry;
  2179. end;
  2180. procedure TDebugInfoDwarf2.appendtag_formaldef(def: tformaldef);
  2181. begin
  2182. { gdb 6.4 doesn't support DW_TAG_unspecified_type so we
  2183. replace it with a unsigned type with size 0 (FK)
  2184. }
  2185. append_entry(DW_TAG_base_type,false,[
  2186. DW_AT_name,DW_FORM_string,'FormalDef'#0,
  2187. DW_AT_encoding,DW_FORM_data1,DW_ATE_unsigned,
  2188. DW_AT_byte_size,DW_FORM_data1,0
  2189. ]);
  2190. finish_entry;
  2191. end;
  2192. procedure TDebugInfoDwarf2.appendtag_objectdef(def: tobjectdef);
  2193. procedure doappend;
  2194. begin
  2195. if assigned(def.objname) then
  2196. append_entry(DW_TAG_structure_type,true,[
  2197. DW_AT_name,DW_FORM_string,def.objname^+#0,
  2198. DW_AT_byte_size,DW_FORM_udata,def.size
  2199. ])
  2200. else
  2201. append_entry(DW_TAG_structure_type,true,[
  2202. DW_AT_byte_size,DW_FORM_udata,def.size
  2203. ]);
  2204. finish_entry;
  2205. if assigned(def.childof) then
  2206. begin
  2207. append_entry(DW_TAG_inheritance,false,[
  2208. DW_AT_accessibility,DW_FORM_data1,DW_ACCESS_public,
  2209. DW_AT_data_member_location,DW_FORM_block1,1+lengthuleb128(0)
  2210. ]);
  2211. current_asmdata.asmlists[al_dwarf_info].concat(tai_const.create_8bit(ord(DW_OP_plus_uconst)));
  2212. current_asmdata.asmlists[al_dwarf_info].concat(tai_const.create_uleb128bit(0));
  2213. append_labelentry_ref(DW_AT_type,def_dwarf_lab(def.childof));
  2214. finish_entry;
  2215. end;
  2216. def.symtable.foreach(@enum_members_callback,nil);
  2217. write_symtable_defs(current_asmdata.asmlists[al_dwarf_info],def.symtable);
  2218. finish_children;
  2219. end;
  2220. var
  2221. obj : tasmlabel;
  2222. begin
  2223. case def.objecttype of
  2224. odt_cppclass,
  2225. odt_object:
  2226. doappend;
  2227. odt_interfacecom,
  2228. odt_interfacecorba,
  2229. odt_dispinterface,
  2230. odt_class:
  2231. begin
  2232. current_asmdata.getdatalabel(obj);
  2233. { implicit pointer }
  2234. append_entry(DW_TAG_pointer_type,false,[]);
  2235. append_labelentry_ref(DW_AT_type,obj);
  2236. finish_entry;
  2237. current_asmdata.asmlists[al_dwarf_info].concat(tai_symbol.create(obj,0));
  2238. doappend;
  2239. end;
  2240. else
  2241. internalerror(200602041);
  2242. end;
  2243. end;
  2244. procedure TDebugInfoDwarf2.appendtag_setdef(def: tsetdef);
  2245. begin
  2246. { at least gdb up to 6.4 doesn't support sets in dwarf, there is a patch available to fix this:
  2247. http://sources.redhat.com/ml/gdb-patches/2005-05/msg00278.html (FK) }
  2248. if assigned(def.typesym) then
  2249. append_entry(DW_TAG_base_type,false,[
  2250. DW_AT_name,DW_FORM_string,def.typesym.name+#0,
  2251. DW_AT_encoding,DW_FORM_data1,DW_ATE_unsigned,
  2252. DW_AT_byte_size,DW_FORM_data2,def.size
  2253. ])
  2254. else
  2255. append_entry(DW_TAG_base_type,false,[
  2256. DW_AT_encoding,DW_FORM_data1,DW_ATE_unsigned,
  2257. DW_AT_byte_size,DW_FORM_data2,def.size
  2258. ]);
  2259. finish_entry;
  2260. end;
  2261. procedure TDebugInfoDwarf2.appendtag_undefineddef(def: tundefineddef);
  2262. begin
  2263. { gdb 6.4 doesn't support DW_TAG_unspecified_type so we
  2264. replace it with a unsigned type with size 0 (FK)
  2265. }
  2266. append_entry(DW_TAG_base_type,false,[
  2267. DW_AT_name,DW_FORM_string,'FormalDef'#0,
  2268. DW_AT_encoding,DW_FORM_data1,DW_ATE_unsigned,
  2269. DW_AT_byte_size,DW_FORM_data1,0
  2270. ]);
  2271. finish_entry;
  2272. end;
  2273. procedure TDebugInfoDwarf2.appendtag_variantdef(def: tvariantdef);
  2274. begin
  2275. { variants aren't known to dwarf2 but writting tvardata should be enough }
  2276. appendtag_recorddef(trecorddef(vardatadef));
  2277. end;
  2278. function TDebugInfoDwarf2.dwarf_version: Word;
  2279. begin
  2280. Result:=2;
  2281. end;
  2282. {****************************************************************************
  2283. TDebugInfoDwarf3
  2284. ****************************************************************************}
  2285. procedure TDebugInfoDwarf3.appendtag_filedef(def: tfiledef);
  2286. begin
  2287. if assigned(def.typesym) then
  2288. append_entry(DW_TAG_file_type,false,[
  2289. DW_AT_name,DW_FORM_string,def.typesym.name+#0,
  2290. DW_AT_byte_size,DW_FORM_data2,def.size
  2291. ])
  2292. else
  2293. append_entry(DW_TAG_file_type,false,[
  2294. DW_AT_byte_size,DW_FORM_data2,def.size
  2295. ]);
  2296. if tfiledef(def).filetyp=ft_typed then
  2297. append_labelentry_ref(DW_AT_type,def_dwarf_lab(tfiledef(def).typedfiletype.def));
  2298. finish_entry;
  2299. end;
  2300. procedure TDebugInfoDwarf3.appendtag_formaldef(def: tformaldef);
  2301. begin
  2302. append_entry(DW_TAG_unspecified_type,false,[
  2303. ]);
  2304. finish_entry;
  2305. end;
  2306. procedure TDebugInfoDwarf3.appendtag_objectdef(def: tobjectdef);
  2307. procedure dostruct(tag: tdwarf_tag);
  2308. begin
  2309. if assigned(def.objname) then
  2310. append_entry(tag,true,[
  2311. DW_AT_name,DW_FORM_string,def.objname^+#0,
  2312. DW_AT_byte_size,DW_FORM_udata,def.size
  2313. ])
  2314. else
  2315. append_entry(DW_TAG_structure_type,true,[
  2316. DW_AT_byte_size,DW_FORM_udata,def.size
  2317. ]);
  2318. finish_entry;
  2319. end;
  2320. procedure doimplicitpointer;
  2321. var
  2322. obj : tasmlabel;
  2323. begin
  2324. current_asmdata.getdatalabel(obj);
  2325. { implicit pointer }
  2326. append_entry(DW_TAG_pointer_type,false,[]);
  2327. append_labelentry_ref(DW_AT_type,obj);
  2328. finish_entry;
  2329. current_asmdata.asmlists[al_dwarf_info].concat(tai_symbol.create(obj,0));
  2330. end;
  2331. procedure doparent(isinterface: boolean);
  2332. begin
  2333. if not assigned(def.childof) then
  2334. exit;
  2335. if isinterface then
  2336. begin
  2337. append_entry(DW_TAG_inheritance,false,[]);
  2338. end
  2339. else
  2340. begin
  2341. append_entry(DW_TAG_inheritance,false,[
  2342. DW_AT_accessibility,DW_FORM_data1,DW_ACCESS_public,
  2343. DW_AT_data_member_location,DW_FORM_block1,1+lengthuleb128(0)
  2344. ]);
  2345. current_asmdata.asmlists[al_dwarf_info].concat(tai_const.create_8bit(ord(DW_OP_plus_uconst)));
  2346. current_asmdata.asmlists[al_dwarf_info].concat(tai_const.create_uleb128bit(0));
  2347. end;
  2348. append_labelentry_ref(DW_AT_type,def_dwarf_lab(def.childof));
  2349. finish_entry;
  2350. end;
  2351. var
  2352. n: integer;
  2353. begin
  2354. case def.objecttype of
  2355. odt_cppclass,
  2356. odt_object:
  2357. begin
  2358. dostruct(DW_TAG_structure_type);
  2359. doparent(false);
  2360. end;
  2361. odt_interfacecom,
  2362. odt_interfacecorba,
  2363. odt_dispinterface:
  2364. begin
  2365. dostruct(DW_TAG_interface_type);
  2366. doparent(true);
  2367. end;
  2368. odt_class:
  2369. begin
  2370. { not sure if the implicit pointer is needed for tag_class (MWE)}
  2371. {
  2372. doimplicitpointer;
  2373. }
  2374. dostruct(DW_TAG_class_type);
  2375. doparent(false);
  2376. end;
  2377. else
  2378. internalerror(200609171);
  2379. end;
  2380. { add implemented interfaces }
  2381. if assigned(def.implementedinterfaces) then
  2382. for n := 1 to def.implementedinterfaces.count do
  2383. begin
  2384. append_entry(DW_TAG_inheritance,false,[]);
  2385. append_labelentry_ref(DW_AT_type,def_dwarf_lab(def.implementedinterfaces.interfaces(n)));
  2386. finish_entry;
  2387. end;
  2388. { add members }
  2389. def.symtable.foreach(@enum_members_callback,nil);
  2390. finish_children;
  2391. end;
  2392. procedure TDebugInfoDwarf3.appendtag_setdef(def: tsetdef);
  2393. begin
  2394. if assigned(def.typesym) then
  2395. append_entry(DW_TAG_set_type,false,[
  2396. DW_AT_name,DW_FORM_string,def.typesym.name+#0,
  2397. DW_AT_byte_size,DW_FORM_data2,def.size
  2398. ])
  2399. else
  2400. append_entry(DW_TAG_set_type,false,[
  2401. DW_AT_byte_size,DW_FORM_data2,def.size
  2402. ]);
  2403. append_labelentry_ref(DW_AT_type,def_dwarf_lab(tsetdef(def).elementtype.def));
  2404. finish_entry;
  2405. end;
  2406. procedure TDebugInfoDwarf3.appendtag_undefineddef(def: tundefineddef);
  2407. begin
  2408. { ??? can a undefined def have a typename ? }
  2409. if assigned(def.typesym) then
  2410. append_entry(DW_TAG_unspecified_type,false,[
  2411. DW_AT_name,DW_FORM_string,def.typesym.name+#0
  2412. ])
  2413. else
  2414. append_entry(DW_TAG_unspecified_type,false,[
  2415. ]);
  2416. finish_entry;
  2417. end;
  2418. procedure TDebugInfoDwarf3.appendtag_variantdef(def: tvariantdef);
  2419. const
  2420. VARIANTS: array[1..27] of record Value: Word; Name: String end = (
  2421. (value:0; name:''),
  2422. (value:1; name:''),
  2423. (value:2; name:'VSMALLINT'),
  2424. (value:3; name:'VINTEGER'),
  2425. (value:4; name:'VSINGLE'),
  2426. (value:5; name:'VDOUBLE'),
  2427. (value:6; name:'VCURRENCY'),
  2428. (value:7; name:'VDATE'),
  2429. (value:8; name:'VOLESTR'),
  2430. (value:9; name:'VDISPATCH'),
  2431. (value:10; name:'VERROR'),
  2432. (value:11; name:'VBOOLEAN'),
  2433. (value:12; name:''),
  2434. (value:13; name:'VUNKNOWN'),
  2435. (value:14; name:''),
  2436. (value:16; name:'VSHORTINT'),
  2437. (value:17; name:'VBYTE'),
  2438. (value:18; name:'VWORD'),
  2439. (value:19; name:'VLONGWORD'),
  2440. (value:20; name:'VINT64'),
  2441. (value:21; name:'VQWORD'),
  2442. (value:36; name:'VRECORD'),
  2443. (value:$48; name:''),
  2444. (value:$100; name:'VSTRING'),
  2445. (value:$101; name:'VANY'),
  2446. (value:$2000; name:'VARRAY'),
  2447. (value:$4000; name:'VPOINTER')
  2448. );
  2449. var
  2450. fs: tfieldvarsym;
  2451. lbl: tasmlabel;
  2452. idx: integer;
  2453. begin
  2454. { it could be done with DW_TAG_variant for the union part (if that info was available)
  2455. now we do it manually for variants (MWE) }
  2456. { struct }
  2457. append_entry(DW_TAG_structure_type,true,[
  2458. DW_AT_name,DW_FORM_string,'VARIANT'#0,
  2459. DW_AT_byte_size,DW_FORM_udata,vardatadef.size
  2460. ]);
  2461. finish_entry;
  2462. append_entry(DW_TAG_variant_part,true,[
  2463. ]);
  2464. current_asmdata.getaddrlabel(lbl);
  2465. append_labelentry_ref(DW_AT_discr,lbl);
  2466. finish_entry;
  2467. { discriminant }
  2468. fs := tfieldvarsym(vardatadef.symtable.search('VTYPE'));
  2469. if (fs = nil) or (fs.typ <> fieldvarsym) then
  2470. internalerror(200609271);
  2471. current_asmdata.asmlists[al_dwarf_info].concat(tai_symbol.create(lbl,0));
  2472. appendsym_fieldvar(fs);
  2473. { variants }
  2474. for idx := Low(VARIANTS) to High(VARIANTS) do
  2475. begin
  2476. append_entry(DW_TAG_variant,true,[
  2477. DW_AT_discr_value,DW_FORM_udata,VARIANTS[idx].value
  2478. ]);
  2479. finish_entry;
  2480. if VARIANTS[idx].name <> '' then
  2481. begin
  2482. fs := tfieldvarsym(vardatadef.symtable.search(VARIANTS[idx].name));
  2483. if (fs = nil) or (fs.typ <> fieldvarsym) then
  2484. internalerror(20060927200+idx);
  2485. appendsym_fieldvar(fs);
  2486. end;
  2487. finish_children; { variant }
  2488. end;
  2489. finish_children; { variant part }
  2490. finish_children; { struct }
  2491. end;
  2492. function TDebugInfoDwarf3.dwarf_version: Word;
  2493. begin
  2494. Result:=3;
  2495. end;
  2496. procedure TDebugInfoDwarf3.insertdef_dependency(list: TAsmList; def: tdef);
  2497. begin
  2498. case def.deftype of
  2499. objectdef :
  2500. begin
  2501. inherited insertdef_dependency(list, def);
  2502. tobjectdef(def).symtable.foreach(@property_write_defs,list);
  2503. end;
  2504. else
  2505. inherited insertdef_dependency(list, def);
  2506. end;
  2507. end;
  2508. procedure TDebugInfoDwarf3.property_write_defs(p: tnamedindexitem; arg: pointer);
  2509. begin
  2510. if Tsym(p).typ <> propertysym then
  2511. exit;
  2512. insertdef(TAsmList(arg),tpropertysym(p).proptype.def);
  2513. if ppo_indexed in tpropertysym(p).propoptions then
  2514. insertdef(TAsmList(arg),tpropertysym(p).indextype.def);
  2515. end;
  2516. {****************************************************************************
  2517. ****************************************************************************}
  2518. const
  2519. dbg_dwarf2_info : tdbginfo =
  2520. (
  2521. id : dbg_dwarf2;
  2522. idtxt : 'DWARF2';
  2523. );
  2524. dbg_dwarf3_info : tdbginfo =
  2525. (
  2526. id : dbg_dwarf3;
  2527. idtxt : 'DWARF3';
  2528. );
  2529. initialization
  2530. RegisterDebugInfo(dbg_dwarf2_info,TDebugInfoDwarf2);
  2531. RegisterDebugInfo(dbg_dwarf3_info,TDebugInfoDwarf3);
  2532. end.