
On 01/09/13 11:28, James Harper wrote:
Is there any way I can do a reasonableness test on the stack from C/C++? At a minimum I think all I would need to do is get the return address and check that is within a certain range and not null's etc.
You can make use of backtrace directly inside the program (http://linux.die.net/man/3/backtrace), producing a set of return addresses from the stack frames, which you can then sanity check (no need to convert to symbols). Note that when there is optimization (particularly if frame pointers are left out), stack frames aren't always as easy to interpret, so it often helps to try to reproduce the problem with optimization turned off if possible. It would also be interesting to turn on the gcc stack protection (-fstack-protector-all), if you think for example that the problem is being caused by a buffer overflow. This won't tell you where the problem is, but it might at least abort more gracefully closer to the point where the failure is occurring. Glenn -- sks-keyservers.net 0x6d656d65