Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

debugging

Posted on 2011-03-07
10
Medium Priority
?
381 Views
Last Modified: 2012-05-11
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.
0
Comment
Question by:BeginToLearn
10 Comments
 
LVL 86

Assisted Solution

by:jkr
jkr earned 400 total points
ID: 35062727
You'll find a complete tutorial here http://www.delorie.com/gnu/docs/gdb/gdb_toc.html ("Debugging with GDB")
0
 

Author Comment

by:BeginToLearn
ID: 35062776
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
 
LVL 12

Assisted Solution

by:trinitrotoluene
trinitrotoluene earned 1200 total points
ID: 35062902
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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:BeginToLearn
ID: 35062965
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
 

Author Comment

by:BeginToLearn
ID: 35063156
server only received x)
So i don't know why
0
 

Author Comment

by:BeginToLearn
ID: 35066456
The filenam was sent sucessfully. it fails to send trunk of file. please advise.
0
 
LVL 8

Assisted Solution

by:ssnkumar
ssnkumar earned 400 total points
ID: 35104968
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
 

Author Comment

by:BeginToLearn
ID: 35105675
tks
0
 
LVL 12

Accepted Solution

by:
trinitrotoluene earned 1200 total points
ID: 35106018
>>>>>>>>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
 

Author Comment

by:BeginToLearn
ID: 35106036
oh I know what cause core dump already. Tks all.
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Having just graduated from college and entered the workforce, I don’t find myself always using the tools and programs I grew accustomed to over the past four years. However, there is one program I continually find myself reverting back to…R.   So …
Examines three attack vectors, specifically, the different types of malware used in malicious attacks, web application attacks, and finally, network based attacks.  Concludes by examining the means of securing and protecting critical systems and inf…
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
Suggested Courses

877 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question