1
00:00:00,150 --> 00:00:07,380
So in this lecture, we are going to go over a kind of offshoot side topic called debugging.

2
00:00:07,770 --> 00:00:13,280
So you may have been doing this already, which I hope you have.

3
00:00:13,290 --> 00:00:19,990
But for those of you that know what debugging is, it's just solving errors in your code.

4
00:00:20,010 --> 00:00:27,210
So if you run into an error, you know whether it be a compile time as a compiler area or at runtime,

5
00:00:27,210 --> 00:00:32,250
or maybe you have some type of logical error when you're running your program and you're trying to figure

6
00:00:32,250 --> 00:00:36,120
out why you got a value that you didn't expect as output or something like that.

7
00:00:36,660 --> 00:00:41,850
Fixing all these errors is considered debugging and just kind of a fun fact, and I'm not a hundred

8
00:00:41,850 --> 00:00:43,980
percent sure if this is true or not.

9
00:00:43,980 --> 00:00:50,190
But what I heard was where debugging came from was way back in the day when there was gigantic computers

10
00:00:50,190 --> 00:00:56,380
that were just like the size of, you know, small apartment or something.

11
00:00:57,600 --> 00:01:04,950
There was a bug that had literally lodged itself in one of these computers, and I believe it was Grace

12
00:01:04,950 --> 00:01:09,620
Hopper, a famous computer scientist that had to remove this bug.

13
00:01:09,630 --> 00:01:15,030
I think it was a moth or something and fixed the error in the computer because there was some bug in

14
00:01:15,030 --> 00:01:16,530
there, like shorting something now.

15
00:01:17,250 --> 00:01:18,780
And so that kind of stuck.

16
00:01:18,780 --> 00:01:23,250
And since then, they've referred to fixing errors as debugging.

17
00:01:24,560 --> 00:01:29,810
So in honor of censure, if that's true, but just kind of an interesting story I thought I'd share.

18
00:01:30,290 --> 00:01:30,710
But.

19
00:01:32,450 --> 00:01:37,400
Yeah, what we're going to be doing is figuring out how to solve errors, so hopefully if you encountered

20
00:01:37,400 --> 00:01:40,100
errors up to this point, you have figured out how to solve them.

21
00:01:40,670 --> 00:01:43,550
I'm going to go over three different ways of debugging.

22
00:01:43,820 --> 00:01:50,090
And the first one is something that you probably have been doing if you've been solving errors on your

23
00:01:50,090 --> 00:01:50,360
own.

24
00:01:50,450 --> 00:01:53,780
And what this is is using see out statements.

25
00:01:53,780 --> 00:01:55,810
So this is kind of most primitive way of debugging.

26
00:01:55,820 --> 00:02:01,190
So I have hidden a couple of errors in here and we are going to debug them.

27
00:02:02,150 --> 00:02:09,290
So if you haven't noticed already, this is Project two that I'm using, so an implementation of Project

28
00:02:09,290 --> 00:02:15,500
two, where we have a binary search, we read in from a file, we saw the file and we use that binary

29
00:02:15,500 --> 00:02:22,460
search to search for some names in this like quote unquote database, which is really just stored in

30
00:02:22,460 --> 00:02:23,060
vectors.

31
00:02:23,990 --> 00:02:31,970
So we expect the program to start and ask us for a name to be searched in the database and then we,

32
00:02:31,970 --> 00:02:35,570
of course, have the option to quit as well.

33
00:02:37,100 --> 00:02:43,910
So if this program wants to run normally, it would have this normal exit code and it would it would

34
00:02:43,910 --> 00:02:44,810
exit fine.

35
00:02:45,410 --> 00:02:47,210
So but it's not going to exit fine.

36
00:02:47,840 --> 00:02:51,050
In fact, it's not going to ask us for a name to be searched in the database.

37
00:02:51,800 --> 00:02:57,530
So if I go ahead and run the program right now here and sea lion, I notice that it doesn't ask me anything.

38
00:02:57,530 --> 00:03:02,270
And just as process finished with exit code, this big number, which is not good, that's not what

39
00:03:02,270 --> 00:03:02,900
you want to see.

40
00:03:03,170 --> 00:03:07,190
You want a normal, you know, exit code like zero or something.

41
00:03:08,630 --> 00:03:10,900
So that is not good.

42
00:03:10,910 --> 00:03:12,010
How are we going to debug this?

43
00:03:12,020 --> 00:03:19,760
So the first thing we're going to do is use C out to figure out how far our program is making it, and

44
00:03:19,760 --> 00:03:24,560
therefore we can narrow down where it is getting stuck and where it's crashing.

45
00:03:25,500 --> 00:03:31,080
So what we can do is kind of put this out in different places, so I could be like, well, it's not

46
00:03:31,080 --> 00:03:31,920
making it to here.

47
00:03:32,250 --> 00:03:33,210
Why don't I just put it?

48
00:03:35,440 --> 00:03:39,920
Right here, I'll just see out the word test and see if that actually prints out.

49
00:03:40,660 --> 00:03:42,190
So I go here and I run it.

50
00:03:44,780 --> 00:03:50,260
And I say, huh, OK, that didn't print out there, so my program is not making it to the line 90.

51
00:03:51,100 --> 00:03:59,600
So I go ahead and I get rid of that and I say, OK, well, maybe I put it before the force or so I

52
00:03:59,680 --> 00:04:02,140
thought maybe it was happening and sort, but I guess it's not.

