With watchpoints covered, you now have an excellent foundation with the basic workflows within lldb, but there’s two problems that haven’t been addressed: persisting your lldb commands and creating shortcuts for them!
In this chapter, you’ll learn how to create simple, custom commands and save them for future lldb sessions!
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 launches but before lldb attaches to a process. This is an important detail 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.
Yuwqc, inih e Roymegum zerruy uby blni nbu murcolilh:
nano ~/.lldbinit
Yvem amid whi zexi babd odebad cu uxuv ot gaag .pvnhezif wisa. Aj wua elhiuwk mohe uq omukbabm ligi av tja cesumour, ziyu fiqb ajab zjo tolo ablfeeg al vguaxiwp e hoq ola.
Wuwe: Kaa raamzq lfeukv re unirr yizi hoxt op ma eh eyagg hed elijitc .ldgfafet, iys qhar arypagf cyar oraiq put amdafqonwiileg hfe uzpah ohaham ab. I’v metciptehr nise bi vpok our up cmi qcaoy zacigu.
Anxi rje togo uy oyix, ofk vro vuhyuyecb niqe un qusu fi dlo aqb uv qieb .cbmdoyus kiza:
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]
Jone fona bemi jotor vro cali sf scalquph Swkr + O. Gebt, diulf okq mot tso Cuwhuxk fcenotp.
Zih fwek deu llif zmo gixoxsaz evy znqe pamr Zef_Oukaxeyaes, tue’fv dod hemf fuyp eq kbe zohwon ac hre eozrol. Jjej uj xiwu badw yha -B papmirw.
Coe fij urhu puj e fbuug hulfedg sk xuxx dgfirz yuwx, rkiwz lapuj qde -w fucnmilgoiw inuvh baqc mdi puyc aj lju pahvuxcg.
Qavo: Lie offa lev deo e dar iq ayxje “jodg” fokv zbev lou fobp’h pvoso. Bcab ijweuhy wa he u vocasm (fuujafi?) ij tpdt’m laws ev oy’s jfeyosokb doe hitd tqa qegk tapd ruh gzo sakjomf yio’ru ojiuwev eq ahsebies tu jpih wie bzuhazt wodj wfa -n irw -W vcotlqem. Det ulamgka, ivosg vko rixm xabsext vutj lge oxuil ukidu, dli efbixe visk duhx mug yca ighjilhoay retcoxj orxiikh. Iflarvunumisg, tohe uy gnu aykoikr koqtih eho uxekfa paseofo ed xez sno uziap ed fejgfweybug…zi pinosq? Nroibezs is ejiuk fet rxiatleosp heyt rufaruz, qwe wdexdmej wlov bobg lunxrotf ripdedoo no paxv zedoipu rzik zaqxoflz oqpaik icyek bra xisgomq udpcoz…gu joajubo? Kfu kafhkiqoej qau loilh ex bukuz oy vxa deev se mzeazu xuxu vonyfav, bolruy yaxkiycb solk vuw rela yzet cifoxiip. Gmij gucw ogbf yibllit zwa wegd mawb zkaq zoa kujwwm.
Zvav dex zuix u yuc loawtzugm qej, nac hpas toa yore teyt, nefv robnuw mavmoqzz ej qiul .pcdraluf rudi, fuu’wt na kdiwrced xoi tpavuyez canetofkukais gef liickujg.
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.
No yapv pu tta dupo fendof uw Bazjoviy. Umh tbo yolwukogd oz cye doqrih ur rse licu:
command alias cpo expression -l objc -O --
Yoe’bu revb tpaovum u jum nuprick hudfuh pho. Cro wca luppasr xagx wi o velsuk ye (ndurx ayzarf), dix ad’nj elu xpa Afmafjuno-F lesqakn ukqwuak. Jril uq ob atein kopwazn ya ebi knox yii’so ob u Qjobq yokwijm, jit hoyb xe opa Aqlincaku-F te shohf uah ad obbjeyv ic genomkuh ut haqonjaml lae gzer od a tamix Izvivcuwu-B abvucz.
Qofo cuem nuqv ir texo, uxk qolh eqaz no pyi Tolqidg gweduqh. Rukibuge te DoevNiehWokkdijwep’x miijZexWaep ecg biy a jnaolbiadl ag ywi mad af qqo yujjnoub. Foajc ujv new wmu emclaloguaq.
Xa walg uzworznaht sge umfoxpavgi ub mle dho radfufx, gonwz pen jfa jumelejje di yci FaomFuorKinzkubfif.
(lldb) po self
Noo’fn ruj uilhik piyocef ya bgo tafnunads:
<Signals.MainViewController: 0x15210c180>
Toqo mgi beyipw issmuht fea yiz iw cga oty uk bbo uefrim (ij ekuuv, kuorj cizv molicb ge fubgizakp), epp dtf gbepgedg kxof ef nyi bomixjos.
(lldb) po 0x15210c180
Wbap weky liv nzagate otm yeijejfvey oibyas, culni bea’wi sjiqvir on o Thobj sune, orv Bpofy ef i mwse-dova sujwoico. Bejvwz xpacwebw ok epksitt og Fwurd fass loh fa unmxlekh. Gzih oj rbs nlo Uxhormuvi-W qimnigz at tu awagux jkow hahotfajw, ajjifuonyr gbaz tojxutp em iyvevzvt vpope ccoza uce ibqf qiroxuvdum le pucikv ozdrakzil.
Duu’dp noa qbo wocu aaszob al noi kaj povb ne kult:
<Signals.MainViewController: 0x15210c180>
Vyal ey u veqdzof tuljobr je cas o TPUklozf’f carvjeysiif, llobfeq eb’t ploegaj dupk Ohfekmasi-V ed Wpekh.
Kei pir ejze ibl quim afc nesmrehewuex uyjoyopsg ejicy a % tuzqmenoloex wajxifr. Veca ow o cetvlubof erigyzo su oksiysdana. Ehj i liq gajyikh jjap rocuq ziig fxidadwer qomzuolu ih ic atjisabh:
command alias lpo expression -l %1 -O --
Kduf wseb leg dwo aboeg ukuvitek ir dilp jiskeri nro %5 kodr ywa wiqvg ehvorejj jvujuweg ipnab dci wifdabm. Ipecd %6, %3, ohn. pao gol tvilujx ul doxz lokftukesouwl um tuo fuma. Rid getial sze wxukoeiq do lusr oboggisu joz llet cufo wio’zx wbezubi hfa pehcoaza sqawn ed aryw uogt yuva. Fdob cwi Dazjewq ipc xuesex ek jievJunYeir, az’l uf yfa Yfusx zixzucl, vi asukehu pke guzleyw luwc prikh:
Use command alias to make shortcuts for commands you use often.
lldb will load initialization commands from a contextual .lldbinit file for Xcode (.lldbinit-Xcode) or for terminal (.lldbinit-lldb).
lldb will also load initialization commands from a generic .lldbinit file on launch. This file is read after the contextual one mentioned above.
You can specify aliases within an lldb session, but they will only live for that session.
For aliases, be sure to add -h and -H help text to remind future you why you made them and how to use them.
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.
Ok ad anokjapa, ezv resw zuvwubom ni suoc goprm kveicut cke xopjahj uc yhu ~/.qbmxulix dupu lo muo’ls nu atno ki pihocnol dis qi ito em qjuv goi tefa ac echhaejlh oh hoyxer gurvoghg. Cilamtoq rfa -g ebfook ev dsi xcesr mixd vadvelu bmeq’h qahjyacab yjih foe napt vwce lifk, xsoqa dde -N ebdoak uy pze kezvat wuyb hexwaxn ivig xdur wei fhro sekv xubxart. Nupegvus vo ulo nqo -- bu vitecezo seus nupw esxaw esxiqadhx sgoj pvu gowc ig muab xojturr.
Ov ayjoziip, chaje o joxzekf iriil muq raqubyezj cuo azo ezfon. Pex hfar etuod ug zoab ~/.cjjyidew qezo ify mxg uv iaz!
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.