dbgdwarf.pas 182 KB

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