LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 01-30-2009, 01:36 PM   #1
palisetty_suman
Member
 
Registered: Feb 2007
Location: TX, USA
Distribution: fedora
Posts: 191

Rep: Reputation: 33
Thumbs up debug c++ prog


Hi,
How to debug a c++ program in c++. I want the command. Suppose my program is prime.cpp. I am not getting any errors. How to debug it.
 
Old 01-30-2009, 02:03 PM   #2
paulsm4
LQ Guru
 
Registered: Mar 2004
Distribution: SusE 8.2
Posts: 5,863
Blog Entries: 1

Rep: Reputation: Disabled
This might be a good place to start:

http://www.unknownroad.com/rtfm/gdbtut/gdbtoc.html

(FYI, the author, Richard M. Stallman, is one of the "founding fathers" of the Open Source movement)
 
Old 01-30-2009, 06:16 PM   #3
salasi
Senior Member
 
Registered: Jul 2007
Location: Directly above centre of the earth, UK
Distribution: SuSE, plus some hopping
Posts: 4,059

Rep: Reputation: 883Reputation: 883Reputation: 883Reputation: 883Reputation: 883Reputation: 883Reputation: 883
With so little information about the problem, I'm not sure if the previous suggestion was the right one for your case. In simpler debugging cases a scattering of diagnostic print statements can be more appropriate.

Obviously, you have to use your skill and judgement to figure out where to put the print statements and what you want to print out, but you didn't want me to put you out of a job, did you?

And, if you are doing this to learn, you might be wanting to try every approach available to you, just for grins.
 
Old 01-30-2009, 06:28 PM   #4
paulsm4
LQ Guru
 
Registered: Mar 2004
Distribution: SusE 8.2
Posts: 5,863
Blog Entries: 1

Rep: Reputation: Disabled
Hi, palisetty_suman -

Yours was a fair question, and I tried to give you a fair answer.

If you're using an IDE to program C++ (for example, KDevelop or Eclipse on Linux, or Visual Studio on Windows), then you probably first want to learn more about your IDE's debugger.

If you're planning on programming C++ on Linux, then you'll almost certainly be using GCC (either directly, from a command line, or behind a GUI IDE). In this case, the command-line "GDB" is definitely a worthwhile tool to learn.

The *last* thing you want to do is rely on "printf" statements. Using them is inevitable. But there are usually better, more effective ways to debug. The trick is to expose yourself to the higher-level tools available (like GDB or Visual Studio), then fall back on "printf" only when you need to.

Good luck - and have fun!

IMHO .. PSM
 
Old 02-01-2009, 08:05 PM   #5
palisetty_suman
Member
 
Registered: Feb 2007
Location: TX, USA
Distribution: fedora
Posts: 191

Original Poster
Rep: Reputation: 33
Thumbs up Thanks

Thanks paul boss. But sorry to say that I haven't got the answer. I am using c++ on linux and i just want a command to debug a program.
like
command filename. I just want the command to debug a filename for errors and execution. Thanks.
 
Old 02-01-2009, 11:07 PM   #6
paulsm4
LQ Guru
 
Registered: Mar 2004
Distribution: SusE 8.2
Posts: 5,863
Blog Entries: 1

Rep: Reputation: Disabled
I gave you a command in the first post:
Quote:
gdb myprogram
I also gave you a tutorial about how to use "gdb". More importantly, the tutorial is also about debugging strategies and tips in general.
 
Old 02-02-2009, 05:26 AM   #7
salasi
Senior Member
 
Registered: Jul 2007
Location: Directly above centre of the earth, UK
Distribution: SuSE, plus some hopping
Posts: 4,059

Rep: Reputation: 883Reputation: 883Reputation: 883Reputation: 883Reputation: 883Reputation: 883Reputation: 883
Quote:
Originally Posted by palisetty_suman View Post
I am using c++ on linux and i just want a command to debug a program. like command filename. I just want the command to debug a filename for errors and execution.
If you are expecting a command that you can run that will automagically remove bugs from an incorrectly written bit of code, then you are setting your expectations rather high.

In addition, maybe you should look at static analysis http://en.wikipedia.org/wiki/List_of..._code_analysis which may be closer to what you want. But you will still have work to do; the best that you can expect is that something will point out potential trouble areas and you will have to come up with a way of writing correct code that corresponds to your intentions.

My assumption is that your program is probably a fairly simple one, of the type that you might be set as a learning problem in the early stages of a programming course.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
How to debug without having debug section in an executable ? unclesam Linux - Newbie 0 02-02-2006 07:23 AM
Help with my prog. Slickmink Programming 7 08-25-2005 11:50 AM
I want to start a prog from another prog but not as child grupoapunte Programming 5 05-23-2005 06:37 PM
[debug]what does the following debug information mean icoming Programming 21 06-08-2004 03:13 AM
Better buying "advanced linux prog" or "unix advanced prog" Dominik Programming 3 12-31-2003 02:11 PM


All times are GMT -5. The time now is 09:49 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration