dbgdwarf.pas 184 KB

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