dbgdwarf.pas 123 KB

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