Thread: Debugging....How??

  1. #1
    Registered User
    Join Date
    Feb 2005
    Posts
    32

    Debugging....How??

    All right, can someone tell me how to debug my own codes...??
    What is step in and step out...??

    I kept pressing F11, but it opened up another window of codes which is not written by me......

    I thought debugging is supposed to help us in checking our codes like how our codes run....??


    Someone pls tell me how to use the debugger...

    _____

  2. #2
    Registered User
    Join Date
    Sep 2001
    Posts
    4,912
    Specifically what compiler / IDE are you using? I've rarely actually used the "debuggers" that come with my compilers, so I'm afraid I can't give you much advice if you're using anything other than a Borland system. The idea is just to give you more information about what's happening behind the scenes of your program to help you diagnose problems. Specifically how to do that, depends on the program. If you can't find what you're looking for here, you may find it useful to look in the documentation of your compiler.

    Keep in mind that the debugger helps you find problems in your code that aren't picked up as errors by the compiler. If it's compiler errors you're trying to solve, the only thing you can do is to look at the error message given to you. You can look up the error code in your documentation, or look at the line on which the error occured and try to spot whatever typo you made.

    Good luck.

  3. #3
    Registered User
    Join Date
    Feb 2005
    Posts
    32
    Ohhh.....I'm using Miscrosoft Visual C++ 6.0 to write on codes on C. Hmmm......nope, I'm not using it to check my errors in my codes.....

    I've several layers of nested loop structure in my codes, hence I need to see how and in what manner does the codes run......

    Thanks for your quick reply.....hmmm.....are you able to give me more advice or how to use the debugger now...??

    _____

  4. #4
    ---
    Join Date
    May 2004
    Posts
    1,379
    'Step over' is stepping over a function.
    'Step Into' is stepping into (go through) a function.
    You can add 'watches' to view the contents of a variable while the program is running.
    Before debugging to need to set a breakpoint somewhere in the code (so the code stops).

    These are some generic things most debuggers have.

  5. #5
    Registered User
    Join Date
    Mar 2004
    Posts
    494
    You can also use printf statements in your loops so you can see in what loop the error occurs. This is i guess one of the easiest ways to narrow down your problems if you dont understand where the probem occurs.
    When no one helps you out. Call google();

  6. #6
    Registered User Kybo_Ren's Avatar
    Join Date
    Sep 2004
    Posts
    136
    Using a million printf statements isn't going to help you much when you have no idea that your program has a buffer overflow error.

  7. #7
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Using a million printf statements is a very handy way to debug a program. I guess you're not familiar with printf. You see, there are these handy things called conversion specifiers, that allow you to make printf display all kinds of things. For example, you can display numbers and even characters! Some of these specifiers can be used to display things like memory addresses, hexadecimal, and all kinds of crazy stuff!

    I know, it's hard to believe. But trust me, it's true. Why, with enough statements and specifiers, I bet it would be possible to even display the value and address of every single variable in your program!

    I hope you were sitting down for that one.

    It truely boggles the mind.

    Quzah.
    Hope is the first step on the road to disappointment.

  8. #8
    Registered User
    Join Date
    Feb 2005
    Posts
    32
    Oh...I think let me post my codes here and let you all see what's going wrong here...
    Code:
    j=0;
    for (k=0; k<NumFeatureElement-1; k++){
    for (j=0; j<Rows; j++){
    	if (j == Rows)
    	{fElementCountRE =0;
    	fcElementCountRE =0;}
    	if (table[j][0] == atof(UniqueFeatureElement[k]) ) 
     	{fElementCountRE += 1;}
    
    	if (table[j][0] == atof(UniqueFeatureElement[k]) && table[j][Columns-1] == 0 )
    	{fcElementCountRE +=1;}
    	
    	fErrorRE =  (float)fcElementCountRE/fElementCountRE*100;  //A formula to calculate something...
    	//for (x=0; x<MAXVALUE; x++){
    	fErrorArrayRE[0] = fErrorRE;
    	//}
    	//fErrorRE =0;
    
    }//End For
    //fElementCountRE =0;
    //fcElementCountRE =0;
    }//End For
    Explanation to my codes: I've already created a dynamic 2-D table using Calloc(). I've a set of data being inserted into this 2-D array. These data include binary values like "0,1,2..."

    What I intend to do here:
    Code:
    First : Compare all the data in first column with all the data in last column.
    (E.g: if both are having 0, than increase value of fcElementCountRE by 1) 
    After all the counting is done,  fErrorRE is calculated using the above formula. Next it is stored into array: fErrorArrayRE[0].
    Code:
    Second : Now the value for K should increase by 1, which means now I'm still comparing data of first column with last column, but now the condition is: if last columns is having value of "1", increase fcElementCountRE by 1.
    
    Note: fcElementCountRE is used again, I intend to make it become zero first, by failed...
    
    So, after the counting is done, formula is applied again and value is now stored into fErrorArrayRE[1] this time.
    Summary: Count and calculate, then place the calculated values in fErrorArrayRE[x] accordingly......
    _____

  9. #9
    Registered User
    Join Date
    Feb 2005
    Posts
    32
    nvm.....above question solved....but still don't know how to use a debugger...

    _____

  10. #10
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,665
    > but still don't know how to use a debugger...
    Take any program you've written and practice
    - breakpoints
    - step into
    - step over
    - quickwatch
    - watch
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Dev-C++: Problems with Breakpoint Debugging
    By Thileepan_Bala in forum C Programming
    Replies: 1
    Last Post: 01-17-2008, 10:48 AM
  2. Problem in debugging in Eclipse
    By Bargi in forum Linux Programming
    Replies: 1
    Last Post: 08-21-2007, 09:53 AM
  3. Debugging Dev C++
    By tuurb046 in forum Tech Board
    Replies: 10
    Last Post: 08-16-2007, 12:51 PM
  4. Debugging book recommendation
    By dagans in forum Projects and Job Recruitment
    Replies: 1
    Last Post: 09-13-2005, 07:35 PM
  5. debugging directx apps
    By confuted in forum C++ Programming
    Replies: 1
    Last Post: 08-16-2003, 08:56 AM