dbgdwarf.pas 164 KB

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