dbgdwarf.pas 185 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615
  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. begin
  1284. case def.ordtype of
  1285. s8bit,
  1286. s16bit,
  1287. s32bit,
  1288. u8bit,
  1289. u16bit,
  1290. u32bit :
  1291. begin
  1292. { generate proper signed/unsigned info for types like 0..3 }
  1293. { these are s8bit, but should be identified as unsigned }
  1294. { because otherwise they are interpreted wrongly when used }
  1295. { in a bitpacked record }
  1296. if (def.low<0) then
  1297. begin
  1298. sign:=DW_ATE_signed;
  1299. signform:=DW_FORM_sdata
  1300. end
  1301. else
  1302. begin
  1303. sign:=DW_ATE_unsigned;
  1304. signform:=DW_FORM_udata
  1305. end;
  1306. fullbytesize:=def.size;
  1307. case fullbytesize of
  1308. 1:
  1309. if (sign=DW_ATE_signed) then
  1310. basedef:=s8inttype
  1311. else
  1312. basedef:=u8inttype;
  1313. 2:
  1314. if (sign=DW_ATE_signed) then
  1315. basedef:=s16inttype
  1316. else
  1317. basedef:=u16inttype;
  1318. 4:
  1319. if (sign=DW_ATE_signed) then
  1320. basedef:=s32inttype
  1321. else
  1322. basedef:=u32inttype;
  1323. else
  1324. internalerror(2008032201);
  1325. end;
  1326. if (def.low=torddef(basedef).low) and
  1327. (def.high=torddef(basedef).high) then
  1328. { base type such as byte/shortint/word/... }
  1329. if assigned(def.typesym) then
  1330. append_entry(DW_TAG_base_type,false,[
  1331. DW_AT_name,DW_FORM_string,symname(def.typesym, false)+#0,
  1332. DW_AT_encoding,DW_FORM_data1,sign,
  1333. DW_AT_byte_size,DW_FORM_data1,fullbytesize])
  1334. else
  1335. append_entry(DW_TAG_base_type,false,[
  1336. DW_AT_encoding,DW_FORM_data1,sign,
  1337. DW_AT_byte_size,DW_FORM_data1,fullbytesize])
  1338. else
  1339. begin
  1340. { subrange type }
  1341. { note: don't do this 64 bit int types, they appear }
  1342. { to be always clipped to s32bit for some reason }
  1343. if assigned(def.typesym) then
  1344. append_entry(DW_TAG_subrange_type,false,[
  1345. DW_AT_name,DW_FORM_string,symname(def.typesym, false)+#0,
  1346. DW_AT_lower_bound,signform,int64(def.low),
  1347. DW_AT_upper_bound,signform,int64(def.high)
  1348. ])
  1349. else
  1350. append_entry(DW_TAG_subrange_type,false,[
  1351. DW_AT_lower_bound,signform,int64(def.low),
  1352. DW_AT_upper_bound,signform,int64(def.high)
  1353. ]);
  1354. append_labelentry_ref(DW_AT_type,def_dwarf_lab(basedef));
  1355. end;
  1356. finish_entry;
  1357. end;
  1358. uvoid :
  1359. begin
  1360. { gdb 6.4 doesn't support DW_TAG_unspecified_type so we
  1361. replace it with a unsigned type with size 0 (FK)
  1362. }
  1363. append_entry(DW_TAG_base_type,false,[
  1364. DW_AT_name,DW_FORM_string,'Void'#0,
  1365. DW_AT_encoding,DW_FORM_data1,DW_ATE_unsigned,
  1366. DW_AT_byte_size,DW_FORM_data1,0
  1367. ]);
  1368. finish_entry;
  1369. end;
  1370. uchar :
  1371. begin
  1372. append_entry(DW_TAG_base_type,false,[
  1373. DW_AT_name,DW_FORM_string,'Char'#0,
  1374. DW_AT_encoding,DW_FORM_data1,DW_ATE_unsigned_char,
  1375. DW_AT_byte_size,DW_FORM_data1,1
  1376. ]);
  1377. finish_entry;
  1378. end;
  1379. uwidechar :
  1380. begin
  1381. append_entry(DW_TAG_base_type,false,[
  1382. DW_AT_name,DW_FORM_string,'WideChar'#0,
  1383. DW_AT_encoding,DW_FORM_data1,DW_ATE_unsigned_char,
  1384. DW_AT_byte_size,DW_FORM_data1,2
  1385. ]);
  1386. finish_entry;
  1387. end;
  1388. pasbool8 :
  1389. begin
  1390. append_entry(DW_TAG_base_type,false,[
  1391. DW_AT_name,DW_FORM_string,'Boolean'#0,
  1392. DW_AT_encoding,DW_FORM_data1,DW_ATE_boolean,
  1393. DW_AT_byte_size,DW_FORM_data1,1
  1394. ]);
  1395. finish_entry;
  1396. end;
  1397. bool8bit :
  1398. begin
  1399. append_entry(DW_TAG_base_type,false,[
  1400. DW_AT_name,DW_FORM_string,'ByteBool'#0,
  1401. DW_AT_encoding,DW_FORM_data1,DW_ATE_boolean,
  1402. DW_AT_byte_size,DW_FORM_data1,1
  1403. ]);
  1404. finish_entry;
  1405. end;
  1406. pasbool16 :
  1407. begin
  1408. append_entry(DW_TAG_base_type,false,[
  1409. DW_AT_name,DW_FORM_string,'Boolean16'#0,
  1410. DW_AT_encoding,DW_FORM_data1,DW_ATE_boolean,
  1411. DW_AT_byte_size,DW_FORM_data1,2
  1412. ]);
  1413. finish_entry;
  1414. end;
  1415. bool16bit :
  1416. begin
  1417. append_entry(DW_TAG_base_type,false,[
  1418. DW_AT_name,DW_FORM_string,'WordBool'#0,
  1419. DW_AT_encoding,DW_FORM_data1,DW_ATE_boolean,
  1420. DW_AT_byte_size,DW_FORM_data1,2
  1421. ]);
  1422. finish_entry;
  1423. end;
  1424. pasbool32 :
  1425. begin
  1426. append_entry(DW_TAG_base_type,false,[
  1427. DW_AT_name,DW_FORM_string,'Boolean32'#0,
  1428. DW_AT_encoding,DW_FORM_data1,DW_ATE_boolean,
  1429. DW_AT_byte_size,DW_FORM_data1,4
  1430. ]);
  1431. finish_entry;
  1432. end;
  1433. bool32bit :
  1434. begin
  1435. append_entry(DW_TAG_base_type,false,[
  1436. DW_AT_name,DW_FORM_string,'LongBool'#0,
  1437. DW_AT_encoding,DW_FORM_data1,DW_ATE_boolean,
  1438. DW_AT_byte_size,DW_FORM_data1,4
  1439. ]);
  1440. finish_entry;
  1441. end;
  1442. pasbool64 :
  1443. begin
  1444. append_entry(DW_TAG_base_type,false,[
  1445. DW_AT_name,DW_FORM_string,'Boolean64'#0,
  1446. DW_AT_encoding,DW_FORM_data1,DW_ATE_boolean,
  1447. DW_AT_byte_size,DW_FORM_data1,8
  1448. ]);
  1449. finish_entry;
  1450. end;
  1451. bool64bit :
  1452. begin
  1453. append_entry(DW_TAG_base_type,false,[
  1454. DW_AT_name,DW_FORM_string,'QWordBool'#0,
  1455. DW_AT_encoding,DW_FORM_data1,DW_ATE_boolean,
  1456. DW_AT_byte_size,DW_FORM_data1,8
  1457. ]);
  1458. finish_entry;
  1459. end;
  1460. u64bit :
  1461. begin
  1462. append_entry(DW_TAG_base_type,false,[
  1463. DW_AT_name,DW_FORM_string,'QWord'#0,
  1464. DW_AT_encoding,DW_FORM_data1,DW_ATE_unsigned,
  1465. DW_AT_byte_size,DW_FORM_data1,8
  1466. ]);
  1467. finish_entry;
  1468. end;
  1469. scurrency :
  1470. begin
  1471. { we should use DW_ATE_signed_fixed, however it isn't supported yet by GDB (FK) }
  1472. append_entry(DW_TAG_base_type,false,[
  1473. DW_AT_name,DW_FORM_string,'Currency'#0,
  1474. DW_AT_encoding,DW_FORM_data1,DW_ATE_signed,
  1475. DW_AT_byte_size,DW_FORM_data1,8
  1476. ]);
  1477. finish_entry;
  1478. end;
  1479. s64bit :
  1480. begin
  1481. append_entry(DW_TAG_base_type,false,[
  1482. DW_AT_name,DW_FORM_string,'Int64'#0,
  1483. DW_AT_encoding,DW_FORM_data1,DW_ATE_signed,
  1484. DW_AT_byte_size,DW_FORM_data1,8
  1485. ]);
  1486. finish_entry;
  1487. end;
  1488. u128bit:
  1489. begin
  1490. append_entry(DW_TAG_base_type,false,[
  1491. DW_AT_name,DW_FORM_string,'Int128'#0,
  1492. DW_AT_encoding,DW_FORM_data1,DW_ATE_unsigned,
  1493. DW_AT_byte_size,DW_FORM_data1,16
  1494. ]);
  1495. finish_entry;
  1496. end;
  1497. s128bit:
  1498. begin
  1499. append_entry(DW_TAG_base_type,false,[
  1500. DW_AT_name,DW_FORM_string,'Int128'#0,
  1501. DW_AT_encoding,DW_FORM_data1,DW_ATE_signed,
  1502. DW_AT_byte_size,DW_FORM_data1,16
  1503. ]);
  1504. finish_entry;
  1505. end;
  1506. else
  1507. internalerror(200601287);
  1508. end;
  1509. end;
  1510. procedure TDebugInfoDwarf.appenddef_float(list:TAsmList;def:tfloatdef);
  1511. begin
  1512. case def.floattype of
  1513. s32real,
  1514. s64real,
  1515. s80real,
  1516. sc80real:
  1517. if assigned(def.typesym) then
  1518. begin
  1519. append_entry(DW_TAG_base_type,false,[
  1520. DW_AT_name,DW_FORM_string,symname(def.typesym, false)+#0,
  1521. DW_AT_encoding,DW_FORM_data1,DW_ATE_float,
  1522. DW_AT_byte_size,DW_FORM_data1,def.size
  1523. ]);
  1524. if (def.floattype in [s80real,sc80real]) and
  1525. (def.size<>10) then
  1526. begin
  1527. append_attribute(DW_AT_bit_size,DW_FORM_data1,[10*8]);
  1528. { "The bit offset attribute describes the offset in bits
  1529. of the high order bit of a value of the given type
  1530. from the high order bit of the storage unit used to
  1531. contain that value." }
  1532. if target_info.endian=endian_little then
  1533. append_attribute(DW_AT_bit_offset,DW_FORM_data1,[(def.size-10)*8]);
  1534. end;
  1535. end
  1536. else
  1537. append_entry(DW_TAG_base_type,false,[
  1538. DW_AT_encoding,DW_FORM_data1,DW_ATE_float,
  1539. DW_AT_byte_size,DW_FORM_data1,def.size
  1540. ]);
  1541. s64currency:
  1542. { we should use DW_ATE_signed_fixed, however it isn't supported yet by GDB (FK) }
  1543. if assigned(def.typesym) then
  1544. append_entry(DW_TAG_base_type,false,[
  1545. DW_AT_name,DW_FORM_string,symname(def.typesym, false)+#0,
  1546. DW_AT_encoding,DW_FORM_data1,DW_ATE_signed,
  1547. DW_AT_byte_size,DW_FORM_data1,8
  1548. ])
  1549. else
  1550. append_entry(DW_TAG_base_type,false,[
  1551. DW_AT_encoding,DW_FORM_data1,DW_ATE_signed,
  1552. DW_AT_byte_size,DW_FORM_data1,8
  1553. ]);
  1554. s64comp:
  1555. if assigned(def.typesym) then
  1556. append_entry(DW_TAG_base_type,false,[
  1557. DW_AT_name,DW_FORM_string,symname(def.typesym, false)+#0,
  1558. DW_AT_encoding,DW_FORM_data1,DW_ATE_signed,
  1559. DW_AT_byte_size,DW_FORM_data1,8
  1560. ])
  1561. else
  1562. append_entry(DW_TAG_base_type,false,[
  1563. DW_AT_encoding,DW_FORM_data1,DW_ATE_signed,
  1564. DW_AT_byte_size,DW_FORM_data1,8
  1565. ]);
  1566. else
  1567. internalerror(200601289);
  1568. end;
  1569. finish_entry;
  1570. end;
  1571. procedure TDebugInfoDwarf.appenddef_enum(list:TAsmList;def:tenumdef);
  1572. var
  1573. hp : tenumsym;
  1574. i : integer;
  1575. begin
  1576. if assigned(def.typesym) then
  1577. append_entry(DW_TAG_enumeration_type,true,[
  1578. DW_AT_name,DW_FORM_string,symname(def.typesym, false)+#0,
  1579. DW_AT_byte_size,DW_FORM_data1,def.size
  1580. ])
  1581. else
  1582. append_entry(DW_TAG_enumeration_type,true,[
  1583. DW_AT_byte_size,DW_FORM_data1,def.size
  1584. ]);
  1585. if assigned(def.basedef) then
  1586. append_labelentry_ref(DW_AT_type,def_dwarf_lab(def.basedef));
  1587. finish_entry;
  1588. { write enum symbols }
  1589. for i := 0 to def.symtable.SymList.Count - 1 do
  1590. begin
  1591. hp:=tenumsym(def.symtable.SymList[i]);
  1592. if hp.value<def.minval then
  1593. continue
  1594. else
  1595. if hp.value>def.maxval then
  1596. break;
  1597. append_entry(DW_TAG_enumerator,false,[
  1598. DW_AT_name,DW_FORM_string,symname(hp, false)+#0,
  1599. DW_AT_const_value,DW_FORM_data4,hp.value
  1600. ]);
  1601. finish_entry;
  1602. end;
  1603. finish_children;
  1604. end;
  1605. procedure TDebugInfoDwarf.appenddef_array(list:TAsmList;def:tarraydef);
  1606. var
  1607. size : PInt;
  1608. elesize : PInt;
  1609. elestrideattr : tdwarf_attribute;
  1610. labsym: tasmlabel;
  1611. begin
  1612. if is_dynamic_array(def) then
  1613. begin
  1614. { It's a pointer to the actual array }
  1615. current_asmdata.getaddrlabel(labsym);
  1616. append_entry(DW_TAG_pointer_type,false,[]);
  1617. append_labelentry_ref(DW_AT_type,labsym);
  1618. finish_entry;
  1619. current_asmdata.asmlists[al_dwarf_info].concat(tai_symbol.create(labsym,0));
  1620. end;
  1621. if not is_packed_array(def) then
  1622. begin
  1623. elestrideattr := DW_AT_byte_stride;
  1624. elesize := def.elesize;
  1625. end
  1626. else
  1627. begin
  1628. elestrideattr := DW_AT_stride_size;
  1629. elesize := def.elepackedbitsize;
  1630. end;
  1631. if is_special_array(def) then
  1632. begin
  1633. { no known size, no known upper bound }
  1634. if assigned(def.typesym) then
  1635. append_entry(DW_TAG_array_type,true,[
  1636. DW_AT_name,DW_FORM_string,symname(def.typesym, false)+#0
  1637. ])
  1638. else
  1639. append_entry(DW_TAG_array_type,true,[]);
  1640. append_labelentry_ref(DW_AT_type,def_dwarf_lab(def.elementdef));
  1641. finish_entry;
  1642. { a missing upper bound means "unknown"/default }
  1643. append_entry(DW_TAG_subrange_type,false,[
  1644. DW_AT_lower_bound,DW_FORM_sdata,def.lowrange,
  1645. elestrideattr,DW_FORM_udata,elesize
  1646. ]);
  1647. end
  1648. else
  1649. begin
  1650. size:=def.size;
  1651. if assigned(def.typesym) then
  1652. append_entry(DW_TAG_array_type,true,[
  1653. DW_AT_name,DW_FORM_string,symname(def.typesym, false)+#0,
  1654. DW_AT_byte_size,DW_FORM_udata,size
  1655. ])
  1656. else
  1657. append_entry(DW_TAG_array_type,true,[
  1658. DW_AT_byte_size,DW_FORM_udata,size
  1659. ]);
  1660. append_labelentry_ref(DW_AT_type,def_dwarf_lab(def.elementdef));
  1661. finish_entry;
  1662. { to simplify things, we don't write a multidimensional array here }
  1663. append_entry(DW_TAG_subrange_type,false,[
  1664. DW_AT_lower_bound,DW_FORM_sdata,def.lowrange,
  1665. DW_AT_upper_bound,DW_FORM_sdata,def.highrange,
  1666. elestrideattr,DW_FORM_udata,elesize
  1667. ]);
  1668. end;
  1669. append_labelentry_ref(DW_AT_type,def_dwarf_lab(def.rangedef));
  1670. finish_entry;
  1671. finish_children;
  1672. end;
  1673. procedure TDebugInfoDwarf.appenddef_record(list:TAsmList;def:trecorddef);
  1674. begin
  1675. if assigned(def.objname) then
  1676. appenddef_record_named(list,def,def.objname^)
  1677. else
  1678. appenddef_record_named(list,def,'');
  1679. end;
  1680. procedure TDebugInfoDwarf.appenddef_record_named(list:TAsmList;def:trecorddef;const name: shortstring);
  1681. begin
  1682. if (name<>'') then
  1683. append_entry(DW_TAG_structure_type,true,[
  1684. DW_AT_name,DW_FORM_string,name+#0,
  1685. DW_AT_byte_size,DW_FORM_udata,def.size
  1686. ])
  1687. else
  1688. append_entry(DW_TAG_structure_type,true,[
  1689. DW_AT_byte_size,DW_FORM_udata,def.size
  1690. ]);
  1691. finish_entry;
  1692. def.symtable.symList.ForEachCall(@enum_membersyms_callback,nil);
  1693. { don't know whether external record declaration is allow but if it so then
  1694. do the same as we do for other object types - skip procdef info generation
  1695. for external defs (Paul Ishenin) }
  1696. if not(oo_is_external in def.objectoptions) then
  1697. write_symtable_procdefs(current_asmdata.asmlists[al_dwarf_info],def.symtable);
  1698. finish_children;
  1699. end;
  1700. procedure TDebugInfoDwarf.appenddef_pointer(list:TAsmList;def:tpointerdef);
  1701. begin
  1702. append_entry(DW_TAG_pointer_type,false,[]);
  1703. append_pointerclass(list,def);
  1704. if not(is_voidpointer(def)) then
  1705. append_labelentry_ref(DW_AT_type,def_dwarf_lab(def.pointeddef));
  1706. finish_entry;
  1707. end;
  1708. procedure TDebugInfoDwarf.appenddef_string(list:TAsmList;def:tstringdef);
  1709. procedure addnormalstringdef(const name: shortstring; lendef: tdef; maxlen: asizeuint);
  1710. var
  1711. { maxlen can be > high(int64) }
  1712. slen : asizeuint;
  1713. arr : tasmlabel;
  1714. begin
  1715. { fix length of openshortstring }
  1716. slen:=aword(def.len);
  1717. if (slen=0) or
  1718. (slen>maxlen) then
  1719. slen:=maxlen;
  1720. { create a structure with two elements }
  1721. if not(tf_dwarf_only_local_labels in target_info.flags) then
  1722. current_asmdata.getglobaldatalabel(arr)
  1723. else
  1724. current_asmdata.getaddrlabel(arr);
  1725. append_entry(DW_TAG_structure_type,true,[
  1726. DW_AT_name,DW_FORM_string,name+#0,
  1727. DW_AT_byte_size,DW_FORM_udata,qword(lendef.size)+slen
  1728. ]);
  1729. finish_entry;
  1730. { length entry }
  1731. append_entry(DW_TAG_member,false,[
  1732. DW_AT_name,DW_FORM_string,'length'#0,
  1733. DW_AT_data_member_location,DW_FORM_block1,1+lengthuleb128(0)
  1734. ]);
  1735. current_asmdata.asmlists[al_dwarf_info].concat(tai_const.create_8bit(ord(DW_OP_plus_uconst)));
  1736. current_asmdata.asmlists[al_dwarf_info].concat(tai_const.create_uleb128bit(0));
  1737. append_labelentry_ref(DW_AT_type,def_dwarf_lab(lendef));
  1738. finish_entry;
  1739. { string data entry }
  1740. append_entry(DW_TAG_member,false,[
  1741. DW_AT_name,DW_FORM_string,'st'#0,
  1742. DW_AT_data_member_location,DW_FORM_block1,1+lengthuleb128(1)
  1743. ]);
  1744. current_asmdata.asmlists[al_dwarf_info].concat(tai_const.create_8bit(ord(DW_OP_plus_uconst)));
  1745. current_asmdata.asmlists[al_dwarf_info].concat(tai_const.create_uleb128bit(lendef.size));
  1746. append_labelentry_ref(DW_AT_type,arr);
  1747. finish_entry;
  1748. finish_children;
  1749. { now the data array }
  1750. if arr.bind=AB_GLOBAL then
  1751. current_asmdata.asmlists[al_dwarf_info].concat(tai_symbol.create_global(arr,0))
  1752. else
  1753. current_asmdata.asmlists[al_dwarf_info].concat(tai_symbol.create(arr,0));
  1754. append_entry(DW_TAG_array_type,true,[
  1755. DW_AT_byte_size,DW_FORM_udata,def.size,
  1756. DW_AT_byte_stride,DW_FORM_udata,1
  1757. ]);
  1758. append_labelentry_ref(DW_AT_type,def_dwarf_lab(cansichartype));
  1759. finish_entry;
  1760. append_entry(DW_TAG_subrange_type,false,[
  1761. DW_AT_lower_bound,DW_FORM_udata,1,
  1762. DW_AT_upper_bound,DW_FORM_udata,qword(slen)
  1763. ]);
  1764. append_labelentry_ref(DW_AT_type,def_dwarf_lab(lendef));
  1765. finish_entry;
  1766. finish_children;
  1767. end;
  1768. begin
  1769. case def.stringtype of
  1770. st_shortstring:
  1771. begin
  1772. addnormalstringdef('ShortString',u8inttype,255);
  1773. end;
  1774. st_longstring:
  1775. begin
  1776. { a) we don't actually support variables of this type currently
  1777. b) this type is only used as the type for constant strings
  1778. > 255 characters
  1779. c) in such a case, gdb will allocate and initialise enough
  1780. memory to hold the maximum size for such a string
  1781. -> don't use high(qword)/high(cardinal) as maximum, since that
  1782. will cause exhausting the VM space, but some "reasonably high"
  1783. number that should be enough for most constant strings
  1784. }
  1785. {$ifdef cpu64bitaddr}
  1786. addnormalstringdef('LongString',u64inttype,qword(1024*1024));
  1787. {$endif cpu64bitaddr}
  1788. {$ifdef cpu32bitaddr}
  1789. addnormalstringdef('LongString',u32inttype,cardinal(1024*1024));
  1790. {$endif cpu32bitaddr}
  1791. {$ifdef cpu16bitaddr}
  1792. addnormalstringdef('LongString',u16inttype,cardinal(1024));
  1793. {$endif cpu16bitaddr}
  1794. end;
  1795. st_ansistring:
  1796. begin
  1797. { looks like a pchar }
  1798. append_entry(DW_TAG_pointer_type,false,[]);
  1799. append_labelentry_ref(DW_AT_type,def_dwarf_lab(cansichartype));
  1800. finish_entry;
  1801. end;
  1802. st_unicodestring,
  1803. st_widestring:
  1804. begin
  1805. { looks like a pwidechar }
  1806. append_entry(DW_TAG_pointer_type,false,[]);
  1807. append_labelentry_ref(DW_AT_type,def_dwarf_lab(cwidechartype));
  1808. finish_entry;
  1809. end;
  1810. end;
  1811. end;
  1812. procedure TDebugInfoDwarf.appenddef_procvar(list:TAsmList;def:tprocvardef);
  1813. procedure doappend;
  1814. var
  1815. i : longint;
  1816. begin
  1817. if assigned(def.typesym) then
  1818. append_entry(DW_TAG_subroutine_type,true,[
  1819. DW_AT_name,DW_FORM_string,symname(def.typesym, false)+#0,
  1820. DW_AT_prototyped,DW_FORM_flag,true
  1821. ])
  1822. else
  1823. append_entry(DW_TAG_subroutine_type,true,[
  1824. DW_AT_prototyped,DW_FORM_flag,true
  1825. ]);
  1826. if not(is_void(tprocvardef(def).returndef)) then
  1827. append_labelentry_ref(DW_AT_type,def_dwarf_lab(tprocvardef(def).returndef));
  1828. finish_entry;
  1829. { write parameters }
  1830. for i:=0 to def.paras.count-1 do
  1831. begin
  1832. append_entry(DW_TAG_formal_parameter,false,[
  1833. DW_AT_name,DW_FORM_string,symname(tsym(def.paras[i]), false)+#0
  1834. ]);
  1835. append_labelentry_ref(DW_AT_type,def_dwarf_lab(tparavarsym(def.paras[i]).vardef));
  1836. finish_entry;
  1837. end;
  1838. finish_children;
  1839. end;
  1840. var
  1841. proc : tasmlabel;
  1842. begin
  1843. if not def.is_addressonly then
  1844. begin
  1845. { create a structure with two elements }
  1846. if not(tf_dwarf_only_local_labels in target_info.flags) then
  1847. current_asmdata.getglobaldatalabel(proc)
  1848. else
  1849. current_asmdata.getaddrlabel(proc);
  1850. append_entry(DW_TAG_structure_type,true,[
  1851. DW_AT_byte_size,DW_FORM_data1,2*sizeof(pint)
  1852. ]);
  1853. finish_entry;
  1854. { proc entry }
  1855. append_entry(DW_TAG_member,false,[
  1856. DW_AT_name,DW_FORM_string,'Proc'#0,
  1857. DW_AT_data_member_location,DW_FORM_block1,1+lengthuleb128(0)
  1858. ]);
  1859. current_asmdata.asmlists[al_dwarf_info].concat(tai_const.create_8bit(ord(DW_OP_plus_uconst)));
  1860. current_asmdata.asmlists[al_dwarf_info].concat(tai_const.create_uleb128bit(0));
  1861. append_labelentry_ref(DW_AT_type,proc);
  1862. finish_entry;
  1863. { self entry }
  1864. append_entry(DW_TAG_member,false,[
  1865. DW_AT_name,DW_FORM_string,'Self'#0,
  1866. DW_AT_data_member_location,DW_FORM_block1,1+lengthuleb128(sizeof(pint))
  1867. ]);
  1868. current_asmdata.asmlists[al_dwarf_info].concat(tai_const.create_8bit(ord(DW_OP_plus_uconst)));
  1869. current_asmdata.asmlists[al_dwarf_info].concat(tai_const.create_uleb128bit(sizeof(pint)));
  1870. append_labelentry_ref(DW_AT_type,def_dwarf_lab(class_tobject));
  1871. finish_entry;
  1872. finish_children;
  1873. if proc.bind=AB_GLOBAL then
  1874. current_asmdata.asmlists[al_dwarf_info].concat(tai_symbol.create_global(proc,0))
  1875. else
  1876. current_asmdata.asmlists[al_dwarf_info].concat(tai_symbol.create(proc,0));
  1877. doappend;
  1878. end
  1879. else
  1880. doappend;
  1881. end;
  1882. procedure TDebugInfoDwarf.beforeappenddef(list:TAsmList;def:tdef);
  1883. var
  1884. labsym : tasmsymbol;
  1885. begin
  1886. current_asmdata.asmlists[al_dwarf_info].concat(tai_comment.Create(strpnew('Definition '+def.typename)));
  1887. labsym:=def_dwarf_lab(def);
  1888. case labsym.bind of
  1889. AB_GLOBAL:
  1890. current_asmdata.asmlists[al_dwarf_info].concat(tai_symbol.create_global(labsym,0));
  1891. AB_LOCAL:
  1892. current_asmdata.asmlists[al_dwarf_info].concat(tai_symbol.create(labsym,0));
  1893. else
  1894. internalerror(2013082001);
  1895. end;
  1896. { On Darwin, dwarf info is not linked in the final binary,
  1897. but kept in the individual object files. This allows for
  1898. faster linking, but means that you have to keep the object
  1899. files for debugging and also that gdb only loads in the
  1900. debug info of a particular object file once you step into
  1901. or over a procedure in it.
  1902. To solve this, there is a tool called dsymutil which can
  1903. extract all the dwarf info from a program's object files.
  1904. This utility however performs "smart linking" on the dwarf
  1905. info and throws away all unreferenced dwarf entries. Since
  1906. variables' types always point to the dwarfinfo for a tdef
  1907. and never to that for a typesym, this means all debug
  1908. entries generated for typesyms are thrown away.
  1909. The problem with that is that we translate typesyms into
  1910. DW_TAG_typedef, and gdb's dwarf-2 reader only makes types
  1911. globally visibly if they are defined using a DW_TAG_typedef.
  1912. So as a result, before running dsymutil types only become
  1913. available once you stepped into/over a function in the object
  1914. file where they are declared, and after running dsymutil they
  1915. are all gone (printing variables still works because the
  1916. tdef dwarf info is still available, but you cannot typecast
  1917. anything outside the declaring units because the type names
  1918. are not known there).
  1919. The solution: if a tdef has an associated typesym, let the
  1920. debug label for the tdef point to a DW_TAG_typedef instead
  1921. of directly to the tdef itself. And don't write anything
  1922. special for the typesym itself.
  1923. Update: we now also do this for other platforms, because
  1924. otherwise if you compile unit A without debug info and
  1925. use one of its types in unit B, then no typedef will be
  1926. generated and hence gdb will not be able to give a definition
  1927. of the type.
  1928. }
  1929. if is_objc_class_or_protocol(def) then
  1930. begin
  1931. { for Objective-C classes, the typedef must refer to the
  1932. struct itself, not to the pointer of the struct; Objective-C
  1933. classes are not implicit pointers in Objective-C itself, only
  1934. in FPC. So make the def label point to a pointer to the
  1935. typedef, which in turn refers to the actual struct (for Delphi-
  1936. style classes, the def points to the typedef, which refers to
  1937. a pointer to the actual struct) }
  1938. { implicit pointer }
  1939. current_asmdata.getaddrlabel(TAsmLabel(pointer(labsym)));
  1940. append_entry(DW_TAG_pointer_type,false,[]);
  1941. append_labelentry_ref(DW_AT_type,labsym);
  1942. finish_entry;
  1943. current_asmdata.asmlists[al_dwarf_info].concat(tai_symbol.create(labsym,0));
  1944. end;
  1945. if assigned(def.typesym) and
  1946. not(df_generic in def.defoptions) then
  1947. begin
  1948. current_asmdata.getaddrlabel(TAsmLabel(pointer(labsym)));
  1949. append_entry(DW_TAG_typedef,false,[
  1950. DW_AT_name,DW_FORM_string,symname(def.typesym, false)+#0
  1951. ]);
  1952. append_labelentry_ref(DW_AT_type,labsym);
  1953. finish_entry;
  1954. current_asmdata.asmlists[al_dwarf_info].concat(tai_symbol.create(labsym,0));
  1955. end
  1956. end;
  1957. procedure TDebugInfoDwarf.afterappenddef(list:TAsmList;def:tdef);
  1958. var
  1959. labsym : tasmsymbol;
  1960. begin
  1961. { create a derived reference type for pass-by-reference parameters }
  1962. { (gdb doesn't support DW_AT_variable_parameter yet) }
  1963. labsym:=def_dwarf_ref_lab(def);
  1964. case labsym.bind of
  1965. AB_GLOBAL:
  1966. current_asmdata.asmlists[al_dwarf_info].concat(tai_symbol.create_global(labsym,0));
  1967. AB_LOCAL:
  1968. current_asmdata.asmlists[al_dwarf_info].concat(tai_symbol.create(labsym,0));
  1969. else
  1970. internalerror(2013082002);
  1971. end;
  1972. append_entry(DW_TAG_reference_type,false,[]);
  1973. append_labelentry_ref(DW_AT_type,def_dwarf_lab(def));
  1974. finish_entry;
  1975. end;
  1976. procedure TDebugInfoDwarf.appendprocdef(list:TAsmList; def:tprocdef);
  1977. function dwarf_calling_convention(def: tprocdef): Tdwarf_calling_convention;
  1978. begin
  1979. case def.proccalloption of
  1980. pocall_register:
  1981. result:=DW_CC_GNU_borland_fastcall_i386;
  1982. pocall_cdecl,
  1983. pocall_stdcall,
  1984. pocall_cppdecl,
  1985. pocall_mwpascal:
  1986. result:=DW_CC_normal;
  1987. else
  1988. result:=DW_CC_nocall;
  1989. end
  1990. end;
  1991. var
  1992. procendlabel : tasmlabel;
  1993. procentry : string;
  1994. cc : Tdwarf_calling_convention;
  1995. st : tsymtable;
  1996. vmtoffset : pint;
  1997. in_currentunit : boolean;
  1998. begin
  1999. { only write debug info for procedures defined in the current module,
  2000. except in case of methods (gcc-compatible)
  2001. }
  2002. in_currentunit:=def.in_currentunit;
  2003. if not in_currentunit and
  2004. not (def.owner.symtabletype in [objectsymtable,recordsymtable]) then
  2005. exit;
  2006. { happens for init procdef of units without init section }
  2007. if in_currentunit and
  2008. not assigned(def.procstarttai) then
  2009. exit;
  2010. { Procdefs are not handled by the regular def writing code, so
  2011. dbg_state is not set/checked for them. Do it here. }
  2012. if (def.dbg_state in [dbg_state_writing,dbg_state_written]) then
  2013. exit;
  2014. defnumberlist.Add(def);
  2015. { Write methods and only in the scope of their parent objectdefs. }
  2016. if (def.owner.symtabletype in [objectsymtable,recordsymtable]) then
  2017. begin
  2018. { this code can also work for nested procdefs, but is not yet
  2019. activated for those because there is no clear advantage yet to
  2020. limiting the scope of nested procedures to that of their parent,
  2021. and it makes it impossible to set breakpoints in them by
  2022. referring to their name. }
  2023. st:=def.owner;
  2024. while assigned(st.defowner) and
  2025. (tdef(st.defowner).typ = procdef) do
  2026. st:=tprocdef(st.defowner).owner;
  2027. if assigned(st) and
  2028. (tdef(st.defowner).dbg_state<>dbg_state_writing) then
  2029. exit;
  2030. end;
  2031. def.dbg_state:=dbg_state_writing;
  2032. current_asmdata.asmlists[al_dwarf_info].concat(tai_comment.Create(strpnew('Procdef '+def.fullprocname(true))));
  2033. if not is_objc_class_or_protocol(def.struct) then
  2034. append_entry(DW_TAG_subprogram,true,
  2035. [DW_AT_name,DW_FORM_string,symname(def.procsym, false)+#0])
  2036. else
  2037. append_entry(DW_TAG_subprogram,true,
  2038. [DW_AT_name,DW_FORM_string,def.mangledname+#0]);
  2039. append_proc_frame_base(list,def);
  2040. { Append optional flags. }
  2041. { All Pascal procedures are prototyped }
  2042. append_attribute(DW_AT_prototyped,DW_FORM_flag,[true]);
  2043. { Calling convention. }
  2044. cc:=dwarf_calling_convention(def);
  2045. if (cc<>DW_CC_normal) then
  2046. append_attribute(DW_AT_calling_convention,DW_FORM_data1,[ord(cc)]);
  2047. {$ifdef i8086}
  2048. { Call model (near or far). Open Watcom compatible. }
  2049. if tcpuprocdef(def).is_far then
  2050. append_attribute(DW_AT_address_class,DW_FORM_data1,[DW_ADDR_far16])
  2051. else
  2052. append_attribute(DW_AT_address_class,DW_FORM_data1,[DW_ADDR_none]);
  2053. {$endif i8086}
  2054. { Externally visible. }
  2055. if (po_global in def.procoptions) and
  2056. (def.parast.symtablelevel<=normal_function_level) then
  2057. append_attribute(DW_AT_external,DW_FORM_flag,[true]);
  2058. { Abstract or virtual/overriding method. }
  2059. if (([po_abstractmethod, po_virtualmethod, po_overridingmethod] * def.procoptions) <> []) and
  2060. not is_objc_class_or_protocol(def.struct) and
  2061. not is_objectpascal_helper(def.struct) then
  2062. begin
  2063. if not(po_abstractmethod in def.procoptions) then
  2064. append_attribute(DW_AT_virtuality,DW_FORM_data1,[ord(DW_VIRTUALITY_virtual)])
  2065. else
  2066. append_attribute(DW_AT_virtuality,DW_FORM_data1,[ord(DW_VIRTUALITY_pure_virtual)]);
  2067. { Element number in the vmt (needs to skip stuff coming before the
  2068. actual method addresses in the vmt, so we use vmtmethodoffset()
  2069. and then divide by sizeof(pint)). }
  2070. vmtoffset:=tobjectdef(def.owner.defowner).vmtmethodoffset(def.extnumber);
  2071. append_attribute(DW_AT_vtable_elem_location,DW_FORM_block1,[3+LengthUleb128(vmtoffset)]);
  2072. current_asmdata.asmlists[al_dwarf_info].concat(tai_const.create_8bit(ord(DW_OP_deref)));
  2073. current_asmdata.asmlists[al_dwarf_info].concat(tai_const.create_8bit(ord(DW_OP_constu)));
  2074. current_asmdata.asmlists[al_dwarf_info].concat(tai_const.Create_uleb128bit(vmtoffset));
  2075. current_asmdata.asmlists[al_dwarf_info].concat(tai_const.create_8bit(ord(DW_OP_plus)));
  2076. end;
  2077. { accessibility: public/private/protected }
  2078. if (def.owner.symtabletype in [objectsymtable,recordsymtable]) then
  2079. append_visibility(def.visibility);
  2080. { Return type. }
  2081. if not(is_void(tprocdef(def).returndef)) then
  2082. append_labelentry_ref(DW_AT_type,def_dwarf_lab(tprocdef(def).returndef));
  2083. { we can only write the start/end if this procedure is implemented in
  2084. this module
  2085. }
  2086. if in_currentunit then
  2087. begin
  2088. { mark end of procedure }
  2089. current_asmdata.getlabel(procendlabel,alt_dbgtype);
  2090. current_asmdata.asmlists[al_procedures].insertbefore(tai_label.create(procendlabel),def.procendtai);
  2091. if use_dotted_functions then
  2092. procentry := '.' + def.mangledname
  2093. else
  2094. procentry := def.mangledname;
  2095. {$ifdef i8086}
  2096. append_seg_name(procentry);
  2097. {$endif i8086}
  2098. append_labelentry(DW_AT_low_pc,current_asmdata.RefAsmSymbol(procentry,AT_FUNCTION));
  2099. append_labelentry(DW_AT_high_pc,procendlabel);
  2100. if not(target_info.system in systems_darwin) then
  2101. begin
  2102. current_asmdata.asmlists[al_dwarf_aranges].Concat(
  2103. tai_const.create_type_sym(aitconst_ptr_unaligned,current_asmdata.RefAsmSymbol(procentry,AT_FUNCTION)));
  2104. {$ifdef i8086}
  2105. { bits 16..31 of the offset }
  2106. current_asmdata.asmlists[al_dwarf_aranges].concat(tai_const.Create_16bit_unaligned(0));
  2107. { segment }
  2108. current_asmdata.asmlists[al_dwarf_aranges].concat(tai_const.Create_seg_name(procentry));
  2109. {$endif i8086}
  2110. current_asmdata.asmlists[al_dwarf_aranges].Concat(
  2111. tai_const.Create_rel_sym(aitconst_ptr_unaligned,current_asmdata.RefAsmSymbol(procentry,AT_FUNCTION),procendlabel));
  2112. {$ifdef i8086}
  2113. { bits 16..31 of length }
  2114. current_asmdata.asmlists[al_dwarf_aranges].concat(tai_const.Create_16bit_unaligned(0));
  2115. {$endif i8086}
  2116. end;
  2117. end;
  2118. { Don't write the funcretsym explicitly, it's also in the
  2119. localsymtable and/or parasymtable.
  2120. }
  2121. finish_entry;
  2122. if assigned(def.parast) then
  2123. begin
  2124. { First insert self, because gdb uses the fact whether or not the
  2125. first parameter of a method is artificial to distinguish static
  2126. from regular methods. }
  2127. { fortunately, self is the always the first parameter in the
  2128. paralist, since it has the lowest paranr. Note that this is not
  2129. true for Objective-C, but those methods are detected in
  2130. another way (by reading the ObjC run time information) }
  2131. write_symtable_parasyms(current_asmdata.asmlists[al_dwarf_info],def.paras);
  2132. end;
  2133. { local type defs and vars should not be written
  2134. inside the main proc }
  2135. if in_currentunit and
  2136. assigned(def.localst) and
  2137. (def.localst.symtabletype=localsymtable) then
  2138. write_symtable_syms(current_asmdata.asmlists[al_dwarf_info],def.localst);
  2139. { last write the types from this procdef }
  2140. if assigned(def.parast) then
  2141. write_symtable_defs(current_asmdata.asmlists[al_dwarf_info],def.parast);
  2142. { only try to write the localst if the routine is implemented here }
  2143. if in_currentunit and
  2144. assigned(def.localst) and
  2145. (def.localst.symtabletype=localsymtable) then
  2146. begin
  2147. write_symtable_defs(current_asmdata.asmlists[al_dwarf_info],def.localst);
  2148. { Write nested procedures -- disabled, see scope check at the
  2149. beginning; currently, these are still written in the global
  2150. scope. }
  2151. // write_symtable_procdefs(current_asmdata.asmlists[al_dwarf_info],def.localst);
  2152. end;
  2153. finish_children;
  2154. end;
  2155. function TDebugInfoDwarf.get_symlist_sym_offset(symlist: ppropaccesslistitem; out sym: tabstractvarsym; out offset: pint): boolean;
  2156. var
  2157. elesize : pint;
  2158. currdef : tdef;
  2159. indirection: boolean;
  2160. begin
  2161. result:=false;
  2162. if not assigned(symlist) then
  2163. exit;
  2164. sym:=nil;
  2165. offset:=0;
  2166. currdef:=nil;
  2167. indirection:=false;
  2168. repeat
  2169. case symlist^.sltype of
  2170. sl_load:
  2171. begin
  2172. if assigned(sym) then
  2173. internalerror(2009031203);
  2174. if not(symlist^.sym.typ in [paravarsym,localvarsym,staticvarsym,fieldvarsym]) then
  2175. { can't handle... }
  2176. exit;
  2177. sym:=tabstractvarsym(symlist^.sym);
  2178. currdef:=tabstractvarsym(sym).vardef;
  2179. if ((sym.typ=paravarsym) and
  2180. paramanager.push_addr_param(tparavarsym(sym).varspez,sym.vardef,tprocdef(sym.owner.defowner).proccalloption)) then
  2181. indirection:=true;
  2182. end;
  2183. sl_subscript:
  2184. begin
  2185. if not assigned(currdef) then
  2186. internalerror(2009031301);
  2187. if (symlist^.sym.typ<>fieldvarsym) then
  2188. internalerror(2009031202);
  2189. { can't handle offsets with indirections yet }
  2190. if indirection then
  2191. exit;
  2192. if is_packed_record_or_object(currdef) then
  2193. begin
  2194. { can't calculate the address of a non-byte aligned field }
  2195. if (tfieldvarsym(symlist^.sym).fieldoffset mod 8) <> 0 then
  2196. exit;
  2197. inc(offset,tfieldvarsym(symlist^.sym).fieldoffset div 8)
  2198. end
  2199. else
  2200. inc(offset,tfieldvarsym(symlist^.sym).fieldoffset);
  2201. currdef:=tfieldvarsym(symlist^.sym).vardef;
  2202. end;
  2203. sl_absolutetype,
  2204. sl_typeconv:
  2205. begin
  2206. currdef:=symlist^.def;
  2207. { ignore, these don't change the address }
  2208. end;
  2209. sl_vec:
  2210. begin
  2211. if not assigned(currdef) or
  2212. (currdef.typ<>arraydef) then
  2213. internalerror(2009031201);
  2214. { can't handle offsets with indirections yet }
  2215. if indirection then
  2216. exit;
  2217. if not is_packed_array(currdef) then
  2218. elesize:=tarraydef(currdef).elesize
  2219. else
  2220. begin
  2221. elesize:=tarraydef(currdef).elepackedbitsize;
  2222. { can't calculate the address of a non-byte aligned element }
  2223. if (elesize mod 8)<>0 then
  2224. exit;
  2225. elesize:=elesize div 8;
  2226. end;
  2227. inc(offset,(symlist^.value.svalue-tarraydef(currdef).lowrange)*elesize);
  2228. currdef:=tarraydef(currdef).elementdef;
  2229. end;
  2230. else
  2231. internalerror(2009031401);
  2232. end;
  2233. symlist:=symlist^.next;
  2234. until not assigned(symlist);
  2235. if not assigned(sym) then
  2236. internalerror(2009031205);
  2237. result:=true;
  2238. end;
  2239. procedure TDebugInfoDwarf.appendsym_var(list:TAsmList;sym:tabstractnormalvarsym);
  2240. begin
  2241. appendsym_var_with_name_type_offset(list,sym,symname(sym, false),sym.vardef,0,[]);
  2242. end;
  2243. procedure TDebugInfoDwarf.appendsym_var_with_name_type_offset(list:TAsmList; sym:tabstractnormalvarsym; const name: string; def: tdef; offset: pint; const flags: tdwarfvarsymflags);
  2244. var
  2245. templist : TAsmList;
  2246. blocksize,size_of_int : longint;
  2247. tag : tdwarf_tag;
  2248. has_high_reg : boolean;
  2249. dreg,dreghigh : shortint;
  2250. {$ifdef i8086}
  2251. has_segment_sym_name : boolean=false;
  2252. segment_sym_name : TSymStr='';
  2253. segment_reg: TRegister=NR_NO;
  2254. {$endif i8086}
  2255. begin
  2256. blocksize:=0;
  2257. dreghigh:=0;
  2258. { external symbols can't be resolved at link time, so we
  2259. can't generate stabs for them
  2260. not sure if this applies to dwarf as well (FK)
  2261. }
  2262. if vo_is_external in sym.varoptions then
  2263. exit;
  2264. { There is no space allocated for not referenced locals }
  2265. if (sym.owner.symtabletype=localsymtable) and (sym.refs=0) then
  2266. exit;
  2267. templist:=TAsmList.create;
  2268. case sym.localloc.loc of
  2269. LOC_REGISTER,
  2270. LOC_CREGISTER,
  2271. LOC_MMREGISTER,
  2272. LOC_CMMREGISTER,
  2273. LOC_FPUREGISTER,
  2274. LOC_CFPUREGISTER :
  2275. begin
  2276. { dwarf_reg_no_error might return -1
  2277. in case the register variable has been optimized out }
  2278. dreg:=dwarf_reg_no_error(sym.localloc.register);
  2279. has_high_reg:=(sym.localloc.loc in [LOC_REGISTER,LOC_CREGISTER]) and (sym.localloc.registerhi<>NR_NO);
  2280. if has_high_reg then
  2281. dreghigh:=dwarf_reg_no_error(sym.localloc.registerhi);
  2282. if dreghigh=-1 then
  2283. has_high_reg:=false;
  2284. if (sym.localloc.loc in [LOC_REGISTER,LOC_CREGISTER]) and
  2285. (sym.typ=paravarsym) and
  2286. paramanager.push_addr_param(sym.varspez,sym.vardef,tprocdef(sym.owner.defowner).proccalloption) and
  2287. not(vo_has_local_copy in sym.varoptions) and
  2288. not is_open_string(sym.vardef) and (dreg>=0) then
  2289. begin
  2290. templist.concat(tai_const.create_8bit(ord(DW_OP_bregx)));
  2291. templist.concat(tai_const.create_uleb128bit(dreg));
  2292. templist.concat(tai_const.create_sleb128bit(0));
  2293. blocksize:=1+Lengthuleb128(dreg)+LengthSleb128(0);
  2294. end
  2295. else
  2296. begin
  2297. if has_high_reg then
  2298. begin
  2299. templist.concat(tai_comment.create(strpnew('high:low reg pair variable')));
  2300. size_of_int:=sizeof(aint);
  2301. templist.concat(tai_const.create_8bit(ord(DW_OP_regx)));
  2302. templist.concat(tai_const.create_uleb128bit(dreg));
  2303. blocksize:=1+Lengthuleb128(dreg);
  2304. templist.concat(tai_const.create_8bit(ord(DW_OP_piece)));
  2305. templist.concat(tai_const.create_uleb128bit(size_of_int));
  2306. blocksize:=blocksize+1+Lengthuleb128(size_of_int);
  2307. templist.concat(tai_const.create_8bit(ord(DW_OP_regx)));
  2308. templist.concat(tai_const.create_uleb128bit(dreghigh));
  2309. blocksize:=blocksize+1+Lengthuleb128(dreghigh);
  2310. templist.concat(tai_const.create_8bit(ord(DW_OP_piece)));
  2311. templist.concat(tai_const.create_uleb128bit(size_of_int));
  2312. blocksize:=blocksize+1+Lengthuleb128(size_of_int);
  2313. end
  2314. else if (dreg>=0) then
  2315. begin
  2316. templist.concat(tai_const.create_8bit(ord(DW_OP_regx)));
  2317. templist.concat(tai_const.create_uleb128bit(dreg));
  2318. blocksize:=1+Lengthuleb128(dreg);
  2319. end;
  2320. end;
  2321. end;
  2322. else
  2323. begin
  2324. case sym.typ of
  2325. staticvarsym:
  2326. begin
  2327. if (vo_is_thread_var in sym.varoptions) then
  2328. begin
  2329. { TODO: !!! FIXME: dwarf for thread vars !!!}
  2330. { This is only a minimal change to at least be able to get a value
  2331. in only one thread is present PM 2014-11-21, like for stabs format }
  2332. templist.concat(tai_const.create_8bit(ord(DW_OP_addr)));
  2333. templist.concat(tai_const.Create_type_name(aitconst_ptr_unaligned,sym.mangledname,
  2334. offset+sizeof(pint)));
  2335. blocksize:=1+sizeof(puint);
  2336. end
  2337. else
  2338. begin
  2339. templist.concat(tai_const.create_8bit(ord(DW_OP_addr)));
  2340. templist.concat(tai_const.Create_type_name(aitconst_ptr_unaligned,sym.mangledname,offset));
  2341. blocksize:=1+sizeof(puint);
  2342. {$ifdef i8086}
  2343. segment_sym_name:=sym.mangledname;
  2344. has_segment_sym_name:=true;
  2345. {$endif i8086}
  2346. end;
  2347. end;
  2348. paravarsym,
  2349. localvarsym:
  2350. begin
  2351. { Happens when writing debug info for paras of procdefs not
  2352. implemented in the current module. Can't add a general check
  2353. for LOC_INVALID above, because staticvarsyms may also have it.
  2354. }
  2355. if sym.localloc.loc<> LOC_INVALID then
  2356. begin
  2357. if is_fbreg(sym.localloc.reference.base) then
  2358. begin
  2359. templist.concat(tai_const.create_8bit(ord(DW_OP_fbreg)));
  2360. templist.concat(tai_const.create_sleb128bit(sym.localloc.reference.offset+offset));
  2361. blocksize:=1+Lengthsleb128(sym.localloc.reference.offset+offset);
  2362. end
  2363. else
  2364. begin
  2365. dreg:=dwarf_reg(sym.localloc.reference.base);
  2366. if dreg<=31 then
  2367. begin
  2368. templist.concat(tai_const.create_8bit(ord(DW_OP_breg0)+dreg));
  2369. templist.concat(tai_const.create_sleb128bit(sym.localloc.reference.offset+offset));
  2370. blocksize:=1+Lengthsleb128(sym.localloc.reference.offset+offset);
  2371. end
  2372. else
  2373. begin
  2374. templist.concat(tai_const.create_8bit(ord(DW_OP_bregx)));
  2375. templist.concat(tai_const.create_uleb128bit(dreg));
  2376. templist.concat(tai_const.create_sleb128bit(sym.localloc.reference.offset+offset));
  2377. blocksize:=1+Lengthuleb128(dreg)+LengthSleb128(sym.localloc.reference.offset+offset);
  2378. end;
  2379. end;
  2380. {$ifdef i8086}
  2381. segment_reg:=sym.localloc.reference.segment;
  2382. {$endif i8086}
  2383. {$ifndef gdb_supports_DW_AT_variable_parameter}
  2384. { Parameters which are passed by reference. (var and the like)
  2385. Hide the reference-pointer and dereference the pointer
  2386. in the DW_AT_location block.
  2387. }
  2388. if (sym.typ=paravarsym) and
  2389. paramanager.push_addr_param(sym.varspez,sym.vardef,tprocdef(sym.owner.defowner).proccalloption) and
  2390. not(vo_has_local_copy in sym.varoptions) and
  2391. not is_open_string(sym.vardef) then
  2392. begin
  2393. templist.concat(tai_const.create_8bit(ord(DW_OP_deref)));
  2394. inc(blocksize);
  2395. end
  2396. {$endif not gdb_supports_DW_AT_variable_parameter}
  2397. end;
  2398. end
  2399. else
  2400. internalerror(200601288);
  2401. end;
  2402. end;
  2403. end;
  2404. { function results must not be added to the parameter list,
  2405. as they are not part of the signature of the function
  2406. (gdb automatically adds them according to the ABI specifications
  2407. when calling the function)
  2408. }
  2409. if (sym.typ=paravarsym) and
  2410. not(dvf_force_local_var in flags) and
  2411. not(vo_is_funcret in sym.varoptions) then
  2412. tag:=DW_TAG_formal_parameter
  2413. else
  2414. tag:=DW_TAG_variable;
  2415. { must be parasym of externally implemented procdef, but
  2416. the parasymtable can con also contain e.g. absolutevarsyms
  2417. -> check symtabletype}
  2418. if (sym.owner.symtabletype=parasymtable) and
  2419. (sym.localloc.loc=LOC_INVALID) then
  2420. begin
  2421. if (sym.owner.symtabletype<>parasymtable) then
  2422. internalerror(2009101001);
  2423. append_entry(tag,false,[
  2424. DW_AT_name,DW_FORM_string,name+#0
  2425. {
  2426. DW_AT_decl_file,DW_FORM_data1,0,
  2427. DW_AT_decl_line,DW_FORM_data1,
  2428. }
  2429. ])
  2430. end
  2431. else if not(sym.localloc.loc in [LOC_REGISTER,LOC_CREGISTER,LOC_MMREGISTER,
  2432. LOC_CMMREGISTER,LOC_FPUREGISTER,LOC_CFPUREGISTER]) and
  2433. ((sym.owner.symtabletype = globalsymtable) or
  2434. (sp_static in sym.symoptions) or
  2435. (vo_is_public in sym.varoptions)) then
  2436. append_entry(tag,false,[
  2437. DW_AT_name,DW_FORM_string,name+#0,
  2438. {
  2439. DW_AT_decl_file,DW_FORM_data1,0,
  2440. DW_AT_decl_line,DW_FORM_data1,
  2441. }
  2442. DW_AT_external,DW_FORM_flag,true,
  2443. { data continues below }
  2444. DW_AT_location,DW_FORM_block1,blocksize
  2445. ])
  2446. {$ifdef gdb_supports_DW_AT_variable_parameter}
  2447. else if (sym.typ=paravarsym) and
  2448. paramanager.push_addr_param(sym.varspez,sym.vardef,tprocdef(sym.owner.defowner).proccalloption) and
  2449. not(vo_has_local_copy in sym.varoptions) and
  2450. not is_open_string(sym.vardef) then
  2451. append_entry(tag,false,[
  2452. DW_AT_name,DW_FORM_string,name+#0,
  2453. DW_AT_variable_parameter,DW_FORM_flag,true,
  2454. {
  2455. DW_AT_decl_file,DW_FORM_data1,0,
  2456. DW_AT_decl_line,DW_FORM_data1,
  2457. }
  2458. { data continues below }
  2459. DW_AT_location,DW_FORM_block1,blocksize
  2460. ])
  2461. {$endif gdb_supports_DW_AT_variable_parameter}
  2462. else
  2463. append_entry(tag,false,[
  2464. DW_AT_name,DW_FORM_string,name+#0,
  2465. {
  2466. DW_AT_decl_file,DW_FORM_data1,0,
  2467. DW_AT_decl_line,DW_FORM_data1,
  2468. }
  2469. { data continues below }
  2470. DW_AT_location,DW_FORM_block1,blocksize
  2471. ]);
  2472. { append block data }
  2473. current_asmdata.asmlists[al_dwarf_info].concatlist(templist);
  2474. { Mark self as artificial for methods, because gdb uses the fact
  2475. whether or not the first parameter of a method is artificial to
  2476. distinguish regular from static methods (since there are no
  2477. no vo_is_self parameters for static methods, we don't have to check
  2478. that). }
  2479. if (vo_is_self in sym.varoptions) then
  2480. append_attribute(DW_AT_artificial,DW_FORM_flag,[true]);
  2481. append_labelentry_ref(DW_AT_type,def_dwarf_lab(def));
  2482. {$ifdef i8086}
  2483. if has_segment_sym_name then
  2484. append_seg_name(segment_sym_name)
  2485. else if segment_reg<>NR_NO then
  2486. append_seg_reg(segment_reg);
  2487. {$endif i8086}
  2488. templist.free;
  2489. finish_entry;
  2490. end;
  2491. procedure TDebugInfoDwarf.appendsym_staticvar(list:TAsmList;sym:tstaticvarsym);
  2492. begin
  2493. appendsym_var(list,sym);
  2494. end;
  2495. procedure TDebugInfoDwarf.appendsym_localvar(list:TAsmList;sym:tlocalvarsym);
  2496. begin
  2497. appendsym_var(list,sym);
  2498. end;
  2499. procedure TDebugInfoDwarf.appendsym_paravar(list:TAsmList;sym:tparavarsym);
  2500. begin
  2501. appendsym_var(list,sym);
  2502. end;
  2503. procedure TDebugInfoDwarf.appendsym_fieldvar(list:TAsmList;sym: tfieldvarsym);
  2504. begin
  2505. appendsym_fieldvar_with_name_offset(list,sym,symname(sym, false),sym.vardef,0);
  2506. end;
  2507. procedure TDebugInfoDwarf.appendsym_fieldvar_with_name_offset(list:TAsmList;sym: tfieldvarsym;const name: string; def: tdef; offset: pint);
  2508. var
  2509. bitoffset,
  2510. fieldoffset,
  2511. fieldnatsize: asizeint;
  2512. begin
  2513. if (sp_static in sym.symoptions) or
  2514. (sym.visibility=vis_hidden) then
  2515. exit;
  2516. if (tabstractrecordsymtable(sym.owner).usefieldalignment<>bit_alignment) or
  2517. { only ordinals are bitpacked }
  2518. not is_ordinal(sym.vardef) then
  2519. begin
  2520. { other kinds of fields can however also appear in a bitpacked }
  2521. { record, and then their offset is also specified in bits rather }
  2522. { than in bytes }
  2523. if (tabstractrecordsymtable(sym.owner).usefieldalignment<>bit_alignment) then
  2524. fieldoffset:=sym.fieldoffset
  2525. else
  2526. fieldoffset:=sym.fieldoffset div 8;
  2527. inc(fieldoffset,offset);
  2528. append_entry(DW_TAG_member,false,[
  2529. DW_AT_name,DW_FORM_string,name+#0,
  2530. DW_AT_data_member_location,DW_FORM_block1,1+lengthuleb128(fieldoffset)
  2531. ]);
  2532. end
  2533. else
  2534. begin
  2535. if (sym.vardef.packedbitsize > 255) then
  2536. internalerror(2007061201);
  2537. { we don't bitpack according to the ABI, but as close as }
  2538. { possible, i.e., equivalent to gcc's }
  2539. { __attribute__((__packed__)), which is also what gpc }
  2540. { does. }
  2541. fieldnatsize:=max(sizeof(pint),sym.vardef.size);
  2542. fieldoffset:=(sym.fieldoffset div (fieldnatsize*8)) * fieldnatsize;
  2543. inc(fieldoffset,offset);
  2544. bitoffset:=sym.fieldoffset mod (fieldnatsize*8);
  2545. if (target_info.endian=endian_little) then
  2546. bitoffset:=(fieldnatsize*8)-bitoffset-sym.vardef.packedbitsize;
  2547. append_entry(DW_TAG_member,false,[
  2548. DW_AT_name,DW_FORM_string,symname(sym, false)+#0,
  2549. { gcc also generates both a bit and byte size attribute }
  2550. { we don't support ordinals >= 256 bits }
  2551. DW_AT_byte_size,DW_FORM_data1,fieldnatsize,
  2552. { nor >= 256 bits (not yet, anyway, see IE above) }
  2553. DW_AT_bit_size,DW_FORM_data1,sym.vardef.packedbitsize,
  2554. { data1 and data2 are unsigned, bitoffset can also be negative }
  2555. DW_AT_bit_offset,DW_FORM_data4,bitoffset,
  2556. DW_AT_data_member_location,DW_FORM_block1,1+lengthuleb128(fieldoffset)
  2557. ]);
  2558. end;
  2559. current_asmdata.asmlists[al_dwarf_info].concat(tai_const.create_8bit(ord(DW_OP_plus_uconst)));
  2560. current_asmdata.asmlists[al_dwarf_info].concat(tai_const.create_uleb128bit(fieldoffset));
  2561. if (sym.owner.symtabletype in [objectsymtable,recordsymtable]) then
  2562. append_visibility(sym.visibility);
  2563. append_labelentry_ref(DW_AT_type,def_dwarf_lab(def));
  2564. finish_entry;
  2565. end;
  2566. procedure TDebugInfoDwarf.appendsym_const(list:TAsmList;sym:tconstsym);
  2567. begin
  2568. appendsym_const_member(list,sym,false);
  2569. end;
  2570. procedure TDebugInfoDwarf.appendsym_const_member(list:TAsmList;sym:tconstsym;ismember:boolean);
  2571. var
  2572. i,
  2573. size: aint;
  2574. usedef: tdef;
  2575. begin
  2576. { These are default values of parameters. These should be encoded
  2577. via DW_AT_default_value, not as a separate sym. Moreover, their
  2578. type is not available when writing the debug info for external
  2579. procedures.
  2580. }
  2581. if (sym.owner.symtabletype=parasymtable) then
  2582. exit;
  2583. if ismember then
  2584. append_entry(DW_TAG_member,false,[
  2585. DW_AT_name,DW_FORM_string,symname(sym, false)+#0,
  2586. { The DW_AT_declaration tag is invalid according to the DWARF specifications.
  2587. But gcc adds this to static const members and gdb checks
  2588. for this flag. So we have to set it also.
  2589. }
  2590. DW_AT_declaration,DW_FORM_flag,true,
  2591. DW_AT_external,DW_FORM_flag,true
  2592. ])
  2593. else
  2594. append_entry(DW_TAG_variable,false,[
  2595. DW_AT_name,DW_FORM_string,symname(sym, false)+#0
  2596. ]);
  2597. { for string constants, constdef isn't set because they have no real type }
  2598. case sym.consttyp of
  2599. conststring:
  2600. begin
  2601. { if DW_FORM_string is used below one day, this usedef should
  2602. probably become nil }
  2603. { note: < 255 instead of <= 255 because we have to store the
  2604. entire length of the string as well, and 256 does not fit in
  2605. a byte }
  2606. if (sym.value.len<255) then
  2607. usedef:=cshortstringtype
  2608. else
  2609. usedef:=clongstringtype;
  2610. end;
  2611. constresourcestring,
  2612. constwstring:
  2613. usedef:=nil;
  2614. else
  2615. usedef:=sym.constdef;
  2616. end;
  2617. if assigned(usedef) then
  2618. append_labelentry_ref(DW_AT_type,def_dwarf_lab(usedef));
  2619. AddConstToAbbrev(ord(DW_AT_const_value));
  2620. case sym.consttyp of
  2621. conststring:
  2622. begin
  2623. { DW_FORM_string isn't supported yet by the Pascal value printer
  2624. -> create a string using raw bytes }
  2625. if (sym.value.len<255) then
  2626. begin
  2627. AddConstToAbbrev(ord(DW_FORM_block1));
  2628. current_asmdata.asmlists[al_dwarf_info].concat(tai_const.create_8bit(sym.value.len+1));
  2629. current_asmdata.asmlists[al_dwarf_info].concat(tai_const.create_8bit(sym.value.len));
  2630. end
  2631. else
  2632. begin
  2633. AddConstToAbbrev(ord(DW_FORM_block));
  2634. current_asmdata.asmlists[al_dwarf_info].concat(tai_const.create_uleb128bit(sym.value.len+sizesinttype.size));
  2635. current_asmdata.asmlists[al_dwarf_info].concat(tai_const.Create_sizeint_unaligned(sym.value.len));
  2636. end;
  2637. i:=0;
  2638. size:=sym.value.len;
  2639. while(i<size) do
  2640. begin
  2641. current_asmdata.asmlists[al_dwarf_info].concat(tai_const.create_8bit((pbyte(sym.value.valueptr+i)^)));
  2642. inc(i);
  2643. end;
  2644. end;
  2645. constguid,
  2646. constset:
  2647. begin
  2648. AddConstToAbbrev(ord(DW_FORM_block1));
  2649. current_asmdata.asmlists[al_dwarf_info].concat(tai_const.create_8bit(usedef.size));
  2650. i:=0;
  2651. size:=sym.constdef.size;
  2652. while (i<size) do
  2653. begin
  2654. current_asmdata.asmlists[al_dwarf_info].concat(tai_const.create_8bit((pbyte(sym.value.valueptr+i)^)));
  2655. inc(i);
  2656. end;
  2657. end;
  2658. constwstring,
  2659. constresourcestring:
  2660. begin
  2661. { write dummy for now }
  2662. AddConstToAbbrev(ord(DW_FORM_string));
  2663. current_asmdata.asmlists[al_dwarf_info].concat(tai_string.create(''));
  2664. current_asmdata.asmlists[al_dwarf_info].concat(tai_const.create_8bit(0));
  2665. end;
  2666. constord:
  2667. begin
  2668. if (sym.value.valueord<0) then
  2669. begin
  2670. AddConstToAbbrev(ord(DW_FORM_sdata));
  2671. current_asmdata.asmlists[al_dwarf_info].concat(tai_const.create_sleb128bit(sym.value.valueord.svalue));
  2672. end
  2673. else
  2674. begin
  2675. AddConstToAbbrev(ord(DW_FORM_udata));
  2676. current_asmdata.asmlists[al_dwarf_info].concat(tai_const.create_uleb128bit(sym.value.valueord.uvalue));
  2677. end;
  2678. end;
  2679. constnil:
  2680. begin
  2681. {$ifdef cpu64bitaddr}
  2682. AddConstToAbbrev(ord(DW_FORM_data8));
  2683. current_asmdata.asmlists[al_dwarf_info].concat(tai_const.create_64bit_unaligned(0));
  2684. {$else cpu64bitaddr}
  2685. AddConstToAbbrev(ord(DW_FORM_data4));
  2686. current_asmdata.asmlists[al_dwarf_info].concat(tai_const.create_32bit_unaligned(0));
  2687. {$endif cpu64bitaddr}
  2688. end;
  2689. constpointer:
  2690. begin
  2691. {$ifdef cpu64bitaddr}
  2692. AddConstToAbbrev(ord(DW_FORM_data8));
  2693. current_asmdata.asmlists[al_dwarf_info].concat(tai_const.create_64bit_unaligned(int64(sym.value.valueordptr)));
  2694. {$else cpu64bitaddr}
  2695. AddConstToAbbrev(ord(DW_FORM_data4));
  2696. current_asmdata.asmlists[al_dwarf_info].concat(tai_const.create_32bit_unaligned(longint(sym.value.valueordptr)));
  2697. {$endif cpu64bitaddr}
  2698. end;
  2699. constreal:
  2700. begin
  2701. AddConstToAbbrev(ord(DW_FORM_block1));
  2702. case tfloatdef(sym.constdef).floattype of
  2703. s32real:
  2704. begin
  2705. current_asmdata.asmlists[al_dwarf_info].concat(tai_const.create_8bit(4));
  2706. current_asmdata.asmlists[al_dwarf_info].concat(tai_realconst.create_s32real(pbestreal(sym.value.valueptr)^));
  2707. end;
  2708. s64real:
  2709. begin
  2710. current_asmdata.asmlists[al_dwarf_info].concat(tai_const.create_8bit(8));
  2711. current_asmdata.asmlists[al_dwarf_info].concat(tai_realconst.create_s64real(pbestreal(sym.value.valueptr)^));
  2712. end;
  2713. s64comp,
  2714. s64currency:
  2715. begin
  2716. current_asmdata.asmlists[al_dwarf_info].concat(tai_const.create_8bit(8));
  2717. current_asmdata.asmlists[al_dwarf_info].concat(tai_const.create_64bit_unaligned(trunc(pbestreal(sym.value.valueptr)^)));
  2718. end;
  2719. s80real,
  2720. sc80real:
  2721. begin
  2722. current_asmdata.asmlists[al_dwarf_info].concat(tai_const.create_8bit(sym.constdef.size));
  2723. current_asmdata.asmlists[al_dwarf_info].concat(tai_realconst.create_s80real(pextended(sym.value.valueptr)^,sym.constdef.size));
  2724. end;
  2725. else
  2726. internalerror(200601291);
  2727. end;
  2728. end;
  2729. else
  2730. internalerror(200601292);
  2731. end;
  2732. finish_entry;
  2733. end;
  2734. procedure TDebugInfoDwarf.appendsym_label(list:TAsmList;sym: tlabelsym);
  2735. begin
  2736. { ignore label syms for now, the problem is that a label sym
  2737. can have more than one label associated e.g. in case of
  2738. an inline procedure expansion }
  2739. end;
  2740. procedure TDebugInfoDwarf.appendsym_property(list:TAsmList;sym: tpropertysym);
  2741. var
  2742. symlist: ppropaccesslistitem;
  2743. tosym: tabstractvarsym;
  2744. offset: pint;
  2745. begin
  2746. if assigned(sym.propaccesslist[palt_read]) and
  2747. not assigned(sym.propaccesslist[palt_read].procdef) then
  2748. symlist:=sym.propaccesslist[palt_read].firstsym
  2749. else
  2750. { can't handle }
  2751. exit;
  2752. if not get_symlist_sym_offset(symlist,tosym,offset) then
  2753. exit;
  2754. if not (tosym.owner.symtabletype in [objectsymtable,recordsymtable]) then
  2755. begin
  2756. if (tosym.typ=fieldvarsym) then
  2757. internalerror(2009031404);
  2758. appendsym_var_with_name_type_offset(list,tabstractnormalvarsym(tosym),symname(sym, false),sym.propdef,offset,[])
  2759. end
  2760. else
  2761. appendsym_fieldvar_with_name_offset(list,tfieldvarsym(tosym),symname(sym, false),sym.propdef,offset)
  2762. end;
  2763. function TDebugInfoDwarf.symdebugname(sym: tsym): String;
  2764. begin
  2765. result := sym.name;
  2766. end;
  2767. procedure TDebugInfoDwarf.appendsym_type(list:TAsmList;sym: ttypesym);
  2768. begin
  2769. { just queue the def if needed, beforeappenddef will
  2770. emit the typedef if necessary }
  2771. def_dwarf_lab(sym.typedef);
  2772. end;
  2773. procedure TDebugInfoDwarf.appendsym_absolute(list:TAsmList;sym:tabsolutevarsym);
  2774. var
  2775. templist : TAsmList;
  2776. blocksize : longint;
  2777. symlist : ppropaccesslistitem;
  2778. tosym: tabstractvarsym;
  2779. offset: pint;
  2780. flags: tdwarfvarsymflags;
  2781. begin
  2782. templist:=TAsmList.create;
  2783. case tabsolutevarsym(sym).abstyp of
  2784. toaddr :
  2785. begin
  2786. { MWE: replaced ifdef i368 }
  2787. (*
  2788. if target_cpu = cpu_i386 then
  2789. begin
  2790. { in theory, we could write a DW_AT_segment entry here for sym.absseg,
  2791. however I doubt that gdb supports this (FK) }
  2792. end;
  2793. *)
  2794. templist.concat(tai_const.create_8bit(3));
  2795. templist.concat(tai_const.create_int_dataptr_unaligned(sym.addroffset));
  2796. blocksize:=1+sizeof(puint);
  2797. end;
  2798. toasm :
  2799. begin
  2800. templist.concat(tai_const.create_8bit(3));
  2801. templist.concat(tai_const.create_type_name(aitconst_ptr_unaligned,sym.mangledname,0));
  2802. blocksize:=1+sizeof(puint);
  2803. end;
  2804. tovar:
  2805. begin
  2806. symlist:=tabsolutevarsym(sym).ref.firstsym;
  2807. if get_symlist_sym_offset(symlist,tosym,offset) then
  2808. begin
  2809. if (tosym.typ=fieldvarsym) then
  2810. internalerror(2009031402);
  2811. flags:=[];
  2812. if (sym.owner.symtabletype=localsymtable) then
  2813. include(flags,dvf_force_local_var);
  2814. appendsym_var_with_name_type_offset(list,tabstractnormalvarsym(tosym),symname(sym, false),tabstractvarsym(sym).vardef,offset,flags);
  2815. end;
  2816. templist.free;
  2817. exit;
  2818. end;
  2819. else
  2820. internalerror(2013120111);
  2821. end;
  2822. append_entry(DW_TAG_variable,false,[
  2823. DW_AT_name,DW_FORM_string,symname(sym, false)+#0,
  2824. {
  2825. DW_AT_decl_file,DW_FORM_data1,0,
  2826. DW_AT_decl_line,DW_FORM_data1,
  2827. }
  2828. DW_AT_external,DW_FORM_flag,true,
  2829. { data continues below }
  2830. DW_AT_location,DW_FORM_block1,blocksize
  2831. ]);
  2832. { append block data }
  2833. current_asmdata.asmlists[al_dwarf_info].concatlist(templist);
  2834. append_labelentry_ref(DW_AT_type,def_dwarf_lab(sym.vardef));
  2835. templist.free;
  2836. finish_entry;
  2837. end;
  2838. procedure TDebugInfoDwarf.beforeappendsym(list:TAsmList;sym:tsym);
  2839. begin
  2840. current_asmdata.asmlists[al_dwarf_info].concat(tai_comment.Create(strpnew('Symbol '+symname(sym, true))));
  2841. end;
  2842. procedure TDebugInfoDwarf.insertmoduleinfo;
  2843. var
  2844. templist: TAsmList;
  2845. linelist: TAsmList;
  2846. lbl : tasmlabel;
  2847. n,m : Integer;
  2848. ditem : TDirIndexItem;
  2849. fitem : TFileIndexItem;
  2850. flist : TFPList;
  2851. dbgname : String;
  2852. begin
  2853. { insert DEBUGSTART and DEBUGEND labels }
  2854. dbgname:=make_mangledname('DEBUGSTART',current_module.localsymtable,'');
  2855. { Darwin's linker does not like two global labels both pointing to the
  2856. end of a section, which can happen in case of units without code ->
  2857. make them local; we don't need the debugtable stuff there either,
  2858. so it doesn't matter that they are not global.
  2859. }
  2860. if (target_info.system in systems_darwin) then
  2861. dbgname:='L'+dbgname;
  2862. new_section(current_asmdata.asmlists[al_start],sec_code,dbgname,0,secorder_begin);
  2863. if not(target_info.system in systems_darwin) then
  2864. current_asmdata.asmlists[al_start].concat(tai_symbol.Createname_global(dbgname,AT_METADATA,0,voidpointertype))
  2865. else
  2866. current_asmdata.asmlists[al_start].concat(tai_symbol.Createname(dbgname,AT_METADATA,0,voidpointertype));
  2867. dbgname:=make_mangledname('DEBUGEND',current_module.localsymtable,'');
  2868. { See above. }
  2869. if (target_info.system in systems_darwin) then
  2870. dbgname:='L'+dbgname;
  2871. new_section(current_asmdata.asmlists[al_end],sec_code,dbgname,0,secorder_end);
  2872. if not(target_info.system in systems_darwin) then
  2873. current_asmdata.asmlists[al_end].concat(tai_symbol.Createname_global(dbgname,AT_METADATA,0,voidpointertype))
  2874. else
  2875. current_asmdata.asmlists[al_end].concat(tai_symbol.Createname(dbgname,AT_METADATA,0,voidpointertype));
  2876. { insert .Ldebug_abbrev0 label }
  2877. templist:=TAsmList.create;
  2878. new_section(templist,sec_debug_abbrev,'',0);
  2879. templist.concat(tai_symbol.createname(target_asm.labelprefix+'debug_abbrevsection0',AT_METADATA,0,voidpointertype));
  2880. { add any extra stuff which needs to be in the abbrev section, but before }
  2881. { the actual abbreviations, in between the symbol above and below, i.e. here }
  2882. templist.concat(tai_symbol.createname(target_asm.labelprefix+'debug_abbrev0',AT_METADATA,0,voidpointertype));
  2883. current_asmdata.asmlists[al_start].insertlist(templist);
  2884. templist.free;
  2885. { insert .Ldebug_line0 label }
  2886. templist:=TAsmList.create;
  2887. new_section(templist,sec_debug_line,'',0);
  2888. templist.concat(tai_symbol.createname(target_asm.labelprefix+'debug_linesection0',AT_METADATA,0,voidpointertype));
  2889. { add any extra stuff which needs to be in the line section, but before }
  2890. { the actual line info, in between the symbol above and below, i.e. here }
  2891. templist.concat(tai_symbol.createname(target_asm.labelprefix+'debug_line0',AT_METADATA,0,voidpointertype));
  2892. current_asmdata.asmlists[al_start].insertlist(templist);
  2893. templist.free;
  2894. { finalize line info if the unit doesn't contain any function/ }
  2895. { procedure/init/final code }
  2896. finish_lineinfo;
  2897. { debug line header }
  2898. linelist := current_asmdata.asmlists[al_dwarf_line];
  2899. new_section(linelist,sec_debug_line,'',0);
  2900. linelist.concat(tai_comment.Create(strpnew('=== header start ===')));
  2901. { size }
  2902. current_asmdata.getlabel(lbl,alt_dbgfile);
  2903. if use_64bit_headers then
  2904. linelist.concat(tai_const.create_32bit_unaligned(longint($FFFFFFFF)));
  2905. linelist.concat(tai_const.create_rel_sym(offsetreltype,
  2906. lbl,current_asmdata.DefineAsmSymbol(target_asm.labelprefix+'edebug_line0',AB_LOCAL,AT_METADATA,voidpointertype)));
  2907. linelist.concat(tai_label.create(lbl));
  2908. { version }
  2909. linelist.concat(tai_const.create_16bit_unaligned(dwarf_version));
  2910. { header length }
  2911. current_asmdata.getlabel(lbl,alt_dbgfile);
  2912. linelist.concat(tai_const.create_rel_sym(offsetreltype,
  2913. lbl,current_asmdata.DefineAsmSymbol(target_asm.labelprefix+'ehdebug_line0',AB_LOCAL,AT_METADATA,voidpointertype)));
  2914. linelist.concat(tai_label.create(lbl));
  2915. { minimum_instruction_length }
  2916. linelist.concat(tai_const.create_8bit(1));
  2917. { default_is_stmt }
  2918. linelist.concat(tai_const.create_8bit(1));
  2919. { line_base }
  2920. linelist.concat(tai_const.create_8bit(LINE_BASE));
  2921. { line_range }
  2922. { only line increase, no adress }
  2923. linelist.concat(tai_const.create_8bit(255));
  2924. { opcode_base }
  2925. linelist.concat(tai_const.create_8bit(OPCODE_BASE));
  2926. { standard_opcode_lengths }
  2927. { MWE: sigh... why adding the default lengths (and make those sizes sense with LEB encoding) }
  2928. { DW_LNS_copy }
  2929. linelist.concat(tai_const.create_8bit(0));
  2930. { DW_LNS_advance_pc }
  2931. linelist.concat(tai_const.create_8bit(1));
  2932. { DW_LNS_advance_line }
  2933. linelist.concat(tai_const.create_8bit(1));
  2934. { DW_LNS_set_file }
  2935. linelist.concat(tai_const.create_8bit(1));
  2936. { DW_LNS_set_column }
  2937. linelist.concat(tai_const.create_8bit(1));
  2938. { DW_LNS_negate_stmt }
  2939. linelist.concat(tai_const.create_8bit(0));
  2940. { DW_LNS_set_basic_block }
  2941. linelist.concat(tai_const.create_8bit(0));
  2942. { DW_LNS_const_add_pc }
  2943. linelist.concat(tai_const.create_8bit(0));
  2944. { DW_LNS_fixed_advance_pc }
  2945. linelist.concat(tai_const.create_8bit(1));
  2946. { DW_LNS_set_prologue_end }
  2947. linelist.concat(tai_const.create_8bit(0));
  2948. { DW_LNS_set_epilogue_begin }
  2949. linelist.concat(tai_const.create_8bit(0));
  2950. { DW_LNS_set_isa }
  2951. linelist.concat(tai_const.create_8bit(1));
  2952. { Create single list of filenames sorted in IndexNr }
  2953. flist:=TFPList.Create;
  2954. for n := 0 to dirlist.Count - 1 do
  2955. begin
  2956. ditem := TDirIndexItem(dirlist[n]);
  2957. for m := 0 to ditem.Files.Count - 1 do
  2958. flist.Add(ditem.Files[m]);
  2959. end;
  2960. flist.Sort(@FileListSortCompare);
  2961. { include_directories }
  2962. linelist.concat(tai_comment.Create(strpnew('include_directories')));
  2963. for n := 0 to dirlist.Count - 1 do
  2964. begin
  2965. ditem := TDirIndexItem(dirlist[n]);
  2966. if ditem.Name = '.' then
  2967. Continue;
  2968. { Write without trailing path delimiter and also don't prefix with ./ for current dir (already done while adding to dirlist }
  2969. linelist.concat(tai_string.create(ditem.Name+#0));
  2970. end;
  2971. linelist.concat(tai_const.create_8bit(0));
  2972. { file_names }
  2973. linelist.concat(tai_comment.Create(strpnew('file_names')));
  2974. for n := 0 to flist.Count - 1 do
  2975. begin
  2976. fitem := TFileIndexItem(flist[n]);
  2977. { file name }
  2978. linelist.concat(tai_string.create(fitem.Name+#0));
  2979. { directory index }
  2980. linelist.concat(tai_const.create_uleb128bit(fitem.DirIndex));
  2981. { last modification }
  2982. linelist.concat(tai_const.create_uleb128bit(0));
  2983. { file length }
  2984. linelist.concat(tai_const.create_uleb128bit(0));
  2985. end;
  2986. linelist.concat(tai_const.create_8bit(0));
  2987. { end of debug line header }
  2988. linelist.concat(tai_symbol.createname(target_asm.labelprefix+'ehdebug_line0',AT_METADATA,0,voidpointertype));
  2989. linelist.concat(tai_comment.Create(strpnew('=== header end ===')));
  2990. { add line program }
  2991. linelist.concatList(asmline);
  2992. { end of debug line table }
  2993. linelist.concat(tai_symbol.createname(target_asm.labelprefix+'edebug_line0',AT_METADATA,0,voidpointertype));
  2994. flist.free;
  2995. end;
  2996. procedure TDebugInfoDwarf.inserttypeinfo;
  2997. var
  2998. storefilepos : tfileposinfo;
  2999. lenstartlabel,arangestartlabel: tasmlabel;
  3000. i : longint;
  3001. def: tdef;
  3002. dbgname: string;
  3003. vardatatype: ttypesym;
  3004. bind: tasmsymbind;
  3005. lang: tdwarf_source_language;
  3006. begin
  3007. current_module.flags:=current_module.flags or uf_has_dwarf_debuginfo;
  3008. storefilepos:=current_filepos;
  3009. current_filepos:=current_module.mainfilepos;
  3010. if assigned(dwarflabels) then
  3011. internalerror(2015100301);
  3012. { one item per def, plus some extra space in case of nested types,
  3013. externally used types etc (it will grow further if necessary) }
  3014. i:=current_module.localsymtable.DefList.count*4;
  3015. if assigned(current_module.globalsymtable) then
  3016. inc(i,current_module.globalsymtable.DefList.count*2);
  3017. dwarflabels:=TDwarfLabHashSet.Create(i,true,false);
  3018. currabbrevnumber:=0;
  3019. defnumberlist:=TFPObjectList.create(false);
  3020. deftowritelist:=TFPObjectList.create(false);
  3021. { not exported (FK)
  3022. FILEREC
  3023. TEXTREC
  3024. }
  3025. vardatatype:=try_search_system_type('TVARDATA');
  3026. if assigned(vardatatype) then
  3027. vardatadef:=trecorddef(vardatatype.typedef);
  3028. { write start labels }
  3029. new_section(current_asmdata.asmlists[al_dwarf_info],sec_debug_info,'',0);
  3030. current_asmdata.asmlists[al_dwarf_info].concat(tai_symbol.createname(target_asm.labelprefix+'debug_info0',AT_METADATA,0,voidpointertype));
  3031. { start abbrev section }
  3032. new_section(current_asmdata.asmlists[al_dwarf_abbrev],sec_debug_abbrev,'',0);
  3033. if not(target_info.system in systems_darwin) then
  3034. begin
  3035. { start aranges section }
  3036. new_section(current_asmdata.asmlists[al_dwarf_aranges],sec_debug_aranges,'',0);
  3037. current_asmdata.getlabel(arangestartlabel,alt_dbgfile);
  3038. if use_64bit_headers then
  3039. current_asmdata.asmlists[al_dwarf_aranges].concat(tai_const.create_32bit_unaligned(longint($FFFFFFFF)));
  3040. current_asmdata.asmlists[al_dwarf_aranges].concat(tai_const.create_rel_sym(offsetreltype,
  3041. arangestartlabel,current_asmdata.DefineAsmSymbol(target_asm.labelprefix+'earanges0',AB_LOCAL,AT_METADATA,voidpointertype)));
  3042. current_asmdata.asmlists[al_dwarf_aranges].concat(tai_label.create(arangestartlabel));
  3043. current_asmdata.asmlists[al_dwarf_aranges].concat(tai_const.create_16bit_unaligned(2));
  3044. if not(tf_dwarf_relative_addresses in target_info.flags) then
  3045. current_asmdata.asmlists[al_dwarf_aranges].concat(tai_const.create_type_sym(offsetabstype,
  3046. current_asmdata.DefineAsmSymbol(target_asm.labelprefix+'debug_info0',AB_LOCAL,AT_METADATA,voidpointertype)))
  3047. else
  3048. current_asmdata.asmlists[al_dwarf_aranges].concat(tai_const.create_rel_sym(offsetreltype,
  3049. current_asmdata.DefineAsmSymbol(target_asm.labelprefix+'debug_infosection0',AB_LOCAL,AT_METADATA,voidpointertype),
  3050. current_asmdata.DefineAsmSymbol(target_asm.labelprefix+'debug_info0',AB_LOCAL,AT_METADATA,voidpointertype)));
  3051. {$ifdef i8086}
  3052. { address_size }
  3053. current_asmdata.asmlists[al_dwarf_aranges].concat(tai_const.create_8bit(4));
  3054. { segment_size }
  3055. current_asmdata.asmlists[al_dwarf_aranges].concat(tai_const.create_8bit(2));
  3056. { no alignment/padding bytes on i8086 for Open Watcom compatibility }
  3057. {$else i8086}
  3058. { address_size }
  3059. current_asmdata.asmlists[al_dwarf_aranges].concat(tai_const.create_8bit(sizeof(pint)));
  3060. { segment_size }
  3061. current_asmdata.asmlists[al_dwarf_aranges].concat(tai_const.create_8bit(0));
  3062. { alignment }
  3063. current_asmdata.asmlists[al_dwarf_aranges].concat(tai_const.create_32bit_unaligned(0));
  3064. {$endif i8086}
  3065. { start ranges section }
  3066. new_section(current_asmdata.asmlists[al_dwarf_ranges],sec_debug_ranges,'',0);
  3067. end;
  3068. { debug info header }
  3069. current_asmdata.getlabel(lenstartlabel,alt_dbgfile);
  3070. { size }
  3071. if use_64bit_headers then
  3072. current_asmdata.asmlists[al_dwarf_info].concat(tai_const.create_32bit_unaligned(longint($FFFFFFFF)));
  3073. current_asmdata.asmlists[al_dwarf_info].concat(tai_const.create_rel_sym(offsetreltype,
  3074. lenstartlabel,current_asmdata.DefineAsmSymbol(target_asm.labelprefix+'edebug_info0',AB_LOCAL,AT_METADATA,voidpointertype)));
  3075. current_asmdata.asmlists[al_dwarf_info].concat(tai_label.create(lenstartlabel));
  3076. { version }
  3077. current_asmdata.asmlists[al_dwarf_info].concat(tai_const.create_16bit_unaligned(dwarf_version));
  3078. { abbrev table (=relative from section start)}
  3079. if not(tf_dwarf_relative_addresses in target_info.flags) then
  3080. current_asmdata.asmlists[al_dwarf_info].concat(tai_const.create_type_sym(offsetabstype,
  3081. current_asmdata.DefineAsmSymbol(target_asm.labelprefix+'debug_abbrev0',AB_LOCAL,AT_METADATA,voidpointertype)))
  3082. else
  3083. current_asmdata.asmlists[al_dwarf_info].concat(tai_const.create_rel_sym(offsetreltype,
  3084. current_asmdata.DefineAsmSymbol(target_asm.labelprefix+'debug_abbrevsection0',AB_LOCAL,AT_METADATA,voidpointertype),
  3085. current_asmdata.DefineAsmSymbol(target_asm.labelprefix+'debug_abbrev0',AB_LOCAL,AT_METADATA,voidpointertype)));
  3086. { address size }
  3087. current_asmdata.asmlists[al_dwarf_info].concat(tai_const.create_8bit(sizeof(pint)));
  3088. if (ds_dwarf_cpp in current_settings.debugswitches) then
  3089. lang:=DW_LANG_C_plus_plus
  3090. else
  3091. lang:=DW_LANG_Pascal83;
  3092. { first manadatory compilation unit TAG }
  3093. append_entry(DW_TAG_compile_unit,true,[
  3094. DW_AT_name,DW_FORM_string,relative_dwarf_path(current_module.sourcefiles.get_file(1).path+current_module.sourcefiles.get_file(1).name)+#0,
  3095. DW_AT_producer,DW_FORM_string,'Free Pascal '+full_version_string+' '+date_string+#0,
  3096. DW_AT_comp_dir,DW_FORM_string,BSToSlash(FixPath(GetCurrentDir,false))+#0,
  3097. DW_AT_language,DW_FORM_data1,lang,
  3098. DW_AT_identifier_case,DW_FORM_data1,DW_ID_case_insensitive]);
  3099. {$ifdef i8086}
  3100. case current_settings.x86memorymodel of
  3101. mm_tiny,
  3102. mm_small:
  3103. append_attribute(DW_AT_WATCOM_memory_model,DW_FORM_data1,[DW_WATCOM_MEMORY_MODEL_small]);
  3104. mm_medium:
  3105. append_attribute(DW_AT_WATCOM_memory_model,DW_FORM_data1,[DW_WATCOM_MEMORY_MODEL_medium]);
  3106. mm_compact:
  3107. append_attribute(DW_AT_WATCOM_memory_model,DW_FORM_data1,[DW_WATCOM_MEMORY_MODEL_compact]);
  3108. mm_large:
  3109. append_attribute(DW_AT_WATCOM_memory_model,DW_FORM_data1,[DW_WATCOM_MEMORY_MODEL_large]);
  3110. mm_huge:
  3111. append_attribute(DW_AT_WATCOM_memory_model,DW_FORM_data1,[DW_WATCOM_MEMORY_MODEL_huge]);
  3112. else
  3113. internalerror(2018052402);
  3114. end;
  3115. {$endif i8086}
  3116. { reference to line info section }
  3117. if not(tf_dwarf_relative_addresses in target_info.flags) then
  3118. append_labelentry_dataptr_abs(DW_AT_stmt_list,current_asmdata.DefineAsmSymbol(target_asm.labelprefix+'debug_line0',AB_LOCAL,AT_METADATA,voidpointertype))
  3119. else
  3120. append_labelentry_dataptr_rel(DW_AT_stmt_list,
  3121. current_asmdata.DefineAsmSymbol(target_asm.labelprefix+'debug_linesection0',AB_LOCAL,AT_METADATA,voidpointertype),
  3122. current_asmdata.DefineAsmSymbol(target_asm.labelprefix+'debug_line0',AB_LOCAL,AT_METADATA,voidpointertype));
  3123. if (m_objectivec1 in current_settings.modeswitches) then
  3124. append_attribute(DW_AT_APPLE_major_runtime_vers,DW_FORM_data1,[1]);
  3125. dbgname:=make_mangledname('DEBUGSTART',current_module.localsymtable,'');
  3126. if (target_info.system in systems_darwin) then
  3127. begin
  3128. bind:=AB_LOCAL;
  3129. dbgname:='L'+dbgname;
  3130. end
  3131. else
  3132. bind:=AB_GLOBAL;
  3133. append_labelentry(DW_AT_low_pc,current_asmdata.DefineAsmSymbol(dbgname,bind,AT_METADATA,voidpointertype));
  3134. dbgname:=make_mangledname('DEBUGEND',current_module.localsymtable,'');
  3135. if (target_info.system in systems_darwin) then
  3136. dbgname:='L'+dbgname;
  3137. append_labelentry(DW_AT_high_pc,current_asmdata.DefineAsmSymbol(dbgname,bind,AT_METADATA,voidpointertype));
  3138. finish_entry;
  3139. { write all global/local variables. This will flag all required tdefs }
  3140. if assigned(current_module.globalsymtable) then
  3141. write_symtable_syms(current_asmdata.asmlists[al_dwarf_info],current_module.globalsymtable);
  3142. if assigned(current_module.localsymtable) then
  3143. write_symtable_syms(current_asmdata.asmlists[al_dwarf_info],current_module.localsymtable);
  3144. { write all procedures and methods. This will flag all required tdefs }
  3145. if assigned(current_module.globalsymtable) then
  3146. write_symtable_procdefs(current_asmdata.asmlists[al_dwarf_info],current_module.globalsymtable);
  3147. if assigned(current_module.localsymtable) then
  3148. write_symtable_procdefs(current_asmdata.asmlists[al_dwarf_info],current_module.localsymtable);
  3149. { reset unit type info flag }
  3150. reset_unit_type_info;
  3151. { write used types from the used units }
  3152. write_used_unit_type_info(current_asmdata.asmlists[al_dwarf_info],current_module);
  3153. { last write the types from this unit }
  3154. if assigned(current_module.globalsymtable) then
  3155. write_symtable_defs(current_asmdata.asmlists[al_dwarf_info],current_module.globalsymtable);
  3156. if assigned(current_module.localsymtable) then
  3157. write_symtable_defs(current_asmdata.asmlists[al_dwarf_info],current_module.localsymtable);
  3158. { write defs not written yet }
  3159. write_remaining_defs_to_write(current_asmdata.asmlists[al_dwarf_info]);
  3160. { close compilation unit entry }
  3161. finish_children;
  3162. { end of debug info table }
  3163. current_asmdata.asmlists[al_dwarf_info].concat(tai_symbol.createname(target_asm.labelprefix+'edebug_info0',AT_METADATA,0,voidpointertype));
  3164. { end of abbrev table }
  3165. current_asmdata.asmlists[al_dwarf_abbrev].concat(tai_const.create_8bit(0));
  3166. if not(target_info.system in systems_darwin) then
  3167. begin
  3168. { end of aranges table }
  3169. {$ifdef i8086}
  3170. { 32-bit offset }
  3171. current_asmdata.asmlists[al_dwarf_aranges].concat(tai_const.Create_32bit_unaligned(0));
  3172. { 16-bit segment }
  3173. current_asmdata.asmlists[al_dwarf_aranges].concat(tai_const.Create_16bit_unaligned(0));
  3174. { 32-bit length }
  3175. current_asmdata.asmlists[al_dwarf_aranges].concat(tai_const.Create_32bit_unaligned(0));
  3176. {$else i8086}
  3177. { offset }
  3178. current_asmdata.asmlists[al_dwarf_aranges].concat(tai_const.Create_aint(0));
  3179. { length }
  3180. current_asmdata.asmlists[al_dwarf_aranges].concat(tai_const.Create_aint(0));
  3181. {$endif i8086}
  3182. current_asmdata.asmlists[al_dwarf_aranges].concat(tai_symbol.createname(target_asm.labelprefix+'earanges0',AT_METADATA,0,voidpointertype));
  3183. end;
  3184. { reset all def debug states }
  3185. for i:=0 to defnumberlist.count-1 do
  3186. begin
  3187. def := tdef(defnumberlist[i]);
  3188. if assigned(def) then
  3189. def.dbg_state:=dbg_state_unused;
  3190. end;
  3191. dwarflabels.free;
  3192. dwarflabels:=nil;
  3193. defnumberlist.free;
  3194. defnumberlist:=nil;
  3195. deftowritelist.free;
  3196. deftowritelist:=nil;
  3197. current_filepos:=storefilepos;
  3198. end;
  3199. procedure TDebugInfoDwarf.referencesections(list:TAsmList);
  3200. var
  3201. hp : tmodule;
  3202. begin
  3203. { Reference all DEBUGINFO sections from the main .fpc section }
  3204. { to prevent eliminating them by smartlinking }
  3205. if (target_info.system in ([system_powerpc_macos]+systems_darwin)) then
  3206. exit;
  3207. new_section(list,sec_fpc,'links',0);
  3208. { include reference to all debuginfo sections of used units }
  3209. hp:=tmodule(loaded_units.first);
  3210. while assigned(hp) do
  3211. begin
  3212. If ((hp.flags and uf_has_dwarf_debuginfo)=uf_has_dwarf_debuginfo) and not assigned(hp.package) then
  3213. begin
  3214. list.concat(Tai_const.Createname(make_mangledname('DEBUGSTART',hp.localsymtable,''),0));
  3215. list.concat(Tai_const.Createname(make_mangledname('DEBUGEND',hp.localsymtable,''),0));
  3216. end;
  3217. hp:=tmodule(hp.next);
  3218. end;
  3219. end;
  3220. function TDebugInfoDwarf.symname(sym: tsym; manglename: boolean): String;
  3221. begin
  3222. if (sym.typ=paravarsym) and
  3223. (vo_is_self in tparavarsym(sym).varoptions) then
  3224. { We use 'this' for regular methods because that's what gdb triggers
  3225. on to automatically search fields. Don't do this for class methods,
  3226. because search class fields is not supported, and gdb 7.0+ fails
  3227. in this case because "this" is not a record in that case (it's a
  3228. pointer to a vmt) }
  3229. if not is_objc_class_or_protocol(tdef(sym.owner.defowner.owner.defowner)) and
  3230. not(po_classmethod in tabstractprocdef(sym.owner.defowner).procoptions) then
  3231. result:='this'
  3232. else
  3233. result:='self'
  3234. else if (sym.typ=typesym) and
  3235. is_objc_class_or_protocol(ttypesym(sym).typedef) then
  3236. result:=tobjectdef(ttypesym(sym).typedef).objextname^
  3237. else if (ds_dwarf_method_class_prefix in current_settings.debugswitches) and
  3238. (sym.typ=procsym) and
  3239. (tprocsym(sym).owner.symtabletype in [objectsymtable,recordsymtable]) then
  3240. begin
  3241. result:=tprocsym(sym).owner.name^+'__';
  3242. if manglename then
  3243. result := result + sym.name
  3244. else
  3245. result := result + symdebugname(sym);
  3246. end
  3247. else
  3248. begin
  3249. if manglename then
  3250. result := sym.name
  3251. else
  3252. result := symdebugname(sym);
  3253. end;
  3254. end;
  3255. procedure TDebugInfoDwarf.append_visibility(vis: tvisibility);
  3256. begin
  3257. case vis of
  3258. vis_private,
  3259. vis_strictprivate:
  3260. append_attribute(DW_AT_accessibility,DW_FORM_data1,[ord(DW_ACCESS_private)]);
  3261. vis_protected,
  3262. vis_strictprotected:
  3263. append_attribute(DW_AT_accessibility,DW_FORM_data1,[ord(DW_ACCESS_protected)]);
  3264. vis_public:
  3265. { default };
  3266. end;
  3267. end;
  3268. procedure TDebugInfoDwarf.insertlineinfo(list:TAsmList);
  3269. var
  3270. currfileinfo,
  3271. lastfileinfo : tfileposinfo;
  3272. currfuncname : pshortstring;
  3273. currstatement: boolean;
  3274. currsectype : TAsmSectiontype;
  3275. hp, hpend : tai;
  3276. infile : tinputfile;
  3277. prevcolumn,
  3278. diffline,
  3279. prevline,
  3280. prevfileidx,
  3281. currfileidx,
  3282. nolineinfolevel : Integer;
  3283. prevlabel,
  3284. currlabel : tasmlabel;
  3285. begin
  3286. {$ifdef OMFOBJSUPPORT}
  3287. if ds_dwarf_omf_linnum in current_settings.debugswitches then
  3288. dbgcodeview.InsertLineInfo_OMF_LINNUM_MsLink(list);
  3289. {$endif OMFOBJSUPPORT}
  3290. { this function will always terminate the lineinfo block }
  3291. generated_lineinfo := true;
  3292. { if this unit only contains code without debug info (implicit init
  3293. or final etc), make sure the file table contains at least one entry
  3294. (the main source of the unit), because normally this table gets
  3295. populated via calls to get_file_index and that won't happen in this
  3296. case }
  3297. get_file_index(current_module.sourcefiles.get_file(1));
  3298. FillChar(lastfileinfo,sizeof(lastfileinfo),0);
  3299. currfuncname:=nil;
  3300. currsectype:=sec_code;
  3301. hp:=Tai(list.first);
  3302. currstatement:=true;
  3303. prevcolumn := 0;
  3304. prevline := 1;
  3305. prevfileidx := 1;
  3306. prevlabel := nil;
  3307. nolineinfolevel:=0;
  3308. while assigned(hp) do
  3309. begin
  3310. case hp.typ of
  3311. ait_section :
  3312. currsectype:=tai_section(hp).sectype;
  3313. ait_function_name :
  3314. begin
  3315. currfuncname:=tai_function_name(hp).funcname;
  3316. asmline.concat(tai_comment.Create(strpnew('function: '+currfuncname^)));
  3317. end;
  3318. ait_force_line :
  3319. begin
  3320. lastfileinfo.line:=-1;
  3321. end;
  3322. ait_marker :
  3323. begin
  3324. case tai_marker(hp).kind of
  3325. mark_NoLineInfoStart:
  3326. inc(nolineinfolevel);
  3327. mark_NoLineInfoEnd:
  3328. dec(nolineinfolevel);
  3329. end;
  3330. end;
  3331. end;
  3332. if (currsectype=sec_code) and
  3333. (hp.typ=ait_instruction) then
  3334. begin
  3335. currfileinfo:=tailineinfo(hp).fileinfo;
  3336. { file changed ? (must be before line info) }
  3337. if (currfileinfo.fileindex<>0) and
  3338. ((lastfileinfo.fileindex<>currfileinfo.fileindex) or
  3339. (lastfileinfo.moduleindex<>currfileinfo.moduleindex)) then
  3340. begin
  3341. infile:=get_module(currfileinfo.moduleindex).sourcefiles.get_file(currfileinfo.fileindex);
  3342. if assigned(infile) then
  3343. begin
  3344. currfileidx := get_file_index(infile);
  3345. if prevfileidx <> currfileidx then
  3346. begin
  3347. list.insertbefore(tai_comment.Create(strpnew('path: '+infile.path)), hp);
  3348. list.insertbefore(tai_comment.Create(strpnew('file: '+infile.name)), hp);
  3349. list.insertbefore(tai_comment.Create(strpnew('indx: '+tostr(currfileidx))), hp);
  3350. { set file }
  3351. asmline.concat(tai_comment.Create(strpnew('path: '+infile.path)));
  3352. asmline.concat(tai_comment.Create(strpnew('file: '+infile.name)));
  3353. asmline.concat(tai_const.create_8bit(DW_LNS_set_file));
  3354. asmline.concat(tai_const.create_uleb128bit(currfileidx));
  3355. prevfileidx := currfileidx;
  3356. end;
  3357. { force new line info }
  3358. lastfileinfo.line:=-1;
  3359. end;
  3360. end;
  3361. { Set the line-nr to 0 if the code does not corresponds to a particular line }
  3362. if nolineinfolevel>0 then
  3363. currfileinfo.line := 0;
  3364. { line changed ? }
  3365. if (lastfileinfo.line<>currfileinfo.line) and ((currfileinfo.line<>0) or (nolineinfolevel>0)) then
  3366. begin
  3367. { set address }
  3368. current_asmdata.getlabel(currlabel, alt_dbgline);
  3369. list.insertbefore(tai_label.create(currlabel), hp);
  3370. asmline.concat(tai_comment.Create(strpnew('['+tostr(currfileinfo.line)+':'+tostr(currfileinfo.column)+']')));
  3371. if (prevlabel = nil) or
  3372. { darwin's assembler cannot create an uleb128 of the difference }
  3373. { between to symbols }
  3374. { same goes for Solaris native assembler }
  3375. (target_info.system in systems_darwin) or
  3376. (target_asm.id=as_solaris_as) then
  3377. begin
  3378. asmline.concat(tai_const.create_8bit(DW_LNS_extended_op));
  3379. asmline.concat(tai_const.create_uleb128bit(1+sizeof(pint)));
  3380. asmline.concat(tai_const.create_8bit(DW_LNE_set_address));
  3381. asmline.concat(tai_const.create_type_sym(aitconst_ptr_unaligned,currlabel));
  3382. {$ifdef i8086}
  3383. { on i8086 we also emit an Open Watcom-specific 'set segment' op }
  3384. asmline.concat(tai_const.create_8bit(DW_LNS_extended_op));
  3385. asmline.concat(tai_const.create_uleb128bit(3));
  3386. asmline.concat(tai_const.create_8bit(DW_LNE_set_segment));
  3387. asmline.concat(tai_const.Create_seg_name(currlabel.Name));
  3388. {$endif i8086}
  3389. end
  3390. else
  3391. begin
  3392. asmline.concat(tai_const.create_8bit(DW_LNS_advance_pc));
  3393. asmline.concat(tai_const.create_rel_sym(aitconst_uleb128bit, prevlabel, currlabel));
  3394. end;
  3395. prevlabel := currlabel;
  3396. { set column }
  3397. if prevcolumn <> currfileinfo.column then
  3398. begin
  3399. asmline.concat(tai_const.create_8bit(DW_LNS_set_column));
  3400. asmline.concat(tai_const.create_uleb128bit(currfileinfo.column));
  3401. prevcolumn := currfileinfo.column;
  3402. end;
  3403. { set statement }
  3404. if (currfileinfo.line=0) and currstatement then
  3405. begin
  3406. currstatement := false;
  3407. asmline.concat(tai_const.create_8bit(DW_LNS_negate_stmt));
  3408. end;
  3409. if not currstatement and (currfileinfo.line>0) then
  3410. begin
  3411. currstatement := true;
  3412. asmline.concat(tai_const.create_8bit(DW_LNS_negate_stmt));
  3413. end;
  3414. { set line }
  3415. diffline := currfileinfo.line - prevline;
  3416. if (diffline >= LINE_BASE) and (OPCODE_BASE + diffline - LINE_BASE <= 255) then
  3417. begin
  3418. { use special opcode, this also adds a row }
  3419. asmline.concat(tai_const.create_8bit(OPCODE_BASE + diffline - LINE_BASE));
  3420. end
  3421. else
  3422. begin
  3423. if diffline <> 0 then
  3424. begin
  3425. asmline.concat(tai_const.create_8bit(DW_LNS_advance_line));
  3426. asmline.concat(tai_const.create_sleb128bit(diffline));
  3427. end;
  3428. { no row added yet, do it manually }
  3429. asmline.concat(tai_const.create_8bit(DW_LNS_copy));
  3430. end;
  3431. prevline := currfileinfo.line;
  3432. end;
  3433. lastfileinfo:=currfileinfo;
  3434. end;
  3435. hpend:=hp;
  3436. hp:=tai(hp.next);
  3437. end;
  3438. if assigned(hpend) then
  3439. begin
  3440. { set address for end (see appendix 3 of dwarf 2 specs) }
  3441. current_asmdata.getlabel(currlabel, alt_dbgline);
  3442. list.insertafter(tai_label.create(currlabel), hpend);
  3443. asmline.concat(tai_const.create_8bit(DW_LNS_extended_op));
  3444. asmline.concat(tai_const.create_uleb128bit(1+sizeof(pint)));
  3445. asmline.concat(tai_const.create_8bit(DW_LNE_set_address));
  3446. asmline.concat(tai_const.create_type_sym(aitconst_ptr_unaligned,currlabel));
  3447. end;
  3448. { end sequence }
  3449. asmline.concat(tai_const.Create_8bit(DW_LNS_extended_op));
  3450. asmline.concat(tai_const.Create_8bit(1));
  3451. asmline.concat(tai_const.Create_8bit(DW_LNE_end_sequence));
  3452. asmline.concat(tai_comment.Create(strpnew('###################')));
  3453. end;
  3454. procedure TDebugInfoDwarf.finish_lineinfo;
  3455. var
  3456. infile: tinputfile;
  3457. begin
  3458. { only needed if no line info at all has been generated }
  3459. if generated_lineinfo then
  3460. begin
  3461. { reset for next module compilation }
  3462. generated_lineinfo:=false;
  3463. exit;
  3464. end;
  3465. { at least the Darwin linker is annoyed if you do not }
  3466. { finish the lineinfo section, or if it doesn't }
  3467. { contain at least one file name and set_address }
  3468. infile:=current_module.sourcefiles.get_file(1);
  3469. if not assigned(infile) then
  3470. internalerror(2006020211);
  3471. asmline.concat(tai_const.create_8bit(DW_LNS_set_file));
  3472. asmline.concat(tai_const.create_uleb128bit(get_file_index(infile)));
  3473. asmline.concat(tai_const.create_8bit(DW_LNS_extended_op));
  3474. asmline.concat(tai_const.create_uleb128bit(1+sizeof(pint)));
  3475. asmline.concat(tai_const.create_8bit(DW_LNE_set_address));
  3476. asmline.concat(tai_const.create_type_sym(aitconst_ptr_unaligned,nil));
  3477. asmline.concat(tai_const.create_8bit(DW_LNS_extended_op));
  3478. asmline.concat(tai_const.Create_8bit(1));
  3479. asmline.concat(tai_const.Create_8bit(DW_LNE_end_sequence));
  3480. asmline.concat(tai_comment.Create(strpnew('###################')));
  3481. end;
  3482. {****************************************************************************
  3483. TDebugInfoDwarf2
  3484. ****************************************************************************}
  3485. procedure TDebugInfoDwarf2.appenddef_file(list:TAsmList;def: tfiledef);
  3486. begin
  3487. { gdb 6.4 doesn't support files so far so we use some fake recorddef
  3488. file recs. are less than 1k so using data2 is enough }
  3489. if assigned(def.typesym) then
  3490. append_entry(DW_TAG_structure_type,false,[
  3491. DW_AT_name,DW_FORM_string,symname(def.typesym, false)+#0,
  3492. DW_AT_byte_size,DW_FORM_udata,def.size
  3493. ])
  3494. else
  3495. append_entry(DW_TAG_structure_type,false,[
  3496. DW_AT_byte_size,DW_FORM_udata,def.size
  3497. ]);
  3498. finish_entry;
  3499. end;
  3500. procedure TDebugInfoDwarf2.appenddef_formal(list:TAsmList;def: tformaldef);
  3501. begin
  3502. { gdb 6.4 doesn't support DW_TAG_unspecified_type so we
  3503. replace it with a unsigned type with size 0 (FK)
  3504. }
  3505. append_entry(DW_TAG_base_type,false,[
  3506. DW_AT_name,DW_FORM_string,'FormalDef'#0,
  3507. DW_AT_encoding,DW_FORM_data1,DW_ATE_unsigned,
  3508. DW_AT_byte_size,DW_FORM_data1,0
  3509. ]);
  3510. finish_entry;
  3511. end;
  3512. procedure TDebugInfoDwarf2.append_object_struct(def: tobjectdef; const createlabel: boolean; const objectname: PShortString);
  3513. begin
  3514. if createlabel then
  3515. begin
  3516. if not(tf_dwarf_only_local_labels in target_info.flags) then
  3517. current_asmdata.asmlists[al_dwarf_info].concat(tai_symbol.create_global(def_dwarf_class_struct_lab(def),0))
  3518. else
  3519. current_asmdata.asmlists[al_dwarf_info].concat(tai_symbol.create(def_dwarf_class_struct_lab(def),0));
  3520. end;
  3521. if assigned(objectname) then
  3522. append_entry(DW_TAG_class_type,true,[
  3523. DW_AT_name,DW_FORM_string,objectname^+#0,
  3524. DW_AT_byte_size,DW_FORM_udata,tobjectsymtable(def.symtable).datasize
  3525. ])
  3526. else
  3527. append_entry(DW_TAG_class_type,true,[
  3528. DW_AT_byte_size,DW_FORM_udata,tobjectsymtable(def.symtable).datasize
  3529. ]);
  3530. { Apple-specific tag that identifies it as an Objective-C class }
  3531. if (def.objecttype=odt_objcclass) then
  3532. append_attribute(DW_AT_APPLE_runtime_class,DW_FORM_data1,[DW_LANG_ObjC]);
  3533. finish_entry;
  3534. if assigned(def.childof) then
  3535. begin
  3536. append_entry(DW_TAG_inheritance,false,[
  3537. DW_AT_accessibility,DW_FORM_data1,DW_ACCESS_public,
  3538. DW_AT_data_member_location,DW_FORM_block1,1+lengthuleb128(0)
  3539. ]);
  3540. current_asmdata.asmlists[al_dwarf_info].concat(tai_const.create_8bit(ord(DW_OP_plus_uconst)));
  3541. current_asmdata.asmlists[al_dwarf_info].concat(tai_const.create_uleb128bit(0));
  3542. if (def.childof.dbg_state=dbg_state_unused) then
  3543. def.childof.dbg_state:=dbg_state_used;
  3544. if is_implicit_pointer_object_type(def) then
  3545. append_labelentry_ref(DW_AT_type,def_dwarf_class_struct_lab(def.childof))
  3546. else
  3547. append_labelentry_ref(DW_AT_type,def_dwarf_lab(def.childof));
  3548. finish_entry;
  3549. end;
  3550. if (oo_has_vmt in def.objectoptions) and
  3551. (not assigned(def.childof) or
  3552. not(oo_has_vmt in def.childof.objectoptions)) then
  3553. begin
  3554. { vmt field }
  3555. append_entry(DW_TAG_member,false,[
  3556. DW_AT_artificial,DW_FORM_flag,true,
  3557. DW_AT_name,DW_FORM_string,'_vptr$'+def.objname^+#0,
  3558. DW_AT_data_member_location,DW_FORM_block1,1+lengthuleb128(def.vmt_offset)
  3559. ]);
  3560. current_asmdata.asmlists[al_dwarf_info].concat(tai_const.create_8bit(ord(DW_OP_plus_uconst)));
  3561. current_asmdata.asmlists[al_dwarf_info].concat(tai_const.create_uleb128bit(def.vmt_offset));
  3562. { should be changed into a pointer to a function returning an }
  3563. { int and with TAG_unspecified_parameters }
  3564. if (voidpointertype.dbg_state=dbg_state_unused) then
  3565. voidpointertype.dbg_state:=dbg_state_used;
  3566. append_labelentry_ref(DW_AT_type,def_dwarf_lab(voidpointertype));
  3567. finish_entry;
  3568. end;
  3569. def.symtable.symList.ForEachCall(@enum_membersyms_callback,nil);
  3570. { Write the methods in the scope of the class/object, except for Objective-C. }
  3571. if is_objc_class_or_protocol(def) then
  3572. finish_children;
  3573. { don't write procdefs of externally defined classes, gcc doesn't
  3574. either (info is probably gotten from ObjC runtime) }
  3575. if not(oo_is_external in def.objectoptions) then
  3576. write_symtable_procdefs(current_asmdata.asmlists[al_dwarf_info],def.symtable);
  3577. if not is_objc_class_or_protocol(def) then
  3578. finish_children;
  3579. end;
  3580. procedure TDebugInfoDwarf2.appenddef_object(list:TAsmList;def: tobjectdef);
  3581. begin
  3582. case def.objecttype of
  3583. odt_cppclass,
  3584. odt_object:
  3585. append_object_struct(def,false,def.objname);
  3586. odt_interfacecom,
  3587. odt_interfacecorba,
  3588. odt_dispinterface,
  3589. odt_helper,
  3590. odt_class:
  3591. begin
  3592. { implicit pointer }
  3593. append_entry(DW_TAG_pointer_type,false,[]);
  3594. append_labelentry_ref(DW_AT_type,def_dwarf_class_struct_lab(def));
  3595. finish_entry;
  3596. append_object_struct(def,true,def.objname);
  3597. end;
  3598. odt_objcclass:
  3599. { Objective-C class: same as regular class, except for
  3600. a) Apple-specific tag that identifies it as an Objective-C class
  3601. b) use extname^ instead of objname
  3602. }
  3603. append_object_struct(def,true,def.objextname);
  3604. odt_objcprotocol:
  3605. begin
  3606. append_entry(DW_TAG_pointer_type,false,[]);
  3607. append_labelentry_ref(DW_AT_type,def_dwarf_lab(voidpointertype));
  3608. finish_entry;
  3609. end;
  3610. else
  3611. internalerror(200602041);
  3612. end;
  3613. end;
  3614. procedure TDebugInfoDwarf2.appenddef_set_intern(list:TAsmList;def: tsetdef; force_tag_set: boolean);
  3615. var
  3616. lab: tasmlabel;
  3617. begin
  3618. if force_tag_set or
  3619. (ds_dwarf_sets in current_settings.debugswitches) then
  3620. begin
  3621. { current (20070704 -- patch was committed on 20060513) gdb cvs supports set types }
  3622. if assigned(def.typesym) then
  3623. append_entry(DW_TAG_set_type,false,[
  3624. DW_AT_name,DW_FORM_string,symname(def.typesym, false)+#0,
  3625. DW_AT_byte_size,DW_FORM_data2,def.size
  3626. ])
  3627. else
  3628. append_entry(DW_TAG_set_type,false,[
  3629. DW_AT_byte_size,DW_FORM_data2,def.size
  3630. ]);
  3631. if assigned(def.elementdef) then
  3632. begin
  3633. if not(tf_dwarf_only_local_labels in target_info.flags) then
  3634. current_asmdata.getglobaldatalabel(lab)
  3635. else
  3636. current_asmdata.getaddrlabel(lab);
  3637. append_labelentry_ref(DW_AT_type,lab);
  3638. finish_entry;
  3639. if lab.bind=AB_GLOBAL then
  3640. current_asmdata.asmlists[al_dwarf_info].concat(tai_symbol.create_global(lab,0))
  3641. else
  3642. current_asmdata.asmlists[al_dwarf_info].concat(tai_symbol.create(lab,0));
  3643. { Sets of e.g. [1..5] are actually stored as a set of [0..7],
  3644. so write the exact boundaries of the set here. Let's hope no
  3645. debugger ever rejects this because this "subrange" type can
  3646. actually have a larger range than the original one. }
  3647. append_entry(DW_TAG_subrange_type,false,[
  3648. DW_AT_lower_bound,DW_FORM_sdata,def.setbase,
  3649. DW_AT_upper_bound,DW_FORM_sdata,get_max_value(def.elementdef).svalue
  3650. ]);
  3651. append_labelentry_ref(DW_AT_type,def_dwarf_lab(def.elementdef))
  3652. end
  3653. end
  3654. else
  3655. begin
  3656. { gdb versions which don't support sets refuse to load the debug }
  3657. { info of modules that contain set tags }
  3658. if assigned(def.typesym) then
  3659. append_entry(DW_TAG_base_type,false,[
  3660. DW_AT_name,DW_FORM_string,symname(def.typesym, false)+#0,
  3661. DW_AT_encoding,DW_FORM_data1,DW_ATE_unsigned,
  3662. DW_AT_byte_size,DW_FORM_data2,def.size
  3663. ])
  3664. else
  3665. append_entry(DW_TAG_base_type,false,[
  3666. DW_AT_encoding,DW_FORM_data1,DW_ATE_unsigned,
  3667. DW_AT_byte_size,DW_FORM_data2,def.size
  3668. ]);
  3669. end;
  3670. finish_entry;
  3671. end;
  3672. procedure TDebugInfoDwarf2.appenddef_set(list:TAsmList;def: tsetdef);
  3673. begin
  3674. appenddef_set_intern(list,def,false);
  3675. end;
  3676. procedure TDebugInfoDwarf2.appenddef_undefined(list:TAsmList;def: tundefineddef);
  3677. begin
  3678. { gdb 6.4 doesn't support DW_TAG_unspecified_type so we
  3679. replace it with a unsigned type with size 0 (FK)
  3680. }
  3681. append_entry(DW_TAG_base_type,false,[
  3682. DW_AT_name,DW_FORM_string,'FormalDef'#0,
  3683. DW_AT_encoding,DW_FORM_data1,DW_ATE_unsigned,
  3684. DW_AT_byte_size,DW_FORM_data1,0
  3685. ]);
  3686. finish_entry;
  3687. end;
  3688. procedure TDebugInfoDwarf2.appenddef_variant(list:TAsmList;def: tvariantdef);
  3689. begin
  3690. { variants aren't known to dwarf2 but writting tvardata should be enough }
  3691. if assigned(vardatadef) then
  3692. appenddef_record_named(list,trecorddef(vardatadef),'Variant');
  3693. end;
  3694. function TDebugInfoDwarf2.dwarf_version: Word;
  3695. begin
  3696. Result:=2;
  3697. end;
  3698. {****************************************************************************
  3699. TDebugInfoDwarf3
  3700. ****************************************************************************}
  3701. procedure TDebugInfoDwarf3.append_labelentry_addr_ref(attr : tdwarf_attribute;sym : tasmsymbol);
  3702. begin
  3703. AddConstToAbbrev(ord(DW_FORM_ref_addr));
  3704. { Since Dwarf 3 the length of a DW_FORM_ref_addr entry is not dependent on the pointer size of the
  3705. target platform, but on the used Dwarf-format (32 bit or 64 bit) for the current compilation section. }
  3706. if use_64bit_headers then
  3707. current_asmdata.asmlists[al_dwarf_info].concat(tai_const.Create_type_sym(aitconst_64bit_unaligned,sym))
  3708. else
  3709. current_asmdata.asmlists[al_dwarf_info].concat(tai_const.Create_type_sym(aitconst_32bit_unaligned,sym));
  3710. end;
  3711. procedure tdebuginfodwarf3.appenddef_array(list: tasmlist; def: tarraydef);
  3712. begin
  3713. if not is_dynamic_array(def) then
  3714. begin
  3715. inherited appenddef_array(list,def);
  3716. exit;
  3717. end;
  3718. if assigned(def.typesym) then
  3719. append_entry(DW_TAG_array_type,true,[
  3720. DW_AT_name,DW_FORM_string,symname(def.typesym, false)+#0,
  3721. DW_AT_data_location,DW_FORM_block1,2
  3722. ])
  3723. else
  3724. append_entry(DW_TAG_array_type,true,[
  3725. DW_AT_data_location,DW_FORM_block1,2
  3726. ]);
  3727. current_asmdata.asmlists[al_dwarf_info].concat(tai_const.create_8bit(ord(DW_OP_push_object_address)));
  3728. current_asmdata.asmlists[al_dwarf_info].concat(tai_const.create_8bit(ord(DW_OP_deref)));
  3729. append_labelentry_ref(DW_AT_type,def_dwarf_lab(def.elementdef));
  3730. finish_entry;
  3731. { to simplify things, we don't write a multidimensional array here }
  3732. append_entry(DW_TAG_subrange_type,false,[
  3733. DW_AT_byte_stride,DW_FORM_udata,def.elesize,
  3734. DW_AT_lower_bound,DW_FORM_udata,0,
  3735. DW_AT_upper_bound,DW_FORM_block1,14
  3736. ]);
  3737. current_asmdata.asmlists[al_dwarf_info].concat(tai_const.create_8bit(ord(DW_OP_push_object_address)));
  3738. current_asmdata.asmlists[al_dwarf_info].concat(tai_const.create_8bit(ord(DW_OP_deref)));
  3739. current_asmdata.asmlists[al_dwarf_info].concat(tai_const.create_8bit(ord(DW_OP_dup)));
  3740. { pointer = nil? }
  3741. current_asmdata.asmlists[al_dwarf_info].concat(tai_const.create_8bit(ord(DW_OP_bra)));
  3742. current_asmdata.asmlists[al_dwarf_info].concat(tai_const.create_16bit_unaligned(5));
  3743. { yes -> length = 0 }
  3744. current_asmdata.asmlists[al_dwarf_info].concat(tai_const.create_8bit(ord(DW_OP_const1s)));
  3745. current_asmdata.asmlists[al_dwarf_info].concat(tai_const.create_8bit(byte(-1)));
  3746. current_asmdata.asmlists[al_dwarf_info].concat(tai_const.create_8bit(ord(DW_OP_skip)));
  3747. current_asmdata.asmlists[al_dwarf_info].concat(tai_const.create_16bit_unaligned(3));
  3748. { no -> load length }
  3749. current_asmdata.asmlists[al_dwarf_info].concat(tai_const.create_8bit(ord(DW_OP_lit0)+sizeof(ptrint)));
  3750. current_asmdata.asmlists[al_dwarf_info].concat(tai_const.create_8bit(ord(DW_OP_minus)));
  3751. current_asmdata.asmlists[al_dwarf_info].concat(tai_const.create_8bit(ord(DW_OP_deref)));
  3752. append_labelentry_ref(DW_AT_type,def_dwarf_lab(def.rangedef));
  3753. finish_entry;
  3754. finish_children;
  3755. end;
  3756. procedure tdebuginfodwarf3.appenddef_string(list: tasmlist; def: tstringdef);
  3757. procedure addstringdef(const name: shortstring; chardef: tdef; deref: boolean; lensize: aint);
  3758. var
  3759. upperopcodes: longint;
  3760. begin
  3761. { deref=true -> ansi/unicde/widestring; deref = false -> short/longstring }
  3762. if assigned(def.typesym) then
  3763. append_entry(DW_TAG_array_type,true,[
  3764. DW_AT_name,DW_FORM_string,name+#0,
  3765. DW_AT_data_location,DW_FORM_block1,2+ord(not(deref))
  3766. ])
  3767. else
  3768. append_entry(DW_TAG_array_type,true,[
  3769. DW_AT_data_location,DW_FORM_block1,2+ord(not(deref))
  3770. ]);
  3771. { in all cases we start with the address of the string }
  3772. current_asmdata.asmlists[al_dwarf_info].concat(tai_const.create_8bit(ord(DW_OP_push_object_address)));
  3773. if deref then
  3774. begin
  3775. { ansi/unicode/widestring -> dereference the address of the string, and then
  3776. we point to address of the string
  3777. }
  3778. current_asmdata.asmlists[al_dwarf_info].concat(tai_const.create_8bit(ord(DW_OP_deref)));
  3779. end
  3780. else
  3781. begin
  3782. { shortstring characters begin at string[1], so add one to the string's address }
  3783. current_asmdata.asmlists[al_dwarf_info].concat(tai_const.create_8bit(ord(DW_OP_lit0)+lensize));
  3784. current_asmdata.asmlists[al_dwarf_info].concat(tai_const.create_8bit(ord(DW_OP_plus)))
  3785. end;
  3786. { reference to the element type of the string }
  3787. append_labelentry_ref(DW_AT_type,def_dwarf_lab(chardef));
  3788. finish_entry;
  3789. { now the information about the length of the string }
  3790. if deref then
  3791. begin
  3792. if (chardef.size=1) then
  3793. upperopcodes:=13
  3794. else
  3795. upperopcodes:=15;
  3796. { lower bound is always 1, upper bound (length) needs to be calculated }
  3797. append_entry(DW_TAG_subrange_type,false,[
  3798. DW_AT_lower_bound,DW_FORM_udata,1,
  3799. DW_AT_upper_bound,DW_FORM_block1,upperopcodes
  3800. ]);
  3801. { high(string) is stored sizeof(ptrint) bytes before the string data }
  3802. current_asmdata.asmlists[al_dwarf_info].concat(tai_const.create_8bit(ord(DW_OP_push_object_address)));
  3803. current_asmdata.asmlists[al_dwarf_info].concat(tai_const.create_8bit(ord(DW_OP_deref)));
  3804. current_asmdata.asmlists[al_dwarf_info].concat(tai_const.create_8bit(ord(DW_OP_dup)));
  3805. { pointer = nil? }
  3806. current_asmdata.asmlists[al_dwarf_info].concat(tai_const.create_8bit(ord(DW_OP_bra)));
  3807. current_asmdata.asmlists[al_dwarf_info].concat(tai_const.create_16bit_unaligned(4));
  3808. { yes -> length = 0 }
  3809. current_asmdata.asmlists[al_dwarf_info].concat(tai_const.create_8bit(ord(DW_OP_lit0)));
  3810. current_asmdata.asmlists[al_dwarf_info].concat(tai_const.create_8bit(ord(DW_OP_skip)));
  3811. current_asmdata.asmlists[al_dwarf_info].concat(tai_const.create_16bit_unaligned(3));
  3812. { no -> load length }
  3813. current_asmdata.asmlists[al_dwarf_info].concat(tai_const.create_8bit(ord(DW_OP_lit0)+sizeof(ptrint)));
  3814. current_asmdata.asmlists[al_dwarf_info].concat(tai_const.create_8bit(ord(DW_OP_minus)));
  3815. current_asmdata.asmlists[al_dwarf_info].concat(tai_const.create_8bit(ord(DW_OP_deref)));
  3816. { for widestrings, the length is specified in bytes, so divide by two }
  3817. if (upperopcodes=15) then
  3818. begin
  3819. current_asmdata.asmlists[al_dwarf_info].concat(tai_const.create_8bit(ord(DW_OP_lit1)));
  3820. current_asmdata.asmlists[al_dwarf_info].concat(tai_const.create_8bit(ord(DW_OP_shr)));
  3821. end;
  3822. end
  3823. else
  3824. begin
  3825. append_entry(DW_TAG_subrange_type,false,[
  3826. DW_AT_lower_bound,DW_FORM_udata,1,
  3827. DW_AT_upper_bound,DW_FORM_block1,3
  3828. ]);
  3829. { for shortstrings, the length is the first byte of the string }
  3830. current_asmdata.asmlists[al_dwarf_info].concat(tai_const.create_8bit(ord(DW_OP_push_object_address)));
  3831. { load 1 byte }
  3832. current_asmdata.asmlists[al_dwarf_info].concat(tai_const.create_8bit(ord(DW_OP_deref_size)));
  3833. current_asmdata.asmlists[al_dwarf_info].concat(tai_const.create_8bit(lensize));
  3834. end;
  3835. finish_entry;
  3836. finish_children;
  3837. end;
  3838. begin
  3839. case def.stringtype of
  3840. st_shortstring:
  3841. begin
  3842. addstringdef('ShortString',cansichartype,false,1);
  3843. end;
  3844. st_longstring:
  3845. begin
  3846. {$ifdef cpu64bitaddr}
  3847. addstringdef('LongString',cansichartype,false,8);
  3848. {$else cpu64bitaddr}
  3849. addstringdef('LongString',cansichartype,false,4);
  3850. {$endif cpu64bitaddr}
  3851. end;
  3852. st_ansistring:
  3853. begin
  3854. addstringdef('AnsiString',cansichartype,true,-1);
  3855. end;
  3856. st_unicodestring:
  3857. begin
  3858. addstringdef('UnicodeString',cwidechartype,true,-1);
  3859. end;
  3860. st_widestring:
  3861. begin
  3862. if not(tf_winlikewidestring in target_info.flags) then
  3863. addstringdef('WideString',cwidechartype,true,-1)
  3864. else
  3865. begin
  3866. { looks like a pwidechar (no idea about length location) }
  3867. append_entry(DW_TAG_pointer_type,false,[]);
  3868. append_labelentry_ref(DW_AT_type,def_dwarf_lab(cwidechartype));
  3869. finish_entry;
  3870. end;
  3871. end;
  3872. end;
  3873. end;
  3874. procedure TDebugInfoDwarf3.appenddef_file(list:TAsmList;def: tfiledef);
  3875. begin
  3876. if assigned(def.typesym) then
  3877. append_entry(DW_TAG_file_type,false,[
  3878. DW_AT_name,DW_FORM_string,symname(def.typesym, false)+#0,
  3879. DW_AT_byte_size,DW_FORM_data2,def.size
  3880. ])
  3881. else
  3882. append_entry(DW_TAG_file_type,false,[
  3883. DW_AT_byte_size,DW_FORM_data2,def.size
  3884. ]);
  3885. if tfiledef(def).filetyp=ft_typed then
  3886. append_labelentry_ref(DW_AT_type,def_dwarf_lab(tfiledef(def).typedfiledef));
  3887. finish_entry;
  3888. end;
  3889. procedure TDebugInfoDwarf3.appenddef_formal(list:TAsmList;def: tformaldef);
  3890. begin
  3891. if (ds_dwarf_cpp in current_settings.debugswitches) then
  3892. begin
  3893. // Do not use DW_TAG_unspecified_type for C++ simulation.
  3894. // At least LLDB 3.9.0 crashes in such case.
  3895. // Call the inherited DWARF 2 implementation, which works fine.
  3896. inherited;
  3897. exit;
  3898. end;
  3899. append_entry(DW_TAG_unspecified_type,false,[]);
  3900. finish_entry;
  3901. end;
  3902. procedure TDebugInfoDwarf3.appenddef_object(list:TAsmList;def: tobjectdef);
  3903. procedure dostruct(tag: tdwarf_tag);
  3904. begin
  3905. if assigned(def.objname) then
  3906. append_entry(tag,true,[
  3907. DW_AT_name,DW_FORM_string,def.objrealname^+#0
  3908. ])
  3909. else
  3910. append_entry(DW_TAG_structure_type,true,[]);
  3911. append_attribute(DW_AT_byte_size,DW_FORM_udata,[tobjectsymtable(def.symtable).datasize]);
  3912. // The pointer to the class-structure is hidden. The debug-information
  3913. // does not contain an implicit pointer, but the data-adress is dereferenced here.
  3914. // In case of a nil-pointer, report the class as being unallocated.
  3915. append_block1(DW_AT_allocated,2);
  3916. current_asmdata.asmlists[al_dwarf_info].concat(tai_const.create_8bit(ord(DW_OP_push_object_address)));
  3917. current_asmdata.asmlists[al_dwarf_info].concat(tai_const.create_8bit(ord(DW_OP_deref)));
  3918. append_block1(DW_AT_data_location,2);
  3919. current_asmdata.asmlists[al_dwarf_info].concat(tai_const.create_8bit(ord(DW_OP_push_object_address)));
  3920. current_asmdata.asmlists[al_dwarf_info].concat(tai_const.create_8bit(ord(DW_OP_deref)));
  3921. finish_entry;
  3922. end;
  3923. procedure doimplicitpointer;
  3924. var
  3925. obj : tasmlabel;
  3926. begin
  3927. if not(tf_dwarf_only_local_labels in target_info.flags) then
  3928. current_asmdata.getglobaldatalabel(obj)
  3929. else
  3930. current_asmdata.getaddrlabel(obj);
  3931. { implicit pointer }
  3932. append_entry(DW_TAG_pointer_type,false,[]);
  3933. append_labelentry_ref(DW_AT_type,obj);
  3934. finish_entry;
  3935. current_asmdata.asmlists[al_dwarf_info].concat(tai_symbol.create(obj,0));
  3936. end;
  3937. procedure doparent(isinterface: boolean);
  3938. begin
  3939. if not assigned(def.childof) then
  3940. exit;
  3941. if isinterface then
  3942. begin
  3943. append_entry(DW_TAG_inheritance,false,[]);
  3944. end
  3945. else
  3946. begin
  3947. append_entry(DW_TAG_inheritance,false,[
  3948. DW_AT_accessibility,DW_FORM_data1,DW_ACCESS_public,
  3949. DW_AT_data_member_location,DW_FORM_block1,1+lengthuleb128(0)
  3950. ]);
  3951. current_asmdata.asmlists[al_dwarf_info].concat(tai_const.create_8bit(ord(DW_OP_plus_uconst)));
  3952. current_asmdata.asmlists[al_dwarf_info].concat(tai_const.create_uleb128bit(0));
  3953. end;
  3954. append_labelentry_ref(DW_AT_type,def_dwarf_lab(def.childof));
  3955. finish_entry;
  3956. end;
  3957. var
  3958. n: integer;
  3959. begin
  3960. case def.objecttype of
  3961. odt_cppclass,
  3962. odt_object:
  3963. begin
  3964. dostruct(DW_TAG_structure_type);
  3965. doparent(false);
  3966. end;
  3967. odt_interfacecom,
  3968. odt_interfacecorba,
  3969. odt_dispinterface:
  3970. begin
  3971. dostruct(DW_TAG_interface_type);
  3972. doparent(true);
  3973. end;
  3974. odt_helper,
  3975. odt_class:
  3976. begin
  3977. //dostruct(DW_TAG_class_type);
  3978. //doparent(false);
  3979. append_entry(DW_TAG_pointer_type,false,[]);
  3980. append_labelentry_ref(DW_AT_type,def_dwarf_class_struct_lab(def));
  3981. finish_entry;
  3982. append_object_struct(def,true,def.objrealname);
  3983. Exit;
  3984. end;
  3985. else
  3986. internalerror(200609171);
  3987. end;
  3988. { add implemented interfaces }
  3989. if assigned(def.ImplementedInterfaces) then
  3990. for n := 0 to def.ImplementedInterfaces.count-1 do
  3991. begin
  3992. append_entry(DW_TAG_inheritance,false,[]);
  3993. append_labelentry_ref(DW_AT_type,def_dwarf_lab(TImplementedInterface(def.ImplementedInterfaces[n]).IntfDef));
  3994. finish_entry;
  3995. end;
  3996. { add members }
  3997. def.symtable.symList.ForEachCall(@enum_membersyms_callback,nil);
  3998. finish_children;
  3999. end;
  4000. procedure TDebugInfoDwarf3.appenddef_set(list:TAsmList;def: tsetdef);
  4001. begin
  4002. appenddef_set_intern(list,def,true);
  4003. end;
  4004. procedure TDebugInfoDwarf3.appenddef_undefined(list:TAsmList;def: tundefineddef);
  4005. begin
  4006. { ??? can a undefined def have a typename ? }
  4007. if assigned(def.typesym) then
  4008. append_entry(DW_TAG_unspecified_type,false,[
  4009. DW_AT_name,DW_FORM_string,symname(def.typesym, false)+#0
  4010. ])
  4011. else
  4012. append_entry(DW_TAG_unspecified_type,false,[
  4013. ]);
  4014. finish_entry;
  4015. end;
  4016. procedure TDebugInfoDwarf3.appenddef_variant(list:TAsmList;def: tvariantdef);
  4017. const
  4018. VARIANTS: array[1..27] of record Value: Word; Name: String end = (
  4019. (value:0; name:''),
  4020. (value:1; name:''),
  4021. (value:2; name:'VSMALLINT'),
  4022. (value:3; name:'VINTEGER'),
  4023. (value:4; name:'VSINGLE'),
  4024. (value:5; name:'VDOUBLE'),
  4025. (value:6; name:'VCURRENCY'),
  4026. (value:7; name:'VDATE'),
  4027. (value:8; name:'VOLESTR'),
  4028. (value:9; name:'VDISPATCH'),
  4029. (value:10; name:'VERROR'),
  4030. (value:11; name:'VBOOLEAN'),
  4031. (value:12; name:''),
  4032. (value:13; name:'VUNKNOWN'),
  4033. (value:14; name:''),
  4034. (value:16; name:'VSHORTINT'),
  4035. (value:17; name:'VBYTE'),
  4036. (value:18; name:'VWORD'),
  4037. (value:19; name:'VLONGWORD'),
  4038. (value:20; name:'VINT64'),
  4039. (value:21; name:'VQWORD'),
  4040. (value:36; name:'VRECORD'),
  4041. (value:$48; name:''),
  4042. (value:$100; name:'VSTRING'),
  4043. (value:$101; name:'VANY'),
  4044. (value:$2000; name:'VARRAY'),
  4045. (value:$4000; name:'VPOINTER')
  4046. );
  4047. var
  4048. fs: tfieldvarsym;
  4049. lbl: tasmlabel;
  4050. idx: integer;
  4051. begin
  4052. { it could be done with DW_TAG_variant for the union part (if that info was available)
  4053. now we do it manually for variants (MWE) }
  4054. { struct }
  4055. append_entry(DW_TAG_structure_type,true,[
  4056. DW_AT_name,DW_FORM_string,'Variant'#0,
  4057. DW_AT_byte_size,DW_FORM_udata,vardatadef.size
  4058. ]);
  4059. finish_entry;
  4060. append_entry(DW_TAG_variant_part,true,[
  4061. ]);
  4062. current_asmdata.getaddrlabel(lbl);
  4063. append_labelentry_ref(DW_AT_discr,lbl);
  4064. finish_entry;
  4065. { discriminant }
  4066. fs := tfieldvarsym(vardatadef.symtable.Find('VTYPE'));
  4067. if (fs = nil) or (fs.typ <> fieldvarsym) then
  4068. internalerror(200609271);
  4069. current_asmdata.asmlists[al_dwarf_info].concat(tai_symbol.create(lbl,0));
  4070. appendsym_fieldvar(list,fs);
  4071. { variants }
  4072. for idx := Low(VARIANTS) to High(VARIANTS) do
  4073. begin
  4074. append_entry(DW_TAG_variant,true,[
  4075. DW_AT_discr_value,DW_FORM_udata,VARIANTS[idx].value
  4076. ]);
  4077. finish_entry;
  4078. if VARIANTS[idx].name <> '' then
  4079. begin
  4080. fs := tfieldvarsym(vardatadef.symtable.Find(VARIANTS[idx].name));
  4081. if (fs = nil) or (fs.typ <> fieldvarsym) then
  4082. internalerror(20060927200+idx);
  4083. appendsym_fieldvar(list,fs);
  4084. end;
  4085. finish_children; { variant }
  4086. end;
  4087. finish_children; { variant part }
  4088. finish_children; { struct }
  4089. end;
  4090. function TDebugInfoDwarf3.dwarf_version: Word;
  4091. begin
  4092. Result:=3;
  4093. end;
  4094. function TDebugInfoDwarf3.symdebugname(sym: tsym): String;
  4095. begin
  4096. Result:=sym.realname;
  4097. end;
  4098. { TDebugInfoDwarf4 }
  4099. function TDebugInfoDwarf4.dwarf_version: Word;
  4100. begin
  4101. Result:=4;
  4102. end;
  4103. {****************************************************************************
  4104. ****************************************************************************}
  4105. const
  4106. dbg_dwarf2_info : tdbginfo =
  4107. (
  4108. id : dbg_dwarf2;
  4109. idtxt : 'DWARF2';
  4110. );
  4111. dbg_dwarf3_info : tdbginfo =
  4112. (
  4113. id : dbg_dwarf3;
  4114. idtxt : 'DWARF3';
  4115. );
  4116. dbg_dwarf4_info : tdbginfo =
  4117. (
  4118. id : dbg_dwarf4;
  4119. idtxt : 'DWARF4';
  4120. );
  4121. initialization
  4122. RegisterDebugInfo(dbg_dwarf2_info,TDebugInfoDwarf2);
  4123. RegisterDebugInfo(dbg_dwarf3_info,TDebugInfoDwarf3);
  4124. RegisterDebugInfo(dbg_dwarf4_info,TDebugInfoDwarf4);
  4125. end.