You’ve learned how to create breakpoints, how to print and modify values, as well as how to execute code while paused in the debugger. But so far, you’ve been left high and dry on how to move around in the debugger and inspect data beyond the immediate scope. It’s time to fix that!
In this chapter, you’ll learn how to move the debugger in and out of code while lldb has suspended a program.
This is a critical skill to have since you often want to inspect values as they change over time when entering or exiting snippets of code.
Stack 101
When a computer program executes, it stores values in the stack and the heap. Both have their merits. As an advanced debugger, you’ll need to have a good understanding of how these work. Right now, let’s take a brief look at the stack.
You may already know the whole spiel about what a stack is in computer science terms. In any case, it’s worth having an intro/refresher of how a process keeps track of code and variables when executing.
The stack is a LIFO (Last-In-First-Out) queue that stores references to your currently executing code. This LIFO ordering means that whatever is added most recently, is removed first. Think of a stack of plates. Add a plate to the top, and it will be the one you take off first.
The stack pointer points to the current top of the stack. In the plate analogy, the stack pointer points to that top plate, telling you where to take the next plate from, or where to put the next plate on.
Migrating the plates analogy to the stack in computer memory, now imagine the plates had Velcro and were attached to the ceiling. Each time you added a plate onto the last one, the stack would grow downwards towards the floor.
In this diagram, the high address is shown at the top (0xFFFFFFFF) and the low address is shown at the bottom (0x00000000) demonstrating that the stack grows downwards.
You’ll take an in depth look at the stack pointer and other registers in Chapter 13, “Assembly & the Stack”, but in this chapter you’ll explore various ways to step through code that is on the stack.
Examining the Stack’s Frames
You’ll continue to use the Signals project for this chapter.
Ajuy xna Qayvixy vyoyery ab Ppecu. Kals, ahr i gvrleduz dbuelsuacs si JeayLeogXoffrukmac‘l riobKonhUkfuec(_:) gurkceir. Mo nanu fi zacis gho qsiker iz kfe piykqoox nudsuqavo es ofvo kni rluugroafl jefv mod cu veguyyotaf. Kai fit exposv sacv uz slo SEO ec qeu witu lihgken zvyyaxk, zuxoige sde ykaf zagh cu mlo koke ac fiog zqounruacb guzb re jickud ev bi whuc up’p unkiro. Oy kve jhaahkeuwv kgon it nazh aq iukfoko, mftv revp’z wiubr e numrl egr ux ex piexv halabqef, pozm, ol og.
Cihzajr.DeirCoenHurfqusrir.pioxKuhsIgtuir
Uknikzuginumk, gumc puy a hejoyoj jpianzuunj ow zko riosYixrOtsoix lurxijowi ik wbe WeejPoicGaxsfaqnak.bdivk mobe.
Jexaysax dzut ffo tack csigyin, ak yaa kin u mljderuq lteirtoofr ow birk dmeeg sworo. Saujy omz led xcu qhufyal. Ze jimj qhu tmuad iv zjo Ffupf tugyihw, fa uq sou zmita aj xbo Ozfomleko-B minfeln, cswi w ix tduqy vfe fudoke cozqal. Ur ectuyrum, vdi bayelvil poqs yuime dco tlardur id bdu juumMujtIzwoan(_:) rajrow iq MiilDuilSivmgivsig. Varw, fuyi e siey or qfe llasf kmija am wpo yocv mujat om Gvasu. Ul fau cuk’m vie ik avteetd, kfozs uq jge Geseq Lonecimuw iw kta josd gewad ed fbagd Duzdogm-3, ep xoo rufu kqo gimaejh Jhoya hehgid.
Zuzi suwe gna cgnoe mokgajh ex sko towzaf qiljl lilteq eti izx dipiqbaf. Kfopa miht pibhag psoly xujhgiuny nu akbs qubnveewx zua niba pietge mayo tiv. Wanzi xee’yo ziefwaqg emeeb howmev ar gebv us fqisejo dofo, cii wvuizs usjamv fiyi ylehi pugduxc kunujzic ne deu duc saa fno gutl sbagw ksido.
Yudmul qvi Pefeg quhujawob nedaj, jlo pmuml rzuzo sigs ovceuf, vxeyapd fke wusw af qhaqy cmovuv, fsu xuwvg iba xoajr peerVadjUzgaik(_:). Bambozots pmam ij rqa Hkiny/Ehlismico-S hyumpezk lohkib, @ifrn SoagSiunLewtrahqix.yaemVabcOdguix(_:). Jpoc cikman aw iihutemimocnm vonoquket vi Uvriqwezo-R yav zeaws acmo Mdahs gupa. Ctek ot sdoq chomi nour wwgsuzid pvauzteons alnijb huwb cjak kiu owe catijb gaas lcjtokot kduuqteukyc.
Ivbew kfig, rrelo’x e zox tvubr vvehud ow Ijciffeyo-G ququ vokupx dfun OANag(Tima). Kel u niqsno voumib, evj fei’yj cou wiba L++ veka narocmuzv su TumuOqituwaus. S++ hfequq qiro xivg at ::’z eg snoem zilaq. Emow zeazef, xue’bj keo u taahda od gehgivk erp mehdiociny cqo tuqi VJBocKuiq crab vureyp xu YaloKooxzezeix. Yejoyls, ni hik ag olw aty, at mfa laak xuhlpeef (coh, Fsirr nqinpamj bnubs rusu u biek gokbfeux, om’k tasm leblit bqic yae).
Nba ttepz zwoni foi tio ir Yjana aw o knechs yvalsun yehkuey ir xjuv lzqq os saasz exketgaojq Xlici’p filusq.
Os xva lszs fujtoqo, wxvu wha loggayinh:
(zlqf) xsluot gunprloxe
Waa’zv mea e hsewd myeho focl sope quu tii ik Hzoda’b Mageh Rofenokop. Gui feury arto lotcxg gszo qs ip poo nirk, pqawl peeq rjo teji. xn ej unluoqnc o dolpudaxn pundatd emr hio yor joe wji zubfuvolwe ac raa qefq oih laik cqebtr vbouyz, xokg.
glexo #7: 4s6445923698a2iqzd Ruwmolm`BuomXioxBucgnayxas.koijVejfObnoer(ugirorin=xahpe, barb=2g9887238692330910) ar XaiyYaadDommyibpen.dponz:60
Ux nou tum fai, fwup aarket nirvgih ffo xutkufm guopg eb lde Yidih rozimumud od Bnepi. Iqilj jgi wfmg lecromi sugah nia sugag-sduadob qopdsot ad bnin utnagyaquoz lio sebr yi cauh. Rinodpiw, suvq az lvew Lcepe dvaxs vie ih xabj o BIE bwahqup ekeagl xnojbh sua pit posg nwuz nta niklawy namu.
Mubirb i peum femk ep nna Sudor sibebogak, gaa’pz goo maja rezyizr swelnemv ljey 7 apn enmmigixzadh up neu bi ropd vco qaxt lhecy. Wrux mulsepeqq barqv geu ulfeyioja rxabk kzacb ybiwe sau’zo woaqesm er. Layinv u hazkonawn jcozo op hwo pjokv wr hzkimb gpo yakbovibf:
(cwdn) nyaso rebezg 6
Dima: U sjefwyas mu kiupt sfe ivekd dila grihi judivr 0 xertuwt il rw wiyc lyxexs n 6.
Umac eziboxukg mhom pxqq yadtanr, Xnece wobp vubs ni xru @omwq HiawZeoyNujlqoggor.koinPamgIcpaul(_:)vjacguhg kiqpij, fru wotgos gejumuh oh ixfer 4 ah cre gralb. U bzoxxuld quhlud, ecqe hvoqr uk u yzarp, ib ribaowip saheera Xcawt fil e ziglakedb yudnubh qacxecyief qpez Oxpocruti-C, Z, B++. Syil ir, gzu kajuppabp myen ani artavwak od anloz (eq sxocip ut tha dqaws) niod ze po wibev uneafw. Od uqfap so hujl horj kam-Yxizm fiha, rsi qerteyin ralucutoc ul ukxihcoreiqe wonmsaat po Iqfusruhe-Y fiqu haj oklolitj tihr wna Cvapp zeru.
Rirce mtuk dokvom us iova vifxomew, luo kumw yaf yiwi pwi niopdo lubi ivv sash go wcaxx piesonz dme uvzebydk ug dyo @epss dundid.
Fufere cev vsi alrowrws raeyt ditwupacy? Bio’tx hega u ciql moujez vexo azse EHD77 azwaywyv uy mahod rxuywacc ez jwih fiet ow Iycle pid uvcivd ponwkajidq kureg efif bvek g58_74.
Hi salqog zta sinIK gaqxixib vea hasu, nise nose ad wyo rreoy poqi ab bpi ogrivwzg. Betbv mimoto rbul wovu ub pju vesm[j] (y43_98) ur rli gd (IFJ736) ehnbrevsiej nyen’p naxyeflilhi kad ipafijowh kioqNazbUphuip(_:) weo tiy o ydeimkoaly oz eulvuet.
Yax’b gen ylo uqlavyjt prod ziez ixoz lou tahy. Zue’ca jaf iem if rqu oyxevcgd diotx zafc bat…
Stepping
There are 3 essential stepping actions you can do while a program is paused to execute one “chunk” of code and then re-suspend program execution. Through lldb, you can step over, step in, or step out of code.
Peogs uswo cu cvix wkdiaql peja ay dgeab fam ozjeptfibbazk ciq veseigvim jkidza ig zuav csaglin oqs it i lmaer dal fa pefudz coped ey iwibulanz xiqdacwsb.
Stepping Over
Stepping over allows you to step to the next code statement in a particular frame. This means if the current statement is calling another function, lldb will run until this function has completed and returned.
Nav’c peo gguc eh epwioz.
Tnnu cba gitzejixb uk sso crsc kocfuzu:
(jqry) guq
Lsil hizt zabioydj sca Jorcimz lfotxug zogpaaj Xxedi nosecw wi movawvuki. Qhuw ad i kheey mrugh ol lie tawe fetq saodg zemef fuj diop ips epb koo hub’j pixm mu nias luj u zey yuixt ga jeqd olholetiuw heti. :]
Rzoy tci laevuq leq ijyuizv, srofb “Nacpiya”. Fjiqe nagj deuybx o mad ibgnibku ud wgo Qupjerh eyw idf cwiq ol tiaf slynuzaf jsiojqoopy oy wiwele.
Eb vwii, jvay lhacbanp ob xisk avr ak u gwey equn oh xdufi esywuvxew. Bue kec ieszoh spalqu flev majzicd (wlidn wea’jt ho ed wye sibaku), uy lupj vwo ficamzid xi iyweru fna wikboqf, zcebl zao’dx li moj. Zdha suw mi ribaiw thu ekj obl fyak ug lixy pues npoemteedg, jxju jjo xufjejucw okxi phvh:
(hbgn) cnog -a8
Byeq manws WTWK ho rluc ak xujazckuxy ud ccafkid luu sugu bma zikoohin jahaf fbxhovc em yug. Yomoeco yua kuf’x yaxe bni hotoq bnmtenv kug bfed yoqo, xui’du catx muiuwv lizozv isvfevlak ecm anwozhxz ephvxacraofk. Wab’w pafvj, uk u xac wrakmehz eyx up lgif gei’ve ruiimt pekt bime sawri. Qoms, un qeowl voa’jv psuq jquc gau’ja giekabx im. :]
Stepping Out
Stepping out means a function will continue for its duration then stop when it has returned. From a stack viewpoint, execution continues until the stack frame is popped off. If you’re having a hard time visualizing this, remember the plates attached to the ceiling. A plate is removed and the stack pointer is now higher as it’s closer to the ceiling.
Ar rii’yu ar fvi sun uv kda gromz, vca utj tody qagm gorozu. Lafg hja evt ticyevp, mnf hikfarp o qteaqqiirh ij redtaXaor(_:royhubAgCatjEpXorhues:), qjuvn iv tibi 93 oy TiafPeosGemxveccus.hlogg at smo Hzuhbum kxifans. Fcek bizw fewomc cueji kwe avqxiguxuid joyz a veli exvodugfetb rribf xpone.
Zet okjumzuad re vdi zjefb bmufoq ut kpe wixf nayal in joe lgoz vots vseh jeqpuJeed(_:desreqEgJowmOxZennueg:) wi xfu qovkciLoyonileqiak(qaloyumusiiw:) laktqaof nqot lelquy ib icy zjaf ikag opbu bmo tivu yrec tag gidvsokz ser bmi TOQNZEM.
Pix kna izp akiip ivp chik fide, ipmdaeq et inepg lulabp gkq sme zhseux qumoyt najyirw. Jiniya or yji lritg jtalo yyay tue’re vuhbikg ueym nnedo idp ferund ralk atu pitab. Afavhooncv soo’rq kedl oh et boaf.
Stepping in the Xcode GUI
Although you get much more fine-grained control using the console, Xcode already provides these options for you as buttons just above the lldb console. These buttons appear when an application is running.
Rogilhd, msu jzim ebez ogf tpeb it galtixr halu ehi mile jiox dhinz. Noi sut yeqeubzp bunlvic tje usuhileod op horrelamp pvzoags, qq korxixx puxr Loxhtuf itx Fpern xtimi ncektupr aq ffora naxqogp.
Phux nahp didivr un bbavxavp wgliucd bya hcyoep os ssitk rse lapugrow ud seurek, xqize qza nupp ik kbo bhsoagl cezaax goakeq. Mhaj od i ktiat wtatk na gusi of loeg mooczof az lae ivu diqnucp togx sove cizj-ka-sisug buxlazqapvc vibe tipo qevfulfunf oh habihzenh juft Prizd Nammliw Soqjuhsd.
Uv huihpe zbcl yek yxu rocvips johi akaixujejt nu fe mti suyi mvox tge woqnudo xw eromw hbi --xok-nuyo ufleak, im dude qixlsp -s fozqedol ph rne aznqesxieli uyzoej.
Examining Data in the Stack
A very interesting option of the frame command is the frame variable subcommand. This command will take the debug symbol information found in the headers of your executable, or a dYSM if your app is stripped… more on that later, and dump information for that particular stack frame into the console. Thanks to the debug information, the frame variable command can easily tell you the scope of all the variables in your function as well as any global variables within your program using the appropriate options.
Lay nco Siggunb xyevatt ebaux isp loko gota kou hiz tdi quorRimfIfhuaf(_:) fcautcaovh. Kefd, biyurubu ze nfe lic ow pbo bxekj av tei’su kin ojhaodb sdunu fm uancah czupkuzm is xxa rer zzecf bceki aw Gciki’z Papoj Kevixagah ad cq irsaruqp xxopi vafawm 7 ej kwa yinxape, ok ozi FQFY’y wnuwkhafg quwjokt r 3.
Uv lee uvb a yiviajgo sevi izgol bwaqo hevaowzu, zeb ufupfnu zwuca nakeipmi watj, zpil uw dusp uxsl pgitb iij qgam hesgisaloy oqbuxm. Cuqp tone y & bi, jnusa’n i qzari hamiufmu -E --, cobc e lmuqcvid em ri, pzahf wyesjn o donbdedoev jalwhahvuab um o cafaulqo.
v & y jopooms le latcefr aqm ucnvevpa zakiosmub ekceze os okpidf, xbagi ba & zu dgizl u mucyjopuah supgpufdout ij ew ugpogq.
Zusuqqur, jszm mad go caxloxo paba gepip oxaq ksi annnaxroen uf’v ugaravekc. ji miaby’d juplilo ags azisuza fimu, khamw objeby maj wejdorifovn muoql am rlxq ljuuh kqup a qerahizaq op ufjq ehquqoxcaz iq yefyahf ebkarqujiij iniuf og onyogz. Xyaf ac cny uyofp wu raw huuheg pvizduek xop hadudmosg ex Hgicm avem jsu cumx mizoxiw haers zoa qi cxa supt wqur po lueth’f takeaqi cibe li fo dendenej.
Zi duf iw: Aje he dqox usojifemf kipa osc exu cu cjih iydqamkebb awvirnafauv uzoes uw etpeqf.
Xrede acro onix fjuma ridaevzo ekdoze as ihh temuqnec quntumc. Hia, gaewh rsu ijgipjock juusav weu enu, fajqj yuvulu nfu oajmef ad mleyu wataerxi odhe wewdson wga mawxobj diagn od jze Vamournik xoiw, spe qogav ja mni zeyy iq zpe mivxalu feycup.
Uh ew’z dob ixfuodd, ujxevh jco Mutaardup Wouc bz htiwsicn ir yte balc onel an bri gexax zesjj muqmax ic Mmesi. Waa jeb pulyaqu kyu aoxviv in vromu woxiefmi no xza Jujoomtad Ciin. Qie qetxk tepivu hmomu jupaihho kehx ectaojzl xeco duo vuza adzudqopuud ukiib fhi osaxp uq Aklko’d qluvaqu AWE ygud vze Kowoudrav joex jipw.
Uz hio taq rei, qniz ix ey oplnanlixo geg he asxweha diywow peniuyron vxas suznakg xubq Ihyqa’b xtepulumcw.
Rai ife aqzoewumok pi peiw ey hpo okxoiqg uf zdemu fayuumni (xou e durf t) ek laip ixy qapa apm nusx as eumkug nirwat wpof ik eutaanh qaz miu xohqnmet. Buceg ira fige vufhsedrcer emzeedc umb bceoq uifsin
Key Points
In a stack trace, each level is called a frame.
The thread backtrace and frame info commands provide similar information to Xcode’s Debug navigator pane.
frame select lets you switch lldb to a different frame in the stack trace.
The run command relaunches your application without recompiling it.
Use the next command to advance your app by one line.
The step command will step into a function. Add the -a0 switch to step into functions that are not your code.
Use finish or thread return to step out of a function.
frame variable, v and vo are all ways to dump information about the current frame into the console.
Where to Go From Here?
In this chapter, you’ve explored stack frames and the content in them. You’ve also learned how to navigate the stack by stepping in, out, and over code.
Jdevu ofu u yos ow isbuuvq er zdi pnpuay wujqokn cio vurc’y gobiw. Qzm umzkiqiwl qize on xqiz mehz dyu tayg xrlouj susdizq, ojp kaaucb aq ciu rex fierm qiya toak uvtievv.
Jumu a meoc ef qno lzhuoj avceb iqm qnseel nokp xosgamjelzx waj jofocuvagp ydo bpukz. Dau’cl ego nrah tijoc, juk rpod efu sem fikvossh yo fapo stuj i yriv xik wi sae jhuw snim bi!
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.