dbgdwarf.pas 186 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637
  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. ordtype : tordtype;
  1284. begin
  1285. ordtype:=def.ordtype;
  1286. if ordtype=customint then
  1287. ordtype:=range_to_basetype(def.low,def.high);
  1288. case ordtype of
  1289. s8bit,
  1290. s16bit,
  1291. s32bit,
  1292. u8bit,
  1293. u16bit,
  1294. u32bit :
  1295. begin
  1296. { generate proper signed/unsigned info for types like 0..3 }
  1297. { these are s8bit, but should be identified as unsigned }
  1298. { because otherwise they are interpreted wrongly when used }
  1299. { in a bitpacked record }
  1300. if (def.low<0) then
  1301. begin
  1302. sign:=DW_ATE_signed;
  1303. signform:=DW_FORM_sdata
  1304. end
  1305. else
  1306. begin
  1307. sign:=DW_ATE_unsigned;
  1308. signform:=DW_FORM_udata
  1309. end;
  1310. fullbytesize:=def.size;
  1311. case fullbytesize of
  1312. 1:
  1313. if (sign=DW_ATE_signed) then
  1314. basedef:=s8inttype
  1315. else
  1316. basedef:=u8inttype;
  1317. 2:
  1318. if (sign=DW_ATE_signed) then
  1319. basedef:=s16inttype
  1320. else
  1321. basedef:=u16inttype;
  1322. 3,4:
  1323. if (sign=DW_ATE_signed) then
  1324. basedef:=s32inttype
  1325. else
  1326. basedef:=u32inttype;
  1327. else
  1328. internalerror(2008032201);
  1329. end;
  1330. if (def.low=torddef(basedef).low) and
  1331. (def.high=torddef(basedef).high) then
  1332. { base type such as byte/shortint/word/... }
  1333. if assigned(def.typesym) then
  1334. append_entry(DW_TAG_base_type,false,[
  1335. DW_AT_name,DW_FORM_string,symname(def.typesym, false)+#0,
  1336. DW_AT_encoding,DW_FORM_data1,sign,
  1337. DW_AT_byte_size,DW_FORM_data1,fullbytesize])
  1338. else
  1339. append_entry(DW_TAG_base_type,false,[
  1340. DW_AT_encoding,DW_FORM_data1,sign,
  1341. DW_AT_byte_size,DW_FORM_data1,fullbytesize])
  1342. else
  1343. begin
  1344. { subrange type }
  1345. { note: don't do this 64 bit int types, they appear }
  1346. { to be always clipped to s32bit for some reason }
  1347. if assigned(def.typesym) then
  1348. append_entry(DW_TAG_subrange_type,false,[
  1349. DW_AT_name,DW_FORM_string,symname(def.typesym, false)+#0,
  1350. DW_AT_lower_bound,signform,int64(def.low),
  1351. DW_AT_upper_bound,signform,int64(def.high)
  1352. ])
  1353. else
  1354. append_entry(DW_TAG_subrange_type,false,[
  1355. DW_AT_lower_bound,signform,int64(def.low),
  1356. DW_AT_upper_bound,signform,int64(def.high)
  1357. ]);
  1358. append_labelentry_ref(DW_AT_type,def_dwarf_lab(basedef));
  1359. end;
  1360. finish_entry;
  1361. end;
  1362. uvoid :
  1363. begin
  1364. { gdb 6.4 doesn't support DW_TAG_unspecified_type so we
  1365. replace it with a unsigned type with size 0 (FK)
  1366. }
  1367. append_entry(DW_TAG_base_type,false,[
  1368. DW_AT_name,DW_FORM_string,'Void'#0,
  1369. DW_AT_encoding,DW_FORM_data1,DW_ATE_unsigned,
  1370. DW_AT_byte_size,DW_FORM_data1,0
  1371. ]);
  1372. finish_entry;
  1373. end;
  1374. uchar :
  1375. begin
  1376. append_entry(DW_TAG_base_type,false,[
  1377. DW_AT_name,DW_FORM_string,'Char'#0,
  1378. DW_AT_encoding,DW_FORM_data1,DW_ATE_unsigned_char,
  1379. DW_AT_byte_size,DW_FORM_data1,1
  1380. ]);
  1381. finish_entry;
  1382. end;
  1383. uwidechar :
  1384. begin
  1385. append_entry(DW_TAG_base_type,false,[
  1386. DW_AT_name,DW_FORM_string,'WideChar'#0,
  1387. DW_AT_encoding,DW_FORM_data1,DW_ATE_unsigned_char,
  1388. DW_AT_byte_size,DW_FORM_data1,2
  1389. ]);
  1390. finish_entry;
  1391. end;
  1392. pasbool1 :
  1393. begin
  1394. append_entry(DW_TAG_base_type,false,[
  1395. DW_AT_name,DW_FORM_string,'Boolean'#0,
  1396. DW_AT_encoding,DW_FORM_data1,DW_ATE_boolean,
  1397. DW_AT_byte_size,DW_FORM_data1,1
  1398. ]);
  1399. finish_entry;
  1400. end;
  1401. pasbool8 :
  1402. begin
  1403. append_entry(DW_TAG_base_type,false,[
  1404. DW_AT_name,DW_FORM_string,'Boolean8'#0,
  1405. DW_AT_encoding,DW_FORM_data1,DW_ATE_boolean,
  1406. DW_AT_byte_size,DW_FORM_data1,1
  1407. ]);
  1408. finish_entry;
  1409. end;
  1410. bool8bit :
  1411. begin
  1412. append_entry(DW_TAG_base_type,false,[
  1413. DW_AT_name,DW_FORM_string,'ByteBool'#0,
  1414. DW_AT_encoding,DW_FORM_data1,DW_ATE_boolean,
  1415. DW_AT_byte_size,DW_FORM_data1,1
  1416. ]);
  1417. finish_entry;
  1418. end;
  1419. pasbool16 :
  1420. begin
  1421. append_entry(DW_TAG_base_type,false,[
  1422. DW_AT_name,DW_FORM_string,'Boolean16'#0,
  1423. DW_AT_encoding,DW_FORM_data1,DW_ATE_boolean,
  1424. DW_AT_byte_size,DW_FORM_data1,2
  1425. ]);
  1426. finish_entry;
  1427. end;
  1428. bool16bit :
  1429. begin
  1430. append_entry(DW_TAG_base_type,false,[
  1431. DW_AT_name,DW_FORM_string,'WordBool'#0,
  1432. DW_AT_encoding,DW_FORM_data1,DW_ATE_boolean,
  1433. DW_AT_byte_size,DW_FORM_data1,2
  1434. ]);
  1435. finish_entry;
  1436. end;
  1437. pasbool32 :
  1438. begin
  1439. append_entry(DW_TAG_base_type,false,[
  1440. DW_AT_name,DW_FORM_string,'Boolean32'#0,
  1441. DW_AT_encoding,DW_FORM_data1,DW_ATE_boolean,
  1442. DW_AT_byte_size,DW_FORM_data1,4
  1443. ]);
  1444. finish_entry;
  1445. end;
  1446. bool32bit :
  1447. begin
  1448. append_entry(DW_TAG_base_type,false,[
  1449. DW_AT_name,DW_FORM_string,'LongBool'#0,
  1450. DW_AT_encoding,DW_FORM_data1,DW_ATE_boolean,
  1451. DW_AT_byte_size,DW_FORM_data1,4
  1452. ]);
  1453. finish_entry;
  1454. end;
  1455. pasbool64 :
  1456. begin
  1457. append_entry(DW_TAG_base_type,false,[
  1458. DW_AT_name,DW_FORM_string,'Boolean64'#0,
  1459. DW_AT_encoding,DW_FORM_data1,DW_ATE_boolean,
  1460. DW_AT_byte_size,DW_FORM_data1,8
  1461. ]);
  1462. finish_entry;
  1463. end;
  1464. bool64bit :
  1465. begin
  1466. append_entry(DW_TAG_base_type,false,[
  1467. DW_AT_name,DW_FORM_string,'QWordBool'#0,
  1468. DW_AT_encoding,DW_FORM_data1,DW_ATE_boolean,
  1469. DW_AT_byte_size,DW_FORM_data1,8
  1470. ]);
  1471. finish_entry;
  1472. end;
  1473. u64bit :
  1474. begin
  1475. append_entry(DW_TAG_base_type,false,[
  1476. DW_AT_name,DW_FORM_string,'QWord'#0,
  1477. DW_AT_encoding,DW_FORM_data1,DW_ATE_unsigned,
  1478. DW_AT_byte_size,DW_FORM_data1,8
  1479. ]);
  1480. finish_entry;
  1481. end;
  1482. scurrency :
  1483. begin
  1484. { we should use DW_ATE_signed_fixed, however it isn't supported yet by GDB (FK) }
  1485. append_entry(DW_TAG_base_type,false,[
  1486. DW_AT_name,DW_FORM_string,'Currency'#0,
  1487. DW_AT_encoding,DW_FORM_data1,DW_ATE_signed,
  1488. DW_AT_byte_size,DW_FORM_data1,8
  1489. ]);
  1490. finish_entry;
  1491. end;
  1492. s64bit :
  1493. begin
  1494. append_entry(DW_TAG_base_type,false,[
  1495. DW_AT_name,DW_FORM_string,'Int64'#0,
  1496. DW_AT_encoding,DW_FORM_data1,DW_ATE_signed,
  1497. DW_AT_byte_size,DW_FORM_data1,8
  1498. ]);
  1499. finish_entry;
  1500. end;
  1501. u128bit:
  1502. begin
  1503. append_entry(DW_TAG_base_type,false,[
  1504. DW_AT_name,DW_FORM_string,'Int128'#0,
  1505. DW_AT_encoding,DW_FORM_data1,DW_ATE_unsigned,
  1506. DW_AT_byte_size,DW_FORM_data1,16
  1507. ]);
  1508. finish_entry;
  1509. end;
  1510. s128bit:
  1511. begin
  1512. append_entry(DW_TAG_base_type,false,[
  1513. DW_AT_name,DW_FORM_string,'Int128'#0,
  1514. DW_AT_encoding,DW_FORM_data1,DW_ATE_signed,
  1515. DW_AT_byte_size,DW_FORM_data1,16
  1516. ]);
  1517. finish_entry;
  1518. end;
  1519. else
  1520. internalerror(200601287);
  1521. end;
  1522. end;
  1523. procedure TDebugInfoDwarf.appenddef_float(list:TAsmList;def:tfloatdef);
  1524. begin
  1525. case def.floattype of
  1526. s32real,
  1527. s64real,
  1528. s80real,
  1529. sc80real:
  1530. if assigned(def.typesym) then
  1531. begin
  1532. append_entry(DW_TAG_base_type,false,[
  1533. DW_AT_name,DW_FORM_string,symname(def.typesym, false)+#0,
  1534. DW_AT_encoding,DW_FORM_data1,DW_ATE_float,
  1535. DW_AT_byte_size,DW_FORM_data1,def.size
  1536. ]);
  1537. if (def.floattype in [s80real,sc80real]) and
  1538. (def.size<>10) then
  1539. begin
  1540. append_attribute(DW_AT_bit_size,DW_FORM_data1,[10*8]);
  1541. { "The bit offset attribute describes the offset in bits
  1542. of the high order bit of a value of the given type
  1543. from the high order bit of the storage unit used to
  1544. contain that value." }
  1545. if target_info.endian=endian_little then
  1546. append_attribute(DW_AT_bit_offset,DW_FORM_data1,[(def.size-10)*8]);
  1547. end;
  1548. end
  1549. else
  1550. append_entry(DW_TAG_base_type,false,[
  1551. DW_AT_encoding,DW_FORM_data1,DW_ATE_float,
  1552. DW_AT_byte_size,DW_FORM_data1,def.size
  1553. ]);
  1554. s64currency:
  1555. { we should use DW_ATE_signed_fixed, however it isn't supported yet by GDB (FK) }
  1556. if assigned(def.typesym) then
  1557. append_entry(DW_TAG_base_type,false,[
  1558. DW_AT_name,DW_FORM_string,symname(def.typesym, false)+#0,
  1559. DW_AT_encoding,DW_FORM_data1,DW_ATE_signed,
  1560. DW_AT_byte_size,DW_FORM_data1,8
  1561. ])
  1562. else
  1563. append_entry(DW_TAG_base_type,false,[
  1564. DW_AT_encoding,DW_FORM_data1,DW_ATE_signed,
  1565. DW_AT_byte_size,DW_FORM_data1,8
  1566. ]);
  1567. s64comp:
  1568. if assigned(def.typesym) then
  1569. append_entry(DW_TAG_base_type,false,[
  1570. DW_AT_name,DW_FORM_string,symname(def.typesym, false)+#0,
  1571. DW_AT_encoding,DW_FORM_data1,DW_ATE_signed,
  1572. DW_AT_byte_size,DW_FORM_data1,8
  1573. ])
  1574. else
  1575. append_entry(DW_TAG_base_type,false,[
  1576. DW_AT_encoding,DW_FORM_data1,DW_ATE_signed,
  1577. DW_AT_byte_size,DW_FORM_data1,8
  1578. ]);
  1579. else
  1580. internalerror(200601289);
  1581. end;
  1582. finish_entry;
  1583. end;
  1584. procedure TDebugInfoDwarf.appenddef_enum(list:TAsmList;def:tenumdef);
  1585. var
  1586. hp : tenumsym;
  1587. i : integer;
  1588. begin
  1589. if assigned(def.typesym) then
  1590. append_entry(DW_TAG_enumeration_type,true,[
  1591. DW_AT_name,DW_FORM_string,symname(def.typesym, false)+#0,
  1592. DW_AT_byte_size,DW_FORM_data1,def.size
  1593. ])
  1594. else
  1595. append_entry(DW_TAG_enumeration_type,true,[
  1596. DW_AT_byte_size,DW_FORM_data1,def.size
  1597. ]);
  1598. if assigned(def.basedef) then
  1599. append_labelentry_ref(DW_AT_type,def_dwarf_lab(def.basedef));
  1600. finish_entry;
  1601. { write enum symbols }
  1602. for i := 0 to def.symtable.SymList.Count - 1 do
  1603. begin
  1604. hp:=tenumsym(def.symtable.SymList[i]);
  1605. if hp.value<def.minval then
  1606. continue
  1607. else
  1608. if hp.value>def.maxval then
  1609. break;
  1610. append_entry(DW_TAG_enumerator,false,[
  1611. DW_AT_name,DW_FORM_string,symname(hp, false)+#0,
  1612. DW_AT_const_value,DW_FORM_data4,hp.value
  1613. ]);
  1614. finish_entry;
  1615. end;
  1616. finish_children;
  1617. end;
  1618. procedure TDebugInfoDwarf.appenddef_array(list:TAsmList;def:tarraydef);
  1619. var
  1620. size : PInt;
  1621. elesize : PInt;
  1622. elestrideattr : tdwarf_attribute;
  1623. labsym: tasmlabel;
  1624. begin
  1625. if is_dynamic_array(def) then
  1626. begin
  1627. { It's a pointer to the actual array }
  1628. current_asmdata.getaddrlabel(labsym);
  1629. append_entry(DW_TAG_pointer_type,false,[]);
  1630. append_labelentry_ref(DW_AT_type,labsym);
  1631. finish_entry;
  1632. current_asmdata.asmlists[al_dwarf_info].concat(tai_symbol.create(labsym,0));
  1633. end;
  1634. if not is_packed_array(def) then
  1635. begin
  1636. elestrideattr := DW_AT_byte_stride;
  1637. elesize := def.elesize;
  1638. end
  1639. else
  1640. begin
  1641. elestrideattr := DW_AT_stride_size;
  1642. elesize := def.elepackedbitsize;
  1643. end;
  1644. if is_special_array(def) then
  1645. begin
  1646. { no known size, no known upper bound }
  1647. if assigned(def.typesym) then
  1648. append_entry(DW_TAG_array_type,true,[
  1649. DW_AT_name,DW_FORM_string,symname(def.typesym, false)+#0
  1650. ])
  1651. else
  1652. append_entry(DW_TAG_array_type,true,[]);
  1653. append_labelentry_ref(DW_AT_type,def_dwarf_lab(def.elementdef));
  1654. finish_entry;
  1655. { a missing upper bound means "unknown"/default }
  1656. append_entry(DW_TAG_subrange_type,false,[
  1657. DW_AT_lower_bound,DW_FORM_sdata,def.lowrange,
  1658. elestrideattr,DW_FORM_udata,elesize
  1659. ]);
  1660. end
  1661. else
  1662. begin
  1663. size:=def.size;
  1664. if assigned(def.typesym) then
  1665. append_entry(DW_TAG_array_type,true,[
  1666. DW_AT_name,DW_FORM_string,symname(def.typesym, false)+#0,
  1667. DW_AT_byte_size,DW_FORM_udata,size
  1668. ])
  1669. else
  1670. append_entry(DW_TAG_array_type,true,[
  1671. DW_AT_byte_size,DW_FORM_udata,size
  1672. ]);
  1673. append_labelentry_ref(DW_AT_type,def_dwarf_lab(def.elementdef));
  1674. finish_entry;
  1675. { to simplify things, we don't write a multidimensional array here }
  1676. append_entry(DW_TAG_subrange_type,false,[
  1677. DW_AT_lower_bound,DW_FORM_sdata,def.lowrange,
  1678. DW_AT_upper_bound,DW_FORM_sdata,def.highrange,
  1679. elestrideattr,DW_FORM_udata,elesize
  1680. ]);
  1681. end;
  1682. append_labelentry_ref(DW_AT_type,def_dwarf_lab(def.rangedef));
  1683. finish_entry;
  1684. finish_children;
  1685. end;
  1686. procedure TDebugInfoDwarf.appenddef_record(list:TAsmList;def:trecorddef);
  1687. begin
  1688. if assigned(def.objname) then
  1689. appenddef_record_named(list,def,def.objname^)
  1690. else
  1691. appenddef_record_named(list,def,'');
  1692. end;
  1693. procedure TDebugInfoDwarf.appenddef_record_named(list:TAsmList;def:trecorddef;const name: shortstring);
  1694. begin
  1695. if (name<>'') then
  1696. append_entry(DW_TAG_structure_type,true,[
  1697. DW_AT_name,DW_FORM_string,name+#0,
  1698. DW_AT_byte_size,DW_FORM_udata,def.size
  1699. ])
  1700. else
  1701. append_entry(DW_TAG_structure_type,true,[
  1702. DW_AT_byte_size,DW_FORM_udata,def.size
  1703. ]);
  1704. finish_entry;
  1705. def.symtable.symList.ForEachCall(@enum_membersyms_callback,nil);
  1706. { don't know whether external record declaration is allow but if it so then
  1707. do the same as we do for other object types - skip procdef info generation
  1708. for external defs (Paul Ishenin) }
  1709. if not(oo_is_external in def.objectoptions) then
  1710. write_symtable_procdefs(current_asmdata.asmlists[al_dwarf_info],def.symtable);
  1711. finish_children;
  1712. end;
  1713. procedure TDebugInfoDwarf.appenddef_pointer(list:TAsmList;def:tpointerdef);
  1714. begin
  1715. append_entry(DW_TAG_pointer_type,false,[]);
  1716. append_pointerclass(list,def);
  1717. if not(is_voidpointer(def)) then
  1718. append_labelentry_ref(DW_AT_type,def_dwarf_lab(def.pointeddef));
  1719. finish_entry;
  1720. end;
  1721. procedure TDebugInfoDwarf.appenddef_string(list:TAsmList;def:tstringdef);
  1722. procedure addnormalstringdef(const name: shortstring; lendef: tdef; maxlen: asizeuint);
  1723. var
  1724. { maxlen can be > high(int64) }
  1725. slen : asizeuint;
  1726. arr : tasmlabel;
  1727. begin
  1728. { fix length of openshortstring }
  1729. slen:=aword(def.len);
  1730. if (slen=0) or
  1731. (slen>maxlen) then
  1732. slen:=maxlen;
  1733. { create a structure with two elements }
  1734. if not(tf_dwarf_only_local_labels in target_info.flags) then
  1735. current_asmdata.getglobaldatalabel(arr)
  1736. else
  1737. current_asmdata.getaddrlabel(arr);
  1738. append_entry(DW_TAG_structure_type,true,[
  1739. DW_AT_name,DW_FORM_string,name+#0,
  1740. DW_AT_byte_size,DW_FORM_udata,qword(lendef.size)+slen
  1741. ]);
  1742. finish_entry;
  1743. { length entry }
  1744. append_entry(DW_TAG_member,false,[
  1745. DW_AT_name,DW_FORM_string,'length'#0,
  1746. DW_AT_data_member_location,DW_FORM_block1,1+lengthuleb128(0)
  1747. ]);
  1748. current_asmdata.asmlists[al_dwarf_info].concat(tai_const.create_8bit(ord(DW_OP_plus_uconst)));
  1749. current_asmdata.asmlists[al_dwarf_info].concat(tai_const.create_uleb128bit(0));
  1750. append_labelentry_ref(DW_AT_type,def_dwarf_lab(lendef));
  1751. finish_entry;
  1752. { string data entry }
  1753. append_entry(DW_TAG_member,false,[
  1754. DW_AT_name,DW_FORM_string,'st'#0,
  1755. DW_AT_data_member_location,DW_FORM_block1,1+lengthuleb128(1)
  1756. ]);
  1757. current_asmdata.asmlists[al_dwarf_info].concat(tai_const.create_8bit(ord(DW_OP_plus_uconst)));
  1758. current_asmdata.asmlists[al_dwarf_info].concat(tai_const.create_uleb128bit(lendef.size));
  1759. append_labelentry_ref(DW_AT_type,arr);
  1760. finish_entry;
  1761. finish_children;
  1762. { now the data array }
  1763. if arr.bind=AB_GLOBAL then
  1764. current_asmdata.asmlists[al_dwarf_info].concat(tai_symbol.create_global(arr,0))
  1765. else
  1766. current_asmdata.asmlists[al_dwarf_info].concat(tai_symbol.create(arr,0));
  1767. append_entry(DW_TAG_array_type,true,[
  1768. DW_AT_byte_size,DW_FORM_udata,def.size,
  1769. DW_AT_byte_stride,DW_FORM_udata,1
  1770. ]);
  1771. append_labelentry_ref(DW_AT_type,def_dwarf_lab(cansichartype));
  1772. finish_entry;
  1773. append_entry(DW_TAG_subrange_type,false,[
  1774. DW_AT_lower_bound,DW_FORM_udata,1,
  1775. DW_AT_upper_bound,DW_FORM_udata,qword(slen)
  1776. ]);
  1777. append_labelentry_ref(DW_AT_type,def_dwarf_lab(lendef));
  1778. finish_entry;
  1779. finish_children;
  1780. end;
  1781. begin
  1782. case def.stringtype of
  1783. st_shortstring:
  1784. begin
  1785. addnormalstringdef('ShortString',u8inttype,255);
  1786. end;
  1787. st_longstring:
  1788. begin
  1789. { a) we don't actually support variables of this type currently
  1790. b) this type is only used as the type for constant strings
  1791. > 255 characters
  1792. c) in such a case, gdb will allocate and initialise enough
  1793. memory to hold the maximum size for such a string
  1794. -> don't use high(qword)/high(cardinal) as maximum, since that
  1795. will cause exhausting the VM space, but some "reasonably high"
  1796. number that should be enough for most constant strings
  1797. }
  1798. {$ifdef cpu64bitaddr}
  1799. addnormalstringdef('LongString',u64inttype,qword(1024*1024));
  1800. {$endif cpu64bitaddr}
  1801. {$ifdef cpu32bitaddr}
  1802. addnormalstringdef('LongString',u32inttype,cardinal(1024*1024));
  1803. {$endif cpu32bitaddr}
  1804. {$ifdef cpu16bitaddr}
  1805. addnormalstringdef('LongString',u16inttype,cardinal(1024));
  1806. {$endif cpu16bitaddr}
  1807. end;
  1808. st_ansistring:
  1809. begin
  1810. { looks like a pchar }
  1811. append_entry(DW_TAG_pointer_type,false,[]);
  1812. append_labelentry_ref(DW_AT_type,def_dwarf_lab(cansichartype));
  1813. finish_entry;
  1814. end;
  1815. st_unicodestring,
  1816. st_widestring:
  1817. begin
  1818. { looks like a pwidechar }
  1819. append_entry(DW_TAG_pointer_type,false,[]);
  1820. append_labelentry_ref(DW_AT_type,def_dwarf_lab(cwidechartype));
  1821. finish_entry;
  1822. end;
  1823. end;
  1824. end;
  1825. procedure TDebugInfoDwarf.appenddef_procvar(list:TAsmList;def:tprocvardef);
  1826. procedure doappend;
  1827. var
  1828. i : longint;
  1829. begin
  1830. if assigned(def.typesym) then
  1831. append_entry(DW_TAG_subroutine_type,true,[
  1832. DW_AT_name,DW_FORM_string,symname(def.typesym, false)+#0,
  1833. DW_AT_prototyped,DW_FORM_flag,true
  1834. ])
  1835. else
  1836. append_entry(DW_TAG_subroutine_type,true,[
  1837. DW_AT_prototyped,DW_FORM_flag,true
  1838. ]);
  1839. if not(is_void(tprocvardef(def).returndef)) then
  1840. append_labelentry_ref(DW_AT_type,def_dwarf_lab(tprocvardef(def).returndef));
  1841. finish_entry;
  1842. { write parameters }
  1843. for i:=0 to def.paras.count-1 do
  1844. begin
  1845. append_entry(DW_TAG_formal_parameter,false,[
  1846. DW_AT_name,DW_FORM_string,symname(tsym(def.paras[i]), false)+#0
  1847. ]);
  1848. append_labelentry_ref(DW_AT_type,def_dwarf_lab(tparavarsym(def.paras[i]).vardef));
  1849. finish_entry;
  1850. end;
  1851. finish_children;
  1852. end;
  1853. var
  1854. proc : tasmlabel;
  1855. begin
  1856. if not def.is_addressonly then
  1857. begin
  1858. { create a structure with two elements }
  1859. if not(tf_dwarf_only_local_labels in target_info.flags) then
  1860. current_asmdata.getglobaldatalabel(proc)
  1861. else
  1862. current_asmdata.getaddrlabel(proc);
  1863. append_entry(DW_TAG_structure_type,true,[
  1864. DW_AT_byte_size,DW_FORM_data1,2*sizeof(pint)
  1865. ]);
  1866. finish_entry;
  1867. { proc entry }
  1868. append_entry(DW_TAG_member,false,[
  1869. DW_AT_name,DW_FORM_string,'Proc'#0,
  1870. DW_AT_data_member_location,DW_FORM_block1,1+lengthuleb128(0)
  1871. ]);
  1872. current_asmdata.asmlists[al_dwarf_info].concat(tai_const.create_8bit(ord(DW_OP_plus_uconst)));
  1873. current_asmdata.asmlists[al_dwarf_info].concat(tai_const.create_uleb128bit(0));
  1874. append_labelentry_ref(DW_AT_type,proc);
  1875. finish_entry;
  1876. { self entry }
  1877. append_entry(DW_TAG_member,false,[
  1878. DW_AT_name,DW_FORM_string,'Self'#0,
  1879. DW_AT_data_member_location,DW_FORM_block1,1+lengthuleb128(sizeof(pint))
  1880. ]);
  1881. current_asmdata.asmlists[al_dwarf_info].concat(tai_const.create_8bit(ord(DW_OP_plus_uconst)));
  1882. current_asmdata.asmlists[al_dwarf_info].concat(tai_const.create_uleb128bit(sizeof(pint)));
  1883. append_labelentry_ref(DW_AT_type,def_dwarf_lab(class_tobject));
  1884. finish_entry;
  1885. finish_children;
  1886. if proc.bind=AB_GLOBAL then
  1887. current_asmdata.asmlists[al_dwarf_info].concat(tai_symbol.create_global(proc,0))
  1888. else
  1889. current_asmdata.asmlists[al_dwarf_info].concat(tai_symbol.create(proc,0));
  1890. doappend;
  1891. end
  1892. else
  1893. doappend;
  1894. end;
  1895. procedure TDebugInfoDwarf.beforeappenddef(list:TAsmList;def:tdef);
  1896. var
  1897. labsym : tasmsymbol;
  1898. begin
  1899. current_asmdata.asmlists[al_dwarf_info].concat(tai_comment.Create(strpnew('Definition '+def.typename)));
  1900. labsym:=def_dwarf_lab(def);
  1901. case labsym.bind of
  1902. AB_GLOBAL:
  1903. current_asmdata.asmlists[al_dwarf_info].concat(tai_symbol.create_global(labsym,0));
  1904. AB_LOCAL:
  1905. current_asmdata.asmlists[al_dwarf_info].concat(tai_symbol.create(labsym,0));
  1906. else
  1907. internalerror(2013082001);
  1908. end;
  1909. { On Darwin, dwarf info is not linked in the final binary,
  1910. but kept in the individual object files. This allows for
  1911. faster linking, but means that you have to keep the object
  1912. files for debugging and also that gdb only loads in the
  1913. debug info of a particular object file once you step into
  1914. or over a procedure in it.
  1915. To solve this, there is a tool called dsymutil which can
  1916. extract all the dwarf info from a program's object files.
  1917. This utility however performs "smart linking" on the dwarf
  1918. info and throws away all unreferenced dwarf entries. Since
  1919. variables' types always point to the dwarfinfo for a tdef
  1920. and never to that for a typesym, this means all debug
  1921. entries generated for typesyms are thrown away.
  1922. The problem with that is that we translate typesyms into
  1923. DW_TAG_typedef, and gdb's dwarf-2 reader only makes types
  1924. globally visibly if they are defined using a DW_TAG_typedef.
  1925. So as a result, before running dsymutil types only become
  1926. available once you stepped into/over a function in the object
  1927. file where they are declared, and after running dsymutil they
  1928. are all gone (printing variables still works because the
  1929. tdef dwarf info is still available, but you cannot typecast
  1930. anything outside the declaring units because the type names
  1931. are not known there).
  1932. The solution: if a tdef has an associated typesym, let the
  1933. debug label for the tdef point to a DW_TAG_typedef instead
  1934. of directly to the tdef itself. And don't write anything
  1935. special for the typesym itself.
  1936. Update: we now also do this for other platforms, because
  1937. otherwise if you compile unit A without debug info and
  1938. use one of its types in unit B, then no typedef will be
  1939. generated and hence gdb will not be able to give a definition
  1940. of the type.
  1941. }
  1942. if is_objc_class_or_protocol(def) then
  1943. begin
  1944. { for Objective-C classes, the typedef must refer to the
  1945. struct itself, not to the pointer of the struct; Objective-C
  1946. classes are not implicit pointers in Objective-C itself, only
  1947. in FPC. So make the def label point to a pointer to the
  1948. typedef, which in turn refers to the actual struct (for Delphi-
  1949. style classes, the def points to the typedef, which refers to
  1950. a pointer to the actual struct) }
  1951. { implicit pointer }
  1952. current_asmdata.getaddrlabel(TAsmLabel(pointer(labsym)));
  1953. append_entry(DW_TAG_pointer_type,false,[]);
  1954. append_labelentry_ref(DW_AT_type,labsym);
  1955. finish_entry;
  1956. current_asmdata.asmlists[al_dwarf_info].concat(tai_symbol.create(labsym,0));
  1957. end;
  1958. if assigned(def.typesym) and
  1959. not(df_generic in def.defoptions) then
  1960. begin
  1961. current_asmdata.getaddrlabel(TAsmLabel(pointer(labsym)));
  1962. append_entry(DW_TAG_typedef,false,[
  1963. DW_AT_name,DW_FORM_string,symname(def.typesym, false)+#0
  1964. ]);
  1965. append_labelentry_ref(DW_AT_type,labsym);
  1966. finish_entry;
  1967. current_asmdata.asmlists[al_dwarf_info].concat(tai_symbol.create(labsym,0));
  1968. end
  1969. end;
  1970. procedure TDebugInfoDwarf.afterappenddef(list:TAsmList;def:tdef);
  1971. var
  1972. labsym : tasmsymbol;
  1973. begin
  1974. { create a derived reference type for pass-by-reference parameters }
  1975. { (gdb doesn't support DW_AT_variable_parameter yet) }
  1976. labsym:=def_dwarf_ref_lab(def);
  1977. case labsym.bind of
  1978. AB_GLOBAL:
  1979. current_asmdata.asmlists[al_dwarf_info].concat(tai_symbol.create_global(labsym,0));
  1980. AB_LOCAL:
  1981. current_asmdata.asmlists[al_dwarf_info].concat(tai_symbol.create(labsym,0));
  1982. else
  1983. internalerror(2013082002);
  1984. end;
  1985. append_entry(DW_TAG_reference_type,false,[]);
  1986. append_labelentry_ref(DW_AT_type,def_dwarf_lab(def));
  1987. finish_entry;
  1988. end;
  1989. procedure TDebugInfoDwarf.appendprocdef(list:TAsmList; def:tprocdef);
  1990. function dwarf_calling_convention(def: tprocdef): Tdwarf_calling_convention;
  1991. begin
  1992. case def.proccalloption of
  1993. pocall_register:
  1994. result:=DW_CC_GNU_borland_fastcall_i386;
  1995. pocall_cdecl,
  1996. pocall_stdcall,
  1997. pocall_cppdecl,
  1998. pocall_mwpascal:
  1999. result:=DW_CC_normal;
  2000. else
  2001. result:=DW_CC_nocall;
  2002. end
  2003. end;
  2004. var
  2005. procendlabel : tasmlabel;
  2006. procentry : string;
  2007. cc : Tdwarf_calling_convention;
  2008. st : tsymtable;
  2009. vmtoffset : pint;
  2010. in_currentunit : boolean;
  2011. begin
  2012. { only write debug info for procedures defined in the current module,
  2013. except in case of methods (gcc-compatible)
  2014. }
  2015. in_currentunit:=def.in_currentunit;
  2016. if not in_currentunit and
  2017. not (def.owner.symtabletype in [objectsymtable,recordsymtable]) then
  2018. exit;
  2019. { happens for init procdef of units without init section }
  2020. if in_currentunit and
  2021. not assigned(def.procstarttai) then
  2022. exit;
  2023. { Procdefs are not handled by the regular def writing code, so
  2024. dbg_state is not set/checked for them. Do it here. }
  2025. if (def.dbg_state in [dbg_state_writing,dbg_state_written]) then
  2026. exit;
  2027. defnumberlist.Add(def);
  2028. { Write methods and only in the scope of their parent objectdefs. }
  2029. if (def.owner.symtabletype in [objectsymtable,recordsymtable]) then
  2030. begin
  2031. { this code can also work for nested procdefs, but is not yet
  2032. activated for those because there is no clear advantage yet to
  2033. limiting the scope of nested procedures to that of their parent,
  2034. and it makes it impossible to set breakpoints in them by
  2035. referring to their name. }
  2036. st:=def.owner;
  2037. while assigned(st.defowner) and
  2038. (tdef(st.defowner).typ = procdef) do
  2039. st:=tprocdef(st.defowner).owner;
  2040. if assigned(st) and
  2041. (tdef(st.defowner).dbg_state<>dbg_state_writing) then
  2042. exit;
  2043. end;
  2044. def.dbg_state:=dbg_state_writing;
  2045. current_asmdata.asmlists[al_dwarf_info].concat(tai_comment.Create(strpnew('Procdef '+def.fullprocname(true))));
  2046. if not is_objc_class_or_protocol(def.struct) then
  2047. append_entry(DW_TAG_subprogram,true,
  2048. [DW_AT_name,DW_FORM_string,symname(def.procsym, false)+#0])
  2049. else
  2050. append_entry(DW_TAG_subprogram,true,
  2051. [DW_AT_name,DW_FORM_string,def.mangledname+#0]);
  2052. append_proc_frame_base(list,def);
  2053. { Append optional flags. }
  2054. { All Pascal procedures are prototyped }
  2055. append_attribute(DW_AT_prototyped,DW_FORM_flag,[true]);
  2056. { Calling convention. }
  2057. cc:=dwarf_calling_convention(def);
  2058. if (cc<>DW_CC_normal) then
  2059. append_attribute(DW_AT_calling_convention,DW_FORM_data1,[ord(cc)]);
  2060. {$ifdef i8086}
  2061. { Call model (near or far). Open Watcom compatible. }
  2062. if tcpuprocdef(def).is_far then
  2063. append_attribute(DW_AT_address_class,DW_FORM_data1,[DW_ADDR_far16])
  2064. else
  2065. append_attribute(DW_AT_address_class,DW_FORM_data1,[DW_ADDR_none]);
  2066. {$endif i8086}
  2067. { Externally visible. }
  2068. if (po_global in def.procoptions) and
  2069. (def.parast.symtablelevel<=normal_function_level) then
  2070. append_attribute(DW_AT_external,DW_FORM_flag,[true]);
  2071. { Abstract or virtual/overriding method. }
  2072. if (([po_abstractmethod, po_virtualmethod, po_overridingmethod] * def.procoptions) <> []) and
  2073. not is_objc_class_or_protocol(def.struct) and
  2074. not is_objectpascal_helper(def.struct) then
  2075. begin
  2076. if not(po_abstractmethod in def.procoptions) then
  2077. append_attribute(DW_AT_virtuality,DW_FORM_data1,[ord(DW_VIRTUALITY_virtual)])
  2078. else
  2079. append_attribute(DW_AT_virtuality,DW_FORM_data1,[ord(DW_VIRTUALITY_pure_virtual)]);
  2080. { Element number in the vmt (needs to skip stuff coming before the
  2081. actual method addresses in the vmt, so we use vmtmethodoffset()
  2082. and then divide by sizeof(pint)). }
  2083. vmtoffset:=tobjectdef(def.owner.defowner).vmtmethodoffset(def.extnumber);
  2084. append_attribute(DW_AT_vtable_elem_location,DW_FORM_block1,[3+LengthUleb128(vmtoffset)]);
  2085. current_asmdata.asmlists[al_dwarf_info].concat(tai_const.create_8bit(ord(DW_OP_deref)));
  2086. current_asmdata.asmlists[al_dwarf_info].concat(tai_const.create_8bit(ord(DW_OP_constu)));
  2087. current_asmdata.asmlists[al_dwarf_info].concat(tai_const.Create_uleb128bit(vmtoffset));
  2088. current_asmdata.asmlists[al_dwarf_info].concat(tai_const.create_8bit(ord(DW_OP_plus)));
  2089. end;
  2090. { accessibility: public/private/protected }
  2091. if (def.owner.symtabletype in [objectsymtable,recordsymtable]) then
  2092. append_visibility(def.visibility);
  2093. { Return type. }
  2094. if not(is_void(tprocdef(def).returndef)) then
  2095. append_labelentry_ref(DW_AT_type,def_dwarf_lab(tprocdef(def).returndef));
  2096. { we can only write the start/end if this procedure is implemented in
  2097. this module
  2098. }
  2099. if in_currentunit then
  2100. begin
  2101. { mark end of procedure }
  2102. current_asmdata.getlabel(procendlabel,alt_dbgtype);
  2103. current_asmdata.asmlists[al_procedures].insertbefore(tai_label.create(procendlabel),def.procendtai);
  2104. if use_dotted_functions then
  2105. procentry := '.' + def.mangledname
  2106. else
  2107. procentry := def.mangledname;
  2108. {$ifdef i8086}
  2109. append_seg_name(procentry);
  2110. {$endif i8086}
  2111. append_labelentry(DW_AT_low_pc,current_asmdata.RefAsmSymbol(procentry,AT_FUNCTION));
  2112. append_labelentry(DW_AT_high_pc,procendlabel);
  2113. if not(target_info.system in systems_darwin) then
  2114. begin
  2115. current_asmdata.asmlists[al_dwarf_aranges].Concat(
  2116. tai_const.create_type_sym(aitconst_ptr_unaligned,current_asmdata.RefAsmSymbol(procentry,AT_FUNCTION)));
  2117. {$ifdef i8086}
  2118. { bits 16..31 of the offset }
  2119. current_asmdata.asmlists[al_dwarf_aranges].concat(tai_const.Create_16bit_unaligned(0));
  2120. { segment }
  2121. current_asmdata.asmlists[al_dwarf_aranges].concat(tai_const.Create_seg_name(procentry));
  2122. {$endif i8086}
  2123. current_asmdata.asmlists[al_dwarf_aranges].Concat(
  2124. tai_const.Create_rel_sym(aitconst_ptr_unaligned,current_asmdata.RefAsmSymbol(procentry,AT_FUNCTION),procendlabel));
  2125. {$ifdef i8086}
  2126. { bits 16..31 of length }
  2127. current_asmdata.asmlists[al_dwarf_aranges].concat(tai_const.Create_16bit_unaligned(0));
  2128. {$endif i8086}
  2129. end;
  2130. end;
  2131. { Don't write the funcretsym explicitly, it's also in the
  2132. localsymtable and/or parasymtable.
  2133. }
  2134. finish_entry;
  2135. if assigned(def.parast) then
  2136. begin
  2137. { First insert self, because gdb uses the fact whether or not the
  2138. first parameter of a method is artificial to distinguish static
  2139. from regular methods. }
  2140. { fortunately, self is the always the first parameter in the
  2141. paralist, since it has the lowest paranr. Note that this is not
  2142. true for Objective-C, but those methods are detected in
  2143. another way (by reading the ObjC run time information) }
  2144. write_symtable_parasyms(current_asmdata.asmlists[al_dwarf_info],def.paras);
  2145. end;
  2146. { local type defs and vars should not be written
  2147. inside the main proc }
  2148. if in_currentunit and
  2149. assigned(def.localst) and
  2150. (def.localst.symtabletype=localsymtable) then
  2151. write_symtable_syms(current_asmdata.asmlists[al_dwarf_info],def.localst);
  2152. { last write the types from this procdef }
  2153. if assigned(def.parast) then
  2154. write_symtable_defs(current_asmdata.asmlists[al_dwarf_info],def.parast);
  2155. { only try to write the localst if the routine is implemented here }
  2156. if in_currentunit and
  2157. assigned(def.localst) and
  2158. (def.localst.symtabletype=localsymtable) then
  2159. begin
  2160. write_symtable_defs(current_asmdata.asmlists[al_dwarf_info],def.localst);
  2161. { Write nested procedures -- disabled, see scope check at the
  2162. beginning; currently, these are still written in the global
  2163. scope. }
  2164. // write_symtable_procdefs(current_asmdata.asmlists[al_dwarf_info],def.localst);
  2165. end;
  2166. finish_children;
  2167. end;
  2168. function TDebugInfoDwarf.get_symlist_sym_offset(symlist: ppropaccesslistitem; out sym: tabstractvarsym; out offset: pint): boolean;
  2169. var
  2170. elesize : pint;
  2171. currdef : tdef;
  2172. indirection: boolean;
  2173. begin
  2174. result:=false;
  2175. if not assigned(symlist) then
  2176. exit;
  2177. sym:=nil;
  2178. offset:=0;
  2179. currdef:=nil;
  2180. indirection:=false;
  2181. repeat
  2182. case symlist^.sltype of
  2183. sl_load:
  2184. begin
  2185. if assigned(sym) then
  2186. internalerror(2009031203);
  2187. if not(symlist^.sym.typ in [paravarsym,localvarsym,staticvarsym,fieldvarsym]) then
  2188. { can't handle... }
  2189. exit;
  2190. sym:=tabstractvarsym(symlist^.sym);
  2191. currdef:=tabstractvarsym(sym).vardef;
  2192. if ((sym.typ=paravarsym) and
  2193. paramanager.push_addr_param(tparavarsym(sym).varspez,sym.vardef,tprocdef(sym.owner.defowner).proccalloption)) then
  2194. indirection:=true;
  2195. end;
  2196. sl_subscript:
  2197. begin
  2198. if not assigned(currdef) then
  2199. internalerror(2009031301);
  2200. if (symlist^.sym.typ<>fieldvarsym) then
  2201. internalerror(2009031202);
  2202. { can't handle offsets with indirections yet }
  2203. if indirection then
  2204. exit;
  2205. if is_packed_record_or_object(currdef) then
  2206. begin
  2207. { can't calculate the address of a non-byte aligned field }
  2208. if (tfieldvarsym(symlist^.sym).fieldoffset mod 8) <> 0 then
  2209. exit;
  2210. inc(offset,tfieldvarsym(symlist^.sym).fieldoffset div 8)
  2211. end
  2212. else
  2213. inc(offset,tfieldvarsym(symlist^.sym).fieldoffset);
  2214. currdef:=tfieldvarsym(symlist^.sym).vardef;
  2215. end;
  2216. sl_absolutetype,
  2217. sl_typeconv:
  2218. begin
  2219. currdef:=symlist^.def;
  2220. { ignore, these don't change the address }
  2221. end;
  2222. sl_vec:
  2223. begin
  2224. if not assigned(currdef) or
  2225. (currdef.typ<>arraydef) then
  2226. internalerror(2009031201);
  2227. { can't handle offsets with indirections yet }
  2228. if indirection then
  2229. exit;
  2230. if not is_packed_array(currdef) then
  2231. elesize:=tarraydef(currdef).elesize
  2232. else
  2233. begin
  2234. elesize:=tarraydef(currdef).elepackedbitsize;
  2235. { can't calculate the address of a non-byte aligned element }
  2236. if (elesize mod 8)<>0 then
  2237. exit;
  2238. elesize:=elesize div 8;
  2239. end;
  2240. inc(offset,(symlist^.value.svalue-tarraydef(currdef).lowrange)*elesize);
  2241. currdef:=tarraydef(currdef).elementdef;
  2242. end;
  2243. else
  2244. internalerror(2009031401);
  2245. end;
  2246. symlist:=symlist^.next;
  2247. until not assigned(symlist);
  2248. if not assigned(sym) then
  2249. internalerror(2009031205);
  2250. result:=true;
  2251. end;
  2252. procedure TDebugInfoDwarf.appendsym_var(list:TAsmList;sym:tabstractnormalvarsym);
  2253. begin
  2254. appendsym_var_with_name_type_offset(list,sym,symname(sym, false),sym.vardef,0,[]);
  2255. end;
  2256. procedure TDebugInfoDwarf.appendsym_var_with_name_type_offset(list:TAsmList; sym:tabstractnormalvarsym; const name: string; def: tdef; offset: pint; const flags: tdwarfvarsymflags);
  2257. var
  2258. templist : TAsmList;
  2259. blocksize,size_of_int : longint;
  2260. tag : tdwarf_tag;
  2261. has_high_reg : boolean;
  2262. dreg,dreghigh : shortint;
  2263. {$ifdef i8086}
  2264. has_segment_sym_name : boolean=false;
  2265. segment_sym_name : TSymStr='';
  2266. segment_reg: TRegister=NR_NO;
  2267. {$endif i8086}
  2268. begin
  2269. blocksize:=0;
  2270. dreghigh:=0;
  2271. { external symbols can't be resolved at link time, so we
  2272. can't generate stabs for them
  2273. not sure if this applies to dwarf as well (FK)
  2274. }
  2275. if vo_is_external in sym.varoptions then
  2276. exit;
  2277. { There is no space allocated for not referenced locals }
  2278. if (sym.owner.symtabletype=localsymtable) and (sym.refs=0) then
  2279. exit;
  2280. templist:=TAsmList.create;
  2281. case sym.localloc.loc of
  2282. LOC_REGISTER,
  2283. LOC_CREGISTER,
  2284. LOC_MMREGISTER,
  2285. LOC_CMMREGISTER,
  2286. LOC_FPUREGISTER,
  2287. LOC_CFPUREGISTER :
  2288. begin
  2289. { dwarf_reg_no_error might return -1
  2290. in case the register variable has been optimized out }
  2291. dreg:=dwarf_reg_no_error(sym.localloc.register);
  2292. has_high_reg:=(sym.localloc.loc in [LOC_REGISTER,LOC_CREGISTER]) and (sym.localloc.registerhi<>NR_NO);
  2293. if has_high_reg then
  2294. dreghigh:=dwarf_reg_no_error(sym.localloc.registerhi);
  2295. if dreghigh=-1 then
  2296. has_high_reg:=false;
  2297. if (sym.localloc.loc in [LOC_REGISTER,LOC_CREGISTER]) and
  2298. (sym.typ=paravarsym) and
  2299. paramanager.push_addr_param(sym.varspez,sym.vardef,tprocdef(sym.owner.defowner).proccalloption) and
  2300. not(vo_has_local_copy in sym.varoptions) and
  2301. not is_open_string(sym.vardef) and (dreg>=0) then
  2302. begin
  2303. templist.concat(tai_const.create_8bit(ord(DW_OP_bregx)));
  2304. templist.concat(tai_const.create_uleb128bit(dreg));
  2305. templist.concat(tai_const.create_sleb128bit(0));
  2306. blocksize:=1+Lengthuleb128(dreg)+LengthSleb128(0);
  2307. end
  2308. else
  2309. begin
  2310. if has_high_reg then
  2311. begin
  2312. templist.concat(tai_comment.create(strpnew('high:low reg pair variable')));
  2313. size_of_int:=sizeof(aint);
  2314. templist.concat(tai_const.create_8bit(ord(DW_OP_regx)));
  2315. templist.concat(tai_const.create_uleb128bit(dreg));
  2316. blocksize:=1+Lengthuleb128(dreg);
  2317. templist.concat(tai_const.create_8bit(ord(DW_OP_piece)));
  2318. templist.concat(tai_const.create_uleb128bit(size_of_int));
  2319. blocksize:=blocksize+1+Lengthuleb128(size_of_int);
  2320. templist.concat(tai_const.create_8bit(ord(DW_OP_regx)));
  2321. templist.concat(tai_const.create_uleb128bit(dreghigh));
  2322. blocksize:=blocksize+1+Lengthuleb128(dreghigh);
  2323. templist.concat(tai_const.create_8bit(ord(DW_OP_piece)));
  2324. templist.concat(tai_const.create_uleb128bit(size_of_int));
  2325. blocksize:=blocksize+1+Lengthuleb128(size_of_int);
  2326. end
  2327. else if (dreg>=0) then
  2328. begin
  2329. templist.concat(tai_const.create_8bit(ord(DW_OP_regx)));
  2330. templist.concat(tai_const.create_uleb128bit(dreg));
  2331. blocksize:=1+Lengthuleb128(dreg);
  2332. end;
  2333. end;
  2334. end;
  2335. else
  2336. begin
  2337. case sym.typ of
  2338. staticvarsym:
  2339. begin
  2340. if (vo_is_thread_var in sym.varoptions) then
  2341. begin
  2342. { TODO: !!! FIXME: dwarf for thread vars !!!}
  2343. { This is only a minimal change to at least be able to get a value
  2344. in only one thread is present PM 2014-11-21, like for stabs format }
  2345. templist.concat(tai_const.create_8bit(ord(DW_OP_addr)));
  2346. templist.concat(tai_const.Create_type_name(aitconst_ptr_unaligned,sym.mangledname,
  2347. offset+sizeof(pint)));
  2348. blocksize:=1+sizeof(puint);
  2349. end
  2350. else
  2351. begin
  2352. templist.concat(tai_const.create_8bit(ord(DW_OP_addr)));
  2353. templist.concat(tai_const.Create_type_name(aitconst_ptr_unaligned,sym.mangledname,offset));
  2354. blocksize:=1+sizeof(puint);
  2355. {$ifdef i8086}
  2356. segment_sym_name:=sym.mangledname;
  2357. has_segment_sym_name:=true;
  2358. {$endif i8086}
  2359. end;
  2360. end;
  2361. paravarsym,
  2362. localvarsym:
  2363. begin
  2364. { Happens when writing debug info for paras of procdefs not
  2365. implemented in the current module. Can't add a general check
  2366. for LOC_INVALID above, because staticvarsyms may also have it.
  2367. }
  2368. if sym.localloc.loc<> LOC_INVALID then
  2369. begin
  2370. if is_fbreg(sym.localloc.reference.base) then
  2371. begin
  2372. templist.concat(tai_const.create_8bit(ord(DW_OP_fbreg)));
  2373. templist.concat(tai_const.create_sleb128bit(sym.localloc.reference.offset+offset));
  2374. blocksize:=1+Lengthsleb128(sym.localloc.reference.offset+offset);
  2375. end
  2376. else
  2377. begin
  2378. dreg:=dwarf_reg(sym.localloc.reference.base);
  2379. if dreg<=31 then
  2380. begin
  2381. templist.concat(tai_const.create_8bit(ord(DW_OP_breg0)+dreg));
  2382. templist.concat(tai_const.create_sleb128bit(sym.localloc.reference.offset+offset));
  2383. blocksize:=1+Lengthsleb128(sym.localloc.reference.offset+offset);
  2384. end
  2385. else
  2386. begin
  2387. templist.concat(tai_const.create_8bit(ord(DW_OP_bregx)));
  2388. templist.concat(tai_const.create_uleb128bit(dreg));
  2389. templist.concat(tai_const.create_sleb128bit(sym.localloc.reference.offset+offset));
  2390. blocksize:=1+Lengthuleb128(dreg)+LengthSleb128(sym.localloc.reference.offset+offset);
  2391. end;
  2392. end;
  2393. {$ifdef i8086}
  2394. segment_reg:=sym.localloc.reference.segment;
  2395. {$endif i8086}
  2396. {$ifndef gdb_supports_DW_AT_variable_parameter}
  2397. { Parameters which are passed by reference. (var and the like)
  2398. Hide the reference-pointer and dereference the pointer
  2399. in the DW_AT_location block.
  2400. }
  2401. if (sym.typ=paravarsym) and
  2402. paramanager.push_addr_param(sym.varspez,sym.vardef,tprocdef(sym.owner.defowner).proccalloption) and
  2403. not(vo_has_local_copy in sym.varoptions) and
  2404. not is_open_string(sym.vardef) then
  2405. begin
  2406. templist.concat(tai_const.create_8bit(ord(DW_OP_deref)));
  2407. inc(blocksize);
  2408. end
  2409. {$endif not gdb_supports_DW_AT_variable_parameter}
  2410. end;
  2411. end
  2412. else
  2413. internalerror(200601288);
  2414. end;
  2415. end;
  2416. end;
  2417. { function results must not be added to the parameter list,
  2418. as they are not part of the signature of the function
  2419. (gdb automatically adds them according to the ABI specifications
  2420. when calling the function)
  2421. }
  2422. if (sym.typ=paravarsym) and
  2423. not(dvf_force_local_var in flags) and
  2424. not(vo_is_funcret in sym.varoptions) then
  2425. tag:=DW_TAG_formal_parameter
  2426. else
  2427. tag:=DW_TAG_variable;
  2428. { must be parasym of externally implemented procdef, but
  2429. the parasymtable can con also contain e.g. absolutevarsyms
  2430. -> check symtabletype}
  2431. if (sym.owner.symtabletype=parasymtable) and
  2432. (sym.localloc.loc=LOC_INVALID) then
  2433. begin
  2434. if (sym.owner.symtabletype<>parasymtable) then
  2435. internalerror(2009101001);
  2436. append_entry(tag,false,[
  2437. DW_AT_name,DW_FORM_string,name+#0
  2438. {
  2439. DW_AT_decl_file,DW_FORM_data1,0,
  2440. DW_AT_decl_line,DW_FORM_data1,
  2441. }
  2442. ])
  2443. end
  2444. else if not(sym.localloc.loc in [LOC_REGISTER,LOC_CREGISTER,LOC_MMREGISTER,
  2445. LOC_CMMREGISTER,LOC_FPUREGISTER,LOC_CFPUREGISTER]) and
  2446. ((sym.owner.symtabletype = globalsymtable) or
  2447. (sp_static in sym.symoptions) or
  2448. (vo_is_public in sym.varoptions)) then
  2449. append_entry(tag,false,[
  2450. DW_AT_name,DW_FORM_string,name+#0,
  2451. {
  2452. DW_AT_decl_file,DW_FORM_data1,0,
  2453. DW_AT_decl_line,DW_FORM_data1,
  2454. }
  2455. DW_AT_external,DW_FORM_flag,true,
  2456. { data continues below }
  2457. DW_AT_location,DW_FORM_block1,blocksize
  2458. ])
  2459. {$ifdef gdb_supports_DW_AT_variable_parameter}
  2460. else if (sym.typ=paravarsym) and
  2461. paramanager.push_addr_param(sym.varspez,sym.vardef,tprocdef(sym.owner.defowner).proccalloption) and
  2462. not(vo_has_local_copy in sym.varoptions) and
  2463. not is_open_string(sym.vardef) then
  2464. append_entry(tag,false,[
  2465. DW_AT_name,DW_FORM_string,name+#0,
  2466. DW_AT_variable_parameter,DW_FORM_flag,true,
  2467. {
  2468. DW_AT_decl_file,DW_FORM_data1,0,
  2469. DW_AT_decl_line,DW_FORM_data1,
  2470. }
  2471. { data continues below }
  2472. DW_AT_location,DW_FORM_block1,blocksize
  2473. ])
  2474. {$endif gdb_supports_DW_AT_variable_parameter}
  2475. else
  2476. append_entry(tag,false,[
  2477. DW_AT_name,DW_FORM_string,name+#0,
  2478. {
  2479. DW_AT_decl_file,DW_FORM_data1,0,
  2480. DW_AT_decl_line,DW_FORM_data1,
  2481. }
  2482. { data continues below }
  2483. DW_AT_location,DW_FORM_block1,blocksize
  2484. ]);
  2485. { append block data }
  2486. current_asmdata.asmlists[al_dwarf_info].concatlist(templist);
  2487. { Mark self as artificial for methods, because gdb uses the fact
  2488. whether or not the first parameter of a method is artificial to
  2489. distinguish regular from static methods (since there are no
  2490. no vo_is_self parameters for static methods, we don't have to check
  2491. that). }
  2492. if (vo_is_self in sym.varoptions) then
  2493. append_attribute(DW_AT_artificial,DW_FORM_flag,[true]);
  2494. append_labelentry_ref(DW_AT_type,def_dwarf_lab(def));
  2495. {$ifdef i8086}
  2496. if has_segment_sym_name then
  2497. append_seg_name(segment_sym_name)
  2498. else if segment_reg<>NR_NO then
  2499. append_seg_reg(segment_reg);
  2500. {$endif i8086}
  2501. templist.free;
  2502. finish_entry;
  2503. end;
  2504. procedure TDebugInfoDwarf.appendsym_staticvar(list:TAsmList;sym:tstaticvarsym);
  2505. begin
  2506. appendsym_var(list,sym);
  2507. end;
  2508. procedure TDebugInfoDwarf.appendsym_localvar(list:TAsmList;sym:tlocalvarsym);
  2509. begin
  2510. appendsym_var(list,sym);
  2511. end;
  2512. procedure TDebugInfoDwarf.appendsym_paravar(list:TAsmList;sym:tparavarsym);
  2513. begin
  2514. appendsym_var(list,sym);
  2515. end;
  2516. procedure TDebugInfoDwarf.appendsym_fieldvar(list:TAsmList;sym: tfieldvarsym);
  2517. begin
  2518. appendsym_fieldvar_with_name_offset(list,sym,symname(sym, false),sym.vardef,0);
  2519. end;
  2520. procedure TDebugInfoDwarf.appendsym_fieldvar_with_name_offset(list:TAsmList;sym: tfieldvarsym;const name: string; def: tdef; offset: pint);
  2521. var
  2522. bitoffset,
  2523. fieldoffset,
  2524. fieldnatsize: asizeint;
  2525. begin
  2526. if (sp_static in sym.symoptions) or
  2527. (sym.visibility=vis_hidden) then
  2528. exit;
  2529. if (tabstractrecordsymtable(sym.owner).usefieldalignment<>bit_alignment) or
  2530. { only ordinals are bitpacked }
  2531. not is_ordinal(sym.vardef) then
  2532. begin
  2533. { other kinds of fields can however also appear in a bitpacked }
  2534. { record, and then their offset is also specified in bits rather }
  2535. { than in bytes }
  2536. if (tabstractrecordsymtable(sym.owner).usefieldalignment<>bit_alignment) then
  2537. fieldoffset:=sym.fieldoffset
  2538. else
  2539. fieldoffset:=sym.fieldoffset div 8;
  2540. inc(fieldoffset,offset);
  2541. append_entry(DW_TAG_member,false,[
  2542. DW_AT_name,DW_FORM_string,name+#0,
  2543. DW_AT_data_member_location,DW_FORM_block1,1+lengthuleb128(fieldoffset)
  2544. ]);
  2545. end
  2546. else
  2547. begin
  2548. if (sym.vardef.packedbitsize > 255) then
  2549. internalerror(2007061201);
  2550. { we don't bitpack according to the ABI, but as close as }
  2551. { possible, i.e., equivalent to gcc's }
  2552. { __attribute__((__packed__)), which is also what gpc }
  2553. { does. }
  2554. fieldnatsize:=max(sizeof(pint),sym.vardef.size);
  2555. fieldoffset:=(sym.fieldoffset div (fieldnatsize*8)) * fieldnatsize;
  2556. inc(fieldoffset,offset);
  2557. bitoffset:=sym.fieldoffset mod (fieldnatsize*8);
  2558. if (target_info.endian=endian_little) then
  2559. bitoffset:=(fieldnatsize*8)-bitoffset-sym.vardef.packedbitsize;
  2560. append_entry(DW_TAG_member,false,[
  2561. DW_AT_name,DW_FORM_string,symname(sym, false)+#0,
  2562. { gcc also generates both a bit and byte size attribute }
  2563. { we don't support ordinals >= 256 bits }
  2564. DW_AT_byte_size,DW_FORM_data1,fieldnatsize,
  2565. { nor >= 256 bits (not yet, anyway, see IE above) }
  2566. DW_AT_bit_size,DW_FORM_data1,sym.vardef.packedbitsize,
  2567. { data1 and data2 are unsigned, bitoffset can also be negative }
  2568. DW_AT_bit_offset,DW_FORM_data4,bitoffset,
  2569. DW_AT_data_member_location,DW_FORM_block1,1+lengthuleb128(fieldoffset)
  2570. ]);
  2571. end;
  2572. current_asmdata.asmlists[al_dwarf_info].concat(tai_const.create_8bit(ord(DW_OP_plus_uconst)));
  2573. current_asmdata.asmlists[al_dwarf_info].concat(tai_const.create_uleb128bit(fieldoffset));
  2574. if (sym.owner.symtabletype in [objectsymtable,recordsymtable]) then
  2575. append_visibility(sym.visibility);
  2576. append_labelentry_ref(DW_AT_type,def_dwarf_lab(def));
  2577. finish_entry;
  2578. end;
  2579. procedure TDebugInfoDwarf.appendsym_const(list:TAsmList;sym:tconstsym);
  2580. begin
  2581. appendsym_const_member(list,sym,false);
  2582. end;
  2583. procedure TDebugInfoDwarf.appendsym_const_member(list:TAsmList;sym:tconstsym;ismember:boolean);
  2584. var
  2585. i,
  2586. size: aint;
  2587. usedef: tdef;
  2588. begin
  2589. { These are default values of parameters. These should be encoded
  2590. via DW_AT_default_value, not as a separate sym. Moreover, their
  2591. type is not available when writing the debug info for external
  2592. procedures.
  2593. }
  2594. if (sym.owner.symtabletype=parasymtable) then
  2595. exit;
  2596. if ismember then
  2597. append_entry(DW_TAG_member,false,[
  2598. DW_AT_name,DW_FORM_string,symname(sym, false)+#0,
  2599. { The DW_AT_declaration tag is invalid according to the DWARF specifications.
  2600. But gcc adds this to static const members and gdb checks
  2601. for this flag. So we have to set it also.
  2602. }
  2603. DW_AT_declaration,DW_FORM_flag,true,
  2604. DW_AT_external,DW_FORM_flag,true
  2605. ])
  2606. else
  2607. append_entry(DW_TAG_variable,false,[
  2608. DW_AT_name,DW_FORM_string,symname(sym, false)+#0
  2609. ]);
  2610. { for string constants, constdef isn't set because they have no real type }
  2611. case sym.consttyp of
  2612. conststring:
  2613. begin
  2614. { if DW_FORM_string is used below one day, this usedef should
  2615. probably become nil }
  2616. { note: < 255 instead of <= 255 because we have to store the
  2617. entire length of the string as well, and 256 does not fit in
  2618. a byte }
  2619. if (sym.value.len<255) then
  2620. usedef:=cshortstringtype
  2621. else
  2622. usedef:=clongstringtype;
  2623. end;
  2624. constresourcestring,
  2625. constwstring:
  2626. usedef:=nil;
  2627. else
  2628. usedef:=sym.constdef;
  2629. end;
  2630. if assigned(usedef) then
  2631. append_labelentry_ref(DW_AT_type,def_dwarf_lab(usedef));
  2632. AddConstToAbbrev(ord(DW_AT_const_value));
  2633. case sym.consttyp of
  2634. conststring:
  2635. begin
  2636. { DW_FORM_string isn't supported yet by the Pascal value printer
  2637. -> create a string using raw bytes }
  2638. if (sym.value.len<255) then
  2639. begin
  2640. AddConstToAbbrev(ord(DW_FORM_block1));
  2641. current_asmdata.asmlists[al_dwarf_info].concat(tai_const.create_8bit(sym.value.len+1));
  2642. current_asmdata.asmlists[al_dwarf_info].concat(tai_const.create_8bit(sym.value.len));
  2643. end
  2644. else
  2645. begin
  2646. AddConstToAbbrev(ord(DW_FORM_block));
  2647. current_asmdata.asmlists[al_dwarf_info].concat(tai_const.create_uleb128bit(sym.value.len+sizesinttype.size));
  2648. current_asmdata.asmlists[al_dwarf_info].concat(tai_const.Create_sizeint_unaligned(sym.value.len));
  2649. end;
  2650. i:=0;
  2651. size:=sym.value.len;
  2652. while(i<size) do
  2653. begin
  2654. current_asmdata.asmlists[al_dwarf_info].concat(tai_const.create_8bit((pbyte(sym.value.valueptr+i)^)));
  2655. inc(i);
  2656. end;
  2657. end;
  2658. constguid,
  2659. constset:
  2660. begin
  2661. AddConstToAbbrev(ord(DW_FORM_block1));
  2662. current_asmdata.asmlists[al_dwarf_info].concat(tai_const.create_8bit(usedef.size));
  2663. i:=0;
  2664. size:=sym.constdef.size;
  2665. while (i<size) do
  2666. begin
  2667. current_asmdata.asmlists[al_dwarf_info].concat(tai_const.create_8bit((pbyte(sym.value.valueptr+i)^)));
  2668. inc(i);
  2669. end;
  2670. end;
  2671. constwstring,
  2672. constresourcestring:
  2673. begin
  2674. { write dummy for now }
  2675. AddConstToAbbrev(ord(DW_FORM_string));
  2676. current_asmdata.asmlists[al_dwarf_info].concat(tai_string.create(''));
  2677. current_asmdata.asmlists[al_dwarf_info].concat(tai_const.create_8bit(0));
  2678. end;
  2679. constord:
  2680. begin
  2681. if (sym.value.valueord<0) then
  2682. begin
  2683. AddConstToAbbrev(ord(DW_FORM_sdata));
  2684. current_asmdata.asmlists[al_dwarf_info].concat(tai_const.create_sleb128bit(sym.value.valueord.svalue));
  2685. end
  2686. else
  2687. begin
  2688. AddConstToAbbrev(ord(DW_FORM_udata));
  2689. current_asmdata.asmlists[al_dwarf_info].concat(tai_const.create_uleb128bit(sym.value.valueord.uvalue));
  2690. end;
  2691. end;
  2692. constnil:
  2693. begin
  2694. {$ifdef cpu64bitaddr}
  2695. AddConstToAbbrev(ord(DW_FORM_data8));
  2696. current_asmdata.asmlists[al_dwarf_info].concat(tai_const.create_64bit_unaligned(0));
  2697. {$else cpu64bitaddr}
  2698. AddConstToAbbrev(ord(DW_FORM_data4));
  2699. current_asmdata.asmlists[al_dwarf_info].concat(tai_const.create_32bit_unaligned(0));
  2700. {$endif cpu64bitaddr}
  2701. end;
  2702. constpointer:
  2703. begin
  2704. {$ifdef cpu64bitaddr}
  2705. AddConstToAbbrev(ord(DW_FORM_data8));
  2706. current_asmdata.asmlists[al_dwarf_info].concat(tai_const.create_64bit_unaligned(int64(sym.value.valueordptr)));
  2707. {$else cpu64bitaddr}
  2708. AddConstToAbbrev(ord(DW_FORM_data4));
  2709. current_asmdata.asmlists[al_dwarf_info].concat(tai_const.create_32bit_unaligned(longint(sym.value.valueordptr)));
  2710. {$endif cpu64bitaddr}
  2711. end;
  2712. constreal:
  2713. begin
  2714. AddConstToAbbrev(ord(DW_FORM_block1));
  2715. case tfloatdef(sym.constdef).floattype of
  2716. s32real:
  2717. begin
  2718. current_asmdata.asmlists[al_dwarf_info].concat(tai_const.create_8bit(4));
  2719. current_asmdata.asmlists[al_dwarf_info].concat(tai_realconst.create_s32real(pbestreal(sym.value.valueptr)^));
  2720. end;
  2721. s64real:
  2722. begin
  2723. current_asmdata.asmlists[al_dwarf_info].concat(tai_const.create_8bit(8));
  2724. current_asmdata.asmlists[al_dwarf_info].concat(tai_realconst.create_s64real(pbestreal(sym.value.valueptr)^));
  2725. end;
  2726. s64comp,
  2727. s64currency:
  2728. begin
  2729. current_asmdata.asmlists[al_dwarf_info].concat(tai_const.create_8bit(8));
  2730. current_asmdata.asmlists[al_dwarf_info].concat(tai_const.create_64bit_unaligned(trunc(pbestreal(sym.value.valueptr)^)));
  2731. end;
  2732. s80real,
  2733. sc80real:
  2734. begin
  2735. current_asmdata.asmlists[al_dwarf_info].concat(tai_const.create_8bit(sym.constdef.size));
  2736. current_asmdata.asmlists[al_dwarf_info].concat(tai_realconst.create_s80real(pextended(sym.value.valueptr)^,sym.constdef.size));
  2737. end;
  2738. else
  2739. internalerror(200601291);
  2740. end;
  2741. end;
  2742. else
  2743. internalerror(200601292);
  2744. end;
  2745. finish_entry;
  2746. end;
  2747. procedure TDebugInfoDwarf.appendsym_label(list:TAsmList;sym: tlabelsym);
  2748. begin
  2749. { ignore label syms for now, the problem is that a label sym
  2750. can have more than one label associated e.g. in case of
  2751. an inline procedure expansion }
  2752. end;
  2753. procedure TDebugInfoDwarf.appendsym_property(list:TAsmList;sym: tpropertysym);
  2754. var
  2755. symlist: ppropaccesslistitem;
  2756. tosym: tabstractvarsym;
  2757. offset: pint;
  2758. begin
  2759. if assigned(sym.propaccesslist[palt_read]) and
  2760. not assigned(sym.propaccesslist[palt_read].procdef) then
  2761. symlist:=sym.propaccesslist[palt_read].firstsym
  2762. else
  2763. { can't handle }
  2764. exit;
  2765. if not get_symlist_sym_offset(symlist,tosym,offset) then
  2766. exit;
  2767. if not (tosym.owner.symtabletype in [objectsymtable,recordsymtable]) then
  2768. begin
  2769. if (tosym.typ=fieldvarsym) then
  2770. internalerror(2009031404);
  2771. appendsym_var_with_name_type_offset(list,tabstractnormalvarsym(tosym),symname(sym, false),sym.propdef,offset,[])
  2772. end
  2773. else
  2774. appendsym_fieldvar_with_name_offset(list,tfieldvarsym(tosym),symname(sym, false),sym.propdef,offset)
  2775. end;
  2776. function TDebugInfoDwarf.symdebugname(sym: tsym): String;
  2777. begin
  2778. result := sym.name;
  2779. end;
  2780. procedure TDebugInfoDwarf.appendsym_type(list:TAsmList;sym: ttypesym);
  2781. begin
  2782. { just queue the def if needed, beforeappenddef will
  2783. emit the typedef if necessary }
  2784. def_dwarf_lab(sym.typedef);
  2785. end;
  2786. procedure TDebugInfoDwarf.appendsym_absolute(list:TAsmList;sym:tabsolutevarsym);
  2787. var
  2788. templist : TAsmList;
  2789. blocksize : longint;
  2790. symlist : ppropaccesslistitem;
  2791. tosym: tabstractvarsym;
  2792. offset: pint;
  2793. flags: tdwarfvarsymflags;
  2794. begin
  2795. templist:=TAsmList.create;
  2796. case tabsolutevarsym(sym).abstyp of
  2797. toaddr :
  2798. begin
  2799. { MWE: replaced ifdef i368 }
  2800. (*
  2801. if target_cpu = cpu_i386 then
  2802. begin
  2803. { in theory, we could write a DW_AT_segment entry here for sym.absseg,
  2804. however I doubt that gdb supports this (FK) }
  2805. end;
  2806. *)
  2807. templist.concat(tai_const.create_8bit(3));
  2808. templist.concat(tai_const.create_int_dataptr_unaligned(sym.addroffset));
  2809. blocksize:=1+sizeof(puint);
  2810. end;
  2811. toasm :
  2812. begin
  2813. templist.concat(tai_const.create_8bit(3));
  2814. templist.concat(tai_const.create_type_name(aitconst_ptr_unaligned,sym.mangledname,0));
  2815. blocksize:=1+sizeof(puint);
  2816. end;
  2817. tovar:
  2818. begin
  2819. symlist:=tabsolutevarsym(sym).ref.firstsym;
  2820. if get_symlist_sym_offset(symlist,tosym,offset) then
  2821. begin
  2822. if (tosym.typ=fieldvarsym) then
  2823. internalerror(2009031402);
  2824. flags:=[];
  2825. if (sym.owner.symtabletype=localsymtable) then
  2826. include(flags,dvf_force_local_var);
  2827. appendsym_var_with_name_type_offset(list,tabstractnormalvarsym(tosym),symname(sym, false),tabstractvarsym(sym).vardef,offset,flags);
  2828. end;
  2829. templist.free;
  2830. exit;
  2831. end;
  2832. else
  2833. internalerror(2013120111);
  2834. end;
  2835. append_entry(DW_TAG_variable,false,[
  2836. DW_AT_name,DW_FORM_string,symname(sym, false)+#0,
  2837. {
  2838. DW_AT_decl_file,DW_FORM_data1,0,
  2839. DW_AT_decl_line,DW_FORM_data1,
  2840. }
  2841. DW_AT_external,DW_FORM_flag,true,
  2842. { data continues below }
  2843. DW_AT_location,DW_FORM_block1,blocksize
  2844. ]);
  2845. { append block data }
  2846. current_asmdata.asmlists[al_dwarf_info].concatlist(templist);
  2847. append_labelentry_ref(DW_AT_type,def_dwarf_lab(sym.vardef));
  2848. templist.free;
  2849. finish_entry;
  2850. end;
  2851. procedure TDebugInfoDwarf.beforeappendsym(list:TAsmList;sym:tsym);
  2852. begin
  2853. current_asmdata.asmlists[al_dwarf_info].concat(tai_comment.Create(strpnew('Symbol '+symname(sym, true))));
  2854. end;
  2855. procedure TDebugInfoDwarf.insertmoduleinfo;
  2856. var
  2857. templist: TAsmList;
  2858. linelist: TAsmList;
  2859. lbl : tasmlabel;
  2860. n,m : Integer;
  2861. ditem : TDirIndexItem;
  2862. fitem : TFileIndexItem;
  2863. flist : TFPList;
  2864. dbgname : String;
  2865. begin
  2866. { insert DEBUGSTART and DEBUGEND labels }
  2867. dbgname:=make_mangledname('DEBUGSTART',current_module.localsymtable,'');
  2868. { Darwin's linker does not like two global labels both pointing to the
  2869. end of a section, which can happen in case of units without code ->
  2870. make them local; we don't need the debugtable stuff there either,
  2871. so it doesn't matter that they are not global.
  2872. }
  2873. if (target_info.system in systems_darwin) then
  2874. dbgname:='L'+dbgname;
  2875. new_section(current_asmdata.asmlists[al_start],sec_code,dbgname,0,secorder_begin);
  2876. if not(target_info.system in systems_darwin) then
  2877. current_asmdata.asmlists[al_start].concat(tai_symbol.Createname_global(dbgname,AT_METADATA,0,voidpointertype))
  2878. else
  2879. current_asmdata.asmlists[al_start].concat(tai_symbol.Createname(dbgname,AT_METADATA,0,voidpointertype));
  2880. dbgname:=make_mangledname('DEBUGEND',current_module.localsymtable,'');
  2881. { See above. }
  2882. if (target_info.system in systems_darwin) then
  2883. dbgname:='L'+dbgname;
  2884. new_section(current_asmdata.asmlists[al_end],sec_code,dbgname,0,secorder_end);
  2885. if not(target_info.system in systems_darwin) then
  2886. current_asmdata.asmlists[al_end].concat(tai_symbol.Createname_global(dbgname,AT_METADATA,0,voidpointertype))
  2887. else
  2888. current_asmdata.asmlists[al_end].concat(tai_symbol.Createname(dbgname,AT_METADATA,0,voidpointertype));
  2889. { insert .Ldebug_abbrev0 label }
  2890. templist:=TAsmList.create;
  2891. new_section(templist,sec_debug_abbrev,'',0);
  2892. templist.concat(tai_symbol.createname(target_asm.labelprefix+'debug_abbrevsection0',AT_METADATA,0,voidpointertype));
  2893. { add any extra stuff which needs to be in the abbrev section, but before }
  2894. { the actual abbreviations, in between the symbol above and below, i.e. here }
  2895. templist.concat(tai_symbol.createname(target_asm.labelprefix+'debug_abbrev0',AT_METADATA,0,voidpointertype));
  2896. current_asmdata.asmlists[al_start].insertlist(templist);
  2897. templist.free;
  2898. { insert .Ldebug_line0 label }
  2899. templist:=TAsmList.create;
  2900. new_section(templist,sec_debug_line,'',0);
  2901. templist.concat(tai_symbol.createname(target_asm.labelprefix+'debug_linesection0',AT_METADATA,0,voidpointertype));
  2902. { add any extra stuff which needs to be in the line section, but before }
  2903. { the actual line info, in between the symbol above and below, i.e. here }
  2904. templist.concat(tai_symbol.createname(target_asm.labelprefix+'debug_line0',AT_METADATA,0,voidpointertype));
  2905. current_asmdata.asmlists[al_start].insertlist(templist);
  2906. templist.free;
  2907. { finalize line info if the unit doesn't contain any function/ }
  2908. { procedure/init/final code }
  2909. finish_lineinfo;
  2910. { debug line header }
  2911. linelist := current_asmdata.asmlists[al_dwarf_line];
  2912. new_section(linelist,sec_debug_line,'',0);
  2913. linelist.concat(tai_comment.Create(strpnew('=== header start ===')));
  2914. { size }
  2915. current_asmdata.getlabel(lbl,alt_dbgfile);
  2916. if use_64bit_headers then
  2917. linelist.concat(tai_const.create_32bit_unaligned(longint($FFFFFFFF)));
  2918. linelist.concat(tai_const.create_rel_sym(offsetreltype,
  2919. lbl,current_asmdata.DefineAsmSymbol(target_asm.labelprefix+'edebug_line0',AB_LOCAL,AT_METADATA,voidpointertype)));
  2920. linelist.concat(tai_label.create(lbl));
  2921. { version }
  2922. linelist.concat(tai_const.create_16bit_unaligned(dwarf_version));
  2923. { header length }
  2924. current_asmdata.getlabel(lbl,alt_dbgfile);
  2925. linelist.concat(tai_const.create_rel_sym(offsetreltype,
  2926. lbl,current_asmdata.DefineAsmSymbol(target_asm.labelprefix+'ehdebug_line0',AB_LOCAL,AT_METADATA,voidpointertype)));
  2927. linelist.concat(tai_label.create(lbl));
  2928. { minimum_instruction_length }
  2929. linelist.concat(tai_const.create_8bit(1));
  2930. { default_is_stmt }
  2931. linelist.concat(tai_const.create_8bit(1));
  2932. { line_base }
  2933. linelist.concat(tai_const.create_8bit(LINE_BASE));
  2934. { line_range }
  2935. { only line increase, no adress }
  2936. linelist.concat(tai_const.create_8bit(255));
  2937. { opcode_base }
  2938. linelist.concat(tai_const.create_8bit(OPCODE_BASE));
  2939. { standard_opcode_lengths }
  2940. { MWE: sigh... why adding the default lengths (and make those sizes sense with LEB encoding) }
  2941. { DW_LNS_copy }
  2942. linelist.concat(tai_const.create_8bit(0));
  2943. { DW_LNS_advance_pc }
  2944. linelist.concat(tai_const.create_8bit(1));
  2945. { DW_LNS_advance_line }
  2946. linelist.concat(tai_const.create_8bit(1));
  2947. { DW_LNS_set_file }
  2948. linelist.concat(tai_const.create_8bit(1));
  2949. { DW_LNS_set_column }
  2950. linelist.concat(tai_const.create_8bit(1));
  2951. { DW_LNS_negate_stmt }
  2952. linelist.concat(tai_const.create_8bit(0));
  2953. { DW_LNS_set_basic_block }
  2954. linelist.concat(tai_const.create_8bit(0));
  2955. { DW_LNS_const_add_pc }
  2956. linelist.concat(tai_const.create_8bit(0));
  2957. { DW_LNS_fixed_advance_pc }
  2958. linelist.concat(tai_const.create_8bit(1));
  2959. { DW_LNS_set_prologue_end }
  2960. linelist.concat(tai_const.create_8bit(0));
  2961. { DW_LNS_set_epilogue_begin }
  2962. linelist.concat(tai_const.create_8bit(0));
  2963. { DW_LNS_set_isa }
  2964. linelist.concat(tai_const.create_8bit(1));
  2965. { Create single list of filenames sorted in IndexNr }
  2966. flist:=TFPList.Create;
  2967. for n := 0 to dirlist.Count - 1 do
  2968. begin
  2969. ditem := TDirIndexItem(dirlist[n]);
  2970. for m := 0 to ditem.Files.Count - 1 do
  2971. flist.Add(ditem.Files[m]);
  2972. end;
  2973. flist.Sort(@FileListSortCompare);
  2974. { include_directories }
  2975. linelist.concat(tai_comment.Create(strpnew('include_directories')));
  2976. for n := 0 to dirlist.Count - 1 do
  2977. begin
  2978. ditem := TDirIndexItem(dirlist[n]);
  2979. if ditem.Name = '.' then
  2980. Continue;
  2981. { Write without trailing path delimiter and also don't prefix with ./ for current dir (already done while adding to dirlist }
  2982. linelist.concat(tai_string.create(ditem.Name+#0));
  2983. end;
  2984. linelist.concat(tai_const.create_8bit(0));
  2985. { file_names }
  2986. linelist.concat(tai_comment.Create(strpnew('file_names')));
  2987. for n := 0 to flist.Count - 1 do
  2988. begin
  2989. fitem := TFileIndexItem(flist[n]);
  2990. { file name }
  2991. linelist.concat(tai_string.create(fitem.Name+#0));
  2992. { directory index }
  2993. linelist.concat(tai_const.create_uleb128bit(fitem.DirIndex));
  2994. { last modification }
  2995. linelist.concat(tai_const.create_uleb128bit(0));
  2996. { file length }
  2997. linelist.concat(tai_const.create_uleb128bit(0));
  2998. end;
  2999. linelist.concat(tai_const.create_8bit(0));
  3000. { end of debug line header }
  3001. linelist.concat(tai_symbol.createname(target_asm.labelprefix+'ehdebug_line0',AT_METADATA,0,voidpointertype));
  3002. linelist.concat(tai_comment.Create(strpnew('=== header end ===')));
  3003. { add line program }
  3004. linelist.concatList(asmline);
  3005. { end of debug line table }
  3006. linelist.concat(tai_symbol.createname(target_asm.labelprefix+'edebug_line0',AT_METADATA,0,voidpointertype));
  3007. flist.free;
  3008. end;
  3009. procedure TDebugInfoDwarf.inserttypeinfo;
  3010. var
  3011. storefilepos : tfileposinfo;
  3012. lenstartlabel,arangestartlabel: tasmlabel;
  3013. i : longint;
  3014. def: tdef;
  3015. dbgname: string;
  3016. vardatatype: ttypesym;
  3017. bind: tasmsymbind;
  3018. lang: tdwarf_source_language;
  3019. begin
  3020. current_module.flags:=current_module.flags or uf_has_dwarf_debuginfo;
  3021. storefilepos:=current_filepos;
  3022. current_filepos:=current_module.mainfilepos;
  3023. if assigned(dwarflabels) then
  3024. internalerror(2015100301);
  3025. { one item per def, plus some extra space in case of nested types,
  3026. externally used types etc (it will grow further if necessary) }
  3027. i:=current_module.localsymtable.DefList.count*4;
  3028. if assigned(current_module.globalsymtable) then
  3029. inc(i,current_module.globalsymtable.DefList.count*2);
  3030. dwarflabels:=TDwarfLabHashSet.Create(i,true,false);
  3031. currabbrevnumber:=0;
  3032. defnumberlist:=TFPObjectList.create(false);
  3033. deftowritelist:=TFPObjectList.create(false);
  3034. { not exported (FK)
  3035. FILEREC
  3036. TEXTREC
  3037. }
  3038. vardatatype:=try_search_system_type('TVARDATA');
  3039. if assigned(vardatatype) then
  3040. vardatadef:=trecorddef(vardatatype.typedef);
  3041. { write start labels }
  3042. new_section(current_asmdata.asmlists[al_dwarf_info],sec_debug_info,'',0);
  3043. current_asmdata.asmlists[al_dwarf_info].concat(tai_symbol.createname(target_asm.labelprefix+'debug_info0',AT_METADATA,0,voidpointertype));
  3044. { start abbrev section }
  3045. new_section(current_asmdata.asmlists[al_dwarf_abbrev],sec_debug_abbrev,'',0);
  3046. if not(target_info.system in systems_darwin) then
  3047. begin
  3048. { start aranges section }
  3049. new_section(current_asmdata.asmlists[al_dwarf_aranges],sec_debug_aranges,'',0);
  3050. current_asmdata.getlabel(arangestartlabel,alt_dbgfile);
  3051. if use_64bit_headers then
  3052. current_asmdata.asmlists[al_dwarf_aranges].concat(tai_const.create_32bit_unaligned(longint($FFFFFFFF)));
  3053. current_asmdata.asmlists[al_dwarf_aranges].concat(tai_const.create_rel_sym(offsetreltype,
  3054. arangestartlabel,current_asmdata.DefineAsmSymbol(target_asm.labelprefix+'earanges0',AB_LOCAL,AT_METADATA,voidpointertype)));
  3055. current_asmdata.asmlists[al_dwarf_aranges].concat(tai_label.create(arangestartlabel));
  3056. current_asmdata.asmlists[al_dwarf_aranges].concat(tai_const.create_16bit_unaligned(2));
  3057. if not(tf_dwarf_relative_addresses in target_info.flags) then
  3058. current_asmdata.asmlists[al_dwarf_aranges].concat(tai_const.create_type_sym(offsetabstype,
  3059. current_asmdata.DefineAsmSymbol(target_asm.labelprefix+'debug_info0',AB_LOCAL,AT_METADATA,voidpointertype)))
  3060. else
  3061. current_asmdata.asmlists[al_dwarf_aranges].concat(tai_const.create_rel_sym(offsetreltype,
  3062. current_asmdata.DefineAsmSymbol(target_asm.labelprefix+'debug_infosection0',AB_LOCAL,AT_METADATA,voidpointertype),
  3063. current_asmdata.DefineAsmSymbol(target_asm.labelprefix+'debug_info0',AB_LOCAL,AT_METADATA,voidpointertype)));
  3064. {$ifdef i8086}
  3065. { address_size }
  3066. current_asmdata.asmlists[al_dwarf_aranges].concat(tai_const.create_8bit(4));
  3067. { segment_size }
  3068. current_asmdata.asmlists[al_dwarf_aranges].concat(tai_const.create_8bit(2));
  3069. { no alignment/padding bytes on i8086 for Open Watcom compatibility }
  3070. {$else i8086}
  3071. { address_size }
  3072. current_asmdata.asmlists[al_dwarf_aranges].concat(tai_const.create_8bit(sizeof(pint)));
  3073. { segment_size }
  3074. current_asmdata.asmlists[al_dwarf_aranges].concat(tai_const.create_8bit(0));
  3075. { alignment }
  3076. current_asmdata.asmlists[al_dwarf_aranges].concat(tai_const.create_32bit_unaligned(0));
  3077. {$endif i8086}
  3078. { start ranges section }
  3079. new_section(current_asmdata.asmlists[al_dwarf_ranges],sec_debug_ranges,'',0);
  3080. end;
  3081. { debug info header }
  3082. current_asmdata.getlabel(lenstartlabel,alt_dbgfile);
  3083. { size }
  3084. if use_64bit_headers then
  3085. current_asmdata.asmlists[al_dwarf_info].concat(tai_const.create_32bit_unaligned(longint($FFFFFFFF)));
  3086. current_asmdata.asmlists[al_dwarf_info].concat(tai_const.create_rel_sym(offsetreltype,
  3087. lenstartlabel,current_asmdata.DefineAsmSymbol(target_asm.labelprefix+'edebug_info0',AB_LOCAL,AT_METADATA,voidpointertype)));
  3088. current_asmdata.asmlists[al_dwarf_info].concat(tai_label.create(lenstartlabel));
  3089. { version }
  3090. current_asmdata.asmlists[al_dwarf_info].concat(tai_const.create_16bit_unaligned(dwarf_version));
  3091. { abbrev table (=relative from section start)}
  3092. if not(tf_dwarf_relative_addresses in target_info.flags) then
  3093. current_asmdata.asmlists[al_dwarf_info].concat(tai_const.create_type_sym(offsetabstype,
  3094. current_asmdata.DefineAsmSymbol(target_asm.labelprefix+'debug_abbrev0',AB_LOCAL,AT_METADATA,voidpointertype)))
  3095. else
  3096. current_asmdata.asmlists[al_dwarf_info].concat(tai_const.create_rel_sym(offsetreltype,
  3097. current_asmdata.DefineAsmSymbol(target_asm.labelprefix+'debug_abbrevsection0',AB_LOCAL,AT_METADATA,voidpointertype),
  3098. current_asmdata.DefineAsmSymbol(target_asm.labelprefix+'debug_abbrev0',AB_LOCAL,AT_METADATA,voidpointertype)));
  3099. { address size }
  3100. current_asmdata.asmlists[al_dwarf_info].concat(tai_const.create_8bit(sizeof(pint)));
  3101. if (ds_dwarf_cpp in current_settings.debugswitches) then
  3102. lang:=DW_LANG_C_plus_plus
  3103. else
  3104. lang:=DW_LANG_Pascal83;
  3105. { first manadatory compilation unit TAG }
  3106. append_entry(DW_TAG_compile_unit,true,[
  3107. DW_AT_name,DW_FORM_string,relative_dwarf_path(current_module.sourcefiles.get_file(1).path+current_module.sourcefiles.get_file(1).name)+#0,
  3108. DW_AT_producer,DW_FORM_string,'Free Pascal '+full_version_string+' '+date_string+#0,
  3109. DW_AT_comp_dir,DW_FORM_string,BSToSlash(FixPath(GetCurrentDir,false))+#0,
  3110. DW_AT_language,DW_FORM_data1,lang,
  3111. DW_AT_identifier_case,DW_FORM_data1,DW_ID_case_insensitive]);
  3112. {$ifdef i8086}
  3113. case current_settings.x86memorymodel of
  3114. mm_tiny,
  3115. mm_small:
  3116. append_attribute(DW_AT_WATCOM_memory_model,DW_FORM_data1,[DW_WATCOM_MEMORY_MODEL_small]);
  3117. mm_medium:
  3118. append_attribute(DW_AT_WATCOM_memory_model,DW_FORM_data1,[DW_WATCOM_MEMORY_MODEL_medium]);
  3119. mm_compact:
  3120. append_attribute(DW_AT_WATCOM_memory_model,DW_FORM_data1,[DW_WATCOM_MEMORY_MODEL_compact]);
  3121. mm_large:
  3122. append_attribute(DW_AT_WATCOM_memory_model,DW_FORM_data1,[DW_WATCOM_MEMORY_MODEL_large]);
  3123. mm_huge:
  3124. append_attribute(DW_AT_WATCOM_memory_model,DW_FORM_data1,[DW_WATCOM_MEMORY_MODEL_huge]);
  3125. else
  3126. internalerror(2018052402);
  3127. end;
  3128. {$endif i8086}
  3129. { reference to line info section }
  3130. if not(tf_dwarf_relative_addresses in target_info.flags) then
  3131. append_labelentry_dataptr_abs(DW_AT_stmt_list,current_asmdata.DefineAsmSymbol(target_asm.labelprefix+'debug_line0',AB_LOCAL,AT_METADATA,voidpointertype))
  3132. else
  3133. append_labelentry_dataptr_rel(DW_AT_stmt_list,
  3134. current_asmdata.DefineAsmSymbol(target_asm.labelprefix+'debug_linesection0',AB_LOCAL,AT_METADATA,voidpointertype),
  3135. current_asmdata.DefineAsmSymbol(target_asm.labelprefix+'debug_line0',AB_LOCAL,AT_METADATA,voidpointertype));
  3136. if (m_objectivec1 in current_settings.modeswitches) then
  3137. append_attribute(DW_AT_APPLE_major_runtime_vers,DW_FORM_data1,[1]);
  3138. dbgname:=make_mangledname('DEBUGSTART',current_module.localsymtable,'');
  3139. if (target_info.system in systems_darwin) then
  3140. begin
  3141. bind:=AB_LOCAL;
  3142. dbgname:='L'+dbgname;
  3143. end
  3144. else
  3145. bind:=AB_GLOBAL;
  3146. append_labelentry(DW_AT_low_pc,current_asmdata.DefineAsmSymbol(dbgname,bind,AT_METADATA,voidpointertype));
  3147. dbgname:=make_mangledname('DEBUGEND',current_module.localsymtable,'');
  3148. if (target_info.system in systems_darwin) then
  3149. dbgname:='L'+dbgname;
  3150. append_labelentry(DW_AT_high_pc,current_asmdata.DefineAsmSymbol(dbgname,bind,AT_METADATA,voidpointertype));
  3151. finish_entry;
  3152. { write all global/local variables. This will flag all required tdefs }
  3153. if assigned(current_module.globalsymtable) then
  3154. write_symtable_syms(current_asmdata.asmlists[al_dwarf_info],current_module.globalsymtable);
  3155. if assigned(current_module.localsymtable) then
  3156. write_symtable_syms(current_asmdata.asmlists[al_dwarf_info],current_module.localsymtable);
  3157. { write all procedures and methods. This will flag all required tdefs }
  3158. if assigned(current_module.globalsymtable) then
  3159. write_symtable_procdefs(current_asmdata.asmlists[al_dwarf_info],current_module.globalsymtable);
  3160. if assigned(current_module.localsymtable) then
  3161. write_symtable_procdefs(current_asmdata.asmlists[al_dwarf_info],current_module.localsymtable);
  3162. { reset unit type info flag }
  3163. reset_unit_type_info;
  3164. { write used types from the used units }
  3165. write_used_unit_type_info(current_asmdata.asmlists[al_dwarf_info],current_module);
  3166. { last write the types from this unit }
  3167. if assigned(current_module.globalsymtable) then
  3168. write_symtable_defs(current_asmdata.asmlists[al_dwarf_info],current_module.globalsymtable);
  3169. if assigned(current_module.localsymtable) then
  3170. write_symtable_defs(current_asmdata.asmlists[al_dwarf_info],current_module.localsymtable);
  3171. { write defs not written yet }
  3172. write_remaining_defs_to_write(current_asmdata.asmlists[al_dwarf_info]);
  3173. { close compilation unit entry }
  3174. finish_children;
  3175. { end of debug info table }
  3176. current_asmdata.asmlists[al_dwarf_info].concat(tai_symbol.createname(target_asm.labelprefix+'edebug_info0',AT_METADATA,0,voidpointertype));
  3177. { end of abbrev table }
  3178. current_asmdata.asmlists[al_dwarf_abbrev].concat(tai_const.create_8bit(0));
  3179. if not(target_info.system in systems_darwin) then
  3180. begin
  3181. { end of aranges table }
  3182. {$ifdef i8086}
  3183. { 32-bit offset }
  3184. current_asmdata.asmlists[al_dwarf_aranges].concat(tai_const.Create_32bit_unaligned(0));
  3185. { 16-bit segment }
  3186. current_asmdata.asmlists[al_dwarf_aranges].concat(tai_const.Create_16bit_unaligned(0));
  3187. { 32-bit length }
  3188. current_asmdata.asmlists[al_dwarf_aranges].concat(tai_const.Create_32bit_unaligned(0));
  3189. {$else i8086}
  3190. { offset }
  3191. current_asmdata.asmlists[al_dwarf_aranges].concat(tai_const.Create_aint(0));
  3192. { length }
  3193. current_asmdata.asmlists[al_dwarf_aranges].concat(tai_const.Create_aint(0));
  3194. {$endif i8086}
  3195. current_asmdata.asmlists[al_dwarf_aranges].concat(tai_symbol.createname(target_asm.labelprefix+'earanges0',AT_METADATA,0,voidpointertype));
  3196. end;
  3197. { reset all def debug states }
  3198. for i:=0 to defnumberlist.count-1 do
  3199. begin
  3200. def := tdef(defnumberlist[i]);
  3201. if assigned(def) then
  3202. def.dbg_state:=dbg_state_unused;
  3203. end;
  3204. dwarflabels.free;
  3205. dwarflabels:=nil;
  3206. defnumberlist.free;
  3207. defnumberlist:=nil;
  3208. deftowritelist.free;
  3209. deftowritelist:=nil;
  3210. current_filepos:=storefilepos;
  3211. end;
  3212. procedure TDebugInfoDwarf.referencesections(list:TAsmList);
  3213. var
  3214. hp : tmodule;
  3215. begin
  3216. { Reference all DEBUGINFO sections from the main .fpc section }
  3217. { to prevent eliminating them by smartlinking }
  3218. if (target_info.system in ([system_powerpc_macos]+systems_darwin)) then
  3219. exit;
  3220. new_section(list,sec_fpc,'links',0);
  3221. { include reference to all debuginfo sections of used units }
  3222. hp:=tmodule(loaded_units.first);
  3223. while assigned(hp) do
  3224. begin
  3225. If ((hp.flags and uf_has_dwarf_debuginfo)=uf_has_dwarf_debuginfo) and not assigned(hp.package) then
  3226. begin
  3227. list.concat(Tai_const.Createname(make_mangledname('DEBUGSTART',hp.localsymtable,''),0));
  3228. list.concat(Tai_const.Createname(make_mangledname('DEBUGEND',hp.localsymtable,''),0));
  3229. end;
  3230. hp:=tmodule(hp.next);
  3231. end;
  3232. end;
  3233. function TDebugInfoDwarf.symname(sym: tsym; manglename: boolean): String;
  3234. begin
  3235. if (sym.typ=paravarsym) and
  3236. (vo_is_self in tparavarsym(sym).varoptions) then
  3237. { We use 'this' for regular methods because that's what gdb triggers
  3238. on to automatically search fields. Don't do this for class methods,
  3239. because search class fields is not supported, and gdb 7.0+ fails
  3240. in this case because "this" is not a record in that case (it's a
  3241. pointer to a vmt) }
  3242. if not is_objc_class_or_protocol(tdef(sym.owner.defowner.owner.defowner)) and
  3243. not(po_classmethod in tabstractprocdef(sym.owner.defowner).procoptions) then
  3244. result:='this'
  3245. else
  3246. result:='self'
  3247. else if (sym.typ=typesym) and
  3248. is_objc_class_or_protocol(ttypesym(sym).typedef) then
  3249. result:=tobjectdef(ttypesym(sym).typedef).objextname^
  3250. else if (ds_dwarf_method_class_prefix in current_settings.debugswitches) and
  3251. (sym.typ=procsym) and
  3252. (tprocsym(sym).owner.symtabletype in [objectsymtable,recordsymtable]) then
  3253. begin
  3254. result:=tprocsym(sym).owner.name^+'__';
  3255. if manglename then
  3256. result := result + sym.name
  3257. else
  3258. result := result + symdebugname(sym);
  3259. end
  3260. else
  3261. begin
  3262. if manglename then
  3263. result := sym.name
  3264. else
  3265. result := symdebugname(sym);
  3266. end;
  3267. end;
  3268. procedure TDebugInfoDwarf.append_visibility(vis: tvisibility);
  3269. begin
  3270. case vis of
  3271. vis_private,
  3272. vis_strictprivate:
  3273. append_attribute(DW_AT_accessibility,DW_FORM_data1,[ord(DW_ACCESS_private)]);
  3274. vis_protected,
  3275. vis_strictprotected:
  3276. append_attribute(DW_AT_accessibility,DW_FORM_data1,[ord(DW_ACCESS_protected)]);
  3277. vis_public:
  3278. { default };
  3279. end;
  3280. end;
  3281. procedure TDebugInfoDwarf.insertlineinfo(list:TAsmList);
  3282. var
  3283. currfileinfo,
  3284. lastfileinfo : tfileposinfo;
  3285. currfuncname : pshortstring;
  3286. currstatement: boolean;
  3287. currsectype : TAsmSectiontype;
  3288. hp, hpend : tai;
  3289. infile : tinputfile;
  3290. prevcolumn,
  3291. diffline,
  3292. prevline,
  3293. prevfileidx,
  3294. currfileidx,
  3295. nolineinfolevel : Integer;
  3296. prevlabel,
  3297. currlabel : tasmlabel;
  3298. begin
  3299. {$ifdef OMFOBJSUPPORT}
  3300. if ds_dwarf_omf_linnum in current_settings.debugswitches then
  3301. dbgcodeview.InsertLineInfo_OMF_LINNUM_MsLink(list);
  3302. {$endif OMFOBJSUPPORT}
  3303. { this function will always terminate the lineinfo block }
  3304. generated_lineinfo := true;
  3305. { if this unit only contains code without debug info (implicit init
  3306. or final etc), make sure the file table contains at least one entry
  3307. (the main source of the unit), because normally this table gets
  3308. populated via calls to get_file_index and that won't happen in this
  3309. case }
  3310. get_file_index(current_module.sourcefiles.get_file(1));
  3311. FillChar(lastfileinfo,sizeof(lastfileinfo),0);
  3312. currfuncname:=nil;
  3313. currsectype:=sec_code;
  3314. hp:=Tai(list.first);
  3315. currstatement:=true;
  3316. prevcolumn := 0;
  3317. prevline := 1;
  3318. prevfileidx := 1;
  3319. prevlabel := nil;
  3320. nolineinfolevel:=0;
  3321. while assigned(hp) do
  3322. begin
  3323. case hp.typ of
  3324. ait_section :
  3325. currsectype:=tai_section(hp).sectype;
  3326. ait_function_name :
  3327. begin
  3328. currfuncname:=tai_function_name(hp).funcname;
  3329. asmline.concat(tai_comment.Create(strpnew('function: '+currfuncname^)));
  3330. end;
  3331. ait_force_line :
  3332. begin
  3333. lastfileinfo.line:=-1;
  3334. end;
  3335. ait_marker :
  3336. begin
  3337. case tai_marker(hp).kind of
  3338. mark_NoLineInfoStart:
  3339. inc(nolineinfolevel);
  3340. mark_NoLineInfoEnd:
  3341. dec(nolineinfolevel);
  3342. end;
  3343. end;
  3344. end;
  3345. if (currsectype=sec_code) and
  3346. (hp.typ=ait_instruction) then
  3347. begin
  3348. currfileinfo:=tailineinfo(hp).fileinfo;
  3349. { file changed ? (must be before line info) }
  3350. if (currfileinfo.fileindex<>0) and
  3351. ((lastfileinfo.fileindex<>currfileinfo.fileindex) or
  3352. (lastfileinfo.moduleindex<>currfileinfo.moduleindex)) then
  3353. begin
  3354. infile:=get_module(currfileinfo.moduleindex).sourcefiles.get_file(currfileinfo.fileindex);
  3355. if assigned(infile) then
  3356. begin
  3357. currfileidx := get_file_index(infile);
  3358. if prevfileidx <> currfileidx then
  3359. begin
  3360. list.insertbefore(tai_comment.Create(strpnew('path: '+infile.path)), hp);
  3361. list.insertbefore(tai_comment.Create(strpnew('file: '+infile.name)), hp);
  3362. list.insertbefore(tai_comment.Create(strpnew('indx: '+tostr(currfileidx))), hp);
  3363. { set file }
  3364. asmline.concat(tai_comment.Create(strpnew('path: '+infile.path)));
  3365. asmline.concat(tai_comment.Create(strpnew('file: '+infile.name)));
  3366. asmline.concat(tai_const.create_8bit(DW_LNS_set_file));
  3367. asmline.concat(tai_const.create_uleb128bit(currfileidx));
  3368. prevfileidx := currfileidx;
  3369. end;
  3370. { force new line info }
  3371. lastfileinfo.line:=-1;
  3372. end;
  3373. end;
  3374. { Set the line-nr to 0 if the code does not corresponds to a particular line }
  3375. if nolineinfolevel>0 then
  3376. currfileinfo.line := 0;
  3377. { line changed ? }
  3378. if (lastfileinfo.line<>currfileinfo.line) and ((currfileinfo.line<>0) or (nolineinfolevel>0)) then
  3379. begin
  3380. { set address }
  3381. current_asmdata.getlabel(currlabel, alt_dbgline);
  3382. list.insertbefore(tai_label.create(currlabel), hp);
  3383. asmline.concat(tai_comment.Create(strpnew('['+tostr(currfileinfo.line)+':'+tostr(currfileinfo.column)+']')));
  3384. if (prevlabel = nil) or
  3385. { darwin's assembler cannot create an uleb128 of the difference
  3386. between to symbols
  3387. same goes for Solaris native assembler
  3388. ... and riscv }
  3389. (target_info.system in systems_darwin+[system_riscv32_linux,system_riscv64_linux]) or
  3390. (target_asm.id=as_solaris_as) then
  3391. begin
  3392. asmline.concat(tai_const.create_8bit(DW_LNS_extended_op));
  3393. asmline.concat(tai_const.create_uleb128bit(1+sizeof(pint)));
  3394. asmline.concat(tai_const.create_8bit(DW_LNE_set_address));
  3395. asmline.concat(tai_const.create_type_sym(aitconst_ptr_unaligned,currlabel));
  3396. {$ifdef i8086}
  3397. { on i8086 we also emit an Open Watcom-specific 'set segment' op }
  3398. asmline.concat(tai_const.create_8bit(DW_LNS_extended_op));
  3399. asmline.concat(tai_const.create_uleb128bit(3));
  3400. asmline.concat(tai_const.create_8bit(DW_LNE_set_segment));
  3401. asmline.concat(tai_const.Create_seg_name(currlabel.Name));
  3402. {$endif i8086}
  3403. end
  3404. else
  3405. begin
  3406. asmline.concat(tai_const.create_8bit(DW_LNS_advance_pc));
  3407. asmline.concat(tai_const.create_rel_sym(aitconst_uleb128bit, prevlabel, currlabel));
  3408. end;
  3409. prevlabel := currlabel;
  3410. { set column }
  3411. if prevcolumn <> currfileinfo.column then
  3412. begin
  3413. asmline.concat(tai_const.create_8bit(DW_LNS_set_column));
  3414. asmline.concat(tai_const.create_uleb128bit(currfileinfo.column));
  3415. prevcolumn := currfileinfo.column;
  3416. end;
  3417. { set statement }
  3418. if (currfileinfo.line=0) and currstatement then
  3419. begin
  3420. currstatement := false;
  3421. asmline.concat(tai_const.create_8bit(DW_LNS_negate_stmt));
  3422. end;
  3423. if not currstatement and (currfileinfo.line>0) then
  3424. begin
  3425. currstatement := true;
  3426. asmline.concat(tai_const.create_8bit(DW_LNS_negate_stmt));
  3427. end;
  3428. { set line }
  3429. diffline := currfileinfo.line - prevline;
  3430. if (diffline >= LINE_BASE) and (OPCODE_BASE + diffline - LINE_BASE <= 255) then
  3431. begin
  3432. { use special opcode, this also adds a row }
  3433. asmline.concat(tai_const.create_8bit(OPCODE_BASE + diffline - LINE_BASE));
  3434. end
  3435. else
  3436. begin
  3437. if diffline <> 0 then
  3438. begin
  3439. asmline.concat(tai_const.create_8bit(DW_LNS_advance_line));
  3440. asmline.concat(tai_const.create_sleb128bit(diffline));
  3441. end;
  3442. { no row added yet, do it manually }
  3443. asmline.concat(tai_const.create_8bit(DW_LNS_copy));
  3444. end;
  3445. prevline := currfileinfo.line;
  3446. end;
  3447. lastfileinfo:=currfileinfo;
  3448. end;
  3449. hpend:=hp;
  3450. hp:=tai(hp.next);
  3451. end;
  3452. if assigned(hpend) then
  3453. begin
  3454. { set address for end (see appendix 3 of dwarf 2 specs) }
  3455. current_asmdata.getlabel(currlabel, alt_dbgline);
  3456. list.insertafter(tai_label.create(currlabel), hpend);
  3457. asmline.concat(tai_const.create_8bit(DW_LNS_extended_op));
  3458. asmline.concat(tai_const.create_uleb128bit(1+sizeof(pint)));
  3459. asmline.concat(tai_const.create_8bit(DW_LNE_set_address));
  3460. asmline.concat(tai_const.create_type_sym(aitconst_ptr_unaligned,currlabel));
  3461. end;
  3462. { end sequence }
  3463. asmline.concat(tai_const.Create_8bit(DW_LNS_extended_op));
  3464. asmline.concat(tai_const.Create_8bit(1));
  3465. asmline.concat(tai_const.Create_8bit(DW_LNE_end_sequence));
  3466. asmline.concat(tai_comment.Create(strpnew('###################')));
  3467. end;
  3468. procedure TDebugInfoDwarf.finish_lineinfo;
  3469. var
  3470. infile: tinputfile;
  3471. begin
  3472. { only needed if no line info at all has been generated }
  3473. if generated_lineinfo then
  3474. begin
  3475. { reset for next module compilation }
  3476. generated_lineinfo:=false;
  3477. exit;
  3478. end;
  3479. { at least the Darwin linker is annoyed if you do not }
  3480. { finish the lineinfo section, or if it doesn't }
  3481. { contain at least one file name and set_address }
  3482. infile:=current_module.sourcefiles.get_file(1);
  3483. if not assigned(infile) then
  3484. internalerror(2006020211);
  3485. asmline.concat(tai_const.create_8bit(DW_LNS_set_file));
  3486. asmline.concat(tai_const.create_uleb128bit(get_file_index(infile)));
  3487. asmline.concat(tai_const.create_8bit(DW_LNS_extended_op));
  3488. asmline.concat(tai_const.create_uleb128bit(1+sizeof(pint)));
  3489. asmline.concat(tai_const.create_8bit(DW_LNE_set_address));
  3490. asmline.concat(tai_const.create_type_sym(aitconst_ptr_unaligned,nil));
  3491. asmline.concat(tai_const.create_8bit(DW_LNS_extended_op));
  3492. asmline.concat(tai_const.Create_8bit(1));
  3493. asmline.concat(tai_const.Create_8bit(DW_LNE_end_sequence));
  3494. asmline.concat(tai_comment.Create(strpnew('###################')));
  3495. end;
  3496. {****************************************************************************
  3497. TDebugInfoDwarf2
  3498. ****************************************************************************}
  3499. procedure TDebugInfoDwarf2.appenddef_file(list:TAsmList;def: tfiledef);
  3500. begin
  3501. { gdb 6.4 doesn't support files so far so we use some fake recorddef
  3502. file recs. are less than 1k so using data2 is enough }
  3503. if assigned(def.typesym) then
  3504. append_entry(DW_TAG_structure_type,false,[
  3505. DW_AT_name,DW_FORM_string,symname(def.typesym, false)+#0,
  3506. DW_AT_byte_size,DW_FORM_udata,def.size
  3507. ])
  3508. else
  3509. append_entry(DW_TAG_structure_type,false,[
  3510. DW_AT_byte_size,DW_FORM_udata,def.size
  3511. ]);
  3512. finish_entry;
  3513. end;
  3514. procedure TDebugInfoDwarf2.appenddef_formal(list:TAsmList;def: tformaldef);
  3515. begin
  3516. { gdb 6.4 doesn't support DW_TAG_unspecified_type so we
  3517. replace it with a unsigned type with size 0 (FK)
  3518. }
  3519. append_entry(DW_TAG_base_type,false,[
  3520. DW_AT_name,DW_FORM_string,'FormalDef'#0,
  3521. DW_AT_encoding,DW_FORM_data1,DW_ATE_unsigned,
  3522. DW_AT_byte_size,DW_FORM_data1,0
  3523. ]);
  3524. finish_entry;
  3525. end;
  3526. procedure TDebugInfoDwarf2.append_object_struct(def: tobjectdef; const createlabel: boolean; const objectname: PShortString);
  3527. begin
  3528. if createlabel then
  3529. begin
  3530. if not(tf_dwarf_only_local_labels in target_info.flags) then
  3531. current_asmdata.asmlists[al_dwarf_info].concat(tai_symbol.create_global(def_dwarf_class_struct_lab(def),0))
  3532. else
  3533. current_asmdata.asmlists[al_dwarf_info].concat(tai_symbol.create(def_dwarf_class_struct_lab(def),0));
  3534. end;
  3535. if assigned(objectname) then
  3536. append_entry(DW_TAG_class_type,true,[
  3537. DW_AT_name,DW_FORM_string,objectname^+#0,
  3538. DW_AT_byte_size,DW_FORM_udata,tobjectsymtable(def.symtable).datasize
  3539. ])
  3540. else
  3541. append_entry(DW_TAG_class_type,true,[
  3542. DW_AT_byte_size,DW_FORM_udata,tobjectsymtable(def.symtable).datasize
  3543. ]);
  3544. { Apple-specific tag that identifies it as an Objective-C class }
  3545. if (def.objecttype=odt_objcclass) then
  3546. append_attribute(DW_AT_APPLE_runtime_class,DW_FORM_data1,[DW_LANG_ObjC]);
  3547. finish_entry;
  3548. if assigned(def.childof) then
  3549. begin
  3550. append_entry(DW_TAG_inheritance,false,[
  3551. DW_AT_accessibility,DW_FORM_data1,DW_ACCESS_public,
  3552. DW_AT_data_member_location,DW_FORM_block1,1+lengthuleb128(0)
  3553. ]);
  3554. current_asmdata.asmlists[al_dwarf_info].concat(tai_const.create_8bit(ord(DW_OP_plus_uconst)));
  3555. current_asmdata.asmlists[al_dwarf_info].concat(tai_const.create_uleb128bit(0));
  3556. if (def.childof.dbg_state=dbg_state_unused) then
  3557. def.childof.dbg_state:=dbg_state_used;
  3558. if is_implicit_pointer_object_type(def) then
  3559. append_labelentry_ref(DW_AT_type,def_dwarf_class_struct_lab(def.childof))
  3560. else
  3561. append_labelentry_ref(DW_AT_type,def_dwarf_lab(def.childof));
  3562. finish_entry;
  3563. end;
  3564. if (oo_has_vmt in def.objectoptions) and
  3565. (not assigned(def.childof) or
  3566. not(oo_has_vmt in def.childof.objectoptions)) then
  3567. begin
  3568. { vmt field }
  3569. append_entry(DW_TAG_member,false,[
  3570. DW_AT_artificial,DW_FORM_flag,true,
  3571. DW_AT_name,DW_FORM_string,'_vptr$'+def.objname^+#0,
  3572. DW_AT_data_member_location,DW_FORM_block1,1+lengthuleb128(def.vmt_offset)
  3573. ]);
  3574. current_asmdata.asmlists[al_dwarf_info].concat(tai_const.create_8bit(ord(DW_OP_plus_uconst)));
  3575. current_asmdata.asmlists[al_dwarf_info].concat(tai_const.create_uleb128bit(def.vmt_offset));
  3576. { should be changed into a pointer to a function returning an }
  3577. { int and with TAG_unspecified_parameters }
  3578. if (voidpointertype.dbg_state=dbg_state_unused) then
  3579. voidpointertype.dbg_state:=dbg_state_used;
  3580. append_labelentry_ref(DW_AT_type,def_dwarf_lab(voidpointertype));
  3581. finish_entry;
  3582. end;
  3583. def.symtable.symList.ForEachCall(@enum_membersyms_callback,nil);
  3584. { Write the methods in the scope of the class/object, except for Objective-C. }
  3585. if is_objc_class_or_protocol(def) then
  3586. finish_children;
  3587. { don't write procdefs of externally defined classes, gcc doesn't
  3588. either (info is probably gotten from ObjC runtime) }
  3589. if not(oo_is_external in def.objectoptions) then
  3590. write_symtable_procdefs(current_asmdata.asmlists[al_dwarf_info],def.symtable);
  3591. if not is_objc_class_or_protocol(def) then
  3592. finish_children;
  3593. end;
  3594. procedure TDebugInfoDwarf2.appenddef_object(list:TAsmList;def: tobjectdef);
  3595. begin
  3596. case def.objecttype of
  3597. odt_cppclass,
  3598. odt_object:
  3599. append_object_struct(def,false,def.objname);
  3600. odt_interfacecom,
  3601. odt_interfacecorba,
  3602. odt_dispinterface,
  3603. odt_helper,
  3604. odt_class:
  3605. begin
  3606. { implicit pointer }
  3607. append_entry(DW_TAG_pointer_type,false,[]);
  3608. append_labelentry_ref(DW_AT_type,def_dwarf_class_struct_lab(def));
  3609. finish_entry;
  3610. append_object_struct(def,true,def.objname);
  3611. end;
  3612. odt_objcclass:
  3613. { Objective-C class: same as regular class, except for
  3614. a) Apple-specific tag that identifies it as an Objective-C class
  3615. b) use extname^ instead of objname
  3616. }
  3617. append_object_struct(def,true,def.objextname);
  3618. odt_objcprotocol:
  3619. begin
  3620. append_entry(DW_TAG_pointer_type,false,[]);
  3621. append_labelentry_ref(DW_AT_type,def_dwarf_lab(voidpointertype));
  3622. finish_entry;
  3623. end;
  3624. else
  3625. internalerror(200602041);
  3626. end;
  3627. end;
  3628. procedure TDebugInfoDwarf2.appenddef_set_intern(list:TAsmList;def: tsetdef; force_tag_set: boolean);
  3629. var
  3630. lab: tasmlabel;
  3631. begin
  3632. if force_tag_set or
  3633. (ds_dwarf_sets in current_settings.debugswitches) then
  3634. begin
  3635. { current (20070704 -- patch was committed on 20060513) gdb cvs supports set types }
  3636. if assigned(def.typesym) then
  3637. append_entry(DW_TAG_set_type,false,[
  3638. DW_AT_name,DW_FORM_string,symname(def.typesym, false)+#0,
  3639. DW_AT_byte_size,DW_FORM_data2,def.size
  3640. ])
  3641. else
  3642. append_entry(DW_TAG_set_type,false,[
  3643. DW_AT_byte_size,DW_FORM_data2,def.size
  3644. ]);
  3645. if assigned(def.elementdef) then
  3646. begin
  3647. if not(tf_dwarf_only_local_labels in target_info.flags) then
  3648. current_asmdata.getglobaldatalabel(lab)
  3649. else
  3650. current_asmdata.getaddrlabel(lab);
  3651. append_labelentry_ref(DW_AT_type,lab);
  3652. finish_entry;
  3653. if lab.bind=AB_GLOBAL then
  3654. current_asmdata.asmlists[al_dwarf_info].concat(tai_symbol.create_global(lab,0))
  3655. else
  3656. current_asmdata.asmlists[al_dwarf_info].concat(tai_symbol.create(lab,0));
  3657. { Sets of e.g. [1..5] are actually stored as a set of [0..7],
  3658. so write the exact boundaries of the set here. Let's hope no
  3659. debugger ever rejects this because this "subrange" type can
  3660. actually have a larger range than the original one. }
  3661. append_entry(DW_TAG_subrange_type,false,[
  3662. DW_AT_lower_bound,DW_FORM_sdata,def.setbase,
  3663. DW_AT_upper_bound,DW_FORM_sdata,get_max_value(def.elementdef).svalue
  3664. ]);
  3665. append_labelentry_ref(DW_AT_type,def_dwarf_lab(def.elementdef))
  3666. end
  3667. end
  3668. else
  3669. begin
  3670. { gdb versions which don't support sets refuse to load the debug }
  3671. { info of modules that contain set tags }
  3672. if assigned(def.typesym) then
  3673. append_entry(DW_TAG_base_type,false,[
  3674. DW_AT_name,DW_FORM_string,symname(def.typesym, false)+#0,
  3675. DW_AT_encoding,DW_FORM_data1,DW_ATE_unsigned,
  3676. DW_AT_byte_size,DW_FORM_data2,def.size
  3677. ])
  3678. else
  3679. append_entry(DW_TAG_base_type,false,[
  3680. DW_AT_encoding,DW_FORM_data1,DW_ATE_unsigned,
  3681. DW_AT_byte_size,DW_FORM_data2,def.size
  3682. ]);
  3683. end;
  3684. finish_entry;
  3685. end;
  3686. procedure TDebugInfoDwarf2.appenddef_set(list:TAsmList;def: tsetdef);
  3687. begin
  3688. appenddef_set_intern(list,def,false);
  3689. end;
  3690. procedure TDebugInfoDwarf2.appenddef_undefined(list:TAsmList;def: tundefineddef);
  3691. begin
  3692. { gdb 6.4 doesn't support DW_TAG_unspecified_type so we
  3693. replace it with a unsigned type with size 0 (FK)
  3694. }
  3695. append_entry(DW_TAG_base_type,false,[
  3696. DW_AT_name,DW_FORM_string,'FormalDef'#0,
  3697. DW_AT_encoding,DW_FORM_data1,DW_ATE_unsigned,
  3698. DW_AT_byte_size,DW_FORM_data1,0
  3699. ]);
  3700. finish_entry;
  3701. end;
  3702. procedure TDebugInfoDwarf2.appenddef_variant(list:TAsmList;def: tvariantdef);
  3703. begin
  3704. { variants aren't known to dwarf2 but writting tvardata should be enough }
  3705. if assigned(vardatadef) then
  3706. appenddef_record_named(list,trecorddef(vardatadef),'Variant');
  3707. end;
  3708. function TDebugInfoDwarf2.dwarf_version: Word;
  3709. begin
  3710. Result:=2;
  3711. end;
  3712. {****************************************************************************
  3713. TDebugInfoDwarf3
  3714. ****************************************************************************}
  3715. procedure TDebugInfoDwarf3.append_labelentry_addr_ref(attr : tdwarf_attribute;sym : tasmsymbol);
  3716. begin
  3717. AddConstToAbbrev(ord(DW_FORM_ref_addr));
  3718. { Since Dwarf 3 the length of a DW_FORM_ref_addr entry is not dependent on the pointer size of the
  3719. target platform, but on the used Dwarf-format (32 bit or 64 bit) for the current compilation section. }
  3720. if use_64bit_headers then
  3721. current_asmdata.asmlists[al_dwarf_info].concat(tai_const.Create_type_sym(aitconst_64bit_unaligned,sym))
  3722. else
  3723. current_asmdata.asmlists[al_dwarf_info].concat(tai_const.Create_type_sym(aitconst_32bit_unaligned,sym));
  3724. end;
  3725. procedure tdebuginfodwarf3.appenddef_array(list: tasmlist; def: tarraydef);
  3726. begin
  3727. if not is_dynamic_array(def) then
  3728. begin
  3729. inherited appenddef_array(list,def);
  3730. exit;
  3731. end;
  3732. if assigned(def.typesym) then
  3733. append_entry(DW_TAG_array_type,true,[
  3734. DW_AT_name,DW_FORM_string,symname(def.typesym, false)+#0,
  3735. DW_AT_data_location,DW_FORM_block1,2
  3736. ])
  3737. else
  3738. append_entry(DW_TAG_array_type,true,[
  3739. DW_AT_data_location,DW_FORM_block1,2
  3740. ]);
  3741. current_asmdata.asmlists[al_dwarf_info].concat(tai_const.create_8bit(ord(DW_OP_push_object_address)));
  3742. current_asmdata.asmlists[al_dwarf_info].concat(tai_const.create_8bit(ord(DW_OP_deref)));
  3743. append_labelentry_ref(DW_AT_type,def_dwarf_lab(def.elementdef));
  3744. finish_entry;
  3745. { to simplify things, we don't write a multidimensional array here }
  3746. append_entry(DW_TAG_subrange_type,false,[
  3747. DW_AT_byte_stride,DW_FORM_udata,def.elesize,
  3748. DW_AT_lower_bound,DW_FORM_udata,0,
  3749. DW_AT_upper_bound,DW_FORM_block1,14
  3750. ]);
  3751. current_asmdata.asmlists[al_dwarf_info].concat(tai_const.create_8bit(ord(DW_OP_push_object_address)));
  3752. current_asmdata.asmlists[al_dwarf_info].concat(tai_const.create_8bit(ord(DW_OP_deref)));
  3753. current_asmdata.asmlists[al_dwarf_info].concat(tai_const.create_8bit(ord(DW_OP_dup)));
  3754. { pointer = nil? }
  3755. current_asmdata.asmlists[al_dwarf_info].concat(tai_const.create_8bit(ord(DW_OP_bra)));
  3756. current_asmdata.asmlists[al_dwarf_info].concat(tai_const.create_16bit_unaligned(5));
  3757. { yes -> length = 0 }
  3758. current_asmdata.asmlists[al_dwarf_info].concat(tai_const.create_8bit(ord(DW_OP_const1s)));
  3759. current_asmdata.asmlists[al_dwarf_info].concat(tai_const.create_8bit(byte(-1)));
  3760. current_asmdata.asmlists[al_dwarf_info].concat(tai_const.create_8bit(ord(DW_OP_skip)));
  3761. current_asmdata.asmlists[al_dwarf_info].concat(tai_const.create_16bit_unaligned(3));
  3762. { no -> load length }
  3763. current_asmdata.asmlists[al_dwarf_info].concat(tai_const.create_8bit(ord(DW_OP_lit0)+sizeof(ptrint)));
  3764. current_asmdata.asmlists[al_dwarf_info].concat(tai_const.create_8bit(ord(DW_OP_minus)));
  3765. current_asmdata.asmlists[al_dwarf_info].concat(tai_const.create_8bit(ord(DW_OP_deref)));
  3766. append_labelentry_ref(DW_AT_type,def_dwarf_lab(def.rangedef));
  3767. finish_entry;
  3768. finish_children;
  3769. end;
  3770. procedure tdebuginfodwarf3.appenddef_string(list: tasmlist; def: tstringdef);
  3771. procedure addstringdef(const name: shortstring; chardef: tdef; deref: boolean; lensize: aint);
  3772. var
  3773. upperopcodes: longint;
  3774. begin
  3775. { deref=true -> ansi/unicde/widestring; deref = false -> short/longstring }
  3776. if assigned(def.typesym) then
  3777. append_entry(DW_TAG_array_type,true,[
  3778. DW_AT_name,DW_FORM_string,name+#0,
  3779. DW_AT_data_location,DW_FORM_block1,2+ord(not(deref))
  3780. ])
  3781. else
  3782. append_entry(DW_TAG_array_type,true,[
  3783. DW_AT_data_location,DW_FORM_block1,2+ord(not(deref))
  3784. ]);
  3785. { in all cases we start with the address of the string }
  3786. current_asmdata.asmlists[al_dwarf_info].concat(tai_const.create_8bit(ord(DW_OP_push_object_address)));
  3787. if deref then
  3788. begin
  3789. { ansi/unicode/widestring -> dereference the address of the string, and then
  3790. we point to address of the string
  3791. }
  3792. current_asmdata.asmlists[al_dwarf_info].concat(tai_const.create_8bit(ord(DW_OP_deref)));
  3793. end
  3794. else
  3795. begin
  3796. { shortstring characters begin at string[1], so add one to the string's address }
  3797. current_asmdata.asmlists[al_dwarf_info].concat(tai_const.create_8bit(ord(DW_OP_lit0)+lensize));
  3798. current_asmdata.asmlists[al_dwarf_info].concat(tai_const.create_8bit(ord(DW_OP_plus)))
  3799. end;
  3800. { reference to the element type of the string }
  3801. append_labelentry_ref(DW_AT_type,def_dwarf_lab(chardef));
  3802. finish_entry;
  3803. { now the information about the length of the string }
  3804. if deref then
  3805. begin
  3806. if (chardef.size=1) then
  3807. upperopcodes:=13
  3808. else
  3809. upperopcodes:=15;
  3810. { lower bound is always 1, upper bound (length) needs to be calculated }
  3811. append_entry(DW_TAG_subrange_type,false,[
  3812. DW_AT_lower_bound,DW_FORM_udata,1,
  3813. DW_AT_upper_bound,DW_FORM_block1,upperopcodes
  3814. ]);
  3815. { high(string) is stored sizeof(ptrint) bytes before the string data }
  3816. current_asmdata.asmlists[al_dwarf_info].concat(tai_const.create_8bit(ord(DW_OP_push_object_address)));
  3817. current_asmdata.asmlists[al_dwarf_info].concat(tai_const.create_8bit(ord(DW_OP_deref)));
  3818. current_asmdata.asmlists[al_dwarf_info].concat(tai_const.create_8bit(ord(DW_OP_dup)));
  3819. { pointer = nil? }
  3820. current_asmdata.asmlists[al_dwarf_info].concat(tai_const.create_8bit(ord(DW_OP_bra)));
  3821. current_asmdata.asmlists[al_dwarf_info].concat(tai_const.create_16bit_unaligned(4));
  3822. { yes -> length = 0 }
  3823. current_asmdata.asmlists[al_dwarf_info].concat(tai_const.create_8bit(ord(DW_OP_lit0)));
  3824. current_asmdata.asmlists[al_dwarf_info].concat(tai_const.create_8bit(ord(DW_OP_skip)));
  3825. current_asmdata.asmlists[al_dwarf_info].concat(tai_const.create_16bit_unaligned(3));
  3826. { no -> load length }
  3827. current_asmdata.asmlists[al_dwarf_info].concat(tai_const.create_8bit(ord(DW_OP_lit0)+sizeof(ptrint)));
  3828. current_asmdata.asmlists[al_dwarf_info].concat(tai_const.create_8bit(ord(DW_OP_minus)));
  3829. current_asmdata.asmlists[al_dwarf_info].concat(tai_const.create_8bit(ord(DW_OP_deref)));
  3830. { for widestrings, the length is specified in bytes, so divide by two }
  3831. if (upperopcodes=15) then
  3832. begin
  3833. current_asmdata.asmlists[al_dwarf_info].concat(tai_const.create_8bit(ord(DW_OP_lit1)));
  3834. current_asmdata.asmlists[al_dwarf_info].concat(tai_const.create_8bit(ord(DW_OP_shr)));
  3835. end;
  3836. end
  3837. else
  3838. begin
  3839. append_entry(DW_TAG_subrange_type,false,[
  3840. DW_AT_lower_bound,DW_FORM_udata,1,
  3841. DW_AT_upper_bound,DW_FORM_block1,3
  3842. ]);
  3843. { for shortstrings, the length is the first byte of the string }
  3844. current_asmdata.asmlists[al_dwarf_info].concat(tai_const.create_8bit(ord(DW_OP_push_object_address)));
  3845. { load 1 byte }
  3846. current_asmdata.asmlists[al_dwarf_info].concat(tai_const.create_8bit(ord(DW_OP_deref_size)));
  3847. current_asmdata.asmlists[al_dwarf_info].concat(tai_const.create_8bit(lensize));
  3848. end;
  3849. finish_entry;
  3850. finish_children;
  3851. end;
  3852. begin
  3853. if (ds_dwarf_cpp in current_settings.debugswitches) then
  3854. begin
  3855. // At least LLDB 6.0.0 does not like this implementation of string types.
  3856. // Call the inherited DWARF 2 implementation, which works fine.
  3857. inherited;
  3858. exit;
  3859. end;
  3860. case def.stringtype of
  3861. st_shortstring:
  3862. begin
  3863. addstringdef('ShortString',cansichartype,false,1);
  3864. end;
  3865. st_longstring:
  3866. begin
  3867. {$ifdef cpu64bitaddr}
  3868. addstringdef('LongString',cansichartype,false,8);
  3869. {$else cpu64bitaddr}
  3870. addstringdef('LongString',cansichartype,false,4);
  3871. {$endif cpu64bitaddr}
  3872. end;
  3873. st_ansistring:
  3874. begin
  3875. addstringdef('AnsiString',cansichartype,true,-1);
  3876. end;
  3877. st_unicodestring:
  3878. begin
  3879. addstringdef('UnicodeString',cwidechartype,true,-1);
  3880. end;
  3881. st_widestring:
  3882. begin
  3883. if not(tf_winlikewidestring in target_info.flags) then
  3884. addstringdef('WideString',cwidechartype,true,-1)
  3885. else
  3886. begin
  3887. { looks like a pwidechar (no idea about length location) }
  3888. append_entry(DW_TAG_pointer_type,false,[]);
  3889. append_labelentry_ref(DW_AT_type,def_dwarf_lab(cwidechartype));
  3890. finish_entry;
  3891. end;
  3892. end;
  3893. end;
  3894. end;
  3895. procedure TDebugInfoDwarf3.appenddef_file(list:TAsmList;def: tfiledef);
  3896. begin
  3897. if assigned(def.typesym) then
  3898. append_entry(DW_TAG_file_type,false,[
  3899. DW_AT_name,DW_FORM_string,symname(def.typesym, false)+#0,
  3900. DW_AT_byte_size,DW_FORM_data2,def.size
  3901. ])
  3902. else
  3903. append_entry(DW_TAG_file_type,false,[
  3904. DW_AT_byte_size,DW_FORM_data2,def.size
  3905. ]);
  3906. if tfiledef(def).filetyp=ft_typed then
  3907. append_labelentry_ref(DW_AT_type,def_dwarf_lab(tfiledef(def).typedfiledef));
  3908. finish_entry;
  3909. end;
  3910. procedure TDebugInfoDwarf3.appenddef_formal(list:TAsmList;def: tformaldef);
  3911. begin
  3912. if (ds_dwarf_cpp in current_settings.debugswitches) then
  3913. begin
  3914. // Do not use DW_TAG_unspecified_type for C++ simulation.
  3915. // At least LLDB 3.9.0 crashes in such case.
  3916. // Call the inherited DWARF 2 implementation, which works fine.
  3917. inherited;
  3918. exit;
  3919. end;
  3920. append_entry(DW_TAG_unspecified_type,false,[]);
  3921. finish_entry;
  3922. end;
  3923. procedure TDebugInfoDwarf3.appenddef_object(list:TAsmList;def: tobjectdef);
  3924. procedure dostruct(tag: tdwarf_tag);
  3925. begin
  3926. if assigned(def.objname) then
  3927. append_entry(tag,true,[
  3928. DW_AT_name,DW_FORM_string,def.objrealname^+#0
  3929. ])
  3930. else
  3931. append_entry(DW_TAG_structure_type,true,[]);
  3932. append_attribute(DW_AT_byte_size,DW_FORM_udata,[tobjectsymtable(def.symtable).datasize]);
  3933. // The pointer to the class-structure is hidden. The debug-information
  3934. // does not contain an implicit pointer, but the data-adress is dereferenced here.
  3935. // In case of a nil-pointer, report the class as being unallocated.
  3936. append_block1(DW_AT_allocated,2);
  3937. current_asmdata.asmlists[al_dwarf_info].concat(tai_const.create_8bit(ord(DW_OP_push_object_address)));
  3938. current_asmdata.asmlists[al_dwarf_info].concat(tai_const.create_8bit(ord(DW_OP_deref)));
  3939. append_block1(DW_AT_data_location,2);
  3940. current_asmdata.asmlists[al_dwarf_info].concat(tai_const.create_8bit(ord(DW_OP_push_object_address)));
  3941. current_asmdata.asmlists[al_dwarf_info].concat(tai_const.create_8bit(ord(DW_OP_deref)));
  3942. finish_entry;
  3943. end;
  3944. procedure doimplicitpointer;
  3945. var
  3946. obj : tasmlabel;
  3947. begin
  3948. if not(tf_dwarf_only_local_labels in target_info.flags) then
  3949. current_asmdata.getglobaldatalabel(obj)
  3950. else
  3951. current_asmdata.getaddrlabel(obj);
  3952. { implicit pointer }
  3953. append_entry(DW_TAG_pointer_type,false,[]);
  3954. append_labelentry_ref(DW_AT_type,obj);
  3955. finish_entry;
  3956. current_asmdata.asmlists[al_dwarf_info].concat(tai_symbol.create(obj,0));
  3957. end;
  3958. procedure doparent(isinterface: boolean);
  3959. begin
  3960. if not assigned(def.childof) then
  3961. exit;
  3962. if isinterface then
  3963. begin
  3964. append_entry(DW_TAG_inheritance,false,[]);
  3965. end
  3966. else
  3967. begin
  3968. append_entry(DW_TAG_inheritance,false,[
  3969. DW_AT_accessibility,DW_FORM_data1,DW_ACCESS_public,
  3970. DW_AT_data_member_location,DW_FORM_block1,1+lengthuleb128(0)
  3971. ]);
  3972. current_asmdata.asmlists[al_dwarf_info].concat(tai_const.create_8bit(ord(DW_OP_plus_uconst)));
  3973. current_asmdata.asmlists[al_dwarf_info].concat(tai_const.create_uleb128bit(0));
  3974. end;
  3975. append_labelentry_ref(DW_AT_type,def_dwarf_lab(def.childof));
  3976. finish_entry;
  3977. end;
  3978. var
  3979. n: integer;
  3980. begin
  3981. case def.objecttype of
  3982. odt_cppclass,
  3983. odt_object:
  3984. begin
  3985. dostruct(DW_TAG_structure_type);
  3986. doparent(false);
  3987. end;
  3988. odt_interfacecom,
  3989. odt_interfacecorba,
  3990. odt_dispinterface:
  3991. begin
  3992. dostruct(DW_TAG_interface_type);
  3993. doparent(true);
  3994. end;
  3995. odt_helper,
  3996. odt_class:
  3997. begin
  3998. //dostruct(DW_TAG_class_type);
  3999. //doparent(false);
  4000. append_entry(DW_TAG_pointer_type,false,[]);
  4001. append_labelentry_ref(DW_AT_type,def_dwarf_class_struct_lab(def));
  4002. finish_entry;
  4003. append_object_struct(def,true,def.objrealname);
  4004. Exit;
  4005. end;
  4006. else
  4007. internalerror(200609171);
  4008. end;
  4009. { add implemented interfaces }
  4010. if assigned(def.ImplementedInterfaces) then
  4011. for n := 0 to def.ImplementedInterfaces.count-1 do
  4012. begin
  4013. append_entry(DW_TAG_inheritance,false,[]);
  4014. append_labelentry_ref(DW_AT_type,def_dwarf_lab(TImplementedInterface(def.ImplementedInterfaces[n]).IntfDef));
  4015. finish_entry;
  4016. end;
  4017. { add members }
  4018. def.symtable.symList.ForEachCall(@enum_membersyms_callback,nil);
  4019. finish_children;
  4020. end;
  4021. procedure TDebugInfoDwarf3.appenddef_set(list:TAsmList;def: tsetdef);
  4022. begin
  4023. appenddef_set_intern(list,def,true);
  4024. end;
  4025. procedure TDebugInfoDwarf3.appenddef_undefined(list:TAsmList;def: tundefineddef);
  4026. begin
  4027. { ??? can a undefined def have a typename ? }
  4028. if assigned(def.typesym) then
  4029. append_entry(DW_TAG_unspecified_type,false,[
  4030. DW_AT_name,DW_FORM_string,symname(def.typesym, false)+#0
  4031. ])
  4032. else
  4033. append_entry(DW_TAG_unspecified_type,false,[
  4034. ]);
  4035. finish_entry;
  4036. end;
  4037. procedure TDebugInfoDwarf3.appenddef_variant(list:TAsmList;def: tvariantdef);
  4038. const
  4039. VARIANTS: array[1..27] of record Value: Word; Name: String end = (
  4040. (value:0; name:''),
  4041. (value:1; name:''),
  4042. (value:2; name:'VSMALLINT'),
  4043. (value:3; name:'VINTEGER'),
  4044. (value:4; name:'VSINGLE'),
  4045. (value:5; name:'VDOUBLE'),
  4046. (value:6; name:'VCURRENCY'),
  4047. (value:7; name:'VDATE'),
  4048. (value:8; name:'VOLESTR'),
  4049. (value:9; name:'VDISPATCH'),
  4050. (value:10; name:'VERROR'),
  4051. (value:11; name:'VBOOLEAN'),
  4052. (value:12; name:''),
  4053. (value:13; name:'VUNKNOWN'),
  4054. (value:14; name:''),
  4055. (value:16; name:'VSHORTINT'),
  4056. (value:17; name:'VBYTE'),
  4057. (value:18; name:'VWORD'),
  4058. (value:19; name:'VLONGWORD'),
  4059. (value:20; name:'VINT64'),
  4060. (value:21; name:'VQWORD'),
  4061. (value:36; name:'VRECORD'),
  4062. (value:$48; name:''),
  4063. (value:$100; name:'VSTRING'),
  4064. (value:$101; name:'VANY'),
  4065. (value:$2000; name:'VARRAY'),
  4066. (value:$4000; name:'VPOINTER')
  4067. );
  4068. var
  4069. fs: tfieldvarsym;
  4070. lbl: tasmlabel;
  4071. idx: integer;
  4072. begin
  4073. { it could be done with DW_TAG_variant for the union part (if that info was available)
  4074. now we do it manually for variants (MWE) }
  4075. { struct }
  4076. append_entry(DW_TAG_structure_type,true,[
  4077. DW_AT_name,DW_FORM_string,'Variant'#0,
  4078. DW_AT_byte_size,DW_FORM_udata,vardatadef.size
  4079. ]);
  4080. finish_entry;
  4081. append_entry(DW_TAG_variant_part,true,[
  4082. ]);
  4083. current_asmdata.getaddrlabel(lbl);
  4084. append_labelentry_ref(DW_AT_discr,lbl);
  4085. finish_entry;
  4086. { discriminant }
  4087. fs := tfieldvarsym(vardatadef.symtable.Find('VTYPE'));
  4088. if (fs = nil) or (fs.typ <> fieldvarsym) then
  4089. internalerror(200609271);
  4090. current_asmdata.asmlists[al_dwarf_info].concat(tai_symbol.create(lbl,0));
  4091. appendsym_fieldvar(list,fs);
  4092. { variants }
  4093. for idx := Low(VARIANTS) to High(VARIANTS) do
  4094. begin
  4095. append_entry(DW_TAG_variant,true,[
  4096. DW_AT_discr_value,DW_FORM_udata,VARIANTS[idx].value
  4097. ]);
  4098. finish_entry;
  4099. if VARIANTS[idx].name <> '' then
  4100. begin
  4101. fs := tfieldvarsym(vardatadef.symtable.Find(VARIANTS[idx].name));
  4102. if (fs = nil) or (fs.typ <> fieldvarsym) then
  4103. internalerror(20060927200+idx);
  4104. appendsym_fieldvar(list,fs);
  4105. end;
  4106. finish_children; { variant }
  4107. end;
  4108. finish_children; { variant part }
  4109. finish_children; { struct }
  4110. end;
  4111. function TDebugInfoDwarf3.dwarf_version: Word;
  4112. begin
  4113. Result:=3;
  4114. end;
  4115. function TDebugInfoDwarf3.symdebugname(sym: tsym): String;
  4116. begin
  4117. Result:=sym.realname;
  4118. end;
  4119. { TDebugInfoDwarf4 }
  4120. function TDebugInfoDwarf4.dwarf_version: Word;
  4121. begin
  4122. Result:=4;
  4123. end;
  4124. {****************************************************************************
  4125. ****************************************************************************}
  4126. const
  4127. dbg_dwarf2_info : tdbginfo =
  4128. (
  4129. id : dbg_dwarf2;
  4130. idtxt : 'DWARF2';
  4131. );
  4132. dbg_dwarf3_info : tdbginfo =
  4133. (
  4134. id : dbg_dwarf3;
  4135. idtxt : 'DWARF3';
  4136. );
  4137. dbg_dwarf4_info : tdbginfo =
  4138. (
  4139. id : dbg_dwarf4;
  4140. idtxt : 'DWARF4';
  4141. );
  4142. initialization
  4143. RegisterDebugInfo(dbg_dwarf2_info,TDebugInfoDwarf2);
  4144. RegisterDebugInfo(dbg_dwarf3_info,TDebugInfoDwarf3);
  4145. RegisterDebugInfo(dbg_dwarf4_info,TDebugInfoDwarf4);
  4146. end.