Assignment 0: Using the Debugger · in debug mode, whenever the program gets to this line, it will...

117
Assignment 0: Using the Debugger

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

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

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

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

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

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

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

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

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

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

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

... 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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

...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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

... 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

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

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

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

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

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

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

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

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

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

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

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

? ? ? ?

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

? ? ? ?

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

... 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

? ? ? ?

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

? ? ? ?

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

? ? ? ?

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

? ? ? ?

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

... 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

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

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

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

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

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

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

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

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

... 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

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

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

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

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

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

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

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

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

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

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

Hope this helps, and welcome to CS106B!