码迷,mamicode.com
首页 > 数据库 > 详细

C基础 - GDB调式工具

时间:2017-09-10 20:48:51      阅读:270      评论:0      收藏:0      [点我收藏+]

标签:prime   ant   conf   std   resource   perm   pos   sum   prim   

 

安装

brew install gdb 

 

一、单步执行和跟踪函数调用

/* main.c -- 学习gdb调试工具 */
#include <stdio.h> int add_range(int low, int high) { int i, sum; for (i = low; i <= high; i++) sum = sum + i; return sum; } int main(void) { int result[100]; result[0] = add_range(1, 10); result[1] = add_range(1, 100); printf("result[0]=%d\nresult[1]=%d\n", result[0], result[1]); return 0; }

 

 

第一步:使用-g生成目标文件

gcc -g main.c -o main

 

 

?  ch02 gdb file nogood.c 

GNU gdb (GDB) 8.0.1

Copyright (C) 2017 Free Software Foundation, Inc.

License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>

This is free software: you are 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 was configured as "x86_64-apple-darwin16.7.0".

Type "show configuration" for configuration details.

For bug reporting instructions, please see:

<http://www.gnu.org/software/gdb/bugs/>.

Find the GDB manual and other documentation resources online at:

<http://www.gnu.org/software/gdb/documentation/>.

For help, type "help".

Type "apropos word" to search for commands related to "word"...

"/usr/bin/file": not in 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基础 - GDB调式工具

标签:prime   ant   conf   std   resource   perm   pos   sum   prim   

原文地址:http://www.cnblogs.com/elewei/p/5996052.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!