dbgdwarf.pas 123 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186
  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,cfileutl,constexp,
  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. asmline.free;
  641. asmline:=nil;
  642. loclist.Free;
  643. loclist := nil;
  644. inherited Destroy;
  645. end;
  646. procedure TDebugInfoDwarf.enum_membersyms_callback(p:TObject; arg: pointer);
  647. begin
  648. case tsym(p).typ of
  649. fieldvarsym:
  650. appendsym_fieldvar(tfieldvarsym(p));
  651. propertysym:
  652. appendsym_property(tpropertysym(p));
  653. procsym:
  654. appendsym_proc(tprocsym(p));
  655. end;
  656. end;
  657. function TDebugInfoDwarf.get_file_index(afile: tinputfile): Integer;
  658. var
  659. dirname: String;
  660. diritem: TDirIndexItem;
  661. diridx: Integer;
  662. fileitem: TFileIndexItem;
  663. begin
  664. if afile.path^ = '' then
  665. dirname := '.'
  666. else
  667. begin
  668. { add the canonical form here already to avoid problems with }
  669. { paths such as './' etc }
  670. dirname := relative_dwarf_path(afile.path^);
  671. if dirname = '' then
  672. dirname := '.';
  673. end;
  674. diritem := TDirIndexItem(dirlist.Find(dirname));
  675. if diritem = nil then
  676. diritem := TDirIndexItem.Create(dirlist,dirname, dirlist.Count);
  677. diridx := diritem.IndexNr;
  678. fileitem := TFileIndexItem(diritem.files.Find(afile.name^));
  679. if fileitem = nil then
  680. begin
  681. Inc(filesequence);
  682. fileitem := TFileIndexItem.Create(diritem.files,afile.name^, diridx, filesequence);
  683. end;
  684. Result := fileitem.IndexNr;
  685. end;
  686. { writing the data through a few simply procedures allows to create easily extra information
  687. for debugging of debug info }
  688. procedure TDebugInfoDwarf.append_entry(tag : tdwarf_tag;has_children : boolean;data : array of const);
  689. var
  690. i : longint;
  691. begin
  692. { todo: store defined abbrevs, so you have to define tehm only once (for this unit) (MWE) }
  693. inc(currabbrevnumber);
  694. current_asmdata.asmlists[al_dwarf_abbrev].concat(tai_comment.Create(strpnew('Abbrev '+tostr(currabbrevnumber))));
  695. { abbrev number }
  696. current_asmdata.asmlists[al_dwarf_info].concat(tai_const.create_uleb128bit(currabbrevnumber));
  697. current_asmdata.asmlists[al_dwarf_abbrev].concat(tai_const.create_uleb128bit(currabbrevnumber));
  698. { tag }
  699. current_asmdata.asmlists[al_dwarf_abbrev].concat(tai_const.create_uleb128bit(ord(tag)));
  700. { children? }
  701. current_asmdata.asmlists[al_dwarf_abbrev].concat(tai_const.create_8bit(ord(has_children)));
  702. i:=0;
  703. while i<=high(data) do
  704. begin
  705. { attribute }
  706. if data[i].VType=vtInteger then
  707. begin
  708. current_asmdata.asmlists[al_dwarf_abbrev].concat(tai_const.create_uleb128bit(data[i].VInteger));
  709. end
  710. else
  711. internalerror(200601261);
  712. inc(i);
  713. { form }
  714. if data[i].VType=vtInteger then
  715. begin
  716. current_asmdata.asmlists[al_dwarf_abbrev].concat(tai_const.create_uleb128bit(data[i].VInteger));
  717. end
  718. else
  719. internalerror(200601262);
  720. inc(i);
  721. { info itself }
  722. case tdwarf_form(data[i-1].VInteger) of
  723. DW_FORM_string:
  724. case data[i].VType of
  725. vtChar:
  726. current_asmdata.asmlists[al_dwarf_info].concat(tai_string.create(data[i].VChar));
  727. vtString:
  728. current_asmdata.asmlists[al_dwarf_info].concat(tai_string.create(data[i].VString^));
  729. vtAnsistring:
  730. current_asmdata.asmlists[al_dwarf_info].concat(tai_string.create(Ansistring(data[i].VAnsiString)));
  731. else
  732. internalerror(200601264);
  733. end;
  734. DW_FORM_flag:
  735. current_asmdata.asmlists[al_dwarf_info].concat(tai_const.create_8bit(byte(data[i].VBoolean)));
  736. DW_FORM_data1:
  737. case data[i].VType of
  738. vtInteger:
  739. current_asmdata.asmlists[al_dwarf_info].concat(tai_const.create_8bit(data[i].VInteger));
  740. vtInt64:
  741. current_asmdata.asmlists[al_dwarf_info].concat(tai_const.create_8bit(data[i].VInt64^));
  742. vtQWord:
  743. current_asmdata.asmlists[al_dwarf_info].concat(tai_const.create_8bit(data[i].VQWord^));
  744. else
  745. internalerror(200602143);
  746. end;
  747. DW_FORM_data2:
  748. case data[i].VType of
  749. vtInteger:
  750. current_asmdata.asmlists[al_dwarf_info].concat(tai_const.create_16bit(data[i].VInteger));
  751. vtInt64:
  752. current_asmdata.asmlists[al_dwarf_info].concat(tai_const.create_16bit(data[i].VInt64^));
  753. vtQWord:
  754. current_asmdata.asmlists[al_dwarf_info].concat(tai_const.create_16bit(data[i].VQWord^));
  755. else
  756. internalerror(200602144);
  757. end;
  758. DW_FORM_data4:
  759. case data[i].VType of
  760. vtInteger:
  761. current_asmdata.asmlists[al_dwarf_info].concat(tai_const.create_32bit(data[i].VInteger));
  762. vtInt64:
  763. current_asmdata.asmlists[al_dwarf_info].concat(tai_const.create_32bit(data[i].VInt64^));
  764. vtQWord:
  765. current_asmdata.asmlists[al_dwarf_info].concat(tai_const.create_32bit(data[i].VQWord^));
  766. else
  767. internalerror(200602145);
  768. end;
  769. DW_FORM_data8:
  770. case data[i].VType of
  771. vtInteger:
  772. current_asmdata.asmlists[al_dwarf_info].concat(tai_const.create_64bit(data[i].VInteger));
  773. vtInt64:
  774. current_asmdata.asmlists[al_dwarf_info].concat(tai_const.create_64bit(data[i].VInt64^));
  775. vtQWord:
  776. current_asmdata.asmlists[al_dwarf_info].concat(tai_const.create_64bit(data[i].VQWord^));
  777. else
  778. internalerror(200602146);
  779. end;
  780. DW_FORM_sdata:
  781. case data[i].VType of
  782. vtInteger:
  783. current_asmdata.asmlists[al_dwarf_info].concat(tai_const.create_sleb128bit(data[i].VInteger));
  784. vtInt64:
  785. current_asmdata.asmlists[al_dwarf_info].concat(tai_const.create_sleb128bit(data[i].VInt64^));
  786. vtQWord:
  787. current_asmdata.asmlists[al_dwarf_info].concat(tai_const.create_sleb128bit(data[i].VQWord^));
  788. else
  789. internalerror(200601285);
  790. end;
  791. DW_FORM_udata:
  792. case data[i].VType of
  793. vtInteger:
  794. current_asmdata.asmlists[al_dwarf_info].concat(tai_const.create_uleb128bit(data[i].VInteger));
  795. vtInt64:
  796. current_asmdata.asmlists[al_dwarf_info].concat(tai_const.create_uleb128bit(data[i].VInt64^));
  797. vtQWord:
  798. current_asmdata.asmlists[al_dwarf_info].concat(tai_const.create_uleb128bit(data[i].VQWord^));
  799. else
  800. internalerror(200601284);
  801. end;
  802. { block gets only the size, the rest is appended manually by the caller }
  803. DW_FORM_block1:
  804. case data[i].VType of
  805. vtInteger:
  806. current_asmdata.asmlists[al_dwarf_info].concat(tai_const.create_8bit(data[i].VInteger));
  807. vtInt64:
  808. current_asmdata.asmlists[al_dwarf_info].concat(tai_const.create_8bit(data[i].VInt64^));
  809. vtQWord:
  810. current_asmdata.asmlists[al_dwarf_info].concat(tai_const.create_8bit(data[i].VQWord^));
  811. else
  812. internalerror(200602141);
  813. end;
  814. else
  815. internalerror(200601263);
  816. end;
  817. inc(i);
  818. end;
  819. end;
  820. procedure TDebugInfoDwarf.append_labelentry(attr : tdwarf_attribute;sym : tasmsymbol);
  821. begin
  822. current_asmdata.asmlists[al_dwarf_abbrev].concat(tai_const.create_uleb128bit(ord(attr)));
  823. current_asmdata.asmlists[al_dwarf_abbrev].concat(tai_const.create_uleb128bit(ord(DW_FORM_addr)));
  824. current_asmdata.asmlists[al_dwarf_info].concat(tai_const.create_sym(sym));
  825. end;
  826. procedure TDebugInfoDwarf.append_labelentry_ref(attr : tdwarf_attribute;sym : tasmsymbol);
  827. begin
  828. current_asmdata.asmlists[al_dwarf_abbrev].concat(tai_const.create_uleb128bit(ord(attr)));
  829. if not(tf_dwarf_only_local_labels in target_info.flags) then
  830. begin
  831. current_asmdata.asmlists[al_dwarf_abbrev].concat(tai_const.create_uleb128bit(ord(DW_FORM_ref_addr)));
  832. current_asmdata.asmlists[al_dwarf_info].concat(tai_const.create_sym(sym))
  833. end
  834. else
  835. begin
  836. current_asmdata.asmlists[al_dwarf_abbrev].concat(tai_const.create_uleb128bit(ord(DW_FORM_ref4)));
  837. current_asmdata.asmlists[al_dwarf_info].concat(tai_const.create_rel_sym(offsetreltype,current_asmdata.RefAsmSymbol(target_asm.labelprefix+'debug_info0'),sym));
  838. end;
  839. end;
  840. procedure TDebugInfoDwarf.append_labelentry_dataptr_common(attr : tdwarf_attribute);
  841. begin
  842. current_asmdata.asmlists[al_dwarf_abbrev].concat(tai_const.create_uleb128bit(ord(attr)));
  843. if use_64bit_headers then
  844. current_asmdata.asmlists[al_dwarf_abbrev].concat(tai_const.create_uleb128bit(ord(DW_FORM_data8)))
  845. else
  846. current_asmdata.asmlists[al_dwarf_abbrev].concat(tai_const.create_uleb128bit(ord(DW_FORM_data4)));
  847. end;
  848. procedure TDebugInfoDwarf.append_labelentry_dataptr_abs(attr : tdwarf_attribute;sym : tasmsymbol);
  849. begin
  850. {
  851. used for writing dwarf lineptr, loclistptr, macptr and rangelistptr classes as FORM_dataN
  852. The size of these depend on the header format
  853. Must be relative to another symbol on tf_dwarf_relative_addresses
  854. targets
  855. }
  856. if (tf_dwarf_relative_addresses in target_info.flags) then
  857. { use append_labelentry_dataptr_rel instead }
  858. internalerror(2007020210);
  859. append_labelentry_dataptr_common(attr);
  860. current_asmdata.asmlists[al_dwarf_info].concat(tai_const.create_type_sym(offsetabstype,sym))
  861. end;
  862. procedure TDebugInfoDwarf.append_labelentry_dataptr_rel(attr : tdwarf_attribute;sym,endsym : tasmsymbol);
  863. begin
  864. {
  865. used for writing dwarf lineptr, loclistptr, macptr and rangelistptr classes as FORM_dataN
  866. The size of these depend on the header format
  867. Must be relative to another symbol on tf_dwarf_relative_addresses
  868. targets
  869. }
  870. append_labelentry_dataptr_common(attr);
  871. current_asmdata.asmlists[al_dwarf_info].concat(tai_const.create_rel_sym(offsetreltype,sym,endsym));
  872. end;
  873. procedure TDebugInfoDwarf.finish_entry;
  874. begin
  875. current_asmdata.asmlists[al_dwarf_abbrev].concat(tai_const.create_8bit(0));
  876. current_asmdata.asmlists[al_dwarf_abbrev].concat(tai_const.create_8bit(0));
  877. end;
  878. procedure TDebugInfoDwarf.finish_children;
  879. begin
  880. current_asmdata.asmlists[al_dwarf_info].concat(tai_const.create_8bit(0));
  881. end;
  882. procedure TDebugInfoDwarf.appenddef_ord(def:torddef);
  883. var
  884. sign: tdwarf_type;
  885. begin
  886. case def.ordtype of
  887. s8bit,
  888. s16bit,
  889. s32bit,
  890. u8bit,
  891. u16bit,
  892. u32bit :
  893. begin
  894. { generate proper signed/unsigned info for types like 0..3 }
  895. { these are s8bit, but should be identified as unsigned }
  896. { because otherwise they are interpreted wrongly when used }
  897. { in a bitpacked record }
  898. if (def.low<0) then
  899. sign:=DW_ATE_signed
  900. else
  901. sign:=DW_ATE_unsigned;
  902. { we should generate a subrange type here }
  903. if assigned(def.typesym) then
  904. append_entry(DW_TAG_base_type,false,[
  905. DW_AT_name,DW_FORM_string,symname(def.typesym)+#0,
  906. DW_AT_encoding,DW_FORM_data1,sign,
  907. DW_AT_byte_size,DW_FORM_data1,def.size
  908. ])
  909. else
  910. append_entry(DW_TAG_base_type,false,[
  911. DW_AT_encoding,DW_FORM_data1,sign,
  912. DW_AT_byte_size,DW_FORM_data1,def.size
  913. ]);
  914. finish_entry;
  915. end;
  916. uvoid :
  917. begin
  918. { gdb 6.4 doesn't support DW_TAG_unspecified_type so we
  919. replace it with a unsigned type with size 0 (FK)
  920. }
  921. append_entry(DW_TAG_base_type,false,[
  922. DW_AT_name,DW_FORM_string,'Void'#0,
  923. DW_AT_encoding,DW_FORM_data1,DW_ATE_unsigned,
  924. DW_AT_byte_size,DW_FORM_data1,0
  925. ]);
  926. finish_entry;
  927. end;
  928. uchar :
  929. begin
  930. append_entry(DW_TAG_base_type,false,[
  931. DW_AT_name,DW_FORM_string,'Char'#0,
  932. DW_AT_encoding,DW_FORM_data1,DW_ATE_unsigned_char,
  933. DW_AT_byte_size,DW_FORM_data1,1
  934. ]);
  935. finish_entry;
  936. end;
  937. uwidechar :
  938. begin
  939. append_entry(DW_TAG_base_type,false,[
  940. DW_AT_name,DW_FORM_string,'WideChar'#0,
  941. DW_AT_encoding,DW_FORM_data1,DW_ATE_unsigned_char,
  942. DW_AT_byte_size,DW_FORM_data1,2
  943. ]);
  944. finish_entry;
  945. end;
  946. bool8bit :
  947. begin
  948. append_entry(DW_TAG_base_type,false,[
  949. DW_AT_name,DW_FORM_string,'Boolean'#0,
  950. DW_AT_encoding,DW_FORM_data1,DW_ATE_boolean,
  951. DW_AT_byte_size,DW_FORM_data1,1
  952. ]);
  953. finish_entry;
  954. end;
  955. bool16bit :
  956. begin
  957. append_entry(DW_TAG_base_type,false,[
  958. DW_AT_name,DW_FORM_string,'WordBool'#0,
  959. DW_AT_encoding,DW_FORM_data1,DW_ATE_boolean,
  960. DW_AT_byte_size,DW_FORM_data1,2
  961. ]);
  962. finish_entry;
  963. end;
  964. bool32bit :
  965. begin
  966. append_entry(DW_TAG_base_type,false,[
  967. DW_AT_name,DW_FORM_string,'LongBool'#0,
  968. DW_AT_encoding,DW_FORM_data1,DW_ATE_boolean,
  969. DW_AT_byte_size,DW_FORM_data1,4
  970. ]);
  971. finish_entry;
  972. end;
  973. bool64bit :
  974. begin
  975. append_entry(DW_TAG_base_type,false,[
  976. DW_AT_name,DW_FORM_string,'QWordBool'#0,
  977. DW_AT_encoding,DW_FORM_data1,DW_ATE_boolean,
  978. DW_AT_byte_size,DW_FORM_data1,8
  979. ]);
  980. finish_entry;
  981. end;
  982. u64bit :
  983. begin
  984. append_entry(DW_TAG_base_type,false,[
  985. DW_AT_name,DW_FORM_string,'QWord'#0,
  986. DW_AT_encoding,DW_FORM_data1,DW_ATE_unsigned,
  987. DW_AT_byte_size,DW_FORM_data1,8
  988. ]);
  989. finish_entry;
  990. end;
  991. scurrency :
  992. begin
  993. { we should use DW_ATE_signed_fixed, however it isn't supported yet by GDB (FK) }
  994. append_entry(DW_TAG_base_type,false,[
  995. DW_AT_name,DW_FORM_string,'Currency'#0,
  996. DW_AT_encoding,DW_FORM_data1,DW_ATE_signed,
  997. DW_AT_byte_size,DW_FORM_data1,8
  998. ]);
  999. finish_entry;
  1000. end;
  1001. s64bit :
  1002. begin
  1003. append_entry(DW_TAG_base_type,false,[
  1004. DW_AT_name,DW_FORM_string,'Int64'#0,
  1005. DW_AT_encoding,DW_FORM_data1,DW_ATE_signed,
  1006. DW_AT_byte_size,DW_FORM_data1,8
  1007. ]);
  1008. finish_entry;
  1009. end;
  1010. else
  1011. internalerror(200601287);
  1012. end;
  1013. end;
  1014. procedure TDebugInfoDwarf.appenddef_float(def:tfloatdef);
  1015. begin
  1016. case def.floattype of
  1017. s32real,
  1018. s64real,
  1019. s80real:
  1020. if assigned(def.typesym) then
  1021. append_entry(DW_TAG_base_type,false,[
  1022. DW_AT_name,DW_FORM_string,symname(def.typesym)+#0,
  1023. DW_AT_encoding,DW_FORM_data1,DW_ATE_float,
  1024. DW_AT_byte_size,DW_FORM_data1,def.size
  1025. ])
  1026. else
  1027. append_entry(DW_TAG_base_type,false,[
  1028. DW_AT_encoding,DW_FORM_data1,DW_ATE_float,
  1029. DW_AT_byte_size,DW_FORM_data1,def.size
  1030. ]);
  1031. s64currency:
  1032. { we should use DW_ATE_signed_fixed, however it isn't supported yet by GDB (FK) }
  1033. if assigned(def.typesym) then
  1034. append_entry(DW_TAG_base_type,false,[
  1035. DW_AT_name,DW_FORM_string,symname(def.typesym)+#0,
  1036. DW_AT_encoding,DW_FORM_data1,DW_ATE_signed,
  1037. DW_AT_byte_size,DW_FORM_data1,8
  1038. ])
  1039. else
  1040. append_entry(DW_TAG_base_type,false,[
  1041. DW_AT_encoding,DW_FORM_data1,DW_ATE_signed,
  1042. DW_AT_byte_size,DW_FORM_data1,8
  1043. ]);
  1044. s64comp:
  1045. if assigned(def.typesym) then
  1046. append_entry(DW_TAG_base_type,false,[
  1047. DW_AT_name,DW_FORM_string,symname(def.typesym)+#0,
  1048. DW_AT_encoding,DW_FORM_data1,DW_ATE_signed,
  1049. DW_AT_byte_size,DW_FORM_data1,8
  1050. ])
  1051. else
  1052. append_entry(DW_TAG_base_type,false,[
  1053. DW_AT_encoding,DW_FORM_data1,DW_ATE_signed,
  1054. DW_AT_byte_size,DW_FORM_data1,8
  1055. ]);
  1056. else
  1057. internalerror(200601289);
  1058. end;
  1059. finish_entry;
  1060. end;
  1061. procedure TDebugInfoDwarf.appenddef_formal(def: tformaldef);
  1062. begin
  1063. { implemented in derived classes }
  1064. end;
  1065. procedure TDebugInfoDwarf.appenddef_enum(def:tenumdef);
  1066. var
  1067. hp : tenumsym;
  1068. begin
  1069. if assigned(def.typesym) then
  1070. append_entry(DW_TAG_enumeration_type,true,[
  1071. DW_AT_name,DW_FORM_string,symname(def.typesym)+#0,
  1072. DW_AT_byte_size,DW_FORM_data1,def.size
  1073. ])
  1074. else
  1075. append_entry(DW_TAG_enumeration_type,true,[
  1076. DW_AT_byte_size,DW_FORM_data1,def.size
  1077. ]);
  1078. if assigned(def.basedef) then
  1079. append_labelentry_ref(DW_AT_type,def_dwarf_lab(def.basedef));
  1080. finish_entry;
  1081. { write enum symbols }
  1082. hp:=tenumsym(def.firstenum);
  1083. while assigned(hp) do
  1084. begin
  1085. append_entry(DW_TAG_enumerator,false,[
  1086. DW_AT_name,DW_FORM_string,symname(hp)+#0,
  1087. DW_AT_const_value,DW_FORM_data4,hp.value
  1088. ]);
  1089. finish_entry;
  1090. hp:=tenumsym(hp).nextenum;
  1091. end;
  1092. finish_children;
  1093. end;
  1094. procedure TDebugInfoDwarf.appenddef_file(def: tfiledef);
  1095. begin
  1096. { implemented in derived classes }
  1097. end;
  1098. procedure TDebugInfoDwarf.appenddef_array(def:tarraydef);
  1099. var
  1100. size : aint;
  1101. elesize : aint;
  1102. begin
  1103. if is_special_array(def) then
  1104. size:=def.elesize
  1105. else
  1106. size:=def.size;
  1107. if not is_packed_array(def) then
  1108. elesize := def.elesize*8
  1109. else
  1110. elesize := def.elepackedbitsize;
  1111. if assigned(def.typesym) then
  1112. append_entry(DW_TAG_array_type,true,[
  1113. DW_AT_name,DW_FORM_string,symname(def.typesym)+#0,
  1114. DW_AT_byte_size,DW_FORM_udata,size,
  1115. DW_AT_stride_size,DW_FORM_udata,elesize
  1116. ])
  1117. else
  1118. append_entry(DW_TAG_array_type,true,[
  1119. DW_AT_byte_size,DW_FORM_udata,size,
  1120. DW_AT_stride_size,DW_FORM_udata,elesize
  1121. ]);
  1122. append_labelentry_ref(DW_AT_type,def_dwarf_lab(def.elementdef));
  1123. if is_dynamic_array(def) then
  1124. begin
  1125. { !!! FIXME !!! }
  1126. { gdb's dwarf implementation sucks, so we can't use DW_OP_push_object here (FK)}
  1127. { insert location attribute manually }
  1128. {
  1129. current_asmdata.asmlists[al_dwarf_abbrev].concat(tai_const.create_uleb128bit(DW_AT_data_location));
  1130. current_asmdata.asmlists[al_dwarf_abbrev].concat(tai_const.create_uleb128bit(DW_FORM_block1));
  1131. current_asmdata.asmlists[al_dwarf_info].concat(tai_const.create_8bit(1));
  1132. current_asmdata.asmlists[al_dwarf_info].concat(tai_const.create_8bit(DW_OP_push_object));
  1133. current_asmdata.asmlists[al_dwarf_info].concat(tai_const.create_8bit(DW_OP_deref));
  1134. }
  1135. finish_entry;
  1136. { to simplify things, we don't write a multidimensional array here }
  1137. append_entry(DW_TAG_subrange_type,false,[
  1138. DW_AT_lower_bound,DW_FORM_udata,0,
  1139. DW_AT_upper_bound,DW_FORM_udata,0
  1140. ]);
  1141. append_labelentry_ref(DW_AT_type,def_dwarf_lab(def.rangedef));
  1142. finish_entry;
  1143. end
  1144. else
  1145. begin
  1146. finish_entry;
  1147. { to simplify things, we don't write a multidimensional array here }
  1148. append_entry(DW_TAG_subrange_type,false,[
  1149. DW_AT_lower_bound,DW_FORM_sdata,def.lowrange,
  1150. DW_AT_upper_bound,DW_FORM_sdata,def.highrange
  1151. ]);
  1152. append_labelentry_ref(DW_AT_type,def_dwarf_lab(def.rangedef));
  1153. finish_entry;
  1154. end;
  1155. finish_children;
  1156. end;
  1157. procedure TDebugInfoDwarf.appenddef_record(def:trecorddef);
  1158. begin
  1159. if assigned(def.typesym) then
  1160. append_entry(DW_TAG_structure_type,true,[
  1161. DW_AT_name,DW_FORM_string,symname(def.typesym)+#0,
  1162. DW_AT_byte_size,DW_FORM_udata,def.size
  1163. ])
  1164. else
  1165. append_entry(DW_TAG_structure_type,true,[
  1166. DW_AT_byte_size,DW_FORM_udata,def.size
  1167. ]);
  1168. finish_entry;
  1169. def.symtable.symList.ForEachCall(@enum_membersyms_callback,nil);
  1170. finish_children;
  1171. end;
  1172. procedure TDebugInfoDwarf.appenddef_pointer(def:tpointerdef);
  1173. begin
  1174. append_entry(DW_TAG_pointer_type,false,[]);
  1175. if not(is_voidpointer(def)) then
  1176. append_labelentry_ref(DW_AT_type,def_dwarf_lab(def.pointeddef));
  1177. finish_entry;
  1178. end;
  1179. procedure TDebugInfoDwarf.appenddef_string(def:tstringdef);
  1180. procedure addnormalstringdef(const name: shortstring; lendef: tdef; maxlen: aword);
  1181. var
  1182. { maxlen can be > high(int64) }
  1183. slen : aword;
  1184. arr : tasmlabel;
  1185. begin
  1186. { fix length of openshortstring }
  1187. slen:=aword(def.len);
  1188. if slen=0 then
  1189. slen:=maxlen;
  1190. { create a structure with two elements }
  1191. if not(tf_dwarf_only_local_labels in target_info.flags) then
  1192. current_asmdata.getdatalabel(arr)
  1193. else
  1194. current_asmdata.getaddrlabel(arr);
  1195. append_entry(DW_TAG_structure_type,true,[
  1196. DW_AT_name,DW_FORM_string,name+#0,
  1197. DW_AT_byte_size,DW_FORM_data1,2*sizeof(aint)
  1198. ]);
  1199. finish_entry;
  1200. { length entry }
  1201. append_entry(DW_TAG_member,false,[
  1202. DW_AT_name,DW_FORM_string,'length'#0,
  1203. DW_AT_data_member_location,DW_FORM_block1,1+lengthuleb128(0)
  1204. ]);
  1205. current_asmdata.asmlists[al_dwarf_info].concat(tai_const.create_8bit(ord(DW_OP_plus_uconst)));
  1206. current_asmdata.asmlists[al_dwarf_info].concat(tai_const.create_uleb128bit(0));
  1207. append_labelentry_ref(DW_AT_type,def_dwarf_lab(lendef));
  1208. finish_entry;
  1209. { string data entry }
  1210. append_entry(DW_TAG_member,false,[
  1211. DW_AT_name,DW_FORM_string,'st'#0,
  1212. DW_AT_data_member_location,DW_FORM_block1,1+lengthuleb128(1)
  1213. ]);
  1214. current_asmdata.asmlists[al_dwarf_info].concat(tai_const.create_8bit(ord(DW_OP_plus_uconst)));
  1215. current_asmdata.asmlists[al_dwarf_info].concat(tai_const.create_uleb128bit(lendef.size));
  1216. append_labelentry_ref(DW_AT_type,arr);
  1217. finish_entry;
  1218. finish_children;
  1219. { now the data array }
  1220. current_asmdata.asmlists[al_dwarf_info].concat(tai_symbol.create(arr,0));
  1221. append_entry(DW_TAG_array_type,true,[
  1222. DW_AT_byte_size,DW_FORM_udata,def.size,
  1223. DW_AT_stride_size,DW_FORM_udata,1*8
  1224. ]);
  1225. append_labelentry_ref(DW_AT_type,def_dwarf_lab(cchartype));
  1226. finish_entry;
  1227. append_entry(DW_TAG_subrange_type,false,[
  1228. DW_AT_lower_bound,DW_FORM_udata,0,
  1229. DW_AT_upper_bound,DW_FORM_udata,slen
  1230. ]);
  1231. append_labelentry_ref(DW_AT_type,def_dwarf_lab(lendef));
  1232. finish_entry;
  1233. finish_children;
  1234. end;
  1235. begin
  1236. case def.stringtype of
  1237. st_shortstring:
  1238. begin
  1239. addnormalstringdef('ShortString',u8inttype,255);
  1240. end;
  1241. st_longstring:
  1242. begin
  1243. {$ifdef cpu64bit}
  1244. addnormalstringdef('LongString',u64inttype,qword(-1));
  1245. {$else cpu64bit}
  1246. addnormalstringdef('LongString',u32inttype,cardinal(-1));
  1247. {$endif cpu64bit}
  1248. end;
  1249. st_ansistring:
  1250. begin
  1251. { looks like a pchar }
  1252. append_entry(DW_TAG_pointer_type,false,[]);
  1253. append_labelentry_ref(DW_AT_type,def_dwarf_lab(cchartype));
  1254. finish_entry;
  1255. end;
  1256. st_unicodestring,
  1257. st_widestring:
  1258. begin
  1259. { looks like a pwidechar }
  1260. append_entry(DW_TAG_pointer_type,false,[]);
  1261. append_labelentry_ref(DW_AT_type,def_dwarf_lab(cwidechartype));
  1262. finish_entry;
  1263. end;
  1264. end;
  1265. end;
  1266. procedure TDebugInfoDwarf.appenddef_procvar(def:tprocvardef);
  1267. procedure doappend;
  1268. var
  1269. i : longint;
  1270. begin
  1271. if assigned(def.typesym) then
  1272. append_entry(DW_TAG_subroutine_type,true,[
  1273. DW_AT_name,DW_FORM_string,symname(def.typesym)+#0,
  1274. DW_AT_prototyped,DW_FORM_flag,true
  1275. ])
  1276. else
  1277. append_entry(DW_TAG_subroutine_type,true,[
  1278. DW_AT_prototyped,DW_FORM_flag,true
  1279. ]);
  1280. if not(is_void(tprocvardef(def).returndef)) then
  1281. append_labelentry_ref(DW_AT_type,def_dwarf_lab(tprocvardef(def).returndef));
  1282. finish_entry;
  1283. { write parameters }
  1284. for i:=0 to def.paras.count-1 do
  1285. begin
  1286. append_entry(DW_TAG_formal_parameter,false,[
  1287. DW_AT_name,DW_FORM_string,symname(tsym(def.paras[i]))+#0
  1288. ]);
  1289. append_labelentry_ref(DW_AT_type,def_dwarf_lab(tparavarsym(def.paras[i]).vardef));
  1290. finish_entry;
  1291. end;
  1292. finish_children;
  1293. end;
  1294. var
  1295. proc : tasmlabel;
  1296. begin
  1297. if def.is_methodpointer then
  1298. begin
  1299. { create a structure with two elements }
  1300. if not(tf_dwarf_only_local_labels in target_info.flags) then
  1301. current_asmdata.getdatalabel(proc)
  1302. else
  1303. current_asmdata.getaddrlabel(proc);
  1304. append_entry(DW_TAG_structure_type,true,[
  1305. DW_AT_byte_size,DW_FORM_data1,2*sizeof(aint)
  1306. ]);
  1307. finish_entry;
  1308. { proc entry }
  1309. append_entry(DW_TAG_member,false,[
  1310. DW_AT_name,DW_FORM_string,'Proc'#0,
  1311. DW_AT_data_member_location,DW_FORM_block1,1+lengthuleb128(0)
  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(0));
  1315. append_labelentry_ref(DW_AT_type,proc);
  1316. finish_entry;
  1317. { self entry }
  1318. append_entry(DW_TAG_member,false,[
  1319. DW_AT_name,DW_FORM_string,'Self'#0,
  1320. DW_AT_data_member_location,DW_FORM_block1,1+lengthuleb128(sizeof(aint))
  1321. ]);
  1322. current_asmdata.asmlists[al_dwarf_info].concat(tai_const.create_8bit(ord(DW_OP_plus_uconst)));
  1323. current_asmdata.asmlists[al_dwarf_info].concat(tai_const.create_uleb128bit(sizeof(aint)));
  1324. append_labelentry_ref(DW_AT_type,def_dwarf_lab(class_tobject));
  1325. finish_entry;
  1326. finish_children;
  1327. current_asmdata.asmlists[al_dwarf_info].concat(tai_symbol.create(proc,0));
  1328. doappend;
  1329. end
  1330. else
  1331. doappend;
  1332. end;
  1333. procedure TDebugInfoDwarf.appenddef(def:tdef);
  1334. var
  1335. labsym : tasmsymbol;
  1336. begin
  1337. if (def.dbg_state in [dbg_state_writing,dbg_state_written]) then
  1338. exit;
  1339. { never write generic template defs }
  1340. if df_generic in def.defoptions then
  1341. begin
  1342. def.dbg_state:=dbg_state_written;
  1343. exit;
  1344. end;
  1345. { to avoid infinite loops }
  1346. def.dbg_state := dbg_state_writing;
  1347. current_asmdata.asmlists[al_dwarf_info].concat(tai_comment.Create(strpnew('Definition '+def.typename)));
  1348. labsym:=def_dwarf_lab(def);
  1349. if ds_dwarf_dbg_info_written in def.defstates then
  1350. current_asmdata.asmlists[al_dwarf_info].concat(tai_symbol.create_global(labsym,0))
  1351. else
  1352. current_asmdata.asmlists[al_dwarf_info].concat(tai_symbol.create(labsym,0));
  1353. if (target_info.system in systems_darwin) then
  1354. begin
  1355. { On Darwin, dwarf info is not linked in the final binary,
  1356. but kept in the individual object files. This allows for
  1357. faster linking, but means that you have to keep the object
  1358. files for debugging and also that gdb only loads in the
  1359. debug info of a particular object file once you step into
  1360. or over a procedure in it.
  1361. To solve this, there is a tool called dsymutil which can
  1362. extract all the dwarf info from a program's object files.
  1363. This utility however performs "smart linking" on the dwarf
  1364. info and throws away all unreferenced dwarf entries. Since
  1365. variables' types always point to the dwarfino for a tdef
  1366. and never to that for a typesym, this means all debug
  1367. entries generated for typesyms are thrown away.
  1368. The problem with that is that we translate typesyms into
  1369. DW_TAG_typedef, and gdb's dwarf-2 reader only makes types
  1370. globally visibly if they are defined using a DW_TAG_typedef.
  1371. So as a result, before running dsymutil types only become
  1372. available once you stepped into/over a function in the object
  1373. file where they are declared, and after running dsymutil they
  1374. are all gone (printng variables still works because the
  1375. tdef dwarf info is still available, but you cannot typecast
  1376. anything outside the declaring units because the type names
  1377. are not known there).
  1378. The solution: if a tdef has an associated typesym, let the
  1379. debug label for the tdef point to a DW_TAG_typedef instead
  1380. of directly to the tdef itself. And don't write anything
  1381. special for the typesym itself.
  1382. }
  1383. if assigned(def.typesym) and
  1384. not(df_generic in def.defoptions) then
  1385. begin
  1386. current_asmdata.getaddrlabel(TAsmLabel(pointer(labsym)));
  1387. append_entry(DW_TAG_typedef,false,[
  1388. DW_AT_name,DW_FORM_string,symname(def.typesym)+#0
  1389. ]);
  1390. append_labelentry_ref(DW_AT_type,labsym);
  1391. finish_entry;
  1392. current_asmdata.asmlists[al_dwarf_info].concat(tai_symbol.create(labsym,0));
  1393. end;
  1394. end;
  1395. case def.typ of
  1396. stringdef :
  1397. appenddef_string(tstringdef(def));
  1398. enumdef :
  1399. appenddef_enum(tenumdef(def));
  1400. orddef :
  1401. appenddef_ord(torddef(def));
  1402. pointerdef :
  1403. appenddef_pointer(tpointerdef(def));
  1404. floatdef :
  1405. appenddef_float(tfloatdef(def));
  1406. filedef :
  1407. appenddef_file(tfiledef(def));
  1408. recorddef :
  1409. appenddef_record(trecorddef(def));
  1410. variantdef :
  1411. appenddef_variant(tvariantdef(def));
  1412. classrefdef :
  1413. appenddef_pointer(tpointerdef(pvmttype));
  1414. setdef :
  1415. appenddef_set(tsetdef(def));
  1416. formaldef :
  1417. appenddef_formal(tformaldef(def));
  1418. arraydef :
  1419. appenddef_array(tarraydef(def));
  1420. procvardef :
  1421. appenddef_procvar(tprocvardef(def));
  1422. objectdef :
  1423. appenddef_object(tobjectdef(def));
  1424. undefineddef :
  1425. appenddef_unineddef(tundefineddef(def));
  1426. else
  1427. internalerror(200601281);
  1428. end;
  1429. { create a derived reference type for pass-by-reference parameters }
  1430. { (gdb doesn't support DW_AT_variable_parameter yet) }
  1431. labsym:=def_dwarf_ref_lab(def);
  1432. if ds_dwarf_dbg_info_written in def.defstates then
  1433. current_asmdata.asmlists[al_dwarf_info].concat(tai_symbol.create_global(labsym,0))
  1434. else
  1435. current_asmdata.asmlists[al_dwarf_info].concat(tai_symbol.create(labsym,0));
  1436. append_entry(DW_TAG_reference_type,false,[]);
  1437. append_labelentry_ref(DW_AT_type,def_dwarf_lab(def));
  1438. finish_entry;
  1439. def.dbg_state := dbg_state_written;
  1440. end;
  1441. procedure TDebugInfoDwarf.insertdef(unused:TAsmList; def:tdef);
  1442. begin
  1443. appenddef(def);
  1444. end;
  1445. procedure TDebugInfoDwarf.write_symtable_defs(unused:TAsmList;st:TSymtable);
  1446. procedure dowritedwarf(st:TSymtable);
  1447. var
  1448. def : tdef;
  1449. i : longint;
  1450. begin
  1451. for i:=0 to st.DefList.Count-1 do
  1452. begin
  1453. def:=tdef(st.DefList[i]);
  1454. if (def.dbg_state=dbg_state_used) then
  1455. appenddef(def);
  1456. end;
  1457. end;
  1458. var
  1459. old_writing_def_dwarf : boolean;
  1460. begin
  1461. case st.symtabletype of
  1462. staticsymtable :
  1463. current_asmdata.asmlists[al_dwarf_info].concat(tai_comment.Create(strpnew('Defs - Begin Staticsymtable')));
  1464. globalsymtable :
  1465. current_asmdata.asmlists[al_dwarf_info].concat(tai_comment.Create(strpnew('Defs - Begin unit '+st.name^+' has index '+tostr(st.moduleid))));
  1466. end;
  1467. old_writing_def_dwarf:=writing_def_dwarf;
  1468. writing_def_dwarf:=true;
  1469. dowritedwarf(st);
  1470. writing_def_dwarf:=old_writing_def_dwarf;
  1471. case st.symtabletype of
  1472. staticsymtable :
  1473. current_asmdata.asmlists[al_dwarf_info].concat(tai_comment.Create(strpnew('Defs - End Staticsymtable')));
  1474. globalsymtable :
  1475. current_asmdata.asmlists[al_dwarf_info].concat(tai_comment.Create(strpnew('Defs - End unit '+st.name^+' has index '+tostr(st.moduleid))));
  1476. end;
  1477. end;
  1478. procedure TDebugInfoDwarf.appendprocdef(pd:tprocdef);
  1479. var
  1480. procendlabel : tasmlabel;
  1481. funcrettype : tasmsymbol;
  1482. procentry : string;
  1483. dreg : byte;
  1484. begin
  1485. if assigned(pd.procstarttai) then
  1486. begin
  1487. current_asmdata.asmlists[al_dwarf_info].concat(tai_comment.Create(strpnew('Procdef '+pd.fullprocname(true))));
  1488. append_entry(DW_TAG_subprogram,true,
  1489. [DW_AT_name,DW_FORM_string,symname(pd.procsym)+#0,
  1490. DW_AT_external,DW_FORM_flag,po_global in pd.procoptions
  1491. { data continues below }
  1492. { problem: base reg isn't known here
  1493. DW_AT_frame_base,DW_FORM_block1,1
  1494. }
  1495. ]);
  1496. { append block data }
  1497. { current_asmdata.asmlists[al_dwarf_info].concat(tai_const.create_8bit(dwarf_reg(pd.))); }
  1498. if not(is_void(tprocdef(pd).returndef)) then
  1499. append_labelentry_ref(DW_AT_type,def_dwarf_lab(tprocdef(pd).returndef));
  1500. { mark end of procedure }
  1501. current_asmdata.getlabel(procendlabel,alt_dbgtype);
  1502. current_asmdata.asmlists[al_procedures].insertbefore(tai_label.create(procendlabel),pd.procendtai);
  1503. if (target_info.system = system_powerpc64_linux) then
  1504. procentry := '.' + pd.mangledname
  1505. else
  1506. procentry := pd.mangledname;
  1507. append_labelentry(DW_AT_low_pc,current_asmdata.RefAsmSymbol(procentry));
  1508. append_labelentry(DW_AT_high_pc,procendlabel);
  1509. if assigned(pd.funcretsym) and
  1510. (tabstractnormalvarsym(pd.funcretsym).refs>0) then
  1511. begin
  1512. if tabstractnormalvarsym(pd.funcretsym).localloc.loc=LOC_REFERENCE then
  1513. begin
  1514. finish_entry;
  1515. if paramanager.ret_in_param(pd.returndef,pd.proccalloption) then
  1516. funcrettype:=def_dwarf_ref_lab(pd.returndef)
  1517. else
  1518. funcrettype:=def_dwarf_lab(pd.returndef);
  1519. append_entry(DW_TAG_formal_parameter,false,[
  1520. DW_AT_name,DW_FORM_string,pd.procsym.name+#0,
  1521. {
  1522. DW_AT_decl_file,DW_FORM_data1,0,
  1523. DW_AT_decl_line,DW_FORM_data1,
  1524. }
  1525. { data continues below }
  1526. DW_AT_location,DW_FORM_block1,1+Lengthsleb128(tabstractnormalvarsym(pd.funcretsym).localloc.reference.offset)
  1527. ]);
  1528. { append block data }
  1529. dreg:=dwarf_reg(tabstractnormalvarsym(pd.funcretsym).localloc.reference.base);
  1530. current_asmdata.asmlists[al_dwarf_info].concat(tai_const.create_8bit(ord(DW_OP_breg0)+dreg));
  1531. current_asmdata.asmlists[al_dwarf_info].concat(tai_const.create_sleb128bit(tabstractnormalvarsym(pd.funcretsym).localloc.reference.offset));
  1532. append_labelentry_ref(DW_AT_type,funcrettype);
  1533. end;
  1534. end;
  1535. finish_entry;
  1536. (*
  1537. { para types }
  1538. write_def_stabstr(templist,pd);
  1539. *)
  1540. if assigned(pd.parast) then
  1541. write_symtable_syms(pd.parast);
  1542. { local type defs and vars should not be written
  1543. inside the main proc stab }
  1544. if assigned(pd.localst) and
  1545. (pd.localst.symtabletype=localsymtable) then
  1546. write_symtable_syms(pd.localst);
  1547. { last write the types from this procdef }
  1548. if assigned(pd.parast) then
  1549. write_symtable_defs(nil,pd.parast);
  1550. if assigned(pd.localst) and
  1551. (pd.localst.symtabletype=localsymtable) then
  1552. write_symtable_defs(nil,pd.localst);
  1553. finish_children;
  1554. end;
  1555. end;
  1556. procedure TDebugInfoDwarf.appendsym_var(sym:tabstractnormalvarsym);
  1557. var
  1558. templist : TAsmList;
  1559. blocksize : longint;
  1560. tag : tdwarf_tag;
  1561. dreg : byte;
  1562. begin
  1563. { external symbols can't be resolved at link time, so we
  1564. can't generate stabs for them
  1565. not sure if this applies to dwarf as well (FK)
  1566. }
  1567. if vo_is_external in sym.varoptions then
  1568. exit;
  1569. { There is no space allocated for not referenced locals }
  1570. if (sym.owner.symtabletype=localsymtable) and (sym.refs=0) then
  1571. exit;
  1572. templist:=TAsmList.create;
  1573. case sym.localloc.loc of
  1574. LOC_REGISTER,
  1575. LOC_CREGISTER,
  1576. LOC_MMREGISTER,
  1577. LOC_CMMREGISTER,
  1578. LOC_FPUREGISTER,
  1579. LOC_CFPUREGISTER :
  1580. begin
  1581. templist.concat(tai_const.create_8bit(ord(DW_OP_regx)));
  1582. dreg:=dwarf_reg(sym.localloc.register);
  1583. templist.concat(tai_const.create_uleb128bit(dreg));
  1584. blocksize:=1+Lengthuleb128(dreg);
  1585. end;
  1586. else
  1587. begin
  1588. case sym.typ of
  1589. staticvarsym:
  1590. begin
  1591. if (vo_is_thread_var in sym.varoptions) then
  1592. begin
  1593. {$warning !!! FIXME: dwarf for thread vars !!!}
  1594. blocksize:=0;
  1595. end
  1596. else
  1597. begin
  1598. templist.concat(tai_const.create_8bit(3));
  1599. templist.concat(tai_const.createname(sym.mangledname,0));
  1600. blocksize:=1+sizeof(aword);
  1601. end;
  1602. end;
  1603. paravarsym,
  1604. localvarsym:
  1605. begin
  1606. dreg:=dwarf_reg(sym.localloc.reference.base);
  1607. templist.concat(tai_const.create_8bit(ord(DW_OP_breg0)+dreg));
  1608. templist.concat(tai_const.create_sleb128bit(sym.localloc.reference.offset));
  1609. blocksize:=1+Lengthsleb128(sym.localloc.reference.offset);
  1610. end
  1611. else
  1612. internalerror(200601288);
  1613. end;
  1614. end;
  1615. end;
  1616. if sym.typ=paravarsym then
  1617. tag:=DW_TAG_formal_parameter
  1618. else
  1619. tag:=DW_TAG_variable;
  1620. if not(sym.localloc.loc in [LOC_REGISTER,LOC_CREGISTER,LOC_MMREGISTER,
  1621. LOC_CMMREGISTER,LOC_FPUREGISTER,LOC_CFPUREGISTER]) and
  1622. ((sym.owner.symtabletype = globalsymtable) or
  1623. (sp_static in sym.symoptions) or
  1624. (vo_is_public in sym.varoptions)) then
  1625. append_entry(tag,false,[
  1626. DW_AT_name,DW_FORM_string,symname(sym)+#0,
  1627. {
  1628. DW_AT_decl_file,DW_FORM_data1,0,
  1629. DW_AT_decl_line,DW_FORM_data1,
  1630. }
  1631. DW_AT_external,DW_FORM_flag,true,
  1632. { data continues below }
  1633. DW_AT_location,DW_FORM_block1,blocksize
  1634. ])
  1635. {$ifdef gdb_supports_DW_AT_variable_parameter}
  1636. else if (sym.typ=paravarsym) and
  1637. paramanager.push_addr_param(sym.varspez,sym.vardef,tprocdef(sym.owner.defowner).proccalloption) and
  1638. not(vo_has_local_copy in sym.varoptions) and
  1639. not is_open_string(sym.vardef) then
  1640. append_entry(tag,false,[
  1641. DW_AT_name,DW_FORM_string,symname(sym)+#0,
  1642. DW_AT_variable_parameter,DW_FORM_flag,true,
  1643. {
  1644. DW_AT_decl_file,DW_FORM_data1,0,
  1645. DW_AT_decl_line,DW_FORM_data1,
  1646. }
  1647. { data continues below }
  1648. DW_AT_location,DW_FORM_block1,blocksize
  1649. ])
  1650. {$endif gdb_supports_DW_AT_variable_parameter}
  1651. else
  1652. append_entry(tag,false,[
  1653. DW_AT_name,DW_FORM_string,symname(sym)+#0,
  1654. {
  1655. DW_AT_decl_file,DW_FORM_data1,0,
  1656. DW_AT_decl_line,DW_FORM_data1,
  1657. }
  1658. { data continues below }
  1659. DW_AT_location,DW_FORM_block1,blocksize
  1660. ]);
  1661. { append block data }
  1662. current_asmdata.asmlists[al_dwarf_info].concatlist(templist);
  1663. {$ifndef gdb_supports_DW_AT_variable_parameter}
  1664. if (sym.typ=paravarsym) and
  1665. paramanager.push_addr_param(sym.varspez,sym.vardef,tprocdef(sym.owner.defowner).proccalloption) and
  1666. not(vo_has_local_copy in sym.varoptions) and
  1667. not is_open_string(sym.vardef) then
  1668. append_labelentry_ref(DW_AT_type,def_dwarf_ref_lab(sym.vardef))
  1669. else
  1670. {$endif not gdb_supports_DW_AT_variable_parameter}
  1671. append_labelentry_ref(DW_AT_type,def_dwarf_lab(sym.vardef));
  1672. templist.free;
  1673. finish_entry;
  1674. end;
  1675. procedure TDebugInfoDwarf.appendsym_fieldvar(sym: tfieldvarsym);
  1676. var
  1677. bitoffset,
  1678. fieldoffset,
  1679. fieldnatsize: aint;
  1680. begin
  1681. if sp_static in sym.symoptions then Exit;
  1682. if (tabstractrecordsymtable(sym.owner).usefieldalignment<>bit_alignment) or
  1683. { only ordinals are bitpacked }
  1684. not is_ordinal(sym.vardef) then
  1685. begin
  1686. { other kinds of fields can however also appear in a bitpacked }
  1687. { record, and then their offset is also specified in bits rather }
  1688. { than in bytes }
  1689. if (tabstractrecordsymtable(sym.owner).usefieldalignment<>bit_alignment) then
  1690. fieldoffset:=sym.fieldoffset
  1691. else
  1692. fieldoffset:=sym.fieldoffset div 8;
  1693. append_entry(DW_TAG_member,false,[
  1694. DW_AT_name,DW_FORM_string,symname(sym)+#0,
  1695. DW_AT_data_member_location,DW_FORM_block1,1+lengthuleb128(fieldoffset)
  1696. ]);
  1697. end
  1698. else
  1699. begin
  1700. if (sym.vardef.packedbitsize > 255) then
  1701. internalerror(2007061201);
  1702. { we don't bitpack according to the ABI, but as close as }
  1703. { possible, i.e., equivalent to gcc's }
  1704. { __attribute__((__packed__)), which is also what gpc }
  1705. { does. }
  1706. fieldnatsize:=max(sizeof(aint),sym.vardef.size);
  1707. fieldoffset:=(sym.fieldoffset div (fieldnatsize*8)) * fieldnatsize;
  1708. bitoffset:=sym.fieldoffset mod (fieldnatsize*8);
  1709. if (target_info.endian=endian_little) then
  1710. bitoffset:=(fieldnatsize*8)-bitoffset-sym.vardef.packedbitsize;
  1711. append_entry(DW_TAG_member,false,[
  1712. DW_AT_name,DW_FORM_string,symname(sym)+#0,
  1713. { gcc also generates both a bit and byte size attribute }
  1714. { we don't support ordinals >= 256 bits }
  1715. DW_AT_byte_size,DW_FORM_data1,fieldnatsize,
  1716. { nor >= 256 bits (not yet, anyway, see IE above) }
  1717. DW_AT_bit_size,DW_FORM_data1,sym.vardef.packedbitsize,
  1718. { data1 and data2 are unsigned, bitoffset can also be negative }
  1719. DW_AT_bit_offset,DW_FORM_data4,bitoffset,
  1720. DW_AT_data_member_location,DW_FORM_block1,1+lengthuleb128(fieldoffset)
  1721. ]);
  1722. end;
  1723. current_asmdata.asmlists[al_dwarf_info].concat(tai_const.create_8bit(ord(DW_OP_plus_uconst)));
  1724. current_asmdata.asmlists[al_dwarf_info].concat(tai_const.create_uleb128bit(fieldoffset));
  1725. append_labelentry_ref(DW_AT_type,def_dwarf_lab(sym.vardef));
  1726. finish_entry;
  1727. end;
  1728. procedure TDebugInfoDwarf.appendsym_const(sym:tconstsym);
  1729. begin
  1730. append_entry(DW_TAG_constant,false,[
  1731. DW_AT_name,DW_FORM_string,symname(sym)+#0
  1732. ]);
  1733. { for string constants, constdef isn't set because they have no real type }
  1734. if not(sym.consttyp in [conststring,constresourcestring,constwstring]) then
  1735. append_labelentry_ref(DW_AT_type,def_dwarf_lab(sym.constdef));
  1736. current_asmdata.asmlists[al_dwarf_abbrev].concat(tai_const.create_uleb128bit(ord(DW_AT_const_value)));
  1737. case sym.consttyp of
  1738. conststring:
  1739. begin
  1740. current_asmdata.asmlists[al_dwarf_abbrev].concat(tai_const.create_uleb128bit(ord(DW_FORM_string)));
  1741. current_asmdata.asmlists[al_dwarf_info].concat(tai_string.create(strpas(pchar(sym.value.valueptr))));
  1742. current_asmdata.asmlists[al_dwarf_info].concat(tai_const.create_8bit(0));
  1743. end;
  1744. constset,
  1745. constwstring,
  1746. constguid,
  1747. constresourcestring:
  1748. begin
  1749. { write dummy for now }
  1750. current_asmdata.asmlists[al_dwarf_abbrev].concat(tai_const.create_uleb128bit(ord(DW_FORM_string)));
  1751. current_asmdata.asmlists[al_dwarf_info].concat(tai_string.create(''));
  1752. current_asmdata.asmlists[al_dwarf_info].concat(tai_const.create_8bit(0));
  1753. end;
  1754. constord:
  1755. begin
  1756. current_asmdata.asmlists[al_dwarf_abbrev].concat(tai_const.create_uleb128bit(ord(DW_FORM_sdata)));
  1757. current_asmdata.asmlists[al_dwarf_info].concat(tai_const.create_sleb128bit(sym.value.valueord.svalue));
  1758. end;
  1759. constnil:
  1760. begin
  1761. {$ifdef cpu64bit}
  1762. current_asmdata.asmlists[al_dwarf_abbrev].concat(tai_const.create_uleb128bit(ord(DW_FORM_data8)));
  1763. current_asmdata.asmlists[al_dwarf_info].concat(tai_const.create_64bit(0));
  1764. {$else cpu64bit}
  1765. current_asmdata.asmlists[al_dwarf_abbrev].concat(tai_const.create_uleb128bit(ord(DW_FORM_data4)));
  1766. current_asmdata.asmlists[al_dwarf_info].concat(tai_const.create_32bit(0));
  1767. {$endif cpu64bit}
  1768. end;
  1769. constpointer:
  1770. begin
  1771. {$ifdef cpu64bit}
  1772. current_asmdata.asmlists[al_dwarf_abbrev].concat(tai_const.create_uleb128bit(ord(DW_FORM_data8)));
  1773. current_asmdata.asmlists[al_dwarf_info].concat(tai_const.create_64bit(int64(sym.value.valueordptr)));
  1774. {$else cpu64bit}
  1775. current_asmdata.asmlists[al_dwarf_abbrev].concat(tai_const.create_uleb128bit(ord(DW_FORM_data4)));
  1776. current_asmdata.asmlists[al_dwarf_info].concat(tai_const.create_32bit(sym.value.valueordptr));
  1777. {$endif cpu64bit}
  1778. end;
  1779. constreal:
  1780. begin
  1781. current_asmdata.asmlists[al_dwarf_abbrev].concat(tai_const.create_uleb128bit(ord(DW_FORM_block1)));
  1782. case tfloatdef(sym.constdef).floattype of
  1783. s32real:
  1784. begin
  1785. current_asmdata.asmlists[al_dwarf_info].concat(tai_const.create_8bit(4));
  1786. current_asmdata.asmlists[al_dwarf_info].concat(tai_real_32bit.create(psingle(sym.value.valueptr)^));
  1787. end;
  1788. s64comp,
  1789. s64currency,
  1790. s64real:
  1791. begin
  1792. current_asmdata.asmlists[al_dwarf_info].concat(tai_const.create_8bit(8));
  1793. current_asmdata.asmlists[al_dwarf_info].concat(tai_real_64bit.create(pdouble(sym.value.valueptr)^));
  1794. end;
  1795. s80real:
  1796. begin
  1797. current_asmdata.asmlists[al_dwarf_info].concat(tai_const.create_8bit(10));
  1798. current_asmdata.asmlists[al_dwarf_info].concat(tai_real_80bit.create(pextended(sym.value.valueptr)^));
  1799. end;
  1800. else
  1801. internalerror(200601291);
  1802. end;
  1803. end;
  1804. else
  1805. internalerror(200601292);
  1806. end;
  1807. finish_entry;
  1808. end;
  1809. procedure TDebugInfoDwarf.appendsym_label(sym: tlabelsym);
  1810. begin
  1811. { ignore label syms for now, the problem is that a label sym
  1812. can have more than one label associated e.g. in case of
  1813. an inline procedure expansion }
  1814. end;
  1815. procedure TDebugInfoDwarf.appendsym_proc(sym:tprocsym);
  1816. var
  1817. i : longint;
  1818. begin
  1819. for i:=0 to sym.ProcdefList.Count-1 do
  1820. appendprocdef(tprocdef(sym.ProcdefList[i]));
  1821. end;
  1822. procedure TDebugInfoDwarf.appendsym_property(sym: tpropertysym);
  1823. begin
  1824. { ignored for now }
  1825. end;
  1826. procedure TDebugInfoDwarf.appendsym_type(sym: ttypesym);
  1827. begin
  1828. if not (target_info.system in systems_darwin) then
  1829. begin
  1830. if not(df_generic in sym.typedef.defoptions) then
  1831. begin
  1832. append_entry(DW_TAG_typedef,false,[
  1833. DW_AT_name,DW_FORM_string,symname(sym)+#0
  1834. ]);
  1835. append_labelentry_ref(DW_AT_type,def_dwarf_lab(sym.typedef));
  1836. end;
  1837. finish_entry;
  1838. end
  1839. else
  1840. { just queue the def if needed }
  1841. def_dwarf_lab(sym.typedef);
  1842. (* Moved fom append sym, do we need this (MWE)
  1843. { For object types write also the symtable entries }
  1844. if (sym.typ=typesym) and (ttypesym(sym).typedef.typ=objectdef) then
  1845. write_symtable_syms(list,tobjectdef(ttypesym(sym).typedef).symtable);
  1846. *)
  1847. end;
  1848. procedure TDebugInfoDwarf.appendsym_unit(sym: tunitsym);
  1849. begin
  1850. { for now, we ignore unit symbols }
  1851. end;
  1852. procedure TDebugInfoDwarf.appendsym_absolute(sym:tabsolutevarsym);
  1853. var
  1854. templist : TAsmList;
  1855. blocksize : longint;
  1856. symlist : ppropaccesslistitem;
  1857. begin
  1858. templist:=TAsmList.create;
  1859. case tabsolutevarsym(sym).abstyp of
  1860. toaddr :
  1861. begin
  1862. { MWE: replaced ifdef i368 }
  1863. (*
  1864. if target_cpu = cpu_i386 then
  1865. begin
  1866. { in theory, we could write a DW_AT_segment entry here for sym.absseg,
  1867. however I doubt that gdb supports this (FK) }
  1868. end;
  1869. *)
  1870. templist.concat(tai_const.create_8bit(3));
  1871. templist.concat(tai_const.create_aint(sym.addroffset));
  1872. blocksize:=1+sizeof(aword);
  1873. end;
  1874. toasm :
  1875. begin
  1876. templist.concat(tai_const.create_8bit(3));
  1877. templist.concat(tai_const.createname(sym.mangledname,0));
  1878. blocksize:=1+sizeof(aword);
  1879. end;
  1880. tovar:
  1881. begin
  1882. symlist:=tabsolutevarsym(sym).ref.firstsym;
  1883. { can we insert the symbol? }
  1884. if assigned(symlist) and
  1885. (symlist^.sltype=sl_load) then
  1886. appendsym(symlist^.sym);
  1887. templist.free;
  1888. exit;
  1889. end;
  1890. end;
  1891. append_entry(DW_TAG_variable,false,[
  1892. DW_AT_name,DW_FORM_string,symname(sym)+#0,
  1893. {
  1894. DW_AT_decl_file,DW_FORM_data1,0,
  1895. DW_AT_decl_line,DW_FORM_data1,
  1896. }
  1897. DW_AT_external,DW_FORM_flag,true,
  1898. { data continues below }
  1899. DW_AT_location,DW_FORM_block1,blocksize
  1900. ]);
  1901. { append block data }
  1902. current_asmdata.asmlists[al_dwarf_info].concatlist(templist);
  1903. append_labelentry_ref(DW_AT_type,def_dwarf_lab(sym.vardef));
  1904. templist.free;
  1905. finish_entry;
  1906. end;
  1907. procedure TDebugInfoDwarf.appendsym(sym:tsym);
  1908. begin
  1909. if sym.isdbgwritten then
  1910. exit;
  1911. current_asmdata.asmlists[al_dwarf_info].concat(tai_comment.Create(strpnew('Symbol '+symname(sym))));
  1912. case sym.typ of
  1913. staticvarsym :
  1914. appendsym_var(tstaticvarsym(sym));
  1915. unitsym:
  1916. appendsym_unit(tunitsym(sym));
  1917. procsym :
  1918. appendsym_proc(tprocsym(sym));
  1919. labelsym :
  1920. appendsym_label(tlabelsym(sym));
  1921. localvarsym :
  1922. appendsym_var(tlocalvarsym(sym));
  1923. paravarsym :
  1924. appendsym_var(tparavarsym(sym));
  1925. constsym :
  1926. appendsym_const(tconstsym(sym));
  1927. typesym :
  1928. appendsym_type(ttypesym(sym));
  1929. enumsym :
  1930. { ignore enum syms, they are written by the owner }
  1931. ;
  1932. syssym :
  1933. { ignore sys syms, they are only of internal use }
  1934. ;
  1935. absolutevarsym :
  1936. appendsym_absolute(tabsolutevarsym(sym));
  1937. propertysym :
  1938. appendsym_property(tpropertysym(sym));
  1939. else
  1940. begin
  1941. writeln(ord(sym.typ));
  1942. internalerror(200601242);
  1943. end;
  1944. end;
  1945. sym.isdbgwritten:=true;
  1946. end;
  1947. procedure TDebugInfoDwarf.write_symtable_syms(st:TSymtable);
  1948. var
  1949. i : longint;
  1950. sym : tsym;
  1951. old_writing_def_dwarf : boolean;
  1952. begin
  1953. old_writing_def_dwarf:=writing_def_dwarf;
  1954. writing_def_dwarf:=false;
  1955. for i:=0 to st.SymList.Count-1 do
  1956. begin
  1957. sym:=tsym(st.SymList[i]);
  1958. if not(sp_hidden in sym.symoptions) and
  1959. (not sym.isdbgwritten) then
  1960. appendsym(sym);
  1961. end;
  1962. writing_def_dwarf:=old_writing_def_dwarf;
  1963. end;
  1964. procedure TDebugInfoDwarf.insertmoduleinfo;
  1965. var
  1966. templist: TAsmList;
  1967. linelist: TAsmList;
  1968. lbl : tasmlabel;
  1969. n,m : Integer;
  1970. ditem : TDirIndexItem;
  1971. fitem : TFileIndexItem;
  1972. flist : TFPList;
  1973. begin
  1974. { insert .Ltext0 label }
  1975. templist:=TAsmList.create;
  1976. new_section(templist,sec_code,'',0);
  1977. templist.concat(tai_symbol.createname(target_asm.labelprefix+'text0',AT_DATA,0));
  1978. current_asmdata.asmlists[al_start].insertlist(templist);
  1979. templist.free;
  1980. { insert .Letext0 label }
  1981. templist:=TAsmList.create;
  1982. new_section(templist,sec_code,'',0);
  1983. templist.concat(tai_symbol.createname(target_asm.labelprefix+'etext0',AT_DATA,0));
  1984. current_asmdata.asmlists[al_end].insertlist(templist);
  1985. templist.free;
  1986. { insert .Ldebug_abbrev0 label }
  1987. templist:=TAsmList.create;
  1988. new_section(templist,sec_debug_abbrev,'',0);
  1989. templist.concat(tai_symbol.createname(target_asm.labelprefix+'debug_abbrevsection0',AT_DATA,0));
  1990. { add any extra stuff which needs to be in the abbrev section, but before }
  1991. { the actual abbreviations, in between the symbol above and below, i.e. here }
  1992. templist.concat(tai_symbol.createname(target_asm.labelprefix+'debug_abbrev0',AT_DATA,0));
  1993. current_asmdata.asmlists[al_start].insertlist(templist);
  1994. templist.free;
  1995. { insert .Ldebug_line0 label }
  1996. templist:=TAsmList.create;
  1997. new_section(templist,sec_debug_line,'',0);
  1998. templist.concat(tai_symbol.createname(target_asm.labelprefix+'debug_linesection0',AT_DATA,0));
  1999. { add any extra stuff which needs to be in the line section, but before }
  2000. { the actual line info, in between the symbol above and below, i.e. here }
  2001. templist.concat(tai_symbol.createname(target_asm.labelprefix+'debug_line0',AT_DATA,0));
  2002. current_asmdata.asmlists[al_start].insertlist(templist);
  2003. templist.free;
  2004. { finalize line info if the unit doesn't contain any function/ }
  2005. { procedure/init/final code }
  2006. finish_lineinfo;
  2007. { debug line header }
  2008. linelist := current_asmdata.asmlists[al_dwarf_line];
  2009. new_section(linelist,sec_debug_line,'',0);
  2010. linelist.concat(tai_comment.Create(strpnew('=== header start ===')));
  2011. { size }
  2012. current_asmdata.getlabel(lbl,alt_dbgfile);
  2013. if use_64bit_headers then
  2014. linelist.concat(tai_const.create_32bit(longint($FFFFFFFF)));
  2015. linelist.concat(tai_const.create_rel_sym(offsetreltype,
  2016. lbl,current_asmdata.RefAsmSymbol(target_asm.labelprefix+'edebug_line0')));
  2017. linelist.concat(tai_label.create(lbl));
  2018. { version }
  2019. linelist.concat(tai_const.create_16bit(dwarf_version));
  2020. { header length }
  2021. current_asmdata.getlabel(lbl,alt_dbgfile);
  2022. linelist.concat(tai_const.create_rel_sym(offsetreltype,
  2023. lbl,current_asmdata.RefAsmSymbol(target_asm.labelprefix+'ehdebug_line0')));
  2024. linelist.concat(tai_label.create(lbl));
  2025. { minimum_instruction_length }
  2026. linelist.concat(tai_const.create_8bit(1));
  2027. { default_is_stmt }
  2028. linelist.concat(tai_const.create_8bit(1));
  2029. { line_base }
  2030. linelist.concat(tai_const.create_8bit(LINE_BASE));
  2031. { line_range }
  2032. { only line increase, no adress }
  2033. linelist.concat(tai_const.create_8bit(255));
  2034. { opcode_base }
  2035. linelist.concat(tai_const.create_8bit(OPCODE_BASE));
  2036. { standard_opcode_lengths }
  2037. { MWE: sigh... why adding the default lengths (and make those sizes sense with LEB encoding) }
  2038. { DW_LNS_copy }
  2039. linelist.concat(tai_const.create_8bit(0));
  2040. { DW_LNS_advance_pc }
  2041. linelist.concat(tai_const.create_8bit(1));
  2042. { DW_LNS_advance_line }
  2043. linelist.concat(tai_const.create_8bit(1));
  2044. { DW_LNS_set_file }
  2045. linelist.concat(tai_const.create_8bit(1));
  2046. { DW_LNS_set_column }
  2047. linelist.concat(tai_const.create_8bit(1));
  2048. { DW_LNS_negate_stmt }
  2049. linelist.concat(tai_const.create_8bit(0));
  2050. { DW_LNS_set_basic_block }
  2051. linelist.concat(tai_const.create_8bit(0));
  2052. { DW_LNS_const_add_pc }
  2053. linelist.concat(tai_const.create_8bit(0));
  2054. { DW_LNS_fixed_advance_pc }
  2055. linelist.concat(tai_const.create_8bit(1));
  2056. { DW_LNS_set_prologue_end }
  2057. linelist.concat(tai_const.create_8bit(0));
  2058. { DW_LNS_set_epilogue_begin }
  2059. linelist.concat(tai_const.create_8bit(0));
  2060. { DW_LNS_set_isa }
  2061. linelist.concat(tai_const.create_8bit(1));
  2062. { Create single list of filenames sorted in IndexNr }
  2063. flist:=TFPList.Create;
  2064. for n := 0 to dirlist.Count - 1 do
  2065. begin
  2066. ditem := TDirIndexItem(dirlist[n]);
  2067. for m := 0 to ditem.Files.Count - 1 do
  2068. flist.Add(ditem.Files[m]);
  2069. end;
  2070. flist.Sort(@FileListSortCompare);
  2071. { include_directories }
  2072. linelist.concat(tai_comment.Create(strpnew('include_directories')));
  2073. for n := 0 to dirlist.Count - 1 do
  2074. begin
  2075. ditem := TDirIndexItem(dirlist[n]);
  2076. if ditem.Name = '.' then
  2077. Continue;
  2078. { Write without trailing path delimiter and also don't prefix with ./ for current dir (already done while adding to dirlist }
  2079. linelist.concat(tai_string.create(ditem.Name+#0));
  2080. end;
  2081. linelist.concat(tai_const.create_8bit(0));
  2082. { file_names }
  2083. linelist.concat(tai_comment.Create(strpnew('file_names')));
  2084. for n := 0 to flist.Count - 1 do
  2085. begin
  2086. fitem := TFileIndexItem(flist[n]);
  2087. { file name }
  2088. linelist.concat(tai_string.create(fitem.Name+#0));
  2089. { directory index }
  2090. linelist.concat(tai_const.create_uleb128bit(fitem.DirIndex));
  2091. { last modification }
  2092. linelist.concat(tai_const.create_uleb128bit(0));
  2093. { file length }
  2094. linelist.concat(tai_const.create_uleb128bit(0));
  2095. end;
  2096. linelist.concat(tai_const.create_8bit(0));
  2097. { end of debug line header }
  2098. linelist.concat(tai_symbol.createname(target_asm.labelprefix+'ehdebug_line0',AT_DATA,0));
  2099. linelist.concat(tai_comment.Create(strpnew('=== header end ===')));
  2100. { add line program }
  2101. linelist.concatList(asmline);
  2102. { end of debug line table }
  2103. linelist.concat(tai_symbol.createname(target_asm.labelprefix+'edebug_line0',AT_DATA,0));
  2104. flist.free;
  2105. end;
  2106. procedure TDebugInfoDwarf.inserttypeinfo;
  2107. procedure write_defs_to_write;
  2108. var
  2109. n : integer;
  2110. looplist,
  2111. templist: TFPObjectList;
  2112. def : tdef;
  2113. begin
  2114. templist := TFPObjectList.Create(False);
  2115. looplist := deftowritelist;
  2116. while looplist.count > 0 do
  2117. begin
  2118. deftowritelist := templist;
  2119. for n := 0 to looplist.count - 1 do
  2120. begin
  2121. def := tdef(looplist[n]);
  2122. case def.dbg_state of
  2123. dbg_state_written:
  2124. continue;
  2125. dbg_state_writing:
  2126. internalerror(200610052);
  2127. dbg_state_unused:
  2128. internalerror(200610053);
  2129. dbg_state_used:
  2130. appenddef(def)
  2131. else
  2132. internalerror(200610054);
  2133. end;
  2134. end;
  2135. looplist.clear;
  2136. templist := looplist;
  2137. looplist := deftowritelist;
  2138. end;
  2139. templist.free;
  2140. end;
  2141. var
  2142. storefilepos : tfileposinfo;
  2143. lenstartlabel : tasmlabel;
  2144. i : longint;
  2145. def: tdef;
  2146. begin
  2147. storefilepos:=current_filepos;
  2148. current_filepos:=current_module.mainfilepos;
  2149. currabbrevnumber:=0;
  2150. writing_def_dwarf:=false;
  2151. defnumberlist:=TFPObjectList.create(false);
  2152. deftowritelist:=TFPObjectList.create(false);
  2153. { not exported (FK)
  2154. FILEREC
  2155. TEXTREC
  2156. }
  2157. vardatadef:=trecorddef(search_system_type('TVARDATA').typedef);
  2158. { write start labels }
  2159. current_asmdata.asmlists[al_dwarf_info].concat(tai_section.create(sec_debug_info,'',0));
  2160. current_asmdata.asmlists[al_dwarf_info].concat(tai_symbol.createname(target_asm.labelprefix+'debug_info0',AT_DATA,0));
  2161. { start abbrev section }
  2162. new_section(current_asmdata.asmlists[al_dwarf_abbrev],sec_debug_abbrev,'',0);
  2163. { debug info header }
  2164. current_asmdata.getlabel(lenstartlabel,alt_dbgfile);
  2165. { size }
  2166. if use_64bit_headers then
  2167. current_asmdata.asmlists[al_dwarf_info].concat(tai_const.create_32bit(longint($FFFFFFFF)));
  2168. current_asmdata.asmlists[al_dwarf_info].concat(tai_const.create_rel_sym(offsetreltype,
  2169. lenstartlabel,current_asmdata.RefAsmSymbol(target_asm.labelprefix+'edebug_info0')));
  2170. current_asmdata.asmlists[al_dwarf_info].concat(tai_label.create(lenstartlabel));
  2171. { version }
  2172. current_asmdata.asmlists[al_dwarf_info].concat(tai_const.create_16bit(dwarf_version));
  2173. { abbrev table (=relative from section start)}
  2174. if not(tf_dwarf_relative_addresses in target_info.flags) then
  2175. current_asmdata.asmlists[al_dwarf_info].concat(tai_const.create_type_sym(offsetabstype,
  2176. current_asmdata.RefAsmSymbol(target_asm.labelprefix+'debug_abbrev0')))
  2177. else
  2178. current_asmdata.asmlists[al_dwarf_info].concat(tai_const.create_rel_sym(offsetreltype,
  2179. current_asmdata.RefAsmSymbol(target_asm.labelprefix+'debug_abbrevsection0'),
  2180. current_asmdata.RefAsmSymbol(target_asm.labelprefix+'debug_abbrev0')));
  2181. { address size }
  2182. current_asmdata.asmlists[al_dwarf_info].concat(tai_const.create_8bit(sizeof(aint)));
  2183. { first manadatory compilation unit TAG }
  2184. append_entry(DW_TAG_compile_unit,true,[
  2185. DW_AT_name,DW_FORM_string,relative_dwarf_path(current_module.sourcefiles.get_file(1).path^+current_module.sourcefiles.get_file(1).name^)+#0,
  2186. DW_AT_producer,DW_FORM_string,'Free Pascal '+full_version_string+' '+date_string+#0,
  2187. DW_AT_comp_dir,DW_FORM_string,BSToSlash(FixPath(GetCurrentDir,false))+#0,
  2188. DW_AT_language,DW_FORM_data1,DW_LANG_Pascal83,
  2189. DW_AT_identifier_case,DW_FORM_data1,DW_ID_case_insensitive]);
  2190. { reference to line info section }
  2191. if not(tf_dwarf_relative_addresses in target_info.flags) then
  2192. append_labelentry_dataptr_abs(DW_AT_stmt_list,current_asmdata.RefAsmSymbol(target_asm.labelprefix+'debug_line0'))
  2193. else
  2194. append_labelentry_dataptr_rel(DW_AT_stmt_list,
  2195. current_asmdata.RefAsmSymbol(target_asm.labelprefix+'debug_linesection0'),
  2196. current_asmdata.RefAsmSymbol(target_asm.labelprefix+'debug_line0'));
  2197. append_labelentry(DW_AT_low_pc,current_asmdata.RefAsmSymbol(target_asm.labelprefix+'text0'));
  2198. append_labelentry(DW_AT_high_pc,current_asmdata.RefAsmSymbol(target_asm.labelprefix+'etext0'));
  2199. finish_entry;
  2200. { first write all global/local symbols. This will flag all required tdefs }
  2201. if assigned(current_module.globalsymtable) then
  2202. begin
  2203. 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))));
  2204. write_symtable_syms(current_module.globalsymtable);
  2205. 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))));
  2206. end;
  2207. if assigned(current_module.localsymtable) then
  2208. begin
  2209. current_asmdata.asmlists[al_dwarf_info].concat(tai_comment.Create(strpnew('Syms - Begin Staticsymtable')));
  2210. write_symtable_syms(current_module.localsymtable);
  2211. current_asmdata.asmlists[al_dwarf_info].concat(tai_comment.Create(strpnew('Syms - End Staticsymtable')));
  2212. end;
  2213. { reset unit type info flag }
  2214. reset_unit_type_info;
  2215. { write used types from the used units }
  2216. write_used_unit_type_info(current_asmdata.asmlists[al_dwarf_info],current_module);
  2217. { last write the types from this unit }
  2218. if assigned(current_module.globalsymtable) then
  2219. write_symtable_defs(current_asmdata.asmlists[al_dwarf_info],current_module.globalsymtable);
  2220. if assigned(current_module.localsymtable) then
  2221. write_symtable_defs(current_asmdata.asmlists[al_dwarf_info],current_module.localsymtable);
  2222. { write defs not written yet }
  2223. write_defs_to_write;
  2224. { close compilation unit entry }
  2225. finish_children;
  2226. { end of debug info table }
  2227. current_asmdata.asmlists[al_dwarf_info].concat(tai_const.create_8bit(0));
  2228. current_asmdata.asmlists[al_dwarf_info].concat(tai_symbol.createname(target_asm.labelprefix+'edebug_info0',AT_DATA,0));
  2229. { end of abbrev table }
  2230. current_asmdata.asmlists[al_dwarf_abbrev].concat(tai_const.create_8bit(0));
  2231. { reset all def labels }
  2232. for i:=0 to defnumberlist.count-1 do
  2233. begin
  2234. def := tdef(defnumberlist[i]);
  2235. if assigned(def) then
  2236. begin
  2237. def.dwarf_lab:=nil;
  2238. def.dbg_state:=dbg_state_unused;
  2239. end;
  2240. end;
  2241. defnumberlist.free;
  2242. defnumberlist:=nil;
  2243. deftowritelist.free;
  2244. deftowritelist:=nil;
  2245. current_filepos:=storefilepos;
  2246. end;
  2247. procedure TDebugInfoDwarf.referencesections(list:TAsmList);
  2248. begin
  2249. end;
  2250. function TDebugInfoDwarf.symname(sym: tsym): String;
  2251. begin
  2252. if (sym.typ=paravarsym) and
  2253. (vo_is_self in tparavarsym(sym).varoptions) then
  2254. result:='this'
  2255. else
  2256. result := sym.Name;
  2257. end;
  2258. procedure TDebugInfoDwarf.insertlineinfo(list:TAsmList);
  2259. var
  2260. currfileinfo,
  2261. lastfileinfo : tfileposinfo;
  2262. currfuncname : pshortstring;
  2263. currsectype : TAsmSectiontype;
  2264. hp, hpend : tai;
  2265. infile : tinputfile;
  2266. prevcolumn,
  2267. diffline,
  2268. prevline,
  2269. prevfileidx,
  2270. currfileidx: Integer;
  2271. prevlabel,
  2272. currlabel : tasmlabel;
  2273. begin
  2274. { this function will always terminate the lineinfo block }
  2275. generated_lineinfo := true;
  2276. FillChar(lastfileinfo,sizeof(lastfileinfo),0);
  2277. currfuncname:=nil;
  2278. currsectype:=sec_code;
  2279. hp:=Tai(list.first);
  2280. prevcolumn := 0;
  2281. prevline := 1;
  2282. prevfileidx := 1;
  2283. prevlabel := nil;
  2284. while assigned(hp) do
  2285. begin
  2286. case hp.typ of
  2287. ait_section :
  2288. currsectype:=tai_section(hp).sectype;
  2289. ait_function_name :
  2290. begin
  2291. currfuncname:=tai_function_name(hp).funcname;
  2292. asmline.concat(tai_comment.Create(strpnew('function: '+currfuncname^)));
  2293. end;
  2294. ait_force_line : begin
  2295. lastfileinfo.line:=-1;
  2296. end;
  2297. end;
  2298. if (currsectype=sec_code) and
  2299. (hp.typ=ait_instruction) then
  2300. begin
  2301. currfileinfo:=tailineinfo(hp).fileinfo;
  2302. { file changed ? (must be before line info) }
  2303. if (currfileinfo.fileindex<>0) and
  2304. (lastfileinfo.fileindex<>currfileinfo.fileindex) then
  2305. begin
  2306. infile:=current_module.sourcefiles.get_file(currfileinfo.fileindex);
  2307. if assigned(infile) then
  2308. begin
  2309. currfileidx := get_file_index(infile);
  2310. if prevfileidx <> currfileidx then
  2311. begin
  2312. list.insertbefore(tai_comment.Create(strpnew('path: '+infile.path^)), hp);
  2313. list.insertbefore(tai_comment.Create(strpnew('file: '+infile.name^)), hp);
  2314. list.insertbefore(tai_comment.Create(strpnew('indx: '+tostr(currfileidx))), hp);
  2315. { set file }
  2316. asmline.concat(tai_comment.Create(strpnew('path: '+infile.path^)));
  2317. asmline.concat(tai_comment.Create(strpnew('file: '+infile.name^)));
  2318. asmline.concat(tai_const.create_8bit(DW_LNS_set_file));
  2319. asmline.concat(tai_const.create_uleb128bit(currfileidx));
  2320. prevfileidx := currfileidx;
  2321. end;
  2322. { force new line info }
  2323. lastfileinfo.line:=-1;
  2324. end;
  2325. end;
  2326. { line changed ? }
  2327. if (lastfileinfo.line<>currfileinfo.line) and (currfileinfo.line<>0) then
  2328. begin
  2329. { set address }
  2330. current_asmdata.getlabel(currlabel, alt_dbgline);
  2331. list.insertbefore(tai_label.create(currlabel), hp);
  2332. asmline.concat(tai_comment.Create(strpnew('['+tostr(currfileinfo.line)+':'+tostr(currfileinfo.column)+']')));
  2333. if (prevlabel = nil) or
  2334. { darwin's assembler cannot create an uleb128 of the difference }
  2335. { between to symbols }
  2336. (target_info.system in systems_darwin) then
  2337. begin
  2338. asmline.concat(tai_const.create_8bit(DW_LNS_extended_op));
  2339. asmline.concat(tai_const.create_uleb128bit(1+sizeof(aint)));
  2340. asmline.concat(tai_const.create_8bit(DW_LNE_set_address));
  2341. asmline.concat(tai_const.create_sym(currlabel));
  2342. end
  2343. else
  2344. begin
  2345. asmline.concat(tai_const.create_8bit(DW_LNS_advance_pc));
  2346. asmline.concat(tai_const.create_rel_sym(aitconst_uleb128bit, prevlabel, currlabel));
  2347. end;
  2348. prevlabel := currlabel;
  2349. { set column }
  2350. if prevcolumn <> currfileinfo.column then
  2351. begin
  2352. asmline.concat(tai_const.create_8bit(DW_LNS_set_column));
  2353. asmline.concat(tai_const.create_uleb128bit(currfileinfo.column));
  2354. prevcolumn := currfileinfo.column;
  2355. end;
  2356. { set line }
  2357. diffline := currfileinfo.line - prevline;
  2358. if (diffline >= LINE_BASE) and (OPCODE_BASE + diffline - LINE_BASE <= 255) then
  2359. begin
  2360. { use special opcode, this also adds a row }
  2361. asmline.concat(tai_const.create_8bit(OPCODE_BASE + diffline - LINE_BASE));
  2362. end
  2363. else
  2364. begin
  2365. if diffline <> 0 then
  2366. begin
  2367. asmline.concat(tai_const.create_8bit(DW_LNS_advance_line));
  2368. asmline.concat(tai_const.create_sleb128bit(diffline));
  2369. end;
  2370. { no row added yet, do it manually }
  2371. asmline.concat(tai_const.create_8bit(DW_LNS_copy));
  2372. end;
  2373. prevline := currfileinfo.line;
  2374. end;
  2375. lastfileinfo:=currfileinfo;
  2376. end;
  2377. hpend:=hp;
  2378. hp:=tai(hp.next);
  2379. end;
  2380. if assigned(hpend) then
  2381. begin
  2382. { set address for end (see appendix 3 of dwarf 2 specs) }
  2383. current_asmdata.getlabel(currlabel, alt_dbgline);
  2384. list.insertafter(tai_label.create(currlabel), hpend);
  2385. asmline.concat(tai_const.create_8bit(DW_LNS_extended_op));
  2386. asmline.concat(tai_const.create_uleb128bit(1+sizeof(aint)));
  2387. asmline.concat(tai_const.create_8bit(DW_LNE_set_address));
  2388. asmline.concat(tai_const.create_sym(currlabel));
  2389. end;
  2390. { end sequence }
  2391. asmline.concat(tai_const.Create_8bit(DW_LNS_extended_op));
  2392. asmline.concat(tai_const.Create_8bit(1));
  2393. asmline.concat(tai_const.Create_8bit(DW_LNE_end_sequence));
  2394. asmline.concat(tai_comment.Create(strpnew('###################')));
  2395. end;
  2396. procedure TDebugInfoDwarf.finish_lineinfo;
  2397. var
  2398. infile: tinputfile;
  2399. begin
  2400. { only needed if no line info at all has been generated }
  2401. if generated_lineinfo then
  2402. begin
  2403. { reset for next module compilation }
  2404. generated_lineinfo:=false;
  2405. exit;
  2406. end;
  2407. { at least the Darwin linker is annoyed if you do not }
  2408. { finish the lineinfo section, or if it doesn't }
  2409. { contain at least one file name and set_address }
  2410. infile:=current_module.sourcefiles.get_file(1);
  2411. if not assigned(infile) then
  2412. internalerror(2006020211);
  2413. asmline.concat(tai_const.create_8bit(DW_LNS_set_file));
  2414. asmline.concat(tai_const.create_uleb128bit(get_file_index(infile)));
  2415. asmline.concat(tai_const.create_8bit(DW_LNS_extended_op));
  2416. asmline.concat(tai_const.create_uleb128bit(1+sizeof(aint)));
  2417. asmline.concat(tai_const.create_8bit(DW_LNE_set_address));
  2418. asmline.concat(tai_const.create_sym(nil));
  2419. asmline.concat(tai_const.create_8bit(DW_LNS_extended_op));
  2420. asmline.concat(tai_const.Create_8bit(1));
  2421. asmline.concat(tai_const.Create_8bit(DW_LNE_end_sequence));
  2422. asmline.concat(tai_comment.Create(strpnew('###################')));
  2423. end;
  2424. {****************************************************************************
  2425. TDebugInfoDwarf2
  2426. ****************************************************************************}
  2427. procedure TDebugInfoDwarf2.appenddef_file(def: tfiledef);
  2428. begin
  2429. { gdb 6.4 doesn't support files so far so we use some fake recorddef
  2430. file recs. are less than 1k so using data2 is enough }
  2431. if assigned(def.typesym) then
  2432. append_entry(DW_TAG_structure_type,false,[
  2433. DW_AT_name,DW_FORM_string,symname(def.typesym)+#0,
  2434. DW_AT_byte_size,DW_FORM_udata,def.size
  2435. ])
  2436. else
  2437. append_entry(DW_TAG_structure_type,false,[
  2438. DW_AT_byte_size,DW_FORM_udata,def.size
  2439. ]);
  2440. finish_entry;
  2441. end;
  2442. procedure TDebugInfoDwarf2.appenddef_formal(def: tformaldef);
  2443. begin
  2444. { gdb 6.4 doesn't support DW_TAG_unspecified_type so we
  2445. replace it with a unsigned type with size 0 (FK)
  2446. }
  2447. append_entry(DW_TAG_base_type,false,[
  2448. DW_AT_name,DW_FORM_string,'FormalDef'#0,
  2449. DW_AT_encoding,DW_FORM_data1,DW_ATE_unsigned,
  2450. DW_AT_byte_size,DW_FORM_data1,0
  2451. ]);
  2452. finish_entry;
  2453. end;
  2454. procedure TDebugInfoDwarf2.appenddef_object(def: tobjectdef);
  2455. procedure doappend;
  2456. begin
  2457. if assigned(def.objname) then
  2458. append_entry(DW_TAG_structure_type,true,[
  2459. DW_AT_name,DW_FORM_string,def.objname^+#0,
  2460. DW_AT_byte_size,DW_FORM_udata,tobjectsymtable(def.symtable).datasize
  2461. ])
  2462. else
  2463. append_entry(DW_TAG_structure_type,true,[
  2464. DW_AT_byte_size,DW_FORM_udata,tobjectsymtable(def.symtable).datasize
  2465. ]);
  2466. finish_entry;
  2467. if assigned(def.childof) then
  2468. begin
  2469. append_entry(DW_TAG_inheritance,false,[
  2470. DW_AT_accessibility,DW_FORM_data1,DW_ACCESS_public,
  2471. DW_AT_data_member_location,DW_FORM_block1,1+lengthuleb128(0)
  2472. ]);
  2473. current_asmdata.asmlists[al_dwarf_info].concat(tai_const.create_8bit(ord(DW_OP_plus_uconst)));
  2474. current_asmdata.asmlists[al_dwarf_info].concat(tai_const.create_uleb128bit(0));
  2475. if (def.childof.dbg_state=dbg_state_unused) then
  2476. def.childof.dbg_state:=dbg_state_used;
  2477. if is_class_or_interface_or_dispinterface(def) then
  2478. append_labelentry_ref(DW_AT_type,def_dwarf_class_struct_lab(def.childof))
  2479. else
  2480. append_labelentry_ref(DW_AT_type,def_dwarf_lab(def.childof));
  2481. finish_entry;
  2482. end;
  2483. if (oo_has_vmt in def.objectoptions) and
  2484. (not assigned(def.childof) or
  2485. not(oo_has_vmt in def.childof.objectoptions)) then
  2486. begin
  2487. { vmt field }
  2488. append_entry(DW_TAG_member,false,[
  2489. DW_AT_artificial,DW_FORM_flag,true,
  2490. DW_AT_name,DW_FORM_string,'_vptr$'+def.objname^+#0,
  2491. DW_AT_data_member_location,DW_FORM_block1,1+lengthuleb128(def.vmt_offset)
  2492. ]);
  2493. current_asmdata.asmlists[al_dwarf_info].concat(tai_const.create_8bit(ord(DW_OP_plus_uconst)));
  2494. current_asmdata.asmlists[al_dwarf_info].concat(tai_const.create_uleb128bit(def.vmt_offset));
  2495. { should be changed into a pointer to a function returning an }
  2496. { int and with TAG_unspecified_parameters }
  2497. if (voidpointertype.dbg_state=dbg_state_unused) then
  2498. voidpointertype.dbg_state:=dbg_state_used;
  2499. append_labelentry_ref(DW_AT_type,def_dwarf_lab(voidpointertype));
  2500. finish_entry;
  2501. end;
  2502. def.symtable.symList.ForEachCall(@enum_membersyms_callback,nil);
  2503. finish_children;
  2504. end;
  2505. begin
  2506. case def.objecttype of
  2507. odt_cppclass,
  2508. odt_object:
  2509. doappend;
  2510. odt_interfacecom,
  2511. odt_interfacecorba,
  2512. odt_dispinterface,
  2513. odt_class:
  2514. begin
  2515. { implicit pointer }
  2516. append_entry(DW_TAG_pointer_type,false,[]);
  2517. append_labelentry_ref(DW_AT_type,def_dwarf_class_struct_lab(def));
  2518. finish_entry;
  2519. if not(tf_dwarf_only_local_labels in target_info.flags) then
  2520. current_asmdata.asmlists[al_dwarf_info].concat(tai_symbol.create_global(def_dwarf_class_struct_lab(def),0))
  2521. else
  2522. current_asmdata.asmlists[al_dwarf_info].concat(tai_symbol.create(def_dwarf_class_struct_lab(def),0));
  2523. doappend;
  2524. end;
  2525. else
  2526. internalerror(200602041);
  2527. end;
  2528. end;
  2529. procedure TDebugInfoDwarf2.appenddef_set(def: tsetdef);
  2530. begin
  2531. if (ds_dwarf_sets in current_settings.debugswitches) then
  2532. begin
  2533. { current (20070704 -- patch was committed on 20060513) gdb cvs supports set types }
  2534. if assigned(def.typesym) then
  2535. append_entry(DW_TAG_set_type,false,[
  2536. DW_AT_name,DW_FORM_string,symname(def.typesym)+#0,
  2537. DW_AT_byte_size,DW_FORM_data2,def.size
  2538. ])
  2539. else
  2540. append_entry(DW_TAG_set_type,false,[
  2541. DW_AT_byte_size,DW_FORM_data2,def.size
  2542. ]);
  2543. append_labelentry_ref(DW_AT_type,def_dwarf_lab(def.elementdef));
  2544. end
  2545. else
  2546. begin
  2547. { gdb versions which don't support sets refuse to load the debug }
  2548. { info of modules that contain set tags }
  2549. if assigned(def.typesym) then
  2550. append_entry(DW_TAG_base_type,false,[
  2551. DW_AT_name,DW_FORM_string,symname(def.typesym)+#0,
  2552. DW_AT_encoding,DW_FORM_data1,DW_ATE_unsigned,
  2553. DW_AT_byte_size,DW_FORM_data2,def.size
  2554. ])
  2555. else
  2556. append_entry(DW_TAG_base_type,false,[
  2557. DW_AT_encoding,DW_FORM_data1,DW_ATE_unsigned,
  2558. DW_AT_byte_size,DW_FORM_data2,def.size
  2559. ]);
  2560. end;
  2561. finish_entry;
  2562. end;
  2563. procedure TDebugInfoDwarf2.appenddef_unineddef(def: tundefineddef);
  2564. begin
  2565. { gdb 6.4 doesn't support DW_TAG_unspecified_type so we
  2566. replace it with a unsigned type with size 0 (FK)
  2567. }
  2568. append_entry(DW_TAG_base_type,false,[
  2569. DW_AT_name,DW_FORM_string,'FormalDef'#0,
  2570. DW_AT_encoding,DW_FORM_data1,DW_ATE_unsigned,
  2571. DW_AT_byte_size,DW_FORM_data1,0
  2572. ]);
  2573. finish_entry;
  2574. end;
  2575. procedure TDebugInfoDwarf2.appenddef_variant(def: tvariantdef);
  2576. begin
  2577. { variants aren't known to dwarf2 but writting tvardata should be enough }
  2578. appenddef_record(trecorddef(vardatadef));
  2579. end;
  2580. function TDebugInfoDwarf2.dwarf_version: Word;
  2581. begin
  2582. Result:=2;
  2583. end;
  2584. {****************************************************************************
  2585. TDebugInfoDwarf3
  2586. ****************************************************************************}
  2587. procedure TDebugInfoDwarf3.appenddef_file(def: tfiledef);
  2588. begin
  2589. if assigned(def.typesym) then
  2590. append_entry(DW_TAG_file_type,false,[
  2591. DW_AT_name,DW_FORM_string,symname(def.typesym)+#0,
  2592. DW_AT_byte_size,DW_FORM_data2,def.size
  2593. ])
  2594. else
  2595. append_entry(DW_TAG_file_type,false,[
  2596. DW_AT_byte_size,DW_FORM_data2,def.size
  2597. ]);
  2598. if tfiledef(def).filetyp=ft_typed then
  2599. append_labelentry_ref(DW_AT_type,def_dwarf_lab(tfiledef(def).typedfiledef));
  2600. finish_entry;
  2601. end;
  2602. procedure TDebugInfoDwarf3.appenddef_formal(def: tformaldef);
  2603. begin
  2604. append_entry(DW_TAG_unspecified_type,false,[
  2605. ]);
  2606. finish_entry;
  2607. end;
  2608. procedure TDebugInfoDwarf3.appenddef_object(def: tobjectdef);
  2609. procedure dostruct(tag: tdwarf_tag);
  2610. begin
  2611. if assigned(def.objname) then
  2612. append_entry(tag,true,[
  2613. DW_AT_name,DW_FORM_string,def.objrealname^+#0,
  2614. DW_AT_byte_size,DW_FORM_udata,def.size
  2615. ])
  2616. else
  2617. append_entry(DW_TAG_structure_type,true,[
  2618. DW_AT_byte_size,DW_FORM_udata,def.size
  2619. ]);
  2620. finish_entry;
  2621. end;
  2622. procedure doimplicitpointer;
  2623. var
  2624. obj : tasmlabel;
  2625. begin
  2626. if not(tf_dwarf_only_local_labels in target_info.flags) then
  2627. current_asmdata.getdatalabel(obj)
  2628. else
  2629. current_asmdata.getaddrlabel(obj);
  2630. { implicit pointer }
  2631. append_entry(DW_TAG_pointer_type,false,[]);
  2632. append_labelentry_ref(DW_AT_type,obj);
  2633. finish_entry;
  2634. current_asmdata.asmlists[al_dwarf_info].concat(tai_symbol.create(obj,0));
  2635. end;
  2636. procedure doparent(isinterface: boolean);
  2637. begin
  2638. if not assigned(def.childof) then
  2639. exit;
  2640. if isinterface then
  2641. begin
  2642. append_entry(DW_TAG_inheritance,false,[]);
  2643. end
  2644. else
  2645. begin
  2646. append_entry(DW_TAG_inheritance,false,[
  2647. DW_AT_accessibility,DW_FORM_data1,DW_ACCESS_public,
  2648. DW_AT_data_member_location,DW_FORM_block1,1+lengthuleb128(0)
  2649. ]);
  2650. current_asmdata.asmlists[al_dwarf_info].concat(tai_const.create_8bit(ord(DW_OP_plus_uconst)));
  2651. current_asmdata.asmlists[al_dwarf_info].concat(tai_const.create_uleb128bit(0));
  2652. end;
  2653. append_labelentry_ref(DW_AT_type,def_dwarf_lab(def.childof));
  2654. finish_entry;
  2655. end;
  2656. var
  2657. n: integer;
  2658. begin
  2659. case def.objecttype of
  2660. odt_cppclass,
  2661. odt_object:
  2662. begin
  2663. dostruct(DW_TAG_structure_type);
  2664. doparent(false);
  2665. end;
  2666. odt_interfacecom,
  2667. odt_interfacecorba,
  2668. odt_dispinterface:
  2669. begin
  2670. dostruct(DW_TAG_interface_type);
  2671. doparent(true);
  2672. end;
  2673. odt_class:
  2674. begin
  2675. { not sure if the implicit pointer is needed for tag_class (MWE)}
  2676. {
  2677. doimplicitpointer;
  2678. }
  2679. dostruct(DW_TAG_class_type);
  2680. doparent(false);
  2681. end;
  2682. else
  2683. internalerror(200609171);
  2684. end;
  2685. { add implemented interfaces }
  2686. if assigned(def.ImplementedInterfaces) then
  2687. for n := 0 to def.ImplementedInterfaces.count-1 do
  2688. begin
  2689. append_entry(DW_TAG_inheritance,false,[]);
  2690. append_labelentry_ref(DW_AT_type,def_dwarf_lab(TImplementedInterface(def.ImplementedInterfaces[n]).IntfDef));
  2691. finish_entry;
  2692. end;
  2693. { add members }
  2694. def.symtable.symList.ForEachCall(@enum_membersyms_callback,nil);
  2695. finish_children;
  2696. end;
  2697. procedure TDebugInfoDwarf3.appenddef_set(def: tsetdef);
  2698. begin
  2699. if assigned(def.typesym) then
  2700. append_entry(DW_TAG_set_type,false,[
  2701. DW_AT_name,DW_FORM_string,symname(def.typesym)+#0,
  2702. DW_AT_byte_size,DW_FORM_data2,def.size
  2703. ])
  2704. else
  2705. append_entry(DW_TAG_set_type,false,[
  2706. DW_AT_byte_size,DW_FORM_data2,def.size
  2707. ]);
  2708. if assigned(tsetdef(def).elementdef) then
  2709. append_labelentry_ref(DW_AT_type,def_dwarf_lab(tsetdef(def).elementdef));
  2710. finish_entry;
  2711. end;
  2712. procedure TDebugInfoDwarf3.appenddef_unineddef(def: tundefineddef);
  2713. begin
  2714. { ??? can a undefined def have a typename ? }
  2715. if assigned(def.typesym) then
  2716. append_entry(DW_TAG_unspecified_type,false,[
  2717. DW_AT_name,DW_FORM_string,symname(def.typesym)+#0
  2718. ])
  2719. else
  2720. append_entry(DW_TAG_unspecified_type,false,[
  2721. ]);
  2722. finish_entry;
  2723. end;
  2724. procedure TDebugInfoDwarf3.appenddef_variant(def: tvariantdef);
  2725. const
  2726. VARIANTS: array[1..27] of record Value: Word; Name: String end = (
  2727. (value:0; name:''),
  2728. (value:1; name:''),
  2729. (value:2; name:'VSMALLINT'),
  2730. (value:3; name:'VINTEGER'),
  2731. (value:4; name:'VSINGLE'),
  2732. (value:5; name:'VDOUBLE'),
  2733. (value:6; name:'VCURRENCY'),
  2734. (value:7; name:'VDATE'),
  2735. (value:8; name:'VOLESTR'),
  2736. (value:9; name:'VDISPATCH'),
  2737. (value:10; name:'VERROR'),
  2738. (value:11; name:'VBOOLEAN'),
  2739. (value:12; name:''),
  2740. (value:13; name:'VUNKNOWN'),
  2741. (value:14; name:''),
  2742. (value:16; name:'VSHORTINT'),
  2743. (value:17; name:'VBYTE'),
  2744. (value:18; name:'VWORD'),
  2745. (value:19; name:'VLONGWORD'),
  2746. (value:20; name:'VINT64'),
  2747. (value:21; name:'VQWORD'),
  2748. (value:36; name:'VRECORD'),
  2749. (value:$48; name:''),
  2750. (value:$100; name:'VSTRING'),
  2751. (value:$101; name:'VANY'),
  2752. (value:$2000; name:'VARRAY'),
  2753. (value:$4000; name:'VPOINTER')
  2754. );
  2755. var
  2756. fs: tfieldvarsym;
  2757. lbl: tasmlabel;
  2758. idx: integer;
  2759. begin
  2760. { it could be done with DW_TAG_variant for the union part (if that info was available)
  2761. now we do it manually for variants (MWE) }
  2762. { struct }
  2763. append_entry(DW_TAG_structure_type,true,[
  2764. DW_AT_name,DW_FORM_string,'Variant'#0,
  2765. DW_AT_byte_size,DW_FORM_udata,vardatadef.size
  2766. ]);
  2767. finish_entry;
  2768. append_entry(DW_TAG_variant_part,true,[
  2769. ]);
  2770. current_asmdata.getaddrlabel(lbl);
  2771. append_labelentry_ref(DW_AT_discr,lbl);
  2772. finish_entry;
  2773. { discriminant }
  2774. fs := tfieldvarsym(vardatadef.symtable.Find('VTYPE'));
  2775. if (fs = nil) or (fs.typ <> fieldvarsym) then
  2776. internalerror(200609271);
  2777. current_asmdata.asmlists[al_dwarf_info].concat(tai_symbol.create(lbl,0));
  2778. appendsym_fieldvar(fs);
  2779. { variants }
  2780. for idx := Low(VARIANTS) to High(VARIANTS) do
  2781. begin
  2782. append_entry(DW_TAG_variant,true,[
  2783. DW_AT_discr_value,DW_FORM_udata,VARIANTS[idx].value
  2784. ]);
  2785. finish_entry;
  2786. if VARIANTS[idx].name <> '' then
  2787. begin
  2788. fs := tfieldvarsym(vardatadef.symtable.Find(VARIANTS[idx].name));
  2789. if (fs = nil) or (fs.typ <> fieldvarsym) then
  2790. internalerror(20060927200+idx);
  2791. appendsym_fieldvar(fs);
  2792. end;
  2793. finish_children; { variant }
  2794. end;
  2795. finish_children; { variant part }
  2796. finish_children; { struct }
  2797. end;
  2798. function TDebugInfoDwarf3.dwarf_version: Word;
  2799. begin
  2800. Result:=3;
  2801. end;
  2802. function TDebugInfoDwarf3.symname(sym: tsym): String;
  2803. begin
  2804. Result:=sym.realname;
  2805. end;
  2806. {****************************************************************************
  2807. ****************************************************************************}
  2808. const
  2809. dbg_dwarf2_info : tdbginfo =
  2810. (
  2811. id : dbg_dwarf2;
  2812. idtxt : 'DWARF2';
  2813. );
  2814. dbg_dwarf3_info : tdbginfo =
  2815. (
  2816. id : dbg_dwarf3;
  2817. idtxt : 'DWARF3';
  2818. );
  2819. initialization
  2820. RegisterDebugInfo(dbg_dwarf2_info,TDebugInfoDwarf2);
  2821. RegisterDebugInfo(dbg_dwarf3_info,TDebugInfoDwarf3);
  2822. end.