Solved

debugging

Posted on 2011-03-07
10
348 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 100 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 300 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
Is Your AD Toolbox Looking More Like a Toybox?

Managing Active Directory can get complicated.  Often, the native tools for managing AD are just not up to the task.  The largest Active Directory installations in the world have relied on one tool to manage their day-to-day administration tasks: Hyena. Start your trial today.

 

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 100 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 300 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

Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
How to split this in C++ 4 102
split53 challenge 7 96
WPF issue with Trigger 2 106
Copy Files - Python 7 83
Article by: SunnyDark
This article's goal is to present you with an easy to use XML wrapper for C++ and also present some interesting techniques that you might use with MS C++. The reason I built this class is to ease the pain of using XML files with C++, since there is…
Windows programmers of the C/C++ variety, how many of you realise that since Window 9x Microsoft has been lying to you about what constitutes Unicode (http://en.wikipedia.org/wiki/Unicode)? They will have you believe that Unicode requires you to use…
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

777 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