dbgdwarf.pas 121 KB

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