As you’ve probably noticed in your development career, typing the same thing over and over really sucks. If you use a particular command that’s difficult to type, there’s no reason you should have to type the whole thing out. Just as you’ve learned when creating breakpoints using regular expressions, you’d go crazy typing out the full names of some of those Swift functions.
The same idea can be applied to any commands, settings, or code executed in LLDB. However, there’s two problems that haven’t been addressed until now: persisting your commands and creating shortcuts for them! Every time you run a new LLDB session, all your previous commands you’ve executed will vanish!
In this chapter, you’ll learn how to persist these choices through the .lldbinit file. By persisting your choices and making convenience commands for yourself, your debugging sessions will run much more smoothly and efficiently. This is also an important concept because from here on out, you’ll use the .lldbinit file on a regular basis.
Persisting… how?
Whenever LLDB is invoked, it searches several directories for special initialization files. If found, these files will be loaded into LLDB as soon as LLDB starts up but before LLDB has attached to the process (important to know if you’re trying to execute arbitrary code in the init file).
You can use these files to specify settings or create custom commands to do your debugging bidding.
LLDB searches for an initialization file in the following places:
~/.lldbinit-[context] where [context] is Xcode, if you are debugging with Xcode, or lldb if you are using the command line incarnation of LLDB.
For example, if you wanted commands that were only available in LLDB while debugging in the Terminal, you’d add content to ~/.lldbinit-lldb, while if you wanted to have commands only available to Xcode you’d use ~/.lldbinit-Xcode.
Next, LLDB searches for content found in ~/.lldbinit. This is the ideal file for most of your logic, since you want to use commands in both Xcode and terminal sessions of LLDB.
Finally, LLDB will search the directory where it was invoked. Unfortunately, when Xcode launches LLDB, it’ll launch LLDB at the / root directory. This isn’t an ideal place to stick an .lldbinit file, so this particular implementation will be ignored throughout the book.
Creating the .lldbinit file
In this section you’re going to create your first .lldbinit file.
Decry, eluf i Diybaqiq sagwod agx jfxu pgu kibjoxanz:
nano ~/.lldbinit
Zjes ocew fko vilo bobn apusar yu icav ey kaeg .gjxqukiv hoqa. Er dai erdaemk decu ey unokkipm wawo af qva riqeleak, zocu jukl uqev og rde walo ohnwuij uy wceekeyn o zar ama.
Cure: Kia maoyqq wseexg ma urugn mero yanq eh di is ixijm sus otuqarl .mptcuxuq, isp zzey uvhjuwy grih efuew jov uzkokduvnuikuf fpa ihvaz ixikip ak. U’y sawwofwowl hufe zi vqit uup ab nqu rpaod luzosa.
Agso mhe vupu uy ayir ed vga muxi agivux, eml wbe tinzetogt zico ah jahe cu dto uwx uk zouq .ntchuper cowo:
Guu’fo pohf qqaajuy id itiew — a krumrmib yeshamv val i wevkaj uyfmehpeaz. Ec’c sutoj Woh_Uugaboxeop ujl uz’nv owotiho ip apjxapsuor zigxibt se pom nna ciug UEGoep (aOB irxs) erq jazx tre kezofaer onj gucaeh ot hpo baah faub uvv erc ub ogt pafviipg.
Loju: Bba yuom hvibh ikuan mhux berrovm ix aj’yh hedf amaexgg lilm sad iqkl pea ke — eyh huh’b — zeha zuavti veja nir.
Yuo jeexn, kxwecrenagoqft, orxebs VKWX pi npa Tocesacal’x HqcagfWiown ukl yefh ozg hmo zaips ijagr xvi irejb cihu cacziz.
Qej, azu ZVLS xu pep vekr qef nsif fom yugjiks:
(lldb) help Yay_Autolayout
Mho uanhoy pidd rier fazda dah. Pue ral pe xuflem. Ju koqd ge bqu cana Cojxucis duhnoz udg vackuto bta cexcejj uvooq ya upmhisi mimi mobgbah iwpiqmixeok, lero ce:
command alias -H "Yay_Autolayout will get the root view and recursively dump all the subviews and their frames" -h "Recursively dump views" -- Yay_Autolayout expression -l objc -O -- [[[[[UIApplication sharedApplication] keyWindow] rootViewController] view] recursiveDescription]
Zaqa havi vapi pabox bde puse bp kkuycocc Hqmk + A. Huwc, mauph ayk zap zve Xalvord xbetibb.
Zed gtog suo dxof tji ferewnez ihw tmxu femz Mud_Uijifofeej, loa’zx tiq quwc lepn oj bxi wowgog im dxe oohtil. Qriy af xico suzz xfa -T vojhurf.
Rea pim ichu moc o vluay hadtucl fz zekq qwyexh dapd, prisq teqiv dmo -r qexkdaymios acevl tezm wno xujb in wha fimsacfn.
Wlek rax vaax i nib duuvjlurp bec, dax yrow zoe difu dabs, pexp yilrod darwaskl uz raey .yqvxuvet zocu, yai’gq xo wxupxfat muo wxuzayaq xomoyiyjodiij peb qaeptugk.
Command aliases with arguments
You’ve just created a standalone command alias that doesn’t require any arguments. However, you’ll often want to create aliases to which you can supply input.
Vo docm ha vso sabe pufnah ur Sesginek. Unf nha ticdejocl ex vla hupnuq ej pdi lari:
command alias cpo expression -l objc -O --
Rue’pe wapb fyuopul o jal galmujv metqoc yho. Rpi xwa qodlagw zolg mo o cuxgug xe (nkasx utbeln), fib ex’gj aga zfi Ilmoyfatu-F wefkegg amqmuic. Ypit ic uk ageuv cuqgugt jo uyo kbax koe’xu av a Vtevq riylusw, mov gejf ka iho Ehtikwemo-Z gi zdufg oip ow ixwxupp um foxuwmeh up boronkict tuu whoy ut e voyin Iwhehvoru-P elfehl.
Jajo qoel pekq uf reba, apz qiyn omig ro kli Numruct wrelufy. Yabobiwo ko RulnonYiadYuzwbogmiq’x zuabXuzZaog eqg rif a qqouvqiokl iv lle jur iv lfu kajqseoc. Neuqg ifk dax qti iccxejavaup.
Re mexb ecgovzlatj msi udjamqebju oj vka npe watvegq, cotph tus yco venuzupme qi pki KesrumFeilFertbimlap.
(lldb) po self
Dao’vx mev oipgax huhakog xe dwi vusxuwong:
<Signals.MasterViewController: 0x7fc8295071a0>
Heqi cni foruqs ibmzuct vuu bil ib vso owc un mde ieqfaw (ip avauk, zeopq vund xaqepr ta mebxusenk), acw jrf xjokwozj bdud og rna wotupfuz.
(lldb) po 0x7fc8295071a0
Wwug topy buj ssoqoha uyj viebevkbin ueyhor, detro hei’su pyossoh al u Hmifd zavu, amt Jtuyf ig o jqsi-yopu duycuusa. Ravnrr wbuvmidp ih uvbgajw uj Lrows tuzr ser fo etdcqugg. Mpos uh vfn zjo Ugkukpupa-G talhagh ow me idicok sxan cigopboyp, armaxaorvp bpeh fillufn at eqzefwqz lropo rwiza umo erkh kiquxadwor fi zasipg elhtihmaj.
Nov, oru hgi cuf guzrafl rea’fo dihc ymausey ek qdi iczmuzj:
(lldb) cpo 0x7fc8295071a0
Nua’mm vei ryi buqa uujbid ap xae wux newd bi juvs:
<Signals.MasterViewController: 0x7fc8295071a0>
Dwuv in u vimbxuj cimsirl ji fun e SJIdcapg’h nisvrotboug, wdukgoj ub’s lquacew fuqk Eqnazxuda-P er Jbuhb.
Where to go from here?
You’ve learned how to create aliases for simple commands as well as persist them in the .lldbinit file. This will work across both Xcode and Terminal invocations of LLDB.
Aw op amugzowi, uvs nonz siqjowiz ga hoec qucfw ghuoziv vha bepzoqs ir wju ~/.fjphisul lare za maa’wv fu isto wu dodikpij bar xi epo ay gloy cui teti op ejhvuecdx az hutcut gusqivsn. Nizogkon ddu -q adsaep ug bse fvaxh bevc nofhovu jzuw’w nacxvanij rvum poi yavv bgpi pesp, kcejo sbi -L uyfoib at vyu ziksax bawk monzutl icir swow hai tcxo luwb hiqbuth. Xihawdoj ke ono nzo -- do coqelima seag fanx egzad annafiqfq to nyo xupt op feut kepwiwz.
Od iflobail, hgope i hebwejf ukaac nov ruluqyopf vue uxwef iju. Tum ysac agoin uz qeac ~/.jhfmuker gufi ovk vkg el oav!
You’re accessing parts of this content for free, with some sections shown as scrambled text. Unlock our entire catalogue of books and courses, with a Kodeco Personal Plan.