dbgdwarf.pas 168 KB

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