UNIX> -g -o fibb fibb.c UNIX> ./fibb < inpt
UNIX> gdb fibbThis only starts the debugger; it does not start running the program in the debugger.
(gdb) b 10"b" is short for breakpoint.
(gdb) run < inpt Starting program: /home/gtowell/Public246/Lab1104/fibb < inpt What number fib number do you want (0 to quit)8 Breakpoint 1, dofibb (n=8) at fibb.c:10 10 int t = f + s;Note that the program execution stopped at our first (and only) breakpoint.
display i display tDisplay is distinct from its relative print. Display shows the value of a variable after every step. Print shows the value of a variable at the time it is executed.
(gdb) display i 1: i = 0 (gdb) display t 2: t = 1821770359 (gdb) s 11 f=s; 1: i = 0 2: t = 0 (gdb) s 12 s=t; 1: i = 0 2: t = 0 (gdb) s 8 for (int i=0; i<n-2; i) 1: i = 0 (gdb) s Breakpoint 1, dofibb (n=8) at fibb.c:10 10 int t = f + s; 1: i = 0 2: t = 0 (gdb) s 11 f=s; 1: i = 0 2: t = 0 (gdb) s 12 s=t; 1: i = 0 2: t = 0 (gdb) s 8 for (int i=0; i<n-2; i) 1: i = 0
run < inpt
This program causes a core dump due to a segmentation fault. We will try to trace the reason for this core dump.
gcc segg.c -g -o segg
Segmentation fault (core dumped)
coredumpctl gdb seggThe output of the above command should look like this:
A whole lot fo stuff ending with Core was generated by `segg'. Program terminated with signal SIGSEGV, Segmentation fault. #0 main () at segg.c:10 10 temp[3]='F';
char *temp = "Paras";We find that temp is a char* which has been assigned a string literal and so we cannot modify the contents of the literal as on line 10. This is what is causing a core dump
int a[n] for i from 0 to n a[i]=i for i from 0 to n-2 j = random in range i <= j < n exchange a[i] with a[j]