53
00:04:02,140 --> 00:04:03,730
So let's put it there and run it.

54
00:04:05,380 --> 00:04:06,970
Oh, it's still not printing out.

55
00:04:07,000 --> 00:04:12,580
OK, well, let's see, I'll just keep moving it up, then I guess I'll put it right here.

56
00:04:16,880 --> 00:04:17,750
And put it here.

57
00:04:18,260 --> 00:04:23,240
Oh, it actually prints out, so our program actually makes it to here, but it doesn't make it to line

58
00:04:23,240 --> 00:04:23,990
eighty nine.

59
00:04:24,650 --> 00:04:27,290
That means that the problem must be right here.

60
00:04:27,410 --> 00:04:31,340
So I see out my Vic six, that's kind of random.

61
00:04:31,940 --> 00:04:33,480
Why is that not OK?

62
00:04:33,500 --> 00:04:34,420
Let's go up here.

63
00:04:34,430 --> 00:04:35,690
What is my vector?

64
00:04:35,930 --> 00:04:37,730
So let's see what that is.

65
00:04:38,820 --> 00:04:44,310
Well, looks like we just declare my verdict, we don't do anything, we don't read into it, we read

66
00:04:44,310 --> 00:04:46,760
into names that we push back to name of.

67
00:04:46,890 --> 00:04:49,800
We push back to bank, but we don't put anything in my vict.

68
00:04:50,700 --> 00:04:52,860
Well, this is kind of one of the areas that I had.

69
00:04:52,860 --> 00:04:54,190
That was just a stupid error.

70
00:04:54,230 --> 00:04:59,100
You know, I put some vector in here that's just has no size here, and I'm trying to read out of thin

71
00:04:59,100 --> 00:05:02,190
air, which is a blatant access violation.

72
00:05:02,730 --> 00:05:06,360
So I'm going to just get rid of this altogether.

73
00:05:08,600 --> 00:05:16,220
And that will fix my hair, so, you know, so you can just move this test around in the code to see

74
00:05:16,220 --> 00:05:18,020
where the problem is.

75
00:05:18,560 --> 00:05:24,170
So that's one type of debugging is just trying to see where the programs crashing.

76
00:05:24,170 --> 00:05:29,090
If your program is crashing, you can just use this see out statement with a little test or something,

77
00:05:29,360 --> 00:05:32,210
and then you can narrow down where the program is crashing.

78
00:05:33,290 --> 00:05:38,750
So I'm going to go ahead and remove this and then let's go ahead and run our program.

79
00:05:42,180 --> 00:05:46,890
OK, so now this is for a name to search in the database, so let's pull up some, let's look at some

80
00:05:46,890 --> 00:05:47,260
names.

81
00:05:47,260 --> 00:05:48,570
So what names do I have in here?

82
00:05:48,600 --> 00:05:50,400
Well, I've got Dylan.

83
00:05:50,400 --> 00:05:52,260
I should be able to search that name.

84
00:05:52,680 --> 00:05:54,960
So I go in here and I search Dylan.

85
00:05:56,340 --> 00:06:01,620
Oh, that's weird, though, since the name Dylan does not exist in the database, but it should exist

86
00:06:01,620 --> 00:06:02,610
in a database.

87
00:06:04,120 --> 00:06:06,010
OK, that's a little weird.

88
00:06:06,670 --> 00:06:08,980
So we're going to have to narrow this down, right?

89
00:06:09,520 --> 00:06:11,500
Why does it not exist in the database?

90
00:06:14,100 --> 00:06:15,270
So now we should.

91
00:06:16,800 --> 00:06:21,540
Try and see kind of like what's going on and why it why it doesn't exist in the database so.

92
00:06:23,080 --> 00:06:25,090
We're reading in some names, right?

93
00:06:25,390 --> 00:06:35,380
And then we're sorting some names, so let's just see, first off, if our names get kind of read into

94
00:06:35,380 --> 00:06:38,710
here correctly, so maybe you want to print out what's in the vector.

95
00:06:39,430 --> 00:06:42,790
So I might just make some code here that I can copy and paste it.

96
00:06:42,790 --> 00:06:47,560
In fact, I might just make a function where I can print out the vector.

97
00:06:49,540 --> 00:06:51,380
So I'm going to put it right here.

98
00:06:51,400 --> 00:06:52,690
I'm just going to make some function.

99
00:06:53,290 --> 00:07:01,990
It's just void and it just says that and it just takes a vector of type

100
00:07:04,630 --> 00:07:12,610
string and I'm just going to call that V and I'm actually going to pass it by a reference.

101
00:07:12,610 --> 00:07:16,600
Or actually, I want fast answers, but it's by copy value.

102
00:07:17,440 --> 00:07:24,220
So it'll take this Vector V and then I'll just say four and I'm going to do a range based loop here.

103
00:07:24,250 --> 00:07:39,190
And I'm just going to say for high or auto, high, the sea out I and space.

104
00:07:42,280 --> 00:07:46,000
And then we will just close and find.

105
00:07:47,140 --> 00:07:49,030
OK, I was just kind of earning their.

106
00:07:52,240 --> 00:07:54,730
First, and I can't reference.

107
00:07:58,370 --> 00:08:04,970
So I can this changes to a cost reference to make it a go with the suggestion there, but it's just

108
00:08:04,970 --> 00:08:07,290
a simple oops conference, everything out in the factory.

