1

I'm just starting with C programming (following along with 'C The Hard Way') - anytime I try to run valgrind I'm getting Segmentation fault in terminal right off the bat.

I've installed and reinstalled valgrind

Any suggestions here?

user438383
  • 5,716
  • 8
  • 28
  • 43
Tony Ciccarone
  • 132
  • 1
  • 7

2 Answers2

2

Valgrind should never segfault - every (even buggy) program should be run and problems intercepted.

If you get segfaults even for innocuous commands like valgrind true, I suggest you to download precompiled valgrind binaries for your OS, presumably with its package manager. Similar problems with compilation sometimes happen (could be bugs in the compiler, incompatibilities between the sources and the compiler, bad libraries...). You probably don't want to dig into this if you're still learning.

If valgrind merely reports a segfault in your program, post its messages. It means you have a bug in your program.

jpalecek
  • 47,058
  • 7
  • 102
  • 144
  • It happens with valgrind true as well. Should I delete all references to valgrind (if so, where the heck are they?) or just run the precompiled package again? – Tony Ciccarone Oct 28 '11 at 17:57
  • 1
    Try to run `sudo make uninstall` in the directory you have run `sudo make install`. If this doesn't work, find freshly created files under `/usr/local` and remove them (try `find /usr/local -newer .`). You can probably remove the entire contents of `/usr/local` unless you have installed other things from source. Then install `valgrind` with your distro's package manager. – n. m. could be an AI Oct 28 '11 at 18:42
  • Any more advice for this? Valgrind just crashes immediately with "Segmentation fault (core dumped)" for me. Only on my code though, it works fine on other stuff, and it is the precompiled version from the Ubuntu 16.04 repositories (version valgrind-3.11.0). At a bit of a loss regarding what to do when valgrind dies... I guess I can try some other versions or something. – Ben Farmer May 09 '18 at 12:27
1

Which program is SEGV faulting, valgrind itself or your own program?

If it is your program, you could just compile it with debugging enabled (that is using gcc -g on Linux) and then run it in the debugger (gdb on Linux).

If it is valgrind itself, since you are a newbie, you are unlucky, but you still can debug your program the traditional way (with gdb). Using gdb is documented here

Basile Starynkevitch
  • 223,805
  • 18
  • 296
  • 547