Need help using gdb with my C program

I am learning assembly language. I use gdb to find out how to get information from the written C code. Am I trying to see the break register at the beginning of each line and see how many bytes of machine code are in each of the C statements in this program? Can someone show me the commands in gdb to find them?

#include <stdio.h> int main(void) { register int wye; int *ptr; int ex; ptr = &ex; ex = 305441741; wye = -1; printf("Enter an integer: "); scanf("%i", ptr); wye += *ptr; printf("The result is %i\n", wye); return 0; } 
+4
source share
1 answer

A short example of what you can do to see some things about your program. $ is a shell prompt, and gdb> is a gdb prompt, so don't type those:

 $ gdb myprogram ... info about gdb and myprogram gdb> disas main ... disassembly of the main function gdb> break main ... sets a breakpoint in main; you see a message about this probably calling it breakpoint 1 gdb> run ... program starts and stops immediately at the start of main gdb> ir ... lots of info about register contents gdb> p $rip ... current instruction pointer (assuming x86_64) gdb> s ... program runs for one source line. gdb> p $rip ... ip has advanced a bit. 
+1
source

Source: https://habr.com/ru/post/1440421/


All Articles