109
00:08:08,420 --> 00:08:11,810
So now I have this nice little foil loop, they can print it out.

110
00:08:11,810 --> 00:08:15,010
So I'm going to say, well, I read everything into the vector.

111
00:08:15,020 --> 00:08:21,710
Let's go ahead and to print fact and say name that.

112
00:08:24,290 --> 00:08:27,060
And let's see, let's see what it says.

113
00:08:27,080 --> 00:08:31,850
Let's see if it actually reads everything into the vector, OK?

114
00:08:35,430 --> 00:08:36,630
So I'm going to run this.

115
00:08:39,110 --> 00:08:44,570
OK, so it looks like it's doing Dylan, Jeff and Elliott Gould Frances, so it is reading Dylan into

116
00:08:44,570 --> 00:08:45,020
their.

117
00:08:48,330 --> 00:08:55,920
So that looks like it should be fine, and it looks like it all at lowercase them all, I came in wanting

118
00:08:55,920 --> 00:08:56,460
it to.

119
00:08:59,630 --> 00:09:03,020
So what seems to be the.

120
00:09:04,770 --> 00:09:06,050
Seems to be the issue.

121
00:09:09,070 --> 00:09:10,830
So, you know, that makes it lower.

122
00:09:11,380 --> 00:09:16,300
I don't really see what the problem is, so let's see what happens after this, because if I type Dylan

123
00:09:16,300 --> 00:09:20,230
now, you know, it still says the name does not exist in the database, so.

124
00:09:21,270 --> 00:09:29,820
Maybe it's something to do with the source, so I could copy this and I could put it here after this

125
00:09:29,820 --> 00:09:30,210
sort.

126
00:09:31,990 --> 00:09:36,700
So I'll go ahead and print it out once, before and once after the.

127
00:09:38,410 --> 00:09:45,010
Maybe it's a problem with the sword, maybe the sword is doing something and that's making it not have

128
00:09:45,010 --> 00:09:45,640
Dylan in that.

129
00:09:45,640 --> 00:09:51,340
Maybe it's changing up the vector and then I can see if they if that is the problem that I can go to

130
00:09:51,340 --> 00:09:52,510
sort of debug sort.

131
00:09:56,420 --> 00:10:00,110
Oh, OK, well, that definitely shows us there's a problem, right?

132
00:10:00,890 --> 00:10:07,250
It says we saw Dylan was in here originally when we printed it out before the sword, but then we did.

133
00:10:07,250 --> 00:10:12,770
The sword only printed out the vector out after the sword and says, and Francis Francis, it doesn't

134
00:10:12,770 --> 00:10:16,010
have Dylan or Jeff or Leopold in there.

135
00:10:16,010 --> 00:10:18,070
So that's definitely a problem.

136
00:10:18,080 --> 00:10:19,860
Now we know the problem is in our sort.

137
00:10:22,160 --> 00:10:26,240
So you can see that we're able to use printing stuff out to help us quite a bit.

138
00:10:26,990 --> 00:10:28,880
So if I head over to sort.

139
00:10:31,830 --> 00:10:38,790
I can go in here and, you know, you can kind of look at this and see if you see anything that's wrong

140
00:10:38,790 --> 00:10:41,010
and maybe you immediately see something that's wrong.

141
00:10:42,800 --> 00:10:46,730
But what we can do is also print some stuff out like.

142
00:10:48,440 --> 00:10:52,070
We expect Dylan to be in the front of the victor, right?

143
00:10:54,320 --> 00:10:55,370
So.

144
00:10:57,730 --> 00:11:04,360
We you think about how it's going to swap initially, you know, with our sorting algorithm, or we

145
00:11:04,360 --> 00:11:06,310
could just go ahead and print it out.

146
00:11:07,030 --> 00:11:10,840
I might just opt to just print it out and just see kind of what happens so.

147
00:11:12,470 --> 00:11:20,670
How about after each iteration of the loop, while we're doing like these swaps and things, I just

148
00:11:20,670 --> 00:11:23,030
choose to see out?

149
00:11:24,350 --> 00:11:33,350
Can I just say that there are those that to say the typing is really becoming a struggle lately and

150
00:11:33,920 --> 00:11:35,420
there is so.

151
00:11:35,720 --> 00:11:40,970
And then I say, how about I say?

152
00:11:42,290 --> 00:11:46,490
Which, in fact, is going to be an issue.

153
00:11:46,550 --> 00:11:48,500
So I'll have to put this above here.

154
00:11:51,020 --> 00:11:52,090
Let me talk to you this.

155
00:12:01,890 --> 00:12:10,490
All right, so I can say preemptive act and I can say, what is this, uh, the string victories fee?

156
00:12:12,550 --> 00:12:13,990
So I can say, in fact, we.

157
00:12:15,290 --> 00:12:20,510
So they don't print out everything on that right after this vector in a space each time is going to

158
00:12:20,510 --> 00:12:24,560
print that out and then it can kind of kind of help me out.

159
00:12:24,570 --> 00:12:27,310
So let's just put a little comment here and say

160
00:12:29,930 --> 00:12:30,500
debug.

161
00:12:32,270 --> 00:12:34,850
So now we can see what's happening to the vector each time, right?

162
00:12:35,210 --> 00:12:36,890
Go ahead and it'll print out there.

163
00:12:37,760 --> 00:12:42,500
So here I deleted these things that we're printing out the vector, the calls to print vector.

