dwarf2out.c 751 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359103601036110362103631036410365103661036710368103691037010371103721037310374103751037610377103781037910380103811038210383103841038510386103871038810389103901039110392103931039410395103961039710398103991040010401104021040310404104051040610407104081040910410104111041210413104141041510416104171041810419104201042110422104231042410425104261042710428104291043010431104321043310434104351043610437104381043910440104411044210443104441044510446104471044810449104501045110452104531045410455104561045710458104591046010461104621046310464104651046610467104681046910470104711047210473104741047510476104771047810479104801048110482104831048410485104861048710488104891049010491104921049310494104951049610497104981049910500105011050210503105041050510506105071050810509105101051110512105131051410515105161051710518105191052010521105221052310524105251052610527105281052910530105311053210533105341053510536105371053810539105401054110542105431054410545105461054710548105491055010551105521055310554105551055610557105581055910560105611056210563105641056510566105671056810569105701057110572105731057410575105761057710578105791058010581105821058310584105851058610587105881058910590105911059210593105941059510596105971059810599106001060110602106031060410605106061060710608106091061010611106121061310614106151061610617106181061910620106211062210623106241062510626106271062810629106301063110632106331063410635106361063710638106391064010641106421064310644106451064610647106481064910650106511065210653106541065510656106571065810659106601066110662106631066410665106661066710668106691067010671106721067310674106751067610677106781067910680106811068210683106841068510686106871068810689106901069110692106931069410695106961069710698106991070010701107021070310704107051070610707107081070910710107111071210713107141071510716107171071810719107201072110722107231072410725107261072710728107291073010731107321073310734107351073610737107381073910740107411074210743107441074510746107471074810749107501075110752107531075410755107561075710758107591076010761107621076310764107651076610767107681076910770107711077210773107741077510776107771077810779107801078110782107831078410785107861078710788107891079010791107921079310794107951079610797107981079910800108011080210803108041080510806108071080810809108101081110812108131081410815108161081710818108191082010821108221082310824108251082610827108281082910830108311083210833108341083510836108371083810839108401084110842108431084410845108461084710848108491085010851108521085310854108551085610857108581085910860108611086210863108641086510866108671086810869108701087110872108731087410875108761087710878108791088010881108821088310884108851088610887108881088910890108911089210893108941089510896108971089810899109001090110902109031090410905109061090710908109091091010911109121091310914109151091610917109181091910920109211092210923109241092510926109271092810929109301093110932109331093410935109361093710938109391094010941109421094310944109451094610947109481094910950109511095210953109541095510956109571095810959109601096110962109631096410965109661096710968109691097010971109721097310974109751097610977109781097910980109811098210983109841098510986109871098810989109901099110992109931099410995109961099710998109991100011001110021100311004110051100611007110081100911010110111101211013110141101511016110171101811019110201102111022110231102411025110261102711028110291103011031110321103311034110351103611037110381103911040110411104211043110441104511046110471104811049110501105111052110531105411055110561105711058110591106011061110621106311064110651106611067110681106911070110711107211073110741107511076110771107811079110801108111082110831108411085110861108711088110891109011091110921109311094110951109611097110981109911100111011110211103111041110511106111071110811109111101111111112111131111411115111161111711118111191112011121111221112311124111251112611127111281112911130111311113211133111341113511136111371113811139111401114111142111431114411145111461114711148111491115011151111521115311154111551115611157111581115911160111611116211163111641116511166111671116811169111701117111172111731117411175111761117711178111791118011181111821118311184111851118611187111881118911190111911119211193111941119511196111971119811199112001120111202112031120411205112061120711208112091121011211112121121311214112151121611217112181121911220112211122211223112241122511226112271122811229112301123111232112331123411235112361123711238112391124011241112421124311244112451124611247112481124911250112511125211253112541125511256112571125811259112601126111262112631126411265112661126711268112691127011271112721127311274112751127611277112781127911280112811128211283112841128511286112871128811289112901129111292112931129411295112961129711298112991130011301113021130311304113051130611307113081130911310113111131211313113141131511316113171131811319113201132111322113231132411325113261132711328113291133011331113321133311334113351133611337113381133911340113411134211343113441134511346113471134811349113501135111352113531135411355113561135711358113591136011361113621136311364113651136611367113681136911370113711137211373113741137511376113771137811379113801138111382113831138411385113861138711388113891139011391113921139311394113951139611397113981139911400114011140211403114041140511406114071140811409114101141111412114131141411415114161141711418114191142011421114221142311424114251142611427114281142911430114311143211433114341143511436114371143811439114401144111442114431144411445114461144711448114491145011451114521145311454114551145611457114581145911460114611146211463114641146511466114671146811469114701147111472114731147411475114761147711478114791148011481114821148311484114851148611487114881148911490114911149211493114941149511496114971149811499115001150111502115031150411505115061150711508115091151011511115121151311514115151151611517115181151911520115211152211523115241152511526115271152811529115301153111532115331153411535115361153711538115391154011541115421154311544115451154611547115481154911550115511155211553115541155511556115571155811559115601156111562115631156411565115661156711568115691157011571115721157311574115751157611577115781157911580115811158211583115841158511586115871158811589115901159111592115931159411595115961159711598115991160011601116021160311604116051160611607116081160911610116111161211613116141161511616116171161811619116201162111622116231162411625116261162711628116291163011631116321163311634116351163611637116381163911640116411164211643116441164511646116471164811649116501165111652116531165411655116561165711658116591166011661116621166311664116651166611667116681166911670116711167211673116741167511676116771167811679116801168111682116831168411685116861168711688116891169011691116921169311694116951169611697116981169911700117011170211703117041170511706117071170811709117101171111712117131171411715117161171711718117191172011721117221172311724117251172611727117281172911730117311173211733117341173511736117371173811739117401174111742117431174411745117461174711748117491175011751117521175311754117551175611757117581175911760117611176211763117641176511766117671176811769117701177111772117731177411775117761177711778117791178011781117821178311784117851178611787117881178911790117911179211793117941179511796117971179811799118001180111802118031180411805118061180711808118091181011811118121181311814118151181611817118181181911820118211182211823118241182511826118271182811829118301183111832118331183411835118361183711838118391184011841118421184311844118451184611847118481184911850118511185211853118541185511856118571185811859118601186111862118631186411865118661186711868118691187011871118721187311874118751187611877118781187911880118811188211883118841188511886118871188811889118901189111892118931189411895118961189711898118991190011901119021190311904119051190611907119081190911910119111191211913119141191511916119171191811919119201192111922119231192411925119261192711928119291193011931119321193311934119351193611937119381193911940119411194211943119441194511946119471194811949119501195111952119531195411955119561195711958119591196011961119621196311964119651196611967119681196911970119711197211973119741197511976119771197811979119801198111982119831198411985119861198711988119891199011991119921199311994119951199611997119981199912000120011200212003120041200512006120071200812009120101201112012120131201412015120161201712018120191202012021120221202312024120251202612027120281202912030120311203212033120341203512036120371203812039120401204112042120431204412045120461204712048120491205012051120521205312054120551205612057120581205912060120611206212063120641206512066120671206812069120701207112072120731207412075120761207712078120791208012081120821208312084120851208612087120881208912090120911209212093120941209512096120971209812099121001210112102121031210412105121061210712108121091211012111121121211312114121151211612117121181211912120121211212212123121241212512126121271212812129121301213112132121331213412135121361213712138121391214012141121421214312144121451214612147121481214912150121511215212153121541215512156121571215812159121601216112162121631216412165121661216712168121691217012171121721217312174121751217612177121781217912180121811218212183121841218512186121871218812189121901219112192121931219412195121961219712198121991220012201122021220312204122051220612207122081220912210122111221212213122141221512216122171221812219122201222112222122231222412225122261222712228122291223012231122321223312234122351223612237122381223912240122411224212243122441224512246122471224812249122501225112252122531225412255122561225712258122591226012261122621226312264122651226612267122681226912270122711227212273122741227512276122771227812279122801228112282122831228412285122861228712288122891229012291122921229312294122951229612297122981229912300123011230212303123041230512306123071230812309123101231112312123131231412315123161231712318123191232012321123221232312324123251232612327123281232912330123311233212333123341233512336123371233812339123401234112342123431234412345123461234712348123491235012351123521235312354123551235612357123581235912360123611236212363123641236512366123671236812369123701237112372123731237412375123761237712378123791238012381123821238312384123851238612387123881238912390123911239212393123941239512396123971239812399124001240112402124031240412405124061240712408124091241012411124121241312414124151241612417124181241912420124211242212423124241242512426124271242812429124301243112432124331243412435124361243712438124391244012441124421244312444124451244612447124481244912450124511245212453124541245512456124571245812459124601246112462124631246412465124661246712468124691247012471124721247312474124751247612477124781247912480124811248212483124841248512486124871248812489124901249112492124931249412495124961249712498124991250012501125021250312504125051250612507125081250912510125111251212513125141251512516125171251812519125201252112522125231252412525125261252712528125291253012531125321253312534125351253612537125381253912540125411254212543125441254512546125471254812549125501255112552125531255412555125561255712558125591256012561125621256312564125651256612567125681256912570125711257212573125741257512576125771257812579125801258112582125831258412585125861258712588125891259012591125921259312594125951259612597125981259912600126011260212603126041260512606126071260812609126101261112612126131261412615126161261712618126191262012621126221262312624126251262612627126281262912630126311263212633126341263512636126371263812639126401264112642126431264412645126461264712648126491265012651126521265312654126551265612657126581265912660126611266212663126641266512666126671266812669126701267112672126731267412675126761267712678126791268012681126821268312684126851268612687126881268912690126911269212693126941269512696126971269812699127001270112702127031270412705127061270712708127091271012711127121271312714127151271612717127181271912720127211272212723127241272512726127271272812729127301273112732127331273412735127361273712738127391274012741127421274312744127451274612747127481274912750127511275212753127541275512756127571275812759127601276112762127631276412765127661276712768127691277012771127721277312774127751277612777127781277912780127811278212783127841278512786127871278812789127901279112792127931279412795127961279712798127991280012801128021280312804128051280612807128081280912810128111281212813128141281512816128171281812819128201282112822128231282412825128261282712828128291283012831128321283312834128351283612837128381283912840128411284212843128441284512846128471284812849128501285112852128531285412855128561285712858128591286012861128621286312864128651286612867128681286912870128711287212873128741287512876128771287812879128801288112882128831288412885128861288712888128891289012891128921289312894128951289612897128981289912900129011290212903129041290512906129071290812909129101291112912129131291412915129161291712918129191292012921129221292312924129251292612927129281292912930129311293212933129341293512936129371293812939129401294112942129431294412945129461294712948129491295012951129521295312954129551295612957129581295912960129611296212963129641296512966129671296812969129701297112972129731297412975129761297712978129791298012981129821298312984129851298612987129881298912990129911299212993129941299512996129971299812999130001300113002130031300413005130061300713008130091301013011130121301313014130151301613017130181301913020130211302213023130241302513026130271302813029130301303113032130331303413035130361303713038130391304013041130421304313044130451304613047130481304913050130511305213053130541305513056130571305813059130601306113062130631306413065130661306713068130691307013071130721307313074130751307613077130781307913080130811308213083130841308513086130871308813089130901309113092130931309413095130961309713098130991310013101131021310313104131051310613107131081310913110131111311213113131141311513116131171311813119131201312113122131231312413125131261312713128131291313013131131321313313134131351313613137131381313913140131411314213143131441314513146131471314813149131501315113152131531315413155131561315713158131591316013161131621316313164131651316613167131681316913170131711317213173131741317513176131771317813179131801318113182131831318413185131861318713188131891319013191131921319313194131951319613197131981319913200132011320213203132041320513206132071320813209132101321113212132131321413215132161321713218132191322013221132221322313224132251322613227132281322913230132311323213233132341323513236132371323813239132401324113242132431324413245132461324713248132491325013251132521325313254132551325613257132581325913260132611326213263132641326513266132671326813269132701327113272132731327413275132761327713278132791328013281132821328313284132851328613287132881328913290132911329213293132941329513296132971329813299133001330113302133031330413305133061330713308133091331013311133121331313314133151331613317133181331913320133211332213323133241332513326133271332813329133301333113332133331333413335133361333713338133391334013341133421334313344133451334613347133481334913350133511335213353133541335513356133571335813359133601336113362133631336413365133661336713368133691337013371133721337313374133751337613377133781337913380133811338213383133841338513386133871338813389133901339113392133931339413395133961339713398133991340013401134021340313404134051340613407134081340913410134111341213413134141341513416134171341813419134201342113422134231342413425134261342713428134291343013431134321343313434134351343613437134381343913440134411344213443134441344513446134471344813449134501345113452134531345413455134561345713458134591346013461134621346313464134651346613467134681346913470134711347213473134741347513476134771347813479134801348113482134831348413485134861348713488134891349013491134921349313494134951349613497134981349913500135011350213503135041350513506135071350813509135101351113512135131351413515135161351713518135191352013521135221352313524135251352613527135281352913530135311353213533135341353513536135371353813539135401354113542135431354413545135461354713548135491355013551135521355313554135551355613557135581355913560135611356213563135641356513566135671356813569135701357113572135731357413575135761357713578135791358013581135821358313584135851358613587135881358913590135911359213593135941359513596135971359813599136001360113602136031360413605136061360713608136091361013611136121361313614136151361613617136181361913620136211362213623136241362513626136271362813629136301363113632136331363413635136361363713638136391364013641136421364313644136451364613647136481364913650136511365213653136541365513656136571365813659136601366113662136631366413665136661366713668136691367013671136721367313674136751367613677136781367913680136811368213683136841368513686136871368813689136901369113692136931369413695136961369713698136991370013701137021370313704137051370613707137081370913710137111371213713137141371513716137171371813719137201372113722137231372413725137261372713728137291373013731137321373313734137351373613737137381373913740137411374213743137441374513746137471374813749137501375113752137531375413755137561375713758137591376013761137621376313764137651376613767137681376913770137711377213773137741377513776137771377813779137801378113782137831378413785137861378713788137891379013791137921379313794137951379613797137981379913800138011380213803138041380513806138071380813809138101381113812138131381413815138161381713818138191382013821138221382313824138251382613827138281382913830138311383213833138341383513836138371383813839138401384113842138431384413845138461384713848138491385013851138521385313854138551385613857138581385913860138611386213863138641386513866138671386813869138701387113872138731387413875138761387713878138791388013881138821388313884138851388613887138881388913890138911389213893138941389513896138971389813899139001390113902139031390413905139061390713908139091391013911139121391313914139151391613917139181391913920139211392213923139241392513926139271392813929139301393113932139331393413935139361393713938139391394013941139421394313944139451394613947139481394913950139511395213953139541395513956139571395813959139601396113962139631396413965139661396713968139691397013971139721397313974139751397613977139781397913980139811398213983139841398513986139871398813989139901399113992139931399413995139961399713998139991400014001140021400314004140051400614007140081400914010140111401214013140141401514016140171401814019140201402114022140231402414025140261402714028140291403014031140321403314034140351403614037140381403914040140411404214043140441404514046140471404814049140501405114052140531405414055140561405714058140591406014061140621406314064140651406614067140681406914070140711407214073140741407514076140771407814079140801408114082140831408414085140861408714088140891409014091140921409314094140951409614097140981409914100141011410214103141041410514106141071410814109141101411114112141131411414115141161411714118141191412014121141221412314124141251412614127141281412914130141311413214133141341413514136141371413814139141401414114142141431414414145141461414714148141491415014151141521415314154141551415614157141581415914160141611416214163141641416514166141671416814169141701417114172141731417414175141761417714178141791418014181141821418314184141851418614187141881418914190141911419214193141941419514196141971419814199142001420114202142031420414205142061420714208142091421014211142121421314214142151421614217142181421914220142211422214223142241422514226142271422814229142301423114232142331423414235142361423714238142391424014241142421424314244142451424614247142481424914250142511425214253142541425514256142571425814259142601426114262142631426414265142661426714268142691427014271142721427314274142751427614277142781427914280142811428214283142841428514286142871428814289142901429114292142931429414295142961429714298142991430014301143021430314304143051430614307143081430914310143111431214313143141431514316143171431814319143201432114322143231432414325143261432714328143291433014331143321433314334143351433614337143381433914340143411434214343143441434514346143471434814349143501435114352143531435414355143561435714358143591436014361143621436314364143651436614367143681436914370143711437214373143741437514376143771437814379143801438114382143831438414385143861438714388143891439014391143921439314394143951439614397143981439914400144011440214403144041440514406144071440814409144101441114412144131441414415144161441714418144191442014421144221442314424144251442614427144281442914430144311443214433144341443514436144371443814439144401444114442144431444414445144461444714448144491445014451144521445314454144551445614457144581445914460144611446214463144641446514466144671446814469144701447114472144731447414475144761447714478144791448014481144821448314484144851448614487144881448914490144911449214493144941449514496144971449814499145001450114502145031450414505145061450714508145091451014511145121451314514145151451614517145181451914520145211452214523145241452514526145271452814529145301453114532145331453414535145361453714538145391454014541145421454314544145451454614547145481454914550145511455214553145541455514556145571455814559145601456114562145631456414565145661456714568145691457014571145721457314574145751457614577145781457914580145811458214583145841458514586145871458814589145901459114592145931459414595145961459714598145991460014601146021460314604146051460614607146081460914610146111461214613146141461514616146171461814619146201462114622146231462414625146261462714628146291463014631146321463314634146351463614637146381463914640146411464214643146441464514646146471464814649146501465114652146531465414655146561465714658146591466014661146621466314664146651466614667146681466914670146711467214673146741467514676146771467814679146801468114682146831468414685146861468714688146891469014691146921469314694146951469614697146981469914700147011470214703147041470514706147071470814709147101471114712147131471414715147161471714718147191472014721147221472314724147251472614727147281472914730147311473214733147341473514736147371473814739147401474114742147431474414745147461474714748147491475014751147521475314754147551475614757147581475914760147611476214763147641476514766147671476814769147701477114772147731477414775147761477714778147791478014781147821478314784147851478614787147881478914790147911479214793147941479514796147971479814799148001480114802148031480414805148061480714808148091481014811148121481314814148151481614817148181481914820148211482214823148241482514826148271482814829148301483114832148331483414835148361483714838148391484014841148421484314844148451484614847148481484914850148511485214853148541485514856148571485814859148601486114862148631486414865148661486714868148691487014871148721487314874148751487614877148781487914880148811488214883148841488514886148871488814889148901489114892148931489414895148961489714898148991490014901149021490314904149051490614907149081490914910149111491214913149141491514916149171491814919149201492114922149231492414925149261492714928149291493014931149321493314934149351493614937149381493914940149411494214943149441494514946149471494814949149501495114952149531495414955149561495714958149591496014961149621496314964149651496614967149681496914970149711497214973149741497514976149771497814979149801498114982149831498414985149861498714988149891499014991149921499314994149951499614997149981499915000150011500215003150041500515006150071500815009150101501115012150131501415015150161501715018150191502015021150221502315024150251502615027150281502915030150311503215033150341503515036150371503815039150401504115042150431504415045150461504715048150491505015051150521505315054150551505615057150581505915060150611506215063150641506515066150671506815069150701507115072150731507415075150761507715078150791508015081150821508315084150851508615087150881508915090150911509215093150941509515096150971509815099151001510115102151031510415105151061510715108151091511015111151121511315114151151511615117151181511915120151211512215123151241512515126151271512815129151301513115132151331513415135151361513715138151391514015141151421514315144151451514615147151481514915150151511515215153151541515515156151571515815159151601516115162151631516415165151661516715168151691517015171151721517315174151751517615177151781517915180151811518215183151841518515186151871518815189151901519115192151931519415195151961519715198151991520015201152021520315204152051520615207152081520915210152111521215213152141521515216152171521815219152201522115222152231522415225152261522715228152291523015231152321523315234152351523615237152381523915240152411524215243152441524515246152471524815249152501525115252152531525415255152561525715258152591526015261152621526315264152651526615267152681526915270152711527215273152741527515276152771527815279152801528115282152831528415285152861528715288152891529015291152921529315294152951529615297152981529915300153011530215303153041530515306153071530815309153101531115312153131531415315153161531715318153191532015321153221532315324153251532615327153281532915330153311533215333153341533515336153371533815339153401534115342153431534415345153461534715348153491535015351153521535315354153551535615357153581535915360153611536215363153641536515366153671536815369153701537115372153731537415375153761537715378153791538015381153821538315384153851538615387153881538915390153911539215393153941539515396153971539815399154001540115402154031540415405154061540715408154091541015411154121541315414154151541615417154181541915420154211542215423154241542515426154271542815429154301543115432154331543415435154361543715438154391544015441154421544315444154451544615447154481544915450154511545215453154541545515456154571545815459154601546115462154631546415465154661546715468154691547015471154721547315474154751547615477154781547915480154811548215483154841548515486154871548815489154901549115492154931549415495154961549715498154991550015501155021550315504155051550615507155081550915510155111551215513155141551515516155171551815519155201552115522155231552415525155261552715528155291553015531155321553315534155351553615537155381553915540155411554215543155441554515546155471554815549155501555115552155531555415555155561555715558155591556015561155621556315564155651556615567155681556915570155711557215573155741557515576155771557815579155801558115582155831558415585155861558715588155891559015591155921559315594155951559615597155981559915600156011560215603156041560515606156071560815609156101561115612156131561415615156161561715618156191562015621156221562315624156251562615627156281562915630156311563215633156341563515636156371563815639156401564115642156431564415645156461564715648156491565015651156521565315654156551565615657156581565915660156611566215663156641566515666156671566815669156701567115672156731567415675156761567715678156791568015681156821568315684156851568615687156881568915690156911569215693156941569515696156971569815699157001570115702157031570415705157061570715708157091571015711157121571315714157151571615717157181571915720157211572215723157241572515726157271572815729157301573115732157331573415735157361573715738157391574015741157421574315744157451574615747157481574915750157511575215753157541575515756157571575815759157601576115762157631576415765157661576715768157691577015771157721577315774157751577615777157781577915780157811578215783157841578515786157871578815789157901579115792157931579415795157961579715798157991580015801158021580315804158051580615807158081580915810158111581215813158141581515816158171581815819158201582115822158231582415825158261582715828158291583015831158321583315834158351583615837158381583915840158411584215843158441584515846158471584815849158501585115852158531585415855158561585715858158591586015861158621586315864158651586615867158681586915870158711587215873158741587515876158771587815879158801588115882158831588415885158861588715888158891589015891158921589315894158951589615897158981589915900159011590215903159041590515906159071590815909159101591115912159131591415915159161591715918159191592015921159221592315924159251592615927159281592915930159311593215933159341593515936159371593815939159401594115942159431594415945159461594715948159491595015951159521595315954159551595615957159581595915960159611596215963159641596515966159671596815969159701597115972159731597415975159761597715978159791598015981159821598315984159851598615987159881598915990159911599215993159941599515996159971599815999160001600116002160031600416005160061600716008160091601016011160121601316014160151601616017160181601916020160211602216023160241602516026160271602816029160301603116032160331603416035160361603716038160391604016041160421604316044160451604616047160481604916050160511605216053160541605516056160571605816059160601606116062160631606416065160661606716068160691607016071160721607316074160751607616077160781607916080160811608216083160841608516086160871608816089160901609116092160931609416095160961609716098160991610016101161021610316104161051610616107161081610916110161111611216113161141611516116161171611816119161201612116122161231612416125161261612716128161291613016131161321613316134161351613616137161381613916140161411614216143161441614516146161471614816149161501615116152161531615416155161561615716158161591616016161161621616316164161651616616167161681616916170161711617216173161741617516176161771617816179161801618116182161831618416185161861618716188161891619016191161921619316194161951619616197161981619916200162011620216203162041620516206162071620816209162101621116212162131621416215162161621716218162191622016221162221622316224162251622616227162281622916230162311623216233162341623516236162371623816239162401624116242162431624416245162461624716248162491625016251162521625316254162551625616257162581625916260162611626216263162641626516266162671626816269162701627116272162731627416275162761627716278162791628016281162821628316284162851628616287162881628916290162911629216293162941629516296162971629816299163001630116302163031630416305163061630716308163091631016311163121631316314163151631616317163181631916320163211632216323163241632516326163271632816329163301633116332163331633416335163361633716338163391634016341163421634316344163451634616347163481634916350163511635216353163541635516356163571635816359163601636116362163631636416365163661636716368163691637016371163721637316374163751637616377163781637916380163811638216383163841638516386163871638816389163901639116392163931639416395163961639716398163991640016401164021640316404164051640616407164081640916410164111641216413164141641516416164171641816419164201642116422164231642416425164261642716428164291643016431164321643316434164351643616437164381643916440164411644216443164441644516446164471644816449164501645116452164531645416455164561645716458164591646016461164621646316464164651646616467164681646916470164711647216473164741647516476164771647816479164801648116482164831648416485164861648716488164891649016491164921649316494164951649616497164981649916500165011650216503165041650516506165071650816509165101651116512165131651416515165161651716518165191652016521165221652316524165251652616527165281652916530165311653216533165341653516536165371653816539165401654116542165431654416545165461654716548165491655016551165521655316554165551655616557165581655916560165611656216563165641656516566165671656816569165701657116572165731657416575165761657716578165791658016581165821658316584165851658616587165881658916590165911659216593165941659516596165971659816599166001660116602166031660416605166061660716608166091661016611166121661316614166151661616617166181661916620166211662216623166241662516626166271662816629166301663116632166331663416635166361663716638166391664016641166421664316644166451664616647166481664916650166511665216653166541665516656166571665816659166601666116662166631666416665166661666716668166691667016671166721667316674166751667616677166781667916680166811668216683166841668516686166871668816689166901669116692166931669416695166961669716698166991670016701167021670316704167051670616707167081670916710167111671216713167141671516716167171671816719167201672116722167231672416725167261672716728167291673016731167321673316734167351673616737167381673916740167411674216743167441674516746167471674816749167501675116752167531675416755167561675716758167591676016761167621676316764167651676616767167681676916770167711677216773167741677516776167771677816779167801678116782167831678416785167861678716788167891679016791167921679316794167951679616797167981679916800168011680216803168041680516806168071680816809168101681116812168131681416815168161681716818168191682016821168221682316824168251682616827168281682916830168311683216833168341683516836168371683816839168401684116842168431684416845168461684716848168491685016851168521685316854168551685616857168581685916860168611686216863168641686516866168671686816869168701687116872168731687416875168761687716878168791688016881168821688316884168851688616887168881688916890168911689216893168941689516896168971689816899169001690116902169031690416905169061690716908169091691016911169121691316914169151691616917169181691916920169211692216923169241692516926169271692816929169301693116932169331693416935169361693716938169391694016941169421694316944169451694616947169481694916950169511695216953169541695516956169571695816959169601696116962169631696416965169661696716968169691697016971169721697316974169751697616977169781697916980169811698216983169841698516986169871698816989169901699116992169931699416995169961699716998169991700017001170021700317004170051700617007170081700917010170111701217013170141701517016170171701817019170201702117022170231702417025170261702717028170291703017031170321703317034170351703617037170381703917040170411704217043170441704517046170471704817049170501705117052170531705417055170561705717058170591706017061170621706317064170651706617067170681706917070170711707217073170741707517076170771707817079170801708117082170831708417085170861708717088170891709017091170921709317094170951709617097170981709917100171011710217103171041710517106171071710817109171101711117112171131711417115171161711717118171191712017121171221712317124171251712617127171281712917130171311713217133171341713517136171371713817139171401714117142171431714417145171461714717148171491715017151171521715317154171551715617157171581715917160171611716217163171641716517166171671716817169171701717117172171731717417175171761717717178171791718017181171821718317184171851718617187171881718917190171911719217193171941719517196171971719817199172001720117202172031720417205172061720717208172091721017211172121721317214172151721617217172181721917220172211722217223172241722517226172271722817229172301723117232172331723417235172361723717238172391724017241172421724317244172451724617247172481724917250172511725217253172541725517256172571725817259172601726117262172631726417265172661726717268172691727017271172721727317274172751727617277172781727917280172811728217283172841728517286172871728817289172901729117292172931729417295172961729717298172991730017301173021730317304173051730617307173081730917310173111731217313173141731517316173171731817319173201732117322173231732417325173261732717328173291733017331173321733317334173351733617337173381733917340173411734217343173441734517346173471734817349173501735117352173531735417355173561735717358173591736017361173621736317364173651736617367173681736917370173711737217373173741737517376173771737817379173801738117382173831738417385173861738717388173891739017391173921739317394173951739617397173981739917400174011740217403174041740517406174071740817409174101741117412174131741417415174161741717418174191742017421174221742317424174251742617427174281742917430174311743217433174341743517436174371743817439174401744117442174431744417445174461744717448174491745017451174521745317454174551745617457174581745917460174611746217463174641746517466174671746817469174701747117472174731747417475174761747717478174791748017481174821748317484174851748617487174881748917490174911749217493174941749517496174971749817499175001750117502175031750417505175061750717508175091751017511175121751317514175151751617517175181751917520175211752217523175241752517526175271752817529175301753117532175331753417535175361753717538175391754017541175421754317544175451754617547175481754917550175511755217553175541755517556175571755817559175601756117562175631756417565175661756717568175691757017571175721757317574175751757617577175781757917580175811758217583175841758517586175871758817589175901759117592175931759417595175961759717598175991760017601176021760317604176051760617607176081760917610176111761217613176141761517616176171761817619176201762117622176231762417625176261762717628176291763017631176321763317634176351763617637176381763917640176411764217643176441764517646176471764817649176501765117652176531765417655176561765717658176591766017661176621766317664176651766617667176681766917670176711767217673176741767517676176771767817679176801768117682176831768417685176861768717688176891769017691176921769317694176951769617697176981769917700177011770217703177041770517706177071770817709177101771117712177131771417715177161771717718177191772017721177221772317724177251772617727177281772917730177311773217733177341773517736177371773817739177401774117742177431774417745177461774717748177491775017751177521775317754177551775617757177581775917760177611776217763177641776517766177671776817769177701777117772177731777417775177761777717778177791778017781177821778317784177851778617787177881778917790177911779217793177941779517796177971779817799178001780117802178031780417805178061780717808178091781017811178121781317814178151781617817178181781917820178211782217823178241782517826178271782817829178301783117832178331783417835178361783717838178391784017841178421784317844178451784617847178481784917850178511785217853178541785517856178571785817859178601786117862178631786417865178661786717868178691787017871178721787317874178751787617877178781787917880178811788217883178841788517886178871788817889178901789117892178931789417895178961789717898178991790017901179021790317904179051790617907179081790917910179111791217913179141791517916179171791817919179201792117922179231792417925179261792717928179291793017931179321793317934179351793617937179381793917940179411794217943179441794517946179471794817949179501795117952179531795417955179561795717958179591796017961179621796317964179651796617967179681796917970179711797217973179741797517976179771797817979179801798117982179831798417985179861798717988179891799017991179921799317994179951799617997179981799918000180011800218003180041800518006180071800818009180101801118012180131801418015180161801718018180191802018021180221802318024180251802618027180281802918030180311803218033180341803518036180371803818039180401804118042180431804418045180461804718048180491805018051180521805318054180551805618057180581805918060180611806218063180641806518066180671806818069180701807118072180731807418075180761807718078180791808018081180821808318084180851808618087180881808918090180911809218093180941809518096180971809818099181001810118102181031810418105181061810718108181091811018111181121811318114181151811618117181181811918120181211812218123181241812518126181271812818129181301813118132181331813418135181361813718138181391814018141181421814318144181451814618147181481814918150181511815218153181541815518156181571815818159181601816118162181631816418165181661816718168181691817018171181721817318174181751817618177181781817918180181811818218183181841818518186181871818818189181901819118192181931819418195181961819718198181991820018201182021820318204182051820618207182081820918210182111821218213182141821518216182171821818219182201822118222182231822418225182261822718228182291823018231182321823318234182351823618237182381823918240182411824218243182441824518246182471824818249182501825118252182531825418255182561825718258182591826018261182621826318264182651826618267182681826918270182711827218273182741827518276182771827818279182801828118282182831828418285182861828718288182891829018291182921829318294182951829618297182981829918300183011830218303183041830518306183071830818309183101831118312183131831418315183161831718318183191832018321183221832318324183251832618327183281832918330183311833218333183341833518336183371833818339183401834118342183431834418345183461834718348183491835018351183521835318354183551835618357183581835918360183611836218363183641836518366183671836818369183701837118372183731837418375183761837718378183791838018381183821838318384183851838618387183881838918390183911839218393183941839518396183971839818399184001840118402184031840418405184061840718408184091841018411184121841318414184151841618417184181841918420184211842218423184241842518426184271842818429184301843118432184331843418435184361843718438184391844018441184421844318444184451844618447184481844918450184511845218453184541845518456184571845818459184601846118462184631846418465184661846718468184691847018471184721847318474184751847618477184781847918480184811848218483184841848518486184871848818489184901849118492184931849418495184961849718498184991850018501185021850318504185051850618507185081850918510185111851218513185141851518516185171851818519185201852118522185231852418525185261852718528185291853018531185321853318534185351853618537185381853918540185411854218543185441854518546185471854818549185501855118552185531855418555185561855718558185591856018561185621856318564185651856618567185681856918570185711857218573185741857518576185771857818579185801858118582185831858418585185861858718588185891859018591185921859318594185951859618597185981859918600186011860218603186041860518606186071860818609186101861118612186131861418615186161861718618186191862018621186221862318624186251862618627186281862918630186311863218633186341863518636186371863818639186401864118642186431864418645186461864718648186491865018651186521865318654186551865618657186581865918660186611866218663186641866518666186671866818669186701867118672186731867418675186761867718678186791868018681186821868318684186851868618687186881868918690186911869218693186941869518696186971869818699187001870118702187031870418705187061870718708187091871018711187121871318714187151871618717187181871918720187211872218723187241872518726187271872818729187301873118732187331873418735187361873718738187391874018741187421874318744187451874618747187481874918750187511875218753187541875518756187571875818759187601876118762187631876418765187661876718768187691877018771187721877318774187751877618777187781877918780187811878218783187841878518786187871878818789187901879118792187931879418795187961879718798187991880018801188021880318804188051880618807188081880918810188111881218813188141881518816188171881818819188201882118822188231882418825188261882718828188291883018831188321883318834188351883618837188381883918840188411884218843188441884518846188471884818849188501885118852188531885418855188561885718858188591886018861188621886318864188651886618867188681886918870188711887218873188741887518876188771887818879188801888118882188831888418885188861888718888188891889018891188921889318894188951889618897188981889918900189011890218903189041890518906189071890818909189101891118912189131891418915189161891718918189191892018921189221892318924189251892618927189281892918930189311893218933189341893518936189371893818939189401894118942189431894418945189461894718948189491895018951189521895318954189551895618957189581895918960189611896218963189641896518966189671896818969189701897118972189731897418975189761897718978189791898018981189821898318984189851898618987189881898918990189911899218993189941899518996189971899818999190001900119002190031900419005190061900719008190091901019011190121901319014190151901619017190181901919020190211902219023190241902519026190271902819029190301903119032190331903419035190361903719038190391904019041190421904319044190451904619047190481904919050190511905219053190541905519056190571905819059190601906119062190631906419065190661906719068190691907019071190721907319074190751907619077190781907919080190811908219083190841908519086190871908819089190901909119092190931909419095190961909719098190991910019101191021910319104191051910619107191081910919110191111911219113191141911519116191171911819119191201912119122191231912419125191261912719128191291913019131191321913319134191351913619137191381913919140191411914219143191441914519146191471914819149191501915119152191531915419155191561915719158191591916019161191621916319164191651916619167191681916919170191711917219173191741917519176191771917819179191801918119182191831918419185191861918719188191891919019191191921919319194191951919619197191981919919200192011920219203192041920519206192071920819209192101921119212192131921419215192161921719218192191922019221192221922319224192251922619227192281922919230192311923219233192341923519236192371923819239192401924119242192431924419245192461924719248192491925019251192521925319254192551925619257192581925919260192611926219263192641926519266192671926819269192701927119272192731927419275192761927719278192791928019281192821928319284192851928619287192881928919290192911929219293192941929519296192971929819299193001930119302193031930419305193061930719308193091931019311193121931319314193151931619317193181931919320193211932219323193241932519326193271932819329193301933119332193331933419335193361933719338193391934019341193421934319344193451934619347193481934919350193511935219353193541935519356193571935819359193601936119362193631936419365193661936719368193691937019371193721937319374193751937619377193781937919380193811938219383193841938519386193871938819389193901939119392193931939419395193961939719398193991940019401194021940319404194051940619407194081940919410194111941219413194141941519416194171941819419194201942119422194231942419425194261942719428194291943019431194321943319434194351943619437194381943919440194411944219443194441944519446194471944819449194501945119452194531945419455194561945719458194591946019461194621946319464194651946619467194681946919470194711947219473194741947519476194771947819479194801948119482194831948419485194861948719488194891949019491194921949319494194951949619497194981949919500195011950219503195041950519506195071950819509195101951119512195131951419515195161951719518195191952019521195221952319524195251952619527195281952919530195311953219533195341953519536195371953819539195401954119542195431954419545195461954719548195491955019551195521955319554195551955619557195581955919560195611956219563195641956519566195671956819569195701957119572195731957419575195761957719578195791958019581195821958319584195851958619587195881958919590195911959219593195941959519596195971959819599196001960119602196031960419605196061960719608196091961019611196121961319614196151961619617196181961919620196211962219623196241962519626196271962819629196301963119632196331963419635196361963719638196391964019641196421964319644196451964619647196481964919650196511965219653196541965519656196571965819659196601966119662196631966419665196661966719668196691967019671196721967319674196751967619677196781967919680196811968219683196841968519686196871968819689196901969119692196931969419695196961969719698196991970019701197021970319704197051970619707197081970919710197111971219713197141971519716197171971819719197201972119722197231972419725197261972719728197291973019731197321973319734197351973619737197381973919740197411974219743197441974519746197471974819749197501975119752197531975419755197561975719758197591976019761197621976319764197651976619767197681976919770197711977219773197741977519776197771977819779197801978119782197831978419785197861978719788197891979019791197921979319794197951979619797197981979919800198011980219803198041980519806198071980819809198101981119812198131981419815198161981719818198191982019821198221982319824198251982619827198281982919830198311983219833198341983519836198371983819839198401984119842198431984419845198461984719848198491985019851198521985319854198551985619857198581985919860198611986219863198641986519866198671986819869198701987119872198731987419875198761987719878198791988019881198821988319884198851988619887198881988919890198911989219893198941989519896198971989819899199001990119902199031990419905199061990719908199091991019911199121991319914199151991619917199181991919920199211992219923199241992519926199271992819929199301993119932199331993419935199361993719938199391994019941199421994319944199451994619947199481994919950199511995219953199541995519956199571995819959199601996119962199631996419965199661996719968199691997019971199721997319974199751997619977199781997919980199811998219983199841998519986199871998819989199901999119992199931999419995199961999719998199992000020001200022000320004200052000620007200082000920010200112001220013200142001520016200172001820019200202002120022200232002420025200262002720028200292003020031200322003320034200352003620037200382003920040200412004220043200442004520046200472004820049200502005120052200532005420055200562005720058200592006020061200622006320064200652006620067200682006920070200712007220073200742007520076200772007820079200802008120082200832008420085200862008720088200892009020091200922009320094200952009620097200982009920100201012010220103201042010520106201072010820109201102011120112201132011420115201162011720118201192012020121201222012320124201252012620127201282012920130201312013220133201342013520136201372013820139201402014120142201432014420145201462014720148201492015020151201522015320154201552015620157201582015920160201612016220163201642016520166201672016820169201702017120172201732017420175201762017720178201792018020181201822018320184201852018620187201882018920190201912019220193201942019520196201972019820199202002020120202202032020420205202062020720208202092021020211202122021320214202152021620217202182021920220202212022220223202242022520226202272022820229202302023120232202332023420235202362023720238202392024020241202422024320244202452024620247202482024920250202512025220253202542025520256202572025820259202602026120262202632026420265202662026720268202692027020271202722027320274202752027620277202782027920280202812028220283202842028520286202872028820289202902029120292202932029420295202962029720298202992030020301203022030320304203052030620307203082030920310203112031220313203142031520316203172031820319203202032120322203232032420325203262032720328203292033020331203322033320334203352033620337203382033920340203412034220343203442034520346203472034820349203502035120352203532035420355203562035720358203592036020361203622036320364203652036620367203682036920370203712037220373203742037520376203772037820379203802038120382203832038420385203862038720388203892039020391203922039320394203952039620397203982039920400204012040220403204042040520406204072040820409204102041120412204132041420415204162041720418204192042020421204222042320424204252042620427204282042920430204312043220433204342043520436204372043820439204402044120442204432044420445204462044720448204492045020451204522045320454204552045620457204582045920460204612046220463204642046520466204672046820469204702047120472204732047420475204762047720478204792048020481204822048320484204852048620487204882048920490204912049220493204942049520496204972049820499205002050120502205032050420505205062050720508205092051020511205122051320514205152051620517205182051920520205212052220523205242052520526205272052820529205302053120532205332053420535205362053720538205392054020541205422054320544205452054620547205482054920550205512055220553205542055520556205572055820559205602056120562205632056420565205662056720568205692057020571205722057320574205752057620577205782057920580205812058220583205842058520586205872058820589205902059120592205932059420595205962059720598205992060020601206022060320604206052060620607206082060920610206112061220613206142061520616206172061820619206202062120622206232062420625206262062720628206292063020631206322063320634206352063620637206382063920640206412064220643206442064520646206472064820649206502065120652206532065420655206562065720658206592066020661206622066320664206652066620667206682066920670206712067220673206742067520676206772067820679206802068120682206832068420685206862068720688206892069020691206922069320694206952069620697206982069920700207012070220703207042070520706207072070820709207102071120712207132071420715207162071720718207192072020721207222072320724207252072620727207282072920730207312073220733207342073520736207372073820739207402074120742207432074420745207462074720748207492075020751207522075320754207552075620757207582075920760207612076220763207642076520766207672076820769207702077120772207732077420775207762077720778207792078020781207822078320784207852078620787207882078920790207912079220793207942079520796207972079820799208002080120802208032080420805208062080720808208092081020811208122081320814208152081620817208182081920820208212082220823208242082520826208272082820829208302083120832208332083420835208362083720838208392084020841208422084320844208452084620847208482084920850208512085220853208542085520856208572085820859208602086120862208632086420865208662086720868208692087020871208722087320874208752087620877208782087920880208812088220883208842088520886208872088820889208902089120892208932089420895208962089720898208992090020901209022090320904209052090620907209082090920910209112091220913209142091520916209172091820919209202092120922209232092420925209262092720928209292093020931209322093320934209352093620937209382093920940209412094220943209442094520946209472094820949209502095120952209532095420955209562095720958209592096020961209622096320964209652096620967209682096920970209712097220973209742097520976209772097820979209802098120982209832098420985209862098720988209892099020991209922099320994209952099620997209982099921000210012100221003210042100521006210072100821009210102101121012210132101421015210162101721018210192102021021210222102321024210252102621027210282102921030210312103221033210342103521036210372103821039210402104121042210432104421045210462104721048210492105021051210522105321054210552105621057210582105921060210612106221063210642106521066210672106821069210702107121072210732107421075210762107721078210792108021081210822108321084210852108621087210882108921090210912109221093210942109521096210972109821099211002110121102211032110421105211062110721108211092111021111211122111321114211152111621117211182111921120211212112221123211242112521126211272112821129211302113121132211332113421135211362113721138211392114021141211422114321144211452114621147211482114921150211512115221153211542115521156211572115821159211602116121162211632116421165211662116721168211692117021171211722117321174211752117621177211782117921180211812118221183211842118521186211872118821189211902119121192211932119421195211962119721198211992120021201212022120321204212052120621207212082120921210212112121221213212142121521216212172121821219212202122121222212232122421225212262122721228212292123021231212322123321234212352123621237212382123921240212412124221243212442124521246212472124821249212502125121252212532125421255212562125721258212592126021261212622126321264212652126621267212682126921270212712127221273212742127521276212772127821279212802128121282212832128421285212862128721288212892129021291212922129321294212952129621297212982129921300213012130221303213042130521306213072130821309213102131121312213132131421315213162131721318213192132021321213222132321324213252132621327213282132921330213312133221333213342133521336213372133821339213402134121342213432134421345213462134721348213492135021351213522135321354213552135621357213582135921360213612136221363213642136521366213672136821369213702137121372213732137421375213762137721378213792138021381213822138321384213852138621387213882138921390213912139221393213942139521396213972139821399214002140121402214032140421405214062140721408214092141021411214122141321414214152141621417214182141921420214212142221423214242142521426214272142821429214302143121432214332143421435214362143721438214392144021441214422144321444214452144621447214482144921450214512145221453214542145521456214572145821459214602146121462214632146421465214662146721468214692147021471214722147321474214752147621477214782147921480214812148221483214842148521486214872148821489214902149121492214932149421495214962149721498214992150021501215022150321504215052150621507215082150921510215112151221513215142151521516215172151821519215202152121522215232152421525215262152721528215292153021531215322153321534215352153621537215382153921540215412154221543215442154521546215472154821549215502155121552215532155421555215562155721558215592156021561215622156321564215652156621567215682156921570215712157221573215742157521576215772157821579215802158121582215832158421585215862158721588215892159021591215922159321594215952159621597215982159921600216012160221603216042160521606216072160821609216102161121612216132161421615216162161721618216192162021621216222162321624216252162621627216282162921630216312163221633216342163521636216372163821639216402164121642216432164421645216462164721648216492165021651216522165321654216552165621657216582165921660216612166221663216642166521666216672166821669216702167121672216732167421675216762167721678216792168021681216822168321684216852168621687216882168921690216912169221693216942169521696216972169821699217002170121702217032170421705217062170721708217092171021711217122171321714217152171621717217182171921720217212172221723217242172521726217272172821729217302173121732217332173421735217362173721738217392174021741217422174321744217452174621747217482174921750217512175221753217542175521756217572175821759217602176121762217632176421765217662176721768217692177021771217722177321774217752177621777217782177921780217812178221783217842178521786217872178821789217902179121792217932179421795217962179721798217992180021801218022180321804218052180621807218082180921810218112181221813218142181521816218172181821819218202182121822218232182421825218262182721828218292183021831218322183321834218352183621837218382183921840218412184221843218442184521846218472184821849218502185121852218532185421855218562185721858218592186021861218622186321864218652186621867218682186921870218712187221873218742187521876218772187821879218802188121882218832188421885218862188721888218892189021891218922189321894218952189621897218982189921900219012190221903219042190521906219072190821909219102191121912219132191421915219162191721918219192192021921219222192321924219252192621927219282192921930219312193221933219342193521936219372193821939219402194121942219432194421945219462194721948219492195021951219522195321954219552195621957219582195921960219612196221963219642196521966219672196821969219702197121972219732197421975219762197721978219792198021981219822198321984219852198621987219882198921990219912199221993219942199521996219972199821999220002200122002220032200422005220062200722008220092201022011220122201322014220152201622017220182201922020220212202222023220242202522026220272202822029220302203122032220332203422035220362203722038220392204022041220422204322044220452204622047220482204922050220512205222053220542205522056220572205822059220602206122062220632206422065220662206722068220692207022071220722207322074220752207622077220782207922080220812208222083220842208522086220872208822089220902209122092220932209422095220962209722098220992210022101221022210322104221052210622107221082210922110221112211222113221142211522116221172211822119221202212122122221232212422125221262212722128221292213022131221322213322134221352213622137221382213922140221412214222143221442214522146221472214822149221502215122152221532215422155221562215722158221592216022161221622216322164221652216622167221682216922170221712217222173221742217522176221772217822179221802218122182221832218422185221862218722188221892219022191221922219322194221952219622197221982219922200222012220222203222042220522206222072220822209222102221122212222132221422215222162221722218222192222022221222222222322224222252222622227222282222922230222312223222233222342223522236222372223822239222402224122242222432224422245222462224722248222492225022251222522225322254222552225622257222582225922260222612226222263222642226522266222672226822269222702227122272222732227422275222762227722278222792228022281222822228322284222852228622287222882228922290222912229222293222942229522296222972229822299223002230122302223032230422305223062230722308223092231022311223122231322314223152231622317223182231922320223212232222323223242232522326223272232822329223302233122332223332233422335223362233722338223392234022341223422234322344223452234622347223482234922350223512235222353223542235522356223572235822359223602236122362223632236422365223662236722368223692237022371223722237322374223752237622377223782237922380223812238222383223842238522386223872238822389223902239122392223932239422395223962239722398223992240022401224022240322404224052240622407224082240922410224112241222413224142241522416224172241822419224202242122422224232242422425224262242722428224292243022431224322243322434224352243622437224382243922440224412244222443224442244522446224472244822449224502245122452224532245422455224562245722458224592246022461224622246322464224652246622467224682246922470224712247222473224742247522476224772247822479224802248122482224832248422485224862248722488224892249022491224922249322494224952249622497224982249922500225012250222503225042250522506225072250822509225102251122512225132251422515225162251722518225192252022521225222252322524225252252622527225282252922530225312253222533225342253522536225372253822539225402254122542225432254422545225462254722548225492255022551225522255322554225552255622557225582255922560225612256222563225642256522566225672256822569225702257122572225732257422575225762257722578225792258022581225822258322584225852258622587225882258922590225912259222593225942259522596225972259822599226002260122602226032260422605226062260722608226092261022611226122261322614226152261622617226182261922620226212262222623226242262522626226272262822629226302263122632226332263422635226362263722638226392264022641226422264322644226452264622647226482264922650226512265222653226542265522656226572265822659226602266122662226632266422665226662266722668226692267022671226722267322674226752267622677226782267922680226812268222683226842268522686226872268822689226902269122692226932269422695226962269722698226992270022701227022270322704227052270622707227082270922710227112271222713227142271522716227172271822719227202272122722227232272422725227262272722728227292273022731227322273322734227352273622737227382273922740227412274222743227442274522746227472274822749227502275122752227532275422755227562275722758227592276022761227622276322764227652276622767227682276922770227712277222773227742277522776227772277822779227802278122782227832278422785227862278722788227892279022791227922279322794227952279622797227982279922800228012280222803228042280522806228072280822809228102281122812228132281422815228162281722818228192282022821228222282322824228252282622827228282282922830228312283222833228342283522836228372283822839228402284122842228432284422845228462284722848228492285022851228522285322854228552285622857228582285922860228612286222863228642286522866228672286822869228702287122872228732287422875228762287722878228792288022881228822288322884228852288622887228882288922890228912289222893228942289522896228972289822899229002290122902229032290422905229062290722908229092291022911229122291322914229152291622917229182291922920229212292222923229242292522926229272292822929229302293122932229332293422935229362293722938229392294022941229422294322944229452294622947229482294922950229512295222953229542295522956229572295822959229602296122962229632296422965229662296722968229692297022971229722297322974229752297622977229782297922980229812298222983229842298522986229872298822989229902299122992229932299422995229962299722998229992300023001230022300323004230052300623007230082300923010230112301223013230142301523016230172301823019230202302123022230232302423025230262302723028230292303023031230322303323034230352303623037230382303923040230412304223043230442304523046230472304823049230502305123052230532305423055230562305723058230592306023061230622306323064230652306623067230682306923070230712307223073230742307523076230772307823079230802308123082230832308423085230862308723088230892309023091230922309323094230952309623097230982309923100231012310223103231042310523106231072310823109231102311123112231132311423115231162311723118231192312023121231222312323124231252312623127231282312923130231312313223133231342313523136231372313823139231402314123142231432314423145231462314723148231492315023151231522315323154231552315623157231582315923160231612316223163231642316523166231672316823169231702317123172231732317423175231762317723178231792318023181231822318323184231852318623187231882318923190231912319223193231942319523196231972319823199232002320123202232032320423205232062320723208232092321023211232122321323214232152321623217232182321923220232212322223223232242322523226232272322823229232302323123232232332323423235232362323723238232392324023241232422324323244232452324623247232482324923250232512325223253232542325523256232572325823259232602326123262232632326423265232662326723268232692327023271232722327323274232752327623277232782327923280232812328223283232842328523286232872328823289232902329123292232932329423295232962329723298232992330023301233022330323304233052330623307233082330923310233112331223313233142331523316233172331823319233202332123322233232332423325233262332723328233292333023331233322333323334233352333623337233382333923340233412334223343233442334523346233472334823349233502335123352233532335423355233562335723358233592336023361233622336323364233652336623367233682336923370233712337223373233742337523376233772337823379233802338123382233832338423385233862338723388233892339023391233922339323394233952339623397233982339923400234012340223403234042340523406234072340823409234102341123412234132341423415234162341723418234192342023421234222342323424234252342623427234282342923430234312343223433234342343523436234372343823439234402344123442234432344423445234462344723448234492345023451234522345323454234552345623457234582345923460234612346223463234642346523466234672346823469234702347123472234732347423475234762347723478234792348023481234822348323484234852348623487234882348923490234912349223493234942349523496234972349823499235002350123502235032350423505235062350723508235092351023511235122351323514235152351623517235182351923520235212352223523235242352523526235272352823529235302353123532235332353423535235362353723538235392354023541235422354323544235452354623547235482354923550235512355223553235542355523556235572355823559235602356123562235632356423565235662356723568235692357023571235722357323574235752357623577235782357923580235812358223583235842358523586235872358823589235902359123592235932359423595235962359723598235992360023601236022360323604236052360623607236082360923610236112361223613236142361523616236172361823619236202362123622236232362423625236262362723628236292363023631236322363323634236352363623637236382363923640236412364223643236442364523646236472364823649236502365123652236532365423655236562365723658236592366023661236622366323664236652366623667236682366923670236712367223673236742367523676236772367823679236802368123682236832368423685236862368723688236892369023691236922369323694236952369623697236982369923700237012370223703237042370523706237072370823709237102371123712237132371423715237162371723718237192372023721237222372323724237252372623727237282372923730237312373223733237342373523736237372373823739237402374123742237432374423745237462374723748237492375023751237522375323754237552375623757237582375923760237612376223763237642376523766237672376823769237702377123772237732377423775237762377723778237792378023781237822378323784237852378623787237882378923790237912379223793237942379523796237972379823799238002380123802238032380423805238062380723808238092381023811238122381323814238152381623817238182381923820238212382223823238242382523826238272382823829238302383123832238332383423835238362383723838238392384023841238422384323844238452384623847238482384923850238512385223853238542385523856238572385823859238602386123862238632386423865238662386723868238692387023871238722387323874238752387623877238782387923880238812388223883238842388523886238872388823889238902389123892238932389423895238962389723898238992390023901239022390323904239052390623907239082390923910239112391223913239142391523916239172391823919239202392123922239232392423925239262392723928239292393023931239322393323934239352393623937239382393923940239412394223943239442394523946239472394823949239502395123952239532395423955239562395723958239592396023961239622396323964239652396623967239682396923970239712397223973239742397523976239772397823979239802398123982239832398423985239862398723988239892399023991239922399323994239952399623997239982399924000240012400224003240042400524006240072400824009240102401124012240132401424015240162401724018240192402024021240222402324024240252402624027240282402924030240312403224033240342403524036240372403824039240402404124042240432404424045240462404724048240492405024051240522405324054240552405624057240582405924060240612406224063240642406524066240672406824069240702407124072240732407424075240762407724078240792408024081240822408324084240852408624087240882408924090240912409224093240942409524096240972409824099241002410124102241032410424105241062410724108241092411024111241122411324114241152411624117241182411924120241212412224123241242412524126241272412824129241302413124132241332413424135241362413724138241392414024141241422414324144241452414624147241482414924150241512415224153241542415524156241572415824159241602416124162241632416424165241662416724168241692417024171241722417324174241752417624177241782417924180241812418224183241842418524186241872418824189241902419124192241932419424195241962419724198241992420024201242022420324204242052420624207242082420924210242112421224213242142421524216242172421824219242202422124222242232422424225242262422724228242292423024231242322423324234242352423624237242382423924240242412424224243242442424524246242472424824249242502425124252242532425424255242562425724258242592426024261242622426324264242652426624267242682426924270242712427224273242742427524276242772427824279242802428124282242832428424285242862428724288242892429024291242922429324294242952429624297242982429924300243012430224303243042430524306243072430824309243102431124312243132431424315243162431724318243192432024321243222432324324243252432624327243282432924330243312433224333243342433524336243372433824339243402434124342243432434424345243462434724348243492435024351243522435324354243552435624357243582435924360243612436224363243642436524366243672436824369243702437124372243732437424375243762437724378243792438024381243822438324384243852438624387243882438924390243912439224393243942439524396243972439824399244002440124402244032440424405244062440724408244092441024411244122441324414244152441624417244182441924420244212442224423244242442524426244272442824429244302443124432244332443424435244362443724438244392444024441244422444324444244452444624447244482444924450244512445224453244542445524456244572445824459244602446124462244632446424465244662446724468244692447024471244722447324474244752447624477244782447924480244812448224483244842448524486244872448824489244902449124492244932449424495244962449724498244992450024501245022450324504245052450624507245082450924510245112451224513245142451524516245172451824519245202452124522245232452424525245262452724528245292453024531245322453324534245352453624537245382453924540245412454224543245442454524546245472454824549245502455124552245532455424555245562455724558245592456024561245622456324564245652456624567245682456924570245712457224573245742457524576245772457824579245802458124582245832458424585245862458724588245892459024591245922459324594245952459624597245982459924600246012460224603246042460524606246072460824609246102461124612246132461424615246162461724618246192462024621246222462324624246252462624627246282462924630246312463224633246342463524636246372463824639246402464124642246432464424645246462464724648246492465024651246522465324654246552465624657246582465924660246612466224663246642466524666246672466824669246702467124672246732467424675246762467724678246792468024681246822468324684246852468624687246882468924690246912469224693246942469524696246972469824699247002470124702247032470424705247062470724708247092471024711247122471324714247152471624717247182471924720247212472224723247242472524726247272472824729247302473124732247332473424735247362473724738247392474024741247422474324744247452474624747247482474924750247512475224753247542475524756247572475824759247602476124762247632476424765247662476724768247692477024771247722477324774247752477624777247782477924780247812478224783247842478524786247872478824789247902479124792247932479424795247962479724798247992480024801248022480324804248052480624807248082480924810248112481224813248142481524816248172481824819248202482124822248232482424825248262482724828248292483024831248322483324834248352483624837248382483924840248412484224843248442484524846248472484824849248502485124852248532485424855248562485724858248592486024861248622486324864248652486624867248682486924870248712487224873248742487524876248772487824879248802488124882248832488424885248862488724888248892489024891248922489324894248952489624897248982489924900249012490224903249042490524906249072490824909249102491124912249132491424915249162491724918249192492024921249222492324924249252492624927249282492924930249312493224933249342493524936249372493824939249402494124942249432494424945249462494724948249492495024951249522495324954249552495624957249582495924960249612496224963249642496524966249672496824969249702497124972249732497424975249762497724978249792498024981249822498324984249852498624987249882498924990249912499224993249942499524996249972499824999250002500125002250032500425005250062500725008250092501025011250122501325014250152501625017250182501925020250212502225023250242502525026250272502825029250302503125032250332503425035250362503725038250392504025041250422504325044250452504625047250482504925050250512505225053250542505525056250572505825059250602506125062250632506425065250662506725068250692507025071250722507325074250752507625077250782507925080250812508225083250842508525086250872508825089
  1. /* Output Dwarf2 format symbol table information from GCC.
  2. Copyright (C) 1992-2015 Free Software Foundation, Inc.
  3. Contributed by Gary Funck (gary@intrepid.com).
  4. Derived from DWARF 1 implementation of Ron Guilmette (rfg@monkeys.com).
  5. Extensively modified by Jason Merrill (jason@cygnus.com).
  6. This file is part of GCC.
  7. GCC is free software; you can redistribute it and/or modify it under
  8. the terms of the GNU General Public License as published by the Free
  9. Software Foundation; either version 3, or (at your option) any later
  10. version.
  11. GCC is distributed in the hope that it will be useful, but WITHOUT ANY
  12. WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13. FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
  14. for more details.
  15. You should have received a copy of the GNU General Public License
  16. along with GCC; see the file COPYING3. If not see
  17. <http://www.gnu.org/licenses/>. */
  18. /* TODO: Emit .debug_line header even when there are no functions, since
  19. the file numbers are used by .debug_info. Alternately, leave
  20. out locations for types and decls.
  21. Avoid talking about ctors and op= for PODs.
  22. Factor out common prologue sequences into multiple CIEs. */
  23. /* The first part of this file deals with the DWARF 2 frame unwind
  24. information, which is also used by the GCC efficient exception handling
  25. mechanism. The second part, controlled only by an #ifdef
  26. DWARF2_DEBUGGING_INFO, deals with the other DWARF 2 debugging
  27. information. */
  28. /* DWARF2 Abbreviation Glossary:
  29. CFA = Canonical Frame Address
  30. a fixed address on the stack which identifies a call frame.
  31. We define it to be the value of SP just before the call insn.
  32. The CFA register and offset, which may change during the course
  33. of the function, are used to calculate its value at runtime.
  34. CFI = Call Frame Instruction
  35. an instruction for the DWARF2 abstract machine
  36. CIE = Common Information Entry
  37. information describing information common to one or more FDEs
  38. DIE = Debugging Information Entry
  39. FDE = Frame Description Entry
  40. information describing the stack call frame, in particular,
  41. how to restore registers
  42. DW_CFA_... = DWARF2 CFA call frame instruction
  43. DW_TAG_... = DWARF2 DIE tag */
  44. #include "config.h"
  45. #include "system.h"
  46. #include "coretypes.h"
  47. #include "tm.h"
  48. #include "rtl.h"
  49. #include "hash-set.h"
  50. #include "machmode.h"
  51. #include "vec.h"
  52. #include "double-int.h"
  53. #include "input.h"
  54. #include "alias.h"
  55. #include "symtab.h"
  56. #include "wide-int.h"
  57. #include "inchash.h"
  58. #include "real.h"
  59. #include "tree.h"
  60. #include "fold-const.h"
  61. #include "stringpool.h"
  62. #include "stor-layout.h"
  63. #include "varasm.h"
  64. #include "hashtab.h"
  65. #include "hard-reg-set.h"
  66. #include "function.h"
  67. #include "emit-rtl.h"
  68. #include "hash-table.h"
  69. #include "version.h"
  70. #include "flags.h"
  71. #include "regs.h"
  72. #include "rtlhash.h"
  73. #include "insn-config.h"
  74. #include "reload.h"
  75. #include "output.h"
  76. #include "statistics.h"
  77. #include "fixed-value.h"
  78. #include "expmed.h"
  79. #include "dojump.h"
  80. #include "explow.h"
  81. #include "calls.h"
  82. #include "stmt.h"
  83. #include "expr.h"
  84. #include "except.h"
  85. #include "dwarf2.h"
  86. #include "dwarf2out.h"
  87. #include "dwarf2asm.h"
  88. #include "toplev.h"
  89. #include "md5.h"
  90. #include "tm_p.h"
  91. #include "diagnostic.h"
  92. #include "tree-pretty-print.h"
  93. #include "debug.h"
  94. #include "target.h"
  95. #include "common/common-target.h"
  96. #include "langhooks.h"
  97. #include "hash-map.h"
  98. #include "is-a.h"
  99. #include "plugin-api.h"
  100. #include "ipa-ref.h"
  101. #include "cgraph.h"
  102. #include "ira.h"
  103. #include "lra.h"
  104. #include "dumpfile.h"
  105. #include "opts.h"
  106. #include "tree-dfa.h"
  107. #include "gdb/gdb-index.h"
  108. #include "rtl-iter.h"
  109. static void dwarf2out_source_line (unsigned int, const char *, int, bool);
  110. static rtx_insn *last_var_location_insn;
  111. static rtx_insn *cached_next_real_insn;
  112. static void dwarf2out_decl (tree);
  113. #ifdef VMS_DEBUGGING_INFO
  114. int vms_file_stats_name (const char *, long long *, long *, char *, int *);
  115. /* Define this macro to be a nonzero value if the directory specifications
  116. which are output in the debug info should end with a separator. */
  117. #define DWARF2_DIR_SHOULD_END_WITH_SEPARATOR 1
  118. /* Define this macro to evaluate to a nonzero value if GCC should refrain
  119. from generating indirect strings in DWARF2 debug information, for instance
  120. if your target is stuck with an old version of GDB that is unable to
  121. process them properly or uses VMS Debug. */
  122. #define DWARF2_INDIRECT_STRING_SUPPORT_MISSING_ON_TARGET 1
  123. #else
  124. #define DWARF2_DIR_SHOULD_END_WITH_SEPARATOR 0
  125. #define DWARF2_INDIRECT_STRING_SUPPORT_MISSING_ON_TARGET 0
  126. #endif
  127. /* ??? Poison these here until it can be done generically. They've been
  128. totally replaced in this file; make sure it stays that way. */
  129. #undef DWARF2_UNWIND_INFO
  130. #undef DWARF2_FRAME_INFO
  131. #if (GCC_VERSION >= 3000)
  132. #pragma GCC poison DWARF2_UNWIND_INFO DWARF2_FRAME_INFO
  133. #endif
  134. /* The size of the target's pointer type. */
  135. #ifndef PTR_SIZE
  136. #define PTR_SIZE (POINTER_SIZE / BITS_PER_UNIT)
  137. #endif
  138. /* Array of RTXes referenced by the debugging information, which therefore
  139. must be kept around forever. */
  140. static GTY(()) vec<rtx, va_gc> *used_rtx_array;
  141. /* A pointer to the base of a list of incomplete types which might be
  142. completed at some later time. incomplete_types_list needs to be a
  143. vec<tree, va_gc> *because we want to tell the garbage collector about
  144. it. */
  145. static GTY(()) vec<tree, va_gc> *incomplete_types;
  146. /* A pointer to the base of a table of references to declaration
  147. scopes. This table is a display which tracks the nesting
  148. of declaration scopes at the current scope and containing
  149. scopes. This table is used to find the proper place to
  150. define type declaration DIE's. */
  151. static GTY(()) vec<tree, va_gc> *decl_scope_table;
  152. /* Pointers to various DWARF2 sections. */
  153. static GTY(()) section *debug_info_section;
  154. static GTY(()) section *debug_skeleton_info_section;
  155. static GTY(()) section *debug_abbrev_section;
  156. static GTY(()) section *debug_skeleton_abbrev_section;
  157. static GTY(()) section *debug_aranges_section;
  158. static GTY(()) section *debug_addr_section;
  159. static GTY(()) section *debug_macinfo_section;
  160. static GTY(()) section *debug_line_section;
  161. static GTY(()) section *debug_skeleton_line_section;
  162. static GTY(()) section *debug_loc_section;
  163. static GTY(()) section *debug_pubnames_section;
  164. static GTY(()) section *debug_pubtypes_section;
  165. static GTY(()) section *debug_str_section;
  166. static GTY(()) section *debug_str_dwo_section;
  167. static GTY(()) section *debug_str_offsets_section;
  168. static GTY(()) section *debug_ranges_section;
  169. static GTY(()) section *debug_frame_section;
  170. /* Maximum size (in bytes) of an artificially generated label. */
  171. #define MAX_ARTIFICIAL_LABEL_BYTES 30
  172. /* According to the (draft) DWARF 3 specification, the initial length
  173. should either be 4 or 12 bytes. When it's 12 bytes, the first 4
  174. bytes are 0xffffffff, followed by the length stored in the next 8
  175. bytes.
  176. However, the SGI/MIPS ABI uses an initial length which is equal to
  177. DWARF_OFFSET_SIZE. It is defined (elsewhere) accordingly. */
  178. #ifndef DWARF_INITIAL_LENGTH_SIZE
  179. #define DWARF_INITIAL_LENGTH_SIZE (DWARF_OFFSET_SIZE == 4 ? 4 : 12)
  180. #endif
  181. /* Round SIZE up to the nearest BOUNDARY. */
  182. #define DWARF_ROUND(SIZE,BOUNDARY) \
  183. ((((SIZE) + (BOUNDARY) - 1) / (BOUNDARY)) * (BOUNDARY))
  184. /* CIE identifier. */
  185. #if HOST_BITS_PER_WIDE_INT >= 64
  186. #define DWARF_CIE_ID \
  187. (unsigned HOST_WIDE_INT) (DWARF_OFFSET_SIZE == 4 ? DW_CIE_ID : DW64_CIE_ID)
  188. #else
  189. #define DWARF_CIE_ID DW_CIE_ID
  190. #endif
  191. /* A vector for a table that contains frame description
  192. information for each routine. */
  193. #define NOT_INDEXED (-1U)
  194. #define NO_INDEX_ASSIGNED (-2U)
  195. static GTY(()) vec<dw_fde_ref, va_gc> *fde_vec;
  196. struct GTY((for_user)) indirect_string_node {
  197. const char *str;
  198. unsigned int refcount;
  199. enum dwarf_form form;
  200. char *label;
  201. unsigned int index;
  202. };
  203. struct indirect_string_hasher : ggc_hasher<indirect_string_node *>
  204. {
  205. typedef const char *compare_type;
  206. static hashval_t hash (indirect_string_node *);
  207. static bool equal (indirect_string_node *, const char *);
  208. };
  209. static GTY (()) hash_table<indirect_string_hasher> *debug_str_hash;
  210. /* With split_debug_info, both the comp_dir and dwo_name go in the
  211. main object file, rather than the dwo, similar to the force_direct
  212. parameter elsewhere but with additional complications:
  213. 1) The string is needed in both the main object file and the dwo.
  214. That is, the comp_dir and dwo_name will appear in both places.
  215. 2) Strings can use three forms: DW_FORM_string, DW_FORM_strp or
  216. DW_FORM_GNU_str_index.
  217. 3) GCC chooses the form to use late, depending on the size and
  218. reference count.
  219. Rather than forcing the all debug string handling functions and
  220. callers to deal with these complications, simply use a separate,
  221. special-cased string table for any attribute that should go in the
  222. main object file. This limits the complexity to just the places
  223. that need it. */
  224. static GTY (()) hash_table<indirect_string_hasher> *skeleton_debug_str_hash;
  225. static GTY(()) int dw2_string_counter;
  226. /* True if the compilation unit places functions in more than one section. */
  227. static GTY(()) bool have_multiple_function_sections = false;
  228. /* Whether the default text and cold text sections have been used at all. */
  229. static GTY(()) bool text_section_used = false;
  230. static GTY(()) bool cold_text_section_used = false;
  231. /* The default cold text section. */
  232. static GTY(()) section *cold_text_section;
  233. /* The DIE for C++14 'auto' in a function return type. */
  234. static GTY(()) dw_die_ref auto_die;
  235. /* The DIE for C++14 'decltype(auto)' in a function return type. */
  236. static GTY(()) dw_die_ref decltype_auto_die;
  237. /* Forward declarations for functions defined in this file. */
  238. static char *stripattributes (const char *);
  239. static void output_call_frame_info (int);
  240. static void dwarf2out_note_section_used (void);
  241. /* Personality decl of current unit. Used only when assembler does not support
  242. personality CFI. */
  243. static GTY(()) rtx current_unit_personality;
  244. /* Data and reference forms for relocatable data. */
  245. #define DW_FORM_data (DWARF_OFFSET_SIZE == 8 ? DW_FORM_data8 : DW_FORM_data4)
  246. #define DW_FORM_ref (DWARF_OFFSET_SIZE == 8 ? DW_FORM_ref8 : DW_FORM_ref4)
  247. #ifndef DEBUG_FRAME_SECTION
  248. #define DEBUG_FRAME_SECTION ".debug_frame"
  249. #endif
  250. #ifndef FUNC_BEGIN_LABEL
  251. #define FUNC_BEGIN_LABEL "LFB"
  252. #endif
  253. #ifndef FUNC_END_LABEL
  254. #define FUNC_END_LABEL "LFE"
  255. #endif
  256. #ifndef PROLOGUE_END_LABEL
  257. #define PROLOGUE_END_LABEL "LPE"
  258. #endif
  259. #ifndef EPILOGUE_BEGIN_LABEL
  260. #define EPILOGUE_BEGIN_LABEL "LEB"
  261. #endif
  262. #ifndef FRAME_BEGIN_LABEL
  263. #define FRAME_BEGIN_LABEL "Lframe"
  264. #endif
  265. #define CIE_AFTER_SIZE_LABEL "LSCIE"
  266. #define CIE_END_LABEL "LECIE"
  267. #define FDE_LABEL "LSFDE"
  268. #define FDE_AFTER_SIZE_LABEL "LASFDE"
  269. #define FDE_END_LABEL "LEFDE"
  270. #define LINE_NUMBER_BEGIN_LABEL "LSLT"
  271. #define LINE_NUMBER_END_LABEL "LELT"
  272. #define LN_PROLOG_AS_LABEL "LASLTP"
  273. #define LN_PROLOG_END_LABEL "LELTP"
  274. #define DIE_LABEL_PREFIX "DW"
  275. /* Match the base name of a file to the base name of a compilation unit. */
  276. static int
  277. matches_main_base (const char *path)
  278. {
  279. /* Cache the last query. */
  280. static const char *last_path = NULL;
  281. static int last_match = 0;
  282. if (path != last_path)
  283. {
  284. const char *base;
  285. int length = base_of_path (path, &base);
  286. last_path = path;
  287. last_match = (length == main_input_baselength
  288. && memcmp (base, main_input_basename, length) == 0);
  289. }
  290. return last_match;
  291. }
  292. #ifdef DEBUG_DEBUG_STRUCT
  293. static int
  294. dump_struct_debug (tree type, enum debug_info_usage usage,
  295. enum debug_struct_file criterion, int generic,
  296. int matches, int result)
  297. {
  298. /* Find the type name. */
  299. tree type_decl = TYPE_STUB_DECL (type);
  300. tree t = type_decl;
  301. const char *name = 0;
  302. if (TREE_CODE (t) == TYPE_DECL)
  303. t = DECL_NAME (t);
  304. if (t)
  305. name = IDENTIFIER_POINTER (t);
  306. fprintf (stderr, " struct %d %s %s %s %s %d %p %s\n",
  307. criterion,
  308. DECL_IN_SYSTEM_HEADER (type_decl) ? "sys" : "usr",
  309. matches ? "bas" : "hdr",
  310. generic ? "gen" : "ord",
  311. usage == DINFO_USAGE_DFN ? ";" :
  312. usage == DINFO_USAGE_DIR_USE ? "." : "*",
  313. result,
  314. (void*) type_decl, name);
  315. return result;
  316. }
  317. #define DUMP_GSTRUCT(type, usage, criterion, generic, matches, result) \
  318. dump_struct_debug (type, usage, criterion, generic, matches, result)
  319. #else
  320. #define DUMP_GSTRUCT(type, usage, criterion, generic, matches, result) \
  321. (result)
  322. #endif
  323. /* Get the number of HOST_WIDE_INTs needed to represent the precision
  324. of the number. */
  325. static unsigned int
  326. get_full_len (const wide_int &op)
  327. {
  328. return ((op.get_precision () + HOST_BITS_PER_WIDE_INT - 1)
  329. / HOST_BITS_PER_WIDE_INT);
  330. }
  331. static bool
  332. should_emit_struct_debug (tree type, enum debug_info_usage usage)
  333. {
  334. enum debug_struct_file criterion;
  335. tree type_decl;
  336. bool generic = lang_hooks.types.generic_p (type);
  337. if (generic)
  338. criterion = debug_struct_generic[usage];
  339. else
  340. criterion = debug_struct_ordinary[usage];
  341. if (criterion == DINFO_STRUCT_FILE_NONE)
  342. return DUMP_GSTRUCT (type, usage, criterion, generic, false, false);
  343. if (criterion == DINFO_STRUCT_FILE_ANY)
  344. return DUMP_GSTRUCT (type, usage, criterion, generic, false, true);
  345. type_decl = TYPE_STUB_DECL (TYPE_MAIN_VARIANT (type));
  346. if (type_decl != NULL)
  347. {
  348. if (criterion == DINFO_STRUCT_FILE_SYS && DECL_IN_SYSTEM_HEADER (type_decl))
  349. return DUMP_GSTRUCT (type, usage, criterion, generic, false, true);
  350. if (matches_main_base (DECL_SOURCE_FILE (type_decl)))
  351. return DUMP_GSTRUCT (type, usage, criterion, generic, true, true);
  352. }
  353. return DUMP_GSTRUCT (type, usage, criterion, generic, false, false);
  354. }
  355. /* Return a pointer to a copy of the section string name S with all
  356. attributes stripped off, and an asterisk prepended (for assemble_name). */
  357. static inline char *
  358. stripattributes (const char *s)
  359. {
  360. char *stripped = XNEWVEC (char, strlen (s) + 2);
  361. char *p = stripped;
  362. *p++ = '*';
  363. while (*s && *s != ',')
  364. *p++ = *s++;
  365. *p = '\0';
  366. return stripped;
  367. }
  368. /* Switch [BACK] to eh_frame_section. If we don't have an eh_frame_section,
  369. switch to the data section instead, and write out a synthetic start label
  370. for collect2 the first time around. */
  371. static void
  372. switch_to_eh_frame_section (bool back)
  373. {
  374. tree label;
  375. #ifdef EH_FRAME_SECTION_NAME
  376. if (eh_frame_section == 0)
  377. {
  378. int flags;
  379. if (EH_TABLES_CAN_BE_READ_ONLY)
  380. {
  381. int fde_encoding;
  382. int per_encoding;
  383. int lsda_encoding;
  384. fde_encoding = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/1,
  385. /*global=*/0);
  386. per_encoding = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/2,
  387. /*global=*/1);
  388. lsda_encoding = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/0,
  389. /*global=*/0);
  390. flags = ((! flag_pic
  391. || ((fde_encoding & 0x70) != DW_EH_PE_absptr
  392. && (fde_encoding & 0x70) != DW_EH_PE_aligned
  393. && (per_encoding & 0x70) != DW_EH_PE_absptr
  394. && (per_encoding & 0x70) != DW_EH_PE_aligned
  395. && (lsda_encoding & 0x70) != DW_EH_PE_absptr
  396. && (lsda_encoding & 0x70) != DW_EH_PE_aligned))
  397. ? 0 : SECTION_WRITE);
  398. }
  399. else
  400. flags = SECTION_WRITE;
  401. eh_frame_section = get_section (EH_FRAME_SECTION_NAME, flags, NULL);
  402. }
  403. #endif /* EH_FRAME_SECTION_NAME */
  404. if (eh_frame_section)
  405. switch_to_section (eh_frame_section);
  406. else
  407. {
  408. /* We have no special eh_frame section. Put the information in
  409. the data section and emit special labels to guide collect2. */
  410. switch_to_section (data_section);
  411. if (!back)
  412. {
  413. label = get_file_function_name ("F");
  414. ASM_OUTPUT_ALIGN (asm_out_file, floor_log2 (PTR_SIZE));
  415. targetm.asm_out.globalize_label (asm_out_file,
  416. IDENTIFIER_POINTER (label));
  417. ASM_OUTPUT_LABEL (asm_out_file, IDENTIFIER_POINTER (label));
  418. }
  419. }
  420. }
  421. /* Switch [BACK] to the eh or debug frame table section, depending on
  422. FOR_EH. */
  423. static void
  424. switch_to_frame_table_section (int for_eh, bool back)
  425. {
  426. if (for_eh)
  427. switch_to_eh_frame_section (back);
  428. else
  429. {
  430. if (!debug_frame_section)
  431. debug_frame_section = get_section (DEBUG_FRAME_SECTION,
  432. SECTION_DEBUG, NULL);
  433. switch_to_section (debug_frame_section);
  434. }
  435. }
  436. /* Describe for the GTY machinery what parts of dw_cfi_oprnd1 are used. */
  437. enum dw_cfi_oprnd_type
  438. dw_cfi_oprnd1_desc (enum dwarf_call_frame_info cfi)
  439. {
  440. switch (cfi)
  441. {
  442. case DW_CFA_nop:
  443. case DW_CFA_GNU_window_save:
  444. case DW_CFA_remember_state:
  445. case DW_CFA_restore_state:
  446. return dw_cfi_oprnd_unused;
  447. case DW_CFA_set_loc:
  448. case DW_CFA_advance_loc1:
  449. case DW_CFA_advance_loc2:
  450. case DW_CFA_advance_loc4:
  451. case DW_CFA_MIPS_advance_loc8:
  452. return dw_cfi_oprnd_addr;
  453. case DW_CFA_offset:
  454. case DW_CFA_offset_extended:
  455. case DW_CFA_def_cfa:
  456. case DW_CFA_offset_extended_sf:
  457. case DW_CFA_def_cfa_sf:
  458. case DW_CFA_restore:
  459. case DW_CFA_restore_extended:
  460. case DW_CFA_undefined:
  461. case DW_CFA_same_value:
  462. case DW_CFA_def_cfa_register:
  463. case DW_CFA_register:
  464. case DW_CFA_expression:
  465. return dw_cfi_oprnd_reg_num;
  466. case DW_CFA_def_cfa_offset:
  467. case DW_CFA_GNU_args_size:
  468. case DW_CFA_def_cfa_offset_sf:
  469. return dw_cfi_oprnd_offset;
  470. case DW_CFA_def_cfa_expression:
  471. return dw_cfi_oprnd_loc;
  472. default:
  473. gcc_unreachable ();
  474. }
  475. }
  476. /* Describe for the GTY machinery what parts of dw_cfi_oprnd2 are used. */
  477. enum dw_cfi_oprnd_type
  478. dw_cfi_oprnd2_desc (enum dwarf_call_frame_info cfi)
  479. {
  480. switch (cfi)
  481. {
  482. case DW_CFA_def_cfa:
  483. case DW_CFA_def_cfa_sf:
  484. case DW_CFA_offset:
  485. case DW_CFA_offset_extended_sf:
  486. case DW_CFA_offset_extended:
  487. return dw_cfi_oprnd_offset;
  488. case DW_CFA_register:
  489. return dw_cfi_oprnd_reg_num;
  490. case DW_CFA_expression:
  491. return dw_cfi_oprnd_loc;
  492. default:
  493. return dw_cfi_oprnd_unused;
  494. }
  495. }
  496. /* Output one FDE. */
  497. static void
  498. output_fde (dw_fde_ref fde, bool for_eh, bool second,
  499. char *section_start_label, int fde_encoding, char *augmentation,
  500. bool any_lsda_needed, int lsda_encoding)
  501. {
  502. const char *begin, *end;
  503. static unsigned int j;
  504. char l1[20], l2[20];
  505. targetm.asm_out.emit_unwind_label (asm_out_file, fde->decl, for_eh,
  506. /* empty */ 0);
  507. targetm.asm_out.internal_label (asm_out_file, FDE_LABEL,
  508. for_eh + j);
  509. ASM_GENERATE_INTERNAL_LABEL (l1, FDE_AFTER_SIZE_LABEL, for_eh + j);
  510. ASM_GENERATE_INTERNAL_LABEL (l2, FDE_END_LABEL, for_eh + j);
  511. if (DWARF_INITIAL_LENGTH_SIZE - DWARF_OFFSET_SIZE == 4 && !for_eh)
  512. dw2_asm_output_data (4, 0xffffffff, "Initial length escape value"
  513. " indicating 64-bit DWARF extension");
  514. dw2_asm_output_delta (for_eh ? 4 : DWARF_OFFSET_SIZE, l2, l1,
  515. "FDE Length");
  516. ASM_OUTPUT_LABEL (asm_out_file, l1);
  517. if (for_eh)
  518. dw2_asm_output_delta (4, l1, section_start_label, "FDE CIE offset");
  519. else
  520. dw2_asm_output_offset (DWARF_OFFSET_SIZE, section_start_label,
  521. debug_frame_section, "FDE CIE offset");
  522. begin = second ? fde->dw_fde_second_begin : fde->dw_fde_begin;
  523. end = second ? fde->dw_fde_second_end : fde->dw_fde_end;
  524. if (for_eh)
  525. {
  526. rtx sym_ref = gen_rtx_SYMBOL_REF (Pmode, begin);
  527. SYMBOL_REF_FLAGS (sym_ref) |= SYMBOL_FLAG_LOCAL;
  528. dw2_asm_output_encoded_addr_rtx (fde_encoding, sym_ref, false,
  529. "FDE initial location");
  530. dw2_asm_output_delta (size_of_encoded_value (fde_encoding),
  531. end, begin, "FDE address range");
  532. }
  533. else
  534. {
  535. dw2_asm_output_addr (DWARF2_ADDR_SIZE, begin, "FDE initial location");
  536. dw2_asm_output_delta (DWARF2_ADDR_SIZE, end, begin, "FDE address range");
  537. }
  538. if (augmentation[0])
  539. {
  540. if (any_lsda_needed)
  541. {
  542. int size = size_of_encoded_value (lsda_encoding);
  543. if (lsda_encoding == DW_EH_PE_aligned)
  544. {
  545. int offset = ( 4 /* Length */
  546. + 4 /* CIE offset */
  547. + 2 * size_of_encoded_value (fde_encoding)
  548. + 1 /* Augmentation size */ );
  549. int pad = -offset & (PTR_SIZE - 1);
  550. size += pad;
  551. gcc_assert (size_of_uleb128 (size) == 1);
  552. }
  553. dw2_asm_output_data_uleb128 (size, "Augmentation size");
  554. if (fde->uses_eh_lsda)
  555. {
  556. ASM_GENERATE_INTERNAL_LABEL (l1, second ? "LLSDAC" : "LLSDA",
  557. fde->funcdef_number);
  558. dw2_asm_output_encoded_addr_rtx (lsda_encoding,
  559. gen_rtx_SYMBOL_REF (Pmode, l1),
  560. false,
  561. "Language Specific Data Area");
  562. }
  563. else
  564. {
  565. if (lsda_encoding == DW_EH_PE_aligned)
  566. ASM_OUTPUT_ALIGN (asm_out_file, floor_log2 (PTR_SIZE));
  567. dw2_asm_output_data (size_of_encoded_value (lsda_encoding), 0,
  568. "Language Specific Data Area (none)");
  569. }
  570. }
  571. else
  572. dw2_asm_output_data_uleb128 (0, "Augmentation size");
  573. }
  574. /* Loop through the Call Frame Instructions associated with this FDE. */
  575. fde->dw_fde_current_label = begin;
  576. {
  577. size_t from, until, i;
  578. from = 0;
  579. until = vec_safe_length (fde->dw_fde_cfi);
  580. if (fde->dw_fde_second_begin == NULL)
  581. ;
  582. else if (!second)
  583. until = fde->dw_fde_switch_cfi_index;
  584. else
  585. from = fde->dw_fde_switch_cfi_index;
  586. for (i = from; i < until; i++)
  587. output_cfi ((*fde->dw_fde_cfi)[i], fde, for_eh);
  588. }
  589. /* If we are to emit a ref/link from function bodies to their frame tables,
  590. do it now. This is typically performed to make sure that tables
  591. associated with functions are dragged with them and not discarded in
  592. garbage collecting links. We need to do this on a per function basis to
  593. cope with -ffunction-sections. */
  594. #ifdef ASM_OUTPUT_DWARF_TABLE_REF
  595. /* Switch to the function section, emit the ref to the tables, and
  596. switch *back* into the table section. */
  597. switch_to_section (function_section (fde->decl));
  598. ASM_OUTPUT_DWARF_TABLE_REF (section_start_label);
  599. switch_to_frame_table_section (for_eh, true);
  600. #endif
  601. /* Pad the FDE out to an address sized boundary. */
  602. ASM_OUTPUT_ALIGN (asm_out_file,
  603. floor_log2 ((for_eh ? PTR_SIZE : DWARF2_ADDR_SIZE)));
  604. ASM_OUTPUT_LABEL (asm_out_file, l2);
  605. j += 2;
  606. }
  607. /* Return true if frame description entry FDE is needed for EH. */
  608. static bool
  609. fde_needed_for_eh_p (dw_fde_ref fde)
  610. {
  611. if (flag_asynchronous_unwind_tables)
  612. return true;
  613. if (TARGET_USES_WEAK_UNWIND_INFO && DECL_WEAK (fde->decl))
  614. return true;
  615. if (fde->uses_eh_lsda)
  616. return true;
  617. /* If exceptions are enabled, we have collected nothrow info. */
  618. if (flag_exceptions && (fde->all_throwers_are_sibcalls || fde->nothrow))
  619. return false;
  620. return true;
  621. }
  622. /* Output the call frame information used to record information
  623. that relates to calculating the frame pointer, and records the
  624. location of saved registers. */
  625. static void
  626. output_call_frame_info (int for_eh)
  627. {
  628. unsigned int i;
  629. dw_fde_ref fde;
  630. dw_cfi_ref cfi;
  631. char l1[20], l2[20], section_start_label[20];
  632. bool any_lsda_needed = false;
  633. char augmentation[6];
  634. int augmentation_size;
  635. int fde_encoding = DW_EH_PE_absptr;
  636. int per_encoding = DW_EH_PE_absptr;
  637. int lsda_encoding = DW_EH_PE_absptr;
  638. int return_reg;
  639. rtx personality = NULL;
  640. int dw_cie_version;
  641. /* Don't emit a CIE if there won't be any FDEs. */
  642. if (!fde_vec)
  643. return;
  644. /* Nothing to do if the assembler's doing it all. */
  645. if (dwarf2out_do_cfi_asm ())
  646. return;
  647. /* If we don't have any functions we'll want to unwind out of, don't emit
  648. any EH unwind information. If we make FDEs linkonce, we may have to
  649. emit an empty label for an FDE that wouldn't otherwise be emitted. We
  650. want to avoid having an FDE kept around when the function it refers to
  651. is discarded. Example where this matters: a primary function template
  652. in C++ requires EH information, an explicit specialization doesn't. */
  653. if (for_eh)
  654. {
  655. bool any_eh_needed = false;
  656. FOR_EACH_VEC_ELT (*fde_vec, i, fde)
  657. {
  658. if (fde->uses_eh_lsda)
  659. any_eh_needed = any_lsda_needed = true;
  660. else if (fde_needed_for_eh_p (fde))
  661. any_eh_needed = true;
  662. else if (TARGET_USES_WEAK_UNWIND_INFO)
  663. targetm.asm_out.emit_unwind_label (asm_out_file, fde->decl, 1, 1);
  664. }
  665. if (!any_eh_needed)
  666. return;
  667. }
  668. /* We're going to be generating comments, so turn on app. */
  669. if (flag_debug_asm)
  670. app_enable ();
  671. /* Switch to the proper frame section, first time. */
  672. switch_to_frame_table_section (for_eh, false);
  673. ASM_GENERATE_INTERNAL_LABEL (section_start_label, FRAME_BEGIN_LABEL, for_eh);
  674. ASM_OUTPUT_LABEL (asm_out_file, section_start_label);
  675. /* Output the CIE. */
  676. ASM_GENERATE_INTERNAL_LABEL (l1, CIE_AFTER_SIZE_LABEL, for_eh);
  677. ASM_GENERATE_INTERNAL_LABEL (l2, CIE_END_LABEL, for_eh);
  678. if (DWARF_INITIAL_LENGTH_SIZE - DWARF_OFFSET_SIZE == 4 && !for_eh)
  679. dw2_asm_output_data (4, 0xffffffff,
  680. "Initial length escape value indicating 64-bit DWARF extension");
  681. dw2_asm_output_delta (for_eh ? 4 : DWARF_OFFSET_SIZE, l2, l1,
  682. "Length of Common Information Entry");
  683. ASM_OUTPUT_LABEL (asm_out_file, l1);
  684. /* Now that the CIE pointer is PC-relative for EH,
  685. use 0 to identify the CIE. */
  686. dw2_asm_output_data ((for_eh ? 4 : DWARF_OFFSET_SIZE),
  687. (for_eh ? 0 : DWARF_CIE_ID),
  688. "CIE Identifier Tag");
  689. /* Use the CIE version 3 for DWARF3; allow DWARF2 to continue to
  690. use CIE version 1, unless that would produce incorrect results
  691. due to overflowing the return register column. */
  692. return_reg = DWARF2_FRAME_REG_OUT (DWARF_FRAME_RETURN_COLUMN, for_eh);
  693. dw_cie_version = 1;
  694. if (return_reg >= 256 || dwarf_version > 2)
  695. dw_cie_version = 3;
  696. dw2_asm_output_data (1, dw_cie_version, "CIE Version");
  697. augmentation[0] = 0;
  698. augmentation_size = 0;
  699. personality = current_unit_personality;
  700. if (for_eh)
  701. {
  702. char *p;
  703. /* Augmentation:
  704. z Indicates that a uleb128 is present to size the
  705. augmentation section.
  706. L Indicates the encoding (and thus presence) of
  707. an LSDA pointer in the FDE augmentation.
  708. R Indicates a non-default pointer encoding for
  709. FDE code pointers.
  710. P Indicates the presence of an encoding + language
  711. personality routine in the CIE augmentation. */
  712. fde_encoding = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/1, /*global=*/0);
  713. per_encoding = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/2, /*global=*/1);
  714. lsda_encoding = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/0, /*global=*/0);
  715. p = augmentation + 1;
  716. if (personality)
  717. {
  718. *p++ = 'P';
  719. augmentation_size += 1 + size_of_encoded_value (per_encoding);
  720. assemble_external_libcall (personality);
  721. }
  722. if (any_lsda_needed)
  723. {
  724. *p++ = 'L';
  725. augmentation_size += 1;
  726. }
  727. if (fde_encoding != DW_EH_PE_absptr)
  728. {
  729. *p++ = 'R';
  730. augmentation_size += 1;
  731. }
  732. if (p > augmentation + 1)
  733. {
  734. augmentation[0] = 'z';
  735. *p = '\0';
  736. }
  737. /* Ug. Some platforms can't do unaligned dynamic relocations at all. */
  738. if (personality && per_encoding == DW_EH_PE_aligned)
  739. {
  740. int offset = ( 4 /* Length */
  741. + 4 /* CIE Id */
  742. + 1 /* CIE version */
  743. + strlen (augmentation) + 1 /* Augmentation */
  744. + size_of_uleb128 (1) /* Code alignment */
  745. + size_of_sleb128 (DWARF_CIE_DATA_ALIGNMENT)
  746. + 1 /* RA column */
  747. + 1 /* Augmentation size */
  748. + 1 /* Personality encoding */ );
  749. int pad = -offset & (PTR_SIZE - 1);
  750. augmentation_size += pad;
  751. /* Augmentations should be small, so there's scarce need to
  752. iterate for a solution. Die if we exceed one uleb128 byte. */
  753. gcc_assert (size_of_uleb128 (augmentation_size) == 1);
  754. }
  755. }
  756. dw2_asm_output_nstring (augmentation, -1, "CIE Augmentation");
  757. if (dw_cie_version >= 4)
  758. {
  759. dw2_asm_output_data (1, DWARF2_ADDR_SIZE, "CIE Address Size");
  760. dw2_asm_output_data (1, 0, "CIE Segment Size");
  761. }
  762. dw2_asm_output_data_uleb128 (1, "CIE Code Alignment Factor");
  763. dw2_asm_output_data_sleb128 (DWARF_CIE_DATA_ALIGNMENT,
  764. "CIE Data Alignment Factor");
  765. if (dw_cie_version == 1)
  766. dw2_asm_output_data (1, return_reg, "CIE RA Column");
  767. else
  768. dw2_asm_output_data_uleb128 (return_reg, "CIE RA Column");
  769. if (augmentation[0])
  770. {
  771. dw2_asm_output_data_uleb128 (augmentation_size, "Augmentation size");
  772. if (personality)
  773. {
  774. dw2_asm_output_data (1, per_encoding, "Personality (%s)",
  775. eh_data_format_name (per_encoding));
  776. dw2_asm_output_encoded_addr_rtx (per_encoding,
  777. personality,
  778. true, NULL);
  779. }
  780. if (any_lsda_needed)
  781. dw2_asm_output_data (1, lsda_encoding, "LSDA Encoding (%s)",
  782. eh_data_format_name (lsda_encoding));
  783. if (fde_encoding != DW_EH_PE_absptr)
  784. dw2_asm_output_data (1, fde_encoding, "FDE Encoding (%s)",
  785. eh_data_format_name (fde_encoding));
  786. }
  787. FOR_EACH_VEC_ELT (*cie_cfi_vec, i, cfi)
  788. output_cfi (cfi, NULL, for_eh);
  789. /* Pad the CIE out to an address sized boundary. */
  790. ASM_OUTPUT_ALIGN (asm_out_file,
  791. floor_log2 (for_eh ? PTR_SIZE : DWARF2_ADDR_SIZE));
  792. ASM_OUTPUT_LABEL (asm_out_file, l2);
  793. /* Loop through all of the FDE's. */
  794. FOR_EACH_VEC_ELT (*fde_vec, i, fde)
  795. {
  796. unsigned int k;
  797. /* Don't emit EH unwind info for leaf functions that don't need it. */
  798. if (for_eh && !fde_needed_for_eh_p (fde))
  799. continue;
  800. for (k = 0; k < (fde->dw_fde_second_begin ? 2 : 1); k++)
  801. output_fde (fde, for_eh, k, section_start_label, fde_encoding,
  802. augmentation, any_lsda_needed, lsda_encoding);
  803. }
  804. if (for_eh && targetm.terminate_dw2_eh_frame_info)
  805. dw2_asm_output_data (4, 0, "End of Table");
  806. /* Turn off app to make assembly quicker. */
  807. if (flag_debug_asm)
  808. app_disable ();
  809. }
  810. /* Emit .cfi_startproc and .cfi_personality/.cfi_lsda if needed. */
  811. static void
  812. dwarf2out_do_cfi_startproc (bool second)
  813. {
  814. int enc;
  815. rtx ref;
  816. rtx personality = get_personality_function (current_function_decl);
  817. fprintf (asm_out_file, "\t.cfi_startproc\n");
  818. if (personality)
  819. {
  820. enc = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/2, /*global=*/1);
  821. ref = personality;
  822. /* ??? The GAS support isn't entirely consistent. We have to
  823. handle indirect support ourselves, but PC-relative is done
  824. in the assembler. Further, the assembler can't handle any
  825. of the weirder relocation types. */
  826. if (enc & DW_EH_PE_indirect)
  827. ref = dw2_force_const_mem (ref, true);
  828. fprintf (asm_out_file, "\t.cfi_personality %#x,", enc);
  829. output_addr_const (asm_out_file, ref);
  830. fputc ('\n', asm_out_file);
  831. }
  832. if (crtl->uses_eh_lsda)
  833. {
  834. char lab[20];
  835. enc = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/0, /*global=*/0);
  836. ASM_GENERATE_INTERNAL_LABEL (lab, second ? "LLSDAC" : "LLSDA",
  837. current_function_funcdef_no);
  838. ref = gen_rtx_SYMBOL_REF (Pmode, lab);
  839. SYMBOL_REF_FLAGS (ref) = SYMBOL_FLAG_LOCAL;
  840. if (enc & DW_EH_PE_indirect)
  841. ref = dw2_force_const_mem (ref, true);
  842. fprintf (asm_out_file, "\t.cfi_lsda %#x,", enc);
  843. output_addr_const (asm_out_file, ref);
  844. fputc ('\n', asm_out_file);
  845. }
  846. }
  847. /* Allocate CURRENT_FDE. Immediately initialize all we can, noting that
  848. this allocation may be done before pass_final. */
  849. dw_fde_ref
  850. dwarf2out_alloc_current_fde (void)
  851. {
  852. dw_fde_ref fde;
  853. fde = ggc_cleared_alloc<dw_fde_node> ();
  854. fde->decl = current_function_decl;
  855. fde->funcdef_number = current_function_funcdef_no;
  856. fde->fde_index = vec_safe_length (fde_vec);
  857. fde->all_throwers_are_sibcalls = crtl->all_throwers_are_sibcalls;
  858. fde->uses_eh_lsda = crtl->uses_eh_lsda;
  859. fde->nothrow = crtl->nothrow;
  860. fde->drap_reg = INVALID_REGNUM;
  861. fde->vdrap_reg = INVALID_REGNUM;
  862. /* Record the FDE associated with this function. */
  863. cfun->fde = fde;
  864. vec_safe_push (fde_vec, fde);
  865. return fde;
  866. }
  867. /* Output a marker (i.e. a label) for the beginning of a function, before
  868. the prologue. */
  869. void
  870. dwarf2out_begin_prologue (unsigned int line ATTRIBUTE_UNUSED,
  871. const char *file ATTRIBUTE_UNUSED)
  872. {
  873. char label[MAX_ARTIFICIAL_LABEL_BYTES];
  874. char * dup_label;
  875. dw_fde_ref fde;
  876. section *fnsec;
  877. bool do_frame;
  878. current_function_func_begin_label = NULL;
  879. do_frame = dwarf2out_do_frame ();
  880. /* ??? current_function_func_begin_label is also used by except.c for
  881. call-site information. We must emit this label if it might be used. */
  882. if (!do_frame
  883. && (!flag_exceptions
  884. || targetm_common.except_unwind_info (&global_options) == UI_SJLJ))
  885. return;
  886. fnsec = function_section (current_function_decl);
  887. switch_to_section (fnsec);
  888. ASM_GENERATE_INTERNAL_LABEL (label, FUNC_BEGIN_LABEL,
  889. current_function_funcdef_no);
  890. ASM_OUTPUT_DEBUG_LABEL (asm_out_file, FUNC_BEGIN_LABEL,
  891. current_function_funcdef_no);
  892. dup_label = xstrdup (label);
  893. current_function_func_begin_label = dup_label;
  894. /* We can elide the fde allocation if we're not emitting debug info. */
  895. if (!do_frame)
  896. return;
  897. /* Cater to the various TARGET_ASM_OUTPUT_MI_THUNK implementations that
  898. emit insns as rtx but bypass the bulk of rest_of_compilation, which
  899. would include pass_dwarf2_frame. If we've not created the FDE yet,
  900. do so now. */
  901. fde = cfun->fde;
  902. if (fde == NULL)
  903. fde = dwarf2out_alloc_current_fde ();
  904. /* Initialize the bits of CURRENT_FDE that were not available earlier. */
  905. fde->dw_fde_begin = dup_label;
  906. fde->dw_fde_current_label = dup_label;
  907. fde->in_std_section = (fnsec == text_section
  908. || (cold_text_section && fnsec == cold_text_section));
  909. /* We only want to output line number information for the genuine dwarf2
  910. prologue case, not the eh frame case. */
  911. #ifdef DWARF2_DEBUGGING_INFO
  912. if (file)
  913. dwarf2out_source_line (line, file, 0, true);
  914. #endif
  915. if (dwarf2out_do_cfi_asm ())
  916. dwarf2out_do_cfi_startproc (false);
  917. else
  918. {
  919. rtx personality = get_personality_function (current_function_decl);
  920. if (!current_unit_personality)
  921. current_unit_personality = personality;
  922. /* We cannot keep a current personality per function as without CFI
  923. asm, at the point where we emit the CFI data, there is no current
  924. function anymore. */
  925. if (personality && current_unit_personality != personality)
  926. sorry ("multiple EH personalities are supported only with assemblers "
  927. "supporting .cfi_personality directive");
  928. }
  929. }
  930. /* Output a marker (i.e. a label) for the end of the generated code
  931. for a function prologue. This gets called *after* the prologue code has
  932. been generated. */
  933. void
  934. dwarf2out_vms_end_prologue (unsigned int line ATTRIBUTE_UNUSED,
  935. const char *file ATTRIBUTE_UNUSED)
  936. {
  937. char label[MAX_ARTIFICIAL_LABEL_BYTES];
  938. /* Output a label to mark the endpoint of the code generated for this
  939. function. */
  940. ASM_GENERATE_INTERNAL_LABEL (label, PROLOGUE_END_LABEL,
  941. current_function_funcdef_no);
  942. ASM_OUTPUT_DEBUG_LABEL (asm_out_file, PROLOGUE_END_LABEL,
  943. current_function_funcdef_no);
  944. cfun->fde->dw_fde_vms_end_prologue = xstrdup (label);
  945. }
  946. /* Output a marker (i.e. a label) for the beginning of the generated code
  947. for a function epilogue. This gets called *before* the prologue code has
  948. been generated. */
  949. void
  950. dwarf2out_vms_begin_epilogue (unsigned int line ATTRIBUTE_UNUSED,
  951. const char *file ATTRIBUTE_UNUSED)
  952. {
  953. dw_fde_ref fde = cfun->fde;
  954. char label[MAX_ARTIFICIAL_LABEL_BYTES];
  955. if (fde->dw_fde_vms_begin_epilogue)
  956. return;
  957. /* Output a label to mark the endpoint of the code generated for this
  958. function. */
  959. ASM_GENERATE_INTERNAL_LABEL (label, EPILOGUE_BEGIN_LABEL,
  960. current_function_funcdef_no);
  961. ASM_OUTPUT_DEBUG_LABEL (asm_out_file, EPILOGUE_BEGIN_LABEL,
  962. current_function_funcdef_no);
  963. fde->dw_fde_vms_begin_epilogue = xstrdup (label);
  964. }
  965. /* Output a marker (i.e. a label) for the absolute end of the generated code
  966. for a function definition. This gets called *after* the epilogue code has
  967. been generated. */
  968. void
  969. dwarf2out_end_epilogue (unsigned int line ATTRIBUTE_UNUSED,
  970. const char *file ATTRIBUTE_UNUSED)
  971. {
  972. dw_fde_ref fde;
  973. char label[MAX_ARTIFICIAL_LABEL_BYTES];
  974. last_var_location_insn = NULL;
  975. cached_next_real_insn = NULL;
  976. if (dwarf2out_do_cfi_asm ())
  977. fprintf (asm_out_file, "\t.cfi_endproc\n");
  978. /* Output a label to mark the endpoint of the code generated for this
  979. function. */
  980. ASM_GENERATE_INTERNAL_LABEL (label, FUNC_END_LABEL,
  981. current_function_funcdef_no);
  982. ASM_OUTPUT_LABEL (asm_out_file, label);
  983. fde = cfun->fde;
  984. gcc_assert (fde != NULL);
  985. if (fde->dw_fde_second_begin == NULL)
  986. fde->dw_fde_end = xstrdup (label);
  987. }
  988. void
  989. dwarf2out_frame_finish (void)
  990. {
  991. /* Output call frame information. */
  992. if (targetm.debug_unwind_info () == UI_DWARF2)
  993. output_call_frame_info (0);
  994. /* Output another copy for the unwinder. */
  995. if ((flag_unwind_tables || flag_exceptions)
  996. && targetm_common.except_unwind_info (&global_options) == UI_DWARF2)
  997. output_call_frame_info (1);
  998. }
  999. /* Note that the current function section is being used for code. */
  1000. static void
  1001. dwarf2out_note_section_used (void)
  1002. {
  1003. section *sec = current_function_section ();
  1004. if (sec == text_section)
  1005. text_section_used = true;
  1006. else if (sec == cold_text_section)
  1007. cold_text_section_used = true;
  1008. }
  1009. static void var_location_switch_text_section (void);
  1010. static void set_cur_line_info_table (section *);
  1011. void
  1012. dwarf2out_switch_text_section (void)
  1013. {
  1014. section *sect;
  1015. dw_fde_ref fde = cfun->fde;
  1016. gcc_assert (cfun && fde && fde->dw_fde_second_begin == NULL);
  1017. if (!in_cold_section_p)
  1018. {
  1019. fde->dw_fde_end = crtl->subsections.cold_section_end_label;
  1020. fde->dw_fde_second_begin = crtl->subsections.hot_section_label;
  1021. fde->dw_fde_second_end = crtl->subsections.hot_section_end_label;
  1022. }
  1023. else
  1024. {
  1025. fde->dw_fde_end = crtl->subsections.hot_section_end_label;
  1026. fde->dw_fde_second_begin = crtl->subsections.cold_section_label;
  1027. fde->dw_fde_second_end = crtl->subsections.cold_section_end_label;
  1028. }
  1029. have_multiple_function_sections = true;
  1030. /* There is no need to mark used sections when not debugging. */
  1031. if (cold_text_section != NULL)
  1032. dwarf2out_note_section_used ();
  1033. if (dwarf2out_do_cfi_asm ())
  1034. fprintf (asm_out_file, "\t.cfi_endproc\n");
  1035. /* Now do the real section switch. */
  1036. sect = current_function_section ();
  1037. switch_to_section (sect);
  1038. fde->second_in_std_section
  1039. = (sect == text_section
  1040. || (cold_text_section && sect == cold_text_section));
  1041. if (dwarf2out_do_cfi_asm ())
  1042. dwarf2out_do_cfi_startproc (true);
  1043. var_location_switch_text_section ();
  1044. if (cold_text_section != NULL)
  1045. set_cur_line_info_table (sect);
  1046. }
  1047. /* And now, the subset of the debugging information support code necessary
  1048. for emitting location expressions. */
  1049. /* Data about a single source file. */
  1050. struct GTY((for_user)) dwarf_file_data {
  1051. const char * filename;
  1052. int emitted_number;
  1053. };
  1054. typedef struct GTY(()) deferred_locations_struct
  1055. {
  1056. tree variable;
  1057. dw_die_ref die;
  1058. } deferred_locations;
  1059. static GTY(()) vec<deferred_locations, va_gc> *deferred_locations_list;
  1060. /* Describe an entry into the .debug_addr section. */
  1061. enum ate_kind {
  1062. ate_kind_rtx,
  1063. ate_kind_rtx_dtprel,
  1064. ate_kind_label
  1065. };
  1066. typedef struct GTY((for_user)) addr_table_entry_struct {
  1067. enum ate_kind kind;
  1068. unsigned int refcount;
  1069. unsigned int index;
  1070. union addr_table_entry_struct_union
  1071. {
  1072. rtx GTY ((tag ("0"))) rtl;
  1073. char * GTY ((tag ("1"))) label;
  1074. }
  1075. GTY ((desc ("%1.kind"))) addr;
  1076. }
  1077. addr_table_entry;
  1078. /* Location lists are ranges + location descriptions for that range,
  1079. so you can track variables that are in different places over
  1080. their entire life. */
  1081. typedef struct GTY(()) dw_loc_list_struct {
  1082. dw_loc_list_ref dw_loc_next;
  1083. const char *begin; /* Label and addr_entry for start of range */
  1084. addr_table_entry *begin_entry;
  1085. const char *end; /* Label for end of range */
  1086. char *ll_symbol; /* Label for beginning of location list.
  1087. Only on head of list */
  1088. const char *section; /* Section this loclist is relative to */
  1089. dw_loc_descr_ref expr;
  1090. hashval_t hash;
  1091. /* True if all addresses in this and subsequent lists are known to be
  1092. resolved. */
  1093. bool resolved_addr;
  1094. /* True if this list has been replaced by dw_loc_next. */
  1095. bool replaced;
  1096. bool emitted;
  1097. /* True if the range should be emitted even if begin and end
  1098. are the same. */
  1099. bool force;
  1100. } dw_loc_list_node;
  1101. static dw_loc_descr_ref int_loc_descriptor (HOST_WIDE_INT);
  1102. /* Convert a DWARF stack opcode into its string name. */
  1103. static const char *
  1104. dwarf_stack_op_name (unsigned int op)
  1105. {
  1106. const char *name = get_DW_OP_name (op);
  1107. if (name != NULL)
  1108. return name;
  1109. return "OP_<unknown>";
  1110. }
  1111. /* Return a pointer to a newly allocated location description. Location
  1112. descriptions are simple expression terms that can be strung
  1113. together to form more complicated location (address) descriptions. */
  1114. static inline dw_loc_descr_ref
  1115. new_loc_descr (enum dwarf_location_atom op, unsigned HOST_WIDE_INT oprnd1,
  1116. unsigned HOST_WIDE_INT oprnd2)
  1117. {
  1118. dw_loc_descr_ref descr = ggc_cleared_alloc<dw_loc_descr_node> ();
  1119. descr->dw_loc_opc = op;
  1120. descr->dw_loc_oprnd1.val_class = dw_val_class_unsigned_const;
  1121. descr->dw_loc_oprnd1.val_entry = NULL;
  1122. descr->dw_loc_oprnd1.v.val_unsigned = oprnd1;
  1123. descr->dw_loc_oprnd2.val_class = dw_val_class_unsigned_const;
  1124. descr->dw_loc_oprnd2.val_entry = NULL;
  1125. descr->dw_loc_oprnd2.v.val_unsigned = oprnd2;
  1126. return descr;
  1127. }
  1128. /* Return a pointer to a newly allocated location description for
  1129. REG and OFFSET. */
  1130. static inline dw_loc_descr_ref
  1131. new_reg_loc_descr (unsigned int reg, unsigned HOST_WIDE_INT offset)
  1132. {
  1133. if (reg <= 31)
  1134. return new_loc_descr ((enum dwarf_location_atom) (DW_OP_breg0 + reg),
  1135. offset, 0);
  1136. else
  1137. return new_loc_descr (DW_OP_bregx, reg, offset);
  1138. }
  1139. /* Add a location description term to a location description expression. */
  1140. static inline void
  1141. add_loc_descr (dw_loc_descr_ref *list_head, dw_loc_descr_ref descr)
  1142. {
  1143. dw_loc_descr_ref *d;
  1144. /* Find the end of the chain. */
  1145. for (d = list_head; (*d) != NULL; d = &(*d)->dw_loc_next)
  1146. ;
  1147. *d = descr;
  1148. }
  1149. /* Compare two location operands for exact equality. */
  1150. static bool
  1151. dw_val_equal_p (dw_val_node *a, dw_val_node *b)
  1152. {
  1153. if (a->val_class != b->val_class)
  1154. return false;
  1155. switch (a->val_class)
  1156. {
  1157. case dw_val_class_none:
  1158. return true;
  1159. case dw_val_class_addr:
  1160. return rtx_equal_p (a->v.val_addr, b->v.val_addr);
  1161. case dw_val_class_offset:
  1162. case dw_val_class_unsigned_const:
  1163. case dw_val_class_const:
  1164. case dw_val_class_range_list:
  1165. case dw_val_class_lineptr:
  1166. case dw_val_class_macptr:
  1167. /* These are all HOST_WIDE_INT, signed or unsigned. */
  1168. return a->v.val_unsigned == b->v.val_unsigned;
  1169. case dw_val_class_loc:
  1170. return a->v.val_loc == b->v.val_loc;
  1171. case dw_val_class_loc_list:
  1172. return a->v.val_loc_list == b->v.val_loc_list;
  1173. case dw_val_class_die_ref:
  1174. return a->v.val_die_ref.die == b->v.val_die_ref.die;
  1175. case dw_val_class_fde_ref:
  1176. return a->v.val_fde_index == b->v.val_fde_index;
  1177. case dw_val_class_lbl_id:
  1178. case dw_val_class_high_pc:
  1179. return strcmp (a->v.val_lbl_id, b->v.val_lbl_id) == 0;
  1180. case dw_val_class_str:
  1181. return a->v.val_str == b->v.val_str;
  1182. case dw_val_class_flag:
  1183. return a->v.val_flag == b->v.val_flag;
  1184. case dw_val_class_file:
  1185. return a->v.val_file == b->v.val_file;
  1186. case dw_val_class_decl_ref:
  1187. return a->v.val_decl_ref == b->v.val_decl_ref;
  1188. case dw_val_class_const_double:
  1189. return (a->v.val_double.high == b->v.val_double.high
  1190. && a->v.val_double.low == b->v.val_double.low);
  1191. case dw_val_class_wide_int:
  1192. return *a->v.val_wide == *b->v.val_wide;
  1193. case dw_val_class_vec:
  1194. {
  1195. size_t a_len = a->v.val_vec.elt_size * a->v.val_vec.length;
  1196. size_t b_len = b->v.val_vec.elt_size * b->v.val_vec.length;
  1197. return (a_len == b_len
  1198. && !memcmp (a->v.val_vec.array, b->v.val_vec.array, a_len));
  1199. }
  1200. case dw_val_class_data8:
  1201. return memcmp (a->v.val_data8, b->v.val_data8, 8) == 0;
  1202. case dw_val_class_vms_delta:
  1203. return (!strcmp (a->v.val_vms_delta.lbl1, b->v.val_vms_delta.lbl1)
  1204. && !strcmp (a->v.val_vms_delta.lbl1, b->v.val_vms_delta.lbl1));
  1205. }
  1206. gcc_unreachable ();
  1207. }
  1208. /* Compare two location atoms for exact equality. */
  1209. static bool
  1210. loc_descr_equal_p_1 (dw_loc_descr_ref a, dw_loc_descr_ref b)
  1211. {
  1212. if (a->dw_loc_opc != b->dw_loc_opc)
  1213. return false;
  1214. /* ??? This is only ever set for DW_OP_constNu, for N equal to the
  1215. address size, but since we always allocate cleared storage it
  1216. should be zero for other types of locations. */
  1217. if (a->dtprel != b->dtprel)
  1218. return false;
  1219. return (dw_val_equal_p (&a->dw_loc_oprnd1, &b->dw_loc_oprnd1)
  1220. && dw_val_equal_p (&a->dw_loc_oprnd2, &b->dw_loc_oprnd2));
  1221. }
  1222. /* Compare two complete location expressions for exact equality. */
  1223. bool
  1224. loc_descr_equal_p (dw_loc_descr_ref a, dw_loc_descr_ref b)
  1225. {
  1226. while (1)
  1227. {
  1228. if (a == b)
  1229. return true;
  1230. if (a == NULL || b == NULL)
  1231. return false;
  1232. if (!loc_descr_equal_p_1 (a, b))
  1233. return false;
  1234. a = a->dw_loc_next;
  1235. b = b->dw_loc_next;
  1236. }
  1237. }
  1238. /* Add a constant OFFSET to a location expression. */
  1239. static void
  1240. loc_descr_plus_const (dw_loc_descr_ref *list_head, HOST_WIDE_INT offset)
  1241. {
  1242. dw_loc_descr_ref loc;
  1243. HOST_WIDE_INT *p;
  1244. gcc_assert (*list_head != NULL);
  1245. if (!offset)
  1246. return;
  1247. /* Find the end of the chain. */
  1248. for (loc = *list_head; loc->dw_loc_next != NULL; loc = loc->dw_loc_next)
  1249. ;
  1250. p = NULL;
  1251. if (loc->dw_loc_opc == DW_OP_fbreg
  1252. || (loc->dw_loc_opc >= DW_OP_breg0 && loc->dw_loc_opc <= DW_OP_breg31))
  1253. p = &loc->dw_loc_oprnd1.v.val_int;
  1254. else if (loc->dw_loc_opc == DW_OP_bregx)
  1255. p = &loc->dw_loc_oprnd2.v.val_int;
  1256. /* If the last operation is fbreg, breg{0..31,x}, optimize by adjusting its
  1257. offset. Don't optimize if an signed integer overflow would happen. */
  1258. if (p != NULL
  1259. && ((offset > 0 && *p <= INTTYPE_MAXIMUM (HOST_WIDE_INT) - offset)
  1260. || (offset < 0 && *p >= INTTYPE_MINIMUM (HOST_WIDE_INT) - offset)))
  1261. *p += offset;
  1262. else if (offset > 0)
  1263. loc->dw_loc_next = new_loc_descr (DW_OP_plus_uconst, offset, 0);
  1264. else
  1265. {
  1266. loc->dw_loc_next = int_loc_descriptor (-offset);
  1267. add_loc_descr (&loc->dw_loc_next, new_loc_descr (DW_OP_minus, 0, 0));
  1268. }
  1269. }
  1270. /* Add a constant OFFSET to a location list. */
  1271. static void
  1272. loc_list_plus_const (dw_loc_list_ref list_head, HOST_WIDE_INT offset)
  1273. {
  1274. dw_loc_list_ref d;
  1275. for (d = list_head; d != NULL; d = d->dw_loc_next)
  1276. loc_descr_plus_const (&d->expr, offset);
  1277. }
  1278. #define DWARF_REF_SIZE \
  1279. (dwarf_version == 2 ? DWARF2_ADDR_SIZE : DWARF_OFFSET_SIZE)
  1280. static unsigned long int get_base_type_offset (dw_die_ref);
  1281. /* Return the size of a location descriptor. */
  1282. static unsigned long
  1283. size_of_loc_descr (dw_loc_descr_ref loc)
  1284. {
  1285. unsigned long size = 1;
  1286. switch (loc->dw_loc_opc)
  1287. {
  1288. case DW_OP_addr:
  1289. size += DWARF2_ADDR_SIZE;
  1290. break;
  1291. case DW_OP_GNU_addr_index:
  1292. case DW_OP_GNU_const_index:
  1293. gcc_assert (loc->dw_loc_oprnd1.val_entry->index != NO_INDEX_ASSIGNED);
  1294. size += size_of_uleb128 (loc->dw_loc_oprnd1.val_entry->index);
  1295. break;
  1296. case DW_OP_const1u:
  1297. case DW_OP_const1s:
  1298. size += 1;
  1299. break;
  1300. case DW_OP_const2u:
  1301. case DW_OP_const2s:
  1302. size += 2;
  1303. break;
  1304. case DW_OP_const4u:
  1305. case DW_OP_const4s:
  1306. size += 4;
  1307. break;
  1308. case DW_OP_const8u:
  1309. case DW_OP_const8s:
  1310. size += 8;
  1311. break;
  1312. case DW_OP_constu:
  1313. size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
  1314. break;
  1315. case DW_OP_consts:
  1316. size += size_of_sleb128 (loc->dw_loc_oprnd1.v.val_int);
  1317. break;
  1318. case DW_OP_pick:
  1319. size += 1;
  1320. break;
  1321. case DW_OP_plus_uconst:
  1322. size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
  1323. break;
  1324. case DW_OP_skip:
  1325. case DW_OP_bra:
  1326. size += 2;
  1327. break;
  1328. case DW_OP_breg0:
  1329. case DW_OP_breg1:
  1330. case DW_OP_breg2:
  1331. case DW_OP_breg3:
  1332. case DW_OP_breg4:
  1333. case DW_OP_breg5:
  1334. case DW_OP_breg6:
  1335. case DW_OP_breg7:
  1336. case DW_OP_breg8:
  1337. case DW_OP_breg9:
  1338. case DW_OP_breg10:
  1339. case DW_OP_breg11:
  1340. case DW_OP_breg12:
  1341. case DW_OP_breg13:
  1342. case DW_OP_breg14:
  1343. case DW_OP_breg15:
  1344. case DW_OP_breg16:
  1345. case DW_OP_breg17:
  1346. case DW_OP_breg18:
  1347. case DW_OP_breg19:
  1348. case DW_OP_breg20:
  1349. case DW_OP_breg21:
  1350. case DW_OP_breg22:
  1351. case DW_OP_breg23:
  1352. case DW_OP_breg24:
  1353. case DW_OP_breg25:
  1354. case DW_OP_breg26:
  1355. case DW_OP_breg27:
  1356. case DW_OP_breg28:
  1357. case DW_OP_breg29:
  1358. case DW_OP_breg30:
  1359. case DW_OP_breg31:
  1360. size += size_of_sleb128 (loc->dw_loc_oprnd1.v.val_int);
  1361. break;
  1362. case DW_OP_regx:
  1363. size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
  1364. break;
  1365. case DW_OP_fbreg:
  1366. size += size_of_sleb128 (loc->dw_loc_oprnd1.v.val_int);
  1367. break;
  1368. case DW_OP_bregx:
  1369. size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
  1370. size += size_of_sleb128 (loc->dw_loc_oprnd2.v.val_int);
  1371. break;
  1372. case DW_OP_piece:
  1373. size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
  1374. break;
  1375. case DW_OP_bit_piece:
  1376. size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
  1377. size += size_of_uleb128 (loc->dw_loc_oprnd2.v.val_unsigned);
  1378. break;
  1379. case DW_OP_deref_size:
  1380. case DW_OP_xderef_size:
  1381. size += 1;
  1382. break;
  1383. case DW_OP_call2:
  1384. size += 2;
  1385. break;
  1386. case DW_OP_call4:
  1387. size += 4;
  1388. break;
  1389. case DW_OP_call_ref:
  1390. size += DWARF_REF_SIZE;
  1391. break;
  1392. case DW_OP_implicit_value:
  1393. size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned)
  1394. + loc->dw_loc_oprnd1.v.val_unsigned;
  1395. break;
  1396. case DW_OP_GNU_implicit_pointer:
  1397. size += DWARF_REF_SIZE + size_of_sleb128 (loc->dw_loc_oprnd2.v.val_int);
  1398. break;
  1399. case DW_OP_GNU_entry_value:
  1400. {
  1401. unsigned long op_size = size_of_locs (loc->dw_loc_oprnd1.v.val_loc);
  1402. size += size_of_uleb128 (op_size) + op_size;
  1403. break;
  1404. }
  1405. case DW_OP_GNU_const_type:
  1406. {
  1407. unsigned long o
  1408. = get_base_type_offset (loc->dw_loc_oprnd1.v.val_die_ref.die);
  1409. size += size_of_uleb128 (o) + 1;
  1410. switch (loc->dw_loc_oprnd2.val_class)
  1411. {
  1412. case dw_val_class_vec:
  1413. size += loc->dw_loc_oprnd2.v.val_vec.length
  1414. * loc->dw_loc_oprnd2.v.val_vec.elt_size;
  1415. break;
  1416. case dw_val_class_const:
  1417. size += HOST_BITS_PER_WIDE_INT / BITS_PER_UNIT;
  1418. break;
  1419. case dw_val_class_const_double:
  1420. size += HOST_BITS_PER_DOUBLE_INT / BITS_PER_UNIT;
  1421. break;
  1422. case dw_val_class_wide_int:
  1423. size += (get_full_len (*loc->dw_loc_oprnd2.v.val_wide)
  1424. * HOST_BITS_PER_WIDE_INT / BITS_PER_UNIT);
  1425. break;
  1426. default:
  1427. gcc_unreachable ();
  1428. }
  1429. break;
  1430. }
  1431. case DW_OP_GNU_regval_type:
  1432. {
  1433. unsigned long o
  1434. = get_base_type_offset (loc->dw_loc_oprnd2.v.val_die_ref.die);
  1435. size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned)
  1436. + size_of_uleb128 (o);
  1437. }
  1438. break;
  1439. case DW_OP_GNU_deref_type:
  1440. {
  1441. unsigned long o
  1442. = get_base_type_offset (loc->dw_loc_oprnd2.v.val_die_ref.die);
  1443. size += 1 + size_of_uleb128 (o);
  1444. }
  1445. break;
  1446. case DW_OP_GNU_convert:
  1447. case DW_OP_GNU_reinterpret:
  1448. if (loc->dw_loc_oprnd1.val_class == dw_val_class_unsigned_const)
  1449. size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
  1450. else
  1451. {
  1452. unsigned long o
  1453. = get_base_type_offset (loc->dw_loc_oprnd1.v.val_die_ref.die);
  1454. size += size_of_uleb128 (o);
  1455. }
  1456. break;
  1457. case DW_OP_GNU_parameter_ref:
  1458. size += 4;
  1459. break;
  1460. default:
  1461. break;
  1462. }
  1463. return size;
  1464. }
  1465. /* Return the size of a series of location descriptors. */
  1466. unsigned long
  1467. size_of_locs (dw_loc_descr_ref loc)
  1468. {
  1469. dw_loc_descr_ref l;
  1470. unsigned long size;
  1471. /* If there are no skip or bra opcodes, don't fill in the dw_loc_addr
  1472. field, to avoid writing to a PCH file. */
  1473. for (size = 0, l = loc; l != NULL; l = l->dw_loc_next)
  1474. {
  1475. if (l->dw_loc_opc == DW_OP_skip || l->dw_loc_opc == DW_OP_bra)
  1476. break;
  1477. size += size_of_loc_descr (l);
  1478. }
  1479. if (! l)
  1480. return size;
  1481. for (size = 0, l = loc; l != NULL; l = l->dw_loc_next)
  1482. {
  1483. l->dw_loc_addr = size;
  1484. size += size_of_loc_descr (l);
  1485. }
  1486. return size;
  1487. }
  1488. static HOST_WIDE_INT extract_int (const unsigned char *, unsigned);
  1489. static void get_ref_die_offset_label (char *, dw_die_ref);
  1490. static unsigned long int get_ref_die_offset (dw_die_ref);
  1491. /* Output location description stack opcode's operands (if any).
  1492. The for_eh_or_skip parameter controls whether register numbers are
  1493. converted using DWARF2_FRAME_REG_OUT, which is needed in the case that
  1494. hard reg numbers have been processed via DWARF_FRAME_REGNUM (i.e. for unwind
  1495. info). This should be suppressed for the cases that have not been converted
  1496. (i.e. symbolic debug info), by setting the parameter < 0. See PR47324. */
  1497. static void
  1498. output_loc_operands (dw_loc_descr_ref loc, int for_eh_or_skip)
  1499. {
  1500. dw_val_ref val1 = &loc->dw_loc_oprnd1;
  1501. dw_val_ref val2 = &loc->dw_loc_oprnd2;
  1502. switch (loc->dw_loc_opc)
  1503. {
  1504. #ifdef DWARF2_DEBUGGING_INFO
  1505. case DW_OP_const2u:
  1506. case DW_OP_const2s:
  1507. dw2_asm_output_data (2, val1->v.val_int, NULL);
  1508. break;
  1509. case DW_OP_const4u:
  1510. if (loc->dtprel)
  1511. {
  1512. gcc_assert (targetm.asm_out.output_dwarf_dtprel);
  1513. targetm.asm_out.output_dwarf_dtprel (asm_out_file, 4,
  1514. val1->v.val_addr);
  1515. fputc ('\n', asm_out_file);
  1516. break;
  1517. }
  1518. /* FALLTHRU */
  1519. case DW_OP_const4s:
  1520. dw2_asm_output_data (4, val1->v.val_int, NULL);
  1521. break;
  1522. case DW_OP_const8u:
  1523. if (loc->dtprel)
  1524. {
  1525. gcc_assert (targetm.asm_out.output_dwarf_dtprel);
  1526. targetm.asm_out.output_dwarf_dtprel (asm_out_file, 8,
  1527. val1->v.val_addr);
  1528. fputc ('\n', asm_out_file);
  1529. break;
  1530. }
  1531. /* FALLTHRU */
  1532. case DW_OP_const8s:
  1533. gcc_assert (HOST_BITS_PER_WIDE_INT >= 64);
  1534. dw2_asm_output_data (8, val1->v.val_int, NULL);
  1535. break;
  1536. case DW_OP_skip:
  1537. case DW_OP_bra:
  1538. {
  1539. int offset;
  1540. gcc_assert (val1->val_class == dw_val_class_loc);
  1541. offset = val1->v.val_loc->dw_loc_addr - (loc->dw_loc_addr + 3);
  1542. dw2_asm_output_data (2, offset, NULL);
  1543. }
  1544. break;
  1545. case DW_OP_implicit_value:
  1546. dw2_asm_output_data_uleb128 (val1->v.val_unsigned, NULL);
  1547. switch (val2->val_class)
  1548. {
  1549. case dw_val_class_const:
  1550. dw2_asm_output_data (val1->v.val_unsigned, val2->v.val_int, NULL);
  1551. break;
  1552. case dw_val_class_vec:
  1553. {
  1554. unsigned int elt_size = val2->v.val_vec.elt_size;
  1555. unsigned int len = val2->v.val_vec.length;
  1556. unsigned int i;
  1557. unsigned char *p;
  1558. if (elt_size > sizeof (HOST_WIDE_INT))
  1559. {
  1560. elt_size /= 2;
  1561. len *= 2;
  1562. }
  1563. for (i = 0, p = val2->v.val_vec.array;
  1564. i < len;
  1565. i++, p += elt_size)
  1566. dw2_asm_output_data (elt_size, extract_int (p, elt_size),
  1567. "fp or vector constant word %u", i);
  1568. }
  1569. break;
  1570. case dw_val_class_const_double:
  1571. {
  1572. unsigned HOST_WIDE_INT first, second;
  1573. if (WORDS_BIG_ENDIAN)
  1574. {
  1575. first = val2->v.val_double.high;
  1576. second = val2->v.val_double.low;
  1577. }
  1578. else
  1579. {
  1580. first = val2->v.val_double.low;
  1581. second = val2->v.val_double.high;
  1582. }
  1583. dw2_asm_output_data (HOST_BITS_PER_WIDE_INT / HOST_BITS_PER_CHAR,
  1584. first, NULL);
  1585. dw2_asm_output_data (HOST_BITS_PER_WIDE_INT / HOST_BITS_PER_CHAR,
  1586. second, NULL);
  1587. }
  1588. break;
  1589. case dw_val_class_wide_int:
  1590. {
  1591. int i;
  1592. int len = get_full_len (*val2->v.val_wide);
  1593. if (WORDS_BIG_ENDIAN)
  1594. for (i = len - 1; i >= 0; --i)
  1595. dw2_asm_output_data (HOST_BITS_PER_WIDE_INT / HOST_BITS_PER_CHAR,
  1596. val2->v.val_wide->elt (i), NULL);
  1597. else
  1598. for (i = 0; i < len; ++i)
  1599. dw2_asm_output_data (HOST_BITS_PER_WIDE_INT / HOST_BITS_PER_CHAR,
  1600. val2->v.val_wide->elt (i), NULL);
  1601. }
  1602. break;
  1603. case dw_val_class_addr:
  1604. gcc_assert (val1->v.val_unsigned == DWARF2_ADDR_SIZE);
  1605. dw2_asm_output_addr_rtx (DWARF2_ADDR_SIZE, val2->v.val_addr, NULL);
  1606. break;
  1607. default:
  1608. gcc_unreachable ();
  1609. }
  1610. break;
  1611. #else
  1612. case DW_OP_const2u:
  1613. case DW_OP_const2s:
  1614. case DW_OP_const4u:
  1615. case DW_OP_const4s:
  1616. case DW_OP_const8u:
  1617. case DW_OP_const8s:
  1618. case DW_OP_skip:
  1619. case DW_OP_bra:
  1620. case DW_OP_implicit_value:
  1621. /* We currently don't make any attempt to make sure these are
  1622. aligned properly like we do for the main unwind info, so
  1623. don't support emitting things larger than a byte if we're
  1624. only doing unwinding. */
  1625. gcc_unreachable ();
  1626. #endif
  1627. case DW_OP_const1u:
  1628. case DW_OP_const1s:
  1629. dw2_asm_output_data (1, val1->v.val_int, NULL);
  1630. break;
  1631. case DW_OP_constu:
  1632. dw2_asm_output_data_uleb128 (val1->v.val_unsigned, NULL);
  1633. break;
  1634. case DW_OP_consts:
  1635. dw2_asm_output_data_sleb128 (val1->v.val_int, NULL);
  1636. break;
  1637. case DW_OP_pick:
  1638. dw2_asm_output_data (1, val1->v.val_int, NULL);
  1639. break;
  1640. case DW_OP_plus_uconst:
  1641. dw2_asm_output_data_uleb128 (val1->v.val_unsigned, NULL);
  1642. break;
  1643. case DW_OP_breg0:
  1644. case DW_OP_breg1:
  1645. case DW_OP_breg2:
  1646. case DW_OP_breg3:
  1647. case DW_OP_breg4:
  1648. case DW_OP_breg5:
  1649. case DW_OP_breg6:
  1650. case DW_OP_breg7:
  1651. case DW_OP_breg8:
  1652. case DW_OP_breg9:
  1653. case DW_OP_breg10:
  1654. case DW_OP_breg11:
  1655. case DW_OP_breg12:
  1656. case DW_OP_breg13:
  1657. case DW_OP_breg14:
  1658. case DW_OP_breg15:
  1659. case DW_OP_breg16:
  1660. case DW_OP_breg17:
  1661. case DW_OP_breg18:
  1662. case DW_OP_breg19:
  1663. case DW_OP_breg20:
  1664. case DW_OP_breg21:
  1665. case DW_OP_breg22:
  1666. case DW_OP_breg23:
  1667. case DW_OP_breg24:
  1668. case DW_OP_breg25:
  1669. case DW_OP_breg26:
  1670. case DW_OP_breg27:
  1671. case DW_OP_breg28:
  1672. case DW_OP_breg29:
  1673. case DW_OP_breg30:
  1674. case DW_OP_breg31:
  1675. dw2_asm_output_data_sleb128 (val1->v.val_int, NULL);
  1676. break;
  1677. case DW_OP_regx:
  1678. {
  1679. unsigned r = val1->v.val_unsigned;
  1680. if (for_eh_or_skip >= 0)
  1681. r = DWARF2_FRAME_REG_OUT (r, for_eh_or_skip);
  1682. gcc_assert (size_of_uleb128 (r)
  1683. == size_of_uleb128 (val1->v.val_unsigned));
  1684. dw2_asm_output_data_uleb128 (r, NULL);
  1685. }
  1686. break;
  1687. case DW_OP_fbreg:
  1688. dw2_asm_output_data_sleb128 (val1->v.val_int, NULL);
  1689. break;
  1690. case DW_OP_bregx:
  1691. {
  1692. unsigned r = val1->v.val_unsigned;
  1693. if (for_eh_or_skip >= 0)
  1694. r = DWARF2_FRAME_REG_OUT (r, for_eh_or_skip);
  1695. gcc_assert (size_of_uleb128 (r)
  1696. == size_of_uleb128 (val1->v.val_unsigned));
  1697. dw2_asm_output_data_uleb128 (r, NULL);
  1698. dw2_asm_output_data_sleb128 (val2->v.val_int, NULL);
  1699. }
  1700. break;
  1701. case DW_OP_piece:
  1702. dw2_asm_output_data_uleb128 (val1->v.val_unsigned, NULL);
  1703. break;
  1704. case DW_OP_bit_piece:
  1705. dw2_asm_output_data_uleb128 (val1->v.val_unsigned, NULL);
  1706. dw2_asm_output_data_uleb128 (val2->v.val_unsigned, NULL);
  1707. break;
  1708. case DW_OP_deref_size:
  1709. case DW_OP_xderef_size:
  1710. dw2_asm_output_data (1, val1->v.val_int, NULL);
  1711. break;
  1712. case DW_OP_addr:
  1713. if (loc->dtprel)
  1714. {
  1715. if (targetm.asm_out.output_dwarf_dtprel)
  1716. {
  1717. targetm.asm_out.output_dwarf_dtprel (asm_out_file,
  1718. DWARF2_ADDR_SIZE,
  1719. val1->v.val_addr);
  1720. fputc ('\n', asm_out_file);
  1721. }
  1722. else
  1723. gcc_unreachable ();
  1724. }
  1725. else
  1726. {
  1727. #ifdef DWARF2_DEBUGGING_INFO
  1728. dw2_asm_output_addr_rtx (DWARF2_ADDR_SIZE, val1->v.val_addr, NULL);
  1729. #else
  1730. gcc_unreachable ();
  1731. #endif
  1732. }
  1733. break;
  1734. case DW_OP_GNU_addr_index:
  1735. case DW_OP_GNU_const_index:
  1736. gcc_assert (loc->dw_loc_oprnd1.val_entry->index != NO_INDEX_ASSIGNED);
  1737. dw2_asm_output_data_uleb128 (loc->dw_loc_oprnd1.val_entry->index,
  1738. "(index into .debug_addr)");
  1739. break;
  1740. case DW_OP_GNU_implicit_pointer:
  1741. {
  1742. char label[MAX_ARTIFICIAL_LABEL_BYTES
  1743. + HOST_BITS_PER_WIDE_INT / 2 + 2];
  1744. gcc_assert (val1->val_class == dw_val_class_die_ref);
  1745. get_ref_die_offset_label (label, val1->v.val_die_ref.die);
  1746. dw2_asm_output_offset (DWARF_REF_SIZE, label, debug_info_section, NULL);
  1747. dw2_asm_output_data_sleb128 (val2->v.val_int, NULL);
  1748. }
  1749. break;
  1750. case DW_OP_GNU_entry_value:
  1751. dw2_asm_output_data_uleb128 (size_of_locs (val1->v.val_loc), NULL);
  1752. output_loc_sequence (val1->v.val_loc, for_eh_or_skip);
  1753. break;
  1754. case DW_OP_GNU_const_type:
  1755. {
  1756. unsigned long o = get_base_type_offset (val1->v.val_die_ref.die), l;
  1757. gcc_assert (o);
  1758. dw2_asm_output_data_uleb128 (o, NULL);
  1759. switch (val2->val_class)
  1760. {
  1761. case dw_val_class_const:
  1762. l = HOST_BITS_PER_WIDE_INT / HOST_BITS_PER_CHAR;
  1763. dw2_asm_output_data (1, l, NULL);
  1764. dw2_asm_output_data (l, val2->v.val_int, NULL);
  1765. break;
  1766. case dw_val_class_vec:
  1767. {
  1768. unsigned int elt_size = val2->v.val_vec.elt_size;
  1769. unsigned int len = val2->v.val_vec.length;
  1770. unsigned int i;
  1771. unsigned char *p;
  1772. l = len * elt_size;
  1773. dw2_asm_output_data (1, l, NULL);
  1774. if (elt_size > sizeof (HOST_WIDE_INT))
  1775. {
  1776. elt_size /= 2;
  1777. len *= 2;
  1778. }
  1779. for (i = 0, p = val2->v.val_vec.array;
  1780. i < len;
  1781. i++, p += elt_size)
  1782. dw2_asm_output_data (elt_size, extract_int (p, elt_size),
  1783. "fp or vector constant word %u", i);
  1784. }
  1785. break;
  1786. case dw_val_class_const_double:
  1787. {
  1788. unsigned HOST_WIDE_INT first, second;
  1789. l = HOST_BITS_PER_WIDE_INT / HOST_BITS_PER_CHAR;
  1790. dw2_asm_output_data (1, 2 * l, NULL);
  1791. if (WORDS_BIG_ENDIAN)
  1792. {
  1793. first = val2->v.val_double.high;
  1794. second = val2->v.val_double.low;
  1795. }
  1796. else
  1797. {
  1798. first = val2->v.val_double.low;
  1799. second = val2->v.val_double.high;
  1800. }
  1801. dw2_asm_output_data (l, first, NULL);
  1802. dw2_asm_output_data (l, second, NULL);
  1803. }
  1804. break;
  1805. case dw_val_class_wide_int:
  1806. {
  1807. int i;
  1808. int len = get_full_len (*val2->v.val_wide);
  1809. l = HOST_BITS_PER_WIDE_INT / HOST_BITS_PER_CHAR;
  1810. dw2_asm_output_data (1, len * l, NULL);
  1811. if (WORDS_BIG_ENDIAN)
  1812. for (i = len - 1; i >= 0; --i)
  1813. dw2_asm_output_data (l, val2->v.val_wide->elt (i), NULL);
  1814. else
  1815. for (i = 0; i < len; ++i)
  1816. dw2_asm_output_data (l, val2->v.val_wide->elt (i), NULL);
  1817. }
  1818. break;
  1819. default:
  1820. gcc_unreachable ();
  1821. }
  1822. }
  1823. break;
  1824. case DW_OP_GNU_regval_type:
  1825. {
  1826. unsigned r = val1->v.val_unsigned;
  1827. unsigned long o = get_base_type_offset (val2->v.val_die_ref.die);
  1828. gcc_assert (o);
  1829. if (for_eh_or_skip >= 0)
  1830. {
  1831. r = DWARF2_FRAME_REG_OUT (r, for_eh_or_skip);
  1832. gcc_assert (size_of_uleb128 (r)
  1833. == size_of_uleb128 (val1->v.val_unsigned));
  1834. }
  1835. dw2_asm_output_data_uleb128 (r, NULL);
  1836. dw2_asm_output_data_uleb128 (o, NULL);
  1837. }
  1838. break;
  1839. case DW_OP_GNU_deref_type:
  1840. {
  1841. unsigned long o = get_base_type_offset (val2->v.val_die_ref.die);
  1842. gcc_assert (o);
  1843. dw2_asm_output_data (1, val1->v.val_int, NULL);
  1844. dw2_asm_output_data_uleb128 (o, NULL);
  1845. }
  1846. break;
  1847. case DW_OP_GNU_convert:
  1848. case DW_OP_GNU_reinterpret:
  1849. if (loc->dw_loc_oprnd1.val_class == dw_val_class_unsigned_const)
  1850. dw2_asm_output_data_uleb128 (val1->v.val_unsigned, NULL);
  1851. else
  1852. {
  1853. unsigned long o = get_base_type_offset (val1->v.val_die_ref.die);
  1854. gcc_assert (o);
  1855. dw2_asm_output_data_uleb128 (o, NULL);
  1856. }
  1857. break;
  1858. case DW_OP_GNU_parameter_ref:
  1859. {
  1860. unsigned long o;
  1861. gcc_assert (val1->val_class == dw_val_class_die_ref);
  1862. o = get_ref_die_offset (val1->v.val_die_ref.die);
  1863. dw2_asm_output_data (4, o, NULL);
  1864. }
  1865. break;
  1866. default:
  1867. /* Other codes have no operands. */
  1868. break;
  1869. }
  1870. }
  1871. /* Output a sequence of location operations.
  1872. The for_eh_or_skip parameter controls whether register numbers are
  1873. converted using DWARF2_FRAME_REG_OUT, which is needed in the case that
  1874. hard reg numbers have been processed via DWARF_FRAME_REGNUM (i.e. for unwind
  1875. info). This should be suppressed for the cases that have not been converted
  1876. (i.e. symbolic debug info), by setting the parameter < 0. See PR47324. */
  1877. void
  1878. output_loc_sequence (dw_loc_descr_ref loc, int for_eh_or_skip)
  1879. {
  1880. for (; loc != NULL; loc = loc->dw_loc_next)
  1881. {
  1882. enum dwarf_location_atom opc = loc->dw_loc_opc;
  1883. /* Output the opcode. */
  1884. if (for_eh_or_skip >= 0
  1885. && opc >= DW_OP_breg0 && opc <= DW_OP_breg31)
  1886. {
  1887. unsigned r = (opc - DW_OP_breg0);
  1888. r = DWARF2_FRAME_REG_OUT (r, for_eh_or_skip);
  1889. gcc_assert (r <= 31);
  1890. opc = (enum dwarf_location_atom) (DW_OP_breg0 + r);
  1891. }
  1892. else if (for_eh_or_skip >= 0
  1893. && opc >= DW_OP_reg0 && opc <= DW_OP_reg31)
  1894. {
  1895. unsigned r = (opc - DW_OP_reg0);
  1896. r = DWARF2_FRAME_REG_OUT (r, for_eh_or_skip);
  1897. gcc_assert (r <= 31);
  1898. opc = (enum dwarf_location_atom) (DW_OP_reg0 + r);
  1899. }
  1900. dw2_asm_output_data (1, opc,
  1901. "%s", dwarf_stack_op_name (opc));
  1902. /* Output the operand(s) (if any). */
  1903. output_loc_operands (loc, for_eh_or_skip);
  1904. }
  1905. }
  1906. /* Output location description stack opcode's operands (if any).
  1907. The output is single bytes on a line, suitable for .cfi_escape. */
  1908. static void
  1909. output_loc_operands_raw (dw_loc_descr_ref loc)
  1910. {
  1911. dw_val_ref val1 = &loc->dw_loc_oprnd1;
  1912. dw_val_ref val2 = &loc->dw_loc_oprnd2;
  1913. switch (loc->dw_loc_opc)
  1914. {
  1915. case DW_OP_addr:
  1916. case DW_OP_GNU_addr_index:
  1917. case DW_OP_GNU_const_index:
  1918. case DW_OP_implicit_value:
  1919. /* We cannot output addresses in .cfi_escape, only bytes. */
  1920. gcc_unreachable ();
  1921. case DW_OP_const1u:
  1922. case DW_OP_const1s:
  1923. case DW_OP_pick:
  1924. case DW_OP_deref_size:
  1925. case DW_OP_xderef_size:
  1926. fputc (',', asm_out_file);
  1927. dw2_asm_output_data_raw (1, val1->v.val_int);
  1928. break;
  1929. case DW_OP_const2u:
  1930. case DW_OP_const2s:
  1931. fputc (',', asm_out_file);
  1932. dw2_asm_output_data_raw (2, val1->v.val_int);
  1933. break;
  1934. case DW_OP_const4u:
  1935. case DW_OP_const4s:
  1936. fputc (',', asm_out_file);
  1937. dw2_asm_output_data_raw (4, val1->v.val_int);
  1938. break;
  1939. case DW_OP_const8u:
  1940. case DW_OP_const8s:
  1941. gcc_assert (HOST_BITS_PER_WIDE_INT >= 64);
  1942. fputc (',', asm_out_file);
  1943. dw2_asm_output_data_raw (8, val1->v.val_int);
  1944. break;
  1945. case DW_OP_skip:
  1946. case DW_OP_bra:
  1947. {
  1948. int offset;
  1949. gcc_assert (val1->val_class == dw_val_class_loc);
  1950. offset = val1->v.val_loc->dw_loc_addr - (loc->dw_loc_addr + 3);
  1951. fputc (',', asm_out_file);
  1952. dw2_asm_output_data_raw (2, offset);
  1953. }
  1954. break;
  1955. case DW_OP_regx:
  1956. {
  1957. unsigned r = DWARF2_FRAME_REG_OUT (val1->v.val_unsigned, 1);
  1958. gcc_assert (size_of_uleb128 (r)
  1959. == size_of_uleb128 (val1->v.val_unsigned));
  1960. fputc (',', asm_out_file);
  1961. dw2_asm_output_data_uleb128_raw (r);
  1962. }
  1963. break;
  1964. case DW_OP_constu:
  1965. case DW_OP_plus_uconst:
  1966. case DW_OP_piece:
  1967. fputc (',', asm_out_file);
  1968. dw2_asm_output_data_uleb128_raw (val1->v.val_unsigned);
  1969. break;
  1970. case DW_OP_bit_piece:
  1971. fputc (',', asm_out_file);
  1972. dw2_asm_output_data_uleb128_raw (val1->v.val_unsigned);
  1973. dw2_asm_output_data_uleb128_raw (val2->v.val_unsigned);
  1974. break;
  1975. case DW_OP_consts:
  1976. case DW_OP_breg0:
  1977. case DW_OP_breg1:
  1978. case DW_OP_breg2:
  1979. case DW_OP_breg3:
  1980. case DW_OP_breg4:
  1981. case DW_OP_breg5:
  1982. case DW_OP_breg6:
  1983. case DW_OP_breg7:
  1984. case DW_OP_breg8:
  1985. case DW_OP_breg9:
  1986. case DW_OP_breg10:
  1987. case DW_OP_breg11:
  1988. case DW_OP_breg12:
  1989. case DW_OP_breg13:
  1990. case DW_OP_breg14:
  1991. case DW_OP_breg15:
  1992. case DW_OP_breg16:
  1993. case DW_OP_breg17:
  1994. case DW_OP_breg18:
  1995. case DW_OP_breg19:
  1996. case DW_OP_breg20:
  1997. case DW_OP_breg21:
  1998. case DW_OP_breg22:
  1999. case DW_OP_breg23:
  2000. case DW_OP_breg24:
  2001. case DW_OP_breg25:
  2002. case DW_OP_breg26:
  2003. case DW_OP_breg27:
  2004. case DW_OP_breg28:
  2005. case DW_OP_breg29:
  2006. case DW_OP_breg30:
  2007. case DW_OP_breg31:
  2008. case DW_OP_fbreg:
  2009. fputc (',', asm_out_file);
  2010. dw2_asm_output_data_sleb128_raw (val1->v.val_int);
  2011. break;
  2012. case DW_OP_bregx:
  2013. {
  2014. unsigned r = DWARF2_FRAME_REG_OUT (val1->v.val_unsigned, 1);
  2015. gcc_assert (size_of_uleb128 (r)
  2016. == size_of_uleb128 (val1->v.val_unsigned));
  2017. fputc (',', asm_out_file);
  2018. dw2_asm_output_data_uleb128_raw (r);
  2019. fputc (',', asm_out_file);
  2020. dw2_asm_output_data_sleb128_raw (val2->v.val_int);
  2021. }
  2022. break;
  2023. case DW_OP_GNU_implicit_pointer:
  2024. case DW_OP_GNU_entry_value:
  2025. case DW_OP_GNU_const_type:
  2026. case DW_OP_GNU_regval_type:
  2027. case DW_OP_GNU_deref_type:
  2028. case DW_OP_GNU_convert:
  2029. case DW_OP_GNU_reinterpret:
  2030. case DW_OP_GNU_parameter_ref:
  2031. gcc_unreachable ();
  2032. break;
  2033. default:
  2034. /* Other codes have no operands. */
  2035. break;
  2036. }
  2037. }
  2038. void
  2039. output_loc_sequence_raw (dw_loc_descr_ref loc)
  2040. {
  2041. while (1)
  2042. {
  2043. enum dwarf_location_atom opc = loc->dw_loc_opc;
  2044. /* Output the opcode. */
  2045. if (opc >= DW_OP_breg0 && opc <= DW_OP_breg31)
  2046. {
  2047. unsigned r = (opc - DW_OP_breg0);
  2048. r = DWARF2_FRAME_REG_OUT (r, 1);
  2049. gcc_assert (r <= 31);
  2050. opc = (enum dwarf_location_atom) (DW_OP_breg0 + r);
  2051. }
  2052. else if (opc >= DW_OP_reg0 && opc <= DW_OP_reg31)
  2053. {
  2054. unsigned r = (opc - DW_OP_reg0);
  2055. r = DWARF2_FRAME_REG_OUT (r, 1);
  2056. gcc_assert (r <= 31);
  2057. opc = (enum dwarf_location_atom) (DW_OP_reg0 + r);
  2058. }
  2059. /* Output the opcode. */
  2060. fprintf (asm_out_file, "%#x", opc);
  2061. output_loc_operands_raw (loc);
  2062. if (!loc->dw_loc_next)
  2063. break;
  2064. loc = loc->dw_loc_next;
  2065. fputc (',', asm_out_file);
  2066. }
  2067. }
  2068. /* This function builds a dwarf location descriptor sequence from a
  2069. dw_cfa_location, adding the given OFFSET to the result of the
  2070. expression. */
  2071. struct dw_loc_descr_node *
  2072. build_cfa_loc (dw_cfa_location *cfa, HOST_WIDE_INT offset)
  2073. {
  2074. struct dw_loc_descr_node *head, *tmp;
  2075. offset += cfa->offset;
  2076. if (cfa->indirect)
  2077. {
  2078. head = new_reg_loc_descr (cfa->reg, cfa->base_offset);
  2079. head->dw_loc_oprnd1.val_class = dw_val_class_const;
  2080. head->dw_loc_oprnd1.val_entry = NULL;
  2081. tmp = new_loc_descr (DW_OP_deref, 0, 0);
  2082. add_loc_descr (&head, tmp);
  2083. if (offset != 0)
  2084. {
  2085. tmp = new_loc_descr (DW_OP_plus_uconst, offset, 0);
  2086. add_loc_descr (&head, tmp);
  2087. }
  2088. }
  2089. else
  2090. head = new_reg_loc_descr (cfa->reg, offset);
  2091. return head;
  2092. }
  2093. /* This function builds a dwarf location descriptor sequence for
  2094. the address at OFFSET from the CFA when stack is aligned to
  2095. ALIGNMENT byte. */
  2096. struct dw_loc_descr_node *
  2097. build_cfa_aligned_loc (dw_cfa_location *cfa,
  2098. HOST_WIDE_INT offset, HOST_WIDE_INT alignment)
  2099. {
  2100. struct dw_loc_descr_node *head;
  2101. unsigned int dwarf_fp
  2102. = DWARF_FRAME_REGNUM (HARD_FRAME_POINTER_REGNUM);
  2103. /* When CFA is defined as FP+OFFSET, emulate stack alignment. */
  2104. if (cfa->reg == HARD_FRAME_POINTER_REGNUM && cfa->indirect == 0)
  2105. {
  2106. head = new_reg_loc_descr (dwarf_fp, 0);
  2107. add_loc_descr (&head, int_loc_descriptor (alignment));
  2108. add_loc_descr (&head, new_loc_descr (DW_OP_and, 0, 0));
  2109. loc_descr_plus_const (&head, offset);
  2110. }
  2111. else
  2112. head = new_reg_loc_descr (dwarf_fp, offset);
  2113. return head;
  2114. }
  2115. /* And now, the support for symbolic debugging information. */
  2116. /* .debug_str support. */
  2117. static void dwarf2out_init (const char *);
  2118. static void dwarf2out_finish (const char *);
  2119. static void dwarf2out_assembly_start (void);
  2120. static void dwarf2out_define (unsigned int, const char *);
  2121. static void dwarf2out_undef (unsigned int, const char *);
  2122. static void dwarf2out_start_source_file (unsigned, const char *);
  2123. static void dwarf2out_end_source_file (unsigned);
  2124. static void dwarf2out_function_decl (tree);
  2125. static void dwarf2out_begin_block (unsigned, unsigned);
  2126. static void dwarf2out_end_block (unsigned, unsigned);
  2127. static bool dwarf2out_ignore_block (const_tree);
  2128. static void dwarf2out_global_decl (tree);
  2129. static void dwarf2out_type_decl (tree, int);
  2130. static void dwarf2out_imported_module_or_decl (tree, tree, tree, bool);
  2131. static void dwarf2out_imported_module_or_decl_1 (tree, tree, tree,
  2132. dw_die_ref);
  2133. static void dwarf2out_abstract_function (tree);
  2134. static void dwarf2out_var_location (rtx_insn *);
  2135. static void dwarf2out_begin_function (tree);
  2136. static void dwarf2out_end_function (unsigned int);
  2137. static void dwarf2out_register_main_translation_unit (tree unit);
  2138. static void dwarf2out_set_name (tree, tree);
  2139. /* The debug hooks structure. */
  2140. const struct gcc_debug_hooks dwarf2_debug_hooks =
  2141. {
  2142. dwarf2out_init,
  2143. dwarf2out_finish,
  2144. dwarf2out_assembly_start,
  2145. dwarf2out_define,
  2146. dwarf2out_undef,
  2147. dwarf2out_start_source_file,
  2148. dwarf2out_end_source_file,
  2149. dwarf2out_begin_block,
  2150. dwarf2out_end_block,
  2151. dwarf2out_ignore_block,
  2152. dwarf2out_source_line,
  2153. dwarf2out_begin_prologue,
  2154. #if VMS_DEBUGGING_INFO
  2155. dwarf2out_vms_end_prologue,
  2156. dwarf2out_vms_begin_epilogue,
  2157. #else
  2158. debug_nothing_int_charstar,
  2159. debug_nothing_int_charstar,
  2160. #endif
  2161. dwarf2out_end_epilogue,
  2162. dwarf2out_begin_function,
  2163. dwarf2out_end_function, /* end_function */
  2164. dwarf2out_register_main_translation_unit,
  2165. dwarf2out_function_decl, /* function_decl */
  2166. dwarf2out_global_decl,
  2167. dwarf2out_type_decl, /* type_decl */
  2168. dwarf2out_imported_module_or_decl,
  2169. debug_nothing_tree, /* deferred_inline_function */
  2170. /* The DWARF 2 backend tries to reduce debugging bloat by not
  2171. emitting the abstract description of inline functions until
  2172. something tries to reference them. */
  2173. dwarf2out_abstract_function, /* outlining_inline_function */
  2174. debug_nothing_rtx_code_label, /* label */
  2175. debug_nothing_int, /* handle_pch */
  2176. dwarf2out_var_location,
  2177. dwarf2out_switch_text_section,
  2178. dwarf2out_set_name,
  2179. 1, /* start_end_main_source_file */
  2180. TYPE_SYMTAB_IS_DIE /* tree_type_symtab_field */
  2181. };
  2182. /* NOTE: In the comments in this file, many references are made to
  2183. "Debugging Information Entries". This term is abbreviated as `DIE'
  2184. throughout the remainder of this file. */
  2185. /* An internal representation of the DWARF output is built, and then
  2186. walked to generate the DWARF debugging info. The walk of the internal
  2187. representation is done after the entire program has been compiled.
  2188. The types below are used to describe the internal representation. */
  2189. /* Whether to put type DIEs into their own section .debug_types instead
  2190. of making them part of the .debug_info section. Only supported for
  2191. Dwarf V4 or higher and the user didn't disable them through
  2192. -fno-debug-types-section. It is more efficient to put them in a
  2193. separate comdat sections since the linker will then be able to
  2194. remove duplicates. But not all tools support .debug_types sections
  2195. yet. */
  2196. #define use_debug_types (dwarf_version >= 4 && flag_debug_types_section)
  2197. /* Various DIE's use offsets relative to the beginning of the
  2198. .debug_info section to refer to each other. */
  2199. typedef long int dw_offset;
  2200. /* Define typedefs here to avoid circular dependencies. */
  2201. typedef struct dw_attr_struct *dw_attr_ref;
  2202. typedef struct dw_line_info_struct *dw_line_info_ref;
  2203. typedef struct pubname_struct *pubname_ref;
  2204. typedef struct dw_ranges_struct *dw_ranges_ref;
  2205. typedef struct dw_ranges_by_label_struct *dw_ranges_by_label_ref;
  2206. typedef struct comdat_type_struct *comdat_type_node_ref;
  2207. /* The entries in the line_info table more-or-less mirror the opcodes
  2208. that are used in the real dwarf line table. Arrays of these entries
  2209. are collected per section when DWARF2_ASM_LINE_DEBUG_INFO is not
  2210. supported. */
  2211. enum dw_line_info_opcode {
  2212. /* Emit DW_LNE_set_address; the operand is the label index. */
  2213. LI_set_address,
  2214. /* Emit a row to the matrix with the given line. This may be done
  2215. via any combination of DW_LNS_copy, DW_LNS_advance_line, and
  2216. special opcodes. */
  2217. LI_set_line,
  2218. /* Emit a DW_LNS_set_file. */
  2219. LI_set_file,
  2220. /* Emit a DW_LNS_set_column. */
  2221. LI_set_column,
  2222. /* Emit a DW_LNS_negate_stmt; the operand is ignored. */
  2223. LI_negate_stmt,
  2224. /* Emit a DW_LNS_set_prologue_end/epilogue_begin; the operand is ignored. */
  2225. LI_set_prologue_end,
  2226. LI_set_epilogue_begin,
  2227. /* Emit a DW_LNE_set_discriminator. */
  2228. LI_set_discriminator
  2229. };
  2230. typedef struct GTY(()) dw_line_info_struct {
  2231. enum dw_line_info_opcode opcode;
  2232. unsigned int val;
  2233. } dw_line_info_entry;
  2234. typedef struct GTY(()) dw_line_info_table_struct {
  2235. /* The label that marks the end of this section. */
  2236. const char *end_label;
  2237. /* The values for the last row of the matrix, as collected in the table.
  2238. These are used to minimize the changes to the next row. */
  2239. unsigned int file_num;
  2240. unsigned int line_num;
  2241. unsigned int column_num;
  2242. int discrim_num;
  2243. bool is_stmt;
  2244. bool in_use;
  2245. vec<dw_line_info_entry, va_gc> *entries;
  2246. } dw_line_info_table;
  2247. typedef dw_line_info_table *dw_line_info_table_p;
  2248. /* Each DIE attribute has a field specifying the attribute kind,
  2249. a link to the next attribute in the chain, and an attribute value.
  2250. Attributes are typically linked below the DIE they modify. */
  2251. typedef struct GTY(()) dw_attr_struct {
  2252. enum dwarf_attribute dw_attr;
  2253. dw_val_node dw_attr_val;
  2254. }
  2255. dw_attr_node;
  2256. /* The Debugging Information Entry (DIE) structure. DIEs form a tree.
  2257. The children of each node form a circular list linked by
  2258. die_sib. die_child points to the node *before* the "first" child node. */
  2259. typedef struct GTY((chain_circular ("%h.die_sib"), for_user)) die_struct {
  2260. union die_symbol_or_type_node
  2261. {
  2262. const char * GTY ((tag ("0"))) die_symbol;
  2263. comdat_type_node_ref GTY ((tag ("1"))) die_type_node;
  2264. }
  2265. GTY ((desc ("%0.comdat_type_p"))) die_id;
  2266. vec<dw_attr_node, va_gc> *die_attr;
  2267. dw_die_ref die_parent;
  2268. dw_die_ref die_child;
  2269. dw_die_ref die_sib;
  2270. dw_die_ref die_definition; /* ref from a specification to its definition */
  2271. dw_offset die_offset;
  2272. unsigned long die_abbrev;
  2273. int die_mark;
  2274. unsigned int decl_id;
  2275. enum dwarf_tag die_tag;
  2276. /* Die is used and must not be pruned as unused. */
  2277. BOOL_BITFIELD die_perennial_p : 1;
  2278. BOOL_BITFIELD comdat_type_p : 1; /* DIE has a type signature */
  2279. /* Lots of spare bits. */
  2280. }
  2281. die_node;
  2282. /* Evaluate 'expr' while 'c' is set to each child of DIE in order. */
  2283. #define FOR_EACH_CHILD(die, c, expr) do { \
  2284. c = die->die_child; \
  2285. if (c) do { \
  2286. c = c->die_sib; \
  2287. expr; \
  2288. } while (c != die->die_child); \
  2289. } while (0)
  2290. /* The pubname structure */
  2291. typedef struct GTY(()) pubname_struct {
  2292. dw_die_ref die;
  2293. const char *name;
  2294. }
  2295. pubname_entry;
  2296. struct GTY(()) dw_ranges_struct {
  2297. /* If this is positive, it's a block number, otherwise it's a
  2298. bitwise-negated index into dw_ranges_by_label. */
  2299. int num;
  2300. };
  2301. /* A structure to hold a macinfo entry. */
  2302. typedef struct GTY(()) macinfo_struct {
  2303. unsigned char code;
  2304. unsigned HOST_WIDE_INT lineno;
  2305. const char *info;
  2306. }
  2307. macinfo_entry;
  2308. struct GTY(()) dw_ranges_by_label_struct {
  2309. const char *begin;
  2310. const char *end;
  2311. };
  2312. /* The comdat type node structure. */
  2313. typedef struct GTY(()) comdat_type_struct
  2314. {
  2315. dw_die_ref root_die;
  2316. dw_die_ref type_die;
  2317. dw_die_ref skeleton_die;
  2318. char signature[DWARF_TYPE_SIGNATURE_SIZE];
  2319. struct comdat_type_struct *next;
  2320. }
  2321. comdat_type_node;
  2322. /* The limbo die list structure. */
  2323. typedef struct GTY(()) limbo_die_struct {
  2324. dw_die_ref die;
  2325. tree created_for;
  2326. struct limbo_die_struct *next;
  2327. }
  2328. limbo_die_node;
  2329. typedef struct skeleton_chain_struct
  2330. {
  2331. dw_die_ref old_die;
  2332. dw_die_ref new_die;
  2333. struct skeleton_chain_struct *parent;
  2334. }
  2335. skeleton_chain_node;
  2336. /* Define a macro which returns nonzero for a TYPE_DECL which was
  2337. implicitly generated for a type.
  2338. Note that, unlike the C front-end (which generates a NULL named
  2339. TYPE_DECL node for each complete tagged type, each array type,
  2340. and each function type node created) the C++ front-end generates
  2341. a _named_ TYPE_DECL node for each tagged type node created.
  2342. These TYPE_DECLs have DECL_ARTIFICIAL set, so we know not to
  2343. generate a DW_TAG_typedef DIE for them. Likewise with the Ada
  2344. front-end, but for each type, tagged or not. */
  2345. #define TYPE_DECL_IS_STUB(decl) \
  2346. (DECL_NAME (decl) == NULL_TREE \
  2347. || (DECL_ARTIFICIAL (decl) \
  2348. && ((decl == TYPE_STUB_DECL (TREE_TYPE (decl))) \
  2349. /* This is necessary for stub decls that \
  2350. appear in nested inline functions. */ \
  2351. || (DECL_ABSTRACT_ORIGIN (decl) != NULL_TREE \
  2352. && (decl_ultimate_origin (decl) \
  2353. == TYPE_STUB_DECL (TREE_TYPE (decl)))))))
  2354. /* Information concerning the compilation unit's programming
  2355. language, and compiler version. */
  2356. /* Fixed size portion of the DWARF compilation unit header. */
  2357. #define DWARF_COMPILE_UNIT_HEADER_SIZE \
  2358. (DWARF_INITIAL_LENGTH_SIZE + DWARF_OFFSET_SIZE + 3)
  2359. /* Fixed size portion of the DWARF comdat type unit header. */
  2360. #define DWARF_COMDAT_TYPE_UNIT_HEADER_SIZE \
  2361. (DWARF_COMPILE_UNIT_HEADER_SIZE + DWARF_TYPE_SIGNATURE_SIZE \
  2362. + DWARF_OFFSET_SIZE)
  2363. /* Fixed size portion of public names info. */
  2364. #define DWARF_PUBNAMES_HEADER_SIZE (2 * DWARF_OFFSET_SIZE + 2)
  2365. /* Fixed size portion of the address range info. */
  2366. #define DWARF_ARANGES_HEADER_SIZE \
  2367. (DWARF_ROUND (DWARF_INITIAL_LENGTH_SIZE + DWARF_OFFSET_SIZE + 4, \
  2368. DWARF2_ADDR_SIZE * 2) \
  2369. - DWARF_INITIAL_LENGTH_SIZE)
  2370. /* Size of padding portion in the address range info. It must be
  2371. aligned to twice the pointer size. */
  2372. #define DWARF_ARANGES_PAD_SIZE \
  2373. (DWARF_ROUND (DWARF_INITIAL_LENGTH_SIZE + DWARF_OFFSET_SIZE + 4, \
  2374. DWARF2_ADDR_SIZE * 2) \
  2375. - (DWARF_INITIAL_LENGTH_SIZE + DWARF_OFFSET_SIZE + 4))
  2376. /* Use assembler line directives if available. */
  2377. #ifndef DWARF2_ASM_LINE_DEBUG_INFO
  2378. #ifdef HAVE_AS_DWARF2_DEBUG_LINE
  2379. #define DWARF2_ASM_LINE_DEBUG_INFO 1
  2380. #else
  2381. #define DWARF2_ASM_LINE_DEBUG_INFO 0
  2382. #endif
  2383. #endif
  2384. /* Minimum line offset in a special line info. opcode.
  2385. This value was chosen to give a reasonable range of values. */
  2386. #define DWARF_LINE_BASE -10
  2387. /* First special line opcode - leave room for the standard opcodes. */
  2388. #define DWARF_LINE_OPCODE_BASE ((int)DW_LNS_set_isa + 1)
  2389. /* Range of line offsets in a special line info. opcode. */
  2390. #define DWARF_LINE_RANGE (254-DWARF_LINE_OPCODE_BASE+1)
  2391. /* Flag that indicates the initial value of the is_stmt_start flag.
  2392. In the present implementation, we do not mark any lines as
  2393. the beginning of a source statement, because that information
  2394. is not made available by the GCC front-end. */
  2395. #define DWARF_LINE_DEFAULT_IS_STMT_START 1
  2396. /* Maximum number of operations per instruction bundle. */
  2397. #ifndef DWARF_LINE_DEFAULT_MAX_OPS_PER_INSN
  2398. #define DWARF_LINE_DEFAULT_MAX_OPS_PER_INSN 1
  2399. #endif
  2400. /* This location is used by calc_die_sizes() to keep track
  2401. the offset of each DIE within the .debug_info section. */
  2402. static unsigned long next_die_offset;
  2403. /* Record the root of the DIE's built for the current compilation unit. */
  2404. static GTY(()) dw_die_ref single_comp_unit_die;
  2405. /* A list of type DIEs that have been separated into comdat sections. */
  2406. static GTY(()) comdat_type_node *comdat_type_list;
  2407. /* A list of DIEs with a NULL parent waiting to be relocated. */
  2408. static GTY(()) limbo_die_node *limbo_die_list;
  2409. /* A list of DIEs for which we may have to generate
  2410. DW_AT_{,MIPS_}linkage_name once their DECL_ASSEMBLER_NAMEs are set. */
  2411. static GTY(()) limbo_die_node *deferred_asm_name;
  2412. struct dwarf_file_hasher : ggc_hasher<dwarf_file_data *>
  2413. {
  2414. typedef const char *compare_type;
  2415. static hashval_t hash (dwarf_file_data *);
  2416. static bool equal (dwarf_file_data *, const char *);
  2417. };
  2418. /* Filenames referenced by this compilation unit. */
  2419. static GTY(()) hash_table<dwarf_file_hasher> *file_table;
  2420. struct decl_die_hasher : ggc_hasher<die_node *>
  2421. {
  2422. typedef tree compare_type;
  2423. static hashval_t hash (die_node *);
  2424. static bool equal (die_node *, tree);
  2425. };
  2426. /* A hash table of references to DIE's that describe declarations.
  2427. The key is a DECL_UID() which is a unique number identifying each decl. */
  2428. static GTY (()) hash_table<decl_die_hasher> *decl_die_table;
  2429. struct block_die_hasher : ggc_hasher<die_struct *>
  2430. {
  2431. static hashval_t hash (die_struct *);
  2432. static bool equal (die_struct *, die_struct *);
  2433. };
  2434. /* A hash table of references to DIE's that describe COMMON blocks.
  2435. The key is DECL_UID() ^ die_parent. */
  2436. static GTY (()) hash_table<block_die_hasher> *common_block_die_table;
  2437. typedef struct GTY(()) die_arg_entry_struct {
  2438. dw_die_ref die;
  2439. tree arg;
  2440. } die_arg_entry;
  2441. /* Node of the variable location list. */
  2442. struct GTY ((chain_next ("%h.next"))) var_loc_node {
  2443. /* Either NOTE_INSN_VAR_LOCATION, or, for SRA optimized variables,
  2444. EXPR_LIST chain. For small bitsizes, bitsize is encoded
  2445. in mode of the EXPR_LIST node and first EXPR_LIST operand
  2446. is either NOTE_INSN_VAR_LOCATION for a piece with a known
  2447. location or NULL for padding. For larger bitsizes,
  2448. mode is 0 and first operand is a CONCAT with bitsize
  2449. as first CONCAT operand and NOTE_INSN_VAR_LOCATION resp.
  2450. NULL as second operand. */
  2451. rtx GTY (()) loc;
  2452. const char * GTY (()) label;
  2453. struct var_loc_node * GTY (()) next;
  2454. };
  2455. /* Variable location list. */
  2456. struct GTY ((for_user)) var_loc_list_def {
  2457. struct var_loc_node * GTY (()) first;
  2458. /* Pointer to the last but one or last element of the
  2459. chained list. If the list is empty, both first and
  2460. last are NULL, if the list contains just one node
  2461. or the last node certainly is not redundant, it points
  2462. to the last node, otherwise points to the last but one.
  2463. Do not mark it for GC because it is marked through the chain. */
  2464. struct var_loc_node * GTY ((skip ("%h"))) last;
  2465. /* Pointer to the last element before section switch,
  2466. if NULL, either sections weren't switched or first
  2467. is after section switch. */
  2468. struct var_loc_node * GTY ((skip ("%h"))) last_before_switch;
  2469. /* DECL_UID of the variable decl. */
  2470. unsigned int decl_id;
  2471. };
  2472. typedef struct var_loc_list_def var_loc_list;
  2473. /* Call argument location list. */
  2474. struct GTY ((chain_next ("%h.next"))) call_arg_loc_node {
  2475. rtx GTY (()) call_arg_loc_note;
  2476. const char * GTY (()) label;
  2477. tree GTY (()) block;
  2478. bool tail_call_p;
  2479. rtx GTY (()) symbol_ref;
  2480. struct call_arg_loc_node * GTY (()) next;
  2481. };
  2482. struct decl_loc_hasher : ggc_hasher<var_loc_list *>
  2483. {
  2484. typedef const_tree compare_type;
  2485. static hashval_t hash (var_loc_list *);
  2486. static bool equal (var_loc_list *, const_tree);
  2487. };
  2488. /* Table of decl location linked lists. */
  2489. static GTY (()) hash_table<decl_loc_hasher> *decl_loc_table;
  2490. /* Head and tail of call_arg_loc chain. */
  2491. static GTY (()) struct call_arg_loc_node *call_arg_locations;
  2492. static struct call_arg_loc_node *call_arg_loc_last;
  2493. /* Number of call sites in the current function. */
  2494. static int call_site_count = -1;
  2495. /* Number of tail call sites in the current function. */
  2496. static int tail_call_site_count = -1;
  2497. /* Vector mapping block numbers to DW_TAG_{lexical_block,inlined_subroutine}
  2498. DIEs. */
  2499. static vec<dw_die_ref> block_map;
  2500. /* A cached location list. */
  2501. struct GTY ((for_user)) cached_dw_loc_list_def {
  2502. /* The DECL_UID of the decl that this entry describes. */
  2503. unsigned int decl_id;
  2504. /* The cached location list. */
  2505. dw_loc_list_ref loc_list;
  2506. };
  2507. typedef struct cached_dw_loc_list_def cached_dw_loc_list;
  2508. struct dw_loc_list_hasher : ggc_hasher<cached_dw_loc_list *>
  2509. {
  2510. typedef const_tree compare_type;
  2511. static hashval_t hash (cached_dw_loc_list *);
  2512. static bool equal (cached_dw_loc_list *, const_tree);
  2513. };
  2514. /* Table of cached location lists. */
  2515. static GTY (()) hash_table<dw_loc_list_hasher> *cached_dw_loc_list_table;
  2516. /* A pointer to the base of a list of references to DIE's that
  2517. are uniquely identified by their tag, presence/absence of
  2518. children DIE's, and list of attribute/value pairs. */
  2519. static GTY((length ("abbrev_die_table_allocated")))
  2520. dw_die_ref *abbrev_die_table;
  2521. /* Number of elements currently allocated for abbrev_die_table. */
  2522. static GTY(()) unsigned abbrev_die_table_allocated;
  2523. /* Number of elements in type_die_table currently in use. */
  2524. static GTY(()) unsigned abbrev_die_table_in_use;
  2525. /* Size (in elements) of increments by which we may expand the
  2526. abbrev_die_table. */
  2527. #define ABBREV_DIE_TABLE_INCREMENT 256
  2528. /* A global counter for generating labels for line number data. */
  2529. static unsigned int line_info_label_num;
  2530. /* The current table to which we should emit line number information
  2531. for the current function. This will be set up at the beginning of
  2532. assembly for the function. */
  2533. static dw_line_info_table *cur_line_info_table;
  2534. /* The two default tables of line number info. */
  2535. static GTY(()) dw_line_info_table *text_section_line_info;
  2536. static GTY(()) dw_line_info_table *cold_text_section_line_info;
  2537. /* The set of all non-default tables of line number info. */
  2538. static GTY(()) vec<dw_line_info_table_p, va_gc> *separate_line_info;
  2539. /* A flag to tell pubnames/types export if there is an info section to
  2540. refer to. */
  2541. static bool info_section_emitted;
  2542. /* A pointer to the base of a table that contains a list of publicly
  2543. accessible names. */
  2544. static GTY (()) vec<pubname_entry, va_gc> *pubname_table;
  2545. /* A pointer to the base of a table that contains a list of publicly
  2546. accessible types. */
  2547. static GTY (()) vec<pubname_entry, va_gc> *pubtype_table;
  2548. /* A pointer to the base of a table that contains a list of macro
  2549. defines/undefines (and file start/end markers). */
  2550. static GTY (()) vec<macinfo_entry, va_gc> *macinfo_table;
  2551. /* True if .debug_macinfo or .debug_macros section is going to be
  2552. emitted. */
  2553. #define have_macinfo \
  2554. (debug_info_level >= DINFO_LEVEL_VERBOSE \
  2555. && !macinfo_table->is_empty ())
  2556. /* Array of dies for which we should generate .debug_ranges info. */
  2557. static GTY ((length ("ranges_table_allocated"))) dw_ranges_ref ranges_table;
  2558. /* Number of elements currently allocated for ranges_table. */
  2559. static GTY(()) unsigned ranges_table_allocated;
  2560. /* Number of elements in ranges_table currently in use. */
  2561. static GTY(()) unsigned ranges_table_in_use;
  2562. /* Array of pairs of labels referenced in ranges_table. */
  2563. static GTY ((length ("ranges_by_label_allocated")))
  2564. dw_ranges_by_label_ref ranges_by_label;
  2565. /* Number of elements currently allocated for ranges_by_label. */
  2566. static GTY(()) unsigned ranges_by_label_allocated;
  2567. /* Number of elements in ranges_by_label currently in use. */
  2568. static GTY(()) unsigned ranges_by_label_in_use;
  2569. /* Size (in elements) of increments by which we may expand the
  2570. ranges_table. */
  2571. #define RANGES_TABLE_INCREMENT 64
  2572. /* Whether we have location lists that need outputting */
  2573. static GTY(()) bool have_location_lists;
  2574. /* Unique label counter. */
  2575. static GTY(()) unsigned int loclabel_num;
  2576. /* Unique label counter for point-of-call tables. */
  2577. static GTY(()) unsigned int poc_label_num;
  2578. /* The last file entry emitted by maybe_emit_file(). */
  2579. static GTY(()) struct dwarf_file_data * last_emitted_file;
  2580. /* Number of internal labels generated by gen_internal_sym(). */
  2581. static GTY(()) int label_num;
  2582. /* Cached result of previous call to lookup_filename. */
  2583. static GTY(()) struct dwarf_file_data * file_table_last_lookup;
  2584. static GTY(()) vec<die_arg_entry, va_gc> *tmpl_value_parm_die_table;
  2585. /* Instances of generic types for which we need to generate debug
  2586. info that describe their generic parameters and arguments. That
  2587. generation needs to happen once all types are properly laid out so
  2588. we do it at the end of compilation. */
  2589. static GTY(()) vec<tree, va_gc> *generic_type_instances;
  2590. /* Offset from the "steady-state frame pointer" to the frame base,
  2591. within the current function. */
  2592. static HOST_WIDE_INT frame_pointer_fb_offset;
  2593. static bool frame_pointer_fb_offset_valid;
  2594. static vec<dw_die_ref> base_types;
  2595. /* Flags to represent a set of attribute classes for attributes that represent
  2596. a scalar value (bounds, pointers, ...). */
  2597. enum dw_scalar_form
  2598. {
  2599. dw_scalar_form_constant = 0x01,
  2600. dw_scalar_form_exprloc = 0x02,
  2601. dw_scalar_form_reference = 0x04
  2602. };
  2603. /* Forward declarations for functions defined in this file. */
  2604. static int is_pseudo_reg (const_rtx);
  2605. static tree type_main_variant (tree);
  2606. static int is_tagged_type (const_tree);
  2607. static const char *dwarf_tag_name (unsigned);
  2608. static const char *dwarf_attr_name (unsigned);
  2609. static const char *dwarf_form_name (unsigned);
  2610. static tree decl_ultimate_origin (const_tree);
  2611. static tree decl_class_context (tree);
  2612. static void add_dwarf_attr (dw_die_ref, dw_attr_ref);
  2613. static inline enum dw_val_class AT_class (dw_attr_ref);
  2614. static inline unsigned int AT_index (dw_attr_ref);
  2615. static void add_AT_flag (dw_die_ref, enum dwarf_attribute, unsigned);
  2616. static inline unsigned AT_flag (dw_attr_ref);
  2617. static void add_AT_int (dw_die_ref, enum dwarf_attribute, HOST_WIDE_INT);
  2618. static inline HOST_WIDE_INT AT_int (dw_attr_ref);
  2619. static void add_AT_unsigned (dw_die_ref, enum dwarf_attribute, unsigned HOST_WIDE_INT);
  2620. static inline unsigned HOST_WIDE_INT AT_unsigned (dw_attr_ref);
  2621. static void add_AT_double (dw_die_ref, enum dwarf_attribute,
  2622. HOST_WIDE_INT, unsigned HOST_WIDE_INT);
  2623. static inline void add_AT_vec (dw_die_ref, enum dwarf_attribute, unsigned int,
  2624. unsigned int, unsigned char *);
  2625. static void add_AT_data8 (dw_die_ref, enum dwarf_attribute, unsigned char *);
  2626. static void add_AT_string (dw_die_ref, enum dwarf_attribute, const char *);
  2627. static inline const char *AT_string (dw_attr_ref);
  2628. static enum dwarf_form AT_string_form (dw_attr_ref);
  2629. static void add_AT_die_ref (dw_die_ref, enum dwarf_attribute, dw_die_ref);
  2630. static void add_AT_specification (dw_die_ref, dw_die_ref);
  2631. static inline dw_die_ref AT_ref (dw_attr_ref);
  2632. static inline int AT_ref_external (dw_attr_ref);
  2633. static inline void set_AT_ref_external (dw_attr_ref, int);
  2634. static void add_AT_fde_ref (dw_die_ref, enum dwarf_attribute, unsigned);
  2635. static void add_AT_loc (dw_die_ref, enum dwarf_attribute, dw_loc_descr_ref);
  2636. static inline dw_loc_descr_ref AT_loc (dw_attr_ref);
  2637. static void add_AT_loc_list (dw_die_ref, enum dwarf_attribute,
  2638. dw_loc_list_ref);
  2639. static inline dw_loc_list_ref AT_loc_list (dw_attr_ref);
  2640. static addr_table_entry *add_addr_table_entry (void *, enum ate_kind);
  2641. static void remove_addr_table_entry (addr_table_entry *);
  2642. static void add_AT_addr (dw_die_ref, enum dwarf_attribute, rtx, bool);
  2643. static inline rtx AT_addr (dw_attr_ref);
  2644. static void add_AT_lbl_id (dw_die_ref, enum dwarf_attribute, const char *);
  2645. static void add_AT_lineptr (dw_die_ref, enum dwarf_attribute, const char *);
  2646. static void add_AT_macptr (dw_die_ref, enum dwarf_attribute, const char *);
  2647. static void add_AT_offset (dw_die_ref, enum dwarf_attribute,
  2648. unsigned HOST_WIDE_INT);
  2649. static void add_AT_range_list (dw_die_ref, enum dwarf_attribute,
  2650. unsigned long, bool);
  2651. static inline const char *AT_lbl (dw_attr_ref);
  2652. static dw_attr_ref get_AT (dw_die_ref, enum dwarf_attribute);
  2653. static const char *get_AT_low_pc (dw_die_ref);
  2654. static const char *get_AT_hi_pc (dw_die_ref);
  2655. static const char *get_AT_string (dw_die_ref, enum dwarf_attribute);
  2656. static int get_AT_flag (dw_die_ref, enum dwarf_attribute);
  2657. static unsigned get_AT_unsigned (dw_die_ref, enum dwarf_attribute);
  2658. static inline dw_die_ref get_AT_ref (dw_die_ref, enum dwarf_attribute);
  2659. static bool is_cxx (void);
  2660. static bool is_fortran (void);
  2661. static bool is_ada (void);
  2662. static void remove_AT (dw_die_ref, enum dwarf_attribute);
  2663. static void remove_child_TAG (dw_die_ref, enum dwarf_tag);
  2664. static void add_child_die (dw_die_ref, dw_die_ref);
  2665. static dw_die_ref new_die (enum dwarf_tag, dw_die_ref, tree);
  2666. static dw_die_ref lookup_type_die (tree);
  2667. static dw_die_ref strip_naming_typedef (tree, dw_die_ref);
  2668. static dw_die_ref lookup_type_die_strip_naming_typedef (tree);
  2669. static void equate_type_number_to_die (tree, dw_die_ref);
  2670. static dw_die_ref lookup_decl_die (tree);
  2671. static var_loc_list *lookup_decl_loc (const_tree);
  2672. static void equate_decl_number_to_die (tree, dw_die_ref);
  2673. static struct var_loc_node *add_var_loc_to_decl (tree, rtx, const char *);
  2674. static void print_spaces (FILE *);
  2675. static void print_die (dw_die_ref, FILE *);
  2676. static dw_die_ref push_new_compile_unit (dw_die_ref, dw_die_ref);
  2677. static dw_die_ref pop_compile_unit (dw_die_ref);
  2678. static void loc_checksum (dw_loc_descr_ref, struct md5_ctx *);
  2679. static void attr_checksum (dw_attr_ref, struct md5_ctx *, int *);
  2680. static void die_checksum (dw_die_ref, struct md5_ctx *, int *);
  2681. static void checksum_sleb128 (HOST_WIDE_INT, struct md5_ctx *);
  2682. static void checksum_uleb128 (unsigned HOST_WIDE_INT, struct md5_ctx *);
  2683. static void loc_checksum_ordered (dw_loc_descr_ref, struct md5_ctx *);
  2684. static void attr_checksum_ordered (enum dwarf_tag, dw_attr_ref,
  2685. struct md5_ctx *, int *);
  2686. struct checksum_attributes;
  2687. static void collect_checksum_attributes (struct checksum_attributes *, dw_die_ref);
  2688. static void die_checksum_ordered (dw_die_ref, struct md5_ctx *, int *);
  2689. static void checksum_die_context (dw_die_ref, struct md5_ctx *);
  2690. static void generate_type_signature (dw_die_ref, comdat_type_node *);
  2691. static int same_loc_p (dw_loc_descr_ref, dw_loc_descr_ref, int *);
  2692. static int same_dw_val_p (const dw_val_node *, const dw_val_node *, int *);
  2693. static int same_attr_p (dw_attr_ref, dw_attr_ref, int *);
  2694. static int same_die_p (dw_die_ref, dw_die_ref, int *);
  2695. static int same_die_p_wrap (dw_die_ref, dw_die_ref);
  2696. static void compute_section_prefix (dw_die_ref);
  2697. static int is_type_die (dw_die_ref);
  2698. static int is_comdat_die (dw_die_ref);
  2699. static int is_symbol_die (dw_die_ref);
  2700. static inline bool is_template_instantiation (dw_die_ref);
  2701. static void assign_symbol_names (dw_die_ref);
  2702. static void break_out_includes (dw_die_ref);
  2703. static int is_declaration_die (dw_die_ref);
  2704. static int should_move_die_to_comdat (dw_die_ref);
  2705. static dw_die_ref clone_as_declaration (dw_die_ref);
  2706. static dw_die_ref clone_die (dw_die_ref);
  2707. static dw_die_ref clone_tree (dw_die_ref);
  2708. static dw_die_ref copy_declaration_context (dw_die_ref, dw_die_ref);
  2709. static void generate_skeleton_ancestor_tree (skeleton_chain_node *);
  2710. static void generate_skeleton_bottom_up (skeleton_chain_node *);
  2711. static dw_die_ref generate_skeleton (dw_die_ref);
  2712. static dw_die_ref remove_child_or_replace_with_skeleton (dw_die_ref,
  2713. dw_die_ref,
  2714. dw_die_ref);
  2715. static void break_out_comdat_types (dw_die_ref);
  2716. static void copy_decls_for_unworthy_types (dw_die_ref);
  2717. static void add_sibling_attributes (dw_die_ref);
  2718. static void output_location_lists (dw_die_ref);
  2719. static int constant_size (unsigned HOST_WIDE_INT);
  2720. static unsigned long size_of_die (dw_die_ref);
  2721. static void calc_die_sizes (dw_die_ref);
  2722. static void calc_base_type_die_sizes (void);
  2723. static void mark_dies (dw_die_ref);
  2724. static void unmark_dies (dw_die_ref);
  2725. static void unmark_all_dies (dw_die_ref);
  2726. static unsigned long size_of_pubnames (vec<pubname_entry, va_gc> *);
  2727. static unsigned long size_of_aranges (void);
  2728. static enum dwarf_form value_format (dw_attr_ref);
  2729. static void output_value_format (dw_attr_ref);
  2730. static void output_abbrev_section (void);
  2731. static void output_die_abbrevs (unsigned long, dw_die_ref);
  2732. static void output_die_symbol (dw_die_ref);
  2733. static void output_die (dw_die_ref);
  2734. static void output_compilation_unit_header (void);
  2735. static void output_comp_unit (dw_die_ref, int);
  2736. static void output_comdat_type_unit (comdat_type_node *);
  2737. static const char *dwarf2_name (tree, int);
  2738. static void add_pubname (tree, dw_die_ref);
  2739. static void add_enumerator_pubname (const char *, dw_die_ref);
  2740. static void add_pubname_string (const char *, dw_die_ref);
  2741. static void add_pubtype (tree, dw_die_ref);
  2742. static void output_pubnames (vec<pubname_entry, va_gc> *);
  2743. static void output_aranges (unsigned long);
  2744. static unsigned int add_ranges_num (int);
  2745. static unsigned int add_ranges (const_tree);
  2746. static void add_ranges_by_labels (dw_die_ref, const char *, const char *,
  2747. bool *, bool);
  2748. static void output_ranges (void);
  2749. static dw_line_info_table *new_line_info_table (void);
  2750. static void output_line_info (bool);
  2751. static void output_file_names (void);
  2752. static dw_die_ref base_type_die (tree);
  2753. static int is_base_type (tree);
  2754. static dw_die_ref subrange_type_die (tree, tree, tree, dw_die_ref);
  2755. static int decl_quals (const_tree);
  2756. static dw_die_ref modified_type_die (tree, int, dw_die_ref);
  2757. static dw_die_ref generic_parameter_die (tree, tree, bool, dw_die_ref);
  2758. static dw_die_ref template_parameter_pack_die (tree, tree, dw_die_ref);
  2759. static int type_is_enum (const_tree);
  2760. static unsigned int dbx_reg_number (const_rtx);
  2761. static void add_loc_descr_op_piece (dw_loc_descr_ref *, int);
  2762. static dw_loc_descr_ref reg_loc_descriptor (rtx, enum var_init_status);
  2763. static dw_loc_descr_ref one_reg_loc_descriptor (unsigned int,
  2764. enum var_init_status);
  2765. static dw_loc_descr_ref multiple_reg_loc_descriptor (rtx, rtx,
  2766. enum var_init_status);
  2767. static dw_loc_descr_ref based_loc_descr (rtx, HOST_WIDE_INT,
  2768. enum var_init_status);
  2769. static int is_based_loc (const_rtx);
  2770. static bool resolve_one_addr (rtx *);
  2771. static dw_loc_descr_ref concat_loc_descriptor (rtx, rtx,
  2772. enum var_init_status);
  2773. static dw_loc_descr_ref loc_descriptor (rtx, machine_mode mode,
  2774. enum var_init_status);
  2775. struct loc_descr_context;
  2776. static dw_loc_list_ref loc_list_from_tree (tree, int,
  2777. const struct loc_descr_context *);
  2778. static dw_loc_descr_ref loc_descriptor_from_tree (tree, int,
  2779. const struct loc_descr_context *);
  2780. static HOST_WIDE_INT ceiling (HOST_WIDE_INT, unsigned int);
  2781. static tree field_type (const_tree);
  2782. static unsigned int simple_type_align_in_bits (const_tree);
  2783. static unsigned int simple_decl_align_in_bits (const_tree);
  2784. static unsigned HOST_WIDE_INT simple_type_size_in_bits (const_tree);
  2785. static HOST_WIDE_INT field_byte_offset (const_tree);
  2786. static void add_AT_location_description (dw_die_ref, enum dwarf_attribute,
  2787. dw_loc_list_ref);
  2788. static void add_data_member_location_attribute (dw_die_ref, tree);
  2789. static bool add_const_value_attribute (dw_die_ref, rtx);
  2790. static void insert_int (HOST_WIDE_INT, unsigned, unsigned char *);
  2791. static void insert_wide_int (const wide_int &, unsigned char *, int);
  2792. static void insert_float (const_rtx, unsigned char *);
  2793. static rtx rtl_for_decl_location (tree);
  2794. static bool add_location_or_const_value_attribute (dw_die_ref, tree, bool,
  2795. enum dwarf_attribute);
  2796. static bool tree_add_const_value_attribute (dw_die_ref, tree);
  2797. static bool tree_add_const_value_attribute_for_decl (dw_die_ref, tree);
  2798. static void add_name_attribute (dw_die_ref, const char *);
  2799. static void add_gnat_descriptive_type_attribute (dw_die_ref, tree, dw_die_ref);
  2800. static void add_comp_dir_attribute (dw_die_ref);
  2801. static void add_scalar_info (dw_die_ref, enum dwarf_attribute, tree, int,
  2802. const struct loc_descr_context *);
  2803. static void add_bound_info (dw_die_ref, enum dwarf_attribute, tree,
  2804. const struct loc_descr_context *);
  2805. static void add_subscript_info (dw_die_ref, tree, bool);
  2806. static void add_byte_size_attribute (dw_die_ref, tree);
  2807. static void add_bit_offset_attribute (dw_die_ref, tree);
  2808. static void add_bit_size_attribute (dw_die_ref, tree);
  2809. static void add_prototyped_attribute (dw_die_ref, tree);
  2810. static dw_die_ref add_abstract_origin_attribute (dw_die_ref, tree);
  2811. static void add_pure_or_virtual_attribute (dw_die_ref, tree);
  2812. static void add_src_coords_attributes (dw_die_ref, tree);
  2813. static void add_name_and_src_coords_attributes (dw_die_ref, tree);
  2814. static void push_decl_scope (tree);
  2815. static void pop_decl_scope (void);
  2816. static dw_die_ref scope_die_for (tree, dw_die_ref);
  2817. static inline int local_scope_p (dw_die_ref);
  2818. static inline int class_scope_p (dw_die_ref);
  2819. static inline int class_or_namespace_scope_p (dw_die_ref);
  2820. static void add_type_attribute (dw_die_ref, tree, int, dw_die_ref);
  2821. static void add_calling_convention_attribute (dw_die_ref, tree);
  2822. static const char *type_tag (const_tree);
  2823. static tree member_declared_type (const_tree);
  2824. #if 0
  2825. static const char *decl_start_label (tree);
  2826. #endif
  2827. static void gen_array_type_die (tree, dw_die_ref);
  2828. static void gen_descr_array_type_die (tree, struct array_descr_info *, dw_die_ref);
  2829. #if 0
  2830. static void gen_entry_point_die (tree, dw_die_ref);
  2831. #endif
  2832. static dw_die_ref gen_enumeration_type_die (tree, dw_die_ref);
  2833. static dw_die_ref gen_formal_parameter_die (tree, tree, bool, dw_die_ref);
  2834. static dw_die_ref gen_formal_parameter_pack_die (tree, tree, dw_die_ref, tree*);
  2835. static void gen_unspecified_parameters_die (tree, dw_die_ref);
  2836. static void gen_formal_types_die (tree, dw_die_ref);
  2837. static void gen_subprogram_die (tree, dw_die_ref);
  2838. static void gen_variable_die (tree, tree, dw_die_ref);
  2839. static void gen_const_die (tree, dw_die_ref);
  2840. static void gen_label_die (tree, dw_die_ref);
  2841. static void gen_lexical_block_die (tree, dw_die_ref);
  2842. static void gen_inlined_subroutine_die (tree, dw_die_ref);
  2843. static void gen_field_die (tree, dw_die_ref);
  2844. static void gen_ptr_to_mbr_type_die (tree, dw_die_ref);
  2845. static dw_die_ref gen_compile_unit_die (const char *);
  2846. static void gen_inheritance_die (tree, tree, dw_die_ref);
  2847. static void gen_member_die (tree, dw_die_ref);
  2848. static void gen_struct_or_union_type_die (tree, dw_die_ref,
  2849. enum debug_info_usage);
  2850. static void gen_subroutine_type_die (tree, dw_die_ref);
  2851. static void gen_typedef_die (tree, dw_die_ref);
  2852. static void gen_type_die (tree, dw_die_ref);
  2853. static void gen_block_die (tree, dw_die_ref);
  2854. static void decls_for_scope (tree, dw_die_ref);
  2855. static inline int is_redundant_typedef (const_tree);
  2856. static bool is_naming_typedef_decl (const_tree);
  2857. static inline dw_die_ref get_context_die (tree);
  2858. static void gen_namespace_die (tree, dw_die_ref);
  2859. static dw_die_ref gen_namelist_decl (tree, dw_die_ref, tree);
  2860. static dw_die_ref gen_decl_die (tree, tree, dw_die_ref);
  2861. static dw_die_ref force_decl_die (tree);
  2862. static dw_die_ref force_type_die (tree);
  2863. static dw_die_ref setup_namespace_context (tree, dw_die_ref);
  2864. static dw_die_ref declare_in_namespace (tree, dw_die_ref);
  2865. static struct dwarf_file_data * lookup_filename (const char *);
  2866. static void retry_incomplete_types (void);
  2867. static void gen_type_die_for_member (tree, tree, dw_die_ref);
  2868. static void gen_generic_params_dies (tree);
  2869. static void gen_tagged_type_die (tree, dw_die_ref, enum debug_info_usage);
  2870. static void gen_type_die_with_usage (tree, dw_die_ref, enum debug_info_usage);
  2871. static void splice_child_die (dw_die_ref, dw_die_ref);
  2872. static int file_info_cmp (const void *, const void *);
  2873. static dw_loc_list_ref new_loc_list (dw_loc_descr_ref, const char *,
  2874. const char *, const char *);
  2875. static void output_loc_list (dw_loc_list_ref);
  2876. static char *gen_internal_sym (const char *);
  2877. static bool want_pubnames (void);
  2878. static void prune_unmark_dies (dw_die_ref);
  2879. static void prune_unused_types_mark_generic_parms_dies (dw_die_ref);
  2880. static void prune_unused_types_mark (dw_die_ref, int);
  2881. static void prune_unused_types_walk (dw_die_ref);
  2882. static void prune_unused_types_walk_attribs (dw_die_ref);
  2883. static void prune_unused_types_prune (dw_die_ref);
  2884. static void prune_unused_types (void);
  2885. static int maybe_emit_file (struct dwarf_file_data *fd);
  2886. static inline const char *AT_vms_delta1 (dw_attr_ref);
  2887. static inline const char *AT_vms_delta2 (dw_attr_ref);
  2888. static inline void add_AT_vms_delta (dw_die_ref, enum dwarf_attribute,
  2889. const char *, const char *);
  2890. static void append_entry_to_tmpl_value_parm_die_table (dw_die_ref, tree);
  2891. static void gen_remaining_tmpl_value_param_die_attribute (void);
  2892. static bool generic_type_p (tree);
  2893. static void schedule_generic_params_dies_gen (tree t);
  2894. static void gen_scheduled_generic_parms_dies (void);
  2895. static const char *comp_dir_string (void);
  2896. static void hash_loc_operands (dw_loc_descr_ref, inchash::hash &);
  2897. /* enum for tracking thread-local variables whose address is really an offset
  2898. relative to the TLS pointer, which will need link-time relocation, but will
  2899. not need relocation by the DWARF consumer. */
  2900. enum dtprel_bool
  2901. {
  2902. dtprel_false = 0,
  2903. dtprel_true = 1
  2904. };
  2905. /* Return the operator to use for an address of a variable. For dtprel_true, we
  2906. use DW_OP_const*. For regular variables, which need both link-time
  2907. relocation and consumer-level relocation (e.g., to account for shared objects
  2908. loaded at a random address), we use DW_OP_addr*. */
  2909. static inline enum dwarf_location_atom
  2910. dw_addr_op (enum dtprel_bool dtprel)
  2911. {
  2912. if (dtprel == dtprel_true)
  2913. return (dwarf_split_debug_info ? DW_OP_GNU_const_index
  2914. : (DWARF2_ADDR_SIZE == 4 ? DW_OP_const4u : DW_OP_const8u));
  2915. else
  2916. return dwarf_split_debug_info ? DW_OP_GNU_addr_index : DW_OP_addr;
  2917. }
  2918. /* Return a pointer to a newly allocated address location description. If
  2919. dwarf_split_debug_info is true, then record the address with the appropriate
  2920. relocation. */
  2921. static inline dw_loc_descr_ref
  2922. new_addr_loc_descr (rtx addr, enum dtprel_bool dtprel)
  2923. {
  2924. dw_loc_descr_ref ref = new_loc_descr (dw_addr_op (dtprel), 0, 0);
  2925. ref->dw_loc_oprnd1.val_class = dw_val_class_addr;
  2926. ref->dw_loc_oprnd1.v.val_addr = addr;
  2927. ref->dtprel = dtprel;
  2928. if (dwarf_split_debug_info)
  2929. ref->dw_loc_oprnd1.val_entry
  2930. = add_addr_table_entry (addr,
  2931. dtprel ? ate_kind_rtx_dtprel : ate_kind_rtx);
  2932. else
  2933. ref->dw_loc_oprnd1.val_entry = NULL;
  2934. return ref;
  2935. }
  2936. /* Section names used to hold DWARF debugging information. */
  2937. #ifndef DEBUG_INFO_SECTION
  2938. #define DEBUG_INFO_SECTION ".debug_info"
  2939. #endif
  2940. #ifndef DEBUG_DWO_INFO_SECTION
  2941. #define DEBUG_DWO_INFO_SECTION ".debug_info.dwo"
  2942. #endif
  2943. #ifndef DEBUG_ABBREV_SECTION
  2944. #define DEBUG_ABBREV_SECTION ".debug_abbrev"
  2945. #endif
  2946. #ifndef DEBUG_DWO_ABBREV_SECTION
  2947. #define DEBUG_DWO_ABBREV_SECTION ".debug_abbrev.dwo"
  2948. #endif
  2949. #ifndef DEBUG_ARANGES_SECTION
  2950. #define DEBUG_ARANGES_SECTION ".debug_aranges"
  2951. #endif
  2952. #ifndef DEBUG_ADDR_SECTION
  2953. #define DEBUG_ADDR_SECTION ".debug_addr"
  2954. #endif
  2955. #ifndef DEBUG_NORM_MACINFO_SECTION
  2956. #define DEBUG_NORM_MACINFO_SECTION ".debug_macinfo"
  2957. #endif
  2958. #ifndef DEBUG_DWO_MACINFO_SECTION
  2959. #define DEBUG_DWO_MACINFO_SECTION ".debug_macinfo.dwo"
  2960. #endif
  2961. #ifndef DEBUG_MACINFO_SECTION
  2962. #define DEBUG_MACINFO_SECTION \
  2963. (!dwarf_split_debug_info \
  2964. ? (DEBUG_NORM_MACINFO_SECTION) : (DEBUG_DWO_MACINFO_SECTION))
  2965. #endif
  2966. #ifndef DEBUG_NORM_MACRO_SECTION
  2967. #define DEBUG_NORM_MACRO_SECTION ".debug_macro"
  2968. #endif
  2969. #ifndef DEBUG_DWO_MACRO_SECTION
  2970. #define DEBUG_DWO_MACRO_SECTION ".debug_macro.dwo"
  2971. #endif
  2972. #ifndef DEBUG_MACRO_SECTION
  2973. #define DEBUG_MACRO_SECTION \
  2974. (!dwarf_split_debug_info \
  2975. ? (DEBUG_NORM_MACRO_SECTION) : (DEBUG_DWO_MACRO_SECTION))
  2976. #endif
  2977. #ifndef DEBUG_LINE_SECTION
  2978. #define DEBUG_LINE_SECTION ".debug_line"
  2979. #endif
  2980. #ifndef DEBUG_DWO_LINE_SECTION
  2981. #define DEBUG_DWO_LINE_SECTION ".debug_line.dwo"
  2982. #endif
  2983. #ifndef DEBUG_LOC_SECTION
  2984. #define DEBUG_LOC_SECTION ".debug_loc"
  2985. #endif
  2986. #ifndef DEBUG_DWO_LOC_SECTION
  2987. #define DEBUG_DWO_LOC_SECTION ".debug_loc.dwo"
  2988. #endif
  2989. #ifndef DEBUG_PUBNAMES_SECTION
  2990. #define DEBUG_PUBNAMES_SECTION \
  2991. ((debug_generate_pub_sections == 2) \
  2992. ? ".debug_gnu_pubnames" : ".debug_pubnames")
  2993. #endif
  2994. #ifndef DEBUG_PUBTYPES_SECTION
  2995. #define DEBUG_PUBTYPES_SECTION \
  2996. ((debug_generate_pub_sections == 2) \
  2997. ? ".debug_gnu_pubtypes" : ".debug_pubtypes")
  2998. #endif
  2999. #define DEBUG_NORM_STR_OFFSETS_SECTION ".debug_str_offsets"
  3000. #define DEBUG_DWO_STR_OFFSETS_SECTION ".debug_str_offsets.dwo"
  3001. #ifndef DEBUG_STR_OFFSETS_SECTION
  3002. #define DEBUG_STR_OFFSETS_SECTION \
  3003. (!dwarf_split_debug_info \
  3004. ? (DEBUG_NORM_STR_OFFSETS_SECTION) : (DEBUG_DWO_STR_OFFSETS_SECTION))
  3005. #endif
  3006. #ifndef DEBUG_STR_DWO_SECTION
  3007. #define DEBUG_STR_DWO_SECTION ".debug_str.dwo"
  3008. #endif
  3009. #ifndef DEBUG_STR_SECTION
  3010. #define DEBUG_STR_SECTION ".debug_str"
  3011. #endif
  3012. #ifndef DEBUG_RANGES_SECTION
  3013. #define DEBUG_RANGES_SECTION ".debug_ranges"
  3014. #endif
  3015. /* Standard ELF section names for compiled code and data. */
  3016. #ifndef TEXT_SECTION_NAME
  3017. #define TEXT_SECTION_NAME ".text"
  3018. #endif
  3019. /* Section flags for .debug_macinfo/.debug_macro section. */
  3020. #define DEBUG_MACRO_SECTION_FLAGS \
  3021. (dwarf_split_debug_info ? SECTION_DEBUG | SECTION_EXCLUDE : SECTION_DEBUG)
  3022. /* Section flags for .debug_str section. */
  3023. #define DEBUG_STR_SECTION_FLAGS \
  3024. (HAVE_GAS_SHF_MERGE && flag_merge_debug_strings \
  3025. ? SECTION_DEBUG | SECTION_MERGE | SECTION_STRINGS | 1 \
  3026. : SECTION_DEBUG)
  3027. /* Section flags for .debug_str.dwo section. */
  3028. #define DEBUG_STR_DWO_SECTION_FLAGS (SECTION_DEBUG | SECTION_EXCLUDE)
  3029. /* Labels we insert at beginning sections we can reference instead of
  3030. the section names themselves. */
  3031. #ifndef TEXT_SECTION_LABEL
  3032. #define TEXT_SECTION_LABEL "Ltext"
  3033. #endif
  3034. #ifndef COLD_TEXT_SECTION_LABEL
  3035. #define COLD_TEXT_SECTION_LABEL "Ltext_cold"
  3036. #endif
  3037. #ifndef DEBUG_LINE_SECTION_LABEL
  3038. #define DEBUG_LINE_SECTION_LABEL "Ldebug_line"
  3039. #endif
  3040. #ifndef DEBUG_SKELETON_LINE_SECTION_LABEL
  3041. #define DEBUG_SKELETON_LINE_SECTION_LABEL "Lskeleton_debug_line"
  3042. #endif
  3043. #ifndef DEBUG_INFO_SECTION_LABEL
  3044. #define DEBUG_INFO_SECTION_LABEL "Ldebug_info"
  3045. #endif
  3046. #ifndef DEBUG_SKELETON_INFO_SECTION_LABEL
  3047. #define DEBUG_SKELETON_INFO_SECTION_LABEL "Lskeleton_debug_info"
  3048. #endif
  3049. #ifndef DEBUG_ABBREV_SECTION_LABEL
  3050. #define DEBUG_ABBREV_SECTION_LABEL "Ldebug_abbrev"
  3051. #endif
  3052. #ifndef DEBUG_SKELETON_ABBREV_SECTION_LABEL
  3053. #define DEBUG_SKELETON_ABBREV_SECTION_LABEL "Lskeleton_debug_abbrev"
  3054. #endif
  3055. #ifndef DEBUG_ADDR_SECTION_LABEL
  3056. #define DEBUG_ADDR_SECTION_LABEL "Ldebug_addr"
  3057. #endif
  3058. #ifndef DEBUG_LOC_SECTION_LABEL
  3059. #define DEBUG_LOC_SECTION_LABEL "Ldebug_loc"
  3060. #endif
  3061. #ifndef DEBUG_RANGES_SECTION_LABEL
  3062. #define DEBUG_RANGES_SECTION_LABEL "Ldebug_ranges"
  3063. #endif
  3064. #ifndef DEBUG_MACINFO_SECTION_LABEL
  3065. #define DEBUG_MACINFO_SECTION_LABEL "Ldebug_macinfo"
  3066. #endif
  3067. #ifndef DEBUG_MACRO_SECTION_LABEL
  3068. #define DEBUG_MACRO_SECTION_LABEL "Ldebug_macro"
  3069. #endif
  3070. #define SKELETON_COMP_DIE_ABBREV 1
  3071. #define SKELETON_TYPE_DIE_ABBREV 2
  3072. /* Definitions of defaults for formats and names of various special
  3073. (artificial) labels which may be generated within this file (when the -g
  3074. options is used and DWARF2_DEBUGGING_INFO is in effect.
  3075. If necessary, these may be overridden from within the tm.h file, but
  3076. typically, overriding these defaults is unnecessary. */
  3077. static char text_end_label[MAX_ARTIFICIAL_LABEL_BYTES];
  3078. static char text_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
  3079. static char cold_text_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
  3080. static char cold_end_label[MAX_ARTIFICIAL_LABEL_BYTES];
  3081. static char abbrev_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
  3082. static char debug_info_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
  3083. static char debug_skeleton_info_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
  3084. static char debug_skeleton_abbrev_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
  3085. static char debug_line_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
  3086. static char debug_addr_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
  3087. static char debug_skeleton_line_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
  3088. static char macinfo_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
  3089. static char loc_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
  3090. static char ranges_section_label[2 * MAX_ARTIFICIAL_LABEL_BYTES];
  3091. #ifndef TEXT_END_LABEL
  3092. #define TEXT_END_LABEL "Letext"
  3093. #endif
  3094. #ifndef COLD_END_LABEL
  3095. #define COLD_END_LABEL "Letext_cold"
  3096. #endif
  3097. #ifndef BLOCK_BEGIN_LABEL
  3098. #define BLOCK_BEGIN_LABEL "LBB"
  3099. #endif
  3100. #ifndef BLOCK_END_LABEL
  3101. #define BLOCK_END_LABEL "LBE"
  3102. #endif
  3103. #ifndef LINE_CODE_LABEL
  3104. #define LINE_CODE_LABEL "LM"
  3105. #endif
  3106. /* Return the root of the DIE's built for the current compilation unit. */
  3107. static dw_die_ref
  3108. comp_unit_die (void)
  3109. {
  3110. if (!single_comp_unit_die)
  3111. single_comp_unit_die = gen_compile_unit_die (NULL);
  3112. return single_comp_unit_die;
  3113. }
  3114. /* We allow a language front-end to designate a function that is to be
  3115. called to "demangle" any name before it is put into a DIE. */
  3116. static const char *(*demangle_name_func) (const char *);
  3117. void
  3118. dwarf2out_set_demangle_name_func (const char *(*func) (const char *))
  3119. {
  3120. demangle_name_func = func;
  3121. }
  3122. /* Test if rtl node points to a pseudo register. */
  3123. static inline int
  3124. is_pseudo_reg (const_rtx rtl)
  3125. {
  3126. return ((REG_P (rtl) && REGNO (rtl) >= FIRST_PSEUDO_REGISTER)
  3127. || (GET_CODE (rtl) == SUBREG
  3128. && REGNO (SUBREG_REG (rtl)) >= FIRST_PSEUDO_REGISTER));
  3129. }
  3130. /* Return a reference to a type, with its const and volatile qualifiers
  3131. removed. */
  3132. static inline tree
  3133. type_main_variant (tree type)
  3134. {
  3135. type = TYPE_MAIN_VARIANT (type);
  3136. /* ??? There really should be only one main variant among any group of
  3137. variants of a given type (and all of the MAIN_VARIANT values for all
  3138. members of the group should point to that one type) but sometimes the C
  3139. front-end messes this up for array types, so we work around that bug
  3140. here. */
  3141. if (TREE_CODE (type) == ARRAY_TYPE)
  3142. while (type != TYPE_MAIN_VARIANT (type))
  3143. type = TYPE_MAIN_VARIANT (type);
  3144. return type;
  3145. }
  3146. /* Return nonzero if the given type node represents a tagged type. */
  3147. static inline int
  3148. is_tagged_type (const_tree type)
  3149. {
  3150. enum tree_code code = TREE_CODE (type);
  3151. return (code == RECORD_TYPE || code == UNION_TYPE
  3152. || code == QUAL_UNION_TYPE || code == ENUMERAL_TYPE);
  3153. }
  3154. /* Set label to debug_info_section_label + die_offset of a DIE reference. */
  3155. static void
  3156. get_ref_die_offset_label (char *label, dw_die_ref ref)
  3157. {
  3158. sprintf (label, "%s+%ld", debug_info_section_label, ref->die_offset);
  3159. }
  3160. /* Return die_offset of a DIE reference to a base type. */
  3161. static unsigned long int
  3162. get_base_type_offset (dw_die_ref ref)
  3163. {
  3164. if (ref->die_offset)
  3165. return ref->die_offset;
  3166. if (comp_unit_die ()->die_abbrev)
  3167. {
  3168. calc_base_type_die_sizes ();
  3169. gcc_assert (ref->die_offset);
  3170. }
  3171. return ref->die_offset;
  3172. }
  3173. /* Return die_offset of a DIE reference other than base type. */
  3174. static unsigned long int
  3175. get_ref_die_offset (dw_die_ref ref)
  3176. {
  3177. gcc_assert (ref->die_offset);
  3178. return ref->die_offset;
  3179. }
  3180. /* Convert a DIE tag into its string name. */
  3181. static const char *
  3182. dwarf_tag_name (unsigned int tag)
  3183. {
  3184. const char *name = get_DW_TAG_name (tag);
  3185. if (name != NULL)
  3186. return name;
  3187. return "DW_TAG_<unknown>";
  3188. }
  3189. /* Convert a DWARF attribute code into its string name. */
  3190. static const char *
  3191. dwarf_attr_name (unsigned int attr)
  3192. {
  3193. const char *name;
  3194. switch (attr)
  3195. {
  3196. #if VMS_DEBUGGING_INFO
  3197. case DW_AT_HP_prologue:
  3198. return "DW_AT_HP_prologue";
  3199. #else
  3200. case DW_AT_MIPS_loop_unroll_factor:
  3201. return "DW_AT_MIPS_loop_unroll_factor";
  3202. #endif
  3203. #if VMS_DEBUGGING_INFO
  3204. case DW_AT_HP_epilogue:
  3205. return "DW_AT_HP_epilogue";
  3206. #else
  3207. case DW_AT_MIPS_stride:
  3208. return "DW_AT_MIPS_stride";
  3209. #endif
  3210. }
  3211. name = get_DW_AT_name (attr);
  3212. if (name != NULL)
  3213. return name;
  3214. return "DW_AT_<unknown>";
  3215. }
  3216. /* Convert a DWARF value form code into its string name. */
  3217. static const char *
  3218. dwarf_form_name (unsigned int form)
  3219. {
  3220. const char *name = get_DW_FORM_name (form);
  3221. if (name != NULL)
  3222. return name;
  3223. return "DW_FORM_<unknown>";
  3224. }
  3225. /* Determine the "ultimate origin" of a decl. The decl may be an inlined
  3226. instance of an inlined instance of a decl which is local to an inline
  3227. function, so we have to trace all of the way back through the origin chain
  3228. to find out what sort of node actually served as the original seed for the
  3229. given block. */
  3230. static tree
  3231. decl_ultimate_origin (const_tree decl)
  3232. {
  3233. if (!CODE_CONTAINS_STRUCT (TREE_CODE (decl), TS_DECL_COMMON))
  3234. return NULL_TREE;
  3235. /* DECL_ABSTRACT_ORIGIN can point to itself; ignore that if
  3236. we're trying to output the abstract instance of this function. */
  3237. if (DECL_ABSTRACT_P (decl) && DECL_ABSTRACT_ORIGIN (decl) == decl)
  3238. return NULL_TREE;
  3239. /* Since the DECL_ABSTRACT_ORIGIN for a DECL is supposed to be the
  3240. most distant ancestor, this should never happen. */
  3241. gcc_assert (!DECL_FROM_INLINE (DECL_ORIGIN (decl)));
  3242. return DECL_ABSTRACT_ORIGIN (decl);
  3243. }
  3244. /* Get the class to which DECL belongs, if any. In g++, the DECL_CONTEXT
  3245. of a virtual function may refer to a base class, so we check the 'this'
  3246. parameter. */
  3247. static tree
  3248. decl_class_context (tree decl)
  3249. {
  3250. tree context = NULL_TREE;
  3251. if (TREE_CODE (decl) != FUNCTION_DECL || ! DECL_VINDEX (decl))
  3252. context = DECL_CONTEXT (decl);
  3253. else
  3254. context = TYPE_MAIN_VARIANT
  3255. (TREE_TYPE (TREE_VALUE (TYPE_ARG_TYPES (TREE_TYPE (decl)))));
  3256. if (context && !TYPE_P (context))
  3257. context = NULL_TREE;
  3258. return context;
  3259. }
  3260. /* Add an attribute/value pair to a DIE. */
  3261. static inline void
  3262. add_dwarf_attr (dw_die_ref die, dw_attr_ref attr)
  3263. {
  3264. /* Maybe this should be an assert? */
  3265. if (die == NULL)
  3266. return;
  3267. vec_safe_reserve (die->die_attr, 1);
  3268. vec_safe_push (die->die_attr, *attr);
  3269. }
  3270. static inline enum dw_val_class
  3271. AT_class (dw_attr_ref a)
  3272. {
  3273. return a->dw_attr_val.val_class;
  3274. }
  3275. /* Return the index for any attribute that will be referenced with a
  3276. DW_FORM_GNU_addr_index or DW_FORM_GNU_str_index. String indices
  3277. are stored in dw_attr_val.v.val_str for reference counting
  3278. pruning. */
  3279. static inline unsigned int
  3280. AT_index (dw_attr_ref a)
  3281. {
  3282. if (AT_class (a) == dw_val_class_str)
  3283. return a->dw_attr_val.v.val_str->index;
  3284. else if (a->dw_attr_val.val_entry != NULL)
  3285. return a->dw_attr_val.val_entry->index;
  3286. return NOT_INDEXED;
  3287. }
  3288. /* Add a flag value attribute to a DIE. */
  3289. static inline void
  3290. add_AT_flag (dw_die_ref die, enum dwarf_attribute attr_kind, unsigned int flag)
  3291. {
  3292. dw_attr_node attr;
  3293. attr.dw_attr = attr_kind;
  3294. attr.dw_attr_val.val_class = dw_val_class_flag;
  3295. attr.dw_attr_val.val_entry = NULL;
  3296. attr.dw_attr_val.v.val_flag = flag;
  3297. add_dwarf_attr (die, &attr);
  3298. }
  3299. static inline unsigned
  3300. AT_flag (dw_attr_ref a)
  3301. {
  3302. gcc_assert (a && AT_class (a) == dw_val_class_flag);
  3303. return a->dw_attr_val.v.val_flag;
  3304. }
  3305. /* Add a signed integer attribute value to a DIE. */
  3306. static inline void
  3307. add_AT_int (dw_die_ref die, enum dwarf_attribute attr_kind, HOST_WIDE_INT int_val)
  3308. {
  3309. dw_attr_node attr;
  3310. attr.dw_attr = attr_kind;
  3311. attr.dw_attr_val.val_class = dw_val_class_const;
  3312. attr.dw_attr_val.val_entry = NULL;
  3313. attr.dw_attr_val.v.val_int = int_val;
  3314. add_dwarf_attr (die, &attr);
  3315. }
  3316. static inline HOST_WIDE_INT
  3317. AT_int (dw_attr_ref a)
  3318. {
  3319. gcc_assert (a && AT_class (a) == dw_val_class_const);
  3320. return a->dw_attr_val.v.val_int;
  3321. }
  3322. /* Add an unsigned integer attribute value to a DIE. */
  3323. static inline void
  3324. add_AT_unsigned (dw_die_ref die, enum dwarf_attribute attr_kind,
  3325. unsigned HOST_WIDE_INT unsigned_val)
  3326. {
  3327. dw_attr_node attr;
  3328. attr.dw_attr = attr_kind;
  3329. attr.dw_attr_val.val_class = dw_val_class_unsigned_const;
  3330. attr.dw_attr_val.val_entry = NULL;
  3331. attr.dw_attr_val.v.val_unsigned = unsigned_val;
  3332. add_dwarf_attr (die, &attr);
  3333. }
  3334. static inline unsigned HOST_WIDE_INT
  3335. AT_unsigned (dw_attr_ref a)
  3336. {
  3337. gcc_assert (a && AT_class (a) == dw_val_class_unsigned_const);
  3338. return a->dw_attr_val.v.val_unsigned;
  3339. }
  3340. /* Add an unsigned wide integer attribute value to a DIE. */
  3341. static inline void
  3342. add_AT_wide (dw_die_ref die, enum dwarf_attribute attr_kind,
  3343. const wide_int& w)
  3344. {
  3345. dw_attr_node attr;
  3346. attr.dw_attr = attr_kind;
  3347. attr.dw_attr_val.val_class = dw_val_class_wide_int;
  3348. attr.dw_attr_val.val_entry = NULL;
  3349. attr.dw_attr_val.v.val_wide = ggc_alloc<wide_int> ();
  3350. *attr.dw_attr_val.v.val_wide = w;
  3351. add_dwarf_attr (die, &attr);
  3352. }
  3353. /* Add an unsigned double integer attribute value to a DIE. */
  3354. static inline void
  3355. add_AT_double (dw_die_ref die, enum dwarf_attribute attr_kind,
  3356. HOST_WIDE_INT high, unsigned HOST_WIDE_INT low)
  3357. {
  3358. dw_attr_node attr;
  3359. attr.dw_attr = attr_kind;
  3360. attr.dw_attr_val.val_class = dw_val_class_const_double;
  3361. attr.dw_attr_val.val_entry = NULL;
  3362. attr.dw_attr_val.v.val_double.high = high;
  3363. attr.dw_attr_val.v.val_double.low = low;
  3364. add_dwarf_attr (die, &attr);
  3365. }
  3366. /* Add a floating point attribute value to a DIE and return it. */
  3367. static inline void
  3368. add_AT_vec (dw_die_ref die, enum dwarf_attribute attr_kind,
  3369. unsigned int length, unsigned int elt_size, unsigned char *array)
  3370. {
  3371. dw_attr_node attr;
  3372. attr.dw_attr = attr_kind;
  3373. attr.dw_attr_val.val_class = dw_val_class_vec;
  3374. attr.dw_attr_val.val_entry = NULL;
  3375. attr.dw_attr_val.v.val_vec.length = length;
  3376. attr.dw_attr_val.v.val_vec.elt_size = elt_size;
  3377. attr.dw_attr_val.v.val_vec.array = array;
  3378. add_dwarf_attr (die, &attr);
  3379. }
  3380. /* Add an 8-byte data attribute value to a DIE. */
  3381. static inline void
  3382. add_AT_data8 (dw_die_ref die, enum dwarf_attribute attr_kind,
  3383. unsigned char data8[8])
  3384. {
  3385. dw_attr_node attr;
  3386. attr.dw_attr = attr_kind;
  3387. attr.dw_attr_val.val_class = dw_val_class_data8;
  3388. attr.dw_attr_val.val_entry = NULL;
  3389. memcpy (attr.dw_attr_val.v.val_data8, data8, 8);
  3390. add_dwarf_attr (die, &attr);
  3391. }
  3392. /* Add DW_AT_low_pc and DW_AT_high_pc to a DIE. When using
  3393. dwarf_split_debug_info, address attributes in dies destined for the
  3394. final executable have force_direct set to avoid using indexed
  3395. references. */
  3396. static inline void
  3397. add_AT_low_high_pc (dw_die_ref die, const char *lbl_low, const char *lbl_high,
  3398. bool force_direct)
  3399. {
  3400. dw_attr_node attr;
  3401. char * lbl_id;
  3402. lbl_id = xstrdup (lbl_low);
  3403. attr.dw_attr = DW_AT_low_pc;
  3404. attr.dw_attr_val.val_class = dw_val_class_lbl_id;
  3405. attr.dw_attr_val.v.val_lbl_id = lbl_id;
  3406. if (dwarf_split_debug_info && !force_direct)
  3407. attr.dw_attr_val.val_entry
  3408. = add_addr_table_entry (lbl_id, ate_kind_label);
  3409. else
  3410. attr.dw_attr_val.val_entry = NULL;
  3411. add_dwarf_attr (die, &attr);
  3412. attr.dw_attr = DW_AT_high_pc;
  3413. if (dwarf_version < 4)
  3414. attr.dw_attr_val.val_class = dw_val_class_lbl_id;
  3415. else
  3416. attr.dw_attr_val.val_class = dw_val_class_high_pc;
  3417. lbl_id = xstrdup (lbl_high);
  3418. attr.dw_attr_val.v.val_lbl_id = lbl_id;
  3419. if (attr.dw_attr_val.val_class == dw_val_class_lbl_id
  3420. && dwarf_split_debug_info && !force_direct)
  3421. attr.dw_attr_val.val_entry
  3422. = add_addr_table_entry (lbl_id, ate_kind_label);
  3423. else
  3424. attr.dw_attr_val.val_entry = NULL;
  3425. add_dwarf_attr (die, &attr);
  3426. }
  3427. /* Hash and equality functions for debug_str_hash. */
  3428. hashval_t
  3429. indirect_string_hasher::hash (indirect_string_node *x)
  3430. {
  3431. return htab_hash_string (x->str);
  3432. }
  3433. bool
  3434. indirect_string_hasher::equal (indirect_string_node *x1, const char *x2)
  3435. {
  3436. return strcmp (x1->str, x2) == 0;
  3437. }
  3438. /* Add STR to the given string hash table. */
  3439. static struct indirect_string_node *
  3440. find_AT_string_in_table (const char *str,
  3441. hash_table<indirect_string_hasher> *table)
  3442. {
  3443. struct indirect_string_node *node;
  3444. indirect_string_node **slot
  3445. = table->find_slot_with_hash (str, htab_hash_string (str), INSERT);
  3446. if (*slot == NULL)
  3447. {
  3448. node = ggc_cleared_alloc<indirect_string_node> ();
  3449. node->str = ggc_strdup (str);
  3450. *slot = node;
  3451. }
  3452. else
  3453. node = *slot;
  3454. node->refcount++;
  3455. return node;
  3456. }
  3457. /* Add STR to the indirect string hash table. */
  3458. static struct indirect_string_node *
  3459. find_AT_string (const char *str)
  3460. {
  3461. if (! debug_str_hash)
  3462. debug_str_hash = hash_table<indirect_string_hasher>::create_ggc (10);
  3463. return find_AT_string_in_table (str, debug_str_hash);
  3464. }
  3465. /* Add a string attribute value to a DIE. */
  3466. static inline void
  3467. add_AT_string (dw_die_ref die, enum dwarf_attribute attr_kind, const char *str)
  3468. {
  3469. dw_attr_node attr;
  3470. struct indirect_string_node *node;
  3471. node = find_AT_string (str);
  3472. attr.dw_attr = attr_kind;
  3473. attr.dw_attr_val.val_class = dw_val_class_str;
  3474. attr.dw_attr_val.val_entry = NULL;
  3475. attr.dw_attr_val.v.val_str = node;
  3476. add_dwarf_attr (die, &attr);
  3477. }
  3478. static inline const char *
  3479. AT_string (dw_attr_ref a)
  3480. {
  3481. gcc_assert (a && AT_class (a) == dw_val_class_str);
  3482. return a->dw_attr_val.v.val_str->str;
  3483. }
  3484. /* Call this function directly to bypass AT_string_form's logic to put
  3485. the string inline in the die. */
  3486. static void
  3487. set_indirect_string (struct indirect_string_node *node)
  3488. {
  3489. char label[32];
  3490. /* Already indirect is a no op. */
  3491. if (node->form == DW_FORM_strp || node->form == DW_FORM_GNU_str_index)
  3492. {
  3493. gcc_assert (node->label);
  3494. return;
  3495. }
  3496. ASM_GENERATE_INTERNAL_LABEL (label, "LASF", dw2_string_counter);
  3497. ++dw2_string_counter;
  3498. node->label = xstrdup (label);
  3499. if (!dwarf_split_debug_info)
  3500. {
  3501. node->form = DW_FORM_strp;
  3502. node->index = NOT_INDEXED;
  3503. }
  3504. else
  3505. {
  3506. node->form = DW_FORM_GNU_str_index;
  3507. node->index = NO_INDEX_ASSIGNED;
  3508. }
  3509. }
  3510. /* Find out whether a string should be output inline in DIE
  3511. or out-of-line in .debug_str section. */
  3512. static enum dwarf_form
  3513. find_string_form (struct indirect_string_node *node)
  3514. {
  3515. unsigned int len;
  3516. if (node->form)
  3517. return node->form;
  3518. len = strlen (node->str) + 1;
  3519. /* If the string is shorter or equal to the size of the reference, it is
  3520. always better to put it inline. */
  3521. if (len <= DWARF_OFFSET_SIZE || node->refcount == 0)
  3522. return node->form = DW_FORM_string;
  3523. /* If we cannot expect the linker to merge strings in .debug_str
  3524. section, only put it into .debug_str if it is worth even in this
  3525. single module. */
  3526. if (DWARF2_INDIRECT_STRING_SUPPORT_MISSING_ON_TARGET
  3527. || ((debug_str_section->common.flags & SECTION_MERGE) == 0
  3528. && (len - DWARF_OFFSET_SIZE) * node->refcount <= len))
  3529. return node->form = DW_FORM_string;
  3530. set_indirect_string (node);
  3531. return node->form;
  3532. }
  3533. /* Find out whether the string referenced from the attribute should be
  3534. output inline in DIE or out-of-line in .debug_str section. */
  3535. static enum dwarf_form
  3536. AT_string_form (dw_attr_ref a)
  3537. {
  3538. gcc_assert (a && AT_class (a) == dw_val_class_str);
  3539. return find_string_form (a->dw_attr_val.v.val_str);
  3540. }
  3541. /* Add a DIE reference attribute value to a DIE. */
  3542. static inline void
  3543. add_AT_die_ref (dw_die_ref die, enum dwarf_attribute attr_kind, dw_die_ref targ_die)
  3544. {
  3545. dw_attr_node attr;
  3546. #ifdef ENABLE_CHECKING
  3547. gcc_assert (targ_die != NULL);
  3548. #else
  3549. /* With LTO we can end up trying to reference something we didn't create
  3550. a DIE for. Avoid crashing later on a NULL referenced DIE. */
  3551. if (targ_die == NULL)
  3552. return;
  3553. #endif
  3554. attr.dw_attr = attr_kind;
  3555. attr.dw_attr_val.val_class = dw_val_class_die_ref;
  3556. attr.dw_attr_val.val_entry = NULL;
  3557. attr.dw_attr_val.v.val_die_ref.die = targ_die;
  3558. attr.dw_attr_val.v.val_die_ref.external = 0;
  3559. add_dwarf_attr (die, &attr);
  3560. }
  3561. /* Change DIE reference REF to point to NEW_DIE instead. */
  3562. static inline void
  3563. change_AT_die_ref (dw_attr_ref ref, dw_die_ref new_die)
  3564. {
  3565. gcc_assert (ref->dw_attr_val.val_class == dw_val_class_die_ref);
  3566. ref->dw_attr_val.v.val_die_ref.die = new_die;
  3567. ref->dw_attr_val.v.val_die_ref.external = 0;
  3568. }
  3569. /* Add an AT_specification attribute to a DIE, and also make the back
  3570. pointer from the specification to the definition. */
  3571. static inline void
  3572. add_AT_specification (dw_die_ref die, dw_die_ref targ_die)
  3573. {
  3574. add_AT_die_ref (die, DW_AT_specification, targ_die);
  3575. gcc_assert (!targ_die->die_definition);
  3576. targ_die->die_definition = die;
  3577. }
  3578. static inline dw_die_ref
  3579. AT_ref (dw_attr_ref a)
  3580. {
  3581. gcc_assert (a && AT_class (a) == dw_val_class_die_ref);
  3582. return a->dw_attr_val.v.val_die_ref.die;
  3583. }
  3584. static inline int
  3585. AT_ref_external (dw_attr_ref a)
  3586. {
  3587. if (a && AT_class (a) == dw_val_class_die_ref)
  3588. return a->dw_attr_val.v.val_die_ref.external;
  3589. return 0;
  3590. }
  3591. static inline void
  3592. set_AT_ref_external (dw_attr_ref a, int i)
  3593. {
  3594. gcc_assert (a && AT_class (a) == dw_val_class_die_ref);
  3595. a->dw_attr_val.v.val_die_ref.external = i;
  3596. }
  3597. /* Add an FDE reference attribute value to a DIE. */
  3598. static inline void
  3599. add_AT_fde_ref (dw_die_ref die, enum dwarf_attribute attr_kind, unsigned int targ_fde)
  3600. {
  3601. dw_attr_node attr;
  3602. attr.dw_attr = attr_kind;
  3603. attr.dw_attr_val.val_class = dw_val_class_fde_ref;
  3604. attr.dw_attr_val.val_entry = NULL;
  3605. attr.dw_attr_val.v.val_fde_index = targ_fde;
  3606. add_dwarf_attr (die, &attr);
  3607. }
  3608. /* Add a location description attribute value to a DIE. */
  3609. static inline void
  3610. add_AT_loc (dw_die_ref die, enum dwarf_attribute attr_kind, dw_loc_descr_ref loc)
  3611. {
  3612. dw_attr_node attr;
  3613. attr.dw_attr = attr_kind;
  3614. attr.dw_attr_val.val_class = dw_val_class_loc;
  3615. attr.dw_attr_val.val_entry = NULL;
  3616. attr.dw_attr_val.v.val_loc = loc;
  3617. add_dwarf_attr (die, &attr);
  3618. }
  3619. static inline dw_loc_descr_ref
  3620. AT_loc (dw_attr_ref a)
  3621. {
  3622. gcc_assert (a && AT_class (a) == dw_val_class_loc);
  3623. return a->dw_attr_val.v.val_loc;
  3624. }
  3625. static inline void
  3626. add_AT_loc_list (dw_die_ref die, enum dwarf_attribute attr_kind, dw_loc_list_ref loc_list)
  3627. {
  3628. dw_attr_node attr;
  3629. attr.dw_attr = attr_kind;
  3630. attr.dw_attr_val.val_class = dw_val_class_loc_list;
  3631. attr.dw_attr_val.val_entry = NULL;
  3632. attr.dw_attr_val.v.val_loc_list = loc_list;
  3633. add_dwarf_attr (die, &attr);
  3634. have_location_lists = true;
  3635. }
  3636. static inline dw_loc_list_ref
  3637. AT_loc_list (dw_attr_ref a)
  3638. {
  3639. gcc_assert (a && AT_class (a) == dw_val_class_loc_list);
  3640. return a->dw_attr_val.v.val_loc_list;
  3641. }
  3642. static inline dw_loc_list_ref *
  3643. AT_loc_list_ptr (dw_attr_ref a)
  3644. {
  3645. gcc_assert (a && AT_class (a) == dw_val_class_loc_list);
  3646. return &a->dw_attr_val.v.val_loc_list;
  3647. }
  3648. struct addr_hasher : ggc_hasher<addr_table_entry *>
  3649. {
  3650. static hashval_t hash (addr_table_entry *);
  3651. static bool equal (addr_table_entry *, addr_table_entry *);
  3652. };
  3653. /* Table of entries into the .debug_addr section. */
  3654. static GTY (()) hash_table<addr_hasher> *addr_index_table;
  3655. /* Hash an address_table_entry. */
  3656. hashval_t
  3657. addr_hasher::hash (addr_table_entry *a)
  3658. {
  3659. inchash::hash hstate;
  3660. switch (a->kind)
  3661. {
  3662. case ate_kind_rtx:
  3663. hstate.add_int (0);
  3664. break;
  3665. case ate_kind_rtx_dtprel:
  3666. hstate.add_int (1);
  3667. break;
  3668. case ate_kind_label:
  3669. return htab_hash_string (a->addr.label);
  3670. default:
  3671. gcc_unreachable ();
  3672. }
  3673. inchash::add_rtx (a->addr.rtl, hstate);
  3674. return hstate.end ();
  3675. }
  3676. /* Determine equality for two address_table_entries. */
  3677. bool
  3678. addr_hasher::equal (addr_table_entry *a1, addr_table_entry *a2)
  3679. {
  3680. if (a1->kind != a2->kind)
  3681. return 0;
  3682. switch (a1->kind)
  3683. {
  3684. case ate_kind_rtx:
  3685. case ate_kind_rtx_dtprel:
  3686. return rtx_equal_p (a1->addr.rtl, a2->addr.rtl);
  3687. case ate_kind_label:
  3688. return strcmp (a1->addr.label, a2->addr.label) == 0;
  3689. default:
  3690. gcc_unreachable ();
  3691. }
  3692. }
  3693. /* Initialize an addr_table_entry. */
  3694. void
  3695. init_addr_table_entry (addr_table_entry *e, enum ate_kind kind, void *addr)
  3696. {
  3697. e->kind = kind;
  3698. switch (kind)
  3699. {
  3700. case ate_kind_rtx:
  3701. case ate_kind_rtx_dtprel:
  3702. e->addr.rtl = (rtx) addr;
  3703. break;
  3704. case ate_kind_label:
  3705. e->addr.label = (char *) addr;
  3706. break;
  3707. }
  3708. e->refcount = 0;
  3709. e->index = NO_INDEX_ASSIGNED;
  3710. }
  3711. /* Add attr to the address table entry to the table. Defer setting an
  3712. index until output time. */
  3713. static addr_table_entry *
  3714. add_addr_table_entry (void *addr, enum ate_kind kind)
  3715. {
  3716. addr_table_entry *node;
  3717. addr_table_entry finder;
  3718. gcc_assert (dwarf_split_debug_info);
  3719. if (! addr_index_table)
  3720. addr_index_table = hash_table<addr_hasher>::create_ggc (10);
  3721. init_addr_table_entry (&finder, kind, addr);
  3722. addr_table_entry **slot = addr_index_table->find_slot (&finder, INSERT);
  3723. if (*slot == HTAB_EMPTY_ENTRY)
  3724. {
  3725. node = ggc_cleared_alloc<addr_table_entry> ();
  3726. init_addr_table_entry (node, kind, addr);
  3727. *slot = node;
  3728. }
  3729. else
  3730. node = *slot;
  3731. node->refcount++;
  3732. return node;
  3733. }
  3734. /* Remove an entry from the addr table by decrementing its refcount.
  3735. Strictly, decrementing the refcount would be enough, but the
  3736. assertion that the entry is actually in the table has found
  3737. bugs. */
  3738. static void
  3739. remove_addr_table_entry (addr_table_entry *entry)
  3740. {
  3741. gcc_assert (dwarf_split_debug_info && addr_index_table);
  3742. /* After an index is assigned, the table is frozen. */
  3743. gcc_assert (entry->refcount > 0 && entry->index == NO_INDEX_ASSIGNED);
  3744. entry->refcount--;
  3745. }
  3746. /* Given a location list, remove all addresses it refers to from the
  3747. address_table. */
  3748. static void
  3749. remove_loc_list_addr_table_entries (dw_loc_descr_ref descr)
  3750. {
  3751. for (; descr; descr = descr->dw_loc_next)
  3752. if (descr->dw_loc_oprnd1.val_entry != NULL)
  3753. {
  3754. gcc_assert (descr->dw_loc_oprnd1.val_entry->index == NO_INDEX_ASSIGNED);
  3755. remove_addr_table_entry (descr->dw_loc_oprnd1.val_entry);
  3756. }
  3757. }
  3758. /* A helper function for dwarf2out_finish called through
  3759. htab_traverse. Assign an addr_table_entry its index. All entries
  3760. must be collected into the table when this function is called,
  3761. because the indexing code relies on htab_traverse to traverse nodes
  3762. in the same order for each run. */
  3763. int
  3764. index_addr_table_entry (addr_table_entry **h, unsigned int *index)
  3765. {
  3766. addr_table_entry *node = *h;
  3767. /* Don't index unreferenced nodes. */
  3768. if (node->refcount == 0)
  3769. return 1;
  3770. gcc_assert (node->index == NO_INDEX_ASSIGNED);
  3771. node->index = *index;
  3772. *index += 1;
  3773. return 1;
  3774. }
  3775. /* Add an address constant attribute value to a DIE. When using
  3776. dwarf_split_debug_info, address attributes in dies destined for the
  3777. final executable should be direct references--setting the parameter
  3778. force_direct ensures this behavior. */
  3779. static inline void
  3780. add_AT_addr (dw_die_ref die, enum dwarf_attribute attr_kind, rtx addr,
  3781. bool force_direct)
  3782. {
  3783. dw_attr_node attr;
  3784. attr.dw_attr = attr_kind;
  3785. attr.dw_attr_val.val_class = dw_val_class_addr;
  3786. attr.dw_attr_val.v.val_addr = addr;
  3787. if (dwarf_split_debug_info && !force_direct)
  3788. attr.dw_attr_val.val_entry = add_addr_table_entry (addr, ate_kind_rtx);
  3789. else
  3790. attr.dw_attr_val.val_entry = NULL;
  3791. add_dwarf_attr (die, &attr);
  3792. }
  3793. /* Get the RTX from to an address DIE attribute. */
  3794. static inline rtx
  3795. AT_addr (dw_attr_ref a)
  3796. {
  3797. gcc_assert (a && AT_class (a) == dw_val_class_addr);
  3798. return a->dw_attr_val.v.val_addr;
  3799. }
  3800. /* Add a file attribute value to a DIE. */
  3801. static inline void
  3802. add_AT_file (dw_die_ref die, enum dwarf_attribute attr_kind,
  3803. struct dwarf_file_data *fd)
  3804. {
  3805. dw_attr_node attr;
  3806. attr.dw_attr = attr_kind;
  3807. attr.dw_attr_val.val_class = dw_val_class_file;
  3808. attr.dw_attr_val.val_entry = NULL;
  3809. attr.dw_attr_val.v.val_file = fd;
  3810. add_dwarf_attr (die, &attr);
  3811. }
  3812. /* Get the dwarf_file_data from a file DIE attribute. */
  3813. static inline struct dwarf_file_data *
  3814. AT_file (dw_attr_ref a)
  3815. {
  3816. gcc_assert (a && AT_class (a) == dw_val_class_file);
  3817. return a->dw_attr_val.v.val_file;
  3818. }
  3819. /* Add a vms delta attribute value to a DIE. */
  3820. static inline void
  3821. add_AT_vms_delta (dw_die_ref die, enum dwarf_attribute attr_kind,
  3822. const char *lbl1, const char *lbl2)
  3823. {
  3824. dw_attr_node attr;
  3825. attr.dw_attr = attr_kind;
  3826. attr.dw_attr_val.val_class = dw_val_class_vms_delta;
  3827. attr.dw_attr_val.val_entry = NULL;
  3828. attr.dw_attr_val.v.val_vms_delta.lbl1 = xstrdup (lbl1);
  3829. attr.dw_attr_val.v.val_vms_delta.lbl2 = xstrdup (lbl2);
  3830. add_dwarf_attr (die, &attr);
  3831. }
  3832. /* Add a label identifier attribute value to a DIE. */
  3833. static inline void
  3834. add_AT_lbl_id (dw_die_ref die, enum dwarf_attribute attr_kind,
  3835. const char *lbl_id)
  3836. {
  3837. dw_attr_node attr;
  3838. attr.dw_attr = attr_kind;
  3839. attr.dw_attr_val.val_class = dw_val_class_lbl_id;
  3840. attr.dw_attr_val.val_entry = NULL;
  3841. attr.dw_attr_val.v.val_lbl_id = xstrdup (lbl_id);
  3842. if (dwarf_split_debug_info)
  3843. attr.dw_attr_val.val_entry
  3844. = add_addr_table_entry (attr.dw_attr_val.v.val_lbl_id,
  3845. ate_kind_label);
  3846. add_dwarf_attr (die, &attr);
  3847. }
  3848. /* Add a section offset attribute value to a DIE, an offset into the
  3849. debug_line section. */
  3850. static inline void
  3851. add_AT_lineptr (dw_die_ref die, enum dwarf_attribute attr_kind,
  3852. const char *label)
  3853. {
  3854. dw_attr_node attr;
  3855. attr.dw_attr = attr_kind;
  3856. attr.dw_attr_val.val_class = dw_val_class_lineptr;
  3857. attr.dw_attr_val.val_entry = NULL;
  3858. attr.dw_attr_val.v.val_lbl_id = xstrdup (label);
  3859. add_dwarf_attr (die, &attr);
  3860. }
  3861. /* Add a section offset attribute value to a DIE, an offset into the
  3862. debug_macinfo section. */
  3863. static inline void
  3864. add_AT_macptr (dw_die_ref die, enum dwarf_attribute attr_kind,
  3865. const char *label)
  3866. {
  3867. dw_attr_node attr;
  3868. attr.dw_attr = attr_kind;
  3869. attr.dw_attr_val.val_class = dw_val_class_macptr;
  3870. attr.dw_attr_val.val_entry = NULL;
  3871. attr.dw_attr_val.v.val_lbl_id = xstrdup (label);
  3872. add_dwarf_attr (die, &attr);
  3873. }
  3874. /* Add an offset attribute value to a DIE. */
  3875. static inline void
  3876. add_AT_offset (dw_die_ref die, enum dwarf_attribute attr_kind,
  3877. unsigned HOST_WIDE_INT offset)
  3878. {
  3879. dw_attr_node attr;
  3880. attr.dw_attr = attr_kind;
  3881. attr.dw_attr_val.val_class = dw_val_class_offset;
  3882. attr.dw_attr_val.val_entry = NULL;
  3883. attr.dw_attr_val.v.val_offset = offset;
  3884. add_dwarf_attr (die, &attr);
  3885. }
  3886. /* Add a range_list attribute value to a DIE. When using
  3887. dwarf_split_debug_info, address attributes in dies destined for the
  3888. final executable should be direct references--setting the parameter
  3889. force_direct ensures this behavior. */
  3890. #define UNRELOCATED_OFFSET ((addr_table_entry *) 1)
  3891. #define RELOCATED_OFFSET (NULL)
  3892. static void
  3893. add_AT_range_list (dw_die_ref die, enum dwarf_attribute attr_kind,
  3894. long unsigned int offset, bool force_direct)
  3895. {
  3896. dw_attr_node attr;
  3897. attr.dw_attr = attr_kind;
  3898. attr.dw_attr_val.val_class = dw_val_class_range_list;
  3899. /* For the range_list attribute, use val_entry to store whether the
  3900. offset should follow split-debug-info or normal semantics. This
  3901. value is read in output_range_list_offset. */
  3902. if (dwarf_split_debug_info && !force_direct)
  3903. attr.dw_attr_val.val_entry = UNRELOCATED_OFFSET;
  3904. else
  3905. attr.dw_attr_val.val_entry = RELOCATED_OFFSET;
  3906. attr.dw_attr_val.v.val_offset = offset;
  3907. add_dwarf_attr (die, &attr);
  3908. }
  3909. /* Return the start label of a delta attribute. */
  3910. static inline const char *
  3911. AT_vms_delta1 (dw_attr_ref a)
  3912. {
  3913. gcc_assert (a && (AT_class (a) == dw_val_class_vms_delta));
  3914. return a->dw_attr_val.v.val_vms_delta.lbl1;
  3915. }
  3916. /* Return the end label of a delta attribute. */
  3917. static inline const char *
  3918. AT_vms_delta2 (dw_attr_ref a)
  3919. {
  3920. gcc_assert (a && (AT_class (a) == dw_val_class_vms_delta));
  3921. return a->dw_attr_val.v.val_vms_delta.lbl2;
  3922. }
  3923. static inline const char *
  3924. AT_lbl (dw_attr_ref a)
  3925. {
  3926. gcc_assert (a && (AT_class (a) == dw_val_class_lbl_id
  3927. || AT_class (a) == dw_val_class_lineptr
  3928. || AT_class (a) == dw_val_class_macptr
  3929. || AT_class (a) == dw_val_class_high_pc));
  3930. return a->dw_attr_val.v.val_lbl_id;
  3931. }
  3932. /* Get the attribute of type attr_kind. */
  3933. static dw_attr_ref
  3934. get_AT (dw_die_ref die, enum dwarf_attribute attr_kind)
  3935. {
  3936. dw_attr_ref a;
  3937. unsigned ix;
  3938. dw_die_ref spec = NULL;
  3939. if (! die)
  3940. return NULL;
  3941. FOR_EACH_VEC_SAFE_ELT (die->die_attr, ix, a)
  3942. if (a->dw_attr == attr_kind)
  3943. return a;
  3944. else if (a->dw_attr == DW_AT_specification
  3945. || a->dw_attr == DW_AT_abstract_origin)
  3946. spec = AT_ref (a);
  3947. if (spec)
  3948. return get_AT (spec, attr_kind);
  3949. return NULL;
  3950. }
  3951. /* Returns the parent of the declaration of DIE. */
  3952. static dw_die_ref
  3953. get_die_parent (dw_die_ref die)
  3954. {
  3955. dw_die_ref t;
  3956. if (!die)
  3957. return NULL;
  3958. if ((t = get_AT_ref (die, DW_AT_abstract_origin))
  3959. || (t = get_AT_ref (die, DW_AT_specification)))
  3960. die = t;
  3961. return die->die_parent;
  3962. }
  3963. /* Return the "low pc" attribute value, typically associated with a subprogram
  3964. DIE. Return null if the "low pc" attribute is either not present, or if it
  3965. cannot be represented as an assembler label identifier. */
  3966. static inline const char *
  3967. get_AT_low_pc (dw_die_ref die)
  3968. {
  3969. dw_attr_ref a = get_AT (die, DW_AT_low_pc);
  3970. return a ? AT_lbl (a) : NULL;
  3971. }
  3972. /* Return the "high pc" attribute value, typically associated with a subprogram
  3973. DIE. Return null if the "high pc" attribute is either not present, or if it
  3974. cannot be represented as an assembler label identifier. */
  3975. static inline const char *
  3976. get_AT_hi_pc (dw_die_ref die)
  3977. {
  3978. dw_attr_ref a = get_AT (die, DW_AT_high_pc);
  3979. return a ? AT_lbl (a) : NULL;
  3980. }
  3981. /* Return the value of the string attribute designated by ATTR_KIND, or
  3982. NULL if it is not present. */
  3983. static inline const char *
  3984. get_AT_string (dw_die_ref die, enum dwarf_attribute attr_kind)
  3985. {
  3986. dw_attr_ref a = get_AT (die, attr_kind);
  3987. return a ? AT_string (a) : NULL;
  3988. }
  3989. /* Return the value of the flag attribute designated by ATTR_KIND, or -1
  3990. if it is not present. */
  3991. static inline int
  3992. get_AT_flag (dw_die_ref die, enum dwarf_attribute attr_kind)
  3993. {
  3994. dw_attr_ref a = get_AT (die, attr_kind);
  3995. return a ? AT_flag (a) : 0;
  3996. }
  3997. /* Return the value of the unsigned attribute designated by ATTR_KIND, or 0
  3998. if it is not present. */
  3999. static inline unsigned
  4000. get_AT_unsigned (dw_die_ref die, enum dwarf_attribute attr_kind)
  4001. {
  4002. dw_attr_ref a = get_AT (die, attr_kind);
  4003. return a ? AT_unsigned (a) : 0;
  4004. }
  4005. static inline dw_die_ref
  4006. get_AT_ref (dw_die_ref die, enum dwarf_attribute attr_kind)
  4007. {
  4008. dw_attr_ref a = get_AT (die, attr_kind);
  4009. return a ? AT_ref (a) : NULL;
  4010. }
  4011. static inline struct dwarf_file_data *
  4012. get_AT_file (dw_die_ref die, enum dwarf_attribute attr_kind)
  4013. {
  4014. dw_attr_ref a = get_AT (die, attr_kind);
  4015. return a ? AT_file (a) : NULL;
  4016. }
  4017. /* Return TRUE if the language is C++. */
  4018. static inline bool
  4019. is_cxx (void)
  4020. {
  4021. unsigned int lang = get_AT_unsigned (comp_unit_die (), DW_AT_language);
  4022. return (lang == DW_LANG_C_plus_plus || lang == DW_LANG_ObjC_plus_plus
  4023. || lang == DW_LANG_C_plus_plus_11 || lang == DW_LANG_C_plus_plus_14);
  4024. }
  4025. /* Return TRUE if the language is Java. */
  4026. static inline bool
  4027. is_java (void)
  4028. {
  4029. unsigned int lang = get_AT_unsigned (comp_unit_die (), DW_AT_language);
  4030. return lang == DW_LANG_Java;
  4031. }
  4032. /* Return TRUE if the language is Fortran. */
  4033. static inline bool
  4034. is_fortran (void)
  4035. {
  4036. unsigned int lang = get_AT_unsigned (comp_unit_die (), DW_AT_language);
  4037. return (lang == DW_LANG_Fortran77
  4038. || lang == DW_LANG_Fortran90
  4039. || lang == DW_LANG_Fortran95
  4040. || lang == DW_LANG_Fortran03
  4041. || lang == DW_LANG_Fortran08);
  4042. }
  4043. /* Return TRUE if the language is Ada. */
  4044. static inline bool
  4045. is_ada (void)
  4046. {
  4047. unsigned int lang = get_AT_unsigned (comp_unit_die (), DW_AT_language);
  4048. return lang == DW_LANG_Ada95 || lang == DW_LANG_Ada83;
  4049. }
  4050. /* Remove the specified attribute if present. */
  4051. static void
  4052. remove_AT (dw_die_ref die, enum dwarf_attribute attr_kind)
  4053. {
  4054. dw_attr_ref a;
  4055. unsigned ix;
  4056. if (! die)
  4057. return;
  4058. FOR_EACH_VEC_SAFE_ELT (die->die_attr, ix, a)
  4059. if (a->dw_attr == attr_kind)
  4060. {
  4061. if (AT_class (a) == dw_val_class_str)
  4062. if (a->dw_attr_val.v.val_str->refcount)
  4063. a->dw_attr_val.v.val_str->refcount--;
  4064. /* vec::ordered_remove should help reduce the number of abbrevs
  4065. that are needed. */
  4066. die->die_attr->ordered_remove (ix);
  4067. return;
  4068. }
  4069. }
  4070. /* Remove CHILD from its parent. PREV must have the property that
  4071. PREV->DIE_SIB == CHILD. Does not alter CHILD. */
  4072. static void
  4073. remove_child_with_prev (dw_die_ref child, dw_die_ref prev)
  4074. {
  4075. gcc_assert (child->die_parent == prev->die_parent);
  4076. gcc_assert (prev->die_sib == child);
  4077. if (prev == child)
  4078. {
  4079. gcc_assert (child->die_parent->die_child == child);
  4080. prev = NULL;
  4081. }
  4082. else
  4083. prev->die_sib = child->die_sib;
  4084. if (child->die_parent->die_child == child)
  4085. child->die_parent->die_child = prev;
  4086. }
  4087. /* Replace OLD_CHILD with NEW_CHILD. PREV must have the property that
  4088. PREV->DIE_SIB == OLD_CHILD. Does not alter OLD_CHILD. */
  4089. static void
  4090. replace_child (dw_die_ref old_child, dw_die_ref new_child, dw_die_ref prev)
  4091. {
  4092. dw_die_ref parent = old_child->die_parent;
  4093. gcc_assert (parent == prev->die_parent);
  4094. gcc_assert (prev->die_sib == old_child);
  4095. new_child->die_parent = parent;
  4096. if (prev == old_child)
  4097. {
  4098. gcc_assert (parent->die_child == old_child);
  4099. new_child->die_sib = new_child;
  4100. }
  4101. else
  4102. {
  4103. prev->die_sib = new_child;
  4104. new_child->die_sib = old_child->die_sib;
  4105. }
  4106. if (old_child->die_parent->die_child == old_child)
  4107. old_child->die_parent->die_child = new_child;
  4108. }
  4109. /* Move all children from OLD_PARENT to NEW_PARENT. */
  4110. static void
  4111. move_all_children (dw_die_ref old_parent, dw_die_ref new_parent)
  4112. {
  4113. dw_die_ref c;
  4114. new_parent->die_child = old_parent->die_child;
  4115. old_parent->die_child = NULL;
  4116. FOR_EACH_CHILD (new_parent, c, c->die_parent = new_parent);
  4117. }
  4118. /* Remove child DIE whose die_tag is TAG. Do nothing if no child
  4119. matches TAG. */
  4120. static void
  4121. remove_child_TAG (dw_die_ref die, enum dwarf_tag tag)
  4122. {
  4123. dw_die_ref c;
  4124. c = die->die_child;
  4125. if (c) do {
  4126. dw_die_ref prev = c;
  4127. c = c->die_sib;
  4128. while (c->die_tag == tag)
  4129. {
  4130. remove_child_with_prev (c, prev);
  4131. /* Might have removed every child. */
  4132. if (c == c->die_sib)
  4133. return;
  4134. c = c->die_sib;
  4135. }
  4136. } while (c != die->die_child);
  4137. }
  4138. /* Add a CHILD_DIE as the last child of DIE. */
  4139. static void
  4140. add_child_die (dw_die_ref die, dw_die_ref child_die)
  4141. {
  4142. /* FIXME this should probably be an assert. */
  4143. if (! die || ! child_die)
  4144. return;
  4145. gcc_assert (die != child_die);
  4146. child_die->die_parent = die;
  4147. if (die->die_child)
  4148. {
  4149. child_die->die_sib = die->die_child->die_sib;
  4150. die->die_child->die_sib = child_die;
  4151. }
  4152. else
  4153. child_die->die_sib = child_die;
  4154. die->die_child = child_die;
  4155. }
  4156. /* Move CHILD, which must be a child of PARENT or the DIE for which PARENT
  4157. is the specification, to the end of PARENT's list of children.
  4158. This is done by removing and re-adding it. */
  4159. static void
  4160. splice_child_die (dw_die_ref parent, dw_die_ref child)
  4161. {
  4162. dw_die_ref p;
  4163. /* We want the declaration DIE from inside the class, not the
  4164. specification DIE at toplevel. */
  4165. if (child->die_parent != parent)
  4166. {
  4167. dw_die_ref tmp = get_AT_ref (child, DW_AT_specification);
  4168. if (tmp)
  4169. child = tmp;
  4170. }
  4171. gcc_assert (child->die_parent == parent
  4172. || (child->die_parent
  4173. == get_AT_ref (parent, DW_AT_specification)));
  4174. for (p = child->die_parent->die_child; ; p = p->die_sib)
  4175. if (p->die_sib == child)
  4176. {
  4177. remove_child_with_prev (child, p);
  4178. break;
  4179. }
  4180. add_child_die (parent, child);
  4181. }
  4182. /* Return a pointer to a newly created DIE node. */
  4183. static inline dw_die_ref
  4184. new_die (enum dwarf_tag tag_value, dw_die_ref parent_die, tree t)
  4185. {
  4186. dw_die_ref die = ggc_cleared_alloc<die_node> ();
  4187. die->die_tag = tag_value;
  4188. if (parent_die != NULL)
  4189. add_child_die (parent_die, die);
  4190. else
  4191. {
  4192. limbo_die_node *limbo_node;
  4193. limbo_node = ggc_cleared_alloc<limbo_die_node> ();
  4194. limbo_node->die = die;
  4195. limbo_node->created_for = t;
  4196. limbo_node->next = limbo_die_list;
  4197. limbo_die_list = limbo_node;
  4198. }
  4199. return die;
  4200. }
  4201. /* Return the DIE associated with the given type specifier. */
  4202. static inline dw_die_ref
  4203. lookup_type_die (tree type)
  4204. {
  4205. return TYPE_SYMTAB_DIE (type);
  4206. }
  4207. /* Given a TYPE_DIE representing the type TYPE, if TYPE is an
  4208. anonymous type named by the typedef TYPE_DIE, return the DIE of the
  4209. anonymous type instead the one of the naming typedef. */
  4210. static inline dw_die_ref
  4211. strip_naming_typedef (tree type, dw_die_ref type_die)
  4212. {
  4213. if (type
  4214. && TREE_CODE (type) == RECORD_TYPE
  4215. && type_die
  4216. && type_die->die_tag == DW_TAG_typedef
  4217. && is_naming_typedef_decl (TYPE_NAME (type)))
  4218. type_die = get_AT_ref (type_die, DW_AT_type);
  4219. return type_die;
  4220. }
  4221. /* Like lookup_type_die, but if type is an anonymous type named by a
  4222. typedef[1], return the DIE of the anonymous type instead the one of
  4223. the naming typedef. This is because in gen_typedef_die, we did
  4224. equate the anonymous struct named by the typedef with the DIE of
  4225. the naming typedef. So by default, lookup_type_die on an anonymous
  4226. struct yields the DIE of the naming typedef.
  4227. [1]: Read the comment of is_naming_typedef_decl to learn about what
  4228. a naming typedef is. */
  4229. static inline dw_die_ref
  4230. lookup_type_die_strip_naming_typedef (tree type)
  4231. {
  4232. dw_die_ref die = lookup_type_die (type);
  4233. return strip_naming_typedef (type, die);
  4234. }
  4235. /* Equate a DIE to a given type specifier. */
  4236. static inline void
  4237. equate_type_number_to_die (tree type, dw_die_ref type_die)
  4238. {
  4239. TYPE_SYMTAB_DIE (type) = type_die;
  4240. }
  4241. /* Returns a hash value for X (which really is a die_struct). */
  4242. inline hashval_t
  4243. decl_die_hasher::hash (die_node *x)
  4244. {
  4245. return (hashval_t) x->decl_id;
  4246. }
  4247. /* Return nonzero if decl_id of die_struct X is the same as UID of decl *Y. */
  4248. inline bool
  4249. decl_die_hasher::equal (die_node *x, tree y)
  4250. {
  4251. return (x->decl_id == DECL_UID (y));
  4252. }
  4253. /* Return the DIE associated with a given declaration. */
  4254. static inline dw_die_ref
  4255. lookup_decl_die (tree decl)
  4256. {
  4257. return decl_die_table->find_with_hash (decl, DECL_UID (decl));
  4258. }
  4259. /* Returns a hash value for X (which really is a var_loc_list). */
  4260. inline hashval_t
  4261. decl_loc_hasher::hash (var_loc_list *x)
  4262. {
  4263. return (hashval_t) x->decl_id;
  4264. }
  4265. /* Return nonzero if decl_id of var_loc_list X is the same as
  4266. UID of decl *Y. */
  4267. inline bool
  4268. decl_loc_hasher::equal (var_loc_list *x, const_tree y)
  4269. {
  4270. return (x->decl_id == DECL_UID (y));
  4271. }
  4272. /* Return the var_loc list associated with a given declaration. */
  4273. static inline var_loc_list *
  4274. lookup_decl_loc (const_tree decl)
  4275. {
  4276. if (!decl_loc_table)
  4277. return NULL;
  4278. return decl_loc_table->find_with_hash (decl, DECL_UID (decl));
  4279. }
  4280. /* Returns a hash value for X (which really is a cached_dw_loc_list_list). */
  4281. inline hashval_t
  4282. dw_loc_list_hasher::hash (cached_dw_loc_list *x)
  4283. {
  4284. return (hashval_t) x->decl_id;
  4285. }
  4286. /* Return nonzero if decl_id of cached_dw_loc_list X is the same as
  4287. UID of decl *Y. */
  4288. inline bool
  4289. dw_loc_list_hasher::equal (cached_dw_loc_list *x, const_tree y)
  4290. {
  4291. return (x->decl_id == DECL_UID (y));
  4292. }
  4293. /* Equate a DIE to a particular declaration. */
  4294. static void
  4295. equate_decl_number_to_die (tree decl, dw_die_ref decl_die)
  4296. {
  4297. unsigned int decl_id = DECL_UID (decl);
  4298. *decl_die_table->find_slot_with_hash (decl, decl_id, INSERT) = decl_die;
  4299. decl_die->decl_id = decl_id;
  4300. }
  4301. /* Return how many bits covers PIECE EXPR_LIST. */
  4302. static HOST_WIDE_INT
  4303. decl_piece_bitsize (rtx piece)
  4304. {
  4305. int ret = (int) GET_MODE (piece);
  4306. if (ret)
  4307. return ret;
  4308. gcc_assert (GET_CODE (XEXP (piece, 0)) == CONCAT
  4309. && CONST_INT_P (XEXP (XEXP (piece, 0), 0)));
  4310. return INTVAL (XEXP (XEXP (piece, 0), 0));
  4311. }
  4312. /* Return pointer to the location of location note in PIECE EXPR_LIST. */
  4313. static rtx *
  4314. decl_piece_varloc_ptr (rtx piece)
  4315. {
  4316. if ((int) GET_MODE (piece))
  4317. return &XEXP (piece, 0);
  4318. else
  4319. return &XEXP (XEXP (piece, 0), 1);
  4320. }
  4321. /* Create an EXPR_LIST for location note LOC_NOTE covering BITSIZE bits.
  4322. Next is the chain of following piece nodes. */
  4323. static rtx_expr_list *
  4324. decl_piece_node (rtx loc_note, HOST_WIDE_INT bitsize, rtx next)
  4325. {
  4326. if (bitsize > 0 && bitsize <= (int) MAX_MACHINE_MODE)
  4327. return alloc_EXPR_LIST (bitsize, loc_note, next);
  4328. else
  4329. return alloc_EXPR_LIST (0, gen_rtx_CONCAT (VOIDmode,
  4330. GEN_INT (bitsize),
  4331. loc_note), next);
  4332. }
  4333. /* Return rtx that should be stored into loc field for
  4334. LOC_NOTE and BITPOS/BITSIZE. */
  4335. static rtx
  4336. construct_piece_list (rtx loc_note, HOST_WIDE_INT bitpos,
  4337. HOST_WIDE_INT bitsize)
  4338. {
  4339. if (bitsize != -1)
  4340. {
  4341. loc_note = decl_piece_node (loc_note, bitsize, NULL_RTX);
  4342. if (bitpos != 0)
  4343. loc_note = decl_piece_node (NULL_RTX, bitpos, loc_note);
  4344. }
  4345. return loc_note;
  4346. }
  4347. /* This function either modifies location piece list *DEST in
  4348. place (if SRC and INNER is NULL), or copies location piece list
  4349. *SRC to *DEST while modifying it. Location BITPOS is modified
  4350. to contain LOC_NOTE, any pieces overlapping it are removed resp.
  4351. not copied and if needed some padding around it is added.
  4352. When modifying in place, DEST should point to EXPR_LIST where
  4353. earlier pieces cover PIECE_BITPOS bits, when copying SRC points
  4354. to the start of the whole list and INNER points to the EXPR_LIST
  4355. where earlier pieces cover PIECE_BITPOS bits. */
  4356. static void
  4357. adjust_piece_list (rtx *dest, rtx *src, rtx *inner,
  4358. HOST_WIDE_INT bitpos, HOST_WIDE_INT piece_bitpos,
  4359. HOST_WIDE_INT bitsize, rtx loc_note)
  4360. {
  4361. HOST_WIDE_INT diff;
  4362. bool copy = inner != NULL;
  4363. if (copy)
  4364. {
  4365. /* First copy all nodes preceding the current bitpos. */
  4366. while (src != inner)
  4367. {
  4368. *dest = decl_piece_node (*decl_piece_varloc_ptr (*src),
  4369. decl_piece_bitsize (*src), NULL_RTX);
  4370. dest = &XEXP (*dest, 1);
  4371. src = &XEXP (*src, 1);
  4372. }
  4373. }
  4374. /* Add padding if needed. */
  4375. if (bitpos != piece_bitpos)
  4376. {
  4377. *dest = decl_piece_node (NULL_RTX, bitpos - piece_bitpos,
  4378. copy ? NULL_RTX : *dest);
  4379. dest = &XEXP (*dest, 1);
  4380. }
  4381. else if (*dest && decl_piece_bitsize (*dest) == bitsize)
  4382. {
  4383. gcc_assert (!copy);
  4384. /* A piece with correct bitpos and bitsize already exist,
  4385. just update the location for it and return. */
  4386. *decl_piece_varloc_ptr (*dest) = loc_note;
  4387. return;
  4388. }
  4389. /* Add the piece that changed. */
  4390. *dest = decl_piece_node (loc_note, bitsize, copy ? NULL_RTX : *dest);
  4391. dest = &XEXP (*dest, 1);
  4392. /* Skip over pieces that overlap it. */
  4393. diff = bitpos - piece_bitpos + bitsize;
  4394. if (!copy)
  4395. src = dest;
  4396. while (diff > 0 && *src)
  4397. {
  4398. rtx piece = *src;
  4399. diff -= decl_piece_bitsize (piece);
  4400. if (copy)
  4401. src = &XEXP (piece, 1);
  4402. else
  4403. {
  4404. *src = XEXP (piece, 1);
  4405. free_EXPR_LIST_node (piece);
  4406. }
  4407. }
  4408. /* Add padding if needed. */
  4409. if (diff < 0 && *src)
  4410. {
  4411. if (!copy)
  4412. dest = src;
  4413. *dest = decl_piece_node (NULL_RTX, -diff, copy ? NULL_RTX : *dest);
  4414. dest = &XEXP (*dest, 1);
  4415. }
  4416. if (!copy)
  4417. return;
  4418. /* Finally copy all nodes following it. */
  4419. while (*src)
  4420. {
  4421. *dest = decl_piece_node (*decl_piece_varloc_ptr (*src),
  4422. decl_piece_bitsize (*src), NULL_RTX);
  4423. dest = &XEXP (*dest, 1);
  4424. src = &XEXP (*src, 1);
  4425. }
  4426. }
  4427. /* Add a variable location node to the linked list for DECL. */
  4428. static struct var_loc_node *
  4429. add_var_loc_to_decl (tree decl, rtx loc_note, const char *label)
  4430. {
  4431. unsigned int decl_id;
  4432. var_loc_list *temp;
  4433. struct var_loc_node *loc = NULL;
  4434. HOST_WIDE_INT bitsize = -1, bitpos = -1;
  4435. if (TREE_CODE (decl) == VAR_DECL
  4436. && DECL_HAS_DEBUG_EXPR_P (decl))
  4437. {
  4438. tree realdecl = DECL_DEBUG_EXPR (decl);
  4439. if (handled_component_p (realdecl)
  4440. || (TREE_CODE (realdecl) == MEM_REF
  4441. && TREE_CODE (TREE_OPERAND (realdecl, 0)) == ADDR_EXPR))
  4442. {
  4443. HOST_WIDE_INT maxsize;
  4444. tree innerdecl;
  4445. innerdecl
  4446. = get_ref_base_and_extent (realdecl, &bitpos, &bitsize, &maxsize);
  4447. if (!DECL_P (innerdecl)
  4448. || DECL_IGNORED_P (innerdecl)
  4449. || TREE_STATIC (innerdecl)
  4450. || bitsize <= 0
  4451. || bitpos + bitsize > 256
  4452. || bitsize != maxsize)
  4453. return NULL;
  4454. decl = innerdecl;
  4455. }
  4456. }
  4457. decl_id = DECL_UID (decl);
  4458. var_loc_list **slot
  4459. = decl_loc_table->find_slot_with_hash (decl, decl_id, INSERT);
  4460. if (*slot == NULL)
  4461. {
  4462. temp = ggc_cleared_alloc<var_loc_list> ();
  4463. temp->decl_id = decl_id;
  4464. *slot = temp;
  4465. }
  4466. else
  4467. temp = *slot;
  4468. /* For PARM_DECLs try to keep around the original incoming value,
  4469. even if that means we'll emit a zero-range .debug_loc entry. */
  4470. if (temp->last
  4471. && temp->first == temp->last
  4472. && TREE_CODE (decl) == PARM_DECL
  4473. && NOTE_P (temp->first->loc)
  4474. && NOTE_VAR_LOCATION_DECL (temp->first->loc) == decl
  4475. && DECL_INCOMING_RTL (decl)
  4476. && NOTE_VAR_LOCATION_LOC (temp->first->loc)
  4477. && GET_CODE (NOTE_VAR_LOCATION_LOC (temp->first->loc))
  4478. == GET_CODE (DECL_INCOMING_RTL (decl))
  4479. && prev_real_insn (temp->first->loc) == NULL_RTX
  4480. && (bitsize != -1
  4481. || !rtx_equal_p (NOTE_VAR_LOCATION_LOC (temp->first->loc),
  4482. NOTE_VAR_LOCATION_LOC (loc_note))
  4483. || (NOTE_VAR_LOCATION_STATUS (temp->first->loc)
  4484. != NOTE_VAR_LOCATION_STATUS (loc_note))))
  4485. {
  4486. loc = ggc_cleared_alloc<var_loc_node> ();
  4487. temp->first->next = loc;
  4488. temp->last = loc;
  4489. loc->loc = construct_piece_list (loc_note, bitpos, bitsize);
  4490. }
  4491. else if (temp->last)
  4492. {
  4493. struct var_loc_node *last = temp->last, *unused = NULL;
  4494. rtx *piece_loc = NULL, last_loc_note;
  4495. HOST_WIDE_INT piece_bitpos = 0;
  4496. if (last->next)
  4497. {
  4498. last = last->next;
  4499. gcc_assert (last->next == NULL);
  4500. }
  4501. if (bitsize != -1 && GET_CODE (last->loc) == EXPR_LIST)
  4502. {
  4503. piece_loc = &last->loc;
  4504. do
  4505. {
  4506. HOST_WIDE_INT cur_bitsize = decl_piece_bitsize (*piece_loc);
  4507. if (piece_bitpos + cur_bitsize > bitpos)
  4508. break;
  4509. piece_bitpos += cur_bitsize;
  4510. piece_loc = &XEXP (*piece_loc, 1);
  4511. }
  4512. while (*piece_loc);
  4513. }
  4514. /* TEMP->LAST here is either pointer to the last but one or
  4515. last element in the chained list, LAST is pointer to the
  4516. last element. */
  4517. if (label && strcmp (last->label, label) == 0)
  4518. {
  4519. /* For SRA optimized variables if there weren't any real
  4520. insns since last note, just modify the last node. */
  4521. if (piece_loc != NULL)
  4522. {
  4523. adjust_piece_list (piece_loc, NULL, NULL,
  4524. bitpos, piece_bitpos, bitsize, loc_note);
  4525. return NULL;
  4526. }
  4527. /* If the last note doesn't cover any instructions, remove it. */
  4528. if (temp->last != last)
  4529. {
  4530. temp->last->next = NULL;
  4531. unused = last;
  4532. last = temp->last;
  4533. gcc_assert (strcmp (last->label, label) != 0);
  4534. }
  4535. else
  4536. {
  4537. gcc_assert (temp->first == temp->last
  4538. || (temp->first->next == temp->last
  4539. && TREE_CODE (decl) == PARM_DECL));
  4540. memset (temp->last, '\0', sizeof (*temp->last));
  4541. temp->last->loc = construct_piece_list (loc_note, bitpos, bitsize);
  4542. return temp->last;
  4543. }
  4544. }
  4545. if (bitsize == -1 && NOTE_P (last->loc))
  4546. last_loc_note = last->loc;
  4547. else if (piece_loc != NULL
  4548. && *piece_loc != NULL_RTX
  4549. && piece_bitpos == bitpos
  4550. && decl_piece_bitsize (*piece_loc) == bitsize)
  4551. last_loc_note = *decl_piece_varloc_ptr (*piece_loc);
  4552. else
  4553. last_loc_note = NULL_RTX;
  4554. /* If the current location is the same as the end of the list,
  4555. and either both or neither of the locations is uninitialized,
  4556. we have nothing to do. */
  4557. if (last_loc_note == NULL_RTX
  4558. || (!rtx_equal_p (NOTE_VAR_LOCATION_LOC (last_loc_note),
  4559. NOTE_VAR_LOCATION_LOC (loc_note)))
  4560. || ((NOTE_VAR_LOCATION_STATUS (last_loc_note)
  4561. != NOTE_VAR_LOCATION_STATUS (loc_note))
  4562. && ((NOTE_VAR_LOCATION_STATUS (last_loc_note)
  4563. == VAR_INIT_STATUS_UNINITIALIZED)
  4564. || (NOTE_VAR_LOCATION_STATUS (loc_note)
  4565. == VAR_INIT_STATUS_UNINITIALIZED))))
  4566. {
  4567. /* Add LOC to the end of list and update LAST. If the last
  4568. element of the list has been removed above, reuse its
  4569. memory for the new node, otherwise allocate a new one. */
  4570. if (unused)
  4571. {
  4572. loc = unused;
  4573. memset (loc, '\0', sizeof (*loc));
  4574. }
  4575. else
  4576. loc = ggc_cleared_alloc<var_loc_node> ();
  4577. if (bitsize == -1 || piece_loc == NULL)
  4578. loc->loc = construct_piece_list (loc_note, bitpos, bitsize);
  4579. else
  4580. adjust_piece_list (&loc->loc, &last->loc, piece_loc,
  4581. bitpos, piece_bitpos, bitsize, loc_note);
  4582. last->next = loc;
  4583. /* Ensure TEMP->LAST will point either to the new last but one
  4584. element of the chain, or to the last element in it. */
  4585. if (last != temp->last)
  4586. temp->last = last;
  4587. }
  4588. else if (unused)
  4589. ggc_free (unused);
  4590. }
  4591. else
  4592. {
  4593. loc = ggc_cleared_alloc<var_loc_node> ();
  4594. temp->first = loc;
  4595. temp->last = loc;
  4596. loc->loc = construct_piece_list (loc_note, bitpos, bitsize);
  4597. }
  4598. return loc;
  4599. }
  4600. /* Keep track of the number of spaces used to indent the
  4601. output of the debugging routines that print the structure of
  4602. the DIE internal representation. */
  4603. static int print_indent;
  4604. /* Indent the line the number of spaces given by print_indent. */
  4605. static inline void
  4606. print_spaces (FILE *outfile)
  4607. {
  4608. fprintf (outfile, "%*s", print_indent, "");
  4609. }
  4610. /* Print a type signature in hex. */
  4611. static inline void
  4612. print_signature (FILE *outfile, char *sig)
  4613. {
  4614. int i;
  4615. for (i = 0; i < DWARF_TYPE_SIGNATURE_SIZE; i++)
  4616. fprintf (outfile, "%02x", sig[i] & 0xff);
  4617. }
  4618. static void print_loc_descr (dw_loc_descr_ref, FILE *);
  4619. /* Print the value associated to the VAL DWARF value node to OUTFILE. If
  4620. RECURSE, output location descriptor operations. */
  4621. static void
  4622. print_dw_val (dw_val_node *val, bool recurse, FILE *outfile)
  4623. {
  4624. switch (val->val_class)
  4625. {
  4626. case dw_val_class_addr:
  4627. fprintf (outfile, "address");
  4628. break;
  4629. case dw_val_class_offset:
  4630. fprintf (outfile, "offset");
  4631. break;
  4632. case dw_val_class_loc:
  4633. fprintf (outfile, "location descriptor");
  4634. if (val->v.val_loc == NULL)
  4635. fprintf (outfile, " -> <null>\n");
  4636. else if (recurse)
  4637. {
  4638. fprintf (outfile, ":\n");
  4639. print_indent += 4;
  4640. print_loc_descr (val->v.val_loc, outfile);
  4641. print_indent -= 4;
  4642. }
  4643. else
  4644. fprintf (outfile, " (%p)\n", (void *) val->v.val_loc);
  4645. break;
  4646. case dw_val_class_loc_list:
  4647. fprintf (outfile, "location list -> label:%s",
  4648. val->v.val_loc_list->ll_symbol);
  4649. break;
  4650. case dw_val_class_range_list:
  4651. fprintf (outfile, "range list");
  4652. break;
  4653. case dw_val_class_const:
  4654. fprintf (outfile, HOST_WIDE_INT_PRINT_DEC, val->v.val_int);
  4655. break;
  4656. case dw_val_class_unsigned_const:
  4657. fprintf (outfile, HOST_WIDE_INT_PRINT_UNSIGNED, val->v.val_unsigned);
  4658. break;
  4659. case dw_val_class_const_double:
  4660. fprintf (outfile, "constant ("HOST_WIDE_INT_PRINT_DEC","\
  4661. HOST_WIDE_INT_PRINT_UNSIGNED")",
  4662. val->v.val_double.high,
  4663. val->v.val_double.low);
  4664. break;
  4665. case dw_val_class_wide_int:
  4666. {
  4667. int i = val->v.val_wide->get_len ();
  4668. fprintf (outfile, "constant (");
  4669. gcc_assert (i > 0);
  4670. if (val->v.val_wide->elt (i - 1) == 0)
  4671. fprintf (outfile, "0x");
  4672. fprintf (outfile, HOST_WIDE_INT_PRINT_HEX,
  4673. val->v.val_wide->elt (--i));
  4674. while (--i >= 0)
  4675. fprintf (outfile, HOST_WIDE_INT_PRINT_PADDED_HEX,
  4676. val->v.val_wide->elt (i));
  4677. fprintf (outfile, ")");
  4678. break;
  4679. }
  4680. case dw_val_class_vec:
  4681. fprintf (outfile, "floating-point or vector constant");
  4682. break;
  4683. case dw_val_class_flag:
  4684. fprintf (outfile, "%u", val->v.val_flag);
  4685. break;
  4686. case dw_val_class_die_ref:
  4687. if (val->v.val_die_ref.die != NULL)
  4688. {
  4689. dw_die_ref die = val->v.val_die_ref.die;
  4690. if (die->comdat_type_p)
  4691. {
  4692. fprintf (outfile, "die -> signature: ");
  4693. print_signature (outfile,
  4694. die->die_id.die_type_node->signature);
  4695. }
  4696. else if (die->die_id.die_symbol)
  4697. fprintf (outfile, "die -> label: %s", die->die_id.die_symbol);
  4698. else
  4699. fprintf (outfile, "die -> %ld", die->die_offset);
  4700. fprintf (outfile, " (%p)", (void *) die);
  4701. }
  4702. else
  4703. fprintf (outfile, "die -> <null>");
  4704. break;
  4705. case dw_val_class_vms_delta:
  4706. fprintf (outfile, "delta: @slotcount(%s-%s)",
  4707. val->v.val_vms_delta.lbl2, val->v.val_vms_delta.lbl1);
  4708. break;
  4709. case dw_val_class_lbl_id:
  4710. case dw_val_class_lineptr:
  4711. case dw_val_class_macptr:
  4712. case dw_val_class_high_pc:
  4713. fprintf (outfile, "label: %s", val->v.val_lbl_id);
  4714. break;
  4715. case dw_val_class_str:
  4716. if (val->v.val_str->str != NULL)
  4717. fprintf (outfile, "\"%s\"", val->v.val_str->str);
  4718. else
  4719. fprintf (outfile, "<null>");
  4720. break;
  4721. case dw_val_class_file:
  4722. fprintf (outfile, "\"%s\" (%d)", val->v.val_file->filename,
  4723. val->v.val_file->emitted_number);
  4724. break;
  4725. case dw_val_class_data8:
  4726. {
  4727. int i;
  4728. for (i = 0; i < 8; i++)
  4729. fprintf (outfile, "%02x", val->v.val_data8[i]);
  4730. break;
  4731. }
  4732. default:
  4733. break;
  4734. }
  4735. }
  4736. /* Likewise, for a DIE attribute. */
  4737. static void
  4738. print_attribute (dw_attr_ref a, bool recurse, FILE *outfile)
  4739. {
  4740. print_dw_val (&a->dw_attr_val, recurse, outfile);
  4741. }
  4742. /* Print the list of operands in the LOC location description to OUTFILE. This
  4743. routine is a debugging aid only. */
  4744. static void
  4745. print_loc_descr (dw_loc_descr_ref loc, FILE *outfile)
  4746. {
  4747. dw_loc_descr_ref l = loc;
  4748. if (loc == NULL)
  4749. {
  4750. print_spaces (outfile);
  4751. fprintf (outfile, "<null>\n");
  4752. return;
  4753. }
  4754. for (l = loc; l != NULL; l = l->dw_loc_next)
  4755. {
  4756. print_spaces (outfile);
  4757. fprintf (outfile, "(%p) %s",
  4758. (void *) l,
  4759. dwarf_stack_op_name (l->dw_loc_opc));
  4760. if (l->dw_loc_oprnd1.val_class != dw_val_class_none)
  4761. {
  4762. fprintf (outfile, " ");
  4763. print_dw_val (&l->dw_loc_oprnd1, false, outfile);
  4764. }
  4765. if (l->dw_loc_oprnd2.val_class != dw_val_class_none)
  4766. {
  4767. fprintf (outfile, ", ");
  4768. print_dw_val (&l->dw_loc_oprnd2, false, outfile);
  4769. }
  4770. fprintf (outfile, "\n");
  4771. }
  4772. }
  4773. /* Print the information associated with a given DIE, and its children.
  4774. This routine is a debugging aid only. */
  4775. static void
  4776. print_die (dw_die_ref die, FILE *outfile)
  4777. {
  4778. dw_attr_ref a;
  4779. dw_die_ref c;
  4780. unsigned ix;
  4781. print_spaces (outfile);
  4782. fprintf (outfile, "DIE %4ld: %s (%p)\n",
  4783. die->die_offset, dwarf_tag_name (die->die_tag),
  4784. (void*) die);
  4785. print_spaces (outfile);
  4786. fprintf (outfile, " abbrev id: %lu", die->die_abbrev);
  4787. fprintf (outfile, " offset: %ld", die->die_offset);
  4788. fprintf (outfile, " mark: %d\n", die->die_mark);
  4789. if (die->comdat_type_p)
  4790. {
  4791. print_spaces (outfile);
  4792. fprintf (outfile, " signature: ");
  4793. print_signature (outfile, die->die_id.die_type_node->signature);
  4794. fprintf (outfile, "\n");
  4795. }
  4796. FOR_EACH_VEC_SAFE_ELT (die->die_attr, ix, a)
  4797. {
  4798. print_spaces (outfile);
  4799. fprintf (outfile, " %s: ", dwarf_attr_name (a->dw_attr));
  4800. print_attribute (a, true, outfile);
  4801. fprintf (outfile, "\n");
  4802. }
  4803. if (die->die_child != NULL)
  4804. {
  4805. print_indent += 4;
  4806. FOR_EACH_CHILD (die, c, print_die (c, outfile));
  4807. print_indent -= 4;
  4808. }
  4809. if (print_indent == 0)
  4810. fprintf (outfile, "\n");
  4811. }
  4812. /* Print the list of operations in the LOC location description. */
  4813. DEBUG_FUNCTION void
  4814. debug_dwarf_loc_descr (dw_loc_descr_ref loc)
  4815. {
  4816. print_loc_descr (loc, stderr);
  4817. }
  4818. /* Print the information collected for a given DIE. */
  4819. DEBUG_FUNCTION void
  4820. debug_dwarf_die (dw_die_ref die)
  4821. {
  4822. print_die (die, stderr);
  4823. }
  4824. DEBUG_FUNCTION void
  4825. debug (die_struct &ref)
  4826. {
  4827. print_die (&ref, stderr);
  4828. }
  4829. DEBUG_FUNCTION void
  4830. debug (die_struct *ptr)
  4831. {
  4832. if (ptr)
  4833. debug (*ptr);
  4834. else
  4835. fprintf (stderr, "<nil>\n");
  4836. }
  4837. /* Print all DWARF information collected for the compilation unit.
  4838. This routine is a debugging aid only. */
  4839. DEBUG_FUNCTION void
  4840. debug_dwarf (void)
  4841. {
  4842. print_indent = 0;
  4843. print_die (comp_unit_die (), stderr);
  4844. }
  4845. /* Start a new compilation unit DIE for an include file. OLD_UNIT is the CU
  4846. for the enclosing include file, if any. BINCL_DIE is the DW_TAG_GNU_BINCL
  4847. DIE that marks the start of the DIEs for this include file. */
  4848. static dw_die_ref
  4849. push_new_compile_unit (dw_die_ref old_unit, dw_die_ref bincl_die)
  4850. {
  4851. const char *filename = get_AT_string (bincl_die, DW_AT_name);
  4852. dw_die_ref new_unit = gen_compile_unit_die (filename);
  4853. new_unit->die_sib = old_unit;
  4854. return new_unit;
  4855. }
  4856. /* Close an include-file CU and reopen the enclosing one. */
  4857. static dw_die_ref
  4858. pop_compile_unit (dw_die_ref old_unit)
  4859. {
  4860. dw_die_ref new_unit = old_unit->die_sib;
  4861. old_unit->die_sib = NULL;
  4862. return new_unit;
  4863. }
  4864. #define CHECKSUM(FOO) md5_process_bytes (&(FOO), sizeof (FOO), ctx)
  4865. #define CHECKSUM_BLOCK(FOO, SIZE) md5_process_bytes ((FOO), (SIZE), ctx)
  4866. #define CHECKSUM_STRING(FOO) md5_process_bytes ((FOO), strlen (FOO), ctx)
  4867. /* Calculate the checksum of a location expression. */
  4868. static inline void
  4869. loc_checksum (dw_loc_descr_ref loc, struct md5_ctx *ctx)
  4870. {
  4871. int tem;
  4872. inchash::hash hstate;
  4873. hashval_t hash;
  4874. tem = (loc->dtprel << 8) | ((unsigned int) loc->dw_loc_opc);
  4875. CHECKSUM (tem);
  4876. hash_loc_operands (loc, hstate);
  4877. hash = hstate.end();
  4878. CHECKSUM (hash);
  4879. }
  4880. /* Calculate the checksum of an attribute. */
  4881. static void
  4882. attr_checksum (dw_attr_ref at, struct md5_ctx *ctx, int *mark)
  4883. {
  4884. dw_loc_descr_ref loc;
  4885. rtx r;
  4886. CHECKSUM (at->dw_attr);
  4887. /* We don't care that this was compiled with a different compiler
  4888. snapshot; if the output is the same, that's what matters. */
  4889. if (at->dw_attr == DW_AT_producer)
  4890. return;
  4891. switch (AT_class (at))
  4892. {
  4893. case dw_val_class_const:
  4894. CHECKSUM (at->dw_attr_val.v.val_int);
  4895. break;
  4896. case dw_val_class_unsigned_const:
  4897. CHECKSUM (at->dw_attr_val.v.val_unsigned);
  4898. break;
  4899. case dw_val_class_const_double:
  4900. CHECKSUM (at->dw_attr_val.v.val_double);
  4901. break;
  4902. case dw_val_class_wide_int:
  4903. CHECKSUM_BLOCK (at->dw_attr_val.v.val_wide->get_val (),
  4904. get_full_len (*at->dw_attr_val.v.val_wide)
  4905. * HOST_BITS_PER_WIDE_INT / HOST_BITS_PER_CHAR);
  4906. break;
  4907. case dw_val_class_vec:
  4908. CHECKSUM_BLOCK (at->dw_attr_val.v.val_vec.array,
  4909. (at->dw_attr_val.v.val_vec.length
  4910. * at->dw_attr_val.v.val_vec.elt_size));
  4911. break;
  4912. case dw_val_class_flag:
  4913. CHECKSUM (at->dw_attr_val.v.val_flag);
  4914. break;
  4915. case dw_val_class_str:
  4916. CHECKSUM_STRING (AT_string (at));
  4917. break;
  4918. case dw_val_class_addr:
  4919. r = AT_addr (at);
  4920. gcc_assert (GET_CODE (r) == SYMBOL_REF);
  4921. CHECKSUM_STRING (XSTR (r, 0));
  4922. break;
  4923. case dw_val_class_offset:
  4924. CHECKSUM (at->dw_attr_val.v.val_offset);
  4925. break;
  4926. case dw_val_class_loc:
  4927. for (loc = AT_loc (at); loc; loc = loc->dw_loc_next)
  4928. loc_checksum (loc, ctx);
  4929. break;
  4930. case dw_val_class_die_ref:
  4931. die_checksum (AT_ref (at), ctx, mark);
  4932. break;
  4933. case dw_val_class_fde_ref:
  4934. case dw_val_class_vms_delta:
  4935. case dw_val_class_lbl_id:
  4936. case dw_val_class_lineptr:
  4937. case dw_val_class_macptr:
  4938. case dw_val_class_high_pc:
  4939. break;
  4940. case dw_val_class_file:
  4941. CHECKSUM_STRING (AT_file (at)->filename);
  4942. break;
  4943. case dw_val_class_data8:
  4944. CHECKSUM (at->dw_attr_val.v.val_data8);
  4945. break;
  4946. default:
  4947. break;
  4948. }
  4949. }
  4950. /* Calculate the checksum of a DIE. */
  4951. static void
  4952. die_checksum (dw_die_ref die, struct md5_ctx *ctx, int *mark)
  4953. {
  4954. dw_die_ref c;
  4955. dw_attr_ref a;
  4956. unsigned ix;
  4957. /* To avoid infinite recursion. */
  4958. if (die->die_mark)
  4959. {
  4960. CHECKSUM (die->die_mark);
  4961. return;
  4962. }
  4963. die->die_mark = ++(*mark);
  4964. CHECKSUM (die->die_tag);
  4965. FOR_EACH_VEC_SAFE_ELT (die->die_attr, ix, a)
  4966. attr_checksum (a, ctx, mark);
  4967. FOR_EACH_CHILD (die, c, die_checksum (c, ctx, mark));
  4968. }
  4969. #undef CHECKSUM
  4970. #undef CHECKSUM_BLOCK
  4971. #undef CHECKSUM_STRING
  4972. /* For DWARF-4 types, include the trailing NULL when checksumming strings. */
  4973. #define CHECKSUM(FOO) md5_process_bytes (&(FOO), sizeof (FOO), ctx)
  4974. #define CHECKSUM_BLOCK(FOO, SIZE) md5_process_bytes ((FOO), (SIZE), ctx)
  4975. #define CHECKSUM_STRING(FOO) md5_process_bytes ((FOO), strlen (FOO) + 1, ctx)
  4976. #define CHECKSUM_SLEB128(FOO) checksum_sleb128 ((FOO), ctx)
  4977. #define CHECKSUM_ULEB128(FOO) checksum_uleb128 ((FOO), ctx)
  4978. #define CHECKSUM_ATTR(FOO) \
  4979. if (FOO) attr_checksum_ordered (die->die_tag, (FOO), ctx, mark)
  4980. /* Calculate the checksum of a number in signed LEB128 format. */
  4981. static void
  4982. checksum_sleb128 (HOST_WIDE_INT value, struct md5_ctx *ctx)
  4983. {
  4984. unsigned char byte;
  4985. bool more;
  4986. while (1)
  4987. {
  4988. byte = (value & 0x7f);
  4989. value >>= 7;
  4990. more = !((value == 0 && (byte & 0x40) == 0)
  4991. || (value == -1 && (byte & 0x40) != 0));
  4992. if (more)
  4993. byte |= 0x80;
  4994. CHECKSUM (byte);
  4995. if (!more)
  4996. break;
  4997. }
  4998. }
  4999. /* Calculate the checksum of a number in unsigned LEB128 format. */
  5000. static void
  5001. checksum_uleb128 (unsigned HOST_WIDE_INT value, struct md5_ctx *ctx)
  5002. {
  5003. while (1)
  5004. {
  5005. unsigned char byte = (value & 0x7f);
  5006. value >>= 7;
  5007. if (value != 0)
  5008. /* More bytes to follow. */
  5009. byte |= 0x80;
  5010. CHECKSUM (byte);
  5011. if (value == 0)
  5012. break;
  5013. }
  5014. }
  5015. /* Checksum the context of the DIE. This adds the names of any
  5016. surrounding namespaces or structures to the checksum. */
  5017. static void
  5018. checksum_die_context (dw_die_ref die, struct md5_ctx *ctx)
  5019. {
  5020. const char *name;
  5021. dw_die_ref spec;
  5022. int tag = die->die_tag;
  5023. if (tag != DW_TAG_namespace
  5024. && tag != DW_TAG_structure_type
  5025. && tag != DW_TAG_class_type)
  5026. return;
  5027. name = get_AT_string (die, DW_AT_name);
  5028. spec = get_AT_ref (die, DW_AT_specification);
  5029. if (spec != NULL)
  5030. die = spec;
  5031. if (die->die_parent != NULL)
  5032. checksum_die_context (die->die_parent, ctx);
  5033. CHECKSUM_ULEB128 ('C');
  5034. CHECKSUM_ULEB128 (tag);
  5035. if (name != NULL)
  5036. CHECKSUM_STRING (name);
  5037. }
  5038. /* Calculate the checksum of a location expression. */
  5039. static inline void
  5040. loc_checksum_ordered (dw_loc_descr_ref loc, struct md5_ctx *ctx)
  5041. {
  5042. /* Special case for lone DW_OP_plus_uconst: checksum as if the location
  5043. were emitted as a DW_FORM_sdata instead of a location expression. */
  5044. if (loc->dw_loc_opc == DW_OP_plus_uconst && loc->dw_loc_next == NULL)
  5045. {
  5046. CHECKSUM_ULEB128 (DW_FORM_sdata);
  5047. CHECKSUM_SLEB128 ((HOST_WIDE_INT) loc->dw_loc_oprnd1.v.val_unsigned);
  5048. return;
  5049. }
  5050. /* Otherwise, just checksum the raw location expression. */
  5051. while (loc != NULL)
  5052. {
  5053. inchash::hash hstate;
  5054. hashval_t hash;
  5055. CHECKSUM_ULEB128 (loc->dtprel);
  5056. CHECKSUM_ULEB128 (loc->dw_loc_opc);
  5057. hash_loc_operands (loc, hstate);
  5058. hash = hstate.end ();
  5059. CHECKSUM (hash);
  5060. loc = loc->dw_loc_next;
  5061. }
  5062. }
  5063. /* Calculate the checksum of an attribute. */
  5064. static void
  5065. attr_checksum_ordered (enum dwarf_tag tag, dw_attr_ref at,
  5066. struct md5_ctx *ctx, int *mark)
  5067. {
  5068. dw_loc_descr_ref loc;
  5069. rtx r;
  5070. if (AT_class (at) == dw_val_class_die_ref)
  5071. {
  5072. dw_die_ref target_die = AT_ref (at);
  5073. /* For pointer and reference types, we checksum only the (qualified)
  5074. name of the target type (if there is a name). For friend entries,
  5075. we checksum only the (qualified) name of the target type or function.
  5076. This allows the checksum to remain the same whether the target type
  5077. is complete or not. */
  5078. if ((at->dw_attr == DW_AT_type
  5079. && (tag == DW_TAG_pointer_type
  5080. || tag == DW_TAG_reference_type
  5081. || tag == DW_TAG_rvalue_reference_type
  5082. || tag == DW_TAG_ptr_to_member_type))
  5083. || (at->dw_attr == DW_AT_friend
  5084. && tag == DW_TAG_friend))
  5085. {
  5086. dw_attr_ref name_attr = get_AT (target_die, DW_AT_name);
  5087. if (name_attr != NULL)
  5088. {
  5089. dw_die_ref decl = get_AT_ref (target_die, DW_AT_specification);
  5090. if (decl == NULL)
  5091. decl = target_die;
  5092. CHECKSUM_ULEB128 ('N');
  5093. CHECKSUM_ULEB128 (at->dw_attr);
  5094. if (decl->die_parent != NULL)
  5095. checksum_die_context (decl->die_parent, ctx);
  5096. CHECKSUM_ULEB128 ('E');
  5097. CHECKSUM_STRING (AT_string (name_attr));
  5098. return;
  5099. }
  5100. }
  5101. /* For all other references to another DIE, we check to see if the
  5102. target DIE has already been visited. If it has, we emit a
  5103. backward reference; if not, we descend recursively. */
  5104. if (target_die->die_mark > 0)
  5105. {
  5106. CHECKSUM_ULEB128 ('R');
  5107. CHECKSUM_ULEB128 (at->dw_attr);
  5108. CHECKSUM_ULEB128 (target_die->die_mark);
  5109. }
  5110. else
  5111. {
  5112. dw_die_ref decl = get_AT_ref (target_die, DW_AT_specification);
  5113. if (decl == NULL)
  5114. decl = target_die;
  5115. target_die->die_mark = ++(*mark);
  5116. CHECKSUM_ULEB128 ('T');
  5117. CHECKSUM_ULEB128 (at->dw_attr);
  5118. if (decl->die_parent != NULL)
  5119. checksum_die_context (decl->die_parent, ctx);
  5120. die_checksum_ordered (target_die, ctx, mark);
  5121. }
  5122. return;
  5123. }
  5124. CHECKSUM_ULEB128 ('A');
  5125. CHECKSUM_ULEB128 (at->dw_attr);
  5126. switch (AT_class (at))
  5127. {
  5128. case dw_val_class_const:
  5129. CHECKSUM_ULEB128 (DW_FORM_sdata);
  5130. CHECKSUM_SLEB128 (at->dw_attr_val.v.val_int);
  5131. break;
  5132. case dw_val_class_unsigned_const:
  5133. CHECKSUM_ULEB128 (DW_FORM_sdata);
  5134. CHECKSUM_SLEB128 ((int) at->dw_attr_val.v.val_unsigned);
  5135. break;
  5136. case dw_val_class_const_double:
  5137. CHECKSUM_ULEB128 (DW_FORM_block);
  5138. CHECKSUM_ULEB128 (sizeof (at->dw_attr_val.v.val_double));
  5139. CHECKSUM (at->dw_attr_val.v.val_double);
  5140. break;
  5141. case dw_val_class_wide_int:
  5142. CHECKSUM_ULEB128 (DW_FORM_block);
  5143. CHECKSUM_ULEB128 (get_full_len (*at->dw_attr_val.v.val_wide)
  5144. * HOST_BITS_PER_WIDE_INT / BITS_PER_UNIT);
  5145. CHECKSUM_BLOCK (at->dw_attr_val.v.val_wide->get_val (),
  5146. get_full_len (*at->dw_attr_val.v.val_wide)
  5147. * HOST_BITS_PER_WIDE_INT / HOST_BITS_PER_CHAR);
  5148. break;
  5149. case dw_val_class_vec:
  5150. CHECKSUM_ULEB128 (DW_FORM_block);
  5151. CHECKSUM_ULEB128 (at->dw_attr_val.v.val_vec.length
  5152. * at->dw_attr_val.v.val_vec.elt_size);
  5153. CHECKSUM_BLOCK (at->dw_attr_val.v.val_vec.array,
  5154. (at->dw_attr_val.v.val_vec.length
  5155. * at->dw_attr_val.v.val_vec.elt_size));
  5156. break;
  5157. case dw_val_class_flag:
  5158. CHECKSUM_ULEB128 (DW_FORM_flag);
  5159. CHECKSUM_ULEB128 (at->dw_attr_val.v.val_flag ? 1 : 0);
  5160. break;
  5161. case dw_val_class_str:
  5162. CHECKSUM_ULEB128 (DW_FORM_string);
  5163. CHECKSUM_STRING (AT_string (at));
  5164. break;
  5165. case dw_val_class_addr:
  5166. r = AT_addr (at);
  5167. gcc_assert (GET_CODE (r) == SYMBOL_REF);
  5168. CHECKSUM_ULEB128 (DW_FORM_string);
  5169. CHECKSUM_STRING (XSTR (r, 0));
  5170. break;
  5171. case dw_val_class_offset:
  5172. CHECKSUM_ULEB128 (DW_FORM_sdata);
  5173. CHECKSUM_ULEB128 (at->dw_attr_val.v.val_offset);
  5174. break;
  5175. case dw_val_class_loc:
  5176. for (loc = AT_loc (at); loc; loc = loc->dw_loc_next)
  5177. loc_checksum_ordered (loc, ctx);
  5178. break;
  5179. case dw_val_class_fde_ref:
  5180. case dw_val_class_lbl_id:
  5181. case dw_val_class_lineptr:
  5182. case dw_val_class_macptr:
  5183. case dw_val_class_high_pc:
  5184. break;
  5185. case dw_val_class_file:
  5186. CHECKSUM_ULEB128 (DW_FORM_string);
  5187. CHECKSUM_STRING (AT_file (at)->filename);
  5188. break;
  5189. case dw_val_class_data8:
  5190. CHECKSUM (at->dw_attr_val.v.val_data8);
  5191. break;
  5192. default:
  5193. break;
  5194. }
  5195. }
  5196. struct checksum_attributes
  5197. {
  5198. dw_attr_ref at_name;
  5199. dw_attr_ref at_type;
  5200. dw_attr_ref at_friend;
  5201. dw_attr_ref at_accessibility;
  5202. dw_attr_ref at_address_class;
  5203. dw_attr_ref at_allocated;
  5204. dw_attr_ref at_artificial;
  5205. dw_attr_ref at_associated;
  5206. dw_attr_ref at_binary_scale;
  5207. dw_attr_ref at_bit_offset;
  5208. dw_attr_ref at_bit_size;
  5209. dw_attr_ref at_bit_stride;
  5210. dw_attr_ref at_byte_size;
  5211. dw_attr_ref at_byte_stride;
  5212. dw_attr_ref at_const_value;
  5213. dw_attr_ref at_containing_type;
  5214. dw_attr_ref at_count;
  5215. dw_attr_ref at_data_location;
  5216. dw_attr_ref at_data_member_location;
  5217. dw_attr_ref at_decimal_scale;
  5218. dw_attr_ref at_decimal_sign;
  5219. dw_attr_ref at_default_value;
  5220. dw_attr_ref at_digit_count;
  5221. dw_attr_ref at_discr;
  5222. dw_attr_ref at_discr_list;
  5223. dw_attr_ref at_discr_value;
  5224. dw_attr_ref at_encoding;
  5225. dw_attr_ref at_endianity;
  5226. dw_attr_ref at_explicit;
  5227. dw_attr_ref at_is_optional;
  5228. dw_attr_ref at_location;
  5229. dw_attr_ref at_lower_bound;
  5230. dw_attr_ref at_mutable;
  5231. dw_attr_ref at_ordering;
  5232. dw_attr_ref at_picture_string;
  5233. dw_attr_ref at_prototyped;
  5234. dw_attr_ref at_small;
  5235. dw_attr_ref at_segment;
  5236. dw_attr_ref at_string_length;
  5237. dw_attr_ref at_threads_scaled;
  5238. dw_attr_ref at_upper_bound;
  5239. dw_attr_ref at_use_location;
  5240. dw_attr_ref at_use_UTF8;
  5241. dw_attr_ref at_variable_parameter;
  5242. dw_attr_ref at_virtuality;
  5243. dw_attr_ref at_visibility;
  5244. dw_attr_ref at_vtable_elem_location;
  5245. };
  5246. /* Collect the attributes that we will want to use for the checksum. */
  5247. static void
  5248. collect_checksum_attributes (struct checksum_attributes *attrs, dw_die_ref die)
  5249. {
  5250. dw_attr_ref a;
  5251. unsigned ix;
  5252. FOR_EACH_VEC_SAFE_ELT (die->die_attr, ix, a)
  5253. {
  5254. switch (a->dw_attr)
  5255. {
  5256. case DW_AT_name:
  5257. attrs->at_name = a;
  5258. break;
  5259. case DW_AT_type:
  5260. attrs->at_type = a;
  5261. break;
  5262. case DW_AT_friend:
  5263. attrs->at_friend = a;
  5264. break;
  5265. case DW_AT_accessibility:
  5266. attrs->at_accessibility = a;
  5267. break;
  5268. case DW_AT_address_class:
  5269. attrs->at_address_class = a;
  5270. break;
  5271. case DW_AT_allocated:
  5272. attrs->at_allocated = a;
  5273. break;
  5274. case DW_AT_artificial:
  5275. attrs->at_artificial = a;
  5276. break;
  5277. case DW_AT_associated:
  5278. attrs->at_associated = a;
  5279. break;
  5280. case DW_AT_binary_scale:
  5281. attrs->at_binary_scale = a;
  5282. break;
  5283. case DW_AT_bit_offset:
  5284. attrs->at_bit_offset = a;
  5285. break;
  5286. case DW_AT_bit_size:
  5287. attrs->at_bit_size = a;
  5288. break;
  5289. case DW_AT_bit_stride:
  5290. attrs->at_bit_stride = a;
  5291. break;
  5292. case DW_AT_byte_size:
  5293. attrs->at_byte_size = a;
  5294. break;
  5295. case DW_AT_byte_stride:
  5296. attrs->at_byte_stride = a;
  5297. break;
  5298. case DW_AT_const_value:
  5299. attrs->at_const_value = a;
  5300. break;
  5301. case DW_AT_containing_type:
  5302. attrs->at_containing_type = a;
  5303. break;
  5304. case DW_AT_count:
  5305. attrs->at_count = a;
  5306. break;
  5307. case DW_AT_data_location:
  5308. attrs->at_data_location = a;
  5309. break;
  5310. case DW_AT_data_member_location:
  5311. attrs->at_data_member_location = a;
  5312. break;
  5313. case DW_AT_decimal_scale:
  5314. attrs->at_decimal_scale = a;
  5315. break;
  5316. case DW_AT_decimal_sign:
  5317. attrs->at_decimal_sign = a;
  5318. break;
  5319. case DW_AT_default_value:
  5320. attrs->at_default_value = a;
  5321. break;
  5322. case DW_AT_digit_count:
  5323. attrs->at_digit_count = a;
  5324. break;
  5325. case DW_AT_discr:
  5326. attrs->at_discr = a;
  5327. break;
  5328. case DW_AT_discr_list:
  5329. attrs->at_discr_list = a;
  5330. break;
  5331. case DW_AT_discr_value:
  5332. attrs->at_discr_value = a;
  5333. break;
  5334. case DW_AT_encoding:
  5335. attrs->at_encoding = a;
  5336. break;
  5337. case DW_AT_endianity:
  5338. attrs->at_endianity = a;
  5339. break;
  5340. case DW_AT_explicit:
  5341. attrs->at_explicit = a;
  5342. break;
  5343. case DW_AT_is_optional:
  5344. attrs->at_is_optional = a;
  5345. break;
  5346. case DW_AT_location:
  5347. attrs->at_location = a;
  5348. break;
  5349. case DW_AT_lower_bound:
  5350. attrs->at_lower_bound = a;
  5351. break;
  5352. case DW_AT_mutable:
  5353. attrs->at_mutable = a;
  5354. break;
  5355. case DW_AT_ordering:
  5356. attrs->at_ordering = a;
  5357. break;
  5358. case DW_AT_picture_string:
  5359. attrs->at_picture_string = a;
  5360. break;
  5361. case DW_AT_prototyped:
  5362. attrs->at_prototyped = a;
  5363. break;
  5364. case DW_AT_small:
  5365. attrs->at_small = a;
  5366. break;
  5367. case DW_AT_segment:
  5368. attrs->at_segment = a;
  5369. break;
  5370. case DW_AT_string_length:
  5371. attrs->at_string_length = a;
  5372. break;
  5373. case DW_AT_threads_scaled:
  5374. attrs->at_threads_scaled = a;
  5375. break;
  5376. case DW_AT_upper_bound:
  5377. attrs->at_upper_bound = a;
  5378. break;
  5379. case DW_AT_use_location:
  5380. attrs->at_use_location = a;
  5381. break;
  5382. case DW_AT_use_UTF8:
  5383. attrs->at_use_UTF8 = a;
  5384. break;
  5385. case DW_AT_variable_parameter:
  5386. attrs->at_variable_parameter = a;
  5387. break;
  5388. case DW_AT_virtuality:
  5389. attrs->at_virtuality = a;
  5390. break;
  5391. case DW_AT_visibility:
  5392. attrs->at_visibility = a;
  5393. break;
  5394. case DW_AT_vtable_elem_location:
  5395. attrs->at_vtable_elem_location = a;
  5396. break;
  5397. default:
  5398. break;
  5399. }
  5400. }
  5401. }
  5402. /* Calculate the checksum of a DIE, using an ordered subset of attributes. */
  5403. static void
  5404. die_checksum_ordered (dw_die_ref die, struct md5_ctx *ctx, int *mark)
  5405. {
  5406. dw_die_ref c;
  5407. dw_die_ref decl;
  5408. struct checksum_attributes attrs;
  5409. CHECKSUM_ULEB128 ('D');
  5410. CHECKSUM_ULEB128 (die->die_tag);
  5411. memset (&attrs, 0, sizeof (attrs));
  5412. decl = get_AT_ref (die, DW_AT_specification);
  5413. if (decl != NULL)
  5414. collect_checksum_attributes (&attrs, decl);
  5415. collect_checksum_attributes (&attrs, die);
  5416. CHECKSUM_ATTR (attrs.at_name);
  5417. CHECKSUM_ATTR (attrs.at_accessibility);
  5418. CHECKSUM_ATTR (attrs.at_address_class);
  5419. CHECKSUM_ATTR (attrs.at_allocated);
  5420. CHECKSUM_ATTR (attrs.at_artificial);
  5421. CHECKSUM_ATTR (attrs.at_associated);
  5422. CHECKSUM_ATTR (attrs.at_binary_scale);
  5423. CHECKSUM_ATTR (attrs.at_bit_offset);
  5424. CHECKSUM_ATTR (attrs.at_bit_size);
  5425. CHECKSUM_ATTR (attrs.at_bit_stride);
  5426. CHECKSUM_ATTR (attrs.at_byte_size);
  5427. CHECKSUM_ATTR (attrs.at_byte_stride);
  5428. CHECKSUM_ATTR (attrs.at_const_value);
  5429. CHECKSUM_ATTR (attrs.at_containing_type);
  5430. CHECKSUM_ATTR (attrs.at_count);
  5431. CHECKSUM_ATTR (attrs.at_data_location);
  5432. CHECKSUM_ATTR (attrs.at_data_member_location);
  5433. CHECKSUM_ATTR (attrs.at_decimal_scale);
  5434. CHECKSUM_ATTR (attrs.at_decimal_sign);
  5435. CHECKSUM_ATTR (attrs.at_default_value);
  5436. CHECKSUM_ATTR (attrs.at_digit_count);
  5437. CHECKSUM_ATTR (attrs.at_discr);
  5438. CHECKSUM_ATTR (attrs.at_discr_list);
  5439. CHECKSUM_ATTR (attrs.at_discr_value);
  5440. CHECKSUM_ATTR (attrs.at_encoding);
  5441. CHECKSUM_ATTR (attrs.at_endianity);
  5442. CHECKSUM_ATTR (attrs.at_explicit);
  5443. CHECKSUM_ATTR (attrs.at_is_optional);
  5444. CHECKSUM_ATTR (attrs.at_location);
  5445. CHECKSUM_ATTR (attrs.at_lower_bound);
  5446. CHECKSUM_ATTR (attrs.at_mutable);
  5447. CHECKSUM_ATTR (attrs.at_ordering);
  5448. CHECKSUM_ATTR (attrs.at_picture_string);
  5449. CHECKSUM_ATTR (attrs.at_prototyped);
  5450. CHECKSUM_ATTR (attrs.at_small);
  5451. CHECKSUM_ATTR (attrs.at_segment);
  5452. CHECKSUM_ATTR (attrs.at_string_length);
  5453. CHECKSUM_ATTR (attrs.at_threads_scaled);
  5454. CHECKSUM_ATTR (attrs.at_upper_bound);
  5455. CHECKSUM_ATTR (attrs.at_use_location);
  5456. CHECKSUM_ATTR (attrs.at_use_UTF8);
  5457. CHECKSUM_ATTR (attrs.at_variable_parameter);
  5458. CHECKSUM_ATTR (attrs.at_virtuality);
  5459. CHECKSUM_ATTR (attrs.at_visibility);
  5460. CHECKSUM_ATTR (attrs.at_vtable_elem_location);
  5461. CHECKSUM_ATTR (attrs.at_type);
  5462. CHECKSUM_ATTR (attrs.at_friend);
  5463. /* Checksum the child DIEs. */
  5464. c = die->die_child;
  5465. if (c) do {
  5466. dw_attr_ref name_attr;
  5467. c = c->die_sib;
  5468. name_attr = get_AT (c, DW_AT_name);
  5469. if (is_template_instantiation (c))
  5470. {
  5471. /* Ignore instantiations of member type and function templates. */
  5472. }
  5473. else if (name_attr != NULL
  5474. && (is_type_die (c) || c->die_tag == DW_TAG_subprogram))
  5475. {
  5476. /* Use a shallow checksum for named nested types and member
  5477. functions. */
  5478. CHECKSUM_ULEB128 ('S');
  5479. CHECKSUM_ULEB128 (c->die_tag);
  5480. CHECKSUM_STRING (AT_string (name_attr));
  5481. }
  5482. else
  5483. {
  5484. /* Use a deep checksum for other children. */
  5485. /* Mark this DIE so it gets processed when unmarking. */
  5486. if (c->die_mark == 0)
  5487. c->die_mark = -1;
  5488. die_checksum_ordered (c, ctx, mark);
  5489. }
  5490. } while (c != die->die_child);
  5491. CHECKSUM_ULEB128 (0);
  5492. }
  5493. /* Add a type name and tag to a hash. */
  5494. static void
  5495. die_odr_checksum (int tag, const char *name, md5_ctx *ctx)
  5496. {
  5497. CHECKSUM_ULEB128 (tag);
  5498. CHECKSUM_STRING (name);
  5499. }
  5500. #undef CHECKSUM
  5501. #undef CHECKSUM_STRING
  5502. #undef CHECKSUM_ATTR
  5503. #undef CHECKSUM_LEB128
  5504. #undef CHECKSUM_ULEB128
  5505. /* Generate the type signature for DIE. This is computed by generating an
  5506. MD5 checksum over the DIE's tag, its relevant attributes, and its
  5507. children. Attributes that are references to other DIEs are processed
  5508. by recursion, using the MARK field to prevent infinite recursion.
  5509. If the DIE is nested inside a namespace or another type, we also
  5510. need to include that context in the signature. The lower 64 bits
  5511. of the resulting MD5 checksum comprise the signature. */
  5512. static void
  5513. generate_type_signature (dw_die_ref die, comdat_type_node *type_node)
  5514. {
  5515. int mark;
  5516. const char *name;
  5517. unsigned char checksum[16];
  5518. struct md5_ctx ctx;
  5519. dw_die_ref decl;
  5520. dw_die_ref parent;
  5521. name = get_AT_string (die, DW_AT_name);
  5522. decl = get_AT_ref (die, DW_AT_specification);
  5523. parent = get_die_parent (die);
  5524. /* First, compute a signature for just the type name (and its surrounding
  5525. context, if any. This is stored in the type unit DIE for link-time
  5526. ODR (one-definition rule) checking. */
  5527. if (is_cxx () && name != NULL)
  5528. {
  5529. md5_init_ctx (&ctx);
  5530. /* Checksum the names of surrounding namespaces and structures. */
  5531. if (parent != NULL)
  5532. checksum_die_context (parent, &ctx);
  5533. /* Checksum the current DIE. */
  5534. die_odr_checksum (die->die_tag, name, &ctx);
  5535. md5_finish_ctx (&ctx, checksum);
  5536. add_AT_data8 (type_node->root_die, DW_AT_GNU_odr_signature, &checksum[8]);
  5537. }
  5538. /* Next, compute the complete type signature. */
  5539. md5_init_ctx (&ctx);
  5540. mark = 1;
  5541. die->die_mark = mark;
  5542. /* Checksum the names of surrounding namespaces and structures. */
  5543. if (parent != NULL)
  5544. checksum_die_context (parent, &ctx);
  5545. /* Checksum the DIE and its children. */
  5546. die_checksum_ordered (die, &ctx, &mark);
  5547. unmark_all_dies (die);
  5548. md5_finish_ctx (&ctx, checksum);
  5549. /* Store the signature in the type node and link the type DIE and the
  5550. type node together. */
  5551. memcpy (type_node->signature, &checksum[16 - DWARF_TYPE_SIGNATURE_SIZE],
  5552. DWARF_TYPE_SIGNATURE_SIZE);
  5553. die->comdat_type_p = true;
  5554. die->die_id.die_type_node = type_node;
  5555. type_node->type_die = die;
  5556. /* If the DIE is a specification, link its declaration to the type node
  5557. as well. */
  5558. if (decl != NULL)
  5559. {
  5560. decl->comdat_type_p = true;
  5561. decl->die_id.die_type_node = type_node;
  5562. }
  5563. }
  5564. /* Do the location expressions look same? */
  5565. static inline int
  5566. same_loc_p (dw_loc_descr_ref loc1, dw_loc_descr_ref loc2, int *mark)
  5567. {
  5568. return loc1->dw_loc_opc == loc2->dw_loc_opc
  5569. && same_dw_val_p (&loc1->dw_loc_oprnd1, &loc2->dw_loc_oprnd1, mark)
  5570. && same_dw_val_p (&loc1->dw_loc_oprnd2, &loc2->dw_loc_oprnd2, mark);
  5571. }
  5572. /* Do the values look the same? */
  5573. static int
  5574. same_dw_val_p (const dw_val_node *v1, const dw_val_node *v2, int *mark)
  5575. {
  5576. dw_loc_descr_ref loc1, loc2;
  5577. rtx r1, r2;
  5578. if (v1->val_class != v2->val_class)
  5579. return 0;
  5580. switch (v1->val_class)
  5581. {
  5582. case dw_val_class_const:
  5583. return v1->v.val_int == v2->v.val_int;
  5584. case dw_val_class_unsigned_const:
  5585. return v1->v.val_unsigned == v2->v.val_unsigned;
  5586. case dw_val_class_const_double:
  5587. return v1->v.val_double.high == v2->v.val_double.high
  5588. && v1->v.val_double.low == v2->v.val_double.low;
  5589. case dw_val_class_wide_int:
  5590. return *v1->v.val_wide == *v2->v.val_wide;
  5591. case dw_val_class_vec:
  5592. if (v1->v.val_vec.length != v2->v.val_vec.length
  5593. || v1->v.val_vec.elt_size != v2->v.val_vec.elt_size)
  5594. return 0;
  5595. if (memcmp (v1->v.val_vec.array, v2->v.val_vec.array,
  5596. v1->v.val_vec.length * v1->v.val_vec.elt_size))
  5597. return 0;
  5598. return 1;
  5599. case dw_val_class_flag:
  5600. return v1->v.val_flag == v2->v.val_flag;
  5601. case dw_val_class_str:
  5602. return !strcmp (v1->v.val_str->str, v2->v.val_str->str);
  5603. case dw_val_class_addr:
  5604. r1 = v1->v.val_addr;
  5605. r2 = v2->v.val_addr;
  5606. if (GET_CODE (r1) != GET_CODE (r2))
  5607. return 0;
  5608. return !rtx_equal_p (r1, r2);
  5609. case dw_val_class_offset:
  5610. return v1->v.val_offset == v2->v.val_offset;
  5611. case dw_val_class_loc:
  5612. for (loc1 = v1->v.val_loc, loc2 = v2->v.val_loc;
  5613. loc1 && loc2;
  5614. loc1 = loc1->dw_loc_next, loc2 = loc2->dw_loc_next)
  5615. if (!same_loc_p (loc1, loc2, mark))
  5616. return 0;
  5617. return !loc1 && !loc2;
  5618. case dw_val_class_die_ref:
  5619. return same_die_p (v1->v.val_die_ref.die, v2->v.val_die_ref.die, mark);
  5620. case dw_val_class_fde_ref:
  5621. case dw_val_class_vms_delta:
  5622. case dw_val_class_lbl_id:
  5623. case dw_val_class_lineptr:
  5624. case dw_val_class_macptr:
  5625. case dw_val_class_high_pc:
  5626. return 1;
  5627. case dw_val_class_file:
  5628. return v1->v.val_file == v2->v.val_file;
  5629. case dw_val_class_data8:
  5630. return !memcmp (v1->v.val_data8, v2->v.val_data8, 8);
  5631. default:
  5632. return 1;
  5633. }
  5634. }
  5635. /* Do the attributes look the same? */
  5636. static int
  5637. same_attr_p (dw_attr_ref at1, dw_attr_ref at2, int *mark)
  5638. {
  5639. if (at1->dw_attr != at2->dw_attr)
  5640. return 0;
  5641. /* We don't care that this was compiled with a different compiler
  5642. snapshot; if the output is the same, that's what matters. */
  5643. if (at1->dw_attr == DW_AT_producer)
  5644. return 1;
  5645. return same_dw_val_p (&at1->dw_attr_val, &at2->dw_attr_val, mark);
  5646. }
  5647. /* Do the dies look the same? */
  5648. static int
  5649. same_die_p (dw_die_ref die1, dw_die_ref die2, int *mark)
  5650. {
  5651. dw_die_ref c1, c2;
  5652. dw_attr_ref a1;
  5653. unsigned ix;
  5654. /* To avoid infinite recursion. */
  5655. if (die1->die_mark)
  5656. return die1->die_mark == die2->die_mark;
  5657. die1->die_mark = die2->die_mark = ++(*mark);
  5658. if (die1->die_tag != die2->die_tag)
  5659. return 0;
  5660. if (vec_safe_length (die1->die_attr) != vec_safe_length (die2->die_attr))
  5661. return 0;
  5662. FOR_EACH_VEC_SAFE_ELT (die1->die_attr, ix, a1)
  5663. if (!same_attr_p (a1, &(*die2->die_attr)[ix], mark))
  5664. return 0;
  5665. c1 = die1->die_child;
  5666. c2 = die2->die_child;
  5667. if (! c1)
  5668. {
  5669. if (c2)
  5670. return 0;
  5671. }
  5672. else
  5673. for (;;)
  5674. {
  5675. if (!same_die_p (c1, c2, mark))
  5676. return 0;
  5677. c1 = c1->die_sib;
  5678. c2 = c2->die_sib;
  5679. if (c1 == die1->die_child)
  5680. {
  5681. if (c2 == die2->die_child)
  5682. break;
  5683. else
  5684. return 0;
  5685. }
  5686. }
  5687. return 1;
  5688. }
  5689. /* Do the dies look the same? Wrapper around same_die_p. */
  5690. static int
  5691. same_die_p_wrap (dw_die_ref die1, dw_die_ref die2)
  5692. {
  5693. int mark = 0;
  5694. int ret = same_die_p (die1, die2, &mark);
  5695. unmark_all_dies (die1);
  5696. unmark_all_dies (die2);
  5697. return ret;
  5698. }
  5699. /* The prefix to attach to symbols on DIEs in the current comdat debug
  5700. info section. */
  5701. static const char *comdat_symbol_id;
  5702. /* The index of the current symbol within the current comdat CU. */
  5703. static unsigned int comdat_symbol_number;
  5704. /* Calculate the MD5 checksum of the compilation unit DIE UNIT_DIE and its
  5705. children, and set comdat_symbol_id accordingly. */
  5706. static void
  5707. compute_section_prefix (dw_die_ref unit_die)
  5708. {
  5709. const char *die_name = get_AT_string (unit_die, DW_AT_name);
  5710. const char *base = die_name ? lbasename (die_name) : "anonymous";
  5711. char *name = XALLOCAVEC (char, strlen (base) + 64);
  5712. char *p;
  5713. int i, mark;
  5714. unsigned char checksum[16];
  5715. struct md5_ctx ctx;
  5716. /* Compute the checksum of the DIE, then append part of it as hex digits to
  5717. the name filename of the unit. */
  5718. md5_init_ctx (&ctx);
  5719. mark = 0;
  5720. die_checksum (unit_die, &ctx, &mark);
  5721. unmark_all_dies (unit_die);
  5722. md5_finish_ctx (&ctx, checksum);
  5723. sprintf (name, "%s.", base);
  5724. clean_symbol_name (name);
  5725. p = name + strlen (name);
  5726. for (i = 0; i < 4; i++)
  5727. {
  5728. sprintf (p, "%.2x", checksum[i]);
  5729. p += 2;
  5730. }
  5731. comdat_symbol_id = unit_die->die_id.die_symbol = xstrdup (name);
  5732. comdat_symbol_number = 0;
  5733. }
  5734. /* Returns nonzero if DIE represents a type, in the sense of TYPE_P. */
  5735. static int
  5736. is_type_die (dw_die_ref die)
  5737. {
  5738. switch (die->die_tag)
  5739. {
  5740. case DW_TAG_array_type:
  5741. case DW_TAG_class_type:
  5742. case DW_TAG_interface_type:
  5743. case DW_TAG_enumeration_type:
  5744. case DW_TAG_pointer_type:
  5745. case DW_TAG_reference_type:
  5746. case DW_TAG_rvalue_reference_type:
  5747. case DW_TAG_string_type:
  5748. case DW_TAG_structure_type:
  5749. case DW_TAG_subroutine_type:
  5750. case DW_TAG_union_type:
  5751. case DW_TAG_ptr_to_member_type:
  5752. case DW_TAG_set_type:
  5753. case DW_TAG_subrange_type:
  5754. case DW_TAG_base_type:
  5755. case DW_TAG_const_type:
  5756. case DW_TAG_file_type:
  5757. case DW_TAG_packed_type:
  5758. case DW_TAG_volatile_type:
  5759. case DW_TAG_typedef:
  5760. return 1;
  5761. default:
  5762. return 0;
  5763. }
  5764. }
  5765. /* Returns 1 iff C is the sort of DIE that should go into a COMDAT CU.
  5766. Basically, we want to choose the bits that are likely to be shared between
  5767. compilations (types) and leave out the bits that are specific to individual
  5768. compilations (functions). */
  5769. static int
  5770. is_comdat_die (dw_die_ref c)
  5771. {
  5772. /* I think we want to leave base types and __vtbl_ptr_type in the main CU, as
  5773. we do for stabs. The advantage is a greater likelihood of sharing between
  5774. objects that don't include headers in the same order (and therefore would
  5775. put the base types in a different comdat). jason 8/28/00 */
  5776. if (c->die_tag == DW_TAG_base_type)
  5777. return 0;
  5778. if (c->die_tag == DW_TAG_pointer_type
  5779. || c->die_tag == DW_TAG_reference_type
  5780. || c->die_tag == DW_TAG_rvalue_reference_type
  5781. || c->die_tag == DW_TAG_const_type
  5782. || c->die_tag == DW_TAG_volatile_type)
  5783. {
  5784. dw_die_ref t = get_AT_ref (c, DW_AT_type);
  5785. return t ? is_comdat_die (t) : 0;
  5786. }
  5787. return is_type_die (c);
  5788. }
  5789. /* Returns 1 iff C is the sort of DIE that might be referred to from another
  5790. compilation unit. */
  5791. static int
  5792. is_symbol_die (dw_die_ref c)
  5793. {
  5794. return (is_type_die (c)
  5795. || is_declaration_die (c)
  5796. || c->die_tag == DW_TAG_namespace
  5797. || c->die_tag == DW_TAG_module);
  5798. }
  5799. /* Returns true iff C is a compile-unit DIE. */
  5800. static inline bool
  5801. is_cu_die (dw_die_ref c)
  5802. {
  5803. return c && c->die_tag == DW_TAG_compile_unit;
  5804. }
  5805. /* Returns true iff C is a unit DIE of some sort. */
  5806. static inline bool
  5807. is_unit_die (dw_die_ref c)
  5808. {
  5809. return c && (c->die_tag == DW_TAG_compile_unit
  5810. || c->die_tag == DW_TAG_partial_unit
  5811. || c->die_tag == DW_TAG_type_unit);
  5812. }
  5813. /* Returns true iff C is a namespace DIE. */
  5814. static inline bool
  5815. is_namespace_die (dw_die_ref c)
  5816. {
  5817. return c && c->die_tag == DW_TAG_namespace;
  5818. }
  5819. /* Returns true iff C is a class or structure DIE. */
  5820. static inline bool
  5821. is_class_die (dw_die_ref c)
  5822. {
  5823. return c && (c->die_tag == DW_TAG_class_type
  5824. || c->die_tag == DW_TAG_structure_type);
  5825. }
  5826. /* Return non-zero if this DIE is a template parameter. */
  5827. static inline bool
  5828. is_template_parameter (dw_die_ref die)
  5829. {
  5830. switch (die->die_tag)
  5831. {
  5832. case DW_TAG_template_type_param:
  5833. case DW_TAG_template_value_param:
  5834. case DW_TAG_GNU_template_template_param:
  5835. case DW_TAG_GNU_template_parameter_pack:
  5836. return true;
  5837. default:
  5838. return false;
  5839. }
  5840. }
  5841. /* Return non-zero if this DIE represents a template instantiation. */
  5842. static inline bool
  5843. is_template_instantiation (dw_die_ref die)
  5844. {
  5845. dw_die_ref c;
  5846. if (!is_type_die (die) && die->die_tag != DW_TAG_subprogram)
  5847. return false;
  5848. FOR_EACH_CHILD (die, c, if (is_template_parameter (c)) return true);
  5849. return false;
  5850. }
  5851. static char *
  5852. gen_internal_sym (const char *prefix)
  5853. {
  5854. char buf[256];
  5855. ASM_GENERATE_INTERNAL_LABEL (buf, prefix, label_num++);
  5856. return xstrdup (buf);
  5857. }
  5858. /* Assign symbols to all worthy DIEs under DIE. */
  5859. static void
  5860. assign_symbol_names (dw_die_ref die)
  5861. {
  5862. dw_die_ref c;
  5863. if (is_symbol_die (die) && !die->comdat_type_p)
  5864. {
  5865. if (comdat_symbol_id)
  5866. {
  5867. char *p = XALLOCAVEC (char, strlen (comdat_symbol_id) + 64);
  5868. sprintf (p, "%s.%s.%x", DIE_LABEL_PREFIX,
  5869. comdat_symbol_id, comdat_symbol_number++);
  5870. die->die_id.die_symbol = xstrdup (p);
  5871. }
  5872. else
  5873. die->die_id.die_symbol = gen_internal_sym ("LDIE");
  5874. }
  5875. FOR_EACH_CHILD (die, c, assign_symbol_names (c));
  5876. }
  5877. struct cu_hash_table_entry
  5878. {
  5879. dw_die_ref cu;
  5880. unsigned min_comdat_num, max_comdat_num;
  5881. struct cu_hash_table_entry *next;
  5882. };
  5883. /* Helpers to manipulate hash table of CUs. */
  5884. struct cu_hash_table_entry_hasher
  5885. {
  5886. typedef cu_hash_table_entry value_type;
  5887. typedef die_struct compare_type;
  5888. static inline hashval_t hash (const value_type *);
  5889. static inline bool equal (const value_type *, const compare_type *);
  5890. static inline void remove (value_type *);
  5891. };
  5892. inline hashval_t
  5893. cu_hash_table_entry_hasher::hash (const value_type *entry)
  5894. {
  5895. return htab_hash_string (entry->cu->die_id.die_symbol);
  5896. }
  5897. inline bool
  5898. cu_hash_table_entry_hasher::equal (const value_type *entry1,
  5899. const compare_type *entry2)
  5900. {
  5901. return !strcmp (entry1->cu->die_id.die_symbol, entry2->die_id.die_symbol);
  5902. }
  5903. inline void
  5904. cu_hash_table_entry_hasher::remove (value_type *entry)
  5905. {
  5906. struct cu_hash_table_entry *next;
  5907. while (entry)
  5908. {
  5909. next = entry->next;
  5910. free (entry);
  5911. entry = next;
  5912. }
  5913. }
  5914. typedef hash_table<cu_hash_table_entry_hasher> cu_hash_type;
  5915. /* Check whether we have already seen this CU and set up SYM_NUM
  5916. accordingly. */
  5917. static int
  5918. check_duplicate_cu (dw_die_ref cu, cu_hash_type *htable, unsigned int *sym_num)
  5919. {
  5920. struct cu_hash_table_entry dummy;
  5921. struct cu_hash_table_entry **slot, *entry, *last = &dummy;
  5922. dummy.max_comdat_num = 0;
  5923. slot = htable->find_slot_with_hash (cu,
  5924. htab_hash_string (cu->die_id.die_symbol),
  5925. INSERT);
  5926. entry = *slot;
  5927. for (; entry; last = entry, entry = entry->next)
  5928. {
  5929. if (same_die_p_wrap (cu, entry->cu))
  5930. break;
  5931. }
  5932. if (entry)
  5933. {
  5934. *sym_num = entry->min_comdat_num;
  5935. return 1;
  5936. }
  5937. entry = XCNEW (struct cu_hash_table_entry);
  5938. entry->cu = cu;
  5939. entry->min_comdat_num = *sym_num = last->max_comdat_num;
  5940. entry->next = *slot;
  5941. *slot = entry;
  5942. return 0;
  5943. }
  5944. /* Record SYM_NUM to record of CU in HTABLE. */
  5945. static void
  5946. record_comdat_symbol_number (dw_die_ref cu, cu_hash_type *htable,
  5947. unsigned int sym_num)
  5948. {
  5949. struct cu_hash_table_entry **slot, *entry;
  5950. slot = htable->find_slot_with_hash (cu,
  5951. htab_hash_string (cu->die_id.die_symbol),
  5952. NO_INSERT);
  5953. entry = *slot;
  5954. entry->max_comdat_num = sym_num;
  5955. }
  5956. /* Traverse the DIE (which is always comp_unit_die), and set up
  5957. additional compilation units for each of the include files we see
  5958. bracketed by BINCL/EINCL. */
  5959. static void
  5960. break_out_includes (dw_die_ref die)
  5961. {
  5962. dw_die_ref c;
  5963. dw_die_ref unit = NULL;
  5964. limbo_die_node *node, **pnode;
  5965. c = die->die_child;
  5966. if (c) do {
  5967. dw_die_ref prev = c;
  5968. c = c->die_sib;
  5969. while (c->die_tag == DW_TAG_GNU_BINCL || c->die_tag == DW_TAG_GNU_EINCL
  5970. || (unit && is_comdat_die (c)))
  5971. {
  5972. dw_die_ref next = c->die_sib;
  5973. /* This DIE is for a secondary CU; remove it from the main one. */
  5974. remove_child_with_prev (c, prev);
  5975. if (c->die_tag == DW_TAG_GNU_BINCL)
  5976. unit = push_new_compile_unit (unit, c);
  5977. else if (c->die_tag == DW_TAG_GNU_EINCL)
  5978. unit = pop_compile_unit (unit);
  5979. else
  5980. add_child_die (unit, c);
  5981. c = next;
  5982. if (c == die->die_child)
  5983. break;
  5984. }
  5985. } while (c != die->die_child);
  5986. #if 0
  5987. /* We can only use this in debugging, since the frontend doesn't check
  5988. to make sure that we leave every include file we enter. */
  5989. gcc_assert (!unit);
  5990. #endif
  5991. assign_symbol_names (die);
  5992. cu_hash_type cu_hash_table (10);
  5993. for (node = limbo_die_list, pnode = &limbo_die_list;
  5994. node;
  5995. node = node->next)
  5996. {
  5997. int is_dupl;
  5998. compute_section_prefix (node->die);
  5999. is_dupl = check_duplicate_cu (node->die, &cu_hash_table,
  6000. &comdat_symbol_number);
  6001. assign_symbol_names (node->die);
  6002. if (is_dupl)
  6003. *pnode = node->next;
  6004. else
  6005. {
  6006. pnode = &node->next;
  6007. record_comdat_symbol_number (node->die, &cu_hash_table,
  6008. comdat_symbol_number);
  6009. }
  6010. }
  6011. }
  6012. /* Return non-zero if this DIE is a declaration. */
  6013. static int
  6014. is_declaration_die (dw_die_ref die)
  6015. {
  6016. dw_attr_ref a;
  6017. unsigned ix;
  6018. FOR_EACH_VEC_SAFE_ELT (die->die_attr, ix, a)
  6019. if (a->dw_attr == DW_AT_declaration)
  6020. return 1;
  6021. return 0;
  6022. }
  6023. /* Return non-zero if this DIE is nested inside a subprogram. */
  6024. static int
  6025. is_nested_in_subprogram (dw_die_ref die)
  6026. {
  6027. dw_die_ref decl = get_AT_ref (die, DW_AT_specification);
  6028. if (decl == NULL)
  6029. decl = die;
  6030. return local_scope_p (decl);
  6031. }
  6032. /* Return non-zero if this DIE contains a defining declaration of a
  6033. subprogram. */
  6034. static int
  6035. contains_subprogram_definition (dw_die_ref die)
  6036. {
  6037. dw_die_ref c;
  6038. if (die->die_tag == DW_TAG_subprogram && ! is_declaration_die (die))
  6039. return 1;
  6040. FOR_EACH_CHILD (die, c, if (contains_subprogram_definition (c)) return 1);
  6041. return 0;
  6042. }
  6043. /* Return non-zero if this is a type DIE that should be moved to a
  6044. COMDAT .debug_types section. */
  6045. static int
  6046. should_move_die_to_comdat (dw_die_ref die)
  6047. {
  6048. switch (die->die_tag)
  6049. {
  6050. case DW_TAG_class_type:
  6051. case DW_TAG_structure_type:
  6052. case DW_TAG_enumeration_type:
  6053. case DW_TAG_union_type:
  6054. /* Don't move declarations, inlined instances, types nested in a
  6055. subprogram, or types that contain subprogram definitions. */
  6056. if (is_declaration_die (die)
  6057. || get_AT (die, DW_AT_abstract_origin)
  6058. || is_nested_in_subprogram (die)
  6059. || contains_subprogram_definition (die))
  6060. return 0;
  6061. return 1;
  6062. case DW_TAG_array_type:
  6063. case DW_TAG_interface_type:
  6064. case DW_TAG_pointer_type:
  6065. case DW_TAG_reference_type:
  6066. case DW_TAG_rvalue_reference_type:
  6067. case DW_TAG_string_type:
  6068. case DW_TAG_subroutine_type:
  6069. case DW_TAG_ptr_to_member_type:
  6070. case DW_TAG_set_type:
  6071. case DW_TAG_subrange_type:
  6072. case DW_TAG_base_type:
  6073. case DW_TAG_const_type:
  6074. case DW_TAG_file_type:
  6075. case DW_TAG_packed_type:
  6076. case DW_TAG_volatile_type:
  6077. case DW_TAG_typedef:
  6078. default:
  6079. return 0;
  6080. }
  6081. }
  6082. /* Make a clone of DIE. */
  6083. static dw_die_ref
  6084. clone_die (dw_die_ref die)
  6085. {
  6086. dw_die_ref clone;
  6087. dw_attr_ref a;
  6088. unsigned ix;
  6089. clone = ggc_cleared_alloc<die_node> ();
  6090. clone->die_tag = die->die_tag;
  6091. FOR_EACH_VEC_SAFE_ELT (die->die_attr, ix, a)
  6092. add_dwarf_attr (clone, a);
  6093. return clone;
  6094. }
  6095. /* Make a clone of the tree rooted at DIE. */
  6096. static dw_die_ref
  6097. clone_tree (dw_die_ref die)
  6098. {
  6099. dw_die_ref c;
  6100. dw_die_ref clone = clone_die (die);
  6101. FOR_EACH_CHILD (die, c, add_child_die (clone, clone_tree (c)));
  6102. return clone;
  6103. }
  6104. /* Make a clone of DIE as a declaration. */
  6105. static dw_die_ref
  6106. clone_as_declaration (dw_die_ref die)
  6107. {
  6108. dw_die_ref clone;
  6109. dw_die_ref decl;
  6110. dw_attr_ref a;
  6111. unsigned ix;
  6112. /* If the DIE is already a declaration, just clone it. */
  6113. if (is_declaration_die (die))
  6114. return clone_die (die);
  6115. /* If the DIE is a specification, just clone its declaration DIE. */
  6116. decl = get_AT_ref (die, DW_AT_specification);
  6117. if (decl != NULL)
  6118. {
  6119. clone = clone_die (decl);
  6120. if (die->comdat_type_p)
  6121. add_AT_die_ref (clone, DW_AT_signature, die);
  6122. return clone;
  6123. }
  6124. clone = ggc_cleared_alloc<die_node> ();
  6125. clone->die_tag = die->die_tag;
  6126. FOR_EACH_VEC_SAFE_ELT (die->die_attr, ix, a)
  6127. {
  6128. /* We don't want to copy over all attributes.
  6129. For example we don't want DW_AT_byte_size because otherwise we will no
  6130. longer have a declaration and GDB will treat it as a definition. */
  6131. switch (a->dw_attr)
  6132. {
  6133. case DW_AT_abstract_origin:
  6134. case DW_AT_artificial:
  6135. case DW_AT_containing_type:
  6136. case DW_AT_external:
  6137. case DW_AT_name:
  6138. case DW_AT_type:
  6139. case DW_AT_virtuality:
  6140. case DW_AT_linkage_name:
  6141. case DW_AT_MIPS_linkage_name:
  6142. add_dwarf_attr (clone, a);
  6143. break;
  6144. case DW_AT_byte_size:
  6145. default:
  6146. break;
  6147. }
  6148. }
  6149. if (die->comdat_type_p)
  6150. add_AT_die_ref (clone, DW_AT_signature, die);
  6151. add_AT_flag (clone, DW_AT_declaration, 1);
  6152. return clone;
  6153. }
  6154. /* Structure to map a DIE in one CU to its copy in a comdat type unit. */
  6155. struct decl_table_entry
  6156. {
  6157. dw_die_ref orig;
  6158. dw_die_ref copy;
  6159. };
  6160. /* Helpers to manipulate hash table of copied declarations. */
  6161. /* Hashtable helpers. */
  6162. struct decl_table_entry_hasher : typed_free_remove <decl_table_entry>
  6163. {
  6164. typedef decl_table_entry value_type;
  6165. typedef die_struct compare_type;
  6166. static inline hashval_t hash (const value_type *);
  6167. static inline bool equal (const value_type *, const compare_type *);
  6168. };
  6169. inline hashval_t
  6170. decl_table_entry_hasher::hash (const value_type *entry)
  6171. {
  6172. return htab_hash_pointer (entry->orig);
  6173. }
  6174. inline bool
  6175. decl_table_entry_hasher::equal (const value_type *entry1,
  6176. const compare_type *entry2)
  6177. {
  6178. return entry1->orig == entry2;
  6179. }
  6180. typedef hash_table<decl_table_entry_hasher> decl_hash_type;
  6181. /* Copy DIE and its ancestors, up to, but not including, the compile unit
  6182. or type unit entry, to a new tree. Adds the new tree to UNIT and returns
  6183. a pointer to the copy of DIE. If DECL_TABLE is provided, it is used
  6184. to check if the ancestor has already been copied into UNIT. */
  6185. static dw_die_ref
  6186. copy_ancestor_tree (dw_die_ref unit, dw_die_ref die,
  6187. decl_hash_type *decl_table)
  6188. {
  6189. dw_die_ref parent = die->die_parent;
  6190. dw_die_ref new_parent = unit;
  6191. dw_die_ref copy;
  6192. decl_table_entry **slot = NULL;
  6193. struct decl_table_entry *entry = NULL;
  6194. if (decl_table)
  6195. {
  6196. /* Check if the entry has already been copied to UNIT. */
  6197. slot = decl_table->find_slot_with_hash (die, htab_hash_pointer (die),
  6198. INSERT);
  6199. if (*slot != HTAB_EMPTY_ENTRY)
  6200. {
  6201. entry = *slot;
  6202. return entry->copy;
  6203. }
  6204. /* Record in DECL_TABLE that DIE has been copied to UNIT. */
  6205. entry = XCNEW (struct decl_table_entry);
  6206. entry->orig = die;
  6207. entry->copy = NULL;
  6208. *slot = entry;
  6209. }
  6210. if (parent != NULL)
  6211. {
  6212. dw_die_ref spec = get_AT_ref (parent, DW_AT_specification);
  6213. if (spec != NULL)
  6214. parent = spec;
  6215. if (!is_unit_die (parent))
  6216. new_parent = copy_ancestor_tree (unit, parent, decl_table);
  6217. }
  6218. copy = clone_as_declaration (die);
  6219. add_child_die (new_parent, copy);
  6220. if (decl_table)
  6221. {
  6222. /* Record the pointer to the copy. */
  6223. entry->copy = copy;
  6224. }
  6225. return copy;
  6226. }
  6227. /* Copy the declaration context to the new type unit DIE. This includes
  6228. any surrounding namespace or type declarations. If the DIE has an
  6229. AT_specification attribute, it also includes attributes and children
  6230. attached to the specification, and returns a pointer to the original
  6231. parent of the declaration DIE. Returns NULL otherwise. */
  6232. static dw_die_ref
  6233. copy_declaration_context (dw_die_ref unit, dw_die_ref die)
  6234. {
  6235. dw_die_ref decl;
  6236. dw_die_ref new_decl;
  6237. dw_die_ref orig_parent = NULL;
  6238. decl = get_AT_ref (die, DW_AT_specification);
  6239. if (decl == NULL)
  6240. decl = die;
  6241. else
  6242. {
  6243. unsigned ix;
  6244. dw_die_ref c;
  6245. dw_attr_ref a;
  6246. /* The original DIE will be changed to a declaration, and must
  6247. be moved to be a child of the original declaration DIE. */
  6248. orig_parent = decl->die_parent;
  6249. /* Copy the type node pointer from the new DIE to the original
  6250. declaration DIE so we can forward references later. */
  6251. decl->comdat_type_p = true;
  6252. decl->die_id.die_type_node = die->die_id.die_type_node;
  6253. remove_AT (die, DW_AT_specification);
  6254. FOR_EACH_VEC_SAFE_ELT (decl->die_attr, ix, a)
  6255. {
  6256. if (a->dw_attr != DW_AT_name
  6257. && a->dw_attr != DW_AT_declaration
  6258. && a->dw_attr != DW_AT_external)
  6259. add_dwarf_attr (die, a);
  6260. }
  6261. FOR_EACH_CHILD (decl, c, add_child_die (die, clone_tree (c)));
  6262. }
  6263. if (decl->die_parent != NULL
  6264. && !is_unit_die (decl->die_parent))
  6265. {
  6266. new_decl = copy_ancestor_tree (unit, decl, NULL);
  6267. if (new_decl != NULL)
  6268. {
  6269. remove_AT (new_decl, DW_AT_signature);
  6270. add_AT_specification (die, new_decl);
  6271. }
  6272. }
  6273. return orig_parent;
  6274. }
  6275. /* Generate the skeleton ancestor tree for the given NODE, then clone
  6276. the DIE and add the clone into the tree. */
  6277. static void
  6278. generate_skeleton_ancestor_tree (skeleton_chain_node *node)
  6279. {
  6280. if (node->new_die != NULL)
  6281. return;
  6282. node->new_die = clone_as_declaration (node->old_die);
  6283. if (node->parent != NULL)
  6284. {
  6285. generate_skeleton_ancestor_tree (node->parent);
  6286. add_child_die (node->parent->new_die, node->new_die);
  6287. }
  6288. }
  6289. /* Generate a skeleton tree of DIEs containing any declarations that are
  6290. found in the original tree. We traverse the tree looking for declaration
  6291. DIEs, and construct the skeleton from the bottom up whenever we find one. */
  6292. static void
  6293. generate_skeleton_bottom_up (skeleton_chain_node *parent)
  6294. {
  6295. skeleton_chain_node node;
  6296. dw_die_ref c;
  6297. dw_die_ref first;
  6298. dw_die_ref prev = NULL;
  6299. dw_die_ref next = NULL;
  6300. node.parent = parent;
  6301. first = c = parent->old_die->die_child;
  6302. if (c)
  6303. next = c->die_sib;
  6304. if (c) do {
  6305. if (prev == NULL || prev->die_sib == c)
  6306. prev = c;
  6307. c = next;
  6308. next = (c == first ? NULL : c->die_sib);
  6309. node.old_die = c;
  6310. node.new_die = NULL;
  6311. if (is_declaration_die (c))
  6312. {
  6313. if (is_template_instantiation (c))
  6314. {
  6315. /* Instantiated templates do not need to be cloned into the
  6316. type unit. Just move the DIE and its children back to
  6317. the skeleton tree (in the main CU). */
  6318. remove_child_with_prev (c, prev);
  6319. add_child_die (parent->new_die, c);
  6320. c = prev;
  6321. }
  6322. else
  6323. {
  6324. /* Clone the existing DIE, move the original to the skeleton
  6325. tree (which is in the main CU), and put the clone, with
  6326. all the original's children, where the original came from
  6327. (which is about to be moved to the type unit). */
  6328. dw_die_ref clone = clone_die (c);
  6329. move_all_children (c, clone);
  6330. /* If the original has a DW_AT_object_pointer attribute,
  6331. it would now point to a child DIE just moved to the
  6332. cloned tree, so we need to remove that attribute from
  6333. the original. */
  6334. remove_AT (c, DW_AT_object_pointer);
  6335. replace_child (c, clone, prev);
  6336. generate_skeleton_ancestor_tree (parent);
  6337. add_child_die (parent->new_die, c);
  6338. node.new_die = c;
  6339. c = clone;
  6340. }
  6341. }
  6342. generate_skeleton_bottom_up (&node);
  6343. } while (next != NULL);
  6344. }
  6345. /* Wrapper function for generate_skeleton_bottom_up. */
  6346. static dw_die_ref
  6347. generate_skeleton (dw_die_ref die)
  6348. {
  6349. skeleton_chain_node node;
  6350. node.old_die = die;
  6351. node.new_die = NULL;
  6352. node.parent = NULL;
  6353. /* If this type definition is nested inside another type,
  6354. and is not an instantiation of a template, always leave
  6355. at least a declaration in its place. */
  6356. if (die->die_parent != NULL
  6357. && is_type_die (die->die_parent)
  6358. && !is_template_instantiation (die))
  6359. node.new_die = clone_as_declaration (die);
  6360. generate_skeleton_bottom_up (&node);
  6361. return node.new_die;
  6362. }
  6363. /* Remove the CHILD DIE from its parent, possibly replacing it with a cloned
  6364. declaration. The original DIE is moved to a new compile unit so that
  6365. existing references to it follow it to the new location. If any of the
  6366. original DIE's descendants is a declaration, we need to replace the
  6367. original DIE with a skeleton tree and move the declarations back into the
  6368. skeleton tree. */
  6369. static dw_die_ref
  6370. remove_child_or_replace_with_skeleton (dw_die_ref unit, dw_die_ref child,
  6371. dw_die_ref prev)
  6372. {
  6373. dw_die_ref skeleton, orig_parent;
  6374. /* Copy the declaration context to the type unit DIE. If the returned
  6375. ORIG_PARENT is not NULL, the skeleton needs to be added as a child of
  6376. that DIE. */
  6377. orig_parent = copy_declaration_context (unit, child);
  6378. skeleton = generate_skeleton (child);
  6379. if (skeleton == NULL)
  6380. remove_child_with_prev (child, prev);
  6381. else
  6382. {
  6383. skeleton->comdat_type_p = true;
  6384. skeleton->die_id.die_type_node = child->die_id.die_type_node;
  6385. /* If the original DIE was a specification, we need to put
  6386. the skeleton under the parent DIE of the declaration.
  6387. This leaves the original declaration in the tree, but
  6388. it will be pruned later since there are no longer any
  6389. references to it. */
  6390. if (orig_parent != NULL)
  6391. {
  6392. remove_child_with_prev (child, prev);
  6393. add_child_die (orig_parent, skeleton);
  6394. }
  6395. else
  6396. replace_child (child, skeleton, prev);
  6397. }
  6398. return skeleton;
  6399. }
  6400. /* Traverse the DIE and set up additional .debug_types sections for each
  6401. type worthy of being placed in a COMDAT section. */
  6402. static void
  6403. break_out_comdat_types (dw_die_ref die)
  6404. {
  6405. dw_die_ref c;
  6406. dw_die_ref first;
  6407. dw_die_ref prev = NULL;
  6408. dw_die_ref next = NULL;
  6409. dw_die_ref unit = NULL;
  6410. first = c = die->die_child;
  6411. if (c)
  6412. next = c->die_sib;
  6413. if (c) do {
  6414. if (prev == NULL || prev->die_sib == c)
  6415. prev = c;
  6416. c = next;
  6417. next = (c == first ? NULL : c->die_sib);
  6418. if (should_move_die_to_comdat (c))
  6419. {
  6420. dw_die_ref replacement;
  6421. comdat_type_node_ref type_node;
  6422. /* Break out nested types into their own type units. */
  6423. break_out_comdat_types (c);
  6424. /* Create a new type unit DIE as the root for the new tree, and
  6425. add it to the list of comdat types. */
  6426. unit = new_die (DW_TAG_type_unit, NULL, NULL);
  6427. add_AT_unsigned (unit, DW_AT_language,
  6428. get_AT_unsigned (comp_unit_die (), DW_AT_language));
  6429. type_node = ggc_cleared_alloc<comdat_type_node> ();
  6430. type_node->root_die = unit;
  6431. type_node->next = comdat_type_list;
  6432. comdat_type_list = type_node;
  6433. /* Generate the type signature. */
  6434. generate_type_signature (c, type_node);
  6435. /* Copy the declaration context, attributes, and children of the
  6436. declaration into the new type unit DIE, then remove this DIE
  6437. from the main CU (or replace it with a skeleton if necessary). */
  6438. replacement = remove_child_or_replace_with_skeleton (unit, c, prev);
  6439. type_node->skeleton_die = replacement;
  6440. /* Add the DIE to the new compunit. */
  6441. add_child_die (unit, c);
  6442. if (replacement != NULL)
  6443. c = replacement;
  6444. }
  6445. else if (c->die_tag == DW_TAG_namespace
  6446. || c->die_tag == DW_TAG_class_type
  6447. || c->die_tag == DW_TAG_structure_type
  6448. || c->die_tag == DW_TAG_union_type)
  6449. {
  6450. /* Look for nested types that can be broken out. */
  6451. break_out_comdat_types (c);
  6452. }
  6453. } while (next != NULL);
  6454. }
  6455. /* Like clone_tree, but copy DW_TAG_subprogram DIEs as declarations.
  6456. Enter all the cloned children into the hash table decl_table. */
  6457. static dw_die_ref
  6458. clone_tree_partial (dw_die_ref die, decl_hash_type *decl_table)
  6459. {
  6460. dw_die_ref c;
  6461. dw_die_ref clone;
  6462. struct decl_table_entry *entry;
  6463. decl_table_entry **slot;
  6464. if (die->die_tag == DW_TAG_subprogram)
  6465. clone = clone_as_declaration (die);
  6466. else
  6467. clone = clone_die (die);
  6468. slot = decl_table->find_slot_with_hash (die,
  6469. htab_hash_pointer (die), INSERT);
  6470. /* Assert that DIE isn't in the hash table yet. If it would be there
  6471. before, the ancestors would be necessarily there as well, therefore
  6472. clone_tree_partial wouldn't be called. */
  6473. gcc_assert (*slot == HTAB_EMPTY_ENTRY);
  6474. entry = XCNEW (struct decl_table_entry);
  6475. entry->orig = die;
  6476. entry->copy = clone;
  6477. *slot = entry;
  6478. if (die->die_tag != DW_TAG_subprogram)
  6479. FOR_EACH_CHILD (die, c,
  6480. add_child_die (clone, clone_tree_partial (c, decl_table)));
  6481. return clone;
  6482. }
  6483. /* Walk the DIE and its children, looking for references to incomplete
  6484. or trivial types that are unmarked (i.e., that are not in the current
  6485. type_unit). */
  6486. static void
  6487. copy_decls_walk (dw_die_ref unit, dw_die_ref die, decl_hash_type *decl_table)
  6488. {
  6489. dw_die_ref c;
  6490. dw_attr_ref a;
  6491. unsigned ix;
  6492. FOR_EACH_VEC_SAFE_ELT (die->die_attr, ix, a)
  6493. {
  6494. if (AT_class (a) == dw_val_class_die_ref)
  6495. {
  6496. dw_die_ref targ = AT_ref (a);
  6497. decl_table_entry **slot;
  6498. struct decl_table_entry *entry;
  6499. if (targ->die_mark != 0 || targ->comdat_type_p)
  6500. continue;
  6501. slot = decl_table->find_slot_with_hash (targ,
  6502. htab_hash_pointer (targ),
  6503. INSERT);
  6504. if (*slot != HTAB_EMPTY_ENTRY)
  6505. {
  6506. /* TARG has already been copied, so we just need to
  6507. modify the reference to point to the copy. */
  6508. entry = *slot;
  6509. a->dw_attr_val.v.val_die_ref.die = entry->copy;
  6510. }
  6511. else
  6512. {
  6513. dw_die_ref parent = unit;
  6514. dw_die_ref copy = clone_die (targ);
  6515. /* Record in DECL_TABLE that TARG has been copied.
  6516. Need to do this now, before the recursive call,
  6517. because DECL_TABLE may be expanded and SLOT
  6518. would no longer be a valid pointer. */
  6519. entry = XCNEW (struct decl_table_entry);
  6520. entry->orig = targ;
  6521. entry->copy = copy;
  6522. *slot = entry;
  6523. /* If TARG is not a declaration DIE, we need to copy its
  6524. children. */
  6525. if (!is_declaration_die (targ))
  6526. {
  6527. FOR_EACH_CHILD (
  6528. targ, c,
  6529. add_child_die (copy,
  6530. clone_tree_partial (c, decl_table)));
  6531. }
  6532. /* Make sure the cloned tree is marked as part of the
  6533. type unit. */
  6534. mark_dies (copy);
  6535. /* If TARG has surrounding context, copy its ancestor tree
  6536. into the new type unit. */
  6537. if (targ->die_parent != NULL
  6538. && !is_unit_die (targ->die_parent))
  6539. parent = copy_ancestor_tree (unit, targ->die_parent,
  6540. decl_table);
  6541. add_child_die (parent, copy);
  6542. a->dw_attr_val.v.val_die_ref.die = copy;
  6543. /* Make sure the newly-copied DIE is walked. If it was
  6544. installed in a previously-added context, it won't
  6545. get visited otherwise. */
  6546. if (parent != unit)
  6547. {
  6548. /* Find the highest point of the newly-added tree,
  6549. mark each node along the way, and walk from there. */
  6550. parent->die_mark = 1;
  6551. while (parent->die_parent
  6552. && parent->die_parent->die_mark == 0)
  6553. {
  6554. parent = parent->die_parent;
  6555. parent->die_mark = 1;
  6556. }
  6557. copy_decls_walk (unit, parent, decl_table);
  6558. }
  6559. }
  6560. }
  6561. }
  6562. FOR_EACH_CHILD (die, c, copy_decls_walk (unit, c, decl_table));
  6563. }
  6564. /* Copy declarations for "unworthy" types into the new comdat section.
  6565. Incomplete types, modified types, and certain other types aren't broken
  6566. out into comdat sections of their own, so they don't have a signature,
  6567. and we need to copy the declaration into the same section so that we
  6568. don't have an external reference. */
  6569. static void
  6570. copy_decls_for_unworthy_types (dw_die_ref unit)
  6571. {
  6572. mark_dies (unit);
  6573. decl_hash_type decl_table (10);
  6574. copy_decls_walk (unit, unit, &decl_table);
  6575. unmark_dies (unit);
  6576. }
  6577. /* Traverse the DIE and add a sibling attribute if it may have the
  6578. effect of speeding up access to siblings. To save some space,
  6579. avoid generating sibling attributes for DIE's without children. */
  6580. static void
  6581. add_sibling_attributes (dw_die_ref die)
  6582. {
  6583. dw_die_ref c;
  6584. if (! die->die_child)
  6585. return;
  6586. if (die->die_parent && die != die->die_parent->die_child)
  6587. add_AT_die_ref (die, DW_AT_sibling, die->die_sib);
  6588. FOR_EACH_CHILD (die, c, add_sibling_attributes (c));
  6589. }
  6590. /* Output all location lists for the DIE and its children. */
  6591. static void
  6592. output_location_lists (dw_die_ref die)
  6593. {
  6594. dw_die_ref c;
  6595. dw_attr_ref a;
  6596. unsigned ix;
  6597. FOR_EACH_VEC_SAFE_ELT (die->die_attr, ix, a)
  6598. if (AT_class (a) == dw_val_class_loc_list)
  6599. output_loc_list (AT_loc_list (a));
  6600. FOR_EACH_CHILD (die, c, output_location_lists (c));
  6601. }
  6602. /* We want to limit the number of external references, because they are
  6603. larger than local references: a relocation takes multiple words, and
  6604. even a sig8 reference is always eight bytes, whereas a local reference
  6605. can be as small as one byte (though DW_FORM_ref is usually 4 in GCC).
  6606. So if we encounter multiple external references to the same type DIE, we
  6607. make a local typedef stub for it and redirect all references there.
  6608. This is the element of the hash table for keeping track of these
  6609. references. */
  6610. struct external_ref
  6611. {
  6612. dw_die_ref type;
  6613. dw_die_ref stub;
  6614. unsigned n_refs;
  6615. };
  6616. /* Hashtable helpers. */
  6617. struct external_ref_hasher : typed_free_remove <external_ref>
  6618. {
  6619. typedef external_ref value_type;
  6620. typedef external_ref compare_type;
  6621. static inline hashval_t hash (const value_type *);
  6622. static inline bool equal (const value_type *, const compare_type *);
  6623. };
  6624. inline hashval_t
  6625. external_ref_hasher::hash (const value_type *r)
  6626. {
  6627. dw_die_ref die = r->type;
  6628. hashval_t h = 0;
  6629. /* We can't use the address of the DIE for hashing, because
  6630. that will make the order of the stub DIEs non-deterministic. */
  6631. if (! die->comdat_type_p)
  6632. /* We have a symbol; use it to compute a hash. */
  6633. h = htab_hash_string (die->die_id.die_symbol);
  6634. else
  6635. {
  6636. /* We have a type signature; use a subset of the bits as the hash.
  6637. The 8-byte signature is at least as large as hashval_t. */
  6638. comdat_type_node_ref type_node = die->die_id.die_type_node;
  6639. memcpy (&h, type_node->signature, sizeof (h));
  6640. }
  6641. return h;
  6642. }
  6643. inline bool
  6644. external_ref_hasher::equal (const value_type *r1, const compare_type *r2)
  6645. {
  6646. return r1->type == r2->type;
  6647. }
  6648. typedef hash_table<external_ref_hasher> external_ref_hash_type;
  6649. /* Return a pointer to the external_ref for references to DIE. */
  6650. static struct external_ref *
  6651. lookup_external_ref (external_ref_hash_type *map, dw_die_ref die)
  6652. {
  6653. struct external_ref ref, *ref_p;
  6654. external_ref **slot;
  6655. ref.type = die;
  6656. slot = map->find_slot (&ref, INSERT);
  6657. if (*slot != HTAB_EMPTY_ENTRY)
  6658. return *slot;
  6659. ref_p = XCNEW (struct external_ref);
  6660. ref_p->type = die;
  6661. *slot = ref_p;
  6662. return ref_p;
  6663. }
  6664. /* Subroutine of optimize_external_refs, below.
  6665. If we see a type skeleton, record it as our stub. If we see external
  6666. references, remember how many we've seen. */
  6667. static void
  6668. optimize_external_refs_1 (dw_die_ref die, external_ref_hash_type *map)
  6669. {
  6670. dw_die_ref c;
  6671. dw_attr_ref a;
  6672. unsigned ix;
  6673. struct external_ref *ref_p;
  6674. if (is_type_die (die)
  6675. && (c = get_AT_ref (die, DW_AT_signature)))
  6676. {
  6677. /* This is a local skeleton; use it for local references. */
  6678. ref_p = lookup_external_ref (map, c);
  6679. ref_p->stub = die;
  6680. }
  6681. /* Scan the DIE references, and remember any that refer to DIEs from
  6682. other CUs (i.e. those which are not marked). */
  6683. FOR_EACH_VEC_SAFE_ELT (die->die_attr, ix, a)
  6684. if (AT_class (a) == dw_val_class_die_ref
  6685. && (c = AT_ref (a))->die_mark == 0
  6686. && is_type_die (c))
  6687. {
  6688. ref_p = lookup_external_ref (map, c);
  6689. ref_p->n_refs++;
  6690. }
  6691. FOR_EACH_CHILD (die, c, optimize_external_refs_1 (c, map));
  6692. }
  6693. /* htab_traverse callback function for optimize_external_refs, below. SLOT
  6694. points to an external_ref, DATA is the CU we're processing. If we don't
  6695. already have a local stub, and we have multiple refs, build a stub. */
  6696. int
  6697. dwarf2_build_local_stub (external_ref **slot, dw_die_ref data)
  6698. {
  6699. struct external_ref *ref_p = *slot;
  6700. if (ref_p->stub == NULL && ref_p->n_refs > 1 && !dwarf_strict)
  6701. {
  6702. /* We have multiple references to this type, so build a small stub.
  6703. Both of these forms are a bit dodgy from the perspective of the
  6704. DWARF standard, since technically they should have names. */
  6705. dw_die_ref cu = data;
  6706. dw_die_ref type = ref_p->type;
  6707. dw_die_ref stub = NULL;
  6708. if (type->comdat_type_p)
  6709. {
  6710. /* If we refer to this type via sig8, use AT_signature. */
  6711. stub = new_die (type->die_tag, cu, NULL_TREE);
  6712. add_AT_die_ref (stub, DW_AT_signature, type);
  6713. }
  6714. else
  6715. {
  6716. /* Otherwise, use a typedef with no name. */
  6717. stub = new_die (DW_TAG_typedef, cu, NULL_TREE);
  6718. add_AT_die_ref (stub, DW_AT_type, type);
  6719. }
  6720. stub->die_mark++;
  6721. ref_p->stub = stub;
  6722. }
  6723. return 1;
  6724. }
  6725. /* DIE is a unit; look through all the DIE references to see if there are
  6726. any external references to types, and if so, create local stubs for
  6727. them which will be applied in build_abbrev_table. This is useful because
  6728. references to local DIEs are smaller. */
  6729. static external_ref_hash_type *
  6730. optimize_external_refs (dw_die_ref die)
  6731. {
  6732. external_ref_hash_type *map = new external_ref_hash_type (10);
  6733. optimize_external_refs_1 (die, map);
  6734. map->traverse <dw_die_ref, dwarf2_build_local_stub> (die);
  6735. return map;
  6736. }
  6737. /* The format of each DIE (and its attribute value pairs) is encoded in an
  6738. abbreviation table. This routine builds the abbreviation table and assigns
  6739. a unique abbreviation id for each abbreviation entry. The children of each
  6740. die are visited recursively. */
  6741. static void
  6742. build_abbrev_table (dw_die_ref die, external_ref_hash_type *extern_map)
  6743. {
  6744. unsigned long abbrev_id;
  6745. unsigned int n_alloc;
  6746. dw_die_ref c;
  6747. dw_attr_ref a;
  6748. unsigned ix;
  6749. /* Scan the DIE references, and replace any that refer to
  6750. DIEs from other CUs (i.e. those which are not marked) with
  6751. the local stubs we built in optimize_external_refs. */
  6752. FOR_EACH_VEC_SAFE_ELT (die->die_attr, ix, a)
  6753. if (AT_class (a) == dw_val_class_die_ref
  6754. && (c = AT_ref (a))->die_mark == 0)
  6755. {
  6756. struct external_ref *ref_p;
  6757. gcc_assert (AT_ref (a)->comdat_type_p || AT_ref (a)->die_id.die_symbol);
  6758. ref_p = lookup_external_ref (extern_map, c);
  6759. if (ref_p->stub && ref_p->stub != die)
  6760. change_AT_die_ref (a, ref_p->stub);
  6761. else
  6762. /* We aren't changing this reference, so mark it external. */
  6763. set_AT_ref_external (a, 1);
  6764. }
  6765. for (abbrev_id = 1; abbrev_id < abbrev_die_table_in_use; ++abbrev_id)
  6766. {
  6767. dw_die_ref abbrev = abbrev_die_table[abbrev_id];
  6768. dw_attr_ref die_a, abbrev_a;
  6769. unsigned ix;
  6770. bool ok = true;
  6771. if (abbrev->die_tag != die->die_tag)
  6772. continue;
  6773. if ((abbrev->die_child != NULL) != (die->die_child != NULL))
  6774. continue;
  6775. if (vec_safe_length (abbrev->die_attr) != vec_safe_length (die->die_attr))
  6776. continue;
  6777. FOR_EACH_VEC_SAFE_ELT (die->die_attr, ix, die_a)
  6778. {
  6779. abbrev_a = &(*abbrev->die_attr)[ix];
  6780. if ((abbrev_a->dw_attr != die_a->dw_attr)
  6781. || (value_format (abbrev_a) != value_format (die_a)))
  6782. {
  6783. ok = false;
  6784. break;
  6785. }
  6786. }
  6787. if (ok)
  6788. break;
  6789. }
  6790. if (abbrev_id >= abbrev_die_table_in_use)
  6791. {
  6792. if (abbrev_die_table_in_use >= abbrev_die_table_allocated)
  6793. {
  6794. n_alloc = abbrev_die_table_allocated + ABBREV_DIE_TABLE_INCREMENT;
  6795. abbrev_die_table = GGC_RESIZEVEC (dw_die_ref, abbrev_die_table,
  6796. n_alloc);
  6797. memset (&abbrev_die_table[abbrev_die_table_allocated], 0,
  6798. (n_alloc - abbrev_die_table_allocated) * sizeof (dw_die_ref));
  6799. abbrev_die_table_allocated = n_alloc;
  6800. }
  6801. ++abbrev_die_table_in_use;
  6802. abbrev_die_table[abbrev_id] = die;
  6803. }
  6804. die->die_abbrev = abbrev_id;
  6805. FOR_EACH_CHILD (die, c, build_abbrev_table (c, extern_map));
  6806. }
  6807. /* Return the power-of-two number of bytes necessary to represent VALUE. */
  6808. static int
  6809. constant_size (unsigned HOST_WIDE_INT value)
  6810. {
  6811. int log;
  6812. if (value == 0)
  6813. log = 0;
  6814. else
  6815. log = floor_log2 (value);
  6816. log = log / 8;
  6817. log = 1 << (floor_log2 (log) + 1);
  6818. return log;
  6819. }
  6820. /* Return the size of a DIE as it is represented in the
  6821. .debug_info section. */
  6822. static unsigned long
  6823. size_of_die (dw_die_ref die)
  6824. {
  6825. unsigned long size = 0;
  6826. dw_attr_ref a;
  6827. unsigned ix;
  6828. enum dwarf_form form;
  6829. size += size_of_uleb128 (die->die_abbrev);
  6830. FOR_EACH_VEC_SAFE_ELT (die->die_attr, ix, a)
  6831. {
  6832. switch (AT_class (a))
  6833. {
  6834. case dw_val_class_addr:
  6835. if (dwarf_split_debug_info && AT_index (a) != NOT_INDEXED)
  6836. {
  6837. gcc_assert (AT_index (a) != NO_INDEX_ASSIGNED);
  6838. size += size_of_uleb128 (AT_index (a));
  6839. }
  6840. else
  6841. size += DWARF2_ADDR_SIZE;
  6842. break;
  6843. case dw_val_class_offset:
  6844. size += DWARF_OFFSET_SIZE;
  6845. break;
  6846. case dw_val_class_loc:
  6847. {
  6848. unsigned long lsize = size_of_locs (AT_loc (a));
  6849. /* Block length. */
  6850. if (dwarf_version >= 4)
  6851. size += size_of_uleb128 (lsize);
  6852. else
  6853. size += constant_size (lsize);
  6854. size += lsize;
  6855. }
  6856. break;
  6857. case dw_val_class_loc_list:
  6858. if (dwarf_split_debug_info && AT_index (a) != NOT_INDEXED)
  6859. {
  6860. gcc_assert (AT_index (a) != NO_INDEX_ASSIGNED);
  6861. size += size_of_uleb128 (AT_index (a));
  6862. }
  6863. else
  6864. size += DWARF_OFFSET_SIZE;
  6865. break;
  6866. case dw_val_class_range_list:
  6867. size += DWARF_OFFSET_SIZE;
  6868. break;
  6869. case dw_val_class_const:
  6870. size += size_of_sleb128 (AT_int (a));
  6871. break;
  6872. case dw_val_class_unsigned_const:
  6873. {
  6874. int csize = constant_size (AT_unsigned (a));
  6875. if (dwarf_version == 3
  6876. && a->dw_attr == DW_AT_data_member_location
  6877. && csize >= 4)
  6878. size += size_of_uleb128 (AT_unsigned (a));
  6879. else
  6880. size += csize;
  6881. }
  6882. break;
  6883. case dw_val_class_const_double:
  6884. size += HOST_BITS_PER_DOUBLE_INT / HOST_BITS_PER_CHAR;
  6885. if (HOST_BITS_PER_WIDE_INT >= 64)
  6886. size++; /* block */
  6887. break;
  6888. case dw_val_class_wide_int:
  6889. size += (get_full_len (*a->dw_attr_val.v.val_wide)
  6890. * HOST_BITS_PER_WIDE_INT / HOST_BITS_PER_CHAR);
  6891. if (get_full_len (*a->dw_attr_val.v.val_wide) * HOST_BITS_PER_WIDE_INT
  6892. > 64)
  6893. size++; /* block */
  6894. break;
  6895. case dw_val_class_vec:
  6896. size += constant_size (a->dw_attr_val.v.val_vec.length
  6897. * a->dw_attr_val.v.val_vec.elt_size)
  6898. + a->dw_attr_val.v.val_vec.length
  6899. * a->dw_attr_val.v.val_vec.elt_size; /* block */
  6900. break;
  6901. case dw_val_class_flag:
  6902. if (dwarf_version >= 4)
  6903. /* Currently all add_AT_flag calls pass in 1 as last argument,
  6904. so DW_FORM_flag_present can be used. If that ever changes,
  6905. we'll need to use DW_FORM_flag and have some optimization
  6906. in build_abbrev_table that will change those to
  6907. DW_FORM_flag_present if it is set to 1 in all DIEs using
  6908. the same abbrev entry. */
  6909. gcc_assert (a->dw_attr_val.v.val_flag == 1);
  6910. else
  6911. size += 1;
  6912. break;
  6913. case dw_val_class_die_ref:
  6914. if (AT_ref_external (a))
  6915. {
  6916. /* In DWARF4, we use DW_FORM_ref_sig8; for earlier versions
  6917. we use DW_FORM_ref_addr. In DWARF2, DW_FORM_ref_addr
  6918. is sized by target address length, whereas in DWARF3
  6919. it's always sized as an offset. */
  6920. if (use_debug_types)
  6921. size += DWARF_TYPE_SIGNATURE_SIZE;
  6922. else if (dwarf_version == 2)
  6923. size += DWARF2_ADDR_SIZE;
  6924. else
  6925. size += DWARF_OFFSET_SIZE;
  6926. }
  6927. else
  6928. size += DWARF_OFFSET_SIZE;
  6929. break;
  6930. case dw_val_class_fde_ref:
  6931. size += DWARF_OFFSET_SIZE;
  6932. break;
  6933. case dw_val_class_lbl_id:
  6934. if (dwarf_split_debug_info && AT_index (a) != NOT_INDEXED)
  6935. {
  6936. gcc_assert (AT_index (a) != NO_INDEX_ASSIGNED);
  6937. size += size_of_uleb128 (AT_index (a));
  6938. }
  6939. else
  6940. size += DWARF2_ADDR_SIZE;
  6941. break;
  6942. case dw_val_class_lineptr:
  6943. case dw_val_class_macptr:
  6944. size += DWARF_OFFSET_SIZE;
  6945. break;
  6946. case dw_val_class_str:
  6947. form = AT_string_form (a);
  6948. if (form == DW_FORM_strp)
  6949. size += DWARF_OFFSET_SIZE;
  6950. else if (form == DW_FORM_GNU_str_index)
  6951. size += size_of_uleb128 (AT_index (a));
  6952. else
  6953. size += strlen (a->dw_attr_val.v.val_str->str) + 1;
  6954. break;
  6955. case dw_val_class_file:
  6956. size += constant_size (maybe_emit_file (a->dw_attr_val.v.val_file));
  6957. break;
  6958. case dw_val_class_data8:
  6959. size += 8;
  6960. break;
  6961. case dw_val_class_vms_delta:
  6962. size += DWARF_OFFSET_SIZE;
  6963. break;
  6964. case dw_val_class_high_pc:
  6965. size += DWARF2_ADDR_SIZE;
  6966. break;
  6967. default:
  6968. gcc_unreachable ();
  6969. }
  6970. }
  6971. return size;
  6972. }
  6973. /* Size the debugging information associated with a given DIE. Visits the
  6974. DIE's children recursively. Updates the global variable next_die_offset, on
  6975. each time through. Uses the current value of next_die_offset to update the
  6976. die_offset field in each DIE. */
  6977. static void
  6978. calc_die_sizes (dw_die_ref die)
  6979. {
  6980. dw_die_ref c;
  6981. gcc_assert (die->die_offset == 0
  6982. || (unsigned long int) die->die_offset == next_die_offset);
  6983. die->die_offset = next_die_offset;
  6984. next_die_offset += size_of_die (die);
  6985. FOR_EACH_CHILD (die, c, calc_die_sizes (c));
  6986. if (die->die_child != NULL)
  6987. /* Count the null byte used to terminate sibling lists. */
  6988. next_die_offset += 1;
  6989. }
  6990. /* Size just the base type children at the start of the CU.
  6991. This is needed because build_abbrev needs to size locs
  6992. and sizing of type based stack ops needs to know die_offset
  6993. values for the base types. */
  6994. static void
  6995. calc_base_type_die_sizes (void)
  6996. {
  6997. unsigned long die_offset = DWARF_COMPILE_UNIT_HEADER_SIZE;
  6998. unsigned int i;
  6999. dw_die_ref base_type;
  7000. #if ENABLE_ASSERT_CHECKING
  7001. dw_die_ref prev = comp_unit_die ()->die_child;
  7002. #endif
  7003. die_offset += size_of_die (comp_unit_die ());
  7004. for (i = 0; base_types.iterate (i, &base_type); i++)
  7005. {
  7006. #if ENABLE_ASSERT_CHECKING
  7007. gcc_assert (base_type->die_offset == 0
  7008. && prev->die_sib == base_type
  7009. && base_type->die_child == NULL
  7010. && base_type->die_abbrev);
  7011. prev = base_type;
  7012. #endif
  7013. base_type->die_offset = die_offset;
  7014. die_offset += size_of_die (base_type);
  7015. }
  7016. }
  7017. /* Set the marks for a die and its children. We do this so
  7018. that we know whether or not a reference needs to use FORM_ref_addr; only
  7019. DIEs in the same CU will be marked. We used to clear out the offset
  7020. and use that as the flag, but ran into ordering problems. */
  7021. static void
  7022. mark_dies (dw_die_ref die)
  7023. {
  7024. dw_die_ref c;
  7025. gcc_assert (!die->die_mark);
  7026. die->die_mark = 1;
  7027. FOR_EACH_CHILD (die, c, mark_dies (c));
  7028. }
  7029. /* Clear the marks for a die and its children. */
  7030. static void
  7031. unmark_dies (dw_die_ref die)
  7032. {
  7033. dw_die_ref c;
  7034. if (! use_debug_types)
  7035. gcc_assert (die->die_mark);
  7036. die->die_mark = 0;
  7037. FOR_EACH_CHILD (die, c, unmark_dies (c));
  7038. }
  7039. /* Clear the marks for a die, its children and referred dies. */
  7040. static void
  7041. unmark_all_dies (dw_die_ref die)
  7042. {
  7043. dw_die_ref c;
  7044. dw_attr_ref a;
  7045. unsigned ix;
  7046. if (!die->die_mark)
  7047. return;
  7048. die->die_mark = 0;
  7049. FOR_EACH_CHILD (die, c, unmark_all_dies (c));
  7050. FOR_EACH_VEC_SAFE_ELT (die->die_attr, ix, a)
  7051. if (AT_class (a) == dw_val_class_die_ref)
  7052. unmark_all_dies (AT_ref (a));
  7053. }
  7054. /* Calculate if the entry should appear in the final output file. It may be
  7055. from a pruned a type. */
  7056. static bool
  7057. include_pubname_in_output (vec<pubname_entry, va_gc> *table, pubname_entry *p)
  7058. {
  7059. /* By limiting gnu pubnames to definitions only, gold can generate a
  7060. gdb index without entries for declarations, which don't include
  7061. enough information to be useful. */
  7062. if (debug_generate_pub_sections == 2 && is_declaration_die (p->die))
  7063. return false;
  7064. if (table == pubname_table)
  7065. {
  7066. /* Enumerator names are part of the pubname table, but the
  7067. parent DW_TAG_enumeration_type die may have been pruned.
  7068. Don't output them if that is the case. */
  7069. if (p->die->die_tag == DW_TAG_enumerator &&
  7070. (p->die->die_parent == NULL
  7071. || !p->die->die_parent->die_perennial_p))
  7072. return false;
  7073. /* Everything else in the pubname table is included. */
  7074. return true;
  7075. }
  7076. /* The pubtypes table shouldn't include types that have been
  7077. pruned. */
  7078. return (p->die->die_offset != 0
  7079. || !flag_eliminate_unused_debug_types);
  7080. }
  7081. /* Return the size of the .debug_pubnames or .debug_pubtypes table
  7082. generated for the compilation unit. */
  7083. static unsigned long
  7084. size_of_pubnames (vec<pubname_entry, va_gc> *names)
  7085. {
  7086. unsigned long size;
  7087. unsigned i;
  7088. pubname_ref p;
  7089. int space_for_flags = (debug_generate_pub_sections == 2) ? 1 : 0;
  7090. size = DWARF_PUBNAMES_HEADER_SIZE;
  7091. FOR_EACH_VEC_ELT (*names, i, p)
  7092. if (include_pubname_in_output (names, p))
  7093. size += strlen (p->name) + DWARF_OFFSET_SIZE + 1 + space_for_flags;
  7094. size += DWARF_OFFSET_SIZE;
  7095. return size;
  7096. }
  7097. /* Return the size of the information in the .debug_aranges section. */
  7098. static unsigned long
  7099. size_of_aranges (void)
  7100. {
  7101. unsigned long size;
  7102. size = DWARF_ARANGES_HEADER_SIZE;
  7103. /* Count the address/length pair for this compilation unit. */
  7104. if (text_section_used)
  7105. size += 2 * DWARF2_ADDR_SIZE;
  7106. if (cold_text_section_used)
  7107. size += 2 * DWARF2_ADDR_SIZE;
  7108. if (have_multiple_function_sections)
  7109. {
  7110. unsigned fde_idx;
  7111. dw_fde_ref fde;
  7112. FOR_EACH_VEC_ELT (*fde_vec, fde_idx, fde)
  7113. {
  7114. if (DECL_IGNORED_P (fde->decl))
  7115. continue;
  7116. if (!fde->in_std_section)
  7117. size += 2 * DWARF2_ADDR_SIZE;
  7118. if (fde->dw_fde_second_begin && !fde->second_in_std_section)
  7119. size += 2 * DWARF2_ADDR_SIZE;
  7120. }
  7121. }
  7122. /* Count the two zero words used to terminated the address range table. */
  7123. size += 2 * DWARF2_ADDR_SIZE;
  7124. return size;
  7125. }
  7126. /* Select the encoding of an attribute value. */
  7127. static enum dwarf_form
  7128. value_format (dw_attr_ref a)
  7129. {
  7130. switch (AT_class (a))
  7131. {
  7132. case dw_val_class_addr:
  7133. /* Only very few attributes allow DW_FORM_addr. */
  7134. switch (a->dw_attr)
  7135. {
  7136. case DW_AT_low_pc:
  7137. case DW_AT_high_pc:
  7138. case DW_AT_entry_pc:
  7139. case DW_AT_trampoline:
  7140. return (AT_index (a) == NOT_INDEXED
  7141. ? DW_FORM_addr : DW_FORM_GNU_addr_index);
  7142. default:
  7143. break;
  7144. }
  7145. switch (DWARF2_ADDR_SIZE)
  7146. {
  7147. case 1:
  7148. return DW_FORM_data1;
  7149. case 2:
  7150. return DW_FORM_data2;
  7151. case 4:
  7152. return DW_FORM_data4;
  7153. case 8:
  7154. return DW_FORM_data8;
  7155. default:
  7156. gcc_unreachable ();
  7157. }
  7158. case dw_val_class_range_list:
  7159. case dw_val_class_loc_list:
  7160. if (dwarf_version >= 4)
  7161. return DW_FORM_sec_offset;
  7162. /* FALLTHRU */
  7163. case dw_val_class_vms_delta:
  7164. case dw_val_class_offset:
  7165. switch (DWARF_OFFSET_SIZE)
  7166. {
  7167. case 4:
  7168. return DW_FORM_data4;
  7169. case 8:
  7170. return DW_FORM_data8;
  7171. default:
  7172. gcc_unreachable ();
  7173. }
  7174. case dw_val_class_loc:
  7175. if (dwarf_version >= 4)
  7176. return DW_FORM_exprloc;
  7177. switch (constant_size (size_of_locs (AT_loc (a))))
  7178. {
  7179. case 1:
  7180. return DW_FORM_block1;
  7181. case 2:
  7182. return DW_FORM_block2;
  7183. case 4:
  7184. return DW_FORM_block4;
  7185. default:
  7186. gcc_unreachable ();
  7187. }
  7188. case dw_val_class_const:
  7189. return DW_FORM_sdata;
  7190. case dw_val_class_unsigned_const:
  7191. switch (constant_size (AT_unsigned (a)))
  7192. {
  7193. case 1:
  7194. return DW_FORM_data1;
  7195. case 2:
  7196. return DW_FORM_data2;
  7197. case 4:
  7198. /* In DWARF3 DW_AT_data_member_location with
  7199. DW_FORM_data4 or DW_FORM_data8 is a loclistptr, not
  7200. constant, so we need to use DW_FORM_udata if we need
  7201. a large constant. */
  7202. if (dwarf_version == 3 && a->dw_attr == DW_AT_data_member_location)
  7203. return DW_FORM_udata;
  7204. return DW_FORM_data4;
  7205. case 8:
  7206. if (dwarf_version == 3 && a->dw_attr == DW_AT_data_member_location)
  7207. return DW_FORM_udata;
  7208. return DW_FORM_data8;
  7209. default:
  7210. gcc_unreachable ();
  7211. }
  7212. case dw_val_class_const_double:
  7213. switch (HOST_BITS_PER_WIDE_INT)
  7214. {
  7215. case 8:
  7216. return DW_FORM_data2;
  7217. case 16:
  7218. return DW_FORM_data4;
  7219. case 32:
  7220. return DW_FORM_data8;
  7221. case 64:
  7222. default:
  7223. return DW_FORM_block1;
  7224. }
  7225. case dw_val_class_wide_int:
  7226. switch (get_full_len (*a->dw_attr_val.v.val_wide) * HOST_BITS_PER_WIDE_INT)
  7227. {
  7228. case 8:
  7229. return DW_FORM_data1;
  7230. case 16:
  7231. return DW_FORM_data2;
  7232. case 32:
  7233. return DW_FORM_data4;
  7234. case 64:
  7235. return DW_FORM_data8;
  7236. default:
  7237. return DW_FORM_block1;
  7238. }
  7239. case dw_val_class_vec:
  7240. switch (constant_size (a->dw_attr_val.v.val_vec.length
  7241. * a->dw_attr_val.v.val_vec.elt_size))
  7242. {
  7243. case 1:
  7244. return DW_FORM_block1;
  7245. case 2:
  7246. return DW_FORM_block2;
  7247. case 4:
  7248. return DW_FORM_block4;
  7249. default:
  7250. gcc_unreachable ();
  7251. }
  7252. case dw_val_class_flag:
  7253. if (dwarf_version >= 4)
  7254. {
  7255. /* Currently all add_AT_flag calls pass in 1 as last argument,
  7256. so DW_FORM_flag_present can be used. If that ever changes,
  7257. we'll need to use DW_FORM_flag and have some optimization
  7258. in build_abbrev_table that will change those to
  7259. DW_FORM_flag_present if it is set to 1 in all DIEs using
  7260. the same abbrev entry. */
  7261. gcc_assert (a->dw_attr_val.v.val_flag == 1);
  7262. return DW_FORM_flag_present;
  7263. }
  7264. return DW_FORM_flag;
  7265. case dw_val_class_die_ref:
  7266. if (AT_ref_external (a))
  7267. return use_debug_types ? DW_FORM_ref_sig8 : DW_FORM_ref_addr;
  7268. else
  7269. return DW_FORM_ref;
  7270. case dw_val_class_fde_ref:
  7271. return DW_FORM_data;
  7272. case dw_val_class_lbl_id:
  7273. return (AT_index (a) == NOT_INDEXED
  7274. ? DW_FORM_addr : DW_FORM_GNU_addr_index);
  7275. case dw_val_class_lineptr:
  7276. case dw_val_class_macptr:
  7277. return dwarf_version >= 4 ? DW_FORM_sec_offset : DW_FORM_data;
  7278. case dw_val_class_str:
  7279. return AT_string_form (a);
  7280. case dw_val_class_file:
  7281. switch (constant_size (maybe_emit_file (a->dw_attr_val.v.val_file)))
  7282. {
  7283. case 1:
  7284. return DW_FORM_data1;
  7285. case 2:
  7286. return DW_FORM_data2;
  7287. case 4:
  7288. return DW_FORM_data4;
  7289. default:
  7290. gcc_unreachable ();
  7291. }
  7292. case dw_val_class_data8:
  7293. return DW_FORM_data8;
  7294. case dw_val_class_high_pc:
  7295. switch (DWARF2_ADDR_SIZE)
  7296. {
  7297. case 1:
  7298. return DW_FORM_data1;
  7299. case 2:
  7300. return DW_FORM_data2;
  7301. case 4:
  7302. return DW_FORM_data4;
  7303. case 8:
  7304. return DW_FORM_data8;
  7305. default:
  7306. gcc_unreachable ();
  7307. }
  7308. default:
  7309. gcc_unreachable ();
  7310. }
  7311. }
  7312. /* Output the encoding of an attribute value. */
  7313. static void
  7314. output_value_format (dw_attr_ref a)
  7315. {
  7316. enum dwarf_form form = value_format (a);
  7317. dw2_asm_output_data_uleb128 (form, "(%s)", dwarf_form_name (form));
  7318. }
  7319. /* Given a die and id, produce the appropriate abbreviations. */
  7320. static void
  7321. output_die_abbrevs (unsigned long abbrev_id, dw_die_ref abbrev)
  7322. {
  7323. unsigned ix;
  7324. dw_attr_ref a_attr;
  7325. dw2_asm_output_data_uleb128 (abbrev_id, "(abbrev code)");
  7326. dw2_asm_output_data_uleb128 (abbrev->die_tag, "(TAG: %s)",
  7327. dwarf_tag_name (abbrev->die_tag));
  7328. if (abbrev->die_child != NULL)
  7329. dw2_asm_output_data (1, DW_children_yes, "DW_children_yes");
  7330. else
  7331. dw2_asm_output_data (1, DW_children_no, "DW_children_no");
  7332. for (ix = 0; vec_safe_iterate (abbrev->die_attr, ix, &a_attr); ix++)
  7333. {
  7334. dw2_asm_output_data_uleb128 (a_attr->dw_attr, "(%s)",
  7335. dwarf_attr_name (a_attr->dw_attr));
  7336. output_value_format (a_attr);
  7337. }
  7338. dw2_asm_output_data (1, 0, NULL);
  7339. dw2_asm_output_data (1, 0, NULL);
  7340. }
  7341. /* Output the .debug_abbrev section which defines the DIE abbreviation
  7342. table. */
  7343. static void
  7344. output_abbrev_section (void)
  7345. {
  7346. unsigned long abbrev_id;
  7347. for (abbrev_id = 1; abbrev_id < abbrev_die_table_in_use; ++abbrev_id)
  7348. output_die_abbrevs (abbrev_id, abbrev_die_table[abbrev_id]);
  7349. /* Terminate the table. */
  7350. dw2_asm_output_data (1, 0, NULL);
  7351. }
  7352. /* Output a symbol we can use to refer to this DIE from another CU. */
  7353. static inline void
  7354. output_die_symbol (dw_die_ref die)
  7355. {
  7356. const char *sym = die->die_id.die_symbol;
  7357. gcc_assert (!die->comdat_type_p);
  7358. if (sym == 0)
  7359. return;
  7360. if (strncmp (sym, DIE_LABEL_PREFIX, sizeof (DIE_LABEL_PREFIX) - 1) == 0)
  7361. /* We make these global, not weak; if the target doesn't support
  7362. .linkonce, it doesn't support combining the sections, so debugging
  7363. will break. */
  7364. targetm.asm_out.globalize_label (asm_out_file, sym);
  7365. ASM_OUTPUT_LABEL (asm_out_file, sym);
  7366. }
  7367. /* Return a new location list, given the begin and end range, and the
  7368. expression. */
  7369. static inline dw_loc_list_ref
  7370. new_loc_list (dw_loc_descr_ref expr, const char *begin, const char *end,
  7371. const char *section)
  7372. {
  7373. dw_loc_list_ref retlist = ggc_cleared_alloc<dw_loc_list_node> ();
  7374. retlist->begin = begin;
  7375. retlist->begin_entry = NULL;
  7376. retlist->end = end;
  7377. retlist->expr = expr;
  7378. retlist->section = section;
  7379. return retlist;
  7380. }
  7381. /* Generate a new internal symbol for this location list node, if it
  7382. hasn't got one yet. */
  7383. static inline void
  7384. gen_llsym (dw_loc_list_ref list)
  7385. {
  7386. gcc_assert (!list->ll_symbol);
  7387. list->ll_symbol = gen_internal_sym ("LLST");
  7388. }
  7389. /* Output the location list given to us. */
  7390. static void
  7391. output_loc_list (dw_loc_list_ref list_head)
  7392. {
  7393. dw_loc_list_ref curr = list_head;
  7394. if (list_head->emitted)
  7395. return;
  7396. list_head->emitted = true;
  7397. ASM_OUTPUT_LABEL (asm_out_file, list_head->ll_symbol);
  7398. /* Walk the location list, and output each range + expression. */
  7399. for (curr = list_head; curr != NULL; curr = curr->dw_loc_next)
  7400. {
  7401. unsigned long size;
  7402. /* Don't output an entry that starts and ends at the same address. */
  7403. if (strcmp (curr->begin, curr->end) == 0 && !curr->force)
  7404. continue;
  7405. size = size_of_locs (curr->expr);
  7406. /* If the expression is too large, drop it on the floor. We could
  7407. perhaps put it into DW_TAG_dwarf_procedure and refer to that
  7408. in the expression, but >= 64KB expressions for a single value
  7409. in a single range are unlikely very useful. */
  7410. if (size > 0xffff)
  7411. continue;
  7412. if (dwarf_split_debug_info)
  7413. {
  7414. dw2_asm_output_data (1, DW_LLE_GNU_start_length_entry,
  7415. "Location list start/length entry (%s)",
  7416. list_head->ll_symbol);
  7417. dw2_asm_output_data_uleb128 (curr->begin_entry->index,
  7418. "Location list range start index (%s)",
  7419. curr->begin);
  7420. /* The length field is 4 bytes. If we ever need to support
  7421. an 8-byte length, we can add a new DW_LLE code or fall back
  7422. to DW_LLE_GNU_start_end_entry. */
  7423. dw2_asm_output_delta (4, curr->end, curr->begin,
  7424. "Location list range length (%s)",
  7425. list_head->ll_symbol);
  7426. }
  7427. else if (!have_multiple_function_sections)
  7428. {
  7429. dw2_asm_output_delta (DWARF2_ADDR_SIZE, curr->begin, curr->section,
  7430. "Location list begin address (%s)",
  7431. list_head->ll_symbol);
  7432. dw2_asm_output_delta (DWARF2_ADDR_SIZE, curr->end, curr->section,
  7433. "Location list end address (%s)",
  7434. list_head->ll_symbol);
  7435. }
  7436. else
  7437. {
  7438. dw2_asm_output_addr (DWARF2_ADDR_SIZE, curr->begin,
  7439. "Location list begin address (%s)",
  7440. list_head->ll_symbol);
  7441. dw2_asm_output_addr (DWARF2_ADDR_SIZE, curr->end,
  7442. "Location list end address (%s)",
  7443. list_head->ll_symbol);
  7444. }
  7445. /* Output the block length for this list of location operations. */
  7446. gcc_assert (size <= 0xffff);
  7447. dw2_asm_output_data (2, size, "%s", "Location expression size");
  7448. output_loc_sequence (curr->expr, -1);
  7449. }
  7450. if (dwarf_split_debug_info)
  7451. dw2_asm_output_data (1, DW_LLE_GNU_end_of_list_entry,
  7452. "Location list terminator (%s)",
  7453. list_head->ll_symbol);
  7454. else
  7455. {
  7456. dw2_asm_output_data (DWARF2_ADDR_SIZE, 0,
  7457. "Location list terminator begin (%s)",
  7458. list_head->ll_symbol);
  7459. dw2_asm_output_data (DWARF2_ADDR_SIZE, 0,
  7460. "Location list terminator end (%s)",
  7461. list_head->ll_symbol);
  7462. }
  7463. }
  7464. /* Output a range_list offset into the debug_range section. Emit a
  7465. relocated reference if val_entry is NULL, otherwise, emit an
  7466. indirect reference. */
  7467. static void
  7468. output_range_list_offset (dw_attr_ref a)
  7469. {
  7470. const char *name = dwarf_attr_name (a->dw_attr);
  7471. if (a->dw_attr_val.val_entry == RELOCATED_OFFSET)
  7472. {
  7473. char *p = strchr (ranges_section_label, '\0');
  7474. sprintf (p, "+" HOST_WIDE_INT_PRINT_HEX, a->dw_attr_val.v.val_offset);
  7475. dw2_asm_output_offset (DWARF_OFFSET_SIZE, ranges_section_label,
  7476. debug_ranges_section, "%s", name);
  7477. *p = '\0';
  7478. }
  7479. else
  7480. dw2_asm_output_data (DWARF_OFFSET_SIZE, a->dw_attr_val.v.val_offset,
  7481. "%s (offset from %s)", name, ranges_section_label);
  7482. }
  7483. /* Output the offset into the debug_loc section. */
  7484. static void
  7485. output_loc_list_offset (dw_attr_ref a)
  7486. {
  7487. char *sym = AT_loc_list (a)->ll_symbol;
  7488. gcc_assert (sym);
  7489. if (dwarf_split_debug_info)
  7490. dw2_asm_output_delta (DWARF_OFFSET_SIZE, sym, loc_section_label,
  7491. "%s", dwarf_attr_name (a->dw_attr));
  7492. else
  7493. dw2_asm_output_offset (DWARF_OFFSET_SIZE, sym, debug_loc_section,
  7494. "%s", dwarf_attr_name (a->dw_attr));
  7495. }
  7496. /* Output an attribute's index or value appropriately. */
  7497. static void
  7498. output_attr_index_or_value (dw_attr_ref a)
  7499. {
  7500. const char *name = dwarf_attr_name (a->dw_attr);
  7501. if (dwarf_split_debug_info && AT_index (a) != NOT_INDEXED)
  7502. {
  7503. dw2_asm_output_data_uleb128 (AT_index (a), "%s", name);
  7504. return;
  7505. }
  7506. switch (AT_class (a))
  7507. {
  7508. case dw_val_class_addr:
  7509. dw2_asm_output_addr_rtx (DWARF2_ADDR_SIZE, AT_addr (a), "%s", name);
  7510. break;
  7511. case dw_val_class_high_pc:
  7512. case dw_val_class_lbl_id:
  7513. dw2_asm_output_addr (DWARF2_ADDR_SIZE, AT_lbl (a), "%s", name);
  7514. break;
  7515. case dw_val_class_loc_list:
  7516. output_loc_list_offset (a);
  7517. break;
  7518. default:
  7519. gcc_unreachable ();
  7520. }
  7521. }
  7522. /* Output a type signature. */
  7523. static inline void
  7524. output_signature (const char *sig, const char *name)
  7525. {
  7526. int i;
  7527. for (i = 0; i < DWARF_TYPE_SIGNATURE_SIZE; i++)
  7528. dw2_asm_output_data (1, sig[i], i == 0 ? "%s" : NULL, name);
  7529. }
  7530. /* Output the DIE and its attributes. Called recursively to generate
  7531. the definitions of each child DIE. */
  7532. static void
  7533. output_die (dw_die_ref die)
  7534. {
  7535. dw_attr_ref a;
  7536. dw_die_ref c;
  7537. unsigned long size;
  7538. unsigned ix;
  7539. /* If someone in another CU might refer to us, set up a symbol for
  7540. them to point to. */
  7541. if (! die->comdat_type_p && die->die_id.die_symbol)
  7542. output_die_symbol (die);
  7543. dw2_asm_output_data_uleb128 (die->die_abbrev, "(DIE (%#lx) %s)",
  7544. (unsigned long)die->die_offset,
  7545. dwarf_tag_name (die->die_tag));
  7546. FOR_EACH_VEC_SAFE_ELT (die->die_attr, ix, a)
  7547. {
  7548. const char *name = dwarf_attr_name (a->dw_attr);
  7549. switch (AT_class (a))
  7550. {
  7551. case dw_val_class_addr:
  7552. output_attr_index_or_value (a);
  7553. break;
  7554. case dw_val_class_offset:
  7555. dw2_asm_output_data (DWARF_OFFSET_SIZE, a->dw_attr_val.v.val_offset,
  7556. "%s", name);
  7557. break;
  7558. case dw_val_class_range_list:
  7559. output_range_list_offset (a);
  7560. break;
  7561. case dw_val_class_loc:
  7562. size = size_of_locs (AT_loc (a));
  7563. /* Output the block length for this list of location operations. */
  7564. if (dwarf_version >= 4)
  7565. dw2_asm_output_data_uleb128 (size, "%s", name);
  7566. else
  7567. dw2_asm_output_data (constant_size (size), size, "%s", name);
  7568. output_loc_sequence (AT_loc (a), -1);
  7569. break;
  7570. case dw_val_class_const:
  7571. /* ??? It would be slightly more efficient to use a scheme like is
  7572. used for unsigned constants below, but gdb 4.x does not sign
  7573. extend. Gdb 5.x does sign extend. */
  7574. dw2_asm_output_data_sleb128 (AT_int (a), "%s", name);
  7575. break;
  7576. case dw_val_class_unsigned_const:
  7577. {
  7578. int csize = constant_size (AT_unsigned (a));
  7579. if (dwarf_version == 3
  7580. && a->dw_attr == DW_AT_data_member_location
  7581. && csize >= 4)
  7582. dw2_asm_output_data_uleb128 (AT_unsigned (a), "%s", name);
  7583. else
  7584. dw2_asm_output_data (csize, AT_unsigned (a), "%s", name);
  7585. }
  7586. break;
  7587. case dw_val_class_const_double:
  7588. {
  7589. unsigned HOST_WIDE_INT first, second;
  7590. if (HOST_BITS_PER_WIDE_INT >= 64)
  7591. dw2_asm_output_data (1,
  7592. HOST_BITS_PER_DOUBLE_INT
  7593. / HOST_BITS_PER_CHAR,
  7594. NULL);
  7595. if (WORDS_BIG_ENDIAN)
  7596. {
  7597. first = a->dw_attr_val.v.val_double.high;
  7598. second = a->dw_attr_val.v.val_double.low;
  7599. }
  7600. else
  7601. {
  7602. first = a->dw_attr_val.v.val_double.low;
  7603. second = a->dw_attr_val.v.val_double.high;
  7604. }
  7605. dw2_asm_output_data (HOST_BITS_PER_WIDE_INT / HOST_BITS_PER_CHAR,
  7606. first, "%s", name);
  7607. dw2_asm_output_data (HOST_BITS_PER_WIDE_INT / HOST_BITS_PER_CHAR,
  7608. second, NULL);
  7609. }
  7610. break;
  7611. case dw_val_class_wide_int:
  7612. {
  7613. int i;
  7614. int len = get_full_len (*a->dw_attr_val.v.val_wide);
  7615. int l = HOST_BITS_PER_WIDE_INT / HOST_BITS_PER_CHAR;
  7616. if (len * HOST_BITS_PER_WIDE_INT > 64)
  7617. dw2_asm_output_data (1, get_full_len (*a->dw_attr_val.v.val_wide) * l,
  7618. NULL);
  7619. if (WORDS_BIG_ENDIAN)
  7620. for (i = len - 1; i >= 0; --i)
  7621. {
  7622. dw2_asm_output_data (l, a->dw_attr_val.v.val_wide->elt (i),
  7623. "%s", name);
  7624. name = NULL;
  7625. }
  7626. else
  7627. for (i = 0; i < len; ++i)
  7628. {
  7629. dw2_asm_output_data (l, a->dw_attr_val.v.val_wide->elt (i),
  7630. "%s", name);
  7631. name = NULL;
  7632. }
  7633. }
  7634. break;
  7635. case dw_val_class_vec:
  7636. {
  7637. unsigned int elt_size = a->dw_attr_val.v.val_vec.elt_size;
  7638. unsigned int len = a->dw_attr_val.v.val_vec.length;
  7639. unsigned int i;
  7640. unsigned char *p;
  7641. dw2_asm_output_data (constant_size (len * elt_size),
  7642. len * elt_size, "%s", name);
  7643. if (elt_size > sizeof (HOST_WIDE_INT))
  7644. {
  7645. elt_size /= 2;
  7646. len *= 2;
  7647. }
  7648. for (i = 0, p = a->dw_attr_val.v.val_vec.array;
  7649. i < len;
  7650. i++, p += elt_size)
  7651. dw2_asm_output_data (elt_size, extract_int (p, elt_size),
  7652. "fp or vector constant word %u", i);
  7653. break;
  7654. }
  7655. case dw_val_class_flag:
  7656. if (dwarf_version >= 4)
  7657. {
  7658. /* Currently all add_AT_flag calls pass in 1 as last argument,
  7659. so DW_FORM_flag_present can be used. If that ever changes,
  7660. we'll need to use DW_FORM_flag and have some optimization
  7661. in build_abbrev_table that will change those to
  7662. DW_FORM_flag_present if it is set to 1 in all DIEs using
  7663. the same abbrev entry. */
  7664. gcc_assert (AT_flag (a) == 1);
  7665. if (flag_debug_asm)
  7666. fprintf (asm_out_file, "\t\t\t%s %s\n",
  7667. ASM_COMMENT_START, name);
  7668. break;
  7669. }
  7670. dw2_asm_output_data (1, AT_flag (a), "%s", name);
  7671. break;
  7672. case dw_val_class_loc_list:
  7673. output_attr_index_or_value (a);
  7674. break;
  7675. case dw_val_class_die_ref:
  7676. if (AT_ref_external (a))
  7677. {
  7678. if (AT_ref (a)->comdat_type_p)
  7679. {
  7680. comdat_type_node_ref type_node =
  7681. AT_ref (a)->die_id.die_type_node;
  7682. gcc_assert (type_node);
  7683. output_signature (type_node->signature, name);
  7684. }
  7685. else
  7686. {
  7687. const char *sym = AT_ref (a)->die_id.die_symbol;
  7688. int size;
  7689. gcc_assert (sym);
  7690. /* In DWARF2, DW_FORM_ref_addr is sized by target address
  7691. length, whereas in DWARF3 it's always sized as an
  7692. offset. */
  7693. if (dwarf_version == 2)
  7694. size = DWARF2_ADDR_SIZE;
  7695. else
  7696. size = DWARF_OFFSET_SIZE;
  7697. dw2_asm_output_offset (size, sym, debug_info_section, "%s",
  7698. name);
  7699. }
  7700. }
  7701. else
  7702. {
  7703. gcc_assert (AT_ref (a)->die_offset);
  7704. dw2_asm_output_data (DWARF_OFFSET_SIZE, AT_ref (a)->die_offset,
  7705. "%s", name);
  7706. }
  7707. break;
  7708. case dw_val_class_fde_ref:
  7709. {
  7710. char l1[20];
  7711. ASM_GENERATE_INTERNAL_LABEL (l1, FDE_LABEL,
  7712. a->dw_attr_val.v.val_fde_index * 2);
  7713. dw2_asm_output_offset (DWARF_OFFSET_SIZE, l1, debug_frame_section,
  7714. "%s", name);
  7715. }
  7716. break;
  7717. case dw_val_class_vms_delta:
  7718. #ifdef ASM_OUTPUT_DWARF_VMS_DELTA
  7719. dw2_asm_output_vms_delta (DWARF_OFFSET_SIZE,
  7720. AT_vms_delta2 (a), AT_vms_delta1 (a),
  7721. "%s", name);
  7722. #else
  7723. dw2_asm_output_delta (DWARF_OFFSET_SIZE,
  7724. AT_vms_delta2 (a), AT_vms_delta1 (a),
  7725. "%s", name);
  7726. #endif
  7727. break;
  7728. case dw_val_class_lbl_id:
  7729. output_attr_index_or_value (a);
  7730. break;
  7731. case dw_val_class_lineptr:
  7732. dw2_asm_output_offset (DWARF_OFFSET_SIZE, AT_lbl (a),
  7733. debug_line_section, "%s", name);
  7734. break;
  7735. case dw_val_class_macptr:
  7736. dw2_asm_output_offset (DWARF_OFFSET_SIZE, AT_lbl (a),
  7737. debug_macinfo_section, "%s", name);
  7738. break;
  7739. case dw_val_class_str:
  7740. if (a->dw_attr_val.v.val_str->form == DW_FORM_strp)
  7741. dw2_asm_output_offset (DWARF_OFFSET_SIZE,
  7742. a->dw_attr_val.v.val_str->label,
  7743. debug_str_section,
  7744. "%s: \"%s\"", name, AT_string (a));
  7745. else if (a->dw_attr_val.v.val_str->form == DW_FORM_GNU_str_index)
  7746. dw2_asm_output_data_uleb128 (AT_index (a),
  7747. "%s: \"%s\"", name, AT_string (a));
  7748. else
  7749. dw2_asm_output_nstring (AT_string (a), -1, "%s", name);
  7750. break;
  7751. case dw_val_class_file:
  7752. {
  7753. int f = maybe_emit_file (a->dw_attr_val.v.val_file);
  7754. dw2_asm_output_data (constant_size (f), f, "%s (%s)", name,
  7755. a->dw_attr_val.v.val_file->filename);
  7756. break;
  7757. }
  7758. case dw_val_class_data8:
  7759. {
  7760. int i;
  7761. for (i = 0; i < 8; i++)
  7762. dw2_asm_output_data (1, a->dw_attr_val.v.val_data8[i],
  7763. i == 0 ? "%s" : NULL, name);
  7764. break;
  7765. }
  7766. case dw_val_class_high_pc:
  7767. dw2_asm_output_delta (DWARF2_ADDR_SIZE, AT_lbl (a),
  7768. get_AT_low_pc (die), "DW_AT_high_pc");
  7769. break;
  7770. default:
  7771. gcc_unreachable ();
  7772. }
  7773. }
  7774. FOR_EACH_CHILD (die, c, output_die (c));
  7775. /* Add null byte to terminate sibling list. */
  7776. if (die->die_child != NULL)
  7777. dw2_asm_output_data (1, 0, "end of children of DIE %#lx",
  7778. (unsigned long) die->die_offset);
  7779. }
  7780. /* Output the compilation unit that appears at the beginning of the
  7781. .debug_info section, and precedes the DIE descriptions. */
  7782. static void
  7783. output_compilation_unit_header (void)
  7784. {
  7785. /* We don't support actual DWARFv5 units yet, we just use some
  7786. DWARFv5 draft DIE tags in DWARFv4 format. */
  7787. int ver = dwarf_version < 5 ? dwarf_version : 4;
  7788. if (DWARF_INITIAL_LENGTH_SIZE - DWARF_OFFSET_SIZE == 4)
  7789. dw2_asm_output_data (4, 0xffffffff,
  7790. "Initial length escape value indicating 64-bit DWARF extension");
  7791. dw2_asm_output_data (DWARF_OFFSET_SIZE,
  7792. next_die_offset - DWARF_INITIAL_LENGTH_SIZE,
  7793. "Length of Compilation Unit Info");
  7794. dw2_asm_output_data (2, ver, "DWARF version number");
  7795. dw2_asm_output_offset (DWARF_OFFSET_SIZE, abbrev_section_label,
  7796. debug_abbrev_section,
  7797. "Offset Into Abbrev. Section");
  7798. dw2_asm_output_data (1, DWARF2_ADDR_SIZE, "Pointer Size (in bytes)");
  7799. }
  7800. /* Output the compilation unit DIE and its children. */
  7801. static void
  7802. output_comp_unit (dw_die_ref die, int output_if_empty)
  7803. {
  7804. const char *secname, *oldsym;
  7805. char *tmp;
  7806. /* Unless we are outputting main CU, we may throw away empty ones. */
  7807. if (!output_if_empty && die->die_child == NULL)
  7808. return;
  7809. /* Even if there are no children of this DIE, we must output the information
  7810. about the compilation unit. Otherwise, on an empty translation unit, we
  7811. will generate a present, but empty, .debug_info section. IRIX 6.5 `nm'
  7812. will then complain when examining the file. First mark all the DIEs in
  7813. this CU so we know which get local refs. */
  7814. mark_dies (die);
  7815. external_ref_hash_type *extern_map = optimize_external_refs (die);
  7816. build_abbrev_table (die, extern_map);
  7817. delete extern_map;
  7818. /* Initialize the beginning DIE offset - and calculate sizes/offsets. */
  7819. next_die_offset = DWARF_COMPILE_UNIT_HEADER_SIZE;
  7820. calc_die_sizes (die);
  7821. oldsym = die->die_id.die_symbol;
  7822. if (oldsym)
  7823. {
  7824. tmp = XALLOCAVEC (char, strlen (oldsym) + 24);
  7825. sprintf (tmp, ".gnu.linkonce.wi.%s", oldsym);
  7826. secname = tmp;
  7827. die->die_id.die_symbol = NULL;
  7828. switch_to_section (get_section (secname, SECTION_DEBUG, NULL));
  7829. }
  7830. else
  7831. {
  7832. switch_to_section (debug_info_section);
  7833. ASM_OUTPUT_LABEL (asm_out_file, debug_info_section_label);
  7834. info_section_emitted = true;
  7835. }
  7836. /* Output debugging information. */
  7837. output_compilation_unit_header ();
  7838. output_die (die);
  7839. /* Leave the marks on the main CU, so we can check them in
  7840. output_pubnames. */
  7841. if (oldsym)
  7842. {
  7843. unmark_dies (die);
  7844. die->die_id.die_symbol = oldsym;
  7845. }
  7846. }
  7847. /* Whether to generate the DWARF accelerator tables in .debug_pubnames
  7848. and .debug_pubtypes. This is configured per-target, but can be
  7849. overridden by the -gpubnames or -gno-pubnames options. */
  7850. static inline bool
  7851. want_pubnames (void)
  7852. {
  7853. if (debug_info_level <= DINFO_LEVEL_TERSE)
  7854. return false;
  7855. if (debug_generate_pub_sections != -1)
  7856. return debug_generate_pub_sections;
  7857. return targetm.want_debug_pub_sections;
  7858. }
  7859. /* Add the DW_AT_GNU_pubnames and DW_AT_GNU_pubtypes attributes. */
  7860. static void
  7861. add_AT_pubnames (dw_die_ref die)
  7862. {
  7863. if (want_pubnames ())
  7864. add_AT_flag (die, DW_AT_GNU_pubnames, 1);
  7865. }
  7866. /* Add a string attribute value to a skeleton DIE. */
  7867. static inline void
  7868. add_skeleton_AT_string (dw_die_ref die, enum dwarf_attribute attr_kind,
  7869. const char *str)
  7870. {
  7871. dw_attr_node attr;
  7872. struct indirect_string_node *node;
  7873. if (! skeleton_debug_str_hash)
  7874. skeleton_debug_str_hash
  7875. = hash_table<indirect_string_hasher>::create_ggc (10);
  7876. node = find_AT_string_in_table (str, skeleton_debug_str_hash);
  7877. find_string_form (node);
  7878. if (node->form == DW_FORM_GNU_str_index)
  7879. node->form = DW_FORM_strp;
  7880. attr.dw_attr = attr_kind;
  7881. attr.dw_attr_val.val_class = dw_val_class_str;
  7882. attr.dw_attr_val.val_entry = NULL;
  7883. attr.dw_attr_val.v.val_str = node;
  7884. add_dwarf_attr (die, &attr);
  7885. }
  7886. /* Helper function to generate top-level dies for skeleton debug_info and
  7887. debug_types. */
  7888. static void
  7889. add_top_level_skeleton_die_attrs (dw_die_ref die)
  7890. {
  7891. const char *dwo_file_name = concat (aux_base_name, ".dwo", NULL);
  7892. const char *comp_dir = comp_dir_string ();
  7893. add_skeleton_AT_string (die, DW_AT_GNU_dwo_name, dwo_file_name);
  7894. if (comp_dir != NULL)
  7895. add_skeleton_AT_string (die, DW_AT_comp_dir, comp_dir);
  7896. add_AT_pubnames (die);
  7897. add_AT_lineptr (die, DW_AT_GNU_addr_base, debug_addr_section_label);
  7898. }
  7899. /* Output skeleton debug sections that point to the dwo file. */
  7900. static void
  7901. output_skeleton_debug_sections (dw_die_ref comp_unit)
  7902. {
  7903. /* We don't support actual DWARFv5 units yet, we just use some
  7904. DWARFv5 draft DIE tags in DWARFv4 format. */
  7905. int ver = dwarf_version < 5 ? dwarf_version : 4;
  7906. /* These attributes will be found in the full debug_info section. */
  7907. remove_AT (comp_unit, DW_AT_producer);
  7908. remove_AT (comp_unit, DW_AT_language);
  7909. switch_to_section (debug_skeleton_info_section);
  7910. ASM_OUTPUT_LABEL (asm_out_file, debug_skeleton_info_section_label);
  7911. /* Produce the skeleton compilation-unit header. This one differs enough from
  7912. a normal CU header that it's better not to call output_compilation_unit
  7913. header. */
  7914. if (DWARF_INITIAL_LENGTH_SIZE - DWARF_OFFSET_SIZE == 4)
  7915. dw2_asm_output_data (4, 0xffffffff,
  7916. "Initial length escape value indicating 64-bit DWARF extension");
  7917. dw2_asm_output_data (DWARF_OFFSET_SIZE,
  7918. DWARF_COMPILE_UNIT_HEADER_SIZE
  7919. - DWARF_INITIAL_LENGTH_SIZE
  7920. + size_of_die (comp_unit),
  7921. "Length of Compilation Unit Info");
  7922. dw2_asm_output_data (2, ver, "DWARF version number");
  7923. dw2_asm_output_offset (DWARF_OFFSET_SIZE, debug_skeleton_abbrev_section_label,
  7924. debug_abbrev_section,
  7925. "Offset Into Abbrev. Section");
  7926. dw2_asm_output_data (1, DWARF2_ADDR_SIZE, "Pointer Size (in bytes)");
  7927. comp_unit->die_abbrev = SKELETON_COMP_DIE_ABBREV;
  7928. output_die (comp_unit);
  7929. /* Build the skeleton debug_abbrev section. */
  7930. switch_to_section (debug_skeleton_abbrev_section);
  7931. ASM_OUTPUT_LABEL (asm_out_file, debug_skeleton_abbrev_section_label);
  7932. output_die_abbrevs (SKELETON_COMP_DIE_ABBREV, comp_unit);
  7933. dw2_asm_output_data (1, 0, "end of skeleton .debug_abbrev");
  7934. }
  7935. /* Output a comdat type unit DIE and its children. */
  7936. static void
  7937. output_comdat_type_unit (comdat_type_node *node)
  7938. {
  7939. const char *secname;
  7940. char *tmp;
  7941. int i;
  7942. #if defined (OBJECT_FORMAT_ELF)
  7943. tree comdat_key;
  7944. #endif
  7945. /* First mark all the DIEs in this CU so we know which get local refs. */
  7946. mark_dies (node->root_die);
  7947. external_ref_hash_type *extern_map = optimize_external_refs (node->root_die);
  7948. build_abbrev_table (node->root_die, extern_map);
  7949. delete extern_map;
  7950. extern_map = NULL;
  7951. /* Initialize the beginning DIE offset - and calculate sizes/offsets. */
  7952. next_die_offset = DWARF_COMDAT_TYPE_UNIT_HEADER_SIZE;
  7953. calc_die_sizes (node->root_die);
  7954. #if defined (OBJECT_FORMAT_ELF)
  7955. if (!dwarf_split_debug_info)
  7956. secname = ".debug_types";
  7957. else
  7958. secname = ".debug_types.dwo";
  7959. tmp = XALLOCAVEC (char, 4 + DWARF_TYPE_SIGNATURE_SIZE * 2);
  7960. sprintf (tmp, "wt.");
  7961. for (i = 0; i < DWARF_TYPE_SIGNATURE_SIZE; i++)
  7962. sprintf (tmp + 3 + i * 2, "%02x", node->signature[i] & 0xff);
  7963. comdat_key = get_identifier (tmp);
  7964. targetm.asm_out.named_section (secname,
  7965. SECTION_DEBUG | SECTION_LINKONCE,
  7966. comdat_key);
  7967. #else
  7968. tmp = XALLOCAVEC (char, 18 + DWARF_TYPE_SIGNATURE_SIZE * 2);
  7969. sprintf (tmp, ".gnu.linkonce.wt.");
  7970. for (i = 0; i < DWARF_TYPE_SIGNATURE_SIZE; i++)
  7971. sprintf (tmp + 17 + i * 2, "%02x", node->signature[i] & 0xff);
  7972. secname = tmp;
  7973. switch_to_section (get_section (secname, SECTION_DEBUG, NULL));
  7974. #endif
  7975. /* Output debugging information. */
  7976. output_compilation_unit_header ();
  7977. output_signature (node->signature, "Type Signature");
  7978. dw2_asm_output_data (DWARF_OFFSET_SIZE, node->type_die->die_offset,
  7979. "Offset to Type DIE");
  7980. output_die (node->root_die);
  7981. unmark_dies (node->root_die);
  7982. }
  7983. /* Return the DWARF2/3 pubname associated with a decl. */
  7984. static const char *
  7985. dwarf2_name (tree decl, int scope)
  7986. {
  7987. if (DECL_NAMELESS (decl))
  7988. return NULL;
  7989. return lang_hooks.dwarf_name (decl, scope ? 1 : 0);
  7990. }
  7991. /* Add a new entry to .debug_pubnames if appropriate. */
  7992. static void
  7993. add_pubname_string (const char *str, dw_die_ref die)
  7994. {
  7995. pubname_entry e;
  7996. e.die = die;
  7997. e.name = xstrdup (str);
  7998. vec_safe_push (pubname_table, e);
  7999. }
  8000. static void
  8001. add_pubname (tree decl, dw_die_ref die)
  8002. {
  8003. if (!want_pubnames ())
  8004. return;
  8005. /* Don't add items to the table when we expect that the consumer will have
  8006. just read the enclosing die. For example, if the consumer is looking at a
  8007. class_member, it will either be inside the class already, or will have just
  8008. looked up the class to find the member. Either way, searching the class is
  8009. faster than searching the index. */
  8010. if ((TREE_PUBLIC (decl) && !class_scope_p (die->die_parent))
  8011. || is_cu_die (die->die_parent) || is_namespace_die (die->die_parent))
  8012. {
  8013. const char *name = dwarf2_name (decl, 1);
  8014. if (name)
  8015. add_pubname_string (name, die);
  8016. }
  8017. }
  8018. /* Add an enumerator to the pubnames section. */
  8019. static void
  8020. add_enumerator_pubname (const char *scope_name, dw_die_ref die)
  8021. {
  8022. pubname_entry e;
  8023. gcc_assert (scope_name);
  8024. e.name = concat (scope_name, get_AT_string (die, DW_AT_name), NULL);
  8025. e.die = die;
  8026. vec_safe_push (pubname_table, e);
  8027. }
  8028. /* Add a new entry to .debug_pubtypes if appropriate. */
  8029. static void
  8030. add_pubtype (tree decl, dw_die_ref die)
  8031. {
  8032. pubname_entry e;
  8033. if (!want_pubnames ())
  8034. return;
  8035. if ((TREE_PUBLIC (decl)
  8036. || is_cu_die (die->die_parent) || is_namespace_die (die->die_parent))
  8037. && (die->die_tag == DW_TAG_typedef || COMPLETE_TYPE_P (decl)))
  8038. {
  8039. tree scope = NULL;
  8040. const char *scope_name = "";
  8041. const char *sep = is_cxx () ? "::" : ".";
  8042. const char *name;
  8043. scope = TYPE_P (decl) ? TYPE_CONTEXT (decl) : NULL;
  8044. if (scope && TREE_CODE (scope) == NAMESPACE_DECL)
  8045. {
  8046. scope_name = lang_hooks.dwarf_name (scope, 1);
  8047. if (scope_name != NULL && scope_name[0] != '\0')
  8048. scope_name = concat (scope_name, sep, NULL);
  8049. else
  8050. scope_name = "";
  8051. }
  8052. if (TYPE_P (decl))
  8053. name = type_tag (decl);
  8054. else
  8055. name = lang_hooks.dwarf_name (decl, 1);
  8056. /* If we don't have a name for the type, there's no point in adding
  8057. it to the table. */
  8058. if (name != NULL && name[0] != '\0')
  8059. {
  8060. e.die = die;
  8061. e.name = concat (scope_name, name, NULL);
  8062. vec_safe_push (pubtype_table, e);
  8063. }
  8064. /* Although it might be more consistent to add the pubinfo for the
  8065. enumerators as their dies are created, they should only be added if the
  8066. enum type meets the criteria above. So rather than re-check the parent
  8067. enum type whenever an enumerator die is created, just output them all
  8068. here. This isn't protected by the name conditional because anonymous
  8069. enums don't have names. */
  8070. if (die->die_tag == DW_TAG_enumeration_type)
  8071. {
  8072. dw_die_ref c;
  8073. FOR_EACH_CHILD (die, c, add_enumerator_pubname (scope_name, c));
  8074. }
  8075. }
  8076. }
  8077. /* Output a single entry in the pubnames table. */
  8078. static void
  8079. output_pubname (dw_offset die_offset, pubname_entry *entry)
  8080. {
  8081. dw_die_ref die = entry->die;
  8082. int is_static = get_AT_flag (die, DW_AT_external) ? 0 : 1;
  8083. dw2_asm_output_data (DWARF_OFFSET_SIZE, die_offset, "DIE offset");
  8084. if (debug_generate_pub_sections == 2)
  8085. {
  8086. /* This logic follows gdb's method for determining the value of the flag
  8087. byte. */
  8088. uint32_t flags = GDB_INDEX_SYMBOL_KIND_NONE;
  8089. switch (die->die_tag)
  8090. {
  8091. case DW_TAG_typedef:
  8092. case DW_TAG_base_type:
  8093. case DW_TAG_subrange_type:
  8094. GDB_INDEX_SYMBOL_KIND_SET_VALUE(flags, GDB_INDEX_SYMBOL_KIND_TYPE);
  8095. GDB_INDEX_SYMBOL_STATIC_SET_VALUE(flags, 1);
  8096. break;
  8097. case DW_TAG_enumerator:
  8098. GDB_INDEX_SYMBOL_KIND_SET_VALUE(flags,
  8099. GDB_INDEX_SYMBOL_KIND_VARIABLE);
  8100. if (!is_cxx () && !is_java ())
  8101. GDB_INDEX_SYMBOL_STATIC_SET_VALUE(flags, 1);
  8102. break;
  8103. case DW_TAG_subprogram:
  8104. GDB_INDEX_SYMBOL_KIND_SET_VALUE(flags,
  8105. GDB_INDEX_SYMBOL_KIND_FUNCTION);
  8106. if (!is_ada ())
  8107. GDB_INDEX_SYMBOL_STATIC_SET_VALUE(flags, is_static);
  8108. break;
  8109. case DW_TAG_constant:
  8110. GDB_INDEX_SYMBOL_KIND_SET_VALUE(flags,
  8111. GDB_INDEX_SYMBOL_KIND_VARIABLE);
  8112. GDB_INDEX_SYMBOL_STATIC_SET_VALUE(flags, is_static);
  8113. break;
  8114. case DW_TAG_variable:
  8115. GDB_INDEX_SYMBOL_KIND_SET_VALUE(flags,
  8116. GDB_INDEX_SYMBOL_KIND_VARIABLE);
  8117. GDB_INDEX_SYMBOL_STATIC_SET_VALUE(flags, is_static);
  8118. break;
  8119. case DW_TAG_namespace:
  8120. case DW_TAG_imported_declaration:
  8121. GDB_INDEX_SYMBOL_KIND_SET_VALUE(flags, GDB_INDEX_SYMBOL_KIND_TYPE);
  8122. break;
  8123. case DW_TAG_class_type:
  8124. case DW_TAG_interface_type:
  8125. case DW_TAG_structure_type:
  8126. case DW_TAG_union_type:
  8127. case DW_TAG_enumeration_type:
  8128. GDB_INDEX_SYMBOL_KIND_SET_VALUE(flags, GDB_INDEX_SYMBOL_KIND_TYPE);
  8129. if (!is_cxx () && !is_java ())
  8130. GDB_INDEX_SYMBOL_STATIC_SET_VALUE(flags, 1);
  8131. break;
  8132. default:
  8133. /* An unusual tag. Leave the flag-byte empty. */
  8134. break;
  8135. }
  8136. dw2_asm_output_data (1, flags >> GDB_INDEX_CU_BITSIZE,
  8137. "GDB-index flags");
  8138. }
  8139. dw2_asm_output_nstring (entry->name, -1, "external name");
  8140. }
  8141. /* Output the public names table used to speed up access to externally
  8142. visible names; or the public types table used to find type definitions. */
  8143. static void
  8144. output_pubnames (vec<pubname_entry, va_gc> *names)
  8145. {
  8146. unsigned i;
  8147. unsigned long pubnames_length = size_of_pubnames (names);
  8148. pubname_ref pub;
  8149. if (DWARF_INITIAL_LENGTH_SIZE - DWARF_OFFSET_SIZE == 4)
  8150. dw2_asm_output_data (4, 0xffffffff,
  8151. "Initial length escape value indicating 64-bit DWARF extension");
  8152. dw2_asm_output_data (DWARF_OFFSET_SIZE, pubnames_length, "Pub Info Length");
  8153. /* Version number for pubnames/pubtypes is independent of dwarf version. */
  8154. dw2_asm_output_data (2, 2, "DWARF Version");
  8155. if (dwarf_split_debug_info)
  8156. dw2_asm_output_offset (DWARF_OFFSET_SIZE, debug_skeleton_info_section_label,
  8157. debug_skeleton_info_section,
  8158. "Offset of Compilation Unit Info");
  8159. else
  8160. dw2_asm_output_offset (DWARF_OFFSET_SIZE, debug_info_section_label,
  8161. debug_info_section,
  8162. "Offset of Compilation Unit Info");
  8163. dw2_asm_output_data (DWARF_OFFSET_SIZE, next_die_offset,
  8164. "Compilation Unit Length");
  8165. FOR_EACH_VEC_ELT (*names, i, pub)
  8166. {
  8167. if (include_pubname_in_output (names, pub))
  8168. {
  8169. dw_offset die_offset = pub->die->die_offset;
  8170. /* We shouldn't see pubnames for DIEs outside of the main CU. */
  8171. if (names == pubname_table && pub->die->die_tag != DW_TAG_enumerator)
  8172. gcc_assert (pub->die->die_mark);
  8173. /* If we're putting types in their own .debug_types sections,
  8174. the .debug_pubtypes table will still point to the compile
  8175. unit (not the type unit), so we want to use the offset of
  8176. the skeleton DIE (if there is one). */
  8177. if (pub->die->comdat_type_p && names == pubtype_table)
  8178. {
  8179. comdat_type_node_ref type_node = pub->die->die_id.die_type_node;
  8180. if (type_node != NULL)
  8181. die_offset = (type_node->skeleton_die != NULL
  8182. ? type_node->skeleton_die->die_offset
  8183. : comp_unit_die ()->die_offset);
  8184. }
  8185. output_pubname (die_offset, pub);
  8186. }
  8187. }
  8188. dw2_asm_output_data (DWARF_OFFSET_SIZE, 0, NULL);
  8189. }
  8190. /* Output public names and types tables if necessary. */
  8191. static void
  8192. output_pubtables (void)
  8193. {
  8194. if (!want_pubnames () || !info_section_emitted)
  8195. return;
  8196. switch_to_section (debug_pubnames_section);
  8197. output_pubnames (pubname_table);
  8198. /* ??? Only defined by DWARF3, but emitted by Darwin for DWARF2.
  8199. It shouldn't hurt to emit it always, since pure DWARF2 consumers
  8200. simply won't look for the section. */
  8201. switch_to_section (debug_pubtypes_section);
  8202. output_pubnames (pubtype_table);
  8203. }
  8204. /* Output the information that goes into the .debug_aranges table.
  8205. Namely, define the beginning and ending address range of the
  8206. text section generated for this compilation unit. */
  8207. static void
  8208. output_aranges (unsigned long aranges_length)
  8209. {
  8210. unsigned i;
  8211. if (DWARF_INITIAL_LENGTH_SIZE - DWARF_OFFSET_SIZE == 4)
  8212. dw2_asm_output_data (4, 0xffffffff,
  8213. "Initial length escape value indicating 64-bit DWARF extension");
  8214. dw2_asm_output_data (DWARF_OFFSET_SIZE, aranges_length,
  8215. "Length of Address Ranges Info");
  8216. /* Version number for aranges is still 2, even up to DWARF5. */
  8217. dw2_asm_output_data (2, 2, "DWARF Version");
  8218. if (dwarf_split_debug_info)
  8219. dw2_asm_output_offset (DWARF_OFFSET_SIZE, debug_skeleton_info_section_label,
  8220. debug_skeleton_info_section,
  8221. "Offset of Compilation Unit Info");
  8222. else
  8223. dw2_asm_output_offset (DWARF_OFFSET_SIZE, debug_info_section_label,
  8224. debug_info_section,
  8225. "Offset of Compilation Unit Info");
  8226. dw2_asm_output_data (1, DWARF2_ADDR_SIZE, "Size of Address");
  8227. dw2_asm_output_data (1, 0, "Size of Segment Descriptor");
  8228. /* We need to align to twice the pointer size here. */
  8229. if (DWARF_ARANGES_PAD_SIZE)
  8230. {
  8231. /* Pad using a 2 byte words so that padding is correct for any
  8232. pointer size. */
  8233. dw2_asm_output_data (2, 0, "Pad to %d byte boundary",
  8234. 2 * DWARF2_ADDR_SIZE);
  8235. for (i = 2; i < (unsigned) DWARF_ARANGES_PAD_SIZE; i += 2)
  8236. dw2_asm_output_data (2, 0, NULL);
  8237. }
  8238. /* It is necessary not to output these entries if the sections were
  8239. not used; if the sections were not used, the length will be 0 and
  8240. the address may end up as 0 if the section is discarded by ld
  8241. --gc-sections, leaving an invalid (0, 0) entry that can be
  8242. confused with the terminator. */
  8243. if (text_section_used)
  8244. {
  8245. dw2_asm_output_addr (DWARF2_ADDR_SIZE, text_section_label, "Address");
  8246. dw2_asm_output_delta (DWARF2_ADDR_SIZE, text_end_label,
  8247. text_section_label, "Length");
  8248. }
  8249. if (cold_text_section_used)
  8250. {
  8251. dw2_asm_output_addr (DWARF2_ADDR_SIZE, cold_text_section_label,
  8252. "Address");
  8253. dw2_asm_output_delta (DWARF2_ADDR_SIZE, cold_end_label,
  8254. cold_text_section_label, "Length");
  8255. }
  8256. if (have_multiple_function_sections)
  8257. {
  8258. unsigned fde_idx;
  8259. dw_fde_ref fde;
  8260. FOR_EACH_VEC_ELT (*fde_vec, fde_idx, fde)
  8261. {
  8262. if (DECL_IGNORED_P (fde->decl))
  8263. continue;
  8264. if (!fde->in_std_section)
  8265. {
  8266. dw2_asm_output_addr (DWARF2_ADDR_SIZE, fde->dw_fde_begin,
  8267. "Address");
  8268. dw2_asm_output_delta (DWARF2_ADDR_SIZE, fde->dw_fde_end,
  8269. fde->dw_fde_begin, "Length");
  8270. }
  8271. if (fde->dw_fde_second_begin && !fde->second_in_std_section)
  8272. {
  8273. dw2_asm_output_addr (DWARF2_ADDR_SIZE, fde->dw_fde_second_begin,
  8274. "Address");
  8275. dw2_asm_output_delta (DWARF2_ADDR_SIZE, fde->dw_fde_second_end,
  8276. fde->dw_fde_second_begin, "Length");
  8277. }
  8278. }
  8279. }
  8280. /* Output the terminator words. */
  8281. dw2_asm_output_data (DWARF2_ADDR_SIZE, 0, NULL);
  8282. dw2_asm_output_data (DWARF2_ADDR_SIZE, 0, NULL);
  8283. }
  8284. /* Add a new entry to .debug_ranges. Return the offset at which it
  8285. was placed. */
  8286. static unsigned int
  8287. add_ranges_num (int num)
  8288. {
  8289. unsigned int in_use = ranges_table_in_use;
  8290. if (in_use == ranges_table_allocated)
  8291. {
  8292. ranges_table_allocated += RANGES_TABLE_INCREMENT;
  8293. ranges_table = GGC_RESIZEVEC (struct dw_ranges_struct, ranges_table,
  8294. ranges_table_allocated);
  8295. memset (ranges_table + ranges_table_in_use, 0,
  8296. RANGES_TABLE_INCREMENT * sizeof (struct dw_ranges_struct));
  8297. }
  8298. ranges_table[in_use].num = num;
  8299. ranges_table_in_use = in_use + 1;
  8300. return in_use * 2 * DWARF2_ADDR_SIZE;
  8301. }
  8302. /* Add a new entry to .debug_ranges corresponding to a block, or a
  8303. range terminator if BLOCK is NULL. */
  8304. static unsigned int
  8305. add_ranges (const_tree block)
  8306. {
  8307. return add_ranges_num (block ? BLOCK_NUMBER (block) : 0);
  8308. }
  8309. /* Add a new entry to .debug_ranges corresponding to a pair of labels.
  8310. When using dwarf_split_debug_info, address attributes in dies destined
  8311. for the final executable should be direct references--setting the
  8312. parameter force_direct ensures this behavior. */
  8313. static void
  8314. add_ranges_by_labels (dw_die_ref die, const char *begin, const char *end,
  8315. bool *added, bool force_direct)
  8316. {
  8317. unsigned int in_use = ranges_by_label_in_use;
  8318. unsigned int offset;
  8319. if (in_use == ranges_by_label_allocated)
  8320. {
  8321. ranges_by_label_allocated += RANGES_TABLE_INCREMENT;
  8322. ranges_by_label = GGC_RESIZEVEC (struct dw_ranges_by_label_struct,
  8323. ranges_by_label,
  8324. ranges_by_label_allocated);
  8325. memset (ranges_by_label + ranges_by_label_in_use, 0,
  8326. RANGES_TABLE_INCREMENT
  8327. * sizeof (struct dw_ranges_by_label_struct));
  8328. }
  8329. ranges_by_label[in_use].begin = begin;
  8330. ranges_by_label[in_use].end = end;
  8331. ranges_by_label_in_use = in_use + 1;
  8332. offset = add_ranges_num (-(int)in_use - 1);
  8333. if (!*added)
  8334. {
  8335. add_AT_range_list (die, DW_AT_ranges, offset, force_direct);
  8336. *added = true;
  8337. }
  8338. }
  8339. static void
  8340. output_ranges (void)
  8341. {
  8342. unsigned i;
  8343. static const char *const start_fmt = "Offset %#x";
  8344. const char *fmt = start_fmt;
  8345. for (i = 0; i < ranges_table_in_use; i++)
  8346. {
  8347. int block_num = ranges_table[i].num;
  8348. if (block_num > 0)
  8349. {
  8350. char blabel[MAX_ARTIFICIAL_LABEL_BYTES];
  8351. char elabel[MAX_ARTIFICIAL_LABEL_BYTES];
  8352. ASM_GENERATE_INTERNAL_LABEL (blabel, BLOCK_BEGIN_LABEL, block_num);
  8353. ASM_GENERATE_INTERNAL_LABEL (elabel, BLOCK_END_LABEL, block_num);
  8354. /* If all code is in the text section, then the compilation
  8355. unit base address defaults to DW_AT_low_pc, which is the
  8356. base of the text section. */
  8357. if (!have_multiple_function_sections)
  8358. {
  8359. dw2_asm_output_delta (DWARF2_ADDR_SIZE, blabel,
  8360. text_section_label,
  8361. fmt, i * 2 * DWARF2_ADDR_SIZE);
  8362. dw2_asm_output_delta (DWARF2_ADDR_SIZE, elabel,
  8363. text_section_label, NULL);
  8364. }
  8365. /* Otherwise, the compilation unit base address is zero,
  8366. which allows us to use absolute addresses, and not worry
  8367. about whether the target supports cross-section
  8368. arithmetic. */
  8369. else
  8370. {
  8371. dw2_asm_output_addr (DWARF2_ADDR_SIZE, blabel,
  8372. fmt, i * 2 * DWARF2_ADDR_SIZE);
  8373. dw2_asm_output_addr (DWARF2_ADDR_SIZE, elabel, NULL);
  8374. }
  8375. fmt = NULL;
  8376. }
  8377. /* Negative block_num stands for an index into ranges_by_label. */
  8378. else if (block_num < 0)
  8379. {
  8380. int lab_idx = - block_num - 1;
  8381. if (!have_multiple_function_sections)
  8382. {
  8383. gcc_unreachable ();
  8384. #if 0
  8385. /* If we ever use add_ranges_by_labels () for a single
  8386. function section, all we have to do is to take out
  8387. the #if 0 above. */
  8388. dw2_asm_output_delta (DWARF2_ADDR_SIZE,
  8389. ranges_by_label[lab_idx].begin,
  8390. text_section_label,
  8391. fmt, i * 2 * DWARF2_ADDR_SIZE);
  8392. dw2_asm_output_delta (DWARF2_ADDR_SIZE,
  8393. ranges_by_label[lab_idx].end,
  8394. text_section_label, NULL);
  8395. #endif
  8396. }
  8397. else
  8398. {
  8399. dw2_asm_output_addr (DWARF2_ADDR_SIZE,
  8400. ranges_by_label[lab_idx].begin,
  8401. fmt, i * 2 * DWARF2_ADDR_SIZE);
  8402. dw2_asm_output_addr (DWARF2_ADDR_SIZE,
  8403. ranges_by_label[lab_idx].end,
  8404. NULL);
  8405. }
  8406. }
  8407. else
  8408. {
  8409. dw2_asm_output_data (DWARF2_ADDR_SIZE, 0, NULL);
  8410. dw2_asm_output_data (DWARF2_ADDR_SIZE, 0, NULL);
  8411. fmt = start_fmt;
  8412. }
  8413. }
  8414. }
  8415. /* Data structure containing information about input files. */
  8416. struct file_info
  8417. {
  8418. const char *path; /* Complete file name. */
  8419. const char *fname; /* File name part. */
  8420. int length; /* Length of entire string. */
  8421. struct dwarf_file_data * file_idx; /* Index in input file table. */
  8422. int dir_idx; /* Index in directory table. */
  8423. };
  8424. /* Data structure containing information about directories with source
  8425. files. */
  8426. struct dir_info
  8427. {
  8428. const char *path; /* Path including directory name. */
  8429. int length; /* Path length. */
  8430. int prefix; /* Index of directory entry which is a prefix. */
  8431. int count; /* Number of files in this directory. */
  8432. int dir_idx; /* Index of directory used as base. */
  8433. };
  8434. /* Callback function for file_info comparison. We sort by looking at
  8435. the directories in the path. */
  8436. static int
  8437. file_info_cmp (const void *p1, const void *p2)
  8438. {
  8439. const struct file_info *const s1 = (const struct file_info *) p1;
  8440. const struct file_info *const s2 = (const struct file_info *) p2;
  8441. const unsigned char *cp1;
  8442. const unsigned char *cp2;
  8443. /* Take care of file names without directories. We need to make sure that
  8444. we return consistent values to qsort since some will get confused if
  8445. we return the same value when identical operands are passed in opposite
  8446. orders. So if neither has a directory, return 0 and otherwise return
  8447. 1 or -1 depending on which one has the directory. */
  8448. if ((s1->path == s1->fname || s2->path == s2->fname))
  8449. return (s2->path == s2->fname) - (s1->path == s1->fname);
  8450. cp1 = (const unsigned char *) s1->path;
  8451. cp2 = (const unsigned char *) s2->path;
  8452. while (1)
  8453. {
  8454. ++cp1;
  8455. ++cp2;
  8456. /* Reached the end of the first path? If so, handle like above. */
  8457. if ((cp1 == (const unsigned char *) s1->fname)
  8458. || (cp2 == (const unsigned char *) s2->fname))
  8459. return ((cp2 == (const unsigned char *) s2->fname)
  8460. - (cp1 == (const unsigned char *) s1->fname));
  8461. /* Character of current path component the same? */
  8462. else if (*cp1 != *cp2)
  8463. return *cp1 - *cp2;
  8464. }
  8465. }
  8466. struct file_name_acquire_data
  8467. {
  8468. struct file_info *files;
  8469. int used_files;
  8470. int max_files;
  8471. };
  8472. /* Traversal function for the hash table. */
  8473. int
  8474. file_name_acquire (dwarf_file_data **slot, file_name_acquire_data *fnad)
  8475. {
  8476. struct dwarf_file_data *d = *slot;
  8477. struct file_info *fi;
  8478. const char *f;
  8479. gcc_assert (fnad->max_files >= d->emitted_number);
  8480. if (! d->emitted_number)
  8481. return 1;
  8482. gcc_assert (fnad->max_files != fnad->used_files);
  8483. fi = fnad->files + fnad->used_files++;
  8484. /* Skip all leading "./". */
  8485. f = d->filename;
  8486. while (f[0] == '.' && IS_DIR_SEPARATOR (f[1]))
  8487. f += 2;
  8488. /* Create a new array entry. */
  8489. fi->path = f;
  8490. fi->length = strlen (f);
  8491. fi->file_idx = d;
  8492. /* Search for the file name part. */
  8493. f = strrchr (f, DIR_SEPARATOR);
  8494. #if defined (DIR_SEPARATOR_2)
  8495. {
  8496. char *g = strrchr (fi->path, DIR_SEPARATOR_2);
  8497. if (g != NULL)
  8498. {
  8499. if (f == NULL || f < g)
  8500. f = g;
  8501. }
  8502. }
  8503. #endif
  8504. fi->fname = f == NULL ? fi->path : f + 1;
  8505. return 1;
  8506. }
  8507. /* Output the directory table and the file name table. We try to minimize
  8508. the total amount of memory needed. A heuristic is used to avoid large
  8509. slowdowns with many input files. */
  8510. static void
  8511. output_file_names (void)
  8512. {
  8513. struct file_name_acquire_data fnad;
  8514. int numfiles;
  8515. struct file_info *files;
  8516. struct dir_info *dirs;
  8517. int *saved;
  8518. int *savehere;
  8519. int *backmap;
  8520. int ndirs;
  8521. int idx_offset;
  8522. int i;
  8523. if (!last_emitted_file)
  8524. {
  8525. dw2_asm_output_data (1, 0, "End directory table");
  8526. dw2_asm_output_data (1, 0, "End file name table");
  8527. return;
  8528. }
  8529. numfiles = last_emitted_file->emitted_number;
  8530. /* Allocate the various arrays we need. */
  8531. files = XALLOCAVEC (struct file_info, numfiles);
  8532. dirs = XALLOCAVEC (struct dir_info, numfiles);
  8533. fnad.files = files;
  8534. fnad.used_files = 0;
  8535. fnad.max_files = numfiles;
  8536. file_table->traverse<file_name_acquire_data *, file_name_acquire> (&fnad);
  8537. gcc_assert (fnad.used_files == fnad.max_files);
  8538. qsort (files, numfiles, sizeof (files[0]), file_info_cmp);
  8539. /* Find all the different directories used. */
  8540. dirs[0].path = files[0].path;
  8541. dirs[0].length = files[0].fname - files[0].path;
  8542. dirs[0].prefix = -1;
  8543. dirs[0].count = 1;
  8544. dirs[0].dir_idx = 0;
  8545. files[0].dir_idx = 0;
  8546. ndirs = 1;
  8547. for (i = 1; i < numfiles; i++)
  8548. if (files[i].fname - files[i].path == dirs[ndirs - 1].length
  8549. && memcmp (dirs[ndirs - 1].path, files[i].path,
  8550. dirs[ndirs - 1].length) == 0)
  8551. {
  8552. /* Same directory as last entry. */
  8553. files[i].dir_idx = ndirs - 1;
  8554. ++dirs[ndirs - 1].count;
  8555. }
  8556. else
  8557. {
  8558. int j;
  8559. /* This is a new directory. */
  8560. dirs[ndirs].path = files[i].path;
  8561. dirs[ndirs].length = files[i].fname - files[i].path;
  8562. dirs[ndirs].count = 1;
  8563. dirs[ndirs].dir_idx = ndirs;
  8564. files[i].dir_idx = ndirs;
  8565. /* Search for a prefix. */
  8566. dirs[ndirs].prefix = -1;
  8567. for (j = 0; j < ndirs; j++)
  8568. if (dirs[j].length < dirs[ndirs].length
  8569. && dirs[j].length > 1
  8570. && (dirs[ndirs].prefix == -1
  8571. || dirs[j].length > dirs[dirs[ndirs].prefix].length)
  8572. && memcmp (dirs[j].path, dirs[ndirs].path, dirs[j].length) == 0)
  8573. dirs[ndirs].prefix = j;
  8574. ++ndirs;
  8575. }
  8576. /* Now to the actual work. We have to find a subset of the directories which
  8577. allow expressing the file name using references to the directory table
  8578. with the least amount of characters. We do not do an exhaustive search
  8579. where we would have to check out every combination of every single
  8580. possible prefix. Instead we use a heuristic which provides nearly optimal
  8581. results in most cases and never is much off. */
  8582. saved = XALLOCAVEC (int, ndirs);
  8583. savehere = XALLOCAVEC (int, ndirs);
  8584. memset (saved, '\0', ndirs * sizeof (saved[0]));
  8585. for (i = 0; i < ndirs; i++)
  8586. {
  8587. int j;
  8588. int total;
  8589. /* We can always save some space for the current directory. But this
  8590. does not mean it will be enough to justify adding the directory. */
  8591. savehere[i] = dirs[i].length;
  8592. total = (savehere[i] - saved[i]) * dirs[i].count;
  8593. for (j = i + 1; j < ndirs; j++)
  8594. {
  8595. savehere[j] = 0;
  8596. if (saved[j] < dirs[i].length)
  8597. {
  8598. /* Determine whether the dirs[i] path is a prefix of the
  8599. dirs[j] path. */
  8600. int k;
  8601. k = dirs[j].prefix;
  8602. while (k != -1 && k != (int) i)
  8603. k = dirs[k].prefix;
  8604. if (k == (int) i)
  8605. {
  8606. /* Yes it is. We can possibly save some memory by
  8607. writing the filenames in dirs[j] relative to
  8608. dirs[i]. */
  8609. savehere[j] = dirs[i].length;
  8610. total += (savehere[j] - saved[j]) * dirs[j].count;
  8611. }
  8612. }
  8613. }
  8614. /* Check whether we can save enough to justify adding the dirs[i]
  8615. directory. */
  8616. if (total > dirs[i].length + 1)
  8617. {
  8618. /* It's worthwhile adding. */
  8619. for (j = i; j < ndirs; j++)
  8620. if (savehere[j] > 0)
  8621. {
  8622. /* Remember how much we saved for this directory so far. */
  8623. saved[j] = savehere[j];
  8624. /* Remember the prefix directory. */
  8625. dirs[j].dir_idx = i;
  8626. }
  8627. }
  8628. }
  8629. /* Emit the directory name table. */
  8630. idx_offset = dirs[0].length > 0 ? 1 : 0;
  8631. for (i = 1 - idx_offset; i < ndirs; i++)
  8632. dw2_asm_output_nstring (dirs[i].path,
  8633. dirs[i].length
  8634. - !DWARF2_DIR_SHOULD_END_WITH_SEPARATOR,
  8635. "Directory Entry: %#x", i + idx_offset);
  8636. dw2_asm_output_data (1, 0, "End directory table");
  8637. /* We have to emit them in the order of emitted_number since that's
  8638. used in the debug info generation. To do this efficiently we
  8639. generate a back-mapping of the indices first. */
  8640. backmap = XALLOCAVEC (int, numfiles);
  8641. for (i = 0; i < numfiles; i++)
  8642. backmap[files[i].file_idx->emitted_number - 1] = i;
  8643. /* Now write all the file names. */
  8644. for (i = 0; i < numfiles; i++)
  8645. {
  8646. int file_idx = backmap[i];
  8647. int dir_idx = dirs[files[file_idx].dir_idx].dir_idx;
  8648. #ifdef VMS_DEBUGGING_INFO
  8649. #define MAX_VMS_VERSION_LEN 6 /* ";32768" */
  8650. /* Setting these fields can lead to debugger miscomparisons,
  8651. but VMS Debug requires them to be set correctly. */
  8652. int ver;
  8653. long long cdt;
  8654. long siz;
  8655. int maxfilelen = strlen (files[file_idx].path)
  8656. + dirs[dir_idx].length
  8657. + MAX_VMS_VERSION_LEN + 1;
  8658. char *filebuf = XALLOCAVEC (char, maxfilelen);
  8659. vms_file_stats_name (files[file_idx].path, 0, 0, 0, &ver);
  8660. snprintf (filebuf, maxfilelen, "%s;%d",
  8661. files[file_idx].path + dirs[dir_idx].length, ver);
  8662. dw2_asm_output_nstring
  8663. (filebuf, -1, "File Entry: %#x", (unsigned) i + 1);
  8664. /* Include directory index. */
  8665. dw2_asm_output_data_uleb128 (dir_idx + idx_offset, NULL);
  8666. /* Modification time. */
  8667. dw2_asm_output_data_uleb128
  8668. ((vms_file_stats_name (files[file_idx].path, &cdt, 0, 0, 0) == 0)
  8669. ? cdt : 0,
  8670. NULL);
  8671. /* File length in bytes. */
  8672. dw2_asm_output_data_uleb128
  8673. ((vms_file_stats_name (files[file_idx].path, 0, &siz, 0, 0) == 0)
  8674. ? siz : 0,
  8675. NULL);
  8676. #else
  8677. dw2_asm_output_nstring (files[file_idx].path + dirs[dir_idx].length, -1,
  8678. "File Entry: %#x", (unsigned) i + 1);
  8679. /* Include directory index. */
  8680. dw2_asm_output_data_uleb128 (dir_idx + idx_offset, NULL);
  8681. /* Modification time. */
  8682. dw2_asm_output_data_uleb128 (0, NULL);
  8683. /* File length in bytes. */
  8684. dw2_asm_output_data_uleb128 (0, NULL);
  8685. #endif /* VMS_DEBUGGING_INFO */
  8686. }
  8687. dw2_asm_output_data (1, 0, "End file name table");
  8688. }
  8689. /* Output one line number table into the .debug_line section. */
  8690. static void
  8691. output_one_line_info_table (dw_line_info_table *table)
  8692. {
  8693. char line_label[MAX_ARTIFICIAL_LABEL_BYTES];
  8694. unsigned int current_line = 1;
  8695. bool current_is_stmt = DWARF_LINE_DEFAULT_IS_STMT_START;
  8696. dw_line_info_entry *ent;
  8697. size_t i;
  8698. FOR_EACH_VEC_SAFE_ELT (table->entries, i, ent)
  8699. {
  8700. switch (ent->opcode)
  8701. {
  8702. case LI_set_address:
  8703. /* ??? Unfortunately, we have little choice here currently, and
  8704. must always use the most general form. GCC does not know the
  8705. address delta itself, so we can't use DW_LNS_advance_pc. Many
  8706. ports do have length attributes which will give an upper bound
  8707. on the address range. We could perhaps use length attributes
  8708. to determine when it is safe to use DW_LNS_fixed_advance_pc. */
  8709. ASM_GENERATE_INTERNAL_LABEL (line_label, LINE_CODE_LABEL, ent->val);
  8710. /* This can handle any delta. This takes
  8711. 4+DWARF2_ADDR_SIZE bytes. */
  8712. dw2_asm_output_data (1, 0, "set address %s", line_label);
  8713. dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE, NULL);
  8714. dw2_asm_output_data (1, DW_LNE_set_address, NULL);
  8715. dw2_asm_output_addr (DWARF2_ADDR_SIZE, line_label, NULL);
  8716. break;
  8717. case LI_set_line:
  8718. if (ent->val == current_line)
  8719. {
  8720. /* We still need to start a new row, so output a copy insn. */
  8721. dw2_asm_output_data (1, DW_LNS_copy,
  8722. "copy line %u", current_line);
  8723. }
  8724. else
  8725. {
  8726. int line_offset = ent->val - current_line;
  8727. int line_delta = line_offset - DWARF_LINE_BASE;
  8728. current_line = ent->val;
  8729. if (line_delta >= 0 && line_delta < (DWARF_LINE_RANGE - 1))
  8730. {
  8731. /* This can handle deltas from -10 to 234, using the current
  8732. definitions of DWARF_LINE_BASE and DWARF_LINE_RANGE.
  8733. This takes 1 byte. */
  8734. dw2_asm_output_data (1, DWARF_LINE_OPCODE_BASE + line_delta,
  8735. "line %u", current_line);
  8736. }
  8737. else
  8738. {
  8739. /* This can handle any delta. This takes at least 4 bytes,
  8740. depending on the value being encoded. */
  8741. dw2_asm_output_data (1, DW_LNS_advance_line,
  8742. "advance to line %u", current_line);
  8743. dw2_asm_output_data_sleb128 (line_offset, NULL);
  8744. dw2_asm_output_data (1, DW_LNS_copy, NULL);
  8745. }
  8746. }
  8747. break;
  8748. case LI_set_file:
  8749. dw2_asm_output_data (1, DW_LNS_set_file, "set file %u", ent->val);
  8750. dw2_asm_output_data_uleb128 (ent->val, "%u", ent->val);
  8751. break;
  8752. case LI_set_column:
  8753. dw2_asm_output_data (1, DW_LNS_set_column, "column %u", ent->val);
  8754. dw2_asm_output_data_uleb128 (ent->val, "%u", ent->val);
  8755. break;
  8756. case LI_negate_stmt:
  8757. current_is_stmt = !current_is_stmt;
  8758. dw2_asm_output_data (1, DW_LNS_negate_stmt,
  8759. "is_stmt %d", current_is_stmt);
  8760. break;
  8761. case LI_set_prologue_end:
  8762. dw2_asm_output_data (1, DW_LNS_set_prologue_end,
  8763. "set prologue end");
  8764. break;
  8765. case LI_set_epilogue_begin:
  8766. dw2_asm_output_data (1, DW_LNS_set_epilogue_begin,
  8767. "set epilogue begin");
  8768. break;
  8769. case LI_set_discriminator:
  8770. dw2_asm_output_data (1, 0, "discriminator %u", ent->val);
  8771. dw2_asm_output_data_uleb128 (1 + size_of_uleb128 (ent->val), NULL);
  8772. dw2_asm_output_data (1, DW_LNE_set_discriminator, NULL);
  8773. dw2_asm_output_data_uleb128 (ent->val, NULL);
  8774. break;
  8775. }
  8776. }
  8777. /* Emit debug info for the address of the end of the table. */
  8778. dw2_asm_output_data (1, 0, "set address %s", table->end_label);
  8779. dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE, NULL);
  8780. dw2_asm_output_data (1, DW_LNE_set_address, NULL);
  8781. dw2_asm_output_addr (DWARF2_ADDR_SIZE, table->end_label, NULL);
  8782. dw2_asm_output_data (1, 0, "end sequence");
  8783. dw2_asm_output_data_uleb128 (1, NULL);
  8784. dw2_asm_output_data (1, DW_LNE_end_sequence, NULL);
  8785. }
  8786. /* Output the source line number correspondence information. This
  8787. information goes into the .debug_line section. */
  8788. static void
  8789. output_line_info (bool prologue_only)
  8790. {
  8791. char l1[20], l2[20], p1[20], p2[20];
  8792. /* We don't support DWARFv5 line tables yet. */
  8793. int ver = dwarf_version < 5 ? dwarf_version : 4;
  8794. bool saw_one = false;
  8795. int opc;
  8796. ASM_GENERATE_INTERNAL_LABEL (l1, LINE_NUMBER_BEGIN_LABEL, 0);
  8797. ASM_GENERATE_INTERNAL_LABEL (l2, LINE_NUMBER_END_LABEL, 0);
  8798. ASM_GENERATE_INTERNAL_LABEL (p1, LN_PROLOG_AS_LABEL, 0);
  8799. ASM_GENERATE_INTERNAL_LABEL (p2, LN_PROLOG_END_LABEL, 0);
  8800. if (DWARF_INITIAL_LENGTH_SIZE - DWARF_OFFSET_SIZE == 4)
  8801. dw2_asm_output_data (4, 0xffffffff,
  8802. "Initial length escape value indicating 64-bit DWARF extension");
  8803. dw2_asm_output_delta (DWARF_OFFSET_SIZE, l2, l1,
  8804. "Length of Source Line Info");
  8805. ASM_OUTPUT_LABEL (asm_out_file, l1);
  8806. dw2_asm_output_data (2, ver, "DWARF Version");
  8807. dw2_asm_output_delta (DWARF_OFFSET_SIZE, p2, p1, "Prolog Length");
  8808. ASM_OUTPUT_LABEL (asm_out_file, p1);
  8809. /* Define the architecture-dependent minimum instruction length (in bytes).
  8810. In this implementation of DWARF, this field is used for information
  8811. purposes only. Since GCC generates assembly language, we have no
  8812. a priori knowledge of how many instruction bytes are generated for each
  8813. source line, and therefore can use only the DW_LNE_set_address and
  8814. DW_LNS_fixed_advance_pc line information commands. Accordingly, we fix
  8815. this as '1', which is "correct enough" for all architectures,
  8816. and don't let the target override. */
  8817. dw2_asm_output_data (1, 1, "Minimum Instruction Length");
  8818. if (ver >= 4)
  8819. dw2_asm_output_data (1, DWARF_LINE_DEFAULT_MAX_OPS_PER_INSN,
  8820. "Maximum Operations Per Instruction");
  8821. dw2_asm_output_data (1, DWARF_LINE_DEFAULT_IS_STMT_START,
  8822. "Default is_stmt_start flag");
  8823. dw2_asm_output_data (1, DWARF_LINE_BASE,
  8824. "Line Base Value (Special Opcodes)");
  8825. dw2_asm_output_data (1, DWARF_LINE_RANGE,
  8826. "Line Range Value (Special Opcodes)");
  8827. dw2_asm_output_data (1, DWARF_LINE_OPCODE_BASE,
  8828. "Special Opcode Base");
  8829. for (opc = 1; opc < DWARF_LINE_OPCODE_BASE; opc++)
  8830. {
  8831. int n_op_args;
  8832. switch (opc)
  8833. {
  8834. case DW_LNS_advance_pc:
  8835. case DW_LNS_advance_line:
  8836. case DW_LNS_set_file:
  8837. case DW_LNS_set_column:
  8838. case DW_LNS_fixed_advance_pc:
  8839. case DW_LNS_set_isa:
  8840. n_op_args = 1;
  8841. break;
  8842. default:
  8843. n_op_args = 0;
  8844. break;
  8845. }
  8846. dw2_asm_output_data (1, n_op_args, "opcode: %#x has %d args",
  8847. opc, n_op_args);
  8848. }
  8849. /* Write out the information about the files we use. */
  8850. output_file_names ();
  8851. ASM_OUTPUT_LABEL (asm_out_file, p2);
  8852. if (prologue_only)
  8853. {
  8854. /* Output the marker for the end of the line number info. */
  8855. ASM_OUTPUT_LABEL (asm_out_file, l2);
  8856. return;
  8857. }
  8858. if (separate_line_info)
  8859. {
  8860. dw_line_info_table *table;
  8861. size_t i;
  8862. FOR_EACH_VEC_ELT (*separate_line_info, i, table)
  8863. if (table->in_use)
  8864. {
  8865. output_one_line_info_table (table);
  8866. saw_one = true;
  8867. }
  8868. }
  8869. if (cold_text_section_line_info && cold_text_section_line_info->in_use)
  8870. {
  8871. output_one_line_info_table (cold_text_section_line_info);
  8872. saw_one = true;
  8873. }
  8874. /* ??? Some Darwin linkers crash on a .debug_line section with no
  8875. sequences. Further, merely a DW_LNE_end_sequence entry is not
  8876. sufficient -- the address column must also be initialized.
  8877. Make sure to output at least one set_address/end_sequence pair,
  8878. choosing .text since that section is always present. */
  8879. if (text_section_line_info->in_use || !saw_one)
  8880. output_one_line_info_table (text_section_line_info);
  8881. /* Output the marker for the end of the line number info. */
  8882. ASM_OUTPUT_LABEL (asm_out_file, l2);
  8883. }
  8884. /* Given a pointer to a tree node for some base type, return a pointer to
  8885. a DIE that describes the given type.
  8886. This routine must only be called for GCC type nodes that correspond to
  8887. Dwarf base (fundamental) types. */
  8888. static dw_die_ref
  8889. base_type_die (tree type)
  8890. {
  8891. dw_die_ref base_type_result;
  8892. enum dwarf_type encoding;
  8893. if (TREE_CODE (type) == ERROR_MARK || TREE_CODE (type) == VOID_TYPE)
  8894. return 0;
  8895. /* If this is a subtype that should not be emitted as a subrange type,
  8896. use the base type. See subrange_type_for_debug_p. */
  8897. if (TREE_CODE (type) == INTEGER_TYPE && TREE_TYPE (type) != NULL_TREE)
  8898. type = TREE_TYPE (type);
  8899. switch (TREE_CODE (type))
  8900. {
  8901. case INTEGER_TYPE:
  8902. if ((dwarf_version >= 4 || !dwarf_strict)
  8903. && TYPE_NAME (type)
  8904. && TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
  8905. && DECL_IS_BUILTIN (TYPE_NAME (type))
  8906. && DECL_NAME (TYPE_NAME (type)))
  8907. {
  8908. const char *name = IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (type)));
  8909. if (strcmp (name, "char16_t") == 0
  8910. || strcmp (name, "char32_t") == 0)
  8911. {
  8912. encoding = DW_ATE_UTF;
  8913. break;
  8914. }
  8915. }
  8916. if (TYPE_STRING_FLAG (type))
  8917. {
  8918. if (TYPE_UNSIGNED (type))
  8919. encoding = DW_ATE_unsigned_char;
  8920. else
  8921. encoding = DW_ATE_signed_char;
  8922. }
  8923. else if (TYPE_UNSIGNED (type))
  8924. encoding = DW_ATE_unsigned;
  8925. else
  8926. encoding = DW_ATE_signed;
  8927. break;
  8928. case REAL_TYPE:
  8929. if (DECIMAL_FLOAT_MODE_P (TYPE_MODE (type)))
  8930. {
  8931. if (dwarf_version >= 3 || !dwarf_strict)
  8932. encoding = DW_ATE_decimal_float;
  8933. else
  8934. encoding = DW_ATE_lo_user;
  8935. }
  8936. else
  8937. encoding = DW_ATE_float;
  8938. break;
  8939. case FIXED_POINT_TYPE:
  8940. if (!(dwarf_version >= 3 || !dwarf_strict))
  8941. encoding = DW_ATE_lo_user;
  8942. else if (TYPE_UNSIGNED (type))
  8943. encoding = DW_ATE_unsigned_fixed;
  8944. else
  8945. encoding = DW_ATE_signed_fixed;
  8946. break;
  8947. /* Dwarf2 doesn't know anything about complex ints, so use
  8948. a user defined type for it. */
  8949. case COMPLEX_TYPE:
  8950. if (TREE_CODE (TREE_TYPE (type)) == REAL_TYPE)
  8951. encoding = DW_ATE_complex_float;
  8952. else
  8953. encoding = DW_ATE_lo_user;
  8954. break;
  8955. case BOOLEAN_TYPE:
  8956. /* GNU FORTRAN/Ada/C++ BOOLEAN type. */
  8957. encoding = DW_ATE_boolean;
  8958. break;
  8959. default:
  8960. /* No other TREE_CODEs are Dwarf fundamental types. */
  8961. gcc_unreachable ();
  8962. }
  8963. base_type_result = new_die (DW_TAG_base_type, comp_unit_die (), type);
  8964. add_AT_unsigned (base_type_result, DW_AT_byte_size,
  8965. int_size_in_bytes (type));
  8966. add_AT_unsigned (base_type_result, DW_AT_encoding, encoding);
  8967. add_pubtype (type, base_type_result);
  8968. return base_type_result;
  8969. }
  8970. /* A C++ function with deduced return type can have a TEMPLATE_TYPE_PARM
  8971. named 'auto' in its type: return true for it, false otherwise. */
  8972. static inline bool
  8973. is_cxx_auto (tree type)
  8974. {
  8975. if (is_cxx ())
  8976. {
  8977. tree name = TYPE_IDENTIFIER (type);
  8978. if (name == get_identifier ("auto")
  8979. || name == get_identifier ("decltype(auto)"))
  8980. return true;
  8981. }
  8982. return false;
  8983. }
  8984. /* Given a pointer to an arbitrary ..._TYPE tree node, return nonzero if the
  8985. given input type is a Dwarf "fundamental" type. Otherwise return null. */
  8986. static inline int
  8987. is_base_type (tree type)
  8988. {
  8989. switch (TREE_CODE (type))
  8990. {
  8991. case ERROR_MARK:
  8992. case VOID_TYPE:
  8993. case INTEGER_TYPE:
  8994. case REAL_TYPE:
  8995. case FIXED_POINT_TYPE:
  8996. case COMPLEX_TYPE:
  8997. case BOOLEAN_TYPE:
  8998. case POINTER_BOUNDS_TYPE:
  8999. return 1;
  9000. case ARRAY_TYPE:
  9001. case RECORD_TYPE:
  9002. case UNION_TYPE:
  9003. case QUAL_UNION_TYPE:
  9004. case ENUMERAL_TYPE:
  9005. case FUNCTION_TYPE:
  9006. case METHOD_TYPE:
  9007. case POINTER_TYPE:
  9008. case REFERENCE_TYPE:
  9009. case NULLPTR_TYPE:
  9010. case OFFSET_TYPE:
  9011. case LANG_TYPE:
  9012. case VECTOR_TYPE:
  9013. return 0;
  9014. default:
  9015. if (is_cxx_auto (type))
  9016. return 0;
  9017. gcc_unreachable ();
  9018. }
  9019. return 0;
  9020. }
  9021. /* Given a pointer to a tree node, assumed to be some kind of a ..._TYPE
  9022. node, return the size in bits for the type if it is a constant, or else
  9023. return the alignment for the type if the type's size is not constant, or
  9024. else return BITS_PER_WORD if the type actually turns out to be an
  9025. ERROR_MARK node. */
  9026. static inline unsigned HOST_WIDE_INT
  9027. simple_type_size_in_bits (const_tree type)
  9028. {
  9029. if (TREE_CODE (type) == ERROR_MARK)
  9030. return BITS_PER_WORD;
  9031. else if (TYPE_SIZE (type) == NULL_TREE)
  9032. return 0;
  9033. else if (tree_fits_uhwi_p (TYPE_SIZE (type)))
  9034. return tree_to_uhwi (TYPE_SIZE (type));
  9035. else
  9036. return TYPE_ALIGN (type);
  9037. }
  9038. /* Similarly, but return an offset_int instead of UHWI. */
  9039. static inline offset_int
  9040. offset_int_type_size_in_bits (const_tree type)
  9041. {
  9042. if (TREE_CODE (type) == ERROR_MARK)
  9043. return BITS_PER_WORD;
  9044. else if (TYPE_SIZE (type) == NULL_TREE)
  9045. return 0;
  9046. else if (TREE_CODE (TYPE_SIZE (type)) == INTEGER_CST)
  9047. return wi::to_offset (TYPE_SIZE (type));
  9048. else
  9049. return TYPE_ALIGN (type);
  9050. }
  9051. /* Given a pointer to a tree node for a subrange type, return a pointer
  9052. to a DIE that describes the given type. */
  9053. static dw_die_ref
  9054. subrange_type_die (tree type, tree low, tree high, dw_die_ref context_die)
  9055. {
  9056. dw_die_ref subrange_die;
  9057. const HOST_WIDE_INT size_in_bytes = int_size_in_bytes (type);
  9058. if (context_die == NULL)
  9059. context_die = comp_unit_die ();
  9060. subrange_die = new_die (DW_TAG_subrange_type, context_die, type);
  9061. if (int_size_in_bytes (TREE_TYPE (type)) != size_in_bytes)
  9062. {
  9063. /* The size of the subrange type and its base type do not match,
  9064. so we need to generate a size attribute for the subrange type. */
  9065. add_AT_unsigned (subrange_die, DW_AT_byte_size, size_in_bytes);
  9066. }
  9067. if (low)
  9068. add_bound_info (subrange_die, DW_AT_lower_bound, low, NULL);
  9069. if (high)
  9070. add_bound_info (subrange_die, DW_AT_upper_bound, high, NULL);
  9071. return subrange_die;
  9072. }
  9073. /* Returns the (const and/or volatile) cv_qualifiers associated with
  9074. the decl node. This will normally be augmented with the
  9075. cv_qualifiers of the underlying type in add_type_attribute. */
  9076. static int
  9077. decl_quals (const_tree decl)
  9078. {
  9079. return ((TREE_READONLY (decl)
  9080. ? TYPE_QUAL_CONST : TYPE_UNQUALIFIED)
  9081. | (TREE_THIS_VOLATILE (decl)
  9082. ? TYPE_QUAL_VOLATILE : TYPE_UNQUALIFIED));
  9083. }
  9084. /* Determine the TYPE whose qualifiers match the largest strict subset
  9085. of the given TYPE_QUALS, and return its qualifiers. Ignore all
  9086. qualifiers outside QUAL_MASK. */
  9087. static int
  9088. get_nearest_type_subqualifiers (tree type, int type_quals, int qual_mask)
  9089. {
  9090. tree t;
  9091. int best_rank = 0, best_qual = 0, max_rank;
  9092. type_quals &= qual_mask;
  9093. max_rank = popcount_hwi (type_quals) - 1;
  9094. for (t = TYPE_MAIN_VARIANT (type); t && best_rank < max_rank;
  9095. t = TYPE_NEXT_VARIANT (t))
  9096. {
  9097. int q = TYPE_QUALS (t) & qual_mask;
  9098. if ((q & type_quals) == q && q != type_quals
  9099. && check_base_type (t, type))
  9100. {
  9101. int rank = popcount_hwi (q);
  9102. if (rank > best_rank)
  9103. {
  9104. best_rank = rank;
  9105. best_qual = q;
  9106. }
  9107. }
  9108. }
  9109. return best_qual;
  9110. }
  9111. /* Given a pointer to an arbitrary ..._TYPE tree node, return a debugging
  9112. entry that chains various modifiers in front of the given type. */
  9113. static dw_die_ref
  9114. modified_type_die (tree type, int cv_quals, dw_die_ref context_die)
  9115. {
  9116. enum tree_code code = TREE_CODE (type);
  9117. dw_die_ref mod_type_die;
  9118. dw_die_ref sub_die = NULL;
  9119. tree item_type = NULL;
  9120. tree qualified_type;
  9121. tree name, low, high;
  9122. dw_die_ref mod_scope;
  9123. /* Only these cv-qualifiers are currently handled. */
  9124. const int cv_qual_mask = (TYPE_QUAL_CONST | TYPE_QUAL_VOLATILE
  9125. | TYPE_QUAL_RESTRICT | TYPE_QUAL_ATOMIC);
  9126. if (code == ERROR_MARK)
  9127. return NULL;
  9128. cv_quals &= cv_qual_mask;
  9129. /* Don't emit DW_TAG_restrict_type for DWARFv2, since it is a type
  9130. tag modifier (and not an attribute) old consumers won't be able
  9131. to handle it. */
  9132. if (dwarf_version < 3)
  9133. cv_quals &= ~TYPE_QUAL_RESTRICT;
  9134. /* Likewise for DW_TAG_atomic_type for DWARFv5. */
  9135. if (dwarf_version < 5)
  9136. cv_quals &= ~TYPE_QUAL_ATOMIC;
  9137. /* See if we already have the appropriately qualified variant of
  9138. this type. */
  9139. qualified_type = get_qualified_type (type, cv_quals);
  9140. if (qualified_type == sizetype
  9141. && TYPE_NAME (qualified_type)
  9142. && TREE_CODE (TYPE_NAME (qualified_type)) == TYPE_DECL)
  9143. {
  9144. tree t = TREE_TYPE (TYPE_NAME (qualified_type));
  9145. gcc_checking_assert (TREE_CODE (t) == INTEGER_TYPE
  9146. && TYPE_PRECISION (t)
  9147. == TYPE_PRECISION (qualified_type)
  9148. && TYPE_UNSIGNED (t)
  9149. == TYPE_UNSIGNED (qualified_type));
  9150. qualified_type = t;
  9151. }
  9152. /* If we do, then we can just use its DIE, if it exists. */
  9153. if (qualified_type)
  9154. {
  9155. mod_type_die = lookup_type_die (qualified_type);
  9156. if (mod_type_die)
  9157. return mod_type_die;
  9158. }
  9159. name = qualified_type ? TYPE_NAME (qualified_type) : NULL;
  9160. /* Handle C typedef types. */
  9161. if (name && TREE_CODE (name) == TYPE_DECL && DECL_ORIGINAL_TYPE (name)
  9162. && !DECL_ARTIFICIAL (name))
  9163. {
  9164. tree dtype = TREE_TYPE (name);
  9165. if (qualified_type == dtype)
  9166. {
  9167. /* For a named type, use the typedef. */
  9168. gen_type_die (qualified_type, context_die);
  9169. return lookup_type_die (qualified_type);
  9170. }
  9171. else
  9172. {
  9173. int dquals = TYPE_QUALS_NO_ADDR_SPACE (dtype);
  9174. dquals &= cv_qual_mask;
  9175. if ((dquals & ~cv_quals) != TYPE_UNQUALIFIED
  9176. || (cv_quals == dquals && DECL_ORIGINAL_TYPE (name) != type))
  9177. /* cv-unqualified version of named type. Just use
  9178. the unnamed type to which it refers. */
  9179. return modified_type_die (DECL_ORIGINAL_TYPE (name),
  9180. cv_quals, context_die);
  9181. /* Else cv-qualified version of named type; fall through. */
  9182. }
  9183. }
  9184. mod_scope = scope_die_for (type, context_die);
  9185. if (cv_quals)
  9186. {
  9187. struct qual_info { int q; enum dwarf_tag t; };
  9188. static const struct qual_info qual_info[] =
  9189. {
  9190. { TYPE_QUAL_ATOMIC, DW_TAG_atomic_type },
  9191. { TYPE_QUAL_RESTRICT, DW_TAG_restrict_type },
  9192. { TYPE_QUAL_VOLATILE, DW_TAG_volatile_type },
  9193. { TYPE_QUAL_CONST, DW_TAG_const_type },
  9194. };
  9195. int sub_quals;
  9196. unsigned i;
  9197. /* Determine a lesser qualified type that most closely matches
  9198. this one. Then generate DW_TAG_* entries for the remaining
  9199. qualifiers. */
  9200. sub_quals = get_nearest_type_subqualifiers (type, cv_quals,
  9201. cv_qual_mask);
  9202. mod_type_die = modified_type_die (type, sub_quals, context_die);
  9203. for (i = 0; i < sizeof (qual_info) / sizeof (qual_info[0]); i++)
  9204. if (qual_info[i].q & cv_quals & ~sub_quals)
  9205. {
  9206. dw_die_ref d = new_die (qual_info[i].t, mod_scope, type);
  9207. if (mod_type_die)
  9208. add_AT_die_ref (d, DW_AT_type, mod_type_die);
  9209. mod_type_die = d;
  9210. }
  9211. }
  9212. else if (code == POINTER_TYPE)
  9213. {
  9214. mod_type_die = new_die (DW_TAG_pointer_type, mod_scope, type);
  9215. add_AT_unsigned (mod_type_die, DW_AT_byte_size,
  9216. simple_type_size_in_bits (type) / BITS_PER_UNIT);
  9217. item_type = TREE_TYPE (type);
  9218. if (!ADDR_SPACE_GENERIC_P (TYPE_ADDR_SPACE (item_type)))
  9219. add_AT_unsigned (mod_type_die, DW_AT_address_class,
  9220. TYPE_ADDR_SPACE (item_type));
  9221. }
  9222. else if (code == REFERENCE_TYPE)
  9223. {
  9224. if (TYPE_REF_IS_RVALUE (type) && dwarf_version >= 4)
  9225. mod_type_die = new_die (DW_TAG_rvalue_reference_type, mod_scope,
  9226. type);
  9227. else
  9228. mod_type_die = new_die (DW_TAG_reference_type, mod_scope, type);
  9229. add_AT_unsigned (mod_type_die, DW_AT_byte_size,
  9230. simple_type_size_in_bits (type) / BITS_PER_UNIT);
  9231. item_type = TREE_TYPE (type);
  9232. if (!ADDR_SPACE_GENERIC_P (TYPE_ADDR_SPACE (item_type)))
  9233. add_AT_unsigned (mod_type_die, DW_AT_address_class,
  9234. TYPE_ADDR_SPACE (item_type));
  9235. }
  9236. else if (code == INTEGER_TYPE
  9237. && TREE_TYPE (type) != NULL_TREE
  9238. && subrange_type_for_debug_p (type, &low, &high))
  9239. {
  9240. mod_type_die = subrange_type_die (type, low, high, context_die);
  9241. item_type = TREE_TYPE (type);
  9242. }
  9243. else if (is_base_type (type))
  9244. mod_type_die = base_type_die (type);
  9245. else
  9246. {
  9247. gen_type_die (type, context_die);
  9248. /* We have to get the type_main_variant here (and pass that to the
  9249. `lookup_type_die' routine) because the ..._TYPE node we have
  9250. might simply be a *copy* of some original type node (where the
  9251. copy was created to help us keep track of typedef names) and
  9252. that copy might have a different TYPE_UID from the original
  9253. ..._TYPE node. */
  9254. if (TREE_CODE (type) != VECTOR_TYPE)
  9255. return lookup_type_die (type_main_variant (type));
  9256. else
  9257. /* Vectors have the debugging information in the type,
  9258. not the main variant. */
  9259. return lookup_type_die (type);
  9260. }
  9261. /* Builtin types don't have a DECL_ORIGINAL_TYPE. For those,
  9262. don't output a DW_TAG_typedef, since there isn't one in the
  9263. user's program; just attach a DW_AT_name to the type.
  9264. Don't attach a DW_AT_name to DW_TAG_const_type or DW_TAG_volatile_type
  9265. if the base type already has the same name. */
  9266. if (name
  9267. && ((TREE_CODE (name) != TYPE_DECL
  9268. && (qualified_type == TYPE_MAIN_VARIANT (type)
  9269. || (cv_quals == TYPE_UNQUALIFIED)))
  9270. || (TREE_CODE (name) == TYPE_DECL
  9271. && TREE_TYPE (name) == qualified_type
  9272. && DECL_NAME (name))))
  9273. {
  9274. if (TREE_CODE (name) == TYPE_DECL)
  9275. /* Could just call add_name_and_src_coords_attributes here,
  9276. but since this is a builtin type it doesn't have any
  9277. useful source coordinates anyway. */
  9278. name = DECL_NAME (name);
  9279. add_name_attribute (mod_type_die, IDENTIFIER_POINTER (name));
  9280. }
  9281. /* This probably indicates a bug. */
  9282. else if (mod_type_die && mod_type_die->die_tag == DW_TAG_base_type)
  9283. {
  9284. name = TYPE_IDENTIFIER (type);
  9285. add_name_attribute (mod_type_die,
  9286. name ? IDENTIFIER_POINTER (name) : "__unknown__");
  9287. }
  9288. if (qualified_type)
  9289. equate_type_number_to_die (qualified_type, mod_type_die);
  9290. if (item_type)
  9291. /* We must do this after the equate_type_number_to_die call, in case
  9292. this is a recursive type. This ensures that the modified_type_die
  9293. recursion will terminate even if the type is recursive. Recursive
  9294. types are possible in Ada. */
  9295. sub_die = modified_type_die (item_type,
  9296. TYPE_QUALS_NO_ADDR_SPACE (item_type),
  9297. context_die);
  9298. if (sub_die != NULL)
  9299. add_AT_die_ref (mod_type_die, DW_AT_type, sub_die);
  9300. add_gnat_descriptive_type_attribute (mod_type_die, type, context_die);
  9301. if (TYPE_ARTIFICIAL (type))
  9302. add_AT_flag (mod_type_die, DW_AT_artificial, 1);
  9303. return mod_type_die;
  9304. }
  9305. /* Generate DIEs for the generic parameters of T.
  9306. T must be either a generic type or a generic function.
  9307. See http://gcc.gnu.org/wiki/TemplateParmsDwarf for more. */
  9308. static void
  9309. gen_generic_params_dies (tree t)
  9310. {
  9311. tree parms, args;
  9312. int parms_num, i;
  9313. dw_die_ref die = NULL;
  9314. int non_default;
  9315. if (!t || (TYPE_P (t) && !COMPLETE_TYPE_P (t)))
  9316. return;
  9317. if (TYPE_P (t))
  9318. die = lookup_type_die (t);
  9319. else if (DECL_P (t))
  9320. die = lookup_decl_die (t);
  9321. gcc_assert (die);
  9322. parms = lang_hooks.get_innermost_generic_parms (t);
  9323. if (!parms)
  9324. /* T has no generic parameter. It means T is neither a generic type
  9325. or function. End of story. */
  9326. return;
  9327. parms_num = TREE_VEC_LENGTH (parms);
  9328. args = lang_hooks.get_innermost_generic_args (t);
  9329. if (TREE_CHAIN (args) && TREE_CODE (TREE_CHAIN (args)) == INTEGER_CST)
  9330. non_default = int_cst_value (TREE_CHAIN (args));
  9331. else
  9332. non_default = TREE_VEC_LENGTH (args);
  9333. for (i = 0; i < parms_num; i++)
  9334. {
  9335. tree parm, arg, arg_pack_elems;
  9336. dw_die_ref parm_die;
  9337. parm = TREE_VEC_ELT (parms, i);
  9338. arg = TREE_VEC_ELT (args, i);
  9339. arg_pack_elems = lang_hooks.types.get_argument_pack_elems (arg);
  9340. gcc_assert (parm && TREE_VALUE (parm) && arg);
  9341. if (parm && TREE_VALUE (parm) && arg)
  9342. {
  9343. /* If PARM represents a template parameter pack,
  9344. emit a DW_TAG_GNU_template_parameter_pack DIE, followed
  9345. by DW_TAG_template_*_parameter DIEs for the argument
  9346. pack elements of ARG. Note that ARG would then be
  9347. an argument pack. */
  9348. if (arg_pack_elems)
  9349. parm_die = template_parameter_pack_die (TREE_VALUE (parm),
  9350. arg_pack_elems,
  9351. die);
  9352. else
  9353. parm_die = generic_parameter_die (TREE_VALUE (parm), arg,
  9354. true /* emit name */, die);
  9355. if (i >= non_default)
  9356. add_AT_flag (parm_die, DW_AT_default_value, 1);
  9357. }
  9358. }
  9359. }
  9360. /* Create and return a DIE for PARM which should be
  9361. the representation of a generic type parameter.
  9362. For instance, in the C++ front end, PARM would be a template parameter.
  9363. ARG is the argument to PARM.
  9364. EMIT_NAME_P if tree, the DIE will have DW_AT_name attribute set to the
  9365. name of the PARM.
  9366. PARENT_DIE is the parent DIE which the new created DIE should be added to,
  9367. as a child node. */
  9368. static dw_die_ref
  9369. generic_parameter_die (tree parm, tree arg,
  9370. bool emit_name_p,
  9371. dw_die_ref parent_die)
  9372. {
  9373. dw_die_ref tmpl_die = NULL;
  9374. const char *name = NULL;
  9375. if (!parm || !DECL_NAME (parm) || !arg)
  9376. return NULL;
  9377. /* We support non-type generic parameters and arguments,
  9378. type generic parameters and arguments, as well as
  9379. generic generic parameters (a.k.a. template template parameters in C++)
  9380. and arguments. */
  9381. if (TREE_CODE (parm) == PARM_DECL)
  9382. /* PARM is a nontype generic parameter */
  9383. tmpl_die = new_die (DW_TAG_template_value_param, parent_die, parm);
  9384. else if (TREE_CODE (parm) == TYPE_DECL)
  9385. /* PARM is a type generic parameter. */
  9386. tmpl_die = new_die (DW_TAG_template_type_param, parent_die, parm);
  9387. else if (lang_hooks.decls.generic_generic_parameter_decl_p (parm))
  9388. /* PARM is a generic generic parameter.
  9389. Its DIE is a GNU extension. It shall have a
  9390. DW_AT_name attribute to represent the name of the template template
  9391. parameter, and a DW_AT_GNU_template_name attribute to represent the
  9392. name of the template template argument. */
  9393. tmpl_die = new_die (DW_TAG_GNU_template_template_param,
  9394. parent_die, parm);
  9395. else
  9396. gcc_unreachable ();
  9397. if (tmpl_die)
  9398. {
  9399. tree tmpl_type;
  9400. /* If PARM is a generic parameter pack, it means we are
  9401. emitting debug info for a template argument pack element.
  9402. In other terms, ARG is a template argument pack element.
  9403. In that case, we don't emit any DW_AT_name attribute for
  9404. the die. */
  9405. if (emit_name_p)
  9406. {
  9407. name = IDENTIFIER_POINTER (DECL_NAME (parm));
  9408. gcc_assert (name);
  9409. add_AT_string (tmpl_die, DW_AT_name, name);
  9410. }
  9411. if (!lang_hooks.decls.generic_generic_parameter_decl_p (parm))
  9412. {
  9413. /* DWARF3, 5.6.8 says if PARM is a non-type generic parameter
  9414. TMPL_DIE should have a child DW_AT_type attribute that is set
  9415. to the type of the argument to PARM, which is ARG.
  9416. If PARM is a type generic parameter, TMPL_DIE should have a
  9417. child DW_AT_type that is set to ARG. */
  9418. tmpl_type = TYPE_P (arg) ? arg : TREE_TYPE (arg);
  9419. add_type_attribute (tmpl_die, tmpl_type,
  9420. (TREE_THIS_VOLATILE (tmpl_type)
  9421. ? TYPE_QUAL_VOLATILE : TYPE_UNQUALIFIED),
  9422. parent_die);
  9423. }
  9424. else
  9425. {
  9426. /* So TMPL_DIE is a DIE representing a
  9427. a generic generic template parameter, a.k.a template template
  9428. parameter in C++ and arg is a template. */
  9429. /* The DW_AT_GNU_template_name attribute of the DIE must be set
  9430. to the name of the argument. */
  9431. name = dwarf2_name (TYPE_P (arg) ? TYPE_NAME (arg) : arg, 1);
  9432. if (name)
  9433. add_AT_string (tmpl_die, DW_AT_GNU_template_name, name);
  9434. }
  9435. if (TREE_CODE (parm) == PARM_DECL)
  9436. /* So PARM is a non-type generic parameter.
  9437. DWARF3 5.6.8 says we must set a DW_AT_const_value child
  9438. attribute of TMPL_DIE which value represents the value
  9439. of ARG.
  9440. We must be careful here:
  9441. The value of ARG might reference some function decls.
  9442. We might currently be emitting debug info for a generic
  9443. type and types are emitted before function decls, we don't
  9444. know if the function decls referenced by ARG will actually be
  9445. emitted after cgraph computations.
  9446. So must defer the generation of the DW_AT_const_value to
  9447. after cgraph is ready. */
  9448. append_entry_to_tmpl_value_parm_die_table (tmpl_die, arg);
  9449. }
  9450. return tmpl_die;
  9451. }
  9452. /* Generate and return a DW_TAG_GNU_template_parameter_pack DIE representing.
  9453. PARM_PACK must be a template parameter pack. The returned DIE
  9454. will be child DIE of PARENT_DIE. */
  9455. static dw_die_ref
  9456. template_parameter_pack_die (tree parm_pack,
  9457. tree parm_pack_args,
  9458. dw_die_ref parent_die)
  9459. {
  9460. dw_die_ref die;
  9461. int j;
  9462. gcc_assert (parent_die && parm_pack);
  9463. die = new_die (DW_TAG_GNU_template_parameter_pack, parent_die, parm_pack);
  9464. add_name_and_src_coords_attributes (die, parm_pack);
  9465. for (j = 0; j < TREE_VEC_LENGTH (parm_pack_args); j++)
  9466. generic_parameter_die (parm_pack,
  9467. TREE_VEC_ELT (parm_pack_args, j),
  9468. false /* Don't emit DW_AT_name */,
  9469. die);
  9470. return die;
  9471. }
  9472. /* Given a pointer to an arbitrary ..._TYPE tree node, return true if it is
  9473. an enumerated type. */
  9474. static inline int
  9475. type_is_enum (const_tree type)
  9476. {
  9477. return TREE_CODE (type) == ENUMERAL_TYPE;
  9478. }
  9479. /* Return the DBX register number described by a given RTL node. */
  9480. static unsigned int
  9481. dbx_reg_number (const_rtx rtl)
  9482. {
  9483. unsigned regno = REGNO (rtl);
  9484. gcc_assert (regno < FIRST_PSEUDO_REGISTER);
  9485. #ifdef LEAF_REG_REMAP
  9486. if (crtl->uses_only_leaf_regs)
  9487. {
  9488. int leaf_reg = LEAF_REG_REMAP (regno);
  9489. if (leaf_reg != -1)
  9490. regno = (unsigned) leaf_reg;
  9491. }
  9492. #endif
  9493. regno = DBX_REGISTER_NUMBER (regno);
  9494. gcc_assert (regno != INVALID_REGNUM);
  9495. return regno;
  9496. }
  9497. /* Optionally add a DW_OP_piece term to a location description expression.
  9498. DW_OP_piece is only added if the location description expression already
  9499. doesn't end with DW_OP_piece. */
  9500. static void
  9501. add_loc_descr_op_piece (dw_loc_descr_ref *list_head, int size)
  9502. {
  9503. dw_loc_descr_ref loc;
  9504. if (*list_head != NULL)
  9505. {
  9506. /* Find the end of the chain. */
  9507. for (loc = *list_head; loc->dw_loc_next != NULL; loc = loc->dw_loc_next)
  9508. ;
  9509. if (loc->dw_loc_opc != DW_OP_piece)
  9510. loc->dw_loc_next = new_loc_descr (DW_OP_piece, size, 0);
  9511. }
  9512. }
  9513. /* Return a location descriptor that designates a machine register or
  9514. zero if there is none. */
  9515. static dw_loc_descr_ref
  9516. reg_loc_descriptor (rtx rtl, enum var_init_status initialized)
  9517. {
  9518. rtx regs;
  9519. if (REGNO (rtl) >= FIRST_PSEUDO_REGISTER)
  9520. return 0;
  9521. /* We only use "frame base" when we're sure we're talking about the
  9522. post-prologue local stack frame. We do this by *not* running
  9523. register elimination until this point, and recognizing the special
  9524. argument pointer and soft frame pointer rtx's.
  9525. Use DW_OP_fbreg offset DW_OP_stack_value in this case. */
  9526. if ((rtl == arg_pointer_rtx || rtl == frame_pointer_rtx)
  9527. && eliminate_regs (rtl, VOIDmode, NULL_RTX) != rtl)
  9528. {
  9529. dw_loc_descr_ref result = NULL;
  9530. if (dwarf_version >= 4 || !dwarf_strict)
  9531. {
  9532. result = mem_loc_descriptor (rtl, GET_MODE (rtl), VOIDmode,
  9533. initialized);
  9534. if (result)
  9535. add_loc_descr (&result,
  9536. new_loc_descr (DW_OP_stack_value, 0, 0));
  9537. }
  9538. return result;
  9539. }
  9540. regs = targetm.dwarf_register_span (rtl);
  9541. if (hard_regno_nregs[REGNO (rtl)][GET_MODE (rtl)] > 1 || regs)
  9542. return multiple_reg_loc_descriptor (rtl, regs, initialized);
  9543. else
  9544. {
  9545. unsigned int dbx_regnum = dbx_reg_number (rtl);
  9546. if (dbx_regnum == IGNORED_DWARF_REGNUM)
  9547. return 0;
  9548. return one_reg_loc_descriptor (dbx_regnum, initialized);
  9549. }
  9550. }
  9551. /* Return a location descriptor that designates a machine register for
  9552. a given hard register number. */
  9553. static dw_loc_descr_ref
  9554. one_reg_loc_descriptor (unsigned int regno, enum var_init_status initialized)
  9555. {
  9556. dw_loc_descr_ref reg_loc_descr;
  9557. if (regno <= 31)
  9558. reg_loc_descr
  9559. = new_loc_descr ((enum dwarf_location_atom) (DW_OP_reg0 + regno), 0, 0);
  9560. else
  9561. reg_loc_descr = new_loc_descr (DW_OP_regx, regno, 0);
  9562. if (initialized == VAR_INIT_STATUS_UNINITIALIZED)
  9563. add_loc_descr (&reg_loc_descr, new_loc_descr (DW_OP_GNU_uninit, 0, 0));
  9564. return reg_loc_descr;
  9565. }
  9566. /* Given an RTL of a register, return a location descriptor that
  9567. designates a value that spans more than one register. */
  9568. static dw_loc_descr_ref
  9569. multiple_reg_loc_descriptor (rtx rtl, rtx regs,
  9570. enum var_init_status initialized)
  9571. {
  9572. int size, i;
  9573. dw_loc_descr_ref loc_result = NULL;
  9574. /* Simple, contiguous registers. */
  9575. if (regs == NULL_RTX)
  9576. {
  9577. unsigned reg = REGNO (rtl);
  9578. int nregs;
  9579. #ifdef LEAF_REG_REMAP
  9580. if (crtl->uses_only_leaf_regs)
  9581. {
  9582. int leaf_reg = LEAF_REG_REMAP (reg);
  9583. if (leaf_reg != -1)
  9584. reg = (unsigned) leaf_reg;
  9585. }
  9586. #endif
  9587. gcc_assert ((unsigned) DBX_REGISTER_NUMBER (reg) == dbx_reg_number (rtl));
  9588. nregs = hard_regno_nregs[REGNO (rtl)][GET_MODE (rtl)];
  9589. size = GET_MODE_SIZE (GET_MODE (rtl)) / nregs;
  9590. loc_result = NULL;
  9591. while (nregs--)
  9592. {
  9593. dw_loc_descr_ref t;
  9594. t = one_reg_loc_descriptor (DBX_REGISTER_NUMBER (reg),
  9595. VAR_INIT_STATUS_INITIALIZED);
  9596. add_loc_descr (&loc_result, t);
  9597. add_loc_descr_op_piece (&loc_result, size);
  9598. ++reg;
  9599. }
  9600. return loc_result;
  9601. }
  9602. /* Now onto stupid register sets in non contiguous locations. */
  9603. gcc_assert (GET_CODE (regs) == PARALLEL);
  9604. size = GET_MODE_SIZE (GET_MODE (XVECEXP (regs, 0, 0)));
  9605. loc_result = NULL;
  9606. for (i = 0; i < XVECLEN (regs, 0); ++i)
  9607. {
  9608. dw_loc_descr_ref t;
  9609. t = one_reg_loc_descriptor (dbx_reg_number (XVECEXP (regs, 0, i)),
  9610. VAR_INIT_STATUS_INITIALIZED);
  9611. add_loc_descr (&loc_result, t);
  9612. add_loc_descr_op_piece (&loc_result, size);
  9613. }
  9614. if (loc_result && initialized == VAR_INIT_STATUS_UNINITIALIZED)
  9615. add_loc_descr (&loc_result, new_loc_descr (DW_OP_GNU_uninit, 0, 0));
  9616. return loc_result;
  9617. }
  9618. static unsigned long size_of_int_loc_descriptor (HOST_WIDE_INT);
  9619. /* Return a location descriptor that designates a constant i,
  9620. as a compound operation from constant (i >> shift), constant shift
  9621. and DW_OP_shl. */
  9622. static dw_loc_descr_ref
  9623. int_shift_loc_descriptor (HOST_WIDE_INT i, int shift)
  9624. {
  9625. dw_loc_descr_ref ret = int_loc_descriptor (i >> shift);
  9626. add_loc_descr (&ret, int_loc_descriptor (shift));
  9627. add_loc_descr (&ret, new_loc_descr (DW_OP_shl, 0, 0));
  9628. return ret;
  9629. }
  9630. /* Return a location descriptor that designates a constant. */
  9631. static dw_loc_descr_ref
  9632. int_loc_descriptor (HOST_WIDE_INT i)
  9633. {
  9634. enum dwarf_location_atom op;
  9635. /* Pick the smallest representation of a constant, rather than just
  9636. defaulting to the LEB encoding. */
  9637. if (i >= 0)
  9638. {
  9639. int clz = clz_hwi (i);
  9640. int ctz = ctz_hwi (i);
  9641. if (i <= 31)
  9642. op = (enum dwarf_location_atom) (DW_OP_lit0 + i);
  9643. else if (i <= 0xff)
  9644. op = DW_OP_const1u;
  9645. else if (i <= 0xffff)
  9646. op = DW_OP_const2u;
  9647. else if (clz + ctz >= HOST_BITS_PER_WIDE_INT - 5
  9648. && clz + 5 + 255 >= HOST_BITS_PER_WIDE_INT)
  9649. /* DW_OP_litX DW_OP_litY DW_OP_shl takes just 3 bytes and
  9650. DW_OP_litX DW_OP_const1u Y DW_OP_shl takes just 4 bytes,
  9651. while DW_OP_const4u is 5 bytes. */
  9652. return int_shift_loc_descriptor (i, HOST_BITS_PER_WIDE_INT - clz - 5);
  9653. else if (clz + ctz >= HOST_BITS_PER_WIDE_INT - 8
  9654. && clz + 8 + 31 >= HOST_BITS_PER_WIDE_INT)
  9655. /* DW_OP_const1u X DW_OP_litY DW_OP_shl takes just 4 bytes,
  9656. while DW_OP_const4u is 5 bytes. */
  9657. return int_shift_loc_descriptor (i, HOST_BITS_PER_WIDE_INT - clz - 8);
  9658. else if (HOST_BITS_PER_WIDE_INT == 32 || i <= 0xffffffff)
  9659. op = DW_OP_const4u;
  9660. else if (clz + ctz >= HOST_BITS_PER_WIDE_INT - 8
  9661. && clz + 8 + 255 >= HOST_BITS_PER_WIDE_INT)
  9662. /* DW_OP_const1u X DW_OP_const1u Y DW_OP_shl takes just 5 bytes,
  9663. while DW_OP_constu of constant >= 0x100000000 takes at least
  9664. 6 bytes. */
  9665. return int_shift_loc_descriptor (i, HOST_BITS_PER_WIDE_INT - clz - 8);
  9666. else if (clz + ctz >= HOST_BITS_PER_WIDE_INT - 16
  9667. && clz + 16 + (size_of_uleb128 (i) > 5 ? 255 : 31)
  9668. >= HOST_BITS_PER_WIDE_INT)
  9669. /* DW_OP_const2u X DW_OP_litY DW_OP_shl takes just 5 bytes,
  9670. DW_OP_const2u X DW_OP_const1u Y DW_OP_shl takes 6 bytes,
  9671. while DW_OP_constu takes in this case at least 6 bytes. */
  9672. return int_shift_loc_descriptor (i, HOST_BITS_PER_WIDE_INT - clz - 16);
  9673. else if (clz + ctz >= HOST_BITS_PER_WIDE_INT - 32
  9674. && clz + 32 + 31 >= HOST_BITS_PER_WIDE_INT
  9675. && size_of_uleb128 (i) > 6)
  9676. /* DW_OP_const4u X DW_OP_litY DW_OP_shl takes just 7 bytes. */
  9677. return int_shift_loc_descriptor (i, HOST_BITS_PER_WIDE_INT - clz - 32);
  9678. else
  9679. op = DW_OP_constu;
  9680. }
  9681. else
  9682. {
  9683. if (i >= -0x80)
  9684. op = DW_OP_const1s;
  9685. else if (i >= -0x8000)
  9686. op = DW_OP_const2s;
  9687. else if (HOST_BITS_PER_WIDE_INT == 32 || i >= -0x80000000)
  9688. {
  9689. if (size_of_int_loc_descriptor (i) < 5)
  9690. {
  9691. dw_loc_descr_ref ret = int_loc_descriptor (-i);
  9692. add_loc_descr (&ret, new_loc_descr (DW_OP_neg, 0, 0));
  9693. return ret;
  9694. }
  9695. op = DW_OP_const4s;
  9696. }
  9697. else
  9698. {
  9699. if (size_of_int_loc_descriptor (i)
  9700. < (unsigned long) 1 + size_of_sleb128 (i))
  9701. {
  9702. dw_loc_descr_ref ret = int_loc_descriptor (-i);
  9703. add_loc_descr (&ret, new_loc_descr (DW_OP_neg, 0, 0));
  9704. return ret;
  9705. }
  9706. op = DW_OP_consts;
  9707. }
  9708. }
  9709. return new_loc_descr (op, i, 0);
  9710. }
  9711. /* Return size_of_locs (int_shift_loc_descriptor (i, shift))
  9712. without actually allocating it. */
  9713. static unsigned long
  9714. size_of_int_shift_loc_descriptor (HOST_WIDE_INT i, int shift)
  9715. {
  9716. return size_of_int_loc_descriptor (i >> shift)
  9717. + size_of_int_loc_descriptor (shift)
  9718. + 1;
  9719. }
  9720. /* Return size_of_locs (int_loc_descriptor (i)) without
  9721. actually allocating it. */
  9722. static unsigned long
  9723. size_of_int_loc_descriptor (HOST_WIDE_INT i)
  9724. {
  9725. unsigned long s;
  9726. if (i >= 0)
  9727. {
  9728. int clz, ctz;
  9729. if (i <= 31)
  9730. return 1;
  9731. else if (i <= 0xff)
  9732. return 2;
  9733. else if (i <= 0xffff)
  9734. return 3;
  9735. clz = clz_hwi (i);
  9736. ctz = ctz_hwi (i);
  9737. if (clz + ctz >= HOST_BITS_PER_WIDE_INT - 5
  9738. && clz + 5 + 255 >= HOST_BITS_PER_WIDE_INT)
  9739. return size_of_int_shift_loc_descriptor (i, HOST_BITS_PER_WIDE_INT
  9740. - clz - 5);
  9741. else if (clz + ctz >= HOST_BITS_PER_WIDE_INT - 8
  9742. && clz + 8 + 31 >= HOST_BITS_PER_WIDE_INT)
  9743. return size_of_int_shift_loc_descriptor (i, HOST_BITS_PER_WIDE_INT
  9744. - clz - 8);
  9745. else if (HOST_BITS_PER_WIDE_INT == 32 || i <= 0xffffffff)
  9746. return 5;
  9747. s = size_of_uleb128 ((unsigned HOST_WIDE_INT) i);
  9748. if (clz + ctz >= HOST_BITS_PER_WIDE_INT - 8
  9749. && clz + 8 + 255 >= HOST_BITS_PER_WIDE_INT)
  9750. return size_of_int_shift_loc_descriptor (i, HOST_BITS_PER_WIDE_INT
  9751. - clz - 8);
  9752. else if (clz + ctz >= HOST_BITS_PER_WIDE_INT - 16
  9753. && clz + 16 + (s > 5 ? 255 : 31) >= HOST_BITS_PER_WIDE_INT)
  9754. return size_of_int_shift_loc_descriptor (i, HOST_BITS_PER_WIDE_INT
  9755. - clz - 16);
  9756. else if (clz + ctz >= HOST_BITS_PER_WIDE_INT - 32
  9757. && clz + 32 + 31 >= HOST_BITS_PER_WIDE_INT
  9758. && s > 6)
  9759. return size_of_int_shift_loc_descriptor (i, HOST_BITS_PER_WIDE_INT
  9760. - clz - 32);
  9761. else
  9762. return 1 + s;
  9763. }
  9764. else
  9765. {
  9766. if (i >= -0x80)
  9767. return 2;
  9768. else if (i >= -0x8000)
  9769. return 3;
  9770. else if (HOST_BITS_PER_WIDE_INT == 32 || i >= -0x80000000)
  9771. {
  9772. if (-(unsigned HOST_WIDE_INT) i != (unsigned HOST_WIDE_INT) i)
  9773. {
  9774. s = size_of_int_loc_descriptor (-i) + 1;
  9775. if (s < 5)
  9776. return s;
  9777. }
  9778. return 5;
  9779. }
  9780. else
  9781. {
  9782. unsigned long r = 1 + size_of_sleb128 (i);
  9783. if (-(unsigned HOST_WIDE_INT) i != (unsigned HOST_WIDE_INT) i)
  9784. {
  9785. s = size_of_int_loc_descriptor (-i) + 1;
  9786. if (s < r)
  9787. return s;
  9788. }
  9789. return r;
  9790. }
  9791. }
  9792. }
  9793. /* Return loc description representing "address" of integer value.
  9794. This can appear only as toplevel expression. */
  9795. static dw_loc_descr_ref
  9796. address_of_int_loc_descriptor (int size, HOST_WIDE_INT i)
  9797. {
  9798. int litsize;
  9799. dw_loc_descr_ref loc_result = NULL;
  9800. if (!(dwarf_version >= 4 || !dwarf_strict))
  9801. return NULL;
  9802. litsize = size_of_int_loc_descriptor (i);
  9803. /* Determine if DW_OP_stack_value or DW_OP_implicit_value
  9804. is more compact. For DW_OP_stack_value we need:
  9805. litsize + 1 (DW_OP_stack_value)
  9806. and for DW_OP_implicit_value:
  9807. 1 (DW_OP_implicit_value) + 1 (length) + size. */
  9808. if ((int) DWARF2_ADDR_SIZE >= size && litsize + 1 <= 1 + 1 + size)
  9809. {
  9810. loc_result = int_loc_descriptor (i);
  9811. add_loc_descr (&loc_result,
  9812. new_loc_descr (DW_OP_stack_value, 0, 0));
  9813. return loc_result;
  9814. }
  9815. loc_result = new_loc_descr (DW_OP_implicit_value,
  9816. size, 0);
  9817. loc_result->dw_loc_oprnd2.val_class = dw_val_class_const;
  9818. loc_result->dw_loc_oprnd2.v.val_int = i;
  9819. return loc_result;
  9820. }
  9821. /* Return a location descriptor that designates a base+offset location. */
  9822. static dw_loc_descr_ref
  9823. based_loc_descr (rtx reg, HOST_WIDE_INT offset,
  9824. enum var_init_status initialized)
  9825. {
  9826. unsigned int regno;
  9827. dw_loc_descr_ref result;
  9828. dw_fde_ref fde = cfun->fde;
  9829. /* We only use "frame base" when we're sure we're talking about the
  9830. post-prologue local stack frame. We do this by *not* running
  9831. register elimination until this point, and recognizing the special
  9832. argument pointer and soft frame pointer rtx's. */
  9833. if (reg == arg_pointer_rtx || reg == frame_pointer_rtx)
  9834. {
  9835. rtx elim = (ira_use_lra_p
  9836. ? lra_eliminate_regs (reg, VOIDmode, NULL_RTX)
  9837. : eliminate_regs (reg, VOIDmode, NULL_RTX));
  9838. if (elim != reg)
  9839. {
  9840. if (GET_CODE (elim) == PLUS)
  9841. {
  9842. offset += INTVAL (XEXP (elim, 1));
  9843. elim = XEXP (elim, 0);
  9844. }
  9845. gcc_assert ((SUPPORTS_STACK_ALIGNMENT
  9846. && (elim == hard_frame_pointer_rtx
  9847. || elim == stack_pointer_rtx))
  9848. || elim == (frame_pointer_needed
  9849. ? hard_frame_pointer_rtx
  9850. : stack_pointer_rtx));
  9851. /* If drap register is used to align stack, use frame
  9852. pointer + offset to access stack variables. If stack
  9853. is aligned without drap, use stack pointer + offset to
  9854. access stack variables. */
  9855. if (crtl->stack_realign_tried
  9856. && reg == frame_pointer_rtx)
  9857. {
  9858. int base_reg
  9859. = DWARF_FRAME_REGNUM ((fde && fde->drap_reg != INVALID_REGNUM)
  9860. ? HARD_FRAME_POINTER_REGNUM
  9861. : REGNO (elim));
  9862. return new_reg_loc_descr (base_reg, offset);
  9863. }
  9864. gcc_assert (frame_pointer_fb_offset_valid);
  9865. offset += frame_pointer_fb_offset;
  9866. return new_loc_descr (DW_OP_fbreg, offset, 0);
  9867. }
  9868. }
  9869. regno = REGNO (reg);
  9870. #ifdef LEAF_REG_REMAP
  9871. if (crtl->uses_only_leaf_regs)
  9872. {
  9873. int leaf_reg = LEAF_REG_REMAP (regno);
  9874. if (leaf_reg != -1)
  9875. regno = (unsigned) leaf_reg;
  9876. }
  9877. #endif
  9878. regno = DWARF_FRAME_REGNUM (regno);
  9879. if (!optimize && fde
  9880. && (fde->drap_reg == regno || fde->vdrap_reg == regno))
  9881. {
  9882. /* Use cfa+offset to represent the location of arguments passed
  9883. on the stack when drap is used to align stack.
  9884. Only do this when not optimizing, for optimized code var-tracking
  9885. is supposed to track where the arguments live and the register
  9886. used as vdrap or drap in some spot might be used for something
  9887. else in other part of the routine. */
  9888. return new_loc_descr (DW_OP_fbreg, offset, 0);
  9889. }
  9890. if (regno <= 31)
  9891. result = new_loc_descr ((enum dwarf_location_atom) (DW_OP_breg0 + regno),
  9892. offset, 0);
  9893. else
  9894. result = new_loc_descr (DW_OP_bregx, regno, offset);
  9895. if (initialized == VAR_INIT_STATUS_UNINITIALIZED)
  9896. add_loc_descr (&result, new_loc_descr (DW_OP_GNU_uninit, 0, 0));
  9897. return result;
  9898. }
  9899. /* Return true if this RTL expression describes a base+offset calculation. */
  9900. static inline int
  9901. is_based_loc (const_rtx rtl)
  9902. {
  9903. return (GET_CODE (rtl) == PLUS
  9904. && ((REG_P (XEXP (rtl, 0))
  9905. && REGNO (XEXP (rtl, 0)) < FIRST_PSEUDO_REGISTER
  9906. && CONST_INT_P (XEXP (rtl, 1)))));
  9907. }
  9908. /* Try to handle TLS MEMs, for which mem_loc_descriptor on XEXP (mem, 0)
  9909. failed. */
  9910. static dw_loc_descr_ref
  9911. tls_mem_loc_descriptor (rtx mem)
  9912. {
  9913. tree base;
  9914. dw_loc_descr_ref loc_result;
  9915. if (MEM_EXPR (mem) == NULL_TREE || !MEM_OFFSET_KNOWN_P (mem))
  9916. return NULL;
  9917. base = get_base_address (MEM_EXPR (mem));
  9918. if (base == NULL
  9919. || TREE_CODE (base) != VAR_DECL
  9920. || !DECL_THREAD_LOCAL_P (base))
  9921. return NULL;
  9922. loc_result = loc_descriptor_from_tree (MEM_EXPR (mem), 1, NULL);
  9923. if (loc_result == NULL)
  9924. return NULL;
  9925. if (MEM_OFFSET (mem))
  9926. loc_descr_plus_const (&loc_result, MEM_OFFSET (mem));
  9927. return loc_result;
  9928. }
  9929. /* Output debug info about reason why we failed to expand expression as dwarf
  9930. expression. */
  9931. static void
  9932. expansion_failed (tree expr, rtx rtl, char const *reason)
  9933. {
  9934. if (dump_file && (dump_flags & TDF_DETAILS))
  9935. {
  9936. fprintf (dump_file, "Failed to expand as dwarf: ");
  9937. if (expr)
  9938. print_generic_expr (dump_file, expr, dump_flags);
  9939. if (rtl)
  9940. {
  9941. fprintf (dump_file, "\n");
  9942. print_rtl (dump_file, rtl);
  9943. }
  9944. fprintf (dump_file, "\nReason: %s\n", reason);
  9945. }
  9946. }
  9947. /* Helper function for const_ok_for_output. */
  9948. static bool
  9949. const_ok_for_output_1 (rtx rtl)
  9950. {
  9951. if (GET_CODE (rtl) == UNSPEC)
  9952. {
  9953. /* If delegitimize_address couldn't do anything with the UNSPEC, assume
  9954. we can't express it in the debug info. */
  9955. #ifdef ENABLE_CHECKING
  9956. /* Don't complain about TLS UNSPECs, those are just too hard to
  9957. delegitimize. Note this could be a non-decl SYMBOL_REF such as
  9958. one in a constant pool entry, so testing SYMBOL_REF_TLS_MODEL
  9959. rather than DECL_THREAD_LOCAL_P is not just an optimization. */
  9960. if (XVECLEN (rtl, 0) == 0
  9961. || GET_CODE (XVECEXP (rtl, 0, 0)) != SYMBOL_REF
  9962. || SYMBOL_REF_TLS_MODEL (XVECEXP (rtl, 0, 0)) == TLS_MODEL_NONE)
  9963. inform (current_function_decl
  9964. ? DECL_SOURCE_LOCATION (current_function_decl)
  9965. : UNKNOWN_LOCATION,
  9966. #if NUM_UNSPEC_VALUES > 0
  9967. "non-delegitimized UNSPEC %s (%d) found in variable location",
  9968. ((XINT (rtl, 1) >= 0 && XINT (rtl, 1) < NUM_UNSPEC_VALUES)
  9969. ? unspec_strings[XINT (rtl, 1)] : "unknown"),
  9970. XINT (rtl, 1));
  9971. #else
  9972. "non-delegitimized UNSPEC %d found in variable location",
  9973. XINT (rtl, 1));
  9974. #endif
  9975. #endif
  9976. expansion_failed (NULL_TREE, rtl,
  9977. "UNSPEC hasn't been delegitimized.\n");
  9978. return false;
  9979. }
  9980. if (targetm.const_not_ok_for_debug_p (rtl))
  9981. {
  9982. expansion_failed (NULL_TREE, rtl,
  9983. "Expression rejected for debug by the backend.\n");
  9984. return false;
  9985. }
  9986. /* FIXME: Refer to PR60655. It is possible for simplification
  9987. of rtl expressions in var tracking to produce such expressions.
  9988. We should really identify / validate expressions
  9989. enclosed in CONST that can be handled by assemblers on various
  9990. targets and only handle legitimate cases here. */
  9991. if (GET_CODE (rtl) != SYMBOL_REF)
  9992. {
  9993. if (GET_CODE (rtl) == NOT)
  9994. return false;
  9995. return true;
  9996. }
  9997. if (CONSTANT_POOL_ADDRESS_P (rtl))
  9998. {
  9999. bool marked;
  10000. get_pool_constant_mark (rtl, &marked);
  10001. /* If all references to this pool constant were optimized away,
  10002. it was not output and thus we can't represent it. */
  10003. if (!marked)
  10004. {
  10005. expansion_failed (NULL_TREE, rtl,
  10006. "Constant was removed from constant pool.\n");
  10007. return false;
  10008. }
  10009. }
  10010. if (SYMBOL_REF_TLS_MODEL (rtl) != TLS_MODEL_NONE)
  10011. return false;
  10012. /* Avoid references to external symbols in debug info, on several targets
  10013. the linker might even refuse to link when linking a shared library,
  10014. and in many other cases the relocations for .debug_info/.debug_loc are
  10015. dropped, so the address becomes zero anyway. Hidden symbols, guaranteed
  10016. to be defined within the same shared library or executable are fine. */
  10017. if (SYMBOL_REF_EXTERNAL_P (rtl))
  10018. {
  10019. tree decl = SYMBOL_REF_DECL (rtl);
  10020. if (decl == NULL || !targetm.binds_local_p (decl))
  10021. {
  10022. expansion_failed (NULL_TREE, rtl,
  10023. "Symbol not defined in current TU.\n");
  10024. return false;
  10025. }
  10026. }
  10027. return true;
  10028. }
  10029. /* Return true if constant RTL can be emitted in DW_OP_addr or
  10030. DW_AT_const_value. TLS SYMBOL_REFs, external SYMBOL_REFs or
  10031. non-marked constant pool SYMBOL_REFs can't be referenced in it. */
  10032. static bool
  10033. const_ok_for_output (rtx rtl)
  10034. {
  10035. if (GET_CODE (rtl) == SYMBOL_REF)
  10036. return const_ok_for_output_1 (rtl);
  10037. if (GET_CODE (rtl) == CONST)
  10038. {
  10039. subrtx_var_iterator::array_type array;
  10040. FOR_EACH_SUBRTX_VAR (iter, array, XEXP (rtl, 0), ALL)
  10041. if (!const_ok_for_output_1 (*iter))
  10042. return false;
  10043. return true;
  10044. }
  10045. return true;
  10046. }
  10047. /* Return a reference to DW_TAG_base_type corresponding to MODE and UNSIGNEDP
  10048. if possible, NULL otherwise. */
  10049. static dw_die_ref
  10050. base_type_for_mode (machine_mode mode, bool unsignedp)
  10051. {
  10052. dw_die_ref type_die;
  10053. tree type = lang_hooks.types.type_for_mode (mode, unsignedp);
  10054. if (type == NULL)
  10055. return NULL;
  10056. switch (TREE_CODE (type))
  10057. {
  10058. case INTEGER_TYPE:
  10059. case REAL_TYPE:
  10060. break;
  10061. default:
  10062. return NULL;
  10063. }
  10064. type_die = lookup_type_die (type);
  10065. if (!type_die)
  10066. type_die = modified_type_die (type, TYPE_UNQUALIFIED, comp_unit_die ());
  10067. if (type_die == NULL || type_die->die_tag != DW_TAG_base_type)
  10068. return NULL;
  10069. return type_die;
  10070. }
  10071. /* For OP descriptor assumed to be in unsigned MODE, convert it to a unsigned
  10072. type matching MODE, or, if MODE is narrower than or as wide as
  10073. DWARF2_ADDR_SIZE, untyped. Return NULL if the conversion is not
  10074. possible. */
  10075. static dw_loc_descr_ref
  10076. convert_descriptor_to_mode (machine_mode mode, dw_loc_descr_ref op)
  10077. {
  10078. machine_mode outer_mode = mode;
  10079. dw_die_ref type_die;
  10080. dw_loc_descr_ref cvt;
  10081. if (GET_MODE_SIZE (mode) <= DWARF2_ADDR_SIZE)
  10082. {
  10083. add_loc_descr (&op, new_loc_descr (DW_OP_GNU_convert, 0, 0));
  10084. return op;
  10085. }
  10086. type_die = base_type_for_mode (outer_mode, 1);
  10087. if (type_die == NULL)
  10088. return NULL;
  10089. cvt = new_loc_descr (DW_OP_GNU_convert, 0, 0);
  10090. cvt->dw_loc_oprnd1.val_class = dw_val_class_die_ref;
  10091. cvt->dw_loc_oprnd1.v.val_die_ref.die = type_die;
  10092. cvt->dw_loc_oprnd1.v.val_die_ref.external = 0;
  10093. add_loc_descr (&op, cvt);
  10094. return op;
  10095. }
  10096. /* Return location descriptor for comparison OP with operands OP0 and OP1. */
  10097. static dw_loc_descr_ref
  10098. compare_loc_descriptor (enum dwarf_location_atom op, dw_loc_descr_ref op0,
  10099. dw_loc_descr_ref op1)
  10100. {
  10101. dw_loc_descr_ref ret = op0;
  10102. add_loc_descr (&ret, op1);
  10103. add_loc_descr (&ret, new_loc_descr (op, 0, 0));
  10104. if (STORE_FLAG_VALUE != 1)
  10105. {
  10106. add_loc_descr (&ret, int_loc_descriptor (STORE_FLAG_VALUE));
  10107. add_loc_descr (&ret, new_loc_descr (DW_OP_mul, 0, 0));
  10108. }
  10109. return ret;
  10110. }
  10111. /* Return location descriptor for signed comparison OP RTL. */
  10112. static dw_loc_descr_ref
  10113. scompare_loc_descriptor (enum dwarf_location_atom op, rtx rtl,
  10114. machine_mode mem_mode)
  10115. {
  10116. machine_mode op_mode = GET_MODE (XEXP (rtl, 0));
  10117. dw_loc_descr_ref op0, op1;
  10118. int shift;
  10119. if (op_mode == VOIDmode)
  10120. op_mode = GET_MODE (XEXP (rtl, 1));
  10121. if (op_mode == VOIDmode)
  10122. return NULL;
  10123. if (dwarf_strict
  10124. && (GET_MODE_CLASS (op_mode) != MODE_INT
  10125. || GET_MODE_SIZE (op_mode) > DWARF2_ADDR_SIZE))
  10126. return NULL;
  10127. op0 = mem_loc_descriptor (XEXP (rtl, 0), op_mode, mem_mode,
  10128. VAR_INIT_STATUS_INITIALIZED);
  10129. op1 = mem_loc_descriptor (XEXP (rtl, 1), op_mode, mem_mode,
  10130. VAR_INIT_STATUS_INITIALIZED);
  10131. if (op0 == NULL || op1 == NULL)
  10132. return NULL;
  10133. if (GET_MODE_CLASS (op_mode) != MODE_INT
  10134. || GET_MODE_SIZE (op_mode) == DWARF2_ADDR_SIZE)
  10135. return compare_loc_descriptor (op, op0, op1);
  10136. if (GET_MODE_SIZE (op_mode) > DWARF2_ADDR_SIZE)
  10137. {
  10138. dw_die_ref type_die = base_type_for_mode (op_mode, 0);
  10139. dw_loc_descr_ref cvt;
  10140. if (type_die == NULL)
  10141. return NULL;
  10142. cvt = new_loc_descr (DW_OP_GNU_convert, 0, 0);
  10143. cvt->dw_loc_oprnd1.val_class = dw_val_class_die_ref;
  10144. cvt->dw_loc_oprnd1.v.val_die_ref.die = type_die;
  10145. cvt->dw_loc_oprnd1.v.val_die_ref.external = 0;
  10146. add_loc_descr (&op0, cvt);
  10147. cvt = new_loc_descr (DW_OP_GNU_convert, 0, 0);
  10148. cvt->dw_loc_oprnd1.val_class = dw_val_class_die_ref;
  10149. cvt->dw_loc_oprnd1.v.val_die_ref.die = type_die;
  10150. cvt->dw_loc_oprnd1.v.val_die_ref.external = 0;
  10151. add_loc_descr (&op1, cvt);
  10152. return compare_loc_descriptor (op, op0, op1);
  10153. }
  10154. shift = (DWARF2_ADDR_SIZE - GET_MODE_SIZE (op_mode)) * BITS_PER_UNIT;
  10155. /* For eq/ne, if the operands are known to be zero-extended,
  10156. there is no need to do the fancy shifting up. */
  10157. if (op == DW_OP_eq || op == DW_OP_ne)
  10158. {
  10159. dw_loc_descr_ref last0, last1;
  10160. for (last0 = op0; last0->dw_loc_next != NULL; last0 = last0->dw_loc_next)
  10161. ;
  10162. for (last1 = op1; last1->dw_loc_next != NULL; last1 = last1->dw_loc_next)
  10163. ;
  10164. /* deref_size zero extends, and for constants we can check
  10165. whether they are zero extended or not. */
  10166. if (((last0->dw_loc_opc == DW_OP_deref_size
  10167. && last0->dw_loc_oprnd1.v.val_int <= GET_MODE_SIZE (op_mode))
  10168. || (CONST_INT_P (XEXP (rtl, 0))
  10169. && (unsigned HOST_WIDE_INT) INTVAL (XEXP (rtl, 0))
  10170. == (INTVAL (XEXP (rtl, 0)) & GET_MODE_MASK (op_mode))))
  10171. && ((last1->dw_loc_opc == DW_OP_deref_size
  10172. && last1->dw_loc_oprnd1.v.val_int <= GET_MODE_SIZE (op_mode))
  10173. || (CONST_INT_P (XEXP (rtl, 1))
  10174. && (unsigned HOST_WIDE_INT) INTVAL (XEXP (rtl, 1))
  10175. == (INTVAL (XEXP (rtl, 1)) & GET_MODE_MASK (op_mode)))))
  10176. return compare_loc_descriptor (op, op0, op1);
  10177. /* EQ/NE comparison against constant in narrower type than
  10178. DWARF2_ADDR_SIZE can be performed either as
  10179. DW_OP_const1u <shift> DW_OP_shl DW_OP_const* <cst << shift>
  10180. DW_OP_{eq,ne}
  10181. or
  10182. DW_OP_const*u <mode_mask> DW_OP_and DW_OP_const* <cst & mode_mask>
  10183. DW_OP_{eq,ne}. Pick whatever is shorter. */
  10184. if (CONST_INT_P (XEXP (rtl, 1))
  10185. && GET_MODE_BITSIZE (op_mode) < HOST_BITS_PER_WIDE_INT
  10186. && (size_of_int_loc_descriptor (shift) + 1
  10187. + size_of_int_loc_descriptor (INTVAL (XEXP (rtl, 1)) << shift)
  10188. >= size_of_int_loc_descriptor (GET_MODE_MASK (op_mode)) + 1
  10189. + size_of_int_loc_descriptor (INTVAL (XEXP (rtl, 1))
  10190. & GET_MODE_MASK (op_mode))))
  10191. {
  10192. add_loc_descr (&op0, int_loc_descriptor (GET_MODE_MASK (op_mode)));
  10193. add_loc_descr (&op0, new_loc_descr (DW_OP_and, 0, 0));
  10194. op1 = int_loc_descriptor (INTVAL (XEXP (rtl, 1))
  10195. & GET_MODE_MASK (op_mode));
  10196. return compare_loc_descriptor (op, op0, op1);
  10197. }
  10198. }
  10199. add_loc_descr (&op0, int_loc_descriptor (shift));
  10200. add_loc_descr (&op0, new_loc_descr (DW_OP_shl, 0, 0));
  10201. if (CONST_INT_P (XEXP (rtl, 1)))
  10202. op1 = int_loc_descriptor (INTVAL (XEXP (rtl, 1)) << shift);
  10203. else
  10204. {
  10205. add_loc_descr (&op1, int_loc_descriptor (shift));
  10206. add_loc_descr (&op1, new_loc_descr (DW_OP_shl, 0, 0));
  10207. }
  10208. return compare_loc_descriptor (op, op0, op1);
  10209. }
  10210. /* Return location descriptor for unsigned comparison OP RTL. */
  10211. static dw_loc_descr_ref
  10212. ucompare_loc_descriptor (enum dwarf_location_atom op, rtx rtl,
  10213. machine_mode mem_mode)
  10214. {
  10215. machine_mode op_mode = GET_MODE (XEXP (rtl, 0));
  10216. dw_loc_descr_ref op0, op1;
  10217. if (op_mode == VOIDmode)
  10218. op_mode = GET_MODE (XEXP (rtl, 1));
  10219. if (op_mode == VOIDmode)
  10220. return NULL;
  10221. if (GET_MODE_CLASS (op_mode) != MODE_INT)
  10222. return NULL;
  10223. if (dwarf_strict && GET_MODE_SIZE (op_mode) > DWARF2_ADDR_SIZE)
  10224. return NULL;
  10225. op0 = mem_loc_descriptor (XEXP (rtl, 0), op_mode, mem_mode,
  10226. VAR_INIT_STATUS_INITIALIZED);
  10227. op1 = mem_loc_descriptor (XEXP (rtl, 1), op_mode, mem_mode,
  10228. VAR_INIT_STATUS_INITIALIZED);
  10229. if (op0 == NULL || op1 == NULL)
  10230. return NULL;
  10231. if (GET_MODE_SIZE (op_mode) < DWARF2_ADDR_SIZE)
  10232. {
  10233. HOST_WIDE_INT mask = GET_MODE_MASK (op_mode);
  10234. dw_loc_descr_ref last0, last1;
  10235. for (last0 = op0; last0->dw_loc_next != NULL; last0 = last0->dw_loc_next)
  10236. ;
  10237. for (last1 = op1; last1->dw_loc_next != NULL; last1 = last1->dw_loc_next)
  10238. ;
  10239. if (CONST_INT_P (XEXP (rtl, 0)))
  10240. op0 = int_loc_descriptor (INTVAL (XEXP (rtl, 0)) & mask);
  10241. /* deref_size zero extends, so no need to mask it again. */
  10242. else if (last0->dw_loc_opc != DW_OP_deref_size
  10243. || last0->dw_loc_oprnd1.v.val_int > GET_MODE_SIZE (op_mode))
  10244. {
  10245. add_loc_descr (&op0, int_loc_descriptor (mask));
  10246. add_loc_descr (&op0, new_loc_descr (DW_OP_and, 0, 0));
  10247. }
  10248. if (CONST_INT_P (XEXP (rtl, 1)))
  10249. op1 = int_loc_descriptor (INTVAL (XEXP (rtl, 1)) & mask);
  10250. /* deref_size zero extends, so no need to mask it again. */
  10251. else if (last1->dw_loc_opc != DW_OP_deref_size
  10252. || last1->dw_loc_oprnd1.v.val_int > GET_MODE_SIZE (op_mode))
  10253. {
  10254. add_loc_descr (&op1, int_loc_descriptor (mask));
  10255. add_loc_descr (&op1, new_loc_descr (DW_OP_and, 0, 0));
  10256. }
  10257. }
  10258. else if (GET_MODE_SIZE (op_mode) == DWARF2_ADDR_SIZE)
  10259. {
  10260. HOST_WIDE_INT bias = 1;
  10261. bias <<= (DWARF2_ADDR_SIZE * BITS_PER_UNIT - 1);
  10262. add_loc_descr (&op0, new_loc_descr (DW_OP_plus_uconst, bias, 0));
  10263. if (CONST_INT_P (XEXP (rtl, 1)))
  10264. op1 = int_loc_descriptor ((unsigned HOST_WIDE_INT) bias
  10265. + INTVAL (XEXP (rtl, 1)));
  10266. else
  10267. add_loc_descr (&op1, new_loc_descr (DW_OP_plus_uconst,
  10268. bias, 0));
  10269. }
  10270. return compare_loc_descriptor (op, op0, op1);
  10271. }
  10272. /* Return location descriptor for {U,S}{MIN,MAX}. */
  10273. static dw_loc_descr_ref
  10274. minmax_loc_descriptor (rtx rtl, machine_mode mode,
  10275. machine_mode mem_mode)
  10276. {
  10277. enum dwarf_location_atom op;
  10278. dw_loc_descr_ref op0, op1, ret;
  10279. dw_loc_descr_ref bra_node, drop_node;
  10280. if (dwarf_strict
  10281. && (GET_MODE_CLASS (mode) != MODE_INT
  10282. || GET_MODE_SIZE (mode) > DWARF2_ADDR_SIZE))
  10283. return NULL;
  10284. op0 = mem_loc_descriptor (XEXP (rtl, 0), mode, mem_mode,
  10285. VAR_INIT_STATUS_INITIALIZED);
  10286. op1 = mem_loc_descriptor (XEXP (rtl, 1), mode, mem_mode,
  10287. VAR_INIT_STATUS_INITIALIZED);
  10288. if (op0 == NULL || op1 == NULL)
  10289. return NULL;
  10290. add_loc_descr (&op0, new_loc_descr (DW_OP_dup, 0, 0));
  10291. add_loc_descr (&op1, new_loc_descr (DW_OP_swap, 0, 0));
  10292. add_loc_descr (&op1, new_loc_descr (DW_OP_over, 0, 0));
  10293. if (GET_CODE (rtl) == UMIN || GET_CODE (rtl) == UMAX)
  10294. {
  10295. if (GET_MODE_SIZE (mode) < DWARF2_ADDR_SIZE)
  10296. {
  10297. HOST_WIDE_INT mask = GET_MODE_MASK (mode);
  10298. add_loc_descr (&op0, int_loc_descriptor (mask));
  10299. add_loc_descr (&op0, new_loc_descr (DW_OP_and, 0, 0));
  10300. add_loc_descr (&op1, int_loc_descriptor (mask));
  10301. add_loc_descr (&op1, new_loc_descr (DW_OP_and, 0, 0));
  10302. }
  10303. else if (GET_MODE_SIZE (mode) == DWARF2_ADDR_SIZE)
  10304. {
  10305. HOST_WIDE_INT bias = 1;
  10306. bias <<= (DWARF2_ADDR_SIZE * BITS_PER_UNIT - 1);
  10307. add_loc_descr (&op0, new_loc_descr (DW_OP_plus_uconst, bias, 0));
  10308. add_loc_descr (&op1, new_loc_descr (DW_OP_plus_uconst, bias, 0));
  10309. }
  10310. }
  10311. else if (GET_MODE_CLASS (mode) == MODE_INT
  10312. && GET_MODE_SIZE (mode) < DWARF2_ADDR_SIZE)
  10313. {
  10314. int shift = (DWARF2_ADDR_SIZE - GET_MODE_SIZE (mode)) * BITS_PER_UNIT;
  10315. add_loc_descr (&op0, int_loc_descriptor (shift));
  10316. add_loc_descr (&op0, new_loc_descr (DW_OP_shl, 0, 0));
  10317. add_loc_descr (&op1, int_loc_descriptor (shift));
  10318. add_loc_descr (&op1, new_loc_descr (DW_OP_shl, 0, 0));
  10319. }
  10320. else if (GET_MODE_CLASS (mode) == MODE_INT
  10321. && GET_MODE_SIZE (mode) > DWARF2_ADDR_SIZE)
  10322. {
  10323. dw_die_ref type_die = base_type_for_mode (mode, 0);
  10324. dw_loc_descr_ref cvt;
  10325. if (type_die == NULL)
  10326. return NULL;
  10327. cvt = new_loc_descr (DW_OP_GNU_convert, 0, 0);
  10328. cvt->dw_loc_oprnd1.val_class = dw_val_class_die_ref;
  10329. cvt->dw_loc_oprnd1.v.val_die_ref.die = type_die;
  10330. cvt->dw_loc_oprnd1.v.val_die_ref.external = 0;
  10331. add_loc_descr (&op0, cvt);
  10332. cvt = new_loc_descr (DW_OP_GNU_convert, 0, 0);
  10333. cvt->dw_loc_oprnd1.val_class = dw_val_class_die_ref;
  10334. cvt->dw_loc_oprnd1.v.val_die_ref.die = type_die;
  10335. cvt->dw_loc_oprnd1.v.val_die_ref.external = 0;
  10336. add_loc_descr (&op1, cvt);
  10337. }
  10338. if (GET_CODE (rtl) == SMIN || GET_CODE (rtl) == UMIN)
  10339. op = DW_OP_lt;
  10340. else
  10341. op = DW_OP_gt;
  10342. ret = op0;
  10343. add_loc_descr (&ret, op1);
  10344. add_loc_descr (&ret, new_loc_descr (op, 0, 0));
  10345. bra_node = new_loc_descr (DW_OP_bra, 0, 0);
  10346. add_loc_descr (&ret, bra_node);
  10347. add_loc_descr (&ret, new_loc_descr (DW_OP_swap, 0, 0));
  10348. drop_node = new_loc_descr (DW_OP_drop, 0, 0);
  10349. add_loc_descr (&ret, drop_node);
  10350. bra_node->dw_loc_oprnd1.val_class = dw_val_class_loc;
  10351. bra_node->dw_loc_oprnd1.v.val_loc = drop_node;
  10352. if ((GET_CODE (rtl) == SMIN || GET_CODE (rtl) == SMAX)
  10353. && GET_MODE_CLASS (mode) == MODE_INT
  10354. && GET_MODE_SIZE (mode) > DWARF2_ADDR_SIZE)
  10355. ret = convert_descriptor_to_mode (mode, ret);
  10356. return ret;
  10357. }
  10358. /* Helper function for mem_loc_descriptor. Perform OP binary op,
  10359. but after converting arguments to type_die, afterwards
  10360. convert back to unsigned. */
  10361. static dw_loc_descr_ref
  10362. typed_binop (enum dwarf_location_atom op, rtx rtl, dw_die_ref type_die,
  10363. machine_mode mode, machine_mode mem_mode)
  10364. {
  10365. dw_loc_descr_ref cvt, op0, op1;
  10366. if (type_die == NULL)
  10367. return NULL;
  10368. op0 = mem_loc_descriptor (XEXP (rtl, 0), mode, mem_mode,
  10369. VAR_INIT_STATUS_INITIALIZED);
  10370. op1 = mem_loc_descriptor (XEXP (rtl, 1), mode, mem_mode,
  10371. VAR_INIT_STATUS_INITIALIZED);
  10372. if (op0 == NULL || op1 == NULL)
  10373. return NULL;
  10374. cvt = new_loc_descr (DW_OP_GNU_convert, 0, 0);
  10375. cvt->dw_loc_oprnd1.val_class = dw_val_class_die_ref;
  10376. cvt->dw_loc_oprnd1.v.val_die_ref.die = type_die;
  10377. cvt->dw_loc_oprnd1.v.val_die_ref.external = 0;
  10378. add_loc_descr (&op0, cvt);
  10379. cvt = new_loc_descr (DW_OP_GNU_convert, 0, 0);
  10380. cvt->dw_loc_oprnd1.val_class = dw_val_class_die_ref;
  10381. cvt->dw_loc_oprnd1.v.val_die_ref.die = type_die;
  10382. cvt->dw_loc_oprnd1.v.val_die_ref.external = 0;
  10383. add_loc_descr (&op1, cvt);
  10384. add_loc_descr (&op0, op1);
  10385. add_loc_descr (&op0, new_loc_descr (op, 0, 0));
  10386. return convert_descriptor_to_mode (mode, op0);
  10387. }
  10388. /* CLZ (where constV is CLZ_DEFINED_VALUE_AT_ZERO computed value,
  10389. const0 is DW_OP_lit0 or corresponding typed constant,
  10390. const1 is DW_OP_lit1 or corresponding typed constant
  10391. and constMSB is constant with just the MSB bit set
  10392. for the mode):
  10393. DW_OP_dup DW_OP_bra <L1> DW_OP_drop constV DW_OP_skip <L4>
  10394. L1: const0 DW_OP_swap
  10395. L2: DW_OP_dup constMSB DW_OP_and DW_OP_bra <L3> const1 DW_OP_shl
  10396. DW_OP_swap DW_OP_plus_uconst <1> DW_OP_swap DW_OP_skip <L2>
  10397. L3: DW_OP_drop
  10398. L4: DW_OP_nop
  10399. CTZ is similar:
  10400. DW_OP_dup DW_OP_bra <L1> DW_OP_drop constV DW_OP_skip <L4>
  10401. L1: const0 DW_OP_swap
  10402. L2: DW_OP_dup const1 DW_OP_and DW_OP_bra <L3> const1 DW_OP_shr
  10403. DW_OP_swap DW_OP_plus_uconst <1> DW_OP_swap DW_OP_skip <L2>
  10404. L3: DW_OP_drop
  10405. L4: DW_OP_nop
  10406. FFS is similar:
  10407. DW_OP_dup DW_OP_bra <L1> DW_OP_drop const0 DW_OP_skip <L4>
  10408. L1: const1 DW_OP_swap
  10409. L2: DW_OP_dup const1 DW_OP_and DW_OP_bra <L3> const1 DW_OP_shr
  10410. DW_OP_swap DW_OP_plus_uconst <1> DW_OP_swap DW_OP_skip <L2>
  10411. L3: DW_OP_drop
  10412. L4: DW_OP_nop */
  10413. static dw_loc_descr_ref
  10414. clz_loc_descriptor (rtx rtl, machine_mode mode,
  10415. machine_mode mem_mode)
  10416. {
  10417. dw_loc_descr_ref op0, ret, tmp;
  10418. HOST_WIDE_INT valv;
  10419. dw_loc_descr_ref l1jump, l1label;
  10420. dw_loc_descr_ref l2jump, l2label;
  10421. dw_loc_descr_ref l3jump, l3label;
  10422. dw_loc_descr_ref l4jump, l4label;
  10423. rtx msb;
  10424. if (GET_MODE_CLASS (mode) != MODE_INT
  10425. || GET_MODE (XEXP (rtl, 0)) != mode)
  10426. return NULL;
  10427. op0 = mem_loc_descriptor (XEXP (rtl, 0), mode, mem_mode,
  10428. VAR_INIT_STATUS_INITIALIZED);
  10429. if (op0 == NULL)
  10430. return NULL;
  10431. ret = op0;
  10432. if (GET_CODE (rtl) == CLZ)
  10433. {
  10434. if (!CLZ_DEFINED_VALUE_AT_ZERO (mode, valv))
  10435. valv = GET_MODE_BITSIZE (mode);
  10436. }
  10437. else if (GET_CODE (rtl) == FFS)
  10438. valv = 0;
  10439. else if (!CTZ_DEFINED_VALUE_AT_ZERO (mode, valv))
  10440. valv = GET_MODE_BITSIZE (mode);
  10441. add_loc_descr (&ret, new_loc_descr (DW_OP_dup, 0, 0));
  10442. l1jump = new_loc_descr (DW_OP_bra, 0, 0);
  10443. add_loc_descr (&ret, l1jump);
  10444. add_loc_descr (&ret, new_loc_descr (DW_OP_drop, 0, 0));
  10445. tmp = mem_loc_descriptor (GEN_INT (valv), mode, mem_mode,
  10446. VAR_INIT_STATUS_INITIALIZED);
  10447. if (tmp == NULL)
  10448. return NULL;
  10449. add_loc_descr (&ret, tmp);
  10450. l4jump = new_loc_descr (DW_OP_skip, 0, 0);
  10451. add_loc_descr (&ret, l4jump);
  10452. l1label = mem_loc_descriptor (GET_CODE (rtl) == FFS
  10453. ? const1_rtx : const0_rtx,
  10454. mode, mem_mode,
  10455. VAR_INIT_STATUS_INITIALIZED);
  10456. if (l1label == NULL)
  10457. return NULL;
  10458. add_loc_descr (&ret, l1label);
  10459. add_loc_descr (&ret, new_loc_descr (DW_OP_swap, 0, 0));
  10460. l2label = new_loc_descr (DW_OP_dup, 0, 0);
  10461. add_loc_descr (&ret, l2label);
  10462. if (GET_CODE (rtl) != CLZ)
  10463. msb = const1_rtx;
  10464. else if (GET_MODE_BITSIZE (mode) <= HOST_BITS_PER_WIDE_INT)
  10465. msb = GEN_INT ((unsigned HOST_WIDE_INT) 1
  10466. << (GET_MODE_BITSIZE (mode) - 1));
  10467. else
  10468. msb = immed_wide_int_const
  10469. (wi::set_bit_in_zero (GET_MODE_PRECISION (mode) - 1,
  10470. GET_MODE_PRECISION (mode)), mode);
  10471. if (GET_CODE (msb) == CONST_INT && INTVAL (msb) < 0)
  10472. tmp = new_loc_descr (HOST_BITS_PER_WIDE_INT == 32
  10473. ? DW_OP_const4u : HOST_BITS_PER_WIDE_INT == 64
  10474. ? DW_OP_const8u : DW_OP_constu, INTVAL (msb), 0);
  10475. else
  10476. tmp = mem_loc_descriptor (msb, mode, mem_mode,
  10477. VAR_INIT_STATUS_INITIALIZED);
  10478. if (tmp == NULL)
  10479. return NULL;
  10480. add_loc_descr (&ret, tmp);
  10481. add_loc_descr (&ret, new_loc_descr (DW_OP_and, 0, 0));
  10482. l3jump = new_loc_descr (DW_OP_bra, 0, 0);
  10483. add_loc_descr (&ret, l3jump);
  10484. tmp = mem_loc_descriptor (const1_rtx, mode, mem_mode,
  10485. VAR_INIT_STATUS_INITIALIZED);
  10486. if (tmp == NULL)
  10487. return NULL;
  10488. add_loc_descr (&ret, tmp);
  10489. add_loc_descr (&ret, new_loc_descr (GET_CODE (rtl) == CLZ
  10490. ? DW_OP_shl : DW_OP_shr, 0, 0));
  10491. add_loc_descr (&ret, new_loc_descr (DW_OP_swap, 0, 0));
  10492. add_loc_descr (&ret, new_loc_descr (DW_OP_plus_uconst, 1, 0));
  10493. add_loc_descr (&ret, new_loc_descr (DW_OP_swap, 0, 0));
  10494. l2jump = new_loc_descr (DW_OP_skip, 0, 0);
  10495. add_loc_descr (&ret, l2jump);
  10496. l3label = new_loc_descr (DW_OP_drop, 0, 0);
  10497. add_loc_descr (&ret, l3label);
  10498. l4label = new_loc_descr (DW_OP_nop, 0, 0);
  10499. add_loc_descr (&ret, l4label);
  10500. l1jump->dw_loc_oprnd1.val_class = dw_val_class_loc;
  10501. l1jump->dw_loc_oprnd1.v.val_loc = l1label;
  10502. l2jump->dw_loc_oprnd1.val_class = dw_val_class_loc;
  10503. l2jump->dw_loc_oprnd1.v.val_loc = l2label;
  10504. l3jump->dw_loc_oprnd1.val_class = dw_val_class_loc;
  10505. l3jump->dw_loc_oprnd1.v.val_loc = l3label;
  10506. l4jump->dw_loc_oprnd1.val_class = dw_val_class_loc;
  10507. l4jump->dw_loc_oprnd1.v.val_loc = l4label;
  10508. return ret;
  10509. }
  10510. /* POPCOUNT (const0 is DW_OP_lit0 or corresponding typed constant,
  10511. const1 is DW_OP_lit1 or corresponding typed constant):
  10512. const0 DW_OP_swap
  10513. L1: DW_OP_dup DW_OP_bra <L2> DW_OP_dup DW_OP_rot const1 DW_OP_and
  10514. DW_OP_plus DW_OP_swap const1 DW_OP_shr DW_OP_skip <L1>
  10515. L2: DW_OP_drop
  10516. PARITY is similar:
  10517. L1: DW_OP_dup DW_OP_bra <L2> DW_OP_dup DW_OP_rot const1 DW_OP_and
  10518. DW_OP_xor DW_OP_swap const1 DW_OP_shr DW_OP_skip <L1>
  10519. L2: DW_OP_drop */
  10520. static dw_loc_descr_ref
  10521. popcount_loc_descriptor (rtx rtl, machine_mode mode,
  10522. machine_mode mem_mode)
  10523. {
  10524. dw_loc_descr_ref op0, ret, tmp;
  10525. dw_loc_descr_ref l1jump, l1label;
  10526. dw_loc_descr_ref l2jump, l2label;
  10527. if (GET_MODE_CLASS (mode) != MODE_INT
  10528. || GET_MODE (XEXP (rtl, 0)) != mode)
  10529. return NULL;
  10530. op0 = mem_loc_descriptor (XEXP (rtl, 0), mode, mem_mode,
  10531. VAR_INIT_STATUS_INITIALIZED);
  10532. if (op0 == NULL)
  10533. return NULL;
  10534. ret = op0;
  10535. tmp = mem_loc_descriptor (const0_rtx, mode, mem_mode,
  10536. VAR_INIT_STATUS_INITIALIZED);
  10537. if (tmp == NULL)
  10538. return NULL;
  10539. add_loc_descr (&ret, tmp);
  10540. add_loc_descr (&ret, new_loc_descr (DW_OP_swap, 0, 0));
  10541. l1label = new_loc_descr (DW_OP_dup, 0, 0);
  10542. add_loc_descr (&ret, l1label);
  10543. l2jump = new_loc_descr (DW_OP_bra, 0, 0);
  10544. add_loc_descr (&ret, l2jump);
  10545. add_loc_descr (&ret, new_loc_descr (DW_OP_dup, 0, 0));
  10546. add_loc_descr (&ret, new_loc_descr (DW_OP_rot, 0, 0));
  10547. tmp = mem_loc_descriptor (const1_rtx, mode, mem_mode,
  10548. VAR_INIT_STATUS_INITIALIZED);
  10549. if (tmp == NULL)
  10550. return NULL;
  10551. add_loc_descr (&ret, tmp);
  10552. add_loc_descr (&ret, new_loc_descr (DW_OP_and, 0, 0));
  10553. add_loc_descr (&ret, new_loc_descr (GET_CODE (rtl) == POPCOUNT
  10554. ? DW_OP_plus : DW_OP_xor, 0, 0));
  10555. add_loc_descr (&ret, new_loc_descr (DW_OP_swap, 0, 0));
  10556. tmp = mem_loc_descriptor (const1_rtx, mode, mem_mode,
  10557. VAR_INIT_STATUS_INITIALIZED);
  10558. add_loc_descr (&ret, tmp);
  10559. add_loc_descr (&ret, new_loc_descr (DW_OP_shr, 0, 0));
  10560. l1jump = new_loc_descr (DW_OP_skip, 0, 0);
  10561. add_loc_descr (&ret, l1jump);
  10562. l2label = new_loc_descr (DW_OP_drop, 0, 0);
  10563. add_loc_descr (&ret, l2label);
  10564. l1jump->dw_loc_oprnd1.val_class = dw_val_class_loc;
  10565. l1jump->dw_loc_oprnd1.v.val_loc = l1label;
  10566. l2jump->dw_loc_oprnd1.val_class = dw_val_class_loc;
  10567. l2jump->dw_loc_oprnd1.v.val_loc = l2label;
  10568. return ret;
  10569. }
  10570. /* BSWAP (constS is initial shift count, either 56 or 24):
  10571. constS const0
  10572. L1: DW_OP_pick <2> constS DW_OP_pick <3> DW_OP_minus DW_OP_shr
  10573. const255 DW_OP_and DW_OP_pick <2> DW_OP_shl DW_OP_or
  10574. DW_OP_swap DW_OP_dup const0 DW_OP_eq DW_OP_bra <L2> const8
  10575. DW_OP_minus DW_OP_swap DW_OP_skip <L1>
  10576. L2: DW_OP_drop DW_OP_swap DW_OP_drop */
  10577. static dw_loc_descr_ref
  10578. bswap_loc_descriptor (rtx rtl, machine_mode mode,
  10579. machine_mode mem_mode)
  10580. {
  10581. dw_loc_descr_ref op0, ret, tmp;
  10582. dw_loc_descr_ref l1jump, l1label;
  10583. dw_loc_descr_ref l2jump, l2label;
  10584. if (GET_MODE_CLASS (mode) != MODE_INT
  10585. || BITS_PER_UNIT != 8
  10586. || (GET_MODE_BITSIZE (mode) != 32
  10587. && GET_MODE_BITSIZE (mode) != 64))
  10588. return NULL;
  10589. op0 = mem_loc_descriptor (XEXP (rtl, 0), mode, mem_mode,
  10590. VAR_INIT_STATUS_INITIALIZED);
  10591. if (op0 == NULL)
  10592. return NULL;
  10593. ret = op0;
  10594. tmp = mem_loc_descriptor (GEN_INT (GET_MODE_BITSIZE (mode) - 8),
  10595. mode, mem_mode,
  10596. VAR_INIT_STATUS_INITIALIZED);
  10597. if (tmp == NULL)
  10598. return NULL;
  10599. add_loc_descr (&ret, tmp);
  10600. tmp = mem_loc_descriptor (const0_rtx, mode, mem_mode,
  10601. VAR_INIT_STATUS_INITIALIZED);
  10602. if (tmp == NULL)
  10603. return NULL;
  10604. add_loc_descr (&ret, tmp);
  10605. l1label = new_loc_descr (DW_OP_pick, 2, 0);
  10606. add_loc_descr (&ret, l1label);
  10607. tmp = mem_loc_descriptor (GEN_INT (GET_MODE_BITSIZE (mode) - 8),
  10608. mode, mem_mode,
  10609. VAR_INIT_STATUS_INITIALIZED);
  10610. add_loc_descr (&ret, tmp);
  10611. add_loc_descr (&ret, new_loc_descr (DW_OP_pick, 3, 0));
  10612. add_loc_descr (&ret, new_loc_descr (DW_OP_minus, 0, 0));
  10613. add_loc_descr (&ret, new_loc_descr (DW_OP_shr, 0, 0));
  10614. tmp = mem_loc_descriptor (GEN_INT (255), mode, mem_mode,
  10615. VAR_INIT_STATUS_INITIALIZED);
  10616. if (tmp == NULL)
  10617. return NULL;
  10618. add_loc_descr (&ret, tmp);
  10619. add_loc_descr (&ret, new_loc_descr (DW_OP_and, 0, 0));
  10620. add_loc_descr (&ret, new_loc_descr (DW_OP_pick, 2, 0));
  10621. add_loc_descr (&ret, new_loc_descr (DW_OP_shl, 0, 0));
  10622. add_loc_descr (&ret, new_loc_descr (DW_OP_or, 0, 0));
  10623. add_loc_descr (&ret, new_loc_descr (DW_OP_swap, 0, 0));
  10624. add_loc_descr (&ret, new_loc_descr (DW_OP_dup, 0, 0));
  10625. tmp = mem_loc_descriptor (const0_rtx, mode, mem_mode,
  10626. VAR_INIT_STATUS_INITIALIZED);
  10627. add_loc_descr (&ret, tmp);
  10628. add_loc_descr (&ret, new_loc_descr (DW_OP_eq, 0, 0));
  10629. l2jump = new_loc_descr (DW_OP_bra, 0, 0);
  10630. add_loc_descr (&ret, l2jump);
  10631. tmp = mem_loc_descriptor (GEN_INT (8), mode, mem_mode,
  10632. VAR_INIT_STATUS_INITIALIZED);
  10633. add_loc_descr (&ret, tmp);
  10634. add_loc_descr (&ret, new_loc_descr (DW_OP_minus, 0, 0));
  10635. add_loc_descr (&ret, new_loc_descr (DW_OP_swap, 0, 0));
  10636. l1jump = new_loc_descr (DW_OP_skip, 0, 0);
  10637. add_loc_descr (&ret, l1jump);
  10638. l2label = new_loc_descr (DW_OP_drop, 0, 0);
  10639. add_loc_descr (&ret, l2label);
  10640. add_loc_descr (&ret, new_loc_descr (DW_OP_swap, 0, 0));
  10641. add_loc_descr (&ret, new_loc_descr (DW_OP_drop, 0, 0));
  10642. l1jump->dw_loc_oprnd1.val_class = dw_val_class_loc;
  10643. l1jump->dw_loc_oprnd1.v.val_loc = l1label;
  10644. l2jump->dw_loc_oprnd1.val_class = dw_val_class_loc;
  10645. l2jump->dw_loc_oprnd1.v.val_loc = l2label;
  10646. return ret;
  10647. }
  10648. /* ROTATE (constMASK is mode mask, BITSIZE is bitsize of mode):
  10649. DW_OP_over DW_OP_over DW_OP_shl [ constMASK DW_OP_and ] DW_OP_rot
  10650. [ DW_OP_swap constMASK DW_OP_and DW_OP_swap ] DW_OP_neg
  10651. DW_OP_plus_uconst <BITSIZE> DW_OP_shr DW_OP_or
  10652. ROTATERT is similar:
  10653. DW_OP_over DW_OP_over DW_OP_neg DW_OP_plus_uconst <BITSIZE>
  10654. DW_OP_shl [ constMASK DW_OP_and ] DW_OP_rot
  10655. [ DW_OP_swap constMASK DW_OP_and DW_OP_swap ] DW_OP_shr DW_OP_or */
  10656. static dw_loc_descr_ref
  10657. rotate_loc_descriptor (rtx rtl, machine_mode mode,
  10658. machine_mode mem_mode)
  10659. {
  10660. rtx rtlop1 = XEXP (rtl, 1);
  10661. dw_loc_descr_ref op0, op1, ret, mask[2] = { NULL, NULL };
  10662. int i;
  10663. if (GET_MODE_CLASS (mode) != MODE_INT)
  10664. return NULL;
  10665. if (GET_MODE (rtlop1) != VOIDmode
  10666. && GET_MODE_BITSIZE (GET_MODE (rtlop1)) < GET_MODE_BITSIZE (mode))
  10667. rtlop1 = gen_rtx_ZERO_EXTEND (mode, rtlop1);
  10668. op0 = mem_loc_descriptor (XEXP (rtl, 0), mode, mem_mode,
  10669. VAR_INIT_STATUS_INITIALIZED);
  10670. op1 = mem_loc_descriptor (rtlop1, mode, mem_mode,
  10671. VAR_INIT_STATUS_INITIALIZED);
  10672. if (op0 == NULL || op1 == NULL)
  10673. return NULL;
  10674. if (GET_MODE_SIZE (mode) < DWARF2_ADDR_SIZE)
  10675. for (i = 0; i < 2; i++)
  10676. {
  10677. if (GET_MODE_BITSIZE (mode) < HOST_BITS_PER_WIDE_INT)
  10678. mask[i] = mem_loc_descriptor (GEN_INT (GET_MODE_MASK (mode)),
  10679. mode, mem_mode,
  10680. VAR_INIT_STATUS_INITIALIZED);
  10681. else if (GET_MODE_BITSIZE (mode) == HOST_BITS_PER_WIDE_INT)
  10682. mask[i] = new_loc_descr (HOST_BITS_PER_WIDE_INT == 32
  10683. ? DW_OP_const4u
  10684. : HOST_BITS_PER_WIDE_INT == 64
  10685. ? DW_OP_const8u : DW_OP_constu,
  10686. GET_MODE_MASK (mode), 0);
  10687. else
  10688. mask[i] = NULL;
  10689. if (mask[i] == NULL)
  10690. return NULL;
  10691. add_loc_descr (&mask[i], new_loc_descr (DW_OP_and, 0, 0));
  10692. }
  10693. ret = op0;
  10694. add_loc_descr (&ret, op1);
  10695. add_loc_descr (&ret, new_loc_descr (DW_OP_over, 0, 0));
  10696. add_loc_descr (&ret, new_loc_descr (DW_OP_over, 0, 0));
  10697. if (GET_CODE (rtl) == ROTATERT)
  10698. {
  10699. add_loc_descr (&ret, new_loc_descr (DW_OP_neg, 0, 0));
  10700. add_loc_descr (&ret, new_loc_descr (DW_OP_plus_uconst,
  10701. GET_MODE_BITSIZE (mode), 0));
  10702. }
  10703. add_loc_descr (&ret, new_loc_descr (DW_OP_shl, 0, 0));
  10704. if (mask[0] != NULL)
  10705. add_loc_descr (&ret, mask[0]);
  10706. add_loc_descr (&ret, new_loc_descr (DW_OP_rot, 0, 0));
  10707. if (mask[1] != NULL)
  10708. {
  10709. add_loc_descr (&ret, new_loc_descr (DW_OP_swap, 0, 0));
  10710. add_loc_descr (&ret, mask[1]);
  10711. add_loc_descr (&ret, new_loc_descr (DW_OP_swap, 0, 0));
  10712. }
  10713. if (GET_CODE (rtl) == ROTATE)
  10714. {
  10715. add_loc_descr (&ret, new_loc_descr (DW_OP_neg, 0, 0));
  10716. add_loc_descr (&ret, new_loc_descr (DW_OP_plus_uconst,
  10717. GET_MODE_BITSIZE (mode), 0));
  10718. }
  10719. add_loc_descr (&ret, new_loc_descr (DW_OP_shr, 0, 0));
  10720. add_loc_descr (&ret, new_loc_descr (DW_OP_or, 0, 0));
  10721. return ret;
  10722. }
  10723. /* Helper function for mem_loc_descriptor. Return DW_OP_GNU_parameter_ref
  10724. for DEBUG_PARAMETER_REF RTL. */
  10725. static dw_loc_descr_ref
  10726. parameter_ref_descriptor (rtx rtl)
  10727. {
  10728. dw_loc_descr_ref ret;
  10729. dw_die_ref ref;
  10730. if (dwarf_strict)
  10731. return NULL;
  10732. gcc_assert (TREE_CODE (DEBUG_PARAMETER_REF_DECL (rtl)) == PARM_DECL);
  10733. ref = lookup_decl_die (DEBUG_PARAMETER_REF_DECL (rtl));
  10734. ret = new_loc_descr (DW_OP_GNU_parameter_ref, 0, 0);
  10735. if (ref)
  10736. {
  10737. ret->dw_loc_oprnd1.val_class = dw_val_class_die_ref;
  10738. ret->dw_loc_oprnd1.v.val_die_ref.die = ref;
  10739. ret->dw_loc_oprnd1.v.val_die_ref.external = 0;
  10740. }
  10741. else
  10742. {
  10743. ret->dw_loc_oprnd1.val_class = dw_val_class_decl_ref;
  10744. ret->dw_loc_oprnd1.v.val_decl_ref = DEBUG_PARAMETER_REF_DECL (rtl);
  10745. }
  10746. return ret;
  10747. }
  10748. /* The following routine converts the RTL for a variable or parameter
  10749. (resident in memory) into an equivalent Dwarf representation of a
  10750. mechanism for getting the address of that same variable onto the top of a
  10751. hypothetical "address evaluation" stack.
  10752. When creating memory location descriptors, we are effectively transforming
  10753. the RTL for a memory-resident object into its Dwarf postfix expression
  10754. equivalent. This routine recursively descends an RTL tree, turning
  10755. it into Dwarf postfix code as it goes.
  10756. MODE is the mode that should be assumed for the rtl if it is VOIDmode.
  10757. MEM_MODE is the mode of the memory reference, needed to handle some
  10758. autoincrement addressing modes.
  10759. Return 0 if we can't represent the location. */
  10760. dw_loc_descr_ref
  10761. mem_loc_descriptor (rtx rtl, machine_mode mode,
  10762. machine_mode mem_mode,
  10763. enum var_init_status initialized)
  10764. {
  10765. dw_loc_descr_ref mem_loc_result = NULL;
  10766. enum dwarf_location_atom op;
  10767. dw_loc_descr_ref op0, op1;
  10768. rtx inner = NULL_RTX;
  10769. if (mode == VOIDmode)
  10770. mode = GET_MODE (rtl);
  10771. /* Note that for a dynamically sized array, the location we will generate a
  10772. description of here will be the lowest numbered location which is
  10773. actually within the array. That's *not* necessarily the same as the
  10774. zeroth element of the array. */
  10775. rtl = targetm.delegitimize_address (rtl);
  10776. if (mode != GET_MODE (rtl) && GET_MODE (rtl) != VOIDmode)
  10777. return NULL;
  10778. switch (GET_CODE (rtl))
  10779. {
  10780. case POST_INC:
  10781. case POST_DEC:
  10782. case POST_MODIFY:
  10783. return mem_loc_descriptor (XEXP (rtl, 0), mode, mem_mode, initialized);
  10784. case SUBREG:
  10785. /* The case of a subreg may arise when we have a local (register)
  10786. variable or a formal (register) parameter which doesn't quite fill
  10787. up an entire register. For now, just assume that it is
  10788. legitimate to make the Dwarf info refer to the whole register which
  10789. contains the given subreg. */
  10790. if (!subreg_lowpart_p (rtl))
  10791. break;
  10792. inner = SUBREG_REG (rtl);
  10793. case TRUNCATE:
  10794. if (inner == NULL_RTX)
  10795. inner = XEXP (rtl, 0);
  10796. if (GET_MODE_CLASS (mode) == MODE_INT
  10797. && GET_MODE_CLASS (GET_MODE (inner)) == MODE_INT
  10798. && (GET_MODE_SIZE (mode) <= DWARF2_ADDR_SIZE
  10799. #ifdef POINTERS_EXTEND_UNSIGNED
  10800. || (mode == Pmode && mem_mode != VOIDmode)
  10801. #endif
  10802. )
  10803. && GET_MODE_SIZE (GET_MODE (inner)) <= DWARF2_ADDR_SIZE)
  10804. {
  10805. mem_loc_result = mem_loc_descriptor (inner,
  10806. GET_MODE (inner),
  10807. mem_mode, initialized);
  10808. break;
  10809. }
  10810. if (dwarf_strict)
  10811. break;
  10812. if (GET_MODE_SIZE (mode) > GET_MODE_SIZE (GET_MODE (inner)))
  10813. break;
  10814. if (GET_MODE_SIZE (mode) != GET_MODE_SIZE (GET_MODE (inner))
  10815. && (GET_MODE_CLASS (mode) != MODE_INT
  10816. || GET_MODE_CLASS (GET_MODE (inner)) != MODE_INT))
  10817. break;
  10818. else
  10819. {
  10820. dw_die_ref type_die;
  10821. dw_loc_descr_ref cvt;
  10822. mem_loc_result = mem_loc_descriptor (inner,
  10823. GET_MODE (inner),
  10824. mem_mode, initialized);
  10825. if (mem_loc_result == NULL)
  10826. break;
  10827. type_die = base_type_for_mode (mode,
  10828. GET_MODE_CLASS (mode) == MODE_INT);
  10829. if (type_die == NULL)
  10830. {
  10831. mem_loc_result = NULL;
  10832. break;
  10833. }
  10834. if (GET_MODE_SIZE (mode)
  10835. != GET_MODE_SIZE (GET_MODE (inner)))
  10836. cvt = new_loc_descr (DW_OP_GNU_convert, 0, 0);
  10837. else
  10838. cvt = new_loc_descr (DW_OP_GNU_reinterpret, 0, 0);
  10839. cvt->dw_loc_oprnd1.val_class = dw_val_class_die_ref;
  10840. cvt->dw_loc_oprnd1.v.val_die_ref.die = type_die;
  10841. cvt->dw_loc_oprnd1.v.val_die_ref.external = 0;
  10842. add_loc_descr (&mem_loc_result, cvt);
  10843. }
  10844. break;
  10845. case REG:
  10846. if (GET_MODE_CLASS (mode) != MODE_INT
  10847. || (GET_MODE_SIZE (mode) > DWARF2_ADDR_SIZE
  10848. && rtl != arg_pointer_rtx
  10849. && rtl != frame_pointer_rtx
  10850. #ifdef POINTERS_EXTEND_UNSIGNED
  10851. && (mode != Pmode || mem_mode == VOIDmode)
  10852. #endif
  10853. ))
  10854. {
  10855. dw_die_ref type_die;
  10856. unsigned int dbx_regnum;
  10857. if (dwarf_strict)
  10858. break;
  10859. if (REGNO (rtl) > FIRST_PSEUDO_REGISTER)
  10860. break;
  10861. type_die = base_type_for_mode (mode,
  10862. GET_MODE_CLASS (mode) == MODE_INT);
  10863. if (type_die == NULL)
  10864. break;
  10865. dbx_regnum = dbx_reg_number (rtl);
  10866. if (dbx_regnum == IGNORED_DWARF_REGNUM)
  10867. break;
  10868. mem_loc_result = new_loc_descr (DW_OP_GNU_regval_type,
  10869. dbx_regnum, 0);
  10870. mem_loc_result->dw_loc_oprnd2.val_class = dw_val_class_die_ref;
  10871. mem_loc_result->dw_loc_oprnd2.v.val_die_ref.die = type_die;
  10872. mem_loc_result->dw_loc_oprnd2.v.val_die_ref.external = 0;
  10873. break;
  10874. }
  10875. /* Whenever a register number forms a part of the description of the
  10876. method for calculating the (dynamic) address of a memory resident
  10877. object, DWARF rules require the register number be referred to as
  10878. a "base register". This distinction is not based in any way upon
  10879. what category of register the hardware believes the given register
  10880. belongs to. This is strictly DWARF terminology we're dealing with
  10881. here. Note that in cases where the location of a memory-resident
  10882. data object could be expressed as: OP_ADD (OP_BASEREG (basereg),
  10883. OP_CONST (0)) the actual DWARF location descriptor that we generate
  10884. may just be OP_BASEREG (basereg). This may look deceptively like
  10885. the object in question was allocated to a register (rather than in
  10886. memory) so DWARF consumers need to be aware of the subtle
  10887. distinction between OP_REG and OP_BASEREG. */
  10888. if (REGNO (rtl) < FIRST_PSEUDO_REGISTER)
  10889. mem_loc_result = based_loc_descr (rtl, 0, VAR_INIT_STATUS_INITIALIZED);
  10890. else if (stack_realign_drap
  10891. && crtl->drap_reg
  10892. && crtl->args.internal_arg_pointer == rtl
  10893. && REGNO (crtl->drap_reg) < FIRST_PSEUDO_REGISTER)
  10894. {
  10895. /* If RTL is internal_arg_pointer, which has been optimized
  10896. out, use DRAP instead. */
  10897. mem_loc_result = based_loc_descr (crtl->drap_reg, 0,
  10898. VAR_INIT_STATUS_INITIALIZED);
  10899. }
  10900. break;
  10901. case SIGN_EXTEND:
  10902. case ZERO_EXTEND:
  10903. if (GET_MODE_CLASS (mode) != MODE_INT)
  10904. break;
  10905. op0 = mem_loc_descriptor (XEXP (rtl, 0), GET_MODE (XEXP (rtl, 0)),
  10906. mem_mode, VAR_INIT_STATUS_INITIALIZED);
  10907. if (op0 == 0)
  10908. break;
  10909. else if (GET_CODE (rtl) == ZERO_EXTEND
  10910. && GET_MODE_SIZE (mode) <= DWARF2_ADDR_SIZE
  10911. && GET_MODE_BITSIZE (GET_MODE (XEXP (rtl, 0)))
  10912. < HOST_BITS_PER_WIDE_INT
  10913. /* If DW_OP_const{1,2,4}u won't be used, it is shorter
  10914. to expand zero extend as two shifts instead of
  10915. masking. */
  10916. && GET_MODE_SIZE (GET_MODE (XEXP (rtl, 0))) <= 4)
  10917. {
  10918. machine_mode imode = GET_MODE (XEXP (rtl, 0));
  10919. mem_loc_result = op0;
  10920. add_loc_descr (&mem_loc_result,
  10921. int_loc_descriptor (GET_MODE_MASK (imode)));
  10922. add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_and, 0, 0));
  10923. }
  10924. else if (GET_MODE_SIZE (mode) <= DWARF2_ADDR_SIZE)
  10925. {
  10926. int shift = DWARF2_ADDR_SIZE
  10927. - GET_MODE_SIZE (GET_MODE (XEXP (rtl, 0)));
  10928. shift *= BITS_PER_UNIT;
  10929. if (GET_CODE (rtl) == SIGN_EXTEND)
  10930. op = DW_OP_shra;
  10931. else
  10932. op = DW_OP_shr;
  10933. mem_loc_result = op0;
  10934. add_loc_descr (&mem_loc_result, int_loc_descriptor (shift));
  10935. add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_shl, 0, 0));
  10936. add_loc_descr (&mem_loc_result, int_loc_descriptor (shift));
  10937. add_loc_descr (&mem_loc_result, new_loc_descr (op, 0, 0));
  10938. }
  10939. else if (!dwarf_strict)
  10940. {
  10941. dw_die_ref type_die1, type_die2;
  10942. dw_loc_descr_ref cvt;
  10943. type_die1 = base_type_for_mode (GET_MODE (XEXP (rtl, 0)),
  10944. GET_CODE (rtl) == ZERO_EXTEND);
  10945. if (type_die1 == NULL)
  10946. break;
  10947. type_die2 = base_type_for_mode (mode, 1);
  10948. if (type_die2 == NULL)
  10949. break;
  10950. mem_loc_result = op0;
  10951. cvt = new_loc_descr (DW_OP_GNU_convert, 0, 0);
  10952. cvt->dw_loc_oprnd1.val_class = dw_val_class_die_ref;
  10953. cvt->dw_loc_oprnd1.v.val_die_ref.die = type_die1;
  10954. cvt->dw_loc_oprnd1.v.val_die_ref.external = 0;
  10955. add_loc_descr (&mem_loc_result, cvt);
  10956. cvt = new_loc_descr (DW_OP_GNU_convert, 0, 0);
  10957. cvt->dw_loc_oprnd1.val_class = dw_val_class_die_ref;
  10958. cvt->dw_loc_oprnd1.v.val_die_ref.die = type_die2;
  10959. cvt->dw_loc_oprnd1.v.val_die_ref.external = 0;
  10960. add_loc_descr (&mem_loc_result, cvt);
  10961. }
  10962. break;
  10963. case MEM:
  10964. {
  10965. rtx new_rtl = avoid_constant_pool_reference (rtl);
  10966. if (new_rtl != rtl)
  10967. {
  10968. mem_loc_result = mem_loc_descriptor (new_rtl, mode, mem_mode,
  10969. initialized);
  10970. if (mem_loc_result != NULL)
  10971. return mem_loc_result;
  10972. }
  10973. }
  10974. mem_loc_result = mem_loc_descriptor (XEXP (rtl, 0),
  10975. get_address_mode (rtl), mode,
  10976. VAR_INIT_STATUS_INITIALIZED);
  10977. if (mem_loc_result == NULL)
  10978. mem_loc_result = tls_mem_loc_descriptor (rtl);
  10979. if (mem_loc_result != NULL)
  10980. {
  10981. if (GET_MODE_SIZE (mode) > DWARF2_ADDR_SIZE
  10982. || GET_MODE_CLASS (mode) != MODE_INT)
  10983. {
  10984. dw_die_ref type_die;
  10985. dw_loc_descr_ref deref;
  10986. if (dwarf_strict)
  10987. return NULL;
  10988. type_die
  10989. = base_type_for_mode (mode, GET_MODE_CLASS (mode) == MODE_INT);
  10990. if (type_die == NULL)
  10991. return NULL;
  10992. deref = new_loc_descr (DW_OP_GNU_deref_type,
  10993. GET_MODE_SIZE (mode), 0);
  10994. deref->dw_loc_oprnd2.val_class = dw_val_class_die_ref;
  10995. deref->dw_loc_oprnd2.v.val_die_ref.die = type_die;
  10996. deref->dw_loc_oprnd2.v.val_die_ref.external = 0;
  10997. add_loc_descr (&mem_loc_result, deref);
  10998. }
  10999. else if (GET_MODE_SIZE (mode) == DWARF2_ADDR_SIZE)
  11000. add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_deref, 0, 0));
  11001. else
  11002. add_loc_descr (&mem_loc_result,
  11003. new_loc_descr (DW_OP_deref_size,
  11004. GET_MODE_SIZE (mode), 0));
  11005. }
  11006. break;
  11007. case LO_SUM:
  11008. return mem_loc_descriptor (XEXP (rtl, 1), mode, mem_mode, initialized);
  11009. case LABEL_REF:
  11010. /* Some ports can transform a symbol ref into a label ref, because
  11011. the symbol ref is too far away and has to be dumped into a constant
  11012. pool. */
  11013. case CONST:
  11014. case SYMBOL_REF:
  11015. if ((GET_MODE_CLASS (mode) != MODE_INT
  11016. && GET_MODE_CLASS (mode) != MODE_PARTIAL_INT)
  11017. || (GET_MODE_SIZE (mode) > DWARF2_ADDR_SIZE
  11018. #ifdef POINTERS_EXTEND_UNSIGNED
  11019. && (mode != Pmode || mem_mode == VOIDmode)
  11020. #endif
  11021. ))
  11022. break;
  11023. if (GET_CODE (rtl) == SYMBOL_REF
  11024. && SYMBOL_REF_TLS_MODEL (rtl) != TLS_MODEL_NONE)
  11025. {
  11026. dw_loc_descr_ref temp;
  11027. /* If this is not defined, we have no way to emit the data. */
  11028. if (!targetm.have_tls || !targetm.asm_out.output_dwarf_dtprel)
  11029. break;
  11030. temp = new_addr_loc_descr (rtl, dtprel_true);
  11031. mem_loc_result = new_loc_descr (DW_OP_GNU_push_tls_address, 0, 0);
  11032. add_loc_descr (&mem_loc_result, temp);
  11033. break;
  11034. }
  11035. if (!const_ok_for_output (rtl))
  11036. break;
  11037. symref:
  11038. mem_loc_result = new_addr_loc_descr (rtl, dtprel_false);
  11039. vec_safe_push (used_rtx_array, rtl);
  11040. break;
  11041. case CONCAT:
  11042. case CONCATN:
  11043. case VAR_LOCATION:
  11044. case DEBUG_IMPLICIT_PTR:
  11045. expansion_failed (NULL_TREE, rtl,
  11046. "CONCAT/CONCATN/VAR_LOCATION is handled only by loc_descriptor");
  11047. return 0;
  11048. case ENTRY_VALUE:
  11049. if (dwarf_strict)
  11050. return NULL;
  11051. if (REG_P (ENTRY_VALUE_EXP (rtl)))
  11052. {
  11053. if (GET_MODE_CLASS (mode) != MODE_INT
  11054. || GET_MODE_SIZE (mode) > DWARF2_ADDR_SIZE)
  11055. op0 = mem_loc_descriptor (ENTRY_VALUE_EXP (rtl), mode,
  11056. VOIDmode, VAR_INIT_STATUS_INITIALIZED);
  11057. else
  11058. {
  11059. unsigned int dbx_regnum = dbx_reg_number (ENTRY_VALUE_EXP (rtl));
  11060. if (dbx_regnum == IGNORED_DWARF_REGNUM)
  11061. return NULL;
  11062. op0 = one_reg_loc_descriptor (dbx_regnum,
  11063. VAR_INIT_STATUS_INITIALIZED);
  11064. }
  11065. }
  11066. else if (MEM_P (ENTRY_VALUE_EXP (rtl))
  11067. && REG_P (XEXP (ENTRY_VALUE_EXP (rtl), 0)))
  11068. {
  11069. op0 = mem_loc_descriptor (ENTRY_VALUE_EXP (rtl), mode,
  11070. VOIDmode, VAR_INIT_STATUS_INITIALIZED);
  11071. if (op0 && op0->dw_loc_opc == DW_OP_fbreg)
  11072. return NULL;
  11073. }
  11074. else
  11075. gcc_unreachable ();
  11076. if (op0 == NULL)
  11077. return NULL;
  11078. mem_loc_result = new_loc_descr (DW_OP_GNU_entry_value, 0, 0);
  11079. mem_loc_result->dw_loc_oprnd1.val_class = dw_val_class_loc;
  11080. mem_loc_result->dw_loc_oprnd1.v.val_loc = op0;
  11081. break;
  11082. case DEBUG_PARAMETER_REF:
  11083. mem_loc_result = parameter_ref_descriptor (rtl);
  11084. break;
  11085. case PRE_MODIFY:
  11086. /* Extract the PLUS expression nested inside and fall into
  11087. PLUS code below. */
  11088. rtl = XEXP (rtl, 1);
  11089. goto plus;
  11090. case PRE_INC:
  11091. case PRE_DEC:
  11092. /* Turn these into a PLUS expression and fall into the PLUS code
  11093. below. */
  11094. rtl = gen_rtx_PLUS (mode, XEXP (rtl, 0),
  11095. gen_int_mode (GET_CODE (rtl) == PRE_INC
  11096. ? GET_MODE_UNIT_SIZE (mem_mode)
  11097. : -GET_MODE_UNIT_SIZE (mem_mode),
  11098. mode));
  11099. /* ... fall through ... */
  11100. case PLUS:
  11101. plus:
  11102. if (is_based_loc (rtl)
  11103. && (GET_MODE_SIZE (mode) <= DWARF2_ADDR_SIZE
  11104. || XEXP (rtl, 0) == arg_pointer_rtx
  11105. || XEXP (rtl, 0) == frame_pointer_rtx)
  11106. && GET_MODE_CLASS (mode) == MODE_INT)
  11107. mem_loc_result = based_loc_descr (XEXP (rtl, 0),
  11108. INTVAL (XEXP (rtl, 1)),
  11109. VAR_INIT_STATUS_INITIALIZED);
  11110. else
  11111. {
  11112. mem_loc_result = mem_loc_descriptor (XEXP (rtl, 0), mode, mem_mode,
  11113. VAR_INIT_STATUS_INITIALIZED);
  11114. if (mem_loc_result == 0)
  11115. break;
  11116. if (CONST_INT_P (XEXP (rtl, 1))
  11117. && GET_MODE_SIZE (mode) <= DWARF2_ADDR_SIZE)
  11118. loc_descr_plus_const (&mem_loc_result, INTVAL (XEXP (rtl, 1)));
  11119. else
  11120. {
  11121. op1 = mem_loc_descriptor (XEXP (rtl, 1), mode, mem_mode,
  11122. VAR_INIT_STATUS_INITIALIZED);
  11123. if (op1 == 0)
  11124. return NULL;
  11125. add_loc_descr (&mem_loc_result, op1);
  11126. add_loc_descr (&mem_loc_result,
  11127. new_loc_descr (DW_OP_plus, 0, 0));
  11128. }
  11129. }
  11130. break;
  11131. /* If a pseudo-reg is optimized away, it is possible for it to
  11132. be replaced with a MEM containing a multiply or shift. */
  11133. case MINUS:
  11134. op = DW_OP_minus;
  11135. goto do_binop;
  11136. case MULT:
  11137. op = DW_OP_mul;
  11138. goto do_binop;
  11139. case DIV:
  11140. if (!dwarf_strict
  11141. && GET_MODE_CLASS (mode) == MODE_INT
  11142. && GET_MODE_SIZE (mode) > DWARF2_ADDR_SIZE)
  11143. {
  11144. mem_loc_result = typed_binop (DW_OP_div, rtl,
  11145. base_type_for_mode (mode, 0),
  11146. mode, mem_mode);
  11147. break;
  11148. }
  11149. op = DW_OP_div;
  11150. goto do_binop;
  11151. case UMOD:
  11152. op = DW_OP_mod;
  11153. goto do_binop;
  11154. case ASHIFT:
  11155. op = DW_OP_shl;
  11156. goto do_shift;
  11157. case ASHIFTRT:
  11158. op = DW_OP_shra;
  11159. goto do_shift;
  11160. case LSHIFTRT:
  11161. op = DW_OP_shr;
  11162. goto do_shift;
  11163. do_shift:
  11164. if (GET_MODE_CLASS (mode) != MODE_INT)
  11165. break;
  11166. op0 = mem_loc_descriptor (XEXP (rtl, 0), mode, mem_mode,
  11167. VAR_INIT_STATUS_INITIALIZED);
  11168. {
  11169. rtx rtlop1 = XEXP (rtl, 1);
  11170. if (GET_MODE (rtlop1) != VOIDmode
  11171. && GET_MODE_BITSIZE (GET_MODE (rtlop1))
  11172. < GET_MODE_BITSIZE (mode))
  11173. rtlop1 = gen_rtx_ZERO_EXTEND (mode, rtlop1);
  11174. op1 = mem_loc_descriptor (rtlop1, mode, mem_mode,
  11175. VAR_INIT_STATUS_INITIALIZED);
  11176. }
  11177. if (op0 == 0 || op1 == 0)
  11178. break;
  11179. mem_loc_result = op0;
  11180. add_loc_descr (&mem_loc_result, op1);
  11181. add_loc_descr (&mem_loc_result, new_loc_descr (op, 0, 0));
  11182. break;
  11183. case AND:
  11184. op = DW_OP_and;
  11185. goto do_binop;
  11186. case IOR:
  11187. op = DW_OP_or;
  11188. goto do_binop;
  11189. case XOR:
  11190. op = DW_OP_xor;
  11191. goto do_binop;
  11192. do_binop:
  11193. op0 = mem_loc_descriptor (XEXP (rtl, 0), mode, mem_mode,
  11194. VAR_INIT_STATUS_INITIALIZED);
  11195. op1 = mem_loc_descriptor (XEXP (rtl, 1), mode, mem_mode,
  11196. VAR_INIT_STATUS_INITIALIZED);
  11197. if (op0 == 0 || op1 == 0)
  11198. break;
  11199. mem_loc_result = op0;
  11200. add_loc_descr (&mem_loc_result, op1);
  11201. add_loc_descr (&mem_loc_result, new_loc_descr (op, 0, 0));
  11202. break;
  11203. case MOD:
  11204. if (GET_MODE_SIZE (mode) > DWARF2_ADDR_SIZE && !dwarf_strict)
  11205. {
  11206. mem_loc_result = typed_binop (DW_OP_mod, rtl,
  11207. base_type_for_mode (mode, 0),
  11208. mode, mem_mode);
  11209. break;
  11210. }
  11211. op0 = mem_loc_descriptor (XEXP (rtl, 0), mode, mem_mode,
  11212. VAR_INIT_STATUS_INITIALIZED);
  11213. op1 = mem_loc_descriptor (XEXP (rtl, 1), mode, mem_mode,
  11214. VAR_INIT_STATUS_INITIALIZED);
  11215. if (op0 == 0 || op1 == 0)
  11216. break;
  11217. mem_loc_result = op0;
  11218. add_loc_descr (&mem_loc_result, op1);
  11219. add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_over, 0, 0));
  11220. add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_over, 0, 0));
  11221. add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_div, 0, 0));
  11222. add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_mul, 0, 0));
  11223. add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_minus, 0, 0));
  11224. break;
  11225. case UDIV:
  11226. if (!dwarf_strict && GET_MODE_CLASS (mode) == MODE_INT)
  11227. {
  11228. if (GET_MODE_CLASS (mode) > DWARF2_ADDR_SIZE)
  11229. {
  11230. op = DW_OP_div;
  11231. goto do_binop;
  11232. }
  11233. mem_loc_result = typed_binop (DW_OP_div, rtl,
  11234. base_type_for_mode (mode, 1),
  11235. mode, mem_mode);
  11236. }
  11237. break;
  11238. case NOT:
  11239. op = DW_OP_not;
  11240. goto do_unop;
  11241. case ABS:
  11242. op = DW_OP_abs;
  11243. goto do_unop;
  11244. case NEG:
  11245. op = DW_OP_neg;
  11246. goto do_unop;
  11247. do_unop:
  11248. op0 = mem_loc_descriptor (XEXP (rtl, 0), mode, mem_mode,
  11249. VAR_INIT_STATUS_INITIALIZED);
  11250. if (op0 == 0)
  11251. break;
  11252. mem_loc_result = op0;
  11253. add_loc_descr (&mem_loc_result, new_loc_descr (op, 0, 0));
  11254. break;
  11255. case CONST_INT:
  11256. if (GET_MODE_SIZE (mode) <= DWARF2_ADDR_SIZE
  11257. #ifdef POINTERS_EXTEND_UNSIGNED
  11258. || (mode == Pmode
  11259. && mem_mode != VOIDmode
  11260. && trunc_int_for_mode (INTVAL (rtl), ptr_mode) == INTVAL (rtl))
  11261. #endif
  11262. )
  11263. {
  11264. mem_loc_result = int_loc_descriptor (INTVAL (rtl));
  11265. break;
  11266. }
  11267. if (!dwarf_strict
  11268. && (GET_MODE_BITSIZE (mode) == HOST_BITS_PER_WIDE_INT
  11269. || GET_MODE_BITSIZE (mode) == HOST_BITS_PER_DOUBLE_INT))
  11270. {
  11271. dw_die_ref type_die = base_type_for_mode (mode, 1);
  11272. machine_mode amode;
  11273. if (type_die == NULL)
  11274. return NULL;
  11275. amode = mode_for_size (DWARF2_ADDR_SIZE * BITS_PER_UNIT,
  11276. MODE_INT, 0);
  11277. if (INTVAL (rtl) >= 0
  11278. && amode != BLKmode
  11279. && trunc_int_for_mode (INTVAL (rtl), amode) == INTVAL (rtl)
  11280. /* const DW_OP_GNU_convert <XXX> vs.
  11281. DW_OP_GNU_const_type <XXX, 1, const>. */
  11282. && size_of_int_loc_descriptor (INTVAL (rtl)) + 1 + 1
  11283. < (unsigned long) 1 + 1 + 1 + GET_MODE_SIZE (mode))
  11284. {
  11285. mem_loc_result = int_loc_descriptor (INTVAL (rtl));
  11286. op0 = new_loc_descr (DW_OP_GNU_convert, 0, 0);
  11287. op0->dw_loc_oprnd1.val_class = dw_val_class_die_ref;
  11288. op0->dw_loc_oprnd1.v.val_die_ref.die = type_die;
  11289. op0->dw_loc_oprnd1.v.val_die_ref.external = 0;
  11290. add_loc_descr (&mem_loc_result, op0);
  11291. return mem_loc_result;
  11292. }
  11293. mem_loc_result = new_loc_descr (DW_OP_GNU_const_type, 0,
  11294. INTVAL (rtl));
  11295. mem_loc_result->dw_loc_oprnd1.val_class = dw_val_class_die_ref;
  11296. mem_loc_result->dw_loc_oprnd1.v.val_die_ref.die = type_die;
  11297. mem_loc_result->dw_loc_oprnd1.v.val_die_ref.external = 0;
  11298. if (GET_MODE_BITSIZE (mode) == HOST_BITS_PER_WIDE_INT)
  11299. mem_loc_result->dw_loc_oprnd2.val_class = dw_val_class_const;
  11300. else
  11301. {
  11302. mem_loc_result->dw_loc_oprnd2.val_class
  11303. = dw_val_class_const_double;
  11304. mem_loc_result->dw_loc_oprnd2.v.val_double
  11305. = double_int::from_shwi (INTVAL (rtl));
  11306. }
  11307. }
  11308. break;
  11309. case CONST_DOUBLE:
  11310. if (!dwarf_strict)
  11311. {
  11312. dw_die_ref type_die;
  11313. /* Note that if TARGET_SUPPORTS_WIDE_INT == 0, a
  11314. CONST_DOUBLE rtx could represent either a large integer
  11315. or a floating-point constant. If TARGET_SUPPORTS_WIDE_INT != 0,
  11316. the value is always a floating point constant.
  11317. When it is an integer, a CONST_DOUBLE is used whenever
  11318. the constant requires 2 HWIs to be adequately represented.
  11319. We output CONST_DOUBLEs as blocks. */
  11320. if (mode == VOIDmode
  11321. || (GET_MODE (rtl) == VOIDmode
  11322. && GET_MODE_BITSIZE (mode) != HOST_BITS_PER_DOUBLE_INT))
  11323. break;
  11324. type_die = base_type_for_mode (mode,
  11325. GET_MODE_CLASS (mode) == MODE_INT);
  11326. if (type_die == NULL)
  11327. return NULL;
  11328. mem_loc_result = new_loc_descr (DW_OP_GNU_const_type, 0, 0);
  11329. mem_loc_result->dw_loc_oprnd1.val_class = dw_val_class_die_ref;
  11330. mem_loc_result->dw_loc_oprnd1.v.val_die_ref.die = type_die;
  11331. mem_loc_result->dw_loc_oprnd1.v.val_die_ref.external = 0;
  11332. #if TARGET_SUPPORTS_WIDE_INT == 0
  11333. if (!SCALAR_FLOAT_MODE_P (mode))
  11334. {
  11335. mem_loc_result->dw_loc_oprnd2.val_class
  11336. = dw_val_class_const_double;
  11337. mem_loc_result->dw_loc_oprnd2.v.val_double
  11338. = rtx_to_double_int (rtl);
  11339. }
  11340. else
  11341. #endif
  11342. {
  11343. unsigned int length = GET_MODE_SIZE (mode);
  11344. unsigned char *array = ggc_vec_alloc<unsigned char> (length);
  11345. insert_float (rtl, array);
  11346. mem_loc_result->dw_loc_oprnd2.val_class = dw_val_class_vec;
  11347. mem_loc_result->dw_loc_oprnd2.v.val_vec.length = length / 4;
  11348. mem_loc_result->dw_loc_oprnd2.v.val_vec.elt_size = 4;
  11349. mem_loc_result->dw_loc_oprnd2.v.val_vec.array = array;
  11350. }
  11351. }
  11352. break;
  11353. case CONST_WIDE_INT:
  11354. if (!dwarf_strict)
  11355. {
  11356. dw_die_ref type_die;
  11357. type_die = base_type_for_mode (mode,
  11358. GET_MODE_CLASS (mode) == MODE_INT);
  11359. if (type_die == NULL)
  11360. return NULL;
  11361. mem_loc_result = new_loc_descr (DW_OP_GNU_const_type, 0, 0);
  11362. mem_loc_result->dw_loc_oprnd1.val_class = dw_val_class_die_ref;
  11363. mem_loc_result->dw_loc_oprnd1.v.val_die_ref.die = type_die;
  11364. mem_loc_result->dw_loc_oprnd1.v.val_die_ref.external = 0;
  11365. mem_loc_result->dw_loc_oprnd2.val_class
  11366. = dw_val_class_wide_int;
  11367. mem_loc_result->dw_loc_oprnd2.v.val_wide = ggc_alloc<wide_int> ();
  11368. *mem_loc_result->dw_loc_oprnd2.v.val_wide = std::make_pair (rtl, mode);
  11369. }
  11370. break;
  11371. case EQ:
  11372. mem_loc_result = scompare_loc_descriptor (DW_OP_eq, rtl, mem_mode);
  11373. break;
  11374. case GE:
  11375. mem_loc_result = scompare_loc_descriptor (DW_OP_ge, rtl, mem_mode);
  11376. break;
  11377. case GT:
  11378. mem_loc_result = scompare_loc_descriptor (DW_OP_gt, rtl, mem_mode);
  11379. break;
  11380. case LE:
  11381. mem_loc_result = scompare_loc_descriptor (DW_OP_le, rtl, mem_mode);
  11382. break;
  11383. case LT:
  11384. mem_loc_result = scompare_loc_descriptor (DW_OP_lt, rtl, mem_mode);
  11385. break;
  11386. case NE:
  11387. mem_loc_result = scompare_loc_descriptor (DW_OP_ne, rtl, mem_mode);
  11388. break;
  11389. case GEU:
  11390. mem_loc_result = ucompare_loc_descriptor (DW_OP_ge, rtl, mem_mode);
  11391. break;
  11392. case GTU:
  11393. mem_loc_result = ucompare_loc_descriptor (DW_OP_gt, rtl, mem_mode);
  11394. break;
  11395. case LEU:
  11396. mem_loc_result = ucompare_loc_descriptor (DW_OP_le, rtl, mem_mode);
  11397. break;
  11398. case LTU:
  11399. mem_loc_result = ucompare_loc_descriptor (DW_OP_lt, rtl, mem_mode);
  11400. break;
  11401. case UMIN:
  11402. case UMAX:
  11403. if (GET_MODE_CLASS (mode) != MODE_INT)
  11404. break;
  11405. /* FALLTHRU */
  11406. case SMIN:
  11407. case SMAX:
  11408. mem_loc_result = minmax_loc_descriptor (rtl, mode, mem_mode);
  11409. break;
  11410. case ZERO_EXTRACT:
  11411. case SIGN_EXTRACT:
  11412. if (CONST_INT_P (XEXP (rtl, 1))
  11413. && CONST_INT_P (XEXP (rtl, 2))
  11414. && ((unsigned) INTVAL (XEXP (rtl, 1))
  11415. + (unsigned) INTVAL (XEXP (rtl, 2))
  11416. <= GET_MODE_BITSIZE (mode))
  11417. && GET_MODE_CLASS (mode) == MODE_INT
  11418. && GET_MODE_SIZE (mode) <= DWARF2_ADDR_SIZE
  11419. && GET_MODE_SIZE (GET_MODE (XEXP (rtl, 0))) <= DWARF2_ADDR_SIZE)
  11420. {
  11421. int shift, size;
  11422. op0 = mem_loc_descriptor (XEXP (rtl, 0), GET_MODE (XEXP (rtl, 0)),
  11423. mem_mode, VAR_INIT_STATUS_INITIALIZED);
  11424. if (op0 == 0)
  11425. break;
  11426. if (GET_CODE (rtl) == SIGN_EXTRACT)
  11427. op = DW_OP_shra;
  11428. else
  11429. op = DW_OP_shr;
  11430. mem_loc_result = op0;
  11431. size = INTVAL (XEXP (rtl, 1));
  11432. shift = INTVAL (XEXP (rtl, 2));
  11433. if (BITS_BIG_ENDIAN)
  11434. shift = GET_MODE_BITSIZE (GET_MODE (XEXP (rtl, 0)))
  11435. - shift - size;
  11436. if (shift + size != (int) DWARF2_ADDR_SIZE)
  11437. {
  11438. add_loc_descr (&mem_loc_result,
  11439. int_loc_descriptor (DWARF2_ADDR_SIZE
  11440. - shift - size));
  11441. add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_shl, 0, 0));
  11442. }
  11443. if (size != (int) DWARF2_ADDR_SIZE)
  11444. {
  11445. add_loc_descr (&mem_loc_result,
  11446. int_loc_descriptor (DWARF2_ADDR_SIZE - size));
  11447. add_loc_descr (&mem_loc_result, new_loc_descr (op, 0, 0));
  11448. }
  11449. }
  11450. break;
  11451. case IF_THEN_ELSE:
  11452. {
  11453. dw_loc_descr_ref op2, bra_node, drop_node;
  11454. op0 = mem_loc_descriptor (XEXP (rtl, 0),
  11455. GET_MODE (XEXP (rtl, 0)) == VOIDmode
  11456. ? word_mode : GET_MODE (XEXP (rtl, 0)),
  11457. mem_mode, VAR_INIT_STATUS_INITIALIZED);
  11458. op1 = mem_loc_descriptor (XEXP (rtl, 1), mode, mem_mode,
  11459. VAR_INIT_STATUS_INITIALIZED);
  11460. op2 = mem_loc_descriptor (XEXP (rtl, 2), mode, mem_mode,
  11461. VAR_INIT_STATUS_INITIALIZED);
  11462. if (op0 == NULL || op1 == NULL || op2 == NULL)
  11463. break;
  11464. mem_loc_result = op1;
  11465. add_loc_descr (&mem_loc_result, op2);
  11466. add_loc_descr (&mem_loc_result, op0);
  11467. bra_node = new_loc_descr (DW_OP_bra, 0, 0);
  11468. add_loc_descr (&mem_loc_result, bra_node);
  11469. add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_swap, 0, 0));
  11470. drop_node = new_loc_descr (DW_OP_drop, 0, 0);
  11471. add_loc_descr (&mem_loc_result, drop_node);
  11472. bra_node->dw_loc_oprnd1.val_class = dw_val_class_loc;
  11473. bra_node->dw_loc_oprnd1.v.val_loc = drop_node;
  11474. }
  11475. break;
  11476. case FLOAT_EXTEND:
  11477. case FLOAT_TRUNCATE:
  11478. case FLOAT:
  11479. case UNSIGNED_FLOAT:
  11480. case FIX:
  11481. case UNSIGNED_FIX:
  11482. if (!dwarf_strict)
  11483. {
  11484. dw_die_ref type_die;
  11485. dw_loc_descr_ref cvt;
  11486. op0 = mem_loc_descriptor (XEXP (rtl, 0), GET_MODE (XEXP (rtl, 0)),
  11487. mem_mode, VAR_INIT_STATUS_INITIALIZED);
  11488. if (op0 == NULL)
  11489. break;
  11490. if (GET_MODE_CLASS (GET_MODE (XEXP (rtl, 0))) == MODE_INT
  11491. && (GET_CODE (rtl) == FLOAT
  11492. || GET_MODE_SIZE (GET_MODE (XEXP (rtl, 0)))
  11493. <= DWARF2_ADDR_SIZE))
  11494. {
  11495. type_die = base_type_for_mode (GET_MODE (XEXP (rtl, 0)),
  11496. GET_CODE (rtl) == UNSIGNED_FLOAT);
  11497. if (type_die == NULL)
  11498. break;
  11499. cvt = new_loc_descr (DW_OP_GNU_convert, 0, 0);
  11500. cvt->dw_loc_oprnd1.val_class = dw_val_class_die_ref;
  11501. cvt->dw_loc_oprnd1.v.val_die_ref.die = type_die;
  11502. cvt->dw_loc_oprnd1.v.val_die_ref.external = 0;
  11503. add_loc_descr (&op0, cvt);
  11504. }
  11505. type_die = base_type_for_mode (mode, GET_CODE (rtl) == UNSIGNED_FIX);
  11506. if (type_die == NULL)
  11507. break;
  11508. cvt = new_loc_descr (DW_OP_GNU_convert, 0, 0);
  11509. cvt->dw_loc_oprnd1.val_class = dw_val_class_die_ref;
  11510. cvt->dw_loc_oprnd1.v.val_die_ref.die = type_die;
  11511. cvt->dw_loc_oprnd1.v.val_die_ref.external = 0;
  11512. add_loc_descr (&op0, cvt);
  11513. if (GET_MODE_CLASS (mode) == MODE_INT
  11514. && (GET_CODE (rtl) == FIX
  11515. || GET_MODE_SIZE (mode) < DWARF2_ADDR_SIZE))
  11516. {
  11517. op0 = convert_descriptor_to_mode (mode, op0);
  11518. if (op0 == NULL)
  11519. break;
  11520. }
  11521. mem_loc_result = op0;
  11522. }
  11523. break;
  11524. case CLZ:
  11525. case CTZ:
  11526. case FFS:
  11527. mem_loc_result = clz_loc_descriptor (rtl, mode, mem_mode);
  11528. break;
  11529. case POPCOUNT:
  11530. case PARITY:
  11531. mem_loc_result = popcount_loc_descriptor (rtl, mode, mem_mode);
  11532. break;
  11533. case BSWAP:
  11534. mem_loc_result = bswap_loc_descriptor (rtl, mode, mem_mode);
  11535. break;
  11536. case ROTATE:
  11537. case ROTATERT:
  11538. mem_loc_result = rotate_loc_descriptor (rtl, mode, mem_mode);
  11539. break;
  11540. case COMPARE:
  11541. /* In theory, we could implement the above. */
  11542. /* DWARF cannot represent the unsigned compare operations
  11543. natively. */
  11544. case SS_MULT:
  11545. case US_MULT:
  11546. case SS_DIV:
  11547. case US_DIV:
  11548. case SS_PLUS:
  11549. case US_PLUS:
  11550. case SS_MINUS:
  11551. case US_MINUS:
  11552. case SS_NEG:
  11553. case US_NEG:
  11554. case SS_ABS:
  11555. case SS_ASHIFT:
  11556. case US_ASHIFT:
  11557. case SS_TRUNCATE:
  11558. case US_TRUNCATE:
  11559. case UNORDERED:
  11560. case ORDERED:
  11561. case UNEQ:
  11562. case UNGE:
  11563. case UNGT:
  11564. case UNLE:
  11565. case UNLT:
  11566. case LTGT:
  11567. case FRACT_CONVERT:
  11568. case UNSIGNED_FRACT_CONVERT:
  11569. case SAT_FRACT:
  11570. case UNSIGNED_SAT_FRACT:
  11571. case SQRT:
  11572. case ASM_OPERANDS:
  11573. case VEC_MERGE:
  11574. case VEC_SELECT:
  11575. case VEC_CONCAT:
  11576. case VEC_DUPLICATE:
  11577. case UNSPEC:
  11578. case HIGH:
  11579. case FMA:
  11580. case STRICT_LOW_PART:
  11581. case CONST_VECTOR:
  11582. case CONST_FIXED:
  11583. case CLRSB:
  11584. case CLOBBER:
  11585. /* If delegitimize_address couldn't do anything with the UNSPEC, we
  11586. can't express it in the debug info. This can happen e.g. with some
  11587. TLS UNSPECs. */
  11588. break;
  11589. case CONST_STRING:
  11590. resolve_one_addr (&rtl);
  11591. goto symref;
  11592. default:
  11593. #ifdef ENABLE_CHECKING
  11594. print_rtl (stderr, rtl);
  11595. gcc_unreachable ();
  11596. #else
  11597. break;
  11598. #endif
  11599. }
  11600. if (mem_loc_result && initialized == VAR_INIT_STATUS_UNINITIALIZED)
  11601. add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_GNU_uninit, 0, 0));
  11602. return mem_loc_result;
  11603. }
  11604. /* Return a descriptor that describes the concatenation of two locations.
  11605. This is typically a complex variable. */
  11606. static dw_loc_descr_ref
  11607. concat_loc_descriptor (rtx x0, rtx x1, enum var_init_status initialized)
  11608. {
  11609. dw_loc_descr_ref cc_loc_result = NULL;
  11610. dw_loc_descr_ref x0_ref
  11611. = loc_descriptor (x0, VOIDmode, VAR_INIT_STATUS_INITIALIZED);
  11612. dw_loc_descr_ref x1_ref
  11613. = loc_descriptor (x1, VOIDmode, VAR_INIT_STATUS_INITIALIZED);
  11614. if (x0_ref == 0 || x1_ref == 0)
  11615. return 0;
  11616. cc_loc_result = x0_ref;
  11617. add_loc_descr_op_piece (&cc_loc_result, GET_MODE_SIZE (GET_MODE (x0)));
  11618. add_loc_descr (&cc_loc_result, x1_ref);
  11619. add_loc_descr_op_piece (&cc_loc_result, GET_MODE_SIZE (GET_MODE (x1)));
  11620. if (initialized == VAR_INIT_STATUS_UNINITIALIZED)
  11621. add_loc_descr (&cc_loc_result, new_loc_descr (DW_OP_GNU_uninit, 0, 0));
  11622. return cc_loc_result;
  11623. }
  11624. /* Return a descriptor that describes the concatenation of N
  11625. locations. */
  11626. static dw_loc_descr_ref
  11627. concatn_loc_descriptor (rtx concatn, enum var_init_status initialized)
  11628. {
  11629. unsigned int i;
  11630. dw_loc_descr_ref cc_loc_result = NULL;
  11631. unsigned int n = XVECLEN (concatn, 0);
  11632. for (i = 0; i < n; ++i)
  11633. {
  11634. dw_loc_descr_ref ref;
  11635. rtx x = XVECEXP (concatn, 0, i);
  11636. ref = loc_descriptor (x, VOIDmode, VAR_INIT_STATUS_INITIALIZED);
  11637. if (ref == NULL)
  11638. return NULL;
  11639. add_loc_descr (&cc_loc_result, ref);
  11640. add_loc_descr_op_piece (&cc_loc_result, GET_MODE_SIZE (GET_MODE (x)));
  11641. }
  11642. if (cc_loc_result && initialized == VAR_INIT_STATUS_UNINITIALIZED)
  11643. add_loc_descr (&cc_loc_result, new_loc_descr (DW_OP_GNU_uninit, 0, 0));
  11644. return cc_loc_result;
  11645. }
  11646. /* Helper function for loc_descriptor. Return DW_OP_GNU_implicit_pointer
  11647. for DEBUG_IMPLICIT_PTR RTL. */
  11648. static dw_loc_descr_ref
  11649. implicit_ptr_descriptor (rtx rtl, HOST_WIDE_INT offset)
  11650. {
  11651. dw_loc_descr_ref ret;
  11652. dw_die_ref ref;
  11653. if (dwarf_strict)
  11654. return NULL;
  11655. gcc_assert (TREE_CODE (DEBUG_IMPLICIT_PTR_DECL (rtl)) == VAR_DECL
  11656. || TREE_CODE (DEBUG_IMPLICIT_PTR_DECL (rtl)) == PARM_DECL
  11657. || TREE_CODE (DEBUG_IMPLICIT_PTR_DECL (rtl)) == RESULT_DECL);
  11658. ref = lookup_decl_die (DEBUG_IMPLICIT_PTR_DECL (rtl));
  11659. ret = new_loc_descr (DW_OP_GNU_implicit_pointer, 0, offset);
  11660. ret->dw_loc_oprnd2.val_class = dw_val_class_const;
  11661. if (ref)
  11662. {
  11663. ret->dw_loc_oprnd1.val_class = dw_val_class_die_ref;
  11664. ret->dw_loc_oprnd1.v.val_die_ref.die = ref;
  11665. ret->dw_loc_oprnd1.v.val_die_ref.external = 0;
  11666. }
  11667. else
  11668. {
  11669. ret->dw_loc_oprnd1.val_class = dw_val_class_decl_ref;
  11670. ret->dw_loc_oprnd1.v.val_decl_ref = DEBUG_IMPLICIT_PTR_DECL (rtl);
  11671. }
  11672. return ret;
  11673. }
  11674. /* Output a proper Dwarf location descriptor for a variable or parameter
  11675. which is either allocated in a register or in a memory location. For a
  11676. register, we just generate an OP_REG and the register number. For a
  11677. memory location we provide a Dwarf postfix expression describing how to
  11678. generate the (dynamic) address of the object onto the address stack.
  11679. MODE is mode of the decl if this loc_descriptor is going to be used in
  11680. .debug_loc section where DW_OP_stack_value and DW_OP_implicit_value are
  11681. allowed, VOIDmode otherwise.
  11682. If we don't know how to describe it, return 0. */
  11683. static dw_loc_descr_ref
  11684. loc_descriptor (rtx rtl, machine_mode mode,
  11685. enum var_init_status initialized)
  11686. {
  11687. dw_loc_descr_ref loc_result = NULL;
  11688. switch (GET_CODE (rtl))
  11689. {
  11690. case SUBREG:
  11691. /* The case of a subreg may arise when we have a local (register)
  11692. variable or a formal (register) parameter which doesn't quite fill
  11693. up an entire register. For now, just assume that it is
  11694. legitimate to make the Dwarf info refer to the whole register which
  11695. contains the given subreg. */
  11696. if (REG_P (SUBREG_REG (rtl)) && subreg_lowpart_p (rtl))
  11697. loc_result = loc_descriptor (SUBREG_REG (rtl),
  11698. GET_MODE (SUBREG_REG (rtl)), initialized);
  11699. else
  11700. goto do_default;
  11701. break;
  11702. case REG:
  11703. loc_result = reg_loc_descriptor (rtl, initialized);
  11704. break;
  11705. case MEM:
  11706. loc_result = mem_loc_descriptor (XEXP (rtl, 0), get_address_mode (rtl),
  11707. GET_MODE (rtl), initialized);
  11708. if (loc_result == NULL)
  11709. loc_result = tls_mem_loc_descriptor (rtl);
  11710. if (loc_result == NULL)
  11711. {
  11712. rtx new_rtl = avoid_constant_pool_reference (rtl);
  11713. if (new_rtl != rtl)
  11714. loc_result = loc_descriptor (new_rtl, mode, initialized);
  11715. }
  11716. break;
  11717. case CONCAT:
  11718. loc_result = concat_loc_descriptor (XEXP (rtl, 0), XEXP (rtl, 1),
  11719. initialized);
  11720. break;
  11721. case CONCATN:
  11722. loc_result = concatn_loc_descriptor (rtl, initialized);
  11723. break;
  11724. case VAR_LOCATION:
  11725. /* Single part. */
  11726. if (GET_CODE (PAT_VAR_LOCATION_LOC (rtl)) != PARALLEL)
  11727. {
  11728. rtx loc = PAT_VAR_LOCATION_LOC (rtl);
  11729. if (GET_CODE (loc) == EXPR_LIST)
  11730. loc = XEXP (loc, 0);
  11731. loc_result = loc_descriptor (loc, mode, initialized);
  11732. break;
  11733. }
  11734. rtl = XEXP (rtl, 1);
  11735. /* FALLTHRU */
  11736. case PARALLEL:
  11737. {
  11738. rtvec par_elems = XVEC (rtl, 0);
  11739. int num_elem = GET_NUM_ELEM (par_elems);
  11740. machine_mode mode;
  11741. int i;
  11742. /* Create the first one, so we have something to add to. */
  11743. loc_result = loc_descriptor (XEXP (RTVEC_ELT (par_elems, 0), 0),
  11744. VOIDmode, initialized);
  11745. if (loc_result == NULL)
  11746. return NULL;
  11747. mode = GET_MODE (XEXP (RTVEC_ELT (par_elems, 0), 0));
  11748. add_loc_descr_op_piece (&loc_result, GET_MODE_SIZE (mode));
  11749. for (i = 1; i < num_elem; i++)
  11750. {
  11751. dw_loc_descr_ref temp;
  11752. temp = loc_descriptor (XEXP (RTVEC_ELT (par_elems, i), 0),
  11753. VOIDmode, initialized);
  11754. if (temp == NULL)
  11755. return NULL;
  11756. add_loc_descr (&loc_result, temp);
  11757. mode = GET_MODE (XEXP (RTVEC_ELT (par_elems, i), 0));
  11758. add_loc_descr_op_piece (&loc_result, GET_MODE_SIZE (mode));
  11759. }
  11760. }
  11761. break;
  11762. case CONST_INT:
  11763. if (mode != VOIDmode && mode != BLKmode)
  11764. loc_result = address_of_int_loc_descriptor (GET_MODE_SIZE (mode),
  11765. INTVAL (rtl));
  11766. break;
  11767. case CONST_DOUBLE:
  11768. if (mode == VOIDmode)
  11769. mode = GET_MODE (rtl);
  11770. if (mode != VOIDmode && (dwarf_version >= 4 || !dwarf_strict))
  11771. {
  11772. gcc_assert (mode == GET_MODE (rtl) || VOIDmode == GET_MODE (rtl));
  11773. /* Note that a CONST_DOUBLE rtx could represent either an integer
  11774. or a floating-point constant. A CONST_DOUBLE is used whenever
  11775. the constant requires more than one word in order to be
  11776. adequately represented. We output CONST_DOUBLEs as blocks. */
  11777. loc_result = new_loc_descr (DW_OP_implicit_value,
  11778. GET_MODE_SIZE (mode), 0);
  11779. #if TARGET_SUPPORTS_WIDE_INT == 0
  11780. if (!SCALAR_FLOAT_MODE_P (mode))
  11781. {
  11782. loc_result->dw_loc_oprnd2.val_class = dw_val_class_const_double;
  11783. loc_result->dw_loc_oprnd2.v.val_double
  11784. = rtx_to_double_int (rtl);
  11785. }
  11786. else
  11787. #endif
  11788. {
  11789. unsigned int length = GET_MODE_SIZE (mode);
  11790. unsigned char *array = ggc_vec_alloc<unsigned char> (length);
  11791. insert_float (rtl, array);
  11792. loc_result->dw_loc_oprnd2.val_class = dw_val_class_vec;
  11793. loc_result->dw_loc_oprnd2.v.val_vec.length = length / 4;
  11794. loc_result->dw_loc_oprnd2.v.val_vec.elt_size = 4;
  11795. loc_result->dw_loc_oprnd2.v.val_vec.array = array;
  11796. }
  11797. }
  11798. break;
  11799. case CONST_WIDE_INT:
  11800. if (mode == VOIDmode)
  11801. mode = GET_MODE (rtl);
  11802. if (mode != VOIDmode && (dwarf_version >= 4 || !dwarf_strict))
  11803. {
  11804. loc_result = new_loc_descr (DW_OP_implicit_value,
  11805. GET_MODE_SIZE (mode), 0);
  11806. loc_result->dw_loc_oprnd2.val_class = dw_val_class_wide_int;
  11807. loc_result->dw_loc_oprnd2.v.val_wide = ggc_alloc<wide_int> ();
  11808. *loc_result->dw_loc_oprnd2.v.val_wide = std::make_pair (rtl, mode);
  11809. }
  11810. break;
  11811. case CONST_VECTOR:
  11812. if (mode == VOIDmode)
  11813. mode = GET_MODE (rtl);
  11814. if (mode != VOIDmode && (dwarf_version >= 4 || !dwarf_strict))
  11815. {
  11816. unsigned int elt_size = GET_MODE_UNIT_SIZE (GET_MODE (rtl));
  11817. unsigned int length = CONST_VECTOR_NUNITS (rtl);
  11818. unsigned char *array
  11819. = ggc_vec_alloc<unsigned char> (length * elt_size);
  11820. unsigned int i;
  11821. unsigned char *p;
  11822. machine_mode imode = GET_MODE_INNER (mode);
  11823. gcc_assert (mode == GET_MODE (rtl) || VOIDmode == GET_MODE (rtl));
  11824. switch (GET_MODE_CLASS (mode))
  11825. {
  11826. case MODE_VECTOR_INT:
  11827. for (i = 0, p = array; i < length; i++, p += elt_size)
  11828. {
  11829. rtx elt = CONST_VECTOR_ELT (rtl, i);
  11830. insert_wide_int (std::make_pair (elt, imode), p, elt_size);
  11831. }
  11832. break;
  11833. case MODE_VECTOR_FLOAT:
  11834. for (i = 0, p = array; i < length; i++, p += elt_size)
  11835. {
  11836. rtx elt = CONST_VECTOR_ELT (rtl, i);
  11837. insert_float (elt, p);
  11838. }
  11839. break;
  11840. default:
  11841. gcc_unreachable ();
  11842. }
  11843. loc_result = new_loc_descr (DW_OP_implicit_value,
  11844. length * elt_size, 0);
  11845. loc_result->dw_loc_oprnd2.val_class = dw_val_class_vec;
  11846. loc_result->dw_loc_oprnd2.v.val_vec.length = length;
  11847. loc_result->dw_loc_oprnd2.v.val_vec.elt_size = elt_size;
  11848. loc_result->dw_loc_oprnd2.v.val_vec.array = array;
  11849. }
  11850. break;
  11851. case CONST:
  11852. if (mode == VOIDmode
  11853. || CONST_SCALAR_INT_P (XEXP (rtl, 0))
  11854. || CONST_DOUBLE_AS_FLOAT_P (XEXP (rtl, 0))
  11855. || GET_CODE (XEXP (rtl, 0)) == CONST_VECTOR)
  11856. {
  11857. loc_result = loc_descriptor (XEXP (rtl, 0), mode, initialized);
  11858. break;
  11859. }
  11860. /* FALLTHROUGH */
  11861. case SYMBOL_REF:
  11862. if (!const_ok_for_output (rtl))
  11863. break;
  11864. case LABEL_REF:
  11865. if (mode != VOIDmode && GET_MODE_SIZE (mode) == DWARF2_ADDR_SIZE
  11866. && (dwarf_version >= 4 || !dwarf_strict))
  11867. {
  11868. loc_result = new_addr_loc_descr (rtl, dtprel_false);
  11869. add_loc_descr (&loc_result, new_loc_descr (DW_OP_stack_value, 0, 0));
  11870. vec_safe_push (used_rtx_array, rtl);
  11871. }
  11872. break;
  11873. case DEBUG_IMPLICIT_PTR:
  11874. loc_result = implicit_ptr_descriptor (rtl, 0);
  11875. break;
  11876. case PLUS:
  11877. if (GET_CODE (XEXP (rtl, 0)) == DEBUG_IMPLICIT_PTR
  11878. && CONST_INT_P (XEXP (rtl, 1)))
  11879. {
  11880. loc_result
  11881. = implicit_ptr_descriptor (XEXP (rtl, 0), INTVAL (XEXP (rtl, 1)));
  11882. break;
  11883. }
  11884. /* FALLTHRU */
  11885. do_default:
  11886. default:
  11887. if ((GET_MODE_CLASS (mode) == MODE_INT && GET_MODE (rtl) == mode
  11888. && GET_MODE_SIZE (GET_MODE (rtl)) <= DWARF2_ADDR_SIZE
  11889. && dwarf_version >= 4)
  11890. || (!dwarf_strict && mode != VOIDmode && mode != BLKmode))
  11891. {
  11892. /* Value expression. */
  11893. loc_result = mem_loc_descriptor (rtl, mode, VOIDmode, initialized);
  11894. if (loc_result)
  11895. add_loc_descr (&loc_result,
  11896. new_loc_descr (DW_OP_stack_value, 0, 0));
  11897. }
  11898. break;
  11899. }
  11900. return loc_result;
  11901. }
  11902. /* We need to figure out what section we should use as the base for the
  11903. address ranges where a given location is valid.
  11904. 1. If this particular DECL has a section associated with it, use that.
  11905. 2. If this function has a section associated with it, use that.
  11906. 3. Otherwise, use the text section.
  11907. XXX: If you split a variable across multiple sections, we won't notice. */
  11908. static const char *
  11909. secname_for_decl (const_tree decl)
  11910. {
  11911. const char *secname;
  11912. if (VAR_OR_FUNCTION_DECL_P (decl)
  11913. && (DECL_EXTERNAL (decl) || TREE_PUBLIC (decl) || TREE_STATIC (decl))
  11914. && DECL_SECTION_NAME (decl))
  11915. secname = DECL_SECTION_NAME (decl);
  11916. else if (current_function_decl && DECL_SECTION_NAME (current_function_decl))
  11917. secname = DECL_SECTION_NAME (current_function_decl);
  11918. else if (cfun && in_cold_section_p)
  11919. secname = crtl->subsections.cold_section_label;
  11920. else
  11921. secname = text_section_label;
  11922. return secname;
  11923. }
  11924. /* Return true when DECL_BY_REFERENCE is defined and set for DECL. */
  11925. static bool
  11926. decl_by_reference_p (tree decl)
  11927. {
  11928. return ((TREE_CODE (decl) == PARM_DECL || TREE_CODE (decl) == RESULT_DECL
  11929. || TREE_CODE (decl) == VAR_DECL)
  11930. && DECL_BY_REFERENCE (decl));
  11931. }
  11932. /* Helper function for dw_loc_list. Compute proper Dwarf location descriptor
  11933. for VARLOC. */
  11934. static dw_loc_descr_ref
  11935. dw_loc_list_1 (tree loc, rtx varloc, int want_address,
  11936. enum var_init_status initialized)
  11937. {
  11938. int have_address = 0;
  11939. dw_loc_descr_ref descr;
  11940. machine_mode mode;
  11941. if (want_address != 2)
  11942. {
  11943. gcc_assert (GET_CODE (varloc) == VAR_LOCATION);
  11944. /* Single part. */
  11945. if (GET_CODE (PAT_VAR_LOCATION_LOC (varloc)) != PARALLEL)
  11946. {
  11947. varloc = PAT_VAR_LOCATION_LOC (varloc);
  11948. if (GET_CODE (varloc) == EXPR_LIST)
  11949. varloc = XEXP (varloc, 0);
  11950. mode = GET_MODE (varloc);
  11951. if (MEM_P (varloc))
  11952. {
  11953. rtx addr = XEXP (varloc, 0);
  11954. descr = mem_loc_descriptor (addr, get_address_mode (varloc),
  11955. mode, initialized);
  11956. if (descr)
  11957. have_address = 1;
  11958. else
  11959. {
  11960. rtx x = avoid_constant_pool_reference (varloc);
  11961. if (x != varloc)
  11962. descr = mem_loc_descriptor (x, mode, VOIDmode,
  11963. initialized);
  11964. }
  11965. }
  11966. else
  11967. descr = mem_loc_descriptor (varloc, mode, VOIDmode, initialized);
  11968. }
  11969. else
  11970. return 0;
  11971. }
  11972. else
  11973. {
  11974. if (GET_CODE (varloc) == VAR_LOCATION)
  11975. mode = DECL_MODE (PAT_VAR_LOCATION_DECL (varloc));
  11976. else
  11977. mode = DECL_MODE (loc);
  11978. descr = loc_descriptor (varloc, mode, initialized);
  11979. have_address = 1;
  11980. }
  11981. if (!descr)
  11982. return 0;
  11983. if (want_address == 2 && !have_address
  11984. && (dwarf_version >= 4 || !dwarf_strict))
  11985. {
  11986. if (int_size_in_bytes (TREE_TYPE (loc)) > DWARF2_ADDR_SIZE)
  11987. {
  11988. expansion_failed (loc, NULL_RTX,
  11989. "DWARF address size mismatch");
  11990. return 0;
  11991. }
  11992. add_loc_descr (&descr, new_loc_descr (DW_OP_stack_value, 0, 0));
  11993. have_address = 1;
  11994. }
  11995. /* Show if we can't fill the request for an address. */
  11996. if (want_address && !have_address)
  11997. {
  11998. expansion_failed (loc, NULL_RTX,
  11999. "Want address and only have value");
  12000. return 0;
  12001. }
  12002. /* If we've got an address and don't want one, dereference. */
  12003. if (!want_address && have_address)
  12004. {
  12005. HOST_WIDE_INT size = int_size_in_bytes (TREE_TYPE (loc));
  12006. enum dwarf_location_atom op;
  12007. if (size > DWARF2_ADDR_SIZE || size == -1)
  12008. {
  12009. expansion_failed (loc, NULL_RTX,
  12010. "DWARF address size mismatch");
  12011. return 0;
  12012. }
  12013. else if (size == DWARF2_ADDR_SIZE)
  12014. op = DW_OP_deref;
  12015. else
  12016. op = DW_OP_deref_size;
  12017. add_loc_descr (&descr, new_loc_descr (op, size, 0));
  12018. }
  12019. return descr;
  12020. }
  12021. /* Create a DW_OP_piece or DW_OP_bit_piece for bitsize, or return NULL
  12022. if it is not possible. */
  12023. static dw_loc_descr_ref
  12024. new_loc_descr_op_bit_piece (HOST_WIDE_INT bitsize, HOST_WIDE_INT offset)
  12025. {
  12026. if ((bitsize % BITS_PER_UNIT) == 0 && offset == 0)
  12027. return new_loc_descr (DW_OP_piece, bitsize / BITS_PER_UNIT, 0);
  12028. else if (dwarf_version >= 3 || !dwarf_strict)
  12029. return new_loc_descr (DW_OP_bit_piece, bitsize, offset);
  12030. else
  12031. return NULL;
  12032. }
  12033. /* Helper function for dw_loc_list. Compute proper Dwarf location descriptor
  12034. for VAR_LOC_NOTE for variable DECL that has been optimized by SRA. */
  12035. static dw_loc_descr_ref
  12036. dw_sra_loc_expr (tree decl, rtx loc)
  12037. {
  12038. rtx p;
  12039. unsigned HOST_WIDE_INT padsize = 0;
  12040. dw_loc_descr_ref descr, *descr_tail;
  12041. unsigned HOST_WIDE_INT decl_size;
  12042. rtx varloc;
  12043. enum var_init_status initialized;
  12044. if (DECL_SIZE (decl) == NULL
  12045. || !tree_fits_uhwi_p (DECL_SIZE (decl)))
  12046. return NULL;
  12047. decl_size = tree_to_uhwi (DECL_SIZE (decl));
  12048. descr = NULL;
  12049. descr_tail = &descr;
  12050. for (p = loc; p; p = XEXP (p, 1))
  12051. {
  12052. unsigned HOST_WIDE_INT bitsize = decl_piece_bitsize (p);
  12053. rtx loc_note = *decl_piece_varloc_ptr (p);
  12054. dw_loc_descr_ref cur_descr;
  12055. dw_loc_descr_ref *tail, last = NULL;
  12056. unsigned HOST_WIDE_INT opsize = 0;
  12057. if (loc_note == NULL_RTX
  12058. || NOTE_VAR_LOCATION_LOC (loc_note) == NULL_RTX)
  12059. {
  12060. padsize += bitsize;
  12061. continue;
  12062. }
  12063. initialized = NOTE_VAR_LOCATION_STATUS (loc_note);
  12064. varloc = NOTE_VAR_LOCATION (loc_note);
  12065. cur_descr = dw_loc_list_1 (decl, varloc, 2, initialized);
  12066. if (cur_descr == NULL)
  12067. {
  12068. padsize += bitsize;
  12069. continue;
  12070. }
  12071. /* Check that cur_descr either doesn't use
  12072. DW_OP_*piece operations, or their sum is equal
  12073. to bitsize. Otherwise we can't embed it. */
  12074. for (tail = &cur_descr; *tail != NULL;
  12075. tail = &(*tail)->dw_loc_next)
  12076. if ((*tail)->dw_loc_opc == DW_OP_piece)
  12077. {
  12078. opsize += (*tail)->dw_loc_oprnd1.v.val_unsigned
  12079. * BITS_PER_UNIT;
  12080. last = *tail;
  12081. }
  12082. else if ((*tail)->dw_loc_opc == DW_OP_bit_piece)
  12083. {
  12084. opsize += (*tail)->dw_loc_oprnd1.v.val_unsigned;
  12085. last = *tail;
  12086. }
  12087. if (last != NULL && opsize != bitsize)
  12088. {
  12089. padsize += bitsize;
  12090. /* Discard the current piece of the descriptor and release any
  12091. addr_table entries it uses. */
  12092. remove_loc_list_addr_table_entries (cur_descr);
  12093. continue;
  12094. }
  12095. /* If there is a hole, add DW_OP_*piece after empty DWARF
  12096. expression, which means that those bits are optimized out. */
  12097. if (padsize)
  12098. {
  12099. if (padsize > decl_size)
  12100. {
  12101. remove_loc_list_addr_table_entries (cur_descr);
  12102. goto discard_descr;
  12103. }
  12104. decl_size -= padsize;
  12105. *descr_tail = new_loc_descr_op_bit_piece (padsize, 0);
  12106. if (*descr_tail == NULL)
  12107. {
  12108. remove_loc_list_addr_table_entries (cur_descr);
  12109. goto discard_descr;
  12110. }
  12111. descr_tail = &(*descr_tail)->dw_loc_next;
  12112. padsize = 0;
  12113. }
  12114. *descr_tail = cur_descr;
  12115. descr_tail = tail;
  12116. if (bitsize > decl_size)
  12117. goto discard_descr;
  12118. decl_size -= bitsize;
  12119. if (last == NULL)
  12120. {
  12121. HOST_WIDE_INT offset = 0;
  12122. if (GET_CODE (varloc) == VAR_LOCATION
  12123. && GET_CODE (PAT_VAR_LOCATION_LOC (varloc)) != PARALLEL)
  12124. {
  12125. varloc = PAT_VAR_LOCATION_LOC (varloc);
  12126. if (GET_CODE (varloc) == EXPR_LIST)
  12127. varloc = XEXP (varloc, 0);
  12128. }
  12129. do
  12130. {
  12131. if (GET_CODE (varloc) == CONST
  12132. || GET_CODE (varloc) == SIGN_EXTEND
  12133. || GET_CODE (varloc) == ZERO_EXTEND)
  12134. varloc = XEXP (varloc, 0);
  12135. else if (GET_CODE (varloc) == SUBREG)
  12136. varloc = SUBREG_REG (varloc);
  12137. else
  12138. break;
  12139. }
  12140. while (1);
  12141. /* DW_OP_bit_size offset should be zero for register
  12142. or implicit location descriptions and empty location
  12143. descriptions, but for memory addresses needs big endian
  12144. adjustment. */
  12145. if (MEM_P (varloc))
  12146. {
  12147. unsigned HOST_WIDE_INT memsize
  12148. = MEM_SIZE (varloc) * BITS_PER_UNIT;
  12149. if (memsize != bitsize)
  12150. {
  12151. if (BYTES_BIG_ENDIAN != WORDS_BIG_ENDIAN
  12152. && (memsize > BITS_PER_WORD || bitsize > BITS_PER_WORD))
  12153. goto discard_descr;
  12154. if (memsize < bitsize)
  12155. goto discard_descr;
  12156. if (BITS_BIG_ENDIAN)
  12157. offset = memsize - bitsize;
  12158. }
  12159. }
  12160. *descr_tail = new_loc_descr_op_bit_piece (bitsize, offset);
  12161. if (*descr_tail == NULL)
  12162. goto discard_descr;
  12163. descr_tail = &(*descr_tail)->dw_loc_next;
  12164. }
  12165. }
  12166. /* If there were any non-empty expressions, add padding till the end of
  12167. the decl. */
  12168. if (descr != NULL && decl_size != 0)
  12169. {
  12170. *descr_tail = new_loc_descr_op_bit_piece (decl_size, 0);
  12171. if (*descr_tail == NULL)
  12172. goto discard_descr;
  12173. }
  12174. return descr;
  12175. discard_descr:
  12176. /* Discard the descriptor and release any addr_table entries it uses. */
  12177. remove_loc_list_addr_table_entries (descr);
  12178. return NULL;
  12179. }
  12180. /* Return the dwarf representation of the location list LOC_LIST of
  12181. DECL. WANT_ADDRESS has the same meaning as in loc_list_from_tree
  12182. function. */
  12183. static dw_loc_list_ref
  12184. dw_loc_list (var_loc_list *loc_list, tree decl, int want_address)
  12185. {
  12186. const char *endname, *secname;
  12187. rtx varloc;
  12188. enum var_init_status initialized;
  12189. struct var_loc_node *node;
  12190. dw_loc_descr_ref descr;
  12191. char label_id[MAX_ARTIFICIAL_LABEL_BYTES];
  12192. dw_loc_list_ref list = NULL;
  12193. dw_loc_list_ref *listp = &list;
  12194. /* Now that we know what section we are using for a base,
  12195. actually construct the list of locations.
  12196. The first location information is what is passed to the
  12197. function that creates the location list, and the remaining
  12198. locations just get added on to that list.
  12199. Note that we only know the start address for a location
  12200. (IE location changes), so to build the range, we use
  12201. the range [current location start, next location start].
  12202. This means we have to special case the last node, and generate
  12203. a range of [last location start, end of function label]. */
  12204. secname = secname_for_decl (decl);
  12205. for (node = loc_list->first; node; node = node->next)
  12206. if (GET_CODE (node->loc) == EXPR_LIST
  12207. || NOTE_VAR_LOCATION_LOC (node->loc) != NULL_RTX)
  12208. {
  12209. if (GET_CODE (node->loc) == EXPR_LIST)
  12210. {
  12211. /* This requires DW_OP_{,bit_}piece, which is not usable
  12212. inside DWARF expressions. */
  12213. if (want_address != 2)
  12214. continue;
  12215. descr = dw_sra_loc_expr (decl, node->loc);
  12216. if (descr == NULL)
  12217. continue;
  12218. }
  12219. else
  12220. {
  12221. initialized = NOTE_VAR_LOCATION_STATUS (node->loc);
  12222. varloc = NOTE_VAR_LOCATION (node->loc);
  12223. descr = dw_loc_list_1 (decl, varloc, want_address, initialized);
  12224. }
  12225. if (descr)
  12226. {
  12227. bool range_across_switch = false;
  12228. /* If section switch happens in between node->label
  12229. and node->next->label (or end of function) and
  12230. we can't emit it as a single entry list,
  12231. emit two ranges, first one ending at the end
  12232. of first partition and second one starting at the
  12233. beginning of second partition. */
  12234. if (node == loc_list->last_before_switch
  12235. && (node != loc_list->first || loc_list->first->next)
  12236. && current_function_decl)
  12237. {
  12238. endname = cfun->fde->dw_fde_end;
  12239. range_across_switch = true;
  12240. }
  12241. /* The variable has a location between NODE->LABEL and
  12242. NODE->NEXT->LABEL. */
  12243. else if (node->next)
  12244. endname = node->next->label;
  12245. /* If the variable has a location at the last label
  12246. it keeps its location until the end of function. */
  12247. else if (!current_function_decl)
  12248. endname = text_end_label;
  12249. else
  12250. {
  12251. ASM_GENERATE_INTERNAL_LABEL (label_id, FUNC_END_LABEL,
  12252. current_function_funcdef_no);
  12253. endname = ggc_strdup (label_id);
  12254. }
  12255. *listp = new_loc_list (descr, node->label, endname, secname);
  12256. if (TREE_CODE (decl) == PARM_DECL
  12257. && node == loc_list->first
  12258. && NOTE_P (node->loc)
  12259. && strcmp (node->label, endname) == 0)
  12260. (*listp)->force = true;
  12261. listp = &(*listp)->dw_loc_next;
  12262. if (range_across_switch)
  12263. {
  12264. if (GET_CODE (node->loc) == EXPR_LIST)
  12265. descr = dw_sra_loc_expr (decl, node->loc);
  12266. else
  12267. {
  12268. initialized = NOTE_VAR_LOCATION_STATUS (node->loc);
  12269. varloc = NOTE_VAR_LOCATION (node->loc);
  12270. descr = dw_loc_list_1 (decl, varloc, want_address,
  12271. initialized);
  12272. }
  12273. gcc_assert (descr);
  12274. /* The variable has a location between NODE->LABEL and
  12275. NODE->NEXT->LABEL. */
  12276. if (node->next)
  12277. endname = node->next->label;
  12278. else
  12279. endname = cfun->fde->dw_fde_second_end;
  12280. *listp = new_loc_list (descr,
  12281. cfun->fde->dw_fde_second_begin,
  12282. endname, secname);
  12283. listp = &(*listp)->dw_loc_next;
  12284. }
  12285. }
  12286. }
  12287. /* Try to avoid the overhead of a location list emitting a location
  12288. expression instead, but only if we didn't have more than one
  12289. location entry in the first place. If some entries were not
  12290. representable, we don't want to pretend a single entry that was
  12291. applies to the entire scope in which the variable is
  12292. available. */
  12293. if (list && loc_list->first->next)
  12294. gen_llsym (list);
  12295. return list;
  12296. }
  12297. /* Return if the loc_list has only single element and thus can be represented
  12298. as location description. */
  12299. static bool
  12300. single_element_loc_list_p (dw_loc_list_ref list)
  12301. {
  12302. gcc_assert (!list->dw_loc_next || list->ll_symbol);
  12303. return !list->ll_symbol;
  12304. }
  12305. /* To each location in list LIST add loc descr REF. */
  12306. static void
  12307. add_loc_descr_to_each (dw_loc_list_ref list, dw_loc_descr_ref ref)
  12308. {
  12309. dw_loc_descr_ref copy;
  12310. add_loc_descr (&list->expr, ref);
  12311. list = list->dw_loc_next;
  12312. while (list)
  12313. {
  12314. copy = ggc_alloc<dw_loc_descr_node> ();
  12315. memcpy (copy, ref, sizeof (dw_loc_descr_node));
  12316. add_loc_descr (&list->expr, copy);
  12317. while (copy->dw_loc_next)
  12318. {
  12319. dw_loc_descr_ref new_copy = ggc_alloc<dw_loc_descr_node> ();
  12320. memcpy (new_copy, copy->dw_loc_next, sizeof (dw_loc_descr_node));
  12321. copy->dw_loc_next = new_copy;
  12322. copy = new_copy;
  12323. }
  12324. list = list->dw_loc_next;
  12325. }
  12326. }
  12327. /* Given two lists RET and LIST
  12328. produce location list that is result of adding expression in LIST
  12329. to expression in RET on each position in program.
  12330. Might be destructive on both RET and LIST.
  12331. TODO: We handle only simple cases of RET or LIST having at most one
  12332. element. General case would inolve sorting the lists in program order
  12333. and merging them that will need some additional work.
  12334. Adding that will improve quality of debug info especially for SRA-ed
  12335. structures. */
  12336. static void
  12337. add_loc_list (dw_loc_list_ref *ret, dw_loc_list_ref list)
  12338. {
  12339. if (!list)
  12340. return;
  12341. if (!*ret)
  12342. {
  12343. *ret = list;
  12344. return;
  12345. }
  12346. if (!list->dw_loc_next)
  12347. {
  12348. add_loc_descr_to_each (*ret, list->expr);
  12349. return;
  12350. }
  12351. if (!(*ret)->dw_loc_next)
  12352. {
  12353. add_loc_descr_to_each (list, (*ret)->expr);
  12354. *ret = list;
  12355. return;
  12356. }
  12357. expansion_failed (NULL_TREE, NULL_RTX,
  12358. "Don't know how to merge two non-trivial"
  12359. " location lists.\n");
  12360. *ret = NULL;
  12361. return;
  12362. }
  12363. /* LOC is constant expression. Try a luck, look it up in constant
  12364. pool and return its loc_descr of its address. */
  12365. static dw_loc_descr_ref
  12366. cst_pool_loc_descr (tree loc)
  12367. {
  12368. /* Get an RTL for this, if something has been emitted. */
  12369. rtx rtl = lookup_constant_def (loc);
  12370. if (!rtl || !MEM_P (rtl))
  12371. {
  12372. gcc_assert (!rtl);
  12373. return 0;
  12374. }
  12375. gcc_assert (GET_CODE (XEXP (rtl, 0)) == SYMBOL_REF);
  12376. /* TODO: We might get more coverage if we was actually delaying expansion
  12377. of all expressions till end of compilation when constant pools are fully
  12378. populated. */
  12379. if (!TREE_ASM_WRITTEN (SYMBOL_REF_DECL (XEXP (rtl, 0))))
  12380. {
  12381. expansion_failed (loc, NULL_RTX,
  12382. "CST value in contant pool but not marked.");
  12383. return 0;
  12384. }
  12385. return mem_loc_descriptor (XEXP (rtl, 0), get_address_mode (rtl),
  12386. GET_MODE (rtl), VAR_INIT_STATUS_INITIALIZED);
  12387. }
  12388. /* Return dw_loc_list representing address of addr_expr LOC
  12389. by looking for inner INDIRECT_REF expression and turning
  12390. it into simple arithmetics.
  12391. See loc_list_from_tree for the meaning of CONTEXT. */
  12392. static dw_loc_list_ref
  12393. loc_list_for_address_of_addr_expr_of_indirect_ref (tree loc, bool toplev,
  12394. const loc_descr_context *context)
  12395. {
  12396. tree obj, offset;
  12397. HOST_WIDE_INT bitsize, bitpos, bytepos;
  12398. machine_mode mode;
  12399. int unsignedp, volatilep = 0;
  12400. dw_loc_list_ref list_ret = NULL, list_ret1 = NULL;
  12401. obj = get_inner_reference (TREE_OPERAND (loc, 0),
  12402. &bitsize, &bitpos, &offset, &mode,
  12403. &unsignedp, &volatilep, false);
  12404. STRIP_NOPS (obj);
  12405. if (bitpos % BITS_PER_UNIT)
  12406. {
  12407. expansion_failed (loc, NULL_RTX, "bitfield access");
  12408. return 0;
  12409. }
  12410. if (!INDIRECT_REF_P (obj))
  12411. {
  12412. expansion_failed (obj,
  12413. NULL_RTX, "no indirect ref in inner refrence");
  12414. return 0;
  12415. }
  12416. if (!offset && !bitpos)
  12417. list_ret = loc_list_from_tree (TREE_OPERAND (obj, 0), toplev ? 2 : 1,
  12418. context);
  12419. else if (toplev
  12420. && int_size_in_bytes (TREE_TYPE (loc)) <= DWARF2_ADDR_SIZE
  12421. && (dwarf_version >= 4 || !dwarf_strict))
  12422. {
  12423. list_ret = loc_list_from_tree (TREE_OPERAND (obj, 0), 0, context);
  12424. if (!list_ret)
  12425. return 0;
  12426. if (offset)
  12427. {
  12428. /* Variable offset. */
  12429. list_ret1 = loc_list_from_tree (offset, 0, context);
  12430. if (list_ret1 == 0)
  12431. return 0;
  12432. add_loc_list (&list_ret, list_ret1);
  12433. if (!list_ret)
  12434. return 0;
  12435. add_loc_descr_to_each (list_ret,
  12436. new_loc_descr (DW_OP_plus, 0, 0));
  12437. }
  12438. bytepos = bitpos / BITS_PER_UNIT;
  12439. if (bytepos > 0)
  12440. add_loc_descr_to_each (list_ret,
  12441. new_loc_descr (DW_OP_plus_uconst,
  12442. bytepos, 0));
  12443. else if (bytepos < 0)
  12444. loc_list_plus_const (list_ret, bytepos);
  12445. add_loc_descr_to_each (list_ret,
  12446. new_loc_descr (DW_OP_stack_value, 0, 0));
  12447. }
  12448. return list_ret;
  12449. }
  12450. /* Helper structure for location descriptions generation. */
  12451. struct loc_descr_context
  12452. {
  12453. /* The type that is implicitly referenced by DW_OP_push_object_address, or
  12454. NULL_TREE if DW_OP_push_object_address in invalid for this location
  12455. description. This is used when processing PLACEHOLDER_EXPR nodes. */
  12456. tree context_type;
  12457. /* The ..._DECL node that should be translated as a
  12458. DW_OP_push_object_address operation. */
  12459. tree base_decl;
  12460. };
  12461. /* Generate Dwarf location list representing LOC.
  12462. If WANT_ADDRESS is false, expression computing LOC will be computed
  12463. If WANT_ADDRESS is 1, expression computing address of LOC will be returned
  12464. if WANT_ADDRESS is 2, expression computing address useable in location
  12465. will be returned (i.e. DW_OP_reg can be used
  12466. to refer to register values).
  12467. CONTEXT provides information to customize the location descriptions
  12468. generation. Its context_type field specifies what type is implicitly
  12469. referenced by DW_OP_push_object_address. If it is NULL_TREE, this operation
  12470. will not be generated.
  12471. If CONTEXT is NULL, the behavior is the same as if both context_type and
  12472. base_decl fields were NULL_TREE. */
  12473. static dw_loc_list_ref
  12474. loc_list_from_tree (tree loc, int want_address,
  12475. const struct loc_descr_context *context)
  12476. {
  12477. dw_loc_descr_ref ret = NULL, ret1 = NULL;
  12478. dw_loc_list_ref list_ret = NULL, list_ret1 = NULL;
  12479. int have_address = 0;
  12480. enum dwarf_location_atom op;
  12481. /* ??? Most of the time we do not take proper care for sign/zero
  12482. extending the values properly. Hopefully this won't be a real
  12483. problem... */
  12484. if (context != NULL
  12485. && context->base_decl == loc
  12486. && want_address == 0)
  12487. {
  12488. if (dwarf_version >= 3 || !dwarf_strict)
  12489. return new_loc_list (new_loc_descr (DW_OP_push_object_address, 0, 0),
  12490. NULL, NULL, NULL);
  12491. else
  12492. return NULL;
  12493. }
  12494. switch (TREE_CODE (loc))
  12495. {
  12496. case ERROR_MARK:
  12497. expansion_failed (loc, NULL_RTX, "ERROR_MARK");
  12498. return 0;
  12499. case PLACEHOLDER_EXPR:
  12500. /* This case involves extracting fields from an object to determine the
  12501. position of other fields. It is supposed to appear only as the first
  12502. operand of COMPONENT_REF nodes and to reference precisely the type
  12503. that the context allows. */
  12504. if (context != NULL
  12505. && TREE_TYPE (loc) == context->context_type
  12506. && want_address >= 1)
  12507. {
  12508. if (dwarf_version >= 3 || !dwarf_strict)
  12509. {
  12510. ret = new_loc_descr (DW_OP_push_object_address, 0, 0);
  12511. have_address = 1;
  12512. break;
  12513. }
  12514. else
  12515. return NULL;
  12516. }
  12517. else
  12518. expansion_failed (loc, NULL_RTX,
  12519. "PLACEHOLDER_EXPR for an unexpected type");
  12520. break;
  12521. case CALL_EXPR:
  12522. expansion_failed (loc, NULL_RTX, "CALL_EXPR");
  12523. /* There are no opcodes for these operations. */
  12524. return 0;
  12525. case PREINCREMENT_EXPR:
  12526. case PREDECREMENT_EXPR:
  12527. case POSTINCREMENT_EXPR:
  12528. case POSTDECREMENT_EXPR:
  12529. expansion_failed (loc, NULL_RTX, "PRE/POST INDCREMENT/DECREMENT");
  12530. /* There are no opcodes for these operations. */
  12531. return 0;
  12532. case ADDR_EXPR:
  12533. /* If we already want an address, see if there is INDIRECT_REF inside
  12534. e.g. for &this->field. */
  12535. if (want_address)
  12536. {
  12537. list_ret = loc_list_for_address_of_addr_expr_of_indirect_ref
  12538. (loc, want_address == 2, context);
  12539. if (list_ret)
  12540. have_address = 1;
  12541. else if (decl_address_ip_invariant_p (TREE_OPERAND (loc, 0))
  12542. && (ret = cst_pool_loc_descr (loc)))
  12543. have_address = 1;
  12544. }
  12545. /* Otherwise, process the argument and look for the address. */
  12546. if (!list_ret && !ret)
  12547. list_ret = loc_list_from_tree (TREE_OPERAND (loc, 0), 1, context);
  12548. else
  12549. {
  12550. if (want_address)
  12551. expansion_failed (loc, NULL_RTX, "need address of ADDR_EXPR");
  12552. return NULL;
  12553. }
  12554. break;
  12555. case VAR_DECL:
  12556. if (DECL_THREAD_LOCAL_P (loc))
  12557. {
  12558. rtx rtl;
  12559. enum dwarf_location_atom tls_op;
  12560. enum dtprel_bool dtprel = dtprel_false;
  12561. if (targetm.have_tls)
  12562. {
  12563. /* If this is not defined, we have no way to emit the
  12564. data. */
  12565. if (!targetm.asm_out.output_dwarf_dtprel)
  12566. return 0;
  12567. /* The way DW_OP_GNU_push_tls_address is specified, we
  12568. can only look up addresses of objects in the current
  12569. module. We used DW_OP_addr as first op, but that's
  12570. wrong, because DW_OP_addr is relocated by the debug
  12571. info consumer, while DW_OP_GNU_push_tls_address
  12572. operand shouldn't be. */
  12573. if (DECL_EXTERNAL (loc) && !targetm.binds_local_p (loc))
  12574. return 0;
  12575. dtprel = dtprel_true;
  12576. tls_op = DW_OP_GNU_push_tls_address;
  12577. }
  12578. else
  12579. {
  12580. if (!targetm.emutls.debug_form_tls_address
  12581. || !(dwarf_version >= 3 || !dwarf_strict))
  12582. return 0;
  12583. /* We stuffed the control variable into the DECL_VALUE_EXPR
  12584. to signal (via DECL_HAS_VALUE_EXPR_P) that the decl should
  12585. no longer appear in gimple code. We used the control
  12586. variable in specific so that we could pick it up here. */
  12587. loc = DECL_VALUE_EXPR (loc);
  12588. tls_op = DW_OP_form_tls_address;
  12589. }
  12590. rtl = rtl_for_decl_location (loc);
  12591. if (rtl == NULL_RTX)
  12592. return 0;
  12593. if (!MEM_P (rtl))
  12594. return 0;
  12595. rtl = XEXP (rtl, 0);
  12596. if (! CONSTANT_P (rtl))
  12597. return 0;
  12598. ret = new_addr_loc_descr (rtl, dtprel);
  12599. ret1 = new_loc_descr (tls_op, 0, 0);
  12600. add_loc_descr (&ret, ret1);
  12601. have_address = 1;
  12602. break;
  12603. }
  12604. /* FALLTHRU */
  12605. case PARM_DECL:
  12606. case RESULT_DECL:
  12607. if (DECL_HAS_VALUE_EXPR_P (loc))
  12608. return loc_list_from_tree (DECL_VALUE_EXPR (loc),
  12609. want_address, context);
  12610. /* FALLTHRU */
  12611. case FUNCTION_DECL:
  12612. {
  12613. rtx rtl;
  12614. var_loc_list *loc_list = lookup_decl_loc (loc);
  12615. if (loc_list && loc_list->first)
  12616. {
  12617. list_ret = dw_loc_list (loc_list, loc, want_address);
  12618. have_address = want_address != 0;
  12619. break;
  12620. }
  12621. rtl = rtl_for_decl_location (loc);
  12622. if (rtl == NULL_RTX)
  12623. {
  12624. expansion_failed (loc, NULL_RTX, "DECL has no RTL");
  12625. return 0;
  12626. }
  12627. else if (CONST_INT_P (rtl))
  12628. {
  12629. HOST_WIDE_INT val = INTVAL (rtl);
  12630. if (TYPE_UNSIGNED (TREE_TYPE (loc)))
  12631. val &= GET_MODE_MASK (DECL_MODE (loc));
  12632. ret = int_loc_descriptor (val);
  12633. }
  12634. else if (GET_CODE (rtl) == CONST_STRING)
  12635. {
  12636. expansion_failed (loc, NULL_RTX, "CONST_STRING");
  12637. return 0;
  12638. }
  12639. else if (CONSTANT_P (rtl) && const_ok_for_output (rtl))
  12640. ret = new_addr_loc_descr (rtl, dtprel_false);
  12641. else
  12642. {
  12643. machine_mode mode, mem_mode;
  12644. /* Certain constructs can only be represented at top-level. */
  12645. if (want_address == 2)
  12646. {
  12647. ret = loc_descriptor (rtl, VOIDmode,
  12648. VAR_INIT_STATUS_INITIALIZED);
  12649. have_address = 1;
  12650. }
  12651. else
  12652. {
  12653. mode = GET_MODE (rtl);
  12654. mem_mode = VOIDmode;
  12655. if (MEM_P (rtl))
  12656. {
  12657. mem_mode = mode;
  12658. mode = get_address_mode (rtl);
  12659. rtl = XEXP (rtl, 0);
  12660. have_address = 1;
  12661. }
  12662. ret = mem_loc_descriptor (rtl, mode, mem_mode,
  12663. VAR_INIT_STATUS_INITIALIZED);
  12664. }
  12665. if (!ret)
  12666. expansion_failed (loc, rtl,
  12667. "failed to produce loc descriptor for rtl");
  12668. }
  12669. }
  12670. break;
  12671. case MEM_REF:
  12672. if (!integer_zerop (TREE_OPERAND (loc, 1)))
  12673. {
  12674. have_address = 1;
  12675. goto do_plus;
  12676. }
  12677. /* Fallthru. */
  12678. case INDIRECT_REF:
  12679. list_ret = loc_list_from_tree (TREE_OPERAND (loc, 0), 0, context);
  12680. have_address = 1;
  12681. break;
  12682. case TARGET_MEM_REF:
  12683. case SSA_NAME:
  12684. case DEBUG_EXPR_DECL:
  12685. return NULL;
  12686. case COMPOUND_EXPR:
  12687. return loc_list_from_tree (TREE_OPERAND (loc, 1), want_address, context);
  12688. CASE_CONVERT:
  12689. case VIEW_CONVERT_EXPR:
  12690. case SAVE_EXPR:
  12691. case MODIFY_EXPR:
  12692. return loc_list_from_tree (TREE_OPERAND (loc, 0), want_address, context);
  12693. case COMPONENT_REF:
  12694. case BIT_FIELD_REF:
  12695. case ARRAY_REF:
  12696. case ARRAY_RANGE_REF:
  12697. case REALPART_EXPR:
  12698. case IMAGPART_EXPR:
  12699. {
  12700. tree obj, offset;
  12701. HOST_WIDE_INT bitsize, bitpos, bytepos;
  12702. machine_mode mode;
  12703. int unsignedp, volatilep = 0;
  12704. obj = get_inner_reference (loc, &bitsize, &bitpos, &offset, &mode,
  12705. &unsignedp, &volatilep, false);
  12706. gcc_assert (obj != loc);
  12707. list_ret = loc_list_from_tree (obj,
  12708. want_address == 2
  12709. && !bitpos && !offset ? 2 : 1,
  12710. context);
  12711. /* TODO: We can extract value of the small expression via shifting even
  12712. for nonzero bitpos. */
  12713. if (list_ret == 0)
  12714. return 0;
  12715. if (bitpos % BITS_PER_UNIT != 0 || bitsize % BITS_PER_UNIT != 0)
  12716. {
  12717. expansion_failed (loc, NULL_RTX,
  12718. "bitfield access");
  12719. return 0;
  12720. }
  12721. if (offset != NULL_TREE)
  12722. {
  12723. /* Variable offset. */
  12724. list_ret1 = loc_list_from_tree (offset, 0, context);
  12725. if (list_ret1 == 0)
  12726. return 0;
  12727. add_loc_list (&list_ret, list_ret1);
  12728. if (!list_ret)
  12729. return 0;
  12730. add_loc_descr_to_each (list_ret, new_loc_descr (DW_OP_plus, 0, 0));
  12731. }
  12732. bytepos = bitpos / BITS_PER_UNIT;
  12733. if (bytepos > 0)
  12734. add_loc_descr_to_each (list_ret, new_loc_descr (DW_OP_plus_uconst, bytepos, 0));
  12735. else if (bytepos < 0)
  12736. loc_list_plus_const (list_ret, bytepos);
  12737. have_address = 1;
  12738. break;
  12739. }
  12740. case INTEGER_CST:
  12741. if ((want_address || !tree_fits_shwi_p (loc))
  12742. && (ret = cst_pool_loc_descr (loc)))
  12743. have_address = 1;
  12744. else if (want_address == 2
  12745. && tree_fits_shwi_p (loc)
  12746. && (ret = address_of_int_loc_descriptor
  12747. (int_size_in_bytes (TREE_TYPE (loc)),
  12748. tree_to_shwi (loc))))
  12749. have_address = 1;
  12750. else if (tree_fits_shwi_p (loc))
  12751. ret = int_loc_descriptor (tree_to_shwi (loc));
  12752. else
  12753. {
  12754. expansion_failed (loc, NULL_RTX,
  12755. "Integer operand is not host integer");
  12756. return 0;
  12757. }
  12758. break;
  12759. case CONSTRUCTOR:
  12760. case REAL_CST:
  12761. case STRING_CST:
  12762. case COMPLEX_CST:
  12763. if ((ret = cst_pool_loc_descr (loc)))
  12764. have_address = 1;
  12765. else
  12766. /* We can construct small constants here using int_loc_descriptor. */
  12767. expansion_failed (loc, NULL_RTX,
  12768. "constructor or constant not in constant pool");
  12769. break;
  12770. case TRUTH_AND_EXPR:
  12771. case TRUTH_ANDIF_EXPR:
  12772. case BIT_AND_EXPR:
  12773. op = DW_OP_and;
  12774. goto do_binop;
  12775. case TRUTH_XOR_EXPR:
  12776. case BIT_XOR_EXPR:
  12777. op = DW_OP_xor;
  12778. goto do_binop;
  12779. case TRUTH_OR_EXPR:
  12780. case TRUTH_ORIF_EXPR:
  12781. case BIT_IOR_EXPR:
  12782. op = DW_OP_or;
  12783. goto do_binop;
  12784. case FLOOR_DIV_EXPR:
  12785. case CEIL_DIV_EXPR:
  12786. case ROUND_DIV_EXPR:
  12787. case TRUNC_DIV_EXPR:
  12788. if (TYPE_UNSIGNED (TREE_TYPE (loc)))
  12789. return 0;
  12790. op = DW_OP_div;
  12791. goto do_binop;
  12792. case MINUS_EXPR:
  12793. op = DW_OP_minus;
  12794. goto do_binop;
  12795. case FLOOR_MOD_EXPR:
  12796. case CEIL_MOD_EXPR:
  12797. case ROUND_MOD_EXPR:
  12798. case TRUNC_MOD_EXPR:
  12799. if (TYPE_UNSIGNED (TREE_TYPE (loc)))
  12800. {
  12801. op = DW_OP_mod;
  12802. goto do_binop;
  12803. }
  12804. list_ret = loc_list_from_tree (TREE_OPERAND (loc, 0), 0, context);
  12805. list_ret1 = loc_list_from_tree (TREE_OPERAND (loc, 1), 0, context);
  12806. if (list_ret == 0 || list_ret1 == 0)
  12807. return 0;
  12808. add_loc_list (&list_ret, list_ret1);
  12809. if (list_ret == 0)
  12810. return 0;
  12811. add_loc_descr_to_each (list_ret, new_loc_descr (DW_OP_over, 0, 0));
  12812. add_loc_descr_to_each (list_ret, new_loc_descr (DW_OP_over, 0, 0));
  12813. add_loc_descr_to_each (list_ret, new_loc_descr (DW_OP_div, 0, 0));
  12814. add_loc_descr_to_each (list_ret, new_loc_descr (DW_OP_mul, 0, 0));
  12815. add_loc_descr_to_each (list_ret, new_loc_descr (DW_OP_minus, 0, 0));
  12816. break;
  12817. case MULT_EXPR:
  12818. op = DW_OP_mul;
  12819. goto do_binop;
  12820. case LSHIFT_EXPR:
  12821. op = DW_OP_shl;
  12822. goto do_binop;
  12823. case RSHIFT_EXPR:
  12824. op = (TYPE_UNSIGNED (TREE_TYPE (loc)) ? DW_OP_shr : DW_OP_shra);
  12825. goto do_binop;
  12826. case POINTER_PLUS_EXPR:
  12827. case PLUS_EXPR:
  12828. do_plus:
  12829. if (tree_fits_shwi_p (TREE_OPERAND (loc, 1)))
  12830. {
  12831. list_ret = loc_list_from_tree (TREE_OPERAND (loc, 0), 0, context);
  12832. if (list_ret == 0)
  12833. return 0;
  12834. loc_list_plus_const (list_ret, tree_to_shwi (TREE_OPERAND (loc, 1)));
  12835. break;
  12836. }
  12837. op = DW_OP_plus;
  12838. goto do_binop;
  12839. case LE_EXPR:
  12840. if (TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc, 0))))
  12841. return 0;
  12842. op = DW_OP_le;
  12843. goto do_binop;
  12844. case GE_EXPR:
  12845. if (TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc, 0))))
  12846. return 0;
  12847. op = DW_OP_ge;
  12848. goto do_binop;
  12849. case LT_EXPR:
  12850. if (TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc, 0))))
  12851. return 0;
  12852. op = DW_OP_lt;
  12853. goto do_binop;
  12854. case GT_EXPR:
  12855. if (TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc, 0))))
  12856. return 0;
  12857. op = DW_OP_gt;
  12858. goto do_binop;
  12859. case EQ_EXPR:
  12860. op = DW_OP_eq;
  12861. goto do_binop;
  12862. case NE_EXPR:
  12863. op = DW_OP_ne;
  12864. goto do_binop;
  12865. do_binop:
  12866. list_ret = loc_list_from_tree (TREE_OPERAND (loc, 0), 0, context);
  12867. list_ret1 = loc_list_from_tree (TREE_OPERAND (loc, 1), 0, context);
  12868. if (list_ret == 0 || list_ret1 == 0)
  12869. return 0;
  12870. add_loc_list (&list_ret, list_ret1);
  12871. if (list_ret == 0)
  12872. return 0;
  12873. add_loc_descr_to_each (list_ret, new_loc_descr (op, 0, 0));
  12874. break;
  12875. case TRUTH_NOT_EXPR:
  12876. case BIT_NOT_EXPR:
  12877. op = DW_OP_not;
  12878. goto do_unop;
  12879. case ABS_EXPR:
  12880. op = DW_OP_abs;
  12881. goto do_unop;
  12882. case NEGATE_EXPR:
  12883. op = DW_OP_neg;
  12884. goto do_unop;
  12885. do_unop:
  12886. list_ret = loc_list_from_tree (TREE_OPERAND (loc, 0), 0, context);
  12887. if (list_ret == 0)
  12888. return 0;
  12889. add_loc_descr_to_each (list_ret, new_loc_descr (op, 0, 0));
  12890. break;
  12891. case MIN_EXPR:
  12892. case MAX_EXPR:
  12893. {
  12894. const enum tree_code code =
  12895. TREE_CODE (loc) == MIN_EXPR ? GT_EXPR : LT_EXPR;
  12896. loc = build3 (COND_EXPR, TREE_TYPE (loc),
  12897. build2 (code, integer_type_node,
  12898. TREE_OPERAND (loc, 0), TREE_OPERAND (loc, 1)),
  12899. TREE_OPERAND (loc, 1), TREE_OPERAND (loc, 0));
  12900. }
  12901. /* ... fall through ... */
  12902. case COND_EXPR:
  12903. {
  12904. dw_loc_descr_ref lhs
  12905. = loc_descriptor_from_tree (TREE_OPERAND (loc, 1), 0, context);
  12906. dw_loc_list_ref rhs
  12907. = loc_list_from_tree (TREE_OPERAND (loc, 2), 0, context);
  12908. dw_loc_descr_ref bra_node, jump_node, tmp;
  12909. list_ret = loc_list_from_tree (TREE_OPERAND (loc, 0), 0, context);
  12910. if (list_ret == 0 || lhs == 0 || rhs == 0)
  12911. return 0;
  12912. bra_node = new_loc_descr (DW_OP_bra, 0, 0);
  12913. add_loc_descr_to_each (list_ret, bra_node);
  12914. add_loc_list (&list_ret, rhs);
  12915. jump_node = new_loc_descr (DW_OP_skip, 0, 0);
  12916. add_loc_descr_to_each (list_ret, jump_node);
  12917. add_loc_descr_to_each (list_ret, lhs);
  12918. bra_node->dw_loc_oprnd1.val_class = dw_val_class_loc;
  12919. bra_node->dw_loc_oprnd1.v.val_loc = lhs;
  12920. /* ??? Need a node to point the skip at. Use a nop. */
  12921. tmp = new_loc_descr (DW_OP_nop, 0, 0);
  12922. add_loc_descr_to_each (list_ret, tmp);
  12923. jump_node->dw_loc_oprnd1.val_class = dw_val_class_loc;
  12924. jump_node->dw_loc_oprnd1.v.val_loc = tmp;
  12925. }
  12926. break;
  12927. case FIX_TRUNC_EXPR:
  12928. return 0;
  12929. default:
  12930. /* Leave front-end specific codes as simply unknown. This comes
  12931. up, for instance, with the C STMT_EXPR. */
  12932. if ((unsigned int) TREE_CODE (loc)
  12933. >= (unsigned int) LAST_AND_UNUSED_TREE_CODE)
  12934. {
  12935. expansion_failed (loc, NULL_RTX,
  12936. "language specific tree node");
  12937. return 0;
  12938. }
  12939. #ifdef ENABLE_CHECKING
  12940. /* Otherwise this is a generic code; we should just lists all of
  12941. these explicitly. We forgot one. */
  12942. gcc_unreachable ();
  12943. #else
  12944. /* In a release build, we want to degrade gracefully: better to
  12945. generate incomplete debugging information than to crash. */
  12946. return NULL;
  12947. #endif
  12948. }
  12949. if (!ret && !list_ret)
  12950. return 0;
  12951. if (want_address == 2 && !have_address
  12952. && (dwarf_version >= 4 || !dwarf_strict))
  12953. {
  12954. if (int_size_in_bytes (TREE_TYPE (loc)) > DWARF2_ADDR_SIZE)
  12955. {
  12956. expansion_failed (loc, NULL_RTX,
  12957. "DWARF address size mismatch");
  12958. return 0;
  12959. }
  12960. if (ret)
  12961. add_loc_descr (&ret, new_loc_descr (DW_OP_stack_value, 0, 0));
  12962. else
  12963. add_loc_descr_to_each (list_ret,
  12964. new_loc_descr (DW_OP_stack_value, 0, 0));
  12965. have_address = 1;
  12966. }
  12967. /* Show if we can't fill the request for an address. */
  12968. if (want_address && !have_address)
  12969. {
  12970. expansion_failed (loc, NULL_RTX,
  12971. "Want address and only have value");
  12972. return 0;
  12973. }
  12974. gcc_assert (!ret || !list_ret);
  12975. /* If we've got an address and don't want one, dereference. */
  12976. if (!want_address && have_address)
  12977. {
  12978. HOST_WIDE_INT size = int_size_in_bytes (TREE_TYPE (loc));
  12979. if (size > DWARF2_ADDR_SIZE || size == -1)
  12980. {
  12981. expansion_failed (loc, NULL_RTX,
  12982. "DWARF address size mismatch");
  12983. return 0;
  12984. }
  12985. else if (size == DWARF2_ADDR_SIZE)
  12986. op = DW_OP_deref;
  12987. else
  12988. op = DW_OP_deref_size;
  12989. if (ret)
  12990. add_loc_descr (&ret, new_loc_descr (op, size, 0));
  12991. else
  12992. add_loc_descr_to_each (list_ret, new_loc_descr (op, size, 0));
  12993. }
  12994. if (ret)
  12995. list_ret = new_loc_list (ret, NULL, NULL, NULL);
  12996. return list_ret;
  12997. }
  12998. /* Same as above but return only single location expression. */
  12999. static dw_loc_descr_ref
  13000. loc_descriptor_from_tree (tree loc, int want_address,
  13001. const struct loc_descr_context *context)
  13002. {
  13003. dw_loc_list_ref ret = loc_list_from_tree (loc, want_address, context);
  13004. if (!ret)
  13005. return NULL;
  13006. if (ret->dw_loc_next)
  13007. {
  13008. expansion_failed (loc, NULL_RTX,
  13009. "Location list where only loc descriptor needed");
  13010. return NULL;
  13011. }
  13012. return ret->expr;
  13013. }
  13014. /* Given a value, round it up to the lowest multiple of `boundary'
  13015. which is not less than the value itself. */
  13016. static inline HOST_WIDE_INT
  13017. ceiling (HOST_WIDE_INT value, unsigned int boundary)
  13018. {
  13019. return (((value + boundary - 1) / boundary) * boundary);
  13020. }
  13021. /* Given a pointer to what is assumed to be a FIELD_DECL node, return a
  13022. pointer to the declared type for the relevant field variable, or return
  13023. `integer_type_node' if the given node turns out to be an
  13024. ERROR_MARK node. */
  13025. static inline tree
  13026. field_type (const_tree decl)
  13027. {
  13028. tree type;
  13029. if (TREE_CODE (decl) == ERROR_MARK)
  13030. return integer_type_node;
  13031. type = DECL_BIT_FIELD_TYPE (decl);
  13032. if (type == NULL_TREE)
  13033. type = TREE_TYPE (decl);
  13034. return type;
  13035. }
  13036. /* Given a pointer to a tree node, return the alignment in bits for
  13037. it, or else return BITS_PER_WORD if the node actually turns out to
  13038. be an ERROR_MARK node. */
  13039. static inline unsigned
  13040. simple_type_align_in_bits (const_tree type)
  13041. {
  13042. return (TREE_CODE (type) != ERROR_MARK) ? TYPE_ALIGN (type) : BITS_PER_WORD;
  13043. }
  13044. static inline unsigned
  13045. simple_decl_align_in_bits (const_tree decl)
  13046. {
  13047. return (TREE_CODE (decl) != ERROR_MARK) ? DECL_ALIGN (decl) : BITS_PER_WORD;
  13048. }
  13049. /* Return the result of rounding T up to ALIGN. */
  13050. static inline offset_int
  13051. round_up_to_align (const offset_int &t, unsigned int align)
  13052. {
  13053. return wi::udiv_trunc (t + align - 1, align) * align;
  13054. }
  13055. /* Given a pointer to a FIELD_DECL, compute and return the byte offset of the
  13056. lowest addressed byte of the "containing object" for the given FIELD_DECL,
  13057. or return 0 if we are unable to determine what that offset is, either
  13058. because the argument turns out to be a pointer to an ERROR_MARK node, or
  13059. because the offset is actually variable. (We can't handle the latter case
  13060. just yet). */
  13061. static HOST_WIDE_INT
  13062. field_byte_offset (const_tree decl)
  13063. {
  13064. offset_int object_offset_in_bits;
  13065. offset_int object_offset_in_bytes;
  13066. offset_int bitpos_int;
  13067. if (TREE_CODE (decl) == ERROR_MARK)
  13068. return 0;
  13069. gcc_assert (TREE_CODE (decl) == FIELD_DECL);
  13070. /* We cannot yet cope with fields whose positions are variable, so
  13071. for now, when we see such things, we simply return 0. Someday, we may
  13072. be able to handle such cases, but it will be damn difficult. */
  13073. if (TREE_CODE (bit_position (decl)) != INTEGER_CST)
  13074. return 0;
  13075. bitpos_int = wi::to_offset (bit_position (decl));
  13076. #ifdef PCC_BITFIELD_TYPE_MATTERS
  13077. if (PCC_BITFIELD_TYPE_MATTERS)
  13078. {
  13079. tree type;
  13080. tree field_size_tree;
  13081. offset_int deepest_bitpos;
  13082. offset_int field_size_in_bits;
  13083. unsigned int type_align_in_bits;
  13084. unsigned int decl_align_in_bits;
  13085. offset_int type_size_in_bits;
  13086. type = field_type (decl);
  13087. type_size_in_bits = offset_int_type_size_in_bits (type);
  13088. type_align_in_bits = simple_type_align_in_bits (type);
  13089. field_size_tree = DECL_SIZE (decl);
  13090. /* The size could be unspecified if there was an error, or for
  13091. a flexible array member. */
  13092. if (!field_size_tree)
  13093. field_size_tree = bitsize_zero_node;
  13094. /* If the size of the field is not constant, use the type size. */
  13095. if (TREE_CODE (field_size_tree) == INTEGER_CST)
  13096. field_size_in_bits = wi::to_offset (field_size_tree);
  13097. else
  13098. field_size_in_bits = type_size_in_bits;
  13099. decl_align_in_bits = simple_decl_align_in_bits (decl);
  13100. /* The GCC front-end doesn't make any attempt to keep track of the
  13101. starting bit offset (relative to the start of the containing
  13102. structure type) of the hypothetical "containing object" for a
  13103. bit-field. Thus, when computing the byte offset value for the
  13104. start of the "containing object" of a bit-field, we must deduce
  13105. this information on our own. This can be rather tricky to do in
  13106. some cases. For example, handling the following structure type
  13107. definition when compiling for an i386/i486 target (which only
  13108. aligns long long's to 32-bit boundaries) can be very tricky:
  13109. struct S { int field1; long long field2:31; };
  13110. Fortunately, there is a simple rule-of-thumb which can be used
  13111. in such cases. When compiling for an i386/i486, GCC will
  13112. allocate 8 bytes for the structure shown above. It decides to
  13113. do this based upon one simple rule for bit-field allocation.
  13114. GCC allocates each "containing object" for each bit-field at
  13115. the first (i.e. lowest addressed) legitimate alignment boundary
  13116. (based upon the required minimum alignment for the declared
  13117. type of the field) which it can possibly use, subject to the
  13118. condition that there is still enough available space remaining
  13119. in the containing object (when allocated at the selected point)
  13120. to fully accommodate all of the bits of the bit-field itself.
  13121. This simple rule makes it obvious why GCC allocates 8 bytes for
  13122. each object of the structure type shown above. When looking
  13123. for a place to allocate the "containing object" for `field2',
  13124. the compiler simply tries to allocate a 64-bit "containing
  13125. object" at each successive 32-bit boundary (starting at zero)
  13126. until it finds a place to allocate that 64- bit field such that
  13127. at least 31 contiguous (and previously unallocated) bits remain
  13128. within that selected 64 bit field. (As it turns out, for the
  13129. example above, the compiler finds it is OK to allocate the
  13130. "containing object" 64-bit field at bit-offset zero within the
  13131. structure type.)
  13132. Here we attempt to work backwards from the limited set of facts
  13133. we're given, and we try to deduce from those facts, where GCC
  13134. must have believed that the containing object started (within
  13135. the structure type). The value we deduce is then used (by the
  13136. callers of this routine) to generate DW_AT_location and
  13137. DW_AT_bit_offset attributes for fields (both bit-fields and, in
  13138. the case of DW_AT_location, regular fields as well). */
  13139. /* Figure out the bit-distance from the start of the structure to
  13140. the "deepest" bit of the bit-field. */
  13141. deepest_bitpos = bitpos_int + field_size_in_bits;
  13142. /* This is the tricky part. Use some fancy footwork to deduce
  13143. where the lowest addressed bit of the containing object must
  13144. be. */
  13145. object_offset_in_bits = deepest_bitpos - type_size_in_bits;
  13146. /* Round up to type_align by default. This works best for
  13147. bitfields. */
  13148. object_offset_in_bits
  13149. = round_up_to_align (object_offset_in_bits, type_align_in_bits);
  13150. if (wi::gtu_p (object_offset_in_bits, bitpos_int))
  13151. {
  13152. object_offset_in_bits = deepest_bitpos - type_size_in_bits;
  13153. /* Round up to decl_align instead. */
  13154. object_offset_in_bits
  13155. = round_up_to_align (object_offset_in_bits, decl_align_in_bits);
  13156. }
  13157. }
  13158. else
  13159. #endif /* PCC_BITFIELD_TYPE_MATTERS */
  13160. object_offset_in_bits = bitpos_int;
  13161. object_offset_in_bytes
  13162. = wi::lrshift (object_offset_in_bits, LOG2_BITS_PER_UNIT);
  13163. return object_offset_in_bytes.to_shwi ();
  13164. }
  13165. /* The following routines define various Dwarf attributes and any data
  13166. associated with them. */
  13167. /* Add a location description attribute value to a DIE.
  13168. This emits location attributes suitable for whole variables and
  13169. whole parameters. Note that the location attributes for struct fields are
  13170. generated by the routine `data_member_location_attribute' below. */
  13171. static inline void
  13172. add_AT_location_description (dw_die_ref die, enum dwarf_attribute attr_kind,
  13173. dw_loc_list_ref descr)
  13174. {
  13175. if (descr == 0)
  13176. return;
  13177. if (single_element_loc_list_p (descr))
  13178. add_AT_loc (die, attr_kind, descr->expr);
  13179. else
  13180. add_AT_loc_list (die, attr_kind, descr);
  13181. }
  13182. /* Add DW_AT_accessibility attribute to DIE if needed. */
  13183. static void
  13184. add_accessibility_attribute (dw_die_ref die, tree decl)
  13185. {
  13186. /* In DWARF3+ the default is DW_ACCESS_private only in DW_TAG_class_type
  13187. children, otherwise the default is DW_ACCESS_public. In DWARF2
  13188. the default has always been DW_ACCESS_public. */
  13189. if (TREE_PROTECTED (decl))
  13190. add_AT_unsigned (die, DW_AT_accessibility, DW_ACCESS_protected);
  13191. else if (TREE_PRIVATE (decl))
  13192. {
  13193. if (dwarf_version == 2
  13194. || die->die_parent == NULL
  13195. || die->die_parent->die_tag != DW_TAG_class_type)
  13196. add_AT_unsigned (die, DW_AT_accessibility, DW_ACCESS_private);
  13197. }
  13198. else if (dwarf_version > 2
  13199. && die->die_parent
  13200. && die->die_parent->die_tag == DW_TAG_class_type)
  13201. add_AT_unsigned (die, DW_AT_accessibility, DW_ACCESS_public);
  13202. }
  13203. /* Attach the specialized form of location attribute used for data members of
  13204. struct and union types. In the special case of a FIELD_DECL node which
  13205. represents a bit-field, the "offset" part of this special location
  13206. descriptor must indicate the distance in bytes from the lowest-addressed
  13207. byte of the containing struct or union type to the lowest-addressed byte of
  13208. the "containing object" for the bit-field. (See the `field_byte_offset'
  13209. function above).
  13210. For any given bit-field, the "containing object" is a hypothetical object
  13211. (of some integral or enum type) within which the given bit-field lives. The
  13212. type of this hypothetical "containing object" is always the same as the
  13213. declared type of the individual bit-field itself (for GCC anyway... the
  13214. DWARF spec doesn't actually mandate this). Note that it is the size (in
  13215. bytes) of the hypothetical "containing object" which will be given in the
  13216. DW_AT_byte_size attribute for this bit-field. (See the
  13217. `byte_size_attribute' function below.) It is also used when calculating the
  13218. value of the DW_AT_bit_offset attribute. (See the `bit_offset_attribute'
  13219. function below.) */
  13220. static void
  13221. add_data_member_location_attribute (dw_die_ref die, tree decl)
  13222. {
  13223. HOST_WIDE_INT offset;
  13224. dw_loc_descr_ref loc_descr = 0;
  13225. if (TREE_CODE (decl) == TREE_BINFO)
  13226. {
  13227. /* We're working on the TAG_inheritance for a base class. */
  13228. if (BINFO_VIRTUAL_P (decl) && is_cxx ())
  13229. {
  13230. /* For C++ virtual bases we can't just use BINFO_OFFSET, as they
  13231. aren't at a fixed offset from all (sub)objects of the same
  13232. type. We need to extract the appropriate offset from our
  13233. vtable. The following dwarf expression means
  13234. BaseAddr = ObAddr + *((*ObAddr) - Offset)
  13235. This is specific to the V3 ABI, of course. */
  13236. dw_loc_descr_ref tmp;
  13237. /* Make a copy of the object address. */
  13238. tmp = new_loc_descr (DW_OP_dup, 0, 0);
  13239. add_loc_descr (&loc_descr, tmp);
  13240. /* Extract the vtable address. */
  13241. tmp = new_loc_descr (DW_OP_deref, 0, 0);
  13242. add_loc_descr (&loc_descr, tmp);
  13243. /* Calculate the address of the offset. */
  13244. offset = tree_to_shwi (BINFO_VPTR_FIELD (decl));
  13245. gcc_assert (offset < 0);
  13246. tmp = int_loc_descriptor (-offset);
  13247. add_loc_descr (&loc_descr, tmp);
  13248. tmp = new_loc_descr (DW_OP_minus, 0, 0);
  13249. add_loc_descr (&loc_descr, tmp);
  13250. /* Extract the offset. */
  13251. tmp = new_loc_descr (DW_OP_deref, 0, 0);
  13252. add_loc_descr (&loc_descr, tmp);
  13253. /* Add it to the object address. */
  13254. tmp = new_loc_descr (DW_OP_plus, 0, 0);
  13255. add_loc_descr (&loc_descr, tmp);
  13256. }
  13257. else
  13258. offset = tree_to_shwi (BINFO_OFFSET (decl));
  13259. }
  13260. else
  13261. offset = field_byte_offset (decl);
  13262. if (! loc_descr)
  13263. {
  13264. if (dwarf_version > 2)
  13265. {
  13266. /* Don't need to output a location expression, just the constant. */
  13267. if (offset < 0)
  13268. add_AT_int (die, DW_AT_data_member_location, offset);
  13269. else
  13270. add_AT_unsigned (die, DW_AT_data_member_location, offset);
  13271. return;
  13272. }
  13273. else
  13274. {
  13275. enum dwarf_location_atom op;
  13276. /* The DWARF2 standard says that we should assume that the structure
  13277. address is already on the stack, so we can specify a structure
  13278. field address by using DW_OP_plus_uconst. */
  13279. op = DW_OP_plus_uconst;
  13280. loc_descr = new_loc_descr (op, offset, 0);
  13281. }
  13282. }
  13283. add_AT_loc (die, DW_AT_data_member_location, loc_descr);
  13284. }
  13285. /* Writes integer values to dw_vec_const array. */
  13286. static void
  13287. insert_int (HOST_WIDE_INT val, unsigned int size, unsigned char *dest)
  13288. {
  13289. while (size != 0)
  13290. {
  13291. *dest++ = val & 0xff;
  13292. val >>= 8;
  13293. --size;
  13294. }
  13295. }
  13296. /* Reads integers from dw_vec_const array. Inverse of insert_int. */
  13297. static HOST_WIDE_INT
  13298. extract_int (const unsigned char *src, unsigned int size)
  13299. {
  13300. HOST_WIDE_INT val = 0;
  13301. src += size;
  13302. while (size != 0)
  13303. {
  13304. val <<= 8;
  13305. val |= *--src & 0xff;
  13306. --size;
  13307. }
  13308. return val;
  13309. }
  13310. /* Writes wide_int values to dw_vec_const array. */
  13311. static void
  13312. insert_wide_int (const wide_int &val, unsigned char *dest, int elt_size)
  13313. {
  13314. int i;
  13315. if (elt_size <= HOST_BITS_PER_WIDE_INT/BITS_PER_UNIT)
  13316. {
  13317. insert_int ((HOST_WIDE_INT) val.elt (0), elt_size, dest);
  13318. return;
  13319. }
  13320. /* We'd have to extend this code to support odd sizes. */
  13321. gcc_assert (elt_size % (HOST_BITS_PER_WIDE_INT / BITS_PER_UNIT) == 0);
  13322. int n = elt_size / (HOST_BITS_PER_WIDE_INT / BITS_PER_UNIT);
  13323. if (WORDS_BIG_ENDIAN)
  13324. for (i = n - 1; i >= 0; i--)
  13325. {
  13326. insert_int ((HOST_WIDE_INT) val.elt (i), sizeof (HOST_WIDE_INT), dest);
  13327. dest += sizeof (HOST_WIDE_INT);
  13328. }
  13329. else
  13330. for (i = 0; i < n; i++)
  13331. {
  13332. insert_int ((HOST_WIDE_INT) val.elt (i), sizeof (HOST_WIDE_INT), dest);
  13333. dest += sizeof (HOST_WIDE_INT);
  13334. }
  13335. }
  13336. /* Writes floating point values to dw_vec_const array. */
  13337. static void
  13338. insert_float (const_rtx rtl, unsigned char *array)
  13339. {
  13340. REAL_VALUE_TYPE rv;
  13341. long val[4];
  13342. int i;
  13343. REAL_VALUE_FROM_CONST_DOUBLE (rv, rtl);
  13344. real_to_target (val, &rv, GET_MODE (rtl));
  13345. /* real_to_target puts 32-bit pieces in each long. Pack them. */
  13346. for (i = 0; i < GET_MODE_SIZE (GET_MODE (rtl)) / 4; i++)
  13347. {
  13348. insert_int (val[i], 4, array);
  13349. array += 4;
  13350. }
  13351. }
  13352. /* Attach a DW_AT_const_value attribute for a variable or a parameter which
  13353. does not have a "location" either in memory or in a register. These
  13354. things can arise in GNU C when a constant is passed as an actual parameter
  13355. to an inlined function. They can also arise in C++ where declared
  13356. constants do not necessarily get memory "homes". */
  13357. static bool
  13358. add_const_value_attribute (dw_die_ref die, rtx rtl)
  13359. {
  13360. switch (GET_CODE (rtl))
  13361. {
  13362. case CONST_INT:
  13363. {
  13364. HOST_WIDE_INT val = INTVAL (rtl);
  13365. if (val < 0)
  13366. add_AT_int (die, DW_AT_const_value, val);
  13367. else
  13368. add_AT_unsigned (die, DW_AT_const_value, (unsigned HOST_WIDE_INT) val);
  13369. }
  13370. return true;
  13371. case CONST_WIDE_INT:
  13372. add_AT_wide (die, DW_AT_const_value,
  13373. std::make_pair (rtl, GET_MODE (rtl)));
  13374. return true;
  13375. case CONST_DOUBLE:
  13376. /* Note that a CONST_DOUBLE rtx could represent either an integer or a
  13377. floating-point constant. A CONST_DOUBLE is used whenever the
  13378. constant requires more than one word in order to be adequately
  13379. represented. */
  13380. {
  13381. machine_mode mode = GET_MODE (rtl);
  13382. if (TARGET_SUPPORTS_WIDE_INT == 0 && !SCALAR_FLOAT_MODE_P (mode))
  13383. add_AT_double (die, DW_AT_const_value,
  13384. CONST_DOUBLE_HIGH (rtl), CONST_DOUBLE_LOW (rtl));
  13385. else
  13386. {
  13387. unsigned int length = GET_MODE_SIZE (mode);
  13388. unsigned char *array = ggc_vec_alloc<unsigned char> (length);
  13389. insert_float (rtl, array);
  13390. add_AT_vec (die, DW_AT_const_value, length / 4, 4, array);
  13391. }
  13392. }
  13393. return true;
  13394. case CONST_VECTOR:
  13395. {
  13396. machine_mode mode = GET_MODE (rtl);
  13397. unsigned int elt_size = GET_MODE_UNIT_SIZE (mode);
  13398. unsigned int length = CONST_VECTOR_NUNITS (rtl);
  13399. unsigned char *array
  13400. = ggc_vec_alloc<unsigned char> (length * elt_size);
  13401. unsigned int i;
  13402. unsigned char *p;
  13403. machine_mode imode = GET_MODE_INNER (mode);
  13404. switch (GET_MODE_CLASS (mode))
  13405. {
  13406. case MODE_VECTOR_INT:
  13407. for (i = 0, p = array; i < length; i++, p += elt_size)
  13408. {
  13409. rtx elt = CONST_VECTOR_ELT (rtl, i);
  13410. insert_wide_int (std::make_pair (elt, imode), p, elt_size);
  13411. }
  13412. break;
  13413. case MODE_VECTOR_FLOAT:
  13414. for (i = 0, p = array; i < length; i++, p += elt_size)
  13415. {
  13416. rtx elt = CONST_VECTOR_ELT (rtl, i);
  13417. insert_float (elt, p);
  13418. }
  13419. break;
  13420. default:
  13421. gcc_unreachable ();
  13422. }
  13423. add_AT_vec (die, DW_AT_const_value, length, elt_size, array);
  13424. }
  13425. return true;
  13426. case CONST_STRING:
  13427. if (dwarf_version >= 4 || !dwarf_strict)
  13428. {
  13429. dw_loc_descr_ref loc_result;
  13430. resolve_one_addr (&rtl);
  13431. rtl_addr:
  13432. loc_result = new_addr_loc_descr (rtl, dtprel_false);
  13433. add_loc_descr (&loc_result, new_loc_descr (DW_OP_stack_value, 0, 0));
  13434. add_AT_loc (die, DW_AT_location, loc_result);
  13435. vec_safe_push (used_rtx_array, rtl);
  13436. return true;
  13437. }
  13438. return false;
  13439. case CONST:
  13440. if (CONSTANT_P (XEXP (rtl, 0)))
  13441. return add_const_value_attribute (die, XEXP (rtl, 0));
  13442. /* FALLTHROUGH */
  13443. case SYMBOL_REF:
  13444. if (!const_ok_for_output (rtl))
  13445. return false;
  13446. case LABEL_REF:
  13447. if (dwarf_version >= 4 || !dwarf_strict)
  13448. goto rtl_addr;
  13449. return false;
  13450. case PLUS:
  13451. /* In cases where an inlined instance of an inline function is passed
  13452. the address of an `auto' variable (which is local to the caller) we
  13453. can get a situation where the DECL_RTL of the artificial local
  13454. variable (for the inlining) which acts as a stand-in for the
  13455. corresponding formal parameter (of the inline function) will look
  13456. like (plus:SI (reg:SI FRAME_PTR) (const_int ...)). This is not
  13457. exactly a compile-time constant expression, but it isn't the address
  13458. of the (artificial) local variable either. Rather, it represents the
  13459. *value* which the artificial local variable always has during its
  13460. lifetime. We currently have no way to represent such quasi-constant
  13461. values in Dwarf, so for now we just punt and generate nothing. */
  13462. return false;
  13463. case HIGH:
  13464. case CONST_FIXED:
  13465. return false;
  13466. case MEM:
  13467. if (GET_CODE (XEXP (rtl, 0)) == CONST_STRING
  13468. && MEM_READONLY_P (rtl)
  13469. && GET_MODE (rtl) == BLKmode)
  13470. {
  13471. add_AT_string (die, DW_AT_const_value, XSTR (XEXP (rtl, 0), 0));
  13472. return true;
  13473. }
  13474. return false;
  13475. default:
  13476. /* No other kinds of rtx should be possible here. */
  13477. gcc_unreachable ();
  13478. }
  13479. return false;
  13480. }
  13481. /* Determine whether the evaluation of EXPR references any variables
  13482. or functions which aren't otherwise used (and therefore may not be
  13483. output). */
  13484. static tree
  13485. reference_to_unused (tree * tp, int * walk_subtrees,
  13486. void * data ATTRIBUTE_UNUSED)
  13487. {
  13488. if (! EXPR_P (*tp) && ! CONSTANT_CLASS_P (*tp))
  13489. *walk_subtrees = 0;
  13490. if (DECL_P (*tp) && ! TREE_PUBLIC (*tp) && ! TREE_USED (*tp)
  13491. && ! TREE_ASM_WRITTEN (*tp))
  13492. return *tp;
  13493. /* ??? The C++ FE emits debug information for using decls, so
  13494. putting gcc_unreachable here falls over. See PR31899. For now
  13495. be conservative. */
  13496. else if (!symtab->global_info_ready
  13497. && (TREE_CODE (*tp) == VAR_DECL || TREE_CODE (*tp) == FUNCTION_DECL))
  13498. return *tp;
  13499. else if (TREE_CODE (*tp) == VAR_DECL)
  13500. {
  13501. varpool_node *node = varpool_node::get (*tp);
  13502. if (!node || !node->definition)
  13503. return *tp;
  13504. }
  13505. else if (TREE_CODE (*tp) == FUNCTION_DECL
  13506. && (!DECL_EXTERNAL (*tp) || DECL_DECLARED_INLINE_P (*tp)))
  13507. {
  13508. /* The call graph machinery must have finished analyzing,
  13509. optimizing and gimplifying the CU by now.
  13510. So if *TP has no call graph node associated
  13511. to it, it means *TP will not be emitted. */
  13512. if (!cgraph_node::get (*tp))
  13513. return *tp;
  13514. }
  13515. else if (TREE_CODE (*tp) == STRING_CST && !TREE_ASM_WRITTEN (*tp))
  13516. return *tp;
  13517. return NULL_TREE;
  13518. }
  13519. /* Generate an RTL constant from a decl initializer INIT with decl type TYPE,
  13520. for use in a later add_const_value_attribute call. */
  13521. static rtx
  13522. rtl_for_decl_init (tree init, tree type)
  13523. {
  13524. rtx rtl = NULL_RTX;
  13525. STRIP_NOPS (init);
  13526. /* If a variable is initialized with a string constant without embedded
  13527. zeros, build CONST_STRING. */
  13528. if (TREE_CODE (init) == STRING_CST && TREE_CODE (type) == ARRAY_TYPE)
  13529. {
  13530. tree enttype = TREE_TYPE (type);
  13531. tree domain = TYPE_DOMAIN (type);
  13532. machine_mode mode = TYPE_MODE (enttype);
  13533. if (GET_MODE_CLASS (mode) == MODE_INT && GET_MODE_SIZE (mode) == 1
  13534. && domain
  13535. && integer_zerop (TYPE_MIN_VALUE (domain))
  13536. && compare_tree_int (TYPE_MAX_VALUE (domain),
  13537. TREE_STRING_LENGTH (init) - 1) == 0
  13538. && ((size_t) TREE_STRING_LENGTH (init)
  13539. == strlen (TREE_STRING_POINTER (init)) + 1))
  13540. {
  13541. rtl = gen_rtx_CONST_STRING (VOIDmode,
  13542. ggc_strdup (TREE_STRING_POINTER (init)));
  13543. rtl = gen_rtx_MEM (BLKmode, rtl);
  13544. MEM_READONLY_P (rtl) = 1;
  13545. }
  13546. }
  13547. /* Other aggregates, and complex values, could be represented using
  13548. CONCAT: FIXME! */
  13549. else if (AGGREGATE_TYPE_P (type)
  13550. || (TREE_CODE (init) == VIEW_CONVERT_EXPR
  13551. && AGGREGATE_TYPE_P (TREE_TYPE (TREE_OPERAND (init, 0))))
  13552. || TREE_CODE (type) == COMPLEX_TYPE)
  13553. ;
  13554. /* Vectors only work if their mode is supported by the target.
  13555. FIXME: generic vectors ought to work too. */
  13556. else if (TREE_CODE (type) == VECTOR_TYPE
  13557. && !VECTOR_MODE_P (TYPE_MODE (type)))
  13558. ;
  13559. /* If the initializer is something that we know will expand into an
  13560. immediate RTL constant, expand it now. We must be careful not to
  13561. reference variables which won't be output. */
  13562. else if (initializer_constant_valid_p (init, type)
  13563. && ! walk_tree (&init, reference_to_unused, NULL, NULL))
  13564. {
  13565. /* Convert vector CONSTRUCTOR initializers to VECTOR_CST if
  13566. possible. */
  13567. if (TREE_CODE (type) == VECTOR_TYPE)
  13568. switch (TREE_CODE (init))
  13569. {
  13570. case VECTOR_CST:
  13571. break;
  13572. case CONSTRUCTOR:
  13573. if (TREE_CONSTANT (init))
  13574. {
  13575. vec<constructor_elt, va_gc> *elts = CONSTRUCTOR_ELTS (init);
  13576. bool constant_p = true;
  13577. tree value;
  13578. unsigned HOST_WIDE_INT ix;
  13579. /* Even when ctor is constant, it might contain non-*_CST
  13580. elements (e.g. { 1.0/0.0 - 1.0/0.0, 0.0 }) and those don't
  13581. belong into VECTOR_CST nodes. */
  13582. FOR_EACH_CONSTRUCTOR_VALUE (elts, ix, value)
  13583. if (!CONSTANT_CLASS_P (value))
  13584. {
  13585. constant_p = false;
  13586. break;
  13587. }
  13588. if (constant_p)
  13589. {
  13590. init = build_vector_from_ctor (type, elts);
  13591. break;
  13592. }
  13593. }
  13594. /* FALLTHRU */
  13595. default:
  13596. return NULL;
  13597. }
  13598. rtl = expand_expr (init, NULL_RTX, VOIDmode, EXPAND_INITIALIZER);
  13599. /* If expand_expr returns a MEM, it wasn't immediate. */
  13600. gcc_assert (!rtl || !MEM_P (rtl));
  13601. }
  13602. return rtl;
  13603. }
  13604. /* Generate RTL for the variable DECL to represent its location. */
  13605. static rtx
  13606. rtl_for_decl_location (tree decl)
  13607. {
  13608. rtx rtl;
  13609. /* Here we have to decide where we are going to say the parameter "lives"
  13610. (as far as the debugger is concerned). We only have a couple of
  13611. choices. GCC provides us with DECL_RTL and with DECL_INCOMING_RTL.
  13612. DECL_RTL normally indicates where the parameter lives during most of the
  13613. activation of the function. If optimization is enabled however, this
  13614. could be either NULL or else a pseudo-reg. Both of those cases indicate
  13615. that the parameter doesn't really live anywhere (as far as the code
  13616. generation parts of GCC are concerned) during most of the function's
  13617. activation. That will happen (for example) if the parameter is never
  13618. referenced within the function.
  13619. We could just generate a location descriptor here for all non-NULL
  13620. non-pseudo values of DECL_RTL and ignore all of the rest, but we can be
  13621. a little nicer than that if we also consider DECL_INCOMING_RTL in cases
  13622. where DECL_RTL is NULL or is a pseudo-reg.
  13623. Note however that we can only get away with using DECL_INCOMING_RTL as
  13624. a backup substitute for DECL_RTL in certain limited cases. In cases
  13625. where DECL_ARG_TYPE (decl) indicates the same type as TREE_TYPE (decl),
  13626. we can be sure that the parameter was passed using the same type as it is
  13627. declared to have within the function, and that its DECL_INCOMING_RTL
  13628. points us to a place where a value of that type is passed.
  13629. In cases where DECL_ARG_TYPE (decl) and TREE_TYPE (decl) are different,
  13630. we cannot (in general) use DECL_INCOMING_RTL as a substitute for DECL_RTL
  13631. because in these cases DECL_INCOMING_RTL points us to a value of some
  13632. type which is *different* from the type of the parameter itself. Thus,
  13633. if we tried to use DECL_INCOMING_RTL to generate a location attribute in
  13634. such cases, the debugger would end up (for example) trying to fetch a
  13635. `float' from a place which actually contains the first part of a
  13636. `double'. That would lead to really incorrect and confusing
  13637. output at debug-time.
  13638. So, in general, we *do not* use DECL_INCOMING_RTL as a backup for DECL_RTL
  13639. in cases where DECL_ARG_TYPE (decl) != TREE_TYPE (decl). There
  13640. are a couple of exceptions however. On little-endian machines we can
  13641. get away with using DECL_INCOMING_RTL even when DECL_ARG_TYPE (decl) is
  13642. not the same as TREE_TYPE (decl), but only when DECL_ARG_TYPE (decl) is
  13643. an integral type that is smaller than TREE_TYPE (decl). These cases arise
  13644. when (on a little-endian machine) a non-prototyped function has a
  13645. parameter declared to be of type `short' or `char'. In such cases,
  13646. TREE_TYPE (decl) will be `short' or `char', DECL_ARG_TYPE (decl) will
  13647. be `int', and DECL_INCOMING_RTL will point to the lowest-order byte of the
  13648. passed `int' value. If the debugger then uses that address to fetch
  13649. a `short' or a `char' (on a little-endian machine) the result will be
  13650. the correct data, so we allow for such exceptional cases below.
  13651. Note that our goal here is to describe the place where the given formal
  13652. parameter lives during most of the function's activation (i.e. between the
  13653. end of the prologue and the start of the epilogue). We'll do that as best
  13654. as we can. Note however that if the given formal parameter is modified
  13655. sometime during the execution of the function, then a stack backtrace (at
  13656. debug-time) will show the function as having been called with the *new*
  13657. value rather than the value which was originally passed in. This happens
  13658. rarely enough that it is not a major problem, but it *is* a problem, and
  13659. I'd like to fix it.
  13660. A future version of dwarf2out.c may generate two additional attributes for
  13661. any given DW_TAG_formal_parameter DIE which will describe the "passed
  13662. type" and the "passed location" for the given formal parameter in addition
  13663. to the attributes we now generate to indicate the "declared type" and the
  13664. "active location" for each parameter. This additional set of attributes
  13665. could be used by debuggers for stack backtraces. Separately, note that
  13666. sometimes DECL_RTL can be NULL and DECL_INCOMING_RTL can be NULL also.
  13667. This happens (for example) for inlined-instances of inline function formal
  13668. parameters which are never referenced. This really shouldn't be
  13669. happening. All PARM_DECL nodes should get valid non-NULL
  13670. DECL_INCOMING_RTL values. FIXME. */
  13671. /* Use DECL_RTL as the "location" unless we find something better. */
  13672. rtl = DECL_RTL_IF_SET (decl);
  13673. /* When generating abstract instances, ignore everything except
  13674. constants, symbols living in memory, and symbols living in
  13675. fixed registers. */
  13676. if (! reload_completed)
  13677. {
  13678. if (rtl
  13679. && (CONSTANT_P (rtl)
  13680. || (MEM_P (rtl)
  13681. && CONSTANT_P (XEXP (rtl, 0)))
  13682. || (REG_P (rtl)
  13683. && TREE_CODE (decl) == VAR_DECL
  13684. && TREE_STATIC (decl))))
  13685. {
  13686. rtl = targetm.delegitimize_address (rtl);
  13687. return rtl;
  13688. }
  13689. rtl = NULL_RTX;
  13690. }
  13691. else if (TREE_CODE (decl) == PARM_DECL)
  13692. {
  13693. if (rtl == NULL_RTX
  13694. || is_pseudo_reg (rtl)
  13695. || (MEM_P (rtl)
  13696. && is_pseudo_reg (XEXP (rtl, 0))
  13697. && DECL_INCOMING_RTL (decl)
  13698. && MEM_P (DECL_INCOMING_RTL (decl))
  13699. && GET_MODE (rtl) == GET_MODE (DECL_INCOMING_RTL (decl))))
  13700. {
  13701. tree declared_type = TREE_TYPE (decl);
  13702. tree passed_type = DECL_ARG_TYPE (decl);
  13703. machine_mode dmode = TYPE_MODE (declared_type);
  13704. machine_mode pmode = TYPE_MODE (passed_type);
  13705. /* This decl represents a formal parameter which was optimized out.
  13706. Note that DECL_INCOMING_RTL may be NULL in here, but we handle
  13707. all cases where (rtl == NULL_RTX) just below. */
  13708. if (dmode == pmode)
  13709. rtl = DECL_INCOMING_RTL (decl);
  13710. else if ((rtl == NULL_RTX || is_pseudo_reg (rtl))
  13711. && SCALAR_INT_MODE_P (dmode)
  13712. && GET_MODE_SIZE (dmode) <= GET_MODE_SIZE (pmode)
  13713. && DECL_INCOMING_RTL (decl))
  13714. {
  13715. rtx inc = DECL_INCOMING_RTL (decl);
  13716. if (REG_P (inc))
  13717. rtl = inc;
  13718. else if (MEM_P (inc))
  13719. {
  13720. if (BYTES_BIG_ENDIAN)
  13721. rtl = adjust_address_nv (inc, dmode,
  13722. GET_MODE_SIZE (pmode)
  13723. - GET_MODE_SIZE (dmode));
  13724. else
  13725. rtl = inc;
  13726. }
  13727. }
  13728. }
  13729. /* If the parm was passed in registers, but lives on the stack, then
  13730. make a big endian correction if the mode of the type of the
  13731. parameter is not the same as the mode of the rtl. */
  13732. /* ??? This is the same series of checks that are made in dbxout.c before
  13733. we reach the big endian correction code there. It isn't clear if all
  13734. of these checks are necessary here, but keeping them all is the safe
  13735. thing to do. */
  13736. else if (MEM_P (rtl)
  13737. && XEXP (rtl, 0) != const0_rtx
  13738. && ! CONSTANT_P (XEXP (rtl, 0))
  13739. /* Not passed in memory. */
  13740. && !MEM_P (DECL_INCOMING_RTL (decl))
  13741. /* Not passed by invisible reference. */
  13742. && (!REG_P (XEXP (rtl, 0))
  13743. || REGNO (XEXP (rtl, 0)) == HARD_FRAME_POINTER_REGNUM
  13744. || REGNO (XEXP (rtl, 0)) == STACK_POINTER_REGNUM
  13745. #if !HARD_FRAME_POINTER_IS_ARG_POINTER
  13746. || REGNO (XEXP (rtl, 0)) == ARG_POINTER_REGNUM
  13747. #endif
  13748. )
  13749. /* Big endian correction check. */
  13750. && BYTES_BIG_ENDIAN
  13751. && TYPE_MODE (TREE_TYPE (decl)) != GET_MODE (rtl)
  13752. && (GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (decl)))
  13753. < UNITS_PER_WORD))
  13754. {
  13755. machine_mode addr_mode = get_address_mode (rtl);
  13756. int offset = (UNITS_PER_WORD
  13757. - GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (decl))));
  13758. rtl = gen_rtx_MEM (TYPE_MODE (TREE_TYPE (decl)),
  13759. plus_constant (addr_mode, XEXP (rtl, 0), offset));
  13760. }
  13761. }
  13762. else if (TREE_CODE (decl) == VAR_DECL
  13763. && rtl
  13764. && MEM_P (rtl)
  13765. && GET_MODE (rtl) != TYPE_MODE (TREE_TYPE (decl))
  13766. && BYTES_BIG_ENDIAN)
  13767. {
  13768. machine_mode addr_mode = get_address_mode (rtl);
  13769. int rsize = GET_MODE_SIZE (GET_MODE (rtl));
  13770. int dsize = GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (decl)));
  13771. /* If a variable is declared "register" yet is smaller than
  13772. a register, then if we store the variable to memory, it
  13773. looks like we're storing a register-sized value, when in
  13774. fact we are not. We need to adjust the offset of the
  13775. storage location to reflect the actual value's bytes,
  13776. else gdb will not be able to display it. */
  13777. if (rsize > dsize)
  13778. rtl = gen_rtx_MEM (TYPE_MODE (TREE_TYPE (decl)),
  13779. plus_constant (addr_mode, XEXP (rtl, 0),
  13780. rsize - dsize));
  13781. }
  13782. /* A variable with no DECL_RTL but a DECL_INITIAL is a compile-time constant,
  13783. and will have been substituted directly into all expressions that use it.
  13784. C does not have such a concept, but C++ and other languages do. */
  13785. if (!rtl && TREE_CODE (decl) == VAR_DECL && DECL_INITIAL (decl))
  13786. rtl = rtl_for_decl_init (DECL_INITIAL (decl), TREE_TYPE (decl));
  13787. if (rtl)
  13788. rtl = targetm.delegitimize_address (rtl);
  13789. /* If we don't look past the constant pool, we risk emitting a
  13790. reference to a constant pool entry that isn't referenced from
  13791. code, and thus is not emitted. */
  13792. if (rtl)
  13793. rtl = avoid_constant_pool_reference (rtl);
  13794. /* Try harder to get a rtl. If this symbol ends up not being emitted
  13795. in the current CU, resolve_addr will remove the expression referencing
  13796. it. */
  13797. if (rtl == NULL_RTX
  13798. && TREE_CODE (decl) == VAR_DECL
  13799. && !DECL_EXTERNAL (decl)
  13800. && TREE_STATIC (decl)
  13801. && DECL_NAME (decl)
  13802. && !DECL_HARD_REGISTER (decl)
  13803. && DECL_MODE (decl) != VOIDmode)
  13804. {
  13805. rtl = make_decl_rtl_for_debug (decl);
  13806. if (!MEM_P (rtl)
  13807. || GET_CODE (XEXP (rtl, 0)) != SYMBOL_REF
  13808. || SYMBOL_REF_DECL (XEXP (rtl, 0)) != decl)
  13809. rtl = NULL_RTX;
  13810. }
  13811. return rtl;
  13812. }
  13813. /* Check whether decl is a Fortran COMMON symbol. If not, NULL_TREE is
  13814. returned. If so, the decl for the COMMON block is returned, and the
  13815. value is the offset into the common block for the symbol. */
  13816. static tree
  13817. fortran_common (tree decl, HOST_WIDE_INT *value)
  13818. {
  13819. tree val_expr, cvar;
  13820. machine_mode mode;
  13821. HOST_WIDE_INT bitsize, bitpos;
  13822. tree offset;
  13823. int unsignedp, volatilep = 0;
  13824. /* If the decl isn't a VAR_DECL, or if it isn't static, or if
  13825. it does not have a value (the offset into the common area), or if it
  13826. is thread local (as opposed to global) then it isn't common, and shouldn't
  13827. be handled as such. */
  13828. if (TREE_CODE (decl) != VAR_DECL
  13829. || !TREE_STATIC (decl)
  13830. || !DECL_HAS_VALUE_EXPR_P (decl)
  13831. || !is_fortran ())
  13832. return NULL_TREE;
  13833. val_expr = DECL_VALUE_EXPR (decl);
  13834. if (TREE_CODE (val_expr) != COMPONENT_REF)
  13835. return NULL_TREE;
  13836. cvar = get_inner_reference (val_expr, &bitsize, &bitpos, &offset,
  13837. &mode, &unsignedp, &volatilep, true);
  13838. if (cvar == NULL_TREE
  13839. || TREE_CODE (cvar) != VAR_DECL
  13840. || DECL_ARTIFICIAL (cvar)
  13841. || !TREE_PUBLIC (cvar))
  13842. return NULL_TREE;
  13843. *value = 0;
  13844. if (offset != NULL)
  13845. {
  13846. if (!tree_fits_shwi_p (offset))
  13847. return NULL_TREE;
  13848. *value = tree_to_shwi (offset);
  13849. }
  13850. if (bitpos != 0)
  13851. *value += bitpos / BITS_PER_UNIT;
  13852. return cvar;
  13853. }
  13854. /* Generate *either* a DW_AT_location attribute or else a DW_AT_const_value
  13855. data attribute for a variable or a parameter. We generate the
  13856. DW_AT_const_value attribute only in those cases where the given variable
  13857. or parameter does not have a true "location" either in memory or in a
  13858. register. This can happen (for example) when a constant is passed as an
  13859. actual argument in a call to an inline function. (It's possible that
  13860. these things can crop up in other ways also.) Note that one type of
  13861. constant value which can be passed into an inlined function is a constant
  13862. pointer. This can happen for example if an actual argument in an inlined
  13863. function call evaluates to a compile-time constant address.
  13864. CACHE_P is true if it is worth caching the location list for DECL,
  13865. so that future calls can reuse it rather than regenerate it from scratch.
  13866. This is true for BLOCK_NONLOCALIZED_VARS in inlined subroutines,
  13867. since we will need to refer to them each time the function is inlined. */
  13868. static bool
  13869. add_location_or_const_value_attribute (dw_die_ref die, tree decl, bool cache_p,
  13870. enum dwarf_attribute attr)
  13871. {
  13872. rtx rtl;
  13873. dw_loc_list_ref list;
  13874. var_loc_list *loc_list;
  13875. cached_dw_loc_list *cache;
  13876. if (TREE_CODE (decl) == ERROR_MARK)
  13877. return false;
  13878. gcc_assert (TREE_CODE (decl) == VAR_DECL || TREE_CODE (decl) == PARM_DECL
  13879. || TREE_CODE (decl) == RESULT_DECL);
  13880. /* Try to get some constant RTL for this decl, and use that as the value of
  13881. the location. */
  13882. rtl = rtl_for_decl_location (decl);
  13883. if (rtl && (CONSTANT_P (rtl) || GET_CODE (rtl) == CONST_STRING)
  13884. && add_const_value_attribute (die, rtl))
  13885. return true;
  13886. /* See if we have single element location list that is equivalent to
  13887. a constant value. That way we are better to use add_const_value_attribute
  13888. rather than expanding constant value equivalent. */
  13889. loc_list = lookup_decl_loc (decl);
  13890. if (loc_list
  13891. && loc_list->first
  13892. && loc_list->first->next == NULL
  13893. && NOTE_P (loc_list->first->loc)
  13894. && NOTE_VAR_LOCATION (loc_list->first->loc)
  13895. && NOTE_VAR_LOCATION_LOC (loc_list->first->loc))
  13896. {
  13897. struct var_loc_node *node;
  13898. node = loc_list->first;
  13899. rtl = NOTE_VAR_LOCATION_LOC (node->loc);
  13900. if (GET_CODE (rtl) == EXPR_LIST)
  13901. rtl = XEXP (rtl, 0);
  13902. if ((CONSTANT_P (rtl) || GET_CODE (rtl) == CONST_STRING)
  13903. && add_const_value_attribute (die, rtl))
  13904. return true;
  13905. }
  13906. /* If this decl is from BLOCK_NONLOCALIZED_VARS, we might need its
  13907. list several times. See if we've already cached the contents. */
  13908. list = NULL;
  13909. if (loc_list == NULL || cached_dw_loc_list_table == NULL)
  13910. cache_p = false;
  13911. if (cache_p)
  13912. {
  13913. cache = cached_dw_loc_list_table->find_with_hash (decl, DECL_UID (decl));
  13914. if (cache)
  13915. list = cache->loc_list;
  13916. }
  13917. if (list == NULL)
  13918. {
  13919. list = loc_list_from_tree (decl, decl_by_reference_p (decl) ? 0 : 2,
  13920. NULL);
  13921. /* It is usually worth caching this result if the decl is from
  13922. BLOCK_NONLOCALIZED_VARS and if the list has at least two elements. */
  13923. if (cache_p && list && list->dw_loc_next)
  13924. {
  13925. cached_dw_loc_list **slot
  13926. = cached_dw_loc_list_table->find_slot_with_hash (decl,
  13927. DECL_UID (decl),
  13928. INSERT);
  13929. cache = ggc_cleared_alloc<cached_dw_loc_list> ();
  13930. cache->decl_id = DECL_UID (decl);
  13931. cache->loc_list = list;
  13932. *slot = cache;
  13933. }
  13934. }
  13935. if (list)
  13936. {
  13937. add_AT_location_description (die, attr, list);
  13938. return true;
  13939. }
  13940. /* None of that worked, so it must not really have a location;
  13941. try adding a constant value attribute from the DECL_INITIAL. */
  13942. return tree_add_const_value_attribute_for_decl (die, decl);
  13943. }
  13944. /* Add VARIABLE and DIE into deferred locations list. */
  13945. static void
  13946. defer_location (tree variable, dw_die_ref die)
  13947. {
  13948. deferred_locations entry;
  13949. entry.variable = variable;
  13950. entry.die = die;
  13951. vec_safe_push (deferred_locations_list, entry);
  13952. }
  13953. /* Helper function for tree_add_const_value_attribute. Natively encode
  13954. initializer INIT into an array. Return true if successful. */
  13955. static bool
  13956. native_encode_initializer (tree init, unsigned char *array, int size)
  13957. {
  13958. tree type;
  13959. if (init == NULL_TREE)
  13960. return false;
  13961. STRIP_NOPS (init);
  13962. switch (TREE_CODE (init))
  13963. {
  13964. case STRING_CST:
  13965. type = TREE_TYPE (init);
  13966. if (TREE_CODE (type) == ARRAY_TYPE)
  13967. {
  13968. tree enttype = TREE_TYPE (type);
  13969. machine_mode mode = TYPE_MODE (enttype);
  13970. if (GET_MODE_CLASS (mode) != MODE_INT || GET_MODE_SIZE (mode) != 1)
  13971. return false;
  13972. if (int_size_in_bytes (type) != size)
  13973. return false;
  13974. if (size > TREE_STRING_LENGTH (init))
  13975. {
  13976. memcpy (array, TREE_STRING_POINTER (init),
  13977. TREE_STRING_LENGTH (init));
  13978. memset (array + TREE_STRING_LENGTH (init),
  13979. '\0', size - TREE_STRING_LENGTH (init));
  13980. }
  13981. else
  13982. memcpy (array, TREE_STRING_POINTER (init), size);
  13983. return true;
  13984. }
  13985. return false;
  13986. case CONSTRUCTOR:
  13987. type = TREE_TYPE (init);
  13988. if (int_size_in_bytes (type) != size)
  13989. return false;
  13990. if (TREE_CODE (type) == ARRAY_TYPE)
  13991. {
  13992. HOST_WIDE_INT min_index;
  13993. unsigned HOST_WIDE_INT cnt;
  13994. int curpos = 0, fieldsize;
  13995. constructor_elt *ce;
  13996. if (TYPE_DOMAIN (type) == NULL_TREE
  13997. || !tree_fits_shwi_p (TYPE_MIN_VALUE (TYPE_DOMAIN (type))))
  13998. return false;
  13999. fieldsize = int_size_in_bytes (TREE_TYPE (type));
  14000. if (fieldsize <= 0)
  14001. return false;
  14002. min_index = tree_to_shwi (TYPE_MIN_VALUE (TYPE_DOMAIN (type)));
  14003. memset (array, '\0', size);
  14004. FOR_EACH_VEC_SAFE_ELT (CONSTRUCTOR_ELTS (init), cnt, ce)
  14005. {
  14006. tree val = ce->value;
  14007. tree index = ce->index;
  14008. int pos = curpos;
  14009. if (index && TREE_CODE (index) == RANGE_EXPR)
  14010. pos = (tree_to_shwi (TREE_OPERAND (index, 0)) - min_index)
  14011. * fieldsize;
  14012. else if (index)
  14013. pos = (tree_to_shwi (index) - min_index) * fieldsize;
  14014. if (val)
  14015. {
  14016. STRIP_NOPS (val);
  14017. if (!native_encode_initializer (val, array + pos, fieldsize))
  14018. return false;
  14019. }
  14020. curpos = pos + fieldsize;
  14021. if (index && TREE_CODE (index) == RANGE_EXPR)
  14022. {
  14023. int count = tree_to_shwi (TREE_OPERAND (index, 1))
  14024. - tree_to_shwi (TREE_OPERAND (index, 0));
  14025. while (count-- > 0)
  14026. {
  14027. if (val)
  14028. memcpy (array + curpos, array + pos, fieldsize);
  14029. curpos += fieldsize;
  14030. }
  14031. }
  14032. gcc_assert (curpos <= size);
  14033. }
  14034. return true;
  14035. }
  14036. else if (TREE_CODE (type) == RECORD_TYPE
  14037. || TREE_CODE (type) == UNION_TYPE)
  14038. {
  14039. tree field = NULL_TREE;
  14040. unsigned HOST_WIDE_INT cnt;
  14041. constructor_elt *ce;
  14042. if (int_size_in_bytes (type) != size)
  14043. return false;
  14044. if (TREE_CODE (type) == RECORD_TYPE)
  14045. field = TYPE_FIELDS (type);
  14046. FOR_EACH_VEC_SAFE_ELT (CONSTRUCTOR_ELTS (init), cnt, ce)
  14047. {
  14048. tree val = ce->value;
  14049. int pos, fieldsize;
  14050. if (ce->index != 0)
  14051. field = ce->index;
  14052. if (val)
  14053. STRIP_NOPS (val);
  14054. if (field == NULL_TREE || DECL_BIT_FIELD (field))
  14055. return false;
  14056. if (TREE_CODE (TREE_TYPE (field)) == ARRAY_TYPE
  14057. && TYPE_DOMAIN (TREE_TYPE (field))
  14058. && ! TYPE_MAX_VALUE (TYPE_DOMAIN (TREE_TYPE (field))))
  14059. return false;
  14060. else if (DECL_SIZE_UNIT (field) == NULL_TREE
  14061. || !tree_fits_shwi_p (DECL_SIZE_UNIT (field)))
  14062. return false;
  14063. fieldsize = tree_to_shwi (DECL_SIZE_UNIT (field));
  14064. pos = int_byte_position (field);
  14065. gcc_assert (pos + fieldsize <= size);
  14066. if (val
  14067. && !native_encode_initializer (val, array + pos, fieldsize))
  14068. return false;
  14069. }
  14070. return true;
  14071. }
  14072. return false;
  14073. case VIEW_CONVERT_EXPR:
  14074. case NON_LVALUE_EXPR:
  14075. return native_encode_initializer (TREE_OPERAND (init, 0), array, size);
  14076. default:
  14077. return native_encode_expr (init, array, size) == size;
  14078. }
  14079. }
  14080. /* Attach a DW_AT_const_value attribute to DIE. The value of the
  14081. attribute is the const value T. */
  14082. static bool
  14083. tree_add_const_value_attribute (dw_die_ref die, tree t)
  14084. {
  14085. tree init;
  14086. tree type = TREE_TYPE (t);
  14087. rtx rtl;
  14088. if (!t || !TREE_TYPE (t) || TREE_TYPE (t) == error_mark_node)
  14089. return false;
  14090. init = t;
  14091. gcc_assert (!DECL_P (init));
  14092. rtl = rtl_for_decl_init (init, type);
  14093. if (rtl)
  14094. return add_const_value_attribute (die, rtl);
  14095. /* If the host and target are sane, try harder. */
  14096. else if (CHAR_BIT == 8 && BITS_PER_UNIT == 8
  14097. && initializer_constant_valid_p (init, type))
  14098. {
  14099. HOST_WIDE_INT size = int_size_in_bytes (TREE_TYPE (init));
  14100. if (size > 0 && (int) size == size)
  14101. {
  14102. unsigned char *array = ggc_cleared_vec_alloc<unsigned char> (size);
  14103. if (native_encode_initializer (init, array, size))
  14104. {
  14105. add_AT_vec (die, DW_AT_const_value, size, 1, array);
  14106. return true;
  14107. }
  14108. ggc_free (array);
  14109. }
  14110. }
  14111. return false;
  14112. }
  14113. /* Attach a DW_AT_const_value attribute to VAR_DIE. The value of the
  14114. attribute is the const value of T, where T is an integral constant
  14115. variable with static storage duration
  14116. (so it can't be a PARM_DECL or a RESULT_DECL). */
  14117. static bool
  14118. tree_add_const_value_attribute_for_decl (dw_die_ref var_die, tree decl)
  14119. {
  14120. if (!decl
  14121. || (TREE_CODE (decl) != VAR_DECL
  14122. && TREE_CODE (decl) != CONST_DECL)
  14123. || (TREE_CODE (decl) == VAR_DECL
  14124. && !TREE_STATIC (decl)))
  14125. return false;
  14126. if (TREE_READONLY (decl)
  14127. && ! TREE_THIS_VOLATILE (decl)
  14128. && DECL_INITIAL (decl))
  14129. /* OK */;
  14130. else
  14131. return false;
  14132. /* Don't add DW_AT_const_value if abstract origin already has one. */
  14133. if (get_AT (var_die, DW_AT_const_value))
  14134. return false;
  14135. return tree_add_const_value_attribute (var_die, DECL_INITIAL (decl));
  14136. }
  14137. /* Convert the CFI instructions for the current function into a
  14138. location list. This is used for DW_AT_frame_base when we targeting
  14139. a dwarf2 consumer that does not support the dwarf3
  14140. DW_OP_call_frame_cfa. OFFSET is a constant to be added to all CFA
  14141. expressions. */
  14142. static dw_loc_list_ref
  14143. convert_cfa_to_fb_loc_list (HOST_WIDE_INT offset)
  14144. {
  14145. int ix;
  14146. dw_fde_ref fde;
  14147. dw_loc_list_ref list, *list_tail;
  14148. dw_cfi_ref cfi;
  14149. dw_cfa_location last_cfa, next_cfa;
  14150. const char *start_label, *last_label, *section;
  14151. dw_cfa_location remember;
  14152. fde = cfun->fde;
  14153. gcc_assert (fde != NULL);
  14154. section = secname_for_decl (current_function_decl);
  14155. list_tail = &list;
  14156. list = NULL;
  14157. memset (&next_cfa, 0, sizeof (next_cfa));
  14158. next_cfa.reg = INVALID_REGNUM;
  14159. remember = next_cfa;
  14160. start_label = fde->dw_fde_begin;
  14161. /* ??? Bald assumption that the CIE opcode list does not contain
  14162. advance opcodes. */
  14163. FOR_EACH_VEC_ELT (*cie_cfi_vec, ix, cfi)
  14164. lookup_cfa_1 (cfi, &next_cfa, &remember);
  14165. last_cfa = next_cfa;
  14166. last_label = start_label;
  14167. if (fde->dw_fde_second_begin && fde->dw_fde_switch_cfi_index == 0)
  14168. {
  14169. /* If the first partition contained no CFI adjustments, the
  14170. CIE opcodes apply to the whole first partition. */
  14171. *list_tail = new_loc_list (build_cfa_loc (&last_cfa, offset),
  14172. fde->dw_fde_begin, fde->dw_fde_end, section);
  14173. list_tail =&(*list_tail)->dw_loc_next;
  14174. start_label = last_label = fde->dw_fde_second_begin;
  14175. }
  14176. FOR_EACH_VEC_SAFE_ELT (fde->dw_fde_cfi, ix, cfi)
  14177. {
  14178. switch (cfi->dw_cfi_opc)
  14179. {
  14180. case DW_CFA_set_loc:
  14181. case DW_CFA_advance_loc1:
  14182. case DW_CFA_advance_loc2:
  14183. case DW_CFA_advance_loc4:
  14184. if (!cfa_equal_p (&last_cfa, &next_cfa))
  14185. {
  14186. *list_tail = new_loc_list (build_cfa_loc (&last_cfa, offset),
  14187. start_label, last_label, section);
  14188. list_tail = &(*list_tail)->dw_loc_next;
  14189. last_cfa = next_cfa;
  14190. start_label = last_label;
  14191. }
  14192. last_label = cfi->dw_cfi_oprnd1.dw_cfi_addr;
  14193. break;
  14194. case DW_CFA_advance_loc:
  14195. /* The encoding is complex enough that we should never emit this. */
  14196. gcc_unreachable ();
  14197. default:
  14198. lookup_cfa_1 (cfi, &next_cfa, &remember);
  14199. break;
  14200. }
  14201. if (ix + 1 == fde->dw_fde_switch_cfi_index)
  14202. {
  14203. if (!cfa_equal_p (&last_cfa, &next_cfa))
  14204. {
  14205. *list_tail = new_loc_list (build_cfa_loc (&last_cfa, offset),
  14206. start_label, last_label, section);
  14207. list_tail = &(*list_tail)->dw_loc_next;
  14208. last_cfa = next_cfa;
  14209. start_label = last_label;
  14210. }
  14211. *list_tail = new_loc_list (build_cfa_loc (&last_cfa, offset),
  14212. start_label, fde->dw_fde_end, section);
  14213. list_tail = &(*list_tail)->dw_loc_next;
  14214. start_label = last_label = fde->dw_fde_second_begin;
  14215. }
  14216. }
  14217. if (!cfa_equal_p (&last_cfa, &next_cfa))
  14218. {
  14219. *list_tail = new_loc_list (build_cfa_loc (&last_cfa, offset),
  14220. start_label, last_label, section);
  14221. list_tail = &(*list_tail)->dw_loc_next;
  14222. start_label = last_label;
  14223. }
  14224. *list_tail = new_loc_list (build_cfa_loc (&next_cfa, offset),
  14225. start_label,
  14226. fde->dw_fde_second_begin
  14227. ? fde->dw_fde_second_end : fde->dw_fde_end,
  14228. section);
  14229. if (list && list->dw_loc_next)
  14230. gen_llsym (list);
  14231. return list;
  14232. }
  14233. /* Compute a displacement from the "steady-state frame pointer" to the
  14234. frame base (often the same as the CFA), and store it in
  14235. frame_pointer_fb_offset. OFFSET is added to the displacement
  14236. before the latter is negated. */
  14237. static void
  14238. compute_frame_pointer_to_fb_displacement (HOST_WIDE_INT offset)
  14239. {
  14240. rtx reg, elim;
  14241. #ifdef FRAME_POINTER_CFA_OFFSET
  14242. reg = frame_pointer_rtx;
  14243. offset += FRAME_POINTER_CFA_OFFSET (current_function_decl);
  14244. #else
  14245. reg = arg_pointer_rtx;
  14246. offset += ARG_POINTER_CFA_OFFSET (current_function_decl);
  14247. #endif
  14248. elim = (ira_use_lra_p
  14249. ? lra_eliminate_regs (reg, VOIDmode, NULL_RTX)
  14250. : eliminate_regs (reg, VOIDmode, NULL_RTX));
  14251. if (GET_CODE (elim) == PLUS)
  14252. {
  14253. offset += INTVAL (XEXP (elim, 1));
  14254. elim = XEXP (elim, 0);
  14255. }
  14256. frame_pointer_fb_offset = -offset;
  14257. /* ??? AVR doesn't set up valid eliminations when there is no stack frame
  14258. in which to eliminate. This is because it's stack pointer isn't
  14259. directly accessible as a register within the ISA. To work around
  14260. this, assume that while we cannot provide a proper value for
  14261. frame_pointer_fb_offset, we won't need one either. */
  14262. frame_pointer_fb_offset_valid
  14263. = ((SUPPORTS_STACK_ALIGNMENT
  14264. && (elim == hard_frame_pointer_rtx
  14265. || elim == stack_pointer_rtx))
  14266. || elim == (frame_pointer_needed
  14267. ? hard_frame_pointer_rtx
  14268. : stack_pointer_rtx));
  14269. }
  14270. /* Generate a DW_AT_name attribute given some string value to be included as
  14271. the value of the attribute. */
  14272. static void
  14273. add_name_attribute (dw_die_ref die, const char *name_string)
  14274. {
  14275. if (name_string != NULL && *name_string != 0)
  14276. {
  14277. if (demangle_name_func)
  14278. name_string = (*demangle_name_func) (name_string);
  14279. add_AT_string (die, DW_AT_name, name_string);
  14280. }
  14281. }
  14282. /* Retrieve the descriptive type of TYPE, if any, make sure it has a
  14283. DIE and attach a DW_AT_GNAT_descriptive_type attribute to the DIE
  14284. of TYPE accordingly.
  14285. ??? This is a temporary measure until after we're able to generate
  14286. regular DWARF for the complex Ada type system. */
  14287. static void
  14288. add_gnat_descriptive_type_attribute (dw_die_ref die, tree type,
  14289. dw_die_ref context_die)
  14290. {
  14291. tree dtype;
  14292. dw_die_ref dtype_die;
  14293. if (!lang_hooks.types.descriptive_type)
  14294. return;
  14295. dtype = lang_hooks.types.descriptive_type (type);
  14296. if (!dtype)
  14297. return;
  14298. dtype_die = lookup_type_die (dtype);
  14299. if (!dtype_die)
  14300. {
  14301. gen_type_die (dtype, context_die);
  14302. dtype_die = lookup_type_die (dtype);
  14303. gcc_assert (dtype_die);
  14304. }
  14305. add_AT_die_ref (die, DW_AT_GNAT_descriptive_type, dtype_die);
  14306. }
  14307. /* Retrieve the comp_dir string suitable for use with DW_AT_comp_dir. */
  14308. static const char *
  14309. comp_dir_string (void)
  14310. {
  14311. const char *wd;
  14312. char *wd1;
  14313. static const char *cached_wd = NULL;
  14314. if (cached_wd != NULL)
  14315. return cached_wd;
  14316. wd = get_src_pwd ();
  14317. if (wd == NULL)
  14318. return NULL;
  14319. if (DWARF2_DIR_SHOULD_END_WITH_SEPARATOR)
  14320. {
  14321. int wdlen;
  14322. wdlen = strlen (wd);
  14323. wd1 = ggc_vec_alloc<char> (wdlen + 2);
  14324. strcpy (wd1, wd);
  14325. wd1 [wdlen] = DIR_SEPARATOR;
  14326. wd1 [wdlen + 1] = 0;
  14327. wd = wd1;
  14328. }
  14329. cached_wd = remap_debug_filename (wd);
  14330. return cached_wd;
  14331. }
  14332. /* Generate a DW_AT_comp_dir attribute for DIE. */
  14333. static void
  14334. add_comp_dir_attribute (dw_die_ref die)
  14335. {
  14336. const char * wd = comp_dir_string ();
  14337. if (wd != NULL)
  14338. add_AT_string (die, DW_AT_comp_dir, wd);
  14339. }
  14340. /* Given a tree node VALUE describing a scalar attribute ATTR (i.e. a bound, a
  14341. pointer computation, ...), output a representation for that bound according
  14342. to the accepted FORMS (see enum dw_scalar_form) and add it to DIE. See
  14343. loc_list_from_tree for the meaning of CONTEXT. */
  14344. static void
  14345. add_scalar_info (dw_die_ref die, enum dwarf_attribute attr, tree value,
  14346. int forms, const struct loc_descr_context *context)
  14347. {
  14348. dw_die_ref ctx, decl_die;
  14349. dw_loc_list_ref list;
  14350. bool strip_conversions = true;
  14351. while (strip_conversions)
  14352. switch (TREE_CODE (value))
  14353. {
  14354. case ERROR_MARK:
  14355. case SAVE_EXPR:
  14356. return;
  14357. CASE_CONVERT:
  14358. case VIEW_CONVERT_EXPR:
  14359. value = TREE_OPERAND (value, 0);
  14360. break;
  14361. default:
  14362. strip_conversions = false;
  14363. break;
  14364. }
  14365. /* If possible and permitted, output the attribute as a constant. */
  14366. if ((forms & dw_scalar_form_constant) != 0
  14367. && TREE_CODE (value) == INTEGER_CST)
  14368. {
  14369. unsigned int prec = simple_type_size_in_bits (TREE_TYPE (value));
  14370. /* If HOST_WIDE_INT is big enough then represent the bound as
  14371. a constant value. We need to choose a form based on
  14372. whether the type is signed or unsigned. We cannot just
  14373. call add_AT_unsigned if the value itself is positive
  14374. (add_AT_unsigned might add the unsigned value encoded as
  14375. DW_FORM_data[1248]). Some DWARF consumers will lookup the
  14376. bounds type and then sign extend any unsigned values found
  14377. for signed types. This is needed only for
  14378. DW_AT_{lower,upper}_bound, since for most other attributes,
  14379. consumers will treat DW_FORM_data[1248] as unsigned values,
  14380. regardless of the underlying type. */
  14381. if (prec <= HOST_BITS_PER_WIDE_INT
  14382. || tree_fits_uhwi_p (value))
  14383. {
  14384. if (TYPE_UNSIGNED (TREE_TYPE (value)))
  14385. add_AT_unsigned (die, attr, TREE_INT_CST_LOW (value));
  14386. else
  14387. add_AT_int (die, attr, TREE_INT_CST_LOW (value));
  14388. }
  14389. else
  14390. /* Otherwise represent the bound as an unsigned value with
  14391. the precision of its type. The precision and signedness
  14392. of the type will be necessary to re-interpret it
  14393. unambiguously. */
  14394. add_AT_wide (die, attr, value);
  14395. return;
  14396. }
  14397. /* Otherwise, if it's possible and permitted too, output a reference to
  14398. another DIE. */
  14399. if ((forms & dw_scalar_form_reference) != 0)
  14400. {
  14401. tree decl = NULL_TREE;
  14402. /* Some type attributes reference an outer type. For instance, the upper
  14403. bound of an array may reference an embedding record (this happens in
  14404. Ada). */
  14405. if (TREE_CODE (value) == COMPONENT_REF
  14406. && TREE_CODE (TREE_OPERAND (value, 0)) == PLACEHOLDER_EXPR
  14407. && TREE_CODE (TREE_OPERAND (value, 1)) == FIELD_DECL)
  14408. decl = TREE_OPERAND (value, 1);
  14409. else if (TREE_CODE (value) == VAR_DECL
  14410. || TREE_CODE (value) == PARM_DECL
  14411. || TREE_CODE (value) == RESULT_DECL)
  14412. decl = value;
  14413. if (decl != NULL_TREE)
  14414. {
  14415. dw_die_ref decl_die = lookup_decl_die (decl);
  14416. /* ??? Can this happen, or should the variable have been bound
  14417. first? Probably it can, since I imagine that we try to create
  14418. the types of parameters in the order in which they exist in
  14419. the list, and won't have created a forward reference to a
  14420. later parameter. */
  14421. if (decl_die != NULL)
  14422. {
  14423. add_AT_die_ref (die, attr, decl_die);
  14424. return;
  14425. }
  14426. }
  14427. }
  14428. /* Last chance: try to create a stack operation procedure to evaluate the
  14429. value. Do nothing if even that is not possible or permitted. */
  14430. if ((forms & dw_scalar_form_exprloc) == 0)
  14431. return;
  14432. list = loc_list_from_tree (value, 2, context);
  14433. if (list == NULL || single_element_loc_list_p (list))
  14434. {
  14435. /* If this attribute is not a reference nor constant, it is
  14436. a DWARF expression rather than location description. For that
  14437. loc_list_from_tree (value, 0, &context) is needed. */
  14438. dw_loc_list_ref list2 = loc_list_from_tree (value, 0, context);
  14439. if (list2 && single_element_loc_list_p (list2))
  14440. {
  14441. add_AT_loc (die, attr, list2->expr);
  14442. return;
  14443. }
  14444. }
  14445. /* If that failed to give a single element location list, fall back to
  14446. outputting this as a reference... still if permitted. */
  14447. if (list == NULL || (forms & dw_scalar_form_reference) == 0)
  14448. return;
  14449. if (current_function_decl == 0)
  14450. ctx = comp_unit_die ();
  14451. else
  14452. ctx = lookup_decl_die (current_function_decl);
  14453. decl_die = new_die (DW_TAG_variable, ctx, value);
  14454. add_AT_flag (decl_die, DW_AT_artificial, 1);
  14455. add_type_attribute (decl_die, TREE_TYPE (value), TYPE_QUAL_CONST, ctx);
  14456. add_AT_location_description (decl_die, DW_AT_location, list);
  14457. add_AT_die_ref (die, attr, decl_die);
  14458. }
  14459. /* Return the default for DW_AT_lower_bound, or -1 if there is not any
  14460. default. */
  14461. static int
  14462. lower_bound_default (void)
  14463. {
  14464. switch (get_AT_unsigned (comp_unit_die (), DW_AT_language))
  14465. {
  14466. case DW_LANG_C:
  14467. case DW_LANG_C89:
  14468. case DW_LANG_C99:
  14469. case DW_LANG_C11:
  14470. case DW_LANG_C_plus_plus:
  14471. case DW_LANG_C_plus_plus_11:
  14472. case DW_LANG_C_plus_plus_14:
  14473. case DW_LANG_ObjC:
  14474. case DW_LANG_ObjC_plus_plus:
  14475. case DW_LANG_Java:
  14476. return 0;
  14477. case DW_LANG_Fortran77:
  14478. case DW_LANG_Fortran90:
  14479. case DW_LANG_Fortran95:
  14480. case DW_LANG_Fortran03:
  14481. case DW_LANG_Fortran08:
  14482. return 1;
  14483. case DW_LANG_UPC:
  14484. case DW_LANG_D:
  14485. case DW_LANG_Python:
  14486. return dwarf_version >= 4 ? 0 : -1;
  14487. case DW_LANG_Ada95:
  14488. case DW_LANG_Ada83:
  14489. case DW_LANG_Cobol74:
  14490. case DW_LANG_Cobol85:
  14491. case DW_LANG_Pascal83:
  14492. case DW_LANG_Modula2:
  14493. case DW_LANG_PLI:
  14494. return dwarf_version >= 4 ? 1 : -1;
  14495. default:
  14496. return -1;
  14497. }
  14498. }
  14499. /* Given a tree node describing an array bound (either lower or upper) output
  14500. a representation for that bound. */
  14501. static void
  14502. add_bound_info (dw_die_ref subrange_die, enum dwarf_attribute bound_attr,
  14503. tree bound, const struct loc_descr_context *context)
  14504. {
  14505. int dflt;
  14506. while (1)
  14507. switch (TREE_CODE (bound))
  14508. {
  14509. /* Strip all conversions. */
  14510. CASE_CONVERT:
  14511. case VIEW_CONVERT_EXPR:
  14512. bound = TREE_OPERAND (bound, 0);
  14513. break;
  14514. /* All fixed-bounds are represented by INTEGER_CST nodes. Lower bounds
  14515. are even omitted when they are the default. */
  14516. case INTEGER_CST:
  14517. /* If the value for this bound is the default one, we can even omit the
  14518. attribute. */
  14519. if (bound_attr == DW_AT_lower_bound
  14520. && tree_fits_shwi_p (bound)
  14521. && (dflt = lower_bound_default ()) != -1
  14522. && tree_to_shwi (bound) == dflt)
  14523. return;
  14524. /* FALLTHRU */
  14525. default:
  14526. add_scalar_info (subrange_die, bound_attr, bound,
  14527. dw_scalar_form_constant
  14528. | dw_scalar_form_exprloc
  14529. | dw_scalar_form_reference,
  14530. context);
  14531. return;
  14532. }
  14533. }
  14534. /* Add subscript info to TYPE_DIE, describing an array TYPE, collapsing
  14535. possibly nested array subscripts in a flat sequence if COLLAPSE_P is true.
  14536. Note that the block of subscript information for an array type also
  14537. includes information about the element type of the given array type. */
  14538. static void
  14539. add_subscript_info (dw_die_ref type_die, tree type, bool collapse_p)
  14540. {
  14541. unsigned dimension_number;
  14542. tree lower, upper;
  14543. dw_die_ref subrange_die;
  14544. for (dimension_number = 0;
  14545. TREE_CODE (type) == ARRAY_TYPE && (dimension_number == 0 || collapse_p);
  14546. type = TREE_TYPE (type), dimension_number++)
  14547. {
  14548. tree domain = TYPE_DOMAIN (type);
  14549. if (TYPE_STRING_FLAG (type) && is_fortran () && dimension_number > 0)
  14550. break;
  14551. /* Arrays come in three flavors: Unspecified bounds, fixed bounds,
  14552. and (in GNU C only) variable bounds. Handle all three forms
  14553. here. */
  14554. subrange_die = new_die (DW_TAG_subrange_type, type_die, NULL);
  14555. if (domain)
  14556. {
  14557. /* We have an array type with specified bounds. */
  14558. lower = TYPE_MIN_VALUE (domain);
  14559. upper = TYPE_MAX_VALUE (domain);
  14560. /* Define the index type. */
  14561. if (TREE_TYPE (domain))
  14562. {
  14563. /* ??? This is probably an Ada unnamed subrange type. Ignore the
  14564. TREE_TYPE field. We can't emit debug info for this
  14565. because it is an unnamed integral type. */
  14566. if (TREE_CODE (domain) == INTEGER_TYPE
  14567. && TYPE_NAME (domain) == NULL_TREE
  14568. && TREE_CODE (TREE_TYPE (domain)) == INTEGER_TYPE
  14569. && TYPE_NAME (TREE_TYPE (domain)) == NULL_TREE)
  14570. ;
  14571. else
  14572. add_type_attribute (subrange_die, TREE_TYPE (domain),
  14573. TYPE_UNQUALIFIED, type_die);
  14574. }
  14575. /* ??? If upper is NULL, the array has unspecified length,
  14576. but it does have a lower bound. This happens with Fortran
  14577. dimension arr(N:*)
  14578. Since the debugger is definitely going to need to know N
  14579. to produce useful results, go ahead and output the lower
  14580. bound solo, and hope the debugger can cope. */
  14581. add_bound_info (subrange_die, DW_AT_lower_bound, lower, NULL);
  14582. if (upper)
  14583. add_bound_info (subrange_die, DW_AT_upper_bound, upper, NULL);
  14584. }
  14585. /* Otherwise we have an array type with an unspecified length. The
  14586. DWARF-2 spec does not say how to handle this; let's just leave out the
  14587. bounds. */
  14588. }
  14589. }
  14590. /* Add a DW_AT_byte_size attribute to DIE with TREE_NODE's size. */
  14591. static void
  14592. add_byte_size_attribute (dw_die_ref die, tree tree_node)
  14593. {
  14594. dw_die_ref decl_die;
  14595. HOST_WIDE_INT size;
  14596. switch (TREE_CODE (tree_node))
  14597. {
  14598. case ERROR_MARK:
  14599. size = 0;
  14600. break;
  14601. case ENUMERAL_TYPE:
  14602. case RECORD_TYPE:
  14603. case UNION_TYPE:
  14604. case QUAL_UNION_TYPE:
  14605. if (TREE_CODE (TYPE_SIZE_UNIT (tree_node)) == VAR_DECL
  14606. && (decl_die = lookup_decl_die (TYPE_SIZE_UNIT (tree_node))))
  14607. {
  14608. add_AT_die_ref (die, DW_AT_byte_size, decl_die);
  14609. return;
  14610. }
  14611. size = int_size_in_bytes (tree_node);
  14612. break;
  14613. case FIELD_DECL:
  14614. /* For a data member of a struct or union, the DW_AT_byte_size is
  14615. generally given as the number of bytes normally allocated for an
  14616. object of the *declared* type of the member itself. This is true
  14617. even for bit-fields. */
  14618. size = int_size_in_bytes (field_type (tree_node));
  14619. break;
  14620. default:
  14621. gcc_unreachable ();
  14622. }
  14623. /* Note that `size' might be -1 when we get to this point. If it is, that
  14624. indicates that the byte size of the entity in question is variable. We
  14625. have no good way of expressing this fact in Dwarf at the present time,
  14626. when location description was not used by the caller code instead. */
  14627. if (size >= 0)
  14628. add_AT_unsigned (die, DW_AT_byte_size, size);
  14629. }
  14630. /* For a FIELD_DECL node which represents a bit-field, output an attribute
  14631. which specifies the distance in bits from the highest order bit of the
  14632. "containing object" for the bit-field to the highest order bit of the
  14633. bit-field itself.
  14634. For any given bit-field, the "containing object" is a hypothetical object
  14635. (of some integral or enum type) within which the given bit-field lives. The
  14636. type of this hypothetical "containing object" is always the same as the
  14637. declared type of the individual bit-field itself. The determination of the
  14638. exact location of the "containing object" for a bit-field is rather
  14639. complicated. It's handled by the `field_byte_offset' function (above).
  14640. Note that it is the size (in bytes) of the hypothetical "containing object"
  14641. which will be given in the DW_AT_byte_size attribute for this bit-field.
  14642. (See `byte_size_attribute' above). */
  14643. static inline void
  14644. add_bit_offset_attribute (dw_die_ref die, tree decl)
  14645. {
  14646. HOST_WIDE_INT object_offset_in_bytes = field_byte_offset (decl);
  14647. tree type = DECL_BIT_FIELD_TYPE (decl);
  14648. HOST_WIDE_INT bitpos_int;
  14649. HOST_WIDE_INT highest_order_object_bit_offset;
  14650. HOST_WIDE_INT highest_order_field_bit_offset;
  14651. HOST_WIDE_INT bit_offset;
  14652. /* Must be a field and a bit field. */
  14653. gcc_assert (type && TREE_CODE (decl) == FIELD_DECL);
  14654. /* We can't yet handle bit-fields whose offsets are variable, so if we
  14655. encounter such things, just return without generating any attribute
  14656. whatsoever. Likewise for variable or too large size. */
  14657. if (! tree_fits_shwi_p (bit_position (decl))
  14658. || ! tree_fits_uhwi_p (DECL_SIZE (decl)))
  14659. return;
  14660. bitpos_int = int_bit_position (decl);
  14661. /* Note that the bit offset is always the distance (in bits) from the
  14662. highest-order bit of the "containing object" to the highest-order bit of
  14663. the bit-field itself. Since the "high-order end" of any object or field
  14664. is different on big-endian and little-endian machines, the computation
  14665. below must take account of these differences. */
  14666. highest_order_object_bit_offset = object_offset_in_bytes * BITS_PER_UNIT;
  14667. highest_order_field_bit_offset = bitpos_int;
  14668. if (! BYTES_BIG_ENDIAN)
  14669. {
  14670. highest_order_field_bit_offset += tree_to_shwi (DECL_SIZE (decl));
  14671. highest_order_object_bit_offset += simple_type_size_in_bits (type);
  14672. }
  14673. bit_offset
  14674. = (! BYTES_BIG_ENDIAN
  14675. ? highest_order_object_bit_offset - highest_order_field_bit_offset
  14676. : highest_order_field_bit_offset - highest_order_object_bit_offset);
  14677. if (bit_offset < 0)
  14678. add_AT_int (die, DW_AT_bit_offset, bit_offset);
  14679. else
  14680. add_AT_unsigned (die, DW_AT_bit_offset, (unsigned HOST_WIDE_INT) bit_offset);
  14681. }
  14682. /* For a FIELD_DECL node which represents a bit field, output an attribute
  14683. which specifies the length in bits of the given field. */
  14684. static inline void
  14685. add_bit_size_attribute (dw_die_ref die, tree decl)
  14686. {
  14687. /* Must be a field and a bit field. */
  14688. gcc_assert (TREE_CODE (decl) == FIELD_DECL
  14689. && DECL_BIT_FIELD_TYPE (decl));
  14690. if (tree_fits_uhwi_p (DECL_SIZE (decl)))
  14691. add_AT_unsigned (die, DW_AT_bit_size, tree_to_uhwi (DECL_SIZE (decl)));
  14692. }
  14693. /* If the compiled language is ANSI C, then add a 'prototyped'
  14694. attribute, if arg types are given for the parameters of a function. */
  14695. static inline void
  14696. add_prototyped_attribute (dw_die_ref die, tree func_type)
  14697. {
  14698. switch (get_AT_unsigned (comp_unit_die (), DW_AT_language))
  14699. {
  14700. case DW_LANG_C:
  14701. case DW_LANG_C89:
  14702. case DW_LANG_C99:
  14703. case DW_LANG_C11:
  14704. case DW_LANG_ObjC:
  14705. if (prototype_p (func_type))
  14706. add_AT_flag (die, DW_AT_prototyped, 1);
  14707. break;
  14708. default:
  14709. break;
  14710. }
  14711. }
  14712. /* Add an 'abstract_origin' attribute below a given DIE. The DIE is found
  14713. by looking in either the type declaration or object declaration
  14714. equate table. */
  14715. static inline dw_die_ref
  14716. add_abstract_origin_attribute (dw_die_ref die, tree origin)
  14717. {
  14718. dw_die_ref origin_die = NULL;
  14719. if (TREE_CODE (origin) != FUNCTION_DECL)
  14720. {
  14721. /* We may have gotten separated from the block for the inlined
  14722. function, if we're in an exception handler or some such; make
  14723. sure that the abstract function has been written out.
  14724. Doing this for nested functions is wrong, however; functions are
  14725. distinct units, and our context might not even be inline. */
  14726. tree fn = origin;
  14727. if (TYPE_P (fn))
  14728. fn = TYPE_STUB_DECL (fn);
  14729. fn = decl_function_context (fn);
  14730. if (fn)
  14731. dwarf2out_abstract_function (fn);
  14732. }
  14733. if (DECL_P (origin))
  14734. origin_die = lookup_decl_die (origin);
  14735. else if (TYPE_P (origin))
  14736. origin_die = lookup_type_die (origin);
  14737. /* XXX: Functions that are never lowered don't always have correct block
  14738. trees (in the case of java, they simply have no block tree, in some other
  14739. languages). For these functions, there is nothing we can really do to
  14740. output correct debug info for inlined functions in all cases. Rather
  14741. than die, we'll just produce deficient debug info now, in that we will
  14742. have variables without a proper abstract origin. In the future, when all
  14743. functions are lowered, we should re-add a gcc_assert (origin_die)
  14744. here. */
  14745. if (origin_die)
  14746. add_AT_die_ref (die, DW_AT_abstract_origin, origin_die);
  14747. return origin_die;
  14748. }
  14749. /* We do not currently support the pure_virtual attribute. */
  14750. static inline void
  14751. add_pure_or_virtual_attribute (dw_die_ref die, tree func_decl)
  14752. {
  14753. if (DECL_VINDEX (func_decl))
  14754. {
  14755. add_AT_unsigned (die, DW_AT_virtuality, DW_VIRTUALITY_virtual);
  14756. if (tree_fits_shwi_p (DECL_VINDEX (func_decl)))
  14757. add_AT_loc (die, DW_AT_vtable_elem_location,
  14758. new_loc_descr (DW_OP_constu,
  14759. tree_to_shwi (DECL_VINDEX (func_decl)),
  14760. 0));
  14761. /* GNU extension: Record what type this method came from originally. */
  14762. if (debug_info_level > DINFO_LEVEL_TERSE
  14763. && DECL_CONTEXT (func_decl))
  14764. add_AT_die_ref (die, DW_AT_containing_type,
  14765. lookup_type_die (DECL_CONTEXT (func_decl)));
  14766. }
  14767. }
  14768. /* Add a DW_AT_linkage_name or DW_AT_MIPS_linkage_name attribute for the
  14769. given decl. This used to be a vendor extension until after DWARF 4
  14770. standardized it. */
  14771. static void
  14772. add_linkage_attr (dw_die_ref die, tree decl)
  14773. {
  14774. const char *name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl));
  14775. /* Mimic what assemble_name_raw does with a leading '*'. */
  14776. if (name[0] == '*')
  14777. name = &name[1];
  14778. if (dwarf_version >= 4)
  14779. add_AT_string (die, DW_AT_linkage_name, name);
  14780. else
  14781. add_AT_string (die, DW_AT_MIPS_linkage_name, name);
  14782. }
  14783. /* Add source coordinate attributes for the given decl. */
  14784. static void
  14785. add_src_coords_attributes (dw_die_ref die, tree decl)
  14786. {
  14787. expanded_location s;
  14788. if (LOCATION_LOCUS (DECL_SOURCE_LOCATION (decl)) == UNKNOWN_LOCATION)
  14789. return;
  14790. s = expand_location (DECL_SOURCE_LOCATION (decl));
  14791. add_AT_file (die, DW_AT_decl_file, lookup_filename (s.file));
  14792. add_AT_unsigned (die, DW_AT_decl_line, s.line);
  14793. }
  14794. /* Add DW_AT_{,MIPS_}linkage_name attribute for the given decl. */
  14795. static void
  14796. add_linkage_name (dw_die_ref die, tree decl)
  14797. {
  14798. if (debug_info_level > DINFO_LEVEL_NONE
  14799. && (TREE_CODE (decl) == FUNCTION_DECL || TREE_CODE (decl) == VAR_DECL)
  14800. && TREE_PUBLIC (decl)
  14801. && !(TREE_CODE (decl) == VAR_DECL && DECL_REGISTER (decl))
  14802. && die->die_tag != DW_TAG_member)
  14803. {
  14804. /* Defer until we have an assembler name set. */
  14805. if (!DECL_ASSEMBLER_NAME_SET_P (decl))
  14806. {
  14807. limbo_die_node *asm_name;
  14808. asm_name = ggc_cleared_alloc<limbo_die_node> ();
  14809. asm_name->die = die;
  14810. asm_name->created_for = decl;
  14811. asm_name->next = deferred_asm_name;
  14812. deferred_asm_name = asm_name;
  14813. }
  14814. else if (DECL_ASSEMBLER_NAME (decl) != DECL_NAME (decl))
  14815. add_linkage_attr (die, decl);
  14816. }
  14817. }
  14818. /* Add a DW_AT_name attribute and source coordinate attribute for the
  14819. given decl, but only if it actually has a name. */
  14820. static void
  14821. add_name_and_src_coords_attributes (dw_die_ref die, tree decl)
  14822. {
  14823. tree decl_name;
  14824. decl_name = DECL_NAME (decl);
  14825. if (decl_name != NULL && IDENTIFIER_POINTER (decl_name) != NULL)
  14826. {
  14827. const char *name = dwarf2_name (decl, 0);
  14828. if (name)
  14829. add_name_attribute (die, name);
  14830. if (! DECL_ARTIFICIAL (decl))
  14831. add_src_coords_attributes (die, decl);
  14832. add_linkage_name (die, decl);
  14833. }
  14834. #ifdef VMS_DEBUGGING_INFO
  14835. /* Get the function's name, as described by its RTL. This may be different
  14836. from the DECL_NAME name used in the source file. */
  14837. if (TREE_CODE (decl) == FUNCTION_DECL && TREE_ASM_WRITTEN (decl))
  14838. {
  14839. add_AT_addr (die, DW_AT_VMS_rtnbeg_pd_address,
  14840. XEXP (DECL_RTL (decl), 0), false);
  14841. vec_safe_push (used_rtx_array, XEXP (DECL_RTL (decl), 0));
  14842. }
  14843. #endif /* VMS_DEBUGGING_INFO */
  14844. }
  14845. #ifdef VMS_DEBUGGING_INFO
  14846. /* Output the debug main pointer die for VMS */
  14847. void
  14848. dwarf2out_vms_debug_main_pointer (void)
  14849. {
  14850. char label[MAX_ARTIFICIAL_LABEL_BYTES];
  14851. dw_die_ref die;
  14852. /* Allocate the VMS debug main subprogram die. */
  14853. die = ggc_cleared_alloc<die_node> ();
  14854. die->die_tag = DW_TAG_subprogram;
  14855. add_name_attribute (die, VMS_DEBUG_MAIN_POINTER);
  14856. ASM_GENERATE_INTERNAL_LABEL (label, PROLOGUE_END_LABEL,
  14857. current_function_funcdef_no);
  14858. add_AT_lbl_id (die, DW_AT_entry_pc, label);
  14859. /* Make it the first child of comp_unit_die (). */
  14860. die->die_parent = comp_unit_die ();
  14861. if (comp_unit_die ()->die_child)
  14862. {
  14863. die->die_sib = comp_unit_die ()->die_child->die_sib;
  14864. comp_unit_die ()->die_child->die_sib = die;
  14865. }
  14866. else
  14867. {
  14868. die->die_sib = die;
  14869. comp_unit_die ()->die_child = die;
  14870. }
  14871. }
  14872. #endif /* VMS_DEBUGGING_INFO */
  14873. /* Push a new declaration scope. */
  14874. static void
  14875. push_decl_scope (tree scope)
  14876. {
  14877. vec_safe_push (decl_scope_table, scope);
  14878. }
  14879. /* Pop a declaration scope. */
  14880. static inline void
  14881. pop_decl_scope (void)
  14882. {
  14883. decl_scope_table->pop ();
  14884. }
  14885. /* walk_tree helper function for uses_local_type, below. */
  14886. static tree
  14887. uses_local_type_r (tree *tp, int *walk_subtrees, void *data ATTRIBUTE_UNUSED)
  14888. {
  14889. if (!TYPE_P (*tp))
  14890. *walk_subtrees = 0;
  14891. else
  14892. {
  14893. tree name = TYPE_NAME (*tp);
  14894. if (name && DECL_P (name) && decl_function_context (name))
  14895. return *tp;
  14896. }
  14897. return NULL_TREE;
  14898. }
  14899. /* If TYPE involves a function-local type (including a local typedef to a
  14900. non-local type), returns that type; otherwise returns NULL_TREE. */
  14901. static tree
  14902. uses_local_type (tree type)
  14903. {
  14904. tree used = walk_tree_without_duplicates (&type, uses_local_type_r, NULL);
  14905. return used;
  14906. }
  14907. /* Return the DIE for the scope that immediately contains this type.
  14908. Non-named types that do not involve a function-local type get global
  14909. scope. Named types nested in namespaces or other types get their
  14910. containing scope. All other types (i.e. function-local named types) get
  14911. the current active scope. */
  14912. static dw_die_ref
  14913. scope_die_for (tree t, dw_die_ref context_die)
  14914. {
  14915. dw_die_ref scope_die = NULL;
  14916. tree containing_scope;
  14917. /* Non-types always go in the current scope. */
  14918. gcc_assert (TYPE_P (t));
  14919. /* Use the scope of the typedef, rather than the scope of the type
  14920. it refers to. */
  14921. if (TYPE_NAME (t) && DECL_P (TYPE_NAME (t)))
  14922. containing_scope = DECL_CONTEXT (TYPE_NAME (t));
  14923. else
  14924. containing_scope = TYPE_CONTEXT (t);
  14925. /* Use the containing namespace if there is one. */
  14926. if (containing_scope && TREE_CODE (containing_scope) == NAMESPACE_DECL)
  14927. {
  14928. if (context_die == lookup_decl_die (containing_scope))
  14929. /* OK */;
  14930. else if (debug_info_level > DINFO_LEVEL_TERSE)
  14931. context_die = get_context_die (containing_scope);
  14932. else
  14933. containing_scope = NULL_TREE;
  14934. }
  14935. /* Ignore function type "scopes" from the C frontend. They mean that
  14936. a tagged type is local to a parmlist of a function declarator, but
  14937. that isn't useful to DWARF. */
  14938. if (containing_scope && TREE_CODE (containing_scope) == FUNCTION_TYPE)
  14939. containing_scope = NULL_TREE;
  14940. if (SCOPE_FILE_SCOPE_P (containing_scope))
  14941. {
  14942. /* If T uses a local type keep it local as well, to avoid references
  14943. to function-local DIEs from outside the function. */
  14944. if (current_function_decl && uses_local_type (t))
  14945. scope_die = context_die;
  14946. else
  14947. scope_die = comp_unit_die ();
  14948. }
  14949. else if (TYPE_P (containing_scope))
  14950. {
  14951. /* For types, we can just look up the appropriate DIE. */
  14952. if (debug_info_level > DINFO_LEVEL_TERSE)
  14953. scope_die = get_context_die (containing_scope);
  14954. else
  14955. {
  14956. scope_die = lookup_type_die_strip_naming_typedef (containing_scope);
  14957. if (scope_die == NULL)
  14958. scope_die = comp_unit_die ();
  14959. }
  14960. }
  14961. else
  14962. scope_die = context_die;
  14963. return scope_die;
  14964. }
  14965. /* Returns nonzero if CONTEXT_DIE is internal to a function. */
  14966. static inline int
  14967. local_scope_p (dw_die_ref context_die)
  14968. {
  14969. for (; context_die; context_die = context_die->die_parent)
  14970. if (context_die->die_tag == DW_TAG_inlined_subroutine
  14971. || context_die->die_tag == DW_TAG_subprogram)
  14972. return 1;
  14973. return 0;
  14974. }
  14975. /* Returns nonzero if CONTEXT_DIE is a class. */
  14976. static inline int
  14977. class_scope_p (dw_die_ref context_die)
  14978. {
  14979. return (context_die
  14980. && (context_die->die_tag == DW_TAG_structure_type
  14981. || context_die->die_tag == DW_TAG_class_type
  14982. || context_die->die_tag == DW_TAG_interface_type
  14983. || context_die->die_tag == DW_TAG_union_type));
  14984. }
  14985. /* Returns nonzero if CONTEXT_DIE is a class or namespace, for deciding
  14986. whether or not to treat a DIE in this context as a declaration. */
  14987. static inline int
  14988. class_or_namespace_scope_p (dw_die_ref context_die)
  14989. {
  14990. return (class_scope_p (context_die)
  14991. || (context_die && context_die->die_tag == DW_TAG_namespace));
  14992. }
  14993. /* Many forms of DIEs require a "type description" attribute. This
  14994. routine locates the proper "type descriptor" die for the type given
  14995. by 'type' plus any additional qualifiers given by 'cv_quals', and
  14996. adds a DW_AT_type attribute below the given die. */
  14997. static void
  14998. add_type_attribute (dw_die_ref object_die, tree type, int cv_quals,
  14999. dw_die_ref context_die)
  15000. {
  15001. enum tree_code code = TREE_CODE (type);
  15002. dw_die_ref type_die = NULL;
  15003. /* ??? If this type is an unnamed subrange type of an integral, floating-point
  15004. or fixed-point type, use the inner type. This is because we have no
  15005. support for unnamed types in base_type_die. This can happen if this is
  15006. an Ada subrange type. Correct solution is emit a subrange type die. */
  15007. if ((code == INTEGER_TYPE || code == REAL_TYPE || code == FIXED_POINT_TYPE)
  15008. && TREE_TYPE (type) != 0 && TYPE_NAME (type) == 0)
  15009. type = TREE_TYPE (type), code = TREE_CODE (type);
  15010. if (code == ERROR_MARK
  15011. /* Handle a special case. For functions whose return type is void, we
  15012. generate *no* type attribute. (Note that no object may have type
  15013. `void', so this only applies to function return types). */
  15014. || code == VOID_TYPE)
  15015. return;
  15016. type_die = modified_type_die (type,
  15017. cv_quals | TYPE_QUALS_NO_ADDR_SPACE (type),
  15018. context_die);
  15019. if (type_die != NULL)
  15020. add_AT_die_ref (object_die, DW_AT_type, type_die);
  15021. }
  15022. /* Given an object die, add the calling convention attribute for the
  15023. function call type. */
  15024. static void
  15025. add_calling_convention_attribute (dw_die_ref subr_die, tree decl)
  15026. {
  15027. enum dwarf_calling_convention value = DW_CC_normal;
  15028. value = ((enum dwarf_calling_convention)
  15029. targetm.dwarf_calling_convention (TREE_TYPE (decl)));
  15030. if (is_fortran ()
  15031. && !strcmp (IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl)), "MAIN__"))
  15032. {
  15033. /* DWARF 2 doesn't provide a way to identify a program's source-level
  15034. entry point. DW_AT_calling_convention attributes are only meant
  15035. to describe functions' calling conventions. However, lacking a
  15036. better way to signal the Fortran main program, we used this for
  15037. a long time, following existing custom. Now, DWARF 4 has
  15038. DW_AT_main_subprogram, which we add below, but some tools still
  15039. rely on the old way, which we thus keep. */
  15040. value = DW_CC_program;
  15041. if (dwarf_version >= 4 || !dwarf_strict)
  15042. add_AT_flag (subr_die, DW_AT_main_subprogram, 1);
  15043. }
  15044. /* Only add the attribute if the backend requests it, and
  15045. is not DW_CC_normal. */
  15046. if (value && (value != DW_CC_normal))
  15047. add_AT_unsigned (subr_die, DW_AT_calling_convention, value);
  15048. }
  15049. /* Given a tree pointer to a struct, class, union, or enum type node, return
  15050. a pointer to the (string) tag name for the given type, or zero if the type
  15051. was declared without a tag. */
  15052. static const char *
  15053. type_tag (const_tree type)
  15054. {
  15055. const char *name = 0;
  15056. if (TYPE_NAME (type) != 0)
  15057. {
  15058. tree t = 0;
  15059. /* Find the IDENTIFIER_NODE for the type name. */
  15060. if (TREE_CODE (TYPE_NAME (type)) == IDENTIFIER_NODE
  15061. && !TYPE_NAMELESS (type))
  15062. t = TYPE_NAME (type);
  15063. /* The g++ front end makes the TYPE_NAME of *each* tagged type point to
  15064. a TYPE_DECL node, regardless of whether or not a `typedef' was
  15065. involved. */
  15066. else if (TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
  15067. && ! DECL_IGNORED_P (TYPE_NAME (type)))
  15068. {
  15069. /* We want to be extra verbose. Don't call dwarf_name if
  15070. DECL_NAME isn't set. The default hook for decl_printable_name
  15071. doesn't like that, and in this context it's correct to return
  15072. 0, instead of "<anonymous>" or the like. */
  15073. if (DECL_NAME (TYPE_NAME (type))
  15074. && !DECL_NAMELESS (TYPE_NAME (type)))
  15075. name = lang_hooks.dwarf_name (TYPE_NAME (type), 2);
  15076. }
  15077. /* Now get the name as a string, or invent one. */
  15078. if (!name && t != 0)
  15079. name = IDENTIFIER_POINTER (t);
  15080. }
  15081. return (name == 0 || *name == '\0') ? 0 : name;
  15082. }
  15083. /* Return the type associated with a data member, make a special check
  15084. for bit field types. */
  15085. static inline tree
  15086. member_declared_type (const_tree member)
  15087. {
  15088. return (DECL_BIT_FIELD_TYPE (member)
  15089. ? DECL_BIT_FIELD_TYPE (member) : TREE_TYPE (member));
  15090. }
  15091. /* Get the decl's label, as described by its RTL. This may be different
  15092. from the DECL_NAME name used in the source file. */
  15093. #if 0
  15094. static const char *
  15095. decl_start_label (tree decl)
  15096. {
  15097. rtx x;
  15098. const char *fnname;
  15099. x = DECL_RTL (decl);
  15100. gcc_assert (MEM_P (x));
  15101. x = XEXP (x, 0);
  15102. gcc_assert (GET_CODE (x) == SYMBOL_REF);
  15103. fnname = XSTR (x, 0);
  15104. return fnname;
  15105. }
  15106. #endif
  15107. /* These routines generate the internal representation of the DIE's for
  15108. the compilation unit. Debugging information is collected by walking
  15109. the declaration trees passed in from dwarf2out_decl(). */
  15110. static void
  15111. gen_array_type_die (tree type, dw_die_ref context_die)
  15112. {
  15113. dw_die_ref scope_die = scope_die_for (type, context_die);
  15114. dw_die_ref array_die;
  15115. /* GNU compilers represent multidimensional array types as sequences of one
  15116. dimensional array types whose element types are themselves array types.
  15117. We sometimes squish that down to a single array_type DIE with multiple
  15118. subscripts in the Dwarf debugging info. The draft Dwarf specification
  15119. say that we are allowed to do this kind of compression in C, because
  15120. there is no difference between an array of arrays and a multidimensional
  15121. array. We don't do this for Ada to remain as close as possible to the
  15122. actual representation, which is especially important against the language
  15123. flexibilty wrt arrays of variable size. */
  15124. bool collapse_nested_arrays = !is_ada ();
  15125. tree element_type;
  15126. /* Emit DW_TAG_string_type for Fortran character types (with kind 1 only, as
  15127. DW_TAG_string_type doesn't have DW_AT_type attribute). */
  15128. if (TYPE_STRING_FLAG (type)
  15129. && TREE_CODE (type) == ARRAY_TYPE
  15130. && is_fortran ()
  15131. && TYPE_MODE (TREE_TYPE (type)) == TYPE_MODE (char_type_node))
  15132. {
  15133. HOST_WIDE_INT size;
  15134. array_die = new_die (DW_TAG_string_type, scope_die, type);
  15135. add_name_attribute (array_die, type_tag (type));
  15136. equate_type_number_to_die (type, array_die);
  15137. size = int_size_in_bytes (type);
  15138. if (size >= 0)
  15139. add_AT_unsigned (array_die, DW_AT_byte_size, size);
  15140. else if (TYPE_DOMAIN (type) != NULL_TREE
  15141. && TYPE_MAX_VALUE (TYPE_DOMAIN (type)) != NULL_TREE
  15142. && DECL_P (TYPE_MAX_VALUE (TYPE_DOMAIN (type))))
  15143. {
  15144. tree szdecl = TYPE_MAX_VALUE (TYPE_DOMAIN (type));
  15145. dw_loc_list_ref loc = loc_list_from_tree (szdecl, 2, NULL);
  15146. size = int_size_in_bytes (TREE_TYPE (szdecl));
  15147. if (loc && size > 0)
  15148. {
  15149. add_AT_location_description (array_die, DW_AT_string_length, loc);
  15150. if (size != DWARF2_ADDR_SIZE)
  15151. add_AT_unsigned (array_die, DW_AT_byte_size, size);
  15152. }
  15153. }
  15154. return;
  15155. }
  15156. array_die = new_die (DW_TAG_array_type, scope_die, type);
  15157. add_name_attribute (array_die, type_tag (type));
  15158. equate_type_number_to_die (type, array_die);
  15159. if (TREE_CODE (type) == VECTOR_TYPE)
  15160. add_AT_flag (array_die, DW_AT_GNU_vector, 1);
  15161. /* For Fortran multidimensional arrays use DW_ORD_col_major ordering. */
  15162. if (is_fortran ()
  15163. && TREE_CODE (type) == ARRAY_TYPE
  15164. && TREE_CODE (TREE_TYPE (type)) == ARRAY_TYPE
  15165. && !TYPE_STRING_FLAG (TREE_TYPE (type)))
  15166. add_AT_unsigned (array_die, DW_AT_ordering, DW_ORD_col_major);
  15167. #if 0
  15168. /* We default the array ordering. SDB will probably do
  15169. the right things even if DW_AT_ordering is not present. It's not even
  15170. an issue until we start to get into multidimensional arrays anyway. If
  15171. SDB is ever caught doing the Wrong Thing for multi-dimensional arrays,
  15172. then we'll have to put the DW_AT_ordering attribute back in. (But if
  15173. and when we find out that we need to put these in, we will only do so
  15174. for multidimensional arrays. */
  15175. add_AT_unsigned (array_die, DW_AT_ordering, DW_ORD_row_major);
  15176. #endif
  15177. if (TREE_CODE (type) == VECTOR_TYPE)
  15178. {
  15179. /* For VECTOR_TYPEs we use an array die with appropriate bounds. */
  15180. dw_die_ref subrange_die = new_die (DW_TAG_subrange_type, array_die, NULL);
  15181. add_bound_info (subrange_die, DW_AT_lower_bound, size_zero_node, NULL);
  15182. add_bound_info (subrange_die, DW_AT_upper_bound,
  15183. size_int (TYPE_VECTOR_SUBPARTS (type) - 1), NULL);
  15184. }
  15185. else
  15186. add_subscript_info (array_die, type, collapse_nested_arrays);
  15187. /* Add representation of the type of the elements of this array type and
  15188. emit the corresponding DIE if we haven't done it already. */
  15189. element_type = TREE_TYPE (type);
  15190. if (collapse_nested_arrays)
  15191. while (TREE_CODE (element_type) == ARRAY_TYPE)
  15192. {
  15193. if (TYPE_STRING_FLAG (element_type) && is_fortran ())
  15194. break;
  15195. element_type = TREE_TYPE (element_type);
  15196. }
  15197. add_type_attribute (array_die, element_type, TYPE_UNQUALIFIED, context_die);
  15198. add_gnat_descriptive_type_attribute (array_die, type, context_die);
  15199. if (TYPE_ARTIFICIAL (type))
  15200. add_AT_flag (array_die, DW_AT_artificial, 1);
  15201. if (get_AT (array_die, DW_AT_name))
  15202. add_pubtype (type, array_die);
  15203. }
  15204. /* This routine generates DIE for array with hidden descriptor, details
  15205. are filled into *info by a langhook. */
  15206. static void
  15207. gen_descr_array_type_die (tree type, struct array_descr_info *info,
  15208. dw_die_ref context_die)
  15209. {
  15210. const dw_die_ref scope_die = scope_die_for (type, context_die);
  15211. const dw_die_ref array_die = new_die (DW_TAG_array_type, scope_die, type);
  15212. const struct loc_descr_context context = { type, info->base_decl };
  15213. int dim;
  15214. add_name_attribute (array_die, type_tag (type));
  15215. equate_type_number_to_die (type, array_die);
  15216. if (info->ndimensions > 1)
  15217. switch (info->ordering)
  15218. {
  15219. case array_descr_ordering_row_major:
  15220. add_AT_unsigned (array_die, DW_AT_ordering, DW_ORD_row_major);
  15221. break;
  15222. case array_descr_ordering_column_major:
  15223. add_AT_unsigned (array_die, DW_AT_ordering, DW_ORD_col_major);
  15224. break;
  15225. default:
  15226. break;
  15227. }
  15228. if (dwarf_version >= 3 || !dwarf_strict)
  15229. {
  15230. if (info->data_location)
  15231. add_scalar_info (array_die, DW_AT_data_location, info->data_location,
  15232. dw_scalar_form_exprloc, &context);
  15233. if (info->associated)
  15234. add_scalar_info (array_die, DW_AT_associated, info->associated,
  15235. dw_scalar_form_constant
  15236. | dw_scalar_form_exprloc
  15237. | dw_scalar_form_reference, &context);
  15238. if (info->allocated)
  15239. add_scalar_info (array_die, DW_AT_allocated, info->allocated,
  15240. dw_scalar_form_constant
  15241. | dw_scalar_form_exprloc
  15242. | dw_scalar_form_reference, &context);
  15243. }
  15244. add_gnat_descriptive_type_attribute (array_die, type, context_die);
  15245. for (dim = 0; dim < info->ndimensions; dim++)
  15246. {
  15247. dw_die_ref subrange_die
  15248. = new_die (DW_TAG_subrange_type, array_die, NULL);
  15249. if (info->dimen[dim].bounds_type)
  15250. add_type_attribute (subrange_die,
  15251. info->dimen[dim].bounds_type, 0,
  15252. context_die);
  15253. if (info->dimen[dim].lower_bound)
  15254. add_bound_info (subrange_die, DW_AT_lower_bound,
  15255. info->dimen[dim].lower_bound, &context);
  15256. if (info->dimen[dim].upper_bound)
  15257. add_bound_info (subrange_die, DW_AT_upper_bound,
  15258. info->dimen[dim].upper_bound, &context);
  15259. if ((dwarf_version >= 3 || !dwarf_strict) && info->dimen[dim].stride)
  15260. add_scalar_info (subrange_die, DW_AT_byte_stride,
  15261. info->dimen[dim].stride,
  15262. dw_scalar_form_constant
  15263. | dw_scalar_form_exprloc
  15264. | dw_scalar_form_reference,
  15265. &context);
  15266. }
  15267. gen_type_die (info->element_type, context_die);
  15268. add_type_attribute (array_die, info->element_type, TYPE_UNQUALIFIED,
  15269. context_die);
  15270. if (get_AT (array_die, DW_AT_name))
  15271. add_pubtype (type, array_die);
  15272. }
  15273. #if 0
  15274. static void
  15275. gen_entry_point_die (tree decl, dw_die_ref context_die)
  15276. {
  15277. tree origin = decl_ultimate_origin (decl);
  15278. dw_die_ref decl_die = new_die (DW_TAG_entry_point, context_die, decl);
  15279. if (origin != NULL)
  15280. add_abstract_origin_attribute (decl_die, origin);
  15281. else
  15282. {
  15283. add_name_and_src_coords_attributes (decl_die, decl);
  15284. add_type_attribute (decl_die, TREE_TYPE (TREE_TYPE (decl)),
  15285. TYPE_UNQUALIFIED, context_die);
  15286. }
  15287. if (DECL_ABSTRACT_P (decl))
  15288. equate_decl_number_to_die (decl, decl_die);
  15289. else
  15290. add_AT_lbl_id (decl_die, DW_AT_low_pc, decl_start_label (decl));
  15291. }
  15292. #endif
  15293. /* Walk through the list of incomplete types again, trying once more to
  15294. emit full debugging info for them. */
  15295. static void
  15296. retry_incomplete_types (void)
  15297. {
  15298. int i;
  15299. for (i = vec_safe_length (incomplete_types) - 1; i >= 0; i--)
  15300. if (should_emit_struct_debug ((*incomplete_types)[i], DINFO_USAGE_DIR_USE))
  15301. gen_type_die ((*incomplete_types)[i], comp_unit_die ());
  15302. }
  15303. /* Determine what tag to use for a record type. */
  15304. static enum dwarf_tag
  15305. record_type_tag (tree type)
  15306. {
  15307. if (! lang_hooks.types.classify_record)
  15308. return DW_TAG_structure_type;
  15309. switch (lang_hooks.types.classify_record (type))
  15310. {
  15311. case RECORD_IS_STRUCT:
  15312. return DW_TAG_structure_type;
  15313. case RECORD_IS_CLASS:
  15314. return DW_TAG_class_type;
  15315. case RECORD_IS_INTERFACE:
  15316. if (dwarf_version >= 3 || !dwarf_strict)
  15317. return DW_TAG_interface_type;
  15318. return DW_TAG_structure_type;
  15319. default:
  15320. gcc_unreachable ();
  15321. }
  15322. }
  15323. /* Generate a DIE to represent an enumeration type. Note that these DIEs
  15324. include all of the information about the enumeration values also. Each
  15325. enumerated type name/value is listed as a child of the enumerated type
  15326. DIE. */
  15327. static dw_die_ref
  15328. gen_enumeration_type_die (tree type, dw_die_ref context_die)
  15329. {
  15330. dw_die_ref type_die = lookup_type_die (type);
  15331. if (type_die == NULL)
  15332. {
  15333. type_die = new_die (DW_TAG_enumeration_type,
  15334. scope_die_for (type, context_die), type);
  15335. equate_type_number_to_die (type, type_die);
  15336. add_name_attribute (type_die, type_tag (type));
  15337. if (dwarf_version >= 4 || !dwarf_strict)
  15338. {
  15339. if (ENUM_IS_SCOPED (type))
  15340. add_AT_flag (type_die, DW_AT_enum_class, 1);
  15341. if (ENUM_IS_OPAQUE (type))
  15342. add_AT_flag (type_die, DW_AT_declaration, 1);
  15343. }
  15344. }
  15345. else if (! TYPE_SIZE (type))
  15346. return type_die;
  15347. else
  15348. remove_AT (type_die, DW_AT_declaration);
  15349. /* Handle a GNU C/C++ extension, i.e. incomplete enum types. If the
  15350. given enum type is incomplete, do not generate the DW_AT_byte_size
  15351. attribute or the DW_AT_element_list attribute. */
  15352. if (TYPE_SIZE (type))
  15353. {
  15354. tree link;
  15355. TREE_ASM_WRITTEN (type) = 1;
  15356. add_byte_size_attribute (type_die, type);
  15357. if (dwarf_version >= 3 || !dwarf_strict)
  15358. {
  15359. tree underlying = lang_hooks.types.enum_underlying_base_type (type);
  15360. add_type_attribute (type_die, underlying, TYPE_UNQUALIFIED,
  15361. context_die);
  15362. }
  15363. if (TYPE_STUB_DECL (type) != NULL_TREE)
  15364. {
  15365. add_src_coords_attributes (type_die, TYPE_STUB_DECL (type));
  15366. add_accessibility_attribute (type_die, TYPE_STUB_DECL (type));
  15367. }
  15368. /* If the first reference to this type was as the return type of an
  15369. inline function, then it may not have a parent. Fix this now. */
  15370. if (type_die->die_parent == NULL)
  15371. add_child_die (scope_die_for (type, context_die), type_die);
  15372. for (link = TYPE_VALUES (type);
  15373. link != NULL; link = TREE_CHAIN (link))
  15374. {
  15375. dw_die_ref enum_die = new_die (DW_TAG_enumerator, type_die, link);
  15376. tree value = TREE_VALUE (link);
  15377. add_name_attribute (enum_die,
  15378. IDENTIFIER_POINTER (TREE_PURPOSE (link)));
  15379. if (TREE_CODE (value) == CONST_DECL)
  15380. value = DECL_INITIAL (value);
  15381. if (simple_type_size_in_bits (TREE_TYPE (value))
  15382. <= HOST_BITS_PER_WIDE_INT || tree_fits_shwi_p (value))
  15383. {
  15384. /* For constant forms created by add_AT_unsigned DWARF
  15385. consumers (GDB, elfutils, etc.) always zero extend
  15386. the value. Only when the actual value is negative
  15387. do we need to use add_AT_int to generate a constant
  15388. form that can represent negative values. */
  15389. HOST_WIDE_INT val = TREE_INT_CST_LOW (value);
  15390. if (TYPE_UNSIGNED (TREE_TYPE (value)) || val >= 0)
  15391. add_AT_unsigned (enum_die, DW_AT_const_value,
  15392. (unsigned HOST_WIDE_INT) val);
  15393. else
  15394. add_AT_int (enum_die, DW_AT_const_value, val);
  15395. }
  15396. else
  15397. /* Enumeration constants may be wider than HOST_WIDE_INT. Handle
  15398. that here. TODO: This should be re-worked to use correct
  15399. signed/unsigned double tags for all cases. */
  15400. add_AT_wide (enum_die, DW_AT_const_value, value);
  15401. }
  15402. add_gnat_descriptive_type_attribute (type_die, type, context_die);
  15403. if (TYPE_ARTIFICIAL (type))
  15404. add_AT_flag (type_die, DW_AT_artificial, 1);
  15405. }
  15406. else
  15407. add_AT_flag (type_die, DW_AT_declaration, 1);
  15408. add_pubtype (type, type_die);
  15409. return type_die;
  15410. }
  15411. /* Generate a DIE to represent either a real live formal parameter decl or to
  15412. represent just the type of some formal parameter position in some function
  15413. type.
  15414. Note that this routine is a bit unusual because its argument may be a
  15415. ..._DECL node (i.e. either a PARM_DECL or perhaps a VAR_DECL which
  15416. represents an inlining of some PARM_DECL) or else some sort of a ..._TYPE
  15417. node. If it's the former then this function is being called to output a
  15418. DIE to represent a formal parameter object (or some inlining thereof). If
  15419. it's the latter, then this function is only being called to output a
  15420. DW_TAG_formal_parameter DIE to stand as a placeholder for some formal
  15421. argument type of some subprogram type.
  15422. If EMIT_NAME_P is true, name and source coordinate attributes
  15423. are emitted. */
  15424. static dw_die_ref
  15425. gen_formal_parameter_die (tree node, tree origin, bool emit_name_p,
  15426. dw_die_ref context_die)
  15427. {
  15428. tree node_or_origin = node ? node : origin;
  15429. tree ultimate_origin;
  15430. dw_die_ref parm_die
  15431. = new_die (DW_TAG_formal_parameter, context_die, node);
  15432. switch (TREE_CODE_CLASS (TREE_CODE (node_or_origin)))
  15433. {
  15434. case tcc_declaration:
  15435. ultimate_origin = decl_ultimate_origin (node_or_origin);
  15436. if (node || ultimate_origin)
  15437. origin = ultimate_origin;
  15438. if (origin != NULL)
  15439. add_abstract_origin_attribute (parm_die, origin);
  15440. else if (emit_name_p)
  15441. add_name_and_src_coords_attributes (parm_die, node);
  15442. if (origin == NULL
  15443. || (! DECL_ABSTRACT_P (node_or_origin)
  15444. && variably_modified_type_p (TREE_TYPE (node_or_origin),
  15445. decl_function_context
  15446. (node_or_origin))))
  15447. {
  15448. tree type = TREE_TYPE (node_or_origin);
  15449. if (decl_by_reference_p (node_or_origin))
  15450. add_type_attribute (parm_die, TREE_TYPE (type),
  15451. TYPE_UNQUALIFIED, context_die);
  15452. else
  15453. add_type_attribute (parm_die, type,
  15454. decl_quals (node_or_origin),
  15455. context_die);
  15456. }
  15457. if (origin == NULL && DECL_ARTIFICIAL (node))
  15458. add_AT_flag (parm_die, DW_AT_artificial, 1);
  15459. if (node && node != origin)
  15460. equate_decl_number_to_die (node, parm_die);
  15461. if (! DECL_ABSTRACT_P (node_or_origin))
  15462. add_location_or_const_value_attribute (parm_die, node_or_origin,
  15463. node == NULL, DW_AT_location);
  15464. break;
  15465. case tcc_type:
  15466. /* We were called with some kind of a ..._TYPE node. */
  15467. add_type_attribute (parm_die, node_or_origin, TYPE_UNQUALIFIED,
  15468. context_die);
  15469. break;
  15470. default:
  15471. gcc_unreachable ();
  15472. }
  15473. return parm_die;
  15474. }
  15475. /* Generate and return a DW_TAG_GNU_formal_parameter_pack. Also generate
  15476. children DW_TAG_formal_parameter DIEs representing the arguments of the
  15477. parameter pack.
  15478. PARM_PACK must be a function parameter pack.
  15479. PACK_ARG is the first argument of the parameter pack. Its TREE_CHAIN
  15480. must point to the subsequent arguments of the function PACK_ARG belongs to.
  15481. SUBR_DIE is the DIE of the function PACK_ARG belongs to.
  15482. If NEXT_ARG is non NULL, *NEXT_ARG is set to the function argument
  15483. following the last one for which a DIE was generated. */
  15484. static dw_die_ref
  15485. gen_formal_parameter_pack_die (tree parm_pack,
  15486. tree pack_arg,
  15487. dw_die_ref subr_die,
  15488. tree *next_arg)
  15489. {
  15490. tree arg;
  15491. dw_die_ref parm_pack_die;
  15492. gcc_assert (parm_pack
  15493. && lang_hooks.function_parameter_pack_p (parm_pack)
  15494. && subr_die);
  15495. parm_pack_die = new_die (DW_TAG_GNU_formal_parameter_pack, subr_die, parm_pack);
  15496. add_src_coords_attributes (parm_pack_die, parm_pack);
  15497. for (arg = pack_arg; arg; arg = DECL_CHAIN (arg))
  15498. {
  15499. if (! lang_hooks.decls.function_parm_expanded_from_pack_p (arg,
  15500. parm_pack))
  15501. break;
  15502. gen_formal_parameter_die (arg, NULL,
  15503. false /* Don't emit name attribute. */,
  15504. parm_pack_die);
  15505. }
  15506. if (next_arg)
  15507. *next_arg = arg;
  15508. return parm_pack_die;
  15509. }
  15510. /* Generate a special type of DIE used as a stand-in for a trailing ellipsis
  15511. at the end of an (ANSI prototyped) formal parameters list. */
  15512. static void
  15513. gen_unspecified_parameters_die (tree decl_or_type, dw_die_ref context_die)
  15514. {
  15515. new_die (DW_TAG_unspecified_parameters, context_die, decl_or_type);
  15516. }
  15517. /* Generate a list of nameless DW_TAG_formal_parameter DIEs (and perhaps a
  15518. DW_TAG_unspecified_parameters DIE) to represent the types of the formal
  15519. parameters as specified in some function type specification (except for
  15520. those which appear as part of a function *definition*). */
  15521. static void
  15522. gen_formal_types_die (tree function_or_method_type, dw_die_ref context_die)
  15523. {
  15524. tree link;
  15525. tree formal_type = NULL;
  15526. tree first_parm_type;
  15527. tree arg;
  15528. if (TREE_CODE (function_or_method_type) == FUNCTION_DECL)
  15529. {
  15530. arg = DECL_ARGUMENTS (function_or_method_type);
  15531. function_or_method_type = TREE_TYPE (function_or_method_type);
  15532. }
  15533. else
  15534. arg = NULL_TREE;
  15535. first_parm_type = TYPE_ARG_TYPES (function_or_method_type);
  15536. /* Make our first pass over the list of formal parameter types and output a
  15537. DW_TAG_formal_parameter DIE for each one. */
  15538. for (link = first_parm_type; link; )
  15539. {
  15540. dw_die_ref parm_die;
  15541. formal_type = TREE_VALUE (link);
  15542. if (formal_type == void_type_node)
  15543. break;
  15544. /* Output a (nameless) DIE to represent the formal parameter itself. */
  15545. if (!POINTER_BOUNDS_TYPE_P (formal_type))
  15546. {
  15547. parm_die = gen_formal_parameter_die (formal_type, NULL,
  15548. true /* Emit name attribute. */,
  15549. context_die);
  15550. if (TREE_CODE (function_or_method_type) == METHOD_TYPE
  15551. && link == first_parm_type)
  15552. {
  15553. add_AT_flag (parm_die, DW_AT_artificial, 1);
  15554. if (dwarf_version >= 3 || !dwarf_strict)
  15555. add_AT_die_ref (context_die, DW_AT_object_pointer, parm_die);
  15556. }
  15557. else if (arg && DECL_ARTIFICIAL (arg))
  15558. add_AT_flag (parm_die, DW_AT_artificial, 1);
  15559. }
  15560. link = TREE_CHAIN (link);
  15561. if (arg)
  15562. arg = DECL_CHAIN (arg);
  15563. }
  15564. /* If this function type has an ellipsis, add a
  15565. DW_TAG_unspecified_parameters DIE to the end of the parameter list. */
  15566. if (formal_type != void_type_node)
  15567. gen_unspecified_parameters_die (function_or_method_type, context_die);
  15568. /* Make our second (and final) pass over the list of formal parameter types
  15569. and output DIEs to represent those types (as necessary). */
  15570. for (link = TYPE_ARG_TYPES (function_or_method_type);
  15571. link && TREE_VALUE (link);
  15572. link = TREE_CHAIN (link))
  15573. gen_type_die (TREE_VALUE (link), context_die);
  15574. }
  15575. /* We want to generate the DIE for TYPE so that we can generate the
  15576. die for MEMBER, which has been defined; we will need to refer back
  15577. to the member declaration nested within TYPE. If we're trying to
  15578. generate minimal debug info for TYPE, processing TYPE won't do the
  15579. trick; we need to attach the member declaration by hand. */
  15580. static void
  15581. gen_type_die_for_member (tree type, tree member, dw_die_ref context_die)
  15582. {
  15583. gen_type_die (type, context_die);
  15584. /* If we're trying to avoid duplicate debug info, we may not have
  15585. emitted the member decl for this function. Emit it now. */
  15586. if (TYPE_STUB_DECL (type)
  15587. && TYPE_DECL_SUPPRESS_DEBUG (TYPE_STUB_DECL (type))
  15588. && ! lookup_decl_die (member))
  15589. {
  15590. dw_die_ref type_die;
  15591. gcc_assert (!decl_ultimate_origin (member));
  15592. push_decl_scope (type);
  15593. type_die = lookup_type_die_strip_naming_typedef (type);
  15594. if (TREE_CODE (member) == FUNCTION_DECL)
  15595. gen_subprogram_die (member, type_die);
  15596. else if (TREE_CODE (member) == FIELD_DECL)
  15597. {
  15598. /* Ignore the nameless fields that are used to skip bits but handle
  15599. C++ anonymous unions and structs. */
  15600. if (DECL_NAME (member) != NULL_TREE
  15601. || TREE_CODE (TREE_TYPE (member)) == UNION_TYPE
  15602. || TREE_CODE (TREE_TYPE (member)) == RECORD_TYPE)
  15603. {
  15604. gen_type_die (member_declared_type (member), type_die);
  15605. gen_field_die (member, type_die);
  15606. }
  15607. }
  15608. else
  15609. gen_variable_die (member, NULL_TREE, type_die);
  15610. pop_decl_scope ();
  15611. }
  15612. }
  15613. /* Forward declare these functions, because they are mutually recursive
  15614. with their set_block_* pairing functions. */
  15615. static void set_decl_origin_self (tree);
  15616. static void set_decl_abstract_flags (tree, vec<tree> &);
  15617. /* Given a pointer to some BLOCK node, if the BLOCK_ABSTRACT_ORIGIN for the
  15618. given BLOCK node is NULL, set the BLOCK_ABSTRACT_ORIGIN for the node so
  15619. that it points to the node itself, thus indicating that the node is its
  15620. own (abstract) origin. Additionally, if the BLOCK_ABSTRACT_ORIGIN for
  15621. the given node is NULL, recursively descend the decl/block tree which
  15622. it is the root of, and for each other ..._DECL or BLOCK node contained
  15623. therein whose DECL_ABSTRACT_ORIGINs or BLOCK_ABSTRACT_ORIGINs are also
  15624. still NULL, set *their* DECL_ABSTRACT_ORIGIN or BLOCK_ABSTRACT_ORIGIN
  15625. values to point to themselves. */
  15626. static void
  15627. set_block_origin_self (tree stmt)
  15628. {
  15629. if (BLOCK_ABSTRACT_ORIGIN (stmt) == NULL_TREE)
  15630. {
  15631. BLOCK_ABSTRACT_ORIGIN (stmt) = stmt;
  15632. {
  15633. tree local_decl;
  15634. for (local_decl = BLOCK_VARS (stmt);
  15635. local_decl != NULL_TREE;
  15636. local_decl = DECL_CHAIN (local_decl))
  15637. /* Do not recurse on nested functions since the inlining status
  15638. of parent and child can be different as per the DWARF spec. */
  15639. if (TREE_CODE (local_decl) != FUNCTION_DECL
  15640. && !DECL_EXTERNAL (local_decl))
  15641. set_decl_origin_self (local_decl);
  15642. }
  15643. {
  15644. tree subblock;
  15645. for (subblock = BLOCK_SUBBLOCKS (stmt);
  15646. subblock != NULL_TREE;
  15647. subblock = BLOCK_CHAIN (subblock))
  15648. set_block_origin_self (subblock); /* Recurse. */
  15649. }
  15650. }
  15651. }
  15652. /* Given a pointer to some ..._DECL node, if the DECL_ABSTRACT_ORIGIN for
  15653. the given ..._DECL node is NULL, set the DECL_ABSTRACT_ORIGIN for the
  15654. node to so that it points to the node itself, thus indicating that the
  15655. node represents its own (abstract) origin. Additionally, if the
  15656. DECL_ABSTRACT_ORIGIN for the given node is NULL, recursively descend
  15657. the decl/block tree of which the given node is the root of, and for
  15658. each other ..._DECL or BLOCK node contained therein whose
  15659. DECL_ABSTRACT_ORIGINs or BLOCK_ABSTRACT_ORIGINs are also still NULL,
  15660. set *their* DECL_ABSTRACT_ORIGIN or BLOCK_ABSTRACT_ORIGIN values to
  15661. point to themselves. */
  15662. static void
  15663. set_decl_origin_self (tree decl)
  15664. {
  15665. if (DECL_ABSTRACT_ORIGIN (decl) == NULL_TREE)
  15666. {
  15667. DECL_ABSTRACT_ORIGIN (decl) = decl;
  15668. if (TREE_CODE (decl) == FUNCTION_DECL)
  15669. {
  15670. tree arg;
  15671. for (arg = DECL_ARGUMENTS (decl); arg; arg = DECL_CHAIN (arg))
  15672. DECL_ABSTRACT_ORIGIN (arg) = arg;
  15673. if (DECL_INITIAL (decl) != NULL_TREE
  15674. && DECL_INITIAL (decl) != error_mark_node)
  15675. set_block_origin_self (DECL_INITIAL (decl));
  15676. }
  15677. }
  15678. }
  15679. /* Given a pointer to some BLOCK node, set the BLOCK_ABSTRACT flag to 1
  15680. and if it wasn't 1 before, push it to abstract_vec vector.
  15681. For all local decls and all local sub-blocks (recursively) do it
  15682. too. */
  15683. static void
  15684. set_block_abstract_flags (tree stmt, vec<tree> &abstract_vec)
  15685. {
  15686. tree local_decl;
  15687. tree subblock;
  15688. unsigned int i;
  15689. if (!BLOCK_ABSTRACT (stmt))
  15690. {
  15691. abstract_vec.safe_push (stmt);
  15692. BLOCK_ABSTRACT (stmt) = 1;
  15693. }
  15694. for (local_decl = BLOCK_VARS (stmt);
  15695. local_decl != NULL_TREE;
  15696. local_decl = DECL_CHAIN (local_decl))
  15697. if (! DECL_EXTERNAL (local_decl))
  15698. set_decl_abstract_flags (local_decl, abstract_vec);
  15699. for (i = 0; i < BLOCK_NUM_NONLOCALIZED_VARS (stmt); i++)
  15700. {
  15701. local_decl = BLOCK_NONLOCALIZED_VAR (stmt, i);
  15702. if ((TREE_CODE (local_decl) == VAR_DECL && !TREE_STATIC (local_decl))
  15703. || TREE_CODE (local_decl) == PARM_DECL)
  15704. set_decl_abstract_flags (local_decl, abstract_vec);
  15705. }
  15706. for (subblock = BLOCK_SUBBLOCKS (stmt);
  15707. subblock != NULL_TREE;
  15708. subblock = BLOCK_CHAIN (subblock))
  15709. set_block_abstract_flags (subblock, abstract_vec);
  15710. }
  15711. /* Given a pointer to some ..._DECL node, set DECL_ABSTRACT_P flag on it
  15712. to 1 and if it wasn't 1 before, push to abstract_vec vector.
  15713. In the case where the decl is a FUNCTION_DECL also set the abstract
  15714. flags for all of the parameters, local vars, local
  15715. blocks and sub-blocks (recursively). */
  15716. static void
  15717. set_decl_abstract_flags (tree decl, vec<tree> &abstract_vec)
  15718. {
  15719. if (!DECL_ABSTRACT_P (decl))
  15720. {
  15721. abstract_vec.safe_push (decl);
  15722. DECL_ABSTRACT_P (decl) = 1;
  15723. }
  15724. if (TREE_CODE (decl) == FUNCTION_DECL)
  15725. {
  15726. tree arg;
  15727. for (arg = DECL_ARGUMENTS (decl); arg; arg = DECL_CHAIN (arg))
  15728. if (!DECL_ABSTRACT_P (arg))
  15729. {
  15730. abstract_vec.safe_push (arg);
  15731. DECL_ABSTRACT_P (arg) = 1;
  15732. }
  15733. if (DECL_INITIAL (decl) != NULL_TREE
  15734. && DECL_INITIAL (decl) != error_mark_node)
  15735. set_block_abstract_flags (DECL_INITIAL (decl), abstract_vec);
  15736. }
  15737. }
  15738. /* Generate the DWARF2 info for the "abstract" instance of a function which we
  15739. may later generate inlined and/or out-of-line instances of. */
  15740. static void
  15741. dwarf2out_abstract_function (tree decl)
  15742. {
  15743. dw_die_ref old_die;
  15744. tree save_fn;
  15745. tree context;
  15746. hash_table<decl_loc_hasher> *old_decl_loc_table;
  15747. hash_table<dw_loc_list_hasher> *old_cached_dw_loc_list_table;
  15748. int old_call_site_count, old_tail_call_site_count;
  15749. struct call_arg_loc_node *old_call_arg_locations;
  15750. /* Make sure we have the actual abstract inline, not a clone. */
  15751. decl = DECL_ORIGIN (decl);
  15752. old_die = lookup_decl_die (decl);
  15753. if (old_die && get_AT (old_die, DW_AT_inline))
  15754. /* We've already generated the abstract instance. */
  15755. return;
  15756. /* We can be called while recursively when seeing block defining inlined subroutine
  15757. DIE. Be sure to not clobber the outer location table nor use it or we would
  15758. get locations in abstract instantces. */
  15759. old_decl_loc_table = decl_loc_table;
  15760. decl_loc_table = NULL;
  15761. old_cached_dw_loc_list_table = cached_dw_loc_list_table;
  15762. cached_dw_loc_list_table = NULL;
  15763. old_call_arg_locations = call_arg_locations;
  15764. call_arg_locations = NULL;
  15765. old_call_site_count = call_site_count;
  15766. call_site_count = -1;
  15767. old_tail_call_site_count = tail_call_site_count;
  15768. tail_call_site_count = -1;
  15769. /* Be sure we've emitted the in-class declaration DIE (if any) first, so
  15770. we don't get confused by DECL_ABSTRACT_P. */
  15771. if (debug_info_level > DINFO_LEVEL_TERSE)
  15772. {
  15773. context = decl_class_context (decl);
  15774. if (context)
  15775. gen_type_die_for_member
  15776. (context, decl, decl_function_context (decl) ? NULL : comp_unit_die ());
  15777. }
  15778. /* Pretend we've just finished compiling this function. */
  15779. save_fn = current_function_decl;
  15780. current_function_decl = decl;
  15781. auto_vec<tree, 64> abstract_vec;
  15782. set_decl_abstract_flags (decl, abstract_vec);
  15783. dwarf2out_decl (decl);
  15784. unsigned int i;
  15785. tree t;
  15786. FOR_EACH_VEC_ELT (abstract_vec, i, t)
  15787. if (TREE_CODE (t) == BLOCK)
  15788. BLOCK_ABSTRACT (t) = 0;
  15789. else
  15790. DECL_ABSTRACT_P (t) = 0;
  15791. current_function_decl = save_fn;
  15792. decl_loc_table = old_decl_loc_table;
  15793. cached_dw_loc_list_table = old_cached_dw_loc_list_table;
  15794. call_arg_locations = old_call_arg_locations;
  15795. call_site_count = old_call_site_count;
  15796. tail_call_site_count = old_tail_call_site_count;
  15797. }
  15798. /* Helper function of premark_used_types() which gets called through
  15799. htab_traverse.
  15800. Marks the DIE of a given type in *SLOT as perennial, so it never gets
  15801. marked as unused by prune_unused_types. */
  15802. bool
  15803. premark_used_types_helper (tree const &type, void *)
  15804. {
  15805. dw_die_ref die;
  15806. die = lookup_type_die (type);
  15807. if (die != NULL)
  15808. die->die_perennial_p = 1;
  15809. return true;
  15810. }
  15811. /* Helper function of premark_types_used_by_global_vars which gets called
  15812. through htab_traverse.
  15813. Marks the DIE of a given type in *SLOT as perennial, so it never gets
  15814. marked as unused by prune_unused_types. The DIE of the type is marked
  15815. only if the global variable using the type will actually be emitted. */
  15816. int
  15817. premark_types_used_by_global_vars_helper (types_used_by_vars_entry **slot,
  15818. void *)
  15819. {
  15820. struct types_used_by_vars_entry *entry;
  15821. dw_die_ref die;
  15822. entry = (struct types_used_by_vars_entry *) *slot;
  15823. gcc_assert (entry->type != NULL
  15824. && entry->var_decl != NULL);
  15825. die = lookup_type_die (entry->type);
  15826. if (die)
  15827. {
  15828. /* Ask cgraph if the global variable really is to be emitted.
  15829. If yes, then we'll keep the DIE of ENTRY->TYPE. */
  15830. varpool_node *node = varpool_node::get (entry->var_decl);
  15831. if (node && node->definition)
  15832. {
  15833. die->die_perennial_p = 1;
  15834. /* Keep the parent DIEs as well. */
  15835. while ((die = die->die_parent) && die->die_perennial_p == 0)
  15836. die->die_perennial_p = 1;
  15837. }
  15838. }
  15839. return 1;
  15840. }
  15841. /* Mark all members of used_types_hash as perennial. */
  15842. static void
  15843. premark_used_types (struct function *fun)
  15844. {
  15845. if (fun && fun->used_types_hash)
  15846. fun->used_types_hash->traverse<void *, premark_used_types_helper> (NULL);
  15847. }
  15848. /* Mark all members of types_used_by_vars_entry as perennial. */
  15849. static void
  15850. premark_types_used_by_global_vars (void)
  15851. {
  15852. if (types_used_by_vars_hash)
  15853. types_used_by_vars_hash
  15854. ->traverse<void *, premark_types_used_by_global_vars_helper> (NULL);
  15855. }
  15856. /* Generate a DW_TAG_GNU_call_site DIE in function DECL under SUBR_DIE
  15857. for CA_LOC call arg loc node. */
  15858. static dw_die_ref
  15859. gen_call_site_die (tree decl, dw_die_ref subr_die,
  15860. struct call_arg_loc_node *ca_loc)
  15861. {
  15862. dw_die_ref stmt_die = NULL, die;
  15863. tree block = ca_loc->block;
  15864. while (block
  15865. && block != DECL_INITIAL (decl)
  15866. && TREE_CODE (block) == BLOCK)
  15867. {
  15868. if (block_map.length () > BLOCK_NUMBER (block))
  15869. stmt_die = block_map[BLOCK_NUMBER (block)];
  15870. if (stmt_die)
  15871. break;
  15872. block = BLOCK_SUPERCONTEXT (block);
  15873. }
  15874. if (stmt_die == NULL)
  15875. stmt_die = subr_die;
  15876. die = new_die (DW_TAG_GNU_call_site, stmt_die, NULL_TREE);
  15877. add_AT_lbl_id (die, DW_AT_low_pc, ca_loc->label);
  15878. if (ca_loc->tail_call_p)
  15879. add_AT_flag (die, DW_AT_GNU_tail_call, 1);
  15880. if (ca_loc->symbol_ref)
  15881. {
  15882. dw_die_ref tdie = lookup_decl_die (SYMBOL_REF_DECL (ca_loc->symbol_ref));
  15883. if (tdie)
  15884. add_AT_die_ref (die, DW_AT_abstract_origin, tdie);
  15885. else
  15886. add_AT_addr (die, DW_AT_abstract_origin, ca_loc->symbol_ref, false);
  15887. }
  15888. return die;
  15889. }
  15890. /* Generate a DIE to represent a declared function (either file-scope or
  15891. block-local). */
  15892. static void
  15893. gen_subprogram_die (tree decl, dw_die_ref context_die)
  15894. {
  15895. tree origin = decl_ultimate_origin (decl);
  15896. dw_die_ref subr_die;
  15897. tree outer_scope;
  15898. dw_die_ref old_die = lookup_decl_die (decl);
  15899. int declaration = (current_function_decl != decl
  15900. || class_or_namespace_scope_p (context_die));
  15901. premark_used_types (DECL_STRUCT_FUNCTION (decl));
  15902. /* It is possible to have both DECL_ABSTRACT_P and DECLARATION be true if we
  15903. started to generate the abstract instance of an inline, decided to output
  15904. its containing class, and proceeded to emit the declaration of the inline
  15905. from the member list for the class. If so, DECLARATION takes priority;
  15906. we'll get back to the abstract instance when done with the class. */
  15907. /* The class-scope declaration DIE must be the primary DIE. */
  15908. if (origin && declaration && class_or_namespace_scope_p (context_die))
  15909. {
  15910. origin = NULL;
  15911. gcc_assert (!old_die);
  15912. }
  15913. /* Now that the C++ front end lazily declares artificial member fns, we
  15914. might need to retrofit the declaration into its class. */
  15915. if (!declaration && !origin && !old_die
  15916. && DECL_CONTEXT (decl) && TYPE_P (DECL_CONTEXT (decl))
  15917. && !class_or_namespace_scope_p (context_die)
  15918. && debug_info_level > DINFO_LEVEL_TERSE)
  15919. old_die = force_decl_die (decl);
  15920. if (origin != NULL)
  15921. {
  15922. gcc_assert (!declaration || local_scope_p (context_die));
  15923. /* Fixup die_parent for the abstract instance of a nested
  15924. inline function. */
  15925. if (old_die && old_die->die_parent == NULL)
  15926. add_child_die (context_die, old_die);
  15927. subr_die = new_die (DW_TAG_subprogram, context_die, decl);
  15928. add_abstract_origin_attribute (subr_die, origin);
  15929. /* This is where the actual code for a cloned function is.
  15930. Let's emit linkage name attribute for it. This helps
  15931. debuggers to e.g, set breakpoints into
  15932. constructors/destructors when the user asks "break
  15933. K::K". */
  15934. add_linkage_name (subr_die, decl);
  15935. }
  15936. else if (old_die)
  15937. {
  15938. expanded_location s = expand_location (DECL_SOURCE_LOCATION (decl));
  15939. struct dwarf_file_data * file_index = lookup_filename (s.file);
  15940. if (!get_AT_flag (old_die, DW_AT_declaration)
  15941. /* We can have a normal definition following an inline one in the
  15942. case of redefinition of GNU C extern inlines.
  15943. It seems reasonable to use AT_specification in this case. */
  15944. && !get_AT (old_die, DW_AT_inline))
  15945. {
  15946. /* Detect and ignore this case, where we are trying to output
  15947. something we have already output. */
  15948. return;
  15949. }
  15950. /* If the definition comes from the same place as the declaration,
  15951. maybe use the old DIE. We always want the DIE for this function
  15952. that has the *_pc attributes to be under comp_unit_die so the
  15953. debugger can find it. We also need to do this for abstract
  15954. instances of inlines, since the spec requires the out-of-line copy
  15955. to have the same parent. For local class methods, this doesn't
  15956. apply; we just use the old DIE. */
  15957. if ((is_cu_die (old_die->die_parent) || context_die == NULL)
  15958. && (DECL_ARTIFICIAL (decl)
  15959. || (get_AT_file (old_die, DW_AT_decl_file) == file_index
  15960. && (get_AT_unsigned (old_die, DW_AT_decl_line)
  15961. == (unsigned) s.line))))
  15962. {
  15963. subr_die = old_die;
  15964. /* Clear out the declaration attribute and the formal parameters.
  15965. Do not remove all children, because it is possible that this
  15966. declaration die was forced using force_decl_die(). In such
  15967. cases die that forced declaration die (e.g. TAG_imported_module)
  15968. is one of the children that we do not want to remove. */
  15969. remove_AT (subr_die, DW_AT_declaration);
  15970. remove_AT (subr_die, DW_AT_object_pointer);
  15971. remove_child_TAG (subr_die, DW_TAG_formal_parameter);
  15972. }
  15973. else
  15974. {
  15975. subr_die = new_die (DW_TAG_subprogram, context_die, decl);
  15976. add_AT_specification (subr_die, old_die);
  15977. add_pubname (decl, subr_die);
  15978. if (get_AT_file (old_die, DW_AT_decl_file) != file_index)
  15979. add_AT_file (subr_die, DW_AT_decl_file, file_index);
  15980. if (get_AT_unsigned (old_die, DW_AT_decl_line) != (unsigned) s.line)
  15981. add_AT_unsigned (subr_die, DW_AT_decl_line, s.line);
  15982. /* If the prototype had an 'auto' or 'decltype(auto)' return type,
  15983. emit the real type on the definition die. */
  15984. if (is_cxx() && debug_info_level > DINFO_LEVEL_TERSE)
  15985. {
  15986. dw_die_ref die = get_AT_ref (old_die, DW_AT_type);
  15987. if (die == auto_die || die == decltype_auto_die)
  15988. add_type_attribute (subr_die, TREE_TYPE (TREE_TYPE (decl)),
  15989. TYPE_UNQUALIFIED, context_die);
  15990. }
  15991. }
  15992. }
  15993. else
  15994. {
  15995. subr_die = new_die (DW_TAG_subprogram, context_die, decl);
  15996. if (TREE_PUBLIC (decl))
  15997. add_AT_flag (subr_die, DW_AT_external, 1);
  15998. add_name_and_src_coords_attributes (subr_die, decl);
  15999. add_pubname (decl, subr_die);
  16000. if (debug_info_level > DINFO_LEVEL_TERSE)
  16001. {
  16002. add_prototyped_attribute (subr_die, TREE_TYPE (decl));
  16003. add_type_attribute (subr_die, TREE_TYPE (TREE_TYPE (decl)),
  16004. TYPE_UNQUALIFIED, context_die);
  16005. }
  16006. add_pure_or_virtual_attribute (subr_die, decl);
  16007. if (DECL_ARTIFICIAL (decl))
  16008. add_AT_flag (subr_die, DW_AT_artificial, 1);
  16009. if (TREE_THIS_VOLATILE (decl) && (dwarf_version >= 5 || !dwarf_strict))
  16010. add_AT_flag (subr_die, DW_AT_noreturn, 1);
  16011. add_accessibility_attribute (subr_die, decl);
  16012. }
  16013. if (declaration)
  16014. {
  16015. if (!old_die || !get_AT (old_die, DW_AT_inline))
  16016. {
  16017. add_AT_flag (subr_die, DW_AT_declaration, 1);
  16018. /* If this is an explicit function declaration then generate
  16019. a DW_AT_explicit attribute. */
  16020. if (lang_hooks.decls.function_decl_explicit_p (decl)
  16021. && (dwarf_version >= 3 || !dwarf_strict))
  16022. add_AT_flag (subr_die, DW_AT_explicit, 1);
  16023. /* If this is a C++11 deleted special function member then generate
  16024. a DW_AT_GNU_deleted attribute. */
  16025. if (lang_hooks.decls.function_decl_deleted_p (decl)
  16026. && (! dwarf_strict))
  16027. add_AT_flag (subr_die, DW_AT_GNU_deleted, 1);
  16028. /* The first time we see a member function, it is in the context of
  16029. the class to which it belongs. We make sure of this by emitting
  16030. the class first. The next time is the definition, which is
  16031. handled above. The two may come from the same source text.
  16032. Note that force_decl_die() forces function declaration die. It is
  16033. later reused to represent definition. */
  16034. equate_decl_number_to_die (decl, subr_die);
  16035. }
  16036. }
  16037. else if (DECL_ABSTRACT_P (decl))
  16038. {
  16039. if (DECL_DECLARED_INLINE_P (decl))
  16040. {
  16041. if (cgraph_function_possibly_inlined_p (decl))
  16042. add_AT_unsigned (subr_die, DW_AT_inline, DW_INL_declared_inlined);
  16043. else
  16044. add_AT_unsigned (subr_die, DW_AT_inline, DW_INL_declared_not_inlined);
  16045. }
  16046. else
  16047. {
  16048. if (cgraph_function_possibly_inlined_p (decl))
  16049. add_AT_unsigned (subr_die, DW_AT_inline, DW_INL_inlined);
  16050. else
  16051. add_AT_unsigned (subr_die, DW_AT_inline, DW_INL_not_inlined);
  16052. }
  16053. if (DECL_DECLARED_INLINE_P (decl)
  16054. && lookup_attribute ("artificial", DECL_ATTRIBUTES (decl)))
  16055. add_AT_flag (subr_die, DW_AT_artificial, 1);
  16056. equate_decl_number_to_die (decl, subr_die);
  16057. }
  16058. else if (!DECL_EXTERNAL (decl))
  16059. {
  16060. HOST_WIDE_INT cfa_fb_offset;
  16061. struct function *fun = DECL_STRUCT_FUNCTION (decl);
  16062. if (!old_die || !get_AT (old_die, DW_AT_inline))
  16063. equate_decl_number_to_die (decl, subr_die);
  16064. gcc_checking_assert (fun);
  16065. if (!flag_reorder_blocks_and_partition)
  16066. {
  16067. dw_fde_ref fde = fun->fde;
  16068. if (fde->dw_fde_begin)
  16069. {
  16070. /* We have already generated the labels. */
  16071. add_AT_low_high_pc (subr_die, fde->dw_fde_begin,
  16072. fde->dw_fde_end, false);
  16073. }
  16074. else
  16075. {
  16076. /* Create start/end labels and add the range. */
  16077. char label_id_low[MAX_ARTIFICIAL_LABEL_BYTES];
  16078. char label_id_high[MAX_ARTIFICIAL_LABEL_BYTES];
  16079. ASM_GENERATE_INTERNAL_LABEL (label_id_low, FUNC_BEGIN_LABEL,
  16080. current_function_funcdef_no);
  16081. ASM_GENERATE_INTERNAL_LABEL (label_id_high, FUNC_END_LABEL,
  16082. current_function_funcdef_no);
  16083. add_AT_low_high_pc (subr_die, label_id_low, label_id_high,
  16084. false);
  16085. }
  16086. #if VMS_DEBUGGING_INFO
  16087. /* HP OpenVMS Industry Standard 64: DWARF Extensions
  16088. Section 2.3 Prologue and Epilogue Attributes:
  16089. When a breakpoint is set on entry to a function, it is generally
  16090. desirable for execution to be suspended, not on the very first
  16091. instruction of the function, but rather at a point after the
  16092. function's frame has been set up, after any language defined local
  16093. declaration processing has been completed, and before execution of
  16094. the first statement of the function begins. Debuggers generally
  16095. cannot properly determine where this point is. Similarly for a
  16096. breakpoint set on exit from a function. The prologue and epilogue
  16097. attributes allow a compiler to communicate the location(s) to use. */
  16098. {
  16099. if (fde->dw_fde_vms_end_prologue)
  16100. add_AT_vms_delta (subr_die, DW_AT_HP_prologue,
  16101. fde->dw_fde_begin, fde->dw_fde_vms_end_prologue);
  16102. if (fde->dw_fde_vms_begin_epilogue)
  16103. add_AT_vms_delta (subr_die, DW_AT_HP_epilogue,
  16104. fde->dw_fde_begin, fde->dw_fde_vms_begin_epilogue);
  16105. }
  16106. #endif
  16107. }
  16108. else
  16109. {
  16110. /* Generate pubnames entries for the split function code ranges. */
  16111. dw_fde_ref fde = fun->fde;
  16112. if (fde->dw_fde_second_begin)
  16113. {
  16114. if (dwarf_version >= 3 || !dwarf_strict)
  16115. {
  16116. /* We should use ranges for non-contiguous code section
  16117. addresses. Use the actual code range for the initial
  16118. section, since the HOT/COLD labels might precede an
  16119. alignment offset. */
  16120. bool range_list_added = false;
  16121. add_ranges_by_labels (subr_die, fde->dw_fde_begin,
  16122. fde->dw_fde_end, &range_list_added,
  16123. false);
  16124. add_ranges_by_labels (subr_die, fde->dw_fde_second_begin,
  16125. fde->dw_fde_second_end,
  16126. &range_list_added, false);
  16127. if (range_list_added)
  16128. add_ranges (NULL);
  16129. }
  16130. else
  16131. {
  16132. /* There is no real support in DW2 for this .. so we make
  16133. a work-around. First, emit the pub name for the segment
  16134. containing the function label. Then make and emit a
  16135. simplified subprogram DIE for the second segment with the
  16136. name pre-fixed by __hot/cold_sect_of_. We use the same
  16137. linkage name for the second die so that gdb will find both
  16138. sections when given "b foo". */
  16139. const char *name = NULL;
  16140. tree decl_name = DECL_NAME (decl);
  16141. dw_die_ref seg_die;
  16142. /* Do the 'primary' section. */
  16143. add_AT_low_high_pc (subr_die, fde->dw_fde_begin,
  16144. fde->dw_fde_end, false);
  16145. /* Build a minimal DIE for the secondary section. */
  16146. seg_die = new_die (DW_TAG_subprogram,
  16147. subr_die->die_parent, decl);
  16148. if (TREE_PUBLIC (decl))
  16149. add_AT_flag (seg_die, DW_AT_external, 1);
  16150. if (decl_name != NULL
  16151. && IDENTIFIER_POINTER (decl_name) != NULL)
  16152. {
  16153. name = dwarf2_name (decl, 1);
  16154. if (! DECL_ARTIFICIAL (decl))
  16155. add_src_coords_attributes (seg_die, decl);
  16156. add_linkage_name (seg_die, decl);
  16157. }
  16158. gcc_assert (name != NULL);
  16159. add_pure_or_virtual_attribute (seg_die, decl);
  16160. if (DECL_ARTIFICIAL (decl))
  16161. add_AT_flag (seg_die, DW_AT_artificial, 1);
  16162. name = concat ("__second_sect_of_", name, NULL);
  16163. add_AT_low_high_pc (seg_die, fde->dw_fde_second_begin,
  16164. fde->dw_fde_second_end, false);
  16165. add_name_attribute (seg_die, name);
  16166. if (want_pubnames ())
  16167. add_pubname_string (name, seg_die);
  16168. }
  16169. }
  16170. else
  16171. add_AT_low_high_pc (subr_die, fde->dw_fde_begin, fde->dw_fde_end,
  16172. false);
  16173. }
  16174. cfa_fb_offset = CFA_FRAME_BASE_OFFSET (decl);
  16175. /* We define the "frame base" as the function's CFA. This is more
  16176. convenient for several reasons: (1) It's stable across the prologue
  16177. and epilogue, which makes it better than just a frame pointer,
  16178. (2) With dwarf3, there exists a one-byte encoding that allows us
  16179. to reference the .debug_frame data by proxy, but failing that,
  16180. (3) We can at least reuse the code inspection and interpretation
  16181. code that determines the CFA position at various points in the
  16182. function. */
  16183. if (dwarf_version >= 3 && targetm.debug_unwind_info () == UI_DWARF2)
  16184. {
  16185. dw_loc_descr_ref op = new_loc_descr (DW_OP_call_frame_cfa, 0, 0);
  16186. add_AT_loc (subr_die, DW_AT_frame_base, op);
  16187. }
  16188. else
  16189. {
  16190. dw_loc_list_ref list = convert_cfa_to_fb_loc_list (cfa_fb_offset);
  16191. if (list->dw_loc_next)
  16192. add_AT_loc_list (subr_die, DW_AT_frame_base, list);
  16193. else
  16194. add_AT_loc (subr_die, DW_AT_frame_base, list->expr);
  16195. }
  16196. /* Compute a displacement from the "steady-state frame pointer" to
  16197. the CFA. The former is what all stack slots and argument slots
  16198. will reference in the rtl; the latter is what we've told the
  16199. debugger about. We'll need to adjust all frame_base references
  16200. by this displacement. */
  16201. compute_frame_pointer_to_fb_displacement (cfa_fb_offset);
  16202. if (fun->static_chain_decl)
  16203. add_AT_location_description (subr_die, DW_AT_static_link,
  16204. loc_list_from_tree (fun->static_chain_decl, 2, NULL));
  16205. }
  16206. /* Generate child dies for template paramaters. */
  16207. if (debug_info_level > DINFO_LEVEL_TERSE)
  16208. gen_generic_params_dies (decl);
  16209. /* Now output descriptions of the arguments for this function. This gets
  16210. (unnecessarily?) complex because of the fact that the DECL_ARGUMENT list
  16211. for a FUNCTION_DECL doesn't indicate cases where there was a trailing
  16212. `...' at the end of the formal parameter list. In order to find out if
  16213. there was a trailing ellipsis or not, we must instead look at the type
  16214. associated with the FUNCTION_DECL. This will be a node of type
  16215. FUNCTION_TYPE. If the chain of type nodes hanging off of this
  16216. FUNCTION_TYPE node ends with a void_type_node then there should *not* be
  16217. an ellipsis at the end. */
  16218. /* In the case where we are describing a mere function declaration, all we
  16219. need to do here (and all we *can* do here) is to describe the *types* of
  16220. its formal parameters. */
  16221. if (debug_info_level <= DINFO_LEVEL_TERSE)
  16222. ;
  16223. else if (declaration)
  16224. gen_formal_types_die (decl, subr_die);
  16225. else
  16226. {
  16227. /* Generate DIEs to represent all known formal parameters. */
  16228. tree parm = DECL_ARGUMENTS (decl);
  16229. tree generic_decl = lang_hooks.decls.get_generic_function_decl (decl);
  16230. tree generic_decl_parm = generic_decl
  16231. ? DECL_ARGUMENTS (generic_decl)
  16232. : NULL;
  16233. /* Now we want to walk the list of parameters of the function and
  16234. emit their relevant DIEs.
  16235. We consider the case of DECL being an instance of a generic function
  16236. as well as it being a normal function.
  16237. If DECL is an instance of a generic function we walk the
  16238. parameters of the generic function declaration _and_ the parameters of
  16239. DECL itself. This is useful because we want to emit specific DIEs for
  16240. function parameter packs and those are declared as part of the
  16241. generic function declaration. In that particular case,
  16242. the parameter pack yields a DW_TAG_GNU_formal_parameter_pack DIE.
  16243. That DIE has children DIEs representing the set of arguments
  16244. of the pack. Note that the set of pack arguments can be empty.
  16245. In that case, the DW_TAG_GNU_formal_parameter_pack DIE will not have any
  16246. children DIE.
  16247. Otherwise, we just consider the parameters of DECL. */
  16248. while (generic_decl_parm || parm)
  16249. {
  16250. if (generic_decl_parm
  16251. && lang_hooks.function_parameter_pack_p (generic_decl_parm))
  16252. gen_formal_parameter_pack_die (generic_decl_parm,
  16253. parm, subr_die,
  16254. &parm);
  16255. else if (parm && !POINTER_BOUNDS_P (parm))
  16256. {
  16257. dw_die_ref parm_die = gen_decl_die (parm, NULL, subr_die);
  16258. if (parm == DECL_ARGUMENTS (decl)
  16259. && TREE_CODE (TREE_TYPE (decl)) == METHOD_TYPE
  16260. && parm_die
  16261. && (dwarf_version >= 3 || !dwarf_strict))
  16262. add_AT_die_ref (subr_die, DW_AT_object_pointer, parm_die);
  16263. parm = DECL_CHAIN (parm);
  16264. }
  16265. else if (parm)
  16266. parm = DECL_CHAIN (parm);
  16267. if (generic_decl_parm)
  16268. generic_decl_parm = DECL_CHAIN (generic_decl_parm);
  16269. }
  16270. /* Decide whether we need an unspecified_parameters DIE at the end.
  16271. There are 2 more cases to do this for: 1) the ansi ... declaration -
  16272. this is detectable when the end of the arg list is not a
  16273. void_type_node 2) an unprototyped function declaration (not a
  16274. definition). This just means that we have no info about the
  16275. parameters at all. */
  16276. if (prototype_p (TREE_TYPE (decl)))
  16277. {
  16278. /* This is the prototyped case, check for.... */
  16279. if (stdarg_p (TREE_TYPE (decl)))
  16280. gen_unspecified_parameters_die (decl, subr_die);
  16281. }
  16282. else if (DECL_INITIAL (decl) == NULL_TREE)
  16283. gen_unspecified_parameters_die (decl, subr_die);
  16284. }
  16285. /* Output Dwarf info for all of the stuff within the body of the function
  16286. (if it has one - it may be just a declaration). */
  16287. outer_scope = DECL_INITIAL (decl);
  16288. /* OUTER_SCOPE is a pointer to the outermost BLOCK node created to represent
  16289. a function. This BLOCK actually represents the outermost binding contour
  16290. for the function, i.e. the contour in which the function's formal
  16291. parameters and labels get declared. Curiously, it appears that the front
  16292. end doesn't actually put the PARM_DECL nodes for the current function onto
  16293. the BLOCK_VARS list for this outer scope, but are strung off of the
  16294. DECL_ARGUMENTS list for the function instead.
  16295. The BLOCK_VARS list for the `outer_scope' does provide us with a list of
  16296. the LABEL_DECL nodes for the function however, and we output DWARF info
  16297. for those in decls_for_scope. Just within the `outer_scope' there will be
  16298. a BLOCK node representing the function's outermost pair of curly braces,
  16299. and any blocks used for the base and member initializers of a C++
  16300. constructor function. */
  16301. if (! declaration && outer_scope && TREE_CODE (outer_scope) != ERROR_MARK)
  16302. {
  16303. int call_site_note_count = 0;
  16304. int tail_call_site_note_count = 0;
  16305. /* Emit a DW_TAG_variable DIE for a named return value. */
  16306. if (DECL_NAME (DECL_RESULT (decl)))
  16307. gen_decl_die (DECL_RESULT (decl), NULL, subr_die);
  16308. decls_for_scope (outer_scope, subr_die);
  16309. if (call_arg_locations && !dwarf_strict)
  16310. {
  16311. struct call_arg_loc_node *ca_loc;
  16312. for (ca_loc = call_arg_locations; ca_loc; ca_loc = ca_loc->next)
  16313. {
  16314. dw_die_ref die = NULL;
  16315. rtx tloc = NULL_RTX, tlocc = NULL_RTX;
  16316. rtx arg, next_arg;
  16317. for (arg = NOTE_VAR_LOCATION (ca_loc->call_arg_loc_note);
  16318. arg; arg = next_arg)
  16319. {
  16320. dw_loc_descr_ref reg, val;
  16321. machine_mode mode = GET_MODE (XEXP (XEXP (arg, 0), 1));
  16322. dw_die_ref cdie, tdie = NULL;
  16323. next_arg = XEXP (arg, 1);
  16324. if (REG_P (XEXP (XEXP (arg, 0), 0))
  16325. && next_arg
  16326. && MEM_P (XEXP (XEXP (next_arg, 0), 0))
  16327. && REG_P (XEXP (XEXP (XEXP (next_arg, 0), 0), 0))
  16328. && REGNO (XEXP (XEXP (arg, 0), 0))
  16329. == REGNO (XEXP (XEXP (XEXP (next_arg, 0), 0), 0)))
  16330. next_arg = XEXP (next_arg, 1);
  16331. if (mode == VOIDmode)
  16332. {
  16333. mode = GET_MODE (XEXP (XEXP (arg, 0), 0));
  16334. if (mode == VOIDmode)
  16335. mode = GET_MODE (XEXP (arg, 0));
  16336. }
  16337. if (mode == VOIDmode || mode == BLKmode)
  16338. continue;
  16339. if (XEXP (XEXP (arg, 0), 0) == pc_rtx)
  16340. {
  16341. gcc_assert (ca_loc->symbol_ref == NULL_RTX);
  16342. tloc = XEXP (XEXP (arg, 0), 1);
  16343. continue;
  16344. }
  16345. else if (GET_CODE (XEXP (XEXP (arg, 0), 0)) == CLOBBER
  16346. && XEXP (XEXP (XEXP (arg, 0), 0), 0) == pc_rtx)
  16347. {
  16348. gcc_assert (ca_loc->symbol_ref == NULL_RTX);
  16349. tlocc = XEXP (XEXP (arg, 0), 1);
  16350. continue;
  16351. }
  16352. reg = NULL;
  16353. if (REG_P (XEXP (XEXP (arg, 0), 0)))
  16354. reg = reg_loc_descriptor (XEXP (XEXP (arg, 0), 0),
  16355. VAR_INIT_STATUS_INITIALIZED);
  16356. else if (MEM_P (XEXP (XEXP (arg, 0), 0)))
  16357. {
  16358. rtx mem = XEXP (XEXP (arg, 0), 0);
  16359. reg = mem_loc_descriptor (XEXP (mem, 0),
  16360. get_address_mode (mem),
  16361. GET_MODE (mem),
  16362. VAR_INIT_STATUS_INITIALIZED);
  16363. }
  16364. else if (GET_CODE (XEXP (XEXP (arg, 0), 0))
  16365. == DEBUG_PARAMETER_REF)
  16366. {
  16367. tree tdecl
  16368. = DEBUG_PARAMETER_REF_DECL (XEXP (XEXP (arg, 0), 0));
  16369. tdie = lookup_decl_die (tdecl);
  16370. if (tdie == NULL)
  16371. continue;
  16372. }
  16373. else
  16374. continue;
  16375. if (reg == NULL
  16376. && GET_CODE (XEXP (XEXP (arg, 0), 0))
  16377. != DEBUG_PARAMETER_REF)
  16378. continue;
  16379. val = mem_loc_descriptor (XEXP (XEXP (arg, 0), 1), mode,
  16380. VOIDmode,
  16381. VAR_INIT_STATUS_INITIALIZED);
  16382. if (val == NULL)
  16383. continue;
  16384. if (die == NULL)
  16385. die = gen_call_site_die (decl, subr_die, ca_loc);
  16386. cdie = new_die (DW_TAG_GNU_call_site_parameter, die,
  16387. NULL_TREE);
  16388. if (reg != NULL)
  16389. add_AT_loc (cdie, DW_AT_location, reg);
  16390. else if (tdie != NULL)
  16391. add_AT_die_ref (cdie, DW_AT_abstract_origin, tdie);
  16392. add_AT_loc (cdie, DW_AT_GNU_call_site_value, val);
  16393. if (next_arg != XEXP (arg, 1))
  16394. {
  16395. mode = GET_MODE (XEXP (XEXP (XEXP (arg, 1), 0), 1));
  16396. if (mode == VOIDmode)
  16397. mode = GET_MODE (XEXP (XEXP (XEXP (arg, 1), 0), 0));
  16398. val = mem_loc_descriptor (XEXP (XEXP (XEXP (arg, 1),
  16399. 0), 1),
  16400. mode, VOIDmode,
  16401. VAR_INIT_STATUS_INITIALIZED);
  16402. if (val != NULL)
  16403. add_AT_loc (cdie, DW_AT_GNU_call_site_data_value, val);
  16404. }
  16405. }
  16406. if (die == NULL
  16407. && (ca_loc->symbol_ref || tloc))
  16408. die = gen_call_site_die (decl, subr_die, ca_loc);
  16409. if (die != NULL && (tloc != NULL_RTX || tlocc != NULL_RTX))
  16410. {
  16411. dw_loc_descr_ref tval = NULL;
  16412. if (tloc != NULL_RTX)
  16413. tval = mem_loc_descriptor (tloc,
  16414. GET_MODE (tloc) == VOIDmode
  16415. ? Pmode : GET_MODE (tloc),
  16416. VOIDmode,
  16417. VAR_INIT_STATUS_INITIALIZED);
  16418. if (tval)
  16419. add_AT_loc (die, DW_AT_GNU_call_site_target, tval);
  16420. else if (tlocc != NULL_RTX)
  16421. {
  16422. tval = mem_loc_descriptor (tlocc,
  16423. GET_MODE (tlocc) == VOIDmode
  16424. ? Pmode : GET_MODE (tlocc),
  16425. VOIDmode,
  16426. VAR_INIT_STATUS_INITIALIZED);
  16427. if (tval)
  16428. add_AT_loc (die, DW_AT_GNU_call_site_target_clobbered,
  16429. tval);
  16430. }
  16431. }
  16432. if (die != NULL)
  16433. {
  16434. call_site_note_count++;
  16435. if (ca_loc->tail_call_p)
  16436. tail_call_site_note_count++;
  16437. }
  16438. }
  16439. }
  16440. call_arg_locations = NULL;
  16441. call_arg_loc_last = NULL;
  16442. if (tail_call_site_count >= 0
  16443. && tail_call_site_count == tail_call_site_note_count
  16444. && !dwarf_strict)
  16445. {
  16446. if (call_site_count >= 0
  16447. && call_site_count == call_site_note_count)
  16448. add_AT_flag (subr_die, DW_AT_GNU_all_call_sites, 1);
  16449. else
  16450. add_AT_flag (subr_die, DW_AT_GNU_all_tail_call_sites, 1);
  16451. }
  16452. call_site_count = -1;
  16453. tail_call_site_count = -1;
  16454. }
  16455. if (subr_die != old_die)
  16456. /* Add the calling convention attribute if requested. */
  16457. add_calling_convention_attribute (subr_die, decl);
  16458. }
  16459. /* Returns a hash value for X (which really is a die_struct). */
  16460. hashval_t
  16461. block_die_hasher::hash (die_struct *d)
  16462. {
  16463. return (hashval_t) d->decl_id ^ htab_hash_pointer (d->die_parent);
  16464. }
  16465. /* Return nonzero if decl_id and die_parent of die_struct X is the same
  16466. as decl_id and die_parent of die_struct Y. */
  16467. bool
  16468. block_die_hasher::equal (die_struct *x, die_struct *y)
  16469. {
  16470. return x->decl_id == y->decl_id && x->die_parent == y->die_parent;
  16471. }
  16472. /* Generate a DIE to represent a declared data object.
  16473. Either DECL or ORIGIN must be non-null. */
  16474. static void
  16475. gen_variable_die (tree decl, tree origin, dw_die_ref context_die)
  16476. {
  16477. HOST_WIDE_INT off = 0;
  16478. tree com_decl;
  16479. tree decl_or_origin = decl ? decl : origin;
  16480. tree ultimate_origin;
  16481. dw_die_ref var_die;
  16482. dw_die_ref old_die = decl ? lookup_decl_die (decl) : NULL;
  16483. dw_die_ref origin_die;
  16484. bool declaration = (DECL_EXTERNAL (decl_or_origin)
  16485. || class_or_namespace_scope_p (context_die));
  16486. bool specialization_p = false;
  16487. ultimate_origin = decl_ultimate_origin (decl_or_origin);
  16488. if (decl || ultimate_origin)
  16489. origin = ultimate_origin;
  16490. com_decl = fortran_common (decl_or_origin, &off);
  16491. /* Symbol in common gets emitted as a child of the common block, in the form
  16492. of a data member. */
  16493. if (com_decl)
  16494. {
  16495. dw_die_ref com_die;
  16496. dw_loc_list_ref loc;
  16497. die_node com_die_arg;
  16498. var_die = lookup_decl_die (decl_or_origin);
  16499. if (var_die)
  16500. {
  16501. if (get_AT (var_die, DW_AT_location) == NULL)
  16502. {
  16503. loc = loc_list_from_tree (com_decl, off ? 1 : 2, NULL);
  16504. if (loc)
  16505. {
  16506. if (off)
  16507. {
  16508. /* Optimize the common case. */
  16509. if (single_element_loc_list_p (loc)
  16510. && loc->expr->dw_loc_opc == DW_OP_addr
  16511. && loc->expr->dw_loc_next == NULL
  16512. && GET_CODE (loc->expr->dw_loc_oprnd1.v.val_addr)
  16513. == SYMBOL_REF)
  16514. {
  16515. rtx x = loc->expr->dw_loc_oprnd1.v.val_addr;
  16516. loc->expr->dw_loc_oprnd1.v.val_addr
  16517. = plus_constant (GET_MODE (x), x , off);
  16518. }
  16519. else
  16520. loc_list_plus_const (loc, off);
  16521. }
  16522. add_AT_location_description (var_die, DW_AT_location, loc);
  16523. remove_AT (var_die, DW_AT_declaration);
  16524. }
  16525. }
  16526. return;
  16527. }
  16528. if (common_block_die_table == NULL)
  16529. common_block_die_table = hash_table<block_die_hasher>::create_ggc (10);
  16530. com_die_arg.decl_id = DECL_UID (com_decl);
  16531. com_die_arg.die_parent = context_die;
  16532. com_die = common_block_die_table->find (&com_die_arg);
  16533. loc = loc_list_from_tree (com_decl, 2, NULL);
  16534. if (com_die == NULL)
  16535. {
  16536. const char *cnam
  16537. = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (com_decl));
  16538. die_node **slot;
  16539. com_die = new_die (DW_TAG_common_block, context_die, decl);
  16540. add_name_and_src_coords_attributes (com_die, com_decl);
  16541. if (loc)
  16542. {
  16543. add_AT_location_description (com_die, DW_AT_location, loc);
  16544. /* Avoid sharing the same loc descriptor between
  16545. DW_TAG_common_block and DW_TAG_variable. */
  16546. loc = loc_list_from_tree (com_decl, 2, NULL);
  16547. }
  16548. else if (DECL_EXTERNAL (decl))
  16549. add_AT_flag (com_die, DW_AT_declaration, 1);
  16550. if (want_pubnames ())
  16551. add_pubname_string (cnam, com_die); /* ??? needed? */
  16552. com_die->decl_id = DECL_UID (com_decl);
  16553. slot = common_block_die_table->find_slot (com_die, INSERT);
  16554. *slot = com_die;
  16555. }
  16556. else if (get_AT (com_die, DW_AT_location) == NULL && loc)
  16557. {
  16558. add_AT_location_description (com_die, DW_AT_location, loc);
  16559. loc = loc_list_from_tree (com_decl, 2, NULL);
  16560. remove_AT (com_die, DW_AT_declaration);
  16561. }
  16562. var_die = new_die (DW_TAG_variable, com_die, decl);
  16563. add_name_and_src_coords_attributes (var_die, decl);
  16564. add_type_attribute (var_die, TREE_TYPE (decl), decl_quals (decl),
  16565. context_die);
  16566. add_AT_flag (var_die, DW_AT_external, 1);
  16567. if (loc)
  16568. {
  16569. if (off)
  16570. {
  16571. /* Optimize the common case. */
  16572. if (single_element_loc_list_p (loc)
  16573. && loc->expr->dw_loc_opc == DW_OP_addr
  16574. && loc->expr->dw_loc_next == NULL
  16575. && GET_CODE (loc->expr->dw_loc_oprnd1.v.val_addr) == SYMBOL_REF)
  16576. {
  16577. rtx x = loc->expr->dw_loc_oprnd1.v.val_addr;
  16578. loc->expr->dw_loc_oprnd1.v.val_addr
  16579. = plus_constant (GET_MODE (x), x, off);
  16580. }
  16581. else
  16582. loc_list_plus_const (loc, off);
  16583. }
  16584. add_AT_location_description (var_die, DW_AT_location, loc);
  16585. }
  16586. else if (DECL_EXTERNAL (decl))
  16587. add_AT_flag (var_die, DW_AT_declaration, 1);
  16588. equate_decl_number_to_die (decl, var_die);
  16589. return;
  16590. }
  16591. /* If the compiler emitted a definition for the DECL declaration
  16592. and if we already emitted a DIE for it, don't emit a second
  16593. DIE for it again. Allow re-declarations of DECLs that are
  16594. inside functions, though. */
  16595. if (old_die && declaration && !local_scope_p (context_die))
  16596. return;
  16597. /* For static data members, the declaration in the class is supposed
  16598. to have DW_TAG_member tag; the specification should still be
  16599. DW_TAG_variable referencing the DW_TAG_member DIE. */
  16600. if (declaration && class_scope_p (context_die))
  16601. var_die = new_die (DW_TAG_member, context_die, decl);
  16602. else
  16603. var_die = new_die (DW_TAG_variable, context_die, decl);
  16604. origin_die = NULL;
  16605. if (origin != NULL)
  16606. origin_die = add_abstract_origin_attribute (var_die, origin);
  16607. /* Loop unrolling can create multiple blocks that refer to the same
  16608. static variable, so we must test for the DW_AT_declaration flag.
  16609. ??? Loop unrolling/reorder_blocks should perhaps be rewritten to
  16610. copy decls and set the DECL_ABSTRACT_P flag on them instead of
  16611. sharing them.
  16612. ??? Duplicated blocks have been rewritten to use .debug_ranges.
  16613. ??? The declare_in_namespace support causes us to get two DIEs for one
  16614. variable, both of which are declarations. We want to avoid considering
  16615. one to be a specification, so we must test that this DIE is not a
  16616. declaration. */
  16617. else if (old_die && TREE_STATIC (decl) && ! declaration
  16618. && get_AT_flag (old_die, DW_AT_declaration) == 1)
  16619. {
  16620. /* This is a definition of a C++ class level static. */
  16621. add_AT_specification (var_die, old_die);
  16622. specialization_p = true;
  16623. if (DECL_NAME (decl))
  16624. {
  16625. expanded_location s = expand_location (DECL_SOURCE_LOCATION (decl));
  16626. struct dwarf_file_data * file_index = lookup_filename (s.file);
  16627. if (get_AT_file (old_die, DW_AT_decl_file) != file_index)
  16628. add_AT_file (var_die, DW_AT_decl_file, file_index);
  16629. if (get_AT_unsigned (old_die, DW_AT_decl_line) != (unsigned) s.line)
  16630. add_AT_unsigned (var_die, DW_AT_decl_line, s.line);
  16631. if (old_die->die_tag == DW_TAG_member)
  16632. add_linkage_name (var_die, decl);
  16633. }
  16634. }
  16635. else
  16636. add_name_and_src_coords_attributes (var_die, decl);
  16637. if ((origin == NULL && !specialization_p)
  16638. || (origin != NULL
  16639. && !DECL_ABSTRACT_P (decl_or_origin)
  16640. && variably_modified_type_p (TREE_TYPE (decl_or_origin),
  16641. decl_function_context
  16642. (decl_or_origin))))
  16643. {
  16644. tree type = TREE_TYPE (decl_or_origin);
  16645. if (decl_by_reference_p (decl_or_origin))
  16646. add_type_attribute (var_die, TREE_TYPE (type), TYPE_UNQUALIFIED,
  16647. context_die);
  16648. else
  16649. add_type_attribute (var_die, type, decl_quals (decl_or_origin),
  16650. context_die);
  16651. }
  16652. if (origin == NULL && !specialization_p)
  16653. {
  16654. if (TREE_PUBLIC (decl))
  16655. add_AT_flag (var_die, DW_AT_external, 1);
  16656. if (DECL_ARTIFICIAL (decl))
  16657. add_AT_flag (var_die, DW_AT_artificial, 1);
  16658. add_accessibility_attribute (var_die, decl);
  16659. }
  16660. if (declaration)
  16661. add_AT_flag (var_die, DW_AT_declaration, 1);
  16662. if (decl && (DECL_ABSTRACT_P (decl) || declaration || old_die == NULL))
  16663. equate_decl_number_to_die (decl, var_die);
  16664. if (! declaration
  16665. && (! DECL_ABSTRACT_P (decl_or_origin)
  16666. /* Local static vars are shared between all clones/inlines,
  16667. so emit DW_AT_location on the abstract DIE if DECL_RTL is
  16668. already set. */
  16669. || (TREE_CODE (decl_or_origin) == VAR_DECL
  16670. && TREE_STATIC (decl_or_origin)
  16671. && DECL_RTL_SET_P (decl_or_origin)))
  16672. /* When abstract origin already has DW_AT_location attribute, no need
  16673. to add it again. */
  16674. && (origin_die == NULL || get_AT (origin_die, DW_AT_location) == NULL))
  16675. {
  16676. if (TREE_CODE (decl_or_origin) == VAR_DECL && TREE_STATIC (decl_or_origin)
  16677. && !TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (decl_or_origin)))
  16678. defer_location (decl_or_origin, var_die);
  16679. else
  16680. add_location_or_const_value_attribute (var_die, decl_or_origin,
  16681. decl == NULL, DW_AT_location);
  16682. add_pubname (decl_or_origin, var_die);
  16683. }
  16684. else
  16685. tree_add_const_value_attribute_for_decl (var_die, decl_or_origin);
  16686. }
  16687. /* Generate a DIE to represent a named constant. */
  16688. static void
  16689. gen_const_die (tree decl, dw_die_ref context_die)
  16690. {
  16691. dw_die_ref const_die;
  16692. tree type = TREE_TYPE (decl);
  16693. const_die = new_die (DW_TAG_constant, context_die, decl);
  16694. add_name_and_src_coords_attributes (const_die, decl);
  16695. add_type_attribute (const_die, type, TYPE_QUAL_CONST, context_die);
  16696. if (TREE_PUBLIC (decl))
  16697. add_AT_flag (const_die, DW_AT_external, 1);
  16698. if (DECL_ARTIFICIAL (decl))
  16699. add_AT_flag (const_die, DW_AT_artificial, 1);
  16700. tree_add_const_value_attribute_for_decl (const_die, decl);
  16701. }
  16702. /* Generate a DIE to represent a label identifier. */
  16703. static void
  16704. gen_label_die (tree decl, dw_die_ref context_die)
  16705. {
  16706. tree origin = decl_ultimate_origin (decl);
  16707. dw_die_ref lbl_die = new_die (DW_TAG_label, context_die, decl);
  16708. rtx insn;
  16709. char label[MAX_ARTIFICIAL_LABEL_BYTES];
  16710. if (origin != NULL)
  16711. add_abstract_origin_attribute (lbl_die, origin);
  16712. else
  16713. add_name_and_src_coords_attributes (lbl_die, decl);
  16714. if (DECL_ABSTRACT_P (decl))
  16715. equate_decl_number_to_die (decl, lbl_die);
  16716. else
  16717. {
  16718. insn = DECL_RTL_IF_SET (decl);
  16719. /* Deleted labels are programmer specified labels which have been
  16720. eliminated because of various optimizations. We still emit them
  16721. here so that it is possible to put breakpoints on them. */
  16722. if (insn
  16723. && (LABEL_P (insn)
  16724. || ((NOTE_P (insn)
  16725. && NOTE_KIND (insn) == NOTE_INSN_DELETED_LABEL))))
  16726. {
  16727. /* When optimization is enabled (via -O) some parts of the compiler
  16728. (e.g. jump.c and cse.c) may try to delete CODE_LABEL insns which
  16729. represent source-level labels which were explicitly declared by
  16730. the user. This really shouldn't be happening though, so catch
  16731. it if it ever does happen. */
  16732. gcc_assert (!as_a<rtx_insn *> (insn)->deleted ());
  16733. ASM_GENERATE_INTERNAL_LABEL (label, "L", CODE_LABEL_NUMBER (insn));
  16734. add_AT_lbl_id (lbl_die, DW_AT_low_pc, label);
  16735. }
  16736. else if (insn
  16737. && NOTE_P (insn)
  16738. && NOTE_KIND (insn) == NOTE_INSN_DELETED_DEBUG_LABEL
  16739. && CODE_LABEL_NUMBER (insn) != -1)
  16740. {
  16741. ASM_GENERATE_INTERNAL_LABEL (label, "LDL", CODE_LABEL_NUMBER (insn));
  16742. add_AT_lbl_id (lbl_die, DW_AT_low_pc, label);
  16743. }
  16744. }
  16745. }
  16746. /* A helper function for gen_inlined_subroutine_die. Add source coordinate
  16747. attributes to the DIE for a block STMT, to describe where the inlined
  16748. function was called from. This is similar to add_src_coords_attributes. */
  16749. static inline void
  16750. add_call_src_coords_attributes (tree stmt, dw_die_ref die)
  16751. {
  16752. expanded_location s = expand_location (BLOCK_SOURCE_LOCATION (stmt));
  16753. if (dwarf_version >= 3 || !dwarf_strict)
  16754. {
  16755. add_AT_file (die, DW_AT_call_file, lookup_filename (s.file));
  16756. add_AT_unsigned (die, DW_AT_call_line, s.line);
  16757. }
  16758. }
  16759. /* A helper function for gen_lexical_block_die and gen_inlined_subroutine_die.
  16760. Add low_pc and high_pc attributes to the DIE for a block STMT. */
  16761. static inline void
  16762. add_high_low_attributes (tree stmt, dw_die_ref die)
  16763. {
  16764. char label[MAX_ARTIFICIAL_LABEL_BYTES];
  16765. if (BLOCK_FRAGMENT_CHAIN (stmt)
  16766. && (dwarf_version >= 3 || !dwarf_strict))
  16767. {
  16768. tree chain, superblock = NULL_TREE;
  16769. dw_die_ref pdie;
  16770. dw_attr_ref attr = NULL;
  16771. if (inlined_function_outer_scope_p (stmt))
  16772. {
  16773. ASM_GENERATE_INTERNAL_LABEL (label, BLOCK_BEGIN_LABEL,
  16774. BLOCK_NUMBER (stmt));
  16775. add_AT_lbl_id (die, DW_AT_entry_pc, label);
  16776. }
  16777. /* Optimize duplicate .debug_ranges lists or even tails of
  16778. lists. If this BLOCK has same ranges as its supercontext,
  16779. lookup DW_AT_ranges attribute in the supercontext (and
  16780. recursively so), verify that the ranges_table contains the
  16781. right values and use it instead of adding a new .debug_range. */
  16782. for (chain = stmt, pdie = die;
  16783. BLOCK_SAME_RANGE (chain);
  16784. chain = BLOCK_SUPERCONTEXT (chain))
  16785. {
  16786. dw_attr_ref new_attr;
  16787. pdie = pdie->die_parent;
  16788. if (pdie == NULL)
  16789. break;
  16790. if (BLOCK_SUPERCONTEXT (chain) == NULL_TREE)
  16791. break;
  16792. new_attr = get_AT (pdie, DW_AT_ranges);
  16793. if (new_attr == NULL
  16794. || new_attr->dw_attr_val.val_class != dw_val_class_range_list)
  16795. break;
  16796. attr = new_attr;
  16797. superblock = BLOCK_SUPERCONTEXT (chain);
  16798. }
  16799. if (attr != NULL
  16800. && (ranges_table[attr->dw_attr_val.v.val_offset
  16801. / 2 / DWARF2_ADDR_SIZE].num
  16802. == BLOCK_NUMBER (superblock))
  16803. && BLOCK_FRAGMENT_CHAIN (superblock))
  16804. {
  16805. unsigned long off = attr->dw_attr_val.v.val_offset
  16806. / 2 / DWARF2_ADDR_SIZE;
  16807. unsigned long supercnt = 0, thiscnt = 0;
  16808. for (chain = BLOCK_FRAGMENT_CHAIN (superblock);
  16809. chain; chain = BLOCK_FRAGMENT_CHAIN (chain))
  16810. {
  16811. ++supercnt;
  16812. gcc_checking_assert (ranges_table[off + supercnt].num
  16813. == BLOCK_NUMBER (chain));
  16814. }
  16815. gcc_checking_assert (ranges_table[off + supercnt + 1].num == 0);
  16816. for (chain = BLOCK_FRAGMENT_CHAIN (stmt);
  16817. chain; chain = BLOCK_FRAGMENT_CHAIN (chain))
  16818. ++thiscnt;
  16819. gcc_assert (supercnt >= thiscnt);
  16820. add_AT_range_list (die, DW_AT_ranges,
  16821. ((off + supercnt - thiscnt)
  16822. * 2 * DWARF2_ADDR_SIZE),
  16823. false);
  16824. return;
  16825. }
  16826. add_AT_range_list (die, DW_AT_ranges, add_ranges (stmt), false);
  16827. chain = BLOCK_FRAGMENT_CHAIN (stmt);
  16828. do
  16829. {
  16830. add_ranges (chain);
  16831. chain = BLOCK_FRAGMENT_CHAIN (chain);
  16832. }
  16833. while (chain);
  16834. add_ranges (NULL);
  16835. }
  16836. else
  16837. {
  16838. char label_high[MAX_ARTIFICIAL_LABEL_BYTES];
  16839. ASM_GENERATE_INTERNAL_LABEL (label, BLOCK_BEGIN_LABEL,
  16840. BLOCK_NUMBER (stmt));
  16841. ASM_GENERATE_INTERNAL_LABEL (label_high, BLOCK_END_LABEL,
  16842. BLOCK_NUMBER (stmt));
  16843. add_AT_low_high_pc (die, label, label_high, false);
  16844. }
  16845. }
  16846. /* Generate a DIE for a lexical block. */
  16847. static void
  16848. gen_lexical_block_die (tree stmt, dw_die_ref context_die)
  16849. {
  16850. dw_die_ref stmt_die = new_die (DW_TAG_lexical_block, context_die, stmt);
  16851. if (call_arg_locations)
  16852. {
  16853. if (block_map.length () <= BLOCK_NUMBER (stmt))
  16854. block_map.safe_grow_cleared (BLOCK_NUMBER (stmt) + 1);
  16855. block_map[BLOCK_NUMBER (stmt)] = stmt_die;
  16856. }
  16857. if (! BLOCK_ABSTRACT (stmt) && TREE_ASM_WRITTEN (stmt))
  16858. add_high_low_attributes (stmt, stmt_die);
  16859. decls_for_scope (stmt, stmt_die);
  16860. }
  16861. /* Generate a DIE for an inlined subprogram. */
  16862. static void
  16863. gen_inlined_subroutine_die (tree stmt, dw_die_ref context_die)
  16864. {
  16865. tree decl;
  16866. /* The instance of function that is effectively being inlined shall not
  16867. be abstract. */
  16868. gcc_assert (! BLOCK_ABSTRACT (stmt));
  16869. decl = block_ultimate_origin (stmt);
  16870. /* Emit info for the abstract instance first, if we haven't yet. We
  16871. must emit this even if the block is abstract, otherwise when we
  16872. emit the block below (or elsewhere), we may end up trying to emit
  16873. a die whose origin die hasn't been emitted, and crashing. */
  16874. dwarf2out_abstract_function (decl);
  16875. if (! BLOCK_ABSTRACT (stmt))
  16876. {
  16877. dw_die_ref subr_die
  16878. = new_die (DW_TAG_inlined_subroutine, context_die, stmt);
  16879. if (call_arg_locations)
  16880. {
  16881. if (block_map.length () <= BLOCK_NUMBER (stmt))
  16882. block_map.safe_grow_cleared (BLOCK_NUMBER (stmt) + 1);
  16883. block_map[BLOCK_NUMBER (stmt)] = subr_die;
  16884. }
  16885. add_abstract_origin_attribute (subr_die, decl);
  16886. if (TREE_ASM_WRITTEN (stmt))
  16887. add_high_low_attributes (stmt, subr_die);
  16888. add_call_src_coords_attributes (stmt, subr_die);
  16889. decls_for_scope (stmt, subr_die);
  16890. }
  16891. }
  16892. /* Generate a DIE for a field in a record, or structure. */
  16893. static void
  16894. gen_field_die (tree decl, dw_die_ref context_die)
  16895. {
  16896. dw_die_ref decl_die;
  16897. if (TREE_TYPE (decl) == error_mark_node)
  16898. return;
  16899. decl_die = new_die (DW_TAG_member, context_die, decl);
  16900. add_name_and_src_coords_attributes (decl_die, decl);
  16901. add_type_attribute (decl_die, member_declared_type (decl),
  16902. decl_quals (decl), context_die);
  16903. if (DECL_BIT_FIELD_TYPE (decl))
  16904. {
  16905. add_byte_size_attribute (decl_die, decl);
  16906. add_bit_size_attribute (decl_die, decl);
  16907. add_bit_offset_attribute (decl_die, decl);
  16908. }
  16909. if (TREE_CODE (DECL_FIELD_CONTEXT (decl)) != UNION_TYPE)
  16910. add_data_member_location_attribute (decl_die, decl);
  16911. if (DECL_ARTIFICIAL (decl))
  16912. add_AT_flag (decl_die, DW_AT_artificial, 1);
  16913. add_accessibility_attribute (decl_die, decl);
  16914. /* Equate decl number to die, so that we can look up this decl later on. */
  16915. equate_decl_number_to_die (decl, decl_die);
  16916. }
  16917. #if 0
  16918. /* Don't generate either pointer_type DIEs or reference_type DIEs here.
  16919. Use modified_type_die instead.
  16920. We keep this code here just in case these types of DIEs may be needed to
  16921. represent certain things in other languages (e.g. Pascal) someday. */
  16922. static void
  16923. gen_pointer_type_die (tree type, dw_die_ref context_die)
  16924. {
  16925. dw_die_ref ptr_die
  16926. = new_die (DW_TAG_pointer_type, scope_die_for (type, context_die), type);
  16927. equate_type_number_to_die (type, ptr_die);
  16928. add_type_attribute (ptr_die, TREE_TYPE (type), TYPE_UNQUALIFIED,
  16929. context_die);
  16930. add_AT_unsigned (mod_type_die, DW_AT_byte_size, PTR_SIZE);
  16931. }
  16932. /* Don't generate either pointer_type DIEs or reference_type DIEs here.
  16933. Use modified_type_die instead.
  16934. We keep this code here just in case these types of DIEs may be needed to
  16935. represent certain things in other languages (e.g. Pascal) someday. */
  16936. static void
  16937. gen_reference_type_die (tree type, dw_die_ref context_die)
  16938. {
  16939. dw_die_ref ref_die, scope_die = scope_die_for (type, context_die);
  16940. if (TYPE_REF_IS_RVALUE (type) && dwarf_version >= 4)
  16941. ref_die = new_die (DW_TAG_rvalue_reference_type, scope_die, type);
  16942. else
  16943. ref_die = new_die (DW_TAG_reference_type, scope_die, type);
  16944. equate_type_number_to_die (type, ref_die);
  16945. add_type_attribute (ref_die, TREE_TYPE (type), TYPE_UNQUALIFIED,
  16946. context_die);
  16947. add_AT_unsigned (mod_type_die, DW_AT_byte_size, PTR_SIZE);
  16948. }
  16949. #endif
  16950. /* Generate a DIE for a pointer to a member type. */
  16951. static void
  16952. gen_ptr_to_mbr_type_die (tree type, dw_die_ref context_die)
  16953. {
  16954. dw_die_ref ptr_die
  16955. = new_die (DW_TAG_ptr_to_member_type,
  16956. scope_die_for (type, context_die), type);
  16957. equate_type_number_to_die (type, ptr_die);
  16958. add_AT_die_ref (ptr_die, DW_AT_containing_type,
  16959. lookup_type_die (TYPE_OFFSET_BASETYPE (type)));
  16960. add_type_attribute (ptr_die, TREE_TYPE (type), TYPE_UNQUALIFIED,
  16961. context_die);
  16962. }
  16963. typedef const char *dchar_p; /* For DEF_VEC_P. */
  16964. static char *producer_string;
  16965. /* Return a heap allocated producer string including command line options
  16966. if -grecord-gcc-switches. */
  16967. static char *
  16968. gen_producer_string (void)
  16969. {
  16970. size_t j;
  16971. auto_vec<dchar_p> switches;
  16972. const char *language_string = lang_hooks.name;
  16973. char *producer, *tail;
  16974. const char *p;
  16975. size_t len = dwarf_record_gcc_switches ? 0 : 3;
  16976. size_t plen = strlen (language_string) + 1 + strlen (version_string);
  16977. for (j = 1; dwarf_record_gcc_switches && j < save_decoded_options_count; j++)
  16978. switch (save_decoded_options[j].opt_index)
  16979. {
  16980. case OPT_o:
  16981. case OPT_d:
  16982. case OPT_dumpbase:
  16983. case OPT_dumpdir:
  16984. case OPT_auxbase:
  16985. case OPT_auxbase_strip:
  16986. case OPT_quiet:
  16987. case OPT_version:
  16988. case OPT_v:
  16989. case OPT_w:
  16990. case OPT_L:
  16991. case OPT_D:
  16992. case OPT_I:
  16993. case OPT_U:
  16994. case OPT_SPECIAL_unknown:
  16995. case OPT_SPECIAL_ignore:
  16996. case OPT_SPECIAL_program_name:
  16997. case OPT_SPECIAL_input_file:
  16998. case OPT_grecord_gcc_switches:
  16999. case OPT_gno_record_gcc_switches:
  17000. case OPT__output_pch_:
  17001. case OPT_fdiagnostics_show_location_:
  17002. case OPT_fdiagnostics_show_option:
  17003. case OPT_fdiagnostics_show_caret:
  17004. case OPT_fdiagnostics_color_:
  17005. case OPT_fverbose_asm:
  17006. case OPT____:
  17007. case OPT__sysroot_:
  17008. case OPT_nostdinc:
  17009. case OPT_nostdinc__:
  17010. case OPT_fpreprocessed:
  17011. case OPT_fltrans_output_list_:
  17012. case OPT_fresolution_:
  17013. /* Ignore these. */
  17014. continue;
  17015. default:
  17016. if (cl_options[save_decoded_options[j].opt_index].flags
  17017. & CL_NO_DWARF_RECORD)
  17018. continue;
  17019. gcc_checking_assert (save_decoded_options[j].canonical_option[0][0]
  17020. == '-');
  17021. switch (save_decoded_options[j].canonical_option[0][1])
  17022. {
  17023. case 'M':
  17024. case 'i':
  17025. case 'W':
  17026. continue;
  17027. case 'f':
  17028. if (strncmp (save_decoded_options[j].canonical_option[0] + 2,
  17029. "dump", 4) == 0)
  17030. continue;
  17031. break;
  17032. default:
  17033. break;
  17034. }
  17035. switches.safe_push (save_decoded_options[j].orig_option_with_args_text);
  17036. len += strlen (save_decoded_options[j].orig_option_with_args_text) + 1;
  17037. break;
  17038. }
  17039. producer = XNEWVEC (char, plen + 1 + len + 1);
  17040. tail = producer;
  17041. sprintf (tail, "%s %s", language_string, version_string);
  17042. tail += plen;
  17043. FOR_EACH_VEC_ELT (switches, j, p)
  17044. {
  17045. len = strlen (p);
  17046. *tail = ' ';
  17047. memcpy (tail + 1, p, len);
  17048. tail += len + 1;
  17049. }
  17050. *tail = '\0';
  17051. return producer;
  17052. }
  17053. /* Given a C and/or C++ language/version string return the "highest".
  17054. C++ is assumed to be "higher" than C in this case. Used for merging
  17055. LTO translation unit languages. */
  17056. static const char *
  17057. highest_c_language (const char *lang1, const char *lang2)
  17058. {
  17059. if (strcmp ("GNU C++14", lang1) == 0 || strcmp ("GNU C++14", lang2) == 0)
  17060. return "GNU C++14";
  17061. if (strcmp ("GNU C++11", lang1) == 0 || strcmp ("GNU C++11", lang2) == 0)
  17062. return "GNU C++11";
  17063. if (strcmp ("GNU C++98", lang1) == 0 || strcmp ("GNU C++98", lang2) == 0)
  17064. return "GNU C++98";
  17065. if (strcmp ("GNU C11", lang1) == 0 || strcmp ("GNU C11", lang2) == 0)
  17066. return "GNU C11";
  17067. if (strcmp ("GNU C99", lang1) == 0 || strcmp ("GNU C99", lang2) == 0)
  17068. return "GNU C99";
  17069. if (strcmp ("GNU C89", lang1) == 0 || strcmp ("GNU C89", lang2) == 0)
  17070. return "GNU C89";
  17071. gcc_unreachable ();
  17072. }
  17073. /* Generate the DIE for the compilation unit. */
  17074. static dw_die_ref
  17075. gen_compile_unit_die (const char *filename)
  17076. {
  17077. dw_die_ref die;
  17078. const char *language_string = lang_hooks.name;
  17079. int language;
  17080. die = new_die (DW_TAG_compile_unit, NULL, NULL);
  17081. if (filename)
  17082. {
  17083. add_name_attribute (die, filename);
  17084. /* Don't add cwd for <built-in>. */
  17085. if (!IS_ABSOLUTE_PATH (filename) && filename[0] != '<')
  17086. add_comp_dir_attribute (die);
  17087. }
  17088. add_AT_string (die, DW_AT_producer, producer_string ? producer_string : "");
  17089. /* If our producer is LTO try to figure out a common language to use
  17090. from the global list of translation units. */
  17091. if (strcmp (language_string, "GNU GIMPLE") == 0)
  17092. {
  17093. unsigned i;
  17094. tree t;
  17095. const char *common_lang = NULL;
  17096. FOR_EACH_VEC_SAFE_ELT (all_translation_units, i, t)
  17097. {
  17098. if (!TRANSLATION_UNIT_LANGUAGE (t))
  17099. continue;
  17100. if (!common_lang)
  17101. common_lang = TRANSLATION_UNIT_LANGUAGE (t);
  17102. else if (strcmp (common_lang, TRANSLATION_UNIT_LANGUAGE (t)) == 0)
  17103. ;
  17104. else if (strncmp (common_lang, "GNU C", 5) == 0
  17105. && strncmp (TRANSLATION_UNIT_LANGUAGE (t), "GNU C", 5) == 0)
  17106. /* Mixing C and C++ is ok, use C++ in that case. */
  17107. common_lang = highest_c_language (common_lang,
  17108. TRANSLATION_UNIT_LANGUAGE (t));
  17109. else
  17110. {
  17111. /* Fall back to C. */
  17112. common_lang = NULL;
  17113. break;
  17114. }
  17115. }
  17116. if (common_lang)
  17117. language_string = common_lang;
  17118. }
  17119. language = DW_LANG_C;
  17120. if (strncmp (language_string, "GNU C", 5) == 0
  17121. && ISDIGIT (language_string[5]))
  17122. {
  17123. language = DW_LANG_C89;
  17124. if (dwarf_version >= 3 || !dwarf_strict)
  17125. {
  17126. if (strcmp (language_string, "GNU C89") != 0)
  17127. language = DW_LANG_C99;
  17128. if (dwarf_version >= 5 /* || !dwarf_strict */)
  17129. if (strcmp (language_string, "GNU C11") == 0)
  17130. language = DW_LANG_C11;
  17131. }
  17132. }
  17133. else if (strncmp (language_string, "GNU C++", 7) == 0)
  17134. {
  17135. language = DW_LANG_C_plus_plus;
  17136. if (dwarf_version >= 5 /* || !dwarf_strict */)
  17137. {
  17138. if (strcmp (language_string, "GNU C++11") == 0)
  17139. language = DW_LANG_C_plus_plus_11;
  17140. else if (strcmp (language_string, "GNU C++14") == 0)
  17141. language = DW_LANG_C_plus_plus_14;
  17142. }
  17143. }
  17144. else if (strcmp (language_string, "GNU F77") == 0)
  17145. language = DW_LANG_Fortran77;
  17146. else if (strcmp (language_string, "GNU Pascal") == 0)
  17147. language = DW_LANG_Pascal83;
  17148. else if (dwarf_version >= 3 || !dwarf_strict)
  17149. {
  17150. if (strcmp (language_string, "GNU Ada") == 0)
  17151. language = DW_LANG_Ada95;
  17152. else if (strncmp (language_string, "GNU Fortran", 11) == 0)
  17153. {
  17154. language = DW_LANG_Fortran95;
  17155. if (dwarf_version >= 5 /* || !dwarf_strict */)
  17156. {
  17157. if (strcmp (language_string, "GNU Fortran2003") == 0)
  17158. language = DW_LANG_Fortran03;
  17159. else if (strcmp (language_string, "GNU Fortran2008") == 0)
  17160. language = DW_LANG_Fortran08;
  17161. }
  17162. }
  17163. else if (strcmp (language_string, "GNU Java") == 0)
  17164. language = DW_LANG_Java;
  17165. else if (strcmp (language_string, "GNU Objective-C") == 0)
  17166. language = DW_LANG_ObjC;
  17167. else if (strcmp (language_string, "GNU Objective-C++") == 0)
  17168. language = DW_LANG_ObjC_plus_plus;
  17169. else if (dwarf_version >= 5 || !dwarf_strict)
  17170. {
  17171. if (strcmp (language_string, "GNU Go") == 0)
  17172. language = DW_LANG_Go;
  17173. }
  17174. }
  17175. /* Use a degraded Fortran setting in strict DWARF2 so is_fortran works. */
  17176. else if (strncmp (language_string, "GNU Fortran", 11) == 0)
  17177. language = DW_LANG_Fortran90;
  17178. add_AT_unsigned (die, DW_AT_language, language);
  17179. switch (language)
  17180. {
  17181. case DW_LANG_Fortran77:
  17182. case DW_LANG_Fortran90:
  17183. case DW_LANG_Fortran95:
  17184. case DW_LANG_Fortran03:
  17185. case DW_LANG_Fortran08:
  17186. /* Fortran has case insensitive identifiers and the front-end
  17187. lowercases everything. */
  17188. add_AT_unsigned (die, DW_AT_identifier_case, DW_ID_down_case);
  17189. break;
  17190. default:
  17191. /* The default DW_ID_case_sensitive doesn't need to be specified. */
  17192. break;
  17193. }
  17194. return die;
  17195. }
  17196. /* Generate the DIE for a base class. */
  17197. static void
  17198. gen_inheritance_die (tree binfo, tree access, dw_die_ref context_die)
  17199. {
  17200. dw_die_ref die = new_die (DW_TAG_inheritance, context_die, binfo);
  17201. add_type_attribute (die, BINFO_TYPE (binfo), TYPE_UNQUALIFIED, context_die);
  17202. add_data_member_location_attribute (die, binfo);
  17203. if (BINFO_VIRTUAL_P (binfo))
  17204. add_AT_unsigned (die, DW_AT_virtuality, DW_VIRTUALITY_virtual);
  17205. /* In DWARF3+ the default is DW_ACCESS_private only in DW_TAG_class_type
  17206. children, otherwise the default is DW_ACCESS_public. In DWARF2
  17207. the default has always been DW_ACCESS_private. */
  17208. if (access == access_public_node)
  17209. {
  17210. if (dwarf_version == 2
  17211. || context_die->die_tag == DW_TAG_class_type)
  17212. add_AT_unsigned (die, DW_AT_accessibility, DW_ACCESS_public);
  17213. }
  17214. else if (access == access_protected_node)
  17215. add_AT_unsigned (die, DW_AT_accessibility, DW_ACCESS_protected);
  17216. else if (dwarf_version > 2
  17217. && context_die->die_tag != DW_TAG_class_type)
  17218. add_AT_unsigned (die, DW_AT_accessibility, DW_ACCESS_private);
  17219. }
  17220. /* Generate a DIE for a class member. */
  17221. static void
  17222. gen_member_die (tree type, dw_die_ref context_die)
  17223. {
  17224. tree member;
  17225. tree binfo = TYPE_BINFO (type);
  17226. dw_die_ref child;
  17227. /* If this is not an incomplete type, output descriptions of each of its
  17228. members. Note that as we output the DIEs necessary to represent the
  17229. members of this record or union type, we will also be trying to output
  17230. DIEs to represent the *types* of those members. However the `type'
  17231. function (above) will specifically avoid generating type DIEs for member
  17232. types *within* the list of member DIEs for this (containing) type except
  17233. for those types (of members) which are explicitly marked as also being
  17234. members of this (containing) type themselves. The g++ front- end can
  17235. force any given type to be treated as a member of some other (containing)
  17236. type by setting the TYPE_CONTEXT of the given (member) type to point to
  17237. the TREE node representing the appropriate (containing) type. */
  17238. /* First output info about the base classes. */
  17239. if (binfo)
  17240. {
  17241. vec<tree, va_gc> *accesses = BINFO_BASE_ACCESSES (binfo);
  17242. int i;
  17243. tree base;
  17244. for (i = 0; BINFO_BASE_ITERATE (binfo, i, base); i++)
  17245. gen_inheritance_die (base,
  17246. (accesses ? (*accesses)[i] : access_public_node),
  17247. context_die);
  17248. }
  17249. /* Now output info about the data members and type members. */
  17250. for (member = TYPE_FIELDS (type); member; member = DECL_CHAIN (member))
  17251. {
  17252. /* If we thought we were generating minimal debug info for TYPE
  17253. and then changed our minds, some of the member declarations
  17254. may have already been defined. Don't define them again, but
  17255. do put them in the right order. */
  17256. child = lookup_decl_die (member);
  17257. if (child)
  17258. splice_child_die (context_die, child);
  17259. else
  17260. gen_decl_die (member, NULL, context_die);
  17261. }
  17262. /* Now output info about the function members (if any). */
  17263. for (member = TYPE_METHODS (type); member; member = DECL_CHAIN (member))
  17264. {
  17265. /* Don't include clones in the member list. */
  17266. if (DECL_ABSTRACT_ORIGIN (member))
  17267. continue;
  17268. child = lookup_decl_die (member);
  17269. if (child)
  17270. splice_child_die (context_die, child);
  17271. else
  17272. gen_decl_die (member, NULL, context_die);
  17273. }
  17274. }
  17275. /* Generate a DIE for a structure or union type. If TYPE_DECL_SUPPRESS_DEBUG
  17276. is set, we pretend that the type was never defined, so we only get the
  17277. member DIEs needed by later specification DIEs. */
  17278. static void
  17279. gen_struct_or_union_type_die (tree type, dw_die_ref context_die,
  17280. enum debug_info_usage usage)
  17281. {
  17282. dw_die_ref type_die = lookup_type_die (type);
  17283. dw_die_ref scope_die = 0;
  17284. int nested = 0;
  17285. int complete = (TYPE_SIZE (type)
  17286. && (! TYPE_STUB_DECL (type)
  17287. || ! TYPE_DECL_SUPPRESS_DEBUG (TYPE_STUB_DECL (type))));
  17288. int ns_decl = (context_die && context_die->die_tag == DW_TAG_namespace);
  17289. complete = complete && should_emit_struct_debug (type, usage);
  17290. if (type_die && ! complete)
  17291. return;
  17292. if (TYPE_CONTEXT (type) != NULL_TREE
  17293. && (AGGREGATE_TYPE_P (TYPE_CONTEXT (type))
  17294. || TREE_CODE (TYPE_CONTEXT (type)) == NAMESPACE_DECL))
  17295. nested = 1;
  17296. scope_die = scope_die_for (type, context_die);
  17297. /* Generate child dies for template paramaters. */
  17298. if (!type_die && debug_info_level > DINFO_LEVEL_TERSE)
  17299. schedule_generic_params_dies_gen (type);
  17300. if (! type_die || (nested && is_cu_die (scope_die)))
  17301. /* First occurrence of type or toplevel definition of nested class. */
  17302. {
  17303. dw_die_ref old_die = type_die;
  17304. type_die = new_die (TREE_CODE (type) == RECORD_TYPE
  17305. ? record_type_tag (type) : DW_TAG_union_type,
  17306. scope_die, type);
  17307. equate_type_number_to_die (type, type_die);
  17308. if (old_die)
  17309. add_AT_specification (type_die, old_die);
  17310. else
  17311. add_name_attribute (type_die, type_tag (type));
  17312. }
  17313. else
  17314. remove_AT (type_die, DW_AT_declaration);
  17315. /* If this type has been completed, then give it a byte_size attribute and
  17316. then give a list of members. */
  17317. if (complete && !ns_decl)
  17318. {
  17319. /* Prevent infinite recursion in cases where the type of some member of
  17320. this type is expressed in terms of this type itself. */
  17321. TREE_ASM_WRITTEN (type) = 1;
  17322. add_byte_size_attribute (type_die, type);
  17323. if (TYPE_STUB_DECL (type) != NULL_TREE)
  17324. {
  17325. add_src_coords_attributes (type_die, TYPE_STUB_DECL (type));
  17326. add_accessibility_attribute (type_die, TYPE_STUB_DECL (type));
  17327. }
  17328. /* If the first reference to this type was as the return type of an
  17329. inline function, then it may not have a parent. Fix this now. */
  17330. if (type_die->die_parent == NULL)
  17331. add_child_die (scope_die, type_die);
  17332. push_decl_scope (type);
  17333. gen_member_die (type, type_die);
  17334. pop_decl_scope ();
  17335. add_gnat_descriptive_type_attribute (type_die, type, context_die);
  17336. if (TYPE_ARTIFICIAL (type))
  17337. add_AT_flag (type_die, DW_AT_artificial, 1);
  17338. /* GNU extension: Record what type our vtable lives in. */
  17339. if (TYPE_VFIELD (type))
  17340. {
  17341. tree vtype = DECL_FCONTEXT (TYPE_VFIELD (type));
  17342. gen_type_die (vtype, context_die);
  17343. add_AT_die_ref (type_die, DW_AT_containing_type,
  17344. lookup_type_die (vtype));
  17345. }
  17346. }
  17347. else
  17348. {
  17349. add_AT_flag (type_die, DW_AT_declaration, 1);
  17350. /* We don't need to do this for function-local types. */
  17351. if (TYPE_STUB_DECL (type)
  17352. && ! decl_function_context (TYPE_STUB_DECL (type)))
  17353. vec_safe_push (incomplete_types, type);
  17354. }
  17355. if (get_AT (type_die, DW_AT_name))
  17356. add_pubtype (type, type_die);
  17357. }
  17358. /* Generate a DIE for a subroutine _type_. */
  17359. static void
  17360. gen_subroutine_type_die (tree type, dw_die_ref context_die)
  17361. {
  17362. tree return_type = TREE_TYPE (type);
  17363. dw_die_ref subr_die
  17364. = new_die (DW_TAG_subroutine_type,
  17365. scope_die_for (type, context_die), type);
  17366. equate_type_number_to_die (type, subr_die);
  17367. add_prototyped_attribute (subr_die, type);
  17368. add_type_attribute (subr_die, return_type, TYPE_UNQUALIFIED, context_die);
  17369. gen_formal_types_die (type, subr_die);
  17370. if (get_AT (subr_die, DW_AT_name))
  17371. add_pubtype (type, subr_die);
  17372. }
  17373. /* Generate a DIE for a type definition. */
  17374. static void
  17375. gen_typedef_die (tree decl, dw_die_ref context_die)
  17376. {
  17377. dw_die_ref type_die;
  17378. tree origin;
  17379. if (TREE_ASM_WRITTEN (decl))
  17380. return;
  17381. TREE_ASM_WRITTEN (decl) = 1;
  17382. type_die = new_die (DW_TAG_typedef, context_die, decl);
  17383. origin = decl_ultimate_origin (decl);
  17384. if (origin != NULL)
  17385. add_abstract_origin_attribute (type_die, origin);
  17386. else
  17387. {
  17388. tree type;
  17389. add_name_and_src_coords_attributes (type_die, decl);
  17390. if (DECL_ORIGINAL_TYPE (decl))
  17391. {
  17392. type = DECL_ORIGINAL_TYPE (decl);
  17393. gcc_assert (type != TREE_TYPE (decl));
  17394. equate_type_number_to_die (TREE_TYPE (decl), type_die);
  17395. }
  17396. else
  17397. {
  17398. type = TREE_TYPE (decl);
  17399. if (is_naming_typedef_decl (TYPE_NAME (type)))
  17400. {
  17401. /* Here, we are in the case of decl being a typedef naming
  17402. an anonymous type, e.g:
  17403. typedef struct {...} foo;
  17404. In that case TREE_TYPE (decl) is not a typedef variant
  17405. type and TYPE_NAME of the anonymous type is set to the
  17406. TYPE_DECL of the typedef. This construct is emitted by
  17407. the C++ FE.
  17408. TYPE is the anonymous struct named by the typedef
  17409. DECL. As we need the DW_AT_type attribute of the
  17410. DW_TAG_typedef to point to the DIE of TYPE, let's
  17411. generate that DIE right away. add_type_attribute
  17412. called below will then pick (via lookup_type_die) that
  17413. anonymous struct DIE. */
  17414. if (!TREE_ASM_WRITTEN (type))
  17415. gen_tagged_type_die (type, context_die, DINFO_USAGE_DIR_USE);
  17416. /* This is a GNU Extension. We are adding a
  17417. DW_AT_linkage_name attribute to the DIE of the
  17418. anonymous struct TYPE. The value of that attribute
  17419. is the name of the typedef decl naming the anonymous
  17420. struct. This greatly eases the work of consumers of
  17421. this debug info. */
  17422. add_linkage_attr (lookup_type_die (type), decl);
  17423. }
  17424. }
  17425. add_type_attribute (type_die, type, decl_quals (decl), context_die);
  17426. if (is_naming_typedef_decl (decl))
  17427. /* We want that all subsequent calls to lookup_type_die with
  17428. TYPE in argument yield the DW_TAG_typedef we have just
  17429. created. */
  17430. equate_type_number_to_die (type, type_die);
  17431. add_accessibility_attribute (type_die, decl);
  17432. }
  17433. if (DECL_ABSTRACT_P (decl))
  17434. equate_decl_number_to_die (decl, type_die);
  17435. if (get_AT (type_die, DW_AT_name))
  17436. add_pubtype (decl, type_die);
  17437. }
  17438. /* Generate a DIE for a struct, class, enum or union type. */
  17439. static void
  17440. gen_tagged_type_die (tree type,
  17441. dw_die_ref context_die,
  17442. enum debug_info_usage usage)
  17443. {
  17444. int need_pop;
  17445. if (type == NULL_TREE
  17446. || !is_tagged_type (type))
  17447. return;
  17448. /* If this is a nested type whose containing class hasn't been written
  17449. out yet, writing it out will cover this one, too. This does not apply
  17450. to instantiations of member class templates; they need to be added to
  17451. the containing class as they are generated. FIXME: This hurts the
  17452. idea of combining type decls from multiple TUs, since we can't predict
  17453. what set of template instantiations we'll get. */
  17454. if (TYPE_CONTEXT (type)
  17455. && AGGREGATE_TYPE_P (TYPE_CONTEXT (type))
  17456. && ! TREE_ASM_WRITTEN (TYPE_CONTEXT (type)))
  17457. {
  17458. gen_type_die_with_usage (TYPE_CONTEXT (type), context_die, usage);
  17459. if (TREE_ASM_WRITTEN (type))
  17460. return;
  17461. /* If that failed, attach ourselves to the stub. */
  17462. push_decl_scope (TYPE_CONTEXT (type));
  17463. context_die = lookup_type_die (TYPE_CONTEXT (type));
  17464. need_pop = 1;
  17465. }
  17466. else if (TYPE_CONTEXT (type) != NULL_TREE
  17467. && (TREE_CODE (TYPE_CONTEXT (type)) == FUNCTION_DECL))
  17468. {
  17469. /* If this type is local to a function that hasn't been written
  17470. out yet, use a NULL context for now; it will be fixed up in
  17471. decls_for_scope. */
  17472. context_die = lookup_decl_die (TYPE_CONTEXT (type));
  17473. /* A declaration DIE doesn't count; nested types need to go in the
  17474. specification. */
  17475. if (context_die && is_declaration_die (context_die))
  17476. context_die = NULL;
  17477. need_pop = 0;
  17478. }
  17479. else
  17480. {
  17481. context_die = declare_in_namespace (type, context_die);
  17482. need_pop = 0;
  17483. }
  17484. if (TREE_CODE (type) == ENUMERAL_TYPE)
  17485. {
  17486. /* This might have been written out by the call to
  17487. declare_in_namespace. */
  17488. if (!TREE_ASM_WRITTEN (type))
  17489. gen_enumeration_type_die (type, context_die);
  17490. }
  17491. else
  17492. gen_struct_or_union_type_die (type, context_die, usage);
  17493. if (need_pop)
  17494. pop_decl_scope ();
  17495. /* Don't set TREE_ASM_WRITTEN on an incomplete struct; we want to fix
  17496. it up if it is ever completed. gen_*_type_die will set it for us
  17497. when appropriate. */
  17498. }
  17499. /* Generate a type description DIE. */
  17500. static void
  17501. gen_type_die_with_usage (tree type, dw_die_ref context_die,
  17502. enum debug_info_usage usage)
  17503. {
  17504. struct array_descr_info info;
  17505. if (type == NULL_TREE || type == error_mark_node)
  17506. return;
  17507. if (TYPE_NAME (type) != NULL_TREE
  17508. && TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
  17509. && is_redundant_typedef (TYPE_NAME (type))
  17510. && DECL_ORIGINAL_TYPE (TYPE_NAME (type)))
  17511. /* The DECL of this type is a typedef we don't want to emit debug
  17512. info for but we want debug info for its underlying typedef.
  17513. This can happen for e.g, the injected-class-name of a C++
  17514. type. */
  17515. type = DECL_ORIGINAL_TYPE (TYPE_NAME (type));
  17516. /* If TYPE is a typedef type variant, let's generate debug info
  17517. for the parent typedef which TYPE is a type of. */
  17518. if (typedef_variant_p (type))
  17519. {
  17520. if (TREE_ASM_WRITTEN (type))
  17521. return;
  17522. /* Prevent broken recursion; we can't hand off to the same type. */
  17523. gcc_assert (DECL_ORIGINAL_TYPE (TYPE_NAME (type)) != type);
  17524. /* Give typedefs the right scope. */
  17525. context_die = scope_die_for (type, context_die);
  17526. TREE_ASM_WRITTEN (type) = 1;
  17527. gen_decl_die (TYPE_NAME (type), NULL, context_die);
  17528. return;
  17529. }
  17530. /* If type is an anonymous tagged type named by a typedef, let's
  17531. generate debug info for the typedef. */
  17532. if (is_naming_typedef_decl (TYPE_NAME (type)))
  17533. {
  17534. /* Use the DIE of the containing namespace as the parent DIE of
  17535. the type description DIE we want to generate. */
  17536. if (DECL_CONTEXT (TYPE_NAME (type))
  17537. && TREE_CODE (DECL_CONTEXT (TYPE_NAME (type))) == NAMESPACE_DECL)
  17538. context_die = get_context_die (DECL_CONTEXT (TYPE_NAME (type)));
  17539. gen_decl_die (TYPE_NAME (type), NULL, context_die);
  17540. return;
  17541. }
  17542. /* We are going to output a DIE to represent the unqualified version
  17543. of this type (i.e. without any const or volatile qualifiers) so
  17544. get the main variant (i.e. the unqualified version) of this type
  17545. now. (Vectors are special because the debugging info is in the
  17546. cloned type itself). */
  17547. if (TREE_CODE (type) != VECTOR_TYPE)
  17548. type = type_main_variant (type);
  17549. /* If this is an array type with hidden descriptor, handle it first. */
  17550. if (!TREE_ASM_WRITTEN (type)
  17551. && lang_hooks.types.get_array_descr_info)
  17552. {
  17553. memset (&info, 0, sizeof (info));
  17554. if (lang_hooks.types.get_array_descr_info (type, &info))
  17555. {
  17556. gen_descr_array_type_die (type, &info, context_die);
  17557. TREE_ASM_WRITTEN (type) = 1;
  17558. return;
  17559. }
  17560. }
  17561. if (TREE_ASM_WRITTEN (type))
  17562. return;
  17563. switch (TREE_CODE (type))
  17564. {
  17565. case ERROR_MARK:
  17566. break;
  17567. case POINTER_TYPE:
  17568. case REFERENCE_TYPE:
  17569. /* We must set TREE_ASM_WRITTEN in case this is a recursive type. This
  17570. ensures that the gen_type_die recursion will terminate even if the
  17571. type is recursive. Recursive types are possible in Ada. */
  17572. /* ??? We could perhaps do this for all types before the switch
  17573. statement. */
  17574. TREE_ASM_WRITTEN (type) = 1;
  17575. /* For these types, all that is required is that we output a DIE (or a
  17576. set of DIEs) to represent the "basis" type. */
  17577. gen_type_die_with_usage (TREE_TYPE (type), context_die,
  17578. DINFO_USAGE_IND_USE);
  17579. break;
  17580. case OFFSET_TYPE:
  17581. /* This code is used for C++ pointer-to-data-member types.
  17582. Output a description of the relevant class type. */
  17583. gen_type_die_with_usage (TYPE_OFFSET_BASETYPE (type), context_die,
  17584. DINFO_USAGE_IND_USE);
  17585. /* Output a description of the type of the object pointed to. */
  17586. gen_type_die_with_usage (TREE_TYPE (type), context_die,
  17587. DINFO_USAGE_IND_USE);
  17588. /* Now output a DIE to represent this pointer-to-data-member type
  17589. itself. */
  17590. gen_ptr_to_mbr_type_die (type, context_die);
  17591. break;
  17592. case FUNCTION_TYPE:
  17593. /* Force out return type (in case it wasn't forced out already). */
  17594. gen_type_die_with_usage (TREE_TYPE (type), context_die,
  17595. DINFO_USAGE_DIR_USE);
  17596. gen_subroutine_type_die (type, context_die);
  17597. break;
  17598. case METHOD_TYPE:
  17599. /* Force out return type (in case it wasn't forced out already). */
  17600. gen_type_die_with_usage (TREE_TYPE (type), context_die,
  17601. DINFO_USAGE_DIR_USE);
  17602. gen_subroutine_type_die (type, context_die);
  17603. break;
  17604. case ARRAY_TYPE:
  17605. gen_array_type_die (type, context_die);
  17606. break;
  17607. case VECTOR_TYPE:
  17608. gen_array_type_die (type, context_die);
  17609. break;
  17610. case ENUMERAL_TYPE:
  17611. case RECORD_TYPE:
  17612. case UNION_TYPE:
  17613. case QUAL_UNION_TYPE:
  17614. gen_tagged_type_die (type, context_die, usage);
  17615. return;
  17616. case VOID_TYPE:
  17617. case INTEGER_TYPE:
  17618. case REAL_TYPE:
  17619. case FIXED_POINT_TYPE:
  17620. case COMPLEX_TYPE:
  17621. case BOOLEAN_TYPE:
  17622. case POINTER_BOUNDS_TYPE:
  17623. /* No DIEs needed for fundamental types. */
  17624. break;
  17625. case NULLPTR_TYPE:
  17626. case LANG_TYPE:
  17627. /* Just use DW_TAG_unspecified_type. */
  17628. {
  17629. dw_die_ref type_die = lookup_type_die (type);
  17630. if (type_die == NULL)
  17631. {
  17632. tree name = TYPE_IDENTIFIER (type);
  17633. type_die = new_die (DW_TAG_unspecified_type, comp_unit_die (),
  17634. type);
  17635. add_name_attribute (type_die, IDENTIFIER_POINTER (name));
  17636. equate_type_number_to_die (type, type_die);
  17637. }
  17638. }
  17639. break;
  17640. default:
  17641. if (is_cxx_auto (type))
  17642. {
  17643. tree name = TYPE_IDENTIFIER (type);
  17644. dw_die_ref *die = (name == get_identifier ("auto")
  17645. ? &auto_die : &decltype_auto_die);
  17646. if (!*die)
  17647. {
  17648. *die = new_die (DW_TAG_unspecified_type,
  17649. comp_unit_die (), NULL_TREE);
  17650. add_name_attribute (*die, IDENTIFIER_POINTER (name));
  17651. }
  17652. equate_type_number_to_die (type, *die);
  17653. break;
  17654. }
  17655. gcc_unreachable ();
  17656. }
  17657. TREE_ASM_WRITTEN (type) = 1;
  17658. }
  17659. static void
  17660. gen_type_die (tree type, dw_die_ref context_die)
  17661. {
  17662. gen_type_die_with_usage (type, context_die, DINFO_USAGE_DIR_USE);
  17663. }
  17664. /* Generate a DW_TAG_lexical_block DIE followed by DIEs to represent all of the
  17665. things which are local to the given block. */
  17666. static void
  17667. gen_block_die (tree stmt, dw_die_ref context_die)
  17668. {
  17669. int must_output_die = 0;
  17670. bool inlined_func;
  17671. /* Ignore blocks that are NULL. */
  17672. if (stmt == NULL_TREE)
  17673. return;
  17674. inlined_func = inlined_function_outer_scope_p (stmt);
  17675. /* If the block is one fragment of a non-contiguous block, do not
  17676. process the variables, since they will have been done by the
  17677. origin block. Do process subblocks. */
  17678. if (BLOCK_FRAGMENT_ORIGIN (stmt))
  17679. {
  17680. tree sub;
  17681. for (sub = BLOCK_SUBBLOCKS (stmt); sub; sub = BLOCK_CHAIN (sub))
  17682. gen_block_die (sub, context_die);
  17683. return;
  17684. }
  17685. /* Determine if we need to output any Dwarf DIEs at all to represent this
  17686. block. */
  17687. if (inlined_func)
  17688. /* The outer scopes for inlinings *must* always be represented. We
  17689. generate DW_TAG_inlined_subroutine DIEs for them. (See below.) */
  17690. must_output_die = 1;
  17691. else
  17692. {
  17693. /* Determine if this block directly contains any "significant"
  17694. local declarations which we will need to output DIEs for. */
  17695. if (debug_info_level > DINFO_LEVEL_TERSE)
  17696. /* We are not in terse mode so *any* local declaration counts
  17697. as being a "significant" one. */
  17698. must_output_die = ((BLOCK_VARS (stmt) != NULL
  17699. || BLOCK_NUM_NONLOCALIZED_VARS (stmt))
  17700. && (TREE_USED (stmt)
  17701. || TREE_ASM_WRITTEN (stmt)
  17702. || BLOCK_ABSTRACT (stmt)));
  17703. else if ((TREE_USED (stmt)
  17704. || TREE_ASM_WRITTEN (stmt)
  17705. || BLOCK_ABSTRACT (stmt))
  17706. && !dwarf2out_ignore_block (stmt))
  17707. must_output_die = 1;
  17708. }
  17709. /* It would be a waste of space to generate a Dwarf DW_TAG_lexical_block
  17710. DIE for any block which contains no significant local declarations at
  17711. all. Rather, in such cases we just call `decls_for_scope' so that any
  17712. needed Dwarf info for any sub-blocks will get properly generated. Note
  17713. that in terse mode, our definition of what constitutes a "significant"
  17714. local declaration gets restricted to include only inlined function
  17715. instances and local (nested) function definitions. */
  17716. if (must_output_die)
  17717. {
  17718. if (inlined_func)
  17719. {
  17720. /* If STMT block is abstract, that means we have been called
  17721. indirectly from dwarf2out_abstract_function.
  17722. That function rightfully marks the descendent blocks (of
  17723. the abstract function it is dealing with) as being abstract,
  17724. precisely to prevent us from emitting any
  17725. DW_TAG_inlined_subroutine DIE as a descendent
  17726. of an abstract function instance. So in that case, we should
  17727. not call gen_inlined_subroutine_die.
  17728. Later though, when cgraph asks dwarf2out to emit info
  17729. for the concrete instance of the function decl into which
  17730. the concrete instance of STMT got inlined, the later will lead
  17731. to the generation of a DW_TAG_inlined_subroutine DIE. */
  17732. if (! BLOCK_ABSTRACT (stmt))
  17733. gen_inlined_subroutine_die (stmt, context_die);
  17734. }
  17735. else
  17736. gen_lexical_block_die (stmt, context_die);
  17737. }
  17738. else
  17739. decls_for_scope (stmt, context_die);
  17740. }
  17741. /* Process variable DECL (or variable with origin ORIGIN) within
  17742. block STMT and add it to CONTEXT_DIE. */
  17743. static void
  17744. process_scope_var (tree stmt, tree decl, tree origin, dw_die_ref context_die)
  17745. {
  17746. dw_die_ref die;
  17747. tree decl_or_origin = decl ? decl : origin;
  17748. if (TREE_CODE (decl_or_origin) == FUNCTION_DECL)
  17749. die = lookup_decl_die (decl_or_origin);
  17750. else if (TREE_CODE (decl_or_origin) == TYPE_DECL
  17751. && TYPE_DECL_IS_STUB (decl_or_origin))
  17752. die = lookup_type_die (TREE_TYPE (decl_or_origin));
  17753. else
  17754. die = NULL;
  17755. if (die != NULL && die->die_parent == NULL)
  17756. add_child_die (context_die, die);
  17757. else if (TREE_CODE (decl_or_origin) == IMPORTED_DECL)
  17758. dwarf2out_imported_module_or_decl_1 (decl_or_origin, DECL_NAME (decl_or_origin),
  17759. stmt, context_die);
  17760. else
  17761. gen_decl_die (decl, origin, context_die);
  17762. }
  17763. /* Generate all of the decls declared within a given scope and (recursively)
  17764. all of its sub-blocks. */
  17765. static void
  17766. decls_for_scope (tree stmt, dw_die_ref context_die)
  17767. {
  17768. tree decl;
  17769. unsigned int i;
  17770. tree subblocks;
  17771. /* Ignore NULL blocks. */
  17772. if (stmt == NULL_TREE)
  17773. return;
  17774. /* Output the DIEs to represent all of the data objects and typedefs
  17775. declared directly within this block but not within any nested
  17776. sub-blocks. Also, nested function and tag DIEs have been
  17777. generated with a parent of NULL; fix that up now. We don't
  17778. have to do this if we're at -g1. */
  17779. if (debug_info_level > DINFO_LEVEL_TERSE)
  17780. {
  17781. for (decl = BLOCK_VARS (stmt); decl != NULL; decl = DECL_CHAIN (decl))
  17782. process_scope_var (stmt, decl, NULL_TREE, context_die);
  17783. for (i = 0; i < BLOCK_NUM_NONLOCALIZED_VARS (stmt); i++)
  17784. process_scope_var (stmt, NULL, BLOCK_NONLOCALIZED_VAR (stmt, i),
  17785. context_die);
  17786. }
  17787. /* Even if we're at -g1, we need to process the subblocks in order to get
  17788. inlined call information. */
  17789. /* Output the DIEs to represent all sub-blocks (and the items declared
  17790. therein) of this block. */
  17791. for (subblocks = BLOCK_SUBBLOCKS (stmt);
  17792. subblocks != NULL;
  17793. subblocks = BLOCK_CHAIN (subblocks))
  17794. gen_block_die (subblocks, context_die);
  17795. }
  17796. /* Is this a typedef we can avoid emitting? */
  17797. static inline int
  17798. is_redundant_typedef (const_tree decl)
  17799. {
  17800. if (TYPE_DECL_IS_STUB (decl))
  17801. return 1;
  17802. if (DECL_ARTIFICIAL (decl)
  17803. && DECL_CONTEXT (decl)
  17804. && is_tagged_type (DECL_CONTEXT (decl))
  17805. && TREE_CODE (TYPE_NAME (DECL_CONTEXT (decl))) == TYPE_DECL
  17806. && DECL_NAME (decl) == DECL_NAME (TYPE_NAME (DECL_CONTEXT (decl))))
  17807. /* Also ignore the artificial member typedef for the class name. */
  17808. return 1;
  17809. return 0;
  17810. }
  17811. /* Return TRUE if TYPE is a typedef that names a type for linkage
  17812. purposes. This kind of typedefs is produced by the C++ FE for
  17813. constructs like:
  17814. typedef struct {...} foo;
  17815. In that case, there is no typedef variant type produced for foo.
  17816. Rather, the TREE_TYPE of the TYPE_DECL of foo is the anonymous
  17817. struct type. */
  17818. static bool
  17819. is_naming_typedef_decl (const_tree decl)
  17820. {
  17821. if (decl == NULL_TREE
  17822. || TREE_CODE (decl) != TYPE_DECL
  17823. || !is_tagged_type (TREE_TYPE (decl))
  17824. || DECL_IS_BUILTIN (decl)
  17825. || is_redundant_typedef (decl)
  17826. /* It looks like Ada produces TYPE_DECLs that are very similar
  17827. to C++ naming typedefs but that have different
  17828. semantics. Let's be specific to c++ for now. */
  17829. || !is_cxx ())
  17830. return FALSE;
  17831. return (DECL_ORIGINAL_TYPE (decl) == NULL_TREE
  17832. && TYPE_NAME (TREE_TYPE (decl)) == decl
  17833. && (TYPE_STUB_DECL (TREE_TYPE (decl))
  17834. != TYPE_NAME (TREE_TYPE (decl))));
  17835. }
  17836. /* Looks up the DIE for a context. */
  17837. static inline dw_die_ref
  17838. lookup_context_die (tree context)
  17839. {
  17840. if (context)
  17841. {
  17842. /* Find die that represents this context. */
  17843. if (TYPE_P (context))
  17844. {
  17845. context = TYPE_MAIN_VARIANT (context);
  17846. dw_die_ref ctx = lookup_type_die (context);
  17847. if (!ctx)
  17848. return NULL;
  17849. return strip_naming_typedef (context, ctx);
  17850. }
  17851. else
  17852. return lookup_decl_die (context);
  17853. }
  17854. return comp_unit_die ();
  17855. }
  17856. /* Returns the DIE for a context. */
  17857. static inline dw_die_ref
  17858. get_context_die (tree context)
  17859. {
  17860. if (context)
  17861. {
  17862. /* Find die that represents this context. */
  17863. if (TYPE_P (context))
  17864. {
  17865. context = TYPE_MAIN_VARIANT (context);
  17866. return strip_naming_typedef (context, force_type_die (context));
  17867. }
  17868. else
  17869. return force_decl_die (context);
  17870. }
  17871. return comp_unit_die ();
  17872. }
  17873. /* Returns the DIE for decl. A DIE will always be returned. */
  17874. static dw_die_ref
  17875. force_decl_die (tree decl)
  17876. {
  17877. dw_die_ref decl_die;
  17878. unsigned saved_external_flag;
  17879. tree save_fn = NULL_TREE;
  17880. decl_die = lookup_decl_die (decl);
  17881. if (!decl_die)
  17882. {
  17883. dw_die_ref context_die = get_context_die (DECL_CONTEXT (decl));
  17884. decl_die = lookup_decl_die (decl);
  17885. if (decl_die)
  17886. return decl_die;
  17887. switch (TREE_CODE (decl))
  17888. {
  17889. case FUNCTION_DECL:
  17890. /* Clear current_function_decl, so that gen_subprogram_die thinks
  17891. that this is a declaration. At this point, we just want to force
  17892. declaration die. */
  17893. save_fn = current_function_decl;
  17894. current_function_decl = NULL_TREE;
  17895. gen_subprogram_die (decl, context_die);
  17896. current_function_decl = save_fn;
  17897. break;
  17898. case VAR_DECL:
  17899. /* Set external flag to force declaration die. Restore it after
  17900. gen_decl_die() call. */
  17901. saved_external_flag = DECL_EXTERNAL (decl);
  17902. DECL_EXTERNAL (decl) = 1;
  17903. gen_decl_die (decl, NULL, context_die);
  17904. DECL_EXTERNAL (decl) = saved_external_flag;
  17905. break;
  17906. case NAMESPACE_DECL:
  17907. if (dwarf_version >= 3 || !dwarf_strict)
  17908. dwarf2out_decl (decl);
  17909. else
  17910. /* DWARF2 has neither DW_TAG_module, nor DW_TAG_namespace. */
  17911. decl_die = comp_unit_die ();
  17912. break;
  17913. case TRANSLATION_UNIT_DECL:
  17914. decl_die = comp_unit_die ();
  17915. break;
  17916. default:
  17917. gcc_unreachable ();
  17918. }
  17919. /* We should be able to find the DIE now. */
  17920. if (!decl_die)
  17921. decl_die = lookup_decl_die (decl);
  17922. gcc_assert (decl_die);
  17923. }
  17924. return decl_die;
  17925. }
  17926. /* Returns the DIE for TYPE, that must not be a base type. A DIE is
  17927. always returned. */
  17928. static dw_die_ref
  17929. force_type_die (tree type)
  17930. {
  17931. dw_die_ref type_die;
  17932. type_die = lookup_type_die (type);
  17933. if (!type_die)
  17934. {
  17935. dw_die_ref context_die = get_context_die (TYPE_CONTEXT (type));
  17936. type_die = modified_type_die (type, TYPE_QUALS_NO_ADDR_SPACE (type),
  17937. context_die);
  17938. gcc_assert (type_die);
  17939. }
  17940. return type_die;
  17941. }
  17942. /* Force out any required namespaces to be able to output DECL,
  17943. and return the new context_die for it, if it's changed. */
  17944. static dw_die_ref
  17945. setup_namespace_context (tree thing, dw_die_ref context_die)
  17946. {
  17947. tree context = (DECL_P (thing)
  17948. ? DECL_CONTEXT (thing) : TYPE_CONTEXT (thing));
  17949. if (context && TREE_CODE (context) == NAMESPACE_DECL)
  17950. /* Force out the namespace. */
  17951. context_die = force_decl_die (context);
  17952. return context_die;
  17953. }
  17954. /* Emit a declaration DIE for THING (which is either a DECL or a tagged
  17955. type) within its namespace, if appropriate.
  17956. For compatibility with older debuggers, namespace DIEs only contain
  17957. declarations; all definitions are emitted at CU scope. */
  17958. static dw_die_ref
  17959. declare_in_namespace (tree thing, dw_die_ref context_die)
  17960. {
  17961. dw_die_ref ns_context;
  17962. if (debug_info_level <= DINFO_LEVEL_TERSE)
  17963. return context_die;
  17964. /* External declarations in the local scope only need to be emitted
  17965. once, not once in the namespace and once in the scope.
  17966. This avoids declaring the `extern' below in the
  17967. namespace DIE as well as in the innermost scope:
  17968. namespace S
  17969. {
  17970. int i=5;
  17971. int foo()
  17972. {
  17973. int i=8;
  17974. extern int i;
  17975. return i;
  17976. }
  17977. }
  17978. */
  17979. if (DECL_P (thing) && DECL_EXTERNAL (thing) && local_scope_p (context_die))
  17980. return context_die;
  17981. /* If this decl is from an inlined function, then don't try to emit it in its
  17982. namespace, as we will get confused. It would have already been emitted
  17983. when the abstract instance of the inline function was emitted anyways. */
  17984. if (DECL_P (thing) && DECL_ABSTRACT_ORIGIN (thing))
  17985. return context_die;
  17986. ns_context = setup_namespace_context (thing, context_die);
  17987. if (ns_context != context_die)
  17988. {
  17989. if (is_fortran ())
  17990. return ns_context;
  17991. if (DECL_P (thing))
  17992. gen_decl_die (thing, NULL, ns_context);
  17993. else
  17994. gen_type_die (thing, ns_context);
  17995. }
  17996. return context_die;
  17997. }
  17998. /* Generate a DIE for a namespace or namespace alias. */
  17999. static void
  18000. gen_namespace_die (tree decl, dw_die_ref context_die)
  18001. {
  18002. dw_die_ref namespace_die;
  18003. /* Namespace aliases have a DECL_ABSTRACT_ORIGIN of the namespace
  18004. they are an alias of. */
  18005. if (DECL_ABSTRACT_ORIGIN (decl) == NULL)
  18006. {
  18007. /* Output a real namespace or module. */
  18008. context_die = setup_namespace_context (decl, comp_unit_die ());
  18009. namespace_die = new_die (is_fortran ()
  18010. ? DW_TAG_module : DW_TAG_namespace,
  18011. context_die, decl);
  18012. /* For Fortran modules defined in different CU don't add src coords. */
  18013. if (namespace_die->die_tag == DW_TAG_module && DECL_EXTERNAL (decl))
  18014. {
  18015. const char *name = dwarf2_name (decl, 0);
  18016. if (name)
  18017. add_name_attribute (namespace_die, name);
  18018. }
  18019. else
  18020. add_name_and_src_coords_attributes (namespace_die, decl);
  18021. if (DECL_EXTERNAL (decl))
  18022. add_AT_flag (namespace_die, DW_AT_declaration, 1);
  18023. equate_decl_number_to_die (decl, namespace_die);
  18024. }
  18025. else
  18026. {
  18027. /* Output a namespace alias. */
  18028. /* Force out the namespace we are an alias of, if necessary. */
  18029. dw_die_ref origin_die
  18030. = force_decl_die (DECL_ABSTRACT_ORIGIN (decl));
  18031. if (DECL_FILE_SCOPE_P (decl)
  18032. || TREE_CODE (DECL_CONTEXT (decl)) == NAMESPACE_DECL)
  18033. context_die = setup_namespace_context (decl, comp_unit_die ());
  18034. /* Now create the namespace alias DIE. */
  18035. namespace_die = new_die (DW_TAG_imported_declaration, context_die, decl);
  18036. add_name_and_src_coords_attributes (namespace_die, decl);
  18037. add_AT_die_ref (namespace_die, DW_AT_import, origin_die);
  18038. equate_decl_number_to_die (decl, namespace_die);
  18039. }
  18040. /* Bypass dwarf2_name's check for DECL_NAMELESS. */
  18041. if (want_pubnames ())
  18042. add_pubname_string (lang_hooks.dwarf_name (decl, 1), namespace_die);
  18043. }
  18044. /* Generate Dwarf debug information for a decl described by DECL.
  18045. The return value is currently only meaningful for PARM_DECLs,
  18046. for all other decls it returns NULL. */
  18047. static dw_die_ref
  18048. gen_decl_die (tree decl, tree origin, dw_die_ref context_die)
  18049. {
  18050. tree decl_or_origin = decl ? decl : origin;
  18051. tree class_origin = NULL, ultimate_origin;
  18052. if (DECL_P (decl_or_origin) && DECL_IGNORED_P (decl_or_origin))
  18053. return NULL;
  18054. /* Ignore pointer bounds decls. */
  18055. if (DECL_P (decl_or_origin)
  18056. && TREE_TYPE (decl_or_origin)
  18057. && POINTER_BOUNDS_P (decl_or_origin))
  18058. return NULL;
  18059. switch (TREE_CODE (decl_or_origin))
  18060. {
  18061. case ERROR_MARK:
  18062. break;
  18063. case CONST_DECL:
  18064. if (!is_fortran () && !is_ada ())
  18065. {
  18066. /* The individual enumerators of an enum type get output when we output
  18067. the Dwarf representation of the relevant enum type itself. */
  18068. break;
  18069. }
  18070. /* Emit its type. */
  18071. gen_type_die (TREE_TYPE (decl), context_die);
  18072. /* And its containing namespace. */
  18073. context_die = declare_in_namespace (decl, context_die);
  18074. gen_const_die (decl, context_die);
  18075. break;
  18076. case FUNCTION_DECL:
  18077. /* Don't output any DIEs to represent mere function declarations,
  18078. unless they are class members or explicit block externs. */
  18079. if (DECL_INITIAL (decl_or_origin) == NULL_TREE
  18080. && DECL_FILE_SCOPE_P (decl_or_origin)
  18081. && (current_function_decl == NULL_TREE
  18082. || DECL_ARTIFICIAL (decl_or_origin)))
  18083. break;
  18084. #if 0
  18085. /* FIXME */
  18086. /* This doesn't work because the C frontend sets DECL_ABSTRACT_ORIGIN
  18087. on local redeclarations of global functions. That seems broken. */
  18088. if (current_function_decl != decl)
  18089. /* This is only a declaration. */;
  18090. #endif
  18091. /* If we're emitting a clone, emit info for the abstract instance. */
  18092. if (origin || DECL_ORIGIN (decl) != decl)
  18093. dwarf2out_abstract_function (origin
  18094. ? DECL_ORIGIN (origin)
  18095. : DECL_ABSTRACT_ORIGIN (decl));
  18096. /* If we're emitting an out-of-line copy of an inline function,
  18097. emit info for the abstract instance and set up to refer to it. */
  18098. else if (cgraph_function_possibly_inlined_p (decl)
  18099. && ! DECL_ABSTRACT_P (decl)
  18100. && ! class_or_namespace_scope_p (context_die)
  18101. /* dwarf2out_abstract_function won't emit a die if this is just
  18102. a declaration. We must avoid setting DECL_ABSTRACT_ORIGIN in
  18103. that case, because that works only if we have a die. */
  18104. && DECL_INITIAL (decl) != NULL_TREE)
  18105. {
  18106. dwarf2out_abstract_function (decl);
  18107. set_decl_origin_self (decl);
  18108. }
  18109. /* Otherwise we're emitting the primary DIE for this decl. */
  18110. else if (debug_info_level > DINFO_LEVEL_TERSE)
  18111. {
  18112. /* Before we describe the FUNCTION_DECL itself, make sure that we
  18113. have its containing type. */
  18114. if (!origin)
  18115. origin = decl_class_context (decl);
  18116. if (origin != NULL_TREE)
  18117. gen_type_die (origin, context_die);
  18118. /* And its return type. */
  18119. gen_type_die (TREE_TYPE (TREE_TYPE (decl)), context_die);
  18120. /* And its virtual context. */
  18121. if (DECL_VINDEX (decl) != NULL_TREE)
  18122. gen_type_die (DECL_CONTEXT (decl), context_die);
  18123. /* Make sure we have a member DIE for decl. */
  18124. if (origin != NULL_TREE)
  18125. gen_type_die_for_member (origin, decl, context_die);
  18126. /* And its containing namespace. */
  18127. context_die = declare_in_namespace (decl, context_die);
  18128. }
  18129. /* Now output a DIE to represent the function itself. */
  18130. if (decl)
  18131. gen_subprogram_die (decl, context_die);
  18132. break;
  18133. case TYPE_DECL:
  18134. /* If we are in terse mode, don't generate any DIEs to represent any
  18135. actual typedefs. */
  18136. if (debug_info_level <= DINFO_LEVEL_TERSE)
  18137. break;
  18138. /* In the special case of a TYPE_DECL node representing the declaration
  18139. of some type tag, if the given TYPE_DECL is marked as having been
  18140. instantiated from some other (original) TYPE_DECL node (e.g. one which
  18141. was generated within the original definition of an inline function) we
  18142. used to generate a special (abbreviated) DW_TAG_structure_type,
  18143. DW_TAG_union_type, or DW_TAG_enumeration_type DIE here. But nothing
  18144. should be actually referencing those DIEs, as variable DIEs with that
  18145. type would be emitted already in the abstract origin, so it was always
  18146. removed during unused type prunning. Don't add anything in this
  18147. case. */
  18148. if (TYPE_DECL_IS_STUB (decl) && decl_ultimate_origin (decl) != NULL_TREE)
  18149. break;
  18150. if (is_redundant_typedef (decl))
  18151. gen_type_die (TREE_TYPE (decl), context_die);
  18152. else
  18153. /* Output a DIE to represent the typedef itself. */
  18154. gen_typedef_die (decl, context_die);
  18155. break;
  18156. case LABEL_DECL:
  18157. if (debug_info_level >= DINFO_LEVEL_NORMAL)
  18158. gen_label_die (decl, context_die);
  18159. break;
  18160. case VAR_DECL:
  18161. case RESULT_DECL:
  18162. /* If we are in terse mode, don't generate any DIEs to represent any
  18163. variable declarations or definitions. */
  18164. if (debug_info_level <= DINFO_LEVEL_TERSE)
  18165. break;
  18166. /* Output any DIEs that are needed to specify the type of this data
  18167. object. */
  18168. if (decl_by_reference_p (decl_or_origin))
  18169. gen_type_die (TREE_TYPE (TREE_TYPE (decl_or_origin)), context_die);
  18170. else
  18171. gen_type_die (TREE_TYPE (decl_or_origin), context_die);
  18172. /* And its containing type. */
  18173. class_origin = decl_class_context (decl_or_origin);
  18174. if (class_origin != NULL_TREE)
  18175. gen_type_die_for_member (class_origin, decl_or_origin, context_die);
  18176. /* And its containing namespace. */
  18177. context_die = declare_in_namespace (decl_or_origin, context_die);
  18178. /* Now output the DIE to represent the data object itself. This gets
  18179. complicated because of the possibility that the VAR_DECL really
  18180. represents an inlined instance of a formal parameter for an inline
  18181. function. */
  18182. ultimate_origin = decl_ultimate_origin (decl_or_origin);
  18183. if (ultimate_origin != NULL_TREE
  18184. && TREE_CODE (ultimate_origin) == PARM_DECL)
  18185. gen_formal_parameter_die (decl, origin,
  18186. true /* Emit name attribute. */,
  18187. context_die);
  18188. else
  18189. gen_variable_die (decl, origin, context_die);
  18190. break;
  18191. case FIELD_DECL:
  18192. /* Ignore the nameless fields that are used to skip bits but handle C++
  18193. anonymous unions and structs. */
  18194. if (DECL_NAME (decl) != NULL_TREE
  18195. || TREE_CODE (TREE_TYPE (decl)) == UNION_TYPE
  18196. || TREE_CODE (TREE_TYPE (decl)) == RECORD_TYPE)
  18197. {
  18198. gen_type_die (member_declared_type (decl), context_die);
  18199. gen_field_die (decl, context_die);
  18200. }
  18201. break;
  18202. case PARM_DECL:
  18203. if (DECL_BY_REFERENCE (decl_or_origin))
  18204. gen_type_die (TREE_TYPE (TREE_TYPE (decl_or_origin)), context_die);
  18205. else
  18206. gen_type_die (TREE_TYPE (decl_or_origin), context_die);
  18207. return gen_formal_parameter_die (decl, origin,
  18208. true /* Emit name attribute. */,
  18209. context_die);
  18210. case NAMESPACE_DECL:
  18211. case IMPORTED_DECL:
  18212. if (dwarf_version >= 3 || !dwarf_strict)
  18213. gen_namespace_die (decl, context_die);
  18214. break;
  18215. case NAMELIST_DECL:
  18216. gen_namelist_decl (DECL_NAME (decl), context_die,
  18217. NAMELIST_DECL_ASSOCIATED_DECL (decl));
  18218. break;
  18219. default:
  18220. /* Probably some frontend-internal decl. Assume we don't care. */
  18221. gcc_assert ((int)TREE_CODE (decl) > NUM_TREE_CODES);
  18222. break;
  18223. }
  18224. return NULL;
  18225. }
  18226. /* Output debug information for global decl DECL. Called from toplev.c after
  18227. compilation proper has finished. */
  18228. static void
  18229. dwarf2out_global_decl (tree decl)
  18230. {
  18231. /* Output DWARF2 information for file-scope tentative data object
  18232. declarations, file-scope (extern) function declarations (which
  18233. had no corresponding body) and file-scope tagged type declarations
  18234. and definitions which have not yet been forced out. */
  18235. if ((TREE_CODE (decl) != FUNCTION_DECL || !DECL_INITIAL (decl))
  18236. && !POINTER_BOUNDS_P (decl))
  18237. dwarf2out_decl (decl);
  18238. }
  18239. /* Output debug information for type decl DECL. Called from toplev.c
  18240. and from language front ends (to record built-in types). */
  18241. static void
  18242. dwarf2out_type_decl (tree decl, int local)
  18243. {
  18244. if (!local)
  18245. dwarf2out_decl (decl);
  18246. }
  18247. /* Output debug information for imported module or decl DECL.
  18248. NAME is non-NULL name in the lexical block if the decl has been renamed.
  18249. LEXICAL_BLOCK is the lexical block (which TREE_CODE is a BLOCK)
  18250. that DECL belongs to.
  18251. LEXICAL_BLOCK_DIE is the DIE of LEXICAL_BLOCK. */
  18252. static void
  18253. dwarf2out_imported_module_or_decl_1 (tree decl,
  18254. tree name,
  18255. tree lexical_block,
  18256. dw_die_ref lexical_block_die)
  18257. {
  18258. expanded_location xloc;
  18259. dw_die_ref imported_die = NULL;
  18260. dw_die_ref at_import_die;
  18261. if (TREE_CODE (decl) == IMPORTED_DECL)
  18262. {
  18263. xloc = expand_location (DECL_SOURCE_LOCATION (decl));
  18264. decl = IMPORTED_DECL_ASSOCIATED_DECL (decl);
  18265. gcc_assert (decl);
  18266. }
  18267. else
  18268. xloc = expand_location (input_location);
  18269. if (TREE_CODE (decl) == TYPE_DECL || TREE_CODE (decl) == CONST_DECL)
  18270. {
  18271. at_import_die = force_type_die (TREE_TYPE (decl));
  18272. /* For namespace N { typedef void T; } using N::T; base_type_die
  18273. returns NULL, but DW_TAG_imported_declaration requires
  18274. the DW_AT_import tag. Force creation of DW_TAG_typedef. */
  18275. if (!at_import_die)
  18276. {
  18277. gcc_assert (TREE_CODE (decl) == TYPE_DECL);
  18278. gen_typedef_die (decl, get_context_die (DECL_CONTEXT (decl)));
  18279. at_import_die = lookup_type_die (TREE_TYPE (decl));
  18280. gcc_assert (at_import_die);
  18281. }
  18282. }
  18283. else
  18284. {
  18285. at_import_die = lookup_decl_die (decl);
  18286. if (!at_import_die)
  18287. {
  18288. /* If we're trying to avoid duplicate debug info, we may not have
  18289. emitted the member decl for this field. Emit it now. */
  18290. if (TREE_CODE (decl) == FIELD_DECL)
  18291. {
  18292. tree type = DECL_CONTEXT (decl);
  18293. if (TYPE_CONTEXT (type)
  18294. && TYPE_P (TYPE_CONTEXT (type))
  18295. && !should_emit_struct_debug (TYPE_CONTEXT (type),
  18296. DINFO_USAGE_DIR_USE))
  18297. return;
  18298. gen_type_die_for_member (type, decl,
  18299. get_context_die (TYPE_CONTEXT (type)));
  18300. }
  18301. if (TREE_CODE (decl) == NAMELIST_DECL)
  18302. at_import_die = gen_namelist_decl (DECL_NAME (decl),
  18303. get_context_die (DECL_CONTEXT (decl)),
  18304. NULL_TREE);
  18305. else
  18306. at_import_die = force_decl_die (decl);
  18307. }
  18308. }
  18309. if (TREE_CODE (decl) == NAMESPACE_DECL)
  18310. {
  18311. if (dwarf_version >= 3 || !dwarf_strict)
  18312. imported_die = new_die (DW_TAG_imported_module,
  18313. lexical_block_die,
  18314. lexical_block);
  18315. else
  18316. return;
  18317. }
  18318. else
  18319. imported_die = new_die (DW_TAG_imported_declaration,
  18320. lexical_block_die,
  18321. lexical_block);
  18322. add_AT_file (imported_die, DW_AT_decl_file, lookup_filename (xloc.file));
  18323. add_AT_unsigned (imported_die, DW_AT_decl_line, xloc.line);
  18324. if (name)
  18325. add_AT_string (imported_die, DW_AT_name,
  18326. IDENTIFIER_POINTER (name));
  18327. add_AT_die_ref (imported_die, DW_AT_import, at_import_die);
  18328. }
  18329. /* Output debug information for imported module or decl DECL.
  18330. NAME is non-NULL name in context if the decl has been renamed.
  18331. CHILD is true if decl is one of the renamed decls as part of
  18332. importing whole module. */
  18333. static void
  18334. dwarf2out_imported_module_or_decl (tree decl, tree name, tree context,
  18335. bool child)
  18336. {
  18337. /* dw_die_ref at_import_die; */
  18338. dw_die_ref scope_die;
  18339. if (debug_info_level <= DINFO_LEVEL_TERSE)
  18340. return;
  18341. gcc_assert (decl);
  18342. /* To emit DW_TAG_imported_module or DW_TAG_imported_decl, we need two DIEs.
  18343. We need decl DIE for reference and scope die. First, get DIE for the decl
  18344. itself. */
  18345. /* Get the scope die for decl context. Use comp_unit_die for global module
  18346. or decl. If die is not found for non globals, force new die. */
  18347. if (context
  18348. && TYPE_P (context)
  18349. && !should_emit_struct_debug (context, DINFO_USAGE_DIR_USE))
  18350. return;
  18351. if (!(dwarf_version >= 3 || !dwarf_strict))
  18352. return;
  18353. scope_die = get_context_die (context);
  18354. if (child)
  18355. {
  18356. gcc_assert (scope_die->die_child);
  18357. gcc_assert (scope_die->die_child->die_tag == DW_TAG_imported_module);
  18358. gcc_assert (TREE_CODE (decl) != NAMESPACE_DECL);
  18359. scope_die = scope_die->die_child;
  18360. }
  18361. /* OK, now we have DIEs for decl as well as scope. Emit imported die. */
  18362. dwarf2out_imported_module_or_decl_1 (decl, name, context, scope_die);
  18363. }
  18364. /* Output debug information for namelists. */
  18365. static dw_die_ref
  18366. gen_namelist_decl (tree name, dw_die_ref scope_die, tree item_decls)
  18367. {
  18368. dw_die_ref nml_die, nml_item_die, nml_item_ref_die;
  18369. tree value;
  18370. unsigned i;
  18371. if (debug_info_level <= DINFO_LEVEL_TERSE)
  18372. return NULL;
  18373. gcc_assert (scope_die != NULL);
  18374. nml_die = new_die (DW_TAG_namelist, scope_die, NULL);
  18375. add_AT_string (nml_die, DW_AT_name, IDENTIFIER_POINTER (name));
  18376. /* If there are no item_decls, we have a nondefining namelist, e.g.
  18377. with USE association; hence, set DW_AT_declaration. */
  18378. if (item_decls == NULL_TREE)
  18379. {
  18380. add_AT_flag (nml_die, DW_AT_declaration, 1);
  18381. return nml_die;
  18382. }
  18383. FOR_EACH_CONSTRUCTOR_VALUE (CONSTRUCTOR_ELTS (item_decls), i, value)
  18384. {
  18385. nml_item_ref_die = lookup_decl_die (value);
  18386. if (!nml_item_ref_die)
  18387. nml_item_ref_die = force_decl_die (value);
  18388. nml_item_die = new_die (DW_TAG_namelist_item, nml_die, NULL);
  18389. add_AT_die_ref (nml_item_die, DW_AT_namelist_items, nml_item_ref_die);
  18390. }
  18391. return nml_die;
  18392. }
  18393. /* Write the debugging output for DECL. */
  18394. static void
  18395. dwarf2out_decl (tree decl)
  18396. {
  18397. dw_die_ref context_die = comp_unit_die ();
  18398. switch (TREE_CODE (decl))
  18399. {
  18400. case ERROR_MARK:
  18401. return;
  18402. case FUNCTION_DECL:
  18403. /* What we would really like to do here is to filter out all mere
  18404. file-scope declarations of file-scope functions which are never
  18405. referenced later within this translation unit (and keep all of ones
  18406. that *are* referenced later on) but we aren't clairvoyant, so we have
  18407. no idea which functions will be referenced in the future (i.e. later
  18408. on within the current translation unit). So here we just ignore all
  18409. file-scope function declarations which are not also definitions. If
  18410. and when the debugger needs to know something about these functions,
  18411. it will have to hunt around and find the DWARF information associated
  18412. with the definition of the function.
  18413. We can't just check DECL_EXTERNAL to find out which FUNCTION_DECL
  18414. nodes represent definitions and which ones represent mere
  18415. declarations. We have to check DECL_INITIAL instead. That's because
  18416. the C front-end supports some weird semantics for "extern inline"
  18417. function definitions. These can get inlined within the current
  18418. translation unit (and thus, we need to generate Dwarf info for their
  18419. abstract instances so that the Dwarf info for the concrete inlined
  18420. instances can have something to refer to) but the compiler never
  18421. generates any out-of-lines instances of such things (despite the fact
  18422. that they *are* definitions).
  18423. The important point is that the C front-end marks these "extern
  18424. inline" functions as DECL_EXTERNAL, but we need to generate DWARF for
  18425. them anyway. Note that the C++ front-end also plays some similar games
  18426. for inline function definitions appearing within include files which
  18427. also contain `#pragma interface' pragmas.
  18428. If we are called from dwarf2out_abstract_function output a DIE
  18429. anyway. We can end up here this way with early inlining and LTO
  18430. where the inlined function is output in a different LTRANS unit
  18431. or not at all. */
  18432. if (DECL_INITIAL (decl) == NULL_TREE
  18433. && ! DECL_ABSTRACT_P (decl))
  18434. return;
  18435. /* If we're a nested function, initially use a parent of NULL; if we're
  18436. a plain function, this will be fixed up in decls_for_scope. If
  18437. we're a method, it will be ignored, since we already have a DIE. */
  18438. if (decl_function_context (decl)
  18439. /* But if we're in terse mode, we don't care about scope. */
  18440. && debug_info_level > DINFO_LEVEL_TERSE)
  18441. context_die = NULL;
  18442. break;
  18443. case VAR_DECL:
  18444. /* Ignore this VAR_DECL if it refers to a file-scope extern data object
  18445. declaration and if the declaration was never even referenced from
  18446. within this entire compilation unit. We suppress these DIEs in
  18447. order to save space in the .debug section (by eliminating entries
  18448. which are probably useless). Note that we must not suppress
  18449. block-local extern declarations (whether used or not) because that
  18450. would screw-up the debugger's name lookup mechanism and cause it to
  18451. miss things which really ought to be in scope at a given point. */
  18452. if (DECL_EXTERNAL (decl) && !TREE_USED (decl))
  18453. return;
  18454. /* For local statics lookup proper context die. */
  18455. if (TREE_STATIC (decl)
  18456. && DECL_CONTEXT (decl)
  18457. && TREE_CODE (DECL_CONTEXT (decl)) == FUNCTION_DECL)
  18458. context_die = lookup_decl_die (DECL_CONTEXT (decl));
  18459. /* If we are in terse mode, don't generate any DIEs to represent any
  18460. variable declarations or definitions. */
  18461. if (debug_info_level <= DINFO_LEVEL_TERSE)
  18462. return;
  18463. break;
  18464. case CONST_DECL:
  18465. if (debug_info_level <= DINFO_LEVEL_TERSE)
  18466. return;
  18467. if (!is_fortran () && !is_ada ())
  18468. return;
  18469. if (TREE_STATIC (decl) && decl_function_context (decl))
  18470. context_die = lookup_decl_die (DECL_CONTEXT (decl));
  18471. break;
  18472. case NAMESPACE_DECL:
  18473. case IMPORTED_DECL:
  18474. if (debug_info_level <= DINFO_LEVEL_TERSE)
  18475. return;
  18476. if (lookup_decl_die (decl) != NULL)
  18477. return;
  18478. break;
  18479. case TYPE_DECL:
  18480. /* Don't emit stubs for types unless they are needed by other DIEs. */
  18481. if (TYPE_DECL_SUPPRESS_DEBUG (decl))
  18482. return;
  18483. /* Don't bother trying to generate any DIEs to represent any of the
  18484. normal built-in types for the language we are compiling. */
  18485. if (DECL_IS_BUILTIN (decl))
  18486. return;
  18487. /* If we are in terse mode, don't generate any DIEs for types. */
  18488. if (debug_info_level <= DINFO_LEVEL_TERSE)
  18489. return;
  18490. /* If we're a function-scope tag, initially use a parent of NULL;
  18491. this will be fixed up in decls_for_scope. */
  18492. if (decl_function_context (decl))
  18493. context_die = NULL;
  18494. break;
  18495. case NAMELIST_DECL:
  18496. break;
  18497. default:
  18498. return;
  18499. }
  18500. gen_decl_die (decl, NULL, context_die);
  18501. }
  18502. /* Write the debugging output for DECL. */
  18503. static void
  18504. dwarf2out_function_decl (tree decl)
  18505. {
  18506. dwarf2out_decl (decl);
  18507. call_arg_locations = NULL;
  18508. call_arg_loc_last = NULL;
  18509. call_site_count = -1;
  18510. tail_call_site_count = -1;
  18511. block_map.release ();
  18512. decl_loc_table->empty ();
  18513. cached_dw_loc_list_table->empty ();
  18514. }
  18515. /* Output a marker (i.e. a label) for the beginning of the generated code for
  18516. a lexical block. */
  18517. static void
  18518. dwarf2out_begin_block (unsigned int line ATTRIBUTE_UNUSED,
  18519. unsigned int blocknum)
  18520. {
  18521. switch_to_section (current_function_section ());
  18522. ASM_OUTPUT_DEBUG_LABEL (asm_out_file, BLOCK_BEGIN_LABEL, blocknum);
  18523. }
  18524. /* Output a marker (i.e. a label) for the end of the generated code for a
  18525. lexical block. */
  18526. static void
  18527. dwarf2out_end_block (unsigned int line ATTRIBUTE_UNUSED, unsigned int blocknum)
  18528. {
  18529. switch_to_section (current_function_section ());
  18530. ASM_OUTPUT_DEBUG_LABEL (asm_out_file, BLOCK_END_LABEL, blocknum);
  18531. }
  18532. /* Returns nonzero if it is appropriate not to emit any debugging
  18533. information for BLOCK, because it doesn't contain any instructions.
  18534. Don't allow this for blocks with nested functions or local classes
  18535. as we would end up with orphans, and in the presence of scheduling
  18536. we may end up calling them anyway. */
  18537. static bool
  18538. dwarf2out_ignore_block (const_tree block)
  18539. {
  18540. tree decl;
  18541. unsigned int i;
  18542. for (decl = BLOCK_VARS (block); decl; decl = DECL_CHAIN (decl))
  18543. if (TREE_CODE (decl) == FUNCTION_DECL
  18544. || (TREE_CODE (decl) == TYPE_DECL && TYPE_DECL_IS_STUB (decl)))
  18545. return 0;
  18546. for (i = 0; i < BLOCK_NUM_NONLOCALIZED_VARS (block); i++)
  18547. {
  18548. decl = BLOCK_NONLOCALIZED_VAR (block, i);
  18549. if (TREE_CODE (decl) == FUNCTION_DECL
  18550. || (TREE_CODE (decl) == TYPE_DECL && TYPE_DECL_IS_STUB (decl)))
  18551. return 0;
  18552. }
  18553. return 1;
  18554. }
  18555. /* Hash table routines for file_hash. */
  18556. bool
  18557. dwarf_file_hasher::equal (dwarf_file_data *p1, const char *p2)
  18558. {
  18559. return filename_cmp (p1->filename, p2) == 0;
  18560. }
  18561. hashval_t
  18562. dwarf_file_hasher::hash (dwarf_file_data *p)
  18563. {
  18564. return htab_hash_string (p->filename);
  18565. }
  18566. /* Lookup FILE_NAME (in the list of filenames that we know about here in
  18567. dwarf2out.c) and return its "index". The index of each (known) filename is
  18568. just a unique number which is associated with only that one filename. We
  18569. need such numbers for the sake of generating labels (in the .debug_sfnames
  18570. section) and references to those files numbers (in the .debug_srcinfo
  18571. and.debug_macinfo sections). If the filename given as an argument is not
  18572. found in our current list, add it to the list and assign it the next
  18573. available unique index number. In order to speed up searches, we remember
  18574. the index of the filename was looked up last. This handles the majority of
  18575. all searches. */
  18576. static struct dwarf_file_data *
  18577. lookup_filename (const char *file_name)
  18578. {
  18579. struct dwarf_file_data * created;
  18580. /* Check to see if the file name that was searched on the previous
  18581. call matches this file name. If so, return the index. */
  18582. if (file_table_last_lookup
  18583. && (file_name == file_table_last_lookup->filename
  18584. || filename_cmp (file_table_last_lookup->filename, file_name) == 0))
  18585. return file_table_last_lookup;
  18586. /* Didn't match the previous lookup, search the table. */
  18587. dwarf_file_data **slot
  18588. = file_table->find_slot_with_hash (file_name, htab_hash_string (file_name),
  18589. INSERT);
  18590. if (*slot)
  18591. return *slot;
  18592. created = ggc_alloc<dwarf_file_data> ();
  18593. created->filename = file_name;
  18594. created->emitted_number = 0;
  18595. *slot = created;
  18596. return created;
  18597. }
  18598. /* If the assembler will construct the file table, then translate the compiler
  18599. internal file table number into the assembler file table number, and emit
  18600. a .file directive if we haven't already emitted one yet. The file table
  18601. numbers are different because we prune debug info for unused variables and
  18602. types, which may include filenames. */
  18603. static int
  18604. maybe_emit_file (struct dwarf_file_data * fd)
  18605. {
  18606. if (! fd->emitted_number)
  18607. {
  18608. if (last_emitted_file)
  18609. fd->emitted_number = last_emitted_file->emitted_number + 1;
  18610. else
  18611. fd->emitted_number = 1;
  18612. last_emitted_file = fd;
  18613. if (DWARF2_ASM_LINE_DEBUG_INFO)
  18614. {
  18615. fprintf (asm_out_file, "\t.file %u ", fd->emitted_number);
  18616. output_quoted_string (asm_out_file,
  18617. remap_debug_filename (fd->filename));
  18618. fputc ('\n', asm_out_file);
  18619. }
  18620. }
  18621. return fd->emitted_number;
  18622. }
  18623. /* Schedule generation of a DW_AT_const_value attribute to DIE.
  18624. That generation should happen after function debug info has been
  18625. generated. The value of the attribute is the constant value of ARG. */
  18626. static void
  18627. append_entry_to_tmpl_value_parm_die_table (dw_die_ref die, tree arg)
  18628. {
  18629. die_arg_entry entry;
  18630. if (!die || !arg)
  18631. return;
  18632. if (!tmpl_value_parm_die_table)
  18633. vec_alloc (tmpl_value_parm_die_table, 32);
  18634. entry.die = die;
  18635. entry.arg = arg;
  18636. vec_safe_push (tmpl_value_parm_die_table, entry);
  18637. }
  18638. /* Return TRUE if T is an instance of generic type, FALSE
  18639. otherwise. */
  18640. static bool
  18641. generic_type_p (tree t)
  18642. {
  18643. if (t == NULL_TREE || !TYPE_P (t))
  18644. return false;
  18645. return lang_hooks.get_innermost_generic_parms (t) != NULL_TREE;
  18646. }
  18647. /* Schedule the generation of the generic parameter dies for the
  18648. instance of generic type T. The proper generation itself is later
  18649. done by gen_scheduled_generic_parms_dies. */
  18650. static void
  18651. schedule_generic_params_dies_gen (tree t)
  18652. {
  18653. if (!generic_type_p (t))
  18654. return;
  18655. if (!generic_type_instances)
  18656. vec_alloc (generic_type_instances, 256);
  18657. vec_safe_push (generic_type_instances, t);
  18658. }
  18659. /* Add a DW_AT_const_value attribute to DIEs that were scheduled
  18660. by append_entry_to_tmpl_value_parm_die_table. This function must
  18661. be called after function DIEs have been generated. */
  18662. static void
  18663. gen_remaining_tmpl_value_param_die_attribute (void)
  18664. {
  18665. if (tmpl_value_parm_die_table)
  18666. {
  18667. unsigned i;
  18668. die_arg_entry *e;
  18669. FOR_EACH_VEC_ELT (*tmpl_value_parm_die_table, i, e)
  18670. tree_add_const_value_attribute (e->die, e->arg);
  18671. }
  18672. }
  18673. /* Generate generic parameters DIEs for instances of generic types
  18674. that have been previously scheduled by
  18675. schedule_generic_params_dies_gen. This function must be called
  18676. after all the types of the CU have been laid out. */
  18677. static void
  18678. gen_scheduled_generic_parms_dies (void)
  18679. {
  18680. unsigned i;
  18681. tree t;
  18682. if (!generic_type_instances)
  18683. return;
  18684. FOR_EACH_VEC_ELT (*generic_type_instances, i, t)
  18685. if (COMPLETE_TYPE_P (t))
  18686. gen_generic_params_dies (t);
  18687. }
  18688. /* Replace DW_AT_name for the decl with name. */
  18689. static void
  18690. dwarf2out_set_name (tree decl, tree name)
  18691. {
  18692. dw_die_ref die;
  18693. dw_attr_ref attr;
  18694. const char *dname;
  18695. die = TYPE_SYMTAB_DIE (decl);
  18696. if (!die)
  18697. return;
  18698. dname = dwarf2_name (name, 0);
  18699. if (!dname)
  18700. return;
  18701. attr = get_AT (die, DW_AT_name);
  18702. if (attr)
  18703. {
  18704. struct indirect_string_node *node;
  18705. node = find_AT_string (dname);
  18706. /* replace the string. */
  18707. attr->dw_attr_val.v.val_str = node;
  18708. }
  18709. else
  18710. add_name_attribute (die, dname);
  18711. }
  18712. /* True if before or during processing of the first function being emitted. */
  18713. static bool in_first_function_p = true;
  18714. /* True if loc_note during dwarf2out_var_location call might still be
  18715. before first real instruction at address equal to .Ltext0. */
  18716. static bool maybe_at_text_label_p = true;
  18717. /* One above highest N where .LVLN label might be equal to .Ltext0 label. */
  18718. static unsigned int first_loclabel_num_not_at_text_label;
  18719. /* Called by the final INSN scan whenever we see a var location. We
  18720. use it to drop labels in the right places, and throw the location in
  18721. our lookup table. */
  18722. static void
  18723. dwarf2out_var_location (rtx_insn *loc_note)
  18724. {
  18725. char loclabel[MAX_ARTIFICIAL_LABEL_BYTES + 2];
  18726. struct var_loc_node *newloc;
  18727. rtx_insn *next_real, *next_note;
  18728. static const char *last_label;
  18729. static const char *last_postcall_label;
  18730. static bool last_in_cold_section_p;
  18731. static rtx_insn *expected_next_loc_note;
  18732. tree decl;
  18733. bool var_loc_p;
  18734. if (!NOTE_P (loc_note))
  18735. {
  18736. if (CALL_P (loc_note))
  18737. {
  18738. call_site_count++;
  18739. if (SIBLING_CALL_P (loc_note))
  18740. tail_call_site_count++;
  18741. }
  18742. return;
  18743. }
  18744. var_loc_p = NOTE_KIND (loc_note) == NOTE_INSN_VAR_LOCATION;
  18745. if (var_loc_p && !DECL_P (NOTE_VAR_LOCATION_DECL (loc_note)))
  18746. return;
  18747. /* Optimize processing a large consecutive sequence of location
  18748. notes so we don't spend too much time in next_real_insn. If the
  18749. next insn is another location note, remember the next_real_insn
  18750. calculation for next time. */
  18751. next_real = cached_next_real_insn;
  18752. if (next_real)
  18753. {
  18754. if (expected_next_loc_note != loc_note)
  18755. next_real = NULL;
  18756. }
  18757. next_note = NEXT_INSN (loc_note);
  18758. if (! next_note
  18759. || next_note->deleted ()
  18760. || ! NOTE_P (next_note)
  18761. || (NOTE_KIND (next_note) != NOTE_INSN_VAR_LOCATION
  18762. && NOTE_KIND (next_note) != NOTE_INSN_CALL_ARG_LOCATION))
  18763. next_note = NULL;
  18764. if (! next_real)
  18765. next_real = next_real_insn (loc_note);
  18766. if (next_note)
  18767. {
  18768. expected_next_loc_note = next_note;
  18769. cached_next_real_insn = next_real;
  18770. }
  18771. else
  18772. cached_next_real_insn = NULL;
  18773. /* If there are no instructions which would be affected by this note,
  18774. don't do anything. */
  18775. if (var_loc_p
  18776. && next_real == NULL_RTX
  18777. && !NOTE_DURING_CALL_P (loc_note))
  18778. return;
  18779. if (next_real == NULL_RTX)
  18780. next_real = get_last_insn ();
  18781. /* If there were any real insns between note we processed last time
  18782. and this note (or if it is the first note), clear
  18783. last_{,postcall_}label so that they are not reused this time. */
  18784. if (last_var_location_insn == NULL_RTX
  18785. || last_var_location_insn != next_real
  18786. || last_in_cold_section_p != in_cold_section_p)
  18787. {
  18788. last_label = NULL;
  18789. last_postcall_label = NULL;
  18790. }
  18791. if (var_loc_p)
  18792. {
  18793. decl = NOTE_VAR_LOCATION_DECL (loc_note);
  18794. newloc = add_var_loc_to_decl (decl, loc_note,
  18795. NOTE_DURING_CALL_P (loc_note)
  18796. ? last_postcall_label : last_label);
  18797. if (newloc == NULL)
  18798. return;
  18799. }
  18800. else
  18801. {
  18802. decl = NULL_TREE;
  18803. newloc = NULL;
  18804. }
  18805. /* If there were no real insns between note we processed last time
  18806. and this note, use the label we emitted last time. Otherwise
  18807. create a new label and emit it. */
  18808. if (last_label == NULL)
  18809. {
  18810. ASM_GENERATE_INTERNAL_LABEL (loclabel, "LVL", loclabel_num);
  18811. ASM_OUTPUT_DEBUG_LABEL (asm_out_file, "LVL", loclabel_num);
  18812. loclabel_num++;
  18813. last_label = ggc_strdup (loclabel);
  18814. /* See if loclabel might be equal to .Ltext0. If yes,
  18815. bump first_loclabel_num_not_at_text_label. */
  18816. if (!have_multiple_function_sections
  18817. && in_first_function_p
  18818. && maybe_at_text_label_p)
  18819. {
  18820. static rtx_insn *last_start;
  18821. rtx_insn *insn;
  18822. for (insn = loc_note; insn; insn = previous_insn (insn))
  18823. if (insn == last_start)
  18824. break;
  18825. else if (!NONDEBUG_INSN_P (insn))
  18826. continue;
  18827. else
  18828. {
  18829. rtx body = PATTERN (insn);
  18830. if (GET_CODE (body) == USE || GET_CODE (body) == CLOBBER)
  18831. continue;
  18832. /* Inline asm could occupy zero bytes. */
  18833. else if (GET_CODE (body) == ASM_INPUT
  18834. || asm_noperands (body) >= 0)
  18835. continue;
  18836. #ifdef HAVE_attr_length
  18837. else if (get_attr_min_length (insn) == 0)
  18838. continue;
  18839. #endif
  18840. else
  18841. {
  18842. /* Assume insn has non-zero length. */
  18843. maybe_at_text_label_p = false;
  18844. break;
  18845. }
  18846. }
  18847. if (maybe_at_text_label_p)
  18848. {
  18849. last_start = loc_note;
  18850. first_loclabel_num_not_at_text_label = loclabel_num;
  18851. }
  18852. }
  18853. }
  18854. if (!var_loc_p)
  18855. {
  18856. struct call_arg_loc_node *ca_loc
  18857. = ggc_cleared_alloc<call_arg_loc_node> ();
  18858. rtx_insn *prev = prev_real_insn (loc_note);
  18859. rtx x;
  18860. ca_loc->call_arg_loc_note = loc_note;
  18861. ca_loc->next = NULL;
  18862. ca_loc->label = last_label;
  18863. gcc_assert (prev
  18864. && (CALL_P (prev)
  18865. || (NONJUMP_INSN_P (prev)
  18866. && GET_CODE (PATTERN (prev)) == SEQUENCE
  18867. && CALL_P (XVECEXP (PATTERN (prev), 0, 0)))));
  18868. if (!CALL_P (prev))
  18869. prev = as_a <rtx_sequence *> (PATTERN (prev))->insn (0);
  18870. ca_loc->tail_call_p = SIBLING_CALL_P (prev);
  18871. x = get_call_rtx_from (PATTERN (prev));
  18872. if (x)
  18873. {
  18874. x = XEXP (XEXP (x, 0), 0);
  18875. if (GET_CODE (x) == SYMBOL_REF
  18876. && SYMBOL_REF_DECL (x)
  18877. && TREE_CODE (SYMBOL_REF_DECL (x)) == FUNCTION_DECL)
  18878. ca_loc->symbol_ref = x;
  18879. }
  18880. ca_loc->block = insn_scope (prev);
  18881. if (call_arg_locations)
  18882. call_arg_loc_last->next = ca_loc;
  18883. else
  18884. call_arg_locations = ca_loc;
  18885. call_arg_loc_last = ca_loc;
  18886. }
  18887. else if (!NOTE_DURING_CALL_P (loc_note))
  18888. newloc->label = last_label;
  18889. else
  18890. {
  18891. if (!last_postcall_label)
  18892. {
  18893. sprintf (loclabel, "%s-1", last_label);
  18894. last_postcall_label = ggc_strdup (loclabel);
  18895. }
  18896. newloc->label = last_postcall_label;
  18897. }
  18898. last_var_location_insn = next_real;
  18899. last_in_cold_section_p = in_cold_section_p;
  18900. }
  18901. /* Note in one location list that text section has changed. */
  18902. int
  18903. var_location_switch_text_section_1 (var_loc_list **slot, void *)
  18904. {
  18905. var_loc_list *list = *slot;
  18906. if (list->first)
  18907. list->last_before_switch
  18908. = list->last->next ? list->last->next : list->last;
  18909. return 1;
  18910. }
  18911. /* Note in all location lists that text section has changed. */
  18912. static void
  18913. var_location_switch_text_section (void)
  18914. {
  18915. if (decl_loc_table == NULL)
  18916. return;
  18917. decl_loc_table->traverse<void *, var_location_switch_text_section_1> (NULL);
  18918. }
  18919. /* Create a new line number table. */
  18920. static dw_line_info_table *
  18921. new_line_info_table (void)
  18922. {
  18923. dw_line_info_table *table;
  18924. table = ggc_cleared_alloc<dw_line_info_table_struct> ();
  18925. table->file_num = 1;
  18926. table->line_num = 1;
  18927. table->is_stmt = DWARF_LINE_DEFAULT_IS_STMT_START;
  18928. return table;
  18929. }
  18930. /* Lookup the "current" table into which we emit line info, so
  18931. that we don't have to do it for every source line. */
  18932. static void
  18933. set_cur_line_info_table (section *sec)
  18934. {
  18935. dw_line_info_table *table;
  18936. if (sec == text_section)
  18937. table = text_section_line_info;
  18938. else if (sec == cold_text_section)
  18939. {
  18940. table = cold_text_section_line_info;
  18941. if (!table)
  18942. {
  18943. cold_text_section_line_info = table = new_line_info_table ();
  18944. table->end_label = cold_end_label;
  18945. }
  18946. }
  18947. else
  18948. {
  18949. const char *end_label;
  18950. if (flag_reorder_blocks_and_partition)
  18951. {
  18952. if (in_cold_section_p)
  18953. end_label = crtl->subsections.cold_section_end_label;
  18954. else
  18955. end_label = crtl->subsections.hot_section_end_label;
  18956. }
  18957. else
  18958. {
  18959. char label[MAX_ARTIFICIAL_LABEL_BYTES];
  18960. ASM_GENERATE_INTERNAL_LABEL (label, FUNC_END_LABEL,
  18961. current_function_funcdef_no);
  18962. end_label = ggc_strdup (label);
  18963. }
  18964. table = new_line_info_table ();
  18965. table->end_label = end_label;
  18966. vec_safe_push (separate_line_info, table);
  18967. }
  18968. if (DWARF2_ASM_LINE_DEBUG_INFO)
  18969. table->is_stmt = (cur_line_info_table
  18970. ? cur_line_info_table->is_stmt
  18971. : DWARF_LINE_DEFAULT_IS_STMT_START);
  18972. cur_line_info_table = table;
  18973. }
  18974. /* We need to reset the locations at the beginning of each
  18975. function. We can't do this in the end_function hook, because the
  18976. declarations that use the locations won't have been output when
  18977. that hook is called. Also compute have_multiple_function_sections here. */
  18978. static void
  18979. dwarf2out_begin_function (tree fun)
  18980. {
  18981. section *sec = function_section (fun);
  18982. if (sec != text_section)
  18983. have_multiple_function_sections = true;
  18984. if (flag_reorder_blocks_and_partition && !cold_text_section)
  18985. {
  18986. gcc_assert (current_function_decl == fun);
  18987. cold_text_section = unlikely_text_section ();
  18988. switch_to_section (cold_text_section);
  18989. ASM_OUTPUT_LABEL (asm_out_file, cold_text_section_label);
  18990. switch_to_section (sec);
  18991. }
  18992. dwarf2out_note_section_used ();
  18993. call_site_count = 0;
  18994. tail_call_site_count = 0;
  18995. set_cur_line_info_table (sec);
  18996. }
  18997. /* Helper function of dwarf2out_end_function, called only after emitting
  18998. the very first function into assembly. Check if some .debug_loc range
  18999. might end with a .LVL* label that could be equal to .Ltext0.
  19000. In that case we must force using absolute addresses in .debug_loc ranges,
  19001. because this range could be .LVLN-.Ltext0 .. .LVLM-.Ltext0 for
  19002. .LVLN == .LVLM == .Ltext0, thus 0 .. 0, which is a .debug_loc
  19003. list terminator.
  19004. Set have_multiple_function_sections to true in that case and
  19005. terminate htab traversal. */
  19006. int
  19007. find_empty_loc_ranges_at_text_label (var_loc_list **slot, int)
  19008. {
  19009. var_loc_list *entry = *slot;
  19010. struct var_loc_node *node;
  19011. node = entry->first;
  19012. if (node && node->next && node->next->label)
  19013. {
  19014. unsigned int i;
  19015. const char *label = node->next->label;
  19016. char loclabel[MAX_ARTIFICIAL_LABEL_BYTES];
  19017. for (i = 0; i < first_loclabel_num_not_at_text_label; i++)
  19018. {
  19019. ASM_GENERATE_INTERNAL_LABEL (loclabel, "LVL", i);
  19020. if (strcmp (label, loclabel) == 0)
  19021. {
  19022. have_multiple_function_sections = true;
  19023. return 0;
  19024. }
  19025. }
  19026. }
  19027. return 1;
  19028. }
  19029. /* Hook called after emitting a function into assembly.
  19030. This does something only for the very first function emitted. */
  19031. static void
  19032. dwarf2out_end_function (unsigned int)
  19033. {
  19034. if (in_first_function_p
  19035. && !have_multiple_function_sections
  19036. && first_loclabel_num_not_at_text_label
  19037. && decl_loc_table)
  19038. decl_loc_table->traverse<int, find_empty_loc_ranges_at_text_label> (0);
  19039. in_first_function_p = false;
  19040. maybe_at_text_label_p = false;
  19041. }
  19042. /* Temporary holder for dwarf2out_register_main_translation_unit. Used to let
  19043. front-ends register a translation unit even before dwarf2out_init is
  19044. called. */
  19045. static tree main_translation_unit = NULL_TREE;
  19046. /* Hook called by front-ends after they built their main translation unit.
  19047. Associate comp_unit_die to UNIT. */
  19048. static void
  19049. dwarf2out_register_main_translation_unit (tree unit)
  19050. {
  19051. gcc_assert (TREE_CODE (unit) == TRANSLATION_UNIT_DECL
  19052. && main_translation_unit == NULL_TREE);
  19053. main_translation_unit = unit;
  19054. /* If dwarf2out_init has not been called yet, it will perform the association
  19055. itself looking at main_translation_unit. */
  19056. if (decl_die_table != NULL)
  19057. equate_decl_number_to_die (unit, comp_unit_die ());
  19058. }
  19059. /* Add OPCODE+VAL as an entry at the end of the opcode array in TABLE. */
  19060. static void
  19061. push_dw_line_info_entry (dw_line_info_table *table,
  19062. enum dw_line_info_opcode opcode, unsigned int val)
  19063. {
  19064. dw_line_info_entry e;
  19065. e.opcode = opcode;
  19066. e.val = val;
  19067. vec_safe_push (table->entries, e);
  19068. }
  19069. /* Output a label to mark the beginning of a source code line entry
  19070. and record information relating to this source line, in
  19071. 'line_info_table' for later output of the .debug_line section. */
  19072. /* ??? The discriminator parameter ought to be unsigned. */
  19073. static void
  19074. dwarf2out_source_line (unsigned int line, const char *filename,
  19075. int discriminator, bool is_stmt)
  19076. {
  19077. unsigned int file_num;
  19078. dw_line_info_table *table;
  19079. if (debug_info_level < DINFO_LEVEL_TERSE || line == 0)
  19080. return;
  19081. /* The discriminator column was added in dwarf4. Simplify the below
  19082. by simply removing it if we're not supposed to output it. */
  19083. if (dwarf_version < 4 && dwarf_strict)
  19084. discriminator = 0;
  19085. table = cur_line_info_table;
  19086. file_num = maybe_emit_file (lookup_filename (filename));
  19087. /* ??? TODO: Elide duplicate line number entries. Traditionally,
  19088. the debugger has used the second (possibly duplicate) line number
  19089. at the beginning of the function to mark the end of the prologue.
  19090. We could eliminate any other duplicates within the function. For
  19091. Dwarf3, we ought to include the DW_LNS_set_prologue_end mark in
  19092. that second line number entry. */
  19093. /* Recall that this end-of-prologue indication is *not* the same thing
  19094. as the end_prologue debug hook. The NOTE_INSN_PROLOGUE_END note,
  19095. to which the hook corresponds, follows the last insn that was
  19096. emitted by gen_prologue. What we need is to precede the first insn
  19097. that had been emitted after NOTE_INSN_FUNCTION_BEG, i.e. the first
  19098. insn that corresponds to something the user wrote. These may be
  19099. very different locations once scheduling is enabled. */
  19100. if (0 && file_num == table->file_num
  19101. && line == table->line_num
  19102. && discriminator == table->discrim_num
  19103. && is_stmt == table->is_stmt)
  19104. return;
  19105. switch_to_section (current_function_section ());
  19106. /* If requested, emit something human-readable. */
  19107. if (flag_debug_asm)
  19108. fprintf (asm_out_file, "\t%s %s:%d\n", ASM_COMMENT_START, filename, line);
  19109. if (DWARF2_ASM_LINE_DEBUG_INFO)
  19110. {
  19111. /* Emit the .loc directive understood by GNU as. */
  19112. /* "\t.loc %u %u 0 is_stmt %u discriminator %u",
  19113. file_num, line, is_stmt, discriminator */
  19114. fputs ("\t.loc ", asm_out_file);
  19115. fprint_ul (asm_out_file, file_num);
  19116. putc (' ', asm_out_file);
  19117. fprint_ul (asm_out_file, line);
  19118. putc (' ', asm_out_file);
  19119. putc ('0', asm_out_file);
  19120. if (is_stmt != table->is_stmt)
  19121. {
  19122. fputs (" is_stmt ", asm_out_file);
  19123. putc (is_stmt ? '1' : '0', asm_out_file);
  19124. }
  19125. if (SUPPORTS_DISCRIMINATOR && discriminator != 0)
  19126. {
  19127. gcc_assert (discriminator > 0);
  19128. fputs (" discriminator ", asm_out_file);
  19129. fprint_ul (asm_out_file, (unsigned long) discriminator);
  19130. }
  19131. putc ('\n', asm_out_file);
  19132. }
  19133. else
  19134. {
  19135. unsigned int label_num = ++line_info_label_num;
  19136. targetm.asm_out.internal_label (asm_out_file, LINE_CODE_LABEL, label_num);
  19137. push_dw_line_info_entry (table, LI_set_address, label_num);
  19138. if (file_num != table->file_num)
  19139. push_dw_line_info_entry (table, LI_set_file, file_num);
  19140. if (discriminator != table->discrim_num)
  19141. push_dw_line_info_entry (table, LI_set_discriminator, discriminator);
  19142. if (is_stmt != table->is_stmt)
  19143. push_dw_line_info_entry (table, LI_negate_stmt, 0);
  19144. push_dw_line_info_entry (table, LI_set_line, line);
  19145. }
  19146. table->file_num = file_num;
  19147. table->line_num = line;
  19148. table->discrim_num = discriminator;
  19149. table->is_stmt = is_stmt;
  19150. table->in_use = true;
  19151. }
  19152. /* Record the beginning of a new source file. */
  19153. static void
  19154. dwarf2out_start_source_file (unsigned int lineno, const char *filename)
  19155. {
  19156. if (flag_eliminate_dwarf2_dups)
  19157. {
  19158. /* Record the beginning of the file for break_out_includes. */
  19159. dw_die_ref bincl_die;
  19160. bincl_die = new_die (DW_TAG_GNU_BINCL, comp_unit_die (), NULL);
  19161. add_AT_string (bincl_die, DW_AT_name, remap_debug_filename (filename));
  19162. }
  19163. if (debug_info_level >= DINFO_LEVEL_VERBOSE)
  19164. {
  19165. macinfo_entry e;
  19166. e.code = DW_MACINFO_start_file;
  19167. e.lineno = lineno;
  19168. e.info = ggc_strdup (filename);
  19169. vec_safe_push (macinfo_table, e);
  19170. }
  19171. }
  19172. /* Record the end of a source file. */
  19173. static void
  19174. dwarf2out_end_source_file (unsigned int lineno ATTRIBUTE_UNUSED)
  19175. {
  19176. if (flag_eliminate_dwarf2_dups)
  19177. /* Record the end of the file for break_out_includes. */
  19178. new_die (DW_TAG_GNU_EINCL, comp_unit_die (), NULL);
  19179. if (debug_info_level >= DINFO_LEVEL_VERBOSE)
  19180. {
  19181. macinfo_entry e;
  19182. e.code = DW_MACINFO_end_file;
  19183. e.lineno = lineno;
  19184. e.info = NULL;
  19185. vec_safe_push (macinfo_table, e);
  19186. }
  19187. }
  19188. /* Called from debug_define in toplev.c. The `buffer' parameter contains
  19189. the tail part of the directive line, i.e. the part which is past the
  19190. initial whitespace, #, whitespace, directive-name, whitespace part. */
  19191. static void
  19192. dwarf2out_define (unsigned int lineno ATTRIBUTE_UNUSED,
  19193. const char *buffer ATTRIBUTE_UNUSED)
  19194. {
  19195. if (debug_info_level >= DINFO_LEVEL_VERBOSE)
  19196. {
  19197. macinfo_entry e;
  19198. /* Insert a dummy first entry to be able to optimize the whole
  19199. predefined macro block using DW_MACRO_GNU_transparent_include. */
  19200. if (macinfo_table->is_empty () && lineno <= 1)
  19201. {
  19202. e.code = 0;
  19203. e.lineno = 0;
  19204. e.info = NULL;
  19205. vec_safe_push (macinfo_table, e);
  19206. }
  19207. e.code = DW_MACINFO_define;
  19208. e.lineno = lineno;
  19209. e.info = ggc_strdup (buffer);
  19210. vec_safe_push (macinfo_table, e);
  19211. }
  19212. }
  19213. /* Called from debug_undef in toplev.c. The `buffer' parameter contains
  19214. the tail part of the directive line, i.e. the part which is past the
  19215. initial whitespace, #, whitespace, directive-name, whitespace part. */
  19216. static void
  19217. dwarf2out_undef (unsigned int lineno ATTRIBUTE_UNUSED,
  19218. const char *buffer ATTRIBUTE_UNUSED)
  19219. {
  19220. if (debug_info_level >= DINFO_LEVEL_VERBOSE)
  19221. {
  19222. macinfo_entry e;
  19223. /* Insert a dummy first entry to be able to optimize the whole
  19224. predefined macro block using DW_MACRO_GNU_transparent_include. */
  19225. if (macinfo_table->is_empty () && lineno <= 1)
  19226. {
  19227. e.code = 0;
  19228. e.lineno = 0;
  19229. e.info = NULL;
  19230. vec_safe_push (macinfo_table, e);
  19231. }
  19232. e.code = DW_MACINFO_undef;
  19233. e.lineno = lineno;
  19234. e.info = ggc_strdup (buffer);
  19235. vec_safe_push (macinfo_table, e);
  19236. }
  19237. }
  19238. /* Helpers to manipulate hash table of CUs. */
  19239. struct macinfo_entry_hasher : typed_noop_remove <macinfo_entry>
  19240. {
  19241. typedef macinfo_entry value_type;
  19242. typedef macinfo_entry compare_type;
  19243. static inline hashval_t hash (const value_type *);
  19244. static inline bool equal (const value_type *, const compare_type *);
  19245. };
  19246. inline hashval_t
  19247. macinfo_entry_hasher::hash (const value_type *entry)
  19248. {
  19249. return htab_hash_string (entry->info);
  19250. }
  19251. inline bool
  19252. macinfo_entry_hasher::equal (const value_type *entry1,
  19253. const compare_type *entry2)
  19254. {
  19255. return !strcmp (entry1->info, entry2->info);
  19256. }
  19257. typedef hash_table<macinfo_entry_hasher> macinfo_hash_type;
  19258. /* Output a single .debug_macinfo entry. */
  19259. static void
  19260. output_macinfo_op (macinfo_entry *ref)
  19261. {
  19262. int file_num;
  19263. size_t len;
  19264. struct indirect_string_node *node;
  19265. char label[MAX_ARTIFICIAL_LABEL_BYTES];
  19266. struct dwarf_file_data *fd;
  19267. switch (ref->code)
  19268. {
  19269. case DW_MACINFO_start_file:
  19270. fd = lookup_filename (ref->info);
  19271. file_num = maybe_emit_file (fd);
  19272. dw2_asm_output_data (1, DW_MACINFO_start_file, "Start new file");
  19273. dw2_asm_output_data_uleb128 (ref->lineno,
  19274. "Included from line number %lu",
  19275. (unsigned long) ref->lineno);
  19276. dw2_asm_output_data_uleb128 (file_num, "file %s", ref->info);
  19277. break;
  19278. case DW_MACINFO_end_file:
  19279. dw2_asm_output_data (1, DW_MACINFO_end_file, "End file");
  19280. break;
  19281. case DW_MACINFO_define:
  19282. case DW_MACINFO_undef:
  19283. len = strlen (ref->info) + 1;
  19284. if (!dwarf_strict
  19285. && len > DWARF_OFFSET_SIZE
  19286. && !DWARF2_INDIRECT_STRING_SUPPORT_MISSING_ON_TARGET
  19287. && (debug_str_section->common.flags & SECTION_MERGE) != 0)
  19288. {
  19289. ref->code = ref->code == DW_MACINFO_define
  19290. ? DW_MACRO_GNU_define_indirect
  19291. : DW_MACRO_GNU_undef_indirect;
  19292. output_macinfo_op (ref);
  19293. return;
  19294. }
  19295. dw2_asm_output_data (1, ref->code,
  19296. ref->code == DW_MACINFO_define
  19297. ? "Define macro" : "Undefine macro");
  19298. dw2_asm_output_data_uleb128 (ref->lineno, "At line number %lu",
  19299. (unsigned long) ref->lineno);
  19300. dw2_asm_output_nstring (ref->info, -1, "The macro");
  19301. break;
  19302. case DW_MACRO_GNU_define_indirect:
  19303. case DW_MACRO_GNU_undef_indirect:
  19304. node = find_AT_string (ref->info);
  19305. gcc_assert (node
  19306. && ((node->form == DW_FORM_strp)
  19307. || (node->form == DW_FORM_GNU_str_index)));
  19308. dw2_asm_output_data (1, ref->code,
  19309. ref->code == DW_MACRO_GNU_define_indirect
  19310. ? "Define macro indirect"
  19311. : "Undefine macro indirect");
  19312. dw2_asm_output_data_uleb128 (ref->lineno, "At line number %lu",
  19313. (unsigned long) ref->lineno);
  19314. if (node->form == DW_FORM_strp)
  19315. dw2_asm_output_offset (DWARF_OFFSET_SIZE, node->label,
  19316. debug_str_section, "The macro: \"%s\"",
  19317. ref->info);
  19318. else
  19319. dw2_asm_output_data_uleb128 (node->index, "The macro: \"%s\"",
  19320. ref->info);
  19321. break;
  19322. case DW_MACRO_GNU_transparent_include:
  19323. dw2_asm_output_data (1, ref->code, "Transparent include");
  19324. ASM_GENERATE_INTERNAL_LABEL (label,
  19325. DEBUG_MACRO_SECTION_LABEL, ref->lineno);
  19326. dw2_asm_output_offset (DWARF_OFFSET_SIZE, label, NULL, NULL);
  19327. break;
  19328. default:
  19329. fprintf (asm_out_file, "%s unrecognized macinfo code %lu\n",
  19330. ASM_COMMENT_START, (unsigned long) ref->code);
  19331. break;
  19332. }
  19333. }
  19334. /* Attempt to make a sequence of define/undef macinfo ops shareable with
  19335. other compilation unit .debug_macinfo sections. IDX is the first
  19336. index of a define/undef, return the number of ops that should be
  19337. emitted in a comdat .debug_macinfo section and emit
  19338. a DW_MACRO_GNU_transparent_include entry referencing it.
  19339. If the define/undef entry should be emitted normally, return 0. */
  19340. static unsigned
  19341. optimize_macinfo_range (unsigned int idx, vec<macinfo_entry, va_gc> *files,
  19342. macinfo_hash_type **macinfo_htab)
  19343. {
  19344. macinfo_entry *first, *second, *cur, *inc;
  19345. char linebuf[sizeof (HOST_WIDE_INT) * 3 + 1];
  19346. unsigned char checksum[16];
  19347. struct md5_ctx ctx;
  19348. char *grp_name, *tail;
  19349. const char *base;
  19350. unsigned int i, count, encoded_filename_len, linebuf_len;
  19351. macinfo_entry **slot;
  19352. first = &(*macinfo_table)[idx];
  19353. second = &(*macinfo_table)[idx + 1];
  19354. /* Optimize only if there are at least two consecutive define/undef ops,
  19355. and either all of them are before first DW_MACINFO_start_file
  19356. with lineno {0,1} (i.e. predefined macro block), or all of them are
  19357. in some included header file. */
  19358. if (second->code != DW_MACINFO_define && second->code != DW_MACINFO_undef)
  19359. return 0;
  19360. if (vec_safe_is_empty (files))
  19361. {
  19362. if (first->lineno > 1 || second->lineno > 1)
  19363. return 0;
  19364. }
  19365. else if (first->lineno == 0)
  19366. return 0;
  19367. /* Find the last define/undef entry that can be grouped together
  19368. with first and at the same time compute md5 checksum of their
  19369. codes, linenumbers and strings. */
  19370. md5_init_ctx (&ctx);
  19371. for (i = idx; macinfo_table->iterate (i, &cur); i++)
  19372. if (cur->code != DW_MACINFO_define && cur->code != DW_MACINFO_undef)
  19373. break;
  19374. else if (vec_safe_is_empty (files) && cur->lineno > 1)
  19375. break;
  19376. else
  19377. {
  19378. unsigned char code = cur->code;
  19379. md5_process_bytes (&code, 1, &ctx);
  19380. checksum_uleb128 (cur->lineno, &ctx);
  19381. md5_process_bytes (cur->info, strlen (cur->info) + 1, &ctx);
  19382. }
  19383. md5_finish_ctx (&ctx, checksum);
  19384. count = i - idx;
  19385. /* From the containing include filename (if any) pick up just
  19386. usable characters from its basename. */
  19387. if (vec_safe_is_empty (files))
  19388. base = "";
  19389. else
  19390. base = lbasename (files->last ().info);
  19391. for (encoded_filename_len = 0, i = 0; base[i]; i++)
  19392. if (ISIDNUM (base[i]) || base[i] == '.')
  19393. encoded_filename_len++;
  19394. /* Count . at the end. */
  19395. if (encoded_filename_len)
  19396. encoded_filename_len++;
  19397. sprintf (linebuf, HOST_WIDE_INT_PRINT_UNSIGNED, first->lineno);
  19398. linebuf_len = strlen (linebuf);
  19399. /* The group name format is: wmN.[<encoded filename>.]<lineno>.<md5sum> */
  19400. grp_name = XALLOCAVEC (char, 4 + encoded_filename_len + linebuf_len + 1
  19401. + 16 * 2 + 1);
  19402. memcpy (grp_name, DWARF_OFFSET_SIZE == 4 ? "wm4." : "wm8.", 4);
  19403. tail = grp_name + 4;
  19404. if (encoded_filename_len)
  19405. {
  19406. for (i = 0; base[i]; i++)
  19407. if (ISIDNUM (base[i]) || base[i] == '.')
  19408. *tail++ = base[i];
  19409. *tail++ = '.';
  19410. }
  19411. memcpy (tail, linebuf, linebuf_len);
  19412. tail += linebuf_len;
  19413. *tail++ = '.';
  19414. for (i = 0; i < 16; i++)
  19415. sprintf (tail + i * 2, "%02x", checksum[i] & 0xff);
  19416. /* Construct a macinfo_entry for DW_MACRO_GNU_transparent_include
  19417. in the empty vector entry before the first define/undef. */
  19418. inc = &(*macinfo_table)[idx - 1];
  19419. inc->code = DW_MACRO_GNU_transparent_include;
  19420. inc->lineno = 0;
  19421. inc->info = ggc_strdup (grp_name);
  19422. if (!*macinfo_htab)
  19423. *macinfo_htab = new macinfo_hash_type (10);
  19424. /* Avoid emitting duplicates. */
  19425. slot = (*macinfo_htab)->find_slot (inc, INSERT);
  19426. if (*slot != NULL)
  19427. {
  19428. inc->code = 0;
  19429. inc->info = NULL;
  19430. /* If such an entry has been used before, just emit
  19431. a DW_MACRO_GNU_transparent_include op. */
  19432. inc = *slot;
  19433. output_macinfo_op (inc);
  19434. /* And clear all macinfo_entry in the range to avoid emitting them
  19435. in the second pass. */
  19436. for (i = idx; macinfo_table->iterate (i, &cur) && i < idx + count; i++)
  19437. {
  19438. cur->code = 0;
  19439. cur->info = NULL;
  19440. }
  19441. }
  19442. else
  19443. {
  19444. *slot = inc;
  19445. inc->lineno = (*macinfo_htab)->elements ();
  19446. output_macinfo_op (inc);
  19447. }
  19448. return count;
  19449. }
  19450. /* Save any strings needed by the macinfo table in the debug str
  19451. table. All strings must be collected into the table by the time
  19452. index_string is called. */
  19453. static void
  19454. save_macinfo_strings (void)
  19455. {
  19456. unsigned len;
  19457. unsigned i;
  19458. macinfo_entry *ref;
  19459. for (i = 0; macinfo_table && macinfo_table->iterate (i, &ref); i++)
  19460. {
  19461. switch (ref->code)
  19462. {
  19463. /* Match the logic in output_macinfo_op to decide on
  19464. indirect strings. */
  19465. case DW_MACINFO_define:
  19466. case DW_MACINFO_undef:
  19467. len = strlen (ref->info) + 1;
  19468. if (!dwarf_strict
  19469. && len > DWARF_OFFSET_SIZE
  19470. && !DWARF2_INDIRECT_STRING_SUPPORT_MISSING_ON_TARGET
  19471. && (debug_str_section->common.flags & SECTION_MERGE) != 0)
  19472. set_indirect_string (find_AT_string (ref->info));
  19473. break;
  19474. case DW_MACRO_GNU_define_indirect:
  19475. case DW_MACRO_GNU_undef_indirect:
  19476. set_indirect_string (find_AT_string (ref->info));
  19477. break;
  19478. default:
  19479. break;
  19480. }
  19481. }
  19482. }
  19483. /* Output macinfo section(s). */
  19484. static void
  19485. output_macinfo (void)
  19486. {
  19487. unsigned i;
  19488. unsigned long length = vec_safe_length (macinfo_table);
  19489. macinfo_entry *ref;
  19490. vec<macinfo_entry, va_gc> *files = NULL;
  19491. macinfo_hash_type *macinfo_htab = NULL;
  19492. if (! length)
  19493. return;
  19494. /* output_macinfo* uses these interchangeably. */
  19495. gcc_assert ((int) DW_MACINFO_define == (int) DW_MACRO_GNU_define
  19496. && (int) DW_MACINFO_undef == (int) DW_MACRO_GNU_undef
  19497. && (int) DW_MACINFO_start_file == (int) DW_MACRO_GNU_start_file
  19498. && (int) DW_MACINFO_end_file == (int) DW_MACRO_GNU_end_file);
  19499. /* For .debug_macro emit the section header. */
  19500. if (!dwarf_strict)
  19501. {
  19502. dw2_asm_output_data (2, 4, "DWARF macro version number");
  19503. if (DWARF_OFFSET_SIZE == 8)
  19504. dw2_asm_output_data (1, 3, "Flags: 64-bit, lineptr present");
  19505. else
  19506. dw2_asm_output_data (1, 2, "Flags: 32-bit, lineptr present");
  19507. dw2_asm_output_offset (DWARF_OFFSET_SIZE,
  19508. (!dwarf_split_debug_info ? debug_line_section_label
  19509. : debug_skeleton_line_section_label),
  19510. debug_line_section, NULL);
  19511. }
  19512. /* In the first loop, it emits the primary .debug_macinfo section
  19513. and after each emitted op the macinfo_entry is cleared.
  19514. If a longer range of define/undef ops can be optimized using
  19515. DW_MACRO_GNU_transparent_include, the
  19516. DW_MACRO_GNU_transparent_include op is emitted and kept in
  19517. the vector before the first define/undef in the range and the
  19518. whole range of define/undef ops is not emitted and kept. */
  19519. for (i = 0; macinfo_table->iterate (i, &ref); i++)
  19520. {
  19521. switch (ref->code)
  19522. {
  19523. case DW_MACINFO_start_file:
  19524. vec_safe_push (files, *ref);
  19525. break;
  19526. case DW_MACINFO_end_file:
  19527. if (!vec_safe_is_empty (files))
  19528. files->pop ();
  19529. break;
  19530. case DW_MACINFO_define:
  19531. case DW_MACINFO_undef:
  19532. if (!dwarf_strict
  19533. && HAVE_COMDAT_GROUP
  19534. && vec_safe_length (files) != 1
  19535. && i > 0
  19536. && i + 1 < length
  19537. && (*macinfo_table)[i - 1].code == 0)
  19538. {
  19539. unsigned count = optimize_macinfo_range (i, files, &macinfo_htab);
  19540. if (count)
  19541. {
  19542. i += count - 1;
  19543. continue;
  19544. }
  19545. }
  19546. break;
  19547. case 0:
  19548. /* A dummy entry may be inserted at the beginning to be able
  19549. to optimize the whole block of predefined macros. */
  19550. if (i == 0)
  19551. continue;
  19552. default:
  19553. break;
  19554. }
  19555. output_macinfo_op (ref);
  19556. ref->info = NULL;
  19557. ref->code = 0;
  19558. }
  19559. if (!macinfo_htab)
  19560. return;
  19561. delete macinfo_htab;
  19562. macinfo_htab = NULL;
  19563. /* If any DW_MACRO_GNU_transparent_include were used, on those
  19564. DW_MACRO_GNU_transparent_include entries terminate the
  19565. current chain and switch to a new comdat .debug_macinfo
  19566. section and emit the define/undef entries within it. */
  19567. for (i = 0; macinfo_table->iterate (i, &ref); i++)
  19568. switch (ref->code)
  19569. {
  19570. case 0:
  19571. continue;
  19572. case DW_MACRO_GNU_transparent_include:
  19573. {
  19574. char label[MAX_ARTIFICIAL_LABEL_BYTES];
  19575. tree comdat_key = get_identifier (ref->info);
  19576. /* Terminate the previous .debug_macinfo section. */
  19577. dw2_asm_output_data (1, 0, "End compilation unit");
  19578. targetm.asm_out.named_section (DEBUG_MACRO_SECTION,
  19579. SECTION_DEBUG
  19580. | SECTION_LINKONCE,
  19581. comdat_key);
  19582. ASM_GENERATE_INTERNAL_LABEL (label,
  19583. DEBUG_MACRO_SECTION_LABEL,
  19584. ref->lineno);
  19585. ASM_OUTPUT_LABEL (asm_out_file, label);
  19586. ref->code = 0;
  19587. ref->info = NULL;
  19588. dw2_asm_output_data (2, 4, "DWARF macro version number");
  19589. if (DWARF_OFFSET_SIZE == 8)
  19590. dw2_asm_output_data (1, 1, "Flags: 64-bit");
  19591. else
  19592. dw2_asm_output_data (1, 0, "Flags: 32-bit");
  19593. }
  19594. break;
  19595. case DW_MACINFO_define:
  19596. case DW_MACINFO_undef:
  19597. output_macinfo_op (ref);
  19598. ref->code = 0;
  19599. ref->info = NULL;
  19600. break;
  19601. default:
  19602. gcc_unreachable ();
  19603. }
  19604. }
  19605. /* Set up for Dwarf output at the start of compilation. */
  19606. static void
  19607. dwarf2out_init (const char *filename ATTRIBUTE_UNUSED)
  19608. {
  19609. /* This option is currently broken, see (PR53118 and PR46102). */
  19610. if (flag_eliminate_dwarf2_dups
  19611. && strstr (lang_hooks.name, "C++"))
  19612. {
  19613. warning (0, "-feliminate-dwarf2-dups is broken for C++, ignoring");
  19614. flag_eliminate_dwarf2_dups = 0;
  19615. }
  19616. /* Allocate the file_table. */
  19617. file_table = hash_table<dwarf_file_hasher>::create_ggc (50);
  19618. /* Allocate the decl_die_table. */
  19619. decl_die_table = hash_table<decl_die_hasher>::create_ggc (10);
  19620. /* Allocate the decl_loc_table. */
  19621. decl_loc_table = hash_table<decl_loc_hasher>::create_ggc (10);
  19622. /* Allocate the cached_dw_loc_list_table. */
  19623. cached_dw_loc_list_table = hash_table<dw_loc_list_hasher>::create_ggc (10);
  19624. /* Allocate the initial hunk of the decl_scope_table. */
  19625. vec_alloc (decl_scope_table, 256);
  19626. /* Allocate the initial hunk of the abbrev_die_table. */
  19627. abbrev_die_table = ggc_cleared_vec_alloc<dw_die_ref>
  19628. (ABBREV_DIE_TABLE_INCREMENT);
  19629. abbrev_die_table_allocated = ABBREV_DIE_TABLE_INCREMENT;
  19630. /* Zero-th entry is allocated, but unused. */
  19631. abbrev_die_table_in_use = 1;
  19632. /* Allocate the pubtypes and pubnames vectors. */
  19633. vec_alloc (pubname_table, 32);
  19634. vec_alloc (pubtype_table, 32);
  19635. vec_alloc (incomplete_types, 64);
  19636. vec_alloc (used_rtx_array, 32);
  19637. if (!dwarf_split_debug_info)
  19638. {
  19639. debug_info_section = get_section (DEBUG_INFO_SECTION,
  19640. SECTION_DEBUG, NULL);
  19641. debug_abbrev_section = get_section (DEBUG_ABBREV_SECTION,
  19642. SECTION_DEBUG, NULL);
  19643. debug_loc_section = get_section (DEBUG_LOC_SECTION,
  19644. SECTION_DEBUG, NULL);
  19645. }
  19646. else
  19647. {
  19648. debug_info_section = get_section (DEBUG_DWO_INFO_SECTION,
  19649. SECTION_DEBUG | SECTION_EXCLUDE, NULL);
  19650. debug_abbrev_section = get_section (DEBUG_DWO_ABBREV_SECTION,
  19651. SECTION_DEBUG | SECTION_EXCLUDE,
  19652. NULL);
  19653. debug_addr_section = get_section (DEBUG_ADDR_SECTION,
  19654. SECTION_DEBUG, NULL);
  19655. debug_skeleton_info_section = get_section (DEBUG_INFO_SECTION,
  19656. SECTION_DEBUG, NULL);
  19657. debug_skeleton_abbrev_section = get_section (DEBUG_ABBREV_SECTION,
  19658. SECTION_DEBUG, NULL);
  19659. ASM_GENERATE_INTERNAL_LABEL (debug_skeleton_abbrev_section_label,
  19660. DEBUG_SKELETON_ABBREV_SECTION_LABEL, 0);
  19661. /* Somewhat confusing detail: The skeleton_[abbrev|info] sections stay in
  19662. the main .o, but the skeleton_line goes into the split off dwo. */
  19663. debug_skeleton_line_section
  19664. = get_section (DEBUG_DWO_LINE_SECTION,
  19665. SECTION_DEBUG | SECTION_EXCLUDE, NULL);
  19666. ASM_GENERATE_INTERNAL_LABEL (debug_skeleton_line_section_label,
  19667. DEBUG_SKELETON_LINE_SECTION_LABEL, 0);
  19668. debug_str_offsets_section = get_section (DEBUG_STR_OFFSETS_SECTION,
  19669. SECTION_DEBUG | SECTION_EXCLUDE,
  19670. NULL);
  19671. ASM_GENERATE_INTERNAL_LABEL (debug_skeleton_info_section_label,
  19672. DEBUG_SKELETON_INFO_SECTION_LABEL, 0);
  19673. debug_loc_section = get_section (DEBUG_DWO_LOC_SECTION,
  19674. SECTION_DEBUG | SECTION_EXCLUDE, NULL);
  19675. debug_str_dwo_section = get_section (DEBUG_STR_DWO_SECTION,
  19676. DEBUG_STR_DWO_SECTION_FLAGS, NULL);
  19677. }
  19678. debug_aranges_section = get_section (DEBUG_ARANGES_SECTION,
  19679. SECTION_DEBUG, NULL);
  19680. debug_macinfo_section = get_section (dwarf_strict
  19681. ? DEBUG_MACINFO_SECTION
  19682. : DEBUG_MACRO_SECTION,
  19683. DEBUG_MACRO_SECTION_FLAGS, NULL);
  19684. debug_line_section = get_section (DEBUG_LINE_SECTION,
  19685. SECTION_DEBUG, NULL);
  19686. debug_pubnames_section = get_section (DEBUG_PUBNAMES_SECTION,
  19687. SECTION_DEBUG, NULL);
  19688. debug_pubtypes_section = get_section (DEBUG_PUBTYPES_SECTION,
  19689. SECTION_DEBUG, NULL);
  19690. debug_str_section = get_section (DEBUG_STR_SECTION,
  19691. DEBUG_STR_SECTION_FLAGS, NULL);
  19692. debug_ranges_section = get_section (DEBUG_RANGES_SECTION,
  19693. SECTION_DEBUG, NULL);
  19694. debug_frame_section = get_section (DEBUG_FRAME_SECTION,
  19695. SECTION_DEBUG, NULL);
  19696. ASM_GENERATE_INTERNAL_LABEL (text_end_label, TEXT_END_LABEL, 0);
  19697. ASM_GENERATE_INTERNAL_LABEL (abbrev_section_label,
  19698. DEBUG_ABBREV_SECTION_LABEL, 0);
  19699. ASM_GENERATE_INTERNAL_LABEL (text_section_label, TEXT_SECTION_LABEL, 0);
  19700. ASM_GENERATE_INTERNAL_LABEL (cold_text_section_label,
  19701. COLD_TEXT_SECTION_LABEL, 0);
  19702. ASM_GENERATE_INTERNAL_LABEL (cold_end_label, COLD_END_LABEL, 0);
  19703. ASM_GENERATE_INTERNAL_LABEL (debug_info_section_label,
  19704. DEBUG_INFO_SECTION_LABEL, 0);
  19705. ASM_GENERATE_INTERNAL_LABEL (debug_line_section_label,
  19706. DEBUG_LINE_SECTION_LABEL, 0);
  19707. ASM_GENERATE_INTERNAL_LABEL (ranges_section_label,
  19708. DEBUG_RANGES_SECTION_LABEL, 0);
  19709. ASM_GENERATE_INTERNAL_LABEL (debug_addr_section_label,
  19710. DEBUG_ADDR_SECTION_LABEL, 0);
  19711. ASM_GENERATE_INTERNAL_LABEL (macinfo_section_label,
  19712. dwarf_strict
  19713. ? DEBUG_MACINFO_SECTION_LABEL
  19714. : DEBUG_MACRO_SECTION_LABEL, 0);
  19715. ASM_GENERATE_INTERNAL_LABEL (loc_section_label, DEBUG_LOC_SECTION_LABEL, 0);
  19716. if (debug_info_level >= DINFO_LEVEL_VERBOSE)
  19717. vec_alloc (macinfo_table, 64);
  19718. switch_to_section (text_section);
  19719. ASM_OUTPUT_LABEL (asm_out_file, text_section_label);
  19720. /* Make sure the line number table for .text always exists. */
  19721. text_section_line_info = new_line_info_table ();
  19722. text_section_line_info->end_label = text_end_label;
  19723. /* If front-ends already registered a main translation unit but we were not
  19724. ready to perform the association, do this now. */
  19725. if (main_translation_unit != NULL_TREE)
  19726. equate_decl_number_to_die (main_translation_unit, comp_unit_die ());
  19727. }
  19728. /* Called before compile () starts outputtting functions, variables
  19729. and toplevel asms into assembly. */
  19730. static void
  19731. dwarf2out_assembly_start (void)
  19732. {
  19733. if (HAVE_GAS_CFI_SECTIONS_DIRECTIVE
  19734. && dwarf2out_do_cfi_asm ()
  19735. && (!(flag_unwind_tables || flag_exceptions)
  19736. || targetm_common.except_unwind_info (&global_options) != UI_DWARF2))
  19737. fprintf (asm_out_file, "\t.cfi_sections\t.debug_frame\n");
  19738. }
  19739. /* A helper function for dwarf2out_finish called through
  19740. htab_traverse. Assign a string its index. All strings must be
  19741. collected into the table by the time index_string is called,
  19742. because the indexing code relies on htab_traverse to traverse nodes
  19743. in the same order for each run. */
  19744. int
  19745. index_string (indirect_string_node **h, unsigned int *index)
  19746. {
  19747. indirect_string_node *node = *h;
  19748. find_string_form (node);
  19749. if (node->form == DW_FORM_GNU_str_index && node->refcount > 0)
  19750. {
  19751. gcc_assert (node->index == NO_INDEX_ASSIGNED);
  19752. node->index = *index;
  19753. *index += 1;
  19754. }
  19755. return 1;
  19756. }
  19757. /* A helper function for output_indirect_strings called through
  19758. htab_traverse. Output the offset to a string and update the
  19759. current offset. */
  19760. int
  19761. output_index_string_offset (indirect_string_node **h, unsigned int *offset)
  19762. {
  19763. indirect_string_node *node = *h;
  19764. if (node->form == DW_FORM_GNU_str_index && node->refcount > 0)
  19765. {
  19766. /* Assert that this node has been assigned an index. */
  19767. gcc_assert (node->index != NO_INDEX_ASSIGNED
  19768. && node->index != NOT_INDEXED);
  19769. dw2_asm_output_data (DWARF_OFFSET_SIZE, *offset,
  19770. "indexed string 0x%x: %s", node->index, node->str);
  19771. *offset += strlen (node->str) + 1;
  19772. }
  19773. return 1;
  19774. }
  19775. /* A helper function for dwarf2out_finish called through
  19776. htab_traverse. Output the indexed string. */
  19777. int
  19778. output_index_string (indirect_string_node **h, unsigned int *cur_idx)
  19779. {
  19780. struct indirect_string_node *node = *h;
  19781. if (node->form == DW_FORM_GNU_str_index && node->refcount > 0)
  19782. {
  19783. /* Assert that the strings are output in the same order as their
  19784. indexes were assigned. */
  19785. gcc_assert (*cur_idx == node->index);
  19786. assemble_string (node->str, strlen (node->str) + 1);
  19787. *cur_idx += 1;
  19788. }
  19789. return 1;
  19790. }
  19791. /* A helper function for dwarf2out_finish called through
  19792. htab_traverse. Emit one queued .debug_str string. */
  19793. int
  19794. output_indirect_string (indirect_string_node **h, void *)
  19795. {
  19796. struct indirect_string_node *node = *h;
  19797. node->form = find_string_form (node);
  19798. if (node->form == DW_FORM_strp && node->refcount > 0)
  19799. {
  19800. ASM_OUTPUT_LABEL (asm_out_file, node->label);
  19801. assemble_string (node->str, strlen (node->str) + 1);
  19802. }
  19803. return 1;
  19804. }
  19805. /* Output the indexed string table. */
  19806. static void
  19807. output_indirect_strings (void)
  19808. {
  19809. switch_to_section (debug_str_section);
  19810. if (!dwarf_split_debug_info)
  19811. debug_str_hash->traverse<void *, output_indirect_string> (NULL);
  19812. else
  19813. {
  19814. unsigned int offset = 0;
  19815. unsigned int cur_idx = 0;
  19816. skeleton_debug_str_hash->traverse<void *, output_indirect_string> (NULL);
  19817. switch_to_section (debug_str_offsets_section);
  19818. debug_str_hash->traverse_noresize
  19819. <unsigned int *, output_index_string_offset> (&offset);
  19820. switch_to_section (debug_str_dwo_section);
  19821. debug_str_hash->traverse_noresize<unsigned int *, output_index_string>
  19822. (&cur_idx);
  19823. }
  19824. }
  19825. /* Callback for htab_traverse to assign an index to an entry in the
  19826. table, and to write that entry to the .debug_addr section. */
  19827. int
  19828. output_addr_table_entry (addr_table_entry **slot, unsigned int *cur_index)
  19829. {
  19830. addr_table_entry *entry = *slot;
  19831. if (entry->refcount == 0)
  19832. {
  19833. gcc_assert (entry->index == NO_INDEX_ASSIGNED
  19834. || entry->index == NOT_INDEXED);
  19835. return 1;
  19836. }
  19837. gcc_assert (entry->index == *cur_index);
  19838. (*cur_index)++;
  19839. switch (entry->kind)
  19840. {
  19841. case ate_kind_rtx:
  19842. dw2_asm_output_addr_rtx (DWARF2_ADDR_SIZE, entry->addr.rtl,
  19843. "0x%x", entry->index);
  19844. break;
  19845. case ate_kind_rtx_dtprel:
  19846. gcc_assert (targetm.asm_out.output_dwarf_dtprel);
  19847. targetm.asm_out.output_dwarf_dtprel (asm_out_file,
  19848. DWARF2_ADDR_SIZE,
  19849. entry->addr.rtl);
  19850. fputc ('\n', asm_out_file);
  19851. break;
  19852. case ate_kind_label:
  19853. dw2_asm_output_addr (DWARF2_ADDR_SIZE, entry->addr.label,
  19854. "0x%x", entry->index);
  19855. break;
  19856. default:
  19857. gcc_unreachable ();
  19858. }
  19859. return 1;
  19860. }
  19861. /* Produce the .debug_addr section. */
  19862. static void
  19863. output_addr_table (void)
  19864. {
  19865. unsigned int index = 0;
  19866. if (addr_index_table == NULL || addr_index_table->size () == 0)
  19867. return;
  19868. switch_to_section (debug_addr_section);
  19869. addr_index_table
  19870. ->traverse_noresize<unsigned int *, output_addr_table_entry> (&index);
  19871. }
  19872. #if ENABLE_ASSERT_CHECKING
  19873. /* Verify that all marks are clear. */
  19874. static void
  19875. verify_marks_clear (dw_die_ref die)
  19876. {
  19877. dw_die_ref c;
  19878. gcc_assert (! die->die_mark);
  19879. FOR_EACH_CHILD (die, c, verify_marks_clear (c));
  19880. }
  19881. #endif /* ENABLE_ASSERT_CHECKING */
  19882. /* Clear the marks for a die and its children.
  19883. Be cool if the mark isn't set. */
  19884. static void
  19885. prune_unmark_dies (dw_die_ref die)
  19886. {
  19887. dw_die_ref c;
  19888. if (die->die_mark)
  19889. die->die_mark = 0;
  19890. FOR_EACH_CHILD (die, c, prune_unmark_dies (c));
  19891. }
  19892. /* Given DIE that we're marking as used, find any other dies
  19893. it references as attributes and mark them as used. */
  19894. static void
  19895. prune_unused_types_walk_attribs (dw_die_ref die)
  19896. {
  19897. dw_attr_ref a;
  19898. unsigned ix;
  19899. FOR_EACH_VEC_SAFE_ELT (die->die_attr, ix, a)
  19900. {
  19901. if (a->dw_attr_val.val_class == dw_val_class_die_ref)
  19902. {
  19903. /* A reference to another DIE.
  19904. Make sure that it will get emitted.
  19905. If it was broken out into a comdat group, don't follow it. */
  19906. if (! AT_ref (a)->comdat_type_p
  19907. || a->dw_attr == DW_AT_specification)
  19908. prune_unused_types_mark (a->dw_attr_val.v.val_die_ref.die, 1);
  19909. }
  19910. /* Set the string's refcount to 0 so that prune_unused_types_mark
  19911. accounts properly for it. */
  19912. if (AT_class (a) == dw_val_class_str)
  19913. a->dw_attr_val.v.val_str->refcount = 0;
  19914. }
  19915. }
  19916. /* Mark the generic parameters and arguments children DIEs of DIE. */
  19917. static void
  19918. prune_unused_types_mark_generic_parms_dies (dw_die_ref die)
  19919. {
  19920. dw_die_ref c;
  19921. if (die == NULL || die->die_child == NULL)
  19922. return;
  19923. c = die->die_child;
  19924. do
  19925. {
  19926. if (is_template_parameter (c))
  19927. prune_unused_types_mark (c, 1);
  19928. c = c->die_sib;
  19929. } while (c && c != die->die_child);
  19930. }
  19931. /* Mark DIE as being used. If DOKIDS is true, then walk down
  19932. to DIE's children. */
  19933. static void
  19934. prune_unused_types_mark (dw_die_ref die, int dokids)
  19935. {
  19936. dw_die_ref c;
  19937. if (die->die_mark == 0)
  19938. {
  19939. /* We haven't done this node yet. Mark it as used. */
  19940. die->die_mark = 1;
  19941. /* If this is the DIE of a generic type instantiation,
  19942. mark the children DIEs that describe its generic parms and
  19943. args. */
  19944. prune_unused_types_mark_generic_parms_dies (die);
  19945. /* We also have to mark its parents as used.
  19946. (But we don't want to mark our parent's kids due to this,
  19947. unless it is a class.) */
  19948. if (die->die_parent)
  19949. prune_unused_types_mark (die->die_parent,
  19950. class_scope_p (die->die_parent));
  19951. /* Mark any referenced nodes. */
  19952. prune_unused_types_walk_attribs (die);
  19953. /* If this node is a specification,
  19954. also mark the definition, if it exists. */
  19955. if (get_AT_flag (die, DW_AT_declaration) && die->die_definition)
  19956. prune_unused_types_mark (die->die_definition, 1);
  19957. }
  19958. if (dokids && die->die_mark != 2)
  19959. {
  19960. /* We need to walk the children, but haven't done so yet.
  19961. Remember that we've walked the kids. */
  19962. die->die_mark = 2;
  19963. /* If this is an array type, we need to make sure our
  19964. kids get marked, even if they're types. If we're
  19965. breaking out types into comdat sections, do this
  19966. for all type definitions. */
  19967. if (die->die_tag == DW_TAG_array_type
  19968. || (use_debug_types
  19969. && is_type_die (die) && ! is_declaration_die (die)))
  19970. FOR_EACH_CHILD (die, c, prune_unused_types_mark (c, 1));
  19971. else
  19972. FOR_EACH_CHILD (die, c, prune_unused_types_walk (c));
  19973. }
  19974. }
  19975. /* For local classes, look if any static member functions were emitted
  19976. and if so, mark them. */
  19977. static void
  19978. prune_unused_types_walk_local_classes (dw_die_ref die)
  19979. {
  19980. dw_die_ref c;
  19981. if (die->die_mark == 2)
  19982. return;
  19983. switch (die->die_tag)
  19984. {
  19985. case DW_TAG_structure_type:
  19986. case DW_TAG_union_type:
  19987. case DW_TAG_class_type:
  19988. break;
  19989. case DW_TAG_subprogram:
  19990. if (!get_AT_flag (die, DW_AT_declaration)
  19991. || die->die_definition != NULL)
  19992. prune_unused_types_mark (die, 1);
  19993. return;
  19994. default:
  19995. return;
  19996. }
  19997. /* Mark children. */
  19998. FOR_EACH_CHILD (die, c, prune_unused_types_walk_local_classes (c));
  19999. }
  20000. /* Walk the tree DIE and mark types that we actually use. */
  20001. static void
  20002. prune_unused_types_walk (dw_die_ref die)
  20003. {
  20004. dw_die_ref c;
  20005. /* Don't do anything if this node is already marked and
  20006. children have been marked as well. */
  20007. if (die->die_mark == 2)
  20008. return;
  20009. switch (die->die_tag)
  20010. {
  20011. case DW_TAG_structure_type:
  20012. case DW_TAG_union_type:
  20013. case DW_TAG_class_type:
  20014. if (die->die_perennial_p)
  20015. break;
  20016. for (c = die->die_parent; c; c = c->die_parent)
  20017. if (c->die_tag == DW_TAG_subprogram)
  20018. break;
  20019. /* Finding used static member functions inside of classes
  20020. is needed just for local classes, because for other classes
  20021. static member function DIEs with DW_AT_specification
  20022. are emitted outside of the DW_TAG_*_type. If we ever change
  20023. it, we'd need to call this even for non-local classes. */
  20024. if (c)
  20025. prune_unused_types_walk_local_classes (die);
  20026. /* It's a type node --- don't mark it. */
  20027. return;
  20028. case DW_TAG_const_type:
  20029. case DW_TAG_packed_type:
  20030. case DW_TAG_pointer_type:
  20031. case DW_TAG_reference_type:
  20032. case DW_TAG_rvalue_reference_type:
  20033. case DW_TAG_volatile_type:
  20034. case DW_TAG_typedef:
  20035. case DW_TAG_array_type:
  20036. case DW_TAG_interface_type:
  20037. case DW_TAG_friend:
  20038. case DW_TAG_variant_part:
  20039. case DW_TAG_enumeration_type:
  20040. case DW_TAG_subroutine_type:
  20041. case DW_TAG_string_type:
  20042. case DW_TAG_set_type:
  20043. case DW_TAG_subrange_type:
  20044. case DW_TAG_ptr_to_member_type:
  20045. case DW_TAG_file_type:
  20046. if (die->die_perennial_p)
  20047. break;
  20048. /* It's a type node --- don't mark it. */
  20049. return;
  20050. default:
  20051. /* Mark everything else. */
  20052. break;
  20053. }
  20054. if (die->die_mark == 0)
  20055. {
  20056. die->die_mark = 1;
  20057. /* Now, mark any dies referenced from here. */
  20058. prune_unused_types_walk_attribs (die);
  20059. }
  20060. die->die_mark = 2;
  20061. /* Mark children. */
  20062. FOR_EACH_CHILD (die, c, prune_unused_types_walk (c));
  20063. }
  20064. /* Increment the string counts on strings referred to from DIE's
  20065. attributes. */
  20066. static void
  20067. prune_unused_types_update_strings (dw_die_ref die)
  20068. {
  20069. dw_attr_ref a;
  20070. unsigned ix;
  20071. FOR_EACH_VEC_SAFE_ELT (die->die_attr, ix, a)
  20072. if (AT_class (a) == dw_val_class_str)
  20073. {
  20074. struct indirect_string_node *s = a->dw_attr_val.v.val_str;
  20075. s->refcount++;
  20076. /* Avoid unnecessarily putting strings that are used less than
  20077. twice in the hash table. */
  20078. if (s->refcount
  20079. == ((DEBUG_STR_SECTION_FLAGS & SECTION_MERGE) ? 1 : 2))
  20080. {
  20081. indirect_string_node **slot
  20082. = debug_str_hash->find_slot_with_hash (s->str,
  20083. htab_hash_string (s->str),
  20084. INSERT);
  20085. gcc_assert (*slot == NULL);
  20086. *slot = s;
  20087. }
  20088. }
  20089. }
  20090. /* Remove from the tree DIE any dies that aren't marked. */
  20091. static void
  20092. prune_unused_types_prune (dw_die_ref die)
  20093. {
  20094. dw_die_ref c;
  20095. gcc_assert (die->die_mark);
  20096. prune_unused_types_update_strings (die);
  20097. if (! die->die_child)
  20098. return;
  20099. c = die->die_child;
  20100. do {
  20101. dw_die_ref prev = c;
  20102. for (c = c->die_sib; ! c->die_mark; c = c->die_sib)
  20103. if (c == die->die_child)
  20104. {
  20105. /* No marked children between 'prev' and the end of the list. */
  20106. if (prev == c)
  20107. /* No marked children at all. */
  20108. die->die_child = NULL;
  20109. else
  20110. {
  20111. prev->die_sib = c->die_sib;
  20112. die->die_child = prev;
  20113. }
  20114. return;
  20115. }
  20116. if (c != prev->die_sib)
  20117. prev->die_sib = c;
  20118. prune_unused_types_prune (c);
  20119. } while (c != die->die_child);
  20120. }
  20121. /* Remove dies representing declarations that we never use. */
  20122. static void
  20123. prune_unused_types (void)
  20124. {
  20125. unsigned int i;
  20126. limbo_die_node *node;
  20127. comdat_type_node *ctnode;
  20128. pubname_ref pub;
  20129. dw_die_ref base_type;
  20130. #if ENABLE_ASSERT_CHECKING
  20131. /* All the marks should already be clear. */
  20132. verify_marks_clear (comp_unit_die ());
  20133. for (node = limbo_die_list; node; node = node->next)
  20134. verify_marks_clear (node->die);
  20135. for (ctnode = comdat_type_list; ctnode; ctnode = ctnode->next)
  20136. verify_marks_clear (ctnode->root_die);
  20137. #endif /* ENABLE_ASSERT_CHECKING */
  20138. /* Mark types that are used in global variables. */
  20139. premark_types_used_by_global_vars ();
  20140. /* Set the mark on nodes that are actually used. */
  20141. prune_unused_types_walk (comp_unit_die ());
  20142. for (node = limbo_die_list; node; node = node->next)
  20143. prune_unused_types_walk (node->die);
  20144. for (ctnode = comdat_type_list; ctnode; ctnode = ctnode->next)
  20145. {
  20146. prune_unused_types_walk (ctnode->root_die);
  20147. prune_unused_types_mark (ctnode->type_die, 1);
  20148. }
  20149. /* Also set the mark on nodes referenced from the pubname_table. Enumerators
  20150. are unusual in that they are pubnames that are the children of pubtypes.
  20151. They should only be marked via their parent DW_TAG_enumeration_type die,
  20152. not as roots in themselves. */
  20153. FOR_EACH_VEC_ELT (*pubname_table, i, pub)
  20154. if (pub->die->die_tag != DW_TAG_enumerator)
  20155. prune_unused_types_mark (pub->die, 1);
  20156. for (i = 0; base_types.iterate (i, &base_type); i++)
  20157. prune_unused_types_mark (base_type, 1);
  20158. if (debug_str_hash)
  20159. debug_str_hash->empty ();
  20160. if (skeleton_debug_str_hash)
  20161. skeleton_debug_str_hash->empty ();
  20162. prune_unused_types_prune (comp_unit_die ());
  20163. for (node = limbo_die_list; node; node = node->next)
  20164. prune_unused_types_prune (node->die);
  20165. for (ctnode = comdat_type_list; ctnode; ctnode = ctnode->next)
  20166. prune_unused_types_prune (ctnode->root_die);
  20167. /* Leave the marks clear. */
  20168. prune_unmark_dies (comp_unit_die ());
  20169. for (node = limbo_die_list; node; node = node->next)
  20170. prune_unmark_dies (node->die);
  20171. for (ctnode = comdat_type_list; ctnode; ctnode = ctnode->next)
  20172. prune_unmark_dies (ctnode->root_die);
  20173. }
  20174. /* Set the parameter to true if there are any relative pathnames in
  20175. the file table. */
  20176. int
  20177. file_table_relative_p (dwarf_file_data **slot, bool *p)
  20178. {
  20179. struct dwarf_file_data *d = *slot;
  20180. if (!IS_ABSOLUTE_PATH (d->filename))
  20181. {
  20182. *p = true;
  20183. return 0;
  20184. }
  20185. return 1;
  20186. }
  20187. /* Helpers to manipulate hash table of comdat type units. */
  20188. struct comdat_type_hasher : typed_noop_remove <comdat_type_node>
  20189. {
  20190. typedef comdat_type_node value_type;
  20191. typedef comdat_type_node compare_type;
  20192. static inline hashval_t hash (const value_type *);
  20193. static inline bool equal (const value_type *, const compare_type *);
  20194. };
  20195. inline hashval_t
  20196. comdat_type_hasher::hash (const value_type *type_node)
  20197. {
  20198. hashval_t h;
  20199. memcpy (&h, type_node->signature, sizeof (h));
  20200. return h;
  20201. }
  20202. inline bool
  20203. comdat_type_hasher::equal (const value_type *type_node_1,
  20204. const compare_type *type_node_2)
  20205. {
  20206. return (! memcmp (type_node_1->signature, type_node_2->signature,
  20207. DWARF_TYPE_SIGNATURE_SIZE));
  20208. }
  20209. /* Move a DW_AT_{,MIPS_}linkage_name attribute just added to dw_die_ref
  20210. to the location it would have been added, should we know its
  20211. DECL_ASSEMBLER_NAME when we added other attributes. This will
  20212. probably improve compactness of debug info, removing equivalent
  20213. abbrevs, and hide any differences caused by deferring the
  20214. computation of the assembler name, triggered by e.g. PCH. */
  20215. static inline void
  20216. move_linkage_attr (dw_die_ref die)
  20217. {
  20218. unsigned ix = vec_safe_length (die->die_attr);
  20219. dw_attr_node linkage = (*die->die_attr)[ix - 1];
  20220. gcc_assert (linkage.dw_attr == DW_AT_linkage_name
  20221. || linkage.dw_attr == DW_AT_MIPS_linkage_name);
  20222. while (--ix > 0)
  20223. {
  20224. dw_attr_node *prev = &(*die->die_attr)[ix - 1];
  20225. if (prev->dw_attr == DW_AT_decl_line || prev->dw_attr == DW_AT_name)
  20226. break;
  20227. }
  20228. if (ix != vec_safe_length (die->die_attr) - 1)
  20229. {
  20230. die->die_attr->pop ();
  20231. die->die_attr->quick_insert (ix, linkage);
  20232. }
  20233. }
  20234. /* Helper function for resolve_addr, mark DW_TAG_base_type nodes
  20235. referenced from typed stack ops and count how often they are used. */
  20236. static void
  20237. mark_base_types (dw_loc_descr_ref loc)
  20238. {
  20239. dw_die_ref base_type = NULL;
  20240. for (; loc; loc = loc->dw_loc_next)
  20241. {
  20242. switch (loc->dw_loc_opc)
  20243. {
  20244. case DW_OP_GNU_regval_type:
  20245. case DW_OP_GNU_deref_type:
  20246. base_type = loc->dw_loc_oprnd2.v.val_die_ref.die;
  20247. break;
  20248. case DW_OP_GNU_convert:
  20249. case DW_OP_GNU_reinterpret:
  20250. if (loc->dw_loc_oprnd1.val_class == dw_val_class_unsigned_const)
  20251. continue;
  20252. /* FALLTHRU */
  20253. case DW_OP_GNU_const_type:
  20254. base_type = loc->dw_loc_oprnd1.v.val_die_ref.die;
  20255. break;
  20256. case DW_OP_GNU_entry_value:
  20257. mark_base_types (loc->dw_loc_oprnd1.v.val_loc);
  20258. continue;
  20259. default:
  20260. continue;
  20261. }
  20262. gcc_assert (base_type->die_parent == comp_unit_die ());
  20263. if (base_type->die_mark)
  20264. base_type->die_mark++;
  20265. else
  20266. {
  20267. base_types.safe_push (base_type);
  20268. base_type->die_mark = 1;
  20269. }
  20270. }
  20271. }
  20272. /* Comparison function for sorting marked base types. */
  20273. static int
  20274. base_type_cmp (const void *x, const void *y)
  20275. {
  20276. dw_die_ref dx = *(const dw_die_ref *) x;
  20277. dw_die_ref dy = *(const dw_die_ref *) y;
  20278. unsigned int byte_size1, byte_size2;
  20279. unsigned int encoding1, encoding2;
  20280. if (dx->die_mark > dy->die_mark)
  20281. return -1;
  20282. if (dx->die_mark < dy->die_mark)
  20283. return 1;
  20284. byte_size1 = get_AT_unsigned (dx, DW_AT_byte_size);
  20285. byte_size2 = get_AT_unsigned (dy, DW_AT_byte_size);
  20286. if (byte_size1 < byte_size2)
  20287. return 1;
  20288. if (byte_size1 > byte_size2)
  20289. return -1;
  20290. encoding1 = get_AT_unsigned (dx, DW_AT_encoding);
  20291. encoding2 = get_AT_unsigned (dy, DW_AT_encoding);
  20292. if (encoding1 < encoding2)
  20293. return 1;
  20294. if (encoding1 > encoding2)
  20295. return -1;
  20296. return 0;
  20297. }
  20298. /* Move base types marked by mark_base_types as early as possible
  20299. in the CU, sorted by decreasing usage count both to make the
  20300. uleb128 references as small as possible and to make sure they
  20301. will have die_offset already computed by calc_die_sizes when
  20302. sizes of typed stack loc ops is computed. */
  20303. static void
  20304. move_marked_base_types (void)
  20305. {
  20306. unsigned int i;
  20307. dw_die_ref base_type, die, c;
  20308. if (base_types.is_empty ())
  20309. return;
  20310. /* Sort by decreasing usage count, they will be added again in that
  20311. order later on. */
  20312. base_types.qsort (base_type_cmp);
  20313. die = comp_unit_die ();
  20314. c = die->die_child;
  20315. do
  20316. {
  20317. dw_die_ref prev = c;
  20318. c = c->die_sib;
  20319. while (c->die_mark)
  20320. {
  20321. remove_child_with_prev (c, prev);
  20322. /* As base types got marked, there must be at least
  20323. one node other than DW_TAG_base_type. */
  20324. gcc_assert (c != c->die_sib);
  20325. c = c->die_sib;
  20326. }
  20327. }
  20328. while (c != die->die_child);
  20329. gcc_assert (die->die_child);
  20330. c = die->die_child;
  20331. for (i = 0; base_types.iterate (i, &base_type); i++)
  20332. {
  20333. base_type->die_mark = 0;
  20334. base_type->die_sib = c->die_sib;
  20335. c->die_sib = base_type;
  20336. c = base_type;
  20337. }
  20338. }
  20339. /* Helper function for resolve_addr, attempt to resolve
  20340. one CONST_STRING, return true if successful. Similarly verify that
  20341. SYMBOL_REFs refer to variables emitted in the current CU. */
  20342. static bool
  20343. resolve_one_addr (rtx *addr)
  20344. {
  20345. rtx rtl = *addr;
  20346. if (GET_CODE (rtl) == CONST_STRING)
  20347. {
  20348. size_t len = strlen (XSTR (rtl, 0)) + 1;
  20349. tree t = build_string (len, XSTR (rtl, 0));
  20350. tree tlen = size_int (len - 1);
  20351. TREE_TYPE (t)
  20352. = build_array_type (char_type_node, build_index_type (tlen));
  20353. rtl = lookup_constant_def (t);
  20354. if (!rtl || !MEM_P (rtl))
  20355. return false;
  20356. rtl = XEXP (rtl, 0);
  20357. if (GET_CODE (rtl) == SYMBOL_REF
  20358. && SYMBOL_REF_DECL (rtl)
  20359. && !TREE_ASM_WRITTEN (SYMBOL_REF_DECL (rtl)))
  20360. return false;
  20361. vec_safe_push (used_rtx_array, rtl);
  20362. *addr = rtl;
  20363. return true;
  20364. }
  20365. if (GET_CODE (rtl) == SYMBOL_REF
  20366. && SYMBOL_REF_DECL (rtl))
  20367. {
  20368. if (TREE_CONSTANT_POOL_ADDRESS_P (rtl))
  20369. {
  20370. if (!TREE_ASM_WRITTEN (DECL_INITIAL (SYMBOL_REF_DECL (rtl))))
  20371. return false;
  20372. }
  20373. else if (!TREE_ASM_WRITTEN (SYMBOL_REF_DECL (rtl)))
  20374. return false;
  20375. }
  20376. if (GET_CODE (rtl) == CONST)
  20377. {
  20378. subrtx_ptr_iterator::array_type array;
  20379. FOR_EACH_SUBRTX_PTR (iter, array, &XEXP (rtl, 0), ALL)
  20380. if (!resolve_one_addr (*iter))
  20381. return false;
  20382. }
  20383. return true;
  20384. }
  20385. /* For STRING_CST, return SYMBOL_REF of its constant pool entry,
  20386. if possible, and create DW_TAG_dwarf_procedure that can be referenced
  20387. from DW_OP_GNU_implicit_pointer if the string hasn't been seen yet. */
  20388. static rtx
  20389. string_cst_pool_decl (tree t)
  20390. {
  20391. rtx rtl = output_constant_def (t, 1);
  20392. unsigned char *array;
  20393. dw_loc_descr_ref l;
  20394. tree decl;
  20395. size_t len;
  20396. dw_die_ref ref;
  20397. if (!rtl || !MEM_P (rtl))
  20398. return NULL_RTX;
  20399. rtl = XEXP (rtl, 0);
  20400. if (GET_CODE (rtl) != SYMBOL_REF
  20401. || SYMBOL_REF_DECL (rtl) == NULL_TREE)
  20402. return NULL_RTX;
  20403. decl = SYMBOL_REF_DECL (rtl);
  20404. if (!lookup_decl_die (decl))
  20405. {
  20406. len = TREE_STRING_LENGTH (t);
  20407. vec_safe_push (used_rtx_array, rtl);
  20408. ref = new_die (DW_TAG_dwarf_procedure, comp_unit_die (), decl);
  20409. array = ggc_vec_alloc<unsigned char> (len);
  20410. memcpy (array, TREE_STRING_POINTER (t), len);
  20411. l = new_loc_descr (DW_OP_implicit_value, len, 0);
  20412. l->dw_loc_oprnd2.val_class = dw_val_class_vec;
  20413. l->dw_loc_oprnd2.v.val_vec.length = len;
  20414. l->dw_loc_oprnd2.v.val_vec.elt_size = 1;
  20415. l->dw_loc_oprnd2.v.val_vec.array = array;
  20416. add_AT_loc (ref, DW_AT_location, l);
  20417. equate_decl_number_to_die (decl, ref);
  20418. }
  20419. return rtl;
  20420. }
  20421. /* Helper function of resolve_addr_in_expr. LOC is
  20422. a DW_OP_addr followed by DW_OP_stack_value, either at the start
  20423. of exprloc or after DW_OP_{,bit_}piece, and val_addr can't be
  20424. resolved. Replace it (both DW_OP_addr and DW_OP_stack_value)
  20425. with DW_OP_GNU_implicit_pointer if possible
  20426. and return true, if unsuccessful, return false. */
  20427. static bool
  20428. optimize_one_addr_into_implicit_ptr (dw_loc_descr_ref loc)
  20429. {
  20430. rtx rtl = loc->dw_loc_oprnd1.v.val_addr;
  20431. HOST_WIDE_INT offset = 0;
  20432. dw_die_ref ref = NULL;
  20433. tree decl;
  20434. if (GET_CODE (rtl) == CONST
  20435. && GET_CODE (XEXP (rtl, 0)) == PLUS
  20436. && CONST_INT_P (XEXP (XEXP (rtl, 0), 1)))
  20437. {
  20438. offset = INTVAL (XEXP (XEXP (rtl, 0), 1));
  20439. rtl = XEXP (XEXP (rtl, 0), 0);
  20440. }
  20441. if (GET_CODE (rtl) == CONST_STRING)
  20442. {
  20443. size_t len = strlen (XSTR (rtl, 0)) + 1;
  20444. tree t = build_string (len, XSTR (rtl, 0));
  20445. tree tlen = size_int (len - 1);
  20446. TREE_TYPE (t)
  20447. = build_array_type (char_type_node, build_index_type (tlen));
  20448. rtl = string_cst_pool_decl (t);
  20449. if (!rtl)
  20450. return false;
  20451. }
  20452. if (GET_CODE (rtl) == SYMBOL_REF && SYMBOL_REF_DECL (rtl))
  20453. {
  20454. decl = SYMBOL_REF_DECL (rtl);
  20455. if (TREE_CODE (decl) == VAR_DECL && !DECL_EXTERNAL (decl))
  20456. {
  20457. ref = lookup_decl_die (decl);
  20458. if (ref && (get_AT (ref, DW_AT_location)
  20459. || get_AT (ref, DW_AT_const_value)))
  20460. {
  20461. loc->dw_loc_opc = DW_OP_GNU_implicit_pointer;
  20462. loc->dw_loc_oprnd1.val_class = dw_val_class_die_ref;
  20463. loc->dw_loc_oprnd1.val_entry = NULL;
  20464. loc->dw_loc_oprnd1.v.val_die_ref.die = ref;
  20465. loc->dw_loc_oprnd1.v.val_die_ref.external = 0;
  20466. loc->dw_loc_next = loc->dw_loc_next->dw_loc_next;
  20467. loc->dw_loc_oprnd2.v.val_int = offset;
  20468. return true;
  20469. }
  20470. }
  20471. }
  20472. return false;
  20473. }
  20474. /* Helper function for resolve_addr, handle one location
  20475. expression, return false if at least one CONST_STRING or SYMBOL_REF in
  20476. the location list couldn't be resolved. */
  20477. static bool
  20478. resolve_addr_in_expr (dw_loc_descr_ref loc)
  20479. {
  20480. dw_loc_descr_ref keep = NULL;
  20481. for (dw_loc_descr_ref prev = NULL; loc; prev = loc, loc = loc->dw_loc_next)
  20482. switch (loc->dw_loc_opc)
  20483. {
  20484. case DW_OP_addr:
  20485. if (!resolve_one_addr (&loc->dw_loc_oprnd1.v.val_addr))
  20486. {
  20487. if ((prev == NULL
  20488. || prev->dw_loc_opc == DW_OP_piece
  20489. || prev->dw_loc_opc == DW_OP_bit_piece)
  20490. && loc->dw_loc_next
  20491. && loc->dw_loc_next->dw_loc_opc == DW_OP_stack_value
  20492. && !dwarf_strict
  20493. && optimize_one_addr_into_implicit_ptr (loc))
  20494. break;
  20495. return false;
  20496. }
  20497. break;
  20498. case DW_OP_GNU_addr_index:
  20499. case DW_OP_GNU_const_index:
  20500. if (loc->dw_loc_opc == DW_OP_GNU_addr_index
  20501. || (loc->dw_loc_opc == DW_OP_GNU_const_index && loc->dtprel))
  20502. {
  20503. rtx rtl = loc->dw_loc_oprnd1.val_entry->addr.rtl;
  20504. if (!resolve_one_addr (&rtl))
  20505. return false;
  20506. remove_addr_table_entry (loc->dw_loc_oprnd1.val_entry);
  20507. loc->dw_loc_oprnd1.val_entry =
  20508. add_addr_table_entry (rtl, ate_kind_rtx);
  20509. }
  20510. break;
  20511. case DW_OP_const4u:
  20512. case DW_OP_const8u:
  20513. if (loc->dtprel
  20514. && !resolve_one_addr (&loc->dw_loc_oprnd1.v.val_addr))
  20515. return false;
  20516. break;
  20517. case DW_OP_plus_uconst:
  20518. if (size_of_loc_descr (loc)
  20519. > size_of_int_loc_descriptor (loc->dw_loc_oprnd1.v.val_unsigned)
  20520. + 1
  20521. && loc->dw_loc_oprnd1.v.val_unsigned > 0)
  20522. {
  20523. dw_loc_descr_ref repl
  20524. = int_loc_descriptor (loc->dw_loc_oprnd1.v.val_unsigned);
  20525. add_loc_descr (&repl, new_loc_descr (DW_OP_plus, 0, 0));
  20526. add_loc_descr (&repl, loc->dw_loc_next);
  20527. *loc = *repl;
  20528. }
  20529. break;
  20530. case DW_OP_implicit_value:
  20531. if (loc->dw_loc_oprnd2.val_class == dw_val_class_addr
  20532. && !resolve_one_addr (&loc->dw_loc_oprnd2.v.val_addr))
  20533. return false;
  20534. break;
  20535. case DW_OP_GNU_implicit_pointer:
  20536. case DW_OP_GNU_parameter_ref:
  20537. if (loc->dw_loc_oprnd1.val_class == dw_val_class_decl_ref)
  20538. {
  20539. dw_die_ref ref
  20540. = lookup_decl_die (loc->dw_loc_oprnd1.v.val_decl_ref);
  20541. if (ref == NULL)
  20542. return false;
  20543. loc->dw_loc_oprnd1.val_class = dw_val_class_die_ref;
  20544. loc->dw_loc_oprnd1.v.val_die_ref.die = ref;
  20545. loc->dw_loc_oprnd1.v.val_die_ref.external = 0;
  20546. }
  20547. break;
  20548. case DW_OP_GNU_const_type:
  20549. case DW_OP_GNU_regval_type:
  20550. case DW_OP_GNU_deref_type:
  20551. case DW_OP_GNU_convert:
  20552. case DW_OP_GNU_reinterpret:
  20553. while (loc->dw_loc_next
  20554. && loc->dw_loc_next->dw_loc_opc == DW_OP_GNU_convert)
  20555. {
  20556. dw_die_ref base1, base2;
  20557. unsigned enc1, enc2, size1, size2;
  20558. if (loc->dw_loc_opc == DW_OP_GNU_regval_type
  20559. || loc->dw_loc_opc == DW_OP_GNU_deref_type)
  20560. base1 = loc->dw_loc_oprnd2.v.val_die_ref.die;
  20561. else if (loc->dw_loc_oprnd1.val_class
  20562. == dw_val_class_unsigned_const)
  20563. break;
  20564. else
  20565. base1 = loc->dw_loc_oprnd1.v.val_die_ref.die;
  20566. if (loc->dw_loc_next->dw_loc_oprnd1.val_class
  20567. == dw_val_class_unsigned_const)
  20568. break;
  20569. base2 = loc->dw_loc_next->dw_loc_oprnd1.v.val_die_ref.die;
  20570. gcc_assert (base1->die_tag == DW_TAG_base_type
  20571. && base2->die_tag == DW_TAG_base_type);
  20572. enc1 = get_AT_unsigned (base1, DW_AT_encoding);
  20573. enc2 = get_AT_unsigned (base2, DW_AT_encoding);
  20574. size1 = get_AT_unsigned (base1, DW_AT_byte_size);
  20575. size2 = get_AT_unsigned (base2, DW_AT_byte_size);
  20576. if (size1 == size2
  20577. && (((enc1 == DW_ATE_unsigned || enc1 == DW_ATE_signed)
  20578. && (enc2 == DW_ATE_unsigned || enc2 == DW_ATE_signed)
  20579. && loc != keep)
  20580. || enc1 == enc2))
  20581. {
  20582. /* Optimize away next DW_OP_GNU_convert after
  20583. adjusting LOC's base type die reference. */
  20584. if (loc->dw_loc_opc == DW_OP_GNU_regval_type
  20585. || loc->dw_loc_opc == DW_OP_GNU_deref_type)
  20586. loc->dw_loc_oprnd2.v.val_die_ref.die = base2;
  20587. else
  20588. loc->dw_loc_oprnd1.v.val_die_ref.die = base2;
  20589. loc->dw_loc_next = loc->dw_loc_next->dw_loc_next;
  20590. continue;
  20591. }
  20592. /* Don't change integer DW_OP_GNU_convert after e.g. floating
  20593. point typed stack entry. */
  20594. else if (enc1 != DW_ATE_unsigned && enc1 != DW_ATE_signed)
  20595. keep = loc->dw_loc_next;
  20596. break;
  20597. }
  20598. break;
  20599. default:
  20600. break;
  20601. }
  20602. return true;
  20603. }
  20604. /* Helper function of resolve_addr. DIE had DW_AT_location of
  20605. DW_OP_addr alone, which referred to DECL in DW_OP_addr's operand
  20606. and DW_OP_addr couldn't be resolved. resolve_addr has already
  20607. removed the DW_AT_location attribute. This function attempts to
  20608. add a new DW_AT_location attribute with DW_OP_GNU_implicit_pointer
  20609. to it or DW_AT_const_value attribute, if possible. */
  20610. static void
  20611. optimize_location_into_implicit_ptr (dw_die_ref die, tree decl)
  20612. {
  20613. if (TREE_CODE (decl) != VAR_DECL
  20614. || lookup_decl_die (decl) != die
  20615. || DECL_EXTERNAL (decl)
  20616. || !TREE_STATIC (decl)
  20617. || DECL_INITIAL (decl) == NULL_TREE
  20618. || DECL_P (DECL_INITIAL (decl))
  20619. || get_AT (die, DW_AT_const_value))
  20620. return;
  20621. tree init = DECL_INITIAL (decl);
  20622. HOST_WIDE_INT offset = 0;
  20623. /* For variables that have been optimized away and thus
  20624. don't have a memory location, see if we can emit
  20625. DW_AT_const_value instead. */
  20626. if (tree_add_const_value_attribute (die, init))
  20627. return;
  20628. if (dwarf_strict)
  20629. return;
  20630. /* If init is ADDR_EXPR or POINTER_PLUS_EXPR of ADDR_EXPR,
  20631. and ADDR_EXPR refers to a decl that has DW_AT_location or
  20632. DW_AT_const_value (but isn't addressable, otherwise
  20633. resolving the original DW_OP_addr wouldn't fail), see if
  20634. we can add DW_OP_GNU_implicit_pointer. */
  20635. STRIP_NOPS (init);
  20636. if (TREE_CODE (init) == POINTER_PLUS_EXPR
  20637. && tree_fits_shwi_p (TREE_OPERAND (init, 1)))
  20638. {
  20639. offset = tree_to_shwi (TREE_OPERAND (init, 1));
  20640. init = TREE_OPERAND (init, 0);
  20641. STRIP_NOPS (init);
  20642. }
  20643. if (TREE_CODE (init) != ADDR_EXPR)
  20644. return;
  20645. if ((TREE_CODE (TREE_OPERAND (init, 0)) == STRING_CST
  20646. && !TREE_ASM_WRITTEN (TREE_OPERAND (init, 0)))
  20647. || (TREE_CODE (TREE_OPERAND (init, 0)) == VAR_DECL
  20648. && !DECL_EXTERNAL (TREE_OPERAND (init, 0))
  20649. && TREE_OPERAND (init, 0) != decl))
  20650. {
  20651. dw_die_ref ref;
  20652. dw_loc_descr_ref l;
  20653. if (TREE_CODE (TREE_OPERAND (init, 0)) == STRING_CST)
  20654. {
  20655. rtx rtl = string_cst_pool_decl (TREE_OPERAND (init, 0));
  20656. if (!rtl)
  20657. return;
  20658. decl = SYMBOL_REF_DECL (rtl);
  20659. }
  20660. else
  20661. decl = TREE_OPERAND (init, 0);
  20662. ref = lookup_decl_die (decl);
  20663. if (ref == NULL
  20664. || (!get_AT (ref, DW_AT_location)
  20665. && !get_AT (ref, DW_AT_const_value)))
  20666. return;
  20667. l = new_loc_descr (DW_OP_GNU_implicit_pointer, 0, offset);
  20668. l->dw_loc_oprnd1.val_class = dw_val_class_die_ref;
  20669. l->dw_loc_oprnd1.v.val_die_ref.die = ref;
  20670. l->dw_loc_oprnd1.v.val_die_ref.external = 0;
  20671. add_AT_loc (die, DW_AT_location, l);
  20672. }
  20673. }
  20674. /* Resolve DW_OP_addr and DW_AT_const_value CONST_STRING arguments to
  20675. an address in .rodata section if the string literal is emitted there,
  20676. or remove the containing location list or replace DW_AT_const_value
  20677. with DW_AT_location and empty location expression, if it isn't found
  20678. in .rodata. Similarly for SYMBOL_REFs, keep only those that refer
  20679. to something that has been emitted in the current CU. */
  20680. static void
  20681. resolve_addr (dw_die_ref die)
  20682. {
  20683. dw_die_ref c;
  20684. dw_attr_ref a;
  20685. dw_loc_list_ref *curr, *start, loc;
  20686. unsigned ix;
  20687. FOR_EACH_VEC_SAFE_ELT (die->die_attr, ix, a)
  20688. switch (AT_class (a))
  20689. {
  20690. case dw_val_class_loc_list:
  20691. start = curr = AT_loc_list_ptr (a);
  20692. loc = *curr;
  20693. gcc_assert (loc);
  20694. /* The same list can be referenced more than once. See if we have
  20695. already recorded the result from a previous pass. */
  20696. if (loc->replaced)
  20697. *curr = loc->dw_loc_next;
  20698. else if (!loc->resolved_addr)
  20699. {
  20700. /* As things stand, we do not expect or allow one die to
  20701. reference a suffix of another die's location list chain.
  20702. References must be identical or completely separate.
  20703. There is therefore no need to cache the result of this
  20704. pass on any list other than the first; doing so
  20705. would lead to unnecessary writes. */
  20706. while (*curr)
  20707. {
  20708. gcc_assert (!(*curr)->replaced && !(*curr)->resolved_addr);
  20709. if (!resolve_addr_in_expr ((*curr)->expr))
  20710. {
  20711. dw_loc_list_ref next = (*curr)->dw_loc_next;
  20712. dw_loc_descr_ref l = (*curr)->expr;
  20713. if (next && (*curr)->ll_symbol)
  20714. {
  20715. gcc_assert (!next->ll_symbol);
  20716. next->ll_symbol = (*curr)->ll_symbol;
  20717. }
  20718. if (dwarf_split_debug_info)
  20719. remove_loc_list_addr_table_entries (l);
  20720. *curr = next;
  20721. }
  20722. else
  20723. {
  20724. mark_base_types ((*curr)->expr);
  20725. curr = &(*curr)->dw_loc_next;
  20726. }
  20727. }
  20728. if (loc == *start)
  20729. loc->resolved_addr = 1;
  20730. else
  20731. {
  20732. loc->replaced = 1;
  20733. loc->dw_loc_next = *start;
  20734. }
  20735. }
  20736. if (!*start)
  20737. {
  20738. remove_AT (die, a->dw_attr);
  20739. ix--;
  20740. }
  20741. break;
  20742. case dw_val_class_loc:
  20743. {
  20744. dw_loc_descr_ref l = AT_loc (a);
  20745. /* For -gdwarf-2 don't attempt to optimize
  20746. DW_AT_data_member_location containing
  20747. DW_OP_plus_uconst - older consumers might
  20748. rely on it being that op instead of a more complex,
  20749. but shorter, location description. */
  20750. if ((dwarf_version > 2
  20751. || a->dw_attr != DW_AT_data_member_location
  20752. || l == NULL
  20753. || l->dw_loc_opc != DW_OP_plus_uconst
  20754. || l->dw_loc_next != NULL)
  20755. && !resolve_addr_in_expr (l))
  20756. {
  20757. if (dwarf_split_debug_info)
  20758. remove_loc_list_addr_table_entries (l);
  20759. if (l != NULL
  20760. && l->dw_loc_next == NULL
  20761. && l->dw_loc_opc == DW_OP_addr
  20762. && GET_CODE (l->dw_loc_oprnd1.v.val_addr) == SYMBOL_REF
  20763. && SYMBOL_REF_DECL (l->dw_loc_oprnd1.v.val_addr)
  20764. && a->dw_attr == DW_AT_location)
  20765. {
  20766. tree decl = SYMBOL_REF_DECL (l->dw_loc_oprnd1.v.val_addr);
  20767. remove_AT (die, a->dw_attr);
  20768. ix--;
  20769. optimize_location_into_implicit_ptr (die, decl);
  20770. break;
  20771. }
  20772. remove_AT (die, a->dw_attr);
  20773. ix--;
  20774. }
  20775. else
  20776. mark_base_types (l);
  20777. }
  20778. break;
  20779. case dw_val_class_addr:
  20780. if (a->dw_attr == DW_AT_const_value
  20781. && !resolve_one_addr (&a->dw_attr_val.v.val_addr))
  20782. {
  20783. if (AT_index (a) != NOT_INDEXED)
  20784. remove_addr_table_entry (a->dw_attr_val.val_entry);
  20785. remove_AT (die, a->dw_attr);
  20786. ix--;
  20787. }
  20788. if (die->die_tag == DW_TAG_GNU_call_site
  20789. && a->dw_attr == DW_AT_abstract_origin)
  20790. {
  20791. tree tdecl = SYMBOL_REF_DECL (a->dw_attr_val.v.val_addr);
  20792. dw_die_ref tdie = lookup_decl_die (tdecl);
  20793. dw_die_ref cdie;
  20794. if (tdie == NULL
  20795. && DECL_EXTERNAL (tdecl)
  20796. && DECL_ABSTRACT_ORIGIN (tdecl) == NULL_TREE
  20797. && (cdie = lookup_context_die (DECL_CONTEXT (tdecl))))
  20798. {
  20799. /* Creating a full DIE for tdecl is overly expensive and
  20800. at this point even wrong when in the LTO phase
  20801. as it can end up generating new type DIEs we didn't
  20802. output and thus optimize_external_refs will crash. */
  20803. tdie = new_die (DW_TAG_subprogram, cdie, NULL_TREE);
  20804. add_AT_flag (tdie, DW_AT_external, 1);
  20805. add_AT_flag (tdie, DW_AT_declaration, 1);
  20806. add_linkage_attr (tdie, tdecl);
  20807. add_name_and_src_coords_attributes (tdie, tdecl);
  20808. equate_decl_number_to_die (tdecl, tdie);
  20809. }
  20810. if (tdie)
  20811. {
  20812. a->dw_attr_val.val_class = dw_val_class_die_ref;
  20813. a->dw_attr_val.v.val_die_ref.die = tdie;
  20814. a->dw_attr_val.v.val_die_ref.external = 0;
  20815. }
  20816. else
  20817. {
  20818. if (AT_index (a) != NOT_INDEXED)
  20819. remove_addr_table_entry (a->dw_attr_val.val_entry);
  20820. remove_AT (die, a->dw_attr);
  20821. ix--;
  20822. }
  20823. }
  20824. break;
  20825. default:
  20826. break;
  20827. }
  20828. FOR_EACH_CHILD (die, c, resolve_addr (c));
  20829. }
  20830. /* Helper routines for optimize_location_lists.
  20831. This pass tries to share identical local lists in .debug_loc
  20832. section. */
  20833. /* Iteratively hash operands of LOC opcode into HSTATE. */
  20834. static void
  20835. hash_loc_operands (dw_loc_descr_ref loc, inchash::hash &hstate)
  20836. {
  20837. dw_val_ref val1 = &loc->dw_loc_oprnd1;
  20838. dw_val_ref val2 = &loc->dw_loc_oprnd2;
  20839. switch (loc->dw_loc_opc)
  20840. {
  20841. case DW_OP_const4u:
  20842. case DW_OP_const8u:
  20843. if (loc->dtprel)
  20844. goto hash_addr;
  20845. /* FALLTHRU */
  20846. case DW_OP_const1u:
  20847. case DW_OP_const1s:
  20848. case DW_OP_const2u:
  20849. case DW_OP_const2s:
  20850. case DW_OP_const4s:
  20851. case DW_OP_const8s:
  20852. case DW_OP_constu:
  20853. case DW_OP_consts:
  20854. case DW_OP_pick:
  20855. case DW_OP_plus_uconst:
  20856. case DW_OP_breg0:
  20857. case DW_OP_breg1:
  20858. case DW_OP_breg2:
  20859. case DW_OP_breg3:
  20860. case DW_OP_breg4:
  20861. case DW_OP_breg5:
  20862. case DW_OP_breg6:
  20863. case DW_OP_breg7:
  20864. case DW_OP_breg8:
  20865. case DW_OP_breg9:
  20866. case DW_OP_breg10:
  20867. case DW_OP_breg11:
  20868. case DW_OP_breg12:
  20869. case DW_OP_breg13:
  20870. case DW_OP_breg14:
  20871. case DW_OP_breg15:
  20872. case DW_OP_breg16:
  20873. case DW_OP_breg17:
  20874. case DW_OP_breg18:
  20875. case DW_OP_breg19:
  20876. case DW_OP_breg20:
  20877. case DW_OP_breg21:
  20878. case DW_OP_breg22:
  20879. case DW_OP_breg23:
  20880. case DW_OP_breg24:
  20881. case DW_OP_breg25:
  20882. case DW_OP_breg26:
  20883. case DW_OP_breg27:
  20884. case DW_OP_breg28:
  20885. case DW_OP_breg29:
  20886. case DW_OP_breg30:
  20887. case DW_OP_breg31:
  20888. case DW_OP_regx:
  20889. case DW_OP_fbreg:
  20890. case DW_OP_piece:
  20891. case DW_OP_deref_size:
  20892. case DW_OP_xderef_size:
  20893. hstate.add_object (val1->v.val_int);
  20894. break;
  20895. case DW_OP_skip:
  20896. case DW_OP_bra:
  20897. {
  20898. int offset;
  20899. gcc_assert (val1->val_class == dw_val_class_loc);
  20900. offset = val1->v.val_loc->dw_loc_addr - (loc->dw_loc_addr + 3);
  20901. hstate.add_object (offset);
  20902. }
  20903. break;
  20904. case DW_OP_implicit_value:
  20905. hstate.add_object (val1->v.val_unsigned);
  20906. switch (val2->val_class)
  20907. {
  20908. case dw_val_class_const:
  20909. hstate.add_object (val2->v.val_int);
  20910. break;
  20911. case dw_val_class_vec:
  20912. {
  20913. unsigned int elt_size = val2->v.val_vec.elt_size;
  20914. unsigned int len = val2->v.val_vec.length;
  20915. hstate.add_int (elt_size);
  20916. hstate.add_int (len);
  20917. hstate.add (val2->v.val_vec.array, len * elt_size);
  20918. }
  20919. break;
  20920. case dw_val_class_const_double:
  20921. hstate.add_object (val2->v.val_double.low);
  20922. hstate.add_object (val2->v.val_double.high);
  20923. break;
  20924. case dw_val_class_wide_int:
  20925. hstate.add (val2->v.val_wide->get_val (),
  20926. get_full_len (*val2->v.val_wide)
  20927. * HOST_BITS_PER_WIDE_INT / HOST_BITS_PER_CHAR);
  20928. break;
  20929. case dw_val_class_addr:
  20930. inchash::add_rtx (val2->v.val_addr, hstate);
  20931. break;
  20932. default:
  20933. gcc_unreachable ();
  20934. }
  20935. break;
  20936. case DW_OP_bregx:
  20937. case DW_OP_bit_piece:
  20938. hstate.add_object (val1->v.val_int);
  20939. hstate.add_object (val2->v.val_int);
  20940. break;
  20941. case DW_OP_addr:
  20942. hash_addr:
  20943. if (loc->dtprel)
  20944. {
  20945. unsigned char dtprel = 0xd1;
  20946. hstate.add_object (dtprel);
  20947. }
  20948. inchash::add_rtx (val1->v.val_addr, hstate);
  20949. break;
  20950. case DW_OP_GNU_addr_index:
  20951. case DW_OP_GNU_const_index:
  20952. {
  20953. if (loc->dtprel)
  20954. {
  20955. unsigned char dtprel = 0xd1;
  20956. hstate.add_object (dtprel);
  20957. }
  20958. inchash::add_rtx (val1->val_entry->addr.rtl, hstate);
  20959. }
  20960. break;
  20961. case DW_OP_GNU_implicit_pointer:
  20962. hstate.add_int (val2->v.val_int);
  20963. break;
  20964. case DW_OP_GNU_entry_value:
  20965. hstate.add_object (val1->v.val_loc);
  20966. break;
  20967. case DW_OP_GNU_regval_type:
  20968. case DW_OP_GNU_deref_type:
  20969. {
  20970. unsigned int byte_size
  20971. = get_AT_unsigned (val2->v.val_die_ref.die, DW_AT_byte_size);
  20972. unsigned int encoding
  20973. = get_AT_unsigned (val2->v.val_die_ref.die, DW_AT_encoding);
  20974. hstate.add_object (val1->v.val_int);
  20975. hstate.add_object (byte_size);
  20976. hstate.add_object (encoding);
  20977. }
  20978. break;
  20979. case DW_OP_GNU_convert:
  20980. case DW_OP_GNU_reinterpret:
  20981. if (val1->val_class == dw_val_class_unsigned_const)
  20982. {
  20983. hstate.add_object (val1->v.val_unsigned);
  20984. break;
  20985. }
  20986. /* FALLTHRU */
  20987. case DW_OP_GNU_const_type:
  20988. {
  20989. unsigned int byte_size
  20990. = get_AT_unsigned (val1->v.val_die_ref.die, DW_AT_byte_size);
  20991. unsigned int encoding
  20992. = get_AT_unsigned (val1->v.val_die_ref.die, DW_AT_encoding);
  20993. hstate.add_object (byte_size);
  20994. hstate.add_object (encoding);
  20995. if (loc->dw_loc_opc != DW_OP_GNU_const_type)
  20996. break;
  20997. hstate.add_object (val2->val_class);
  20998. switch (val2->val_class)
  20999. {
  21000. case dw_val_class_const:
  21001. hstate.add_object (val2->v.val_int);
  21002. break;
  21003. case dw_val_class_vec:
  21004. {
  21005. unsigned int elt_size = val2->v.val_vec.elt_size;
  21006. unsigned int len = val2->v.val_vec.length;
  21007. hstate.add_object (elt_size);
  21008. hstate.add_object (len);
  21009. hstate.add (val2->v.val_vec.array, len * elt_size);
  21010. }
  21011. break;
  21012. case dw_val_class_const_double:
  21013. hstate.add_object (val2->v.val_double.low);
  21014. hstate.add_object (val2->v.val_double.high);
  21015. break;
  21016. case dw_val_class_wide_int:
  21017. hstate.add (val2->v.val_wide->get_val (),
  21018. get_full_len (*val2->v.val_wide)
  21019. * HOST_BITS_PER_WIDE_INT / HOST_BITS_PER_CHAR);
  21020. break;
  21021. default:
  21022. gcc_unreachable ();
  21023. }
  21024. }
  21025. break;
  21026. default:
  21027. /* Other codes have no operands. */
  21028. break;
  21029. }
  21030. }
  21031. /* Iteratively hash the whole DWARF location expression LOC into HSTATE. */
  21032. static inline void
  21033. hash_locs (dw_loc_descr_ref loc, inchash::hash &hstate)
  21034. {
  21035. dw_loc_descr_ref l;
  21036. bool sizes_computed = false;
  21037. /* Compute sizes, so that DW_OP_skip/DW_OP_bra can be checksummed. */
  21038. size_of_locs (loc);
  21039. for (l = loc; l != NULL; l = l->dw_loc_next)
  21040. {
  21041. enum dwarf_location_atom opc = l->dw_loc_opc;
  21042. hstate.add_object (opc);
  21043. if ((opc == DW_OP_skip || opc == DW_OP_bra) && !sizes_computed)
  21044. {
  21045. size_of_locs (loc);
  21046. sizes_computed = true;
  21047. }
  21048. hash_loc_operands (l, hstate);
  21049. }
  21050. }
  21051. /* Compute hash of the whole location list LIST_HEAD. */
  21052. static inline void
  21053. hash_loc_list (dw_loc_list_ref list_head)
  21054. {
  21055. dw_loc_list_ref curr = list_head;
  21056. inchash::hash hstate;
  21057. for (curr = list_head; curr != NULL; curr = curr->dw_loc_next)
  21058. {
  21059. hstate.add (curr->begin, strlen (curr->begin) + 1);
  21060. hstate.add (curr->end, strlen (curr->end) + 1);
  21061. if (curr->section)
  21062. hstate.add (curr->section, strlen (curr->section) + 1);
  21063. hash_locs (curr->expr, hstate);
  21064. }
  21065. list_head->hash = hstate.end ();
  21066. }
  21067. /* Return true if X and Y opcodes have the same operands. */
  21068. static inline bool
  21069. compare_loc_operands (dw_loc_descr_ref x, dw_loc_descr_ref y)
  21070. {
  21071. dw_val_ref valx1 = &x->dw_loc_oprnd1;
  21072. dw_val_ref valx2 = &x->dw_loc_oprnd2;
  21073. dw_val_ref valy1 = &y->dw_loc_oprnd1;
  21074. dw_val_ref valy2 = &y->dw_loc_oprnd2;
  21075. switch (x->dw_loc_opc)
  21076. {
  21077. case DW_OP_const4u:
  21078. case DW_OP_const8u:
  21079. if (x->dtprel)
  21080. goto hash_addr;
  21081. /* FALLTHRU */
  21082. case DW_OP_const1u:
  21083. case DW_OP_const1s:
  21084. case DW_OP_const2u:
  21085. case DW_OP_const2s:
  21086. case DW_OP_const4s:
  21087. case DW_OP_const8s:
  21088. case DW_OP_constu:
  21089. case DW_OP_consts:
  21090. case DW_OP_pick:
  21091. case DW_OP_plus_uconst:
  21092. case DW_OP_breg0:
  21093. case DW_OP_breg1:
  21094. case DW_OP_breg2:
  21095. case DW_OP_breg3:
  21096. case DW_OP_breg4:
  21097. case DW_OP_breg5:
  21098. case DW_OP_breg6:
  21099. case DW_OP_breg7:
  21100. case DW_OP_breg8:
  21101. case DW_OP_breg9:
  21102. case DW_OP_breg10:
  21103. case DW_OP_breg11:
  21104. case DW_OP_breg12:
  21105. case DW_OP_breg13:
  21106. case DW_OP_breg14:
  21107. case DW_OP_breg15:
  21108. case DW_OP_breg16:
  21109. case DW_OP_breg17:
  21110. case DW_OP_breg18:
  21111. case DW_OP_breg19:
  21112. case DW_OP_breg20:
  21113. case DW_OP_breg21:
  21114. case DW_OP_breg22:
  21115. case DW_OP_breg23:
  21116. case DW_OP_breg24:
  21117. case DW_OP_breg25:
  21118. case DW_OP_breg26:
  21119. case DW_OP_breg27:
  21120. case DW_OP_breg28:
  21121. case DW_OP_breg29:
  21122. case DW_OP_breg30:
  21123. case DW_OP_breg31:
  21124. case DW_OP_regx:
  21125. case DW_OP_fbreg:
  21126. case DW_OP_piece:
  21127. case DW_OP_deref_size:
  21128. case DW_OP_xderef_size:
  21129. return valx1->v.val_int == valy1->v.val_int;
  21130. case DW_OP_skip:
  21131. case DW_OP_bra:
  21132. /* If splitting debug info, the use of DW_OP_GNU_addr_index
  21133. can cause irrelevant differences in dw_loc_addr. */
  21134. gcc_assert (valx1->val_class == dw_val_class_loc
  21135. && valy1->val_class == dw_val_class_loc
  21136. && (dwarf_split_debug_info
  21137. || x->dw_loc_addr == y->dw_loc_addr));
  21138. return valx1->v.val_loc->dw_loc_addr == valy1->v.val_loc->dw_loc_addr;
  21139. case DW_OP_implicit_value:
  21140. if (valx1->v.val_unsigned != valy1->v.val_unsigned
  21141. || valx2->val_class != valy2->val_class)
  21142. return false;
  21143. switch (valx2->val_class)
  21144. {
  21145. case dw_val_class_const:
  21146. return valx2->v.val_int == valy2->v.val_int;
  21147. case dw_val_class_vec:
  21148. return valx2->v.val_vec.elt_size == valy2->v.val_vec.elt_size
  21149. && valx2->v.val_vec.length == valy2->v.val_vec.length
  21150. && memcmp (valx2->v.val_vec.array, valy2->v.val_vec.array,
  21151. valx2->v.val_vec.elt_size
  21152. * valx2->v.val_vec.length) == 0;
  21153. case dw_val_class_const_double:
  21154. return valx2->v.val_double.low == valy2->v.val_double.low
  21155. && valx2->v.val_double.high == valy2->v.val_double.high;
  21156. case dw_val_class_wide_int:
  21157. return *valx2->v.val_wide == *valy2->v.val_wide;
  21158. case dw_val_class_addr:
  21159. return rtx_equal_p (valx2->v.val_addr, valy2->v.val_addr);
  21160. default:
  21161. gcc_unreachable ();
  21162. }
  21163. case DW_OP_bregx:
  21164. case DW_OP_bit_piece:
  21165. return valx1->v.val_int == valy1->v.val_int
  21166. && valx2->v.val_int == valy2->v.val_int;
  21167. case DW_OP_addr:
  21168. hash_addr:
  21169. return rtx_equal_p (valx1->v.val_addr, valy1->v.val_addr);
  21170. case DW_OP_GNU_addr_index:
  21171. case DW_OP_GNU_const_index:
  21172. {
  21173. rtx ax1 = valx1->val_entry->addr.rtl;
  21174. rtx ay1 = valy1->val_entry->addr.rtl;
  21175. return rtx_equal_p (ax1, ay1);
  21176. }
  21177. case DW_OP_GNU_implicit_pointer:
  21178. return valx1->val_class == dw_val_class_die_ref
  21179. && valx1->val_class == valy1->val_class
  21180. && valx1->v.val_die_ref.die == valy1->v.val_die_ref.die
  21181. && valx2->v.val_int == valy2->v.val_int;
  21182. case DW_OP_GNU_entry_value:
  21183. return compare_loc_operands (valx1->v.val_loc, valy1->v.val_loc);
  21184. case DW_OP_GNU_const_type:
  21185. if (valx1->v.val_die_ref.die != valy1->v.val_die_ref.die
  21186. || valx2->val_class != valy2->val_class)
  21187. return false;
  21188. switch (valx2->val_class)
  21189. {
  21190. case dw_val_class_const:
  21191. return valx2->v.val_int == valy2->v.val_int;
  21192. case dw_val_class_vec:
  21193. return valx2->v.val_vec.elt_size == valy2->v.val_vec.elt_size
  21194. && valx2->v.val_vec.length == valy2->v.val_vec.length
  21195. && memcmp (valx2->v.val_vec.array, valy2->v.val_vec.array,
  21196. valx2->v.val_vec.elt_size
  21197. * valx2->v.val_vec.length) == 0;
  21198. case dw_val_class_const_double:
  21199. return valx2->v.val_double.low == valy2->v.val_double.low
  21200. && valx2->v.val_double.high == valy2->v.val_double.high;
  21201. case dw_val_class_wide_int:
  21202. return *valx2->v.val_wide == *valy2->v.val_wide;
  21203. default:
  21204. gcc_unreachable ();
  21205. }
  21206. case DW_OP_GNU_regval_type:
  21207. case DW_OP_GNU_deref_type:
  21208. return valx1->v.val_int == valy1->v.val_int
  21209. && valx2->v.val_die_ref.die == valy2->v.val_die_ref.die;
  21210. case DW_OP_GNU_convert:
  21211. case DW_OP_GNU_reinterpret:
  21212. if (valx1->val_class != valy1->val_class)
  21213. return false;
  21214. if (valx1->val_class == dw_val_class_unsigned_const)
  21215. return valx1->v.val_unsigned == valy1->v.val_unsigned;
  21216. return valx1->v.val_die_ref.die == valy1->v.val_die_ref.die;
  21217. case DW_OP_GNU_parameter_ref:
  21218. return valx1->val_class == dw_val_class_die_ref
  21219. && valx1->val_class == valy1->val_class
  21220. && valx1->v.val_die_ref.die == valy1->v.val_die_ref.die;
  21221. default:
  21222. /* Other codes have no operands. */
  21223. return true;
  21224. }
  21225. }
  21226. /* Return true if DWARF location expressions X and Y are the same. */
  21227. static inline bool
  21228. compare_locs (dw_loc_descr_ref x, dw_loc_descr_ref y)
  21229. {
  21230. for (; x != NULL && y != NULL; x = x->dw_loc_next, y = y->dw_loc_next)
  21231. if (x->dw_loc_opc != y->dw_loc_opc
  21232. || x->dtprel != y->dtprel
  21233. || !compare_loc_operands (x, y))
  21234. break;
  21235. return x == NULL && y == NULL;
  21236. }
  21237. /* Hashtable helpers. */
  21238. struct loc_list_hasher : typed_noop_remove <dw_loc_list_struct>
  21239. {
  21240. typedef dw_loc_list_struct value_type;
  21241. typedef dw_loc_list_struct compare_type;
  21242. static inline hashval_t hash (const value_type *);
  21243. static inline bool equal (const value_type *, const compare_type *);
  21244. };
  21245. /* Return precomputed hash of location list X. */
  21246. inline hashval_t
  21247. loc_list_hasher::hash (const value_type *x)
  21248. {
  21249. return x->hash;
  21250. }
  21251. /* Return true if location lists A and B are the same. */
  21252. inline bool
  21253. loc_list_hasher::equal (const value_type *a, const compare_type *b)
  21254. {
  21255. if (a == b)
  21256. return 1;
  21257. if (a->hash != b->hash)
  21258. return 0;
  21259. for (; a != NULL && b != NULL; a = a->dw_loc_next, b = b->dw_loc_next)
  21260. if (strcmp (a->begin, b->begin) != 0
  21261. || strcmp (a->end, b->end) != 0
  21262. || (a->section == NULL) != (b->section == NULL)
  21263. || (a->section && strcmp (a->section, b->section) != 0)
  21264. || !compare_locs (a->expr, b->expr))
  21265. break;
  21266. return a == NULL && b == NULL;
  21267. }
  21268. typedef hash_table<loc_list_hasher> loc_list_hash_type;
  21269. /* Recursively optimize location lists referenced from DIE
  21270. children and share them whenever possible. */
  21271. static void
  21272. optimize_location_lists_1 (dw_die_ref die, loc_list_hash_type *htab)
  21273. {
  21274. dw_die_ref c;
  21275. dw_attr_ref a;
  21276. unsigned ix;
  21277. dw_loc_list_struct **slot;
  21278. FOR_EACH_VEC_SAFE_ELT (die->die_attr, ix, a)
  21279. if (AT_class (a) == dw_val_class_loc_list)
  21280. {
  21281. dw_loc_list_ref list = AT_loc_list (a);
  21282. /* TODO: perform some optimizations here, before hashing
  21283. it and storing into the hash table. */
  21284. hash_loc_list (list);
  21285. slot = htab->find_slot_with_hash (list, list->hash, INSERT);
  21286. if (*slot == NULL)
  21287. *slot = list;
  21288. else
  21289. a->dw_attr_val.v.val_loc_list = *slot;
  21290. }
  21291. FOR_EACH_CHILD (die, c, optimize_location_lists_1 (c, htab));
  21292. }
  21293. /* Recursively assign each location list a unique index into the debug_addr
  21294. section. */
  21295. static void
  21296. index_location_lists (dw_die_ref die)
  21297. {
  21298. dw_die_ref c;
  21299. dw_attr_ref a;
  21300. unsigned ix;
  21301. FOR_EACH_VEC_SAFE_ELT (die->die_attr, ix, a)
  21302. if (AT_class (a) == dw_val_class_loc_list)
  21303. {
  21304. dw_loc_list_ref list = AT_loc_list (a);
  21305. dw_loc_list_ref curr;
  21306. for (curr = list; curr != NULL; curr = curr->dw_loc_next)
  21307. {
  21308. /* Don't index an entry that has already been indexed
  21309. or won't be output. */
  21310. if (curr->begin_entry != NULL
  21311. || (strcmp (curr->begin, curr->end) == 0 && !curr->force))
  21312. continue;
  21313. curr->begin_entry
  21314. = add_addr_table_entry (xstrdup (curr->begin),
  21315. ate_kind_label);
  21316. }
  21317. }
  21318. FOR_EACH_CHILD (die, c, index_location_lists (c));
  21319. }
  21320. /* Optimize location lists referenced from DIE
  21321. children and share them whenever possible. */
  21322. static void
  21323. optimize_location_lists (dw_die_ref die)
  21324. {
  21325. loc_list_hash_type htab (500);
  21326. optimize_location_lists_1 (die, &htab);
  21327. }
  21328. /* Output stuff that dwarf requires at the end of every file,
  21329. and generate the DWARF-2 debugging info. */
  21330. static void
  21331. dwarf2out_finish (const char *filename)
  21332. {
  21333. limbo_die_node *node, *next_node;
  21334. comdat_type_node *ctnode;
  21335. unsigned int i;
  21336. dw_die_ref main_comp_unit_die;
  21337. /* PCH might result in DW_AT_producer string being restored from the
  21338. header compilation, so always fill it with empty string initially
  21339. and overwrite only here. */
  21340. dw_attr_ref producer = get_AT (comp_unit_die (), DW_AT_producer);
  21341. producer_string = gen_producer_string ();
  21342. producer->dw_attr_val.v.val_str->refcount--;
  21343. producer->dw_attr_val.v.val_str = find_AT_string (producer_string);
  21344. gen_scheduled_generic_parms_dies ();
  21345. gen_remaining_tmpl_value_param_die_attribute ();
  21346. /* Add the name for the main input file now. We delayed this from
  21347. dwarf2out_init to avoid complications with PCH.
  21348. For LTO produced units use a fixed artificial name to avoid
  21349. leaking tempfile names into the dwarf. */
  21350. if (!in_lto_p)
  21351. add_name_attribute (comp_unit_die (), remap_debug_filename (filename));
  21352. else
  21353. add_name_attribute (comp_unit_die (), "<artificial>");
  21354. if (!IS_ABSOLUTE_PATH (filename) || targetm.force_at_comp_dir)
  21355. add_comp_dir_attribute (comp_unit_die ());
  21356. else if (get_AT (comp_unit_die (), DW_AT_comp_dir) == NULL)
  21357. {
  21358. bool p = false;
  21359. file_table->traverse<bool *, file_table_relative_p> (&p);
  21360. if (p)
  21361. add_comp_dir_attribute (comp_unit_die ());
  21362. }
  21363. if (deferred_locations_list)
  21364. for (i = 0; i < deferred_locations_list->length (); i++)
  21365. {
  21366. add_location_or_const_value_attribute (
  21367. (*deferred_locations_list)[i].die,
  21368. (*deferred_locations_list)[i].variable,
  21369. false,
  21370. DW_AT_location);
  21371. }
  21372. /* Traverse the limbo die list, and add parent/child links. The only
  21373. dies without parents that should be here are concrete instances of
  21374. inline functions, and the comp_unit_die. We can ignore the comp_unit_die.
  21375. For concrete instances, we can get the parent die from the abstract
  21376. instance. */
  21377. for (node = limbo_die_list; node; node = next_node)
  21378. {
  21379. dw_die_ref die = node->die;
  21380. next_node = node->next;
  21381. if (die->die_parent == NULL)
  21382. {
  21383. dw_die_ref origin = get_AT_ref (die, DW_AT_abstract_origin);
  21384. if (origin && origin->die_parent)
  21385. add_child_die (origin->die_parent, die);
  21386. else if (is_cu_die (die))
  21387. ;
  21388. else if (seen_error ())
  21389. /* It's OK to be confused by errors in the input. */
  21390. add_child_die (comp_unit_die (), die);
  21391. else
  21392. {
  21393. /* In certain situations, the lexical block containing a
  21394. nested function can be optimized away, which results
  21395. in the nested function die being orphaned. Likewise
  21396. with the return type of that nested function. Force
  21397. this to be a child of the containing function.
  21398. It may happen that even the containing function got fully
  21399. inlined and optimized out. In that case we are lost and
  21400. assign the empty child. This should not be big issue as
  21401. the function is likely unreachable too. */
  21402. gcc_assert (node->created_for);
  21403. if (DECL_P (node->created_for))
  21404. origin = get_context_die (DECL_CONTEXT (node->created_for));
  21405. else if (TYPE_P (node->created_for))
  21406. origin = scope_die_for (node->created_for, comp_unit_die ());
  21407. else
  21408. origin = comp_unit_die ();
  21409. add_child_die (origin, die);
  21410. }
  21411. }
  21412. }
  21413. limbo_die_list = NULL;
  21414. #if ENABLE_ASSERT_CHECKING
  21415. {
  21416. dw_die_ref die = comp_unit_die (), c;
  21417. FOR_EACH_CHILD (die, c, gcc_assert (! c->die_mark));
  21418. }
  21419. #endif
  21420. resolve_addr (comp_unit_die ());
  21421. move_marked_base_types ();
  21422. for (node = deferred_asm_name; node; node = node->next)
  21423. {
  21424. tree decl = node->created_for;
  21425. /* When generating LTO bytecode we can not generate new assembler
  21426. names at this point and all important decls got theirs via
  21427. free-lang-data. */
  21428. if (((!flag_generate_lto && !flag_generate_offload)
  21429. || DECL_ASSEMBLER_NAME_SET_P (decl))
  21430. && DECL_ASSEMBLER_NAME (decl) != DECL_NAME (decl))
  21431. {
  21432. add_linkage_attr (node->die, decl);
  21433. move_linkage_attr (node->die);
  21434. }
  21435. }
  21436. deferred_asm_name = NULL;
  21437. /* Walk through the list of incomplete types again, trying once more to
  21438. emit full debugging info for them. */
  21439. retry_incomplete_types ();
  21440. if (flag_eliminate_unused_debug_types)
  21441. prune_unused_types ();
  21442. /* Generate separate COMDAT sections for type DIEs. */
  21443. if (use_debug_types)
  21444. {
  21445. break_out_comdat_types (comp_unit_die ());
  21446. /* Each new type_unit DIE was added to the limbo die list when created.
  21447. Since these have all been added to comdat_type_list, clear the
  21448. limbo die list. */
  21449. limbo_die_list = NULL;
  21450. /* For each new comdat type unit, copy declarations for incomplete
  21451. types to make the new unit self-contained (i.e., no direct
  21452. references to the main compile unit). */
  21453. for (ctnode = comdat_type_list; ctnode != NULL; ctnode = ctnode->next)
  21454. copy_decls_for_unworthy_types (ctnode->root_die);
  21455. copy_decls_for_unworthy_types (comp_unit_die ());
  21456. /* In the process of copying declarations from one unit to another,
  21457. we may have left some declarations behind that are no longer
  21458. referenced. Prune them. */
  21459. prune_unused_types ();
  21460. }
  21461. /* Generate separate CUs for each of the include files we've seen.
  21462. They will go into limbo_die_list. */
  21463. if (flag_eliminate_dwarf2_dups)
  21464. break_out_includes (comp_unit_die ());
  21465. /* Traverse the DIE's and add add sibling attributes to those DIE's
  21466. that have children. */
  21467. add_sibling_attributes (comp_unit_die ());
  21468. for (node = limbo_die_list; node; node = node->next)
  21469. add_sibling_attributes (node->die);
  21470. for (ctnode = comdat_type_list; ctnode != NULL; ctnode = ctnode->next)
  21471. add_sibling_attributes (ctnode->root_die);
  21472. /* When splitting DWARF info, we put some attributes in the
  21473. skeleton compile_unit DIE that remains in the .o, while
  21474. most attributes go in the DWO compile_unit_die. */
  21475. if (dwarf_split_debug_info)
  21476. main_comp_unit_die = gen_compile_unit_die (NULL);
  21477. else
  21478. main_comp_unit_die = comp_unit_die ();
  21479. /* Output a terminator label for the .text section. */
  21480. switch_to_section (text_section);
  21481. targetm.asm_out.internal_label (asm_out_file, TEXT_END_LABEL, 0);
  21482. if (cold_text_section)
  21483. {
  21484. switch_to_section (cold_text_section);
  21485. targetm.asm_out.internal_label (asm_out_file, COLD_END_LABEL, 0);
  21486. }
  21487. /* We can only use the low/high_pc attributes if all of the code was
  21488. in .text. */
  21489. if (!have_multiple_function_sections
  21490. || (dwarf_version < 3 && dwarf_strict))
  21491. {
  21492. /* Don't add if the CU has no associated code. */
  21493. if (text_section_used)
  21494. add_AT_low_high_pc (main_comp_unit_die, text_section_label,
  21495. text_end_label, true);
  21496. }
  21497. else
  21498. {
  21499. unsigned fde_idx;
  21500. dw_fde_ref fde;
  21501. bool range_list_added = false;
  21502. if (text_section_used)
  21503. add_ranges_by_labels (main_comp_unit_die, text_section_label,
  21504. text_end_label, &range_list_added, true);
  21505. if (cold_text_section_used)
  21506. add_ranges_by_labels (main_comp_unit_die, cold_text_section_label,
  21507. cold_end_label, &range_list_added, true);
  21508. FOR_EACH_VEC_ELT (*fde_vec, fde_idx, fde)
  21509. {
  21510. if (DECL_IGNORED_P (fde->decl))
  21511. continue;
  21512. if (!fde->in_std_section)
  21513. add_ranges_by_labels (main_comp_unit_die, fde->dw_fde_begin,
  21514. fde->dw_fde_end, &range_list_added,
  21515. true);
  21516. if (fde->dw_fde_second_begin && !fde->second_in_std_section)
  21517. add_ranges_by_labels (main_comp_unit_die, fde->dw_fde_second_begin,
  21518. fde->dw_fde_second_end, &range_list_added,
  21519. true);
  21520. }
  21521. if (range_list_added)
  21522. {
  21523. /* We need to give .debug_loc and .debug_ranges an appropriate
  21524. "base address". Use zero so that these addresses become
  21525. absolute. Historically, we've emitted the unexpected
  21526. DW_AT_entry_pc instead of DW_AT_low_pc for this purpose.
  21527. Emit both to give time for other tools to adapt. */
  21528. add_AT_addr (main_comp_unit_die, DW_AT_low_pc, const0_rtx, true);
  21529. if (! dwarf_strict && dwarf_version < 4)
  21530. add_AT_addr (main_comp_unit_die, DW_AT_entry_pc, const0_rtx, true);
  21531. add_ranges (NULL);
  21532. }
  21533. }
  21534. if (debug_info_level >= DINFO_LEVEL_TERSE)
  21535. add_AT_lineptr (main_comp_unit_die, DW_AT_stmt_list,
  21536. debug_line_section_label);
  21537. if (have_macinfo)
  21538. add_AT_macptr (comp_unit_die (),
  21539. dwarf_strict ? DW_AT_macro_info : DW_AT_GNU_macros,
  21540. macinfo_section_label);
  21541. if (dwarf_split_debug_info)
  21542. {
  21543. /* optimize_location_lists calculates the size of the lists,
  21544. so index them first, and assign indices to the entries.
  21545. Although optimize_location_lists will remove entries from
  21546. the table, it only does so for duplicates, and therefore
  21547. only reduces ref_counts to 1. */
  21548. index_location_lists (comp_unit_die ());
  21549. if (addr_index_table != NULL)
  21550. {
  21551. unsigned int index = 0;
  21552. addr_index_table
  21553. ->traverse_noresize<unsigned int *, index_addr_table_entry>
  21554. (&index);
  21555. }
  21556. }
  21557. if (have_location_lists)
  21558. optimize_location_lists (comp_unit_die ());
  21559. save_macinfo_strings ();
  21560. if (dwarf_split_debug_info)
  21561. {
  21562. unsigned int index = 0;
  21563. /* Add attributes common to skeleton compile_units and
  21564. type_units. Because these attributes include strings, it
  21565. must be done before freezing the string table. Top-level
  21566. skeleton die attrs are added when the skeleton type unit is
  21567. created, so ensure it is created by this point. */
  21568. add_top_level_skeleton_die_attrs (main_comp_unit_die);
  21569. debug_str_hash->traverse_noresize<unsigned int *, index_string> (&index);
  21570. }
  21571. /* Output all of the compilation units. We put the main one last so that
  21572. the offsets are available to output_pubnames. */
  21573. for (node = limbo_die_list; node; node = node->next)
  21574. output_comp_unit (node->die, 0);
  21575. hash_table<comdat_type_hasher> comdat_type_table (100);
  21576. for (ctnode = comdat_type_list; ctnode != NULL; ctnode = ctnode->next)
  21577. {
  21578. comdat_type_node **slot = comdat_type_table.find_slot (ctnode, INSERT);
  21579. /* Don't output duplicate types. */
  21580. if (*slot != HTAB_EMPTY_ENTRY)
  21581. continue;
  21582. /* Add a pointer to the line table for the main compilation unit
  21583. so that the debugger can make sense of DW_AT_decl_file
  21584. attributes. */
  21585. if (debug_info_level >= DINFO_LEVEL_TERSE)
  21586. add_AT_lineptr (ctnode->root_die, DW_AT_stmt_list,
  21587. (!dwarf_split_debug_info
  21588. ? debug_line_section_label
  21589. : debug_skeleton_line_section_label));
  21590. output_comdat_type_unit (ctnode);
  21591. *slot = ctnode;
  21592. }
  21593. /* The AT_pubnames attribute needs to go in all skeleton dies, including
  21594. both the main_cu and all skeleton TUs. Making this call unconditional
  21595. would end up either adding a second copy of the AT_pubnames attribute, or
  21596. requiring a special case in add_top_level_skeleton_die_attrs. */
  21597. if (!dwarf_split_debug_info)
  21598. add_AT_pubnames (comp_unit_die ());
  21599. if (dwarf_split_debug_info)
  21600. {
  21601. int mark;
  21602. unsigned char checksum[16];
  21603. struct md5_ctx ctx;
  21604. /* Compute a checksum of the comp_unit to use as the dwo_id. */
  21605. md5_init_ctx (&ctx);
  21606. mark = 0;
  21607. die_checksum (comp_unit_die (), &ctx, &mark);
  21608. unmark_all_dies (comp_unit_die ());
  21609. md5_finish_ctx (&ctx, checksum);
  21610. /* Use the first 8 bytes of the checksum as the dwo_id,
  21611. and add it to both comp-unit DIEs. */
  21612. add_AT_data8 (main_comp_unit_die, DW_AT_GNU_dwo_id, checksum);
  21613. add_AT_data8 (comp_unit_die (), DW_AT_GNU_dwo_id, checksum);
  21614. /* Add the base offset of the ranges table to the skeleton
  21615. comp-unit DIE. */
  21616. if (ranges_table_in_use)
  21617. add_AT_lineptr (main_comp_unit_die, DW_AT_GNU_ranges_base,
  21618. ranges_section_label);
  21619. switch_to_section (debug_addr_section);
  21620. ASM_OUTPUT_LABEL (asm_out_file, debug_addr_section_label);
  21621. output_addr_table ();
  21622. }
  21623. /* Output the main compilation unit if non-empty or if .debug_macinfo
  21624. or .debug_macro will be emitted. */
  21625. output_comp_unit (comp_unit_die (), have_macinfo);
  21626. if (dwarf_split_debug_info && info_section_emitted)
  21627. output_skeleton_debug_sections (main_comp_unit_die);
  21628. /* Output the abbreviation table. */
  21629. if (abbrev_die_table_in_use != 1)
  21630. {
  21631. switch_to_section (debug_abbrev_section);
  21632. ASM_OUTPUT_LABEL (asm_out_file, abbrev_section_label);
  21633. output_abbrev_section ();
  21634. }
  21635. /* Output location list section if necessary. */
  21636. if (have_location_lists)
  21637. {
  21638. /* Output the location lists info. */
  21639. switch_to_section (debug_loc_section);
  21640. ASM_OUTPUT_LABEL (asm_out_file, loc_section_label);
  21641. output_location_lists (comp_unit_die ());
  21642. }
  21643. output_pubtables ();
  21644. /* Output the address range information if a CU (.debug_info section)
  21645. was emitted. We output an empty table even if we had no functions
  21646. to put in it. This because the consumer has no way to tell the
  21647. difference between an empty table that we omitted and failure to
  21648. generate a table that would have contained data. */
  21649. if (info_section_emitted)
  21650. {
  21651. unsigned long aranges_length = size_of_aranges ();
  21652. switch_to_section (debug_aranges_section);
  21653. output_aranges (aranges_length);
  21654. }
  21655. /* Output ranges section if necessary. */
  21656. if (ranges_table_in_use)
  21657. {
  21658. switch_to_section (debug_ranges_section);
  21659. ASM_OUTPUT_LABEL (asm_out_file, ranges_section_label);
  21660. output_ranges ();
  21661. }
  21662. /* Have to end the macro section. */
  21663. if (have_macinfo)
  21664. {
  21665. switch_to_section (debug_macinfo_section);
  21666. ASM_OUTPUT_LABEL (asm_out_file, macinfo_section_label);
  21667. output_macinfo ();
  21668. dw2_asm_output_data (1, 0, "End compilation unit");
  21669. }
  21670. /* Output the source line correspondence table. We must do this
  21671. even if there is no line information. Otherwise, on an empty
  21672. translation unit, we will generate a present, but empty,
  21673. .debug_info section. IRIX 6.5 `nm' will then complain when
  21674. examining the file. This is done late so that any filenames
  21675. used by the debug_info section are marked as 'used'. */
  21676. switch_to_section (debug_line_section);
  21677. ASM_OUTPUT_LABEL (asm_out_file, debug_line_section_label);
  21678. if (! DWARF2_ASM_LINE_DEBUG_INFO)
  21679. output_line_info (false);
  21680. if (dwarf_split_debug_info && info_section_emitted)
  21681. {
  21682. switch_to_section (debug_skeleton_line_section);
  21683. ASM_OUTPUT_LABEL (asm_out_file, debug_skeleton_line_section_label);
  21684. output_line_info (true);
  21685. }
  21686. /* If we emitted any indirect strings, output the string table too. */
  21687. if (debug_str_hash || skeleton_debug_str_hash)
  21688. output_indirect_strings ();
  21689. }
  21690. /* Reset all state within dwarf2out.c so that we can rerun the compiler
  21691. within the same process. For use by toplev::finalize. */
  21692. void
  21693. dwarf2out_c_finalize (void)
  21694. {
  21695. last_var_location_insn = NULL;
  21696. cached_next_real_insn = NULL;
  21697. used_rtx_array = NULL;
  21698. incomplete_types = NULL;
  21699. decl_scope_table = NULL;
  21700. debug_info_section = NULL;
  21701. debug_skeleton_info_section = NULL;
  21702. debug_abbrev_section = NULL;
  21703. debug_skeleton_abbrev_section = NULL;
  21704. debug_aranges_section = NULL;
  21705. debug_addr_section = NULL;
  21706. debug_macinfo_section = NULL;
  21707. debug_line_section = NULL;
  21708. debug_skeleton_line_section = NULL;
  21709. debug_loc_section = NULL;
  21710. debug_pubnames_section = NULL;
  21711. debug_pubtypes_section = NULL;
  21712. debug_str_section = NULL;
  21713. debug_str_dwo_section = NULL;
  21714. debug_str_offsets_section = NULL;
  21715. debug_ranges_section = NULL;
  21716. debug_frame_section = NULL;
  21717. fde_vec = NULL;
  21718. debug_str_hash = NULL;
  21719. skeleton_debug_str_hash = NULL;
  21720. dw2_string_counter = 0;
  21721. have_multiple_function_sections = false;
  21722. text_section_used = false;
  21723. cold_text_section_used = false;
  21724. cold_text_section = NULL;
  21725. current_unit_personality = NULL;
  21726. deferred_locations_list = NULL;
  21727. next_die_offset = 0;
  21728. single_comp_unit_die = NULL;
  21729. comdat_type_list = NULL;
  21730. limbo_die_list = NULL;
  21731. deferred_asm_name = NULL;
  21732. file_table = NULL;
  21733. decl_die_table = NULL;
  21734. common_block_die_table = NULL;
  21735. decl_loc_table = NULL;
  21736. call_arg_locations = NULL;
  21737. call_arg_loc_last = NULL;
  21738. call_site_count = -1;
  21739. tail_call_site_count = -1;
  21740. //block_map = NULL;
  21741. cached_dw_loc_list_table = NULL;
  21742. abbrev_die_table = NULL;
  21743. abbrev_die_table_allocated = 0;
  21744. abbrev_die_table_in_use = 0;
  21745. line_info_label_num = 0;
  21746. cur_line_info_table = NULL;
  21747. text_section_line_info = NULL;
  21748. cold_text_section_line_info = NULL;
  21749. separate_line_info = NULL;
  21750. info_section_emitted = false;
  21751. pubname_table = NULL;
  21752. pubtype_table = NULL;
  21753. macinfo_table = NULL;
  21754. ranges_table = NULL;
  21755. ranges_table_allocated = 0;
  21756. ranges_table_in_use = 0;
  21757. ranges_by_label = 0;
  21758. ranges_by_label_allocated = 0;
  21759. ranges_by_label_in_use = 0;
  21760. have_location_lists = false;
  21761. loclabel_num = 0;
  21762. poc_label_num = 0;
  21763. last_emitted_file = NULL;
  21764. label_num = 0;
  21765. file_table_last_lookup = NULL;
  21766. tmpl_value_parm_die_table = NULL;
  21767. generic_type_instances = NULL;
  21768. frame_pointer_fb_offset = 0;
  21769. frame_pointer_fb_offset_valid = false;
  21770. base_types.release ();
  21771. XDELETEVEC (producer_string);
  21772. producer_string = NULL;
  21773. }
  21774. #include "gt-dwarf2out.h"