dbgdwarf.pas 113 KB

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