dbgdwarf.pas 104 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796
  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. current_asmdata.asmlists[al_dwarf_abbrev].concat(tai_const.create_uleb128bit(DW_AT_data_location));
  1022. current_asmdata.asmlists[al_dwarf_abbrev].concat(tai_const.create_uleb128bit(DW_FORM_block1));
  1023. current_asmdata.asmlists[al_dwarf_info].concat(tai_const.create_8bit(1));
  1024. current_asmdata.asmlists[al_dwarf_info].concat(tai_const.create_8bit(DW_OP_push_object));
  1025. current_asmdata.asmlists[al_dwarf_info].concat(tai_const.create_8bit(DW_OP_deref));
  1026. }
  1027. finish_entry;
  1028. { to simplify things, we don't write a multidimensional array here }
  1029. append_entry(DW_TAG_subrange_type,false,[
  1030. DW_AT_lower_bound,DW_FORM_udata,0,
  1031. DW_AT_upper_bound,DW_FORM_udata,0
  1032. ]);
  1033. append_labelentry_ref(DW_AT_type,def_dwarf_lab(def.rangedef));
  1034. finish_entry;
  1035. end
  1036. else
  1037. begin
  1038. finish_entry;
  1039. { to simplify things, we don't write a multidimensional array here }
  1040. append_entry(DW_TAG_subrange_type,false,[
  1041. DW_AT_lower_bound,DW_FORM_sdata,def.lowrange,
  1042. DW_AT_upper_bound,DW_FORM_sdata,def.highrange
  1043. ]);
  1044. append_labelentry_ref(DW_AT_type,def_dwarf_lab(def.rangedef));
  1045. finish_entry;
  1046. end;
  1047. finish_children;
  1048. end;
  1049. procedure TDebugInfoDwarf.appenddef_record(def:trecorddef);
  1050. begin
  1051. if assigned(def.typesym) then
  1052. append_entry(DW_TAG_structure_type,true,[
  1053. DW_AT_name,DW_FORM_string,symname(def.typesym)+#0,
  1054. DW_AT_byte_size,DW_FORM_udata,def.size
  1055. ])
  1056. else
  1057. append_entry(DW_TAG_structure_type,true,[
  1058. DW_AT_byte_size,DW_FORM_udata,def.size
  1059. ]);
  1060. finish_entry;
  1061. def.symtable.symList.ForEachCall(@enum_membersyms_callback,nil);
  1062. finish_children;
  1063. end;
  1064. procedure TDebugInfoDwarf.appenddef_pointer(def:tpointerdef);
  1065. begin
  1066. append_entry(DW_TAG_pointer_type,false,[]);
  1067. if not(is_voidpointer(def)) then
  1068. append_labelentry_ref(DW_AT_type,def_dwarf_lab(def.pointeddef));
  1069. finish_entry;
  1070. end;
  1071. procedure TDebugInfoDwarf.appenddef_string(def:tstringdef);
  1072. var
  1073. slen : aint;
  1074. arr : tasmlabel;
  1075. begin
  1076. case def.stringtype of
  1077. st_shortstring:
  1078. begin
  1079. { fix length of openshortstring }
  1080. slen:=def.len;
  1081. if slen=0 then
  1082. slen:=255;
  1083. { create a structure with two elements }
  1084. current_asmdata.getdatalabel(arr);
  1085. append_entry(DW_TAG_structure_type,true,[
  1086. DW_AT_name,DW_FORM_string,'ShortString'#0,
  1087. DW_AT_byte_size,DW_FORM_data1,2*sizeof(aint)
  1088. ]);
  1089. finish_entry;
  1090. { length entry }
  1091. append_entry(DW_TAG_member,false,[
  1092. DW_AT_name,DW_FORM_string,'Length'#0,
  1093. DW_AT_data_member_location,DW_FORM_block1,1+lengthuleb128(0)
  1094. ]);
  1095. current_asmdata.asmlists[al_dwarf_info].concat(tai_const.create_8bit(ord(DW_OP_plus_uconst)));
  1096. current_asmdata.asmlists[al_dwarf_info].concat(tai_const.create_uleb128bit(0));
  1097. append_labelentry_ref(DW_AT_type,def_dwarf_lab(u8inttype));
  1098. finish_entry;
  1099. { string data entry }
  1100. append_entry(DW_TAG_member,false,[
  1101. DW_AT_name,DW_FORM_string,'Data'#0,
  1102. DW_AT_data_member_location,DW_FORM_block1,1+lengthuleb128(1)
  1103. ]);
  1104. current_asmdata.asmlists[al_dwarf_info].concat(tai_const.create_8bit(ord(DW_OP_plus_uconst)));
  1105. current_asmdata.asmlists[al_dwarf_info].concat(tai_const.create_uleb128bit(1));
  1106. append_labelentry_ref(DW_AT_type,arr);
  1107. finish_entry;
  1108. finish_children;
  1109. { now the data array }
  1110. current_asmdata.asmlists[al_dwarf_info].concat(tai_symbol.create(arr,0));
  1111. append_entry(DW_TAG_array_type,true,[
  1112. DW_AT_byte_size,DW_FORM_udata,def.size,
  1113. DW_AT_stride_size,DW_FORM_udata,1*8
  1114. ]);
  1115. append_labelentry_ref(DW_AT_type,def_dwarf_lab(cchartype));
  1116. finish_entry;
  1117. append_entry(DW_TAG_subrange_type,false,[
  1118. DW_AT_lower_bound,DW_FORM_udata,0,
  1119. DW_AT_upper_bound,DW_FORM_udata,slen
  1120. ]);
  1121. append_labelentry_ref(DW_AT_type,def_dwarf_lab(u8inttype));
  1122. finish_entry;
  1123. finish_children;
  1124. end;
  1125. st_longstring:
  1126. begin
  1127. {
  1128. charst:=def_stab_number(cchartype);
  1129. bytest:=def_stab_number(u8inttype);
  1130. longst:=def_stab_number(u32inttype);
  1131. result:=def_stabstr_evaluate(def,'s$1length:$2,0,32;dummy:$6,32,8;st:ar$2;1;$3;$4,40,$5;;',
  1132. [tostr(def.len+5),longst,tostr(def.len),charst,tostr(def.len*8),bytest]);
  1133. }
  1134. end;
  1135. st_ansistring:
  1136. begin
  1137. { looks like a pchar }
  1138. append_entry(DW_TAG_pointer_type,false,[]);
  1139. append_labelentry_ref(DW_AT_type,def_dwarf_lab(cchartype));
  1140. finish_entry;
  1141. end;
  1142. st_widestring:
  1143. begin
  1144. { looks like a pwidechar }
  1145. append_entry(DW_TAG_pointer_type,false,[]);
  1146. append_labelentry_ref(DW_AT_type,def_dwarf_lab(cwidechartype));
  1147. finish_entry;
  1148. end;
  1149. end;
  1150. end;
  1151. procedure TDebugInfoDwarf.appenddef_procvar(def:tprocvardef);
  1152. procedure doappend;
  1153. var
  1154. i : longint;
  1155. begin
  1156. if assigned(def.typesym) then
  1157. append_entry(DW_TAG_subroutine_type,true,[
  1158. DW_AT_name,DW_FORM_string,symname(def.typesym)+#0,
  1159. DW_AT_prototyped,DW_FORM_flag,true
  1160. ])
  1161. else
  1162. append_entry(DW_TAG_subroutine_type,true,[
  1163. DW_AT_prototyped,DW_FORM_flag,true
  1164. ]);
  1165. if not(is_void(tprocvardef(def).returndef)) then
  1166. append_labelentry_ref(DW_AT_type,def_dwarf_lab(tprocvardef(def).returndef));
  1167. finish_entry;
  1168. { write parameters }
  1169. for i:=0 to def.paras.count-1 do
  1170. begin
  1171. append_entry(DW_TAG_formal_parameter,false,[
  1172. DW_AT_name,DW_FORM_string,symname(tsym(def.paras[i]))+#0
  1173. ]);
  1174. append_labelentry_ref(DW_AT_type,def_dwarf_lab(tparavarsym(def.paras[i]).vardef));
  1175. finish_entry;
  1176. end;
  1177. finish_children;
  1178. end;
  1179. var
  1180. proc : tasmlabel;
  1181. begin
  1182. if def.is_methodpointer then
  1183. begin
  1184. { create a structure with two elements }
  1185. current_asmdata.getdatalabel(proc);
  1186. append_entry(DW_TAG_structure_type,true,[
  1187. DW_AT_byte_size,DW_FORM_data1,2*sizeof(aint)
  1188. ]);
  1189. finish_entry;
  1190. { proc entry }
  1191. append_entry(DW_TAG_member,false,[
  1192. DW_AT_name,DW_FORM_string,'Proc'#0,
  1193. DW_AT_data_member_location,DW_FORM_block1,1+lengthuleb128(0)
  1194. ]);
  1195. current_asmdata.asmlists[al_dwarf_info].concat(tai_const.create_8bit(ord(DW_OP_plus_uconst)));
  1196. current_asmdata.asmlists[al_dwarf_info].concat(tai_const.create_uleb128bit(0));
  1197. append_labelentry_ref(DW_AT_type,proc);
  1198. finish_entry;
  1199. { self entry }
  1200. append_entry(DW_TAG_member,false,[
  1201. DW_AT_name,DW_FORM_string,'Self'#0,
  1202. DW_AT_data_member_location,DW_FORM_block1,1+lengthuleb128(sizeof(aint))
  1203. ]);
  1204. current_asmdata.asmlists[al_dwarf_info].concat(tai_const.create_8bit(ord(DW_OP_plus_uconst)));
  1205. current_asmdata.asmlists[al_dwarf_info].concat(tai_const.create_uleb128bit(sizeof(aint)));
  1206. append_labelentry_ref(DW_AT_type,def_dwarf_lab(class_tobject));
  1207. finish_entry;
  1208. finish_children;
  1209. current_asmdata.asmlists[al_dwarf_info].concat(tai_symbol.create(proc,0));
  1210. doappend;
  1211. end
  1212. else
  1213. doappend;
  1214. end;
  1215. procedure TDebugInfoDwarf.appenddef(def:tdef);
  1216. var
  1217. labsym : tasmsymbol;
  1218. begin
  1219. if (def.dbg_state in [dbg_state_writing,dbg_state_written]) then
  1220. exit;
  1221. { never write generic template defs }
  1222. if df_generic in def.defoptions then
  1223. begin
  1224. def.dbg_state:=dbg_state_written;
  1225. exit;
  1226. end;
  1227. { to avoid infinite loops }
  1228. def.dbg_state := dbg_state_writing;
  1229. current_asmdata.asmlists[al_dwarf_info].concat(tai_comment.Create(strpnew('Definition '+def.typename)));
  1230. labsym:=def_dwarf_lab(def);
  1231. if ds_dwarf_dbg_info_written in def.defstates then
  1232. current_asmdata.asmlists[al_dwarf_info].concat(tai_symbol.create_global(labsym,0))
  1233. else
  1234. current_asmdata.asmlists[al_dwarf_info].concat(tai_symbol.create(labsym,0));
  1235. case def.typ of
  1236. stringdef :
  1237. appenddef_string(tstringdef(def));
  1238. enumdef :
  1239. appenddef_enum(tenumdef(def));
  1240. orddef :
  1241. appenddef_ord(torddef(def));
  1242. pointerdef :
  1243. appenddef_pointer(tpointerdef(def));
  1244. floatdef :
  1245. appenddef_float(tfloatdef(def));
  1246. filedef :
  1247. appenddef_file(tfiledef(def));
  1248. recorddef :
  1249. appenddef_record(trecorddef(def));
  1250. variantdef :
  1251. appenddef_variant(tvariantdef(def));
  1252. classrefdef :
  1253. appenddef_pointer(tpointerdef(pvmttype));
  1254. setdef :
  1255. appenddef_set(tsetdef(def));
  1256. formaldef :
  1257. appenddef_formal(tformaldef(def));
  1258. arraydef :
  1259. appenddef_array(tarraydef(def));
  1260. procvardef :
  1261. appenddef_procvar(tprocvardef(def));
  1262. objectdef :
  1263. appenddef_object(tobjectdef(def));
  1264. undefineddef :
  1265. appenddef_unineddef(tundefineddef(def));
  1266. else
  1267. internalerror(200601281);
  1268. end;
  1269. def.dbg_state := dbg_state_written;
  1270. end;
  1271. procedure TDebugInfoDwarf.insertdef(unused:TAsmList; def:tdef);
  1272. begin
  1273. appenddef(def);
  1274. end;
  1275. procedure TDebugInfoDwarf.write_symtable_defs(unused:TAsmList;st:TSymtable);
  1276. procedure dowritedwarf(st:TSymtable);
  1277. var
  1278. def : tdef;
  1279. i : longint;
  1280. begin
  1281. for i:=0 to st.DefList.Count-1 do
  1282. begin
  1283. def:=tdef(st.DefList[i]);
  1284. if not(df_deleted in def.defoptions) and
  1285. (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. p : pchar;
  1314. hs : string;
  1315. begin
  1316. if assigned(pd.procstarttai) then
  1317. begin
  1318. current_asmdata.asmlists[al_dwarf_info].concat(tai_comment.Create(strpnew('Procdef '+pd.fullprocname(true))));
  1319. append_entry(DW_TAG_subprogram,true,
  1320. [DW_AT_name,DW_FORM_string,symname(pd.procsym)+#0
  1321. { data continues below }
  1322. { problem: base reg isn't known here
  1323. DW_AT_frame_base,DW_FORM_block1,1
  1324. }
  1325. ]);
  1326. { append block data }
  1327. { current_asmdata.asmlists[al_dwarf_info].concat(tai_const.create_8bit(dwarf_reg(pd.))); }
  1328. if not(is_void(tprocdef(pd).returndef)) then
  1329. append_labelentry_ref(DW_AT_type,def_dwarf_lab(tprocdef(pd).returndef));
  1330. { mark end of procedure }
  1331. current_asmdata.getlabel(procendlabel,alt_dbgtype);
  1332. current_asmdata.asmlists[al_procedures].insertbefore(tai_label.create(procendlabel),pd.procendtai);
  1333. append_labelentry(DW_AT_low_pc,current_asmdata.RefAsmSymbol(pd.mangledname));
  1334. append_labelentry(DW_AT_high_pc,procendlabel);
  1335. {
  1336. if assigned(pd.funcretsym) and
  1337. (tabstractnormalvarsym(pd.funcretsym).refs>0) then
  1338. begin
  1339. if tabstractnormalvarsym(pd.funcretsym).localloc.loc=LOC_REFERENCE then
  1340. begin
  1341. {$warning Need to add gdb support for ret in param register calling}
  1342. if paramanager.ret_in_param(pd.returndef,pd.proccalloption) then
  1343. hs:='X*'
  1344. else
  1345. hs:='X';
  1346. templist.concat(Tai_stab.create(stab_stabs,strpnew(
  1347. '"'+pd.procsym.name+':'+hs+def_stab_number(pd.returndef)+'",'+
  1348. tostr(N_tsym)+',0,0,'+tostr(tabstractnormalvarsym(pd.funcretsym).localloc.reference.offset))));
  1349. if (m_result in current_settings.modeswitches) then
  1350. templist.concat(Tai_stab.create(stab_stabs,strpnew(
  1351. '"RESULT:'+hs+def_stab_number(pd.returndef)+'",'+
  1352. tostr(N_tsym)+',0,0,'+tostr(tabstractnormalvarsym(pd.funcretsym).localloc.reference.offset))));
  1353. end;
  1354. end;
  1355. }
  1356. finish_entry;
  1357. {
  1358. { para types }
  1359. write_def_stabstr(templist,pd);
  1360. }
  1361. if assigned(pd.parast) then
  1362. write_symtable_syms(pd.parast);
  1363. { local type defs and vars should not be written
  1364. inside the main proc stab }
  1365. if assigned(pd.localst) and
  1366. (pd.localst.symtabletype=localsymtable) then
  1367. write_symtable_syms(pd.localst);
  1368. { last write the types from this procdef }
  1369. if assigned(pd.parast) then
  1370. write_symtable_defs(nil,pd.parast);
  1371. if assigned(pd.localst) and
  1372. (pd.localst.symtabletype=localsymtable) then
  1373. write_symtable_defs(nil,pd.localst);
  1374. finish_children;
  1375. end;
  1376. end;
  1377. procedure TDebugInfoDwarf.appendsym_var(sym:tabstractnormalvarsym);
  1378. var
  1379. templist : TAsmList;
  1380. blocksize : longint;
  1381. tag : tdwarf_tag;
  1382. dreg : byte;
  1383. begin
  1384. { external symbols can't be resolved at link time, so we
  1385. can't generate stabs for them
  1386. not sure if this applies to dwarf as well (FK)
  1387. }
  1388. if vo_is_external in sym.varoptions then
  1389. exit;
  1390. { There is no space allocated for not referenced locals }
  1391. if (sym.owner.symtabletype=localsymtable) and (sym.refs=0) then
  1392. exit;
  1393. templist:=TAsmList.create;
  1394. case sym.localloc.loc of
  1395. LOC_REGISTER,
  1396. LOC_CREGISTER,
  1397. LOC_MMREGISTER,
  1398. LOC_CMMREGISTER,
  1399. LOC_FPUREGISTER,
  1400. LOC_CFPUREGISTER :
  1401. begin
  1402. templist.concat(tai_const.create_8bit(ord(DW_OP_regx)));
  1403. dreg:=dwarf_reg(sym.localloc.register);
  1404. templist.concat(tai_const.create_uleb128bit(dreg));
  1405. blocksize:=1+Lengthuleb128(dreg);
  1406. end;
  1407. else
  1408. begin
  1409. case sym.typ of
  1410. staticvarsym:
  1411. begin
  1412. if (vo_is_thread_var in sym.varoptions) then
  1413. begin
  1414. {$warning !!! FIXME: dwarf for thread vars !!!}
  1415. blocksize:=0;
  1416. end
  1417. else
  1418. begin
  1419. templist.concat(tai_const.create_8bit(3));
  1420. templist.concat(tai_const.createname(sym.mangledname,0));
  1421. blocksize:=1+sizeof(aword);
  1422. end;
  1423. end;
  1424. paravarsym,
  1425. localvarsym:
  1426. begin
  1427. dreg:=dwarf_reg(sym.localloc.reference.base);
  1428. templist.concat(tai_const.create_8bit(ord(DW_OP_breg0)+dreg));
  1429. templist.concat(tai_const.create_sleb128bit(sym.localloc.reference.offset));
  1430. blocksize:=1+Lengthsleb128(sym.localloc.reference.offset);
  1431. end
  1432. else
  1433. internalerror(200601288);
  1434. end;
  1435. end;
  1436. end;
  1437. if sym.typ=paravarsym then
  1438. tag:=DW_TAG_formal_parameter
  1439. else
  1440. tag:=DW_TAG_variable;
  1441. append_entry(tag,false,[
  1442. DW_AT_name,DW_FORM_string,symname(sym)+#0,
  1443. {
  1444. DW_AT_decl_file,DW_FORM_data1,0,
  1445. DW_AT_decl_line,DW_FORM_data1,
  1446. }
  1447. DW_AT_external,DW_FORM_flag,true,
  1448. { data continues below }
  1449. DW_AT_location,DW_FORM_block1,blocksize
  1450. ]);
  1451. { append block data }
  1452. current_asmdata.asmlists[al_dwarf_info].concatlist(templist);
  1453. append_labelentry_ref(DW_AT_type,def_dwarf_lab(sym.vardef));
  1454. templist.free;
  1455. finish_entry;
  1456. end;
  1457. procedure TDebugInfoDwarf.appendsym_fieldvar(sym: tfieldvarsym);
  1458. begin
  1459. if sp_static in sym.symoptions then Exit;
  1460. append_entry(DW_TAG_member,false,[
  1461. DW_AT_name,DW_FORM_string,symname(sym)+#0,
  1462. DW_AT_data_member_location,DW_FORM_block1,1+lengthuleb128(sym.fieldoffset)
  1463. ]);
  1464. current_asmdata.asmlists[al_dwarf_info].concat(tai_const.create_8bit(ord(DW_OP_plus_uconst)));
  1465. current_asmdata.asmlists[al_dwarf_info].concat(tai_const.create_uleb128bit(sym.fieldoffset));
  1466. append_labelentry_ref(DW_AT_type,def_dwarf_lab(sym.vardef));
  1467. finish_entry;
  1468. end;
  1469. procedure TDebugInfoDwarf.appendsym_const(sym:tconstsym);
  1470. begin
  1471. append_entry(DW_TAG_constant,false,[
  1472. DW_AT_name,DW_FORM_string,symname(sym)+#0
  1473. ]);
  1474. { for string constants, constdef isn't set because they have no real type }
  1475. if not(sym.consttyp in [conststring,constresourcestring]) then
  1476. append_labelentry_ref(DW_AT_type,def_dwarf_lab(sym.constdef));
  1477. current_asmdata.asmlists[al_dwarf_abbrev].concat(tai_const.create_uleb128bit(ord(DW_AT_const_value)));
  1478. case sym.consttyp of
  1479. conststring:
  1480. begin
  1481. current_asmdata.asmlists[al_dwarf_abbrev].concat(tai_const.create_uleb128bit(ord(DW_FORM_string)));
  1482. current_asmdata.asmlists[al_dwarf_info].concat(tai_string.create(strpas(pchar(sym.value.valueptr))));
  1483. current_asmdata.asmlists[al_dwarf_info].concat(tai_const.create_8bit(0));
  1484. end;
  1485. constset,
  1486. constwstring,
  1487. constguid,
  1488. constresourcestring:
  1489. begin
  1490. { write dummy for now }
  1491. current_asmdata.asmlists[al_dwarf_abbrev].concat(tai_const.create_uleb128bit(ord(DW_FORM_string)));
  1492. current_asmdata.asmlists[al_dwarf_info].concat(tai_string.create(''));
  1493. current_asmdata.asmlists[al_dwarf_info].concat(tai_const.create_8bit(0));
  1494. end;
  1495. constord:
  1496. begin
  1497. current_asmdata.asmlists[al_dwarf_abbrev].concat(tai_const.create_uleb128bit(ord(DW_FORM_sdata)));
  1498. current_asmdata.asmlists[al_dwarf_info].concat(tai_const.create_sleb128bit(sym.value.valueord));
  1499. end;
  1500. constnil:
  1501. begin
  1502. {$ifdef cpu64bit}
  1503. current_asmdata.asmlists[al_dwarf_abbrev].concat(tai_const.create_uleb128bit(ord(DW_FORM_data8)));
  1504. current_asmdata.asmlists[al_dwarf_info].concat(tai_const.create_64bit(0));
  1505. {$else cpu64bit}
  1506. current_asmdata.asmlists[al_dwarf_abbrev].concat(tai_const.create_uleb128bit(ord(DW_FORM_data4)));
  1507. current_asmdata.asmlists[al_dwarf_info].concat(tai_const.create_32bit(0));
  1508. {$endif cpu64bit}
  1509. end;
  1510. constpointer:
  1511. begin
  1512. {$ifdef cpu64bit}
  1513. current_asmdata.asmlists[al_dwarf_abbrev].concat(tai_const.create_uleb128bit(ord(DW_FORM_data8)));
  1514. current_asmdata.asmlists[al_dwarf_info].concat(tai_const.create_64bit(sym.value.valueordptr));
  1515. {$else cpu64bit}
  1516. current_asmdata.asmlists[al_dwarf_abbrev].concat(tai_const.create_uleb128bit(ord(DW_FORM_data4)));
  1517. current_asmdata.asmlists[al_dwarf_info].concat(tai_const.create_32bit(sym.value.valueordptr));
  1518. {$endif cpu64bit}
  1519. end;
  1520. constreal:
  1521. begin
  1522. current_asmdata.asmlists[al_dwarf_abbrev].concat(tai_const.create_uleb128bit(ord(DW_FORM_block1)));
  1523. case tfloatdef(sym.constdef).floattype of
  1524. s32real:
  1525. begin
  1526. current_asmdata.asmlists[al_dwarf_info].concat(tai_const.create_8bit(4));
  1527. current_asmdata.asmlists[al_dwarf_info].concat(tai_real_32bit.create(psingle(sym.value.valueptr)^));
  1528. end;
  1529. s64comp,
  1530. s64currency,
  1531. s64real:
  1532. begin
  1533. current_asmdata.asmlists[al_dwarf_info].concat(tai_const.create_8bit(8));
  1534. current_asmdata.asmlists[al_dwarf_info].concat(tai_real_64bit.create(pdouble(sym.value.valueptr)^));
  1535. end;
  1536. s80real:
  1537. begin
  1538. current_asmdata.asmlists[al_dwarf_info].concat(tai_const.create_8bit(10));
  1539. current_asmdata.asmlists[al_dwarf_info].concat(tai_real_80bit.create(pextended(sym.value.valueptr)^));
  1540. end;
  1541. else
  1542. internalerror(200601291);
  1543. end;
  1544. end;
  1545. else
  1546. internalerror(200601292);
  1547. end;
  1548. finish_entry;
  1549. end;
  1550. procedure TDebugInfoDwarf.appendsym_label(sym: tlabelsym);
  1551. begin
  1552. { ignore label syms for now, the problem is that a label sym
  1553. can have more than one label associated e.g. in case of
  1554. an inline procedure expansion }
  1555. end;
  1556. procedure TDebugInfoDwarf.appendsym_proc(sym:tprocsym);
  1557. var
  1558. i : longint;
  1559. begin
  1560. for i:=0 to sym.ProcdefList.Count-1 do
  1561. appendprocdef(tprocdef(sym.ProcdefList[i]));
  1562. end;
  1563. procedure TDebugInfoDwarf.appendsym_property(sym: tpropertysym);
  1564. begin
  1565. { ignored for now }
  1566. end;
  1567. procedure TDebugInfoDwarf.appendsym_type(sym: ttypesym);
  1568. begin
  1569. append_entry(DW_TAG_typedef,false,[
  1570. DW_AT_name,DW_FORM_string,symname(sym)+#0
  1571. ]);
  1572. append_labelentry_ref(DW_AT_type,def_dwarf_lab(sym.typedef));
  1573. finish_entry;
  1574. { Moved fom append sym, do we need this (MWE)
  1575. { For object types write also the symtable entries }
  1576. if (sym.typ=typesym) and (ttypesym(sym).typedef.typ=objectdef) then
  1577. write_symtable_syms(list,tobjectdef(ttypesym(sym).typedef).symtable);
  1578. }
  1579. end;
  1580. procedure TDebugInfoDwarf.appendsym_unit(sym: tunitsym);
  1581. begin
  1582. { for now, we ignore unit symbols }
  1583. end;
  1584. procedure TDebugInfoDwarf.appendsym_absolute(sym:tabsolutevarsym);
  1585. var
  1586. templist : TAsmList;
  1587. blocksize : longint;
  1588. symlist : ppropaccesslistitem;
  1589. begin
  1590. templist:=TAsmList.create;
  1591. case tabsolutevarsym(sym).abstyp of
  1592. toaddr :
  1593. begin
  1594. { MWE: replaced ifdef i368 }
  1595. {
  1596. if target_cpu = cpu_i386 then
  1597. begin
  1598. { in theory, we could write a DW_AT_segment entry here for sym.absseg,
  1599. however I doubt that gdb supports this (FK) }
  1600. end;
  1601. }
  1602. templist.concat(tai_const.create_8bit(3));
  1603. templist.concat(tai_const.create_aint(sym.addroffset));
  1604. blocksize:=1+sizeof(aword);
  1605. end;
  1606. toasm :
  1607. begin
  1608. templist.concat(tai_const.create_8bit(3));
  1609. templist.concat(tai_const.createname(sym.mangledname,0));
  1610. blocksize:=1+sizeof(aword);
  1611. end;
  1612. tovar:
  1613. begin
  1614. symlist:=tabsolutevarsym(sym).ref.firstsym;
  1615. { can we insert the symbol? }
  1616. if assigned(symlist) and
  1617. (symlist^.sltype=sl_load) then
  1618. appendsym(symlist^.sym);
  1619. templist.free;
  1620. exit;
  1621. end;
  1622. end;
  1623. append_entry(DW_TAG_variable,false,[
  1624. DW_AT_name,DW_FORM_string,symname(sym)+#0,
  1625. {
  1626. DW_AT_decl_file,DW_FORM_data1,0,
  1627. DW_AT_decl_line,DW_FORM_data1,
  1628. }
  1629. DW_AT_external,DW_FORM_flag,true,
  1630. { data continues below }
  1631. DW_AT_location,DW_FORM_block1,blocksize
  1632. ]);
  1633. { append block data }
  1634. current_asmdata.asmlists[al_dwarf_info].concatlist(templist);
  1635. append_labelentry_ref(DW_AT_type,def_dwarf_lab(sym.vardef));
  1636. templist.free;
  1637. finish_entry;
  1638. end;
  1639. procedure TDebugInfoDwarf.appendsym(sym:tsym);
  1640. begin
  1641. if sym.isdbgwritten then
  1642. exit;
  1643. current_asmdata.asmlists[al_dwarf_info].concat(tai_comment.Create(strpnew('Symbol '+symname(sym))));
  1644. case sym.typ of
  1645. staticvarsym :
  1646. appendsym_var(tstaticvarsym(sym));
  1647. unitsym:
  1648. appendsym_unit(tunitsym(sym));
  1649. procsym :
  1650. appendsym_proc(tprocsym(sym));
  1651. labelsym :
  1652. appendsym_label(tlabelsym(sym));
  1653. localvarsym :
  1654. appendsym_var(tlocalvarsym(sym));
  1655. paravarsym :
  1656. appendsym_var(tparavarsym(sym));
  1657. constsym :
  1658. appendsym_const(tconstsym(sym));
  1659. typesym :
  1660. appendsym_type(ttypesym(sym));
  1661. enumsym :
  1662. { ignore enum syms, they are written by the owner }
  1663. ;
  1664. syssym :
  1665. { ignore sys syms, they are only of internal use }
  1666. ;
  1667. absolutevarsym :
  1668. appendsym_absolute(tabsolutevarsym(sym));
  1669. propertysym :
  1670. appendsym_property(tpropertysym(sym));
  1671. else
  1672. begin
  1673. writeln(ord(sym.typ));
  1674. internalerror(200601242);
  1675. end;
  1676. end;
  1677. sym.isdbgwritten:=true;
  1678. end;
  1679. procedure TDebugInfoDwarf.write_symtable_syms(st:TSymtable);
  1680. var
  1681. i : longint;
  1682. sym : tsym;
  1683. old_writing_def_dwarf : boolean;
  1684. begin
  1685. old_writing_def_dwarf:=writing_def_dwarf;
  1686. writing_def_dwarf:=false;
  1687. for i:=0 to st.SymList.Count-1 do
  1688. begin
  1689. sym:=tsym(st.SymList[i]);
  1690. if not(sp_hidden in sym.symoptions) and
  1691. (not sym.isdbgwritten) then
  1692. appendsym(sym);
  1693. end;
  1694. writing_def_dwarf:=old_writing_def_dwarf;
  1695. end;
  1696. procedure TDebugInfoDwarf.insertmoduleinfo;
  1697. var
  1698. templist: TAsmList;
  1699. linelist: TAsmList;
  1700. lbl : tasmlabel;
  1701. n,m : Integer;
  1702. ditem : TDirIndexItem;
  1703. fitem : TFileIndexItem;
  1704. flist : TFPList;
  1705. begin
  1706. { insert .Ltext0 label }
  1707. templist:=TAsmList.create;
  1708. new_section(templist,sec_code,'',0);
  1709. templist.concat(tai_symbol.createname('.Ltext0',AT_DATA,0));
  1710. current_asmdata.asmlists[al_start].insertlist(templist);
  1711. templist.free;
  1712. { insert .Letext0 label }
  1713. templist:=TAsmList.create;
  1714. new_section(templist,sec_code,'',0);
  1715. templist.concat(tai_symbol.createname('.Letext0',AT_DATA,0));
  1716. current_asmdata.asmlists[al_end].insertlist(templist);
  1717. templist.free;
  1718. { insert .Ldebug_abbrev0 label }
  1719. templist:=TAsmList.create;
  1720. new_section(templist,sec_debug_abbrev,'',0);
  1721. templist.concat(tai_symbol.createname('.Ldebug_abbrev0',AT_DATA,0));
  1722. current_asmdata.asmlists[al_start].insertlist(templist);
  1723. templist.free;
  1724. { insert .Ldebug_line0 label }
  1725. templist:=TAsmList.create;
  1726. new_section(templist,sec_debug_line,'',0);
  1727. templist.concat(tai_symbol.createname('.Ldebug_line0',AT_DATA,0));
  1728. current_asmdata.asmlists[al_start].insertlist(templist);
  1729. templist.free;
  1730. { debug line header }
  1731. linelist := current_asmdata.asmlists[al_dwarf_line];
  1732. new_section(linelist,sec_debug_line,'',0);
  1733. linelist.concat(tai_comment.Create(strpnew('=== header start ===')));
  1734. { size }
  1735. current_asmdata.getlabel(lbl,alt_dbgfile);
  1736. if use_64bit_headers then
  1737. begin
  1738. linelist.concat(tai_const.create_32bit(longint($FFFFFFFF)));
  1739. linelist.concat(tai_const.create_rel_sym(aitconst_64bit,
  1740. lbl,current_asmdata.RefAsmSymbol('.Ledebug_line0')));
  1741. end
  1742. else
  1743. linelist.concat(tai_const.create_rel_sym(aitconst_32bit,
  1744. lbl,current_asmdata.RefAsmSymbol('.Ledebug_line0')));
  1745. linelist.concat(tai_label.create(lbl));
  1746. { version }
  1747. linelist.concat(tai_const.create_16bit(dwarf_version));
  1748. { header length }
  1749. current_asmdata.getlabel(lbl,alt_dbgfile);
  1750. if use_64bit_headers then
  1751. linelist.concat(tai_const.create_rel_sym(aitconst_64bit,
  1752. lbl,current_asmdata.RefAsmSymbol('.Lehdebug_line0')))
  1753. else
  1754. linelist.concat(tai_const.create_rel_sym(aitconst_32bit,
  1755. lbl,current_asmdata.RefAsmSymbol('.Lehdebug_line0')));
  1756. linelist.concat(tai_label.create(lbl));
  1757. { minimum_instruction_length }
  1758. linelist.concat(tai_const.create_8bit(1));
  1759. { default_is_stmt }
  1760. linelist.concat(tai_const.create_8bit(1));
  1761. { line_base }
  1762. linelist.concat(tai_const.create_8bit(LINE_BASE));
  1763. { line_range }
  1764. { only line increase, no adress }
  1765. linelist.concat(tai_const.create_8bit(255));
  1766. { opcode_base }
  1767. linelist.concat(tai_const.create_8bit(OPCODE_BASE));
  1768. { standard_opcode_lengths }
  1769. { MWE: sigh... why adding the default lengths (and make those sizes sense with LEB encoding) }
  1770. { DW_LNS_copy }
  1771. linelist.concat(tai_const.create_8bit(0));
  1772. { DW_LNS_advance_pc }
  1773. linelist.concat(tai_const.create_8bit(1));
  1774. { DW_LNS_advance_line }
  1775. linelist.concat(tai_const.create_8bit(1));
  1776. { DW_LNS_set_file }
  1777. linelist.concat(tai_const.create_8bit(1));
  1778. { DW_LNS_set_column }
  1779. linelist.concat(tai_const.create_8bit(1));
  1780. { DW_LNS_negate_stmt }
  1781. linelist.concat(tai_const.create_8bit(0));
  1782. { DW_LNS_set_basic_block }
  1783. linelist.concat(tai_const.create_8bit(0));
  1784. { DW_LNS_const_add_pc }
  1785. linelist.concat(tai_const.create_8bit(0));
  1786. { DW_LNS_fixed_advance_pc }
  1787. linelist.concat(tai_const.create_8bit(1));
  1788. { DW_LNS_set_prologue_end }
  1789. linelist.concat(tai_const.create_8bit(0));
  1790. { DW_LNS_set_epilogue_begin }
  1791. linelist.concat(tai_const.create_8bit(0));
  1792. { DW_LNS_set_isa }
  1793. linelist.concat(tai_const.create_8bit(1));
  1794. { Create single list of filenames sorted in IndexNr }
  1795. flist:=TFPList.Create;
  1796. for n := 0 to dirlist.Count - 1 do
  1797. begin
  1798. ditem := TDirIndexItem(dirlist[n]);
  1799. for m := 0 to ditem.Files.Count - 1 do
  1800. flist.Add(ditem.Files[m]);
  1801. end;
  1802. flist.Sort(@FileListSortCompare);
  1803. { include_directories }
  1804. linelist.concat(tai_comment.Create(strpnew('include_directories')));
  1805. for n := 0 to dirlist.Count - 1 do
  1806. begin
  1807. ditem := TDirIndexItem(dirlist[n]);
  1808. if ditem.Name = '.' then
  1809. Continue;
  1810. linelist.concat(tai_string.create(ditem.Name+#0));
  1811. end;
  1812. linelist.concat(tai_const.create_8bit(0));
  1813. { file_names }
  1814. linelist.concat(tai_comment.Create(strpnew('file_names')));
  1815. for n := 0 to flist.Count - 1 do
  1816. begin
  1817. fitem := TFileIndexItem(flist[n]);
  1818. { file name }
  1819. linelist.concat(tai_string.create(fitem.Name+#0));
  1820. { directory index }
  1821. linelist.concat(tai_const.create_uleb128bit(fitem.DirIndex));
  1822. { last modification }
  1823. linelist.concat(tai_const.create_uleb128bit(0));
  1824. { file length }
  1825. linelist.concat(tai_const.create_uleb128bit(0));
  1826. end;
  1827. linelist.concat(tai_const.create_8bit(0));
  1828. { end of debug line header }
  1829. linelist.concat(tai_symbol.createname('.Lehdebug_line0',AT_DATA,0));
  1830. linelist.concat(tai_comment.Create(strpnew('=== header end ===')));
  1831. { add line program }
  1832. linelist.concatList(asmline);
  1833. { end of debug line table }
  1834. linelist.concat(tai_symbol.createname('.Ledebug_line0',AT_DATA,0));
  1835. end;
  1836. procedure TDebugInfoDwarf.inserttypeinfo;
  1837. procedure write_defs_to_write;
  1838. var
  1839. n : integer;
  1840. looplist,
  1841. templist: TFPObjectList;
  1842. def : tdef;
  1843. begin
  1844. templist := TFPObjectList.Create(False);
  1845. looplist := deftowritelist;
  1846. while looplist.count > 0 do
  1847. begin
  1848. deftowritelist := templist;
  1849. for n := 0 to looplist.count - 1 do
  1850. begin
  1851. def := tdef(looplist[n]);
  1852. case def.dbg_state of
  1853. dbg_state_written:
  1854. continue;
  1855. dbg_state_writing:
  1856. internalerror(200610052);
  1857. dbg_state_unused:
  1858. internalerror(200610053);
  1859. dbg_state_used:
  1860. appenddef(def)
  1861. else
  1862. internalerror(200610054);
  1863. end;
  1864. end;
  1865. looplist.clear;
  1866. templist := looplist;
  1867. looplist := deftowritelist;
  1868. end;
  1869. templist.free;
  1870. end;
  1871. var
  1872. storefilepos : tfileposinfo;
  1873. lenstartlabel : tasmlabel;
  1874. i : longint;
  1875. def: tdef;
  1876. begin
  1877. storefilepos:=current_filepos;
  1878. current_filepos:=current_module.mainfilepos;
  1879. currabbrevnumber:=0;
  1880. writing_def_dwarf:=false;
  1881. defnumberlist:=TFPObjectList.create(false);
  1882. deftowritelist:=TFPObjectList.create(false);
  1883. { not exported (FK)
  1884. FILEREC
  1885. TEXTREC
  1886. }
  1887. vardatadef:=trecorddef(search_system_type('TVARDATA').typedef);
  1888. { write start labels }
  1889. current_asmdata.asmlists[al_dwarf_info].concat(tai_section.create(sec_debug_info,'',0));
  1890. current_asmdata.asmlists[al_dwarf_info].concat(tai_symbol.createname('.Ldebug_info0',AT_DATA,0));
  1891. { start abbrev section }
  1892. new_section(current_asmdata.asmlists[al_dwarf_abbrev],sec_debug_abbrev,'',0);
  1893. { debug info header }
  1894. current_asmdata.getlabel(lenstartlabel,alt_dbgfile);
  1895. { size }
  1896. if use_64bit_headers then
  1897. begin
  1898. current_asmdata.asmlists[al_dwarf_info].concat(tai_const.create_32bit(longint($FFFFFFFF)));
  1899. current_asmdata.asmlists[al_dwarf_info].concat(tai_const.create_rel_sym(aitconst_64bit,
  1900. lenstartlabel,current_asmdata.RefAsmSymbol('.Ledebug_info0')));
  1901. end
  1902. else
  1903. current_asmdata.asmlists[al_dwarf_info].concat(tai_const.create_rel_sym(aitconst_32bit,
  1904. lenstartlabel,current_asmdata.RefAsmSymbol('.Ledebug_info0')));
  1905. current_asmdata.asmlists[al_dwarf_info].concat(tai_label.create(lenstartlabel));
  1906. { version }
  1907. current_asmdata.asmlists[al_dwarf_info].concat(tai_const.create_16bit(dwarf_version));
  1908. { abbrev table (=relative from section start)}
  1909. if use_64bit_headers then
  1910. current_asmdata.asmlists[al_dwarf_info].concat(tai_const.create_type_sym(aitconst_64bit,
  1911. current_asmdata.RefAsmSymbol('.Ldebug_abbrev0')))
  1912. else
  1913. current_asmdata.asmlists[al_dwarf_info].concat(tai_const.create_type_sym(aitconst_32bit,
  1914. current_asmdata.RefAsmSymbol('.Ldebug_abbrev0')));
  1915. { address size }
  1916. current_asmdata.asmlists[al_dwarf_info].concat(tai_const.create_8bit(sizeof(aint)));
  1917. { first manadatory compilation unit TAG }
  1918. append_entry(DW_TAG_compile_unit,true,[
  1919. DW_AT_name,DW_FORM_string,FixFileName(current_module.sourcefiles.get_file(1).name^)+#0,
  1920. DW_AT_producer,DW_FORM_string,'Free Pascal '+full_version_string+' '+date_string+#0,
  1921. DW_AT_comp_dir,DW_FORM_string,BsToSlash(FixPath(current_module.sourcefiles.get_file(1).path^,false))+#0,
  1922. DW_AT_language,DW_FORM_data1,DW_LANG_Pascal83,
  1923. DW_AT_identifier_case,DW_FORM_data1,DW_ID_case_insensitive]);
  1924. { reference to line info section }
  1925. append_labelentry_dataptr(DW_AT_stmt_list,current_asmdata.RefAsmSymbol('.Ldebug_line0'));
  1926. append_labelentry(DW_AT_low_pc,current_asmdata.RefAsmSymbol('.Ltext0'));
  1927. append_labelentry(DW_AT_high_pc,current_asmdata.RefAsmSymbol('.Letext0'));
  1928. finish_entry;
  1929. { first write all global/local symbols. This will flag all required tdefs }
  1930. if assigned(current_module.globalsymtable) then
  1931. begin
  1932. 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))));
  1933. write_symtable_syms(current_module.globalsymtable);
  1934. 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))));
  1935. end;
  1936. if assigned(current_module.localsymtable) then
  1937. begin
  1938. current_asmdata.asmlists[al_dwarf_info].concat(tai_comment.Create(strpnew('Syms - Begin Staticsymtable')));
  1939. write_symtable_syms(current_module.localsymtable);
  1940. current_asmdata.asmlists[al_dwarf_info].concat(tai_comment.Create(strpnew('Syms - End Staticsymtable')));
  1941. end;
  1942. { reset unit type info flag }
  1943. reset_unit_type_info;
  1944. { write used types from the used units }
  1945. write_used_unit_type_info(current_asmdata.asmlists[al_dwarf_info],current_module);
  1946. { last write the types from this unit }
  1947. if assigned(current_module.globalsymtable) then
  1948. write_symtable_defs(current_asmdata.asmlists[al_dwarf_info],current_module.globalsymtable);
  1949. if assigned(current_module.localsymtable) then
  1950. write_symtable_defs(current_asmdata.asmlists[al_dwarf_info],current_module.localsymtable);
  1951. { write defs not written yet }
  1952. write_defs_to_write;
  1953. { close compilation unit entry }
  1954. finish_children;
  1955. { end of debug info table }
  1956. current_asmdata.asmlists[al_dwarf_info].concat(tai_const.create_8bit(0));
  1957. current_asmdata.asmlists[al_dwarf_info].concat(tai_symbol.createname('.Ledebug_info0',AT_DATA,0));
  1958. { end of abbrev table }
  1959. current_asmdata.asmlists[al_dwarf_abbrev].concat(tai_const.create_8bit(0));
  1960. { reset all def labels }
  1961. for i:=0 to defnumberlist.count-1 do
  1962. begin
  1963. def := tdef(defnumberlist[i]);
  1964. if assigned(def) then
  1965. begin
  1966. def.dwarf_lab:=nil;
  1967. def.dbg_state:=dbg_state_unused;
  1968. end;
  1969. end;
  1970. defnumberlist.free;
  1971. defnumberlist:=nil;
  1972. deftowritelist.free;
  1973. deftowritelist:=nil;
  1974. current_filepos:=storefilepos;
  1975. end;
  1976. procedure TDebugInfoDwarf.referencesections(list:TAsmList);
  1977. begin
  1978. end;
  1979. function TDebugInfoDwarf.symname(sym: tsym): String;
  1980. begin
  1981. result := sym.Name;
  1982. end;
  1983. procedure TDebugInfoDwarf.insertlineinfo(list:TAsmList);
  1984. var
  1985. currfileinfo,
  1986. lastfileinfo : tfileposinfo;
  1987. currfuncname : pshortstring;
  1988. currsectype : TAsmSectiontype;
  1989. hlabel : tasmlabel;
  1990. hp : tai;
  1991. infile : tinputfile;
  1992. prevcolumn,
  1993. diffline,
  1994. prevline,
  1995. prevfileidx,
  1996. currfileidx: Integer;
  1997. prevlabel,
  1998. currlabel : tasmlabel;
  1999. begin
  2000. FillChar(lastfileinfo,sizeof(lastfileinfo),0);
  2001. currfuncname:=nil;
  2002. currsectype:=sec_code;
  2003. hp:=Tai(list.first);
  2004. prevcolumn := 0;
  2005. prevline := 1;
  2006. prevfileidx := 1;
  2007. prevlabel := nil;
  2008. while assigned(hp) do
  2009. begin
  2010. case hp.typ of
  2011. ait_section :
  2012. currsectype:=tai_section(hp).sectype;
  2013. ait_function_name :
  2014. begin
  2015. currfuncname:=tai_function_name(hp).funcname;
  2016. asmline.concat(tai_comment.Create(strpnew('function: '+currfuncname^)));
  2017. end;
  2018. ait_force_line : begin
  2019. lastfileinfo.line:=-1;
  2020. end;
  2021. end;
  2022. if (currsectype=sec_code) and
  2023. (hp.typ=ait_instruction) then
  2024. begin
  2025. currfileinfo:=tailineinfo(hp).fileinfo;
  2026. { file changed ? (must be before line info) }
  2027. if (currfileinfo.fileindex<>0) and
  2028. (lastfileinfo.fileindex<>currfileinfo.fileindex) then
  2029. begin
  2030. infile:=current_module.sourcefiles.get_file(currfileinfo.fileindex);
  2031. if assigned(infile) then
  2032. begin
  2033. currfileidx := get_file_index(infile);
  2034. if prevfileidx <> currfileidx then
  2035. begin
  2036. list.insertbefore(tai_comment.Create(strpnew('path: '+infile.path^)), hp);
  2037. list.insertbefore(tai_comment.Create(strpnew('file: '+infile.name^)), hp);
  2038. list.insertbefore(tai_comment.Create(strpnew('indx: '+tostr(currfileidx))), hp);
  2039. { set file }
  2040. asmline.concat(tai_comment.Create(strpnew('path: '+infile.path^)));
  2041. asmline.concat(tai_comment.Create(strpnew('file: '+infile.name^)));
  2042. asmline.concat(tai_const.create_8bit(DW_LNS_set_file));
  2043. asmline.concat(tai_const.create_uleb128bit(currfileidx));
  2044. prevfileidx := currfileidx;
  2045. end;
  2046. { force new line info }
  2047. lastfileinfo.line:=-1;
  2048. end;
  2049. end;
  2050. { line changed ? }
  2051. if (lastfileinfo.line<>currfileinfo.line) and (currfileinfo.line<>0) then
  2052. begin
  2053. { set address }
  2054. current_asmdata.getlabel(currlabel, alt_dbgline);
  2055. list.insertbefore(tai_label.create(currlabel), hp);
  2056. asmline.concat(tai_comment.Create(strpnew('['+tostr(currfileinfo.line)+':'+tostr(currfileinfo.column)+']')));
  2057. if prevlabel = nil then
  2058. begin
  2059. asmline.concat(tai_const.create_8bit(DW_LNS_extended_op));
  2060. {$ifdef cpu64bit}
  2061. asmline.concat(tai_const.create_uleb128bit(9)); { 1 + 8 }
  2062. asmline.concat(tai_const.create_8bit(DW_LNE_set_address));
  2063. asmline.concat(tai_const.create_type_sym(aitconst_64bit, currlabel));
  2064. {$else cpu64bit}
  2065. asmline.concat(tai_const.create_uleb128bit(5)); { 1 + 4 }
  2066. asmline.concat(tai_const.create_8bit(DW_LNE_set_address));
  2067. asmline.concat(tai_const.create_type_sym(aitconst_32bit, currlabel));
  2068. {$endif cpu64bit}
  2069. end
  2070. else
  2071. begin
  2072. asmline.concat(tai_const.create_8bit(DW_LNS_advance_pc));
  2073. asmline.concat(tai_const.create_rel_sym(aitconst_uleb128bit, prevlabel, currlabel));
  2074. end;
  2075. prevlabel := currlabel;
  2076. { set column }
  2077. if prevcolumn <> currfileinfo.column then
  2078. begin
  2079. asmline.concat(tai_const.create_8bit(DW_LNS_set_column));
  2080. asmline.concat(tai_const.create_uleb128bit(currfileinfo.column));
  2081. prevcolumn := currfileinfo.column;
  2082. end;
  2083. { set line }
  2084. diffline := currfileinfo.line - prevline;
  2085. if (diffline >= LINE_BASE) and (OPCODE_BASE + diffline - LINE_BASE <= 255) then
  2086. begin
  2087. { use special opcode, this also adds a row }
  2088. asmline.concat(tai_const.create_8bit(OPCODE_BASE + diffline - LINE_BASE));
  2089. end
  2090. else
  2091. begin
  2092. if diffline <> 0 then
  2093. begin
  2094. asmline.concat(tai_const.create_8bit(DW_LNS_advance_line));
  2095. asmline.concat(tai_const.create_sleb128bit(diffline));
  2096. end;
  2097. { no row added yet, do it manually }
  2098. asmline.concat(tai_const.create_8bit(DW_LNS_copy));
  2099. end;
  2100. prevline := currfileinfo.line;
  2101. end;
  2102. lastfileinfo:=currfileinfo;
  2103. end;
  2104. hp:=tai(hp.next);
  2105. end;
  2106. { end sequence }
  2107. asmline.concat(tai_const.Create_8bit(DW_LNS_extended_op));
  2108. asmline.concat(tai_const.Create_8bit(1));
  2109. asmline.concat(tai_const.Create_8bit(DW_LNE_end_sequence));
  2110. asmline.concat(tai_comment.Create(strpnew('###################')));
  2111. end;
  2112. {****************************************************************************
  2113. TDebugInfoDwarf2
  2114. ****************************************************************************}
  2115. procedure TDebugInfoDwarf2.appenddef_file(def: tfiledef);
  2116. begin
  2117. { gdb 6.4 doesn't support files so far so we use some fake recorddef
  2118. file recs. are less than 1k so using data2 is enough }
  2119. if assigned(def.typesym) then
  2120. append_entry(DW_TAG_structure_type,false,[
  2121. DW_AT_name,DW_FORM_string,symname(def.typesym)+#0,
  2122. DW_AT_byte_size,DW_FORM_udata,def.size
  2123. ])
  2124. else
  2125. append_entry(DW_TAG_structure_type,false,[
  2126. DW_AT_byte_size,DW_FORM_udata,def.size
  2127. ]);
  2128. finish_entry;
  2129. end;
  2130. procedure TDebugInfoDwarf2.appenddef_formal(def: tformaldef);
  2131. begin
  2132. { gdb 6.4 doesn't support DW_TAG_unspecified_type so we
  2133. replace it with a unsigned type with size 0 (FK)
  2134. }
  2135. append_entry(DW_TAG_base_type,false,[
  2136. DW_AT_name,DW_FORM_string,'FormalDef'#0,
  2137. DW_AT_encoding,DW_FORM_data1,DW_ATE_unsigned,
  2138. DW_AT_byte_size,DW_FORM_data1,0
  2139. ]);
  2140. finish_entry;
  2141. end;
  2142. procedure TDebugInfoDwarf2.appenddef_object(def: tobjectdef);
  2143. procedure doappend;
  2144. begin
  2145. if assigned(def.objname) then
  2146. append_entry(DW_TAG_structure_type,true,[
  2147. DW_AT_name,DW_FORM_string,def.objname^+#0,
  2148. DW_AT_byte_size,DW_FORM_udata,def.size
  2149. ])
  2150. else
  2151. append_entry(DW_TAG_structure_type,true,[
  2152. DW_AT_byte_size,DW_FORM_udata,def.size
  2153. ]);
  2154. finish_entry;
  2155. if assigned(def.childof) then
  2156. begin
  2157. append_entry(DW_TAG_inheritance,false,[
  2158. DW_AT_accessibility,DW_FORM_data1,DW_ACCESS_public,
  2159. DW_AT_data_member_location,DW_FORM_block1,1+lengthuleb128(0)
  2160. ]);
  2161. current_asmdata.asmlists[al_dwarf_info].concat(tai_const.create_8bit(ord(DW_OP_plus_uconst)));
  2162. current_asmdata.asmlists[al_dwarf_info].concat(tai_const.create_uleb128bit(0));
  2163. append_labelentry_ref(DW_AT_type,def_dwarf_lab(def.childof));
  2164. finish_entry;
  2165. end;
  2166. def.symtable.symList.ForEachCall(@enum_membersyms_callback,nil);
  2167. finish_children;
  2168. end;
  2169. var
  2170. obj : tasmlabel;
  2171. begin
  2172. case def.objecttype of
  2173. odt_cppclass,
  2174. odt_object:
  2175. doappend;
  2176. odt_interfacecom,
  2177. odt_interfacecorba,
  2178. odt_dispinterface,
  2179. odt_class:
  2180. begin
  2181. current_asmdata.getdatalabel(obj);
  2182. { implicit pointer }
  2183. append_entry(DW_TAG_pointer_type,false,[]);
  2184. append_labelentry_ref(DW_AT_type,obj);
  2185. finish_entry;
  2186. current_asmdata.asmlists[al_dwarf_info].concat(tai_symbol.create(obj,0));
  2187. doappend;
  2188. end;
  2189. else
  2190. internalerror(200602041);
  2191. end;
  2192. end;
  2193. procedure TDebugInfoDwarf2.appenddef_set(def: tsetdef);
  2194. begin
  2195. { at least gdb up to 6.4 doesn't support sets in dwarf, there is a patch available to fix this:
  2196. http://sources.redhat.com/ml/gdb-patches/2005-05/msg00278.html (FK) }
  2197. if assigned(def.typesym) then
  2198. append_entry(DW_TAG_base_type,false,[
  2199. DW_AT_name,DW_FORM_string,symname(def.typesym)+#0,
  2200. DW_AT_encoding,DW_FORM_data1,DW_ATE_unsigned,
  2201. DW_AT_byte_size,DW_FORM_data2,def.size
  2202. ])
  2203. else
  2204. append_entry(DW_TAG_base_type,false,[
  2205. DW_AT_encoding,DW_FORM_data1,DW_ATE_unsigned,
  2206. DW_AT_byte_size,DW_FORM_data2,def.size
  2207. ]);
  2208. finish_entry;
  2209. end;
  2210. procedure TDebugInfoDwarf2.appenddef_unineddef(def: tundefineddef);
  2211. begin
  2212. { gdb 6.4 doesn't support DW_TAG_unspecified_type so we
  2213. replace it with a unsigned type with size 0 (FK)
  2214. }
  2215. append_entry(DW_TAG_base_type,false,[
  2216. DW_AT_name,DW_FORM_string,'FormalDef'#0,
  2217. DW_AT_encoding,DW_FORM_data1,DW_ATE_unsigned,
  2218. DW_AT_byte_size,DW_FORM_data1,0
  2219. ]);
  2220. finish_entry;
  2221. end;
  2222. procedure TDebugInfoDwarf2.appenddef_variant(def: tvariantdef);
  2223. begin
  2224. { variants aren't known to dwarf2 but writting tvardata should be enough }
  2225. appenddef_record(trecorddef(vardatadef));
  2226. end;
  2227. function TDebugInfoDwarf2.dwarf_version: Word;
  2228. begin
  2229. Result:=2;
  2230. end;
  2231. {****************************************************************************
  2232. TDebugInfoDwarf3
  2233. ****************************************************************************}
  2234. procedure TDebugInfoDwarf3.appenddef_file(def: tfiledef);
  2235. begin
  2236. if assigned(def.typesym) then
  2237. append_entry(DW_TAG_file_type,false,[
  2238. DW_AT_name,DW_FORM_string,symname(def.typesym)+#0,
  2239. DW_AT_byte_size,DW_FORM_data2,def.size
  2240. ])
  2241. else
  2242. append_entry(DW_TAG_file_type,false,[
  2243. DW_AT_byte_size,DW_FORM_data2,def.size
  2244. ]);
  2245. if tfiledef(def).filetyp=ft_typed then
  2246. append_labelentry_ref(DW_AT_type,def_dwarf_lab(tfiledef(def).typedfiledef));
  2247. finish_entry;
  2248. end;
  2249. procedure TDebugInfoDwarf3.appenddef_formal(def: tformaldef);
  2250. begin
  2251. append_entry(DW_TAG_unspecified_type,false,[
  2252. ]);
  2253. finish_entry;
  2254. end;
  2255. procedure TDebugInfoDwarf3.appenddef_object(def: tobjectdef);
  2256. procedure dostruct(tag: tdwarf_tag);
  2257. begin
  2258. if assigned(def.objname) then
  2259. append_entry(tag,true,[
  2260. DW_AT_name,DW_FORM_string,def.objrealname^+#0,
  2261. DW_AT_byte_size,DW_FORM_udata,def.size
  2262. ])
  2263. else
  2264. append_entry(DW_TAG_structure_type,true,[
  2265. DW_AT_byte_size,DW_FORM_udata,def.size
  2266. ]);
  2267. finish_entry;
  2268. end;
  2269. procedure doimplicitpointer;
  2270. var
  2271. obj : tasmlabel;
  2272. begin
  2273. current_asmdata.getdatalabel(obj);
  2274. { implicit pointer }
  2275. append_entry(DW_TAG_pointer_type,false,[]);
  2276. append_labelentry_ref(DW_AT_type,obj);
  2277. finish_entry;
  2278. current_asmdata.asmlists[al_dwarf_info].concat(tai_symbol.create(obj,0));
  2279. end;
  2280. procedure doparent(isinterface: boolean);
  2281. begin
  2282. if not assigned(def.childof) then
  2283. exit;
  2284. if isinterface then
  2285. begin
  2286. append_entry(DW_TAG_inheritance,false,[]);
  2287. end
  2288. else
  2289. begin
  2290. append_entry(DW_TAG_inheritance,false,[
  2291. DW_AT_accessibility,DW_FORM_data1,DW_ACCESS_public,
  2292. DW_AT_data_member_location,DW_FORM_block1,1+lengthuleb128(0)
  2293. ]);
  2294. current_asmdata.asmlists[al_dwarf_info].concat(tai_const.create_8bit(ord(DW_OP_plus_uconst)));
  2295. current_asmdata.asmlists[al_dwarf_info].concat(tai_const.create_uleb128bit(0));
  2296. end;
  2297. append_labelentry_ref(DW_AT_type,def_dwarf_lab(def.childof));
  2298. finish_entry;
  2299. end;
  2300. var
  2301. n: integer;
  2302. begin
  2303. case def.objecttype of
  2304. odt_cppclass,
  2305. odt_object:
  2306. begin
  2307. dostruct(DW_TAG_structure_type);
  2308. doparent(false);
  2309. end;
  2310. odt_interfacecom,
  2311. odt_interfacecorba,
  2312. odt_dispinterface:
  2313. begin
  2314. dostruct(DW_TAG_interface_type);
  2315. doparent(true);
  2316. end;
  2317. odt_class:
  2318. begin
  2319. { not sure if the implicit pointer is needed for tag_class (MWE)}
  2320. {
  2321. doimplicitpointer;
  2322. }
  2323. dostruct(DW_TAG_class_type);
  2324. doparent(false);
  2325. end;
  2326. else
  2327. internalerror(200609171);
  2328. end;
  2329. { add implemented interfaces }
  2330. if assigned(def.ImplementedInterfaces) then
  2331. for n := 0 to def.ImplementedInterfaces.count-1 do
  2332. begin
  2333. append_entry(DW_TAG_inheritance,false,[]);
  2334. append_labelentry_ref(DW_AT_type,def_dwarf_lab(TImplementedInterface(def.ImplementedInterfaces[n]).IntfDef));
  2335. finish_entry;
  2336. end;
  2337. { add members }
  2338. def.symtable.symList.ForEachCall(@enum_membersyms_callback,nil);
  2339. finish_children;
  2340. end;
  2341. procedure TDebugInfoDwarf3.appenddef_set(def: tsetdef);
  2342. begin
  2343. if assigned(def.typesym) then
  2344. append_entry(DW_TAG_set_type,false,[
  2345. DW_AT_name,DW_FORM_string,symname(def.typesym)+#0,
  2346. DW_AT_byte_size,DW_FORM_data2,def.size
  2347. ])
  2348. else
  2349. append_entry(DW_TAG_set_type,false,[
  2350. DW_AT_byte_size,DW_FORM_data2,def.size
  2351. ]);
  2352. if assigned(tsetdef(def).elementdef) then
  2353. append_labelentry_ref(DW_AT_type,def_dwarf_lab(tsetdef(def).elementdef));
  2354. finish_entry;
  2355. end;
  2356. procedure TDebugInfoDwarf3.appenddef_unineddef(def: tundefineddef);
  2357. begin
  2358. { ??? can a undefined def have a typename ? }
  2359. if assigned(def.typesym) then
  2360. append_entry(DW_TAG_unspecified_type,false,[
  2361. DW_AT_name,DW_FORM_string,symname(def.typesym)+#0
  2362. ])
  2363. else
  2364. append_entry(DW_TAG_unspecified_type,false,[
  2365. ]);
  2366. finish_entry;
  2367. end;
  2368. procedure TDebugInfoDwarf3.appenddef_variant(def: tvariantdef);
  2369. const
  2370. VARIANTS: array[1..27] of record Value: Word; Name: String end = (
  2371. (value:0; name:''),
  2372. (value:1; name:''),
  2373. (value:2; name:'VSMALLINT'),
  2374. (value:3; name:'VINTEGER'),
  2375. (value:4; name:'VSINGLE'),
  2376. (value:5; name:'VDOUBLE'),
  2377. (value:6; name:'VCURRENCY'),
  2378. (value:7; name:'VDATE'),
  2379. (value:8; name:'VOLESTR'),
  2380. (value:9; name:'VDISPATCH'),
  2381. (value:10; name:'VERROR'),
  2382. (value:11; name:'VBOOLEAN'),
  2383. (value:12; name:''),
  2384. (value:13; name:'VUNKNOWN'),
  2385. (value:14; name:''),
  2386. (value:16; name:'VSHORTINT'),
  2387. (value:17; name:'VBYTE'),
  2388. (value:18; name:'VWORD'),
  2389. (value:19; name:'VLONGWORD'),
  2390. (value:20; name:'VINT64'),
  2391. (value:21; name:'VQWORD'),
  2392. (value:36; name:'VRECORD'),
  2393. (value:$48; name:''),
  2394. (value:$100; name:'VSTRING'),
  2395. (value:$101; name:'VANY'),
  2396. (value:$2000; name:'VARRAY'),
  2397. (value:$4000; name:'VPOINTER')
  2398. );
  2399. var
  2400. fs: tfieldvarsym;
  2401. lbl: tasmlabel;
  2402. idx: integer;
  2403. begin
  2404. { it could be done with DW_TAG_variant for the union part (if that info was available)
  2405. now we do it manually for variants (MWE) }
  2406. { struct }
  2407. append_entry(DW_TAG_structure_type,true,[
  2408. DW_AT_name,DW_FORM_string,'Variant'#0,
  2409. DW_AT_byte_size,DW_FORM_udata,vardatadef.size
  2410. ]);
  2411. finish_entry;
  2412. append_entry(DW_TAG_variant_part,true,[
  2413. ]);
  2414. current_asmdata.getaddrlabel(lbl);
  2415. append_labelentry_ref(DW_AT_discr,lbl);
  2416. finish_entry;
  2417. { discriminant }
  2418. fs := tfieldvarsym(vardatadef.symtable.Find('VTYPE'));
  2419. if (fs = nil) or (fs.typ <> fieldvarsym) then
  2420. internalerror(200609271);
  2421. current_asmdata.asmlists[al_dwarf_info].concat(tai_symbol.create(lbl,0));
  2422. appendsym_fieldvar(fs);
  2423. { variants }
  2424. for idx := Low(VARIANTS) to High(VARIANTS) do
  2425. begin
  2426. append_entry(DW_TAG_variant,true,[
  2427. DW_AT_discr_value,DW_FORM_udata,VARIANTS[idx].value
  2428. ]);
  2429. finish_entry;
  2430. if VARIANTS[idx].name <> '' then
  2431. begin
  2432. fs := tfieldvarsym(vardatadef.symtable.Find(VARIANTS[idx].name));
  2433. if (fs = nil) or (fs.typ <> fieldvarsym) then
  2434. internalerror(20060927200+idx);
  2435. appendsym_fieldvar(fs);
  2436. end;
  2437. finish_children; { variant }
  2438. end;
  2439. finish_children; { variant part }
  2440. finish_children; { struct }
  2441. end;
  2442. function TDebugInfoDwarf3.dwarf_version: Word;
  2443. begin
  2444. Result:=3;
  2445. end;
  2446. function TDebugInfoDwarf3.symname(sym: tsym): String;
  2447. begin
  2448. Result:=sym.realname;
  2449. end;
  2450. {****************************************************************************
  2451. ****************************************************************************}
  2452. const
  2453. dbg_dwarf2_info : tdbginfo =
  2454. (
  2455. id : dbg_dwarf2;
  2456. idtxt : 'DWARF2';
  2457. );
  2458. dbg_dwarf3_info : tdbginfo =
  2459. (
  2460. id : dbg_dwarf3;
  2461. idtxt : 'DWARF3';
  2462. );
  2463. initialization
  2464. RegisterDebugInfo(dbg_dwarf2_info,TDebugInfoDwarf2);
  2465. RegisterDebugInfo(dbg_dwarf3_info,TDebugInfoDwarf3);
  2466. end.