dbgdwarf.pas 123 KB

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