dbgdwarf.pas 119 KB

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