dbgdwarf.pas 187 KB

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