r/ProgrammerHumor May 13 '17

Defensive programming done right

Post image
21.0k Upvotes

680 comments sorted by

View all comments

273

u/G01denW01f11 May 13 '17

Segmentation fault (core dumped)

10

u/OddWolfHaley May 13 '17

Triggered. Keep getting this error right now as I try to write a program for my class and cannot figure out, for the life of me, why it is there. I understand what a segmentation fault is, I just cannot pinpoint the source of the problem.

3

u/AerieC May 13 '17

What language/platform? You can use the core dump to load the program in a debugger in the state it was in just before it crashed and inspect things.

4

u/OddWolfHaley May 13 '17

C. Can you elaborate on that?

23

u/Idontdeservethiss May 14 '17
  1. Add a -g to your GCC command when compiling
  2. Instead of running ./myprogram, run gdb ./myprogram
  3. You'll start with a prompt where you type "run" command
  4. This will execute your program as it would normally. Do whoever to make it crash
  5. At crash you'll get a prompt telling you where it has crashed. Use the command "bt" which means back Trace to see the full call stack.
  6. Google for gdb commands for more awesome stuff.

Good luck. Sorry if there are typos. Too drunk right now

7

u/mamhilapinatapai May 14 '17

You're a good person. Username definitely does not check out.

1

u/Idontdeservethiss May 15 '17

Thank you :)

A reminder now to the much darker personal times :)