dbgdwarf.pas 182 KB

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