Hello, my name is Typhoon.
And in this section we'll do program analysis with a debugger which is a GDB.
So in this section we will introduce debugging and assemble a program.
So debugging is an important skill because with a debugger you can investigate the content of registers
and memory in hexadecimal, binary or decimal representation.
You already know from the previous lectures that the CPU is intensively using registers and memory and
debugger allows you to execute the instructions step by step while looking at how the content of registers,
memory and flag changes.
So maybe you have experienced already your first assembly program crashing upon the execution with an
unfriendly message such as the memory segmentation fault.
So with the debugger, you can step through your program and find out exactly where and why things went
wrong.
So once you have assembled and linked your Helloworld program, remember we did that in previous lecture.
Let's.
Boom family here and here we have Hello program.
If we try to run this, we will see the Hello world message and we can also see the mouse pad.
hello.sm So we can also see this the code.
So it's a 15 line assembly program so we don't save this for now clear at our hello.
So if we cut this, as you can see here, we are getting some weird output.
So that's why we will debug this compiled program.
So let's see, here we have.
Hello.
We also have Makefile.
Remember we did compile this.
Program twice with make file and without make file here.
So you already know how to compile this.
And as I said, once you have assembled and linked your Hello World program without errors, you obtain
this executable file.
So with the debugger tool, you can load an executable program into the computer's memory and execute
it line by line while examining various registers and memory places.
So there are several free and commercial debuggers available in Linux.
The mother of all debuggers is GDB.
It is a command line program with very cryptic commands.
So this is a much fun and in future sections we will use a tool with a graphical user interface that
is based on GDB.
But having a basic knowledge of GDB itself can be useful because not all gdb functionality is available
in CSM and in your further career as an assembler programmer or reverse engineer, you will certainly
look at various debuggers with a nice user interfaces and targeted at a specific platform such as Windows,
Mac or Linux.
So these graphical user interface debuggers will help you debug long and complex programs with much
more ease as compared to this CLI.
So the command line interface debugger.
So but the GDB is a comprehensive and quick and dirty way to the Linux debugging and GDB is installed
on most Linux development systems as you can see it, and if not it can easily be installed.
It can easily be installed here.
Uh, for troubleshooting without much overhead on the for the system.
So here we will now quit, uh, from the, uh, debugger here so you can quit with Ctrl X and we will
use GDB for now to give you some essential and uh, turn the other tools in uh, later sections.
And uh, one more note.
So GDB seems to be developed for debugging higher level languages, so some features will not be of
any help when debugging in assembly and debugging of program with a CLI.
So the command line interface debugger can be overwhelming at the first time.
So do not despair when reading this.
Um, the outputs.
Uh, this program will give us.
Oops, my mouse actually glitched a little bit, so let's actually.
Open it again.
Perfect.
And here.
So as I said, don't be scared when you are reading this octopus, because it is it was scary to me
at once.
And here, let's actually, as you as you can see here, uh, the GDB is already installed on our system,
but you can also install sudo apt get install gdb here.
And.
GDP.
And as you can see, it's already installed.
So it actually comes pre-installed in most systems, both Linux Windows or Mac OS because it is needed
tool for system and GDB here we will.
Now as you can see we have a hello program so we will write the GDB.
BdB.
Hello.
And as you can see here, this is our Halo program.
So with this command gdb will load the executable alone into memory and answer with its own prompt which
is as you can see it's a gdb prompt.
So gdb will show a number of lines for your code.
And so if we type the list here and as you can see here, um, if you type this list gdb will show the
next lines and so on.
So to list a specific line, for example, the start of your code is.
Um, the list one here, the last one you will get the also the same output because the list one actually
it's actually use the list two.
And as you can see here, we are getting two different outputs here and here.
This is the output here.
So if the output on your screen is different from, uh, the, your screen containing the lots of this
ampersand signs, then your GDB is configured to use the AT&T system syntax flavor.
So we will use the Intel syntax flavor.
So which is more intuitive to us.
Um, so we will show how to change the flavor in a minute.
But um, if you run, uh, if you type this run here.
As you can see here, starting program read debugging using using hold here and hello world and interfere
one process for 840 exited normally and the gdb will run your with this command here.
If you run the ip test run in your gdb prompt uh gdb will run hello program printing the hello world
and return return to its prompt again and to quit the gdb type quit here.
That's it.
And now let's do some interesting stuff with gdb.
But uh, first we will.
In this lecture we will change the disassembler flavor.
And to do this only you had this uh, sign, this ampersand sign when you typed list in previous exercise.
So if you get that, uh, got that error.
You need to write this.
We will load the executable hello into gdb if it's not already there.
So we will use set this assembly flavor Intel.
So here.
As you can see here.
It's actually.
Hello.
And so you will you will need to write this in.
Flavor Intel.
And you will need to write this both here and here.
So this will part the disassembled code in a format that is already familiar so you can make Intel the
default flavor for GDB by using the appropriate setting in your Linux shell profile.
So you can see the documentation of your Linux distribution in Ubuntu 18.0 and want to get the Debian
here.
GDB init file in your home directory containing the previous set instructions.
So log out and log in and you should be using gdb with the Intel flavor from now on.
And now here in next lecture we will also disassemble main to begin our analysis.
So I'm waiting you in next lecture.