dbgdwarf.pas 161 KB

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