dbgdwarf.pas 104 KB

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