dbgdwarf.pas 185 KB

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