dbgdwarf.pas 120 KB

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