dbgdwarf.pas 124 KB

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