最近在使用GDB调试的时候出现了一个奇怪的问题,我使用C实现了一个线程池,但是运行的时候segment fault了,很自然的我使用了GDB去调试它,然而奇怪的地方了来了:
上述代码是没有问题的,然而当我使用gdb进行单步调试的时候,出现了如下错误:
gdb无法进入malloc内部执行??
一番百度无果,只能求助stackfoverflow爸爸:果然,让我找到了下面这个答案:
Call to malloc failing in gdb session
其中是这么说的:
You can safely ignore this. gdb is complaining that it doesn’t have the source for malloc – and it’s almost certain you don’t want to step through the source.
Two easy solutions:
Use next instead of step – it won’t descend into functions
If you’ve accidentally steped into a function already, use finish to run to the return statement of the function.
And an alternative approach:
You could also break a bit before the segfault, rather than stepping through the whole code.
- 原因是gdb是没有malloc的代码的,自然我们也就无法进入malloc执行,解决办法就是使用next而不是step,这样就可避免进入函数内部了,推想,除了malloc之外,应该还有其他一些函数是无法在gdb中进行单步调试的,看来还是我使用GDB太少了,惭愧。