breakpoint.c 449 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506950795089509951095119512951395149515951695179518951995209521952295239524952595269527952895299530953195329533953495359536953795389539954095419542954395449545954695479548954995509551955295539554955595569557955895599560956195629563956495659566956795689569957095719572957395749575957695779578957995809581958295839584958595869587958895899590959195929593959495959596959795989599960096019602960396049605960696079608960996109611961296139614961596169617961896199620962196229623962496259626962796289629963096319632963396349635963696379638963996409641964296439644964596469647964896499650965196529653965496559656965796589659966096619662966396649665966696679668966996709671967296739674967596769677967896799680968196829683968496859686968796889689969096919692969396949695969696979698969997009701970297039704970597069707970897099710971197129713971497159716971797189719972097219722972397249725972697279728972997309731973297339734973597369737973897399740974197429743974497459746974797489749975097519752975397549755975697579758975997609761976297639764976597669767976897699770977197729773977497759776977797789779978097819782978397849785978697879788978997909791979297939794979597969797979897999800980198029803980498059806980798089809981098119812981398149815981698179818981998209821982298239824982598269827982898299830983198329833983498359836983798389839984098419842984398449845984698479848984998509851985298539854985598569857985898599860986198629863986498659866986798689869987098719872987398749875987698779878987998809881988298839884988598869887988898899890989198929893989498959896989798989899990099019902990399049905990699079908990999109911991299139914991599169917991899199920992199229923992499259926992799289929993099319932993399349935993699379938993999409941994299439944994599469947994899499950995199529953995499559956995799589959996099619962996399649965996699679968996999709971997299739974997599769977997899799980998199829983998499859986998799889989999099919992999399949995999699979998999910000100011000210003100041000510006100071000810009100101001110012100131001410015100161001710018100191002010021100221002310024100251002610027100281002910030100311003210033100341003510036100371003810039100401004110042100431004410045100461004710048100491005010051100521005310054100551005610057100581005910060100611006210063100641006510066100671006810069100701007110072100731007410075100761007710078100791008010081100821008310084100851008610087100881008910090100911009210093100941009510096100971009810099101001010110102101031010410105101061010710108101091011010111101121011310114101151011610117101181011910120101211012210123101241012510126101271012810129101301013110132101331013410135101361013710138101391014010141101421014310144101451014610147101481014910150101511015210153101541015510156101571015810159101601016110162101631016410165101661016710168101691017010171101721017310174101751017610177101781017910180101811018210183101841018510186101871018810189101901019110192101931019410195101961019710198101991020010201102021020310204102051020610207102081020910210102111021210213102141021510216102171021810219102201022110222102231022410225102261022710228102291023010231102321023310234102351023610237102381023910240102411024210243102441024510246102471024810249102501025110252102531025410255102561025710258102591026010261102621026310264102651026610267102681026910270102711027210273102741027510276102771027810279102801028110282102831028410285102861028710288102891029010291102921029310294102951029610297102981029910300103011030210303103041030510306103071030810309103101031110312103131031410315103161031710318103191032010321103221032310324103251032610327103281032910330103311033210333103341033510336103371033810339103401034110342103431034410345103461034710348103491035010351103521035310354103551035610357103581035910360103611036210363103641036510366103671036810369103701037110372103731037410375103761037710378103791038010381103821038310384103851038610387103881038910390103911039210393103941039510396103971039810399104001040110402104031040410405104061040710408104091041010411104121041310414104151041610417104181041910420104211042210423104241042510426104271042810429104301043110432104331043410435104361043710438104391044010441104421044310444104451044610447104481044910450104511045210453104541045510456104571045810459104601046110462104631046410465104661046710468104691047010471104721047310474104751047610477104781047910480104811048210483104841048510486104871048810489104901049110492104931049410495104961049710498104991050010501105021050310504105051050610507105081050910510105111051210513105141051510516105171051810519105201052110522105231052410525105261052710528105291053010531105321053310534105351053610537105381053910540105411054210543105441054510546105471054810549105501055110552105531055410555105561055710558105591056010561105621056310564105651056610567105681056910570105711057210573105741057510576105771057810579105801058110582105831058410585105861058710588105891059010591105921059310594105951059610597105981059910600106011060210603106041060510606106071060810609106101061110612106131061410615106161061710618106191062010621106221062310624106251062610627106281062910630106311063210633106341063510636106371063810639106401064110642106431064410645106461064710648106491065010651106521065310654106551065610657106581065910660106611066210663106641066510666106671066810669106701067110672106731067410675106761067710678106791068010681106821068310684106851068610687106881068910690106911069210693106941069510696106971069810699107001070110702107031070410705107061070710708107091071010711107121071310714107151071610717107181071910720107211072210723107241072510726107271072810729107301073110732107331073410735107361073710738107391074010741107421074310744107451074610747107481074910750107511075210753107541075510756107571075810759107601076110762107631076410765107661076710768107691077010771107721077310774107751077610777107781077910780107811078210783107841078510786107871078810789107901079110792107931079410795107961079710798107991080010801108021080310804108051080610807108081080910810108111081210813108141081510816108171081810819108201082110822108231082410825108261082710828108291083010831108321083310834108351083610837108381083910840108411084210843108441084510846108471084810849108501085110852108531085410855108561085710858108591086010861108621086310864108651086610867108681086910870108711087210873108741087510876108771087810879108801088110882108831088410885108861088710888108891089010891108921089310894108951089610897108981089910900109011090210903109041090510906109071090810909109101091110912109131091410915109161091710918109191092010921109221092310924109251092610927109281092910930109311093210933109341093510936109371093810939109401094110942109431094410945109461094710948109491095010951109521095310954109551095610957109581095910960109611096210963109641096510966109671096810969109701097110972109731097410975109761097710978109791098010981109821098310984109851098610987109881098910990109911099210993109941099510996109971099810999110001100111002110031100411005110061100711008110091101011011110121101311014110151101611017110181101911020110211102211023110241102511026110271102811029110301103111032110331103411035110361103711038110391104011041110421104311044110451104611047110481104911050110511105211053110541105511056110571105811059110601106111062110631106411065110661106711068110691107011071110721107311074110751107611077110781107911080110811108211083110841108511086110871108811089110901109111092110931109411095110961109711098110991110011101111021110311104111051110611107111081110911110111111111211113111141111511116111171111811119111201112111122111231112411125111261112711128111291113011131111321113311134111351113611137111381113911140111411114211143111441114511146111471114811149111501115111152111531115411155111561115711158111591116011161111621116311164111651116611167111681116911170111711117211173111741117511176111771117811179111801118111182111831118411185111861118711188111891119011191111921119311194111951119611197111981119911200112011120211203112041120511206112071120811209112101121111212112131121411215112161121711218112191122011221112221122311224112251122611227112281122911230112311123211233112341123511236112371123811239112401124111242112431124411245112461124711248112491125011251112521125311254112551125611257112581125911260112611126211263112641126511266112671126811269112701127111272112731127411275112761127711278112791128011281112821128311284112851128611287112881128911290112911129211293112941129511296112971129811299113001130111302113031130411305113061130711308113091131011311113121131311314113151131611317113181131911320113211132211323113241132511326113271132811329113301133111332113331133411335113361133711338113391134011341113421134311344113451134611347113481134911350113511135211353113541135511356113571135811359113601136111362113631136411365113661136711368113691137011371113721137311374113751137611377113781137911380113811138211383113841138511386113871138811389113901139111392113931139411395113961139711398113991140011401114021140311404114051140611407114081140911410114111141211413114141141511416114171141811419114201142111422114231142411425114261142711428114291143011431114321143311434114351143611437114381143911440114411144211443114441144511446114471144811449114501145111452114531145411455114561145711458114591146011461114621146311464114651146611467114681146911470114711147211473114741147511476114771147811479114801148111482114831148411485114861148711488114891149011491114921149311494114951149611497114981149911500115011150211503115041150511506115071150811509115101151111512115131151411515115161151711518115191152011521115221152311524115251152611527115281152911530115311153211533115341153511536115371153811539115401154111542115431154411545115461154711548115491155011551115521155311554115551155611557115581155911560115611156211563115641156511566115671156811569115701157111572115731157411575115761157711578115791158011581115821158311584115851158611587115881158911590115911159211593115941159511596115971159811599116001160111602116031160411605116061160711608116091161011611116121161311614116151161611617116181161911620116211162211623116241162511626116271162811629116301163111632116331163411635116361163711638116391164011641116421164311644116451164611647116481164911650116511165211653116541165511656116571165811659116601166111662116631166411665116661166711668116691167011671116721167311674116751167611677116781167911680116811168211683116841168511686116871168811689116901169111692116931169411695116961169711698116991170011701117021170311704117051170611707117081170911710117111171211713117141171511716117171171811719117201172111722117231172411725117261172711728117291173011731117321173311734117351173611737117381173911740117411174211743117441174511746117471174811749117501175111752117531175411755117561175711758117591176011761117621176311764117651176611767117681176911770117711177211773117741177511776117771177811779117801178111782117831178411785117861178711788117891179011791117921179311794117951179611797117981179911800118011180211803118041180511806118071180811809118101181111812118131181411815118161181711818118191182011821118221182311824118251182611827118281182911830118311183211833118341183511836118371183811839118401184111842118431184411845118461184711848118491185011851118521185311854118551185611857118581185911860118611186211863118641186511866118671186811869118701187111872118731187411875118761187711878118791188011881118821188311884118851188611887118881188911890118911189211893118941189511896118971189811899119001190111902119031190411905119061190711908119091191011911119121191311914119151191611917119181191911920119211192211923119241192511926119271192811929119301193111932119331193411935119361193711938119391194011941119421194311944119451194611947119481194911950119511195211953119541195511956119571195811959119601196111962119631196411965119661196711968119691197011971119721197311974119751197611977119781197911980119811198211983119841198511986119871198811989119901199111992119931199411995119961199711998119991200012001120021200312004120051200612007120081200912010120111201212013120141201512016120171201812019120201202112022120231202412025120261202712028120291203012031120321203312034120351203612037120381203912040120411204212043120441204512046120471204812049120501205112052120531205412055120561205712058120591206012061120621206312064120651206612067120681206912070120711207212073120741207512076120771207812079120801208112082120831208412085120861208712088120891209012091120921209312094120951209612097120981209912100121011210212103121041210512106121071210812109121101211112112121131211412115121161211712118121191212012121121221212312124121251212612127121281212912130121311213212133121341213512136121371213812139121401214112142121431214412145121461214712148121491215012151121521215312154121551215612157121581215912160121611216212163121641216512166121671216812169121701217112172121731217412175121761217712178121791218012181121821218312184121851218612187121881218912190121911219212193121941219512196121971219812199122001220112202122031220412205122061220712208122091221012211122121221312214122151221612217122181221912220122211222212223122241222512226122271222812229122301223112232122331223412235122361223712238122391224012241122421224312244122451224612247122481224912250122511225212253122541225512256122571225812259122601226112262122631226412265122661226712268122691227012271122721227312274122751227612277122781227912280122811228212283122841228512286122871228812289122901229112292122931229412295122961229712298122991230012301123021230312304123051230612307123081230912310123111231212313123141231512316123171231812319123201232112322123231232412325123261232712328123291233012331123321233312334123351233612337123381233912340123411234212343123441234512346123471234812349123501235112352123531235412355123561235712358123591236012361123621236312364123651236612367123681236912370123711237212373123741237512376123771237812379123801238112382123831238412385123861238712388123891239012391123921239312394123951239612397123981239912400124011240212403124041240512406124071240812409124101241112412124131241412415124161241712418124191242012421124221242312424124251242612427124281242912430124311243212433124341243512436124371243812439124401244112442124431244412445124461244712448124491245012451124521245312454124551245612457124581245912460124611246212463124641246512466124671246812469124701247112472124731247412475124761247712478124791248012481124821248312484124851248612487124881248912490124911249212493124941249512496124971249812499125001250112502125031250412505125061250712508125091251012511125121251312514125151251612517125181251912520125211252212523125241252512526125271252812529125301253112532125331253412535125361253712538125391254012541125421254312544125451254612547125481254912550125511255212553125541255512556125571255812559125601256112562125631256412565125661256712568125691257012571125721257312574125751257612577125781257912580125811258212583125841258512586125871258812589125901259112592125931259412595125961259712598125991260012601126021260312604126051260612607126081260912610126111261212613126141261512616126171261812619126201262112622126231262412625126261262712628126291263012631126321263312634126351263612637126381263912640126411264212643126441264512646126471264812649126501265112652126531265412655126561265712658126591266012661126621266312664126651266612667126681266912670126711267212673126741267512676126771267812679126801268112682126831268412685126861268712688126891269012691126921269312694126951269612697126981269912700127011270212703127041270512706127071270812709127101271112712127131271412715127161271712718127191272012721127221272312724127251272612727127281272912730127311273212733127341273512736127371273812739127401274112742127431274412745127461274712748127491275012751127521275312754127551275612757127581275912760127611276212763127641276512766127671276812769127701277112772127731277412775127761277712778127791278012781127821278312784127851278612787127881278912790127911279212793127941279512796127971279812799128001280112802128031280412805128061280712808128091281012811128121281312814128151281612817128181281912820128211282212823128241282512826128271282812829128301283112832128331283412835128361283712838128391284012841128421284312844128451284612847128481284912850128511285212853128541285512856128571285812859128601286112862128631286412865128661286712868128691287012871128721287312874128751287612877128781287912880128811288212883128841288512886128871288812889128901289112892128931289412895128961289712898128991290012901129021290312904129051290612907129081290912910129111291212913129141291512916129171291812919129201292112922129231292412925129261292712928129291293012931129321293312934129351293612937129381293912940129411294212943129441294512946129471294812949129501295112952129531295412955129561295712958129591296012961129621296312964129651296612967129681296912970129711297212973129741297512976129771297812979129801298112982129831298412985129861298712988129891299012991129921299312994129951299612997129981299913000130011300213003130041300513006130071300813009130101301113012130131301413015130161301713018130191302013021130221302313024130251302613027130281302913030130311303213033130341303513036130371303813039130401304113042130431304413045130461304713048130491305013051130521305313054130551305613057130581305913060130611306213063130641306513066130671306813069130701307113072130731307413075130761307713078130791308013081130821308313084130851308613087130881308913090130911309213093130941309513096130971309813099131001310113102131031310413105131061310713108131091311013111131121311313114131151311613117131181311913120131211312213123131241312513126131271312813129131301313113132131331313413135131361313713138131391314013141131421314313144131451314613147131481314913150131511315213153131541315513156131571315813159131601316113162131631316413165131661316713168131691317013171131721317313174131751317613177131781317913180131811318213183131841318513186131871318813189131901319113192131931319413195131961319713198131991320013201132021320313204132051320613207132081320913210132111321213213132141321513216132171321813219132201322113222132231322413225132261322713228132291323013231132321323313234132351323613237132381323913240132411324213243132441324513246132471324813249132501325113252132531325413255132561325713258132591326013261132621326313264132651326613267132681326913270132711327213273132741327513276132771327813279132801328113282132831328413285132861328713288132891329013291132921329313294132951329613297132981329913300133011330213303133041330513306133071330813309133101331113312133131331413315133161331713318133191332013321133221332313324133251332613327133281332913330133311333213333133341333513336133371333813339133401334113342133431334413345133461334713348133491335013351133521335313354133551335613357133581335913360133611336213363133641336513366133671336813369133701337113372133731337413375133761337713378133791338013381133821338313384133851338613387133881338913390133911339213393133941339513396133971339813399134001340113402134031340413405134061340713408134091341013411134121341313414134151341613417134181341913420134211342213423134241342513426134271342813429134301343113432134331343413435134361343713438134391344013441134421344313444134451344613447134481344913450134511345213453134541345513456134571345813459134601346113462134631346413465134661346713468134691347013471134721347313474134751347613477134781347913480134811348213483134841348513486134871348813489134901349113492134931349413495134961349713498134991350013501135021350313504135051350613507135081350913510135111351213513135141351513516135171351813519135201352113522135231352413525135261352713528135291353013531135321353313534135351353613537135381353913540135411354213543135441354513546135471354813549135501355113552135531355413555135561355713558135591356013561135621356313564135651356613567135681356913570135711357213573135741357513576135771357813579135801358113582135831358413585135861358713588135891359013591135921359313594135951359613597135981359913600136011360213603136041360513606136071360813609136101361113612136131361413615136161361713618136191362013621136221362313624136251362613627136281362913630136311363213633136341363513636136371363813639136401364113642136431364413645136461364713648136491365013651136521365313654136551365613657136581365913660136611366213663136641366513666136671366813669136701367113672136731367413675136761367713678136791368013681136821368313684136851368613687136881368913690136911369213693136941369513696136971369813699137001370113702137031370413705137061370713708137091371013711137121371313714137151371613717137181371913720137211372213723137241372513726137271372813729137301373113732137331373413735137361373713738137391374013741137421374313744137451374613747137481374913750137511375213753137541375513756137571375813759137601376113762137631376413765137661376713768137691377013771137721377313774137751377613777137781377913780137811378213783137841378513786137871378813789137901379113792137931379413795137961379713798137991380013801138021380313804138051380613807138081380913810138111381213813138141381513816138171381813819138201382113822138231382413825138261382713828138291383013831138321383313834138351383613837138381383913840138411384213843138441384513846138471384813849138501385113852138531385413855138561385713858138591386013861138621386313864138651386613867138681386913870138711387213873138741387513876138771387813879138801388113882138831388413885138861388713888138891389013891138921389313894138951389613897138981389913900139011390213903139041390513906139071390813909139101391113912139131391413915139161391713918139191392013921139221392313924139251392613927139281392913930139311393213933139341393513936139371393813939139401394113942139431394413945139461394713948139491395013951139521395313954139551395613957139581395913960139611396213963139641396513966139671396813969139701397113972139731397413975139761397713978139791398013981139821398313984139851398613987139881398913990139911399213993139941399513996139971399813999140001400114002140031400414005140061400714008140091401014011140121401314014140151401614017140181401914020140211402214023140241402514026140271402814029140301403114032140331403414035140361403714038140391404014041140421404314044140451404614047140481404914050140511405214053140541405514056140571405814059140601406114062140631406414065140661406714068140691407014071140721407314074140751407614077140781407914080140811408214083140841408514086140871408814089140901409114092140931409414095140961409714098140991410014101141021410314104141051410614107141081410914110141111411214113141141411514116141171411814119141201412114122141231412414125141261412714128141291413014131141321413314134141351413614137141381413914140141411414214143141441414514146141471414814149141501415114152141531415414155141561415714158141591416014161141621416314164141651416614167141681416914170141711417214173141741417514176141771417814179141801418114182141831418414185141861418714188141891419014191141921419314194141951419614197141981419914200142011420214203142041420514206142071420814209142101421114212142131421414215142161421714218142191422014221142221422314224142251422614227142281422914230142311423214233142341423514236142371423814239142401424114242142431424414245142461424714248142491425014251142521425314254142551425614257142581425914260142611426214263142641426514266142671426814269142701427114272142731427414275142761427714278142791428014281142821428314284142851428614287142881428914290142911429214293142941429514296142971429814299143001430114302143031430414305143061430714308143091431014311143121431314314143151431614317143181431914320143211432214323143241432514326143271432814329143301433114332143331433414335143361433714338143391434014341143421434314344143451434614347143481434914350143511435214353143541435514356143571435814359143601436114362143631436414365143661436714368143691437014371143721437314374143751437614377143781437914380143811438214383143841438514386143871438814389143901439114392143931439414395143961439714398143991440014401144021440314404144051440614407144081440914410144111441214413144141441514416144171441814419144201442114422144231442414425144261442714428144291443014431144321443314434144351443614437144381443914440144411444214443144441444514446144471444814449144501445114452144531445414455144561445714458144591446014461144621446314464144651446614467144681446914470144711447214473144741447514476144771447814479144801448114482144831448414485144861448714488144891449014491144921449314494144951449614497144981449914500145011450214503145041450514506145071450814509145101451114512145131451414515145161451714518145191452014521145221452314524145251452614527145281452914530145311453214533145341453514536145371453814539145401454114542145431454414545145461454714548145491455014551145521455314554145551455614557145581455914560145611456214563145641456514566145671456814569145701457114572145731457414575145761457714578145791458014581145821458314584145851458614587145881458914590145911459214593145941459514596145971459814599146001460114602146031460414605146061460714608146091461014611146121461314614146151461614617146181461914620146211462214623146241462514626146271462814629146301463114632146331463414635146361463714638146391464014641146421464314644146451464614647146481464914650146511465214653146541465514656146571465814659146601466114662146631466414665146661466714668146691467014671146721467314674146751467614677146781467914680146811468214683146841468514686146871468814689146901469114692146931469414695146961469714698146991470014701147021470314704147051470614707147081470914710147111471214713147141471514716147171471814719147201472114722147231472414725147261472714728147291473014731147321473314734147351473614737147381473914740147411474214743147441474514746147471474814749147501475114752147531475414755147561475714758147591476014761147621476314764147651476614767147681476914770147711477214773147741477514776147771477814779147801478114782147831478414785147861478714788147891479014791147921479314794147951479614797147981479914800148011480214803148041480514806148071480814809148101481114812148131481414815148161481714818148191482014821148221482314824148251482614827148281482914830148311483214833148341483514836148371483814839148401484114842148431484414845148461484714848148491485014851148521485314854148551485614857148581485914860148611486214863148641486514866148671486814869148701487114872148731487414875148761487714878148791488014881148821488314884148851488614887148881488914890148911489214893148941489514896148971489814899149001490114902149031490414905149061490714908149091491014911149121491314914149151491614917149181491914920149211492214923149241492514926149271492814929149301493114932149331493414935149361493714938149391494014941149421494314944149451494614947149481494914950149511495214953149541495514956149571495814959149601496114962149631496414965149661496714968149691497014971149721497314974149751497614977149781497914980149811498214983149841498514986149871498814989149901499114992149931499414995149961499714998149991500015001150021500315004150051500615007150081500915010150111501215013150141501515016150171501815019150201502115022150231502415025150261502715028150291503015031150321503315034150351503615037150381503915040150411504215043150441504515046150471504815049150501505115052150531505415055150561505715058150591506015061150621506315064150651506615067150681506915070150711507215073150741507515076150771507815079150801508115082150831508415085150861508715088150891509015091150921509315094150951509615097150981509915100151011510215103151041510515106151071510815109151101511115112151131511415115151161511715118151191512015121151221512315124151251512615127151281512915130151311513215133151341513515136151371513815139151401514115142151431514415145151461514715148151491515015151151521515315154151551515615157151581515915160151611516215163151641516515166151671516815169151701517115172151731517415175151761517715178151791518015181151821518315184151851518615187151881518915190151911519215193151941519515196151971519815199152001520115202152031520415205152061520715208152091521015211152121521315214152151521615217152181521915220152211522215223152241522515226152271522815229152301523115232152331523415235152361523715238152391524015241152421524315244152451524615247152481524915250152511525215253152541525515256152571525815259152601526115262152631526415265152661526715268152691527015271152721527315274152751527615277152781527915280152811528215283152841528515286152871528815289152901529115292152931529415295152961529715298152991530015301153021530315304153051530615307153081530915310153111531215313153141531515316153171531815319153201532115322153231532415325153261532715328153291533015331153321533315334153351533615337153381533915340153411534215343153441534515346153471534815349153501535115352153531535415355153561535715358153591536015361153621536315364153651536615367153681536915370153711537215373153741537515376153771537815379153801538115382153831538415385153861538715388153891539015391153921539315394153951539615397153981539915400154011540215403154041540515406
  1. /* Everything about breakpoints, for GDB.
  2. Copyright (C) 1986-2022 Free Software Foundation, Inc.
  3. This file is part of GDB.
  4. This program is free software; you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation; either version 3 of the License, or
  7. (at your option) any later version.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with this program. If not, see <http://www.gnu.org/licenses/>. */
  14. #include "defs.h"
  15. #include "arch-utils.h"
  16. #include <ctype.h>
  17. #include "hashtab.h"
  18. #include "symtab.h"
  19. #include "frame.h"
  20. #include "breakpoint.h"
  21. #include "tracepoint.h"
  22. #include "gdbtypes.h"
  23. #include "expression.h"
  24. #include "gdbcore.h"
  25. #include "gdbcmd.h"
  26. #include "value.h"
  27. #include "command.h"
  28. #include "inferior.h"
  29. #include "infrun.h"
  30. #include "gdbthread.h"
  31. #include "target.h"
  32. #include "language.h"
  33. #include "gdb-demangle.h"
  34. #include "filenames.h"
  35. #include "annotate.h"
  36. #include "symfile.h"
  37. #include "objfiles.h"
  38. #include "source.h"
  39. #include "linespec.h"
  40. #include "completer.h"
  41. #include "ui-out.h"
  42. #include "cli/cli-script.h"
  43. #include "block.h"
  44. #include "solib.h"
  45. #include "solist.h"
  46. #include "observable.h"
  47. #include "memattr.h"
  48. #include "ada-lang.h"
  49. #include "top.h"
  50. #include "valprint.h"
  51. #include "jit.h"
  52. #include "parser-defs.h"
  53. #include "gdbsupport/gdb_regex.h"
  54. #include "probe.h"
  55. #include "cli/cli-utils.h"
  56. #include "stack.h"
  57. #include "ax-gdb.h"
  58. #include "dummy-frame.h"
  59. #include "interps.h"
  60. #include "gdbsupport/format.h"
  61. #include "thread-fsm.h"
  62. #include "tid-parse.h"
  63. #include "cli/cli-style.h"
  64. #include "cli/cli-decode.h"
  65. /* readline include files */
  66. #include "readline/tilde.h"
  67. /* readline defines this. */
  68. #undef savestring
  69. #include "mi/mi-common.h"
  70. #include "extension.h"
  71. #include <algorithm>
  72. #include "progspace-and-thread.h"
  73. #include "gdbsupport/array-view.h"
  74. #include "gdbsupport/gdb_optional.h"
  75. /* Prototypes for local functions. */
  76. static void map_breakpoint_numbers (const char *,
  77. gdb::function_view<void (breakpoint *)>);
  78. static void breakpoint_re_set_default (struct breakpoint *);
  79. static void
  80. create_sals_from_location_default (struct event_location *location,
  81. struct linespec_result *canonical,
  82. enum bptype type_wanted);
  83. static void create_breakpoints_sal_default (struct gdbarch *,
  84. struct linespec_result *,
  85. gdb::unique_xmalloc_ptr<char>,
  86. gdb::unique_xmalloc_ptr<char>,
  87. enum bptype,
  88. enum bpdisp, int, int,
  89. int,
  90. const struct breakpoint_ops *,
  91. int, int, int, unsigned);
  92. static std::vector<symtab_and_line> decode_location_default
  93. (struct breakpoint *b, struct event_location *location,
  94. struct program_space *search_pspace);
  95. static int can_use_hardware_watchpoint
  96. (const std::vector<value_ref_ptr> &vals);
  97. static void mention (struct breakpoint *);
  98. static struct breakpoint *set_raw_breakpoint_without_location (struct gdbarch *,
  99. enum bptype,
  100. const struct breakpoint_ops *);
  101. static struct bp_location *add_location_to_breakpoint (struct breakpoint *,
  102. const struct symtab_and_line *);
  103. /* This function is used in gdbtk sources and thus can not be made
  104. static. */
  105. static struct breakpoint *set_raw_breakpoint (struct gdbarch *gdbarch,
  106. struct symtab_and_line,
  107. enum bptype,
  108. const struct breakpoint_ops *);
  109. static struct breakpoint *
  110. momentary_breakpoint_from_master (struct breakpoint *orig,
  111. enum bptype type,
  112. const struct breakpoint_ops *ops,
  113. int loc_enabled);
  114. static void breakpoint_adjustment_warning (CORE_ADDR, CORE_ADDR, int, int);
  115. static CORE_ADDR adjust_breakpoint_address (struct gdbarch *gdbarch,
  116. CORE_ADDR bpaddr,
  117. enum bptype bptype);
  118. static void describe_other_breakpoints (struct gdbarch *,
  119. struct program_space *, CORE_ADDR,
  120. struct obj_section *, int);
  121. static int watchpoint_locations_match (struct bp_location *loc1,
  122. struct bp_location *loc2);
  123. static int breakpoint_locations_match (struct bp_location *loc1,
  124. struct bp_location *loc2,
  125. bool sw_hw_bps_match = false);
  126. static int breakpoint_location_address_match (struct bp_location *bl,
  127. const struct address_space *aspace,
  128. CORE_ADDR addr);
  129. static int breakpoint_location_address_range_overlap (struct bp_location *,
  130. const address_space *,
  131. CORE_ADDR, int);
  132. static int remove_breakpoint (struct bp_location *);
  133. static int remove_breakpoint_1 (struct bp_location *, enum remove_bp_reason);
  134. static enum print_stop_action print_bp_stop_message (bpstat *bs);
  135. static int hw_breakpoint_used_count (void);
  136. static int hw_watchpoint_use_count (struct breakpoint *);
  137. static int hw_watchpoint_used_count_others (struct breakpoint *except,
  138. enum bptype type,
  139. int *other_type_used);
  140. static void enable_breakpoint_disp (struct breakpoint *, enum bpdisp,
  141. int count);
  142. static void decref_bp_location (struct bp_location **loc);
  143. static struct bp_location *allocate_bp_location (struct breakpoint *bpt);
  144. /* update_global_location_list's modes of operation wrt to whether to
  145. insert locations now. */
  146. enum ugll_insert_mode
  147. {
  148. /* Don't insert any breakpoint locations into the inferior, only
  149. remove already-inserted locations that no longer should be
  150. inserted. Functions that delete a breakpoint or breakpoints
  151. should specify this mode, so that deleting a breakpoint doesn't
  152. have the side effect of inserting the locations of other
  153. breakpoints that are marked not-inserted, but should_be_inserted
  154. returns true on them.
  155. This behavior is useful is situations close to tear-down -- e.g.,
  156. after an exec, while the target still has execution, but
  157. breakpoint shadows of the previous executable image should *NOT*
  158. be restored to the new image; or before detaching, where the
  159. target still has execution and wants to delete breakpoints from
  160. GDB's lists, and all breakpoints had already been removed from
  161. the inferior. */
  162. UGLL_DONT_INSERT,
  163. /* May insert breakpoints iff breakpoints_should_be_inserted_now
  164. claims breakpoints should be inserted now. */
  165. UGLL_MAY_INSERT,
  166. /* Insert locations now, irrespective of
  167. breakpoints_should_be_inserted_now. E.g., say all threads are
  168. stopped right now, and the user did "continue". We need to
  169. insert breakpoints _before_ resuming the target, but
  170. UGLL_MAY_INSERT wouldn't insert them, because
  171. breakpoints_should_be_inserted_now returns false at that point,
  172. as no thread is running yet. */
  173. UGLL_INSERT
  174. };
  175. static void update_global_location_list (enum ugll_insert_mode);
  176. static void update_global_location_list_nothrow (enum ugll_insert_mode);
  177. static void insert_breakpoint_locations (void);
  178. static void trace_pass_command (const char *, int);
  179. static void set_tracepoint_count (int num);
  180. static bool is_masked_watchpoint (const struct breakpoint *b);
  181. /* Return 1 if B refers to a static tracepoint set by marker ("-m"), zero
  182. otherwise. */
  183. static int strace_marker_p (struct breakpoint *b);
  184. /* The breakpoint_ops structure to be inherited by all breakpoint_ops
  185. that are implemented on top of software or hardware breakpoints
  186. (user breakpoints, internal and momentary breakpoints, etc.). */
  187. static struct breakpoint_ops bkpt_base_breakpoint_ops;
  188. /* Internal breakpoints class type. */
  189. static struct breakpoint_ops internal_breakpoint_ops;
  190. /* Momentary breakpoints class type. */
  191. static struct breakpoint_ops momentary_breakpoint_ops;
  192. /* The breakpoint_ops structure to be used in regular user created
  193. breakpoints. */
  194. struct breakpoint_ops bkpt_breakpoint_ops;
  195. /* Breakpoints set on probes. */
  196. static struct breakpoint_ops bkpt_probe_breakpoint_ops;
  197. /* Tracepoints set on probes. */
  198. static struct breakpoint_ops tracepoint_probe_breakpoint_ops;
  199. /* Dynamic printf class type. */
  200. struct breakpoint_ops dprintf_breakpoint_ops;
  201. /* The style in which to perform a dynamic printf. This is a user
  202. option because different output options have different tradeoffs;
  203. if GDB does the printing, there is better error handling if there
  204. is a problem with any of the arguments, but using an inferior
  205. function lets you have special-purpose printers and sending of
  206. output to the same place as compiled-in print functions. */
  207. static const char dprintf_style_gdb[] = "gdb";
  208. static const char dprintf_style_call[] = "call";
  209. static const char dprintf_style_agent[] = "agent";
  210. static const char *const dprintf_style_enums[] = {
  211. dprintf_style_gdb,
  212. dprintf_style_call,
  213. dprintf_style_agent,
  214. NULL
  215. };
  216. static const char *dprintf_style = dprintf_style_gdb;
  217. /* The function to use for dynamic printf if the preferred style is to
  218. call into the inferior. The value is simply a string that is
  219. copied into the command, so it can be anything that GDB can
  220. evaluate to a callable address, not necessarily a function name. */
  221. static std::string dprintf_function = "printf";
  222. /* The channel to use for dynamic printf if the preferred style is to
  223. call into the inferior; if a nonempty string, it will be passed to
  224. the call as the first argument, with the format string as the
  225. second. As with the dprintf function, this can be anything that
  226. GDB knows how to evaluate, so in addition to common choices like
  227. "stderr", this could be an app-specific expression like
  228. "mystreams[curlogger]". */
  229. static std::string dprintf_channel;
  230. /* True if dprintf commands should continue to operate even if GDB
  231. has disconnected. */
  232. static bool disconnected_dprintf = true;
  233. struct command_line *
  234. breakpoint_commands (struct breakpoint *b)
  235. {
  236. return b->commands ? b->commands.get () : NULL;
  237. }
  238. /* Flag indicating that a command has proceeded the inferior past the
  239. current breakpoint. */
  240. static bool breakpoint_proceeded;
  241. const char *
  242. bpdisp_text (enum bpdisp disp)
  243. {
  244. /* NOTE: the following values are a part of MI protocol and
  245. represent values of 'disp' field returned when inferior stops at
  246. a breakpoint. */
  247. static const char * const bpdisps[] = {"del", "dstp", "dis", "keep"};
  248. return bpdisps[(int) disp];
  249. }
  250. /* Prototypes for exported functions. */
  251. /* If FALSE, gdb will not use hardware support for watchpoints, even
  252. if such is available. */
  253. static int can_use_hw_watchpoints;
  254. static void
  255. show_can_use_hw_watchpoints (struct ui_file *file, int from_tty,
  256. struct cmd_list_element *c,
  257. const char *value)
  258. {
  259. gdb_printf (file,
  260. _("Debugger's willingness to use "
  261. "watchpoint hardware is %s.\n"),
  262. value);
  263. }
  264. /* If AUTO_BOOLEAN_FALSE, gdb will not attempt to create pending breakpoints.
  265. If AUTO_BOOLEAN_TRUE, gdb will automatically create pending breakpoints
  266. for unrecognized breakpoint locations.
  267. If AUTO_BOOLEAN_AUTO, gdb will query when breakpoints are unrecognized. */
  268. static enum auto_boolean pending_break_support;
  269. static void
  270. show_pending_break_support (struct ui_file *file, int from_tty,
  271. struct cmd_list_element *c,
  272. const char *value)
  273. {
  274. gdb_printf (file,
  275. _("Debugger's behavior regarding "
  276. "pending breakpoints is %s.\n"),
  277. value);
  278. }
  279. /* If true, gdb will automatically use hardware breakpoints for breakpoints
  280. set with "break" but falling in read-only memory.
  281. If false, gdb will warn about such breakpoints, but won't automatically
  282. use hardware breakpoints. */
  283. static bool automatic_hardware_breakpoints;
  284. static void
  285. show_automatic_hardware_breakpoints (struct ui_file *file, int from_tty,
  286. struct cmd_list_element *c,
  287. const char *value)
  288. {
  289. gdb_printf (file,
  290. _("Automatic usage of hardware breakpoints is %s.\n"),
  291. value);
  292. }
  293. /* If on, GDB keeps breakpoints inserted even if the inferior is
  294. stopped, and immediately inserts any new breakpoints as soon as
  295. they're created. If off (default), GDB keeps breakpoints off of
  296. the target as long as possible. That is, it delays inserting
  297. breakpoints until the next resume, and removes them again when the
  298. target fully stops. This is a bit safer in case GDB crashes while
  299. processing user input. */
  300. static bool always_inserted_mode = false;
  301. static void
  302. show_always_inserted_mode (struct ui_file *file, int from_tty,
  303. struct cmd_list_element *c, const char *value)
  304. {
  305. gdb_printf (file, _("Always inserted breakpoint mode is %s.\n"),
  306. value);
  307. }
  308. /* See breakpoint.h. */
  309. int
  310. breakpoints_should_be_inserted_now (void)
  311. {
  312. if (gdbarch_has_global_breakpoints (target_gdbarch ()))
  313. {
  314. /* If breakpoints are global, they should be inserted even if no
  315. thread under gdb's control is running, or even if there are
  316. no threads under GDB's control yet. */
  317. return 1;
  318. }
  319. else
  320. {
  321. if (always_inserted_mode)
  322. {
  323. /* The user wants breakpoints inserted even if all threads
  324. are stopped. */
  325. return 1;
  326. }
  327. for (inferior *inf : all_inferiors ())
  328. if (inf->has_execution ()
  329. && threads_are_executing (inf->process_target ()))
  330. return 1;
  331. /* Don't remove breakpoints yet if, even though all threads are
  332. stopped, we still have events to process. */
  333. for (thread_info *tp : all_non_exited_threads ())
  334. if (tp->resumed () && tp->has_pending_waitstatus ())
  335. return 1;
  336. }
  337. return 0;
  338. }
  339. static const char condition_evaluation_both[] = "host or target";
  340. /* Modes for breakpoint condition evaluation. */
  341. static const char condition_evaluation_auto[] = "auto";
  342. static const char condition_evaluation_host[] = "host";
  343. static const char condition_evaluation_target[] = "target";
  344. static const char *const condition_evaluation_enums[] = {
  345. condition_evaluation_auto,
  346. condition_evaluation_host,
  347. condition_evaluation_target,
  348. NULL
  349. };
  350. /* Global that holds the current mode for breakpoint condition evaluation. */
  351. static const char *condition_evaluation_mode_1 = condition_evaluation_auto;
  352. /* Global that we use to display information to the user (gets its value from
  353. condition_evaluation_mode_1. */
  354. static const char *condition_evaluation_mode = condition_evaluation_auto;
  355. /* Translate a condition evaluation mode MODE into either "host"
  356. or "target". This is used mostly to translate from "auto" to the
  357. real setting that is being used. It returns the translated
  358. evaluation mode. */
  359. static const char *
  360. translate_condition_evaluation_mode (const char *mode)
  361. {
  362. if (mode == condition_evaluation_auto)
  363. {
  364. if (target_supports_evaluation_of_breakpoint_conditions ())
  365. return condition_evaluation_target;
  366. else
  367. return condition_evaluation_host;
  368. }
  369. else
  370. return mode;
  371. }
  372. /* Discovers what condition_evaluation_auto translates to. */
  373. static const char *
  374. breakpoint_condition_evaluation_mode (void)
  375. {
  376. return translate_condition_evaluation_mode (condition_evaluation_mode);
  377. }
  378. /* Return true if GDB should evaluate breakpoint conditions or false
  379. otherwise. */
  380. static int
  381. gdb_evaluates_breakpoint_condition_p (void)
  382. {
  383. const char *mode = breakpoint_condition_evaluation_mode ();
  384. return (mode == condition_evaluation_host);
  385. }
  386. /* Are we executing breakpoint commands? */
  387. static int executing_breakpoint_commands;
  388. /* Are overlay event breakpoints enabled? */
  389. static int overlay_events_enabled;
  390. /* See description in breakpoint.h. */
  391. bool target_exact_watchpoints = false;
  392. /* Walk the following statement or block through all breakpoints.
  393. ALL_BREAKPOINTS_SAFE does so even if the statement deletes the
  394. current breakpoint. */
  395. #define ALL_BREAKPOINTS_SAFE(B,TMP) \
  396. for (B = breakpoint_chain; \
  397. B ? (TMP=B->next, 1): 0; \
  398. B = TMP)
  399. /* Chains of all breakpoints defined. */
  400. static struct breakpoint *breakpoint_chain;
  401. /* See breakpoint.h. */
  402. breakpoint_range
  403. all_breakpoints ()
  404. {
  405. return breakpoint_range (breakpoint_chain);
  406. }
  407. /* See breakpoint.h. */
  408. breakpoint_safe_range
  409. all_breakpoints_safe ()
  410. {
  411. return breakpoint_safe_range (all_breakpoints ());
  412. }
  413. /* See breakpoint.h. */
  414. tracepoint_range
  415. all_tracepoints ()
  416. {
  417. return tracepoint_range (breakpoint_chain);
  418. }
  419. /* Array is sorted by bp_location_is_less_than - primarily by the ADDRESS. */
  420. static std::vector<bp_location *> bp_locations;
  421. /* See breakpoint.h. */
  422. const std::vector<bp_location *> &
  423. all_bp_locations ()
  424. {
  425. return bp_locations;
  426. }
  427. /* Range to iterate over breakpoint locations at a given address. */
  428. struct bp_locations_at_addr_range
  429. {
  430. using iterator = std::vector<bp_location *>::iterator;
  431. bp_locations_at_addr_range (CORE_ADDR addr)
  432. {
  433. struct compare
  434. {
  435. bool operator() (const bp_location *loc, CORE_ADDR addr_) const
  436. { return loc->address < addr_; }
  437. bool operator() (CORE_ADDR addr_, const bp_location *loc) const
  438. { return addr_ < loc->address; }
  439. };
  440. auto it_pair = std::equal_range (bp_locations.begin (), bp_locations.end (),
  441. addr, compare ());
  442. m_begin = it_pair.first;
  443. m_end = it_pair.second;
  444. }
  445. iterator begin () const
  446. { return m_begin; }
  447. iterator end () const
  448. { return m_end; }
  449. private:
  450. iterator m_begin;
  451. iterator m_end;
  452. };
  453. /* Return a range to iterate over all breakpoint locations exactly at address
  454. ADDR.
  455. If it's needed to iterate multiple times on the same range, it's possible
  456. to save the range in a local variable and use it multiple times:
  457. auto range = all_bp_locations_at_addr (addr);
  458. for (bp_location *loc : range)
  459. // use loc
  460. for (bp_location *loc : range)
  461. // use loc
  462. This saves a bit of time, as it avoids re-doing the binary searches to find
  463. the range's boundaries. Just remember not to change the bp_locations vector
  464. in the mean time, as it could make the range's iterators stale. */
  465. static bp_locations_at_addr_range
  466. all_bp_locations_at_addr (CORE_ADDR addr)
  467. {
  468. return bp_locations_at_addr_range (addr);
  469. }
  470. /* Maximum alignment offset between bp_target_info.PLACED_ADDRESS and
  471. ADDRESS for the current elements of BP_LOCATIONS which get a valid
  472. result from bp_location_has_shadow. You can use it for roughly
  473. limiting the subrange of BP_LOCATIONS to scan for shadow bytes for
  474. an address you need to read. */
  475. static CORE_ADDR bp_locations_placed_address_before_address_max;
  476. /* Maximum offset plus alignment between bp_target_info.PLACED_ADDRESS
  477. + bp_target_info.SHADOW_LEN and ADDRESS for the current elements of
  478. BP_LOCATIONS which get a valid result from bp_location_has_shadow.
  479. You can use it for roughly limiting the subrange of BP_LOCATIONS to
  480. scan for shadow bytes for an address you need to read. */
  481. static CORE_ADDR bp_locations_shadow_len_after_address_max;
  482. /* The locations that no longer correspond to any breakpoint, unlinked
  483. from the bp_locations array, but for which a hit may still be
  484. reported by a target. */
  485. static std::vector<bp_location *> moribund_locations;
  486. /* Number of last breakpoint made. */
  487. static int breakpoint_count;
  488. /* The value of `breakpoint_count' before the last command that
  489. created breakpoints. If the last (break-like) command created more
  490. than one breakpoint, then the difference between BREAKPOINT_COUNT
  491. and PREV_BREAKPOINT_COUNT is more than one. */
  492. static int prev_breakpoint_count;
  493. /* Number of last tracepoint made. */
  494. static int tracepoint_count;
  495. static struct cmd_list_element *breakpoint_set_cmdlist;
  496. static struct cmd_list_element *breakpoint_show_cmdlist;
  497. struct cmd_list_element *save_cmdlist;
  498. /* Return whether a breakpoint is an active enabled breakpoint. */
  499. static int
  500. breakpoint_enabled (struct breakpoint *b)
  501. {
  502. return (b->enable_state == bp_enabled);
  503. }
  504. /* Set breakpoint count to NUM. */
  505. static void
  506. set_breakpoint_count (int num)
  507. {
  508. prev_breakpoint_count = breakpoint_count;
  509. breakpoint_count = num;
  510. set_internalvar_integer (lookup_internalvar ("bpnum"), num);
  511. }
  512. /* Used by `start_rbreak_breakpoints' below, to record the current
  513. breakpoint count before "rbreak" creates any breakpoint. */
  514. static int rbreak_start_breakpoint_count;
  515. /* Called at the start an "rbreak" command to record the first
  516. breakpoint made. */
  517. scoped_rbreak_breakpoints::scoped_rbreak_breakpoints ()
  518. {
  519. rbreak_start_breakpoint_count = breakpoint_count;
  520. }
  521. /* Called at the end of an "rbreak" command to record the last
  522. breakpoint made. */
  523. scoped_rbreak_breakpoints::~scoped_rbreak_breakpoints ()
  524. {
  525. prev_breakpoint_count = rbreak_start_breakpoint_count;
  526. }
  527. /* Used in run_command to zero the hit count when a new run starts. */
  528. void
  529. clear_breakpoint_hit_counts (void)
  530. {
  531. for (breakpoint *b : all_breakpoints ())
  532. b->hit_count = 0;
  533. }
  534. /* Return the breakpoint with the specified number, or NULL
  535. if the number does not refer to an existing breakpoint. */
  536. struct breakpoint *
  537. get_breakpoint (int num)
  538. {
  539. for (breakpoint *b : all_breakpoints ())
  540. if (b->number == num)
  541. return b;
  542. return nullptr;
  543. }
  544. /* Mark locations as "conditions have changed" in case the target supports
  545. evaluating conditions on its side. */
  546. static void
  547. mark_breakpoint_modified (struct breakpoint *b)
  548. {
  549. /* This is only meaningful if the target is
  550. evaluating conditions and if the user has
  551. opted for condition evaluation on the target's
  552. side. */
  553. if (gdb_evaluates_breakpoint_condition_p ()
  554. || !target_supports_evaluation_of_breakpoint_conditions ())
  555. return;
  556. if (!is_breakpoint (b))
  557. return;
  558. for (bp_location *loc : b->locations ())
  559. loc->condition_changed = condition_modified;
  560. }
  561. /* Mark location as "conditions have changed" in case the target supports
  562. evaluating conditions on its side. */
  563. static void
  564. mark_breakpoint_location_modified (struct bp_location *loc)
  565. {
  566. /* This is only meaningful if the target is
  567. evaluating conditions and if the user has
  568. opted for condition evaluation on the target's
  569. side. */
  570. if (gdb_evaluates_breakpoint_condition_p ()
  571. || !target_supports_evaluation_of_breakpoint_conditions ())
  572. return;
  573. if (!is_breakpoint (loc->owner))
  574. return;
  575. loc->condition_changed = condition_modified;
  576. }
  577. /* Sets the condition-evaluation mode using the static global
  578. condition_evaluation_mode. */
  579. static void
  580. set_condition_evaluation_mode (const char *args, int from_tty,
  581. struct cmd_list_element *c)
  582. {
  583. const char *old_mode, *new_mode;
  584. if ((condition_evaluation_mode_1 == condition_evaluation_target)
  585. && !target_supports_evaluation_of_breakpoint_conditions ())
  586. {
  587. condition_evaluation_mode_1 = condition_evaluation_mode;
  588. warning (_("Target does not support breakpoint condition evaluation.\n"
  589. "Using host evaluation mode instead."));
  590. return;
  591. }
  592. new_mode = translate_condition_evaluation_mode (condition_evaluation_mode_1);
  593. old_mode = translate_condition_evaluation_mode (condition_evaluation_mode);
  594. /* Flip the switch. Flip it even if OLD_MODE == NEW_MODE as one of the
  595. settings was "auto". */
  596. condition_evaluation_mode = condition_evaluation_mode_1;
  597. /* Only update the mode if the user picked a different one. */
  598. if (new_mode != old_mode)
  599. {
  600. /* If the user switched to a different evaluation mode, we
  601. need to synch the changes with the target as follows:
  602. "host" -> "target": Send all (valid) conditions to the target.
  603. "target" -> "host": Remove all the conditions from the target.
  604. */
  605. if (new_mode == condition_evaluation_target)
  606. {
  607. /* Mark everything modified and synch conditions with the
  608. target. */
  609. for (bp_location *loc : all_bp_locations ())
  610. mark_breakpoint_location_modified (loc);
  611. }
  612. else
  613. {
  614. /* Manually mark non-duplicate locations to synch conditions
  615. with the target. We do this to remove all the conditions the
  616. target knows about. */
  617. for (bp_location *loc : all_bp_locations ())
  618. if (is_breakpoint (loc->owner) && loc->inserted)
  619. loc->needs_update = 1;
  620. }
  621. /* Do the update. */
  622. update_global_location_list (UGLL_MAY_INSERT);
  623. }
  624. return;
  625. }
  626. /* Shows the current mode of breakpoint condition evaluation. Explicitly shows
  627. what "auto" is translating to. */
  628. static void
  629. show_condition_evaluation_mode (struct ui_file *file, int from_tty,
  630. struct cmd_list_element *c, const char *value)
  631. {
  632. if (condition_evaluation_mode == condition_evaluation_auto)
  633. gdb_printf (file,
  634. _("Breakpoint condition evaluation "
  635. "mode is %s (currently %s).\n"),
  636. value,
  637. breakpoint_condition_evaluation_mode ());
  638. else
  639. gdb_printf (file, _("Breakpoint condition evaluation mode is %s.\n"),
  640. value);
  641. }
  642. /* Parse COND_STRING in the context of LOC and set as the condition
  643. expression of LOC. BP_NUM is the number of LOC's owner, LOC_NUM is
  644. the number of LOC within its owner. In case of parsing error, mark
  645. LOC as DISABLED_BY_COND. In case of success, unset DISABLED_BY_COND. */
  646. static void
  647. set_breakpoint_location_condition (const char *cond_string, bp_location *loc,
  648. int bp_num, int loc_num)
  649. {
  650. bool has_junk = false;
  651. try
  652. {
  653. expression_up new_exp = parse_exp_1 (&cond_string, loc->address,
  654. block_for_pc (loc->address), 0);
  655. if (*cond_string != 0)
  656. has_junk = true;
  657. else
  658. {
  659. loc->cond = std::move (new_exp);
  660. if (loc->disabled_by_cond && loc->enabled)
  661. gdb_printf (_("Breakpoint %d's condition is now valid at "
  662. "location %d, enabling.\n"),
  663. bp_num, loc_num);
  664. loc->disabled_by_cond = false;
  665. }
  666. }
  667. catch (const gdb_exception_error &e)
  668. {
  669. if (loc->enabled)
  670. {
  671. /* Warn if a user-enabled location is now becoming disabled-by-cond.
  672. BP_NUM is 0 if the breakpoint is being defined for the first
  673. time using the "break ... if ..." command, and non-zero if
  674. already defined. */
  675. if (bp_num != 0)
  676. warning (_("failed to validate condition at location %d.%d, "
  677. "disabling:\n %s"), bp_num, loc_num, e.what ());
  678. else
  679. warning (_("failed to validate condition at location %d, "
  680. "disabling:\n %s"), loc_num, e.what ());
  681. }
  682. loc->disabled_by_cond = true;
  683. }
  684. if (has_junk)
  685. error (_("Garbage '%s' follows condition"), cond_string);
  686. }
  687. void
  688. set_breakpoint_condition (struct breakpoint *b, const char *exp,
  689. int from_tty, bool force)
  690. {
  691. if (*exp == 0)
  692. {
  693. b->cond_string.reset ();
  694. if (is_watchpoint (b))
  695. static_cast<watchpoint *> (b)->cond_exp.reset ();
  696. else
  697. {
  698. int loc_num = 1;
  699. for (bp_location *loc : b->locations ())
  700. {
  701. loc->cond.reset ();
  702. if (loc->disabled_by_cond && loc->enabled)
  703. gdb_printf (_("Breakpoint %d's condition is now valid at "
  704. "location %d, enabling.\n"),
  705. b->number, loc_num);
  706. loc->disabled_by_cond = false;
  707. loc_num++;
  708. /* No need to free the condition agent expression
  709. bytecode (if we have one). We will handle this
  710. when we go through update_global_location_list. */
  711. }
  712. }
  713. if (from_tty)
  714. gdb_printf (_("Breakpoint %d now unconditional.\n"), b->number);
  715. }
  716. else
  717. {
  718. if (is_watchpoint (b))
  719. {
  720. innermost_block_tracker tracker;
  721. const char *arg = exp;
  722. expression_up new_exp = parse_exp_1 (&arg, 0, 0, 0, &tracker);
  723. if (*arg != 0)
  724. error (_("Junk at end of expression"));
  725. watchpoint *w = static_cast<watchpoint *> (b);
  726. w->cond_exp = std::move (new_exp);
  727. w->cond_exp_valid_block = tracker.block ();
  728. }
  729. else
  730. {
  731. /* Parse and set condition expressions. We make two passes.
  732. In the first, we parse the condition string to see if it
  733. is valid in at least one location. If so, the condition
  734. would be accepted. So we go ahead and set the locations'
  735. conditions. In case no valid case is found, we throw
  736. the error and the condition string will be rejected.
  737. This two-pass approach is taken to avoid setting the
  738. state of locations in case of a reject. */
  739. for (bp_location *loc : b->locations ())
  740. {
  741. try
  742. {
  743. const char *arg = exp;
  744. parse_exp_1 (&arg, loc->address,
  745. block_for_pc (loc->address), 0);
  746. if (*arg != 0)
  747. error (_("Junk at end of expression"));
  748. break;
  749. }
  750. catch (const gdb_exception_error &e)
  751. {
  752. /* Condition string is invalid. If this happens to
  753. be the last loc, abandon (if not forced) or continue
  754. (if forced). */
  755. if (loc->next == nullptr && !force)
  756. throw;
  757. }
  758. }
  759. /* If we reach here, the condition is valid at some locations. */
  760. int loc_num = 1;
  761. for (bp_location *loc : b->locations ())
  762. {
  763. set_breakpoint_location_condition (exp, loc, b->number, loc_num);
  764. loc_num++;
  765. }
  766. }
  767. /* We know that the new condition parsed successfully. The
  768. condition string of the breakpoint can be safely updated. */
  769. b->cond_string = make_unique_xstrdup (exp);
  770. b->condition_not_parsed = 0;
  771. }
  772. mark_breakpoint_modified (b);
  773. gdb::observers::breakpoint_modified.notify (b);
  774. }
  775. /* See breakpoint.h. */
  776. void
  777. set_breakpoint_condition (int bpnum, const char *exp, int from_tty,
  778. bool force)
  779. {
  780. for (breakpoint *b : all_breakpoints ())
  781. if (b->number == bpnum)
  782. {
  783. /* Check if this breakpoint has a "stop" method implemented in an
  784. extension language. This method and conditions entered into GDB
  785. from the CLI are mutually exclusive. */
  786. const struct extension_language_defn *extlang
  787. = get_breakpoint_cond_ext_lang (b, EXT_LANG_NONE);
  788. if (extlang != NULL)
  789. {
  790. error (_("Only one stop condition allowed. There is currently"
  791. " a %s stop condition defined for this breakpoint."),
  792. ext_lang_capitalized_name (extlang));
  793. }
  794. set_breakpoint_condition (b, exp, from_tty, force);
  795. if (is_breakpoint (b))
  796. update_global_location_list (UGLL_MAY_INSERT);
  797. return;
  798. }
  799. error (_("No breakpoint number %d."), bpnum);
  800. }
  801. /* The options for the "condition" command. */
  802. struct condition_command_opts
  803. {
  804. /* For "-force". */
  805. bool force_condition = false;
  806. };
  807. static const gdb::option::option_def condition_command_option_defs[] = {
  808. gdb::option::flag_option_def<condition_command_opts> {
  809. "force",
  810. [] (condition_command_opts *opts) { return &opts->force_condition; },
  811. N_("Set the condition even if it is invalid for all current locations."),
  812. },
  813. };
  814. /* Create an option_def_group for the "condition" options, with
  815. CC_OPTS as context. */
  816. static inline gdb::option::option_def_group
  817. make_condition_command_options_def_group (condition_command_opts *cc_opts)
  818. {
  819. return {{condition_command_option_defs}, cc_opts};
  820. }
  821. /* Completion for the "condition" command. */
  822. static void
  823. condition_completer (struct cmd_list_element *cmd,
  824. completion_tracker &tracker,
  825. const char *text, const char * /*word*/)
  826. {
  827. bool has_no_arguments = (*text == '\0');
  828. condition_command_opts cc_opts;
  829. const auto group = make_condition_command_options_def_group (&cc_opts);
  830. if (gdb::option::complete_options
  831. (tracker, &text, gdb::option::PROCESS_OPTIONS_UNKNOWN_IS_ERROR, group))
  832. return;
  833. text = skip_spaces (text);
  834. const char *space = skip_to_space (text);
  835. if (*space == '\0')
  836. {
  837. int len;
  838. if (text[0] == '$')
  839. {
  840. tracker.advance_custom_word_point_by (1);
  841. /* We don't support completion of history indices. */
  842. if (!isdigit (text[1]))
  843. complete_internalvar (tracker, &text[1]);
  844. return;
  845. }
  846. /* Suggest the "-force" flag if no arguments are given. If
  847. arguments were passed, they either already include the flag,
  848. or we are beyond the point of suggesting it because it's
  849. positionally the first argument. */
  850. if (has_no_arguments)
  851. gdb::option::complete_on_all_options (tracker, group);
  852. /* We're completing the breakpoint number. */
  853. len = strlen (text);
  854. for (breakpoint *b : all_breakpoints ())
  855. {
  856. char number[50];
  857. xsnprintf (number, sizeof (number), "%d", b->number);
  858. if (strncmp (number, text, len) == 0)
  859. tracker.add_completion (make_unique_xstrdup (number));
  860. }
  861. return;
  862. }
  863. /* We're completing the expression part. Skip the breakpoint num. */
  864. const char *exp_start = skip_spaces (space);
  865. tracker.advance_custom_word_point_by (exp_start - text);
  866. text = exp_start;
  867. const char *word = advance_to_expression_complete_word_point (tracker, text);
  868. expression_completer (cmd, tracker, text, word);
  869. }
  870. /* condition N EXP -- set break condition of breakpoint N to EXP. */
  871. static void
  872. condition_command (const char *arg, int from_tty)
  873. {
  874. const char *p;
  875. int bnum;
  876. if (arg == 0)
  877. error_no_arg (_("breakpoint number"));
  878. p = arg;
  879. /* Check if the "-force" flag was passed. */
  880. condition_command_opts cc_opts;
  881. const auto group = make_condition_command_options_def_group (&cc_opts);
  882. gdb::option::process_options
  883. (&p, gdb::option::PROCESS_OPTIONS_UNKNOWN_IS_ERROR, group);
  884. bnum = get_number (&p);
  885. if (bnum == 0)
  886. error (_("Bad breakpoint argument: '%s'"), arg);
  887. set_breakpoint_condition (bnum, p, from_tty, cc_opts.force_condition);
  888. }
  889. /* Check that COMMAND do not contain commands that are suitable
  890. only for tracepoints and not suitable for ordinary breakpoints.
  891. Throw if any such commands is found. */
  892. static void
  893. check_no_tracepoint_commands (struct command_line *commands)
  894. {
  895. struct command_line *c;
  896. for (c = commands; c; c = c->next)
  897. {
  898. if (c->control_type == while_stepping_control)
  899. error (_("The 'while-stepping' command can "
  900. "only be used for tracepoints"));
  901. check_no_tracepoint_commands (c->body_list_0.get ());
  902. check_no_tracepoint_commands (c->body_list_1.get ());
  903. /* Not that command parsing removes leading whitespace and comment
  904. lines and also empty lines. So, we only need to check for
  905. command directly. */
  906. if (strstr (c->line, "collect ") == c->line)
  907. error (_("The 'collect' command can only be used for tracepoints"));
  908. if (strstr (c->line, "teval ") == c->line)
  909. error (_("The 'teval' command can only be used for tracepoints"));
  910. }
  911. }
  912. struct longjmp_breakpoint : public breakpoint
  913. {
  914. ~longjmp_breakpoint () override;
  915. };
  916. /* Encapsulate tests for different types of tracepoints. */
  917. static bool
  918. is_tracepoint_type (bptype type)
  919. {
  920. return (type == bp_tracepoint
  921. || type == bp_fast_tracepoint
  922. || type == bp_static_tracepoint);
  923. }
  924. static bool
  925. is_longjmp_type (bptype type)
  926. {
  927. return type == bp_longjmp || type == bp_exception;
  928. }
  929. /* See breakpoint.h. */
  930. bool
  931. is_tracepoint (const struct breakpoint *b)
  932. {
  933. return is_tracepoint_type (b->type);
  934. }
  935. /* Factory function to create an appropriate instance of breakpoint given
  936. TYPE. */
  937. static std::unique_ptr<breakpoint>
  938. new_breakpoint_from_type (bptype type)
  939. {
  940. breakpoint *b;
  941. if (is_tracepoint_type (type))
  942. b = new tracepoint ();
  943. else if (is_longjmp_type (type))
  944. b = new longjmp_breakpoint ();
  945. else
  946. b = new breakpoint ();
  947. return std::unique_ptr<breakpoint> (b);
  948. }
  949. /* A helper function that validates that COMMANDS are valid for a
  950. breakpoint. This function will throw an exception if a problem is
  951. found. */
  952. static void
  953. validate_commands_for_breakpoint (struct breakpoint *b,
  954. struct command_line *commands)
  955. {
  956. if (is_tracepoint (b))
  957. {
  958. struct tracepoint *t = (struct tracepoint *) b;
  959. struct command_line *c;
  960. struct command_line *while_stepping = 0;
  961. /* Reset the while-stepping step count. The previous commands
  962. might have included a while-stepping action, while the new
  963. ones might not. */
  964. t->step_count = 0;
  965. /* We need to verify that each top-level element of commands is
  966. valid for tracepoints, that there's at most one
  967. while-stepping element, and that the while-stepping's body
  968. has valid tracing commands excluding nested while-stepping.
  969. We also need to validate the tracepoint action line in the
  970. context of the tracepoint --- validate_actionline actually
  971. has side effects, like setting the tracepoint's
  972. while-stepping STEP_COUNT, in addition to checking if the
  973. collect/teval actions parse and make sense in the
  974. tracepoint's context. */
  975. for (c = commands; c; c = c->next)
  976. {
  977. if (c->control_type == while_stepping_control)
  978. {
  979. if (b->type == bp_fast_tracepoint)
  980. error (_("The 'while-stepping' command "
  981. "cannot be used for fast tracepoint"));
  982. else if (b->type == bp_static_tracepoint)
  983. error (_("The 'while-stepping' command "
  984. "cannot be used for static tracepoint"));
  985. if (while_stepping)
  986. error (_("The 'while-stepping' command "
  987. "can be used only once"));
  988. else
  989. while_stepping = c;
  990. }
  991. validate_actionline (c->line, b);
  992. }
  993. if (while_stepping)
  994. {
  995. struct command_line *c2;
  996. gdb_assert (while_stepping->body_list_1 == nullptr);
  997. c2 = while_stepping->body_list_0.get ();
  998. for (; c2; c2 = c2->next)
  999. {
  1000. if (c2->control_type == while_stepping_control)
  1001. error (_("The 'while-stepping' command cannot be nested"));
  1002. }
  1003. }
  1004. }
  1005. else
  1006. {
  1007. check_no_tracepoint_commands (commands);
  1008. }
  1009. }
  1010. /* Return a vector of all the static tracepoints set at ADDR. The
  1011. caller is responsible for releasing the vector. */
  1012. std::vector<breakpoint *>
  1013. static_tracepoints_here (CORE_ADDR addr)
  1014. {
  1015. std::vector<breakpoint *> found;
  1016. for (breakpoint *b : all_breakpoints ())
  1017. if (b->type == bp_static_tracepoint)
  1018. {
  1019. for (bp_location *loc : b->locations ())
  1020. if (loc->address == addr)
  1021. found.push_back (b);
  1022. }
  1023. return found;
  1024. }
  1025. /* Set the command list of B to COMMANDS. If breakpoint is tracepoint,
  1026. validate that only allowed commands are included. */
  1027. void
  1028. breakpoint_set_commands (struct breakpoint *b,
  1029. counted_command_line &&commands)
  1030. {
  1031. validate_commands_for_breakpoint (b, commands.get ());
  1032. b->commands = std::move (commands);
  1033. gdb::observers::breakpoint_modified.notify (b);
  1034. }
  1035. /* Set the internal `silent' flag on the breakpoint. Note that this
  1036. is not the same as the "silent" that may appear in the breakpoint's
  1037. commands. */
  1038. void
  1039. breakpoint_set_silent (struct breakpoint *b, int silent)
  1040. {
  1041. int old_silent = b->silent;
  1042. b->silent = silent;
  1043. if (old_silent != silent)
  1044. gdb::observers::breakpoint_modified.notify (b);
  1045. }
  1046. /* Set the thread for this breakpoint. If THREAD is -1, make the
  1047. breakpoint work for any thread. */
  1048. void
  1049. breakpoint_set_thread (struct breakpoint *b, int thread)
  1050. {
  1051. int old_thread = b->thread;
  1052. b->thread = thread;
  1053. if (old_thread != thread)
  1054. gdb::observers::breakpoint_modified.notify (b);
  1055. }
  1056. /* Set the task for this breakpoint. If TASK is 0, make the
  1057. breakpoint work for any task. */
  1058. void
  1059. breakpoint_set_task (struct breakpoint *b, int task)
  1060. {
  1061. int old_task = b->task;
  1062. b->task = task;
  1063. if (old_task != task)
  1064. gdb::observers::breakpoint_modified.notify (b);
  1065. }
  1066. static void
  1067. commands_command_1 (const char *arg, int from_tty,
  1068. struct command_line *control)
  1069. {
  1070. counted_command_line cmd;
  1071. /* cmd_read will be true once we have read cmd. Note that cmd might still be
  1072. NULL after the call to read_command_lines if the user provides an empty
  1073. list of command by just typing "end". */
  1074. bool cmd_read = false;
  1075. std::string new_arg;
  1076. if (arg == NULL || !*arg)
  1077. {
  1078. /* Argument not explicitly given. Synthesize it. */
  1079. if (breakpoint_count - prev_breakpoint_count > 1)
  1080. new_arg = string_printf ("%d-%d", prev_breakpoint_count + 1,
  1081. breakpoint_count);
  1082. else if (breakpoint_count > 0)
  1083. new_arg = string_printf ("%d", breakpoint_count);
  1084. }
  1085. else
  1086. {
  1087. /* Create a copy of ARG. This is needed because the "commands"
  1088. command may be coming from a script. In that case, the read
  1089. line buffer is going to be overwritten in the lambda of
  1090. 'map_breakpoint_numbers' below when reading the next line
  1091. before we are are done parsing the breakpoint numbers. */
  1092. new_arg = arg;
  1093. }
  1094. arg = new_arg.c_str ();
  1095. map_breakpoint_numbers
  1096. (arg, [&] (breakpoint *b)
  1097. {
  1098. if (!cmd_read)
  1099. {
  1100. gdb_assert (cmd == NULL);
  1101. if (control != NULL)
  1102. cmd = control->body_list_0;
  1103. else
  1104. {
  1105. std::string str
  1106. = string_printf (_("Type commands for breakpoint(s) "
  1107. "%s, one per line."),
  1108. arg);
  1109. auto do_validate = [=] (const char *line)
  1110. {
  1111. validate_actionline (line, b);
  1112. };
  1113. gdb::function_view<void (const char *)> validator;
  1114. if (is_tracepoint (b))
  1115. validator = do_validate;
  1116. cmd = read_command_lines (str.c_str (), from_tty, 1, validator);
  1117. }
  1118. cmd_read = true;
  1119. }
  1120. /* If a breakpoint was on the list more than once, we don't need to
  1121. do anything. */
  1122. if (b->commands != cmd)
  1123. {
  1124. validate_commands_for_breakpoint (b, cmd.get ());
  1125. b->commands = cmd;
  1126. gdb::observers::breakpoint_modified.notify (b);
  1127. }
  1128. });
  1129. }
  1130. static void
  1131. commands_command (const char *arg, int from_tty)
  1132. {
  1133. commands_command_1 (arg, from_tty, NULL);
  1134. }
  1135. /* Like commands_command, but instead of reading the commands from
  1136. input stream, takes them from an already parsed command structure.
  1137. This is used by cli-script.c to DTRT with breakpoint commands
  1138. that are part of if and while bodies. */
  1139. enum command_control_type
  1140. commands_from_control_command (const char *arg, struct command_line *cmd)
  1141. {
  1142. commands_command_1 (arg, 0, cmd);
  1143. return simple_control;
  1144. }
  1145. /* Return non-zero if BL->TARGET_INFO contains valid information. */
  1146. static int
  1147. bp_location_has_shadow (struct bp_location *bl)
  1148. {
  1149. if (bl->loc_type != bp_loc_software_breakpoint)
  1150. return 0;
  1151. if (!bl->inserted)
  1152. return 0;
  1153. if (bl->target_info.shadow_len == 0)
  1154. /* BL isn't valid, or doesn't shadow memory. */
  1155. return 0;
  1156. return 1;
  1157. }
  1158. /* Update BUF, which is LEN bytes read from the target address
  1159. MEMADDR, by replacing a memory breakpoint with its shadowed
  1160. contents.
  1161. If READBUF is not NULL, this buffer must not overlap with the of
  1162. the breakpoint location's shadow_contents buffer. Otherwise, a
  1163. failed assertion internal error will be raised. */
  1164. static void
  1165. one_breakpoint_xfer_memory (gdb_byte *readbuf, gdb_byte *writebuf,
  1166. const gdb_byte *writebuf_org,
  1167. ULONGEST memaddr, LONGEST len,
  1168. struct bp_target_info *target_info,
  1169. struct gdbarch *gdbarch)
  1170. {
  1171. /* Now do full processing of the found relevant range of elements. */
  1172. CORE_ADDR bp_addr = 0;
  1173. int bp_size = 0;
  1174. int bptoffset = 0;
  1175. if (!breakpoint_address_match (target_info->placed_address_space, 0,
  1176. current_program_space->aspace, 0))
  1177. {
  1178. /* The breakpoint is inserted in a different address space. */
  1179. return;
  1180. }
  1181. /* Addresses and length of the part of the breakpoint that
  1182. we need to copy. */
  1183. bp_addr = target_info->placed_address;
  1184. bp_size = target_info->shadow_len;
  1185. if (bp_addr + bp_size <= memaddr)
  1186. {
  1187. /* The breakpoint is entirely before the chunk of memory we are
  1188. reading. */
  1189. return;
  1190. }
  1191. if (bp_addr >= memaddr + len)
  1192. {
  1193. /* The breakpoint is entirely after the chunk of memory we are
  1194. reading. */
  1195. return;
  1196. }
  1197. /* Offset within shadow_contents. */
  1198. if (bp_addr < memaddr)
  1199. {
  1200. /* Only copy the second part of the breakpoint. */
  1201. bp_size -= memaddr - bp_addr;
  1202. bptoffset = memaddr - bp_addr;
  1203. bp_addr = memaddr;
  1204. }
  1205. if (bp_addr + bp_size > memaddr + len)
  1206. {
  1207. /* Only copy the first part of the breakpoint. */
  1208. bp_size -= (bp_addr + bp_size) - (memaddr + len);
  1209. }
  1210. if (readbuf != NULL)
  1211. {
  1212. /* Verify that the readbuf buffer does not overlap with the
  1213. shadow_contents buffer. */
  1214. gdb_assert (target_info->shadow_contents >= readbuf + len
  1215. || readbuf >= (target_info->shadow_contents
  1216. + target_info->shadow_len));
  1217. /* Update the read buffer with this inserted breakpoint's
  1218. shadow. */
  1219. memcpy (readbuf + bp_addr - memaddr,
  1220. target_info->shadow_contents + bptoffset, bp_size);
  1221. }
  1222. else
  1223. {
  1224. const unsigned char *bp;
  1225. CORE_ADDR addr = target_info->reqstd_address;
  1226. int placed_size;
  1227. /* Update the shadow with what we want to write to memory. */
  1228. memcpy (target_info->shadow_contents + bptoffset,
  1229. writebuf_org + bp_addr - memaddr, bp_size);
  1230. /* Determine appropriate breakpoint contents and size for this
  1231. address. */
  1232. bp = gdbarch_breakpoint_from_pc (gdbarch, &addr, &placed_size);
  1233. /* Update the final write buffer with this inserted
  1234. breakpoint's INSN. */
  1235. memcpy (writebuf + bp_addr - memaddr, bp + bptoffset, bp_size);
  1236. }
  1237. }
  1238. /* Update BUF, which is LEN bytes read from the target address MEMADDR,
  1239. by replacing any memory breakpoints with their shadowed contents.
  1240. If READBUF is not NULL, this buffer must not overlap with any of
  1241. the breakpoint location's shadow_contents buffers. Otherwise,
  1242. a failed assertion internal error will be raised.
  1243. The range of shadowed area by each bp_location is:
  1244. bl->address - bp_locations_placed_address_before_address_max
  1245. up to bl->address + bp_locations_shadow_len_after_address_max
  1246. The range we were requested to resolve shadows for is:
  1247. memaddr ... memaddr + len
  1248. Thus the safe cutoff boundaries for performance optimization are
  1249. memaddr + len <= (bl->address
  1250. - bp_locations_placed_address_before_address_max)
  1251. and:
  1252. bl->address + bp_locations_shadow_len_after_address_max <= memaddr */
  1253. void
  1254. breakpoint_xfer_memory (gdb_byte *readbuf, gdb_byte *writebuf,
  1255. const gdb_byte *writebuf_org,
  1256. ULONGEST memaddr, LONGEST len)
  1257. {
  1258. /* Left boundary, right boundary and median element of our binary
  1259. search. */
  1260. unsigned bc_l, bc_r, bc;
  1261. /* Find BC_L which is a leftmost element which may affect BUF
  1262. content. It is safe to report lower value but a failure to
  1263. report higher one. */
  1264. bc_l = 0;
  1265. bc_r = bp_locations.size ();
  1266. while (bc_l + 1 < bc_r)
  1267. {
  1268. struct bp_location *bl;
  1269. bc = (bc_l + bc_r) / 2;
  1270. bl = bp_locations[bc];
  1271. /* Check first BL->ADDRESS will not overflow due to the added
  1272. constant. Then advance the left boundary only if we are sure
  1273. the BC element can in no way affect the BUF content (MEMADDR
  1274. to MEMADDR + LEN range).
  1275. Use the BP_LOCATIONS_SHADOW_LEN_AFTER_ADDRESS_MAX safety
  1276. offset so that we cannot miss a breakpoint with its shadow
  1277. range tail still reaching MEMADDR. */
  1278. if ((bl->address + bp_locations_shadow_len_after_address_max
  1279. >= bl->address)
  1280. && (bl->address + bp_locations_shadow_len_after_address_max
  1281. <= memaddr))
  1282. bc_l = bc;
  1283. else
  1284. bc_r = bc;
  1285. }
  1286. /* Due to the binary search above, we need to make sure we pick the
  1287. first location that's at BC_L's address. E.g., if there are
  1288. multiple locations at the same address, BC_L may end up pointing
  1289. at a duplicate location, and miss the "master"/"inserted"
  1290. location. Say, given locations L1, L2 and L3 at addresses A and
  1291. B:
  1292. L1@A, L2@A, L3@B, ...
  1293. BC_L could end up pointing at location L2, while the "master"
  1294. location could be L1. Since the `loc->inserted' flag is only set
  1295. on "master" locations, we'd forget to restore the shadow of L1
  1296. and L2. */
  1297. while (bc_l > 0
  1298. && bp_locations[bc_l]->address == bp_locations[bc_l - 1]->address)
  1299. bc_l--;
  1300. /* Now do full processing of the found relevant range of elements. */
  1301. for (bc = bc_l; bc < bp_locations.size (); bc++)
  1302. {
  1303. struct bp_location *bl = bp_locations[bc];
  1304. /* bp_location array has BL->OWNER always non-NULL. */
  1305. if (bl->owner->type == bp_none)
  1306. warning (_("reading through apparently deleted breakpoint #%d?"),
  1307. bl->owner->number);
  1308. /* Performance optimization: any further element can no longer affect BUF
  1309. content. */
  1310. if (bl->address >= bp_locations_placed_address_before_address_max
  1311. && (memaddr + len
  1312. <= (bl->address
  1313. - bp_locations_placed_address_before_address_max)))
  1314. break;
  1315. if (!bp_location_has_shadow (bl))
  1316. continue;
  1317. one_breakpoint_xfer_memory (readbuf, writebuf, writebuf_org,
  1318. memaddr, len, &bl->target_info, bl->gdbarch);
  1319. }
  1320. }
  1321. /* See breakpoint.h. */
  1322. bool
  1323. is_breakpoint (const struct breakpoint *bpt)
  1324. {
  1325. return (bpt->type == bp_breakpoint
  1326. || bpt->type == bp_hardware_breakpoint
  1327. || bpt->type == bp_dprintf);
  1328. }
  1329. /* Return true if BPT is of any hardware watchpoint kind. */
  1330. static bool
  1331. is_hardware_watchpoint (const struct breakpoint *bpt)
  1332. {
  1333. return (bpt->type == bp_hardware_watchpoint
  1334. || bpt->type == bp_read_watchpoint
  1335. || bpt->type == bp_access_watchpoint);
  1336. }
  1337. /* See breakpoint.h. */
  1338. bool
  1339. is_watchpoint (const struct breakpoint *bpt)
  1340. {
  1341. return (is_hardware_watchpoint (bpt)
  1342. || bpt->type == bp_watchpoint);
  1343. }
  1344. /* Returns true if the current thread and its running state are safe
  1345. to evaluate or update watchpoint B. Watchpoints on local
  1346. expressions need to be evaluated in the context of the thread that
  1347. was current when the watchpoint was created, and, that thread needs
  1348. to be stopped to be able to select the correct frame context.
  1349. Watchpoints on global expressions can be evaluated on any thread,
  1350. and in any state. It is presently left to the target allowing
  1351. memory accesses when threads are running. */
  1352. static int
  1353. watchpoint_in_thread_scope (struct watchpoint *b)
  1354. {
  1355. return (b->pspace == current_program_space
  1356. && (b->watchpoint_thread == null_ptid
  1357. || (inferior_ptid == b->watchpoint_thread
  1358. && !inferior_thread ()->executing ())));
  1359. }
  1360. /* Set watchpoint B to disp_del_at_next_stop, even including its possible
  1361. associated bp_watchpoint_scope breakpoint. */
  1362. static void
  1363. watchpoint_del_at_next_stop (struct watchpoint *w)
  1364. {
  1365. if (w->related_breakpoint != w)
  1366. {
  1367. gdb_assert (w->related_breakpoint->type == bp_watchpoint_scope);
  1368. gdb_assert (w->related_breakpoint->related_breakpoint == w);
  1369. w->related_breakpoint->disposition = disp_del_at_next_stop;
  1370. w->related_breakpoint->related_breakpoint = w->related_breakpoint;
  1371. w->related_breakpoint = w;
  1372. }
  1373. w->disposition = disp_del_at_next_stop;
  1374. }
  1375. /* Extract a bitfield value from value VAL using the bit parameters contained in
  1376. watchpoint W. */
  1377. static struct value *
  1378. extract_bitfield_from_watchpoint_value (struct watchpoint *w, struct value *val)
  1379. {
  1380. struct value *bit_val;
  1381. if (val == NULL)
  1382. return NULL;
  1383. bit_val = allocate_value (value_type (val));
  1384. unpack_value_bitfield (bit_val,
  1385. w->val_bitpos,
  1386. w->val_bitsize,
  1387. value_contents_for_printing (val).data (),
  1388. value_offset (val),
  1389. val);
  1390. return bit_val;
  1391. }
  1392. /* Allocate a dummy location and add it to B, which must be a software
  1393. watchpoint. This is required because even if a software watchpoint
  1394. is not watching any memory, bpstat_stop_status requires a location
  1395. to be able to report stops. */
  1396. static void
  1397. software_watchpoint_add_no_memory_location (struct breakpoint *b,
  1398. struct program_space *pspace)
  1399. {
  1400. gdb_assert (b->type == bp_watchpoint && b->loc == NULL);
  1401. b->loc = allocate_bp_location (b);
  1402. b->loc->pspace = pspace;
  1403. b->loc->address = -1;
  1404. b->loc->length = -1;
  1405. }
  1406. /* Returns true if B is a software watchpoint that is not watching any
  1407. memory (e.g., "watch $pc"). */
  1408. static bool
  1409. is_no_memory_software_watchpoint (struct breakpoint *b)
  1410. {
  1411. return (b->type == bp_watchpoint
  1412. && b->loc != NULL
  1413. && b->loc->next == NULL
  1414. && b->loc->address == -1
  1415. && b->loc->length == -1);
  1416. }
  1417. /* Assuming that B is a watchpoint:
  1418. - Reparse watchpoint expression, if REPARSE is non-zero
  1419. - Evaluate expression and store the result in B->val
  1420. - Evaluate the condition if there is one, and store the result
  1421. in b->loc->cond.
  1422. - Update the list of values that must be watched in B->loc.
  1423. If the watchpoint disposition is disp_del_at_next_stop, then do
  1424. nothing. If this is local watchpoint that is out of scope, delete
  1425. it.
  1426. Even with `set breakpoint always-inserted on' the watchpoints are
  1427. removed + inserted on each stop here. Normal breakpoints must
  1428. never be removed because they might be missed by a running thread
  1429. when debugging in non-stop mode. On the other hand, hardware
  1430. watchpoints (is_hardware_watchpoint; processed here) are specific
  1431. to each LWP since they are stored in each LWP's hardware debug
  1432. registers. Therefore, such LWP must be stopped first in order to
  1433. be able to modify its hardware watchpoints.
  1434. Hardware watchpoints must be reset exactly once after being
  1435. presented to the user. It cannot be done sooner, because it would
  1436. reset the data used to present the watchpoint hit to the user. And
  1437. it must not be done later because it could display the same single
  1438. watchpoint hit during multiple GDB stops. Note that the latter is
  1439. relevant only to the hardware watchpoint types bp_read_watchpoint
  1440. and bp_access_watchpoint. False hit by bp_hardware_watchpoint is
  1441. not user-visible - its hit is suppressed if the memory content has
  1442. not changed.
  1443. The following constraints influence the location where we can reset
  1444. hardware watchpoints:
  1445. * target_stopped_by_watchpoint and target_stopped_data_address are
  1446. called several times when GDB stops.
  1447. [linux]
  1448. * Multiple hardware watchpoints can be hit at the same time,
  1449. causing GDB to stop. GDB only presents one hardware watchpoint
  1450. hit at a time as the reason for stopping, and all the other hits
  1451. are presented later, one after the other, each time the user
  1452. requests the execution to be resumed. Execution is not resumed
  1453. for the threads still having pending hit event stored in
  1454. LWP_INFO->STATUS. While the watchpoint is already removed from
  1455. the inferior on the first stop the thread hit event is kept being
  1456. reported from its cached value by linux_nat_stopped_data_address
  1457. until the real thread resume happens after the watchpoint gets
  1458. presented and thus its LWP_INFO->STATUS gets reset.
  1459. Therefore the hardware watchpoint hit can get safely reset on the
  1460. watchpoint removal from inferior. */
  1461. static void
  1462. update_watchpoint (struct watchpoint *b, int reparse)
  1463. {
  1464. int within_current_scope;
  1465. struct frame_id saved_frame_id;
  1466. int frame_saved;
  1467. /* If this is a local watchpoint, we only want to check if the
  1468. watchpoint frame is in scope if the current thread is the thread
  1469. that was used to create the watchpoint. */
  1470. if (!watchpoint_in_thread_scope (b))
  1471. return;
  1472. if (b->disposition == disp_del_at_next_stop)
  1473. return;
  1474. frame_saved = 0;
  1475. /* Determine if the watchpoint is within scope. */
  1476. if (b->exp_valid_block == NULL)
  1477. within_current_scope = 1;
  1478. else
  1479. {
  1480. struct frame_info *fi = get_current_frame ();
  1481. struct gdbarch *frame_arch = get_frame_arch (fi);
  1482. CORE_ADDR frame_pc = get_frame_pc (fi);
  1483. /* If we're at a point where the stack has been destroyed
  1484. (e.g. in a function epilogue), unwinding may not work
  1485. properly. Do not attempt to recreate locations at this
  1486. point. See similar comments in watchpoint_check. */
  1487. if (gdbarch_stack_frame_destroyed_p (frame_arch, frame_pc))
  1488. return;
  1489. /* Save the current frame's ID so we can restore it after
  1490. evaluating the watchpoint expression on its own frame. */
  1491. /* FIXME drow/2003-09-09: It would be nice if evaluate_expression
  1492. took a frame parameter, so that we didn't have to change the
  1493. selected frame. */
  1494. frame_saved = 1;
  1495. saved_frame_id = get_frame_id (get_selected_frame (NULL));
  1496. fi = frame_find_by_id (b->watchpoint_frame);
  1497. within_current_scope = (fi != NULL);
  1498. if (within_current_scope)
  1499. select_frame (fi);
  1500. }
  1501. /* We don't free locations. They are stored in the bp_location array
  1502. and update_global_location_list will eventually delete them and
  1503. remove breakpoints if needed. */
  1504. b->loc = NULL;
  1505. if (within_current_scope && reparse)
  1506. {
  1507. const char *s;
  1508. b->exp.reset ();
  1509. s = (b->exp_string_reparse
  1510. ? b->exp_string_reparse.get ()
  1511. : b->exp_string.get ());
  1512. b->exp = parse_exp_1 (&s, 0, b->exp_valid_block, 0);
  1513. /* If the meaning of expression itself changed, the old value is
  1514. no longer relevant. We don't want to report a watchpoint hit
  1515. to the user when the old value and the new value may actually
  1516. be completely different objects. */
  1517. b->val = NULL;
  1518. b->val_valid = false;
  1519. /* Note that unlike with breakpoints, the watchpoint's condition
  1520. expression is stored in the breakpoint object, not in the
  1521. locations (re)created below. */
  1522. if (b->cond_string != NULL)
  1523. {
  1524. b->cond_exp.reset ();
  1525. s = b->cond_string.get ();
  1526. b->cond_exp = parse_exp_1 (&s, 0, b->cond_exp_valid_block, 0);
  1527. }
  1528. }
  1529. /* If we failed to parse the expression, for example because
  1530. it refers to a global variable in a not-yet-loaded shared library,
  1531. don't try to insert watchpoint. We don't automatically delete
  1532. such watchpoint, though, since failure to parse expression
  1533. is different from out-of-scope watchpoint. */
  1534. if (!target_has_execution ())
  1535. {
  1536. /* Without execution, memory can't change. No use to try and
  1537. set watchpoint locations. The watchpoint will be reset when
  1538. the target gains execution, through breakpoint_re_set. */
  1539. if (!can_use_hw_watchpoints)
  1540. {
  1541. if (b->ops->works_in_software_mode (b))
  1542. b->type = bp_watchpoint;
  1543. else
  1544. error (_("Can't set read/access watchpoint when "
  1545. "hardware watchpoints are disabled."));
  1546. }
  1547. }
  1548. else if (within_current_scope && b->exp)
  1549. {
  1550. std::vector<value_ref_ptr> val_chain;
  1551. struct value *v, *result;
  1552. struct program_space *frame_pspace;
  1553. fetch_subexp_value (b->exp.get (), b->exp->op.get (), &v, &result,
  1554. &val_chain, false);
  1555. /* Avoid setting b->val if it's already set. The meaning of
  1556. b->val is 'the last value' user saw, and we should update
  1557. it only if we reported that last value to user. As it
  1558. happens, the code that reports it updates b->val directly.
  1559. We don't keep track of the memory value for masked
  1560. watchpoints. */
  1561. if (!b->val_valid && !is_masked_watchpoint (b))
  1562. {
  1563. if (b->val_bitsize != 0)
  1564. v = extract_bitfield_from_watchpoint_value (b, v);
  1565. b->val = release_value (v);
  1566. b->val_valid = true;
  1567. }
  1568. frame_pspace = get_frame_program_space (get_selected_frame (NULL));
  1569. /* Look at each value on the value chain. */
  1570. gdb_assert (!val_chain.empty ());
  1571. for (const value_ref_ptr &iter : val_chain)
  1572. {
  1573. v = iter.get ();
  1574. /* If it's a memory location, and GDB actually needed
  1575. its contents to evaluate the expression, then we
  1576. must watch it. If the first value returned is
  1577. still lazy, that means an error occurred reading it;
  1578. watch it anyway in case it becomes readable. */
  1579. if (VALUE_LVAL (v) == lval_memory
  1580. && (v == val_chain[0] || ! value_lazy (v)))
  1581. {
  1582. struct type *vtype = check_typedef (value_type (v));
  1583. /* We only watch structs and arrays if user asked
  1584. for it explicitly, never if they just happen to
  1585. appear in the middle of some value chain. */
  1586. if (v == result
  1587. || (vtype->code () != TYPE_CODE_STRUCT
  1588. && vtype->code () != TYPE_CODE_ARRAY))
  1589. {
  1590. CORE_ADDR addr;
  1591. enum target_hw_bp_type type;
  1592. struct bp_location *loc, **tmp;
  1593. int bitpos = 0, bitsize = 0;
  1594. if (value_bitsize (v) != 0)
  1595. {
  1596. /* Extract the bit parameters out from the bitfield
  1597. sub-expression. */
  1598. bitpos = value_bitpos (v);
  1599. bitsize = value_bitsize (v);
  1600. }
  1601. else if (v == result && b->val_bitsize != 0)
  1602. {
  1603. /* If VAL_BITSIZE != 0 then RESULT is actually a bitfield
  1604. lvalue whose bit parameters are saved in the fields
  1605. VAL_BITPOS and VAL_BITSIZE. */
  1606. bitpos = b->val_bitpos;
  1607. bitsize = b->val_bitsize;
  1608. }
  1609. addr = value_address (v);
  1610. if (bitsize != 0)
  1611. {
  1612. /* Skip the bytes that don't contain the bitfield. */
  1613. addr += bitpos / 8;
  1614. }
  1615. type = hw_write;
  1616. if (b->type == bp_read_watchpoint)
  1617. type = hw_read;
  1618. else if (b->type == bp_access_watchpoint)
  1619. type = hw_access;
  1620. loc = allocate_bp_location (b);
  1621. for (tmp = &(b->loc); *tmp != NULL; tmp = &((*tmp)->next))
  1622. ;
  1623. *tmp = loc;
  1624. loc->gdbarch = value_type (v)->arch ();
  1625. loc->pspace = frame_pspace;
  1626. loc->address = address_significant (loc->gdbarch, addr);
  1627. if (bitsize != 0)
  1628. {
  1629. /* Just cover the bytes that make up the bitfield. */
  1630. loc->length = ((bitpos % 8) + bitsize + 7) / 8;
  1631. }
  1632. else
  1633. loc->length = TYPE_LENGTH (value_type (v));
  1634. loc->watchpoint_type = type;
  1635. }
  1636. }
  1637. }
  1638. /* Change the type of breakpoint between hardware assisted or
  1639. an ordinary watchpoint depending on the hardware support
  1640. and free hardware slots. REPARSE is set when the inferior
  1641. is started. */
  1642. if (reparse)
  1643. {
  1644. int reg_cnt;
  1645. enum bp_loc_type loc_type;
  1646. reg_cnt = can_use_hardware_watchpoint (val_chain);
  1647. if (reg_cnt)
  1648. {
  1649. int i, target_resources_ok, other_type_used;
  1650. enum bptype type;
  1651. /* Use an exact watchpoint when there's only one memory region to be
  1652. watched, and only one debug register is needed to watch it. */
  1653. b->exact = target_exact_watchpoints && reg_cnt == 1;
  1654. /* We need to determine how many resources are already
  1655. used for all other hardware watchpoints plus this one
  1656. to see if we still have enough resources to also fit
  1657. this watchpoint in as well. */
  1658. /* If this is a software watchpoint, we try to turn it
  1659. to a hardware one -- count resources as if B was of
  1660. hardware watchpoint type. */
  1661. type = b->type;
  1662. if (type == bp_watchpoint)
  1663. type = bp_hardware_watchpoint;
  1664. /* This watchpoint may or may not have been placed on
  1665. the list yet at this point (it won't be in the list
  1666. if we're trying to create it for the first time,
  1667. through watch_command), so always account for it
  1668. manually. */
  1669. /* Count resources used by all watchpoints except B. */
  1670. i = hw_watchpoint_used_count_others (b, type, &other_type_used);
  1671. /* Add in the resources needed for B. */
  1672. i += hw_watchpoint_use_count (b);
  1673. target_resources_ok
  1674. = target_can_use_hardware_watchpoint (type, i, other_type_used);
  1675. if (target_resources_ok <= 0)
  1676. {
  1677. int sw_mode = b->ops->works_in_software_mode (b);
  1678. if (target_resources_ok == 0 && !sw_mode)
  1679. error (_("Target does not support this type of "
  1680. "hardware watchpoint."));
  1681. else if (target_resources_ok < 0 && !sw_mode)
  1682. error (_("There are not enough available hardware "
  1683. "resources for this watchpoint."));
  1684. /* Downgrade to software watchpoint. */
  1685. b->type = bp_watchpoint;
  1686. }
  1687. else
  1688. {
  1689. /* If this was a software watchpoint, we've just
  1690. found we have enough resources to turn it to a
  1691. hardware watchpoint. Otherwise, this is a
  1692. nop. */
  1693. b->type = type;
  1694. }
  1695. }
  1696. else if (!b->ops->works_in_software_mode (b))
  1697. {
  1698. if (!can_use_hw_watchpoints)
  1699. error (_("Can't set read/access watchpoint when "
  1700. "hardware watchpoints are disabled."));
  1701. else
  1702. error (_("Expression cannot be implemented with "
  1703. "read/access watchpoint."));
  1704. }
  1705. else
  1706. b->type = bp_watchpoint;
  1707. loc_type = (b->type == bp_watchpoint? bp_loc_other
  1708. : bp_loc_hardware_watchpoint);
  1709. for (bp_location *bl : b->locations ())
  1710. bl->loc_type = loc_type;
  1711. }
  1712. /* If a software watchpoint is not watching any memory, then the
  1713. above left it without any location set up. But,
  1714. bpstat_stop_status requires a location to be able to report
  1715. stops, so make sure there's at least a dummy one. */
  1716. if (b->type == bp_watchpoint && b->loc == NULL)
  1717. software_watchpoint_add_no_memory_location (b, frame_pspace);
  1718. }
  1719. else if (!within_current_scope)
  1720. {
  1721. gdb_printf (_("\
  1722. Watchpoint %d deleted because the program has left the block\n\
  1723. in which its expression is valid.\n"),
  1724. b->number);
  1725. watchpoint_del_at_next_stop (b);
  1726. }
  1727. /* Restore the selected frame. */
  1728. if (frame_saved)
  1729. select_frame (frame_find_by_id (saved_frame_id));
  1730. }
  1731. /* Returns 1 iff breakpoint location should be
  1732. inserted in the inferior. We don't differentiate the type of BL's owner
  1733. (breakpoint vs. tracepoint), although insert_location in tracepoint's
  1734. breakpoint_ops is not defined, because in insert_bp_location,
  1735. tracepoint's insert_location will not be called. */
  1736. static int
  1737. should_be_inserted (struct bp_location *bl)
  1738. {
  1739. if (bl->owner == NULL || !breakpoint_enabled (bl->owner))
  1740. return 0;
  1741. if (bl->owner->disposition == disp_del_at_next_stop)
  1742. return 0;
  1743. if (!bl->enabled || bl->disabled_by_cond
  1744. || bl->shlib_disabled || bl->duplicate)
  1745. return 0;
  1746. if (user_breakpoint_p (bl->owner) && bl->pspace->executing_startup)
  1747. return 0;
  1748. /* This is set for example, when we're attached to the parent of a
  1749. vfork, and have detached from the child. The child is running
  1750. free, and we expect it to do an exec or exit, at which point the
  1751. OS makes the parent schedulable again (and the target reports
  1752. that the vfork is done). Until the child is done with the shared
  1753. memory region, do not insert breakpoints in the parent, otherwise
  1754. the child could still trip on the parent's breakpoints. Since
  1755. the parent is blocked anyway, it won't miss any breakpoint. */
  1756. if (bl->pspace->breakpoints_not_allowed)
  1757. return 0;
  1758. /* Don't insert a breakpoint if we're trying to step past its
  1759. location, except if the breakpoint is a single-step breakpoint,
  1760. and the breakpoint's thread is the thread which is stepping past
  1761. a breakpoint. */
  1762. if ((bl->loc_type == bp_loc_software_breakpoint
  1763. || bl->loc_type == bp_loc_hardware_breakpoint)
  1764. && stepping_past_instruction_at (bl->pspace->aspace,
  1765. bl->address)
  1766. /* The single-step breakpoint may be inserted at the location
  1767. we're trying to step if the instruction branches to itself.
  1768. However, the instruction won't be executed at all and it may
  1769. break the semantics of the instruction, for example, the
  1770. instruction is a conditional branch or updates some flags.
  1771. We can't fix it unless GDB is able to emulate the instruction
  1772. or switch to displaced stepping. */
  1773. && !(bl->owner->type == bp_single_step
  1774. && thread_is_stepping_over_breakpoint (bl->owner->thread)))
  1775. {
  1776. infrun_debug_printf ("skipping breakpoint: stepping past insn at: %s",
  1777. paddress (bl->gdbarch, bl->address));
  1778. return 0;
  1779. }
  1780. /* Don't insert watchpoints if we're trying to step past the
  1781. instruction that triggered one. */
  1782. if ((bl->loc_type == bp_loc_hardware_watchpoint)
  1783. && stepping_past_nonsteppable_watchpoint ())
  1784. {
  1785. infrun_debug_printf ("stepping past non-steppable watchpoint. "
  1786. "skipping watchpoint at %s:%d",
  1787. paddress (bl->gdbarch, bl->address), bl->length);
  1788. return 0;
  1789. }
  1790. return 1;
  1791. }
  1792. /* Same as should_be_inserted but does the check assuming
  1793. that the location is not duplicated. */
  1794. static int
  1795. unduplicated_should_be_inserted (struct bp_location *bl)
  1796. {
  1797. int result;
  1798. const int save_duplicate = bl->duplicate;
  1799. bl->duplicate = 0;
  1800. result = should_be_inserted (bl);
  1801. bl->duplicate = save_duplicate;
  1802. return result;
  1803. }
  1804. /* Parses a conditional described by an expression COND into an
  1805. agent expression bytecode suitable for evaluation
  1806. by the bytecode interpreter. Return NULL if there was
  1807. any error during parsing. */
  1808. static agent_expr_up
  1809. parse_cond_to_aexpr (CORE_ADDR scope, struct expression *cond)
  1810. {
  1811. if (cond == NULL)
  1812. return NULL;
  1813. agent_expr_up aexpr;
  1814. /* We don't want to stop processing, so catch any errors
  1815. that may show up. */
  1816. try
  1817. {
  1818. aexpr = gen_eval_for_expr (scope, cond);
  1819. }
  1820. catch (const gdb_exception_error &ex)
  1821. {
  1822. /* If we got here, it means the condition could not be parsed to a valid
  1823. bytecode expression and thus can't be evaluated on the target's side.
  1824. It's no use iterating through the conditions. */
  1825. }
  1826. /* We have a valid agent expression. */
  1827. return aexpr;
  1828. }
  1829. /* Based on location BL, create a list of breakpoint conditions to be
  1830. passed on to the target. If we have duplicated locations with different
  1831. conditions, we will add such conditions to the list. The idea is that the
  1832. target will evaluate the list of conditions and will only notify GDB when
  1833. one of them is true. */
  1834. static void
  1835. build_target_condition_list (struct bp_location *bl)
  1836. {
  1837. int null_condition_or_parse_error = 0;
  1838. int modified = bl->needs_update;
  1839. /* Release conditions left over from a previous insert. */
  1840. bl->target_info.conditions.clear ();
  1841. /* This is only meaningful if the target is
  1842. evaluating conditions and if the user has
  1843. opted for condition evaluation on the target's
  1844. side. */
  1845. if (gdb_evaluates_breakpoint_condition_p ()
  1846. || !target_supports_evaluation_of_breakpoint_conditions ())
  1847. return;
  1848. auto loc_range = all_bp_locations_at_addr (bl->address);
  1849. /* Do a first pass to check for locations with no assigned
  1850. conditions or conditions that fail to parse to a valid agent
  1851. expression bytecode. If any of these happen, then it's no use to
  1852. send conditions to the target since this location will always
  1853. trigger and generate a response back to GDB. Note we consider
  1854. all locations at the same address irrespective of type, i.e.,
  1855. even if the locations aren't considered duplicates (e.g.,
  1856. software breakpoint and hardware breakpoint at the same
  1857. address). */
  1858. for (bp_location *loc : loc_range)
  1859. {
  1860. if (is_breakpoint (loc->owner) && loc->pspace->num == bl->pspace->num)
  1861. {
  1862. if (modified)
  1863. {
  1864. /* Re-parse the conditions since something changed. In that
  1865. case we already freed the condition bytecodes (see
  1866. force_breakpoint_reinsertion). We just
  1867. need to parse the condition to bytecodes again. */
  1868. loc->cond_bytecode = parse_cond_to_aexpr (bl->address,
  1869. loc->cond.get ());
  1870. }
  1871. /* If we have a NULL bytecode expression, it means something
  1872. went wrong or we have a null condition expression. */
  1873. if (!loc->cond_bytecode)
  1874. {
  1875. null_condition_or_parse_error = 1;
  1876. break;
  1877. }
  1878. }
  1879. }
  1880. /* If any of these happened, it means we will have to evaluate the conditions
  1881. for the location's address on gdb's side. It is no use keeping bytecodes
  1882. for all the other duplicate locations, thus we free all of them here.
  1883. This is so we have a finer control over which locations' conditions are
  1884. being evaluated by GDB or the remote stub. */
  1885. if (null_condition_or_parse_error)
  1886. {
  1887. for (bp_location *loc : loc_range)
  1888. {
  1889. if (is_breakpoint (loc->owner) && loc->pspace->num == bl->pspace->num)
  1890. {
  1891. /* Only go as far as the first NULL bytecode is
  1892. located. */
  1893. if (!loc->cond_bytecode)
  1894. return;
  1895. loc->cond_bytecode.reset ();
  1896. }
  1897. }
  1898. }
  1899. /* No NULL conditions or failed bytecode generation. Build a
  1900. condition list for this location's address. If we have software
  1901. and hardware locations at the same address, they aren't
  1902. considered duplicates, but we still marge all the conditions
  1903. anyway, as it's simpler, and doesn't really make a practical
  1904. difference. */
  1905. for (bp_location *loc : loc_range)
  1906. if (loc->cond
  1907. && is_breakpoint (loc->owner)
  1908. && loc->pspace->num == bl->pspace->num
  1909. && loc->owner->enable_state == bp_enabled
  1910. && loc->enabled
  1911. && !loc->disabled_by_cond)
  1912. {
  1913. /* Add the condition to the vector. This will be used later
  1914. to send the conditions to the target. */
  1915. bl->target_info.conditions.push_back (loc->cond_bytecode.get ());
  1916. }
  1917. return;
  1918. }
  1919. /* Parses a command described by string CMD into an agent expression
  1920. bytecode suitable for evaluation by the bytecode interpreter.
  1921. Return NULL if there was any error during parsing. */
  1922. static agent_expr_up
  1923. parse_cmd_to_aexpr (CORE_ADDR scope, char *cmd)
  1924. {
  1925. const char *cmdrest;
  1926. const char *format_start, *format_end;
  1927. struct gdbarch *gdbarch = get_current_arch ();
  1928. if (cmd == NULL)
  1929. return NULL;
  1930. cmdrest = cmd;
  1931. if (*cmdrest == ',')
  1932. ++cmdrest;
  1933. cmdrest = skip_spaces (cmdrest);
  1934. if (*cmdrest++ != '"')
  1935. error (_("No format string following the location"));
  1936. format_start = cmdrest;
  1937. format_pieces fpieces (&cmdrest);
  1938. format_end = cmdrest;
  1939. if (*cmdrest++ != '"')
  1940. error (_("Bad format string, non-terminated '\"'."));
  1941. cmdrest = skip_spaces (cmdrest);
  1942. if (!(*cmdrest == ',' || *cmdrest == '\0'))
  1943. error (_("Invalid argument syntax"));
  1944. if (*cmdrest == ',')
  1945. cmdrest++;
  1946. cmdrest = skip_spaces (cmdrest);
  1947. /* For each argument, make an expression. */
  1948. std::vector<struct expression *> argvec;
  1949. while (*cmdrest != '\0')
  1950. {
  1951. const char *cmd1;
  1952. cmd1 = cmdrest;
  1953. expression_up expr = parse_exp_1 (&cmd1, scope, block_for_pc (scope), 1);
  1954. argvec.push_back (expr.release ());
  1955. cmdrest = cmd1;
  1956. if (*cmdrest == ',')
  1957. ++cmdrest;
  1958. }
  1959. agent_expr_up aexpr;
  1960. /* We don't want to stop processing, so catch any errors
  1961. that may show up. */
  1962. try
  1963. {
  1964. aexpr = gen_printf (scope, gdbarch, 0, 0,
  1965. format_start, format_end - format_start,
  1966. argvec.size (), argvec.data ());
  1967. }
  1968. catch (const gdb_exception_error &ex)
  1969. {
  1970. /* If we got here, it means the command could not be parsed to a valid
  1971. bytecode expression and thus can't be evaluated on the target's side.
  1972. It's no use iterating through the other commands. */
  1973. }
  1974. /* We have a valid agent expression, return it. */
  1975. return aexpr;
  1976. }
  1977. /* Based on location BL, create a list of breakpoint commands to be
  1978. passed on to the target. If we have duplicated locations with
  1979. different commands, we will add any such to the list. */
  1980. static void
  1981. build_target_command_list (struct bp_location *bl)
  1982. {
  1983. int null_command_or_parse_error = 0;
  1984. int modified = bl->needs_update;
  1985. /* Clear commands left over from a previous insert. */
  1986. bl->target_info.tcommands.clear ();
  1987. if (!target_can_run_breakpoint_commands ())
  1988. return;
  1989. /* For now, limit to agent-style dprintf breakpoints. */
  1990. if (dprintf_style != dprintf_style_agent)
  1991. return;
  1992. auto loc_range = all_bp_locations_at_addr (bl->address);
  1993. /* For now, if we have any location at the same address that isn't a
  1994. dprintf, don't install the target-side commands, as that would
  1995. make the breakpoint not be reported to the core, and we'd lose
  1996. control. */
  1997. for (bp_location *loc : loc_range)
  1998. if (is_breakpoint (loc->owner)
  1999. && loc->pspace->num == bl->pspace->num
  2000. && loc->owner->type != bp_dprintf)
  2001. return;
  2002. /* Do a first pass to check for locations with no assigned
  2003. conditions or conditions that fail to parse to a valid agent expression
  2004. bytecode. If any of these happen, then it's no use to send conditions
  2005. to the target since this location will always trigger and generate a
  2006. response back to GDB. */
  2007. for (bp_location *loc : loc_range)
  2008. {
  2009. if (is_breakpoint (loc->owner) && loc->pspace->num == bl->pspace->num)
  2010. {
  2011. if (modified)
  2012. {
  2013. /* Re-parse the commands since something changed. In that
  2014. case we already freed the command bytecodes (see
  2015. force_breakpoint_reinsertion). We just
  2016. need to parse the command to bytecodes again. */
  2017. loc->cmd_bytecode
  2018. = parse_cmd_to_aexpr (bl->address,
  2019. loc->owner->extra_string.get ());
  2020. }
  2021. /* If we have a NULL bytecode expression, it means something
  2022. went wrong or we have a null command expression. */
  2023. if (!loc->cmd_bytecode)
  2024. {
  2025. null_command_or_parse_error = 1;
  2026. break;
  2027. }
  2028. }
  2029. }
  2030. /* If anything failed, then we're not doing target-side commands,
  2031. and so clean up. */
  2032. if (null_command_or_parse_error)
  2033. {
  2034. for (bp_location *loc : loc_range)
  2035. if (is_breakpoint (loc->owner)
  2036. && loc->pspace->num == bl->pspace->num)
  2037. {
  2038. /* Only go as far as the first NULL bytecode is
  2039. located. */
  2040. if (loc->cmd_bytecode == NULL)
  2041. return;
  2042. loc->cmd_bytecode.reset ();
  2043. }
  2044. }
  2045. /* No NULL commands or failed bytecode generation. Build a command
  2046. list for all duplicate locations at this location's address.
  2047. Note that here we must care for whether the breakpoint location
  2048. types are considered duplicates, otherwise, say, if we have a
  2049. software and hardware location at the same address, the target
  2050. could end up running the commands twice. For the moment, we only
  2051. support targets-side commands with dprintf, but it doesn't hurt
  2052. to be pedantically correct in case that changes. */
  2053. for (bp_location *loc : loc_range)
  2054. if (breakpoint_locations_match (bl, loc)
  2055. && loc->owner->extra_string
  2056. && is_breakpoint (loc->owner)
  2057. && loc->pspace->num == bl->pspace->num
  2058. && loc->owner->enable_state == bp_enabled
  2059. && loc->enabled
  2060. && !loc->disabled_by_cond)
  2061. {
  2062. /* Add the command to the vector. This will be used later
  2063. to send the commands to the target. */
  2064. bl->target_info.tcommands.push_back (loc->cmd_bytecode.get ());
  2065. }
  2066. bl->target_info.persist = 0;
  2067. /* Maybe flag this location as persistent. */
  2068. if (bl->owner->type == bp_dprintf && disconnected_dprintf)
  2069. bl->target_info.persist = 1;
  2070. }
  2071. /* Return the kind of breakpoint on address *ADDR. Get the kind
  2072. of breakpoint according to ADDR except single-step breakpoint.
  2073. Get the kind of single-step breakpoint according to the current
  2074. registers state. */
  2075. static int
  2076. breakpoint_kind (struct bp_location *bl, CORE_ADDR *addr)
  2077. {
  2078. if (bl->owner->type == bp_single_step)
  2079. {
  2080. struct thread_info *thr = find_thread_global_id (bl->owner->thread);
  2081. struct regcache *regcache;
  2082. regcache = get_thread_regcache (thr);
  2083. return gdbarch_breakpoint_kind_from_current_state (bl->gdbarch,
  2084. regcache, addr);
  2085. }
  2086. else
  2087. return gdbarch_breakpoint_kind_from_pc (bl->gdbarch, addr);
  2088. }
  2089. /* Insert a low-level "breakpoint" of some type. BL is the breakpoint
  2090. location. Any error messages are printed to TMP_ERROR_STREAM; and
  2091. DISABLED_BREAKS, and HW_BREAKPOINT_ERROR are used to report problems.
  2092. Returns 0 for success, 1 if the bp_location type is not supported or
  2093. -1 for failure.
  2094. NOTE drow/2003-09-09: This routine could be broken down to an
  2095. object-style method for each breakpoint or catchpoint type. */
  2096. static int
  2097. insert_bp_location (struct bp_location *bl,
  2098. struct ui_file *tmp_error_stream,
  2099. int *disabled_breaks,
  2100. int *hw_breakpoint_error,
  2101. int *hw_bp_error_explained_already)
  2102. {
  2103. gdb_exception bp_excpt;
  2104. if (!should_be_inserted (bl) || (bl->inserted && !bl->needs_update))
  2105. return 0;
  2106. /* Note we don't initialize bl->target_info, as that wipes out
  2107. the breakpoint location's shadow_contents if the breakpoint
  2108. is still inserted at that location. This in turn breaks
  2109. target_read_memory which depends on these buffers when
  2110. a memory read is requested at the breakpoint location:
  2111. Once the target_info has been wiped, we fail to see that
  2112. we have a breakpoint inserted at that address and thus
  2113. read the breakpoint instead of returning the data saved in
  2114. the breakpoint location's shadow contents. */
  2115. bl->target_info.reqstd_address = bl->address;
  2116. bl->target_info.placed_address_space = bl->pspace->aspace;
  2117. bl->target_info.length = bl->length;
  2118. /* When working with target-side conditions, we must pass all the conditions
  2119. for the same breakpoint address down to the target since GDB will not
  2120. insert those locations. With a list of breakpoint conditions, the target
  2121. can decide when to stop and notify GDB. */
  2122. if (is_breakpoint (bl->owner))
  2123. {
  2124. build_target_condition_list (bl);
  2125. build_target_command_list (bl);
  2126. /* Reset the modification marker. */
  2127. bl->needs_update = 0;
  2128. }
  2129. /* If "set breakpoint auto-hw" is "on" and a software breakpoint was
  2130. set at a read-only address, then a breakpoint location will have
  2131. been changed to hardware breakpoint before we get here. If it is
  2132. "off" however, error out before actually trying to insert the
  2133. breakpoint, with a nicer error message. */
  2134. if (bl->loc_type == bp_loc_software_breakpoint
  2135. && !automatic_hardware_breakpoints)
  2136. {
  2137. mem_region *mr = lookup_mem_region (bl->address);
  2138. if (mr != nullptr && mr->attrib.mode != MEM_RW)
  2139. {
  2140. gdb_printf (tmp_error_stream,
  2141. _("Cannot insert breakpoint %d.\n"
  2142. "Cannot set software breakpoint "
  2143. "at read-only address %s\n"),
  2144. bl->owner->number,
  2145. paddress (bl->gdbarch, bl->address));
  2146. return 1;
  2147. }
  2148. }
  2149. if (bl->loc_type == bp_loc_software_breakpoint
  2150. || bl->loc_type == bp_loc_hardware_breakpoint)
  2151. {
  2152. /* First check to see if we have to handle an overlay. */
  2153. if (overlay_debugging == ovly_off
  2154. || bl->section == NULL
  2155. || !(section_is_overlay (bl->section)))
  2156. {
  2157. /* No overlay handling: just set the breakpoint. */
  2158. try
  2159. {
  2160. int val;
  2161. val = bl->owner->ops->insert_location (bl);
  2162. if (val)
  2163. bp_excpt = gdb_exception {RETURN_ERROR, GENERIC_ERROR};
  2164. }
  2165. catch (gdb_exception &e)
  2166. {
  2167. bp_excpt = std::move (e);
  2168. }
  2169. }
  2170. else
  2171. {
  2172. /* This breakpoint is in an overlay section.
  2173. Shall we set a breakpoint at the LMA? */
  2174. if (!overlay_events_enabled)
  2175. {
  2176. /* Yes -- overlay event support is not active,
  2177. so we must try to set a breakpoint at the LMA.
  2178. This will not work for a hardware breakpoint. */
  2179. if (bl->loc_type == bp_loc_hardware_breakpoint)
  2180. warning (_("hardware breakpoint %d not supported in overlay!"),
  2181. bl->owner->number);
  2182. else
  2183. {
  2184. CORE_ADDR addr = overlay_unmapped_address (bl->address,
  2185. bl->section);
  2186. /* Set a software (trap) breakpoint at the LMA. */
  2187. bl->overlay_target_info = bl->target_info;
  2188. bl->overlay_target_info.reqstd_address = addr;
  2189. /* No overlay handling: just set the breakpoint. */
  2190. try
  2191. {
  2192. int val;
  2193. bl->overlay_target_info.kind
  2194. = breakpoint_kind (bl, &addr);
  2195. bl->overlay_target_info.placed_address = addr;
  2196. val = target_insert_breakpoint (bl->gdbarch,
  2197. &bl->overlay_target_info);
  2198. if (val)
  2199. bp_excpt
  2200. = gdb_exception {RETURN_ERROR, GENERIC_ERROR};
  2201. }
  2202. catch (gdb_exception &e)
  2203. {
  2204. bp_excpt = std::move (e);
  2205. }
  2206. if (bp_excpt.reason != 0)
  2207. gdb_printf (tmp_error_stream,
  2208. "Overlay breakpoint %d "
  2209. "failed: in ROM?\n",
  2210. bl->owner->number);
  2211. }
  2212. }
  2213. /* Shall we set a breakpoint at the VMA? */
  2214. if (section_is_mapped (bl->section))
  2215. {
  2216. /* Yes. This overlay section is mapped into memory. */
  2217. try
  2218. {
  2219. int val;
  2220. val = bl->owner->ops->insert_location (bl);
  2221. if (val)
  2222. bp_excpt = gdb_exception {RETURN_ERROR, GENERIC_ERROR};
  2223. }
  2224. catch (gdb_exception &e)
  2225. {
  2226. bp_excpt = std::move (e);
  2227. }
  2228. }
  2229. else
  2230. {
  2231. /* No. This breakpoint will not be inserted.
  2232. No error, but do not mark the bp as 'inserted'. */
  2233. return 0;
  2234. }
  2235. }
  2236. if (bp_excpt.reason != 0)
  2237. {
  2238. /* Can't set the breakpoint. */
  2239. /* If the target has closed then it will have deleted any
  2240. breakpoints inserted within the target inferior, as a result
  2241. any further attempts to interact with the breakpoint objects
  2242. is not possible. Just rethrow the error. */
  2243. if (bp_excpt.error == TARGET_CLOSE_ERROR)
  2244. throw bp_excpt;
  2245. gdb_assert (bl->owner != nullptr);
  2246. /* In some cases, we might not be able to insert a
  2247. breakpoint in a shared library that has already been
  2248. removed, but we have not yet processed the shlib unload
  2249. event. Unfortunately, some targets that implement
  2250. breakpoint insertion themselves can't tell why the
  2251. breakpoint insertion failed (e.g., the remote target
  2252. doesn't define error codes), so we must treat generic
  2253. errors as memory errors. */
  2254. if (bp_excpt.reason == RETURN_ERROR
  2255. && (bp_excpt.error == GENERIC_ERROR
  2256. || bp_excpt.error == MEMORY_ERROR)
  2257. && bl->loc_type == bp_loc_software_breakpoint
  2258. && (solib_name_from_address (bl->pspace, bl->address)
  2259. || shared_objfile_contains_address_p (bl->pspace,
  2260. bl->address)))
  2261. {
  2262. /* See also: disable_breakpoints_in_shlibs. */
  2263. bl->shlib_disabled = 1;
  2264. gdb::observers::breakpoint_modified.notify (bl->owner);
  2265. if (!*disabled_breaks)
  2266. {
  2267. gdb_printf (tmp_error_stream,
  2268. "Cannot insert breakpoint %d.\n",
  2269. bl->owner->number);
  2270. gdb_printf (tmp_error_stream,
  2271. "Temporarily disabling shared "
  2272. "library breakpoints:\n");
  2273. }
  2274. *disabled_breaks = 1;
  2275. gdb_printf (tmp_error_stream,
  2276. "breakpoint #%d\n", bl->owner->number);
  2277. return 0;
  2278. }
  2279. else
  2280. {
  2281. if (bl->loc_type == bp_loc_hardware_breakpoint)
  2282. {
  2283. *hw_breakpoint_error = 1;
  2284. *hw_bp_error_explained_already = bp_excpt.message != NULL;
  2285. gdb_printf (tmp_error_stream,
  2286. "Cannot insert hardware breakpoint %d%s",
  2287. bl->owner->number,
  2288. bp_excpt.message ? ":" : ".\n");
  2289. if (bp_excpt.message != NULL)
  2290. gdb_printf (tmp_error_stream, "%s.\n",
  2291. bp_excpt.what ());
  2292. }
  2293. else
  2294. {
  2295. if (bp_excpt.message == NULL)
  2296. {
  2297. std::string message
  2298. = memory_error_message (TARGET_XFER_E_IO,
  2299. bl->gdbarch, bl->address);
  2300. gdb_printf (tmp_error_stream,
  2301. "Cannot insert breakpoint %d.\n"
  2302. "%s\n",
  2303. bl->owner->number, message.c_str ());
  2304. }
  2305. else
  2306. {
  2307. gdb_printf (tmp_error_stream,
  2308. "Cannot insert breakpoint %d: %s\n",
  2309. bl->owner->number,
  2310. bp_excpt.what ());
  2311. }
  2312. }
  2313. return 1;
  2314. }
  2315. }
  2316. else
  2317. bl->inserted = 1;
  2318. return 0;
  2319. }
  2320. else if (bl->loc_type == bp_loc_hardware_watchpoint
  2321. /* NOTE drow/2003-09-08: This state only exists for removing
  2322. watchpoints. It's not clear that it's necessary... */
  2323. && bl->owner->disposition != disp_del_at_next_stop)
  2324. {
  2325. int val;
  2326. gdb_assert (bl->owner->ops != NULL
  2327. && bl->owner->ops->insert_location != NULL);
  2328. val = bl->owner->ops->insert_location (bl);
  2329. /* If trying to set a read-watchpoint, and it turns out it's not
  2330. supported, try emulating one with an access watchpoint. */
  2331. if (val == 1 && bl->watchpoint_type == hw_read)
  2332. {
  2333. /* But don't try to insert it, if there's already another
  2334. hw_access location that would be considered a duplicate
  2335. of this one. */
  2336. for (bp_location *loc : all_bp_locations ())
  2337. if (loc != bl
  2338. && loc->watchpoint_type == hw_access
  2339. && watchpoint_locations_match (bl, loc))
  2340. {
  2341. bl->duplicate = 1;
  2342. bl->inserted = 1;
  2343. bl->target_info = loc->target_info;
  2344. bl->watchpoint_type = hw_access;
  2345. val = 0;
  2346. break;
  2347. }
  2348. if (val == 1)
  2349. {
  2350. bl->watchpoint_type = hw_access;
  2351. val = bl->owner->ops->insert_location (bl);
  2352. if (val)
  2353. /* Back to the original value. */
  2354. bl->watchpoint_type = hw_read;
  2355. }
  2356. }
  2357. bl->inserted = (val == 0);
  2358. }
  2359. else if (bl->owner->type == bp_catchpoint)
  2360. {
  2361. int val;
  2362. gdb_assert (bl->owner->ops != NULL
  2363. && bl->owner->ops->insert_location != NULL);
  2364. val = bl->owner->ops->insert_location (bl);
  2365. if (val)
  2366. {
  2367. bl->owner->enable_state = bp_disabled;
  2368. if (val == 1)
  2369. warning (_("\
  2370. Error inserting catchpoint %d: Your system does not support this type\n\
  2371. of catchpoint."), bl->owner->number);
  2372. else
  2373. warning (_("Error inserting catchpoint %d."), bl->owner->number);
  2374. }
  2375. bl->inserted = (val == 0);
  2376. /* We've already printed an error message if there was a problem
  2377. inserting this catchpoint, and we've disabled the catchpoint,
  2378. so just return success. */
  2379. return 0;
  2380. }
  2381. return 0;
  2382. }
  2383. /* This function is called when program space PSPACE is about to be
  2384. deleted. It takes care of updating breakpoints to not reference
  2385. PSPACE anymore. */
  2386. void
  2387. breakpoint_program_space_exit (struct program_space *pspace)
  2388. {
  2389. /* Remove any breakpoint that was set through this program space. */
  2390. for (breakpoint *b : all_breakpoints_safe ())
  2391. if (b->pspace == pspace)
  2392. delete_breakpoint (b);
  2393. /* Breakpoints set through other program spaces could have locations
  2394. bound to PSPACE as well. Remove those. */
  2395. for (bp_location *loc : all_bp_locations ())
  2396. {
  2397. struct bp_location *tmp;
  2398. if (loc->pspace == pspace)
  2399. {
  2400. /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always non-NULL. */
  2401. if (loc->owner->loc == loc)
  2402. loc->owner->loc = loc->next;
  2403. else
  2404. for (tmp = loc->owner->loc; tmp->next != NULL; tmp = tmp->next)
  2405. if (tmp->next == loc)
  2406. {
  2407. tmp->next = loc->next;
  2408. break;
  2409. }
  2410. }
  2411. }
  2412. /* Now update the global location list to permanently delete the
  2413. removed locations above. */
  2414. update_global_location_list (UGLL_DONT_INSERT);
  2415. }
  2416. /* Make sure all breakpoints are inserted in inferior.
  2417. Throws exception on any error.
  2418. A breakpoint that is already inserted won't be inserted
  2419. again, so calling this function twice is safe. */
  2420. void
  2421. insert_breakpoints (void)
  2422. {
  2423. for (breakpoint *bpt : all_breakpoints ())
  2424. if (is_hardware_watchpoint (bpt))
  2425. {
  2426. struct watchpoint *w = (struct watchpoint *) bpt;
  2427. update_watchpoint (w, 0 /* don't reparse. */);
  2428. }
  2429. /* Updating watchpoints creates new locations, so update the global
  2430. location list. Explicitly tell ugll to insert locations and
  2431. ignore breakpoints_always_inserted_mode. Also,
  2432. update_global_location_list tries to "upgrade" software
  2433. breakpoints to hardware breakpoints to handle "set breakpoint
  2434. auto-hw", so we need to call it even if we don't have new
  2435. locations. */
  2436. update_global_location_list (UGLL_INSERT);
  2437. }
  2438. /* This is used when we need to synch breakpoint conditions between GDB and the
  2439. target. It is the case with deleting and disabling of breakpoints when using
  2440. always-inserted mode. */
  2441. static void
  2442. update_inserted_breakpoint_locations (void)
  2443. {
  2444. int error_flag = 0;
  2445. int val = 0;
  2446. int disabled_breaks = 0;
  2447. int hw_breakpoint_error = 0;
  2448. int hw_bp_details_reported = 0;
  2449. string_file tmp_error_stream;
  2450. /* Explicitly mark the warning -- this will only be printed if
  2451. there was an error. */
  2452. tmp_error_stream.puts ("Warning:\n");
  2453. scoped_restore_current_pspace_and_thread restore_pspace_thread;
  2454. for (bp_location *bl : all_bp_locations ())
  2455. {
  2456. /* We only want to update software breakpoints and hardware
  2457. breakpoints. */
  2458. if (!is_breakpoint (bl->owner))
  2459. continue;
  2460. /* We only want to update locations that are already inserted
  2461. and need updating. This is to avoid unwanted insertion during
  2462. deletion of breakpoints. */
  2463. if (!bl->inserted || !bl->needs_update)
  2464. continue;
  2465. switch_to_program_space_and_thread (bl->pspace);
  2466. /* For targets that support global breakpoints, there's no need
  2467. to select an inferior to insert breakpoint to. In fact, even
  2468. if we aren't attached to any process yet, we should still
  2469. insert breakpoints. */
  2470. if (!gdbarch_has_global_breakpoints (target_gdbarch ())
  2471. && (inferior_ptid == null_ptid || !target_has_execution ()))
  2472. continue;
  2473. val = insert_bp_location (bl, &tmp_error_stream, &disabled_breaks,
  2474. &hw_breakpoint_error, &hw_bp_details_reported);
  2475. if (val)
  2476. error_flag = val;
  2477. }
  2478. if (error_flag)
  2479. {
  2480. target_terminal::ours_for_output ();
  2481. error_stream (tmp_error_stream);
  2482. }
  2483. }
  2484. /* Used when starting or continuing the program. */
  2485. static void
  2486. insert_breakpoint_locations (void)
  2487. {
  2488. int error_flag = 0;
  2489. int val = 0;
  2490. int disabled_breaks = 0;
  2491. int hw_breakpoint_error = 0;
  2492. int hw_bp_error_explained_already = 0;
  2493. string_file tmp_error_stream;
  2494. /* Explicitly mark the warning -- this will only be printed if
  2495. there was an error. */
  2496. tmp_error_stream.puts ("Warning:\n");
  2497. scoped_restore_current_pspace_and_thread restore_pspace_thread;
  2498. for (bp_location *bl : all_bp_locations ())
  2499. {
  2500. if (!should_be_inserted (bl) || (bl->inserted && !bl->needs_update))
  2501. continue;
  2502. /* There is no point inserting thread-specific breakpoints if
  2503. the thread no longer exists. ALL_BP_LOCATIONS bp_location
  2504. has BL->OWNER always non-NULL. */
  2505. if (bl->owner->thread != -1
  2506. && !valid_global_thread_id (bl->owner->thread))
  2507. continue;
  2508. switch_to_program_space_and_thread (bl->pspace);
  2509. /* For targets that support global breakpoints, there's no need
  2510. to select an inferior to insert breakpoint to. In fact, even
  2511. if we aren't attached to any process yet, we should still
  2512. insert breakpoints. */
  2513. if (!gdbarch_has_global_breakpoints (target_gdbarch ())
  2514. && (inferior_ptid == null_ptid || !target_has_execution ()))
  2515. continue;
  2516. val = insert_bp_location (bl, &tmp_error_stream, &disabled_breaks,
  2517. &hw_breakpoint_error, &hw_bp_error_explained_already);
  2518. if (val)
  2519. error_flag = val;
  2520. }
  2521. /* If we failed to insert all locations of a watchpoint, remove
  2522. them, as half-inserted watchpoint is of limited use. */
  2523. for (breakpoint *bpt : all_breakpoints ())
  2524. {
  2525. int some_failed = 0;
  2526. if (!is_hardware_watchpoint (bpt))
  2527. continue;
  2528. if (!breakpoint_enabled (bpt))
  2529. continue;
  2530. if (bpt->disposition == disp_del_at_next_stop)
  2531. continue;
  2532. for (bp_location *loc : bpt->locations ())
  2533. if (!loc->inserted && should_be_inserted (loc))
  2534. {
  2535. some_failed = 1;
  2536. break;
  2537. }
  2538. if (some_failed)
  2539. {
  2540. for (bp_location *loc : bpt->locations ())
  2541. if (loc->inserted)
  2542. remove_breakpoint (loc);
  2543. hw_breakpoint_error = 1;
  2544. tmp_error_stream.printf ("Could not insert "
  2545. "hardware watchpoint %d.\n",
  2546. bpt->number);
  2547. error_flag = -1;
  2548. }
  2549. }
  2550. if (error_flag)
  2551. {
  2552. /* If a hardware breakpoint or watchpoint was inserted, add a
  2553. message about possibly exhausted resources. */
  2554. if (hw_breakpoint_error && !hw_bp_error_explained_already)
  2555. {
  2556. tmp_error_stream.printf ("Could not insert hardware breakpoints:\n\
  2557. You may have requested too many hardware breakpoints/watchpoints.\n");
  2558. }
  2559. target_terminal::ours_for_output ();
  2560. error_stream (tmp_error_stream);
  2561. }
  2562. }
  2563. /* Used when the program stops.
  2564. Returns zero if successful, or non-zero if there was a problem
  2565. removing a breakpoint location. */
  2566. int
  2567. remove_breakpoints (void)
  2568. {
  2569. int val = 0;
  2570. for (bp_location *bl : all_bp_locations ())
  2571. if (bl->inserted && !is_tracepoint (bl->owner))
  2572. val |= remove_breakpoint (bl);
  2573. return val;
  2574. }
  2575. /* When a thread exits, remove breakpoints that are related to
  2576. that thread. */
  2577. static void
  2578. remove_threaded_breakpoints (struct thread_info *tp, int silent)
  2579. {
  2580. for (breakpoint *b : all_breakpoints_safe ())
  2581. {
  2582. if (b->thread == tp->global_num && user_breakpoint_p (b))
  2583. {
  2584. b->disposition = disp_del_at_next_stop;
  2585. gdb_printf (_("\
  2586. Thread-specific breakpoint %d deleted - thread %s no longer in the thread list.\n"),
  2587. b->number, print_thread_id (tp));
  2588. /* Hide it from the user. */
  2589. b->number = 0;
  2590. }
  2591. }
  2592. }
  2593. /* See breakpoint.h. */
  2594. void
  2595. remove_breakpoints_inf (inferior *inf)
  2596. {
  2597. int val;
  2598. for (bp_location *bl : all_bp_locations ())
  2599. {
  2600. if (bl->pspace != inf->pspace)
  2601. continue;
  2602. if (bl->inserted && !bl->target_info.persist)
  2603. {
  2604. val = remove_breakpoint (bl);
  2605. if (val != 0)
  2606. return;
  2607. }
  2608. }
  2609. }
  2610. static int internal_breakpoint_number = -1;
  2611. /* Set the breakpoint number of B, depending on the value of INTERNAL.
  2612. If INTERNAL is non-zero, the breakpoint number will be populated
  2613. from internal_breakpoint_number and that variable decremented.
  2614. Otherwise the breakpoint number will be populated from
  2615. breakpoint_count and that value incremented. Internal breakpoints
  2616. do not set the internal var bpnum. */
  2617. static void
  2618. set_breakpoint_number (int internal, struct breakpoint *b)
  2619. {
  2620. if (internal)
  2621. b->number = internal_breakpoint_number--;
  2622. else
  2623. {
  2624. set_breakpoint_count (breakpoint_count + 1);
  2625. b->number = breakpoint_count;
  2626. }
  2627. }
  2628. static struct breakpoint *
  2629. create_internal_breakpoint (struct gdbarch *gdbarch,
  2630. CORE_ADDR address, enum bptype type,
  2631. const struct breakpoint_ops *ops)
  2632. {
  2633. symtab_and_line sal;
  2634. sal.pc = address;
  2635. sal.section = find_pc_overlay (sal.pc);
  2636. sal.pspace = current_program_space;
  2637. breakpoint *b = set_raw_breakpoint (gdbarch, sal, type, ops);
  2638. b->number = internal_breakpoint_number--;
  2639. b->disposition = disp_donttouch;
  2640. return b;
  2641. }
  2642. static const char *const longjmp_names[] =
  2643. {
  2644. "longjmp", "_longjmp", "siglongjmp", "_siglongjmp"
  2645. };
  2646. #define NUM_LONGJMP_NAMES ARRAY_SIZE(longjmp_names)
  2647. /* Per-objfile data private to breakpoint.c. */
  2648. struct breakpoint_objfile_data
  2649. {
  2650. /* Minimal symbol for "_ovly_debug_event" (if any). */
  2651. struct bound_minimal_symbol overlay_msym;
  2652. /* Minimal symbol(s) for "longjmp", "siglongjmp", etc. (if any). */
  2653. struct bound_minimal_symbol longjmp_msym[NUM_LONGJMP_NAMES];
  2654. /* True if we have looked for longjmp probes. */
  2655. int longjmp_searched = 0;
  2656. /* SystemTap probe points for longjmp (if any). These are non-owning
  2657. references. */
  2658. std::vector<probe *> longjmp_probes;
  2659. /* Minimal symbol for "std::terminate()" (if any). */
  2660. struct bound_minimal_symbol terminate_msym;
  2661. /* Minimal symbol for "_Unwind_DebugHook" (if any). */
  2662. struct bound_minimal_symbol exception_msym;
  2663. /* True if we have looked for exception probes. */
  2664. int exception_searched = 0;
  2665. /* SystemTap probe points for unwinding (if any). These are non-owning
  2666. references. */
  2667. std::vector<probe *> exception_probes;
  2668. };
  2669. static const struct objfile_key<breakpoint_objfile_data>
  2670. breakpoint_objfile_key;
  2671. /* Minimal symbol not found sentinel. */
  2672. static struct minimal_symbol msym_not_found;
  2673. /* Returns TRUE if MSYM point to the "not found" sentinel. */
  2674. static int
  2675. msym_not_found_p (const struct minimal_symbol *msym)
  2676. {
  2677. return msym == &msym_not_found;
  2678. }
  2679. /* Return per-objfile data needed by breakpoint.c.
  2680. Allocate the data if necessary. */
  2681. static struct breakpoint_objfile_data *
  2682. get_breakpoint_objfile_data (struct objfile *objfile)
  2683. {
  2684. struct breakpoint_objfile_data *bp_objfile_data;
  2685. bp_objfile_data = breakpoint_objfile_key.get (objfile);
  2686. if (bp_objfile_data == NULL)
  2687. bp_objfile_data = breakpoint_objfile_key.emplace (objfile);
  2688. return bp_objfile_data;
  2689. }
  2690. static void
  2691. create_overlay_event_breakpoint (void)
  2692. {
  2693. const char *const func_name = "_ovly_debug_event";
  2694. for (objfile *objfile : current_program_space->objfiles ())
  2695. {
  2696. struct breakpoint *b;
  2697. struct breakpoint_objfile_data *bp_objfile_data;
  2698. CORE_ADDR addr;
  2699. struct explicit_location explicit_loc;
  2700. bp_objfile_data = get_breakpoint_objfile_data (objfile);
  2701. if (msym_not_found_p (bp_objfile_data->overlay_msym.minsym))
  2702. continue;
  2703. if (bp_objfile_data->overlay_msym.minsym == NULL)
  2704. {
  2705. struct bound_minimal_symbol m;
  2706. m = lookup_minimal_symbol_text (func_name, objfile);
  2707. if (m.minsym == NULL)
  2708. {
  2709. /* Avoid future lookups in this objfile. */
  2710. bp_objfile_data->overlay_msym.minsym = &msym_not_found;
  2711. continue;
  2712. }
  2713. bp_objfile_data->overlay_msym = m;
  2714. }
  2715. addr = BMSYMBOL_VALUE_ADDRESS (bp_objfile_data->overlay_msym);
  2716. b = create_internal_breakpoint (objfile->arch (), addr,
  2717. bp_overlay_event,
  2718. &internal_breakpoint_ops);
  2719. initialize_explicit_location (&explicit_loc);
  2720. explicit_loc.function_name = ASTRDUP (func_name);
  2721. b->location = new_explicit_location (&explicit_loc);
  2722. if (overlay_debugging == ovly_auto)
  2723. {
  2724. b->enable_state = bp_enabled;
  2725. overlay_events_enabled = 1;
  2726. }
  2727. else
  2728. {
  2729. b->enable_state = bp_disabled;
  2730. overlay_events_enabled = 0;
  2731. }
  2732. }
  2733. }
  2734. /* Install a master longjmp breakpoint for OBJFILE using a probe. Return
  2735. true if a breakpoint was installed. */
  2736. static bool
  2737. create_longjmp_master_breakpoint_probe (objfile *objfile)
  2738. {
  2739. struct gdbarch *gdbarch = objfile->arch ();
  2740. struct breakpoint_objfile_data *bp_objfile_data
  2741. = get_breakpoint_objfile_data (objfile);
  2742. if (!bp_objfile_data->longjmp_searched)
  2743. {
  2744. std::vector<probe *> ret
  2745. = find_probes_in_objfile (objfile, "libc", "longjmp");
  2746. if (!ret.empty ())
  2747. {
  2748. /* We are only interested in checking one element. */
  2749. probe *p = ret[0];
  2750. if (!p->can_evaluate_arguments ())
  2751. {
  2752. /* We cannot use the probe interface here,
  2753. because it does not know how to evaluate
  2754. arguments. */
  2755. ret.clear ();
  2756. }
  2757. }
  2758. bp_objfile_data->longjmp_probes = ret;
  2759. bp_objfile_data->longjmp_searched = 1;
  2760. }
  2761. if (bp_objfile_data->longjmp_probes.empty ())
  2762. return false;
  2763. for (probe *p : bp_objfile_data->longjmp_probes)
  2764. {
  2765. struct breakpoint *b;
  2766. b = create_internal_breakpoint (gdbarch,
  2767. p->get_relocated_address (objfile),
  2768. bp_longjmp_master,
  2769. &internal_breakpoint_ops);
  2770. b->location = new_probe_location ("-probe-stap libc:longjmp");
  2771. b->enable_state = bp_disabled;
  2772. }
  2773. return true;
  2774. }
  2775. /* Install master longjmp breakpoints for OBJFILE using longjmp_names.
  2776. Return true if at least one breakpoint was installed. */
  2777. static bool
  2778. create_longjmp_master_breakpoint_names (objfile *objfile)
  2779. {
  2780. struct gdbarch *gdbarch = objfile->arch ();
  2781. if (!gdbarch_get_longjmp_target_p (gdbarch))
  2782. return false;
  2783. struct breakpoint_objfile_data *bp_objfile_data
  2784. = get_breakpoint_objfile_data (objfile);
  2785. unsigned int installed_bp = 0;
  2786. for (int i = 0; i < NUM_LONGJMP_NAMES; i++)
  2787. {
  2788. struct breakpoint *b;
  2789. const char *func_name;
  2790. CORE_ADDR addr;
  2791. struct explicit_location explicit_loc;
  2792. if (msym_not_found_p (bp_objfile_data->longjmp_msym[i].minsym))
  2793. continue;
  2794. func_name = longjmp_names[i];
  2795. if (bp_objfile_data->longjmp_msym[i].minsym == NULL)
  2796. {
  2797. struct bound_minimal_symbol m;
  2798. m = lookup_minimal_symbol_text (func_name, objfile);
  2799. if (m.minsym == NULL)
  2800. {
  2801. /* Prevent future lookups in this objfile. */
  2802. bp_objfile_data->longjmp_msym[i].minsym = &msym_not_found;
  2803. continue;
  2804. }
  2805. bp_objfile_data->longjmp_msym[i] = m;
  2806. }
  2807. addr = BMSYMBOL_VALUE_ADDRESS (bp_objfile_data->longjmp_msym[i]);
  2808. b = create_internal_breakpoint (gdbarch, addr, bp_longjmp_master,
  2809. &internal_breakpoint_ops);
  2810. initialize_explicit_location (&explicit_loc);
  2811. explicit_loc.function_name = ASTRDUP (func_name);
  2812. b->location = new_explicit_location (&explicit_loc);
  2813. b->enable_state = bp_disabled;
  2814. installed_bp++;
  2815. }
  2816. return installed_bp > 0;
  2817. }
  2818. /* Create a master longjmp breakpoint. */
  2819. static void
  2820. create_longjmp_master_breakpoint (void)
  2821. {
  2822. scoped_restore_current_program_space restore_pspace;
  2823. for (struct program_space *pspace : program_spaces)
  2824. {
  2825. set_current_program_space (pspace);
  2826. for (objfile *obj : current_program_space->objfiles ())
  2827. {
  2828. /* Skip separate debug object, it's handled in the loop below. */
  2829. if (obj->separate_debug_objfile_backlink != nullptr)
  2830. continue;
  2831. /* Try a probe kind breakpoint on main objfile. */
  2832. if (create_longjmp_master_breakpoint_probe (obj))
  2833. continue;
  2834. /* Try longjmp_names kind breakpoints on main and separate_debug
  2835. objfiles. */
  2836. for (objfile *debug_objfile : obj->separate_debug_objfiles ())
  2837. if (create_longjmp_master_breakpoint_names (debug_objfile))
  2838. break;
  2839. }
  2840. }
  2841. }
  2842. /* Create a master std::terminate breakpoint. */
  2843. static void
  2844. create_std_terminate_master_breakpoint (void)
  2845. {
  2846. const char *const func_name = "std::terminate()";
  2847. scoped_restore_current_program_space restore_pspace;
  2848. for (struct program_space *pspace : program_spaces)
  2849. {
  2850. CORE_ADDR addr;
  2851. set_current_program_space (pspace);
  2852. for (objfile *objfile : current_program_space->objfiles ())
  2853. {
  2854. struct breakpoint *b;
  2855. struct breakpoint_objfile_data *bp_objfile_data;
  2856. struct explicit_location explicit_loc;
  2857. bp_objfile_data = get_breakpoint_objfile_data (objfile);
  2858. if (msym_not_found_p (bp_objfile_data->terminate_msym.minsym))
  2859. continue;
  2860. if (bp_objfile_data->terminate_msym.minsym == NULL)
  2861. {
  2862. struct bound_minimal_symbol m;
  2863. m = lookup_minimal_symbol (func_name, NULL, objfile);
  2864. if (m.minsym == NULL || (MSYMBOL_TYPE (m.minsym) != mst_text
  2865. && MSYMBOL_TYPE (m.minsym) != mst_file_text))
  2866. {
  2867. /* Prevent future lookups in this objfile. */
  2868. bp_objfile_data->terminate_msym.minsym = &msym_not_found;
  2869. continue;
  2870. }
  2871. bp_objfile_data->terminate_msym = m;
  2872. }
  2873. addr = BMSYMBOL_VALUE_ADDRESS (bp_objfile_data->terminate_msym);
  2874. b = create_internal_breakpoint (objfile->arch (), addr,
  2875. bp_std_terminate_master,
  2876. &internal_breakpoint_ops);
  2877. initialize_explicit_location (&explicit_loc);
  2878. explicit_loc.function_name = ASTRDUP (func_name);
  2879. b->location = new_explicit_location (&explicit_loc);
  2880. b->enable_state = bp_disabled;
  2881. }
  2882. }
  2883. }
  2884. /* Install a master breakpoint on the unwinder's debug hook for OBJFILE using a
  2885. probe. Return true if a breakpoint was installed. */
  2886. static bool
  2887. create_exception_master_breakpoint_probe (objfile *objfile)
  2888. {
  2889. struct breakpoint *b;
  2890. struct gdbarch *gdbarch;
  2891. struct breakpoint_objfile_data *bp_objfile_data;
  2892. bp_objfile_data = get_breakpoint_objfile_data (objfile);
  2893. /* We prefer the SystemTap probe point if it exists. */
  2894. if (!bp_objfile_data->exception_searched)
  2895. {
  2896. std::vector<probe *> ret
  2897. = find_probes_in_objfile (objfile, "libgcc", "unwind");
  2898. if (!ret.empty ())
  2899. {
  2900. /* We are only interested in checking one element. */
  2901. probe *p = ret[0];
  2902. if (!p->can_evaluate_arguments ())
  2903. {
  2904. /* We cannot use the probe interface here, because it does
  2905. not know how to evaluate arguments. */
  2906. ret.clear ();
  2907. }
  2908. }
  2909. bp_objfile_data->exception_probes = ret;
  2910. bp_objfile_data->exception_searched = 1;
  2911. }
  2912. if (bp_objfile_data->exception_probes.empty ())
  2913. return false;
  2914. gdbarch = objfile->arch ();
  2915. for (probe *p : bp_objfile_data->exception_probes)
  2916. {
  2917. b = create_internal_breakpoint (gdbarch,
  2918. p->get_relocated_address (objfile),
  2919. bp_exception_master,
  2920. &internal_breakpoint_ops);
  2921. b->location = new_probe_location ("-probe-stap libgcc:unwind");
  2922. b->enable_state = bp_disabled;
  2923. }
  2924. return true;
  2925. }
  2926. /* Install a master breakpoint on the unwinder's debug hook for OBJFILE using
  2927. _Unwind_DebugHook. Return true if a breakpoint was installed. */
  2928. static bool
  2929. create_exception_master_breakpoint_hook (objfile *objfile)
  2930. {
  2931. const char *const func_name = "_Unwind_DebugHook";
  2932. struct breakpoint *b;
  2933. struct gdbarch *gdbarch;
  2934. struct breakpoint_objfile_data *bp_objfile_data;
  2935. CORE_ADDR addr;
  2936. struct explicit_location explicit_loc;
  2937. bp_objfile_data = get_breakpoint_objfile_data (objfile);
  2938. if (msym_not_found_p (bp_objfile_data->exception_msym.minsym))
  2939. return false;
  2940. gdbarch = objfile->arch ();
  2941. if (bp_objfile_data->exception_msym.minsym == NULL)
  2942. {
  2943. struct bound_minimal_symbol debug_hook;
  2944. debug_hook = lookup_minimal_symbol (func_name, NULL, objfile);
  2945. if (debug_hook.minsym == NULL)
  2946. {
  2947. bp_objfile_data->exception_msym.minsym = &msym_not_found;
  2948. return false;
  2949. }
  2950. bp_objfile_data->exception_msym = debug_hook;
  2951. }
  2952. addr = BMSYMBOL_VALUE_ADDRESS (bp_objfile_data->exception_msym);
  2953. addr = gdbarch_convert_from_func_ptr_addr
  2954. (gdbarch, addr, current_inferior ()->top_target ());
  2955. b = create_internal_breakpoint (gdbarch, addr, bp_exception_master,
  2956. &internal_breakpoint_ops);
  2957. initialize_explicit_location (&explicit_loc);
  2958. explicit_loc.function_name = ASTRDUP (func_name);
  2959. b->location = new_explicit_location (&explicit_loc);
  2960. b->enable_state = bp_disabled;
  2961. return true;
  2962. }
  2963. /* Install a master breakpoint on the unwinder's debug hook. */
  2964. static void
  2965. create_exception_master_breakpoint (void)
  2966. {
  2967. for (objfile *obj : current_program_space->objfiles ())
  2968. {
  2969. /* Skip separate debug object. */
  2970. if (obj->separate_debug_objfile_backlink)
  2971. continue;
  2972. /* Try a probe kind breakpoint. */
  2973. if (create_exception_master_breakpoint_probe (obj))
  2974. continue;
  2975. /* Iterate over main and separate debug objects and try an
  2976. _Unwind_DebugHook kind breakpoint. */
  2977. for (objfile *debug_objfile : obj->separate_debug_objfiles ())
  2978. if (create_exception_master_breakpoint_hook (debug_objfile))
  2979. break;
  2980. }
  2981. }
  2982. /* Does B have a location spec? */
  2983. static int
  2984. breakpoint_event_location_empty_p (const struct breakpoint *b)
  2985. {
  2986. return b->location != NULL && event_location_empty_p (b->location.get ());
  2987. }
  2988. void
  2989. update_breakpoints_after_exec (void)
  2990. {
  2991. /* We're about to delete breakpoints from GDB's lists. If the
  2992. INSERTED flag is true, GDB will try to lift the breakpoints by
  2993. writing the breakpoints' "shadow contents" back into memory. The
  2994. "shadow contents" are NOT valid after an exec, so GDB should not
  2995. do that. Instead, the target is responsible from marking
  2996. breakpoints out as soon as it detects an exec. We don't do that
  2997. here instead, because there may be other attempts to delete
  2998. breakpoints after detecting an exec and before reaching here. */
  2999. for (bp_location *bploc : all_bp_locations ())
  3000. if (bploc->pspace == current_program_space)
  3001. gdb_assert (!bploc->inserted);
  3002. for (breakpoint *b : all_breakpoints_safe ())
  3003. {
  3004. if (b->pspace != current_program_space)
  3005. continue;
  3006. /* Solib breakpoints must be explicitly reset after an exec(). */
  3007. if (b->type == bp_shlib_event)
  3008. {
  3009. delete_breakpoint (b);
  3010. continue;
  3011. }
  3012. /* JIT breakpoints must be explicitly reset after an exec(). */
  3013. if (b->type == bp_jit_event)
  3014. {
  3015. delete_breakpoint (b);
  3016. continue;
  3017. }
  3018. /* Thread event breakpoints must be set anew after an exec(),
  3019. as must overlay event and longjmp master breakpoints. */
  3020. if (b->type == bp_thread_event || b->type == bp_overlay_event
  3021. || b->type == bp_longjmp_master || b->type == bp_std_terminate_master
  3022. || b->type == bp_exception_master)
  3023. {
  3024. delete_breakpoint (b);
  3025. continue;
  3026. }
  3027. /* Step-resume breakpoints are meaningless after an exec(). */
  3028. if (b->type == bp_step_resume || b->type == bp_hp_step_resume)
  3029. {
  3030. delete_breakpoint (b);
  3031. continue;
  3032. }
  3033. /* Just like single-step breakpoints. */
  3034. if (b->type == bp_single_step)
  3035. {
  3036. delete_breakpoint (b);
  3037. continue;
  3038. }
  3039. /* Longjmp and longjmp-resume breakpoints are also meaningless
  3040. after an exec. */
  3041. if (b->type == bp_longjmp || b->type == bp_longjmp_resume
  3042. || b->type == bp_longjmp_call_dummy
  3043. || b->type == bp_exception || b->type == bp_exception_resume)
  3044. {
  3045. delete_breakpoint (b);
  3046. continue;
  3047. }
  3048. if (b->type == bp_catchpoint)
  3049. {
  3050. /* For now, none of the bp_catchpoint breakpoints need to
  3051. do anything at this point. In the future, if some of
  3052. the catchpoints need to something, we will need to add
  3053. a new method, and call this method from here. */
  3054. continue;
  3055. }
  3056. /* bp_finish is a special case. The only way we ought to be able
  3057. to see one of these when an exec() has happened, is if the user
  3058. caught a vfork, and then said "finish". Ordinarily a finish just
  3059. carries them to the call-site of the current callee, by setting
  3060. a temporary bp there and resuming. But in this case, the finish
  3061. will carry them entirely through the vfork & exec.
  3062. We don't want to allow a bp_finish to remain inserted now. But
  3063. we can't safely delete it, 'cause finish_command has a handle to
  3064. the bp on a bpstat, and will later want to delete it. There's a
  3065. chance (and I've seen it happen) that if we delete the bp_finish
  3066. here, that its storage will get reused by the time finish_command
  3067. gets 'round to deleting the "use to be a bp_finish" breakpoint.
  3068. We really must allow finish_command to delete a bp_finish.
  3069. In the absence of a general solution for the "how do we know
  3070. it's safe to delete something others may have handles to?"
  3071. problem, what we'll do here is just uninsert the bp_finish, and
  3072. let finish_command delete it.
  3073. (We know the bp_finish is "doomed" in the sense that it's
  3074. momentary, and will be deleted as soon as finish_command sees
  3075. the inferior stopped. So it doesn't matter that the bp's
  3076. address is probably bogus in the new a.out, unlike e.g., the
  3077. solib breakpoints.) */
  3078. if (b->type == bp_finish)
  3079. {
  3080. continue;
  3081. }
  3082. /* Without a symbolic address, we have little hope of the
  3083. pre-exec() address meaning the same thing in the post-exec()
  3084. a.out. */
  3085. if (breakpoint_event_location_empty_p (b))
  3086. {
  3087. delete_breakpoint (b);
  3088. continue;
  3089. }
  3090. }
  3091. }
  3092. int
  3093. detach_breakpoints (ptid_t ptid)
  3094. {
  3095. int val = 0;
  3096. scoped_restore save_inferior_ptid = make_scoped_restore (&inferior_ptid);
  3097. struct inferior *inf = current_inferior ();
  3098. if (ptid.pid () == inferior_ptid.pid ())
  3099. error (_("Cannot detach breakpoints of inferior_ptid"));
  3100. /* Set inferior_ptid; remove_breakpoint_1 uses this global. */
  3101. inferior_ptid = ptid;
  3102. for (bp_location *bl : all_bp_locations ())
  3103. {
  3104. if (bl->pspace != inf->pspace)
  3105. continue;
  3106. /* This function must physically remove breakpoints locations
  3107. from the specified ptid, without modifying the breakpoint
  3108. package's state. Locations of type bp_loc_other are only
  3109. maintained at GDB side. So, there is no need to remove
  3110. these bp_loc_other locations. Moreover, removing these
  3111. would modify the breakpoint package's state. */
  3112. if (bl->loc_type == bp_loc_other)
  3113. continue;
  3114. if (bl->inserted)
  3115. val |= remove_breakpoint_1 (bl, DETACH_BREAKPOINT);
  3116. }
  3117. return val;
  3118. }
  3119. /* Remove the breakpoint location BL from the current address space.
  3120. Note that this is used to detach breakpoints from a child fork.
  3121. When we get here, the child isn't in the inferior list, and neither
  3122. do we have objects to represent its address space --- we should
  3123. *not* look at bl->pspace->aspace here. */
  3124. static int
  3125. remove_breakpoint_1 (struct bp_location *bl, enum remove_bp_reason reason)
  3126. {
  3127. int val;
  3128. /* BL is never in moribund_locations by our callers. */
  3129. gdb_assert (bl->owner != NULL);
  3130. /* The type of none suggests that owner is actually deleted.
  3131. This should not ever happen. */
  3132. gdb_assert (bl->owner->type != bp_none);
  3133. if (bl->loc_type == bp_loc_software_breakpoint
  3134. || bl->loc_type == bp_loc_hardware_breakpoint)
  3135. {
  3136. /* "Normal" instruction breakpoint: either the standard
  3137. trap-instruction bp (bp_breakpoint), or a
  3138. bp_hardware_breakpoint. */
  3139. /* First check to see if we have to handle an overlay. */
  3140. if (overlay_debugging == ovly_off
  3141. || bl->section == NULL
  3142. || !(section_is_overlay (bl->section)))
  3143. {
  3144. /* No overlay handling: just remove the breakpoint. */
  3145. /* If we're trying to uninsert a memory breakpoint that we
  3146. know is set in a dynamic object that is marked
  3147. shlib_disabled, then either the dynamic object was
  3148. removed with "remove-symbol-file" or with
  3149. "nosharedlibrary". In the former case, we don't know
  3150. whether another dynamic object might have loaded over the
  3151. breakpoint's address -- the user might well let us know
  3152. about it next with add-symbol-file (the whole point of
  3153. add-symbol-file is letting the user manually maintain a
  3154. list of dynamically loaded objects). If we have the
  3155. breakpoint's shadow memory, that is, this is a software
  3156. breakpoint managed by GDB, check whether the breakpoint
  3157. is still inserted in memory, to avoid overwriting wrong
  3158. code with stale saved shadow contents. Note that HW
  3159. breakpoints don't have shadow memory, as they're
  3160. implemented using a mechanism that is not dependent on
  3161. being able to modify the target's memory, and as such
  3162. they should always be removed. */
  3163. if (bl->shlib_disabled
  3164. && bl->target_info.shadow_len != 0
  3165. && !memory_validate_breakpoint (bl->gdbarch, &bl->target_info))
  3166. val = 0;
  3167. else
  3168. val = bl->owner->ops->remove_location (bl, reason);
  3169. }
  3170. else
  3171. {
  3172. /* This breakpoint is in an overlay section.
  3173. Did we set a breakpoint at the LMA? */
  3174. if (!overlay_events_enabled)
  3175. {
  3176. /* Yes -- overlay event support is not active, so we
  3177. should have set a breakpoint at the LMA. Remove it.
  3178. */
  3179. /* Ignore any failures: if the LMA is in ROM, we will
  3180. have already warned when we failed to insert it. */
  3181. if (bl->loc_type == bp_loc_hardware_breakpoint)
  3182. target_remove_hw_breakpoint (bl->gdbarch,
  3183. &bl->overlay_target_info);
  3184. else
  3185. target_remove_breakpoint (bl->gdbarch,
  3186. &bl->overlay_target_info,
  3187. reason);
  3188. }
  3189. /* Did we set a breakpoint at the VMA?
  3190. If so, we will have marked the breakpoint 'inserted'. */
  3191. if (bl->inserted)
  3192. {
  3193. /* Yes -- remove it. Previously we did not bother to
  3194. remove the breakpoint if the section had been
  3195. unmapped, but let's not rely on that being safe. We
  3196. don't know what the overlay manager might do. */
  3197. /* However, we should remove *software* breakpoints only
  3198. if the section is still mapped, or else we overwrite
  3199. wrong code with the saved shadow contents. */
  3200. if (bl->loc_type == bp_loc_hardware_breakpoint
  3201. || section_is_mapped (bl->section))
  3202. val = bl->owner->ops->remove_location (bl, reason);
  3203. else
  3204. val = 0;
  3205. }
  3206. else
  3207. {
  3208. /* No -- not inserted, so no need to remove. No error. */
  3209. val = 0;
  3210. }
  3211. }
  3212. /* In some cases, we might not be able to remove a breakpoint in
  3213. a shared library that has already been removed, but we have
  3214. not yet processed the shlib unload event. Similarly for an
  3215. unloaded add-symbol-file object - the user might not yet have
  3216. had the chance to remove-symbol-file it. shlib_disabled will
  3217. be set if the library/object has already been removed, but
  3218. the breakpoint hasn't been uninserted yet, e.g., after
  3219. "nosharedlibrary" or "remove-symbol-file" with breakpoints
  3220. always-inserted mode. */
  3221. if (val
  3222. && (bl->loc_type == bp_loc_software_breakpoint
  3223. && (bl->shlib_disabled
  3224. || solib_name_from_address (bl->pspace, bl->address)
  3225. || shared_objfile_contains_address_p (bl->pspace,
  3226. bl->address))))
  3227. val = 0;
  3228. if (val)
  3229. return val;
  3230. bl->inserted = (reason == DETACH_BREAKPOINT);
  3231. }
  3232. else if (bl->loc_type == bp_loc_hardware_watchpoint)
  3233. {
  3234. gdb_assert (bl->owner->ops != NULL
  3235. && bl->owner->ops->remove_location != NULL);
  3236. bl->inserted = (reason == DETACH_BREAKPOINT);
  3237. bl->owner->ops->remove_location (bl, reason);
  3238. /* Failure to remove any of the hardware watchpoints comes here. */
  3239. if (reason == REMOVE_BREAKPOINT && bl->inserted)
  3240. warning (_("Could not remove hardware watchpoint %d."),
  3241. bl->owner->number);
  3242. }
  3243. else if (bl->owner->type == bp_catchpoint
  3244. && breakpoint_enabled (bl->owner)
  3245. && !bl->duplicate)
  3246. {
  3247. gdb_assert (bl->owner->ops != NULL
  3248. && bl->owner->ops->remove_location != NULL);
  3249. val = bl->owner->ops->remove_location (bl, reason);
  3250. if (val)
  3251. return val;
  3252. bl->inserted = (reason == DETACH_BREAKPOINT);
  3253. }
  3254. return 0;
  3255. }
  3256. static int
  3257. remove_breakpoint (struct bp_location *bl)
  3258. {
  3259. /* BL is never in moribund_locations by our callers. */
  3260. gdb_assert (bl->owner != NULL);
  3261. /* The type of none suggests that owner is actually deleted.
  3262. This should not ever happen. */
  3263. gdb_assert (bl->owner->type != bp_none);
  3264. scoped_restore_current_pspace_and_thread restore_pspace_thread;
  3265. switch_to_program_space_and_thread (bl->pspace);
  3266. return remove_breakpoint_1 (bl, REMOVE_BREAKPOINT);
  3267. }
  3268. /* Clear the "inserted" flag in all breakpoints. */
  3269. void
  3270. mark_breakpoints_out (void)
  3271. {
  3272. for (bp_location *bl : all_bp_locations ())
  3273. if (bl->pspace == current_program_space)
  3274. bl->inserted = 0;
  3275. }
  3276. /* Clear the "inserted" flag in all breakpoints and delete any
  3277. breakpoints which should go away between runs of the program.
  3278. Plus other such housekeeping that has to be done for breakpoints
  3279. between runs.
  3280. Note: this function gets called at the end of a run (by
  3281. generic_mourn_inferior) and when a run begins (by
  3282. init_wait_for_inferior). */
  3283. void
  3284. breakpoint_init_inferior (enum inf_context context)
  3285. {
  3286. struct program_space *pspace = current_program_space;
  3287. /* If breakpoint locations are shared across processes, then there's
  3288. nothing to do. */
  3289. if (gdbarch_has_global_breakpoints (target_gdbarch ()))
  3290. return;
  3291. mark_breakpoints_out ();
  3292. for (breakpoint *b : all_breakpoints_safe ())
  3293. {
  3294. if (b->loc && b->loc->pspace != pspace)
  3295. continue;
  3296. switch (b->type)
  3297. {
  3298. case bp_call_dummy:
  3299. case bp_longjmp_call_dummy:
  3300. /* If the call dummy breakpoint is at the entry point it will
  3301. cause problems when the inferior is rerun, so we better get
  3302. rid of it. */
  3303. case bp_watchpoint_scope:
  3304. /* Also get rid of scope breakpoints. */
  3305. case bp_shlib_event:
  3306. /* Also remove solib event breakpoints. Their addresses may
  3307. have changed since the last time we ran the program.
  3308. Actually we may now be debugging against different target;
  3309. and so the solib backend that installed this breakpoint may
  3310. not be used in by the target. E.g.,
  3311. (gdb) file prog-linux
  3312. (gdb) run # native linux target
  3313. ...
  3314. (gdb) kill
  3315. (gdb) file prog-win.exe
  3316. (gdb) tar rem :9999 # remote Windows gdbserver.
  3317. */
  3318. case bp_step_resume:
  3319. /* Also remove step-resume breakpoints. */
  3320. case bp_single_step:
  3321. /* Also remove single-step breakpoints. */
  3322. delete_breakpoint (b);
  3323. break;
  3324. case bp_watchpoint:
  3325. case bp_hardware_watchpoint:
  3326. case bp_read_watchpoint:
  3327. case bp_access_watchpoint:
  3328. {
  3329. struct watchpoint *w = (struct watchpoint *) b;
  3330. /* Likewise for watchpoints on local expressions. */
  3331. if (w->exp_valid_block != NULL)
  3332. delete_breakpoint (b);
  3333. else
  3334. {
  3335. /* Get rid of existing locations, which are no longer
  3336. valid. New ones will be created in
  3337. update_watchpoint, when the inferior is restarted.
  3338. The next update_global_location_list call will
  3339. garbage collect them. */
  3340. b->loc = NULL;
  3341. if (context == inf_starting)
  3342. {
  3343. /* Reset val field to force reread of starting value in
  3344. insert_breakpoints. */
  3345. w->val.reset (nullptr);
  3346. w->val_valid = false;
  3347. }
  3348. }
  3349. }
  3350. break;
  3351. default:
  3352. break;
  3353. }
  3354. }
  3355. /* Get rid of the moribund locations. */
  3356. for (bp_location *bl : moribund_locations)
  3357. decref_bp_location (&bl);
  3358. moribund_locations.clear ();
  3359. }
  3360. /* These functions concern about actual breakpoints inserted in the
  3361. target --- to e.g. check if we need to do decr_pc adjustment or if
  3362. we need to hop over the bkpt --- so we check for address space
  3363. match, not program space. */
  3364. /* breakpoint_here_p (PC) returns non-zero if an enabled breakpoint
  3365. exists at PC. It returns ordinary_breakpoint_here if it's an
  3366. ordinary breakpoint, or permanent_breakpoint_here if it's a
  3367. permanent breakpoint.
  3368. - When continuing from a location with an ordinary breakpoint, we
  3369. actually single step once before calling insert_breakpoints.
  3370. - When continuing from a location with a permanent breakpoint, we
  3371. need to use the `SKIP_PERMANENT_BREAKPOINT' macro, provided by
  3372. the target, to advance the PC past the breakpoint. */
  3373. enum breakpoint_here
  3374. breakpoint_here_p (const address_space *aspace, CORE_ADDR pc)
  3375. {
  3376. int any_breakpoint_here = 0;
  3377. for (bp_location *bl : all_bp_locations ())
  3378. {
  3379. if (bl->loc_type != bp_loc_software_breakpoint
  3380. && bl->loc_type != bp_loc_hardware_breakpoint)
  3381. continue;
  3382. /* ALL_BP_LOCATIONS bp_location has BL->OWNER always non-NULL. */
  3383. if ((breakpoint_enabled (bl->owner)
  3384. || bl->permanent)
  3385. && breakpoint_location_address_match (bl, aspace, pc))
  3386. {
  3387. if (overlay_debugging
  3388. && section_is_overlay (bl->section)
  3389. && !section_is_mapped (bl->section))
  3390. continue; /* unmapped overlay -- can't be a match */
  3391. else if (bl->permanent)
  3392. return permanent_breakpoint_here;
  3393. else
  3394. any_breakpoint_here = 1;
  3395. }
  3396. }
  3397. return any_breakpoint_here ? ordinary_breakpoint_here : no_breakpoint_here;
  3398. }
  3399. /* See breakpoint.h. */
  3400. int
  3401. breakpoint_in_range_p (const address_space *aspace,
  3402. CORE_ADDR addr, ULONGEST len)
  3403. {
  3404. for (bp_location *bl : all_bp_locations ())
  3405. {
  3406. if (bl->loc_type != bp_loc_software_breakpoint
  3407. && bl->loc_type != bp_loc_hardware_breakpoint)
  3408. continue;
  3409. if ((breakpoint_enabled (bl->owner)
  3410. || bl->permanent)
  3411. && breakpoint_location_address_range_overlap (bl, aspace,
  3412. addr, len))
  3413. {
  3414. if (overlay_debugging
  3415. && section_is_overlay (bl->section)
  3416. && !section_is_mapped (bl->section))
  3417. {
  3418. /* Unmapped overlay -- can't be a match. */
  3419. continue;
  3420. }
  3421. return 1;
  3422. }
  3423. }
  3424. return 0;
  3425. }
  3426. /* Return true if there's a moribund breakpoint at PC. */
  3427. int
  3428. moribund_breakpoint_here_p (const address_space *aspace, CORE_ADDR pc)
  3429. {
  3430. for (bp_location *loc : moribund_locations)
  3431. if (breakpoint_location_address_match (loc, aspace, pc))
  3432. return 1;
  3433. return 0;
  3434. }
  3435. /* Returns non-zero iff BL is inserted at PC, in address space
  3436. ASPACE. */
  3437. static int
  3438. bp_location_inserted_here_p (struct bp_location *bl,
  3439. const address_space *aspace, CORE_ADDR pc)
  3440. {
  3441. if (bl->inserted
  3442. && breakpoint_address_match (bl->pspace->aspace, bl->address,
  3443. aspace, pc))
  3444. {
  3445. if (overlay_debugging
  3446. && section_is_overlay (bl->section)
  3447. && !section_is_mapped (bl->section))
  3448. return 0; /* unmapped overlay -- can't be a match */
  3449. else
  3450. return 1;
  3451. }
  3452. return 0;
  3453. }
  3454. /* Returns non-zero iff there's a breakpoint inserted at PC. */
  3455. int
  3456. breakpoint_inserted_here_p (const address_space *aspace, CORE_ADDR pc)
  3457. {
  3458. for (bp_location *bl : all_bp_locations_at_addr (pc))
  3459. {
  3460. if (bl->loc_type != bp_loc_software_breakpoint
  3461. && bl->loc_type != bp_loc_hardware_breakpoint)
  3462. continue;
  3463. if (bp_location_inserted_here_p (bl, aspace, pc))
  3464. return 1;
  3465. }
  3466. return 0;
  3467. }
  3468. /* This function returns non-zero iff there is a software breakpoint
  3469. inserted at PC. */
  3470. int
  3471. software_breakpoint_inserted_here_p (const address_space *aspace,
  3472. CORE_ADDR pc)
  3473. {
  3474. for (bp_location *bl : all_bp_locations_at_addr (pc))
  3475. {
  3476. if (bl->loc_type != bp_loc_software_breakpoint)
  3477. continue;
  3478. if (bp_location_inserted_here_p (bl, aspace, pc))
  3479. return 1;
  3480. }
  3481. return 0;
  3482. }
  3483. /* See breakpoint.h. */
  3484. int
  3485. hardware_breakpoint_inserted_here_p (const address_space *aspace,
  3486. CORE_ADDR pc)
  3487. {
  3488. for (bp_location *bl : all_bp_locations_at_addr (pc))
  3489. {
  3490. if (bl->loc_type != bp_loc_hardware_breakpoint)
  3491. continue;
  3492. if (bp_location_inserted_here_p (bl, aspace, pc))
  3493. return 1;
  3494. }
  3495. return 0;
  3496. }
  3497. int
  3498. hardware_watchpoint_inserted_in_range (const address_space *aspace,
  3499. CORE_ADDR addr, ULONGEST len)
  3500. {
  3501. for (breakpoint *bpt : all_breakpoints ())
  3502. {
  3503. if (bpt->type != bp_hardware_watchpoint
  3504. && bpt->type != bp_access_watchpoint)
  3505. continue;
  3506. if (!breakpoint_enabled (bpt))
  3507. continue;
  3508. for (bp_location *loc : bpt->locations ())
  3509. if (loc->pspace->aspace == aspace && loc->inserted)
  3510. {
  3511. CORE_ADDR l, h;
  3512. /* Check for intersection. */
  3513. l = std::max<CORE_ADDR> (loc->address, addr);
  3514. h = std::min<CORE_ADDR> (loc->address + loc->length, addr + len);
  3515. if (l < h)
  3516. return 1;
  3517. }
  3518. }
  3519. return 0;
  3520. }
  3521. /* See breakpoint.h. */
  3522. bool
  3523. is_catchpoint (struct breakpoint *b)
  3524. {
  3525. return (b->type == bp_catchpoint);
  3526. }
  3527. /* Clear a bpstat so that it says we are not at any breakpoint.
  3528. Also free any storage that is part of a bpstat. */
  3529. void
  3530. bpstat_clear (bpstat **bsp)
  3531. {
  3532. bpstat *p;
  3533. bpstat *q;
  3534. if (bsp == 0)
  3535. return;
  3536. p = *bsp;
  3537. while (p != NULL)
  3538. {
  3539. q = p->next;
  3540. delete p;
  3541. p = q;
  3542. }
  3543. *bsp = NULL;
  3544. }
  3545. bpstat::bpstat (const bpstat &other)
  3546. : next (NULL),
  3547. bp_location_at (other.bp_location_at),
  3548. breakpoint_at (other.breakpoint_at),
  3549. commands (other.commands),
  3550. print (other.print),
  3551. stop (other.stop),
  3552. print_it (other.print_it)
  3553. {
  3554. if (other.old_val != NULL)
  3555. old_val = release_value (value_copy (other.old_val.get ()));
  3556. }
  3557. /* Return a copy of a bpstat. Like "bs1 = bs2" but all storage that
  3558. is part of the bpstat is copied as well. */
  3559. bpstat *
  3560. bpstat_copy (bpstat *bs)
  3561. {
  3562. bpstat *p = nullptr;
  3563. bpstat *tmp;
  3564. bpstat *retval = nullptr;
  3565. if (bs == NULL)
  3566. return bs;
  3567. for (; bs != NULL; bs = bs->next)
  3568. {
  3569. tmp = new bpstat (*bs);
  3570. if (p == NULL)
  3571. /* This is the first thing in the chain. */
  3572. retval = tmp;
  3573. else
  3574. p->next = tmp;
  3575. p = tmp;
  3576. }
  3577. p->next = NULL;
  3578. return retval;
  3579. }
  3580. /* Find the bpstat associated with this breakpoint. */
  3581. bpstat *
  3582. bpstat_find_breakpoint (bpstat *bsp, struct breakpoint *breakpoint)
  3583. {
  3584. if (bsp == NULL)
  3585. return NULL;
  3586. for (; bsp != NULL; bsp = bsp->next)
  3587. {
  3588. if (bsp->breakpoint_at == breakpoint)
  3589. return bsp;
  3590. }
  3591. return NULL;
  3592. }
  3593. /* See breakpoint.h. */
  3594. bool
  3595. bpstat_explains_signal (bpstat *bsp, enum gdb_signal sig)
  3596. {
  3597. for (; bsp != NULL; bsp = bsp->next)
  3598. {
  3599. if (bsp->breakpoint_at == NULL)
  3600. {
  3601. /* A moribund location can never explain a signal other than
  3602. GDB_SIGNAL_TRAP. */
  3603. if (sig == GDB_SIGNAL_TRAP)
  3604. return true;
  3605. }
  3606. else
  3607. {
  3608. if (bsp->breakpoint_at->ops->explains_signal (bsp->breakpoint_at,
  3609. sig))
  3610. return true;
  3611. }
  3612. }
  3613. return false;
  3614. }
  3615. /* Put in *NUM the breakpoint number of the first breakpoint we are
  3616. stopped at. *BSP upon return is a bpstat which points to the
  3617. remaining breakpoints stopped at (but which is not guaranteed to be
  3618. good for anything but further calls to bpstat_num).
  3619. Return 0 if passed a bpstat which does not indicate any breakpoints.
  3620. Return -1 if stopped at a breakpoint that has been deleted since
  3621. we set it.
  3622. Return 1 otherwise. */
  3623. int
  3624. bpstat_num (bpstat **bsp, int *num)
  3625. {
  3626. struct breakpoint *b;
  3627. if ((*bsp) == NULL)
  3628. return 0; /* No more breakpoint values */
  3629. /* We assume we'll never have several bpstats that correspond to a
  3630. single breakpoint -- otherwise, this function might return the
  3631. same number more than once and this will look ugly. */
  3632. b = (*bsp)->breakpoint_at;
  3633. *bsp = (*bsp)->next;
  3634. if (b == NULL)
  3635. return -1; /* breakpoint that's been deleted since */
  3636. *num = b->number; /* We have its number */
  3637. return 1;
  3638. }
  3639. /* See breakpoint.h. */
  3640. void
  3641. bpstat_clear_actions (void)
  3642. {
  3643. bpstat *bs;
  3644. if (inferior_ptid == null_ptid)
  3645. return;
  3646. thread_info *tp = inferior_thread ();
  3647. for (bs = tp->control.stop_bpstat; bs != NULL; bs = bs->next)
  3648. {
  3649. bs->commands = NULL;
  3650. bs->old_val.reset (nullptr);
  3651. }
  3652. }
  3653. /* Called when a command is about to proceed the inferior. */
  3654. static void
  3655. breakpoint_about_to_proceed (void)
  3656. {
  3657. if (inferior_ptid != null_ptid)
  3658. {
  3659. struct thread_info *tp = inferior_thread ();
  3660. /* Allow inferior function calls in breakpoint commands to not
  3661. interrupt the command list. When the call finishes
  3662. successfully, the inferior will be standing at the same
  3663. breakpoint as if nothing happened. */
  3664. if (tp->control.in_infcall)
  3665. return;
  3666. }
  3667. breakpoint_proceeded = 1;
  3668. }
  3669. /* Return non-zero iff CMD as the first line of a command sequence is `silent'
  3670. or its equivalent. */
  3671. static int
  3672. command_line_is_silent (struct command_line *cmd)
  3673. {
  3674. return cmd && (strcmp ("silent", cmd->line) == 0);
  3675. }
  3676. /* Execute all the commands associated with all the breakpoints at
  3677. this location. Any of these commands could cause the process to
  3678. proceed beyond this point, etc. We look out for such changes by
  3679. checking the global "breakpoint_proceeded" after each command.
  3680. Returns true if a breakpoint command resumed the inferior. In that
  3681. case, it is the caller's responsibility to recall it again with the
  3682. bpstat of the current thread. */
  3683. static int
  3684. bpstat_do_actions_1 (bpstat **bsp)
  3685. {
  3686. bpstat *bs;
  3687. int again = 0;
  3688. /* Avoid endless recursion if a `source' command is contained
  3689. in bs->commands. */
  3690. if (executing_breakpoint_commands)
  3691. return 0;
  3692. scoped_restore save_executing
  3693. = make_scoped_restore (&executing_breakpoint_commands, 1);
  3694. scoped_restore preventer = prevent_dont_repeat ();
  3695. /* This pointer will iterate over the list of bpstat's. */
  3696. bs = *bsp;
  3697. breakpoint_proceeded = 0;
  3698. for (; bs != NULL; bs = bs->next)
  3699. {
  3700. struct command_line *cmd = NULL;
  3701. /* Take ownership of the BSP's command tree, if it has one.
  3702. The command tree could legitimately contain commands like
  3703. 'step' and 'next', which call clear_proceed_status, which
  3704. frees stop_bpstat's command tree. To make sure this doesn't
  3705. free the tree we're executing out from under us, we need to
  3706. take ownership of the tree ourselves. Since a given bpstat's
  3707. commands are only executed once, we don't need to copy it; we
  3708. can clear the pointer in the bpstat, and make sure we free
  3709. the tree when we're done. */
  3710. counted_command_line ccmd = bs->commands;
  3711. bs->commands = NULL;
  3712. if (ccmd != NULL)
  3713. cmd = ccmd.get ();
  3714. if (command_line_is_silent (cmd))
  3715. {
  3716. /* The action has been already done by bpstat_stop_status. */
  3717. cmd = cmd->next;
  3718. }
  3719. while (cmd != NULL)
  3720. {
  3721. execute_control_command (cmd);
  3722. if (breakpoint_proceeded)
  3723. break;
  3724. else
  3725. cmd = cmd->next;
  3726. }
  3727. if (breakpoint_proceeded)
  3728. {
  3729. if (current_ui->async)
  3730. /* If we are in async mode, then the target might be still
  3731. running, not stopped at any breakpoint, so nothing for
  3732. us to do here -- just return to the event loop. */
  3733. ;
  3734. else
  3735. /* In sync mode, when execute_control_command returns
  3736. we're already standing on the next breakpoint.
  3737. Breakpoint commands for that stop were not run, since
  3738. execute_command does not run breakpoint commands --
  3739. only command_line_handler does, but that one is not
  3740. involved in execution of breakpoint commands. So, we
  3741. can now execute breakpoint commands. It should be
  3742. noted that making execute_command do bpstat actions is
  3743. not an option -- in this case we'll have recursive
  3744. invocation of bpstat for each breakpoint with a
  3745. command, and can easily blow up GDB stack. Instead, we
  3746. return true, which will trigger the caller to recall us
  3747. with the new stop_bpstat. */
  3748. again = 1;
  3749. break;
  3750. }
  3751. }
  3752. return again;
  3753. }
  3754. /* Helper for bpstat_do_actions. Get the current thread, if there's
  3755. one, is alive and has execution. Return NULL otherwise. */
  3756. static thread_info *
  3757. get_bpstat_thread ()
  3758. {
  3759. if (inferior_ptid == null_ptid || !target_has_execution ())
  3760. return NULL;
  3761. thread_info *tp = inferior_thread ();
  3762. if (tp->state == THREAD_EXITED || tp->executing ())
  3763. return NULL;
  3764. return tp;
  3765. }
  3766. void
  3767. bpstat_do_actions (void)
  3768. {
  3769. auto cleanup_if_error = make_scope_exit (bpstat_clear_actions);
  3770. thread_info *tp;
  3771. /* Do any commands attached to breakpoint we are stopped at. */
  3772. while ((tp = get_bpstat_thread ()) != NULL)
  3773. {
  3774. /* Since in sync mode, bpstat_do_actions may resume the
  3775. inferior, and only return when it is stopped at the next
  3776. breakpoint, we keep doing breakpoint actions until it returns
  3777. false to indicate the inferior was not resumed. */
  3778. if (!bpstat_do_actions_1 (&tp->control.stop_bpstat))
  3779. break;
  3780. }
  3781. cleanup_if_error.release ();
  3782. }
  3783. /* Print out the (old or new) value associated with a watchpoint. */
  3784. static void
  3785. watchpoint_value_print (struct value *val, struct ui_file *stream)
  3786. {
  3787. if (val == NULL)
  3788. fprintf_styled (stream, metadata_style.style (), _("<unreadable>"));
  3789. else
  3790. {
  3791. struct value_print_options opts;
  3792. get_user_print_options (&opts);
  3793. value_print (val, stream, &opts);
  3794. }
  3795. }
  3796. /* Print the "Thread ID hit" part of "Thread ID hit Breakpoint N" if
  3797. debugging multiple threads. */
  3798. void
  3799. maybe_print_thread_hit_breakpoint (struct ui_out *uiout)
  3800. {
  3801. if (uiout->is_mi_like_p ())
  3802. return;
  3803. uiout->text ("\n");
  3804. if (show_thread_that_caused_stop ())
  3805. {
  3806. struct thread_info *thr = inferior_thread ();
  3807. uiout->text ("Thread ");
  3808. uiout->field_string ("thread-id", print_thread_id (thr));
  3809. const char *name = thread_name (thr);
  3810. if (name != NULL)
  3811. {
  3812. uiout->text (" \"");
  3813. uiout->field_string ("name", name);
  3814. uiout->text ("\"");
  3815. }
  3816. uiout->text (" hit ");
  3817. }
  3818. }
  3819. /* Generic routine for printing messages indicating why we
  3820. stopped. The behavior of this function depends on the value
  3821. 'print_it' in the bpstat structure. Under some circumstances we
  3822. may decide not to print anything here and delegate the task to
  3823. normal_stop(). */
  3824. static enum print_stop_action
  3825. print_bp_stop_message (bpstat *bs)
  3826. {
  3827. switch (bs->print_it)
  3828. {
  3829. case print_it_noop:
  3830. /* Nothing should be printed for this bpstat entry. */
  3831. return PRINT_UNKNOWN;
  3832. break;
  3833. case print_it_done:
  3834. /* We still want to print the frame, but we already printed the
  3835. relevant messages. */
  3836. return PRINT_SRC_AND_LOC;
  3837. break;
  3838. case print_it_normal:
  3839. {
  3840. struct breakpoint *b = bs->breakpoint_at;
  3841. /* bs->breakpoint_at can be NULL if it was a momentary breakpoint
  3842. which has since been deleted. */
  3843. if (b == NULL)
  3844. return PRINT_UNKNOWN;
  3845. /* Normal case. Call the breakpoint's print_it method. */
  3846. return b->ops->print_it (bs);
  3847. }
  3848. break;
  3849. default:
  3850. internal_error (__FILE__, __LINE__,
  3851. _("print_bp_stop_message: unrecognized enum value"));
  3852. break;
  3853. }
  3854. }
  3855. /* A helper function that prints a shared library stopped event. */
  3856. static void
  3857. print_solib_event (int is_catchpoint)
  3858. {
  3859. bool any_deleted = !current_program_space->deleted_solibs.empty ();
  3860. bool any_added = !current_program_space->added_solibs.empty ();
  3861. if (!is_catchpoint)
  3862. {
  3863. if (any_added || any_deleted)
  3864. current_uiout->text (_("Stopped due to shared library event:\n"));
  3865. else
  3866. current_uiout->text (_("Stopped due to shared library event (no "
  3867. "libraries added or removed)\n"));
  3868. }
  3869. if (current_uiout->is_mi_like_p ())
  3870. current_uiout->field_string ("reason",
  3871. async_reason_lookup (EXEC_ASYNC_SOLIB_EVENT));
  3872. if (any_deleted)
  3873. {
  3874. current_uiout->text (_(" Inferior unloaded "));
  3875. ui_out_emit_list list_emitter (current_uiout, "removed");
  3876. for (int ix = 0; ix < current_program_space->deleted_solibs.size (); ix++)
  3877. {
  3878. const std::string &name = current_program_space->deleted_solibs[ix];
  3879. if (ix > 0)
  3880. current_uiout->text (" ");
  3881. current_uiout->field_string ("library", name);
  3882. current_uiout->text ("\n");
  3883. }
  3884. }
  3885. if (any_added)
  3886. {
  3887. current_uiout->text (_(" Inferior loaded "));
  3888. ui_out_emit_list list_emitter (current_uiout, "added");
  3889. bool first = true;
  3890. for (so_list *iter : current_program_space->added_solibs)
  3891. {
  3892. if (!first)
  3893. current_uiout->text (" ");
  3894. first = false;
  3895. current_uiout->field_string ("library", iter->so_name);
  3896. current_uiout->text ("\n");
  3897. }
  3898. }
  3899. }
  3900. /* Print a message indicating what happened. This is called from
  3901. normal_stop(). The input to this routine is the head of the bpstat
  3902. list - a list of the eventpoints that caused this stop. KIND is
  3903. the target_waitkind for the stopping event. This
  3904. routine calls the generic print routine for printing a message
  3905. about reasons for stopping. This will print (for example) the
  3906. "Breakpoint n," part of the output. The return value of this
  3907. routine is one of:
  3908. PRINT_UNKNOWN: Means we printed nothing.
  3909. PRINT_SRC_AND_LOC: Means we printed something, and expect subsequent
  3910. code to print the location. An example is
  3911. "Breakpoint 1, " which should be followed by
  3912. the location.
  3913. PRINT_SRC_ONLY: Means we printed something, but there is no need
  3914. to also print the location part of the message.
  3915. An example is the catch/throw messages, which
  3916. don't require a location appended to the end.
  3917. PRINT_NOTHING: We have done some printing and we don't need any
  3918. further info to be printed. */
  3919. enum print_stop_action
  3920. bpstat_print (bpstat *bs, int kind)
  3921. {
  3922. enum print_stop_action val;
  3923. /* Maybe another breakpoint in the chain caused us to stop.
  3924. (Currently all watchpoints go on the bpstat whether hit or not.
  3925. That probably could (should) be changed, provided care is taken
  3926. with respect to bpstat_explains_signal). */
  3927. for (; bs; bs = bs->next)
  3928. {
  3929. val = print_bp_stop_message (bs);
  3930. if (val == PRINT_SRC_ONLY
  3931. || val == PRINT_SRC_AND_LOC
  3932. || val == PRINT_NOTHING)
  3933. return val;
  3934. }
  3935. /* If we had hit a shared library event breakpoint,
  3936. print_bp_stop_message would print out this message. If we hit an
  3937. OS-level shared library event, do the same thing. */
  3938. if (kind == TARGET_WAITKIND_LOADED)
  3939. {
  3940. print_solib_event (0);
  3941. return PRINT_NOTHING;
  3942. }
  3943. /* We reached the end of the chain, or we got a null BS to start
  3944. with and nothing was printed. */
  3945. return PRINT_UNKNOWN;
  3946. }
  3947. /* Evaluate the boolean expression EXP and return the result. */
  3948. static bool
  3949. breakpoint_cond_eval (expression *exp)
  3950. {
  3951. struct value *mark = value_mark ();
  3952. bool res = value_true (evaluate_expression (exp));
  3953. value_free_to_mark (mark);
  3954. return res;
  3955. }
  3956. /* Allocate a new bpstat. Link it to the FIFO list by BS_LINK_POINTER. */
  3957. bpstat::bpstat (struct bp_location *bl, bpstat ***bs_link_pointer)
  3958. : next (NULL),
  3959. bp_location_at (bp_location_ref_ptr::new_reference (bl)),
  3960. breakpoint_at (bl->owner),
  3961. commands (NULL),
  3962. print (0),
  3963. stop (0),
  3964. print_it (print_it_normal)
  3965. {
  3966. **bs_link_pointer = this;
  3967. *bs_link_pointer = &next;
  3968. }
  3969. bpstat::bpstat ()
  3970. : next (NULL),
  3971. breakpoint_at (NULL),
  3972. commands (NULL),
  3973. print (0),
  3974. stop (0),
  3975. print_it (print_it_normal)
  3976. {
  3977. }
  3978. /* The target has stopped with waitstatus WS. Check if any hardware
  3979. watchpoints have triggered, according to the target. */
  3980. int
  3981. watchpoints_triggered (const target_waitstatus &ws)
  3982. {
  3983. bool stopped_by_watchpoint = target_stopped_by_watchpoint ();
  3984. CORE_ADDR addr;
  3985. if (!stopped_by_watchpoint)
  3986. {
  3987. /* We were not stopped by a watchpoint. Mark all watchpoints
  3988. as not triggered. */
  3989. for (breakpoint *b : all_breakpoints ())
  3990. if (is_hardware_watchpoint (b))
  3991. {
  3992. struct watchpoint *w = (struct watchpoint *) b;
  3993. w->watchpoint_triggered = watch_triggered_no;
  3994. }
  3995. return 0;
  3996. }
  3997. if (!target_stopped_data_address (current_inferior ()->top_target (), &addr))
  3998. {
  3999. /* We were stopped by a watchpoint, but we don't know where.
  4000. Mark all watchpoints as unknown. */
  4001. for (breakpoint *b : all_breakpoints ())
  4002. if (is_hardware_watchpoint (b))
  4003. {
  4004. struct watchpoint *w = (struct watchpoint *) b;
  4005. w->watchpoint_triggered = watch_triggered_unknown;
  4006. }
  4007. return 1;
  4008. }
  4009. /* The target could report the data address. Mark watchpoints
  4010. affected by this data address as triggered, and all others as not
  4011. triggered. */
  4012. for (breakpoint *b : all_breakpoints ())
  4013. if (is_hardware_watchpoint (b))
  4014. {
  4015. struct watchpoint *w = (struct watchpoint *) b;
  4016. w->watchpoint_triggered = watch_triggered_no;
  4017. for (bp_location *loc : b->locations ())
  4018. {
  4019. if (is_masked_watchpoint (b))
  4020. {
  4021. CORE_ADDR newaddr = addr & w->hw_wp_mask;
  4022. CORE_ADDR start = loc->address & w->hw_wp_mask;
  4023. if (newaddr == start)
  4024. {
  4025. w->watchpoint_triggered = watch_triggered_yes;
  4026. break;
  4027. }
  4028. }
  4029. /* Exact match not required. Within range is sufficient. */
  4030. else if (target_watchpoint_addr_within_range
  4031. (current_inferior ()->top_target (), addr, loc->address,
  4032. loc->length))
  4033. {
  4034. w->watchpoint_triggered = watch_triggered_yes;
  4035. break;
  4036. }
  4037. }
  4038. }
  4039. return 1;
  4040. }
  4041. /* Possible return values for watchpoint_check. */
  4042. enum wp_check_result
  4043. {
  4044. /* The watchpoint has been deleted. */
  4045. WP_DELETED = 1,
  4046. /* The value has changed. */
  4047. WP_VALUE_CHANGED = 2,
  4048. /* The value has not changed. */
  4049. WP_VALUE_NOT_CHANGED = 3,
  4050. /* Ignore this watchpoint, no matter if the value changed or not. */
  4051. WP_IGNORE = 4,
  4052. };
  4053. #define BP_TEMPFLAG 1
  4054. #define BP_HARDWAREFLAG 2
  4055. /* Evaluate watchpoint condition expression and check if its value
  4056. changed. */
  4057. static wp_check_result
  4058. watchpoint_check (bpstat *bs)
  4059. {
  4060. struct watchpoint *b;
  4061. struct frame_info *fr;
  4062. int within_current_scope;
  4063. /* BS is built from an existing struct breakpoint. */
  4064. gdb_assert (bs->breakpoint_at != NULL);
  4065. b = (struct watchpoint *) bs->breakpoint_at;
  4066. /* If this is a local watchpoint, we only want to check if the
  4067. watchpoint frame is in scope if the current thread is the thread
  4068. that was used to create the watchpoint. */
  4069. if (!watchpoint_in_thread_scope (b))
  4070. return WP_IGNORE;
  4071. if (b->exp_valid_block == NULL)
  4072. within_current_scope = 1;
  4073. else
  4074. {
  4075. struct frame_info *frame = get_current_frame ();
  4076. struct gdbarch *frame_arch = get_frame_arch (frame);
  4077. CORE_ADDR frame_pc = get_frame_pc (frame);
  4078. /* stack_frame_destroyed_p() returns a non-zero value if we're
  4079. still in the function but the stack frame has already been
  4080. invalidated. Since we can't rely on the values of local
  4081. variables after the stack has been destroyed, we are treating
  4082. the watchpoint in that state as `not changed' without further
  4083. checking. Don't mark watchpoints as changed if the current
  4084. frame is in an epilogue - even if they are in some other
  4085. frame, our view of the stack is likely to be wrong and
  4086. frame_find_by_id could error out. */
  4087. if (gdbarch_stack_frame_destroyed_p (frame_arch, frame_pc))
  4088. return WP_IGNORE;
  4089. fr = frame_find_by_id (b->watchpoint_frame);
  4090. within_current_scope = (fr != NULL);
  4091. /* If we've gotten confused in the unwinder, we might have
  4092. returned a frame that can't describe this variable. */
  4093. if (within_current_scope)
  4094. {
  4095. struct symbol *function;
  4096. function = get_frame_function (fr);
  4097. if (function == NULL
  4098. || !contained_in (b->exp_valid_block,
  4099. SYMBOL_BLOCK_VALUE (function)))
  4100. within_current_scope = 0;
  4101. }
  4102. if (within_current_scope)
  4103. /* If we end up stopping, the current frame will get selected
  4104. in normal_stop. So this call to select_frame won't affect
  4105. the user. */
  4106. select_frame (fr);
  4107. }
  4108. if (within_current_scope)
  4109. {
  4110. /* We use value_{,free_to_}mark because it could be a *long*
  4111. time before we return to the command level and call
  4112. free_all_values. We can't call free_all_values because we
  4113. might be in the middle of evaluating a function call. */
  4114. struct value *mark;
  4115. struct value *new_val;
  4116. if (is_masked_watchpoint (b))
  4117. /* Since we don't know the exact trigger address (from
  4118. stopped_data_address), just tell the user we've triggered
  4119. a mask watchpoint. */
  4120. return WP_VALUE_CHANGED;
  4121. mark = value_mark ();
  4122. fetch_subexp_value (b->exp.get (), b->exp->op.get (), &new_val,
  4123. NULL, NULL, false);
  4124. if (b->val_bitsize != 0)
  4125. new_val = extract_bitfield_from_watchpoint_value (b, new_val);
  4126. /* We use value_equal_contents instead of value_equal because
  4127. the latter coerces an array to a pointer, thus comparing just
  4128. the address of the array instead of its contents. This is
  4129. not what we want. */
  4130. if ((b->val != NULL) != (new_val != NULL)
  4131. || (b->val != NULL && !value_equal_contents (b->val.get (),
  4132. new_val)))
  4133. {
  4134. bs->old_val = b->val;
  4135. b->val = release_value (new_val);
  4136. b->val_valid = true;
  4137. if (new_val != NULL)
  4138. value_free_to_mark (mark);
  4139. return WP_VALUE_CHANGED;
  4140. }
  4141. else
  4142. {
  4143. /* Nothing changed. */
  4144. value_free_to_mark (mark);
  4145. return WP_VALUE_NOT_CHANGED;
  4146. }
  4147. }
  4148. else
  4149. {
  4150. /* This seems like the only logical thing to do because
  4151. if we temporarily ignored the watchpoint, then when
  4152. we reenter the block in which it is valid it contains
  4153. garbage (in the case of a function, it may have two
  4154. garbage values, one before and one after the prologue).
  4155. So we can't even detect the first assignment to it and
  4156. watch after that (since the garbage may or may not equal
  4157. the first value assigned). */
  4158. /* We print all the stop information in
  4159. breakpoint_ops->print_it, but in this case, by the time we
  4160. call breakpoint_ops->print_it this bp will be deleted
  4161. already. So we have no choice but print the information
  4162. here. */
  4163. SWITCH_THRU_ALL_UIS ()
  4164. {
  4165. struct ui_out *uiout = current_uiout;
  4166. if (uiout->is_mi_like_p ())
  4167. uiout->field_string
  4168. ("reason", async_reason_lookup (EXEC_ASYNC_WATCHPOINT_SCOPE));
  4169. uiout->message ("\nWatchpoint %pF deleted because the program has "
  4170. "left the block in\n"
  4171. "which its expression is valid.\n",
  4172. signed_field ("wpnum", b->number));
  4173. }
  4174. /* Make sure the watchpoint's commands aren't executed. */
  4175. b->commands = NULL;
  4176. watchpoint_del_at_next_stop (b);
  4177. return WP_DELETED;
  4178. }
  4179. }
  4180. /* Return true if it looks like target has stopped due to hitting
  4181. breakpoint location BL. This function does not check if we should
  4182. stop, only if BL explains the stop. */
  4183. static int
  4184. bpstat_check_location (const struct bp_location *bl,
  4185. const address_space *aspace, CORE_ADDR bp_addr,
  4186. const target_waitstatus &ws)
  4187. {
  4188. struct breakpoint *b = bl->owner;
  4189. /* BL is from an existing breakpoint. */
  4190. gdb_assert (b != NULL);
  4191. return b->ops->breakpoint_hit (bl, aspace, bp_addr, ws);
  4192. }
  4193. /* Determine if the watched values have actually changed, and we
  4194. should stop. If not, set BS->stop to 0. */
  4195. static void
  4196. bpstat_check_watchpoint (bpstat *bs)
  4197. {
  4198. const struct bp_location *bl;
  4199. struct watchpoint *b;
  4200. /* BS is built for existing struct breakpoint. */
  4201. bl = bs->bp_location_at.get ();
  4202. gdb_assert (bl != NULL);
  4203. b = (struct watchpoint *) bs->breakpoint_at;
  4204. gdb_assert (b != NULL);
  4205. {
  4206. int must_check_value = 0;
  4207. if (b->type == bp_watchpoint)
  4208. /* For a software watchpoint, we must always check the
  4209. watched value. */
  4210. must_check_value = 1;
  4211. else if (b->watchpoint_triggered == watch_triggered_yes)
  4212. /* We have a hardware watchpoint (read, write, or access)
  4213. and the target earlier reported an address watched by
  4214. this watchpoint. */
  4215. must_check_value = 1;
  4216. else if (b->watchpoint_triggered == watch_triggered_unknown
  4217. && b->type == bp_hardware_watchpoint)
  4218. /* We were stopped by a hardware watchpoint, but the target could
  4219. not report the data address. We must check the watchpoint's
  4220. value. Access and read watchpoints are out of luck; without
  4221. a data address, we can't figure it out. */
  4222. must_check_value = 1;
  4223. if (must_check_value)
  4224. {
  4225. wp_check_result e;
  4226. try
  4227. {
  4228. e = watchpoint_check (bs);
  4229. }
  4230. catch (const gdb_exception &ex)
  4231. {
  4232. exception_fprintf (gdb_stderr, ex,
  4233. "Error evaluating expression "
  4234. "for watchpoint %d\n",
  4235. b->number);
  4236. SWITCH_THRU_ALL_UIS ()
  4237. {
  4238. gdb_printf (_("Watchpoint %d deleted.\n"),
  4239. b->number);
  4240. }
  4241. watchpoint_del_at_next_stop (b);
  4242. e = WP_DELETED;
  4243. }
  4244. switch (e)
  4245. {
  4246. case WP_DELETED:
  4247. /* We've already printed what needs to be printed. */
  4248. bs->print_it = print_it_done;
  4249. /* Stop. */
  4250. break;
  4251. case WP_IGNORE:
  4252. bs->print_it = print_it_noop;
  4253. bs->stop = 0;
  4254. break;
  4255. case WP_VALUE_CHANGED:
  4256. if (b->type == bp_read_watchpoint)
  4257. {
  4258. /* There are two cases to consider here:
  4259. 1. We're watching the triggered memory for reads.
  4260. In that case, trust the target, and always report
  4261. the watchpoint hit to the user. Even though
  4262. reads don't cause value changes, the value may
  4263. have changed since the last time it was read, and
  4264. since we're not trapping writes, we will not see
  4265. those, and as such we should ignore our notion of
  4266. old value.
  4267. 2. We're watching the triggered memory for both
  4268. reads and writes. There are two ways this may
  4269. happen:
  4270. 2.1. This is a target that can't break on data
  4271. reads only, but can break on accesses (reads or
  4272. writes), such as e.g., x86. We detect this case
  4273. at the time we try to insert read watchpoints.
  4274. 2.2. Otherwise, the target supports read
  4275. watchpoints, but, the user set an access or write
  4276. watchpoint watching the same memory as this read
  4277. watchpoint.
  4278. If we're watching memory writes as well as reads,
  4279. ignore watchpoint hits when we find that the
  4280. value hasn't changed, as reads don't cause
  4281. changes. This still gives false positives when
  4282. the program writes the same value to memory as
  4283. what there was already in memory (we will confuse
  4284. it for a read), but it's much better than
  4285. nothing. */
  4286. int other_write_watchpoint = 0;
  4287. if (bl->watchpoint_type == hw_read)
  4288. {
  4289. for (breakpoint *other_b : all_breakpoints ())
  4290. if (other_b->type == bp_hardware_watchpoint
  4291. || other_b->type == bp_access_watchpoint)
  4292. {
  4293. struct watchpoint *other_w =
  4294. (struct watchpoint *) other_b;
  4295. if (other_w->watchpoint_triggered
  4296. == watch_triggered_yes)
  4297. {
  4298. other_write_watchpoint = 1;
  4299. break;
  4300. }
  4301. }
  4302. }
  4303. if (other_write_watchpoint
  4304. || bl->watchpoint_type == hw_access)
  4305. {
  4306. /* We're watching the same memory for writes,
  4307. and the value changed since the last time we
  4308. updated it, so this trap must be for a write.
  4309. Ignore it. */
  4310. bs->print_it = print_it_noop;
  4311. bs->stop = 0;
  4312. }
  4313. }
  4314. break;
  4315. case WP_VALUE_NOT_CHANGED:
  4316. if (b->type == bp_hardware_watchpoint
  4317. || b->type == bp_watchpoint)
  4318. {
  4319. /* Don't stop: write watchpoints shouldn't fire if
  4320. the value hasn't changed. */
  4321. bs->print_it = print_it_noop;
  4322. bs->stop = 0;
  4323. }
  4324. /* Stop. */
  4325. break;
  4326. default:
  4327. /* Can't happen. */
  4328. break;
  4329. }
  4330. }
  4331. else /* must_check_value == 0 */
  4332. {
  4333. /* This is a case where some watchpoint(s) triggered, but
  4334. not at the address of this watchpoint, or else no
  4335. watchpoint triggered after all. So don't print
  4336. anything for this watchpoint. */
  4337. bs->print_it = print_it_noop;
  4338. bs->stop = 0;
  4339. }
  4340. }
  4341. }
  4342. /* For breakpoints that are currently marked as telling gdb to stop,
  4343. check conditions (condition proper, frame, thread and ignore count)
  4344. of breakpoint referred to by BS. If we should not stop for this
  4345. breakpoint, set BS->stop to 0. */
  4346. static void
  4347. bpstat_check_breakpoint_conditions (bpstat *bs, thread_info *thread)
  4348. {
  4349. const struct bp_location *bl;
  4350. struct breakpoint *b;
  4351. /* Assume stop. */
  4352. bool condition_result = true;
  4353. struct expression *cond;
  4354. gdb_assert (bs->stop);
  4355. /* BS is built for existing struct breakpoint. */
  4356. bl = bs->bp_location_at.get ();
  4357. gdb_assert (bl != NULL);
  4358. b = bs->breakpoint_at;
  4359. gdb_assert (b != NULL);
  4360. /* Even if the target evaluated the condition on its end and notified GDB, we
  4361. need to do so again since GDB does not know if we stopped due to a
  4362. breakpoint or a single step breakpoint. */
  4363. if (frame_id_p (b->frame_id)
  4364. && !frame_id_eq (b->frame_id, get_stack_frame_id (get_current_frame ())))
  4365. {
  4366. bs->stop = 0;
  4367. return;
  4368. }
  4369. /* If this is a thread/task-specific breakpoint, don't waste cpu
  4370. evaluating the condition if this isn't the specified
  4371. thread/task. */
  4372. if ((b->thread != -1 && b->thread != thread->global_num)
  4373. || (b->task != 0 && b->task != ada_get_task_number (thread)))
  4374. {
  4375. bs->stop = 0;
  4376. return;
  4377. }
  4378. /* Evaluate extension language breakpoints that have a "stop" method
  4379. implemented. */
  4380. bs->stop = breakpoint_ext_lang_cond_says_stop (b);
  4381. if (is_watchpoint (b))
  4382. {
  4383. struct watchpoint *w = (struct watchpoint *) b;
  4384. cond = w->cond_exp.get ();
  4385. }
  4386. else
  4387. cond = bl->cond.get ();
  4388. if (cond && b->disposition != disp_del_at_next_stop)
  4389. {
  4390. int within_current_scope = 1;
  4391. struct watchpoint * w;
  4392. /* We use value_mark and value_free_to_mark because it could
  4393. be a long time before we return to the command level and
  4394. call free_all_values. We can't call free_all_values
  4395. because we might be in the middle of evaluating a
  4396. function call. */
  4397. struct value *mark = value_mark ();
  4398. if (is_watchpoint (b))
  4399. w = (struct watchpoint *) b;
  4400. else
  4401. w = NULL;
  4402. /* Need to select the frame, with all that implies so that
  4403. the conditions will have the right context. Because we
  4404. use the frame, we will not see an inlined function's
  4405. variables when we arrive at a breakpoint at the start
  4406. of the inlined function; the current frame will be the
  4407. call site. */
  4408. if (w == NULL || w->cond_exp_valid_block == NULL)
  4409. select_frame (get_current_frame ());
  4410. else
  4411. {
  4412. struct frame_info *frame;
  4413. /* For local watchpoint expressions, which particular
  4414. instance of a local is being watched matters, so we
  4415. keep track of the frame to evaluate the expression
  4416. in. To evaluate the condition however, it doesn't
  4417. really matter which instantiation of the function
  4418. where the condition makes sense triggers the
  4419. watchpoint. This allows an expression like "watch
  4420. global if q > 10" set in `func', catch writes to
  4421. global on all threads that call `func', or catch
  4422. writes on all recursive calls of `func' by a single
  4423. thread. We simply always evaluate the condition in
  4424. the innermost frame that's executing where it makes
  4425. sense to evaluate the condition. It seems
  4426. intuitive. */
  4427. frame = block_innermost_frame (w->cond_exp_valid_block);
  4428. if (frame != NULL)
  4429. select_frame (frame);
  4430. else
  4431. within_current_scope = 0;
  4432. }
  4433. if (within_current_scope)
  4434. {
  4435. try
  4436. {
  4437. condition_result = breakpoint_cond_eval (cond);
  4438. }
  4439. catch (const gdb_exception &ex)
  4440. {
  4441. exception_fprintf (gdb_stderr, ex,
  4442. "Error in testing breakpoint condition:\n");
  4443. }
  4444. }
  4445. else
  4446. {
  4447. warning (_("Watchpoint condition cannot be tested "
  4448. "in the current scope"));
  4449. /* If we failed to set the right context for this
  4450. watchpoint, unconditionally report it. */
  4451. }
  4452. /* FIXME-someday, should give breakpoint #. */
  4453. value_free_to_mark (mark);
  4454. }
  4455. if (cond && !condition_result)
  4456. {
  4457. bs->stop = 0;
  4458. }
  4459. else if (b->ignore_count > 0)
  4460. {
  4461. b->ignore_count--;
  4462. bs->stop = 0;
  4463. /* Increase the hit count even though we don't stop. */
  4464. ++(b->hit_count);
  4465. gdb::observers::breakpoint_modified.notify (b);
  4466. }
  4467. }
  4468. /* Returns true if we need to track moribund locations of LOC's type
  4469. on the current target. */
  4470. static int
  4471. need_moribund_for_location_type (struct bp_location *loc)
  4472. {
  4473. return ((loc->loc_type == bp_loc_software_breakpoint
  4474. && !target_supports_stopped_by_sw_breakpoint ())
  4475. || (loc->loc_type == bp_loc_hardware_breakpoint
  4476. && !target_supports_stopped_by_hw_breakpoint ()));
  4477. }
  4478. /* See breakpoint.h. */
  4479. bpstat *
  4480. build_bpstat_chain (const address_space *aspace, CORE_ADDR bp_addr,
  4481. const target_waitstatus &ws)
  4482. {
  4483. bpstat *bs_head = nullptr, **bs_link = &bs_head;
  4484. for (breakpoint *b : all_breakpoints ())
  4485. {
  4486. if (!breakpoint_enabled (b))
  4487. continue;
  4488. for (bp_location *bl : b->locations ())
  4489. {
  4490. /* For hardware watchpoints, we look only at the first
  4491. location. The watchpoint_check function will work on the
  4492. entire expression, not the individual locations. For
  4493. read watchpoints, the watchpoints_triggered function has
  4494. checked all locations already. */
  4495. if (b->type == bp_hardware_watchpoint && bl != b->loc)
  4496. break;
  4497. if (!bl->enabled || bl->disabled_by_cond || bl->shlib_disabled)
  4498. continue;
  4499. if (!bpstat_check_location (bl, aspace, bp_addr, ws))
  4500. continue;
  4501. /* Come here if it's a watchpoint, or if the break address
  4502. matches. */
  4503. bpstat *bs = new bpstat (bl, &bs_link); /* Alloc a bpstat to
  4504. explain stop. */
  4505. /* Assume we stop. Should we find a watchpoint that is not
  4506. actually triggered, or if the condition of the breakpoint
  4507. evaluates as false, we'll reset 'stop' to 0. */
  4508. bs->stop = 1;
  4509. bs->print = 1;
  4510. /* If this is a scope breakpoint, mark the associated
  4511. watchpoint as triggered so that we will handle the
  4512. out-of-scope event. We'll get to the watchpoint next
  4513. iteration. */
  4514. if (b->type == bp_watchpoint_scope && b->related_breakpoint != b)
  4515. {
  4516. struct watchpoint *w = (struct watchpoint *) b->related_breakpoint;
  4517. w->watchpoint_triggered = watch_triggered_yes;
  4518. }
  4519. }
  4520. }
  4521. /* Check if a moribund breakpoint explains the stop. */
  4522. if (!target_supports_stopped_by_sw_breakpoint ()
  4523. || !target_supports_stopped_by_hw_breakpoint ())
  4524. {
  4525. for (bp_location *loc : moribund_locations)
  4526. {
  4527. if (breakpoint_location_address_match (loc, aspace, bp_addr)
  4528. && need_moribund_for_location_type (loc))
  4529. {
  4530. bpstat *bs = new bpstat (loc, &bs_link);
  4531. /* For hits of moribund locations, we should just proceed. */
  4532. bs->stop = 0;
  4533. bs->print = 0;
  4534. bs->print_it = print_it_noop;
  4535. }
  4536. }
  4537. }
  4538. return bs_head;
  4539. }
  4540. /* See breakpoint.h. */
  4541. bpstat *
  4542. bpstat_stop_status (const address_space *aspace,
  4543. CORE_ADDR bp_addr, thread_info *thread,
  4544. const target_waitstatus &ws,
  4545. bpstat *stop_chain)
  4546. {
  4547. struct breakpoint *b = NULL;
  4548. /* First item of allocated bpstat's. */
  4549. bpstat *bs_head = stop_chain;
  4550. bpstat *bs;
  4551. int need_remove_insert;
  4552. int removed_any;
  4553. /* First, build the bpstat chain with locations that explain a
  4554. target stop, while being careful to not set the target running,
  4555. as that may invalidate locations (in particular watchpoint
  4556. locations are recreated). Resuming will happen here with
  4557. breakpoint conditions or watchpoint expressions that include
  4558. inferior function calls. */
  4559. if (bs_head == NULL)
  4560. bs_head = build_bpstat_chain (aspace, bp_addr, ws);
  4561. /* A bit of special processing for shlib breakpoints. We need to
  4562. process solib loading here, so that the lists of loaded and
  4563. unloaded libraries are correct before we handle "catch load" and
  4564. "catch unload". */
  4565. for (bs = bs_head; bs != NULL; bs = bs->next)
  4566. {
  4567. if (bs->breakpoint_at && bs->breakpoint_at->type == bp_shlib_event)
  4568. {
  4569. handle_solib_event ();
  4570. break;
  4571. }
  4572. }
  4573. /* Now go through the locations that caused the target to stop, and
  4574. check whether we're interested in reporting this stop to higher
  4575. layers, or whether we should resume the target transparently. */
  4576. removed_any = 0;
  4577. for (bs = bs_head; bs != NULL; bs = bs->next)
  4578. {
  4579. if (!bs->stop)
  4580. continue;
  4581. b = bs->breakpoint_at;
  4582. b->ops->check_status (bs);
  4583. if (bs->stop)
  4584. {
  4585. bpstat_check_breakpoint_conditions (bs, thread);
  4586. if (bs->stop)
  4587. {
  4588. ++(b->hit_count);
  4589. /* We will stop here. */
  4590. if (b->disposition == disp_disable)
  4591. {
  4592. --(b->enable_count);
  4593. if (b->enable_count <= 0)
  4594. b->enable_state = bp_disabled;
  4595. removed_any = 1;
  4596. }
  4597. gdb::observers::breakpoint_modified.notify (b);
  4598. if (b->silent)
  4599. bs->print = 0;
  4600. bs->commands = b->commands;
  4601. if (command_line_is_silent (bs->commands
  4602. ? bs->commands.get () : NULL))
  4603. bs->print = 0;
  4604. b->ops->after_condition_true (bs);
  4605. }
  4606. }
  4607. /* Print nothing for this entry if we don't stop or don't
  4608. print. */
  4609. if (!bs->stop || !bs->print)
  4610. bs->print_it = print_it_noop;
  4611. }
  4612. /* If we aren't stopping, the value of some hardware watchpoint may
  4613. not have changed, but the intermediate memory locations we are
  4614. watching may have. Don't bother if we're stopping; this will get
  4615. done later. */
  4616. need_remove_insert = 0;
  4617. if (! bpstat_causes_stop (bs_head))
  4618. for (bs = bs_head; bs != NULL; bs = bs->next)
  4619. if (!bs->stop
  4620. && bs->breakpoint_at
  4621. && is_hardware_watchpoint (bs->breakpoint_at))
  4622. {
  4623. struct watchpoint *w = (struct watchpoint *) bs->breakpoint_at;
  4624. update_watchpoint (w, 0 /* don't reparse. */);
  4625. need_remove_insert = 1;
  4626. }
  4627. if (need_remove_insert)
  4628. update_global_location_list (UGLL_MAY_INSERT);
  4629. else if (removed_any)
  4630. update_global_location_list (UGLL_DONT_INSERT);
  4631. return bs_head;
  4632. }
  4633. /* See breakpoint.h. */
  4634. bpstat *
  4635. bpstat_stop_status_nowatch (const address_space *aspace, CORE_ADDR bp_addr,
  4636. thread_info *thread, const target_waitstatus &ws)
  4637. {
  4638. gdb_assert (!target_stopped_by_watchpoint ());
  4639. /* Clear all watchpoints' 'watchpoint_triggered' value from a
  4640. previous stop to avoid confusing bpstat_stop_status. */
  4641. watchpoints_triggered (ws);
  4642. return bpstat_stop_status (aspace, bp_addr, thread, ws);
  4643. }
  4644. static void
  4645. handle_jit_event (CORE_ADDR address)
  4646. {
  4647. struct gdbarch *gdbarch;
  4648. infrun_debug_printf ("handling bp_jit_event");
  4649. /* Switch terminal for any messages produced by
  4650. breakpoint_re_set. */
  4651. target_terminal::ours_for_output ();
  4652. gdbarch = get_frame_arch (get_current_frame ());
  4653. /* This event is caused by a breakpoint set in `jit_breakpoint_re_set`,
  4654. thus it is expected that its objectfile can be found through
  4655. minimal symbol lookup. If it doesn't work (and assert fails), it
  4656. most likely means that `jit_breakpoint_re_set` was changes and this
  4657. function needs to be updated too. */
  4658. bound_minimal_symbol jit_bp_sym = lookup_minimal_symbol_by_pc (address);
  4659. gdb_assert (jit_bp_sym.objfile != nullptr);
  4660. jit_event_handler (gdbarch, jit_bp_sym.objfile);
  4661. target_terminal::inferior ();
  4662. }
  4663. /* Prepare WHAT final decision for infrun. */
  4664. /* Decide what infrun needs to do with this bpstat. */
  4665. struct bpstat_what
  4666. bpstat_what (bpstat *bs_head)
  4667. {
  4668. struct bpstat_what retval;
  4669. bpstat *bs;
  4670. retval.main_action = BPSTAT_WHAT_KEEP_CHECKING;
  4671. retval.call_dummy = STOP_NONE;
  4672. retval.is_longjmp = false;
  4673. for (bs = bs_head; bs != NULL; bs = bs->next)
  4674. {
  4675. /* Extract this BS's action. After processing each BS, we check
  4676. if its action overrides all we've seem so far. */
  4677. enum bpstat_what_main_action this_action = BPSTAT_WHAT_KEEP_CHECKING;
  4678. enum bptype bptype;
  4679. if (bs->breakpoint_at == NULL)
  4680. {
  4681. /* I suspect this can happen if it was a momentary
  4682. breakpoint which has since been deleted. */
  4683. bptype = bp_none;
  4684. }
  4685. else
  4686. bptype = bs->breakpoint_at->type;
  4687. switch (bptype)
  4688. {
  4689. case bp_none:
  4690. break;
  4691. case bp_breakpoint:
  4692. case bp_hardware_breakpoint:
  4693. case bp_single_step:
  4694. case bp_until:
  4695. case bp_finish:
  4696. case bp_shlib_event:
  4697. if (bs->stop)
  4698. {
  4699. if (bs->print)
  4700. this_action = BPSTAT_WHAT_STOP_NOISY;
  4701. else
  4702. this_action = BPSTAT_WHAT_STOP_SILENT;
  4703. }
  4704. else
  4705. this_action = BPSTAT_WHAT_SINGLE;
  4706. break;
  4707. case bp_watchpoint:
  4708. case bp_hardware_watchpoint:
  4709. case bp_read_watchpoint:
  4710. case bp_access_watchpoint:
  4711. if (bs->stop)
  4712. {
  4713. if (bs->print)
  4714. this_action = BPSTAT_WHAT_STOP_NOISY;
  4715. else
  4716. this_action = BPSTAT_WHAT_STOP_SILENT;
  4717. }
  4718. else
  4719. {
  4720. /* There was a watchpoint, but we're not stopping.
  4721. This requires no further action. */
  4722. }
  4723. break;
  4724. case bp_longjmp:
  4725. case bp_longjmp_call_dummy:
  4726. case bp_exception:
  4727. if (bs->stop)
  4728. {
  4729. this_action = BPSTAT_WHAT_SET_LONGJMP_RESUME;
  4730. retval.is_longjmp = bptype != bp_exception;
  4731. }
  4732. else
  4733. this_action = BPSTAT_WHAT_SINGLE;
  4734. break;
  4735. case bp_longjmp_resume:
  4736. case bp_exception_resume:
  4737. if (bs->stop)
  4738. {
  4739. this_action = BPSTAT_WHAT_CLEAR_LONGJMP_RESUME;
  4740. retval.is_longjmp = bptype == bp_longjmp_resume;
  4741. }
  4742. else
  4743. this_action = BPSTAT_WHAT_SINGLE;
  4744. break;
  4745. case bp_step_resume:
  4746. if (bs->stop)
  4747. this_action = BPSTAT_WHAT_STEP_RESUME;
  4748. else
  4749. {
  4750. /* It is for the wrong frame. */
  4751. this_action = BPSTAT_WHAT_SINGLE;
  4752. }
  4753. break;
  4754. case bp_hp_step_resume:
  4755. if (bs->stop)
  4756. this_action = BPSTAT_WHAT_HP_STEP_RESUME;
  4757. else
  4758. {
  4759. /* It is for the wrong frame. */
  4760. this_action = BPSTAT_WHAT_SINGLE;
  4761. }
  4762. break;
  4763. case bp_watchpoint_scope:
  4764. case bp_thread_event:
  4765. case bp_overlay_event:
  4766. case bp_longjmp_master:
  4767. case bp_std_terminate_master:
  4768. case bp_exception_master:
  4769. this_action = BPSTAT_WHAT_SINGLE;
  4770. break;
  4771. case bp_catchpoint:
  4772. if (bs->stop)
  4773. {
  4774. if (bs->print)
  4775. this_action = BPSTAT_WHAT_STOP_NOISY;
  4776. else
  4777. this_action = BPSTAT_WHAT_STOP_SILENT;
  4778. }
  4779. else
  4780. {
  4781. /* Some catchpoints are implemented with breakpoints.
  4782. For those, we need to step over the breakpoint. */
  4783. if (bs->bp_location_at->loc_type != bp_loc_other)
  4784. this_action = BPSTAT_WHAT_SINGLE;
  4785. }
  4786. break;
  4787. case bp_jit_event:
  4788. this_action = BPSTAT_WHAT_SINGLE;
  4789. break;
  4790. case bp_call_dummy:
  4791. /* Make sure the action is stop (silent or noisy),
  4792. so infrun.c pops the dummy frame. */
  4793. retval.call_dummy = STOP_STACK_DUMMY;
  4794. this_action = BPSTAT_WHAT_STOP_SILENT;
  4795. break;
  4796. case bp_std_terminate:
  4797. /* Make sure the action is stop (silent or noisy),
  4798. so infrun.c pops the dummy frame. */
  4799. retval.call_dummy = STOP_STD_TERMINATE;
  4800. this_action = BPSTAT_WHAT_STOP_SILENT;
  4801. break;
  4802. case bp_tracepoint:
  4803. case bp_fast_tracepoint:
  4804. case bp_static_tracepoint:
  4805. /* Tracepoint hits should not be reported back to GDB, and
  4806. if one got through somehow, it should have been filtered
  4807. out already. */
  4808. internal_error (__FILE__, __LINE__,
  4809. _("bpstat_what: tracepoint encountered"));
  4810. break;
  4811. case bp_gnu_ifunc_resolver:
  4812. /* Step over it (and insert bp_gnu_ifunc_resolver_return). */
  4813. this_action = BPSTAT_WHAT_SINGLE;
  4814. break;
  4815. case bp_gnu_ifunc_resolver_return:
  4816. /* The breakpoint will be removed, execution will restart from the
  4817. PC of the former breakpoint. */
  4818. this_action = BPSTAT_WHAT_KEEP_CHECKING;
  4819. break;
  4820. case bp_dprintf:
  4821. if (bs->stop)
  4822. this_action = BPSTAT_WHAT_STOP_SILENT;
  4823. else
  4824. this_action = BPSTAT_WHAT_SINGLE;
  4825. break;
  4826. default:
  4827. internal_error (__FILE__, __LINE__,
  4828. _("bpstat_what: unhandled bptype %d"), (int) bptype);
  4829. }
  4830. retval.main_action = std::max (retval.main_action, this_action);
  4831. }
  4832. return retval;
  4833. }
  4834. void
  4835. bpstat_run_callbacks (bpstat *bs_head)
  4836. {
  4837. bpstat *bs;
  4838. for (bs = bs_head; bs != NULL; bs = bs->next)
  4839. {
  4840. struct breakpoint *b = bs->breakpoint_at;
  4841. if (b == NULL)
  4842. continue;
  4843. switch (b->type)
  4844. {
  4845. case bp_jit_event:
  4846. handle_jit_event (bs->bp_location_at->address);
  4847. break;
  4848. case bp_gnu_ifunc_resolver:
  4849. gnu_ifunc_resolver_stop (b);
  4850. break;
  4851. case bp_gnu_ifunc_resolver_return:
  4852. gnu_ifunc_resolver_return_stop (b);
  4853. break;
  4854. }
  4855. }
  4856. }
  4857. /* See breakpoint.h. */
  4858. bool
  4859. bpstat_should_step ()
  4860. {
  4861. for (breakpoint *b : all_breakpoints ())
  4862. if (breakpoint_enabled (b) && b->type == bp_watchpoint && b->loc != NULL)
  4863. return true;
  4864. return false;
  4865. }
  4866. /* See breakpoint.h. */
  4867. bool
  4868. bpstat_causes_stop (bpstat *bs)
  4869. {
  4870. for (; bs != NULL; bs = bs->next)
  4871. if (bs->stop)
  4872. return true;
  4873. return false;
  4874. }
  4875. /* Compute a number of spaces suitable to indent the next line
  4876. so it starts at the position corresponding to the table column
  4877. named COL_NAME in the currently active table of UIOUT. */
  4878. static int
  4879. wrap_indent_at_field (struct ui_out *uiout, const char *col_name)
  4880. {
  4881. int i, total_width, width, align;
  4882. const char *text;
  4883. total_width = 0;
  4884. for (i = 1; uiout->query_table_field (i, &width, &align, &text); i++)
  4885. {
  4886. if (strcmp (text, col_name) == 0)
  4887. return total_width;
  4888. total_width += width + 1;
  4889. }
  4890. return 0;
  4891. }
  4892. /* Determine if the locations of this breakpoint will have their conditions
  4893. evaluated by the target, host or a mix of both. Returns the following:
  4894. "host": Host evals condition.
  4895. "host or target": Host or Target evals condition.
  4896. "target": Target evals condition.
  4897. */
  4898. static const char *
  4899. bp_condition_evaluator (struct breakpoint *b)
  4900. {
  4901. char host_evals = 0;
  4902. char target_evals = 0;
  4903. if (!b)
  4904. return NULL;
  4905. if (!is_breakpoint (b))
  4906. return NULL;
  4907. if (gdb_evaluates_breakpoint_condition_p ()
  4908. || !target_supports_evaluation_of_breakpoint_conditions ())
  4909. return condition_evaluation_host;
  4910. for (bp_location *bl : b->locations ())
  4911. {
  4912. if (bl->cond_bytecode)
  4913. target_evals++;
  4914. else
  4915. host_evals++;
  4916. }
  4917. if (host_evals && target_evals)
  4918. return condition_evaluation_both;
  4919. else if (target_evals)
  4920. return condition_evaluation_target;
  4921. else
  4922. return condition_evaluation_host;
  4923. }
  4924. /* Determine the breakpoint location's condition evaluator. This is
  4925. similar to bp_condition_evaluator, but for locations. */
  4926. static const char *
  4927. bp_location_condition_evaluator (struct bp_location *bl)
  4928. {
  4929. if (bl && !is_breakpoint (bl->owner))
  4930. return NULL;
  4931. if (gdb_evaluates_breakpoint_condition_p ()
  4932. || !target_supports_evaluation_of_breakpoint_conditions ())
  4933. return condition_evaluation_host;
  4934. if (bl && bl->cond_bytecode)
  4935. return condition_evaluation_target;
  4936. else
  4937. return condition_evaluation_host;
  4938. }
  4939. /* Print the LOC location out of the list of B->LOC locations. */
  4940. static void
  4941. print_breakpoint_location (struct breakpoint *b,
  4942. struct bp_location *loc)
  4943. {
  4944. struct ui_out *uiout = current_uiout;
  4945. scoped_restore_current_program_space restore_pspace;
  4946. if (loc != NULL && loc->shlib_disabled)
  4947. loc = NULL;
  4948. if (loc != NULL)
  4949. set_current_program_space (loc->pspace);
  4950. if (b->display_canonical)
  4951. uiout->field_string ("what", event_location_to_string (b->location.get ()));
  4952. else if (loc && loc->symtab)
  4953. {
  4954. const struct symbol *sym = loc->symbol;
  4955. if (sym)
  4956. {
  4957. uiout->text ("in ");
  4958. uiout->field_string ("func", sym->print_name (),
  4959. function_name_style.style ());
  4960. uiout->text (" ");
  4961. uiout->wrap_hint (wrap_indent_at_field (uiout, "what"));
  4962. uiout->text ("at ");
  4963. }
  4964. uiout->field_string ("file",
  4965. symtab_to_filename_for_display (loc->symtab),
  4966. file_name_style.style ());
  4967. uiout->text (":");
  4968. if (uiout->is_mi_like_p ())
  4969. uiout->field_string ("fullname", symtab_to_fullname (loc->symtab));
  4970. uiout->field_signed ("line", loc->line_number);
  4971. }
  4972. else if (loc)
  4973. {
  4974. string_file stb;
  4975. print_address_symbolic (loc->gdbarch, loc->address, &stb,
  4976. demangle, "");
  4977. uiout->field_stream ("at", stb);
  4978. }
  4979. else
  4980. {
  4981. uiout->field_string ("pending",
  4982. event_location_to_string (b->location.get ()));
  4983. /* If extra_string is available, it could be holding a condition
  4984. or dprintf arguments. In either case, make sure it is printed,
  4985. too, but only for non-MI streams. */
  4986. if (!uiout->is_mi_like_p () && b->extra_string != NULL)
  4987. {
  4988. if (b->type == bp_dprintf)
  4989. uiout->text (",");
  4990. else
  4991. uiout->text (" ");
  4992. uiout->text (b->extra_string.get ());
  4993. }
  4994. }
  4995. if (loc && is_breakpoint (b)
  4996. && breakpoint_condition_evaluation_mode () == condition_evaluation_target
  4997. && bp_condition_evaluator (b) == condition_evaluation_both)
  4998. {
  4999. uiout->text (" (");
  5000. uiout->field_string ("evaluated-by",
  5001. bp_location_condition_evaluator (loc));
  5002. uiout->text (")");
  5003. }
  5004. }
  5005. static const char *
  5006. bptype_string (enum bptype type)
  5007. {
  5008. struct ep_type_description
  5009. {
  5010. enum bptype type;
  5011. const char *description;
  5012. };
  5013. static struct ep_type_description bptypes[] =
  5014. {
  5015. {bp_none, "?deleted?"},
  5016. {bp_breakpoint, "breakpoint"},
  5017. {bp_hardware_breakpoint, "hw breakpoint"},
  5018. {bp_single_step, "sw single-step"},
  5019. {bp_until, "until"},
  5020. {bp_finish, "finish"},
  5021. {bp_watchpoint, "watchpoint"},
  5022. {bp_hardware_watchpoint, "hw watchpoint"},
  5023. {bp_read_watchpoint, "read watchpoint"},
  5024. {bp_access_watchpoint, "acc watchpoint"},
  5025. {bp_longjmp, "longjmp"},
  5026. {bp_longjmp_resume, "longjmp resume"},
  5027. {bp_longjmp_call_dummy, "longjmp for call dummy"},
  5028. {bp_exception, "exception"},
  5029. {bp_exception_resume, "exception resume"},
  5030. {bp_step_resume, "step resume"},
  5031. {bp_hp_step_resume, "high-priority step resume"},
  5032. {bp_watchpoint_scope, "watchpoint scope"},
  5033. {bp_call_dummy, "call dummy"},
  5034. {bp_std_terminate, "std::terminate"},
  5035. {bp_shlib_event, "shlib events"},
  5036. {bp_thread_event, "thread events"},
  5037. {bp_overlay_event, "overlay events"},
  5038. {bp_longjmp_master, "longjmp master"},
  5039. {bp_std_terminate_master, "std::terminate master"},
  5040. {bp_exception_master, "exception master"},
  5041. {bp_catchpoint, "catchpoint"},
  5042. {bp_tracepoint, "tracepoint"},
  5043. {bp_fast_tracepoint, "fast tracepoint"},
  5044. {bp_static_tracepoint, "static tracepoint"},
  5045. {bp_dprintf, "dprintf"},
  5046. {bp_jit_event, "jit events"},
  5047. {bp_gnu_ifunc_resolver, "STT_GNU_IFUNC resolver"},
  5048. {bp_gnu_ifunc_resolver_return, "STT_GNU_IFUNC resolver return"},
  5049. };
  5050. if (((int) type >= (sizeof (bptypes) / sizeof (bptypes[0])))
  5051. || ((int) type != bptypes[(int) type].type))
  5052. internal_error (__FILE__, __LINE__,
  5053. _("bptypes table does not describe type #%d."),
  5054. (int) type);
  5055. return bptypes[(int) type].description;
  5056. }
  5057. /* For MI, output a field named 'thread-groups' with a list as the value.
  5058. For CLI, prefix the list with the string 'inf'. */
  5059. static void
  5060. output_thread_groups (struct ui_out *uiout,
  5061. const char *field_name,
  5062. const std::vector<int> &inf_nums,
  5063. int mi_only)
  5064. {
  5065. int is_mi = uiout->is_mi_like_p ();
  5066. /* For backward compatibility, don't display inferiors in CLI unless
  5067. there are several. Always display them for MI. */
  5068. if (!is_mi && mi_only)
  5069. return;
  5070. ui_out_emit_list list_emitter (uiout, field_name);
  5071. for (size_t i = 0; i < inf_nums.size (); i++)
  5072. {
  5073. if (is_mi)
  5074. {
  5075. char mi_group[10];
  5076. xsnprintf (mi_group, sizeof (mi_group), "i%d", inf_nums[i]);
  5077. uiout->field_string (NULL, mi_group);
  5078. }
  5079. else
  5080. {
  5081. if (i == 0)
  5082. uiout->text (" inf ");
  5083. else
  5084. uiout->text (", ");
  5085. uiout->text (plongest (inf_nums[i]));
  5086. }
  5087. }
  5088. }
  5089. /* Print B to gdb_stdout. If RAW_LOC, print raw breakpoint locations
  5090. instead of going via breakpoint_ops::print_one. This makes "maint
  5091. info breakpoints" show the software breakpoint locations of
  5092. catchpoints, which are considered internal implementation
  5093. detail. */
  5094. static void
  5095. print_one_breakpoint_location (struct breakpoint *b,
  5096. struct bp_location *loc,
  5097. int loc_number,
  5098. struct bp_location **last_loc,
  5099. int allflag, bool raw_loc)
  5100. {
  5101. struct command_line *l;
  5102. static char bpenables[] = "nynny";
  5103. struct ui_out *uiout = current_uiout;
  5104. int header_of_multiple = 0;
  5105. int part_of_multiple = (loc != NULL);
  5106. struct value_print_options opts;
  5107. get_user_print_options (&opts);
  5108. gdb_assert (!loc || loc_number != 0);
  5109. /* See comment in print_one_breakpoint concerning treatment of
  5110. breakpoints with single disabled location. */
  5111. if (loc == NULL
  5112. && (b->loc != NULL
  5113. && (b->loc->next != NULL
  5114. || !b->loc->enabled || b->loc->disabled_by_cond)))
  5115. header_of_multiple = 1;
  5116. if (loc == NULL)
  5117. loc = b->loc;
  5118. annotate_record ();
  5119. /* 1 */
  5120. annotate_field (0);
  5121. if (part_of_multiple)
  5122. uiout->field_fmt ("number", "%d.%d", b->number, loc_number);
  5123. else
  5124. uiout->field_signed ("number", b->number);
  5125. /* 2 */
  5126. annotate_field (1);
  5127. if (part_of_multiple)
  5128. uiout->field_skip ("type");
  5129. else
  5130. uiout->field_string ("type", bptype_string (b->type));
  5131. /* 3 */
  5132. annotate_field (2);
  5133. if (part_of_multiple)
  5134. uiout->field_skip ("disp");
  5135. else
  5136. uiout->field_string ("disp", bpdisp_text (b->disposition));
  5137. /* 4 */
  5138. annotate_field (3);
  5139. /* For locations that are disabled because of an invalid condition,
  5140. display "N*" on CLI, where "*" refers to a footnote below the
  5141. table. For MI, simply display a "N" without a footnote. */
  5142. const char *N = (uiout->is_mi_like_p ()) ? "N" : "N*";
  5143. if (part_of_multiple)
  5144. uiout->field_string ("enabled", (loc->disabled_by_cond ? N
  5145. : (loc->enabled ? "y" : "n")));
  5146. else
  5147. uiout->field_fmt ("enabled", "%c", bpenables[(int) b->enable_state]);
  5148. /* 5 and 6 */
  5149. if (!raw_loc && b->ops != NULL && b->ops->print_one != NULL)
  5150. b->ops->print_one (b, last_loc);
  5151. else
  5152. {
  5153. if (is_watchpoint (b))
  5154. {
  5155. struct watchpoint *w = (struct watchpoint *) b;
  5156. /* Field 4, the address, is omitted (which makes the columns
  5157. not line up too nicely with the headers, but the effect
  5158. is relatively readable). */
  5159. if (opts.addressprint)
  5160. uiout->field_skip ("addr");
  5161. annotate_field (5);
  5162. uiout->field_string ("what", w->exp_string.get ());
  5163. }
  5164. else if (!is_catchpoint (b) || is_exception_catchpoint (b)
  5165. || is_ada_exception_catchpoint (b))
  5166. {
  5167. if (opts.addressprint)
  5168. {
  5169. annotate_field (4);
  5170. if (header_of_multiple)
  5171. uiout->field_string ("addr", "<MULTIPLE>",
  5172. metadata_style.style ());
  5173. else if (b->loc == NULL || loc->shlib_disabled)
  5174. uiout->field_string ("addr", "<PENDING>",
  5175. metadata_style.style ());
  5176. else
  5177. uiout->field_core_addr ("addr",
  5178. loc->gdbarch, loc->address);
  5179. }
  5180. annotate_field (5);
  5181. if (!header_of_multiple)
  5182. print_breakpoint_location (b, loc);
  5183. if (b->loc)
  5184. *last_loc = b->loc;
  5185. }
  5186. }
  5187. if (loc != NULL && !header_of_multiple)
  5188. {
  5189. std::vector<int> inf_nums;
  5190. int mi_only = 1;
  5191. for (inferior *inf : all_inferiors ())
  5192. {
  5193. if (inf->pspace == loc->pspace)
  5194. inf_nums.push_back (inf->num);
  5195. }
  5196. /* For backward compatibility, don't display inferiors in CLI unless
  5197. there are several. Always display for MI. */
  5198. if (allflag
  5199. || (!gdbarch_has_global_breakpoints (target_gdbarch ())
  5200. && (program_spaces.size () > 1
  5201. || number_of_inferiors () > 1)
  5202. /* LOC is for existing B, it cannot be in
  5203. moribund_locations and thus having NULL OWNER. */
  5204. && loc->owner->type != bp_catchpoint))
  5205. mi_only = 0;
  5206. output_thread_groups (uiout, "thread-groups", inf_nums, mi_only);
  5207. }
  5208. if (!part_of_multiple)
  5209. {
  5210. if (b->thread != -1)
  5211. {
  5212. /* FIXME: This seems to be redundant and lost here; see the
  5213. "stop only in" line a little further down. */
  5214. uiout->text (" thread ");
  5215. uiout->field_signed ("thread", b->thread);
  5216. }
  5217. else if (b->task != 0)
  5218. {
  5219. uiout->text (" task ");
  5220. uiout->field_signed ("task", b->task);
  5221. }
  5222. }
  5223. uiout->text ("\n");
  5224. if (!part_of_multiple)
  5225. b->ops->print_one_detail (b, uiout);
  5226. if (part_of_multiple && frame_id_p (b->frame_id))
  5227. {
  5228. annotate_field (6);
  5229. uiout->text ("\tstop only in stack frame at ");
  5230. /* FIXME: cagney/2002-12-01: Shouldn't be poking around inside
  5231. the frame ID. */
  5232. uiout->field_core_addr ("frame",
  5233. b->gdbarch, b->frame_id.stack_addr);
  5234. uiout->text ("\n");
  5235. }
  5236. if (!part_of_multiple && b->cond_string)
  5237. {
  5238. annotate_field (7);
  5239. if (is_tracepoint (b))
  5240. uiout->text ("\ttrace only if ");
  5241. else
  5242. uiout->text ("\tstop only if ");
  5243. uiout->field_string ("cond", b->cond_string.get ());
  5244. /* Print whether the target is doing the breakpoint's condition
  5245. evaluation. If GDB is doing the evaluation, don't print anything. */
  5246. if (is_breakpoint (b)
  5247. && breakpoint_condition_evaluation_mode ()
  5248. == condition_evaluation_target)
  5249. {
  5250. uiout->message (" (%pF evals)",
  5251. string_field ("evaluated-by",
  5252. bp_condition_evaluator (b)));
  5253. }
  5254. uiout->text ("\n");
  5255. }
  5256. if (!part_of_multiple && b->thread != -1)
  5257. {
  5258. /* FIXME should make an annotation for this. */
  5259. uiout->text ("\tstop only in thread ");
  5260. if (uiout->is_mi_like_p ())
  5261. uiout->field_signed ("thread", b->thread);
  5262. else
  5263. {
  5264. struct thread_info *thr = find_thread_global_id (b->thread);
  5265. uiout->field_string ("thread", print_thread_id (thr));
  5266. }
  5267. uiout->text ("\n");
  5268. }
  5269. if (!part_of_multiple)
  5270. {
  5271. if (b->hit_count)
  5272. {
  5273. /* FIXME should make an annotation for this. */
  5274. if (is_catchpoint (b))
  5275. uiout->text ("\tcatchpoint");
  5276. else if (is_tracepoint (b))
  5277. uiout->text ("\ttracepoint");
  5278. else
  5279. uiout->text ("\tbreakpoint");
  5280. uiout->text (" already hit ");
  5281. uiout->field_signed ("times", b->hit_count);
  5282. if (b->hit_count == 1)
  5283. uiout->text (" time\n");
  5284. else
  5285. uiout->text (" times\n");
  5286. }
  5287. else
  5288. {
  5289. /* Output the count also if it is zero, but only if this is mi. */
  5290. if (uiout->is_mi_like_p ())
  5291. uiout->field_signed ("times", b->hit_count);
  5292. }
  5293. }
  5294. if (!part_of_multiple && b->ignore_count)
  5295. {
  5296. annotate_field (8);
  5297. uiout->message ("\tignore next %pF hits\n",
  5298. signed_field ("ignore", b->ignore_count));
  5299. }
  5300. /* Note that an enable count of 1 corresponds to "enable once"
  5301. behavior, which is reported by the combination of enablement and
  5302. disposition, so we don't need to mention it here. */
  5303. if (!part_of_multiple && b->enable_count > 1)
  5304. {
  5305. annotate_field (8);
  5306. uiout->text ("\tdisable after ");
  5307. /* Tweak the wording to clarify that ignore and enable counts
  5308. are distinct, and have additive effect. */
  5309. if (b->ignore_count)
  5310. uiout->text ("additional ");
  5311. else
  5312. uiout->text ("next ");
  5313. uiout->field_signed ("enable", b->enable_count);
  5314. uiout->text (" hits\n");
  5315. }
  5316. if (!part_of_multiple && is_tracepoint (b))
  5317. {
  5318. struct tracepoint *tp = (struct tracepoint *) b;
  5319. if (tp->traceframe_usage)
  5320. {
  5321. uiout->text ("\ttrace buffer usage ");
  5322. uiout->field_signed ("traceframe-usage", tp->traceframe_usage);
  5323. uiout->text (" bytes\n");
  5324. }
  5325. }
  5326. l = b->commands ? b->commands.get () : NULL;
  5327. if (!part_of_multiple && l)
  5328. {
  5329. annotate_field (9);
  5330. ui_out_emit_tuple tuple_emitter (uiout, "script");
  5331. print_command_lines (uiout, l, 4);
  5332. }
  5333. if (is_tracepoint (b))
  5334. {
  5335. struct tracepoint *t = (struct tracepoint *) b;
  5336. if (!part_of_multiple && t->pass_count)
  5337. {
  5338. annotate_field (10);
  5339. uiout->text ("\tpass count ");
  5340. uiout->field_signed ("pass", t->pass_count);
  5341. uiout->text (" \n");
  5342. }
  5343. /* Don't display it when tracepoint or tracepoint location is
  5344. pending. */
  5345. if (!header_of_multiple && loc != NULL && !loc->shlib_disabled)
  5346. {
  5347. annotate_field (11);
  5348. if (uiout->is_mi_like_p ())
  5349. uiout->field_string ("installed",
  5350. loc->inserted ? "y" : "n");
  5351. else
  5352. {
  5353. if (loc->inserted)
  5354. uiout->text ("\t");
  5355. else
  5356. uiout->text ("\tnot ");
  5357. uiout->text ("installed on target\n");
  5358. }
  5359. }
  5360. }
  5361. if (uiout->is_mi_like_p () && !part_of_multiple)
  5362. {
  5363. if (is_watchpoint (b))
  5364. {
  5365. struct watchpoint *w = (struct watchpoint *) b;
  5366. uiout->field_string ("original-location", w->exp_string.get ());
  5367. }
  5368. else if (b->location != NULL
  5369. && event_location_to_string (b->location.get ()) != NULL)
  5370. uiout->field_string ("original-location",
  5371. event_location_to_string (b->location.get ()));
  5372. }
  5373. }
  5374. /* See breakpoint.h. */
  5375. bool fix_multi_location_breakpoint_output_globally = false;
  5376. static void
  5377. print_one_breakpoint (struct breakpoint *b,
  5378. struct bp_location **last_loc,
  5379. int allflag)
  5380. {
  5381. struct ui_out *uiout = current_uiout;
  5382. bool use_fixed_output
  5383. = (uiout->test_flags (fix_multi_location_breakpoint_output)
  5384. || fix_multi_location_breakpoint_output_globally);
  5385. gdb::optional<ui_out_emit_tuple> bkpt_tuple_emitter (gdb::in_place, uiout, "bkpt");
  5386. print_one_breakpoint_location (b, NULL, 0, last_loc, allflag, false);
  5387. /* The mi2 broken format: the main breakpoint tuple ends here, the locations
  5388. are outside. */
  5389. if (!use_fixed_output)
  5390. bkpt_tuple_emitter.reset ();
  5391. /* If this breakpoint has custom print function,
  5392. it's already printed. Otherwise, print individual
  5393. locations, if any. */
  5394. if (b->ops == NULL
  5395. || b->ops->print_one == NULL
  5396. || allflag)
  5397. {
  5398. /* If breakpoint has a single location that is disabled, we
  5399. print it as if it had several locations, since otherwise it's
  5400. hard to represent "breakpoint enabled, location disabled"
  5401. situation.
  5402. Note that while hardware watchpoints have several locations
  5403. internally, that's not a property exposed to users.
  5404. Likewise, while catchpoints may be implemented with
  5405. breakpoints (e.g., catch throw), that's not a property
  5406. exposed to users. We do however display the internal
  5407. breakpoint locations with "maint info breakpoints". */
  5408. if (!is_hardware_watchpoint (b)
  5409. && (!is_catchpoint (b) || is_exception_catchpoint (b)
  5410. || is_ada_exception_catchpoint (b))
  5411. && (allflag
  5412. || (b->loc && (b->loc->next
  5413. || !b->loc->enabled
  5414. || b->loc->disabled_by_cond))))
  5415. {
  5416. gdb::optional<ui_out_emit_list> locations_list;
  5417. /* For MI version <= 2, keep the behavior where GDB outputs an invalid
  5418. MI record. For later versions, place breakpoint locations in a
  5419. list. */
  5420. if (uiout->is_mi_like_p () && use_fixed_output)
  5421. locations_list.emplace (uiout, "locations");
  5422. int n = 1;
  5423. for (bp_location *loc : b->locations ())
  5424. {
  5425. ui_out_emit_tuple loc_tuple_emitter (uiout, NULL);
  5426. print_one_breakpoint_location (b, loc, n, last_loc,
  5427. allflag, allflag);
  5428. n++;
  5429. }
  5430. }
  5431. }
  5432. }
  5433. static int
  5434. breakpoint_address_bits (struct breakpoint *b)
  5435. {
  5436. int print_address_bits = 0;
  5437. /* Software watchpoints that aren't watching memory don't have an
  5438. address to print. */
  5439. if (is_no_memory_software_watchpoint (b))
  5440. return 0;
  5441. for (bp_location *loc : b->locations ())
  5442. {
  5443. int addr_bit;
  5444. addr_bit = gdbarch_addr_bit (loc->gdbarch);
  5445. if (addr_bit > print_address_bits)
  5446. print_address_bits = addr_bit;
  5447. }
  5448. return print_address_bits;
  5449. }
  5450. /* See breakpoint.h. */
  5451. void
  5452. print_breakpoint (breakpoint *b)
  5453. {
  5454. struct bp_location *dummy_loc = NULL;
  5455. print_one_breakpoint (b, &dummy_loc, 0);
  5456. }
  5457. /* Return true if this breakpoint was set by the user, false if it is
  5458. internal or momentary. */
  5459. int
  5460. user_breakpoint_p (struct breakpoint *b)
  5461. {
  5462. return b->number > 0;
  5463. }
  5464. /* See breakpoint.h. */
  5465. int
  5466. pending_breakpoint_p (struct breakpoint *b)
  5467. {
  5468. return b->loc == NULL;
  5469. }
  5470. /* Print information on breakpoints (including watchpoints and tracepoints).
  5471. If non-NULL, BP_NUM_LIST is a list of numbers and number ranges as
  5472. understood by number_or_range_parser. Only breakpoints included in this
  5473. list are then printed.
  5474. If SHOW_INTERNAL is true, print internal breakpoints.
  5475. If FILTER is non-NULL, call it on each breakpoint and only include the
  5476. ones for which it returns true.
  5477. Return the total number of breakpoints listed. */
  5478. static int
  5479. breakpoint_1 (const char *bp_num_list, bool show_internal,
  5480. bool (*filter) (const struct breakpoint *))
  5481. {
  5482. struct bp_location *last_loc = NULL;
  5483. int nr_printable_breakpoints;
  5484. struct value_print_options opts;
  5485. int print_address_bits = 0;
  5486. int print_type_col_width = 14;
  5487. struct ui_out *uiout = current_uiout;
  5488. bool has_disabled_by_cond_location = false;
  5489. get_user_print_options (&opts);
  5490. /* Compute the number of rows in the table, as well as the size
  5491. required for address fields. */
  5492. nr_printable_breakpoints = 0;
  5493. for (breakpoint *b : all_breakpoints ())
  5494. {
  5495. /* If we have a filter, only list the breakpoints it accepts. */
  5496. if (filter && !filter (b))
  5497. continue;
  5498. /* If we have a BP_NUM_LIST string, it is a list of breakpoints to
  5499. accept. Skip the others. */
  5500. if (bp_num_list != NULL && *bp_num_list != '\0')
  5501. {
  5502. if (show_internal && parse_and_eval_long (bp_num_list) != b->number)
  5503. continue;
  5504. if (!show_internal && !number_is_in_list (bp_num_list, b->number))
  5505. continue;
  5506. }
  5507. if (show_internal || user_breakpoint_p (b))
  5508. {
  5509. int addr_bit, type_len;
  5510. addr_bit = breakpoint_address_bits (b);
  5511. if (addr_bit > print_address_bits)
  5512. print_address_bits = addr_bit;
  5513. type_len = strlen (bptype_string (b->type));
  5514. if (type_len > print_type_col_width)
  5515. print_type_col_width = type_len;
  5516. nr_printable_breakpoints++;
  5517. }
  5518. }
  5519. {
  5520. ui_out_emit_table table_emitter (uiout,
  5521. opts.addressprint ? 6 : 5,
  5522. nr_printable_breakpoints,
  5523. "BreakpointTable");
  5524. if (nr_printable_breakpoints > 0)
  5525. annotate_breakpoints_headers ();
  5526. if (nr_printable_breakpoints > 0)
  5527. annotate_field (0);
  5528. uiout->table_header (7, ui_left, "number", "Num"); /* 1 */
  5529. if (nr_printable_breakpoints > 0)
  5530. annotate_field (1);
  5531. uiout->table_header (print_type_col_width, ui_left, "type", "Type"); /* 2 */
  5532. if (nr_printable_breakpoints > 0)
  5533. annotate_field (2);
  5534. uiout->table_header (4, ui_left, "disp", "Disp"); /* 3 */
  5535. if (nr_printable_breakpoints > 0)
  5536. annotate_field (3);
  5537. uiout->table_header (3, ui_left, "enabled", "Enb"); /* 4 */
  5538. if (opts.addressprint)
  5539. {
  5540. if (nr_printable_breakpoints > 0)
  5541. annotate_field (4);
  5542. if (print_address_bits <= 32)
  5543. uiout->table_header (10, ui_left, "addr", "Address"); /* 5 */
  5544. else
  5545. uiout->table_header (18, ui_left, "addr", "Address"); /* 5 */
  5546. }
  5547. if (nr_printable_breakpoints > 0)
  5548. annotate_field (5);
  5549. uiout->table_header (40, ui_noalign, "what", "What"); /* 6 */
  5550. uiout->table_body ();
  5551. if (nr_printable_breakpoints > 0)
  5552. annotate_breakpoints_table ();
  5553. for (breakpoint *b : all_breakpoints ())
  5554. {
  5555. QUIT;
  5556. /* If we have a filter, only list the breakpoints it accepts. */
  5557. if (filter && !filter (b))
  5558. continue;
  5559. /* If we have a BP_NUM_LIST string, it is a list of breakpoints to
  5560. accept. Skip the others. */
  5561. if (bp_num_list != NULL && *bp_num_list != '\0')
  5562. {
  5563. if (show_internal) /* maintenance info breakpoint */
  5564. {
  5565. if (parse_and_eval_long (bp_num_list) != b->number)
  5566. continue;
  5567. }
  5568. else /* all others */
  5569. {
  5570. if (!number_is_in_list (bp_num_list, b->number))
  5571. continue;
  5572. }
  5573. }
  5574. /* We only print out user settable breakpoints unless the
  5575. show_internal is set. */
  5576. if (show_internal || user_breakpoint_p (b))
  5577. {
  5578. print_one_breakpoint (b, &last_loc, show_internal);
  5579. for (bp_location *loc : b->locations ())
  5580. if (loc->disabled_by_cond)
  5581. has_disabled_by_cond_location = true;
  5582. }
  5583. }
  5584. }
  5585. if (nr_printable_breakpoints == 0)
  5586. {
  5587. /* If there's a filter, let the caller decide how to report
  5588. empty list. */
  5589. if (!filter)
  5590. {
  5591. if (bp_num_list == NULL || *bp_num_list == '\0')
  5592. uiout->message ("No breakpoints or watchpoints.\n");
  5593. else
  5594. uiout->message ("No breakpoint or watchpoint matching '%s'.\n",
  5595. bp_num_list);
  5596. }
  5597. }
  5598. else
  5599. {
  5600. if (last_loc && !server_command)
  5601. set_next_address (last_loc->gdbarch, last_loc->address);
  5602. if (has_disabled_by_cond_location && !uiout->is_mi_like_p ())
  5603. uiout->message (_("(*): Breakpoint condition is invalid at this "
  5604. "location.\n"));
  5605. }
  5606. /* FIXME? Should this be moved up so that it is only called when
  5607. there have been breakpoints? */
  5608. annotate_breakpoints_table_end ();
  5609. return nr_printable_breakpoints;
  5610. }
  5611. /* Display the value of default-collect in a way that is generally
  5612. compatible with the breakpoint list. */
  5613. static void
  5614. default_collect_info (void)
  5615. {
  5616. struct ui_out *uiout = current_uiout;
  5617. /* If it has no value (which is frequently the case), say nothing; a
  5618. message like "No default-collect." gets in user's face when it's
  5619. not wanted. */
  5620. if (default_collect.empty ())
  5621. return;
  5622. /* The following phrase lines up nicely with per-tracepoint collect
  5623. actions. */
  5624. uiout->text ("default collect ");
  5625. uiout->field_string ("default-collect", default_collect);
  5626. uiout->text (" \n");
  5627. }
  5628. static void
  5629. info_breakpoints_command (const char *args, int from_tty)
  5630. {
  5631. breakpoint_1 (args, false, NULL);
  5632. default_collect_info ();
  5633. }
  5634. static void
  5635. info_watchpoints_command (const char *args, int from_tty)
  5636. {
  5637. int num_printed = breakpoint_1 (args, false, is_watchpoint);
  5638. struct ui_out *uiout = current_uiout;
  5639. if (num_printed == 0)
  5640. {
  5641. if (args == NULL || *args == '\0')
  5642. uiout->message ("No watchpoints.\n");
  5643. else
  5644. uiout->message ("No watchpoint matching '%s'.\n", args);
  5645. }
  5646. }
  5647. static void
  5648. maintenance_info_breakpoints (const char *args, int from_tty)
  5649. {
  5650. breakpoint_1 (args, true, NULL);
  5651. default_collect_info ();
  5652. }
  5653. static int
  5654. breakpoint_has_pc (struct breakpoint *b,
  5655. struct program_space *pspace,
  5656. CORE_ADDR pc, struct obj_section *section)
  5657. {
  5658. for (bp_location *bl : b->locations ())
  5659. {
  5660. if (bl->pspace == pspace
  5661. && bl->address == pc
  5662. && (!overlay_debugging || bl->section == section))
  5663. return 1;
  5664. }
  5665. return 0;
  5666. }
  5667. /* Print a message describing any user-breakpoints set at PC. This
  5668. concerns with logical breakpoints, so we match program spaces, not
  5669. address spaces. */
  5670. static void
  5671. describe_other_breakpoints (struct gdbarch *gdbarch,
  5672. struct program_space *pspace, CORE_ADDR pc,
  5673. struct obj_section *section, int thread)
  5674. {
  5675. int others = 0;
  5676. for (breakpoint *b : all_breakpoints ())
  5677. others += (user_breakpoint_p (b)
  5678. && breakpoint_has_pc (b, pspace, pc, section));
  5679. if (others > 0)
  5680. {
  5681. if (others == 1)
  5682. gdb_printf (_("Note: breakpoint "));
  5683. else /* if (others == ???) */
  5684. gdb_printf (_("Note: breakpoints "));
  5685. for (breakpoint *b : all_breakpoints ())
  5686. if (user_breakpoint_p (b) && breakpoint_has_pc (b, pspace, pc, section))
  5687. {
  5688. others--;
  5689. gdb_printf ("%d", b->number);
  5690. if (b->thread == -1 && thread != -1)
  5691. gdb_printf (" (all threads)");
  5692. else if (b->thread != -1)
  5693. gdb_printf (" (thread %d)", b->thread);
  5694. gdb_printf ("%s%s ",
  5695. ((b->enable_state == bp_disabled
  5696. || b->enable_state == bp_call_disabled)
  5697. ? " (disabled)"
  5698. : ""),
  5699. (others > 1) ? ","
  5700. : ((others == 1) ? " and" : ""));
  5701. }
  5702. current_uiout->message (_("also set at pc %ps.\n"),
  5703. styled_string (address_style.style (),
  5704. paddress (gdbarch, pc)));
  5705. }
  5706. }
  5707. /* Return true iff it is meaningful to use the address member of LOC.
  5708. For some breakpoint types, the locations' address members are
  5709. irrelevant and it makes no sense to attempt to compare them to
  5710. other addresses (or use them for any other purpose either).
  5711. More specifically, software watchpoints and catchpoints that are
  5712. not backed by breakpoints always have a zero valued location
  5713. address and we don't want to mark breakpoints of any of these types
  5714. to be a duplicate of an actual breakpoint location at address
  5715. zero. */
  5716. static bool
  5717. bl_address_is_meaningful (bp_location *loc)
  5718. {
  5719. return loc->loc_type != bp_loc_other;
  5720. }
  5721. /* Assuming LOC1 and LOC2's owners are hardware watchpoints, returns
  5722. true if LOC1 and LOC2 represent the same watchpoint location. */
  5723. static int
  5724. watchpoint_locations_match (struct bp_location *loc1,
  5725. struct bp_location *loc2)
  5726. {
  5727. struct watchpoint *w1 = (struct watchpoint *) loc1->owner;
  5728. struct watchpoint *w2 = (struct watchpoint *) loc2->owner;
  5729. /* Both of them must exist. */
  5730. gdb_assert (w1 != NULL);
  5731. gdb_assert (w2 != NULL);
  5732. /* If the target can evaluate the condition expression in hardware,
  5733. then we we need to insert both watchpoints even if they are at
  5734. the same place. Otherwise the watchpoint will only trigger when
  5735. the condition of whichever watchpoint was inserted evaluates to
  5736. true, not giving a chance for GDB to check the condition of the
  5737. other watchpoint. */
  5738. if ((w1->cond_exp
  5739. && target_can_accel_watchpoint_condition (loc1->address,
  5740. loc1->length,
  5741. loc1->watchpoint_type,
  5742. w1->cond_exp.get ()))
  5743. || (w2->cond_exp
  5744. && target_can_accel_watchpoint_condition (loc2->address,
  5745. loc2->length,
  5746. loc2->watchpoint_type,
  5747. w2->cond_exp.get ())))
  5748. return 0;
  5749. /* Note that this checks the owner's type, not the location's. In
  5750. case the target does not support read watchpoints, but does
  5751. support access watchpoints, we'll have bp_read_watchpoint
  5752. watchpoints with hw_access locations. Those should be considered
  5753. duplicates of hw_read locations. The hw_read locations will
  5754. become hw_access locations later. */
  5755. return (loc1->owner->type == loc2->owner->type
  5756. && loc1->pspace->aspace == loc2->pspace->aspace
  5757. && loc1->address == loc2->address
  5758. && loc1->length == loc2->length);
  5759. }
  5760. /* See breakpoint.h. */
  5761. int
  5762. breakpoint_address_match (const address_space *aspace1, CORE_ADDR addr1,
  5763. const address_space *aspace2, CORE_ADDR addr2)
  5764. {
  5765. return ((gdbarch_has_global_breakpoints (target_gdbarch ())
  5766. || aspace1 == aspace2)
  5767. && addr1 == addr2);
  5768. }
  5769. /* Returns true if {ASPACE2,ADDR2} falls within the range determined by
  5770. {ASPACE1,ADDR1,LEN1}. In most targets, this can only be true if ASPACE1
  5771. matches ASPACE2. On targets that have global breakpoints, the address
  5772. space doesn't really matter. */
  5773. static int
  5774. breakpoint_address_match_range (const address_space *aspace1,
  5775. CORE_ADDR addr1,
  5776. int len1, const address_space *aspace2,
  5777. CORE_ADDR addr2)
  5778. {
  5779. return ((gdbarch_has_global_breakpoints (target_gdbarch ())
  5780. || aspace1 == aspace2)
  5781. && addr2 >= addr1 && addr2 < addr1 + len1);
  5782. }
  5783. /* Returns true if {ASPACE,ADDR} matches the breakpoint BL. BL may be
  5784. a ranged breakpoint. In most targets, a match happens only if ASPACE
  5785. matches the breakpoint's address space. On targets that have global
  5786. breakpoints, the address space doesn't really matter. */
  5787. static int
  5788. breakpoint_location_address_match (struct bp_location *bl,
  5789. const address_space *aspace,
  5790. CORE_ADDR addr)
  5791. {
  5792. return (breakpoint_address_match (bl->pspace->aspace, bl->address,
  5793. aspace, addr)
  5794. || (bl->length
  5795. && breakpoint_address_match_range (bl->pspace->aspace,
  5796. bl->address, bl->length,
  5797. aspace, addr)));
  5798. }
  5799. /* Returns true if the [ADDR,ADDR+LEN) range in ASPACE overlaps
  5800. breakpoint BL. BL may be a ranged breakpoint. In most targets, a
  5801. match happens only if ASPACE matches the breakpoint's address
  5802. space. On targets that have global breakpoints, the address space
  5803. doesn't really matter. */
  5804. static int
  5805. breakpoint_location_address_range_overlap (struct bp_location *bl,
  5806. const address_space *aspace,
  5807. CORE_ADDR addr, int len)
  5808. {
  5809. if (gdbarch_has_global_breakpoints (target_gdbarch ())
  5810. || bl->pspace->aspace == aspace)
  5811. {
  5812. int bl_len = bl->length != 0 ? bl->length : 1;
  5813. if (mem_ranges_overlap (addr, len, bl->address, bl_len))
  5814. return 1;
  5815. }
  5816. return 0;
  5817. }
  5818. /* If LOC1 and LOC2's owners are not tracepoints, returns false directly.
  5819. Then, if LOC1 and LOC2 represent the same tracepoint location, returns
  5820. true, otherwise returns false. */
  5821. static int
  5822. tracepoint_locations_match (struct bp_location *loc1,
  5823. struct bp_location *loc2)
  5824. {
  5825. if (is_tracepoint (loc1->owner) && is_tracepoint (loc2->owner))
  5826. /* Since tracepoint locations are never duplicated with others', tracepoint
  5827. locations at the same address of different tracepoints are regarded as
  5828. different locations. */
  5829. return (loc1->address == loc2->address && loc1->owner == loc2->owner);
  5830. else
  5831. return 0;
  5832. }
  5833. /* Assuming LOC1 and LOC2's types' have meaningful target addresses
  5834. (bl_address_is_meaningful), returns true if LOC1 and LOC2 represent
  5835. the same location. If SW_HW_BPS_MATCH is true, then software
  5836. breakpoint locations and hardware breakpoint locations match,
  5837. otherwise they don't. */
  5838. static int
  5839. breakpoint_locations_match (struct bp_location *loc1,
  5840. struct bp_location *loc2,
  5841. bool sw_hw_bps_match)
  5842. {
  5843. int hw_point1, hw_point2;
  5844. /* Both of them must not be in moribund_locations. */
  5845. gdb_assert (loc1->owner != NULL);
  5846. gdb_assert (loc2->owner != NULL);
  5847. hw_point1 = is_hardware_watchpoint (loc1->owner);
  5848. hw_point2 = is_hardware_watchpoint (loc2->owner);
  5849. if (hw_point1 != hw_point2)
  5850. return 0;
  5851. else if (hw_point1)
  5852. return watchpoint_locations_match (loc1, loc2);
  5853. else if (is_tracepoint (loc1->owner) || is_tracepoint (loc2->owner))
  5854. return tracepoint_locations_match (loc1, loc2);
  5855. else
  5856. /* We compare bp_location.length in order to cover ranged
  5857. breakpoints. Keep this in sync with
  5858. bp_location_is_less_than. */
  5859. return (breakpoint_address_match (loc1->pspace->aspace, loc1->address,
  5860. loc2->pspace->aspace, loc2->address)
  5861. && (loc1->loc_type == loc2->loc_type || sw_hw_bps_match)
  5862. && loc1->length == loc2->length);
  5863. }
  5864. static void
  5865. breakpoint_adjustment_warning (CORE_ADDR from_addr, CORE_ADDR to_addr,
  5866. int bnum, int have_bnum)
  5867. {
  5868. /* The longest string possibly returned by hex_string_custom
  5869. is 50 chars. These must be at least that big for safety. */
  5870. char astr1[64];
  5871. char astr2[64];
  5872. strcpy (astr1, hex_string_custom ((unsigned long) from_addr, 8));
  5873. strcpy (astr2, hex_string_custom ((unsigned long) to_addr, 8));
  5874. if (have_bnum)
  5875. warning (_("Breakpoint %d address previously adjusted from %s to %s."),
  5876. bnum, astr1, astr2);
  5877. else
  5878. warning (_("Breakpoint address adjusted from %s to %s."), astr1, astr2);
  5879. }
  5880. /* Adjust a breakpoint's address to account for architectural
  5881. constraints on breakpoint placement. Return the adjusted address.
  5882. Note: Very few targets require this kind of adjustment. For most
  5883. targets, this function is simply the identity function. */
  5884. static CORE_ADDR
  5885. adjust_breakpoint_address (struct gdbarch *gdbarch,
  5886. CORE_ADDR bpaddr, enum bptype bptype)
  5887. {
  5888. if (bptype == bp_watchpoint
  5889. || bptype == bp_hardware_watchpoint
  5890. || bptype == bp_read_watchpoint
  5891. || bptype == bp_access_watchpoint
  5892. || bptype == bp_catchpoint)
  5893. {
  5894. /* Watchpoints and the various bp_catch_* eventpoints should not
  5895. have their addresses modified. */
  5896. return bpaddr;
  5897. }
  5898. else if (bptype == bp_single_step)
  5899. {
  5900. /* Single-step breakpoints should not have their addresses
  5901. modified. If there's any architectural constrain that
  5902. applies to this address, then it should have already been
  5903. taken into account when the breakpoint was created in the
  5904. first place. If we didn't do this, stepping through e.g.,
  5905. Thumb-2 IT blocks would break. */
  5906. return bpaddr;
  5907. }
  5908. else
  5909. {
  5910. CORE_ADDR adjusted_bpaddr = bpaddr;
  5911. if (gdbarch_adjust_breakpoint_address_p (gdbarch))
  5912. {
  5913. /* Some targets have architectural constraints on the placement
  5914. of breakpoint instructions. Obtain the adjusted address. */
  5915. adjusted_bpaddr = gdbarch_adjust_breakpoint_address (gdbarch, bpaddr);
  5916. }
  5917. adjusted_bpaddr = address_significant (gdbarch, adjusted_bpaddr);
  5918. /* An adjusted breakpoint address can significantly alter
  5919. a user's expectations. Print a warning if an adjustment
  5920. is required. */
  5921. if (adjusted_bpaddr != bpaddr)
  5922. breakpoint_adjustment_warning (bpaddr, adjusted_bpaddr, 0, 0);
  5923. return adjusted_bpaddr;
  5924. }
  5925. }
  5926. static bp_loc_type
  5927. bp_location_from_bp_type (bptype type)
  5928. {
  5929. switch (type)
  5930. {
  5931. case bp_breakpoint:
  5932. case bp_single_step:
  5933. case bp_until:
  5934. case bp_finish:
  5935. case bp_longjmp:
  5936. case bp_longjmp_resume:
  5937. case bp_longjmp_call_dummy:
  5938. case bp_exception:
  5939. case bp_exception_resume:
  5940. case bp_step_resume:
  5941. case bp_hp_step_resume:
  5942. case bp_watchpoint_scope:
  5943. case bp_call_dummy:
  5944. case bp_std_terminate:
  5945. case bp_shlib_event:
  5946. case bp_thread_event:
  5947. case bp_overlay_event:
  5948. case bp_jit_event:
  5949. case bp_longjmp_master:
  5950. case bp_std_terminate_master:
  5951. case bp_exception_master:
  5952. case bp_gnu_ifunc_resolver:
  5953. case bp_gnu_ifunc_resolver_return:
  5954. case bp_dprintf:
  5955. return bp_loc_software_breakpoint;
  5956. case bp_hardware_breakpoint:
  5957. return bp_loc_hardware_breakpoint;
  5958. case bp_hardware_watchpoint:
  5959. case bp_read_watchpoint:
  5960. case bp_access_watchpoint:
  5961. return bp_loc_hardware_watchpoint;
  5962. case bp_watchpoint:
  5963. case bp_catchpoint:
  5964. case bp_tracepoint:
  5965. case bp_fast_tracepoint:
  5966. case bp_static_tracepoint:
  5967. return bp_loc_other;
  5968. default:
  5969. internal_error (__FILE__, __LINE__, _("unknown breakpoint type"));
  5970. }
  5971. }
  5972. bp_location::bp_location (breakpoint *owner, bp_loc_type type)
  5973. {
  5974. this->owner = owner;
  5975. this->cond_bytecode = NULL;
  5976. this->shlib_disabled = 0;
  5977. this->enabled = 1;
  5978. this->disabled_by_cond = false;
  5979. this->loc_type = type;
  5980. if (this->loc_type == bp_loc_software_breakpoint
  5981. || this->loc_type == bp_loc_hardware_breakpoint)
  5982. mark_breakpoint_location_modified (this);
  5983. incref ();
  5984. }
  5985. bp_location::bp_location (breakpoint *owner)
  5986. : bp_location::bp_location (owner,
  5987. bp_location_from_bp_type (owner->type))
  5988. {
  5989. }
  5990. /* Allocate a struct bp_location. */
  5991. static struct bp_location *
  5992. allocate_bp_location (struct breakpoint *bpt)
  5993. {
  5994. return bpt->ops->allocate_location (bpt);
  5995. }
  5996. /* Decrement reference count. If the reference count reaches 0,
  5997. destroy the bp_location. Sets *BLP to NULL. */
  5998. static void
  5999. decref_bp_location (struct bp_location **blp)
  6000. {
  6001. bp_location_ref_policy::decref (*blp);
  6002. *blp = NULL;
  6003. }
  6004. /* Add breakpoint B at the end of the global breakpoint chain. */
  6005. static breakpoint *
  6006. add_to_breakpoint_chain (std::unique_ptr<breakpoint> &&b)
  6007. {
  6008. struct breakpoint *b1;
  6009. struct breakpoint *result = b.get ();
  6010. /* Add this breakpoint to the end of the chain so that a list of
  6011. breakpoints will come out in order of increasing numbers. */
  6012. b1 = breakpoint_chain;
  6013. if (b1 == 0)
  6014. breakpoint_chain = b.release ();
  6015. else
  6016. {
  6017. while (b1->next)
  6018. b1 = b1->next;
  6019. b1->next = b.release ();
  6020. }
  6021. return result;
  6022. }
  6023. /* Initializes breakpoint B with type BPTYPE and no locations yet. */
  6024. static void
  6025. init_raw_breakpoint_without_location (struct breakpoint *b,
  6026. struct gdbarch *gdbarch,
  6027. enum bptype bptype,
  6028. const struct breakpoint_ops *ops)
  6029. {
  6030. gdb_assert (ops != NULL);
  6031. b->ops = ops;
  6032. b->type = bptype;
  6033. b->gdbarch = gdbarch;
  6034. b->language = current_language->la_language;
  6035. b->input_radix = input_radix;
  6036. b->related_breakpoint = b;
  6037. }
  6038. /* Helper to set_raw_breakpoint below. Creates a breakpoint
  6039. that has type BPTYPE and has no locations as yet. */
  6040. static struct breakpoint *
  6041. set_raw_breakpoint_without_location (struct gdbarch *gdbarch,
  6042. enum bptype bptype,
  6043. const struct breakpoint_ops *ops)
  6044. {
  6045. std::unique_ptr<breakpoint> b = new_breakpoint_from_type (bptype);
  6046. init_raw_breakpoint_without_location (b.get (), gdbarch, bptype, ops);
  6047. return add_to_breakpoint_chain (std::move (b));
  6048. }
  6049. /* Initialize loc->function_name. */
  6050. static void
  6051. set_breakpoint_location_function (struct bp_location *loc)
  6052. {
  6053. gdb_assert (loc->owner != NULL);
  6054. if (loc->owner->type == bp_breakpoint
  6055. || loc->owner->type == bp_hardware_breakpoint
  6056. || is_tracepoint (loc->owner))
  6057. {
  6058. const char *function_name;
  6059. if (loc->msymbol != NULL
  6060. && (MSYMBOL_TYPE (loc->msymbol) == mst_text_gnu_ifunc
  6061. || MSYMBOL_TYPE (loc->msymbol) == mst_data_gnu_ifunc))
  6062. {
  6063. struct breakpoint *b = loc->owner;
  6064. function_name = loc->msymbol->linkage_name ();
  6065. if (b->type == bp_breakpoint && b->loc == loc
  6066. && loc->next == NULL && b->related_breakpoint == b)
  6067. {
  6068. /* Create only the whole new breakpoint of this type but do not
  6069. mess more complicated breakpoints with multiple locations. */
  6070. b->type = bp_gnu_ifunc_resolver;
  6071. /* Remember the resolver's address for use by the return
  6072. breakpoint. */
  6073. loc->related_address = loc->address;
  6074. }
  6075. }
  6076. else
  6077. find_pc_partial_function (loc->address, &function_name, NULL, NULL);
  6078. if (function_name)
  6079. loc->function_name = make_unique_xstrdup (function_name);
  6080. }
  6081. }
  6082. /* Attempt to determine architecture of location identified by SAL. */
  6083. struct gdbarch *
  6084. get_sal_arch (struct symtab_and_line sal)
  6085. {
  6086. if (sal.section)
  6087. return sal.section->objfile->arch ();
  6088. if (sal.symtab)
  6089. return sal.symtab->compunit ()->objfile ()->arch ();
  6090. return NULL;
  6091. }
  6092. /* Low level routine for partially initializing a breakpoint of type
  6093. BPTYPE. The newly created breakpoint's address, section, source
  6094. file name, and line number are provided by SAL.
  6095. It is expected that the caller will complete the initialization of
  6096. the newly created breakpoint struct as well as output any status
  6097. information regarding the creation of a new breakpoint. */
  6098. static void
  6099. init_raw_breakpoint (struct breakpoint *b, struct gdbarch *gdbarch,
  6100. struct symtab_and_line sal, enum bptype bptype,
  6101. const struct breakpoint_ops *ops)
  6102. {
  6103. init_raw_breakpoint_without_location (b, gdbarch, bptype, ops);
  6104. add_location_to_breakpoint (b, &sal);
  6105. if (bptype != bp_catchpoint)
  6106. gdb_assert (sal.pspace != NULL);
  6107. /* Store the program space that was used to set the breakpoint,
  6108. except for ordinary breakpoints, which are independent of the
  6109. program space. */
  6110. if (bptype != bp_breakpoint && bptype != bp_hardware_breakpoint)
  6111. b->pspace = sal.pspace;
  6112. }
  6113. /* set_raw_breakpoint is a low level routine for allocating and
  6114. partially initializing a breakpoint of type BPTYPE. The newly
  6115. created breakpoint's address, section, source file name, and line
  6116. number are provided by SAL. The newly created and partially
  6117. initialized breakpoint is added to the breakpoint chain and
  6118. is also returned as the value of this function.
  6119. It is expected that the caller will complete the initialization of
  6120. the newly created breakpoint struct as well as output any status
  6121. information regarding the creation of a new breakpoint. In
  6122. particular, set_raw_breakpoint does NOT set the breakpoint
  6123. number! Care should be taken to not allow an error to occur
  6124. prior to completing the initialization of the breakpoint. If this
  6125. should happen, a bogus breakpoint will be left on the chain. */
  6126. static struct breakpoint *
  6127. set_raw_breakpoint (struct gdbarch *gdbarch,
  6128. struct symtab_and_line sal, enum bptype bptype,
  6129. const struct breakpoint_ops *ops)
  6130. {
  6131. std::unique_ptr<breakpoint> b = new_breakpoint_from_type (bptype);
  6132. init_raw_breakpoint (b.get (), gdbarch, sal, bptype, ops);
  6133. return add_to_breakpoint_chain (std::move (b));
  6134. }
  6135. /* Call this routine when stepping and nexting to enable a breakpoint
  6136. if we do a longjmp() or 'throw' in TP. FRAME is the frame which
  6137. initiated the operation. */
  6138. void
  6139. set_longjmp_breakpoint (struct thread_info *tp, struct frame_id frame)
  6140. {
  6141. int thread = tp->global_num;
  6142. /* To avoid having to rescan all objfile symbols at every step,
  6143. we maintain a list of continually-inserted but always disabled
  6144. longjmp "master" breakpoints. Here, we simply create momentary
  6145. clones of those and enable them for the requested thread. */
  6146. for (breakpoint *b : all_breakpoints_safe ())
  6147. if (b->pspace == current_program_space
  6148. && (b->type == bp_longjmp_master
  6149. || b->type == bp_exception_master))
  6150. {
  6151. enum bptype type = b->type == bp_longjmp_master ? bp_longjmp : bp_exception;
  6152. struct breakpoint *clone;
  6153. /* longjmp_breakpoint_ops ensures INITIATING_FRAME is cleared again
  6154. after their removal. */
  6155. clone = momentary_breakpoint_from_master (b, type,
  6156. &momentary_breakpoint_ops, 1);
  6157. clone->thread = thread;
  6158. }
  6159. tp->initiating_frame = frame;
  6160. }
  6161. /* Delete all longjmp breakpoints from THREAD. */
  6162. void
  6163. delete_longjmp_breakpoint (int thread)
  6164. {
  6165. for (breakpoint *b : all_breakpoints_safe ())
  6166. if (b->type == bp_longjmp || b->type == bp_exception)
  6167. {
  6168. if (b->thread == thread)
  6169. delete_breakpoint (b);
  6170. }
  6171. }
  6172. void
  6173. delete_longjmp_breakpoint_at_next_stop (int thread)
  6174. {
  6175. for (breakpoint *b : all_breakpoints_safe ())
  6176. if (b->type == bp_longjmp || b->type == bp_exception)
  6177. {
  6178. if (b->thread == thread)
  6179. b->disposition = disp_del_at_next_stop;
  6180. }
  6181. }
  6182. /* Place breakpoints of type bp_longjmp_call_dummy to catch longjmp for
  6183. INFERIOR_PTID thread. Chain them all by RELATED_BREAKPOINT and return
  6184. pointer to any of them. Return NULL if this system cannot place longjmp
  6185. breakpoints. */
  6186. struct breakpoint *
  6187. set_longjmp_breakpoint_for_call_dummy (void)
  6188. {
  6189. breakpoint *retval = nullptr;
  6190. for (breakpoint *b : all_breakpoints ())
  6191. if (b->pspace == current_program_space && b->type == bp_longjmp_master)
  6192. {
  6193. struct breakpoint *new_b;
  6194. new_b = momentary_breakpoint_from_master (b, bp_longjmp_call_dummy,
  6195. &momentary_breakpoint_ops,
  6196. 1);
  6197. new_b->thread = inferior_thread ()->global_num;
  6198. /* Link NEW_B into the chain of RETVAL breakpoints. */
  6199. gdb_assert (new_b->related_breakpoint == new_b);
  6200. if (retval == NULL)
  6201. retval = new_b;
  6202. new_b->related_breakpoint = retval;
  6203. while (retval->related_breakpoint != new_b->related_breakpoint)
  6204. retval = retval->related_breakpoint;
  6205. retval->related_breakpoint = new_b;
  6206. }
  6207. return retval;
  6208. }
  6209. /* Verify all existing dummy frames and their associated breakpoints for
  6210. TP. Remove those which can no longer be found in the current frame
  6211. stack.
  6212. If the unwind fails then there is not sufficient information to discard
  6213. dummy frames. In this case, elide the clean up and the dummy frames will
  6214. be cleaned up next time this function is called from a location where
  6215. unwinding is possible. */
  6216. void
  6217. check_longjmp_breakpoint_for_call_dummy (struct thread_info *tp)
  6218. {
  6219. struct breakpoint *b, *b_tmp;
  6220. ALL_BREAKPOINTS_SAFE (b, b_tmp)
  6221. if (b->type == bp_longjmp_call_dummy && b->thread == tp->global_num)
  6222. {
  6223. struct breakpoint *dummy_b = b->related_breakpoint;
  6224. /* Find the bp_call_dummy breakpoint in the list of breakpoints
  6225. chained off b->related_breakpoint. */
  6226. while (dummy_b != b && dummy_b->type != bp_call_dummy)
  6227. dummy_b = dummy_b->related_breakpoint;
  6228. /* If there was no bp_call_dummy breakpoint then there's nothing
  6229. more to do. Or, if the dummy frame associated with the
  6230. bp_call_dummy is still on the stack then we need to leave this
  6231. bp_call_dummy in place. */
  6232. if (dummy_b->type != bp_call_dummy
  6233. || frame_find_by_id (dummy_b->frame_id) != NULL)
  6234. continue;
  6235. /* We didn't find the dummy frame on the stack, this could be
  6236. because we have longjmp'd to a stack frame that is previous to
  6237. the dummy frame, or it could be because the stack unwind is
  6238. broken at some point between the longjmp frame and the dummy
  6239. frame.
  6240. Next we figure out why the stack unwind stopped. If it looks
  6241. like the unwind is complete then we assume the dummy frame has
  6242. been jumped over, however, if the unwind stopped for an
  6243. unexpected reason then we assume the stack unwind is currently
  6244. broken, and that we will (eventually) return to the dummy
  6245. frame.
  6246. It might be tempting to consider using frame_id_inner here, but
  6247. that is not safe. There is no guarantee that the stack frames
  6248. we are looking at here are even on the same stack as the
  6249. original dummy frame, hence frame_id_inner can't be used. See
  6250. the comments on frame_id_inner for more details. */
  6251. bool unwind_finished_unexpectedly = false;
  6252. for (struct frame_info *fi = get_current_frame (); fi != nullptr; )
  6253. {
  6254. struct frame_info *prev = get_prev_frame (fi);
  6255. if (prev == nullptr)
  6256. {
  6257. /* FI is the last stack frame. Why did this frame not
  6258. unwind further? */
  6259. auto stop_reason = get_frame_unwind_stop_reason (fi);
  6260. if (stop_reason != UNWIND_NO_REASON
  6261. && stop_reason != UNWIND_OUTERMOST)
  6262. unwind_finished_unexpectedly = true;
  6263. }
  6264. fi = prev;
  6265. }
  6266. if (unwind_finished_unexpectedly)
  6267. continue;
  6268. dummy_frame_discard (dummy_b->frame_id, tp);
  6269. while (b->related_breakpoint != b)
  6270. {
  6271. if (b_tmp == b->related_breakpoint)
  6272. b_tmp = b->related_breakpoint->next;
  6273. delete_breakpoint (b->related_breakpoint);
  6274. }
  6275. delete_breakpoint (b);
  6276. }
  6277. }
  6278. void
  6279. enable_overlay_breakpoints (void)
  6280. {
  6281. for (breakpoint *b : all_breakpoints ())
  6282. if (b->type == bp_overlay_event)
  6283. {
  6284. b->enable_state = bp_enabled;
  6285. update_global_location_list (UGLL_MAY_INSERT);
  6286. overlay_events_enabled = 1;
  6287. }
  6288. }
  6289. void
  6290. disable_overlay_breakpoints (void)
  6291. {
  6292. for (breakpoint *b : all_breakpoints ())
  6293. if (b->type == bp_overlay_event)
  6294. {
  6295. b->enable_state = bp_disabled;
  6296. update_global_location_list (UGLL_DONT_INSERT);
  6297. overlay_events_enabled = 0;
  6298. }
  6299. }
  6300. /* Set an active std::terminate breakpoint for each std::terminate
  6301. master breakpoint. */
  6302. void
  6303. set_std_terminate_breakpoint (void)
  6304. {
  6305. for (breakpoint *b : all_breakpoints_safe ())
  6306. if (b->pspace == current_program_space
  6307. && b->type == bp_std_terminate_master)
  6308. {
  6309. momentary_breakpoint_from_master (b, bp_std_terminate,
  6310. &momentary_breakpoint_ops, 1);
  6311. }
  6312. }
  6313. /* Delete all the std::terminate breakpoints. */
  6314. void
  6315. delete_std_terminate_breakpoint (void)
  6316. {
  6317. for (breakpoint *b : all_breakpoints_safe ())
  6318. if (b->type == bp_std_terminate)
  6319. delete_breakpoint (b);
  6320. }
  6321. struct breakpoint *
  6322. create_thread_event_breakpoint (struct gdbarch *gdbarch, CORE_ADDR address)
  6323. {
  6324. struct breakpoint *b;
  6325. b = create_internal_breakpoint (gdbarch, address, bp_thread_event,
  6326. &internal_breakpoint_ops);
  6327. b->enable_state = bp_enabled;
  6328. /* location has to be used or breakpoint_re_set will delete me. */
  6329. b->location = new_address_location (b->loc->address, NULL, 0);
  6330. update_global_location_list_nothrow (UGLL_MAY_INSERT);
  6331. return b;
  6332. }
  6333. struct lang_and_radix
  6334. {
  6335. enum language lang;
  6336. int radix;
  6337. };
  6338. /* Create a breakpoint for JIT code registration and unregistration. */
  6339. struct breakpoint *
  6340. create_jit_event_breakpoint (struct gdbarch *gdbarch, CORE_ADDR address)
  6341. {
  6342. return create_internal_breakpoint (gdbarch, address, bp_jit_event,
  6343. &internal_breakpoint_ops);
  6344. }
  6345. /* Remove JIT code registration and unregistration breakpoint(s). */
  6346. void
  6347. remove_jit_event_breakpoints (void)
  6348. {
  6349. for (breakpoint *b : all_breakpoints_safe ())
  6350. if (b->type == bp_jit_event
  6351. && b->loc->pspace == current_program_space)
  6352. delete_breakpoint (b);
  6353. }
  6354. void
  6355. remove_solib_event_breakpoints (void)
  6356. {
  6357. for (breakpoint *b : all_breakpoints_safe ())
  6358. if (b->type == bp_shlib_event
  6359. && b->loc->pspace == current_program_space)
  6360. delete_breakpoint (b);
  6361. }
  6362. /* See breakpoint.h. */
  6363. void
  6364. remove_solib_event_breakpoints_at_next_stop (void)
  6365. {
  6366. for (breakpoint *b : all_breakpoints_safe ())
  6367. if (b->type == bp_shlib_event
  6368. && b->loc->pspace == current_program_space)
  6369. b->disposition = disp_del_at_next_stop;
  6370. }
  6371. /* Helper for create_solib_event_breakpoint /
  6372. create_and_insert_solib_event_breakpoint. Allows specifying which
  6373. INSERT_MODE to pass through to update_global_location_list. */
  6374. static struct breakpoint *
  6375. create_solib_event_breakpoint_1 (struct gdbarch *gdbarch, CORE_ADDR address,
  6376. enum ugll_insert_mode insert_mode)
  6377. {
  6378. struct breakpoint *b;
  6379. b = create_internal_breakpoint (gdbarch, address, bp_shlib_event,
  6380. &internal_breakpoint_ops);
  6381. update_global_location_list_nothrow (insert_mode);
  6382. return b;
  6383. }
  6384. struct breakpoint *
  6385. create_solib_event_breakpoint (struct gdbarch *gdbarch, CORE_ADDR address)
  6386. {
  6387. return create_solib_event_breakpoint_1 (gdbarch, address, UGLL_MAY_INSERT);
  6388. }
  6389. /* See breakpoint.h. */
  6390. struct breakpoint *
  6391. create_and_insert_solib_event_breakpoint (struct gdbarch *gdbarch, CORE_ADDR address)
  6392. {
  6393. struct breakpoint *b;
  6394. /* Explicitly tell update_global_location_list to insert
  6395. locations. */
  6396. b = create_solib_event_breakpoint_1 (gdbarch, address, UGLL_INSERT);
  6397. if (!b->loc->inserted)
  6398. {
  6399. delete_breakpoint (b);
  6400. return NULL;
  6401. }
  6402. return b;
  6403. }
  6404. /* Disable any breakpoints that are on code in shared libraries. Only
  6405. apply to enabled breakpoints, disabled ones can just stay disabled. */
  6406. void
  6407. disable_breakpoints_in_shlibs (void)
  6408. {
  6409. for (bp_location *loc : all_bp_locations ())
  6410. {
  6411. /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always non-NULL. */
  6412. struct breakpoint *b = loc->owner;
  6413. /* We apply the check to all breakpoints, including disabled for
  6414. those with loc->duplicate set. This is so that when breakpoint
  6415. becomes enabled, or the duplicate is removed, gdb will try to
  6416. insert all breakpoints. If we don't set shlib_disabled here,
  6417. we'll try to insert those breakpoints and fail. */
  6418. if (((b->type == bp_breakpoint)
  6419. || (b->type == bp_jit_event)
  6420. || (b->type == bp_hardware_breakpoint)
  6421. || (is_tracepoint (b)))
  6422. && loc->pspace == current_program_space
  6423. && !loc->shlib_disabled
  6424. && solib_name_from_address (loc->pspace, loc->address)
  6425. )
  6426. {
  6427. loc->shlib_disabled = 1;
  6428. }
  6429. }
  6430. }
  6431. /* Disable any breakpoints and tracepoints that are in SOLIB upon
  6432. notification of unloaded_shlib. Only apply to enabled breakpoints,
  6433. disabled ones can just stay disabled. */
  6434. static void
  6435. disable_breakpoints_in_unloaded_shlib (struct so_list *solib)
  6436. {
  6437. int disabled_shlib_breaks = 0;
  6438. for (bp_location *loc : all_bp_locations ())
  6439. {
  6440. /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always non-NULL. */
  6441. struct breakpoint *b = loc->owner;
  6442. if (solib->pspace == loc->pspace
  6443. && !loc->shlib_disabled
  6444. && (((b->type == bp_breakpoint
  6445. || b->type == bp_jit_event
  6446. || b->type == bp_hardware_breakpoint)
  6447. && (loc->loc_type == bp_loc_hardware_breakpoint
  6448. || loc->loc_type == bp_loc_software_breakpoint))
  6449. || is_tracepoint (b))
  6450. && solib_contains_address_p (solib, loc->address))
  6451. {
  6452. loc->shlib_disabled = 1;
  6453. /* At this point, we cannot rely on remove_breakpoint
  6454. succeeding so we must mark the breakpoint as not inserted
  6455. to prevent future errors occurring in remove_breakpoints. */
  6456. loc->inserted = 0;
  6457. /* This may cause duplicate notifications for the same breakpoint. */
  6458. gdb::observers::breakpoint_modified.notify (b);
  6459. if (!disabled_shlib_breaks)
  6460. {
  6461. target_terminal::ours_for_output ();
  6462. warning (_("Temporarily disabling breakpoints "
  6463. "for unloaded shared library \"%s\""),
  6464. solib->so_name);
  6465. }
  6466. disabled_shlib_breaks = 1;
  6467. }
  6468. }
  6469. }
  6470. /* Disable any breakpoints and tracepoints in OBJFILE upon
  6471. notification of free_objfile. Only apply to enabled breakpoints,
  6472. disabled ones can just stay disabled. */
  6473. static void
  6474. disable_breakpoints_in_freed_objfile (struct objfile *objfile)
  6475. {
  6476. if (objfile == NULL)
  6477. return;
  6478. /* OBJF_SHARED|OBJF_USERLOADED objfiles are dynamic modules manually
  6479. managed by the user with add-symbol-file/remove-symbol-file.
  6480. Similarly to how breakpoints in shared libraries are handled in
  6481. response to "nosharedlibrary", mark breakpoints in such modules
  6482. shlib_disabled so they end up uninserted on the next global
  6483. location list update. Shared libraries not loaded by the user
  6484. aren't handled here -- they're already handled in
  6485. disable_breakpoints_in_unloaded_shlib, called by solib.c's
  6486. solib_unloaded observer. We skip objfiles that are not
  6487. OBJF_SHARED as those aren't considered dynamic objects (e.g. the
  6488. main objfile). */
  6489. if ((objfile->flags & OBJF_SHARED) == 0
  6490. || (objfile->flags & OBJF_USERLOADED) == 0)
  6491. return;
  6492. for (breakpoint *b : all_breakpoints ())
  6493. {
  6494. int bp_modified = 0;
  6495. if (!is_breakpoint (b) && !is_tracepoint (b))
  6496. continue;
  6497. for (bp_location *loc : b->locations ())
  6498. {
  6499. CORE_ADDR loc_addr = loc->address;
  6500. if (loc->loc_type != bp_loc_hardware_breakpoint
  6501. && loc->loc_type != bp_loc_software_breakpoint)
  6502. continue;
  6503. if (loc->shlib_disabled != 0)
  6504. continue;
  6505. if (objfile->pspace != loc->pspace)
  6506. continue;
  6507. if (loc->loc_type != bp_loc_hardware_breakpoint
  6508. && loc->loc_type != bp_loc_software_breakpoint)
  6509. continue;
  6510. if (is_addr_in_objfile (loc_addr, objfile))
  6511. {
  6512. loc->shlib_disabled = 1;
  6513. /* At this point, we don't know whether the object was
  6514. unmapped from the inferior or not, so leave the
  6515. inserted flag alone. We'll handle failure to
  6516. uninsert quietly, in case the object was indeed
  6517. unmapped. */
  6518. mark_breakpoint_location_modified (loc);
  6519. bp_modified = 1;
  6520. }
  6521. }
  6522. if (bp_modified)
  6523. gdb::observers::breakpoint_modified.notify (b);
  6524. }
  6525. }
  6526. /* An instance of this type is used to represent an solib catchpoint.
  6527. A breakpoint is really of this type iff its ops pointer points to
  6528. CATCH_SOLIB_BREAKPOINT_OPS. */
  6529. struct solib_catchpoint : public breakpoint
  6530. {
  6531. /* True for "catch load", false for "catch unload". */
  6532. bool is_load;
  6533. /* Regular expression to match, if any. COMPILED is only valid when
  6534. REGEX is non-NULL. */
  6535. gdb::unique_xmalloc_ptr<char> regex;
  6536. std::unique_ptr<compiled_regex> compiled;
  6537. };
  6538. static int
  6539. insert_catch_solib (struct bp_location *ignore)
  6540. {
  6541. return 0;
  6542. }
  6543. static int
  6544. remove_catch_solib (struct bp_location *ignore, enum remove_bp_reason reason)
  6545. {
  6546. return 0;
  6547. }
  6548. static int
  6549. breakpoint_hit_catch_solib (const struct bp_location *bl,
  6550. const address_space *aspace,
  6551. CORE_ADDR bp_addr,
  6552. const target_waitstatus &ws)
  6553. {
  6554. struct solib_catchpoint *self = (struct solib_catchpoint *) bl->owner;
  6555. if (ws.kind () == TARGET_WAITKIND_LOADED)
  6556. return 1;
  6557. for (breakpoint *other : all_breakpoints ())
  6558. {
  6559. if (other == bl->owner)
  6560. continue;
  6561. if (other->type != bp_shlib_event)
  6562. continue;
  6563. if (self->pspace != NULL && other->pspace != self->pspace)
  6564. continue;
  6565. for (bp_location *other_bl : other->locations ())
  6566. {
  6567. if (other->ops->breakpoint_hit (other_bl, aspace, bp_addr, ws))
  6568. return 1;
  6569. }
  6570. }
  6571. return 0;
  6572. }
  6573. static void
  6574. check_status_catch_solib (struct bpstat *bs)
  6575. {
  6576. struct solib_catchpoint *self
  6577. = (struct solib_catchpoint *) bs->breakpoint_at;
  6578. if (self->is_load)
  6579. {
  6580. for (so_list *iter : current_program_space->added_solibs)
  6581. {
  6582. if (!self->regex
  6583. || self->compiled->exec (iter->so_name, 0, NULL, 0) == 0)
  6584. return;
  6585. }
  6586. }
  6587. else
  6588. {
  6589. for (const std::string &iter : current_program_space->deleted_solibs)
  6590. {
  6591. if (!self->regex
  6592. || self->compiled->exec (iter.c_str (), 0, NULL, 0) == 0)
  6593. return;
  6594. }
  6595. }
  6596. bs->stop = 0;
  6597. bs->print_it = print_it_noop;
  6598. }
  6599. static enum print_stop_action
  6600. print_it_catch_solib (bpstat *bs)
  6601. {
  6602. struct breakpoint *b = bs->breakpoint_at;
  6603. struct ui_out *uiout = current_uiout;
  6604. annotate_catchpoint (b->number);
  6605. maybe_print_thread_hit_breakpoint (uiout);
  6606. if (b->disposition == disp_del)
  6607. uiout->text ("Temporary catchpoint ");
  6608. else
  6609. uiout->text ("Catchpoint ");
  6610. uiout->field_signed ("bkptno", b->number);
  6611. uiout->text ("\n");
  6612. if (uiout->is_mi_like_p ())
  6613. uiout->field_string ("disp", bpdisp_text (b->disposition));
  6614. print_solib_event (1);
  6615. return PRINT_SRC_AND_LOC;
  6616. }
  6617. static void
  6618. print_one_catch_solib (struct breakpoint *b, struct bp_location **locs)
  6619. {
  6620. struct solib_catchpoint *self = (struct solib_catchpoint *) b;
  6621. struct value_print_options opts;
  6622. struct ui_out *uiout = current_uiout;
  6623. get_user_print_options (&opts);
  6624. /* Field 4, the address, is omitted (which makes the columns not
  6625. line up too nicely with the headers, but the effect is relatively
  6626. readable). */
  6627. if (opts.addressprint)
  6628. {
  6629. annotate_field (4);
  6630. uiout->field_skip ("addr");
  6631. }
  6632. std::string msg;
  6633. annotate_field (5);
  6634. if (self->is_load)
  6635. {
  6636. if (self->regex)
  6637. msg = string_printf (_("load of library matching %s"),
  6638. self->regex.get ());
  6639. else
  6640. msg = _("load of library");
  6641. }
  6642. else
  6643. {
  6644. if (self->regex)
  6645. msg = string_printf (_("unload of library matching %s"),
  6646. self->regex.get ());
  6647. else
  6648. msg = _("unload of library");
  6649. }
  6650. uiout->field_string ("what", msg);
  6651. if (uiout->is_mi_like_p ())
  6652. uiout->field_string ("catch-type", self->is_load ? "load" : "unload");
  6653. }
  6654. static void
  6655. print_mention_catch_solib (struct breakpoint *b)
  6656. {
  6657. struct solib_catchpoint *self = (struct solib_catchpoint *) b;
  6658. gdb_printf (_("Catchpoint %d (%s)"), b->number,
  6659. self->is_load ? "load" : "unload");
  6660. }
  6661. static void
  6662. print_recreate_catch_solib (struct breakpoint *b, struct ui_file *fp)
  6663. {
  6664. struct solib_catchpoint *self = (struct solib_catchpoint *) b;
  6665. gdb_printf (fp, "%s %s",
  6666. b->disposition == disp_del ? "tcatch" : "catch",
  6667. self->is_load ? "load" : "unload");
  6668. if (self->regex)
  6669. gdb_printf (fp, " %s", self->regex.get ());
  6670. gdb_printf (fp, "\n");
  6671. }
  6672. static struct breakpoint_ops catch_solib_breakpoint_ops;
  6673. /* See breakpoint.h. */
  6674. void
  6675. add_solib_catchpoint (const char *arg, bool is_load, bool is_temp, bool enabled)
  6676. {
  6677. struct gdbarch *gdbarch = get_current_arch ();
  6678. if (!arg)
  6679. arg = "";
  6680. arg = skip_spaces (arg);
  6681. std::unique_ptr<solib_catchpoint> c (new solib_catchpoint ());
  6682. if (*arg != '\0')
  6683. {
  6684. c->compiled.reset (new compiled_regex (arg, REG_NOSUB,
  6685. _("Invalid regexp")));
  6686. c->regex = make_unique_xstrdup (arg);
  6687. }
  6688. c->is_load = is_load;
  6689. init_catchpoint (c.get (), gdbarch, is_temp, NULL,
  6690. &catch_solib_breakpoint_ops);
  6691. c->enable_state = enabled ? bp_enabled : bp_disabled;
  6692. install_breakpoint (0, std::move (c), 1);
  6693. }
  6694. /* A helper function that does all the work for "catch load" and
  6695. "catch unload". */
  6696. static void
  6697. catch_load_or_unload (const char *arg, int from_tty, int is_load,
  6698. struct cmd_list_element *command)
  6699. {
  6700. const int enabled = 1;
  6701. bool temp = command->context () == CATCH_TEMPORARY;
  6702. add_solib_catchpoint (arg, is_load, temp, enabled);
  6703. }
  6704. static void
  6705. catch_load_command_1 (const char *arg, int from_tty,
  6706. struct cmd_list_element *command)
  6707. {
  6708. catch_load_or_unload (arg, from_tty, 1, command);
  6709. }
  6710. static void
  6711. catch_unload_command_1 (const char *arg, int from_tty,
  6712. struct cmd_list_element *command)
  6713. {
  6714. catch_load_or_unload (arg, from_tty, 0, command);
  6715. }
  6716. /* See breakpoint.h. */
  6717. void
  6718. init_catchpoint (struct breakpoint *b,
  6719. struct gdbarch *gdbarch, bool temp,
  6720. const char *cond_string,
  6721. const struct breakpoint_ops *ops)
  6722. {
  6723. symtab_and_line sal;
  6724. sal.pspace = current_program_space;
  6725. init_raw_breakpoint (b, gdbarch, sal, bp_catchpoint, ops);
  6726. if (cond_string == nullptr)
  6727. b->cond_string.reset ();
  6728. else
  6729. b->cond_string = make_unique_xstrdup (cond_string);
  6730. b->disposition = temp ? disp_del : disp_donttouch;
  6731. }
  6732. void
  6733. install_breakpoint (int internal, std::unique_ptr<breakpoint> &&arg, int update_gll)
  6734. {
  6735. breakpoint *b = add_to_breakpoint_chain (std::move (arg));
  6736. set_breakpoint_number (internal, b);
  6737. if (is_tracepoint (b))
  6738. set_tracepoint_count (breakpoint_count);
  6739. if (!internal)
  6740. mention (b);
  6741. gdb::observers::breakpoint_created.notify (b);
  6742. if (update_gll)
  6743. update_global_location_list (UGLL_MAY_INSERT);
  6744. }
  6745. static int
  6746. hw_breakpoint_used_count (void)
  6747. {
  6748. int i = 0;
  6749. for (breakpoint *b : all_breakpoints ())
  6750. if (b->type == bp_hardware_breakpoint && breakpoint_enabled (b))
  6751. for (bp_location *bl : b->locations ())
  6752. {
  6753. /* Special types of hardware breakpoints may use more than
  6754. one register. */
  6755. i += b->ops->resources_needed (bl);
  6756. }
  6757. return i;
  6758. }
  6759. /* Returns the resources B would use if it were a hardware
  6760. watchpoint. */
  6761. static int
  6762. hw_watchpoint_use_count (struct breakpoint *b)
  6763. {
  6764. int i = 0;
  6765. if (!breakpoint_enabled (b))
  6766. return 0;
  6767. for (bp_location *bl : b->locations ())
  6768. {
  6769. /* Special types of hardware watchpoints may use more than
  6770. one register. */
  6771. i += b->ops->resources_needed (bl);
  6772. }
  6773. return i;
  6774. }
  6775. /* Returns the sum the used resources of all hardware watchpoints of
  6776. type TYPE in the breakpoints list. Also returns in OTHER_TYPE_USED
  6777. the sum of the used resources of all hardware watchpoints of other
  6778. types _not_ TYPE. */
  6779. static int
  6780. hw_watchpoint_used_count_others (struct breakpoint *except,
  6781. enum bptype type, int *other_type_used)
  6782. {
  6783. int i = 0;
  6784. *other_type_used = 0;
  6785. for (breakpoint *b : all_breakpoints ())
  6786. {
  6787. if (b == except)
  6788. continue;
  6789. if (!breakpoint_enabled (b))
  6790. continue;
  6791. if (b->type == type)
  6792. i += hw_watchpoint_use_count (b);
  6793. else if (is_hardware_watchpoint (b))
  6794. *other_type_used = 1;
  6795. }
  6796. return i;
  6797. }
  6798. void
  6799. disable_watchpoints_before_interactive_call_start (void)
  6800. {
  6801. for (breakpoint *b : all_breakpoints ())
  6802. if (is_watchpoint (b) && breakpoint_enabled (b))
  6803. {
  6804. b->enable_state = bp_call_disabled;
  6805. update_global_location_list (UGLL_DONT_INSERT);
  6806. }
  6807. }
  6808. void
  6809. enable_watchpoints_after_interactive_call_stop (void)
  6810. {
  6811. for (breakpoint *b : all_breakpoints ())
  6812. if (is_watchpoint (b) && b->enable_state == bp_call_disabled)
  6813. {
  6814. b->enable_state = bp_enabled;
  6815. update_global_location_list (UGLL_MAY_INSERT);
  6816. }
  6817. }
  6818. void
  6819. disable_breakpoints_before_startup (void)
  6820. {
  6821. current_program_space->executing_startup = 1;
  6822. update_global_location_list (UGLL_DONT_INSERT);
  6823. }
  6824. void
  6825. enable_breakpoints_after_startup (void)
  6826. {
  6827. current_program_space->executing_startup = 0;
  6828. breakpoint_re_set ();
  6829. }
  6830. /* Create a new single-step breakpoint for thread THREAD, with no
  6831. locations. */
  6832. static struct breakpoint *
  6833. new_single_step_breakpoint (int thread, struct gdbarch *gdbarch)
  6834. {
  6835. std::unique_ptr<breakpoint> b (new breakpoint ());
  6836. init_raw_breakpoint_without_location (b.get (), gdbarch, bp_single_step,
  6837. &momentary_breakpoint_ops);
  6838. b->disposition = disp_donttouch;
  6839. b->frame_id = null_frame_id;
  6840. b->thread = thread;
  6841. gdb_assert (b->thread != 0);
  6842. return add_to_breakpoint_chain (std::move (b));
  6843. }
  6844. /* Set a momentary breakpoint of type TYPE at address specified by
  6845. SAL. If FRAME_ID is valid, the breakpoint is restricted to that
  6846. frame. */
  6847. breakpoint_up
  6848. set_momentary_breakpoint (struct gdbarch *gdbarch, struct symtab_and_line sal,
  6849. struct frame_id frame_id, enum bptype type)
  6850. {
  6851. struct breakpoint *b;
  6852. /* If FRAME_ID is valid, it should be a real frame, not an inlined or
  6853. tail-called one. */
  6854. gdb_assert (!frame_id_artificial_p (frame_id));
  6855. b = set_raw_breakpoint (gdbarch, sal, type, &momentary_breakpoint_ops);
  6856. b->enable_state = bp_enabled;
  6857. b->disposition = disp_donttouch;
  6858. b->frame_id = frame_id;
  6859. b->thread = inferior_thread ()->global_num;
  6860. update_global_location_list_nothrow (UGLL_MAY_INSERT);
  6861. return breakpoint_up (b);
  6862. }
  6863. /* Make a momentary breakpoint based on the master breakpoint ORIG.
  6864. The new breakpoint will have type TYPE, use OPS as its
  6865. breakpoint_ops, and will set enabled to LOC_ENABLED. */
  6866. static struct breakpoint *
  6867. momentary_breakpoint_from_master (struct breakpoint *orig,
  6868. enum bptype type,
  6869. const struct breakpoint_ops *ops,
  6870. int loc_enabled)
  6871. {
  6872. struct breakpoint *copy;
  6873. copy = set_raw_breakpoint_without_location (orig->gdbarch, type, ops);
  6874. copy->loc = allocate_bp_location (copy);
  6875. set_breakpoint_location_function (copy->loc);
  6876. copy->loc->gdbarch = orig->loc->gdbarch;
  6877. copy->loc->requested_address = orig->loc->requested_address;
  6878. copy->loc->address = orig->loc->address;
  6879. copy->loc->section = orig->loc->section;
  6880. copy->loc->pspace = orig->loc->pspace;
  6881. copy->loc->probe = orig->loc->probe;
  6882. copy->loc->line_number = orig->loc->line_number;
  6883. copy->loc->symtab = orig->loc->symtab;
  6884. copy->loc->enabled = loc_enabled;
  6885. copy->frame_id = orig->frame_id;
  6886. copy->thread = orig->thread;
  6887. copy->pspace = orig->pspace;
  6888. copy->enable_state = bp_enabled;
  6889. copy->disposition = disp_donttouch;
  6890. copy->number = internal_breakpoint_number--;
  6891. update_global_location_list_nothrow (UGLL_DONT_INSERT);
  6892. return copy;
  6893. }
  6894. /* Make a deep copy of momentary breakpoint ORIG. Returns NULL if
  6895. ORIG is NULL. */
  6896. struct breakpoint *
  6897. clone_momentary_breakpoint (struct breakpoint *orig)
  6898. {
  6899. /* If there's nothing to clone, then return nothing. */
  6900. if (orig == NULL)
  6901. return NULL;
  6902. return momentary_breakpoint_from_master (orig, orig->type, orig->ops, 0);
  6903. }
  6904. breakpoint_up
  6905. set_momentary_breakpoint_at_pc (struct gdbarch *gdbarch, CORE_ADDR pc,
  6906. enum bptype type)
  6907. {
  6908. struct symtab_and_line sal;
  6909. sal = find_pc_line (pc, 0);
  6910. sal.pc = pc;
  6911. sal.section = find_pc_overlay (pc);
  6912. sal.explicit_pc = 1;
  6913. return set_momentary_breakpoint (gdbarch, sal, null_frame_id, type);
  6914. }
  6915. /* Tell the user we have just set a breakpoint B. */
  6916. static void
  6917. mention (struct breakpoint *b)
  6918. {
  6919. b->ops->print_mention (b);
  6920. current_uiout->text ("\n");
  6921. }
  6922. static bool bp_loc_is_permanent (struct bp_location *loc);
  6923. /* Handle "set breakpoint auto-hw on".
  6924. If the explicitly specified breakpoint type is not hardware
  6925. breakpoint, check the memory map to see whether the breakpoint
  6926. address is in read-only memory.
  6927. - location type is not hardware breakpoint, memory is read-only.
  6928. We change the type of the location to hardware breakpoint.
  6929. - location type is hardware breakpoint, memory is read-write. This
  6930. means we've previously made the location hardware one, but then the
  6931. memory map changed, so we undo.
  6932. */
  6933. static void
  6934. handle_automatic_hardware_breakpoints (bp_location *bl)
  6935. {
  6936. if (automatic_hardware_breakpoints
  6937. && bl->owner->type != bp_hardware_breakpoint
  6938. && (bl->loc_type == bp_loc_software_breakpoint
  6939. || bl->loc_type == bp_loc_hardware_breakpoint))
  6940. {
  6941. /* When breakpoints are removed, remove_breakpoints will use
  6942. location types we've just set here, the only possible problem
  6943. is that memory map has changed during running program, but
  6944. it's not going to work anyway with current gdb. */
  6945. mem_region *mr = lookup_mem_region (bl->address);
  6946. if (mr != nullptr)
  6947. {
  6948. enum bp_loc_type new_type;
  6949. if (mr->attrib.mode != MEM_RW)
  6950. new_type = bp_loc_hardware_breakpoint;
  6951. else
  6952. new_type = bp_loc_software_breakpoint;
  6953. if (new_type != bl->loc_type)
  6954. {
  6955. static bool said = false;
  6956. bl->loc_type = new_type;
  6957. if (!said)
  6958. {
  6959. gdb_printf (_("Note: automatically using "
  6960. "hardware breakpoints for "
  6961. "read-only addresses.\n"));
  6962. said = true;
  6963. }
  6964. }
  6965. }
  6966. }
  6967. }
  6968. static struct bp_location *
  6969. add_location_to_breakpoint (struct breakpoint *b,
  6970. const struct symtab_and_line *sal)
  6971. {
  6972. struct bp_location *loc, **tmp;
  6973. CORE_ADDR adjusted_address;
  6974. struct gdbarch *loc_gdbarch = get_sal_arch (*sal);
  6975. if (loc_gdbarch == NULL)
  6976. loc_gdbarch = b->gdbarch;
  6977. /* Adjust the breakpoint's address prior to allocating a location.
  6978. Once we call allocate_bp_location(), that mostly uninitialized
  6979. location will be placed on the location chain. Adjustment of the
  6980. breakpoint may cause target_read_memory() to be called and we do
  6981. not want its scan of the location chain to find a breakpoint and
  6982. location that's only been partially initialized. */
  6983. adjusted_address = adjust_breakpoint_address (loc_gdbarch,
  6984. sal->pc, b->type);
  6985. /* Sort the locations by their ADDRESS. */
  6986. loc = allocate_bp_location (b);
  6987. for (tmp = &(b->loc); *tmp != NULL && (*tmp)->address <= adjusted_address;
  6988. tmp = &((*tmp)->next))
  6989. ;
  6990. loc->next = *tmp;
  6991. *tmp = loc;
  6992. loc->requested_address = sal->pc;
  6993. loc->address = adjusted_address;
  6994. loc->pspace = sal->pspace;
  6995. loc->probe.prob = sal->prob;
  6996. loc->probe.objfile = sal->objfile;
  6997. gdb_assert (loc->pspace != NULL);
  6998. loc->section = sal->section;
  6999. loc->gdbarch = loc_gdbarch;
  7000. loc->line_number = sal->line;
  7001. loc->symtab = sal->symtab;
  7002. loc->symbol = sal->symbol;
  7003. loc->msymbol = sal->msymbol;
  7004. loc->objfile = sal->objfile;
  7005. set_breakpoint_location_function (loc);
  7006. /* While by definition, permanent breakpoints are already present in the
  7007. code, we don't mark the location as inserted. Normally one would expect
  7008. that GDB could rely on that breakpoint instruction to stop the program,
  7009. thus removing the need to insert its own breakpoint, except that executing
  7010. the breakpoint instruction can kill the target instead of reporting a
  7011. SIGTRAP. E.g., on SPARC, when interrupts are disabled, executing the
  7012. instruction resets the CPU, so QEMU 2.0.0 for SPARC correspondingly dies
  7013. with "Trap 0x02 while interrupts disabled, Error state". Letting the
  7014. breakpoint be inserted normally results in QEMU knowing about the GDB
  7015. breakpoint, and thus trap before the breakpoint instruction is executed.
  7016. (If GDB later needs to continue execution past the permanent breakpoint,
  7017. it manually increments the PC, thus avoiding executing the breakpoint
  7018. instruction.) */
  7019. if (bp_loc_is_permanent (loc))
  7020. loc->permanent = 1;
  7021. return loc;
  7022. }
  7023. /* Return true if LOC is pointing to a permanent breakpoint,
  7024. return false otherwise. */
  7025. static bool
  7026. bp_loc_is_permanent (struct bp_location *loc)
  7027. {
  7028. gdb_assert (loc != NULL);
  7029. /* If we have a non-breakpoint-backed catchpoint or a software
  7030. watchpoint, just return 0. We should not attempt to read from
  7031. the addresses the locations of these breakpoint types point to.
  7032. gdbarch_program_breakpoint_here_p, below, will attempt to read
  7033. memory. */
  7034. if (!bl_address_is_meaningful (loc))
  7035. return false;
  7036. scoped_restore_current_pspace_and_thread restore_pspace_thread;
  7037. switch_to_program_space_and_thread (loc->pspace);
  7038. return gdbarch_program_breakpoint_here_p (loc->gdbarch, loc->address);
  7039. }
  7040. /* Build a command list for the dprintf corresponding to the current
  7041. settings of the dprintf style options. */
  7042. static void
  7043. update_dprintf_command_list (struct breakpoint *b)
  7044. {
  7045. const char *dprintf_args = b->extra_string.get ();
  7046. gdb::unique_xmalloc_ptr<char> printf_line = nullptr;
  7047. if (!dprintf_args)
  7048. return;
  7049. dprintf_args = skip_spaces (dprintf_args);
  7050. /* Allow a comma, as it may have terminated a location, but don't
  7051. insist on it. */
  7052. if (*dprintf_args == ',')
  7053. ++dprintf_args;
  7054. dprintf_args = skip_spaces (dprintf_args);
  7055. if (*dprintf_args != '"')
  7056. error (_("Bad format string, missing '\"'."));
  7057. if (strcmp (dprintf_style, dprintf_style_gdb) == 0)
  7058. printf_line = xstrprintf ("printf %s", dprintf_args);
  7059. else if (strcmp (dprintf_style, dprintf_style_call) == 0)
  7060. {
  7061. if (dprintf_function.empty ())
  7062. error (_("No function supplied for dprintf call"));
  7063. if (!dprintf_channel.empty ())
  7064. printf_line = xstrprintf ("call (void) %s (%s,%s)",
  7065. dprintf_function.c_str (),
  7066. dprintf_channel.c_str (),
  7067. dprintf_args);
  7068. else
  7069. printf_line = xstrprintf ("call (void) %s (%s)",
  7070. dprintf_function.c_str (),
  7071. dprintf_args);
  7072. }
  7073. else if (strcmp (dprintf_style, dprintf_style_agent) == 0)
  7074. {
  7075. if (target_can_run_breakpoint_commands ())
  7076. printf_line = xstrprintf ("agent-printf %s", dprintf_args);
  7077. else
  7078. {
  7079. warning (_("Target cannot run dprintf commands, falling back to GDB printf"));
  7080. printf_line = xstrprintf ("printf %s", dprintf_args);
  7081. }
  7082. }
  7083. else
  7084. internal_error (__FILE__, __LINE__,
  7085. _("Invalid dprintf style."));
  7086. gdb_assert (printf_line != NULL);
  7087. /* Manufacture a printf sequence. */
  7088. struct command_line *printf_cmd_line
  7089. = new struct command_line (simple_control, printf_line.release ());
  7090. breakpoint_set_commands (b, counted_command_line (printf_cmd_line,
  7091. command_lines_deleter ()));
  7092. }
  7093. /* Update all dprintf commands, making their command lists reflect
  7094. current style settings. */
  7095. static void
  7096. update_dprintf_commands (const char *args, int from_tty,
  7097. struct cmd_list_element *c)
  7098. {
  7099. for (breakpoint *b : all_breakpoints ())
  7100. if (b->type == bp_dprintf)
  7101. update_dprintf_command_list (b);
  7102. }
  7103. /* Create a breakpoint with SAL as location. Use LOCATION
  7104. as a description of the location, and COND_STRING
  7105. as condition expression. If LOCATION is NULL then create an
  7106. "address location" from the address in the SAL. */
  7107. static void
  7108. init_breakpoint_sal (struct breakpoint *b, struct gdbarch *gdbarch,
  7109. gdb::array_view<const symtab_and_line> sals,
  7110. event_location_up &&location,
  7111. gdb::unique_xmalloc_ptr<char> filter,
  7112. gdb::unique_xmalloc_ptr<char> cond_string,
  7113. gdb::unique_xmalloc_ptr<char> extra_string,
  7114. enum bptype type, enum bpdisp disposition,
  7115. int thread, int task, int ignore_count,
  7116. const struct breakpoint_ops *ops, int from_tty,
  7117. int enabled, int internal, unsigned flags,
  7118. int display_canonical)
  7119. {
  7120. int i;
  7121. if (type == bp_hardware_breakpoint)
  7122. {
  7123. int target_resources_ok;
  7124. i = hw_breakpoint_used_count ();
  7125. target_resources_ok =
  7126. target_can_use_hardware_watchpoint (bp_hardware_breakpoint,
  7127. i + 1, 0);
  7128. if (target_resources_ok == 0)
  7129. error (_("No hardware breakpoint support in the target."));
  7130. else if (target_resources_ok < 0)
  7131. error (_("Hardware breakpoints used exceeds limit."));
  7132. }
  7133. gdb_assert (!sals.empty ());
  7134. for (const auto &sal : sals)
  7135. {
  7136. struct bp_location *loc;
  7137. if (from_tty)
  7138. {
  7139. struct gdbarch *loc_gdbarch = get_sal_arch (sal);
  7140. if (!loc_gdbarch)
  7141. loc_gdbarch = gdbarch;
  7142. describe_other_breakpoints (loc_gdbarch,
  7143. sal.pspace, sal.pc, sal.section, thread);
  7144. }
  7145. if (&sal == &sals[0])
  7146. {
  7147. init_raw_breakpoint (b, gdbarch, sal, type, ops);
  7148. b->thread = thread;
  7149. b->task = task;
  7150. b->cond_string = std::move (cond_string);
  7151. b->extra_string = std::move (extra_string);
  7152. b->ignore_count = ignore_count;
  7153. b->enable_state = enabled ? bp_enabled : bp_disabled;
  7154. b->disposition = disposition;
  7155. if ((flags & CREATE_BREAKPOINT_FLAGS_INSERTED) != 0)
  7156. b->loc->inserted = 1;
  7157. if (type == bp_static_tracepoint)
  7158. {
  7159. struct tracepoint *t = (struct tracepoint *) b;
  7160. struct static_tracepoint_marker marker;
  7161. if (strace_marker_p (b))
  7162. {
  7163. /* We already know the marker exists, otherwise, we
  7164. wouldn't see a sal for it. */
  7165. const char *p
  7166. = &event_location_to_string (b->location.get ())[3];
  7167. const char *endp;
  7168. p = skip_spaces (p);
  7169. endp = skip_to_space (p);
  7170. t->static_trace_marker_id.assign (p, endp - p);
  7171. gdb_printf (_("Probed static tracepoint "
  7172. "marker \"%s\"\n"),
  7173. t->static_trace_marker_id.c_str ());
  7174. }
  7175. else if (target_static_tracepoint_marker_at (sal.pc, &marker))
  7176. {
  7177. t->static_trace_marker_id = std::move (marker.str_id);
  7178. gdb_printf (_("Probed static tracepoint "
  7179. "marker \"%s\"\n"),
  7180. t->static_trace_marker_id.c_str ());
  7181. }
  7182. else
  7183. warning (_("Couldn't determine the static "
  7184. "tracepoint marker to probe"));
  7185. }
  7186. loc = b->loc;
  7187. }
  7188. else
  7189. {
  7190. loc = add_location_to_breakpoint (b, &sal);
  7191. if ((flags & CREATE_BREAKPOINT_FLAGS_INSERTED) != 0)
  7192. loc->inserted = 1;
  7193. }
  7194. /* Do not set breakpoint locations conditions yet. As locations
  7195. are inserted, they get sorted based on their addresses. Let
  7196. the list stabilize to have reliable location numbers. */
  7197. /* Dynamic printf requires and uses additional arguments on the
  7198. command line, otherwise it's an error. */
  7199. if (type == bp_dprintf)
  7200. {
  7201. if (b->extra_string)
  7202. update_dprintf_command_list (b);
  7203. else
  7204. error (_("Format string required"));
  7205. }
  7206. else if (b->extra_string)
  7207. error (_("Garbage '%s' at end of command"), b->extra_string.get ());
  7208. }
  7209. /* The order of the locations is now stable. Set the location
  7210. condition using the location's number. */
  7211. int loc_num = 1;
  7212. for (bp_location *loc : b->locations ())
  7213. {
  7214. if (b->cond_string != nullptr)
  7215. set_breakpoint_location_condition (b->cond_string.get (), loc,
  7216. b->number, loc_num);
  7217. ++loc_num;
  7218. }
  7219. b->display_canonical = display_canonical;
  7220. if (location != NULL)
  7221. b->location = std::move (location);
  7222. else
  7223. b->location = new_address_location (b->loc->address, NULL, 0);
  7224. b->filter = std::move (filter);
  7225. }
  7226. static void
  7227. create_breakpoint_sal (struct gdbarch *gdbarch,
  7228. gdb::array_view<const symtab_and_line> sals,
  7229. event_location_up &&location,
  7230. gdb::unique_xmalloc_ptr<char> filter,
  7231. gdb::unique_xmalloc_ptr<char> cond_string,
  7232. gdb::unique_xmalloc_ptr<char> extra_string,
  7233. enum bptype type, enum bpdisp disposition,
  7234. int thread, int task, int ignore_count,
  7235. const struct breakpoint_ops *ops, int from_tty,
  7236. int enabled, int internal, unsigned flags,
  7237. int display_canonical)
  7238. {
  7239. std::unique_ptr<breakpoint> b = new_breakpoint_from_type (type);
  7240. init_breakpoint_sal (b.get (), gdbarch,
  7241. sals, std::move (location),
  7242. std::move (filter),
  7243. std::move (cond_string),
  7244. std::move (extra_string),
  7245. type, disposition,
  7246. thread, task, ignore_count,
  7247. ops, from_tty,
  7248. enabled, internal, flags,
  7249. display_canonical);
  7250. install_breakpoint (internal, std::move (b), 0);
  7251. }
  7252. /* Add SALS.nelts breakpoints to the breakpoint table. For each
  7253. SALS.sal[i] breakpoint, include the corresponding ADDR_STRING[i]
  7254. value. COND_STRING, if not NULL, specified the condition to be
  7255. used for all breakpoints. Essentially the only case where
  7256. SALS.nelts is not 1 is when we set a breakpoint on an overloaded
  7257. function. In that case, it's still not possible to specify
  7258. separate conditions for different overloaded functions, so
  7259. we take just a single condition string.
  7260. NOTE: If the function succeeds, the caller is expected to cleanup
  7261. the arrays ADDR_STRING, COND_STRING, and SALS (but not the
  7262. array contents). If the function fails (error() is called), the
  7263. caller is expected to cleanups both the ADDR_STRING, COND_STRING,
  7264. COND and SALS arrays and each of those arrays contents. */
  7265. static void
  7266. create_breakpoints_sal (struct gdbarch *gdbarch,
  7267. struct linespec_result *canonical,
  7268. gdb::unique_xmalloc_ptr<char> cond_string,
  7269. gdb::unique_xmalloc_ptr<char> extra_string,
  7270. enum bptype type, enum bpdisp disposition,
  7271. int thread, int task, int ignore_count,
  7272. const struct breakpoint_ops *ops, int from_tty,
  7273. int enabled, int internal, unsigned flags)
  7274. {
  7275. if (canonical->pre_expanded)
  7276. gdb_assert (canonical->lsals.size () == 1);
  7277. for (const auto &lsal : canonical->lsals)
  7278. {
  7279. /* Note that 'location' can be NULL in the case of a plain
  7280. 'break', without arguments. */
  7281. event_location_up location
  7282. = (canonical->location != NULL
  7283. ? copy_event_location (canonical->location.get ()) : NULL);
  7284. gdb::unique_xmalloc_ptr<char> filter_string
  7285. (lsal.canonical != NULL ? xstrdup (lsal.canonical) : NULL);
  7286. create_breakpoint_sal (gdbarch, lsal.sals,
  7287. std::move (location),
  7288. std::move (filter_string),
  7289. std::move (cond_string),
  7290. std::move (extra_string),
  7291. type, disposition,
  7292. thread, task, ignore_count, ops,
  7293. from_tty, enabled, internal, flags,
  7294. canonical->special_display);
  7295. }
  7296. }
  7297. /* Parse LOCATION which is assumed to be a SAL specification possibly
  7298. followed by conditionals. On return, SALS contains an array of SAL
  7299. addresses found. LOCATION points to the end of the SAL (for
  7300. linespec locations).
  7301. The array and the line spec strings are allocated on the heap, it is
  7302. the caller's responsibility to free them. */
  7303. static void
  7304. parse_breakpoint_sals (struct event_location *location,
  7305. struct linespec_result *canonical)
  7306. {
  7307. struct symtab_and_line cursal;
  7308. if (event_location_type (location) == LINESPEC_LOCATION)
  7309. {
  7310. const char *spec = get_linespec_location (location)->spec_string;
  7311. if (spec == NULL)
  7312. {
  7313. /* The last displayed codepoint, if it's valid, is our default
  7314. breakpoint address. */
  7315. if (last_displayed_sal_is_valid ())
  7316. {
  7317. /* Set sal's pspace, pc, symtab, and line to the values
  7318. corresponding to the last call to print_frame_info.
  7319. Be sure to reinitialize LINE with NOTCURRENT == 0
  7320. as the breakpoint line number is inappropriate otherwise.
  7321. find_pc_line would adjust PC, re-set it back. */
  7322. symtab_and_line sal = get_last_displayed_sal ();
  7323. CORE_ADDR pc = sal.pc;
  7324. sal = find_pc_line (pc, 0);
  7325. /* "break" without arguments is equivalent to "break *PC"
  7326. where PC is the last displayed codepoint's address. So
  7327. make sure to set sal.explicit_pc to prevent GDB from
  7328. trying to expand the list of sals to include all other
  7329. instances with the same symtab and line. */
  7330. sal.pc = pc;
  7331. sal.explicit_pc = 1;
  7332. struct linespec_sals lsal;
  7333. lsal.sals = {sal};
  7334. lsal.canonical = NULL;
  7335. canonical->lsals.push_back (std::move (lsal));
  7336. return;
  7337. }
  7338. else
  7339. error (_("No default breakpoint address now."));
  7340. }
  7341. }
  7342. /* Force almost all breakpoints to be in terms of the
  7343. current_source_symtab (which is decode_line_1's default).
  7344. This should produce the results we want almost all of the
  7345. time while leaving default_breakpoint_* alone.
  7346. ObjC: However, don't match an Objective-C method name which
  7347. may have a '+' or '-' succeeded by a '['. */
  7348. cursal = get_current_source_symtab_and_line ();
  7349. if (last_displayed_sal_is_valid ())
  7350. {
  7351. const char *spec = NULL;
  7352. if (event_location_type (location) == LINESPEC_LOCATION)
  7353. spec = get_linespec_location (location)->spec_string;
  7354. if (!cursal.symtab
  7355. || (spec != NULL
  7356. && strchr ("+-", spec[0]) != NULL
  7357. && spec[1] != '['))
  7358. {
  7359. decode_line_full (location, DECODE_LINE_FUNFIRSTLINE, NULL,
  7360. get_last_displayed_symtab (),
  7361. get_last_displayed_line (),
  7362. canonical, NULL, NULL);
  7363. return;
  7364. }
  7365. }
  7366. decode_line_full (location, DECODE_LINE_FUNFIRSTLINE, NULL,
  7367. cursal.symtab, cursal.line, canonical, NULL, NULL);
  7368. }
  7369. /* Convert each SAL into a real PC. Verify that the PC can be
  7370. inserted as a breakpoint. If it can't throw an error. */
  7371. static void
  7372. breakpoint_sals_to_pc (std::vector<symtab_and_line> &sals)
  7373. {
  7374. for (auto &sal : sals)
  7375. resolve_sal_pc (&sal);
  7376. }
  7377. /* Fast tracepoints may have restrictions on valid locations. For
  7378. instance, a fast tracepoint using a jump instead of a trap will
  7379. likely have to overwrite more bytes than a trap would, and so can
  7380. only be placed where the instruction is longer than the jump, or a
  7381. multi-instruction sequence does not have a jump into the middle of
  7382. it, etc. */
  7383. static void
  7384. check_fast_tracepoint_sals (struct gdbarch *gdbarch,
  7385. gdb::array_view<const symtab_and_line> sals)
  7386. {
  7387. for (const auto &sal : sals)
  7388. {
  7389. struct gdbarch *sarch;
  7390. sarch = get_sal_arch (sal);
  7391. /* We fall back to GDBARCH if there is no architecture
  7392. associated with SAL. */
  7393. if (sarch == NULL)
  7394. sarch = gdbarch;
  7395. std::string msg;
  7396. if (!gdbarch_fast_tracepoint_valid_at (sarch, sal.pc, &msg))
  7397. error (_("May not have a fast tracepoint at %s%s"),
  7398. paddress (sarch, sal.pc), msg.c_str ());
  7399. }
  7400. }
  7401. /* Given TOK, a string specification of condition and thread, as
  7402. accepted by the 'break' command, extract the condition
  7403. string and thread number and set *COND_STRING and *THREAD.
  7404. PC identifies the context at which the condition should be parsed.
  7405. If no condition is found, *COND_STRING is set to NULL.
  7406. If no thread is found, *THREAD is set to -1. */
  7407. static void
  7408. find_condition_and_thread (const char *tok, CORE_ADDR pc,
  7409. gdb::unique_xmalloc_ptr<char> *cond_string,
  7410. int *thread, int *task,
  7411. gdb::unique_xmalloc_ptr<char> *rest)
  7412. {
  7413. cond_string->reset ();
  7414. *thread = -1;
  7415. *task = 0;
  7416. rest->reset ();
  7417. bool force = false;
  7418. while (tok && *tok)
  7419. {
  7420. const char *end_tok;
  7421. int toklen;
  7422. const char *cond_start = NULL;
  7423. const char *cond_end = NULL;
  7424. tok = skip_spaces (tok);
  7425. if ((*tok == '"' || *tok == ',') && rest)
  7426. {
  7427. rest->reset (savestring (tok, strlen (tok)));
  7428. return;
  7429. }
  7430. end_tok = skip_to_space (tok);
  7431. toklen = end_tok - tok;
  7432. if (toklen >= 1 && strncmp (tok, "if", toklen) == 0)
  7433. {
  7434. tok = cond_start = end_tok + 1;
  7435. try
  7436. {
  7437. parse_exp_1 (&tok, pc, block_for_pc (pc), 0);
  7438. }
  7439. catch (const gdb_exception_error &)
  7440. {
  7441. if (!force)
  7442. throw;
  7443. else
  7444. tok = tok + strlen (tok);
  7445. }
  7446. cond_end = tok;
  7447. cond_string->reset (savestring (cond_start, cond_end - cond_start));
  7448. }
  7449. else if (toklen >= 1 && strncmp (tok, "-force-condition", toklen) == 0)
  7450. {
  7451. tok = tok + toklen;
  7452. force = true;
  7453. }
  7454. else if (toklen >= 1 && strncmp (tok, "thread", toklen) == 0)
  7455. {
  7456. const char *tmptok;
  7457. struct thread_info *thr;
  7458. tok = end_tok + 1;
  7459. thr = parse_thread_id (tok, &tmptok);
  7460. if (tok == tmptok)
  7461. error (_("Junk after thread keyword."));
  7462. *thread = thr->global_num;
  7463. tok = tmptok;
  7464. }
  7465. else if (toklen >= 1 && strncmp (tok, "task", toklen) == 0)
  7466. {
  7467. char *tmptok;
  7468. tok = end_tok + 1;
  7469. *task = strtol (tok, &tmptok, 0);
  7470. if (tok == tmptok)
  7471. error (_("Junk after task keyword."));
  7472. if (!valid_task_id (*task))
  7473. error (_("Unknown task %d."), *task);
  7474. tok = tmptok;
  7475. }
  7476. else if (rest)
  7477. {
  7478. rest->reset (savestring (tok, strlen (tok)));
  7479. return;
  7480. }
  7481. else
  7482. error (_("Junk at end of arguments."));
  7483. }
  7484. }
  7485. /* Call 'find_condition_and_thread' for each sal in SALS until a parse
  7486. succeeds. The parsed values are written to COND_STRING, THREAD,
  7487. TASK, and REST. See the comment of 'find_condition_and_thread'
  7488. for the description of these parameters and INPUT. */
  7489. static void
  7490. find_condition_and_thread_for_sals (const std::vector<symtab_and_line> &sals,
  7491. const char *input,
  7492. gdb::unique_xmalloc_ptr<char> *cond_string,
  7493. int *thread, int *task,
  7494. gdb::unique_xmalloc_ptr<char> *rest)
  7495. {
  7496. int num_failures = 0;
  7497. for (auto &sal : sals)
  7498. {
  7499. gdb::unique_xmalloc_ptr<char> cond;
  7500. int thread_id = 0;
  7501. int task_id = 0;
  7502. gdb::unique_xmalloc_ptr<char> remaining;
  7503. /* Here we want to parse 'arg' to separate condition from thread
  7504. number. But because parsing happens in a context and the
  7505. contexts of sals might be different, try each until there is
  7506. success. Finding one successful parse is sufficient for our
  7507. goal. When setting the breakpoint we'll re-parse the
  7508. condition in the context of each sal. */
  7509. try
  7510. {
  7511. find_condition_and_thread (input, sal.pc, &cond, &thread_id,
  7512. &task_id, &remaining);
  7513. *cond_string = std::move (cond);
  7514. *thread = thread_id;
  7515. *task = task_id;
  7516. *rest = std::move (remaining);
  7517. break;
  7518. }
  7519. catch (const gdb_exception_error &e)
  7520. {
  7521. num_failures++;
  7522. /* If no sal remains, do not continue. */
  7523. if (num_failures == sals.size ())
  7524. throw;
  7525. }
  7526. }
  7527. }
  7528. /* Decode a static tracepoint marker spec. */
  7529. static std::vector<symtab_and_line>
  7530. decode_static_tracepoint_spec (const char **arg_p)
  7531. {
  7532. const char *p = &(*arg_p)[3];
  7533. const char *endp;
  7534. p = skip_spaces (p);
  7535. endp = skip_to_space (p);
  7536. std::string marker_str (p, endp - p);
  7537. std::vector<static_tracepoint_marker> markers
  7538. = target_static_tracepoint_markers_by_strid (marker_str.c_str ());
  7539. if (markers.empty ())
  7540. error (_("No known static tracepoint marker named %s"),
  7541. marker_str.c_str ());
  7542. std::vector<symtab_and_line> sals;
  7543. sals.reserve (markers.size ());
  7544. for (const static_tracepoint_marker &marker : markers)
  7545. {
  7546. symtab_and_line sal = find_pc_line (marker.address, 0);
  7547. sal.pc = marker.address;
  7548. sals.push_back (sal);
  7549. }
  7550. *arg_p = endp;
  7551. return sals;
  7552. }
  7553. /* Returns the breakpoint ops appropriate for use with with LOCATION_TYPE and
  7554. according to IS_TRACEPOINT. */
  7555. static const struct breakpoint_ops *
  7556. breakpoint_ops_for_event_location_type (enum event_location_type location_type,
  7557. bool is_tracepoint)
  7558. {
  7559. if (is_tracepoint)
  7560. {
  7561. if (location_type == PROBE_LOCATION)
  7562. return &tracepoint_probe_breakpoint_ops;
  7563. else
  7564. return &tracepoint_breakpoint_ops;
  7565. }
  7566. else
  7567. {
  7568. if (location_type == PROBE_LOCATION)
  7569. return &bkpt_probe_breakpoint_ops;
  7570. else
  7571. return &bkpt_breakpoint_ops;
  7572. }
  7573. }
  7574. /* See breakpoint.h. */
  7575. const struct breakpoint_ops *
  7576. breakpoint_ops_for_event_location (const struct event_location *location,
  7577. bool is_tracepoint)
  7578. {
  7579. if (location != nullptr)
  7580. return breakpoint_ops_for_event_location_type
  7581. (event_location_type (location), is_tracepoint);
  7582. return is_tracepoint ? &tracepoint_breakpoint_ops : &bkpt_breakpoint_ops;
  7583. }
  7584. /* See breakpoint.h. */
  7585. int
  7586. create_breakpoint (struct gdbarch *gdbarch,
  7587. struct event_location *location,
  7588. const char *cond_string,
  7589. int thread, const char *extra_string,
  7590. bool force_condition, int parse_extra,
  7591. int tempflag, enum bptype type_wanted,
  7592. int ignore_count,
  7593. enum auto_boolean pending_break_support,
  7594. const struct breakpoint_ops *ops,
  7595. int from_tty, int enabled, int internal,
  7596. unsigned flags)
  7597. {
  7598. struct linespec_result canonical;
  7599. int pending = 0;
  7600. int task = 0;
  7601. int prev_bkpt_count = breakpoint_count;
  7602. gdb_assert (ops != NULL);
  7603. /* If extra_string isn't useful, set it to NULL. */
  7604. if (extra_string != NULL && *extra_string == '\0')
  7605. extra_string = NULL;
  7606. try
  7607. {
  7608. ops->create_sals_from_location (location, &canonical, type_wanted);
  7609. }
  7610. catch (const gdb_exception_error &e)
  7611. {
  7612. /* If caller is interested in rc value from parse, set
  7613. value. */
  7614. if (e.error == NOT_FOUND_ERROR)
  7615. {
  7616. /* If pending breakpoint support is turned off, throw
  7617. error. */
  7618. if (pending_break_support == AUTO_BOOLEAN_FALSE)
  7619. throw;
  7620. exception_print (gdb_stderr, e);
  7621. /* If pending breakpoint support is auto query and the user
  7622. selects no, then simply return the error code. */
  7623. if (pending_break_support == AUTO_BOOLEAN_AUTO
  7624. && !nquery (_("Make %s pending on future shared library load? "),
  7625. bptype_string (type_wanted)))
  7626. return 0;
  7627. /* At this point, either the user was queried about setting
  7628. a pending breakpoint and selected yes, or pending
  7629. breakpoint behavior is on and thus a pending breakpoint
  7630. is defaulted on behalf of the user. */
  7631. pending = 1;
  7632. }
  7633. else
  7634. throw;
  7635. }
  7636. if (!pending && canonical.lsals.empty ())
  7637. return 0;
  7638. /* Resolve all line numbers to PC's and verify that the addresses
  7639. are ok for the target. */
  7640. if (!pending)
  7641. {
  7642. for (auto &lsal : canonical.lsals)
  7643. breakpoint_sals_to_pc (lsal.sals);
  7644. }
  7645. /* Fast tracepoints may have additional restrictions on location. */
  7646. if (!pending && type_wanted == bp_fast_tracepoint)
  7647. {
  7648. for (const auto &lsal : canonical.lsals)
  7649. check_fast_tracepoint_sals (gdbarch, lsal.sals);
  7650. }
  7651. /* Verify that condition can be parsed, before setting any
  7652. breakpoints. Allocate a separate condition expression for each
  7653. breakpoint. */
  7654. if (!pending)
  7655. {
  7656. gdb::unique_xmalloc_ptr<char> cond_string_copy;
  7657. gdb::unique_xmalloc_ptr<char> extra_string_copy;
  7658. if (parse_extra)
  7659. {
  7660. gdb::unique_xmalloc_ptr<char> rest;
  7661. gdb::unique_xmalloc_ptr<char> cond;
  7662. const linespec_sals &lsal = canonical.lsals[0];
  7663. find_condition_and_thread_for_sals (lsal.sals, extra_string,
  7664. &cond, &thread, &task, &rest);
  7665. cond_string_copy = std::move (cond);
  7666. extra_string_copy = std::move (rest);
  7667. }
  7668. else
  7669. {
  7670. if (type_wanted != bp_dprintf
  7671. && extra_string != NULL && *extra_string != '\0')
  7672. error (_("Garbage '%s' at end of location"), extra_string);
  7673. /* Check the validity of the condition. We should error out
  7674. if the condition is invalid at all of the locations and
  7675. if it is not forced. In the PARSE_EXTRA case above, this
  7676. check is done when parsing the EXTRA_STRING. */
  7677. if (cond_string != nullptr && !force_condition)
  7678. {
  7679. int num_failures = 0;
  7680. const linespec_sals &lsal = canonical.lsals[0];
  7681. for (const auto &sal : lsal.sals)
  7682. {
  7683. const char *cond = cond_string;
  7684. try
  7685. {
  7686. parse_exp_1 (&cond, sal.pc, block_for_pc (sal.pc), 0);
  7687. /* One success is sufficient to keep going. */
  7688. break;
  7689. }
  7690. catch (const gdb_exception_error &)
  7691. {
  7692. num_failures++;
  7693. /* If this is the last sal, error out. */
  7694. if (num_failures == lsal.sals.size ())
  7695. throw;
  7696. }
  7697. }
  7698. }
  7699. /* Create a private copy of condition string. */
  7700. if (cond_string)
  7701. cond_string_copy.reset (xstrdup (cond_string));
  7702. /* Create a private copy of any extra string. */
  7703. if (extra_string)
  7704. extra_string_copy.reset (xstrdup (extra_string));
  7705. }
  7706. ops->create_breakpoints_sal (gdbarch, &canonical,
  7707. std::move (cond_string_copy),
  7708. std::move (extra_string_copy),
  7709. type_wanted,
  7710. tempflag ? disp_del : disp_donttouch,
  7711. thread, task, ignore_count, ops,
  7712. from_tty, enabled, internal, flags);
  7713. }
  7714. else
  7715. {
  7716. std::unique_ptr <breakpoint> b = new_breakpoint_from_type (type_wanted);
  7717. init_raw_breakpoint_without_location (b.get (), gdbarch, type_wanted, ops);
  7718. b->location = copy_event_location (location);
  7719. if (parse_extra)
  7720. b->cond_string = NULL;
  7721. else
  7722. {
  7723. /* Create a private copy of condition string. */
  7724. b->cond_string.reset (cond_string != NULL
  7725. ? xstrdup (cond_string)
  7726. : NULL);
  7727. b->thread = thread;
  7728. }
  7729. /* Create a private copy of any extra string. */
  7730. b->extra_string.reset (extra_string != NULL
  7731. ? xstrdup (extra_string)
  7732. : NULL);
  7733. b->ignore_count = ignore_count;
  7734. b->disposition = tempflag ? disp_del : disp_donttouch;
  7735. b->condition_not_parsed = 1;
  7736. b->enable_state = enabled ? bp_enabled : bp_disabled;
  7737. if ((type_wanted != bp_breakpoint
  7738. && type_wanted != bp_hardware_breakpoint) || thread != -1)
  7739. b->pspace = current_program_space;
  7740. install_breakpoint (internal, std::move (b), 0);
  7741. }
  7742. if (canonical.lsals.size () > 1)
  7743. {
  7744. warning (_("Multiple breakpoints were set.\nUse the "
  7745. "\"delete\" command to delete unwanted breakpoints."));
  7746. prev_breakpoint_count = prev_bkpt_count;
  7747. }
  7748. update_global_location_list (UGLL_MAY_INSERT);
  7749. return 1;
  7750. }
  7751. /* Set a breakpoint.
  7752. ARG is a string describing breakpoint address,
  7753. condition, and thread.
  7754. FLAG specifies if a breakpoint is hardware on,
  7755. and if breakpoint is temporary, using BP_HARDWARE_FLAG
  7756. and BP_TEMPFLAG. */
  7757. static void
  7758. break_command_1 (const char *arg, int flag, int from_tty)
  7759. {
  7760. int tempflag = flag & BP_TEMPFLAG;
  7761. enum bptype type_wanted = (flag & BP_HARDWAREFLAG
  7762. ? bp_hardware_breakpoint
  7763. : bp_breakpoint);
  7764. event_location_up location = string_to_event_location (&arg, current_language);
  7765. const struct breakpoint_ops *ops = breakpoint_ops_for_event_location
  7766. (location.get (), false /* is_tracepoint */);
  7767. create_breakpoint (get_current_arch (),
  7768. location.get (),
  7769. NULL, 0, arg, false, 1 /* parse arg */,
  7770. tempflag, type_wanted,
  7771. 0 /* Ignore count */,
  7772. pending_break_support,
  7773. ops,
  7774. from_tty,
  7775. 1 /* enabled */,
  7776. 0 /* internal */,
  7777. 0);
  7778. }
  7779. /* Helper function for break_command_1 and disassemble_command. */
  7780. void
  7781. resolve_sal_pc (struct symtab_and_line *sal)
  7782. {
  7783. CORE_ADDR pc;
  7784. if (sal->pc == 0 && sal->symtab != NULL)
  7785. {
  7786. if (!find_line_pc (sal->symtab, sal->line, &pc))
  7787. error (_("No line %d in file \"%s\"."),
  7788. sal->line, symtab_to_filename_for_display (sal->symtab));
  7789. sal->pc = pc;
  7790. /* If this SAL corresponds to a breakpoint inserted using a line
  7791. number, then skip the function prologue if necessary. */
  7792. if (sal->explicit_line)
  7793. skip_prologue_sal (sal);
  7794. }
  7795. if (sal->section == 0 && sal->symtab != NULL)
  7796. {
  7797. const struct blockvector *bv;
  7798. const struct block *b;
  7799. struct symbol *sym;
  7800. bv = blockvector_for_pc_sect (sal->pc, 0, &b,
  7801. sal->symtab->compunit ());
  7802. if (bv != NULL)
  7803. {
  7804. sym = block_linkage_function (b);
  7805. if (sym != NULL)
  7806. {
  7807. fixup_symbol_section (sym, sal->symtab->compunit ()->objfile ());
  7808. sal->section
  7809. = sym->obj_section (sal->symtab->compunit ()->objfile ());
  7810. }
  7811. else
  7812. {
  7813. /* It really is worthwhile to have the section, so we'll
  7814. just have to look harder. This case can be executed
  7815. if we have line numbers but no functions (as can
  7816. happen in assembly source). */
  7817. scoped_restore_current_pspace_and_thread restore_pspace_thread;
  7818. switch_to_program_space_and_thread (sal->pspace);
  7819. bound_minimal_symbol msym = lookup_minimal_symbol_by_pc (sal->pc);
  7820. if (msym.minsym)
  7821. sal->section = msym.obj_section ();
  7822. }
  7823. }
  7824. }
  7825. }
  7826. void
  7827. break_command (const char *arg, int from_tty)
  7828. {
  7829. break_command_1 (arg, 0, from_tty);
  7830. }
  7831. void
  7832. tbreak_command (const char *arg, int from_tty)
  7833. {
  7834. break_command_1 (arg, BP_TEMPFLAG, from_tty);
  7835. }
  7836. static void
  7837. hbreak_command (const char *arg, int from_tty)
  7838. {
  7839. break_command_1 (arg, BP_HARDWAREFLAG, from_tty);
  7840. }
  7841. static void
  7842. thbreak_command (const char *arg, int from_tty)
  7843. {
  7844. break_command_1 (arg, (BP_TEMPFLAG | BP_HARDWAREFLAG), from_tty);
  7845. }
  7846. /* The dynamic printf command is mostly like a regular breakpoint, but
  7847. with a prewired command list consisting of a single output command,
  7848. built from extra arguments supplied on the dprintf command
  7849. line. */
  7850. static void
  7851. dprintf_command (const char *arg, int from_tty)
  7852. {
  7853. event_location_up location = string_to_event_location (&arg, current_language);
  7854. /* If non-NULL, ARG should have been advanced past the location;
  7855. the next character must be ','. */
  7856. if (arg != NULL)
  7857. {
  7858. if (arg[0] != ',' || arg[1] == '\0')
  7859. error (_("Format string required"));
  7860. else
  7861. {
  7862. /* Skip the comma. */
  7863. ++arg;
  7864. }
  7865. }
  7866. create_breakpoint (get_current_arch (),
  7867. location.get (),
  7868. NULL, 0, arg, false, 1 /* parse arg */,
  7869. 0, bp_dprintf,
  7870. 0 /* Ignore count */,
  7871. pending_break_support,
  7872. &dprintf_breakpoint_ops,
  7873. from_tty,
  7874. 1 /* enabled */,
  7875. 0 /* internal */,
  7876. 0);
  7877. }
  7878. static void
  7879. agent_printf_command (const char *arg, int from_tty)
  7880. {
  7881. error (_("May only run agent-printf on the target"));
  7882. }
  7883. /* Implement the "breakpoint_hit" breakpoint_ops method for
  7884. ranged breakpoints. */
  7885. static int
  7886. breakpoint_hit_ranged_breakpoint (const struct bp_location *bl,
  7887. const address_space *aspace,
  7888. CORE_ADDR bp_addr,
  7889. const target_waitstatus &ws)
  7890. {
  7891. if (ws.kind () != TARGET_WAITKIND_STOPPED
  7892. || ws.sig () != GDB_SIGNAL_TRAP)
  7893. return 0;
  7894. return breakpoint_address_match_range (bl->pspace->aspace, bl->address,
  7895. bl->length, aspace, bp_addr);
  7896. }
  7897. /* Implement the "resources_needed" breakpoint_ops method for
  7898. ranged breakpoints. */
  7899. static int
  7900. resources_needed_ranged_breakpoint (const struct bp_location *bl)
  7901. {
  7902. return target_ranged_break_num_registers ();
  7903. }
  7904. /* Implement the "print_it" breakpoint_ops method for
  7905. ranged breakpoints. */
  7906. static enum print_stop_action
  7907. print_it_ranged_breakpoint (bpstat *bs)
  7908. {
  7909. struct breakpoint *b = bs->breakpoint_at;
  7910. struct bp_location *bl = b->loc;
  7911. struct ui_out *uiout = current_uiout;
  7912. gdb_assert (b->type == bp_hardware_breakpoint);
  7913. /* Ranged breakpoints have only one location. */
  7914. gdb_assert (bl && bl->next == NULL);
  7915. annotate_breakpoint (b->number);
  7916. maybe_print_thread_hit_breakpoint (uiout);
  7917. if (b->disposition == disp_del)
  7918. uiout->text ("Temporary ranged breakpoint ");
  7919. else
  7920. uiout->text ("Ranged breakpoint ");
  7921. if (uiout->is_mi_like_p ())
  7922. {
  7923. uiout->field_string ("reason",
  7924. async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT));
  7925. uiout->field_string ("disp", bpdisp_text (b->disposition));
  7926. }
  7927. uiout->field_signed ("bkptno", b->number);
  7928. uiout->text (", ");
  7929. return PRINT_SRC_AND_LOC;
  7930. }
  7931. /* Implement the "print_one" breakpoint_ops method for
  7932. ranged breakpoints. */
  7933. static void
  7934. print_one_ranged_breakpoint (struct breakpoint *b,
  7935. struct bp_location **last_loc)
  7936. {
  7937. struct bp_location *bl = b->loc;
  7938. struct value_print_options opts;
  7939. struct ui_out *uiout = current_uiout;
  7940. /* Ranged breakpoints have only one location. */
  7941. gdb_assert (bl && bl->next == NULL);
  7942. get_user_print_options (&opts);
  7943. if (opts.addressprint)
  7944. /* We don't print the address range here, it will be printed later
  7945. by print_one_detail_ranged_breakpoint. */
  7946. uiout->field_skip ("addr");
  7947. annotate_field (5);
  7948. print_breakpoint_location (b, bl);
  7949. *last_loc = bl;
  7950. }
  7951. /* Implement the "print_one_detail" breakpoint_ops method for
  7952. ranged breakpoints. */
  7953. static void
  7954. print_one_detail_ranged_breakpoint (const struct breakpoint *b,
  7955. struct ui_out *uiout)
  7956. {
  7957. CORE_ADDR address_start, address_end;
  7958. struct bp_location *bl = b->loc;
  7959. string_file stb;
  7960. gdb_assert (bl);
  7961. address_start = bl->address;
  7962. address_end = address_start + bl->length - 1;
  7963. uiout->text ("\taddress range: ");
  7964. stb.printf ("[%s, %s]",
  7965. print_core_address (bl->gdbarch, address_start),
  7966. print_core_address (bl->gdbarch, address_end));
  7967. uiout->field_stream ("addr", stb);
  7968. uiout->text ("\n");
  7969. }
  7970. /* Implement the "print_mention" breakpoint_ops method for
  7971. ranged breakpoints. */
  7972. static void
  7973. print_mention_ranged_breakpoint (struct breakpoint *b)
  7974. {
  7975. struct bp_location *bl = b->loc;
  7976. struct ui_out *uiout = current_uiout;
  7977. gdb_assert (bl);
  7978. gdb_assert (b->type == bp_hardware_breakpoint);
  7979. uiout->message (_("Hardware assisted ranged breakpoint %d from %s to %s."),
  7980. b->number, paddress (bl->gdbarch, bl->address),
  7981. paddress (bl->gdbarch, bl->address + bl->length - 1));
  7982. }
  7983. /* Implement the "print_recreate" breakpoint_ops method for
  7984. ranged breakpoints. */
  7985. static void
  7986. print_recreate_ranged_breakpoint (struct breakpoint *b, struct ui_file *fp)
  7987. {
  7988. gdb_printf (fp, "break-range %s, %s",
  7989. event_location_to_string (b->location.get ()),
  7990. event_location_to_string (b->location_range_end.get ()));
  7991. print_recreate_thread (b, fp);
  7992. }
  7993. /* The breakpoint_ops structure to be used in ranged breakpoints. */
  7994. static struct breakpoint_ops ranged_breakpoint_ops;
  7995. /* Find the address where the end of the breakpoint range should be
  7996. placed, given the SAL of the end of the range. This is so that if
  7997. the user provides a line number, the end of the range is set to the
  7998. last instruction of the given line. */
  7999. static CORE_ADDR
  8000. find_breakpoint_range_end (struct symtab_and_line sal)
  8001. {
  8002. CORE_ADDR end;
  8003. /* If the user provided a PC value, use it. Otherwise,
  8004. find the address of the end of the given location. */
  8005. if (sal.explicit_pc)
  8006. end = sal.pc;
  8007. else
  8008. {
  8009. int ret;
  8010. CORE_ADDR start;
  8011. ret = find_line_pc_range (sal, &start, &end);
  8012. if (!ret)
  8013. error (_("Could not find location of the end of the range."));
  8014. /* find_line_pc_range returns the start of the next line. */
  8015. end--;
  8016. }
  8017. return end;
  8018. }
  8019. /* Implement the "break-range" CLI command. */
  8020. static void
  8021. break_range_command (const char *arg, int from_tty)
  8022. {
  8023. const char *arg_start;
  8024. struct linespec_result canonical_start, canonical_end;
  8025. int bp_count, can_use_bp, length;
  8026. CORE_ADDR end;
  8027. struct breakpoint *b;
  8028. /* We don't support software ranged breakpoints. */
  8029. if (target_ranged_break_num_registers () < 0)
  8030. error (_("This target does not support hardware ranged breakpoints."));
  8031. bp_count = hw_breakpoint_used_count ();
  8032. bp_count += target_ranged_break_num_registers ();
  8033. can_use_bp = target_can_use_hardware_watchpoint (bp_hardware_breakpoint,
  8034. bp_count, 0);
  8035. if (can_use_bp < 0)
  8036. error (_("Hardware breakpoints used exceeds limit."));
  8037. arg = skip_spaces (arg);
  8038. if (arg == NULL || arg[0] == '\0')
  8039. error(_("No address range specified."));
  8040. arg_start = arg;
  8041. event_location_up start_location = string_to_event_location (&arg,
  8042. current_language);
  8043. parse_breakpoint_sals (start_location.get (), &canonical_start);
  8044. if (arg[0] != ',')
  8045. error (_("Too few arguments."));
  8046. else if (canonical_start.lsals.empty ())
  8047. error (_("Could not find location of the beginning of the range."));
  8048. const linespec_sals &lsal_start = canonical_start.lsals[0];
  8049. if (canonical_start.lsals.size () > 1
  8050. || lsal_start.sals.size () != 1)
  8051. error (_("Cannot create a ranged breakpoint with multiple locations."));
  8052. const symtab_and_line &sal_start = lsal_start.sals[0];
  8053. std::string addr_string_start (arg_start, arg - arg_start);
  8054. arg++; /* Skip the comma. */
  8055. arg = skip_spaces (arg);
  8056. /* Parse the end location. */
  8057. arg_start = arg;
  8058. /* We call decode_line_full directly here instead of using
  8059. parse_breakpoint_sals because we need to specify the start location's
  8060. symtab and line as the default symtab and line for the end of the
  8061. range. This makes it possible to have ranges like "foo.c:27, +14",
  8062. where +14 means 14 lines from the start location. */
  8063. event_location_up end_location = string_to_event_location (&arg,
  8064. current_language);
  8065. decode_line_full (end_location.get (), DECODE_LINE_FUNFIRSTLINE, NULL,
  8066. sal_start.symtab, sal_start.line,
  8067. &canonical_end, NULL, NULL);
  8068. if (canonical_end.lsals.empty ())
  8069. error (_("Could not find location of the end of the range."));
  8070. const linespec_sals &lsal_end = canonical_end.lsals[0];
  8071. if (canonical_end.lsals.size () > 1
  8072. || lsal_end.sals.size () != 1)
  8073. error (_("Cannot create a ranged breakpoint with multiple locations."));
  8074. const symtab_and_line &sal_end = lsal_end.sals[0];
  8075. end = find_breakpoint_range_end (sal_end);
  8076. if (sal_start.pc > end)
  8077. error (_("Invalid address range, end precedes start."));
  8078. length = end - sal_start.pc + 1;
  8079. if (length < 0)
  8080. /* Length overflowed. */
  8081. error (_("Address range too large."));
  8082. else if (length == 1)
  8083. {
  8084. /* This range is simple enough to be handled by
  8085. the `hbreak' command. */
  8086. hbreak_command (&addr_string_start[0], 1);
  8087. return;
  8088. }
  8089. /* Now set up the breakpoint. */
  8090. b = set_raw_breakpoint (get_current_arch (), sal_start,
  8091. bp_hardware_breakpoint, &ranged_breakpoint_ops);
  8092. set_breakpoint_count (breakpoint_count + 1);
  8093. b->number = breakpoint_count;
  8094. b->disposition = disp_donttouch;
  8095. b->location = std::move (start_location);
  8096. b->location_range_end = std::move (end_location);
  8097. b->loc->length = length;
  8098. mention (b);
  8099. gdb::observers::breakpoint_created.notify (b);
  8100. update_global_location_list (UGLL_MAY_INSERT);
  8101. }
  8102. /* Return non-zero if EXP is verified as constant. Returned zero
  8103. means EXP is variable. Also the constant detection may fail for
  8104. some constant expressions and in such case still falsely return
  8105. zero. */
  8106. static bool
  8107. watchpoint_exp_is_const (const struct expression *exp)
  8108. {
  8109. return exp->op->constant_p ();
  8110. }
  8111. /* Implement the "re_set" breakpoint_ops method for watchpoints. */
  8112. static void
  8113. re_set_watchpoint (struct breakpoint *b)
  8114. {
  8115. struct watchpoint *w = (struct watchpoint *) b;
  8116. /* Watchpoint can be either on expression using entirely global
  8117. variables, or it can be on local variables.
  8118. Watchpoints of the first kind are never auto-deleted, and even
  8119. persist across program restarts. Since they can use variables
  8120. from shared libraries, we need to reparse expression as libraries
  8121. are loaded and unloaded.
  8122. Watchpoints on local variables can also change meaning as result
  8123. of solib event. For example, if a watchpoint uses both a local
  8124. and a global variables in expression, it's a local watchpoint,
  8125. but unloading of a shared library will make the expression
  8126. invalid. This is not a very common use case, but we still
  8127. re-evaluate expression, to avoid surprises to the user.
  8128. Note that for local watchpoints, we re-evaluate it only if
  8129. watchpoints frame id is still valid. If it's not, it means the
  8130. watchpoint is out of scope and will be deleted soon. In fact,
  8131. I'm not sure we'll ever be called in this case.
  8132. If a local watchpoint's frame id is still valid, then
  8133. w->exp_valid_block is likewise valid, and we can safely use it.
  8134. Don't do anything about disabled watchpoints, since they will be
  8135. reevaluated again when enabled. */
  8136. update_watchpoint (w, 1 /* reparse */);
  8137. }
  8138. /* Implement the "insert" breakpoint_ops method for hardware watchpoints. */
  8139. static int
  8140. insert_watchpoint (struct bp_location *bl)
  8141. {
  8142. struct watchpoint *w = (struct watchpoint *) bl->owner;
  8143. int length = w->exact ? 1 : bl->length;
  8144. return target_insert_watchpoint (bl->address, length, bl->watchpoint_type,
  8145. w->cond_exp.get ());
  8146. }
  8147. /* Implement the "remove" breakpoint_ops method for hardware watchpoints. */
  8148. static int
  8149. remove_watchpoint (struct bp_location *bl, enum remove_bp_reason reason)
  8150. {
  8151. struct watchpoint *w = (struct watchpoint *) bl->owner;
  8152. int length = w->exact ? 1 : bl->length;
  8153. return target_remove_watchpoint (bl->address, length, bl->watchpoint_type,
  8154. w->cond_exp.get ());
  8155. }
  8156. static int
  8157. breakpoint_hit_watchpoint (const struct bp_location *bl,
  8158. const address_space *aspace, CORE_ADDR bp_addr,
  8159. const target_waitstatus &ws)
  8160. {
  8161. struct breakpoint *b = bl->owner;
  8162. struct watchpoint *w = (struct watchpoint *) b;
  8163. /* Continuable hardware watchpoints are treated as non-existent if the
  8164. reason we stopped wasn't a hardware watchpoint (we didn't stop on
  8165. some data address). Otherwise gdb won't stop on a break instruction
  8166. in the code (not from a breakpoint) when a hardware watchpoint has
  8167. been defined. Also skip watchpoints which we know did not trigger
  8168. (did not match the data address). */
  8169. if (is_hardware_watchpoint (b)
  8170. && w->watchpoint_triggered == watch_triggered_no)
  8171. return 0;
  8172. return 1;
  8173. }
  8174. static void
  8175. check_status_watchpoint (bpstat *bs)
  8176. {
  8177. gdb_assert (is_watchpoint (bs->breakpoint_at));
  8178. bpstat_check_watchpoint (bs);
  8179. }
  8180. /* Implement the "resources_needed" breakpoint_ops method for
  8181. hardware watchpoints. */
  8182. static int
  8183. resources_needed_watchpoint (const struct bp_location *bl)
  8184. {
  8185. struct watchpoint *w = (struct watchpoint *) bl->owner;
  8186. int length = w->exact? 1 : bl->length;
  8187. return target_region_ok_for_hw_watchpoint (bl->address, length);
  8188. }
  8189. /* Implement the "works_in_software_mode" breakpoint_ops method for
  8190. hardware watchpoints. */
  8191. static int
  8192. works_in_software_mode_watchpoint (const struct breakpoint *b)
  8193. {
  8194. /* Read and access watchpoints only work with hardware support. */
  8195. return b->type == bp_watchpoint || b->type == bp_hardware_watchpoint;
  8196. }
  8197. static enum print_stop_action
  8198. print_it_watchpoint (bpstat *bs)
  8199. {
  8200. struct breakpoint *b;
  8201. enum print_stop_action result;
  8202. struct watchpoint *w;
  8203. struct ui_out *uiout = current_uiout;
  8204. gdb_assert (bs->bp_location_at != NULL);
  8205. b = bs->breakpoint_at;
  8206. w = (struct watchpoint *) b;
  8207. annotate_watchpoint (b->number);
  8208. maybe_print_thread_hit_breakpoint (uiout);
  8209. string_file stb;
  8210. gdb::optional<ui_out_emit_tuple> tuple_emitter;
  8211. switch (b->type)
  8212. {
  8213. case bp_watchpoint:
  8214. case bp_hardware_watchpoint:
  8215. if (uiout->is_mi_like_p ())
  8216. uiout->field_string
  8217. ("reason", async_reason_lookup (EXEC_ASYNC_WATCHPOINT_TRIGGER));
  8218. mention (b);
  8219. tuple_emitter.emplace (uiout, "value");
  8220. uiout->text ("\nOld value = ");
  8221. watchpoint_value_print (bs->old_val.get (), &stb);
  8222. uiout->field_stream ("old", stb);
  8223. uiout->text ("\nNew value = ");
  8224. watchpoint_value_print (w->val.get (), &stb);
  8225. uiout->field_stream ("new", stb);
  8226. uiout->text ("\n");
  8227. /* More than one watchpoint may have been triggered. */
  8228. result = PRINT_UNKNOWN;
  8229. break;
  8230. case bp_read_watchpoint:
  8231. if (uiout->is_mi_like_p ())
  8232. uiout->field_string
  8233. ("reason", async_reason_lookup (EXEC_ASYNC_READ_WATCHPOINT_TRIGGER));
  8234. mention (b);
  8235. tuple_emitter.emplace (uiout, "value");
  8236. uiout->text ("\nValue = ");
  8237. watchpoint_value_print (w->val.get (), &stb);
  8238. uiout->field_stream ("value", stb);
  8239. uiout->text ("\n");
  8240. result = PRINT_UNKNOWN;
  8241. break;
  8242. case bp_access_watchpoint:
  8243. if (bs->old_val != NULL)
  8244. {
  8245. if (uiout->is_mi_like_p ())
  8246. uiout->field_string
  8247. ("reason",
  8248. async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER));
  8249. mention (b);
  8250. tuple_emitter.emplace (uiout, "value");
  8251. uiout->text ("\nOld value = ");
  8252. watchpoint_value_print (bs->old_val.get (), &stb);
  8253. uiout->field_stream ("old", stb);
  8254. uiout->text ("\nNew value = ");
  8255. }
  8256. else
  8257. {
  8258. mention (b);
  8259. if (uiout->is_mi_like_p ())
  8260. uiout->field_string
  8261. ("reason",
  8262. async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER));
  8263. tuple_emitter.emplace (uiout, "value");
  8264. uiout->text ("\nValue = ");
  8265. }
  8266. watchpoint_value_print (w->val.get (), &stb);
  8267. uiout->field_stream ("new", stb);
  8268. uiout->text ("\n");
  8269. result = PRINT_UNKNOWN;
  8270. break;
  8271. default:
  8272. result = PRINT_UNKNOWN;
  8273. }
  8274. return result;
  8275. }
  8276. /* Implement the "print_mention" breakpoint_ops method for hardware
  8277. watchpoints. */
  8278. static void
  8279. print_mention_watchpoint (struct breakpoint *b)
  8280. {
  8281. struct watchpoint *w = (struct watchpoint *) b;
  8282. struct ui_out *uiout = current_uiout;
  8283. const char *tuple_name;
  8284. switch (b->type)
  8285. {
  8286. case bp_watchpoint:
  8287. uiout->text ("Watchpoint ");
  8288. tuple_name = "wpt";
  8289. break;
  8290. case bp_hardware_watchpoint:
  8291. uiout->text ("Hardware watchpoint ");
  8292. tuple_name = "wpt";
  8293. break;
  8294. case bp_read_watchpoint:
  8295. uiout->text ("Hardware read watchpoint ");
  8296. tuple_name = "hw-rwpt";
  8297. break;
  8298. case bp_access_watchpoint:
  8299. uiout->text ("Hardware access (read/write) watchpoint ");
  8300. tuple_name = "hw-awpt";
  8301. break;
  8302. default:
  8303. internal_error (__FILE__, __LINE__,
  8304. _("Invalid hardware watchpoint type."));
  8305. }
  8306. ui_out_emit_tuple tuple_emitter (uiout, tuple_name);
  8307. uiout->field_signed ("number", b->number);
  8308. uiout->text (": ");
  8309. uiout->field_string ("exp", w->exp_string.get ());
  8310. }
  8311. /* Implement the "print_recreate" breakpoint_ops method for
  8312. watchpoints. */
  8313. static void
  8314. print_recreate_watchpoint (struct breakpoint *b, struct ui_file *fp)
  8315. {
  8316. struct watchpoint *w = (struct watchpoint *) b;
  8317. switch (b->type)
  8318. {
  8319. case bp_watchpoint:
  8320. case bp_hardware_watchpoint:
  8321. gdb_printf (fp, "watch");
  8322. break;
  8323. case bp_read_watchpoint:
  8324. gdb_printf (fp, "rwatch");
  8325. break;
  8326. case bp_access_watchpoint:
  8327. gdb_printf (fp, "awatch");
  8328. break;
  8329. default:
  8330. internal_error (__FILE__, __LINE__,
  8331. _("Invalid watchpoint type."));
  8332. }
  8333. gdb_printf (fp, " %s", w->exp_string.get ());
  8334. print_recreate_thread (b, fp);
  8335. }
  8336. /* Implement the "explains_signal" breakpoint_ops method for
  8337. watchpoints. */
  8338. static int
  8339. explains_signal_watchpoint (struct breakpoint *b, enum gdb_signal sig)
  8340. {
  8341. /* A software watchpoint cannot cause a signal other than
  8342. GDB_SIGNAL_TRAP. */
  8343. if (b->type == bp_watchpoint && sig != GDB_SIGNAL_TRAP)
  8344. return 0;
  8345. return 1;
  8346. }
  8347. /* The breakpoint_ops structure to be used in hardware watchpoints. */
  8348. static struct breakpoint_ops watchpoint_breakpoint_ops;
  8349. /* Implement the "insert" breakpoint_ops method for
  8350. masked hardware watchpoints. */
  8351. static int
  8352. insert_masked_watchpoint (struct bp_location *bl)
  8353. {
  8354. struct watchpoint *w = (struct watchpoint *) bl->owner;
  8355. return target_insert_mask_watchpoint (bl->address, w->hw_wp_mask,
  8356. bl->watchpoint_type);
  8357. }
  8358. /* Implement the "remove" breakpoint_ops method for
  8359. masked hardware watchpoints. */
  8360. static int
  8361. remove_masked_watchpoint (struct bp_location *bl, enum remove_bp_reason reason)
  8362. {
  8363. struct watchpoint *w = (struct watchpoint *) bl->owner;
  8364. return target_remove_mask_watchpoint (bl->address, w->hw_wp_mask,
  8365. bl->watchpoint_type);
  8366. }
  8367. /* Implement the "resources_needed" breakpoint_ops method for
  8368. masked hardware watchpoints. */
  8369. static int
  8370. resources_needed_masked_watchpoint (const struct bp_location *bl)
  8371. {
  8372. struct watchpoint *w = (struct watchpoint *) bl->owner;
  8373. return target_masked_watch_num_registers (bl->address, w->hw_wp_mask);
  8374. }
  8375. /* Implement the "works_in_software_mode" breakpoint_ops method for
  8376. masked hardware watchpoints. */
  8377. static int
  8378. works_in_software_mode_masked_watchpoint (const struct breakpoint *b)
  8379. {
  8380. return 0;
  8381. }
  8382. /* Implement the "print_it" breakpoint_ops method for
  8383. masked hardware watchpoints. */
  8384. static enum print_stop_action
  8385. print_it_masked_watchpoint (bpstat *bs)
  8386. {
  8387. struct breakpoint *b = bs->breakpoint_at;
  8388. struct ui_out *uiout = current_uiout;
  8389. /* Masked watchpoints have only one location. */
  8390. gdb_assert (b->loc && b->loc->next == NULL);
  8391. annotate_watchpoint (b->number);
  8392. maybe_print_thread_hit_breakpoint (uiout);
  8393. switch (b->type)
  8394. {
  8395. case bp_hardware_watchpoint:
  8396. if (uiout->is_mi_like_p ())
  8397. uiout->field_string
  8398. ("reason", async_reason_lookup (EXEC_ASYNC_WATCHPOINT_TRIGGER));
  8399. break;
  8400. case bp_read_watchpoint:
  8401. if (uiout->is_mi_like_p ())
  8402. uiout->field_string
  8403. ("reason", async_reason_lookup (EXEC_ASYNC_READ_WATCHPOINT_TRIGGER));
  8404. break;
  8405. case bp_access_watchpoint:
  8406. if (uiout->is_mi_like_p ())
  8407. uiout->field_string
  8408. ("reason",
  8409. async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER));
  8410. break;
  8411. default:
  8412. internal_error (__FILE__, __LINE__,
  8413. _("Invalid hardware watchpoint type."));
  8414. }
  8415. mention (b);
  8416. uiout->text (_("\n\
  8417. Check the underlying instruction at PC for the memory\n\
  8418. address and value which triggered this watchpoint.\n"));
  8419. uiout->text ("\n");
  8420. /* More than one watchpoint may have been triggered. */
  8421. return PRINT_UNKNOWN;
  8422. }
  8423. /* Implement the "print_one_detail" breakpoint_ops method for
  8424. masked hardware watchpoints. */
  8425. static void
  8426. print_one_detail_masked_watchpoint (const struct breakpoint *b,
  8427. struct ui_out *uiout)
  8428. {
  8429. struct watchpoint *w = (struct watchpoint *) b;
  8430. /* Masked watchpoints have only one location. */
  8431. gdb_assert (b->loc && b->loc->next == NULL);
  8432. uiout->text ("\tmask ");
  8433. uiout->field_core_addr ("mask", b->loc->gdbarch, w->hw_wp_mask);
  8434. uiout->text ("\n");
  8435. }
  8436. /* Implement the "print_mention" breakpoint_ops method for
  8437. masked hardware watchpoints. */
  8438. static void
  8439. print_mention_masked_watchpoint (struct breakpoint *b)
  8440. {
  8441. struct watchpoint *w = (struct watchpoint *) b;
  8442. struct ui_out *uiout = current_uiout;
  8443. const char *tuple_name;
  8444. switch (b->type)
  8445. {
  8446. case bp_hardware_watchpoint:
  8447. uiout->text ("Masked hardware watchpoint ");
  8448. tuple_name = "wpt";
  8449. break;
  8450. case bp_read_watchpoint:
  8451. uiout->text ("Masked hardware read watchpoint ");
  8452. tuple_name = "hw-rwpt";
  8453. break;
  8454. case bp_access_watchpoint:
  8455. uiout->text ("Masked hardware access (read/write) watchpoint ");
  8456. tuple_name = "hw-awpt";
  8457. break;
  8458. default:
  8459. internal_error (__FILE__, __LINE__,
  8460. _("Invalid hardware watchpoint type."));
  8461. }
  8462. ui_out_emit_tuple tuple_emitter (uiout, tuple_name);
  8463. uiout->field_signed ("number", b->number);
  8464. uiout->text (": ");
  8465. uiout->field_string ("exp", w->exp_string.get ());
  8466. }
  8467. /* Implement the "print_recreate" breakpoint_ops method for
  8468. masked hardware watchpoints. */
  8469. static void
  8470. print_recreate_masked_watchpoint (struct breakpoint *b, struct ui_file *fp)
  8471. {
  8472. struct watchpoint *w = (struct watchpoint *) b;
  8473. switch (b->type)
  8474. {
  8475. case bp_hardware_watchpoint:
  8476. gdb_printf (fp, "watch");
  8477. break;
  8478. case bp_read_watchpoint:
  8479. gdb_printf (fp, "rwatch");
  8480. break;
  8481. case bp_access_watchpoint:
  8482. gdb_printf (fp, "awatch");
  8483. break;
  8484. default:
  8485. internal_error (__FILE__, __LINE__,
  8486. _("Invalid hardware watchpoint type."));
  8487. }
  8488. gdb_printf (fp, " %s mask 0x%s", w->exp_string.get (),
  8489. phex (w->hw_wp_mask, sizeof (CORE_ADDR)));
  8490. print_recreate_thread (b, fp);
  8491. }
  8492. /* The breakpoint_ops structure to be used in masked hardware watchpoints. */
  8493. static struct breakpoint_ops masked_watchpoint_breakpoint_ops;
  8494. /* Tell whether the given watchpoint is a masked hardware watchpoint. */
  8495. static bool
  8496. is_masked_watchpoint (const struct breakpoint *b)
  8497. {
  8498. return b->ops == &masked_watchpoint_breakpoint_ops;
  8499. }
  8500. /* accessflag: hw_write: watch write,
  8501. hw_read: watch read,
  8502. hw_access: watch access (read or write) */
  8503. static void
  8504. watch_command_1 (const char *arg, int accessflag, int from_tty,
  8505. bool just_location, bool internal)
  8506. {
  8507. struct breakpoint *scope_breakpoint = NULL;
  8508. const struct block *exp_valid_block = NULL, *cond_exp_valid_block = NULL;
  8509. struct value *result;
  8510. int saved_bitpos = 0, saved_bitsize = 0;
  8511. const char *exp_start = NULL;
  8512. const char *exp_end = NULL;
  8513. const char *tok, *end_tok;
  8514. int toklen = -1;
  8515. const char *cond_start = NULL;
  8516. const char *cond_end = NULL;
  8517. enum bptype bp_type;
  8518. int thread = -1;
  8519. /* Flag to indicate whether we are going to use masks for
  8520. the hardware watchpoint. */
  8521. bool use_mask = false;
  8522. CORE_ADDR mask = 0;
  8523. int task = 0;
  8524. /* Make sure that we actually have parameters to parse. */
  8525. if (arg != NULL && arg[0] != '\0')
  8526. {
  8527. const char *value_start;
  8528. exp_end = arg + strlen (arg);
  8529. /* Look for "parameter value" pairs at the end
  8530. of the arguments string. */
  8531. for (tok = exp_end - 1; tok > arg; tok--)
  8532. {
  8533. /* Skip whitespace at the end of the argument list. */
  8534. while (tok > arg && (*tok == ' ' || *tok == '\t'))
  8535. tok--;
  8536. /* Find the beginning of the last token.
  8537. This is the value of the parameter. */
  8538. while (tok > arg && (*tok != ' ' && *tok != '\t'))
  8539. tok--;
  8540. value_start = tok + 1;
  8541. /* Skip whitespace. */
  8542. while (tok > arg && (*tok == ' ' || *tok == '\t'))
  8543. tok--;
  8544. end_tok = tok;
  8545. /* Find the beginning of the second to last token.
  8546. This is the parameter itself. */
  8547. while (tok > arg && (*tok != ' ' && *tok != '\t'))
  8548. tok--;
  8549. tok++;
  8550. toklen = end_tok - tok + 1;
  8551. if (toklen == 6 && startswith (tok, "thread"))
  8552. {
  8553. struct thread_info *thr;
  8554. /* At this point we've found a "thread" token, which means
  8555. the user is trying to set a watchpoint that triggers
  8556. only in a specific thread. */
  8557. const char *endp;
  8558. if (thread != -1)
  8559. error(_("You can specify only one thread."));
  8560. /* Extract the thread ID from the next token. */
  8561. thr = parse_thread_id (value_start, &endp);
  8562. /* Check if the user provided a valid thread ID. */
  8563. if (*endp != ' ' && *endp != '\t' && *endp != '\0')
  8564. invalid_thread_id_error (value_start);
  8565. thread = thr->global_num;
  8566. }
  8567. else if (toklen == 4 && startswith (tok, "task"))
  8568. {
  8569. char *tmp;
  8570. task = strtol (value_start, &tmp, 0);
  8571. if (tmp == value_start)
  8572. error (_("Junk after task keyword."));
  8573. if (!valid_task_id (task))
  8574. error (_("Unknown task %d."), task);
  8575. }
  8576. else if (toklen == 4 && startswith (tok, "mask"))
  8577. {
  8578. /* We've found a "mask" token, which means the user wants to
  8579. create a hardware watchpoint that is going to have the mask
  8580. facility. */
  8581. struct value *mask_value, *mark;
  8582. if (use_mask)
  8583. error(_("You can specify only one mask."));
  8584. use_mask = just_location = true;
  8585. mark = value_mark ();
  8586. mask_value = parse_to_comma_and_eval (&value_start);
  8587. mask = value_as_address (mask_value);
  8588. value_free_to_mark (mark);
  8589. }
  8590. else
  8591. /* We didn't recognize what we found. We should stop here. */
  8592. break;
  8593. /* Truncate the string and get rid of the "parameter value" pair before
  8594. the arguments string is parsed by the parse_exp_1 function. */
  8595. exp_end = tok;
  8596. }
  8597. }
  8598. else
  8599. exp_end = arg;
  8600. /* Parse the rest of the arguments. From here on out, everything
  8601. is in terms of a newly allocated string instead of the original
  8602. ARG. */
  8603. std::string expression (arg, exp_end - arg);
  8604. exp_start = arg = expression.c_str ();
  8605. innermost_block_tracker tracker;
  8606. expression_up exp = parse_exp_1 (&arg, 0, 0, 0, &tracker);
  8607. exp_end = arg;
  8608. /* Remove trailing whitespace from the expression before saving it.
  8609. This makes the eventual display of the expression string a bit
  8610. prettier. */
  8611. while (exp_end > exp_start && (exp_end[-1] == ' ' || exp_end[-1] == '\t'))
  8612. --exp_end;
  8613. /* Checking if the expression is not constant. */
  8614. if (watchpoint_exp_is_const (exp.get ()))
  8615. {
  8616. int len;
  8617. len = exp_end - exp_start;
  8618. while (len > 0 && isspace (exp_start[len - 1]))
  8619. len--;
  8620. error (_("Cannot watch constant value `%.*s'."), len, exp_start);
  8621. }
  8622. exp_valid_block = tracker.block ();
  8623. struct value *mark = value_mark ();
  8624. struct value *val_as_value = nullptr;
  8625. fetch_subexp_value (exp.get (), exp->op.get (), &val_as_value, &result, NULL,
  8626. just_location);
  8627. if (val_as_value != NULL && just_location)
  8628. {
  8629. saved_bitpos = value_bitpos (val_as_value);
  8630. saved_bitsize = value_bitsize (val_as_value);
  8631. }
  8632. value_ref_ptr val;
  8633. if (just_location)
  8634. {
  8635. int ret;
  8636. exp_valid_block = NULL;
  8637. val = release_value (value_addr (result));
  8638. value_free_to_mark (mark);
  8639. if (use_mask)
  8640. {
  8641. ret = target_masked_watch_num_registers (value_as_address (val.get ()),
  8642. mask);
  8643. if (ret == -1)
  8644. error (_("This target does not support masked watchpoints."));
  8645. else if (ret == -2)
  8646. error (_("Invalid mask or memory region."));
  8647. }
  8648. }
  8649. else if (val_as_value != NULL)
  8650. val = release_value (val_as_value);
  8651. tok = skip_spaces (arg);
  8652. end_tok = skip_to_space (tok);
  8653. toklen = end_tok - tok;
  8654. if (toklen >= 1 && strncmp (tok, "if", toklen) == 0)
  8655. {
  8656. tok = cond_start = end_tok + 1;
  8657. innermost_block_tracker if_tracker;
  8658. parse_exp_1 (&tok, 0, 0, 0, &if_tracker);
  8659. /* The watchpoint expression may not be local, but the condition
  8660. may still be. E.g.: `watch global if local > 0'. */
  8661. cond_exp_valid_block = if_tracker.block ();
  8662. cond_end = tok;
  8663. }
  8664. if (*tok)
  8665. error (_("Junk at end of command."));
  8666. frame_info *wp_frame = block_innermost_frame (exp_valid_block);
  8667. /* Save this because create_internal_breakpoint below invalidates
  8668. 'wp_frame'. */
  8669. frame_id watchpoint_frame = get_frame_id (wp_frame);
  8670. /* If the expression is "local", then set up a "watchpoint scope"
  8671. breakpoint at the point where we've left the scope of the watchpoint
  8672. expression. Create the scope breakpoint before the watchpoint, so
  8673. that we will encounter it first in bpstat_stop_status. */
  8674. if (exp_valid_block != NULL && wp_frame != NULL)
  8675. {
  8676. frame_id caller_frame_id = frame_unwind_caller_id (wp_frame);
  8677. if (frame_id_p (caller_frame_id))
  8678. {
  8679. gdbarch *caller_arch = frame_unwind_caller_arch (wp_frame);
  8680. CORE_ADDR caller_pc = frame_unwind_caller_pc (wp_frame);
  8681. scope_breakpoint
  8682. = create_internal_breakpoint (caller_arch, caller_pc,
  8683. bp_watchpoint_scope,
  8684. &momentary_breakpoint_ops);
  8685. /* create_internal_breakpoint could invalidate WP_FRAME. */
  8686. wp_frame = NULL;
  8687. scope_breakpoint->enable_state = bp_enabled;
  8688. /* Automatically delete the breakpoint when it hits. */
  8689. scope_breakpoint->disposition = disp_del;
  8690. /* Only break in the proper frame (help with recursion). */
  8691. scope_breakpoint->frame_id = caller_frame_id;
  8692. /* Set the address at which we will stop. */
  8693. scope_breakpoint->loc->gdbarch = caller_arch;
  8694. scope_breakpoint->loc->requested_address = caller_pc;
  8695. scope_breakpoint->loc->address
  8696. = adjust_breakpoint_address (scope_breakpoint->loc->gdbarch,
  8697. scope_breakpoint->loc->requested_address,
  8698. scope_breakpoint->type);
  8699. }
  8700. }
  8701. /* Now set up the breakpoint. We create all watchpoints as hardware
  8702. watchpoints here even if hardware watchpoints are turned off, a call
  8703. to update_watchpoint later in this function will cause the type to
  8704. drop back to bp_watchpoint (software watchpoint) if required. */
  8705. if (accessflag == hw_read)
  8706. bp_type = bp_read_watchpoint;
  8707. else if (accessflag == hw_access)
  8708. bp_type = bp_access_watchpoint;
  8709. else
  8710. bp_type = bp_hardware_watchpoint;
  8711. std::unique_ptr<watchpoint> w (new watchpoint ());
  8712. if (use_mask)
  8713. init_raw_breakpoint_without_location (w.get (), NULL, bp_type,
  8714. &masked_watchpoint_breakpoint_ops);
  8715. else
  8716. init_raw_breakpoint_without_location (w.get (), NULL, bp_type,
  8717. &watchpoint_breakpoint_ops);
  8718. w->thread = thread;
  8719. w->task = task;
  8720. w->disposition = disp_donttouch;
  8721. w->pspace = current_program_space;
  8722. w->exp = std::move (exp);
  8723. w->exp_valid_block = exp_valid_block;
  8724. w->cond_exp_valid_block = cond_exp_valid_block;
  8725. if (just_location)
  8726. {
  8727. struct type *t = value_type (val.get ());
  8728. CORE_ADDR addr = value_as_address (val.get ());
  8729. w->exp_string_reparse
  8730. = current_language->watch_location_expression (t, addr);
  8731. w->exp_string = xstrprintf ("-location %.*s",
  8732. (int) (exp_end - exp_start), exp_start);
  8733. }
  8734. else
  8735. w->exp_string.reset (savestring (exp_start, exp_end - exp_start));
  8736. if (use_mask)
  8737. {
  8738. w->hw_wp_mask = mask;
  8739. }
  8740. else
  8741. {
  8742. w->val = val;
  8743. w->val_bitpos = saved_bitpos;
  8744. w->val_bitsize = saved_bitsize;
  8745. w->val_valid = true;
  8746. }
  8747. if (cond_start)
  8748. w->cond_string.reset (savestring (cond_start, cond_end - cond_start));
  8749. else
  8750. w->cond_string = 0;
  8751. if (frame_id_p (watchpoint_frame))
  8752. {
  8753. w->watchpoint_frame = watchpoint_frame;
  8754. w->watchpoint_thread = inferior_ptid;
  8755. }
  8756. else
  8757. {
  8758. w->watchpoint_frame = null_frame_id;
  8759. w->watchpoint_thread = null_ptid;
  8760. }
  8761. if (scope_breakpoint != NULL)
  8762. {
  8763. /* The scope breakpoint is related to the watchpoint. We will
  8764. need to act on them together. */
  8765. w->related_breakpoint = scope_breakpoint;
  8766. scope_breakpoint->related_breakpoint = w.get ();
  8767. }
  8768. if (!just_location)
  8769. value_free_to_mark (mark);
  8770. /* Finally update the new watchpoint. This creates the locations
  8771. that should be inserted. */
  8772. update_watchpoint (w.get (), 1);
  8773. install_breakpoint (internal, std::move (w), 1);
  8774. }
  8775. /* Return count of debug registers needed to watch the given expression.
  8776. If the watchpoint cannot be handled in hardware return zero. */
  8777. static int
  8778. can_use_hardware_watchpoint (const std::vector<value_ref_ptr> &vals)
  8779. {
  8780. int found_memory_cnt = 0;
  8781. /* Did the user specifically forbid us to use hardware watchpoints? */
  8782. if (!can_use_hw_watchpoints)
  8783. return 0;
  8784. gdb_assert (!vals.empty ());
  8785. struct value *head = vals[0].get ();
  8786. /* Make sure that the value of the expression depends only upon
  8787. memory contents, and values computed from them within GDB. If we
  8788. find any register references or function calls, we can't use a
  8789. hardware watchpoint.
  8790. The idea here is that evaluating an expression generates a series
  8791. of values, one holding the value of every subexpression. (The
  8792. expression a*b+c has five subexpressions: a, b, a*b, c, and
  8793. a*b+c.) GDB's values hold almost enough information to establish
  8794. the criteria given above --- they identify memory lvalues,
  8795. register lvalues, computed values, etcetera. So we can evaluate
  8796. the expression, and then scan the chain of values that leaves
  8797. behind to decide whether we can detect any possible change to the
  8798. expression's final value using only hardware watchpoints.
  8799. However, I don't think that the values returned by inferior
  8800. function calls are special in any way. So this function may not
  8801. notice that an expression involving an inferior function call
  8802. can't be watched with hardware watchpoints. FIXME. */
  8803. for (const value_ref_ptr &iter : vals)
  8804. {
  8805. struct value *v = iter.get ();
  8806. if (VALUE_LVAL (v) == lval_memory)
  8807. {
  8808. if (v != head && value_lazy (v))
  8809. /* A lazy memory lvalue in the chain is one that GDB never
  8810. needed to fetch; we either just used its address (e.g.,
  8811. `a' in `a.b') or we never needed it at all (e.g., `a'
  8812. in `a,b'). This doesn't apply to HEAD; if that is
  8813. lazy then it was not readable, but watch it anyway. */
  8814. ;
  8815. else
  8816. {
  8817. /* Ahh, memory we actually used! Check if we can cover
  8818. it with hardware watchpoints. */
  8819. struct type *vtype = check_typedef (value_type (v));
  8820. /* We only watch structs and arrays if user asked for it
  8821. explicitly, never if they just happen to appear in a
  8822. middle of some value chain. */
  8823. if (v == head
  8824. || (vtype->code () != TYPE_CODE_STRUCT
  8825. && vtype->code () != TYPE_CODE_ARRAY))
  8826. {
  8827. CORE_ADDR vaddr = value_address (v);
  8828. int len;
  8829. int num_regs;
  8830. len = (target_exact_watchpoints
  8831. && is_scalar_type_recursive (vtype))?
  8832. 1 : TYPE_LENGTH (value_type (v));
  8833. num_regs = target_region_ok_for_hw_watchpoint (vaddr, len);
  8834. if (!num_regs)
  8835. return 0;
  8836. else
  8837. found_memory_cnt += num_regs;
  8838. }
  8839. }
  8840. }
  8841. else if (VALUE_LVAL (v) != not_lval
  8842. && deprecated_value_modifiable (v) == 0)
  8843. return 0; /* These are values from the history (e.g., $1). */
  8844. else if (VALUE_LVAL (v) == lval_register)
  8845. return 0; /* Cannot watch a register with a HW watchpoint. */
  8846. }
  8847. /* The expression itself looks suitable for using a hardware
  8848. watchpoint, but give the target machine a chance to reject it. */
  8849. return found_memory_cnt;
  8850. }
  8851. void
  8852. watch_command_wrapper (const char *arg, int from_tty, bool internal)
  8853. {
  8854. watch_command_1 (arg, hw_write, from_tty, 0, internal);
  8855. }
  8856. /* Options for the watch, awatch, and rwatch commands. */
  8857. struct watch_options
  8858. {
  8859. /* For -location. */
  8860. bool location = false;
  8861. };
  8862. /* Definitions of options for the "watch", "awatch", and "rwatch" commands.
  8863. Historically GDB always accepted both '-location' and '-l' flags for
  8864. these commands (both flags being synonyms). When converting to the
  8865. newer option scheme only '-location' is added here. That's fine (for
  8866. backward compatibility) as any non-ambiguous prefix of a flag will be
  8867. accepted, so '-l', '-loc', are now all accepted.
  8868. What this means is that, if in the future, we add any new flag here
  8869. that starts with '-l' then this will break backward compatibility, so
  8870. please, don't do that! */
  8871. static const gdb::option::option_def watch_option_defs[] = {
  8872. gdb::option::flag_option_def<watch_options> {
  8873. "location",
  8874. [] (watch_options *opt) { return &opt->location; },
  8875. N_("\
  8876. This evaluates EXPRESSION and watches the memory to which is refers.\n\
  8877. -l can be used as a short form of -location."),
  8878. },
  8879. };
  8880. /* Returns the option group used by 'watch', 'awatch', and 'rwatch'
  8881. commands. */
  8882. static gdb::option::option_def_group
  8883. make_watch_options_def_group (watch_options *opts)
  8884. {
  8885. return {{watch_option_defs}, opts};
  8886. }
  8887. /* A helper function that looks for the "-location" argument and then
  8888. calls watch_command_1. */
  8889. static void
  8890. watch_maybe_just_location (const char *arg, int accessflag, int from_tty)
  8891. {
  8892. watch_options opts;
  8893. auto grp = make_watch_options_def_group (&opts);
  8894. gdb::option::process_options
  8895. (&arg, gdb::option::PROCESS_OPTIONS_UNKNOWN_IS_OPERAND, grp);
  8896. if (arg != nullptr && *arg == '\0')
  8897. arg = nullptr;
  8898. watch_command_1 (arg, accessflag, from_tty, opts.location, false);
  8899. }
  8900. /* Command completion for 'watch', 'awatch', and 'rwatch' commands. */
  8901. static void
  8902. watch_command_completer (struct cmd_list_element *ignore,
  8903. completion_tracker &tracker,
  8904. const char *text, const char * /*word*/)
  8905. {
  8906. const auto group = make_watch_options_def_group (nullptr);
  8907. if (gdb::option::complete_options
  8908. (tracker, &text, gdb::option::PROCESS_OPTIONS_UNKNOWN_IS_OPERAND, group))
  8909. return;
  8910. const char *word = advance_to_expression_complete_word_point (tracker, text);
  8911. expression_completer (ignore, tracker, text, word);
  8912. }
  8913. static void
  8914. watch_command (const char *arg, int from_tty)
  8915. {
  8916. watch_maybe_just_location (arg, hw_write, from_tty);
  8917. }
  8918. void
  8919. rwatch_command_wrapper (const char *arg, int from_tty, bool internal)
  8920. {
  8921. watch_command_1 (arg, hw_read, from_tty, 0, internal);
  8922. }
  8923. static void
  8924. rwatch_command (const char *arg, int from_tty)
  8925. {
  8926. watch_maybe_just_location (arg, hw_read, from_tty);
  8927. }
  8928. void
  8929. awatch_command_wrapper (const char *arg, int from_tty, bool internal)
  8930. {
  8931. watch_command_1 (arg, hw_access, from_tty, 0, internal);
  8932. }
  8933. static void
  8934. awatch_command (const char *arg, int from_tty)
  8935. {
  8936. watch_maybe_just_location (arg, hw_access, from_tty);
  8937. }
  8938. /* Data for the FSM that manages the until(location)/advance commands
  8939. in infcmd.c. Here because it uses the mechanisms of
  8940. breakpoints. */
  8941. struct until_break_fsm : public thread_fsm
  8942. {
  8943. /* The thread that was current when the command was executed. */
  8944. int thread;
  8945. /* The breakpoint set at the return address in the caller frame,
  8946. plus breakpoints at all the destination locations. */
  8947. std::vector<breakpoint_up> breakpoints;
  8948. until_break_fsm (struct interp *cmd_interp, int thread,
  8949. std::vector<breakpoint_up> &&breakpoints)
  8950. : thread_fsm (cmd_interp),
  8951. thread (thread),
  8952. breakpoints (std::move (breakpoints))
  8953. {
  8954. }
  8955. void clean_up (struct thread_info *thread) override;
  8956. bool should_stop (struct thread_info *thread) override;
  8957. enum async_reply_reason do_async_reply_reason () override;
  8958. };
  8959. /* Implementation of the 'should_stop' FSM method for the
  8960. until(location)/advance commands. */
  8961. bool
  8962. until_break_fsm::should_stop (struct thread_info *tp)
  8963. {
  8964. for (const breakpoint_up &bp : breakpoints)
  8965. if (bpstat_find_breakpoint (tp->control.stop_bpstat,
  8966. bp.get ()) != NULL)
  8967. {
  8968. set_finished ();
  8969. break;
  8970. }
  8971. return true;
  8972. }
  8973. /* Implementation of the 'clean_up' FSM method for the
  8974. until(location)/advance commands. */
  8975. void
  8976. until_break_fsm::clean_up (struct thread_info *)
  8977. {
  8978. /* Clean up our temporary breakpoints. */
  8979. breakpoints.clear ();
  8980. delete_longjmp_breakpoint (thread);
  8981. }
  8982. /* Implementation of the 'async_reply_reason' FSM method for the
  8983. until(location)/advance commands. */
  8984. enum async_reply_reason
  8985. until_break_fsm::do_async_reply_reason ()
  8986. {
  8987. return EXEC_ASYNC_LOCATION_REACHED;
  8988. }
  8989. void
  8990. until_break_command (const char *arg, int from_tty, int anywhere)
  8991. {
  8992. struct frame_info *frame;
  8993. struct gdbarch *frame_gdbarch;
  8994. struct frame_id stack_frame_id;
  8995. struct frame_id caller_frame_id;
  8996. int thread;
  8997. struct thread_info *tp;
  8998. clear_proceed_status (0);
  8999. /* Set a breakpoint where the user wants it and at return from
  9000. this function. */
  9001. event_location_up location = string_to_event_location (&arg, current_language);
  9002. std::vector<symtab_and_line> sals
  9003. = (last_displayed_sal_is_valid ()
  9004. ? decode_line_1 (location.get (), DECODE_LINE_FUNFIRSTLINE, NULL,
  9005. get_last_displayed_symtab (),
  9006. get_last_displayed_line ())
  9007. : decode_line_1 (location.get (), DECODE_LINE_FUNFIRSTLINE,
  9008. NULL, NULL, 0));
  9009. if (sals.empty ())
  9010. error (_("Couldn't get information on specified line."));
  9011. if (*arg)
  9012. error (_("Junk at end of arguments."));
  9013. tp = inferior_thread ();
  9014. thread = tp->global_num;
  9015. /* Note linespec handling above invalidates the frame chain.
  9016. Installing a breakpoint also invalidates the frame chain (as it
  9017. may need to switch threads), so do any frame handling before
  9018. that. */
  9019. frame = get_selected_frame (NULL);
  9020. frame_gdbarch = get_frame_arch (frame);
  9021. stack_frame_id = get_stack_frame_id (frame);
  9022. caller_frame_id = frame_unwind_caller_id (frame);
  9023. /* Keep within the current frame, or in frames called by the current
  9024. one. */
  9025. std::vector<breakpoint_up> breakpoints;
  9026. gdb::optional<delete_longjmp_breakpoint_cleanup> lj_deleter;
  9027. if (frame_id_p (caller_frame_id))
  9028. {
  9029. struct symtab_and_line sal2;
  9030. struct gdbarch *caller_gdbarch;
  9031. sal2 = find_pc_line (frame_unwind_caller_pc (frame), 0);
  9032. sal2.pc = frame_unwind_caller_pc (frame);
  9033. caller_gdbarch = frame_unwind_caller_arch (frame);
  9034. breakpoint_up caller_breakpoint
  9035. = set_momentary_breakpoint (caller_gdbarch, sal2,
  9036. caller_frame_id, bp_until);
  9037. breakpoints.emplace_back (std::move (caller_breakpoint));
  9038. set_longjmp_breakpoint (tp, caller_frame_id);
  9039. lj_deleter.emplace (thread);
  9040. }
  9041. /* set_momentary_breakpoint could invalidate FRAME. */
  9042. frame = NULL;
  9043. /* If the user told us to continue until a specified location, we
  9044. don't specify a frame at which we need to stop. Otherwise,
  9045. specify the selected frame, because we want to stop only at the
  9046. very same frame. */
  9047. frame_id stop_frame_id = anywhere ? null_frame_id : stack_frame_id;
  9048. for (symtab_and_line &sal : sals)
  9049. {
  9050. resolve_sal_pc (&sal);
  9051. breakpoint_up location_breakpoint
  9052. = set_momentary_breakpoint (frame_gdbarch, sal,
  9053. stop_frame_id, bp_until);
  9054. breakpoints.emplace_back (std::move (location_breakpoint));
  9055. }
  9056. tp->set_thread_fsm
  9057. (std::unique_ptr<thread_fsm>
  9058. (new until_break_fsm (command_interp (), tp->global_num,
  9059. std::move (breakpoints))));
  9060. if (lj_deleter)
  9061. lj_deleter->release ();
  9062. proceed (-1, GDB_SIGNAL_DEFAULT);
  9063. }
  9064. void
  9065. init_ada_exception_breakpoint (struct breakpoint *b,
  9066. struct gdbarch *gdbarch,
  9067. struct symtab_and_line sal,
  9068. const char *addr_string,
  9069. const struct breakpoint_ops *ops,
  9070. int tempflag,
  9071. int enabled,
  9072. int from_tty)
  9073. {
  9074. if (from_tty)
  9075. {
  9076. struct gdbarch *loc_gdbarch = get_sal_arch (sal);
  9077. if (!loc_gdbarch)
  9078. loc_gdbarch = gdbarch;
  9079. describe_other_breakpoints (loc_gdbarch,
  9080. sal.pspace, sal.pc, sal.section, -1);
  9081. /* FIXME: brobecker/2006-12-28: Actually, re-implement a special
  9082. version for exception catchpoints, because two catchpoints
  9083. used for different exception names will use the same address.
  9084. In this case, a "breakpoint ... also set at..." warning is
  9085. unproductive. Besides, the warning phrasing is also a bit
  9086. inappropriate, we should use the word catchpoint, and tell
  9087. the user what type of catchpoint it is. The above is good
  9088. enough for now, though. */
  9089. }
  9090. init_raw_breakpoint (b, gdbarch, sal, bp_catchpoint, ops);
  9091. b->enable_state = enabled ? bp_enabled : bp_disabled;
  9092. b->disposition = tempflag ? disp_del : disp_donttouch;
  9093. b->location = string_to_event_location (&addr_string,
  9094. language_def (language_ada));
  9095. b->language = language_ada;
  9096. }
  9097. /* Compare two breakpoints and return a strcmp-like result. */
  9098. static int
  9099. compare_breakpoints (const breakpoint *a, const breakpoint *b)
  9100. {
  9101. uintptr_t ua = (uintptr_t) a;
  9102. uintptr_t ub = (uintptr_t) b;
  9103. if (a->number < b->number)
  9104. return -1;
  9105. else if (a->number > b->number)
  9106. return 1;
  9107. /* Now sort by address, in case we see, e..g, two breakpoints with
  9108. the number 0. */
  9109. if (ua < ub)
  9110. return -1;
  9111. return ua > ub ? 1 : 0;
  9112. }
  9113. /* Delete breakpoints by address or line. */
  9114. static void
  9115. clear_command (const char *arg, int from_tty)
  9116. {
  9117. int default_match;
  9118. std::vector<symtab_and_line> decoded_sals;
  9119. symtab_and_line last_sal;
  9120. gdb::array_view<symtab_and_line> sals;
  9121. if (arg)
  9122. {
  9123. decoded_sals
  9124. = decode_line_with_current_source (arg,
  9125. (DECODE_LINE_FUNFIRSTLINE
  9126. | DECODE_LINE_LIST_MODE));
  9127. default_match = 0;
  9128. sals = decoded_sals;
  9129. }
  9130. else
  9131. {
  9132. /* Set sal's line, symtab, pc, and pspace to the values
  9133. corresponding to the last call to print_frame_info. If the
  9134. codepoint is not valid, this will set all the fields to 0. */
  9135. last_sal = get_last_displayed_sal ();
  9136. if (last_sal.symtab == 0)
  9137. error (_("No source file specified."));
  9138. default_match = 1;
  9139. sals = last_sal;
  9140. }
  9141. /* We don't call resolve_sal_pc here. That's not as bad as it
  9142. seems, because all existing breakpoints typically have both
  9143. file/line and pc set. So, if clear is given file/line, we can
  9144. match this to existing breakpoint without obtaining pc at all.
  9145. We only support clearing given the address explicitly
  9146. present in breakpoint table. Say, we've set breakpoint
  9147. at file:line. There were several PC values for that file:line,
  9148. due to optimization, all in one block.
  9149. We've picked one PC value. If "clear" is issued with another
  9150. PC corresponding to the same file:line, the breakpoint won't
  9151. be cleared. We probably can still clear the breakpoint, but
  9152. since the other PC value is never presented to user, user
  9153. can only find it by guessing, and it does not seem important
  9154. to support that. */
  9155. /* For each line spec given, delete bps which correspond to it. Do
  9156. it in two passes, solely to preserve the current behavior that
  9157. from_tty is forced true if we delete more than one
  9158. breakpoint. */
  9159. std::vector<struct breakpoint *> found;
  9160. for (const auto &sal : sals)
  9161. {
  9162. const char *sal_fullname;
  9163. /* If exact pc given, clear bpts at that pc.
  9164. If line given (pc == 0), clear all bpts on specified line.
  9165. If defaulting, clear all bpts on default line
  9166. or at default pc.
  9167. defaulting sal.pc != 0 tests to do
  9168. 0 1 pc
  9169. 1 1 pc _and_ line
  9170. 0 0 line
  9171. 1 0 <can't happen> */
  9172. sal_fullname = (sal.symtab == NULL
  9173. ? NULL : symtab_to_fullname (sal.symtab));
  9174. /* Find all matching breakpoints and add them to 'found'. */
  9175. for (breakpoint *b : all_breakpoints ())
  9176. {
  9177. int match = 0;
  9178. /* Are we going to delete b? */
  9179. if (b->type != bp_none && !is_watchpoint (b))
  9180. {
  9181. for (bp_location *loc : b->locations ())
  9182. {
  9183. /* If the user specified file:line, don't allow a PC
  9184. match. This matches historical gdb behavior. */
  9185. int pc_match = (!sal.explicit_line
  9186. && sal.pc
  9187. && (loc->pspace == sal.pspace)
  9188. && (loc->address == sal.pc)
  9189. && (!section_is_overlay (loc->section)
  9190. || loc->section == sal.section));
  9191. int line_match = 0;
  9192. if ((default_match || sal.explicit_line)
  9193. && loc->symtab != NULL
  9194. && sal_fullname != NULL
  9195. && sal.pspace == loc->pspace
  9196. && loc->line_number == sal.line
  9197. && filename_cmp (symtab_to_fullname (loc->symtab),
  9198. sal_fullname) == 0)
  9199. line_match = 1;
  9200. if (pc_match || line_match)
  9201. {
  9202. match = 1;
  9203. break;
  9204. }
  9205. }
  9206. }
  9207. if (match)
  9208. found.push_back (b);
  9209. }
  9210. }
  9211. /* Now go thru the 'found' chain and delete them. */
  9212. if (found.empty ())
  9213. {
  9214. if (arg)
  9215. error (_("No breakpoint at %s."), arg);
  9216. else
  9217. error (_("No breakpoint at this line."));
  9218. }
  9219. /* Remove duplicates from the vec. */
  9220. std::sort (found.begin (), found.end (),
  9221. [] (const breakpoint *bp_a, const breakpoint *bp_b)
  9222. {
  9223. return compare_breakpoints (bp_a, bp_b) < 0;
  9224. });
  9225. found.erase (std::unique (found.begin (), found.end (),
  9226. [] (const breakpoint *bp_a, const breakpoint *bp_b)
  9227. {
  9228. return compare_breakpoints (bp_a, bp_b) == 0;
  9229. }),
  9230. found.end ());
  9231. if (found.size () > 1)
  9232. from_tty = 1; /* Always report if deleted more than one. */
  9233. if (from_tty)
  9234. {
  9235. if (found.size () == 1)
  9236. gdb_printf (_("Deleted breakpoint "));
  9237. else
  9238. gdb_printf (_("Deleted breakpoints "));
  9239. }
  9240. for (breakpoint *iter : found)
  9241. {
  9242. if (from_tty)
  9243. gdb_printf ("%d ", iter->number);
  9244. delete_breakpoint (iter);
  9245. }
  9246. if (from_tty)
  9247. gdb_putc ('\n');
  9248. }
  9249. /* Delete breakpoint in BS if they are `delete' breakpoints and
  9250. all breakpoints that are marked for deletion, whether hit or not.
  9251. This is called after any breakpoint is hit, or after errors. */
  9252. void
  9253. breakpoint_auto_delete (bpstat *bs)
  9254. {
  9255. for (; bs; bs = bs->next)
  9256. if (bs->breakpoint_at
  9257. && bs->breakpoint_at->disposition == disp_del
  9258. && bs->stop)
  9259. delete_breakpoint (bs->breakpoint_at);
  9260. for (breakpoint *b : all_breakpoints_safe ())
  9261. if (b->disposition == disp_del_at_next_stop)
  9262. delete_breakpoint (b);
  9263. }
  9264. /* A comparison function for bp_location AP and BP being interfaced to
  9265. std::sort. Sort elements primarily by their ADDRESS (no matter what
  9266. bl_address_is_meaningful says), secondarily by ordering first
  9267. permanent elements and terciarily just ensuring the array is sorted
  9268. stable way despite std::sort being an unstable algorithm. */
  9269. static int
  9270. bp_location_is_less_than (const bp_location *a, const bp_location *b)
  9271. {
  9272. if (a->address != b->address)
  9273. return a->address < b->address;
  9274. /* Sort locations at the same address by their pspace number, keeping
  9275. locations of the same inferior (in a multi-inferior environment)
  9276. grouped. */
  9277. if (a->pspace->num != b->pspace->num)
  9278. return a->pspace->num < b->pspace->num;
  9279. /* Sort permanent breakpoints first. */
  9280. if (a->permanent != b->permanent)
  9281. return a->permanent > b->permanent;
  9282. /* Sort by type in order to make duplicate determination easier.
  9283. See update_global_location_list. This is kept in sync with
  9284. breakpoint_locations_match. */
  9285. if (a->loc_type < b->loc_type)
  9286. return true;
  9287. /* Likewise, for range-breakpoints, sort by length. */
  9288. if (a->loc_type == bp_loc_hardware_breakpoint
  9289. && b->loc_type == bp_loc_hardware_breakpoint
  9290. && a->length < b->length)
  9291. return true;
  9292. /* Make the internal GDB representation stable across GDB runs
  9293. where A and B memory inside GDB can differ. Breakpoint locations of
  9294. the same type at the same address can be sorted in arbitrary order. */
  9295. if (a->owner->number != b->owner->number)
  9296. return a->owner->number < b->owner->number;
  9297. return a < b;
  9298. }
  9299. /* Set bp_locations_placed_address_before_address_max and
  9300. bp_locations_shadow_len_after_address_max according to the current
  9301. content of the bp_locations array. */
  9302. static void
  9303. bp_locations_target_extensions_update (void)
  9304. {
  9305. bp_locations_placed_address_before_address_max = 0;
  9306. bp_locations_shadow_len_after_address_max = 0;
  9307. for (bp_location *bl : all_bp_locations ())
  9308. {
  9309. CORE_ADDR start, end, addr;
  9310. if (!bp_location_has_shadow (bl))
  9311. continue;
  9312. start = bl->target_info.placed_address;
  9313. end = start + bl->target_info.shadow_len;
  9314. gdb_assert (bl->address >= start);
  9315. addr = bl->address - start;
  9316. if (addr > bp_locations_placed_address_before_address_max)
  9317. bp_locations_placed_address_before_address_max = addr;
  9318. /* Zero SHADOW_LEN would not pass bp_location_has_shadow. */
  9319. gdb_assert (bl->address < end);
  9320. addr = end - bl->address;
  9321. if (addr > bp_locations_shadow_len_after_address_max)
  9322. bp_locations_shadow_len_after_address_max = addr;
  9323. }
  9324. }
  9325. /* Download tracepoint locations if they haven't been. */
  9326. static void
  9327. download_tracepoint_locations (void)
  9328. {
  9329. enum tribool can_download_tracepoint = TRIBOOL_UNKNOWN;
  9330. scoped_restore_current_pspace_and_thread restore_pspace_thread;
  9331. for (breakpoint *b : all_tracepoints ())
  9332. {
  9333. struct tracepoint *t;
  9334. int bp_location_downloaded = 0;
  9335. if ((b->type == bp_fast_tracepoint
  9336. ? !may_insert_fast_tracepoints
  9337. : !may_insert_tracepoints))
  9338. continue;
  9339. if (can_download_tracepoint == TRIBOOL_UNKNOWN)
  9340. {
  9341. if (target_can_download_tracepoint ())
  9342. can_download_tracepoint = TRIBOOL_TRUE;
  9343. else
  9344. can_download_tracepoint = TRIBOOL_FALSE;
  9345. }
  9346. if (can_download_tracepoint == TRIBOOL_FALSE)
  9347. break;
  9348. for (bp_location *bl : b->locations ())
  9349. {
  9350. /* In tracepoint, locations are _never_ duplicated, so
  9351. should_be_inserted is equivalent to
  9352. unduplicated_should_be_inserted. */
  9353. if (!should_be_inserted (bl) || bl->inserted)
  9354. continue;
  9355. switch_to_program_space_and_thread (bl->pspace);
  9356. target_download_tracepoint (bl);
  9357. bl->inserted = 1;
  9358. bp_location_downloaded = 1;
  9359. }
  9360. t = (struct tracepoint *) b;
  9361. t->number_on_target = b->number;
  9362. if (bp_location_downloaded)
  9363. gdb::observers::breakpoint_modified.notify (b);
  9364. }
  9365. }
  9366. /* Swap the insertion/duplication state between two locations. */
  9367. static void
  9368. swap_insertion (struct bp_location *left, struct bp_location *right)
  9369. {
  9370. const int left_inserted = left->inserted;
  9371. const int left_duplicate = left->duplicate;
  9372. const int left_needs_update = left->needs_update;
  9373. const struct bp_target_info left_target_info = left->target_info;
  9374. /* Locations of tracepoints can never be duplicated. */
  9375. if (is_tracepoint (left->owner))
  9376. gdb_assert (!left->duplicate);
  9377. if (is_tracepoint (right->owner))
  9378. gdb_assert (!right->duplicate);
  9379. left->inserted = right->inserted;
  9380. left->duplicate = right->duplicate;
  9381. left->needs_update = right->needs_update;
  9382. left->target_info = right->target_info;
  9383. right->inserted = left_inserted;
  9384. right->duplicate = left_duplicate;
  9385. right->needs_update = left_needs_update;
  9386. right->target_info = left_target_info;
  9387. }
  9388. /* Force the re-insertion of the locations at ADDRESS. This is called
  9389. once a new/deleted/modified duplicate location is found and we are evaluating
  9390. conditions on the target's side. Such conditions need to be updated on
  9391. the target. */
  9392. static void
  9393. force_breakpoint_reinsertion (struct bp_location *bl)
  9394. {
  9395. CORE_ADDR address = 0;
  9396. int pspace_num;
  9397. address = bl->address;
  9398. pspace_num = bl->pspace->num;
  9399. /* This is only meaningful if the target is
  9400. evaluating conditions and if the user has
  9401. opted for condition evaluation on the target's
  9402. side. */
  9403. if (gdb_evaluates_breakpoint_condition_p ()
  9404. || !target_supports_evaluation_of_breakpoint_conditions ())
  9405. return;
  9406. /* Flag all breakpoint locations with this address and
  9407. the same program space as the location
  9408. as "its condition has changed". We need to
  9409. update the conditions on the target's side. */
  9410. for (bp_location *loc : all_bp_locations_at_addr (address))
  9411. {
  9412. if (!is_breakpoint (loc->owner)
  9413. || pspace_num != loc->pspace->num)
  9414. continue;
  9415. /* Flag the location appropriately. We use a different state to
  9416. let everyone know that we already updated the set of locations
  9417. with addr bl->address and program space bl->pspace. This is so
  9418. we don't have to keep calling these functions just to mark locations
  9419. that have already been marked. */
  9420. loc->condition_changed = condition_updated;
  9421. /* Free the agent expression bytecode as well. We will compute
  9422. it later on. */
  9423. loc->cond_bytecode.reset ();
  9424. }
  9425. }
  9426. /* Called whether new breakpoints are created, or existing breakpoints
  9427. deleted, to update the global location list and recompute which
  9428. locations are duplicate of which.
  9429. The INSERT_MODE flag determines whether locations may not, may, or
  9430. shall be inserted now. See 'enum ugll_insert_mode' for more
  9431. info. */
  9432. static void
  9433. update_global_location_list (enum ugll_insert_mode insert_mode)
  9434. {
  9435. /* Last breakpoint location address that was marked for update. */
  9436. CORE_ADDR last_addr = 0;
  9437. /* Last breakpoint location program space that was marked for update. */
  9438. int last_pspace_num = -1;
  9439. /* Used in the duplicates detection below. When iterating over all
  9440. bp_locations, points to the first bp_location of a given address.
  9441. Breakpoints and watchpoints of different types are never
  9442. duplicates of each other. Keep one pointer for each type of
  9443. breakpoint/watchpoint, so we only need to loop over all locations
  9444. once. */
  9445. struct bp_location *bp_loc_first; /* breakpoint */
  9446. struct bp_location *wp_loc_first; /* hardware watchpoint */
  9447. struct bp_location *awp_loc_first; /* access watchpoint */
  9448. struct bp_location *rwp_loc_first; /* read watchpoint */
  9449. /* Saved former bp_locations array which we compare against the newly
  9450. built bp_locations from the current state of ALL_BREAKPOINTS. */
  9451. std::vector<bp_location *> old_locations = std::move (bp_locations);
  9452. bp_locations.clear ();
  9453. for (breakpoint *b : all_breakpoints ())
  9454. for (bp_location *loc : b->locations ())
  9455. bp_locations.push_back (loc);
  9456. /* See if we need to "upgrade" a software breakpoint to a hardware
  9457. breakpoint. Do this before deciding whether locations are
  9458. duplicates. Also do this before sorting because sorting order
  9459. depends on location type. */
  9460. for (bp_location *loc : bp_locations)
  9461. if (!loc->inserted && should_be_inserted (loc))
  9462. handle_automatic_hardware_breakpoints (loc);
  9463. std::sort (bp_locations.begin (), bp_locations.end (),
  9464. bp_location_is_less_than);
  9465. bp_locations_target_extensions_update ();
  9466. /* Identify bp_location instances that are no longer present in the
  9467. new list, and therefore should be freed. Note that it's not
  9468. necessary that those locations should be removed from inferior --
  9469. if there's another location at the same address (previously
  9470. marked as duplicate), we don't need to remove/insert the
  9471. location.
  9472. LOCP is kept in sync with OLD_LOCP, each pointing to the current
  9473. and former bp_location array state respectively. */
  9474. size_t loc_i = 0;
  9475. for (bp_location *old_loc : old_locations)
  9476. {
  9477. /* Tells if 'old_loc' is found among the new locations. If
  9478. not, we have to free it. */
  9479. int found_object = 0;
  9480. /* Tells if the location should remain inserted in the target. */
  9481. int keep_in_target = 0;
  9482. int removed = 0;
  9483. /* Skip LOCP entries which will definitely never be needed.
  9484. Stop either at or being the one matching OLD_LOC. */
  9485. while (loc_i < bp_locations.size ()
  9486. && bp_locations[loc_i]->address < old_loc->address)
  9487. loc_i++;
  9488. for (size_t loc2_i = loc_i;
  9489. (loc2_i < bp_locations.size ()
  9490. && bp_locations[loc2_i]->address == old_loc->address);
  9491. loc2_i++)
  9492. {
  9493. /* Check if this is a new/duplicated location or a duplicated
  9494. location that had its condition modified. If so, we want to send
  9495. its condition to the target if evaluation of conditions is taking
  9496. place there. */
  9497. if (bp_locations[loc2_i]->condition_changed == condition_modified
  9498. && (last_addr != old_loc->address
  9499. || last_pspace_num != old_loc->pspace->num))
  9500. {
  9501. force_breakpoint_reinsertion (bp_locations[loc2_i]);
  9502. last_pspace_num = old_loc->pspace->num;
  9503. }
  9504. if (bp_locations[loc2_i] == old_loc)
  9505. found_object = 1;
  9506. }
  9507. /* We have already handled this address, update it so that we don't
  9508. have to go through updates again. */
  9509. last_addr = old_loc->address;
  9510. /* Target-side condition evaluation: Handle deleted locations. */
  9511. if (!found_object)
  9512. force_breakpoint_reinsertion (old_loc);
  9513. /* If this location is no longer present, and inserted, look if
  9514. there's maybe a new location at the same address. If so,
  9515. mark that one inserted, and don't remove this one. This is
  9516. needed so that we don't have a time window where a breakpoint
  9517. at certain location is not inserted. */
  9518. if (old_loc->inserted)
  9519. {
  9520. /* If the location is inserted now, we might have to remove
  9521. it. */
  9522. if (found_object && should_be_inserted (old_loc))
  9523. {
  9524. /* The location is still present in the location list,
  9525. and still should be inserted. Don't do anything. */
  9526. keep_in_target = 1;
  9527. }
  9528. else
  9529. {
  9530. /* This location still exists, but it won't be kept in the
  9531. target since it may have been disabled. We proceed to
  9532. remove its target-side condition. */
  9533. /* The location is either no longer present, or got
  9534. disabled. See if there's another location at the
  9535. same address, in which case we don't need to remove
  9536. this one from the target. */
  9537. /* OLD_LOC comes from existing struct breakpoint. */
  9538. if (bl_address_is_meaningful (old_loc))
  9539. {
  9540. for (size_t loc2_i = loc_i;
  9541. (loc2_i < bp_locations.size ()
  9542. && bp_locations[loc2_i]->address == old_loc->address);
  9543. loc2_i++)
  9544. {
  9545. bp_location *loc2 = bp_locations[loc2_i];
  9546. if (loc2 == old_loc)
  9547. continue;
  9548. if (breakpoint_locations_match (loc2, old_loc))
  9549. {
  9550. /* Read watchpoint locations are switched to
  9551. access watchpoints, if the former are not
  9552. supported, but the latter are. */
  9553. if (is_hardware_watchpoint (old_loc->owner))
  9554. {
  9555. gdb_assert (is_hardware_watchpoint (loc2->owner));
  9556. loc2->watchpoint_type = old_loc->watchpoint_type;
  9557. }
  9558. /* loc2 is a duplicated location. We need to check
  9559. if it should be inserted in case it will be
  9560. unduplicated. */
  9561. if (unduplicated_should_be_inserted (loc2))
  9562. {
  9563. swap_insertion (old_loc, loc2);
  9564. keep_in_target = 1;
  9565. break;
  9566. }
  9567. }
  9568. }
  9569. }
  9570. }
  9571. if (!keep_in_target)
  9572. {
  9573. if (remove_breakpoint (old_loc))
  9574. {
  9575. /* This is just about all we can do. We could keep
  9576. this location on the global list, and try to
  9577. remove it next time, but there's no particular
  9578. reason why we will succeed next time.
  9579. Note that at this point, old_loc->owner is still
  9580. valid, as delete_breakpoint frees the breakpoint
  9581. only after calling us. */
  9582. gdb_printf (_("warning: Error removing "
  9583. "breakpoint %d\n"),
  9584. old_loc->owner->number);
  9585. }
  9586. removed = 1;
  9587. }
  9588. }
  9589. if (!found_object)
  9590. {
  9591. if (removed && target_is_non_stop_p ()
  9592. && need_moribund_for_location_type (old_loc))
  9593. {
  9594. /* This location was removed from the target. In
  9595. non-stop mode, a race condition is possible where
  9596. we've removed a breakpoint, but stop events for that
  9597. breakpoint are already queued and will arrive later.
  9598. We apply an heuristic to be able to distinguish such
  9599. SIGTRAPs from other random SIGTRAPs: we keep this
  9600. breakpoint location for a bit, and will retire it
  9601. after we see some number of events. The theory here
  9602. is that reporting of events should, "on the average",
  9603. be fair, so after a while we'll see events from all
  9604. threads that have anything of interest, and no longer
  9605. need to keep this breakpoint location around. We
  9606. don't hold locations forever so to reduce chances of
  9607. mistaking a non-breakpoint SIGTRAP for a breakpoint
  9608. SIGTRAP.
  9609. The heuristic failing can be disastrous on
  9610. decr_pc_after_break targets.
  9611. On decr_pc_after_break targets, like e.g., x86-linux,
  9612. if we fail to recognize a late breakpoint SIGTRAP,
  9613. because events_till_retirement has reached 0 too
  9614. soon, we'll fail to do the PC adjustment, and report
  9615. a random SIGTRAP to the user. When the user resumes
  9616. the inferior, it will most likely immediately crash
  9617. with SIGILL/SIGBUS/SIGSEGV, or worse, get silently
  9618. corrupted, because of being resumed e.g., in the
  9619. middle of a multi-byte instruction, or skipped a
  9620. one-byte instruction. This was actually seen happen
  9621. on native x86-linux, and should be less rare on
  9622. targets that do not support new thread events, like
  9623. remote, due to the heuristic depending on
  9624. thread_count.
  9625. Mistaking a random SIGTRAP for a breakpoint trap
  9626. causes similar symptoms (PC adjustment applied when
  9627. it shouldn't), but then again, playing with SIGTRAPs
  9628. behind the debugger's back is asking for trouble.
  9629. Since hardware watchpoint traps are always
  9630. distinguishable from other traps, so we don't need to
  9631. apply keep hardware watchpoint moribund locations
  9632. around. We simply always ignore hardware watchpoint
  9633. traps we can no longer explain. */
  9634. process_stratum_target *proc_target = nullptr;
  9635. for (inferior *inf : all_inferiors ())
  9636. if (inf->pspace == old_loc->pspace)
  9637. {
  9638. proc_target = inf->process_target ();
  9639. break;
  9640. }
  9641. if (proc_target != nullptr)
  9642. old_loc->events_till_retirement
  9643. = 3 * (thread_count (proc_target) + 1);
  9644. else
  9645. old_loc->events_till_retirement = 1;
  9646. old_loc->owner = NULL;
  9647. moribund_locations.push_back (old_loc);
  9648. }
  9649. else
  9650. {
  9651. old_loc->owner = NULL;
  9652. decref_bp_location (&old_loc);
  9653. }
  9654. }
  9655. }
  9656. /* Rescan breakpoints at the same address and section, marking the
  9657. first one as "first" and any others as "duplicates". This is so
  9658. that the bpt instruction is only inserted once. If we have a
  9659. permanent breakpoint at the same place as BPT, make that one the
  9660. official one, and the rest as duplicates. Permanent breakpoints
  9661. are sorted first for the same address.
  9662. Do the same for hardware watchpoints, but also considering the
  9663. watchpoint's type (regular/access/read) and length. */
  9664. bp_loc_first = NULL;
  9665. wp_loc_first = NULL;
  9666. awp_loc_first = NULL;
  9667. rwp_loc_first = NULL;
  9668. for (bp_location *loc : all_bp_locations ())
  9669. {
  9670. /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always
  9671. non-NULL. */
  9672. struct bp_location **loc_first_p;
  9673. breakpoint *b = loc->owner;
  9674. if (!unduplicated_should_be_inserted (loc)
  9675. || !bl_address_is_meaningful (loc)
  9676. /* Don't detect duplicate for tracepoint locations because they are
  9677. never duplicated. See the comments in field `duplicate' of
  9678. `struct bp_location'. */
  9679. || is_tracepoint (b))
  9680. {
  9681. /* Clear the condition modification flag. */
  9682. loc->condition_changed = condition_unchanged;
  9683. continue;
  9684. }
  9685. if (b->type == bp_hardware_watchpoint)
  9686. loc_first_p = &wp_loc_first;
  9687. else if (b->type == bp_read_watchpoint)
  9688. loc_first_p = &rwp_loc_first;
  9689. else if (b->type == bp_access_watchpoint)
  9690. loc_first_p = &awp_loc_first;
  9691. else
  9692. loc_first_p = &bp_loc_first;
  9693. if (*loc_first_p == NULL
  9694. || (overlay_debugging && loc->section != (*loc_first_p)->section)
  9695. || !breakpoint_locations_match (loc, *loc_first_p))
  9696. {
  9697. *loc_first_p = loc;
  9698. loc->duplicate = 0;
  9699. if (is_breakpoint (loc->owner) && loc->condition_changed)
  9700. {
  9701. loc->needs_update = 1;
  9702. /* Clear the condition modification flag. */
  9703. loc->condition_changed = condition_unchanged;
  9704. }
  9705. continue;
  9706. }
  9707. /* This and the above ensure the invariant that the first location
  9708. is not duplicated, and is the inserted one.
  9709. All following are marked as duplicated, and are not inserted. */
  9710. if (loc->inserted)
  9711. swap_insertion (loc, *loc_first_p);
  9712. loc->duplicate = 1;
  9713. /* Clear the condition modification flag. */
  9714. loc->condition_changed = condition_unchanged;
  9715. }
  9716. if (insert_mode == UGLL_INSERT || breakpoints_should_be_inserted_now ())
  9717. {
  9718. if (insert_mode != UGLL_DONT_INSERT)
  9719. insert_breakpoint_locations ();
  9720. else
  9721. {
  9722. /* Even though the caller told us to not insert new
  9723. locations, we may still need to update conditions on the
  9724. target's side of breakpoints that were already inserted
  9725. if the target is evaluating breakpoint conditions. We
  9726. only update conditions for locations that are marked
  9727. "needs_update". */
  9728. update_inserted_breakpoint_locations ();
  9729. }
  9730. }
  9731. if (insert_mode != UGLL_DONT_INSERT)
  9732. download_tracepoint_locations ();
  9733. }
  9734. void
  9735. breakpoint_retire_moribund (void)
  9736. {
  9737. for (int ix = 0; ix < moribund_locations.size (); ++ix)
  9738. {
  9739. struct bp_location *loc = moribund_locations[ix];
  9740. if (--(loc->events_till_retirement) == 0)
  9741. {
  9742. decref_bp_location (&loc);
  9743. unordered_remove (moribund_locations, ix);
  9744. --ix;
  9745. }
  9746. }
  9747. }
  9748. static void
  9749. update_global_location_list_nothrow (enum ugll_insert_mode insert_mode)
  9750. {
  9751. try
  9752. {
  9753. update_global_location_list (insert_mode);
  9754. }
  9755. catch (const gdb_exception_error &e)
  9756. {
  9757. }
  9758. }
  9759. /* Clear BKP from a BPS. */
  9760. static void
  9761. bpstat_remove_bp_location (bpstat *bps, struct breakpoint *bpt)
  9762. {
  9763. bpstat *bs;
  9764. for (bs = bps; bs; bs = bs->next)
  9765. if (bs->breakpoint_at == bpt)
  9766. {
  9767. bs->breakpoint_at = NULL;
  9768. bs->old_val = NULL;
  9769. /* bs->commands will be freed later. */
  9770. }
  9771. }
  9772. /* Callback for iterate_over_threads. */
  9773. static int
  9774. bpstat_remove_breakpoint_callback (struct thread_info *th, void *data)
  9775. {
  9776. struct breakpoint *bpt = (struct breakpoint *) data;
  9777. bpstat_remove_bp_location (th->control.stop_bpstat, bpt);
  9778. return 0;
  9779. }
  9780. /* Helper for breakpoint and tracepoint breakpoint_ops->mention
  9781. callbacks. */
  9782. static void
  9783. say_where (struct breakpoint *b)
  9784. {
  9785. struct value_print_options opts;
  9786. get_user_print_options (&opts);
  9787. /* i18n: cagney/2005-02-11: Below needs to be merged into a
  9788. single string. */
  9789. if (b->loc == NULL)
  9790. {
  9791. /* For pending locations, the output differs slightly based
  9792. on b->extra_string. If this is non-NULL, it contains either
  9793. a condition or dprintf arguments. */
  9794. if (b->extra_string == NULL)
  9795. {
  9796. gdb_printf (_(" (%s) pending."),
  9797. event_location_to_string (b->location.get ()));
  9798. }
  9799. else if (b->type == bp_dprintf)
  9800. {
  9801. gdb_printf (_(" (%s,%s) pending."),
  9802. event_location_to_string (b->location.get ()),
  9803. b->extra_string.get ());
  9804. }
  9805. else
  9806. {
  9807. gdb_printf (_(" (%s %s) pending."),
  9808. event_location_to_string (b->location.get ()),
  9809. b->extra_string.get ());
  9810. }
  9811. }
  9812. else
  9813. {
  9814. if (opts.addressprint || b->loc->symtab == NULL)
  9815. gdb_printf (" at %ps",
  9816. styled_string (address_style.style (),
  9817. paddress (b->loc->gdbarch,
  9818. b->loc->address)));
  9819. if (b->loc->symtab != NULL)
  9820. {
  9821. /* If there is a single location, we can print the location
  9822. more nicely. */
  9823. if (b->loc->next == NULL)
  9824. {
  9825. const char *filename
  9826. = symtab_to_filename_for_display (b->loc->symtab);
  9827. gdb_printf (": file %ps, line %d.",
  9828. styled_string (file_name_style.style (),
  9829. filename),
  9830. b->loc->line_number);
  9831. }
  9832. else
  9833. /* This is not ideal, but each location may have a
  9834. different file name, and this at least reflects the
  9835. real situation somewhat. */
  9836. gdb_printf (": %s.",
  9837. event_location_to_string (b->location.get ()));
  9838. }
  9839. if (b->loc->next)
  9840. {
  9841. struct bp_location *loc = b->loc;
  9842. int n = 0;
  9843. for (; loc; loc = loc->next)
  9844. ++n;
  9845. gdb_printf (" (%d locations)", n);
  9846. }
  9847. }
  9848. }
  9849. /* See breakpoint.h. */
  9850. bp_location_range breakpoint::locations ()
  9851. {
  9852. return bp_location_range (this->loc);
  9853. }
  9854. static struct bp_location *
  9855. base_breakpoint_allocate_location (struct breakpoint *self)
  9856. {
  9857. return new bp_location (self);
  9858. }
  9859. static void
  9860. base_breakpoint_re_set (struct breakpoint *b)
  9861. {
  9862. /* Nothing to re-set. */
  9863. }
  9864. #define internal_error_pure_virtual_called() \
  9865. gdb_assert_not_reached ("pure virtual function called")
  9866. static int
  9867. base_breakpoint_insert_location (struct bp_location *bl)
  9868. {
  9869. internal_error_pure_virtual_called ();
  9870. }
  9871. static int
  9872. base_breakpoint_remove_location (struct bp_location *bl,
  9873. enum remove_bp_reason reason)
  9874. {
  9875. internal_error_pure_virtual_called ();
  9876. }
  9877. static int
  9878. base_breakpoint_breakpoint_hit (const struct bp_location *bl,
  9879. const address_space *aspace,
  9880. CORE_ADDR bp_addr,
  9881. const target_waitstatus &ws)
  9882. {
  9883. internal_error_pure_virtual_called ();
  9884. }
  9885. static void
  9886. base_breakpoint_check_status (bpstat *bs)
  9887. {
  9888. /* Always stop. */
  9889. }
  9890. /* A "works_in_software_mode" breakpoint_ops method that just internal
  9891. errors. */
  9892. static int
  9893. base_breakpoint_works_in_software_mode (const struct breakpoint *b)
  9894. {
  9895. internal_error_pure_virtual_called ();
  9896. }
  9897. /* A "resources_needed" breakpoint_ops method that just internal
  9898. errors. */
  9899. static int
  9900. base_breakpoint_resources_needed (const struct bp_location *bl)
  9901. {
  9902. internal_error_pure_virtual_called ();
  9903. }
  9904. static enum print_stop_action
  9905. base_breakpoint_print_it (bpstat *bs)
  9906. {
  9907. internal_error_pure_virtual_called ();
  9908. }
  9909. static void
  9910. base_breakpoint_print_one_detail (const struct breakpoint *self,
  9911. struct ui_out *uiout)
  9912. {
  9913. /* nothing */
  9914. }
  9915. static void
  9916. base_breakpoint_print_mention (struct breakpoint *b)
  9917. {
  9918. internal_error_pure_virtual_called ();
  9919. }
  9920. static void
  9921. base_breakpoint_print_recreate (struct breakpoint *b, struct ui_file *fp)
  9922. {
  9923. internal_error_pure_virtual_called ();
  9924. }
  9925. static void
  9926. base_breakpoint_create_sals_from_location
  9927. (struct event_location *location,
  9928. struct linespec_result *canonical,
  9929. enum bptype type_wanted)
  9930. {
  9931. internal_error_pure_virtual_called ();
  9932. }
  9933. static void
  9934. base_breakpoint_create_breakpoints_sal (struct gdbarch *gdbarch,
  9935. struct linespec_result *c,
  9936. gdb::unique_xmalloc_ptr<char> cond_string,
  9937. gdb::unique_xmalloc_ptr<char> extra_string,
  9938. enum bptype type_wanted,
  9939. enum bpdisp disposition,
  9940. int thread,
  9941. int task, int ignore_count,
  9942. const struct breakpoint_ops *o,
  9943. int from_tty, int enabled,
  9944. int internal, unsigned flags)
  9945. {
  9946. internal_error_pure_virtual_called ();
  9947. }
  9948. static std::vector<symtab_and_line>
  9949. base_breakpoint_decode_location (struct breakpoint *b,
  9950. struct event_location *location,
  9951. struct program_space *search_pspace)
  9952. {
  9953. internal_error_pure_virtual_called ();
  9954. }
  9955. /* The default 'explains_signal' method. */
  9956. static int
  9957. base_breakpoint_explains_signal (struct breakpoint *b, enum gdb_signal sig)
  9958. {
  9959. return 1;
  9960. }
  9961. /* The default "after_condition_true" method. */
  9962. static void
  9963. base_breakpoint_after_condition_true (struct bpstat *bs)
  9964. {
  9965. /* Nothing to do. */
  9966. }
  9967. struct breakpoint_ops base_breakpoint_ops =
  9968. {
  9969. base_breakpoint_allocate_location,
  9970. base_breakpoint_re_set,
  9971. base_breakpoint_insert_location,
  9972. base_breakpoint_remove_location,
  9973. base_breakpoint_breakpoint_hit,
  9974. base_breakpoint_check_status,
  9975. base_breakpoint_resources_needed,
  9976. base_breakpoint_works_in_software_mode,
  9977. base_breakpoint_print_it,
  9978. NULL,
  9979. base_breakpoint_print_one_detail,
  9980. base_breakpoint_print_mention,
  9981. base_breakpoint_print_recreate,
  9982. base_breakpoint_create_sals_from_location,
  9983. base_breakpoint_create_breakpoints_sal,
  9984. base_breakpoint_decode_location,
  9985. base_breakpoint_explains_signal,
  9986. base_breakpoint_after_condition_true,
  9987. };
  9988. /* Default breakpoint_ops methods. */
  9989. static void
  9990. bkpt_re_set (struct breakpoint *b)
  9991. {
  9992. /* FIXME: is this still reachable? */
  9993. if (breakpoint_event_location_empty_p (b))
  9994. {
  9995. /* Anything without a location can't be re-set. */
  9996. delete_breakpoint (b);
  9997. return;
  9998. }
  9999. breakpoint_re_set_default (b);
  10000. }
  10001. static int
  10002. bkpt_insert_location (struct bp_location *bl)
  10003. {
  10004. CORE_ADDR addr = bl->target_info.reqstd_address;
  10005. bl->target_info.kind = breakpoint_kind (bl, &addr);
  10006. bl->target_info.placed_address = addr;
  10007. if (bl->loc_type == bp_loc_hardware_breakpoint)
  10008. return target_insert_hw_breakpoint (bl->gdbarch, &bl->target_info);
  10009. else
  10010. return target_insert_breakpoint (bl->gdbarch, &bl->target_info);
  10011. }
  10012. static int
  10013. bkpt_remove_location (struct bp_location *bl, enum remove_bp_reason reason)
  10014. {
  10015. if (bl->loc_type == bp_loc_hardware_breakpoint)
  10016. return target_remove_hw_breakpoint (bl->gdbarch, &bl->target_info);
  10017. else
  10018. return target_remove_breakpoint (bl->gdbarch, &bl->target_info, reason);
  10019. }
  10020. static int
  10021. bkpt_breakpoint_hit (const struct bp_location *bl,
  10022. const address_space *aspace, CORE_ADDR bp_addr,
  10023. const target_waitstatus &ws)
  10024. {
  10025. if (ws.kind () != TARGET_WAITKIND_STOPPED
  10026. || ws.sig () != GDB_SIGNAL_TRAP)
  10027. return 0;
  10028. if (!breakpoint_address_match (bl->pspace->aspace, bl->address,
  10029. aspace, bp_addr))
  10030. return 0;
  10031. if (overlay_debugging /* unmapped overlay section */
  10032. && section_is_overlay (bl->section)
  10033. && !section_is_mapped (bl->section))
  10034. return 0;
  10035. return 1;
  10036. }
  10037. static int
  10038. dprintf_breakpoint_hit (const struct bp_location *bl,
  10039. const address_space *aspace, CORE_ADDR bp_addr,
  10040. const target_waitstatus &ws)
  10041. {
  10042. if (dprintf_style == dprintf_style_agent
  10043. && target_can_run_breakpoint_commands ())
  10044. {
  10045. /* An agent-style dprintf never causes a stop. If we see a trap
  10046. for this address it must be for a breakpoint that happens to
  10047. be set at the same address. */
  10048. return 0;
  10049. }
  10050. return bkpt_breakpoint_hit (bl, aspace, bp_addr, ws);
  10051. }
  10052. static int
  10053. bkpt_resources_needed (const struct bp_location *bl)
  10054. {
  10055. gdb_assert (bl->owner->type == bp_hardware_breakpoint);
  10056. return 1;
  10057. }
  10058. static enum print_stop_action
  10059. bkpt_print_it (bpstat *bs)
  10060. {
  10061. struct breakpoint *b;
  10062. const struct bp_location *bl;
  10063. int bp_temp;
  10064. struct ui_out *uiout = current_uiout;
  10065. gdb_assert (bs->bp_location_at != NULL);
  10066. bl = bs->bp_location_at.get ();
  10067. b = bs->breakpoint_at;
  10068. bp_temp = b->disposition == disp_del;
  10069. if (bl->address != bl->requested_address)
  10070. breakpoint_adjustment_warning (bl->requested_address,
  10071. bl->address,
  10072. b->number, 1);
  10073. annotate_breakpoint (b->number);
  10074. maybe_print_thread_hit_breakpoint (uiout);
  10075. if (uiout->is_mi_like_p ())
  10076. {
  10077. uiout->field_string ("reason",
  10078. async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT));
  10079. uiout->field_string ("disp", bpdisp_text (b->disposition));
  10080. }
  10081. if (bp_temp)
  10082. uiout->message ("Temporary breakpoint %pF, ",
  10083. signed_field ("bkptno", b->number));
  10084. else
  10085. uiout->message ("Breakpoint %pF, ",
  10086. signed_field ("bkptno", b->number));
  10087. return PRINT_SRC_AND_LOC;
  10088. }
  10089. static void
  10090. bkpt_print_mention (struct breakpoint *b)
  10091. {
  10092. if (current_uiout->is_mi_like_p ())
  10093. return;
  10094. switch (b->type)
  10095. {
  10096. case bp_breakpoint:
  10097. case bp_gnu_ifunc_resolver:
  10098. if (b->disposition == disp_del)
  10099. gdb_printf (_("Temporary breakpoint"));
  10100. else
  10101. gdb_printf (_("Breakpoint"));
  10102. gdb_printf (_(" %d"), b->number);
  10103. if (b->type == bp_gnu_ifunc_resolver)
  10104. gdb_printf (_(" at gnu-indirect-function resolver"));
  10105. break;
  10106. case bp_hardware_breakpoint:
  10107. gdb_printf (_("Hardware assisted breakpoint %d"), b->number);
  10108. break;
  10109. case bp_dprintf:
  10110. gdb_printf (_("Dprintf %d"), b->number);
  10111. break;
  10112. }
  10113. say_where (b);
  10114. }
  10115. static void
  10116. bkpt_print_recreate (struct breakpoint *tp, struct ui_file *fp)
  10117. {
  10118. if (tp->type == bp_breakpoint && tp->disposition == disp_del)
  10119. gdb_printf (fp, "tbreak");
  10120. else if (tp->type == bp_breakpoint)
  10121. gdb_printf (fp, "break");
  10122. else if (tp->type == bp_hardware_breakpoint
  10123. && tp->disposition == disp_del)
  10124. gdb_printf (fp, "thbreak");
  10125. else if (tp->type == bp_hardware_breakpoint)
  10126. gdb_printf (fp, "hbreak");
  10127. else
  10128. internal_error (__FILE__, __LINE__,
  10129. _("unhandled breakpoint type %d"), (int) tp->type);
  10130. gdb_printf (fp, " %s",
  10131. event_location_to_string (tp->location.get ()));
  10132. /* Print out extra_string if this breakpoint is pending. It might
  10133. contain, for example, conditions that were set by the user. */
  10134. if (tp->loc == NULL && tp->extra_string != NULL)
  10135. gdb_printf (fp, " %s", tp->extra_string.get ());
  10136. print_recreate_thread (tp, fp);
  10137. }
  10138. static void
  10139. bkpt_create_sals_from_location (struct event_location *location,
  10140. struct linespec_result *canonical,
  10141. enum bptype type_wanted)
  10142. {
  10143. create_sals_from_location_default (location, canonical, type_wanted);
  10144. }
  10145. static void
  10146. bkpt_create_breakpoints_sal (struct gdbarch *gdbarch,
  10147. struct linespec_result *canonical,
  10148. gdb::unique_xmalloc_ptr<char> cond_string,
  10149. gdb::unique_xmalloc_ptr<char> extra_string,
  10150. enum bptype type_wanted,
  10151. enum bpdisp disposition,
  10152. int thread,
  10153. int task, int ignore_count,
  10154. const struct breakpoint_ops *ops,
  10155. int from_tty, int enabled,
  10156. int internal, unsigned flags)
  10157. {
  10158. create_breakpoints_sal_default (gdbarch, canonical,
  10159. std::move (cond_string),
  10160. std::move (extra_string),
  10161. type_wanted,
  10162. disposition, thread, task,
  10163. ignore_count, ops, from_tty,
  10164. enabled, internal, flags);
  10165. }
  10166. static std::vector<symtab_and_line>
  10167. bkpt_decode_location (struct breakpoint *b,
  10168. struct event_location *location,
  10169. struct program_space *search_pspace)
  10170. {
  10171. return decode_location_default (b, location, search_pspace);
  10172. }
  10173. /* Virtual table for internal breakpoints. */
  10174. static void
  10175. internal_bkpt_re_set (struct breakpoint *b)
  10176. {
  10177. switch (b->type)
  10178. {
  10179. /* Delete overlay event and longjmp master breakpoints; they
  10180. will be reset later by breakpoint_re_set. */
  10181. case bp_overlay_event:
  10182. case bp_longjmp_master:
  10183. case bp_std_terminate_master:
  10184. case bp_exception_master:
  10185. delete_breakpoint (b);
  10186. break;
  10187. /* This breakpoint is special, it's set up when the inferior
  10188. starts and we really don't want to touch it. */
  10189. case bp_shlib_event:
  10190. /* Like bp_shlib_event, this breakpoint type is special. Once
  10191. it is set up, we do not want to touch it. */
  10192. case bp_thread_event:
  10193. break;
  10194. }
  10195. }
  10196. static void
  10197. internal_bkpt_check_status (bpstat *bs)
  10198. {
  10199. if (bs->breakpoint_at->type == bp_shlib_event)
  10200. {
  10201. /* If requested, stop when the dynamic linker notifies GDB of
  10202. events. This allows the user to get control and place
  10203. breakpoints in initializer routines for dynamically loaded
  10204. objects (among other things). */
  10205. bs->stop = stop_on_solib_events;
  10206. bs->print = stop_on_solib_events;
  10207. }
  10208. else
  10209. bs->stop = 0;
  10210. }
  10211. static enum print_stop_action
  10212. internal_bkpt_print_it (bpstat *bs)
  10213. {
  10214. struct breakpoint *b;
  10215. b = bs->breakpoint_at;
  10216. switch (b->type)
  10217. {
  10218. case bp_shlib_event:
  10219. /* Did we stop because the user set the stop_on_solib_events
  10220. variable? (If so, we report this as a generic, "Stopped due
  10221. to shlib event" message.) */
  10222. print_solib_event (0);
  10223. break;
  10224. case bp_thread_event:
  10225. /* Not sure how we will get here.
  10226. GDB should not stop for these breakpoints. */
  10227. gdb_printf (_("Thread Event Breakpoint: gdb should not stop!\n"));
  10228. break;
  10229. case bp_overlay_event:
  10230. /* By analogy with the thread event, GDB should not stop for these. */
  10231. gdb_printf (_("Overlay Event Breakpoint: gdb should not stop!\n"));
  10232. break;
  10233. case bp_longjmp_master:
  10234. /* These should never be enabled. */
  10235. gdb_printf (_("Longjmp Master Breakpoint: gdb should not stop!\n"));
  10236. break;
  10237. case bp_std_terminate_master:
  10238. /* These should never be enabled. */
  10239. gdb_printf (_("std::terminate Master Breakpoint: "
  10240. "gdb should not stop!\n"));
  10241. break;
  10242. case bp_exception_master:
  10243. /* These should never be enabled. */
  10244. gdb_printf (_("Exception Master Breakpoint: "
  10245. "gdb should not stop!\n"));
  10246. break;
  10247. }
  10248. return PRINT_NOTHING;
  10249. }
  10250. static void
  10251. internal_bkpt_print_mention (struct breakpoint *b)
  10252. {
  10253. /* Nothing to mention. These breakpoints are internal. */
  10254. }
  10255. /* Virtual table for momentary breakpoints */
  10256. static void
  10257. momentary_bkpt_re_set (struct breakpoint *b)
  10258. {
  10259. /* Keep temporary breakpoints, which can be encountered when we step
  10260. over a dlopen call and solib_add is resetting the breakpoints.
  10261. Otherwise these should have been blown away via the cleanup chain
  10262. or by breakpoint_init_inferior when we rerun the executable. */
  10263. }
  10264. static void
  10265. momentary_bkpt_check_status (bpstat *bs)
  10266. {
  10267. /* Nothing. The point of these breakpoints is causing a stop. */
  10268. }
  10269. static enum print_stop_action
  10270. momentary_bkpt_print_it (bpstat *bs)
  10271. {
  10272. return PRINT_UNKNOWN;
  10273. }
  10274. static void
  10275. momentary_bkpt_print_mention (struct breakpoint *b)
  10276. {
  10277. /* Nothing to mention. These breakpoints are internal. */
  10278. }
  10279. /* Ensure INITIATING_FRAME is cleared when no such breakpoint exists.
  10280. It gets cleared already on the removal of the first one of such placed
  10281. breakpoints. This is OK as they get all removed altogether. */
  10282. longjmp_breakpoint::~longjmp_breakpoint ()
  10283. {
  10284. thread_info *tp = find_thread_global_id (this->thread);
  10285. if (tp != NULL)
  10286. tp->initiating_frame = null_frame_id;
  10287. }
  10288. /* Specific methods for probe breakpoints. */
  10289. static int
  10290. bkpt_probe_insert_location (struct bp_location *bl)
  10291. {
  10292. int v = bkpt_insert_location (bl);
  10293. if (v == 0)
  10294. {
  10295. /* The insertion was successful, now let's set the probe's semaphore
  10296. if needed. */
  10297. bl->probe.prob->set_semaphore (bl->probe.objfile, bl->gdbarch);
  10298. }
  10299. return v;
  10300. }
  10301. static int
  10302. bkpt_probe_remove_location (struct bp_location *bl,
  10303. enum remove_bp_reason reason)
  10304. {
  10305. /* Let's clear the semaphore before removing the location. */
  10306. bl->probe.prob->clear_semaphore (bl->probe.objfile, bl->gdbarch);
  10307. return bkpt_remove_location (bl, reason);
  10308. }
  10309. static void
  10310. bkpt_probe_create_sals_from_location (struct event_location *location,
  10311. struct linespec_result *canonical,
  10312. enum bptype type_wanted)
  10313. {
  10314. struct linespec_sals lsal;
  10315. lsal.sals = parse_probes (location, NULL, canonical);
  10316. lsal.canonical
  10317. = xstrdup (event_location_to_string (canonical->location.get ()));
  10318. canonical->lsals.push_back (std::move (lsal));
  10319. }
  10320. static std::vector<symtab_and_line>
  10321. bkpt_probe_decode_location (struct breakpoint *b,
  10322. struct event_location *location,
  10323. struct program_space *search_pspace)
  10324. {
  10325. std::vector<symtab_and_line> sals = parse_probes (location, search_pspace, NULL);
  10326. if (sals.empty ())
  10327. error (_("probe not found"));
  10328. return sals;
  10329. }
  10330. /* The breakpoint_ops structure to be used in tracepoints. */
  10331. static void
  10332. tracepoint_re_set (struct breakpoint *b)
  10333. {
  10334. breakpoint_re_set_default (b);
  10335. }
  10336. static int
  10337. tracepoint_breakpoint_hit (const struct bp_location *bl,
  10338. const address_space *aspace, CORE_ADDR bp_addr,
  10339. const target_waitstatus &ws)
  10340. {
  10341. /* By definition, the inferior does not report stops at
  10342. tracepoints. */
  10343. return 0;
  10344. }
  10345. static void
  10346. tracepoint_print_one_detail (const struct breakpoint *self,
  10347. struct ui_out *uiout)
  10348. {
  10349. struct tracepoint *tp = (struct tracepoint *) self;
  10350. if (!tp->static_trace_marker_id.empty ())
  10351. {
  10352. gdb_assert (self->type == bp_static_tracepoint);
  10353. uiout->message ("\tmarker id is %pF\n",
  10354. string_field ("static-tracepoint-marker-string-id",
  10355. tp->static_trace_marker_id.c_str ()));
  10356. }
  10357. }
  10358. static void
  10359. tracepoint_print_mention (struct breakpoint *b)
  10360. {
  10361. if (current_uiout->is_mi_like_p ())
  10362. return;
  10363. switch (b->type)
  10364. {
  10365. case bp_tracepoint:
  10366. gdb_printf (_("Tracepoint"));
  10367. gdb_printf (_(" %d"), b->number);
  10368. break;
  10369. case bp_fast_tracepoint:
  10370. gdb_printf (_("Fast tracepoint"));
  10371. gdb_printf (_(" %d"), b->number);
  10372. break;
  10373. case bp_static_tracepoint:
  10374. gdb_printf (_("Static tracepoint"));
  10375. gdb_printf (_(" %d"), b->number);
  10376. break;
  10377. default:
  10378. internal_error (__FILE__, __LINE__,
  10379. _("unhandled tracepoint type %d"), (int) b->type);
  10380. }
  10381. say_where (b);
  10382. }
  10383. static void
  10384. tracepoint_print_recreate (struct breakpoint *self, struct ui_file *fp)
  10385. {
  10386. struct tracepoint *tp = (struct tracepoint *) self;
  10387. if (self->type == bp_fast_tracepoint)
  10388. gdb_printf (fp, "ftrace");
  10389. else if (self->type == bp_static_tracepoint)
  10390. gdb_printf (fp, "strace");
  10391. else if (self->type == bp_tracepoint)
  10392. gdb_printf (fp, "trace");
  10393. else
  10394. internal_error (__FILE__, __LINE__,
  10395. _("unhandled tracepoint type %d"), (int) self->type);
  10396. gdb_printf (fp, " %s",
  10397. event_location_to_string (self->location.get ()));
  10398. print_recreate_thread (self, fp);
  10399. if (tp->pass_count)
  10400. gdb_printf (fp, " passcount %d\n", tp->pass_count);
  10401. }
  10402. static void
  10403. tracepoint_create_sals_from_location (struct event_location *location,
  10404. struct linespec_result *canonical,
  10405. enum bptype type_wanted)
  10406. {
  10407. create_sals_from_location_default (location, canonical, type_wanted);
  10408. }
  10409. static void
  10410. tracepoint_create_breakpoints_sal (struct gdbarch *gdbarch,
  10411. struct linespec_result *canonical,
  10412. gdb::unique_xmalloc_ptr<char> cond_string,
  10413. gdb::unique_xmalloc_ptr<char> extra_string,
  10414. enum bptype type_wanted,
  10415. enum bpdisp disposition,
  10416. int thread,
  10417. int task, int ignore_count,
  10418. const struct breakpoint_ops *ops,
  10419. int from_tty, int enabled,
  10420. int internal, unsigned flags)
  10421. {
  10422. create_breakpoints_sal_default (gdbarch, canonical,
  10423. std::move (cond_string),
  10424. std::move (extra_string),
  10425. type_wanted,
  10426. disposition, thread, task,
  10427. ignore_count, ops, from_tty,
  10428. enabled, internal, flags);
  10429. }
  10430. static std::vector<symtab_and_line>
  10431. tracepoint_decode_location (struct breakpoint *b,
  10432. struct event_location *location,
  10433. struct program_space *search_pspace)
  10434. {
  10435. return decode_location_default (b, location, search_pspace);
  10436. }
  10437. struct breakpoint_ops tracepoint_breakpoint_ops;
  10438. /* Virtual table for tracepoints on static probes. */
  10439. static void
  10440. tracepoint_probe_create_sals_from_location
  10441. (struct event_location *location,
  10442. struct linespec_result *canonical,
  10443. enum bptype type_wanted)
  10444. {
  10445. /* We use the same method for breakpoint on probes. */
  10446. bkpt_probe_create_sals_from_location (location, canonical, type_wanted);
  10447. }
  10448. static std::vector<symtab_and_line>
  10449. tracepoint_probe_decode_location (struct breakpoint *b,
  10450. struct event_location *location,
  10451. struct program_space *search_pspace)
  10452. {
  10453. /* We use the same method for breakpoint on probes. */
  10454. return bkpt_probe_decode_location (b, location, search_pspace);
  10455. }
  10456. /* Dprintf breakpoint_ops methods. */
  10457. static void
  10458. dprintf_re_set (struct breakpoint *b)
  10459. {
  10460. breakpoint_re_set_default (b);
  10461. /* extra_string should never be non-NULL for dprintf. */
  10462. gdb_assert (b->extra_string != NULL);
  10463. /* 1 - connect to target 1, that can run breakpoint commands.
  10464. 2 - create a dprintf, which resolves fine.
  10465. 3 - disconnect from target 1
  10466. 4 - connect to target 2, that can NOT run breakpoint commands.
  10467. After steps #3/#4, you'll want the dprintf command list to
  10468. be updated, because target 1 and 2 may well return different
  10469. answers for target_can_run_breakpoint_commands().
  10470. Given absence of finer grained resetting, we get to do
  10471. it all the time. */
  10472. if (b->extra_string != NULL)
  10473. update_dprintf_command_list (b);
  10474. }
  10475. /* Implement the "print_recreate" breakpoint_ops method for dprintf. */
  10476. static void
  10477. dprintf_print_recreate (struct breakpoint *tp, struct ui_file *fp)
  10478. {
  10479. gdb_printf (fp, "dprintf %s,%s",
  10480. event_location_to_string (tp->location.get ()),
  10481. tp->extra_string.get ());
  10482. print_recreate_thread (tp, fp);
  10483. }
  10484. /* Implement the "after_condition_true" breakpoint_ops method for
  10485. dprintf.
  10486. dprintf's are implemented with regular commands in their command
  10487. list, but we run the commands here instead of before presenting the
  10488. stop to the user, as dprintf's don't actually cause a stop. This
  10489. also makes it so that the commands of multiple dprintfs at the same
  10490. address are all handled. */
  10491. static void
  10492. dprintf_after_condition_true (struct bpstat *bs)
  10493. {
  10494. /* dprintf's never cause a stop. This wasn't set in the
  10495. check_status hook instead because that would make the dprintf's
  10496. condition not be evaluated. */
  10497. bs->stop = 0;
  10498. /* Run the command list here. Take ownership of it instead of
  10499. copying. We never want these commands to run later in
  10500. bpstat_do_actions, if a breakpoint that causes a stop happens to
  10501. be set at same address as this dprintf, or even if running the
  10502. commands here throws. */
  10503. counted_command_line cmds = std::move (bs->commands);
  10504. gdb_assert (cmds != nullptr);
  10505. execute_control_commands (cmds.get (), 0);
  10506. }
  10507. /* The breakpoint_ops structure to be used on static tracepoints with
  10508. markers (`-m'). */
  10509. static void
  10510. strace_marker_create_sals_from_location (struct event_location *location,
  10511. struct linespec_result *canonical,
  10512. enum bptype type_wanted)
  10513. {
  10514. struct linespec_sals lsal;
  10515. const char *arg_start, *arg;
  10516. arg = arg_start = get_linespec_location (location)->spec_string;
  10517. lsal.sals = decode_static_tracepoint_spec (&arg);
  10518. std::string str (arg_start, arg - arg_start);
  10519. const char *ptr = str.c_str ();
  10520. canonical->location
  10521. = new_linespec_location (&ptr, symbol_name_match_type::FULL);
  10522. lsal.canonical
  10523. = xstrdup (event_location_to_string (canonical->location.get ()));
  10524. canonical->lsals.push_back (std::move (lsal));
  10525. }
  10526. static void
  10527. strace_marker_create_breakpoints_sal (struct gdbarch *gdbarch,
  10528. struct linespec_result *canonical,
  10529. gdb::unique_xmalloc_ptr<char> cond_string,
  10530. gdb::unique_xmalloc_ptr<char> extra_string,
  10531. enum bptype type_wanted,
  10532. enum bpdisp disposition,
  10533. int thread,
  10534. int task, int ignore_count,
  10535. const struct breakpoint_ops *ops,
  10536. int from_tty, int enabled,
  10537. int internal, unsigned flags)
  10538. {
  10539. const linespec_sals &lsal = canonical->lsals[0];
  10540. /* If the user is creating a static tracepoint by marker id
  10541. (strace -m MARKER_ID), then store the sals index, so that
  10542. breakpoint_re_set can try to match up which of the newly
  10543. found markers corresponds to this one, and, don't try to
  10544. expand multiple locations for each sal, given than SALS
  10545. already should contain all sals for MARKER_ID. */
  10546. for (size_t i = 0; i < lsal.sals.size (); i++)
  10547. {
  10548. event_location_up location
  10549. = copy_event_location (canonical->location.get ());
  10550. std::unique_ptr<tracepoint> tp (new tracepoint ());
  10551. init_breakpoint_sal (tp.get (), gdbarch, lsal.sals[i],
  10552. std::move (location), NULL,
  10553. std::move (cond_string),
  10554. std::move (extra_string),
  10555. type_wanted, disposition,
  10556. thread, task, ignore_count, ops,
  10557. from_tty, enabled, internal, flags,
  10558. canonical->special_display);
  10559. /* Given that its possible to have multiple markers with
  10560. the same string id, if the user is creating a static
  10561. tracepoint by marker id ("strace -m MARKER_ID"), then
  10562. store the sals index, so that breakpoint_re_set can
  10563. try to match up which of the newly found markers
  10564. corresponds to this one */
  10565. tp->static_trace_marker_id_idx = i;
  10566. install_breakpoint (internal, std::move (tp), 0);
  10567. }
  10568. }
  10569. static std::vector<symtab_and_line>
  10570. strace_marker_decode_location (struct breakpoint *b,
  10571. struct event_location *location,
  10572. struct program_space *search_pspace)
  10573. {
  10574. struct tracepoint *tp = (struct tracepoint *) b;
  10575. const char *s = get_linespec_location (location)->spec_string;
  10576. std::vector<symtab_and_line> sals = decode_static_tracepoint_spec (&s);
  10577. if (sals.size () > tp->static_trace_marker_id_idx)
  10578. {
  10579. sals[0] = sals[tp->static_trace_marker_id_idx];
  10580. sals.resize (1);
  10581. return sals;
  10582. }
  10583. else
  10584. error (_("marker %s not found"), tp->static_trace_marker_id.c_str ());
  10585. }
  10586. static struct breakpoint_ops strace_marker_breakpoint_ops;
  10587. static int
  10588. strace_marker_p (struct breakpoint *b)
  10589. {
  10590. return b->ops == &strace_marker_breakpoint_ops;
  10591. }
  10592. /* Delete a breakpoint and clean up all traces of it in the data
  10593. structures. */
  10594. void
  10595. delete_breakpoint (struct breakpoint *bpt)
  10596. {
  10597. gdb_assert (bpt != NULL);
  10598. /* Has this bp already been deleted? This can happen because
  10599. multiple lists can hold pointers to bp's. bpstat lists are
  10600. especial culprits.
  10601. One example of this happening is a watchpoint's scope bp. When
  10602. the scope bp triggers, we notice that the watchpoint is out of
  10603. scope, and delete it. We also delete its scope bp. But the
  10604. scope bp is marked "auto-deleting", and is already on a bpstat.
  10605. That bpstat is then checked for auto-deleting bp's, which are
  10606. deleted.
  10607. A real solution to this problem might involve reference counts in
  10608. bp's, and/or giving them pointers back to their referencing
  10609. bpstat's, and teaching delete_breakpoint to only free a bp's
  10610. storage when no more references were extent. A cheaper bandaid
  10611. was chosen. */
  10612. if (bpt->type == bp_none)
  10613. return;
  10614. /* At least avoid this stale reference until the reference counting
  10615. of breakpoints gets resolved. */
  10616. if (bpt->related_breakpoint != bpt)
  10617. {
  10618. struct breakpoint *related;
  10619. struct watchpoint *w;
  10620. if (bpt->type == bp_watchpoint_scope)
  10621. w = (struct watchpoint *) bpt->related_breakpoint;
  10622. else if (bpt->related_breakpoint->type == bp_watchpoint_scope)
  10623. w = (struct watchpoint *) bpt;
  10624. else
  10625. w = NULL;
  10626. if (w != NULL)
  10627. watchpoint_del_at_next_stop (w);
  10628. /* Unlink bpt from the bpt->related_breakpoint ring. */
  10629. for (related = bpt; related->related_breakpoint != bpt;
  10630. related = related->related_breakpoint);
  10631. related->related_breakpoint = bpt->related_breakpoint;
  10632. bpt->related_breakpoint = bpt;
  10633. }
  10634. /* watch_command_1 creates a watchpoint but only sets its number if
  10635. update_watchpoint succeeds in creating its bp_locations. If there's
  10636. a problem in that process, we'll be asked to delete the half-created
  10637. watchpoint. In that case, don't announce the deletion. */
  10638. if (bpt->number)
  10639. gdb::observers::breakpoint_deleted.notify (bpt);
  10640. if (breakpoint_chain == bpt)
  10641. breakpoint_chain = bpt->next;
  10642. for (breakpoint *b : all_breakpoints ())
  10643. if (b->next == bpt)
  10644. {
  10645. b->next = bpt->next;
  10646. break;
  10647. }
  10648. /* Be sure no bpstat's are pointing at the breakpoint after it's
  10649. been freed. */
  10650. /* FIXME, how can we find all bpstat's? We just check stop_bpstat
  10651. in all threads for now. Note that we cannot just remove bpstats
  10652. pointing at bpt from the stop_bpstat list entirely, as breakpoint
  10653. commands are associated with the bpstat; if we remove it here,
  10654. then the later call to bpstat_do_actions (&stop_bpstat); in
  10655. event-top.c won't do anything, and temporary breakpoints with
  10656. commands won't work. */
  10657. iterate_over_threads (bpstat_remove_breakpoint_callback, bpt);
  10658. /* Now that breakpoint is removed from breakpoint list, update the
  10659. global location list. This will remove locations that used to
  10660. belong to this breakpoint. Do this before freeing the breakpoint
  10661. itself, since remove_breakpoint looks at location's owner. It
  10662. might be better design to have location completely
  10663. self-contained, but it's not the case now. */
  10664. update_global_location_list (UGLL_DONT_INSERT);
  10665. /* On the chance that someone will soon try again to delete this
  10666. same bp, we mark it as deleted before freeing its storage. */
  10667. bpt->type = bp_none;
  10668. delete bpt;
  10669. }
  10670. /* Iterator function to call a user-provided callback function once
  10671. for each of B and its related breakpoints. */
  10672. static void
  10673. iterate_over_related_breakpoints (struct breakpoint *b,
  10674. gdb::function_view<void (breakpoint *)> function)
  10675. {
  10676. struct breakpoint *related;
  10677. related = b;
  10678. do
  10679. {
  10680. struct breakpoint *next;
  10681. /* FUNCTION may delete RELATED. */
  10682. next = related->related_breakpoint;
  10683. if (next == related)
  10684. {
  10685. /* RELATED is the last ring entry. */
  10686. function (related);
  10687. /* FUNCTION may have deleted it, so we'd never reach back to
  10688. B. There's nothing left to do anyway, so just break
  10689. out. */
  10690. break;
  10691. }
  10692. else
  10693. function (related);
  10694. related = next;
  10695. }
  10696. while (related != b);
  10697. }
  10698. static void
  10699. delete_command (const char *arg, int from_tty)
  10700. {
  10701. dont_repeat ();
  10702. if (arg == 0)
  10703. {
  10704. int breaks_to_delete = 0;
  10705. /* Delete all breakpoints if no argument. Do not delete
  10706. internal breakpoints, these have to be deleted with an
  10707. explicit breakpoint number argument. */
  10708. for (breakpoint *b : all_breakpoints ())
  10709. if (user_breakpoint_p (b))
  10710. {
  10711. breaks_to_delete = 1;
  10712. break;
  10713. }
  10714. /* Ask user only if there are some breakpoints to delete. */
  10715. if (!from_tty
  10716. || (breaks_to_delete && query (_("Delete all breakpoints? "))))
  10717. for (breakpoint *b : all_breakpoints_safe ())
  10718. if (user_breakpoint_p (b))
  10719. delete_breakpoint (b);
  10720. }
  10721. else
  10722. map_breakpoint_numbers
  10723. (arg, [&] (breakpoint *br)
  10724. {
  10725. iterate_over_related_breakpoints (br, delete_breakpoint);
  10726. });
  10727. }
  10728. /* Return true if all locations of B bound to PSPACE are pending. If
  10729. PSPACE is NULL, all locations of all program spaces are
  10730. considered. */
  10731. static int
  10732. all_locations_are_pending (struct breakpoint *b, struct program_space *pspace)
  10733. {
  10734. for (bp_location *loc : b->locations ())
  10735. if ((pspace == NULL
  10736. || loc->pspace == pspace)
  10737. && !loc->shlib_disabled
  10738. && !loc->pspace->executing_startup)
  10739. return 0;
  10740. return 1;
  10741. }
  10742. /* Subroutine of update_breakpoint_locations to simplify it.
  10743. Return non-zero if multiple fns in list LOC have the same name.
  10744. Null names are ignored. */
  10745. static int
  10746. ambiguous_names_p (struct bp_location *loc)
  10747. {
  10748. struct bp_location *l;
  10749. htab_up htab (htab_create_alloc (13, htab_hash_string, htab_eq_string, NULL,
  10750. xcalloc, xfree));
  10751. for (l = loc; l != NULL; l = l->next)
  10752. {
  10753. const char **slot;
  10754. const char *name = l->function_name.get ();
  10755. /* Allow for some names to be NULL, ignore them. */
  10756. if (name == NULL)
  10757. continue;
  10758. slot = (const char **) htab_find_slot (htab.get (), (const void *) name,
  10759. INSERT);
  10760. /* NOTE: We can assume slot != NULL here because xcalloc never
  10761. returns NULL. */
  10762. if (*slot != NULL)
  10763. return 1;
  10764. *slot = name;
  10765. }
  10766. return 0;
  10767. }
  10768. /* When symbols change, it probably means the sources changed as well,
  10769. and it might mean the static tracepoint markers are no longer at
  10770. the same address or line numbers they used to be at last we
  10771. checked. Losing your static tracepoints whenever you rebuild is
  10772. undesirable. This function tries to resync/rematch gdb static
  10773. tracepoints with the markers on the target, for static tracepoints
  10774. that have not been set by marker id. Static tracepoint that have
  10775. been set by marker id are reset by marker id in breakpoint_re_set.
  10776. The heuristic is:
  10777. 1) For a tracepoint set at a specific address, look for a marker at
  10778. the old PC. If one is found there, assume to be the same marker.
  10779. If the name / string id of the marker found is different from the
  10780. previous known name, assume that means the user renamed the marker
  10781. in the sources, and output a warning.
  10782. 2) For a tracepoint set at a given line number, look for a marker
  10783. at the new address of the old line number. If one is found there,
  10784. assume to be the same marker. If the name / string id of the
  10785. marker found is different from the previous known name, assume that
  10786. means the user renamed the marker in the sources, and output a
  10787. warning.
  10788. 3) If a marker is no longer found at the same address or line, it
  10789. may mean the marker no longer exists. But it may also just mean
  10790. the code changed a bit. Maybe the user added a few lines of code
  10791. that made the marker move up or down (in line number terms). Ask
  10792. the target for info about the marker with the string id as we knew
  10793. it. If found, update line number and address in the matching
  10794. static tracepoint. This will get confused if there's more than one
  10795. marker with the same ID (possible in UST, although unadvised
  10796. precisely because it confuses tools). */
  10797. static struct symtab_and_line
  10798. update_static_tracepoint (struct breakpoint *b, struct symtab_and_line sal)
  10799. {
  10800. struct tracepoint *tp = (struct tracepoint *) b;
  10801. struct static_tracepoint_marker marker;
  10802. CORE_ADDR pc;
  10803. pc = sal.pc;
  10804. if (sal.line)
  10805. find_line_pc (sal.symtab, sal.line, &pc);
  10806. if (target_static_tracepoint_marker_at (pc, &marker))
  10807. {
  10808. if (tp->static_trace_marker_id != marker.str_id)
  10809. warning (_("static tracepoint %d changed probed marker from %s to %s"),
  10810. b->number, tp->static_trace_marker_id.c_str (),
  10811. marker.str_id.c_str ());
  10812. tp->static_trace_marker_id = std::move (marker.str_id);
  10813. return sal;
  10814. }
  10815. /* Old marker wasn't found on target at lineno. Try looking it up
  10816. by string ID. */
  10817. if (!sal.explicit_pc
  10818. && sal.line != 0
  10819. && sal.symtab != NULL
  10820. && !tp->static_trace_marker_id.empty ())
  10821. {
  10822. std::vector<static_tracepoint_marker> markers
  10823. = target_static_tracepoint_markers_by_strid
  10824. (tp->static_trace_marker_id.c_str ());
  10825. if (!markers.empty ())
  10826. {
  10827. struct symbol *sym;
  10828. struct static_tracepoint_marker *tpmarker;
  10829. struct ui_out *uiout = current_uiout;
  10830. struct explicit_location explicit_loc;
  10831. tpmarker = &markers[0];
  10832. tp->static_trace_marker_id = std::move (tpmarker->str_id);
  10833. warning (_("marker for static tracepoint %d (%s) not "
  10834. "found at previous line number"),
  10835. b->number, tp->static_trace_marker_id.c_str ());
  10836. symtab_and_line sal2 = find_pc_line (tpmarker->address, 0);
  10837. sym = find_pc_sect_function (tpmarker->address, NULL);
  10838. uiout->text ("Now in ");
  10839. if (sym)
  10840. {
  10841. uiout->field_string ("func", sym->print_name (),
  10842. function_name_style.style ());
  10843. uiout->text (" at ");
  10844. }
  10845. uiout->field_string ("file",
  10846. symtab_to_filename_for_display (sal2.symtab),
  10847. file_name_style.style ());
  10848. uiout->text (":");
  10849. if (uiout->is_mi_like_p ())
  10850. {
  10851. const char *fullname = symtab_to_fullname (sal2.symtab);
  10852. uiout->field_string ("fullname", fullname);
  10853. }
  10854. uiout->field_signed ("line", sal2.line);
  10855. uiout->text ("\n");
  10856. b->loc->line_number = sal2.line;
  10857. b->loc->symtab = sym != NULL ? sal2.symtab : NULL;
  10858. b->location.reset (NULL);
  10859. initialize_explicit_location (&explicit_loc);
  10860. explicit_loc.source_filename
  10861. = ASTRDUP (symtab_to_filename_for_display (sal2.symtab));
  10862. explicit_loc.line_offset.offset = b->loc->line_number;
  10863. explicit_loc.line_offset.sign = LINE_OFFSET_NONE;
  10864. b->location = new_explicit_location (&explicit_loc);
  10865. /* Might be nice to check if function changed, and warn if
  10866. so. */
  10867. }
  10868. }
  10869. return sal;
  10870. }
  10871. /* Returns 1 iff locations A and B are sufficiently same that
  10872. we don't need to report breakpoint as changed. */
  10873. static int
  10874. locations_are_equal (struct bp_location *a, struct bp_location *b)
  10875. {
  10876. while (a && b)
  10877. {
  10878. if (a->address != b->address)
  10879. return 0;
  10880. if (a->shlib_disabled != b->shlib_disabled)
  10881. return 0;
  10882. if (a->enabled != b->enabled)
  10883. return 0;
  10884. if (a->disabled_by_cond != b->disabled_by_cond)
  10885. return 0;
  10886. a = a->next;
  10887. b = b->next;
  10888. }
  10889. if ((a == NULL) != (b == NULL))
  10890. return 0;
  10891. return 1;
  10892. }
  10893. /* Split all locations of B that are bound to PSPACE out of B's
  10894. location list to a separate list and return that list's head. If
  10895. PSPACE is NULL, hoist out all locations of B. */
  10896. static struct bp_location *
  10897. hoist_existing_locations (struct breakpoint *b, struct program_space *pspace)
  10898. {
  10899. struct bp_location head;
  10900. struct bp_location *i = b->loc;
  10901. struct bp_location **i_link = &b->loc;
  10902. struct bp_location *hoisted = &head;
  10903. if (pspace == NULL)
  10904. {
  10905. i = b->loc;
  10906. b->loc = NULL;
  10907. return i;
  10908. }
  10909. head.next = NULL;
  10910. while (i != NULL)
  10911. {
  10912. if (i->pspace == pspace)
  10913. {
  10914. *i_link = i->next;
  10915. i->next = NULL;
  10916. hoisted->next = i;
  10917. hoisted = i;
  10918. }
  10919. else
  10920. i_link = &i->next;
  10921. i = *i_link;
  10922. }
  10923. return head.next;
  10924. }
  10925. /* Create new breakpoint locations for B (a hardware or software
  10926. breakpoint) based on SALS and SALS_END. If SALS_END.NELTS is not
  10927. zero, then B is a ranged breakpoint. Only recreates locations for
  10928. FILTER_PSPACE. Locations of other program spaces are left
  10929. untouched. */
  10930. void
  10931. update_breakpoint_locations (struct breakpoint *b,
  10932. struct program_space *filter_pspace,
  10933. gdb::array_view<const symtab_and_line> sals,
  10934. gdb::array_view<const symtab_and_line> sals_end)
  10935. {
  10936. struct bp_location *existing_locations;
  10937. if (!sals_end.empty () && (sals.size () != 1 || sals_end.size () != 1))
  10938. {
  10939. /* Ranged breakpoints have only one start location and one end
  10940. location. */
  10941. b->enable_state = bp_disabled;
  10942. gdb_printf (gdb_stderr,
  10943. _("Could not reset ranged breakpoint %d: "
  10944. "multiple locations found\n"),
  10945. b->number);
  10946. return;
  10947. }
  10948. /* If there's no new locations, and all existing locations are
  10949. pending, don't do anything. This optimizes the common case where
  10950. all locations are in the same shared library, that was unloaded.
  10951. We'd like to retain the location, so that when the library is
  10952. loaded again, we don't loose the enabled/disabled status of the
  10953. individual locations. */
  10954. if (all_locations_are_pending (b, filter_pspace) && sals.empty ())
  10955. return;
  10956. existing_locations = hoist_existing_locations (b, filter_pspace);
  10957. for (const auto &sal : sals)
  10958. {
  10959. struct bp_location *new_loc;
  10960. switch_to_program_space_and_thread (sal.pspace);
  10961. new_loc = add_location_to_breakpoint (b, &sal);
  10962. /* Reparse conditions, they might contain references to the
  10963. old symtab. */
  10964. if (b->cond_string != NULL)
  10965. {
  10966. const char *s;
  10967. s = b->cond_string.get ();
  10968. try
  10969. {
  10970. new_loc->cond = parse_exp_1 (&s, sal.pc,
  10971. block_for_pc (sal.pc),
  10972. 0);
  10973. }
  10974. catch (const gdb_exception_error &e)
  10975. {
  10976. new_loc->disabled_by_cond = true;
  10977. }
  10978. }
  10979. if (!sals_end.empty ())
  10980. {
  10981. CORE_ADDR end = find_breakpoint_range_end (sals_end[0]);
  10982. new_loc->length = end - sals[0].pc + 1;
  10983. }
  10984. }
  10985. /* If possible, carry over 'disable' status from existing
  10986. breakpoints. */
  10987. {
  10988. struct bp_location *e = existing_locations;
  10989. /* If there are multiple breakpoints with the same function name,
  10990. e.g. for inline functions, comparing function names won't work.
  10991. Instead compare pc addresses; this is just a heuristic as things
  10992. may have moved, but in practice it gives the correct answer
  10993. often enough until a better solution is found. */
  10994. int have_ambiguous_names = ambiguous_names_p (b->loc);
  10995. for (; e; e = e->next)
  10996. {
  10997. if ((!e->enabled || e->disabled_by_cond) && e->function_name)
  10998. {
  10999. if (have_ambiguous_names)
  11000. {
  11001. for (bp_location *l : b->locations ())
  11002. {
  11003. /* Ignore software vs hardware location type at
  11004. this point, because with "set breakpoint
  11005. auto-hw", after a re-set, locations that were
  11006. hardware can end up as software, or vice versa.
  11007. As mentioned above, this is an heuristic and in
  11008. practice should give the correct answer often
  11009. enough. */
  11010. if (breakpoint_locations_match (e, l, true))
  11011. {
  11012. l->enabled = e->enabled;
  11013. l->disabled_by_cond = e->disabled_by_cond;
  11014. break;
  11015. }
  11016. }
  11017. }
  11018. else
  11019. {
  11020. for (bp_location *l : b->locations ())
  11021. if (l->function_name
  11022. && strcmp (e->function_name.get (),
  11023. l->function_name.get ()) == 0)
  11024. {
  11025. l->enabled = e->enabled;
  11026. l->disabled_by_cond = e->disabled_by_cond;
  11027. break;
  11028. }
  11029. }
  11030. }
  11031. }
  11032. }
  11033. if (!locations_are_equal (existing_locations, b->loc))
  11034. gdb::observers::breakpoint_modified.notify (b);
  11035. }
  11036. /* Find the SaL locations corresponding to the given LOCATION.
  11037. On return, FOUND will be 1 if any SaL was found, zero otherwise. */
  11038. static std::vector<symtab_and_line>
  11039. location_to_sals (struct breakpoint *b, struct event_location *location,
  11040. struct program_space *search_pspace, int *found)
  11041. {
  11042. struct gdb_exception exception;
  11043. gdb_assert (b->ops != NULL);
  11044. std::vector<symtab_and_line> sals;
  11045. try
  11046. {
  11047. sals = b->ops->decode_location (b, location, search_pspace);
  11048. }
  11049. catch (gdb_exception_error &e)
  11050. {
  11051. int not_found_and_ok = 0;
  11052. /* For pending breakpoints, it's expected that parsing will
  11053. fail until the right shared library is loaded. User has
  11054. already told to create pending breakpoints and don't need
  11055. extra messages. If breakpoint is in bp_shlib_disabled
  11056. state, then user already saw the message about that
  11057. breakpoint being disabled, and don't want to see more
  11058. errors. */
  11059. if (e.error == NOT_FOUND_ERROR
  11060. && (b->condition_not_parsed
  11061. || (b->loc != NULL
  11062. && search_pspace != NULL
  11063. && b->loc->pspace != search_pspace)
  11064. || (b->loc && b->loc->shlib_disabled)
  11065. || (b->loc && b->loc->pspace->executing_startup)
  11066. || b->enable_state == bp_disabled))
  11067. not_found_and_ok = 1;
  11068. if (!not_found_and_ok)
  11069. {
  11070. /* We surely don't want to warn about the same breakpoint
  11071. 10 times. One solution, implemented here, is disable
  11072. the breakpoint on error. Another solution would be to
  11073. have separate 'warning emitted' flag. Since this
  11074. happens only when a binary has changed, I don't know
  11075. which approach is better. */
  11076. b->enable_state = bp_disabled;
  11077. throw;
  11078. }
  11079. exception = std::move (e);
  11080. }
  11081. if (exception.reason == 0 || exception.error != NOT_FOUND_ERROR)
  11082. {
  11083. for (auto &sal : sals)
  11084. resolve_sal_pc (&sal);
  11085. if (b->condition_not_parsed && b->extra_string != NULL)
  11086. {
  11087. gdb::unique_xmalloc_ptr<char> cond_string, extra_string;
  11088. int thread, task;
  11089. find_condition_and_thread_for_sals (sals, b->extra_string.get (),
  11090. &cond_string, &thread,
  11091. &task, &extra_string);
  11092. gdb_assert (b->cond_string == NULL);
  11093. if (cond_string)
  11094. b->cond_string = std::move (cond_string);
  11095. b->thread = thread;
  11096. b->task = task;
  11097. if (extra_string)
  11098. b->extra_string = std::move (extra_string);
  11099. b->condition_not_parsed = 0;
  11100. }
  11101. if (b->type == bp_static_tracepoint && !strace_marker_p (b))
  11102. sals[0] = update_static_tracepoint (b, sals[0]);
  11103. *found = 1;
  11104. }
  11105. else
  11106. *found = 0;
  11107. return sals;
  11108. }
  11109. /* The default re_set method, for typical hardware or software
  11110. breakpoints. Reevaluate the breakpoint and recreate its
  11111. locations. */
  11112. static void
  11113. breakpoint_re_set_default (struct breakpoint *b)
  11114. {
  11115. struct program_space *filter_pspace = current_program_space;
  11116. std::vector<symtab_and_line> expanded, expanded_end;
  11117. int found;
  11118. std::vector<symtab_and_line> sals = location_to_sals (b, b->location.get (),
  11119. filter_pspace, &found);
  11120. if (found)
  11121. expanded = std::move (sals);
  11122. if (b->location_range_end != NULL)
  11123. {
  11124. std::vector<symtab_and_line> sals_end
  11125. = location_to_sals (b, b->location_range_end.get (),
  11126. filter_pspace, &found);
  11127. if (found)
  11128. expanded_end = std::move (sals_end);
  11129. }
  11130. update_breakpoint_locations (b, filter_pspace, expanded, expanded_end);
  11131. }
  11132. /* Default method for creating SALs from an address string. It basically
  11133. calls parse_breakpoint_sals. Return 1 for success, zero for failure. */
  11134. static void
  11135. create_sals_from_location_default (struct event_location *location,
  11136. struct linespec_result *canonical,
  11137. enum bptype type_wanted)
  11138. {
  11139. parse_breakpoint_sals (location, canonical);
  11140. }
  11141. /* Call create_breakpoints_sal for the given arguments. This is the default
  11142. function for the `create_breakpoints_sal' method of
  11143. breakpoint_ops. */
  11144. static void
  11145. create_breakpoints_sal_default (struct gdbarch *gdbarch,
  11146. struct linespec_result *canonical,
  11147. gdb::unique_xmalloc_ptr<char> cond_string,
  11148. gdb::unique_xmalloc_ptr<char> extra_string,
  11149. enum bptype type_wanted,
  11150. enum bpdisp disposition,
  11151. int thread,
  11152. int task, int ignore_count,
  11153. const struct breakpoint_ops *ops,
  11154. int from_tty, int enabled,
  11155. int internal, unsigned flags)
  11156. {
  11157. create_breakpoints_sal (gdbarch, canonical,
  11158. std::move (cond_string),
  11159. std::move (extra_string),
  11160. type_wanted, disposition,
  11161. thread, task, ignore_count, ops, from_tty,
  11162. enabled, internal, flags);
  11163. }
  11164. /* Decode the line represented by S by calling decode_line_full. This is the
  11165. default function for the `decode_location' method of breakpoint_ops. */
  11166. static std::vector<symtab_and_line>
  11167. decode_location_default (struct breakpoint *b,
  11168. struct event_location *location,
  11169. struct program_space *search_pspace)
  11170. {
  11171. struct linespec_result canonical;
  11172. decode_line_full (location, DECODE_LINE_FUNFIRSTLINE, search_pspace,
  11173. NULL, 0, &canonical, multiple_symbols_all,
  11174. b->filter.get ());
  11175. /* We should get 0 or 1 resulting SALs. */
  11176. gdb_assert (canonical.lsals.size () < 2);
  11177. if (!canonical.lsals.empty ())
  11178. {
  11179. const linespec_sals &lsal = canonical.lsals[0];
  11180. return std::move (lsal.sals);
  11181. }
  11182. return {};
  11183. }
  11184. /* Reset a breakpoint. */
  11185. static void
  11186. breakpoint_re_set_one (breakpoint *b)
  11187. {
  11188. input_radix = b->input_radix;
  11189. set_language (b->language);
  11190. b->ops->re_set (b);
  11191. }
  11192. /* Re-set breakpoint locations for the current program space.
  11193. Locations bound to other program spaces are left untouched. */
  11194. void
  11195. breakpoint_re_set (void)
  11196. {
  11197. {
  11198. scoped_restore_current_language save_language;
  11199. scoped_restore save_input_radix = make_scoped_restore (&input_radix);
  11200. scoped_restore_current_pspace_and_thread restore_pspace_thread;
  11201. /* breakpoint_re_set_one sets the current_language to the language
  11202. of the breakpoint it is resetting (see prepare_re_set_context)
  11203. before re-evaluating the breakpoint's location. This change can
  11204. unfortunately get undone by accident if the language_mode is set
  11205. to auto, and we either switch frames, or more likely in this context,
  11206. we select the current frame.
  11207. We prevent this by temporarily turning the language_mode to
  11208. language_mode_manual. We restore it once all breakpoints
  11209. have been reset. */
  11210. scoped_restore save_language_mode = make_scoped_restore (&language_mode);
  11211. language_mode = language_mode_manual;
  11212. /* Note: we must not try to insert locations until after all
  11213. breakpoints have been re-set. Otherwise, e.g., when re-setting
  11214. breakpoint 1, we'd insert the locations of breakpoint 2, which
  11215. hadn't been re-set yet, and thus may have stale locations. */
  11216. for (breakpoint *b : all_breakpoints_safe ())
  11217. {
  11218. try
  11219. {
  11220. breakpoint_re_set_one (b);
  11221. }
  11222. catch (const gdb_exception &ex)
  11223. {
  11224. exception_fprintf (gdb_stderr, ex,
  11225. "Error in re-setting breakpoint %d: ",
  11226. b->number);
  11227. }
  11228. }
  11229. jit_breakpoint_re_set ();
  11230. }
  11231. create_overlay_event_breakpoint ();
  11232. create_longjmp_master_breakpoint ();
  11233. create_std_terminate_master_breakpoint ();
  11234. create_exception_master_breakpoint ();
  11235. /* Now we can insert. */
  11236. update_global_location_list (UGLL_MAY_INSERT);
  11237. }
  11238. /* Reset the thread number of this breakpoint:
  11239. - If the breakpoint is for all threads, leave it as-is.
  11240. - Else, reset it to the current thread for inferior_ptid. */
  11241. void
  11242. breakpoint_re_set_thread (struct breakpoint *b)
  11243. {
  11244. if (b->thread != -1)
  11245. {
  11246. b->thread = inferior_thread ()->global_num;
  11247. /* We're being called after following a fork. The new fork is
  11248. selected as current, and unless this was a vfork will have a
  11249. different program space from the original thread. Reset that
  11250. as well. */
  11251. b->loc->pspace = current_program_space;
  11252. }
  11253. }
  11254. /* Set ignore-count of breakpoint number BPTNUM to COUNT.
  11255. If from_tty is nonzero, it prints a message to that effect,
  11256. which ends with a period (no newline). */
  11257. void
  11258. set_ignore_count (int bptnum, int count, int from_tty)
  11259. {
  11260. if (count < 0)
  11261. count = 0;
  11262. for (breakpoint *b : all_breakpoints ())
  11263. if (b->number == bptnum)
  11264. {
  11265. if (is_tracepoint (b))
  11266. {
  11267. if (from_tty && count != 0)
  11268. gdb_printf (_("Ignore count ignored for tracepoint %d."),
  11269. bptnum);
  11270. return;
  11271. }
  11272. b->ignore_count = count;
  11273. if (from_tty)
  11274. {
  11275. if (count == 0)
  11276. gdb_printf (_("Will stop next time "
  11277. "breakpoint %d is reached."),
  11278. bptnum);
  11279. else if (count == 1)
  11280. gdb_printf (_("Will ignore next crossing of breakpoint %d."),
  11281. bptnum);
  11282. else
  11283. gdb_printf (_("Will ignore next %d "
  11284. "crossings of breakpoint %d."),
  11285. count, bptnum);
  11286. }
  11287. gdb::observers::breakpoint_modified.notify (b);
  11288. return;
  11289. }
  11290. error (_("No breakpoint number %d."), bptnum);
  11291. }
  11292. /* Command to set ignore-count of breakpoint N to COUNT. */
  11293. static void
  11294. ignore_command (const char *args, int from_tty)
  11295. {
  11296. const char *p = args;
  11297. int num;
  11298. if (p == 0)
  11299. error_no_arg (_("a breakpoint number"));
  11300. num = get_number (&p);
  11301. if (num == 0)
  11302. error (_("bad breakpoint number: '%s'"), args);
  11303. if (*p == 0)
  11304. error (_("Second argument (specified ignore-count) is missing."));
  11305. set_ignore_count (num,
  11306. longest_to_int (value_as_long (parse_and_eval (p))),
  11307. from_tty);
  11308. if (from_tty)
  11309. gdb_printf ("\n");
  11310. }
  11311. /* Call FUNCTION on each of the breakpoints with numbers in the range
  11312. defined by BP_NUM_RANGE (an inclusive range). */
  11313. static void
  11314. map_breakpoint_number_range (std::pair<int, int> bp_num_range,
  11315. gdb::function_view<void (breakpoint *)> function)
  11316. {
  11317. if (bp_num_range.first == 0)
  11318. {
  11319. warning (_("bad breakpoint number at or near '%d'"),
  11320. bp_num_range.first);
  11321. }
  11322. else
  11323. {
  11324. for (int i = bp_num_range.first; i <= bp_num_range.second; i++)
  11325. {
  11326. bool match = false;
  11327. for (breakpoint *b : all_breakpoints_safe ())
  11328. if (b->number == i)
  11329. {
  11330. match = true;
  11331. function (b);
  11332. break;
  11333. }
  11334. if (!match)
  11335. gdb_printf (_("No breakpoint number %d.\n"), i);
  11336. }
  11337. }
  11338. }
  11339. /* Call FUNCTION on each of the breakpoints whose numbers are given in
  11340. ARGS. */
  11341. static void
  11342. map_breakpoint_numbers (const char *args,
  11343. gdb::function_view<void (breakpoint *)> function)
  11344. {
  11345. if (args == NULL || *args == '\0')
  11346. error_no_arg (_("one or more breakpoint numbers"));
  11347. number_or_range_parser parser (args);
  11348. while (!parser.finished ())
  11349. {
  11350. int num = parser.get_number ();
  11351. map_breakpoint_number_range (std::make_pair (num, num), function);
  11352. }
  11353. }
  11354. /* Return the breakpoint location structure corresponding to the
  11355. BP_NUM and LOC_NUM values. */
  11356. static struct bp_location *
  11357. find_location_by_number (int bp_num, int loc_num)
  11358. {
  11359. breakpoint *b = get_breakpoint (bp_num);
  11360. if (!b || b->number != bp_num)
  11361. error (_("Bad breakpoint number '%d'"), bp_num);
  11362. if (loc_num == 0)
  11363. error (_("Bad breakpoint location number '%d'"), loc_num);
  11364. int n = 0;
  11365. for (bp_location *loc : b->locations ())
  11366. if (++n == loc_num)
  11367. return loc;
  11368. error (_("Bad breakpoint location number '%d'"), loc_num);
  11369. }
  11370. /* Modes of operation for extract_bp_num. */
  11371. enum class extract_bp_kind
  11372. {
  11373. /* Extracting a breakpoint number. */
  11374. bp,
  11375. /* Extracting a location number. */
  11376. loc,
  11377. };
  11378. /* Extract a breakpoint or location number (as determined by KIND)
  11379. from the string starting at START. TRAILER is a character which
  11380. can be found after the number. If you don't want a trailer, use
  11381. '\0'. If END_OUT is not NULL, it is set to point after the parsed
  11382. string. This always returns a positive integer. */
  11383. static int
  11384. extract_bp_num (extract_bp_kind kind, const char *start,
  11385. int trailer, const char **end_out = NULL)
  11386. {
  11387. const char *end = start;
  11388. int num = get_number_trailer (&end, trailer);
  11389. if (num < 0)
  11390. error (kind == extract_bp_kind::bp
  11391. ? _("Negative breakpoint number '%.*s'")
  11392. : _("Negative breakpoint location number '%.*s'"),
  11393. int (end - start), start);
  11394. if (num == 0)
  11395. error (kind == extract_bp_kind::bp
  11396. ? _("Bad breakpoint number '%.*s'")
  11397. : _("Bad breakpoint location number '%.*s'"),
  11398. int (end - start), start);
  11399. if (end_out != NULL)
  11400. *end_out = end;
  11401. return num;
  11402. }
  11403. /* Extract a breakpoint or location range (as determined by KIND) in
  11404. the form NUM1-NUM2 stored at &ARG[arg_offset]. Returns a std::pair
  11405. representing the (inclusive) range. The returned pair's elements
  11406. are always positive integers. */
  11407. static std::pair<int, int>
  11408. extract_bp_or_bp_range (extract_bp_kind kind,
  11409. const std::string &arg,
  11410. std::string::size_type arg_offset)
  11411. {
  11412. std::pair<int, int> range;
  11413. const char *bp_loc = &arg[arg_offset];
  11414. std::string::size_type dash = arg.find ('-', arg_offset);
  11415. if (dash != std::string::npos)
  11416. {
  11417. /* bp_loc is a range (x-z). */
  11418. if (arg.length () == dash + 1)
  11419. error (kind == extract_bp_kind::bp
  11420. ? _("Bad breakpoint number at or near: '%s'")
  11421. : _("Bad breakpoint location number at or near: '%s'"),
  11422. bp_loc);
  11423. const char *end;
  11424. const char *start_first = bp_loc;
  11425. const char *start_second = &arg[dash + 1];
  11426. range.first = extract_bp_num (kind, start_first, '-');
  11427. range.second = extract_bp_num (kind, start_second, '\0', &end);
  11428. if (range.first > range.second)
  11429. error (kind == extract_bp_kind::bp
  11430. ? _("Inverted breakpoint range at '%.*s'")
  11431. : _("Inverted breakpoint location range at '%.*s'"),
  11432. int (end - start_first), start_first);
  11433. }
  11434. else
  11435. {
  11436. /* bp_loc is a single value. */
  11437. range.first = extract_bp_num (kind, bp_loc, '\0');
  11438. range.second = range.first;
  11439. }
  11440. return range;
  11441. }
  11442. /* Extract the breakpoint/location range specified by ARG. Returns
  11443. the breakpoint range in BP_NUM_RANGE, and the location range in
  11444. BP_LOC_RANGE.
  11445. ARG may be in any of the following forms:
  11446. x where 'x' is a breakpoint number.
  11447. x-y where 'x' and 'y' specify a breakpoint numbers range.
  11448. x.y where 'x' is a breakpoint number and 'y' a location number.
  11449. x.y-z where 'x' is a breakpoint number and 'y' and 'z' specify a
  11450. location number range.
  11451. */
  11452. static void
  11453. extract_bp_number_and_location (const std::string &arg,
  11454. std::pair<int, int> &bp_num_range,
  11455. std::pair<int, int> &bp_loc_range)
  11456. {
  11457. std::string::size_type dot = arg.find ('.');
  11458. if (dot != std::string::npos)
  11459. {
  11460. /* Handle 'x.y' and 'x.y-z' cases. */
  11461. if (arg.length () == dot + 1 || dot == 0)
  11462. error (_("Bad breakpoint number at or near: '%s'"), arg.c_str ());
  11463. bp_num_range.first
  11464. = extract_bp_num (extract_bp_kind::bp, arg.c_str (), '.');
  11465. bp_num_range.second = bp_num_range.first;
  11466. bp_loc_range = extract_bp_or_bp_range (extract_bp_kind::loc,
  11467. arg, dot + 1);
  11468. }
  11469. else
  11470. {
  11471. /* Handle x and x-y cases. */
  11472. bp_num_range = extract_bp_or_bp_range (extract_bp_kind::bp, arg, 0);
  11473. bp_loc_range.first = 0;
  11474. bp_loc_range.second = 0;
  11475. }
  11476. }
  11477. /* Enable or disable a breakpoint location BP_NUM.LOC_NUM. ENABLE
  11478. specifies whether to enable or disable. */
  11479. static void
  11480. enable_disable_bp_num_loc (int bp_num, int loc_num, bool enable)
  11481. {
  11482. struct bp_location *loc = find_location_by_number (bp_num, loc_num);
  11483. if (loc != NULL)
  11484. {
  11485. if (loc->disabled_by_cond && enable)
  11486. error (_("Breakpoint %d's condition is invalid at location %d, "
  11487. "cannot enable."), bp_num, loc_num);
  11488. if (loc->enabled != enable)
  11489. {
  11490. loc->enabled = enable;
  11491. mark_breakpoint_location_modified (loc);
  11492. }
  11493. if (target_supports_enable_disable_tracepoint ()
  11494. && current_trace_status ()->running && loc->owner
  11495. && is_tracepoint (loc->owner))
  11496. target_disable_tracepoint (loc);
  11497. }
  11498. update_global_location_list (UGLL_DONT_INSERT);
  11499. gdb::observers::breakpoint_modified.notify (loc->owner);
  11500. }
  11501. /* Enable or disable a range of breakpoint locations. BP_NUM is the
  11502. number of the breakpoint, and BP_LOC_RANGE specifies the
  11503. (inclusive) range of location numbers of that breakpoint to
  11504. enable/disable. ENABLE specifies whether to enable or disable the
  11505. location. */
  11506. static void
  11507. enable_disable_breakpoint_location_range (int bp_num,
  11508. std::pair<int, int> &bp_loc_range,
  11509. bool enable)
  11510. {
  11511. for (int i = bp_loc_range.first; i <= bp_loc_range.second; i++)
  11512. enable_disable_bp_num_loc (bp_num, i, enable);
  11513. }
  11514. /* Set ignore-count of breakpoint number BPTNUM to COUNT.
  11515. If from_tty is nonzero, it prints a message to that effect,
  11516. which ends with a period (no newline). */
  11517. void
  11518. disable_breakpoint (struct breakpoint *bpt)
  11519. {
  11520. /* Never disable a watchpoint scope breakpoint; we want to
  11521. hit them when we leave scope so we can delete both the
  11522. watchpoint and its scope breakpoint at that time. */
  11523. if (bpt->type == bp_watchpoint_scope)
  11524. return;
  11525. bpt->enable_state = bp_disabled;
  11526. /* Mark breakpoint locations modified. */
  11527. mark_breakpoint_modified (bpt);
  11528. if (target_supports_enable_disable_tracepoint ()
  11529. && current_trace_status ()->running && is_tracepoint (bpt))
  11530. {
  11531. for (bp_location *location : bpt->locations ())
  11532. target_disable_tracepoint (location);
  11533. }
  11534. update_global_location_list (UGLL_DONT_INSERT);
  11535. gdb::observers::breakpoint_modified.notify (bpt);
  11536. }
  11537. /* Enable or disable the breakpoint(s) or breakpoint location(s)
  11538. specified in ARGS. ARGS may be in any of the formats handled by
  11539. extract_bp_number_and_location. ENABLE specifies whether to enable
  11540. or disable the breakpoints/locations. */
  11541. static void
  11542. enable_disable_command (const char *args, int from_tty, bool enable)
  11543. {
  11544. if (args == 0)
  11545. {
  11546. for (breakpoint *bpt : all_breakpoints ())
  11547. if (user_breakpoint_p (bpt))
  11548. {
  11549. if (enable)
  11550. enable_breakpoint (bpt);
  11551. else
  11552. disable_breakpoint (bpt);
  11553. }
  11554. }
  11555. else
  11556. {
  11557. std::string num = extract_arg (&args);
  11558. while (!num.empty ())
  11559. {
  11560. std::pair<int, int> bp_num_range, bp_loc_range;
  11561. extract_bp_number_and_location (num, bp_num_range, bp_loc_range);
  11562. if (bp_loc_range.first == bp_loc_range.second
  11563. && bp_loc_range.first == 0)
  11564. {
  11565. /* Handle breakpoint ids with formats 'x' or 'x-z'. */
  11566. map_breakpoint_number_range (bp_num_range,
  11567. enable
  11568. ? enable_breakpoint
  11569. : disable_breakpoint);
  11570. }
  11571. else
  11572. {
  11573. /* Handle breakpoint ids with formats 'x.y' or
  11574. 'x.y-z'. */
  11575. enable_disable_breakpoint_location_range
  11576. (bp_num_range.first, bp_loc_range, enable);
  11577. }
  11578. num = extract_arg (&args);
  11579. }
  11580. }
  11581. }
  11582. /* The disable command disables the specified breakpoints/locations
  11583. (or all defined breakpoints) so they're no longer effective in
  11584. stopping the inferior. ARGS may be in any of the forms defined in
  11585. extract_bp_number_and_location. */
  11586. static void
  11587. disable_command (const char *args, int from_tty)
  11588. {
  11589. enable_disable_command (args, from_tty, false);
  11590. }
  11591. static void
  11592. enable_breakpoint_disp (struct breakpoint *bpt, enum bpdisp disposition,
  11593. int count)
  11594. {
  11595. int target_resources_ok;
  11596. if (bpt->type == bp_hardware_breakpoint)
  11597. {
  11598. int i;
  11599. i = hw_breakpoint_used_count ();
  11600. target_resources_ok =
  11601. target_can_use_hardware_watchpoint (bp_hardware_breakpoint,
  11602. i + 1, 0);
  11603. if (target_resources_ok == 0)
  11604. error (_("No hardware breakpoint support in the target."));
  11605. else if (target_resources_ok < 0)
  11606. error (_("Hardware breakpoints used exceeds limit."));
  11607. }
  11608. if (is_watchpoint (bpt))
  11609. {
  11610. /* Initialize it just to avoid a GCC false warning. */
  11611. enum enable_state orig_enable_state = bp_disabled;
  11612. try
  11613. {
  11614. struct watchpoint *w = (struct watchpoint *) bpt;
  11615. orig_enable_state = bpt->enable_state;
  11616. bpt->enable_state = bp_enabled;
  11617. update_watchpoint (w, 1 /* reparse */);
  11618. }
  11619. catch (const gdb_exception &e)
  11620. {
  11621. bpt->enable_state = orig_enable_state;
  11622. exception_fprintf (gdb_stderr, e, _("Cannot enable watchpoint %d: "),
  11623. bpt->number);
  11624. return;
  11625. }
  11626. }
  11627. bpt->enable_state = bp_enabled;
  11628. /* Mark breakpoint locations modified. */
  11629. mark_breakpoint_modified (bpt);
  11630. if (target_supports_enable_disable_tracepoint ()
  11631. && current_trace_status ()->running && is_tracepoint (bpt))
  11632. {
  11633. for (bp_location *location : bpt->locations ())
  11634. target_enable_tracepoint (location);
  11635. }
  11636. bpt->disposition = disposition;
  11637. bpt->enable_count = count;
  11638. update_global_location_list (UGLL_MAY_INSERT);
  11639. gdb::observers::breakpoint_modified.notify (bpt);
  11640. }
  11641. void
  11642. enable_breakpoint (struct breakpoint *bpt)
  11643. {
  11644. enable_breakpoint_disp (bpt, bpt->disposition, 0);
  11645. }
  11646. /* The enable command enables the specified breakpoints/locations (or
  11647. all defined breakpoints) so they once again become (or continue to
  11648. be) effective in stopping the inferior. ARGS may be in any of the
  11649. forms defined in extract_bp_number_and_location. */
  11650. static void
  11651. enable_command (const char *args, int from_tty)
  11652. {
  11653. enable_disable_command (args, from_tty, true);
  11654. }
  11655. static void
  11656. enable_once_command (const char *args, int from_tty)
  11657. {
  11658. map_breakpoint_numbers
  11659. (args, [&] (breakpoint *b)
  11660. {
  11661. iterate_over_related_breakpoints
  11662. (b, [&] (breakpoint *bpt)
  11663. {
  11664. enable_breakpoint_disp (bpt, disp_disable, 1);
  11665. });
  11666. });
  11667. }
  11668. static void
  11669. enable_count_command (const char *args, int from_tty)
  11670. {
  11671. int count;
  11672. if (args == NULL)
  11673. error_no_arg (_("hit count"));
  11674. count = get_number (&args);
  11675. map_breakpoint_numbers
  11676. (args, [&] (breakpoint *b)
  11677. {
  11678. iterate_over_related_breakpoints
  11679. (b, [&] (breakpoint *bpt)
  11680. {
  11681. enable_breakpoint_disp (bpt, disp_disable, count);
  11682. });
  11683. });
  11684. }
  11685. static void
  11686. enable_delete_command (const char *args, int from_tty)
  11687. {
  11688. map_breakpoint_numbers
  11689. (args, [&] (breakpoint *b)
  11690. {
  11691. iterate_over_related_breakpoints
  11692. (b, [&] (breakpoint *bpt)
  11693. {
  11694. enable_breakpoint_disp (bpt, disp_del, 1);
  11695. });
  11696. });
  11697. }
  11698. /* Invalidate last known value of any hardware watchpoint if
  11699. the memory which that value represents has been written to by
  11700. GDB itself. */
  11701. static void
  11702. invalidate_bp_value_on_memory_change (struct inferior *inferior,
  11703. CORE_ADDR addr, ssize_t len,
  11704. const bfd_byte *data)
  11705. {
  11706. for (breakpoint *bp : all_breakpoints ())
  11707. if (bp->enable_state == bp_enabled
  11708. && bp->type == bp_hardware_watchpoint)
  11709. {
  11710. struct watchpoint *wp = (struct watchpoint *) bp;
  11711. if (wp->val_valid && wp->val != nullptr)
  11712. {
  11713. for (bp_location *loc : bp->locations ())
  11714. if (loc->loc_type == bp_loc_hardware_watchpoint
  11715. && loc->address + loc->length > addr
  11716. && addr + len > loc->address)
  11717. {
  11718. wp->val = NULL;
  11719. wp->val_valid = false;
  11720. }
  11721. }
  11722. }
  11723. }
  11724. /* Create and insert a breakpoint for software single step. */
  11725. void
  11726. insert_single_step_breakpoint (struct gdbarch *gdbarch,
  11727. const address_space *aspace,
  11728. CORE_ADDR next_pc)
  11729. {
  11730. struct thread_info *tp = inferior_thread ();
  11731. struct symtab_and_line sal;
  11732. CORE_ADDR pc = next_pc;
  11733. if (tp->control.single_step_breakpoints == NULL)
  11734. {
  11735. tp->control.single_step_breakpoints
  11736. = new_single_step_breakpoint (tp->global_num, gdbarch);
  11737. }
  11738. sal = find_pc_line (pc, 0);
  11739. sal.pc = pc;
  11740. sal.section = find_pc_overlay (pc);
  11741. sal.explicit_pc = 1;
  11742. add_location_to_breakpoint (tp->control.single_step_breakpoints, &sal);
  11743. update_global_location_list (UGLL_INSERT);
  11744. }
  11745. /* Insert single step breakpoints according to the current state. */
  11746. int
  11747. insert_single_step_breakpoints (struct gdbarch *gdbarch)
  11748. {
  11749. struct regcache *regcache = get_current_regcache ();
  11750. std::vector<CORE_ADDR> next_pcs;
  11751. next_pcs = gdbarch_software_single_step (gdbarch, regcache);
  11752. if (!next_pcs.empty ())
  11753. {
  11754. struct frame_info *frame = get_current_frame ();
  11755. const address_space *aspace = get_frame_address_space (frame);
  11756. for (CORE_ADDR pc : next_pcs)
  11757. insert_single_step_breakpoint (gdbarch, aspace, pc);
  11758. return 1;
  11759. }
  11760. else
  11761. return 0;
  11762. }
  11763. /* See breakpoint.h. */
  11764. int
  11765. breakpoint_has_location_inserted_here (struct breakpoint *bp,
  11766. const address_space *aspace,
  11767. CORE_ADDR pc)
  11768. {
  11769. for (bp_location *loc : bp->locations ())
  11770. if (loc->inserted
  11771. && breakpoint_location_address_match (loc, aspace, pc))
  11772. return 1;
  11773. return 0;
  11774. }
  11775. /* Check whether a software single-step breakpoint is inserted at
  11776. PC. */
  11777. int
  11778. single_step_breakpoint_inserted_here_p (const address_space *aspace,
  11779. CORE_ADDR pc)
  11780. {
  11781. for (breakpoint *bpt : all_breakpoints ())
  11782. {
  11783. if (bpt->type == bp_single_step
  11784. && breakpoint_has_location_inserted_here (bpt, aspace, pc))
  11785. return 1;
  11786. }
  11787. return 0;
  11788. }
  11789. /* Tracepoint-specific operations. */
  11790. /* Set tracepoint count to NUM. */
  11791. static void
  11792. set_tracepoint_count (int num)
  11793. {
  11794. tracepoint_count = num;
  11795. set_internalvar_integer (lookup_internalvar ("tpnum"), num);
  11796. }
  11797. static void
  11798. trace_command (const char *arg, int from_tty)
  11799. {
  11800. event_location_up location = string_to_event_location (&arg,
  11801. current_language);
  11802. const struct breakpoint_ops *ops = breakpoint_ops_for_event_location
  11803. (location.get (), true /* is_tracepoint */);
  11804. create_breakpoint (get_current_arch (),
  11805. location.get (),
  11806. NULL, 0, arg, false, 1 /* parse arg */,
  11807. 0 /* tempflag */,
  11808. bp_tracepoint /* type_wanted */,
  11809. 0 /* Ignore count */,
  11810. pending_break_support,
  11811. ops,
  11812. from_tty,
  11813. 1 /* enabled */,
  11814. 0 /* internal */, 0);
  11815. }
  11816. static void
  11817. ftrace_command (const char *arg, int from_tty)
  11818. {
  11819. event_location_up location = string_to_event_location (&arg,
  11820. current_language);
  11821. create_breakpoint (get_current_arch (),
  11822. location.get (),
  11823. NULL, 0, arg, false, 1 /* parse arg */,
  11824. 0 /* tempflag */,
  11825. bp_fast_tracepoint /* type_wanted */,
  11826. 0 /* Ignore count */,
  11827. pending_break_support,
  11828. &tracepoint_breakpoint_ops,
  11829. from_tty,
  11830. 1 /* enabled */,
  11831. 0 /* internal */, 0);
  11832. }
  11833. /* strace command implementation. Creates a static tracepoint. */
  11834. static void
  11835. strace_command (const char *arg, int from_tty)
  11836. {
  11837. struct breakpoint_ops *ops;
  11838. event_location_up location;
  11839. /* Decide if we are dealing with a static tracepoint marker (`-m'),
  11840. or with a normal static tracepoint. */
  11841. if (arg && startswith (arg, "-m") && isspace (arg[2]))
  11842. {
  11843. ops = &strace_marker_breakpoint_ops;
  11844. location = new_linespec_location (&arg, symbol_name_match_type::FULL);
  11845. }
  11846. else
  11847. {
  11848. ops = &tracepoint_breakpoint_ops;
  11849. location = string_to_event_location (&arg, current_language);
  11850. }
  11851. create_breakpoint (get_current_arch (),
  11852. location.get (),
  11853. NULL, 0, arg, false, 1 /* parse arg */,
  11854. 0 /* tempflag */,
  11855. bp_static_tracepoint /* type_wanted */,
  11856. 0 /* Ignore count */,
  11857. pending_break_support,
  11858. ops,
  11859. from_tty,
  11860. 1 /* enabled */,
  11861. 0 /* internal */, 0);
  11862. }
  11863. /* Set up a fake reader function that gets command lines from a linked
  11864. list that was acquired during tracepoint uploading. */
  11865. static struct uploaded_tp *this_utp;
  11866. static int next_cmd;
  11867. static char *
  11868. read_uploaded_action (void)
  11869. {
  11870. char *rslt = nullptr;
  11871. if (next_cmd < this_utp->cmd_strings.size ())
  11872. {
  11873. rslt = this_utp->cmd_strings[next_cmd].get ();
  11874. next_cmd++;
  11875. }
  11876. return rslt;
  11877. }
  11878. /* Given information about a tracepoint as recorded on a target (which
  11879. can be either a live system or a trace file), attempt to create an
  11880. equivalent GDB tracepoint. This is not a reliable process, since
  11881. the target does not necessarily have all the information used when
  11882. the tracepoint was originally defined. */
  11883. struct tracepoint *
  11884. create_tracepoint_from_upload (struct uploaded_tp *utp)
  11885. {
  11886. const char *addr_str;
  11887. char small_buf[100];
  11888. struct tracepoint *tp;
  11889. if (utp->at_string)
  11890. addr_str = utp->at_string.get ();
  11891. else
  11892. {
  11893. /* In the absence of a source location, fall back to raw
  11894. address. Since there is no way to confirm that the address
  11895. means the same thing as when the trace was started, warn the
  11896. user. */
  11897. warning (_("Uploaded tracepoint %d has no "
  11898. "source location, using raw address"),
  11899. utp->number);
  11900. xsnprintf (small_buf, sizeof (small_buf), "*%s", hex_string (utp->addr));
  11901. addr_str = small_buf;
  11902. }
  11903. /* There's not much we can do with a sequence of bytecodes. */
  11904. if (utp->cond && !utp->cond_string)
  11905. warning (_("Uploaded tracepoint %d condition "
  11906. "has no source form, ignoring it"),
  11907. utp->number);
  11908. event_location_up location = string_to_event_location (&addr_str,
  11909. current_language);
  11910. if (!create_breakpoint (get_current_arch (),
  11911. location.get (),
  11912. utp->cond_string.get (), -1, addr_str,
  11913. false /* force_condition */,
  11914. 0 /* parse cond/thread */,
  11915. 0 /* tempflag */,
  11916. utp->type /* type_wanted */,
  11917. 0 /* Ignore count */,
  11918. pending_break_support,
  11919. &tracepoint_breakpoint_ops,
  11920. 0 /* from_tty */,
  11921. utp->enabled /* enabled */,
  11922. 0 /* internal */,
  11923. CREATE_BREAKPOINT_FLAGS_INSERTED))
  11924. return NULL;
  11925. /* Get the tracepoint we just created. */
  11926. tp = get_tracepoint (tracepoint_count);
  11927. gdb_assert (tp != NULL);
  11928. if (utp->pass > 0)
  11929. {
  11930. xsnprintf (small_buf, sizeof (small_buf), "%d %d", utp->pass,
  11931. tp->number);
  11932. trace_pass_command (small_buf, 0);
  11933. }
  11934. /* If we have uploaded versions of the original commands, set up a
  11935. special-purpose "reader" function and call the usual command line
  11936. reader, then pass the result to the breakpoint command-setting
  11937. function. */
  11938. if (!utp->cmd_strings.empty ())
  11939. {
  11940. counted_command_line cmd_list;
  11941. this_utp = utp;
  11942. next_cmd = 0;
  11943. cmd_list = read_command_lines_1 (read_uploaded_action, 1, NULL);
  11944. breakpoint_set_commands (tp, std::move (cmd_list));
  11945. }
  11946. else if (!utp->actions.empty ()
  11947. || !utp->step_actions.empty ())
  11948. warning (_("Uploaded tracepoint %d actions "
  11949. "have no source form, ignoring them"),
  11950. utp->number);
  11951. /* Copy any status information that might be available. */
  11952. tp->hit_count = utp->hit_count;
  11953. tp->traceframe_usage = utp->traceframe_usage;
  11954. return tp;
  11955. }
  11956. /* Print information on tracepoint number TPNUM_EXP, or all if
  11957. omitted. */
  11958. static void
  11959. info_tracepoints_command (const char *args, int from_tty)
  11960. {
  11961. struct ui_out *uiout = current_uiout;
  11962. int num_printed;
  11963. num_printed = breakpoint_1 (args, false, is_tracepoint);
  11964. if (num_printed == 0)
  11965. {
  11966. if (args == NULL || *args == '\0')
  11967. uiout->message ("No tracepoints.\n");
  11968. else
  11969. uiout->message ("No tracepoint matching '%s'.\n", args);
  11970. }
  11971. default_collect_info ();
  11972. }
  11973. /* The 'enable trace' command enables tracepoints.
  11974. Not supported by all targets. */
  11975. static void
  11976. enable_trace_command (const char *args, int from_tty)
  11977. {
  11978. enable_command (args, from_tty);
  11979. }
  11980. /* The 'disable trace' command disables tracepoints.
  11981. Not supported by all targets. */
  11982. static void
  11983. disable_trace_command (const char *args, int from_tty)
  11984. {
  11985. disable_command (args, from_tty);
  11986. }
  11987. /* Remove a tracepoint (or all if no argument). */
  11988. static void
  11989. delete_trace_command (const char *arg, int from_tty)
  11990. {
  11991. dont_repeat ();
  11992. if (arg == 0)
  11993. {
  11994. int breaks_to_delete = 0;
  11995. /* Delete all breakpoints if no argument.
  11996. Do not delete internal or call-dummy breakpoints, these
  11997. have to be deleted with an explicit breakpoint number
  11998. argument. */
  11999. for (breakpoint *tp : all_tracepoints ())
  12000. if (is_tracepoint (tp) && user_breakpoint_p (tp))
  12001. {
  12002. breaks_to_delete = 1;
  12003. break;
  12004. }
  12005. /* Ask user only if there are some breakpoints to delete. */
  12006. if (!from_tty
  12007. || (breaks_to_delete && query (_("Delete all tracepoints? "))))
  12008. {
  12009. for (breakpoint *b : all_breakpoints_safe ())
  12010. if (is_tracepoint (b) && user_breakpoint_p (b))
  12011. delete_breakpoint (b);
  12012. }
  12013. }
  12014. else
  12015. map_breakpoint_numbers
  12016. (arg, [&] (breakpoint *br)
  12017. {
  12018. iterate_over_related_breakpoints (br, delete_breakpoint);
  12019. });
  12020. }
  12021. /* Helper function for trace_pass_command. */
  12022. static void
  12023. trace_pass_set_count (struct tracepoint *tp, int count, int from_tty)
  12024. {
  12025. tp->pass_count = count;
  12026. gdb::observers::breakpoint_modified.notify (tp);
  12027. if (from_tty)
  12028. gdb_printf (_("Setting tracepoint %d's passcount to %d\n"),
  12029. tp->number, count);
  12030. }
  12031. /* Set passcount for tracepoint.
  12032. First command argument is passcount, second is tracepoint number.
  12033. If tracepoint number omitted, apply to most recently defined.
  12034. Also accepts special argument "all". */
  12035. static void
  12036. trace_pass_command (const char *args, int from_tty)
  12037. {
  12038. struct tracepoint *t1;
  12039. ULONGEST count;
  12040. if (args == 0 || *args == 0)
  12041. error (_("passcount command requires an "
  12042. "argument (count + optional TP num)"));
  12043. count = strtoulst (args, &args, 10); /* Count comes first, then TP num. */
  12044. args = skip_spaces (args);
  12045. if (*args && strncasecmp (args, "all", 3) == 0)
  12046. {
  12047. args += 3; /* Skip special argument "all". */
  12048. if (*args)
  12049. error (_("Junk at end of arguments."));
  12050. for (breakpoint *b : all_tracepoints ())
  12051. {
  12052. t1 = (struct tracepoint *) b;
  12053. trace_pass_set_count (t1, count, from_tty);
  12054. }
  12055. }
  12056. else if (*args == '\0')
  12057. {
  12058. t1 = get_tracepoint_by_number (&args, NULL);
  12059. if (t1)
  12060. trace_pass_set_count (t1, count, from_tty);
  12061. }
  12062. else
  12063. {
  12064. number_or_range_parser parser (args);
  12065. while (!parser.finished ())
  12066. {
  12067. t1 = get_tracepoint_by_number (&args, &parser);
  12068. if (t1)
  12069. trace_pass_set_count (t1, count, from_tty);
  12070. }
  12071. }
  12072. }
  12073. struct tracepoint *
  12074. get_tracepoint (int num)
  12075. {
  12076. for (breakpoint *t : all_tracepoints ())
  12077. if (t->number == num)
  12078. return (struct tracepoint *) t;
  12079. return NULL;
  12080. }
  12081. /* Find the tracepoint with the given target-side number (which may be
  12082. different from the tracepoint number after disconnecting and
  12083. reconnecting). */
  12084. struct tracepoint *
  12085. get_tracepoint_by_number_on_target (int num)
  12086. {
  12087. for (breakpoint *b : all_tracepoints ())
  12088. {
  12089. struct tracepoint *t = (struct tracepoint *) b;
  12090. if (t->number_on_target == num)
  12091. return t;
  12092. }
  12093. return NULL;
  12094. }
  12095. /* Utility: parse a tracepoint number and look it up in the list.
  12096. If STATE is not NULL, use, get_number_or_range_state and ignore ARG.
  12097. If the argument is missing, the most recent tracepoint
  12098. (tracepoint_count) is returned. */
  12099. struct tracepoint *
  12100. get_tracepoint_by_number (const char **arg,
  12101. number_or_range_parser *parser)
  12102. {
  12103. int tpnum;
  12104. const char *instring = arg == NULL ? NULL : *arg;
  12105. if (parser != NULL)
  12106. {
  12107. gdb_assert (!parser->finished ());
  12108. tpnum = parser->get_number ();
  12109. }
  12110. else if (arg == NULL || *arg == NULL || ! **arg)
  12111. tpnum = tracepoint_count;
  12112. else
  12113. tpnum = get_number (arg);
  12114. if (tpnum <= 0)
  12115. {
  12116. if (instring && *instring)
  12117. gdb_printf (_("bad tracepoint number at or near '%s'\n"),
  12118. instring);
  12119. else
  12120. gdb_printf (_("No previous tracepoint\n"));
  12121. return NULL;
  12122. }
  12123. for (breakpoint *t : all_tracepoints ())
  12124. if (t->number == tpnum)
  12125. return (struct tracepoint *) t;
  12126. gdb_printf ("No tracepoint number %d.\n", tpnum);
  12127. return NULL;
  12128. }
  12129. void
  12130. print_recreate_thread (struct breakpoint *b, struct ui_file *fp)
  12131. {
  12132. if (b->thread != -1)
  12133. gdb_printf (fp, " thread %d", b->thread);
  12134. if (b->task != 0)
  12135. gdb_printf (fp, " task %d", b->task);
  12136. gdb_printf (fp, "\n");
  12137. }
  12138. /* Save information on user settable breakpoints (watchpoints, etc) to
  12139. a new script file named FILENAME. If FILTER is non-NULL, call it
  12140. on each breakpoint and only include the ones for which it returns
  12141. true. */
  12142. static void
  12143. save_breakpoints (const char *filename, int from_tty,
  12144. bool (*filter) (const struct breakpoint *))
  12145. {
  12146. int any = 0;
  12147. int extra_trace_bits = 0;
  12148. if (filename == 0 || *filename == 0)
  12149. error (_("Argument required (file name in which to save)"));
  12150. /* See if we have anything to save. */
  12151. for (breakpoint *tp : all_breakpoints ())
  12152. {
  12153. /* Skip internal and momentary breakpoints. */
  12154. if (!user_breakpoint_p (tp))
  12155. continue;
  12156. /* If we have a filter, only save the breakpoints it accepts. */
  12157. if (filter && !filter (tp))
  12158. continue;
  12159. any = 1;
  12160. if (is_tracepoint (tp))
  12161. {
  12162. extra_trace_bits = 1;
  12163. /* We can stop searching. */
  12164. break;
  12165. }
  12166. }
  12167. if (!any)
  12168. {
  12169. warning (_("Nothing to save."));
  12170. return;
  12171. }
  12172. gdb::unique_xmalloc_ptr<char> expanded_filename (tilde_expand (filename));
  12173. stdio_file fp;
  12174. if (!fp.open (expanded_filename.get (), "w"))
  12175. error (_("Unable to open file '%s' for saving (%s)"),
  12176. expanded_filename.get (), safe_strerror (errno));
  12177. if (extra_trace_bits)
  12178. save_trace_state_variables (&fp);
  12179. for (breakpoint *tp : all_breakpoints ())
  12180. {
  12181. /* Skip internal and momentary breakpoints. */
  12182. if (!user_breakpoint_p (tp))
  12183. continue;
  12184. /* If we have a filter, only save the breakpoints it accepts. */
  12185. if (filter && !filter (tp))
  12186. continue;
  12187. tp->ops->print_recreate (tp, &fp);
  12188. /* Note, we can't rely on tp->number for anything, as we can't
  12189. assume the recreated breakpoint numbers will match. Use $bpnum
  12190. instead. */
  12191. if (tp->cond_string)
  12192. fp.printf (" condition $bpnum %s\n", tp->cond_string.get ());
  12193. if (tp->ignore_count)
  12194. fp.printf (" ignore $bpnum %d\n", tp->ignore_count);
  12195. if (tp->type != bp_dprintf && tp->commands)
  12196. {
  12197. fp.puts (" commands\n");
  12198. current_uiout->redirect (&fp);
  12199. try
  12200. {
  12201. print_command_lines (current_uiout, tp->commands.get (), 2);
  12202. }
  12203. catch (const gdb_exception &ex)
  12204. {
  12205. current_uiout->redirect (NULL);
  12206. throw;
  12207. }
  12208. current_uiout->redirect (NULL);
  12209. fp.puts (" end\n");
  12210. }
  12211. if (tp->enable_state == bp_disabled)
  12212. fp.puts ("disable $bpnum\n");
  12213. /* If this is a multi-location breakpoint, check if the locations
  12214. should be individually disabled. Watchpoint locations are
  12215. special, and not user visible. */
  12216. if (!is_watchpoint (tp) && tp->loc && tp->loc->next)
  12217. {
  12218. int n = 1;
  12219. for (bp_location *loc : tp->locations ())
  12220. {
  12221. if (!loc->enabled)
  12222. fp.printf ("disable $bpnum.%d\n", n);
  12223. n++;
  12224. }
  12225. }
  12226. }
  12227. if (extra_trace_bits && !default_collect.empty ())
  12228. fp.printf ("set default-collect %s\n", default_collect.c_str ());
  12229. if (from_tty)
  12230. gdb_printf (_("Saved to file '%s'.\n"), expanded_filename.get ());
  12231. }
  12232. /* The `save breakpoints' command. */
  12233. static void
  12234. save_breakpoints_command (const char *args, int from_tty)
  12235. {
  12236. save_breakpoints (args, from_tty, NULL);
  12237. }
  12238. /* The `save tracepoints' command. */
  12239. static void
  12240. save_tracepoints_command (const char *args, int from_tty)
  12241. {
  12242. save_breakpoints (args, from_tty, is_tracepoint);
  12243. }
  12244. /* This help string is used to consolidate all the help string for specifying
  12245. locations used by several commands. */
  12246. #define LOCATION_HELP_STRING \
  12247. "Linespecs are colon-separated lists of location parameters, such as\n\
  12248. source filename, function name, label name, and line number.\n\
  12249. Example: To specify the start of a label named \"the_top\" in the\n\
  12250. function \"fact\" in the file \"factorial.c\", use\n\
  12251. \"factorial.c:fact:the_top\".\n\
  12252. \n\
  12253. Address locations begin with \"*\" and specify an exact address in the\n\
  12254. program. Example: To specify the fourth byte past the start function\n\
  12255. \"main\", use \"*main + 4\".\n\
  12256. \n\
  12257. Explicit locations are similar to linespecs but use an option/argument\n\
  12258. syntax to specify location parameters.\n\
  12259. Example: To specify the start of the label named \"the_top\" in the\n\
  12260. function \"fact\" in the file \"factorial.c\", use \"-source factorial.c\n\
  12261. -function fact -label the_top\".\n\
  12262. \n\
  12263. By default, a specified function is matched against the program's\n\
  12264. functions in all scopes. For C++, this means in all namespaces and\n\
  12265. classes. For Ada, this means in all packages. E.g., in C++,\n\
  12266. \"func()\" matches \"A::func()\", \"A::B::func()\", etc. The\n\
  12267. \"-qualified\" flag overrides this behavior, making GDB interpret the\n\
  12268. specified name as a complete fully-qualified name instead."
  12269. /* This help string is used for the break, hbreak, tbreak and thbreak
  12270. commands. It is defined as a macro to prevent duplication.
  12271. COMMAND should be a string constant containing the name of the
  12272. command. */
  12273. #define BREAK_ARGS_HELP(command) \
  12274. command" [PROBE_MODIFIER] [LOCATION] [thread THREADNUM]\n\
  12275. \t[-force-condition] [if CONDITION]\n\
  12276. PROBE_MODIFIER shall be present if the command is to be placed in a\n\
  12277. probe point. Accepted values are `-probe' (for a generic, automatically\n\
  12278. guessed probe type), `-probe-stap' (for a SystemTap probe) or \n\
  12279. `-probe-dtrace' (for a DTrace probe).\n\
  12280. LOCATION may be a linespec, address, or explicit location as described\n\
  12281. below.\n\
  12282. \n\
  12283. With no LOCATION, uses current execution address of the selected\n\
  12284. stack frame. This is useful for breaking on return to a stack frame.\n\
  12285. \n\
  12286. THREADNUM is the number from \"info threads\".\n\
  12287. CONDITION is a boolean expression.\n\
  12288. \n\
  12289. With the \"-force-condition\" flag, the condition is defined even when\n\
  12290. it is invalid for all current locations.\n\
  12291. \n" LOCATION_HELP_STRING "\n\n\
  12292. Multiple breakpoints at one place are permitted, and useful if their\n\
  12293. conditions are different.\n\
  12294. \n\
  12295. Do \"help breakpoints\" for info on other commands dealing with breakpoints."
  12296. /* List of subcommands for "catch". */
  12297. static struct cmd_list_element *catch_cmdlist;
  12298. /* List of subcommands for "tcatch". */
  12299. static struct cmd_list_element *tcatch_cmdlist;
  12300. void
  12301. add_catch_command (const char *name, const char *docstring,
  12302. cmd_func_ftype *func,
  12303. completer_ftype *completer,
  12304. void *user_data_catch,
  12305. void *user_data_tcatch)
  12306. {
  12307. struct cmd_list_element *command;
  12308. command = add_cmd (name, class_breakpoint, docstring,
  12309. &catch_cmdlist);
  12310. command->func = func;
  12311. command->set_context (user_data_catch);
  12312. set_cmd_completer (command, completer);
  12313. command = add_cmd (name, class_breakpoint, docstring,
  12314. &tcatch_cmdlist);
  12315. command->func = func;
  12316. command->set_context (user_data_tcatch);
  12317. set_cmd_completer (command, completer);
  12318. }
  12319. /* Zero if any of the breakpoint's locations could be a location where
  12320. functions have been inlined, nonzero otherwise. */
  12321. static int
  12322. is_non_inline_function (struct breakpoint *b)
  12323. {
  12324. /* The shared library event breakpoint is set on the address of a
  12325. non-inline function. */
  12326. if (b->type == bp_shlib_event)
  12327. return 1;
  12328. return 0;
  12329. }
  12330. /* Nonzero if the specified PC cannot be a location where functions
  12331. have been inlined. */
  12332. int
  12333. pc_at_non_inline_function (const address_space *aspace, CORE_ADDR pc,
  12334. const target_waitstatus &ws)
  12335. {
  12336. for (breakpoint *b : all_breakpoints ())
  12337. {
  12338. if (!is_non_inline_function (b))
  12339. continue;
  12340. for (bp_location *bl : b->locations ())
  12341. {
  12342. if (!bl->shlib_disabled
  12343. && bpstat_check_location (bl, aspace, pc, ws))
  12344. return 1;
  12345. }
  12346. }
  12347. return 0;
  12348. }
  12349. /* Remove any references to OBJFILE which is going to be freed. */
  12350. void
  12351. breakpoint_free_objfile (struct objfile *objfile)
  12352. {
  12353. for (bp_location *loc : all_bp_locations ())
  12354. if (loc->symtab != NULL && loc->symtab->compunit ()->objfile () == objfile)
  12355. loc->symtab = NULL;
  12356. }
  12357. void
  12358. initialize_breakpoint_ops (void)
  12359. {
  12360. static int initialized = 0;
  12361. struct breakpoint_ops *ops;
  12362. if (initialized)
  12363. return;
  12364. initialized = 1;
  12365. /* The breakpoint_ops structure to be inherit by all kinds of
  12366. breakpoints (real breakpoints, i.e., user "break" breakpoints,
  12367. internal and momentary breakpoints, etc.). */
  12368. ops = &bkpt_base_breakpoint_ops;
  12369. *ops = base_breakpoint_ops;
  12370. ops->re_set = bkpt_re_set;
  12371. ops->insert_location = bkpt_insert_location;
  12372. ops->remove_location = bkpt_remove_location;
  12373. ops->breakpoint_hit = bkpt_breakpoint_hit;
  12374. ops->create_sals_from_location = bkpt_create_sals_from_location;
  12375. ops->create_breakpoints_sal = bkpt_create_breakpoints_sal;
  12376. ops->decode_location = bkpt_decode_location;
  12377. /* The breakpoint_ops structure to be used in regular breakpoints. */
  12378. ops = &bkpt_breakpoint_ops;
  12379. *ops = bkpt_base_breakpoint_ops;
  12380. ops->re_set = bkpt_re_set;
  12381. ops->resources_needed = bkpt_resources_needed;
  12382. ops->print_it = bkpt_print_it;
  12383. ops->print_mention = bkpt_print_mention;
  12384. ops->print_recreate = bkpt_print_recreate;
  12385. /* Ranged breakpoints. */
  12386. ops = &ranged_breakpoint_ops;
  12387. *ops = bkpt_breakpoint_ops;
  12388. ops->breakpoint_hit = breakpoint_hit_ranged_breakpoint;
  12389. ops->resources_needed = resources_needed_ranged_breakpoint;
  12390. ops->print_it = print_it_ranged_breakpoint;
  12391. ops->print_one = print_one_ranged_breakpoint;
  12392. ops->print_one_detail = print_one_detail_ranged_breakpoint;
  12393. ops->print_mention = print_mention_ranged_breakpoint;
  12394. ops->print_recreate = print_recreate_ranged_breakpoint;
  12395. /* Internal breakpoints. */
  12396. ops = &internal_breakpoint_ops;
  12397. *ops = bkpt_base_breakpoint_ops;
  12398. ops->re_set = internal_bkpt_re_set;
  12399. ops->check_status = internal_bkpt_check_status;
  12400. ops->print_it = internal_bkpt_print_it;
  12401. ops->print_mention = internal_bkpt_print_mention;
  12402. /* Momentary breakpoints. */
  12403. ops = &momentary_breakpoint_ops;
  12404. *ops = bkpt_base_breakpoint_ops;
  12405. ops->re_set = momentary_bkpt_re_set;
  12406. ops->check_status = momentary_bkpt_check_status;
  12407. ops->print_it = momentary_bkpt_print_it;
  12408. ops->print_mention = momentary_bkpt_print_mention;
  12409. /* Probe breakpoints. */
  12410. ops = &bkpt_probe_breakpoint_ops;
  12411. *ops = bkpt_breakpoint_ops;
  12412. ops->insert_location = bkpt_probe_insert_location;
  12413. ops->remove_location = bkpt_probe_remove_location;
  12414. ops->create_sals_from_location = bkpt_probe_create_sals_from_location;
  12415. ops->decode_location = bkpt_probe_decode_location;
  12416. /* Watchpoints. */
  12417. ops = &watchpoint_breakpoint_ops;
  12418. *ops = base_breakpoint_ops;
  12419. ops->re_set = re_set_watchpoint;
  12420. ops->insert_location = insert_watchpoint;
  12421. ops->remove_location = remove_watchpoint;
  12422. ops->breakpoint_hit = breakpoint_hit_watchpoint;
  12423. ops->check_status = check_status_watchpoint;
  12424. ops->resources_needed = resources_needed_watchpoint;
  12425. ops->works_in_software_mode = works_in_software_mode_watchpoint;
  12426. ops->print_it = print_it_watchpoint;
  12427. ops->print_mention = print_mention_watchpoint;
  12428. ops->print_recreate = print_recreate_watchpoint;
  12429. ops->explains_signal = explains_signal_watchpoint;
  12430. /* Masked watchpoints. */
  12431. ops = &masked_watchpoint_breakpoint_ops;
  12432. *ops = watchpoint_breakpoint_ops;
  12433. ops->insert_location = insert_masked_watchpoint;
  12434. ops->remove_location = remove_masked_watchpoint;
  12435. ops->resources_needed = resources_needed_masked_watchpoint;
  12436. ops->works_in_software_mode = works_in_software_mode_masked_watchpoint;
  12437. ops->print_it = print_it_masked_watchpoint;
  12438. ops->print_one_detail = print_one_detail_masked_watchpoint;
  12439. ops->print_mention = print_mention_masked_watchpoint;
  12440. ops->print_recreate = print_recreate_masked_watchpoint;
  12441. /* Tracepoints. */
  12442. ops = &tracepoint_breakpoint_ops;
  12443. *ops = base_breakpoint_ops;
  12444. ops->re_set = tracepoint_re_set;
  12445. ops->breakpoint_hit = tracepoint_breakpoint_hit;
  12446. ops->print_one_detail = tracepoint_print_one_detail;
  12447. ops->print_mention = tracepoint_print_mention;
  12448. ops->print_recreate = tracepoint_print_recreate;
  12449. ops->create_sals_from_location = tracepoint_create_sals_from_location;
  12450. ops->create_breakpoints_sal = tracepoint_create_breakpoints_sal;
  12451. ops->decode_location = tracepoint_decode_location;
  12452. /* Probe tracepoints. */
  12453. ops = &tracepoint_probe_breakpoint_ops;
  12454. *ops = tracepoint_breakpoint_ops;
  12455. ops->create_sals_from_location = tracepoint_probe_create_sals_from_location;
  12456. ops->decode_location = tracepoint_probe_decode_location;
  12457. /* Static tracepoints with marker (`-m'). */
  12458. ops = &strace_marker_breakpoint_ops;
  12459. *ops = tracepoint_breakpoint_ops;
  12460. ops->create_sals_from_location = strace_marker_create_sals_from_location;
  12461. ops->create_breakpoints_sal = strace_marker_create_breakpoints_sal;
  12462. ops->decode_location = strace_marker_decode_location;
  12463. /* Solib-related catchpoints. */
  12464. ops = &catch_solib_breakpoint_ops;
  12465. *ops = base_breakpoint_ops;
  12466. ops->insert_location = insert_catch_solib;
  12467. ops->remove_location = remove_catch_solib;
  12468. ops->breakpoint_hit = breakpoint_hit_catch_solib;
  12469. ops->check_status = check_status_catch_solib;
  12470. ops->print_it = print_it_catch_solib;
  12471. ops->print_one = print_one_catch_solib;
  12472. ops->print_mention = print_mention_catch_solib;
  12473. ops->print_recreate = print_recreate_catch_solib;
  12474. ops = &dprintf_breakpoint_ops;
  12475. *ops = bkpt_base_breakpoint_ops;
  12476. ops->re_set = dprintf_re_set;
  12477. ops->resources_needed = bkpt_resources_needed;
  12478. ops->print_it = bkpt_print_it;
  12479. ops->print_mention = bkpt_print_mention;
  12480. ops->print_recreate = dprintf_print_recreate;
  12481. ops->after_condition_true = dprintf_after_condition_true;
  12482. ops->breakpoint_hit = dprintf_breakpoint_hit;
  12483. }
  12484. /* Chain containing all defined "enable breakpoint" subcommands. */
  12485. static struct cmd_list_element *enablebreaklist = NULL;
  12486. /* See breakpoint.h. */
  12487. cmd_list_element *commands_cmd_element = nullptr;
  12488. void _initialize_breakpoint ();
  12489. void
  12490. _initialize_breakpoint ()
  12491. {
  12492. struct cmd_list_element *c;
  12493. initialize_breakpoint_ops ();
  12494. gdb::observers::solib_unloaded.attach (disable_breakpoints_in_unloaded_shlib,
  12495. "breakpoint");
  12496. gdb::observers::free_objfile.attach (disable_breakpoints_in_freed_objfile,
  12497. "breakpoint");
  12498. gdb::observers::memory_changed.attach (invalidate_bp_value_on_memory_change,
  12499. "breakpoint");
  12500. breakpoint_chain = 0;
  12501. /* Don't bother to call set_breakpoint_count. $bpnum isn't useful
  12502. before a breakpoint is set. */
  12503. breakpoint_count = 0;
  12504. tracepoint_count = 0;
  12505. add_com ("ignore", class_breakpoint, ignore_command, _("\
  12506. Set ignore-count of breakpoint number N to COUNT.\n\
  12507. Usage is `ignore N COUNT'."));
  12508. commands_cmd_element = add_com ("commands", class_breakpoint,
  12509. commands_command, _("\
  12510. Set commands to be executed when the given breakpoints are hit.\n\
  12511. Give a space-separated breakpoint list as argument after \"commands\".\n\
  12512. A list element can be a breakpoint number (e.g. `5') or a range of numbers\n\
  12513. (e.g. `5-7').\n\
  12514. With no argument, the targeted breakpoint is the last one set.\n\
  12515. The commands themselves follow starting on the next line.\n\
  12516. Type a line containing \"end\" to indicate the end of them.\n\
  12517. Give \"silent\" as the first line to make the breakpoint silent;\n\
  12518. then no output is printed when it is hit, except what the commands print."));
  12519. const auto cc_opts = make_condition_command_options_def_group (nullptr);
  12520. static std::string condition_command_help
  12521. = gdb::option::build_help (_("\
  12522. Specify breakpoint number N to break only if COND is true.\n\
  12523. Usage is `condition [OPTION] N COND', where N is an integer and COND\n\
  12524. is an expression to be evaluated whenever breakpoint N is reached.\n\
  12525. \n\
  12526. Options:\n\
  12527. %OPTIONS%"), cc_opts);
  12528. c = add_com ("condition", class_breakpoint, condition_command,
  12529. condition_command_help.c_str ());
  12530. set_cmd_completer_handle_brkchars (c, condition_completer);
  12531. c = add_com ("tbreak", class_breakpoint, tbreak_command, _("\
  12532. Set a temporary breakpoint.\n\
  12533. Like \"break\" except the breakpoint is only temporary,\n\
  12534. so it will be deleted when hit. Equivalent to \"break\" followed\n\
  12535. by using \"enable delete\" on the breakpoint number.\n\
  12536. \n"
  12537. BREAK_ARGS_HELP ("tbreak")));
  12538. set_cmd_completer (c, location_completer);
  12539. c = add_com ("hbreak", class_breakpoint, hbreak_command, _("\
  12540. Set a hardware assisted breakpoint.\n\
  12541. Like \"break\" except the breakpoint requires hardware support,\n\
  12542. some target hardware may not have this support.\n\
  12543. \n"
  12544. BREAK_ARGS_HELP ("hbreak")));
  12545. set_cmd_completer (c, location_completer);
  12546. c = add_com ("thbreak", class_breakpoint, thbreak_command, _("\
  12547. Set a temporary hardware assisted breakpoint.\n\
  12548. Like \"hbreak\" except the breakpoint is only temporary,\n\
  12549. so it will be deleted when hit.\n\
  12550. \n"
  12551. BREAK_ARGS_HELP ("thbreak")));
  12552. set_cmd_completer (c, location_completer);
  12553. cmd_list_element *enable_cmd
  12554. = add_prefix_cmd ("enable", class_breakpoint, enable_command, _("\
  12555. Enable all or some breakpoints.\n\
  12556. Usage: enable [BREAKPOINTNUM]...\n\
  12557. Give breakpoint numbers (separated by spaces) as arguments.\n\
  12558. With no subcommand, breakpoints are enabled until you command otherwise.\n\
  12559. This is used to cancel the effect of the \"disable\" command.\n\
  12560. With a subcommand you can enable temporarily."),
  12561. &enablelist, 1, &cmdlist);
  12562. add_com_alias ("en", enable_cmd, class_breakpoint, 1);
  12563. add_prefix_cmd ("breakpoints", class_breakpoint, enable_command, _("\
  12564. Enable all or some breakpoints.\n\
  12565. Usage: enable breakpoints [BREAKPOINTNUM]...\n\
  12566. Give breakpoint numbers (separated by spaces) as arguments.\n\
  12567. This is used to cancel the effect of the \"disable\" command.\n\
  12568. May be abbreviated to simply \"enable\"."),
  12569. &enablebreaklist, 1, &enablelist);
  12570. add_cmd ("once", no_class, enable_once_command, _("\
  12571. Enable some breakpoints for one hit.\n\
  12572. Usage: enable breakpoints once BREAKPOINTNUM...\n\
  12573. If a breakpoint is hit while enabled in this fashion, it becomes disabled."),
  12574. &enablebreaklist);
  12575. add_cmd ("delete", no_class, enable_delete_command, _("\
  12576. Enable some breakpoints and delete when hit.\n\
  12577. Usage: enable breakpoints delete BREAKPOINTNUM...\n\
  12578. If a breakpoint is hit while enabled in this fashion, it is deleted."),
  12579. &enablebreaklist);
  12580. add_cmd ("count", no_class, enable_count_command, _("\
  12581. Enable some breakpoints for COUNT hits.\n\
  12582. Usage: enable breakpoints count COUNT BREAKPOINTNUM...\n\
  12583. If a breakpoint is hit while enabled in this fashion,\n\
  12584. the count is decremented; when it reaches zero, the breakpoint is disabled."),
  12585. &enablebreaklist);
  12586. add_cmd ("delete", no_class, enable_delete_command, _("\
  12587. Enable some breakpoints and delete when hit.\n\
  12588. Usage: enable delete BREAKPOINTNUM...\n\
  12589. If a breakpoint is hit while enabled in this fashion, it is deleted."),
  12590. &enablelist);
  12591. add_cmd ("once", no_class, enable_once_command, _("\
  12592. Enable some breakpoints for one hit.\n\
  12593. Usage: enable once BREAKPOINTNUM...\n\
  12594. If a breakpoint is hit while enabled in this fashion, it becomes disabled."),
  12595. &enablelist);
  12596. add_cmd ("count", no_class, enable_count_command, _("\
  12597. Enable some breakpoints for COUNT hits.\n\
  12598. Usage: enable count COUNT BREAKPOINTNUM...\n\
  12599. If a breakpoint is hit while enabled in this fashion,\n\
  12600. the count is decremented; when it reaches zero, the breakpoint is disabled."),
  12601. &enablelist);
  12602. cmd_list_element *disable_cmd
  12603. = add_prefix_cmd ("disable", class_breakpoint, disable_command, _("\
  12604. Disable all or some breakpoints.\n\
  12605. Usage: disable [BREAKPOINTNUM]...\n\
  12606. Arguments are breakpoint numbers with spaces in between.\n\
  12607. To disable all breakpoints, give no argument.\n\
  12608. A disabled breakpoint is not forgotten, but has no effect until re-enabled."),
  12609. &disablelist, 1, &cmdlist);
  12610. add_com_alias ("dis", disable_cmd, class_breakpoint, 1);
  12611. add_com_alias ("disa", disable_cmd, class_breakpoint, 1);
  12612. add_cmd ("breakpoints", class_breakpoint, disable_command, _("\
  12613. Disable all or some breakpoints.\n\
  12614. Usage: disable breakpoints [BREAKPOINTNUM]...\n\
  12615. Arguments are breakpoint numbers with spaces in between.\n\
  12616. To disable all breakpoints, give no argument.\n\
  12617. A disabled breakpoint is not forgotten, but has no effect until re-enabled.\n\
  12618. This command may be abbreviated \"disable\"."),
  12619. &disablelist);
  12620. cmd_list_element *delete_cmd
  12621. = add_prefix_cmd ("delete", class_breakpoint, delete_command, _("\
  12622. Delete all or some breakpoints.\n\
  12623. Usage: delete [BREAKPOINTNUM]...\n\
  12624. Arguments are breakpoint numbers with spaces in between.\n\
  12625. To delete all breakpoints, give no argument.\n\
  12626. \n\
  12627. Also a prefix command for deletion of other GDB objects."),
  12628. &deletelist, 1, &cmdlist);
  12629. add_com_alias ("d", delete_cmd, class_breakpoint, 1);
  12630. add_com_alias ("del", delete_cmd, class_breakpoint, 1);
  12631. add_cmd ("breakpoints", class_breakpoint, delete_command, _("\
  12632. Delete all or some breakpoints or auto-display expressions.\n\
  12633. Usage: delete breakpoints [BREAKPOINTNUM]...\n\
  12634. Arguments are breakpoint numbers with spaces in between.\n\
  12635. To delete all breakpoints, give no argument.\n\
  12636. This command may be abbreviated \"delete\"."),
  12637. &deletelist);
  12638. cmd_list_element *clear_cmd
  12639. = add_com ("clear", class_breakpoint, clear_command, _("\
  12640. Clear breakpoint at specified location.\n\
  12641. Argument may be a linespec, explicit, or address location as described below.\n\
  12642. \n\
  12643. With no argument, clears all breakpoints in the line that the selected frame\n\
  12644. is executing in.\n"
  12645. "\n" LOCATION_HELP_STRING "\n\n\
  12646. See also the \"delete\" command which clears breakpoints by number."));
  12647. add_com_alias ("cl", clear_cmd, class_breakpoint, 1);
  12648. cmd_list_element *break_cmd
  12649. = add_com ("break", class_breakpoint, break_command, _("\
  12650. Set breakpoint at specified location.\n"
  12651. BREAK_ARGS_HELP ("break")));
  12652. set_cmd_completer (break_cmd, location_completer);
  12653. add_com_alias ("b", break_cmd, class_run, 1);
  12654. add_com_alias ("br", break_cmd, class_run, 1);
  12655. add_com_alias ("bre", break_cmd, class_run, 1);
  12656. add_com_alias ("brea", break_cmd, class_run, 1);
  12657. cmd_list_element *info_breakpoints_cmd
  12658. = add_info ("breakpoints", info_breakpoints_command, _("\
  12659. Status of specified breakpoints (all user-settable breakpoints if no argument).\n\
  12660. The \"Type\" column indicates one of:\n\
  12661. \tbreakpoint - normal breakpoint\n\
  12662. \twatchpoint - watchpoint\n\
  12663. The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
  12664. the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
  12665. breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
  12666. address and file/line number respectively.\n\
  12667. \n\
  12668. Convenience variable \"$_\" and default examine address for \"x\"\n\
  12669. are set to the address of the last breakpoint listed unless the command\n\
  12670. is prefixed with \"server \".\n\n\
  12671. Convenience variable \"$bpnum\" contains the number of the last\n\
  12672. breakpoint set."));
  12673. add_info_alias ("b", info_breakpoints_cmd, 1);
  12674. add_cmd ("breakpoints", class_maintenance, maintenance_info_breakpoints, _("\
  12675. Status of all breakpoints, or breakpoint number NUMBER.\n\
  12676. The \"Type\" column indicates one of:\n\
  12677. \tbreakpoint - normal breakpoint\n\
  12678. \twatchpoint - watchpoint\n\
  12679. \tlongjmp - internal breakpoint used to step through longjmp()\n\
  12680. \tlongjmp resume - internal breakpoint at the target of longjmp()\n\
  12681. \tuntil - internal breakpoint used by the \"until\" command\n\
  12682. \tfinish - internal breakpoint used by the \"finish\" command\n\
  12683. The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
  12684. the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
  12685. breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
  12686. address and file/line number respectively.\n\
  12687. \n\
  12688. Convenience variable \"$_\" and default examine address for \"x\"\n\
  12689. are set to the address of the last breakpoint listed unless the command\n\
  12690. is prefixed with \"server \".\n\n\
  12691. Convenience variable \"$bpnum\" contains the number of the last\n\
  12692. breakpoint set."),
  12693. &maintenanceinfolist);
  12694. add_basic_prefix_cmd ("catch", class_breakpoint, _("\
  12695. Set catchpoints to catch events."),
  12696. &catch_cmdlist,
  12697. 0/*allow-unknown*/, &cmdlist);
  12698. add_basic_prefix_cmd ("tcatch", class_breakpoint, _("\
  12699. Set temporary catchpoints to catch events."),
  12700. &tcatch_cmdlist,
  12701. 0/*allow-unknown*/, &cmdlist);
  12702. add_catch_command ("load", _("Catch loads of shared libraries.\n\
  12703. Usage: catch load [REGEX]\n\
  12704. If REGEX is given, only stop for libraries matching the regular expression."),
  12705. catch_load_command_1,
  12706. NULL,
  12707. CATCH_PERMANENT,
  12708. CATCH_TEMPORARY);
  12709. add_catch_command ("unload", _("Catch unloads of shared libraries.\n\
  12710. Usage: catch unload [REGEX]\n\
  12711. If REGEX is given, only stop for libraries matching the regular expression."),
  12712. catch_unload_command_1,
  12713. NULL,
  12714. CATCH_PERMANENT,
  12715. CATCH_TEMPORARY);
  12716. const auto opts = make_watch_options_def_group (nullptr);
  12717. static const std::string watch_help = gdb::option::build_help (_("\
  12718. Set a watchpoint for EXPRESSION.\n\
  12719. Usage: watch [-location] EXPRESSION\n\
  12720. \n\
  12721. Options:\n\
  12722. %OPTIONS%\n\
  12723. \n\
  12724. A watchpoint stops execution of your program whenever the value of\n\
  12725. an expression changes."), opts);
  12726. c = add_com ("watch", class_breakpoint, watch_command,
  12727. watch_help.c_str ());
  12728. set_cmd_completer_handle_brkchars (c, watch_command_completer);
  12729. static const std::string rwatch_help = gdb::option::build_help (_("\
  12730. Set a read watchpoint for EXPRESSION.\n\
  12731. Usage: rwatch [-location] EXPRESSION\n\
  12732. \n\
  12733. Options:\n\
  12734. %OPTIONS%\n\
  12735. \n\
  12736. A read watchpoint stops execution of your program whenever the value of\n\
  12737. an expression is read."), opts);
  12738. c = add_com ("rwatch", class_breakpoint, rwatch_command,
  12739. rwatch_help.c_str ());
  12740. set_cmd_completer_handle_brkchars (c, watch_command_completer);
  12741. static const std::string awatch_help = gdb::option::build_help (_("\
  12742. Set an access watchpoint for EXPRESSION.\n\
  12743. Usage: awatch [-location] EXPRESSION\n\
  12744. \n\
  12745. Options:\n\
  12746. %OPTIONS%\n\
  12747. \n\
  12748. An access watchpoint stops execution of your program whenever the value\n\
  12749. of an expression is either read or written."), opts);
  12750. c = add_com ("awatch", class_breakpoint, awatch_command,
  12751. awatch_help.c_str ());
  12752. set_cmd_completer_handle_brkchars (c, watch_command_completer);
  12753. add_info ("watchpoints", info_watchpoints_command, _("\
  12754. Status of specified watchpoints (all watchpoints if no argument)."));
  12755. /* XXX: cagney/2005-02-23: This should be a boolean, and should
  12756. respond to changes - contrary to the description. */
  12757. add_setshow_zinteger_cmd ("can-use-hw-watchpoints", class_support,
  12758. &can_use_hw_watchpoints, _("\
  12759. Set debugger's willingness to use watchpoint hardware."), _("\
  12760. Show debugger's willingness to use watchpoint hardware."), _("\
  12761. If zero, gdb will not use hardware for new watchpoints, even if\n\
  12762. such is available. (However, any hardware watchpoints that were\n\
  12763. created before setting this to nonzero, will continue to use watchpoint\n\
  12764. hardware.)"),
  12765. NULL,
  12766. show_can_use_hw_watchpoints,
  12767. &setlist, &showlist);
  12768. can_use_hw_watchpoints = 1;
  12769. /* Tracepoint manipulation commands. */
  12770. cmd_list_element *trace_cmd
  12771. = add_com ("trace", class_breakpoint, trace_command, _("\
  12772. Set a tracepoint at specified location.\n\
  12773. \n"
  12774. BREAK_ARGS_HELP ("trace") "\n\
  12775. Do \"help tracepoints\" for info on other tracepoint commands."));
  12776. set_cmd_completer (trace_cmd, location_completer);
  12777. add_com_alias ("tp", trace_cmd, class_breakpoint, 0);
  12778. add_com_alias ("tr", trace_cmd, class_breakpoint, 1);
  12779. add_com_alias ("tra", trace_cmd, class_breakpoint, 1);
  12780. add_com_alias ("trac", trace_cmd, class_breakpoint, 1);
  12781. c = add_com ("ftrace", class_breakpoint, ftrace_command, _("\
  12782. Set a fast tracepoint at specified location.\n\
  12783. \n"
  12784. BREAK_ARGS_HELP ("ftrace") "\n\
  12785. Do \"help tracepoints\" for info on other tracepoint commands."));
  12786. set_cmd_completer (c, location_completer);
  12787. c = add_com ("strace", class_breakpoint, strace_command, _("\
  12788. Set a static tracepoint at location or marker.\n\
  12789. \n\
  12790. strace [LOCATION] [if CONDITION]\n\
  12791. LOCATION may be a linespec, explicit, or address location (described below) \n\
  12792. or -m MARKER_ID.\n\n\
  12793. If a marker id is specified, probe the marker with that name. With\n\
  12794. no LOCATION, uses current execution address of the selected stack frame.\n\
  12795. Static tracepoints accept an extra collect action -- ``collect $_sdata''.\n\
  12796. This collects arbitrary user data passed in the probe point call to the\n\
  12797. tracing library. You can inspect it when analyzing the trace buffer,\n\
  12798. by printing the $_sdata variable like any other convenience variable.\n\
  12799. \n\
  12800. CONDITION is a boolean expression.\n\
  12801. \n" LOCATION_HELP_STRING "\n\n\
  12802. Multiple tracepoints at one place are permitted, and useful if their\n\
  12803. conditions are different.\n\
  12804. \n\
  12805. Do \"help breakpoints\" for info on other commands dealing with breakpoints.\n\
  12806. Do \"help tracepoints\" for info on other tracepoint commands."));
  12807. set_cmd_completer (c, location_completer);
  12808. cmd_list_element *info_tracepoints_cmd
  12809. = add_info ("tracepoints", info_tracepoints_command, _("\
  12810. Status of specified tracepoints (all tracepoints if no argument).\n\
  12811. Convenience variable \"$tpnum\" contains the number of the\n\
  12812. last tracepoint set."));
  12813. add_info_alias ("tp", info_tracepoints_cmd, 1);
  12814. cmd_list_element *delete_tracepoints_cmd
  12815. = add_cmd ("tracepoints", class_trace, delete_trace_command, _("\
  12816. Delete specified tracepoints.\n\
  12817. Arguments are tracepoint numbers, separated by spaces.\n\
  12818. No argument means delete all tracepoints."),
  12819. &deletelist);
  12820. add_alias_cmd ("tr", delete_tracepoints_cmd, class_trace, 1, &deletelist);
  12821. c = add_cmd ("tracepoints", class_trace, disable_trace_command, _("\
  12822. Disable specified tracepoints.\n\
  12823. Arguments are tracepoint numbers, separated by spaces.\n\
  12824. No argument means disable all tracepoints."),
  12825. &disablelist);
  12826. deprecate_cmd (c, "disable");
  12827. c = add_cmd ("tracepoints", class_trace, enable_trace_command, _("\
  12828. Enable specified tracepoints.\n\
  12829. Arguments are tracepoint numbers, separated by spaces.\n\
  12830. No argument means enable all tracepoints."),
  12831. &enablelist);
  12832. deprecate_cmd (c, "enable");
  12833. add_com ("passcount", class_trace, trace_pass_command, _("\
  12834. Set the passcount for a tracepoint.\n\
  12835. The trace will end when the tracepoint has been passed 'count' times.\n\
  12836. Usage: passcount COUNT TPNUM, where TPNUM may also be \"all\";\n\
  12837. if TPNUM is omitted, passcount refers to the last tracepoint defined."));
  12838. add_basic_prefix_cmd ("save", class_breakpoint,
  12839. _("Save breakpoint definitions as a script."),
  12840. &save_cmdlist,
  12841. 0/*allow-unknown*/, &cmdlist);
  12842. c = add_cmd ("breakpoints", class_breakpoint, save_breakpoints_command, _("\
  12843. Save current breakpoint definitions as a script.\n\
  12844. This includes all types of breakpoints (breakpoints, watchpoints,\n\
  12845. catchpoints, tracepoints). Use the 'source' command in another debug\n\
  12846. session to restore them."),
  12847. &save_cmdlist);
  12848. set_cmd_completer (c, filename_completer);
  12849. cmd_list_element *save_tracepoints_cmd
  12850. = add_cmd ("tracepoints", class_trace, save_tracepoints_command, _("\
  12851. Save current tracepoint definitions as a script.\n\
  12852. Use the 'source' command in another debug session to restore them."),
  12853. &save_cmdlist);
  12854. set_cmd_completer (save_tracepoints_cmd, filename_completer);
  12855. c = add_com_alias ("save-tracepoints", save_tracepoints_cmd, class_trace, 0);
  12856. deprecate_cmd (c, "save tracepoints");
  12857. add_setshow_prefix_cmd ("breakpoint", class_maintenance,
  12858. _("\
  12859. Breakpoint specific settings.\n\
  12860. Configure various breakpoint-specific variables such as\n\
  12861. pending breakpoint behavior."),
  12862. _("\
  12863. Breakpoint specific settings.\n\
  12864. Configure various breakpoint-specific variables such as\n\
  12865. pending breakpoint behavior."),
  12866. &breakpoint_set_cmdlist, &breakpoint_show_cmdlist,
  12867. &setlist, &showlist);
  12868. add_setshow_auto_boolean_cmd ("pending", no_class,
  12869. &pending_break_support, _("\
  12870. Set debugger's behavior regarding pending breakpoints."), _("\
  12871. Show debugger's behavior regarding pending breakpoints."), _("\
  12872. If on, an unrecognized breakpoint location will cause gdb to create a\n\
  12873. pending breakpoint. If off, an unrecognized breakpoint location results in\n\
  12874. an error. If auto, an unrecognized breakpoint location results in a\n\
  12875. user-query to see if a pending breakpoint should be created."),
  12876. NULL,
  12877. show_pending_break_support,
  12878. &breakpoint_set_cmdlist,
  12879. &breakpoint_show_cmdlist);
  12880. pending_break_support = AUTO_BOOLEAN_AUTO;
  12881. add_setshow_boolean_cmd ("auto-hw", no_class,
  12882. &automatic_hardware_breakpoints, _("\
  12883. Set automatic usage of hardware breakpoints."), _("\
  12884. Show automatic usage of hardware breakpoints."), _("\
  12885. If set, the debugger will automatically use hardware breakpoints for\n\
  12886. breakpoints set with \"break\" but falling in read-only memory. If not set,\n\
  12887. a warning will be emitted for such breakpoints."),
  12888. NULL,
  12889. show_automatic_hardware_breakpoints,
  12890. &breakpoint_set_cmdlist,
  12891. &breakpoint_show_cmdlist);
  12892. add_setshow_boolean_cmd ("always-inserted", class_support,
  12893. &always_inserted_mode, _("\
  12894. Set mode for inserting breakpoints."), _("\
  12895. Show mode for inserting breakpoints."), _("\
  12896. When this mode is on, breakpoints are inserted immediately as soon as\n\
  12897. they're created, kept inserted even when execution stops, and removed\n\
  12898. only when the user deletes them. When this mode is off (the default),\n\
  12899. breakpoints are inserted only when execution continues, and removed\n\
  12900. when execution stops."),
  12901. NULL,
  12902. &show_always_inserted_mode,
  12903. &breakpoint_set_cmdlist,
  12904. &breakpoint_show_cmdlist);
  12905. add_setshow_enum_cmd ("condition-evaluation", class_breakpoint,
  12906. condition_evaluation_enums,
  12907. &condition_evaluation_mode_1, _("\
  12908. Set mode of breakpoint condition evaluation."), _("\
  12909. Show mode of breakpoint condition evaluation."), _("\
  12910. When this is set to \"host\", breakpoint conditions will be\n\
  12911. evaluated on the host's side by GDB. When it is set to \"target\",\n\
  12912. breakpoint conditions will be downloaded to the target (if the target\n\
  12913. supports such feature) and conditions will be evaluated on the target's side.\n\
  12914. If this is set to \"auto\" (default), this will be automatically set to\n\
  12915. \"target\" if it supports condition evaluation, otherwise it will\n\
  12916. be set to \"host\"."),
  12917. &set_condition_evaluation_mode,
  12918. &show_condition_evaluation_mode,
  12919. &breakpoint_set_cmdlist,
  12920. &breakpoint_show_cmdlist);
  12921. add_com ("break-range", class_breakpoint, break_range_command, _("\
  12922. Set a breakpoint for an address range.\n\
  12923. break-range START-LOCATION, END-LOCATION\n\
  12924. where START-LOCATION and END-LOCATION can be one of the following:\n\
  12925. LINENUM, for that line in the current file,\n\
  12926. FILE:LINENUM, for that line in that file,\n\
  12927. +OFFSET, for that number of lines after the current line\n\
  12928. or the start of the range\n\
  12929. FUNCTION, for the first line in that function,\n\
  12930. FILE:FUNCTION, to distinguish among like-named static functions.\n\
  12931. *ADDRESS, for the instruction at that address.\n\
  12932. \n\
  12933. The breakpoint will stop execution of the inferior whenever it executes\n\
  12934. an instruction at any address within the [START-LOCATION, END-LOCATION]\n\
  12935. range (including START-LOCATION and END-LOCATION)."));
  12936. c = add_com ("dprintf", class_breakpoint, dprintf_command, _("\
  12937. Set a dynamic printf at specified location.\n\
  12938. dprintf location,format string,arg1,arg2,...\n\
  12939. location may be a linespec, explicit, or address location.\n"
  12940. "\n" LOCATION_HELP_STRING));
  12941. set_cmd_completer (c, location_completer);
  12942. add_setshow_enum_cmd ("dprintf-style", class_support,
  12943. dprintf_style_enums, &dprintf_style, _("\
  12944. Set the style of usage for dynamic printf."), _("\
  12945. Show the style of usage for dynamic printf."), _("\
  12946. This setting chooses how GDB will do a dynamic printf.\n\
  12947. If the value is \"gdb\", then the printing is done by GDB to its own\n\
  12948. console, as with the \"printf\" command.\n\
  12949. If the value is \"call\", the print is done by calling a function in your\n\
  12950. program; by default printf(), but you can choose a different function or\n\
  12951. output stream by setting dprintf-function and dprintf-channel."),
  12952. update_dprintf_commands, NULL,
  12953. &setlist, &showlist);
  12954. add_setshow_string_cmd ("dprintf-function", class_support,
  12955. &dprintf_function, _("\
  12956. Set the function to use for dynamic printf."), _("\
  12957. Show the function to use for dynamic printf."), NULL,
  12958. update_dprintf_commands, NULL,
  12959. &setlist, &showlist);
  12960. add_setshow_string_cmd ("dprintf-channel", class_support,
  12961. &dprintf_channel, _("\
  12962. Set the channel to use for dynamic printf."), _("\
  12963. Show the channel to use for dynamic printf."), NULL,
  12964. update_dprintf_commands, NULL,
  12965. &setlist, &showlist);
  12966. add_setshow_boolean_cmd ("disconnected-dprintf", no_class,
  12967. &disconnected_dprintf, _("\
  12968. Set whether dprintf continues after GDB disconnects."), _("\
  12969. Show whether dprintf continues after GDB disconnects."), _("\
  12970. Use this to let dprintf commands continue to hit and produce output\n\
  12971. even if GDB disconnects or detaches from the target."),
  12972. NULL,
  12973. NULL,
  12974. &setlist, &showlist);
  12975. add_com ("agent-printf", class_vars, agent_printf_command, _("\
  12976. Target agent only formatted printing, like the C \"printf\" function.\n\
  12977. Usage: agent-printf \"format string\", ARG1, ARG2, ARG3, ..., ARGN\n\
  12978. This supports most C printf format specifications, like %s, %d, etc.\n\
  12979. This is useful for formatted output in user-defined commands."));
  12980. automatic_hardware_breakpoints = true;
  12981. gdb::observers::about_to_proceed.attach (breakpoint_about_to_proceed,
  12982. "breakpoint");
  12983. gdb::observers::thread_exit.attach (remove_threaded_breakpoints,
  12984. "breakpoint");
  12985. }