6

How do I debug a segmentation fault?

Basically this is what happens:

I run my server in background: ./server &

then I run my client: ./client

When I try to login to my server, on correct username and password, everything is okay, but when I type invalid user and password, it results in a segmentation fault.

How do I make the compiler/debugger able to output what error its actually see that causes segmentation core dump.

I know gdb but I try using gdb client but it doesn't seem to work.

nalply
29.1k15 gold badges83 silver badges104 bronze badges
asked Aug 12, 2012 at 9:21
2
  • may be post a question on the problem you are facing with gdb Commented Aug 12, 2012 at 9:24
  • 1
    And note that question marks are used to ask questions (opposed to full stops). Commented Aug 12, 2012 at 9:29

3 Answers 3

7

A good idea with segmentation faults is to run the program with valgrind for debugging. That way, you'll often get more detailed information about what caused your segmentation fault. For example, it will tell you if you are reading from uninitialized memory.

answered Aug 12, 2012 at 9:40
Sign up to request clarification or add additional context in comments.

Comments

6

If you are using g++ first compile your program using the -g option. Then use

 gdb name_of_program core 

to run gdb on the core dump you get (name_of_program is the name of the executable file you just built with g++). This link is useful for how to use gdb.

http://www.ibm.com/developerworks/library/l-gdb/

answered Aug 12, 2012 at 9:26

Comments

-1

this ads annotations to the code. it's helpful only if you have a lot of function calls and you don't know the call path.

answered Aug 12, 2012 at 10:44

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.