Thread: debugging code

  1. #1
    Registered User
    Join Date
    Apr 2019
    Posts
    662

    debugging code

    As some of you know i use code blocks to write my code as i like several of the features it affords me rather than using a standard text editor.

    the issue comes to debugging other than setting a breakpoint and stepping through the code a line at a time it seems to be rather limited. i know years ago when i did a little bit of vb i could type into the debug window certain commands to test the value of things as it went through the code. however i cant find anything on the internet that says how to do that with code blocks.

    is there another program i could use that would achieve this or even an idiots guide to the error messages gcc produces

    many thanks
    coop

  2. #2
    Registered User
    Join Date
    May 2016
    Posts
    101
    You will want to use GDB then, or LLDB if you plan on sticking to console based debuggers, it has a much, much nicer text UI.
    Once you start using GDB as a glorified interpreter for C, your eyes will be opened. I can't stress enough what an amazing learning tool it is.

    EDIT: I don't know how easy will be to use these if you're on Windows. You might want to look into WSL if that's the case.
    Last edited by Dren; 05-26-2019 at 05:01 AM.
    printf("I'm a %s.\n", strrev("Dren"));

  3. #3
    Registered User
    Join Date
    Apr 2019
    Posts
    662
    ok thanks i shall google them

  4. #4
    Registered User awsdert's Avatar
    Join Date
    Jan 2015
    Posts
    546

  5. #5
    TEIAM - problem solved
    Join Date
    Apr 2012
    Location
    Melbourne Australia
    Posts
    1,859
    I think what you are looking for is the "watch window" where you can look at the values of variables as you are debugging.
    Fact - Beethoven wrote his first symphony in C

  6. #6
    Registered User
    Join Date
    Apr 2019
    Posts
    662
    Quote Originally Posted by Click_here View Post
    I think what you are looking for is the "watch window" where you can look at the values of variables as you are debugging.
    ive found that but on several occasions i have had a situation where a value changes drastically and i don't see it until im back in the function that uses it. However i discovered this evening quite by accident that there is a whole host of things you can type into the debug window at the bottom once your on a breakpoint and i suspect not all of them are relevant to c
    coop

  7. #7
    Registered User
    Join Date
    Apr 2019
    Posts
    662
    incidently while we are on the subject of codeblocks and debugging i came across some code that someone posted here as a suggestion on how to do something code blocks wouldn't compile it but gcc did with no issues
    ill see if i can find it again and post it here
    coop

  8. #8
    Registered User
    Join Date
    Apr 2019
    Posts
    662
    Code:
    #include <stdio.h>
    #include <stdlib.h>
    
    int main()
    {
        static const char * const msgs[] = { "improve", "average", "good", "great", "excellent" };
      double a;
      int g;//, offset;
    
      // get the avarage from keyboard...
      scanf( "%lf", &a );
    
      g =  ( a >= 90.0 );
      printf("%d", g);
      g += ( a >= 80.0 );
      printf("%d", g);
      g += ( a >= 70.0 );
      printf("%d", g);
      g += ( a >= 60.0 );
      printf("%d", g);
    
      printf ( "%g: %s\n", a, msgs[g] );
        return 0;
    }

  9. #9
    TEIAM - problem solved
    Join Date
    Apr 2012
    Location
    Melbourne Australia
    Posts
    1,859
    Appart from being a horrible programme (it doesn't prompt the user to do anything), it worked on my CB -

    I'm running it on Windows 10
    Fact - Beethoven wrote his first symphony in C

  10. #10
    Registered User
    Join Date
    Apr 2019
    Posts
    662
    i got an error saying un-terminated strimg but as i say gcc compiled it with no issues

  11. #11
    TEIAM - problem solved
    Join Date
    Apr 2012
    Location
    Melbourne Australia
    Posts
    1,859
    Was the cause of it ever identified?
    Fact - Beethoven wrote his first symphony in C

  12. #12
    Registered User
    Join Date
    Apr 2019
    Posts
    662
    Quote Originally Posted by Click_here View Post
    I think what you are looking for is the "watch window" where you can look at the values of variables as you are debugging.
    my apologies i didn't understand what you meant until you said about writing in to the watch window on another post and i did it by accident as the watch window had focus when i wanted to type something. just what i was looking for i have been using it all day.

    thanks
    coop

  13. #13
    Registered User
    Join Date
    Apr 2019
    Posts
    662
    Quote Originally Posted by Click_here View Post
    Was the cause of it ever identified?
    no as it wasn't my topic i didn't feel it was fair to the op to question someone else's code when they were trying to help

  14. #14
    TEIAM - problem solved
    Join Date
    Apr 2012
    Location
    Melbourne Australia
    Posts
    1,859
    Quote Originally Posted by cooper1200 View Post
    my apologies i didn't understand what you meant until you said about writing in to the watch window on another post and i did it by accident as the watch window had focus when i wanted to type something. just what i was looking for i have been using it all day.

    thanks
    coop
    That's great to hear - I copy and paste algorithms from other IDEs to Codeblocks for the watch window.

    The fact that you can just type what you want to see is so good

    Code:
     
    (*apple) -> banana[grape] 
    
    Not a problem!

    I'm going to be spending today debugging some code myself - It's just a process of finding something that is not behaving the way it is supposed to and tracking down where that behaviour starts

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. help for debugging my code
    By mathink in forum C Programming
    Replies: 22
    Last Post: 01-09-2013, 05:06 AM
  2. Help with Debugging Code
    By husslela2 in forum C Programming
    Replies: 14
    Last Post: 03-24-2010, 02:56 PM
  3. Replies: 1
    Last Post: 03-10-2010, 11:28 AM
  4. Need help in debugging this code
    By jaggesh in forum C Programming
    Replies: 4
    Last Post: 02-09-2008, 08:47 AM
  5. debugging code
    By DeViLs_SouL in forum C++ Programming
    Replies: 3
    Last Post: 12-05-2001, 01:34 PM

Tags for this Thread