dbgdwarf.pas 123 KB

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