debugging

hi all,
 I have a small program to send file from client to server and it has segmentation fault. I compile them by g++. Could you please show me step by step how to run debugger ? tks.
BeginToLearnAsked:
Who is Participating?

Improve company productivity with a Business Account.Sign Up

x
 
trinitrotolueneConnect With a Mentor Director - Software EngineeringCommented:
>>>>>>>>The filenam was sent sucessfully. it fails to send trunk of file. please advise.

what do you mean? so have you solved the segmentation fault.

Have you allocated enough memory for the buffer? Is there a buffer overflow? If its a C-string has it been terminated with a null char? How is the socket being declared?

Answer these questions else it is really difficult to figure out your problem
0
 
jkrConnect With a Mentor Commented:
You'll find a complete tutorial here http://www.delorie.com/gnu/docs/gdb/gdb_toc.html ("Debugging with GDB")
0
 
BeginToLearnAuthor Commented:
i am using those break, run, next, display to trace my "segmentation fault" now. can u show me what i did wrong in my code hihi?
0
What Kind of Coding Program is Right for You?

There are many ways to learn to code these days. From coding bootcamps like Flatiron School to online courses to totally free beginner resources. The best way to learn to code depends on many factors, but the most important one is you. See what course is best for you.

 
trinitrotolueneConnect With a Mentor Director - Software EngineeringCommented:
actually you need not even use the debugger. Just insert a lot of log statements in your code. I mean printfs and output these log statements. Then run your program, you will be able to narrow down your search to a few lines as to where the problem might be

Once you have a fair idea of where the problem might be just check the pointer initializations and operations you are doing in your program. It most probably is a simple issue with some pointer you are using


however also take a look at these links

http://www.unknownroad.com/rtfm/gdbtut/gdbsegfault.html
http://www.cprogramming.com/debugging/segfaults.html


Let me know if this helps
0
 
BeginToLearnAuthor Commented:
for links. I grab those tutorial from here
  http://www.csc.sdstate.edu/~gamradtk/resources/debuggercpp.pdf
 very succient and enough for me.
 I can see that before sending, the buffer is exactly what i expected. But the server can't receive data of that buffer. hix hix.
0
 
BeginToLearnAuthor Commented:
server only received x)
So i don't know why
0
 
BeginToLearnAuthor Commented:
The filenam was sent sucessfully. it fails to send trunk of file. please advise.
0
 
ssnkumarConnect With a Mentor Commented:
Core file will be useful in debugging. It has the call stack of the crashed code.
So, install gdb on your computer.
Then invoke gdb with the following command: gdb a.out core
And in the gdb prompt, issue the command: bt

That will show the call stack and the exact place where the code crashed.
For this to work, you will need to compile your code with -g option and then get a core file.
0
 
BeginToLearnAuthor Commented:
tks
0
 
BeginToLearnAuthor Commented:
oh I know what cause core dump already. Tks all.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.