164
00:12:42,510 --> 00:12:46,760
Now I'm just going to check what happens when we're sorting it.

165
00:12:46,760 --> 00:12:49,220
So it's going to print each time for us.

166
00:12:55,110 --> 00:12:59,880
OK, so Vector starts out as Dylan Jeff and Leopold Frances.

167
00:13:01,510 --> 00:13:11,250
Then it is Dylan, Anna and Leopold Francis, then it's Anna Leopold Francis.

168
00:13:12,190 --> 00:13:15,370
OK, yeah, that's definitely a problem, huh?

169
00:13:16,210 --> 00:13:25,630
So it looks like what it's doing is it's not actually swapping things correctly because it's just replacing

170
00:13:26,110 --> 00:13:32,160
names like it looks like Anna was just here and it wanted to swap with Jeff.

171
00:13:32,170 --> 00:13:33,370
But then it just over it.

172
00:13:33,370 --> 00:13:36,550
Just put Anna here, but it didn't put Jeff over here.

173
00:13:36,880 --> 00:13:43,030
And then when he wanted to swap again as we're just moving it right all the way to the left with this

174
00:13:43,030 --> 00:13:45,760
sort, you know, this is an insertion sort.

175
00:13:45,770 --> 00:13:51,850
So it's just like moving through this moving left as much as it can tell us in the sort of position.

176
00:13:52,330 --> 00:13:55,600
And it looks like it just keeps overwriting as it goes over.

177
00:13:55,630 --> 00:13:59,680
So I think that there's not something being swapped and look right here.

178
00:13:59,690 --> 00:14:04,030
You know, this might have been really obvious to you, but this is accidentally commented out.

179
00:14:04,030 --> 00:14:07,360
So it's not actually swapping the.

180
00:14:09,080 --> 00:14:13,650
Temporary one, so we're trying to do a swap here, but it doesn't finish the swap.

181
00:14:13,670 --> 00:14:15,950
It only swaps one position, so it takes.

182
00:14:16,930 --> 00:14:22,180
Whatever is at this sort of position plus one and puts it in a sort of position, but it doesn't take

183
00:14:22,180 --> 00:14:27,610
the Syrian position what whatever was there which just saved into Tampa doesn't put that into this sort

184
00:14:27,610 --> 00:14:28,870
of position plus one.

185
00:14:29,830 --> 00:14:32,380
So we go ahead and we can comment that.

186
00:14:34,290 --> 00:14:36,540
And now we will go ahead and run it.

187
00:14:40,930 --> 00:14:44,740
And it looks like it actually supports things in a correct manner.

188
00:14:44,980 --> 00:14:48,940
So let's say if I type Dylan, it actually knows now.

189
00:14:48,940 --> 00:14:52,270
The age for Dylan is 20 and that is correct.

190
00:14:54,630 --> 00:15:00,360
OK, so that's kind of how you can use printing out things with the sea, our statement to help you

191
00:15:00,360 --> 00:15:01,290
debug code.

192
00:15:02,100 --> 00:15:07,860
So I'm actually going to delete that and now I'm going to show you two other ways that we can debug

193
00:15:07,860 --> 00:15:08,280
the code.

194
00:15:09,480 --> 00:15:16,950
So let's say we had the same error here and I wanted to see what was inside of the vector.

195
00:15:19,230 --> 00:15:25,400
So I wanted to know, like, oh, you know, what is the what's the issue?

196
00:15:25,430 --> 00:15:30,480
Why is there, you know, why is it not being sorted or something like that?

197
00:15:30,570 --> 00:15:36,060
The air is not here anymore because I can't get out, but what I can do is I could actually examine

198
00:15:36,060 --> 00:15:43,140
this zone right here, so I could say, All right, I want to stop when I'm here and I want to take

199
00:15:43,140 --> 00:15:50,130
a look at the vector and I want to step through the code and watch as things change, watch as the vector

200
00:15:50,130 --> 00:15:55,770
values move around and why, how, you know, variables change and all of that.

201
00:15:56,100 --> 00:16:02,580
This is something that we can do with a debugger, and it's actually a tool that is Bill tend to see

202
00:16:02,580 --> 00:16:03,060
Lion.

203
00:16:04,760 --> 00:16:09,560
So I'm going to go ahead and clear this, and I'm going to show you how to use the C line to bugger,

204
00:16:09,560 --> 00:16:11,540
so to use the sea lion debugger.

205
00:16:11,840 --> 00:16:18,650
You first need to place some points in which you want the code to stop on so you can examine what's

206
00:16:18,650 --> 00:16:19,850
happening in your code.

207
00:16:20,960 --> 00:16:28,040
So if let's say that we want to stop here and kind of slowly steps through these lines and see what's

208
00:16:28,040 --> 00:16:34,670
going on in our code, what I can do is click in this zone right here on the line that I want to stop

209
00:16:34,670 --> 00:16:36,770
on, so I click notice like this.

210
00:16:37,070 --> 00:16:39,320
This is what I'm talking about this gray zone right here.

211
00:16:39,830 --> 00:16:41,090
So I click right here.

212
00:16:41,330 --> 00:16:44,090
You see a red dot appear in this becomes highlighted.

213
00:16:44,810 --> 00:16:51,500
This is something that we call a breakpoint, and what it means is that it's going to basically break

