Assignment 0: Using the Debugger · in debug mode, whenever the program gets to this line, it will...
Transcript of Assignment 0: Using the Debugger · in debug mode, whenever the program gets to this line, it will...
![Page 1: Assignment 0: Using the Debugger · in debug mode, whenever the program gets to this line, it will pause and open up the debugger so we can see what's going on. Now, we're going to](https://reader033.fdocuments.in/reader033/viewer/2022060920/60ac5091a12d445dad178a04/html5/thumbnails/1.jpg)
Assignment 0: Using the Debugger
![Page 2: Assignment 0: Using the Debugger · in debug mode, whenever the program gets to this line, it will pause and open up the debugger so we can see what's going on. Now, we're going to](https://reader033.fdocuments.in/reader033/viewer/2022060920/60ac5091a12d445dad178a04/html5/thumbnails/2.jpg)
Hi everybody!
![Page 3: Assignment 0: Using the Debugger · in debug mode, whenever the program gets to this line, it will pause and open up the debugger so we can see what's going on. Now, we're going to](https://reader033.fdocuments.in/reader033/viewer/2022060920/60ac5091a12d445dad178a04/html5/thumbnails/3.jpg)
As part of Assignment 0, we'd like you toget a little bit of practice using the
debugger in Qt Creator.
![Page 4: Assignment 0: Using the Debugger · in debug mode, whenever the program gets to this line, it will pause and open up the debugger so we can see what's going on. Now, we're going to](https://reader033.fdocuments.in/reader033/viewer/2022060920/60ac5091a12d445dad178a04/html5/thumbnails/4.jpg)
The debugger is a tool you can use to helpsee what your program is doing as you
run it.
![Page 5: Assignment 0: Using the Debugger · in debug mode, whenever the program gets to this line, it will pause and open up the debugger so we can see what's going on. Now, we're going to](https://reader033.fdocuments.in/reader033/viewer/2022060920/60ac5091a12d445dad178a04/html5/thumbnails/5.jpg)
It's really useful for helping find errors inyour programs, and the more practice youget with it, the easier it'll be to correct
mistakes in the programs you write.
![Page 6: Assignment 0: Using the Debugger · in debug mode, whenever the program gets to this line, it will pause and open up the debugger so we can see what's going on. Now, we're going to](https://reader033.fdocuments.in/reader033/viewer/2022060920/60ac5091a12d445dad178a04/html5/thumbnails/6.jpg)
Think of this guide as a little tutorialwalkthrough to help give you a sense of
how to use the debugger and how to makesense of what you're seeing.
![Page 7: Assignment 0: Using the Debugger · in debug mode, whenever the program gets to this line, it will pause and open up the debugger so we can see what's going on. Now, we're going to](https://reader033.fdocuments.in/reader033/viewer/2022060920/60ac5091a12d445dad178a04/html5/thumbnails/7.jpg)
To start things off, open up the Name Hashprogram you ran in Part One of this assignment.Scroll down to the nameHash function so that youcan see the entire function in your window.
![Page 8: Assignment 0: Using the Debugger · in debug mode, whenever the program gets to this line, it will pause and open up the debugger so we can see what's going on. Now, we're going to](https://reader033.fdocuments.in/reader033/viewer/2022060920/60ac5091a12d445dad178a04/html5/thumbnails/8.jpg)
Move your mouse cursor so that it's in the spaceright before the line number for line 66.
Now, click the mouse!
![Page 9: Assignment 0: Using the Debugger · in debug mode, whenever the program gets to this line, it will pause and open up the debugger so we can see what's going on. Now, we're going to](https://reader033.fdocuments.in/reader033/viewer/2022060920/60ac5091a12d445dad178a04/html5/thumbnails/9.jpg)
When you do, you should see a red circle with alittle hourglass pop up.
This is called a breakpoint. If we run the programin debug mode, whenever the program gets tothis line, it will pause and open up the debugger
so we can see what's going on.
![Page 10: Assignment 0: Using the Debugger · in debug mode, whenever the program gets to this line, it will pause and open up the debugger so we can see what's going on. Now, we're going to](https://reader033.fdocuments.in/reader033/viewer/2022060920/60ac5091a12d445dad178a04/html5/thumbnails/10.jpg)
Now, we're going to run this program in debugmode. To do so, click on the “run in debug mode”button in the bottom-right corner of the screen.It's the one just below the regular green “run”
button. When you do...
![Page 11: Assignment 0: Using the Debugger · in debug mode, whenever the program gets to this line, it will pause and open up the debugger so we can see what's going on. Now, we're going to](https://reader033.fdocuments.in/reader033/viewer/2022060920/60ac5091a12d445dad178a04/html5/thumbnails/11.jpg)
... you should see something like this! Notice thata bunch of extra panels popped up in Qt Creator.We'll talk about what each of these windows mean
in a second.
![Page 12: Assignment 0: Using the Debugger · in debug mode, whenever the program gets to this line, it will pause and open up the debugger so we can see what's going on. Now, we're going to](https://reader033.fdocuments.in/reader033/viewer/2022060920/60ac5091a12d445dad178a04/html5/thumbnails/12.jpg)
In the meantime, type in the first name Ada and hitenter, as shown here.
![Page 13: Assignment 0: Using the Debugger · in debug mode, whenever the program gets to this line, it will pause and open up the debugger so we can see what's going on. Now, we're going to](https://reader033.fdocuments.in/reader033/viewer/2022060920/60ac5091a12d445dad178a04/html5/thumbnails/13.jpg)
Now, type in Lovelace as a last name, butdon't hit enter yet!
![Page 14: Assignment 0: Using the Debugger · in debug mode, whenever the program gets to this line, it will pause and open up the debugger so we can see what's going on. Now, we're going to](https://reader033.fdocuments.in/reader033/viewer/2022060920/60ac5091a12d445dad178a04/html5/thumbnails/14.jpg)
As soon as you hit enter, a bunch of things aregoing to pop up in Qt Creator. Don't panic! It's
normal.
![Page 15: Assignment 0: Using the Debugger · in debug mode, whenever the program gets to this line, it will pause and open up the debugger so we can see what's going on. Now, we're going to](https://reader033.fdocuments.in/reader033/viewer/2022060920/60ac5091a12d445dad178a04/html5/thumbnails/15.jpg)
With that said, hit enter,and watch the magic happen!
![Page 16: Assignment 0: Using the Debugger · in debug mode, whenever the program gets to this line, it will pause and open up the debugger so we can see what's going on. Now, we're going to](https://reader033.fdocuments.in/reader033/viewer/2022060920/60ac5091a12d445dad178a04/html5/thumbnails/16.jpg)
Shazam! We're back in Qt Creator, and there'stons of values showing up everywhere.
![Page 17: Assignment 0: Using the Debugger · in debug mode, whenever the program gets to this line, it will pause and open up the debugger so we can see what's going on. Now, we're going to](https://reader033.fdocuments.in/reader033/viewer/2022060920/60ac5091a12d445dad178a04/html5/thumbnails/17.jpg)
There's a lot going on right here. Let's see what'shappening.
![Page 18: Assignment 0: Using the Debugger · in debug mode, whenever the program gets to this line, it will pause and open up the debugger so we can see what's going on. Now, we're going to](https://reader033.fdocuments.in/reader033/viewer/2022060920/60ac5091a12d445dad178a04/html5/thumbnails/18.jpg)
First, notice that our red breakpoint now has ayellow arrow in it.
![Page 19: Assignment 0: Using the Debugger · in debug mode, whenever the program gets to this line, it will pause and open up the debugger so we can see what's going on. Now, we're going to](https://reader033.fdocuments.in/reader033/viewer/2022060920/60ac5091a12d445dad178a04/html5/thumbnails/19.jpg)
This yellow arrow indicates where in the programwe are right now. The program stopped running atthis line because we hit that breakpoint you set
earlier.
![Page 20: Assignment 0: Using the Debugger · in debug mode, whenever the program gets to this line, it will pause and open up the debugger so we can see what's going on. Now, we're going to](https://reader033.fdocuments.in/reader033/viewer/2022060920/60ac5091a12d445dad178a04/html5/thumbnails/20.jpg)
Whenever you pop up the debugger, it's good tofigure out exactly where you are in the programthat you're running, so you'll get into the habit
of checking for this yellow arrow.
![Page 21: Assignment 0: Using the Debugger · in debug mode, whenever the program gets to this line, it will pause and open up the debugger so we can see what's going on. Now, we're going to](https://reader033.fdocuments.in/reader033/viewer/2022060920/60ac5091a12d445dad178a04/html5/thumbnails/21.jpg)
Next, let's take a look at this panel.This is called the call stack.
![Page 22: Assignment 0: Using the Debugger · in debug mode, whenever the program gets to this line, it will pause and open up the debugger so we can see what's going on. Now, we're going to](https://reader033.fdocuments.in/reader033/viewer/2022060920/60ac5091a12d445dad178a04/html5/thumbnails/22.jpg)
Right now, we know we're in the nameHashfunction, because our helpful friend the Yellow
Arrow tells us exactly what line we're on!
![Page 23: Assignment 0: Using the Debugger · in debug mode, whenever the program gets to this line, it will pause and open up the debugger so we can see what's going on. Now, we're going to](https://reader033.fdocuments.in/reader033/viewer/2022060920/60ac5091a12d445dad178a04/html5/thumbnails/23.jpg)
However, the yellow arrow can't tell us exactlyhow we got to this part of the program. Whatpart of the program actually called nameHash?
![Page 24: Assignment 0: Using the Debugger · in debug mode, whenever the program gets to this line, it will pause and open up the debugger so we can see what's going on. Now, we're going to](https://reader033.fdocuments.in/reader033/viewer/2022060920/60ac5091a12d445dad178a04/html5/thumbnails/24.jpg)
The call stack can tell us exactly that!
![Page 25: Assignment 0: Using the Debugger · in debug mode, whenever the program gets to this line, it will pause and open up the debugger so we can see what's going on. Now, we're going to](https://reader033.fdocuments.in/reader033/viewer/2022060920/60ac5091a12d445dad178a04/html5/thumbnails/25.jpg)
Notice that the call stack lists a series of differentfunctions in order. Here, it has nameHash (wherewe are now) at the top, and right below that is
studentMain.
![Page 26: Assignment 0: Using the Debugger · in debug mode, whenever the program gets to this line, it will pause and open up the debugger so we can see what's going on. Now, we're going to](https://reader033.fdocuments.in/reader033/viewer/2022060920/60ac5091a12d445dad178a04/html5/thumbnails/26.jpg)
Go and double-click the call to studentMainon Level 2. When you do...
![Page 27: Assignment 0: Using the Debugger · in debug mode, whenever the program gets to this line, it will pause and open up the debugger so we can see what's going on. Now, we're going to](https://reader033.fdocuments.in/reader033/viewer/2022060920/60ac5091a12d445dad178a04/html5/thumbnails/27.jpg)
You’ll end up over here!
![Page 28: Assignment 0: Using the Debugger · in debug mode, whenever the program gets to this line, it will pause and open up the debugger so we can see what's going on. Now, we're going to](https://reader033.fdocuments.in/reader033/viewer/2022060920/60ac5091a12d445dad178a04/html5/thumbnails/28.jpg)
Notice that the yellow arrowpoints to Line 31. That lineincludes a call to the nameHashfunction. This is the part of
the code that actuallycalled nameHash, which is howwe got to the line with the
breakpoint!
![Page 29: Assignment 0: Using the Debugger · in debug mode, whenever the program gets to this line, it will pause and open up the debugger so we can see what's going on. Now, we're going to](https://reader033.fdocuments.in/reader033/viewer/2022060920/60ac5091a12d445dad178a04/html5/thumbnails/29.jpg)
Generally speaking, you can use the call stack as away to see which function calls got us to the point
where the program paused at the breakpoint!
![Page 30: Assignment 0: Using the Debugger · in debug mode, whenever the program gets to this line, it will pause and open up the debugger so we can see what's going on. Now, we're going to](https://reader033.fdocuments.in/reader033/viewer/2022060920/60ac5091a12d445dad178a04/html5/thumbnails/30.jpg)
You might notice that there's some more stuffin the call stack beyond just main and nameHash.
What are those?
![Page 31: Assignment 0: Using the Debugger · in debug mode, whenever the program gets to this line, it will pause and open up the debugger so we can see what's going on. Now, we're going to](https://reader033.fdocuments.in/reader033/viewer/2022060920/60ac5091a12d445dad178a04/html5/thumbnails/31.jpg)
Let's find out! Double-click on the functionon Level 3. (Here’s what it looks like on mysystem; you might see something different.)
![Page 32: Assignment 0: Using the Debugger · in debug mode, whenever the program gets to this line, it will pause and open up the debugger so we can see what's going on. Now, we're going to](https://reader033.fdocuments.in/reader033/viewer/2022060920/60ac5091a12d445dad178a04/html5/thumbnails/32.jpg)
When you do, you’ll see something like this.(This might be different depending on your OS.
Don’t panic if it doesn’t exactly match.)
![Page 33: Assignment 0: Using the Debugger · in debug mode, whenever the program gets to this line, it will pause and open up the debugger so we can see what's going on. Now, we're going to](https://reader033.fdocuments.in/reader033/viewer/2022060920/60ac5091a12d445dad178a04/html5/thumbnails/33.jpg)
Yikes! This looks Hairy and Scary! What happened?
![Page 34: Assignment 0: Using the Debugger · in debug mode, whenever the program gets to this line, it will pause and open up the debugger so we can see what's going on. Now, we're going to](https://reader033.fdocuments.in/reader033/viewer/2022060920/60ac5091a12d445dad178a04/html5/thumbnails/34.jpg)
Whenever you start up a program in CS106B, there'sa little bit of code that we automatically call foryou, which does things like setting up the console.
![Page 35: Assignment 0: Using the Debugger · in debug mode, whenever the program gets to this line, it will pause and open up the debugger so we can see what's going on. Now, we're going to](https://reader033.fdocuments.in/reader033/viewer/2022060920/60ac5091a12d445dad178a04/html5/thumbnails/35.jpg)
This code will show up in the call stack below youractual program.
![Page 36: Assignment 0: Using the Debugger · in debug mode, whenever the program gets to this line, it will pause and open up the debugger so we can see what's going on. Now, we're going to](https://reader033.fdocuments.in/reader033/viewer/2022060920/60ac5091a12d445dad178a04/html5/thumbnails/36.jpg)
You shouldn't need to dig around this deep inthe call stack, and if you do, it should probablybe a message telling you to back up a bit back to
code that you actually wrote.
![Page 37: Assignment 0: Using the Debugger · in debug mode, whenever the program gets to this line, it will pause and open up the debugger so we can see what's going on. Now, we're going to](https://reader033.fdocuments.in/reader033/viewer/2022060920/60ac5091a12d445dad178a04/html5/thumbnails/37.jpg)
So let's jump back to the code that we actuallywrote.
![Page 38: Assignment 0: Using the Debugger · in debug mode, whenever the program gets to this line, it will pause and open up the debugger so we can see what's going on. Now, we're going to](https://reader033.fdocuments.in/reader033/viewer/2022060920/60ac5091a12d445dad178a04/html5/thumbnails/38.jpg)
To do that, double-click on Level 1, the call tonameHash. When you do...
![Page 39: Assignment 0: Using the Debugger · in debug mode, whenever the program gets to this line, it will pause and open up the debugger so we can see what's going on. Now, we're going to](https://reader033.fdocuments.in/reader033/viewer/2022060920/60ac5091a12d445dad178a04/html5/thumbnails/39.jpg)
You'll be teleported back to safety!
![Page 40: Assignment 0: Using the Debugger · in debug mode, whenever the program gets to this line, it will pause and open up the debugger so we can see what's going on. Now, we're going to](https://reader033.fdocuments.in/reader033/viewer/2022060920/60ac5091a12d445dad178a04/html5/thumbnails/40.jpg)
Let's quickly recap what we've seen so far.
![Page 41: Assignment 0: Using the Debugger · in debug mode, whenever the program gets to this line, it will pause and open up the debugger so we can see what's going on. Now, we're going to](https://reader033.fdocuments.in/reader033/viewer/2022060920/60ac5091a12d445dad178a04/html5/thumbnails/41.jpg)
To set a breakpoint so that we can pause theprogram and look around, click in the margin justbefore the line number where you want to pause.
![Page 42: Assignment 0: Using the Debugger · in debug mode, whenever the program gets to this line, it will pause and open up the debugger so we can see what's going on. Now, we're going to](https://reader033.fdocuments.in/reader033/viewer/2022060920/60ac5091a12d445dad178a04/html5/thumbnails/42.jpg)
Once the breakpoint is reached, it will pull up allsorts of useful information.
![Page 43: Assignment 0: Using the Debugger · in debug mode, whenever the program gets to this line, it will pause and open up the debugger so we can see what's going on. Now, we're going to](https://reader033.fdocuments.in/reader033/viewer/2022060920/60ac5091a12d445dad178a04/html5/thumbnails/43.jpg)
The yellow arrow points out where we are right now.
![Page 44: Assignment 0: Using the Debugger · in debug mode, whenever the program gets to this line, it will pause and open up the debugger so we can see what's going on. Now, we're going to](https://reader033.fdocuments.in/reader033/viewer/2022060920/60ac5091a12d445dad178a04/html5/thumbnails/44.jpg)
The call stack shows us how we got into the currentfunction.
![Page 45: Assignment 0: Using the Debugger · in debug mode, whenever the program gets to this line, it will pause and open up the debugger so we can see what's going on. Now, we're going to](https://reader033.fdocuments.in/reader033/viewer/2022060920/60ac5091a12d445dad178a04/html5/thumbnails/45.jpg)
Now, let's see how we can read the values of thevariables in this function.
![Page 46: Assignment 0: Using the Debugger · in debug mode, whenever the program gets to this line, it will pause and open up the debugger so we can see what's going on. Now, we're going to](https://reader033.fdocuments.in/reader033/viewer/2022060920/60ac5091a12d445dad178a04/html5/thumbnails/46.jpg)
Look up at this panel over here.
![Page 47: Assignment 0: Using the Debugger · in debug mode, whenever the program gets to this line, it will pause and open up the debugger so we can see what's going on. Now, we're going to](https://reader033.fdocuments.in/reader033/viewer/2022060920/60ac5091a12d445dad178a04/html5/thumbnails/47.jpg)
This window lets you take a look at all the valuesof the local variables that are in scope right now.
![Page 48: Assignment 0: Using the Debugger · in debug mode, whenever the program gets to this line, it will pause and open up the debugger so we can see what's going on. Now, we're going to](https://reader033.fdocuments.in/reader033/viewer/2022060920/60ac5091a12d445dad178a04/html5/thumbnails/48.jpg)
Depending on what OS you're using, these might bein a different order, and there might be someweird-looking ones in there in addition to nicer
ones like ch and hashVal.
![Page 49: Assignment 0: Using the Debugger · in debug mode, whenever the program gets to this line, it will pause and open up the debugger so we can see what's going on. Now, we're going to](https://reader033.fdocuments.in/reader033/viewer/2022060920/60ac5091a12d445dad178a04/html5/thumbnails/49.jpg)
If we ignore the weird-looking ones, we cansee some nice, familiar names.
![Page 50: Assignment 0: Using the Debugger · in debug mode, whenever the program gets to this line, it will pause and open up the debugger so we can see what's going on. Now, we're going to](https://reader033.fdocuments.in/reader033/viewer/2022060920/60ac5091a12d445dad178a04/html5/thumbnails/50.jpg)
For example, here you can see the values ofkLargePrime and kSmallPrime, which match the
values they were declared with.
![Page 51: Assignment 0: Using the Debugger · in debug mode, whenever the program gets to this line, it will pause and open up the debugger so we can see what's going on. Now, we're going to](https://reader033.fdocuments.in/reader033/viewer/2022060920/60ac5091a12d445dad178a04/html5/thumbnails/51.jpg)
We can also see that, at this point, hashValis still zero.
![Page 52: Assignment 0: Using the Debugger · in debug mode, whenever the program gets to this line, it will pause and open up the debugger so we can see what's going on. Now, we're going to](https://reader033.fdocuments.in/reader033/viewer/2022060920/60ac5091a12d445dad178a04/html5/thumbnails/52.jpg)
As we walk through the program one step at a time,we'll see these values change.
![Page 53: Assignment 0: Using the Debugger · in debug mode, whenever the program gets to this line, it will pause and open up the debugger so we can see what's going on. Now, we're going to](https://reader033.fdocuments.in/reader033/viewer/2022060920/60ac5091a12d445dad178a04/html5/thumbnails/53.jpg)
Now, let's take a look at this for loop.
![Page 54: Assignment 0: Using the Debugger · in debug mode, whenever the program gets to this line, it will pause and open up the debugger so we can see what's going on. Now, we're going to](https://reader033.fdocuments.in/reader033/viewer/2022060920/60ac5091a12d445dad178a04/html5/thumbnails/54.jpg)
This loop is a range-based for loop. It says“for each character in the string first + last,
do something with that character.”
![Page 55: Assignment 0: Using the Debugger · in debug mode, whenever the program gets to this line, it will pause and open up the debugger so we can see what's going on. Now, we're going to](https://reader033.fdocuments.in/reader033/viewer/2022060920/60ac5091a12d445dad178a04/html5/thumbnails/55.jpg)
Remember (from a while back) that we enteredthe name Ada Lovelace?
![Page 56: Assignment 0: Using the Debugger · in debug mode, whenever the program gets to this line, it will pause and open up the debugger so we can see what's going on. Now, we're going to](https://reader033.fdocuments.in/reader033/viewer/2022060920/60ac5091a12d445dad178a04/html5/thumbnails/56.jpg)
If we take a look at the current value of thevariable ch, we can see that it has the value A.
That's the first letter of the name Ada Lovelace.
![Page 57: Assignment 0: Using the Debugger · in debug mode, whenever the program gets to this line, it will pause and open up the debugger so we can see what's going on. Now, we're going to](https://reader033.fdocuments.in/reader033/viewer/2022060920/60ac5091a12d445dad178a04/html5/thumbnails/57.jpg)
So now we know where we are (line 66), how we gotthere (main called nameHash), and the values in the
program at this point.
![Page 58: Assignment 0: Using the Debugger · in debug mode, whenever the program gets to this line, it will pause and open up the debugger so we can see what's going on. Now, we're going to](https://reader033.fdocuments.in/reader033/viewer/2022060920/60ac5091a12d445dad178a04/html5/thumbnails/58.jpg)
Now, let's do something really cool – we're going torun this program one line at a time, watching what
happens at each step!
![Page 59: Assignment 0: Using the Debugger · in debug mode, whenever the program gets to this line, it will pause and open up the debugger so we can see what's going on. Now, we're going to](https://reader033.fdocuments.in/reader033/viewer/2022060920/60ac5091a12d445dad178a04/html5/thumbnails/59.jpg)
Right above the stack trace, you'll see there aresome small button icons.
![Page 60: Assignment 0: Using the Debugger · in debug mode, whenever the program gets to this line, it will pause and open up the debugger so we can see what's going on. Now, we're going to](https://reader033.fdocuments.in/reader033/viewer/2022060920/60ac5091a12d445dad178a04/html5/thumbnails/60.jpg)
These buttons let you resume the program, stop theprogram, walk through it one line at a time, etc.
![Page 61: Assignment 0: Using the Debugger · in debug mode, whenever the program gets to this line, it will pause and open up the debugger so we can see what's going on. Now, we're going to](https://reader033.fdocuments.in/reader033/viewer/2022060920/60ac5091a12d445dad178a04/html5/thumbnails/61.jpg)
Move your mouse so that you're hovering over thebutton that's third from the left. If you hover
over it, it should say “step over.”
![Page 62: Assignment 0: Using the Debugger · in debug mode, whenever the program gets to this line, it will pause and open up the debugger so we can see what's going on. Now, we're going to](https://reader033.fdocuments.in/reader033/viewer/2022060920/60ac5091a12d445dad178a04/html5/thumbnails/62.jpg)
Once you're confident that you're on the “Step Over”button – and not the “Step Into” or “Step Out”
buttons – go and click it! When you do...
![Page 63: Assignment 0: Using the Debugger · in debug mode, whenever the program gets to this line, it will pause and open up the debugger so we can see what's going on. Now, we're going to](https://reader033.fdocuments.in/reader033/viewer/2022060920/60ac5091a12d445dad178a04/html5/thumbnails/63.jpg)
...your window should look something like this.
![Page 64: Assignment 0: Using the Debugger · in debug mode, whenever the program gets to this line, it will pause and open up the debugger so we can see what's going on. Now, we're going to](https://reader033.fdocuments.in/reader033/viewer/2022060920/60ac5091a12d445dad178a04/html5/thumbnails/64.jpg)
Okay! A few things have changed. Let's see what'sgoing on.
![Page 65: Assignment 0: Using the Debugger · in debug mode, whenever the program gets to this line, it will pause and open up the debugger so we can see what's going on. Now, we're going to](https://reader033.fdocuments.in/reader033/viewer/2022060920/60ac5091a12d445dad178a04/html5/thumbnails/65.jpg)
First, notice that our helpful Yellow Arrow friendis now pointing at line 67.
![Page 66: Assignment 0: Using the Debugger · in debug mode, whenever the program gets to this line, it will pause and open up the debugger so we can see what's going on. Now, we're going to](https://reader033.fdocuments.in/reader033/viewer/2022060920/60ac5091a12d445dad178a04/html5/thumbnails/66.jpg)
We're now at the line right after the one wherewe stopped. You just ran a single line of the
program! Pretty cool!
![Page 67: Assignment 0: Using the Debugger · in debug mode, whenever the program gets to this line, it will pause and open up the debugger so we can see what's going on. Now, we're going to](https://reader033.fdocuments.in/reader033/viewer/2022060920/60ac5091a12d445dad178a04/html5/thumbnails/67.jpg)
So what did that line of code do?
![Page 68: Assignment 0: Using the Debugger · in debug mode, whenever the program gets to this line, it will pause and open up the debugger so we can see what's going on. Now, we're going to](https://reader033.fdocuments.in/reader033/viewer/2022060920/60ac5091a12d445dad178a04/html5/thumbnails/68.jpg)
This line converts ch to lower case. The tolowerfunction takes in a character and returns a lower-case version of it, so this overwrites ch with a
lower-case version of itself.
![Page 69: Assignment 0: Using the Debugger · in debug mode, whenever the program gets to this line, it will pause and open up the debugger so we can see what's going on. Now, we're going to](https://reader033.fdocuments.in/reader033/viewer/2022060920/60ac5091a12d445dad178a04/html5/thumbnails/69.jpg)
You can actually see this by looking at the valuespanel over on the side!
![Page 70: Assignment 0: Using the Debugger · in debug mode, whenever the program gets to this line, it will pause and open up the debugger so we can see what's going on. Now, we're going to](https://reader033.fdocuments.in/reader033/viewer/2022060920/60ac5091a12d445dad178a04/html5/thumbnails/70.jpg)
Notice that the value associated with ch has changedfrom 'A' to 'a' – it's now in lower-case!
![Page 71: Assignment 0: Using the Debugger · in debug mode, whenever the program gets to this line, it will pause and open up the debugger so we can see what's going on. Now, we're going to](https://reader033.fdocuments.in/reader033/viewer/2022060920/60ac5091a12d445dad178a04/html5/thumbnails/71.jpg)
If you'll notice, this value is in red while all theother values are in black.
![Page 72: Assignment 0: Using the Debugger · in debug mode, whenever the program gets to this line, it will pause and open up the debugger so we can see what's going on. Now, we're going to](https://reader033.fdocuments.in/reader033/viewer/2022060920/60ac5091a12d445dad178a04/html5/thumbnails/72.jpg)
This indicates that the value here has changed sincethe previous step. This is a really useful way tokeep track of what's changing as you run the
program.
![Page 73: Assignment 0: Using the Debugger · in debug mode, whenever the program gets to this line, it will pause and open up the debugger so we can see what's going on. Now, we're going to](https://reader033.fdocuments.in/reader033/viewer/2022060920/60ac5091a12d445dad178a04/html5/thumbnails/73.jpg)
Now, let's take a look at line 67, where we areright now.
![Page 74: Assignment 0: Using the Debugger · in debug mode, whenever the program gets to this line, it will pause and open up the debugger so we can see what's going on. Now, we're going to](https://reader033.fdocuments.in/reader033/viewer/2022060920/60ac5091a12d445dad178a04/html5/thumbnails/74.jpg)
Not gonna lie, this is a pretty dense line ofcode. It performs some weird sort of
mathematical calculation on a bunch of differentvalues.
![Page 75: Assignment 0: Using the Debugger · in debug mode, whenever the program gets to this line, it will pause and open up the debugger so we can see what's going on. Now, we're going to](https://reader033.fdocuments.in/reader033/viewer/2022060920/60ac5091a12d445dad178a04/html5/thumbnails/75.jpg)
Fundamentally, though, it's just computing someweird function of some values and stashing it into
hashVal.
![Page 76: Assignment 0: Using the Debugger · in debug mode, whenever the program gets to this line, it will pause and open up the debugger so we can see what's going on. Now, we're going to](https://reader033.fdocuments.in/reader033/viewer/2022060920/60ac5091a12d445dad178a04/html5/thumbnails/76.jpg)
Let's go run that line of code and see whathappens!
![Page 77: Assignment 0: Using the Debugger · in debug mode, whenever the program gets to this line, it will pause and open up the debugger so we can see what's going on. Now, we're going to](https://reader033.fdocuments.in/reader033/viewer/2022060920/60ac5091a12d445dad178a04/html5/thumbnails/77.jpg)
Hover over the “Step Over” button, confirm thatthe button you're clicking really is “Step Over,”
and click it! When you do...
![Page 78: Assignment 0: Using the Debugger · in debug mode, whenever the program gets to this line, it will pause and open up the debugger so we can see what's going on. Now, we're going to](https://reader033.fdocuments.in/reader033/viewer/2022060920/60ac5091a12d445dad178a04/html5/thumbnails/78.jpg)
... you'll end up with something like this!
![Page 79: Assignment 0: Using the Debugger · in debug mode, whenever the program gets to this line, it will pause and open up the debugger so we can see what's going on. Now, we're going to](https://reader033.fdocuments.in/reader033/viewer/2022060920/60ac5091a12d445dad178a04/html5/thumbnails/79.jpg)
Let's see what's changed.
![Page 80: Assignment 0: Using the Debugger · in debug mode, whenever the program gets to this line, it will pause and open up the debugger so we can see what's going on. Now, we're going to](https://reader033.fdocuments.in/reader033/viewer/2022060920/60ac5091a12d445dad178a04/html5/thumbnails/80.jpg)
First, notice that the value stored in hashValchanged to 97. We know that it changed because the
value is in red, and we know that nothing elsechanged because nothing else is in red!
![Page 81: Assignment 0: Using the Debugger · in debug mode, whenever the program gets to this line, it will pause and open up the debugger so we can see what's going on. Now, we're going to](https://reader033.fdocuments.in/reader033/viewer/2022060920/60ac5091a12d445dad178a04/html5/thumbnails/81.jpg)
Second, notice that we're back up at the top ofthe for loop, since that's where the yellow arrowis pointing. We ended up back here because this
is the next line that gets executed.
![Page 82: Assignment 0: Using the Debugger · in debug mode, whenever the program gets to this line, it will pause and open up the debugger so we can see what's going on. Now, we're going to](https://reader033.fdocuments.in/reader033/viewer/2022060920/60ac5091a12d445dad178a04/html5/thumbnails/82.jpg)
We just single-stepped through a single iterationof that loop! Pretty cool!
![Page 83: Assignment 0: Using the Debugger · in debug mode, whenever the program gets to this line, it will pause and open up the debugger so we can see what's going on. Now, we're going to](https://reader033.fdocuments.in/reader033/viewer/2022060920/60ac5091a12d445dad178a04/html5/thumbnails/83.jpg)
Let's go do it again!
![Page 84: Assignment 0: Using the Debugger · in debug mode, whenever the program gets to this line, it will pause and open up the debugger so we can see what's going on. Now, we're going to](https://reader033.fdocuments.in/reader033/viewer/2022060920/60ac5091a12d445dad178a04/html5/thumbnails/84.jpg)
Again, move your mouse over the Step Overbutton (and make sure it says “Step Over” and
not something else!), then click it.
![Page 85: Assignment 0: Using the Debugger · in debug mode, whenever the program gets to this line, it will pause and open up the debugger so we can see what's going on. Now, we're going to](https://reader033.fdocuments.in/reader033/viewer/2022060920/60ac5091a12d445dad178a04/html5/thumbnails/85.jpg)
Now we're here! Notice that ch now has the value'd', which is the second letter of the name Ada.
![Page 86: Assignment 0: Using the Debugger · in debug mode, whenever the program gets to this line, it will pause and open up the debugger so we can see what's going on. Now, we're going to](https://reader033.fdocuments.in/reader033/viewer/2022060920/60ac5091a12d445dad178a04/html5/thumbnails/86.jpg)
Go click “Step Over” again to run this line ofcode.
![Page 87: Assignment 0: Using the Debugger · in debug mode, whenever the program gets to this line, it will pause and open up the debugger so we can see what's going on. Now, we're going to](https://reader033.fdocuments.in/reader033/viewer/2022060920/60ac5091a12d445dad178a04/html5/thumbnails/87.jpg)
You should be here now. Notice that none of thevalues changed. That makes sense, since all we didwas convert a lower-case 'd' to a lower-case 'd'.
![Page 88: Assignment 0: Using the Debugger · in debug mode, whenever the program gets to this line, it will pause and open up the debugger so we can see what's going on. Now, we're going to](https://reader033.fdocuments.in/reader033/viewer/2022060920/60ac5091a12d445dad178a04/html5/thumbnails/88.jpg)
Now, click “Step Over” one more time.
![Page 89: Assignment 0: Using the Debugger · in debug mode, whenever the program gets to this line, it will pause and open up the debugger so we can see what's going on. Now, we're going to](https://reader033.fdocuments.in/reader033/viewer/2022060920/60ac5091a12d445dad178a04/html5/thumbnails/89.jpg)
You'll now be at this point in the program. We'vecovered up the value of hashVal in this image, because
at this point you should be able to see what hashVal is byreading the value in the side pane. This is the special valuewe want you to tell us when submitting the assignment!
? ? ? ?
Look here!Look here!
![Page 90: Assignment 0: Using the Debugger · in debug mode, whenever the program gets to this line, it will pause and open up the debugger so we can see what's going on. Now, we're going to](https://reader033.fdocuments.in/reader033/viewer/2022060920/60ac5091a12d445dad178a04/html5/thumbnails/90.jpg)
? ? ? ?
To finish up this section on the debugger, we'd like to showyou two last little techniques that you might find useful
when debugging programs.
![Page 91: Assignment 0: Using the Debugger · in debug mode, whenever the program gets to this line, it will pause and open up the debugger so we can see what's going on. Now, we're going to](https://reader033.fdocuments.in/reader033/viewer/2022060920/60ac5091a12d445dad178a04/html5/thumbnails/91.jpg)
? ? ? ?
To start this off, click on the the breakpoint that we setearlier in the program. If you do...
![Page 92: Assignment 0: Using the Debugger · in debug mode, whenever the program gets to this line, it will pause and open up the debugger so we can see what's going on. Now, we're going to](https://reader033.fdocuments.in/reader033/viewer/2022060920/60ac5091a12d445dad178a04/html5/thumbnails/92.jpg)
... it should clear the breakpoint. Now, if we were to runthis program again in debug mode, it would not stop at this
point, since nothing's telling it to!
? ? ? ?
![Page 93: Assignment 0: Using the Debugger · in debug mode, whenever the program gets to this line, it will pause and open up the debugger so we can see what's going on. Now, we're going to](https://reader033.fdocuments.in/reader033/viewer/2022060920/60ac5091a12d445dad178a04/html5/thumbnails/93.jpg)
? ? ? ?
Now, take a look back at these buttons.
![Page 94: Assignment 0: Using the Debugger · in debug mode, whenever the program gets to this line, it will pause and open up the debugger so we can see what's going on. Now, we're going to](https://reader033.fdocuments.in/reader033/viewer/2022060920/60ac5091a12d445dad178a04/html5/thumbnails/94.jpg)
? ? ? ?
Hover your mouse over the one that's on the far right. When you hover over
it, it should say “Step Out.”
![Page 95: Assignment 0: Using the Debugger · in debug mode, whenever the program gets to this line, it will pause and open up the debugger so we can see what's going on. Now, we're going to](https://reader033.fdocuments.in/reader033/viewer/2022060920/60ac5091a12d445dad178a04/html5/thumbnails/95.jpg)
? ? ? ?
Don’t click just yet. But when you do click,it will run the rest of the nameHash
function until it finishes and returns.
![Page 96: Assignment 0: Using the Debugger · in debug mode, whenever the program gets to this line, it will pause and open up the debugger so we can see what's going on. Now, we're going to](https://reader033.fdocuments.in/reader033/viewer/2022060920/60ac5091a12d445dad178a04/html5/thumbnails/96.jpg)
? ? ? ?
Now, go click that button. If you dideverything right...
![Page 97: Assignment 0: Using the Debugger · in debug mode, whenever the program gets to this line, it will pause and open up the debugger so we can see what's going on. Now, we're going to](https://reader033.fdocuments.in/reader033/viewer/2022060920/60ac5091a12d445dad178a04/html5/thumbnails/97.jpg)
... you should end up with something thatlooks like this!
![Page 98: Assignment 0: Using the Debugger · in debug mode, whenever the program gets to this line, it will pause and open up the debugger so we can see what's going on. Now, we're going to](https://reader033.fdocuments.in/reader033/viewer/2022060920/60ac5091a12d445dad178a04/html5/thumbnails/98.jpg)
Let's take a minute to get our bearings.Where exactly are we?
![Page 99: Assignment 0: Using the Debugger · in debug mode, whenever the program gets to this line, it will pause and open up the debugger so we can see what's going on. Now, we're going to](https://reader033.fdocuments.in/reader033/viewer/2022060920/60ac5091a12d445dad178a04/html5/thumbnails/99.jpg)
Well, the yellow arrow indicates that we'reback in main again. Cool!
![Page 100: Assignment 0: Using the Debugger · in debug mode, whenever the program gets to this line, it will pause and open up the debugger so we can see what's going on. Now, we're going to](https://reader033.fdocuments.in/reader033/viewer/2022060920/60ac5091a12d445dad178a04/html5/thumbnails/100.jpg)
We can see that the nameHash functionreturned 1967457. Thanks, debugger!
(A note: it seems like on some Macs, thisnumber isn’t displaying. Don’t worry if youdon’t see it – just continue on as usual.)
![Page 101: Assignment 0: Using the Debugger · in debug mode, whenever the program gets to this line, it will pause and open up the debugger so we can see what's going on. Now, we're going to](https://reader033.fdocuments.in/reader033/viewer/2022060920/60ac5091a12d445dad178a04/html5/thumbnails/101.jpg)
But if we look up over here, we see thathashValue isn’t storing 1967457, even though that’s
what was returned.
(You might see a number other than 0 onyour system – that’s okay.)
![Page 102: Assignment 0: Using the Debugger · in debug mode, whenever the program gets to this line, it will pause and open up the debugger so we can see what's going on. Now, we're going to](https://reader033.fdocuments.in/reader033/viewer/2022060920/60ac5091a12d445dad178a04/html5/thumbnails/102.jpg)
But it looks like we're setting hashValueequal to the number that was returned bythe nameHash function. What's going on?
![Page 103: Assignment 0: Using the Debugger · in debug mode, whenever the program gets to this line, it will pause and open up the debugger so we can see what's going on. Now, we're going to](https://reader033.fdocuments.in/reader033/viewer/2022060920/60ac5091a12d445dad178a04/html5/thumbnails/103.jpg)
This is pretty cool, actually!
![Page 104: Assignment 0: Using the Debugger · in debug mode, whenever the program gets to this line, it will pause and open up the debugger so we can see what's going on. Now, we're going to](https://reader033.fdocuments.in/reader033/viewer/2022060920/60ac5091a12d445dad178a04/html5/thumbnails/104.jpg)
What's happened is that we've just returnedfrom nameHash with a value, but since we're
going through the program one step at a time,we haven't actually assigned that value to
hashValue yet!
![Page 105: Assignment 0: Using the Debugger · in debug mode, whenever the program gets to this line, it will pause and open up the debugger so we can see what's going on. Now, we're going to](https://reader033.fdocuments.in/reader033/viewer/2022060920/60ac5091a12d445dad178a04/html5/thumbnails/105.jpg)
Let's do a “Step Over” so that we can finishexecuting this line. Click “Step Over,” and
if you did everything right...
![Page 106: Assignment 0: Using the Debugger · in debug mode, whenever the program gets to this line, it will pause and open up the debugger so we can see what's going on. Now, we're going to](https://reader033.fdocuments.in/reader033/viewer/2022060920/60ac5091a12d445dad178a04/html5/thumbnails/106.jpg)
... you should see the right value get stored(notice it's in red!) and we've moved to the
next line.
![Page 107: Assignment 0: Using the Debugger · in debug mode, whenever the program gets to this line, it will pause and open up the debugger so we can see what's going on. Now, we're going to](https://reader033.fdocuments.in/reader033/viewer/2022060920/60ac5091a12d445dad178a04/html5/thumbnails/107.jpg)
At this point, we've seen just about everythingwe care about. Rather than single-steppingall the way to the end, let's just tell the
program to keep on running.
![Page 108: Assignment 0: Using the Debugger · in debug mode, whenever the program gets to this line, it will pause and open up the debugger so we can see what's going on. Now, we're going to](https://reader033.fdocuments.in/reader033/viewer/2022060920/60ac5091a12d445dad178a04/html5/thumbnails/108.jpg)
To do this, click on this button. If you hoverover it, it says “Continue,” and that buttonmeans “unpause the program and let it keep
running from here.”
![Page 109: Assignment 0: Using the Debugger · in debug mode, whenever the program gets to this line, it will pause and open up the debugger so we can see what's going on. Now, we're going to](https://reader033.fdocuments.in/reader033/viewer/2022060920/60ac5091a12d445dad178a04/html5/thumbnails/109.jpg)
If you do, you should see something like this.(The program window might not automaticallypop up. That's okay! Just open it manually.)
Our program is now done running!
![Page 110: Assignment 0: Using the Debugger · in debug mode, whenever the program gets to this line, it will pause and open up the debugger so we can see what's going on. Now, we're going to](https://reader033.fdocuments.in/reader033/viewer/2022060920/60ac5091a12d445dad178a04/html5/thumbnails/110.jpg)
So there you have it! You've now gotten morefamiliar with the debugger!
![Page 111: Assignment 0: Using the Debugger · in debug mode, whenever the program gets to this line, it will pause and open up the debugger so we can see what's going on. Now, we're going to](https://reader033.fdocuments.in/reader033/viewer/2022060920/60ac5091a12d445dad178a04/html5/thumbnails/111.jpg)
You know how to set a breakpoint to pause theprogram at a particular point.
![Page 112: Assignment 0: Using the Debugger · in debug mode, whenever the program gets to this line, it will pause and open up the debugger so we can see what's going on. Now, we're going to](https://reader033.fdocuments.in/reader033/viewer/2022060920/60ac5091a12d445dad178a04/html5/thumbnails/112.jpg)
You know how to read the call stack and tosee the values of local variables.
![Page 113: Assignment 0: Using the Debugger · in debug mode, whenever the program gets to this line, it will pause and open up the debugger so we can see what's going on. Now, we're going to](https://reader033.fdocuments.in/reader033/viewer/2022060920/60ac5091a12d445dad178a04/html5/thumbnails/113.jpg)
You know how to single-step the program andsee what values change.
![Page 114: Assignment 0: Using the Debugger · in debug mode, whenever the program gets to this line, it will pause and open up the debugger so we can see what's going on. Now, we're going to](https://reader033.fdocuments.in/reader033/viewer/2022060920/60ac5091a12d445dad178a04/html5/thumbnails/114.jpg)
You know how to run a function to completion,and how to let the program keep on running.
![Page 115: Assignment 0: Using the Debugger · in debug mode, whenever the program gets to this line, it will pause and open up the debugger so we can see what's going on. Now, we're going to](https://reader033.fdocuments.in/reader033/viewer/2022060920/60ac5091a12d445dad178a04/html5/thumbnails/115.jpg)
As you write more and more complicatedprograms this quarter, you'll get a lot morefamiliar using the debugger and seeing how
your programs work.
![Page 116: Assignment 0: Using the Debugger · in debug mode, whenever the program gets to this line, it will pause and open up the debugger so we can see what's going on. Now, we're going to](https://reader033.fdocuments.in/reader033/viewer/2022060920/60ac5091a12d445dad178a04/html5/thumbnails/116.jpg)
And, if you continue to build larger and largerpieces of software, you'll find that knowing how
to use a debugger is a surprisingly valuableskill!
![Page 117: Assignment 0: Using the Debugger · in debug mode, whenever the program gets to this line, it will pause and open up the debugger so we can see what's going on. Now, we're going to](https://reader033.fdocuments.in/reader033/viewer/2022060920/60ac5091a12d445dad178a04/html5/thumbnails/117.jpg)
Hope this helps, and welcome to CS106B!