dbgdwarf.pas 183 KB

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