如何找到库调用返回的位置?
我正在分析一个相当庞大的外部 FORTRAN 库。无论如何,该库的重点是适合我提供的函数的参数值。入口点是一个带有大量参数的方法调用。
问题是,有时调用返回得很快,并且它吐出的参数值也可能来自随机数生成器。问题是:gdb(或其他调试器)是否有任何方法可以查看库方法的返回值被调用的位置?我确实有源代码并且已经用 -g
编译了它们。顺便说一句,我使用 g++
和 gfortran
进行编译。我无法手动浏览源代码或逐行执行它,因为整个代码大约有 10k 行混乱的代码。
我想到的一个想法是浏览源代码并找到所有可能的返回并在所有返回上设置断点。但还有其他办法吗?
I am analyzing an external FORTRAN library which is quite huge. Anyways, the whole point of the library is to fit parameters values for a function I supply. The entry point is one method call with godzillion parameters.
The problem is, sometimes the call returns quite quickly, and the parameters values it spits out may as well have come from a random number generator. The question is: Is there any way in gdb (or some other debugger) to see where the return from the library method was called? I do have the sources and have already compiled them with -g
. Btw, I use g++
and gfortran
for compilation. I can't go through the sources manually or execute it line by line, since the whole code is ~ 10k
lines of messy code.
One idea that came to my mind is to go through the source code and find all possible returns and set up breakpoints on all of them. But is there any other way?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
运行 gdb,输入
help next
或help nexti
,您可以看到next
命令的描述,该命令基本上在您的程序中向前推进。您可以做的是,在函数的开头设置一个断点,然后从那里逐步运行程序(使用
next
)并查看它从函数的哪里出去。如果程序很大,可以对返回点进行二分查找。即在函数的开头设置一个断点,然后从那里键入例如
next 500
。如果您退出该函数,则说明您走了太多步,因此请重新开始,下次迈出较小的一步,例如next 250
。如果您仍在函数中,您可以进一步执行并总结您的步骤,以了解您走了多远。因此,如果您再次说下一个 500
并且您超出了该功能,则您可以重新开始,这次从下一个 750
开始。你明白了。编辑 1:使用
step
而不是next
进入函数内部。编辑2:试试这个看看它是否有效:
在函数的开头放置一个中断并进入它的内部。然后(当然是在 gdb 中)输入
finish
运行,直到函数完成。然后(这是我不确定它是否能正常工作的部分),输入reverse-step
并在执行中向后查看函数退出的位置! (那有多酷?!)Run gdb, type
help next
orhelp nexti
and you can see the description of thenext
command which basically steps forward in your program.What you can do is, set a breakpoint in the beginning of the function, and then from there, run the program step by step (using
next
) and see where it goes out of the function.If the program is huge, you can binary search the return point. That is set a breakpoint in the beginning of the function and then from there type for example
next 500
. If you came out of the function, you stepped too many so start over and next time make a smaller step, for examplenext 250
. If you were still in the function, you could step more and sum up your steps to know how far you went. So if you say another timenext 500
and you were out of the function, you start over and this time start withnext 750
. You get the idea.Edit 1: Use
step
instead ofnext
to go inside functions.Edit 2: Try this see if it works:
Put a break in the beginning of the function and go inside it. Then (in gdb of course) type
finish
to run until function is finished. Then (this is the part I'm not sure if it would work correctly), typereverse-step
and go backwards in the execution to see where the function had exited! (How cool is that?!)您是否添加了 -g3 -gdwarf-2 标志?他们可能会提供用于调试的附加信息。
然后您可以单步执行程序的每一行,但我不知道它是否可以开箱即用地用于库
Have you added the -g3 -gdwarf-2 flags ? They may provide additional info for debugging.
Then you can step into each line of the program, but I don't know if it will work out of the box for a library