214
00:16:51,500 --> 00:16:58,230
out of the running of the program and stop right here and let you control as you step through the program.

215
00:16:58,340 --> 00:17:04,820
So now we have our break point, but how do we start this debugging process of our code?

216
00:17:06,200 --> 00:17:12,250
Well, you see up here in the right, we have this button that says Run Project two and this is what

217
00:17:12,290 --> 00:17:18,020
we've been clicking if we want to run the project, when we click that, it opens up the console down

218
00:17:18,020 --> 00:17:20,840
here and it lets us type something right?

219
00:17:24,410 --> 00:17:28,100
So you notice now this exits, finds you, by the way, it has exit code zero.

220
00:17:28,130 --> 00:17:29,160
That's what we want to see.

221
00:17:30,090 --> 00:17:32,600
So that's if we run our program normally.

222
00:17:32,600 --> 00:17:34,280
But now we want to debug.

223
00:17:34,290 --> 00:17:39,680
So if I go one to the right, here you see it, says Debug Project two and you actually notice this

224
00:17:39,680 --> 00:17:41,750
little symbol is like a little bug, right?

225
00:17:42,020 --> 00:17:43,670
Has little antennas and feet.

226
00:17:44,240 --> 00:17:49,370
So instead of running Project two right here, I'm going to click the debug project to and it's going

227
00:17:49,370 --> 00:17:57,710
to basically run my program until this line happens, right until this line gets executed and it's going

228
00:17:57,710 --> 00:17:59,270
to stop there on that line.

229
00:18:01,200 --> 00:18:06,060
So I click that button and you notice now this is highlighted in blue.

230
00:18:06,450 --> 00:18:10,950
What this is telling us is that the program has ran up until this point.

231
00:18:11,250 --> 00:18:13,980
So what happened is it ran it started here.

232
00:18:13,980 --> 00:18:17,610
I mean, it went through all of this in Maine right here.

233
00:18:17,880 --> 00:18:22,740
It saw this the call to sort the sort function that we made it hit.

234
00:18:22,740 --> 00:18:29,960
This line 94 called sort jumped up here to the start function, started running code inside this sort

235
00:18:29,980 --> 00:18:34,440
function, and it got down all the way to here where we put the little red dot right.

236
00:18:34,830 --> 00:18:36,360
And now it's stopped here.

237
00:18:37,170 --> 00:18:41,370
And what we can do now is we can go down here where our console would normally be.

238
00:18:42,270 --> 00:18:45,210
This is the console notice that says Console here.

239
00:18:45,810 --> 00:18:51,210
If I click this right here, it says Debugger and the cool thing right here is now.

240
00:18:51,210 --> 00:18:57,720
It gives us a view into all of these different variables in here.

241
00:18:58,900 --> 00:19:06,340
Which is pretty cool, so it says, you know, insertion item right here, which is a variable.

242
00:19:06,700 --> 00:19:12,670
It tells us what that currently is when we're on this line in our program, so.

243
00:19:13,830 --> 00:19:21,090
As our as we execute line by line, it's like updating the code, right, like what we're doing is we're

244
00:19:21,090 --> 00:19:26,880
running the code line by line now and we can actually step through you notice insertions item has been

245
00:19:26,880 --> 00:19:28,060
modified right here.

246
00:19:28,080 --> 00:19:29,670
So this is the line.

247
00:19:30,740 --> 00:19:36,770
That modified insertion item that is reflected right here, so when it said insertion item equals VII,

248
00:19:36,770 --> 00:19:42,620
it basically, you know, put the name Dylan into this variable insertion item.

249
00:19:42,620 --> 00:19:47,780
And that is why when we stop right here, we notice nothing else in between here and here.

250
00:19:47,810 --> 00:19:50,360
Nothing else has happened to insert an item.

251
00:19:50,840 --> 00:19:56,720
That's why we know that since it says Dylan here, that was a result of this line.

252
00:19:56,720 --> 00:19:57,320
Fifty one.

253
00:19:58,010 --> 00:19:59,900
We can also look at the rest of our variable.

254
00:19:59,900 --> 00:20:00,770
So right now.

255
00:20:01,190 --> 00:20:06,260
We're interested in is our vector of names, which is v right?

256
00:20:06,560 --> 00:20:07,730
We've called it v right.

257
00:20:07,730 --> 00:20:09,800
Here we go down to main.

258
00:20:09,800 --> 00:20:13,010
We notice that we passed name vectors the first argument.

259
00:20:13,370 --> 00:20:16,040
So if we scroll back up here, what's the first argument?

260
00:20:16,040 --> 00:20:17,240
What's the first parameter?

261
00:20:17,720 --> 00:20:20,360
It's this one right v and it's passed by reference.

262
00:20:21,780 --> 00:20:27,750
So I'm stopped here, I can examine everything that is within the scope of this function.

263
00:20:28,890 --> 00:20:34,020
And that's all this stuff right here, so we see temp agencies tonight and we see V, this is a vector

264
00:20:34,020 --> 00:20:34,530
right here.

265
00:20:34,860 --> 00:20:40,740
If I click this little arrow, it's going to drop down more little arrows here.

266
00:20:41,040 --> 00:20:45,690
And what is actually showing us is everything that's in the vector and what position is.

267
00:20:45,910 --> 00:20:52,710
So what's position zero in the vector is Dylan was position one in the vector, it's Jeff and so on

268
00:20:52,710 --> 00:20:53,430
and so forth.

