/*********************************************************************
* Author : Samson
* Date : 01/30/2015
* Test platform:
* 3.13.0-24-generic
* GNU bash, 4.3.11(1)-release
* *******************************************************************/
很多时候,发行版的程序在编译的时候都是没有加上-g这个选项的,那么若是想调试一个程序,应该怎么办呢?
在加了-g选项时,是可以通过行号、函数名等进行断点的设置的,但是没有符号表的情况下,那么怎么来进行程序的断点的设置并进行调试呢?
这就要用到反汇编然后再对地址进行断点的设置来进行调试,具体情况可参看以下例子的过程:
test.c代码如下:
#include
#include
int main()
{
int m = 0, n =9;
int k = m+n;
printf("k is %d\n", k);
m = k + n;
printf("m is %d\n", m);
n = m-n;
printf("n is %d\n", n);
return 0;
}
使用不带-g参数的编译命令行进行编译:
linuxidc@linuxidc:~$ gcc test.c
使用gdb进行程序的调试:
linuxidc@linuxidc:~$ gdb a.out
GNU gdb (GDB) 7.5.91.20130417-cvs-Ubuntu
Copyright (C) 2013 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later
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 warrant