C基础 - GDB调式工具

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了C基础 - GDB调式工具相关的知识,希望对你有一定的参考价值。

 

安装

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调式工具的主要内容,如果未能解决你的问题,请参考以下文章

gdb调试工具

Linux基础常用开发工具——gdb调试器

性能分析之 GDB 动态修改内存变量值(C/C++)

性能分析之 GDB 动态修改内存变量值(C/C++)

使用GNU/gdb调试Linux C/C++可执行程序查看出错源代码、设置断点

基于c语言中调试工具的用法汇总(不包含gdb)