 Okay, I'm going to talk to you about a debugger and My opinion is everyone should use a debugger and if you're not using a debugger, it's because you haven't found the right one yet So before I show you debugger, I have to show you a bug So here's a bug. It's a real one. It's a bug in mercurial It's about something called phases. So mercurial has this thing called phases and I'll show you what it does in a moment So here's a mercurial repo. Can everyone read that? big enough Okay So here's a mercurial repo and there are some commits lying around Now the phases command What it does is it tells you? It just tells you if your commit has been published or not or if it's secret Right now I'm in a public commit and this bug is about the return code of this command here I'm gonna add a little echo so you can see the return code here. You can see the return code It's just zero which is fine Now the bug report is that if you try to change the face to something that you're not supposed to be able to change it without Without a force like a stash-force It gives you a return code of one, this is fine Because you're trying to do something that you're not supposed to normally do But if you try to change it into what it already is It is a draft Then you're still getting an error code of one. So it's a very simple bug You're getting the wrong error code Because this shouldn't happen if you're trying to change it, but it's already what it is You shouldn't be getting an error from that Now in order to handle bugs mercurial has a debugger command So we can run the same command inside a debugger debugger and by default this opens pdb And if pdb is the only debugger you've ever seen I won't blame you for not using a debugger Because it's I mean it's a debugger, but it's kind of crappy I mean you can do up to move up the call stack you can do L to look at the source code here We're looking at the mercurial source code. It looks really ugly Because the debugger is ugly not because the source code is ugly So here I can do C to continue and it'll continue executing the code and then go back to my bug again Which is no faces changed. I'm getting an error code of one So mercurial has a command to pick a different debugger, and I'm gonna pick this one config ui Debugger equals I'm gonna pronounce this put B But I don't know it's pronounced. I guess it's P you like it stinks DB. I don't know, but it doesn't stink. It's great And this opens this It opens this beautiful colorful thing. It even has a welcome screen We're not gonna read that right now But the first thing it does is ask you to configure it. We are gonna configure it I'm gonna tell it to show me the line numbers. I'm gonna tell me to you tell to use Python I Python and I like dark themes, so I'm gonna make it dark Okay, so here we are in actual debugger if you ever used an IDE you might have seen something like this This is why I call it the debugger without an IDE because it's just old command line. Well text-based Up here you can see that the variables here. You have your call stack here. You have your code It's all wonderful and colorful So let's look at our bug. I happen to know the mercurial source code pretty well, so I know that The bug is somewhere in the command module, so I'm gonna pick a module to look at I'm gonna look at the mercurial Commands module and Within the mercurial commands module. I'm gonna search for a function. I'm gonna search for the Phases so here we are and here I can move down. I'm just moving. I'm just this is just I'm just looking around. I'm not doing actually and executing anything and I'm gonna set a break point there by pressing B It looks all red now because there's a break point now and I can press C to continue execution to that point And here I am I'm actually running my code now. I'm actually running the mercurial code and you can as usual press N to move around and I Don't know the first time I saw debugger. I was pretty amazed by it So Let's look let's look a bit around more here and now I'm gonna look down and this is all just Handling a lot of complicated logical phases But here we get to interesting part. Ah, here we get the return code is one if rejected. That looks alright But if there were changes, there were no changes, so we should be getting here So I'm gonna press T for until and Execution should continue to that point it does cool and One of the nice things is that you remember how in the beginning I told you to use I Python At any moment you can press the exclamation mark And it actually opens an I Python shell in which you can analyze your variables like any other time Here for example, I can see that their return code at this point is zero, but that line is turning into one So I'm going to just press C to continue It continued it kept executing my code and it gonna give me the bad return code that I don't want So let's actually go and fix the code Here's a code. This is an emacs. It's not my debugger anymore, but I can just go here I'm gonna delete this line here. Let's go back to my debugger. I'm going to run it again Now the one of the cool things is that you saw that I exited debugging came back in this debugger actually remembers your break points So if I press C again It's gonna execute up until against that break point. I can go back to that place before Where I had my error It's here the lines been deleted. I can continue on the way there I can again verify here that the return code is zero as it should be and I can continue and Now my turn could zero so using a very simple debugger the buzzword things fixed