269
00:20:55,140 --> 00:20:56,400
So it's pretty cool.

270
00:20:58,060 --> 00:21:02,020
You can check out all this stuff, drop down, see what's in each thing and examine it.

271
00:21:02,560 --> 00:21:09,370
And so let's go ahead and step through our program and see how things change inside this vector.

272
00:21:10,600 --> 00:21:14,050
So this is where these buttons come into play.

273
00:21:14,230 --> 00:21:17,530
These let you move through your code in a certain way.

274
00:21:18,760 --> 00:21:21,220
This right here is step over.

275
00:21:21,520 --> 00:21:23,410
This right here is step into.

276
00:21:24,040 --> 00:21:28,870
We're interested in stepping over when we just want to move to the next line.

277
00:21:28,930 --> 00:21:33,400
So if we want to go from this line to this line, this is a comment.

278
00:21:33,460 --> 00:21:35,740
So it's not going to consider this line 50.

279
00:21:36,220 --> 00:21:41,410
If we go to the next line, it's going to go to the next line that can be executed, which is line fifty

280
00:21:41,410 --> 00:21:41,800
nine.

281
00:21:42,760 --> 00:21:44,260
So this can go from here to here.

282
00:21:44,800 --> 00:21:49,750
The step into is meant for going into a function call or something like that.

283
00:21:49,750 --> 00:21:55,480
So let's say that instead of this blue highlighted line, we'll put a breakpoint on this highlighted

284
00:21:55,480 --> 00:21:56,320
line or something.

285
00:21:58,090 --> 00:22:04,840
If I wanted to go, if I could step over when we were on this line, it would go to here.

286
00:22:05,910 --> 00:22:12,960
If I did step into which is this, it would go into the call to sort and it would bring us all the way

287
00:22:12,960 --> 00:22:15,240
up here to the sort of function.

288
00:22:17,370 --> 00:22:21,210
Right now, we want to go from here to here, we're not going into anything right.

289
00:22:21,240 --> 00:22:23,880
We don't want to go into anything here, so we're just going to go over.

290
00:22:23,880 --> 00:22:24,930
So I press over.

291
00:22:26,360 --> 00:22:31,700
And actually, it looks like it jumped us right back up to there instead of going into here.

292
00:22:31,970 --> 00:22:35,540
That's because this must have not been true.

293
00:22:36,590 --> 00:22:37,880
I sort of position.

294
00:22:38,150 --> 00:22:39,170
It's only going to jump.

295
00:22:39,530 --> 00:22:41,120
It's only you go from here to here.

296
00:22:41,300 --> 00:22:43,400
It's this evaluated to true, right?

297
00:22:43,400 --> 00:22:45,030
Otherwise it's not going to go in the wild.

298
00:22:45,180 --> 00:22:49,790
So what happens is that it goes to the end of the while loop, which is right here.

299
00:22:50,210 --> 00:22:53,210
And then you notice the for loop ends on this bracket right here.

300
00:22:53,210 --> 00:22:58,050
So it goes right back up to the top of the for loop so we can continue stepping.

301
00:22:58,070 --> 00:23:00,890
So I step here a step here, a step here.

302
00:23:02,620 --> 00:23:03,160
Let's see.

303
00:23:03,190 --> 00:23:05,110
Let's try and predict if it will step in the loop.

304
00:23:05,470 --> 00:23:11,020
What is sorted position sort of position is zero, so well sort of position is greater than or equal

305
00:23:11,020 --> 00:23:11,650
to zero.

306
00:23:11,860 --> 00:23:12,520
It's zero.

307
00:23:12,520 --> 00:23:13,900
So it's not going to go in there.

308
00:23:14,470 --> 00:23:15,760
So we go back to the top.

309
00:23:17,490 --> 00:23:21,360
Let's go back down sort of position this one that's greater than or equal to zero.

310
00:23:21,630 --> 00:23:25,320
And we sorted position is greater than insertion item.

311
00:23:25,650 --> 00:23:26,790
What is insertion item?

312
00:23:26,790 --> 00:23:27,510
It's Anna.

313
00:23:28,060 --> 00:23:28,380
Hmm.

314
00:23:29,490 --> 00:23:36,510
What is it we sort of position sort of position as one, so what's that v one?

315
00:23:36,600 --> 00:23:38,830
Well, here's v here's v one.

316
00:23:39,210 --> 00:23:39,960
It's Jeff.

317
00:23:41,960 --> 00:23:50,360
So is Jeff greater than insertion item on certain items, and that's alphabetically less than Jeff.

318
00:23:50,510 --> 00:23:52,280
So this is true, right?

319
00:23:52,850 --> 00:23:54,860
One is greater than equal to zero.

320
00:23:54,890 --> 00:23:59,680
And Anna, I'm sorry, Jeff is greater than Anna, right?

321
00:23:59,780 --> 00:24:02,570
As far as alphabetical Lexa graphical order.

322
00:24:03,230 --> 00:24:05,210
So this should go to here now.

323
00:24:06,370 --> 00:24:08,200
And it does, so it goes in the loop.

324
00:24:08,560 --> 00:24:10,210
So let's look how things change.

325
00:24:10,570 --> 00:24:16,120
We see temp name equals v Soviet position, so let's check this out.

326
00:24:18,040 --> 00:24:19,630
So a phone call right there.

327
00:24:20,350 --> 00:24:29,350
So now we are going to go ahead and step through to right here, so I'm going to go down here and see

