dbgdwarf.pas 117 KB

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