dbgdwarf.pas 104 KB

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