328
00:24:29,350 --> 00:24:30,970
what happens to 10th names.

329
00:24:30,970 --> 00:24:33,430
So we see temp name is an empty string.

330
00:24:33,430 --> 00:24:36,040
But what happens when we go like this now?

331
00:24:36,040 --> 00:24:37,630
Temp name is Jeff.

332
00:24:39,140 --> 00:24:41,660
So pretty interesting as we step through here.

333
00:24:43,720 --> 00:24:49,090
So let's continue on and see how the things inside the vector change.

334
00:24:49,360 --> 00:24:54,350
So if we keep stepping over, I'm going to go ahead and drop down what's in the vector here.

335
00:24:54,430 --> 00:24:58,630
So we noticed his name became just like we were just talking about.

336
00:24:59,170 --> 00:25:03,910
So let's see what happens in the vector when we go over these line.

337
00:25:03,920 --> 00:25:05,620
60 in line 61.

338
00:25:07,010 --> 00:25:12,350
So we have sort of position equals the sort of position plus one.

339
00:25:13,410 --> 00:25:16,320
So if we check it out here, sort of position is one.

340
00:25:16,470 --> 00:25:18,630
So we're going to look at this one.

341
00:25:18,930 --> 00:25:22,170
So we have Jeff right here, right?

342
00:25:22,830 --> 00:25:29,670
And then so name because Jeff, but we're saying that now this is going to be sort of position plus

343
00:25:29,670 --> 00:25:29,970
one.

344
00:25:30,330 --> 00:25:32,910
So sorry, position plus one would be two.

345
00:25:33,120 --> 00:25:35,000
So it would be moving Anna to here.

346
00:25:35,010 --> 00:25:36,450
So let's go ahead and do that.

347
00:25:37,730 --> 00:25:43,730
So after we step over, you notice we have copy Anna from here to here, and I go ahead and I'm going

348
00:25:43,730 --> 00:25:47,150
to step over this one, we say we sort of position plus one equals temp name.

349
00:25:47,150 --> 00:25:54,170
We've stored Jeff and temp name, so we should now be having one plus one is two.

350
00:25:54,170 --> 00:25:57,890
The of two is right here and we two should become Jeff.

351
00:25:59,730 --> 00:26:01,380
And we noticed that it does.

352
00:26:02,430 --> 00:26:03,910
So this is pretty cool.

353
00:26:03,930 --> 00:26:10,110
You can use this debugger to kind of step through your code, look at values as you step through your

354
00:26:10,110 --> 00:26:15,210
code, you can do the step into when there is a function call.

355
00:26:16,230 --> 00:26:20,580
And this is actually continue or resume programs, so I can show you that as well.

356
00:26:20,590 --> 00:26:25,800
So let's say that we want to see where in our.

357
00:26:27,330 --> 00:26:33,390
Sort right here, and maybe we want to continue the program until somewhere in our binary search right

358
00:26:33,390 --> 00:26:41,040
here, so I'll say like right here this, if you like that, it's right there.

359
00:26:41,310 --> 00:26:42,360
So you notice that.

360
00:26:43,960 --> 00:26:52,840
After this sort here, so I'll go ahead and take this break point away down here is where we're actually

361
00:26:52,840 --> 00:26:54,730
calling binary search, right?

362
00:26:55,120 --> 00:26:56,290
You were in sort.

363
00:26:56,390 --> 00:26:58,270
So this initial function call to sort.

364
00:26:59,760 --> 00:27:02,490
So I actually what I could do is.

365
00:27:05,120 --> 00:27:10,250
I could put a breakpoint right here and then I could actually show how we can step into how about that?

366
00:27:10,760 --> 00:27:16,360
So I'll go ahead and remove this breakpoint, but I'm going to we're right here on this line right now,

367
00:27:16,370 --> 00:27:21,200
and what I'm doing is I'm putting in breakpoint right here because what we did was we hit this sort

368
00:27:21,200 --> 00:27:25,910
online 94, and that jumped us up into this sort of function where we were sorting everything.

369
00:27:26,750 --> 00:27:31,160
So now we're going to go past this line 94 and to here.

370
00:27:31,160 --> 00:27:34,400
So when I do continue, it'll keep running the program.

371
00:27:34,670 --> 00:27:39,380
So it's actually this called resume program, so it'll resume the program and keep running until it

372
00:27:39,380 --> 00:27:41,360
hits the next breakpoint that we've set.

373
00:27:42,050 --> 00:27:43,640
So I'm going to go ahead and do that.

374
00:27:45,810 --> 00:27:50,700
And actually, you notice it doesn't necessarily necessarily hit this right away, because first, it

375
00:27:50,700 --> 00:27:56,940
needs to get this 998 seat inquiry, so you notice that this little arrow came up in the console here.

376
00:27:57,540 --> 00:28:01,560
So that means we need to jump over to the console and we need to type some name to be searched.

377
00:28:01,620 --> 00:28:02,750
I was going to say Anna.

378
00:28:03,060 --> 00:28:09,900
And now, once I press enter, it should go past this user input line for scene and go to here and stop

379
00:28:09,900 --> 00:28:10,200
here.

380
00:28:11,570 --> 00:28:16,730
So I do that, and we notice now that we are down here at ninety nine.

381
00:28:19,420 --> 00:28:23,350
So let's go back to the debugger, we see that little line in the debugger.

