dbgdwarf.pas 185 KB

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