dbgdwarf.pas 121 KB

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