dbgdwarf.pas 108 KB

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