2
0

dbgdwarf.pas 188 KB

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