A segfault is usually a bad pointer or something pointing outside allocated space. Why it stops segfaulting when you run it through Valgrind I don't know. Compile with -g for either Valgrind or gdb, and if it still runs in Valgrind try gdb. You can just do gdb <executable> then you'll probably have to type run in gdb. At least if it segfaults in there you can do a backtrace and maybe figure out why. Compiling with -g will usually enable gdb to print out bits of your code when it stops so you may recognize where it is. Google something like "gdb segfault tutorial", you usually have to pick a frame I think.
hmm, umass, I used to work there until 2009. On 1/26/19, Eliot Moss <m...@cs.umass.edu> wrote: > On 1/26/2019 6:12 PM, Peng Yu wrote: > >> I have an executable. If I just run on its own, there will be >> segmentation fault. But if I run it using valgrind, it finishes >> successfully. Does anybody how can this happen? How to debug such a >> program? Thanks. > > Maybe not the sort of answer you have in mind, but I might start > with using gdb. It should still segfault under those conditions. > You can then try recompiling to -g to get debug symbols. Doing > that might affect whether the bug exhibits, but it would make > debugging easier. > > Valgrind might be useful if you think the fault has to do with > improper freeing or lack of initialization of pointers ... > > Regards - Eliot Moss > > > _______________________________________________ > Valgrind-users mailing list > Valgrind-users@lists.sourceforge.net > https://lists.sourceforge.net/lists/listinfo/valgrind-users > -- ------------- No, I won't call it "climate change", do you have a "reality problem"? - AB1JX Cities are cages built to contain excess people and keep them from cluttering up nature. Impeach Impeach Impeach Impeach Impeach Impeach Impeach Impeach _______________________________________________ Valgrind-users mailing list Valgrind-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/valgrind-users