dbgdwarf.pas 120 KB

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