dbgdwarf.pas 121 KB

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