dbgdwarf.pas 123 KB

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