382
00:28:23,620 --> 00:28:26,830
So now what I can do is I could.

383
00:28:29,320 --> 00:28:33,860
Step over a couple times.

384
00:28:33,910 --> 00:28:41,700
So until I get to this binary search, so I step over if query equals quit, well, what is query queries

385
00:28:41,710 --> 00:28:43,030
and it's not equal to quiz.

386
00:28:43,030 --> 00:28:45,730
So let's jump over this and go here to one of three.

387
00:28:46,800 --> 00:28:52,290
Now we're on binary search on one, two, three, so now what we can do is use the step into command

388
00:28:52,650 --> 00:28:53,860
rather than step over.

389
00:28:53,880 --> 00:28:59,130
So instead of going to the next line, we're going to jump into the function call and.

390
00:29:00,360 --> 00:29:03,930
That is going to bring us up here to a binary search.

391
00:29:05,870 --> 00:29:07,190
So let's go ahead and do that.

392
00:29:08,060 --> 00:29:13,310
So step into and it takes us to the first line inside the binary search function, and now we can step

393
00:29:13,310 --> 00:29:15,470
through the binary search function.

394
00:29:15,860 --> 00:29:21,680
We can continue, you know, I can put a breakpoint here on this list if in press continue and now it

395
00:29:21,680 --> 00:29:25,360
would continue and tell this line got executed right here.

396
00:29:27,310 --> 00:29:35,860
OK, so I think that that's probably enough to cover the basics of going through this debugger is really

397
00:29:35,860 --> 00:29:44,440
powerful debugger here and sea lion, it's it's great this visual kind of the ability to drop down these

398
00:29:44,440 --> 00:29:46,900
little things and examine everything.

399
00:29:47,920 --> 00:29:49,450
It's just so, so good.

400
00:29:50,470 --> 00:29:58,390
You can also set like watch points and things, and they have this memory of you.

401
00:29:58,390 --> 00:30:01,180
GDB is something that we're going to talk about next.

402
00:30:01,180 --> 00:30:07,120
You can use TDB in here, but I'm going to show you how to use it in the terminal, but there's a lot

403
00:30:07,120 --> 00:30:08,500
of other stuff you can do.

404
00:30:08,530 --> 00:30:13,810
I'm not going to go over everything for this, but I just wanted to kind of point out to you, there's

405
00:30:13,810 --> 00:30:17,200
things so you can, like I said, you can set.

406
00:30:20,100 --> 00:30:26,730
New watch like, oh, you can watch a variable and it will kind of keep it up at the top for you and

407
00:30:26,730 --> 00:30:31,080
show you how that variable changes, you won't have to like, drop down and examine it.

408
00:30:32,490 --> 00:30:38,160
You know, if you went into another function or something like that or it was a global variable, you

409
00:30:38,160 --> 00:30:42,380
know, it can show you how it changes across the program as you're moving around, you know, or I'm

410
00:30:42,390 --> 00:30:46,470
like, Yeah, so you can experiment with that setting watch points.

411
00:30:46,920 --> 00:30:52,050
I think I would not like to tell you too much more about it because I think it's really important for

412
00:30:53,580 --> 00:31:01,860
people to learn how to go online and look at documentation on how to use debunkers and just documentation

413
00:31:01,860 --> 00:31:02,430
in general.

414
00:31:03,030 --> 00:31:09,900
So if you like to know more about it, you should go online and try and find documentation from jet

415
00:31:09,900 --> 00:31:18,360
brains, the people that make it seem like and try and find the specific documentation for the sea lion

416
00:31:18,360 --> 00:31:20,170
debugger so you can look at that.

417
00:31:20,190 --> 00:31:21,890
There's also, you know, tutorials and things.

418
00:31:21,900 --> 00:31:24,780
It's really good to be able to find some stuff on your own online.

419
00:31:25,320 --> 00:31:26,660
Can't just get it.

420
00:31:26,880 --> 00:31:27,690
Have it all given to you.

421
00:31:27,720 --> 00:31:31,760
So with that, I'm going to bail out of this.

422
00:31:31,780 --> 00:31:37,560
Well, actually, I'll stop this right now, and then I'm going to head over to the terminal to show

423
00:31:37,560 --> 00:31:38,230
you GDB.

424
00:31:38,230 --> 00:31:40,530
You notice there is something called GDB here.

425
00:31:40,890 --> 00:31:43,380
GDB steps for a new debugger.

426
00:31:44,550 --> 00:31:52,740
So it's kind of related to like mini GW, you know, that kind of had to do with the new compiler collection

427
00:31:52,740 --> 00:31:56,970
for Windows minimum compiler collection for Windows.

428
00:31:57,000 --> 00:31:59,190
This is going to be the new debugger.

429
00:31:59,790 --> 00:32:04,860
So as although it's available here and sea lion, I would like to show you how to use it in the terminal

430
00:32:04,860 --> 00:32:10,050
because the main point is you've seen the sea lion debugger in here and how powerful it is.

431
00:32:10,710 --> 00:32:12,870
But maybe you don't have sea lion.

432
00:32:12,870 --> 00:32:19,620
Maybe you don't have access to sea lion, and maybe you're just using them in the terminal and or you're

433
00:32:19,620 --> 00:32:26,220
using GPS code, which I know you can set up a debugger for s code as well, but I'd like to show you

434
00:32:26,220 --> 00:32:27,390
the GDB debugger.
