installationBrew Install GDBsingle-step and trace function calls
/* MAIN.C--Learn gdb Debug tool */
#include <stdio.h>intAdd_range (intLowintHigh ) { inti, sum; for(i = low, I <= high; i++) Sum= Sum +i; returnsum;}intMainvoid){ intresult[ -]; result[0] = Add_range (1,Ten); result[1] = Add_range (1, -); printf ("result[0]=%d\nresult[1]=%d\n", result[0], result[1]); return 0;}
First step: Generate the target file using-G
Gcc-g Main.c-o Main
? ch02 gdb file nogood.c
GNU gdb (GDB) 8.0.1
Copyright (C) Free Software Foundation, Inc.
License gplv3+: GNU GPL version 3 or later
This was free software:you was free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law. Type "Show copying"
and "Show warranty" for details.
This GDB is configured as "x86_64-apple-darwin16.7.0".
Type "Show Configuration" for configuration details.
For bugs reporting instructions, please see:
Find the GDB manual and other documentation resources online at:
For help, type ' help '.
Type "Apropos word" to search for commands related to "word" ...
"/usr/bin/file": Executable format:file format not recognized
"/USERS/DAVID/DESKTOP/C-PRIMER-PLUS-SOURCE-CODE/CH02/NOGOOD.C" is not a core dump:file format not recognized
(GDB)
C Basics-GDB Mode tool