Cfi Directives
.cfi GNU Assembler Directives
In Chapter 10, our first look at the assembly language generated by gcc
included a lot of assembly directives that start with .cfi
. I showed you the gcc
command line options to eliminate these directives from the code so we could focus on the machine instructions. In case you’re curious, let’s look here at how these directives are used by the gdb
debugger.
x86-64 Architecture
(gdb) l factorial
1 /* factorial.c
2 */
3 #include "factorial.h"
4
5 unsigned int factorial(unsigned int n)
6 {
7 unsigned int current = 1; /* assume base case */
8 if (n != 0)
9 current = n * factorial(n - 1);
10 return current;
(gdb) b 9
Breakpoint 1 at 0x11a5: file factorial.c, line 9.
(gdb) r
Starting program: /home/bob/GitHub/itco_x86-64/build/chapter_15/Text_Listings/factorial_C/threeFactorial
Breakpoint 1, factorial (n=10) at factorial.c:9
9 current = n * factorial(n - 1);
(gdb) c
Continuing.
Breakpoint 1, factorial (n=9) at factorial.c:9
9 current = n * factorial(n - 1);
(gdb)
Continuing.
Breakpoint 1, factorial (n=8) at factorial.c:9
9 current = n * factorial(n - 1);
(gdb)
Continuing.
Breakpoint 1, factorial (n=7) at factorial.c:9
9 current = n * factorial(n - 1);
(gdb)
Continuing.
Breakpoint 1, factorial (n=6) at factorial.c:9
9 current = n * factorial(n - 1);
(gdb)
Continuing.
Breakpoint 1, factorial (n=5) at factorial.c:9
9 current = n * factorial(n - 1);
(gdb)
Continuing.
Breakpoint 1, factorial (n=4) at factorial.c:9
9 current = n * factorial(n - 1);
(gdb)
Continuing.
Breakpoint 1, factorial (n=3) at factorial.c:9
9 current = n * factorial(n - 1);
(gdb)
Continuing.
Breakpoint 1, factorial (n=2) at factorial.c:9
9 current = n * factorial(n - 1);
(gdb)
Continuing.
Breakpoint 1, factorial (n=1) at factorial.c:9
9 current = n * factorial(n - 1);
(gdb) bt
#0 factorial (n=1) at factorial.c:9
#1 0x00005555555551b2 in factorial (n=2) at factorial.c:9
#2 0x00005555555551b2 in factorial (n=3) at factorial.c:9
#3 0x00005555555551b2 in factorial (n=4) at factorial.c:9
#4 0x00005555555551b2 in factorial (n=5) at factorial.c:9
#5 0x00005555555551b2 in factorial (n=6) at factorial.c:9
#6 0x00005555555551b2 in factorial (n=7) at factorial.c:9
#7 0x00005555555551b2 in factorial (n=8) at factorial.c:9
#8 0x00005555555551b2 in factorial (n=9) at factorial.c:9
#9 0x00005555555551b2 in factorial (n=10) at factorial.c:9
#10 0x0000555555555166 in main () at threeFactorial.c:11
(gdb)