Hello, my name is Tayfun.
And in this lecture we will step through the program with the debugger.
Now, as we did in previous lecture, we will look at our program again.
So actually, let's run it our Hello program that we will assemble a program, assembler language.
And here this is our source code for it.
So we will gdb hello again and that's it.
So here what we're going to do is we will firstly.
It.
We will we will put a break in the program, which is pausing the execution and allowing us to examine
a number of things.
So here we will do break main.
So here, as you can see here, it gave us output a breakpoint at, uh, 40 1110 file.
Hello.
And in line eight.
And now in our case, this is the output here.
So.
But this memory numbers will be different at your PC.
And now what we're going to do is we will run the program now run.
And as you can see here, we also have the breakpoint here.
So the debugger stops at the break and throws the next instruction that will be executed.
So that is, uh, move here, move rax one is not executed yet.
And now we will type this info registers here.
And as you can see, we this is the gdb returns the output here.
So.
The content of these registers is not that important now, except for this recipe.
Here we will, as you can see here, our IP.
So the instructor instruction pointer.
So the register our IP has the value of 40 1110, which is the memory address of the next instructions
to execute.
So remember, we put the breakpoint at the four 1110, and this is the same address for 11 1040 1110,
same address.
Right.
So here, this points to the first instruction.
And we also have mov rax one gdb.
Let's actually put this somewhere move rax one gdb here.
This stops and gdb stops just before the instructions and waits for your command.
And it is not important.
And it's sorry.
It's important to remember that the instruction pointed to by RIP here.
This rip is not executed.
Not yet executed here.
So in your case gdb may show something different from the 40 1110 that and that's okay.
It is the address of that particular line in memory and which may be different depending on depending
on your computer configuration.
But in most cases it will be different than this.
And now we will type the step.
Yep.
And as you can see here, we have this here now, which is the now we will also.
Type I and are here.
So this is the abbreviation for info registers.
As you can see here I if stands for EHR info and r for registers.
And after that we will get this output here.
Now indeed Rax contains now zero here, 00X1 here actually.
And here.
0X11.
And and the rip here.
The rip here contains the address of the next instruction to execute.
So we can also step further through the program and notice that how RSI receives the address of message.
A message which prints the Hello World on the screen and exits.
And notice also how Rip Rip points every time to the next instruction to execute.
And here we also I want to discuss here is also some additional GDB commands here which is the break
here or b sets a break point as we have done before in this lecture.
So for example, we can also disable this uh, break point here.
So disable break point.
Uh, break.
Point.
And after that, you will enter the number in this case, actually.
As you can see, this is the main is not the breakpoint number here.
But also we also can, after disabling it, enable the break point again.
Like this.
And we also have the continue.
Or see this is the continue the execution until the next breakpoint.
As you can see here, we don't have we don't have breakpoints except that main breakpoint here with.
And that's why our program exited normally.
So our program done executed.
And we also have the next we have this is to step over the current line and stop at the next line.
So we also have help.
This shows the help here, help or age.
So.
As you can see here.
And we also have to enable this is enables the text user interface and to disable it, you can simply
write why disable and we can also which you learned in previous lecture actually um, print and also
print the value of a variable registers and so on.
So now let's actually see some examples here.
Uh, now we will print, uh, p.
Racks.
Racks here.
And as you can see, there is a no registers because our program is already done executing.
Now we will.
Let's actually start this again.
Clear the screen and gdb.
Hello.
And as you can see here, we started our, uh, debugging process from zero again.
And now what we're going to do is we will start.
We must set a break point.
Break.
Break main.
And we can also enable or disable the break point as we did in previous.
As you learned in here.
In order to.
Run it.
So we will disable, as you can see here, when we set the break main here, we are getting this one
number here so we can use it to disable break point.
And after that we will set the number one.
And as you can see, it's disabled and we can also delete the break point.
So we disabled it but didn't delete it.
So after that we can also enable a break point.
So but if you deleted it, you need to define a Neve break Neve break here enable break point.
And as you can see here, we also have the break point here enabled.
And now we will delete the break point here.
And after that you will enter the number and this is the list.
So now if we enable this break point right now, enable break point one, we will get an error because
the no break point number one.
So now we will add our break point again.
And after that we will run here or run our main program.
And we will also use the info registers here that we did here.
And as you can see, that's so this line is not executed.
And now we will also get the info registers, info registers here and now.
We will use this print function here.
Now p here and this dollar sign rax and as you can see, we have this.
And.
P message here.
As you can see, it's void because there's no message here, which the message is not stored.
Variable type stored in the memory.
So we need to get that memory address to print it out.
In this case here.
Of which we learned that in previous lecture.
We did some examples to print the Hello world message using the GDB.
And one important remark about the GDP is to properly use it, you must insert a function prologue and
the function epilogue in your code.
So I will show in the next sections how to do that.
And in later sections we will discuss function, prologue and function epilogues when we talk about
stack frames.
So for short information, for short programs such as our Hello World program, there is no problem.
But with longer and bigger and fancy programs, GDB will show an expected behavior if there is no prologue
or epilogue.
So play around with gdb refer to the online manual for example.
You can also type the man gdb here man.
EDB.
So here.
And in this case, I didn't get it any.
So it's okay.
But you can also find or find a lot of online manuals and get familiar with GDB because even when you
use a graphical user interface debugger, some functionality may not be available or may not want to
install the graphical user interface debugger on your system because GDB does all the job at 10 or 10
out of ten.
And now in the next lecture we will also create some assembly code, a slightly improved version of
Hello World.
So I'm meeting you in next lecture.