ch1-debug
Chapter_1 make | Chapter_2 |
debug.txt ALP, p. 23-24
make CFLAGS=-g
gcc -g -I ./include -c ./src/main.c
g++ -g -I ./include -c ./src/reciprocal.cpp
g++ -g main.o reciprocal.o -o reciprocal
gdb reciprocal
(gdb) run 0
// reciprocal: ./src/reciprocal.cpp:7: double reciprocal(int):
// Assertion `i != 0' failed.
// Program received signal SIGABRT, Aborted.
(gdb) where
#0 ...
#1 ...
#2 assertion=... "i != 0",
file=... "./src/reciprocal.cpp", line=7,
#3 function=... "double reciprocal(int)")
#4 in reciprocal (i=0) at ./src/reciprocal.cpp:7
#5 in main (argc=2, argv=...) at ./src/main.c:17
(gdb) up
#1 ...
(gdb) up 3
#4 ...
(gdb) print i
// $1 = 0
(gdb) down
#3 ...
(gdb) down 2
#1 ...
(gdb) next
// Program terminated with signal SIGABRT, Aborted.
// The program no longer exists.
(gdb) break main
// Breakpoint 1, main (argc=..., argv=...) at ./src/main.c:6
(gdb) break reciprocal
// Breakpoint 2 at ...: file ./src/reciprocal.cpp, line 5.
(gdb) run 0
// Breakpoint 1, main
(gdb) next
// if (argc != 2)
(gdb) next
// i = atoi (argv[1]);
(gdb) next
// printf ("The reciprocal of %d is %g\n", i, reciprocal (i));
(gdb) step
// Breakpoint 2, reciprocal
(gdb) step
// assert (i != 0);
(gdb) step
// __GI___assert_fail (assertion=... "i != 0",
// file=... "./src/reciprocal.cpp", line=7,
// function=... "double reciprocal(int)")
(gdb) next
// reciprocal: ./src/reciprocal.cpp:7: double reciprocal(int):
// Assertion `i != 0' failed.
// Program received signal SIGABRT, Aborted.
(gdb) next
// Program terminated with signal SIGABRT, Aborted.
// The program no longer exists.
(gdb) next
// The program is not being run.
(gdb) q // quit debugger
make clean
rm *.o
Chapter_1 make | BACK_TO_TOP | Chapter_2 |
Comments
Post a Comment