开发者

How to find where a library call returns?

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 ~ 10klines 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 break开发者_如何学运维points on all of them. But is there any other way?


Run gdb, type help next or help nexti and you can see the description of the next 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 example next 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 time next 500 and you were out of the function, you start over and this time start with next 750. You get the idea.

Edit 1: Use step instead of next 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), type reverse-step and go backwards in the execution to see where the function had exited! (How cool is that?!)


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