dbgdwarf.pas 188 KB

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