dbgdwarf.pas 163 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128
  1. {
  2. Copyright (c) 2003-2006 by Peter Vreman and Florian Klaempfl
  3. This units contains support for DWARF debug info generation
  4. This program is free software; you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation; either version 2 of the License, or
  7. (at your option) any later version.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with this program; if not, write to the Free Software
  14. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  15. ****************************************************************************
  16. }
  17. {
  18. This units contains support for DWARF debug info generation.
  19. Currently a lot of code looks like being mergable with dbgstabs. This might
  20. change however when improved dwarf info is generated, so the stuff shouldn't be
  21. merged yet. (FK)
  22. The easiest way to debug dwarf debug info generation is the usage of
  23. readelf --debug-dump <executable>
  24. This works only with elf targets though.
  25. There is a similar utility called dwarfdump which is not elf-specific and
  26. which has been ported to most systems.
  27. }
  28. unit dbgdwarf;
  29. {$i fpcdefs.inc}
  30. interface
  31. uses
  32. cclasses,globtype,
  33. aasmbase,aasmtai,aasmdata,
  34. symbase,symconst,symtype,symdef,symsym,
  35. finput,
  36. DbgBase;
  37. type
  38. { Tag names and codes. }
  39. tdwarf_tag = (DW_TAG_padding := $00,DW_TAG_array_type := $01,
  40. DW_TAG_class_type := $02,DW_TAG_entry_point := $03,
  41. DW_TAG_enumeration_type := $04,DW_TAG_formal_parameter := $05,
  42. DW_TAG_imported_declaration := $08,DW_TAG_label := $0a,
  43. DW_TAG_lexical_block := $0b,DW_TAG_member := $0d,
  44. DW_TAG_pointer_type := $0f,DW_TAG_reference_type := $10,
  45. DW_TAG_compile_unit := $11,DW_TAG_stringtypee := $12,
  46. DW_TAG_structure_type := $13,DW_TAG_subroutine_type := $15,
  47. DW_TAG_typedef := $16,DW_TAG_union_type := $17,
  48. DW_TAG_unspecified_parameters := $18,
  49. DW_TAG_variant := $19,DW_TAG_common_block := $1a,
  50. DW_TAG_common_inclusion := $1b,DW_TAG_inheritance := $1c,
  51. DW_TAG_inlined_subroutine := $1d,DW_TAG_module := $1e,
  52. DW_TAG_ptr_to_member_type := $1f,DW_TAG_set_type := $20,
  53. DW_TAG_subrange_type := $21,DW_TAG_with_stmt := $22,
  54. DW_TAG_access_declaration := $23,DW_TAG_base_type := $24,
  55. DW_TAG_catch_block := $25,DW_TAG_const_type := $26,
  56. DW_TAG_constant := $27,DW_TAG_enumerator := $28,
  57. DW_TAG_file_type := $29,DW_TAG_friend := $2a,
  58. DW_TAG_namelist := $2b,DW_TAG_namelist_item := $2c,
  59. DW_TAG_packed_type := $2d,DW_TAG_subprogram := $2e,
  60. DW_TAG_template_type_param := $2f,DW_TAG_template_value_param := $30,
  61. DW_TAG_thrown_type := $31,DW_TAG_try_block := $32,
  62. DW_TAG_variant_part := $33,DW_TAG_variable := $34,
  63. DW_TAG_volatile_type := $35,
  64. { DWARF 3. }
  65. DW_TAG_dwarf_procedure := $36,
  66. DW_TAG_restrict_type := $37,DW_TAG_interface_type := $38,
  67. DW_TAG_namespace := $39,DW_TAG_imported_module := $3a,
  68. DW_TAG_unspecified_type := $3b,DW_TAG_partial_unit := $3c,
  69. DW_TAG_imported_unit := $3d,
  70. DW_TAG_condition := $3f,
  71. DW_TAG_shared_type := $40,
  72. { DWARF 4 }
  73. DW_TAG_type_unit := $41,
  74. DW_TAG_rvalue_reference_type := $42,
  75. DW_TAG_template_alias := $43,
  76. { SGI/MIPS Extensions. }
  77. DW_TAG_MIPS_loop := $4081,
  78. { HP extensions. See: ftp://ftp.hp.com/pub/lang/tools/WDB/wdb-4.0.tar.gz . }
  79. DW_TAG_HP_array_descriptor := $4090,
  80. { GNU extensions. }
  81. { For FORTRAN 77 and Fortran 90. }
  82. DW_TAG_format_label := $4101,
  83. { For C++. }
  84. DW_TAG_function_template := $4102,DW_TAG_class_template := $4103,
  85. DW_TAG_GNU_BINCL := $4104,DW_TAG_GNU_EINCL := $4105,
  86. { Extensions for UPC. See: http://upc.gwu.edu/~upc. }
  87. DW_TAG_upc_shared_type := $8765,DW_TAG_upc_strict_type := $8766,
  88. DW_TAG_upc_relaxed_type := $8767,
  89. { PGI (STMicroelectronics) extensions. No documentation available. }
  90. DW_TAG_PGI_kanji_type := $A000,
  91. DW_TAG_PGI_interface_block := $A020
  92. );
  93. {$notes off}
  94. { Attribute names and codes. }
  95. tdwarf_attribute = (DW_AT_sibling := $01,DW_AT_location := $02,
  96. DW_AT_name := $03,DW_AT_ordering := $09,
  97. DW_AT_subscr_data := $0a,DW_AT_byte_size := $0b,
  98. DW_AT_bit_offset := $0c,DW_AT_bit_size := $0d,
  99. DW_AT_element_list := $0f,DW_AT_stmt_list := $10,
  100. DW_AT_low_pc := $11,DW_AT_high_pc := $12,
  101. DW_AT_language := $13,DW_AT_member := $14,
  102. DW_AT_discr := $15,DW_AT_discr_value := $16,
  103. DW_AT_visibility := $17,DW_AT_import := $18,
  104. DW_AT_string_length := $19,DW_AT_common_reference := $1a,
  105. DW_AT_comp_dir := $1b,DW_AT_const_value := $1c,
  106. DW_AT_containing_type := $1d,DW_AT_default_value := $1e,
  107. DW_AT_inline := $20,DW_AT_is_optional := $21,
  108. DW_AT_lower_bound := $22,DW_AT_producer := $25,
  109. DW_AT_prototyped := $27,DW_AT_return_addr := $2a,
  110. DW_AT_start_scope := $2c,DW_AT_stride_size := $2e,
  111. DW_AT_upper_bound := $2f,DW_AT_abstract_origin := $31,
  112. DW_AT_accessibility := $32,DW_AT_address_class := $33,
  113. DW_AT_artificial := $34,DW_AT_base_types := $35,
  114. DW_AT_calling_convention := $36,DW_AT_count := $37,
  115. DW_AT_data_member_location := $38,DW_AT_decl_column := $39,
  116. DW_AT_decl_file := $3a,DW_AT_decl_line := $3b,
  117. DW_AT_declaration := $3c,DW_AT_discr_list := $3d,
  118. DW_AT_encoding := $3e,DW_AT_external := $3f,
  119. DW_AT_frame_base := $40,DW_AT_friend := $41,
  120. DW_AT_identifier_case := $42,DW_AT_macro_info := $43,
  121. DW_AT_namelist_items := $44,DW_AT_priority := $45,
  122. DW_AT_segment := $46,DW_AT_specification := $47,
  123. DW_AT_static_link := $48,DW_AT_type := $49,
  124. DW_AT_use_location := $4a,DW_AT_variable_parameter := $4b,
  125. DW_AT_virtuality := $4c,DW_AT_vtable_elem_location := $4d,
  126. { DWARF 3 values. }
  127. DW_AT_allocated := $4e,DW_AT_associated := $4f,
  128. DW_AT_data_location := $50,DW_AT_byte_stride := $51,
  129. DW_AT_entry_pc := $52,DW_AT_use_UTF8 := $53,
  130. DW_AT_extension := $54,DW_AT_ranges := $55,
  131. DW_AT_trampoline := $56,DW_AT_call_column := $57,
  132. DW_AT_call_file := $58,DW_AT_call_line := $59,
  133. DW_AT_description := $5a, { string }
  134. DW_AT_binary_scale := $5b, { constant }
  135. DW_AT_decimal_scale := $5c, { constant }
  136. DW_AT_small := $5d, { reference }
  137. DW_AT_decimal_sign := $5e, { constant }
  138. DW_AT_digit_count := $5f, { constant }
  139. DW_AT_picture_string := $60, { string }
  140. DW_AT_mutable := $61, { flag }
  141. DW_AT_threads_scaled := $62, { flag }
  142. DW_AT_explicit := $63, { flag }
  143. DW_AT_object_pointer := $64, { reference }
  144. DW_AT_endianity := $65, { constant }
  145. DW_AT_elemental := $66, { flag }
  146. DW_AT_pure := $67, { flag }
  147. DW_AT_recursive := $68, { flag }
  148. { DWARF 4 values }
  149. DW_AT_signature := $69, { reference }
  150. DW_AT_main_subprogram := $6a, { flag }
  151. DW_AT_data_bit_offset := $6b, { constant }
  152. DW_AT_const_expr := $6c, { flag }
  153. DW_AT_enum_class := $6d, { flag }
  154. DW_AT_linkage_name := $6e, { string }
  155. { SGI/MIPS extensions. }
  156. DW_AT_MIPS_fde := $2001,DW_AT_MIPS_loop_begin := $2002,
  157. DW_AT_MIPS_tail_loop_begin := $2003,DW_AT_MIPS_epilog_begin := $2004,
  158. DW_AT_MIPS_loop_unroll_factor := $2005,
  159. DW_AT_MIPS_software_pipeline_depth := $2006,
  160. DW_AT_MIPS_linkage_name := $2007,DW_AT_MIPS_stride := $2008,
  161. DW_AT_MIPS_abstract_name := $2009,DW_AT_MIPS_clone_origin := $200a,
  162. DW_AT_MIPS_has_inlines := $200b,
  163. { HP extensions. }
  164. DW_AT_HP_block_index := $2000,
  165. DW_AT_HP_unmodifiable := $2001,DW_AT_HP_actuals_stmt_list := $2010,
  166. DW_AT_HP_proc_per_section := $2011,DW_AT_HP_raw_data_ptr := $2012,
  167. DW_AT_HP_pass_by_reference := $2013,DW_AT_HP_opt_level := $2014,
  168. DW_AT_HP_prof_version_id := $2015,DW_AT_HP_opt_flags := $2016,
  169. DW_AT_HP_cold_region_low_pc := $2017,DW_AT_HP_cold_region_high_pc := $2018,
  170. DW_AT_HP_all_variables_modifiable := $2019,
  171. DW_AT_HP_linkage_name := $201a,DW_AT_HP_prof_flags := $201b,
  172. { GNU extensions. }
  173. DW_AT_sf_names := $2101,DW_AT_src_info := $2102,
  174. DW_AT_mac_info := $2103,DW_AT_src_coords := $2104,
  175. DW_AT_body_begin := $2105,DW_AT_body_end := $2106,
  176. DW_AT_GNU_vector := $2107,
  177. { VMS extensions. }
  178. DW_AT_VMS_rtnbeg_pd_address := $2201,
  179. { UPC extension. }
  180. DW_AT_upc_threads_scaled := $3210,
  181. { PGI (STMicroelectronics) extensions. }
  182. DW_AT_PGI_lbase := $3a00,
  183. DW_AT_PGI_soffset := $3a01,DW_AT_PGI_lstride := $3a02,
  184. { Apple extensions }
  185. DW_AT_APPLE_optimized := $3fe1,
  186. DW_AT_APPLE_flags := $3fe2,
  187. DW_AT_APPLE_major_runtime_vers := $3fe5,
  188. DW_AT_APPLE_runtime_class := $3fe6
  189. );
  190. {$notes on}
  191. { Form names and codes. }
  192. Tdwarf_form = (DW_FORM_addr := $01,DW_FORM_block2 := $03,
  193. DW_FORM_block4 := $04,DW_FORM_data2 := $05,
  194. DW_FORM_data4 := $06,DW_FORM_data8 := $07,
  195. DW_FORM_string := $08,DW_FORM_block := $09,
  196. DW_FORM_block1 := $0a,DW_FORM_data1 := $0b,
  197. DW_FORM_flag := $0c,DW_FORM_sdata := $0d,
  198. DW_FORM_strp := $0e,DW_FORM_udata := $0f,
  199. DW_FORM_ref_addr := $10,DW_FORM_ref1 := $11,
  200. DW_FORM_ref2 := $12,DW_FORM_ref4 := $13,
  201. DW_FORM_ref8 := $14,DW_FORM_ref_udata := $15,
  202. DW_FORM_indirect := $16,
  203. { DWARF 4 }
  204. DW_FORM_sec_offset := $17, { lineptr, loclistptr, macptr, rangelistptr }
  205. DW_FORM_exprloc := $18, { exprloc }
  206. DW_FORM_flag_present := $19, { flag }
  207. DW_FORM_ref_sig8 := $20 { reference }
  208. );
  209. TDwarfFile = record
  210. Index: integer;
  211. Name: PChar;
  212. end;
  213. { flags for emitting variables/parameters }
  214. tdwarfvarsymflag =
  215. { force the sym to be emitted as a local variable regardless of its
  216. type; used for "absolute" local variables referring to parameters.
  217. }
  218. (dvf_force_local_var
  219. );
  220. tdwarfvarsymflags = set of tdwarfvarsymflag;
  221. pAbbrevSearchTreeItem = ^tAbbrevSearchTreeItem;
  222. tAbbrevSearchTreeItem = record
  223. value: QWord;
  224. Abbrev: longint;
  225. // When this item does not match the abbrev-value, look for it
  226. // in the next SearchItem
  227. SearchItem: pAbbrevSearchTreeItem;
  228. // Next and prior item of the abbrev-section
  229. NextItem: pAbbrevSearchTreeItem;
  230. PriorItem: pAbbrevSearchTreeItem;
  231. bit8: boolean;
  232. end;
  233. { TDebugInfoDwarf }
  234. TDebugInfoDwarf = class(TDebugInfo)
  235. private
  236. currabbrevnumber : longint;
  237. { use this defs to create info for variants and file handles }
  238. { unused (MWE)
  239. filerecdef,
  240. textrecdef : tdef;
  241. }
  242. dirlist: TFPHashObjectList;
  243. filesequence: Integer;
  244. loclist: tdynamicarray;
  245. asmline: TAsmList;
  246. // The current entry in dwarf_info with the link to the abbrev-section
  247. dwarf_info_abbref_tai: tai_const;
  248. // Empty start-item of the abbrev-searchtree
  249. AbbrevSearchTree: pAbbrevSearchTreeItem;
  250. // The current abbrev-item
  251. CurrentSearchTreeItem: pAbbrevSearchTreeItem;
  252. // Is true when the abbrev-section is newly created
  253. NewAbbrev: boolean;
  254. procedure StartAbbrevSearch;
  255. procedure AddConstToAbbrev(Value: QWord; bit8:boolean=false);
  256. procedure StartAbbrevSectionFromSearchtree;
  257. procedure WriteSearchItemToAbbrevSection(SI: pAbbrevSearchTreeItem);
  258. function FinishAbbrevSearch: longint;
  259. function def_dwarf_lab(def:tdef) : tasmsymbol;
  260. function def_dwarf_ref_lab(def:tdef) : tasmsymbol;
  261. function def_dwarf_class_struct_lab(def:tobjectdef) : tasmsymbol;
  262. function get_file_index(afile: tinputfile): Integer;
  263. function relative_dwarf_path(const s:tcmdstr):tcmdstr;
  264. protected
  265. // set if we should use 64bit headers (dwarf3 and up)
  266. _use_64bit_headers: Boolean;
  267. // set to ait_const32bit if use_64bit_headers is false, otherwise
  268. // to ait_const64bit
  269. offsetreltype,
  270. offsetabstype : taiconst_type;
  271. // set if we generated any lineinfo at all. If not, we have to terminate
  272. // when insertmoduleinfo is called.
  273. generated_lineinfo: boolean;
  274. vardatadef: trecorddef;
  275. procedure set_use_64bit_headers(state: boolean);
  276. property use_64bit_headers: Boolean read _use_64bit_headers write set_use_64bit_headers;
  277. procedure set_def_dwarf_labs(def:tdef);
  278. { Convenience version of the method below, so the compiler creates the
  279. tvarrec for us (must only pass one element in the last parameter). }
  280. procedure append_attribute(attr: tdwarf_attribute; form: tdwarf_form; const values: array of const);
  281. procedure append_attribute(attr: tdwarf_attribute; form: tdwarf_form; const value: tvarrec);
  282. procedure append_entry(tag : tdwarf_tag;has_children : boolean;data : array of const);
  283. procedure append_block1(attr: tdwarf_attribute; size: aint);
  284. procedure append_labelentry(attr : tdwarf_attribute;sym : tasmsymbol);
  285. procedure append_labelentry_addr_ref(attr : tdwarf_attribute;sym : tasmsymbol); virtual;
  286. procedure append_labelentry_ref(attr : tdwarf_attribute;sym : tasmsymbol);
  287. procedure append_labelentry_dataptr_abs(attr : tdwarf_attribute;sym : tasmsymbol);
  288. procedure append_labelentry_dataptr_rel(attr : tdwarf_attribute;sym,endsym : tasmsymbol);
  289. procedure append_labelentry_dataptr_common(attr : tdwarf_attribute);
  290. procedure beforeappenddef(list:TAsmList;def:tdef);override;
  291. procedure afterappenddef(list:TAsmList;def:tdef);override;
  292. procedure appenddef_ord(list:TAsmList;def:torddef);override;
  293. procedure appenddef_float(list:TAsmList;def:tfloatdef);override;
  294. procedure appenddef_enum(list:TAsmList;def:tenumdef);override;
  295. procedure appenddef_array(list:TAsmList;def:tarraydef);override;
  296. procedure appenddef_record_named(list:TAsmList;def:trecorddef;const name: shortstring);
  297. procedure appenddef_record(list:TAsmList;def:trecorddef);override;
  298. procedure appenddef_pointer(list:TAsmList;def:tpointerdef);override;
  299. procedure appenddef_string(list:TAsmList;def:tstringdef);override;
  300. procedure appenddef_procvar(list:TAsmList;def:tprocvardef);override;
  301. procedure appendprocdef(list:TAsmList;def:tprocdef);override;
  302. function get_symlist_sym_offset(symlist: ppropaccesslistitem; out sym: tabstractvarsym; out offset: pint): boolean;
  303. procedure appendsym_var(list:TAsmList;sym:tabstractnormalvarsym);
  304. procedure appendsym_var_with_name_type_offset(list:TAsmList; sym:tabstractnormalvarsym; const name: string; def: tdef; offset: pint; const flags: tdwarfvarsymflags);
  305. { used for fields and properties mapped to fields }
  306. procedure appendsym_fieldvar_with_name_offset(list:TAsmList;sym: tfieldvarsym;const name: string; def: tdef; offset: pint);
  307. procedure appendsym_const_member(list:TAsmList;sym:tconstsym;ismember:boolean);
  308. procedure beforeappendsym(list:TAsmList;sym:tsym);override;
  309. procedure appendsym_staticvar(list:TAsmList;sym:tstaticvarsym);override;
  310. procedure appendsym_paravar(list:TAsmList;sym:tparavarsym);override;
  311. procedure appendsym_localvar(list:TAsmList;sym:tlocalvarsym);override;
  312. procedure appendsym_fieldvar(list:TAsmList;sym:tfieldvarsym);override;
  313. procedure appendsym_const(list:TAsmList;sym:tconstsym);override;
  314. procedure appendsym_type(list:TAsmList;sym:ttypesym);override;
  315. procedure appendsym_label(list:TAsmList;sym:tlabelsym);override;
  316. procedure appendsym_absolute(list:TAsmList;sym:tabsolutevarsym);override;
  317. procedure appendsym_property(list:TAsmList;sym:tpropertysym);override;
  318. function symname(sym:tsym): String; virtual;
  319. procedure append_visibility(vis: tvisibility);
  320. procedure enum_membersyms_callback(p:TObject;arg:pointer);
  321. procedure finish_children;
  322. procedure finish_entry;
  323. procedure finish_lineinfo;
  324. public
  325. constructor Create;override;
  326. destructor Destroy;override;
  327. procedure insertmoduleinfo;override;
  328. procedure inserttypeinfo;override;
  329. procedure referencesections(list:TAsmList);override;
  330. procedure insertlineinfo(list:TAsmList);override;
  331. function dwarf_version: Word; virtual; abstract;
  332. end;
  333. { TDebugInfoDwarf2 }
  334. TDebugInfoDwarf2 = class(TDebugInfoDwarf)
  335. private
  336. protected
  337. procedure appenddef_set_intern(list:TAsmList;def:tsetdef; force_tag_set: boolean);
  338. procedure append_object_struct(def: tobjectdef; const createlabel: boolean; const objectname: PShortString);
  339. procedure appenddef_file(list:TAsmList;def:tfiledef); override;
  340. procedure appenddef_formal(list:TAsmList;def:tformaldef); override;
  341. procedure appenddef_object(list:TAsmList;def:tobjectdef); override;
  342. procedure appenddef_set(list:TAsmList;def:tsetdef); override;
  343. procedure appenddef_undefined(list:TAsmList;def:tundefineddef); override;
  344. procedure appenddef_variant(list:TAsmList;def:tvariantdef); override;
  345. public
  346. function dwarf_version: Word; override;
  347. end;
  348. { TDebugInfoDwarf3 }
  349. TDebugInfoDwarf3 = class(TDebugInfoDwarf2)
  350. private
  351. protected
  352. procedure append_labelentry_addr_ref(attr : tdwarf_attribute;sym : tasmsymbol); override;
  353. procedure appenddef_array(list:TAsmList;def:tarraydef); override;
  354. procedure appenddef_string(list:TAsmList;def:tstringdef);override;
  355. procedure appenddef_file(list:TAsmList;def:tfiledef); override;
  356. procedure appenddef_formal(list:TAsmList;def:tformaldef); override;
  357. procedure appenddef_object(list:TAsmList;def:tobjectdef); override;
  358. procedure appenddef_set(list:TAsmList;def: tsetdef); override;
  359. procedure appenddef_undefined(list:TAsmList;def:tundefineddef); override;
  360. procedure appenddef_variant(list:TAsmList;def:tvariantdef); override;
  361. function symname(sym:tsym): String; override;
  362. public
  363. function dwarf_version: Word; override;
  364. end;
  365. TDebugInfoDwarf4 = class(TDebugInfoDwarf3)
  366. public
  367. function dwarf_version: Word; override;
  368. end;
  369. implementation
  370. uses
  371. sysutils,cutils,cfileutl,constexp,
  372. version,globals,verbose,systems,
  373. cpubase,cpuinfo,cgbase,paramgr,
  374. fmodule,
  375. defutil,symtable,ppu
  376. ;
  377. const
  378. LINE_BASE = 1;
  379. OPCODE_BASE = 13;
  380. const
  381. DW_TAG_lo_user = $4080;
  382. DW_TAG_hi_user = $ffff;
  383. { Flag that tells whether entry has a child or not. }
  384. DW_children_no = 0;
  385. DW_children_yes = 1;
  386. const
  387. { Implementation-defined range start. }
  388. DW_AT_lo_user = $2000;
  389. { Implementation-defined range end. }
  390. DW_AT_hi_user = $3ff0;
  391. type
  392. { Source language names and codes. }
  393. tdwarf_source_language = (DW_LANG_C89 := $0001,DW_LANG_C := $0002,DW_LANG_Ada83 := $0003,
  394. DW_LANG_C_plus_plus := $0004,DW_LANG_Cobol74 := $0005,
  395. DW_LANG_Cobol85 := $0006,DW_LANG_Fortran77 := $0007,
  396. DW_LANG_Fortran90 := $0008,DW_LANG_Pascal83 := $0009,
  397. DW_LANG_Modula2 := $000a,DW_LANG_Java := $000b,
  398. { DWARF 3. }
  399. DW_LANG_C99 := $000c,DW_LANG_Ada95 := $000d,
  400. DW_LANG_Fortran95 := $000e,
  401. { Objective-C }
  402. DW_LANG_ObjC := $10,
  403. { MIPS. }
  404. DW_LANG_Mips_Assembler := $8001,
  405. { UPC. }
  406. DW_LANG_Upc := $8765
  407. );
  408. const
  409. { Implementation-defined range start. }
  410. DW_LANG_lo_user = $8000;
  411. { Implementation-defined range start. }
  412. DW_LANG_hi_user = $ffff;
  413. type
  414. { Names and codes for macro information. }
  415. tdwarf_macinfo_record_type = (DW_MACINFO_define := 1,DW_MACINFO_undef := 2,
  416. DW_MACINFO_start_file := 3,DW_MACINFO_end_file := 4,
  417. DW_MACINFO_vendor_ext := 255);
  418. type
  419. { Type encodings. }
  420. Tdwarf_type = (DW_ATE_void := $0,DW_ATE_address := $1,
  421. DW_ATE_boolean := $2,DW_ATE_complex_float := $3,
  422. DW_ATE_float := $4,DW_ATE_signed := $5,
  423. DW_ATE_signed_char := $6,DW_ATE_unsigned := $7,
  424. DW_ATE_unsigned_char := $8,DW_ATE_imaginary_float := $9,
  425. { HP extensions. }
  426. DW_ATE_HP_float80 := $80,DW_ATE_HP_complex_float80 := $81,
  427. DW_ATE_HP_float128 := $82,DW_ATE_HP_complex_float128 := $83,
  428. DW_ATE_HP_floathpintel := $84,DW_ATE_HP_imaginary_float80 := $85,
  429. DW_ATE_HP_imaginary_float128 := $86
  430. );
  431. const
  432. DW_ATE_lo_user = $80;
  433. DW_ATE_hi_user = $ff;
  434. type
  435. Tdwarf_array_dim_ordering = (DW_ORD_row_major := 0,DW_ORD_col_major := 1
  436. );
  437. { Access attribute. }
  438. Tdwarf_access_attribute = (DW_ACCESS_public := 1,DW_ACCESS_protected := 2,
  439. DW_ACCESS_private := 3);
  440. { Visibility. }
  441. Tdwarf_visibility_attribute = (DW_VIS_local := 1,DW_VIS_exported := 2,
  442. DW_VIS_qualified := 3);
  443. { Virtuality. }
  444. Tdwarf_virtuality_attribute = (DW_VIRTUALITY_none := 0,DW_VIRTUALITY_virtual := 1,
  445. DW_VIRTUALITY_pure_virtual := 2);
  446. { Case sensitivity. }
  447. Tdwarf_id_case = (DW_ID_case_sensitive := 0,DW_ID_up_case := 1,
  448. DW_ID_down_case := 2,DW_ID_case_insensitive := 3
  449. );
  450. { Calling convention. }
  451. Tdwarf_calling_convention = (DW_CC_normal := $1,DW_CC_program := $2,
  452. DW_CC_nocall := $3,DW_CC_GNU_renesas_sh := $40, DW_CC_GNU_borland_fastcall_i386 := $41
  453. );
  454. {$notes off}
  455. { Location atom names and codes. }
  456. Tdwarf_location_atom = (DW_OP_addr := $03,DW_OP_deref := $06,DW_OP_const1u := $08,
  457. DW_OP_const1s := $09,DW_OP_const2u := $0a,
  458. DW_OP_const2s := $0b,DW_OP_const4u := $0c,
  459. DW_OP_const4s := $0d,DW_OP_const8u := $0e,
  460. DW_OP_const8s := $0f,DW_OP_constu := $10,
  461. DW_OP_consts := $11,DW_OP_dup := $12,DW_OP_drop := $13,
  462. DW_OP_over := $14,DW_OP_pick := $15,DW_OP_swap := $16,
  463. DW_OP_rot := $17,DW_OP_xderef := $18,DW_OP_abs := $19,
  464. DW_OP_and := $1a,DW_OP_div := $1b,DW_OP_minus := $1c,
  465. DW_OP_mod := $1d,DW_OP_mul := $1e,DW_OP_neg := $1f,
  466. DW_OP_not := $20,DW_OP_or := $21,DW_OP_plus := $22,
  467. DW_OP_plus_uconst := $23,DW_OP_shl := $24,
  468. DW_OP_shr := $25,DW_OP_shra := $26,DW_OP_xor := $27,
  469. DW_OP_bra := $28,DW_OP_eq := $29,DW_OP_ge := $2a,
  470. DW_OP_gt := $2b,DW_OP_le := $2c,DW_OP_lt := $2d,
  471. DW_OP_ne := $2e,DW_OP_skip := $2f,DW_OP_lit0 := $30,
  472. DW_OP_lit1 := $31,DW_OP_lit2 := $32,DW_OP_lit3 := $33,
  473. DW_OP_lit4 := $34,DW_OP_lit5 := $35,DW_OP_lit6 := $36,
  474. DW_OP_lit7 := $37,DW_OP_lit8 := $38,DW_OP_lit9 := $39,
  475. DW_OP_lit10 := $3a,DW_OP_lit11 := $3b,
  476. DW_OP_lit12 := $3c,DW_OP_lit13 := $3d,
  477. DW_OP_lit14 := $3e,DW_OP_lit15 := $3f,
  478. DW_OP_lit16 := $40,DW_OP_lit17 := $41,
  479. DW_OP_lit18 := $42,DW_OP_lit19 := $43,
  480. DW_OP_lit20 := $44,DW_OP_lit21 := $45,
  481. DW_OP_lit22 := $46,DW_OP_lit23 := $47,
  482. DW_OP_lit24 := $48,DW_OP_lit25 := $49,
  483. DW_OP_lit26 := $4a,DW_OP_lit27 := $4b,
  484. DW_OP_lit28 := $4c,DW_OP_lit29 := $4d,
  485. DW_OP_lit30 := $4e,DW_OP_lit31 := $4f,
  486. DW_OP_reg0 := $50,DW_OP_reg1 := $51,DW_OP_reg2 := $52,
  487. DW_OP_reg3 := $53,DW_OP_reg4 := $54,DW_OP_reg5 := $55,
  488. DW_OP_reg6 := $56,DW_OP_reg7 := $57,DW_OP_reg8 := $58,
  489. DW_OP_reg9 := $59,DW_OP_reg10 := $5a,DW_OP_reg11 := $5b,
  490. DW_OP_reg12 := $5c,DW_OP_reg13 := $5d,
  491. DW_OP_reg14 := $5e,DW_OP_reg15 := $5f,
  492. DW_OP_reg16 := $60,DW_OP_reg17 := $61,
  493. DW_OP_reg18 := $62,DW_OP_reg19 := $63,
  494. DW_OP_reg20 := $64,DW_OP_reg21 := $65,
  495. DW_OP_reg22 := $66,DW_OP_reg23 := $67,
  496. DW_OP_reg24 := $68,DW_OP_reg25 := $69,
  497. DW_OP_reg26 := $6a,DW_OP_reg27 := $6b,
  498. DW_OP_reg28 := $6c,DW_OP_reg29 := $6d,
  499. DW_OP_reg30 := $6e,DW_OP_reg31 := $6f,
  500. DW_OP_breg0 := $70,DW_OP_breg1 := $71,
  501. DW_OP_breg2 := $72,DW_OP_breg3 := $73,
  502. DW_OP_breg4 := $74,DW_OP_breg5 := $75,
  503. DW_OP_breg6 := $76,DW_OP_breg7 := $77,
  504. DW_OP_breg8 := $78,DW_OP_breg9 := $79,
  505. DW_OP_breg10 := $7a,DW_OP_breg11 := $7b,
  506. DW_OP_breg12 := $7c,DW_OP_breg13 := $7d,
  507. DW_OP_breg14 := $7e,DW_OP_breg15 := $7f,
  508. DW_OP_breg16 := $80,DW_OP_breg17 := $81,
  509. DW_OP_breg18 := $82,DW_OP_breg19 := $83,
  510. DW_OP_breg20 := $84,DW_OP_breg21 := $85,
  511. DW_OP_breg22 := $86,DW_OP_breg23 := $87,
  512. DW_OP_breg24 := $88,DW_OP_breg25 := $89,
  513. DW_OP_breg26 := $8a,DW_OP_breg27 := $8b,
  514. DW_OP_breg28 := $8c,DW_OP_breg29 := $8d,
  515. DW_OP_breg30 := $8e,DW_OP_breg31 := $8f,
  516. DW_OP_regx := $90,DW_OP_fbreg := $91,DW_OP_bregx := $92,
  517. DW_OP_piece := $93,DW_OP_deref_size := $94,
  518. DW_OP_xderef_size := $95,DW_OP_nop := $96,
  519. { DWARF 3 extensions. }
  520. DW_OP_push_object_address := $97,DW_OP_call2 := $98,
  521. DW_OP_call4 := $99,DW_OP_call_ref := $9a,
  522. { DWARF 4 extensions. }
  523. DW_OP_implicit_value := $9e, DW_OP_stack_value := $9f,
  524. { GNU extensions. }
  525. DW_OP_GNU_push_tls_address := $e0,
  526. { HP extensions. }
  527. DW_OP_HP_unknown := $e0,
  528. DW_OP_HP_is_value := $e1,DW_OP_HP_fltconst4 := $e2,
  529. DW_OP_HP_fltconst8 := $e3,DW_OP_HP_mod_range := $e4,
  530. DW_OP_HP_unmod_range := $e5,DW_OP_HP_tls := $e6
  531. );
  532. {$notes on}
  533. const
  534. { Implementation-defined range start. }
  535. DW_OP_lo_user = $e0;
  536. { Implementation-defined range end. }
  537. DW_OP_hi_user = $ff;
  538. const
  539. DW_LNS_extended_op = $00;
  540. { next copied from cfidwarf, need to go to something shared }
  541. DW_LNS_copy = $01;
  542. DW_LNS_advance_pc = $02;
  543. DW_LNS_advance_line = $03;
  544. DW_LNS_set_file = $04;
  545. DW_LNS_set_column = $05;
  546. DW_LNS_negate_stmt = $06;
  547. DW_LNS_set_basic_block = $07;
  548. DW_LNS_const_add_pc = $08;
  549. DW_LNS_fixed_advance_pc = $09;
  550. DW_LNS_set_prologue_end = $0a;
  551. DW_LNS_set_epilogue_begin = $0b;
  552. DW_LNS_set_isa = $0c;
  553. DW_LNE_end_sequence = $01;
  554. DW_LNE_set_address = $02;
  555. DW_LNE_define_file = $03;
  556. DW_LNE_lo_user = $80;
  557. DW_LNE_hi_user = $ff;
  558. type
  559. { TDirIndexItem }
  560. TDirIndexItem = class(TFPHashObject)
  561. private
  562. FFiles: TFPHashObjectList;
  563. public
  564. IndexNr : Integer;
  565. constructor Create(AList:TFPHashObjectList;const AName: String; AIndex: Integer);
  566. destructor Destroy;override;
  567. property Files: TFPHashObjectList read FFiles;
  568. end;
  569. { TFileIndexItem }
  570. TFileIndexItem = class(TFPHashObject)
  571. private
  572. FDirIndex: Integer;
  573. public
  574. IndexNr : Integer;
  575. constructor Create(AList:TFPHashObjectList;const AName: String; ADirIndex, AIndex: Integer);
  576. property DirIndex: Integer read FDirIndex;
  577. end;
  578. {****************************************************************************
  579. procs
  580. ****************************************************************************}
  581. function DirListSortCompare(AItem1, AItem2: Pointer): Integer;
  582. begin
  583. Result := TDirIndexItem(AItem1).IndexNr - TDirIndexItem(AItem2).IndexNr;
  584. end;
  585. function FileListSortCompare(AItem1, AItem2: Pointer): Integer;
  586. begin
  587. Result := TFileIndexItem(AItem1).IndexNr - TFileIndexItem(AItem2).IndexNr;
  588. end;
  589. function AllocateNewAiSearchItem: pAbbrevSearchTreeItem;
  590. begin
  591. new(result);
  592. FillChar(result^,sizeof(result^),#0);
  593. end;
  594. procedure FreeSearchItem(SI: pAbbrevSearchTreeItem);
  595. begin
  596. if assigned(SI^.NextItem) then
  597. FreeSearchItem(SI^.NextItem);
  598. if assigned(SI^.SearchItem) then
  599. FreeSearchItem(SI^.SearchItem);
  600. Dispose(SI);
  601. end;
  602. {****************************************************************************
  603. TDirIndexItem
  604. ****************************************************************************}
  605. constructor TDirIndexItem.Create(AList:TFPHashObjectList;const AName: String; AIndex: Integer);
  606. begin
  607. inherited Create(AList,AName);
  608. FFiles := TFPHashObjectList.Create;
  609. IndexNr := AIndex;
  610. end;
  611. destructor TDirIndexItem.Destroy;
  612. begin
  613. FFiles.Free;
  614. inherited Destroy;
  615. end;
  616. {****************************************************************************
  617. TFileIndexItem
  618. ****************************************************************************}
  619. constructor TFileIndexItem.Create(AList:TFPHashObjectList;const AName: String; ADirIndex, AIndex: Integer);
  620. begin
  621. inherited Create(AList,Aname);
  622. FDirIndex := ADirIndex;
  623. IndexNr := AIndex;
  624. end;
  625. {****************************************************************************
  626. TDebugInfoDwarf
  627. ****************************************************************************}
  628. procedure TDebugInfoDwarf.StartAbbrevSearch;
  629. begin
  630. CurrentSearchTreeItem:=AbbrevSearchTree;
  631. end;
  632. procedure TDebugInfoDwarf.WriteSearchItemToAbbrevSection(SI: pAbbrevSearchTreeItem);
  633. begin
  634. if SI^.bit8 then
  635. current_asmdata.asmlists[al_dwarf_abbrev].concat(tai_const.Create_8bit(SI^.value))
  636. else
  637. current_asmdata.asmlists[al_dwarf_abbrev].concat(tai_const.Create_uleb128bit(SI^.value));
  638. end;
  639. procedure TDebugInfoDwarf.StartAbbrevSectionFromSearchtree;
  640. procedure AddCurrentAndPriorItemsToAbrev(SI: pAbbrevSearchTreeItem);
  641. begin
  642. if assigned(SI^.PriorItem) then
  643. AddCurrentAndPriorItemsToAbrev(SI^.PriorItem);
  644. WriteSearchItemToAbbrevSection(SI);
  645. end;
  646. begin
  647. NewAbbrev:=true;
  648. inc(currabbrevnumber);
  649. current_asmdata.asmlists[al_dwarf_abbrev].concat(tai_comment.Create(strpnew('Abbrev '+tostr(currabbrevnumber))));
  650. current_asmdata.asmlists[al_dwarf_abbrev].concat(tai_const.create_uleb128bit(currabbrevnumber));
  651. if CurrentSearchTreeItem<>AbbrevSearchTree then
  652. AddCurrentAndPriorItemsToAbrev(CurrentSearchTreeItem);
  653. end;
  654. function TDebugInfoDwarf.FinishAbbrevSearch: longint;
  655. procedure FinalizeAbbrevSection;
  656. begin
  657. current_asmdata.asmlists[al_dwarf_abbrev].concat(tai_const.create_8bit(0));
  658. current_asmdata.asmlists[al_dwarf_abbrev].concat(tai_const.create_8bit(0));
  659. CurrentSearchTreeItem^.Abbrev:=currabbrevnumber;
  660. NewAbbrev := false;
  661. end;
  662. begin
  663. if NewAbbrev then
  664. FinalizeAbbrevSection;
  665. result := CurrentSearchTreeItem^.Abbrev;
  666. if result=0 then
  667. begin
  668. // In this case the abbrev-section equals an existing longer abbrev section.
  669. // So a new abbrev-section has to be made which ends on the current
  670. // searchtree item
  671. StartAbbrevSectionFromSearchtree;
  672. FinalizeAbbrevSection;
  673. result := CurrentSearchTreeItem^.Abbrev;
  674. end;
  675. end;
  676. procedure TDebugInfoDwarf.AddConstToAbbrev(Value: QWord; bit8:boolean);
  677. procedure AddCurrentItemToAbbrev;
  678. begin
  679. CurrentSearchTreeItem^.value:=value;
  680. CurrentSearchTreeItem^.bit8:=bit8;
  681. WriteSearchItemToAbbrevSection(CurrentSearchTreeItem);
  682. end;
  683. var si: pAbbrevSearchTreeItem;
  684. begin
  685. // Instead of adding this value directly to the ai-tree, search if an
  686. // abbrev section with the same values already exist, and use the existing
  687. // one or create one.
  688. if NewAbbrev then
  689. begin
  690. // The current abbrev-section is new, so add the value to the abbrev-section
  691. // and add it to the search-list.
  692. CurrentSearchTreeItem^.NextItem:=AllocateNewAiSearchItem;
  693. CurrentSearchTreeItem^.NextItem^.PriorItem:=CurrentSearchTreeItem;
  694. CurrentSearchTreeItem := CurrentSearchTreeItem^.NextItem;
  695. AddCurrentItemToAbbrev;
  696. end
  697. else
  698. begin
  699. // Search for the value which is added in the next sections of the
  700. // searchtree for a match
  701. si := CurrentSearchTreeItem^.NextItem;
  702. while assigned(si) do
  703. begin
  704. if (SI^.value=Value) and (si^.bit8=bit8) then
  705. begin
  706. // If a match is found, set the current searchtree item to the next item
  707. CurrentSearchTreeItem:=SI;
  708. Exit;
  709. end
  710. else if si^.SearchItem=nil then
  711. begin
  712. // If no match is found, add a new item to the searchtree and write
  713. // a new abbrev-section.
  714. StartAbbrevSectionFromSearchtree;
  715. si^.SearchItem:=AllocateNewAiSearchItem;
  716. if currentsearchtreeitem<>AbbrevSearchTree then
  717. si^.SearchItem^.PriorItem:=CurrentSearchTreeItem;
  718. CurrentSearchTreeItem := si^.SearchItem;
  719. AddCurrentItemToAbbrev;
  720. Exit;
  721. end;
  722. Si := SI^.SearchItem;
  723. end;
  724. // The abbrev section we are looking for is longer than the one
  725. // which is already in the search-tree. So expand the searchtree with
  726. // the new value and write a new abbrev section
  727. StartAbbrevSectionFromSearchtree;
  728. CurrentSearchTreeItem^.NextItem:=AllocateNewAiSearchItem;
  729. if currentsearchtreeitem^.PriorItem<>AbbrevSearchTree then
  730. CurrentSearchTreeItem^.NextItem^.PriorItem:=CurrentSearchTreeItem;
  731. CurrentSearchTreeItem := CurrentSearchTreeItem^.NextItem;
  732. AddCurrentItemToAbbrev;
  733. end;
  734. end;
  735. function TDebugInfoDwarf.relative_dwarf_path(const s:tcmdstr):tcmdstr;
  736. begin
  737. { Make a clean path for gdb. Remove trailing / and ./ prefixes and
  738. use always a / }
  739. result:=BsToSlash(ExcludeTrailingPathDelimiter(ExtractRelativePath(GetCurrentDir,FixFileName(ExpandFileName(s)))));
  740. end;
  741. procedure TDebugInfoDwarf.set_use_64bit_headers(state: boolean);
  742. begin
  743. _use_64bit_headers:=state;
  744. if not(state) then
  745. begin
  746. if (target_info.system in systems_windows+systems_wince) then
  747. offsetabstype:=aitconst_secrel32_symbol
  748. else
  749. offsetabstype:=aitconst_32bit;
  750. if (target_info.system in systems_darwin) then
  751. offsetreltype:=aitconst_darwin_dwarf_delta32
  752. else
  753. offsetreltype:=aitconst_32bit;
  754. end
  755. else
  756. begin
  757. if (target_info.system in systems_darwin) then
  758. offsetreltype:=aitconst_darwin_dwarf_delta64
  759. else
  760. offsetreltype:=aitconst_64bit;
  761. offsetabstype:=aitconst_64bit;
  762. end;
  763. end;
  764. procedure TDebugInfoDwarf.set_def_dwarf_labs(def:tdef);
  765. begin
  766. { Keep track of used dwarf entries, this info is only useful for dwarf entries
  767. referenced by the symbols. Definitions will always include all
  768. required stabs }
  769. if def.dbg_state=dbg_state_unused then
  770. def.dbg_state:=dbg_state_used;
  771. { Need a new label? }
  772. if not assigned(def.dwarf_lab) then
  773. begin
  774. if not(tf_dwarf_only_local_labels in target_info.flags) then
  775. begin
  776. if (ds_dwarf_dbg_info_written in def.defstates) then
  777. begin
  778. if not assigned(def.typesym) then
  779. internalerror(200610011);
  780. def.dwarf_lab:=current_asmdata.RefAsmSymbol(make_mangledname('DBG',def.owner,symname(def.typesym)));
  781. def.dwarf_ref_lab:=current_asmdata.RefAsmSymbol(make_mangledname('DBGREF',def.owner,symname(def.typesym)));
  782. if is_class_or_interface_or_dispinterface(def) then
  783. tobjectdef(def).dwarf_struct_lab:=current_asmdata.RefAsmSymbol(make_mangledname('DBG2',def.owner,symname(def.typesym)));
  784. def.dbg_state:=dbg_state_written;
  785. end
  786. else
  787. begin
  788. { Create an exported DBG symbol if we are generating a def defined in the
  789. globalsymtable of the current unit }
  790. if assigned(def.typesym) and
  791. (def.owner.symtabletype=globalsymtable) and
  792. (def.owner.iscurrentunit) then
  793. begin
  794. def.dwarf_lab:=current_asmdata.DefineAsmSymbol(make_mangledname('DBG',def.owner,symname(def.typesym)),AB_GLOBAL,AT_DATA);
  795. def.dwarf_ref_lab:=current_asmdata.DefineAsmSymbol(make_mangledname('DBGREF',def.owner,symname(def.typesym)),AB_GLOBAL,AT_DATA);
  796. if is_class_or_interface_or_dispinterface(def) then
  797. tobjectdef(def).dwarf_struct_lab:=current_asmdata.DefineAsmSymbol(make_mangledname('DBG2',def.owner,symname(def.typesym)),AB_GLOBAL,AT_DATA);
  798. include(def.defstates,ds_dwarf_dbg_info_written);
  799. end
  800. else
  801. begin
  802. { The pointer typecast is needed to prevent a problem with range checking
  803. on when the typecast is changed to 'as' }
  804. current_asmdata.getdatalabel(TAsmLabel(pointer(def.dwarf_lab)));
  805. current_asmdata.getdatalabel(TAsmLabel(pointer(def.dwarf_ref_lab)));
  806. if is_implicit_pointer_object_type(def) then
  807. current_asmdata.getdatalabel(TAsmLabel(pointer(tobjectdef(def).dwarf_struct_lab)));
  808. end;
  809. end;
  810. end
  811. else
  812. begin
  813. { The pointer typecast is needed to prevent a problem with range checking
  814. on when the typecast is changed to 'as' }
  815. { addrlabel instead of datalabel because it must be a local one }
  816. current_asmdata.getaddrlabel(TAsmLabel(pointer(def.dwarf_lab)));
  817. current_asmdata.getaddrlabel(TAsmLabel(pointer(def.dwarf_ref_lab)));
  818. if is_implicit_pointer_object_type(def) then
  819. current_asmdata.getaddrlabel(TAsmLabel(pointer(tobjectdef(def).dwarf_struct_lab)));
  820. end;
  821. if def.dbg_state=dbg_state_used then
  822. deftowritelist.Add(def);
  823. defnumberlist.Add(def);
  824. end;
  825. end;
  826. function TDebugInfoDwarf.def_dwarf_lab(def: tdef): tasmsymbol;
  827. begin
  828. set_def_dwarf_labs(def);
  829. result:=def.dwarf_lab;
  830. end;
  831. function TDebugInfoDwarf.def_dwarf_class_struct_lab(def: tobjectdef): tasmsymbol;
  832. begin
  833. set_def_dwarf_labs(def);
  834. result:=def.dwarf_struct_lab;
  835. end;
  836. function TDebugInfoDwarf.def_dwarf_ref_lab(def: tdef): tasmsymbol;
  837. begin
  838. set_def_dwarf_labs(def);
  839. result:=def.dwarf_ref_lab;
  840. end;
  841. constructor TDebugInfoDwarf.Create;
  842. begin
  843. inherited Create;
  844. { 64bit headers are only supported for dwarf3 and up, so default off }
  845. use_64bit_headers := false;
  846. { we haven't generated any lineinfo yet }
  847. generated_lineinfo := false;
  848. dirlist := TFPHashObjectList.Create;
  849. { add current dir as first item (index=0) }
  850. TDirIndexItem.Create(dirlist,'.', 0);
  851. asmline := TAsmList.create;
  852. loclist := tdynamicarray.Create(4096);
  853. AbbrevSearchTree:=AllocateNewAiSearchItem;
  854. vardatadef := nil;
  855. end;
  856. destructor TDebugInfoDwarf.Destroy;
  857. begin
  858. dirlist.Free;
  859. if assigned(AbbrevSearchTree) then
  860. FreeSearchItem(AbbrevSearchTree);
  861. dirlist := nil;
  862. asmline.free;
  863. asmline:=nil;
  864. loclist.Free;
  865. loclist := nil;
  866. inherited Destroy;
  867. end;
  868. procedure TDebugInfoDwarf.enum_membersyms_callback(p:TObject; arg: pointer);
  869. begin
  870. case tsym(p).typ of
  871. fieldvarsym:
  872. appendsym_fieldvar(TAsmList(arg),tfieldvarsym(p));
  873. propertysym:
  874. appendsym_property(TAsmList(arg),tpropertysym(p));
  875. constsym:
  876. appendsym_const_member(TAsmList(arg),tconstsym(p),true);
  877. end;
  878. end;
  879. function TDebugInfoDwarf.get_file_index(afile: tinputfile): Integer;
  880. var
  881. dirname: String;
  882. diritem: TDirIndexItem;
  883. diridx: Integer;
  884. fileitem: TFileIndexItem;
  885. begin
  886. if afile.path^ = '' then
  887. dirname := '.'
  888. else
  889. begin
  890. { add the canonical form here already to avoid problems with }
  891. { paths such as './' etc }
  892. dirname := relative_dwarf_path(afile.path^);
  893. if dirname = '' then
  894. dirname := '.';
  895. end;
  896. diritem := TDirIndexItem(dirlist.Find(dirname));
  897. if diritem = nil then
  898. diritem := TDirIndexItem.Create(dirlist,dirname, dirlist.Count);
  899. diridx := diritem.IndexNr;
  900. fileitem := TFileIndexItem(diritem.files.Find(afile.name^));
  901. if fileitem = nil then
  902. begin
  903. Inc(filesequence);
  904. fileitem := TFileIndexItem.Create(diritem.files,afile.name^, diridx, filesequence);
  905. end;
  906. Result := fileitem.IndexNr;
  907. end;
  908. procedure TDebugInfoDwarf.append_attribute(attr: tdwarf_attribute; form: tdwarf_form; const values: array of const);
  909. begin
  910. if length(values)<>1 then
  911. internalerror(2009040402);
  912. append_attribute(attr,form,values[0]);
  913. end;
  914. procedure TDebugInfoDwarf.append_attribute(attr: tdwarf_attribute; form: tdwarf_form; const value: tvarrec);
  915. begin
  916. { attribute }
  917. AddConstToAbbrev(cardinal(attr));
  918. { form }
  919. AddConstToAbbrev(cardinal(form));
  920. { info itself }
  921. case form of
  922. DW_FORM_string:
  923. case value.VType of
  924. vtChar:
  925. current_asmdata.asmlists[al_dwarf_info].concat(tai_string.create(value.VChar));
  926. vtString:
  927. current_asmdata.asmlists[al_dwarf_info].concat(tai_string.create(value.VString^));
  928. vtAnsistring:
  929. current_asmdata.asmlists[al_dwarf_info].concat(tai_string.create(Ansistring(value.VAnsiString)));
  930. else
  931. internalerror(200601264);
  932. end;
  933. DW_FORM_flag:
  934. current_asmdata.asmlists[al_dwarf_info].concat(tai_const.create_8bit(byte(value.VBoolean)));
  935. DW_FORM_data1:
  936. case value.VType of
  937. vtInteger:
  938. current_asmdata.asmlists[al_dwarf_info].concat(tai_const.create_8bit(value.VInteger));
  939. vtInt64:
  940. current_asmdata.asmlists[al_dwarf_info].concat(tai_const.create_8bit(value.VInt64^));
  941. vtQWord:
  942. current_asmdata.asmlists[al_dwarf_info].concat(tai_const.create_8bit(value.VQWord^));
  943. else
  944. internalerror(200602143);
  945. end;
  946. DW_FORM_data2:
  947. case value.VType of
  948. vtInteger:
  949. current_asmdata.asmlists[al_dwarf_info].concat(tai_const.create_16bit(value.VInteger));
  950. vtInt64:
  951. current_asmdata.asmlists[al_dwarf_info].concat(tai_const.create_16bit(value.VInt64^));
  952. vtQWord:
  953. current_asmdata.asmlists[al_dwarf_info].concat(tai_const.create_16bit(value.VQWord^));
  954. else
  955. internalerror(200602144);
  956. end;
  957. DW_FORM_data4:
  958. case value.VType of
  959. vtInteger:
  960. current_asmdata.asmlists[al_dwarf_info].concat(tai_const.create_32bit(value.VInteger));
  961. vtInt64:
  962. current_asmdata.asmlists[al_dwarf_info].concat(tai_const.create_32bit(value.VInt64^));
  963. vtQWord:
  964. current_asmdata.asmlists[al_dwarf_info].concat(tai_const.create_32bit(value.VQWord^));
  965. else
  966. internalerror(200602145);
  967. end;
  968. DW_FORM_data8:
  969. case value.VType of
  970. vtInteger:
  971. current_asmdata.asmlists[al_dwarf_info].concat(tai_const.create_64bit(value.VInteger));
  972. vtInt64:
  973. current_asmdata.asmlists[al_dwarf_info].concat(tai_const.create_64bit(value.VInt64^));
  974. vtQWord:
  975. current_asmdata.asmlists[al_dwarf_info].concat(tai_const.create_64bit(value.VQWord^));
  976. else
  977. internalerror(200602146);
  978. end;
  979. DW_FORM_sdata:
  980. case value.VType of
  981. vtInteger:
  982. current_asmdata.asmlists[al_dwarf_info].concat(tai_const.create_sleb128bit(value.VInteger));
  983. vtInt64:
  984. current_asmdata.asmlists[al_dwarf_info].concat(tai_const.create_sleb128bit(value.VInt64^));
  985. vtQWord:
  986. current_asmdata.asmlists[al_dwarf_info].concat(tai_const.create_sleb128bit(value.VQWord^));
  987. else
  988. internalerror(200601285);
  989. end;
  990. DW_FORM_udata:
  991. case value.VType of
  992. vtInteger:
  993. current_asmdata.asmlists[al_dwarf_info].concat(tai_const.create_uleb128bit(value.VInteger));
  994. vtInt64:
  995. current_asmdata.asmlists[al_dwarf_info].concat(tai_const.create_uleb128bit(value.VInt64^));
  996. vtQWord:
  997. current_asmdata.asmlists[al_dwarf_info].concat(tai_const.create_uleb128bit(value.VQWord^));
  998. else
  999. internalerror(200601284);
  1000. end;
  1001. { block gets only the size, the rest is appended manually by the caller }
  1002. DW_FORM_block1:
  1003. case value.VType of
  1004. vtInteger:
  1005. current_asmdata.asmlists[al_dwarf_info].concat(tai_const.create_8bit(value.VInteger));
  1006. vtInt64:
  1007. current_asmdata.asmlists[al_dwarf_info].concat(tai_const.create_8bit(value.VInt64^));
  1008. vtQWord:
  1009. current_asmdata.asmlists[al_dwarf_info].concat(tai_const.create_8bit(value.VQWord^));
  1010. else
  1011. internalerror(200602141);
  1012. end;
  1013. else
  1014. internalerror(200601263);
  1015. end;
  1016. end;
  1017. { writing the data through a few simply procedures allows to create easily extra information
  1018. for debugging of debug info }
  1019. procedure TDebugInfoDwarf.append_entry(tag : tdwarf_tag;has_children : boolean;data : array of const);
  1020. var
  1021. i : longint;
  1022. begin
  1023. { abbrev number }
  1024. // Store the ai with the reference to the abbrev number and start a search
  1025. // to find the right abbrev-section. (Or create one)
  1026. dwarf_info_abbref_tai := tai_const.create_uleb128bit(currabbrevnumber);
  1027. current_asmdata.asmlists[al_dwarf_info].concat(dwarf_info_abbref_tai);
  1028. StartAbbrevSearch;
  1029. { tag }
  1030. AddConstToAbbrev(ord(tag));
  1031. { children? }
  1032. AddConstToAbbrev(ord(has_children),true);
  1033. i:=0;
  1034. while i<=high(data) do
  1035. begin
  1036. if (i+2 > high(data)) then
  1037. internalerror(2009040401);
  1038. if data[i].VType<>vtInteger then
  1039. internalerror(200601261);
  1040. if data[i+1].VType<>vtInteger then
  1041. internalerror(200601261);
  1042. append_attribute(tdwarf_attribute(data[i].VInteger),tdwarf_form(data[i+1].VInteger),data[i+2]);
  1043. inc(i,3);
  1044. end;
  1045. end;
  1046. procedure TDebugInfoDwarf.append_block1(attr: tdwarf_attribute; size: aint);
  1047. begin
  1048. AddConstToAbbrev(ord(attr));
  1049. AddConstToAbbrev(ord(DW_FORM_block1));
  1050. current_asmdata.asmlists[al_dwarf_info].concat(tai_const.create_8bit(size));
  1051. end;
  1052. procedure TDebugInfoDwarf.append_labelentry(attr : tdwarf_attribute;sym : tasmsymbol);
  1053. begin
  1054. AddConstToAbbrev(ord(attr));
  1055. AddConstToAbbrev(ord(DW_FORM_addr));
  1056. current_asmdata.asmlists[al_dwarf_info].concat(tai_const.create_sym(sym));
  1057. end;
  1058. procedure TDebugInfoDwarf.append_labelentry_addr_ref(attr : tdwarf_attribute;sym : tasmsymbol);
  1059. begin
  1060. AddConstToAbbrev(ord(DW_FORM_ref_addr));
  1061. current_asmdata.asmlists[al_dwarf_info].concat(tai_const.create_sym(sym))
  1062. end;
  1063. procedure TDebugInfoDwarf.append_labelentry_ref(attr : tdwarf_attribute;sym : tasmsymbol);
  1064. begin
  1065. AddConstToAbbrev(ord(attr));
  1066. if not(tf_dwarf_only_local_labels in target_info.flags) then
  1067. append_labelentry_addr_ref(attr, sym)
  1068. else
  1069. begin
  1070. AddConstToAbbrev(ord(DW_FORM_ref4));
  1071. current_asmdata.asmlists[al_dwarf_info].concat(tai_const.create_rel_sym(offsetreltype,current_asmdata.RefAsmSymbol(target_asm.labelprefix+'debug_info0'),sym));
  1072. end;
  1073. end;
  1074. procedure TDebugInfoDwarf.append_labelentry_dataptr_common(attr : tdwarf_attribute);
  1075. begin
  1076. AddConstToAbbrev(ord(attr));
  1077. if use_64bit_headers then
  1078. AddConstToAbbrev(ord(DW_FORM_data8))
  1079. else
  1080. AddConstToAbbrev(ord(DW_FORM_data4));
  1081. end;
  1082. procedure TDebugInfoDwarf.append_labelentry_dataptr_abs(attr : tdwarf_attribute;sym : tasmsymbol);
  1083. begin
  1084. {
  1085. used for writing dwarf lineptr, loclistptr, macptr and rangelistptr classes as FORM_dataN
  1086. The size of these depend on the header format
  1087. Must be relative to another symbol on tf_dwarf_relative_addresses
  1088. targets
  1089. }
  1090. if (tf_dwarf_relative_addresses in target_info.flags) then
  1091. { use append_labelentry_dataptr_rel instead }
  1092. internalerror(2007020210);
  1093. append_labelentry_dataptr_common(attr);
  1094. current_asmdata.asmlists[al_dwarf_info].concat(tai_const.create_type_sym(offsetabstype,sym))
  1095. end;
  1096. procedure TDebugInfoDwarf.append_labelentry_dataptr_rel(attr : tdwarf_attribute;sym,endsym : tasmsymbol);
  1097. begin
  1098. {
  1099. used for writing dwarf lineptr, loclistptr, macptr and rangelistptr classes as FORM_dataN
  1100. The size of these depend on the header format
  1101. Must be relative to another symbol on tf_dwarf_relative_addresses
  1102. targets
  1103. }
  1104. append_labelentry_dataptr_common(attr);
  1105. current_asmdata.asmlists[al_dwarf_info].concat(tai_const.create_rel_sym(offsetreltype,sym,endsym));
  1106. end;
  1107. procedure TDebugInfoDwarf.finish_entry;
  1108. begin
  1109. dwarf_info_abbref_tai.value:=FinishAbbrevSearch;
  1110. end;
  1111. procedure TDebugInfoDwarf.finish_children;
  1112. begin
  1113. current_asmdata.asmlists[al_dwarf_info].concat(tai_const.create_8bit(0));
  1114. end;
  1115. procedure TDebugInfoDwarf.appenddef_ord(list:TAsmList;def:torddef);
  1116. var
  1117. basedef : tdef;
  1118. sign : tdwarf_type;
  1119. signform : tdwarf_form;
  1120. fullbytesize : byte;
  1121. begin
  1122. case def.ordtype of
  1123. s8bit,
  1124. s16bit,
  1125. s32bit,
  1126. u8bit,
  1127. u16bit,
  1128. u32bit :
  1129. begin
  1130. { generate proper signed/unsigned info for types like 0..3 }
  1131. { these are s8bit, but should be identified as unsigned }
  1132. { because otherwise they are interpreted wrongly when used }
  1133. { in a bitpacked record }
  1134. if (def.low<0) then
  1135. begin
  1136. sign:=DW_ATE_signed;
  1137. signform:=DW_FORM_sdata
  1138. end
  1139. else
  1140. begin
  1141. sign:=DW_ATE_unsigned;
  1142. signform:=DW_FORM_udata
  1143. end;
  1144. fullbytesize:=def.size;
  1145. case fullbytesize of
  1146. 1:
  1147. if (sign=DW_ATE_signed) then
  1148. basedef:=s8inttype
  1149. else
  1150. basedef:=u8inttype;
  1151. 2:
  1152. if (sign=DW_ATE_signed) then
  1153. basedef:=s16inttype
  1154. else
  1155. basedef:=u16inttype;
  1156. 4:
  1157. if (sign=DW_ATE_signed) then
  1158. basedef:=s32inttype
  1159. else
  1160. basedef:=u32inttype;
  1161. else
  1162. internalerror(2008032201);
  1163. end;
  1164. if (def.low=torddef(basedef).low) and
  1165. (def.high=torddef(basedef).high) then
  1166. { base type such as byte/shortint/word/... }
  1167. if assigned(def.typesym) then
  1168. append_entry(DW_TAG_base_type,false,[
  1169. DW_AT_name,DW_FORM_string,symname(def.typesym)+#0,
  1170. DW_AT_encoding,DW_FORM_data1,sign,
  1171. DW_AT_byte_size,DW_FORM_data1,fullbytesize])
  1172. else
  1173. append_entry(DW_TAG_base_type,false,[
  1174. DW_AT_encoding,DW_FORM_data1,sign,
  1175. DW_AT_byte_size,DW_FORM_data1,fullbytesize])
  1176. else
  1177. begin
  1178. { subrange type }
  1179. { note: don't do this 64 bit int types, they appear }
  1180. { to be always clipped to s32bit for some reason }
  1181. if assigned(def.typesym) then
  1182. append_entry(DW_TAG_subrange_type,false,[
  1183. DW_AT_name,DW_FORM_string,symname(def.typesym)+#0,
  1184. DW_AT_lower_bound,signform,int64(def.low),
  1185. DW_AT_upper_bound,signform,int64(def.high)
  1186. ])
  1187. else
  1188. append_entry(DW_TAG_subrange_type,false,[
  1189. DW_AT_lower_bound,signform,int64(def.low),
  1190. DW_AT_upper_bound,signform,int64(def.high)
  1191. ]);
  1192. append_labelentry_ref(DW_AT_type,def_dwarf_lab(basedef));
  1193. end;
  1194. finish_entry;
  1195. end;
  1196. uvoid :
  1197. begin
  1198. { gdb 6.4 doesn't support DW_TAG_unspecified_type so we
  1199. replace it with a unsigned type with size 0 (FK)
  1200. }
  1201. append_entry(DW_TAG_base_type,false,[
  1202. DW_AT_name,DW_FORM_string,'Void'#0,
  1203. DW_AT_encoding,DW_FORM_data1,DW_ATE_unsigned,
  1204. DW_AT_byte_size,DW_FORM_data1,0
  1205. ]);
  1206. finish_entry;
  1207. end;
  1208. uchar :
  1209. begin
  1210. append_entry(DW_TAG_base_type,false,[
  1211. DW_AT_name,DW_FORM_string,'Char'#0,
  1212. DW_AT_encoding,DW_FORM_data1,DW_ATE_unsigned_char,
  1213. DW_AT_byte_size,DW_FORM_data1,1
  1214. ]);
  1215. finish_entry;
  1216. end;
  1217. uwidechar :
  1218. begin
  1219. append_entry(DW_TAG_base_type,false,[
  1220. DW_AT_name,DW_FORM_string,'WideChar'#0,
  1221. DW_AT_encoding,DW_FORM_data1,DW_ATE_unsigned_char,
  1222. DW_AT_byte_size,DW_FORM_data1,2
  1223. ]);
  1224. finish_entry;
  1225. end;
  1226. pasbool8 :
  1227. begin
  1228. append_entry(DW_TAG_base_type,false,[
  1229. DW_AT_name,DW_FORM_string,'Boolean'#0,
  1230. DW_AT_encoding,DW_FORM_data1,DW_ATE_boolean,
  1231. DW_AT_byte_size,DW_FORM_data1,1
  1232. ]);
  1233. finish_entry;
  1234. end;
  1235. bool8bit :
  1236. begin
  1237. append_entry(DW_TAG_base_type,false,[
  1238. DW_AT_name,DW_FORM_string,'ByteBool'#0,
  1239. DW_AT_encoding,DW_FORM_data1,DW_ATE_boolean,
  1240. DW_AT_byte_size,DW_FORM_data1,1
  1241. ]);
  1242. finish_entry;
  1243. end;
  1244. pasbool16 :
  1245. begin
  1246. append_entry(DW_TAG_base_type,false,[
  1247. DW_AT_name,DW_FORM_string,'Boolean16'#0,
  1248. DW_AT_encoding,DW_FORM_data1,DW_ATE_boolean,
  1249. DW_AT_byte_size,DW_FORM_data1,2
  1250. ]);
  1251. finish_entry;
  1252. end;
  1253. bool16bit :
  1254. begin
  1255. append_entry(DW_TAG_base_type,false,[
  1256. DW_AT_name,DW_FORM_string,'WordBool'#0,
  1257. DW_AT_encoding,DW_FORM_data1,DW_ATE_boolean,
  1258. DW_AT_byte_size,DW_FORM_data1,2
  1259. ]);
  1260. finish_entry;
  1261. end;
  1262. pasbool32 :
  1263. begin
  1264. append_entry(DW_TAG_base_type,false,[
  1265. DW_AT_name,DW_FORM_string,'Boolean32'#0,
  1266. DW_AT_encoding,DW_FORM_data1,DW_ATE_boolean,
  1267. DW_AT_byte_size,DW_FORM_data1,4
  1268. ]);
  1269. finish_entry;
  1270. end;
  1271. bool32bit :
  1272. begin
  1273. append_entry(DW_TAG_base_type,false,[
  1274. DW_AT_name,DW_FORM_string,'LongBool'#0,
  1275. DW_AT_encoding,DW_FORM_data1,DW_ATE_boolean,
  1276. DW_AT_byte_size,DW_FORM_data1,4
  1277. ]);
  1278. finish_entry;
  1279. end;
  1280. pasbool64 :
  1281. begin
  1282. append_entry(DW_TAG_base_type,false,[
  1283. DW_AT_name,DW_FORM_string,'Boolean64'#0,
  1284. DW_AT_encoding,DW_FORM_data1,DW_ATE_boolean,
  1285. DW_AT_byte_size,DW_FORM_data1,8
  1286. ]);
  1287. finish_entry;
  1288. end;
  1289. bool64bit :
  1290. begin
  1291. append_entry(DW_TAG_base_type,false,[
  1292. DW_AT_name,DW_FORM_string,'QWordBool'#0,
  1293. DW_AT_encoding,DW_FORM_data1,DW_ATE_boolean,
  1294. DW_AT_byte_size,DW_FORM_data1,8
  1295. ]);
  1296. finish_entry;
  1297. end;
  1298. u64bit :
  1299. begin
  1300. append_entry(DW_TAG_base_type,false,[
  1301. DW_AT_name,DW_FORM_string,'QWord'#0,
  1302. DW_AT_encoding,DW_FORM_data1,DW_ATE_unsigned,
  1303. DW_AT_byte_size,DW_FORM_data1,8
  1304. ]);
  1305. finish_entry;
  1306. end;
  1307. scurrency :
  1308. begin
  1309. { we should use DW_ATE_signed_fixed, however it isn't supported yet by GDB (FK) }
  1310. append_entry(DW_TAG_base_type,false,[
  1311. DW_AT_name,DW_FORM_string,'Currency'#0,
  1312. DW_AT_encoding,DW_FORM_data1,DW_ATE_signed,
  1313. DW_AT_byte_size,DW_FORM_data1,8
  1314. ]);
  1315. finish_entry;
  1316. end;
  1317. s64bit :
  1318. begin
  1319. append_entry(DW_TAG_base_type,false,[
  1320. DW_AT_name,DW_FORM_string,'Int64'#0,
  1321. DW_AT_encoding,DW_FORM_data1,DW_ATE_signed,
  1322. DW_AT_byte_size,DW_FORM_data1,8
  1323. ]);
  1324. finish_entry;
  1325. end;
  1326. else
  1327. internalerror(200601287);
  1328. end;
  1329. end;
  1330. procedure TDebugInfoDwarf.appenddef_float(list:TAsmList;def:tfloatdef);
  1331. begin
  1332. case def.floattype of
  1333. s32real,
  1334. s64real,
  1335. s80real,
  1336. sc80real:
  1337. if assigned(def.typesym) then
  1338. begin
  1339. append_entry(DW_TAG_base_type,false,[
  1340. DW_AT_name,DW_FORM_string,symname(def.typesym)+#0,
  1341. DW_AT_encoding,DW_FORM_data1,DW_ATE_float,
  1342. DW_AT_byte_size,DW_FORM_data1,def.size
  1343. ]);
  1344. if (def.floattype in [s80real,sc80real]) and
  1345. (def.size<>10) then
  1346. begin
  1347. append_attribute(DW_AT_bit_size,DW_FORM_data1,[10*8]);
  1348. { "The bit offset attribute describes the offset in bits
  1349. of the high order bit of a value of the given type
  1350. from the high order bit of the storage unit used to
  1351. contain that value." }
  1352. if target_info.endian=endian_little then
  1353. append_attribute(DW_AT_bit_offset,DW_FORM_data1,[(def.size-10)*8]);
  1354. end;
  1355. end
  1356. else
  1357. append_entry(DW_TAG_base_type,false,[
  1358. DW_AT_encoding,DW_FORM_data1,DW_ATE_float,
  1359. DW_AT_byte_size,DW_FORM_data1,def.size
  1360. ]);
  1361. s64currency:
  1362. { we should use DW_ATE_signed_fixed, however it isn't supported yet by GDB (FK) }
  1363. if assigned(def.typesym) then
  1364. append_entry(DW_TAG_base_type,false,[
  1365. DW_AT_name,DW_FORM_string,symname(def.typesym)+#0,
  1366. DW_AT_encoding,DW_FORM_data1,DW_ATE_signed,
  1367. DW_AT_byte_size,DW_FORM_data1,8
  1368. ])
  1369. else
  1370. append_entry(DW_TAG_base_type,false,[
  1371. DW_AT_encoding,DW_FORM_data1,DW_ATE_signed,
  1372. DW_AT_byte_size,DW_FORM_data1,8
  1373. ]);
  1374. s64comp:
  1375. if assigned(def.typesym) then
  1376. append_entry(DW_TAG_base_type,false,[
  1377. DW_AT_name,DW_FORM_string,symname(def.typesym)+#0,
  1378. DW_AT_encoding,DW_FORM_data1,DW_ATE_signed,
  1379. DW_AT_byte_size,DW_FORM_data1,8
  1380. ])
  1381. else
  1382. append_entry(DW_TAG_base_type,false,[
  1383. DW_AT_encoding,DW_FORM_data1,DW_ATE_signed,
  1384. DW_AT_byte_size,DW_FORM_data1,8
  1385. ]);
  1386. else
  1387. internalerror(200601289);
  1388. end;
  1389. finish_entry;
  1390. end;
  1391. procedure TDebugInfoDwarf.appenddef_enum(list:TAsmList;def:tenumdef);
  1392. var
  1393. hp : tenumsym;
  1394. i : integer;
  1395. begin
  1396. if assigned(def.typesym) then
  1397. append_entry(DW_TAG_enumeration_type,true,[
  1398. DW_AT_name,DW_FORM_string,symname(def.typesym)+#0,
  1399. DW_AT_byte_size,DW_FORM_data1,def.size
  1400. ])
  1401. else
  1402. append_entry(DW_TAG_enumeration_type,true,[
  1403. DW_AT_byte_size,DW_FORM_data1,def.size
  1404. ]);
  1405. if assigned(def.basedef) then
  1406. append_labelentry_ref(DW_AT_type,def_dwarf_lab(def.basedef));
  1407. finish_entry;
  1408. { write enum symbols }
  1409. for i := 0 to def.symtable.SymList.Count - 1 do
  1410. begin
  1411. hp:=tenumsym(def.symtable.SymList[i]);
  1412. if hp.value<def.minval then
  1413. continue
  1414. else
  1415. if hp.value>def.maxval then
  1416. break;
  1417. append_entry(DW_TAG_enumerator,false,[
  1418. DW_AT_name,DW_FORM_string,symname(hp)+#0,
  1419. DW_AT_const_value,DW_FORM_data4,hp.value
  1420. ]);
  1421. finish_entry;
  1422. end;
  1423. finish_children;
  1424. end;
  1425. procedure TDebugInfoDwarf.appenddef_array(list:TAsmList;def:tarraydef);
  1426. var
  1427. size : aint;
  1428. elesize : aint;
  1429. elestrideattr : tdwarf_attribute;
  1430. labsym: tasmlabel;
  1431. begin
  1432. if is_dynamic_array(def) then
  1433. begin
  1434. { It's a pointer to the actual array }
  1435. current_asmdata.getaddrlabel(labsym);
  1436. append_entry(DW_TAG_pointer_type,false,[]);
  1437. append_labelentry_ref(DW_AT_type,labsym);
  1438. finish_entry;
  1439. current_asmdata.asmlists[al_dwarf_info].concat(tai_symbol.create(labsym,0));
  1440. end;
  1441. if not is_packed_array(def) then
  1442. begin
  1443. elestrideattr := DW_AT_byte_stride;
  1444. elesize := def.elesize;
  1445. end
  1446. else
  1447. begin
  1448. elestrideattr := DW_AT_stride_size;
  1449. elesize := def.elepackedbitsize;
  1450. end;
  1451. if is_special_array(def) then
  1452. begin
  1453. { no known size, no known upper bound }
  1454. if assigned(def.typesym) then
  1455. append_entry(DW_TAG_array_type,true,[
  1456. DW_AT_name,DW_FORM_string,symname(def.typesym)+#0
  1457. ])
  1458. else
  1459. append_entry(DW_TAG_array_type,true,[]);
  1460. append_labelentry_ref(DW_AT_type,def_dwarf_lab(def.elementdef));
  1461. finish_entry;
  1462. { a missing upper bound means "unknown"/default }
  1463. append_entry(DW_TAG_subrange_type,false,[
  1464. DW_AT_lower_bound,DW_FORM_sdata,def.lowrange,
  1465. elestrideattr,DW_FORM_udata,elesize
  1466. ]);
  1467. end
  1468. else
  1469. begin
  1470. size:=def.size;
  1471. if assigned(def.typesym) then
  1472. append_entry(DW_TAG_array_type,true,[
  1473. DW_AT_name,DW_FORM_string,symname(def.typesym)+#0,
  1474. DW_AT_byte_size,DW_FORM_udata,size
  1475. ])
  1476. else
  1477. append_entry(DW_TAG_array_type,true,[
  1478. DW_AT_byte_size,DW_FORM_udata,size
  1479. ]);
  1480. append_labelentry_ref(DW_AT_type,def_dwarf_lab(def.elementdef));
  1481. finish_entry;
  1482. { to simplify things, we don't write a multidimensional array here }
  1483. append_entry(DW_TAG_subrange_type,false,[
  1484. DW_AT_lower_bound,DW_FORM_sdata,def.lowrange,
  1485. DW_AT_upper_bound,DW_FORM_sdata,def.highrange,
  1486. elestrideattr,DW_FORM_udata,elesize
  1487. ]);
  1488. end;
  1489. append_labelentry_ref(DW_AT_type,def_dwarf_lab(def.rangedef));
  1490. finish_entry;
  1491. finish_children;
  1492. end;
  1493. procedure TDebugInfoDwarf.appenddef_record(list:TAsmList;def:trecorddef);
  1494. begin
  1495. if assigned(def.objname) then
  1496. appenddef_record_named(list,def,def.objname^)
  1497. else
  1498. appenddef_record_named(list,def,'');
  1499. end;
  1500. procedure TDebugInfoDwarf.appenddef_record_named(list:TAsmList;def:trecorddef;const name: shortstring);
  1501. begin
  1502. if (name<>'') then
  1503. append_entry(DW_TAG_structure_type,true,[
  1504. DW_AT_name,DW_FORM_string,name+#0,
  1505. DW_AT_byte_size,DW_FORM_udata,def.size
  1506. ])
  1507. else
  1508. append_entry(DW_TAG_structure_type,true,[
  1509. DW_AT_byte_size,DW_FORM_udata,def.size
  1510. ]);
  1511. finish_entry;
  1512. def.symtable.symList.ForEachCall(@enum_membersyms_callback,nil);
  1513. { don't know whether external record declaration is allow but if it so then
  1514. do the same as we do for other object types - skip procdef info generation
  1515. for external defs (Paul Ishenin) }
  1516. if not(oo_is_external in def.objectoptions) then
  1517. write_symtable_procdefs(current_asmdata.asmlists[al_dwarf_info],def.symtable);
  1518. finish_children;
  1519. end;
  1520. procedure TDebugInfoDwarf.appenddef_pointer(list:TAsmList;def:tpointerdef);
  1521. begin
  1522. append_entry(DW_TAG_pointer_type,false,[]);
  1523. if not(is_voidpointer(def)) then
  1524. append_labelentry_ref(DW_AT_type,def_dwarf_lab(def.pointeddef));
  1525. finish_entry;
  1526. end;
  1527. procedure TDebugInfoDwarf.appenddef_string(list:TAsmList;def:tstringdef);
  1528. procedure addnormalstringdef(const name: shortstring; lendef: tdef; maxlen: asizeuint);
  1529. var
  1530. { maxlen can be > high(int64) }
  1531. slen : asizeuint;
  1532. arr : tasmlabel;
  1533. begin
  1534. { fix length of openshortstring }
  1535. slen:=aword(def.len);
  1536. if (slen=0) or
  1537. (slen>maxlen) then
  1538. slen:=maxlen;
  1539. { create a structure with two elements }
  1540. if not(tf_dwarf_only_local_labels in target_info.flags) then
  1541. current_asmdata.getdatalabel(arr)
  1542. else
  1543. current_asmdata.getaddrlabel(arr);
  1544. append_entry(DW_TAG_structure_type,true,[
  1545. DW_AT_name,DW_FORM_string,name+#0,
  1546. DW_AT_byte_size,DW_FORM_udata,qword(lendef.size)+slen
  1547. ]);
  1548. finish_entry;
  1549. { length entry }
  1550. append_entry(DW_TAG_member,false,[
  1551. DW_AT_name,DW_FORM_string,'length'#0,
  1552. DW_AT_data_member_location,DW_FORM_block1,1+lengthuleb128(0)
  1553. ]);
  1554. current_asmdata.asmlists[al_dwarf_info].concat(tai_const.create_8bit(ord(DW_OP_plus_uconst)));
  1555. current_asmdata.asmlists[al_dwarf_info].concat(tai_const.create_uleb128bit(0));
  1556. append_labelentry_ref(DW_AT_type,def_dwarf_lab(lendef));
  1557. finish_entry;
  1558. { string data entry }
  1559. append_entry(DW_TAG_member,false,[
  1560. DW_AT_name,DW_FORM_string,'st'#0,
  1561. DW_AT_data_member_location,DW_FORM_block1,1+lengthuleb128(1)
  1562. ]);
  1563. current_asmdata.asmlists[al_dwarf_info].concat(tai_const.create_8bit(ord(DW_OP_plus_uconst)));
  1564. current_asmdata.asmlists[al_dwarf_info].concat(tai_const.create_uleb128bit(lendef.size));
  1565. append_labelentry_ref(DW_AT_type,arr);
  1566. finish_entry;
  1567. finish_children;
  1568. { now the data array }
  1569. current_asmdata.asmlists[al_dwarf_info].concat(tai_symbol.create(arr,0));
  1570. append_entry(DW_TAG_array_type,true,[
  1571. DW_AT_byte_size,DW_FORM_udata,def.size,
  1572. DW_AT_byte_stride,DW_FORM_udata,1
  1573. ]);
  1574. append_labelentry_ref(DW_AT_type,def_dwarf_lab(cchartype));
  1575. finish_entry;
  1576. append_entry(DW_TAG_subrange_type,false,[
  1577. DW_AT_lower_bound,DW_FORM_udata,0,
  1578. DW_AT_upper_bound,DW_FORM_udata,qword(slen)
  1579. ]);
  1580. append_labelentry_ref(DW_AT_type,def_dwarf_lab(lendef));
  1581. finish_entry;
  1582. finish_children;
  1583. end;
  1584. begin
  1585. case def.stringtype of
  1586. st_shortstring:
  1587. begin
  1588. addnormalstringdef('ShortString',u8inttype,255);
  1589. end;
  1590. st_longstring:
  1591. begin
  1592. { a) we don't actually support variables of this type currently
  1593. b) this type is only used as the type for constant strings
  1594. > 255 characters
  1595. c) in such a case, gdb will allocate and initialise enough
  1596. memory to hold the maximum size for such a string
  1597. -> don't use high(qword)/high(cardinal) as maximum, since that
  1598. will cause exhausting the VM space, but some "reasonably high"
  1599. number that should be enough for most constant strings
  1600. }
  1601. {$ifdef cpu64bitaddr}
  1602. addnormalstringdef('LongString',u64inttype,qword(1024*1024));
  1603. {$endif cpu64bitaddr}
  1604. {$ifdef cpu32bitaddr}
  1605. addnormalstringdef('LongString',u32inttype,cardinal(1024*1024));
  1606. {$endif cpu32bitaddr}
  1607. {$ifdef cpu16bitaddr}
  1608. addnormalstringdef('LongString',u16inttype,cardinal(1024));
  1609. {$endif cpu16bitaddr}
  1610. end;
  1611. st_ansistring:
  1612. begin
  1613. { looks like a pchar }
  1614. append_entry(DW_TAG_pointer_type,false,[]);
  1615. append_labelentry_ref(DW_AT_type,def_dwarf_lab(cchartype));
  1616. finish_entry;
  1617. end;
  1618. st_unicodestring,
  1619. st_widestring:
  1620. begin
  1621. { looks like a pwidechar }
  1622. append_entry(DW_TAG_pointer_type,false,[]);
  1623. append_labelentry_ref(DW_AT_type,def_dwarf_lab(cwidechartype));
  1624. finish_entry;
  1625. end;
  1626. end;
  1627. end;
  1628. procedure TDebugInfoDwarf.appenddef_procvar(list:TAsmList;def:tprocvardef);
  1629. procedure doappend;
  1630. var
  1631. i : longint;
  1632. begin
  1633. if assigned(def.typesym) then
  1634. append_entry(DW_TAG_subroutine_type,true,[
  1635. DW_AT_name,DW_FORM_string,symname(def.typesym)+#0,
  1636. DW_AT_prototyped,DW_FORM_flag,true
  1637. ])
  1638. else
  1639. append_entry(DW_TAG_subroutine_type,true,[
  1640. DW_AT_prototyped,DW_FORM_flag,true
  1641. ]);
  1642. if not(is_void(tprocvardef(def).returndef)) then
  1643. append_labelentry_ref(DW_AT_type,def_dwarf_lab(tprocvardef(def).returndef));
  1644. finish_entry;
  1645. { write parameters }
  1646. for i:=0 to def.paras.count-1 do
  1647. begin
  1648. append_entry(DW_TAG_formal_parameter,false,[
  1649. DW_AT_name,DW_FORM_string,symname(tsym(def.paras[i]))+#0
  1650. ]);
  1651. append_labelentry_ref(DW_AT_type,def_dwarf_lab(tparavarsym(def.paras[i]).vardef));
  1652. finish_entry;
  1653. end;
  1654. finish_children;
  1655. end;
  1656. var
  1657. proc : tasmlabel;
  1658. begin
  1659. if not def.is_addressonly then
  1660. begin
  1661. { create a structure with two elements }
  1662. if not(tf_dwarf_only_local_labels in target_info.flags) then
  1663. current_asmdata.getdatalabel(proc)
  1664. else
  1665. current_asmdata.getaddrlabel(proc);
  1666. append_entry(DW_TAG_structure_type,true,[
  1667. DW_AT_byte_size,DW_FORM_data1,2*sizeof(pint)
  1668. ]);
  1669. finish_entry;
  1670. { proc entry }
  1671. append_entry(DW_TAG_member,false,[
  1672. DW_AT_name,DW_FORM_string,'Proc'#0,
  1673. DW_AT_data_member_location,DW_FORM_block1,1+lengthuleb128(0)
  1674. ]);
  1675. current_asmdata.asmlists[al_dwarf_info].concat(tai_const.create_8bit(ord(DW_OP_plus_uconst)));
  1676. current_asmdata.asmlists[al_dwarf_info].concat(tai_const.create_uleb128bit(0));
  1677. append_labelentry_ref(DW_AT_type,proc);
  1678. finish_entry;
  1679. { self entry }
  1680. append_entry(DW_TAG_member,false,[
  1681. DW_AT_name,DW_FORM_string,'Self'#0,
  1682. DW_AT_data_member_location,DW_FORM_block1,1+lengthuleb128(sizeof(pint))
  1683. ]);
  1684. current_asmdata.asmlists[al_dwarf_info].concat(tai_const.create_8bit(ord(DW_OP_plus_uconst)));
  1685. current_asmdata.asmlists[al_dwarf_info].concat(tai_const.create_uleb128bit(sizeof(pint)));
  1686. append_labelentry_ref(DW_AT_type,def_dwarf_lab(class_tobject));
  1687. finish_entry;
  1688. finish_children;
  1689. current_asmdata.asmlists[al_dwarf_info].concat(tai_symbol.create(proc,0));
  1690. doappend;
  1691. end
  1692. else
  1693. doappend;
  1694. end;
  1695. procedure TDebugInfoDwarf.beforeappenddef(list:TAsmList;def:tdef);
  1696. var
  1697. labsym : tasmsymbol;
  1698. begin
  1699. current_asmdata.asmlists[al_dwarf_info].concat(tai_comment.Create(strpnew('Definition '+def.typename)));
  1700. labsym:=def_dwarf_lab(def);
  1701. if ds_dwarf_dbg_info_written in def.defstates then
  1702. current_asmdata.asmlists[al_dwarf_info].concat(tai_symbol.create_global(labsym,0))
  1703. else
  1704. current_asmdata.asmlists[al_dwarf_info].concat(tai_symbol.create(labsym,0));
  1705. { On Darwin, dwarf info is not linked in the final binary,
  1706. but kept in the individual object files. This allows for
  1707. faster linking, but means that you have to keep the object
  1708. files for debugging and also that gdb only loads in the
  1709. debug info of a particular object file once you step into
  1710. or over a procedure in it.
  1711. To solve this, there is a tool called dsymutil which can
  1712. extract all the dwarf info from a program's object files.
  1713. This utility however performs "smart linking" on the dwarf
  1714. info and throws away all unreferenced dwarf entries. Since
  1715. variables' types always point to the dwarfinfo for a tdef
  1716. and never to that for a typesym, this means all debug
  1717. entries generated for typesyms are thrown away.
  1718. The problem with that is that we translate typesyms into
  1719. DW_TAG_typedef, and gdb's dwarf-2 reader only makes types
  1720. globally visibly if they are defined using a DW_TAG_typedef.
  1721. So as a result, before running dsymutil types only become
  1722. available once you stepped into/over a function in the object
  1723. file where they are declared, and after running dsymutil they
  1724. are all gone (printing variables still works because the
  1725. tdef dwarf info is still available, but you cannot typecast
  1726. anything outside the declaring units because the type names
  1727. are not known there).
  1728. The solution: if a tdef has an associated typesym, let the
  1729. debug label for the tdef point to a DW_TAG_typedef instead
  1730. of directly to the tdef itself. And don't write anything
  1731. special for the typesym itself.
  1732. Update: we now also do this for other platforms, because
  1733. otherwise if you compile unit A without debug info and
  1734. use one of its types in unit B, then no typedef will be
  1735. generated and hence gdb will not be able to give a definition
  1736. of the type.
  1737. }
  1738. if is_objc_class_or_protocol(def) then
  1739. begin
  1740. { for Objective-C classes, the typedef must refer to the
  1741. struct itself, not to the pointer of the struct; Objective-C
  1742. classes are not implicit pointers in Objective-C itself, only
  1743. in FPC. So make the def label point to a pointer to the
  1744. typedef, which in turn refers to the actual struct (for Delphi-
  1745. style classes, the def points to the typedef, which refers to
  1746. a pointer to the actual struct) }
  1747. { implicit pointer }
  1748. current_asmdata.getaddrlabel(TAsmLabel(pointer(labsym)));
  1749. append_entry(DW_TAG_pointer_type,false,[]);
  1750. append_labelentry_ref(DW_AT_type,labsym);
  1751. finish_entry;
  1752. current_asmdata.asmlists[al_dwarf_info].concat(tai_symbol.create(labsym,0));
  1753. end;
  1754. if assigned(def.typesym) and
  1755. not(df_generic in def.defoptions) then
  1756. begin
  1757. current_asmdata.getaddrlabel(TAsmLabel(pointer(labsym)));
  1758. append_entry(DW_TAG_typedef,false,[
  1759. DW_AT_name,DW_FORM_string,symname(def.typesym)+#0
  1760. ]);
  1761. append_labelentry_ref(DW_AT_type,labsym);
  1762. finish_entry;
  1763. current_asmdata.asmlists[al_dwarf_info].concat(tai_symbol.create(labsym,0));
  1764. end
  1765. end;
  1766. procedure TDebugInfoDwarf.afterappenddef(list:TAsmList;def:tdef);
  1767. var
  1768. labsym : tasmsymbol;
  1769. begin
  1770. { create a derived reference type for pass-by-reference parameters }
  1771. { (gdb doesn't support DW_AT_variable_parameter yet) }
  1772. labsym:=def_dwarf_ref_lab(def);
  1773. if ds_dwarf_dbg_info_written in def.defstates then
  1774. current_asmdata.asmlists[al_dwarf_info].concat(tai_symbol.create_global(labsym,0))
  1775. else
  1776. current_asmdata.asmlists[al_dwarf_info].concat(tai_symbol.create(labsym,0));
  1777. append_entry(DW_TAG_reference_type,false,[]);
  1778. append_labelentry_ref(DW_AT_type,def_dwarf_lab(def));
  1779. finish_entry;
  1780. end;
  1781. procedure TDebugInfoDwarf.appendprocdef(list:TAsmList; def:tprocdef);
  1782. function dwarf_calling_convention(def: tprocdef): Tdwarf_calling_convention;
  1783. begin
  1784. case def.proccalloption of
  1785. pocall_register:
  1786. result:=DW_CC_GNU_borland_fastcall_i386;
  1787. pocall_cdecl,
  1788. pocall_stdcall,
  1789. pocall_cppdecl,
  1790. pocall_mwpascal:
  1791. result:=DW_CC_normal;
  1792. else
  1793. result:=DW_CC_nocall;
  1794. end
  1795. end;
  1796. var
  1797. procendlabel : tasmlabel;
  1798. procentry : string;
  1799. cc : Tdwarf_calling_convention;
  1800. st : tsymtable;
  1801. vmtindexnr : pint;
  1802. in_currentunit : boolean;
  1803. begin
  1804. { only write debug info for procedures defined in the current module,
  1805. except in case of methods (gcc-compatible)
  1806. }
  1807. in_currentunit:=def.in_currentunit;
  1808. if not in_currentunit and
  1809. not (def.owner.symtabletype in [objectsymtable,recordsymtable]) then
  1810. exit;
  1811. { happens for init procdef of units without init section }
  1812. if in_currentunit and
  1813. not assigned(def.procstarttai) then
  1814. exit;
  1815. { Procdefs are not handled by the regular def writing code, so
  1816. dbg_state is not set/checked for them. Do it here. }
  1817. if (def.dbg_state in [dbg_state_writing,dbg_state_written]) then
  1818. exit;
  1819. defnumberlist.Add(def);
  1820. { Write methods and only in the scope of their parent objectdefs. }
  1821. if (def.owner.symtabletype in [objectsymtable,recordsymtable]) then
  1822. begin
  1823. { this code can also work for nested procdefs, but is not yet
  1824. activated for those because there is no clear advantage yet to
  1825. limiting the scope of nested procedures to that of their parent,
  1826. and it makes it impossible to set breakpoints in them by
  1827. referring to their name. }
  1828. st:=def.owner;
  1829. while assigned(st.defowner) and
  1830. (tdef(st.defowner).typ = procdef) do
  1831. st:=tprocdef(st.defowner).owner;
  1832. if assigned(st) and
  1833. (tdef(st.defowner).dbg_state<>dbg_state_writing) then
  1834. exit;
  1835. end;
  1836. def.dbg_state:=dbg_state_writing;
  1837. current_asmdata.asmlists[al_dwarf_info].concat(tai_comment.Create(strpnew('Procdef '+def.fullprocname(true))));
  1838. if not is_objc_class_or_protocol(def.struct) then
  1839. append_entry(DW_TAG_subprogram,true,
  1840. [DW_AT_name,DW_FORM_string,symname(def.procsym)+#0
  1841. { data continues below }
  1842. { problem: base reg isn't known here
  1843. DW_AT_frame_base,DW_FORM_block1,1
  1844. }
  1845. ])
  1846. else
  1847. append_entry(DW_TAG_subprogram,true,
  1848. [DW_AT_name,DW_FORM_string,def.mangledname+#0
  1849. { data continues below }
  1850. { problem: base reg isn't known here
  1851. DW_AT_frame_base,DW_FORM_block1,1
  1852. }
  1853. ]);
  1854. { Append optional flags. }
  1855. { All Pascal procedures are prototyped }
  1856. append_attribute(DW_AT_prototyped,DW_FORM_flag,[true]);
  1857. { Calling convention. }
  1858. cc:=dwarf_calling_convention(def);
  1859. if (cc<>DW_CC_normal) then
  1860. append_attribute(DW_AT_calling_convention,DW_FORM_data1,[ord(cc)]);
  1861. { Externally visible. }
  1862. if (po_global in def.procoptions) and
  1863. (def.parast.symtablelevel<=normal_function_level) then
  1864. append_attribute(DW_AT_external,DW_FORM_flag,[true]);
  1865. { Abstract or virtual/overriding method. }
  1866. if (([po_abstractmethod, po_virtualmethod, po_overridingmethod] * def.procoptions) <> []) and
  1867. not is_objc_class_or_protocol(def.struct) and
  1868. not is_objectpascal_helper(def.struct) then
  1869. begin
  1870. if not(po_abstractmethod in def.procoptions) then
  1871. append_attribute(DW_AT_virtuality,DW_FORM_data1,[ord(DW_VIRTUALITY_virtual)])
  1872. else
  1873. append_attribute(DW_AT_virtuality,DW_FORM_data1,[ord(DW_VIRTUALITY_pure_virtual)]);
  1874. { Element number in the vmt (needs to skip stuff coming before the
  1875. actual method addresses in the vmt, so we use vmtmethodoffset()
  1876. and then divide by sizeof(pint)). }
  1877. vmtindexnr:=tobjectdef(def.owner.defowner).vmtmethodoffset(def.extnumber) div sizeof(pint);
  1878. append_attribute(DW_AT_vtable_elem_location,DW_FORM_block1,[1+LengthUleb128(vmtindexnr)]);
  1879. current_asmdata.asmlists[al_dwarf_info].concat(tai_const.create_8bit(ord(DW_OP_constu)));
  1880. current_asmdata.asmlists[al_dwarf_info].concat(tai_const.Create_uleb128bit(vmtindexnr));
  1881. end;
  1882. { accessibility: public/private/protected }
  1883. if (def.owner.symtabletype in [objectsymtable,recordsymtable]) then
  1884. append_visibility(def.visibility);
  1885. { Return type. }
  1886. if not(is_void(tprocdef(def).returndef)) then
  1887. append_labelentry_ref(DW_AT_type,def_dwarf_lab(tprocdef(def).returndef));
  1888. { we can only write the start/end if this procedure is implemented in
  1889. this module
  1890. }
  1891. if in_currentunit then
  1892. begin
  1893. { mark end of procedure }
  1894. current_asmdata.getlabel(procendlabel,alt_dbgtype);
  1895. current_asmdata.asmlists[al_procedures].insertbefore(tai_label.create(procendlabel),def.procendtai);
  1896. if (target_info.system = system_powerpc64_linux) then
  1897. procentry := '.' + def.mangledname
  1898. else
  1899. procentry := def.mangledname;
  1900. append_labelentry(DW_AT_low_pc,current_asmdata.RefAsmSymbol(procentry));
  1901. append_labelentry(DW_AT_high_pc,procendlabel);
  1902. end;
  1903. { Don't write the funcretsym explicitly, it's also in the
  1904. localsymtable and/or parasymtable.
  1905. }
  1906. finish_entry;
  1907. if assigned(def.parast) then
  1908. begin
  1909. { First insert self, because gdb uses the fact whether or not the
  1910. first parameter of a method is artificial to distinguish static
  1911. from regular methods. }
  1912. { fortunately, self is the always the first parameter in the
  1913. paralist, since it has the lowest paranr. Note that this is not
  1914. true for Objective-C, but those methods are detected in
  1915. another way (by reading the ObjC run time information) }
  1916. write_symtable_parasyms(current_asmdata.asmlists[al_dwarf_info],def.paras);
  1917. end;
  1918. { local type defs and vars should not be written
  1919. inside the main proc }
  1920. if in_currentunit and
  1921. assigned(def.localst) and
  1922. (def.localst.symtabletype=localsymtable) then
  1923. write_symtable_syms(current_asmdata.asmlists[al_dwarf_info],def.localst);
  1924. { last write the types from this procdef }
  1925. if assigned(def.parast) then
  1926. write_symtable_defs(current_asmdata.asmlists[al_dwarf_info],def.parast);
  1927. { only try to write the localst if the routine is implemented here }
  1928. if in_currentunit and
  1929. assigned(def.localst) and
  1930. (def.localst.symtabletype=localsymtable) then
  1931. begin
  1932. write_symtable_defs(current_asmdata.asmlists[al_dwarf_info],def.localst);
  1933. { Write nested procedures -- disabled, see scope check at the
  1934. beginning; currently, these are still written in the global
  1935. scope. }
  1936. // write_symtable_procdefs(current_asmdata.asmlists[al_dwarf_info],def.localst);
  1937. end;
  1938. finish_children;
  1939. end;
  1940. function TDebugInfoDwarf.get_symlist_sym_offset(symlist: ppropaccesslistitem; out sym: tabstractvarsym; out offset: pint): boolean;
  1941. var
  1942. elesize : pint;
  1943. currdef : tdef;
  1944. indirection: boolean;
  1945. begin
  1946. result:=false;
  1947. if not assigned(symlist) then
  1948. exit;
  1949. sym:=nil;
  1950. offset:=0;
  1951. currdef:=nil;
  1952. indirection:=false;
  1953. repeat
  1954. case symlist^.sltype of
  1955. sl_load:
  1956. begin
  1957. if assigned(sym) then
  1958. internalerror(2009031203);
  1959. if not(symlist^.sym.typ in [paravarsym,localvarsym,staticvarsym,fieldvarsym]) then
  1960. { can't handle... }
  1961. exit;
  1962. sym:=tabstractvarsym(symlist^.sym);
  1963. currdef:=tabstractvarsym(sym).vardef;
  1964. if ((sym.typ=paravarsym) and
  1965. paramanager.push_addr_param(tparavarsym(sym).varspez,sym.vardef,tprocdef(sym.owner.defowner).proccalloption)) then
  1966. indirection:=true;
  1967. end;
  1968. sl_subscript:
  1969. begin
  1970. if not assigned(currdef) then
  1971. internalerror(2009031301);
  1972. if (symlist^.sym.typ<>fieldvarsym) then
  1973. internalerror(2009031202);
  1974. { can't handle offsets with indirections yet }
  1975. if indirection then
  1976. exit;
  1977. if is_packed_record_or_object(currdef) then
  1978. begin
  1979. { can't calculate the address of a non-byte aligned field }
  1980. if (tfieldvarsym(symlist^.sym).fieldoffset mod 8) <> 0 then
  1981. exit;
  1982. inc(offset,tfieldvarsym(symlist^.sym).fieldoffset div 8)
  1983. end
  1984. else
  1985. inc(offset,tfieldvarsym(symlist^.sym).fieldoffset);
  1986. currdef:=tfieldvarsym(symlist^.sym).vardef;
  1987. end;
  1988. sl_absolutetype,
  1989. sl_typeconv:
  1990. begin
  1991. currdef:=tfieldvarsym(symlist^.sym).vardef;
  1992. { ignore, these don't change the address }
  1993. end;
  1994. sl_vec:
  1995. begin
  1996. if not assigned(currdef) or
  1997. (currdef.typ<>arraydef) then
  1998. internalerror(2009031201);
  1999. { can't handle offsets with indirections yet }
  2000. if indirection then
  2001. exit;
  2002. if not is_packed_array(currdef) then
  2003. elesize:=tarraydef(currdef).elesize
  2004. else
  2005. begin
  2006. elesize:=tarraydef(currdef).elepackedbitsize;
  2007. { can't calculate the address of a non-byte aligned element }
  2008. if (elesize mod 8)<>0 then
  2009. exit;
  2010. elesize:=elesize div 8;
  2011. end;
  2012. inc(offset,(symlist^.value.svalue-tarraydef(currdef).lowrange)*elesize);
  2013. currdef:=tarraydef(currdef).elementdef;
  2014. end;
  2015. else
  2016. internalerror(2009031401);
  2017. end;
  2018. symlist:=symlist^.next;
  2019. until not assigned(symlist);
  2020. if not assigned(sym) then
  2021. internalerror(2009031205);
  2022. result:=true;
  2023. end;
  2024. procedure TDebugInfoDwarf.appendsym_var(list:TAsmList;sym:tabstractnormalvarsym);
  2025. begin
  2026. appendsym_var_with_name_type_offset(list,sym,symname(sym),sym.vardef,0,[]);
  2027. end;
  2028. procedure TDebugInfoDwarf.appendsym_var_with_name_type_offset(list:TAsmList; sym:tabstractnormalvarsym; const name: string; def: tdef; offset: pint; const flags: tdwarfvarsymflags);
  2029. var
  2030. templist : TAsmList;
  2031. blocksize : longint;
  2032. tag : tdwarf_tag;
  2033. dreg : byte;
  2034. begin
  2035. { external symbols can't be resolved at link time, so we
  2036. can't generate stabs for them
  2037. not sure if this applies to dwarf as well (FK)
  2038. }
  2039. if vo_is_external in sym.varoptions then
  2040. exit;
  2041. { There is no space allocated for not referenced locals }
  2042. if (sym.owner.symtabletype=localsymtable) and (sym.refs=0) then
  2043. exit;
  2044. templist:=TAsmList.create;
  2045. case sym.localloc.loc of
  2046. LOC_REGISTER,
  2047. LOC_CREGISTER,
  2048. LOC_MMREGISTER,
  2049. LOC_CMMREGISTER,
  2050. LOC_FPUREGISTER,
  2051. LOC_CFPUREGISTER :
  2052. begin
  2053. templist.concat(tai_const.create_8bit(ord(DW_OP_regx)));
  2054. dreg:=dwarf_reg(sym.localloc.register);
  2055. templist.concat(tai_const.create_uleb128bit(dreg));
  2056. blocksize:=1+Lengthuleb128(dreg);
  2057. end;
  2058. else
  2059. begin
  2060. case sym.typ of
  2061. staticvarsym:
  2062. begin
  2063. if (vo_is_thread_var in sym.varoptions) then
  2064. begin
  2065. { TODO: !!! FIXME: dwarf for thread vars !!!}
  2066. blocksize:=0;
  2067. end
  2068. else
  2069. begin
  2070. templist.concat(tai_const.create_8bit(ord(DW_OP_addr)));
  2071. templist.concat(tai_const.createname(sym.mangledname,offset));
  2072. blocksize:=1+sizeof(puint);
  2073. end;
  2074. end;
  2075. paravarsym,
  2076. localvarsym:
  2077. begin
  2078. { Happens when writing debug info for paras of procdefs not
  2079. implemented in the current module. Can't add a general check
  2080. for LOC_INVALID above, because staticvarsyms may also have it.
  2081. }
  2082. if sym.localloc.loc<> LOC_INVALID then
  2083. begin
  2084. dreg:=dwarf_reg(sym.localloc.reference.base);
  2085. templist.concat(tai_const.create_8bit(ord(DW_OP_breg0)+dreg));
  2086. templist.concat(tai_const.create_sleb128bit(sym.localloc.reference.offset+offset));
  2087. blocksize:=1+Lengthsleb128(sym.localloc.reference.offset);
  2088. {$ifndef gdb_supports_DW_AT_variable_parameter}
  2089. { Parameters which are passed by reference. (var and the like)
  2090. Hide the reference-pointer and dereference the pointer
  2091. in the DW_AT_location block.
  2092. }
  2093. if (sym.typ=paravarsym) and
  2094. paramanager.push_addr_param(sym.varspez,sym.vardef,tprocdef(sym.owner.defowner).proccalloption) and
  2095. not(vo_has_local_copy in sym.varoptions) and
  2096. not is_open_string(sym.vardef) then
  2097. begin
  2098. templist.concat(tai_const.create_8bit(ord(DW_OP_deref)));
  2099. inc(blocksize);
  2100. end
  2101. {$endif not gdb_supports_DW_AT_variable_parameter}
  2102. end;
  2103. end
  2104. else
  2105. internalerror(200601288);
  2106. end;
  2107. end;
  2108. end;
  2109. { function results must not be added to the parameter list,
  2110. as they are not part of the signature of the function
  2111. (gdb automatically adds them according to the ABI specifications
  2112. when calling the function)
  2113. }
  2114. if (sym.typ=paravarsym) and
  2115. not(dvf_force_local_var in flags) and
  2116. not(vo_is_funcret in sym.varoptions) then
  2117. tag:=DW_TAG_formal_parameter
  2118. else
  2119. tag:=DW_TAG_variable;
  2120. { must be parasym of externally implemented procdef, but
  2121. the parasymtable can con also contain e.g. absolutevarsyms
  2122. -> check symtabletype}
  2123. if (sym.owner.symtabletype=parasymtable) and
  2124. (sym.localloc.loc=LOC_INVALID) then
  2125. begin
  2126. if (sym.owner.symtabletype<>parasymtable) then
  2127. internalerror(2009101001);
  2128. append_entry(tag,false,[
  2129. DW_AT_name,DW_FORM_string,name+#0
  2130. {
  2131. DW_AT_decl_file,DW_FORM_data1,0,
  2132. DW_AT_decl_line,DW_FORM_data1,
  2133. }
  2134. ])
  2135. end
  2136. else if not(sym.localloc.loc in [LOC_REGISTER,LOC_CREGISTER,LOC_MMREGISTER,
  2137. LOC_CMMREGISTER,LOC_FPUREGISTER,LOC_CFPUREGISTER]) and
  2138. ((sym.owner.symtabletype = globalsymtable) or
  2139. (sp_static in sym.symoptions) or
  2140. (vo_is_public in sym.varoptions)) then
  2141. append_entry(tag,false,[
  2142. DW_AT_name,DW_FORM_string,name+#0,
  2143. {
  2144. DW_AT_decl_file,DW_FORM_data1,0,
  2145. DW_AT_decl_line,DW_FORM_data1,
  2146. }
  2147. DW_AT_external,DW_FORM_flag,true,
  2148. { data continues below }
  2149. DW_AT_location,DW_FORM_block1,blocksize
  2150. ])
  2151. {$ifdef gdb_supports_DW_AT_variable_parameter}
  2152. else if (sym.typ=paravarsym) and
  2153. paramanager.push_addr_param(sym.varspez,sym.vardef,tprocdef(sym.owner.defowner).proccalloption) and
  2154. not(vo_has_local_copy in sym.varoptions) and
  2155. not is_open_string(sym.vardef) then
  2156. append_entry(tag,false,[
  2157. DW_AT_name,DW_FORM_string,name+#0,
  2158. DW_AT_variable_parameter,DW_FORM_flag,true,
  2159. {
  2160. DW_AT_decl_file,DW_FORM_data1,0,
  2161. DW_AT_decl_line,DW_FORM_data1,
  2162. }
  2163. { data continues below }
  2164. DW_AT_location,DW_FORM_block1,blocksize
  2165. ])
  2166. {$endif gdb_supports_DW_AT_variable_parameter}
  2167. else
  2168. append_entry(tag,false,[
  2169. DW_AT_name,DW_FORM_string,name+#0,
  2170. {
  2171. DW_AT_decl_file,DW_FORM_data1,0,
  2172. DW_AT_decl_line,DW_FORM_data1,
  2173. }
  2174. { data continues below }
  2175. DW_AT_location,DW_FORM_block1,blocksize
  2176. ]);
  2177. { append block data }
  2178. current_asmdata.asmlists[al_dwarf_info].concatlist(templist);
  2179. { Mark self as artificial for methods, because gdb uses the fact
  2180. whether or not the first parameter of a method is artificial to
  2181. distinguish regular from static methods (since there are no
  2182. no vo_is_self parameters for static methods, we don't have to check
  2183. that). }
  2184. if (vo_is_self in sym.varoptions) then
  2185. append_attribute(DW_AT_artificial,DW_FORM_flag,[true]);
  2186. append_labelentry_ref(DW_AT_type,def_dwarf_lab(def));
  2187. templist.free;
  2188. finish_entry;
  2189. end;
  2190. procedure TDebugInfoDwarf.appendsym_staticvar(list:TAsmList;sym:tstaticvarsym);
  2191. begin
  2192. appendsym_var(list,sym);
  2193. end;
  2194. procedure TDebugInfoDwarf.appendsym_localvar(list:TAsmList;sym:tlocalvarsym);
  2195. begin
  2196. appendsym_var(list,sym);
  2197. end;
  2198. procedure TDebugInfoDwarf.appendsym_paravar(list:TAsmList;sym:tparavarsym);
  2199. begin
  2200. appendsym_var(list,sym);
  2201. end;
  2202. procedure TDebugInfoDwarf.appendsym_fieldvar(list:TAsmList;sym: tfieldvarsym);
  2203. begin
  2204. appendsym_fieldvar_with_name_offset(list,sym,symname(sym),sym.vardef,0);
  2205. end;
  2206. procedure TDebugInfoDwarf.appendsym_fieldvar_with_name_offset(list:TAsmList;sym: tfieldvarsym;const name: string; def: tdef; offset: pint);
  2207. var
  2208. bitoffset,
  2209. fieldoffset,
  2210. fieldnatsize: asizeint;
  2211. begin
  2212. if (sp_static in sym.symoptions) or
  2213. (sym.visibility=vis_hidden) then
  2214. exit;
  2215. if (tabstractrecordsymtable(sym.owner).usefieldalignment<>bit_alignment) or
  2216. { only ordinals are bitpacked }
  2217. not is_ordinal(sym.vardef) then
  2218. begin
  2219. { other kinds of fields can however also appear in a bitpacked }
  2220. { record, and then their offset is also specified in bits rather }
  2221. { than in bytes }
  2222. if (tabstractrecordsymtable(sym.owner).usefieldalignment<>bit_alignment) then
  2223. fieldoffset:=sym.fieldoffset
  2224. else
  2225. fieldoffset:=sym.fieldoffset div 8;
  2226. inc(fieldoffset,offset);
  2227. append_entry(DW_TAG_member,false,[
  2228. DW_AT_name,DW_FORM_string,name+#0,
  2229. DW_AT_data_member_location,DW_FORM_block1,1+lengthuleb128(fieldoffset)
  2230. ]);
  2231. end
  2232. else
  2233. begin
  2234. if (sym.vardef.packedbitsize > 255) then
  2235. internalerror(2007061201);
  2236. { we don't bitpack according to the ABI, but as close as }
  2237. { possible, i.e., equivalent to gcc's }
  2238. { __attribute__((__packed__)), which is also what gpc }
  2239. { does. }
  2240. fieldnatsize:=max(sizeof(pint),sym.vardef.size);
  2241. fieldoffset:=(sym.fieldoffset div (fieldnatsize*8)) * fieldnatsize;
  2242. inc(fieldoffset,offset);
  2243. bitoffset:=sym.fieldoffset mod (fieldnatsize*8);
  2244. if (target_info.endian=endian_little) then
  2245. bitoffset:=(fieldnatsize*8)-bitoffset-sym.vardef.packedbitsize;
  2246. append_entry(DW_TAG_member,false,[
  2247. DW_AT_name,DW_FORM_string,symname(sym)+#0,
  2248. { gcc also generates both a bit and byte size attribute }
  2249. { we don't support ordinals >= 256 bits }
  2250. DW_AT_byte_size,DW_FORM_data1,fieldnatsize,
  2251. { nor >= 256 bits (not yet, anyway, see IE above) }
  2252. DW_AT_bit_size,DW_FORM_data1,sym.vardef.packedbitsize,
  2253. { data1 and data2 are unsigned, bitoffset can also be negative }
  2254. DW_AT_bit_offset,DW_FORM_data4,bitoffset,
  2255. DW_AT_data_member_location,DW_FORM_block1,1+lengthuleb128(fieldoffset)
  2256. ]);
  2257. end;
  2258. current_asmdata.asmlists[al_dwarf_info].concat(tai_const.create_8bit(ord(DW_OP_plus_uconst)));
  2259. current_asmdata.asmlists[al_dwarf_info].concat(tai_const.create_uleb128bit(fieldoffset));
  2260. if (sym.owner.symtabletype in [objectsymtable,recordsymtable]) then
  2261. append_visibility(sym.visibility);
  2262. append_labelentry_ref(DW_AT_type,def_dwarf_lab(def));
  2263. finish_entry;
  2264. end;
  2265. procedure TDebugInfoDwarf.appendsym_const(list:TAsmList;sym:tconstsym);
  2266. begin
  2267. appendsym_const_member(list,sym,false);
  2268. end;
  2269. procedure TDebugInfoDwarf.appendsym_const_member(list:TAsmList;sym:tconstsym;ismember:boolean);
  2270. var
  2271. i,
  2272. size: aint;
  2273. usedef: tdef;
  2274. begin
  2275. { These are default values of parameters. These should be encoded
  2276. via DW_AT_default_value, not as a separate sym. Moreover, their
  2277. type is not available when writing the debug info for external
  2278. procedures.
  2279. }
  2280. if (sym.owner.symtabletype=parasymtable) then
  2281. exit;
  2282. if ismember then
  2283. append_entry(DW_TAG_member,false,[
  2284. DW_AT_name,DW_FORM_string,symname(sym)+#0,
  2285. { The DW_AT_declaration tag is invalid according to the DWARF specifications.
  2286. But gcc adds this to static const members and gdb checks
  2287. for this flag. So we have to set it also.
  2288. }
  2289. DW_AT_declaration,DW_FORM_flag,true,
  2290. DW_AT_external,DW_FORM_flag,true
  2291. ])
  2292. else
  2293. append_entry(DW_TAG_variable,false,[
  2294. DW_AT_name,DW_FORM_string,symname(sym)+#0
  2295. ]);
  2296. { for string constants, constdef isn't set because they have no real type }
  2297. case sym.consttyp of
  2298. conststring:
  2299. begin
  2300. { if DW_FORM_string is used below one day, this usedef should
  2301. probably become nil }
  2302. { note: < 255 instead of <= 255 because we have to store the
  2303. entire length of the string as well, and 256 does not fit in
  2304. a byte }
  2305. if (sym.value.len<255) then
  2306. usedef:=cshortstringtype
  2307. else
  2308. usedef:=clongstringtype;
  2309. end;
  2310. constresourcestring,
  2311. constwstring:
  2312. usedef:=nil;
  2313. else
  2314. usedef:=sym.constdef;
  2315. end;
  2316. if assigned(usedef) then
  2317. append_labelentry_ref(DW_AT_type,def_dwarf_lab(usedef));
  2318. AddConstToAbbrev(ord(DW_AT_const_value));
  2319. case sym.consttyp of
  2320. conststring:
  2321. begin
  2322. { DW_FORM_string isn't supported yet by the Pascal value printer
  2323. -> create a string using raw bytes }
  2324. if (sym.value.len<255) then
  2325. begin
  2326. AddConstToAbbrev(ord(DW_FORM_block1));
  2327. current_asmdata.asmlists[al_dwarf_info].concat(tai_const.create_8bit(sym.value.len+1));
  2328. current_asmdata.asmlists[al_dwarf_info].concat(tai_const.create_8bit(sym.value.len));
  2329. end
  2330. else
  2331. begin
  2332. AddConstToAbbrev(ord(DW_FORM_block));
  2333. current_asmdata.asmlists[al_dwarf_info].concat(tai_const.create_uleb128bit(sym.value.len+sizeof(pint)));
  2334. current_asmdata.asmlists[al_dwarf_info].concat(tai_const.create_pint(sym.value.len));
  2335. end;
  2336. i:=0;
  2337. size:=sym.value.len;
  2338. while(i<size) do
  2339. begin
  2340. current_asmdata.asmlists[al_dwarf_info].concat(tai_const.create_8bit((pbyte(sym.value.valueptr+i)^)));
  2341. inc(i);
  2342. end;
  2343. end;
  2344. constguid,
  2345. constset:
  2346. begin
  2347. AddConstToAbbrev(ord(DW_FORM_block1));
  2348. current_asmdata.asmlists[al_dwarf_info].concat(tai_const.create_8bit(usedef.size));
  2349. i:=0;
  2350. size:=sym.constdef.size;
  2351. while (i<size) do
  2352. begin
  2353. current_asmdata.asmlists[al_dwarf_info].concat(tai_const.create_8bit((pbyte(sym.value.valueptr+i)^)));
  2354. inc(i);
  2355. end;
  2356. end;
  2357. constwstring,
  2358. constresourcestring:
  2359. begin
  2360. { write dummy for now }
  2361. AddConstToAbbrev(ord(DW_FORM_string));
  2362. current_asmdata.asmlists[al_dwarf_info].concat(tai_string.create(''));
  2363. current_asmdata.asmlists[al_dwarf_info].concat(tai_const.create_8bit(0));
  2364. end;
  2365. constord:
  2366. begin
  2367. if (sym.value.valueord<0) then
  2368. begin
  2369. AddConstToAbbrev(ord(DW_FORM_sdata));
  2370. current_asmdata.asmlists[al_dwarf_info].concat(tai_const.create_sleb128bit(sym.value.valueord.svalue));
  2371. end
  2372. else
  2373. begin
  2374. AddConstToAbbrev(ord(DW_FORM_udata));
  2375. current_asmdata.asmlists[al_dwarf_info].concat(tai_const.create_uleb128bit(sym.value.valueord.uvalue));
  2376. end;
  2377. end;
  2378. constnil:
  2379. begin
  2380. {$ifdef cpu64bitaddr}
  2381. AddConstToAbbrev(ord(DW_FORM_data8));
  2382. current_asmdata.asmlists[al_dwarf_info].concat(tai_const.create_64bit(0));
  2383. {$else cpu64bitaddr}
  2384. AddConstToAbbrev(ord(DW_FORM_data4));
  2385. current_asmdata.asmlists[al_dwarf_info].concat(tai_const.create_32bit(0));
  2386. {$endif cpu64bitaddr}
  2387. end;
  2388. constpointer:
  2389. begin
  2390. {$ifdef cpu64bitaddr}
  2391. AddConstToAbbrev(ord(DW_FORM_data8));
  2392. current_asmdata.asmlists[al_dwarf_info].concat(tai_const.create_64bit(int64(sym.value.valueordptr)));
  2393. {$else cpu64bitaddr}
  2394. AddConstToAbbrev(ord(DW_FORM_data4));
  2395. current_asmdata.asmlists[al_dwarf_info].concat(tai_const.create_32bit(longint(sym.value.valueordptr)));
  2396. {$endif cpu64bitaddr}
  2397. end;
  2398. constreal:
  2399. begin
  2400. AddConstToAbbrev(ord(DW_FORM_block1));
  2401. case tfloatdef(sym.constdef).floattype of
  2402. s32real:
  2403. begin
  2404. current_asmdata.asmlists[al_dwarf_info].concat(tai_const.create_8bit(4));
  2405. current_asmdata.asmlists[al_dwarf_info].concat(tai_real_32bit.create(pbestreal(sym.value.valueptr)^));
  2406. end;
  2407. s64real:
  2408. begin
  2409. current_asmdata.asmlists[al_dwarf_info].concat(tai_const.create_8bit(8));
  2410. current_asmdata.asmlists[al_dwarf_info].concat(tai_real_64bit.create(pbestreal(sym.value.valueptr)^));
  2411. end;
  2412. s64comp,
  2413. s64currency:
  2414. begin
  2415. current_asmdata.asmlists[al_dwarf_info].concat(tai_const.create_8bit(8));
  2416. current_asmdata.asmlists[al_dwarf_info].concat(tai_const.create_64bit(trunc(pbestreal(sym.value.valueptr)^)));
  2417. end;
  2418. s80real,
  2419. sc80real:
  2420. begin
  2421. current_asmdata.asmlists[al_dwarf_info].concat(tai_const.create_8bit(sym.constdef.size));
  2422. current_asmdata.asmlists[al_dwarf_info].concat(tai_real_80bit.create(pextended(sym.value.valueptr)^,sym.constdef.size));
  2423. end;
  2424. else
  2425. internalerror(200601291);
  2426. end;
  2427. end;
  2428. else
  2429. internalerror(200601292);
  2430. end;
  2431. finish_entry;
  2432. end;
  2433. procedure TDebugInfoDwarf.appendsym_label(list:TAsmList;sym: tlabelsym);
  2434. begin
  2435. { ignore label syms for now, the problem is that a label sym
  2436. can have more than one label associated e.g. in case of
  2437. an inline procedure expansion }
  2438. end;
  2439. procedure TDebugInfoDwarf.appendsym_property(list:TAsmList;sym: tpropertysym);
  2440. var
  2441. symlist: ppropaccesslistitem;
  2442. tosym: tabstractvarsym;
  2443. offset: pint;
  2444. begin
  2445. if assigned(sym.propaccesslist[palt_read]) and
  2446. not assigned(sym.propaccesslist[palt_read].procdef) then
  2447. symlist:=sym.propaccesslist[palt_read].firstsym
  2448. else
  2449. { can't handle }
  2450. exit;
  2451. if not get_symlist_sym_offset(symlist,tosym,offset) then
  2452. exit;
  2453. if not (tosym.owner.symtabletype in [objectsymtable,recordsymtable]) then
  2454. begin
  2455. if (tosym.typ=fieldvarsym) then
  2456. internalerror(2009031404);
  2457. appendsym_var_with_name_type_offset(list,tabstractnormalvarsym(tosym),symname(sym),sym.propdef,offset,[])
  2458. end
  2459. else
  2460. appendsym_fieldvar_with_name_offset(list,tfieldvarsym(tosym),symname(sym),sym.propdef,offset)
  2461. end;
  2462. procedure TDebugInfoDwarf.appendsym_type(list:TAsmList;sym: ttypesym);
  2463. begin
  2464. { just queue the def if needed, beforeappenddef will
  2465. emit the typedef if necessary }
  2466. def_dwarf_lab(sym.typedef);
  2467. end;
  2468. procedure TDebugInfoDwarf.appendsym_absolute(list:TAsmList;sym:tabsolutevarsym);
  2469. var
  2470. templist : TAsmList;
  2471. blocksize : longint;
  2472. symlist : ppropaccesslistitem;
  2473. tosym: tabstractvarsym;
  2474. offset: pint;
  2475. flags: tdwarfvarsymflags;
  2476. begin
  2477. templist:=TAsmList.create;
  2478. case tabsolutevarsym(sym).abstyp of
  2479. toaddr :
  2480. begin
  2481. { MWE: replaced ifdef i368 }
  2482. (*
  2483. if target_cpu = cpu_i386 then
  2484. begin
  2485. { in theory, we could write a DW_AT_segment entry here for sym.absseg,
  2486. however I doubt that gdb supports this (FK) }
  2487. end;
  2488. *)
  2489. templist.concat(tai_const.create_8bit(3));
  2490. templist.concat(tai_const.create_pint(sym.addroffset));
  2491. blocksize:=1+sizeof(puint);
  2492. end;
  2493. toasm :
  2494. begin
  2495. templist.concat(tai_const.create_8bit(3));
  2496. templist.concat(tai_const.createname(sym.mangledname,0));
  2497. blocksize:=1+sizeof(puint);
  2498. end;
  2499. tovar:
  2500. begin
  2501. symlist:=tabsolutevarsym(sym).ref.firstsym;
  2502. if get_symlist_sym_offset(symlist,tosym,offset) then
  2503. begin
  2504. if (tosym.typ=fieldvarsym) then
  2505. internalerror(2009031402);
  2506. flags:=[];
  2507. if (sym.owner.symtabletype=localsymtable) then
  2508. include(flags,dvf_force_local_var);
  2509. appendsym_var_with_name_type_offset(list,tabstractnormalvarsym(tosym),symname(sym),tabstractvarsym(sym).vardef,offset,flags);
  2510. end;
  2511. templist.free;
  2512. exit;
  2513. end;
  2514. end;
  2515. append_entry(DW_TAG_variable,false,[
  2516. DW_AT_name,DW_FORM_string,symname(sym)+#0,
  2517. {
  2518. DW_AT_decl_file,DW_FORM_data1,0,
  2519. DW_AT_decl_line,DW_FORM_data1,
  2520. }
  2521. DW_AT_external,DW_FORM_flag,true,
  2522. { data continues below }
  2523. DW_AT_location,DW_FORM_block1,blocksize
  2524. ]);
  2525. { append block data }
  2526. current_asmdata.asmlists[al_dwarf_info].concatlist(templist);
  2527. append_labelentry_ref(DW_AT_type,def_dwarf_lab(sym.vardef));
  2528. templist.free;
  2529. finish_entry;
  2530. end;
  2531. procedure TDebugInfoDwarf.beforeappendsym(list:TAsmList;sym:tsym);
  2532. begin
  2533. current_asmdata.asmlists[al_dwarf_info].concat(tai_comment.Create(strpnew('Symbol '+symname(sym))));
  2534. end;
  2535. procedure TDebugInfoDwarf.insertmoduleinfo;
  2536. var
  2537. templist: TAsmList;
  2538. linelist: TAsmList;
  2539. lbl : tasmlabel;
  2540. n,m : Integer;
  2541. ditem : TDirIndexItem;
  2542. fitem : TFileIndexItem;
  2543. flist : TFPList;
  2544. dbgname : String;
  2545. begin
  2546. { insert DEBUGSTART and DEBUGEND labels }
  2547. dbgname:=make_mangledname('DEBUGSTART',current_module.localsymtable,'');
  2548. { Darwin's linker does not like two global labels both pointing to the
  2549. end of a section, which can happen in case of units without code ->
  2550. make them local; we don't need the debugtable stuff there either,
  2551. so it doesn't matter that they are not global.
  2552. }
  2553. if (target_info.system in systems_darwin) then
  2554. dbgname:='L'+dbgname;
  2555. new_section(current_asmdata.asmlists[al_start],sec_code,dbgname,0,secorder_begin);
  2556. if not(target_info.system in systems_darwin) then
  2557. current_asmdata.asmlists[al_start].concat(tai_symbol.Createname_global(dbgname,AT_DATA,0))
  2558. else
  2559. current_asmdata.asmlists[al_start].concat(tai_symbol.Createname(dbgname,AT_DATA,0));
  2560. dbgname:=make_mangledname('DEBUGEND',current_module.localsymtable,'');
  2561. { See above. }
  2562. if (target_info.system in systems_darwin) then
  2563. dbgname:='L'+dbgname;
  2564. new_section(current_asmdata.asmlists[al_end],sec_code,dbgname,0,secorder_end);
  2565. if not(target_info.system in systems_darwin) then
  2566. current_asmdata.asmlists[al_end].concat(tai_symbol.Createname_global(dbgname,AT_DATA,0))
  2567. else
  2568. current_asmdata.asmlists[al_end].concat(tai_symbol.Createname(dbgname,AT_DATA,0));
  2569. { insert .Ldebug_abbrev0 label }
  2570. templist:=TAsmList.create;
  2571. new_section(templist,sec_debug_abbrev,'',0);
  2572. templist.concat(tai_symbol.createname(target_asm.labelprefix+'debug_abbrevsection0',AT_DATA,0));
  2573. { add any extra stuff which needs to be in the abbrev section, but before }
  2574. { the actual abbreviations, in between the symbol above and below, i.e. here }
  2575. templist.concat(tai_symbol.createname(target_asm.labelprefix+'debug_abbrev0',AT_DATA,0));
  2576. current_asmdata.asmlists[al_start].insertlist(templist);
  2577. templist.free;
  2578. { insert .Ldebug_line0 label }
  2579. templist:=TAsmList.create;
  2580. new_section(templist,sec_debug_line,'',0);
  2581. templist.concat(tai_symbol.createname(target_asm.labelprefix+'debug_linesection0',AT_DATA,0));
  2582. { add any extra stuff which needs to be in the line section, but before }
  2583. { the actual line info, in between the symbol above and below, i.e. here }
  2584. templist.concat(tai_symbol.createname(target_asm.labelprefix+'debug_line0',AT_DATA,0));
  2585. current_asmdata.asmlists[al_start].insertlist(templist);
  2586. templist.free;
  2587. { finalize line info if the unit doesn't contain any function/ }
  2588. { procedure/init/final code }
  2589. finish_lineinfo;
  2590. { debug line header }
  2591. linelist := current_asmdata.asmlists[al_dwarf_line];
  2592. new_section(linelist,sec_debug_line,'',0);
  2593. linelist.concat(tai_comment.Create(strpnew('=== header start ===')));
  2594. { size }
  2595. current_asmdata.getlabel(lbl,alt_dbgfile);
  2596. if use_64bit_headers then
  2597. linelist.concat(tai_const.create_32bit(longint($FFFFFFFF)));
  2598. linelist.concat(tai_const.create_rel_sym(offsetreltype,
  2599. lbl,current_asmdata.RefAsmSymbol(target_asm.labelprefix+'edebug_line0')));
  2600. linelist.concat(tai_label.create(lbl));
  2601. { version }
  2602. linelist.concat(tai_const.create_16bit(dwarf_version));
  2603. { header length }
  2604. current_asmdata.getlabel(lbl,alt_dbgfile);
  2605. linelist.concat(tai_const.create_rel_sym(offsetreltype,
  2606. lbl,current_asmdata.RefAsmSymbol(target_asm.labelprefix+'ehdebug_line0')));
  2607. linelist.concat(tai_label.create(lbl));
  2608. { minimum_instruction_length }
  2609. linelist.concat(tai_const.create_8bit(1));
  2610. { default_is_stmt }
  2611. linelist.concat(tai_const.create_8bit(1));
  2612. { line_base }
  2613. linelist.concat(tai_const.create_8bit(LINE_BASE));
  2614. { line_range }
  2615. { only line increase, no adress }
  2616. linelist.concat(tai_const.create_8bit(255));
  2617. { opcode_base }
  2618. linelist.concat(tai_const.create_8bit(OPCODE_BASE));
  2619. { standard_opcode_lengths }
  2620. { MWE: sigh... why adding the default lengths (and make those sizes sense with LEB encoding) }
  2621. { DW_LNS_copy }
  2622. linelist.concat(tai_const.create_8bit(0));
  2623. { DW_LNS_advance_pc }
  2624. linelist.concat(tai_const.create_8bit(1));
  2625. { DW_LNS_advance_line }
  2626. linelist.concat(tai_const.create_8bit(1));
  2627. { DW_LNS_set_file }
  2628. linelist.concat(tai_const.create_8bit(1));
  2629. { DW_LNS_set_column }
  2630. linelist.concat(tai_const.create_8bit(1));
  2631. { DW_LNS_negate_stmt }
  2632. linelist.concat(tai_const.create_8bit(0));
  2633. { DW_LNS_set_basic_block }
  2634. linelist.concat(tai_const.create_8bit(0));
  2635. { DW_LNS_const_add_pc }
  2636. linelist.concat(tai_const.create_8bit(0));
  2637. { DW_LNS_fixed_advance_pc }
  2638. linelist.concat(tai_const.create_8bit(1));
  2639. { DW_LNS_set_prologue_end }
  2640. linelist.concat(tai_const.create_8bit(0));
  2641. { DW_LNS_set_epilogue_begin }
  2642. linelist.concat(tai_const.create_8bit(0));
  2643. { DW_LNS_set_isa }
  2644. linelist.concat(tai_const.create_8bit(1));
  2645. { Create single list of filenames sorted in IndexNr }
  2646. flist:=TFPList.Create;
  2647. for n := 0 to dirlist.Count - 1 do
  2648. begin
  2649. ditem := TDirIndexItem(dirlist[n]);
  2650. for m := 0 to ditem.Files.Count - 1 do
  2651. flist.Add(ditem.Files[m]);
  2652. end;
  2653. flist.Sort(@FileListSortCompare);
  2654. { include_directories }
  2655. linelist.concat(tai_comment.Create(strpnew('include_directories')));
  2656. for n := 0 to dirlist.Count - 1 do
  2657. begin
  2658. ditem := TDirIndexItem(dirlist[n]);
  2659. if ditem.Name = '.' then
  2660. Continue;
  2661. { Write without trailing path delimiter and also don't prefix with ./ for current dir (already done while adding to dirlist }
  2662. linelist.concat(tai_string.create(ditem.Name+#0));
  2663. end;
  2664. linelist.concat(tai_const.create_8bit(0));
  2665. { file_names }
  2666. linelist.concat(tai_comment.Create(strpnew('file_names')));
  2667. for n := 0 to flist.Count - 1 do
  2668. begin
  2669. fitem := TFileIndexItem(flist[n]);
  2670. { file name }
  2671. linelist.concat(tai_string.create(fitem.Name+#0));
  2672. { directory index }
  2673. linelist.concat(tai_const.create_uleb128bit(fitem.DirIndex));
  2674. { last modification }
  2675. linelist.concat(tai_const.create_uleb128bit(0));
  2676. { file length }
  2677. linelist.concat(tai_const.create_uleb128bit(0));
  2678. end;
  2679. linelist.concat(tai_const.create_8bit(0));
  2680. { end of debug line header }
  2681. linelist.concat(tai_symbol.createname(target_asm.labelprefix+'ehdebug_line0',AT_DATA,0));
  2682. linelist.concat(tai_comment.Create(strpnew('=== header end ===')));
  2683. { add line program }
  2684. linelist.concatList(asmline);
  2685. { end of debug line table }
  2686. linelist.concat(tai_symbol.createname(target_asm.labelprefix+'edebug_line0',AT_DATA,0));
  2687. flist.free;
  2688. end;
  2689. procedure TDebugInfoDwarf.inserttypeinfo;
  2690. var
  2691. storefilepos : tfileposinfo;
  2692. lenstartlabel : tasmlabel;
  2693. i : longint;
  2694. def: tdef;
  2695. dbgname: string;
  2696. vardatatype: ttypesym;
  2697. begin
  2698. current_module.flags:=current_module.flags or uf_has_dwarf_debuginfo;
  2699. storefilepos:=current_filepos;
  2700. current_filepos:=current_module.mainfilepos;
  2701. currabbrevnumber:=0;
  2702. defnumberlist:=TFPObjectList.create(false);
  2703. deftowritelist:=TFPObjectList.create(false);
  2704. { not exported (FK)
  2705. FILEREC
  2706. TEXTREC
  2707. }
  2708. vardatatype:=try_search_system_type('TVARDATA');
  2709. if assigned(vardatatype) then
  2710. vardatadef:=trecorddef(vardatatype.typedef);
  2711. { write start labels }
  2712. new_section(current_asmdata.asmlists[al_dwarf_info],sec_debug_info,'',0);
  2713. current_asmdata.asmlists[al_dwarf_info].concat(tai_symbol.createname(target_asm.labelprefix+'debug_info0',AT_DATA,0));
  2714. { start abbrev section }
  2715. new_section(current_asmdata.asmlists[al_dwarf_abbrev],sec_debug_abbrev,'',0);
  2716. { debug info header }
  2717. current_asmdata.getlabel(lenstartlabel,alt_dbgfile);
  2718. { size }
  2719. if use_64bit_headers then
  2720. current_asmdata.asmlists[al_dwarf_info].concat(tai_const.create_32bit(longint($FFFFFFFF)));
  2721. current_asmdata.asmlists[al_dwarf_info].concat(tai_const.create_rel_sym(offsetreltype,
  2722. lenstartlabel,current_asmdata.RefAsmSymbol(target_asm.labelprefix+'edebug_info0')));
  2723. current_asmdata.asmlists[al_dwarf_info].concat(tai_label.create(lenstartlabel));
  2724. { version }
  2725. current_asmdata.asmlists[al_dwarf_info].concat(tai_const.create_16bit(dwarf_version));
  2726. { abbrev table (=relative from section start)}
  2727. if not(tf_dwarf_relative_addresses in target_info.flags) then
  2728. current_asmdata.asmlists[al_dwarf_info].concat(tai_const.create_type_sym(offsetabstype,
  2729. current_asmdata.RefAsmSymbol(target_asm.labelprefix+'debug_abbrev0')))
  2730. else
  2731. current_asmdata.asmlists[al_dwarf_info].concat(tai_const.create_rel_sym(offsetreltype,
  2732. current_asmdata.RefAsmSymbol(target_asm.labelprefix+'debug_abbrevsection0'),
  2733. current_asmdata.RefAsmSymbol(target_asm.labelprefix+'debug_abbrev0')));
  2734. { address size }
  2735. current_asmdata.asmlists[al_dwarf_info].concat(tai_const.create_8bit(sizeof(pint)));
  2736. { first manadatory compilation unit TAG }
  2737. append_entry(DW_TAG_compile_unit,true,[
  2738. DW_AT_name,DW_FORM_string,relative_dwarf_path(current_module.sourcefiles.get_file(1).path^+current_module.sourcefiles.get_file(1).name^)+#0,
  2739. DW_AT_producer,DW_FORM_string,'Free Pascal '+full_version_string+' '+date_string+#0,
  2740. DW_AT_comp_dir,DW_FORM_string,BSToSlash(FixPath(GetCurrentDir,false))+#0,
  2741. DW_AT_language,DW_FORM_data1,DW_LANG_Pascal83,
  2742. DW_AT_identifier_case,DW_FORM_data1,DW_ID_case_insensitive]);
  2743. { reference to line info section }
  2744. if not(tf_dwarf_relative_addresses in target_info.flags) then
  2745. append_labelentry_dataptr_abs(DW_AT_stmt_list,current_asmdata.RefAsmSymbol(target_asm.labelprefix+'debug_line0'))
  2746. else
  2747. append_labelentry_dataptr_rel(DW_AT_stmt_list,
  2748. current_asmdata.RefAsmSymbol(target_asm.labelprefix+'debug_linesection0'),
  2749. current_asmdata.RefAsmSymbol(target_asm.labelprefix+'debug_line0'));
  2750. if (m_objectivec1 in current_settings.modeswitches) then
  2751. append_attribute(DW_AT_APPLE_major_runtime_vers,DW_FORM_data1,[1]);
  2752. dbgname:=make_mangledname('DEBUGSTART',current_module.localsymtable,'');
  2753. if (target_info.system in systems_darwin) then
  2754. dbgname:='L'+dbgname;
  2755. append_labelentry(DW_AT_low_pc,current_asmdata.RefAsmSymbol(dbgname));
  2756. dbgname:=make_mangledname('DEBUGEND',current_module.localsymtable,'');
  2757. if (target_info.system in systems_darwin) then
  2758. dbgname:='L'+dbgname;
  2759. append_labelentry(DW_AT_high_pc,current_asmdata.RefAsmSymbol(dbgname));
  2760. finish_entry;
  2761. { write all global/local variables. This will flag all required tdefs }
  2762. if assigned(current_module.globalsymtable) then
  2763. write_symtable_syms(current_asmdata.asmlists[al_dwarf_info],current_module.globalsymtable);
  2764. if assigned(current_module.localsymtable) then
  2765. write_symtable_syms(current_asmdata.asmlists[al_dwarf_info],current_module.localsymtable);
  2766. { write all procedures and methods. This will flag all required tdefs }
  2767. if assigned(current_module.globalsymtable) then
  2768. write_symtable_procdefs(current_asmdata.asmlists[al_dwarf_info],current_module.globalsymtable);
  2769. if assigned(current_module.localsymtable) then
  2770. write_symtable_procdefs(current_asmdata.asmlists[al_dwarf_info],current_module.localsymtable);
  2771. { reset unit type info flag }
  2772. reset_unit_type_info;
  2773. { write used types from the used units }
  2774. write_used_unit_type_info(current_asmdata.asmlists[al_dwarf_info],current_module);
  2775. { last write the types from this unit }
  2776. if assigned(current_module.globalsymtable) then
  2777. write_symtable_defs(current_asmdata.asmlists[al_dwarf_info],current_module.globalsymtable);
  2778. if assigned(current_module.localsymtable) then
  2779. write_symtable_defs(current_asmdata.asmlists[al_dwarf_info],current_module.localsymtable);
  2780. { write defs not written yet }
  2781. write_remaining_defs_to_write(current_asmdata.asmlists[al_dwarf_info]);
  2782. { close compilation unit entry }
  2783. finish_children;
  2784. { end of debug info table }
  2785. current_asmdata.asmlists[al_dwarf_info].concat(tai_symbol.createname(target_asm.labelprefix+'edebug_info0',AT_DATA,0));
  2786. { end of abbrev table }
  2787. current_asmdata.asmlists[al_dwarf_abbrev].concat(tai_const.create_8bit(0));
  2788. { reset all def labels }
  2789. for i:=0 to defnumberlist.count-1 do
  2790. begin
  2791. def := tdef(defnumberlist[i]);
  2792. if assigned(def) then
  2793. begin
  2794. def.dwarf_lab:=nil;
  2795. def.dbg_state:=dbg_state_unused;
  2796. end;
  2797. end;
  2798. defnumberlist.free;
  2799. defnumberlist:=nil;
  2800. deftowritelist.free;
  2801. deftowritelist:=nil;
  2802. current_filepos:=storefilepos;
  2803. end;
  2804. procedure TDebugInfoDwarf.referencesections(list:TAsmList);
  2805. var
  2806. hp : tmodule;
  2807. begin
  2808. { Reference all DEBUGINFO sections from the main .fpc section }
  2809. { to prevent eliminating them by smartlinking }
  2810. if (target_info.system in ([system_powerpc_macos]+systems_darwin)) then
  2811. exit;
  2812. new_section(list,sec_fpc,'links',0);
  2813. { include reference to all debuginfo sections of used units }
  2814. hp:=tmodule(loaded_units.first);
  2815. while assigned(hp) do
  2816. begin
  2817. If (hp.flags and uf_has_dwarf_debuginfo)=uf_has_dwarf_debuginfo then
  2818. begin
  2819. list.concat(Tai_const.Createname(make_mangledname('DEBUGSTART',hp.localsymtable,''),0));
  2820. list.concat(Tai_const.Createname(make_mangledname('DEBUGEND',hp.localsymtable,''),0));
  2821. end;
  2822. hp:=tmodule(hp.next);
  2823. end;
  2824. end;
  2825. function TDebugInfoDwarf.symname(sym: tsym): String;
  2826. begin
  2827. if (sym.typ=paravarsym) and
  2828. (vo_is_self in tparavarsym(sym).varoptions) then
  2829. { We use 'this' for regular methods because that's what gdb triggers
  2830. on to automatically search fields. Don't do this for class methods,
  2831. because search class fields is not supported, and gdb 7.0+ fails
  2832. in this case because "this" is not a record in that case (it's a
  2833. pointer to a vmt) }
  2834. if not is_objc_class_or_protocol(tdef(sym.owner.defowner.owner.defowner)) and
  2835. not(po_classmethod in tabstractprocdef(sym.owner.defowner).procoptions) then
  2836. result:='this'
  2837. else
  2838. result:='self'
  2839. else if (sym.typ=typesym) and
  2840. is_objc_class_or_protocol(ttypesym(sym).typedef) then
  2841. result:=tobjectdef(ttypesym(sym).typedef).objextname^
  2842. else if (ds_dwarf_method_class_prefix in current_settings.debugswitches) and
  2843. (sym.typ=procsym) and
  2844. (tprocsym(sym).owner.symtabletype in [objectsymtable,recordsymtable]) then
  2845. result:=tprocsym(sym).owner.name^+'__'+sym.name
  2846. else
  2847. result:=sym.name;
  2848. end;
  2849. procedure tdebuginfodwarf.append_visibility(vis: tvisibility);
  2850. begin
  2851. case vis of
  2852. vis_private,
  2853. vis_strictprivate:
  2854. append_attribute(DW_AT_accessibility,DW_FORM_data1,[ord(DW_ACCESS_private)]);
  2855. vis_protected,
  2856. vis_strictprotected:
  2857. append_attribute(DW_AT_accessibility,DW_FORM_data1,[ord(DW_ACCESS_protected)]);
  2858. vis_public:
  2859. { default };
  2860. end;
  2861. end;
  2862. procedure TDebugInfoDwarf.insertlineinfo(list:TAsmList);
  2863. var
  2864. currfileinfo,
  2865. lastfileinfo : tfileposinfo;
  2866. currfuncname : pshortstring;
  2867. currsectype : TAsmSectiontype;
  2868. hp, hpend : tai;
  2869. infile : tinputfile;
  2870. prevcolumn,
  2871. diffline,
  2872. prevline,
  2873. prevfileidx,
  2874. currfileidx,
  2875. nolineinfolevel : Integer;
  2876. prevlabel,
  2877. currlabel : tasmlabel;
  2878. begin
  2879. { this function will always terminate the lineinfo block }
  2880. generated_lineinfo := true;
  2881. FillChar(lastfileinfo,sizeof(lastfileinfo),0);
  2882. currfuncname:=nil;
  2883. currsectype:=sec_code;
  2884. hp:=Tai(list.first);
  2885. prevcolumn := 0;
  2886. prevline := 1;
  2887. prevfileidx := 1;
  2888. prevlabel := nil;
  2889. nolineinfolevel:=0;
  2890. while assigned(hp) do
  2891. begin
  2892. case hp.typ of
  2893. ait_section :
  2894. currsectype:=tai_section(hp).sectype;
  2895. ait_function_name :
  2896. begin
  2897. currfuncname:=tai_function_name(hp).funcname;
  2898. asmline.concat(tai_comment.Create(strpnew('function: '+currfuncname^)));
  2899. end;
  2900. ait_force_line :
  2901. begin
  2902. lastfileinfo.line:=-1;
  2903. end;
  2904. ait_marker :
  2905. begin
  2906. case tai_marker(hp).kind of
  2907. mark_NoLineInfoStart:
  2908. inc(nolineinfolevel);
  2909. mark_NoLineInfoEnd:
  2910. dec(nolineinfolevel);
  2911. end;
  2912. end;
  2913. end;
  2914. if (currsectype=sec_code) and
  2915. (hp.typ=ait_instruction) and
  2916. (nolineinfolevel=0) then
  2917. begin
  2918. currfileinfo:=tailineinfo(hp).fileinfo;
  2919. { file changed ? (must be before line info) }
  2920. if (currfileinfo.fileindex<>0) and
  2921. ((lastfileinfo.fileindex<>currfileinfo.fileindex) or
  2922. (lastfileinfo.moduleindex<>currfileinfo.moduleindex)) then
  2923. begin
  2924. infile:=get_module(currfileinfo.moduleindex).sourcefiles.get_file(currfileinfo.fileindex);
  2925. if assigned(infile) then
  2926. begin
  2927. currfileidx := get_file_index(infile);
  2928. if prevfileidx <> currfileidx then
  2929. begin
  2930. list.insertbefore(tai_comment.Create(strpnew('path: '+infile.path^)), hp);
  2931. list.insertbefore(tai_comment.Create(strpnew('file: '+infile.name^)), hp);
  2932. list.insertbefore(tai_comment.Create(strpnew('indx: '+tostr(currfileidx))), hp);
  2933. { set file }
  2934. asmline.concat(tai_comment.Create(strpnew('path: '+infile.path^)));
  2935. asmline.concat(tai_comment.Create(strpnew('file: '+infile.name^)));
  2936. asmline.concat(tai_const.create_8bit(DW_LNS_set_file));
  2937. asmline.concat(tai_const.create_uleb128bit(currfileidx));
  2938. prevfileidx := currfileidx;
  2939. end;
  2940. { force new line info }
  2941. lastfileinfo.line:=-1;
  2942. end;
  2943. end;
  2944. { line changed ? }
  2945. if (lastfileinfo.line<>currfileinfo.line) and (currfileinfo.line<>0) then
  2946. begin
  2947. { set address }
  2948. current_asmdata.getlabel(currlabel, alt_dbgline);
  2949. list.insertbefore(tai_label.create(currlabel), hp);
  2950. asmline.concat(tai_comment.Create(strpnew('['+tostr(currfileinfo.line)+':'+tostr(currfileinfo.column)+']')));
  2951. if (prevlabel = nil) or
  2952. { darwin's assembler cannot create an uleb128 of the difference }
  2953. { between to symbols }
  2954. (target_info.system in systems_darwin) then
  2955. begin
  2956. asmline.concat(tai_const.create_8bit(DW_LNS_extended_op));
  2957. asmline.concat(tai_const.create_uleb128bit(1+sizeof(pint)));
  2958. asmline.concat(tai_const.create_8bit(DW_LNE_set_address));
  2959. asmline.concat(tai_const.create_sym(currlabel));
  2960. end
  2961. else
  2962. begin
  2963. asmline.concat(tai_const.create_8bit(DW_LNS_advance_pc));
  2964. asmline.concat(tai_const.create_rel_sym(aitconst_uleb128bit, prevlabel, currlabel));
  2965. end;
  2966. prevlabel := currlabel;
  2967. { set column }
  2968. if prevcolumn <> currfileinfo.column then
  2969. begin
  2970. asmline.concat(tai_const.create_8bit(DW_LNS_set_column));
  2971. asmline.concat(tai_const.create_uleb128bit(currfileinfo.column));
  2972. prevcolumn := currfileinfo.column;
  2973. end;
  2974. { set line }
  2975. diffline := currfileinfo.line - prevline;
  2976. if (diffline >= LINE_BASE) and (OPCODE_BASE + diffline - LINE_BASE <= 255) then
  2977. begin
  2978. { use special opcode, this also adds a row }
  2979. asmline.concat(tai_const.create_8bit(OPCODE_BASE + diffline - LINE_BASE));
  2980. end
  2981. else
  2982. begin
  2983. if diffline <> 0 then
  2984. begin
  2985. asmline.concat(tai_const.create_8bit(DW_LNS_advance_line));
  2986. asmline.concat(tai_const.create_sleb128bit(diffline));
  2987. end;
  2988. { no row added yet, do it manually }
  2989. asmline.concat(tai_const.create_8bit(DW_LNS_copy));
  2990. end;
  2991. prevline := currfileinfo.line;
  2992. end;
  2993. lastfileinfo:=currfileinfo;
  2994. end;
  2995. hpend:=hp;
  2996. hp:=tai(hp.next);
  2997. end;
  2998. if assigned(hpend) then
  2999. begin
  3000. { set address for end (see appendix 3 of dwarf 2 specs) }
  3001. current_asmdata.getlabel(currlabel, alt_dbgline);
  3002. list.insertafter(tai_label.create(currlabel), hpend);
  3003. asmline.concat(tai_const.create_8bit(DW_LNS_extended_op));
  3004. asmline.concat(tai_const.create_uleb128bit(1+sizeof(pint)));
  3005. asmline.concat(tai_const.create_8bit(DW_LNE_set_address));
  3006. asmline.concat(tai_const.create_sym(currlabel));
  3007. end;
  3008. { end sequence }
  3009. asmline.concat(tai_const.Create_8bit(DW_LNS_extended_op));
  3010. asmline.concat(tai_const.Create_8bit(1));
  3011. asmline.concat(tai_const.Create_8bit(DW_LNE_end_sequence));
  3012. asmline.concat(tai_comment.Create(strpnew('###################')));
  3013. end;
  3014. procedure TDebugInfoDwarf.finish_lineinfo;
  3015. var
  3016. infile: tinputfile;
  3017. begin
  3018. { only needed if no line info at all has been generated }
  3019. if generated_lineinfo then
  3020. begin
  3021. { reset for next module compilation }
  3022. generated_lineinfo:=false;
  3023. exit;
  3024. end;
  3025. { at least the Darwin linker is annoyed if you do not }
  3026. { finish the lineinfo section, or if it doesn't }
  3027. { contain at least one file name and set_address }
  3028. infile:=current_module.sourcefiles.get_file(1);
  3029. if not assigned(infile) then
  3030. internalerror(2006020211);
  3031. asmline.concat(tai_const.create_8bit(DW_LNS_set_file));
  3032. asmline.concat(tai_const.create_uleb128bit(get_file_index(infile)));
  3033. asmline.concat(tai_const.create_8bit(DW_LNS_extended_op));
  3034. asmline.concat(tai_const.create_uleb128bit(1+sizeof(pint)));
  3035. asmline.concat(tai_const.create_8bit(DW_LNE_set_address));
  3036. asmline.concat(tai_const.create_sym(nil));
  3037. asmline.concat(tai_const.create_8bit(DW_LNS_extended_op));
  3038. asmline.concat(tai_const.Create_8bit(1));
  3039. asmline.concat(tai_const.Create_8bit(DW_LNE_end_sequence));
  3040. asmline.concat(tai_comment.Create(strpnew('###################')));
  3041. end;
  3042. {****************************************************************************
  3043. TDebugInfoDwarf2
  3044. ****************************************************************************}
  3045. procedure TDebugInfoDwarf2.appenddef_file(list:TAsmList;def: tfiledef);
  3046. begin
  3047. { gdb 6.4 doesn't support files so far so we use some fake recorddef
  3048. file recs. are less than 1k so using data2 is enough }
  3049. if assigned(def.typesym) then
  3050. append_entry(DW_TAG_structure_type,false,[
  3051. DW_AT_name,DW_FORM_string,symname(def.typesym)+#0,
  3052. DW_AT_byte_size,DW_FORM_udata,def.size
  3053. ])
  3054. else
  3055. append_entry(DW_TAG_structure_type,false,[
  3056. DW_AT_byte_size,DW_FORM_udata,def.size
  3057. ]);
  3058. finish_entry;
  3059. end;
  3060. procedure TDebugInfoDwarf2.appenddef_formal(list:TAsmList;def: tformaldef);
  3061. begin
  3062. { gdb 6.4 doesn't support DW_TAG_unspecified_type so we
  3063. replace it with a unsigned type with size 0 (FK)
  3064. }
  3065. append_entry(DW_TAG_base_type,false,[
  3066. DW_AT_name,DW_FORM_string,'FormalDef'#0,
  3067. DW_AT_encoding,DW_FORM_data1,DW_ATE_unsigned,
  3068. DW_AT_byte_size,DW_FORM_data1,0
  3069. ]);
  3070. finish_entry;
  3071. end;
  3072. procedure TDebugInfoDwarf2.append_object_struct(def: tobjectdef; const createlabel: boolean; const objectname: PShortString);
  3073. begin
  3074. if createlabel then
  3075. begin
  3076. if not(tf_dwarf_only_local_labels in target_info.flags) then
  3077. current_asmdata.asmlists[al_dwarf_info].concat(tai_symbol.create_global(def_dwarf_class_struct_lab(def),0))
  3078. else
  3079. current_asmdata.asmlists[al_dwarf_info].concat(tai_symbol.create(def_dwarf_class_struct_lab(def),0));
  3080. end;
  3081. if assigned(objectname) then
  3082. append_entry(DW_TAG_structure_type,true,[
  3083. DW_AT_name,DW_FORM_string,objectname^+#0,
  3084. DW_AT_byte_size,DW_FORM_udata,tobjectsymtable(def.symtable).datasize
  3085. ])
  3086. else
  3087. append_entry(DW_TAG_structure_type,true,[
  3088. DW_AT_byte_size,DW_FORM_udata,tobjectsymtable(def.symtable).datasize
  3089. ]);
  3090. { Apple-specific tag that identifies it as an Objective-C class }
  3091. if (def.objecttype=odt_objcclass) then
  3092. append_attribute(DW_AT_APPLE_runtime_class,DW_FORM_data1,[DW_LANG_ObjC]);
  3093. finish_entry;
  3094. if assigned(def.childof) then
  3095. begin
  3096. append_entry(DW_TAG_inheritance,false,[
  3097. DW_AT_accessibility,DW_FORM_data1,DW_ACCESS_public,
  3098. DW_AT_data_member_location,DW_FORM_block1,1+lengthuleb128(0)
  3099. ]);
  3100. current_asmdata.asmlists[al_dwarf_info].concat(tai_const.create_8bit(ord(DW_OP_plus_uconst)));
  3101. current_asmdata.asmlists[al_dwarf_info].concat(tai_const.create_uleb128bit(0));
  3102. if (def.childof.dbg_state=dbg_state_unused) then
  3103. def.childof.dbg_state:=dbg_state_used;
  3104. if is_implicit_pointer_object_type(def) then
  3105. append_labelentry_ref(DW_AT_type,def_dwarf_class_struct_lab(def.childof))
  3106. else
  3107. append_labelentry_ref(DW_AT_type,def_dwarf_lab(def.childof));
  3108. finish_entry;
  3109. end;
  3110. if (oo_has_vmt in def.objectoptions) and
  3111. (not assigned(def.childof) or
  3112. not(oo_has_vmt in def.childof.objectoptions)) then
  3113. begin
  3114. { vmt field }
  3115. append_entry(DW_TAG_member,false,[
  3116. DW_AT_artificial,DW_FORM_flag,true,
  3117. DW_AT_name,DW_FORM_string,'_vptr$'+def.objname^+#0,
  3118. DW_AT_data_member_location,DW_FORM_block1,1+lengthuleb128(def.vmt_offset)
  3119. ]);
  3120. current_asmdata.asmlists[al_dwarf_info].concat(tai_const.create_8bit(ord(DW_OP_plus_uconst)));
  3121. current_asmdata.asmlists[al_dwarf_info].concat(tai_const.create_uleb128bit(def.vmt_offset));
  3122. { should be changed into a pointer to a function returning an }
  3123. { int and with TAG_unspecified_parameters }
  3124. if (voidpointertype.dbg_state=dbg_state_unused) then
  3125. voidpointertype.dbg_state:=dbg_state_used;
  3126. append_labelentry_ref(DW_AT_type,def_dwarf_lab(voidpointertype));
  3127. finish_entry;
  3128. end;
  3129. def.symtable.symList.ForEachCall(@enum_membersyms_callback,nil);
  3130. { Write the methods in the scope of the class/object, except for Objective-C. }
  3131. if is_objc_class_or_protocol(def) then
  3132. finish_children;
  3133. { don't write procdefs of externally defined classes, gcc doesn't
  3134. either (info is probably gotten from ObjC runtime) }
  3135. if not(oo_is_external in def.objectoptions) then
  3136. write_symtable_procdefs(current_asmdata.asmlists[al_dwarf_info],def.symtable);
  3137. if not is_objc_class_or_protocol(def) then
  3138. finish_children;
  3139. end;
  3140. procedure TDebugInfoDwarf2.appenddef_object(list:TAsmList;def: tobjectdef);
  3141. begin
  3142. case def.objecttype of
  3143. odt_cppclass,
  3144. odt_object:
  3145. append_object_struct(def,false,def.objname);
  3146. odt_interfacecom,
  3147. odt_interfacecorba,
  3148. odt_dispinterface,
  3149. odt_class:
  3150. begin
  3151. { implicit pointer }
  3152. append_entry(DW_TAG_pointer_type,false,[]);
  3153. append_labelentry_ref(DW_AT_type,def_dwarf_class_struct_lab(def));
  3154. finish_entry;
  3155. append_object_struct(def,true,def.objname);
  3156. end;
  3157. odt_objcclass:
  3158. { Objective-C class: same as regular class, except for
  3159. a) Apple-specific tag that identifies it as an Objective-C class
  3160. b) use extname^ instead of objname
  3161. }
  3162. append_object_struct(def,true,def.objextname);
  3163. odt_objcprotocol:
  3164. begin
  3165. append_entry(DW_TAG_pointer_type,false,[]);
  3166. append_labelentry_ref(DW_AT_type,def_dwarf_lab(voidpointertype));
  3167. finish_entry;
  3168. end;
  3169. else
  3170. internalerror(200602041);
  3171. end;
  3172. end;
  3173. procedure TDebugInfoDwarf2.appenddef_set_intern(list:TAsmList;def: tsetdef; force_tag_set: boolean);
  3174. var
  3175. lab: tasmlabel;
  3176. begin
  3177. if force_tag_set or
  3178. (ds_dwarf_sets in current_settings.debugswitches) then
  3179. begin
  3180. { current (20070704 -- patch was committed on 20060513) gdb cvs supports set types }
  3181. if assigned(def.typesym) then
  3182. append_entry(DW_TAG_set_type,false,[
  3183. DW_AT_name,DW_FORM_string,symname(def.typesym)+#0,
  3184. DW_AT_byte_size,DW_FORM_data2,def.size
  3185. ])
  3186. else
  3187. append_entry(DW_TAG_set_type,false,[
  3188. DW_AT_byte_size,DW_FORM_data2,def.size
  3189. ]);
  3190. if assigned(def.elementdef) then
  3191. begin
  3192. if not(tf_dwarf_only_local_labels in target_info.flags) then
  3193. current_asmdata.getdatalabel(lab)
  3194. else
  3195. current_asmdata.getaddrlabel(lab);
  3196. append_labelentry_ref(DW_AT_type,lab);
  3197. finish_entry;
  3198. current_asmdata.asmlists[al_dwarf_info].concat(tai_symbol.create(lab,0));
  3199. { Sets of e.g. [1..5] are actually stored as a set of [0..7],
  3200. so write the exact boundaries of the set here. Let's hope no
  3201. debugger ever rejects this because this "subrange" type can
  3202. actually have a larger range than the original one. }
  3203. append_entry(DW_TAG_subrange_type,false,[
  3204. DW_AT_lower_bound,DW_FORM_sdata,def.setbase,
  3205. DW_AT_upper_bound,DW_FORM_sdata,get_max_value(def.elementdef).svalue
  3206. ]);
  3207. append_labelentry_ref(DW_AT_type,def_dwarf_lab(def.elementdef))
  3208. end
  3209. end
  3210. else
  3211. begin
  3212. { gdb versions which don't support sets refuse to load the debug }
  3213. { info of modules that contain set tags }
  3214. if assigned(def.typesym) then
  3215. append_entry(DW_TAG_base_type,false,[
  3216. DW_AT_name,DW_FORM_string,symname(def.typesym)+#0,
  3217. DW_AT_encoding,DW_FORM_data1,DW_ATE_unsigned,
  3218. DW_AT_byte_size,DW_FORM_data2,def.size
  3219. ])
  3220. else
  3221. append_entry(DW_TAG_base_type,false,[
  3222. DW_AT_encoding,DW_FORM_data1,DW_ATE_unsigned,
  3223. DW_AT_byte_size,DW_FORM_data2,def.size
  3224. ]);
  3225. end;
  3226. finish_entry;
  3227. end;
  3228. procedure TDebugInfoDwarf2.appenddef_set(list:TAsmList;def: tsetdef);
  3229. begin
  3230. appenddef_set_intern(list,def,false);
  3231. end;
  3232. procedure TDebugInfoDwarf2.appenddef_undefined(list:TAsmList;def: tundefineddef);
  3233. begin
  3234. { gdb 6.4 doesn't support DW_TAG_unspecified_type so we
  3235. replace it with a unsigned type with size 0 (FK)
  3236. }
  3237. append_entry(DW_TAG_base_type,false,[
  3238. DW_AT_name,DW_FORM_string,'FormalDef'#0,
  3239. DW_AT_encoding,DW_FORM_data1,DW_ATE_unsigned,
  3240. DW_AT_byte_size,DW_FORM_data1,0
  3241. ]);
  3242. finish_entry;
  3243. end;
  3244. procedure TDebugInfoDwarf2.appenddef_variant(list:TAsmList;def: tvariantdef);
  3245. begin
  3246. { variants aren't known to dwarf2 but writting tvardata should be enough }
  3247. if assigned(vardatadef) then
  3248. appenddef_record_named(list,trecorddef(vardatadef),'Variant');
  3249. end;
  3250. function TDebugInfoDwarf2.dwarf_version: Word;
  3251. begin
  3252. Result:=2;
  3253. end;
  3254. {****************************************************************************
  3255. TDebugInfoDwarf3
  3256. ****************************************************************************}
  3257. procedure TDebugInfoDwarf3.append_labelentry_addr_ref(attr : tdwarf_attribute;sym : tasmsymbol);
  3258. begin
  3259. AddConstToAbbrev(ord(DW_FORM_ref_addr));
  3260. { Since Dwarf 3 the length of a DW_FORM_ref_addr entry is not dependent on the pointer size of the
  3261. target platform, but on the used Dwarf-format (32 bit or 64 bit) for the current compilation section. }
  3262. if use_64bit_headers then
  3263. current_asmdata.asmlists[al_dwarf_info].concat(tai_const.Create_type_sym(aitconst_64bit,sym))
  3264. else
  3265. current_asmdata.asmlists[al_dwarf_info].concat(tai_const.Create_type_sym(aitconst_32bit,sym));
  3266. end;
  3267. procedure tdebuginfodwarf3.appenddef_array(list: tasmlist; def: tarraydef);
  3268. begin
  3269. if not is_dynamic_array(def) then
  3270. begin
  3271. inherited appenddef_array(list,def);
  3272. exit;
  3273. end;
  3274. if assigned(def.typesym) then
  3275. append_entry(DW_TAG_array_type,true,[
  3276. DW_AT_name,DW_FORM_string,symname(def.typesym)+#0,
  3277. DW_AT_data_location,DW_FORM_block1,2
  3278. ])
  3279. else
  3280. append_entry(DW_TAG_array_type,true,[
  3281. DW_AT_data_location,DW_FORM_block1,2
  3282. ]);
  3283. current_asmdata.asmlists[al_dwarf_info].concat(tai_const.create_8bit(ord(DW_OP_push_object_address)));
  3284. current_asmdata.asmlists[al_dwarf_info].concat(tai_const.create_8bit(ord(DW_OP_deref)));
  3285. append_labelentry_ref(DW_AT_type,def_dwarf_lab(def.elementdef));
  3286. finish_entry;
  3287. { to simplify things, we don't write a multidimensional array here }
  3288. append_entry(DW_TAG_subrange_type,false,[
  3289. DW_AT_byte_stride,DW_FORM_udata,def.elesize,
  3290. DW_AT_lower_bound,DW_FORM_udata,0,
  3291. DW_AT_upper_bound,DW_FORM_block1,14
  3292. ]);
  3293. current_asmdata.asmlists[al_dwarf_info].concat(tai_const.create_8bit(ord(DW_OP_push_object_address)));
  3294. current_asmdata.asmlists[al_dwarf_info].concat(tai_const.create_8bit(ord(DW_OP_deref)));
  3295. current_asmdata.asmlists[al_dwarf_info].concat(tai_const.create_8bit(ord(DW_OP_dup)));
  3296. { pointer = nil? }
  3297. current_asmdata.asmlists[al_dwarf_info].concat(tai_const.create_8bit(ord(DW_OP_bra)));
  3298. current_asmdata.asmlists[al_dwarf_info].concat(tai_const.create_16bit(5));
  3299. { yes -> length = 0 }
  3300. current_asmdata.asmlists[al_dwarf_info].concat(tai_const.create_8bit(ord(DW_OP_const1s)));
  3301. current_asmdata.asmlists[al_dwarf_info].concat(tai_const.create_8bit(byte(-1)));
  3302. current_asmdata.asmlists[al_dwarf_info].concat(tai_const.create_8bit(ord(DW_OP_skip)));
  3303. current_asmdata.asmlists[al_dwarf_info].concat(tai_const.create_16bit(3));
  3304. { no -> load length }
  3305. current_asmdata.asmlists[al_dwarf_info].concat(tai_const.create_8bit(ord(DW_OP_lit0)+sizeof(ptrint)));
  3306. current_asmdata.asmlists[al_dwarf_info].concat(tai_const.create_8bit(ord(DW_OP_minus)));
  3307. current_asmdata.asmlists[al_dwarf_info].concat(tai_const.create_8bit(ord(DW_OP_deref)));
  3308. append_labelentry_ref(DW_AT_type,def_dwarf_lab(def.rangedef));
  3309. finish_entry;
  3310. finish_children;
  3311. end;
  3312. procedure tdebuginfodwarf3.appenddef_string(list: tasmlist; def: tstringdef);
  3313. procedure addstringdef(const name: shortstring; chardef: tdef; deref: boolean; lensize: aint);
  3314. var
  3315. upperopcodes: longint;
  3316. begin
  3317. { deref=true -> ansi/unicde/widestring; deref = false -> short/longstring }
  3318. if assigned(def.typesym) then
  3319. append_entry(DW_TAG_array_type,true,[
  3320. DW_AT_name,DW_FORM_string,name+#0,
  3321. DW_AT_data_location,DW_FORM_block1,2+ord(not(deref))
  3322. ])
  3323. else
  3324. append_entry(DW_TAG_array_type,true,[
  3325. DW_AT_data_location,DW_FORM_block1,2+ord(not(deref))
  3326. ]);
  3327. { in all cases we start with the address of the string }
  3328. current_asmdata.asmlists[al_dwarf_info].concat(tai_const.create_8bit(ord(DW_OP_push_object_address)));
  3329. if deref then
  3330. begin
  3331. { ansi/unicode/widestring -> dereference the address of the string, and then
  3332. we point to address of the string
  3333. }
  3334. current_asmdata.asmlists[al_dwarf_info].concat(tai_const.create_8bit(ord(DW_OP_deref)));
  3335. end
  3336. else
  3337. begin
  3338. { shortstring characters begin at string[1], so add one to the string's address }
  3339. current_asmdata.asmlists[al_dwarf_info].concat(tai_const.create_8bit(ord(DW_OP_lit0)+lensize));
  3340. current_asmdata.asmlists[al_dwarf_info].concat(tai_const.create_8bit(ord(DW_OP_plus)))
  3341. end;
  3342. { reference to the element type of the string }
  3343. append_labelentry_ref(DW_AT_type,def_dwarf_lab(chardef));
  3344. finish_entry;
  3345. { now the information about the length of the string }
  3346. if deref then
  3347. begin
  3348. if (chardef.size=1) then
  3349. upperopcodes:=13
  3350. else
  3351. upperopcodes:=15;
  3352. { lower bound is always 1, upper bound (length) needs to be calculated }
  3353. append_entry(DW_TAG_subrange_type,false,[
  3354. DW_AT_lower_bound,DW_FORM_udata,1,
  3355. DW_AT_upper_bound,DW_FORM_block1,upperopcodes
  3356. ]);
  3357. { high(string) is stored sizeof(ptrint) bytes before the string data }
  3358. current_asmdata.asmlists[al_dwarf_info].concat(tai_const.create_8bit(ord(DW_OP_push_object_address)));
  3359. current_asmdata.asmlists[al_dwarf_info].concat(tai_const.create_8bit(ord(DW_OP_deref)));
  3360. current_asmdata.asmlists[al_dwarf_info].concat(tai_const.create_8bit(ord(DW_OP_dup)));
  3361. { pointer = nil? }
  3362. current_asmdata.asmlists[al_dwarf_info].concat(tai_const.create_8bit(ord(DW_OP_bra)));
  3363. current_asmdata.asmlists[al_dwarf_info].concat(tai_const.create_16bit(4));
  3364. { yes -> length = 0 }
  3365. current_asmdata.asmlists[al_dwarf_info].concat(tai_const.create_8bit(ord(DW_OP_lit0)));
  3366. current_asmdata.asmlists[al_dwarf_info].concat(tai_const.create_8bit(ord(DW_OP_skip)));
  3367. current_asmdata.asmlists[al_dwarf_info].concat(tai_const.create_16bit(3));
  3368. { no -> load length }
  3369. current_asmdata.asmlists[al_dwarf_info].concat(tai_const.create_8bit(ord(DW_OP_lit0)+sizeof(ptrint)));
  3370. current_asmdata.asmlists[al_dwarf_info].concat(tai_const.create_8bit(ord(DW_OP_minus)));
  3371. current_asmdata.asmlists[al_dwarf_info].concat(tai_const.create_8bit(ord(DW_OP_deref)));
  3372. { for widestrings, the length is specified in bytes, so divide by two }
  3373. if (upperopcodes=15) then
  3374. begin
  3375. current_asmdata.asmlists[al_dwarf_info].concat(tai_const.create_8bit(ord(DW_OP_lit1)));
  3376. current_asmdata.asmlists[al_dwarf_info].concat(tai_const.create_8bit(ord(DW_OP_shr)));
  3377. end;
  3378. end
  3379. else
  3380. begin
  3381. append_entry(DW_TAG_subrange_type,false,[
  3382. DW_AT_lower_bound,DW_FORM_udata,1,
  3383. DW_AT_upper_bound,DW_FORM_block1,3
  3384. ]);
  3385. { for shortstrings, the length is the first byte of the string }
  3386. current_asmdata.asmlists[al_dwarf_info].concat(tai_const.create_8bit(ord(DW_OP_push_object_address)));
  3387. { load 1 byte }
  3388. current_asmdata.asmlists[al_dwarf_info].concat(tai_const.create_8bit(ord(DW_OP_deref_size)));
  3389. current_asmdata.asmlists[al_dwarf_info].concat(tai_const.create_8bit(lensize));
  3390. end;
  3391. finish_entry;
  3392. finish_children;
  3393. end;
  3394. begin
  3395. case def.stringtype of
  3396. st_shortstring:
  3397. begin
  3398. addstringdef('ShortString',cchartype,false,1);
  3399. end;
  3400. st_longstring:
  3401. begin
  3402. {$ifdef cpu64bitaddr}
  3403. addstringdef('LongString',cchartype,false,8);
  3404. {$else cpu64bitaddr}
  3405. addstringdef('LongString',cchartype,false,4);
  3406. {$endif cpu64bitaddr}
  3407. end;
  3408. st_ansistring:
  3409. begin
  3410. addstringdef('AnsiString',cchartype,true,-1);
  3411. end;
  3412. st_unicodestring:
  3413. begin
  3414. addstringdef('UnicodeString',cwidechartype,true,-1);
  3415. end;
  3416. st_widestring:
  3417. begin
  3418. if not(tf_winlikewidestring in target_info.flags) then
  3419. addstringdef('WideString',cwidechartype,true,-1)
  3420. else
  3421. begin
  3422. { looks like a pwidechar (no idea about length location) }
  3423. append_entry(DW_TAG_pointer_type,false,[]);
  3424. append_labelentry_ref(DW_AT_type,def_dwarf_lab(cwidechartype));
  3425. finish_entry;
  3426. end;
  3427. end;
  3428. end;
  3429. end;
  3430. procedure TDebugInfoDwarf3.appenddef_file(list:TAsmList;def: tfiledef);
  3431. begin
  3432. if assigned(def.typesym) then
  3433. append_entry(DW_TAG_file_type,false,[
  3434. DW_AT_name,DW_FORM_string,symname(def.typesym)+#0,
  3435. DW_AT_byte_size,DW_FORM_data2,def.size
  3436. ])
  3437. else
  3438. append_entry(DW_TAG_file_type,false,[
  3439. DW_AT_byte_size,DW_FORM_data2,def.size
  3440. ]);
  3441. if tfiledef(def).filetyp=ft_typed then
  3442. append_labelentry_ref(DW_AT_type,def_dwarf_lab(tfiledef(def).typedfiledef));
  3443. finish_entry;
  3444. end;
  3445. procedure TDebugInfoDwarf3.appenddef_formal(list:TAsmList;def: tformaldef);
  3446. begin
  3447. append_entry(DW_TAG_unspecified_type,false,[
  3448. ]);
  3449. finish_entry;
  3450. end;
  3451. procedure TDebugInfoDwarf3.appenddef_object(list:TAsmList;def: tobjectdef);
  3452. procedure dostruct(tag: tdwarf_tag);
  3453. begin
  3454. if assigned(def.objname) then
  3455. append_entry(tag,true,[
  3456. DW_AT_name,DW_FORM_string,def.objrealname^+#0
  3457. ])
  3458. else
  3459. append_entry(DW_TAG_structure_type,true,[]);
  3460. append_attribute(DW_AT_byte_size,DW_FORM_udata,[tobjectsymtable(def.symtable).datasize]);
  3461. // The pointer to the class-structure is hidden. The debug-information
  3462. // does not contain an implicit pointer, but the data-adress is dereferenced here.
  3463. // In case of a nil-pointer, report the class as being unallocated.
  3464. append_block1(DW_AT_allocated,2);
  3465. current_asmdata.asmlists[al_dwarf_info].concat(tai_const.create_8bit(ord(DW_OP_push_object_address)));
  3466. current_asmdata.asmlists[al_dwarf_info].concat(tai_const.create_8bit(ord(DW_OP_deref)));
  3467. append_block1(DW_AT_data_location,2);
  3468. current_asmdata.asmlists[al_dwarf_info].concat(tai_const.create_8bit(ord(DW_OP_push_object_address)));
  3469. current_asmdata.asmlists[al_dwarf_info].concat(tai_const.create_8bit(ord(DW_OP_deref)));
  3470. finish_entry;
  3471. end;
  3472. procedure doimplicitpointer;
  3473. var
  3474. obj : tasmlabel;
  3475. begin
  3476. if not(tf_dwarf_only_local_labels in target_info.flags) then
  3477. current_asmdata.getdatalabel(obj)
  3478. else
  3479. current_asmdata.getaddrlabel(obj);
  3480. { implicit pointer }
  3481. append_entry(DW_TAG_pointer_type,false,[]);
  3482. append_labelentry_ref(DW_AT_type,obj);
  3483. finish_entry;
  3484. current_asmdata.asmlists[al_dwarf_info].concat(tai_symbol.create(obj,0));
  3485. end;
  3486. procedure doparent(isinterface: boolean);
  3487. begin
  3488. if not assigned(def.childof) then
  3489. exit;
  3490. if isinterface then
  3491. begin
  3492. append_entry(DW_TAG_inheritance,false,[]);
  3493. end
  3494. else
  3495. begin
  3496. append_entry(DW_TAG_inheritance,false,[
  3497. DW_AT_accessibility,DW_FORM_data1,DW_ACCESS_public,
  3498. DW_AT_data_member_location,DW_FORM_block1,1+lengthuleb128(0)
  3499. ]);
  3500. current_asmdata.asmlists[al_dwarf_info].concat(tai_const.create_8bit(ord(DW_OP_plus_uconst)));
  3501. current_asmdata.asmlists[al_dwarf_info].concat(tai_const.create_uleb128bit(0));
  3502. end;
  3503. append_labelentry_ref(DW_AT_type,def_dwarf_lab(def.childof));
  3504. finish_entry;
  3505. end;
  3506. var
  3507. n: integer;
  3508. begin
  3509. case def.objecttype of
  3510. odt_cppclass,
  3511. odt_object:
  3512. begin
  3513. dostruct(DW_TAG_structure_type);
  3514. doparent(false);
  3515. end;
  3516. odt_interfacecom,
  3517. odt_interfacecorba,
  3518. odt_dispinterface:
  3519. begin
  3520. dostruct(DW_TAG_interface_type);
  3521. doparent(true);
  3522. end;
  3523. odt_class:
  3524. begin
  3525. //dostruct(DW_TAG_class_type);
  3526. //doparent(false);
  3527. append_entry(DW_TAG_pointer_type,false,[]);
  3528. append_labelentry_ref(DW_AT_type,def_dwarf_class_struct_lab(def));
  3529. finish_entry;
  3530. append_object_struct(def,true,def.objrealname);
  3531. Exit;
  3532. end;
  3533. else
  3534. internalerror(200609171);
  3535. end;
  3536. { add implemented interfaces }
  3537. if assigned(def.ImplementedInterfaces) then
  3538. for n := 0 to def.ImplementedInterfaces.count-1 do
  3539. begin
  3540. append_entry(DW_TAG_inheritance,false,[]);
  3541. append_labelentry_ref(DW_AT_type,def_dwarf_lab(TImplementedInterface(def.ImplementedInterfaces[n]).IntfDef));
  3542. finish_entry;
  3543. end;
  3544. { add members }
  3545. def.symtable.symList.ForEachCall(@enum_membersyms_callback,nil);
  3546. finish_children;
  3547. end;
  3548. procedure TDebugInfoDwarf3.appenddef_set(list:TAsmList;def: tsetdef);
  3549. begin
  3550. appenddef_set_intern(list,def,true);
  3551. end;
  3552. procedure TDebugInfoDwarf3.appenddef_undefined(list:TAsmList;def: tundefineddef);
  3553. begin
  3554. { ??? can a undefined def have a typename ? }
  3555. if assigned(def.typesym) then
  3556. append_entry(DW_TAG_unspecified_type,false,[
  3557. DW_AT_name,DW_FORM_string,symname(def.typesym)+#0
  3558. ])
  3559. else
  3560. append_entry(DW_TAG_unspecified_type,false,[
  3561. ]);
  3562. finish_entry;
  3563. end;
  3564. procedure TDebugInfoDwarf3.appenddef_variant(list:TAsmList;def: tvariantdef);
  3565. const
  3566. VARIANTS: array[1..27] of record Value: Word; Name: String end = (
  3567. (value:0; name:''),
  3568. (value:1; name:''),
  3569. (value:2; name:'VSMALLINT'),
  3570. (value:3; name:'VINTEGER'),
  3571. (value:4; name:'VSINGLE'),
  3572. (value:5; name:'VDOUBLE'),
  3573. (value:6; name:'VCURRENCY'),
  3574. (value:7; name:'VDATE'),
  3575. (value:8; name:'VOLESTR'),
  3576. (value:9; name:'VDISPATCH'),
  3577. (value:10; name:'VERROR'),
  3578. (value:11; name:'VBOOLEAN'),
  3579. (value:12; name:''),
  3580. (value:13; name:'VUNKNOWN'),
  3581. (value:14; name:''),
  3582. (value:16; name:'VSHORTINT'),
  3583. (value:17; name:'VBYTE'),
  3584. (value:18; name:'VWORD'),
  3585. (value:19; name:'VLONGWORD'),
  3586. (value:20; name:'VINT64'),
  3587. (value:21; name:'VQWORD'),
  3588. (value:36; name:'VRECORD'),
  3589. (value:$48; name:''),
  3590. (value:$100; name:'VSTRING'),
  3591. (value:$101; name:'VANY'),
  3592. (value:$2000; name:'VARRAY'),
  3593. (value:$4000; name:'VPOINTER')
  3594. );
  3595. var
  3596. fs: tfieldvarsym;
  3597. lbl: tasmlabel;
  3598. idx: integer;
  3599. begin
  3600. { it could be done with DW_TAG_variant for the union part (if that info was available)
  3601. now we do it manually for variants (MWE) }
  3602. { struct }
  3603. append_entry(DW_TAG_structure_type,true,[
  3604. DW_AT_name,DW_FORM_string,'Variant'#0,
  3605. DW_AT_byte_size,DW_FORM_udata,vardatadef.size
  3606. ]);
  3607. finish_entry;
  3608. append_entry(DW_TAG_variant_part,true,[
  3609. ]);
  3610. current_asmdata.getaddrlabel(lbl);
  3611. append_labelentry_ref(DW_AT_discr,lbl);
  3612. finish_entry;
  3613. { discriminant }
  3614. fs := tfieldvarsym(vardatadef.symtable.Find('VTYPE'));
  3615. if (fs = nil) or (fs.typ <> fieldvarsym) then
  3616. internalerror(200609271);
  3617. current_asmdata.asmlists[al_dwarf_info].concat(tai_symbol.create(lbl,0));
  3618. appendsym_fieldvar(list,fs);
  3619. { variants }
  3620. for idx := Low(VARIANTS) to High(VARIANTS) do
  3621. begin
  3622. append_entry(DW_TAG_variant,true,[
  3623. DW_AT_discr_value,DW_FORM_udata,VARIANTS[idx].value
  3624. ]);
  3625. finish_entry;
  3626. if VARIANTS[idx].name <> '' then
  3627. begin
  3628. fs := tfieldvarsym(vardatadef.symtable.Find(VARIANTS[idx].name));
  3629. if (fs = nil) or (fs.typ <> fieldvarsym) then
  3630. internalerror(20060927200+idx);
  3631. appendsym_fieldvar(list,fs);
  3632. end;
  3633. finish_children; { variant }
  3634. end;
  3635. finish_children; { variant part }
  3636. finish_children; { struct }
  3637. end;
  3638. function TDebugInfoDwarf3.dwarf_version: Word;
  3639. begin
  3640. Result:=3;
  3641. end;
  3642. function TDebugInfoDwarf3.symname(sym: tsym): String;
  3643. begin
  3644. Result:=sym.realname;
  3645. end;
  3646. { TDebugInfoDwarf4 }
  3647. function TDebugInfoDwarf4.dwarf_version: Word;
  3648. begin
  3649. Result:=4;
  3650. end;
  3651. {****************************************************************************
  3652. ****************************************************************************}
  3653. const
  3654. dbg_dwarf2_info : tdbginfo =
  3655. (
  3656. id : dbg_dwarf2;
  3657. idtxt : 'DWARF2';
  3658. );
  3659. dbg_dwarf3_info : tdbginfo =
  3660. (
  3661. id : dbg_dwarf3;
  3662. idtxt : 'DWARF3';
  3663. );
  3664. dbg_dwarf4_info : tdbginfo =
  3665. (
  3666. id : dbg_dwarf4;
  3667. idtxt : 'DWARF4';
  3668. );
  3669. initialization
  3670. RegisterDebugInfo(dbg_dwarf2_info,TDebugInfoDwarf2);
  3671. RegisterDebugInfo(dbg_dwarf3_info,TDebugInfoDwarf3);
  3672. RegisterDebugInfo(dbg_dwarf4_info,TDebugInfoDwarf4);
  3673. end.