Let's Talk About C/Assembly things (gdb)

2024/3/5

One of the good way of learning the C or Assembly programming languageIs to using debugger while you are trying to understand the concept ofThat thing. For example if you are trying to understand what exactly isArray in C programming language, you can do it by using GDB (Gnome Debugger).That debugger will exactly shows you, how C manage the array in assembly languageAs long as we know that the C programming language create a suitable Assembly code (Maybe Better than human minds, who knows ^^). The main reason of that is that youHave the main address of memory in your hands, address of variables, functions, arraysAnd good ones, registers.That's it's so important to use debugger for learning. Debugger is so much important forEverything, I know we all used to use `print` fucions for debugging things, but what if youWant to access the address? hmmm seems like now we all know why debugger is so great.

You can start using GDB by learning some base things like `lay` command that isfor layouting your screen, in some cases split your screenTry run the following command:
(gdb) lay next
This code will split your screen in 2 sections:
  • the Source Code section: It's where you see your source code (if you compile your code with -g flag, you can see your C source code too)
  • the GDB command line section: This is where your gonna run your gdb command like break point
Try to press enter to change the source between C and AssemblyNow it's a good time to make a break point on your `main` C function.If you wanna trace all functions start from your program entry point(default main) the best way of doing that is following:
(gdb) break main
By using this command, you set a break point on main that when you run the programwith `run` command, it waits until you doing something like run the next instruction (asm)