GIDForums  

Go Back   GIDForums > Computer Programming Forums > C++ Forum
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
 
Thread Tools Search this Thread Rate Thread
  #1  
Old 12-Aug-2008, 22:48
kssu05 kssu05 is offline
New Member
 
Join Date: Aug 2008
Posts: 4
kssu05 is on a distinguished road
Wink

Tips for effective debugging in C++


hi all,
am beginner for c++ environment.
i need to debug de c++ code stuffs .
so need some help and tips for effective debugging for fixing bugs
am supposed to use Microsoft Visual Studio
  #2  
Old 13-Aug-2008, 05:15
L7Sqr L7Sqr is offline
Member
 
Join Date: Jul 2005
Location: constant limbo
Posts: 234
L7Sqr is a jewel in the roughL7Sqr is a jewel in the rough

Re: need tips for effective debugging in c++


I believe MSVS has built-in debugging tools. Any reason you cant use them?
  #3  
Old 13-Aug-2008, 05:37
kssu05 kssu05 is offline
New Member
 
Join Date: Aug 2008
Posts: 4
kssu05 is on a distinguished road

Re: need tips for effective debugging in c++


okey thanks .
is there any other alternative for debugging
  #4  
Old 13-Aug-2008, 06:47
dlp dlp is offline
Member
 
Join Date: May 2006
Posts: 157
dlp has a spectacular aura about

Re: need tips for effective debugging in c++


Well placed cout/cerr/ofstream object calls. Can be pretty handy as sometimes Visual Studio's debugger limits the scope of variables you need to know the value of, but a real pain to insert and remove.
  #5  
Old 13-Aug-2008, 12:11
L7Sqr L7Sqr is offline
Member
 
Join Date: Jul 2005
Location: constant limbo
Posts: 234
L7Sqr is a jewel in the roughL7Sqr is a jewel in the rough

Re: need tips for effective debugging in c++


If you are going to use tracer bullets (output statements for debugging) you may as well design them so they can be turned off at compilation (or by internal flag)
CPP / C++ / C Code:
#ifdef USE_MY_DEBUG
#define DEBUG(msg...) fprintf(stderr, msg)
#else
#define DEBUG(msg...) 
#endif

Internal flag example
CPP / C++ / C Code:
void trace(FILE * out, const char * fmt, ...) {
   if (debugging_flag_set) {
      /* do your output here */
   }
}

I used C examples above as it makes the example easier, but you can derive equivalent methods in C++ that accomplish the same.
  #6  
Old 13-Aug-2008, 18:36
ocicat ocicat is offline
Regular Member
 
Join Date: May 2008
Posts: 586
ocicat is a jewel in the roughocicat is a jewel in the rough

Re: Tips for effective debugging in C++


Quote:
Originally Posted by kssu05
so need some help and tips for effective debugging for fixing bugs
Actually, the debugger integrated into Visual Studio's IDE is one of the best debuggers around. With not a lot of poking about the menus or reading the help, it is fairly simple to display watch windows displaying the running values of selected variables, a stack trace, & memory contents of specified regions of memory. Yes, this can be done in other debuggers as well (as it should...), but this is easily done in Visual Studio's debugger.

As for generalized debugging techniques, yes, the brute force method many will advocate is by integrating printf() statements in one form or another, however this can adversely affect performance if the purpose of the code is time-critical.

Fundamentally, nothing replaces knowledge of the problem space. If you have prior experience debugging code & debugging code related to the problem at hand, you will be able to more effectively & efficiently track down errors. Yet in the absense of domain-specific knowledge:
  • focus on whatever variables appear to be most important to the application & watch their values as execute proceeds through the logic.
  • watch dynamic memory allocations & pointer usage. Ensure that all addresses being manipulated are initialized & that any memory copies done to allocated memory.
  • If arrays are involved, make sure that reading & writing past the end of arrays is not done.
  • watch scoping. Make sure that whatever variables are being used are still in scope.
As can be seen in this list, in the absence of specific knowledge about the domain space, one has to fall back on ensuring that language features are not being unduly abused.

Lastly, experience helps. The more you debug, the better you will become at the skill. Learning to debug your own code is a beginning, but learning how to debug other people's code is more important as you have to figure out how they understood the problem & implemented their solution.
 
 

Recent GIDBlogProblems with the Navy (Officers) by crystalattice

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Google AdSense tips to earn money amigo AdSense Forum 30 17-Mar-2008 09:02
I/O array problem with data files Mr_Peepers C++ Forum 8 21-Feb-2008 19:22
4 Tips to Find the Web Host That's Right for You abdellah2d Web Hosting Advertisements & Offers 1 11-Aug-2007 10:36
Memory de-allocation during debugging gaoanyu C Programming Language 12 19-Dec-2005 04:50
Royalty Free Music Tips abacomedia Music Forum 0 26-Jul-2004 14:26

Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The

All times are GMT -6. The time now is 06:11.


vBulletin, Copyright © 2000 - 2010, Jelsoft Enterprises Ltd.