dbgdwarf.pas 121 KB

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