dbgdwarf.pas 110 KB

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