ping Elysia, the VC++ expert :)

This is a discussion on ping Elysia, the VC++ expert :) within the Tech Board forums, part of the Community Boards category; Would you happen to have a link to a good tutorial on how to use VC++ 2008 Express to debug ...

  1. #1
    In my head happyclown's Avatar
    Join Date
    Dec 2008
    Location
    In my head
    Posts
    391

    ping Elysia, the VC++ expert :)

    Would you happen to have a link to a good tutorial on how to use VC++ 2008 Express to debug C programs?

    The online help that came with VC++ gives a short(simple) tutorial on how to debug a basic C++ program, so all the debugging tools and codes are related to C++.

    I am a C newbie, and would like instructions(as comprehensive as possible) relevant to C, which I can at least partially understand.

    Thanks in advance.
    OS: Linux Mint 13(Maya) LTS 64 bit.

  2. #2
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Set breakpoint(s) with F9, use F10 (step over) and F11 (step into) to step around the code. F5 runs to the next breakpoint.

    There are other things you can do, but with those few things, you have a starting point.

    If you have a crash, the "call stack" window is good to see how you ended up where you ended up [unless you have made a REAL mess of things].

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  3. #3
    In my head happyclown's Avatar
    Join Date
    Dec 2008
    Location
    In my head
    Posts
    391
    Thanks Mats.
    OS: Linux Mint 13(Maya) LTS 64 bit.

  4. #4
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Posts
    23,021
    Also, Shift+F11 is step out (running to the end of a function).
    All the commands are available through the Debug menu.
    Pay attention to the variables window, as well. You can select Auto or Watch, to manually select which variables to watch.
    You can also hover the mouse over variables to see their contents.

    There are lots of things a debugger can do, but these are the basics. If you need help tracking down a problem, we can explain additional techniques you can use.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  5. #5
    In my head happyclown's Avatar
    Join Date
    Dec 2008
    Location
    In my head
    Posts
    391
    Thanks Elysia.

    I am going to devote 1-2 weeks learning how to use the debugger.
    OS: Linux Mint 13(Maya) LTS 64 bit.

  6. #6
    In my head happyclown's Avatar
    Join Date
    Dec 2008
    Location
    In my head
    Posts
    391
    Quote Originally Posted by matsp View Post

    If you have a crash, the "call stack" window is good to see how you ended up where you ended up [unless you have made a REAL mess of things].
    In my "call stack" window, are these 5 lines:
    > test.exe!main() Line 37 C
    test.exe!__tmainCRTStartup() Line 586 + 0x19 bytes C
    test.exe!mainCRTStartup() Line 403 C
    kernel32.dll!7c817067()
    [Frames below may be incorrect and/or missing, no symbols loaded for kernel32.dll]
    The only thing that changes when I keep pressing F10 is the line number, and the bottom 2 lines are permanently greyed out.

    Should there be alot more happening in this window?

    And for the pointers that I've declared, in the "Autos" window, I get:
    + p_line 0xcccccccc <Bad Ptr> char *
    + p_newline 0xcccccccc <Bad Ptr> char *
    But I think it's because they haven't been initialised yet?

    Thanks.
    OS: Linux Mint 13(Maya) LTS 64 bit.

  7. #7
    Registered User
    Join Date
    Dec 2006
    Location
    Canada
    Posts
    3,183
    Code:
    > test.exe!main() Line 37 C
    test.exe!__tmainCRTStartup() Line 586 + 0x19 bytes C
    test.exe!mainCRTStartup() Line 403 C
    kernel32.dll!7c817067()
    [Frames below may be incorrect and/or missing, no symbols loaded for kernel32.dll]
    Typically we don't care about anything below main().

    The call stack is just telling you that you are on Line 37 in main().

  8. #8
    In my head happyclown's Avatar
    Join Date
    Dec 2008
    Location
    In my head
    Posts
    391
    Thanks cyberfish.

    Here's something that some may find interesting.

    I did a little research on the net, and have found that the symbols that is required by the debugger does not come packaged with Visual Studio.

    So you have to set the debugger to download the symbols from the M$ symbol server, and there are 2 ways to do this, automatically, or manually. These instructions are directly from the VC++ online help.

    Automatically

    1.On the Debug menu, click Options.

    2.In the Options dialog box, open the Debugging node, and then click Symbols. For more information, see How to: Specify a Symbol Path.

    3.Edit the text to add a new path to the symbol server.

    To use the Microsoft public symbol server, type:

    http://msdl.microsoft.com/download/symbols (this is not browseable, and can only be accessed by the debugger for downloading).

    Manually
    Right-click in the Modules window and choose Find Symbols on the shortcut menu.

    The debugger searches the symbol path to try to find symbols itself. If symbols were not found, the Find Symbols dialog box appears. In the Find Symbols dialog box, locate the symbols file (PDB or DBG file) you want to load. When the name of the symbols file appears in the File Name box, click OK.

    Now my 'call stack' window looks like this:
    > test.exe!main() Line 19 C
    test.exe!__tmainCRTStartup() Line 586 + 0x19 bytes C
    test.exe!mainCRTStartup() Line 403 C
    kernel32.dll!_BaseProcessStart@4() + 0x23 bytes
    The debugger will download whatever symbols are needed for whatever dll is required(ie. kernel32.dll). Don't know what, if any use it is to me, but at least the debugger is getting what it needs, and I don't see this anymore

    kernel32.dll!7c817067()
    [Frames below may be incorrect and/or missing, no symbols loaded for kernel32.dll]
    Time for me to play some more with the debugger.
    OS: Linux Mint 13(Maya) LTS 64 bit.

  9. #9
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Posts
    23,021
    Quote Originally Posted by happyclown View Post
    And for the pointers that I've declared, in the "Autos" window, I get:
    But I think it's because they haven't been initialised yet?
    Yes, as you can see, the debugger will automatically try to dereference any pointers it encounters and display its value. In this case, the pointers aren't initialized (in Debug mode, all variables are automatically initialized to 0xCC...). You can click on the plus to see what it's pointing to, if it's a valid pointer. If the pointer you dereference points to a struct that contains more pointers of if it's a pointer to pointer, you can dereference the other pointers and see where they lead, etc, into eternity.

    Variables that have been destroyed and pointers that have been freed are filled with 0xFEFEFEFE.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  10. #10
    In my head happyclown's Avatar
    Join Date
    Dec 2008
    Location
    In my head
    Posts
    391
    I am trying to debug this program
    Code:
    /* Passing an array to a function. Alternative way. */
    
    #include <stdio.h>
    
    #define MAX 10
    
    int array[MAX+1], count;
    
    int largest(int num_array[]);
    
    int main( void )
    {
        /* Input MAX values from the keyboard. */
    
        for (count = 0; count < MAX; count++)
        {
            printf("Enter an integer value: ");
            scanf("%d", &array[count]);
    
            if ( array[count] == 0 )
                count = MAX;               /* will exit for loop */
        }
        array[MAX] = 0;
    
        /* Call the function and display the return value. */
        printf("\n\nLargest value = %d\n", largest(array));
    
        return 0;
    }
    /* Function largest() returns the largest value */
    /* in an integer array */
    
    int largest(int num_array[])
    {
        int count, biggest = -12000;
    
        for ( count = 0; num_array[count] != 0; count++)
        {
            if (num_array[count] > biggest)
                biggest = num_array[count];
        }
    
        return biggest;
    }
    In the "Autos" window, the only variable shown is count, and it's value. Why isn't array[count](and it's value) shown as well? If I was to run the mouse over array[count], I can see it's value, but I would like to see it's value as the program is running. Other programs that I've debugged show ALL values of arrays, and pointers, as they are assigned, so why isn't that happening in this case?

    Thanks.
    OS: Linux Mint 13(Maya) LTS 64 bit.

  11. #11
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Posts
    23,021
    "Auto" isn't always automatic. Use manual watching instead.
    Highlight the variable, right-click and select Add Watch. Then turn to your Watch window beside the Auto window. Here you can see all the variables you have specified to watch.

    Oh and global variables are bad. That might be one of the reasons that debugger is ignoring it
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  12. #12
    Hail to the king, baby. Akkernight's Avatar
    Join Date
    Oct 2008
    Location
    Faroe Islands
    Posts
    717
    o.o ok... I really just thought Visual C++ was a text editor with intellisense(?) and a compiler... Didn't know it was so advanced and stuff, I should start learning this
    Currently research OpenGL

  13. #13
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Code:
            if ( array[count] == 0 )
                count = MAX;               /* will exit for loop */
    If you want to break a loop, use "break", not changing the loop variable - it can confuse the compiler, and is definitely harder to follow for humans.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  14. #14
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Posts
    23,021
    Visual Studio is a complete developer package. It contains compiler, debugger, editor, code analysis, testing, source server, and much more, depending on version.
    There is a reason companies use it over any other IDE.
    But for non-professional developers, most of those extra features are overkill. Although, that is not to say testing and code analysis are bad things.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  15. #15
    Hail to the king, baby. Akkernight's Avatar
    Join Date
    Oct 2008
    Location
    Faroe Islands
    Posts
    717
    source server o.o? Any explaination to that? Like, do you get a server where you can save your source, and others in the team(if you have one) can just download and upload to it o.o?
    If that's it, then it's the ultimate team working benefit, or something! And I've been looking for such a thing for quite sometime xP but I guess it's not in the express version?
    Currently research OpenGL

Page 1 of 3 123 LastLast
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. ping script doesn't work?
    By userpingz in forum C Programming
    Replies: 3
    Last Post: 05-31-2009, 08:53 PM
  2. Replies: 8
    Last Post: 05-07-2009, 12:31 PM
  3. IPv6 ping in windows...problem..lots of ode:(
    By Neill KElly in forum C Programming
    Replies: 3
    Last Post: 04-28-2009, 12:50 AM
  4. ping client
    By cpp_is_fun in forum C Programming
    Replies: 4
    Last Post: 11-29-2006, 12:44 PM
  5. Ping
    By ZakkWylde969 in forum Tech Board
    Replies: 5
    Last Post: 09-23-2003, 01:28 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21