简体   繁体   中英

How to debug code that seg faults at load time?

I have a fairly complex C++ code that generates a segmentation fault as soon as it loads. The first statement in main() never gets executed. I think the problem lies in a static library libWhatever.a because the segmentation fault only occurs if I try to instantiate an object from that library. How would a smart person debug this problem?

EDIT #1: The code that instantiates the object never executes. In fact I put it inside an if-statement with a clause that I know is impossible (but the compiler does not know). That is why I think the code is seg-faulting at load-time.

Use valgrind:

valgrind <yourProgram>

it will tell you where memory leak is.

Or you can use gdb to see where it breaks, by stepping through the code.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM