dbgdwarf.pas 124 KB

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